diff mbox series

[RFC,net-next,2/7] net: phylink: provide phylink_find_max_speed()

Message ID E1pex8L-00Dvnl-1F@rmk-PC.armlinux.org.uk
State New
Headers show
Series Another attempt at moving mv88e6xxx forward | expand

Commit Message

Russell King (Oracle) March 22, 2023, noon UTC
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/phylink.c | 32 ++++++++++++++++++++++++++++++++
 include/linux/phylink.h   |  1 +
 2 files changed, 33 insertions(+)

Comments

Andrew Lunn March 22, 2023, 6:44 p.m. UTC | #1
On Wed, Mar 22, 2023 at 12:00:01PM +0000, Russell King (Oracle) wrote:
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index f7da96f0c75b..5cd29cceaf93 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -426,6 +426,38 @@  static unsigned long phylink_cap_from_speed_duplex(int speed,
 	return 0;
 }
 
+/**
+ * phylink_find_max_speed
+ * @caps: bitmask of MAC capabilities
+ * @speed: pointer to int for speed
+ * @duplex: pointer to int for duplex
+ */
+int phylink_find_max_speed(unsigned long caps, int *speed, int *duplex)
+{
+	static const int duplex_order[] = {
+		DUPLEX_FULL,
+		DUPLEX_HALF,
+	};
+	int i, j;
+
+	*speed = SPEED_UNKNOWN;
+	*duplex = DUPLEX_UNKNOWN;
+
+	for (j = 0; j < ARRAY_SIZE(duplex_order); j++) {
+		for (i = 0; i < ARRAY_SIZE(phylink_caps_params); i++) {
+			if (phylink_caps_params[i].duplex == duplex_order[j] &&
+			    caps & phylink_caps_params[i].mask) {
+				*speed = phylink_caps_params[i].speed;
+				*duplex = phylink_caps_params[i].duplex;
+				return 0;
+			}
+		}
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(phylink_find_max_speed);
+
 /**
  * phylink_get_capabilities() - get capabilities for a given MAC
  * @interface: phy interface mode defined by &typedef phy_interface_t
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index 9ff56b050584..f8e20ff1e70e 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -557,6 +557,7 @@  void pcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
 		 phy_interface_t interface, int speed, int duplex);
 #endif
 
+int phylink_find_max_speed(unsigned long caps, int *speed, int *duplex);
 void phylink_caps_to_linkmodes(unsigned long *linkmodes, unsigned long caps);
 unsigned long phylink_get_capabilities(phy_interface_t interface,
 				       unsigned long mac_capabilities,