Skip to content

Commit f392a18

Browse files
Russell King (Oracle)davem330
authored andcommitted
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]>
1 parent 045d050 commit f392a18

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

drivers/net/phy/phylink.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,48 @@ unsigned long phylink_get_capabilities(phy_interface_t interface,
562562
EXPORT_SYMBOL_GPL(phylink_get_capabilities);
563563

564564
/**
565-
* phylink_generic_validate() - generic validate() callback implementation
566-
* @config: a pointer to a &struct phylink_config.
565+
* phylink_validate_mask_caps() - Restrict link modes based on caps
567566
* @supported: ethtool bitmask for supported link modes.
568-
* @state: a pointer to a &struct phylink_link_state.
567+
* @state: an (optional) pointer to a &struct phylink_link_state.
568+
* @mac_capabilities: bitmask of MAC capabilities
569569
*
570-
* Generic implementation of the validate() callback that MAC drivers can
571-
* use when they pass the range of supported interfaces and MAC capabilities.
572-
* This makes use of phylink_get_linkmodes().
570+
* Calculate the supported link modes based on @mac_capabilities, and restrict
571+
* @supported and @state based on that. Use this function if your capabiliies
572+
* aren't constant, such as if they vary depending on the interface.
573573
*/
574-
void phylink_generic_validate(struct phylink_config *config,
575-
unsigned long *supported,
576-
struct phylink_link_state *state)
574+
void phylink_validate_mask_caps(unsigned long *supported,
575+
struct phylink_link_state *state,
576+
unsigned long mac_capabilities)
577577
{
578578
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
579579
unsigned long caps;
580580

581581
phylink_set_port_modes(mask);
582582
phylink_set(mask, Autoneg);
583-
caps = phylink_get_capabilities(state->interface,
584-
config->mac_capabilities,
583+
caps = phylink_get_capabilities(state->interface, mac_capabilities,
585584
state->rate_matching);
586585
phylink_caps_to_linkmodes(mask, caps);
587586

588587
linkmode_and(supported, supported, mask);
589-
linkmode_and(state->advertising, state->advertising, mask);
588+
if (state)
589+
linkmode_and(state->advertising, state->advertising, mask);
590+
}
591+
EXPORT_SYMBOL_GPL(phylink_validate_mask_caps);
592+
593+
/**
594+
* phylink_generic_validate() - generic validate() callback implementation
595+
* @config: a pointer to a &struct phylink_config.
596+
* @supported: ethtool bitmask for supported link modes.
597+
* @state: a pointer to a &struct phylink_link_state.
598+
*
599+
* Generic implementation of the validate() callback that MAC drivers can
600+
* use when they pass the range of supported interfaces and MAC capabilities.
601+
*/
602+
void phylink_generic_validate(struct phylink_config *config,
603+
unsigned long *supported,
604+
struct phylink_link_state *state)
605+
{
606+
phylink_validate_mask_caps(supported, state, config->mac_capabilities);
590607
}
591608
EXPORT_SYMBOL_GPL(phylink_generic_validate);
592609

include/linux/phylink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
556556
unsigned long phylink_get_capabilities(phy_interface_t interface,
557557
unsigned long mac_capabilities,
558558
int rate_matching);
559+
void phylink_validate_mask_caps(unsigned long *supported,
560+
struct phylink_link_state *state,
561+
unsigned long caps);
559562
void phylink_generic_validate(struct phylink_config *config,
560563
unsigned long *supported,
561564
struct phylink_link_state *state);

0 commit comments

Comments
 (0)