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. We fall back to calling do_ioctl()
7 * for drivers which haven't been converted to ethtool_ops yet.
8 *
9 * It's GPL, stupid.
10 */
11
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/errno.h>
15 #include <linux/ethtool.h>
16 #include <linux/netdevice.h>
17 #include <asm/uaccess.h>
18
19 /*
20 * Some useful ethtool_ops methods that're device independent.
21 * If we find that all drivers want to do the same thing here,
22 * we can turn these into dev_() function calls.
23 */
24
ethtool_op_get_link(struct net_device * dev)25 u32 ethtool_op_get_link(struct net_device *dev)
26 {
27 return netif_carrier_ok(dev) ? 1 : 0;
28 }
29
ethtool_op_get_tx_csum(struct net_device * dev)30 u32 ethtool_op_get_tx_csum(struct net_device *dev)
31 {
32 return (dev->features & NETIF_F_IP_CSUM) != 0;
33 }
34
ethtool_op_set_tx_csum(struct net_device * dev,u32 data)35 int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
36 {
37 if (data)
38 dev->features |= NETIF_F_IP_CSUM;
39 else
40 dev->features &= ~NETIF_F_IP_CSUM;
41
42 return 0;
43 }
44
ethtool_op_get_sg(struct net_device * dev)45 u32 ethtool_op_get_sg(struct net_device *dev)
46 {
47 return (dev->features & NETIF_F_SG) != 0;
48 }
49
ethtool_op_set_sg(struct net_device * dev,u32 data)50 int ethtool_op_set_sg(struct net_device *dev, u32 data)
51 {
52 if (data)
53 dev->features |= NETIF_F_SG;
54 else
55 dev->features &= ~NETIF_F_SG;
56
57 return 0;
58 }
59
60 #ifdef NETIF_F_TSO
ethtool_op_get_tso(struct net_device * dev)61 u32 ethtool_op_get_tso(struct net_device *dev)
62 {
63 return (dev->features & NETIF_F_TSO) != 0;
64 }
65
ethtool_op_set_tso(struct net_device * dev,u32 data)66 int ethtool_op_set_tso(struct net_device *dev, u32 data)
67 {
68 if (data)
69 dev->features |= NETIF_F_TSO;
70 else
71 dev->features &= ~NETIF_F_TSO;
72
73 return 0;
74 }
75 #endif /* NETIF_F_TSO */
76
77 /* Handlers for each ethtool command */
78
ethtool_get_settings(struct net_device * dev,void __user * useraddr)79 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
80 {
81 struct ethtool_cmd cmd = { ETHTOOL_GSET };
82 int err;
83
84 if (!dev->ethtool_ops->get_settings)
85 return -EOPNOTSUPP;
86
87 err = dev->ethtool_ops->get_settings(dev, &cmd);
88 if (err < 0)
89 return err;
90
91 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
92 return -EFAULT;
93 return 0;
94 }
95
ethtool_set_settings(struct net_device * dev,void __user * useraddr)96 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
97 {
98 struct ethtool_cmd cmd;
99
100 if (!dev->ethtool_ops->set_settings)
101 return -EOPNOTSUPP;
102
103 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
104 return -EFAULT;
105
106 return dev->ethtool_ops->set_settings(dev, &cmd);
107 }
108
ethtool_get_drvinfo(struct net_device * dev,void __user * useraddr)109 static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
110 {
111 struct ethtool_drvinfo info;
112 struct ethtool_ops *ops = dev->ethtool_ops;
113
114 if (!ops->get_drvinfo)
115 return -EOPNOTSUPP;
116
117 memset(&info, 0, sizeof(info));
118 info.cmd = ETHTOOL_GDRVINFO;
119 ops->get_drvinfo(dev, &info);
120
121 if (ops->self_test_count)
122 info.testinfo_len = ops->self_test_count(dev);
123 if (ops->get_stats_count)
124 info.n_stats = ops->get_stats_count(dev);
125 if (ops->get_regs_len)
126 info.regdump_len = ops->get_regs_len(dev);
127 if (ops->get_eeprom_len)
128 info.eedump_len = ops->get_eeprom_len(dev);
129
130 if (copy_to_user(useraddr, &info, sizeof(info)))
131 return -EFAULT;
132 return 0;
133 }
134
ethtool_get_regs(struct net_device * dev,char __user * useraddr)135 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
136 {
137 struct ethtool_regs regs;
138 struct ethtool_ops *ops = dev->ethtool_ops;
139 void *regbuf;
140 int reglen, ret;
141
142 if (!ops->get_regs || !ops->get_regs_len)
143 return -EOPNOTSUPP;
144
145 if (copy_from_user(®s, useraddr, sizeof(regs)))
146 return -EFAULT;
147
148 reglen = ops->get_regs_len(dev);
149 if (regs.len > reglen)
150 regs.len = reglen;
151
152 regbuf = kmalloc(reglen, GFP_USER);
153 if (!regbuf)
154 return -ENOMEM;
155
156 ops->get_regs(dev, ®s, regbuf);
157
158 ret = -EFAULT;
159 if (copy_to_user(useraddr, ®s, sizeof(regs)))
160 goto out;
161 useraddr += offsetof(struct ethtool_regs, data);
162 if (copy_to_user(useraddr, regbuf, regs.len))
163 goto out;
164 ret = 0;
165
166 out:
167 kfree(regbuf);
168 return ret;
169 }
170
ethtool_get_wol(struct net_device * dev,char __user * useraddr)171 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
172 {
173 struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
174
175 if (!dev->ethtool_ops->get_wol)
176 return -EOPNOTSUPP;
177
178 dev->ethtool_ops->get_wol(dev, &wol);
179
180 if (copy_to_user(useraddr, &wol, sizeof(wol)))
181 return -EFAULT;
182 return 0;
183 }
184
ethtool_set_wol(struct net_device * dev,char __user * useraddr)185 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
186 {
187 struct ethtool_wolinfo wol;
188
189 if (!dev->ethtool_ops->set_wol)
190 return -EOPNOTSUPP;
191
192 if (copy_from_user(&wol, useraddr, sizeof(wol)))
193 return -EFAULT;
194
195 return dev->ethtool_ops->set_wol(dev, &wol);
196 }
197
ethtool_get_msglevel(struct net_device * dev,char __user * useraddr)198 static int ethtool_get_msglevel(struct net_device *dev, char __user *useraddr)
199 {
200 struct ethtool_value edata = { ETHTOOL_GMSGLVL };
201
202 if (!dev->ethtool_ops->get_msglevel)
203 return -EOPNOTSUPP;
204
205 edata.data = dev->ethtool_ops->get_msglevel(dev);
206
207 if (copy_to_user(useraddr, &edata, sizeof(edata)))
208 return -EFAULT;
209 return 0;
210 }
211
ethtool_set_msglevel(struct net_device * dev,char __user * useraddr)212 static int ethtool_set_msglevel(struct net_device *dev, char __user *useraddr)
213 {
214 struct ethtool_value edata;
215
216 if (!dev->ethtool_ops->set_msglevel)
217 return -EOPNOTSUPP;
218
219 if (copy_from_user(&edata, useraddr, sizeof(edata)))
220 return -EFAULT;
221
222 dev->ethtool_ops->set_msglevel(dev, edata.data);
223 return 0;
224 }
225
ethtool_nway_reset(struct net_device * dev)226 static int ethtool_nway_reset(struct net_device *dev)
227 {
228 if (!dev->ethtool_ops->nway_reset)
229 return -EOPNOTSUPP;
230
231 return dev->ethtool_ops->nway_reset(dev);
232 }
233
ethtool_get_link(struct net_device * dev,void __user * useraddr)234 static int ethtool_get_link(struct net_device *dev, void __user *useraddr)
235 {
236 struct ethtool_value edata = { ETHTOOL_GLINK };
237
238 if (!dev->ethtool_ops->get_link)
239 return -EOPNOTSUPP;
240
241 edata.data = dev->ethtool_ops->get_link(dev);
242
243 if (copy_to_user(useraddr, &edata, sizeof(edata)))
244 return -EFAULT;
245 return 0;
246 }
247
ethtool_get_eeprom(struct net_device * dev,void __user * useraddr)248 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
249 {
250 struct ethtool_eeprom eeprom;
251 struct ethtool_ops *ops = dev->ethtool_ops;
252 u8 *data;
253 int ret;
254
255 if (!ops->get_eeprom || !ops->get_eeprom_len)
256 return -EOPNOTSUPP;
257
258 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
259 return -EFAULT;
260
261 /* Check for wrap and zero */
262 if (eeprom.offset + eeprom.len <= eeprom.offset)
263 return -EINVAL;
264
265 /* Check for exceeding total eeprom len */
266 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
267 return -EINVAL;
268
269 data = kmalloc(eeprom.len, GFP_USER);
270 if (!data)
271 return -ENOMEM;
272
273 ret = -EFAULT;
274 if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
275 goto out;
276
277 ret = ops->get_eeprom(dev, &eeprom, data);
278 if (ret)
279 goto out;
280
281 ret = -EFAULT;
282 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
283 goto out;
284 if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
285 goto out;
286 ret = 0;
287
288 out:
289 kfree(data);
290 return ret;
291 }
292
ethtool_set_eeprom(struct net_device * dev,void __user * useraddr)293 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
294 {
295 struct ethtool_eeprom eeprom;
296 struct ethtool_ops *ops = dev->ethtool_ops;
297 u8 *data;
298 int ret;
299
300 if (!ops->set_eeprom || !ops->get_eeprom_len)
301 return -EOPNOTSUPP;
302
303 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
304 return -EFAULT;
305
306 /* Check for wrap and zero */
307 if (eeprom.offset + eeprom.len <= eeprom.offset)
308 return -EINVAL;
309
310 /* Check for exceeding total eeprom len */
311 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
312 return -EINVAL;
313
314 data = kmalloc(eeprom.len, GFP_USER);
315 if (!data)
316 return -ENOMEM;
317
318 ret = -EFAULT;
319 if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
320 goto out;
321
322 ret = ops->set_eeprom(dev, &eeprom, data);
323 if (ret)
324 goto out;
325
326 if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
327 ret = -EFAULT;
328
329 out:
330 kfree(data);
331 return ret;
332 }
333
ethtool_get_coalesce(struct net_device * dev,void __user * useraddr)334 static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
335 {
336 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
337
338 if (!dev->ethtool_ops->get_coalesce)
339 return -EOPNOTSUPP;
340
341 dev->ethtool_ops->get_coalesce(dev, &coalesce);
342
343 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
344 return -EFAULT;
345 return 0;
346 }
347
ethtool_set_coalesce(struct net_device * dev,void __user * useraddr)348 static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
349 {
350 struct ethtool_coalesce coalesce;
351
352 if (!dev->ethtool_ops->set_coalesce)
353 return -EOPNOTSUPP;
354
355 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
356 return -EFAULT;
357
358 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
359 }
360
ethtool_get_ringparam(struct net_device * dev,void __user * useraddr)361 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
362 {
363 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
364
365 if (!dev->ethtool_ops->get_ringparam)
366 return -EOPNOTSUPP;
367
368 dev->ethtool_ops->get_ringparam(dev, &ringparam);
369
370 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
371 return -EFAULT;
372 return 0;
373 }
374
ethtool_set_ringparam(struct net_device * dev,void __user * useraddr)375 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
376 {
377 struct ethtool_ringparam ringparam;
378
379 if (!dev->ethtool_ops->set_ringparam)
380 return -EOPNOTSUPP;
381
382 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
383 return -EFAULT;
384
385 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
386 }
387
ethtool_get_pauseparam(struct net_device * dev,void __user * useraddr)388 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
389 {
390 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
391
392 if (!dev->ethtool_ops->get_pauseparam)
393 return -EOPNOTSUPP;
394
395 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
396
397 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
398 return -EFAULT;
399 return 0;
400 }
401
ethtool_set_pauseparam(struct net_device * dev,void __user * useraddr)402 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
403 {
404 struct ethtool_pauseparam pauseparam;
405
406 if (!dev->ethtool_ops->set_pauseparam)
407 return -EOPNOTSUPP;
408
409 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
410 return -EFAULT;
411
412 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
413 }
414
ethtool_get_rx_csum(struct net_device * dev,char __user * useraddr)415 static int ethtool_get_rx_csum(struct net_device *dev, char __user *useraddr)
416 {
417 struct ethtool_value edata = { ETHTOOL_GRXCSUM };
418
419 if (!dev->ethtool_ops->get_rx_csum)
420 return -EOPNOTSUPP;
421
422 edata.data = dev->ethtool_ops->get_rx_csum(dev);
423
424 if (copy_to_user(useraddr, &edata, sizeof(edata)))
425 return -EFAULT;
426 return 0;
427 }
428
ethtool_set_rx_csum(struct net_device * dev,char __user * useraddr)429 static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
430 {
431 struct ethtool_value edata;
432
433 if (!dev->ethtool_ops->set_rx_csum)
434 return -EOPNOTSUPP;
435
436 if (copy_from_user(&edata, useraddr, sizeof(edata)))
437 return -EFAULT;
438
439 dev->ethtool_ops->set_rx_csum(dev, edata.data);
440 return 0;
441 }
442
ethtool_get_tx_csum(struct net_device * dev,char __user * useraddr)443 static int ethtool_get_tx_csum(struct net_device *dev, char __user *useraddr)
444 {
445 struct ethtool_value edata = { ETHTOOL_GTXCSUM };
446
447 if (!dev->ethtool_ops->get_tx_csum)
448 return -EOPNOTSUPP;
449
450 edata.data = dev->ethtool_ops->get_tx_csum(dev);
451
452 if (copy_to_user(useraddr, &edata, sizeof(edata)))
453 return -EFAULT;
454 return 0;
455 }
456
ethtool_set_tx_csum(struct net_device * dev,char __user * useraddr)457 static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
458 {
459 struct ethtool_value edata;
460
461 if (!dev->ethtool_ops->set_tx_csum)
462 return -EOPNOTSUPP;
463
464 if (copy_from_user(&edata, useraddr, sizeof(edata)))
465 return -EFAULT;
466
467 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
468 }
469
ethtool_get_sg(struct net_device * dev,char __user * useraddr)470 static int ethtool_get_sg(struct net_device *dev, char __user *useraddr)
471 {
472 struct ethtool_value edata = { ETHTOOL_GSG };
473
474 if (!dev->ethtool_ops->get_sg)
475 return -EOPNOTSUPP;
476
477 edata.data = dev->ethtool_ops->get_sg(dev);
478
479 if (copy_to_user(useraddr, &edata, sizeof(edata)))
480 return -EFAULT;
481 return 0;
482 }
483
ethtool_set_sg(struct net_device * dev,char __user * useraddr)484 static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
485 {
486 struct ethtool_value edata;
487
488 if (!dev->ethtool_ops->set_sg)
489 return -EOPNOTSUPP;
490
491 if (copy_from_user(&edata, useraddr, sizeof(edata)))
492 return -EFAULT;
493
494 return dev->ethtool_ops->set_sg(dev, edata.data);
495 }
496
497 #ifdef NETIF_F_TSO
ethtool_get_tso(struct net_device * dev,char __user * useraddr)498 static int ethtool_get_tso(struct net_device *dev, char __user *useraddr)
499 {
500 struct ethtool_value edata = { ETHTOOL_GTSO };
501
502 if (!dev->ethtool_ops->get_tso)
503 return -EOPNOTSUPP;
504
505 edata.data = dev->ethtool_ops->get_tso(dev);
506
507 if (copy_to_user(useraddr, &edata, sizeof(edata)))
508 return -EFAULT;
509 return 0;
510 }
511
ethtool_set_tso(struct net_device * dev,char __user * useraddr)512 static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
513 {
514 struct ethtool_value edata;
515
516 if (!dev->ethtool_ops->set_tso)
517 return -EOPNOTSUPP;
518
519 if (copy_from_user(&edata, useraddr, sizeof(edata)))
520 return -EFAULT;
521
522 return dev->ethtool_ops->set_tso(dev, edata.data);
523 }
524
525 EXPORT_SYMBOL(ethtool_op_get_tso);
526 EXPORT_SYMBOL(ethtool_op_set_tso);
527 #endif /* NETIF_F_TSO */
528
ethtool_self_test(struct net_device * dev,char __user * useraddr)529 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
530 {
531 struct ethtool_test test;
532 struct ethtool_ops *ops = dev->ethtool_ops;
533 u64 *data;
534 int ret;
535
536 if (!ops->self_test || !ops->self_test_count)
537 return -EOPNOTSUPP;
538
539 if (copy_from_user(&test, useraddr, sizeof(test)))
540 return -EFAULT;
541
542 test.len = ops->self_test_count(dev);
543 data = kmalloc(test.len * sizeof(u64), GFP_USER);
544 if (!data)
545 return -ENOMEM;
546
547 ops->self_test(dev, &test, data);
548
549 ret = -EFAULT;
550 if (copy_to_user(useraddr, &test, sizeof(test)))
551 goto out;
552 useraddr += sizeof(test);
553 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
554 goto out;
555 ret = 0;
556
557 out:
558 kfree(data);
559 return ret;
560 }
561
ethtool_get_strings(struct net_device * dev,void __user * useraddr)562 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
563 {
564 struct ethtool_gstrings gstrings;
565 struct ethtool_ops *ops = dev->ethtool_ops;
566 u8 *data;
567 int ret;
568
569 if (!ops->get_strings)
570 return -EOPNOTSUPP;
571
572 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
573 return -EFAULT;
574
575 switch (gstrings.string_set) {
576 case ETH_SS_TEST:
577 if (!ops->self_test_count)
578 return -EOPNOTSUPP;
579 gstrings.len = ops->self_test_count(dev);
580 break;
581 case ETH_SS_STATS:
582 if (!ops->get_stats_count)
583 return -EOPNOTSUPP;
584 gstrings.len = ops->get_stats_count(dev);
585 break;
586 default:
587 return -EINVAL;
588 }
589
590 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
591 if (!data)
592 return -ENOMEM;
593
594 ops->get_strings(dev, gstrings.string_set, data);
595
596 ret = -EFAULT;
597 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
598 goto out;
599 useraddr += sizeof(gstrings);
600 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
601 goto out;
602 ret = 0;
603
604 out:
605 kfree(data);
606 return ret;
607 }
608
ethtool_phys_id(struct net_device * dev,void __user * useraddr)609 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
610 {
611 struct ethtool_value id;
612
613 if (!dev->ethtool_ops->phys_id)
614 return -EOPNOTSUPP;
615
616 if (copy_from_user(&id, useraddr, sizeof(id)))
617 return -EFAULT;
618
619 return dev->ethtool_ops->phys_id(dev, id.data);
620 }
621
ethtool_get_stats(struct net_device * dev,void __user * useraddr)622 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
623 {
624 struct ethtool_stats stats;
625 struct ethtool_ops *ops = dev->ethtool_ops;
626 u64 *data;
627 int ret;
628
629 if (!ops->get_ethtool_stats || !ops->get_stats_count)
630 return -EOPNOTSUPP;
631
632 if (copy_from_user(&stats, useraddr, sizeof(stats)))
633 return -EFAULT;
634
635 stats.n_stats = ops->get_stats_count(dev);
636 data = kmalloc(stats.n_stats * sizeof(u64), GFP_USER);
637 if (!data)
638 return -ENOMEM;
639
640 ops->get_ethtool_stats(dev, &stats, data);
641
642 ret = -EFAULT;
643 if (copy_to_user(useraddr, &stats, sizeof(stats)))
644 goto out;
645 useraddr += sizeof(stats);
646 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
647 goto out;
648 ret = 0;
649
650 out:
651 kfree(data);
652 return ret;
653 }
654
655 /* The main entry point in this file. Called from net/core/dev.c */
656
dev_ethtool(struct ifreq * ifr)657 int dev_ethtool(struct ifreq *ifr)
658 {
659 struct net_device *dev = __dev_get_by_name(ifr->ifr_name);
660 void __user *useraddr = ifr->ifr_data;
661 u32 ethcmd;
662 int rc;
663
664 /*
665 * XXX: This can be pushed down into the ethtool_* handlers that
666 * need it. Keep existing behaviour for the moment.
667 */
668 if (!capable(CAP_NET_ADMIN))
669 return -EPERM;
670
671 if (!dev || !netif_device_present(dev))
672 return -ENODEV;
673
674 if (!dev->ethtool_ops)
675 goto ioctl;
676
677 if (copy_from_user(ðcmd, useraddr, sizeof (ethcmd)))
678 return -EFAULT;
679
680 if(dev->ethtool_ops->begin)
681 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
682 return rc;
683
684 switch (ethcmd) {
685 case ETHTOOL_GSET:
686 rc = ethtool_get_settings(dev, useraddr);
687 break;
688 case ETHTOOL_SSET:
689 rc = ethtool_set_settings(dev, useraddr);
690 break;
691 case ETHTOOL_GDRVINFO:
692 rc = ethtool_get_drvinfo(dev, useraddr);
693
694 break;
695 case ETHTOOL_GREGS:
696 rc = ethtool_get_regs(dev, useraddr);
697 break;
698 case ETHTOOL_GWOL:
699 rc = ethtool_get_wol(dev, useraddr);
700 break;
701 case ETHTOOL_SWOL:
702 rc = ethtool_set_wol(dev, useraddr);
703 break;
704 case ETHTOOL_GMSGLVL:
705 rc = ethtool_get_msglevel(dev, useraddr);
706 break;
707 case ETHTOOL_SMSGLVL:
708 rc = ethtool_set_msglevel(dev, useraddr);
709 break;
710 case ETHTOOL_NWAY_RST:
711 rc = ethtool_nway_reset(dev);
712 break;
713 case ETHTOOL_GLINK:
714 rc = ethtool_get_link(dev, useraddr);
715 break;
716 case ETHTOOL_GEEPROM:
717 rc = ethtool_get_eeprom(dev, useraddr);
718 break;
719 case ETHTOOL_SEEPROM:
720 rc = ethtool_set_eeprom(dev, useraddr);
721 break;
722 case ETHTOOL_GCOALESCE:
723 rc = ethtool_get_coalesce(dev, useraddr);
724 break;
725 case ETHTOOL_SCOALESCE:
726 rc = ethtool_set_coalesce(dev, useraddr);
727 break;
728 case ETHTOOL_GRINGPARAM:
729 rc = ethtool_get_ringparam(dev, useraddr);
730 break;
731 case ETHTOOL_SRINGPARAM:
732 rc = ethtool_set_ringparam(dev, useraddr);
733 break;
734 case ETHTOOL_GPAUSEPARAM:
735 rc = ethtool_get_pauseparam(dev, useraddr);
736 break;
737 case ETHTOOL_SPAUSEPARAM:
738 rc = ethtool_set_pauseparam(dev, useraddr);
739 break;
740 case ETHTOOL_GRXCSUM:
741 rc = ethtool_get_rx_csum(dev, useraddr);
742 break;
743 case ETHTOOL_SRXCSUM:
744 rc = ethtool_set_rx_csum(dev, useraddr);
745 break;
746 case ETHTOOL_GTXCSUM:
747 rc = ethtool_get_tx_csum(dev, useraddr);
748 break;
749 case ETHTOOL_STXCSUM:
750 rc = ethtool_set_tx_csum(dev, useraddr);
751 break;
752 case ETHTOOL_GSG:
753 rc = ethtool_get_sg(dev, useraddr);
754 break;
755 case ETHTOOL_SSG:
756 rc = ethtool_set_sg(dev, useraddr);
757 break;
758 #ifdef NETIF_F_TSO
759 case ETHTOOL_GTSO:
760 rc = ethtool_get_tso(dev, useraddr);
761 break;
762 case ETHTOOL_STSO:
763 rc = ethtool_set_tso(dev, useraddr);
764 break;
765 #endif /* NETIF_F_TSO */
766 case ETHTOOL_TEST:
767 rc = ethtool_self_test(dev, useraddr);
768 break;
769 case ETHTOOL_GSTRINGS:
770 rc = ethtool_get_strings(dev, useraddr);
771 break;
772 case ETHTOOL_PHYS_ID:
773 rc = ethtool_phys_id(dev, useraddr);
774 break;
775 case ETHTOOL_GSTATS:
776 rc = ethtool_get_stats(dev, useraddr);
777 break;
778 default:
779 rc = -EOPNOTSUPP;
780 }
781
782 if(dev->ethtool_ops->complete)
783 dev->ethtool_ops->complete(dev);
784 return rc;
785
786 ioctl:
787 if (dev->do_ioctl)
788 return dev->do_ioctl(dev, ifr, SIOCETHTOOL);
789 return -EOPNOTSUPP;
790 }
791
792 EXPORT_SYMBOL(dev_ethtool);
793 EXPORT_SYMBOL(ethtool_op_get_link);
794 EXPORT_SYMBOL(ethtool_op_get_sg);
795 EXPORT_SYMBOL(ethtool_op_get_tx_csum);
796 EXPORT_SYMBOL(ethtool_op_set_sg);
797 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
798