Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ixgbe: update PHY code to support 100Mbps as well as 1G/10G

This change updates the PHY setup code to support 100Mbps capable PHYs
as well as 10G and 1Gbps.

Signed-off-by: Emil Tantilov <emil.s.tantilov@intel.com>
Tested-by: Stephen Ko <stephen.s.ko@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

authored by

Emil Tantilov and committed by
Jeff Kirsher
9dda1736 7e7eb434

+245 -99
+1
drivers/net/ixgbe/ixgbe_82598.c
··· 158 158 159 159 switch (hw->phy.type) { 160 160 case ixgbe_phy_tn: 161 + phy->ops.setup_link = &ixgbe_setup_phy_link_tnx; 161 162 phy->ops.check_link = &ixgbe_check_phy_link_tnx; 162 163 phy->ops.get_firmware_version = 163 164 &ixgbe_get_phy_firmware_version_tnx;
+236 -99
drivers/net/ixgbe/ixgbe_phy.c
··· 402 402 **/ 403 403 s32 ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw) 404 404 { 405 - s32 status = IXGBE_NOT_IMPLEMENTED; 405 + s32 status = 0; 406 406 u32 time_out; 407 407 u32 max_time_out = 10; 408 - u16 autoneg_reg; 408 + u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; 409 + bool autoneg = false; 410 + ixgbe_link_speed speed; 409 411 410 - /* 411 - * Set advertisement settings in PHY based on autoneg_advertised 412 - * settings. If autoneg_advertised = 0, then advertise default values 413 - * tnx devices cannot be "forced" to a autoneg 10G and fail. But can 414 - * for a 1G. 415 - */ 416 - hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, &autoneg_reg); 412 + ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg); 417 413 418 - if (hw->phy.autoneg_advertised == IXGBE_LINK_SPEED_1GB_FULL) 414 + if (speed & IXGBE_LINK_SPEED_10GB_FULL) { 415 + /* Set or unset auto-negotiation 10G advertisement */ 416 + hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, 417 + MDIO_MMD_AN, 418 + &autoneg_reg); 419 + 419 420 autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G; 420 - else 421 - autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; 421 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) 422 + autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; 422 423 423 - hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, MDIO_MMD_AN, autoneg_reg); 424 + hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, 425 + MDIO_MMD_AN, 426 + autoneg_reg); 427 + } 428 + 429 + if (speed & IXGBE_LINK_SPEED_1GB_FULL) { 430 + /* Set or unset auto-negotiation 1G advertisement */ 431 + hw->phy.ops.read_reg(hw, 432 + IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG, 433 + MDIO_MMD_AN, 434 + &autoneg_reg); 435 + 436 + autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE; 437 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) 438 + autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE; 439 + 440 + hw->phy.ops.write_reg(hw, 441 + IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG, 442 + MDIO_MMD_AN, 443 + autoneg_reg); 444 + } 445 + 446 + if (speed & IXGBE_LINK_SPEED_100_FULL) { 447 + /* Set or unset auto-negotiation 100M advertisement */ 448 + hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, 449 + MDIO_MMD_AN, 450 + &autoneg_reg); 451 + 452 + autoneg_reg &= ~ADVERTISE_100FULL; 453 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) 454 + autoneg_reg |= ADVERTISE_100FULL; 455 + 456 + hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, 457 + MDIO_MMD_AN, 458 + autoneg_reg); 459 + } 424 460 425 461 /* Restart PHY autonegotiation and wait for completion */ 426 - hw->phy.ops.read_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, &autoneg_reg); 462 + hw->phy.ops.read_reg(hw, MDIO_CTRL1, 463 + MDIO_MMD_AN, &autoneg_reg); 427 464 428 465 autoneg_reg |= MDIO_AN_CTRL1_RESTART; 429 466 430 - hw->phy.ops.write_reg(hw, MDIO_CTRL1, MDIO_MMD_AN, autoneg_reg); 467 + hw->phy.ops.write_reg(hw, MDIO_CTRL1, 468 + MDIO_MMD_AN, autoneg_reg); 431 469 432 470 /* Wait for autonegotiation to finish */ 433 471 for (time_out = 0; time_out < max_time_out; time_out++) { 434 472 udelay(10); 435 473 /* Restart PHY autonegotiation and wait for completion */ 436 - status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN, 437 - &autoneg_reg); 474 + status = hw->phy.ops.read_reg(hw, MDIO_STAT1, 475 + MDIO_MMD_AN, 476 + &autoneg_reg); 438 477 439 478 autoneg_reg &= MDIO_AN_STAT1_COMPLETE; 440 479 if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) { 441 - status = 0; 442 480 break; 443 481 } 444 482 } 445 483 446 - if (time_out == max_time_out) 484 + if (time_out == max_time_out) { 447 485 status = IXGBE_ERR_LINK_SETUP; 486 + hw_dbg(hw, "ixgbe_setup_phy_link_generic: time out"); 487 + } 448 488 449 489 return status; 450 490 } ··· 512 472 513 473 if (speed & IXGBE_LINK_SPEED_1GB_FULL) 514 474 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL; 475 + 476 + if (speed & IXGBE_LINK_SPEED_100_FULL) 477 + hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL; 515 478 516 479 /* Setup link based on the new speed settings */ 517 480 hw->phy.ops.setup_link(hw); ··· 551 508 if (speed_ability & MDIO_PMA_SPEED_100) 552 509 *speed |= IXGBE_LINK_SPEED_100_FULL; 553 510 } 511 + 512 + return status; 513 + } 514 + 515 + /** 516 + * ixgbe_check_phy_link_tnx - Determine link and speed status 517 + * @hw: pointer to hardware structure 518 + * 519 + * Reads the VS1 register to determine if link is up and the current speed for 520 + * the PHY. 521 + **/ 522 + s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed, 523 + bool *link_up) 524 + { 525 + s32 status = 0; 526 + u32 time_out; 527 + u32 max_time_out = 10; 528 + u16 phy_link = 0; 529 + u16 phy_speed = 0; 530 + u16 phy_data = 0; 531 + 532 + /* Initialize speed and link to default case */ 533 + *link_up = false; 534 + *speed = IXGBE_LINK_SPEED_10GB_FULL; 535 + 536 + /* 537 + * Check current speed and link status of the PHY register. 538 + * This is a vendor specific register and may have to 539 + * be changed for other copper PHYs. 540 + */ 541 + for (time_out = 0; time_out < max_time_out; time_out++) { 542 + udelay(10); 543 + status = hw->phy.ops.read_reg(hw, 544 + MDIO_STAT1, 545 + MDIO_MMD_VEND1, 546 + &phy_data); 547 + phy_link = phy_data & 548 + IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS; 549 + phy_speed = phy_data & 550 + IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS; 551 + if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) { 552 + *link_up = true; 553 + if (phy_speed == 554 + IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS) 555 + *speed = IXGBE_LINK_SPEED_1GB_FULL; 556 + break; 557 + } 558 + } 559 + 560 + return status; 561 + } 562 + 563 + /** 564 + * ixgbe_setup_phy_link_tnx - Set and restart autoneg 565 + * @hw: pointer to hardware structure 566 + * 567 + * Restart autonegotiation and PHY and waits for completion. 568 + **/ 569 + s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw) 570 + { 571 + s32 status = 0; 572 + u32 time_out; 573 + u32 max_time_out = 10; 574 + u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; 575 + bool autoneg = false; 576 + ixgbe_link_speed speed; 577 + 578 + ixgbe_get_copper_link_capabilities_generic(hw, &speed, &autoneg); 579 + 580 + if (speed & IXGBE_LINK_SPEED_10GB_FULL) { 581 + /* Set or unset auto-negotiation 10G advertisement */ 582 + hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL, 583 + MDIO_MMD_AN, 584 + &autoneg_reg); 585 + 586 + autoneg_reg &= ~MDIO_AN_10GBT_CTRL_ADV10G; 587 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL) 588 + autoneg_reg |= MDIO_AN_10GBT_CTRL_ADV10G; 589 + 590 + hw->phy.ops.write_reg(hw, MDIO_AN_10GBT_CTRL, 591 + MDIO_MMD_AN, 592 + autoneg_reg); 593 + } 594 + 595 + if (speed & IXGBE_LINK_SPEED_1GB_FULL) { 596 + /* Set or unset auto-negotiation 1G advertisement */ 597 + hw->phy.ops.read_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG, 598 + MDIO_MMD_AN, 599 + &autoneg_reg); 600 + 601 + autoneg_reg &= ~IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX; 602 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL) 603 + autoneg_reg |= IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX; 604 + 605 + hw->phy.ops.write_reg(hw, IXGBE_MII_AUTONEG_XNP_TX_REG, 606 + MDIO_MMD_AN, 607 + autoneg_reg); 608 + } 609 + 610 + if (speed & IXGBE_LINK_SPEED_100_FULL) { 611 + /* Set or unset auto-negotiation 100M advertisement */ 612 + hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE, 613 + MDIO_MMD_AN, 614 + &autoneg_reg); 615 + 616 + autoneg_reg &= ~ADVERTISE_100FULL; 617 + if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_100_FULL) 618 + autoneg_reg |= ADVERTISE_100FULL; 619 + 620 + hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE, 621 + MDIO_MMD_AN, 622 + autoneg_reg); 623 + } 624 + 625 + /* Restart PHY autonegotiation and wait for completion */ 626 + hw->phy.ops.read_reg(hw, MDIO_CTRL1, 627 + MDIO_MMD_AN, &autoneg_reg); 628 + 629 + autoneg_reg |= MDIO_AN_CTRL1_RESTART; 630 + 631 + hw->phy.ops.write_reg(hw, MDIO_CTRL1, 632 + MDIO_MMD_AN, autoneg_reg); 633 + 634 + /* Wait for autonegotiation to finish */ 635 + for (time_out = 0; time_out < max_time_out; time_out++) { 636 + udelay(10); 637 + /* Restart PHY autonegotiation and wait for completion */ 638 + status = hw->phy.ops.read_reg(hw, MDIO_STAT1, 639 + MDIO_MMD_AN, 640 + &autoneg_reg); 641 + 642 + autoneg_reg &= MDIO_AN_STAT1_COMPLETE; 643 + if (autoneg_reg == MDIO_AN_STAT1_COMPLETE) 644 + break; 645 + } 646 + 647 + if (time_out == max_time_out) { 648 + status = IXGBE_ERR_LINK_SETUP; 649 + hw_dbg(hw, "ixgbe_setup_phy_link_tnx: time out"); 650 + } 651 + 652 + return status; 653 + } 654 + 655 + /** 656 + * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version 657 + * @hw: pointer to hardware structure 658 + * @firmware_version: pointer to the PHY Firmware Version 659 + **/ 660 + s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, 661 + u16 *firmware_version) 662 + { 663 + s32 status = 0; 664 + 665 + status = hw->phy.ops.read_reg(hw, TNX_FW_REV, 666 + MDIO_MMD_VEND1, 667 + firmware_version); 668 + 669 + return status; 670 + } 671 + 672 + /** 673 + * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version 674 + * @hw: pointer to hardware structure 675 + * @firmware_version: pointer to the PHY Firmware Version 676 + **/ 677 + s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw, 678 + u16 *firmware_version) 679 + { 680 + s32 status = 0; 681 + 682 + status = hw->phy.ops.read_reg(hw, AQ_FW_REV, 683 + MDIO_MMD_VEND1, 684 + firmware_version); 554 685 555 686 return status; 556 687 } ··· 1691 1474 1692 1475 /* Put the i2c bus back to default state */ 1693 1476 ixgbe_i2c_stop(hw); 1694 - } 1695 - 1696 - /** 1697 - * ixgbe_check_phy_link_tnx - Determine link and speed status 1698 - * @hw: pointer to hardware structure 1699 - * 1700 - * Reads the VS1 register to determine if link is up and the current speed for 1701 - * the PHY. 1702 - **/ 1703 - s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed, 1704 - bool *link_up) 1705 - { 1706 - s32 status = 0; 1707 - u32 time_out; 1708 - u32 max_time_out = 10; 1709 - u16 phy_link = 0; 1710 - u16 phy_speed = 0; 1711 - u16 phy_data = 0; 1712 - 1713 - /* Initialize speed and link to default case */ 1714 - *link_up = false; 1715 - *speed = IXGBE_LINK_SPEED_10GB_FULL; 1716 - 1717 - /* 1718 - * Check current speed and link status of the PHY register. 1719 - * This is a vendor specific register and may have to 1720 - * be changed for other copper PHYs. 1721 - */ 1722 - for (time_out = 0; time_out < max_time_out; time_out++) { 1723 - udelay(10); 1724 - status = hw->phy.ops.read_reg(hw, 1725 - IXGBE_MDIO_VENDOR_SPECIFIC_1_STATUS, 1726 - MDIO_MMD_VEND1, 1727 - &phy_data); 1728 - phy_link = phy_data & 1729 - IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS; 1730 - phy_speed = phy_data & 1731 - IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS; 1732 - if (phy_link == IXGBE_MDIO_VENDOR_SPECIFIC_1_LINK_STATUS) { 1733 - *link_up = true; 1734 - if (phy_speed == 1735 - IXGBE_MDIO_VENDOR_SPECIFIC_1_SPEED_STATUS) 1736 - *speed = IXGBE_LINK_SPEED_1GB_FULL; 1737 - break; 1738 - } 1739 - } 1740 - 1741 - return status; 1742 - } 1743 - 1744 - /** 1745 - * ixgbe_get_phy_firmware_version_tnx - Gets the PHY Firmware Version 1746 - * @hw: pointer to hardware structure 1747 - * @firmware_version: pointer to the PHY Firmware Version 1748 - **/ 1749 - s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, 1750 - u16 *firmware_version) 1751 - { 1752 - s32 status = 0; 1753 - 1754 - status = hw->phy.ops.read_reg(hw, TNX_FW_REV, MDIO_MMD_VEND1, 1755 - firmware_version); 1756 - 1757 - return status; 1758 - } 1759 - 1760 - /** 1761 - * ixgbe_get_phy_firmware_version_generic - Gets the PHY Firmware Version 1762 - * @hw: pointer to hardware structure 1763 - * @firmware_version: pointer to the PHY Firmware Version 1764 - **/ 1765 - s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw, 1766 - u16 *firmware_version) 1767 - { 1768 - s32 status = 0; 1769 - 1770 - status = hw->phy.ops.read_reg(hw, AQ_FW_REV, MDIO_MMD_VEND1, 1771 - firmware_version); 1772 - 1773 - return status; 1774 1477 } 1775 1478 1776 1479 /**
+1
drivers/net/ixgbe/ixgbe_phy.h
··· 108 108 s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, 109 109 ixgbe_link_speed *speed, 110 110 bool *link_up); 111 + s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw); 111 112 s32 ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, 112 113 u16 *firmware_version); 113 114 s32 ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw,
+7
drivers/net/ixgbe/ixgbe_type.h
··· 1009 1009 #define IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA 0xC30B /* PHY_XS SDA/SCL Data Reg */ 1010 1010 #define IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT 0xC30C /* PHY_XS SDA/SCL Status Reg */ 1011 1011 1012 + /* MII clause 22/28 definitions */ 1013 + #define IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG 0xC400 /* 1G Provisioning 1 */ 1014 + #define IXGBE_MII_AUTONEG_XNP_TX_REG 0x17 /* 1G XNP Transmit */ 1015 + #define IXGBE_MII_1GBASE_T_ADVERTISE_XNP_TX 0x4000 /* full duplex, bit:14*/ 1016 + #define IXGBE_MII_1GBASE_T_ADVERTISE 0x8000 /* full duplex, bit:15*/ 1017 + #define IXGBE_MII_AUTONEG_REG 0x0 1018 + 1012 1019 #define IXGBE_PHY_REVISION_MASK 0xFFFFFFF0 1013 1020 #define IXGBE_MAX_PHY_ADDR 32 1014 1021