715-04-v6.2-net-phylink-provide-phylink_validate_mask_caps-helpe.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From bf4de031052fe7c5309e8956c342d4e5ce79038e Mon Sep 17 00:00:00 2001
  2. From: "Russell King (Oracle)" <[email protected]>
  3. Date: Mon, 17 Oct 2022 16:22:35 -0400
  4. Subject: [PATCH 04/21] net: phylink: provide phylink_validate_mask_caps()
  5. helper
  6. Provide a helper that restricts the link modes according to the
  7. phylink capabilities.
  8. Signed-off-by: Russell King (Oracle) <[email protected]>
  9. [rebased on net-next/master and added documentation]
  10. Signed-off-by: Sean Anderson <[email protected]>
  11. Signed-off-by: David S. Miller <[email protected]>
  12. ---
  13. drivers/net/phy/phylink.c | 41 +++++++++++++++++++++++++++------------
  14. include/linux/phylink.h | 3 +++
  15. 2 files changed, 32 insertions(+), 12 deletions(-)
  16. --- a/drivers/net/phy/phylink.c
  17. +++ b/drivers/net/phy/phylink.c
  18. @@ -564,31 +564,48 @@ unsigned long phylink_get_capabilities(p
  19. EXPORT_SYMBOL_GPL(phylink_get_capabilities);
  20. /**
  21. - * phylink_generic_validate() - generic validate() callback implementation
  22. - * @config: a pointer to a &struct phylink_config.
  23. + * phylink_validate_mask_caps() - Restrict link modes based on caps
  24. * @supported: ethtool bitmask for supported link modes.
  25. - * @state: a pointer to a &struct phylink_link_state.
  26. + * @state: an (optional) pointer to a &struct phylink_link_state.
  27. + * @mac_capabilities: bitmask of MAC capabilities
  28. *
  29. - * Generic implementation of the validate() callback that MAC drivers can
  30. - * use when they pass the range of supported interfaces and MAC capabilities.
  31. - * This makes use of phylink_get_linkmodes().
  32. + * Calculate the supported link modes based on @mac_capabilities, and restrict
  33. + * @supported and @state based on that. Use this function if your capabiliies
  34. + * aren't constant, such as if they vary depending on the interface.
  35. */
  36. -void phylink_generic_validate(struct phylink_config *config,
  37. - unsigned long *supported,
  38. - struct phylink_link_state *state)
  39. +void phylink_validate_mask_caps(unsigned long *supported,
  40. + struct phylink_link_state *state,
  41. + unsigned long mac_capabilities)
  42. {
  43. __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
  44. unsigned long caps;
  45. phylink_set_port_modes(mask);
  46. phylink_set(mask, Autoneg);
  47. - caps = phylink_get_capabilities(state->interface,
  48. - config->mac_capabilities,
  49. + caps = phylink_get_capabilities(state->interface, mac_capabilities,
  50. state->rate_matching);
  51. phylink_caps_to_linkmodes(mask, caps);
  52. linkmode_and(supported, supported, mask);
  53. - linkmode_and(state->advertising, state->advertising, mask);
  54. + if (state)
  55. + linkmode_and(state->advertising, state->advertising, mask);
  56. +}
  57. +EXPORT_SYMBOL_GPL(phylink_validate_mask_caps);
  58. +
  59. +/**
  60. + * phylink_generic_validate() - generic validate() callback implementation
  61. + * @config: a pointer to a &struct phylink_config.
  62. + * @supported: ethtool bitmask for supported link modes.
  63. + * @state: a pointer to a &struct phylink_link_state.
  64. + *
  65. + * Generic implementation of the validate() callback that MAC drivers can
  66. + * use when they pass the range of supported interfaces and MAC capabilities.
  67. + */
  68. +void phylink_generic_validate(struct phylink_config *config,
  69. + unsigned long *supported,
  70. + struct phylink_link_state *state)
  71. +{
  72. + phylink_validate_mask_caps(supported, state, config->mac_capabilities);
  73. }
  74. EXPORT_SYMBOL_GPL(phylink_generic_validate);
  75. --- a/include/linux/phylink.h
  76. +++ b/include/linux/phylink.h
  77. @@ -558,6 +558,9 @@ void phylink_caps_to_linkmodes(unsigned
  78. unsigned long phylink_get_capabilities(phy_interface_t interface,
  79. unsigned long mac_capabilities,
  80. int rate_matching);
  81. +void phylink_validate_mask_caps(unsigned long *supported,
  82. + struct phylink_link_state *state,
  83. + unsigned long caps);
  84. void phylink_generic_validate(struct phylink_config *config,
  85. unsigned long *supported,
  86. struct phylink_link_state *state);