Skip to content

Commit 6a94b8c

Browse files
mkubecekdavem330
authored andcommitted
ethtool: provide message mask with DEBUG_GET request
Implement DEBUG_GET request to get debugging settings for a device. At the moment, only message mask corresponding to message level as reported by ETHTOOL_GMSGLVL ioctl request is provided. (It is called message level in ioctl interface but almost all drivers interpret it as a bit mask.) As part of the implementation, provide symbolic names for message mask bits as ETH_SS_MSG_CLASSES string set. Signed-off-by: Michal Kubecek <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d2c4b44 commit 6a94b8c

File tree

11 files changed

+205
-17
lines changed

11 files changed

+205
-17
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Userspace to kernel:
185185
``ETHTOOL_MSG_LINKMODES_GET`` get link modes info
186186
``ETHTOOL_MSG_LINKMODES_SET`` set link modes info
187187
``ETHTOOL_MSG_LINKSTATE_GET`` get link state
188+
``ETHTOOL_MSG_DEBUG_GET`` get debugging settings
188189
===================================== ================================
189190

190191
Kernel to userspace:
@@ -196,6 +197,7 @@ Kernel to userspace:
196197
``ETHTOOL_MSG_LINKMODES_GET_REPLY`` link modes info
197198
``ETHTOOL_MSG_LINKMODES_NTF`` link modes notification
198199
``ETHTOOL_MSG_LINKSTATE_GET_REPLY`` link state info
200+
``ETHTOOL_MSG_DEBUG_GET_REPLY`` debugging settings
199201
===================================== ================================
200202

201203
``GET`` requests are sent by userspace applications to retrieve device
@@ -423,6 +425,36 @@ define their own handler.
423425
devices supporting the request).
424426

425427

428+
DEBUG_GET
429+
=========
430+
431+
Requests debugging settings of a device. At the moment, only message mask is
432+
provided.
433+
434+
Request contents:
435+
436+
==================================== ====== ==========================
437+
``ETHTOOL_A_DEBUG_HEADER`` nested request header
438+
==================================== ====== ==========================
439+
440+
Kernel response contents:
441+
442+
==================================== ====== ==========================
443+
``ETHTOOL_A_DEBUG_HEADER`` nested reply header
444+
``ETHTOOL_A_DEBUG_MSGMASK`` bitset message mask
445+
==================================== ====== ==========================
446+
447+
The message mask (``ETHTOOL_A_DEBUG_MSGMASK``) is equal to message level as
448+
provided by ``ETHTOOL_GMSGLVL`` and set by ``ETHTOOL_SMSGLVL`` in ioctl
449+
interface. While it is called message level there for historical reasons, most
450+
drivers and almost all newer drivers use it as a mask of enabled message
451+
classes (represented by ``NETIF_MSG_*`` constants); therefore netlink
452+
interface follows its actual use in practice.
453+
454+
``DEBUG_GET`` allows dump requests (kernel returns reply messages for all
455+
devices supporting the request).
456+
457+
426458
Request translation
427459
===================
428460

@@ -441,7 +473,7 @@ have their netlink replacement yet.
441473
``ETHTOOL_GREGS`` n/a
442474
``ETHTOOL_GWOL`` n/a
443475
``ETHTOOL_SWOL`` n/a
444-
``ETHTOOL_GMSGLVL`` n/a
476+
``ETHTOOL_GMSGLVL`` ``ETHTOOL_MSG_DEBUG_GET``
445477
``ETHTOOL_SMSGLVL`` n/a
446478
``ETHTOOL_NWAY_RST`` n/a
447479
``ETHTOOL_GLINK`` ``ETHTOOL_MSG_LINKSTATE_GET``

include/linux/netdevice.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,22 +3913,48 @@ void netif_device_attach(struct net_device *dev);
39133913
*/
39143914

