Commit 87b22ce3 authored by Maxime Chevallier's avatar Maxime Chevallier Committed by Paolo Abeni
Browse files

net: phy: phy_caps: Introduce phy_caps_valid



With the link_capabilities array, it's trivial to validate a given mask
againts a <speed, duplex> tuple. Create a helper for that purpose, and
use it to replace a phy_settings lookup in phy_check_valid();

Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20250307173611.129125-6-maxime.chevallier@bootlin.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 4823ed06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ int phy_caps_init(void);
size_t phy_caps_speeds(unsigned int *speeds, size_t size,
		       unsigned long *linkmodes);
void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes);
bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes);


#endif /* __PHY_CAPS_H */
+1 −1
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ unsigned int phy_supported_speeds(struct phy_device *phy,
 */
bool phy_check_valid(int speed, int duplex, unsigned long *features)
{
	return !!phy_lookup_setting(speed, duplex, features, true);
	return phy_caps_valid(speed, duplex, features);
}
EXPORT_SYMBOL(phy_check_valid);

+19 −0
Original line number Diff line number Diff line
@@ -140,3 +140,22 @@ void phy_caps_linkmode_max_speed(u32 max_speed, unsigned long *linkmodes)
		else
			break;
}

/**
 * phy_caps_valid() - Validate a linkmodes set agains given speed and duplex
 * @speed: input speed to validate
 * @duplex: input duplex to validate. Passing DUPLEX_UNKNOWN is always not valid
 * @linkmodes: The linkmodes to validate
 *
 * Returns: True if at least one of the linkmodes in @linkmodes can function at
 *          the given speed and duplex, false otherwise.
 */
bool phy_caps_valid(int speed, int duplex, const unsigned long *linkmodes)
{
	int capa = speed_duplex_to_capa(speed, duplex);

	if (capa < 0)
		return false;

	return linkmode_intersects(link_caps[capa].linkmodes, linkmodes);
}