Skip to content

Commit e54d04e

Browse files
mkubecekdavem330
authored andcommitted
ethtool: set message mask with DEBUG_SET request
Implement DEBUG_SET netlink request to set debugging settings for a device. At the moment, only message mask corresponding to message level as set by ETHTOOL_SMSGLVL ioctl request can be set. (It is called message level in ioctl interface but almost all drivers interpret it as a bit mask.) Signed-off-by: Michal Kubecek <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6a94b8c commit e54d04e

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Userspace to kernel:
186186
``ETHTOOL_MSG_LINKMODES_SET`` set link modes info
187187
``ETHTOOL_MSG_LINKSTATE_GET`` get link state
188188
``ETHTOOL_MSG_DEBUG_GET`` get debugging settings
189+
``ETHTOOL_MSG_DEBUG_SET`` set debugging settings
189190
===================================== ================================
190191

191192
Kernel to userspace:
@@ -455,6 +456,23 @@ interface follows its actual use in practice.
455456
devices supporting the request).
456457

457458

459+
DEBUG_SET
460+
=========
461+
462+
Set or update debugging settings of a device. At the moment, only message mask
463+
is supported.
464+
465+
Request contents:
466+
467+
==================================== ====== ==========================
468+
``ETHTOOL_A_DEBUG_HEADER`` nested request header
469+
``ETHTOOL_A_DEBUG_MSGMASK`` bitset message mask
470+
==================================== ====== ==========================
471+
472+
``ETHTOOL_A_DEBUG_MSGMASK`` bit set allows setting or modifying mask of
473+
enabled debugging message types for the device.
474+
475+
458476
Request translation
459477
===================
460478

@@ -474,7 +492,7 @@ have their netlink replacement yet.
474492
``ETHTOOL_GWOL`` n/a
475493
``ETHTOOL_SWOL`` n/a
476494
``ETHTOOL_GMSGLVL`` ``ETHTOOL_MSG_DEBUG_GET``
477-
``ETHTOOL_SMSGLVL`` n/a
495+
``ETHTOOL_SMSGLVL`` ``ETHTOOL_MSG_DEBUG_SET``
478496
``ETHTOOL_NWAY_RST`` n/a
479497
``ETHTOOL_GLINK`` ``ETHTOOL_MSG_LINKSTATE_GET``
480498
``ETHTOOL_GEEPROM`` n/a

include/uapi/linux/ethtool_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum {
2121
ETHTOOL_MSG_LINKMODES_SET,
2222
ETHTOOL_MSG_LINKSTATE_GET,
2323
ETHTOOL_MSG_DEBUG_GET,
24+
ETHTOOL_MSG_DEBUG_SET,
2425

2526
/* add new constants above here */
2627
__ETHTOOL_MSG_USER_CNT,

net/ethtool/debug.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,56 @@ const struct ethnl_request_ops ethnl_debug_request_ops = {
7878
.reply_size = debug_reply_size,
7979
.fill_reply = debug_fill_reply,
8080
};
81+
82+
/* DEBUG_SET */
83+
84+
static const struct nla_policy
85+
debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = {
86+
[ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT },
87+
[ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED },
88+
[ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_NESTED },
89+
};
90+
91+
int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info)
92+
{
93+
struct nlattr *tb[ETHTOOL_A_DEBUG_MAX + 1];
94+
struct ethnl_req_info req_info = {};
95+
struct net_device *dev;
96+
bool mod = false;
97+
u32 msg_mask;
98+
int ret;
99+
100+
ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
101+
ETHTOOL_A_DEBUG_MAX, debug_set_policy,
102+
info->extack);
103+
if (ret < 0)
104+
return ret;
105+
ret = ethnl_parse_header(&req_info, tb[ETHTOOL_A_DEBUG_HEADER],
106+
genl_info_net(info), info->extack, true);
107+
if (ret < 0)
108+
return ret;
109+
dev = req_info.dev;
110+
if (!dev->ethtool_ops->get_msglevel || !dev->ethtool_ops->set_msglevel)
111+
return -EOPNOTSUPP;
112+
113+
rtnl_lock();
114+
ret = ethnl_ops_begin(dev);
115+
if (ret < 0)
116+
goto out_rtnl;
117+
118+
msg_mask = dev->ethtool_ops->get_msglevel(dev);
119+
ret = ethnl_update_bitset32(&msg_mask, NETIF_MSG_CLASS_COUNT,
120+
tb[ETHTOOL_A_DEBUG_MSGMASK],
121+
netif_msg_class_names, info->extack, &mod);
122+
if (ret < 0 || !mod)
123+
goto out_ops;
124+
125+
dev->ethtool_ops->set_msglevel(dev, msg_mask);
126+
127+
out_ops:
128+
ethnl_ops_complete(dev);
129+
out_rtnl:
130+
rtnl_unlock();
131+
dev_put(dev);
132+
return ret;
133+
}

net/ethtool/netlink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
672672
.dumpit = ethnl_default_dumpit,
673673
.done = ethnl_default_done,
674674
},
675+
{
676+
.cmd = ETHTOOL_MSG_DEBUG_SET,
677+
.flags = GENL_UNS_ADMIN_PERM,
678+
.doit = ethnl_set_debug,
679+
},
675680
};
676681

677682
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
@@ -338,5 +338,6 @@ extern const struct ethnl_request_ops ethnl_debug_request_ops;
338338

339339
int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info);
340340
int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);
341+
int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info);
341342

342343
#endif /* _NET_ETHTOOL_NETLINK_H */

0 commit comments

Comments
 (0)