ARM: 6280/1: imx: Fix build failure when including <mach/gpio.h> without <linux/spinl...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / core / ethtool.c
blobf4d6a129605148865f77772a8813d14d5175b873
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/slab.h>
22 #include <asm/uaccess.h>
25 * Some useful ethtool_ops methods that're device independent.
26 * If we find that all drivers want to do the same thing here,
27 * we can turn these into dev_() function calls.
30 u32 ethtool_op_get_link(struct net_device *dev)
32 return netif_carrier_ok(dev) ? 1 : 0;
35 u32 ethtool_op_get_rx_csum(struct net_device *dev)
37 return (dev->features & NETIF_F_ALL_CSUM) != 0;
39 EXPORT_SYMBOL(ethtool_op_get_rx_csum);
41 u32 ethtool_op_get_tx_csum(struct net_device *dev)
43 return (dev->features & NETIF_F_ALL_CSUM) != 0;
45 EXPORT_SYMBOL(ethtool_op_get_tx_csum);
47 int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
49 if (data)
50 dev->features |= NETIF_F_IP_CSUM;
51 else
52 dev->features &= ~NETIF_F_IP_CSUM;
54 return 0;
57 int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
59 if (data)
60 dev->features |= NETIF_F_HW_CSUM;
61 else
62 dev->features &= ~NETIF_F_HW_CSUM;
64 return 0;
67 int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
69 if (data)
70 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
71 else
72 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
74 return 0;
77 u32 ethtool_op_get_sg(struct net_device *dev)
79 return (dev->features & NETIF_F_SG) != 0;
82 int ethtool_op_set_sg(struct net_device *dev, u32 data)
84 if (data)
85 dev->features |= NETIF_F_SG;
86 else
87 dev->features &= ~NETIF_F_SG;
89 return 0;
92 u32 ethtool_op_get_tso(struct net_device *dev)
94 return (dev->features & NETIF_F_TSO) != 0;
97 int ethtool_op_set_tso(struct net_device *dev, u32 data)
99 if (data)
100 dev->features |= NETIF_F_TSO;
101 else
102 dev->features &= ~NETIF_F_TSO;
104 return 0;
107 u32 ethtool_op_get_ufo(struct net_device *dev)
109 return (dev->features & NETIF_F_UFO) != 0;
112 int ethtool_op_set_ufo(struct net_device *dev, u32 data)
114 if (data)
115 dev->features |= NETIF_F_UFO;
116 else
117 dev->features &= ~NETIF_F_UFO;
118 return 0;
121 /* the following list of flags are the same as their associated
122 * NETIF_F_xxx values in include/linux/netdevice.h
124 static const u32 flags_dup_features =
125 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
127 u32 ethtool_op_get_flags(struct net_device *dev)
129 /* in the future, this function will probably contain additional
130 * handling for flags which are not so easily handled
131 * by a simple masking operation
134 return dev->features & flags_dup_features;
137 int ethtool_op_set_flags(struct net_device *dev, u32 data)
139 const struct ethtool_ops *ops = dev->ethtool_ops;
140 unsigned long features = dev->features;
142 if (data & ETH_FLAG_LRO)
143 features |= NETIF_F_LRO;
144 else
145 features &= ~NETIF_F_LRO;
147 if (data & ETH_FLAG_NTUPLE) {
148 if (!ops->set_rx_ntuple)
149 return -EOPNOTSUPP;
150 features |= NETIF_F_NTUPLE;
151 } else {
152 /* safe to clear regardless */
153 features &= ~NETIF_F_NTUPLE;
156 dev->features = features;
157 return 0;
160 void ethtool_ntuple_flush(struct net_device *dev)
162 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
164 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
165 list_del(&fsc->list);
166 kfree(fsc);
168 dev->ethtool_ntuple_list.count = 0;
170 EXPORT_SYMBOL(ethtool_ntuple_flush);
172 /* Handlers for each ethtool command */
174 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
176 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
177 int err;
179 if (!dev->ethtool_ops->get_settings)
180 return -EOPNOTSUPP;
182 err = dev->ethtool_ops->get_settings(dev, &cmd);
183 if (err < 0)
184 return err;
186 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
187 return -EFAULT;
188 return 0;
191 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
193 struct ethtool_cmd cmd;
195 if (!dev->ethtool_ops->set_settings)
196 return -EOPNOTSUPP;
198 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
199 return -EFAULT;
201 return dev->ethtool_ops->set_settings(dev, &cmd);
204 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
206 struct ethtool_drvinfo info;
207 const struct ethtool_ops *ops = dev->ethtool_ops;
209 if (!ops->get_drvinfo)
210 return -EOPNOTSUPP;
212 memset(&info, 0, sizeof(info));
213 info.cmd = ETHTOOL_GDRVINFO;
214 ops->get_drvinfo(dev, &info);
217 * this method of obtaining string set info is deprecated;
218 * Use ETHTOOL_GSSET_INFO instead.
220 if (ops->get_sset_count) {
221 int rc;
223 rc = ops->get_sset_count(dev, ETH_SS_TEST);
224 if (rc >= 0)
225 info.testinfo_len = rc;
226 rc = ops->get_sset_count(dev, ETH_SS_STATS);
227 if (rc >= 0)
228 info.n_stats = rc;
229 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
230 if (rc >= 0)
231 info.n_priv_flags = rc;
233 if (ops->get_regs_len)
234 info.regdump_len = ops->get_regs_len(dev);
235 if (ops->get_eeprom_len)
236 info.eedump_len = ops->get_eeprom_len(dev);
238 if (copy_to_user(useraddr, &info, sizeof(info)))
239 return -EFAULT;
240 return 0;
243 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
244 void __user *useraddr)
246 struct ethtool_sset_info info;
247 const struct ethtool_ops *ops = dev->ethtool_ops;
248 u64 sset_mask;
249 int i, idx = 0, n_bits = 0, ret, rc;
250 u32 *info_buf = NULL;
252 if (!ops->get_sset_count)
253 return -EOPNOTSUPP;
255 if (copy_from_user(&info, useraddr, sizeof(info)))
256 return -EFAULT;
258 /* store copy of mask, because we zero struct later on */
259 sset_mask = info.sset_mask;
260 if (!sset_mask)
261 return 0;
263 /* calculate size of return buffer */
264 n_bits = hweight64(sset_mask);
266 memset(&info, 0, sizeof(info));
267 info.cmd = ETHTOOL_GSSET_INFO;
269 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
270 if (!info_buf)
271 return -ENOMEM;
274 * fill return buffer based on input bitmask and successful
275 * get_sset_count return
277 for (i = 0; i < 64; i++) {
278 if (!(sset_mask & (1ULL << i)))
279 continue;
281 rc = ops->get_sset_count(dev, i);
282 if (rc >= 0) {
283 info.sset_mask |= (1ULL << i);
284 info_buf[idx++] = rc;
288 ret = -EFAULT;
289 if (copy_to_user(useraddr, &info, sizeof(info)))
290 goto out;
292 useraddr += offsetof(struct ethtool_sset_info, data);
293 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
294 goto out;
296 ret = 0;
298 out:
299 kfree(info_buf);
300 return ret;
303 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
304 u32 cmd, void __user *useraddr)
306 struct ethtool_rxnfc info;
307 size_t info_size = sizeof(info);
309 if (!dev->ethtool_ops->set_rxnfc)
310 return -EOPNOTSUPP;
312 /* struct ethtool_rxnfc was originally defined for
313 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
314 * members. User-space might still be using that
315 * definition. */
316 if (cmd == ETHTOOL_SRXFH)
317 info_size = (offsetof(struct ethtool_rxnfc, data) +
318 sizeof(info.data));
320 if (copy_from_user(&info, useraddr, info_size))
321 return -EFAULT;
323 return dev->ethtool_ops->set_rxnfc(dev, &info);
326 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
327 u32 cmd, void __user *useraddr)
329 struct ethtool_rxnfc info;
330 size_t info_size = sizeof(info);
331 const struct ethtool_ops *ops = dev->ethtool_ops;
332 int ret;
333 void *rule_buf = NULL;
335 if (!ops->get_rxnfc)
336 return -EOPNOTSUPP;
338 /* struct ethtool_rxnfc was originally defined for
339 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
340 * members. User-space might still be using that
341 * definition. */
342 if (cmd == ETHTOOL_GRXFH)
343 info_size = (offsetof(struct ethtool_rxnfc, data) +
344 sizeof(info.data));
346 if (copy_from_user(&info, useraddr, info_size))
347 return -EFAULT;
349 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
350 if (info.rule_cnt > 0) {
351 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
352 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
353 GFP_USER);
354 if (!rule_buf)
355 return -ENOMEM;
359 ret = ops->get_rxnfc(dev, &info, rule_buf);
360 if (ret < 0)
361 goto err_out;
363 ret = -EFAULT;
364 if (copy_to_user(useraddr, &info, info_size))
365 goto err_out;
367 if (rule_buf) {
368 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
369 if (copy_to_user(useraddr, rule_buf,
370 info.rule_cnt * sizeof(u32)))
371 goto err_out;
373 ret = 0;
375 err_out:
376 kfree(rule_buf);
378 return ret;
381 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
382 struct ethtool_rx_ntuple_flow_spec *spec,
383 struct ethtool_rx_ntuple_flow_spec_container *fsc)
386 /* don't add filters forever */
387 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
388 /* free the container */
389 kfree(fsc);
390 return;
393 /* Copy the whole filter over */
394 fsc->fs.flow_type = spec->flow_type;
395 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
396 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
398 fsc->fs.vlan_tag = spec->vlan_tag;
399 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
400 fsc->fs.data = spec->data;
401 fsc->fs.data_mask = spec->data_mask;
402 fsc->fs.action = spec->action;
404 /* add to the list */
405 list_add_tail_rcu(&fsc->list, &list->list);
406 list->count++;
409 static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
411 struct ethtool_rx_ntuple cmd;
412 const struct ethtool_ops *ops = dev->ethtool_ops;
413 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
414 int ret;
416 if (!(dev->features & NETIF_F_NTUPLE))
417 return -EINVAL;
419 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
420 return -EFAULT;
423 * Cache filter in dev struct for GET operation only if
424 * the underlying driver doesn't have its own GET operation, and
425 * only if the filter was added successfully. First make sure we
426 * can allocate the filter, then continue if successful.
428 if (!ops->get_rx_ntuple) {
429 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
430 if (!fsc)
431 return -ENOMEM;
434 ret = ops->set_rx_ntuple(dev, &cmd);
435 if (ret) {
436 kfree(fsc);
437 return ret;
440 if (!ops->get_rx_ntuple)
441 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
443 return ret;
446 static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
448 struct ethtool_gstrings gstrings;
449 const struct ethtool_ops *ops = dev->ethtool_ops;
450 struct ethtool_rx_ntuple_flow_spec_container *fsc;
451 u8 *data;
452 char *p;
453 int ret, i, num_strings = 0;
455 if (!ops->get_sset_count)
456 return -EOPNOTSUPP;
458 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
459 return -EFAULT;
461 ret = ops->get_sset_count(dev, gstrings.string_set);
462 if (ret < 0)
463 return ret;
465 gstrings.len = ret;
467 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
468 if (!data)
469 return -ENOMEM;
471 if (ops->get_rx_ntuple) {
472 /* driver-specific filter grab */
473 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
474 goto copy;
477 /* default ethtool filter grab */
478 i = 0;
479 p = (char *)data;
480 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
481 sprintf(p, "Filter %d:\n", i);
482 p += ETH_GSTRING_LEN;
483 num_strings++;
485 switch (fsc->fs.flow_type) {
486 case TCP_V4_FLOW:
487 sprintf(p, "\tFlow Type: TCP\n");
488 p += ETH_GSTRING_LEN;
489 num_strings++;
490 break;
491 case UDP_V4_FLOW:
492 sprintf(p, "\tFlow Type: UDP\n");
493 p += ETH_GSTRING_LEN;
494 num_strings++;
495 break;
496 case SCTP_V4_FLOW:
497 sprintf(p, "\tFlow Type: SCTP\n");
498 p += ETH_GSTRING_LEN;
499 num_strings++;
500 break;
501 case AH_ESP_V4_FLOW:
502 sprintf(p, "\tFlow Type: AH ESP\n");
503 p += ETH_GSTRING_LEN;
504 num_strings++;
505 break;
506 case ESP_V4_FLOW:
507 sprintf(p, "\tFlow Type: ESP\n");
508 p += ETH_GSTRING_LEN;
509 num_strings++;
510 break;
511 case IP_USER_FLOW:
512 sprintf(p, "\tFlow Type: Raw IP\n");
513 p += ETH_GSTRING_LEN;
514 num_strings++;
515 break;
516 case IPV4_FLOW:
517 sprintf(p, "\tFlow Type: IPv4\n");
518 p += ETH_GSTRING_LEN;
519 num_strings++;
520 break;
521 default:
522 sprintf(p, "\tFlow Type: Unknown\n");
523 p += ETH_GSTRING_LEN;
524 num_strings++;
525 goto unknown_filter;
528 /* now the rest of the filters */
529 switch (fsc->fs.flow_type) {
530 case TCP_V4_FLOW:
531 case UDP_V4_FLOW:
532 case SCTP_V4_FLOW:
533 sprintf(p, "\tSrc IP addr: 0x%x\n",
534 fsc->fs.h_u.tcp_ip4_spec.ip4src);
535 p += ETH_GSTRING_LEN;
536 num_strings++;
537 sprintf(p, "\tSrc IP mask: 0x%x\n",
538 fsc->fs.m_u.tcp_ip4_spec.ip4src);
539 p += ETH_GSTRING_LEN;
540 num_strings++;
541 sprintf(p, "\tDest IP addr: 0x%x\n",
542 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
543 p += ETH_GSTRING_LEN;
544 num_strings++;
545 sprintf(p, "\tDest IP mask: 0x%x\n",
546 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
547 p += ETH_GSTRING_LEN;
548 num_strings++;
549 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
550 fsc->fs.h_u.tcp_ip4_spec.psrc,
551 fsc->fs.m_u.tcp_ip4_spec.psrc);
552 p += ETH_GSTRING_LEN;
553 num_strings++;
554 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
555 fsc->fs.h_u.tcp_ip4_spec.pdst,
556 fsc->fs.m_u.tcp_ip4_spec.pdst);
557 p += ETH_GSTRING_LEN;
558 num_strings++;
559 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
560 fsc->fs.h_u.tcp_ip4_spec.tos,
561 fsc->fs.m_u.tcp_ip4_spec.tos);
562 p += ETH_GSTRING_LEN;
563 num_strings++;
564 break;
565 case AH_ESP_V4_FLOW:
566 case ESP_V4_FLOW:
567 sprintf(p, "\tSrc IP addr: 0x%x\n",
568 fsc->fs.h_u.ah_ip4_spec.ip4src);
569 p += ETH_GSTRING_LEN;
570 num_strings++;
571 sprintf(p, "\tSrc IP mask: 0x%x\n",
572 fsc->fs.m_u.ah_ip4_spec.ip4src);
573 p += ETH_GSTRING_LEN;
574 num_strings++;
575 sprintf(p, "\tDest IP addr: 0x%x\n",
576 fsc->fs.h_u.ah_ip4_spec.ip4dst);
577 p += ETH_GSTRING_LEN;
578 num_strings++;
579 sprintf(p, "\tDest IP mask: 0x%x\n",
580 fsc->fs.m_u.ah_ip4_spec.ip4dst);
581 p += ETH_GSTRING_LEN;
582 num_strings++;
583 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
584 fsc->fs.h_u.ah_ip4_spec.spi,
585 fsc->fs.m_u.ah_ip4_spec.spi);
586 p += ETH_GSTRING_LEN;
587 num_strings++;
588 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
589 fsc->fs.h_u.ah_ip4_spec.tos,
590 fsc->fs.m_u.ah_ip4_spec.tos);
591 p += ETH_GSTRING_LEN;
592 num_strings++;
593 break;
594 case IP_USER_FLOW:
595 sprintf(p, "\tSrc IP addr: 0x%x\n",
596 fsc->fs.h_u.raw_ip4_spec.ip4src);
597 p += ETH_GSTRING_LEN;
598 num_strings++;
599 sprintf(p, "\tSrc IP mask: 0x%x\n",
600 fsc->fs.m_u.raw_ip4_spec.ip4src);
601 p += ETH_GSTRING_LEN;
602 num_strings++;
603 sprintf(p, "\tDest IP addr: 0x%x\n",
604 fsc->fs.h_u.raw_ip4_spec.ip4dst);
605 p += ETH_GSTRING_LEN;
606 num_strings++;
607 sprintf(p, "\tDest IP mask: 0x%x\n",
608 fsc->fs.m_u.raw_ip4_spec.ip4dst);
609 p += ETH_GSTRING_LEN;
610 num_strings++;
611 break;
612 case IPV4_FLOW:
613 sprintf(p, "\tSrc IP addr: 0x%x\n",
614 fsc->fs.h_u.usr_ip4_spec.ip4src);
615 p += ETH_GSTRING_LEN;
616 num_strings++;
617 sprintf(p, "\tSrc IP mask: 0x%x\n",
618 fsc->fs.m_u.usr_ip4_spec.ip4src);
619 p += ETH_GSTRING_LEN;
620 num_strings++;
621 sprintf(p, "\tDest IP addr: 0x%x\n",
622 fsc->fs.h_u.usr_ip4_spec.ip4dst);
623 p += ETH_GSTRING_LEN;
624 num_strings++;
625 sprintf(p, "\tDest IP mask: 0x%x\n",
626 fsc->fs.m_u.usr_ip4_spec.ip4dst);
627 p += ETH_GSTRING_LEN;
628 num_strings++;
629 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
630 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
631 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
632 p += ETH_GSTRING_LEN;
633 num_strings++;
634 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
635 fsc->fs.h_u.usr_ip4_spec.tos,
636 fsc->fs.m_u.usr_ip4_spec.tos);
637 p += ETH_GSTRING_LEN;
638 num_strings++;
639 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
640 fsc->fs.h_u.usr_ip4_spec.ip_ver,
641 fsc->fs.m_u.usr_ip4_spec.ip_ver);
642 p += ETH_GSTRING_LEN;
643 num_strings++;
644 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
645 fsc->fs.h_u.usr_ip4_spec.proto,
646 fsc->fs.m_u.usr_ip4_spec.proto);
647 p += ETH_GSTRING_LEN;
648 num_strings++;
649 break;
651 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
652 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
653 p += ETH_GSTRING_LEN;
654 num_strings++;
655 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
656 p += ETH_GSTRING_LEN;
657 num_strings++;
658 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
659 p += ETH_GSTRING_LEN;
660 num_strings++;
661 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
662 sprintf(p, "\tAction: Drop\n");
663 else
664 sprintf(p, "\tAction: Direct to queue %d\n",
665 fsc->fs.action);
666 p += ETH_GSTRING_LEN;
667 num_strings++;
668 unknown_filter:
669 i++;
671 copy:
672 /* indicate to userspace how many strings we actually have */
673 gstrings.len = num_strings;
674 ret = -EFAULT;
675 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
676 goto out;
677 useraddr += sizeof(gstrings);
678 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
679 goto out;
680 ret = 0;
682 out:
683 kfree(data);
684 return ret;
687 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
689 struct ethtool_regs regs;
690 const struct ethtool_ops *ops = dev->ethtool_ops;
691 void *regbuf;
692 int reglen, ret;
694 if (!ops->get_regs || !ops->get_regs_len)
695 return -EOPNOTSUPP;
697 if (copy_from_user(&regs, useraddr, sizeof(regs)))
698 return -EFAULT;
700 reglen = ops->get_regs_len(dev);
701 if (regs.len > reglen)
702 regs.len = reglen;
704 regbuf = kmalloc(reglen, GFP_USER);
705 if (!regbuf)
706 return -ENOMEM;
708 ops->get_regs(dev, &regs, regbuf);
710 ret = -EFAULT;
711 if (copy_to_user(useraddr, &regs, sizeof(regs)))
712 goto out;
713 useraddr += offsetof(struct ethtool_regs, data);
714 if (copy_to_user(useraddr, regbuf, regs.len))
715 goto out;
716 ret = 0;
718 out:
719 kfree(regbuf);
720 return ret;
723 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
725 struct ethtool_value reset;
726 int ret;
728 if (!dev->ethtool_ops->reset)
729 return -EOPNOTSUPP;
731 if (copy_from_user(&reset, useraddr, sizeof(reset)))
732 return -EFAULT;
734 ret = dev->ethtool_ops->reset(dev, &reset.data);
735 if (ret)
736 return ret;
738 if (copy_to_user(useraddr, &reset, sizeof(reset)))
739 return -EFAULT;
740 return 0;
743 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
745 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
747 if (!dev->ethtool_ops->get_wol)
748 return -EOPNOTSUPP;
750 dev->ethtool_ops->get_wol(dev, &wol);
752 if (copy_to_user(useraddr, &wol, sizeof(wol)))
753 return -EFAULT;
754 return 0;
757 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
759 struct ethtool_wolinfo wol;
761 if (!dev->ethtool_ops->set_wol)
762 return -EOPNOTSUPP;
764 if (copy_from_user(&wol, useraddr, sizeof(wol)))
765 return -EFAULT;
767 return dev->ethtool_ops->set_wol(dev, &wol);
770 static int ethtool_nway_reset(struct net_device *dev)
772 if (!dev->ethtool_ops->nway_reset)
773 return -EOPNOTSUPP;
775 return dev->ethtool_ops->nway_reset(dev);
778 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
780 struct ethtool_eeprom eeprom;
781 const struct ethtool_ops *ops = dev->ethtool_ops;
782 void __user *userbuf = useraddr + sizeof(eeprom);
783 u32 bytes_remaining;
784 u8 *data;
785 int ret = 0;
787 if (!ops->get_eeprom || !ops->get_eeprom_len)
788 return -EOPNOTSUPP;
790 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
791 return -EFAULT;
793 /* Check for wrap and zero */
794 if (eeprom.offset + eeprom.len <= eeprom.offset)
795 return -EINVAL;
797 /* Check for exceeding total eeprom len */
798 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
799 return -EINVAL;
801 data = kmalloc(PAGE_SIZE, GFP_USER);
802 if (!data)
803 return -ENOMEM;
805 bytes_remaining = eeprom.len;
806 while (bytes_remaining > 0) {
807 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
809 ret = ops->get_eeprom(dev, &eeprom, data);
810 if (ret)
811 break;
812 if (copy_to_user(userbuf, data, eeprom.len)) {
813 ret = -EFAULT;
814 break;
816 userbuf += eeprom.len;
817 eeprom.offset += eeprom.len;
818 bytes_remaining -= eeprom.len;
821 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
822 eeprom.offset -= eeprom.len;
823 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
824 ret = -EFAULT;
826 kfree(data);
827 return ret;
830 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
832 struct ethtool_eeprom eeprom;
833 const struct ethtool_ops *ops = dev->ethtool_ops;
834 void __user *userbuf = useraddr + sizeof(eeprom);
835 u32 bytes_remaining;
836 u8 *data;
837 int ret = 0;
839 if (!ops->set_eeprom || !ops->get_eeprom_len)
840 return -EOPNOTSUPP;
842 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
843 return -EFAULT;
845 /* Check for wrap and zero */
846 if (eeprom.offset + eeprom.len <= eeprom.offset)
847 return -EINVAL;
849 /* Check for exceeding total eeprom len */
850 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
851 return -EINVAL;
853 data = kmalloc(PAGE_SIZE, GFP_USER);
854 if (!data)
855 return -ENOMEM;
857 bytes_remaining = eeprom.len;
858 while (bytes_remaining > 0) {
859 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
861 if (copy_from_user(data, userbuf, eeprom.len)) {
862 ret = -EFAULT;
863 break;
865 ret = ops->set_eeprom(dev, &eeprom, data);
866 if (ret)
867 break;
868 userbuf += eeprom.len;
869 eeprom.offset += eeprom.len;
870 bytes_remaining -= eeprom.len;
873 kfree(data);
874 return ret;
877 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
879 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
881 if (!dev->ethtool_ops->get_coalesce)
882 return -EOPNOTSUPP;
884 dev->ethtool_ops->get_coalesce(dev, &coalesce);
886 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
887 return -EFAULT;
888 return 0;
891 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
893 struct ethtool_coalesce coalesce;
895 if (!dev->ethtool_ops->set_coalesce)
896 return -EOPNOTSUPP;
898 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
899 return -EFAULT;
901 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
904 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
906 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
908 if (!dev->ethtool_ops->get_ringparam)
909 return -EOPNOTSUPP;
911 dev->ethtool_ops->get_ringparam(dev, &ringparam);
913 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
914 return -EFAULT;
915 return 0;
918 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
920 struct ethtool_ringparam ringparam;
922 if (!dev->ethtool_ops->set_ringparam)
923 return -EOPNOTSUPP;
925 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
926 return -EFAULT;
928 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
931 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
933 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
935 if (!dev->ethtool_ops->get_pauseparam)
936 return -EOPNOTSUPP;
938 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
940 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
941 return -EFAULT;
942 return 0;
945 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
947 struct ethtool_pauseparam pauseparam;
949 if (!dev->ethtool_ops->set_pauseparam)
950 return -EOPNOTSUPP;
952 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
953 return -EFAULT;
955 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
958 static int __ethtool_set_sg(struct net_device *dev, u32 data)
960 int err;
962 if (!data && dev->ethtool_ops->set_tso) {
963 err = dev->ethtool_ops->set_tso(dev, 0);
964 if (err)
965 return err;
968 if (!data && dev->ethtool_ops->set_ufo) {
969 err = dev->ethtool_ops->set_ufo(dev, 0);
970 if (err)
971 return err;
973 return dev->ethtool_ops->set_sg(dev, data);
976 static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
978 struct ethtool_value edata;
979 int err;
981 if (!dev->ethtool_ops->set_tx_csum)
982 return -EOPNOTSUPP;
984 if (copy_from_user(&edata, useraddr, sizeof(edata)))
985 return -EFAULT;
987 if (!edata.data && dev->ethtool_ops->set_sg) {
988 err = __ethtool_set_sg(dev, 0);
989 if (err)
990 return err;
993 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
996 static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
998 struct ethtool_value edata;
1000 if (!dev->ethtool_ops->set_rx_csum)
1001 return -EOPNOTSUPP;
1003 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1004 return -EFAULT;
1006 if (!edata.data && dev->ethtool_ops->set_sg)
1007 dev->features &= ~NETIF_F_GRO;
1009 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
1012 static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
1014 struct ethtool_value edata;
1016 if (!dev->ethtool_ops->set_sg)
1017 return -EOPNOTSUPP;
1019 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1020 return -EFAULT;
1022 if (edata.data &&
1023 !(dev->features & NETIF_F_ALL_CSUM))
1024 return -EINVAL;
1026 return __ethtool_set_sg(dev, edata.data);
1029 static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1031 struct ethtool_value edata;
1033 if (!dev->ethtool_ops->set_tso)
1034 return -EOPNOTSUPP;
1036 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1037 return -EFAULT;
1039 if (edata.data && !(dev->features & NETIF_F_SG))
1040 return -EINVAL;
1042 return dev->ethtool_ops->set_tso(dev, edata.data);
1045 static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1047 struct ethtool_value edata;
1049 if (!dev->ethtool_ops->set_ufo)
1050 return -EOPNOTSUPP;
1051 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1052 return -EFAULT;
1053 if (edata.data && !(dev->features & NETIF_F_SG))
1054 return -EINVAL;
1055 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1056 return -EINVAL;
1057 return dev->ethtool_ops->set_ufo(dev, edata.data);
1060 static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1062 struct ethtool_value edata = { ETHTOOL_GGSO };
1064 edata.data = dev->features & NETIF_F_GSO;
1065 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1066 return -EFAULT;
1067 return 0;
1070 static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1072 struct ethtool_value edata;
1074 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1075 return -EFAULT;
1076 if (edata.data)
1077 dev->features |= NETIF_F_GSO;
1078 else
1079 dev->features &= ~NETIF_F_GSO;
1080 return 0;
1083 static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1085 struct ethtool_value edata = { ETHTOOL_GGRO };
1087 edata.data = dev->features & NETIF_F_GRO;
1088 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1089 return -EFAULT;
1090 return 0;
1093 static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1095 struct ethtool_value edata;
1097 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1098 return -EFAULT;
1100 if (edata.data) {
1101 if (!dev->ethtool_ops->get_rx_csum ||
1102 !dev->ethtool_ops->get_rx_csum(dev))
1103 return -EINVAL;
1104 dev->features |= NETIF_F_GRO;
1105 } else
1106 dev->features &= ~NETIF_F_GRO;
1108 return 0;
1111 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1113 struct ethtool_test test;
1114 const struct ethtool_ops *ops = dev->ethtool_ops;
1115 u64 *data;
1116 int ret, test_len;
1118 if (!ops->self_test || !ops->get_sset_count)
1119 return -EOPNOTSUPP;
1121 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1122 if (test_len < 0)
1123 return test_len;
1124 WARN_ON(test_len == 0);
1126 if (copy_from_user(&test, useraddr, sizeof(test)))
1127 return -EFAULT;
1129 test.len = test_len;
1130 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1131 if (!data)
1132 return -ENOMEM;
1134 ops->self_test(dev, &test, data);
1136 ret = -EFAULT;
1137 if (copy_to_user(useraddr, &test, sizeof(test)))
1138 goto out;
1139 useraddr += sizeof(test);
1140 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1141 goto out;
1142 ret = 0;
1144 out:
1145 kfree(data);
1146 return ret;
1149 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1151 struct ethtool_gstrings gstrings;
1152 const struct ethtool_ops *ops = dev->ethtool_ops;
1153 u8 *data;
1154 int ret;
1156 if (!ops->get_strings || !ops->get_sset_count)
1157 return -EOPNOTSUPP;
1159 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1160 return -EFAULT;
1162 ret = ops->get_sset_count(dev, gstrings.string_set);
1163 if (ret < 0)
1164 return ret;
1166 gstrings.len = ret;
1168 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1169 if (!data)
1170 return -ENOMEM;
1172 ops->get_strings(dev, gstrings.string_set, data);
1174 ret = -EFAULT;
1175 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1176 goto out;
1177 useraddr += sizeof(gstrings);
1178 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1179 goto out;
1180 ret = 0;
1182 out:
1183 kfree(data);
1184 return ret;
1187 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1189 struct ethtool_value id;
1191 if (!dev->ethtool_ops->phys_id)
1192 return -EOPNOTSUPP;
1194 if (copy_from_user(&id, useraddr, sizeof(id)))
1195 return -EFAULT;
1197 return dev->ethtool_ops->phys_id(dev, id.data);
1200 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1202 struct ethtool_stats stats;
1203 const struct ethtool_ops *ops = dev->ethtool_ops;
1204 u64 *data;
1205 int ret, n_stats;
1207 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1208 return -EOPNOTSUPP;
1210 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1211 if (n_stats < 0)
1212 return n_stats;
1213 WARN_ON(n_stats == 0);
1215 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1216 return -EFAULT;
1218 stats.n_stats = n_stats;
1219 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1220 if (!data)
1221 return -ENOMEM;
1223 ops->get_ethtool_stats(dev, &stats, data);
1225 ret = -EFAULT;
1226 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1227 goto out;
1228 useraddr += sizeof(stats);
1229 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1230 goto out;
1231 ret = 0;
1233 out:
1234 kfree(data);
1235 return ret;
1238 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1240 struct ethtool_perm_addr epaddr;
1242 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1243 return -EFAULT;
1245 if (epaddr.size < dev->addr_len)
1246 return -ETOOSMALL;
1247 epaddr.size = dev->addr_len;
1249 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1250 return -EFAULT;
1251 useraddr += sizeof(epaddr);
1252 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1253 return -EFAULT;
1254 return 0;
1257 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1258 u32 cmd, u32 (*actor)(struct net_device *))
1260 struct ethtool_value edata = { .cmd = cmd };
1262 if (!actor)
1263 return -EOPNOTSUPP;
1265 edata.data = actor(dev);
1267 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1268 return -EFAULT;
1269 return 0;
1272 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1273 void (*actor)(struct net_device *, u32))
1275 struct ethtool_value edata;
1277 if (!actor)
1278 return -EOPNOTSUPP;
1280 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1281 return -EFAULT;
1283 actor(dev, edata.data);
1284 return 0;
1287 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1288 int (*actor)(struct net_device *, u32))
1290 struct ethtool_value edata;
1292 if (!actor)
1293 return -EOPNOTSUPP;
1295 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1296 return -EFAULT;
1298 return actor(dev, edata.data);
1301 static noinline_for_stack int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
1303 struct ethtool_flash efl;
1305 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1306 return -EFAULT;
1308 if (!dev->ethtool_ops->flash_device)
1309 return -EOPNOTSUPP;
1311 return dev->ethtool_ops->flash_device(dev, &efl);
1314 /* The main entry point in this file. Called from net/core/dev.c */
1316 int dev_ethtool(struct net *net, struct ifreq *ifr)
1318 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1319 void __user *useraddr = ifr->ifr_data;
1320 u32 ethcmd;
1321 int rc;
1322 unsigned long old_features;
1324 if (!dev || !netif_device_present(dev))
1325 return -ENODEV;
1327 if (!dev->ethtool_ops)
1328 return -EOPNOTSUPP;
1330 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1331 return -EFAULT;
1333 /* Allow some commands to be done by anyone */
1334 switch(ethcmd) {
1335 case ETHTOOL_GDRVINFO:
1336 case ETHTOOL_GMSGLVL:
1337 case ETHTOOL_GCOALESCE:
1338 case ETHTOOL_GRINGPARAM:
1339 case ETHTOOL_GPAUSEPARAM:
1340 case ETHTOOL_GRXCSUM:
1341 case ETHTOOL_GTXCSUM:
1342 case ETHTOOL_GSG:
1343 case ETHTOOL_GSTRINGS:
1344 case ETHTOOL_GTSO:
1345 case ETHTOOL_GPERMADDR:
1346 case ETHTOOL_GUFO:
1347 case ETHTOOL_GGSO:
1348 case ETHTOOL_GGRO:
1349 case ETHTOOL_GFLAGS:
1350 case ETHTOOL_GPFLAGS:
1351 case ETHTOOL_GRXFH:
1352 case ETHTOOL_GRXRINGS:
1353 case ETHTOOL_GRXCLSRLCNT:
1354 case ETHTOOL_GRXCLSRULE:
1355 case ETHTOOL_GRXCLSRLALL:
1356 break;
1357 default:
1358 if (!capable(CAP_NET_ADMIN))
1359 return -EPERM;
1362 if (dev->ethtool_ops->begin)
1363 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1364 return rc;
1366 old_features = dev->features;
1368 switch (ethcmd) {
1369 case ETHTOOL_GSET:
1370 rc = ethtool_get_settings(dev, useraddr);
1371 break;
1372 case ETHTOOL_SSET:
1373 rc = ethtool_set_settings(dev, useraddr);
1374 break;
1375 case ETHTOOL_GDRVINFO:
1376 rc = ethtool_get_drvinfo(dev, useraddr);
1377 break;
1378 case ETHTOOL_GREGS:
1379 rc = ethtool_get_regs(dev, useraddr);
1380 break;
1381 case ETHTOOL_GWOL:
1382 rc = ethtool_get_wol(dev, useraddr);
1383 break;
1384 case ETHTOOL_SWOL:
1385 rc = ethtool_set_wol(dev, useraddr);
1386 break;
1387 case ETHTOOL_GMSGLVL:
1388 rc = ethtool_get_value(dev, useraddr, ethcmd,
1389 dev->ethtool_ops->get_msglevel);
1390 break;
1391 case ETHTOOL_SMSGLVL:
1392 rc = ethtool_set_value_void(dev, useraddr,
1393 dev->ethtool_ops->set_msglevel);
1394 break;
1395 case ETHTOOL_NWAY_RST:
1396 rc = ethtool_nway_reset(dev);
1397 break;
1398 case ETHTOOL_GLINK:
1399 rc = ethtool_get_value(dev, useraddr, ethcmd,
1400 dev->ethtool_ops->get_link);
1401 break;
1402 case ETHTOOL_GEEPROM:
1403 rc = ethtool_get_eeprom(dev, useraddr);
1404 break;
1405 case ETHTOOL_SEEPROM:
1406 rc = ethtool_set_eeprom(dev, useraddr);
1407 break;
1408 case ETHTOOL_GCOALESCE:
1409 rc = ethtool_get_coalesce(dev, useraddr);
1410 break;
1411 case ETHTOOL_SCOALESCE:
1412 rc = ethtool_set_coalesce(dev, useraddr);
1413 break;
1414 case ETHTOOL_GRINGPARAM:
1415 rc = ethtool_get_ringparam(dev, useraddr);
1416 break;
1417 case ETHTOOL_SRINGPARAM:
1418 rc = ethtool_set_ringparam(dev, useraddr);
1419 break;
1420 case ETHTOOL_GPAUSEPARAM:
1421 rc = ethtool_get_pauseparam(dev, useraddr);
1422 break;
1423 case ETHTOOL_SPAUSEPARAM:
1424 rc = ethtool_set_pauseparam(dev, useraddr);
1425 break;
1426 case ETHTOOL_GRXCSUM:
1427 rc = ethtool_get_value(dev, useraddr, ethcmd,
1428 (dev->ethtool_ops->get_rx_csum ?
1429 dev->ethtool_ops->get_rx_csum :
1430 ethtool_op_get_rx_csum));
1431 break;
1432 case ETHTOOL_SRXCSUM:
1433 rc = ethtool_set_rx_csum(dev, useraddr);
1434 break;
1435 case ETHTOOL_GTXCSUM:
1436 rc = ethtool_get_value(dev, useraddr, ethcmd,
1437 (dev->ethtool_ops->get_tx_csum ?
1438 dev->ethtool_ops->get_tx_csum :
1439 ethtool_op_get_tx_csum));
1440 break;
1441 case ETHTOOL_STXCSUM:
1442 rc = ethtool_set_tx_csum(dev, useraddr);
1443 break;
1444 case ETHTOOL_GSG:
1445 rc = ethtool_get_value(dev, useraddr, ethcmd,
1446 (dev->ethtool_ops->get_sg ?
1447 dev->ethtool_ops->get_sg :
1448 ethtool_op_get_sg));
1449 break;
1450 case ETHTOOL_SSG:
1451 rc = ethtool_set_sg(dev, useraddr);
1452 break;
1453 case ETHTOOL_GTSO:
1454 rc = ethtool_get_value(dev, useraddr, ethcmd,
1455 (dev->ethtool_ops->get_tso ?
1456 dev->ethtool_ops->get_tso :
1457 ethtool_op_get_tso));
1458 break;
1459 case ETHTOOL_STSO:
1460 rc = ethtool_set_tso(dev, useraddr);
1461 break;
1462 case ETHTOOL_TEST:
1463 rc = ethtool_self_test(dev, useraddr);
1464 break;
1465 case ETHTOOL_GSTRINGS:
1466 rc = ethtool_get_strings(dev, useraddr);
1467 break;
1468 case ETHTOOL_PHYS_ID:
1469 rc = ethtool_phys_id(dev, useraddr);
1470 break;
1471 case ETHTOOL_GSTATS:
1472 rc = ethtool_get_stats(dev, useraddr);
1473 break;
1474 case ETHTOOL_GPERMADDR:
1475 rc = ethtool_get_perm_addr(dev, useraddr);
1476 break;
1477 case ETHTOOL_GUFO:
1478 rc = ethtool_get_value(dev, useraddr, ethcmd,
1479 (dev->ethtool_ops->get_ufo ?
1480 dev->ethtool_ops->get_ufo :
1481 ethtool_op_get_ufo));
1482 break;
1483 case ETHTOOL_SUFO:
1484 rc = ethtool_set_ufo(dev, useraddr);
1485 break;
1486 case ETHTOOL_GGSO:
1487 rc = ethtool_get_gso(dev, useraddr);
1488 break;
1489 case ETHTOOL_SGSO:
1490 rc = ethtool_set_gso(dev, useraddr);
1491 break;
1492 case ETHTOOL_GFLAGS:
1493 rc = ethtool_get_value(dev, useraddr, ethcmd,
1494 (dev->ethtool_ops->get_flags ?
1495 dev->ethtool_ops->get_flags :
1496 ethtool_op_get_flags));
1497 break;
1498 case ETHTOOL_SFLAGS:
1499 rc = ethtool_set_value(dev, useraddr,
1500 dev->ethtool_ops->set_flags);
1501 break;
1502 case ETHTOOL_GPFLAGS:
1503 rc = ethtool_get_value(dev, useraddr, ethcmd,
1504 dev->ethtool_ops->get_priv_flags);
1505 break;
1506 case ETHTOOL_SPFLAGS:
1507 rc = ethtool_set_value(dev, useraddr,
1508 dev->ethtool_ops->set_priv_flags);
1509 break;
1510 case ETHTOOL_GRXFH:
1511 case ETHTOOL_GRXRINGS:
1512 case ETHTOOL_GRXCLSRLCNT:
1513 case ETHTOOL_GRXCLSRULE:
1514 case ETHTOOL_GRXCLSRLALL:
1515 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1516 break;
1517 case ETHTOOL_SRXFH:
1518 case ETHTOOL_SRXCLSRLDEL:
1519 case ETHTOOL_SRXCLSRLINS:
1520 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1521 break;
1522 case ETHTOOL_GGRO:
1523 rc = ethtool_get_gro(dev, useraddr);
1524 break;
1525 case ETHTOOL_SGRO:
1526 rc = ethtool_set_gro(dev, useraddr);
1527 break;
1528 case ETHTOOL_FLASHDEV:
1529 rc = ethtool_flash_device(dev, useraddr);
1530 break;
1531 case ETHTOOL_RESET:
1532 rc = ethtool_reset(dev, useraddr);
1533 break;
1534 case ETHTOOL_SRXNTUPLE:
1535 rc = ethtool_set_rx_ntuple(dev, useraddr);
1536 break;
1537 case ETHTOOL_GRXNTUPLE:
1538 rc = ethtool_get_rx_ntuple(dev, useraddr);
1539 break;
1540 case ETHTOOL_GSSET_INFO:
1541 rc = ethtool_get_sset_info(dev, useraddr);
1542 break;
1543 default:
1544 rc = -EOPNOTSUPP;
1547 if (dev->ethtool_ops->complete)
1548 dev->ethtool_ops->complete(dev);
1550 if (old_features != dev->features)
1551 netdev_features_change(dev);
1553 return rc;
1556 EXPORT_SYMBOL(ethtool_op_get_link);
1557 EXPORT_SYMBOL(ethtool_op_get_sg);
1558 EXPORT_SYMBOL(ethtool_op_get_tso);
1559 EXPORT_SYMBOL(ethtool_op_set_sg);
1560 EXPORT_SYMBOL(ethtool_op_set_tso);
1561 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
1562 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
1563 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
1564 EXPORT_SYMBOL(ethtool_op_set_ufo);
1565 EXPORT_SYMBOL(ethtool_op_get_ufo);
1566 EXPORT_SYMBOL(ethtool_op_set_flags);
1567 EXPORT_SYMBOL(ethtool_op_get_flags);