Skip to content

Commit 7192169

Browse files
mkubecekdavem330
authored andcommitted
ethtool: provide string sets with STRSET_GET request
Requests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS commands of ioctl interface. Unlike ioctl interface, all information can be retrieved with one request and mulitple string sets can be requested at once. There are three types of requests: - no NLM_F_DUMP, no device: get "global" stringsets - no NLM_F_DUMP, with device: get string sets related to the device - NLM_F_DUMP, no device: get device related string sets for all devices Client can request either all string sets of given type (global or device related) or only specific sets. With ETHTOOL_A_STRSET_COUNTS flag set, only set sizes (numbers of strings) are returned. Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 728480f commit 7192169

7 files changed

Lines changed: 570 additions & 3 deletions

File tree

‎Documentation/networking/ethtool-netlink.rst‎

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ according to message purpose:
176176
``_NTF`` kernel notification
177177
============== ======================================
178178

179+
Userspace to kernel:
180+
181+
===================================== ================================
182+
``ETHTOOL_MSG_STRSET_GET`` get string set
183+
===================================== ================================
184+
185+
Kernel to userspace:
186+
187+
===================================== ================================
188+
``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents
189+
===================================== ================================
190+
179191
``GET`` requests are sent by userspace applications to retrieve device
180192
information. They usually do not contain any message specific attributes.
181193
Kernel replies with corresponding "GET_REPLY" message. For most types, ``GET``
@@ -207,6 +219,65 @@ an ``ACT_REPLY`` message. Performing an action also triggers a notification
207219
Later sections describe the format and semantics of these messages.
208220

209221

222+
STRSET_GET
223+
==========
224+
225+
Requests contents of a string set as provided by ioctl commands
226+
``ETHTOOL_GSSET_INFO`` and ``ETHTOOL_GSTRINGS.`` String sets are not user
227+
writeable so that the corresponding ``STRSET_SET`` message is only used in
228+
kernel replies. There are two types of string sets: global (independent of
229+
a device, e.g. device feature names) and device specific (e.g. device private
230+
flags).
231+
232+
Request contents:
233+
234+
+---------------------------------------+--------+------------------------+
235+
| ``ETHTOOL_A_STRSET_HEADER`` | nested | request header |
236+
+---------------------------------------+--------+------------------------+
237+
| ``ETHTOOL_A_STRSET_STRINGSETS`` | nested | string set to request |
238+
+-+-------------------------------------+--------+------------------------+
239+
| | ``ETHTOOL_A_STRINGSETS_STRINGSET+`` | nested | one string set |
240+
+-+-+-----------------------------------+--------+------------------------+
241+
| | | ``ETHTOOL_A_STRINGSET_ID`` | u32 | set id |
242+
+-+-+-----------------------------------+--------+------------------------+
243+
244+
Kernel response contents:
245+
246+
+---------------------------------------+--------+-----------------------+
247+
| ``ETHTOOL_A_STRSET_HEADER`` | nested | reply header |
248+
+---------------------------------------+--------+-----------------------+
249+
| ``ETHTOOL_A_STRSET_STRINGSETS`` | nested | array of string sets |
250+
+-+-------------------------------------+--------+-----------------------+
251+
| | ``ETHTOOL_A_STRINGSETS_STRINGSET+`` | nested | one string set |
252+
+-+-+-----------------------------------+--------+-----------------------+
253+
| | | ``ETHTOOL_A_STRINGSET_ID`` | u32 | set id |
254+
+-+-+-----------------------------------+--------+-----------------------+
255+
| | | ``ETHTOOL_A_STRINGSET_COUNT`` | u32 | number of strings |
256+
+-+-+-----------------------------------+--------+-----------------------+
257+
| | | ``ETHTOOL_A_STRINGSET_STRINGS`` | nested | array of strings |
258+
+-+-+-+---------------------------------+--------+-----------------------+
259+
| | | | ``ETHTOOL_A_STRINGS_STRING+`` | nested | one string |
260+
+-+-+-+-+-------------------------------+--------+-----------------------+
261+
| | | | | ``ETHTOOL_A_STRING_INDEX`` | u32 | string index |
262+
+-+-+-+-+-------------------------------+--------+-----------------------+
263+
| | | | | ``ETHTOOL_A_STRING_VALUE`` | string | string value |
264+
+-+-+-+-+-------------------------------+--------+-----------------------+
265+
| ``ETHTOOL_A_STRSET_COUNTS_ONLY`` | flag | return only counts |
266+
+---------------------------------------+--------+-----------------------+
267+
268+
Device identification in request header is optional. Depending on its presence
269+
a and ``NLM_F_DUMP`` flag, there are three type of ``STRSET_GET`` requests:
270+
271+
- no ``NLM_F_DUMP,`` no device: get "global" stringsets
272+
- no ``NLM_F_DUMP``, with device: get string sets related to the device
273+
- ``NLM_F_DUMP``, no device: get device related string sets for all devices
274+
275+
If there is no ``ETHTOOL_A_STRSET_STRINGSETS`` array, all string sets of
276+
requested type are returned, otherwise only those specified in the request.
277+
Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells kernel to only return string
278+
counts of the sets, not the actual strings.
279+
280+
210281
Request translation
211282
===================
212283

