diff options
Diffstat (limited to 'drivers/net/igb/e1000_phy.c')
-rw-r--r-- | drivers/net/igb/e1000_phy.c | 479 |
1 files changed, 460 insertions, 19 deletions
diff --git a/drivers/net/igb/e1000_phy.c b/drivers/net/igb/e1000_phy.c index ee460600e74b..cf1f32300923 100644 --- a/drivers/net/igb/e1000_phy.c +++ b/drivers/net/igb/e1000_phy.c | |||
@@ -39,6 +39,9 @@ static s32 igb_wait_autoneg(struct e1000_hw *hw); | |||
39 | /* Cable length tables */ | 39 | /* Cable length tables */ |
40 | static const u16 e1000_m88_cable_length_table[] = | 40 | static const u16 e1000_m88_cable_length_table[] = |
41 | { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED }; | 41 | { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED }; |
42 | #define M88E1000_CABLE_LENGTH_TABLE_SIZE \ | ||
43 | (sizeof(e1000_m88_cable_length_table) / \ | ||
44 | sizeof(e1000_m88_cable_length_table[0])) | ||
42 | 45 | ||
43 | static const u16 e1000_igp_2_cable_length_table[] = | 46 | 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, | 47 | { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21, |
@@ -109,7 +112,10 @@ out: | |||
109 | **/ | 112 | **/ |
110 | static s32 igb_phy_reset_dsp(struct e1000_hw *hw) | 113 | static s32 igb_phy_reset_dsp(struct e1000_hw *hw) |
111 | { | 114 | { |
112 | s32 ret_val; | 115 | s32 ret_val = 0; |
116 | |||
117 | if (!(hw->phy.ops.write_reg)) | ||
118 | goto out; | ||
113 | 119 | ||
114 | ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1); | 120 | ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1); |
115 | if (ret_val) | 121 | if (ret_val) |
@@ -130,7 +136,7 @@ out: | |||
130 | * Reads the MDI control regsiter in the PHY at offset and stores the | 136 | * Reads the MDI control regsiter in the PHY at offset and stores the |
131 | * information read to data. | 137 | * information read to data. |
132 | **/ | 138 | **/ |
133 | static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data) | 139 | s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data) |
134 | { | 140 | { |
135 | struct e1000_phy_info *phy = &hw->phy; | 141 | struct e1000_phy_info *phy = &hw->phy; |
136 | u32 i, mdic = 0; | 142 | u32 i, mdic = 0; |
@@ -188,7 +194,7 @@ out: | |||
188 | * | 194 | * |
189 | * Writes data to MDI control register in the PHY at offset. | 195 | * Writes data to MDI control register in the PHY at offset. |
190 | **/ | 196 | **/ |
191 | static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data) | 197 | s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data) |
192 | { | 198 | { |
193 | struct e1000_phy_info *phy = &hw->phy; | 199 | struct e1000_phy_info *phy = &hw->phy; |
194 | u32 i, mdic = 0; | 200 | u32 i, mdic = 0; |
@@ -239,6 +245,103 @@ out: | |||
239 | } | 245 | } |
240 | 246 | ||
241 | /** | 247 | /** |
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 | /** | ||
242 | * igb_read_phy_reg_igp - Read igp PHY register | 345 | * igb_read_phy_reg_igp - Read igp PHY register |
243 | * @hw: pointer to the HW structure | 346 | * @hw: pointer to the HW structure |
244 | * @offset: register offset to be read | 347 | * @offset: register offset to be read |
@@ -318,6 +421,48 @@ out: | |||
318 | } | 421 | } |
319 | 422 | ||
320 | /** | 423 | /** |
424 | * igb_copper_link_setup_82580 - Setup 82580 PHY for copper link | ||
425 | * @hw: pointer to the HW structure | ||
426 | * | ||
427 | * Sets up Carrier-sense on Transmit and downshift values. | ||
428 | **/ | ||
429 | s32 igb_copper_link_setup_82580(struct e1000_hw *hw) | ||
430 | { | ||
431 | struct e1000_phy_info *phy = &hw->phy; | ||
432 | s32 ret_val; | ||
433 | u16 phy_data; | ||
434 | |||
435 | |||
436 | if (phy->reset_disable) { | ||
437 | ret_val = 0; | ||
438 | goto out; | ||
439 | } | ||
440 | |||
441 | if (phy->type == e1000_phy_82580) { | ||
442 | ret_val = hw->phy.ops.reset(hw); | ||
443 | if (ret_val) { | ||
444 | hw_dbg("Error resetting the PHY.\n"); | ||
445 | goto out; | ||
446 | } | ||
447 | } | ||
448 | |||
449 | /* Enable CRS on TX. This must be set for half-duplex operation. */ | ||
450 | ret_val = phy->ops.read_reg(hw, I82580_CFG_REG, &phy_data); | ||
451 | if (ret_val) | ||
452 | goto out; | ||
453 | |||
454 | phy_data |= I82580_CFG_ASSERT_CRS_ON_TX; | ||
455 | |||
456 | /* Enable downshift */ | ||
457 | phy_data |= I82580_CFG_ENABLE_DOWNSHIFT; | ||
458 | |||
459 | ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data); | ||
460 | |||
461 | out: | ||
462 | return ret_val; | ||
463 | } | ||
464 | |||
465 | /** | ||
321 | * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link | 466 | * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link |
322 | * @hw: pointer to the HW structure | 467 | * @hw: pointer to the HW structure |
323 | * | 468 | * |
@@ -572,7 +717,7 @@ out: | |||
572 | * and restart the negotiation process between the link partner. If | 717 | * and restart the negotiation process between the link partner. If |
573 | * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. | 718 | * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. |
574 | **/ | 719 | **/ |
575 | s32 igb_copper_link_autoneg(struct e1000_hw *hw) | 720 | static s32 igb_copper_link_autoneg(struct e1000_hw *hw) |
576 | { | 721 | { |
577 | struct e1000_phy_info *phy = &hw->phy; | 722 | struct e1000_phy_info *phy = &hw->phy; |
578 | s32 ret_val; | 723 | s32 ret_val; |
@@ -796,6 +941,65 @@ out: | |||
796 | } | 941 | } |
797 | 942 | ||
798 | /** | 943 | /** |
944 | * igb_setup_copper_link - Configure copper link settings | ||
945 | * @hw: pointer to the HW structure | ||
946 | * | ||
947 | * Calls the appropriate function to configure the link for auto-neg or forced | ||
948 | * speed and duplex. Then we check for link, once link is established calls | ||
949 | * to configure collision distance and flow control are called. If link is | ||
950 | * not established, we return -E1000_ERR_PHY (-2). | ||
951 | **/ | ||
952 | s32 igb_setup_copper_link(struct e1000_hw *hw) | ||
953 | { | ||
954 | s32 ret_val; | ||
955 | bool link; | ||
956 | |||
957 | |||
958 | if (hw->mac.autoneg) { | ||
959 | /* | ||
960 | * Setup autoneg and flow control advertisement and perform | ||
961 | * autonegotiation. | ||
962 | */ | ||
963 | ret_val = igb_copper_link_autoneg(hw); | ||
964 | if (ret_val) | ||
965 | goto out; | ||
966 | } else { | ||
967 | /* | ||
968 | * PHY will be set to 10H, 10F, 100H or 100F | ||
969 | * depending on user settings. | ||
970 | */ | ||
971 | hw_dbg("Forcing Speed and Duplex\n"); | ||
972 | ret_val = hw->phy.ops.force_speed_duplex(hw); | ||
973 | if (ret_val) { | ||
974 | hw_dbg("Error Forcing Speed and Duplex\n"); | ||
975 | goto out; | ||
976 | } | ||
977 | } | ||
978 | |||
979 | /* | ||
980 | * Check link status. Wait up to 100 microseconds for link to become | ||
981 | * valid. | ||
982 | */ | ||
983 | ret_val = igb_phy_has_link(hw, | ||
984 | COPPER_LINK_UP_LIMIT, | ||
985 | 10, | ||
986 | &link); | ||
987 | if (ret_val) | ||
988 | goto out; | ||
989 | |||
990 | if (link) { | ||
991 | hw_dbg("Valid link established!!!\n"); | ||
992 | igb_config_collision_dist(hw); | ||
993 | ret_val = igb_config_fc_after_link_up(hw); | ||
994 | } else { | ||
995 | hw_dbg("Unable to establish link!!!\n"); | ||
996 | } | ||
997 | |||
998 | out: | ||
999 | return ret_val; | ||
1000 | } | ||
1001 | |||
1002 | /** | ||
799 | * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY | 1003 | * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY |
800 | * @hw: pointer to the HW structure | 1004 | * @hw: pointer to the HW structure |
801 | * | 1005 | * |
@@ -903,22 +1107,19 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw) | |||
903 | 1107 | ||
904 | igb_phy_force_speed_duplex_setup(hw, &phy_data); | 1108 | igb_phy_force_speed_duplex_setup(hw, &phy_data); |
905 | 1109 | ||
906 | /* Reset the phy to commit changes. */ | ||
907 | phy_data |= MII_CR_RESET; | ||
908 | |||
909 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); | 1110 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); |
910 | if (ret_val) | 1111 | if (ret_val) |
911 | goto out; | 1112 | goto out; |
912 | 1113 | ||
913 | udelay(1); | 1114 | /* Reset the phy to commit changes. */ |
1115 | ret_val = igb_phy_sw_reset(hw); | ||
1116 | if (ret_val) | ||
1117 | goto out; | ||
914 | 1118 | ||
915 | if (phy->autoneg_wait_to_complete) { | 1119 | if (phy->autoneg_wait_to_complete) { |
916 | hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n"); | 1120 | hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n"); |
917 | 1121 | ||
918 | ret_val = igb_phy_has_link(hw, | 1122 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link); |
919 | PHY_FORCE_LIMIT, | ||
920 | 100000, | ||
921 | &link); | ||
922 | if (ret_val) | 1123 | if (ret_val) |
923 | goto out; | 1124 | goto out; |
924 | 1125 | ||
@@ -928,8 +1129,8 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw) | |||
928 | * Reset the DSP and cross our fingers. | 1129 | * Reset the DSP and cross our fingers. |
929 | */ | 1130 | */ |
930 | ret_val = phy->ops.write_reg(hw, | 1131 | ret_val = phy->ops.write_reg(hw, |
931 | M88E1000_PHY_PAGE_SELECT, | 1132 | M88E1000_PHY_PAGE_SELECT, |
932 | 0x001d); | 1133 | 0x001d); |
933 | if (ret_val) | 1134 | if (ret_val) |
934 | goto out; | 1135 | goto out; |
935 | ret_val = igb_phy_reset_dsp(hw); | 1136 | ret_val = igb_phy_reset_dsp(hw); |
@@ -939,7 +1140,7 @@ s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw) | |||
939 | 1140 | ||
940 | /* Try once more */ | 1141 | /* Try once more */ |
941 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, | 1142 | ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, |
942 | 100000, &link); | 1143 | 100000, &link); |
943 | if (ret_val) | 1144 | if (ret_val) |
944 | goto out; | 1145 | goto out; |
945 | } | 1146 | } |
@@ -1051,9 +1252,12 @@ static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, | |||
1051 | s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active) | 1252 | s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active) |
1052 | { | 1253 | { |
1053 | struct e1000_phy_info *phy = &hw->phy; | 1254 | struct e1000_phy_info *phy = &hw->phy; |
1054 | s32 ret_val; | 1255 | s32 ret_val = 0; |
1055 | u16 data; | 1256 | u16 data; |
1056 | 1257 | ||
1258 | if (!(hw->phy.ops.read_reg)) | ||
1259 | goto out; | ||
1260 | |||
1057 | ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data); | 1261 | ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data); |
1058 | if (ret_val) | 1262 | if (ret_val) |
1059 | goto out; | 1263 | goto out; |
@@ -1288,8 +1492,14 @@ s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations, | |||
1288 | * it across the board. | 1492 | * it across the board. |
1289 | */ | 1493 | */ |
1290 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); | 1494 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
1291 | if (ret_val) | 1495 | if (ret_val) { |
1292 | break; | 1496 | /* |
1497 | * If the first read fails, another entity may have | ||
1498 | * ownership of the resources, wait and try again to | ||
1499 | * see if they have relinquished the resources yet. | ||
1500 | */ | ||
1501 | udelay(usec_interval); | ||
1502 | } | ||
1293 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); | 1503 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
1294 | if (ret_val) | 1504 | if (ret_val) |
1295 | break; | 1505 | break; |
@@ -1333,8 +1543,13 @@ s32 igb_get_cable_length_m88(struct e1000_hw *hw) | |||
1333 | 1543 | ||
1334 | index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> | 1544 | index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >> |
1335 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; | 1545 | M88E1000_PSSR_CABLE_LENGTH_SHIFT; |
1546 | if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) { | ||
1547 | ret_val = -E1000_ERR_PHY; | ||
1548 | goto out; | ||
1549 | } | ||
1550 | |||
1336 | phy->min_cable_length = e1000_m88_cable_length_table[index]; | 1551 | phy->min_cable_length = e1000_m88_cable_length_table[index]; |
1337 | phy->max_cable_length = e1000_m88_cable_length_table[index+1]; | 1552 | phy->max_cable_length = e1000_m88_cable_length_table[index + 1]; |
1338 | 1553 | ||
1339 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; | 1554 | phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2; |
1340 | 1555 | ||
@@ -1715,3 +1930,229 @@ s32 igb_phy_init_script_igp3(struct e1000_hw *hw) | |||
1715 | return 0; | 1930 | return 0; |
1716 | } | 1931 | } |
1717 | 1932 | ||
1933 | /** | ||
1934 | * igb_power_up_phy_copper - Restore copper link in case of PHY power down | ||
1935 | * @hw: pointer to the HW structure | ||
1936 | * | ||
1937 | * In the case of a PHY power down to save power, or to turn off link during a | ||
1938 | * driver unload, restore the link to previous settings. | ||
1939 | **/ | ||
1940 | void igb_power_up_phy_copper(struct e1000_hw *hw) | ||
1941 | { | ||
1942 | u16 mii_reg = 0; | ||
1943 | |||
1944 | /* The PHY will retain its settings across a power down/up cycle */ | ||
1945 | hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg); | ||
1946 | mii_reg &= ~MII_CR_POWER_DOWN; | ||
1947 | hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg); | ||
1948 | } | ||
1949 | |||
1950 | /** | ||
1951 | * igb_power_down_phy_copper - Power down copper PHY | ||
1952 | * @hw: pointer to the HW structure | ||
1953 | * | ||
1954 | * Power down PHY to save power when interface is down and wake on lan | ||
1955 | * is not enabled. | ||
1956 | **/ | ||
1957 | void igb_power_down_phy_copper(struct e1000_hw *hw) | ||
1958 | { | ||
1959 | u16 mii_reg = 0; | ||
1960 | |||
1961 | /* The PHY will retain its settings across a power down/up cycle */ | ||
1962 | hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg); | ||
1963 | mii_reg |= MII_CR_POWER_DOWN; | ||
1964 | hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg); | ||
1965 | msleep(1); | ||
1966 | } | ||
1967 | |||
1968 | /** | ||
1969 | * igb_check_polarity_82580 - Checks the polarity. | ||
1970 | * @hw: pointer to the HW structure | ||
1971 | * | ||
1972 | * Success returns 0, Failure returns -E1000_ERR_PHY (-2) | ||
1973 | * | ||
1974 | * Polarity is determined based on the PHY specific status register. | ||
1975 | **/ | ||
1976 | static s32 igb_check_polarity_82580(struct e1000_hw *hw) | ||
1977 | { | ||
1978 | struct e1000_phy_info *phy = &hw->phy; | ||
1979 | s32 ret_val; | ||
1980 | u16 data; | ||
1981 | |||
1982 | |||
1983 | ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data); | ||
1984 | |||
1985 | if (!ret_val) | ||
1986 | phy->cable_polarity = (data & I82580_PHY_STATUS2_REV_POLARITY) | ||
1987 | ? e1000_rev_polarity_reversed | ||
1988 | : e1000_rev_polarity_normal; | ||
1989 | |||
1990 | return ret_val; | ||
1991 | } | ||
1992 | |||
1993 | /** | ||
1994 | * igb_phy_force_speed_duplex_82580 - Force speed/duplex for I82580 PHY | ||
1995 | * @hw: pointer to the HW structure | ||
1996 | * | ||
1997 | * Calls the PHY setup function to force speed and duplex. Clears the | ||
1998 | * auto-crossover to force MDI manually. Waits for link and returns | ||
1999 | * successful if link up is successful, else -E1000_ERR_PHY (-2). | ||
2000 | **/ | ||
2001 | s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw) | ||
2002 | { | ||
2003 | struct e1000_phy_info *phy = &hw->phy; | ||
2004 | s32 ret_val; | ||
2005 | u16 phy_data; | ||
2006 | bool link; | ||
2007 | |||
2008 | |||
2009 | ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data); | ||
2010 | if (ret_val) | ||
2011 | goto out; | ||
2012 | |||
2013 | igb_phy_force_speed_duplex_setup(hw, &phy_data); | ||
2014 | |||
2015 | ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data); | ||
2016 | if (ret_val) | ||
2017 | goto out; | ||
2018 | |||
2019 | /* | ||
2020 | * Clear Auto-Crossover to force MDI manually. 82580 requires MDI | ||
2021 | * forced whenever speed and duplex are forced. | ||
2022 | */ | ||
2023 | ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data); | ||
2024 | if (ret_val) | ||
2025 | goto out; | ||
2026 | |||
2027 | phy_data &= ~I82580_PHY_CTRL2_AUTO_MDIX; | ||
2028 | phy_data &= ~I82580_PHY_CTRL2_FORCE_MDI_MDIX; | ||
2029 | |||
2030 | ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data); | ||
2031 | if (ret_val) | ||
2032 | goto out; | ||
2033 | |||
2034 | hw_dbg("I82580_PHY_CTRL_2: %X\n", phy_data); | ||
2035 | |||
2036 | udelay(1); | ||
2037 | |||
2038 | if (phy->autoneg_wait_to_complete) { | ||
2039 | hw_dbg("Waiting for forced speed/duplex link on 82580 phy\n"); | ||
2040 | |||
2041 | ret_val = igb_phy_has_link(hw, | ||
2042 | PHY_FORCE_LIMIT, | ||
2043 | 100000, | ||
2044 | &link); | ||
2045 | if (ret_val) | ||
2046 | goto out; | ||
2047 | |||
2048 | if (!link) | ||
2049 | hw_dbg("Link taking longer than expected.\n"); | ||
2050 | |||
2051 | /* Try once more */ | ||
2052 | ret_val = igb_phy_has_link(hw, | ||
2053 | PHY_FORCE_LIMIT, | ||
2054 | 100000, | ||
2055 | &link); | ||
2056 | if (ret_val) | ||
2057 | goto out; | ||
2058 | } | ||
2059 | |||
2060 | out: | ||
2061 | return ret_val; | ||
2062 | } | ||
2063 | |||
2064 | /** | ||
2065 | * igb_get_phy_info_82580 - Retrieve I82580 PHY information | ||
2066 | * @hw: pointer to the HW structure | ||
2067 | * | ||
2068 | * Read PHY status to determine if link is up. If link is up, then | ||
2069 | * set/determine 10base-T extended distance and polarity correction. Read | ||
2070 | * PHY port status to determine MDI/MDIx and speed. Based on the speed, | ||
2071 | * determine on the cable length, local and remote receiver. | ||
2072 | **/ | ||
2073 | s32 igb_get_phy_info_82580(struct e1000_hw *hw) | ||
2074 | { | ||
2075 | struct e1000_phy_info *phy = &hw->phy; | ||
2076 | s32 ret_val; | ||
2077 | u16 data; | ||
2078 | bool link; | ||
2079 | |||
2080 | |||
2081 | ret_val = igb_phy_has_link(hw, 1, 0, &link); | ||
2082 | if (ret_val) | ||
2083 | goto out; | ||
2084 | |||
2085 | if (!link) { | ||
2086 | hw_dbg("Phy info is only valid if link is up\n"); | ||
2087 | ret_val = -E1000_ERR_CONFIG; | ||
2088 | goto out; | ||
2089 | } | ||
2090 | |||
2091 | phy->polarity_correction = true; | ||
2092 | |||
2093 | ret_val = igb_check_polarity_82580(hw); | ||
2094 | if (ret_val) | ||
2095 | goto out; | ||
2096 | |||
2097 | ret_val = phy->ops.read_reg(hw, I82580_PHY_STATUS_2, &data); | ||
2098 | if (ret_val) | ||
2099 | goto out; | ||
2100 | |||
2101 | phy->is_mdix = (data & I82580_PHY_STATUS2_MDIX) ? true : false; | ||
2102 | |||
2103 | if ((data & I82580_PHY_STATUS2_SPEED_MASK) == | ||
2104 | I82580_PHY_STATUS2_SPEED_1000MBPS) { | ||
2105 | ret_val = hw->phy.ops.get_cable_length(hw); | ||
2106 | if (ret_val) | ||
2107 | goto out; | ||
2108 | |||
2109 | ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data); | ||
2110 | if (ret_val) | ||
2111 | goto out; | ||
2112 | |||
2113 | phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS) | ||
2114 | ? e1000_1000t_rx_status_ok | ||
2115 | : e1000_1000t_rx_status_not_ok; | ||
2116 | |||
2117 | phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS) | ||
2118 | ? e1000_1000t_rx_status_ok | ||
2119 | : e1000_1000t_rx_status_not_ok; | ||
2120 | } else { | ||
2121 | phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED; | ||
2122 | phy->local_rx = e1000_1000t_rx_status_undefined; | ||
2123 | phy->remote_rx = e1000_1000t_rx_status_undefined; | ||
2124 | } | ||
2125 | |||
2126 | out: | ||
2127 | return ret_val; | ||
2128 | } | ||
2129 | |||
2130 | /** | ||
2131 | * igb_get_cable_length_82580 - Determine cable length for 82580 PHY | ||
2132 | * @hw: pointer to the HW structure | ||
2133 | * | ||
2134 | * Reads the diagnostic status register and verifies result is valid before | ||
2135 | * placing it in the phy_cable_length field. | ||
2136 | **/ | ||
2137 | s32 igb_get_cable_length_82580(struct e1000_hw *hw) | ||
2138 | { | ||
2139 | struct e1000_phy_info *phy = &hw->phy; | ||
2140 | s32 ret_val; | ||
2141 | u16 phy_data, length; | ||
2142 | |||
2143 | |||
2144 | ret_val = phy->ops.read_reg(hw, I82580_PHY_DIAG_STATUS, &phy_data); | ||
2145 | if (ret_val) | ||
2146 | goto out; | ||
2147 | |||
2148 | length = (phy_data & I82580_DSTATUS_CABLE_LENGTH) >> | ||
2149 | I82580_DSTATUS_CABLE_LENGTH_SHIFT; | ||
2150 | |||
2151 | if (length == E1000_CABLE_LENGTH_UNDEFINED) | ||
2152 | ret_val = -E1000_ERR_PHY; | ||
2153 | |||
2154 | phy->cable_length = length; | ||
2155 | |||
2156 | out: | ||
2157 | return ret_val; | ||
2158 | } | ||