706-net-phy-populate-host_interfaces-when-attaching-PHY.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 4e432e530db0056450fbc4a3cee793f16adc39a7 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Tue, 8 Oct 2024 23:58:41 +0100
  4. Subject: [PATCH] net: phy: populate host_interfaces when attaching PHY
  5. Use bitmask of interfaces supported by the MAC for the PHY to choose
  6. from if the declared interface mode is among those using a single pair
  7. of SerDes lanes.
  8. This will allow 2500Base-T PHYs to switch to SGMII on most hosts, which
  9. results in half-duplex being supported in case the MAC supports them.
  10. Without this change, 2500Base-T PHYs will always operate in 2500Base-X
  11. mode with rate-matching, which is not only wasteful in terms of energy
  12. consumption, but also limits the supported interface modes to
  13. full-duplex only.
  14. Signed-off-by: Daniel Golle <[email protected]>
  15. ---
  16. drivers/net/phy/phylink.c | 21 ++++++++++++++++++++-
  17. 1 file changed, 20 insertions(+), 1 deletion(-)
  18. --- a/drivers/net/phy/phylink.c
  19. +++ b/drivers/net/phy/phylink.c
  20. @@ -2017,7 +2017,7 @@ int phylink_fwnode_phy_connect(struct ph
  21. {
  22. struct fwnode_handle *phy_fwnode;
  23. struct phy_device *phy_dev;
  24. - int ret;
  25. + int i, ret;
  26. /* Fixed links and 802.3z are handled without needing a PHY */
  27. if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
  28. @@ -2044,6 +2044,25 @@ int phylink_fwnode_phy_connect(struct ph
  29. pl->link_config.interface = pl->link_interface;
  30. }
  31. + /* Assume single-lane SerDes interface modes share the same
  32. + * lanes and allow the PHY to switch to slower also supported modes
  33. + */
  34. + for (i = ARRAY_SIZE(phylink_sfp_interface_preference) - 1; i >= 0; i--) {
  35. + /* skip unsupported modes */
  36. + if (!test_bit(phylink_sfp_interface_preference[i], pl->config->supported_interfaces))
  37. + continue;
  38. +
  39. + __set_bit(phylink_sfp_interface_preference[i], phy_dev->host_interfaces);
  40. +
  41. + /* skip all faster modes */
  42. + if (phylink_sfp_interface_preference[i] == pl->link_interface)
  43. + break;
  44. + }
  45. +
  46. + if (test_bit(pl->link_interface, phylink_sfp_interfaces))
  47. + phy_interface_and(phy_dev->host_interfaces, phylink_sfp_interfaces,
  48. + pl->config->supported_interfaces);
  49. +
  50. ret = phy_attach_direct(pl->netdev, phy_dev, flags,
  51. pl->link_interface);
  52. phy_device_free(phy_dev);