@@ -242,7 +313,7 @@ have their netlink replacement yet.
242313
``ETHTOOL_GSG`` n/a
243314
``ETHTOOL_SSG`` n/a
244315
``ETHTOOL_TEST`` n/a
245-
``ETHTOOL_GSTRINGS`` n/a
316+
``ETHTOOL_GSTRINGS`` ``ETHTOOL_MSG_STRSET_GET``
246317
``ETHTOOL_PHYS_ID`` n/a
247318
``ETHTOOL_GSTATS`` n/a
248319
``ETHTOOL_GTSO`` n/a
@@ -270,7 +341,7 @@ have their netlink replacement yet.
270341
``ETHTOOL_RESET`` n/a
271342
``ETHTOOL_SRXNTUPLE`` n/a
272343
``ETHTOOL_GRXNTUPLE`` n/a
273-
``ETHTOOL_GSSET_INFO`` n/a
344+
``ETHTOOL_GSSET_INFO`` ``ETHTOOL_MSG_STRSET_GET``
274345
``ETHTOOL_GRXFHINDIR`` n/a
275346
``ETHTOOL_SRXFHINDIR`` n/a
276347
``ETHTOOL_GFEATURES`` n/a

‎include/uapi/linux/ethtool.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ enum ethtool_stringset {
606606
ETH_SS_PHY_STATS,
607607
ETH_SS_PHY_TUNABLES,
608608
ETH_SS_LINK_MODES,
609+
610+
/* add new constants above here */
611+
ETH_SS_COUNT
609612
};
610613

