Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Akeem G. Abodunrin | 4b9ea46 | 2013-01-08 18:31:12 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2013 Intel Corporation. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/if_ether.h> |
| 29 | #include <linux/delay.h> |
| 30 | |
| 31 | #include "e1000_mac.h" |
| 32 | #include "e1000_phy.h" |
| 33 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 34 | static s32 igb_phy_setup_autoneg(struct e1000_hw *hw); |
| 35 | static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 36 | u16 *phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 37 | static s32 igb_wait_autoneg(struct e1000_hw *hw); |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 38 | static s32 igb_set_master_slave_mode(struct e1000_hw *hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 39 | |
| 40 | /* Cable length tables */ |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 41 | static const u16 e1000_m88_cable_length_table[] = { |
| 42 | 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED }; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 43 | #define M88E1000_CABLE_LENGTH_TABLE_SIZE \ |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 44 | (sizeof(e1000_m88_cable_length_table) / \ |
| 45 | sizeof(e1000_m88_cable_length_table[0])) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 46 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 47 | static const u16 e1000_igp_2_cable_length_table[] = { |
| 48 | 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, |
| 49 | 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, |
| 50 | 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, |
| 51 | 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, |
| 52 | 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, |
| 53 | 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, |
| 54 | 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124, |
| 55 | 104, 109, 114, 118, 121, 124}; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 56 | #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \ |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 57 | (sizeof(e1000_igp_2_cable_length_table) / \ |
| 58 | sizeof(e1000_igp_2_cable_length_table[0])) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 61 | * igb_check_reset_block - Check if PHY reset is blocked |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 62 | * @hw: pointer to the HW structure |
| 63 | * |
| 64 | * Read the PHY management control register and check whether a PHY reset |
| 65 | * is blocked. If a reset is not blocked return 0, otherwise |
| 66 | * return E1000_BLK_PHY_RESET (12). |
| 67 | **/ |
| 68 | s32 igb_check_reset_block(struct e1000_hw *hw) |
| 69 | { |
| 70 | u32 manc; |
| 71 | |
| 72 | manc = rd32(E1000_MANC); |
| 73 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 74 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? E1000_BLK_PHY_RESET : 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 78 | * igb_get_phy_id - Retrieve the PHY ID and revision |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 79 | * @hw: pointer to the HW structure |
| 80 | * |
| 81 | * Reads the PHY registers and stores the PHY ID and possibly the PHY |
| 82 | * revision in the hardware structure. |
| 83 | **/ |
| 84 | s32 igb_get_phy_id(struct e1000_hw *hw) |
| 85 | { |
| 86 | struct e1000_phy_info *phy = &hw->phy; |
| 87 | s32 ret_val = 0; |
| 88 | u16 phy_id; |
| 89 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 90 | ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 91 | if (ret_val) |
| 92 | goto out; |
| 93 | |
| 94 | phy->id = (u32)(phy_id << 16); |
| 95 | udelay(20); |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 96 | ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 97 | if (ret_val) |
| 98 | goto out; |
| 99 | |
| 100 | phy->id |= (u32)(phy_id & PHY_REVISION_MASK); |
| 101 | phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK); |
| 102 | |
| 103 | out: |
| 104 | return ret_val; |
| 105 | } |
| 106 | |
| 107 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 108 | * igb_phy_reset_dsp - Reset PHY DSP |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 109 | * @hw: pointer to the HW structure |
| 110 | * |
| 111 | * Reset the digital signal processor. |
| 112 | **/ |
| 113 | static s32 igb_phy_reset_dsp(struct e1000_hw *hw) |
| 114 | { |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 115 | s32 ret_val = 0; |
| 116 | |
| 117 | if (!(hw->phy.ops.write_reg)) |
| 118 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 119 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 120 | ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 121 | if (ret_val) |
| 122 | goto out; |
| 123 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 124 | ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 125 | |
| 126 | out: |
| 127 | return ret_val; |
| 128 | } |
| 129 | |
| 130 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 131 | * igb_read_phy_reg_mdic - Read MDI control register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 132 | * @hw: pointer to the HW structure |
| 133 | * @offset: register offset to be read |
| 134 | * @data: pointer to the read data |
| 135 | * |
| 136 | * Reads the MDI control regsiter in the PHY at offset and stores the |
| 137 | * information read to data. |
| 138 | **/ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 139 | s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 140 | { |
| 141 | struct e1000_phy_info *phy = &hw->phy; |
| 142 | u32 i, mdic = 0; |
| 143 | s32 ret_val = 0; |
| 144 | |
| 145 | if (offset > MAX_PHY_REG_ADDRESS) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 146 | hw_dbg("PHY Address %d is out of range\n", offset); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 147 | ret_val = -E1000_ERR_PARAM; |
| 148 | goto out; |
| 149 | } |
| 150 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 151 | /* Set up Op-code, Phy Address, and register offset in the MDI |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 152 | * Control register. The MAC will take care of interfacing with the |
| 153 | * PHY to retrieve the desired data. |
| 154 | */ |
| 155 | mdic = ((offset << E1000_MDIC_REG_SHIFT) | |
| 156 | (phy->addr << E1000_MDIC_PHY_SHIFT) | |
| 157 | (E1000_MDIC_OP_READ)); |
| 158 | |
| 159 | wr32(E1000_MDIC, mdic); |
| 160 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 161 | /* Poll the ready bit to see if the MDI read completed |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 162 | * Increasing the time out as testing showed failures with |
| 163 | * the lower time out |
| 164 | */ |
| 165 | for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) { |
| 166 | udelay(50); |
| 167 | mdic = rd32(E1000_MDIC); |
| 168 | if (mdic & E1000_MDIC_READY) |
| 169 | break; |
| 170 | } |
| 171 | if (!(mdic & E1000_MDIC_READY)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 172 | hw_dbg("MDI Read did not complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 173 | ret_val = -E1000_ERR_PHY; |
| 174 | goto out; |
| 175 | } |
| 176 | if (mdic & E1000_MDIC_ERROR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 177 | hw_dbg("MDI Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 178 | ret_val = -E1000_ERR_PHY; |
| 179 | goto out; |
| 180 | } |
| 181 | *data = (u16) mdic; |
| 182 | |
| 183 | out: |
| 184 | return ret_val; |
| 185 | } |
| 186 | |
| 187 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 188 | * igb_write_phy_reg_mdic - Write MDI control register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 189 | * @hw: pointer to the HW structure |
| 190 | * @offset: register offset to write to |
| 191 | * @data: data to write to register at offset |
| 192 | * |
| 193 | * Writes data to MDI control register in the PHY at offset. |
| 194 | **/ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 195 | s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 196 | { |
| 197 | struct e1000_phy_info *phy = &hw->phy; |
| 198 | u32 i, mdic = 0; |
| 199 | s32 ret_val = 0; |
| 200 | |
| 201 | if (offset > MAX_PHY_REG_ADDRESS) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 202 | hw_dbg("PHY Address %d is out of range\n", offset); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 203 | ret_val = -E1000_ERR_PARAM; |
| 204 | goto out; |
| 205 | } |
| 206 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 207 | /* Set up Op-code, Phy Address, and register offset in the MDI |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 208 | * Control register. The MAC will take care of interfacing with the |
| 209 | * PHY to retrieve the desired data. |
| 210 | */ |
| 211 | mdic = (((u32)data) | |
| 212 | (offset << E1000_MDIC_REG_SHIFT) | |
| 213 | (phy->addr << E1000_MDIC_PHY_SHIFT) | |
| 214 | (E1000_MDIC_OP_WRITE)); |
| 215 | |
| 216 | wr32(E1000_MDIC, mdic); |
| 217 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 218 | /* Poll the ready bit to see if the MDI read completed |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 219 | * Increasing the time out as testing showed failures with |
| 220 | * the lower time out |
| 221 | */ |
| 222 | for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) { |
| 223 | udelay(50); |
| 224 | mdic = rd32(E1000_MDIC); |
| 225 | if (mdic & E1000_MDIC_READY) |
| 226 | break; |
| 227 | } |
| 228 | if (!(mdic & E1000_MDIC_READY)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 229 | hw_dbg("MDI Write did not complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 230 | ret_val = -E1000_ERR_PHY; |
| 231 | goto out; |
| 232 | } |
| 233 | if (mdic & E1000_MDIC_ERROR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 234 | hw_dbg("MDI Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 235 | ret_val = -E1000_ERR_PHY; |
| 236 | goto out; |
| 237 | } |
| 238 | |
| 239 | out: |
| 240 | return ret_val; |
| 241 | } |
| 242 | |
| 243 | /** |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 244 | * igb_read_phy_reg_i2c - Read PHY register using i2c |
| 245 | * @hw: pointer to the HW structure |
| 246 | * @offset: register offset to be read |
| 247 | * @data: pointer to the read data |
| 248 | * |
| 249 | * Reads the PHY register at offset using the i2c interface and stores the |
| 250 | * retrieved information in data. |
| 251 | **/ |
| 252 | s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data) |
| 253 | { |
| 254 | struct e1000_phy_info *phy = &hw->phy; |
| 255 | u32 i, i2ccmd = 0; |
| 256 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 257 | /* Set up Op-code, Phy Address, and register address in the I2CCMD |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 258 | * register. The MAC will take care of interfacing with the |
| 259 | * PHY to retrieve the desired data. |
| 260 | */ |
| 261 | i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 262 | (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) | |
| 263 | (E1000_I2CCMD_OPCODE_READ)); |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 264 | |
| 265 | wr32(E1000_I2CCMD, i2ccmd); |
| 266 | |
| 267 | /* Poll the ready bit to see if the I2C read completed */ |
| 268 | for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) { |
| 269 | udelay(50); |
| 270 | i2ccmd = rd32(E1000_I2CCMD); |
| 271 | if (i2ccmd & E1000_I2CCMD_READY) |
| 272 | break; |
| 273 | } |
| 274 | if (!(i2ccmd & E1000_I2CCMD_READY)) { |
| 275 | hw_dbg("I2CCMD Read did not complete\n"); |
| 276 | return -E1000_ERR_PHY; |
| 277 | } |
| 278 | if (i2ccmd & E1000_I2CCMD_ERROR) { |
| 279 | hw_dbg("I2CCMD Error bit set\n"); |
| 280 | return -E1000_ERR_PHY; |
| 281 | } |
| 282 | |
| 283 | /* Need to byte-swap the 16-bit value. */ |
| 284 | *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * igb_write_phy_reg_i2c - Write PHY register using i2c |
| 291 | * @hw: pointer to the HW structure |
| 292 | * @offset: register offset to write to |
| 293 | * @data: data to write at register offset |
| 294 | * |
| 295 | * Writes the data to PHY register at the offset using the i2c interface. |
| 296 | **/ |
| 297 | s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data) |
| 298 | { |
| 299 | struct e1000_phy_info *phy = &hw->phy; |
| 300 | u32 i, i2ccmd = 0; |
| 301 | u16 phy_data_swapped; |
| 302 | |
Akeem G. Abodunrin | 76d0652 | 2011-09-02 23:11:19 +0000 | [diff] [blame] | 303 | /* Prevent overwritting SFP I2C EEPROM which is at A0 address.*/ |
| 304 | if ((hw->phy.addr == 0) || (hw->phy.addr > 7)) { |
| 305 | hw_dbg("PHY I2C Address %d is out of range.\n", |
| 306 | hw->phy.addr); |
| 307 | return -E1000_ERR_CONFIG; |
| 308 | } |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 309 | |
| 310 | /* Swap the data bytes for the I2C interface */ |
| 311 | phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00); |
| 312 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 313 | /* Set up Op-code, Phy Address, and register address in the I2CCMD |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 314 | * register. The MAC will take care of interfacing with the |
| 315 | * PHY to retrieve the desired data. |
| 316 | */ |
| 317 | i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 318 | (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) | |
| 319 | E1000_I2CCMD_OPCODE_WRITE | |
| 320 | phy_data_swapped); |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 321 | |
| 322 | wr32(E1000_I2CCMD, i2ccmd); |
| 323 | |
| 324 | /* Poll the ready bit to see if the I2C read completed */ |
| 325 | for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) { |
| 326 | udelay(50); |
| 327 | i2ccmd = rd32(E1000_I2CCMD); |
| 328 | if (i2ccmd & E1000_I2CCMD_READY) |
| 329 | break; |
| 330 | } |
| 331 | if (!(i2ccmd & E1000_I2CCMD_READY)) { |
| 332 | hw_dbg("I2CCMD Write did not complete\n"); |
| 333 | return -E1000_ERR_PHY; |
| 334 | } |
| 335 | if (i2ccmd & E1000_I2CCMD_ERROR) { |
| 336 | hw_dbg("I2CCMD Error bit set\n"); |
| 337 | return -E1000_ERR_PHY; |
| 338 | } |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /** |
Akeem G. Abodunrin | 641ac5c | 2013-04-24 16:54:50 +0000 | [diff] [blame] | 344 | * igb_read_sfp_data_byte - Reads SFP module data. |
| 345 | * @hw: pointer to the HW structure |
| 346 | * @offset: byte location offset to be read |
| 347 | * @data: read data buffer pointer |
| 348 | * |
| 349 | * Reads one byte from SFP module data stored |
| 350 | * in SFP resided EEPROM memory or SFP diagnostic area. |
| 351 | * Function should be called with |
| 352 | * E1000_I2CCMD_SFP_DATA_ADDR(<byte offset>) for SFP module database access |
| 353 | * E1000_I2CCMD_SFP_DIAG_ADDR(<byte offset>) for SFP diagnostics parameters |
| 354 | * access |
| 355 | **/ |
| 356 | s32 igb_read_sfp_data_byte(struct e1000_hw *hw, u16 offset, u8 *data) |
| 357 | { |
| 358 | u32 i = 0; |
| 359 | u32 i2ccmd = 0; |
| 360 | u32 data_local = 0; |
| 361 | |
| 362 | if (offset > E1000_I2CCMD_SFP_DIAG_ADDR(255)) { |
| 363 | hw_dbg("I2CCMD command address exceeds upper limit\n"); |
| 364 | return -E1000_ERR_PHY; |
| 365 | } |
| 366 | |
| 367 | /* Set up Op-code, EEPROM Address,in the I2CCMD |
| 368 | * register. The MAC will take care of interfacing with the |
| 369 | * EEPROM to retrieve the desired data. |
| 370 | */ |
| 371 | i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) | |
| 372 | E1000_I2CCMD_OPCODE_READ); |
| 373 | |
| 374 | wr32(E1000_I2CCMD, i2ccmd); |
| 375 | |
| 376 | /* Poll the ready bit to see if the I2C read completed */ |
| 377 | for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) { |
| 378 | udelay(50); |
| 379 | data_local = rd32(E1000_I2CCMD); |
| 380 | if (data_local & E1000_I2CCMD_READY) |
| 381 | break; |
| 382 | } |
| 383 | if (!(data_local & E1000_I2CCMD_READY)) { |
| 384 | hw_dbg("I2CCMD Read did not complete\n"); |
| 385 | return -E1000_ERR_PHY; |
| 386 | } |
| 387 | if (data_local & E1000_I2CCMD_ERROR) { |
| 388 | hw_dbg("I2CCMD Error bit set\n"); |
| 389 | return -E1000_ERR_PHY; |
| 390 | } |
| 391 | *data = (u8) data_local & 0xFF; |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 397 | * igb_read_phy_reg_igp - Read igp PHY register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 398 | * @hw: pointer to the HW structure |
| 399 | * @offset: register offset to be read |
| 400 | * @data: pointer to the read data |
| 401 | * |
| 402 | * Acquires semaphore, if necessary, then reads the PHY register at offset |
| 403 | * and storing the retrieved information in data. Release any acquired |
| 404 | * semaphores before exiting. |
| 405 | **/ |
| 406 | s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data) |
| 407 | { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 408 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 409 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 410 | if (!(hw->phy.ops.acquire)) |
| 411 | goto out; |
| 412 | |
| 413 | ret_val = hw->phy.ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 414 | if (ret_val) |
| 415 | goto out; |
| 416 | |
| 417 | if (offset > MAX_PHY_MULTI_PAGE_REG) { |
| 418 | ret_val = igb_write_phy_reg_mdic(hw, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 419 | IGP01E1000_PHY_PAGE_SELECT, |
| 420 | (u16)offset); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 421 | if (ret_val) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 422 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 423 | goto out; |
| 424 | } |
| 425 | } |
| 426 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 427 | ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, |
| 428 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 429 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 430 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 431 | |
| 432 | out: |
| 433 | return ret_val; |
| 434 | } |
| 435 | |
| 436 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 437 | * igb_write_phy_reg_igp - Write igp PHY register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 438 | * @hw: pointer to the HW structure |
| 439 | * @offset: register offset to write to |
| 440 | * @data: data to write at register offset |
| 441 | * |
| 442 | * Acquires semaphore, if necessary, then writes the data to PHY register |
| 443 | * at the offset. Release any acquired semaphores before exiting. |
| 444 | **/ |
| 445 | s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data) |
| 446 | { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 447 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 448 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 449 | if (!(hw->phy.ops.acquire)) |
| 450 | goto out; |
| 451 | |
| 452 | ret_val = hw->phy.ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 453 | if (ret_val) |
| 454 | goto out; |
| 455 | |
| 456 | if (offset > MAX_PHY_MULTI_PAGE_REG) { |
| 457 | ret_val = igb_write_phy_reg_mdic(hw, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 458 | IGP01E1000_PHY_PAGE_SELECT, |
| 459 | (u16)offset); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 460 | if (ret_val) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 461 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 462 | goto out; |
| 463 | } |
| 464 | } |
| 465 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 466 | ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 467 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 468 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 469 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 470 | |
| 471 | out: |
| 472 | return ret_val; |
| 473 | } |
| 474 | |
| 475 | /** |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 476 | * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link |
| 477 | * @hw: pointer to the HW structure |
| 478 | * |
| 479 | * Sets up Carrier-sense on Transmit and downshift values. |
| 480 | **/ |
| 481 | s32 igb_copper_link_setup_82580(struct e1000_hw *hw) |
| 482 | { |
| 483 | struct e1000_phy_info *phy = &hw->phy; |
| 484 | s32 ret_val; |
| 485 | u16 phy_data; |
| 486 | |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 487 | if (phy->reset_disable) { |
| 488 | ret_val = 0; |
| 489 | goto out; |
| 490 | } |
| 491 | |
| 492 | if (phy->type == e1000_phy_82580) { |
| 493 | ret_val = hw->phy.ops.reset(hw); |
| 494 | if (ret_val) { |
| 495 | hw_dbg("Error resetting the PHY.\n"); |
| 496 | goto out; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
| 501 | ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data); |
| 502 | if (ret_val) |
| 503 | goto out; |
| 504 | |
| 505 | phy_data |= I82580_CFG_ASSERT_CRS_ON_TX; |
| 506 | |
| 507 | /* Enable downshift */ |
| 508 | phy_data |= I82580_CFG_ENABLE_DOWNSHIFT; |
| 509 | |
| 510 | ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data); |
Jesse Brandeburg | 1b55678 | 2012-07-26 02:31:04 +0000 | [diff] [blame] | 511 | if (ret_val) |
| 512 | goto out; |
| 513 | |
| 514 | /* Set MDI/MDIX mode */ |
| 515 | ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data); |
| 516 | if (ret_val) |
| 517 | goto out; |
| 518 | phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK; |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 519 | /* Options: |
Jesse Brandeburg | 1b55678 | 2012-07-26 02:31:04 +0000 | [diff] [blame] | 520 | * 0 - Auto (default) |
| 521 | * 1 - MDI mode |
| 522 | * 2 - MDI-X mode |
| 523 | */ |
| 524 | switch (hw->phy.mdix) { |
| 525 | case 1: |
| 526 | break; |
| 527 | case 2: |
| 528 | phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX; |
| 529 | break; |
| 530 | case 0: |
| 531 | default: |
| 532 | phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX; |
| 533 | break; |
| 534 | } |
| 535 | ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data); |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 536 | |
| 537 | out: |
| 538 | return ret_val; |
| 539 | } |
| 540 | |
| 541 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 542 | * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 543 | * @hw: pointer to the HW structure |
| 544 | * |
| 545 | * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock |
| 546 | * and downshift values are set also. |
| 547 | **/ |
| 548 | s32 igb_copper_link_setup_m88(struct e1000_hw *hw) |
| 549 | { |
| 550 | struct e1000_phy_info *phy = &hw->phy; |
| 551 | s32 ret_val; |
| 552 | u16 phy_data; |
| 553 | |
| 554 | if (phy->reset_disable) { |
| 555 | ret_val = 0; |
| 556 | goto out; |
| 557 | } |
| 558 | |
| 559 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 560 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 561 | if (ret_val) |
| 562 | goto out; |
| 563 | |
| 564 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 565 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 566 | /* Options: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 567 | * MDI/MDI-X = 0 (default) |
| 568 | * 0 - Auto for all speeds |
| 569 | * 1 - MDI mode |
| 570 | * 2 - MDI-X mode |
| 571 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 572 | */ |
| 573 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 574 | |
| 575 | switch (phy->mdix) { |
| 576 | case 1: |
| 577 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 578 | break; |
| 579 | case 2: |
| 580 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 581 | break; |
| 582 | case 3: |
| 583 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 584 | break; |
| 585 | case 0: |
| 586 | default: |
| 587 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 588 | break; |
| 589 | } |
| 590 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 591 | /* Options: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 592 | * disable_polarity_correction = 0 (default) |
| 593 | * Automatic Correction for Reversed Cable Polarity |
| 594 | * 0 - Disabled |
| 595 | * 1 - Enabled |
| 596 | */ |
| 597 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
| 598 | if (phy->disable_polarity_correction == 1) |
| 599 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
| 600 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 601 | ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 602 | if (ret_val) |
| 603 | goto out; |
| 604 | |
| 605 | if (phy->revision < E1000_REVISION_4) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 606 | /* Force TX_CLK in the Extended PHY Specific Control Register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 607 | * to 25MHz clock. |
| 608 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 609 | ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 610 | &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 611 | if (ret_val) |
| 612 | goto out; |
| 613 | |
| 614 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 615 | |
| 616 | if ((phy->revision == E1000_REVISION_2) && |
| 617 | (phy->id == M88E1111_I_PHY_ID)) { |
| 618 | /* 82573L PHY - set the downshift counter to 5x. */ |
| 619 | phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK; |
| 620 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 621 | } else { |
| 622 | /* Configure Master and Slave downshift values */ |
| 623 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 624 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 625 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 626 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 627 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 628 | ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 629 | phy_data); |
| 630 | if (ret_val) |
| 631 | goto out; |
| 632 | } |
| 633 | |
| 634 | /* Commit the changes. */ |
| 635 | ret_val = igb_phy_sw_reset(hw); |
| 636 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 637 | hw_dbg("Error committing the PHY changes\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 638 | goto out; |
| 639 | } |
| 640 | |
| 641 | out: |
| 642 | return ret_val; |
| 643 | } |
| 644 | |
| 645 | /** |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 646 | * igb_copper_link_setup_m88_gen2 - Setup m88 PHY's for copper link |
| 647 | * @hw: pointer to the HW structure |
| 648 | * |
| 649 | * Sets up MDI/MDI-X and polarity for i347-AT4, m88e1322 and m88e1112 PHY's. |
| 650 | * Also enables and sets the downshift parameters. |
| 651 | **/ |
| 652 | s32 igb_copper_link_setup_m88_gen2(struct e1000_hw *hw) |
| 653 | { |
| 654 | struct e1000_phy_info *phy = &hw->phy; |
| 655 | s32 ret_val; |
| 656 | u16 phy_data; |
| 657 | |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 658 | if (phy->reset_disable) |
| 659 | return 0; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 660 | |
| 661 | /* Enable CRS on Tx. This must be set for half-duplex operation. */ |
| 662 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
| 663 | if (ret_val) |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 664 | return ret_val; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 665 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 666 | /* Options: |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 667 | * MDI/MDI-X = 0 (default) |
| 668 | * 0 - Auto for all speeds |
| 669 | * 1 - MDI mode |
| 670 | * 2 - MDI-X mode |
| 671 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 672 | */ |
| 673 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 674 | |
| 675 | switch (phy->mdix) { |
| 676 | case 1: |
| 677 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 678 | break; |
| 679 | case 2: |
| 680 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 681 | break; |
| 682 | case 3: |
| 683 | /* M88E1112 does not support this mode) */ |
| 684 | if (phy->id != M88E1112_E_PHY_ID) { |
| 685 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 686 | break; |
| 687 | } |
| 688 | case 0: |
| 689 | default: |
| 690 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 691 | break; |
| 692 | } |
| 693 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 694 | /* Options: |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 695 | * disable_polarity_correction = 0 (default) |
| 696 | * Automatic Correction for Reversed Cable Polarity |
| 697 | * 0 - Disabled |
| 698 | * 1 - Enabled |
| 699 | */ |
| 700 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
| 701 | if (phy->disable_polarity_correction == 1) |
| 702 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
| 703 | |
| 704 | /* Enable downshift and setting it to X6 */ |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 705 | if (phy->id == M88E1543_E_PHY_ID) { |
| 706 | phy_data &= ~I347AT4_PSCR_DOWNSHIFT_ENABLE; |
| 707 | ret_val = |
| 708 | phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 709 | if (ret_val) |
| 710 | return ret_val; |
| 711 | |
| 712 | ret_val = igb_phy_sw_reset(hw); |
| 713 | if (ret_val) { |
| 714 | hw_dbg("Error committing the PHY changes\n"); |
| 715 | return ret_val; |
| 716 | } |
| 717 | } |
| 718 | |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 719 | phy_data &= ~I347AT4_PSCR_DOWNSHIFT_MASK; |
| 720 | phy_data |= I347AT4_PSCR_DOWNSHIFT_6X; |
| 721 | phy_data |= I347AT4_PSCR_DOWNSHIFT_ENABLE; |
| 722 | |
| 723 | ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
| 724 | if (ret_val) |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 725 | return ret_val; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 726 | |
| 727 | /* Commit the changes. */ |
| 728 | ret_val = igb_phy_sw_reset(hw); |
| 729 | if (ret_val) { |
| 730 | hw_dbg("Error committing the PHY changes\n"); |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 731 | return ret_val; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 732 | } |
Carolyn Wyborny | d1c17d8 | 2013-08-16 00:39:10 +0000 | [diff] [blame] | 733 | ret_val = igb_set_master_slave_mode(hw); |
| 734 | if (ret_val) |
| 735 | return ret_val; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 736 | |
Akeem G Abodunrin | dfc7075 | 2013-08-28 02:22:48 +0000 | [diff] [blame] | 737 | return 0; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 741 | * igb_copper_link_setup_igp - Setup igp PHY's for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 742 | * @hw: pointer to the HW structure |
| 743 | * |
| 744 | * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for |
| 745 | * igp PHY's. |
| 746 | **/ |
| 747 | s32 igb_copper_link_setup_igp(struct e1000_hw *hw) |
| 748 | { |
| 749 | struct e1000_phy_info *phy = &hw->phy; |
| 750 | s32 ret_val; |
| 751 | u16 data; |
| 752 | |
| 753 | if (phy->reset_disable) { |
| 754 | ret_val = 0; |
| 755 | goto out; |
| 756 | } |
| 757 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 758 | ret_val = phy->ops.reset(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 759 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 760 | hw_dbg("Error resetting the PHY.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 761 | goto out; |
| 762 | } |
| 763 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 764 | /* Wait 100ms for MAC to configure PHY from NVM settings, to avoid |
Alexander Duyck | a6a6056 | 2009-03-31 20:38:38 +0000 | [diff] [blame] | 765 | * timeout issues when LFS is enabled. |
| 766 | */ |
| 767 | msleep(100); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 768 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 769 | /* The NVM settings will configure LPLU in D3 for |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 770 | * non-IGP1 PHYs. |
| 771 | */ |
| 772 | if (phy->type == e1000_phy_igp) { |
| 773 | /* disable lplu d3 during driver init */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 774 | if (phy->ops.set_d3_lplu_state) |
| 775 | ret_val = phy->ops.set_d3_lplu_state(hw, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 776 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 777 | hw_dbg("Error Disabling LPLU D3\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 778 | goto out; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* disable lplu d0 during driver init */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 783 | ret_val = phy->ops.set_d0_lplu_state(hw, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 784 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 785 | hw_dbg("Error Disabling LPLU D0\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 786 | goto out; |
| 787 | } |
| 788 | /* Configure mdi-mdix settings */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 789 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 790 | if (ret_val) |
| 791 | goto out; |
| 792 | |
| 793 | data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 794 | |
| 795 | switch (phy->mdix) { |
| 796 | case 1: |
| 797 | data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 798 | break; |
| 799 | case 2: |
| 800 | data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 801 | break; |
| 802 | case 0: |
| 803 | default: |
| 804 | data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 805 | break; |
| 806 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 807 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 808 | if (ret_val) |
| 809 | goto out; |
| 810 | |
| 811 | /* set auto-master slave resolution settings */ |
| 812 | if (hw->mac.autoneg) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 813 | /* when autonegotiation advertisement is only 1000Mbps then we |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 814 | * should disable SmartSpeed and enable Auto MasterSlave |
| 815 | * resolution as hardware default. |
| 816 | */ |
| 817 | if (phy->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 818 | /* Disable SmartSpeed */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 819 | ret_val = phy->ops.read_reg(hw, |
| 820 | IGP01E1000_PHY_PORT_CONFIG, |
| 821 | &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 822 | if (ret_val) |
| 823 | goto out; |
| 824 | |
| 825 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 826 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 827 | IGP01E1000_PHY_PORT_CONFIG, |
| 828 | data); |
| 829 | if (ret_val) |
| 830 | goto out; |
| 831 | |
| 832 | /* Set auto Master/Slave resolution process */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 833 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 834 | if (ret_val) |
| 835 | goto out; |
| 836 | |
| 837 | data &= ~CR_1000T_MS_ENABLE; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 838 | ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 839 | if (ret_val) |
| 840 | goto out; |
| 841 | } |
| 842 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 843 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 844 | if (ret_val) |
| 845 | goto out; |
| 846 | |
| 847 | /* load defaults for future use */ |
| 848 | phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ? |
| 849 | ((data & CR_1000T_MS_VALUE) ? |
| 850 | e1000_ms_force_master : |
| 851 | e1000_ms_force_slave) : |
| 852 | e1000_ms_auto; |
| 853 | |
| 854 | switch (phy->ms_type) { |
| 855 | case e1000_ms_force_master: |
| 856 | data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 857 | break; |
| 858 | case e1000_ms_force_slave: |
| 859 | data |= CR_1000T_MS_ENABLE; |
| 860 | data &= ~(CR_1000T_MS_VALUE); |
| 861 | break; |
| 862 | case e1000_ms_auto: |
| 863 | data &= ~CR_1000T_MS_ENABLE; |
| 864 | default: |
| 865 | break; |
| 866 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 867 | ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 868 | if (ret_val) |
| 869 | goto out; |
| 870 | } |
| 871 | |
| 872 | out: |
| 873 | return ret_val; |
| 874 | } |
| 875 | |
| 876 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 877 | * igb_copper_link_autoneg - Setup/Enable autoneg for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 878 | * @hw: pointer to the HW structure |
| 879 | * |
| 880 | * Performs initial bounds checking on autoneg advertisement parameter, then |
| 881 | * configure to advertise the full capability. Setup the PHY to autoneg |
| 882 | * and restart the negotiation process between the link partner. If |
| 883 | * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. |
| 884 | **/ |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 885 | static s32 igb_copper_link_autoneg(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 886 | { |
| 887 | struct e1000_phy_info *phy = &hw->phy; |
| 888 | s32 ret_val; |
| 889 | u16 phy_ctrl; |
| 890 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 891 | /* Perform some bounds checking on the autoneg advertisement |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 892 | * parameter. |
| 893 | */ |
| 894 | phy->autoneg_advertised &= phy->autoneg_mask; |
| 895 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 896 | /* If autoneg_advertised is zero, we assume it was not defaulted |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 897 | * by the calling code so we set to advertise full capability. |
| 898 | */ |
| 899 | if (phy->autoneg_advertised == 0) |
| 900 | phy->autoneg_advertised = phy->autoneg_mask; |
| 901 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 902 | hw_dbg("Reconfiguring auto-neg advertisement params\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 903 | ret_val = igb_phy_setup_autoneg(hw); |
| 904 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 905 | hw_dbg("Error Setting up Auto-Negotiation\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 906 | goto out; |
| 907 | } |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 908 | hw_dbg("Restarting Auto-Neg\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 909 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 910 | /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 911 | * the Auto Neg Restart bit in the PHY control register. |
| 912 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 913 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 914 | if (ret_val) |
| 915 | goto out; |
| 916 | |
| 917 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 918 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 919 | if (ret_val) |
| 920 | goto out; |
| 921 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 922 | /* Does the user want to wait for Auto-Neg to complete here, or |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 923 | * check at a later time (for example, callback routine). |
| 924 | */ |
| 925 | if (phy->autoneg_wait_to_complete) { |
| 926 | ret_val = igb_wait_autoneg(hw); |
| 927 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 928 | hw_dbg("Error while waiting for " |
| 929 | "autoneg to complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 930 | goto out; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | hw->mac.get_link_status = true; |
| 935 | |
| 936 | out: |
| 937 | return ret_val; |
| 938 | } |
| 939 | |
| 940 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 941 | * igb_phy_setup_autoneg - Configure PHY for auto-negotiation |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 942 | * @hw: pointer to the HW structure |
| 943 | * |
| 944 | * Reads the MII auto-neg advertisement register and/or the 1000T control |
| 945 | * register and if the PHY is already setup for auto-negotiation, then |
| 946 | * return successful. Otherwise, setup advertisement and flow control to |
| 947 | * the appropriate values for the wanted auto-negotiation. |
| 948 | **/ |
| 949 | static s32 igb_phy_setup_autoneg(struct e1000_hw *hw) |
| 950 | { |
| 951 | struct e1000_phy_info *phy = &hw->phy; |
| 952 | s32 ret_val; |
| 953 | u16 mii_autoneg_adv_reg; |
| 954 | u16 mii_1000t_ctrl_reg = 0; |
| 955 | |
| 956 | phy->autoneg_advertised &= phy->autoneg_mask; |
| 957 | |
| 958 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 959 | ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 960 | if (ret_val) |
| 961 | goto out; |
| 962 | |
| 963 | if (phy->autoneg_mask & ADVERTISE_1000_FULL) { |
| 964 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 965 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 966 | &mii_1000t_ctrl_reg); |
| 967 | if (ret_val) |
| 968 | goto out; |
| 969 | } |
| 970 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 971 | /* Need to parse both autoneg_advertised and fc and set up |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 972 | * the appropriate PHY registers. First we will parse for |
| 973 | * autoneg_advertised software override. Since we can advertise |
| 974 | * a plethora of combinations, we need to check each bit |
| 975 | * individually. |
| 976 | */ |
| 977 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 978 | /* First we clear all the 10/100 mb speed bits in the Auto-Neg |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 979 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 980 | * the 1000Base-T Control Register (Address 9). |
| 981 | */ |
| 982 | mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS | |
| 983 | NWAY_AR_100TX_HD_CAPS | |
| 984 | NWAY_AR_10T_FD_CAPS | |
| 985 | NWAY_AR_10T_HD_CAPS); |
| 986 | mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS); |
| 987 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 988 | hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 989 | |
| 990 | /* Do we want to advertise 10 Mb Half Duplex? */ |
| 991 | if (phy->autoneg_advertised & ADVERTISE_10_HALF) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 992 | hw_dbg("Advertise 10mb Half duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 993 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 994 | } |
| 995 | |
| 996 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 997 | if (phy->autoneg_advertised & ADVERTISE_10_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 998 | hw_dbg("Advertise 10mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 999 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 1000 | } |
| 1001 | |
| 1002 | /* Do we want to advertise 100 Mb Half Duplex? */ |
| 1003 | if (phy->autoneg_advertised & ADVERTISE_100_HALF) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1004 | hw_dbg("Advertise 100mb Half duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1005 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 1006 | } |
| 1007 | |
| 1008 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 1009 | if (phy->autoneg_advertised & ADVERTISE_100_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1010 | hw_dbg("Advertise 100mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1011 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 1012 | } |
| 1013 | |
| 1014 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 1015 | if (phy->autoneg_advertised & ADVERTISE_1000_HALF) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1016 | hw_dbg("Advertise 1000mb Half duplex request denied!\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1017 | |
| 1018 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 1019 | if (phy->autoneg_advertised & ADVERTISE_1000_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1020 | hw_dbg("Advertise 1000mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1021 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 1022 | } |
| 1023 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1024 | /* Check for a software override of the flow control settings, and |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1025 | * setup the PHY advertisement registers accordingly. If |
| 1026 | * auto-negotiation is enabled, then software will have to set the |
| 1027 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 1028 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto- |
| 1029 | * negotiation. |
| 1030 | * |
| 1031 | * The possible values of the "fc" parameter are: |
| 1032 | * 0: Flow control is completely disabled |
| 1033 | * 1: Rx flow control is enabled (we can receive pause frames |
| 1034 | * but not send pause frames). |
| 1035 | * 2: Tx flow control is enabled (we can send pause frames |
| 1036 | * but we do not support receiving pause frames). |
| 1037 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 1038 | * other: No software override. The flow control configuration |
| 1039 | * in the EEPROM is used. |
| 1040 | */ |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1041 | switch (hw->fc.current_mode) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1042 | case e1000_fc_none: |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1043 | /* Flow control (RX & TX) is completely disabled by a |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1044 | * software over-ride. |
| 1045 | */ |
| 1046 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1047 | break; |
| 1048 | case e1000_fc_rx_pause: |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1049 | /* RX Flow control is enabled, and TX Flow control is |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1050 | * disabled, by a software over-ride. |
| 1051 | * |
| 1052 | * Since there really isn't a way to advertise that we are |
| 1053 | * capable of RX Pause ONLY, we will advertise that we |
| 1054 | * support both symmetric and asymmetric RX PAUSE. Later |
| 1055 | * (in e1000_config_fc_after_link_up) we will disable the |
| 1056 | * hw's ability to send PAUSE frames. |
| 1057 | */ |
| 1058 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1059 | break; |
| 1060 | case e1000_fc_tx_pause: |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1061 | /* TX Flow control is enabled, and RX Flow control is |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1062 | * disabled, by a software over-ride. |
| 1063 | */ |
| 1064 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 1065 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 1066 | break; |
| 1067 | case e1000_fc_full: |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1068 | /* Flow control (both RX and TX) is enabled by a software |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1069 | * over-ride. |
| 1070 | */ |
| 1071 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 1072 | break; |
| 1073 | default: |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1074 | hw_dbg("Flow control param set incorrectly\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1075 | ret_val = -E1000_ERR_CONFIG; |
| 1076 | goto out; |
| 1077 | } |
| 1078 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1079 | ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1080 | if (ret_val) |
| 1081 | goto out; |
| 1082 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1083 | hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1084 | |
| 1085 | if (phy->autoneg_mask & ADVERTISE_1000_FULL) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1086 | ret_val = phy->ops.write_reg(hw, |
| 1087 | PHY_1000T_CTRL, |
| 1088 | mii_1000t_ctrl_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1089 | if (ret_val) |
| 1090 | goto out; |
| 1091 | } |
| 1092 | |
| 1093 | out: |
| 1094 | return ret_val; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1098 | * igb_setup_copper_link - Configure copper link settings |
| 1099 | * @hw: pointer to the HW structure |
| 1100 | * |
| 1101 | * Calls the appropriate function to configure the link for auto-neg or forced |
| 1102 | * speed and duplex. Then we check for link, once link is established calls |
| 1103 | * to configure collision distance and flow control are called. If link is |
| 1104 | * not established, we return -E1000_ERR_PHY (-2). |
| 1105 | **/ |
| 1106 | s32 igb_setup_copper_link(struct e1000_hw *hw) |
| 1107 | { |
| 1108 | s32 ret_val; |
| 1109 | bool link; |
| 1110 | |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1111 | if (hw->mac.autoneg) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1112 | /* Setup autoneg and flow control advertisement and perform |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1113 | * autonegotiation. |
| 1114 | */ |
| 1115 | ret_val = igb_copper_link_autoneg(hw); |
| 1116 | if (ret_val) |
| 1117 | goto out; |
| 1118 | } else { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1119 | /* PHY will be set to 10H, 10F, 100H or 100F |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1120 | * depending on user settings. |
| 1121 | */ |
| 1122 | hw_dbg("Forcing Speed and Duplex\n"); |
| 1123 | ret_val = hw->phy.ops.force_speed_duplex(hw); |
| 1124 | if (ret_val) { |
| 1125 | hw_dbg("Error Forcing Speed and Duplex\n"); |
| 1126 | goto out; |
| 1127 | } |
| 1128 | } |
| 1129 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1130 | /* Check link status. Wait up to 100 microseconds for link to become |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1131 | * valid. |
| 1132 | */ |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1133 | ret_val = igb_phy_has_link(hw, COPPER_LINK_UP_LIMIT, 10, &link); |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1134 | if (ret_val) |
| 1135 | goto out; |
| 1136 | |
| 1137 | if (link) { |
| 1138 | hw_dbg("Valid link established!!!\n"); |
| 1139 | igb_config_collision_dist(hw); |
| 1140 | ret_val = igb_config_fc_after_link_up(hw); |
| 1141 | } else { |
| 1142 | hw_dbg("Unable to establish link!!!\n"); |
| 1143 | } |
| 1144 | |
| 1145 | out: |
| 1146 | return ret_val; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1150 | * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1151 | * @hw: pointer to the HW structure |
| 1152 | * |
| 1153 | * Calls the PHY setup function to force speed and duplex. Clears the |
| 1154 | * auto-crossover to force MDI manually. Waits for link and returns |
| 1155 | * successful if link up is successful, else -E1000_ERR_PHY (-2). |
| 1156 | **/ |
| 1157 | s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw) |
| 1158 | { |
| 1159 | struct e1000_phy_info *phy = &hw->phy; |
| 1160 | s32 ret_val; |
| 1161 | u16 phy_data; |
| 1162 | bool link; |
| 1163 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1164 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1165 | if (ret_val) |
| 1166 | goto out; |
| 1167 | |
| 1168 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
| 1169 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1170 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1171 | if (ret_val) |
| 1172 | goto out; |
| 1173 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1174 | /* Clear Auto-Crossover to force MDI manually. IGP requires MDI |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1175 | * forced whenever speed and duplex are forced. |
| 1176 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1177 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1178 | if (ret_val) |
| 1179 | goto out; |
| 1180 | |
| 1181 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 1182 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 1183 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1184 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1185 | if (ret_val) |
| 1186 | goto out; |
| 1187 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1188 | hw_dbg("IGP PSCR: %X\n", phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1189 | |
| 1190 | udelay(1); |
| 1191 | |
| 1192 | if (phy->autoneg_wait_to_complete) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1193 | hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1194 | |
Andi Kleen | dc3d226 | 2013-04-22 07:46:40 +0000 | [diff] [blame] | 1195 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1196 | if (ret_val) |
| 1197 | goto out; |
| 1198 | |
| 1199 | if (!link) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1200 | hw_dbg("Link taking longer than expected.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1201 | |
| 1202 | /* Try once more */ |
Andi Kleen | dc3d226 | 2013-04-22 07:46:40 +0000 | [diff] [blame] | 1203 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 10000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1204 | if (ret_val) |
| 1205 | goto out; |
| 1206 | } |
| 1207 | |
| 1208 | out: |
| 1209 | return ret_val; |
| 1210 | } |
| 1211 | |
| 1212 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1213 | * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1214 | * @hw: pointer to the HW structure |
| 1215 | * |
| 1216 | * Calls the PHY setup function to force speed and duplex. Clears the |
| 1217 | * auto-crossover to force MDI manually. Resets the PHY to commit the |
| 1218 | * changes. If time expires while waiting for link up, we reset the DSP. |
| 1219 | * After reset, TX_CLK and CRS on TX must be set. Return successful upon |
| 1220 | * successful completion, else return corresponding error code. |
| 1221 | **/ |
| 1222 | s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw) |
| 1223 | { |
| 1224 | struct e1000_phy_info *phy = &hw->phy; |
| 1225 | s32 ret_val; |
| 1226 | u16 phy_data; |
| 1227 | bool link; |
| 1228 | |
Matthew Vick | 9f0b851 | 2012-10-16 07:44:45 +0000 | [diff] [blame] | 1229 | /* I210 and I211 devices support Auto-Crossover in forced operation. */ |
| 1230 | if (phy->type != e1000_phy_i210) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1231 | /* Clear Auto-Crossover to force MDI manually. M88E1000 |
Matthew Vick | 9f0b851 | 2012-10-16 07:44:45 +0000 | [diff] [blame] | 1232 | * requires MDI forced whenever speed and duplex are forced. |
| 1233 | */ |
| 1234 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 1235 | &phy_data); |
| 1236 | if (ret_val) |
| 1237 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1238 | |
Matthew Vick | 9f0b851 | 2012-10-16 07:44:45 +0000 | [diff] [blame] | 1239 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1240 | ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, |
| 1241 | phy_data); |
| 1242 | if (ret_val) |
| 1243 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1244 | |
Matthew Vick | 9f0b851 | 2012-10-16 07:44:45 +0000 | [diff] [blame] | 1245 | hw_dbg("M88E1000 PSCR: %X\n", phy_data); |
| 1246 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1247 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1248 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1249 | if (ret_val) |
| 1250 | goto out; |
| 1251 | |
| 1252 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
| 1253 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1254 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1255 | if (ret_val) |
| 1256 | goto out; |
| 1257 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1258 | /* Reset the phy to commit changes. */ |
| 1259 | ret_val = igb_phy_sw_reset(hw); |
| 1260 | if (ret_val) |
| 1261 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1262 | |
| 1263 | if (phy->autoneg_wait_to_complete) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1264 | hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1265 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1266 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1267 | if (ret_val) |
| 1268 | goto out; |
| 1269 | |
| 1270 | if (!link) { |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1271 | bool reset_dsp = true; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1272 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1273 | switch (hw->phy.id) { |
| 1274 | case I347AT4_E_PHY_ID: |
| 1275 | case M88E1112_E_PHY_ID: |
| 1276 | case I210_I_PHY_ID: |
| 1277 | reset_dsp = false; |
| 1278 | break; |
| 1279 | default: |
| 1280 | if (hw->phy.type != e1000_phy_m88) |
| 1281 | reset_dsp = false; |
| 1282 | break; |
| 1283 | } |
| 1284 | if (!reset_dsp) |
| 1285 | hw_dbg("Link taking longer than expected.\n"); |
| 1286 | else { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1287 | /* We didn't get link. |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1288 | * Reset the DSP and cross our fingers. |
| 1289 | */ |
| 1290 | ret_val = phy->ops.write_reg(hw, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1291 | M88E1000_PHY_PAGE_SELECT, |
| 1292 | 0x001d); |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1293 | if (ret_val) |
| 1294 | goto out; |
| 1295 | ret_val = igb_phy_reset_dsp(hw); |
| 1296 | if (ret_val) |
| 1297 | goto out; |
| 1298 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /* Try once more */ |
| 1302 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1303 | 100000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1304 | if (ret_val) |
| 1305 | goto out; |
| 1306 | } |
| 1307 | |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1308 | if (hw->phy.type != e1000_phy_m88 || |
| 1309 | hw->phy.id == I347AT4_E_PHY_ID || |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1310 | hw->phy.id == M88E1112_E_PHY_ID || |
| 1311 | hw->phy.id == I210_I_PHY_ID) |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1312 | goto out; |
| 1313 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1314 | ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1315 | if (ret_val) |
| 1316 | goto out; |
| 1317 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1318 | /* Resetting the phy means we need to re-force TX_CLK in the |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1319 | * Extended PHY Specific Control Register to 25MHz clock from |
| 1320 | * the reset value of 2.5MHz. |
| 1321 | */ |
| 1322 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1323 | ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1324 | if (ret_val) |
| 1325 | goto out; |
| 1326 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1327 | /* In addition, we must re-enable CRS on Tx for both half and full |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1328 | * duplex. |
| 1329 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1330 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1331 | if (ret_val) |
| 1332 | goto out; |
| 1333 | |
| 1334 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1335 | ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1336 | |
| 1337 | out: |
| 1338 | return ret_val; |
| 1339 | } |
| 1340 | |
| 1341 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1342 | * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1343 | * @hw: pointer to the HW structure |
| 1344 | * @phy_ctrl: pointer to current value of PHY_CONTROL |
| 1345 | * |
| 1346 | * Forces speed and duplex on the PHY by doing the following: disable flow |
| 1347 | * control, force speed/duplex on the MAC, disable auto speed detection, |
| 1348 | * disable auto-negotiation, configure duplex, configure speed, configure |
| 1349 | * the collision distance, write configuration to CTRL register. The |
| 1350 | * caller must write to the PHY_CONTROL register for these settings to |
| 1351 | * take affect. |
| 1352 | **/ |
| 1353 | static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1354 | u16 *phy_ctrl) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1355 | { |
| 1356 | struct e1000_mac_info *mac = &hw->mac; |
| 1357 | u32 ctrl; |
| 1358 | |
| 1359 | /* Turn off flow control when forcing speed/duplex */ |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1360 | hw->fc.current_mode = e1000_fc_none; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1361 | |
| 1362 | /* Force speed/duplex on the mac */ |
| 1363 | ctrl = rd32(E1000_CTRL); |
| 1364 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1365 | ctrl &= ~E1000_CTRL_SPD_SEL; |
| 1366 | |
| 1367 | /* Disable Auto Speed Detection */ |
| 1368 | ctrl &= ~E1000_CTRL_ASDE; |
| 1369 | |
| 1370 | /* Disable autoneg on the phy */ |
| 1371 | *phy_ctrl &= ~MII_CR_AUTO_NEG_EN; |
| 1372 | |
| 1373 | /* Forcing Full or Half Duplex? */ |
| 1374 | if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) { |
| 1375 | ctrl &= ~E1000_CTRL_FD; |
| 1376 | *phy_ctrl &= ~MII_CR_FULL_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1377 | hw_dbg("Half Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1378 | } else { |
| 1379 | ctrl |= E1000_CTRL_FD; |
| 1380 | *phy_ctrl |= MII_CR_FULL_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1381 | hw_dbg("Full Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | /* Forcing 10mb or 100mb? */ |
| 1385 | if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) { |
| 1386 | ctrl |= E1000_CTRL_SPD_100; |
| 1387 | *phy_ctrl |= MII_CR_SPEED_100; |
| 1388 | *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1389 | hw_dbg("Forcing 100mb\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1390 | } else { |
| 1391 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1392 | *phy_ctrl |= MII_CR_SPEED_10; |
| 1393 | *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1394 | hw_dbg("Forcing 10mb\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | igb_config_collision_dist(hw); |
| 1398 | |
| 1399 | wr32(E1000_CTRL, ctrl); |
| 1400 | } |
| 1401 | |
| 1402 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1403 | * igb_set_d3_lplu_state - Sets low power link up state for D3 |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1404 | * @hw: pointer to the HW structure |
| 1405 | * @active: boolean used to enable/disable lplu |
| 1406 | * |
| 1407 | * Success returns 0, Failure returns 1 |
| 1408 | * |
| 1409 | * The low power link up (lplu) state is set to the power management level D3 |
| 1410 | * and SmartSpeed is disabled when active is true, else clear lplu for D3 |
| 1411 | * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU |
| 1412 | * is used during Dx states where the power conservation is most important. |
| 1413 | * During driver activity, SmartSpeed should be enabled so performance is |
| 1414 | * maintained. |
| 1415 | **/ |
| 1416 | s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active) |
| 1417 | { |
| 1418 | struct e1000_phy_info *phy = &hw->phy; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1419 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1420 | u16 data; |
| 1421 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1422 | if (!(hw->phy.ops.read_reg)) |
| 1423 | goto out; |
| 1424 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1425 | ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1426 | if (ret_val) |
| 1427 | goto out; |
| 1428 | |
| 1429 | if (!active) { |
| 1430 | data &= ~IGP02E1000_PM_D3_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1431 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1432 | data); |
| 1433 | if (ret_val) |
| 1434 | goto out; |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1435 | /* LPLU and SmartSpeed are mutually exclusive. LPLU is used |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1436 | * during Dx states where the power conservation is most |
| 1437 | * important. During driver activity we should enable |
| 1438 | * SmartSpeed, so performance is maintained. |
| 1439 | */ |
| 1440 | if (phy->smart_speed == e1000_smart_speed_on) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1441 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1442 | IGP01E1000_PHY_PORT_CONFIG, |
| 1443 | &data); |
| 1444 | if (ret_val) |
| 1445 | goto out; |
| 1446 | |
| 1447 | data |= IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1448 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1449 | IGP01E1000_PHY_PORT_CONFIG, |
| 1450 | data); |
| 1451 | if (ret_val) |
| 1452 | goto out; |
| 1453 | } else if (phy->smart_speed == e1000_smart_speed_off) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1454 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1455 | IGP01E1000_PHY_PORT_CONFIG, |
| 1456 | &data); |
| 1457 | if (ret_val) |
| 1458 | goto out; |
| 1459 | |
| 1460 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1461 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1462 | IGP01E1000_PHY_PORT_CONFIG, |
| 1463 | data); |
| 1464 | if (ret_val) |
| 1465 | goto out; |
| 1466 | } |
| 1467 | } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) || |
| 1468 | (phy->autoneg_advertised == E1000_ALL_NOT_GIG) || |
| 1469 | (phy->autoneg_advertised == E1000_ALL_10_SPEED)) { |
| 1470 | data |= IGP02E1000_PM_D3_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1471 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1472 | data); |
| 1473 | if (ret_val) |
| 1474 | goto out; |
| 1475 | |
| 1476 | /* When LPLU is enabled, we should disable SmartSpeed */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1477 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1478 | &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1479 | if (ret_val) |
| 1480 | goto out; |
| 1481 | |
| 1482 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1483 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1484 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | out: |
| 1488 | return ret_val; |
| 1489 | } |
| 1490 | |
| 1491 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1492 | * igb_check_downshift - Checks whether a downshift in speed occurred |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1493 | * @hw: pointer to the HW structure |
| 1494 | * |
| 1495 | * Success returns 0, Failure returns 1 |
| 1496 | * |
| 1497 | * A downshift is detected by querying the PHY link health. |
| 1498 | **/ |
| 1499 | s32 igb_check_downshift(struct e1000_hw *hw) |
| 1500 | { |
| 1501 | struct e1000_phy_info *phy = &hw->phy; |
| 1502 | s32 ret_val; |
| 1503 | u16 phy_data, offset, mask; |
| 1504 | |
| 1505 | switch (phy->type) { |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1506 | case e1000_phy_i210: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1507 | case e1000_phy_m88: |
| 1508 | case e1000_phy_gg82563: |
| 1509 | offset = M88E1000_PHY_SPEC_STATUS; |
| 1510 | mask = M88E1000_PSSR_DOWNSHIFT; |
| 1511 | break; |
| 1512 | case e1000_phy_igp_2: |
| 1513 | case e1000_phy_igp: |
| 1514 | case e1000_phy_igp_3: |
| 1515 | offset = IGP01E1000_PHY_LINK_HEALTH; |
| 1516 | mask = IGP01E1000_PLHR_SS_DOWNGRADE; |
| 1517 | break; |
| 1518 | default: |
| 1519 | /* speed downshift not supported */ |
| 1520 | phy->speed_downgraded = false; |
| 1521 | ret_val = 0; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1525 | ret_val = phy->ops.read_reg(hw, offset, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1526 | |
| 1527 | if (!ret_val) |
| 1528 | phy->speed_downgraded = (phy_data & mask) ? true : false; |
| 1529 | |
| 1530 | out: |
| 1531 | return ret_val; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1535 | * igb_check_polarity_m88 - Checks the polarity. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1536 | * @hw: pointer to the HW structure |
| 1537 | * |
| 1538 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) |
| 1539 | * |
| 1540 | * Polarity is determined based on the PHY specific status register. |
| 1541 | **/ |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1542 | s32 igb_check_polarity_m88(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1543 | { |
| 1544 | struct e1000_phy_info *phy = &hw->phy; |
| 1545 | s32 ret_val; |
| 1546 | u16 data; |
| 1547 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1548 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1549 | |
| 1550 | if (!ret_val) |
| 1551 | phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY) |
| 1552 | ? e1000_rev_polarity_reversed |
| 1553 | : e1000_rev_polarity_normal; |
| 1554 | |
| 1555 | return ret_val; |
| 1556 | } |
| 1557 | |
| 1558 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1559 | * igb_check_polarity_igp - Checks the polarity. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1560 | * @hw: pointer to the HW structure |
| 1561 | * |
| 1562 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) |
| 1563 | * |
| 1564 | * Polarity is determined based on the PHY port status register, and the |
| 1565 | * current speed (since there is no polarity at 100Mbps). |
| 1566 | **/ |
| 1567 | static s32 igb_check_polarity_igp(struct e1000_hw *hw) |
| 1568 | { |
| 1569 | struct e1000_phy_info *phy = &hw->phy; |
| 1570 | s32 ret_val; |
| 1571 | u16 data, offset, mask; |
| 1572 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1573 | /* Polarity is determined based on the speed of |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1574 | * our connection. |
| 1575 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1576 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1577 | if (ret_val) |
| 1578 | goto out; |
| 1579 | |
| 1580 | if ((data & IGP01E1000_PSSR_SPEED_MASK) == |
| 1581 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 1582 | offset = IGP01E1000_PHY_PCS_INIT_REG; |
| 1583 | mask = IGP01E1000_PHY_POLARITY_MASK; |
| 1584 | } else { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1585 | /* This really only applies to 10Mbps since |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1586 | * there is no polarity for 100Mbps (always 0). |
| 1587 | */ |
| 1588 | offset = IGP01E1000_PHY_PORT_STATUS; |
| 1589 | mask = IGP01E1000_PSSR_POLARITY_REVERSED; |
| 1590 | } |
| 1591 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1592 | ret_val = phy->ops.read_reg(hw, offset, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1593 | |
| 1594 | if (!ret_val) |
| 1595 | phy->cable_polarity = (data & mask) |
| 1596 | ? e1000_rev_polarity_reversed |
| 1597 | : e1000_rev_polarity_normal; |
| 1598 | |
| 1599 | out: |
| 1600 | return ret_val; |
| 1601 | } |
| 1602 | |
| 1603 | /** |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1604 | * igb_wait_autoneg - Wait for auto-neg completion |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1605 | * @hw: pointer to the HW structure |
| 1606 | * |
| 1607 | * Waits for auto-negotiation to complete or for the auto-negotiation time |
| 1608 | * limit to expire, which ever happens first. |
| 1609 | **/ |
| 1610 | static s32 igb_wait_autoneg(struct e1000_hw *hw) |
| 1611 | { |
| 1612 | s32 ret_val = 0; |
| 1613 | u16 i, phy_status; |
| 1614 | |
| 1615 | /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */ |
| 1616 | for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1617 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1618 | if (ret_val) |
| 1619 | break; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1620 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1621 | if (ret_val) |
| 1622 | break; |
| 1623 | if (phy_status & MII_SR_AUTONEG_COMPLETE) |
| 1624 | break; |
| 1625 | msleep(100); |
| 1626 | } |
| 1627 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1628 | /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1629 | * has completed. |
| 1630 | */ |
| 1631 | return ret_val; |
| 1632 | } |
| 1633 | |
| 1634 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1635 | * igb_phy_has_link - Polls PHY for link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1636 | * @hw: pointer to the HW structure |
| 1637 | * @iterations: number of times to poll for link |
| 1638 | * @usec_interval: delay between polling attempts |
| 1639 | * @success: pointer to whether polling was successful or not |
| 1640 | * |
| 1641 | * Polls the PHY status register for link, 'iterations' number of times. |
| 1642 | **/ |
| 1643 | s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations, |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1644 | u32 usec_interval, bool *success) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1645 | { |
| 1646 | s32 ret_val = 0; |
| 1647 | u16 i, phy_status; |
| 1648 | |
| 1649 | for (i = 0; i < iterations; i++) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1650 | /* Some PHYs require the PHY_STATUS register to be read |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1651 | * twice due to the link bit being sticky. No harm doing |
| 1652 | * it across the board. |
| 1653 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1654 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Andi Kleen | dc3d226 | 2013-04-22 07:46:40 +0000 | [diff] [blame] | 1655 | if (ret_val && usec_interval > 0) { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1656 | /* If the first read fails, another entity may have |
Alexander Duyck | ab57638 | 2009-10-05 06:35:23 +0000 | [diff] [blame] | 1657 | * ownership of the resources, wait and try again to |
| 1658 | * see if they have relinquished the resources yet. |
| 1659 | */ |
Carolyn Wyborny | df29df9 | 2013-12-14 03:26:46 -0800 | [diff] [blame] | 1660 | if (usec_interval >= 1000) |
| 1661 | mdelay(usec_interval/1000); |
| 1662 | else |
| 1663 | udelay(usec_interval); |
Alexander Duyck | ab57638 | 2009-10-05 06:35:23 +0000 | [diff] [blame] | 1664 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1665 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1666 | if (ret_val) |
| 1667 | break; |
| 1668 | if (phy_status & MII_SR_LINK_STATUS) |
| 1669 | break; |
| 1670 | if (usec_interval >= 1000) |
| 1671 | mdelay(usec_interval/1000); |
| 1672 | else |
| 1673 | udelay(usec_interval); |
| 1674 | } |
| 1675 | |
| 1676 | *success = (i < iterations) ? true : false; |
| 1677 | |
| 1678 | return ret_val; |
| 1679 | } |
| 1680 | |
| 1681 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1682 | * igb_get_cable_length_m88 - Determine cable length for m88 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1683 | * @hw: pointer to the HW structure |
| 1684 | * |
| 1685 | * Reads the PHY specific status register to retrieve the cable length |
| 1686 | * information. The cable length is determined by averaging the minimum and |
| 1687 | * maximum values to get the "average" cable length. The m88 PHY has four |
| 1688 | * possible cable length values, which are: |
| 1689 | * Register Value Cable Length |
| 1690 | * 0 < 50 meters |
| 1691 | * 1 50 - 80 meters |
| 1692 | * 2 80 - 110 meters |
| 1693 | * 3 110 - 140 meters |
| 1694 | * 4 > 140 meters |
| 1695 | **/ |
| 1696 | s32 igb_get_cable_length_m88(struct e1000_hw *hw) |
| 1697 | { |
| 1698 | struct e1000_phy_info *phy = &hw->phy; |
| 1699 | s32 ret_val; |
| 1700 | u16 phy_data, index; |
| 1701 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1702 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1703 | if (ret_val) |
| 1704 | goto out; |
| 1705 | |
| 1706 | index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 1707 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1708 | if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) { |
| 1709 | ret_val = -E1000_ERR_PHY; |
| 1710 | goto out; |
| 1711 | } |
| 1712 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1713 | phy->min_cable_length = e1000_m88_cable_length_table[index]; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1714 | phy->max_cable_length = e1000_m88_cable_length_table[index + 1]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1715 | |
| 1716 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; |
| 1717 | |
| 1718 | out: |
| 1719 | return ret_val; |
| 1720 | } |
| 1721 | |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1722 | s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw) |
| 1723 | { |
| 1724 | struct e1000_phy_info *phy = &hw->phy; |
| 1725 | s32 ret_val; |
| 1726 | u16 phy_data, phy_data2, index, default_page, is_cm; |
| 1727 | |
| 1728 | switch (hw->phy.id) { |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1729 | case I210_I_PHY_ID: |
Carolyn Wyborny | 59f3010 | 2012-10-10 04:42:59 +0000 | [diff] [blame] | 1730 | /* Get cable length from PHY Cable Diagnostics Control Reg */ |
| 1731 | ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) + |
| 1732 | (I347AT4_PCDL + phy->addr), |
| 1733 | &phy_data); |
| 1734 | if (ret_val) |
| 1735 | return ret_val; |
| 1736 | |
| 1737 | /* Check if the unit of cable length is meters or cm */ |
| 1738 | ret_val = phy->ops.read_reg(hw, (0x7 << GS40G_PAGE_SHIFT) + |
| 1739 | I347AT4_PCDC, &phy_data2); |
| 1740 | if (ret_val) |
| 1741 | return ret_val; |
| 1742 | |
| 1743 | is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT); |
| 1744 | |
| 1745 | /* Populate the phy structure with cable length in meters */ |
| 1746 | phy->min_cable_length = phy_data / (is_cm ? 100 : 1); |
| 1747 | phy->max_cable_length = phy_data / (is_cm ? 100 : 1); |
| 1748 | phy->cable_length = phy_data / (is_cm ? 100 : 1); |
| 1749 | break; |
Akeem G Abodunrin | 99af472 | 2013-08-28 02:22:58 +0000 | [diff] [blame] | 1750 | case M88E1543_E_PHY_ID: |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1751 | case I347AT4_E_PHY_ID: |
| 1752 | /* Remember the original page select and set it to 7 */ |
| 1753 | ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT, |
| 1754 | &default_page); |
| 1755 | if (ret_val) |
| 1756 | goto out; |
| 1757 | |
| 1758 | ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x07); |
| 1759 | if (ret_val) |
| 1760 | goto out; |
| 1761 | |
| 1762 | /* Get cable length from PHY Cable Diagnostics Control Reg */ |
| 1763 | ret_val = phy->ops.read_reg(hw, (I347AT4_PCDL + phy->addr), |
| 1764 | &phy_data); |
| 1765 | if (ret_val) |
| 1766 | goto out; |
| 1767 | |
| 1768 | /* Check if the unit of cable length is meters or cm */ |
| 1769 | ret_val = phy->ops.read_reg(hw, I347AT4_PCDC, &phy_data2); |
| 1770 | if (ret_val) |
| 1771 | goto out; |
| 1772 | |
Kantecki, Tomasz | d5a0e36 | 2011-10-17 22:06:59 +0000 | [diff] [blame] | 1773 | is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT); |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1774 | |
| 1775 | /* Populate the phy structure with cable length in meters */ |
| 1776 | phy->min_cable_length = phy_data / (is_cm ? 100 : 1); |
| 1777 | phy->max_cable_length = phy_data / (is_cm ? 100 : 1); |
| 1778 | phy->cable_length = phy_data / (is_cm ? 100 : 1); |
| 1779 | |
| 1780 | /* Reset the page selec to its original value */ |
| 1781 | ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, |
| 1782 | default_page); |
| 1783 | if (ret_val) |
| 1784 | goto out; |
| 1785 | break; |
| 1786 | case M88E1112_E_PHY_ID: |
| 1787 | /* Remember the original page select and set it to 5 */ |
| 1788 | ret_val = phy->ops.read_reg(hw, I347AT4_PAGE_SELECT, |
| 1789 | &default_page); |
| 1790 | if (ret_val) |
| 1791 | goto out; |
| 1792 | |
| 1793 | ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, 0x05); |
| 1794 | if (ret_val) |
| 1795 | goto out; |
| 1796 | |
| 1797 | ret_val = phy->ops.read_reg(hw, M88E1112_VCT_DSP_DISTANCE, |
| 1798 | &phy_data); |
| 1799 | if (ret_val) |
| 1800 | goto out; |
| 1801 | |
| 1802 | index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 1803 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
| 1804 | if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) { |
| 1805 | ret_val = -E1000_ERR_PHY; |
| 1806 | goto out; |
| 1807 | } |
| 1808 | |
| 1809 | phy->min_cable_length = e1000_m88_cable_length_table[index]; |
| 1810 | phy->max_cable_length = e1000_m88_cable_length_table[index + 1]; |
| 1811 | |
| 1812 | phy->cable_length = (phy->min_cable_length + |
| 1813 | phy->max_cable_length) / 2; |
| 1814 | |
| 1815 | /* Reset the page select to its original value */ |
| 1816 | ret_val = phy->ops.write_reg(hw, I347AT4_PAGE_SELECT, |
| 1817 | default_page); |
| 1818 | if (ret_val) |
| 1819 | goto out; |
| 1820 | |
| 1821 | break; |
| 1822 | default: |
| 1823 | ret_val = -E1000_ERR_PHY; |
| 1824 | goto out; |
| 1825 | } |
| 1826 | |
| 1827 | out: |
| 1828 | return ret_val; |
| 1829 | } |
| 1830 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1831 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1832 | * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1833 | * @hw: pointer to the HW structure |
| 1834 | * |
| 1835 | * The automatic gain control (agc) normalizes the amplitude of the |
| 1836 | * received signal, adjusting for the attenuation produced by the |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1837 | * cable. By reading the AGC registers, which represent the |
| 1838 | * combination of coarse and fine gain value, the value can be put |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1839 | * into a lookup table to obtain the approximate cable length |
| 1840 | * for each channel. |
| 1841 | **/ |
| 1842 | s32 igb_get_cable_length_igp_2(struct e1000_hw *hw) |
| 1843 | { |
| 1844 | struct e1000_phy_info *phy = &hw->phy; |
| 1845 | s32 ret_val = 0; |
| 1846 | u16 phy_data, i, agc_value = 0; |
| 1847 | u16 cur_agc_index, max_agc_index = 0; |
| 1848 | u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1; |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1849 | static const u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = { |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1850 | IGP02E1000_PHY_AGC_A, |
| 1851 | IGP02E1000_PHY_AGC_B, |
| 1852 | IGP02E1000_PHY_AGC_C, |
| 1853 | IGP02E1000_PHY_AGC_D |
Jeff Kirsher | 6674450 | 2010-12-01 19:59:50 +0000 | [diff] [blame] | 1854 | }; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1855 | |
| 1856 | /* Read the AGC registers for all channels */ |
| 1857 | for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1858 | ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1859 | if (ret_val) |
| 1860 | goto out; |
| 1861 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 1862 | /* Getting bits 15:9, which represent the combination of |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1863 | * coarse and fine gain values. The result is a number |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1864 | * that can be put into the lookup table to obtain the |
| 1865 | * approximate cable length. |
| 1866 | */ |
| 1867 | cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) & |
| 1868 | IGP02E1000_AGC_LENGTH_MASK; |
| 1869 | |
| 1870 | /* Array index bound check. */ |
| 1871 | if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) || |
| 1872 | (cur_agc_index == 0)) { |
| 1873 | ret_val = -E1000_ERR_PHY; |
| 1874 | goto out; |
| 1875 | } |
| 1876 | |
| 1877 | /* Remove min & max AGC values from calculation. */ |
| 1878 | if (e1000_igp_2_cable_length_table[min_agc_index] > |
| 1879 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 1880 | min_agc_index = cur_agc_index; |
| 1881 | if (e1000_igp_2_cable_length_table[max_agc_index] < |
| 1882 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 1883 | max_agc_index = cur_agc_index; |
| 1884 | |
| 1885 | agc_value += e1000_igp_2_cable_length_table[cur_agc_index]; |
| 1886 | } |
| 1887 | |
| 1888 | agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] + |
| 1889 | e1000_igp_2_cable_length_table[max_agc_index]); |
| 1890 | agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2); |
| 1891 | |
| 1892 | /* Calculate cable length with the error range of +/- 10 meters. */ |
| 1893 | phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ? |
| 1894 | (agc_value - IGP02E1000_AGC_RANGE) : 0; |
| 1895 | phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE; |
| 1896 | |
| 1897 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; |
| 1898 | |
| 1899 | out: |
| 1900 | return ret_val; |
| 1901 | } |
| 1902 | |
| 1903 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1904 | * igb_get_phy_info_m88 - Retrieve PHY information |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1905 | * @hw: pointer to the HW structure |
| 1906 | * |
| 1907 | * Valid for only copper links. Read the PHY status register (sticky read) |
| 1908 | * to verify that link is up. Read the PHY special control register to |
| 1909 | * determine the polarity and 10base-T extended distance. Read the PHY |
| 1910 | * special status register to determine MDI/MDIx and current speed. If |
| 1911 | * speed is 1000, then determine cable length, local and remote receiver. |
| 1912 | **/ |
| 1913 | s32 igb_get_phy_info_m88(struct e1000_hw *hw) |
| 1914 | { |
| 1915 | struct e1000_phy_info *phy = &hw->phy; |
| 1916 | s32 ret_val; |
| 1917 | u16 phy_data; |
| 1918 | bool link; |
| 1919 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1920 | if (phy->media_type != e1000_media_type_copper) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1921 | hw_dbg("Phy info is only valid for copper media\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1922 | ret_val = -E1000_ERR_CONFIG; |
| 1923 | goto out; |
| 1924 | } |
| 1925 | |
| 1926 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 1927 | if (ret_val) |
| 1928 | goto out; |
| 1929 | |
| 1930 | if (!link) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1931 | hw_dbg("Phy info is only valid if link is up\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1932 | ret_val = -E1000_ERR_CONFIG; |
| 1933 | goto out; |
| 1934 | } |
| 1935 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1936 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1937 | if (ret_val) |
| 1938 | goto out; |
| 1939 | |
| 1940 | phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1941 | ? true : false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1942 | |
| 1943 | ret_val = igb_check_polarity_m88(hw); |
| 1944 | if (ret_val) |
| 1945 | goto out; |
| 1946 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1947 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1948 | if (ret_val) |
| 1949 | goto out; |
| 1950 | |
| 1951 | phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false; |
| 1952 | |
| 1953 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1954 | ret_val = phy->ops.get_cable_length(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1955 | if (ret_val) |
| 1956 | goto out; |
| 1957 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1958 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1959 | if (ret_val) |
| 1960 | goto out; |
| 1961 | |
| 1962 | phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) |
| 1963 | ? e1000_1000t_rx_status_ok |
| 1964 | : e1000_1000t_rx_status_not_ok; |
| 1965 | |
| 1966 | phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) |
| 1967 | ? e1000_1000t_rx_status_ok |
| 1968 | : e1000_1000t_rx_status_not_ok; |
| 1969 | } else { |
| 1970 | /* Set values to "undefined" */ |
| 1971 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; |
| 1972 | phy->local_rx = e1000_1000t_rx_status_undefined; |
| 1973 | phy->remote_rx = e1000_1000t_rx_status_undefined; |
| 1974 | } |
| 1975 | |
| 1976 | out: |
| 1977 | return ret_val; |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1981 | * igb_get_phy_info_igp - Retrieve igp PHY information |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1982 | * @hw: pointer to the HW structure |
| 1983 | * |
| 1984 | * Read PHY status to determine if link is up. If link is up, then |
| 1985 | * set/determine 10base-T extended distance and polarity correction. Read |
| 1986 | * PHY port status to determine MDI/MDIx and speed. Based on the speed, |
| 1987 | * determine on the cable length, local and remote receiver. |
| 1988 | **/ |
| 1989 | s32 igb_get_phy_info_igp(struct e1000_hw *hw) |
| 1990 | { |
| 1991 | struct e1000_phy_info *phy = &hw->phy; |
| 1992 | s32 ret_val; |
| 1993 | u16 data; |
| 1994 | bool link; |
| 1995 | |
| 1996 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 1997 | if (ret_val) |
| 1998 | goto out; |
| 1999 | |
| 2000 | if (!link) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 2001 | hw_dbg("Phy info is only valid if link is up\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2002 | ret_val = -E1000_ERR_CONFIG; |
| 2003 | goto out; |
| 2004 | } |
| 2005 | |
| 2006 | phy->polarity_correction = true; |
| 2007 | |
| 2008 | ret_val = igb_check_polarity_igp(hw); |
| 2009 | if (ret_val) |
| 2010 | goto out; |
| 2011 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2012 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2013 | if (ret_val) |
| 2014 | goto out; |
| 2015 | |
| 2016 | phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false; |
| 2017 | |
| 2018 | if ((data & IGP01E1000_PSSR_SPEED_MASK) == |
| 2019 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2020 | ret_val = phy->ops.get_cable_length(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2021 | if (ret_val) |
| 2022 | goto out; |
| 2023 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2024 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2025 | if (ret_val) |
| 2026 | goto out; |
| 2027 | |
| 2028 | phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS) |
| 2029 | ? e1000_1000t_rx_status_ok |
| 2030 | : e1000_1000t_rx_status_not_ok; |
| 2031 | |
| 2032 | phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS) |
| 2033 | ? e1000_1000t_rx_status_ok |
| 2034 | : e1000_1000t_rx_status_not_ok; |
| 2035 | } else { |
| 2036 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; |
| 2037 | phy->local_rx = e1000_1000t_rx_status_undefined; |
| 2038 | phy->remote_rx = e1000_1000t_rx_status_undefined; |
| 2039 | } |
| 2040 | |
| 2041 | out: |
| 2042 | return ret_val; |
| 2043 | } |
| 2044 | |
| 2045 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 2046 | * igb_phy_sw_reset - PHY software reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2047 | * @hw: pointer to the HW structure |
| 2048 | * |
| 2049 | * Does a software reset of the PHY by reading the PHY control register and |
| 2050 | * setting/write the control register reset bit to the PHY. |
| 2051 | **/ |
| 2052 | s32 igb_phy_sw_reset(struct e1000_hw *hw) |
| 2053 | { |
Alexander Duyck | d314737 | 2009-09-14 08:23:13 +0000 | [diff] [blame] | 2054 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2055 | u16 phy_ctrl; |
| 2056 | |
Alexander Duyck | d314737 | 2009-09-14 08:23:13 +0000 | [diff] [blame] | 2057 | if (!(hw->phy.ops.read_reg)) |
| 2058 | goto out; |
| 2059 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2060 | ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2061 | if (ret_val) |
| 2062 | goto out; |
| 2063 | |
| 2064 | phy_ctrl |= MII_CR_RESET; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2065 | ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2066 | if (ret_val) |
| 2067 | goto out; |
| 2068 | |
| 2069 | udelay(1); |
| 2070 | |
| 2071 | out: |
| 2072 | return ret_val; |
| 2073 | } |
| 2074 | |
| 2075 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 2076 | * igb_phy_hw_reset - PHY hardware reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2077 | * @hw: pointer to the HW structure |
| 2078 | * |
| 2079 | * Verify the reset block is not blocking us from resetting. Acquire |
| 2080 | * semaphore (if necessary) and read/set/write the device control reset |
| 2081 | * bit in the PHY. Wait the appropriate delay time for the device to |
Geert Uytterhoeven | 83a35e3 | 2013-06-28 11:27:31 +0200 | [diff] [blame] | 2082 | * reset and release the semaphore (if necessary). |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2083 | **/ |
| 2084 | s32 igb_phy_hw_reset(struct e1000_hw *hw) |
| 2085 | { |
| 2086 | struct e1000_phy_info *phy = &hw->phy; |
| 2087 | s32 ret_val; |
| 2088 | u32 ctrl; |
| 2089 | |
| 2090 | ret_val = igb_check_reset_block(hw); |
| 2091 | if (ret_val) { |
| 2092 | ret_val = 0; |
| 2093 | goto out; |
| 2094 | } |
| 2095 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2096 | ret_val = phy->ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2097 | if (ret_val) |
| 2098 | goto out; |
| 2099 | |
| 2100 | ctrl = rd32(E1000_CTRL); |
| 2101 | wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 2102 | wrfl(); |
| 2103 | |
| 2104 | udelay(phy->reset_delay_us); |
| 2105 | |
| 2106 | wr32(E1000_CTRL, ctrl); |
| 2107 | wrfl(); |
| 2108 | |
| 2109 | udelay(150); |
| 2110 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2111 | phy->ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2112 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2113 | ret_val = phy->ops.get_cfg_done(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2114 | |
| 2115 | out: |
| 2116 | return ret_val; |
| 2117 | } |
| 2118 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2119 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 2120 | * igb_phy_init_script_igp3 - Inits the IGP3 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2121 | * @hw: pointer to the HW structure |
| 2122 | * |
| 2123 | * Initializes a Intel Gigabit PHY3 when an EEPROM is not present. |
| 2124 | **/ |
| 2125 | s32 igb_phy_init_script_igp3(struct e1000_hw *hw) |
| 2126 | { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 2127 | hw_dbg("Running IGP 3 PHY init script\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2128 | |
| 2129 | /* PHY init IGP 3 */ |
| 2130 | /* Enable rise/fall, 10-mode work in class-A */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2131 | hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2132 | /* Remove all caps from Replica path filter */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2133 | hw->phy.ops.write_reg(hw, 0x2F52, 0x0000); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2134 | /* Bias trimming for ADC, AFE and Driver (Default) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2135 | hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2136 | /* Increase Hybrid poly bias */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2137 | hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2138 | /* Add 4% to TX amplitude in Giga mode */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2139 | hw->phy.ops.write_reg(hw, 0x2010, 0x10B0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2140 | /* Disable trimming (TTT) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2141 | hw->phy.ops.write_reg(hw, 0x2011, 0x0000); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2142 | /* Poly DC correction to 94.6% + 2% for all channels */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2143 | hw->phy.ops.write_reg(hw, 0x20DD, 0x249A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2144 | /* ABS DC correction to 95.9% */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2145 | hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2146 | /* BG temp curve trim */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2147 | hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2148 | /* Increasing ADC OPAMP stage 1 currents to max */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2149 | hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2150 | /* Force 1000 ( required for enabling PHY regs configuration) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2151 | hw->phy.ops.write_reg(hw, 0x0000, 0x0140); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2152 | /* Set upd_freq to 6 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2153 | hw->phy.ops.write_reg(hw, 0x1F30, 0x1606); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2154 | /* Disable NPDFE */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2155 | hw->phy.ops.write_reg(hw, 0x1F31, 0xB814); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2156 | /* Disable adaptive fixed FFE (Default) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2157 | hw->phy.ops.write_reg(hw, 0x1F35, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2158 | /* Enable FFE hysteresis */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2159 | hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2160 | /* Fixed FFE for short cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2161 | hw->phy.ops.write_reg(hw, 0x1F54, 0x0065); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2162 | /* Fixed FFE for medium cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2163 | hw->phy.ops.write_reg(hw, 0x1F55, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2164 | /* Fixed FFE for long cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2165 | hw->phy.ops.write_reg(hw, 0x1F56, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2166 | /* Enable Adaptive Clip Threshold */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2167 | hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2168 | /* AHT reset limit to 1 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2169 | hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2170 | /* Set AHT master delay to 127 msec */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2171 | hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2172 | /* Set scan bits for AHT */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2173 | hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2174 | /* Set AHT Preset bits */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2175 | hw->phy.ops.write_reg(hw, 0x1F79, 0x0210); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2176 | /* Change integ_factor of channel A to 3 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2177 | hw->phy.ops.write_reg(hw, 0x1895, 0x0003); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2178 | /* Change prop_factor of channels BCD to 8 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2179 | hw->phy.ops.write_reg(hw, 0x1796, 0x0008); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2180 | /* Change cg_icount + enable integbp for channels BCD */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2181 | hw->phy.ops.write_reg(hw, 0x1798, 0xD008); |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2182 | /* Change cg_icount + enable integbp + change prop_factor_master |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2183 | * to 8 for channel A |
| 2184 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2185 | hw->phy.ops.write_reg(hw, 0x1898, 0xD918); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2186 | /* Disable AHT in Slave mode on channel A */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2187 | hw->phy.ops.write_reg(hw, 0x187A, 0x0800); |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2188 | /* Enable LPLU and disable AN to 1000 in non-D0a states, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2189 | * Enable SPD+B2B |
| 2190 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2191 | hw->phy.ops.write_reg(hw, 0x0019, 0x008D); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2192 | /* Enable restart AN on an1000_dis change */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2193 | hw->phy.ops.write_reg(hw, 0x001B, 0x2080); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2194 | /* Enable wh_fifo read clock in 10/100 modes */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2195 | hw->phy.ops.write_reg(hw, 0x0014, 0x0045); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2196 | /* Restart AN, Speed selection is 1000 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2197 | hw->phy.ops.write_reg(hw, 0x0000, 0x1340); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2198 | |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2202 | /** |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2203 | * igb_power_up_phy_copper - Restore copper link in case of PHY power down |
| 2204 | * @hw: pointer to the HW structure |
| 2205 | * |
| 2206 | * In the case of a PHY power down to save power, or to turn off link during a |
| 2207 | * driver unload, restore the link to previous settings. |
| 2208 | **/ |
| 2209 | void igb_power_up_phy_copper(struct e1000_hw *hw) |
| 2210 | { |
| 2211 | u16 mii_reg = 0; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 2212 | u16 power_reg = 0; |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2213 | |
| 2214 | /* The PHY will retain its settings across a power down/up cycle */ |
| 2215 | hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg); |
| 2216 | mii_reg &= ~MII_CR_POWER_DOWN; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 2217 | if (hw->phy.type == e1000_phy_i210) { |
| 2218 | hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg); |
| 2219 | power_reg &= ~GS40G_CS_POWER_DOWN; |
| 2220 | hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg); |
| 2221 | } |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2222 | hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg); |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * igb_power_down_phy_copper - Power down copper PHY |
| 2227 | * @hw: pointer to the HW structure |
| 2228 | * |
| 2229 | * Power down PHY to save power when interface is down and wake on lan |
| 2230 | * is not enabled. |
| 2231 | **/ |
| 2232 | void igb_power_down_phy_copper(struct e1000_hw *hw) |
| 2233 | { |
| 2234 | u16 mii_reg = 0; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 2235 | u16 power_reg = 0; |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2236 | |
| 2237 | /* The PHY will retain its settings across a power down/up cycle */ |
| 2238 | hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg); |
| 2239 | mii_reg |= MII_CR_POWER_DOWN; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 2240 | |
| 2241 | /* i210 Phy requires an additional bit for power up/down */ |
| 2242 | if (hw->phy.type == e1000_phy_i210) { |
| 2243 | hw->phy.ops.read_reg(hw, GS40G_COPPER_SPEC, &power_reg); |
| 2244 | power_reg |= GS40G_CS_POWER_DOWN; |
| 2245 | hw->phy.ops.write_reg(hw, GS40G_COPPER_SPEC, power_reg); |
| 2246 | } |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2247 | hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg); |
| 2248 | msleep(1); |
| 2249 | } |
| 2250 | |
| 2251 | /** |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2252 | * igb_check_polarity_82580 - Checks the polarity. |
| 2253 | * @hw: pointer to the HW structure |
| 2254 | * |
| 2255 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) |
| 2256 | * |
| 2257 | * Polarity is determined based on the PHY specific status register. |
| 2258 | **/ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 2259 | static s32 igb_check_polarity_82580(struct e1000_hw *hw) |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2260 | { |
| 2261 | struct e1000_phy_info *phy = &hw->phy; |
| 2262 | s32 ret_val; |
| 2263 | u16 data; |
| 2264 | |
| 2265 | |
| 2266 | ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data); |
| 2267 | |
| 2268 | if (!ret_val) |
| 2269 | phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY) |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2270 | ? e1000_rev_polarity_reversed |
| 2271 | : e1000_rev_polarity_normal; |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2272 | |
| 2273 | return ret_val; |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY |
| 2278 | * @hw: pointer to the HW structure |
| 2279 | * |
| 2280 | * Calls the PHY setup function to force speed and duplex. Clears the |
| 2281 | * auto-crossover to force MDI manually. Waits for link and returns |
| 2282 | * successful if link up is successful, else -E1000_ERR_PHY (-2). |
| 2283 | **/ |
| 2284 | s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw) |
| 2285 | { |
| 2286 | struct e1000_phy_info *phy = &hw->phy; |
| 2287 | s32 ret_val; |
| 2288 | u16 phy_data; |
| 2289 | bool link; |
| 2290 | |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2291 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); |
| 2292 | if (ret_val) |
| 2293 | goto out; |
| 2294 | |
| 2295 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
| 2296 | |
| 2297 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
| 2298 | if (ret_val) |
| 2299 | goto out; |
| 2300 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2301 | /* Clear Auto-Crossover to force MDI manually. 82580 requires MDI |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2302 | * forced whenever speed and duplex are forced. |
| 2303 | */ |
| 2304 | ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data); |
| 2305 | if (ret_val) |
| 2306 | goto out; |
| 2307 | |
Jesse Brandeburg | 1b55678 | 2012-07-26 02:31:04 +0000 | [diff] [blame] | 2308 | phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK; |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2309 | |
| 2310 | ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data); |
| 2311 | if (ret_val) |
| 2312 | goto out; |
| 2313 | |
| 2314 | hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data); |
| 2315 | |
| 2316 | udelay(1); |
| 2317 | |
| 2318 | if (phy->autoneg_wait_to_complete) { |
| 2319 | hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n"); |
| 2320 | |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2321 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link); |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2322 | if (ret_val) |
| 2323 | goto out; |
| 2324 | |
| 2325 | if (!link) |
| 2326 | hw_dbg("Link taking longer than expected.\n"); |
| 2327 | |
| 2328 | /* Try once more */ |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2329 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link); |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2330 | if (ret_val) |
| 2331 | goto out; |
| 2332 | } |
| 2333 | |
| 2334 | out: |
| 2335 | return ret_val; |
| 2336 | } |
| 2337 | |
| 2338 | /** |
| 2339 | * igb_get_phy_info_82580 - Retrieve I82580 PHY information |
| 2340 | * @hw: pointer to the HW structure |
| 2341 | * |
| 2342 | * Read PHY status to determine if link is up. If link is up, then |
| 2343 | * set/determine 10base-T extended distance and polarity correction. Read |
| 2344 | * PHY port status to determine MDI/MDIx and speed. Based on the speed, |
| 2345 | * determine on the cable length, local and remote receiver. |
| 2346 | **/ |
| 2347 | s32 igb_get_phy_info_82580(struct e1000_hw *hw) |
| 2348 | { |
| 2349 | struct e1000_phy_info *phy = &hw->phy; |
| 2350 | s32 ret_val; |
| 2351 | u16 data; |
| 2352 | bool link; |
| 2353 | |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2354 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 2355 | if (ret_val) |
| 2356 | goto out; |
| 2357 | |
| 2358 | if (!link) { |
| 2359 | hw_dbg("Phy info is only valid if link is up\n"); |
| 2360 | ret_val = -E1000_ERR_CONFIG; |
| 2361 | goto out; |
| 2362 | } |
| 2363 | |
| 2364 | phy->polarity_correction = true; |
| 2365 | |
| 2366 | ret_val = igb_check_polarity_82580(hw); |
| 2367 | if (ret_val) |
| 2368 | goto out; |
| 2369 | |
| 2370 | ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data); |
| 2371 | if (ret_val) |
| 2372 | goto out; |
| 2373 | |
| 2374 | phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false; |
| 2375 | |
| 2376 | if ((data & I82580_PHY_STATUS2_SPEED_MASK) == |
| 2377 | I82580_PHY_STATUS2_SPEED_1000MBPS) { |
| 2378 | ret_val = hw->phy.ops.get_cable_length(hw); |
| 2379 | if (ret_val) |
| 2380 | goto out; |
| 2381 | |
| 2382 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data); |
| 2383 | if (ret_val) |
| 2384 | goto out; |
| 2385 | |
| 2386 | phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS) |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2387 | ? e1000_1000t_rx_status_ok |
| 2388 | : e1000_1000t_rx_status_not_ok; |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2389 | |
| 2390 | phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS) |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2391 | ? e1000_1000t_rx_status_ok |
| 2392 | : e1000_1000t_rx_status_not_ok; |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2393 | } else { |
| 2394 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; |
| 2395 | phy->local_rx = e1000_1000t_rx_status_undefined; |
| 2396 | phy->remote_rx = e1000_1000t_rx_status_undefined; |
| 2397 | } |
| 2398 | |
| 2399 | out: |
| 2400 | return ret_val; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * igb_get_cable_length_82580 - Determine cable length for 82580 PHY |
| 2405 | * @hw: pointer to the HW structure |
| 2406 | * |
| 2407 | * Reads the diagnostic status register and verifies result is valid before |
| 2408 | * placing it in the phy_cable_length field. |
| 2409 | **/ |
| 2410 | s32 igb_get_cable_length_82580(struct e1000_hw *hw) |
| 2411 | { |
| 2412 | struct e1000_phy_info *phy = &hw->phy; |
| 2413 | s32 ret_val; |
| 2414 | u16 phy_data, length; |
| 2415 | |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2416 | ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data); |
| 2417 | if (ret_val) |
| 2418 | goto out; |
| 2419 | |
| 2420 | length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >> |
Jeff Kirsher | b980ac1 | 2013-02-23 07:29:56 +0000 | [diff] [blame] | 2421 | I82580_DSTATUS_CABLE_LENGTH_SHIFT; |
Alexander Duyck | 2909c3f | 2009-11-19 12:41:42 +0000 | [diff] [blame] | 2422 | |
| 2423 | if (length == E1000_CABLE_LENGTH_UNDEFINED) |
| 2424 | ret_val = -E1000_ERR_PHY; |
| 2425 | |
| 2426 | phy->cable_length = length; |
| 2427 | |
| 2428 | out: |
| 2429 | return ret_val; |
| 2430 | } |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 2431 | |
| 2432 | /** |
| 2433 | * igb_write_phy_reg_gs40g - Write GS40G PHY register |
| 2434 | * @hw: pointer to the HW structure |
| 2435 | * @offset: lower half is register offset to write to |
| 2436 | * upper half is page to use. |
| 2437 | * @data: data to write at register offset |
| 2438 | * |
| 2439 | * Acquires semaphore, if necessary, then writes the data to PHY register |
| 2440 | * at the offset. Release any acquired semaphores before exiting. |
| 2441 | **/ |
| 2442 | s32 igb_write_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 data) |
| 2443 | { |
| 2444 | s32 ret_val; |
| 2445 | u16 page = offset >> GS40G_PAGE_SHIFT; |
| 2446 | |
| 2447 | offset = offset & GS40G_OFFSET_MASK; |
| 2448 | ret_val = hw->phy.ops.acquire(hw); |
| 2449 | if (ret_val) |
| 2450 | return ret_val; |
| 2451 | |
| 2452 | ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page); |
| 2453 | if (ret_val) |
| 2454 | goto release; |
| 2455 | ret_val = igb_write_phy_reg_mdic(hw, offset, data); |
| 2456 | |
| 2457 | release: |
| 2458 | hw->phy.ops.release(hw); |
| 2459 | return ret_val; |
| 2460 | } |
| 2461 | |
| 2462 | /** |
| 2463 | * igb_read_phy_reg_gs40g - Read GS40G PHY register |
| 2464 | * @hw: pointer to the HW structure |
| 2465 | * @offset: lower half is register offset to read to |
| 2466 | * upper half is page to use. |
| 2467 | * @data: data to read at register offset |
| 2468 | * |
| 2469 | * Acquires semaphore, if necessary, then reads the data in the PHY register |
| 2470 | * at the offset. Release any acquired semaphores before exiting. |
| 2471 | **/ |
| 2472 | s32 igb_read_phy_reg_gs40g(struct e1000_hw *hw, u32 offset, u16 *data) |
| 2473 | { |
| 2474 | s32 ret_val; |
| 2475 | u16 page = offset >> GS40G_PAGE_SHIFT; |
| 2476 | |
| 2477 | offset = offset & GS40G_OFFSET_MASK; |
| 2478 | ret_val = hw->phy.ops.acquire(hw); |
| 2479 | if (ret_val) |
| 2480 | return ret_val; |
| 2481 | |
| 2482 | ret_val = igb_write_phy_reg_mdic(hw, GS40G_PAGE_SELECT, page); |
| 2483 | if (ret_val) |
| 2484 | goto release; |
| 2485 | ret_val = igb_read_phy_reg_mdic(hw, offset, data); |
| 2486 | |
| 2487 | release: |
| 2488 | hw->phy.ops.release(hw); |
| 2489 | return ret_val; |
| 2490 | } |
| 2491 | |
| 2492 | /** |
| 2493 | * igb_set_master_slave_mode - Setup PHY for Master/slave mode |
| 2494 | * @hw: pointer to the HW structure |
| 2495 | * |
| 2496 | * Sets up Master/slave mode |
| 2497 | **/ |
| 2498 | static s32 igb_set_master_slave_mode(struct e1000_hw *hw) |
| 2499 | { |
| 2500 | s32 ret_val; |
| 2501 | u16 phy_data; |
| 2502 | |
| 2503 | /* Resolve Master/Slave mode */ |
| 2504 | ret_val = hw->phy.ops.read_reg(hw, PHY_1000T_CTRL, &phy_data); |
| 2505 | if (ret_val) |
| 2506 | return ret_val; |
| 2507 | |
| 2508 | /* load defaults for future use */ |
| 2509 | hw->phy.original_ms_type = (phy_data & CR_1000T_MS_ENABLE) ? |
| 2510 | ((phy_data & CR_1000T_MS_VALUE) ? |
| 2511 | e1000_ms_force_master : |
| 2512 | e1000_ms_force_slave) : e1000_ms_auto; |
| 2513 | |
| 2514 | switch (hw->phy.ms_type) { |
| 2515 | case e1000_ms_force_master: |
| 2516 | phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 2517 | break; |
| 2518 | case e1000_ms_force_slave: |
| 2519 | phy_data |= CR_1000T_MS_ENABLE; |
| 2520 | phy_data &= ~(CR_1000T_MS_VALUE); |
| 2521 | break; |
| 2522 | case e1000_ms_auto: |
| 2523 | phy_data &= ~CR_1000T_MS_ENABLE; |
| 2524 | /* fall-through */ |
| 2525 | default: |
| 2526 | break; |
| 2527 | } |
| 2528 | |
| 2529 | return hw->phy.ops.write_reg(hw, PHY_1000T_CTRL, phy_data); |
| 2530 | } |