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