Skip to content

Commit 11ca3c4

Browse files
lunnkuba-moo
authored andcommitted
net: ethtool: netlink: Add support for triggering a cable test
Add new ethtool netlink calls to trigger the starting of a PHY cable test. Add Kconfig'ury to ETHTOOL_NETLINK so that PHYLIB is not a module when ETHTOOL_NETLINK is builtin, which would result in kernel linking errors. v2: Remove unwanted white space change Remove ethnl_cable_test_act_ops and use doit handler Rename cable_test_set_policy cable_test_act_policy Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY v3: Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY from documentation Remove unused cable_test_get_policy Add Reviewed-by tags v4: Remove unwanted blank line Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Michal Kubecek <mkubecek@suse.cz> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 97c2243 commit 11ca3c4

7 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎Documentation/networking/ethtool-netlink.rst‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Userspace to kernel:
204204
``ETHTOOL_MSG_EEE_GET`` get EEE settings
205205
``ETHTOOL_MSG_EEE_SET`` set EEE settings
206206
``ETHTOOL_MSG_TSINFO_GET`` get timestamping info
207+
``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test
207208
===================================== ================================
208209

209210
Kernel to userspace:
@@ -958,13 +959,25 @@ Kernel response contents:
958959
is no special value for this case). The bitset attributes are omitted if they
959960
would be empty (no bit set).
960961

962+
CABLE_TEST
963+
==========
964+
965+
Start a cable test.
966+
967+
Request contents:
968+
969+
==================================== ====== ==========================
970+
``ETHTOOL_A_CABLE_TEST_HEADER`` nested request header
971+
==================================== ====== ==========================
972+
961973

962974
Request translation
963975
===================
964976

965977
The following table maps ioctl commands to netlink commands providing their
966978
functionality. Entries with "n/a" in right column are commands which do not
967-
have their netlink replacement yet.
979+
have their netlink replacement yet. Entries which "n/a" in the left column
980+
are netlink only.
968981

969982
=================================== =====================================
970983
ioctl command netlink command
@@ -1053,4 +1066,5 @@ have their netlink replacement yet.
10531066
``ETHTOOL_PHY_STUNABLE`` n/a
10541067
``ETHTOOL_GFECPARAM`` n/a
10551068
``ETHTOOL_SFECPARAM`` n/a
1069+
n/a ''ETHTOOL_MSG_CABLE_TEST_ACT''
10561070
=================================== =====================================

‎include/uapi/linux/ethtool_netlink.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum {
3939
ETHTOOL_MSG_EEE_GET,
4040
ETHTOOL_MSG_EEE_SET,
4141
ETHTOOL_MSG_TSINFO_GET,
42+
ETHTOOL_MSG_CABLE_TEST_ACT,
4243

4344
/* add new constants above here */
4445
__ETHTOOL_MSG_USER_CNT,
@@ -405,6 +406,17 @@ enum {
405406
ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
406407
};
407408

409+
/* CABLE TEST */
410+
411+
enum {
412+
ETHTOOL_A_CABLE_TEST_UNSPEC,
413+
ETHTOOL_A_CABLE_TEST_HEADER, /* nest - _A_HEADER_* */
414+
415+
/* add new constants above here */
416+
__ETHTOOL_A_CABLE_TEST_CNT,
417+
ETHTOOL_A_CABLE_TEST_MAX = __ETHTOOL_A_CABLE_TEST_CNT - 1
418+
};
419+
408420
/* generic netlink info */
409421
#define ETHTOOL_GENL_NAME "ethtool"
410422
#define ETHTOOL_GENL_VERSION 1

‎net/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ config FAILOVER
455455
config ETHTOOL_NETLINK
456456
bool "Netlink interface for ethtool"
457457
default y
458+
depends on PHYLIB=y || PHYLIB=n
458459
help
459460
An alternative userspace interface for ethtool based on generic
460461
netlink. It provides better extensibility and some new features,

‎net/ethtool/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o
66

77
ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \
88
linkstate.o debug.o wol.o features.o privflags.o rings.o \
9-
channels.o coalesce.o pause.o eee.o tsinfo.o
9+
channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o

‎net/ethtool/cabletest.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/phy.h>
4+
#include "netlink.h"
5+
#include "common.h"
6+
7+
/* CABLE_TEST_ACT */
8+
9+
static const struct nla_policy
10+
cable_test_act_policy[ETHTOOL_A_CABLE_TEST_MAX + 1] = {
11+
[ETHTOOL_A_CABLE_TEST_UNSPEC] = { .type = NLA_REJECT },
12+
[ETHTOOL_A_CABLE_TEST_HEADER] = { .type = NLA_NESTED },
13+
};
14+
15+
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
16+
{
17+
struct nlattr *tb[ETHTOOL_A_CABLE_TEST_MAX + 1];
18+
struct ethnl_req_info req_info = {};
19+
struct net_device *dev;
20+
int ret;
21+
22+
ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
23+
ETHTOOL_A_CABLE_TEST_MAX,
24+
cable_test_act_policy, info->extack);
25+
if (ret < 0)
26+
return ret;
27+
28+
ret = ethnl_parse_header_dev_get(&req_info,
29+
tb[ETHTOOL_A_CABLE_TEST_HEADER],
30+
genl_info_net(info), info->extack,
31+
true);
32+
if (ret < 0)
33+
return ret;
34+
35+
dev = req_info.dev;
36+
if (!dev->phydev) {
37+
ret = -EOPNOTSUPP;
38+
goto out_dev_put;
39+
}
40+
41+
rtnl_lock();
42+
ret = ethnl_ops_begin(dev);
43+
if (ret < 0)
44+
goto out_rtnl;
45+
46+
ret = phy_start_cable_test(dev->phydev, info->extack);
47+
48+
ethnl_ops_complete(dev);
49+
out_rtnl:
50+
rtnl_unlock();
51+
out_dev_put:
52+
dev_put(dev);
53+
return ret;
54+
}

‎net/ethtool/netlink.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
839839
.dumpit = ethnl_default_dumpit,
840840
.done = ethnl_default_done,
841841
},
842+
{
843+
.cmd = ETHTOOL_MSG_CABLE_TEST_ACT,
844+
.flags = GENL_UNS_ADMIN_PERM,
845+
.doit = ethnl_act_cable_test,
846+
},
842847
};
843848

844849
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

‎net/ethtool/netlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,6 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info);
357357
int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info);
358358
int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info);
359359
int ethnl_set_eee(struct sk_buff *skb, struct genl_info *info);
360+
int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
360361

361362
#endif /* _NET_ETHTOOL_NETLINK_H */

0 commit comments

Comments
 (0)