Skip to content

Commit 17194be

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 <maxime.chevallier@bootlin.com> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9af0e89 commit 17194be

File tree

6 files changed

+384
-1
lines changed

6 files changed

+384
-1
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,46 @@ string.
21912191
The ``ETHTOOL_A_MODULE_FW_FLASH_DONE`` and ``ETHTOOL_A_MODULE_FW_FLASH_TOTAL``
21922192
attributes encode the completed and total amount of work, respectively.
21932193

2194+
PHY_GET
2195+
=======
2196+
2197+
Retrieve information about a given Ethernet PHY sitting on the link. The DO
2198+
operation returns all available information about dev->phydev. User can also
2199+
specify a PHY_INDEX, in which case the DO request returns information about that
2200+
specific PHY.
2201+
As there can be more than one PHY, the DUMP operation can be used to list the PHYs
2202+
present on a given interface, by passing an interface index or name in
2203+
the dump request.
2204+
2205+
Request contents:
2206+
2207+
==================================== ====== ==========================
2208+
``ETHTOOL_A_PHY_HEADER`` nested request header
2209+
==================================== ====== ==========================
2210+
2211+
Kernel response contents:
2212+
2213+
===================================== ====== ===============================
2214+
``ETHTOOL_A_PHY_HEADER`` nested request header
2215+
``ETHTOOL_A_PHY_INDEX`` u32 the phy's unique index, that can
2216+
be used for phy-specific
2217+
requests
2218+
``ETHTOOL_A_PHY_DRVNAME`` string the phy driver name
2219+
``ETHTOOL_A_PHY_NAME`` string the phy device name
2220+
``ETHTOOL_A_PHY_UPSTREAM_TYPE`` u32 the type of device this phy is
2221+
connected to
2222+
``ETHTOOL_A_PHY_UPSTREAM_INDEX`` u32 the PHY index of the upstream
2223+
PHY
2224+
``ETHTOOL_A_PHY_UPSTREAM_SFP_NAME`` string if this PHY is connected to
2225+
its parent PHY through an SFP
2226+
bus, the name of this sfp bus
2227+
``ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME`` string if the phy controls an sfp bus,
2228+
the name of the sfp bus
2229+
===================================== ====== ===============================
2230+
2231+
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
2232+
another PHY.
2233+
21942234
Request translation
21952235
===================
21962236

@@ -2298,4 +2338,5 @@ are netlink only.
22982338
n/a ``ETHTOOL_MSG_MM_GET``
22992339
n/a ``ETHTOOL_MSG_MM_SET``
23002340
n/a ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT``
2341+
n/a ``ETHTOOL_MSG_PHY_GET``
23012342
=================================== =====================================

include/uapi/linux/ethtool_netlink.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum {
5858
ETHTOOL_MSG_MM_GET,
5959
ETHTOOL_MSG_MM_SET,
6060
ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
61+
ETHTOOL_MSG_PHY_GET,
6162

6263
/* add new constants above here */
6364
__ETHTOOL_MSG_USER_CNT,
@@ -111,6 +112,8 @@ enum {
111112
ETHTOOL_MSG_MM_GET_REPLY,
112113
ETHTOOL_MSG_MM_NTF,
113114
ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
115+
ETHTOOL_MSG_PHY_GET_REPLY,
116+
ETHTOOL_MSG_PHY_NTF,
114117

115118
/* add new constants above here */
116119
__ETHTOOL_MSG_KERNEL_CNT,
@@ -1055,6 +1058,22 @@ enum {
10551058
ETHTOOL_A_MODULE_FW_FLASH_MAX = (__ETHTOOL_A_MODULE_FW_FLASH_CNT - 1)
10561059
};
10571060

1061+
enum {
1062+
ETHTOOL_A_PHY_UNSPEC,
1063+
ETHTOOL_A_PHY_HEADER, /* nest - _A_HEADER_* */
1064+
ETHTOOL_A_PHY_INDEX, /* u32 */
1065+
ETHTOOL_A_PHY_DRVNAME, /* string */
1066+
ETHTOOL_A_PHY_NAME, /* string */
1067+
ETHTOOL_A_PHY_UPSTREAM_TYPE, /* u32 */
1068+
ETHTOOL_A_PHY_UPSTREAM_INDEX, /* u32 */
1069+
ETHTOOL_A_PHY_UPSTREAM_SFP_NAME, /* string */
1070+
ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME, /* string */
1071+
1072+
/* add new constants above here */
1073+
__ETHTOOL_A_PHY_CNT,
1074+
ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
1075+
};
1076+
10581077
/* generic netlink info */
10591078
#define ETHTOOL_GENL_NAME "ethtool"
10601079
#define ETHTOOL_GENL_VERSION 1

net/ethtool/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ 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 cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o
11+
module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o \
12+
phy.o

net/ethtool/netlink.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
12341234
.policy = ethnl_module_fw_flash_act_policy,
12351235
.maxattr = ARRAY_SIZE(ethnl_module_fw_flash_act_policy) - 1,
12361236
},
1237+
{
1238+
.cmd = ETHTOOL_MSG_PHY_GET,
1239+
.doit = ethnl_phy_doit,
1240+
.start = ethnl_phy_start,
1241+
.dumpit = ethnl_phy_dumpit,
1242+
.done = ethnl_phy_done,
1243+
.policy = ethnl_phy_get_policy,
1244+
.maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
1245+
},
12371246
};
12381247

12391248
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
@@ -484,6 +484,7 @@ extern const struct nla_policy ethnl_plca_get_status_policy[ETHTOOL_A_PLCA_HEADE
484484
extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1];
485485
extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1];
486486
extern const struct nla_policy ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1];
487+
extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
487488

488489
int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
489490
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
@@ -494,6 +495,10 @@ int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
494495
int ethnl_act_module_fw_flash(struct sk_buff *skb, struct genl_info *info);
495496
int ethnl_rss_dump_start(struct netlink_callback *cb);
496497
int ethnl_rss_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
498+
int ethnl_phy_start(struct netlink_callback *cb);
499+
int ethnl_phy_doit(struct sk_buff *skb, struct genl_info *info);
500+
int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
501+
int ethnl_phy_done(struct netlink_callback *cb);
497502

498503
extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
499504
extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];

0 commit comments

Comments
 (0)