USB: usb-storage: unusual_devs update for Super TOP SATA bridge
[linux/fpc-iii.git] / net / core / ethtool.c
blob6d6d7d25caaa30319870c6b1d62b38eb8972e543
1 /*
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/bitops.h>
21 #include <linux/uaccess.h>
22 #include <linux/vmalloc.h>
23 #include <linux/slab.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/sched.h>
28 * Some useful ethtool_ops methods that're device independent.
29 * If we find that all drivers want to do the same thing here,
30 * we can turn these into dev_() function calls.
33 u32 ethtool_op_get_link(struct net_device *dev)
35 return netif_carrier_ok(dev) ? 1 : 0;
37 EXPORT_SYMBOL(ethtool_op_get_link);
39 /* Handlers for each ethtool command */
41 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
43 static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
44 [NETIF_F_SG_BIT] = "tx-scatter-gather",
45 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
46 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
47 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
48 [NETIF_F_HIGHDMA_BIT] = "highdma",
49 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
50 [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert",
52 [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse",
53 [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter",
54 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
55 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
56 [NETIF_F_LLTX_BIT] = "tx-lockless",
57 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
58 [NETIF_F_GRO_BIT] = "rx-gro",
59 [NETIF_F_LRO_BIT] = "rx-lro",
61 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
62 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
63 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
64 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
65 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
66 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
68 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
69 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
70 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
71 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
72 [NETIF_F_RXHASH_BIT] = "rx-hashing",
73 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
74 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
75 [NETIF_F_LOOPBACK_BIT] = "loopback",
76 [NETIF_F_RXFCS_BIT] = "rx-fcs",
77 [NETIF_F_RXALL_BIT] = "rx-all",
80 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
82 struct ethtool_gfeatures cmd = {
83 .cmd = ETHTOOL_GFEATURES,
84 .size = ETHTOOL_DEV_FEATURE_WORDS,
86 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
87 u32 __user *sizeaddr;
88 u32 copy_size;
89 int i;
91 /* in case feature bits run out again */
92 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
94 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
95 features[i].available = (u32)(dev->hw_features >> (32 * i));
96 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
97 features[i].active = (u32)(dev->features >> (32 * i));
98 features[i].never_changed =
99 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
102 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
103 if (get_user(copy_size, sizeaddr))
104 return -EFAULT;
106 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
107 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
109 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
110 return -EFAULT;
111 useraddr += sizeof(cmd);
112 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
113 return -EFAULT;
115 return 0;
118 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
120 struct ethtool_sfeatures cmd;
121 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
122 netdev_features_t wanted = 0, valid = 0;
123 int i, ret = 0;
125 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
126 return -EFAULT;
127 useraddr += sizeof(cmd);
129 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
130 return -EINVAL;
132 if (copy_from_user(features, useraddr, sizeof(features)))
133 return -EFAULT;
135 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
136 valid |= (netdev_features_t)features[i].valid << (32 * i);
137 wanted |= (netdev_features_t)features[i].requested << (32 * i);
140 if (valid & ~NETIF_F_ETHTOOL_BITS)
141 return -EINVAL;
143 if (valid & ~dev->hw_features) {
144 valid &= dev->hw_features;
145 ret |= ETHTOOL_F_UNSUPPORTED;
148 dev->wanted_features &= ~valid;
149 dev->wanted_features |= wanted & valid;
150 __netdev_update_features(dev);
152 if ((dev->wanted_features ^ dev->features) & valid)
153 ret |= ETHTOOL_F_WISH;
155 return ret;
158 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
160 const struct ethtool_ops *ops = dev->ethtool_ops;
162 if (sset == ETH_SS_FEATURES)
163 return ARRAY_SIZE(netdev_features_strings);
165 if (ops && ops->get_sset_count && ops->get_strings)
166 return ops->get_sset_count(dev, sset);
167 else
168 return -EOPNOTSUPP;
171 static void __ethtool_get_strings(struct net_device *dev,
172 u32 stringset, u8 *data)
174 const struct ethtool_ops *ops = dev->ethtool_ops;
176 if (stringset == ETH_SS_FEATURES)
177 memcpy(data, netdev_features_strings,
178 sizeof(netdev_features_strings));
179 else
180 /* ops->get_strings is valid because checked earlier */
181 ops->get_strings(dev, stringset, data);
184 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
186 /* feature masks of legacy discrete ethtool ops */
188 switch (eth_cmd) {
189 case ETHTOOL_GTXCSUM:
190 case ETHTOOL_STXCSUM:
191 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
192 case ETHTOOL_GRXCSUM:
193 case ETHTOOL_SRXCSUM:
194 return NETIF_F_RXCSUM;
195 case ETHTOOL_GSG:
196 case ETHTOOL_SSG:
197 return NETIF_F_SG;
198 case ETHTOOL_GTSO:
199 case ETHTOOL_STSO:
200 return NETIF_F_ALL_TSO;
201 case ETHTOOL_GUFO:
202 case ETHTOOL_SUFO:
203 return NETIF_F_UFO;
204 case ETHTOOL_GGSO:
205 case ETHTOOL_SGSO:
206 return NETIF_F_GSO;
207 case ETHTOOL_GGRO:
208 case ETHTOOL_SGRO:
209 return NETIF_F_GRO;
210 default:
211 BUG();
215 static int ethtool_get_one_feature(struct net_device *dev,
216 char __user *useraddr, u32 ethcmd)
218 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
219 struct ethtool_value edata = {
220 .cmd = ethcmd,
221 .data = !!(dev->features & mask),
224 if (copy_to_user(useraddr, &edata, sizeof(edata)))
225 return -EFAULT;
226 return 0;
229 static int ethtool_set_one_feature(struct net_device *dev,
230 void __user *useraddr, u32 ethcmd)
232 struct ethtool_value edata;
233 netdev_features_t mask;
235 if (copy_from_user(&edata, useraddr, sizeof(edata)))
236 return -EFAULT;
238 mask = ethtool_get_feature_mask(ethcmd);
239 mask &= dev->hw_features;
240 if (!mask)
241 return -EOPNOTSUPP;
243 if (edata.data)
244 dev->wanted_features |= mask;
245 else
246 dev->wanted_features &= ~mask;
248 __netdev_update_features(dev);
250 return 0;
253 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
254 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
255 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
256 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
258 static u32 __ethtool_get_flags(struct net_device *dev)
260 u32 flags = 0;
262 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
263 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
264 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
265 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
266 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
268 return flags;
271 static int __ethtool_set_flags(struct net_device *dev, u32 data)
273 netdev_features_t features = 0, changed;
275 if (data & ~ETH_ALL_FLAGS)
276 return -EINVAL;
278 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
279 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
280 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
281 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
282 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
284 /* allow changing only bits set in hw_features */
285 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
286 if (changed & ~dev->hw_features)
287 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
289 dev->wanted_features =
290 (dev->wanted_features & ~changed) | (features & changed);
292 __netdev_update_features(dev);
294 return 0;
297 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
299 ASSERT_RTNL();
301 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
302 return -EOPNOTSUPP;
304 memset(cmd, 0, sizeof(struct ethtool_cmd));
305 cmd->cmd = ETHTOOL_GSET;
306 return dev->ethtool_ops->get_settings(dev, cmd);
308 EXPORT_SYMBOL(__ethtool_get_settings);
310 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
312 int err;
313 struct ethtool_cmd cmd;
315 err = __ethtool_get_settings(dev, &cmd);
316 if (err < 0)
317 return err;
319 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
320 return -EFAULT;
321 return 0;
324 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
326 struct ethtool_cmd cmd;
328 if (!dev->ethtool_ops->set_settings)
329 return -EOPNOTSUPP;
331 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
332 return -EFAULT;
334 return dev->ethtool_ops->set_settings(dev, &cmd);
337 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
338 void __user *useraddr)
340 struct ethtool_drvinfo info;
341 const struct ethtool_ops *ops = dev->ethtool_ops;
343 memset(&info, 0, sizeof(info));
344 info.cmd = ETHTOOL_GDRVINFO;
345 if (ops && ops->get_drvinfo) {
346 ops->get_drvinfo(dev, &info);
347 } else if (dev->dev.parent && dev->dev.parent->driver) {
348 strlcpy(info.bus_info, dev_name(dev->dev.parent),
349 sizeof(info.bus_info));
350 strlcpy(info.driver, dev->dev.parent->driver->name,
351 sizeof(info.driver));
352 } else {
353 return -EOPNOTSUPP;
357 * this method of obtaining string set info is deprecated;
358 * Use ETHTOOL_GSSET_INFO instead.
360 if (ops && ops->get_sset_count) {
361 int rc;
363 rc = ops->get_sset_count(dev, ETH_SS_TEST);
364 if (rc >= 0)
365 info.testinfo_len = rc;
366 rc = ops->get_sset_count(dev, ETH_SS_STATS);
367 if (rc >= 0)
368 info.n_stats = rc;
369 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
370 if (rc >= 0)
371 info.n_priv_flags = rc;
373 if (ops && ops->get_regs_len)
374 info.regdump_len = ops->get_regs_len(dev);
375 if (ops && ops->get_eeprom_len)
376 info.eedump_len = ops->get_eeprom_len(dev);
378 if (copy_to_user(useraddr, &info, sizeof(info)))
379 return -EFAULT;
380 return 0;
383 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
384 void __user *useraddr)
386 struct ethtool_sset_info info;
387 u64 sset_mask;
388 int i, idx = 0, n_bits = 0, ret, rc;
389 u32 *info_buf = NULL;
391 if (copy_from_user(&info, useraddr, sizeof(info)))
392 return -EFAULT;
394 /* store copy of mask, because we zero struct later on */
395 sset_mask = info.sset_mask;
396 if (!sset_mask)
397 return 0;
399 /* calculate size of return buffer */
400 n_bits = hweight64(sset_mask);
402 memset(&info, 0, sizeof(info));
403 info.cmd = ETHTOOL_GSSET_INFO;
405 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
406 if (!info_buf)
407 return -ENOMEM;
410 * fill return buffer based on input bitmask and successful
411 * get_sset_count return
413 for (i = 0; i < 64; i++) {
414 if (!(sset_mask & (1ULL << i)))
415 continue;
417 rc = __ethtool_get_sset_count(dev, i);
418 if (rc >= 0) {
419 info.sset_mask |= (1ULL << i);
420 info_buf[idx++] = rc;
424 ret = -EFAULT;
425 if (copy_to_user(useraddr, &info, sizeof(info)))
426 goto out;
428 useraddr += offsetof(struct ethtool_sset_info, data);
429 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
430 goto out;
432 ret = 0;
434 out:
435 kfree(info_buf);
436 return ret;
439 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
440 u32 cmd, void __user *useraddr)
442 struct ethtool_rxnfc info;
443 size_t info_size = sizeof(info);
444 int rc;
446 if (!dev->ethtool_ops->set_rxnfc)
447 return -EOPNOTSUPP;
449 /* struct ethtool_rxnfc was originally defined for
450 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
451 * members. User-space might still be using that
452 * definition. */
453 if (cmd == ETHTOOL_SRXFH)
454 info_size = (offsetof(struct ethtool_rxnfc, data) +
455 sizeof(info.data));
457 if (copy_from_user(&info, useraddr, info_size))
458 return -EFAULT;
460 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
461 if (rc)
462 return rc;
464 if (cmd == ETHTOOL_SRXCLSRLINS &&
465 copy_to_user(useraddr, &info, info_size))
466 return -EFAULT;
468 return 0;
471 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
472 u32 cmd, void __user *useraddr)
474 struct ethtool_rxnfc info;
475 size_t info_size = sizeof(info);
476 const struct ethtool_ops *ops = dev->ethtool_ops;
477 int ret;
478 void *rule_buf = NULL;
480 if (!ops->get_rxnfc)
481 return -EOPNOTSUPP;
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
486 * definition. */
487 if (cmd == ETHTOOL_GRXFH)
488 info_size = (offsetof(struct ethtool_rxnfc, data) +
489 sizeof(info.data));
491 if (copy_from_user(&info, useraddr, info_size))
492 return -EFAULT;
494 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
495 if (info.rule_cnt > 0) {
496 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
497 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
498 GFP_USER);
499 if (!rule_buf)
500 return -ENOMEM;
504 ret = ops->get_rxnfc(dev, &info, rule_buf);
505 if (ret < 0)
506 goto err_out;
508 ret = -EFAULT;
509 if (copy_to_user(useraddr, &info, info_size))
510 goto err_out;
512 if (rule_buf) {
513 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
514 if (copy_to_user(useraddr, rule_buf,
515 info.rule_cnt * sizeof(u32)))
516 goto err_out;
518 ret = 0;
520 err_out:
521 kfree(rule_buf);
523 return ret;
526 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
527 void __user *useraddr)
529 u32 user_size, dev_size;
530 u32 *indir;
531 int ret;
533 if (!dev->ethtool_ops->get_rxfh_indir_size ||
534 !dev->ethtool_ops->get_rxfh_indir)
535 return -EOPNOTSUPP;
536 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
537 if (dev_size == 0)
538 return -EOPNOTSUPP;
540 if (copy_from_user(&user_size,
541 useraddr + offsetof(struct ethtool_rxfh_indir, size),
542 sizeof(user_size)))
543 return -EFAULT;
545 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
546 &dev_size, sizeof(dev_size)))
547 return -EFAULT;
549 /* If the user buffer size is 0, this is just a query for the
550 * device table size. Otherwise, if it's smaller than the
551 * device table size it's an error.
553 if (user_size < dev_size)
554 return user_size == 0 ? 0 : -EINVAL;
556 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
557 if (!indir)
558 return -ENOMEM;
560 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
561 if (ret)
562 goto out;
564 if (copy_to_user(useraddr +
565 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
566 indir, dev_size * sizeof(indir[0])))
567 ret = -EFAULT;
569 out:
570 kfree(indir);
571 return ret;
574 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
575 void __user *useraddr)
577 struct ethtool_rxnfc rx_rings;
578 u32 user_size, dev_size, i;
579 u32 *indir;
580 int ret;
582 if (!dev->ethtool_ops->get_rxfh_indir_size ||
583 !dev->ethtool_ops->set_rxfh_indir ||
584 !dev->ethtool_ops->get_rxnfc)
585 return -EOPNOTSUPP;
586 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
587 if (dev_size == 0)
588 return -EOPNOTSUPP;
590 if (copy_from_user(&user_size,
591 useraddr + offsetof(struct ethtool_rxfh_indir, size),
592 sizeof(user_size)))
593 return -EFAULT;
595 if (user_size != 0 && user_size != dev_size)
596 return -EINVAL;
598 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
599 if (!indir)
600 return -ENOMEM;
602 rx_rings.cmd = ETHTOOL_GRXRINGS;
603 ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
604 if (ret)
605 goto out;
607 if (user_size == 0) {
608 for (i = 0; i < dev_size; i++)
609 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
610 } else {
611 if (copy_from_user(indir,
612 useraddr +
613 offsetof(struct ethtool_rxfh_indir,
614 ring_index[0]),
615 dev_size * sizeof(indir[0]))) {
616 ret = -EFAULT;
617 goto out;
620 /* Validate ring indices */
621 for (i = 0; i < dev_size; i++) {
622 if (indir[i] >= rx_rings.data) {
623 ret = -EINVAL;
624 goto out;
629 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
631 out:
632 kfree(indir);
633 return ret;
636 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
638 struct ethtool_regs regs;
639 const struct ethtool_ops *ops = dev->ethtool_ops;
640 void *regbuf;
641 int reglen, ret;
643 if (!ops->get_regs || !ops->get_regs_len)
644 return -EOPNOTSUPP;
646 if (copy_from_user(&regs, useraddr, sizeof(regs)))
647 return -EFAULT;
649 reglen = ops->get_regs_len(dev);
650 if (regs.len > reglen)
651 regs.len = reglen;
653 regbuf = vzalloc(reglen);
654 if (reglen && !regbuf)
655 return -ENOMEM;
657 ops->get_regs(dev, &regs, regbuf);
659 ret = -EFAULT;
660 if (copy_to_user(useraddr, &regs, sizeof(regs)))
661 goto out;
662 useraddr += offsetof(struct ethtool_regs, data);
663 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
664 goto out;
665 ret = 0;
667 out:
668 vfree(regbuf);
669 return ret;
672 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
674 struct ethtool_value reset;
675 int ret;
677 if (!dev->ethtool_ops->reset)
678 return -EOPNOTSUPP;
680 if (copy_from_user(&reset, useraddr, sizeof(reset)))
681 return -EFAULT;
683 ret = dev->ethtool_ops->reset(dev, &reset.data);
684 if (ret)
685 return ret;
687 if (copy_to_user(useraddr, &reset, sizeof(reset)))
688 return -EFAULT;
689 return 0;
692 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
694 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
696 if (!dev->ethtool_ops->get_wol)
697 return -EOPNOTSUPP;
699 dev->ethtool_ops->get_wol(dev, &wol);
701 if (copy_to_user(useraddr, &wol, sizeof(wol)))
702 return -EFAULT;
703 return 0;
706 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
708 struct ethtool_wolinfo wol;
710 if (!dev->ethtool_ops->set_wol)
711 return -EOPNOTSUPP;
713 if (copy_from_user(&wol, useraddr, sizeof(wol)))
714 return -EFAULT;
716 return dev->ethtool_ops->set_wol(dev, &wol);
719 static int ethtool_nway_reset(struct net_device *dev)
721 if (!dev->ethtool_ops->nway_reset)
722 return -EOPNOTSUPP;
724 return dev->ethtool_ops->nway_reset(dev);
727 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
729 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
731 if (!dev->ethtool_ops->get_link)
732 return -EOPNOTSUPP;
734 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
736 if (copy_to_user(useraddr, &edata, sizeof(edata)))
737 return -EFAULT;
738 return 0;
741 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
743 struct ethtool_eeprom eeprom;
744 const struct ethtool_ops *ops = dev->ethtool_ops;
745 void __user *userbuf = useraddr + sizeof(eeprom);
746 u32 bytes_remaining;
747 u8 *data;
748 int ret = 0;
750 if (!ops->get_eeprom || !ops->get_eeprom_len)
751 return -EOPNOTSUPP;
753 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
754 return -EFAULT;
756 /* Check for wrap and zero */
757 if (eeprom.offset + eeprom.len <= eeprom.offset)
758 return -EINVAL;
760 /* Check for exceeding total eeprom len */
761 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
762 return -EINVAL;
764 data = kmalloc(PAGE_SIZE, GFP_USER);
765 if (!data)
766 return -ENOMEM;
768 bytes_remaining = eeprom.len;
769 while (bytes_remaining > 0) {
770 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
772 ret = ops->get_eeprom(dev, &eeprom, data);
773 if (ret)
774 break;
775 if (copy_to_user(userbuf, data, eeprom.len)) {
776 ret = -EFAULT;
777 break;
779 userbuf += eeprom.len;
780 eeprom.offset += eeprom.len;
781 bytes_remaining -= eeprom.len;
784 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
785 eeprom.offset -= eeprom.len;
786 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
787 ret = -EFAULT;
789 kfree(data);
790 return ret;
793 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
795 struct ethtool_eeprom eeprom;
796 const struct ethtool_ops *ops = dev->ethtool_ops;
797 void __user *userbuf = useraddr + sizeof(eeprom);
798 u32 bytes_remaining;
799 u8 *data;
800 int ret = 0;
802 if (!ops->set_eeprom || !ops->get_eeprom_len)
803 return -EOPNOTSUPP;
805 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
806 return -EFAULT;
808 /* Check for wrap and zero */
809 if (eeprom.offset + eeprom.len <= eeprom.offset)
810 return -EINVAL;
812 /* Check for exceeding total eeprom len */
813 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
814 return -EINVAL;
816 data = kmalloc(PAGE_SIZE, GFP_USER);
817 if (!data)
818 return -ENOMEM;
820 bytes_remaining = eeprom.len;
821 while (bytes_remaining > 0) {
822 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
824 if (copy_from_user(data, userbuf, eeprom.len)) {
825 ret = -EFAULT;
826 break;
828 ret = ops->set_eeprom(dev, &eeprom, data);
829 if (ret)
830 break;
831 userbuf += eeprom.len;
832 eeprom.offset += eeprom.len;
833 bytes_remaining -= eeprom.len;
836 kfree(data);
837 return ret;
840 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
841 void __user *useraddr)
843 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
845 if (!dev->ethtool_ops->get_coalesce)
846 return -EOPNOTSUPP;
848 dev->ethtool_ops->get_coalesce(dev, &coalesce);
850 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
851 return -EFAULT;
852 return 0;
855 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
856 void __user *useraddr)
858 struct ethtool_coalesce coalesce;
860 if (!dev->ethtool_ops->set_coalesce)
861 return -EOPNOTSUPP;
863 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
864 return -EFAULT;
866 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
869 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
871 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
873 if (!dev->ethtool_ops->get_ringparam)
874 return -EOPNOTSUPP;
876 dev->ethtool_ops->get_ringparam(dev, &ringparam);
878 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
879 return -EFAULT;
880 return 0;
883 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
885 struct ethtool_ringparam ringparam;
887 if (!dev->ethtool_ops->set_ringparam)
888 return -EOPNOTSUPP;
890 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
891 return -EFAULT;
893 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
896 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
897 void __user *useraddr)
899 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
901 if (!dev->ethtool_ops->get_channels)
902 return -EOPNOTSUPP;
904 dev->ethtool_ops->get_channels(dev, &channels);
906 if (copy_to_user(useraddr, &channels, sizeof(channels)))
907 return -EFAULT;
908 return 0;
911 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
912 void __user *useraddr)
914 struct ethtool_channels channels;
916 if (!dev->ethtool_ops->set_channels)
917 return -EOPNOTSUPP;
919 if (copy_from_user(&channels, useraddr, sizeof(channels)))
920 return -EFAULT;
922 return dev->ethtool_ops->set_channels(dev, &channels);
925 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
927 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
929 if (!dev->ethtool_ops->get_pauseparam)
930 return -EOPNOTSUPP;
932 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
934 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
935 return -EFAULT;
936 return 0;
939 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
941 struct ethtool_pauseparam pauseparam;
943 if (!dev->ethtool_ops->set_pauseparam)
944 return -EOPNOTSUPP;
946 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
947 return -EFAULT;
949 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
952 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
954 struct ethtool_test test;
955 const struct ethtool_ops *ops = dev->ethtool_ops;
956 u64 *data;
957 int ret, test_len;
959 if (!ops->self_test || !ops->get_sset_count)
960 return -EOPNOTSUPP;
962 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
963 if (test_len < 0)
964 return test_len;
965 WARN_ON(test_len == 0);
967 if (copy_from_user(&test, useraddr, sizeof(test)))
968 return -EFAULT;
970 test.len = test_len;
971 data = kmalloc(test_len * sizeof(u64), GFP_USER);
972 if (!data)
973 return -ENOMEM;
975 ops->self_test(dev, &test, data);
977 ret = -EFAULT;
978 if (copy_to_user(useraddr, &test, sizeof(test)))
979 goto out;
980 useraddr += sizeof(test);
981 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
982 goto out;
983 ret = 0;
985 out:
986 kfree(data);
987 return ret;
990 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
992 struct ethtool_gstrings gstrings;
993 u8 *data;
994 int ret;
996 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
997 return -EFAULT;
999 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1000 if (ret < 0)
1001 return ret;
1003 gstrings.len = ret;
1005 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1006 if (!data)
1007 return -ENOMEM;
1009 __ethtool_get_strings(dev, gstrings.string_set, data);
1011 ret = -EFAULT;
1012 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1013 goto out;
1014 useraddr += sizeof(gstrings);
1015 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1016 goto out;
1017 ret = 0;
1019 out:
1020 kfree(data);
1021 return ret;
1024 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1026 struct ethtool_value id;
1027 static bool busy;
1028 int rc;
1030 if (!dev->ethtool_ops->set_phys_id)
1031 return -EOPNOTSUPP;
1033 if (busy)
1034 return -EBUSY;
1036 if (copy_from_user(&id, useraddr, sizeof(id)))
1037 return -EFAULT;
1039 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1040 if (rc < 0)
1041 return rc;
1043 /* Drop the RTNL lock while waiting, but prevent reentry or
1044 * removal of the device.
1046 busy = true;
1047 dev_hold(dev);
1048 rtnl_unlock();
1050 if (rc == 0) {
1051 /* Driver will handle this itself */
1052 schedule_timeout_interruptible(
1053 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1054 } else {
1055 /* Driver expects to be called at twice the frequency in rc */
1056 int n = rc * 2, i, interval = HZ / n;
1058 /* Count down seconds */
1059 do {
1060 /* Count down iterations per second */
1061 i = n;
1062 do {
1063 rtnl_lock();
1064 rc = dev->ethtool_ops->set_phys_id(dev,
1065 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1066 rtnl_unlock();
1067 if (rc)
1068 break;
1069 schedule_timeout_interruptible(interval);
1070 } while (!signal_pending(current) && --i != 0);
1071 } while (!signal_pending(current) &&
1072 (id.data == 0 || --id.data != 0));
1075 rtnl_lock();
1076 dev_put(dev);
1077 busy = false;
1079 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1080 return rc;
1083 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1085 struct ethtool_stats stats;
1086 const struct ethtool_ops *ops = dev->ethtool_ops;
1087 u64 *data;
1088 int ret, n_stats;
1090 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1091 return -EOPNOTSUPP;
1093 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1094 if (n_stats < 0)
1095 return n_stats;
1096 WARN_ON(n_stats == 0);
1098 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1099 return -EFAULT;
1101 stats.n_stats = n_stats;
1102 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1103 if (!data)
1104 return -ENOMEM;
1106 ops->get_ethtool_stats(dev, &stats, data);
1108 ret = -EFAULT;
1109 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1110 goto out;
1111 useraddr += sizeof(stats);
1112 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1113 goto out;
1114 ret = 0;
1116 out:
1117 kfree(data);
1118 return ret;
1121 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1123 struct ethtool_perm_addr epaddr;
1125 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1126 return -EFAULT;
1128 if (epaddr.size < dev->addr_len)
1129 return -ETOOSMALL;
1130 epaddr.size = dev->addr_len;
1132 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1133 return -EFAULT;
1134 useraddr += sizeof(epaddr);
1135 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1136 return -EFAULT;
1137 return 0;
1140 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1141 u32 cmd, u32 (*actor)(struct net_device *))
1143 struct ethtool_value edata = { .cmd = cmd };
1145 if (!actor)
1146 return -EOPNOTSUPP;
1148 edata.data = actor(dev);
1150 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1151 return -EFAULT;
1152 return 0;
1155 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1156 void (*actor)(struct net_device *, u32))
1158 struct ethtool_value edata;
1160 if (!actor)
1161 return -EOPNOTSUPP;
1163 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1164 return -EFAULT;
1166 actor(dev, edata.data);
1167 return 0;
1170 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1171 int (*actor)(struct net_device *, u32))
1173 struct ethtool_value edata;
1175 if (!actor)
1176 return -EOPNOTSUPP;
1178 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1179 return -EFAULT;
1181 return actor(dev, edata.data);
1184 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1185 char __user *useraddr)
1187 struct ethtool_flash efl;
1189 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1190 return -EFAULT;
1192 if (!dev->ethtool_ops->flash_device)
1193 return -EOPNOTSUPP;
1195 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1197 return dev->ethtool_ops->flash_device(dev, &efl);
1200 static int ethtool_set_dump(struct net_device *dev,
1201 void __user *useraddr)
1203 struct ethtool_dump dump;
1205 if (!dev->ethtool_ops->set_dump)
1206 return -EOPNOTSUPP;
1208 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1209 return -EFAULT;
1211 return dev->ethtool_ops->set_dump(dev, &dump);
1214 static int ethtool_get_dump_flag(struct net_device *dev,
1215 void __user *useraddr)
1217 int ret;
1218 struct ethtool_dump dump;
1219 const struct ethtool_ops *ops = dev->ethtool_ops;
1221 if (!dev->ethtool_ops->get_dump_flag)
1222 return -EOPNOTSUPP;
1224 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1225 return -EFAULT;
1227 ret = ops->get_dump_flag(dev, &dump);
1228 if (ret)
1229 return ret;
1231 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1232 return -EFAULT;
1233 return 0;
1236 static int ethtool_get_dump_data(struct net_device *dev,
1237 void __user *useraddr)
1239 int ret;
1240 __u32 len;
1241 struct ethtool_dump dump, tmp;
1242 const struct ethtool_ops *ops = dev->ethtool_ops;
1243 void *data = NULL;
1245 if (!dev->ethtool_ops->get_dump_data ||
1246 !dev->ethtool_ops->get_dump_flag)
1247 return -EOPNOTSUPP;
1249 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1250 return -EFAULT;
1252 memset(&tmp, 0, sizeof(tmp));
1253 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1254 ret = ops->get_dump_flag(dev, &tmp);
1255 if (ret)
1256 return ret;
1258 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1259 if (!len)
1260 return -EFAULT;
1262 data = vzalloc(tmp.len);
1263 if (!data)
1264 return -ENOMEM;
1265 ret = ops->get_dump_data(dev, &dump, data);
1266 if (ret)
1267 goto out;
1269 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1270 ret = -EFAULT;
1271 goto out;
1273 useraddr += offsetof(struct ethtool_dump, data);
1274 if (copy_to_user(useraddr, data, len))
1275 ret = -EFAULT;
1276 out:
1277 vfree(data);
1278 return ret;
1281 /* The main entry point in this file. Called from net/core/dev.c */
1283 int dev_ethtool(struct net *net, struct ifreq *ifr)
1285 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1286 void __user *useraddr = ifr->ifr_data;
1287 u32 ethcmd;
1288 int rc;
1289 u32 old_features;
1291 if (!dev || !netif_device_present(dev))
1292 return -ENODEV;
1294 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
1295 return -EFAULT;
1297 if (!dev->ethtool_ops) {
1298 /* ETHTOOL_GDRVINFO does not require any driver support.
1299 * It is also unprivileged and does not change anything,
1300 * so we can take a shortcut to it. */
1301 if (ethcmd == ETHTOOL_GDRVINFO)
1302 return ethtool_get_drvinfo(dev, useraddr);
1303 else
1304 return -EOPNOTSUPP;
1307 /* Allow some commands to be done by anyone */
1308 switch (ethcmd) {
1309 case ETHTOOL_GSET:
1310 case ETHTOOL_GDRVINFO:
1311 case ETHTOOL_GMSGLVL:
1312 case ETHTOOL_GCOALESCE:
1313 case ETHTOOL_GRINGPARAM:
1314 case ETHTOOL_GPAUSEPARAM:
1315 case ETHTOOL_GRXCSUM:
1316 case ETHTOOL_GTXCSUM:
1317 case ETHTOOL_GSG:
1318 case ETHTOOL_GSSET_INFO:
1319 case ETHTOOL_GSTRINGS:
1320 case ETHTOOL_GTSO:
1321 case ETHTOOL_GPERMADDR:
1322 case ETHTOOL_GUFO:
1323 case ETHTOOL_GGSO:
1324 case ETHTOOL_GGRO:
1325 case ETHTOOL_GFLAGS:
1326 case ETHTOOL_GPFLAGS:
1327 case ETHTOOL_GRXFH:
1328 case ETHTOOL_GRXRINGS:
1329 case ETHTOOL_GRXCLSRLCNT:
1330 case ETHTOOL_GRXCLSRULE:
1331 case ETHTOOL_GRXCLSRLALL:
1332 case ETHTOOL_GFEATURES:
1333 break;
1334 default:
1335 if (!capable(CAP_NET_ADMIN))
1336 return -EPERM;
1339 if (dev->ethtool_ops->begin) {
1340 rc = dev->ethtool_ops->begin(dev);
1341 if (rc < 0)
1342 return rc;
1344 old_features = dev->features;
1346 switch (ethcmd) {
1347 case ETHTOOL_GSET:
1348 rc = ethtool_get_settings(dev, useraddr);
1349 break;
1350 case ETHTOOL_SSET:
1351 rc = ethtool_set_settings(dev, useraddr);
1352 break;
1353 case ETHTOOL_GDRVINFO:
1354 rc = ethtool_get_drvinfo(dev, useraddr);
1355 break;
1356 case ETHTOOL_GREGS:
1357 rc = ethtool_get_regs(dev, useraddr);
1358 break;
1359 case ETHTOOL_GWOL:
1360 rc = ethtool_get_wol(dev, useraddr);
1361 break;
1362 case ETHTOOL_SWOL:
1363 rc = ethtool_set_wol(dev, useraddr);
1364 break;
1365 case ETHTOOL_GMSGLVL:
1366 rc = ethtool_get_value(dev, useraddr, ethcmd,
1367 dev->ethtool_ops->get_msglevel);
1368 break;
1369 case ETHTOOL_SMSGLVL:
1370 rc = ethtool_set_value_void(dev, useraddr,
1371 dev->ethtool_ops->set_msglevel);
1372 break;
1373 case ETHTOOL_NWAY_RST:
1374 rc = ethtool_nway_reset(dev);
1375 break;
1376 case ETHTOOL_GLINK:
1377 rc = ethtool_get_link(dev, useraddr);
1378 break;
1379 case ETHTOOL_GEEPROM:
1380 rc = ethtool_get_eeprom(dev, useraddr);
1381 break;
1382 case ETHTOOL_SEEPROM:
1383 rc = ethtool_set_eeprom(dev, useraddr);
1384 break;
1385 case ETHTOOL_GCOALESCE:
1386 rc = ethtool_get_coalesce(dev, useraddr);
1387 break;
1388 case ETHTOOL_SCOALESCE:
1389 rc = ethtool_set_coalesce(dev, useraddr);
1390 break;
1391 case ETHTOOL_GRINGPARAM:
1392 rc = ethtool_get_ringparam(dev, useraddr);
1393 break;
1394 case ETHTOOL_SRINGPARAM:
1395 rc = ethtool_set_ringparam(dev, useraddr);
1396 break;
1397 case ETHTOOL_GPAUSEPARAM:
1398 rc = ethtool_get_pauseparam(dev, useraddr);
1399 break;
1400 case ETHTOOL_SPAUSEPARAM:
1401 rc = ethtool_set_pauseparam(dev, useraddr);
1402 break;
1403 case ETHTOOL_TEST:
1404 rc = ethtool_self_test(dev, useraddr);
1405 break;
1406 case ETHTOOL_GSTRINGS:
1407 rc = ethtool_get_strings(dev, useraddr);
1408 break;
1409 case ETHTOOL_PHYS_ID:
1410 rc = ethtool_phys_id(dev, useraddr);
1411 break;
1412 case ETHTOOL_GSTATS:
1413 rc = ethtool_get_stats(dev, useraddr);
1414 break;
1415 case ETHTOOL_GPERMADDR:
1416 rc = ethtool_get_perm_addr(dev, useraddr);
1417 break;
1418 case ETHTOOL_GFLAGS:
1419 rc = ethtool_get_value(dev, useraddr, ethcmd,
1420 __ethtool_get_flags);
1421 break;
1422 case ETHTOOL_SFLAGS:
1423 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1424 break;
1425 case ETHTOOL_GPFLAGS:
1426 rc = ethtool_get_value(dev, useraddr, ethcmd,
1427 dev->ethtool_ops->get_priv_flags);
1428 break;
1429 case ETHTOOL_SPFLAGS:
1430 rc = ethtool_set_value(dev, useraddr,
1431 dev->ethtool_ops->set_priv_flags);
1432 break;
1433 case ETHTOOL_GRXFH:
1434 case ETHTOOL_GRXRINGS:
1435 case ETHTOOL_GRXCLSRLCNT:
1436 case ETHTOOL_GRXCLSRULE:
1437 case ETHTOOL_GRXCLSRLALL:
1438 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1439 break;
1440 case ETHTOOL_SRXFH:
1441 case ETHTOOL_SRXCLSRLDEL:
1442 case ETHTOOL_SRXCLSRLINS:
1443 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1444 break;
1445 case ETHTOOL_FLASHDEV:
1446 rc = ethtool_flash_device(dev, useraddr);
1447 break;
1448 case ETHTOOL_RESET:
1449 rc = ethtool_reset(dev, useraddr);
1450 break;
1451 case ETHTOOL_GSSET_INFO:
1452 rc = ethtool_get_sset_info(dev, useraddr);
1453 break;
1454 case ETHTOOL_GRXFHINDIR:
1455 rc = ethtool_get_rxfh_indir(dev, useraddr);
1456 break;
1457 case ETHTOOL_SRXFHINDIR:
1458 rc = ethtool_set_rxfh_indir(dev, useraddr);
1459 break;
1460 case ETHTOOL_GFEATURES:
1461 rc = ethtool_get_features(dev, useraddr);
1462 break;
1463 case ETHTOOL_SFEATURES:
1464 rc = ethtool_set_features(dev, useraddr);
1465 break;
1466 case ETHTOOL_GTXCSUM:
1467 case ETHTOOL_GRXCSUM:
1468 case ETHTOOL_GSG:
1469 case ETHTOOL_GTSO:
1470 case ETHTOOL_GUFO:
1471 case ETHTOOL_GGSO:
1472 case ETHTOOL_GGRO:
1473 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1474 break;
1475 case ETHTOOL_STXCSUM:
1476 case ETHTOOL_SRXCSUM:
1477 case ETHTOOL_SSG:
1478 case ETHTOOL_STSO:
1479 case ETHTOOL_SUFO:
1480 case ETHTOOL_SGSO:
1481 case ETHTOOL_SGRO:
1482 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1483 break;
1484 case ETHTOOL_GCHANNELS:
1485 rc = ethtool_get_channels(dev, useraddr);
1486 break;
1487 case ETHTOOL_SCHANNELS:
1488 rc = ethtool_set_channels(dev, useraddr);
1489 break;
1490 case ETHTOOL_SET_DUMP:
1491 rc = ethtool_set_dump(dev, useraddr);
1492 break;
1493 case ETHTOOL_GET_DUMP_FLAG:
1494 rc = ethtool_get_dump_flag(dev, useraddr);
1495 break;
1496 case ETHTOOL_GET_DUMP_DATA:
1497 rc = ethtool_get_dump_data(dev, useraddr);
1498 break;
1499 default:
1500 rc = -EOPNOTSUPP;
1503 if (dev->ethtool_ops->complete)
1504 dev->ethtool_ops->complete(dev);
1506 if (old_features != dev->features)
1507 netdev_features_change(dev);
1509 return rc;