[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <E1pex8L-00Dvnl-1F@rmk-PC.armlinux.org.uk>
Date: Wed, 22 Mar 2023 12:00:01 +0000
From: "Russell King (Oracle)" <rmk+kernel@...linux.org.uk>
To: Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Florian Fainelli <f.fainelli@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Jakub Kicinski <kuba@...nel.org>, linux-acpi@...r.kernel.org,
netdev@...r.kernel.org, Paolo Abeni <pabeni@...hat.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Vladimir Oltean <olteanv@...il.com>
Subject: [PATCH RFC net-next 2/7] net: phylink: provide
phylink_find_max_speed()
Signed-off-by: Russell King (Oracle) <rmk+kernel@...linux.org.uk>
---
drivers/net/phy/phylink.c | 32 ++++++++++++++++++++++++++++++++
include/linux/phylink.h | 1 +
2 files changed, 33 insertions(+)
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,
--
2.30.2
Powered by blists - more mailing lists