Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2009 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, |
| 36 | u16 *phy_ctrl); |
| 37 | static s32 igb_wait_autoneg(struct e1000_hw *hw); |
| 38 | |
| 39 | /* Cable length tables */ |
| 40 | static const u16 e1000_m88_cable_length_table[] = |
| 41 | { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED }; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 42 | #define M88E1000_CABLE_LENGTH_TABLE_SIZE \ |
| 43 | (sizeof(e1000_m88_cable_length_table) / \ |
| 44 | sizeof(e1000_m88_cable_length_table[0])) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 45 | |
| 46 | static const u16 e1000_igp_2_cable_length_table[] = |
| 47 | { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, |
| 48 | 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41, |
| 49 | 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61, |
| 50 | 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82, |
| 51 | 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104, |
| 52 | 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121, |
| 53 | 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124, |
| 54 | 104, 109, 114, 118, 121, 124}; |
| 55 | #define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \ |
| 56 | (sizeof(e1000_igp_2_cable_length_table) / \ |
| 57 | sizeof(e1000_igp_2_cable_length_table[0])) |
| 58 | |
| 59 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 60 | * igb_check_reset_block - Check if PHY reset is blocked |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 61 | * @hw: pointer to the HW structure |
| 62 | * |
| 63 | * Read the PHY management control register and check whether a PHY reset |
| 64 | * is blocked. If a reset is not blocked return 0, otherwise |
| 65 | * return E1000_BLK_PHY_RESET (12). |
| 66 | **/ |
| 67 | s32 igb_check_reset_block(struct e1000_hw *hw) |
| 68 | { |
| 69 | u32 manc; |
| 70 | |
| 71 | manc = rd32(E1000_MANC); |
| 72 | |
| 73 | return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ? |
| 74 | E1000_BLK_PHY_RESET : 0; |
| 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 | **/ |
| 139 | static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data) |
| 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 | |
| 151 | /* |
| 152 | * Set up Op-code, Phy Address, and register offset in the MDI |
| 153 | * Control register. The MAC will take care of interfacing with the |
| 154 | * PHY to retrieve the desired data. |
| 155 | */ |
| 156 | mdic = ((offset << E1000_MDIC_REG_SHIFT) | |
| 157 | (phy->addr << E1000_MDIC_PHY_SHIFT) | |
| 158 | (E1000_MDIC_OP_READ)); |
| 159 | |
| 160 | wr32(E1000_MDIC, mdic); |
| 161 | |
| 162 | /* |
| 163 | * Poll the ready bit to see if the MDI read completed |
| 164 | * Increasing the time out as testing showed failures with |
| 165 | * the lower time out |
| 166 | */ |
| 167 | for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) { |
| 168 | udelay(50); |
| 169 | mdic = rd32(E1000_MDIC); |
| 170 | if (mdic & E1000_MDIC_READY) |
| 171 | break; |
| 172 | } |
| 173 | if (!(mdic & E1000_MDIC_READY)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 174 | hw_dbg("MDI Read did not complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 175 | ret_val = -E1000_ERR_PHY; |
| 176 | goto out; |
| 177 | } |
| 178 | if (mdic & E1000_MDIC_ERROR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 179 | hw_dbg("MDI Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 180 | ret_val = -E1000_ERR_PHY; |
| 181 | goto out; |
| 182 | } |
| 183 | *data = (u16) mdic; |
| 184 | |
| 185 | out: |
| 186 | return ret_val; |
| 187 | } |
| 188 | |
| 189 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 190 | * igb_write_phy_reg_mdic - Write MDI control register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 191 | * @hw: pointer to the HW structure |
| 192 | * @offset: register offset to write to |
| 193 | * @data: data to write to register at offset |
| 194 | * |
| 195 | * Writes data to MDI control register in the PHY at offset. |
| 196 | **/ |
| 197 | static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data) |
| 198 | { |
| 199 | struct e1000_phy_info *phy = &hw->phy; |
| 200 | u32 i, mdic = 0; |
| 201 | s32 ret_val = 0; |
| 202 | |
| 203 | if (offset > MAX_PHY_REG_ADDRESS) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 204 | hw_dbg("PHY Address %d is out of range\n", offset); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 205 | ret_val = -E1000_ERR_PARAM; |
| 206 | goto out; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Set up Op-code, Phy Address, and register offset in the MDI |
| 211 | * Control register. The MAC will take care of interfacing with the |
| 212 | * PHY to retrieve the desired data. |
| 213 | */ |
| 214 | mdic = (((u32)data) | |
| 215 | (offset << E1000_MDIC_REG_SHIFT) | |
| 216 | (phy->addr << E1000_MDIC_PHY_SHIFT) | |
| 217 | (E1000_MDIC_OP_WRITE)); |
| 218 | |
| 219 | wr32(E1000_MDIC, mdic); |
| 220 | |
| 221 | /* |
| 222 | * Poll the ready bit to see if the MDI read completed |
| 223 | * Increasing the time out as testing showed failures with |
| 224 | * the lower time out |
| 225 | */ |
| 226 | for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) { |
| 227 | udelay(50); |
| 228 | mdic = rd32(E1000_MDIC); |
| 229 | if (mdic & E1000_MDIC_READY) |
| 230 | break; |
| 231 | } |
| 232 | if (!(mdic & E1000_MDIC_READY)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 233 | hw_dbg("MDI Write did not complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 234 | ret_val = -E1000_ERR_PHY; |
| 235 | goto out; |
| 236 | } |
| 237 | if (mdic & E1000_MDIC_ERROR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 238 | hw_dbg("MDI Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 239 | ret_val = -E1000_ERR_PHY; |
| 240 | goto out; |
| 241 | } |
| 242 | |
| 243 | out: |
| 244 | return ret_val; |
| 245 | } |
| 246 | |
| 247 | /** |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 248 | * igb_read_phy_reg_i2c - Read PHY register using i2c |
| 249 | * @hw: pointer to the HW structure |
| 250 | * @offset: register offset to be read |
| 251 | * @data: pointer to the read data |
| 252 | * |
| 253 | * Reads the PHY register at offset using the i2c interface and stores the |
| 254 | * retrieved information in data. |
| 255 | **/ |
| 256 | s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data) |
| 257 | { |
| 258 | struct e1000_phy_info *phy = &hw->phy; |
| 259 | u32 i, i2ccmd = 0; |
| 260 | |
| 261 | |
| 262 | /* |
| 263 | * Set up Op-code, Phy Address, and register address in the I2CCMD |
| 264 | * register. The MAC will take care of interfacing with the |
| 265 | * PHY to retrieve the desired data. |
| 266 | */ |
| 267 | i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) | |
| 268 | (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) | |
| 269 | (E1000_I2CCMD_OPCODE_READ)); |
| 270 | |
| 271 | wr32(E1000_I2CCMD, i2ccmd); |
| 272 | |
| 273 | /* Poll the ready bit to see if the I2C read completed */ |
| 274 | for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) { |
| 275 | udelay(50); |
| 276 | i2ccmd = rd32(E1000_I2CCMD); |
| 277 | if (i2ccmd & E1000_I2CCMD_READY) |
| 278 | break; |
| 279 | } |
| 280 | if (!(i2ccmd & E1000_I2CCMD_READY)) { |
| 281 | hw_dbg("I2CCMD Read did not complete\n"); |
| 282 | return -E1000_ERR_PHY; |
| 283 | } |
| 284 | if (i2ccmd & E1000_I2CCMD_ERROR) { |
| 285 | hw_dbg("I2CCMD Error bit set\n"); |
| 286 | return -E1000_ERR_PHY; |
| 287 | } |
| 288 | |
| 289 | /* Need to byte-swap the 16-bit value. */ |
| 290 | *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * igb_write_phy_reg_i2c - Write PHY register using i2c |
| 297 | * @hw: pointer to the HW structure |
| 298 | * @offset: register offset to write to |
| 299 | * @data: data to write at register offset |
| 300 | * |
| 301 | * Writes the data to PHY register at the offset using the i2c interface. |
| 302 | **/ |
| 303 | s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data) |
| 304 | { |
| 305 | struct e1000_phy_info *phy = &hw->phy; |
| 306 | u32 i, i2ccmd = 0; |
| 307 | u16 phy_data_swapped; |
| 308 | |
| 309 | |
| 310 | /* Swap the data bytes for the I2C interface */ |
| 311 | phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00); |
| 312 | |
| 313 | /* |
| 314 | * Set up Op-code, Phy Address, and register address in the I2CCMD |
| 315 | * register. The MAC will take care of interfacing with the |
| 316 | * PHY to retrieve the desired data. |
| 317 | */ |
| 318 | i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) | |
| 319 | (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) | |
| 320 | E1000_I2CCMD_OPCODE_WRITE | |
| 321 | phy_data_swapped); |
| 322 | |
| 323 | wr32(E1000_I2CCMD, i2ccmd); |
| 324 | |
| 325 | /* Poll the ready bit to see if the I2C read completed */ |
| 326 | for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) { |
| 327 | udelay(50); |
| 328 | i2ccmd = rd32(E1000_I2CCMD); |
| 329 | if (i2ccmd & E1000_I2CCMD_READY) |
| 330 | break; |
| 331 | } |
| 332 | if (!(i2ccmd & E1000_I2CCMD_READY)) { |
| 333 | hw_dbg("I2CCMD Write did not complete\n"); |
| 334 | return -E1000_ERR_PHY; |
| 335 | } |
| 336 | if (i2ccmd & E1000_I2CCMD_ERROR) { |
| 337 | hw_dbg("I2CCMD Error bit set\n"); |
| 338 | return -E1000_ERR_PHY; |
| 339 | } |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 345 | * igb_read_phy_reg_igp - Read igp PHY register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 346 | * @hw: pointer to the HW structure |
| 347 | * @offset: register offset to be read |
| 348 | * @data: pointer to the read data |
| 349 | * |
| 350 | * Acquires semaphore, if necessary, then reads the PHY register at offset |
| 351 | * and storing the retrieved information in data. Release any acquired |
| 352 | * semaphores before exiting. |
| 353 | **/ |
| 354 | s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data) |
| 355 | { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 356 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 357 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 358 | if (!(hw->phy.ops.acquire)) |
| 359 | goto out; |
| 360 | |
| 361 | ret_val = hw->phy.ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 362 | if (ret_val) |
| 363 | goto out; |
| 364 | |
| 365 | if (offset > MAX_PHY_MULTI_PAGE_REG) { |
| 366 | ret_val = igb_write_phy_reg_mdic(hw, |
| 367 | IGP01E1000_PHY_PAGE_SELECT, |
| 368 | (u16)offset); |
| 369 | if (ret_val) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 370 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 371 | goto out; |
| 372 | } |
| 373 | } |
| 374 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 375 | ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, |
| 376 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 377 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 378 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 379 | |
| 380 | out: |
| 381 | return ret_val; |
| 382 | } |
| 383 | |
| 384 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 385 | * igb_write_phy_reg_igp - Write igp PHY register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 386 | * @hw: pointer to the HW structure |
| 387 | * @offset: register offset to write to |
| 388 | * @data: data to write at register offset |
| 389 | * |
| 390 | * Acquires semaphore, if necessary, then writes the data to PHY register |
| 391 | * at the offset. Release any acquired semaphores before exiting. |
| 392 | **/ |
| 393 | s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data) |
| 394 | { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 395 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 396 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 397 | if (!(hw->phy.ops.acquire)) |
| 398 | goto out; |
| 399 | |
| 400 | ret_val = hw->phy.ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 401 | if (ret_val) |
| 402 | goto out; |
| 403 | |
| 404 | if (offset > MAX_PHY_MULTI_PAGE_REG) { |
| 405 | ret_val = igb_write_phy_reg_mdic(hw, |
| 406 | IGP01E1000_PHY_PAGE_SELECT, |
| 407 | (u16)offset); |
| 408 | if (ret_val) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 409 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 410 | goto out; |
| 411 | } |
| 412 | } |
| 413 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 414 | ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 415 | data); |
| 416 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 417 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 418 | |
| 419 | out: |
| 420 | return ret_val; |
| 421 | } |
| 422 | |
| 423 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 424 | * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 425 | * @hw: pointer to the HW structure |
| 426 | * |
| 427 | * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock |
| 428 | * and downshift values are set also. |
| 429 | **/ |
| 430 | s32 igb_copper_link_setup_m88(struct e1000_hw *hw) |
| 431 | { |
| 432 | struct e1000_phy_info *phy = &hw->phy; |
| 433 | s32 ret_val; |
| 434 | u16 phy_data; |
| 435 | |
| 436 | if (phy->reset_disable) { |
| 437 | ret_val = 0; |
| 438 | goto out; |
| 439 | } |
| 440 | |
| 441 | /* Enable CRS on TX. This must be set for half-duplex operation. */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 442 | 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] | 443 | if (ret_val) |
| 444 | goto out; |
| 445 | |
| 446 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 447 | |
| 448 | /* |
| 449 | * Options: |
| 450 | * MDI/MDI-X = 0 (default) |
| 451 | * 0 - Auto for all speeds |
| 452 | * 1 - MDI mode |
| 453 | * 2 - MDI-X mode |
| 454 | * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes) |
| 455 | */ |
| 456 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 457 | |
| 458 | switch (phy->mdix) { |
| 459 | case 1: |
| 460 | phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE; |
| 461 | break; |
| 462 | case 2: |
| 463 | phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE; |
| 464 | break; |
| 465 | case 3: |
| 466 | phy_data |= M88E1000_PSCR_AUTO_X_1000T; |
| 467 | break; |
| 468 | case 0: |
| 469 | default: |
| 470 | phy_data |= M88E1000_PSCR_AUTO_X_MODE; |
| 471 | break; |
| 472 | } |
| 473 | |
| 474 | /* |
| 475 | * Options: |
| 476 | * disable_polarity_correction = 0 (default) |
| 477 | * Automatic Correction for Reversed Cable Polarity |
| 478 | * 0 - Disabled |
| 479 | * 1 - Enabled |
| 480 | */ |
| 481 | phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL; |
| 482 | if (phy->disable_polarity_correction == 1) |
| 483 | phy_data |= M88E1000_PSCR_POLARITY_REVERSAL; |
| 484 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 485 | 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] | 486 | if (ret_val) |
| 487 | goto out; |
| 488 | |
| 489 | if (phy->revision < E1000_REVISION_4) { |
| 490 | /* |
| 491 | * Force TX_CLK in the Extended PHY Specific Control Register |
| 492 | * to 25MHz clock. |
| 493 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 494 | ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 495 | &phy_data); |
| 496 | if (ret_val) |
| 497 | goto out; |
| 498 | |
| 499 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
| 500 | |
| 501 | if ((phy->revision == E1000_REVISION_2) && |
| 502 | (phy->id == M88E1111_I_PHY_ID)) { |
| 503 | /* 82573L PHY - set the downshift counter to 5x. */ |
| 504 | phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK; |
| 505 | phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X; |
| 506 | } else { |
| 507 | /* Configure Master and Slave downshift values */ |
| 508 | phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK | |
| 509 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK); |
| 510 | phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X | |
| 511 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X); |
| 512 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 513 | ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 514 | phy_data); |
| 515 | if (ret_val) |
| 516 | goto out; |
| 517 | } |
| 518 | |
| 519 | /* Commit the changes. */ |
| 520 | ret_val = igb_phy_sw_reset(hw); |
| 521 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 522 | hw_dbg("Error committing the PHY changes\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 523 | goto out; |
| 524 | } |
| 525 | |
| 526 | out: |
| 527 | return ret_val; |
| 528 | } |
| 529 | |
| 530 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 531 | * igb_copper_link_setup_igp - Setup igp PHY's for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 532 | * @hw: pointer to the HW structure |
| 533 | * |
| 534 | * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for |
| 535 | * igp PHY's. |
| 536 | **/ |
| 537 | s32 igb_copper_link_setup_igp(struct e1000_hw *hw) |
| 538 | { |
| 539 | struct e1000_phy_info *phy = &hw->phy; |
| 540 | s32 ret_val; |
| 541 | u16 data; |
| 542 | |
| 543 | if (phy->reset_disable) { |
| 544 | ret_val = 0; |
| 545 | goto out; |
| 546 | } |
| 547 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 548 | ret_val = phy->ops.reset(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 549 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 550 | hw_dbg("Error resetting the PHY.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 551 | goto out; |
| 552 | } |
| 553 | |
Alexander Duyck | a6a6056 | 2009-03-31 20:38:38 +0000 | [diff] [blame] | 554 | /* |
| 555 | * Wait 100ms for MAC to configure PHY from NVM settings, to avoid |
| 556 | * timeout issues when LFS is enabled. |
| 557 | */ |
| 558 | msleep(100); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 559 | |
| 560 | /* |
| 561 | * The NVM settings will configure LPLU in D3 for |
| 562 | * non-IGP1 PHYs. |
| 563 | */ |
| 564 | if (phy->type == e1000_phy_igp) { |
| 565 | /* disable lplu d3 during driver init */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 566 | if (phy->ops.set_d3_lplu_state) |
| 567 | ret_val = phy->ops.set_d3_lplu_state(hw, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 568 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 569 | hw_dbg("Error Disabling LPLU D3\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 570 | goto out; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /* disable lplu d0 during driver init */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 575 | ret_val = phy->ops.set_d0_lplu_state(hw, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 576 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 577 | hw_dbg("Error Disabling LPLU D0\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 578 | goto out; |
| 579 | } |
| 580 | /* Configure mdi-mdix settings */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 581 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 582 | if (ret_val) |
| 583 | goto out; |
| 584 | |
| 585 | data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 586 | |
| 587 | switch (phy->mdix) { |
| 588 | case 1: |
| 589 | data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 590 | break; |
| 591 | case 2: |
| 592 | data |= IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 593 | break; |
| 594 | case 0: |
| 595 | default: |
| 596 | data |= IGP01E1000_PSCR_AUTO_MDIX; |
| 597 | break; |
| 598 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 599 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 600 | if (ret_val) |
| 601 | goto out; |
| 602 | |
| 603 | /* set auto-master slave resolution settings */ |
| 604 | if (hw->mac.autoneg) { |
| 605 | /* |
| 606 | * when autonegotiation advertisement is only 1000Mbps then we |
| 607 | * should disable SmartSpeed and enable Auto MasterSlave |
| 608 | * resolution as hardware default. |
| 609 | */ |
| 610 | if (phy->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 611 | /* Disable SmartSpeed */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 612 | ret_val = phy->ops.read_reg(hw, |
| 613 | IGP01E1000_PHY_PORT_CONFIG, |
| 614 | &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 615 | if (ret_val) |
| 616 | goto out; |
| 617 | |
| 618 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 619 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 620 | IGP01E1000_PHY_PORT_CONFIG, |
| 621 | data); |
| 622 | if (ret_val) |
| 623 | goto out; |
| 624 | |
| 625 | /* Set auto Master/Slave resolution process */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 626 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 627 | if (ret_val) |
| 628 | goto out; |
| 629 | |
| 630 | data &= ~CR_1000T_MS_ENABLE; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 631 | ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 632 | if (ret_val) |
| 633 | goto out; |
| 634 | } |
| 635 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 636 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 637 | if (ret_val) |
| 638 | goto out; |
| 639 | |
| 640 | /* load defaults for future use */ |
| 641 | phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ? |
| 642 | ((data & CR_1000T_MS_VALUE) ? |
| 643 | e1000_ms_force_master : |
| 644 | e1000_ms_force_slave) : |
| 645 | e1000_ms_auto; |
| 646 | |
| 647 | switch (phy->ms_type) { |
| 648 | case e1000_ms_force_master: |
| 649 | data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE); |
| 650 | break; |
| 651 | case e1000_ms_force_slave: |
| 652 | data |= CR_1000T_MS_ENABLE; |
| 653 | data &= ~(CR_1000T_MS_VALUE); |
| 654 | break; |
| 655 | case e1000_ms_auto: |
| 656 | data &= ~CR_1000T_MS_ENABLE; |
| 657 | default: |
| 658 | break; |
| 659 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 660 | ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 661 | if (ret_val) |
| 662 | goto out; |
| 663 | } |
| 664 | |
| 665 | out: |
| 666 | return ret_val; |
| 667 | } |
| 668 | |
| 669 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 670 | * igb_copper_link_autoneg - Setup/Enable autoneg for copper link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 671 | * @hw: pointer to the HW structure |
| 672 | * |
| 673 | * Performs initial bounds checking on autoneg advertisement parameter, then |
| 674 | * configure to advertise the full capability. Setup the PHY to autoneg |
| 675 | * and restart the negotiation process between the link partner. If |
| 676 | * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. |
| 677 | **/ |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 678 | static s32 igb_copper_link_autoneg(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 679 | { |
| 680 | struct e1000_phy_info *phy = &hw->phy; |
| 681 | s32 ret_val; |
| 682 | u16 phy_ctrl; |
| 683 | |
| 684 | /* |
| 685 | * Perform some bounds checking on the autoneg advertisement |
| 686 | * parameter. |
| 687 | */ |
| 688 | phy->autoneg_advertised &= phy->autoneg_mask; |
| 689 | |
| 690 | /* |
| 691 | * If autoneg_advertised is zero, we assume it was not defaulted |
| 692 | * by the calling code so we set to advertise full capability. |
| 693 | */ |
| 694 | if (phy->autoneg_advertised == 0) |
| 695 | phy->autoneg_advertised = phy->autoneg_mask; |
| 696 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 697 | hw_dbg("Reconfiguring auto-neg advertisement params\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 698 | ret_val = igb_phy_setup_autoneg(hw); |
| 699 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 700 | hw_dbg("Error Setting up Auto-Negotiation\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 701 | goto out; |
| 702 | } |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 703 | hw_dbg("Restarting Auto-Neg\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 704 | |
| 705 | /* |
| 706 | * Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 707 | * the Auto Neg Restart bit in the PHY control register. |
| 708 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 709 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 710 | if (ret_val) |
| 711 | goto out; |
| 712 | |
| 713 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 714 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 715 | if (ret_val) |
| 716 | goto out; |
| 717 | |
| 718 | /* |
| 719 | * Does the user want to wait for Auto-Neg to complete here, or |
| 720 | * check at a later time (for example, callback routine). |
| 721 | */ |
| 722 | if (phy->autoneg_wait_to_complete) { |
| 723 | ret_val = igb_wait_autoneg(hw); |
| 724 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 725 | hw_dbg("Error while waiting for " |
| 726 | "autoneg to complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 727 | goto out; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | hw->mac.get_link_status = true; |
| 732 | |
| 733 | out: |
| 734 | return ret_val; |
| 735 | } |
| 736 | |
| 737 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 738 | * igb_phy_setup_autoneg - Configure PHY for auto-negotiation |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 739 | * @hw: pointer to the HW structure |
| 740 | * |
| 741 | * Reads the MII auto-neg advertisement register and/or the 1000T control |
| 742 | * register and if the PHY is already setup for auto-negotiation, then |
| 743 | * return successful. Otherwise, setup advertisement and flow control to |
| 744 | * the appropriate values for the wanted auto-negotiation. |
| 745 | **/ |
| 746 | static s32 igb_phy_setup_autoneg(struct e1000_hw *hw) |
| 747 | { |
| 748 | struct e1000_phy_info *phy = &hw->phy; |
| 749 | s32 ret_val; |
| 750 | u16 mii_autoneg_adv_reg; |
| 751 | u16 mii_1000t_ctrl_reg = 0; |
| 752 | |
| 753 | phy->autoneg_advertised &= phy->autoneg_mask; |
| 754 | |
| 755 | /* Read the MII Auto-Neg Advertisement Register (Address 4). */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 756 | 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] | 757 | if (ret_val) |
| 758 | goto out; |
| 759 | |
| 760 | if (phy->autoneg_mask & ADVERTISE_1000_FULL) { |
| 761 | /* Read the MII 1000Base-T Control Register (Address 9). */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 762 | ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 763 | &mii_1000t_ctrl_reg); |
| 764 | if (ret_val) |
| 765 | goto out; |
| 766 | } |
| 767 | |
| 768 | /* |
| 769 | * Need to parse both autoneg_advertised and fc and set up |
| 770 | * the appropriate PHY registers. First we will parse for |
| 771 | * autoneg_advertised software override. Since we can advertise |
| 772 | * a plethora of combinations, we need to check each bit |
| 773 | * individually. |
| 774 | */ |
| 775 | |
| 776 | /* |
| 777 | * First we clear all the 10/100 mb speed bits in the Auto-Neg |
| 778 | * Advertisement Register (Address 4) and the 1000 mb speed bits in |
| 779 | * the 1000Base-T Control Register (Address 9). |
| 780 | */ |
| 781 | mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS | |
| 782 | NWAY_AR_100TX_HD_CAPS | |
| 783 | NWAY_AR_10T_FD_CAPS | |
| 784 | NWAY_AR_10T_HD_CAPS); |
| 785 | mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS); |
| 786 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 787 | hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 788 | |
| 789 | /* Do we want to advertise 10 Mb Half Duplex? */ |
| 790 | if (phy->autoneg_advertised & ADVERTISE_10_HALF) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 791 | hw_dbg("Advertise 10mb Half duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 792 | mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS; |
| 793 | } |
| 794 | |
| 795 | /* Do we want to advertise 10 Mb Full Duplex? */ |
| 796 | if (phy->autoneg_advertised & ADVERTISE_10_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 797 | hw_dbg("Advertise 10mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 798 | mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS; |
| 799 | } |
| 800 | |
| 801 | /* Do we want to advertise 100 Mb Half Duplex? */ |
| 802 | if (phy->autoneg_advertised & ADVERTISE_100_HALF) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 803 | hw_dbg("Advertise 100mb Half duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 804 | mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS; |
| 805 | } |
| 806 | |
| 807 | /* Do we want to advertise 100 Mb Full Duplex? */ |
| 808 | if (phy->autoneg_advertised & ADVERTISE_100_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 809 | hw_dbg("Advertise 100mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 810 | mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS; |
| 811 | } |
| 812 | |
| 813 | /* We do not allow the Phy to advertise 1000 Mb Half Duplex */ |
| 814 | if (phy->autoneg_advertised & ADVERTISE_1000_HALF) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 815 | hw_dbg("Advertise 1000mb Half duplex request denied!\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 816 | |
| 817 | /* Do we want to advertise 1000 Mb Full Duplex? */ |
| 818 | if (phy->autoneg_advertised & ADVERTISE_1000_FULL) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 819 | hw_dbg("Advertise 1000mb Full duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 820 | mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS; |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Check for a software override of the flow control settings, and |
| 825 | * setup the PHY advertisement registers accordingly. If |
| 826 | * auto-negotiation is enabled, then software will have to set the |
| 827 | * "PAUSE" bits to the correct value in the Auto-Negotiation |
| 828 | * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto- |
| 829 | * negotiation. |
| 830 | * |
| 831 | * The possible values of the "fc" parameter are: |
| 832 | * 0: Flow control is completely disabled |
| 833 | * 1: Rx flow control is enabled (we can receive pause frames |
| 834 | * but not send pause frames). |
| 835 | * 2: Tx flow control is enabled (we can send pause frames |
| 836 | * but we do not support receiving pause frames). |
| 837 | * 3: Both Rx and TX flow control (symmetric) are enabled. |
| 838 | * other: No software override. The flow control configuration |
| 839 | * in the EEPROM is used. |
| 840 | */ |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 841 | switch (hw->fc.current_mode) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 842 | case e1000_fc_none: |
| 843 | /* |
| 844 | * Flow control (RX & TX) is completely disabled by a |
| 845 | * software over-ride. |
| 846 | */ |
| 847 | mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 848 | break; |
| 849 | case e1000_fc_rx_pause: |
| 850 | /* |
| 851 | * RX Flow control is enabled, and TX Flow control is |
| 852 | * disabled, by a software over-ride. |
| 853 | * |
| 854 | * Since there really isn't a way to advertise that we are |
| 855 | * capable of RX Pause ONLY, we will advertise that we |
| 856 | * support both symmetric and asymmetric RX PAUSE. Later |
| 857 | * (in e1000_config_fc_after_link_up) we will disable the |
| 858 | * hw's ability to send PAUSE frames. |
| 859 | */ |
| 860 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 861 | break; |
| 862 | case e1000_fc_tx_pause: |
| 863 | /* |
| 864 | * TX Flow control is enabled, and RX Flow control is |
| 865 | * disabled, by a software over-ride. |
| 866 | */ |
| 867 | mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR; |
| 868 | mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; |
| 869 | break; |
| 870 | case e1000_fc_full: |
| 871 | /* |
| 872 | * Flow control (both RX and TX) is enabled by a software |
| 873 | * over-ride. |
| 874 | */ |
| 875 | mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); |
| 876 | break; |
| 877 | default: |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 878 | hw_dbg("Flow control param set incorrectly\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 879 | ret_val = -E1000_ERR_CONFIG; |
| 880 | goto out; |
| 881 | } |
| 882 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 883 | 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] | 884 | if (ret_val) |
| 885 | goto out; |
| 886 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 887 | hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 888 | |
| 889 | if (phy->autoneg_mask & ADVERTISE_1000_FULL) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 890 | ret_val = phy->ops.write_reg(hw, |
| 891 | PHY_1000T_CTRL, |
| 892 | mii_1000t_ctrl_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 893 | if (ret_val) |
| 894 | goto out; |
| 895 | } |
| 896 | |
| 897 | out: |
| 898 | return ret_val; |
| 899 | } |
| 900 | |
| 901 | /** |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 902 | * igb_setup_copper_link - Configure copper link settings |
| 903 | * @hw: pointer to the HW structure |
| 904 | * |
| 905 | * Calls the appropriate function to configure the link for auto-neg or forced |
| 906 | * speed and duplex. Then we check for link, once link is established calls |
| 907 | * to configure collision distance and flow control are called. If link is |
| 908 | * not established, we return -E1000_ERR_PHY (-2). |
| 909 | **/ |
| 910 | s32 igb_setup_copper_link(struct e1000_hw *hw) |
| 911 | { |
| 912 | s32 ret_val; |
| 913 | bool link; |
| 914 | |
| 915 | |
| 916 | if (hw->mac.autoneg) { |
| 917 | /* |
| 918 | * Setup autoneg and flow control advertisement and perform |
| 919 | * autonegotiation. |
| 920 | */ |
| 921 | ret_val = igb_copper_link_autoneg(hw); |
| 922 | if (ret_val) |
| 923 | goto out; |
| 924 | } else { |
| 925 | /* |
| 926 | * PHY will be set to 10H, 10F, 100H or 100F |
| 927 | * depending on user settings. |
| 928 | */ |
| 929 | hw_dbg("Forcing Speed and Duplex\n"); |
| 930 | ret_val = hw->phy.ops.force_speed_duplex(hw); |
| 931 | if (ret_val) { |
| 932 | hw_dbg("Error Forcing Speed and Duplex\n"); |
| 933 | goto out; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * Check link status. Wait up to 100 microseconds for link to become |
| 939 | * valid. |
| 940 | */ |
| 941 | ret_val = igb_phy_has_link(hw, |
| 942 | COPPER_LINK_UP_LIMIT, |
| 943 | 10, |
| 944 | &link); |
| 945 | if (ret_val) |
| 946 | goto out; |
| 947 | |
| 948 | if (link) { |
| 949 | hw_dbg("Valid link established!!!\n"); |
| 950 | igb_config_collision_dist(hw); |
| 951 | ret_val = igb_config_fc_after_link_up(hw); |
| 952 | } else { |
| 953 | hw_dbg("Unable to establish link!!!\n"); |
| 954 | } |
| 955 | |
| 956 | out: |
| 957 | return ret_val; |
| 958 | } |
| 959 | |
| 960 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 961 | * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 962 | * @hw: pointer to the HW structure |
| 963 | * |
| 964 | * Calls the PHY setup function to force speed and duplex. Clears the |
| 965 | * auto-crossover to force MDI manually. Waits for link and returns |
| 966 | * successful if link up is successful, else -E1000_ERR_PHY (-2). |
| 967 | **/ |
| 968 | s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw) |
| 969 | { |
| 970 | struct e1000_phy_info *phy = &hw->phy; |
| 971 | s32 ret_val; |
| 972 | u16 phy_data; |
| 973 | bool link; |
| 974 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 975 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 976 | if (ret_val) |
| 977 | goto out; |
| 978 | |
| 979 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
| 980 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 981 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 982 | if (ret_val) |
| 983 | goto out; |
| 984 | |
| 985 | /* |
| 986 | * Clear Auto-Crossover to force MDI manually. IGP requires MDI |
| 987 | * forced whenever speed and duplex are forced. |
| 988 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 989 | 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] | 990 | if (ret_val) |
| 991 | goto out; |
| 992 | |
| 993 | phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX; |
| 994 | phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX; |
| 995 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 996 | 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] | 997 | if (ret_val) |
| 998 | goto out; |
| 999 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1000 | hw_dbg("IGP PSCR: %X\n", phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1001 | |
| 1002 | udelay(1); |
| 1003 | |
| 1004 | if (phy->autoneg_wait_to_complete) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1005 | hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1006 | |
| 1007 | ret_val = igb_phy_has_link(hw, |
| 1008 | PHY_FORCE_LIMIT, |
| 1009 | 100000, |
| 1010 | &link); |
| 1011 | if (ret_val) |
| 1012 | goto out; |
| 1013 | |
| 1014 | if (!link) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1015 | hw_dbg("Link taking longer than expected.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1016 | |
| 1017 | /* Try once more */ |
| 1018 | ret_val = igb_phy_has_link(hw, |
| 1019 | PHY_FORCE_LIMIT, |
| 1020 | 100000, |
| 1021 | &link); |
| 1022 | if (ret_val) |
| 1023 | goto out; |
| 1024 | } |
| 1025 | |
| 1026 | out: |
| 1027 | return ret_val; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1031 | * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1032 | * @hw: pointer to the HW structure |
| 1033 | * |
| 1034 | * Calls the PHY setup function to force speed and duplex. Clears the |
| 1035 | * auto-crossover to force MDI manually. Resets the PHY to commit the |
| 1036 | * changes. If time expires while waiting for link up, we reset the DSP. |
| 1037 | * After reset, TX_CLK and CRS on TX must be set. Return successful upon |
| 1038 | * successful completion, else return corresponding error code. |
| 1039 | **/ |
| 1040 | s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw) |
| 1041 | { |
| 1042 | struct e1000_phy_info *phy = &hw->phy; |
| 1043 | s32 ret_val; |
| 1044 | u16 phy_data; |
| 1045 | bool link; |
| 1046 | |
| 1047 | /* |
| 1048 | * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI |
| 1049 | * forced whenever speed and duplex are forced. |
| 1050 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1051 | 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] | 1052 | if (ret_val) |
| 1053 | goto out; |
| 1054 | |
| 1055 | phy_data &= ~M88E1000_PSCR_AUTO_X_MODE; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1056 | 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] | 1057 | if (ret_val) |
| 1058 | goto out; |
| 1059 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1060 | hw_dbg("M88E1000 PSCR: %X\n", phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1061 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1062 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1063 | if (ret_val) |
| 1064 | goto out; |
| 1065 | |
| 1066 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
| 1067 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1068 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1069 | if (ret_val) |
| 1070 | goto out; |
| 1071 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1072 | /* Reset the phy to commit changes. */ |
| 1073 | ret_val = igb_phy_sw_reset(hw); |
| 1074 | if (ret_val) |
| 1075 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1076 | |
| 1077 | if (phy->autoneg_wait_to_complete) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1078 | hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1079 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1080 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1081 | if (ret_val) |
| 1082 | goto out; |
| 1083 | |
| 1084 | if (!link) { |
| 1085 | /* |
| 1086 | * We didn't get link. |
| 1087 | * Reset the DSP and cross our fingers. |
| 1088 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1089 | ret_val = phy->ops.write_reg(hw, |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1090 | M88E1000_PHY_PAGE_SELECT, |
| 1091 | 0x001d); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1092 | if (ret_val) |
| 1093 | goto out; |
| 1094 | ret_val = igb_phy_reset_dsp(hw); |
| 1095 | if (ret_val) |
| 1096 | goto out; |
| 1097 | } |
| 1098 | |
| 1099 | /* Try once more */ |
| 1100 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1101 | 100000, &link); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1102 | if (ret_val) |
| 1103 | goto out; |
| 1104 | } |
| 1105 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1106 | 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] | 1107 | if (ret_val) |
| 1108 | goto out; |
| 1109 | |
| 1110 | /* |
| 1111 | * Resetting the phy means we need to re-force TX_CLK in the |
| 1112 | * Extended PHY Specific Control Register to 25MHz clock from |
| 1113 | * the reset value of 2.5MHz. |
| 1114 | */ |
| 1115 | phy_data |= M88E1000_EPSCR_TX_CLK_25; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1116 | 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] | 1117 | if (ret_val) |
| 1118 | goto out; |
| 1119 | |
| 1120 | /* |
| 1121 | * In addition, we must re-enable CRS on Tx for both half and full |
| 1122 | * duplex. |
| 1123 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1124 | 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] | 1125 | if (ret_val) |
| 1126 | goto out; |
| 1127 | |
| 1128 | phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1129 | 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] | 1130 | |
| 1131 | out: |
| 1132 | return ret_val; |
| 1133 | } |
| 1134 | |
| 1135 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1136 | * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1137 | * @hw: pointer to the HW structure |
| 1138 | * @phy_ctrl: pointer to current value of PHY_CONTROL |
| 1139 | * |
| 1140 | * Forces speed and duplex on the PHY by doing the following: disable flow |
| 1141 | * control, force speed/duplex on the MAC, disable auto speed detection, |
| 1142 | * disable auto-negotiation, configure duplex, configure speed, configure |
| 1143 | * the collision distance, write configuration to CTRL register. The |
| 1144 | * caller must write to the PHY_CONTROL register for these settings to |
| 1145 | * take affect. |
| 1146 | **/ |
| 1147 | static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, |
| 1148 | u16 *phy_ctrl) |
| 1149 | { |
| 1150 | struct e1000_mac_info *mac = &hw->mac; |
| 1151 | u32 ctrl; |
| 1152 | |
| 1153 | /* Turn off flow control when forcing speed/duplex */ |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1154 | hw->fc.current_mode = e1000_fc_none; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1155 | |
| 1156 | /* Force speed/duplex on the mac */ |
| 1157 | ctrl = rd32(E1000_CTRL); |
| 1158 | ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1159 | ctrl &= ~E1000_CTRL_SPD_SEL; |
| 1160 | |
| 1161 | /* Disable Auto Speed Detection */ |
| 1162 | ctrl &= ~E1000_CTRL_ASDE; |
| 1163 | |
| 1164 | /* Disable autoneg on the phy */ |
| 1165 | *phy_ctrl &= ~MII_CR_AUTO_NEG_EN; |
| 1166 | |
| 1167 | /* Forcing Full or Half Duplex? */ |
| 1168 | if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) { |
| 1169 | ctrl &= ~E1000_CTRL_FD; |
| 1170 | *phy_ctrl &= ~MII_CR_FULL_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1171 | hw_dbg("Half Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1172 | } else { |
| 1173 | ctrl |= E1000_CTRL_FD; |
| 1174 | *phy_ctrl |= MII_CR_FULL_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1175 | hw_dbg("Full Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* Forcing 10mb or 100mb? */ |
| 1179 | if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) { |
| 1180 | ctrl |= E1000_CTRL_SPD_100; |
| 1181 | *phy_ctrl |= MII_CR_SPEED_100; |
| 1182 | *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10); |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1183 | hw_dbg("Forcing 100mb\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1184 | } else { |
| 1185 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1186 | *phy_ctrl |= MII_CR_SPEED_10; |
| 1187 | *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100); |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1188 | hw_dbg("Forcing 10mb\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | igb_config_collision_dist(hw); |
| 1192 | |
| 1193 | wr32(E1000_CTRL, ctrl); |
| 1194 | } |
| 1195 | |
| 1196 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1197 | * 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] | 1198 | * @hw: pointer to the HW structure |
| 1199 | * @active: boolean used to enable/disable lplu |
| 1200 | * |
| 1201 | * Success returns 0, Failure returns 1 |
| 1202 | * |
| 1203 | * The low power link up (lplu) state is set to the power management level D3 |
| 1204 | * and SmartSpeed is disabled when active is true, else clear lplu for D3 |
| 1205 | * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU |
| 1206 | * is used during Dx states where the power conservation is most important. |
| 1207 | * During driver activity, SmartSpeed should be enabled so performance is |
| 1208 | * maintained. |
| 1209 | **/ |
| 1210 | s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active) |
| 1211 | { |
| 1212 | struct e1000_phy_info *phy = &hw->phy; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1213 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1214 | u16 data; |
| 1215 | |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1216 | if (!(hw->phy.ops.read_reg)) |
| 1217 | goto out; |
| 1218 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1219 | ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1220 | if (ret_val) |
| 1221 | goto out; |
| 1222 | |
| 1223 | if (!active) { |
| 1224 | data &= ~IGP02E1000_PM_D3_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1225 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1226 | data); |
| 1227 | if (ret_val) |
| 1228 | goto out; |
| 1229 | /* |
| 1230 | * LPLU and SmartSpeed are mutually exclusive. LPLU is used |
| 1231 | * during Dx states where the power conservation is most |
| 1232 | * important. During driver activity we should enable |
| 1233 | * SmartSpeed, so performance is maintained. |
| 1234 | */ |
| 1235 | if (phy->smart_speed == e1000_smart_speed_on) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1236 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1237 | IGP01E1000_PHY_PORT_CONFIG, |
| 1238 | &data); |
| 1239 | if (ret_val) |
| 1240 | goto out; |
| 1241 | |
| 1242 | data |= IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1243 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1244 | IGP01E1000_PHY_PORT_CONFIG, |
| 1245 | data); |
| 1246 | if (ret_val) |
| 1247 | goto out; |
| 1248 | } else if (phy->smart_speed == e1000_smart_speed_off) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1249 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1250 | IGP01E1000_PHY_PORT_CONFIG, |
| 1251 | &data); |
| 1252 | if (ret_val) |
| 1253 | goto out; |
| 1254 | |
| 1255 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1256 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1257 | IGP01E1000_PHY_PORT_CONFIG, |
| 1258 | data); |
| 1259 | if (ret_val) |
| 1260 | goto out; |
| 1261 | } |
| 1262 | } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) || |
| 1263 | (phy->autoneg_advertised == E1000_ALL_NOT_GIG) || |
| 1264 | (phy->autoneg_advertised == E1000_ALL_10_SPEED)) { |
| 1265 | data |= IGP02E1000_PM_D3_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1266 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1267 | data); |
| 1268 | if (ret_val) |
| 1269 | goto out; |
| 1270 | |
| 1271 | /* When LPLU is enabled, we should disable SmartSpeed */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1272 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1273 | &data); |
| 1274 | if (ret_val) |
| 1275 | goto out; |
| 1276 | |
| 1277 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1278 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1279 | data); |
| 1280 | } |
| 1281 | |
| 1282 | out: |
| 1283 | return ret_val; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1287 | * igb_check_downshift - Checks whether a downshift in speed occured |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1288 | * @hw: pointer to the HW structure |
| 1289 | * |
| 1290 | * Success returns 0, Failure returns 1 |
| 1291 | * |
| 1292 | * A downshift is detected by querying the PHY link health. |
| 1293 | **/ |
| 1294 | s32 igb_check_downshift(struct e1000_hw *hw) |
| 1295 | { |
| 1296 | struct e1000_phy_info *phy = &hw->phy; |
| 1297 | s32 ret_val; |
| 1298 | u16 phy_data, offset, mask; |
| 1299 | |
| 1300 | switch (phy->type) { |
| 1301 | case e1000_phy_m88: |
| 1302 | case e1000_phy_gg82563: |
| 1303 | offset = M88E1000_PHY_SPEC_STATUS; |
| 1304 | mask = M88E1000_PSSR_DOWNSHIFT; |
| 1305 | break; |
| 1306 | case e1000_phy_igp_2: |
| 1307 | case e1000_phy_igp: |
| 1308 | case e1000_phy_igp_3: |
| 1309 | offset = IGP01E1000_PHY_LINK_HEALTH; |
| 1310 | mask = IGP01E1000_PLHR_SS_DOWNGRADE; |
| 1311 | break; |
| 1312 | default: |
| 1313 | /* speed downshift not supported */ |
| 1314 | phy->speed_downgraded = false; |
| 1315 | ret_val = 0; |
| 1316 | goto out; |
| 1317 | } |
| 1318 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1319 | ret_val = phy->ops.read_reg(hw, offset, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1320 | |
| 1321 | if (!ret_val) |
| 1322 | phy->speed_downgraded = (phy_data & mask) ? true : false; |
| 1323 | |
| 1324 | out: |
| 1325 | return ret_val; |
| 1326 | } |
| 1327 | |
| 1328 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1329 | * igb_check_polarity_m88 - Checks the polarity. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1330 | * @hw: pointer to the HW structure |
| 1331 | * |
| 1332 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) |
| 1333 | * |
| 1334 | * Polarity is determined based on the PHY specific status register. |
| 1335 | **/ |
| 1336 | static s32 igb_check_polarity_m88(struct e1000_hw *hw) |
| 1337 | { |
| 1338 | struct e1000_phy_info *phy = &hw->phy; |
| 1339 | s32 ret_val; |
| 1340 | u16 data; |
| 1341 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1342 | ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1343 | |
| 1344 | if (!ret_val) |
| 1345 | phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY) |
| 1346 | ? e1000_rev_polarity_reversed |
| 1347 | : e1000_rev_polarity_normal; |
| 1348 | |
| 1349 | return ret_val; |
| 1350 | } |
| 1351 | |
| 1352 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1353 | * igb_check_polarity_igp - Checks the polarity. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1354 | * @hw: pointer to the HW structure |
| 1355 | * |
| 1356 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) |
| 1357 | * |
| 1358 | * Polarity is determined based on the PHY port status register, and the |
| 1359 | * current speed (since there is no polarity at 100Mbps). |
| 1360 | **/ |
| 1361 | static s32 igb_check_polarity_igp(struct e1000_hw *hw) |
| 1362 | { |
| 1363 | struct e1000_phy_info *phy = &hw->phy; |
| 1364 | s32 ret_val; |
| 1365 | u16 data, offset, mask; |
| 1366 | |
| 1367 | /* |
| 1368 | * Polarity is determined based on the speed of |
| 1369 | * our connection. |
| 1370 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1371 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1372 | if (ret_val) |
| 1373 | goto out; |
| 1374 | |
| 1375 | if ((data & IGP01E1000_PSSR_SPEED_MASK) == |
| 1376 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
| 1377 | offset = IGP01E1000_PHY_PCS_INIT_REG; |
| 1378 | mask = IGP01E1000_PHY_POLARITY_MASK; |
| 1379 | } else { |
| 1380 | /* |
| 1381 | * This really only applies to 10Mbps since |
| 1382 | * there is no polarity for 100Mbps (always 0). |
| 1383 | */ |
| 1384 | offset = IGP01E1000_PHY_PORT_STATUS; |
| 1385 | mask = IGP01E1000_PSSR_POLARITY_REVERSED; |
| 1386 | } |
| 1387 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1388 | ret_val = phy->ops.read_reg(hw, offset, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1389 | |
| 1390 | if (!ret_val) |
| 1391 | phy->cable_polarity = (data & mask) |
| 1392 | ? e1000_rev_polarity_reversed |
| 1393 | : e1000_rev_polarity_normal; |
| 1394 | |
| 1395 | out: |
| 1396 | return ret_val; |
| 1397 | } |
| 1398 | |
| 1399 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1400 | * igb_wait_autoneg - Wait for auto-neg compeletion |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1401 | * @hw: pointer to the HW structure |
| 1402 | * |
| 1403 | * Waits for auto-negotiation to complete or for the auto-negotiation time |
| 1404 | * limit to expire, which ever happens first. |
| 1405 | **/ |
| 1406 | static s32 igb_wait_autoneg(struct e1000_hw *hw) |
| 1407 | { |
| 1408 | s32 ret_val = 0; |
| 1409 | u16 i, phy_status; |
| 1410 | |
| 1411 | /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */ |
| 1412 | for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1413 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1414 | if (ret_val) |
| 1415 | break; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1416 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1417 | if (ret_val) |
| 1418 | break; |
| 1419 | if (phy_status & MII_SR_AUTONEG_COMPLETE) |
| 1420 | break; |
| 1421 | msleep(100); |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation |
| 1426 | * has completed. |
| 1427 | */ |
| 1428 | return ret_val; |
| 1429 | } |
| 1430 | |
| 1431 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1432 | * igb_phy_has_link - Polls PHY for link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1433 | * @hw: pointer to the HW structure |
| 1434 | * @iterations: number of times to poll for link |
| 1435 | * @usec_interval: delay between polling attempts |
| 1436 | * @success: pointer to whether polling was successful or not |
| 1437 | * |
| 1438 | * Polls the PHY status register for link, 'iterations' number of times. |
| 1439 | **/ |
| 1440 | s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations, |
| 1441 | u32 usec_interval, bool *success) |
| 1442 | { |
| 1443 | s32 ret_val = 0; |
| 1444 | u16 i, phy_status; |
| 1445 | |
| 1446 | for (i = 0; i < iterations; i++) { |
| 1447 | /* |
| 1448 | * Some PHYs require the PHY_STATUS register to be read |
| 1449 | * twice due to the link bit being sticky. No harm doing |
| 1450 | * it across the board. |
| 1451 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1452 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Alexander Duyck | ab57638 | 2009-10-05 06:35:23 +0000 | [diff] [blame] | 1453 | if (ret_val) { |
| 1454 | /* |
| 1455 | * If the first read fails, another entity may have |
| 1456 | * ownership of the resources, wait and try again to |
| 1457 | * see if they have relinquished the resources yet. |
| 1458 | */ |
| 1459 | udelay(usec_interval); |
| 1460 | } |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1461 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1462 | if (ret_val) |
| 1463 | break; |
| 1464 | if (phy_status & MII_SR_LINK_STATUS) |
| 1465 | break; |
| 1466 | if (usec_interval >= 1000) |
| 1467 | mdelay(usec_interval/1000); |
| 1468 | else |
| 1469 | udelay(usec_interval); |
| 1470 | } |
| 1471 | |
| 1472 | *success = (i < iterations) ? true : false; |
| 1473 | |
| 1474 | return ret_val; |
| 1475 | } |
| 1476 | |
| 1477 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1478 | * igb_get_cable_length_m88 - Determine cable length for m88 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1479 | * @hw: pointer to the HW structure |
| 1480 | * |
| 1481 | * Reads the PHY specific status register to retrieve the cable length |
| 1482 | * information. The cable length is determined by averaging the minimum and |
| 1483 | * maximum values to get the "average" cable length. The m88 PHY has four |
| 1484 | * possible cable length values, which are: |
| 1485 | * Register Value Cable Length |
| 1486 | * 0 < 50 meters |
| 1487 | * 1 50 - 80 meters |
| 1488 | * 2 80 - 110 meters |
| 1489 | * 3 110 - 140 meters |
| 1490 | * 4 > 140 meters |
| 1491 | **/ |
| 1492 | s32 igb_get_cable_length_m88(struct e1000_hw *hw) |
| 1493 | { |
| 1494 | struct e1000_phy_info *phy = &hw->phy; |
| 1495 | s32 ret_val; |
| 1496 | u16 phy_data, index; |
| 1497 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1498 | 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] | 1499 | if (ret_val) |
| 1500 | goto out; |
| 1501 | |
| 1502 | index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
| 1503 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1504 | if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) { |
| 1505 | ret_val = -E1000_ERR_PHY; |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1509 | phy->min_cable_length = e1000_m88_cable_length_table[index]; |
Alexander Duyck | 2553bb2 | 2009-10-05 06:35:42 +0000 | [diff] [blame] | 1510 | phy->max_cable_length = e1000_m88_cable_length_table[index + 1]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1511 | |
| 1512 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; |
| 1513 | |
| 1514 | out: |
| 1515 | return ret_val; |
| 1516 | } |
| 1517 | |
| 1518 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1519 | * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1520 | * @hw: pointer to the HW structure |
| 1521 | * |
| 1522 | * The automatic gain control (agc) normalizes the amplitude of the |
| 1523 | * received signal, adjusting for the attenuation produced by the |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1524 | * cable. By reading the AGC registers, which represent the |
| 1525 | * combination of coarse and fine gain value, the value can be put |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1526 | * into a lookup table to obtain the approximate cable length |
| 1527 | * for each channel. |
| 1528 | **/ |
| 1529 | s32 igb_get_cable_length_igp_2(struct e1000_hw *hw) |
| 1530 | { |
| 1531 | struct e1000_phy_info *phy = &hw->phy; |
| 1532 | s32 ret_val = 0; |
| 1533 | u16 phy_data, i, agc_value = 0; |
| 1534 | u16 cur_agc_index, max_agc_index = 0; |
| 1535 | u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1; |
| 1536 | u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] = |
| 1537 | {IGP02E1000_PHY_AGC_A, |
| 1538 | IGP02E1000_PHY_AGC_B, |
| 1539 | IGP02E1000_PHY_AGC_C, |
| 1540 | IGP02E1000_PHY_AGC_D}; |
| 1541 | |
| 1542 | /* Read the AGC registers for all channels */ |
| 1543 | for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1544 | 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] | 1545 | if (ret_val) |
| 1546 | goto out; |
| 1547 | |
| 1548 | /* |
| 1549 | * Getting bits 15:9, which represent the combination of |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1550 | * coarse and fine gain values. The result is a number |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1551 | * that can be put into the lookup table to obtain the |
| 1552 | * approximate cable length. |
| 1553 | */ |
| 1554 | cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) & |
| 1555 | IGP02E1000_AGC_LENGTH_MASK; |
| 1556 | |
| 1557 | /* Array index bound check. */ |
| 1558 | if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) || |
| 1559 | (cur_agc_index == 0)) { |
| 1560 | ret_val = -E1000_ERR_PHY; |
| 1561 | goto out; |
| 1562 | } |
| 1563 | |
| 1564 | /* Remove min & max AGC values from calculation. */ |
| 1565 | if (e1000_igp_2_cable_length_table[min_agc_index] > |
| 1566 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 1567 | min_agc_index = cur_agc_index; |
| 1568 | if (e1000_igp_2_cable_length_table[max_agc_index] < |
| 1569 | e1000_igp_2_cable_length_table[cur_agc_index]) |
| 1570 | max_agc_index = cur_agc_index; |
| 1571 | |
| 1572 | agc_value += e1000_igp_2_cable_length_table[cur_agc_index]; |
| 1573 | } |
| 1574 | |
| 1575 | agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] + |
| 1576 | e1000_igp_2_cable_length_table[max_agc_index]); |
| 1577 | agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2); |
| 1578 | |
| 1579 | /* Calculate cable length with the error range of +/- 10 meters. */ |
| 1580 | phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ? |
| 1581 | (agc_value - IGP02E1000_AGC_RANGE) : 0; |
| 1582 | phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE; |
| 1583 | |
| 1584 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; |
| 1585 | |
| 1586 | out: |
| 1587 | return ret_val; |
| 1588 | } |
| 1589 | |
| 1590 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1591 | * igb_get_phy_info_m88 - Retrieve PHY information |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1592 | * @hw: pointer to the HW structure |
| 1593 | * |
| 1594 | * Valid for only copper links. Read the PHY status register (sticky read) |
| 1595 | * to verify that link is up. Read the PHY special control register to |
| 1596 | * determine the polarity and 10base-T extended distance. Read the PHY |
| 1597 | * special status register to determine MDI/MDIx and current speed. If |
| 1598 | * speed is 1000, then determine cable length, local and remote receiver. |
| 1599 | **/ |
| 1600 | s32 igb_get_phy_info_m88(struct e1000_hw *hw) |
| 1601 | { |
| 1602 | struct e1000_phy_info *phy = &hw->phy; |
| 1603 | s32 ret_val; |
| 1604 | u16 phy_data; |
| 1605 | bool link; |
| 1606 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1607 | if (phy->media_type != e1000_media_type_copper) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1608 | hw_dbg("Phy info is only valid for copper media\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1609 | ret_val = -E1000_ERR_CONFIG; |
| 1610 | goto out; |
| 1611 | } |
| 1612 | |
| 1613 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 1614 | if (ret_val) |
| 1615 | goto out; |
| 1616 | |
| 1617 | if (!link) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1618 | hw_dbg("Phy info is only valid if link is up\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1619 | ret_val = -E1000_ERR_CONFIG; |
| 1620 | goto out; |
| 1621 | } |
| 1622 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1623 | 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] | 1624 | if (ret_val) |
| 1625 | goto out; |
| 1626 | |
| 1627 | phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1628 | ? true : false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1629 | |
| 1630 | ret_val = igb_check_polarity_m88(hw); |
| 1631 | if (ret_val) |
| 1632 | goto out; |
| 1633 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1634 | 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] | 1635 | if (ret_val) |
| 1636 | goto out; |
| 1637 | |
| 1638 | phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false; |
| 1639 | |
| 1640 | if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1641 | ret_val = phy->ops.get_cable_length(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1642 | if (ret_val) |
| 1643 | goto out; |
| 1644 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1645 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1646 | if (ret_val) |
| 1647 | goto out; |
| 1648 | |
| 1649 | phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) |
| 1650 | ? e1000_1000t_rx_status_ok |
| 1651 | : e1000_1000t_rx_status_not_ok; |
| 1652 | |
| 1653 | phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) |
| 1654 | ? e1000_1000t_rx_status_ok |
| 1655 | : e1000_1000t_rx_status_not_ok; |
| 1656 | } else { |
| 1657 | /* Set values to "undefined" */ |
| 1658 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; |
| 1659 | phy->local_rx = e1000_1000t_rx_status_undefined; |
| 1660 | phy->remote_rx = e1000_1000t_rx_status_undefined; |
| 1661 | } |
| 1662 | |
| 1663 | out: |
| 1664 | return ret_val; |
| 1665 | } |
| 1666 | |
| 1667 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1668 | * igb_get_phy_info_igp - Retrieve igp PHY information |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1669 | * @hw: pointer to the HW structure |
| 1670 | * |
| 1671 | * Read PHY status to determine if link is up. If link is up, then |
| 1672 | * set/determine 10base-T extended distance and polarity correction. Read |
| 1673 | * PHY port status to determine MDI/MDIx and speed. Based on the speed, |
| 1674 | * determine on the cable length, local and remote receiver. |
| 1675 | **/ |
| 1676 | s32 igb_get_phy_info_igp(struct e1000_hw *hw) |
| 1677 | { |
| 1678 | struct e1000_phy_info *phy = &hw->phy; |
| 1679 | s32 ret_val; |
| 1680 | u16 data; |
| 1681 | bool link; |
| 1682 | |
| 1683 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 1684 | if (ret_val) |
| 1685 | goto out; |
| 1686 | |
| 1687 | if (!link) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1688 | hw_dbg("Phy info is only valid if link is up\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1689 | ret_val = -E1000_ERR_CONFIG; |
| 1690 | goto out; |
| 1691 | } |
| 1692 | |
| 1693 | phy->polarity_correction = true; |
| 1694 | |
| 1695 | ret_val = igb_check_polarity_igp(hw); |
| 1696 | if (ret_val) |
| 1697 | goto out; |
| 1698 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1699 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1700 | if (ret_val) |
| 1701 | goto out; |
| 1702 | |
| 1703 | phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false; |
| 1704 | |
| 1705 | if ((data & IGP01E1000_PSSR_SPEED_MASK) == |
| 1706 | IGP01E1000_PSSR_SPEED_1000MBPS) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1707 | ret_val = phy->ops.get_cable_length(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1708 | if (ret_val) |
| 1709 | goto out; |
| 1710 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1711 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1712 | if (ret_val) |
| 1713 | goto out; |
| 1714 | |
| 1715 | phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS) |
| 1716 | ? e1000_1000t_rx_status_ok |
| 1717 | : e1000_1000t_rx_status_not_ok; |
| 1718 | |
| 1719 | phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS) |
| 1720 | ? e1000_1000t_rx_status_ok |
| 1721 | : e1000_1000t_rx_status_not_ok; |
| 1722 | } else { |
| 1723 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; |
| 1724 | phy->local_rx = e1000_1000t_rx_status_undefined; |
| 1725 | phy->remote_rx = e1000_1000t_rx_status_undefined; |
| 1726 | } |
| 1727 | |
| 1728 | out: |
| 1729 | return ret_val; |
| 1730 | } |
| 1731 | |
| 1732 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1733 | * igb_phy_sw_reset - PHY software reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1734 | * @hw: pointer to the HW structure |
| 1735 | * |
| 1736 | * Does a software reset of the PHY by reading the PHY control register and |
| 1737 | * setting/write the control register reset bit to the PHY. |
| 1738 | **/ |
| 1739 | s32 igb_phy_sw_reset(struct e1000_hw *hw) |
| 1740 | { |
Alexander Duyck | d314737 | 2009-09-14 08:23:13 +0000 | [diff] [blame] | 1741 | s32 ret_val = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1742 | u16 phy_ctrl; |
| 1743 | |
Alexander Duyck | d314737 | 2009-09-14 08:23:13 +0000 | [diff] [blame] | 1744 | if (!(hw->phy.ops.read_reg)) |
| 1745 | goto out; |
| 1746 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1747 | ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1748 | if (ret_val) |
| 1749 | goto out; |
| 1750 | |
| 1751 | phy_ctrl |= MII_CR_RESET; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1752 | ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1753 | if (ret_val) |
| 1754 | goto out; |
| 1755 | |
| 1756 | udelay(1); |
| 1757 | |
| 1758 | out: |
| 1759 | return ret_val; |
| 1760 | } |
| 1761 | |
| 1762 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1763 | * igb_phy_hw_reset - PHY hardware reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1764 | * @hw: pointer to the HW structure |
| 1765 | * |
| 1766 | * Verify the reset block is not blocking us from resetting. Acquire |
| 1767 | * semaphore (if necessary) and read/set/write the device control reset |
| 1768 | * bit in the PHY. Wait the appropriate delay time for the device to |
| 1769 | * reset and relase the semaphore (if necessary). |
| 1770 | **/ |
| 1771 | s32 igb_phy_hw_reset(struct e1000_hw *hw) |
| 1772 | { |
| 1773 | struct e1000_phy_info *phy = &hw->phy; |
| 1774 | s32 ret_val; |
| 1775 | u32 ctrl; |
| 1776 | |
| 1777 | ret_val = igb_check_reset_block(hw); |
| 1778 | if (ret_val) { |
| 1779 | ret_val = 0; |
| 1780 | goto out; |
| 1781 | } |
| 1782 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1783 | ret_val = phy->ops.acquire(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1784 | if (ret_val) |
| 1785 | goto out; |
| 1786 | |
| 1787 | ctrl = rd32(E1000_CTRL); |
| 1788 | wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST); |
| 1789 | wrfl(); |
| 1790 | |
| 1791 | udelay(phy->reset_delay_us); |
| 1792 | |
| 1793 | wr32(E1000_CTRL, ctrl); |
| 1794 | wrfl(); |
| 1795 | |
| 1796 | udelay(150); |
| 1797 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1798 | phy->ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1799 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1800 | ret_val = phy->ops.get_cfg_done(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1801 | |
| 1802 | out: |
| 1803 | return ret_val; |
| 1804 | } |
| 1805 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1806 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1807 | * igb_phy_init_script_igp3 - Inits the IGP3 PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1808 | * @hw: pointer to the HW structure |
| 1809 | * |
| 1810 | * Initializes a Intel Gigabit PHY3 when an EEPROM is not present. |
| 1811 | **/ |
| 1812 | s32 igb_phy_init_script_igp3(struct e1000_hw *hw) |
| 1813 | { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1814 | hw_dbg("Running IGP 3 PHY init script\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1815 | |
| 1816 | /* PHY init IGP 3 */ |
| 1817 | /* Enable rise/fall, 10-mode work in class-A */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1818 | hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1819 | /* Remove all caps from Replica path filter */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1820 | hw->phy.ops.write_reg(hw, 0x2F52, 0x0000); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1821 | /* Bias trimming for ADC, AFE and Driver (Default) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1822 | hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1823 | /* Increase Hybrid poly bias */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1824 | hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1825 | /* Add 4% to TX amplitude in Giga mode */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1826 | hw->phy.ops.write_reg(hw, 0x2010, 0x10B0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1827 | /* Disable trimming (TTT) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1828 | hw->phy.ops.write_reg(hw, 0x2011, 0x0000); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1829 | /* Poly DC correction to 94.6% + 2% for all channels */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1830 | hw->phy.ops.write_reg(hw, 0x20DD, 0x249A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1831 | /* ABS DC correction to 95.9% */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1832 | hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1833 | /* BG temp curve trim */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1834 | hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1835 | /* Increasing ADC OPAMP stage 1 currents to max */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1836 | hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1837 | /* Force 1000 ( required for enabling PHY regs configuration) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1838 | hw->phy.ops.write_reg(hw, 0x0000, 0x0140); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1839 | /* Set upd_freq to 6 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1840 | hw->phy.ops.write_reg(hw, 0x1F30, 0x1606); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1841 | /* Disable NPDFE */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1842 | hw->phy.ops.write_reg(hw, 0x1F31, 0xB814); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1843 | /* Disable adaptive fixed FFE (Default) */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1844 | hw->phy.ops.write_reg(hw, 0x1F35, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1845 | /* Enable FFE hysteresis */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1846 | hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1847 | /* Fixed FFE for short cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1848 | hw->phy.ops.write_reg(hw, 0x1F54, 0x0065); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1849 | /* Fixed FFE for medium cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1850 | hw->phy.ops.write_reg(hw, 0x1F55, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1851 | /* Fixed FFE for long cable lengths */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1852 | hw->phy.ops.write_reg(hw, 0x1F56, 0x002A); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1853 | /* Enable Adaptive Clip Threshold */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1854 | hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1855 | /* AHT reset limit to 1 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1856 | hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1857 | /* Set AHT master delay to 127 msec */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1858 | hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1859 | /* Set scan bits for AHT */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1860 | hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1861 | /* Set AHT Preset bits */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1862 | hw->phy.ops.write_reg(hw, 0x1F79, 0x0210); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1863 | /* Change integ_factor of channel A to 3 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1864 | hw->phy.ops.write_reg(hw, 0x1895, 0x0003); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1865 | /* Change prop_factor of channels BCD to 8 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1866 | hw->phy.ops.write_reg(hw, 0x1796, 0x0008); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1867 | /* Change cg_icount + enable integbp for channels BCD */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1868 | hw->phy.ops.write_reg(hw, 0x1798, 0xD008); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1869 | /* |
| 1870 | * Change cg_icount + enable integbp + change prop_factor_master |
| 1871 | * to 8 for channel A |
| 1872 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1873 | hw->phy.ops.write_reg(hw, 0x1898, 0xD918); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1874 | /* Disable AHT in Slave mode on channel A */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1875 | hw->phy.ops.write_reg(hw, 0x187A, 0x0800); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1876 | /* |
| 1877 | * Enable LPLU and disable AN to 1000 in non-D0a states, |
| 1878 | * Enable SPD+B2B |
| 1879 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1880 | hw->phy.ops.write_reg(hw, 0x0019, 0x008D); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1881 | /* Enable restart AN on an1000_dis change */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1882 | hw->phy.ops.write_reg(hw, 0x001B, 0x2080); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1883 | /* Enable wh_fifo read clock in 10/100 modes */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1884 | hw->phy.ops.write_reg(hw, 0x0014, 0x0045); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1885 | /* Restart AN, Speed selection is 1000 */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 1886 | hw->phy.ops.write_reg(hw, 0x0000, 0x1340); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1887 | |
| 1888 | return 0; |
| 1889 | } |
| 1890 | |