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