2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
20 #include <linux/net_tstamp.h>
21 #include <linux/phy.h>
22 #include <linux/bitops.h>
23 #include <linux/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <linux/slab.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/sched.h>
28 #include <linux/net.h>
31 * Some useful ethtool_ops methods that're device independent.
32 * If we find that all drivers want to do the same thing here,
33 * we can turn these into dev_() function calls.
36 u32 ethtool_op_get_link(struct net_device *dev)
38 return netif_carrier_ok(dev) ? 1 : 0;
40 EXPORT_SYMBOL(ethtool_op_get_link);
42 int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
44 info->so_timestamping =
45 SOF_TIMESTAMPING_TX_SOFTWARE |
46 SOF_TIMESTAMPING_RX_SOFTWARE |
47 SOF_TIMESTAMPING_SOFTWARE;
51 EXPORT_SYMBOL(ethtool_op_get_ts_info);
53 /* Handlers for each ethtool command */
55 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
57 static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
58 [NETIF_F_SG_BIT] = "tx-scatter-gather",
59 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
60 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
61 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
62 [NETIF_F_HIGHDMA_BIT] = "highdma",
63 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
64 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
66 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
67 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
68 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
69 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
70 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
71 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
72 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
73 [NETIF_F_LLTX_BIT] = "tx-lockless",
74 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
75 [NETIF_F_GRO_BIT] = "rx-gro",
76 [NETIF_F_LRO_BIT] = "rx-lro",
78 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
79 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
80 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
81 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
82 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
83 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
84 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
85 [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
86 [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
87 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
89 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
90 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
91 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
92 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
93 [NETIF_F_RXHASH_BIT] = "rx-hashing",
94 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
95 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
96 [NETIF_F_LOOPBACK_BIT] = "loopback",
97 [NETIF_F_RXFCS_BIT] = "rx-fcs",
98 [NETIF_F_RXALL_BIT] = "rx-all",
99 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
100 [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
104 rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = {
105 [ETH_RSS_HASH_TOP_BIT] = "toeplitz",
106 [ETH_RSS_HASH_XOR_BIT] = "xor",
110 tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
111 [ETHTOOL_ID_UNSPEC] = "Unspec",
112 [ETHTOOL_RX_COPYBREAK] = "rx-copybreak",
113 [ETHTOOL_TX_COPYBREAK] = "tx-copybreak",
116 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
118 struct ethtool_gfeatures cmd = {
119 .cmd = ETHTOOL_GFEATURES,
120 .size = ETHTOOL_DEV_FEATURE_WORDS,
122 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
123 u32 __user *sizeaddr;
127 /* in case feature bits run out again */
128 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
130 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
131 features[i].available = (u32)(dev->hw_features >> (32 * i));
132 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
133 features[i].active = (u32)(dev->features >> (32 * i));
134 features[i].never_changed =
135 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
138 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
139 if (get_user(copy_size, sizeaddr))
142 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
143 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
145 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
147 useraddr += sizeof(cmd);
148 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
154 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
156 struct ethtool_sfeatures cmd;
157 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
158 netdev_features_t wanted = 0, valid = 0;
161 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
163 useraddr += sizeof(cmd);
165 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
168 if (copy_from_user(features, useraddr, sizeof(features)))
171 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
172 valid |= (netdev_features_t)features[i].valid << (32 * i);
173 wanted |= (netdev_features_t)features[i].requested << (32 * i);
176 if (valid & ~NETIF_F_ETHTOOL_BITS)
179 if (valid & ~dev->hw_features) {
180 valid &= dev->hw_features;
181 ret |= ETHTOOL_F_UNSUPPORTED;
184 dev->wanted_features &= ~valid;
185 dev->wanted_features |= wanted & valid;
186 __netdev_update_features(dev);
188 if ((dev->wanted_features ^ dev->features) & valid)
189 ret |= ETHTOOL_F_WISH;
194 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
196 const struct ethtool_ops *ops = dev->ethtool_ops;
198 if (sset == ETH_SS_FEATURES)
199 return ARRAY_SIZE(netdev_features_strings);
201 if (sset == ETH_SS_RSS_HASH_FUNCS)
202 return ARRAY_SIZE(rss_hash_func_strings);
204 if (sset == ETH_SS_TUNABLES)
205 return ARRAY_SIZE(tunable_strings);
207 if (ops->get_sset_count && ops->get_strings)
208 return ops->get_sset_count(dev, sset);
213 static void __ethtool_get_strings(struct net_device *dev,
214 u32 stringset, u8 *data)
216 const struct ethtool_ops *ops = dev->ethtool_ops;
218 if (stringset == ETH_SS_FEATURES)
219 memcpy(data, netdev_features_strings,
220 sizeof(netdev_features_strings));
221 else if (stringset == ETH_SS_RSS_HASH_FUNCS)
222 memcpy(data, rss_hash_func_strings,
223 sizeof(rss_hash_func_strings));
224 else if (stringset == ETH_SS_TUNABLES)
225 memcpy(data, tunable_strings, sizeof(tunable_strings));
227 /* ops->get_strings is valid because checked earlier */
228 ops->get_strings(dev, stringset, data);
231 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
233 /* feature masks of legacy discrete ethtool ops */
236 case ETHTOOL_GTXCSUM:
237 case ETHTOOL_STXCSUM:
238 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
239 case ETHTOOL_GRXCSUM:
240 case ETHTOOL_SRXCSUM:
241 return NETIF_F_RXCSUM;
247 return NETIF_F_ALL_TSO;
262 static int ethtool_get_one_feature(struct net_device *dev,
263 char __user *useraddr, u32 ethcmd)
265 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
266 struct ethtool_value edata = {
268 .data = !!(dev->features & mask),
271 if (copy_to_user(useraddr, &edata, sizeof(edata)))
276 static int ethtool_set_one_feature(struct net_device *dev,
277 void __user *useraddr, u32 ethcmd)
279 struct ethtool_value edata;
280 netdev_features_t mask;
282 if (copy_from_user(&edata, useraddr, sizeof(edata)))
285 mask = ethtool_get_feature_mask(ethcmd);
286 mask &= dev->hw_features;
291 dev->wanted_features |= mask;
293 dev->wanted_features &= ~mask;
295 __netdev_update_features(dev);
300 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
301 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
302 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
303 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
306 static u32 __ethtool_get_flags(struct net_device *dev)
310 if (dev->features & NETIF_F_LRO)
311 flags |= ETH_FLAG_LRO;
312 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
313 flags |= ETH_FLAG_RXVLAN;
314 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
315 flags |= ETH_FLAG_TXVLAN;
316 if (dev->features & NETIF_F_NTUPLE)
317 flags |= ETH_FLAG_NTUPLE;
318 if (dev->features & NETIF_F_RXHASH)
319 flags |= ETH_FLAG_RXHASH;
324 static int __ethtool_set_flags(struct net_device *dev, u32 data)
326 netdev_features_t features = 0, changed;
328 if (data & ~ETH_ALL_FLAGS)
331 if (data & ETH_FLAG_LRO)
332 features |= NETIF_F_LRO;
333 if (data & ETH_FLAG_RXVLAN)
334 features |= NETIF_F_HW_VLAN_CTAG_RX;
335 if (data & ETH_FLAG_TXVLAN)
336 features |= NETIF_F_HW_VLAN_CTAG_TX;
337 if (data & ETH_FLAG_NTUPLE)
338 features |= NETIF_F_NTUPLE;
339 if (data & ETH_FLAG_RXHASH)
340 features |= NETIF_F_RXHASH;
342 /* allow changing only bits set in hw_features */
343 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
344 if (changed & ~dev->hw_features)
345 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
347 dev->wanted_features =
348 (dev->wanted_features & ~changed) | (features & changed);
350 __netdev_update_features(dev);
355 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
359 if (!dev->ethtool_ops->get_settings)
362 memset(cmd, 0, sizeof(struct ethtool_cmd));
363 cmd->cmd = ETHTOOL_GSET;
364 return dev->ethtool_ops->get_settings(dev, cmd);
366 EXPORT_SYMBOL(__ethtool_get_settings);
368 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
371 struct ethtool_cmd cmd;
373 err = __ethtool_get_settings(dev, &cmd);
377 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
382 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
384 struct ethtool_cmd cmd;
386 if (!dev->ethtool_ops->set_settings)
389 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
392 return dev->ethtool_ops->set_settings(dev, &cmd);
395 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
396 void __user *useraddr)
398 struct ethtool_drvinfo info;
399 const struct ethtool_ops *ops = dev->ethtool_ops;
401 memset(&info, 0, sizeof(info));
402 info.cmd = ETHTOOL_GDRVINFO;
403 if (ops->get_drvinfo) {
404 ops->get_drvinfo(dev, &info);
405 } else if (dev->dev.parent && dev->dev.parent->driver) {
406 strlcpy(info.bus_info, dev_name(dev->dev.parent),
407 sizeof(info.bus_info));
408 strlcpy(info.driver, dev->dev.parent->driver->name,
409 sizeof(info.driver));
415 * this method of obtaining string set info is deprecated;
416 * Use ETHTOOL_GSSET_INFO instead.
418 if (ops->get_sset_count) {
421 rc = ops->get_sset_count(dev, ETH_SS_TEST);
423 info.testinfo_len = rc;
424 rc = ops->get_sset_count(dev, ETH_SS_STATS);
427 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
429 info.n_priv_flags = rc;
431 if (ops->get_regs_len) {
432 int ret = ops->get_regs_len(dev);
435 info.regdump_len = ret;
438 if (ops->get_eeprom_len)
439 info.eedump_len = ops->get_eeprom_len(dev);
441 if (copy_to_user(useraddr, &info, sizeof(info)))
446 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
447 void __user *useraddr)
449 struct ethtool_sset_info info;
451 int i, idx = 0, n_bits = 0, ret, rc;
452 u32 *info_buf = NULL;
454 if (copy_from_user(&info, useraddr, sizeof(info)))
457 /* store copy of mask, because we zero struct later on */
458 sset_mask = info.sset_mask;
462 /* calculate size of return buffer */
463 n_bits = hweight64(sset_mask);
465 memset(&info, 0, sizeof(info));
466 info.cmd = ETHTOOL_GSSET_INFO;
468 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
473 * fill return buffer based on input bitmask and successful
474 * get_sset_count return
476 for (i = 0; i < 64; i++) {
477 if (!(sset_mask & (1ULL << i)))
480 rc = __ethtool_get_sset_count(dev, i);
482 info.sset_mask |= (1ULL << i);
483 info_buf[idx++] = rc;
488 if (copy_to_user(useraddr, &info, sizeof(info)))
491 useraddr += offsetof(struct ethtool_sset_info, data);
492 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
502 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
503 u32 cmd, void __user *useraddr)
505 struct ethtool_rxnfc info;
506 size_t info_size = sizeof(info);
509 if (!dev->ethtool_ops->set_rxnfc)
512 /* struct ethtool_rxnfc was originally defined for
513 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
514 * members. User-space might still be using that
516 if (cmd == ETHTOOL_SRXFH)
517 info_size = (offsetof(struct ethtool_rxnfc, data) +
520 if (copy_from_user(&info, useraddr, info_size))
523 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
527 if (cmd == ETHTOOL_SRXCLSRLINS &&
528 copy_to_user(useraddr, &info, info_size))
534 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
535 u32 cmd, void __user *useraddr)
537 struct ethtool_rxnfc info;
538 size_t info_size = sizeof(info);
539 const struct ethtool_ops *ops = dev->ethtool_ops;
541 void *rule_buf = NULL;
546 /* struct ethtool_rxnfc was originally defined for
547 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
548 * members. User-space might still be using that
550 if (cmd == ETHTOOL_GRXFH)
551 info_size = (offsetof(struct ethtool_rxnfc, data) +
554 if (copy_from_user(&info, useraddr, info_size))
557 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
558 if (info.rule_cnt > 0) {
559 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
560 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
567 ret = ops->get_rxnfc(dev, &info, rule_buf);
572 if (copy_to_user(useraddr, &info, info_size))
576 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
577 if (copy_to_user(useraddr, rule_buf,
578 info.rule_cnt * sizeof(u32)))
589 static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
590 struct ethtool_rxnfc *rx_rings,
595 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
598 /* Validate ring indices */
599 for (i = 0; i < size; i++)
600 if (indir[i] >= rx_rings->data)
606 u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
608 void netdev_rss_key_fill(void *buffer, size_t len)
610 BUG_ON(len > sizeof(netdev_rss_key));
611 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
612 memcpy(buffer, netdev_rss_key, len);
614 EXPORT_SYMBOL(netdev_rss_key_fill);
616 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
617 void __user *useraddr)
619 u32 user_size, dev_size;
623 if (!dev->ethtool_ops->get_rxfh_indir_size ||
624 !dev->ethtool_ops->get_rxfh)
626 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
630 if (copy_from_user(&user_size,
631 useraddr + offsetof(struct ethtool_rxfh_indir, size),
635 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
636 &dev_size, sizeof(dev_size)))
639 /* If the user buffer size is 0, this is just a query for the
640 * device table size. Otherwise, if it's smaller than the
641 * device table size it's an error.
643 if (user_size < dev_size)
644 return user_size == 0 ? 0 : -EINVAL;
646 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
650 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
654 if (copy_to_user(useraddr +
655 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
656 indir, dev_size * sizeof(indir[0])))
664 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
665 void __user *useraddr)
667 struct ethtool_rxnfc rx_rings;
668 u32 user_size, dev_size, i;
670 const struct ethtool_ops *ops = dev->ethtool_ops;
672 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
674 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
678 dev_size = ops->get_rxfh_indir_size(dev);
682 if (copy_from_user(&user_size,
683 useraddr + offsetof(struct ethtool_rxfh_indir, size),
687 if (user_size != 0 && user_size != dev_size)
690 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
694 rx_rings.cmd = ETHTOOL_GRXRINGS;
695 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
699 if (user_size == 0) {
700 for (i = 0; i < dev_size; i++)
701 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
703 ret = ethtool_copy_validate_indir(indir,
704 useraddr + ringidx_offset,
711 ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE);
718 static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
719 void __user *useraddr)
722 const struct ethtool_ops *ops = dev->ethtool_ops;
723 u32 user_indir_size, user_key_size;
724 u32 dev_indir_size = 0, dev_key_size = 0;
725 struct ethtool_rxfh rxfh;
736 if (ops->get_rxfh_indir_size)
737 dev_indir_size = ops->get_rxfh_indir_size(dev);
738 if (ops->get_rxfh_key_size)
739 dev_key_size = ops->get_rxfh_key_size(dev);
741 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
743 user_indir_size = rxfh.indir_size;
744 user_key_size = rxfh.key_size;
746 /* Check that reserved fields are 0 for now */
747 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
748 rxfh.rsvd8[2] || rxfh.rsvd32)
751 rxfh.indir_size = dev_indir_size;
752 rxfh.key_size = dev_key_size;
753 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
756 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
757 (user_key_size && (user_key_size != dev_key_size)))
760 indir_bytes = user_indir_size * sizeof(indir[0]);
761 total_size = indir_bytes + user_key_size;
762 rss_config = kzalloc(total_size, GFP_USER);
767 indir = (u32 *)rss_config;
770 hkey = rss_config + indir_bytes;
772 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc);
776 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc),
777 &dev_hfunc, sizeof(rxfh.hfunc))) {
779 } else if (copy_to_user(useraddr +
780 offsetof(struct ethtool_rxfh, rss_config[0]),
781 rss_config, total_size)) {
790 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
791 void __user *useraddr)
794 const struct ethtool_ops *ops = dev->ethtool_ops;
795 struct ethtool_rxnfc rx_rings;
796 struct ethtool_rxfh rxfh;
797 u32 dev_indir_size = 0, dev_key_size = 0, i;
798 u32 *indir = NULL, indir_bytes = 0;
801 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
803 if (!ops->get_rxnfc || !ops->set_rxfh)
806 if (ops->get_rxfh_indir_size)
807 dev_indir_size = ops->get_rxfh_indir_size(dev);
808 if (ops->get_rxfh_key_size)
809 dev_key_size = ops->get_rxfh_key_size(dev);
811 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
814 /* Check that reserved fields are 0 for now */
815 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
816 rxfh.rsvd8[2] || rxfh.rsvd32)
819 /* If either indir, hash key or function is valid, proceed further.
820 * Must request at least one change: indir size, hash key or function.
822 if ((rxfh.indir_size &&
823 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
824 rxfh.indir_size != dev_indir_size) ||
825 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
826 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
827 rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
830 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
831 indir_bytes = dev_indir_size * sizeof(indir[0]);
833 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
837 rx_rings.cmd = ETHTOOL_GRXRINGS;
838 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
842 /* rxfh.indir_size == 0 means reset the indir table to default.
843 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
845 if (rxfh.indir_size &&
846 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
847 indir = (u32 *)rss_config;
848 ret = ethtool_copy_validate_indir(indir,
849 useraddr + rss_cfg_offset,
854 } else if (rxfh.indir_size == 0) {
855 indir = (u32 *)rss_config;
856 for (i = 0; i < dev_indir_size; i++)
857 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
861 hkey = rss_config + indir_bytes;
862 if (copy_from_user(hkey,
863 useraddr + rss_cfg_offset + indir_bytes,
870 ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc);
877 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
879 struct ethtool_regs regs;
880 const struct ethtool_ops *ops = dev->ethtool_ops;
884 if (!ops->get_regs || !ops->get_regs_len)
887 if (copy_from_user(®s, useraddr, sizeof(regs)))
890 reglen = ops->get_regs_len(dev);
894 if (regs.len > reglen)
899 regbuf = vzalloc(reglen);
904 if (regs.len < reglen)
907 ops->get_regs(dev, ®s, regbuf);
910 if (copy_to_user(useraddr, ®s, sizeof(regs)))
912 useraddr += offsetof(struct ethtool_regs, data);
913 if (copy_to_user(useraddr, regbuf, reglen))
922 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
924 struct ethtool_value reset;
927 if (!dev->ethtool_ops->reset)
930 if (copy_from_user(&reset, useraddr, sizeof(reset)))
933 ret = dev->ethtool_ops->reset(dev, &reset.data);
937 if (copy_to_user(useraddr, &reset, sizeof(reset)))
942 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
944 struct ethtool_wolinfo wol;
946 if (!dev->ethtool_ops->get_wol)
949 memset(&wol, 0, sizeof(struct ethtool_wolinfo));
950 wol.cmd = ETHTOOL_GWOL;
951 dev->ethtool_ops->get_wol(dev, &wol);
953 if (copy_to_user(useraddr, &wol, sizeof(wol)))
958 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
960 struct ethtool_wolinfo wol;
962 if (!dev->ethtool_ops->set_wol)
965 if (copy_from_user(&wol, useraddr, sizeof(wol)))
968 return dev->ethtool_ops->set_wol(dev, &wol);
971 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
973 struct ethtool_eee edata;
976 if (!dev->ethtool_ops->get_eee)
979 memset(&edata, 0, sizeof(struct ethtool_eee));
980 edata.cmd = ETHTOOL_GEEE;
981 rc = dev->ethtool_ops->get_eee(dev, &edata);
986 if (copy_to_user(useraddr, &edata, sizeof(edata)))
992 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
994 struct ethtool_eee edata;
996 if (!dev->ethtool_ops->set_eee)
999 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1002 return dev->ethtool_ops->set_eee(dev, &edata);
1005 static int ethtool_nway_reset(struct net_device *dev)
1007 if (!dev->ethtool_ops->nway_reset)
1010 return dev->ethtool_ops->nway_reset(dev);
1013 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
1015 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
1017 if (!dev->ethtool_ops->get_link)
1020 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
1022 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1027 static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
1028 int (*getter)(struct net_device *,
1029 struct ethtool_eeprom *, u8 *),
1032 struct ethtool_eeprom eeprom;
1033 void __user *userbuf = useraddr + sizeof(eeprom);
1034 u32 bytes_remaining;
1038 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1041 /* Check for wrap and zero */
1042 if (eeprom.offset + eeprom.len <= eeprom.offset)
1045 /* Check for exceeding total eeprom len */
1046 if (eeprom.offset + eeprom.len > total_len)
1049 data = kmalloc(PAGE_SIZE, GFP_USER);
1053 bytes_remaining = eeprom.len;
1054 while (bytes_remaining > 0) {
1055 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1057 ret = getter(dev, &eeprom, data);
1060 if (copy_to_user(userbuf, data, eeprom.len)) {
1064 userbuf += eeprom.len;
1065 eeprom.offset += eeprom.len;
1066 bytes_remaining -= eeprom.len;
1069 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1070 eeprom.offset -= eeprom.len;
1071 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1078 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1080 const struct ethtool_ops *ops = dev->ethtool_ops;
1082 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1083 !ops->get_eeprom_len(dev))
1086 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1087 ops->get_eeprom_len(dev));
1090 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1092 struct ethtool_eeprom eeprom;
1093 const struct ethtool_ops *ops = dev->ethtool_ops;
1094 void __user *userbuf = useraddr + sizeof(eeprom);
1095 u32 bytes_remaining;
1099 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1100 !ops->get_eeprom_len(dev))
1103 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1106 /* Check for wrap and zero */
1107 if (eeprom.offset + eeprom.len <= eeprom.offset)
1110 /* Check for exceeding total eeprom len */
1111 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1114 data = kmalloc(PAGE_SIZE, GFP_USER);
1118 bytes_remaining = eeprom.len;
1119 while (bytes_remaining > 0) {
1120 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1122 if (copy_from_user(data, userbuf, eeprom.len)) {
1126 ret = ops->set_eeprom(dev, &eeprom, data);
1129 userbuf += eeprom.len;
1130 eeprom.offset += eeprom.len;
1131 bytes_remaining -= eeprom.len;
1138 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1139 void __user *useraddr)
1141 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1143 if (!dev->ethtool_ops->get_coalesce)
1146 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1148 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1153 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1154 void __user *useraddr)
1156 struct ethtool_coalesce coalesce;
1158 if (!dev->ethtool_ops->set_coalesce)
1161 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1164 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1167 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1169 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1171 if (!dev->ethtool_ops->get_ringparam)
1174 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1176 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1181 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1183 struct ethtool_ringparam ringparam;
1185 if (!dev->ethtool_ops->set_ringparam)
1188 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1191 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1194 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1195 void __user *useraddr)
1197 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1199 if (!dev->ethtool_ops->get_channels)
1202 dev->ethtool_ops->get_channels(dev, &channels);
1204 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1209 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1210 void __user *useraddr)
1212 struct ethtool_channels channels;
1214 if (!dev->ethtool_ops->set_channels)
1217 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1220 return dev->ethtool_ops->set_channels(dev, &channels);
1223 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1225 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1227 if (!dev->ethtool_ops->get_pauseparam)
1230 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1232 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1237 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1239 struct ethtool_pauseparam pauseparam;
1241 if (!dev->ethtool_ops->set_pauseparam)
1244 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1247 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1250 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1252 struct ethtool_test test;
1253 const struct ethtool_ops *ops = dev->ethtool_ops;
1257 if (!ops->self_test || !ops->get_sset_count)
1260 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1263 WARN_ON(test_len == 0);
1265 if (copy_from_user(&test, useraddr, sizeof(test)))
1268 test.len = test_len;
1269 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1273 ops->self_test(dev, &test, data);
1276 if (copy_to_user(useraddr, &test, sizeof(test)))
1278 useraddr += sizeof(test);
1279 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1288 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1290 struct ethtool_gstrings gstrings;
1294 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1297 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1304 data = kcalloc(gstrings.len, ETH_GSTRING_LEN, GFP_USER);
1308 __ethtool_get_strings(dev, gstrings.string_set, data);
1314 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1316 useraddr += sizeof(gstrings);
1318 copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1327 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1329 struct ethtool_value id;
1331 const struct ethtool_ops *ops = dev->ethtool_ops;
1334 if (!ops->set_phys_id)
1340 if (copy_from_user(&id, useraddr, sizeof(id)))
1343 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1347 /* Drop the RTNL lock while waiting, but prevent reentry or
1348 * removal of the device.
1355 /* Driver will handle this itself */
1356 schedule_timeout_interruptible(
1357 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1359 /* Driver expects to be called at twice the frequency in rc */
1360 int n = rc * 2, i, interval = HZ / n;
1362 /* Count down seconds */
1364 /* Count down iterations per second */
1368 rc = ops->set_phys_id(dev,
1369 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1373 schedule_timeout_interruptible(interval);
1374 } while (!signal_pending(current) && --i != 0);
1375 } while (!signal_pending(current) &&
1376 (id.data == 0 || --id.data != 0));
1383 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1387 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1389 struct ethtool_stats stats;
1390 const struct ethtool_ops *ops = dev->ethtool_ops;
1394 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1397 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1400 WARN_ON(n_stats == 0);
1402 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1405 stats.n_stats = n_stats;
1407 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1411 ops->get_ethtool_stats(dev, &stats, data);
1417 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1419 useraddr += sizeof(stats);
1420 if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64)))
1429 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1431 struct ethtool_perm_addr epaddr;
1433 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1436 if (epaddr.size < dev->addr_len)
1438 epaddr.size = dev->addr_len;
1440 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1442 useraddr += sizeof(epaddr);
1443 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1448 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1449 u32 cmd, u32 (*actor)(struct net_device *))
1451 struct ethtool_value edata = { .cmd = cmd };
1456 edata.data = actor(dev);
1458 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1463 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1464 void (*actor)(struct net_device *, u32))
1466 struct ethtool_value edata;
1471 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1474 actor(dev, edata.data);
1478 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1479 int (*actor)(struct net_device *, u32))
1481 struct ethtool_value edata;
1486 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1489 return actor(dev, edata.data);
1492 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1493 char __user *useraddr)
1495 struct ethtool_flash efl;
1497 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1500 if (!dev->ethtool_ops->flash_device)
1503 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1505 return dev->ethtool_ops->flash_device(dev, &efl);
1508 static int ethtool_set_dump(struct net_device *dev,
1509 void __user *useraddr)
1511 struct ethtool_dump dump;
1513 if (!dev->ethtool_ops->set_dump)
1516 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1519 return dev->ethtool_ops->set_dump(dev, &dump);
1522 static int ethtool_get_dump_flag(struct net_device *dev,
1523 void __user *useraddr)
1526 struct ethtool_dump dump;
1527 const struct ethtool_ops *ops = dev->ethtool_ops;
1529 if (!ops->get_dump_flag)
1532 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1535 ret = ops->get_dump_flag(dev, &dump);
1539 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1544 static int ethtool_get_dump_data(struct net_device *dev,
1545 void __user *useraddr)
1549 struct ethtool_dump dump, tmp;
1550 const struct ethtool_ops *ops = dev->ethtool_ops;
1553 if (!ops->get_dump_data || !ops->get_dump_flag)
1556 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1559 memset(&tmp, 0, sizeof(tmp));
1560 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1561 ret = ops->get_dump_flag(dev, &tmp);
1565 len = min(tmp.len, dump.len);
1569 /* Don't ever let the driver think there's more space available
1570 * than it requested with .get_dump_flag().
1574 /* Always allocate enough space to hold the whole thing so that the
1575 * driver does not need to check the length and bother with partial
1578 data = vzalloc(tmp.len);
1581 ret = ops->get_dump_data(dev, &dump, data);
1585 /* There are two sane possibilities:
1586 * 1. The driver's .get_dump_data() does not touch dump.len.
1587 * 2. Or it may set dump.len to how much it really writes, which
1588 * should be tmp.len (or len if it can do a partial dump).
1589 * In any case respond to userspace with the actual length of data
1592 WARN_ON(dump.len != len && dump.len != tmp.len);
1595 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1599 useraddr += offsetof(struct ethtool_dump, data);
1600 if (copy_to_user(useraddr, data, len))
1607 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1610 struct ethtool_ts_info info;
1611 const struct ethtool_ops *ops = dev->ethtool_ops;
1612 struct phy_device *phydev = dev->phydev;
1614 memset(&info, 0, sizeof(info));
1615 info.cmd = ETHTOOL_GET_TS_INFO;
1617 if (phydev && phydev->drv && phydev->drv->ts_info) {
1618 err = phydev->drv->ts_info(phydev, &info);
1619 } else if (ops->get_ts_info) {
1620 err = ops->get_ts_info(dev, &info);
1622 info.so_timestamping =
1623 SOF_TIMESTAMPING_RX_SOFTWARE |
1624 SOF_TIMESTAMPING_SOFTWARE;
1625 info.phc_index = -1;
1631 if (copy_to_user(useraddr, &info, sizeof(info)))
1637 static int __ethtool_get_module_info(struct net_device *dev,
1638 struct ethtool_modinfo *modinfo)
1640 const struct ethtool_ops *ops = dev->ethtool_ops;
1641 struct phy_device *phydev = dev->phydev;
1643 if (phydev && phydev->drv && phydev->drv->module_info)
1644 return phydev->drv->module_info(phydev, modinfo);
1646 if (ops->get_module_info)
1647 return ops->get_module_info(dev, modinfo);
1652 static int ethtool_get_module_info(struct net_device *dev,
1653 void __user *useraddr)
1656 struct ethtool_modinfo modinfo;
1658 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1661 ret = __ethtool_get_module_info(dev, &modinfo);
1665 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1671 static int __ethtool_get_module_eeprom(struct net_device *dev,
1672 struct ethtool_eeprom *ee, u8 *data)
1674 const struct ethtool_ops *ops = dev->ethtool_ops;
1675 struct phy_device *phydev = dev->phydev;
1677 if (phydev && phydev->drv && phydev->drv->module_eeprom)
1678 return phydev->drv->module_eeprom(phydev, ee, data);
1680 if (ops->get_module_eeprom)
1681 return ops->get_module_eeprom(dev, ee, data);
1686 static int ethtool_get_module_eeprom(struct net_device *dev,
1687 void __user *useraddr)
1690 struct ethtool_modinfo modinfo;
1692 ret = __ethtool_get_module_info(dev, &modinfo);
1696 return ethtool_get_any_eeprom(dev, useraddr,
1697 __ethtool_get_module_eeprom,
1698 modinfo.eeprom_len);
1701 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1704 case ETHTOOL_RX_COPYBREAK:
1705 case ETHTOOL_TX_COPYBREAK:
1706 if (tuna->len != sizeof(u32) ||
1707 tuna->type_id != ETHTOOL_TUNABLE_U32)
1717 static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1720 struct ethtool_tunable tuna;
1721 const struct ethtool_ops *ops = dev->ethtool_ops;
1724 if (!ops->get_tunable)
1726 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1728 ret = ethtool_tunable_valid(&tuna);
1731 data = kmalloc(tuna.len, GFP_USER);
1734 ret = ops->get_tunable(dev, &tuna, data);
1737 useraddr += sizeof(tuna);
1739 if (copy_to_user(useraddr, data, tuna.len))
1748 static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1751 struct ethtool_tunable tuna;
1752 const struct ethtool_ops *ops = dev->ethtool_ops;
1755 if (!ops->set_tunable)
1757 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1759 ret = ethtool_tunable_valid(&tuna);
1762 data = kmalloc(tuna.len, GFP_USER);
1765 useraddr += sizeof(tuna);
1767 if (copy_from_user(data, useraddr, tuna.len))
1769 ret = ops->set_tunable(dev, &tuna, data);
1776 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
1778 int dev_ethtool(struct net *net, struct ifreq *ifr)
1780 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1781 void __user *useraddr = ifr->ifr_data;
1784 netdev_features_t old_features;
1786 if (!dev || !netif_device_present(dev))
1789 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1792 /* Allow some commands to be done by anyone */
1795 case ETHTOOL_GDRVINFO:
1796 case ETHTOOL_GMSGLVL:
1798 case ETHTOOL_GCOALESCE:
1799 case ETHTOOL_GRINGPARAM:
1800 case ETHTOOL_GPAUSEPARAM:
1801 case ETHTOOL_GRXCSUM:
1802 case ETHTOOL_GTXCSUM:
1804 case ETHTOOL_GSSET_INFO:
1805 case ETHTOOL_GSTRINGS:
1806 case ETHTOOL_GSTATS:
1808 case ETHTOOL_GPERMADDR:
1812 case ETHTOOL_GFLAGS:
1813 case ETHTOOL_GPFLAGS:
1815 case ETHTOOL_GRXRINGS:
1816 case ETHTOOL_GRXCLSRLCNT:
1817 case ETHTOOL_GRXCLSRULE:
1818 case ETHTOOL_GRXCLSRLALL:
1819 case ETHTOOL_GRXFHINDIR:
1821 case ETHTOOL_GFEATURES:
1822 case ETHTOOL_GCHANNELS:
1823 case ETHTOOL_GET_TS_INFO:
1825 case ETHTOOL_GTUNABLE:
1828 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1832 if (dev->ethtool_ops->begin) {
1833 rc = dev->ethtool_ops->begin(dev);
1837 old_features = dev->features;
1841 rc = ethtool_get_settings(dev, useraddr);
1844 rc = ethtool_set_settings(dev, useraddr);
1846 case ETHTOOL_GDRVINFO:
1847 rc = ethtool_get_drvinfo(dev, useraddr);
1850 rc = ethtool_get_regs(dev, useraddr);
1853 rc = ethtool_get_wol(dev, useraddr);
1856 rc = ethtool_set_wol(dev, useraddr);
1858 case ETHTOOL_GMSGLVL:
1859 rc = ethtool_get_value(dev, useraddr, ethcmd,
1860 dev->ethtool_ops->get_msglevel);
1862 case ETHTOOL_SMSGLVL:
1863 rc = ethtool_set_value_void(dev, useraddr,
1864 dev->ethtool_ops->set_msglevel);
1867 rc = ethtool_get_eee(dev, useraddr);
1870 rc = ethtool_set_eee(dev, useraddr);
1872 case ETHTOOL_NWAY_RST:
1873 rc = ethtool_nway_reset(dev);
1876 rc = ethtool_get_link(dev, useraddr);
1878 case ETHTOOL_GEEPROM:
1879 rc = ethtool_get_eeprom(dev, useraddr);
1881 case ETHTOOL_SEEPROM:
1882 rc = ethtool_set_eeprom(dev, useraddr);
1884 case ETHTOOL_GCOALESCE:
1885 rc = ethtool_get_coalesce(dev, useraddr);
1887 case ETHTOOL_SCOALESCE:
1888 rc = ethtool_set_coalesce(dev, useraddr);
1890 case ETHTOOL_GRINGPARAM:
1891 rc = ethtool_get_ringparam(dev, useraddr);
1893 case ETHTOOL_SRINGPARAM:
1894 rc = ethtool_set_ringparam(dev, useraddr);
1896 case ETHTOOL_GPAUSEPARAM:
1897 rc = ethtool_get_pauseparam(dev, useraddr);
1899 case ETHTOOL_SPAUSEPARAM:
1900 rc = ethtool_set_pauseparam(dev, useraddr);
1903 rc = ethtool_self_test(dev, useraddr);
1905 case ETHTOOL_GSTRINGS:
1906 rc = ethtool_get_strings(dev, useraddr);
1908 case ETHTOOL_PHYS_ID:
1909 rc = ethtool_phys_id(dev, useraddr);
1911 case ETHTOOL_GSTATS:
1912 rc = ethtool_get_stats(dev, useraddr);
1914 case ETHTOOL_GPERMADDR:
1915 rc = ethtool_get_perm_addr(dev, useraddr);
1917 case ETHTOOL_GFLAGS:
1918 rc = ethtool_get_value(dev, useraddr, ethcmd,
1919 __ethtool_get_flags);
1921 case ETHTOOL_SFLAGS:
1922 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1924 case ETHTOOL_GPFLAGS:
1925 rc = ethtool_get_value(dev, useraddr, ethcmd,
1926 dev->ethtool_ops->get_priv_flags);
1928 case ETHTOOL_SPFLAGS:
1929 rc = ethtool_set_value(dev, useraddr,
1930 dev->ethtool_ops->set_priv_flags);
1933 case ETHTOOL_GRXRINGS:
1934 case ETHTOOL_GRXCLSRLCNT:
1935 case ETHTOOL_GRXCLSRULE:
1936 case ETHTOOL_GRXCLSRLALL:
1937 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1940 case ETHTOOL_SRXCLSRLDEL:
1941 case ETHTOOL_SRXCLSRLINS:
1942 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1944 case ETHTOOL_FLASHDEV:
1945 rc = ethtool_flash_device(dev, useraddr);
1948 rc = ethtool_reset(dev, useraddr);
1950 case ETHTOOL_GSSET_INFO:
1951 rc = ethtool_get_sset_info(dev, useraddr);
1953 case ETHTOOL_GRXFHINDIR:
1954 rc = ethtool_get_rxfh_indir(dev, useraddr);
1956 case ETHTOOL_SRXFHINDIR:
1957 rc = ethtool_set_rxfh_indir(dev, useraddr);
1960 rc = ethtool_get_rxfh(dev, useraddr);
1963 rc = ethtool_set_rxfh(dev, useraddr);
1965 case ETHTOOL_GFEATURES:
1966 rc = ethtool_get_features(dev, useraddr);
1968 case ETHTOOL_SFEATURES:
1969 rc = ethtool_set_features(dev, useraddr);
1971 case ETHTOOL_GTXCSUM:
1972 case ETHTOOL_GRXCSUM:
1978 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1980 case ETHTOOL_STXCSUM:
1981 case ETHTOOL_SRXCSUM:
1987 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1989 case ETHTOOL_GCHANNELS:
1990 rc = ethtool_get_channels(dev, useraddr);
1992 case ETHTOOL_SCHANNELS:
1993 rc = ethtool_set_channels(dev, useraddr);
1995 case ETHTOOL_SET_DUMP:
1996 rc = ethtool_set_dump(dev, useraddr);
1998 case ETHTOOL_GET_DUMP_FLAG:
1999 rc = ethtool_get_dump_flag(dev, useraddr);
2001 case ETHTOOL_GET_DUMP_DATA:
2002 rc = ethtool_get_dump_data(dev, useraddr);
2004 case ETHTOOL_GET_TS_INFO:
2005 rc = ethtool_get_ts_info(dev, useraddr);
2007 case ETHTOOL_GMODULEINFO:
2008 rc = ethtool_get_module_info(dev, useraddr);
2010 case ETHTOOL_GMODULEEEPROM:
2011 rc = ethtool_get_module_eeprom(dev, useraddr);
2013 case ETHTOOL_GTUNABLE:
2014 rc = ethtool_get_tunable(dev, useraddr);
2016 case ETHTOOL_STUNABLE:
2017 rc = ethtool_set_tunable(dev, useraddr);
2023 if (dev->ethtool_ops->complete)
2024 dev->ethtool_ops->complete(dev);
2026 if (old_features != dev->features)
2027 netdev_features_change(dev);