intel-gtt: call init_gtt_init in probe function
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / core / ethtool.c
blob7a85367b3c2f8010af24bbd6b6f4249698f9d78d
1 /*
2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
20 #include <linux/bitops.h>
21 #include <linux/uaccess.h>
22 #include <linux/slab.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;
34 EXPORT_SYMBOL(ethtool_op_get_link);
36 u32 ethtool_op_get_rx_csum(struct net_device *dev)
38 return (dev->features & NETIF_F_ALL_CSUM) != 0;
40 EXPORT_SYMBOL(ethtool_op_get_rx_csum);
42 u32 ethtool_op_get_tx_csum(struct net_device *dev)
44 return (dev->features & NETIF_F_ALL_CSUM) != 0;
46 EXPORT_SYMBOL(ethtool_op_get_tx_csum);
48 int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
50 if (data)
51 dev->features |= NETIF_F_IP_CSUM;
52 else
53 dev->features &= ~NETIF_F_IP_CSUM;
55 return 0;
58 int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
60 if (data)
61 dev->features |= NETIF_F_HW_CSUM;
62 else
63 dev->features &= ~NETIF_F_HW_CSUM;
65 return 0;
67 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
69 int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
71 if (data)
72 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
73 else
74 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
76 return 0;
78 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
80 u32 ethtool_op_get_sg(struct net_device *dev)
82 return (dev->features & NETIF_F_SG) != 0;
84 EXPORT_SYMBOL(ethtool_op_get_sg);
86 int ethtool_op_set_sg(struct net_device *dev, u32 data)
88 if (data)
89 dev->features |= NETIF_F_SG;
90 else
91 dev->features &= ~NETIF_F_SG;
93 return 0;
95 EXPORT_SYMBOL(ethtool_op_set_sg);
97 u32 ethtool_op_get_tso(struct net_device *dev)
99 return (dev->features & NETIF_F_TSO) != 0;
101 EXPORT_SYMBOL(ethtool_op_get_tso);
103 int ethtool_op_set_tso(struct net_device *dev, u32 data)
105 if (data)
106 dev->features |= NETIF_F_TSO;
107 else
108 dev->features &= ~NETIF_F_TSO;
110 return 0;
112 EXPORT_SYMBOL(ethtool_op_set_tso);
114 u32 ethtool_op_get_ufo(struct net_device *dev)
116 return (dev->features & NETIF_F_UFO) != 0;
118 EXPORT_SYMBOL(ethtool_op_get_ufo);
120 int ethtool_op_set_ufo(struct net_device *dev, u32 data)
122 if (data)
123 dev->features |= NETIF_F_UFO;
124 else
125 dev->features &= ~NETIF_F_UFO;
126 return 0;
128 EXPORT_SYMBOL(ethtool_op_set_ufo);
130 /* the following list of flags are the same as their associated
131 * NETIF_F_xxx values in include/linux/netdevice.h
133 static const u32 flags_dup_features =
134 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH);
136 u32 ethtool_op_get_flags(struct net_device *dev)
138 /* in the future, this function will probably contain additional
139 * handling for flags which are not so easily handled
140 * by a simple masking operation
143 return dev->features & flags_dup_features;
145 EXPORT_SYMBOL(ethtool_op_get_flags);
147 int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
149 if (data & ~supported)
150 return -EINVAL;
152 dev->features = ((dev->features & ~flags_dup_features) |
153 (data & flags_dup_features));
154 return 0;
156 EXPORT_SYMBOL(ethtool_op_set_flags);
158 void ethtool_ntuple_flush(struct net_device *dev)
160 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
162 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
163 list_del(&fsc->list);
164 kfree(fsc);
166 dev->ethtool_ntuple_list.count = 0;
168 EXPORT_SYMBOL(ethtool_ntuple_flush);
170 /* Handlers for each ethtool command */
172 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
174 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
175 int err;
177 if (!dev->ethtool_ops->get_settings)
178 return -EOPNOTSUPP;
180 err = dev->ethtool_ops->get_settings(dev, &cmd);
181 if (err < 0)
182 return err;
184 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
185 return -EFAULT;
186 return 0;
189 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
191 struct ethtool_cmd cmd;
193 if (!dev->ethtool_ops->set_settings)
194 return -EOPNOTSUPP;
196 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
197 return -EFAULT;
199 return dev->ethtool_ops->set_settings(dev, &cmd);
202 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
203 void __user *useraddr)
205 struct ethtool_drvinfo info;
206 const struct ethtool_ops *ops = dev->ethtool_ops;
208 if (!ops->get_drvinfo)
209 return -EOPNOTSUPP;
211 memset(&info, 0, sizeof(info));
212 info.cmd = ETHTOOL_GDRVINFO;
213 ops->get_drvinfo(dev, &info);
216 * this method of obtaining string set info is deprecated;
217 * Use ETHTOOL_GSSET_INFO instead.
219 if (ops->get_sset_count) {
220 int rc;
222 rc = ops->get_sset_count(dev, ETH_SS_TEST);
223 if (rc >= 0)
224 info.testinfo_len = rc;
225 rc = ops->get_sset_count(dev, ETH_SS_STATS);
226 if (rc >= 0)
227 info.n_stats = rc;
228 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
229 if (rc >= 0)
230 info.n_priv_flags = rc;
232 if (ops->get_regs_len)
233 info.regdump_len = ops->get_regs_len(dev);
234 if (ops->get_eeprom_len)
235 info.eedump_len = ops->get_eeprom_len(dev);
237 if (copy_to_user(useraddr, &info, sizeof(info)))
238 return -EFAULT;
239 return 0;
242 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
243 void __user *useraddr)
245 struct ethtool_sset_info info;
246 const struct ethtool_ops *ops = dev->ethtool_ops;
247 u64 sset_mask;
248 int i, idx = 0, n_bits = 0, ret, rc;
249 u32 *info_buf = NULL;
251 if (!ops->get_sset_count)
252 return -EOPNOTSUPP;
254 if (copy_from_user(&info, useraddr, sizeof(info)))
255 return -EFAULT;
257 /* store copy of mask, because we zero struct later on */
258 sset_mask = info.sset_mask;
259 if (!sset_mask)
260 return 0;
262 /* calculate size of return buffer */
263 n_bits = hweight64(sset_mask);
265 memset(&info, 0, sizeof(info));
266 info.cmd = ETHTOOL_GSSET_INFO;
268 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
269 if (!info_buf)
270 return -ENOMEM;
273 * fill return buffer based on input bitmask and successful
274 * get_sset_count return
276 for (i = 0; i < 64; i++) {
277 if (!(sset_mask & (1ULL << i)))
278 continue;
280 rc = ops->get_sset_count(dev, i);
281 if (rc >= 0) {
282 info.sset_mask |= (1ULL << i);
283 info_buf[idx++] = rc;
287 ret = -EFAULT;
288 if (copy_to_user(useraddr, &info, sizeof(info)))
289 goto out;
291 useraddr += offsetof(struct ethtool_sset_info, data);
292 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
293 goto out;
295 ret = 0;
297 out:
298 kfree(info_buf);
299 return ret;
302 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
303 u32 cmd, void __user *useraddr)
305 struct ethtool_rxnfc info;
306 size_t info_size = sizeof(info);
308 if (!dev->ethtool_ops->set_rxnfc)
309 return -EOPNOTSUPP;
311 /* struct ethtool_rxnfc was originally defined for
312 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
313 * members. User-space might still be using that
314 * definition. */
315 if (cmd == ETHTOOL_SRXFH)
316 info_size = (offsetof(struct ethtool_rxnfc, data) +
317 sizeof(info.data));
319 if (copy_from_user(&info, useraddr, info_size))
320 return -EFAULT;
322 return dev->ethtool_ops->set_rxnfc(dev, &info);
325 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
326 u32 cmd, void __user *useraddr)
328 struct ethtool_rxnfc info;
329 size_t info_size = sizeof(info);
330 const struct ethtool_ops *ops = dev->ethtool_ops;
331 int ret;
332 void *rule_buf = NULL;
334 if (!ops->get_rxnfc)
335 return -EOPNOTSUPP;
337 /* struct ethtool_rxnfc was originally defined for
338 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
339 * members. User-space might still be using that
340 * definition. */
341 if (cmd == ETHTOOL_GRXFH)
342 info_size = (offsetof(struct ethtool_rxnfc, data) +
343 sizeof(info.data));
345 if (copy_from_user(&info, useraddr, info_size))
346 return -EFAULT;
348 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
349 if (info.rule_cnt > 0) {
350 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
351 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
352 GFP_USER);
353 if (!rule_buf)
354 return -ENOMEM;
358 ret = ops->get_rxnfc(dev, &info, rule_buf);
359 if (ret < 0)
360 goto err_out;
362 ret = -EFAULT;
363 if (copy_to_user(useraddr, &info, info_size))
364 goto err_out;
366 if (rule_buf) {
367 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
368 if (copy_to_user(useraddr, rule_buf,
369 info.rule_cnt * sizeof(u32)))
370 goto err_out;
372 ret = 0;
374 err_out:
375 kfree(rule_buf);
377 return ret;
380 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
381 void __user *useraddr)
383 struct ethtool_rxfh_indir *indir;
384 u32 table_size;
385 size_t full_size;
386 int ret;
388 if (!dev->ethtool_ops->get_rxfh_indir)
389 return -EOPNOTSUPP;
391 if (copy_from_user(&table_size,
392 useraddr + offsetof(struct ethtool_rxfh_indir, size),
393 sizeof(table_size)))
394 return -EFAULT;
396 if (table_size >
397 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
398 return -ENOMEM;
399 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
400 indir = kmalloc(full_size, GFP_USER);
401 if (!indir)
402 return -ENOMEM;
404 indir->cmd = ETHTOOL_GRXFHINDIR;
405 indir->size = table_size;
406 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
407 if (ret)
408 goto out;
410 if (copy_to_user(useraddr, indir, full_size))
411 ret = -EFAULT;
413 out:
414 kfree(indir);
415 return ret;
418 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
419 void __user *useraddr)
421 struct ethtool_rxfh_indir *indir;
422 u32 table_size;
423 size_t full_size;
424 int ret;
426 if (!dev->ethtool_ops->set_rxfh_indir)
427 return -EOPNOTSUPP;
429 if (copy_from_user(&table_size,
430 useraddr + offsetof(struct ethtool_rxfh_indir, size),
431 sizeof(table_size)))
432 return -EFAULT;
434 if (table_size >
435 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
436 return -ENOMEM;
437 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
438 indir = kmalloc(full_size, GFP_USER);
439 if (!indir)
440 return -ENOMEM;
442 if (copy_from_user(indir, useraddr, full_size)) {
443 ret = -EFAULT;
444 goto out;
447 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
449 out:
450 kfree(indir);
451 return ret;
454 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
455 struct ethtool_rx_ntuple_flow_spec *spec,
456 struct ethtool_rx_ntuple_flow_spec_container *fsc)
459 /* don't add filters forever */
460 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
461 /* free the container */
462 kfree(fsc);
463 return;
466 /* Copy the whole filter over */
467 fsc->fs.flow_type = spec->flow_type;
468 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
469 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
471 fsc->fs.vlan_tag = spec->vlan_tag;
472 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
473 fsc->fs.data = spec->data;
474 fsc->fs.data_mask = spec->data_mask;
475 fsc->fs.action = spec->action;
477 /* add to the list */
478 list_add_tail_rcu(&fsc->list, &list->list);
479 list->count++;
482 static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
483 void __user *useraddr)
485 struct ethtool_rx_ntuple cmd;
486 const struct ethtool_ops *ops = dev->ethtool_ops;
487 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
488 int ret;
490 if (!(dev->features & NETIF_F_NTUPLE))
491 return -EINVAL;
493 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
494 return -EFAULT;
497 * Cache filter in dev struct for GET operation only if
498 * the underlying driver doesn't have its own GET operation, and
499 * only if the filter was added successfully. First make sure we
500 * can allocate the filter, then continue if successful.
502 if (!ops->get_rx_ntuple) {
503 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
504 if (!fsc)
505 return -ENOMEM;
508 ret = ops->set_rx_ntuple(dev, &cmd);
509 if (ret) {
510 kfree(fsc);
511 return ret;
514 if (!ops->get_rx_ntuple)
515 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
517 return ret;
520 static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
522 struct ethtool_gstrings gstrings;
523 const struct ethtool_ops *ops = dev->ethtool_ops;
524 struct ethtool_rx_ntuple_flow_spec_container *fsc;
525 u8 *data;
526 char *p;
527 int ret, i, num_strings = 0;
529 if (!ops->get_sset_count)
530 return -EOPNOTSUPP;
532 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
533 return -EFAULT;
535 ret = ops->get_sset_count(dev, gstrings.string_set);
536 if (ret < 0)
537 return ret;
539 gstrings.len = ret;
541 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
542 if (!data)
543 return -ENOMEM;
545 if (ops->get_rx_ntuple) {
546 /* driver-specific filter grab */
547 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
548 goto copy;
551 /* default ethtool filter grab */
552 i = 0;
553 p = (char *)data;
554 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
555 sprintf(p, "Filter %d:\n", i);
556 p += ETH_GSTRING_LEN;
557 num_strings++;
559 switch (fsc->fs.flow_type) {
560 case TCP_V4_FLOW:
561 sprintf(p, "\tFlow Type: TCP\n");
562 p += ETH_GSTRING_LEN;
563 num_strings++;
564 break;
565 case UDP_V4_FLOW:
566 sprintf(p, "\tFlow Type: UDP\n");
567 p += ETH_GSTRING_LEN;
568 num_strings++;
569 break;
570 case SCTP_V4_FLOW:
571 sprintf(p, "\tFlow Type: SCTP\n");
572 p += ETH_GSTRING_LEN;
573 num_strings++;
574 break;
575 case AH_ESP_V4_FLOW:
576 sprintf(p, "\tFlow Type: AH ESP\n");
577 p += ETH_GSTRING_LEN;
578 num_strings++;
579 break;
580 case ESP_V4_FLOW:
581 sprintf(p, "\tFlow Type: ESP\n");
582 p += ETH_GSTRING_LEN;
583 num_strings++;
584 break;
585 case IP_USER_FLOW:
586 sprintf(p, "\tFlow Type: Raw IP\n");
587 p += ETH_GSTRING_LEN;
588 num_strings++;
589 break;
590 case IPV4_FLOW:
591 sprintf(p, "\tFlow Type: IPv4\n");
592 p += ETH_GSTRING_LEN;
593 num_strings++;
594 break;
595 default:
596 sprintf(p, "\tFlow Type: Unknown\n");
597 p += ETH_GSTRING_LEN;
598 num_strings++;
599 goto unknown_filter;
602 /* now the rest of the filters */
603 switch (fsc->fs.flow_type) {
604 case TCP_V4_FLOW:
605 case UDP_V4_FLOW:
606 case SCTP_V4_FLOW:
607 sprintf(p, "\tSrc IP addr: 0x%x\n",
608 fsc->fs.h_u.tcp_ip4_spec.ip4src);
609 p += ETH_GSTRING_LEN;
610 num_strings++;
611 sprintf(p, "\tSrc IP mask: 0x%x\n",
612 fsc->fs.m_u.tcp_ip4_spec.ip4src);
613 p += ETH_GSTRING_LEN;
614 num_strings++;
615 sprintf(p, "\tDest IP addr: 0x%x\n",
616 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
617 p += ETH_GSTRING_LEN;
618 num_strings++;
619 sprintf(p, "\tDest IP mask: 0x%x\n",
620 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
621 p += ETH_GSTRING_LEN;
622 num_strings++;
623 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
624 fsc->fs.h_u.tcp_ip4_spec.psrc,
625 fsc->fs.m_u.tcp_ip4_spec.psrc);
626 p += ETH_GSTRING_LEN;
627 num_strings++;
628 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
629 fsc->fs.h_u.tcp_ip4_spec.pdst,
630 fsc->fs.m_u.tcp_ip4_spec.pdst);
631 p += ETH_GSTRING_LEN;
632 num_strings++;
633 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
634 fsc->fs.h_u.tcp_ip4_spec.tos,
635 fsc->fs.m_u.tcp_ip4_spec.tos);
636 p += ETH_GSTRING_LEN;
637 num_strings++;
638 break;
639 case AH_ESP_V4_FLOW:
640 case ESP_V4_FLOW:
641 sprintf(p, "\tSrc IP addr: 0x%x\n",
642 fsc->fs.h_u.ah_ip4_spec.ip4src);
643 p += ETH_GSTRING_LEN;
644 num_strings++;
645 sprintf(p, "\tSrc IP mask: 0x%x\n",
646 fsc->fs.m_u.ah_ip4_spec.ip4src);
647 p += ETH_GSTRING_LEN;
648 num_strings++;
649 sprintf(p, "\tDest IP addr: 0x%x\n",
650 fsc->fs.h_u.ah_ip4_spec.ip4dst);
651 p += ETH_GSTRING_LEN;
652 num_strings++;
653 sprintf(p, "\tDest IP mask: 0x%x\n",
654 fsc->fs.m_u.ah_ip4_spec.ip4dst);
655 p += ETH_GSTRING_LEN;
656 num_strings++;
657 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
658 fsc->fs.h_u.ah_ip4_spec.spi,
659 fsc->fs.m_u.ah_ip4_spec.spi);
660 p += ETH_GSTRING_LEN;
661 num_strings++;
662 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
663 fsc->fs.h_u.ah_ip4_spec.tos,
664 fsc->fs.m_u.ah_ip4_spec.tos);
665 p += ETH_GSTRING_LEN;
666 num_strings++;
667 break;
668 case IP_USER_FLOW:
669 sprintf(p, "\tSrc IP addr: 0x%x\n",
670 fsc->fs.h_u.raw_ip4_spec.ip4src);
671 p += ETH_GSTRING_LEN;
672 num_strings++;
673 sprintf(p, "\tSrc IP mask: 0x%x\n",
674 fsc->fs.m_u.raw_ip4_spec.ip4src);
675 p += ETH_GSTRING_LEN;
676 num_strings++;
677 sprintf(p, "\tDest IP addr: 0x%x\n",
678 fsc->fs.h_u.raw_ip4_spec.ip4dst);
679 p += ETH_GSTRING_LEN;
680 num_strings++;
681 sprintf(p, "\tDest IP mask: 0x%x\n",
682 fsc->fs.m_u.raw_ip4_spec.ip4dst);
683 p += ETH_GSTRING_LEN;
684 num_strings++;
685 break;
686 case IPV4_FLOW:
687 sprintf(p, "\tSrc IP addr: 0x%x\n",
688 fsc->fs.h_u.usr_ip4_spec.ip4src);
689 p += ETH_GSTRING_LEN;
690 num_strings++;
691 sprintf(p, "\tSrc IP mask: 0x%x\n",
692 fsc->fs.m_u.usr_ip4_spec.ip4src);
693 p += ETH_GSTRING_LEN;
694 num_strings++;
695 sprintf(p, "\tDest IP addr: 0x%x\n",
696 fsc->fs.h_u.usr_ip4_spec.ip4dst);
697 p += ETH_GSTRING_LEN;
698 num_strings++;
699 sprintf(p, "\tDest IP mask: 0x%x\n",
700 fsc->fs.m_u.usr_ip4_spec.ip4dst);
701 p += ETH_GSTRING_LEN;
702 num_strings++;
703 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
704 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
705 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
706 p += ETH_GSTRING_LEN;
707 num_strings++;
708 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
709 fsc->fs.h_u.usr_ip4_spec.tos,
710 fsc->fs.m_u.usr_ip4_spec.tos);
711 p += ETH_GSTRING_LEN;
712 num_strings++;
713 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
714 fsc->fs.h_u.usr_ip4_spec.ip_ver,
715 fsc->fs.m_u.usr_ip4_spec.ip_ver);
716 p += ETH_GSTRING_LEN;
717 num_strings++;
718 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
719 fsc->fs.h_u.usr_ip4_spec.proto,
720 fsc->fs.m_u.usr_ip4_spec.proto);
721 p += ETH_GSTRING_LEN;
722 num_strings++;
723 break;
725 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
726 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
727 p += ETH_GSTRING_LEN;
728 num_strings++;
729 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
730 p += ETH_GSTRING_LEN;
731 num_strings++;
732 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
733 p += ETH_GSTRING_LEN;
734 num_strings++;
735 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
736 sprintf(p, "\tAction: Drop\n");
737 else
738 sprintf(p, "\tAction: Direct to queue %d\n",
739 fsc->fs.action);
740 p += ETH_GSTRING_LEN;
741 num_strings++;
742 unknown_filter:
743 i++;
745 copy:
746 /* indicate to userspace how many strings we actually have */
747 gstrings.len = num_strings;
748 ret = -EFAULT;
749 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
750 goto out;
751 useraddr += sizeof(gstrings);
752 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
753 goto out;
754 ret = 0;
756 out:
757 kfree(data);
758 return ret;
761 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
763 struct ethtool_regs regs;
764 const struct ethtool_ops *ops = dev->ethtool_ops;
765 void *regbuf;
766 int reglen, ret;
768 if (!ops->get_regs || !ops->get_regs_len)
769 return -EOPNOTSUPP;
771 if (copy_from_user(&regs, useraddr, sizeof(regs)))
772 return -EFAULT;
774 reglen = ops->get_regs_len(dev);
775 if (regs.len > reglen)
776 regs.len = reglen;
778 regbuf = kmalloc(reglen, GFP_USER);
779 if (!regbuf)
780 return -ENOMEM;
782 ops->get_regs(dev, &regs, regbuf);
784 ret = -EFAULT;
785 if (copy_to_user(useraddr, &regs, sizeof(regs)))
786 goto out;
787 useraddr += offsetof(struct ethtool_regs, data);
788 if (copy_to_user(useraddr, regbuf, regs.len))
789 goto out;
790 ret = 0;
792 out:
793 kfree(regbuf);
794 return ret;
797 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
799 struct ethtool_value reset;
800 int ret;
802 if (!dev->ethtool_ops->reset)
803 return -EOPNOTSUPP;
805 if (copy_from_user(&reset, useraddr, sizeof(reset)))
806 return -EFAULT;
808 ret = dev->ethtool_ops->reset(dev, &reset.data);
809 if (ret)
810 return ret;
812 if (copy_to_user(useraddr, &reset, sizeof(reset)))
813 return -EFAULT;
814 return 0;
817 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
819 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
821 if (!dev->ethtool_ops->get_wol)
822 return -EOPNOTSUPP;
824 dev->ethtool_ops->get_wol(dev, &wol);
826 if (copy_to_user(useraddr, &wol, sizeof(wol)))
827 return -EFAULT;
828 return 0;
831 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
833 struct ethtool_wolinfo wol;
835 if (!dev->ethtool_ops->set_wol)
836 return -EOPNOTSUPP;
838 if (copy_from_user(&wol, useraddr, sizeof(wol)))
839 return -EFAULT;
841 return dev->ethtool_ops->set_wol(dev, &wol);
844 static int ethtool_nway_reset(struct net_device *dev)
846 if (!dev->ethtool_ops->nway_reset)
847 return -EOPNOTSUPP;
849 return dev->ethtool_ops->nway_reset(dev);
852 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
854 struct ethtool_eeprom eeprom;
855 const struct ethtool_ops *ops = dev->ethtool_ops;
856 void __user *userbuf = useraddr + sizeof(eeprom);
857 u32 bytes_remaining;
858 u8 *data;
859 int ret = 0;
861 if (!ops->get_eeprom || !ops->get_eeprom_len)
862 return -EOPNOTSUPP;
864 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
865 return -EFAULT;
867 /* Check for wrap and zero */
868 if (eeprom.offset + eeprom.len <= eeprom.offset)
869 return -EINVAL;
871 /* Check for exceeding total eeprom len */
872 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
873 return -EINVAL;
875 data = kmalloc(PAGE_SIZE, GFP_USER);
876 if (!data)
877 return -ENOMEM;
879 bytes_remaining = eeprom.len;
880 while (bytes_remaining > 0) {
881 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
883 ret = ops->get_eeprom(dev, &eeprom, data);
884 if (ret)
885 break;
886 if (copy_to_user(userbuf, data, eeprom.len)) {
887 ret = -EFAULT;
888 break;
890 userbuf += eeprom.len;
891 eeprom.offset += eeprom.len;
892 bytes_remaining -= eeprom.len;
895 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
896 eeprom.offset -= eeprom.len;
897 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
898 ret = -EFAULT;
900 kfree(data);
901 return ret;
904 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
906 struct ethtool_eeprom eeprom;
907 const struct ethtool_ops *ops = dev->ethtool_ops;
908 void __user *userbuf = useraddr + sizeof(eeprom);
909 u32 bytes_remaining;
910 u8 *data;
911 int ret = 0;
913 if (!ops->set_eeprom || !ops->get_eeprom_len)
914 return -EOPNOTSUPP;
916 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
917 return -EFAULT;
919 /* Check for wrap and zero */
920 if (eeprom.offset + eeprom.len <= eeprom.offset)
921 return -EINVAL;
923 /* Check for exceeding total eeprom len */
924 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
925 return -EINVAL;
927 data = kmalloc(PAGE_SIZE, GFP_USER);
928 if (!data)
929 return -ENOMEM;
931 bytes_remaining = eeprom.len;
932 while (bytes_remaining > 0) {
933 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
935 if (copy_from_user(data, userbuf, eeprom.len)) {
936 ret = -EFAULT;
937 break;
939 ret = ops->set_eeprom(dev, &eeprom, data);
940 if (ret)
941 break;
942 userbuf += eeprom.len;
943 eeprom.offset += eeprom.len;
944 bytes_remaining -= eeprom.len;
947 kfree(data);
948 return ret;
951 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
952 void __user *useraddr)
954 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
956 if (!dev->ethtool_ops->get_coalesce)
957 return -EOPNOTSUPP;
959 dev->ethtool_ops->get_coalesce(dev, &coalesce);
961 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
962 return -EFAULT;
963 return 0;
966 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
967 void __user *useraddr)
969 struct ethtool_coalesce coalesce;
971 if (!dev->ethtool_ops->set_coalesce)
972 return -EOPNOTSUPP;
974 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
975 return -EFAULT;
977 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
980 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
982 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
984 if (!dev->ethtool_ops->get_ringparam)
985 return -EOPNOTSUPP;
987 dev->ethtool_ops->get_ringparam(dev, &ringparam);
989 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
990 return -EFAULT;
991 return 0;
994 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
996 struct ethtool_ringparam ringparam;
998 if (!dev->ethtool_ops->set_ringparam)
999 return -EOPNOTSUPP;
1001 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1002 return -EFAULT;
1004 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1007 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1009 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1011 if (!dev->ethtool_ops->get_pauseparam)
1012 return -EOPNOTSUPP;
1014 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1016 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1017 return -EFAULT;
1018 return 0;
1021 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1023 struct ethtool_pauseparam pauseparam;
1025 if (!dev->ethtool_ops->set_pauseparam)
1026 return -EOPNOTSUPP;
1028 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1029 return -EFAULT;
1031 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1034 static int __ethtool_set_sg(struct net_device *dev, u32 data)
1036 int err;
1038 if (!data && dev->ethtool_ops->set_tso) {
1039 err = dev->ethtool_ops->set_tso(dev, 0);
1040 if (err)
1041 return err;
1044 if (!data && dev->ethtool_ops->set_ufo) {
1045 err = dev->ethtool_ops->set_ufo(dev, 0);
1046 if (err)
1047 return err;
1049 return dev->ethtool_ops->set_sg(dev, data);
1052 static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
1054 struct ethtool_value edata;
1055 int err;
1057 if (!dev->ethtool_ops->set_tx_csum)
1058 return -EOPNOTSUPP;
1060 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1061 return -EFAULT;
1063 if (!edata.data && dev->ethtool_ops->set_sg) {
1064 err = __ethtool_set_sg(dev, 0);
1065 if (err)
1066 return err;
1069 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
1071 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
1073 static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
1075 struct ethtool_value edata;
1077 if (!dev->ethtool_ops->set_rx_csum)
1078 return -EOPNOTSUPP;
1080 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1081 return -EFAULT;
1083 if (!edata.data && dev->ethtool_ops->set_sg)
1084 dev->features &= ~NETIF_F_GRO;
1086 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
1089 static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
1091 struct ethtool_value edata;
1093 if (!dev->ethtool_ops->set_sg)
1094 return -EOPNOTSUPP;
1096 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1097 return -EFAULT;
1099 if (edata.data &&
1100 !(dev->features & NETIF_F_ALL_CSUM))
1101 return -EINVAL;
1103 return __ethtool_set_sg(dev, edata.data);
1106 static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1108 struct ethtool_value edata;
1110 if (!dev->ethtool_ops->set_tso)
1111 return -EOPNOTSUPP;
1113 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1114 return -EFAULT;
1116 if (edata.data && !(dev->features & NETIF_F_SG))
1117 return -EINVAL;
1119 return dev->ethtool_ops->set_tso(dev, edata.data);
1122 static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1124 struct ethtool_value edata;
1126 if (!dev->ethtool_ops->set_ufo)
1127 return -EOPNOTSUPP;
1128 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1129 return -EFAULT;
1130 if (edata.data && !(dev->features & NETIF_F_SG))
1131 return -EINVAL;
1132 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1133 return -EINVAL;
1134 return dev->ethtool_ops->set_ufo(dev, edata.data);
1137 static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1139 struct ethtool_value edata = { ETHTOOL_GGSO };
1141 edata.data = dev->features & NETIF_F_GSO;
1142 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1143 return -EFAULT;
1144 return 0;
1147 static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1149 struct ethtool_value edata;
1151 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1152 return -EFAULT;
1153 if (edata.data)
1154 dev->features |= NETIF_F_GSO;
1155 else
1156 dev->features &= ~NETIF_F_GSO;
1157 return 0;
1160 static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1162 struct ethtool_value edata = { ETHTOOL_GGRO };
1164 edata.data = dev->features & NETIF_F_GRO;
1165 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1166 return -EFAULT;
1167 return 0;
1170 static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1172 struct ethtool_value edata;
1174 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1175 return -EFAULT;
1177 if (edata.data) {
1178 if (!dev->ethtool_ops->get_rx_csum ||
1179 !dev->ethtool_ops->get_rx_csum(dev))
1180 return -EINVAL;
1181 dev->features |= NETIF_F_GRO;
1182 } else
1183 dev->features &= ~NETIF_F_GRO;
1185 return 0;
1188 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1190 struct ethtool_test test;
1191 const struct ethtool_ops *ops = dev->ethtool_ops;
1192 u64 *data;
1193 int ret, test_len;
1195 if (!ops->self_test || !ops->get_sset_count)
1196 return -EOPNOTSUPP;
1198 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1199 if (test_len < 0)
1200 return test_len;
1201 WARN_ON(test_len == 0);
1203 if (copy_from_user(&test, useraddr, sizeof(test)))
1204 return -EFAULT;
1206 test.len = test_len;
1207 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1208 if (!data)
1209 return -ENOMEM;
1211 ops->self_test(dev, &test, data);
1213 ret = -EFAULT;
1214 if (copy_to_user(useraddr, &test, sizeof(test)))
1215 goto out;
1216 useraddr += sizeof(test);
1217 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1218 goto out;
1219 ret = 0;
1221 out:
1222 kfree(data);
1223 return ret;
1226 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1228 struct ethtool_gstrings gstrings;
1229 const struct ethtool_ops *ops = dev->ethtool_ops;
1230 u8 *data;
1231 int ret;
1233 if (!ops->get_strings || !ops->get_sset_count)
1234 return -EOPNOTSUPP;
1236 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1237 return -EFAULT;
1239 ret = ops->get_sset_count(dev, gstrings.string_set);
1240 if (ret < 0)
1241 return ret;
1243 gstrings.len = ret;
1245 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1246 if (!data)
1247 return -ENOMEM;
1249 ops->get_strings(dev, gstrings.string_set, data);
1251 ret = -EFAULT;
1252 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1253 goto out;
1254 useraddr += sizeof(gstrings);
1255 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1256 goto out;
1257 ret = 0;
1259 out:
1260 kfree(data);
1261 return ret;
1264 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1266 struct ethtool_value id;
1268 if (!dev->ethtool_ops->phys_id)
1269 return -EOPNOTSUPP;
1271 if (copy_from_user(&id, useraddr, sizeof(id)))
1272 return -EFAULT;
1274 return dev->ethtool_ops->phys_id(dev, id.data);
1277 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1279 struct ethtool_stats stats;
1280 const struct ethtool_ops *ops = dev->ethtool_ops;
1281 u64 *data;
1282 int ret, n_stats;
1284 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1285 return -EOPNOTSUPP;
1287 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1288 if (n_stats < 0)
1289 return n_stats;
1290 WARN_ON(n_stats == 0);
1292 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1293 return -EFAULT;
1295 stats.n_stats = n_stats;
1296 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1297 if (!data)
1298 return -ENOMEM;
1300 ops->get_ethtool_stats(dev, &stats, data);
1302 ret = -EFAULT;
1303 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1304 goto out;
1305 useraddr += sizeof(stats);
1306 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1307 goto out;
1308 ret = 0;
1310 out:
1311 kfree(data);
1312 return ret;
1315 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1317 struct ethtool_perm_addr epaddr;
1319 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1320 return -EFAULT;
1322 if (epaddr.size < dev->addr_len)
1323 return -ETOOSMALL;
1324 epaddr.size = dev->addr_len;
1326 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1327 return -EFAULT;
1328 useraddr += sizeof(epaddr);
1329 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1330 return -EFAULT;
1331 return 0;
1334 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1335 u32 cmd, u32 (*actor)(struct net_device *))
1337 struct ethtool_value edata = { .cmd = cmd };
1339 if (!actor)
1340 return -EOPNOTSUPP;
1342 edata.data = actor(dev);
1344 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1345 return -EFAULT;
1346 return 0;
1349 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1350 void (*actor)(struct net_device *, u32))
1352 struct ethtool_value edata;
1354 if (!actor)
1355 return -EOPNOTSUPP;
1357 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1358 return -EFAULT;
1360 actor(dev, edata.data);
1361 return 0;
1364 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1365 int (*actor)(struct net_device *, u32))
1367 struct ethtool_value edata;
1369 if (!actor)
1370 return -EOPNOTSUPP;
1372 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1373 return -EFAULT;
1375 return actor(dev, edata.data);
1378 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1379 char __user *useraddr)
1381 struct ethtool_flash efl;
1383 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1384 return -EFAULT;
1386 if (!dev->ethtool_ops->flash_device)
1387 return -EOPNOTSUPP;
1389 return dev->ethtool_ops->flash_device(dev, &efl);
1392 /* The main entry point in this file. Called from net/core/dev.c */
1394 int dev_ethtool(struct net *net, struct ifreq *ifr)
1396 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1397 void __user *useraddr = ifr->ifr_data;
1398 u32 ethcmd;
1399 int rc;
1400 unsigned long old_features;
1402 if (!dev || !netif_device_present(dev))
1403 return -ENODEV;
1405 if (!dev->ethtool_ops)
1406 return -EOPNOTSUPP;
1408 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
1409 return -EFAULT;
1411 /* Allow some commands to be done by anyone */
1412 switch (ethcmd) {
1413 case ETHTOOL_GDRVINFO:
1414 case ETHTOOL_GMSGLVL:
1415 case ETHTOOL_GCOALESCE:
1416 case ETHTOOL_GRINGPARAM:
1417 case ETHTOOL_GPAUSEPARAM:
1418 case ETHTOOL_GRXCSUM:
1419 case ETHTOOL_GTXCSUM:
1420 case ETHTOOL_GSG:
1421 case ETHTOOL_GSTRINGS:
1422 case ETHTOOL_GTSO:
1423 case ETHTOOL_GPERMADDR:
1424 case ETHTOOL_GUFO:
1425 case ETHTOOL_GGSO:
1426 case ETHTOOL_GGRO:
1427 case ETHTOOL_GFLAGS:
1428 case ETHTOOL_GPFLAGS:
1429 case ETHTOOL_GRXFH:
1430 case ETHTOOL_GRXRINGS:
1431 case ETHTOOL_GRXCLSRLCNT:
1432 case ETHTOOL_GRXCLSRULE:
1433 case ETHTOOL_GRXCLSRLALL:
1434 break;
1435 default:
1436 if (!capable(CAP_NET_ADMIN))
1437 return -EPERM;
1440 if (dev->ethtool_ops->begin) {
1441 rc = dev->ethtool_ops->begin(dev);
1442 if (rc < 0)
1443 return rc;
1445 old_features = dev->features;
1447 switch (ethcmd) {
1448 case ETHTOOL_GSET:
1449 rc = ethtool_get_settings(dev, useraddr);
1450 break;
1451 case ETHTOOL_SSET:
1452 rc = ethtool_set_settings(dev, useraddr);
1453 break;
1454 case ETHTOOL_GDRVINFO:
1455 rc = ethtool_get_drvinfo(dev, useraddr);
1456 break;
1457 case ETHTOOL_GREGS:
1458 rc = ethtool_get_regs(dev, useraddr);
1459 break;
1460 case ETHTOOL_GWOL:
1461 rc = ethtool_get_wol(dev, useraddr);
1462 break;
1463 case ETHTOOL_SWOL:
1464 rc = ethtool_set_wol(dev, useraddr);
1465 break;
1466 case ETHTOOL_GMSGLVL:
1467 rc = ethtool_get_value(dev, useraddr, ethcmd,
1468 dev->ethtool_ops->get_msglevel);
1469 break;
1470 case ETHTOOL_SMSGLVL:
1471 rc = ethtool_set_value_void(dev, useraddr,
1472 dev->ethtool_ops->set_msglevel);
1473 break;
1474 case ETHTOOL_NWAY_RST:
1475 rc = ethtool_nway_reset(dev);
1476 break;
1477 case ETHTOOL_GLINK:
1478 rc = ethtool_get_value(dev, useraddr, ethcmd,
1479 dev->ethtool_ops->get_link);
1480 break;
1481 case ETHTOOL_GEEPROM:
1482 rc = ethtool_get_eeprom(dev, useraddr);
1483 break;
1484 case ETHTOOL_SEEPROM:
1485 rc = ethtool_set_eeprom(dev, useraddr);
1486 break;
1487 case ETHTOOL_GCOALESCE:
1488 rc = ethtool_get_coalesce(dev, useraddr);
1489 break;
1490 case ETHTOOL_SCOALESCE:
1491 rc = ethtool_set_coalesce(dev, useraddr);
1492 break;
1493 case ETHTOOL_GRINGPARAM:
1494 rc = ethtool_get_ringparam(dev, useraddr);
1495 break;
1496 case ETHTOOL_SRINGPARAM:
1497 rc = ethtool_set_ringparam(dev, useraddr);
1498 break;
1499 case ETHTOOL_GPAUSEPARAM:
1500 rc = ethtool_get_pauseparam(dev, useraddr);
1501 break;
1502 case ETHTOOL_SPAUSEPARAM:
1503 rc = ethtool_set_pauseparam(dev, useraddr);
1504 break;
1505 case ETHTOOL_GRXCSUM:
1506 rc = ethtool_get_value(dev, useraddr, ethcmd,
1507 (dev->ethtool_ops->get_rx_csum ?
1508 dev->ethtool_ops->get_rx_csum :
1509 ethtool_op_get_rx_csum));
1510 break;
1511 case ETHTOOL_SRXCSUM:
1512 rc = ethtool_set_rx_csum(dev, useraddr);
1513 break;
1514 case ETHTOOL_GTXCSUM:
1515 rc = ethtool_get_value(dev, useraddr, ethcmd,
1516 (dev->ethtool_ops->get_tx_csum ?
1517 dev->ethtool_ops->get_tx_csum :
1518 ethtool_op_get_tx_csum));
1519 break;
1520 case ETHTOOL_STXCSUM:
1521 rc = ethtool_set_tx_csum(dev, useraddr);
1522 break;
1523 case ETHTOOL_GSG:
1524 rc = ethtool_get_value(dev, useraddr, ethcmd,
1525 (dev->ethtool_ops->get_sg ?
1526 dev->ethtool_ops->get_sg :
1527 ethtool_op_get_sg));
1528 break;
1529 case ETHTOOL_SSG:
1530 rc = ethtool_set_sg(dev, useraddr);
1531 break;
1532 case ETHTOOL_GTSO:
1533 rc = ethtool_get_value(dev, useraddr, ethcmd,
1534 (dev->ethtool_ops->get_tso ?
1535 dev->ethtool_ops->get_tso :
1536 ethtool_op_get_tso));
1537 break;
1538 case ETHTOOL_STSO:
1539 rc = ethtool_set_tso(dev, useraddr);
1540 break;
1541 case ETHTOOL_TEST:
1542 rc = ethtool_self_test(dev, useraddr);
1543 break;
1544 case ETHTOOL_GSTRINGS:
1545 rc = ethtool_get_strings(dev, useraddr);
1546 break;
1547 case ETHTOOL_PHYS_ID:
1548 rc = ethtool_phys_id(dev, useraddr);
1549 break;
1550 case ETHTOOL_GSTATS:
1551 rc = ethtool_get_stats(dev, useraddr);
1552 break;
1553 case ETHTOOL_GPERMADDR:
1554 rc = ethtool_get_perm_addr(dev, useraddr);
1555 break;
1556 case ETHTOOL_GUFO:
1557 rc = ethtool_get_value(dev, useraddr, ethcmd,
1558 (dev->ethtool_ops->get_ufo ?
1559 dev->ethtool_ops->get_ufo :
1560 ethtool_op_get_ufo));
1561 break;
1562 case ETHTOOL_SUFO:
1563 rc = ethtool_set_ufo(dev, useraddr);
1564 break;
1565 case ETHTOOL_GGSO:
1566 rc = ethtool_get_gso(dev, useraddr);
1567 break;
1568 case ETHTOOL_SGSO:
1569 rc = ethtool_set_gso(dev, useraddr);
1570 break;
1571 case ETHTOOL_GFLAGS:
1572 rc = ethtool_get_value(dev, useraddr, ethcmd,
1573 (dev->ethtool_ops->get_flags ?
1574 dev->ethtool_ops->get_flags :
1575 ethtool_op_get_flags));
1576 break;
1577 case ETHTOOL_SFLAGS:
1578 rc = ethtool_set_value(dev, useraddr,
1579 dev->ethtool_ops->set_flags);
1580 break;
1581 case ETHTOOL_GPFLAGS:
1582 rc = ethtool_get_value(dev, useraddr, ethcmd,
1583 dev->ethtool_ops->get_priv_flags);
1584 break;
1585 case ETHTOOL_SPFLAGS:
1586 rc = ethtool_set_value(dev, useraddr,
1587 dev->ethtool_ops->set_priv_flags);
1588 break;
1589 case ETHTOOL_GRXFH:
1590 case ETHTOOL_GRXRINGS:
1591 case ETHTOOL_GRXCLSRLCNT:
1592 case ETHTOOL_GRXCLSRULE:
1593 case ETHTOOL_GRXCLSRLALL:
1594 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
1595 break;
1596 case ETHTOOL_SRXFH:
1597 case ETHTOOL_SRXCLSRLDEL:
1598 case ETHTOOL_SRXCLSRLINS:
1599 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
1600 break;
1601 case ETHTOOL_GGRO:
1602 rc = ethtool_get_gro(dev, useraddr);
1603 break;
1604 case ETHTOOL_SGRO:
1605 rc = ethtool_set_gro(dev, useraddr);
1606 break;
1607 case ETHTOOL_FLASHDEV:
1608 rc = ethtool_flash_device(dev, useraddr);
1609 break;
1610 case ETHTOOL_RESET:
1611 rc = ethtool_reset(dev, useraddr);
1612 break;
1613 case ETHTOOL_SRXNTUPLE:
1614 rc = ethtool_set_rx_ntuple(dev, useraddr);
1615 break;
1616 case ETHTOOL_GRXNTUPLE:
1617 rc = ethtool_get_rx_ntuple(dev, useraddr);
1618 break;
1619 case ETHTOOL_GSSET_INFO:
1620 rc = ethtool_get_sset_info(dev, useraddr);
1621 break;
1622 case ETHTOOL_GRXFHINDIR:
1623 rc = ethtool_get_rxfh_indir(dev, useraddr);
1624 break;
1625 case ETHTOOL_SRXFHINDIR:
1626 rc = ethtool_set_rxfh_indir(dev, useraddr);
1627 break;
1628 default:
1629 rc = -EOPNOTSUPP;
1632 if (dev->ethtool_ops->complete)
1633 dev->ethtool_ops->complete(dev);
1635 if (old_features != dev->features)
1636 netdev_features_change(dev);
1638 return rc;