xref: /freebsd/sys/dev/e1000/e1000_phy.c (revision ddfec1fb6814088abc5805f45c4a18c5731d51b9)
18cfa0ad2SJack F Vogel /******************************************************************************
27282444bSPedro F. Giffuni   SPDX-License-Identifier: BSD-3-Clause
38cfa0ad2SJack F Vogel 
4702cac6cSKevin Bowling   Copyright (c) 2001-2020, Intel Corporation
58cfa0ad2SJack F Vogel   All rights reserved.
68cfa0ad2SJack F Vogel 
78cfa0ad2SJack F Vogel   Redistribution and use in source and binary forms, with or without
88cfa0ad2SJack F Vogel   modification, are permitted provided that the following conditions are met:
98cfa0ad2SJack F Vogel 
108cfa0ad2SJack F Vogel    1. Redistributions of source code must retain the above copyright notice,
118cfa0ad2SJack F Vogel       this list of conditions and the following disclaimer.
128cfa0ad2SJack F Vogel 
138cfa0ad2SJack F Vogel    2. Redistributions in binary form must reproduce the above copyright
148cfa0ad2SJack F Vogel       notice, this list of conditions and the following disclaimer in the
158cfa0ad2SJack F Vogel       documentation and/or other materials provided with the distribution.
168cfa0ad2SJack F Vogel 
178cfa0ad2SJack F Vogel    3. Neither the name of the Intel Corporation nor the names of its
188cfa0ad2SJack F Vogel       contributors may be used to endorse or promote products derived from
198cfa0ad2SJack F Vogel       this software without specific prior written permission.
208cfa0ad2SJack F Vogel 
218cfa0ad2SJack F Vogel   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
228cfa0ad2SJack F Vogel   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238cfa0ad2SJack F Vogel   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248cfa0ad2SJack F Vogel   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
258cfa0ad2SJack F Vogel   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
268cfa0ad2SJack F Vogel   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
278cfa0ad2SJack F Vogel   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
288cfa0ad2SJack F Vogel   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
298cfa0ad2SJack F Vogel   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
308cfa0ad2SJack F Vogel   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
318cfa0ad2SJack F Vogel   POSSIBILITY OF SUCH DAMAGE.
328cfa0ad2SJack F Vogel 
338cfa0ad2SJack F Vogel ******************************************************************************/
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  **/
e1000_init_phy_ops_generic(struct e1000_hw * hw)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
1065b426b3eSGuinan Sun  *  @data: dummy variable
1074dab5c37SJack F Vogel  **/
e1000_null_set_page(struct e1000_hw E1000_UNUSEDARG * hw,u16 E1000_UNUSEDARG data)1087609433eSJack F Vogel s32 e1000_null_set_page(struct e1000_hw E1000_UNUSEDARG *hw,
1097609433eSJack F Vogel 			u16 E1000_UNUSEDARG data)
1104dab5c37SJack F Vogel {
1114dab5c37SJack F Vogel 	DEBUGFUNC("e1000_null_set_page");
1124dab5c37SJack F Vogel 	return E1000_SUCCESS;
1134dab5c37SJack F Vogel }
1144dab5c37SJack F Vogel 
1154dab5c37SJack F Vogel /**
1168cfa0ad2SJack F Vogel  *  e1000_null_read_reg - No-op function, return 0
1178cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1185b426b3eSGuinan Sun  *  @offset: dummy variable
1195b426b3eSGuinan Sun  *  @data: dummy variable
1208cfa0ad2SJack F Vogel  **/
e1000_null_read_reg(struct e1000_hw E1000_UNUSEDARG * hw,u32 E1000_UNUSEDARG offset,u16 E1000_UNUSEDARG * data)1217609433eSJack F Vogel s32 e1000_null_read_reg(struct e1000_hw E1000_UNUSEDARG *hw,
1227609433eSJack F Vogel 			u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG *data)
1238cfa0ad2SJack F Vogel {
1248cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_read_reg");
1258cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1268cfa0ad2SJack F Vogel }
1278cfa0ad2SJack F Vogel 
1288cfa0ad2SJack F Vogel /**
1298cfa0ad2SJack F Vogel  *  e1000_null_phy_generic - No-op function, return void
1308cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1318cfa0ad2SJack F Vogel  **/
e1000_null_phy_generic(struct e1000_hw E1000_UNUSEDARG * hw)1327609433eSJack F Vogel void e1000_null_phy_generic(struct e1000_hw E1000_UNUSEDARG *hw)
1338cfa0ad2SJack F Vogel {
1348cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_phy_generic");
1358cfa0ad2SJack F Vogel 	return;
1368cfa0ad2SJack F Vogel }
1378cfa0ad2SJack F Vogel 
1388cfa0ad2SJack F Vogel /**
1398cfa0ad2SJack F Vogel  *  e1000_null_lplu_state - No-op function, return 0
1408cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1415b426b3eSGuinan Sun  *  @active: dummy variable
1428cfa0ad2SJack F Vogel  **/
e1000_null_lplu_state(struct e1000_hw E1000_UNUSEDARG * hw,bool E1000_UNUSEDARG active)1437609433eSJack F Vogel s32 e1000_null_lplu_state(struct e1000_hw E1000_UNUSEDARG *hw,
1447609433eSJack F Vogel 			  bool E1000_UNUSEDARG active)
1458cfa0ad2SJack F Vogel {
1468cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_lplu_state");
1478cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1488cfa0ad2SJack F Vogel }
1498cfa0ad2SJack F Vogel 
1508cfa0ad2SJack F Vogel /**
1518cfa0ad2SJack F Vogel  *  e1000_null_write_reg - No-op function, return 0
1528cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
1535b426b3eSGuinan Sun  *  @offset: dummy variable
1545b426b3eSGuinan Sun  *  @data: dummy variable
1558cfa0ad2SJack F Vogel  **/
e1000_null_write_reg(struct e1000_hw E1000_UNUSEDARG * hw,u32 E1000_UNUSEDARG offset,u16 E1000_UNUSEDARG data)1567609433eSJack F Vogel s32 e1000_null_write_reg(struct e1000_hw E1000_UNUSEDARG *hw,
1577609433eSJack F Vogel 			 u32 E1000_UNUSEDARG offset, u16 E1000_UNUSEDARG data)
1588cfa0ad2SJack F Vogel {
1598cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_null_write_reg");
1608cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
1618cfa0ad2SJack F Vogel }
1628cfa0ad2SJack F Vogel 
1638cfa0ad2SJack F Vogel /**
164ab5d0362SJack F Vogel  *  e1000_read_i2c_byte_null - No-op function, return 0
165ab5d0362SJack F Vogel  *  @hw: pointer to hardware structure
166ab5d0362SJack F Vogel  *  @byte_offset: byte offset to write
167ab5d0362SJack F Vogel  *  @dev_addr: device address
168ab5d0362SJack F Vogel  *  @data: data value read
169ab5d0362SJack F Vogel  *
170ab5d0362SJack F Vogel  **/
e1000_read_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG * hw,u8 E1000_UNUSEDARG byte_offset,u8 E1000_UNUSEDARG dev_addr,u8 E1000_UNUSEDARG * data)1717609433eSJack F Vogel s32 e1000_read_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
1727609433eSJack F Vogel 			     u8 E1000_UNUSEDARG byte_offset,
1737609433eSJack F Vogel 			     u8 E1000_UNUSEDARG dev_addr,
1747609433eSJack F Vogel 			     u8 E1000_UNUSEDARG *data)
175ab5d0362SJack F Vogel {
176ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_read_i2c_byte_null");
177ab5d0362SJack F Vogel 	return E1000_SUCCESS;
178ab5d0362SJack F Vogel }
179ab5d0362SJack F Vogel 
180ab5d0362SJack F Vogel /**
181ab5d0362SJack F Vogel  *  e1000_write_i2c_byte_null - No-op function, return 0
182ab5d0362SJack F Vogel  *  @hw: pointer to hardware structure
183ab5d0362SJack F Vogel  *  @byte_offset: byte offset to write
184ab5d0362SJack F Vogel  *  @dev_addr: device address
185ab5d0362SJack F Vogel  *  @data: data value to write
186ab5d0362SJack F Vogel  *
187ab5d0362SJack F Vogel  **/
e1000_write_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG * hw,u8 E1000_UNUSEDARG byte_offset,u8 E1000_UNUSEDARG dev_addr,u8 E1000_UNUSEDARG data)1887609433eSJack F Vogel s32 e1000_write_i2c_byte_null(struct e1000_hw E1000_UNUSEDARG *hw,
1897609433eSJack F Vogel 			      u8 E1000_UNUSEDARG byte_offset,
1907609433eSJack F Vogel 			      u8 E1000_UNUSEDARG dev_addr,
1917609433eSJack F Vogel 			      u8 E1000_UNUSEDARG data)
192ab5d0362SJack F Vogel {
193ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_write_i2c_byte_null");
194ab5d0362SJack F Vogel 	return E1000_SUCCESS;
195ab5d0362SJack F Vogel }
196ab5d0362SJack F Vogel 
197ab5d0362SJack F Vogel /**
1988cfa0ad2SJack F Vogel  *  e1000_check_reset_block_generic - Check if PHY reset is blocked
1998cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2008cfa0ad2SJack F Vogel  *
2018cfa0ad2SJack F Vogel  *  Read the PHY management control register and check whether a PHY reset
2028cfa0ad2SJack F Vogel  *  is blocked.  If a reset is not blocked return E1000_SUCCESS, otherwise
2038cfa0ad2SJack F Vogel  *  return E1000_BLK_PHY_RESET (12).
2048cfa0ad2SJack F Vogel  **/
e1000_check_reset_block_generic(struct e1000_hw * hw)2058cfa0ad2SJack F Vogel s32 e1000_check_reset_block_generic(struct e1000_hw *hw)
2068cfa0ad2SJack F Vogel {
2078cfa0ad2SJack F Vogel 	u32 manc;
2088cfa0ad2SJack F Vogel 
2098cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_reset_block");
2108cfa0ad2SJack F Vogel 
2118cfa0ad2SJack F Vogel 	manc = E1000_READ_REG(hw, E1000_MANC);
2128cfa0ad2SJack F Vogel 
2138cfa0ad2SJack F Vogel 	return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
2148cfa0ad2SJack F Vogel 	       E1000_BLK_PHY_RESET : E1000_SUCCESS;
2158cfa0ad2SJack F Vogel }
2168cfa0ad2SJack F Vogel 
2178cfa0ad2SJack F Vogel /**
2188cfa0ad2SJack F Vogel  *  e1000_get_phy_id - Retrieve the PHY ID and revision
2198cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2208cfa0ad2SJack F Vogel  *
2218cfa0ad2SJack F Vogel  *  Reads the PHY registers and stores the PHY ID and possibly the PHY
2228cfa0ad2SJack F Vogel  *  revision in the hardware structure.
2238cfa0ad2SJack F Vogel  **/
e1000_get_phy_id(struct e1000_hw * hw)2248cfa0ad2SJack F Vogel s32 e1000_get_phy_id(struct e1000_hw *hw)
2258cfa0ad2SJack F Vogel {
2268cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2278cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
2288cfa0ad2SJack F Vogel 	u16 phy_id;
2299d81738fSJack F Vogel 	u16 retry_count = 0;
2308cfa0ad2SJack F Vogel 
2318cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_id");
2328cfa0ad2SJack F Vogel 
233ab5d0362SJack F Vogel 	if (!phy->ops.read_reg)
234ab5d0362SJack F Vogel 		return E1000_SUCCESS;
2358cfa0ad2SJack F Vogel 
2369d81738fSJack F Vogel 	while (retry_count < 2) {
2378cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_ID1, &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 << 16);
2428cfa0ad2SJack F Vogel 		usec_delay(20);
2438cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
2448cfa0ad2SJack F Vogel 		if (ret_val)
245ab5d0362SJack F Vogel 			return ret_val;
2468cfa0ad2SJack F Vogel 
2478cfa0ad2SJack F Vogel 		phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
2488cfa0ad2SJack F Vogel 		phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
2498cfa0ad2SJack F Vogel 
2509d81738fSJack F Vogel 		if (phy->id != 0 && phy->id != PHY_REVISION_MASK)
251ab5d0362SJack F Vogel 			return E1000_SUCCESS;
2529d81738fSJack F Vogel 
2539d81738fSJack F Vogel 		retry_count++;
2549d81738fSJack F Vogel 	}
255ab5d0362SJack F Vogel 
256ab5d0362SJack F Vogel 	return E1000_SUCCESS;
2578cfa0ad2SJack F Vogel }
2588cfa0ad2SJack F Vogel 
2598cfa0ad2SJack F Vogel /**
2608cfa0ad2SJack F Vogel  *  e1000_phy_reset_dsp_generic - Reset PHY DSP
2618cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2628cfa0ad2SJack F Vogel  *
2638cfa0ad2SJack F Vogel  *  Reset the digital signal processor.
2648cfa0ad2SJack F Vogel  **/
e1000_phy_reset_dsp_generic(struct e1000_hw * hw)2658cfa0ad2SJack F Vogel s32 e1000_phy_reset_dsp_generic(struct e1000_hw *hw)
2668cfa0ad2SJack F Vogel {
267ab5d0362SJack F Vogel 	s32 ret_val;
2688cfa0ad2SJack F Vogel 
2698cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_reset_dsp_generic");
2708cfa0ad2SJack F Vogel 
271ab5d0362SJack F Vogel 	if (!hw->phy.ops.write_reg)
272ab5d0362SJack F Vogel 		return E1000_SUCCESS;
2738cfa0ad2SJack F Vogel 
2748cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
2758cfa0ad2SJack F Vogel 	if (ret_val)
2768cfa0ad2SJack F Vogel 		return ret_val;
277ab5d0362SJack F Vogel 
278ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
2798cfa0ad2SJack F Vogel }
2808cfa0ad2SJack F Vogel 
2818cfa0ad2SJack F Vogel /**
2828cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_mdic - Read MDI control register
2838cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
2848cfa0ad2SJack F Vogel  *  @offset: register offset to be read
2858cfa0ad2SJack F Vogel  *  @data: pointer to the read data
2868cfa0ad2SJack F Vogel  *
2878cfa0ad2SJack F Vogel  *  Reads the MDI control register in the PHY at offset and stores the
2888cfa0ad2SJack F Vogel  *  information read to data.
2898cfa0ad2SJack F Vogel  **/
e1000_read_phy_reg_mdic(struct e1000_hw * hw,u32 offset,u16 * data)2908cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
2918cfa0ad2SJack F Vogel {
2928cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2938cfa0ad2SJack F Vogel 	u32 i, mdic = 0;
2948cfa0ad2SJack F Vogel 
2958cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_mdic");
2968cfa0ad2SJack F Vogel 
297a69ed8dfSJack F Vogel 	if (offset > MAX_PHY_REG_ADDRESS) {
298a69ed8dfSJack F Vogel 		DEBUGOUT1("PHY Address %d is out of range\n", offset);
299a69ed8dfSJack F Vogel 		return -E1000_ERR_PARAM;
300a69ed8dfSJack F Vogel 	}
301a69ed8dfSJack F Vogel 
3026ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register offset in the MDI
3038cfa0ad2SJack F Vogel 	 * Control register.  The MAC will take care of interfacing with the
3048cfa0ad2SJack F Vogel 	 * PHY to retrieve the desired data.
3058cfa0ad2SJack F Vogel 	 */
3068cfa0ad2SJack F Vogel 	mdic = ((offset << E1000_MDIC_REG_SHIFT) |
3078cfa0ad2SJack F Vogel 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
3088cfa0ad2SJack F Vogel 		(E1000_MDIC_OP_READ));
3098cfa0ad2SJack F Vogel 
3108cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_MDIC, mdic);
3118cfa0ad2SJack F Vogel 
3126ab6bfe3SJack F Vogel 	/* Poll the ready bit to see if the MDI read completed
3138cfa0ad2SJack F Vogel 	 * Increasing the time out as testing showed failures with
3148cfa0ad2SJack F Vogel 	 * the lower time out
3158cfa0ad2SJack F Vogel 	 */
3168cfa0ad2SJack F Vogel 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
3177609433eSJack F Vogel 		usec_delay_irq(50);
3188cfa0ad2SJack F Vogel 		mdic = E1000_READ_REG(hw, E1000_MDIC);
3198cfa0ad2SJack F Vogel 		if (mdic & E1000_MDIC_READY)
3208cfa0ad2SJack F Vogel 			break;
3218cfa0ad2SJack F Vogel 	}
3228cfa0ad2SJack F Vogel 	if (!(mdic & E1000_MDIC_READY)) {
3238cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Read did not complete\n");
324ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3258cfa0ad2SJack F Vogel 	}
3268cfa0ad2SJack F Vogel 	if (mdic & E1000_MDIC_ERROR) {
3278cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Error\n");
328ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3298cfa0ad2SJack F Vogel 	}
3306ab6bfe3SJack F Vogel 	if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
3316ab6bfe3SJack F Vogel 		DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
3326ab6bfe3SJack F Vogel 			  offset,
3336ab6bfe3SJack F Vogel 			  (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
3346ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
3356ab6bfe3SJack F Vogel 	}
3368cfa0ad2SJack F Vogel 	*data = (u16) mdic;
3378cfa0ad2SJack F Vogel 
3386ab6bfe3SJack F Vogel 	/* Allow some time after each MDIC transaction to avoid
3397d9119bdSJack F Vogel 	 * reading duplicate data in the next MDIC transaction.
3407d9119bdSJack F Vogel 	 */
3417d9119bdSJack F Vogel 	if (hw->mac.type == e1000_pch2lan)
3427609433eSJack F Vogel 		usec_delay_irq(100);
3437d9119bdSJack F Vogel 
344ab5d0362SJack F Vogel 	return E1000_SUCCESS;
3458cfa0ad2SJack F Vogel }
3468cfa0ad2SJack F Vogel 
3478cfa0ad2SJack F Vogel /**
3488cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_mdic - Write MDI control register
3498cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
3508cfa0ad2SJack F Vogel  *  @offset: register offset to write to
3518cfa0ad2SJack F Vogel  *  @data: data to write to register at offset
3528cfa0ad2SJack F Vogel  *
3538cfa0ad2SJack F Vogel  *  Writes data to MDI control register in the PHY at offset.
3548cfa0ad2SJack F Vogel  **/
e1000_write_phy_reg_mdic(struct e1000_hw * hw,u32 offset,u16 data)3558cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
3568cfa0ad2SJack F Vogel {
3578cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
3588cfa0ad2SJack F Vogel 	u32 i, mdic = 0;
3598cfa0ad2SJack F Vogel 
3608cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_mdic");
3618cfa0ad2SJack F Vogel 
362a69ed8dfSJack F Vogel 	if (offset > MAX_PHY_REG_ADDRESS) {
363a69ed8dfSJack F Vogel 		DEBUGOUT1("PHY Address %d is out of range\n", offset);
364a69ed8dfSJack F Vogel 		return -E1000_ERR_PARAM;
365a69ed8dfSJack F Vogel 	}
366a69ed8dfSJack F Vogel 
3676ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register offset in the MDI
3688cfa0ad2SJack F Vogel 	 * Control register.  The MAC will take care of interfacing with the
3698cfa0ad2SJack F Vogel 	 * PHY to retrieve the desired data.
3708cfa0ad2SJack F Vogel 	 */
3718cfa0ad2SJack F Vogel 	mdic = (((u32)data) |
3728cfa0ad2SJack F Vogel 		(offset << E1000_MDIC_REG_SHIFT) |
3738cfa0ad2SJack F Vogel 		(phy->addr << E1000_MDIC_PHY_SHIFT) |
3748cfa0ad2SJack F Vogel 		(E1000_MDIC_OP_WRITE));
3758cfa0ad2SJack F Vogel 
3768cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_MDIC, mdic);
3778cfa0ad2SJack F Vogel 
3786ab6bfe3SJack F Vogel 	/* Poll the ready bit to see if the MDI read completed
3798cfa0ad2SJack F Vogel 	 * Increasing the time out as testing showed failures with
3808cfa0ad2SJack F Vogel 	 * the lower time out
3818cfa0ad2SJack F Vogel 	 */
3828cfa0ad2SJack F Vogel 	for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
3837609433eSJack F Vogel 		usec_delay_irq(50);
3848cfa0ad2SJack F Vogel 		mdic = E1000_READ_REG(hw, E1000_MDIC);
3858cfa0ad2SJack F Vogel 		if (mdic & E1000_MDIC_READY)
3868cfa0ad2SJack F Vogel 			break;
3878cfa0ad2SJack F Vogel 	}
3888cfa0ad2SJack F Vogel 	if (!(mdic & E1000_MDIC_READY)) {
3898cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Write did not complete\n");
390ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3918cfa0ad2SJack F Vogel 	}
3928cfa0ad2SJack F Vogel 	if (mdic & E1000_MDIC_ERROR) {
3938cfa0ad2SJack F Vogel 		DEBUGOUT("MDI Error\n");
394ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
3958cfa0ad2SJack F Vogel 	}
3966ab6bfe3SJack F Vogel 	if (((mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT) != offset) {
3976ab6bfe3SJack F Vogel 		DEBUGOUT2("MDI Write offset error - requested %d, returned %d\n",
3986ab6bfe3SJack F Vogel 			  offset,
3996ab6bfe3SJack F Vogel 			  (mdic & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
4006ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
4016ab6bfe3SJack F Vogel 	}
4028cfa0ad2SJack F Vogel 
4036ab6bfe3SJack F Vogel 	/* Allow some time after each MDIC transaction to avoid
4047d9119bdSJack F Vogel 	 * reading duplicate data in the next MDIC transaction.
4057d9119bdSJack F Vogel 	 */
4067d9119bdSJack F Vogel 	if (hw->mac.type == e1000_pch2lan)
4077609433eSJack F Vogel 		usec_delay_irq(100);
4087d9119bdSJack F Vogel 
409ab5d0362SJack F Vogel 	return E1000_SUCCESS;
4108cfa0ad2SJack F Vogel }
4118cfa0ad2SJack F Vogel 
4128cfa0ad2SJack F Vogel /**
4134edd8523SJack F Vogel  *  e1000_read_phy_reg_i2c - Read PHY register using i2c
4144edd8523SJack F Vogel  *  @hw: pointer to the HW structure
4154edd8523SJack F Vogel  *  @offset: register offset to be read
4164edd8523SJack F Vogel  *  @data: pointer to the read data
4174edd8523SJack F Vogel  *
4184edd8523SJack F Vogel  *  Reads the PHY register at offset using the i2c interface and stores the
4194edd8523SJack F Vogel  *  retrieved information in data.
4204edd8523SJack F Vogel  **/
e1000_read_phy_reg_i2c(struct e1000_hw * hw,u32 offset,u16 * data)4214edd8523SJack F Vogel s32 e1000_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
4224edd8523SJack F Vogel {
4234edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
4244edd8523SJack F Vogel 	u32 i, i2ccmd = 0;
4254edd8523SJack F Vogel 
4264edd8523SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_i2c");
4274edd8523SJack F Vogel 
4286ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register address in the I2CCMD
4294edd8523SJack F Vogel 	 * register.  The MAC will take care of interfacing with the
4304edd8523SJack F Vogel 	 * PHY to retrieve the desired data.
4314edd8523SJack F Vogel 	 */
4324edd8523SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
4334edd8523SJack F Vogel 		  (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
4344edd8523SJack F Vogel 		  (E1000_I2CCMD_OPCODE_READ));
4354edd8523SJack F Vogel 
4364edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
4374edd8523SJack F Vogel 
4384edd8523SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
4394edd8523SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
4404edd8523SJack F Vogel 		usec_delay(50);
4414edd8523SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
4424edd8523SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY)
4434edd8523SJack F Vogel 			break;
4444edd8523SJack F Vogel 	}
4454edd8523SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
4464edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Read did not complete\n");
4474edd8523SJack F Vogel 		return -E1000_ERR_PHY;
4484edd8523SJack F Vogel 	}
4494edd8523SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
4504edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
4514edd8523SJack F Vogel 		return -E1000_ERR_PHY;
4524edd8523SJack F Vogel 	}
4534edd8523SJack F Vogel 
4544edd8523SJack F Vogel 	/* Need to byte-swap the 16-bit value. */
4554edd8523SJack F Vogel 	*data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
4564edd8523SJack F Vogel 
4574edd8523SJack F Vogel 	return E1000_SUCCESS;
4584edd8523SJack F Vogel }
4594edd8523SJack F Vogel 
4604edd8523SJack F Vogel /**
4614edd8523SJack F Vogel  *  e1000_write_phy_reg_i2c - Write PHY register using i2c
4624edd8523SJack F Vogel  *  @hw: pointer to the HW structure
4634edd8523SJack F Vogel  *  @offset: register offset to write to
4644edd8523SJack F Vogel  *  @data: data to write at register offset
4654edd8523SJack F Vogel  *
4664edd8523SJack F Vogel  *  Writes the data to PHY register at the offset using the i2c interface.
4674edd8523SJack F Vogel  **/
e1000_write_phy_reg_i2c(struct e1000_hw * hw,u32 offset,u16 data)4684edd8523SJack F Vogel s32 e1000_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
4694edd8523SJack F Vogel {
4704edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
4714edd8523SJack F Vogel 	u32 i, i2ccmd = 0;
4724edd8523SJack F Vogel 	u16 phy_data_swapped;
4734edd8523SJack F Vogel 
4744edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_i2c");
4754edd8523SJack F Vogel 
476e9c7c6f5SGordon Bergling 	/* Prevent overwriting SFP I2C EEPROM which is at A0 address.*/
4774dab5c37SJack F Vogel 	if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) {
4784dab5c37SJack F Vogel 		DEBUGOUT1("PHY I2C Address %d is out of range.\n",
4794dab5c37SJack F Vogel 			  hw->phy.addr);
4804dab5c37SJack F Vogel 		return -E1000_ERR_CONFIG;
4814dab5c37SJack F Vogel 	}
4824dab5c37SJack F Vogel 
4834edd8523SJack F Vogel 	/* Swap the data bytes for the I2C interface */
4844edd8523SJack F Vogel 	phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
4854edd8523SJack F Vogel 
4866ab6bfe3SJack F Vogel 	/* Set up Op-code, Phy Address, and register address in the I2CCMD
4874edd8523SJack F Vogel 	 * register.  The MAC will take care of interfacing with the
4884edd8523SJack F Vogel 	 * PHY to retrieve the desired data.
4894edd8523SJack F Vogel 	 */
4904edd8523SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
4914edd8523SJack F Vogel 		  (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
4924edd8523SJack F Vogel 		  E1000_I2CCMD_OPCODE_WRITE |
4934edd8523SJack F Vogel 		  phy_data_swapped);
4944edd8523SJack F Vogel 
4954edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
4964edd8523SJack F Vogel 
4974edd8523SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
4984edd8523SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
4994edd8523SJack F Vogel 		usec_delay(50);
5004edd8523SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
5014edd8523SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY)
5024edd8523SJack F Vogel 			break;
5034edd8523SJack F Vogel 	}
5044edd8523SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
5054edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Write did not complete\n");
5064edd8523SJack F Vogel 		return -E1000_ERR_PHY;
5074edd8523SJack F Vogel 	}
5084edd8523SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
5094edd8523SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
5104edd8523SJack F Vogel 		return -E1000_ERR_PHY;
5114edd8523SJack F Vogel 	}
5124edd8523SJack F Vogel 
5134edd8523SJack F Vogel 	return E1000_SUCCESS;
5144edd8523SJack F Vogel }
5154edd8523SJack F Vogel 
5164edd8523SJack F Vogel /**
5174dab5c37SJack F Vogel  *  e1000_read_sfp_data_byte - Reads SFP module data.
5184dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
5194dab5c37SJack F Vogel  *  @offset: byte location offset to be read
5204dab5c37SJack F Vogel  *  @data: read data buffer pointer
5214dab5c37SJack F Vogel  *
5224dab5c37SJack F Vogel  *  Reads one byte from SFP module data stored
5234dab5c37SJack F Vogel  *  in SFP resided EEPROM memory or SFP diagnostic area.
5244dab5c37SJack F Vogel  *  Function should be called with
5254dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
5264dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
5274dab5c37SJack F Vogel  *  access
5284dab5c37SJack F Vogel  **/
e1000_read_sfp_data_byte(struct e1000_hw * hw,u16 offset,u8 * data)5294dab5c37SJack F Vogel s32 e1000_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data)
5304dab5c37SJack F Vogel {
5314dab5c37SJack F Vogel 	u32 i = 0;
5324dab5c37SJack F Vogel 	u32 i2ccmd = 0;
5334dab5c37SJack F Vogel 	u32 data_local = 0;
5344dab5c37SJack F Vogel 
5354dab5c37SJack F Vogel 	DEBUGFUNC("e1000_read_sfp_data_byte");
5364dab5c37SJack F Vogel 
5374dab5c37SJack F Vogel 	if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
5384dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD command address exceeds upper limit\n");
5394dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5404dab5c37SJack F Vogel 	}
5414dab5c37SJack F Vogel 
5426ab6bfe3SJack F Vogel 	/* Set up Op-code, EEPROM Address,in the I2CCMD
5434dab5c37SJack F Vogel 	 * register. The MAC will take care of interfacing with the
5444dab5c37SJack F Vogel 	 * EEPROM to retrieve the desired data.
5454dab5c37SJack F Vogel 	 */
5464dab5c37SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
5474dab5c37SJack F Vogel 		  E1000_I2CCMD_OPCODE_READ);
5484dab5c37SJack F Vogel 
5494dab5c37SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
5504dab5c37SJack F Vogel 
5514dab5c37SJack F Vogel 	/* Poll the ready bit to see if the I2C read completed */
5524dab5c37SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
5534dab5c37SJack F Vogel 		usec_delay(50);
5544dab5c37SJack F Vogel 		data_local = E1000_READ_REG(hw, E1000_I2CCMD);
5554dab5c37SJack F Vogel 		if (data_local & E1000_I2CCMD_READY)
5564dab5c37SJack F Vogel 			break;
5574dab5c37SJack F Vogel 	}
5584dab5c37SJack F Vogel 	if (!(data_local & E1000_I2CCMD_READY)) {
5594dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Read did not complete\n");
5604dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5614dab5c37SJack F Vogel 	}
5624dab5c37SJack F Vogel 	if (data_local & E1000_I2CCMD_ERROR) {
5634dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
5644dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5654dab5c37SJack F Vogel 	}
5664dab5c37SJack F Vogel 	*data = (u8) data_local & 0xFF;
5674dab5c37SJack F Vogel 
5684dab5c37SJack F Vogel 	return E1000_SUCCESS;
5694dab5c37SJack F Vogel }
5704dab5c37SJack F Vogel 
5714dab5c37SJack F Vogel /**
5724dab5c37SJack F Vogel  *  e1000_write_sfp_data_byte - Writes SFP module data.
5734dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
5744dab5c37SJack F Vogel  *  @offset: byte location offset to write to
5754dab5c37SJack F Vogel  *  @data: data to write
5764dab5c37SJack F Vogel  *
5774dab5c37SJack F Vogel  *  Writes one byte to SFP module data stored
5784dab5c37SJack F Vogel  *  in SFP resided EEPROM memory or SFP diagnostic area.
5794dab5c37SJack F Vogel  *  Function should be called with
5804dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access
5814dab5c37SJack F Vogel  *  E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters
5824dab5c37SJack F Vogel  *  access
5834dab5c37SJack F Vogel  **/
e1000_write_sfp_data_byte(struct e1000_hw * hw,u16 offset,u8 data)5844dab5c37SJack F Vogel s32 e1000_write_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 data)
5854dab5c37SJack F Vogel {
5864dab5c37SJack F Vogel 	u32 i = 0;
5874dab5c37SJack F Vogel 	u32 i2ccmd = 0;
5884dab5c37SJack F Vogel 	u32 data_local = 0;
5894dab5c37SJack F Vogel 
5904dab5c37SJack F Vogel 	DEBUGFUNC("e1000_write_sfp_data_byte");
5914dab5c37SJack F Vogel 
5924dab5c37SJack F Vogel 	if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) {
5934dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD command address exceeds upper limit\n");
5944dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
5954dab5c37SJack F Vogel 	}
5966ab6bfe3SJack F Vogel 	/* The programming interface is 16 bits wide
5974dab5c37SJack F Vogel 	 * so we need to read the whole word first
5984dab5c37SJack F Vogel 	 * then update appropriate byte lane and write
5994dab5c37SJack F Vogel 	 * the updated word back.
6004dab5c37SJack F Vogel 	 */
6016ab6bfe3SJack F Vogel 	/* Set up Op-code, EEPROM Address,in the I2CCMD
6024dab5c37SJack F Vogel 	 * register. The MAC will take care of interfacing
6034dab5c37SJack F Vogel 	 * with an EEPROM to write the data given.
6044dab5c37SJack F Vogel 	 */
6054dab5c37SJack F Vogel 	i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
6064dab5c37SJack F Vogel 		  E1000_I2CCMD_OPCODE_READ);
6074dab5c37SJack F Vogel 	/* Set a command to read single word */
6084dab5c37SJack F Vogel 	E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
6094dab5c37SJack F Vogel 	for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
6104dab5c37SJack F Vogel 		usec_delay(50);
6116ab6bfe3SJack F Vogel 		/* Poll the ready bit to see if lastly
6124dab5c37SJack F Vogel 		 * launched I2C operation completed
6134dab5c37SJack F Vogel 		 */
6144dab5c37SJack F Vogel 		i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
6154dab5c37SJack F Vogel 		if (i2ccmd & E1000_I2CCMD_READY) {
6164dab5c37SJack F Vogel 			/* Check if this is READ or WRITE phase */
6174dab5c37SJack F Vogel 			if ((i2ccmd & E1000_I2CCMD_OPCODE_READ) ==
6184dab5c37SJack F Vogel 			    E1000_I2CCMD_OPCODE_READ) {
6196ab6bfe3SJack F Vogel 				/* Write the selected byte
6204dab5c37SJack F Vogel 				 * lane and update whole word
6214dab5c37SJack F Vogel 				 */
6224dab5c37SJack F Vogel 				data_local = i2ccmd & 0xFF00;
6236c59e186SGuinan Sun 				data_local |= (u32)data;
6244dab5c37SJack F Vogel 				i2ccmd = ((offset <<
6254dab5c37SJack F Vogel 					E1000_I2CCMD_REG_ADDR_SHIFT) |
6264dab5c37SJack F Vogel 					E1000_I2CCMD_OPCODE_WRITE | data_local);
6274dab5c37SJack F Vogel 				E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
6284dab5c37SJack F Vogel 			} else {
6294dab5c37SJack F Vogel 				break;
6304dab5c37SJack F Vogel 			}
6314dab5c37SJack F Vogel 		}
6324dab5c37SJack F Vogel 	}
6334dab5c37SJack F Vogel 	if (!(i2ccmd & E1000_I2CCMD_READY)) {
6344dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Write did not complete\n");
6354dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
6364dab5c37SJack F Vogel 	}
6374dab5c37SJack F Vogel 	if (i2ccmd & E1000_I2CCMD_ERROR) {
6384dab5c37SJack F Vogel 		DEBUGOUT("I2CCMD Error bit set\n");
6394dab5c37SJack F Vogel 		return -E1000_ERR_PHY;
6404dab5c37SJack F Vogel 	}
6414dab5c37SJack F Vogel 	return E1000_SUCCESS;
6424dab5c37SJack F Vogel }
6434dab5c37SJack F Vogel 
6444dab5c37SJack F Vogel /**
6458cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_m88 - Read m88 PHY register
6468cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
6478cfa0ad2SJack F Vogel  *  @offset: register offset to be read
6488cfa0ad2SJack F Vogel  *  @data: pointer to the read data
6498cfa0ad2SJack F Vogel  *
6508cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
6518cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
6528cfa0ad2SJack F Vogel  *  semaphores before exiting.
6538cfa0ad2SJack F Vogel  **/
e1000_read_phy_reg_m88(struct e1000_hw * hw,u32 offset,u16 * data)6548cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
6558cfa0ad2SJack F Vogel {
656ab5d0362SJack F Vogel 	s32 ret_val;
6578cfa0ad2SJack F Vogel 
6588cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_m88");
6598cfa0ad2SJack F Vogel 
660ab5d0362SJack F Vogel 	if (!hw->phy.ops.acquire)
661ab5d0362SJack F Vogel 		return E1000_SUCCESS;
6628cfa0ad2SJack F Vogel 
6638cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
6648cfa0ad2SJack F Vogel 	if (ret_val)
665ab5d0362SJack F Vogel 		return ret_val;
6668cfa0ad2SJack F Vogel 
667daf9197cSJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
6688cfa0ad2SJack F Vogel 					  data);
6698cfa0ad2SJack F Vogel 
6708cfa0ad2SJack F Vogel 	hw->phy.ops.release(hw);
6718cfa0ad2SJack F Vogel 
6728cfa0ad2SJack F Vogel 	return ret_val;
6738cfa0ad2SJack F Vogel }
6748cfa0ad2SJack F Vogel 
6758cfa0ad2SJack F Vogel /**
6768cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_m88 - Write m88 PHY register
6778cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
6788cfa0ad2SJack F Vogel  *  @offset: register offset to write to
6798cfa0ad2SJack F Vogel  *  @data: data to write at register offset
6808cfa0ad2SJack F Vogel  *
6818cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
6828cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
6838cfa0ad2SJack F Vogel  **/
e1000_write_phy_reg_m88(struct e1000_hw * hw,u32 offset,u16 data)6848cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
6858cfa0ad2SJack F Vogel {
686ab5d0362SJack F Vogel 	s32 ret_val;
6878cfa0ad2SJack F Vogel 
6888cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_m88");
6898cfa0ad2SJack F Vogel 
690ab5d0362SJack F Vogel 	if (!hw->phy.ops.acquire)
691ab5d0362SJack F Vogel 		return E1000_SUCCESS;
6928cfa0ad2SJack F Vogel 
6938cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
6948cfa0ad2SJack F Vogel 	if (ret_val)
695ab5d0362SJack F Vogel 		return ret_val;
6968cfa0ad2SJack F Vogel 
697daf9197cSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
6988cfa0ad2SJack F Vogel 					   data);
6998cfa0ad2SJack F Vogel 
7008cfa0ad2SJack F Vogel 	hw->phy.ops.release(hw);
7018cfa0ad2SJack F Vogel 
7028cfa0ad2SJack F Vogel 	return ret_val;
7038cfa0ad2SJack F Vogel }
7048cfa0ad2SJack F Vogel 
7058cfa0ad2SJack F Vogel /**
7064dab5c37SJack F Vogel  *  e1000_set_page_igp - Set page as on IGP-like PHY(s)
7074dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
7084dab5c37SJack F Vogel  *  @page: page to set (shifted left when necessary)
7094dab5c37SJack F Vogel  *
7104dab5c37SJack F Vogel  *  Sets PHY page required for PHY register access.  Assumes semaphore is
7114dab5c37SJack F Vogel  *  already acquired.  Note, this function sets phy.addr to 1 so the caller
7124dab5c37SJack F Vogel  *  must set it appropriately (if necessary) after this function returns.
7134dab5c37SJack F Vogel  **/
e1000_set_page_igp(struct e1000_hw * hw,u16 page)7144dab5c37SJack F Vogel s32 e1000_set_page_igp(struct e1000_hw *hw, u16 page)
7154dab5c37SJack F Vogel {
7164dab5c37SJack F Vogel 	DEBUGFUNC("e1000_set_page_igp");
7174dab5c37SJack F Vogel 
7184dab5c37SJack F Vogel 	DEBUGOUT1("Setting page 0x%x\n", page);
7194dab5c37SJack F Vogel 
7204dab5c37SJack F Vogel 	hw->phy.addr = 1;
7214dab5c37SJack F Vogel 
7224dab5c37SJack F Vogel 	return e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, page);
7234dab5c37SJack F Vogel }
7244dab5c37SJack F Vogel 
7254dab5c37SJack F Vogel /**
7264edd8523SJack F Vogel  *  __e1000_read_phy_reg_igp - Read igp PHY register
7278cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
7288cfa0ad2SJack F Vogel  *  @offset: register offset to be read
7298cfa0ad2SJack F Vogel  *  @data: pointer to the read data
7304edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
7318cfa0ad2SJack F Vogel  *
7328cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
7334edd8523SJack F Vogel  *  and stores the retrieved information in data.  Release any acquired
7348cfa0ad2SJack F Vogel  *  semaphores before exiting.
7358cfa0ad2SJack F Vogel  **/
__e1000_read_phy_reg_igp(struct e1000_hw * hw,u32 offset,u16 * data,bool locked)7364edd8523SJack F Vogel static s32 __e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
7374edd8523SJack F Vogel 				    bool locked)
7388cfa0ad2SJack F Vogel {
7398cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
7408cfa0ad2SJack F Vogel 
7414edd8523SJack F Vogel 	DEBUGFUNC("__e1000_read_phy_reg_igp");
7428cfa0ad2SJack F Vogel 
7434edd8523SJack F Vogel 	if (!locked) {
744ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
745ab5d0362SJack F Vogel 			return E1000_SUCCESS;
7468cfa0ad2SJack F Vogel 
7478cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
7488cfa0ad2SJack F Vogel 		if (ret_val)
749ab5d0362SJack F Vogel 			return ret_val;
7504edd8523SJack F Vogel 	}
7518cfa0ad2SJack F Vogel 
752ab5d0362SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG)
7538cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw,
7548cfa0ad2SJack F Vogel 						   IGP01E1000_PHY_PAGE_SELECT,
7558cfa0ad2SJack F Vogel 						   (u16)offset);
756ab5d0362SJack F Vogel 	if (!ret_val)
757ab5d0362SJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw,
758ab5d0362SJack F Vogel 						  MAX_PHY_REG_ADDRESS & offset,
7598cfa0ad2SJack F Vogel 						  data);
7604edd8523SJack F Vogel 	if (!locked)
7614edd8523SJack F Vogel 		hw->phy.ops.release(hw);
762ab5d0362SJack F Vogel 
7634edd8523SJack F Vogel 	return ret_val;
7644edd8523SJack F Vogel }
7654edd8523SJack F Vogel 
7664edd8523SJack F Vogel /**
7674edd8523SJack F Vogel  *  e1000_read_phy_reg_igp - Read igp PHY register
7684edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7694edd8523SJack F Vogel  *  @offset: register offset to be read
7704edd8523SJack F Vogel  *  @data: pointer to the read data
7714edd8523SJack F Vogel  *
7724edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset and stores the
7734edd8523SJack F Vogel  *  retrieved information in data.
7744edd8523SJack F Vogel  *  Release the acquired semaphore before exiting.
7754edd8523SJack F Vogel  **/
e1000_read_phy_reg_igp(struct e1000_hw * hw,u32 offset,u16 * data)7764edd8523SJack F Vogel s32 e1000_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
7774edd8523SJack F Vogel {
7781bbdc25fSKevin Bowling 	return __e1000_read_phy_reg_igp(hw, offset, data, false);
7794edd8523SJack F Vogel }
7804edd8523SJack F Vogel 
7814edd8523SJack F Vogel /**
7824edd8523SJack F Vogel  *  e1000_read_phy_reg_igp_locked - Read igp PHY register
7834edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7844edd8523SJack F Vogel  *  @offset: register offset to be read
7854edd8523SJack F Vogel  *  @data: pointer to the read data
7864edd8523SJack F Vogel  *
7874edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
7884edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.
7894edd8523SJack F Vogel  **/
e1000_read_phy_reg_igp_locked(struct e1000_hw * hw,u32 offset,u16 * data)7904edd8523SJack F Vogel s32 e1000_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
7914edd8523SJack F Vogel {
7921bbdc25fSKevin Bowling 	return __e1000_read_phy_reg_igp(hw, offset, data, true);
7934edd8523SJack F Vogel }
7944edd8523SJack F Vogel 
7954edd8523SJack F Vogel /**
7964edd8523SJack F Vogel  *  e1000_write_phy_reg_igp - Write igp PHY register
7974edd8523SJack F Vogel  *  @hw: pointer to the HW structure
7984edd8523SJack F Vogel  *  @offset: register offset to write to
7994edd8523SJack F Vogel  *  @data: data to write at register offset
8004edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
8014edd8523SJack F Vogel  *
8024edd8523SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
8034edd8523SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
8044edd8523SJack F Vogel  **/
__e1000_write_phy_reg_igp(struct e1000_hw * hw,u32 offset,u16 data,bool locked)8054edd8523SJack F Vogel static s32 __e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
8064edd8523SJack F Vogel 				     bool locked)
8074edd8523SJack F Vogel {
8084edd8523SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
8094edd8523SJack F Vogel 
8104edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_igp");
8114edd8523SJack F Vogel 
8124edd8523SJack F Vogel 	if (!locked) {
813ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
814ab5d0362SJack F Vogel 			return E1000_SUCCESS;
8154edd8523SJack F Vogel 
8164edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
8174edd8523SJack F Vogel 		if (ret_val)
818ab5d0362SJack F Vogel 			return ret_val;
8194edd8523SJack F Vogel 	}
8204edd8523SJack F Vogel 
821ab5d0362SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG)
8224edd8523SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw,
8234edd8523SJack F Vogel 						   IGP01E1000_PHY_PAGE_SELECT,
8244edd8523SJack F Vogel 						   (u16)offset);
825ab5d0362SJack F Vogel 	if (!ret_val)
826ab5d0362SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS &
827ab5d0362SJack F Vogel 						       offset,
8284edd8523SJack F Vogel 						   data);
8294edd8523SJack F Vogel 	if (!locked)
8308cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
8318cfa0ad2SJack F Vogel 
8328cfa0ad2SJack F Vogel 	return ret_val;
8338cfa0ad2SJack F Vogel }
8348cfa0ad2SJack F Vogel 
8358cfa0ad2SJack F Vogel /**
8368cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_igp - Write igp PHY register
8378cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
8388cfa0ad2SJack F Vogel  *  @offset: register offset to write to
8398cfa0ad2SJack F Vogel  *  @data: data to write at register offset
8408cfa0ad2SJack F Vogel  *
8414edd8523SJack F Vogel  *  Acquires semaphore then writes the data to PHY register
8428cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
8438cfa0ad2SJack F Vogel  **/
e1000_write_phy_reg_igp(struct e1000_hw * hw,u32 offset,u16 data)8448cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
8458cfa0ad2SJack F Vogel {
8461bbdc25fSKevin Bowling 	return __e1000_write_phy_reg_igp(hw, offset, data, false);
8474edd8523SJack F Vogel }
8484edd8523SJack F Vogel 
8494edd8523SJack F Vogel /**
8504edd8523SJack F Vogel  *  e1000_write_phy_reg_igp_locked - Write igp PHY register
8514edd8523SJack F Vogel  *  @hw: pointer to the HW structure
8524edd8523SJack F Vogel  *  @offset: register offset to write to
8534edd8523SJack F Vogel  *  @data: data to write at register offset
8544edd8523SJack F Vogel  *
8554edd8523SJack F Vogel  *  Writes the data to PHY register at the offset.
8564edd8523SJack F Vogel  *  Assumes semaphore already acquired.
8574edd8523SJack F Vogel  **/
e1000_write_phy_reg_igp_locked(struct e1000_hw * hw,u32 offset,u16 data)8584edd8523SJack F Vogel s32 e1000_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
8594edd8523SJack F Vogel {
8601bbdc25fSKevin Bowling 	return __e1000_write_phy_reg_igp(hw, offset, data, true);
8614edd8523SJack F Vogel }
8624edd8523SJack F Vogel 
8634edd8523SJack F Vogel /**
8644edd8523SJack F Vogel  *  __e1000_read_kmrn_reg - Read kumeran register
8654edd8523SJack F Vogel  *  @hw: pointer to the HW structure
8664edd8523SJack F Vogel  *  @offset: register offset to be read
8674edd8523SJack F Vogel  *  @data: pointer to the read data
8684edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
8694edd8523SJack F Vogel  *
8704edd8523SJack F Vogel  *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
8714edd8523SJack F Vogel  *  using the kumeran interface.  The information retrieved is stored in data.
8724edd8523SJack F Vogel  *  Release any acquired semaphores before exiting.
8734edd8523SJack F Vogel  **/
__e1000_read_kmrn_reg(struct e1000_hw * hw,u32 offset,u16 * data,bool locked)8744edd8523SJack F Vogel static s32 __e1000_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
8754edd8523SJack F Vogel 				 bool locked)
8764edd8523SJack F Vogel {
8774edd8523SJack F Vogel 	u32 kmrnctrlsta;
8788cfa0ad2SJack F Vogel 
8794edd8523SJack F Vogel 	DEBUGFUNC("__e1000_read_kmrn_reg");
8808cfa0ad2SJack F Vogel 
8814edd8523SJack F Vogel 	if (!locked) {
882ab5d0362SJack F Vogel 		s32 ret_val = E1000_SUCCESS;
883ab5d0362SJack F Vogel 
884ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
885ab5d0362SJack F Vogel 			return E1000_SUCCESS;
8868cfa0ad2SJack F Vogel 
8878cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
8888cfa0ad2SJack F Vogel 		if (ret_val)
889ab5d0362SJack F Vogel 			return ret_val;
8908cfa0ad2SJack F Vogel 	}
8918cfa0ad2SJack F Vogel 
8924edd8523SJack F Vogel 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
8934edd8523SJack F Vogel 		       E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
8944edd8523SJack F Vogel 	E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
8954dab5c37SJack F Vogel 	E1000_WRITE_FLUSH(hw);
8968cfa0ad2SJack F Vogel 
8974edd8523SJack F Vogel 	usec_delay(2);
8984edd8523SJack F Vogel 
8994edd8523SJack F Vogel 	kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
9004edd8523SJack F Vogel 	*data = (u16)kmrnctrlsta;
9014edd8523SJack F Vogel 
9024edd8523SJack F Vogel 	if (!locked)
9038cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
9048cfa0ad2SJack F Vogel 
905ab5d0362SJack F Vogel 	return E1000_SUCCESS;
9068cfa0ad2SJack F Vogel }
9078cfa0ad2SJack F Vogel 
9088cfa0ad2SJack F Vogel /**
9098cfa0ad2SJack F Vogel  *  e1000_read_kmrn_reg_generic -  Read kumeran register
9108cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
9118cfa0ad2SJack F Vogel  *  @offset: register offset to be read
9128cfa0ad2SJack F Vogel  *  @data: pointer to the read data
9138cfa0ad2SJack F Vogel  *
9144edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset using the
9154edd8523SJack F Vogel  *  kumeran interface.  The information retrieved is stored in data.
9164edd8523SJack F Vogel  *  Release the acquired semaphore before exiting.
9178cfa0ad2SJack F Vogel  **/
e1000_read_kmrn_reg_generic(struct e1000_hw * hw,u32 offset,u16 * data)9188cfa0ad2SJack F Vogel s32 e1000_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
9198cfa0ad2SJack F Vogel {
9201bbdc25fSKevin Bowling 	return __e1000_read_kmrn_reg(hw, offset, data, false);
9214edd8523SJack F Vogel }
9224edd8523SJack F Vogel 
9234edd8523SJack F Vogel /**
9244edd8523SJack F Vogel  *  e1000_read_kmrn_reg_locked -  Read kumeran register
9254edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9264edd8523SJack F Vogel  *  @offset: register offset to be read
9274edd8523SJack F Vogel  *  @data: pointer to the read data
9284edd8523SJack F Vogel  *
9294edd8523SJack F Vogel  *  Reads the PHY register at offset using the kumeran interface.  The
9304edd8523SJack F Vogel  *  information retrieved is stored in data.
9314edd8523SJack F Vogel  *  Assumes semaphore already acquired.
9324edd8523SJack F Vogel  **/
e1000_read_kmrn_reg_locked(struct e1000_hw * hw,u32 offset,u16 * data)9334edd8523SJack F Vogel s32 e1000_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
9344edd8523SJack F Vogel {
9351bbdc25fSKevin Bowling 	return __e1000_read_kmrn_reg(hw, offset, data, true);
9364edd8523SJack F Vogel }
9374edd8523SJack F Vogel 
9384edd8523SJack F Vogel /**
9394edd8523SJack F Vogel  *  __e1000_write_kmrn_reg - Write kumeran register
9404edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9414edd8523SJack F Vogel  *  @offset: register offset to write to
9424edd8523SJack F Vogel  *  @data: data to write at register offset
9434edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
9444edd8523SJack F Vogel  *
9454edd8523SJack F Vogel  *  Acquires semaphore, if necessary.  Then write the data to PHY register
9464edd8523SJack F Vogel  *  at the offset using the kumeran interface.  Release any acquired semaphores
9474edd8523SJack F Vogel  *  before exiting.
9484edd8523SJack F Vogel  **/
__e1000_write_kmrn_reg(struct e1000_hw * hw,u32 offset,u16 data,bool locked)9494edd8523SJack F Vogel static s32 __e1000_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
9504edd8523SJack F Vogel 				  bool locked)
9514edd8523SJack F Vogel {
9528cfa0ad2SJack F Vogel 	u32 kmrnctrlsta;
9538cfa0ad2SJack F Vogel 
9544edd8523SJack F Vogel 	DEBUGFUNC("e1000_write_kmrn_reg_generic");
9558cfa0ad2SJack F Vogel 
9564edd8523SJack F Vogel 	if (!locked) {
957ab5d0362SJack F Vogel 		s32 ret_val = E1000_SUCCESS;
958ab5d0362SJack F Vogel 
959ab5d0362SJack F Vogel 		if (!hw->phy.ops.acquire)
960ab5d0362SJack F Vogel 			return E1000_SUCCESS;
9618cfa0ad2SJack F Vogel 
9628cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
9638cfa0ad2SJack F Vogel 		if (ret_val)
964ab5d0362SJack F Vogel 			return ret_val;
9654edd8523SJack F Vogel 	}
9668cfa0ad2SJack F Vogel 
9678cfa0ad2SJack F Vogel 	kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
9684edd8523SJack F Vogel 		       E1000_KMRNCTRLSTA_OFFSET) | data;
9698cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
9704dab5c37SJack F Vogel 	E1000_WRITE_FLUSH(hw);
9718cfa0ad2SJack F Vogel 
9728cfa0ad2SJack F Vogel 	usec_delay(2);
9738cfa0ad2SJack F Vogel 
9744edd8523SJack F Vogel 	if (!locked)
9758cfa0ad2SJack F Vogel 		hw->phy.ops.release(hw);
9768cfa0ad2SJack F Vogel 
977ab5d0362SJack F Vogel 	return E1000_SUCCESS;
9788cfa0ad2SJack F Vogel }
9798cfa0ad2SJack F Vogel 
9808cfa0ad2SJack F Vogel /**
9818cfa0ad2SJack F Vogel  *  e1000_write_kmrn_reg_generic -  Write kumeran register
9828cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
9838cfa0ad2SJack F Vogel  *  @offset: register offset to write to
9848cfa0ad2SJack F Vogel  *  @data: data to write at register offset
9858cfa0ad2SJack F Vogel  *
9864edd8523SJack F Vogel  *  Acquires semaphore then writes the data to the PHY register at the offset
9874edd8523SJack F Vogel  *  using the kumeran interface.  Release the acquired semaphore before exiting.
9888cfa0ad2SJack F Vogel  **/
e1000_write_kmrn_reg_generic(struct e1000_hw * hw,u32 offset,u16 data)9898cfa0ad2SJack F Vogel s32 e1000_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
9908cfa0ad2SJack F Vogel {
9911bbdc25fSKevin Bowling 	return __e1000_write_kmrn_reg(hw, offset, data, false);
9924edd8523SJack F Vogel }
9938cfa0ad2SJack F Vogel 
9944edd8523SJack F Vogel /**
9954edd8523SJack F Vogel  *  e1000_write_kmrn_reg_locked -  Write kumeran register
9964edd8523SJack F Vogel  *  @hw: pointer to the HW structure
9974edd8523SJack F Vogel  *  @offset: register offset to write to
9984edd8523SJack F Vogel  *  @data: data to write at register offset
9994edd8523SJack F Vogel  *
10004edd8523SJack F Vogel  *  Write the data to PHY register at the offset using the kumeran interface.
10014edd8523SJack F Vogel  *  Assumes semaphore already acquired.
10024edd8523SJack F Vogel  **/
e1000_write_kmrn_reg_locked(struct e1000_hw * hw,u32 offset,u16 data)10034edd8523SJack F Vogel s32 e1000_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
10044edd8523SJack F Vogel {
10051bbdc25fSKevin Bowling 	return __e1000_write_kmrn_reg(hw, offset, data, true);
10068cfa0ad2SJack F Vogel }
10078cfa0ad2SJack F Vogel 
10088cfa0ad2SJack F Vogel /**
1009ab5d0362SJack F Vogel  *  e1000_set_master_slave_mode - Setup PHY for Master/slave mode
10109d81738fSJack F Vogel  *  @hw: pointer to the HW structure
10119d81738fSJack F Vogel  *
1012ab5d0362SJack F Vogel  *  Sets up Master/slave mode
10139d81738fSJack F Vogel  **/
e1000_set_master_slave_mode(struct e1000_hw * hw)1014ab5d0362SJack F Vogel static s32 e1000_set_master_slave_mode(struct e1000_hw *hw)
10159d81738fSJack F Vogel {
10169d81738fSJack F Vogel 	s32 ret_val;
10179d81738fSJack F Vogel 	u16 phy_data;
10189d81738fSJack F Vogel 
10194dab5c37SJack F Vogel 	/* Resolve Master/Slave mode */
10204dab5c37SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data);
10214dab5c37SJack F Vogel 	if (ret_val)
1022ab5d0362SJack F Vogel 		return ret_val;
10234dab5c37SJack F Vogel 
10244dab5c37SJack F Vogel 	/* load defaults for future use */
10254dab5c37SJack F Vogel 	hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ?
10264dab5c37SJack F Vogel 				   ((phy_data & CR_1000T_MS_VALUE) ?
10274dab5c37SJack F Vogel 				    e1000_ms_force_master :
10284dab5c37SJack F Vogel 				    e1000_ms_force_slave) : e1000_ms_auto;
10294dab5c37SJack F Vogel 
10304dab5c37SJack F Vogel 	switch (hw->phy.ms_type) {
10314dab5c37SJack F Vogel 	case e1000_ms_force_master:
10324dab5c37SJack F Vogel 		phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
10334dab5c37SJack F Vogel 		break;
10344dab5c37SJack F Vogel 	case e1000_ms_force_slave:
10354dab5c37SJack F Vogel 		phy_data |= CR_1000T_MS_ENABLE;
10364dab5c37SJack F Vogel 		phy_data &= ~(CR_1000T_MS_VALUE);
10374dab5c37SJack F Vogel 		break;
10384dab5c37SJack F Vogel 	case e1000_ms_auto:
10394dab5c37SJack F Vogel 		phy_data &= ~CR_1000T_MS_ENABLE;
1040*ddfec1fbSKevin Bowling 		break;
10414dab5c37SJack F Vogel 	default:
10424dab5c37SJack F Vogel 		break;
10434dab5c37SJack F Vogel 	}
10444dab5c37SJack F Vogel 
1045ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data);
1046ab5d0362SJack F Vogel }
10479d81738fSJack F Vogel 
1048ab5d0362SJack F Vogel /**
1049ab5d0362SJack F Vogel  *  e1000_copper_link_setup_82577 - Setup 82577 PHY for copper link
1050ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
1051ab5d0362SJack F Vogel  *
1052ab5d0362SJack F Vogel  *  Sets up Carrier-sense on Transmit and downshift values.
1053ab5d0362SJack F Vogel  **/
e1000_copper_link_setup_82577(struct e1000_hw * hw)1054ab5d0362SJack F Vogel s32 e1000_copper_link_setup_82577(struct e1000_hw *hw)
1055ab5d0362SJack F Vogel {
1056ab5d0362SJack F Vogel 	s32 ret_val;
1057ab5d0362SJack F Vogel 	u16 phy_data;
1058ab5d0362SJack F Vogel 
1059ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_82577");
1060ab5d0362SJack F Vogel 
1061ab5d0362SJack F Vogel 	if (hw->phy.type == e1000_phy_82580) {
1062ab5d0362SJack F Vogel 		ret_val = hw->phy.ops.reset(hw);
1063ab5d0362SJack F Vogel 		if (ret_val) {
1064ab5d0362SJack F Vogel 			DEBUGOUT("Error resetting the PHY.\n");
10659d81738fSJack F Vogel 			return ret_val;
10669d81738fSJack F Vogel 		}
1067ab5d0362SJack F Vogel 	}
1068ab5d0362SJack F Vogel 
10697609433eSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
1070ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, I82577_CFG_REG, &phy_data);
1071ab5d0362SJack F Vogel 	if (ret_val)
1072ab5d0362SJack F Vogel 		return ret_val;
1073ab5d0362SJack F Vogel 
1074ab5d0362SJack F Vogel 	phy_data |= I82577_CFG_ASSERT_CRS_ON_TX;
1075ab5d0362SJack F Vogel 
1076ab5d0362SJack F Vogel 	/* Enable downshift */
1077ab5d0362SJack F Vogel 	phy_data |= I82577_CFG_ENABLE_DOWNSHIFT;
1078ab5d0362SJack F Vogel 
1079ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, I82577_CFG_REG, phy_data);
1080ab5d0362SJack F Vogel 	if (ret_val)
1081ab5d0362SJack F Vogel 		return ret_val;
1082ab5d0362SJack F Vogel 
1083ab5d0362SJack F Vogel 	/* Set MDI/MDIX mode */
1084ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, I82577_PHY_CTRL_2, &phy_data);
1085ab5d0362SJack F Vogel 	if (ret_val)
1086ab5d0362SJack F Vogel 		return ret_val;
1087ab5d0362SJack F Vogel 	phy_data &= ~I82577_PHY_CTRL2_MDIX_CFG_MASK;
10886ab6bfe3SJack F Vogel 	/* Options:
1089ab5d0362SJack F Vogel 	 *   0 - Auto (default)
1090ab5d0362SJack F Vogel 	 *   1 - MDI mode
1091ab5d0362SJack F Vogel 	 *   2 - MDI-X mode
1092ab5d0362SJack F Vogel 	 */
1093ab5d0362SJack F Vogel 	switch (hw->phy.mdix) {
1094ab5d0362SJack F Vogel 	case 1:
1095ab5d0362SJack F Vogel 		break;
1096ab5d0362SJack F Vogel 	case 2:
1097ab5d0362SJack F Vogel 		phy_data |= I82577_PHY_CTRL2_MANUAL_MDIX;
1098ab5d0362SJack F Vogel 		break;
1099ab5d0362SJack F Vogel 	case 0:
1100e05d9788SKevin Bowling 		/* FALLTHROUGH */
1101ab5d0362SJack F Vogel 	default:
1102ab5d0362SJack F Vogel 		phy_data |= I82577_PHY_CTRL2_AUTO_MDI_MDIX;
1103ab5d0362SJack F Vogel 		break;
1104ab5d0362SJack F Vogel 	}
1105ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, I82577_PHY_CTRL_2, phy_data);
1106ab5d0362SJack F Vogel 	if (ret_val)
1107ab5d0362SJack F Vogel 		return ret_val;
1108ab5d0362SJack F Vogel 
1109ab5d0362SJack F Vogel 	return e1000_set_master_slave_mode(hw);
1110ab5d0362SJack F Vogel }
11119d81738fSJack F Vogel 
11129d81738fSJack F Vogel /**
11138cfa0ad2SJack F Vogel  *  e1000_copper_link_setup_m88 - Setup m88 PHY's for copper link
11148cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
11158cfa0ad2SJack F Vogel  *
11168cfa0ad2SJack F Vogel  *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
11178cfa0ad2SJack F Vogel  *  and downshift values are set also.
11188cfa0ad2SJack F Vogel  **/
e1000_copper_link_setup_m88(struct e1000_hw * hw)11198cfa0ad2SJack F Vogel s32 e1000_copper_link_setup_m88(struct e1000_hw *hw)
11208cfa0ad2SJack F Vogel {
11218cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
11228cfa0ad2SJack F Vogel 	s32 ret_val;
11238cfa0ad2SJack F Vogel 	u16 phy_data;
11248cfa0ad2SJack F Vogel 
11258cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_m88");
11268cfa0ad2SJack F Vogel 
11278cfa0ad2SJack F Vogel 
1128a69ed8dfSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
11298cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
11308cfa0ad2SJack F Vogel 	if (ret_val)
1131ab5d0362SJack F Vogel 		return ret_val;
11328cfa0ad2SJack F Vogel 
11337d9119bdSJack F Vogel 	/* For BM PHY this bit is downshift enable */
1134f0ecc46dSJack F Vogel 	if (phy->type != e1000_phy_bm)
1135f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
11368cfa0ad2SJack F Vogel 
11376ab6bfe3SJack F Vogel 	/* Options:
11388cfa0ad2SJack F Vogel 	 *   MDI/MDI-X = 0 (default)
11398cfa0ad2SJack F Vogel 	 *   0 - Auto for all speeds
11408cfa0ad2SJack F Vogel 	 *   1 - MDI mode
11418cfa0ad2SJack F Vogel 	 *   2 - MDI-X mode
11428cfa0ad2SJack F Vogel 	 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
11438cfa0ad2SJack F Vogel 	 */
11448cfa0ad2SJack F Vogel 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
11458cfa0ad2SJack F Vogel 
11468cfa0ad2SJack F Vogel 	switch (phy->mdix) {
11478cfa0ad2SJack F Vogel 	case 1:
11488cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
11498cfa0ad2SJack F Vogel 		break;
11508cfa0ad2SJack F Vogel 	case 2:
11518cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
11528cfa0ad2SJack F Vogel 		break;
11538cfa0ad2SJack F Vogel 	case 3:
11548cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_1000T;
11558cfa0ad2SJack F Vogel 		break;
11568cfa0ad2SJack F Vogel 	case 0:
1157e05d9788SKevin Bowling 		/* FALLTHROUGH */
11588cfa0ad2SJack F Vogel 	default:
11598cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;
11608cfa0ad2SJack F Vogel 		break;
11618cfa0ad2SJack F Vogel 	}
11628cfa0ad2SJack F Vogel 
11636ab6bfe3SJack F Vogel 	/* Options:
11648cfa0ad2SJack F Vogel 	 *   disable_polarity_correction = 0 (default)
11658cfa0ad2SJack F Vogel 	 *       Automatic Correction for Reversed Cable Polarity
11668cfa0ad2SJack F Vogel 	 *   0 - Disabled
11678cfa0ad2SJack F Vogel 	 *   1 - Enabled
11688cfa0ad2SJack F Vogel 	 */
11698cfa0ad2SJack F Vogel 	phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1170ab5d0362SJack F Vogel 	if (phy->disable_polarity_correction)
11718cfa0ad2SJack F Vogel 		phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
11728cfa0ad2SJack F Vogel 
11738cfa0ad2SJack F Vogel 	/* Enable downshift on BM (disabled by default) */
1174ab5d0362SJack F Vogel 	if (phy->type == e1000_phy_bm) {
1175ab5d0362SJack F Vogel 		/* For 82574/82583, first disable then enable downshift */
1176ab5d0362SJack F Vogel 		if (phy->id == BME1000_E_PHY_ID_R2) {
1177ab5d0362SJack F Vogel 			phy_data &= ~BME1000_PSCR_ENABLE_DOWNSHIFT;
1178ab5d0362SJack F Vogel 			ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
1179ab5d0362SJack F Vogel 						     phy_data);
1180ab5d0362SJack F Vogel 			if (ret_val)
1181ab5d0362SJack F Vogel 				return ret_val;
1182ab5d0362SJack F Vogel 			/* Commit the changes. */
1183ab5d0362SJack F Vogel 			ret_val = phy->ops.commit(hw);
1184ab5d0362SJack F Vogel 			if (ret_val) {
1185ab5d0362SJack F Vogel 				DEBUGOUT("Error committing the PHY changes\n");
1186ab5d0362SJack F Vogel 				return ret_val;
1187ab5d0362SJack F Vogel 			}
1188ab5d0362SJack F Vogel 		}
1189ab5d0362SJack F Vogel 
11908cfa0ad2SJack F Vogel 		phy_data |= BME1000_PSCR_ENABLE_DOWNSHIFT;
1191ab5d0362SJack F Vogel 	}
11928cfa0ad2SJack F Vogel 
11938cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
11948cfa0ad2SJack F Vogel 	if (ret_val)
1195ab5d0362SJack F Vogel 		return ret_val;
11968cfa0ad2SJack F Vogel 
11978cfa0ad2SJack F Vogel 	if ((phy->type == e1000_phy_m88) &&
11988cfa0ad2SJack F Vogel 	    (phy->revision < E1000_REVISION_4) &&
11998cfa0ad2SJack F Vogel 	    (phy->id != BME1000_E_PHY_ID_R2)) {
12006ab6bfe3SJack F Vogel 		/* Force TX_CLK in the Extended PHY Specific Control Register
12018cfa0ad2SJack F Vogel 		 * to 25MHz clock.
12028cfa0ad2SJack F Vogel 		 */
1203daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12048cfa0ad2SJack F Vogel 					    &phy_data);
12058cfa0ad2SJack F Vogel 		if (ret_val)
1206ab5d0362SJack F Vogel 			return ret_val;
12078cfa0ad2SJack F Vogel 
12088cfa0ad2SJack F Vogel 		phy_data |= M88E1000_EPSCR_TX_CLK_25;
12098cfa0ad2SJack F Vogel 
12108cfa0ad2SJack F Vogel 		if ((phy->revision == E1000_REVISION_2) &&
12118cfa0ad2SJack F Vogel 		    (phy->id == M88E1111_I_PHY_ID)) {
12128cfa0ad2SJack F Vogel 			/* 82573L PHY - set the downshift counter to 5x. */
12138cfa0ad2SJack F Vogel 			phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
12148cfa0ad2SJack F Vogel 			phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
12158cfa0ad2SJack F Vogel 		} else {
12168cfa0ad2SJack F Vogel 			/* Configure Master and Slave downshift values */
12178cfa0ad2SJack F Vogel 			phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
12188cfa0ad2SJack F Vogel 				     M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
12198cfa0ad2SJack F Vogel 			phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
12208cfa0ad2SJack F Vogel 				     M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
12218cfa0ad2SJack F Vogel 		}
1222daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12238cfa0ad2SJack F Vogel 					     phy_data);
12248cfa0ad2SJack F Vogel 		if (ret_val)
1225ab5d0362SJack F Vogel 			return ret_val;
12268cfa0ad2SJack F Vogel 	}
12278cfa0ad2SJack F Vogel 
12288cfa0ad2SJack F Vogel 	if ((phy->type == e1000_phy_bm) && (phy->id == BME1000_E_PHY_ID_R2)) {
12298cfa0ad2SJack F Vogel 		/* Set PHY page 0, register 29 to 0x0003 */
12308cfa0ad2SJack F Vogel 		ret_val = phy->ops.write_reg(hw, 29, 0x0003);
12318cfa0ad2SJack F Vogel 		if (ret_val)
1232ab5d0362SJack F Vogel 			return ret_val;
12338cfa0ad2SJack F Vogel 
12348cfa0ad2SJack F Vogel 		/* Set PHY page 0, register 30 to 0x0000 */
12358cfa0ad2SJack F Vogel 		ret_val = phy->ops.write_reg(hw, 30, 0x0000);
12368cfa0ad2SJack F Vogel 		if (ret_val)
1237ab5d0362SJack F Vogel 			return ret_val;
12388cfa0ad2SJack F Vogel 	}
12398cfa0ad2SJack F Vogel 
12408cfa0ad2SJack F Vogel 	/* Commit the changes. */
12418cfa0ad2SJack F Vogel 	ret_val = phy->ops.commit(hw);
12428cfa0ad2SJack F Vogel 	if (ret_val) {
12438cfa0ad2SJack F Vogel 		DEBUGOUT("Error committing the PHY changes\n");
1244ab5d0362SJack F Vogel 		return ret_val;
12458cfa0ad2SJack F Vogel 	}
12468cfa0ad2SJack F Vogel 
12479d81738fSJack F Vogel 	if (phy->type == e1000_phy_82578) {
12489d81738fSJack F Vogel 		ret_val = phy->ops.read_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 		/* 82578 PHY - set the downshift count to 1x. */
12549d81738fSJack F Vogel 		phy_data |= I82578_EPSCR_DOWNSHIFT_ENABLE;
12559d81738fSJack F Vogel 		phy_data &= ~I82578_EPSCR_DOWNSHIFT_COUNTER_MASK;
12569d81738fSJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
12579d81738fSJack F Vogel 					     phy_data);
12589d81738fSJack F Vogel 		if (ret_val)
1259ab5d0362SJack F Vogel 			return ret_val;
12609d81738fSJack F Vogel 	}
12619d81738fSJack F Vogel 
1262ab5d0362SJack F Vogel 	return E1000_SUCCESS;
1263ab5d0362SJack F Vogel }
1264ab5d0362SJack F Vogel 
12658cfa0ad2SJack F Vogel /**
1266f0ecc46dSJack F Vogel  *  e1000_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link
1267f0ecc46dSJack F Vogel  *  @hw: pointer to the HW structure
1268f0ecc46dSJack F Vogel  *
1269f0ecc46dSJack F Vogel  *  Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's.
1270f0ecc46dSJack F Vogel  *  Also enables and sets the downshift parameters.
1271f0ecc46dSJack F Vogel  **/
e1000_copper_link_setup_m88_gen2(struct e1000_hw * hw)1272f0ecc46dSJack F Vogel s32 e1000_copper_link_setup_m88_gen2(struct e1000_hw *hw)
1273f0ecc46dSJack F Vogel {
1274f0ecc46dSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
1275f0ecc46dSJack F Vogel 	s32 ret_val;
1276f0ecc46dSJack F Vogel 	u16 phy_data;
1277f0ecc46dSJack F Vogel 
1278f0ecc46dSJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_m88_gen2");
1279f0ecc46dSJack F Vogel 
1280f0ecc46dSJack F Vogel 
1281f0ecc46dSJack F Vogel 	/* Enable CRS on Tx. This must be set for half-duplex operation. */
1282f0ecc46dSJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1283f0ecc46dSJack F Vogel 	if (ret_val)
1284ab5d0362SJack F Vogel 		return ret_val;
1285f0ecc46dSJack F Vogel 
12866ab6bfe3SJack F Vogel 	/* Options:
1287f0ecc46dSJack F Vogel 	 *   MDI/MDI-X = 0 (default)
1288f0ecc46dSJack F Vogel 	 *   0 - Auto for all speeds
1289f0ecc46dSJack F Vogel 	 *   1 - MDI mode
1290f0ecc46dSJack F Vogel 	 *   2 - MDI-X mode
1291f0ecc46dSJack F Vogel 	 *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1292f0ecc46dSJack F Vogel 	 */
1293f0ecc46dSJack F Vogel 	phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1294f0ecc46dSJack F Vogel 
1295f0ecc46dSJack F Vogel 	switch (phy->mdix) {
1296f0ecc46dSJack F Vogel 	case 1:
1297f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1298f0ecc46dSJack F Vogel 		break;
1299f0ecc46dSJack F Vogel 	case 2:
1300f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1301f0ecc46dSJack F Vogel 		break;
1302f0ecc46dSJack F Vogel 	case 3:
1303f0ecc46dSJack F Vogel 		/* M88E1112 does not support this mode) */
1304f0ecc46dSJack F Vogel 		if (phy->id != M88E1112_E_PHY_ID) {
1305f0ecc46dSJack F Vogel 			phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1306f0ecc46dSJack F Vogel 			break;
1307f0ecc46dSJack F Vogel 		}
1308a5b0fd9cSToomas Soome 		/* FALLTHROUGH */
1309f0ecc46dSJack F Vogel 	case 0:
1310e05d9788SKevin Bowling 		/* FALLTHROUGH */
1311f0ecc46dSJack F Vogel 	default:
1312f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1313f0ecc46dSJack F Vogel 		break;
1314f0ecc46dSJack F Vogel 	}
1315f0ecc46dSJack F Vogel 
13166ab6bfe3SJack F Vogel 	/* Options:
1317f0ecc46dSJack F Vogel 	 *   disable_polarity_correction = 0 (default)
1318f0ecc46dSJack F Vogel 	 *       Automatic Correction for Reversed Cable Polarity
1319f0ecc46dSJack F Vogel 	 *   0 - Disabled
1320f0ecc46dSJack F Vogel 	 *   1 - Enabled
1321f0ecc46dSJack F Vogel 	 */
1322f0ecc46dSJack F Vogel 	phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1323ab5d0362SJack F Vogel 	if (phy->disable_polarity_correction)
1324f0ecc46dSJack F Vogel 		phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1325f0ecc46dSJack F Vogel 
1326f0ecc46dSJack F Vogel 	/* Enable downshift and setting it to X6 */
13277609433eSJack F Vogel 	if (phy->id == M88E1543_E_PHY_ID) {
13287609433eSJack F Vogel 		phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE;
13297609433eSJack F Vogel 		ret_val =
13307609433eSJack F Vogel 		    phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
13317609433eSJack F Vogel 		if (ret_val)
13327609433eSJack F Vogel 			return ret_val;
13337609433eSJack F Vogel 
13347609433eSJack F Vogel 		ret_val = phy->ops.commit(hw);
13357609433eSJack F Vogel 		if (ret_val) {
13367609433eSJack F Vogel 			DEBUGOUT("Error committing the PHY changes\n");
13377609433eSJack F Vogel 			return ret_val;
13387609433eSJack F Vogel 		}
13397609433eSJack F Vogel 	}
13407609433eSJack F Vogel 
1341f0ecc46dSJack F Vogel 	phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK;
1342f0ecc46dSJack F Vogel 	phy_data |= I347AT4_PSCR_DOWNSHIFT_6X;
1343f0ecc46dSJack F Vogel 	phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE;
1344f0ecc46dSJack F Vogel 
1345f0ecc46dSJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1346f0ecc46dSJack F Vogel 	if (ret_val)
1347ab5d0362SJack F Vogel 		return ret_val;
1348f0ecc46dSJack F Vogel 
1349f0ecc46dSJack F Vogel 	/* Commit the changes. */
1350f0ecc46dSJack F Vogel 	ret_val = phy->ops.commit(hw);
1351f0ecc46dSJack F Vogel 	if (ret_val) {
1352f0ecc46dSJack F Vogel 		DEBUGOUT("Error committing the PHY changes\n");
1353ab5d0362SJack F Vogel 		return ret_val;
1354f0ecc46dSJack F Vogel 	}
1355f0ecc46dSJack F Vogel 
13567609433eSJack F Vogel 	ret_val = e1000_set_master_slave_mode(hw);
13577609433eSJack F Vogel 	if (ret_val)
13587609433eSJack F Vogel 		return ret_val;
13597609433eSJack F Vogel 
1360ab5d0362SJack F Vogel 	return E1000_SUCCESS;
1361f0ecc46dSJack F Vogel }
1362f0ecc46dSJack F Vogel 
1363f0ecc46dSJack F Vogel /**
13648cfa0ad2SJack F Vogel  *  e1000_copper_link_setup_igp - Setup igp PHY's for copper link
13658cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
13668cfa0ad2SJack F Vogel  *
13678cfa0ad2SJack F Vogel  *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
13688cfa0ad2SJack F Vogel  *  igp PHY's.
13698cfa0ad2SJack F Vogel  **/
e1000_copper_link_setup_igp(struct e1000_hw * hw)13708cfa0ad2SJack F Vogel s32 e1000_copper_link_setup_igp(struct e1000_hw *hw)
13718cfa0ad2SJack F Vogel {
13728cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
13738cfa0ad2SJack F Vogel 	s32 ret_val;
13748cfa0ad2SJack F Vogel 	u16 data;
13758cfa0ad2SJack F Vogel 
13768cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_copper_link_setup_igp");
13778cfa0ad2SJack F Vogel 
13788cfa0ad2SJack F Vogel 
13798cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.reset(hw);
13808cfa0ad2SJack F Vogel 	if (ret_val) {
13818cfa0ad2SJack F Vogel 		DEBUGOUT("Error resetting the PHY.\n");
1382ab5d0362SJack F Vogel 		return ret_val;
13838cfa0ad2SJack F Vogel 	}
13848cfa0ad2SJack F Vogel 
13856ab6bfe3SJack F Vogel 	/* Wait 100ms for MAC to configure PHY from NVM settings, to avoid
13868cfa0ad2SJack F Vogel 	 * timeout issues when LFS is enabled.
13878cfa0ad2SJack F Vogel 	 */
13888cfa0ad2SJack F Vogel 	msec_delay(100);
13898cfa0ad2SJack F Vogel 
13906ab6bfe3SJack F Vogel 	/* The NVM settings will configure LPLU in D3 for
13918cfa0ad2SJack F Vogel 	 * non-IGP1 PHYs.
13928cfa0ad2SJack F Vogel 	 */
13938cfa0ad2SJack F Vogel 	if (phy->type == e1000_phy_igp) {
13948cfa0ad2SJack F Vogel 		/* disable lplu d3 during driver init */
13951bbdc25fSKevin Bowling 		ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
13968cfa0ad2SJack F Vogel 		if (ret_val) {
13978cfa0ad2SJack F Vogel 			DEBUGOUT("Error Disabling LPLU D3\n");
1398ab5d0362SJack F Vogel 			return ret_val;
13998cfa0ad2SJack F Vogel 		}
14008cfa0ad2SJack F Vogel 	}
14018cfa0ad2SJack F Vogel 
14028cfa0ad2SJack F Vogel 	/* disable lplu d0 during driver init */
14038cfa0ad2SJack F Vogel 	if (hw->phy.ops.set_d0_lplu_state) {
14041bbdc25fSKevin Bowling 		ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
14058cfa0ad2SJack F Vogel 		if (ret_val) {
14068cfa0ad2SJack F Vogel 			DEBUGOUT("Error Disabling LPLU D0\n");
1407ab5d0362SJack F Vogel 			return ret_val;
14088cfa0ad2SJack F Vogel 		}
14098cfa0ad2SJack F Vogel 	}
14108cfa0ad2SJack F Vogel 	/* Configure mdi-mdix settings */
14118cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
14128cfa0ad2SJack F Vogel 	if (ret_val)
1413ab5d0362SJack F Vogel 		return ret_val;
14148cfa0ad2SJack F Vogel 
14158cfa0ad2SJack F Vogel 	data &= ~IGP01E1000_PSCR_AUTO_MDIX;
14168cfa0ad2SJack F Vogel 
14178cfa0ad2SJack F Vogel 	switch (phy->mdix) {
14188cfa0ad2SJack F Vogel 	case 1:
14198cfa0ad2SJack F Vogel 		data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
14208cfa0ad2SJack F Vogel 		break;
14218cfa0ad2SJack F Vogel 	case 2:
14228cfa0ad2SJack F Vogel 		data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
14238cfa0ad2SJack F Vogel 		break;
14248cfa0ad2SJack F Vogel 	case 0:
1425e05d9788SKevin Bowling 		/* FALLTHROUGH */
14268cfa0ad2SJack F Vogel 	default:
14278cfa0ad2SJack F Vogel 		data |= IGP01E1000_PSCR_AUTO_MDIX;
14288cfa0ad2SJack F Vogel 		break;
14298cfa0ad2SJack F Vogel 	}
14308cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
14318cfa0ad2SJack F Vogel 	if (ret_val)
1432ab5d0362SJack F Vogel 		return ret_val;
14338cfa0ad2SJack F Vogel 
14348cfa0ad2SJack F Vogel 	/* set auto-master slave resolution settings */
14358cfa0ad2SJack F Vogel 	if (hw->mac.autoneg) {
14366ab6bfe3SJack F Vogel 		/* when autonegotiation advertisement is only 1000Mbps then we
14378cfa0ad2SJack F Vogel 		 * should disable SmartSpeed and enable Auto MasterSlave
14388cfa0ad2SJack F Vogel 		 * resolution as hardware default.
14398cfa0ad2SJack F Vogel 		 */
14408cfa0ad2SJack F Vogel 		if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
14418cfa0ad2SJack F Vogel 			/* Disable SmartSpeed */
14428cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
14438cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
14448cfa0ad2SJack F Vogel 						    &data);
14458cfa0ad2SJack F Vogel 			if (ret_val)
1446ab5d0362SJack F Vogel 				return ret_val;
14478cfa0ad2SJack F Vogel 
14488cfa0ad2SJack F Vogel 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
14498cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
14508cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
14518cfa0ad2SJack F Vogel 						     data);
14528cfa0ad2SJack F Vogel 			if (ret_val)
1453ab5d0362SJack F Vogel 				return ret_val;
14548cfa0ad2SJack F Vogel 
14558cfa0ad2SJack F Vogel 			/* Set auto Master/Slave resolution process */
14568cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
14578cfa0ad2SJack F Vogel 			if (ret_val)
1458ab5d0362SJack F Vogel 				return ret_val;
14598cfa0ad2SJack F Vogel 
14608cfa0ad2SJack F Vogel 			data &= ~CR_1000T_MS_ENABLE;
14618cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
14628cfa0ad2SJack F Vogel 			if (ret_val)
14638cfa0ad2SJack F Vogel 				return ret_val;
14648cfa0ad2SJack F Vogel 		}
14658cfa0ad2SJack F Vogel 
1466ab5d0362SJack F Vogel 		ret_val = e1000_set_master_slave_mode(hw);
14678cfa0ad2SJack F Vogel 	}
14688cfa0ad2SJack F Vogel 
14698cfa0ad2SJack F Vogel 	return ret_val;
14708cfa0ad2SJack F Vogel }
14718cfa0ad2SJack F Vogel 
14728cfa0ad2SJack F Vogel /**
14738cfa0ad2SJack F Vogel  *  e1000_phy_setup_autoneg - Configure PHY for auto-negotiation
14748cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
14758cfa0ad2SJack F Vogel  *
14768cfa0ad2SJack F Vogel  *  Reads the MII auto-neg advertisement register and/or the 1000T control
14778cfa0ad2SJack F Vogel  *  register and if the PHY is already setup for auto-negotiation, then
14788cfa0ad2SJack F Vogel  *  return successful.  Otherwise, setup advertisement and flow control to
14798cfa0ad2SJack F Vogel  *  the appropriate values for the wanted auto-negotiation.
14808cfa0ad2SJack F Vogel  **/
e1000_phy_setup_autoneg(struct e1000_hw * hw)14818cfa0ad2SJack F Vogel s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
14828cfa0ad2SJack F Vogel {
14838cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
14848cfa0ad2SJack F Vogel 	s32 ret_val;
14858cfa0ad2SJack F Vogel 	u16 mii_autoneg_adv_reg;
14868cfa0ad2SJack F Vogel 	u16 mii_1000t_ctrl_reg = 0;
14878cfa0ad2SJack F Vogel 
14888cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_setup_autoneg");
14898cfa0ad2SJack F Vogel 
14908cfa0ad2SJack F Vogel 	phy->autoneg_advertised &= phy->autoneg_mask;
14918cfa0ad2SJack F Vogel 
14928cfa0ad2SJack F Vogel 	/* Read the MII Auto-Neg Advertisement Register (Address 4). */
14938cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
14948cfa0ad2SJack F Vogel 	if (ret_val)
1495ab5d0362SJack F Vogel 		return ret_val;
14968cfa0ad2SJack F Vogel 
14978cfa0ad2SJack F Vogel 	if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
14988cfa0ad2SJack F Vogel 		/* Read the MII 1000Base-T Control Register (Address 9). */
1499daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
15008cfa0ad2SJack F Vogel 					    &mii_1000t_ctrl_reg);
15018cfa0ad2SJack F Vogel 		if (ret_val)
1502ab5d0362SJack F Vogel 			return ret_val;
15038cfa0ad2SJack F Vogel 	}
15048cfa0ad2SJack F Vogel 
15056ab6bfe3SJack F Vogel 	/* Need to parse both autoneg_advertised and fc and set up
15068cfa0ad2SJack F Vogel 	 * the appropriate PHY registers.  First we will parse for
15078cfa0ad2SJack F Vogel 	 * autoneg_advertised software override.  Since we can advertise
15088cfa0ad2SJack F Vogel 	 * a plethora of combinations, we need to check each bit
15098cfa0ad2SJack F Vogel 	 * individually.
15108cfa0ad2SJack F Vogel 	 */
15118cfa0ad2SJack F Vogel 
15126ab6bfe3SJack F Vogel 	/* First we clear all the 10/100 mb speed bits in the Auto-Neg
15138cfa0ad2SJack F Vogel 	 * Advertisement Register (Address 4) and the 1000 mb speed bits in
15148cfa0ad2SJack F Vogel 	 * the  1000Base-T Control Register (Address 9).
15158cfa0ad2SJack F Vogel 	 */
15168cfa0ad2SJack F Vogel 	mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
15178cfa0ad2SJack F Vogel 				 NWAY_AR_100TX_HD_CAPS |
15188cfa0ad2SJack F Vogel 				 NWAY_AR_10T_FD_CAPS   |
15198cfa0ad2SJack F Vogel 				 NWAY_AR_10T_HD_CAPS);
15208cfa0ad2SJack F Vogel 	mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
15218cfa0ad2SJack F Vogel 
15228cfa0ad2SJack F Vogel 	DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
15238cfa0ad2SJack F Vogel 
15248cfa0ad2SJack F Vogel 	/* Do we want to advertise 10 Mb Half Duplex? */
15258cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
15268cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 10mb Half duplex\n");
15278cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
15288cfa0ad2SJack F Vogel 	}
15298cfa0ad2SJack F Vogel 
15308cfa0ad2SJack F Vogel 	/* Do we want to advertise 10 Mb Full Duplex? */
15318cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
15328cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 10mb Full duplex\n");
15338cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
15348cfa0ad2SJack F Vogel 	}
15358cfa0ad2SJack F Vogel 
15368cfa0ad2SJack F Vogel 	/* Do we want to advertise 100 Mb Half Duplex? */
15378cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
15388cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 100mb Half duplex\n");
15398cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
15408cfa0ad2SJack F Vogel 	}
15418cfa0ad2SJack F Vogel 
15428cfa0ad2SJack F Vogel 	/* Do we want to advertise 100 Mb Full Duplex? */
15438cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
15448cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 100mb Full duplex\n");
15458cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
15468cfa0ad2SJack F Vogel 	}
15478cfa0ad2SJack F Vogel 
15488cfa0ad2SJack F Vogel 	/* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1549daf9197cSJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
15508cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
15518cfa0ad2SJack F Vogel 
15528cfa0ad2SJack F Vogel 	/* Do we want to advertise 1000 Mb Full Duplex? */
15538cfa0ad2SJack F Vogel 	if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
15548cfa0ad2SJack F Vogel 		DEBUGOUT("Advertise 1000mb Full duplex\n");
15558cfa0ad2SJack F Vogel 		mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
15568cfa0ad2SJack F Vogel 	}
15578cfa0ad2SJack F Vogel 
15586ab6bfe3SJack F Vogel 	/* Check for a software override of the flow control settings, and
15598cfa0ad2SJack F Vogel 	 * setup the PHY advertisement registers accordingly.  If
15608cfa0ad2SJack F Vogel 	 * auto-negotiation is enabled, then software will have to set the
15618cfa0ad2SJack F Vogel 	 * "PAUSE" bits to the correct value in the Auto-Negotiation
15628cfa0ad2SJack F Vogel 	 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
15638cfa0ad2SJack F Vogel 	 * negotiation.
15648cfa0ad2SJack F Vogel 	 *
15658cfa0ad2SJack F Vogel 	 * The possible values of the "fc" parameter are:
15668cfa0ad2SJack F Vogel 	 *      0:  Flow control is completely disabled
15678cfa0ad2SJack F Vogel 	 *      1:  Rx flow control is enabled (we can receive pause frames
15688cfa0ad2SJack F Vogel 	 *          but not send pause frames).
15698cfa0ad2SJack F Vogel 	 *      2:  Tx flow control is enabled (we can send pause frames
15708cfa0ad2SJack F Vogel 	 *          but we do not support receiving pause frames).
15718cfa0ad2SJack F Vogel 	 *      3:  Both Rx and Tx flow control (symmetric) are enabled.
15728cfa0ad2SJack F Vogel 	 *  other:  No software override.  The flow control configuration
15738cfa0ad2SJack F Vogel 	 *          in the EEPROM is used.
15748cfa0ad2SJack F Vogel 	 */
1575daf9197cSJack F Vogel 	switch (hw->fc.current_mode) {
15768cfa0ad2SJack F Vogel 	case e1000_fc_none:
15776ab6bfe3SJack F Vogel 		/* Flow control (Rx & Tx) is completely disabled by a
15788cfa0ad2SJack F Vogel 		 * software over-ride.
15798cfa0ad2SJack F Vogel 		 */
15808cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
15818cfa0ad2SJack F Vogel 		break;
15828cfa0ad2SJack F Vogel 	case e1000_fc_rx_pause:
15836ab6bfe3SJack F Vogel 		/* Rx Flow control is enabled, and Tx Flow control is
15848cfa0ad2SJack F Vogel 		 * disabled, by a software over-ride.
15858cfa0ad2SJack F Vogel 		 *
15868cfa0ad2SJack F Vogel 		 * Since there really isn't a way to advertise that we are
15878cfa0ad2SJack F Vogel 		 * capable of Rx Pause ONLY, we will advertise that we
15888cfa0ad2SJack F Vogel 		 * support both symmetric and asymmetric Rx PAUSE.  Later
15898cfa0ad2SJack F Vogel 		 * (in e1000_config_fc_after_link_up) we will disable the
15908cfa0ad2SJack F Vogel 		 * hw's ability to send PAUSE frames.
15918cfa0ad2SJack F Vogel 		 */
15928cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
15938cfa0ad2SJack F Vogel 		break;
15948cfa0ad2SJack F Vogel 	case e1000_fc_tx_pause:
15956ab6bfe3SJack F Vogel 		/* Tx Flow control is enabled, and Rx Flow control is
15968cfa0ad2SJack F Vogel 		 * disabled, by a software over-ride.
15978cfa0ad2SJack F Vogel 		 */
15988cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
15998cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
16008cfa0ad2SJack F Vogel 		break;
16018cfa0ad2SJack F Vogel 	case e1000_fc_full:
16026ab6bfe3SJack F Vogel 		/* Flow control (both Rx and Tx) is enabled by a software
16038cfa0ad2SJack F Vogel 		 * over-ride.
16048cfa0ad2SJack F Vogel 		 */
16058cfa0ad2SJack F Vogel 		mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
16068cfa0ad2SJack F Vogel 		break;
16078cfa0ad2SJack F Vogel 	default:
16088cfa0ad2SJack F Vogel 		DEBUGOUT("Flow control param set incorrectly\n");
1609ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
16108cfa0ad2SJack F Vogel 	}
16118cfa0ad2SJack F Vogel 
16128cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
16138cfa0ad2SJack F Vogel 	if (ret_val)
1614ab5d0362SJack F Vogel 		return ret_val;
16158cfa0ad2SJack F Vogel 
16168cfa0ad2SJack F Vogel 	DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
16178cfa0ad2SJack F Vogel 
1618ab5d0362SJack F Vogel 	if (phy->autoneg_mask & ADVERTISE_1000_FULL)
16194dab5c37SJack F Vogel 		ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
16208cfa0ad2SJack F Vogel 					     mii_1000t_ctrl_reg);
1621ab5d0362SJack F Vogel 
1622ab5d0362SJack F Vogel 	return ret_val;
16238cfa0ad2SJack F Vogel }
16248cfa0ad2SJack F Vogel 
1625ab5d0362SJack F Vogel /**
1626ab5d0362SJack F Vogel  *  e1000_copper_link_autoneg - Setup/Enable autoneg for copper link
1627ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
1628ab5d0362SJack F Vogel  *
1629ab5d0362SJack F Vogel  *  Performs initial bounds checking on autoneg advertisement parameter, then
1630ab5d0362SJack F Vogel  *  configure to advertise the full capability.  Setup the PHY to autoneg
1631ab5d0362SJack F Vogel  *  and restart the negotiation process between the link partner.  If
1632ab5d0362SJack F Vogel  *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
1633ab5d0362SJack F Vogel  **/
e1000_copper_link_autoneg(struct e1000_hw * hw)1634ab5d0362SJack F Vogel s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1635ab5d0362SJack F Vogel {
1636ab5d0362SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
1637ab5d0362SJack F Vogel 	s32 ret_val;
1638ab5d0362SJack F Vogel 	u16 phy_ctrl;
1639ab5d0362SJack F Vogel 
1640ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_copper_link_autoneg");
1641ab5d0362SJack F Vogel 
16426ab6bfe3SJack F Vogel 	/* Perform some bounds checking on the autoneg advertisement
1643ab5d0362SJack F Vogel 	 * parameter.
1644ab5d0362SJack F Vogel 	 */
1645ab5d0362SJack F Vogel 	phy->autoneg_advertised &= phy->autoneg_mask;
1646ab5d0362SJack F Vogel 
16476ab6bfe3SJack F Vogel 	/* If autoneg_advertised is zero, we assume it was not defaulted
1648ab5d0362SJack F Vogel 	 * by the calling code so we set to advertise full capability.
1649ab5d0362SJack F Vogel 	 */
1650ab5d0362SJack F Vogel 	if (!phy->autoneg_advertised)
1651ab5d0362SJack F Vogel 		phy->autoneg_advertised = phy->autoneg_mask;
1652ab5d0362SJack F Vogel 
1653ab5d0362SJack F Vogel 	DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1654ab5d0362SJack F Vogel 	ret_val = e1000_phy_setup_autoneg(hw);
1655ab5d0362SJack F Vogel 	if (ret_val) {
1656ab5d0362SJack F Vogel 		DEBUGOUT("Error Setting up Auto-Negotiation\n");
1657ab5d0362SJack F Vogel 		return ret_val;
1658ab5d0362SJack F Vogel 	}
1659ab5d0362SJack F Vogel 	DEBUGOUT("Restarting Auto-Neg\n");
1660ab5d0362SJack F Vogel 
16616ab6bfe3SJack F Vogel 	/* Restart auto-negotiation by setting the Auto Neg Enable bit and
1662ab5d0362SJack F Vogel 	 * the Auto Neg Restart bit in the PHY control register.
1663ab5d0362SJack F Vogel 	 */
1664ab5d0362SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
1665ab5d0362SJack F Vogel 	if (ret_val)
1666ab5d0362SJack F Vogel 		return ret_val;
1667ab5d0362SJack F Vogel 
1668ab5d0362SJack F Vogel 	phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1669ab5d0362SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
1670ab5d0362SJack F Vogel 	if (ret_val)
1671ab5d0362SJack F Vogel 		return ret_val;
1672ab5d0362SJack F Vogel 
16736ab6bfe3SJack F Vogel 	/* Does the user want to wait for Auto-Neg to complete here, or
1674ab5d0362SJack F Vogel 	 * check at a later time (for example, callback routine).
1675ab5d0362SJack F Vogel 	 */
1676ab5d0362SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
16776ab6bfe3SJack F Vogel 		ret_val = e1000_wait_autoneg(hw);
1678ab5d0362SJack F Vogel 		if (ret_val) {
1679ab5d0362SJack F Vogel 			DEBUGOUT("Error while waiting for autoneg to complete\n");
1680ab5d0362SJack F Vogel 			return ret_val;
1681ab5d0362SJack F Vogel 		}
1682ab5d0362SJack F Vogel 	}
1683ab5d0362SJack F Vogel 
16841bbdc25fSKevin Bowling 	hw->mac.get_link_status = true;
1685ab5d0362SJack F Vogel 
16868cfa0ad2SJack F Vogel 	return ret_val;
16878cfa0ad2SJack F Vogel }
16888cfa0ad2SJack F Vogel 
16898cfa0ad2SJack F Vogel /**
16908cfa0ad2SJack F Vogel  *  e1000_setup_copper_link_generic - Configure copper link settings
16918cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
16928cfa0ad2SJack F Vogel  *
16938cfa0ad2SJack F Vogel  *  Calls the appropriate function to configure the link for auto-neg or forced
16948cfa0ad2SJack F Vogel  *  speed and duplex.  Then we check for link, once link is established calls
16958cfa0ad2SJack F Vogel  *  to configure collision distance and flow control are called.  If link is
16968cfa0ad2SJack F Vogel  *  not established, we return -E1000_ERR_PHY (-2).
16978cfa0ad2SJack F Vogel  **/
e1000_setup_copper_link_generic(struct e1000_hw * hw)16988cfa0ad2SJack F Vogel s32 e1000_setup_copper_link_generic(struct e1000_hw *hw)
16998cfa0ad2SJack F Vogel {
17008cfa0ad2SJack F Vogel 	s32 ret_val;
1701089cdb39SAndrzej Ostruszka 	bool link = true;
17028cfa0ad2SJack F Vogel 
17038cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_setup_copper_link_generic");
17048cfa0ad2SJack F Vogel 
17058cfa0ad2SJack F Vogel 	if (hw->mac.autoneg) {
17066ab6bfe3SJack F Vogel 		/* Setup autoneg and flow control advertisement and perform
17078cfa0ad2SJack F Vogel 		 * autonegotiation.
17088cfa0ad2SJack F Vogel 		 */
17098cfa0ad2SJack F Vogel 		ret_val = e1000_copper_link_autoneg(hw);
17108cfa0ad2SJack F Vogel 		if (ret_val)
1711ab5d0362SJack F Vogel 			return ret_val;
17128cfa0ad2SJack F Vogel 	} else {
17136ab6bfe3SJack F Vogel 		/* PHY will be set to 10H, 10F, 100H or 100F
17148cfa0ad2SJack F Vogel 		 * depending on user settings.
17158cfa0ad2SJack F Vogel 		 */
17168cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing Speed and Duplex\n");
17178cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.force_speed_duplex(hw);
17188cfa0ad2SJack F Vogel 		if (ret_val) {
17198cfa0ad2SJack F Vogel 			DEBUGOUT("Error Forcing Speed and Duplex\n");
1720ab5d0362SJack F Vogel 			return ret_val;
17218cfa0ad2SJack F Vogel 		}
17228cfa0ad2SJack F Vogel 	}
17238cfa0ad2SJack F Vogel 
17246ab6bfe3SJack F Vogel 	/* Check link status. Wait up to 100 microseconds for link to become
17258cfa0ad2SJack F Vogel 	 * valid.
17268cfa0ad2SJack F Vogel 	 */
17274dab5c37SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
17288cfa0ad2SJack F Vogel 					     &link);
17298cfa0ad2SJack F Vogel 	if (ret_val)
1730ab5d0362SJack F Vogel 		return ret_val;
17318cfa0ad2SJack F Vogel 
17328cfa0ad2SJack F Vogel 	if (link) {
17338cfa0ad2SJack F Vogel 		DEBUGOUT("Valid link established!!!\n");
1734ab5d0362SJack F Vogel 		hw->mac.ops.config_collision_dist(hw);
17358cfa0ad2SJack F Vogel 		ret_val = e1000_config_fc_after_link_up_generic(hw);
17368cfa0ad2SJack F Vogel 	} else {
17378cfa0ad2SJack F Vogel 		DEBUGOUT("Unable to establish link!!!\n");
17388cfa0ad2SJack F Vogel 	}
17398cfa0ad2SJack F Vogel 
17408cfa0ad2SJack F Vogel 	return ret_val;
17418cfa0ad2SJack F Vogel }
17428cfa0ad2SJack F Vogel 
17438cfa0ad2SJack F Vogel /**
17448cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
17458cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
17468cfa0ad2SJack F Vogel  *
17478cfa0ad2SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.  Clears the
17488cfa0ad2SJack F Vogel  *  auto-crossover to force MDI manually.  Waits for link and returns
17498cfa0ad2SJack F Vogel  *  successful if link up is successful, else -E1000_ERR_PHY (-2).
17508cfa0ad2SJack F Vogel  **/
e1000_phy_force_speed_duplex_igp(struct e1000_hw * hw)17518cfa0ad2SJack F Vogel s32 e1000_phy_force_speed_duplex_igp(struct e1000_hw *hw)
17528cfa0ad2SJack F Vogel {
17538cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
17548cfa0ad2SJack F Vogel 	s32 ret_val;
17558cfa0ad2SJack F Vogel 	u16 phy_data;
17568cfa0ad2SJack F Vogel 	bool link;
17578cfa0ad2SJack F Vogel 
17588cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_igp");
17598cfa0ad2SJack F Vogel 
17608cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
17618cfa0ad2SJack F Vogel 	if (ret_val)
1762ab5d0362SJack F Vogel 		return ret_val;
17638cfa0ad2SJack F Vogel 
17648cfa0ad2SJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
17658cfa0ad2SJack F Vogel 
17668cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
17678cfa0ad2SJack F Vogel 	if (ret_val)
1768ab5d0362SJack F Vogel 		return ret_val;
17698cfa0ad2SJack F Vogel 
17706ab6bfe3SJack F Vogel 	/* Clear Auto-Crossover to force MDI manually.  IGP requires MDI
17718cfa0ad2SJack F Vogel 	 * forced whenever speed and duplex are forced.
17728cfa0ad2SJack F Vogel 	 */
17738cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
17748cfa0ad2SJack F Vogel 	if (ret_val)
1775ab5d0362SJack F Vogel 		return ret_val;
17768cfa0ad2SJack F Vogel 
17778cfa0ad2SJack F Vogel 	phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
17788cfa0ad2SJack F Vogel 	phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
17798cfa0ad2SJack F Vogel 
17808cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
17818cfa0ad2SJack F Vogel 	if (ret_val)
1782ab5d0362SJack F Vogel 		return ret_val;
17838cfa0ad2SJack F Vogel 
17848cfa0ad2SJack F Vogel 	DEBUGOUT1("IGP PSCR: %X\n", phy_data);
17858cfa0ad2SJack F Vogel 
17868cfa0ad2SJack F Vogel 	usec_delay(1);
17878cfa0ad2SJack F Vogel 
17888cfa0ad2SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
17898cfa0ad2SJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
17908cfa0ad2SJack F Vogel 
17914dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
17924dab5c37SJack F Vogel 						     100000, &link);
17938cfa0ad2SJack F Vogel 		if (ret_val)
1794ab5d0362SJack F Vogel 			return ret_val;
17958cfa0ad2SJack F Vogel 
1796daf9197cSJack F Vogel 		if (!link)
17978cfa0ad2SJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
17988cfa0ad2SJack F Vogel 
17998cfa0ad2SJack F Vogel 		/* Try once more */
18004dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
18014dab5c37SJack F Vogel 						     100000, &link);
18028cfa0ad2SJack F Vogel 	}
18038cfa0ad2SJack F Vogel 
18048cfa0ad2SJack F Vogel 	return ret_val;
18058cfa0ad2SJack F Vogel }
18068cfa0ad2SJack F Vogel 
18078cfa0ad2SJack F Vogel /**
18088cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
18098cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
18108cfa0ad2SJack F Vogel  *
18118cfa0ad2SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.  Clears the
18128cfa0ad2SJack F Vogel  *  auto-crossover to force MDI manually.  Resets the PHY to commit the
18138cfa0ad2SJack F Vogel  *  changes.  If time expires while waiting for link up, we reset the DSP.
18148cfa0ad2SJack F Vogel  *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
18158cfa0ad2SJack F Vogel  *  successful completion, else return corresponding error code.
18168cfa0ad2SJack F Vogel  **/
e1000_phy_force_speed_duplex_m88(struct e1000_hw * hw)18178cfa0ad2SJack F Vogel s32 e1000_phy_force_speed_duplex_m88(struct e1000_hw *hw)
18188cfa0ad2SJack F Vogel {
18198cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
18208cfa0ad2SJack F Vogel 	s32 ret_val;
18218cfa0ad2SJack F Vogel 	u16 phy_data;
18228cfa0ad2SJack F Vogel 	bool link;
18238cfa0ad2SJack F Vogel 
18248cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_m88");
18258cfa0ad2SJack F Vogel 
18266ab6bfe3SJack F Vogel 	/* I210 and I211 devices support Auto-Crossover in forced operation. */
18276ab6bfe3SJack F Vogel 	if (phy->type != e1000_phy_i210) {
18286ab6bfe3SJack F Vogel 		/* Clear Auto-Crossover to force MDI manually.  M88E1000
18296ab6bfe3SJack F Vogel 		 * requires MDI forced whenever speed and duplex are forced.
18308cfa0ad2SJack F Vogel 		 */
18316ab6bfe3SJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL,
18326ab6bfe3SJack F Vogel 					    &phy_data);
18338cfa0ad2SJack F Vogel 		if (ret_val)
1834ab5d0362SJack F Vogel 			return ret_val;
18358cfa0ad2SJack F Vogel 
18368cfa0ad2SJack F Vogel 		phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
18376ab6bfe3SJack F Vogel 		ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL,
18386ab6bfe3SJack F Vogel 					     phy_data);
18398cfa0ad2SJack F Vogel 		if (ret_val)
1840ab5d0362SJack F Vogel 			return ret_val;
18418cfa0ad2SJack F Vogel 
18428cfa0ad2SJack F Vogel 		DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
1843c80429ceSEric Joyner 	}
18448cfa0ad2SJack F Vogel 
18458cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
18468cfa0ad2SJack F Vogel 	if (ret_val)
1847ab5d0362SJack F Vogel 		return ret_val;
18488cfa0ad2SJack F Vogel 
18498cfa0ad2SJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
18508cfa0ad2SJack F Vogel 
18518cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
18528cfa0ad2SJack F Vogel 	if (ret_val)
1853ab5d0362SJack F Vogel 		return ret_val;
18548cfa0ad2SJack F Vogel 
18558cfa0ad2SJack F Vogel 	/* Reset the phy to commit changes. */
18568cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.commit(hw);
18578cfa0ad2SJack F Vogel 	if (ret_val)
1858ab5d0362SJack F Vogel 		return ret_val;
18598cfa0ad2SJack F Vogel 
18608cfa0ad2SJack F Vogel 	if (phy->autoneg_wait_to_complete) {
18618cfa0ad2SJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
18628cfa0ad2SJack F Vogel 
1863daf9197cSJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1864daf9197cSJack F Vogel 						     100000, &link);
18658cfa0ad2SJack F Vogel 		if (ret_val)
1866ab5d0362SJack F Vogel 			return ret_val;
18678cfa0ad2SJack F Vogel 
18688cfa0ad2SJack F Vogel 		if (!link) {
18691bbdc25fSKevin Bowling 			bool reset_dsp = true;
1870ab5d0362SJack F Vogel 
1871ab5d0362SJack F Vogel 			switch (hw->phy.id) {
1872ab5d0362SJack F Vogel 			case I347AT4_E_PHY_ID:
1873ab5d0362SJack F Vogel 			case M88E1340M_E_PHY_ID:
1874ab5d0362SJack F Vogel 			case M88E1112_E_PHY_ID:
18757609433eSJack F Vogel 			case M88E1543_E_PHY_ID:
18767609433eSJack F Vogel 			case M88E1512_E_PHY_ID:
1877ab5d0362SJack F Vogel 			case I210_I_PHY_ID:
18781bbdc25fSKevin Bowling 				reset_dsp = false;
1879ab5d0362SJack F Vogel 				break;
1880ab5d0362SJack F Vogel 			default:
1881ab5d0362SJack F Vogel 				if (hw->phy.type != e1000_phy_m88)
18821bbdc25fSKevin Bowling 					reset_dsp = false;
1883ab5d0362SJack F Vogel 				break;
1884ab5d0362SJack F Vogel 			}
1885ab5d0362SJack F Vogel 
1886ab5d0362SJack F Vogel 			if (!reset_dsp) {
18874edd8523SJack F Vogel 				DEBUGOUT("Link taking longer than expected.\n");
18884edd8523SJack F Vogel 			} else {
18896ab6bfe3SJack F Vogel 				/* We didn't get link.
18908cfa0ad2SJack F Vogel 				 * Reset the DSP and cross our fingers.
18918cfa0ad2SJack F Vogel 				 */
18928cfa0ad2SJack F Vogel 				ret_val = phy->ops.write_reg(hw,
18938cfa0ad2SJack F Vogel 						M88E1000_PHY_PAGE_SELECT,
18948cfa0ad2SJack F Vogel 						0x001d);
18958cfa0ad2SJack F Vogel 				if (ret_val)
1896ab5d0362SJack F Vogel 					return ret_val;
18978cfa0ad2SJack F Vogel 				ret_val = e1000_phy_reset_dsp_generic(hw);
18988cfa0ad2SJack F Vogel 				if (ret_val)
1899ab5d0362SJack F Vogel 					return ret_val;
19008cfa0ad2SJack F Vogel 			}
19014edd8523SJack F Vogel 		}
19028cfa0ad2SJack F Vogel 
19038cfa0ad2SJack F Vogel 		/* Try once more */
1904daf9197cSJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1905daf9197cSJack F Vogel 						     100000, &link);
19068cfa0ad2SJack F Vogel 		if (ret_val)
1907ab5d0362SJack F Vogel 			return ret_val;
19088cfa0ad2SJack F Vogel 	}
19098cfa0ad2SJack F Vogel 
1910ab5d0362SJack F Vogel 	if (hw->phy.type != e1000_phy_m88)
1911ab5d0362SJack F Vogel 		return E1000_SUCCESS;
1912ab5d0362SJack F Vogel 
1913ab5d0362SJack F Vogel 	if (hw->phy.id == I347AT4_E_PHY_ID ||
19141fd3c44fSJack F Vogel 		hw->phy.id == M88E1340M_E_PHY_ID ||
1915f0ecc46dSJack F Vogel 		hw->phy.id == M88E1112_E_PHY_ID)
1916ab5d0362SJack F Vogel 		return E1000_SUCCESS;
1917ab5d0362SJack F Vogel 	if (hw->phy.id == I210_I_PHY_ID)
1918ab5d0362SJack F Vogel 		return E1000_SUCCESS;
19197609433eSJack F Vogel 	if ((hw->phy.id == M88E1543_E_PHY_ID) ||
19207609433eSJack F Vogel 	    (hw->phy.id == M88E1512_E_PHY_ID))
19217609433eSJack F Vogel 		return E1000_SUCCESS;
19228cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
19238cfa0ad2SJack F Vogel 	if (ret_val)
1924ab5d0362SJack F Vogel 		return ret_val;
19258cfa0ad2SJack F Vogel 
19266ab6bfe3SJack F Vogel 	/* Resetting the phy means we need to re-force TX_CLK in the
19278cfa0ad2SJack F Vogel 	 * Extended PHY Specific Control Register to 25MHz clock from
19288cfa0ad2SJack F Vogel 	 * the reset value of 2.5MHz.
19298cfa0ad2SJack F Vogel 	 */
19308cfa0ad2SJack F Vogel 	phy_data |= M88E1000_EPSCR_TX_CLK_25;
19318cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
19328cfa0ad2SJack F Vogel 	if (ret_val)
1933ab5d0362SJack F Vogel 		return ret_val;
19348cfa0ad2SJack F Vogel 
19356ab6bfe3SJack F Vogel 	/* In addition, we must re-enable CRS on Tx for both half and full
19368cfa0ad2SJack F Vogel 	 * duplex.
19378cfa0ad2SJack F Vogel 	 */
19388cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
19398cfa0ad2SJack F Vogel 	if (ret_val)
1940ab5d0362SJack F Vogel 		return ret_val;
19418cfa0ad2SJack F Vogel 
19428cfa0ad2SJack F Vogel 	phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
19438cfa0ad2SJack F Vogel 	ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
19448cfa0ad2SJack F Vogel 
19458cfa0ad2SJack F Vogel 	return ret_val;
19468cfa0ad2SJack F Vogel }
19478cfa0ad2SJack F Vogel 
19488cfa0ad2SJack F Vogel /**
19499d81738fSJack F Vogel  *  e1000_phy_force_speed_duplex_ife - Force PHY speed & duplex
19509d81738fSJack F Vogel  *  @hw: pointer to the HW structure
19519d81738fSJack F Vogel  *
19529d81738fSJack F Vogel  *  Forces the speed and duplex settings of the PHY.
19539d81738fSJack F Vogel  *  This is a function pointer entry point only called by
19549d81738fSJack F Vogel  *  PHY setup routines.
19559d81738fSJack F Vogel  **/
e1000_phy_force_speed_duplex_ife(struct e1000_hw * hw)19569d81738fSJack F Vogel s32 e1000_phy_force_speed_duplex_ife(struct e1000_hw *hw)
19579d81738fSJack F Vogel {
19589d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
19599d81738fSJack F Vogel 	s32 ret_val;
19609d81738fSJack F Vogel 	u16 data;
19619d81738fSJack F Vogel 	bool link;
19629d81738fSJack F Vogel 
19639d81738fSJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_ife");
19649d81738fSJack F Vogel 
19659d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
19669d81738fSJack F Vogel 	if (ret_val)
1967ab5d0362SJack F Vogel 		return ret_val;
19689d81738fSJack F Vogel 
19699d81738fSJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &data);
19709d81738fSJack F Vogel 
19719d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
19729d81738fSJack F Vogel 	if (ret_val)
1973ab5d0362SJack F Vogel 		return ret_val;
19749d81738fSJack F Vogel 
19759d81738fSJack F Vogel 	/* Disable MDI-X support for 10/100 */
19769d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
19779d81738fSJack F Vogel 	if (ret_val)
1978ab5d0362SJack F Vogel 		return ret_val;
19799d81738fSJack F Vogel 
19809d81738fSJack F Vogel 	data &= ~IFE_PMC_AUTO_MDIX;
19819d81738fSJack F Vogel 	data &= ~IFE_PMC_FORCE_MDIX;
19829d81738fSJack F Vogel 
19839d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
19849d81738fSJack F Vogel 	if (ret_val)
1985ab5d0362SJack F Vogel 		return ret_val;
19869d81738fSJack F Vogel 
19879d81738fSJack F Vogel 	DEBUGOUT1("IFE PMC: %X\n", data);
19889d81738fSJack F Vogel 
19899d81738fSJack F Vogel 	usec_delay(1);
19909d81738fSJack F Vogel 
19919d81738fSJack F Vogel 	if (phy->autoneg_wait_to_complete) {
19929d81738fSJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
19939d81738fSJack F Vogel 
19944dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
19954dab5c37SJack F Vogel 						     100000, &link);
19969d81738fSJack F Vogel 		if (ret_val)
1997ab5d0362SJack F Vogel 			return ret_val;
19989d81738fSJack F Vogel 
19999d81738fSJack F Vogel 		if (!link)
20009d81738fSJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
20019d81738fSJack F Vogel 
20029d81738fSJack F Vogel 		/* Try once more */
20034dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
20044dab5c37SJack F Vogel 						     100000, &link);
20059d81738fSJack F Vogel 		if (ret_val)
2006ab5d0362SJack F Vogel 			return ret_val;
20079d81738fSJack F Vogel 	}
20089d81738fSJack F Vogel 
2009ab5d0362SJack F Vogel 	return E1000_SUCCESS;
20109d81738fSJack F Vogel }
20119d81738fSJack F Vogel 
20129d81738fSJack F Vogel /**
20138cfa0ad2SJack F Vogel  *  e1000_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
20148cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
20158cfa0ad2SJack F Vogel  *  @phy_ctrl: pointer to current value of PHY_CONTROL
20168cfa0ad2SJack F Vogel  *
20178cfa0ad2SJack F Vogel  *  Forces speed and duplex on the PHY by doing the following: disable flow
20188cfa0ad2SJack F Vogel  *  control, force speed/duplex on the MAC, disable auto speed detection,
20198cfa0ad2SJack F Vogel  *  disable auto-negotiation, configure duplex, configure speed, configure
20208cfa0ad2SJack F Vogel  *  the collision distance, write configuration to CTRL register.  The
20218cfa0ad2SJack F Vogel  *  caller must write to the PHY_CONTROL register for these settings to
2022f7c32ed6Sbetterentley  *  take effect.
20238cfa0ad2SJack F Vogel  **/
e1000_phy_force_speed_duplex_setup(struct e1000_hw * hw,u16 * phy_ctrl)20248cfa0ad2SJack F Vogel void e1000_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
20258cfa0ad2SJack F Vogel {
20268cfa0ad2SJack F Vogel 	struct e1000_mac_info *mac = &hw->mac;
20278cfa0ad2SJack F Vogel 	u32 ctrl;
20288cfa0ad2SJack F Vogel 
20298cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_setup");
20308cfa0ad2SJack F Vogel 
20318cfa0ad2SJack F Vogel 	/* Turn off flow control when forcing speed/duplex */
2032daf9197cSJack F Vogel 	hw->fc.current_mode = e1000_fc_none;
20338cfa0ad2SJack F Vogel 
20348cfa0ad2SJack F Vogel 	/* Force speed/duplex on the mac */
20358cfa0ad2SJack F Vogel 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
20368cfa0ad2SJack F Vogel 	ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
20378cfa0ad2SJack F Vogel 	ctrl &= ~E1000_CTRL_SPD_SEL;
20388cfa0ad2SJack F Vogel 
20398cfa0ad2SJack F Vogel 	/* Disable Auto Speed Detection */
20408cfa0ad2SJack F Vogel 	ctrl &= ~E1000_CTRL_ASDE;
20418cfa0ad2SJack F Vogel 
20428cfa0ad2SJack F Vogel 	/* Disable autoneg on the phy */
20438cfa0ad2SJack F Vogel 	*phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
20448cfa0ad2SJack F Vogel 
20458cfa0ad2SJack F Vogel 	/* Forcing Full or Half Duplex? */
20468cfa0ad2SJack F Vogel 	if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
20478cfa0ad2SJack F Vogel 		ctrl &= ~E1000_CTRL_FD;
20488cfa0ad2SJack F Vogel 		*phy_ctrl &= ~MII_CR_FULL_DUPLEX;
20498cfa0ad2SJack F Vogel 		DEBUGOUT("Half Duplex\n");
20508cfa0ad2SJack F Vogel 	} else {
20518cfa0ad2SJack F Vogel 		ctrl |= E1000_CTRL_FD;
20528cfa0ad2SJack F Vogel 		*phy_ctrl |= MII_CR_FULL_DUPLEX;
20538cfa0ad2SJack F Vogel 		DEBUGOUT("Full Duplex\n");
20548cfa0ad2SJack F Vogel 	}
20558cfa0ad2SJack F Vogel 
20568cfa0ad2SJack F Vogel 	/* Forcing 10mb or 100mb? */
20578cfa0ad2SJack F Vogel 	if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
20588cfa0ad2SJack F Vogel 		ctrl |= E1000_CTRL_SPD_100;
20598cfa0ad2SJack F Vogel 		*phy_ctrl |= MII_CR_SPEED_100;
20606ab6bfe3SJack F Vogel 		*phy_ctrl &= ~MII_CR_SPEED_1000;
20618cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing 100mb\n");
20628cfa0ad2SJack F Vogel 	} else {
20638cfa0ad2SJack F Vogel 		ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
20648cfa0ad2SJack F Vogel 		*phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
20658cfa0ad2SJack F Vogel 		DEBUGOUT("Forcing 10mb\n");
20668cfa0ad2SJack F Vogel 	}
20678cfa0ad2SJack F Vogel 
2068ab5d0362SJack F Vogel 	hw->mac.ops.config_collision_dist(hw);
20698cfa0ad2SJack F Vogel 
20708cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20718cfa0ad2SJack F Vogel }
20728cfa0ad2SJack F Vogel 
20738cfa0ad2SJack F Vogel /**
20748cfa0ad2SJack F Vogel  *  e1000_set_d3_lplu_state_generic - Sets low power link up state for D3
20758cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
20768cfa0ad2SJack F Vogel  *  @active: boolean used to enable/disable lplu
20778cfa0ad2SJack F Vogel  *
20788cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns 1
20798cfa0ad2SJack F Vogel  *
20808cfa0ad2SJack F Vogel  *  The low power link up (lplu) state is set to the power management level D3
20811bbdc25fSKevin Bowling  *  and SmartSpeed is disabled when active is true, else clear lplu for D3
20828cfa0ad2SJack F Vogel  *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
20838cfa0ad2SJack F Vogel  *  is used during Dx states where the power conservation is most important.
20848cfa0ad2SJack F Vogel  *  During driver activity, SmartSpeed should be enabled so performance is
20858cfa0ad2SJack F Vogel  *  maintained.
20868cfa0ad2SJack F Vogel  **/
e1000_set_d3_lplu_state_generic(struct e1000_hw * hw,bool active)20878cfa0ad2SJack F Vogel s32 e1000_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
20888cfa0ad2SJack F Vogel {
20898cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2090ab5d0362SJack F Vogel 	s32 ret_val;
20918cfa0ad2SJack F Vogel 	u16 data;
20928cfa0ad2SJack F Vogel 
20938cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_set_d3_lplu_state_generic");
20948cfa0ad2SJack F Vogel 
2095ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
2096ab5d0362SJack F Vogel 		return E1000_SUCCESS;
20978cfa0ad2SJack F Vogel 
20988cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
20998cfa0ad2SJack F Vogel 	if (ret_val)
2100ab5d0362SJack F Vogel 		return ret_val;
21018cfa0ad2SJack F Vogel 
21028cfa0ad2SJack F Vogel 	if (!active) {
21038cfa0ad2SJack F Vogel 		data &= ~IGP02E1000_PM_D3_LPLU;
2104daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
21058cfa0ad2SJack F Vogel 					     data);
21068cfa0ad2SJack F Vogel 		if (ret_val)
2107ab5d0362SJack F Vogel 			return ret_val;
21086ab6bfe3SJack F Vogel 		/* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
21098cfa0ad2SJack F Vogel 		 * during Dx states where the power conservation is most
21108cfa0ad2SJack F Vogel 		 * important.  During driver activity we should enable
21118cfa0ad2SJack F Vogel 		 * SmartSpeed, so performance is maintained.
21128cfa0ad2SJack F Vogel 		 */
21138cfa0ad2SJack F Vogel 		if (phy->smart_speed == e1000_smart_speed_on) {
21148cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
21158cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
21168cfa0ad2SJack F Vogel 						    &data);
21178cfa0ad2SJack F Vogel 			if (ret_val)
2118ab5d0362SJack F Vogel 				return ret_val;
21198cfa0ad2SJack F Vogel 
21208cfa0ad2SJack F Vogel 			data |= IGP01E1000_PSCFR_SMART_SPEED;
21218cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
21228cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
21238cfa0ad2SJack F Vogel 						     data);
21248cfa0ad2SJack F Vogel 			if (ret_val)
2125ab5d0362SJack F Vogel 				return ret_val;
21268cfa0ad2SJack F Vogel 		} else if (phy->smart_speed == e1000_smart_speed_off) {
21278cfa0ad2SJack F Vogel 			ret_val = phy->ops.read_reg(hw,
21288cfa0ad2SJack F Vogel 						    IGP01E1000_PHY_PORT_CONFIG,
21298cfa0ad2SJack F Vogel 						    &data);
21308cfa0ad2SJack F Vogel 			if (ret_val)
2131ab5d0362SJack F Vogel 				return ret_val;
21328cfa0ad2SJack F Vogel 
21338cfa0ad2SJack F Vogel 			data &= ~IGP01E1000_PSCFR_SMART_SPEED;
21348cfa0ad2SJack F Vogel 			ret_val = phy->ops.write_reg(hw,
21358cfa0ad2SJack F Vogel 						     IGP01E1000_PHY_PORT_CONFIG,
21368cfa0ad2SJack F Vogel 						     data);
21378cfa0ad2SJack F Vogel 			if (ret_val)
2138ab5d0362SJack F Vogel 				return ret_val;
21398cfa0ad2SJack F Vogel 		}
21408cfa0ad2SJack F Vogel 	} else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
21418cfa0ad2SJack F Vogel 		   (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
21428cfa0ad2SJack F Vogel 		   (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
21438cfa0ad2SJack F Vogel 		data |= IGP02E1000_PM_D3_LPLU;
2144daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
21458cfa0ad2SJack F Vogel 					     data);
21468cfa0ad2SJack F Vogel 		if (ret_val)
2147ab5d0362SJack F Vogel 			return ret_val;
21488cfa0ad2SJack F Vogel 
21498cfa0ad2SJack F Vogel 		/* When LPLU is enabled, we should disable SmartSpeed */
2150daf9197cSJack F Vogel 		ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
21518cfa0ad2SJack F Vogel 					    &data);
21528cfa0ad2SJack F Vogel 		if (ret_val)
2153ab5d0362SJack F Vogel 			return ret_val;
21548cfa0ad2SJack F Vogel 
21558cfa0ad2SJack F Vogel 		data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2156daf9197cSJack F Vogel 		ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
21578cfa0ad2SJack F Vogel 					     data);
21588cfa0ad2SJack F Vogel 	}
21598cfa0ad2SJack F Vogel 
21608cfa0ad2SJack F Vogel 	return ret_val;
21618cfa0ad2SJack F Vogel }
21628cfa0ad2SJack F Vogel 
21638cfa0ad2SJack F Vogel /**
21648cfa0ad2SJack F Vogel  *  e1000_check_downshift_generic - Checks whether a downshift in speed occurred
21658cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
21668cfa0ad2SJack F Vogel  *
21678cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns 1
21688cfa0ad2SJack F Vogel  *
21698cfa0ad2SJack F Vogel  *  A downshift is detected by querying the PHY link health.
21708cfa0ad2SJack F Vogel  **/
e1000_check_downshift_generic(struct e1000_hw * hw)21718cfa0ad2SJack F Vogel s32 e1000_check_downshift_generic(struct e1000_hw *hw)
21728cfa0ad2SJack F Vogel {
21738cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
21748cfa0ad2SJack F Vogel 	s32 ret_val;
21758cfa0ad2SJack F Vogel 	u16 phy_data, offset, mask;
21768cfa0ad2SJack F Vogel 
21778cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_downshift_generic");
21788cfa0ad2SJack F Vogel 
21798cfa0ad2SJack F Vogel 	switch (phy->type) {
2180ab5d0362SJack F Vogel 	case e1000_phy_i210:
21818cfa0ad2SJack F Vogel 	case e1000_phy_m88:
21828cfa0ad2SJack F Vogel 	case e1000_phy_gg82563:
21838cfa0ad2SJack F Vogel 	case e1000_phy_bm:
21849d81738fSJack F Vogel 	case e1000_phy_82578:
21858cfa0ad2SJack F Vogel 		offset = M88E1000_PHY_SPEC_STATUS;
21868cfa0ad2SJack F Vogel 		mask = M88E1000_PSSR_DOWNSHIFT;
21878cfa0ad2SJack F Vogel 		break;
21888cfa0ad2SJack F Vogel 	case e1000_phy_igp:
21894edd8523SJack F Vogel 	case e1000_phy_igp_2:
21908cfa0ad2SJack F Vogel 	case e1000_phy_igp_3:
21918cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_LINK_HEALTH;
21928cfa0ad2SJack F Vogel 		mask = IGP01E1000_PLHR_SS_DOWNGRADE;
21938cfa0ad2SJack F Vogel 		break;
21948cfa0ad2SJack F Vogel 	default:
21958cfa0ad2SJack F Vogel 		/* speed downshift not supported */
21961bbdc25fSKevin Bowling 		phy->speed_downgraded = false;
2197ab5d0362SJack F Vogel 		return E1000_SUCCESS;
21988cfa0ad2SJack F Vogel 	}
21998cfa0ad2SJack F Vogel 
22008cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &phy_data);
22018cfa0ad2SJack F Vogel 
22028cfa0ad2SJack F Vogel 	if (!ret_val)
2203ab5d0362SJack F Vogel 		phy->speed_downgraded = !!(phy_data & mask);
22048cfa0ad2SJack F Vogel 
22058cfa0ad2SJack F Vogel 	return ret_val;
22068cfa0ad2SJack F Vogel }
22078cfa0ad2SJack F Vogel 
22088cfa0ad2SJack F Vogel /**
22098cfa0ad2SJack F Vogel  *  e1000_check_polarity_m88 - Checks the polarity.
22108cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
22118cfa0ad2SJack F Vogel  *
22128cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
22138cfa0ad2SJack F Vogel  *
22148cfa0ad2SJack F Vogel  *  Polarity is determined based on the PHY specific status register.
22158cfa0ad2SJack F Vogel  **/
e1000_check_polarity_m88(struct e1000_hw * hw)22168cfa0ad2SJack F Vogel s32 e1000_check_polarity_m88(struct e1000_hw *hw)
22178cfa0ad2SJack F Vogel {
22188cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22198cfa0ad2SJack F Vogel 	s32 ret_val;
22208cfa0ad2SJack F Vogel 	u16 data;
22218cfa0ad2SJack F Vogel 
22228cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_polarity_m88");
22238cfa0ad2SJack F Vogel 
22248cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
22258cfa0ad2SJack F Vogel 
22268cfa0ad2SJack F Vogel 	if (!ret_val)
22277609433eSJack F Vogel 		phy->cable_polarity = ((data & M88E1000_PSSR_REV_POLARITY)
22288cfa0ad2SJack F Vogel 				       ? e1000_rev_polarity_reversed
22297609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
22308cfa0ad2SJack F Vogel 
22318cfa0ad2SJack F Vogel 	return ret_val;
22328cfa0ad2SJack F Vogel }
22338cfa0ad2SJack F Vogel 
22348cfa0ad2SJack F Vogel /**
22358cfa0ad2SJack F Vogel  *  e1000_check_polarity_igp - Checks the polarity.
22368cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
22378cfa0ad2SJack F Vogel  *
22388cfa0ad2SJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
22398cfa0ad2SJack F Vogel  *
22408cfa0ad2SJack F Vogel  *  Polarity is determined based on the PHY port status register, and the
22418cfa0ad2SJack F Vogel  *  current speed (since there is no polarity at 100Mbps).
22428cfa0ad2SJack F Vogel  **/
e1000_check_polarity_igp(struct e1000_hw * hw)22438cfa0ad2SJack F Vogel s32 e1000_check_polarity_igp(struct e1000_hw *hw)
22448cfa0ad2SJack F Vogel {
22458cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22468cfa0ad2SJack F Vogel 	s32 ret_val;
22478cfa0ad2SJack F Vogel 	u16 data, offset, mask;
22488cfa0ad2SJack F Vogel 
22498cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_check_polarity_igp");
22508cfa0ad2SJack F Vogel 
22516ab6bfe3SJack F Vogel 	/* Polarity is determined based on the speed of
22528cfa0ad2SJack F Vogel 	 * our connection.
22538cfa0ad2SJack F Vogel 	 */
22548cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
22558cfa0ad2SJack F Vogel 	if (ret_val)
2256ab5d0362SJack F Vogel 		return ret_val;
22578cfa0ad2SJack F Vogel 
22588cfa0ad2SJack F Vogel 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
22598cfa0ad2SJack F Vogel 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
22608cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_PCS_INIT_REG;
22618cfa0ad2SJack F Vogel 		mask = IGP01E1000_PHY_POLARITY_MASK;
22628cfa0ad2SJack F Vogel 	} else {
22636ab6bfe3SJack F Vogel 		/* This really only applies to 10Mbps since
22648cfa0ad2SJack F Vogel 		 * there is no polarity for 100Mbps (always 0).
22658cfa0ad2SJack F Vogel 		 */
22668cfa0ad2SJack F Vogel 		offset = IGP01E1000_PHY_PORT_STATUS;
22678cfa0ad2SJack F Vogel 		mask = IGP01E1000_PSSR_POLARITY_REVERSED;
22688cfa0ad2SJack F Vogel 	}
22698cfa0ad2SJack F Vogel 
22708cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &data);
22718cfa0ad2SJack F Vogel 
22728cfa0ad2SJack F Vogel 	if (!ret_val)
22737609433eSJack F Vogel 		phy->cable_polarity = ((data & mask)
22748cfa0ad2SJack F Vogel 				       ? e1000_rev_polarity_reversed
22757609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
22768cfa0ad2SJack F Vogel 
22778cfa0ad2SJack F Vogel 	return ret_val;
22788cfa0ad2SJack F Vogel }
22798cfa0ad2SJack F Vogel 
22808cfa0ad2SJack F Vogel /**
22819d81738fSJack F Vogel  *  e1000_check_polarity_ife - Check cable polarity for IFE PHY
22829d81738fSJack F Vogel  *  @hw: pointer to the HW structure
22839d81738fSJack F Vogel  *
22849d81738fSJack F Vogel  *  Polarity is determined on the polarity reversal feature being enabled.
22859d81738fSJack F Vogel  **/
e1000_check_polarity_ife(struct e1000_hw * hw)22869d81738fSJack F Vogel s32 e1000_check_polarity_ife(struct e1000_hw *hw)
22879d81738fSJack F Vogel {
22889d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
22899d81738fSJack F Vogel 	s32 ret_val;
22909d81738fSJack F Vogel 	u16 phy_data, offset, mask;
22919d81738fSJack F Vogel 
22929d81738fSJack F Vogel 	DEBUGFUNC("e1000_check_polarity_ife");
22939d81738fSJack F Vogel 
22946ab6bfe3SJack F Vogel 	/* Polarity is determined based on the reversal feature being enabled.
22959d81738fSJack F Vogel 	 */
22969d81738fSJack F Vogel 	if (phy->polarity_correction) {
22979d81738fSJack F Vogel 		offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
22989d81738fSJack F Vogel 		mask = IFE_PESC_POLARITY_REVERSED;
22999d81738fSJack F Vogel 	} else {
23009d81738fSJack F Vogel 		offset = IFE_PHY_SPECIAL_CONTROL;
23019d81738fSJack F Vogel 		mask = IFE_PSC_FORCE_POLARITY;
23029d81738fSJack F Vogel 	}
23039d81738fSJack F Vogel 
23049d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, offset, &phy_data);
23059d81738fSJack F Vogel 
23069d81738fSJack F Vogel 	if (!ret_val)
23077609433eSJack F Vogel 		phy->cable_polarity = ((phy_data & mask)
23089d81738fSJack F Vogel 				       ? e1000_rev_polarity_reversed
23097609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
23109d81738fSJack F Vogel 
23119d81738fSJack F Vogel 	return ret_val;
23129d81738fSJack F Vogel }
23139d81738fSJack F Vogel 
23149d81738fSJack F Vogel /**
23156ab6bfe3SJack F Vogel  *  e1000_wait_autoneg - Wait for auto-neg completion
23168cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
23178cfa0ad2SJack F Vogel  *
23188cfa0ad2SJack F Vogel  *  Waits for auto-negotiation to complete or for the auto-negotiation time
23198cfa0ad2SJack F Vogel  *  limit to expire, which ever happens first.
23208cfa0ad2SJack F Vogel  **/
e1000_wait_autoneg(struct e1000_hw * hw)23216ab6bfe3SJack F Vogel static s32 e1000_wait_autoneg(struct e1000_hw *hw)
23228cfa0ad2SJack F Vogel {
23238cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
23248cfa0ad2SJack F Vogel 	u16 i, phy_status;
23258cfa0ad2SJack F Vogel 
23266ab6bfe3SJack F Vogel 	DEBUGFUNC("e1000_wait_autoneg");
23278cfa0ad2SJack F Vogel 
2328ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
23298cfa0ad2SJack F Vogel 		return E1000_SUCCESS;
23308cfa0ad2SJack F Vogel 
23318cfa0ad2SJack F Vogel 	/* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
23328cfa0ad2SJack F Vogel 	for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
23338cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23348cfa0ad2SJack F Vogel 		if (ret_val)
23358cfa0ad2SJack F Vogel 			break;
23368cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23378cfa0ad2SJack F Vogel 		if (ret_val)
23388cfa0ad2SJack F Vogel 			break;
23398cfa0ad2SJack F Vogel 		if (phy_status & MII_SR_AUTONEG_COMPLETE)
23408cfa0ad2SJack F Vogel 			break;
23418cfa0ad2SJack F Vogel 		msec_delay(100);
23428cfa0ad2SJack F Vogel 	}
23438cfa0ad2SJack F Vogel 
23446ab6bfe3SJack F Vogel 	/* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
23458cfa0ad2SJack F Vogel 	 * has completed.
23468cfa0ad2SJack F Vogel 	 */
23478cfa0ad2SJack F Vogel 	return ret_val;
23488cfa0ad2SJack F Vogel }
23498cfa0ad2SJack F Vogel 
23508cfa0ad2SJack F Vogel /**
23518cfa0ad2SJack F Vogel  *  e1000_phy_has_link_generic - Polls PHY for link
23528cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
23538cfa0ad2SJack F Vogel  *  @iterations: number of times to poll for link
23548cfa0ad2SJack F Vogel  *  @usec_interval: delay between polling attempts
23558cfa0ad2SJack F Vogel  *  @success: pointer to whether polling was successful or not
23568cfa0ad2SJack F Vogel  *
23578cfa0ad2SJack F Vogel  *  Polls the PHY status register for link, 'iterations' number of times.
23588cfa0ad2SJack F Vogel  **/
e1000_phy_has_link_generic(struct e1000_hw * hw,u32 iterations,u32 usec_interval,bool * success)23598cfa0ad2SJack F Vogel s32 e1000_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
23608cfa0ad2SJack F Vogel 			       u32 usec_interval, bool *success)
23618cfa0ad2SJack F Vogel {
23628cfa0ad2SJack F Vogel 	s32 ret_val = E1000_SUCCESS;
23638cfa0ad2SJack F Vogel 	u16 i, phy_status;
23648cfa0ad2SJack F Vogel 
23658cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_has_link_generic");
23668cfa0ad2SJack F Vogel 
2367ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
23688cfa0ad2SJack F Vogel 		return E1000_SUCCESS;
23698cfa0ad2SJack F Vogel 
23708cfa0ad2SJack F Vogel 	for (i = 0; i < iterations; i++) {
23716ab6bfe3SJack F Vogel 		/* Some PHYs require the PHY_STATUS register to be read
23728cfa0ad2SJack F Vogel 		 * twice due to the link bit being sticky.  No harm doing
23738cfa0ad2SJack F Vogel 		 * it across the board.
23748cfa0ad2SJack F Vogel 		 */
23758cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23768cc64f1eSJack F Vogel 		if (ret_val) {
23776ab6bfe3SJack F Vogel 			/* If the first read fails, another entity may have
23789d81738fSJack F Vogel 			 * ownership of the resources, wait and try again to
23799d81738fSJack F Vogel 			 * see if they have relinquished the resources yet.
23809d81738fSJack F Vogel 			 */
23818cc64f1eSJack F Vogel 			if (usec_interval >= 1000)
23828cc64f1eSJack F Vogel 				msec_delay(usec_interval/1000);
23838cc64f1eSJack F Vogel 			else
23849d81738fSJack F Vogel 				usec_delay(usec_interval);
23858cc64f1eSJack F Vogel 		}
23864edd8523SJack F Vogel 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
23878cfa0ad2SJack F Vogel 		if (ret_val)
23888cfa0ad2SJack F Vogel 			break;
23898cfa0ad2SJack F Vogel 		if (phy_status & MII_SR_LINK_STATUS)
23908cfa0ad2SJack F Vogel 			break;
23918cfa0ad2SJack F Vogel 		if (usec_interval >= 1000)
23928cc64f1eSJack F Vogel 			msec_delay(usec_interval/1000);
23938cfa0ad2SJack F Vogel 		else
23948cfa0ad2SJack F Vogel 			usec_delay(usec_interval);
23958cfa0ad2SJack F Vogel 	}
23968cfa0ad2SJack F Vogel 
2397ab5d0362SJack F Vogel 	*success = (i < iterations);
23988cfa0ad2SJack F Vogel 
23998cfa0ad2SJack F Vogel 	return ret_val;
24008cfa0ad2SJack F Vogel }
24018cfa0ad2SJack F Vogel 
24028cfa0ad2SJack F Vogel /**
24038cfa0ad2SJack F Vogel  *  e1000_get_cable_length_m88 - Determine cable length for m88 PHY
24048cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
24058cfa0ad2SJack F Vogel  *
24068cfa0ad2SJack F Vogel  *  Reads the PHY specific status register to retrieve the cable length
24078cfa0ad2SJack F Vogel  *  information.  The cable length is determined by averaging the minimum and
24088cfa0ad2SJack F Vogel  *  maximum values to get the "average" cable length.  The m88 PHY has four
24098cfa0ad2SJack F Vogel  *  possible cable length values, which are:
24108cfa0ad2SJack F Vogel  *	Register Value		Cable Length
24118cfa0ad2SJack F Vogel  *	0			< 50 meters
24128cfa0ad2SJack F Vogel  *	1			50 - 80 meters
24138cfa0ad2SJack F Vogel  *	2			80 - 110 meters
24148cfa0ad2SJack F Vogel  *	3			110 - 140 meters
24158cfa0ad2SJack F Vogel  *	4			> 140 meters
24168cfa0ad2SJack F Vogel  **/
e1000_get_cable_length_m88(struct e1000_hw * hw)24178cfa0ad2SJack F Vogel s32 e1000_get_cable_length_m88(struct e1000_hw *hw)
24188cfa0ad2SJack F Vogel {
24198cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
24208cfa0ad2SJack F Vogel 	s32 ret_val;
24218cfa0ad2SJack F Vogel 	u16 phy_data, index;
24228cfa0ad2SJack F Vogel 
24238cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_m88");
24248cfa0ad2SJack F Vogel 
24258cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
24268cfa0ad2SJack F Vogel 	if (ret_val)
2427ab5d0362SJack F Vogel 		return ret_val;
24288cfa0ad2SJack F Vogel 
24297609433eSJack F Vogel 	index = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
24307609433eSJack F Vogel 		 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2431ab5d0362SJack F Vogel 
2432ab5d0362SJack F Vogel 	if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2433ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
2434d035aa2dSJack F Vogel 
24358cfa0ad2SJack F Vogel 	phy->min_cable_length = e1000_m88_cable_length_table[index];
24368cfa0ad2SJack F Vogel 	phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
24378cfa0ad2SJack F Vogel 
2438d035aa2dSJack F Vogel 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
24398cfa0ad2SJack F Vogel 
2440ab5d0362SJack F Vogel 	return E1000_SUCCESS;
24418cfa0ad2SJack F Vogel }
24428cfa0ad2SJack F Vogel 
e1000_get_cable_length_m88_gen2(struct e1000_hw * hw)2443f0ecc46dSJack F Vogel s32 e1000_get_cable_length_m88_gen2(struct e1000_hw *hw)
2444f0ecc46dSJack F Vogel {
2445f0ecc46dSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2446f0ecc46dSJack F Vogel 	s32 ret_val;
24476ab6bfe3SJack F Vogel 	u16 phy_data, phy_data2, is_cm;
24486ab6bfe3SJack F Vogel 	u16 index, default_page;
2449f0ecc46dSJack F Vogel 
2450f0ecc46dSJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_m88_gen2");
2451f0ecc46dSJack F Vogel 
2452f0ecc46dSJack F Vogel 	switch (hw->phy.id) {
2453ab5d0362SJack F Vogel 	case I210_I_PHY_ID:
2454ab5d0362SJack F Vogel 		/* Get cable length from PHY Cable Diagnostics Control Reg */
2455ab5d0362SJack F Vogel 		ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2456ab5d0362SJack F Vogel 					    (I347AT4_PCDL + phy->addr),
2457ab5d0362SJack F Vogel 					    &phy_data);
2458ab5d0362SJack F Vogel 		if (ret_val)
2459ab5d0362SJack F Vogel 			return ret_val;
2460ab5d0362SJack F Vogel 
2461ab5d0362SJack F Vogel 		/* Check if the unit of cable length is meters or cm */
2462ab5d0362SJack F Vogel 		ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) +
2463ab5d0362SJack F Vogel 					    I347AT4_PCDC, &phy_data2);
2464ab5d0362SJack F Vogel 		if (ret_val)
2465ab5d0362SJack F Vogel 			return ret_val;
2466ab5d0362SJack F Vogel 
2467ab5d0362SJack F Vogel 		is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2468ab5d0362SJack F Vogel 
2469ab5d0362SJack F Vogel 		/* Populate the phy structure with cable length in meters */
2470ab5d0362SJack F Vogel 		phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2471ab5d0362SJack F Vogel 		phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2472ab5d0362SJack F Vogel 		phy->cable_length = phy_data / (is_cm ? 100 : 1);
2473ab5d0362SJack F Vogel 		break;
24747609433eSJack F Vogel 	case M88E1543_E_PHY_ID:
24757609433eSJack F Vogel 	case M88E1512_E_PHY_ID:
24761fd3c44fSJack F Vogel 	case M88E1340M_E_PHY_ID:
2477f0ecc46dSJack F Vogel 	case I347AT4_E_PHY_ID:
2478f0ecc46dSJack F Vogel 		/* Remember the original page select and set it to 7 */
2479f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2480f0ecc46dSJack F Vogel 					    &default_page);
2481f0ecc46dSJack F Vogel 		if (ret_val)
2482ab5d0362SJack F Vogel 			return ret_val;
2483f0ecc46dSJack F Vogel 
2484f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07);
2485f0ecc46dSJack F Vogel 		if (ret_val)
2486ab5d0362SJack F Vogel 			return ret_val;
2487f0ecc46dSJack F Vogel 
2488f0ecc46dSJack F Vogel 		/* Get cable length from PHY Cable Diagnostics Control Reg */
2489f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr),
2490f0ecc46dSJack F Vogel 					    &phy_data);
2491f0ecc46dSJack F Vogel 		if (ret_val)
2492ab5d0362SJack F Vogel 			return ret_val;
2493f0ecc46dSJack F Vogel 
2494f0ecc46dSJack F Vogel 		/* Check if the unit of cable length is meters or cm */
2495f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2);
2496f0ecc46dSJack F Vogel 		if (ret_val)
2497ab5d0362SJack F Vogel 			return ret_val;
2498f0ecc46dSJack F Vogel 
24994dab5c37SJack F Vogel 		is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
2500f0ecc46dSJack F Vogel 
2501f0ecc46dSJack F Vogel 		/* Populate the phy structure with cable length in meters */
2502f0ecc46dSJack F Vogel 		phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
2503f0ecc46dSJack F Vogel 		phy->max_cable_length = phy_data / (is_cm ? 100 : 1);
2504f0ecc46dSJack F Vogel 		phy->cable_length = phy_data / (is_cm ? 100 : 1);
2505f0ecc46dSJack F Vogel 
25064dab5c37SJack F Vogel 		/* Reset the page select to its original value */
2507f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2508f0ecc46dSJack F Vogel 					     default_page);
2509f0ecc46dSJack F Vogel 		if (ret_val)
2510ab5d0362SJack F Vogel 			return ret_val;
2511f0ecc46dSJack F Vogel 		break;
2512ab5d0362SJack F Vogel 
2513f0ecc46dSJack F Vogel 	case M88E1112_E_PHY_ID:
2514f0ecc46dSJack F Vogel 		/* Remember the original page select and set it to 5 */
2515f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT,
2516f0ecc46dSJack F Vogel 					    &default_page);
2517f0ecc46dSJack F Vogel 		if (ret_val)
2518ab5d0362SJack F Vogel 			return ret_val;
2519f0ecc46dSJack F Vogel 
2520f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05);
2521f0ecc46dSJack F Vogel 		if (ret_val)
2522ab5d0362SJack F Vogel 			return ret_val;
2523f0ecc46dSJack F Vogel 
2524f0ecc46dSJack F Vogel 		ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE,
2525f0ecc46dSJack F Vogel 					    &phy_data);
2526f0ecc46dSJack F Vogel 		if (ret_val)
2527ab5d0362SJack F Vogel 			return ret_val;
2528f0ecc46dSJack F Vogel 
2529f0ecc46dSJack F Vogel 		index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2530f0ecc46dSJack F Vogel 			M88E1000_PSSR_CABLE_LENGTH_SHIFT;
2531ab5d0362SJack F Vogel 
2532ab5d0362SJack F Vogel 		if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1)
2533ab5d0362SJack F Vogel 			return -E1000_ERR_PHY;
2534f0ecc46dSJack F Vogel 
2535f0ecc46dSJack F Vogel 		phy->min_cable_length = e1000_m88_cable_length_table[index];
2536f0ecc46dSJack F Vogel 		phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
2537f0ecc46dSJack F Vogel 
2538f0ecc46dSJack F Vogel 		phy->cable_length = (phy->min_cable_length +
2539f0ecc46dSJack F Vogel 				     phy->max_cable_length) / 2;
2540f0ecc46dSJack F Vogel 
2541f0ecc46dSJack F Vogel 		/* Reset the page select to its original value */
2542f0ecc46dSJack F Vogel 		ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT,
2543f0ecc46dSJack F Vogel 					     default_page);
2544f0ecc46dSJack F Vogel 		if (ret_val)
2545ab5d0362SJack F Vogel 			return ret_val;
2546f0ecc46dSJack F Vogel 
2547f0ecc46dSJack F Vogel 		break;
2548f0ecc46dSJack F Vogel 	default:
2549ab5d0362SJack F Vogel 		return -E1000_ERR_PHY;
2550f0ecc46dSJack F Vogel 	}
2551f0ecc46dSJack F Vogel 
2552f0ecc46dSJack F Vogel 	return ret_val;
2553f0ecc46dSJack F Vogel }
2554f0ecc46dSJack F Vogel 
25558cfa0ad2SJack F Vogel /**
25568cfa0ad2SJack F Vogel  *  e1000_get_cable_length_igp_2 - Determine cable length for igp2 PHY
25578cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
25588cfa0ad2SJack F Vogel  *
25598cfa0ad2SJack F Vogel  *  The automatic gain control (agc) normalizes the amplitude of the
25608cfa0ad2SJack F Vogel  *  received signal, adjusting for the attenuation produced by the
25618cfa0ad2SJack F Vogel  *  cable.  By reading the AGC registers, which represent the
25628cfa0ad2SJack F Vogel  *  combination of coarse and fine gain value, the value can be put
25638cfa0ad2SJack F Vogel  *  into a lookup table to obtain the approximate cable length
25648cfa0ad2SJack F Vogel  *  for each channel.
25658cfa0ad2SJack F Vogel  **/
e1000_get_cable_length_igp_2(struct e1000_hw * hw)25668cfa0ad2SJack F Vogel s32 e1000_get_cable_length_igp_2(struct e1000_hw *hw)
25678cfa0ad2SJack F Vogel {
25688cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2569ab5d0362SJack F Vogel 	s32 ret_val;
25708cfa0ad2SJack F Vogel 	u16 phy_data, i, agc_value = 0;
25718cfa0ad2SJack F Vogel 	u16 cur_agc_index, max_agc_index = 0;
25728cfa0ad2SJack F Vogel 	u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
2573f0ecc46dSJack F Vogel 	static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = {
2574f0ecc46dSJack F Vogel 		IGP02E1000_PHY_AGC_A,
25758cfa0ad2SJack F Vogel 		IGP02E1000_PHY_AGC_B,
25768cfa0ad2SJack F Vogel 		IGP02E1000_PHY_AGC_C,
2577f0ecc46dSJack F Vogel 		IGP02E1000_PHY_AGC_D
2578f0ecc46dSJack F Vogel 	};
25798cfa0ad2SJack F Vogel 
25808cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_igp_2");
25818cfa0ad2SJack F Vogel 
25828cfa0ad2SJack F Vogel 	/* Read the AGC registers for all channels */
25838cfa0ad2SJack F Vogel 	for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
25848cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
25858cfa0ad2SJack F Vogel 		if (ret_val)
2586ab5d0362SJack F Vogel 			return ret_val;
25878cfa0ad2SJack F Vogel 
25886ab6bfe3SJack F Vogel 		/* Getting bits 15:9, which represent the combination of
25898cfa0ad2SJack F Vogel 		 * coarse and fine gain values.  The result is a number
25908cfa0ad2SJack F Vogel 		 * that can be put into the lookup table to obtain the
25918cfa0ad2SJack F Vogel 		 * approximate cable length.
25928cfa0ad2SJack F Vogel 		 */
25937609433eSJack F Vogel 		cur_agc_index = ((phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
25947609433eSJack F Vogel 				 IGP02E1000_AGC_LENGTH_MASK);
25958cfa0ad2SJack F Vogel 
25968cfa0ad2SJack F Vogel 		/* Array index bound check. */
25978cfa0ad2SJack F Vogel 		if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
2598ab5d0362SJack F Vogel 		    (cur_agc_index == 0))
2599ab5d0362SJack F Vogel 			return -E1000_ERR_PHY;
26008cfa0ad2SJack F Vogel 
26018cfa0ad2SJack F Vogel 		/* Remove min & max AGC values from calculation. */
26028cfa0ad2SJack F Vogel 		if (e1000_igp_2_cable_length_table[min_agc_index] >
26038cfa0ad2SJack F Vogel 		    e1000_igp_2_cable_length_table[cur_agc_index])
26048cfa0ad2SJack F Vogel 			min_agc_index = cur_agc_index;
26058cfa0ad2SJack F Vogel 		if (e1000_igp_2_cable_length_table[max_agc_index] <
26068cfa0ad2SJack F Vogel 		    e1000_igp_2_cable_length_table[cur_agc_index])
26078cfa0ad2SJack F Vogel 			max_agc_index = cur_agc_index;
26088cfa0ad2SJack F Vogel 
26098cfa0ad2SJack F Vogel 		agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
26108cfa0ad2SJack F Vogel 	}
26118cfa0ad2SJack F Vogel 
26128cfa0ad2SJack F Vogel 	agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
26138cfa0ad2SJack F Vogel 		      e1000_igp_2_cable_length_table[max_agc_index]);
26148cfa0ad2SJack F Vogel 	agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
26158cfa0ad2SJack F Vogel 
26168cfa0ad2SJack F Vogel 	/* Calculate cable length with the error range of +/- 10 meters. */
26177609433eSJack F Vogel 	phy->min_cable_length = (((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
26187609433eSJack F Vogel 				 (agc_value - IGP02E1000_AGC_RANGE) : 0);
26198cfa0ad2SJack F Vogel 	phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
26208cfa0ad2SJack F Vogel 
26218cfa0ad2SJack F Vogel 	phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
26228cfa0ad2SJack F Vogel 
2623ab5d0362SJack F Vogel 	return E1000_SUCCESS;
26248cfa0ad2SJack F Vogel }
26258cfa0ad2SJack F Vogel 
26268cfa0ad2SJack F Vogel /**
26278cfa0ad2SJack F Vogel  *  e1000_get_phy_info_m88 - Retrieve PHY information
26288cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
26298cfa0ad2SJack F Vogel  *
26308cfa0ad2SJack F Vogel  *  Valid for only copper links.  Read the PHY status register (sticky read)
26318cfa0ad2SJack F Vogel  *  to verify that link is up.  Read the PHY special control register to
26328cfa0ad2SJack F Vogel  *  determine the polarity and 10base-T extended distance.  Read the PHY
26338cfa0ad2SJack F Vogel  *  special status register to determine MDI/MDIx and current speed.  If
26348cfa0ad2SJack F Vogel  *  speed is 1000, then determine cable length, local and remote receiver.
26358cfa0ad2SJack F Vogel  **/
e1000_get_phy_info_m88(struct e1000_hw * hw)26368cfa0ad2SJack F Vogel s32 e1000_get_phy_info_m88(struct e1000_hw *hw)
26378cfa0ad2SJack F Vogel {
26388cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
26398cfa0ad2SJack F Vogel 	s32  ret_val;
26408cfa0ad2SJack F Vogel 	u16 phy_data;
26418cfa0ad2SJack F Vogel 	bool link;
26428cfa0ad2SJack F Vogel 
26438cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_m88");
26448cfa0ad2SJack F Vogel 
26454edd8523SJack F Vogel 	if (phy->media_type != e1000_media_type_copper) {
26468cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid for copper media\n");
2647ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
26488cfa0ad2SJack F Vogel 	}
26498cfa0ad2SJack F Vogel 
26508cfa0ad2SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
26518cfa0ad2SJack F Vogel 	if (ret_val)
2652ab5d0362SJack F Vogel 		return ret_val;
26538cfa0ad2SJack F Vogel 
26548cfa0ad2SJack F Vogel 	if (!link) {
26558cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2656ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
26578cfa0ad2SJack F Vogel 	}
26588cfa0ad2SJack F Vogel 
26598cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
26608cfa0ad2SJack F Vogel 	if (ret_val)
2661ab5d0362SJack F Vogel 		return ret_val;
26628cfa0ad2SJack F Vogel 
2663ab5d0362SJack F Vogel 	phy->polarity_correction = !!(phy_data &
2664ab5d0362SJack F Vogel 				      M88E1000_PSCR_POLARITY_REVERSAL);
26658cfa0ad2SJack F Vogel 
26668cfa0ad2SJack F Vogel 	ret_val = e1000_check_polarity_m88(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, M88E1000_PHY_SPEC_STATUS, &phy_data);
26718cfa0ad2SJack F Vogel 	if (ret_val)
2672ab5d0362SJack F Vogel 		return ret_val;
26738cfa0ad2SJack F Vogel 
2674ab5d0362SJack F Vogel 	phy->is_mdix = !!(phy_data & M88E1000_PSSR_MDIX);
26758cfa0ad2SJack F Vogel 
26768cfa0ad2SJack F Vogel 	if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
26778cfa0ad2SJack F Vogel 		ret_val = hw->phy.ops.get_cable_length(hw);
26788cfa0ad2SJack F Vogel 		if (ret_val)
2679ab5d0362SJack F Vogel 			return ret_val;
26808cfa0ad2SJack F Vogel 
26818cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
26828cfa0ad2SJack F Vogel 		if (ret_val)
2683ab5d0362SJack F Vogel 			return ret_val;
26848cfa0ad2SJack F Vogel 
26858cfa0ad2SJack F Vogel 		phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
26868cfa0ad2SJack F Vogel 				? e1000_1000t_rx_status_ok
26878cfa0ad2SJack F Vogel 				: e1000_1000t_rx_status_not_ok;
26888cfa0ad2SJack F Vogel 
26898cfa0ad2SJack F Vogel 		phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
26908cfa0ad2SJack F Vogel 				 ? e1000_1000t_rx_status_ok
26918cfa0ad2SJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
26928cfa0ad2SJack F Vogel 	} else {
26938cfa0ad2SJack F Vogel 		/* Set values to "undefined" */
26948cfa0ad2SJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
26958cfa0ad2SJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
26968cfa0ad2SJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
26978cfa0ad2SJack F Vogel 	}
26988cfa0ad2SJack F Vogel 
26998cfa0ad2SJack F Vogel 	return ret_val;
27008cfa0ad2SJack F Vogel }
27018cfa0ad2SJack F Vogel 
27028cfa0ad2SJack F Vogel /**
27038cfa0ad2SJack F Vogel  *  e1000_get_phy_info_igp - Retrieve igp PHY information
27048cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
27058cfa0ad2SJack F Vogel  *
27068cfa0ad2SJack F Vogel  *  Read PHY status to determine if link is up.  If link is up, then
27078cfa0ad2SJack F Vogel  *  set/determine 10base-T extended distance and polarity correction.  Read
27088cfa0ad2SJack F Vogel  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
27098cfa0ad2SJack F Vogel  *  determine on the cable length, local and remote receiver.
27108cfa0ad2SJack F Vogel  **/
e1000_get_phy_info_igp(struct e1000_hw * hw)27118cfa0ad2SJack F Vogel s32 e1000_get_phy_info_igp(struct e1000_hw *hw)
27128cfa0ad2SJack F Vogel {
27138cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
27148cfa0ad2SJack F Vogel 	s32 ret_val;
27158cfa0ad2SJack F Vogel 	u16 data;
27168cfa0ad2SJack F Vogel 	bool link;
27178cfa0ad2SJack F Vogel 
27188cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_igp");
27198cfa0ad2SJack F Vogel 
27208cfa0ad2SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
27218cfa0ad2SJack F Vogel 	if (ret_val)
2722ab5d0362SJack F Vogel 		return ret_val;
27238cfa0ad2SJack F Vogel 
27248cfa0ad2SJack F Vogel 	if (!link) {
27258cfa0ad2SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2726ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
27278cfa0ad2SJack F Vogel 	}
27288cfa0ad2SJack F Vogel 
27291bbdc25fSKevin Bowling 	phy->polarity_correction = true;
27308cfa0ad2SJack F Vogel 
27318cfa0ad2SJack F Vogel 	ret_val = e1000_check_polarity_igp(hw);
27328cfa0ad2SJack F Vogel 	if (ret_val)
2733ab5d0362SJack F Vogel 		return ret_val;
27348cfa0ad2SJack F Vogel 
27358cfa0ad2SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
27368cfa0ad2SJack F Vogel 	if (ret_val)
2737ab5d0362SJack F Vogel 		return ret_val;
27388cfa0ad2SJack F Vogel 
2739ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & IGP01E1000_PSSR_MDIX);
27408cfa0ad2SJack F Vogel 
27418cfa0ad2SJack F Vogel 	if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
27428cfa0ad2SJack F Vogel 	    IGP01E1000_PSSR_SPEED_1000MBPS) {
27434edd8523SJack F Vogel 		ret_val = phy->ops.get_cable_length(hw);
27448cfa0ad2SJack F Vogel 		if (ret_val)
2745ab5d0362SJack F Vogel 			return ret_val;
27468cfa0ad2SJack F Vogel 
27478cfa0ad2SJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
27488cfa0ad2SJack F Vogel 		if (ret_val)
2749ab5d0362SJack F Vogel 			return ret_val;
27508cfa0ad2SJack F Vogel 
27518cfa0ad2SJack F Vogel 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
27528cfa0ad2SJack F Vogel 				? e1000_1000t_rx_status_ok
27538cfa0ad2SJack F Vogel 				: e1000_1000t_rx_status_not_ok;
27548cfa0ad2SJack F Vogel 
27558cfa0ad2SJack F Vogel 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
27568cfa0ad2SJack F Vogel 				 ? e1000_1000t_rx_status_ok
27578cfa0ad2SJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
27588cfa0ad2SJack F Vogel 	} else {
27598cfa0ad2SJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
27608cfa0ad2SJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
27618cfa0ad2SJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
27628cfa0ad2SJack F Vogel 	}
27638cfa0ad2SJack F Vogel 
27648cfa0ad2SJack F Vogel 	return ret_val;
27658cfa0ad2SJack F Vogel }
27668cfa0ad2SJack F Vogel 
27678cfa0ad2SJack F Vogel /**
27684edd8523SJack F Vogel  *  e1000_get_phy_info_ife - Retrieves various IFE PHY states
27694edd8523SJack F Vogel  *  @hw: pointer to the HW structure
27704edd8523SJack F Vogel  *
27714edd8523SJack F Vogel  *  Populates "phy" structure with various feature states.
27724edd8523SJack F Vogel  **/
e1000_get_phy_info_ife(struct e1000_hw * hw)27734edd8523SJack F Vogel s32 e1000_get_phy_info_ife(struct e1000_hw *hw)
27744edd8523SJack F Vogel {
27754edd8523SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
27764edd8523SJack F Vogel 	s32 ret_val;
27774edd8523SJack F Vogel 	u16 data;
27784edd8523SJack F Vogel 	bool link;
27794edd8523SJack F Vogel 
27804edd8523SJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_ife");
27814edd8523SJack F Vogel 
27824edd8523SJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
27834edd8523SJack F Vogel 	if (ret_val)
2784ab5d0362SJack F Vogel 		return ret_val;
27854edd8523SJack F Vogel 
27864edd8523SJack F Vogel 	if (!link) {
27874edd8523SJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
2788ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
27894edd8523SJack F Vogel 	}
27904edd8523SJack F Vogel 
27914edd8523SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
27924edd8523SJack F Vogel 	if (ret_val)
2793ab5d0362SJack F Vogel 		return ret_val;
2794ab5d0362SJack F Vogel 	phy->polarity_correction = !(data & IFE_PSC_AUTO_POLARITY_DISABLE);
27954edd8523SJack F Vogel 
27964edd8523SJack F Vogel 	if (phy->polarity_correction) {
27974edd8523SJack F Vogel 		ret_val = e1000_check_polarity_ife(hw);
27984edd8523SJack F Vogel 		if (ret_val)
2799ab5d0362SJack F Vogel 			return ret_val;
28004edd8523SJack F Vogel 	} else {
28014edd8523SJack F Vogel 		/* Polarity is forced */
28027609433eSJack F Vogel 		phy->cable_polarity = ((data & IFE_PSC_FORCE_POLARITY)
28034edd8523SJack F Vogel 				       ? e1000_rev_polarity_reversed
28047609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
28054edd8523SJack F Vogel 	}
28064edd8523SJack F Vogel 
28074edd8523SJack F Vogel 	ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
28084edd8523SJack F Vogel 	if (ret_val)
2809ab5d0362SJack F Vogel 		return ret_val;
28104edd8523SJack F Vogel 
2811ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & IFE_PMC_MDIX_STATUS);
28124edd8523SJack F Vogel 
28134edd8523SJack F Vogel 	/* The following parameters are undefined for 10/100 operation. */
28144edd8523SJack F Vogel 	phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
28154edd8523SJack F Vogel 	phy->local_rx = e1000_1000t_rx_status_undefined;
28164edd8523SJack F Vogel 	phy->remote_rx = e1000_1000t_rx_status_undefined;
28174edd8523SJack F Vogel 
2818ab5d0362SJack F Vogel 	return E1000_SUCCESS;
28194edd8523SJack F Vogel }
28204edd8523SJack F Vogel 
28214edd8523SJack F Vogel /**
28228cfa0ad2SJack F Vogel  *  e1000_phy_sw_reset_generic - PHY software reset
28238cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28248cfa0ad2SJack F Vogel  *
28258cfa0ad2SJack F Vogel  *  Does a software reset of the PHY by reading the PHY control register and
28268cfa0ad2SJack F Vogel  *  setting/write the control register reset bit to the PHY.
28278cfa0ad2SJack F Vogel  **/
e1000_phy_sw_reset_generic(struct e1000_hw * hw)28288cfa0ad2SJack F Vogel s32 e1000_phy_sw_reset_generic(struct e1000_hw *hw)
28298cfa0ad2SJack F Vogel {
2830ab5d0362SJack F Vogel 	s32 ret_val;
28318cfa0ad2SJack F Vogel 	u16 phy_ctrl;
28328cfa0ad2SJack F Vogel 
28338cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_sw_reset_generic");
28348cfa0ad2SJack F Vogel 
2835ab5d0362SJack F Vogel 	if (!hw->phy.ops.read_reg)
2836ab5d0362SJack F Vogel 		return E1000_SUCCESS;
28378cfa0ad2SJack F Vogel 
28388cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
28398cfa0ad2SJack F Vogel 	if (ret_val)
2840ab5d0362SJack F Vogel 		return ret_val;
28418cfa0ad2SJack F Vogel 
28428cfa0ad2SJack F Vogel 	phy_ctrl |= MII_CR_RESET;
28438cfa0ad2SJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
28448cfa0ad2SJack F Vogel 	if (ret_val)
2845ab5d0362SJack F Vogel 		return ret_val;
28468cfa0ad2SJack F Vogel 
28478cfa0ad2SJack F Vogel 	usec_delay(1);
28488cfa0ad2SJack F Vogel 
28498cfa0ad2SJack F Vogel 	return ret_val;
28508cfa0ad2SJack F Vogel }
28518cfa0ad2SJack F Vogel 
28528cfa0ad2SJack F Vogel /**
28538cfa0ad2SJack F Vogel  *  e1000_phy_hw_reset_generic - PHY hardware reset
28548cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28558cfa0ad2SJack F Vogel  *
28568cfa0ad2SJack F Vogel  *  Verify the reset block is not blocking us from resetting.  Acquire
28578cfa0ad2SJack F Vogel  *  semaphore (if necessary) and read/set/write the device control reset
28588cfa0ad2SJack F Vogel  *  bit in the PHY.  Wait the appropriate delay time for the device to
28598cfa0ad2SJack F Vogel  *  reset and release the semaphore (if necessary).
28608cfa0ad2SJack F Vogel  **/
e1000_phy_hw_reset_generic(struct e1000_hw * hw)28618cfa0ad2SJack F Vogel s32 e1000_phy_hw_reset_generic(struct e1000_hw *hw)
28628cfa0ad2SJack F Vogel {
28638cfa0ad2SJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
2864ab5d0362SJack F Vogel 	s32 ret_val;
28658cfa0ad2SJack F Vogel 	u32 ctrl;
28668cfa0ad2SJack F Vogel 
28678cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_phy_hw_reset_generic");
28688cfa0ad2SJack F Vogel 
2869ab5d0362SJack F Vogel 	if (phy->ops.check_reset_block) {
28708cfa0ad2SJack F Vogel 		ret_val = phy->ops.check_reset_block(hw);
2871ab5d0362SJack F Vogel 		if (ret_val)
2872ab5d0362SJack F Vogel 			return E1000_SUCCESS;
28738cfa0ad2SJack F Vogel 	}
28748cfa0ad2SJack F Vogel 
28758cfa0ad2SJack F Vogel 	ret_val = phy->ops.acquire(hw);
28768cfa0ad2SJack F Vogel 	if (ret_val)
2877ab5d0362SJack F Vogel 		return ret_val;
28788cfa0ad2SJack F Vogel 
28798cfa0ad2SJack F Vogel 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
28808cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
28818cfa0ad2SJack F Vogel 	E1000_WRITE_FLUSH(hw);
28828cfa0ad2SJack F Vogel 
28838cfa0ad2SJack F Vogel 	usec_delay(phy->reset_delay_us);
28848cfa0ad2SJack F Vogel 
28858cfa0ad2SJack F Vogel 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
28868cfa0ad2SJack F Vogel 	E1000_WRITE_FLUSH(hw);
28878cfa0ad2SJack F Vogel 
28888cfa0ad2SJack F Vogel 	usec_delay(150);
28898cfa0ad2SJack F Vogel 
28908cfa0ad2SJack F Vogel 	phy->ops.release(hw);
28918cfa0ad2SJack F Vogel 
2892ab5d0362SJack F Vogel 	return phy->ops.get_cfg_done(hw);
28938cfa0ad2SJack F Vogel }
28948cfa0ad2SJack F Vogel 
28958cfa0ad2SJack F Vogel /**
28968cfa0ad2SJack F Vogel  *  e1000_get_cfg_done_generic - Generic configuration done
28978cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
28988cfa0ad2SJack F Vogel  *
28998cfa0ad2SJack F Vogel  *  Generic function to wait 10 milli-seconds for configuration to complete
29008cfa0ad2SJack F Vogel  *  and return success.
29018cfa0ad2SJack F Vogel  **/
e1000_get_cfg_done_generic(struct e1000_hw E1000_UNUSEDARG * hw)29027609433eSJack F Vogel s32 e1000_get_cfg_done_generic(struct e1000_hw E1000_UNUSEDARG *hw)
29038cfa0ad2SJack F Vogel {
29048cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_get_cfg_done_generic");
29058cfa0ad2SJack F Vogel 
29068cfa0ad2SJack F Vogel 	msec_delay_irq(10);
29078cfa0ad2SJack F Vogel 
29088cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
29098cfa0ad2SJack F Vogel }
29108cfa0ad2SJack F Vogel 
29118cfa0ad2SJack F Vogel /**
29128cfa0ad2SJack F Vogel  *  e1000_phy_init_script_igp3 - Inits the IGP3 PHY
29138cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
29148cfa0ad2SJack F Vogel  *
29158cfa0ad2SJack F Vogel  *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
29168cfa0ad2SJack F Vogel  **/
e1000_phy_init_script_igp3(struct e1000_hw * hw)29178cfa0ad2SJack F Vogel s32 e1000_phy_init_script_igp3(struct e1000_hw *hw)
29188cfa0ad2SJack F Vogel {
29198cfa0ad2SJack F Vogel 	DEBUGOUT("Running IGP 3 PHY init script\n");
29208cfa0ad2SJack F Vogel 
29218cfa0ad2SJack F Vogel 	/* PHY init IGP 3 */
29228cfa0ad2SJack F Vogel 	/* Enable rise/fall, 10-mode work in class-A */
29238cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
29248cfa0ad2SJack F Vogel 	/* Remove all caps from Replica path filter */
29258cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
29268cfa0ad2SJack F Vogel 	/* Bias trimming for ADC, AFE and Driver (Default) */
29278cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
29288cfa0ad2SJack F Vogel 	/* Increase Hybrid poly bias */
29298cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
29308cfa0ad2SJack F Vogel 	/* Add 4% to Tx amplitude in Gig mode */
29318cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
29328cfa0ad2SJack F Vogel 	/* Disable trimming (TTT) */
29338cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
29348cfa0ad2SJack F Vogel 	/* Poly DC correction to 94.6% + 2% for all channels */
29358cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
29368cfa0ad2SJack F Vogel 	/* ABS DC correction to 95.9% */
29378cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
29388cfa0ad2SJack F Vogel 	/* BG temp curve trim */
29398cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
29408cfa0ad2SJack F Vogel 	/* Increasing ADC OPAMP stage 1 currents to max */
29418cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
29428cfa0ad2SJack F Vogel 	/* Force 1000 ( required for enabling PHY regs configuration) */
29438cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
29448cfa0ad2SJack F Vogel 	/* Set upd_freq to 6 */
29458cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
29468cfa0ad2SJack F Vogel 	/* Disable NPDFE */
29478cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
29488cfa0ad2SJack F Vogel 	/* Disable adaptive fixed FFE (Default) */
29498cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
29508cfa0ad2SJack F Vogel 	/* Enable FFE hysteresis */
29518cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
29528cfa0ad2SJack F Vogel 	/* Fixed FFE for short cable lengths */
29538cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
29548cfa0ad2SJack F Vogel 	/* Fixed FFE for medium cable lengths */
29558cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
29568cfa0ad2SJack F Vogel 	/* Fixed FFE for long cable lengths */
29578cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
29588cfa0ad2SJack F Vogel 	/* Enable Adaptive Clip Threshold */
29598cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
29608cfa0ad2SJack F Vogel 	/* AHT reset limit to 1 */
29618cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
29628cfa0ad2SJack F Vogel 	/* Set AHT master delay to 127 msec */
29638cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
29648cfa0ad2SJack F Vogel 	/* Set scan bits for AHT */
29658cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
29668cfa0ad2SJack F Vogel 	/* Set AHT Preset bits */
29678cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
29688cfa0ad2SJack F Vogel 	/* Change integ_factor of channel A to 3 */
29698cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
29708cfa0ad2SJack F Vogel 	/* Change prop_factor of channels BCD to 8 */
29718cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
29728cfa0ad2SJack F Vogel 	/* Change cg_icount + enable integbp for channels BCD */
29738cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
29746ab6bfe3SJack F Vogel 	/* Change cg_icount + enable integbp + change prop_factor_master
29758cfa0ad2SJack F Vogel 	 * to 8 for channel A
29768cfa0ad2SJack F Vogel 	 */
29778cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
29788cfa0ad2SJack F Vogel 	/* Disable AHT in Slave mode on channel A */
29798cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
29806ab6bfe3SJack F Vogel 	/* Enable LPLU and disable AN to 1000 in non-D0a states,
29818cfa0ad2SJack F Vogel 	 * Enable SPD+B2B
29828cfa0ad2SJack F Vogel 	 */
29838cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
29848cfa0ad2SJack F Vogel 	/* Enable restart AN on an1000_dis change */
29858cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
29868cfa0ad2SJack F Vogel 	/* Enable wh_fifo read clock in 10/100 modes */
29878cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
29888cfa0ad2SJack F Vogel 	/* Restart AN, Speed selection is 1000 */
29898cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
29908cfa0ad2SJack F Vogel 
29918cfa0ad2SJack F Vogel 	return E1000_SUCCESS;
29928cfa0ad2SJack F Vogel }
29938cfa0ad2SJack F Vogel 
29948cfa0ad2SJack F Vogel /**
29958cfa0ad2SJack F Vogel  *  e1000_get_phy_type_from_id - Get PHY type from id
29968cfa0ad2SJack F Vogel  *  @phy_id: phy_id read from the phy
29978cfa0ad2SJack F Vogel  *
29988cfa0ad2SJack F Vogel  *  Returns the phy type from the id.
29998cfa0ad2SJack F Vogel  **/
e1000_get_phy_type_from_id(u32 phy_id)30008cfa0ad2SJack F Vogel enum e1000_phy_type e1000_get_phy_type_from_id(u32 phy_id)
30018cfa0ad2SJack F Vogel {
30028cfa0ad2SJack F Vogel 	enum e1000_phy_type phy_type = e1000_phy_unknown;
30038cfa0ad2SJack F Vogel 
30048cfa0ad2SJack F Vogel 	switch (phy_id) {
30058cfa0ad2SJack F Vogel 	case M88E1000_I_PHY_ID:
30068cfa0ad2SJack F Vogel 	case M88E1000_E_PHY_ID:
30078cfa0ad2SJack F Vogel 	case M88E1111_I_PHY_ID:
30088cfa0ad2SJack F Vogel 	case M88E1011_I_PHY_ID:
30097609433eSJack F Vogel 	case M88E1543_E_PHY_ID:
30107609433eSJack F Vogel 	case M88E1512_E_PHY_ID:
3011f0ecc46dSJack F Vogel 	case I347AT4_E_PHY_ID:
3012f0ecc46dSJack F Vogel 	case M88E1112_E_PHY_ID:
30131fd3c44fSJack F Vogel 	case M88E1340M_E_PHY_ID:
30148cfa0ad2SJack F Vogel 		phy_type = e1000_phy_m88;
30158cfa0ad2SJack F Vogel 		break;
30168cfa0ad2SJack F Vogel 	case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
30178cfa0ad2SJack F Vogel 		phy_type = e1000_phy_igp_2;
30188cfa0ad2SJack F Vogel 		break;
30198cfa0ad2SJack F Vogel 	case GG82563_E_PHY_ID:
30208cfa0ad2SJack F Vogel 		phy_type = e1000_phy_gg82563;
30218cfa0ad2SJack F Vogel 		break;
30228cfa0ad2SJack F Vogel 	case IGP03E1000_E_PHY_ID:
30238cfa0ad2SJack F Vogel 		phy_type = e1000_phy_igp_3;
30248cfa0ad2SJack F Vogel 		break;
30258cfa0ad2SJack F Vogel 	case IFE_E_PHY_ID:
30268cfa0ad2SJack F Vogel 	case IFE_PLUS_E_PHY_ID:
30278cfa0ad2SJack F Vogel 	case IFE_C_E_PHY_ID:
30288cfa0ad2SJack F Vogel 		phy_type = e1000_phy_ife;
30298cfa0ad2SJack F Vogel 		break;
30308cfa0ad2SJack F Vogel 	case BME1000_E_PHY_ID:
30318cfa0ad2SJack F Vogel 	case BME1000_E_PHY_ID_R2:
30328cfa0ad2SJack F Vogel 		phy_type = e1000_phy_bm;
30338cfa0ad2SJack F Vogel 		break;
30349d81738fSJack F Vogel 	case I82578_E_PHY_ID:
30359d81738fSJack F Vogel 		phy_type = e1000_phy_82578;
30369d81738fSJack F Vogel 		break;
30379d81738fSJack F Vogel 	case I82577_E_PHY_ID:
30389d81738fSJack F Vogel 		phy_type = e1000_phy_82577;
30399d81738fSJack F Vogel 		break;
30407d9119bdSJack F Vogel 	case I82579_E_PHY_ID:
30417d9119bdSJack F Vogel 		phy_type = e1000_phy_82579;
30427d9119bdSJack F Vogel 		break;
30436ab6bfe3SJack F Vogel 	case I217_E_PHY_ID:
30446ab6bfe3SJack F Vogel 		phy_type = e1000_phy_i217;
30456ab6bfe3SJack F Vogel 		break;
30464edd8523SJack F Vogel 	case I82580_I_PHY_ID:
30474edd8523SJack F Vogel 		phy_type = e1000_phy_82580;
30484edd8523SJack F Vogel 		break;
3049ab5d0362SJack F Vogel 	case I210_I_PHY_ID:
3050ab5d0362SJack F Vogel 		phy_type = e1000_phy_i210;
3051ab5d0362SJack F Vogel 		break;
30528cfa0ad2SJack F Vogel 	default:
30538cfa0ad2SJack F Vogel 		phy_type = e1000_phy_unknown;
30548cfa0ad2SJack F Vogel 		break;
30558cfa0ad2SJack F Vogel 	}
30568cfa0ad2SJack F Vogel 	return phy_type;
30578cfa0ad2SJack F Vogel }
30588cfa0ad2SJack F Vogel 
30598cfa0ad2SJack F Vogel /**
30608cfa0ad2SJack F Vogel  *  e1000_determine_phy_address - Determines PHY address.
30618cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
30628cfa0ad2SJack F Vogel  *
30638cfa0ad2SJack F Vogel  *  This uses a trial and error method to loop through possible PHY
30648cfa0ad2SJack F Vogel  *  addresses. It tests each by reading the PHY ID registers and
30658cfa0ad2SJack F Vogel  *  checking for a match.
30668cfa0ad2SJack F Vogel  **/
e1000_determine_phy_address(struct e1000_hw * hw)30678cfa0ad2SJack F Vogel s32 e1000_determine_phy_address(struct e1000_hw *hw)
30688cfa0ad2SJack F Vogel {
30698cfa0ad2SJack F Vogel 	u32 phy_addr = 0;
30708cfa0ad2SJack F Vogel 	u32 i;
30718cfa0ad2SJack F Vogel 	enum e1000_phy_type phy_type = e1000_phy_unknown;
30728cfa0ad2SJack F Vogel 
3073d035aa2dSJack F Vogel 	hw->phy.id = phy_type;
3074d035aa2dSJack F Vogel 
30758cfa0ad2SJack F Vogel 	for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
30768cfa0ad2SJack F Vogel 		hw->phy.addr = phy_addr;
30778cfa0ad2SJack F Vogel 		i = 0;
30788cfa0ad2SJack F Vogel 
30798cfa0ad2SJack F Vogel 		do {
30808cfa0ad2SJack F Vogel 			e1000_get_phy_id(hw);
30818cfa0ad2SJack F Vogel 			phy_type = e1000_get_phy_type_from_id(hw->phy.id);
30828cfa0ad2SJack F Vogel 
30836ab6bfe3SJack F Vogel 			/* If phy_type is valid, break - we found our
30848cfa0ad2SJack F Vogel 			 * PHY address
30858cfa0ad2SJack F Vogel 			 */
3086ab5d0362SJack F Vogel 			if (phy_type != e1000_phy_unknown)
3087ab5d0362SJack F Vogel 				return E1000_SUCCESS;
3088ab5d0362SJack F Vogel 
30898cfa0ad2SJack F Vogel 			msec_delay(1);
30908cfa0ad2SJack F Vogel 			i++;
30918cfa0ad2SJack F Vogel 		} while (i < 10);
30928cfa0ad2SJack F Vogel 	}
30938cfa0ad2SJack F Vogel 
3094ab5d0362SJack F Vogel 	return -E1000_ERR_PHY_TYPE;
30958cfa0ad2SJack F Vogel }
30968cfa0ad2SJack F Vogel 
30978cfa0ad2SJack F Vogel /**
30988cfa0ad2SJack F Vogel  *  e1000_get_phy_addr_for_bm_page - Retrieve PHY page address
30998cfa0ad2SJack F Vogel  *  @page: page to access
31006c59e186SGuinan Sun  *  @reg: register to access
31018cfa0ad2SJack F Vogel  *
31028cfa0ad2SJack F Vogel  *  Returns the phy address for the page requested.
31038cfa0ad2SJack F Vogel  **/
e1000_get_phy_addr_for_bm_page(u32 page,u32 reg)31048cfa0ad2SJack F Vogel static u32 e1000_get_phy_addr_for_bm_page(u32 page, u32 reg)
31058cfa0ad2SJack F Vogel {
31068cfa0ad2SJack F Vogel 	u32 phy_addr = 2;
31078cfa0ad2SJack F Vogel 
31088cfa0ad2SJack F Vogel 	if ((page >= 768) || (page == 0 && reg == 25) || (reg == 31))
31098cfa0ad2SJack F Vogel 		phy_addr = 1;
31108cfa0ad2SJack F Vogel 
31118cfa0ad2SJack F Vogel 	return phy_addr;
31128cfa0ad2SJack F Vogel }
31138cfa0ad2SJack F Vogel 
31148cfa0ad2SJack F Vogel /**
31158cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_bm - Write BM PHY register
31168cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
31178cfa0ad2SJack F Vogel  *  @offset: register offset to write to
31188cfa0ad2SJack F Vogel  *  @data: data to write at register offset
31198cfa0ad2SJack F Vogel  *
31208cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
31218cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
31228cfa0ad2SJack F Vogel  **/
e1000_write_phy_reg_bm(struct e1000_hw * hw,u32 offset,u16 data)31238cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 data)
31248cfa0ad2SJack F Vogel {
31258cfa0ad2SJack F Vogel 	s32 ret_val;
31268cfa0ad2SJack F Vogel 	u32 page = offset >> IGP_PAGE_SHIFT;
31278cfa0ad2SJack F Vogel 
31288cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_bm");
31298cfa0ad2SJack F Vogel 
31304edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
31314edd8523SJack F Vogel 	if (ret_val)
31324edd8523SJack F Vogel 		return ret_val;
31334edd8523SJack F Vogel 
31348cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
31358cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
3136daf9197cSJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
31371bbdc25fSKevin Bowling 							 false, false);
3138ab5d0362SJack F Vogel 		goto release;
31398cfa0ad2SJack F Vogel 	}
31408cfa0ad2SJack F Vogel 
31418cfa0ad2SJack F Vogel 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
31428cfa0ad2SJack F Vogel 
31438cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
3144f0ecc46dSJack F Vogel 		u32 page_shift, page_select;
3145f0ecc46dSJack F Vogel 
31466ab6bfe3SJack F Vogel 		/* Page select is register 31 for phy address 1 and 22 for
31478cfa0ad2SJack F Vogel 		 * phy address 2 and 3. Page select is shifted only for
31488cfa0ad2SJack F Vogel 		 * phy address 1.
31498cfa0ad2SJack F Vogel 		 */
31508cfa0ad2SJack F Vogel 		if (hw->phy.addr == 1) {
31518cfa0ad2SJack F Vogel 			page_shift = IGP_PAGE_SHIFT;
31528cfa0ad2SJack F Vogel 			page_select = IGP01E1000_PHY_PAGE_SELECT;
31538cfa0ad2SJack F Vogel 		} else {
31548cfa0ad2SJack F Vogel 			page_shift = 0;
31558cfa0ad2SJack F Vogel 			page_select = BM_PHY_PAGE_SELECT;
31568cfa0ad2SJack F Vogel 		}
31578cfa0ad2SJack F Vogel 
31588cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
31598cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, page_select,
31608cfa0ad2SJack F Vogel 						   (page << page_shift));
31614edd8523SJack F Vogel 		if (ret_val)
3162ab5d0362SJack F Vogel 			goto release;
31638cfa0ad2SJack F Vogel 	}
31648cfa0ad2SJack F Vogel 
3165daf9197cSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
31668cfa0ad2SJack F Vogel 					   data);
31678cfa0ad2SJack F Vogel 
3168ab5d0362SJack F Vogel release:
31694edd8523SJack F Vogel 	hw->phy.ops.release(hw);
31708cfa0ad2SJack F Vogel 	return ret_val;
31718cfa0ad2SJack F Vogel }
31728cfa0ad2SJack F Vogel 
31738cfa0ad2SJack F Vogel /**
31748cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_bm - Read BM PHY register
31758cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
31768cfa0ad2SJack F Vogel  *  @offset: register offset to be read
31778cfa0ad2SJack F Vogel  *  @data: pointer to the read data
31788cfa0ad2SJack F Vogel  *
31798cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
31808cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
31818cfa0ad2SJack F Vogel  *  semaphores before exiting.
31828cfa0ad2SJack F Vogel  **/
e1000_read_phy_reg_bm(struct e1000_hw * hw,u32 offset,u16 * data)31838cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_bm(struct e1000_hw *hw, u32 offset, u16 *data)
31848cfa0ad2SJack F Vogel {
31858cfa0ad2SJack F Vogel 	s32 ret_val;
31868cfa0ad2SJack F Vogel 	u32 page = offset >> IGP_PAGE_SHIFT;
31878cfa0ad2SJack F Vogel 
31888cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_bm");
31898cfa0ad2SJack F Vogel 
31904edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
31914edd8523SJack F Vogel 	if (ret_val)
31924edd8523SJack F Vogel 		return ret_val;
31934edd8523SJack F Vogel 
31948cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
31958cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
3196daf9197cSJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
31971bbdc25fSKevin Bowling 							 true, false);
3198ab5d0362SJack F Vogel 		goto release;
31998cfa0ad2SJack F Vogel 	}
32008cfa0ad2SJack F Vogel 
32018cfa0ad2SJack F Vogel 	hw->phy.addr = e1000_get_phy_addr_for_bm_page(page, offset);
32028cfa0ad2SJack F Vogel 
32038cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
3204f0ecc46dSJack F Vogel 		u32 page_shift, page_select;
3205f0ecc46dSJack F Vogel 
32066ab6bfe3SJack F Vogel 		/* Page select is register 31 for phy address 1 and 22 for
32078cfa0ad2SJack F Vogel 		 * phy address 2 and 3. Page select is shifted only for
32088cfa0ad2SJack F Vogel 		 * phy address 1.
32098cfa0ad2SJack F Vogel 		 */
32108cfa0ad2SJack F Vogel 		if (hw->phy.addr == 1) {
32118cfa0ad2SJack F Vogel 			page_shift = IGP_PAGE_SHIFT;
32128cfa0ad2SJack F Vogel 			page_select = IGP01E1000_PHY_PAGE_SELECT;
32138cfa0ad2SJack F Vogel 		} else {
32148cfa0ad2SJack F Vogel 			page_shift = 0;
32158cfa0ad2SJack F Vogel 			page_select = BM_PHY_PAGE_SELECT;
32168cfa0ad2SJack F Vogel 		}
32178cfa0ad2SJack F Vogel 
32188cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
32198cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, page_select,
32208cfa0ad2SJack F Vogel 						   (page << page_shift));
32214edd8523SJack F Vogel 		if (ret_val)
3222ab5d0362SJack F Vogel 			goto release;
32238cfa0ad2SJack F Vogel 	}
32248cfa0ad2SJack F Vogel 
3225daf9197cSJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
32268cfa0ad2SJack F Vogel 					  data);
3227ab5d0362SJack F Vogel release:
32284edd8523SJack F Vogel 	hw->phy.ops.release(hw);
32298cfa0ad2SJack F Vogel 	return ret_val;
32308cfa0ad2SJack F Vogel }
32318cfa0ad2SJack F Vogel 
32328cfa0ad2SJack F Vogel /**
32338cfa0ad2SJack F Vogel  *  e1000_read_phy_reg_bm2 - Read BM PHY register
32348cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
32358cfa0ad2SJack F Vogel  *  @offset: register offset to be read
32368cfa0ad2SJack F Vogel  *  @data: pointer to the read data
32378cfa0ad2SJack F Vogel  *
32388cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
32398cfa0ad2SJack F Vogel  *  and storing the retrieved information in data.  Release any acquired
32408cfa0ad2SJack F Vogel  *  semaphores before exiting.
32418cfa0ad2SJack F Vogel  **/
e1000_read_phy_reg_bm2(struct e1000_hw * hw,u32 offset,u16 * data)32428cfa0ad2SJack F Vogel s32 e1000_read_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 *data)
32438cfa0ad2SJack F Vogel {
32448cfa0ad2SJack F Vogel 	s32 ret_val;
32458cfa0ad2SJack F Vogel 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
32468cfa0ad2SJack F Vogel 
32474dab5c37SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_bm2");
32488cfa0ad2SJack F Vogel 
32494edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
32504edd8523SJack F Vogel 	if (ret_val)
32514edd8523SJack F Vogel 		return ret_val;
32524edd8523SJack F Vogel 
32538cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
32548cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
32558cfa0ad2SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
32561bbdc25fSKevin Bowling 							 true, false);
3257ab5d0362SJack F Vogel 		goto release;
32588cfa0ad2SJack F Vogel 	}
32598cfa0ad2SJack F Vogel 
32608cfa0ad2SJack F Vogel 	hw->phy.addr = 1;
32618cfa0ad2SJack F Vogel 
32628cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
32638cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
32648cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
32658cfa0ad2SJack F Vogel 						   page);
32668cfa0ad2SJack F Vogel 
32674edd8523SJack F Vogel 		if (ret_val)
3268ab5d0362SJack F Vogel 			goto release;
32698cfa0ad2SJack F Vogel 	}
32708cfa0ad2SJack F Vogel 
32718cfa0ad2SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
32728cfa0ad2SJack F Vogel 					  data);
3273ab5d0362SJack F Vogel release:
32744edd8523SJack F Vogel 	hw->phy.ops.release(hw);
32758cfa0ad2SJack F Vogel 	return ret_val;
32768cfa0ad2SJack F Vogel }
32778cfa0ad2SJack F Vogel 
32788cfa0ad2SJack F Vogel /**
32798cfa0ad2SJack F Vogel  *  e1000_write_phy_reg_bm2 - Write BM PHY register
32808cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
32818cfa0ad2SJack F Vogel  *  @offset: register offset to write to
32828cfa0ad2SJack F Vogel  *  @data: data to write at register offset
32838cfa0ad2SJack F Vogel  *
32848cfa0ad2SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
32858cfa0ad2SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
32868cfa0ad2SJack F Vogel  **/
e1000_write_phy_reg_bm2(struct e1000_hw * hw,u32 offset,u16 data)32878cfa0ad2SJack F Vogel s32 e1000_write_phy_reg_bm2(struct e1000_hw *hw, u32 offset, u16 data)
32888cfa0ad2SJack F Vogel {
32898cfa0ad2SJack F Vogel 	s32 ret_val;
32908cfa0ad2SJack F Vogel 	u16 page = (u16)(offset >> IGP_PAGE_SHIFT);
32918cfa0ad2SJack F Vogel 
32928cfa0ad2SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_bm2");
32938cfa0ad2SJack F Vogel 
32944edd8523SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
32954edd8523SJack F Vogel 	if (ret_val)
32964edd8523SJack F Vogel 		return ret_val;
32974edd8523SJack F Vogel 
32988cfa0ad2SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
32998cfa0ad2SJack F Vogel 	if (page == BM_WUC_PAGE) {
33008cfa0ad2SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
33011bbdc25fSKevin Bowling 							 false, false);
3302ab5d0362SJack F Vogel 		goto release;
33038cfa0ad2SJack F Vogel 	}
33048cfa0ad2SJack F Vogel 
33058cfa0ad2SJack F Vogel 	hw->phy.addr = 1;
33068cfa0ad2SJack F Vogel 
33078cfa0ad2SJack F Vogel 	if (offset > MAX_PHY_MULTI_PAGE_REG) {
33088cfa0ad2SJack F Vogel 		/* Page is shifted left, PHY expects (page x 32) */
33098cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_PHY_PAGE_SELECT,
33108cfa0ad2SJack F Vogel 						   page);
33118cfa0ad2SJack F Vogel 
33124edd8523SJack F Vogel 		if (ret_val)
3313ab5d0362SJack F Vogel 			goto release;
33148cfa0ad2SJack F Vogel 	}
33158cfa0ad2SJack F Vogel 
33168cfa0ad2SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
33178cfa0ad2SJack F Vogel 					   data);
33188cfa0ad2SJack F Vogel 
3319ab5d0362SJack F Vogel release:
33204edd8523SJack F Vogel 	hw->phy.ops.release(hw);
33218cfa0ad2SJack F Vogel 	return ret_val;
33228cfa0ad2SJack F Vogel }
33238cfa0ad2SJack F Vogel 
33248cfa0ad2SJack F Vogel /**
33254dab5c37SJack F Vogel  *  e1000_enable_phy_wakeup_reg_access_bm - enable access to BM wakeup registers
33264dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
33274dab5c37SJack F Vogel  *  @phy_reg: pointer to store original contents of BM_WUC_ENABLE_REG
33284dab5c37SJack F Vogel  *
33294dab5c37SJack F Vogel  *  Assumes semaphore already acquired and phy_reg points to a valid memory
33304dab5c37SJack F Vogel  *  address to store contents of the BM_WUC_ENABLE_REG register.
33314dab5c37SJack F Vogel  **/
e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw * hw,u16 * phy_reg)33324dab5c37SJack F Vogel s32 e1000_enable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
33334dab5c37SJack F Vogel {
33344dab5c37SJack F Vogel 	s32 ret_val;
33354dab5c37SJack F Vogel 	u16 temp;
33364dab5c37SJack F Vogel 
33374dab5c37SJack F Vogel 	DEBUGFUNC("e1000_enable_phy_wakeup_reg_access_bm");
33384dab5c37SJack F Vogel 
3339ab5d0362SJack F Vogel 	if (!phy_reg)
3340ab5d0362SJack F Vogel 		return -E1000_ERR_PARAM;
33414dab5c37SJack F Vogel 
33424dab5c37SJack F Vogel 	/* All page select, port ctrl and wakeup registers use phy address 1 */
33434dab5c37SJack F Vogel 	hw->phy.addr = 1;
33444dab5c37SJack F Vogel 
33454dab5c37SJack F Vogel 	/* Select Port Control Registers page */
33464dab5c37SJack F Vogel 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
33474dab5c37SJack F Vogel 	if (ret_val) {
33484dab5c37SJack F Vogel 		DEBUGOUT("Could not set Port Control page\n");
3349ab5d0362SJack F Vogel 		return ret_val;
33504dab5c37SJack F Vogel 	}
33514dab5c37SJack F Vogel 
33524dab5c37SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, phy_reg);
33534dab5c37SJack F Vogel 	if (ret_val) {
33544dab5c37SJack F Vogel 		DEBUGOUT2("Could not read PHY register %d.%d\n",
33554dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3356ab5d0362SJack F Vogel 		return ret_val;
33574dab5c37SJack F Vogel 	}
33584dab5c37SJack F Vogel 
33596ab6bfe3SJack F Vogel 	/* Enable both PHY wakeup mode and Wakeup register page writes.
33604dab5c37SJack F Vogel 	 * Prevent a power state change by disabling ME and Host PHY wakeup.
33614dab5c37SJack F Vogel 	 */
33624dab5c37SJack F Vogel 	temp = *phy_reg;
33634dab5c37SJack F Vogel 	temp |= BM_WUC_ENABLE_BIT;
33644dab5c37SJack F Vogel 	temp &= ~(BM_WUC_ME_WU_BIT | BM_WUC_HOST_WU_BIT);
33654dab5c37SJack F Vogel 
33664dab5c37SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, temp);
33674dab5c37SJack F Vogel 	if (ret_val) {
33684dab5c37SJack F Vogel 		DEBUGOUT2("Could not write PHY register %d.%d\n",
33694dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3370ab5d0362SJack F Vogel 		return ret_val;
33714dab5c37SJack F Vogel 	}
33724dab5c37SJack F Vogel 
33736ab6bfe3SJack F Vogel 	/* Select Host Wakeup Registers page - caller now able to write
3374ab5d0362SJack F Vogel 	 * registers on the Wakeup registers page
3375ab5d0362SJack F Vogel 	 */
3376ab5d0362SJack F Vogel 	return e1000_set_page_igp(hw, (BM_WUC_PAGE << IGP_PAGE_SHIFT));
33774dab5c37SJack F Vogel }
33784dab5c37SJack F Vogel 
33794dab5c37SJack F Vogel /**
33804dab5c37SJack F Vogel  *  e1000_disable_phy_wakeup_reg_access_bm - disable access to BM wakeup regs
33814dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
33824dab5c37SJack F Vogel  *  @phy_reg: pointer to original contents of BM_WUC_ENABLE_REG
33834dab5c37SJack F Vogel  *
33844dab5c37SJack F Vogel  *  Restore BM_WUC_ENABLE_REG to its original value.
33854dab5c37SJack F Vogel  *
33864dab5c37SJack F Vogel  *  Assumes semaphore already acquired and *phy_reg is the contents of the
33874dab5c37SJack F Vogel  *  BM_WUC_ENABLE_REG before register(s) on BM_WUC_PAGE were accessed by
33884dab5c37SJack F Vogel  *  caller.
33894dab5c37SJack F Vogel  **/
e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw * hw,u16 * phy_reg)33904dab5c37SJack F Vogel s32 e1000_disable_phy_wakeup_reg_access_bm(struct e1000_hw *hw, u16 *phy_reg)
33914dab5c37SJack F Vogel {
33926ab6bfe3SJack F Vogel 	s32 ret_val;
33934dab5c37SJack F Vogel 
33944dab5c37SJack F Vogel 	DEBUGFUNC("e1000_disable_phy_wakeup_reg_access_bm");
33954dab5c37SJack F Vogel 
33964dab5c37SJack F Vogel 	if (!phy_reg)
33974dab5c37SJack F Vogel 		return -E1000_ERR_PARAM;
33984dab5c37SJack F Vogel 
33994dab5c37SJack F Vogel 	/* Select Port Control Registers page */
34004dab5c37SJack F Vogel 	ret_val = e1000_set_page_igp(hw, (BM_PORT_CTRL_PAGE << IGP_PAGE_SHIFT));
34014dab5c37SJack F Vogel 	if (ret_val) {
34024dab5c37SJack F Vogel 		DEBUGOUT("Could not set Port Control page\n");
3403ab5d0362SJack F Vogel 		return ret_val;
34044dab5c37SJack F Vogel 	}
34054dab5c37SJack F Vogel 
34064dab5c37SJack F Vogel 	/* Restore 769.17 to its original value */
34074dab5c37SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ENABLE_REG, *phy_reg);
34084dab5c37SJack F Vogel 	if (ret_val)
34094dab5c37SJack F Vogel 		DEBUGOUT2("Could not restore PHY register %d.%d\n",
34104dab5c37SJack F Vogel 			  BM_PORT_CTRL_PAGE, BM_WUC_ENABLE_REG);
3411ab5d0362SJack F Vogel 
34124dab5c37SJack F Vogel 	return ret_val;
34134dab5c37SJack F Vogel }
34144dab5c37SJack F Vogel 
34154dab5c37SJack F Vogel /**
34164dab5c37SJack F Vogel  *  e1000_access_phy_wakeup_reg_bm - Read/write BM PHY wakeup register
34178cfa0ad2SJack F Vogel  *  @hw: pointer to the HW structure
34188cfa0ad2SJack F Vogel  *  @offset: register offset to be read or written
34198cfa0ad2SJack F Vogel  *  @data: pointer to the data to read or write
34208cfa0ad2SJack F Vogel  *  @read: determines if operation is read or write
34214dab5c37SJack F Vogel  *  @page_set: BM_WUC_PAGE already set and access enabled
34228cfa0ad2SJack F Vogel  *
34234dab5c37SJack F Vogel  *  Read the PHY register at offset and store the retrieved information in
34244dab5c37SJack F Vogel  *  data, or write data to PHY register at offset.  Note the procedure to
34254dab5c37SJack F Vogel  *  access the PHY wakeup registers is different than reading the other PHY
34264dab5c37SJack F Vogel  *  registers. It works as such:
34274dab5c37SJack F Vogel  *  1) Set 769.17.2 (page 769, register 17, bit 2) = 1
34288cfa0ad2SJack F Vogel  *  2) Set page to 800 for host (801 if we were manageability)
34298cfa0ad2SJack F Vogel  *  3) Write the address using the address opcode (0x11)
34308cfa0ad2SJack F Vogel  *  4) Read or write the data using the data opcode (0x12)
34314dab5c37SJack F Vogel  *  5) Restore 769.17.2 to its original value
34324edd8523SJack F Vogel  *
34334dab5c37SJack F Vogel  *  Steps 1 and 2 are done by e1000_enable_phy_wakeup_reg_access_bm() and
34344dab5c37SJack F Vogel  *  step 5 is done by e1000_disable_phy_wakeup_reg_access_bm().
34354dab5c37SJack F Vogel  *
34361bbdc25fSKevin Bowling  *  Assumes semaphore is already acquired.  When page_set==true, assumes
34374dab5c37SJack F Vogel  *  the PHY page is set to BM_WUC_PAGE (i.e. a function in the call stack
34384dab5c37SJack F Vogel  *  is responsible for calls to e1000_[enable|disable]_phy_wakeup_reg_bm()).
34398cfa0ad2SJack F Vogel  **/
e1000_access_phy_wakeup_reg_bm(struct e1000_hw * hw,u32 offset,u16 * data,bool read,bool page_set)3440daf9197cSJack F Vogel static s32 e1000_access_phy_wakeup_reg_bm(struct e1000_hw *hw, u32 offset,
34414dab5c37SJack F Vogel 					  u16 *data, bool read, bool page_set)
34428cfa0ad2SJack F Vogel {
34438cfa0ad2SJack F Vogel 	s32 ret_val;
3444c80429ceSEric Joyner 	u16 reg = BM_PHY_REG_NUM(offset);
3445c80429ceSEric Joyner 	u16 page = BM_PHY_REG_PAGE(offset);
34468cfa0ad2SJack F Vogel 	u16 phy_reg = 0;
34478cfa0ad2SJack F Vogel 
3448d035aa2dSJack F Vogel 	DEBUGFUNC("e1000_access_phy_wakeup_reg_bm");
344948600901SSean Bruno 
34504dab5c37SJack F Vogel 	/* Gig must be disabled for MDIO accesses to Host Wakeup reg page */
34519d81738fSJack F Vogel 	if ((hw->mac.type == e1000_pchlan) &&
34529d81738fSJack F Vogel 	   (!(E1000_READ_REG(hw, E1000_PHY_CTRL) & E1000_PHY_CTRL_GBE_DISABLE)))
34534dab5c37SJack F Vogel 		DEBUGOUT1("Attempting to access page %d while gig enabled.\n",
34544dab5c37SJack F Vogel 			  page);
34559d81738fSJack F Vogel 
34564dab5c37SJack F Vogel 	if (!page_set) {
34574dab5c37SJack F Vogel 		/* Enable access to PHY wakeup registers */
34584dab5c37SJack F Vogel 		ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
34598cfa0ad2SJack F Vogel 		if (ret_val) {
34604dab5c37SJack F Vogel 			DEBUGOUT("Could not enable PHY wakeup reg access\n");
3461ab5d0362SJack F Vogel 			return ret_val;
34628cfa0ad2SJack F Vogel 		}
34638cfa0ad2SJack F Vogel 	}
34648cfa0ad2SJack F Vogel 
34654dab5c37SJack F Vogel 	DEBUGOUT2("Accessing PHY page %d reg 0x%x\n", page, reg);
34668cfa0ad2SJack F Vogel 
34674dab5c37SJack F Vogel 	/* Write the Wakeup register page offset value using opcode 0x11 */
34688cfa0ad2SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_ADDRESS_OPCODE, reg);
34698cfa0ad2SJack F Vogel 	if (ret_val) {
34704dab5c37SJack F Vogel 		DEBUGOUT1("Could not write address opcode to page %d\n", page);
3471ab5d0362SJack F Vogel 		return ret_val;
34728cfa0ad2SJack F Vogel 	}
34738cfa0ad2SJack F Vogel 
34748cfa0ad2SJack F Vogel 	if (read) {
34754dab5c37SJack F Vogel 		/* Read the Wakeup register page value using opcode 0x12 */
34768cfa0ad2SJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
34778cfa0ad2SJack F Vogel 						  data);
34788cfa0ad2SJack F Vogel 	} else {
34794dab5c37SJack F Vogel 		/* Write the Wakeup register page value using opcode 0x12 */
34808cfa0ad2SJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, BM_WUC_DATA_OPCODE,
34818cfa0ad2SJack F Vogel 						   *data);
34828cfa0ad2SJack F Vogel 	}
34838cfa0ad2SJack F Vogel 
34848cfa0ad2SJack F Vogel 	if (ret_val) {
34854dab5c37SJack F Vogel 		DEBUGOUT2("Could not access PHY reg %d.%d\n", page, reg);
3486ab5d0362SJack F Vogel 		return ret_val;
34878cfa0ad2SJack F Vogel 	}
34888cfa0ad2SJack F Vogel 
34894dab5c37SJack F Vogel 	if (!page_set)
34904dab5c37SJack F Vogel 		ret_val = e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
34918cfa0ad2SJack F Vogel 
34928cfa0ad2SJack F Vogel 	return ret_val;
34938cfa0ad2SJack F Vogel }
34948cfa0ad2SJack F Vogel 
34958cfa0ad2SJack F Vogel /**
34968cfa0ad2SJack F Vogel  * e1000_power_up_phy_copper - Restore copper link in case of PHY power down
34978cfa0ad2SJack F Vogel  * @hw: pointer to the HW structure
34988cfa0ad2SJack F Vogel  *
34998cfa0ad2SJack F Vogel  * In the case of a PHY power down to save power, or to turn off link during a
35008cfa0ad2SJack F Vogel  * driver unload, or wake on lan is not enabled, restore the link to previous
35018cfa0ad2SJack F Vogel  * settings.
35028cfa0ad2SJack F Vogel  **/
e1000_power_up_phy_copper(struct e1000_hw * hw)35038cfa0ad2SJack F Vogel void e1000_power_up_phy_copper(struct e1000_hw *hw)
35048cfa0ad2SJack F Vogel {
35058cfa0ad2SJack F Vogel 	u16 mii_reg = 0;
35068cfa0ad2SJack F Vogel 
35078cfa0ad2SJack F Vogel 	/* The PHY will retain its settings across a power down/up cycle */
35088cfa0ad2SJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
35098cfa0ad2SJack F Vogel 	mii_reg &= ~MII_CR_POWER_DOWN;
35108cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
35118cfa0ad2SJack F Vogel }
35128cfa0ad2SJack F Vogel 
35138cfa0ad2SJack F Vogel /**
35148cfa0ad2SJack F Vogel  * e1000_power_down_phy_copper - Restore copper link in case of PHY power down
35158cfa0ad2SJack F Vogel  * @hw: pointer to the HW structure
35168cfa0ad2SJack F Vogel  *
35178cfa0ad2SJack F Vogel  * In the case of a PHY power down to save power, or to turn off link during a
35188cfa0ad2SJack F Vogel  * driver unload, or wake on lan is not enabled, restore the link to previous
35198cfa0ad2SJack F Vogel  * settings.
35208cfa0ad2SJack F Vogel  **/
e1000_power_down_phy_copper(struct e1000_hw * hw)35218cfa0ad2SJack F Vogel void e1000_power_down_phy_copper(struct e1000_hw *hw)
35228cfa0ad2SJack F Vogel {
35238cfa0ad2SJack F Vogel 	u16 mii_reg = 0;
35248cfa0ad2SJack F Vogel 
35258cfa0ad2SJack F Vogel 	/* The PHY will retain its settings across a power down/up cycle */
35268cfa0ad2SJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
35278cfa0ad2SJack F Vogel 	mii_reg |= MII_CR_POWER_DOWN;
35288cfa0ad2SJack F Vogel 	hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
35298cfa0ad2SJack F Vogel 	msec_delay(1);
35308cfa0ad2SJack F Vogel }
35319d81738fSJack F Vogel 
35324edd8523SJack F Vogel /**
35334edd8523SJack F Vogel  *  __e1000_read_phy_reg_hv -  Read HV PHY register
35344edd8523SJack F Vogel  *  @hw: pointer to the HW structure
35354edd8523SJack F Vogel  *  @offset: register offset to be read
35364edd8523SJack F Vogel  *  @data: pointer to the read data
35374edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
35386c59e186SGuinan Sun  *  @page_set: BM_WUC_PAGE already set and access enabled
35394edd8523SJack F Vogel  *
35404edd8523SJack F Vogel  *  Acquires semaphore, if necessary, then reads the PHY register at offset
35414edd8523SJack F Vogel  *  and stores the retrieved information in data.  Release any acquired
35424edd8523SJack F Vogel  *  semaphore before exiting.
35434edd8523SJack F Vogel  **/
__e1000_read_phy_reg_hv(struct e1000_hw * hw,u32 offset,u16 * data,bool locked,bool page_set)35444edd8523SJack F Vogel static s32 __e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data,
35454dab5c37SJack F Vogel 				   bool locked, bool page_set)
35464edd8523SJack F Vogel {
35474edd8523SJack F Vogel 	s32 ret_val;
35484edd8523SJack F Vogel 	u16 page = BM_PHY_REG_PAGE(offset);
35494edd8523SJack F Vogel 	u16 reg = BM_PHY_REG_NUM(offset);
35504dab5c37SJack F Vogel 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
35514edd8523SJack F Vogel 
3552a69ed8dfSJack F Vogel 	DEBUGFUNC("__e1000_read_phy_reg_hv");
35534edd8523SJack F Vogel 
35544edd8523SJack F Vogel 	if (!locked) {
35554edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
35564edd8523SJack F Vogel 		if (ret_val)
35574edd8523SJack F Vogel 			return ret_val;
35584edd8523SJack F Vogel 	}
35594edd8523SJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
35604edd8523SJack F Vogel 	if (page == BM_WUC_PAGE) {
35614dab5c37SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, data,
35621bbdc25fSKevin Bowling 							 true, page_set);
35634edd8523SJack F Vogel 		goto out;
35644edd8523SJack F Vogel 	}
35654edd8523SJack F Vogel 
35664edd8523SJack F Vogel 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
35674edd8523SJack F Vogel 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
35681bbdc25fSKevin Bowling 							 data, true);
35694edd8523SJack F Vogel 		goto out;
35704edd8523SJack F Vogel 	}
35714edd8523SJack F Vogel 
35724dab5c37SJack F Vogel 	if (!page_set) {
35734edd8523SJack F Vogel 		if (page == HV_INTC_FC_PAGE_START)
35744edd8523SJack F Vogel 			page = 0;
35754edd8523SJack F Vogel 
35764edd8523SJack F Vogel 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
35774edd8523SJack F Vogel 			/* Page is shifted left, PHY expects (page x 32) */
35784dab5c37SJack F Vogel 			ret_val = e1000_set_page_igp(hw,
35794edd8523SJack F Vogel 						     (page << IGP_PAGE_SHIFT));
35804dab5c37SJack F Vogel 
35814edd8523SJack F Vogel 			hw->phy.addr = phy_addr;
35824edd8523SJack F Vogel 
35834edd8523SJack F Vogel 			if (ret_val)
35844edd8523SJack F Vogel 				goto out;
35854edd8523SJack F Vogel 		}
35864dab5c37SJack F Vogel 	}
35874dab5c37SJack F Vogel 
35884dab5c37SJack F Vogel 	DEBUGOUT3("reading PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
35894dab5c37SJack F Vogel 		  page << IGP_PAGE_SHIFT, reg);
35904edd8523SJack F Vogel 
35914edd8523SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
35924edd8523SJack F Vogel 					  data);
35934edd8523SJack F Vogel out:
35944edd8523SJack F Vogel 	if (!locked)
35959d81738fSJack F Vogel 		hw->phy.ops.release(hw);
35969d81738fSJack F Vogel 
35979d81738fSJack F Vogel 	return ret_val;
35989d81738fSJack F Vogel }
35999d81738fSJack F Vogel 
36009d81738fSJack F Vogel /**
36019d81738fSJack F Vogel  *  e1000_read_phy_reg_hv -  Read HV PHY register
36029d81738fSJack F Vogel  *  @hw: pointer to the HW structure
36039d81738fSJack F Vogel  *  @offset: register offset to be read
36049d81738fSJack F Vogel  *  @data: pointer to the read data
36059d81738fSJack F Vogel  *
36064edd8523SJack F Vogel  *  Acquires semaphore then reads the PHY register at offset and stores
36074edd8523SJack F Vogel  *  the retrieved information in data.  Release the acquired semaphore
36084edd8523SJack F Vogel  *  before exiting.
36099d81738fSJack F Vogel  **/
e1000_read_phy_reg_hv(struct e1000_hw * hw,u32 offset,u16 * data)36109d81738fSJack F Vogel s32 e1000_read_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 *data)
36119d81738fSJack F Vogel {
36121bbdc25fSKevin Bowling 	return __e1000_read_phy_reg_hv(hw, offset, data, false, false);
36139d81738fSJack F Vogel }
36149d81738fSJack F Vogel 
36159d81738fSJack F Vogel /**
36164edd8523SJack F Vogel  *  e1000_read_phy_reg_hv_locked -  Read HV PHY register
36174edd8523SJack F Vogel  *  @hw: pointer to the HW structure
36184edd8523SJack F Vogel  *  @offset: register offset to be read
36194edd8523SJack F Vogel  *  @data: pointer to the read data
36204edd8523SJack F Vogel  *
36214edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
36224edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.
36234edd8523SJack F Vogel  **/
e1000_read_phy_reg_hv_locked(struct e1000_hw * hw,u32 offset,u16 * data)36244edd8523SJack F Vogel s32 e1000_read_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 *data)
36254edd8523SJack F Vogel {
36261bbdc25fSKevin Bowling 	return __e1000_read_phy_reg_hv(hw, offset, data, true, false);
36274dab5c37SJack F Vogel }
36284dab5c37SJack F Vogel 
36294dab5c37SJack F Vogel /**
36304dab5c37SJack F Vogel  *  e1000_read_phy_reg_page_hv - Read HV PHY register
36314dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
36324dab5c37SJack F Vogel  *  @offset: register offset to write to
36334dab5c37SJack F Vogel  *  @data: data to write at register offset
36344dab5c37SJack F Vogel  *
36354dab5c37SJack F Vogel  *  Reads the PHY register at offset and stores the retrieved information
36364dab5c37SJack F Vogel  *  in data.  Assumes semaphore already acquired and page already set.
36374dab5c37SJack F Vogel  **/
e1000_read_phy_reg_page_hv(struct e1000_hw * hw,u32 offset,u16 * data)36384dab5c37SJack F Vogel s32 e1000_read_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 *data)
36394dab5c37SJack F Vogel {
36401bbdc25fSKevin Bowling 	return __e1000_read_phy_reg_hv(hw, offset, data, true, true);
36414edd8523SJack F Vogel }
36424edd8523SJack F Vogel 
36434edd8523SJack F Vogel /**
36444edd8523SJack F Vogel  *  __e1000_write_phy_reg_hv - Write HV PHY register
36459d81738fSJack F Vogel  *  @hw: pointer to the HW structure
36469d81738fSJack F Vogel  *  @offset: register offset to write to
36479d81738fSJack F Vogel  *  @data: data to write at register offset
36484edd8523SJack F Vogel  *  @locked: semaphore has already been acquired or not
36496c59e186SGuinan Sun  *  @page_set: BM_WUC_PAGE already set and access enabled
36509d81738fSJack F Vogel  *
36519d81738fSJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
36529d81738fSJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
36539d81738fSJack F Vogel  **/
__e1000_write_phy_reg_hv(struct e1000_hw * hw,u32 offset,u16 data,bool locked,bool page_set)36544edd8523SJack F Vogel static s32 __e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data,
36554dab5c37SJack F Vogel 				    bool locked, bool page_set)
36569d81738fSJack F Vogel {
36579d81738fSJack F Vogel 	s32 ret_val;
36589d81738fSJack F Vogel 	u16 page = BM_PHY_REG_PAGE(offset);
36599d81738fSJack F Vogel 	u16 reg = BM_PHY_REG_NUM(offset);
36604dab5c37SJack F Vogel 	u32 phy_addr = hw->phy.addr = e1000_get_phy_addr_for_hv_page(page);
36619d81738fSJack F Vogel 
3662a69ed8dfSJack F Vogel 	DEBUGFUNC("__e1000_write_phy_reg_hv");
36639d81738fSJack F Vogel 
36644edd8523SJack F Vogel 	if (!locked) {
36654edd8523SJack F Vogel 		ret_val = hw->phy.ops.acquire(hw);
36664edd8523SJack F Vogel 		if (ret_val)
36674edd8523SJack F Vogel 			return ret_val;
36684edd8523SJack F Vogel 	}
36699d81738fSJack F Vogel 	/* Page 800 works differently than the rest so it has its own func */
36709d81738fSJack F Vogel 	if (page == BM_WUC_PAGE) {
36714dab5c37SJack F Vogel 		ret_val = e1000_access_phy_wakeup_reg_bm(hw, offset, &data,
36721bbdc25fSKevin Bowling 							 false, page_set);
36739d81738fSJack F Vogel 		goto out;
36749d81738fSJack F Vogel 	}
36759d81738fSJack F Vogel 
36769d81738fSJack F Vogel 	if (page > 0 && page < HV_INTC_FC_PAGE_START) {
36779d81738fSJack F Vogel 		ret_val = e1000_access_phy_debug_regs_hv(hw, offset,
36781bbdc25fSKevin Bowling 							 &data, false);
36799d81738fSJack F Vogel 		goto out;
36809d81738fSJack F Vogel 	}
36819d81738fSJack F Vogel 
36824dab5c37SJack F Vogel 	if (!page_set) {
36839d81738fSJack F Vogel 		if (page == HV_INTC_FC_PAGE_START)
36849d81738fSJack F Vogel 			page = 0;
36859d81738fSJack F Vogel 
36866ab6bfe3SJack F Vogel 		/* Workaround MDIO accesses being disabled after entering IEEE
36874dab5c37SJack F Vogel 		 * Power Down (when bit 11 of the PHY Control register is set)
36889d81738fSJack F Vogel 		 */
36899d81738fSJack F Vogel 		if ((hw->phy.type == e1000_phy_82578) &&
36909d81738fSJack F Vogel 		    (hw->phy.revision >= 1) &&
36919d81738fSJack F Vogel 		    (hw->phy.addr == 2) &&
3692ab5d0362SJack F Vogel 		    !(MAX_PHY_REG_ADDRESS & reg) &&
36939d81738fSJack F Vogel 		    (data & (1 << 11))) {
36949d81738fSJack F Vogel 			u16 data2 = 0x7EFF;
36954dab5c37SJack F Vogel 			ret_val = e1000_access_phy_debug_regs_hv(hw,
36964dab5c37SJack F Vogel 								 (1 << 6) | 0x3,
36971bbdc25fSKevin Bowling 								 &data2, false);
36989d81738fSJack F Vogel 			if (ret_val)
36999d81738fSJack F Vogel 				goto out;
37009d81738fSJack F Vogel 		}
37019d81738fSJack F Vogel 
37029d81738fSJack F Vogel 		if (reg > MAX_PHY_MULTI_PAGE_REG) {
37039d81738fSJack F Vogel 			/* Page is shifted left, PHY expects (page x 32) */
37044dab5c37SJack F Vogel 			ret_val = e1000_set_page_igp(hw,
37059d81738fSJack F Vogel 						     (page << IGP_PAGE_SHIFT));
37064dab5c37SJack F Vogel 
37079d81738fSJack F Vogel 			hw->phy.addr = phy_addr;
37084edd8523SJack F Vogel 
37094edd8523SJack F Vogel 			if (ret_val)
37104edd8523SJack F Vogel 				goto out;
37119d81738fSJack F Vogel 		}
37124dab5c37SJack F Vogel 	}
37134dab5c37SJack F Vogel 
37144dab5c37SJack F Vogel 	DEBUGOUT3("writing PHY page %d (or 0x%x shifted) reg 0x%x\n", page,
37154dab5c37SJack F Vogel 		  page << IGP_PAGE_SHIFT, reg);
37169d81738fSJack F Vogel 
37179d81738fSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & reg,
37189d81738fSJack F Vogel 					   data);
37199d81738fSJack F Vogel 
37209d81738fSJack F Vogel out:
37214edd8523SJack F Vogel 	if (!locked)
37224edd8523SJack F Vogel 		hw->phy.ops.release(hw);
37239d81738fSJack F Vogel 
37249d81738fSJack F Vogel 	return ret_val;
37259d81738fSJack F Vogel }
37269d81738fSJack F Vogel 
37279d81738fSJack F Vogel /**
37284edd8523SJack F Vogel  *  e1000_write_phy_reg_hv - Write HV PHY register
37294edd8523SJack F Vogel  *  @hw: pointer to the HW structure
37304edd8523SJack F Vogel  *  @offset: register offset to write to
37314edd8523SJack F Vogel  *  @data: data to write at register offset
37324edd8523SJack F Vogel  *
37334edd8523SJack F Vogel  *  Acquires semaphore then writes the data to PHY register at the offset.
37344edd8523SJack F Vogel  *  Release the acquired semaphores before exiting.
37354edd8523SJack F Vogel  **/
e1000_write_phy_reg_hv(struct e1000_hw * hw,u32 offset,u16 data)37364edd8523SJack F Vogel s32 e1000_write_phy_reg_hv(struct e1000_hw *hw, u32 offset, u16 data)
37374edd8523SJack F Vogel {
37381bbdc25fSKevin Bowling 	return __e1000_write_phy_reg_hv(hw, offset, data, false, false);
37394edd8523SJack F Vogel }
37404edd8523SJack F Vogel 
37414edd8523SJack F Vogel /**
37424edd8523SJack F Vogel  *  e1000_write_phy_reg_hv_locked - Write HV PHY register
37434edd8523SJack F Vogel  *  @hw: pointer to the HW structure
37444edd8523SJack F Vogel  *  @offset: register offset to write to
37454edd8523SJack F Vogel  *  @data: data to write at register offset
37464edd8523SJack F Vogel  *
37474edd8523SJack F Vogel  *  Writes the data to PHY register at the offset.  Assumes semaphore
37484edd8523SJack F Vogel  *  already acquired.
37494edd8523SJack F Vogel  **/
e1000_write_phy_reg_hv_locked(struct e1000_hw * hw,u32 offset,u16 data)37504edd8523SJack F Vogel s32 e1000_write_phy_reg_hv_locked(struct e1000_hw *hw, u32 offset, u16 data)
37514edd8523SJack F Vogel {
37521bbdc25fSKevin Bowling 	return __e1000_write_phy_reg_hv(hw, offset, data, true, false);
37534dab5c37SJack F Vogel }
37544dab5c37SJack F Vogel 
37554dab5c37SJack F Vogel /**
37564dab5c37SJack F Vogel  *  e1000_write_phy_reg_page_hv - Write HV PHY register
37574dab5c37SJack F Vogel  *  @hw: pointer to the HW structure
37584dab5c37SJack F Vogel  *  @offset: register offset to write to
37594dab5c37SJack F Vogel  *  @data: data to write at register offset
37604dab5c37SJack F Vogel  *
37614dab5c37SJack F Vogel  *  Writes the data to PHY register at the offset.  Assumes semaphore
37624dab5c37SJack F Vogel  *  already acquired and page already set.
37634dab5c37SJack F Vogel  **/
e1000_write_phy_reg_page_hv(struct e1000_hw * hw,u32 offset,u16 data)37644dab5c37SJack F Vogel s32 e1000_write_phy_reg_page_hv(struct e1000_hw *hw, u32 offset, u16 data)
37654dab5c37SJack F Vogel {
37661bbdc25fSKevin Bowling 	return __e1000_write_phy_reg_hv(hw, offset, data, true, true);
37674edd8523SJack F Vogel }
37684edd8523SJack F Vogel 
37694edd8523SJack F Vogel /**
37709d81738fSJack F Vogel  *  e1000_get_phy_addr_for_hv_page - Get PHY adrress based on page
37719d81738fSJack F Vogel  *  @page: page to be accessed
37729d81738fSJack F Vogel  **/
e1000_get_phy_addr_for_hv_page(u32 page)37739d81738fSJack F Vogel static u32 e1000_get_phy_addr_for_hv_page(u32 page)
37749d81738fSJack F Vogel {
37759d81738fSJack F Vogel 	u32 phy_addr = 2;
37769d81738fSJack F Vogel 
37779d81738fSJack F Vogel 	if (page >= HV_INTC_FC_PAGE_START)
37789d81738fSJack F Vogel 		phy_addr = 1;
37799d81738fSJack F Vogel 
37809d81738fSJack F Vogel 	return phy_addr;
37819d81738fSJack F Vogel }
37829d81738fSJack F Vogel 
37839d81738fSJack F Vogel /**
37849d81738fSJack F Vogel  *  e1000_access_phy_debug_regs_hv - Read HV PHY vendor specific high registers
37859d81738fSJack F Vogel  *  @hw: pointer to the HW structure
37869d81738fSJack F Vogel  *  @offset: register offset to be read or written
37879d81738fSJack F Vogel  *  @data: pointer to the data to be read or written
37884dab5c37SJack F Vogel  *  @read: determines if operation is read or write
37899d81738fSJack F Vogel  *
37904edd8523SJack F Vogel  *  Reads the PHY register at offset and stores the retreived information
37914edd8523SJack F Vogel  *  in data.  Assumes semaphore already acquired.  Note that the procedure
37924dab5c37SJack F Vogel  *  to access these regs uses the address port and data port to read/write.
37934dab5c37SJack F Vogel  *  These accesses done with PHY address 2 and without using pages.
37949d81738fSJack F Vogel  **/
e1000_access_phy_debug_regs_hv(struct e1000_hw * hw,u32 offset,u16 * data,bool read)37959d81738fSJack F Vogel static s32 e1000_access_phy_debug_regs_hv(struct e1000_hw *hw, u32 offset,
37969d81738fSJack F Vogel 					  u16 *data, bool read)
37979d81738fSJack F Vogel {
37989d81738fSJack F Vogel 	s32 ret_val;
37996ab6bfe3SJack F Vogel 	u32 addr_reg;
38006ab6bfe3SJack F Vogel 	u32 data_reg;
38019d81738fSJack F Vogel 
38029d81738fSJack F Vogel 	DEBUGFUNC("e1000_access_phy_debug_regs_hv");
38039d81738fSJack F Vogel 
38049d81738fSJack F Vogel 	/* This takes care of the difference with desktop vs mobile phy */
38057609433eSJack F Vogel 	addr_reg = ((hw->phy.type == e1000_phy_82578) ?
38067609433eSJack F Vogel 		    I82578_ADDR_REG : I82577_ADDR_REG);
38079d81738fSJack F Vogel 	data_reg = addr_reg + 1;
38089d81738fSJack F Vogel 
38099d81738fSJack F Vogel 	/* All operations in this function are phy address 2 */
38109d81738fSJack F Vogel 	hw->phy.addr = 2;
38119d81738fSJack F Vogel 
38129d81738fSJack F Vogel 	/* masking with 0x3F to remove the page from offset */
38139d81738fSJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, addr_reg, (u16)offset & 0x3F);
38149d81738fSJack F Vogel 	if (ret_val) {
38154dab5c37SJack F Vogel 		DEBUGOUT("Could not write the Address Offset port register\n");
3816ab5d0362SJack F Vogel 		return ret_val;
38179d81738fSJack F Vogel 	}
38189d81738fSJack F Vogel 
38199d81738fSJack F Vogel 	/* Read or write the data value next */
38209d81738fSJack F Vogel 	if (read)
38219d81738fSJack F Vogel 		ret_val = e1000_read_phy_reg_mdic(hw, data_reg, data);
38229d81738fSJack F Vogel 	else
38239d81738fSJack F Vogel 		ret_val = e1000_write_phy_reg_mdic(hw, data_reg, *data);
38249d81738fSJack F Vogel 
3825ab5d0362SJack F Vogel 	if (ret_val)
38264dab5c37SJack F Vogel 		DEBUGOUT("Could not access the Data port register\n");
38279d81738fSJack F Vogel 
38289d81738fSJack F Vogel 	return ret_val;
38299d81738fSJack F Vogel }
38309d81738fSJack F Vogel 
38319d81738fSJack F Vogel /**
38329d81738fSJack F Vogel  *  e1000_link_stall_workaround_hv - Si workaround
38339d81738fSJack F Vogel  *  @hw: pointer to the HW structure
38349d81738fSJack F Vogel  *
38359d81738fSJack F Vogel  *  This function works around a Si bug where the link partner can get
38369d81738fSJack F Vogel  *  a link up indication before the PHY does.  If small packets are sent
38379d81738fSJack F Vogel  *  by the link partner they can be placed in the packet buffer without
38389d81738fSJack F Vogel  *  being properly accounted for by the PHY and will stall preventing
38399d81738fSJack F Vogel  *  further packets from being received.  The workaround is to clear the
38409d81738fSJack F Vogel  *  packet buffer after the PHY detects link up.
38419d81738fSJack F Vogel  **/
e1000_link_stall_workaround_hv(struct e1000_hw * hw)38429d81738fSJack F Vogel s32 e1000_link_stall_workaround_hv(struct e1000_hw *hw)
38439d81738fSJack F Vogel {
38449d81738fSJack F Vogel 	s32 ret_val = E1000_SUCCESS;
38459d81738fSJack F Vogel 	u16 data;
38469d81738fSJack F Vogel 
38479d81738fSJack F Vogel 	DEBUGFUNC("e1000_link_stall_workaround_hv");
38489d81738fSJack F Vogel 
38499d81738fSJack F Vogel 	if (hw->phy.type != e1000_phy_82578)
3850ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38519d81738fSJack F Vogel 
38529d81738fSJack F Vogel 	/* Do not apply workaround if in PHY loopback bit 14 set */
38539d81738fSJack F Vogel 	hw->phy.ops.read_reg(hw, PHY_CONTROL, &data);
38549d81738fSJack F Vogel 	if (data & PHY_CONTROL_LB)
3855ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38569d81738fSJack F Vogel 
38579d81738fSJack F Vogel 	/* check if link is up and at 1Gbps */
38589d81738fSJack F Vogel 	ret_val = hw->phy.ops.read_reg(hw, BM_CS_STATUS, &data);
38599d81738fSJack F Vogel 	if (ret_val)
3860ab5d0362SJack F Vogel 		return ret_val;
38619d81738fSJack F Vogel 
38627609433eSJack F Vogel 	data &= (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
38637609433eSJack F Vogel 		 BM_CS_STATUS_SPEED_MASK);
38649d81738fSJack F Vogel 
38654dab5c37SJack F Vogel 	if (data != (BM_CS_STATUS_LINK_UP | BM_CS_STATUS_RESOLVED |
38669d81738fSJack F Vogel 		     BM_CS_STATUS_SPEED_1000))
3867ab5d0362SJack F Vogel 		return E1000_SUCCESS;
38689d81738fSJack F Vogel 
38699d81738fSJack F Vogel 	msec_delay(200);
38709d81738fSJack F Vogel 
38719d81738fSJack F Vogel 	/* flush the packets in the fifo buffer */
38729d81738fSJack F Vogel 	ret_val = hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
38736ab6bfe3SJack F Vogel 					(HV_MUX_DATA_CTRL_GEN_TO_MAC |
38746ab6bfe3SJack F Vogel 					 HV_MUX_DATA_CTRL_FORCE_SPEED));
38759d81738fSJack F Vogel 	if (ret_val)
38769d81738fSJack F Vogel 		return ret_val;
3877ab5d0362SJack F Vogel 
3878ab5d0362SJack F Vogel 	return hw->phy.ops.write_reg(hw, HV_MUX_DATA_CTRL,
3879ab5d0362SJack F Vogel 				     HV_MUX_DATA_CTRL_GEN_TO_MAC);
38809d81738fSJack F Vogel }
38819d81738fSJack F Vogel 
38829d81738fSJack F Vogel /**
38839d81738fSJack F Vogel  *  e1000_check_polarity_82577 - Checks the polarity.
38849d81738fSJack F Vogel  *  @hw: pointer to the HW structure
38859d81738fSJack F Vogel  *
38869d81738fSJack F Vogel  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
38879d81738fSJack F Vogel  *
38889d81738fSJack F Vogel  *  Polarity is determined based on the PHY specific status register.
38899d81738fSJack F Vogel  **/
e1000_check_polarity_82577(struct e1000_hw * hw)38909d81738fSJack F Vogel s32 e1000_check_polarity_82577(struct e1000_hw *hw)
38919d81738fSJack F Vogel {
38929d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
38939d81738fSJack F Vogel 	s32 ret_val;
38949d81738fSJack F Vogel 	u16 data;
38959d81738fSJack F Vogel 
38969d81738fSJack F Vogel 	DEBUGFUNC("e1000_check_polarity_82577");
38979d81738fSJack F Vogel 
38989d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, I82577_PHY_STATUS_2, &data);
38999d81738fSJack F Vogel 
39009d81738fSJack F Vogel 	if (!ret_val)
39017609433eSJack F Vogel 		phy->cable_polarity = ((data & I82577_PHY_STATUS2_REV_POLARITY)
39029d81738fSJack F Vogel 				       ? e1000_rev_polarity_reversed
39037609433eSJack F Vogel 				       : e1000_rev_polarity_normal);
39049d81738fSJack F Vogel 
39059d81738fSJack F Vogel 	return ret_val;
39069d81738fSJack F Vogel }
39079d81738fSJack F Vogel 
39089d81738fSJack F Vogel /**
39099d81738fSJack F Vogel  *  e1000_phy_force_speed_duplex_82577 - Force speed/duplex for I82577 PHY
39109d81738fSJack F Vogel  *  @hw: pointer to the HW structure
39119d81738fSJack F Vogel  *
39128ec87fc5SJack F Vogel  *  Calls the PHY setup function to force speed and duplex.
39139d81738fSJack F Vogel  **/
e1000_phy_force_speed_duplex_82577(struct e1000_hw * hw)39149d81738fSJack F Vogel s32 e1000_phy_force_speed_duplex_82577(struct e1000_hw *hw)
39159d81738fSJack F Vogel {
39169d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
39179d81738fSJack F Vogel 	s32 ret_val;
39189d81738fSJack F Vogel 	u16 phy_data;
39199d81738fSJack F Vogel 	bool link;
39209d81738fSJack F Vogel 
39219d81738fSJack F Vogel 	DEBUGFUNC("e1000_phy_force_speed_duplex_82577");
39229d81738fSJack F Vogel 
39239d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
39249d81738fSJack F Vogel 	if (ret_val)
3925ab5d0362SJack F Vogel 		return ret_val;
39269d81738fSJack F Vogel 
39279d81738fSJack F Vogel 	e1000_phy_force_speed_duplex_setup(hw, &phy_data);
39289d81738fSJack F Vogel 
39299d81738fSJack F Vogel 	ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
39309d81738fSJack F Vogel 	if (ret_val)
3931ab5d0362SJack F Vogel 		return ret_val;
39329d81738fSJack F Vogel 
39339d81738fSJack F Vogel 	usec_delay(1);
39349d81738fSJack F Vogel 
39359d81738fSJack F Vogel 	if (phy->autoneg_wait_to_complete) {
39369d81738fSJack F Vogel 		DEBUGOUT("Waiting for forced speed/duplex link on 82577 phy\n");
39379d81738fSJack F Vogel 
39384dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
39394dab5c37SJack F Vogel 						     100000, &link);
39409d81738fSJack F Vogel 		if (ret_val)
3941ab5d0362SJack F Vogel 			return ret_val;
39429d81738fSJack F Vogel 
39439d81738fSJack F Vogel 		if (!link)
39449d81738fSJack F Vogel 			DEBUGOUT("Link taking longer than expected.\n");
39459d81738fSJack F Vogel 
39469d81738fSJack F Vogel 		/* Try once more */
39474dab5c37SJack F Vogel 		ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
39484dab5c37SJack F Vogel 						     100000, &link);
39499d81738fSJack F Vogel 	}
39509d81738fSJack F Vogel 
39519d81738fSJack F Vogel 	return ret_val;
39529d81738fSJack F Vogel }
39539d81738fSJack F Vogel 
39549d81738fSJack F Vogel /**
39559d81738fSJack F Vogel  *  e1000_get_phy_info_82577 - Retrieve I82577 PHY information
39569d81738fSJack F Vogel  *  @hw: pointer to the HW structure
39579d81738fSJack F Vogel  *
39589d81738fSJack F Vogel  *  Read PHY status to determine if link is up.  If link is up, then
39599d81738fSJack F Vogel  *  set/determine 10base-T extended distance and polarity correction.  Read
39609d81738fSJack F Vogel  *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
39619d81738fSJack F Vogel  *  determine on the cable length, local and remote receiver.
39629d81738fSJack F Vogel  **/
e1000_get_phy_info_82577(struct e1000_hw * hw)39639d81738fSJack F Vogel s32 e1000_get_phy_info_82577(struct e1000_hw *hw)
39649d81738fSJack F Vogel {
39659d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
39669d81738fSJack F Vogel 	s32 ret_val;
39679d81738fSJack F Vogel 	u16 data;
39689d81738fSJack F Vogel 	bool link;
39699d81738fSJack F Vogel 
39709d81738fSJack F Vogel 	DEBUGFUNC("e1000_get_phy_info_82577");
39719d81738fSJack F Vogel 
39729d81738fSJack F Vogel 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
39739d81738fSJack F Vogel 	if (ret_val)
3974ab5d0362SJack F Vogel 		return ret_val;
39759d81738fSJack F Vogel 
39769d81738fSJack F Vogel 	if (!link) {
39779d81738fSJack F Vogel 		DEBUGOUT("Phy info is only valid if link is up\n");
3978ab5d0362SJack F Vogel 		return -E1000_ERR_CONFIG;
39799d81738fSJack F Vogel 	}
39809d81738fSJack F Vogel 
39811bbdc25fSKevin Bowling 	phy->polarity_correction = true;
39829d81738fSJack F Vogel 
39839d81738fSJack F Vogel 	ret_val = e1000_check_polarity_82577(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, I82577_PHY_STATUS_2, &data);
39889d81738fSJack F Vogel 	if (ret_val)
3989ab5d0362SJack F Vogel 		return ret_val;
39909d81738fSJack F Vogel 
3991ab5d0362SJack F Vogel 	phy->is_mdix = !!(data & I82577_PHY_STATUS2_MDIX);
39929d81738fSJack F Vogel 
39939d81738fSJack F Vogel 	if ((data & I82577_PHY_STATUS2_SPEED_MASK) ==
39949d81738fSJack F Vogel 	    I82577_PHY_STATUS2_SPEED_1000MBPS) {
39959d81738fSJack F Vogel 		ret_val = hw->phy.ops.get_cable_length(hw);
39969d81738fSJack F Vogel 		if (ret_val)
3997ab5d0362SJack F Vogel 			return ret_val;
39989d81738fSJack F Vogel 
39999d81738fSJack F Vogel 		ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
40009d81738fSJack F Vogel 		if (ret_val)
4001ab5d0362SJack F Vogel 			return ret_val;
40029d81738fSJack F Vogel 
40039d81738fSJack F Vogel 		phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
40049d81738fSJack F Vogel 				? e1000_1000t_rx_status_ok
40059d81738fSJack F Vogel 				: e1000_1000t_rx_status_not_ok;
40069d81738fSJack F Vogel 
40079d81738fSJack F Vogel 		phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
40089d81738fSJack F Vogel 				 ? e1000_1000t_rx_status_ok
40099d81738fSJack F Vogel 				 : e1000_1000t_rx_status_not_ok;
40109d81738fSJack F Vogel 	} else {
40119d81738fSJack F Vogel 		phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
40129d81738fSJack F Vogel 		phy->local_rx = e1000_1000t_rx_status_undefined;
40139d81738fSJack F Vogel 		phy->remote_rx = e1000_1000t_rx_status_undefined;
40149d81738fSJack F Vogel 	}
40159d81738fSJack F Vogel 
4016ab5d0362SJack F Vogel 	return E1000_SUCCESS;
40179d81738fSJack F Vogel }
40189d81738fSJack F Vogel 
40199d81738fSJack F Vogel /**
40209d81738fSJack F Vogel  *  e1000_get_cable_length_82577 - Determine cable length for 82577 PHY
40219d81738fSJack F Vogel  *  @hw: pointer to the HW structure
40229d81738fSJack F Vogel  *
40239d81738fSJack F Vogel  * Reads the diagnostic status register and verifies result is valid before
40249d81738fSJack F Vogel  * placing it in the phy_cable_length field.
40259d81738fSJack F Vogel  **/
e1000_get_cable_length_82577(struct e1000_hw * hw)40269d81738fSJack F Vogel s32 e1000_get_cable_length_82577(struct e1000_hw *hw)
40279d81738fSJack F Vogel {
40289d81738fSJack F Vogel 	struct e1000_phy_info *phy = &hw->phy;
40299d81738fSJack F Vogel 	s32 ret_val;
40309d81738fSJack F Vogel 	u16 phy_data, length;
40319d81738fSJack F Vogel 
40329d81738fSJack F Vogel 	DEBUGFUNC("e1000_get_cable_length_82577");
40339d81738fSJack F Vogel 
40349d81738fSJack F Vogel 	ret_val = phy->ops.read_reg(hw, I82577_PHY_DIAG_STATUS, &phy_data);
40359d81738fSJack F Vogel 	if (ret_val)
4036ab5d0362SJack F Vogel 		return ret_val;
40379d81738fSJack F Vogel 
40387609433eSJack F Vogel 	length = ((phy_data & I82577_DSTATUS_CABLE_LENGTH) >>
40397609433eSJack F Vogel 		  I82577_DSTATUS_CABLE_LENGTH_SHIFT);
40409d81738fSJack F Vogel 
40419d81738fSJack F Vogel 	if (length == E1000_CABLE_LENGTH_UNDEFINED)
40426ab6bfe3SJack F Vogel 		return -E1000_ERR_PHY;
40439d81738fSJack F Vogel 
40449d81738fSJack F Vogel 	phy->cable_length = length;
40459d81738fSJack F Vogel 
4046ab5d0362SJack F Vogel 	return E1000_SUCCESS;
4047ab5d0362SJack F Vogel }
4048ab5d0362SJack F Vogel 
4049ab5d0362SJack F Vogel /**
4050ab5d0362SJack F Vogel  *  e1000_write_phy_reg_gs40g - Write GS40G  PHY register
4051ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
4052ab5d0362SJack F Vogel  *  @offset: register offset to write to
4053ab5d0362SJack F Vogel  *  @data: data to write at register offset
4054ab5d0362SJack F Vogel  *
4055ab5d0362SJack F Vogel  *  Acquires semaphore, if necessary, then writes the data to PHY register
4056ab5d0362SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
4057ab5d0362SJack F Vogel  **/
e1000_write_phy_reg_gs40g(struct e1000_hw * hw,u32 offset,u16 data)4058ab5d0362SJack F Vogel s32 e1000_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data)
4059ab5d0362SJack F Vogel {
4060ab5d0362SJack F Vogel 	s32 ret_val;
4061ab5d0362SJack F Vogel 	u16 page = offset >> GS40G_PAGE_SHIFT;
4062ab5d0362SJack F Vogel 
4063ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_gs40g");
4064ab5d0362SJack F Vogel 
4065ab5d0362SJack F Vogel 	offset = offset & GS40G_OFFSET_MASK;
4066ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
4067ab5d0362SJack F Vogel 	if (ret_val)
4068ab5d0362SJack F Vogel 		return ret_val;
4069ab5d0362SJack F Vogel 
4070ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4071ab5d0362SJack F Vogel 	if (ret_val)
4072ab5d0362SJack F Vogel 		goto release;
4073ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, offset, data);
4074ab5d0362SJack F Vogel 
4075ab5d0362SJack F Vogel release:
4076ab5d0362SJack F Vogel 	hw->phy.ops.release(hw);
4077ab5d0362SJack F Vogel 	return ret_val;
4078ab5d0362SJack F Vogel }
4079ab5d0362SJack F Vogel 
4080ab5d0362SJack F Vogel /**
4081ab5d0362SJack F Vogel  *  e1000_read_phy_reg_gs40g - Read GS40G  PHY register
4082ab5d0362SJack F Vogel  *  @hw: pointer to the HW structure
4083ab5d0362SJack F Vogel  *  @offset: lower half is register offset to read to
4084ab5d0362SJack F Vogel  *     upper half is page to use.
4085ab5d0362SJack F Vogel  *  @data: data to read at register offset
4086ab5d0362SJack F Vogel  *
4087ab5d0362SJack F Vogel  *  Acquires semaphore, if necessary, then reads the data in the PHY register
4088ab5d0362SJack F Vogel  *  at the offset.  Release any acquired semaphores before exiting.
4089ab5d0362SJack F Vogel  **/
e1000_read_phy_reg_gs40g(struct e1000_hw * hw,u32 offset,u16 * data)4090ab5d0362SJack F Vogel s32 e1000_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data)
4091ab5d0362SJack F Vogel {
4092ab5d0362SJack F Vogel 	s32 ret_val;
4093ab5d0362SJack F Vogel 	u16 page = offset >> GS40G_PAGE_SHIFT;
4094ab5d0362SJack F Vogel 
4095ab5d0362SJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_gs40g");
4096ab5d0362SJack F Vogel 
4097ab5d0362SJack F Vogel 	offset = offset & GS40G_OFFSET_MASK;
4098ab5d0362SJack F Vogel 	ret_val = hw->phy.ops.acquire(hw);
4099ab5d0362SJack F Vogel 	if (ret_val)
4100ab5d0362SJack F Vogel 		return ret_val;
4101ab5d0362SJack F Vogel 
4102ab5d0362SJack F Vogel 	ret_val = e1000_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page);
4103ab5d0362SJack F Vogel 	if (ret_val)
4104ab5d0362SJack F Vogel 		goto release;
4105ab5d0362SJack F Vogel 	ret_val = e1000_read_phy_reg_mdic(hw, offset, data);
4106ab5d0362SJack F Vogel 
4107ab5d0362SJack F Vogel release:
4108ab5d0362SJack F Vogel 	hw->phy.ops.release(hw);
41099d81738fSJack F Vogel 	return ret_val;
41109d81738fSJack F Vogel }
41116ab6bfe3SJack F Vogel 
41127609433eSJack F Vogel /**
41137609433eSJack F Vogel  *  e1000_read_phy_reg_mphy - Read mPHY control register
41147609433eSJack F Vogel  *  @hw: pointer to the HW structure
41157609433eSJack F Vogel  *  @address: address to be read
41167609433eSJack F Vogel  *  @data: pointer to the read data
41177609433eSJack F Vogel  *
41187609433eSJack F Vogel  *  Reads the mPHY control register in the PHY at offset and stores the
41197609433eSJack F Vogel  *  information read to data.
41207609433eSJack F Vogel  **/
e1000_read_phy_reg_mphy(struct e1000_hw * hw,u32 address,u32 * data)41217609433eSJack F Vogel s32 e1000_read_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 *data)
41227609433eSJack F Vogel {
41237609433eSJack F Vogel 	u32 mphy_ctrl = 0;
41241bbdc25fSKevin Bowling 	bool locked = false;
41258cc64f1eSJack F Vogel 	bool ready;
41267609433eSJack F Vogel 
41277609433eSJack F Vogel 	DEBUGFUNC("e1000_read_phy_reg_mphy");
41287609433eSJack F Vogel 
41297609433eSJack F Vogel 	/* Check if mPHY is ready to read/write operations */
41307609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41317609433eSJack F Vogel 	if (!ready)
41327609433eSJack F Vogel 		return -E1000_ERR_PHY;
41337609433eSJack F Vogel 
41347609433eSJack F Vogel 	/* Check if mPHY access is disabled and enable it if so */
41357609433eSJack F Vogel 	mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
41367609433eSJack F Vogel 	if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
41371bbdc25fSKevin Bowling 		locked = true;
41387609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
41397609433eSJack F Vogel 		if (!ready)
41407609433eSJack F Vogel 			return -E1000_ERR_PHY;
41417609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
41427609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
41437609433eSJack F Vogel 	}
41447609433eSJack F Vogel 
41457609433eSJack F Vogel 	/* Set the address that we want to read */
41467609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41477609433eSJack F Vogel 	if (!ready)
41487609433eSJack F Vogel 		return -E1000_ERR_PHY;
41497609433eSJack F Vogel 
41507609433eSJack F Vogel 	/* We mask address, because we want to use only current lane */
41517609433eSJack F Vogel 	mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK &
41527609433eSJack F Vogel 		~E1000_MPHY_ADDRESS_FNC_OVERRIDE) |
41537609433eSJack F Vogel 		(address & E1000_MPHY_ADDRESS_MASK);
41547609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
41557609433eSJack F Vogel 
41567609433eSJack F Vogel 	/* Read data from the address */
41577609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41587609433eSJack F Vogel 	if (!ready)
41597609433eSJack F Vogel 		return -E1000_ERR_PHY;
41607609433eSJack F Vogel 	*data = E1000_READ_REG(hw, E1000_MPHY_DATA);
41617609433eSJack F Vogel 
41627609433eSJack F Vogel 	/* Disable access to mPHY if it was originally disabled */
4163a4378873SKevin Bowling 	if (locked)
41647609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
41657609433eSJack F Vogel 	if (!ready)
41667609433eSJack F Vogel 		return -E1000_ERR_PHY;
4167e760e292SSean Bruno 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
4168e760e292SSean Bruno 			E1000_MPHY_DIS_ACCESS);
4169e760e292SSean Bruno 
41707609433eSJack F Vogel 	return E1000_SUCCESS;
41717609433eSJack F Vogel }
41727609433eSJack F Vogel 
41737609433eSJack F Vogel /**
41747609433eSJack F Vogel  *  e1000_write_phy_reg_mphy - Write mPHY control register
41757609433eSJack F Vogel  *  @hw: pointer to the HW structure
41767609433eSJack F Vogel  *  @address: address to write to
41777609433eSJack F Vogel  *  @data: data to write to register at offset
41787609433eSJack F Vogel  *  @line_override: used when we want to use different line than default one
41797609433eSJack F Vogel  *
41807609433eSJack F Vogel  *  Writes data to mPHY control register.
41817609433eSJack F Vogel  **/
e1000_write_phy_reg_mphy(struct e1000_hw * hw,u32 address,u32 data,bool line_override)41827609433eSJack F Vogel s32 e1000_write_phy_reg_mphy(struct e1000_hw *hw, u32 address, u32 data,
41837609433eSJack F Vogel 			     bool line_override)
41847609433eSJack F Vogel {
41857609433eSJack F Vogel 	u32 mphy_ctrl = 0;
41861bbdc25fSKevin Bowling 	bool locked = false;
41878cc64f1eSJack F Vogel 	bool ready;
41887609433eSJack F Vogel 
41897609433eSJack F Vogel 	DEBUGFUNC("e1000_write_phy_reg_mphy");
41907609433eSJack F Vogel 
41917609433eSJack F Vogel 	/* Check if mPHY is ready to read/write operations */
41927609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
41937609433eSJack F Vogel 	if (!ready)
41947609433eSJack F Vogel 		return -E1000_ERR_PHY;
41957609433eSJack F Vogel 
41967609433eSJack F Vogel 	/* Check if mPHY access is disabled and enable it if so */
41977609433eSJack F Vogel 	mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
41987609433eSJack F Vogel 	if (mphy_ctrl & E1000_MPHY_DIS_ACCESS) {
41991bbdc25fSKevin Bowling 		locked = true;
42007609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
42017609433eSJack F Vogel 		if (!ready)
42027609433eSJack F Vogel 			return -E1000_ERR_PHY;
42037609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ENA_ACCESS;
42047609433eSJack F Vogel 		E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
42057609433eSJack F Vogel 	}
42067609433eSJack F Vogel 
42077609433eSJack F Vogel 	/* Set the address that we want to read */
42087609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
42097609433eSJack F Vogel 	if (!ready)
42107609433eSJack F Vogel 		return -E1000_ERR_PHY;
42117609433eSJack F Vogel 
42127609433eSJack F Vogel 	/* We mask address, because we want to use only current lane */
42137609433eSJack F Vogel 	if (line_override)
42147609433eSJack F Vogel 		mphy_ctrl |= E1000_MPHY_ADDRESS_FNC_OVERRIDE;
42157609433eSJack F Vogel 	else
42167609433eSJack F Vogel 		mphy_ctrl &= ~E1000_MPHY_ADDRESS_FNC_OVERRIDE;
42177609433eSJack F Vogel 	mphy_ctrl = (mphy_ctrl & ~E1000_MPHY_ADDRESS_MASK) |
42187609433eSJack F Vogel 		(address & E1000_MPHY_ADDRESS_MASK);
42197609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL, mphy_ctrl);
42207609433eSJack F Vogel 
42217609433eSJack F Vogel 	/* Read data from the address */
42227609433eSJack F Vogel 	ready = e1000_is_mphy_ready(hw);
42237609433eSJack F Vogel 	if (!ready)
42247609433eSJack F Vogel 		return -E1000_ERR_PHY;
42257609433eSJack F Vogel 	E1000_WRITE_REG(hw, E1000_MPHY_DATA, data);
42267609433eSJack F Vogel 
42277609433eSJack F Vogel 	/* Disable access to mPHY if it was originally disabled */
4228a4378873SKevin Bowling 	if (locked)
42297609433eSJack F Vogel 		ready = e1000_is_mphy_ready(hw);
42307609433eSJack F Vogel 	if (!ready)
42317609433eSJack F Vogel 		return -E1000_ERR_PHY;
4232e760e292SSean Bruno 	E1000_WRITE_REG(hw, E1000_MPHY_ADDR_CTRL,
4233e760e292SSean Bruno 			E1000_MPHY_DIS_ACCESS);
4234e760e292SSean Bruno 
42357609433eSJack F Vogel 	return E1000_SUCCESS;
42367609433eSJack F Vogel }
42377609433eSJack F Vogel 
42387609433eSJack F Vogel /**
42397609433eSJack F Vogel  *  e1000_is_mphy_ready - Check if mPHY control register is not busy
42407609433eSJack F Vogel  *  @hw: pointer to the HW structure
42417609433eSJack F Vogel  *
42427609433eSJack F Vogel  *  Returns mPHY control register status.
42437609433eSJack F Vogel  **/
e1000_is_mphy_ready(struct e1000_hw * hw)42447609433eSJack F Vogel bool e1000_is_mphy_ready(struct e1000_hw *hw)
42457609433eSJack F Vogel {
42467609433eSJack F Vogel 	u16 retry_count = 0;
42477609433eSJack F Vogel 	u32 mphy_ctrl = 0;
42481bbdc25fSKevin Bowling 	bool ready = false;
42497609433eSJack F Vogel 
42507609433eSJack F Vogel 	while (retry_count < 2) {
42517609433eSJack F Vogel 		mphy_ctrl = E1000_READ_REG(hw, E1000_MPHY_ADDR_CTRL);
42527609433eSJack F Vogel 		if (mphy_ctrl & E1000_MPHY_BUSY) {
42537609433eSJack F Vogel 			usec_delay(20);
42547609433eSJack F Vogel 			retry_count++;
42557609433eSJack F Vogel 			continue;
42567609433eSJack F Vogel 		}
42571bbdc25fSKevin Bowling 		ready = true;
42587609433eSJack F Vogel 		break;
42597609433eSJack F Vogel 	}
42607609433eSJack F Vogel 
42617609433eSJack F Vogel 	if (!ready)
42627609433eSJack F Vogel 		DEBUGOUT("ERROR READING mPHY control register, phy is busy.\n");
42637609433eSJack F Vogel 
42647609433eSJack F Vogel 	return ready;
42657609433eSJack F Vogel }
4266da24467cSGuinan Sun 
4267da24467cSGuinan Sun /**
4268da24467cSGuinan Sun  *  __e1000_access_xmdio_reg - Read/write XMDIO register
4269da24467cSGuinan Sun  *  @hw: pointer to the HW structure
4270da24467cSGuinan Sun  *  @address: XMDIO address to program
4271da24467cSGuinan Sun  *  @dev_addr: device address to program
4272da24467cSGuinan Sun  *  @data: pointer to value to read/write from/to the XMDIO address
4273da24467cSGuinan Sun  *  @read: boolean flag to indicate read or write
4274da24467cSGuinan Sun  **/
__e1000_access_xmdio_reg(struct e1000_hw * hw,u16 address,u8 dev_addr,u16 * data,bool read)4275da24467cSGuinan Sun static s32 __e1000_access_xmdio_reg(struct e1000_hw *hw, u16 address,
4276da24467cSGuinan Sun 				    u8 dev_addr, u16 *data, bool read)
4277da24467cSGuinan Sun {
4278da24467cSGuinan Sun 	s32 ret_val;
4279da24467cSGuinan Sun 
4280da24467cSGuinan Sun 	DEBUGFUNC("__e1000_access_xmdio_reg");
4281da24467cSGuinan Sun 
4282da24467cSGuinan Sun 	ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, dev_addr);
4283da24467cSGuinan Sun 	if (ret_val)
4284da24467cSGuinan Sun 		return ret_val;
4285da24467cSGuinan Sun 
4286da24467cSGuinan Sun 	ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, address);
4287da24467cSGuinan Sun 	if (ret_val)
4288da24467cSGuinan Sun 		return ret_val;
4289da24467cSGuinan Sun 
4290da24467cSGuinan Sun 	ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, E1000_MMDAC_FUNC_DATA |
4291da24467cSGuinan Sun 					dev_addr);
4292da24467cSGuinan Sun 	if (ret_val)
4293da24467cSGuinan Sun 		return ret_val;
4294da24467cSGuinan Sun 
4295da24467cSGuinan Sun 	if (read)
4296da24467cSGuinan Sun 		ret_val = hw->phy.ops.read_reg(hw, E1000_MMDAAD, data);
4297da24467cSGuinan Sun 	else
4298da24467cSGuinan Sun 		ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAAD, *data);
4299da24467cSGuinan Sun 	if (ret_val)
4300da24467cSGuinan Sun 		return ret_val;
4301da24467cSGuinan Sun 
4302da24467cSGuinan Sun 	/* Recalibrate the device back to 0 */
4303da24467cSGuinan Sun 	ret_val = hw->phy.ops.write_reg(hw, E1000_MMDAC, 0);
4304da24467cSGuinan Sun 	if (ret_val)
4305da24467cSGuinan Sun 		return ret_val;
4306da24467cSGuinan Sun 
4307da24467cSGuinan Sun 	return ret_val;
4308da24467cSGuinan Sun }
4309da24467cSGuinan Sun 
4310da24467cSGuinan Sun /**
4311da24467cSGuinan Sun  *  e1000_read_xmdio_reg - Read XMDIO register
4312da24467cSGuinan Sun  *  @hw: pointer to the HW structure
4313da24467cSGuinan Sun  *  @addr: XMDIO address to program
4314da24467cSGuinan Sun  *  @dev_addr: device address to program
4315da24467cSGuinan Sun  *  @data: value to be read from the EMI address
4316da24467cSGuinan Sun  **/
e1000_read_xmdio_reg(struct e1000_hw * hw,u16 addr,u8 dev_addr,u16 * data)4317da24467cSGuinan Sun s32 e1000_read_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 *data)
4318da24467cSGuinan Sun {
4319da24467cSGuinan Sun 	DEBUGFUNC("e1000_read_xmdio_reg");
4320da24467cSGuinan Sun 
4321da24467cSGuinan Sun 		return __e1000_access_xmdio_reg(hw, addr, dev_addr, data, true);
4322da24467cSGuinan Sun }
4323da24467cSGuinan Sun 
4324da24467cSGuinan Sun /**
4325da24467cSGuinan Sun  *  e1000_write_xmdio_reg - Write XMDIO register
4326da24467cSGuinan Sun  *  @hw: pointer to the HW structure
4327da24467cSGuinan Sun  *  @addr: XMDIO address to program
4328da24467cSGuinan Sun  *  @dev_addr: device address to program
4329da24467cSGuinan Sun  *  @data: value to be written to the XMDIO address
4330da24467cSGuinan Sun  **/
e1000_write_xmdio_reg(struct e1000_hw * hw,u16 addr,u8 dev_addr,u16 data)4331da24467cSGuinan Sun s32 e1000_write_xmdio_reg(struct e1000_hw *hw, u16 addr, u8 dev_addr, u16 data)
4332da24467cSGuinan Sun {
4333da24467cSGuinan Sun 	DEBUGFUNC("e1000_write_xmdio_reg");
4334da24467cSGuinan Sun 
4335da24467cSGuinan Sun 		return __e1000_access_xmdio_reg(hw, addr, dev_addr, &data,
4336da24467cSGuinan Sun 						false);
4337da24467cSGuinan Sun }
4338