39153915
enum {
3916-
NETIF_MSG_DRV = 0x0001,
3917-
NETIF_MSG_PROBE = 0x0002,
3918-
NETIF_MSG_LINK = 0x0004,
3919-
NETIF_MSG_TIMER = 0x0008,
3920-
NETIF_MSG_IFDOWN = 0x0010,
3921-
NETIF_MSG_IFUP = 0x0020,
3922-
NETIF_MSG_RX_ERR = 0x0040,
3923-
NETIF_MSG_TX_ERR = 0x0080,
3924-
NETIF_MSG_TX_QUEUED = 0x0100,
3925-
NETIF_MSG_INTR = 0x0200,
3926-
NETIF_MSG_TX_DONE = 0x0400,
3927-
NETIF_MSG_RX_STATUS = 0x0800,
3928-
NETIF_MSG_PKTDATA = 0x1000,
3929-
NETIF_MSG_HW = 0x2000,
3930-
NETIF_MSG_WOL = 0x4000,
3916+
NETIF_MSG_DRV_BIT,
3917+
NETIF_MSG_PROBE_BIT,
3918+
NETIF_MSG_LINK_BIT,
3919+
NETIF_MSG_TIMER_BIT,
3920+
NETIF_MSG_IFDOWN_BIT,
3921+
NETIF_MSG_IFUP_BIT,
3922+
NETIF_MSG_RX_ERR_BIT,
3923+
NETIF_MSG_TX_ERR_BIT,
3924+
NETIF_MSG_TX_QUEUED_BIT,
3925+
NETIF_MSG_INTR_BIT,
3926+
NETIF_MSG_TX_DONE_BIT,
3927+
NETIF_MSG_RX_STATUS_BIT,
3928+
NETIF_MSG_PKTDATA_BIT,
3929+
NETIF_MSG_HW_BIT,
3930+
NETIF_MSG_WOL_BIT,
3931+
3932+
/* When you add a new bit above, update netif_msg_class_names array
3933+
* in net/ethtool/common.c
3934+
*/
3935+
NETIF_MSG_CLASS_COUNT,
39313936
};
3937+
/* Both ethtool_ops interface and internal driver implementation use u32 */
3938+
static_assert(NETIF_MSG_CLASS_COUNT <= 32);
3939+
3940+
#define __NETIF_MSG_BIT(bit) ((u32)1 << (bit))
3941+
#define __NETIF_MSG(name) __NETIF_MSG_BIT(NETIF_MSG_ ## name ## _BIT)
3942+
3943+
#define NETIF_MSG_DRV __NETIF_MSG(DRV)
3944+
#define NETIF_MSG_PROBE __NETIF_MSG(PROBE)
3945+
#define NETIF_MSG_LINK __NETIF_MSG(LINK)
3946+
#define NETIF_MSG_TIMER __NETIF_MSG(TIMER)
3947+
#define NETIF_MSG_IFDOWN __NETIF_MSG(IFDOWN)
3948+
#define NETIF_MSG_IFUP __NETIF_MSG(IFUP)
3949+
#define NETIF_MSG_RX_ERR __NETIF_MSG(RX_ERR)
3950+
#define NETIF_MSG_TX_ERR __NETIF_MSG(TX_ERR)
3951+
#define NETIF_MSG_TX_QUEUED __NETIF_MSG(TX_QUEUED)
3952+
#define NETIF_MSG_INTR __NETIF_MSG(INTR)
3953+
#define NETIF_MSG_TX_DONE __NETIF_MSG(TX_DONE)
3954+
#define NETIF_MSG_RX_STATUS __NETIF_MSG(RX_STATUS)
3955+
#define NETIF_MSG_PKTDATA __NETIF_MSG(PKTDATA)
3956+
#define NETIF_MSG_HW __NETIF_MSG(HW)
3957+
#define NETIF_MSG_WOL __NETIF_MSG(WOL)
39323958

39333959
#define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
39343960
#define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)

