@@ -562,31 +562,48 @@ unsigned long phylink_get_capabilities(phy_interface_t interface,
562562EXPORT_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}
591608EXPORT_SYMBOL_GPL (phylink_generic_validate );
592609
0 commit comments