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",
103 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
105 struct ethtool_gfeatures cmd = {
106 .cmd = ETHTOOL_GFEATURES,
107 .size = ETHTOOL_DEV_FEATURE_WORDS,
109 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
110 u32 __user *sizeaddr;
114 /* in case feature bits run out again */
115 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
117 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
118 features[i].available = (u32)(dev->hw_features >> (32 * i));
119 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
120 features[i].active = (u32)(dev->features >> (32 * i));
121 features[i].never_changed =
122 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
125 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
126 if (get_user(copy_size, sizeaddr))
129 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
130 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
132 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
134 useraddr += sizeof(cmd);
135 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
141 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
143 struct ethtool_sfeatures cmd;
144 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
145 netdev_features_t wanted = 0, valid = 0;
148 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
150 useraddr += sizeof(cmd);
152 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
155 if (copy_from_user(features, useraddr, sizeof(features)))
158 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
159 valid |= (netdev_features_t)features[i].valid << (32 * i);
160 wanted |= (netdev_features_t)features[i].requested << (32 * i);
163 if (valid & ~NETIF_F_ETHTOOL_BITS)
166 if (valid & ~dev->hw_features) {
167 valid &= dev->hw_features;
168 ret |= ETHTOOL_F_UNSUPPORTED;
171 dev->wanted_features &= ~valid;
172 dev->wanted_features |= wanted & valid;
173 __netdev_update_features(dev);
175 if ((dev->wanted_features ^ dev->features) & valid)
176 ret |= ETHTOOL_F_WISH;
181 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
183 const struct ethtool_ops *ops = dev->ethtool_ops;
185 if (sset == ETH_SS_FEATURES)
186 return ARRAY_SIZE(netdev_features_strings);
188 if (ops->get_sset_count && ops->get_strings)
189 return ops->get_sset_count(dev, sset);
194 static void __ethtool_get_strings(struct net_device *dev,
195 u32 stringset, u8 *data)
197 const struct ethtool_ops *ops = dev->ethtool_ops;
199 if (stringset == ETH_SS_FEATURES)
200 memcpy(data, netdev_features_strings,
201 sizeof(netdev_features_strings));
203 /* ops->get_strings is valid because checked earlier */
204 ops->get_strings(dev, stringset, data);
207 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
209 /* feature masks of legacy discrete ethtool ops */
212 case ETHTOOL_GTXCSUM:
213 case ETHTOOL_STXCSUM:
214 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
215 case ETHTOOL_GRXCSUM:
216 case ETHTOOL_SRXCSUM:
217 return NETIF_F_RXCSUM;
223 return NETIF_F_ALL_TSO;
238 static int ethtool_get_one_feature(struct net_device *dev,
239 char __user *useraddr, u32 ethcmd)
241 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
242 struct ethtool_value edata = {
244 .data = !!(dev->features & mask),
247 if (copy_to_user(useraddr, &edata, sizeof(edata)))
252 static int ethtool_set_one_feature(struct net_device *dev,
253 void __user *useraddr, u32 ethcmd)
255 struct ethtool_value edata;
256 netdev_features_t mask;
258 if (copy_from_user(&edata, useraddr, sizeof(edata)))
261 mask = ethtool_get_feature_mask(ethcmd);
262 mask &= dev->hw_features;
267 dev->wanted_features |= mask;
269 dev->wanted_features &= ~mask;
271 __netdev_update_features(dev);
276 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
277 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
278 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
279 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
282 static u32 __ethtool_get_flags(struct net_device *dev)
286 if (dev->features & NETIF_F_LRO)
287 flags |= ETH_FLAG_LRO;
288 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
289 flags |= ETH_FLAG_RXVLAN;
290 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
291 flags |= ETH_FLAG_TXVLAN;
292 if (dev->features & NETIF_F_NTUPLE)
293 flags |= ETH_FLAG_NTUPLE;
294 if (dev->features & NETIF_F_RXHASH)
295 flags |= ETH_FLAG_RXHASH;
300 static int __ethtool_set_flags(struct net_device *dev, u32 data)
302 netdev_features_t features = 0, changed;
304 if (data & ~ETH_ALL_FLAGS)
307 if (data & ETH_FLAG_LRO)
308 features |= NETIF_F_LRO;
309 if (data & ETH_FLAG_RXVLAN)
310 features |= NETIF_F_HW_VLAN_CTAG_RX;
311 if (data & ETH_FLAG_TXVLAN)
312 features |= NETIF_F_HW_VLAN_CTAG_TX;
313 if (data & ETH_FLAG_NTUPLE)
314 features |= NETIF_F_NTUPLE;
315 if (data & ETH_FLAG_RXHASH)
316 features |= NETIF_F_RXHASH;
318 /* allow changing only bits set in hw_features */
319 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
320 if (changed & ~dev->hw_features)
321 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
323 dev->wanted_features =
324 (dev->wanted_features & ~changed) | (features & changed);
326 __netdev_update_features(dev);
331 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
335 if (!dev->ethtool_ops->get_settings)
338 memset(cmd, 0, sizeof(struct ethtool_cmd));
339 cmd->cmd = ETHTOOL_GSET;
340 return dev->ethtool_ops->get_settings(dev, cmd);
342 EXPORT_SYMBOL(__ethtool_get_settings);
344 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
347 struct ethtool_cmd cmd;
349 err = __ethtool_get_settings(dev, &cmd);
353 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
358 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
360 struct ethtool_cmd cmd;
362 if (!dev->ethtool_ops->set_settings)
365 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
368 return dev->ethtool_ops->set_settings(dev, &cmd);
371 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
372 void __user *useraddr)
374 struct ethtool_drvinfo info;
375 const struct ethtool_ops *ops = dev->ethtool_ops;
377 memset(&info, 0, sizeof(info));
378 info.cmd = ETHTOOL_GDRVINFO;
379 if (ops->get_drvinfo) {
380 ops->get_drvinfo(dev, &info);
381 } else if (dev->dev.parent && dev->dev.parent->driver) {
382 strlcpy(info.bus_info, dev_name(dev->dev.parent),
383 sizeof(info.bus_info));
384 strlcpy(info.driver, dev->dev.parent->driver->name,
385 sizeof(info.driver));
391 * this method of obtaining string set info is deprecated;
392 * Use ETHTOOL_GSSET_INFO instead.
394 if (ops->get_sset_count) {
397 rc = ops->get_sset_count(dev, ETH_SS_TEST);
399 info.testinfo_len = rc;
400 rc = ops->get_sset_count(dev, ETH_SS_STATS);
403 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
405 info.n_priv_flags = rc;
407 if (ops->get_regs_len)
408 info.regdump_len = ops->get_regs_len(dev);
409 if (ops->get_eeprom_len)
410 info.eedump_len = ops->get_eeprom_len(dev);
412 if (copy_to_user(useraddr, &info, sizeof(info)))
417 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
418 void __user *useraddr)
420 struct ethtool_sset_info info;
422 int i, idx = 0, n_bits = 0, ret, rc;
423 u32 *info_buf = NULL;
425 if (copy_from_user(&info, useraddr, sizeof(info)))
428 /* store copy of mask, because we zero struct later on */
429 sset_mask = info.sset_mask;
433 /* calculate size of return buffer */
434 n_bits = hweight64(sset_mask);
436 memset(&info, 0, sizeof(info));
437 info.cmd = ETHTOOL_GSSET_INFO;
439 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
444 * fill return buffer based on input bitmask and successful
445 * get_sset_count return
447 for (i = 0; i < 64; i++) {
448 if (!(sset_mask & (1ULL << i)))
451 rc = __ethtool_get_sset_count(dev, i);
453 info.sset_mask |= (1ULL << i);
454 info_buf[idx++] = rc;
459 if (copy_to_user(useraddr, &info, sizeof(info)))
462 useraddr += offsetof(struct ethtool_sset_info, data);
463 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
473 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
474 u32 cmd, void __user *useraddr)
476 struct ethtool_rxnfc info;
477 size_t info_size = sizeof(info);
480 if (!dev->ethtool_ops->set_rxnfc)
483 /* struct ethtool_rxnfc was originally defined for
484 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
485 * members. User-space might still be using that
487 if (cmd == ETHTOOL_SRXFH)
488 info_size = (offsetof(struct ethtool_rxnfc, data) +
491 if (copy_from_user(&info, useraddr, info_size))
494 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
498 if (cmd == ETHTOOL_SRXCLSRLINS &&
499 copy_to_user(useraddr, &info, info_size))
505 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
506 u32 cmd, void __user *useraddr)
508 struct ethtool_rxnfc info;
509 size_t info_size = sizeof(info);
510 const struct ethtool_ops *ops = dev->ethtool_ops;
512 void *rule_buf = NULL;
517 /* struct ethtool_rxnfc was originally defined for
518 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
519 * members. User-space might still be using that
521 if (cmd == ETHTOOL_GRXFH)
522 info_size = (offsetof(struct ethtool_rxnfc, data) +
525 if (copy_from_user(&info, useraddr, info_size))
528 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
529 if (info.rule_cnt > 0) {
530 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
531 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
538 ret = ops->get_rxnfc(dev, &info, rule_buf);
543 if (copy_to_user(useraddr, &info, info_size))
547 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
548 if (copy_to_user(useraddr, rule_buf,
549 info.rule_cnt * sizeof(u32)))
560 static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
561 struct ethtool_rxnfc *rx_rings,
566 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
569 /* Validate ring indices */
570 for (i = 0; i < size; i++)
571 if (indir[i] >= rx_rings->data)
577 u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
579 void netdev_rss_key_fill(void *buffer, size_t len)
581 BUG_ON(len > sizeof(netdev_rss_key));
582 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
583 memcpy(buffer, netdev_rss_key, len);
585 EXPORT_SYMBOL(netdev_rss_key_fill);
587 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
588 void __user *useraddr)
590 u32 user_size, dev_size;
594 if (!dev->ethtool_ops->get_rxfh_indir_size ||
595 !dev->ethtool_ops->get_rxfh)
597 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
601 if (copy_from_user(&user_size,
602 useraddr + offsetof(struct ethtool_rxfh_indir, size),
606 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
607 &dev_size, sizeof(dev_size)))
610 /* If the user buffer size is 0, this is just a query for the
611 * device table size. Otherwise, if it's smaller than the
612 * device table size it's an error.
614 if (user_size < dev_size)
615 return user_size == 0 ? 0 : -EINVAL;
617 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
621 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL);
625 if (copy_to_user(useraddr +
626 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
627 indir, dev_size * sizeof(indir[0])))
635 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
636 void __user *useraddr)
638 struct ethtool_rxnfc rx_rings;
639 u32 user_size, dev_size, i;
641 const struct ethtool_ops *ops = dev->ethtool_ops;
643 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
645 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
649 dev_size = ops->get_rxfh_indir_size(dev);
653 if (copy_from_user(&user_size,
654 useraddr + offsetof(struct ethtool_rxfh_indir, size),
658 if (user_size != 0 && user_size != dev_size)
661 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
665 rx_rings.cmd = ETHTOOL_GRXRINGS;
666 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
670 if (user_size == 0) {
671 for (i = 0; i < dev_size; i++)
672 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
674 ret = ethtool_copy_validate_indir(indir,
675 useraddr + ringidx_offset,
682 ret = ops->set_rxfh(dev, indir, NULL);
689 static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
690 void __user *useraddr)
693 const struct ethtool_ops *ops = dev->ethtool_ops;
694 u32 user_indir_size, user_key_size;
695 u32 dev_indir_size = 0, dev_key_size = 0;
696 struct ethtool_rxfh rxfh;
703 if (!(dev->ethtool_ops->get_rxfh_indir_size ||
704 dev->ethtool_ops->get_rxfh_key_size) ||
705 !dev->ethtool_ops->get_rxfh)
708 if (ops->get_rxfh_indir_size)
709 dev_indir_size = ops->get_rxfh_indir_size(dev);
710 if (ops->get_rxfh_key_size)
711 dev_key_size = ops->get_rxfh_key_size(dev);
713 if ((dev_key_size + dev_indir_size) == 0)
716 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
718 user_indir_size = rxfh.indir_size;
719 user_key_size = rxfh.key_size;
721 /* Check that reserved fields are 0 for now */
722 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
725 rxfh.indir_size = dev_indir_size;
726 rxfh.key_size = dev_key_size;
727 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
730 /* If the user buffer size is 0, this is just a query for the
731 * device table size and key size. Otherwise, if the User size is
732 * not equal to device table size or key size it's an error.
734 if (!user_indir_size && !user_key_size)
737 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
738 (user_key_size && (user_key_size != dev_key_size)))
741 indir_bytes = user_indir_size * sizeof(indir[0]);
742 total_size = indir_bytes + user_key_size;
743 rss_config = kzalloc(total_size, GFP_USER);
748 indir = (u32 *)rss_config;
751 hkey = rss_config + indir_bytes;
753 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey);
755 if (copy_to_user(useraddr +
756 offsetof(struct ethtool_rxfh, rss_config[0]),
757 rss_config, total_size))
766 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
767 void __user *useraddr)
770 const struct ethtool_ops *ops = dev->ethtool_ops;
771 struct ethtool_rxnfc rx_rings;
772 struct ethtool_rxfh rxfh;
773 u32 dev_indir_size = 0, dev_key_size = 0, i;
774 u32 *indir = NULL, indir_bytes = 0;
777 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
779 if (!(ops->get_rxfh_indir_size || ops->get_rxfh_key_size) ||
780 !ops->get_rxnfc || !ops->set_rxfh)
783 if (ops->get_rxfh_indir_size)
784 dev_indir_size = ops->get_rxfh_indir_size(dev);
785 if (ops->get_rxfh_key_size)
786 dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
787 if ((dev_key_size + dev_indir_size) == 0)
790 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
793 /* Check that reserved fields are 0 for now */
794 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
797 /* If either indir or hash key is valid, proceed further.
798 * It is not valid to request that both be unchanged.
800 if ((rxfh.indir_size &&
801 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
802 rxfh.indir_size != dev_indir_size) ||
803 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
804 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
808 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
809 indir_bytes = dev_indir_size * sizeof(indir[0]);
811 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
815 rx_rings.cmd = ETHTOOL_GRXRINGS;
816 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
820 /* rxfh.indir_size == 0 means reset the indir table to default.
821 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
823 if (rxfh.indir_size &&
824 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
825 indir = (u32 *)rss_config;
826 ret = ethtool_copy_validate_indir(indir,
827 useraddr + rss_cfg_offset,
832 } else if (rxfh.indir_size == 0) {
833 indir = (u32 *)rss_config;
834 for (i = 0; i < dev_indir_size; i++)
835 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
839 hkey = rss_config + indir_bytes;
840 if (copy_from_user(hkey,
841 useraddr + rss_cfg_offset + indir_bytes,
848 ret = ops->set_rxfh(dev, indir, hkey);
855 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
857 struct ethtool_regs regs;
858 const struct ethtool_ops *ops = dev->ethtool_ops;
862 if (!ops->get_regs || !ops->get_regs_len)
865 if (copy_from_user(®s, useraddr, sizeof(regs)))
868 reglen = ops->get_regs_len(dev);
869 if (regs.len > reglen)
872 regbuf = vzalloc(reglen);
873 if (reglen && !regbuf)
876 ops->get_regs(dev, ®s, regbuf);
879 if (copy_to_user(useraddr, ®s, sizeof(regs)))
881 useraddr += offsetof(struct ethtool_regs, data);
882 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
891 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
893 struct ethtool_value reset;
896 if (!dev->ethtool_ops->reset)
899 if (copy_from_user(&reset, useraddr, sizeof(reset)))
902 ret = dev->ethtool_ops->reset(dev, &reset.data);
906 if (copy_to_user(useraddr, &reset, sizeof(reset)))
911 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
913 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
915 if (!dev->ethtool_ops->get_wol)
918 dev->ethtool_ops->get_wol(dev, &wol);
920 if (copy_to_user(useraddr, &wol, sizeof(wol)))
925 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
927 struct ethtool_wolinfo wol;
929 if (!dev->ethtool_ops->set_wol)
932 if (copy_from_user(&wol, useraddr, sizeof(wol)))
935 return dev->ethtool_ops->set_wol(dev, &wol);
938 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
940 struct ethtool_eee edata;
943 if (!dev->ethtool_ops->get_eee)
946 memset(&edata, 0, sizeof(struct ethtool_eee));
947 edata.cmd = ETHTOOL_GEEE;
948 rc = dev->ethtool_ops->get_eee(dev, &edata);
953 if (copy_to_user(useraddr, &edata, sizeof(edata)))
959 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
961 struct ethtool_eee edata;
963 if (!dev->ethtool_ops->set_eee)
966 if (copy_from_user(&edata, useraddr, sizeof(edata)))
969 return dev->ethtool_ops->set_eee(dev, &edata);
972 static int ethtool_nway_reset(struct net_device *dev)
974 if (!dev->ethtool_ops->nway_reset)
977 return dev->ethtool_ops->nway_reset(dev);
980 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
982 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
984 if (!dev->ethtool_ops->get_link)
987 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
989 if (copy_to_user(useraddr, &edata, sizeof(edata)))
994 static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
995 int (*getter)(struct net_device *,
996 struct ethtool_eeprom *, u8 *),
999 struct ethtool_eeprom eeprom;
1000 void __user *userbuf = useraddr + sizeof(eeprom);
1001 u32 bytes_remaining;
1005 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1008 /* Check for wrap and zero */
1009 if (eeprom.offset + eeprom.len <= eeprom.offset)
1012 /* Check for exceeding total eeprom len */
1013 if (eeprom.offset + eeprom.len > total_len)
1016 data = kmalloc(PAGE_SIZE, GFP_USER);
1020 bytes_remaining = eeprom.len;
1021 while (bytes_remaining > 0) {
1022 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1024 ret = getter(dev, &eeprom, data);
1027 if (copy_to_user(userbuf, data, eeprom.len)) {
1031 userbuf += eeprom.len;
1032 eeprom.offset += eeprom.len;
1033 bytes_remaining -= eeprom.len;
1036 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1037 eeprom.offset -= eeprom.len;
1038 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1045 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1047 const struct ethtool_ops *ops = dev->ethtool_ops;
1049 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1050 !ops->get_eeprom_len(dev))
1053 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1054 ops->get_eeprom_len(dev));
1057 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1059 struct ethtool_eeprom eeprom;
1060 const struct ethtool_ops *ops = dev->ethtool_ops;
1061 void __user *userbuf = useraddr + sizeof(eeprom);
1062 u32 bytes_remaining;
1066 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1067 !ops->get_eeprom_len(dev))
1070 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1073 /* Check for wrap and zero */
1074 if (eeprom.offset + eeprom.len <= eeprom.offset)
1077 /* Check for exceeding total eeprom len */
1078 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1081 data = kmalloc(PAGE_SIZE, GFP_USER);
1085 bytes_remaining = eeprom.len;
1086 while (bytes_remaining > 0) {
1087 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1089 if (copy_from_user(data, userbuf, eeprom.len)) {
1093 ret = ops->set_eeprom(dev, &eeprom, data);
1096 userbuf += eeprom.len;
1097 eeprom.offset += eeprom.len;
1098 bytes_remaining -= eeprom.len;
1105 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1106 void __user *useraddr)
1108 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1110 if (!dev->ethtool_ops->get_coalesce)
1113 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1115 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1120 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1121 void __user *useraddr)
1123 struct ethtool_coalesce coalesce;
1125 if (!dev->ethtool_ops->set_coalesce)
1128 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1131 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1134 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1136 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1138 if (!dev->ethtool_ops->get_ringparam)
1141 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1143 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1148 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1150 struct ethtool_ringparam ringparam;
1152 if (!dev->ethtool_ops->set_ringparam)
1155 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1158 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1161 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1162 void __user *useraddr)
1164 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1166 if (!dev->ethtool_ops->get_channels)
1169 dev->ethtool_ops->get_channels(dev, &channels);
1171 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1176 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1177 void __user *useraddr)
1179 struct ethtool_channels channels;
1181 if (!dev->ethtool_ops->set_channels)
1184 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1187 return dev->ethtool_ops->set_channels(dev, &channels);
1190 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1192 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1194 if (!dev->ethtool_ops->get_pauseparam)
1197 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1199 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1204 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1206 struct ethtool_pauseparam pauseparam;
1208 if (!dev->ethtool_ops->set_pauseparam)
1211 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1214 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1217 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1219 struct ethtool_test test;
1220 const struct ethtool_ops *ops = dev->ethtool_ops;
1224 if (!ops->self_test || !ops->get_sset_count)
1227 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1230 WARN_ON(test_len == 0);
1232 if (copy_from_user(&test, useraddr, sizeof(test)))
1235 test.len = test_len;
1236 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1240 ops->self_test(dev, &test, data);
1243 if (copy_to_user(useraddr, &test, sizeof(test)))
1245 useraddr += sizeof(test);
1246 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1255 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1257 struct ethtool_gstrings gstrings;
1261 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1264 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1270 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1274 __ethtool_get_strings(dev, gstrings.string_set, data);
1277 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1279 useraddr += sizeof(gstrings);
1280 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1289 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1291 struct ethtool_value id;
1293 const struct ethtool_ops *ops = dev->ethtool_ops;
1296 if (!ops->set_phys_id)
1302 if (copy_from_user(&id, useraddr, sizeof(id)))
1305 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1309 /* Drop the RTNL lock while waiting, but prevent reentry or
1310 * removal of the device.
1317 /* Driver will handle this itself */
1318 schedule_timeout_interruptible(
1319 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1321 /* Driver expects to be called at twice the frequency in rc */
1322 int n = rc * 2, i, interval = HZ / n;
1324 /* Count down seconds */
1326 /* Count down iterations per second */
1330 rc = ops->set_phys_id(dev,
1331 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1335 schedule_timeout_interruptible(interval);
1336 } while (!signal_pending(current) && --i != 0);
1337 } while (!signal_pending(current) &&
1338 (id.data == 0 || --id.data != 0));
1345 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1349 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1351 struct ethtool_stats stats;
1352 const struct ethtool_ops *ops = dev->ethtool_ops;
1356 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1359 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1362 WARN_ON(n_stats == 0);
1364 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1367 stats.n_stats = n_stats;
1368 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1372 ops->get_ethtool_stats(dev, &stats, data);
1375 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1377 useraddr += sizeof(stats);
1378 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1387 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1389 struct ethtool_perm_addr epaddr;
1391 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1394 if (epaddr.size < dev->addr_len)
1396 epaddr.size = dev->addr_len;
1398 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1400 useraddr += sizeof(epaddr);
1401 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1406 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1407 u32 cmd, u32 (*actor)(struct net_device *))
1409 struct ethtool_value edata = { .cmd = cmd };
1414 edata.data = actor(dev);
1416 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1421 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1422 void (*actor)(struct net_device *, u32))
1424 struct ethtool_value edata;
1429 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1432 actor(dev, edata.data);
1436 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1437 int (*actor)(struct net_device *, u32))
1439 struct ethtool_value edata;
1444 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1447 return actor(dev, edata.data);
1450 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1451 char __user *useraddr)
1453 struct ethtool_flash efl;
1455 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1458 if (!dev->ethtool_ops->flash_device)
1461 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1463 return dev->ethtool_ops->flash_device(dev, &efl);
1466 static int ethtool_set_dump(struct net_device *dev,
1467 void __user *useraddr)
1469 struct ethtool_dump dump;
1471 if (!dev->ethtool_ops->set_dump)
1474 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1477 return dev->ethtool_ops->set_dump(dev, &dump);
1480 static int ethtool_get_dump_flag(struct net_device *dev,
1481 void __user *useraddr)
1484 struct ethtool_dump dump;
1485 const struct ethtool_ops *ops = dev->ethtool_ops;
1487 if (!ops->get_dump_flag)
1490 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1493 ret = ops->get_dump_flag(dev, &dump);
1497 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1502 static int ethtool_get_dump_data(struct net_device *dev,
1503 void __user *useraddr)
1507 struct ethtool_dump dump, tmp;
1508 const struct ethtool_ops *ops = dev->ethtool_ops;
1511 if (!ops->get_dump_data || !ops->get_dump_flag)
1514 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1517 memset(&tmp, 0, sizeof(tmp));
1518 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1519 ret = ops->get_dump_flag(dev, &tmp);
1523 len = min(tmp.len, dump.len);
1527 /* Don't ever let the driver think there's more space available
1528 * than it requested with .get_dump_flag().
1532 /* Always allocate enough space to hold the whole thing so that the
1533 * driver does not need to check the length and bother with partial
1536 data = vzalloc(tmp.len);
1539 ret = ops->get_dump_data(dev, &dump, data);
1543 /* There are two sane possibilities:
1544 * 1. The driver's .get_dump_data() does not touch dump.len.
1545 * 2. Or it may set dump.len to how much it really writes, which
1546 * should be tmp.len (or len if it can do a partial dump).
1547 * In any case respond to userspace with the actual length of data
1550 WARN_ON(dump.len != len && dump.len != tmp.len);
1553 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1557 useraddr += offsetof(struct ethtool_dump, data);
1558 if (copy_to_user(useraddr, data, len))
1565 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1568 struct ethtool_ts_info info;
1569 const struct ethtool_ops *ops = dev->ethtool_ops;
1570 struct phy_device *phydev = dev->phydev;
1572 memset(&info, 0, sizeof(info));
1573 info.cmd = ETHTOOL_GET_TS_INFO;
1575 if (phydev && phydev->drv && phydev->drv->ts_info) {
1576 err = phydev->drv->ts_info(phydev, &info);
1577 } else if (ops->get_ts_info) {
1578 err = ops->get_ts_info(dev, &info);
1580 info.so_timestamping =
1581 SOF_TIMESTAMPING_RX_SOFTWARE |
1582 SOF_TIMESTAMPING_SOFTWARE;
1583 info.phc_index = -1;
1589 if (copy_to_user(useraddr, &info, sizeof(info)))
1595 static int ethtool_get_module_info(struct net_device *dev,
1596 void __user *useraddr)
1599 struct ethtool_modinfo modinfo;
1600 const struct ethtool_ops *ops = dev->ethtool_ops;
1602 if (!ops->get_module_info)
1605 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1608 ret = ops->get_module_info(dev, &modinfo);
1612 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1618 static int ethtool_get_module_eeprom(struct net_device *dev,
1619 void __user *useraddr)
1622 struct ethtool_modinfo modinfo;
1623 const struct ethtool_ops *ops = dev->ethtool_ops;
1625 if (!ops->get_module_info || !ops->get_module_eeprom)
1628 ret = ops->get_module_info(dev, &modinfo);
1632 return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
1633 modinfo.eeprom_len);
1636 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1639 case ETHTOOL_RX_COPYBREAK:
1640 case ETHTOOL_TX_COPYBREAK:
1641 if (tuna->len != sizeof(u32) ||
1642 tuna->type_id != ETHTOOL_TUNABLE_U32)
1652 static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1655 struct ethtool_tunable tuna;
1656 const struct ethtool_ops *ops = dev->ethtool_ops;
1659 if (!ops->get_tunable)
1661 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1663 ret = ethtool_tunable_valid(&tuna);
1666 data = kmalloc(tuna.len, GFP_USER);
1669 ret = ops->get_tunable(dev, &tuna, data);
1672 useraddr += sizeof(tuna);
1674 if (copy_to_user(useraddr, data, tuna.len))
1683 static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1686 struct ethtool_tunable tuna;
1687 const struct ethtool_ops *ops = dev->ethtool_ops;
1690 if (!ops->set_tunable)
1692 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1694 ret = ethtool_tunable_valid(&tuna);
1697 data = kmalloc(tuna.len, GFP_USER);
1700 useraddr += sizeof(tuna);
1702 if (copy_from_user(data, useraddr, tuna.len))
1704 ret = ops->set_tunable(dev, &tuna, data);
1711 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
1713 int dev_ethtool(struct net *net, struct ifreq *ifr)
1715 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1716 void __user *useraddr = ifr->ifr_data;
1719 netdev_features_t old_features;
1721 if (!dev || !netif_device_present(dev))
1724 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1727 /* Allow some commands to be done by anyone */
1730 case ETHTOOL_GDRVINFO:
1731 case ETHTOOL_GMSGLVL:
1733 case ETHTOOL_GCOALESCE:
1734 case ETHTOOL_GRINGPARAM:
1735 case ETHTOOL_GPAUSEPARAM:
1736 case ETHTOOL_GRXCSUM:
1737 case ETHTOOL_GTXCSUM:
1739 case ETHTOOL_GSSET_INFO:
1740 case ETHTOOL_GSTRINGS:
1741 case ETHTOOL_GSTATS:
1743 case ETHTOOL_GPERMADDR:
1747 case ETHTOOL_GFLAGS:
1748 case ETHTOOL_GPFLAGS:
1750 case ETHTOOL_GRXRINGS:
1751 case ETHTOOL_GRXCLSRLCNT:
1752 case ETHTOOL_GRXCLSRULE:
1753 case ETHTOOL_GRXCLSRLALL:
1754 case ETHTOOL_GRXFHINDIR:
1756 case ETHTOOL_GFEATURES:
1757 case ETHTOOL_GCHANNELS:
1758 case ETHTOOL_GET_TS_INFO:
1760 case ETHTOOL_GTUNABLE:
1763 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1767 if (dev->ethtool_ops->begin) {
1768 rc = dev->ethtool_ops->begin(dev);
1772 old_features = dev->features;
1776 rc = ethtool_get_settings(dev, useraddr);
1779 rc = ethtool_set_settings(dev, useraddr);
1781 case ETHTOOL_GDRVINFO:
1782 rc = ethtool_get_drvinfo(dev, useraddr);
1785 rc = ethtool_get_regs(dev, useraddr);
1788 rc = ethtool_get_wol(dev, useraddr);
1791 rc = ethtool_set_wol(dev, useraddr);
1793 case ETHTOOL_GMSGLVL:
1794 rc = ethtool_get_value(dev, useraddr, ethcmd,
1795 dev->ethtool_ops->get_msglevel);
1797 case ETHTOOL_SMSGLVL:
1798 rc = ethtool_set_value_void(dev, useraddr,
1799 dev->ethtool_ops->set_msglevel);
1802 rc = ethtool_get_eee(dev, useraddr);
1805 rc = ethtool_set_eee(dev, useraddr);
1807 case ETHTOOL_NWAY_RST:
1808 rc = ethtool_nway_reset(dev);
1811 rc = ethtool_get_link(dev, useraddr);
1813 case ETHTOOL_GEEPROM:
1814 rc = ethtool_get_eeprom(dev, useraddr);
1816 case ETHTOOL_SEEPROM:
1817 rc = ethtool_set_eeprom(dev, useraddr);
1819 case ETHTOOL_GCOALESCE:
1820 rc = ethtool_get_coalesce(dev, useraddr);
1822 case ETHTOOL_SCOALESCE:
1823 rc = ethtool_set_coalesce(dev, useraddr);
1825 case ETHTOOL_GRINGPARAM:
1826 rc = ethtool_get_ringparam(dev, useraddr);
1828 case ETHTOOL_SRINGPARAM:
1829 rc = ethtool_set_ringparam(dev, useraddr);
1831 case ETHTOOL_GPAUSEPARAM:
1832 rc = ethtool_get_pauseparam(dev, useraddr);
1834 case ETHTOOL_SPAUSEPARAM:
1835 rc = ethtool_set_pauseparam(dev, useraddr);
1838 rc = ethtool_self_test(dev, useraddr);
1840 case ETHTOOL_GSTRINGS:
1841 rc = ethtool_get_strings(dev, useraddr);
1843 case ETHTOOL_PHYS_ID:
1844 rc = ethtool_phys_id(dev, useraddr);
1846 case ETHTOOL_GSTATS:
1847 rc = ethtool_get_stats(dev, useraddr);
1849 case ETHTOOL_GPERMADDR:
1850 rc = ethtool_get_perm_addr(dev, useraddr);
1852 case ETHTOOL_GFLAGS:
1853 rc = ethtool_get_value(dev, useraddr, ethcmd,
1854 __ethtool_get_flags);
1856 case ETHTOOL_SFLAGS:
1857 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1859 case ETHTOOL_GPFLAGS:
1860 rc = ethtool_get_value(dev, useraddr, ethcmd,
1861 dev->ethtool_ops->get_priv_flags);
1863 case ETHTOOL_SPFLAGS:
1864 rc = ethtool_set_value(dev, useraddr,
1865 dev->ethtool_ops->set_priv_flags);
1868 case ETHTOOL_GRXRINGS:
1869 case ETHTOOL_GRXCLSRLCNT:
1870 case ETHTOOL_GRXCLSRULE:
1871 case ETHTOOL_GRXCLSRLALL:
1872 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1875 case ETHTOOL_SRXCLSRLDEL:
1876 case ETHTOOL_SRXCLSRLINS:
1877 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1879 case ETHTOOL_FLASHDEV:
1880 rc = ethtool_flash_device(dev, useraddr);
1883 rc = ethtool_reset(dev, useraddr);
1885 case ETHTOOL_GSSET_INFO:
1886 rc = ethtool_get_sset_info(dev, useraddr);
1888 case ETHTOOL_GRXFHINDIR:
1889 rc = ethtool_get_rxfh_indir(dev, useraddr);
1891 case ETHTOOL_SRXFHINDIR:
1892 rc = ethtool_set_rxfh_indir(dev, useraddr);
1895 rc = ethtool_get_rxfh(dev, useraddr);
1898 rc = ethtool_set_rxfh(dev, useraddr);
1900 case ETHTOOL_GFEATURES:
1901 rc = ethtool_get_features(dev, useraddr);
1903 case ETHTOOL_SFEATURES:
1904 rc = ethtool_set_features(dev, useraddr);
1906 case ETHTOOL_GTXCSUM:
1907 case ETHTOOL_GRXCSUM:
1913 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1915 case ETHTOOL_STXCSUM:
1916 case ETHTOOL_SRXCSUM:
1922 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1924 case ETHTOOL_GCHANNELS:
1925 rc = ethtool_get_channels(dev, useraddr);
1927 case ETHTOOL_SCHANNELS:
1928 rc = ethtool_set_channels(dev, useraddr);
1930 case ETHTOOL_SET_DUMP:
1931 rc = ethtool_set_dump(dev, useraddr);
1933 case ETHTOOL_GET_DUMP_FLAG:
1934 rc = ethtool_get_dump_flag(dev, useraddr);
1936 case ETHTOOL_GET_DUMP_DATA:
1937 rc = ethtool_get_dump_data(dev, useraddr);
1939 case ETHTOOL_GET_TS_INFO:
1940 rc = ethtool_get_ts_info(dev, useraddr);
1942 case ETHTOOL_GMODULEINFO:
1943 rc = ethtool_get_module_info(dev, useraddr);
1945 case ETHTOOL_GMODULEEEPROM:
1946 rc = ethtool_get_module_eeprom(dev, useraddr);
1948 case ETHTOOL_GTUNABLE:
1949 rc = ethtool_get_tunable(dev, useraddr);
1951 case ETHTOOL_STUNABLE:
1952 rc = ethtool_set_tunable(dev, useraddr);
1958 if (dev->ethtool_ops->complete)
1959 dev->ethtool_ops->complete(dev);
1961 if (old_features != dev->features)
1962 netdev_features_change(dev);