123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- From bf4de031052fe7c5309e8956c342d4e5ce79038e Mon Sep 17 00:00:00 2001
- From: "Russell King (Oracle)" <[email protected]>
- Date: Mon, 17 Oct 2022 16:22:35 -0400
- Subject: [PATCH 04/21] net: phylink: provide phylink_validate_mask_caps()
- helper
- Provide a helper that restricts the link modes according to the
- phylink capabilities.
- Signed-off-by: Russell King (Oracle) <[email protected]>
- [rebased on net-next/master and added documentation]
- Signed-off-by: Sean Anderson <[email protected]>
- Signed-off-by: David S. Miller <[email protected]>
- ---
- drivers/net/phy/phylink.c | 41 +++++++++++++++++++++++++++------------
- include/linux/phylink.h | 3 +++
- 2 files changed, 32 insertions(+), 12 deletions(-)
- --- a/drivers/net/phy/phylink.c
- +++ b/drivers/net/phy/phylink.c
- @@ -564,31 +564,48 @@ unsigned long phylink_get_capabilities(p
- EXPORT_SYMBOL_GPL(phylink_get_capabilities);
-
- /**
- - * phylink_generic_validate() - generic validate() callback implementation
- - * @config: a pointer to a &struct phylink_config.
- + * phylink_validate_mask_caps() - Restrict link modes based on caps
- * @supported: ethtool bitmask for supported link modes.
- - * @state: a pointer to a &struct phylink_link_state.
- + * @state: an (optional) pointer to a &struct phylink_link_state.
- + * @mac_capabilities: bitmask of MAC capabilities
- *
- - * Generic implementation of the validate() callback that MAC drivers can
- - * use when they pass the range of supported interfaces and MAC capabilities.
- - * This makes use of phylink_get_linkmodes().
- + * Calculate the supported link modes based on @mac_capabilities, and restrict
- + * @supported and @state based on that. Use this function if your capabiliies
- + * aren't constant, such as if they vary depending on the interface.
- */
- -void phylink_generic_validate(struct phylink_config *config,
- - unsigned long *supported,
- - struct phylink_link_state *state)
- +void phylink_validate_mask_caps(unsigned long *supported,
- + struct phylink_link_state *state,
- + unsigned long mac_capabilities)
- {
- __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
- unsigned long caps;
-
- phylink_set_port_modes(mask);
- phylink_set(mask, Autoneg);
- - caps = phylink_get_capabilities(state->interface,
- - config->mac_capabilities,
- + caps = phylink_get_capabilities(state->interface, mac_capabilities,
- state->rate_matching);
- phylink_caps_to_linkmodes(mask, caps);
-
- linkmode_and(supported, supported, mask);
- - linkmode_and(state->advertising, state->advertising, mask);
- + if (state)
- + linkmode_and(state->advertising, state->advertising, mask);
- +}
- +EXPORT_SYMBOL_GPL(phylink_validate_mask_caps);
- +
- +/**
- + * phylink_generic_validate() - generic validate() callback implementation
- + * @config: a pointer to a &struct phylink_config.
- + * @supported: ethtool bitmask for supported link modes.
- + * @state: a pointer to a &struct phylink_link_state.
- + *
- + * Generic implementation of the validate() callback that MAC drivers can
- + * use when they pass the range of supported interfaces and MAC capabilities.
- + */
- +void phylink_generic_validate(struct phylink_config *config,
- + unsigned long *supported,
- + struct phylink_link_state *state)
- +{
- + phylink_validate_mask_caps(supported, state, config->mac_capabilities);
- }
- EXPORT_SYMBOL_GPL(phylink_generic_validate);
-
- --- a/include/linux/phylink.h
- +++ b/include/linux/phylink.h
- @@ -558,6 +558,9 @@ void phylink_caps_to_linkmodes(unsigned
- unsigned long phylink_get_capabilities(phy_interface_t interface,
- unsigned long mac_capabilities,
- int rate_matching);
- +void phylink_validate_mask_caps(unsigned long *supported,
- + struct phylink_link_state *state,
- + unsigned long caps);
- void phylink_generic_validate(struct phylink_config *config,
- unsigned long *supported,
- struct phylink_link_state *state);
|