Commit 428c122f authored by Michal Kubecek's avatar Michal Kubecek Committed by David S. Miller

ethtool: provide link mode names as a string set

Unlike e.g. netdev features, the ethtool ioctl interface requires link mode
table to be in sync between kernel and userspace for userspace to be able
to display and set all link modes supported by kernel. The way arbitrary
length bitsets are implemented in netlink interface, this will be no longer
needed.

To allow userspace to access all link modes running kernel supports, add
table of ethernet link mode names and make it available as a string set to
userspace GET_STRSET requests. Add build time check to make sure names
are defined for all modes declared in enum ethtool_link_mode_bit_indices.

Once the string set is available, make it also accessible via ioctl.
Signed-off-by: default avatarMichal Kubecek <mkubecek@suse.cz>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d44e1310
...@@ -593,6 +593,7 @@ struct ethtool_pauseparam { ...@@ -593,6 +593,7 @@ struct ethtool_pauseparam {
* @ETH_SS_RSS_HASH_FUNCS: RSS hush function names * @ETH_SS_RSS_HASH_FUNCS: RSS hush function names
* @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS * @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
* @ETH_SS_PHY_TUNABLES: PHY tunable names * @ETH_SS_PHY_TUNABLES: PHY tunable names
* @ETH_SS_LINK_MODES: link mode names
*/ */
enum ethtool_stringset { enum ethtool_stringset {
ETH_SS_TEST = 0, ETH_SS_TEST = 0,
...@@ -604,6 +605,7 @@ enum ethtool_stringset { ...@@ -604,6 +605,7 @@ enum ethtool_stringset {
ETH_SS_TUNABLES, ETH_SS_TUNABLES,
ETH_SS_PHY_STATS, ETH_SS_PHY_STATS,
ETH_SS_PHY_TUNABLES, ETH_SS_PHY_TUNABLES,
ETH_SS_LINK_MODES,
}; };
/** /**
......
...@@ -83,3 +83,89 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { ...@@ -83,3 +83,89 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
[ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down", [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down",
[ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down", [ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down",
}; };
#define __LINK_MODE_NAME(speed, type, duplex) \
#speed "base" #type "/" #duplex
#define __DEFINE_LINK_MODE_NAME(speed, type, duplex) \
[ETHTOOL_LINK_MODE(speed, type, duplex)] = \
__LINK_MODE_NAME(speed, type, duplex)
#define __DEFINE_SPECIAL_MODE_NAME(_mode, _name) \
[ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = _name
const char link_mode_names[][ETH_GSTRING_LEN] = {
__DEFINE_LINK_MODE_NAME(10, T, Half),
__DEFINE_LINK_MODE_NAME(10, T, Full),
__DEFINE_LINK_MODE_NAME(100, T, Half),
__DEFINE_LINK_MODE_NAME(100, T, Full),
__DEFINE_LINK_MODE_NAME(1000, T, Half),
__DEFINE_LINK_MODE_NAME(1000, T, Full),
__DEFINE_SPECIAL_MODE_NAME(Autoneg, "Autoneg"),
__DEFINE_SPECIAL_MODE_NAME(TP, "TP"),
__DEFINE_SPECIAL_MODE_NAME(AUI, "AUI"),
__DEFINE_SPECIAL_MODE_NAME(MII, "MII"),
__DEFINE_SPECIAL_MODE_NAME(FIBRE, "FIBRE"),
__DEFINE_SPECIAL_MODE_NAME(BNC, "BNC"),
__DEFINE_LINK_MODE_NAME(10000, T, Full),
__DEFINE_SPECIAL_MODE_NAME(Pause, "Pause"),
__DEFINE_SPECIAL_MODE_NAME(Asym_Pause, "Asym_Pause"),
__DEFINE_LINK_MODE_NAME(2500, X, Full),
__DEFINE_SPECIAL_MODE_NAME(Backplane, "Backplane"),
__DEFINE_LINK_MODE_NAME(1000, KX, Full),
__DEFINE_LINK_MODE_NAME(10000, KX4, Full),
__DEFINE_LINK_MODE_NAME(10000, KR, Full),
__DEFINE_SPECIAL_MODE_NAME(10000baseR_FEC, "10000baseR_FEC"),
__DEFINE_LINK_MODE_NAME(20000, MLD2, Full),
__DEFINE_LINK_MODE_NAME(20000, KR2, Full),
__DEFINE_LINK_MODE_NAME(40000, KR4, Full),
__DEFINE_LINK_MODE_NAME(40000, CR4, Full),
__DEFINE_LINK_MODE_NAME(40000, SR4, Full),
__DEFINE_LINK_MODE_NAME(40000, LR4, Full),
__DEFINE_LINK_MODE_NAME(56000, KR4, Full),
__DEFINE_LINK_MODE_NAME(56000, CR4, Full),
__DEFINE_LINK_MODE_NAME(56000, SR4, Full),
__DEFINE_LINK_MODE_NAME(56000, LR4, Full),
__DEFINE_LINK_MODE_NAME(25000, CR, Full),
__DEFINE_LINK_MODE_NAME(25000, KR, Full),
__DEFINE_LINK_MODE_NAME(25000, SR, Full),
__DEFINE_LINK_MODE_NAME(50000, CR2, Full),
__DEFINE_LINK_MODE_NAME(50000, KR2, Full),
__DEFINE_LINK_MODE_NAME(100000, KR4, Full),
__DEFINE_LINK_MODE_NAME(100000, SR4, Full),
__DEFINE_LINK_MODE_NAME(100000, CR4, Full),
__DEFINE_LINK_MODE_NAME(100000, LR4_ER4, Full),
__DEFINE_LINK_MODE_NAME(50000, SR2, Full),
__DEFINE_LINK_MODE_NAME(1000, X, Full),
__DEFINE_LINK_MODE_NAME(10000, CR, Full),
__DEFINE_LINK_MODE_NAME(10000, SR, Full),
__DEFINE_LINK_MODE_NAME(10000, LR, Full),
__DEFINE_LINK_MODE_NAME(10000, LRM, Full),
__DEFINE_LINK_MODE_NAME(10000, ER, Full),
__DEFINE_LINK_MODE_NAME(2500, T, Full),
__DEFINE_LINK_MODE_NAME(5000, T, Full),
__DEFINE_SPECIAL_MODE_NAME(FEC_NONE, "None"),
__DEFINE_SPECIAL_MODE_NAME(FEC_RS, "RS"),
__DEFINE_SPECIAL_MODE_NAME(FEC_BASER, "BASER"),
__DEFINE_LINK_MODE_NAME(50000, KR, Full),
__DEFINE_LINK_MODE_NAME(50000, SR, Full),
__DEFINE_LINK_MODE_NAME(50000, CR, Full),
__DEFINE_LINK_MODE_NAME(50000, LR_ER_FR, Full),
__DEFINE_LINK_MODE_NAME(50000, DR, Full),
__DEFINE_LINK_MODE_NAME(100000, KR2, Full),
__DEFINE_LINK_MODE_NAME(100000, SR2, Full),
__DEFINE_LINK_MODE_NAME(100000, CR2, Full),
__DEFINE_LINK_MODE_NAME(100000, LR2_ER2_FR2, Full),
__DEFINE_LINK_MODE_NAME(100000, DR2, Full),
__DEFINE_LINK_MODE_NAME(200000, KR4, Full),
__DEFINE_LINK_MODE_NAME(200000, SR4, Full),
__DEFINE_LINK_MODE_NAME(200000, LR4_ER4_FR4, Full),
__DEFINE_LINK_MODE_NAME(200000, DR4, Full),
__DEFINE_LINK_MODE_NAME(200000, CR4, Full),
__DEFINE_LINK_MODE_NAME(100, T1, Full),
__DEFINE_LINK_MODE_NAME(1000, T1, Full),
__DEFINE_LINK_MODE_NAME(400000, KR8, Full),
__DEFINE_LINK_MODE_NAME(400000, SR8, Full),
__DEFINE_LINK_MODE_NAME(400000, LR8_ER8_FR8, Full),
__DEFINE_LINK_MODE_NAME(400000, DR8, Full),
__DEFINE_LINK_MODE_NAME(400000, CR8, Full),
};
static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
/* compose link mode index from speed, type and duplex */
#define ETHTOOL_LINK_MODE(speed, type, duplex) \
ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT
extern const char extern const char
netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]; netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN];
extern const char extern const char
...@@ -13,5 +17,6 @@ extern const char ...@@ -13,5 +17,6 @@ extern const char
tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN]; tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
extern const char extern const char
phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN]; phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
extern const char link_mode_names[][ETH_GSTRING_LEN];
#endif /* _ETHTOOL_COMMON_H */ #endif /* _ETHTOOL_COMMON_H */
...@@ -154,6 +154,9 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset) ...@@ -154,6 +154,9 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset)
!ops->get_ethtool_phy_stats) !ops->get_ethtool_phy_stats)
return phy_ethtool_get_sset_count(dev->phydev); return phy_ethtool_get_sset_count(dev->phydev);
if (sset == ETH_SS_LINK_MODES)
return __ETHTOOL_LINK_MODE_MASK_NBITS;
if (ops->get_sset_count && ops->get_strings) if (ops->get_sset_count && ops->get_strings)
return ops->get_sset_count(dev, sset); return ops->get_sset_count(dev, sset);
else else
...@@ -178,6 +181,9 @@ static void __ethtool_get_strings(struct net_device *dev, ...@@ -178,6 +181,9 @@ static void __ethtool_get_strings(struct net_device *dev,
else if (stringset == ETH_SS_PHY_STATS && dev->phydev && else if (stringset == ETH_SS_PHY_STATS && dev->phydev &&
!ops->get_ethtool_phy_stats) !ops->get_ethtool_phy_stats)
phy_ethtool_get_strings(dev->phydev, data); phy_ethtool_get_strings(dev->phydev, data);
else if (stringset == ETH_SS_LINK_MODES)
memcpy(data, link_mode_names,
__ETHTOOL_LINK_MODE_MASK_NBITS * ETH_GSTRING_LEN);
else else
/* ops->get_strings is valid because checked earlier */ /* ops->get_strings is valid because checked earlier */
ops->get_strings(dev, stringset, data); ops->get_strings(dev, stringset, data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment