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/vmalloc.h>
23 #include <linux/slab.h>
26 * Some useful ethtool_ops methods that're device independent.
27 * If we find that all drivers want to do the same thing here,
28 * we can turn these into dev_() function calls.
31 u32
ethtool_op_get_link(struct net_device
*dev
)
33 return netif_carrier_ok(dev
) ? 1 : 0;
35 EXPORT_SYMBOL(ethtool_op_get_link
);
37 u32
ethtool_op_get_tx_csum(struct net_device
*dev
)
39 return (dev
->features
& NETIF_F_ALL_CSUM
) != 0;
41 EXPORT_SYMBOL(ethtool_op_get_tx_csum
);
43 int ethtool_op_set_tx_csum(struct net_device
*dev
, u32 data
)
46 dev
->features
|= NETIF_F_IP_CSUM
;
48 dev
->features
&= ~NETIF_F_IP_CSUM
;
52 EXPORT_SYMBOL(ethtool_op_set_tx_csum
);
54 int ethtool_op_set_tx_hw_csum(struct net_device
*dev
, u32 data
)
57 dev
->features
|= NETIF_F_HW_CSUM
;
59 dev
->features
&= ~NETIF_F_HW_CSUM
;
63 EXPORT_SYMBOL(ethtool_op_set_tx_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
);
74 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum
);
76 u32
ethtool_op_get_sg(struct net_device
*dev
)
78 return (dev
->features
& NETIF_F_SG
) != 0;
80 EXPORT_SYMBOL(ethtool_op_get_sg
);
82 int ethtool_op_set_sg(struct net_device
*dev
, u32 data
)
85 dev
->features
|= NETIF_F_SG
;
87 dev
->features
&= ~NETIF_F_SG
;
91 EXPORT_SYMBOL(ethtool_op_set_sg
);
93 u32
ethtool_op_get_tso(struct net_device
*dev
)
95 return (dev
->features
& NETIF_F_TSO
) != 0;
97 EXPORT_SYMBOL(ethtool_op_get_tso
);
99 int ethtool_op_set_tso(struct net_device
*dev
, u32 data
)
102 dev
->features
|= NETIF_F_TSO
;
104 dev
->features
&= ~NETIF_F_TSO
;
108 EXPORT_SYMBOL(ethtool_op_set_tso
);
110 u32
ethtool_op_get_ufo(struct net_device
*dev
)
112 return (dev
->features
& NETIF_F_UFO
) != 0;
114 EXPORT_SYMBOL(ethtool_op_get_ufo
);
116 int ethtool_op_set_ufo(struct net_device
*dev
, u32 data
)
119 dev
->features
|= NETIF_F_UFO
;
121 dev
->features
&= ~NETIF_F_UFO
;
124 EXPORT_SYMBOL(ethtool_op_set_ufo
);
126 /* the following list of flags are the same as their associated
127 * NETIF_F_xxx values in include/linux/netdevice.h
129 static const u32 flags_dup_features
=
130 (ETH_FLAG_LRO
| ETH_FLAG_RXVLAN
| ETH_FLAG_TXVLAN
| ETH_FLAG_NTUPLE
|
133 u32
ethtool_op_get_flags(struct net_device
*dev
)
135 /* in the future, this function will probably contain additional
136 * handling for flags which are not so easily handled
137 * by a simple masking operation
140 return dev
->features
& flags_dup_features
;
142 EXPORT_SYMBOL(ethtool_op_get_flags
);
144 int ethtool_op_set_flags(struct net_device
*dev
, u32 data
, u32 supported
)
146 if (data
& ~supported
)
149 dev
->features
= ((dev
->features
& ~flags_dup_features
) |
150 (data
& flags_dup_features
));
153 EXPORT_SYMBOL(ethtool_op_set_flags
);
155 void ethtool_ntuple_flush(struct net_device
*dev
)
157 struct ethtool_rx_ntuple_flow_spec_container
*fsc
, *f
;
159 list_for_each_entry_safe(fsc
, f
, &dev
->ethtool_ntuple_list
.list
, list
) {
160 list_del(&fsc
->list
);
163 dev
->ethtool_ntuple_list
.count
= 0;
165 EXPORT_SYMBOL(ethtool_ntuple_flush
);
167 /* Handlers for each ethtool command */
169 #define ETHTOOL_DEV_FEATURE_WORDS 1
171 static void ethtool_get_features_compat(struct net_device
*dev
,
172 struct ethtool_get_features_block
*features
)
174 if (!dev
->ethtool_ops
)
177 /* getting RX checksum */
178 if (dev
->ethtool_ops
->get_rx_csum
)
179 if (dev
->ethtool_ops
->get_rx_csum(dev
))
180 features
[0].active
|= NETIF_F_RXCSUM
;
182 /* mark legacy-changeable features */
183 if (dev
->ethtool_ops
->set_sg
)
184 features
[0].available
|= NETIF_F_SG
;
185 if (dev
->ethtool_ops
->set_tx_csum
)
186 features
[0].available
|= NETIF_F_ALL_CSUM
;
187 if (dev
->ethtool_ops
->set_tso
)
188 features
[0].available
|= NETIF_F_ALL_TSO
;
189 if (dev
->ethtool_ops
->set_rx_csum
)
190 features
[0].available
|= NETIF_F_RXCSUM
;
191 if (dev
->ethtool_ops
->set_flags
)
192 features
[0].available
|= flags_dup_features
;
195 static int ethtool_set_feature_compat(struct net_device
*dev
,
196 int (*legacy_set
)(struct net_device
*, u32
),
197 struct ethtool_set_features_block
*features
, u32 mask
)
204 if (!(features
[0].valid
& mask
))
207 features
[0].valid
&= ~mask
;
209 do_set
= !!(features
[0].requested
& mask
);
211 if (legacy_set(dev
, do_set
) < 0)
213 "Legacy feature change (%s) failed for 0x%08x\n",
214 do_set
? "set" : "clear", mask
);
219 static int ethtool_set_features_compat(struct net_device
*dev
,
220 struct ethtool_set_features_block
*features
)
224 if (!dev
->ethtool_ops
)
227 compat
= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_sg
,
228 features
, NETIF_F_SG
);
229 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_tx_csum
,
230 features
, NETIF_F_ALL_CSUM
);
231 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_tso
,
232 features
, NETIF_F_ALL_TSO
);
233 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_rx_csum
,
234 features
, NETIF_F_RXCSUM
);
235 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_flags
,
236 features
, flags_dup_features
);
241 static int ethtool_get_features(struct net_device
*dev
, void __user
*useraddr
)
243 struct ethtool_gfeatures cmd
= {
244 .cmd
= ETHTOOL_GFEATURES
,
245 .size
= ETHTOOL_DEV_FEATURE_WORDS
,
247 struct ethtool_get_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
] = {
249 .available
= dev
->hw_features
,
250 .requested
= dev
->wanted_features
,
251 .active
= dev
->features
,
252 .never_changed
= NETIF_F_NEVER_CHANGE
,
255 u32 __user
*sizeaddr
;
258 ethtool_get_features_compat(dev
, features
);
260 sizeaddr
= useraddr
+ offsetof(struct ethtool_gfeatures
, size
);
261 if (get_user(copy_size
, sizeaddr
))
264 if (copy_size
> ETHTOOL_DEV_FEATURE_WORDS
)
265 copy_size
= ETHTOOL_DEV_FEATURE_WORDS
;
267 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
269 useraddr
+= sizeof(cmd
);
270 if (copy_to_user(useraddr
, features
, copy_size
* sizeof(*features
)))
276 static int ethtool_set_features(struct net_device
*dev
, void __user
*useraddr
)
278 struct ethtool_sfeatures cmd
;
279 struct ethtool_set_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
];
282 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
284 useraddr
+= sizeof(cmd
);
286 if (cmd
.size
!= ETHTOOL_DEV_FEATURE_WORDS
)
289 if (copy_from_user(features
, useraddr
, sizeof(features
)))
292 if (features
[0].valid
& ~NETIF_F_ETHTOOL_BITS
)
295 if (ethtool_set_features_compat(dev
, features
))
296 ret
|= ETHTOOL_F_COMPAT
;
298 if (features
[0].valid
& ~dev
->hw_features
) {
299 features
[0].valid
&= dev
->hw_features
;
300 ret
|= ETHTOOL_F_UNSUPPORTED
;
303 dev
->wanted_features
&= ~features
[0].valid
;
304 dev
->wanted_features
|= features
[0].valid
& features
[0].requested
;
305 netdev_update_features(dev
);
307 if ((dev
->wanted_features
^ dev
->features
) & features
[0].valid
)
308 ret
|= ETHTOOL_F_WISH
;
313 static const char netdev_features_strings
[ETHTOOL_DEV_FEATURE_WORDS
* 32][ETH_GSTRING_LEN
] = {
314 /* NETIF_F_SG */ "tx-scatter-gather",
315 /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
316 /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
317 /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
318 /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6",
319 /* NETIF_F_HIGHDMA */ "highdma",
320 /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
321 /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
323 /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
324 /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
325 /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
326 /* NETIF_F_GSO */ "tx-generic-segmentation",
327 /* NETIF_F_LLTX */ "tx-lockless",
328 /* NETIF_F_NETNS_LOCAL */ "netns-local",
329 /* NETIF_F_GRO */ "rx-gro",
330 /* NETIF_F_LRO */ "rx-lro",
332 /* NETIF_F_TSO */ "tx-tcp-segmentation",
333 /* NETIF_F_UFO */ "tx-udp-fragmentation",
334 /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
335 /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
336 /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
337 /* NETIF_F_FSO */ "tx-fcoe-segmentation",
341 /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
342 /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
343 /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
344 /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
345 /* NETIF_F_RXHASH */ "rx-hashing",
346 /* NETIF_F_RXCSUM */ "rx-checksum",
351 static int __ethtool_get_sset_count(struct net_device
*dev
, int sset
)
353 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
355 if (sset
== ETH_SS_FEATURES
)
356 return ARRAY_SIZE(netdev_features_strings
);
358 if (ops
&& ops
->get_sset_count
&& ops
->get_strings
)
359 return ops
->get_sset_count(dev
, sset
);
364 static void __ethtool_get_strings(struct net_device
*dev
,
365 u32 stringset
, u8
*data
)
367 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
369 if (stringset
== ETH_SS_FEATURES
)
370 memcpy(data
, netdev_features_strings
,
371 sizeof(netdev_features_strings
));
373 /* ops->get_strings is valid because checked earlier */
374 ops
->get_strings(dev
, stringset
, data
);
377 static u32
ethtool_get_feature_mask(u32 eth_cmd
)
379 /* feature masks of legacy discrete ethtool ops */
382 case ETHTOOL_GTXCSUM
:
383 case ETHTOOL_STXCSUM
:
384 return NETIF_F_ALL_CSUM
| NETIF_F_SCTP_CSUM
;
385 case ETHTOOL_GRXCSUM
:
386 case ETHTOOL_SRXCSUM
:
387 return NETIF_F_RXCSUM
;
393 return NETIF_F_ALL_TSO
;
408 static void *__ethtool_get_one_feature_actor(struct net_device
*dev
, u32 ethcmd
)
410 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
416 case ETHTOOL_GTXCSUM
:
417 return ops
->get_tx_csum
;
418 case ETHTOOL_GRXCSUM
:
419 return ops
->get_rx_csum
;
431 static u32
__ethtool_get_rx_csum_oldbug(struct net_device
*dev
)
433 return !!(dev
->features
& NETIF_F_ALL_CSUM
);
436 static int ethtool_get_one_feature(struct net_device
*dev
,
437 char __user
*useraddr
, u32 ethcmd
)
439 u32 mask
= ethtool_get_feature_mask(ethcmd
);
440 struct ethtool_value edata
= {
442 .data
= !!(dev
->features
& mask
),
445 /* compatibility with discrete get_ ops */
446 if (!(dev
->hw_features
& mask
)) {
447 u32 (*actor
)(struct net_device
*);
449 actor
= __ethtool_get_one_feature_actor(dev
, ethcmd
);
451 /* bug compatibility with old get_rx_csum */
452 if (ethcmd
== ETHTOOL_GRXCSUM
&& !actor
)
453 actor
= __ethtool_get_rx_csum_oldbug
;
456 edata
.data
= actor(dev
);
459 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
464 static int __ethtool_set_tx_csum(struct net_device
*dev
, u32 data
);
465 static int __ethtool_set_rx_csum(struct net_device
*dev
, u32 data
);
466 static int __ethtool_set_sg(struct net_device
*dev
, u32 data
);
467 static int __ethtool_set_tso(struct net_device
*dev
, u32 data
);
468 static int __ethtool_set_ufo(struct net_device
*dev
, u32 data
);
470 static int ethtool_set_one_feature(struct net_device
*dev
,
471 void __user
*useraddr
, u32 ethcmd
)
473 struct ethtool_value edata
;
476 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
479 mask
= ethtool_get_feature_mask(ethcmd
);
480 mask
&= dev
->hw_features
;
483 dev
->wanted_features
|= mask
;
485 dev
->wanted_features
&= ~mask
;
487 netdev_update_features(dev
);
491 /* Driver is not converted to ndo_fix_features or does not
492 * support changing this offload. In the latter case it won't
493 * have corresponding ethtool_ops field set.
495 * Following part is to be removed after all drivers advertise
496 * their changeable features in netdev->hw_features and stop
497 * using discrete offload setting ops.
501 case ETHTOOL_STXCSUM
:
502 return __ethtool_set_tx_csum(dev
, edata
.data
);
503 case ETHTOOL_SRXCSUM
:
504 return __ethtool_set_rx_csum(dev
, edata
.data
);
506 return __ethtool_set_sg(dev
, edata
.data
);
508 return __ethtool_set_tso(dev
, edata
.data
);
510 return __ethtool_set_ufo(dev
, edata
.data
);
516 int __ethtool_set_flags(struct net_device
*dev
, u32 data
)
520 if (data
& ~flags_dup_features
)
523 /* legacy set_flags() op */
524 if (dev
->ethtool_ops
->set_flags
) {
525 if (unlikely(dev
->hw_features
& flags_dup_features
))
527 "driver BUG: mixed hw_features and set_flags()\n");
528 return dev
->ethtool_ops
->set_flags(dev
, data
);
531 /* allow changing only bits set in hw_features */
532 changed
= (data
^ dev
->wanted_features
) & flags_dup_features
;
533 if (changed
& ~dev
->hw_features
)
534 return (changed
& dev
->hw_features
) ? -EINVAL
: -EOPNOTSUPP
;
536 dev
->wanted_features
=
537 (dev
->wanted_features
& ~changed
) | data
;
539 netdev_update_features(dev
);
544 static int ethtool_get_settings(struct net_device
*dev
, void __user
*useraddr
)
546 struct ethtool_cmd cmd
= { .cmd
= ETHTOOL_GSET
};
549 if (!dev
->ethtool_ops
->get_settings
)
552 err
= dev
->ethtool_ops
->get_settings(dev
, &cmd
);
556 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
561 static int ethtool_set_settings(struct net_device
*dev
, void __user
*useraddr
)
563 struct ethtool_cmd cmd
;
565 if (!dev
->ethtool_ops
->set_settings
)
568 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
571 return dev
->ethtool_ops
->set_settings(dev
, &cmd
);
574 static noinline_for_stack
int ethtool_get_drvinfo(struct net_device
*dev
,
575 void __user
*useraddr
)
577 struct ethtool_drvinfo info
;
578 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
580 memset(&info
, 0, sizeof(info
));
581 info
.cmd
= ETHTOOL_GDRVINFO
;
582 if (ops
&& ops
->get_drvinfo
) {
583 ops
->get_drvinfo(dev
, &info
);
584 } else if (dev
->dev
.parent
&& dev
->dev
.parent
->driver
) {
585 strlcpy(info
.bus_info
, dev_name(dev
->dev
.parent
),
586 sizeof(info
.bus_info
));
587 strlcpy(info
.driver
, dev
->dev
.parent
->driver
->name
,
588 sizeof(info
.driver
));
594 * this method of obtaining string set info is deprecated;
595 * Use ETHTOOL_GSSET_INFO instead.
597 if (ops
&& ops
->get_sset_count
) {
600 rc
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
602 info
.testinfo_len
= rc
;
603 rc
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
606 rc
= ops
->get_sset_count(dev
, ETH_SS_PRIV_FLAGS
);
608 info
.n_priv_flags
= rc
;
610 if (ops
&& ops
->get_regs_len
)
611 info
.regdump_len
= ops
->get_regs_len(dev
);
612 if (ops
&& ops
->get_eeprom_len
)
613 info
.eedump_len
= ops
->get_eeprom_len(dev
);
615 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
620 static noinline_for_stack
int ethtool_get_sset_info(struct net_device
*dev
,
621 void __user
*useraddr
)
623 struct ethtool_sset_info info
;
625 int i
, idx
= 0, n_bits
= 0, ret
, rc
;
626 u32
*info_buf
= NULL
;
628 if (copy_from_user(&info
, useraddr
, sizeof(info
)))
631 /* store copy of mask, because we zero struct later on */
632 sset_mask
= info
.sset_mask
;
636 /* calculate size of return buffer */
637 n_bits
= hweight64(sset_mask
);
639 memset(&info
, 0, sizeof(info
));
640 info
.cmd
= ETHTOOL_GSSET_INFO
;
642 info_buf
= kzalloc(n_bits
* sizeof(u32
), GFP_USER
);
647 * fill return buffer based on input bitmask and successful
648 * get_sset_count return
650 for (i
= 0; i
< 64; i
++) {
651 if (!(sset_mask
& (1ULL << i
)))
654 rc
= __ethtool_get_sset_count(dev
, i
);
656 info
.sset_mask
|= (1ULL << i
);
657 info_buf
[idx
++] = rc
;
662 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
665 useraddr
+= offsetof(struct ethtool_sset_info
, data
);
666 if (copy_to_user(useraddr
, info_buf
, idx
* sizeof(u32
)))
676 static noinline_for_stack
int ethtool_set_rxnfc(struct net_device
*dev
,
677 u32 cmd
, void __user
*useraddr
)
679 struct ethtool_rxnfc info
;
680 size_t info_size
= sizeof(info
);
682 if (!dev
->ethtool_ops
->set_rxnfc
)
685 /* struct ethtool_rxnfc was originally defined for
686 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
687 * members. User-space might still be using that
689 if (cmd
== ETHTOOL_SRXFH
)
690 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
693 if (copy_from_user(&info
, useraddr
, info_size
))
696 return dev
->ethtool_ops
->set_rxnfc(dev
, &info
);
699 static noinline_for_stack
int ethtool_get_rxnfc(struct net_device
*dev
,
700 u32 cmd
, void __user
*useraddr
)
702 struct ethtool_rxnfc info
;
703 size_t info_size
= sizeof(info
);
704 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
706 void *rule_buf
= NULL
;
711 /* struct ethtool_rxnfc was originally defined for
712 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
713 * members. User-space might still be using that
715 if (cmd
== ETHTOOL_GRXFH
)
716 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
719 if (copy_from_user(&info
, useraddr
, info_size
))
722 if (info
.cmd
== ETHTOOL_GRXCLSRLALL
) {
723 if (info
.rule_cnt
> 0) {
724 if (info
.rule_cnt
<= KMALLOC_MAX_SIZE
/ sizeof(u32
))
725 rule_buf
= kzalloc(info
.rule_cnt
* sizeof(u32
),
732 ret
= ops
->get_rxnfc(dev
, &info
, rule_buf
);
737 if (copy_to_user(useraddr
, &info
, info_size
))
741 useraddr
+= offsetof(struct ethtool_rxnfc
, rule_locs
);
742 if (copy_to_user(useraddr
, rule_buf
,
743 info
.rule_cnt
* sizeof(u32
)))
754 static noinline_for_stack
int ethtool_get_rxfh_indir(struct net_device
*dev
,
755 void __user
*useraddr
)
757 struct ethtool_rxfh_indir
*indir
;
762 if (!dev
->ethtool_ops
->get_rxfh_indir
)
765 if (copy_from_user(&table_size
,
766 useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
771 (KMALLOC_MAX_SIZE
- sizeof(*indir
)) / sizeof(*indir
->ring_index
))
773 full_size
= sizeof(*indir
) + sizeof(*indir
->ring_index
) * table_size
;
774 indir
= kzalloc(full_size
, GFP_USER
);
778 indir
->cmd
= ETHTOOL_GRXFHINDIR
;
779 indir
->size
= table_size
;
780 ret
= dev
->ethtool_ops
->get_rxfh_indir(dev
, indir
);
784 if (copy_to_user(useraddr
, indir
, full_size
))
792 static noinline_for_stack
int ethtool_set_rxfh_indir(struct net_device
*dev
,
793 void __user
*useraddr
)
795 struct ethtool_rxfh_indir
*indir
;
800 if (!dev
->ethtool_ops
->set_rxfh_indir
)
803 if (copy_from_user(&table_size
,
804 useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
809 (KMALLOC_MAX_SIZE
- sizeof(*indir
)) / sizeof(*indir
->ring_index
))
811 full_size
= sizeof(*indir
) + sizeof(*indir
->ring_index
) * table_size
;
812 indir
= kmalloc(full_size
, GFP_USER
);
816 if (copy_from_user(indir
, useraddr
, full_size
)) {
821 ret
= dev
->ethtool_ops
->set_rxfh_indir(dev
, indir
);
828 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list
*list
,
829 struct ethtool_rx_ntuple_flow_spec
*spec
,
830 struct ethtool_rx_ntuple_flow_spec_container
*fsc
)
833 /* don't add filters forever */
834 if (list
->count
>= ETHTOOL_MAX_NTUPLE_LIST_ENTRY
) {
835 /* free the container */
840 /* Copy the whole filter over */
841 fsc
->fs
.flow_type
= spec
->flow_type
;
842 memcpy(&fsc
->fs
.h_u
, &spec
->h_u
, sizeof(spec
->h_u
));
843 memcpy(&fsc
->fs
.m_u
, &spec
->m_u
, sizeof(spec
->m_u
));
845 fsc
->fs
.vlan_tag
= spec
->vlan_tag
;
846 fsc
->fs
.vlan_tag_mask
= spec
->vlan_tag_mask
;
847 fsc
->fs
.data
= spec
->data
;
848 fsc
->fs
.data_mask
= spec
->data_mask
;
849 fsc
->fs
.action
= spec
->action
;
851 /* add to the list */
852 list_add_tail_rcu(&fsc
->list
, &list
->list
);
857 * ethtool does not (or did not) set masks for flow parameters that are
858 * not specified, so if both value and mask are 0 then this must be
859 * treated as equivalent to a mask with all bits set. Implement that
860 * here rather than in drivers.
862 static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec
*fs
)
864 struct ethtool_tcpip4_spec
*entry
= &fs
->h_u
.tcp_ip4_spec
;
865 struct ethtool_tcpip4_spec
*mask
= &fs
->m_u
.tcp_ip4_spec
;
867 if (fs
->flow_type
!= TCP_V4_FLOW
&&
868 fs
->flow_type
!= UDP_V4_FLOW
&&
869 fs
->flow_type
!= SCTP_V4_FLOW
)
872 if (!(entry
->ip4src
| mask
->ip4src
))
873 mask
->ip4src
= htonl(0xffffffff);
874 if (!(entry
->ip4dst
| mask
->ip4dst
))
875 mask
->ip4dst
= htonl(0xffffffff);
876 if (!(entry
->psrc
| mask
->psrc
))
877 mask
->psrc
= htons(0xffff);
878 if (!(entry
->pdst
| mask
->pdst
))
879 mask
->pdst
= htons(0xffff);
880 if (!(entry
->tos
| mask
->tos
))
882 if (!(fs
->vlan_tag
| fs
->vlan_tag_mask
))
883 fs
->vlan_tag_mask
= 0xffff;
884 if (!(fs
->data
| fs
->data_mask
))
885 fs
->data_mask
= 0xffffffffffffffffULL
;
888 static noinline_for_stack
int ethtool_set_rx_ntuple(struct net_device
*dev
,
889 void __user
*useraddr
)
891 struct ethtool_rx_ntuple cmd
;
892 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
893 struct ethtool_rx_ntuple_flow_spec_container
*fsc
= NULL
;
896 if (!(dev
->features
& NETIF_F_NTUPLE
))
899 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
902 rx_ntuple_fix_masks(&cmd
.fs
);
905 * Cache filter in dev struct for GET operation only if
906 * the underlying driver doesn't have its own GET operation, and
907 * only if the filter was added successfully. First make sure we
908 * can allocate the filter, then continue if successful.
910 if (!ops
->get_rx_ntuple
) {
911 fsc
= kmalloc(sizeof(*fsc
), GFP_ATOMIC
);
916 ret
= ops
->set_rx_ntuple(dev
, &cmd
);
922 if (!ops
->get_rx_ntuple
)
923 __rx_ntuple_filter_add(&dev
->ethtool_ntuple_list
, &cmd
.fs
, fsc
);
928 static int ethtool_get_rx_ntuple(struct net_device
*dev
, void __user
*useraddr
)
930 struct ethtool_gstrings gstrings
;
931 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
932 struct ethtool_rx_ntuple_flow_spec_container
*fsc
;
935 int ret
, i
, num_strings
= 0;
937 if (!ops
->get_sset_count
)
940 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
943 ret
= ops
->get_sset_count(dev
, gstrings
.string_set
);
949 data
= kzalloc(gstrings
.len
* ETH_GSTRING_LEN
, GFP_USER
);
953 if (ops
->get_rx_ntuple
) {
954 /* driver-specific filter grab */
955 ret
= ops
->get_rx_ntuple(dev
, gstrings
.string_set
, data
);
959 /* default ethtool filter grab */
962 list_for_each_entry(fsc
, &dev
->ethtool_ntuple_list
.list
, list
) {
963 sprintf(p
, "Filter %d:\n", i
);
964 p
+= ETH_GSTRING_LEN
;
967 switch (fsc
->fs
.flow_type
) {
969 sprintf(p
, "\tFlow Type: TCP\n");
970 p
+= ETH_GSTRING_LEN
;
974 sprintf(p
, "\tFlow Type: UDP\n");
975 p
+= ETH_GSTRING_LEN
;
979 sprintf(p
, "\tFlow Type: SCTP\n");
980 p
+= ETH_GSTRING_LEN
;
984 sprintf(p
, "\tFlow Type: AH ESP\n");
985 p
+= ETH_GSTRING_LEN
;
989 sprintf(p
, "\tFlow Type: ESP\n");
990 p
+= ETH_GSTRING_LEN
;
994 sprintf(p
, "\tFlow Type: Raw IP\n");
995 p
+= ETH_GSTRING_LEN
;
999 sprintf(p
, "\tFlow Type: IPv4\n");
1000 p
+= ETH_GSTRING_LEN
;
1004 sprintf(p
, "\tFlow Type: Unknown\n");
1005 p
+= ETH_GSTRING_LEN
;
1007 goto unknown_filter
;
1010 /* now the rest of the filters */
1011 switch (fsc
->fs
.flow_type
) {
1015 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1016 fsc
->fs
.h_u
.tcp_ip4_spec
.ip4src
);
1017 p
+= ETH_GSTRING_LEN
;
1019 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1020 fsc
->fs
.m_u
.tcp_ip4_spec
.ip4src
);
1021 p
+= ETH_GSTRING_LEN
;
1023 sprintf(p
, "\tDest IP addr: 0x%x\n",
1024 fsc
->fs
.h_u
.tcp_ip4_spec
.ip4dst
);
1025 p
+= ETH_GSTRING_LEN
;
1027 sprintf(p
, "\tDest IP mask: 0x%x\n",
1028 fsc
->fs
.m_u
.tcp_ip4_spec
.ip4dst
);
1029 p
+= ETH_GSTRING_LEN
;
1031 sprintf(p
, "\tSrc Port: %d, mask: 0x%x\n",
1032 fsc
->fs
.h_u
.tcp_ip4_spec
.psrc
,
1033 fsc
->fs
.m_u
.tcp_ip4_spec
.psrc
);
1034 p
+= ETH_GSTRING_LEN
;
1036 sprintf(p
, "\tDest Port: %d, mask: 0x%x\n",
1037 fsc
->fs
.h_u
.tcp_ip4_spec
.pdst
,
1038 fsc
->fs
.m_u
.tcp_ip4_spec
.pdst
);
1039 p
+= ETH_GSTRING_LEN
;
1041 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1042 fsc
->fs
.h_u
.tcp_ip4_spec
.tos
,
1043 fsc
->fs
.m_u
.tcp_ip4_spec
.tos
);
1044 p
+= ETH_GSTRING_LEN
;
1047 case AH_ESP_V4_FLOW
:
1049 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1050 fsc
->fs
.h_u
.ah_ip4_spec
.ip4src
);
1051 p
+= ETH_GSTRING_LEN
;
1053 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1054 fsc
->fs
.m_u
.ah_ip4_spec
.ip4src
);
1055 p
+= ETH_GSTRING_LEN
;
1057 sprintf(p
, "\tDest IP addr: 0x%x\n",
1058 fsc
->fs
.h_u
.ah_ip4_spec
.ip4dst
);
1059 p
+= ETH_GSTRING_LEN
;
1061 sprintf(p
, "\tDest IP mask: 0x%x\n",
1062 fsc
->fs
.m_u
.ah_ip4_spec
.ip4dst
);
1063 p
+= ETH_GSTRING_LEN
;
1065 sprintf(p
, "\tSPI: %d, mask: 0x%x\n",
1066 fsc
->fs
.h_u
.ah_ip4_spec
.spi
,
1067 fsc
->fs
.m_u
.ah_ip4_spec
.spi
);
1068 p
+= ETH_GSTRING_LEN
;
1070 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1071 fsc
->fs
.h_u
.ah_ip4_spec
.tos
,
1072 fsc
->fs
.m_u
.ah_ip4_spec
.tos
);
1073 p
+= ETH_GSTRING_LEN
;
1077 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1078 fsc
->fs
.h_u
.usr_ip4_spec
.ip4src
);
1079 p
+= ETH_GSTRING_LEN
;
1081 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1082 fsc
->fs
.m_u
.usr_ip4_spec
.ip4src
);
1083 p
+= ETH_GSTRING_LEN
;
1085 sprintf(p
, "\tDest IP addr: 0x%x\n",
1086 fsc
->fs
.h_u
.usr_ip4_spec
.ip4dst
);
1087 p
+= ETH_GSTRING_LEN
;
1089 sprintf(p
, "\tDest IP mask: 0x%x\n",
1090 fsc
->fs
.m_u
.usr_ip4_spec
.ip4dst
);
1091 p
+= ETH_GSTRING_LEN
;
1095 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1096 fsc
->fs
.h_u
.usr_ip4_spec
.ip4src
);
1097 p
+= ETH_GSTRING_LEN
;
1099 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1100 fsc
->fs
.m_u
.usr_ip4_spec
.ip4src
);
1101 p
+= ETH_GSTRING_LEN
;
1103 sprintf(p
, "\tDest IP addr: 0x%x\n",
1104 fsc
->fs
.h_u
.usr_ip4_spec
.ip4dst
);
1105 p
+= ETH_GSTRING_LEN
;
1107 sprintf(p
, "\tDest IP mask: 0x%x\n",
1108 fsc
->fs
.m_u
.usr_ip4_spec
.ip4dst
);
1109 p
+= ETH_GSTRING_LEN
;
1111 sprintf(p
, "\tL4 bytes: 0x%x, mask: 0x%x\n",
1112 fsc
->fs
.h_u
.usr_ip4_spec
.l4_4_bytes
,
1113 fsc
->fs
.m_u
.usr_ip4_spec
.l4_4_bytes
);
1114 p
+= ETH_GSTRING_LEN
;
1116 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1117 fsc
->fs
.h_u
.usr_ip4_spec
.tos
,
1118 fsc
->fs
.m_u
.usr_ip4_spec
.tos
);
1119 p
+= ETH_GSTRING_LEN
;
1121 sprintf(p
, "\tIP Version: %d, mask: 0x%x\n",
1122 fsc
->fs
.h_u
.usr_ip4_spec
.ip_ver
,
1123 fsc
->fs
.m_u
.usr_ip4_spec
.ip_ver
);
1124 p
+= ETH_GSTRING_LEN
;
1126 sprintf(p
, "\tProtocol: %d, mask: 0x%x\n",
1127 fsc
->fs
.h_u
.usr_ip4_spec
.proto
,
1128 fsc
->fs
.m_u
.usr_ip4_spec
.proto
);
1129 p
+= ETH_GSTRING_LEN
;
1133 sprintf(p
, "\tVLAN: %d, mask: 0x%x\n",
1134 fsc
->fs
.vlan_tag
, fsc
->fs
.vlan_tag_mask
);
1135 p
+= ETH_GSTRING_LEN
;
1137 sprintf(p
, "\tUser-defined: 0x%Lx\n", fsc
->fs
.data
);
1138 p
+= ETH_GSTRING_LEN
;
1140 sprintf(p
, "\tUser-defined mask: 0x%Lx\n", fsc
->fs
.data_mask
);
1141 p
+= ETH_GSTRING_LEN
;
1143 if (fsc
->fs
.action
== ETHTOOL_RXNTUPLE_ACTION_DROP
)
1144 sprintf(p
, "\tAction: Drop\n");
1146 sprintf(p
, "\tAction: Direct to queue %d\n",
1148 p
+= ETH_GSTRING_LEN
;
1154 /* indicate to userspace how many strings we actually have */
1155 gstrings
.len
= num_strings
;
1157 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
1159 useraddr
+= sizeof(gstrings
);
1160 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
1169 static int ethtool_get_regs(struct net_device
*dev
, char __user
*useraddr
)
1171 struct ethtool_regs regs
;
1172 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1176 if (!ops
->get_regs
|| !ops
->get_regs_len
)
1179 if (copy_from_user(®s
, useraddr
, sizeof(regs
)))
1182 reglen
= ops
->get_regs_len(dev
);
1183 if (regs
.len
> reglen
)
1186 regbuf
= vzalloc(reglen
);
1190 ops
->get_regs(dev
, ®s
, regbuf
);
1193 if (copy_to_user(useraddr
, ®s
, sizeof(regs
)))
1195 useraddr
+= offsetof(struct ethtool_regs
, data
);
1196 if (copy_to_user(useraddr
, regbuf
, regs
.len
))
1205 static int ethtool_reset(struct net_device
*dev
, char __user
*useraddr
)
1207 struct ethtool_value reset
;
1210 if (!dev
->ethtool_ops
->reset
)
1213 if (copy_from_user(&reset
, useraddr
, sizeof(reset
)))
1216 ret
= dev
->ethtool_ops
->reset(dev
, &reset
.data
);
1220 if (copy_to_user(useraddr
, &reset
, sizeof(reset
)))
1225 static int ethtool_get_wol(struct net_device
*dev
, char __user
*useraddr
)
1227 struct ethtool_wolinfo wol
= { .cmd
= ETHTOOL_GWOL
};
1229 if (!dev
->ethtool_ops
->get_wol
)
1232 dev
->ethtool_ops
->get_wol(dev
, &wol
);
1234 if (copy_to_user(useraddr
, &wol
, sizeof(wol
)))
1239 static int ethtool_set_wol(struct net_device
*dev
, char __user
*useraddr
)
1241 struct ethtool_wolinfo wol
;
1243 if (!dev
->ethtool_ops
->set_wol
)
1246 if (copy_from_user(&wol
, useraddr
, sizeof(wol
)))
1249 return dev
->ethtool_ops
->set_wol(dev
, &wol
);
1252 static int ethtool_nway_reset(struct net_device
*dev
)
1254 if (!dev
->ethtool_ops
->nway_reset
)
1257 return dev
->ethtool_ops
->nway_reset(dev
);
1260 static int ethtool_get_link(struct net_device
*dev
, char __user
*useraddr
)
1262 struct ethtool_value edata
= { .cmd
= ETHTOOL_GLINK
};
1264 if (!dev
->ethtool_ops
->get_link
)
1267 edata
.data
= netif_running(dev
) && dev
->ethtool_ops
->get_link(dev
);
1269 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1274 static int ethtool_get_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1276 struct ethtool_eeprom eeprom
;
1277 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1278 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1279 u32 bytes_remaining
;
1283 if (!ops
->get_eeprom
|| !ops
->get_eeprom_len
)
1286 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1289 /* Check for wrap and zero */
1290 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1293 /* Check for exceeding total eeprom len */
1294 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
1297 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1301 bytes_remaining
= eeprom
.len
;
1302 while (bytes_remaining
> 0) {
1303 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1305 ret
= ops
->get_eeprom(dev
, &eeprom
, data
);
1308 if (copy_to_user(userbuf
, data
, eeprom
.len
)) {
1312 userbuf
+= eeprom
.len
;
1313 eeprom
.offset
+= eeprom
.len
;
1314 bytes_remaining
-= eeprom
.len
;
1317 eeprom
.len
= userbuf
- (useraddr
+ sizeof(eeprom
));
1318 eeprom
.offset
-= eeprom
.len
;
1319 if (copy_to_user(useraddr
, &eeprom
, sizeof(eeprom
)))
1326 static int ethtool_set_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1328 struct ethtool_eeprom eeprom
;
1329 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1330 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1331 u32 bytes_remaining
;
1335 if (!ops
->set_eeprom
|| !ops
->get_eeprom_len
)
1338 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1341 /* Check for wrap and zero */
1342 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1345 /* Check for exceeding total eeprom len */
1346 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
1349 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1353 bytes_remaining
= eeprom
.len
;
1354 while (bytes_remaining
> 0) {
1355 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1357 if (copy_from_user(data
, userbuf
, eeprom
.len
)) {
1361 ret
= ops
->set_eeprom(dev
, &eeprom
, data
);
1364 userbuf
+= eeprom
.len
;
1365 eeprom
.offset
+= eeprom
.len
;
1366 bytes_remaining
-= eeprom
.len
;
1373 static noinline_for_stack
int ethtool_get_coalesce(struct net_device
*dev
,
1374 void __user
*useraddr
)
1376 struct ethtool_coalesce coalesce
= { .cmd
= ETHTOOL_GCOALESCE
};
1378 if (!dev
->ethtool_ops
->get_coalesce
)
1381 dev
->ethtool_ops
->get_coalesce(dev
, &coalesce
);
1383 if (copy_to_user(useraddr
, &coalesce
, sizeof(coalesce
)))
1388 static noinline_for_stack
int ethtool_set_coalesce(struct net_device
*dev
,
1389 void __user
*useraddr
)
1391 struct ethtool_coalesce coalesce
;
1393 if (!dev
->ethtool_ops
->set_coalesce
)
1396 if (copy_from_user(&coalesce
, useraddr
, sizeof(coalesce
)))
1399 return dev
->ethtool_ops
->set_coalesce(dev
, &coalesce
);
1402 static int ethtool_get_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1404 struct ethtool_ringparam ringparam
= { .cmd
= ETHTOOL_GRINGPARAM
};
1406 if (!dev
->ethtool_ops
->get_ringparam
)
1409 dev
->ethtool_ops
->get_ringparam(dev
, &ringparam
);
1411 if (copy_to_user(useraddr
, &ringparam
, sizeof(ringparam
)))
1416 static int ethtool_set_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1418 struct ethtool_ringparam ringparam
;
1420 if (!dev
->ethtool_ops
->set_ringparam
)
1423 if (copy_from_user(&ringparam
, useraddr
, sizeof(ringparam
)))
1426 return dev
->ethtool_ops
->set_ringparam(dev
, &ringparam
);
1429 static int ethtool_get_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1431 struct ethtool_pauseparam pauseparam
= { ETHTOOL_GPAUSEPARAM
};
1433 if (!dev
->ethtool_ops
->get_pauseparam
)
1436 dev
->ethtool_ops
->get_pauseparam(dev
, &pauseparam
);
1438 if (copy_to_user(useraddr
, &pauseparam
, sizeof(pauseparam
)))
1443 static int ethtool_set_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1445 struct ethtool_pauseparam pauseparam
;
1447 if (!dev
->ethtool_ops
->set_pauseparam
)
1450 if (copy_from_user(&pauseparam
, useraddr
, sizeof(pauseparam
)))
1453 return dev
->ethtool_ops
->set_pauseparam(dev
, &pauseparam
);
1456 static int __ethtool_set_sg(struct net_device
*dev
, u32 data
)
1460 if (!dev
->ethtool_ops
->set_sg
)
1463 if (data
&& !(dev
->features
& NETIF_F_ALL_CSUM
))
1466 if (!data
&& dev
->ethtool_ops
->set_tso
) {
1467 err
= dev
->ethtool_ops
->set_tso(dev
, 0);
1472 if (!data
&& dev
->ethtool_ops
->set_ufo
) {
1473 err
= dev
->ethtool_ops
->set_ufo(dev
, 0);
1477 return dev
->ethtool_ops
->set_sg(dev
, data
);
1480 static int __ethtool_set_tx_csum(struct net_device
*dev
, u32 data
)
1484 if (!dev
->ethtool_ops
->set_tx_csum
)
1487 if (!data
&& dev
->ethtool_ops
->set_sg
) {
1488 err
= __ethtool_set_sg(dev
, 0);
1493 return dev
->ethtool_ops
->set_tx_csum(dev
, data
);
1496 static int __ethtool_set_rx_csum(struct net_device
*dev
, u32 data
)
1498 if (!dev
->ethtool_ops
->set_rx_csum
)
1502 dev
->features
&= ~NETIF_F_GRO
;
1504 return dev
->ethtool_ops
->set_rx_csum(dev
, data
);
1507 static int __ethtool_set_tso(struct net_device
*dev
, u32 data
)
1509 if (!dev
->ethtool_ops
->set_tso
)
1512 if (data
&& !(dev
->features
& NETIF_F_SG
))
1515 return dev
->ethtool_ops
->set_tso(dev
, data
);
1518 static int __ethtool_set_ufo(struct net_device
*dev
, u32 data
)
1520 if (!dev
->ethtool_ops
->set_ufo
)
1522 if (data
&& !(dev
->features
& NETIF_F_SG
))
1524 if (data
&& !((dev
->features
& NETIF_F_GEN_CSUM
) ||
1525 (dev
->features
& (NETIF_F_IP_CSUM
|NETIF_F_IPV6_CSUM
))
1526 == (NETIF_F_IP_CSUM
|NETIF_F_IPV6_CSUM
)))
1528 return dev
->ethtool_ops
->set_ufo(dev
, data
);
1531 static int ethtool_self_test(struct net_device
*dev
, char __user
*useraddr
)
1533 struct ethtool_test test
;
1534 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1538 if (!ops
->self_test
|| !ops
->get_sset_count
)
1541 test_len
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
1544 WARN_ON(test_len
== 0);
1546 if (copy_from_user(&test
, useraddr
, sizeof(test
)))
1549 test
.len
= test_len
;
1550 data
= kmalloc(test_len
* sizeof(u64
), GFP_USER
);
1554 ops
->self_test(dev
, &test
, data
);
1557 if (copy_to_user(useraddr
, &test
, sizeof(test
)))
1559 useraddr
+= sizeof(test
);
1560 if (copy_to_user(useraddr
, data
, test
.len
* sizeof(u64
)))
1569 static int ethtool_get_strings(struct net_device
*dev
, void __user
*useraddr
)
1571 struct ethtool_gstrings gstrings
;
1575 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
1578 ret
= __ethtool_get_sset_count(dev
, gstrings
.string_set
);
1584 data
= kmalloc(gstrings
.len
* ETH_GSTRING_LEN
, GFP_USER
);
1588 __ethtool_get_strings(dev
, gstrings
.string_set
, data
);
1591 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
1593 useraddr
+= sizeof(gstrings
);
1594 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
1603 static int ethtool_phys_id(struct net_device
*dev
, void __user
*useraddr
)
1605 struct ethtool_value id
;
1607 if (!dev
->ethtool_ops
->phys_id
)
1610 if (copy_from_user(&id
, useraddr
, sizeof(id
)))
1613 return dev
->ethtool_ops
->phys_id(dev
, id
.data
);
1616 static int ethtool_get_stats(struct net_device
*dev
, void __user
*useraddr
)
1618 struct ethtool_stats stats
;
1619 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1623 if (!ops
->get_ethtool_stats
|| !ops
->get_sset_count
)
1626 n_stats
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
1629 WARN_ON(n_stats
== 0);
1631 if (copy_from_user(&stats
, useraddr
, sizeof(stats
)))
1634 stats
.n_stats
= n_stats
;
1635 data
= kmalloc(n_stats
* sizeof(u64
), GFP_USER
);
1639 ops
->get_ethtool_stats(dev
, &stats
, data
);
1642 if (copy_to_user(useraddr
, &stats
, sizeof(stats
)))
1644 useraddr
+= sizeof(stats
);
1645 if (copy_to_user(useraddr
, data
, stats
.n_stats
* sizeof(u64
)))
1654 static int ethtool_get_perm_addr(struct net_device
*dev
, void __user
*useraddr
)
1656 struct ethtool_perm_addr epaddr
;
1658 if (copy_from_user(&epaddr
, useraddr
, sizeof(epaddr
)))
1661 if (epaddr
.size
< dev
->addr_len
)
1663 epaddr
.size
= dev
->addr_len
;
1665 if (copy_to_user(useraddr
, &epaddr
, sizeof(epaddr
)))
1667 useraddr
+= sizeof(epaddr
);
1668 if (copy_to_user(useraddr
, dev
->perm_addr
, epaddr
.size
))
1673 static int ethtool_get_value(struct net_device
*dev
, char __user
*useraddr
,
1674 u32 cmd
, u32 (*actor
)(struct net_device
*))
1676 struct ethtool_value edata
= { .cmd
= cmd
};
1681 edata
.data
= actor(dev
);
1683 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1688 static int ethtool_set_value_void(struct net_device
*dev
, char __user
*useraddr
,
1689 void (*actor
)(struct net_device
*, u32
))
1691 struct ethtool_value edata
;
1696 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1699 actor(dev
, edata
.data
);
1703 static int ethtool_set_value(struct net_device
*dev
, char __user
*useraddr
,
1704 int (*actor
)(struct net_device
*, u32
))
1706 struct ethtool_value edata
;
1711 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1714 return actor(dev
, edata
.data
);
1717 static noinline_for_stack
int ethtool_flash_device(struct net_device
*dev
,
1718 char __user
*useraddr
)
1720 struct ethtool_flash efl
;
1722 if (copy_from_user(&efl
, useraddr
, sizeof(efl
)))
1725 if (!dev
->ethtool_ops
->flash_device
)
1728 return dev
->ethtool_ops
->flash_device(dev
, &efl
);
1731 /* The main entry point in this file. Called from net/core/dev.c */
1733 int dev_ethtool(struct net
*net
, struct ifreq
*ifr
)
1735 struct net_device
*dev
= __dev_get_by_name(net
, ifr
->ifr_name
);
1736 void __user
*useraddr
= ifr
->ifr_data
;
1741 if (!dev
|| !netif_device_present(dev
))
1744 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
1747 if (!dev
->ethtool_ops
) {
1748 /* ETHTOOL_GDRVINFO does not require any driver support.
1749 * It is also unprivileged and does not change anything,
1750 * so we can take a shortcut to it. */
1751 if (ethcmd
== ETHTOOL_GDRVINFO
)
1752 return ethtool_get_drvinfo(dev
, useraddr
);
1757 /* Allow some commands to be done by anyone */
1760 case ETHTOOL_GDRVINFO
:
1761 case ETHTOOL_GMSGLVL
:
1762 case ETHTOOL_GCOALESCE
:
1763 case ETHTOOL_GRINGPARAM
:
1764 case ETHTOOL_GPAUSEPARAM
:
1765 case ETHTOOL_GRXCSUM
:
1766 case ETHTOOL_GTXCSUM
:
1768 case ETHTOOL_GSTRINGS
:
1770 case ETHTOOL_GPERMADDR
:
1774 case ETHTOOL_GFLAGS
:
1775 case ETHTOOL_GPFLAGS
:
1777 case ETHTOOL_GRXRINGS
:
1778 case ETHTOOL_GRXCLSRLCNT
:
1779 case ETHTOOL_GRXCLSRULE
:
1780 case ETHTOOL_GRXCLSRLALL
:
1781 case ETHTOOL_GFEATURES
:
1784 if (!capable(CAP_NET_ADMIN
))
1788 if (dev
->ethtool_ops
->begin
) {
1789 rc
= dev
->ethtool_ops
->begin(dev
);
1793 old_features
= dev
->features
;
1797 rc
= ethtool_get_settings(dev
, useraddr
);
1800 rc
= ethtool_set_settings(dev
, useraddr
);
1802 case ETHTOOL_GDRVINFO
:
1803 rc
= ethtool_get_drvinfo(dev
, useraddr
);
1806 rc
= ethtool_get_regs(dev
, useraddr
);
1809 rc
= ethtool_get_wol(dev
, useraddr
);
1812 rc
= ethtool_set_wol(dev
, useraddr
);
1814 case ETHTOOL_GMSGLVL
:
1815 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1816 dev
->ethtool_ops
->get_msglevel
);
1818 case ETHTOOL_SMSGLVL
:
1819 rc
= ethtool_set_value_void(dev
, useraddr
,
1820 dev
->ethtool_ops
->set_msglevel
);
1822 case ETHTOOL_NWAY_RST
:
1823 rc
= ethtool_nway_reset(dev
);
1826 rc
= ethtool_get_link(dev
, useraddr
);
1828 case ETHTOOL_GEEPROM
:
1829 rc
= ethtool_get_eeprom(dev
, useraddr
);
1831 case ETHTOOL_SEEPROM
:
1832 rc
= ethtool_set_eeprom(dev
, useraddr
);
1834 case ETHTOOL_GCOALESCE
:
1835 rc
= ethtool_get_coalesce(dev
, useraddr
);
1837 case ETHTOOL_SCOALESCE
:
1838 rc
= ethtool_set_coalesce(dev
, useraddr
);
1840 case ETHTOOL_GRINGPARAM
:
1841 rc
= ethtool_get_ringparam(dev
, useraddr
);
1843 case ETHTOOL_SRINGPARAM
:
1844 rc
= ethtool_set_ringparam(dev
, useraddr
);
1846 case ETHTOOL_GPAUSEPARAM
:
1847 rc
= ethtool_get_pauseparam(dev
, useraddr
);
1849 case ETHTOOL_SPAUSEPARAM
:
1850 rc
= ethtool_set_pauseparam(dev
, useraddr
);
1853 rc
= ethtool_self_test(dev
, useraddr
);
1855 case ETHTOOL_GSTRINGS
:
1856 rc
= ethtool_get_strings(dev
, useraddr
);
1858 case ETHTOOL_PHYS_ID
:
1859 rc
= ethtool_phys_id(dev
, useraddr
);
1861 case ETHTOOL_GSTATS
:
1862 rc
= ethtool_get_stats(dev
, useraddr
);
1864 case ETHTOOL_GPERMADDR
:
1865 rc
= ethtool_get_perm_addr(dev
, useraddr
);
1867 case ETHTOOL_GFLAGS
:
1868 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1869 (dev
->ethtool_ops
->get_flags
?
1870 dev
->ethtool_ops
->get_flags
:
1871 ethtool_op_get_flags
));
1873 case ETHTOOL_SFLAGS
:
1874 rc
= ethtool_set_value(dev
, useraddr
, __ethtool_set_flags
);
1876 case ETHTOOL_GPFLAGS
:
1877 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1878 dev
->ethtool_ops
->get_priv_flags
);
1880 case ETHTOOL_SPFLAGS
:
1881 rc
= ethtool_set_value(dev
, useraddr
,
1882 dev
->ethtool_ops
->set_priv_flags
);
1885 case ETHTOOL_GRXRINGS
:
1886 case ETHTOOL_GRXCLSRLCNT
:
1887 case ETHTOOL_GRXCLSRULE
:
1888 case ETHTOOL_GRXCLSRLALL
:
1889 rc
= ethtool_get_rxnfc(dev
, ethcmd
, useraddr
);
1892 case ETHTOOL_SRXCLSRLDEL
:
1893 case ETHTOOL_SRXCLSRLINS
:
1894 rc
= ethtool_set_rxnfc(dev
, ethcmd
, useraddr
);
1896 case ETHTOOL_FLASHDEV
:
1897 rc
= ethtool_flash_device(dev
, useraddr
);
1900 rc
= ethtool_reset(dev
, useraddr
);
1902 case ETHTOOL_SRXNTUPLE
:
1903 rc
= ethtool_set_rx_ntuple(dev
, useraddr
);
1905 case ETHTOOL_GRXNTUPLE
:
1906 rc
= ethtool_get_rx_ntuple(dev
, useraddr
);
1908 case ETHTOOL_GSSET_INFO
:
1909 rc
= ethtool_get_sset_info(dev
, useraddr
);
1911 case ETHTOOL_GRXFHINDIR
:
1912 rc
= ethtool_get_rxfh_indir(dev
, useraddr
);
1914 case ETHTOOL_SRXFHINDIR
:
1915 rc
= ethtool_set_rxfh_indir(dev
, useraddr
);
1917 case ETHTOOL_GFEATURES
:
1918 rc
= ethtool_get_features(dev
, useraddr
);
1920 case ETHTOOL_SFEATURES
:
1921 rc
= ethtool_set_features(dev
, useraddr
);
1923 case ETHTOOL_GTXCSUM
:
1924 case ETHTOOL_GRXCSUM
:
1930 rc
= ethtool_get_one_feature(dev
, useraddr
, ethcmd
);
1932 case ETHTOOL_STXCSUM
:
1933 case ETHTOOL_SRXCSUM
:
1939 rc
= ethtool_set_one_feature(dev
, useraddr
, ethcmd
);
1945 if (dev
->ethtool_ops
->complete
)
1946 dev
->ethtool_ops
->complete(dev
);
1948 if (old_features
!= dev
->features
)
1949 netdev_features_change(dev
);