diff options
| author | Maxime Chevallier <maxime.chevallier@bootlin.com> | 2025-03-07 18:36:00 +0100 |
|---|---|---|
| committer | Paolo Abeni <pabeni@redhat.com> | 2025-03-18 09:03:11 +0100 |
| commit | 8c8c4a87933dd924f9fb56dfd35bae7e8f30a4b5 (patch) | |
| tree | eeb96748efc4c788bf51f90c803b3771c7ac55cd /drivers/net/phy/phy_caps.c | |
| parent | d8c838a57ce25c746c9882ffa427d8bb3f22b526 (diff) | |
net: phy: phy_caps: Move phy_speeds to phy_caps
Use the newly introduced link_capabilities array to derive the list of
possible speeds when given a combination of linkmodes. As
link_capabilities is indexed by speed, we don't have to iterate the
whole phy_settings array.
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20250307173611.129125-4-maxime.chevallier@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'drivers/net/phy/phy_caps.c')
| -rw-r--r-- | drivers/net/phy/phy_caps.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/net/phy/phy_caps.c b/drivers/net/phy/phy_caps.c index 6cb18e216d97..8ce91257160f 100644 --- a/drivers/net/phy/phy_caps.c +++ b/drivers/net/phy/phy_caps.c @@ -57,6 +57,9 @@ static int speed_duplex_to_capa(int speed, unsigned int duplex) return -EINVAL; } +#define for_each_link_caps_asc_speed(cap) \ + for (cap = link_caps; cap < &link_caps[__LINK_CAPA_MAX]; cap++) + /** * phy_caps_init() - Initializes the link_caps array from the link_mode_params. * @@ -88,3 +91,33 @@ int phy_caps_init(void) return 0; } + +/** + * phy_caps_speeds() - Fill an array of supported SPEED_* values for given modes + * @speeds: Output array to store the speeds list into + * @size: Size of the output array + * @linkmodes: Linkmodes to get the speeds from + * + * Fills the speeds array with all possible speeds that can be achieved with + * the specified linkmodes. + * + * Returns: The number of speeds filled into the array. If the input array isn't + * big enough to store all speeds, fill it as much as possible. + */ +size_t phy_caps_speeds(unsigned int *speeds, size_t size, + unsigned long *linkmodes) +{ + struct link_capabilities *lcap; + size_t count = 0; + + for_each_link_caps_asc_speed(lcap) { + if (linkmode_intersects(lcap->linkmodes, linkmodes) && + (count == 0 || speeds[count - 1] != lcap->speed)) { + speeds[count++] = lcap->speed; + if (count >= size) + break; + } + } + + return count; +} |