1 // SPDX-License-Identifier: GPL-2.0-only
4 #include <linux/ethtool_netlink.h>
7 static struct genl_family ethtool_genl_family;
9 static bool ethnl_ok __read_mostly;
10 static u32 ethnl_bcast_seq;
12 #define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS | \
13 ETHTOOL_FLAG_OMIT_REPLY)
14 #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
16 const struct nla_policy ethnl_header_policy[] = {
17 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
18 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
19 .len = ALTIFNAMSIZ - 1 },
20 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
24 const struct nla_policy ethnl_header_policy_stats[] = {
25 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
26 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
27 .len = ALTIFNAMSIZ - 1 },
28 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
32 int ethnl_ops_begin(struct net_device *dev)
34 if (dev && dev->ethtool_ops->begin)
35 return dev->ethtool_ops->begin(dev);
40 void ethnl_ops_complete(struct net_device *dev)
42 if (dev && dev->ethtool_ops->complete)
43 dev->ethtool_ops->complete(dev);
47 * ethnl_parse_header_dev_get() - parse request header
48 * @req_info: structure to put results into
49 * @header: nest attribute with request header
51 * @extack: netlink extack for error reporting
52 * @require_dev: fail if no device identified in header
54 * Parse request header in nested attribute @nest and puts results into
55 * the structure pointed to by @req_info. Extack from @info is used for error
56 * reporting. If req_info->dev is not null on return, reference to it has
57 * been taken. If error is returned, *req_info is null initialized and no
60 * Return: 0 on success or negative error code
62 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
63 const struct nlattr *header, struct net *net,
64 struct netlink_ext_ack *extack, bool require_dev)
66 struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy)];
67 const struct nlattr *devname_attr;
68 struct net_device *dev = NULL;
73 NL_SET_ERR_MSG(extack, "request header missing");
76 /* No validation here, command policy should have a nested policy set
77 * for the header, therefore validation should have already been done.
79 ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy) - 1, header,
83 if (tb[ETHTOOL_A_HEADER_FLAGS])
84 flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
86 devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
87 if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
88 u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
90 dev = dev_get_by_index(net, ifindex);
92 NL_SET_ERR_MSG_ATTR(extack,
93 tb[ETHTOOL_A_HEADER_DEV_INDEX],
94 "no device matches ifindex");
97 /* if both ifindex and ifname are passed, they must match */
99 strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) {
101 NL_SET_ERR_MSG_ATTR(extack, header,
102 "ifindex and name do not match");
105 } else if (devname_attr) {
106 dev = dev_get_by_name(net, nla_data(devname_attr));
108 NL_SET_ERR_MSG_ATTR(extack, devname_attr,
109 "no device matches name");
112 } else if (require_dev) {
113 NL_SET_ERR_MSG_ATTR(extack, header,
114 "neither ifindex nor name specified");
118 if (dev && !netif_device_present(dev)) {
120 NL_SET_ERR_MSG(extack, "device not present");
125 req_info->flags = flags;
130 * ethnl_fill_reply_header() - Put common header into a reply message
131 * @skb: skb with the message
132 * @dev: network device to describe in header
133 * @attrtype: attribute type to use for the nest
135 * Create a nested attribute with attributes describing given network device.
137 * Return: 0 on success, error value (-EMSGSIZE only) on error
139 int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,
146 nest = nla_nest_start(skb, attrtype);
150 if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) ||
151 nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name))
152 goto nla_put_failure;
153 /* If more attributes are put into reply header, ethnl_header_size()
154 * must be updated to account for them.
157 nla_nest_end(skb, nest);
161 nla_nest_cancel(skb, nest);
166 * ethnl_reply_init() - Create skb for a reply and fill device identification
167 * @payload: payload length (without netlink and genetlink header)
168 * @dev: device the reply is about (may be null)
169 * @cmd: ETHTOOL_MSG_* message type for reply
170 * @hdr_attrtype: attribute type for common header
171 * @info: genetlink info of the received packet we respond to
172 * @ehdrp: place to store payload pointer returned by genlmsg_new()
174 * Return: pointer to allocated skb on success, NULL on error
176 struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
177 u16 hdr_attrtype, struct genl_info *info,
182 skb = genlmsg_new(payload, GFP_KERNEL);
185 *ehdrp = genlmsg_put_reply(skb, info, ðtool_genl_family, 0, cmd);
192 ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype);
202 GENL_SET_ERR_MSG(info, "failed to setup reply message");
206 void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd)
208 return genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
209 ðtool_genl_family, 0, cmd);
212 void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd)
214 return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0,
218 int ethnl_multicast(struct sk_buff *skb, struct net_device *dev)
220 return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb,
221 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL);
224 /* GET request helpers */
227 * struct ethnl_dump_ctx - context structure for generic dumpit() callback
228 * @ops: request ops of currently processed message type
229 * @req_info: parsed request header of processed request
230 * @reply_data: data needed to compose the reply
231 * @pos_hash: saved iteration position - hashbucket
232 * @pos_idx: saved iteration position - index
234 * These parameters are kept in struct netlink_callback as context preserved
235 * between iterations. They are initialized by ethnl_default_start() and used
236 * in ethnl_default_dumpit() and ethnl_default_done().
238 struct ethnl_dump_ctx {
239 const struct ethnl_request_ops *ops;
240 struct ethnl_req_info *req_info;
241 struct ethnl_reply_data *reply_data;
246 static const struct ethnl_request_ops *
247 ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
248 [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops,
249 [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops,
250 [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops,
251 [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops,
252 [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops,
253 [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops,
254 [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops,
255 [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops,
256 [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops,
257 [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops,
258 [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops,
259 [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops,
260 [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops,
261 [ETHTOOL_MSG_FEC_GET] = ðnl_fec_request_ops,
262 [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops,
263 [ETHTOOL_MSG_MODULE_EEPROM_GET] = ðnl_module_eeprom_request_ops,
264 [ETHTOOL_MSG_STATS_GET] = ðnl_stats_request_ops,
265 [ETHTOOL_MSG_PHC_VCLOCKS_GET] = ðnl_phc_vclocks_request_ops,
268 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
270 return (struct ethnl_dump_ctx *)cb->ctx;
274 * ethnl_default_parse() - Parse request message
275 * @req_info: pointer to structure to put data into
276 * @tb: parsed attributes
277 * @net: request netns
278 * @request_ops: struct request_ops for request type
279 * @extack: netlink extack for error reporting
280 * @require_dev: fail if no device identified in header
282 * Parse universal request header and call request specific ->parse_request()
283 * callback (if defined) to parse the rest of the message.
285 * Return: 0 on success or negative error code
287 static int ethnl_default_parse(struct ethnl_req_info *req_info,
288 struct nlattr **tb, struct net *net,
289 const struct ethnl_request_ops *request_ops,
290 struct netlink_ext_ack *extack, bool require_dev)
294 ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr],
295 net, extack, require_dev);
299 if (request_ops->parse_request) {
300 ret = request_ops->parse_request(req_info, tb, extack);
309 * ethnl_init_reply_data() - Initialize reply data for GET request
310 * @reply_data: pointer to embedded struct ethnl_reply_data
311 * @ops: instance of struct ethnl_request_ops describing the layout
312 * @dev: network device to initialize the reply for
314 * Fills the reply data part with zeros and sets the dev member. Must be called
315 * before calling the ->fill_reply() callback (for each iteration when handling
318 static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,
319 const struct ethnl_request_ops *ops,
320 struct net_device *dev)
322 memset(reply_data, 0, ops->reply_data_size);
323 reply_data->dev = dev;
326 /* default ->doit() handler for GET type requests */
327 static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
329 struct ethnl_reply_data *reply_data = NULL;
330 struct ethnl_req_info *req_info = NULL;
331 const u8 cmd = info->genlhdr->cmd;
332 const struct ethnl_request_ops *ops;
333 int hdr_len, reply_len;
334 struct sk_buff *rskb;
338 ops = ethnl_default_requests[cmd];
339 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd))
341 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
344 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
350 ret = ethnl_default_parse(req_info, info->attrs, genl_info_net(info),
351 ops, info->extack, !ops->allow_nodev_do);
354 ethnl_init_reply_data(reply_data, ops, req_info->dev);
357 ret = ops->prepare_data(req_info, reply_data, info);
361 ret = ops->reply_size(req_info, reply_data);
366 rskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(),
367 req_info->dev, ops->reply_cmd,
368 ops->hdr_attr, info, &reply_payload);
372 ret = ops->fill_reply(rskb, req_info, reply_data);
375 WARN_ONCE(rskb->len - hdr_len > reply_len,
376 "ethnl cmd %d: calculated reply length %d, but consumed %d\n",
377 cmd, reply_len, rskb->len - hdr_len);
378 if (ops->cleanup_data)
379 ops->cleanup_data(reply_data);
381 genlmsg_end(rskb, reply_payload);
383 dev_put(req_info->dev);
386 return genlmsg_reply(rskb, info);
389 WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len);
392 if (ops->cleanup_data)
393 ops->cleanup_data(reply_data);
396 dev_put(req_info->dev);
402 static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
403 const struct ethnl_dump_ctx *ctx,
404 struct netlink_callback *cb)
409 ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
410 ðtool_genl_family, NLM_F_MULTI,
411 ctx->ops->reply_cmd);
415 ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev);
417 ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, NULL);
421 ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
424 ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data);
427 if (ctx->ops->cleanup_data)
428 ctx->ops->cleanup_data(ctx->reply_data);
429 ctx->reply_data->dev = NULL;
431 genlmsg_cancel(skb, ehdr);
433 genlmsg_end(skb, ehdr);
437 /* Default ->dumpit() handler for GET requests. Device iteration copied from
438 * rtnl_dump_ifinfo(); we have to be more careful about device hashtable
439 * persistence as we cannot guarantee to hold RTNL lock through the whole
440 * function as rtnetnlink does.
442 static int ethnl_default_dumpit(struct sk_buff *skb,
443 struct netlink_callback *cb)
445 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
446 struct net *net = sock_net(skb->sk);
447 int s_idx = ctx->pos_idx;
452 for (h = ctx->pos_hash; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
453 struct hlist_head *head;
454 struct net_device *dev;
457 head = &net->dev_index_head[h];
460 seq = net->dev_base_seq;
463 hlist_for_each_entry(dev, head, index_hlist) {
469 ret = ethnl_default_dump_one(skb, dev, ctx, cb);
472 if (ret == -EOPNOTSUPP)
474 if (likely(skb->len))
480 if (net->dev_base_seq != seq) {
494 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
499 /* generic ->start() handler for GET requests */
500 static int ethnl_default_start(struct netlink_callback *cb)
502 const struct genl_dumpit_info *info = genl_dumpit_info(cb);
503 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
504 struct ethnl_reply_data *reply_data;
505 const struct ethnl_request_ops *ops;
506 struct ethnl_req_info *req_info;
507 struct genlmsghdr *ghdr;
510 BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
512 ghdr = nlmsg_data(cb->nlh);
513 ops = ethnl_default_requests[ghdr->cmd];
514 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd))
516 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
519 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
525 ret = ethnl_default_parse(req_info, info->attrs, sock_net(cb->skb->sk),
526 ops, cb->extack, false);
528 /* We ignore device specification in dump requests but as the
529 * same parser as for non-dump (doit) requests is used, it
530 * would take reference to the device if it finds one
532 dev_put(req_info->dev);
533 req_info->dev = NULL;
536 goto free_reply_data;
539 ctx->req_info = req_info;
540 ctx->reply_data = reply_data;
554 /* default ->done() handler for GET requests */
555 static int ethnl_default_done(struct netlink_callback *cb)
557 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
559 kfree(ctx->reply_data);
560 kfree(ctx->req_info);
565 static const struct ethnl_request_ops *
566 ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
567 [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops,
568 [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops,
569 [ETHTOOL_MSG_DEBUG_NTF] = ðnl_debug_request_ops,
570 [ETHTOOL_MSG_WOL_NTF] = ðnl_wol_request_ops,
571 [ETHTOOL_MSG_FEATURES_NTF] = ðnl_features_request_ops,
572 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ðnl_privflags_request_ops,
573 [ETHTOOL_MSG_RINGS_NTF] = ðnl_rings_request_ops,
574 [ETHTOOL_MSG_CHANNELS_NTF] = ðnl_channels_request_ops,
575 [ETHTOOL_MSG_COALESCE_NTF] = ðnl_coalesce_request_ops,
576 [ETHTOOL_MSG_PAUSE_NTF] = ðnl_pause_request_ops,
577 [ETHTOOL_MSG_EEE_NTF] = ðnl_eee_request_ops,
578 [ETHTOOL_MSG_FEC_NTF] = ðnl_fec_request_ops,
581 /* default notification handler */
582 static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
585 struct ethnl_reply_data *reply_data;
586 const struct ethnl_request_ops *ops;
587 struct ethnl_req_info *req_info;
593 if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX ||
594 !ethnl_default_notify_ops[cmd],
595 "unexpected notification type %u\n", cmd))
597 ops = ethnl_default_notify_ops[cmd];
598 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
601 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
608 req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS;
610 ethnl_init_reply_data(reply_data, ops, dev);
611 ret = ops->prepare_data(req_info, reply_data, NULL);
614 ret = ops->reply_size(req_info, reply_data);
617 reply_len = ret + ethnl_reply_header_size();
619 skb = genlmsg_new(reply_len, GFP_KERNEL);
622 reply_payload = ethnl_bcastmsg_put(skb, cmd);
625 ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr);
628 ret = ops->fill_reply(skb, req_info, reply_data);
631 if (ops->cleanup_data)
632 ops->cleanup_data(reply_data);
634 genlmsg_end(skb, reply_payload);
637 ethnl_multicast(skb, dev);
641 WARN_ONCE(ret == -EMSGSIZE,
642 "calculated message payload length (%d) not sufficient\n",
647 if (ops->cleanup_data)
648 ops->cleanup_data(reply_data);
656 typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
659 static const ethnl_notify_handler_t ethnl_notify_handlers[] = {
660 [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify,
661 [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify,
662 [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify,
663 [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify,
664 [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify,
665 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ethnl_default_notify,
666 [ETHTOOL_MSG_RINGS_NTF] = ethnl_default_notify,
667 [ETHTOOL_MSG_CHANNELS_NTF] = ethnl_default_notify,
668 [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify,
669 [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify,
670 [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify,
671 [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify,
674 void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data)
676 if (unlikely(!ethnl_ok))
680 if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) &&
681 ethnl_notify_handlers[cmd]))
682 ethnl_notify_handlers[cmd](dev, cmd, data);
684 WARN_ONCE(1, "notification %u not implemented (dev=%s)\n",
685 cmd, netdev_name(dev));
687 EXPORT_SYMBOL(ethtool_notify);
689 static void ethnl_notify_features(struct netdev_notifier_info *info)
691 struct net_device *dev = netdev_notifier_info_to_dev(info);
693 ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL);
696 static int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
700 case NETDEV_FEAT_CHANGE:
701 ethnl_notify_features(ptr);
708 static struct notifier_block ethnl_netdev_notifier = {
709 .notifier_call = ethnl_netdev_event,
712 /* genetlink setup */
714 static const struct genl_ops ethtool_genl_ops[] = {
716 .cmd = ETHTOOL_MSG_STRSET_GET,
717 .doit = ethnl_default_doit,
718 .start = ethnl_default_start,
719 .dumpit = ethnl_default_dumpit,
720 .done = ethnl_default_done,
721 .policy = ethnl_strset_get_policy,
722 .maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1,
725 .cmd = ETHTOOL_MSG_LINKINFO_GET,
726 .doit = ethnl_default_doit,
727 .start = ethnl_default_start,
728 .dumpit = ethnl_default_dumpit,
729 .done = ethnl_default_done,
730 .policy = ethnl_linkinfo_get_policy,
731 .maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1,
734 .cmd = ETHTOOL_MSG_LINKINFO_SET,
735 .flags = GENL_UNS_ADMIN_PERM,
736 .doit = ethnl_set_linkinfo,
737 .policy = ethnl_linkinfo_set_policy,
738 .maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1,
741 .cmd = ETHTOOL_MSG_LINKMODES_GET,
742 .doit = ethnl_default_doit,
743 .start = ethnl_default_start,
744 .dumpit = ethnl_default_dumpit,
745 .done = ethnl_default_done,
746 .policy = ethnl_linkmodes_get_policy,
747 .maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1,
750 .cmd = ETHTOOL_MSG_LINKMODES_SET,
751 .flags = GENL_UNS_ADMIN_PERM,
752 .doit = ethnl_set_linkmodes,
753 .policy = ethnl_linkmodes_set_policy,
754 .maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1,
757 .cmd = ETHTOOL_MSG_LINKSTATE_GET,
758 .doit = ethnl_default_doit,
759 .start = ethnl_default_start,
760 .dumpit = ethnl_default_dumpit,
761 .done = ethnl_default_done,
762 .policy = ethnl_linkstate_get_policy,
763 .maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1,
766 .cmd = ETHTOOL_MSG_DEBUG_GET,
767 .doit = ethnl_default_doit,
768 .start = ethnl_default_start,
769 .dumpit = ethnl_default_dumpit,
770 .done = ethnl_default_done,
771 .policy = ethnl_debug_get_policy,
772 .maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1,
775 .cmd = ETHTOOL_MSG_DEBUG_SET,
776 .flags = GENL_UNS_ADMIN_PERM,
777 .doit = ethnl_set_debug,
778 .policy = ethnl_debug_set_policy,
779 .maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1,
782 .cmd = ETHTOOL_MSG_WOL_GET,
783 .flags = GENL_UNS_ADMIN_PERM,
784 .doit = ethnl_default_doit,
785 .start = ethnl_default_start,
786 .dumpit = ethnl_default_dumpit,
787 .done = ethnl_default_done,
788 .policy = ethnl_wol_get_policy,
789 .maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1,
792 .cmd = ETHTOOL_MSG_WOL_SET,
793 .flags = GENL_UNS_ADMIN_PERM,
794 .doit = ethnl_set_wol,
795 .policy = ethnl_wol_set_policy,
796 .maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1,
799 .cmd = ETHTOOL_MSG_FEATURES_GET,
800 .doit = ethnl_default_doit,
801 .start = ethnl_default_start,
802 .dumpit = ethnl_default_dumpit,
803 .done = ethnl_default_done,
804 .policy = ethnl_features_get_policy,
805 .maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1,
808 .cmd = ETHTOOL_MSG_FEATURES_SET,
809 .flags = GENL_UNS_ADMIN_PERM,
810 .doit = ethnl_set_features,
811 .policy = ethnl_features_set_policy,
812 .maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1,
815 .cmd = ETHTOOL_MSG_PRIVFLAGS_GET,
816 .doit = ethnl_default_doit,
817 .start = ethnl_default_start,
818 .dumpit = ethnl_default_dumpit,
819 .done = ethnl_default_done,
820 .policy = ethnl_privflags_get_policy,
821 .maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1,
824 .cmd = ETHTOOL_MSG_PRIVFLAGS_SET,
825 .flags = GENL_UNS_ADMIN_PERM,
826 .doit = ethnl_set_privflags,
827 .policy = ethnl_privflags_set_policy,
828 .maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1,
831 .cmd = ETHTOOL_MSG_RINGS_GET,
832 .doit = ethnl_default_doit,
833 .start = ethnl_default_start,
834 .dumpit = ethnl_default_dumpit,
835 .done = ethnl_default_done,
836 .policy = ethnl_rings_get_policy,
837 .maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1,
840 .cmd = ETHTOOL_MSG_RINGS_SET,
841 .flags = GENL_UNS_ADMIN_PERM,
842 .doit = ethnl_set_rings,
843 .policy = ethnl_rings_set_policy,
844 .maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1,
847 .cmd = ETHTOOL_MSG_CHANNELS_GET,
848 .doit = ethnl_default_doit,
849 .start = ethnl_default_start,
850 .dumpit = ethnl_default_dumpit,
851 .done = ethnl_default_done,
852 .policy = ethnl_channels_get_policy,
853 .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1,
856 .cmd = ETHTOOL_MSG_CHANNELS_SET,
857 .flags = GENL_UNS_ADMIN_PERM,
858 .doit = ethnl_set_channels,
859 .policy = ethnl_channels_set_policy,
860 .maxattr = ARRAY_SIZE(ethnl_channels_set_policy) - 1,
863 .cmd = ETHTOOL_MSG_COALESCE_GET,
864 .doit = ethnl_default_doit,
865 .start = ethnl_default_start,
866 .dumpit = ethnl_default_dumpit,
867 .done = ethnl_default_done,
868 .policy = ethnl_coalesce_get_policy,
869 .maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1,
872 .cmd = ETHTOOL_MSG_COALESCE_SET,
873 .flags = GENL_UNS_ADMIN_PERM,
874 .doit = ethnl_set_coalesce,
875 .policy = ethnl_coalesce_set_policy,
876 .maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1,
879 .cmd = ETHTOOL_MSG_PAUSE_GET,
880 .doit = ethnl_default_doit,
881 .start = ethnl_default_start,
882 .dumpit = ethnl_default_dumpit,
883 .done = ethnl_default_done,
884 .policy = ethnl_pause_get_policy,
885 .maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1,
888 .cmd = ETHTOOL_MSG_PAUSE_SET,
889 .flags = GENL_UNS_ADMIN_PERM,
890 .doit = ethnl_set_pause,
891 .policy = ethnl_pause_set_policy,
892 .maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1,
895 .cmd = ETHTOOL_MSG_EEE_GET,
896 .doit = ethnl_default_doit,
897 .start = ethnl_default_start,
898 .dumpit = ethnl_default_dumpit,
899 .done = ethnl_default_done,
900 .policy = ethnl_eee_get_policy,
901 .maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1,
904 .cmd = ETHTOOL_MSG_EEE_SET,
905 .flags = GENL_UNS_ADMIN_PERM,
906 .doit = ethnl_set_eee,
907 .policy = ethnl_eee_set_policy,
908 .maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1,
911 .cmd = ETHTOOL_MSG_TSINFO_GET,
912 .doit = ethnl_default_doit,
913 .start = ethnl_default_start,
914 .dumpit = ethnl_default_dumpit,
915 .done = ethnl_default_done,
916 .policy = ethnl_tsinfo_get_policy,
917 .maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1,
920 .cmd = ETHTOOL_MSG_CABLE_TEST_ACT,
921 .flags = GENL_UNS_ADMIN_PERM,
922 .doit = ethnl_act_cable_test,
923 .policy = ethnl_cable_test_act_policy,
924 .maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1,
927 .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
928 .flags = GENL_UNS_ADMIN_PERM,
929 .doit = ethnl_act_cable_test_tdr,
930 .policy = ethnl_cable_test_tdr_act_policy,
931 .maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1,
934 .cmd = ETHTOOL_MSG_TUNNEL_INFO_GET,
935 .doit = ethnl_tunnel_info_doit,
936 .start = ethnl_tunnel_info_start,
937 .dumpit = ethnl_tunnel_info_dumpit,
938 .policy = ethnl_tunnel_info_get_policy,
939 .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1,
942 .cmd = ETHTOOL_MSG_FEC_GET,
943 .doit = ethnl_default_doit,
944 .start = ethnl_default_start,
945 .dumpit = ethnl_default_dumpit,
946 .done = ethnl_default_done,
947 .policy = ethnl_fec_get_policy,
948 .maxattr = ARRAY_SIZE(ethnl_fec_get_policy) - 1,
951 .cmd = ETHTOOL_MSG_FEC_SET,
952 .flags = GENL_UNS_ADMIN_PERM,
953 .doit = ethnl_set_fec,
954 .policy = ethnl_fec_set_policy,
955 .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1,
958 .cmd = ETHTOOL_MSG_MODULE_EEPROM_GET,
959 .flags = GENL_UNS_ADMIN_PERM,
960 .doit = ethnl_default_doit,
961 .start = ethnl_default_start,
962 .dumpit = ethnl_default_dumpit,
963 .done = ethnl_default_done,
964 .policy = ethnl_module_eeprom_get_policy,
965 .maxattr = ARRAY_SIZE(ethnl_module_eeprom_get_policy) - 1,
968 .cmd = ETHTOOL_MSG_STATS_GET,
969 .doit = ethnl_default_doit,
970 .start = ethnl_default_start,
971 .dumpit = ethnl_default_dumpit,
972 .done = ethnl_default_done,
973 .policy = ethnl_stats_get_policy,
974 .maxattr = ARRAY_SIZE(ethnl_stats_get_policy) - 1,
977 .cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET,
978 .doit = ethnl_default_doit,
979 .start = ethnl_default_start,
980 .dumpit = ethnl_default_dumpit,
981 .done = ethnl_default_done,
982 .policy = ethnl_phc_vclocks_get_policy,
983 .maxattr = ARRAY_SIZE(ethnl_phc_vclocks_get_policy) - 1,
987 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
988 [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME },
991 static struct genl_family ethtool_genl_family __ro_after_init = {
992 .name = ETHTOOL_GENL_NAME,
993 .version = ETHTOOL_GENL_VERSION,
995 .parallel_ops = true,
996 .ops = ethtool_genl_ops,
997 .n_ops = ARRAY_SIZE(ethtool_genl_ops),
998 .mcgrps = ethtool_nl_mcgrps,
999 .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps),
1004 static int __init ethnl_init(void)
1008 ret = genl_register_family(ðtool_genl_family);
1009 if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
1013 ret = register_netdevice_notifier(ðnl_netdev_notifier);
1014 WARN(ret < 0, "ethtool: net device notifier registration failed");
1018 subsys_initcall(ethnl_init);