080161924a0d499359dd8d2f00404ac276783c17
[deliverable/linux.git] / net / core / ethtool.c
1 /*
2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
4 *
5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs.
7 *
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.
12 */
13
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>
26
27 /*
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.
31 */
32
33 u32 ethtool_op_get_link(struct net_device *dev)
34 {
35 return netif_carrier_ok(dev) ? 1 : 0;
36 }
37 EXPORT_SYMBOL(ethtool_op_get_link);
38
39 /* Handlers for each ethtool command */
40
41 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
42
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",
51
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",
60
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",
67
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 };
78
79 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
80 {
81 struct ethtool_gfeatures cmd = {
82 .cmd = ETHTOOL_GFEATURES,
83 .size = ETHTOOL_DEV_FEATURE_WORDS,
84 };
85 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
86 u32 __user *sizeaddr;
87 u32 copy_size;
88 int i;
89
90 /* in case feature bits run out again */
91 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
92
93 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
94 features[i].available = (u32)(dev->hw_features >> (32 * i));
95 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
96 features[i].active = (u32)(dev->features >> (32 * i));
97 features[i].never_changed =
98 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
99 }
100
101 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
102 if (get_user(copy_size, sizeaddr))
103 return -EFAULT;
104
105 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
106 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
107
108 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
109 return -EFAULT;
110 useraddr += sizeof(cmd);
111 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
112 return -EFAULT;
113
114 return 0;
115 }
116
117 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
118 {
119 struct ethtool_sfeatures cmd;
120 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
121 netdev_features_t wanted = 0, valid = 0;
122 int i, ret = 0;
123
124 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
125 return -EFAULT;
126 useraddr += sizeof(cmd);
127
128 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
129 return -EINVAL;
130
131 if (copy_from_user(features, useraddr, sizeof(features)))
132 return -EFAULT;
133
134 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
135 valid |= (netdev_features_t)features[i].valid << (32 * i);
136 wanted |= (netdev_features_t)features[i].requested << (32 * i);
137 }
138
139 if (valid & ~NETIF_F_ETHTOOL_BITS)
140 return -EINVAL;
141
142 if (valid & ~dev->hw_features) {
143 valid &= dev->hw_features;
144 ret |= ETHTOOL_F_UNSUPPORTED;
145 }
146
147 dev->wanted_features &= ~valid;
148 dev->wanted_features |= wanted & valid;
149 __netdev_update_features(dev);
150
151 if ((dev->wanted_features ^ dev->features) & valid)
152 ret |= ETHTOOL_F_WISH;
153
154 return ret;
155 }
156
157 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
158 {
159 const struct ethtool_ops *ops = dev->ethtool_ops;
160
161 if (sset == ETH_SS_FEATURES)
162 return ARRAY_SIZE(netdev_features_strings);
163
164 if (ops && ops->get_sset_count && ops->get_strings)
165 return ops->get_sset_count(dev, sset);
166 else
167 return -EOPNOTSUPP;
168 }
169
170 static void __ethtool_get_strings(struct net_device *dev,
171 u32 stringset, u8 *data)
172 {
173 const struct ethtool_ops *ops = dev->ethtool_ops;
174
175 if (stringset == ETH_SS_FEATURES)
176 memcpy(data, netdev_features_strings,
177 sizeof(netdev_features_strings));
178 else
179 /* ops->get_strings is valid because checked earlier */
180 ops->get_strings(dev, stringset, data);
181 }
182
183 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
184 {
185 /* feature masks of legacy discrete ethtool ops */
186
187 switch (eth_cmd) {
188 case ETHTOOL_GTXCSUM:
189 case ETHTOOL_STXCSUM:
190 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
191 case ETHTOOL_GRXCSUM:
192 case ETHTOOL_SRXCSUM:
193 return NETIF_F_RXCSUM;
194 case ETHTOOL_GSG:
195 case ETHTOOL_SSG:
196 return NETIF_F_SG;
197 case ETHTOOL_GTSO:
198 case ETHTOOL_STSO:
199 return NETIF_F_ALL_TSO;
200 case ETHTOOL_GUFO:
201 case ETHTOOL_SUFO:
202 return NETIF_F_UFO;
203 case ETHTOOL_GGSO:
204 case ETHTOOL_SGSO:
205 return NETIF_F_GSO;
206 case ETHTOOL_GGRO:
207 case ETHTOOL_SGRO:
208 return NETIF_F_GRO;
209 default:
210 BUG();
211 }
212 }
213
214 static int ethtool_get_one_feature(struct net_device *dev,
215 char __user *useraddr, u32 ethcmd)
216 {
217 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
218 struct ethtool_value edata = {
219 .cmd = ethcmd,
220 .data = !!(dev->features & mask),
221 };
222
223 if (copy_to_user(useraddr, &edata, sizeof(edata)))
224 return -EFAULT;
225 return 0;
226 }
227
228 static int ethtool_set_one_feature(struct net_device *dev,
229 void __user *useraddr, u32 ethcmd)
230 {
231 struct ethtool_value edata;
232 netdev_features_t mask;
233
234 if (copy_from_user(&edata, useraddr, sizeof(edata)))
235 return -EFAULT;
236
237 mask = ethtool_get_feature_mask(ethcmd);
238 mask &= dev->hw_features;
239 if (!mask)
240 return -EOPNOTSUPP;
241
242 if (edata.data)
243 dev->wanted_features |= mask;
244 else
245 dev->wanted_features &= ~mask;
246
247 __netdev_update_features(dev);
248
249 return 0;
250 }
251
252 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
253 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
254 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
255 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
256
257 static u32 __ethtool_get_flags(struct net_device *dev)
258 {
259 u32 flags = 0;
260
261 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
262 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
263 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
264 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
265 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
266
267 return flags;
268 }
269
270 static int __ethtool_set_flags(struct net_device *dev, u32 data)
271 {
272 netdev_features_t features = 0, changed;
273
274 if (data & ~ETH_ALL_FLAGS)
275 return -EINVAL;
276
277 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
278 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
279 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
280 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
281 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
282
283 /* allow changing only bits set in hw_features */
284 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
285 if (changed & ~dev->hw_features)
286 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
287
288 dev->wanted_features =
289 (dev->wanted_features & ~changed) | (features & changed);
290
291 __netdev_update_features(dev);
292
293 return 0;
294 }
295
296 int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
297 {
298 ASSERT_RTNL();
299
300 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
301 return -EOPNOTSUPP;
302
303 memset(cmd, 0, sizeof(struct ethtool_cmd));
304 cmd->cmd = ETHTOOL_GSET;
305 return dev->ethtool_ops->get_settings(dev, cmd);
306 }
307 EXPORT_SYMBOL(__ethtool_get_settings);
308
309 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
310 {
311 int err;
312 struct ethtool_cmd cmd;
313
314 err = __ethtool_get_settings(dev, &cmd);
315 if (err < 0)
316 return err;
317
318 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
319 return -EFAULT;
320 return 0;
321 }
322
323 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
324 {
325 struct ethtool_cmd cmd;
326
327 if (!dev->ethtool_ops->set_settings)
328 return -EOPNOTSUPP;
329
330 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
331 return -EFAULT;
332
333 return dev->ethtool_ops->set_settings(dev, &cmd);
334 }
335
336 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
337 void __user *useraddr)
338 {
339 struct ethtool_drvinfo info;
340 const struct ethtool_ops *ops = dev->ethtool_ops;
341
342 memset(&info, 0, sizeof(info));
343 info.cmd = ETHTOOL_GDRVINFO;
344 if (ops && ops->get_drvinfo) {
345 ops->get_drvinfo(dev, &info);
346 } else if (dev->dev.parent && dev->dev.parent->driver) {
347 strlcpy(info.bus_info, dev_name(dev->dev.parent),
348 sizeof(info.bus_info));
349 strlcpy(info.driver, dev->dev.parent->driver->name,
350 sizeof(info.driver));
351 } else {
352 return -EOPNOTSUPP;
353 }
354
355 /*
356 * this method of obtaining string set info is deprecated;
357 * Use ETHTOOL_GSSET_INFO instead.
358 */
359 if (ops && ops->get_sset_count) {
360 int rc;
361
362 rc = ops->get_sset_count(dev, ETH_SS_TEST);
363 if (rc >= 0)
364 info.testinfo_len = rc;
365 rc = ops->get_sset_count(dev, ETH_SS_STATS);
366 if (rc >= 0)
367 info.n_stats = rc;
368 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
369 if (rc >= 0)
370 info.n_priv_flags = rc;
371 }
372 if (ops && ops->get_regs_len)
373 info.regdump_len = ops->get_regs_len(dev);
374 if (ops && ops->get_eeprom_len)
375 info.eedump_len = ops->get_eeprom_len(dev);
376
377 if (copy_to_user(useraddr, &info, sizeof(info)))
378 return -EFAULT;
379 return 0;
380 }
381
382 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
383 void __user *useraddr)
384 {
385 struct ethtool_sset_info info;
386 u64 sset_mask;
387 int i, idx = 0, n_bits = 0, ret, rc;
388 u32 *info_buf = NULL;
389
390 if (copy_from_user(&info, useraddr, sizeof(info)))
391 return -EFAULT;
392
393 /* store copy of mask, because we zero struct later on */
394 sset_mask = info.sset_mask;
395 if (!sset_mask)
396 return 0;
397
398 /* calculate size of return buffer */
399 n_bits = hweight64(sset_mask);
400
401 memset(&info, 0, sizeof(info));
402 info.cmd = ETHTOOL_GSSET_INFO;
403
404 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
405 if (!info_buf)
406 return -ENOMEM;
407
408 /*
409 * fill return buffer based on input bitmask and successful
410 * get_sset_count return
411 */
412 for (i = 0; i < 64; i++) {
413 if (!(sset_mask & (1ULL << i)))
414 continue;
415
416 rc = __ethtool_get_sset_count(dev, i);
417 if (rc >= 0) {
418 info.sset_mask |= (1ULL << i);
419 info_buf[idx++] = rc;
420 }
421 }
422
423 ret = -EFAULT;
424 if (copy_to_user(useraddr, &info, sizeof(info)))
425 goto out;
426
427 useraddr += offsetof(struct ethtool_sset_info, data);
428 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
429 goto out;
430
431 ret = 0;
432
433 out:
434 kfree(info_buf);
435 return ret;
436 }
437
438 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
439 u32 cmd, void __user *useraddr)
440 {
441 struct ethtool_rxnfc info;
442 size_t info_size = sizeof(info);
443 int rc;
444
445 if (!dev->ethtool_ops->set_rxnfc)
446 return -EOPNOTSUPP;
447
448 /* struct ethtool_rxnfc was originally defined for
449 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
450 * members. User-space might still be using that
451 * definition. */
452 if (cmd == ETHTOOL_SRXFH)
453 info_size = (offsetof(struct ethtool_rxnfc, data) +
454 sizeof(info.data));
455
456 if (copy_from_user(&info, useraddr, info_size))
457 return -EFAULT;
458
459 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
460 if (rc)
461 return rc;
462
463 if (cmd == ETHTOOL_SRXCLSRLINS &&
464 copy_to_user(useraddr, &info, info_size))
465 return -EFAULT;
466
467 return 0;
468 }
469
470 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
471 u32 cmd, void __user *useraddr)
472 {
473 struct ethtool_rxnfc info;
474 size_t info_size = sizeof(info);
475 const struct ethtool_ops *ops = dev->ethtool_ops;
476 int ret;
477 void *rule_buf = NULL;
478
479 if (!ops->get_rxnfc)
480 return -EOPNOTSUPP;
481
482 /* struct ethtool_rxnfc was originally defined for
483 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
484 * members. User-space might still be using that
485 * definition. */
486 if (cmd == ETHTOOL_GRXFH)
487 info_size = (offsetof(struct ethtool_rxnfc, data) +
488 sizeof(info.data));
489
490 if (copy_from_user(&info, useraddr, info_size))
491 return -EFAULT;
492
493 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
494 if (info.rule_cnt > 0) {
495 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
496 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
497 GFP_USER);
498 if (!rule_buf)
499 return -ENOMEM;
500 }
501 }
502
503 ret = ops->get_rxnfc(dev, &info, rule_buf);
504 if (ret < 0)
505 goto err_out;
506
507 ret = -EFAULT;
508 if (copy_to_user(useraddr, &info, info_size))
509 goto err_out;
510
511 if (rule_buf) {
512 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
513 if (copy_to_user(useraddr, rule_buf,
514 info.rule_cnt * sizeof(u32)))
515 goto err_out;
516 }
517 ret = 0;
518
519 err_out:
520 kfree(rule_buf);
521
522 return ret;
523 }
524
525 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
526 void __user *useraddr)
527 {
528 u32 user_size, dev_size;
529 u32 *indir;
530 int ret;
531
532 if (!dev->ethtool_ops->get_rxfh_indir_size ||
533 !dev->ethtool_ops->get_rxfh_indir)
534 return -EOPNOTSUPP;
535 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
536 if (dev_size == 0)
537 return -EOPNOTSUPP;
538
539 if (copy_from_user(&user_size,
540 useraddr + offsetof(struct ethtool_rxfh_indir, size),
541 sizeof(user_size)))
542 return -EFAULT;
543
544 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
545 &dev_size, sizeof(dev_size)))
546 return -EFAULT;
547
548 /* If the user buffer size is 0, this is just a query for the
549 * device table size. Otherwise, if it's smaller than the
550 * device table size it's an error.
551 */
552 if (user_size < dev_size)
553 return user_size == 0 ? 0 : -EINVAL;
554
555 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
556 if (!indir)
557 return -ENOMEM;
558
559 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
560 if (ret)
561 goto out;
562
563 if (copy_to_user(useraddr +
564 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
565 indir, dev_size * sizeof(indir[0])))
566 ret = -EFAULT;
567
568 out:
569 kfree(indir);
570 return ret;
571 }
572
573 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
574 void __user *useraddr)
575 {
576 struct ethtool_rxnfc rx_rings;
577 u32 user_size, dev_size, i;
578 u32 *indir;
579 int ret;
580
581 if (!dev->ethtool_ops->get_rxfh_indir_size ||
582 !dev->ethtool_ops->set_rxfh_indir ||
583 !dev->ethtool_ops->get_rxnfc)
584 return -EOPNOTSUPP;
585 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
586 if (dev_size == 0)
587 return -EOPNOTSUPP;
588
589 if (copy_from_user(&user_size,
590 useraddr + offsetof(struct ethtool_rxfh_indir, size),
591 sizeof(user_size)))
592 return -EFAULT;
593
594 if (user_size != 0 && user_size != dev_size)
595 return -EINVAL;
596
597 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
598 if (!indir)
599 return -ENOMEM;
600
601 rx_rings.cmd = ETHTOOL_GRXRINGS;
602 ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
603 if (ret)
604 goto out;
605
606 if (user_size == 0) {
607 for (i = 0; i < dev_size; i++)
608 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
609 } else {
610 if (copy_from_user(indir,
611 useraddr +
612 offsetof(struct ethtool_rxfh_indir,
613 ring_index[0]),
614 dev_size * sizeof(indir[0]))) {
615 ret = -EFAULT;
616 goto out;
617 }
618
619 /* Validate ring indices */
620 for (i = 0; i < dev_size; i++) {
621 if (indir[i] >= rx_rings.data) {
622 ret = -EINVAL;
623 goto out;
624 }
625 }
626 }
627
628 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
629
630 out:
631 kfree(indir);
632 return ret;
633 }
634
635 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
636 {
637 struct ethtool_regs regs;
638 const struct ethtool_ops *ops = dev->ethtool_ops;
639 void *regbuf;
640 int reglen, ret;
641
642 if (!ops->get_regs || !ops->get_regs_len)
643 return -EOPNOTSUPP;
644
645 if (copy_from_user(&regs, useraddr, sizeof(regs)))
646 return -EFAULT;
647
648 reglen = ops->get_regs_len(dev);
649 if (regs.len > reglen)
650 regs.len = reglen;
651
652 regbuf = vzalloc(reglen);
653 if (reglen && !regbuf)
654 return -ENOMEM;
655
656 ops->get_regs(dev, &regs, regbuf);
657
658 ret = -EFAULT;
659 if (copy_to_user(useraddr, &regs, sizeof(regs)))
660 goto out;
661 useraddr += offsetof(struct ethtool_regs, data);
662 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
663 goto out;
664 ret = 0;
665
666 out:
667 vfree(regbuf);
668 return ret;
669 }
670
671 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
672 {
673 struct ethtool_value reset;
674 int ret;
675
676 if (!dev->ethtool_ops->reset)
677 return -EOPNOTSUPP;
678
679 if (copy_from_user(&reset, useraddr, sizeof(reset)))
680 return -EFAULT;
681
682 ret = dev->ethtool_ops->reset(dev, &reset.data);
683 if (ret)
684 return ret;
685
686 if (copy_to_user(useraddr, &reset, sizeof(reset)))
687 return -EFAULT;
688 return 0;
689 }
690
691 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
692 {
693 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
694
695 if (!dev->ethtool_ops->get_wol)
696 return -EOPNOTSUPP;
697
698 dev->ethtool_ops->get_wol(dev, &wol);
699
700 if (copy_to_user(useraddr, &wol, sizeof(wol)))
701 return -EFAULT;
702 return 0;
703 }
704
705 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
706 {
707 struct ethtool_wolinfo wol;
708
709 if (!dev->ethtool_ops->set_wol)
710 return -EOPNOTSUPP;
711
712 if (copy_from_user(&wol, useraddr, sizeof(wol)))
713 return -EFAULT;
714
715 return dev->ethtool_ops->set_wol(dev, &wol);
716 }
717
718 static int ethtool_nway_reset(struct net_device *dev)
719 {
720 if (!dev->ethtool_ops->nway_reset)
721 return -EOPNOTSUPP;
722
723 return dev->ethtool_ops->nway_reset(dev);
724 }
725
726 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
727 {
728 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
729
730 if (!dev->ethtool_ops->get_link)
731 return -EOPNOTSUPP;
732
733 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
734
735 if (copy_to_user(useraddr, &edata, sizeof(edata)))
736 return -EFAULT;
737 return 0;
738 }
739
740 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
741 {
742 struct ethtool_eeprom eeprom;
743 const struct ethtool_ops *ops = dev->ethtool_ops;
744 void __user *userbuf = useraddr + sizeof(eeprom);
745 u32 bytes_remaining;
746 u8 *data;
747 int ret = 0;
748
749 if (!ops->get_eeprom || !ops->get_eeprom_len)
750 return -EOPNOTSUPP;
751
752 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
753 return -EFAULT;
754
755 /* Check for wrap and zero */
756 if (eeprom.offset + eeprom.len <= eeprom.offset)
757 return -EINVAL;
758
759 /* Check for exceeding total eeprom len */
760 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
761 return -EINVAL;
762
763 data = kmalloc(PAGE_SIZE, GFP_USER);
764 if (!data)
765 return -ENOMEM;
766
767 bytes_remaining = eeprom.len;
768 while (bytes_remaining > 0) {
769 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
770
771 ret = ops->get_eeprom(dev, &eeprom, data);
772 if (ret)
773 break;
774 if (copy_to_user(userbuf, data, eeprom.len)) {
775 ret = -EFAULT;
776 break;
777 }
778 userbuf += eeprom.len;
779 eeprom.offset += eeprom.len;
780 bytes_remaining -= eeprom.len;
781 }
782
783 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
784 eeprom.offset -= eeprom.len;
785 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
786 ret = -EFAULT;
787
788 kfree(data);
789 return ret;
790 }
791
792 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
793 {
794 struct ethtool_eeprom eeprom;
795 const struct ethtool_ops *ops = dev->ethtool_ops;
796 void __user *userbuf = useraddr + sizeof(eeprom);
797 u32 bytes_remaining;
798 u8 *data;
799 int ret = 0;
800
801 if (!ops->set_eeprom || !ops->get_eeprom_len)
802 return -EOPNOTSUPP;
803
804 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
805 return -EFAULT;
806
807 /* Check for wrap and zero */
808 if (eeprom.offset + eeprom.len <= eeprom.offset)
809 return -EINVAL;
810
811 /* Check for exceeding total eeprom len */
812 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
813 return -EINVAL;
814
815 data = kmalloc(PAGE_SIZE, GFP_USER);
816 if (!data)
817 return -ENOMEM;
818
819 bytes_remaining = eeprom.len;
820 while (bytes_remaining > 0) {
821 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
822
823 if (copy_from_user(data, userbuf, eeprom.len)) {
824 ret = -EFAULT;
825 break;
826 }
827 ret = ops->set_eeprom(dev, &eeprom, data);
828 if (ret)
829 break;
830 userbuf += eeprom.len;
831 eeprom.offset += eeprom.len;
832 bytes_remaining -= eeprom.len;
833 }
834
835 kfree(data);
836 return ret;
837 }
838
839 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
840 void __user *useraddr)
841 {
842 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
843
844 if (!dev->ethtool_ops->get_coalesce)
845 return -EOPNOTSUPP;
846
847 dev->ethtool_ops->get_coalesce(dev, &coalesce);
848
849 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
850 return -EFAULT;
851 return 0;
852 }
853
854 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
855 void __user *useraddr)
856 {
857 struct ethtool_coalesce coalesce;
858
859 if (!dev->ethtool_ops->set_coalesce)
860 return -EOPNOTSUPP;
861
862 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
863 return -EFAULT;
864
865 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
866 }
867
868 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
869 {
870 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
871
872 if (!dev->ethtool_ops->get_ringparam)
873 return -EOPNOTSUPP;
874
875 dev->ethtool_ops->get_ringparam(dev, &ringparam);
876
877 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
878 return -EFAULT;
879 return 0;
880 }
881
882 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
883 {
884 struct ethtool_ringparam ringparam;
885
886 if (!dev->ethtool_ops->set_ringparam)
887 return -EOPNOTSUPP;
888
889 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
890 return -EFAULT;
891
892 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
893 }
894
895 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
896 void __user *useraddr)
897 {
898 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
899
900 if (!dev->ethtool_ops->get_channels)
901 return -EOPNOTSUPP;
902
903 dev->ethtool_ops->get_channels(dev, &channels);
904
905 if (copy_to_user(useraddr, &channels, sizeof(channels)))
906 return -EFAULT;
907 return 0;
908 }
909
910 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
911 void __user *useraddr)
912 {
913 struct ethtool_channels channels;
914
915 if (!dev->ethtool_ops->set_channels)
916 return -EOPNOTSUPP;
917
918 if (copy_from_user(&channels, useraddr, sizeof(channels)))
919 return -EFAULT;
920
921 return dev->ethtool_ops->set_channels(dev, &channels);
922 }
923
924 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
925 {
926 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
927
928 if (!dev->ethtool_ops->get_pauseparam)
929 return -EOPNOTSUPP;
930
931 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
932
933 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
934 return -EFAULT;
935 return 0;
936 }
937
938 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
939 {
940 struct ethtool_pauseparam pauseparam;
941
942 if (!dev->ethtool_ops->set_pauseparam)
943 return -EOPNOTSUPP;
944
945 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
946 return -EFAULT;
947
948 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
949 }
950
951 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
952 {
953 struct ethtool_test test;
954 const struct ethtool_ops *ops = dev->ethtool_ops;
955 u64 *data;
956 int ret, test_len;
957
958 if (!ops->self_test || !ops->get_sset_count)
959 return -EOPNOTSUPP;
960
961 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
962 if (test_len < 0)
963 return test_len;
964 WARN_ON(test_len == 0);
965
966 if (copy_from_user(&test, useraddr, sizeof(test)))
967 return -EFAULT;
968
969 test.len = test_len;
970 data = kmalloc(test_len * sizeof(u64), GFP_USER);
971 if (!data)
972 return -ENOMEM;
973
974 ops->self_test(dev, &test, data);
975
976 ret = -EFAULT;
977 if (copy_to_user(useraddr, &test, sizeof(test)))
978 goto out;
979 useraddr += sizeof(test);
980 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
981 goto out;
982 ret = 0;
983
984 out:
985 kfree(data);
986 return ret;
987 }
988
989 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
990 {
991 struct ethtool_gstrings gstrings;
992 u8 *data;
993 int ret;
994
995 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
996 return -EFAULT;
997
998 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
999 if (ret < 0)
1000 return ret;
1001
1002 gstrings.len = ret;
1003
1004 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1005 if (!data)
1006 return -ENOMEM;
1007
1008 __ethtool_get_strings(dev, gstrings.string_set, data);
1009
1010 ret = -EFAULT;
1011 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1012 goto out;
1013 useraddr += sizeof(gstrings);
1014 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1015 goto out;
1016 ret = 0;
1017
1018 out:
1019 kfree(data);
1020 return ret;
1021 }
1022
1023 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1024 {
1025 struct ethtool_value id;
1026 static bool busy;
1027 int rc;
1028
1029 if (!dev->ethtool_ops->set_phys_id)
1030 return -EOPNOTSUPP;
1031
1032 if (busy)
1033 return -EBUSY;
1034
1035 if (copy_from_user(&id, useraddr, sizeof(id)))
1036 return -EFAULT;
1037
1038 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1039 if (rc < 0)
1040 return rc;
1041
1042 /* Drop the RTNL lock while waiting, but prevent reentry or
1043 * removal of the device.
1044 */
1045 busy = true;
1046 dev_hold(dev);
1047 rtnl_unlock();
1048
1049 if (rc == 0) {
1050 /* Driver will handle this itself */
1051 schedule_timeout_interruptible(
1052 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1053 } else {
1054 /* Driver expects to be called at twice the frequency in rc */
1055 int n = rc * 2, i, interval = HZ / n;
1056
1057 /* Count down seconds */
1058 do {
1059 /* Count down iterations per second */
1060 i = n;
1061 do {
1062 rtnl_lock();
1063 rc = dev->ethtool_ops->set_phys_id(dev,
1064 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1065 rtnl_unlock();
1066 if (rc)
1067 break;
1068 schedule_timeout_interruptible(interval);
1069 } while (!signal_pending(current) && --i != 0);
1070 } while (!signal_pending(current) &&
1071 (id.data == 0 || --id.data != 0));
1072 }
1073
1074 rtnl_lock();
1075 dev_put(dev);
1076 busy = false;
1077
1078 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1079 return rc;
1080 }
1081
1082 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1083 {
1084 struct ethtool_stats stats;
1085 const struct ethtool_ops *ops = dev->ethtool_ops;
1086 u64 *data;
1087 int ret, n_stats;
1088
1089 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1090 return -EOPNOTSUPP;
1091
1092 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1093 if (n_stats < 0)
1094 return n_stats;
1095 WARN_ON(n_stats == 0);
1096
1097 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1098 return -EFAULT;
1099
1100 stats.n_stats = n_stats;
1101 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1102 if (!data)
1103 return -ENOMEM;
1104
1105 ops->get_ethtool_stats(dev, &stats, data);
1106
1107 ret = -EFAULT;
1108 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1109 goto out;
1110 useraddr += sizeof(stats);
1111 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1112 goto out;
1113 ret = 0;
1114
1115 out:
1116 kfree(data);
1117 return ret;
1118 }
1119
1120 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1121 {
1122 struct ethtool_perm_addr epaddr;
1123
1124 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1125 return -EFAULT;
1126
1127 if (epaddr.size < dev->addr_len)
1128 return -ETOOSMALL;
1129 epaddr.size = dev->addr_len;
1130
1131 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1132 return -EFAULT;
1133 useraddr += sizeof(epaddr);
1134 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1135 return -EFAULT;
1136 return 0;
1137 }
1138
1139 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1140 u32 cmd, u32 (*actor)(struct net_device *))
1141 {
1142 struct ethtool_value edata = { .cmd = cmd };
1143
1144 if (!actor)
1145 return -EOPNOTSUPP;
1146
1147 edata.data = actor(dev);
1148
1149 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1150 return -EFAULT;
1151 return 0;
1152 }
1153
1154 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1155 void (*actor)(struct net_device *, u32))
1156 {
1157 struct ethtool_value edata;
1158
1159 if (!actor)
1160 return -EOPNOTSUPP;
1161
1162 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1163 return -EFAULT;
1164
1165 actor(dev, edata.data);
1166 return 0;
1167 }
1168
1169 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1170 int (*actor)(struct net_device *, u32))
1171 {
1172 struct ethtool_value edata;
1173
1174 if (!actor)
1175 return -EOPNOTSUPP;
1176
1177 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1178 return -EFAULT;
1179
1180 return actor(dev, edata.data);
1181 }
1182
1183 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1184 char __user *useraddr)
1185 {
1186 struct ethtool_flash efl;
1187
1188 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1189 return -EFAULT;
1190
1191 if (!dev->ethtool_ops->flash_device)
1192 return -EOPNOTSUPP;
1193
1194 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1195
1196 return dev->ethtool_ops->flash_device(dev, &efl);
1197 }
1198
1199 static int ethtool_set_dump(struct net_device *dev,
1200 void __user *useraddr)
1201 {
1202 struct ethtool_dump dump;
1203
1204 if (!dev->ethtool_ops->set_dump)
1205 return -EOPNOTSUPP;
1206
1207 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1208 return -EFAULT;
1209
1210 return dev->ethtool_ops->set_dump(dev, &dump);
1211 }
1212
1213 static int ethtool_get_dump_flag(struct net_device *dev,
1214 void __user *useraddr)
1215 {
1216 int ret;
1217 struct ethtool_dump dump;
1218 const struct ethtool_ops *ops = dev->ethtool_ops;
1219
1220 if (!dev->ethtool_ops->get_dump_flag)
1221 return -EOPNOTSUPP;
1222
1223 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1224 return -EFAULT;
1225
1226 ret = ops->get_dump_flag(dev, &dump);
1227 if (ret)
1228 return ret;
1229
1230 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1231 return -EFAULT;
1232 return 0;
1233 }
1234
1235 static int ethtool_get_dump_data(struct net_device *dev,
1236 void __user *useraddr)
1237 {
1238 int ret;
1239 __u32 len;
1240 struct ethtool_dump dump, tmp;
1241 const struct ethtool_ops *ops = dev->ethtool_ops;
1242 void *data = NULL;
1243
1244 if (!dev->ethtool_ops->get_dump_data ||
1245 !dev->ethtool_ops->get_dump_flag)
1246 return -EOPNOTSUPP;
1247
1248 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1249 return -EFAULT;
1250
1251 memset(&tmp, 0, sizeof(tmp));
1252 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1253 ret = ops->get_dump_flag(dev, &tmp);
1254 if (ret)
1255 return ret;
1256
1257 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1258 if (!len)
1259 return -EFAULT;
1260
1261 data = vzalloc(tmp.len);
1262 if (!data)
1263 return -ENOMEM;
1264 ret = ops->get_dump_data(dev, &dump, data);
1265 if (ret)
1266 goto out;
1267
1268 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1269 ret = -EFAULT;
1270 goto out;
1271 }
1272 useraddr += offsetof(struct ethtool_dump, data);
1273 if (copy_to_user(useraddr, data, len))
1274 ret = -EFAULT;
1275 out:
1276 vfree(data);
1277 return ret;
1278 }
1279
1280 /* The main entry point in this file. Called from net/core/dev.c */
1281
1282 int dev_ethtool(struct net *net, struct ifreq *ifr)
1283 {
1284 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1285 void __user *useraddr = ifr->ifr_data;
1286 u32 ethcmd;
1287 int rc;
1288 u32 old_features;
1289
1290 if (!dev || !netif_device_present(dev))
1291 return -ENODEV;
1292
1293 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
1294 return -EFAULT;
1295
1296 if (!dev->ethtool_ops) {
1297 /* ETHTOOL_GDRVINFO does not require any driver support.
1298 * It is also unprivileged and does not change anything,
1299 * so we can take a shortcut to it. */
1300 if (ethcmd == ETHTOOL_GDRVINFO)
1301 return ethtool_get_drvinfo(dev, useraddr);
1302 else
1303 return -EOPNOTSUPP;
1304 }
1305
1306 /* Allow some commands to be done by anyone */
1307 switch (ethcmd) {
1308 case ETHTOOL_GSET:
1309 case ETHTOOL_GDRVINFO:
1310 case ETHTOOL_GMSGLVL:
1311 case ETHTOOL_GCOALESCE:
1312 case ETHTOOL_GRINGPARAM:
1313 case ETHTOOL_GPAUSEPARAM:
1314 case ETHTOOL_GRXCSUM:
1315 case ETHTOOL_GTXCSUM:
1316 case ETHTOOL_GSG:
1317 case ETHTOOL_GSSET_INFO:
1318 case ETHTOOL_GSTRINGS:
1319 case ETHTOOL_GTSO:
1320 case ETHTOOL_GPERMADDR:
1321 case ETHTOOL_GUFO:
1322 case ETHTOOL_GGSO:
1323 case ETHTOOL_GGRO:
1324 case ETHTOOL_GFLAGS:
1325 case ETHTOOL_GPFLAGS:
1326 case ETHTOOL_GRXFH:
1327 case ETHTOOL_GRXRINGS:
1328 case ETHTOOL_GRXCLSRLCNT:
1329 case ETHTOOL_GRXCLSRULE:
1330 case ETHTOOL_GRXCLSRLALL:
1331 case ETHTOOL_GFEATURES:
1332 break;
1333 default:
1334 if (!capable(CAP_NET_ADMIN))
1335 return -EPERM;
1336 }
1337
1338 if (dev->ethtool_ops->begin) {
1339 rc = dev->ethtool_ops->begin(dev);
1340 if (rc < 0)
1341 return rc;
1342 }
1343 old_features = dev->features;
1344
1345 switch (ethcmd) {
1346 case ETHTOOL_GSET:
1347 rc = ethtool_get_settings(dev, useraddr);
1348 break;
1349 case ETHTOOL_SSET:
1350 rc = ethtool_set_settings(dev, useraddr);
1351 break;
1352 case ETHTOOL_GDRVINFO:
1353 rc = ethtool_get_drvinfo(dev, useraddr);
1354 break;
1355 case ETHTOOL_GREGS:
1356 rc = ethtool_get_regs(dev, useraddr);
1357 break;
1358 case ETHTOOL_GWOL:
1359 rc = ethtool_get_wol(dev, useraddr);
1360 break;
1361 case ETHTOOL_SWOL:
1362 rc = ethtool_set_wol(dev, useraddr);
1363 break;
1364 case ETHTOOL_GMSGLVL:
1365 rc = ethtool_get_value(dev, useraddr, ethcmd,
1366 dev->ethtool_ops->get_msglevel);
1367 break;
1368 case ETHTOOL_SMSGLVL:
1369 rc = ethtool_set_value_void(dev, useraddr,
1370 dev->ethtool_ops->set_msglevel);
1371 break;
1372 case ETHTOOL_NWAY_RST:
1373 rc = ethtool_nway_reset(dev);
1374 break;
1375 case ETHTOOL_GLINK:
1376 rc = ethtool_get_link(dev, useraddr);
1377 break;
1378 case ETHTOOL_GEEPROM:
1379 rc = ethtool_get_eeprom(dev, useraddr);
1380 break;
1381 case ETHTOOL_SEEPROM:
1382 rc = ethtool_set_eeprom(dev, useraddr);
1383 break;
1384 case ETHTOOL_GCOALESCE:
1385 rc = ethtool_get_coalesce(dev, useraddr);
1386 break;
1387 case ETHTOOL_SCOALESCE:
1388 rc = ethtool_set_coalesce(dev, useraddr);
1389 break;
1390 case ETHTOOL_GRINGPARAM:
1391 rc = ethtool_get_ringparam(dev, useraddr);
1392 break;
1393 case ETHTOOL_SRINGPARAM:
1394 rc = ethtool_set_ringparam(dev, useraddr);
1395 break;
1396 case ETHTOOL_GPAUSEPARAM:
1397 rc = ethtool_get_pauseparam(dev, useraddr);
1398 break;
1399 case ETHTOOL_SPAUSEPARAM:
1400 rc = ethtool_set_pauseparam(dev, useraddr);
1401 break;
1402 case ETHTOOL_TEST:
1403 rc = ethtool_self_test(dev, useraddr);
1404 break;
1405 case ETHTOOL_GSTRINGS:
1406 rc = ethtool_get_strings(dev, useraddr);
1407 break;
1408 case ETHTOOL_PHYS_ID:
1409 rc = ethtool_phys_id(dev, useraddr);
1410 break;
1411 case ETHTOOL_GSTATS:
1412 rc = ethtool_get_stats(dev, useraddr);
1413 break;
1414 case ETHTOOL_GPERMADDR:
1415 rc = ethtool_get_perm_addr(dev, useraddr);
1416 break;
1417 case ETHTOOL_GFLAGS:
1418 rc = ethtool_get_value(dev, useraddr, ethcmd,
1419 __ethtool_get_flags);
1420 break;
1421 case ETHTOOL_SFLAGS:
1422 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
1423 break;
1424 case ETHTOOL_GPFLAGS:
1425 rc = ethtool_get_value(dev, useraddr, ethcmd,
1426 dev->ethtool_ops->get_priv_flags);
1427 break;
1428 case ETHTOOL_SPFLAGS:
1429 rc = ethtool_set_value(dev, useraddr,
1430 dev->ethtool_ops->set_priv_flags);
1431 break;
1432 case ETHTOOL_GRXFH:
1433 case ETHTOOL_GRXRINGS:
1434 case ETHTOOL_GRXCLSRLCNT:
1435 case ETHTOOL_GRXCLSRULE:
1436 case ETHTOOL_GRXCLSRLALL:
1437 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1438 break;
1439 case ETHTOOL_SRXFH:
1440 case ETHTOOL_SRXCLSRLDEL:
1441 case ETHTOOL_SRXCLSRLINS:
1442 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1443 break;
1444 case ETHTOOL_FLASHDEV:
1445 rc = ethtool_flash_device(dev, useraddr);
1446 break;
1447 case ETHTOOL_RESET:
1448 rc = ethtool_reset(dev, useraddr);
1449 break;
1450 case ETHTOOL_GSSET_INFO:
1451 rc = ethtool_get_sset_info(dev, useraddr);
1452 break;
1453 case ETHTOOL_GRXFHINDIR:
1454 rc = ethtool_get_rxfh_indir(dev, useraddr);
1455 break;
1456 case ETHTOOL_SRXFHINDIR:
1457 rc = ethtool_set_rxfh_indir(dev, useraddr);
1458 break;
1459 case ETHTOOL_GFEATURES:
1460 rc = ethtool_get_features(dev, useraddr);
1461 break;
1462 case ETHTOOL_SFEATURES:
1463 rc = ethtool_set_features(dev, useraddr);
1464 break;
1465 case ETHTOOL_GTXCSUM:
1466 case ETHTOOL_GRXCSUM:
1467 case ETHTOOL_GSG:
1468 case ETHTOOL_GTSO:
1469 case ETHTOOL_GUFO:
1470 case ETHTOOL_GGSO:
1471 case ETHTOOL_GGRO:
1472 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1473 break;
1474 case ETHTOOL_STXCSUM:
1475 case ETHTOOL_SRXCSUM:
1476 case ETHTOOL_SSG:
1477 case ETHTOOL_STSO:
1478 case ETHTOOL_SUFO:
1479 case ETHTOOL_SGSO:
1480 case ETHTOOL_SGRO:
1481 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1482 break;
1483 case ETHTOOL_GCHANNELS:
1484 rc = ethtool_get_channels(dev, useraddr);
1485 break;
1486 case ETHTOOL_SCHANNELS:
1487 rc = ethtool_set_channels(dev, useraddr);
1488 break;
1489 case ETHTOOL_SET_DUMP:
1490 rc = ethtool_set_dump(dev, useraddr);
1491 break;
1492 case ETHTOOL_GET_DUMP_FLAG:
1493 rc = ethtool_get_dump_flag(dev, useraddr);
1494 break;
1495 case ETHTOOL_GET_DUMP_DATA:
1496 rc = ethtool_get_dump_data(dev, useraddr);
1497 break;
1498 default:
1499 rc = -EOPNOTSUPP;
1500 }
1501
1502 if (dev->ethtool_ops->complete)
1503 dev->ethtool_ops->complete(dev);
1504
1505 if (old_features != dev->features)
1506 netdev_features_change(dev);
1507
1508 return rc;
1509 }
This page took 0.059178 seconds and 4 git commands to generate.