Skip to content

Commit 63d5eaf

Browse files
minimaxwelldavem330
authored andcommitted
net: ethtool: Introduce a command to list PHYs on an interface
As we have the ability to track the PHYs connected to a net_device through the link_topology, we can expose this list to userspace. This allows userspace to use these identifiers for phy-specific commands and take the decision of which PHY to target by knowing the link topology. Add PHY_GET and PHY_DUMP, which can be a filtered DUMP operation to list devices on only one interface. Signed-off-by: Maxime Chevallier <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c29451a commit 63d5eaf

File tree

6 files changed

+394
-1
lines changed

6 files changed

+394
-1
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,49 @@ The attributes are propagated to the driver through the following structure:
20112011
.. kernel-doc:: include/linux/ethtool.h
20122012
:identifiers: ethtool_mm_cfg
20132013

2014+
PHY_GET
2015+
=======
2016+
2017+
Retrieve information about a given Ethernet PHY sitting on the link. As there
2018+
can be more than one PHY, the DUMP operation can be used to list the PHYs
2019+
present on a given interface, by passing an interface index or name in
2020+
the dump request
2021+
2022+
Request contents:
2023+
2024+
==================================== ====== ==========================
2025+
``ETHTOOL_A_PHY_HEADER`` nested request header
2026+
==================================== ====== ==========================
2027+
2028+
Kernel response contents:
2029+
2030+
===================================== ====== ==========================
2031+
``ETHTOOL_A_PHY_HEADER`` nested request header
2032+
``ETHTOOL_A_PHY_INDEX`` u32 the phy's unique index, that can
2033+
be used for phy-specific requests
2034+
``ETHTOOL_A_PHY_DRVNAME`` string the phy driver name
2035+
``ETHTOOL_A_PHY_NAME`` string the phy device name
2036+
``ETHTOOL_A_PHY_UPSTREAM_TYPE`` u32 the type of device this phy is
2037+
connected to
2038+
``ETHTOOL_A_PHY_UPSTREAM_PHY`` nested if the phy is connected to another
2039+
phy, this nest contains info on
2040+
that connection
2041+
``ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME`` string if the phy controls an sfp bus,
2042+
the name of the sfp bus
2043+
``ETHTOOL_A_PHY_ID`` u32 the phy id if the phy is C22
2044+
===================================== ====== ==========================
2045+
2046+
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
2047+
another PHY. Information on the parent PHY will be set in the
2048+
``ETHTOOL_A_PHY_UPSTREAM_PHY`` nest, which has the following structure :
2049+
2050+
=================================== ====== ==========================
2051+
``ETHTOOL_A_PHY_UPSTREAM_INDEX`` u32 the PHY index of the upstream PHY
2052+
``ETHTOOL_A_PHY_UPSTREAM_SFP_NAME`` string if this PHY is connected to it's
2053+
parent PHY through an SFP bus, the
2054+
name of this sfp bus
2055+
=================================== ====== ==========================
2056+
20142057
Request translation
20152058
===================
20162059

@@ -2117,4 +2160,5 @@ are netlink only.
21172160
n/a ``ETHTOOL_MSG_PLCA_GET_STATUS``
21182161
n/a ``ETHTOOL_MSG_MM_GET``
21192162
n/a ``ETHTOOL_MSG_MM_SET``
2163+
n/a ``ETHTOOL_MSG_PHY_GET``
21202164
=================================== =====================================

include/uapi/linux/ethtool_netlink.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum {
5757
ETHTOOL_MSG_PLCA_GET_STATUS,
5858
ETHTOOL_MSG_MM_GET,
5959
ETHTOOL_MSG_MM_SET,
60+
ETHTOOL_MSG_PHY_GET,
6061

6162
/* add new constants above here */
6263
__ETHTOOL_MSG_USER_CNT,
@@ -109,6 +110,8 @@ enum {
109110
ETHTOOL_MSG_PLCA_NTF,
110111
ETHTOOL_MSG_MM_GET_REPLY,
111112
ETHTOOL_MSG_MM_NTF,
113+
ETHTOOL_MSG_PHY_GET_REPLY,
114+
ETHTOOL_MSG_PHY_NTF,
112115

113116
/* add new constants above here */
114117
__ETHTOOL_MSG_KERNEL_CNT,
@@ -977,6 +980,32 @@ enum {
977980
ETHTOOL_A_MM_MAX = (__ETHTOOL_A_MM_CNT - 1)
978981
};
979982

983+
enum {
984+
ETHTOOL_A_PHY_UPSTREAM_UNSPEC,
985+
ETHTOOL_A_PHY_UPSTREAM_INDEX, /* u32 */
986+
ETHTOOL_A_PHY_UPSTREAM_SFP_NAME, /* string */
987+
988+
/* add new constants above here */
989+
__ETHTOOL_A_PHY_UPSTREAM_CNT,
990+
ETHTOOL_A_PHY_UPSTREAM_MAX = (__ETHTOOL_A_PHY_UPSTREAM_CNT - 1)
991+
};
992+
993+
enum {
994+
ETHTOOL_A_PHY_UNSPEC,
995+
ETHTOOL_A_PHY_HEADER, /* nest - _A_HEADER_* */
996+
ETHTOOL_A_PHY_INDEX, /* u32 */
997+
ETHTOOL_A_PHY_DRVNAME, /* string */
998+
ETHTOOL_A_PHY_NAME, /* string */
999+
ETHTOOL_A_PHY_UPSTREAM_TYPE, /* u8 */
1000+
ETHTOOL_A_PHY_UPSTREAM, /* nest - _A_PHY_UPSTREAM_* */
1001+
ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME, /* string */
1002+
ETHTOOL_A_PHY_ID, /* u32 */
1003+
1004+
/* add new constants above here */
1005+
__ETHTOOL_A_PHY_CNT,
1006+
ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
1007+
};
1008+
9801009
/* generic netlink info */
9811010
#define ETHTOOL_GENL_NAME "ethtool"
9821011
#define ETHTOOL_GENL_VERSION 1

net/ethtool/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
88
linkstate.o debug.o wol.o features.o privflags.o rings.o \
99
channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
1010
tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
11-
module.o pse-pd.o plca.o mm.o
11+
module.o pse-pd.o plca.o mm.o phy.o

net/ethtool/netlink.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
11531153
.policy = ethnl_mm_set_policy,
11541154
.maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1,
11551155
},
1156+
{
1157+
.cmd = ETHTOOL_MSG_PHY_GET,
1158+
.doit = ethnl_phy_doit,
1159+
.start = ethnl_phy_start,
1160+
.dumpit = ethnl_phy_dumpit,
1161+
.done = ethnl_phy_done,
1162+
.policy = ethnl_phy_get_policy,
1163+
.maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
1164+
},
11561165
};
11571166

11581167
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

net/ethtool/netlink.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,18 @@ extern const struct nla_policy ethnl_plca_set_cfg_policy[ETHTOOL_A_PLCA_MAX + 1]
444444
extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADER + 1];
445445
extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];
446446
extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];
447+
extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
447448

448449
int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
449450
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
450451
int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info);
451452
int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info);
452453
int ethnl_tunnel_info_start(struct netlink_callback *cb);
453454
int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
455+
int ethnl_phy_start(struct netlink_callback *cb);
456+
int ethnl_phy_doit(struct sk_buff *skb, struct genl_info *info);
457+
int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
458+
int ethnl_phy_done(struct netlink_callback *cb);
454459

455460
extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
456461
extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];

0 commit comments

Comments
 (0)