include/uapi/linux/ethtool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ struct ethtool_pauseparam {
594594
* @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
595595
* @ETH_SS_PHY_TUNABLES: PHY tunable names
596596
* @ETH_SS_LINK_MODES: link mode names
597+
* @ETH_SS_MSG_CLASSES: debug message class names
597598
*/
598599
enum ethtool_stringset {
599600
ETH_SS_TEST = 0,
@@ -606,6 +607,7 @@ enum ethtool_stringset {
606607
ETH_SS_PHY_STATS,
607608
ETH_SS_PHY_TUNABLES,
608609
ETH_SS_LINK_MODES,
610+
ETH_SS_MSG_CLASSES,
609611

610612
/* add new constants above here */
611613
ETH_SS_COUNT

include/uapi/linux/ethtool_netlink.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum {
2020
ETHTOOL_MSG_LINKMODES_GET,
2121
ETHTOOL_MSG_LINKMODES_SET,
2222
ETHTOOL_MSG_LINKSTATE_GET,
23+
ETHTOOL_MSG_DEBUG_GET,
2324

2425
/* add new constants above here */
2526
__ETHTOOL_MSG_USER_CNT,
@@ -35,6 +36,7 @@ enum {
3536
ETHTOOL_MSG_LINKMODES_GET_REPLY,
3637
ETHTOOL_MSG_LINKMODES_NTF,
3738
ETHTOOL_MSG_LINKSTATE_GET_REPLY,
39+
ETHTOOL_MSG_DEBUG_GET_REPLY,
3840

3941
/* add new constants above here */
4042
__ETHTOOL_MSG_KERNEL_CNT,
@@ -195,6 +197,18 @@ enum {
195197
ETHTOOL_A_LINKSTATE_MAX = __ETHTOOL_A_LINKSTATE_CNT - 1
196198
};
197199

200+
/* DEBUG */
201+
202+
enum {
203+
ETHTOOL_A_DEBUG_UNSPEC,
204+
ETHTOOL_A_DEBUG_HEADER, /* nest - _A_HEADER_* */
205+
ETHTOOL_A_DEBUG_MSGMASK, /* bitset */
206+
207+
/* add new constants above here */
208+
__ETHTOOL_A_DEBUG_CNT,
209+
ETHTOOL_A_DEBUG_MAX = __ETHTOOL_A_DEBUG_CNT - 1
210+
};
211+
198212
/* generic netlink info */
199213
#define ETHTOOL_GENL_NAME "ethtool"
200214
#define ETHTOOL_GENL_VERSION 1

net/ethtool/Makefile

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

77
ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \
8-
linkstate.o
8+
linkstate.o debug.o

net/ethtool/common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ const char link_mode_names[][ETH_GSTRING_LEN] = {
171171
};
172172
static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
173173

174+
const char netif_msg_class_names[][ETH_GSTRING_LEN] = {
175+
[NETIF_MSG_DRV_BIT] = "drv",
176+
[NETIF_MSG_PROBE_BIT] = "probe",
177+
[NETIF_MSG_LINK_BIT] = "link",
178+
[NETIF_MSG_TIMER_BIT] = "timer",
179+
[NETIF_MSG_IFDOWN_BIT] = "ifdown",
180+
[NETIF_MSG_IFUP_BIT] = "ifup",
181+
[NETIF_MSG_RX_ERR_BIT] = "rx_err",
182+
[NETIF_MSG_TX_ERR_BIT] = "tx_err",
183+
[NETIF_MSG_TX_QUEUED_BIT] = "tx_queued",
184+
[NETIF_MSG_INTR_BIT] = "intr",
185+
[NETIF_MSG_TX_DONE_BIT] = "tx_done",
186+
[NETIF_MSG_RX_STATUS_BIT] = "rx_status",
187+
[NETIF_MSG_PKTDATA_BIT] = "pktdata",
188+
[NETIF_MSG_HW_BIT] = "hw",
189+
[NETIF_MSG_WOL_BIT] = "wol",
190+
};
191+
static_assert(ARRAY_SIZE(netif_msg_class_names) == NETIF_MSG_CLASS_COUNT);
192+
174193
/* return false if legacy contained non-0 deprecated fields
175194
* maxtxpkt/maxrxpkt. rest of ksettings always updated
176195
*/

net/ethtool/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
1919
extern const char
2020
phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
2121
extern const char link_mode_names[][ETH_GSTRING_LEN];
22+
extern const char netif_msg_class_names[][ETH_GSTRING_LEN];
2223

2324
int __ethtool_get_link(struct net_device *dev);
2425

net/ethtool/debug.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include "netlink.h"
4+
#include "common.h"
5+
#include "bitset.h"
6+
7+
struct debug_req_info {
8+
struct ethnl_req_info base;
9+
};
10+
11+
struct debug_reply_data {
12+
struct ethnl_reply_data base;
13+
u32 msg_mask;
14+
};
15+
16+
#define DEBUG_REPDATA(__reply_base) \
17+
container_of(__reply_base, struct debug_reply_data, base)
18+
19+
static const struct nla_policy
20+
debug_get_policy[ETHTOOL_A_DEBUG_MAX + 1] = {
21+
[ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT },
22+
[ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED },
23+
[ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_REJECT },
24+
};
25+
26+
static int debug_prepare_data(const struct ethnl_req_info *req_base,
27+
struct ethnl_reply_data *reply_base,
28+
struct genl_info *info)
29+
{
30+
struct debug_reply_data *data = DEBUG_REPDATA(reply_base);
31+
struct net_device *dev = reply_base->dev;
32+
int ret;
33+
34+
if (!dev->ethtool_ops->get_msglevel)
35+
return -EOPNOTSUPP;
36+
37+
ret = ethnl_ops_begin(dev);
38+
if (ret < 0)
39+
return ret;
40+
data->msg_mask = dev->ethtool_ops->get_msglevel(dev);
41+
ethnl_ops_complete(dev);
42+
43+
return 0;
44+
}
45+
46+
static int debug_reply_size(const struct ethnl_req_info *req_base,
47+
const struct ethnl_reply_data *reply_base)
48+
{
49+
const struct debug_reply_data *data = DEBUG_REPDATA(reply_base);
50+
bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
51+
52+
return ethnl_bitset32_size(&data->msg_mask, NULL, NETIF_MSG_CLASS_COUNT,
53+
netif_msg_class_names, compact);
54+
}
55+
56+
static int debug_fill_reply(struct sk_buff *skb,
57+
const struct ethnl_req_info *req_base,
58+
const struct ethnl_reply_data *reply_base)
59+
{
60+
const struct debug_reply_data *data = DEBUG_REPDATA(reply_base);
61+
bool compact = req_base->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
62+
63+
return ethnl_put_bitset32(skb, ETHTOOL_A_DEBUG_MSGMASK, &data->msg_mask,
64+
NULL, NETIF_MSG_CLASS_COUNT,
65+
netif_msg_class_names, compact);
66+
}
67+
68+
const struct ethnl_request_ops ethnl_debug_request_ops = {
69+
.request_cmd = ETHTOOL_MSG_DEBUG_GET,
70+
.reply_cmd = ETHTOOL_MSG_DEBUG_GET_REPLY,
71+
.hdr_attr = ETHTOOL_A_DEBUG_HEADER,
72+
.max_attr = ETHTOOL_A_DEBUG_MAX,
73+
.req_info_size = sizeof(struct debug_req_info),
74+
.reply_data_size = sizeof(struct debug_reply_data),
75+
.request_policy = debug_get_policy,
76+
77+
.prepare_data = debug_prepare_data,
78+
.reply_size = debug_reply_size,
79+
.fill_reply = debug_fill_reply,
80+
};

net/ethtool/netlink.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
213213
[ETHTOOL_MSG_LINKINFO_GET] = &ethnl_linkinfo_request_ops,
214214
[ETHTOOL_MSG_LINKMODES_GET] = &ethnl_linkmodes_request_ops,
215215
[ETHTOOL_MSG_LINKSTATE_GET] = &ethnl_linkstate_request_ops,
216+
[ETHTOOL_MSG_DEBUG_GET] = &ethnl_debug_request_ops,
216217
};
217218

218219
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -664,6 +665,13 @@ static const struct genl_ops ethtool_genl_ops[] = {
664665
.dumpit = ethnl_default_dumpit,
665666
.done = ethnl_default_done,
666667
},
668+
{
669+
.cmd = ETHTOOL_MSG_DEBUG_GET,
670+
.doit = ethnl_default_doit,
671+
.start = ethnl_default_start,
672+
.dumpit = ethnl_default_dumpit,
673+
.done = ethnl_default_done,
674+
},
667675
};
668676

669677
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
@@ -334,6 +334,7 @@ extern const struct ethnl_request_ops ethnl_strset_request_ops;
334334
extern const struct ethnl_request_ops ethnl_linkinfo_request_ops;
335335
extern const struct ethnl_request_ops ethnl_linkmodes_request_ops;
336336
extern const struct ethnl_request_ops ethnl_linkstate_request_ops;
337+
extern const struct ethnl_request_ops ethnl_debug_request_ops;
337338

338339
int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info);
339340
int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);

0 commit comments

Comments
 (0)