[net-next,v4,2/3] net: phy: add simple helper to return count of supported speeds

Message ID 20231216161206.1729-3-ansuelsmth@gmail.com
State New
Headers
Series net: add define to describe link speed modes |

Commit Message

Christian Marangi Dec. 16, 2023, 4:12 p.m. UTC
  Add simple helper to return count of supported speeds for the passed PHY
device.

This can be useful to know the number of speed modes to dynamically
allocate a speed array for it.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phy.c | 12 ++++++++++++
 include/linux/phy.h   |  2 ++
 2 files changed, 14 insertions(+)
  

Patch

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index a5fa077650e8..3e579dd8a5e7 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -229,6 +229,18 @@  phy_find_valid(int speed, int duplex, unsigned long *supported)
 	return phy_lookup_setting(speed, duplex, supported, false);
 }
 
+/**
+ * phy_supported_speeds_num - return the number of all speeds currently
+ *			      supported by a phy device
+ * @phy: The phy device to return supported speeds of.
+ *
+ * Returns: the number of supported speeds.
+ */
+unsigned int phy_supported_speeds_num(struct phy_device *phy)
+{
+	return phy_speeds(NULL, 0, phy->supported);
+}
+
 /**
  * phy_supported_speeds - return all speeds currently supported by a phy device
  * @phy: The phy device to return supported speeds of.
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3cc52826f18e..52aa415fab0f 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -202,6 +202,8 @@  static inline void phy_interface_set_rgmii(unsigned long *intf)
 	__set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf);
 }
 
+unsigned int phy_supported_speeds_num(struct phy_device *phy);
+
 /*
  * phy_supported_speeds - return all speeds currently supported by a PHY device
  */