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 <asm/uaccess.h>
23 * Some useful ethtool_ops methods that're device independent.
24 * If we find that all drivers want to do the same thing here,
25 * we can turn these into dev_() function calls.
28 u32
ethtool_op_get_link(struct net_device
*dev
)
30 return netif_carrier_ok(dev
) ? 1 : 0;
33 u32
ethtool_op_get_rx_csum(struct net_device
*dev
)
35 return (dev
->features
& NETIF_F_ALL_CSUM
) != 0;
37 EXPORT_SYMBOL(ethtool_op_get_rx_csum
);
39 u32
ethtool_op_get_tx_csum(struct net_device
*dev
)
41 return (dev
->features
& NETIF_F_ALL_CSUM
) != 0;
43 EXPORT_SYMBOL(ethtool_op_get_tx_csum
);
45 int ethtool_op_set_tx_csum(struct net_device
*dev
, u32 data
)
48 dev
->features
|= NETIF_F_IP_CSUM
;
50 dev
->features
&= ~NETIF_F_IP_CSUM
;
55 int ethtool_op_set_tx_hw_csum(struct net_device
*dev
, u32 data
)
58 dev
->features
|= NETIF_F_HW_CSUM
;
60 dev
->features
&= ~NETIF_F_HW_CSUM
;
65 int ethtool_op_set_tx_ipv6_csum(struct net_device
*dev
, u32 data
)
68 dev
->features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
70 dev
->features
&= ~(NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
);
75 u32
ethtool_op_get_sg(struct net_device
*dev
)
77 return (dev
->features
& NETIF_F_SG
) != 0;
80 int ethtool_op_set_sg(struct net_device
*dev
, u32 data
)
83 dev
->features
|= NETIF_F_SG
;
85 dev
->features
&= ~NETIF_F_SG
;
90 u32
ethtool_op_get_tso(struct net_device
*dev
)
92 return (dev
->features
& NETIF_F_TSO
) != 0;
95 int ethtool_op_set_tso(struct net_device
*dev
, u32 data
)
98 dev
->features
|= NETIF_F_TSO
;
100 dev
->features
&= ~NETIF_F_TSO
;
105 u32
ethtool_op_get_ufo(struct net_device
*dev
)
107 return (dev
->features
& NETIF_F_UFO
) != 0;
110 int ethtool_op_set_ufo(struct net_device
*dev
, u32 data
)
113 dev
->features
|= NETIF_F_UFO
;
115 dev
->features
&= ~NETIF_F_UFO
;
119 /* the following list of flags are the same as their associated
120 * NETIF_F_xxx values in include/linux/netdevice.h
122 static const u32 flags_dup_features
=
125 u32
ethtool_op_get_flags(struct net_device
*dev
)
127 /* in the future, this function will probably contain additional
128 * handling for flags which are not so easily handled
129 * by a simple masking operation
132 return dev
->features
& flags_dup_features
;
135 int ethtool_op_set_flags(struct net_device
*dev
, u32 data
)
137 if (data
& ETH_FLAG_LRO
)
138 dev
->features
|= NETIF_F_LRO
;
140 dev
->features
&= ~NETIF_F_LRO
;
145 /* Handlers for each ethtool command */
147 static int ethtool_get_settings(struct net_device
*dev
, void __user
*useraddr
)
149 struct ethtool_cmd cmd
= { ETHTOOL_GSET
};
152 if (!dev
->ethtool_ops
->get_settings
)
155 err
= dev
->ethtool_ops
->get_settings(dev
, &cmd
);
159 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
164 static int ethtool_set_settings(struct net_device
*dev
, void __user
*useraddr
)
166 struct ethtool_cmd cmd
;
168 if (!dev
->ethtool_ops
->set_settings
)
171 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
174 return dev
->ethtool_ops
->set_settings(dev
, &cmd
);
177 static int ethtool_get_drvinfo(struct net_device
*dev
, void __user
*useraddr
)
179 struct ethtool_drvinfo info
;
180 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
182 if (!ops
->get_drvinfo
)
185 memset(&info
, 0, sizeof(info
));
186 info
.cmd
= ETHTOOL_GDRVINFO
;
187 ops
->get_drvinfo(dev
, &info
);
189 if (ops
->get_sset_count
) {
192 rc
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
194 info
.testinfo_len
= rc
;
195 rc
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
198 rc
= ops
->get_sset_count(dev
, ETH_SS_PRIV_FLAGS
);
200 info
.n_priv_flags
= rc
;
202 /* code path for obsolete hooks */
204 if (ops
->self_test_count
)
205 info
.testinfo_len
= ops
->self_test_count(dev
);
206 if (ops
->get_stats_count
)
207 info
.n_stats
= ops
->get_stats_count(dev
);
209 if (ops
->get_regs_len
)
210 info
.regdump_len
= ops
->get_regs_len(dev
);
211 if (ops
->get_eeprom_len
)
212 info
.eedump_len
= ops
->get_eeprom_len(dev
);
214 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
219 static int ethtool_set_rxnfc(struct net_device
*dev
,
220 u32 cmd
, void __user
*useraddr
)
222 struct ethtool_rxnfc info
;
223 size_t info_size
= sizeof(info
);
225 if (!dev
->ethtool_ops
->set_rxnfc
)
228 /* struct ethtool_rxnfc was originally defined for
229 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
230 * members. User-space might still be using that
232 if (cmd
== ETHTOOL_SRXFH
)
233 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
236 if (copy_from_user(&info
, useraddr
, info_size
))
239 return dev
->ethtool_ops
->set_rxnfc(dev
, &info
);
242 static int ethtool_get_rxnfc(struct net_device
*dev
,
243 u32 cmd
, void __user
*useraddr
)
245 struct ethtool_rxnfc info
;
246 size_t info_size
= sizeof(info
);
247 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
249 void *rule_buf
= NULL
;
254 /* struct ethtool_rxnfc was originally defined for
255 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
256 * members. User-space might still be using that
258 if (cmd
== ETHTOOL_GRXFH
)
259 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
262 if (copy_from_user(&info
, useraddr
, info_size
))
265 if (info
.cmd
== ETHTOOL_GRXCLSRLALL
) {
266 if (info
.rule_cnt
> 0) {
267 if (info
.rule_cnt
<= KMALLOC_MAX_SIZE
/ sizeof(u32
))
268 rule_buf
= kzalloc(info
.rule_cnt
* sizeof(u32
),
275 ret
= ops
->get_rxnfc(dev
, &info
, rule_buf
);
280 if (copy_to_user(useraddr
, &info
, info_size
))
284 useraddr
+= offsetof(struct ethtool_rxnfc
, rule_locs
);
285 if (copy_to_user(useraddr
, rule_buf
,
286 info
.rule_cnt
* sizeof(u32
)))
297 static int ethtool_get_regs(struct net_device
*dev
, char __user
*useraddr
)
299 struct ethtool_regs regs
;
300 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
304 if (!ops
->get_regs
|| !ops
->get_regs_len
)
307 if (copy_from_user(®s
, useraddr
, sizeof(regs
)))
310 reglen
= ops
->get_regs_len(dev
);
311 if (regs
.len
> reglen
)
314 regbuf
= kzalloc(reglen
, GFP_USER
);
318 ops
->get_regs(dev
, ®s
, regbuf
);
321 if (copy_to_user(useraddr
, ®s
, sizeof(regs
)))
323 useraddr
+= offsetof(struct ethtool_regs
, data
);
324 if (copy_to_user(useraddr
, regbuf
, regs
.len
))
333 static int ethtool_get_wol(struct net_device
*dev
, char __user
*useraddr
)
335 struct ethtool_wolinfo wol
= { ETHTOOL_GWOL
};
337 if (!dev
->ethtool_ops
->get_wol
)
340 dev
->ethtool_ops
->get_wol(dev
, &wol
);
342 if (copy_to_user(useraddr
, &wol
, sizeof(wol
)))
347 static int ethtool_set_wol(struct net_device
*dev
, char __user
*useraddr
)
349 struct ethtool_wolinfo wol
;
351 if (!dev
->ethtool_ops
->set_wol
)
354 if (copy_from_user(&wol
, useraddr
, sizeof(wol
)))
357 return dev
->ethtool_ops
->set_wol(dev
, &wol
);
360 static int ethtool_nway_reset(struct net_device
*dev
)
362 if (!dev
->ethtool_ops
->nway_reset
)
365 return dev
->ethtool_ops
->nway_reset(dev
);
368 static int ethtool_get_eeprom(struct net_device
*dev
, void __user
*useraddr
)
370 struct ethtool_eeprom eeprom
;
371 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
372 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
377 if (!ops
->get_eeprom
|| !ops
->get_eeprom_len
)
380 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
383 /* Check for wrap and zero */
384 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
387 /* Check for exceeding total eeprom len */
388 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
391 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
395 bytes_remaining
= eeprom
.len
;
396 while (bytes_remaining
> 0) {
397 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
399 ret
= ops
->get_eeprom(dev
, &eeprom
, data
);
402 if (copy_to_user(userbuf
, data
, eeprom
.len
)) {
406 userbuf
+= eeprom
.len
;
407 eeprom
.offset
+= eeprom
.len
;
408 bytes_remaining
-= eeprom
.len
;
411 eeprom
.len
= userbuf
- (useraddr
+ sizeof(eeprom
));
412 eeprom
.offset
-= eeprom
.len
;
413 if (copy_to_user(useraddr
, &eeprom
, sizeof(eeprom
)))
420 static int ethtool_set_eeprom(struct net_device
*dev
, void __user
*useraddr
)
422 struct ethtool_eeprom eeprom
;
423 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
424 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
429 if (!ops
->set_eeprom
|| !ops
->get_eeprom_len
)
432 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
435 /* Check for wrap and zero */
436 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
439 /* Check for exceeding total eeprom len */
440 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
443 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
447 bytes_remaining
= eeprom
.len
;
448 while (bytes_remaining
> 0) {
449 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
451 if (copy_from_user(data
, userbuf
, eeprom
.len
)) {
455 ret
= ops
->set_eeprom(dev
, &eeprom
, data
);
458 userbuf
+= eeprom
.len
;
459 eeprom
.offset
+= eeprom
.len
;
460 bytes_remaining
-= eeprom
.len
;
467 static int ethtool_get_coalesce(struct net_device
*dev
, void __user
*useraddr
)
469 struct ethtool_coalesce coalesce
= { ETHTOOL_GCOALESCE
};
471 if (!dev
->ethtool_ops
->get_coalesce
)
474 dev
->ethtool_ops
->get_coalesce(dev
, &coalesce
);
476 if (copy_to_user(useraddr
, &coalesce
, sizeof(coalesce
)))
481 static int ethtool_set_coalesce(struct net_device
*dev
, void __user
*useraddr
)
483 struct ethtool_coalesce coalesce
;
485 if (!dev
->ethtool_ops
->set_coalesce
)
488 if (copy_from_user(&coalesce
, useraddr
, sizeof(coalesce
)))
491 return dev
->ethtool_ops
->set_coalesce(dev
, &coalesce
);
494 static int ethtool_get_ringparam(struct net_device
*dev
, void __user
*useraddr
)
496 struct ethtool_ringparam ringparam
= { ETHTOOL_GRINGPARAM
};
498 if (!dev
->ethtool_ops
->get_ringparam
)
501 dev
->ethtool_ops
->get_ringparam(dev
, &ringparam
);
503 if (copy_to_user(useraddr
, &ringparam
, sizeof(ringparam
)))
508 static int ethtool_set_ringparam(struct net_device
*dev
, void __user
*useraddr
)
510 struct ethtool_ringparam ringparam
;
512 if (!dev
->ethtool_ops
->set_ringparam
)
515 if (copy_from_user(&ringparam
, useraddr
, sizeof(ringparam
)))
518 return dev
->ethtool_ops
->set_ringparam(dev
, &ringparam
);
521 static int ethtool_get_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
523 struct ethtool_pauseparam pauseparam
= { ETHTOOL_GPAUSEPARAM
};
525 if (!dev
->ethtool_ops
->get_pauseparam
)
528 dev
->ethtool_ops
->get_pauseparam(dev
, &pauseparam
);
530 if (copy_to_user(useraddr
, &pauseparam
, sizeof(pauseparam
)))
535 static int ethtool_set_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
537 struct ethtool_pauseparam pauseparam
;
539 if (!dev
->ethtool_ops
->set_pauseparam
)
542 if (copy_from_user(&pauseparam
, useraddr
, sizeof(pauseparam
)))
545 return dev
->ethtool_ops
->set_pauseparam(dev
, &pauseparam
);
548 static int __ethtool_set_sg(struct net_device
*dev
, u32 data
)
552 if (!data
&& dev
->ethtool_ops
->set_tso
) {
553 err
= dev
->ethtool_ops
->set_tso(dev
, 0);
558 if (!data
&& dev
->ethtool_ops
->set_ufo
) {
559 err
= dev
->ethtool_ops
->set_ufo(dev
, 0);
563 return dev
->ethtool_ops
->set_sg(dev
, data
);
566 static int ethtool_set_tx_csum(struct net_device
*dev
, char __user
*useraddr
)
568 struct ethtool_value edata
;
571 if (!dev
->ethtool_ops
->set_tx_csum
)
574 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
577 if (!edata
.data
&& dev
->ethtool_ops
->set_sg
) {
578 err
= __ethtool_set_sg(dev
, 0);
583 return dev
->ethtool_ops
->set_tx_csum(dev
, edata
.data
);
586 static int ethtool_set_rx_csum(struct net_device
*dev
, char __user
*useraddr
)
588 struct ethtool_value edata
;
590 if (!dev
->ethtool_ops
->set_rx_csum
)
593 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
596 if (!edata
.data
&& dev
->ethtool_ops
->set_sg
)
597 dev
->features
&= ~NETIF_F_GRO
;
599 return dev
->ethtool_ops
->set_rx_csum(dev
, edata
.data
);
602 static int ethtool_set_sg(struct net_device
*dev
, char __user
*useraddr
)
604 struct ethtool_value edata
;
606 if (!dev
->ethtool_ops
->set_sg
)
609 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
613 !(dev
->features
& NETIF_F_ALL_CSUM
))
616 return __ethtool_set_sg(dev
, edata
.data
);
619 static int ethtool_set_tso(struct net_device
*dev
, char __user
*useraddr
)
621 struct ethtool_value edata
;
623 if (!dev
->ethtool_ops
->set_tso
)
626 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
629 if (edata
.data
&& !(dev
->features
& NETIF_F_SG
))
632 return dev
->ethtool_ops
->set_tso(dev
, edata
.data
);
635 static int ethtool_set_ufo(struct net_device
*dev
, char __user
*useraddr
)
637 struct ethtool_value edata
;
639 if (!dev
->ethtool_ops
->set_ufo
)
641 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
643 if (edata
.data
&& !(dev
->features
& NETIF_F_SG
))
645 if (edata
.data
&& !(dev
->features
& NETIF_F_HW_CSUM
))
647 return dev
->ethtool_ops
->set_ufo(dev
, edata
.data
);
650 static int ethtool_get_gso(struct net_device
*dev
, char __user
*useraddr
)
652 struct ethtool_value edata
= { ETHTOOL_GGSO
};
654 edata
.data
= dev
->features
& NETIF_F_GSO
;
655 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
660 static int ethtool_set_gso(struct net_device
*dev
, char __user
*useraddr
)
662 struct ethtool_value edata
;
664 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
667 dev
->features
|= NETIF_F_GSO
;
669 dev
->features
&= ~NETIF_F_GSO
;
673 static int ethtool_get_gro(struct net_device
*dev
, char __user
*useraddr
)
675 struct ethtool_value edata
= { ETHTOOL_GGRO
};
677 edata
.data
= dev
->features
& NETIF_F_GRO
;
678 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
683 static int ethtool_set_gro(struct net_device
*dev
, char __user
*useraddr
)
685 struct ethtool_value edata
;
687 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
691 if (!dev
->ethtool_ops
->get_rx_csum
||
692 !dev
->ethtool_ops
->get_rx_csum(dev
))
694 dev
->features
|= NETIF_F_GRO
;
696 dev
->features
&= ~NETIF_F_GRO
;
701 static int ethtool_self_test(struct net_device
*dev
, char __user
*useraddr
)
703 struct ethtool_test test
;
704 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
710 if (!ops
->get_sset_count
&& !ops
->self_test_count
)
713 if (ops
->get_sset_count
)
714 test_len
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
716 /* code path for obsolete hook */
717 test_len
= ops
->self_test_count(dev
);
720 WARN_ON(test_len
== 0);
722 if (copy_from_user(&test
, useraddr
, sizeof(test
)))
726 data
= kmalloc(test_len
* sizeof(u64
), GFP_USER
);
730 ops
->self_test(dev
, &test
, data
);
733 if (copy_to_user(useraddr
, &test
, sizeof(test
)))
735 useraddr
+= sizeof(test
);
736 if (copy_to_user(useraddr
, data
, test
.len
* sizeof(u64
)))
745 static int ethtool_get_strings(struct net_device
*dev
, void __user
*useraddr
)
747 struct ethtool_gstrings gstrings
;
748 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
752 if (!ops
->get_strings
)
755 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
758 if (ops
->get_sset_count
) {
759 ret
= ops
->get_sset_count(dev
, gstrings
.string_set
);
765 /* code path for obsolete hooks */
767 switch (gstrings
.string_set
) {
769 if (!ops
->self_test_count
)
771 gstrings
.len
= ops
->self_test_count(dev
);
774 if (!ops
->get_stats_count
)
776 gstrings
.len
= ops
->get_stats_count(dev
);
783 data
= kmalloc(gstrings
.len
* ETH_GSTRING_LEN
, GFP_USER
);
787 ops
->get_strings(dev
, gstrings
.string_set
, data
);
790 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
792 useraddr
+= sizeof(gstrings
);
793 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
802 static int ethtool_phys_id(struct net_device
*dev
, void __user
*useraddr
)
804 struct ethtool_value id
;
806 if (!dev
->ethtool_ops
->phys_id
)
809 if (copy_from_user(&id
, useraddr
, sizeof(id
)))
812 return dev
->ethtool_ops
->phys_id(dev
, id
.data
);
815 static int ethtool_get_stats(struct net_device
*dev
, void __user
*useraddr
)
817 struct ethtool_stats stats
;
818 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
822 if (!ops
->get_ethtool_stats
)
824 if (!ops
->get_sset_count
&& !ops
->get_stats_count
)
827 if (ops
->get_sset_count
)
828 n_stats
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
830 /* code path for obsolete hook */
831 n_stats
= ops
->get_stats_count(dev
);
834 WARN_ON(n_stats
== 0);
836 if (copy_from_user(&stats
, useraddr
, sizeof(stats
)))
839 stats
.n_stats
= n_stats
;
840 data
= kmalloc(n_stats
* sizeof(u64
), GFP_USER
);
844 ops
->get_ethtool_stats(dev
, &stats
, data
);
847 if (copy_to_user(useraddr
, &stats
, sizeof(stats
)))
849 useraddr
+= sizeof(stats
);
850 if (copy_to_user(useraddr
, data
, stats
.n_stats
* sizeof(u64
)))
859 static int ethtool_get_perm_addr(struct net_device
*dev
, void __user
*useraddr
)
861 struct ethtool_perm_addr epaddr
;
863 if (copy_from_user(&epaddr
, useraddr
, sizeof(epaddr
)))
866 if (epaddr
.size
< dev
->addr_len
)
868 epaddr
.size
= dev
->addr_len
;
870 if (copy_to_user(useraddr
, &epaddr
, sizeof(epaddr
)))
872 useraddr
+= sizeof(epaddr
);
873 if (copy_to_user(useraddr
, dev
->perm_addr
, epaddr
.size
))
878 static int ethtool_get_value(struct net_device
*dev
, char __user
*useraddr
,
879 u32 cmd
, u32 (*actor
)(struct net_device
*))
881 struct ethtool_value edata
= { cmd
};
886 edata
.data
= actor(dev
);
888 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
893 static int ethtool_set_value_void(struct net_device
*dev
, char __user
*useraddr
,
894 void (*actor
)(struct net_device
*, u32
))
896 struct ethtool_value edata
;
901 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
904 actor(dev
, edata
.data
);
908 static int ethtool_set_value(struct net_device
*dev
, char __user
*useraddr
,
909 int (*actor
)(struct net_device
*, u32
))
911 struct ethtool_value edata
;
916 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
919 return actor(dev
, edata
.data
);
922 static int ethtool_flash_device(struct net_device
*dev
, char __user
*useraddr
)
924 struct ethtool_flash efl
;
926 if (copy_from_user(&efl
, useraddr
, sizeof(efl
)))
929 if (!dev
->ethtool_ops
->flash_device
)
932 return dev
->ethtool_ops
->flash_device(dev
, &efl
);
935 /* The main entry point in this file. Called from net/core/dev.c */
937 int dev_ethtool(struct net
*net
, struct ifreq
*ifr
)
939 struct net_device
*dev
= __dev_get_by_name(net
, ifr
->ifr_name
);
940 void __user
*useraddr
= ifr
->ifr_data
;
943 unsigned long old_features
;
945 if (!dev
|| !netif_device_present(dev
))
948 if (!dev
->ethtool_ops
)
951 if (copy_from_user(ðcmd
, useraddr
, sizeof (ethcmd
)))
954 /* Allow some commands to be done by anyone */
956 case ETHTOOL_GDRVINFO
:
957 case ETHTOOL_GMSGLVL
:
958 case ETHTOOL_GCOALESCE
:
959 case ETHTOOL_GRINGPARAM
:
960 case ETHTOOL_GPAUSEPARAM
:
961 case ETHTOOL_GRXCSUM
:
962 case ETHTOOL_GTXCSUM
:
964 case ETHTOOL_GSTRINGS
:
966 case ETHTOOL_GPERMADDR
:
970 case ETHTOOL_GPFLAGS
:
972 case ETHTOOL_GRXRINGS
:
973 case ETHTOOL_GRXCLSRLCNT
:
974 case ETHTOOL_GRXCLSRULE
:
975 case ETHTOOL_GRXCLSRLALL
:
978 if (!capable(CAP_NET_ADMIN
))
982 if (dev
->ethtool_ops
->begin
)
983 if ((rc
= dev
->ethtool_ops
->begin(dev
)) < 0)
986 old_features
= dev
->features
;
990 rc
= ethtool_get_settings(dev
, useraddr
);
993 rc
= ethtool_set_settings(dev
, useraddr
);
995 case ETHTOOL_GDRVINFO
:
996 rc
= ethtool_get_drvinfo(dev
, useraddr
);
999 rc
= ethtool_get_regs(dev
, useraddr
);
1002 rc
= ethtool_get_wol(dev
, useraddr
);
1005 rc
= ethtool_set_wol(dev
, useraddr
);
1007 case ETHTOOL_GMSGLVL
:
1008 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1009 dev
->ethtool_ops
->get_msglevel
);
1011 case ETHTOOL_SMSGLVL
:
1012 rc
= ethtool_set_value_void(dev
, useraddr
,
1013 dev
->ethtool_ops
->set_msglevel
);
1015 case ETHTOOL_NWAY_RST
:
1016 rc
= ethtool_nway_reset(dev
);
1019 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1020 dev
->ethtool_ops
->get_link
);
1022 case ETHTOOL_GEEPROM
:
1023 rc
= ethtool_get_eeprom(dev
, useraddr
);
1025 case ETHTOOL_SEEPROM
:
1026 rc
= ethtool_set_eeprom(dev
, useraddr
);
1028 case ETHTOOL_GCOALESCE
:
1029 rc
= ethtool_get_coalesce(dev
, useraddr
);
1031 case ETHTOOL_SCOALESCE
:
1032 rc
= ethtool_set_coalesce(dev
, useraddr
);
1034 case ETHTOOL_GRINGPARAM
:
1035 rc
= ethtool_get_ringparam(dev
, useraddr
);
1037 case ETHTOOL_SRINGPARAM
:
1038 rc
= ethtool_set_ringparam(dev
, useraddr
);
1040 case ETHTOOL_GPAUSEPARAM
:
1041 rc
= ethtool_get_pauseparam(dev
, useraddr
);
1043 case ETHTOOL_SPAUSEPARAM
:
1044 rc
= ethtool_set_pauseparam(dev
, useraddr
);
1046 case ETHTOOL_GRXCSUM
:
1047 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1048 (dev
->ethtool_ops
->get_rx_csum
?
1049 dev
->ethtool_ops
->get_rx_csum
:
1050 ethtool_op_get_rx_csum
));
1052 case ETHTOOL_SRXCSUM
:
1053 rc
= ethtool_set_rx_csum(dev
, useraddr
);
1055 case ETHTOOL_GTXCSUM
:
1056 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1057 (dev
->ethtool_ops
->get_tx_csum
?
1058 dev
->ethtool_ops
->get_tx_csum
:
1059 ethtool_op_get_tx_csum
));
1061 case ETHTOOL_STXCSUM
:
1062 rc
= ethtool_set_tx_csum(dev
, useraddr
);
1065 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1066 (dev
->ethtool_ops
->get_sg
?
1067 dev
->ethtool_ops
->get_sg
:
1068 ethtool_op_get_sg
));
1071 rc
= ethtool_set_sg(dev
, useraddr
);
1074 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1075 (dev
->ethtool_ops
->get_tso
?
1076 dev
->ethtool_ops
->get_tso
:
1077 ethtool_op_get_tso
));
1080 rc
= ethtool_set_tso(dev
, useraddr
);
1083 rc
= ethtool_self_test(dev
, useraddr
);
1085 case ETHTOOL_GSTRINGS
:
1086 rc
= ethtool_get_strings(dev
, useraddr
);
1088 case ETHTOOL_PHYS_ID
:
1089 rc
= ethtool_phys_id(dev
, useraddr
);
1091 case ETHTOOL_GSTATS
:
1092 rc
= ethtool_get_stats(dev
, useraddr
);
1094 case ETHTOOL_GPERMADDR
:
1095 rc
= ethtool_get_perm_addr(dev
, useraddr
);
1098 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1099 (dev
->ethtool_ops
->get_ufo
?
1100 dev
->ethtool_ops
->get_ufo
:
1101 ethtool_op_get_ufo
));
1104 rc
= ethtool_set_ufo(dev
, useraddr
);
1107 rc
= ethtool_get_gso(dev
, useraddr
);
1110 rc
= ethtool_set_gso(dev
, useraddr
);
1112 case ETHTOOL_GFLAGS
:
1113 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1114 (dev
->ethtool_ops
->get_flags
?
1115 dev
->ethtool_ops
->get_flags
:
1116 ethtool_op_get_flags
));
1118 case ETHTOOL_SFLAGS
:
1119 rc
= ethtool_set_value(dev
, useraddr
,
1120 dev
->ethtool_ops
->set_flags
);
1122 case ETHTOOL_GPFLAGS
:
1123 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1124 dev
->ethtool_ops
->get_priv_flags
);
1126 case ETHTOOL_SPFLAGS
:
1127 rc
= ethtool_set_value(dev
, useraddr
,
1128 dev
->ethtool_ops
->set_priv_flags
);
1131 case ETHTOOL_GRXRINGS
:
1132 case ETHTOOL_GRXCLSRLCNT
:
1133 case ETHTOOL_GRXCLSRULE
:
1134 case ETHTOOL_GRXCLSRLALL
:
1135 rc
= ethtool_get_rxnfc(dev
, ethcmd
, useraddr
);
1138 case ETHTOOL_SRXCLSRLDEL
:
1139 case ETHTOOL_SRXCLSRLINS
:
1140 rc
= ethtool_set_rxnfc(dev
, ethcmd
, useraddr
);
1143 rc
= ethtool_get_gro(dev
, useraddr
);
1146 rc
= ethtool_set_gro(dev
, useraddr
);
1148 case ETHTOOL_FLASHDEV
:
1149 rc
= ethtool_flash_device(dev
, useraddr
);
1155 if (dev
->ethtool_ops
->complete
)
1156 dev
->ethtool_ops
->complete(dev
);
1158 if (old_features
!= dev
->features
)
1159 netdev_features_change(dev
);
1164 EXPORT_SYMBOL(ethtool_op_get_link
);
1165 EXPORT_SYMBOL(ethtool_op_get_sg
);
1166 EXPORT_SYMBOL(ethtool_op_get_tso
);
1167 EXPORT_SYMBOL(ethtool_op_set_sg
);
1168 EXPORT_SYMBOL(ethtool_op_set_tso
);
1169 EXPORT_SYMBOL(ethtool_op_set_tx_csum
);
1170 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum
);
1171 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum
);
1172 EXPORT_SYMBOL(ethtool_op_set_ufo
);
1173 EXPORT_SYMBOL(ethtool_op_get_ufo
);
1174 EXPORT_SYMBOL(ethtool_op_set_flags
);
1175 EXPORT_SYMBOL(ethtool_op_get_flags
);