703-02-v5.16-net-phylink-use-supported_interfaces-for-phylink-val.patch 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From d25f3a74f30aace819163dfa54f2a4b8ca1dc932 Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Tue, 26 Oct 2021 11:06:11 +0100
  4. Subject: [PATCH] net: phylink: use supported_interfaces for phylink
  5. validation
  6. If the network device supplies a supported interface bitmap, we can use
  7. that during phylink's validation to simplify MAC drivers in two ways by
  8. using the supported_interfaces bitmap to:
  9. 1. reject unsupported interfaces before calling into the MAC driver.
  10. 2. generate the set of all supported link modes across all supported
  11. interfaces (used mainly for SFP, but also some 10G PHYs.)
  12. Suggested-by: Sean Anderson <[email protected]>
  13. Signed-off-by: Russell King (Oracle) <[email protected]>
  14. Signed-off-by: David S. Miller <[email protected]>
  15. ---
  16. drivers/net/phy/phylink.c | 36 ++++++++++++++++++++++++++++++++++++
  17. include/linux/phylink.h | 12 ++++++++++--
  18. 2 files changed, 46 insertions(+), 2 deletions(-)
  19. --- a/drivers/net/phy/phylink.c
  20. +++ b/drivers/net/phy/phylink.c
  21. @@ -155,9 +155,45 @@ static const char *phylink_an_mode_str(u
  22. return mode < ARRAY_SIZE(modestr) ? modestr[mode] : "unknown";
  23. }
  24. +static int phylink_validate_any(struct phylink *pl, unsigned long *supported,
  25. + struct phylink_link_state *state)
  26. +{
  27. + __ETHTOOL_DECLARE_LINK_MODE_MASK(all_adv) = { 0, };
  28. + __ETHTOOL_DECLARE_LINK_MODE_MASK(all_s) = { 0, };
  29. + __ETHTOOL_DECLARE_LINK_MODE_MASK(s);
  30. + struct phylink_link_state t;
  31. + int intf;
  32. +
  33. + for (intf = 0; intf < PHY_INTERFACE_MODE_MAX; intf++) {
  34. + if (test_bit(intf, pl->config->supported_interfaces)) {
  35. + linkmode_copy(s, supported);
  36. +
  37. + t = *state;
  38. + t.interface = intf;
  39. + pl->mac_ops->validate(pl->config, s, &t);
  40. + linkmode_or(all_s, all_s, s);
  41. + linkmode_or(all_adv, all_adv, t.advertising);
  42. + }
  43. + }
  44. +
  45. + linkmode_copy(supported, all_s);
  46. + linkmode_copy(state->advertising, all_adv);
  47. +
  48. + return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
  49. +}
  50. +
  51. static int phylink_validate(struct phylink *pl, unsigned long *supported,
  52. struct phylink_link_state *state)
  53. {
  54. + if (!phy_interface_empty(pl->config->supported_interfaces)) {
  55. + if (state->interface == PHY_INTERFACE_MODE_NA)
  56. + return phylink_validate_any(pl, supported, state);
  57. +
  58. + if (!test_bit(state->interface,
  59. + pl->config->supported_interfaces))
  60. + return -EINVAL;
  61. + }
  62. +
  63. pl->mac_ops->validate(pl->config, supported, state);
  64. return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
  65. --- a/include/linux/phylink.h
  66. +++ b/include/linux/phylink.h
  67. @@ -67,6 +67,8 @@ enum phylink_op_type {
  68. * @ovr_an_inband: if true, override PCS to MLO_AN_INBAND
  69. * @get_fixed_state: callback to execute to determine the fixed link state,
  70. * if MAC link is at %MLO_AN_FIXED mode.
  71. + * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx
  72. + * are supported by the MAC/PCS.
  73. */
  74. struct phylink_config {
  75. struct device *dev;
  76. @@ -134,8 +136,14 @@ struct phylink_mac_ops {
  77. * based on @state->advertising and/or @state->speed and update
  78. * @state->interface accordingly. See phylink_helper_basex_speed().
  79. *
  80. - * When @state->interface is %PHY_INTERFACE_MODE_NA, phylink expects the
  81. - * MAC driver to return all supported link modes.
  82. + * When @config->supported_interfaces has been set, phylink will iterate
  83. + * over the supported interfaces to determine the full capability of the
  84. + * MAC. The validation function must not print errors if @state->interface
  85. + * is set to an unexpected value.
  86. + *
  87. + * When @config->supported_interfaces is empty, phylink will call this
  88. + * function with @state->interface set to %PHY_INTERFACE_MODE_NA, and
  89. + * expects the MAC driver to return all supported link modes.
  90. *
  91. * If the @state->interface mode is not supported, then the @supported
  92. * mask must be cleared.