aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ixgbe/ixgbe_phy.c
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2009-04-29 04:08:58 -0400
committerDavid S. Miller <davem@davemloft.net>2009-04-29 20:32:33 -0400
commit6b73e10d2d89f9ce773f9b47d61b195936d059ba (patch)
tree108a5d6ad55cb795d6afb0e0846c6782f42f5c90 /drivers/net/ixgbe/ixgbe_phy.c
parent0f07c4ee8c800923ae7918c231532a9256233eed (diff)
ixgbe: Use generic MDIO definitions and functions
Compile-tested only. Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ixgbe/ixgbe_phy.c')
-rw-r--r--drivers/net/ixgbe/ixgbe_phy.c95
1 files changed, 32 insertions, 63 deletions
diff --git a/drivers/net/ixgbe/ixgbe_phy.c b/drivers/net/ixgbe/ixgbe_phy.c
index 2543c32ca84..6d385ea3c2a 100644
--- a/drivers/net/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ixgbe/ixgbe_phy.c
@@ -44,7 +44,6 @@ static void ixgbe_lower_i2c_clk(struct ixgbe_hw *hw, u32 *i2cctl);
44static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data); 44static s32 ixgbe_set_i2c_data(struct ixgbe_hw *hw, u32 *i2cctl, bool data);
45static bool ixgbe_get_i2c_data(u32 *i2cctl); 45static bool ixgbe_get_i2c_data(u32 *i2cctl);
46static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw); 46static void ixgbe_i2c_bus_clear(struct ixgbe_hw *hw);
47static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr);
48static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id); 47static enum ixgbe_phy_type ixgbe_get_phy_type_from_id(u32 phy_id);
49static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw); 48static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw);
50 49
@@ -61,8 +60,7 @@ s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
61 60
62 if (hw->phy.type == ixgbe_phy_unknown) { 61 if (hw->phy.type == ixgbe_phy_unknown) {
63 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) { 62 for (phy_addr = 0; phy_addr < IXGBE_MAX_PHY_ADDR; phy_addr++) {
64 if (ixgbe_validate_phy_addr(hw, phy_addr)) { 63 if (mdio45_probe(&hw->phy.mdio, phy_addr) == 0) {
65 hw->phy.addr = phy_addr;
66 ixgbe_get_phy_id(hw); 64 ixgbe_get_phy_id(hw);
67 hw->phy.type = 65 hw->phy.type =
68 ixgbe_get_phy_type_from_id(hw->phy.id); 66 ixgbe_get_phy_type_from_id(hw->phy.id);
@@ -78,26 +76,6 @@ s32 ixgbe_identify_phy_generic(struct ixgbe_hw *hw)
78} 76}
79 77
80/** 78/**
81 * ixgbe_validate_phy_addr - Determines phy address is valid
82 * @hw: pointer to hardware structure
83 *
84 **/
85static bool ixgbe_validate_phy_addr(struct ixgbe_hw *hw, u32 phy_addr)
86{
87 u16 phy_id = 0;
88 bool valid = false;
89
90 hw->phy.addr = phy_addr;
91 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH,
92 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &phy_id);
93
94 if (phy_id != 0xFFFF && phy_id != 0x0)
95 valid = true;
96
97 return valid;
98}
99
100/**
101 * ixgbe_get_phy_id - Get the phy type 79 * ixgbe_get_phy_id - Get the phy type
102 * @hw: pointer to hardware structure 80 * @hw: pointer to hardware structure
103 * 81 *
@@ -108,14 +86,12 @@ static s32 ixgbe_get_phy_id(struct ixgbe_hw *hw)
108 u16 phy_id_high = 0; 86 u16 phy_id_high = 0;
109 u16 phy_id_low = 0; 87 u16 phy_id_low = 0;
110 88
111 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_HIGH, 89 status = hw->phy.ops.read_reg(hw, MDIO_DEVID1, MDIO_MMD_PMAPMD,
112 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
113 &phy_id_high); 90 &phy_id_high);
114 91
115 if (status == 0) { 92 if (status == 0) {
116 hw->phy.id = (u32)(phy_id_high << 16); 93 hw->phy.id = (u32)(phy_id_high << 16);
117 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_ID_LOW, 94 status = hw->phy.ops.read_reg(hw, MDIO_DEVID2, MDIO_MMD_PMAPMD,
118 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
119 &phy_id_low); 95 &phy_id_low);
120 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK); 96 hw->phy.id |= (u32)(phy_id_low & IXGBE_PHY_REVISION_MASK);
121 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK); 97 hw->phy.revision = (u32)(phy_id_low & ~IXGBE_PHY_REVISION_MASK);
@@ -160,9 +136,8 @@ s32 ixgbe_reset_phy_generic(struct ixgbe_hw *hw)
160 * Perform soft PHY reset to the PHY_XS. 136 * Perform soft PHY reset to the PHY_XS.
161 * This will cause a soft reset to the PHY 137 * This will cause a soft reset to the PHY
162 */ 138 */
163 return hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL, 139 return hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
164 IXGBE_MDIO_PHY_XS_DEV_TYPE, 140 MDIO_CTRL1_RESET);
165 IXGBE_MDIO_PHY_XS_RESET);
166} 141}
167 142
168/** 143/**
@@ -192,7 +167,7 @@ s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
192 /* Setup and write the address cycle command */ 167 /* Setup and write the address cycle command */
193 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | 168 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
194 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | 169 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
195 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) | 170 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
196 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); 171 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
197 172
198 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); 173 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
@@ -223,7 +198,8 @@ s32 ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
223 */ 198 */
224 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | 199 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
225 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | 200 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
226 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) | 201 (hw->phy.mdio.prtad <<
202 IXGBE_MSCA_PHY_ADDR_SHIFT) |
227 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND)); 203 (IXGBE_MSCA_READ | IXGBE_MSCA_MDI_COMMAND));
228 204
229 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); 205 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
@@ -292,7 +268,7 @@ s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
292 /* Setup and write the address cycle command */ 268 /* Setup and write the address cycle command */
293 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | 269 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
294 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | 270 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
295 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) | 271 (hw->phy.mdio.prtad << IXGBE_MSCA_PHY_ADDR_SHIFT) |
296 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND)); 272 (IXGBE_MSCA_ADDR_CYCLE | IXGBE_MSCA_MDI_COMMAND));
297 273
298 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); 274 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
@@ -323,7 +299,8 @@ s32 ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, u32 reg_addr,
323 */ 299 */
324 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) | 300 command = ((reg_addr << IXGBE_MSCA_NP_ADDR_SHIFT) |
325 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) | 301 (device_type << IXGBE_MSCA_DEV_TYPE_SHIFT) |
326 (hw->phy.addr << IXGBE_MSCA_PHY_ADDR_SHIFT) | 302 (hw->phy.mdio.prtad <<
303 IXGBE_MSCA_PHY_ADDR_SHIFT) |
327 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND)); 304 (IXGBE_MSCA_WRITE | IXGBE_MSCA_MDI_COMMAND));
328 305
329 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command); 306 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
@@ -365,7 +342,7 @@ s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
365 s32 status = IXGBE_NOT_IMPLEMENTED; 342 s32 status = IXGBE_NOT_IMPLEMENTED;
366 u32 time_out; 343 u32 time_out;
367 u32 max_time_out = 10; 344 u32 max_time_out = 10;
368 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; 345 u16 autoneg_reg;
369 346
370 /* 347 /*
371 * Set advertisement settings in PHY based on autoneg_advertised 348 * Set advertisement settings in PHY based on autoneg_advertised
@@ -373,36 +350,31 @@ s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw)
373 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can 350 * tnx devices cannot be "forced" to a autoneg 10G and fail. But can
374 * for a 1G. 351 * for a 1G.
375 */ 352 */
376 hw->phy.ops.read_reg(hw, IXGBE_MII_SPEED_SELECTION_REG, 353 hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg);
377 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
378 354
379 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL) 355 if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL)
380 autoneg_reg &= 0xEFFF; /* 0 in bit 12 is 1G operation */ 356 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G;
381 else 357 else
382 autoneg_reg |= 0x1000; /* 1 in bit 12 is 10G/1G operation */ 358 autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G;
383 359
384 hw->phy.ops.write_reg(hw, IXGBE_MII_SPEED_SELECTION_REG, 360 hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg);
385 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
386 361
387 /* Restart PHY autonegotiation and wait for completion */ 362 /* Restart PHY autonegotiation and wait for completion */
388 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL, 363 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg);
389 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_reg);
390 364
391 autoneg_reg |= IXGBE_MII_RESTART; 365 autoneg_reg |= MDIO_AN_CTRL1_RESTART;
392 366
393 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_CONTROL, 367 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg);
394 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_reg);
395 368
396 /* Wait for autonegotiation to finish */ 369 /* Wait for autonegotiation to finish */
397 for (time_out = 0; time_out < max_time_out; time_out++) { 370 for (time_out = 0; time_out < max_time_out; time_out++) {
398 udelay(10); 371 udelay(10);
399 /* Restart PHY autonegotiation and wait for completion */ 372 /* Restart PHY autonegotiation and wait for completion */
400 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS, 373 status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
401 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
402 &autoneg_reg); 374 &autoneg_reg);
403 375
404 autoneg_reg &= IXGBE_MII_AUTONEG_COMPLETE; 376 autoneg_reg &= MDIO_AN_STAT1_COMPLETE;
405 if (autoneg_reg == IXGBE_MII_AUTONEG_COMPLETE) { 377 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) {
406 status = 0; 378 status = 0;
407 break; 379 break;
408 } 380 }
@@ -457,23 +429,21 @@ s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
457 s32 ret_val = 0; 429 s32 ret_val = 0;
458 u32 i; 430 u32 i;
459 431
460 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL, 432 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS, &phy_data);
461 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data);
462 433
463 /* reset the PHY and poll for completion */ 434 /* reset the PHY and poll for completion */
464 hw->phy.ops.write_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL, 435 hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
465 IXGBE_MDIO_PHY_XS_DEV_TYPE, 436 (phy_data | MDIO_CTRL1_RESET));
466 (phy_data | IXGBE_MDIO_PHY_XS_RESET));
467 437
468 for (i = 0; i < 100; i++) { 438 for (i = 0; i < 100; i++) {
469 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_XS_CONTROL, 439 hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_PHYXS,
470 IXGBE_MDIO_PHY_XS_DEV_TYPE, &phy_data); 440 &phy_data);
471 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) == 0) 441 if ((phy_data & MDIO_CTRL1_RESET) == 0)
472 break; 442 break;
473 msleep(10); 443 msleep(10);
474 } 444 }
475 445
476 if ((phy_data & IXGBE_MDIO_PHY_XS_RESET) != 0) { 446 if ((phy_data & MDIO_CTRL1_RESET) != 0) {
477 hw_dbg(hw, "PHY reset did not complete.\n"); 447 hw_dbg(hw, "PHY reset did not complete.\n");
478 ret_val = IXGBE_ERR_PHY; 448 ret_val = IXGBE_ERR_PHY;
479 goto out; 449 goto out;
@@ -509,7 +479,7 @@ s32 ixgbe_reset_phy_nl(struct ixgbe_hw *hw)
509 for (i = 0; i < edata; i++) { 479 for (i = 0; i < edata; i++) {
510 hw->eeprom.ops.read(hw, data_offset, &eword); 480 hw->eeprom.ops.read(hw, data_offset, &eword);
511 hw->phy.ops.write_reg(hw, phy_offset, 481 hw->phy.ops.write_reg(hw, phy_offset,
512 IXGBE_TWINAX_DEV, eword); 482 MDIO_MMD_PMAPMD, eword);
513 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword, 483 hw_dbg(hw, "Wrote %4.4x to %4.4x\n", eword,
514 phy_offset); 484 phy_offset);
515 data_offset++; 485 data_offset++;
@@ -1302,7 +1272,7 @@ s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
1302 udelay(10); 1272 udelay(10);
1303 status = hw->phy.ops.read_reg(hw, 1273 status = hw->phy.ops.read_reg(hw,
1304 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS, 1274 IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS,
1305 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, 1275 MDIO_MMD_VEND1,
1306 &phy_data); 1276 &phy_data);
1307 phy_link = phy_data & 1277 phy_link = phy_data &
1308 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS; 1278 IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS;
@@ -1330,8 +1300,7 @@ s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw,
1330{ 1300{
1331 s32 status = 0; 1301 s32 status = 0;
1332 1302
1333 status = hw->phy.ops.read_reg(hw, TNX_FW_REV, 1303 status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1,
1334 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1335 firmware_version); 1304 firmware_version);
1336 1305
1337 return status; 1306 return status;