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",
101 [NETIF_F_HW_SWITCH_OFFLOAD_BIT] = "hw-switch-offload",
105 rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = {
106 [ETH_RSS_HASH_TOP_BIT] = "toeplitz",
107 [ETH_RSS_HASH_XOR_BIT] = "xor",
110 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
112 struct ethtool_gfeatures cmd = {
113 .cmd = ETHTOOL_GFEATURES,
114 .size = ETHTOOL_DEV_FEATURE_WORDS,
116 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
117 u32 __user *sizeaddr;
121 /* in case feature bits run out again */
122 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
124 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
125 features[i].available = (u32)(dev->hw_features >> (32 * i));
126 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
127 features[i].active = (u32)(dev->features >> (32 * i));
128 features[i].never_changed =
129 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
132 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
133 if (get_user(copy_size, sizeaddr))
136 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
137 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
139 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
141 useraddr += sizeof(cmd);
142 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
148 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
150 struct ethtool_sfeatures cmd;
151 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
152 netdev_features_t wanted = 0, valid = 0;
155 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
157 useraddr += sizeof(cmd);
159 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
162 if (copy_from_user(features, useraddr, sizeof(features)))
165 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
166 valid |= (netdev_features_t)features[i].valid << (32 * i);
167 wanted |= (netdev_features_t)features[i].requested << (32 * i);
170 if (valid & ~NETIF_F_ETHTOOL_BITS)
173 if (valid & ~dev->hw_features) {
174 valid &= dev->hw_features;
175 ret |= ETHTOOL_F_UNSUPPORTED;
178 dev->wanted_features &= ~valid;
179 dev->wanted_features |= wanted & valid;
180 __netdev_update_features(dev);
182 if ((dev->wanted_features ^ dev->features) & valid)
183 ret |= ETHTOOL_F_WISH;
188 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
190 const struct ethtool_ops *ops = dev->ethtool_ops;
192 if (sset == ETH_SS_FEATURES)
193 return ARRAY_SIZE(netdev_features_strings);
195 if (sset == ETH_SS_RSS_HASH_FUNCS)
196 return ARRAY_SIZE(rss_hash_func_strings);
198 if (ops->get_sset_count && ops->get_strings)
199 return ops->get_sset_count(dev, sset);
204 static void __ethtool_get_strings(struct net_device *dev,
205 u32 stringset, u8 *data)
207 const struct ethtool_ops *ops = dev->ethtool_ops;
209 if (stringset == ETH_SS_FEATURES)
210 memcpy(data, netdev_features_strings,
211 sizeof(netdev_features_strings));
212 else if (stringset == ETH_SS_RSS_HASH_FUNCS)
213 memcpy(data, rss_hash_func_strings,
214 sizeof(rss_hash_func_strings));
216 /* ops->get_strings is valid because checked earlier */
217 ops->get_strings(dev, stringset, data);
220 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
222 /* feature masks of legacy discrete ethtool ops */
225 case ETHTOOL_GTXCSUM:
226 case ETHTOOL_STXCSUM:
227 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
228 case ETHTOOL_GRXCSUM:
229 case ETHTOOL_SRXCSUM:
230 return NETIF_F_RXCSUM;
236 return NETIF_F_ALL_TSO;
251 static int ethtool_get_one_feature(struct net_device *dev,
252 char __user *useraddr, u32 ethcmd)
254 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
255 struct ethtool_value edata = {
257 .data = !!(dev->features & mask),
260 if (copy_to_user(useraddr, &edata, sizeof(edata)))
265 static int ethtool_set_one_feature(struct net_device *dev,
266 void __user *useraddr, u32 ethcmd)
268 struct ethtool_value edata;
269 netdev_features_t mask;
271 if (copy_from_user(&edata, useraddr, sizeof(edata)))
274 mask = ethtool_get_feature_mask(ethcmd);
275 mask &= dev->hw_features;
280 dev->wanted_features |= mask;
282 dev->wanted_features &= ~mask;
284 __netdev_update_features(dev);
289 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
290 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
291 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
292 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
295 static u32 __ethtool_get_flags(struct net_device *dev)
299 if (dev->features & NETIF_F_LRO)
300 flags |= ETH_FLAG_LRO;
301 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
302 flags |= ETH_FLAG_RXVLAN;
303 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
304 flags |= ETH_FLAG_TXVLAN;
305 if (dev->features & NETIF_F_NTUPLE)
306 flags |= ETH_FLAG_NTUPLE;
307 if (dev->features & NETIF_F_RXHASH)
308 flags |= ETH_FLAG_RXHASH;
313 static int __ethtool_set_flags(struct net_device *dev, u32 data)
315 netdev_features_t features = 0, changed;
317 if (data & ~ETH_ALL_FLAGS)
320 if (data & ETH_FLAG_LRO)
321 features |= NETIF_F_LRO;
322 if (data & ETH_FLAG_RXVLAN)
323 features |= NETIF_F_HW_VLAN_CTAG_RX;
324 if (data & ETH_FLAG_TXVLAN)
325 features |= NETIF_F_HW_VLAN_CTAG_TX;
326 if (data & ETH_FLAG_NTUPLE)
327 features |= NETIF_F_NTUPLE;
328 if (data & ETH_FLAG_RXHASH)
329 features |= NETIF_F_RXHASH;
331 /* allow changing only bits set in hw_features */
332 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
333 if (changed & ~dev->hw_features)
334 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
336 dev->wanted_features =
337 (dev->wanted_features & ~changed) | (features & changed);
339 __netdev_update_features(dev);
344 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
348 if (!dev->ethtool_ops->get_settings)
351 memset(cmd, 0, sizeof(struct ethtool_cmd));
352 cmd->cmd = ETHTOOL_GSET;
353 return dev->ethtool_ops->get_settings(dev, cmd);
355 EXPORT_SYMBOL(__ethtool_get_settings);
357 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
360 struct ethtool_cmd cmd;
362 if (!dev->ethtool_ops->get_settings)
365 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
368 cmd.cmd = ETHTOOL_GSET;
370 err = dev->ethtool_ops->get_settings(dev, &cmd);
374 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
379 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
381 struct ethtool_cmd cmd;
383 if (!dev->ethtool_ops->set_settings)
386 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
389 return dev->ethtool_ops->set_settings(dev, &cmd);
392 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
393 void __user *useraddr)
395 struct ethtool_drvinfo info;
396 const struct ethtool_ops *ops = dev->ethtool_ops;
398 memset(&info, 0, sizeof(info));
399 info.cmd = ETHTOOL_GDRVINFO;
400 if (ops->get_drvinfo) {
401 ops->get_drvinfo(dev, &info);
402 } else if (dev->dev.parent && dev->dev.parent->driver) {
403 strlcpy(info.bus_info, dev_name(dev->dev.parent),
404 sizeof(info.bus_info));
405 strlcpy(info.driver, dev->dev.parent->driver->name,
406 sizeof(info.driver));
412 * this method of obtaining string set info is deprecated;
413 * Use ETHTOOL_GSSET_INFO instead.
415 if (ops->get_sset_count) {
418 rc = ops->get_sset_count(dev, ETH_SS_TEST);
420 info.testinfo_len = rc;
421 rc = ops->get_sset_count(dev, ETH_SS_STATS);
424 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
426 info.n_priv_flags = rc;
428 if (ops->get_regs_len)
429 info.regdump_len = ops->get_regs_len(dev);
430 if (ops->get_eeprom_len)
431 info.eedump_len = ops->get_eeprom_len(dev);
433 if (copy_to_user(useraddr, &info, sizeof(info)))
438 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
439 void __user *useraddr)
441 struct ethtool_sset_info info;
443 int i, idx = 0, n_bits = 0, ret, rc;
444 u32 *info_buf = NULL;
446 if (copy_from_user(&info, useraddr, sizeof(info)))
449 /* store copy of mask, because we zero struct later on */
450 sset_mask = info.sset_mask;
454 /* calculate size of return buffer */
455 n_bits = hweight64(sset_mask);
457 memset(&info, 0, sizeof(info));
458 info.cmd = ETHTOOL_GSSET_INFO;
460 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
465 * fill return buffer based on input bitmask and successful
466 * get_sset_count return
468 for (i = 0; i < 64; i++) {
469 if (!(sset_mask & (1ULL << i)))
472 rc = __ethtool_get_sset_count(dev, i);
474 info.sset_mask |= (1ULL << i);
475 info_buf[idx++] = rc;
480 if (copy_to_user(useraddr, &info, sizeof(info)))
483 useraddr += offsetof(struct ethtool_sset_info, data);
484 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
494 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
495 u32 cmd, void __user *useraddr)
497 struct ethtool_rxnfc info;
498 size_t info_size = sizeof(info);
501 if (!dev->ethtool_ops->set_rxnfc)
504 /* struct ethtool_rxnfc was originally defined for
505 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
506 * members. User-space might still be using that
508 if (cmd == ETHTOOL_SRXFH)
509 info_size = (offsetof(struct ethtool_rxnfc, data) +
512 if (copy_from_user(&info, useraddr, info_size))
515 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
519 if (cmd == ETHTOOL_SRXCLSRLINS &&
520 copy_to_user(useraddr, &info, info_size))
526 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
527 u32 cmd, void __user *useraddr)
529 struct ethtool_rxnfc info;
530 size_t info_size = sizeof(info);
531 const struct ethtool_ops *ops = dev->ethtool_ops;
533 void *rule_buf = NULL;
538 /* struct ethtool_rxnfc was originally defined for
539 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
540 * members. User-space might still be using that
542 if (cmd == ETHTOOL_GRXFH)
543 info_size = (offsetof(struct ethtool_rxnfc, data) +
546 if (copy_from_user(&info, useraddr, info_size))
549 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
550 if (info.rule_cnt > 0) {
551 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
552 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
559 ret = ops->get_rxnfc(dev, &info, rule_buf);
564 if (copy_to_user(useraddr, &info, info_size))
568 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
569 if (copy_to_user(useraddr, rule_buf,
570 info.rule_cnt * sizeof(u32)))
581 static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
582 struct ethtool_rxnfc *rx_rings,
587 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
590 /* Validate ring indices */
591 for (i = 0; i < size; i++)
592 if (indir[i] >= rx_rings->data)
598 u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
600 void netdev_rss_key_fill(void *buffer, size_t len)
602 BUG_ON(len > sizeof(netdev_rss_key));
603 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
604 memcpy(buffer, netdev_rss_key, len);
606 EXPORT_SYMBOL(netdev_rss_key_fill);
608 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
609 void __user *useraddr)
611 u32 user_size, dev_size;
615 if (!dev->ethtool_ops->get_rxfh_indir_size ||
616 !dev->ethtool_ops->get_rxfh)
618 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
622 if (copy_from_user(&user_size,
623 useraddr + offsetof(struct ethtool_rxfh_indir, size),
627 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
628 &dev_size, sizeof(dev_size)))
631 /* If the user buffer size is 0, this is just a query for the
632 * device table size. Otherwise, if it's smaller than the
633 * device table size it's an error.
635 if (user_size < dev_size)
636 return user_size == 0 ? 0 : -EINVAL;
638 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
642 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
646 if (copy_to_user(useraddr +
647 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
648 indir, dev_size * sizeof(indir[0])))
656 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
657 void __user *useraddr)
659 struct ethtool_rxnfc rx_rings;
660 u32 user_size, dev_size, i;
662 const struct ethtool_ops *ops = dev->ethtool_ops;
664 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
666 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
670 dev_size = ops->get_rxfh_indir_size(dev);
674 if (copy_from_user(&user_size,
675 useraddr + offsetof(struct ethtool_rxfh_indir, size),
679 if (user_size != 0 && user_size != dev_size)
682 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
686 rx_rings.cmd = ETHTOOL_GRXRINGS;
687 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
691 if (user_size == 0) {
692 for (i = 0; i < dev_size; i++)
693 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
695 ret = ethtool_copy_validate_indir(indir,
696 useraddr + ringidx_offset,
703 ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE);
710 static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
711 void __user *useraddr)
714 const struct ethtool_ops *ops = dev->ethtool_ops;
715 u32 user_indir_size, user_key_size;
716 u32 dev_indir_size = 0, dev_key_size = 0;
717 struct ethtool_rxfh rxfh;
728 if (ops->get_rxfh_indir_size)
729 dev_indir_size = ops->get_rxfh_indir_size(dev);
730 if (ops->get_rxfh_key_size)
731 dev_key_size = ops->get_rxfh_key_size(dev);
733 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
735 user_indir_size = rxfh.indir_size;
736 user_key_size = rxfh.key_size;
738 /* Check that reserved fields are 0 for now */
739 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
740 rxfh.rsvd8[2] || rxfh.rsvd32)
743 rxfh.indir_size = dev_indir_size;
744 rxfh.key_size = dev_key_size;
745 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
748 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
749 (user_key_size && (user_key_size != dev_key_size)))
752 indir_bytes = user_indir_size * sizeof(indir[0]);
753 total_size = indir_bytes + user_key_size;
754 rss_config = kzalloc(total_size, GFP_USER);
759 indir = (u32 *)rss_config;
762 hkey = rss_config + indir_bytes;
764 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc);
768 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc),
769 &dev_hfunc, sizeof(rxfh.hfunc))) {
771 } else if (copy_to_user(useraddr +
772 offsetof(struct ethtool_rxfh, rss_config[0]),
773 rss_config, total_size)) {
782 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
783 void __user *useraddr)
786 const struct ethtool_ops *ops = dev->ethtool_ops;
787 struct ethtool_rxnfc rx_rings;
788 struct ethtool_rxfh rxfh;
789 u32 dev_indir_size = 0, dev_key_size = 0, i;
790 u32 *indir = NULL, indir_bytes = 0;
793 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
795 if (!ops->get_rxnfc || !ops->set_rxfh)
798 if (ops->get_rxfh_indir_size)
799 dev_indir_size = ops->get_rxfh_indir_size(dev);
800 if (ops->get_rxfh_key_size)
801 dev_key_size = ops->get_rxfh_key_size(dev);
803 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
806 /* Check that reserved fields are 0 for now */
807 if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
808 rxfh.rsvd8[2] || rxfh.rsvd32)
811 /* If either indir, hash key or function is valid, proceed further.
812 * Must request at least one change: indir size, hash key or function.
814 if ((rxfh.indir_size &&
815 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
816 rxfh.indir_size != dev_indir_size) ||
817 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
818 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
819 rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
822 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
823 indir_bytes = dev_indir_size * sizeof(indir[0]);
825 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
829 rx_rings.cmd = ETHTOOL_GRXRINGS;
830 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
834 /* rxfh.indir_size == 0 means reset the indir table to default.
835 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
837 if (rxfh.indir_size &&
838 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
839 indir = (u32 *)rss_config;
840 ret = ethtool_copy_validate_indir(indir,
841 useraddr + rss_cfg_offset,
846 } else if (rxfh.indir_size == 0) {
847 indir = (u32 *)rss_config;
848 for (i = 0; i < dev_indir_size; i++)
849 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
853 hkey = rss_config + indir_bytes;
854 if (copy_from_user(hkey,
855 useraddr + rss_cfg_offset + indir_bytes,
862 ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc);
869 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
871 struct ethtool_regs regs;
872 const struct ethtool_ops *ops = dev->ethtool_ops;
876 if (!ops->get_regs || !ops->get_regs_len)
879 if (copy_from_user(®s, useraddr, sizeof(regs)))
882 reglen = ops->get_regs_len(dev);
883 if (regs.len > reglen)
886 regbuf = vzalloc(reglen);
887 if (reglen && !regbuf)
890 ops->get_regs(dev, ®s, regbuf);
893 if (copy_to_user(useraddr, ®s, sizeof(regs)))
895 useraddr += offsetof(struct ethtool_regs, data);
896 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
905 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
907 struct ethtool_value reset;
910 if (!dev->ethtool_ops->reset)
913 if (copy_from_user(&reset, useraddr, sizeof(reset)))
916 ret = dev->ethtool_ops->reset(dev, &reset.data);
920 if (copy_to_user(useraddr, &reset, sizeof(reset)))
925 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
927 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
929 if (!dev->ethtool_ops->get_wol)
932 dev->ethtool_ops->get_wol(dev, &wol);
934 if (copy_to_user(useraddr, &wol, sizeof(wol)))
939 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
941 struct ethtool_wolinfo wol;
943 if (!dev->ethtool_ops->set_wol)
946 if (copy_from_user(&wol, useraddr, sizeof(wol)))
949 return dev->ethtool_ops->set_wol(dev, &wol);
952 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
954 struct ethtool_eee edata;
957 if (!dev->ethtool_ops->get_eee)
960 memset(&edata, 0, sizeof(struct ethtool_eee));
961 edata.cmd = ETHTOOL_GEEE;
962 rc = dev->ethtool_ops->get_eee(dev, &edata);
967 if (copy_to_user(useraddr, &edata, sizeof(edata)))
973 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
975 struct ethtool_eee edata;
977 if (!dev->ethtool_ops->set_eee)
980 if (copy_from_user(&edata, useraddr, sizeof(edata)))
983 return dev->ethtool_ops->set_eee(dev, &edata);
986 static int ethtool_nway_reset(struct net_device *dev)
988 if (!dev->ethtool_ops->nway_reset)
991 return dev->ethtool_ops->nway_reset(dev);
994 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
996 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
998 if (!dev->ethtool_ops->get_link)
1001 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
1003 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1008 static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
1009 int (*getter)(struct net_device *,
1010 struct ethtool_eeprom *, u8 *),
1013 struct ethtool_eeprom eeprom;
1014 void __user *userbuf = useraddr + sizeof(eeprom);
1015 u32 bytes_remaining;
1019 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1022 /* Check for wrap and zero */
1023 if (eeprom.offset + eeprom.len <= eeprom.offset)
1026 /* Check for exceeding total eeprom len */
1027 if (eeprom.offset + eeprom.len > total_len)
1030 data = kmalloc(PAGE_SIZE, GFP_USER);
1034 bytes_remaining = eeprom.len;
1035 while (bytes_remaining > 0) {
1036 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1038 ret = getter(dev, &eeprom, data);
1041 if (copy_to_user(userbuf, data, eeprom.len)) {
1045 userbuf += eeprom.len;
1046 eeprom.offset += eeprom.len;
1047 bytes_remaining -= eeprom.len;
1050 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1051 eeprom.offset -= eeprom.len;
1052 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1059 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1061 const struct ethtool_ops *ops = dev->ethtool_ops;
1063 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1064 !ops->get_eeprom_len(dev))
1067 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1068 ops->get_eeprom_len(dev));
1071 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1073 struct ethtool_eeprom eeprom;
1074 const struct ethtool_ops *ops = dev->ethtool_ops;
1075 void __user *userbuf = useraddr + sizeof(eeprom);
1076 u32 bytes_remaining;
1080 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1081 !ops->get_eeprom_len(dev))
1084 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1087 /* Check for wrap and zero */
1088 if (eeprom.offset + eeprom.len <= eeprom.offset)
1091 /* Check for exceeding total eeprom len */
1092 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1095 data = kmalloc(PAGE_SIZE, GFP_USER);
1099 bytes_remaining = eeprom.len;
1100 while (bytes_remaining > 0) {
1101 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1103 if (copy_from_user(data, userbuf, eeprom.len)) {
1107 ret = ops->set_eeprom(dev, &eeprom, data);
1110 userbuf += eeprom.len;
1111 eeprom.offset += eeprom.len;
1112 bytes_remaining -= eeprom.len;
1119 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1120 void __user *useraddr)
1122 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1124 if (!dev->ethtool_ops->get_coalesce)
1127 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1129 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1134 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1135 void __user *useraddr)
1137 struct ethtool_coalesce coalesce;
1139 if (!dev->ethtool_ops->set_coalesce)
1142 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1145 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1148 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1150 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1152 if (!dev->ethtool_ops->get_ringparam)
1155 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1157 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1162 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1164 struct ethtool_ringparam ringparam;
1166 if (!dev->ethtool_ops->set_ringparam)
1169 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1172 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1175 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1176 void __user *useraddr)
1178 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1180 if (!dev->ethtool_ops->get_channels)
1183 dev->ethtool_ops->get_channels(dev, &channels);
1185 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1190 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1191 void __user *useraddr)
1193 struct ethtool_channels channels;
1195 if (!dev->ethtool_ops->set_channels)
1198 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1201 return dev->ethtool_ops->set_channels(dev, &channels);
1204 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1206 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1208 if (!dev->ethtool_ops->get_pauseparam)
1211 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1213 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1218 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1220 struct ethtool_pauseparam pauseparam;
1222 if (!dev->ethtool_ops->set_pauseparam)
1225 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1228 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1231 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1233 struct ethtool_test test;
1234 const struct ethtool_ops *ops = dev->ethtool_ops;
1238 if (!ops->self_test || !ops->get_sset_count)
1241 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1244 WARN_ON(test_len == 0);
1246 if (copy_from_user(&test, useraddr, sizeof(test)))
1249 test.len = test_len;
1250 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1254 ops->self_test(dev, &test, data);
1257 if (copy_to_user(useraddr, &test, sizeof(test)))
1259 useraddr += sizeof(test);
1260 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1269 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1271 struct ethtool_gstrings gstrings;
1275 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1278 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1284 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1288 __ethtool_get_strings(dev, gstrings.string_set, data);
1291 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1293 useraddr += sizeof(gstrings);
1294 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1303 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1305 struct ethtool_value id;
1307 const struct ethtool_ops *ops = dev->ethtool_ops;
1310 if (!ops->set_phys_id)
1316 if (copy_from_user(&id, useraddr, sizeof(id)))
1319 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1323 /* Drop the RTNL lock while waiting, but prevent reentry or
1324 * removal of the device.
1331 /* Driver will handle this itself */
1332 schedule_timeout_interruptible(
1333 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1335 /* Driver expects to be called at twice the frequency in rc */
1336 int n = rc * 2, i, interval = HZ / n;
1338 /* Count down seconds */
1340 /* Count down iterations per second */
1344 rc = ops->set_phys_id(dev,
1345 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1349 schedule_timeout_interruptible(interval);
1350 } while (!signal_pending(current) && --i != 0);
1351 } while (!signal_pending(current) &&
1352 (id.data == 0 || --id.data != 0));
1359 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1363 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1365 struct ethtool_stats stats;
1366 const struct ethtool_ops *ops = dev->ethtool_ops;
1370 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1373 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1376 WARN_ON(n_stats == 0);
1378 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1381 stats.n_stats = n_stats;
1382 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1386 ops->get_ethtool_stats(dev, &stats, data);
1389 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1391 useraddr += sizeof(stats);
1392 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1401 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1403 struct ethtool_perm_addr epaddr;
1405 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1408 if (epaddr.size < dev->addr_len)
1410 epaddr.size = dev->addr_len;
1412 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1414 useraddr += sizeof(epaddr);
1415 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1420 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1421 u32 cmd, u32 (*actor)(struct net_device *))
1423 struct ethtool_value edata = { .cmd = cmd };
1428 edata.data = actor(dev);
1430 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1435 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1436 void (*actor)(struct net_device *, u32))
1438 struct ethtool_value edata;
1443 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1446 actor(dev, edata.data);
1450 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1451 int (*actor)(struct net_device *, u32))
1453 struct ethtool_value edata;
1458 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1461 return actor(dev, edata.data);
1464 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1465 char __user *useraddr)
1467 struct ethtool_flash efl;
1469 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1472 if (!dev->ethtool_ops->flash_device)
1475 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1477 return dev->ethtool_ops->flash_device(dev, &efl);
1480 static int ethtool_set_dump(struct net_device *dev,
1481 void __user *useraddr)
1483 struct ethtool_dump dump;
1485 if (!dev->ethtool_ops->set_dump)
1488 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1491 return dev->ethtool_ops->set_dump(dev, &dump);
1494 static int ethtool_get_dump_flag(struct net_device *dev,
1495 void __user *useraddr)
1498 struct ethtool_dump dump;
1499 const struct ethtool_ops *ops = dev->ethtool_ops;
1501 if (!ops->get_dump_flag)
1504 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1507 ret = ops->get_dump_flag(dev, &dump);
1511 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1516 static int ethtool_get_dump_data(struct net_device *dev,
1517 void __user *useraddr)
1521 struct ethtool_dump dump, tmp;
1522 const struct ethtool_ops *ops = dev->ethtool_ops;
1525 if (!ops->get_dump_data || !ops->get_dump_flag)
1528 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1531 memset(&tmp, 0, sizeof(tmp));
1532 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1533 ret = ops->get_dump_flag(dev, &tmp);
1537 len = min(tmp.len, dump.len);
1541 /* Don't ever let the driver think there's more space available
1542 * than it requested with .get_dump_flag().
1546 /* Always allocate enough space to hold the whole thing so that the
1547 * driver does not need to check the length and bother with partial
1550 data = vzalloc(tmp.len);
1553 ret = ops->get_dump_data(dev, &dump, data);
1557 /* There are two sane possibilities:
1558 * 1. The driver's .get_dump_data() does not touch dump.len.
1559 * 2. Or it may set dump.len to how much it really writes, which
1560 * should be tmp.len (or len if it can do a partial dump).
1561 * In any case respond to userspace with the actual length of data
1564 WARN_ON(dump.len != len && dump.len != tmp.len);
1567 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1571 useraddr += offsetof(struct ethtool_dump, data);
1572 if (copy_to_user(useraddr, data, len))
1579 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1582 struct ethtool_ts_info info;
1583 const struct ethtool_ops *ops = dev->ethtool_ops;
1584 struct phy_device *phydev = dev->phydev;
1586 memset(&info, 0, sizeof(info));
1587 info.cmd = ETHTOOL_GET_TS_INFO;
1589 if (phydev && phydev->drv && phydev->drv->ts_info) {
1590 err = phydev->drv->ts_info(phydev, &info);
1591 } else if (ops->get_ts_info) {
1592 err = ops->get_ts_info(dev, &info);
1594 info.so_timestamping =
1595 SOF_TIMESTAMPING_RX_SOFTWARE |
1596 SOF_TIMESTAMPING_SOFTWARE;
1597 info.phc_index = -1;
1603 if (copy_to_user(useraddr, &info, sizeof(info)))
1609 static int __ethtool_get_module_info(struct net_device *dev,
1610 struct ethtool_modinfo *modinfo)
1612 const struct ethtool_ops *ops = dev->ethtool_ops;
1613 struct phy_device *phydev = dev->phydev;
1615 if (phydev && phydev->drv && phydev->drv->module_info)
1616 return phydev->drv->module_info(phydev, modinfo);
1618 if (ops->get_module_info)
1619 return ops->get_module_info(dev, modinfo);
1624 static int ethtool_get_module_info(struct net_device *dev,
1625 void __user *useraddr)
1628 struct ethtool_modinfo modinfo;
1630 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1633 ret = __ethtool_get_module_info(dev, &modinfo);
1637 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1643 static int __ethtool_get_module_eeprom(struct net_device *dev,
1644 struct ethtool_eeprom *ee, u8 *data)
1646 const struct ethtool_ops *ops = dev->ethtool_ops;
1647 struct phy_device *phydev = dev->phydev;
1649 if (phydev && phydev->drv && phydev->drv->module_eeprom)
1650 return phydev->drv->module_eeprom(phydev, ee, data);
1652 if (ops->get_module_eeprom)
1653 return ops->get_module_eeprom(dev, ee, data);
1658 static int ethtool_get_module_eeprom(struct net_device *dev,
1659 void __user *useraddr)
1662 struct ethtool_modinfo modinfo;
1664 ret = __ethtool_get_module_info(dev, &modinfo);
1668 return ethtool_get_any_eeprom(dev, useraddr,
1669 __ethtool_get_module_eeprom,
1670 modinfo.eeprom_len);
1673 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1676 case ETHTOOL_RX_COPYBREAK:
1677 case ETHTOOL_TX_COPYBREAK:
1678 if (tuna->len != sizeof(u32) ||
1679 tuna->type_id != ETHTOOL_TUNABLE_U32)
1689 static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1692 struct ethtool_tunable tuna;
1693 const struct ethtool_ops *ops = dev->ethtool_ops;
1696 if (!ops->get_tunable)
1698 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1700 ret = ethtool_tunable_valid(&tuna);
1703 data = kmalloc(tuna.len, GFP_USER);
1706 ret = ops->get_tunable(dev, &tuna, data);
1709 useraddr += sizeof(tuna);
1711 if (copy_to_user(useraddr, data, tuna.len))
1720 static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1723 struct ethtool_tunable tuna;
1724 const struct ethtool_ops *ops = dev->ethtool_ops;
1727 if (!ops->set_tunable)
1729 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1731 ret = ethtool_tunable_valid(&tuna);
1734 data = kmalloc(tuna.len, GFP_USER);
1737 useraddr += sizeof(tuna);
1739 if (copy_from_user(data, useraddr, tuna.len))
1741 ret = ops->set_tunable(dev, &tuna, data);
1748 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
1750 int dev_ethtool(struct net *net, struct ifreq *ifr)
1752 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1753 void __user *useraddr = ifr->ifr_data;
1756 netdev_features_t old_features;
1758 if (!dev || !netif_device_present(dev))
1761 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1764 /* Allow some commands to be done by anyone */
1767 case ETHTOOL_GDRVINFO:
1768 case ETHTOOL_GMSGLVL:
1770 case ETHTOOL_GCOALESCE:
1771 case ETHTOOL_GRINGPARAM:
1772 case ETHTOOL_GPAUSEPARAM:
1773 case ETHTOOL_GRXCSUM:
1774 case ETHTOOL_GTXCSUM:
1776 case ETHTOOL_GSSET_INFO:
1777 case ETHTOOL_GSTRINGS:
1778 case ETHTOOL_GSTATS:
1780 case ETHTOOL_GPERMADDR:
1784 case ETHTOOL_GFLAGS:
1785 case ETHTOOL_GPFLAGS:
1787 case ETHTOOL_GRXRINGS:
1788 case ETHTOOL_GRXCLSRLCNT:
1789 case ETHTOOL_GRXCLSRULE:
1790 case ETHTOOL_GRXCLSRLALL:
1791 case ETHTOOL_GRXFHINDIR:
1793 case ETHTOOL_GFEATURES:
1794 case ETHTOOL_GCHANNELS:
1795 case ETHTOOL_GET_TS_INFO:
1797 case ETHTOOL_GTUNABLE:
1800 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1804 if (dev->ethtool_ops->begin) {
1805 rc = dev->ethtool_ops->begin(dev);
1809 old_features = dev->features;
1813 rc = ethtool_get_settings(dev, useraddr);
1816 rc = ethtool_set_settings(dev, useraddr);
1818 case ETHTOOL_GDRVINFO:
1819 rc = ethtool_get_drvinfo(dev, useraddr);
1822 rc = ethtool_get_regs(dev, useraddr);
1825 rc = ethtool_get_wol(dev, useraddr);
1828 rc = ethtool_set_wol(dev, useraddr);
1830 case ETHTOOL_GMSGLVL:
1831 rc = ethtool_get_value(dev, useraddr, ethcmd,
1832 dev->ethtool_ops->get_msglevel);
1834 case ETHTOOL_SMSGLVL:
1835 rc = ethtool_set_value_void(dev, useraddr,
1836 dev->ethtool_ops->set_msglevel);
1839 rc = ethtool_get_eee(dev, useraddr);
1842 rc = ethtool_set_eee(dev, useraddr);
1844 case ETHTOOL_NWAY_RST:
1845 rc = ethtool_nway_reset(dev);
1848 rc = ethtool_get_link(dev, useraddr);
1850 case ETHTOOL_GEEPROM:
1851 rc = ethtool_get_eeprom(dev, useraddr);
1853 case ETHTOOL_SEEPROM:
1854 rc = ethtool_set_eeprom(dev, useraddr);
1856 case ETHTOOL_GCOALESCE:
1857 rc = ethtool_get_coalesce(dev, useraddr);
1859 case ETHTOOL_SCOALESCE:
1860 rc = ethtool_set_coalesce(dev, useraddr);
1862 case ETHTOOL_GRINGPARAM:
1863 rc = ethtool_get_ringparam(dev, useraddr);
1865 case ETHTOOL_SRINGPARAM:
1866 rc = ethtool_set_ringparam(dev, useraddr);
1868 case ETHTOOL_GPAUSEPARAM:
1869 rc = ethtool_get_pauseparam(dev, useraddr);
1871 case ETHTOOL_SPAUSEPARAM:
1872 rc = ethtool_set_pauseparam(dev, useraddr);
1875 rc = ethtool_self_test(dev, useraddr);
1877 case ETHTOOL_GSTRINGS:
1878 rc = ethtool_get_strings(dev, useraddr);
1880 case ETHTOOL_PHYS_ID:
1881 rc = ethtool_phys_id(dev, useraddr);
1883 case ETHTOOL_GSTATS:
1884 rc = ethtool_get_stats(dev, useraddr);
1886 case ETHTOOL_GPERMADDR:
1887 rc = ethtool_get_perm_addr(dev, useraddr);
1889 case ETHTOOL_GFLAGS:
1890 rc = ethtool_get_value(dev, useraddr, ethcmd,
1891 __ethtool_get_flags);
1893 case ETHTOOL_SFLAGS:
1894 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1896 case ETHTOOL_GPFLAGS:
1897 rc = ethtool_get_value(dev, useraddr, ethcmd,
1898 dev->ethtool_ops->get_priv_flags);
1900 case ETHTOOL_SPFLAGS:
1901 rc = ethtool_set_value(dev, useraddr,
1902 dev->ethtool_ops->set_priv_flags);
1905 case ETHTOOL_GRXRINGS:
1906 case ETHTOOL_GRXCLSRLCNT:
1907 case ETHTOOL_GRXCLSRULE:
1908 case ETHTOOL_GRXCLSRLALL:
1909 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1912 case ETHTOOL_SRXCLSRLDEL:
1913 case ETHTOOL_SRXCLSRLINS:
1914 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1916 case ETHTOOL_FLASHDEV:
1917 rc = ethtool_flash_device(dev, useraddr);
1920 rc = ethtool_reset(dev, useraddr);
1922 case ETHTOOL_GSSET_INFO:
1923 rc = ethtool_get_sset_info(dev, useraddr);
1925 case ETHTOOL_GRXFHINDIR:
1926 rc = ethtool_get_rxfh_indir(dev, useraddr);
1928 case ETHTOOL_SRXFHINDIR:
1929 rc = ethtool_set_rxfh_indir(dev, useraddr);
1932 rc = ethtool_get_rxfh(dev, useraddr);
1935 rc = ethtool_set_rxfh(dev, useraddr);
1937 case ETHTOOL_GFEATURES:
1938 rc = ethtool_get_features(dev, useraddr);
1940 case ETHTOOL_SFEATURES:
1941 rc = ethtool_set_features(dev, useraddr);
1943 case ETHTOOL_GTXCSUM:
1944 case ETHTOOL_GRXCSUM:
1950 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1952 case ETHTOOL_STXCSUM:
1953 case ETHTOOL_SRXCSUM:
1959 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1961 case ETHTOOL_GCHANNELS:
1962 rc = ethtool_get_channels(dev, useraddr);
1964 case ETHTOOL_SCHANNELS:
1965 rc = ethtool_set_channels(dev, useraddr);
1967 case ETHTOOL_SET_DUMP:
1968 rc = ethtool_set_dump(dev, useraddr);
1970 case ETHTOOL_GET_DUMP_FLAG:
1971 rc = ethtool_get_dump_flag(dev, useraddr);
1973 case ETHTOOL_GET_DUMP_DATA:
1974 rc = ethtool_get_dump_data(dev, useraddr);
1976 case ETHTOOL_GET_TS_INFO:
1977 rc = ethtool_get_ts_info(dev, useraddr);
1979 case ETHTOOL_GMODULEINFO:
1980 rc = ethtool_get_module_info(dev, useraddr);
1982 case ETHTOOL_GMODULEEEPROM:
1983 rc = ethtool_get_module_eeprom(dev, useraddr);
1985 case ETHTOOL_GTUNABLE:
1986 rc = ethtool_get_tunable(dev, useraddr);
1988 case ETHTOOL_STUNABLE:
1989 rc = ethtool_set_tunable(dev, useraddr);
1995 if (dev->ethtool_ops->complete)
1996 dev->ethtool_ops->complete(dev);
1998 if (old_features != dev->features)
1999 netdev_features_change(dev);