611614
/**

‎include/uapi/linux/ethtool_netlink.h‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/* message types - userspace to kernel */
1515
enum {
1616
ETHTOOL_MSG_USER_NONE,
17+
ETHTOOL_MSG_STRSET_GET,
1718

1819
/* add new constants above here */
1920
__ETHTOOL_MSG_USER_CNT,
@@ -23,6 +24,7 @@ enum {
2324
/* message types - kernel to userspace */
2425
enum {
2526
ETHTOOL_MSG_KERNEL_NONE,
27+
ETHTOOL_MSG_STRSET_GET_REPLY,
2628

2729
/* add new constants above here */
2830
__ETHTOOL_MSG_KERNEL_CNT,
@@ -85,6 +87,60 @@ enum {
8587
ETHTOOL_A_BITSET_MAX = __ETHTOOL_A_BITSET_CNT - 1
8688
};
8789

90+
/* string sets */
91+
92+
enum {
93+
ETHTOOL_A_STRING_UNSPEC,
94+
ETHTOOL_A_STRING_INDEX, /* u32 */
95+
ETHTOOL_A_STRING_VALUE, /* string */
96+
97+
/* add new constants above here */
98+
__ETHTOOL_A_STRING_CNT,
99+
ETHTOOL_A_STRING_MAX = __ETHTOOL_A_STRING_CNT - 1
100+
};
101+
102+
enum {
103+
ETHTOOL_A_STRINGS_UNSPEC,
104+
ETHTOOL_A_STRINGS_STRING, /* nest - _A_STRINGS_* */
105+
106+
/* add new constants above here */
107+
__ETHTOOL_A_STRINGS_CNT,
108+
ETHTOOL_A_STRINGS_MAX = __ETHTOOL_A_STRINGS_CNT - 1
109+
};
110+
111+
enum {
112+
ETHTOOL_A_STRINGSET_UNSPEC,
113+
ETHTOOL_A_STRINGSET_ID, /* u32 */
114+
ETHTOOL_A_STRINGSET_COUNT, /* u32 */
115+
ETHTOOL_A_STRINGSET_STRINGS, /* nest - _A_STRINGS_* */
116+
117+
/* add new constants above here */
118+
__ETHTOOL_A_STRINGSET_CNT,
119+
ETHTOOL_A_STRINGSET_MAX = __ETHTOOL_A_STRINGSET_CNT - 1
120+
};
121+
122+
enum {
123+
ETHTOOL_A_STRINGSETS_UNSPEC,
124+
ETHTOOL_A_STRINGSETS_STRINGSET, /* nest - _A_STRINGSET_* */
125+
126+
/* add new constants above here */
127+
__ETHTOOL_A_STRINGSETS_CNT,
128+
ETHTOOL_A_STRINGSETS_MAX = __ETHTOOL_A_STRINGSETS_CNT - 1
129+
};
130+
131+
/* STRSET */
132+
133+
enum {
134+
ETHTOOL_A_STRSET_UNSPEC,
135+
ETHTOOL_A_STRSET_HEADER, /* nest - _A_HEADER_* */
136+
ETHTOOL_A_STRSET_STRINGSETS, /* nest - _A_STRINGSETS_* */
137+
ETHTOOL_A_STRSET_COUNTS_ONLY, /* flag */
138+
139+
/* add new constants above here */
140+
__ETHTOOL_A_STRSET_CNT,
141+
ETHTOOL_A_STRSET_MAX = __ETHTOOL_A_STRSET_CNT - 1
142+
};
143+
88144
/* generic netlink info */
89145
#define ETHTOOL_GENL_NAME "ethtool"
90146
#define ETHTOOL_GENL_VERSION 1

‎net/ethtool/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ obj-y += ioctl.o common.o
44

55
obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o
66

7-
ethtool_nl-y := netlink.o bitset.o
7+
ethtool_nl-y := netlink.o bitset.o strset.o

‎net/ethtool/netlink.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct ethnl_dump_ctx {
194194

195195
static const struct ethnl_request_ops *
196196
ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
197+
[ETHTOOL_MSG_STRSET_GET] = &ethnl_strset_request_ops,
197198
};
198199

199200
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -518,6 +519,13 @@ EXPORT_SYMBOL(ethtool_notify);
518519
/* genetlink setup */
519520

520521
static const struct genl_ops ethtool_genl_ops[] = {
522+
{
523+
.cmd = ETHTOOL_MSG_STRSET_GET,
524+
.doit = ethnl_default_doit,
525+
.start = ethnl_default_start,
526+
.dumpit = ethnl_default_dumpit,
527+
.done = ethnl_default_done,
528+
},
521529
};
522530

523531
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

‎net/ethtool/netlink.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,8 @@ struct ethnl_request_ops {
326326
void (*cleanup_data)(struct ethnl_reply_data *reply_data);
327327
};
328328

329+
/* request handlers */
330+
331+
extern const struct ethnl_request_ops ethnl_strset_request_ops;
332+
329333
#endif /* _NET_ETHTOOL_NETLINK_H */

0 commit comments

Comments
 (0)