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 /* Check if device can enable (or disable) particular feature coded in "data"
145 * argument. Flags "supported" describe features that can be toggled by device.
146 * If feature can not be toggled, it state (enabled or disabled) must match
147 * hardcoded device features state, otherwise flags are marked as invalid.
149 bool ethtool_invalid_flags(struct net_device
*dev
, u32 data
, u32 supported
)
151 u32 features
= dev
->features
& flags_dup_features
;
152 /* "data" can contain only flags_dup_features bits,
153 * see __ethtool_set_flags */
155 return (features
& ~supported
) != (data
& ~supported
);
157 EXPORT_SYMBOL(ethtool_invalid_flags
);
159 int ethtool_op_set_flags(struct net_device
*dev
, u32 data
, u32 supported
)
161 if (ethtool_invalid_flags(dev
, data
, supported
))
164 dev
->features
= ((dev
->features
& ~flags_dup_features
) |
165 (data
& flags_dup_features
));
168 EXPORT_SYMBOL(ethtool_op_set_flags
);
170 void ethtool_ntuple_flush(struct net_device
*dev
)
172 struct ethtool_rx_ntuple_flow_spec_container
*fsc
, *f
;
174 list_for_each_entry_safe(fsc
, f
, &dev
->ethtool_ntuple_list
.list
, list
) {
175 list_del(&fsc
->list
);
178 dev
->ethtool_ntuple_list
.count
= 0;
180 EXPORT_SYMBOL(ethtool_ntuple_flush
);
182 /* Handlers for each ethtool command */
184 #define ETHTOOL_DEV_FEATURE_WORDS 1
186 static void ethtool_get_features_compat(struct net_device
*dev
,
187 struct ethtool_get_features_block
*features
)
189 if (!dev
->ethtool_ops
)
192 /* getting RX checksum */
193 if (dev
->ethtool_ops
->get_rx_csum
)
194 if (dev
->ethtool_ops
->get_rx_csum(dev
))
195 features
[0].active
|= NETIF_F_RXCSUM
;
197 /* mark legacy-changeable features */
198 if (dev
->ethtool_ops
->set_sg
)
199 features
[0].available
|= NETIF_F_SG
;
200 if (dev
->ethtool_ops
->set_tx_csum
)
201 features
[0].available
|= NETIF_F_ALL_CSUM
;
202 if (dev
->ethtool_ops
->set_tso
)
203 features
[0].available
|= NETIF_F_ALL_TSO
;
204 if (dev
->ethtool_ops
->set_rx_csum
)
205 features
[0].available
|= NETIF_F_RXCSUM
;
206 if (dev
->ethtool_ops
->set_flags
)
207 features
[0].available
|= flags_dup_features
;
210 static int ethtool_set_feature_compat(struct net_device
*dev
,
211 int (*legacy_set
)(struct net_device
*, u32
),
212 struct ethtool_set_features_block
*features
, u32 mask
)
219 if (!(features
[0].valid
& mask
))
222 features
[0].valid
&= ~mask
;
224 do_set
= !!(features
[0].requested
& mask
);
226 if (legacy_set(dev
, do_set
) < 0)
228 "Legacy feature change (%s) failed for 0x%08x\n",
229 do_set
? "set" : "clear", mask
);
234 static int ethtool_set_flags_compat(struct net_device
*dev
,
235 int (*legacy_set
)(struct net_device
*, u32
),
236 struct ethtool_set_features_block
*features
, u32 mask
)
243 if (!(features
[0].valid
& mask
))
246 value
= dev
->features
& ~features
[0].valid
;
247 value
|= features
[0].requested
;
249 features
[0].valid
&= ~mask
;
251 if (legacy_set(dev
, value
& mask
) < 0)
252 netdev_info(dev
, "Legacy flags change failed\n");
257 static int ethtool_set_features_compat(struct net_device
*dev
,
258 struct ethtool_set_features_block
*features
)
262 if (!dev
->ethtool_ops
)
265 compat
= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_sg
,
266 features
, NETIF_F_SG
);
267 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_tx_csum
,
268 features
, NETIF_F_ALL_CSUM
);
269 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_tso
,
270 features
, NETIF_F_ALL_TSO
);
271 compat
|= ethtool_set_feature_compat(dev
, dev
->ethtool_ops
->set_rx_csum
,
272 features
, NETIF_F_RXCSUM
);
273 compat
|= ethtool_set_flags_compat(dev
, dev
->ethtool_ops
->set_flags
,
274 features
, flags_dup_features
);
279 static int ethtool_get_features(struct net_device
*dev
, void __user
*useraddr
)
281 struct ethtool_gfeatures cmd
= {
282 .cmd
= ETHTOOL_GFEATURES
,
283 .size
= ETHTOOL_DEV_FEATURE_WORDS
,
285 struct ethtool_get_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
] = {
287 .available
= dev
->hw_features
,
288 .requested
= dev
->wanted_features
,
289 .active
= dev
->features
,
290 .never_changed
= NETIF_F_NEVER_CHANGE
,
293 u32 __user
*sizeaddr
;
296 ethtool_get_features_compat(dev
, features
);
298 sizeaddr
= useraddr
+ offsetof(struct ethtool_gfeatures
, size
);
299 if (get_user(copy_size
, sizeaddr
))
302 if (copy_size
> ETHTOOL_DEV_FEATURE_WORDS
)
303 copy_size
= ETHTOOL_DEV_FEATURE_WORDS
;
305 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
307 useraddr
+= sizeof(cmd
);
308 if (copy_to_user(useraddr
, features
, copy_size
* sizeof(*features
)))
314 static int ethtool_set_features(struct net_device
*dev
, void __user
*useraddr
)
316 struct ethtool_sfeatures cmd
;
317 struct ethtool_set_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
];
320 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
322 useraddr
+= sizeof(cmd
);
324 if (cmd
.size
!= ETHTOOL_DEV_FEATURE_WORDS
)
327 if (copy_from_user(features
, useraddr
, sizeof(features
)))
330 if (features
[0].valid
& ~NETIF_F_ETHTOOL_BITS
)
333 if (ethtool_set_features_compat(dev
, features
))
334 ret
|= ETHTOOL_F_COMPAT
;
336 if (features
[0].valid
& ~dev
->hw_features
) {
337 features
[0].valid
&= dev
->hw_features
;
338 ret
|= ETHTOOL_F_UNSUPPORTED
;
341 dev
->wanted_features
&= ~features
[0].valid
;
342 dev
->wanted_features
|= features
[0].valid
& features
[0].requested
;
343 netdev_update_features(dev
);
345 if ((dev
->wanted_features
^ dev
->features
) & features
[0].valid
)
346 ret
|= ETHTOOL_F_WISH
;
351 static const char netdev_features_strings
[ETHTOOL_DEV_FEATURE_WORDS
* 32][ETH_GSTRING_LEN
] = {
352 /* NETIF_F_SG */ "tx-scatter-gather",
353 /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
354 /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
355 /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
356 /* NETIF_F_IPV6_CSUM */ "tx-checksum-ipv6",
357 /* NETIF_F_HIGHDMA */ "highdma",
358 /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
359 /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
361 /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
362 /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
363 /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
364 /* NETIF_F_GSO */ "tx-generic-segmentation",
365 /* NETIF_F_LLTX */ "tx-lockless",
366 /* NETIF_F_NETNS_LOCAL */ "netns-local",
367 /* NETIF_F_GRO */ "rx-gro",
368 /* NETIF_F_LRO */ "rx-lro",
370 /* NETIF_F_TSO */ "tx-tcp-segmentation",
371 /* NETIF_F_UFO */ "tx-udp-fragmentation",
372 /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
373 /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
374 /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
375 /* NETIF_F_FSO */ "tx-fcoe-segmentation",
379 /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
380 /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
381 /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
382 /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
383 /* NETIF_F_RXHASH */ "rx-hashing",
384 /* NETIF_F_RXCSUM */ "rx-checksum",
389 static int __ethtool_get_sset_count(struct net_device
*dev
, int sset
)
391 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
393 if (sset
== ETH_SS_FEATURES
)
394 return ARRAY_SIZE(netdev_features_strings
);
396 if (ops
&& ops
->get_sset_count
&& ops
->get_strings
)
397 return ops
->get_sset_count(dev
, sset
);
402 static void __ethtool_get_strings(struct net_device
*dev
,
403 u32 stringset
, u8
*data
)
405 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
407 if (stringset
== ETH_SS_FEATURES
)
408 memcpy(data
, netdev_features_strings
,
409 sizeof(netdev_features_strings
));
411 /* ops->get_strings is valid because checked earlier */
412 ops
->get_strings(dev
, stringset
, data
);
415 static u32
ethtool_get_feature_mask(u32 eth_cmd
)
417 /* feature masks of legacy discrete ethtool ops */
420 case ETHTOOL_GTXCSUM
:
421 case ETHTOOL_STXCSUM
:
422 return NETIF_F_ALL_CSUM
| NETIF_F_SCTP_CSUM
;
423 case ETHTOOL_GRXCSUM
:
424 case ETHTOOL_SRXCSUM
:
425 return NETIF_F_RXCSUM
;
431 return NETIF_F_ALL_TSO
;
446 static void *__ethtool_get_one_feature_actor(struct net_device
*dev
, u32 ethcmd
)
448 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
454 case ETHTOOL_GTXCSUM
:
455 return ops
->get_tx_csum
;
456 case ETHTOOL_GRXCSUM
:
457 return ops
->get_rx_csum
;
469 static u32
__ethtool_get_rx_csum_oldbug(struct net_device
*dev
)
471 return !!(dev
->features
& NETIF_F_ALL_CSUM
);
474 static int ethtool_get_one_feature(struct net_device
*dev
,
475 char __user
*useraddr
, u32 ethcmd
)
477 u32 mask
= ethtool_get_feature_mask(ethcmd
);
478 struct ethtool_value edata
= {
480 .data
= !!(dev
->features
& mask
),
483 /* compatibility with discrete get_ ops */
484 if (!(dev
->hw_features
& mask
)) {
485 u32 (*actor
)(struct net_device
*);
487 actor
= __ethtool_get_one_feature_actor(dev
, ethcmd
);
489 /* bug compatibility with old get_rx_csum */
490 if (ethcmd
== ETHTOOL_GRXCSUM
&& !actor
)
491 actor
= __ethtool_get_rx_csum_oldbug
;
494 edata
.data
= actor(dev
);
497 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
502 static int __ethtool_set_tx_csum(struct net_device
*dev
, u32 data
);
503 static int __ethtool_set_rx_csum(struct net_device
*dev
, u32 data
);
504 static int __ethtool_set_sg(struct net_device
*dev
, u32 data
);
505 static int __ethtool_set_tso(struct net_device
*dev
, u32 data
);
506 static int __ethtool_set_ufo(struct net_device
*dev
, u32 data
);
508 static int ethtool_set_one_feature(struct net_device
*dev
,
509 void __user
*useraddr
, u32 ethcmd
)
511 struct ethtool_value edata
;
514 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
517 mask
= ethtool_get_feature_mask(ethcmd
);
518 mask
&= dev
->hw_features
;
521 dev
->wanted_features
|= mask
;
523 dev
->wanted_features
&= ~mask
;
525 netdev_update_features(dev
);
529 /* Driver is not converted to ndo_fix_features or does not
530 * support changing this offload. In the latter case it won't
531 * have corresponding ethtool_ops field set.
533 * Following part is to be removed after all drivers advertise
534 * their changeable features in netdev->hw_features and stop
535 * using discrete offload setting ops.
539 case ETHTOOL_STXCSUM
:
540 return __ethtool_set_tx_csum(dev
, edata
.data
);
541 case ETHTOOL_SRXCSUM
:
542 return __ethtool_set_rx_csum(dev
, edata
.data
);
544 return __ethtool_set_sg(dev
, edata
.data
);
546 return __ethtool_set_tso(dev
, edata
.data
);
548 return __ethtool_set_ufo(dev
, edata
.data
);
554 int __ethtool_set_flags(struct net_device
*dev
, u32 data
)
558 if (data
& ~flags_dup_features
)
561 /* legacy set_flags() op */
562 if (dev
->ethtool_ops
->set_flags
) {
563 if (unlikely(dev
->hw_features
& flags_dup_features
))
565 "driver BUG: mixed hw_features and set_flags()\n");
566 return dev
->ethtool_ops
->set_flags(dev
, data
);
569 /* allow changing only bits set in hw_features */
570 changed
= (data
^ dev
->wanted_features
) & flags_dup_features
;
571 if (changed
& ~dev
->hw_features
)
572 return (changed
& dev
->hw_features
) ? -EINVAL
: -EOPNOTSUPP
;
574 dev
->wanted_features
=
575 (dev
->wanted_features
& ~changed
) | data
;
577 netdev_update_features(dev
);
582 static int ethtool_get_settings(struct net_device
*dev
, void __user
*useraddr
)
584 struct ethtool_cmd cmd
= { .cmd
= ETHTOOL_GSET
};
587 if (!dev
->ethtool_ops
->get_settings
)
590 err
= dev
->ethtool_ops
->get_settings(dev
, &cmd
);
594 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
599 static int ethtool_set_settings(struct net_device
*dev
, void __user
*useraddr
)
601 struct ethtool_cmd cmd
;
603 if (!dev
->ethtool_ops
->set_settings
)
606 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
609 return dev
->ethtool_ops
->set_settings(dev
, &cmd
);
612 static noinline_for_stack
int ethtool_get_drvinfo(struct net_device
*dev
,
613 void __user
*useraddr
)
615 struct ethtool_drvinfo info
;
616 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
618 memset(&info
, 0, sizeof(info
));
619 info
.cmd
= ETHTOOL_GDRVINFO
;
620 if (ops
&& ops
->get_drvinfo
) {
621 ops
->get_drvinfo(dev
, &info
);
622 } else if (dev
->dev
.parent
&& dev
->dev
.parent
->driver
) {
623 strlcpy(info
.bus_info
, dev_name(dev
->dev
.parent
),
624 sizeof(info
.bus_info
));
625 strlcpy(info
.driver
, dev
->dev
.parent
->driver
->name
,
626 sizeof(info
.driver
));
632 * this method of obtaining string set info is deprecated;
633 * Use ETHTOOL_GSSET_INFO instead.
635 if (ops
&& ops
->get_sset_count
) {
638 rc
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
640 info
.testinfo_len
= rc
;
641 rc
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
644 rc
= ops
->get_sset_count(dev
, ETH_SS_PRIV_FLAGS
);
646 info
.n_priv_flags
= rc
;
648 if (ops
&& ops
->get_regs_len
)
649 info
.regdump_len
= ops
->get_regs_len(dev
);
650 if (ops
&& ops
->get_eeprom_len
)
651 info
.eedump_len
= ops
->get_eeprom_len(dev
);
653 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
658 static noinline_for_stack
int ethtool_get_sset_info(struct net_device
*dev
,
659 void __user
*useraddr
)
661 struct ethtool_sset_info info
;
663 int i
, idx
= 0, n_bits
= 0, ret
, rc
;
664 u32
*info_buf
= NULL
;
666 if (copy_from_user(&info
, useraddr
, sizeof(info
)))
669 /* store copy of mask, because we zero struct later on */
670 sset_mask
= info
.sset_mask
;
674 /* calculate size of return buffer */
675 n_bits
= hweight64(sset_mask
);
677 memset(&info
, 0, sizeof(info
));
678 info
.cmd
= ETHTOOL_GSSET_INFO
;
680 info_buf
= kzalloc(n_bits
* sizeof(u32
), GFP_USER
);
685 * fill return buffer based on input bitmask and successful
686 * get_sset_count return
688 for (i
= 0; i
< 64; i
++) {
689 if (!(sset_mask
& (1ULL << i
)))
692 rc
= __ethtool_get_sset_count(dev
, i
);
694 info
.sset_mask
|= (1ULL << i
);
695 info_buf
[idx
++] = rc
;
700 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
703 useraddr
+= offsetof(struct ethtool_sset_info
, data
);
704 if (copy_to_user(useraddr
, info_buf
, idx
* sizeof(u32
)))
714 static noinline_for_stack
int ethtool_set_rxnfc(struct net_device
*dev
,
715 u32 cmd
, void __user
*useraddr
)
717 struct ethtool_rxnfc info
;
718 size_t info_size
= sizeof(info
);
720 if (!dev
->ethtool_ops
->set_rxnfc
)
723 /* struct ethtool_rxnfc was originally defined for
724 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
725 * members. User-space might still be using that
727 if (cmd
== ETHTOOL_SRXFH
)
728 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
731 if (copy_from_user(&info
, useraddr
, info_size
))
734 return dev
->ethtool_ops
->set_rxnfc(dev
, &info
);
737 static noinline_for_stack
int ethtool_get_rxnfc(struct net_device
*dev
,
738 u32 cmd
, void __user
*useraddr
)
740 struct ethtool_rxnfc info
;
741 size_t info_size
= sizeof(info
);
742 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
744 void *rule_buf
= NULL
;
749 /* struct ethtool_rxnfc was originally defined for
750 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
751 * members. User-space might still be using that
753 if (cmd
== ETHTOOL_GRXFH
)
754 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
757 if (copy_from_user(&info
, useraddr
, info_size
))
760 if (info
.cmd
== ETHTOOL_GRXCLSRLALL
) {
761 if (info
.rule_cnt
> 0) {
762 if (info
.rule_cnt
<= KMALLOC_MAX_SIZE
/ sizeof(u32
))
763 rule_buf
= kzalloc(info
.rule_cnt
* sizeof(u32
),
770 ret
= ops
->get_rxnfc(dev
, &info
, rule_buf
);
775 if (copy_to_user(useraddr
, &info
, info_size
))
779 useraddr
+= offsetof(struct ethtool_rxnfc
, rule_locs
);
780 if (copy_to_user(useraddr
, rule_buf
,
781 info
.rule_cnt
* sizeof(u32
)))
792 static noinline_for_stack
int ethtool_get_rxfh_indir(struct net_device
*dev
,
793 void __user
*useraddr
)
795 struct ethtool_rxfh_indir
*indir
;
800 if (!dev
->ethtool_ops
->get_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
= kzalloc(full_size
, GFP_USER
);
816 indir
->cmd
= ETHTOOL_GRXFHINDIR
;
817 indir
->size
= table_size
;
818 ret
= dev
->ethtool_ops
->get_rxfh_indir(dev
, indir
);
822 if (copy_to_user(useraddr
, indir
, full_size
))
830 static noinline_for_stack
int ethtool_set_rxfh_indir(struct net_device
*dev
,
831 void __user
*useraddr
)
833 struct ethtool_rxfh_indir
*indir
;
838 if (!dev
->ethtool_ops
->set_rxfh_indir
)
841 if (copy_from_user(&table_size
,
842 useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
847 (KMALLOC_MAX_SIZE
- sizeof(*indir
)) / sizeof(*indir
->ring_index
))
849 full_size
= sizeof(*indir
) + sizeof(*indir
->ring_index
) * table_size
;
850 indir
= kmalloc(full_size
, GFP_USER
);
854 if (copy_from_user(indir
, useraddr
, full_size
)) {
859 ret
= dev
->ethtool_ops
->set_rxfh_indir(dev
, indir
);
866 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list
*list
,
867 struct ethtool_rx_ntuple_flow_spec
*spec
,
868 struct ethtool_rx_ntuple_flow_spec_container
*fsc
)
871 /* don't add filters forever */
872 if (list
->count
>= ETHTOOL_MAX_NTUPLE_LIST_ENTRY
) {
873 /* free the container */
878 /* Copy the whole filter over */
879 fsc
->fs
.flow_type
= spec
->flow_type
;
880 memcpy(&fsc
->fs
.h_u
, &spec
->h_u
, sizeof(spec
->h_u
));
881 memcpy(&fsc
->fs
.m_u
, &spec
->m_u
, sizeof(spec
->m_u
));
883 fsc
->fs
.vlan_tag
= spec
->vlan_tag
;
884 fsc
->fs
.vlan_tag_mask
= spec
->vlan_tag_mask
;
885 fsc
->fs
.data
= spec
->data
;
886 fsc
->fs
.data_mask
= spec
->data_mask
;
887 fsc
->fs
.action
= spec
->action
;
889 /* add to the list */
890 list_add_tail_rcu(&fsc
->list
, &list
->list
);
895 * ethtool does not (or did not) set masks for flow parameters that are
896 * not specified, so if both value and mask are 0 then this must be
897 * treated as equivalent to a mask with all bits set. Implement that
898 * here rather than in drivers.
900 static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec
*fs
)
902 struct ethtool_tcpip4_spec
*entry
= &fs
->h_u
.tcp_ip4_spec
;
903 struct ethtool_tcpip4_spec
*mask
= &fs
->m_u
.tcp_ip4_spec
;
905 if (fs
->flow_type
!= TCP_V4_FLOW
&&
906 fs
->flow_type
!= UDP_V4_FLOW
&&
907 fs
->flow_type
!= SCTP_V4_FLOW
)
910 if (!(entry
->ip4src
| mask
->ip4src
))
911 mask
->ip4src
= htonl(0xffffffff);
912 if (!(entry
->ip4dst
| mask
->ip4dst
))
913 mask
->ip4dst
= htonl(0xffffffff);
914 if (!(entry
->psrc
| mask
->psrc
))
915 mask
->psrc
= htons(0xffff);
916 if (!(entry
->pdst
| mask
->pdst
))
917 mask
->pdst
= htons(0xffff);
918 if (!(entry
->tos
| mask
->tos
))
920 if (!(fs
->vlan_tag
| fs
->vlan_tag_mask
))
921 fs
->vlan_tag_mask
= 0xffff;
922 if (!(fs
->data
| fs
->data_mask
))
923 fs
->data_mask
= 0xffffffffffffffffULL
;
926 static noinline_for_stack
int ethtool_set_rx_ntuple(struct net_device
*dev
,
927 void __user
*useraddr
)
929 struct ethtool_rx_ntuple cmd
;
930 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
931 struct ethtool_rx_ntuple_flow_spec_container
*fsc
= NULL
;
934 if (!(dev
->features
& NETIF_F_NTUPLE
))
937 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
940 rx_ntuple_fix_masks(&cmd
.fs
);
943 * Cache filter in dev struct for GET operation only if
944 * the underlying driver doesn't have its own GET operation, and
945 * only if the filter was added successfully. First make sure we
946 * can allocate the filter, then continue if successful.
948 if (!ops
->get_rx_ntuple
) {
949 fsc
= kmalloc(sizeof(*fsc
), GFP_ATOMIC
);
954 ret
= ops
->set_rx_ntuple(dev
, &cmd
);
960 if (!ops
->get_rx_ntuple
)
961 __rx_ntuple_filter_add(&dev
->ethtool_ntuple_list
, &cmd
.fs
, fsc
);
966 static int ethtool_get_rx_ntuple(struct net_device
*dev
, void __user
*useraddr
)
968 struct ethtool_gstrings gstrings
;
969 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
970 struct ethtool_rx_ntuple_flow_spec_container
*fsc
;
973 int ret
, i
, num_strings
= 0;
975 if (!ops
->get_sset_count
)
978 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
981 ret
= ops
->get_sset_count(dev
, gstrings
.string_set
);
987 data
= kzalloc(gstrings
.len
* ETH_GSTRING_LEN
, GFP_USER
);
991 if (ops
->get_rx_ntuple
) {
992 /* driver-specific filter grab */
993 ret
= ops
->get_rx_ntuple(dev
, gstrings
.string_set
, data
);
997 /* default ethtool filter grab */
1000 list_for_each_entry(fsc
, &dev
->ethtool_ntuple_list
.list
, list
) {
1001 sprintf(p
, "Filter %d:\n", i
);
1002 p
+= ETH_GSTRING_LEN
;
1005 switch (fsc
->fs
.flow_type
) {
1007 sprintf(p
, "\tFlow Type: TCP\n");
1008 p
+= ETH_GSTRING_LEN
;
1012 sprintf(p
, "\tFlow Type: UDP\n");
1013 p
+= ETH_GSTRING_LEN
;
1017 sprintf(p
, "\tFlow Type: SCTP\n");
1018 p
+= ETH_GSTRING_LEN
;
1021 case AH_ESP_V4_FLOW
:
1022 sprintf(p
, "\tFlow Type: AH ESP\n");
1023 p
+= ETH_GSTRING_LEN
;
1027 sprintf(p
, "\tFlow Type: ESP\n");
1028 p
+= ETH_GSTRING_LEN
;
1032 sprintf(p
, "\tFlow Type: Raw IP\n");
1033 p
+= ETH_GSTRING_LEN
;
1037 sprintf(p
, "\tFlow Type: IPv4\n");
1038 p
+= ETH_GSTRING_LEN
;
1042 sprintf(p
, "\tFlow Type: Unknown\n");
1043 p
+= ETH_GSTRING_LEN
;
1045 goto unknown_filter
;
1048 /* now the rest of the filters */
1049 switch (fsc
->fs
.flow_type
) {
1053 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1054 fsc
->fs
.h_u
.tcp_ip4_spec
.ip4src
);
1055 p
+= ETH_GSTRING_LEN
;
1057 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1058 fsc
->fs
.m_u
.tcp_ip4_spec
.ip4src
);
1059 p
+= ETH_GSTRING_LEN
;
1061 sprintf(p
, "\tDest IP addr: 0x%x\n",
1062 fsc
->fs
.h_u
.tcp_ip4_spec
.ip4dst
);
1063 p
+= ETH_GSTRING_LEN
;
1065 sprintf(p
, "\tDest IP mask: 0x%x\n",
1066 fsc
->fs
.m_u
.tcp_ip4_spec
.ip4dst
);
1067 p
+= ETH_GSTRING_LEN
;
1069 sprintf(p
, "\tSrc Port: %d, mask: 0x%x\n",
1070 fsc
->fs
.h_u
.tcp_ip4_spec
.psrc
,
1071 fsc
->fs
.m_u
.tcp_ip4_spec
.psrc
);
1072 p
+= ETH_GSTRING_LEN
;
1074 sprintf(p
, "\tDest Port: %d, mask: 0x%x\n",
1075 fsc
->fs
.h_u
.tcp_ip4_spec
.pdst
,
1076 fsc
->fs
.m_u
.tcp_ip4_spec
.pdst
);
1077 p
+= ETH_GSTRING_LEN
;
1079 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1080 fsc
->fs
.h_u
.tcp_ip4_spec
.tos
,
1081 fsc
->fs
.m_u
.tcp_ip4_spec
.tos
);
1082 p
+= ETH_GSTRING_LEN
;
1085 case AH_ESP_V4_FLOW
:
1087 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1088 fsc
->fs
.h_u
.ah_ip4_spec
.ip4src
);
1089 p
+= ETH_GSTRING_LEN
;
1091 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1092 fsc
->fs
.m_u
.ah_ip4_spec
.ip4src
);
1093 p
+= ETH_GSTRING_LEN
;
1095 sprintf(p
, "\tDest IP addr: 0x%x\n",
1096 fsc
->fs
.h_u
.ah_ip4_spec
.ip4dst
);
1097 p
+= ETH_GSTRING_LEN
;
1099 sprintf(p
, "\tDest IP mask: 0x%x\n",
1100 fsc
->fs
.m_u
.ah_ip4_spec
.ip4dst
);
1101 p
+= ETH_GSTRING_LEN
;
1103 sprintf(p
, "\tSPI: %d, mask: 0x%x\n",
1104 fsc
->fs
.h_u
.ah_ip4_spec
.spi
,
1105 fsc
->fs
.m_u
.ah_ip4_spec
.spi
);
1106 p
+= ETH_GSTRING_LEN
;
1108 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1109 fsc
->fs
.h_u
.ah_ip4_spec
.tos
,
1110 fsc
->fs
.m_u
.ah_ip4_spec
.tos
);
1111 p
+= ETH_GSTRING_LEN
;
1115 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1116 fsc
->fs
.h_u
.usr_ip4_spec
.ip4src
);
1117 p
+= ETH_GSTRING_LEN
;
1119 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1120 fsc
->fs
.m_u
.usr_ip4_spec
.ip4src
);
1121 p
+= ETH_GSTRING_LEN
;
1123 sprintf(p
, "\tDest IP addr: 0x%x\n",
1124 fsc
->fs
.h_u
.usr_ip4_spec
.ip4dst
);
1125 p
+= ETH_GSTRING_LEN
;
1127 sprintf(p
, "\tDest IP mask: 0x%x\n",
1128 fsc
->fs
.m_u
.usr_ip4_spec
.ip4dst
);
1129 p
+= ETH_GSTRING_LEN
;
1133 sprintf(p
, "\tSrc IP addr: 0x%x\n",
1134 fsc
->fs
.h_u
.usr_ip4_spec
.ip4src
);
1135 p
+= ETH_GSTRING_LEN
;
1137 sprintf(p
, "\tSrc IP mask: 0x%x\n",
1138 fsc
->fs
.m_u
.usr_ip4_spec
.ip4src
);
1139 p
+= ETH_GSTRING_LEN
;
1141 sprintf(p
, "\tDest IP addr: 0x%x\n",
1142 fsc
->fs
.h_u
.usr_ip4_spec
.ip4dst
);
1143 p
+= ETH_GSTRING_LEN
;
1145 sprintf(p
, "\tDest IP mask: 0x%x\n",
1146 fsc
->fs
.m_u
.usr_ip4_spec
.ip4dst
);
1147 p
+= ETH_GSTRING_LEN
;
1149 sprintf(p
, "\tL4 bytes: 0x%x, mask: 0x%x\n",
1150 fsc
->fs
.h_u
.usr_ip4_spec
.l4_4_bytes
,
1151 fsc
->fs
.m_u
.usr_ip4_spec
.l4_4_bytes
);
1152 p
+= ETH_GSTRING_LEN
;
1154 sprintf(p
, "\tTOS: %d, mask: 0x%x\n",
1155 fsc
->fs
.h_u
.usr_ip4_spec
.tos
,
1156 fsc
->fs
.m_u
.usr_ip4_spec
.tos
);
1157 p
+= ETH_GSTRING_LEN
;
1159 sprintf(p
, "\tIP Version: %d, mask: 0x%x\n",
1160 fsc
->fs
.h_u
.usr_ip4_spec
.ip_ver
,
1161 fsc
->fs
.m_u
.usr_ip4_spec
.ip_ver
);
1162 p
+= ETH_GSTRING_LEN
;
1164 sprintf(p
, "\tProtocol: %d, mask: 0x%x\n",
1165 fsc
->fs
.h_u
.usr_ip4_spec
.proto
,
1166 fsc
->fs
.m_u
.usr_ip4_spec
.proto
);
1167 p
+= ETH_GSTRING_LEN
;
1171 sprintf(p
, "\tVLAN: %d, mask: 0x%x\n",
1172 fsc
->fs
.vlan_tag
, fsc
->fs
.vlan_tag_mask
);
1173 p
+= ETH_GSTRING_LEN
;
1175 sprintf(p
, "\tUser-defined: 0x%Lx\n", fsc
->fs
.data
);
1176 p
+= ETH_GSTRING_LEN
;
1178 sprintf(p
, "\tUser-defined mask: 0x%Lx\n", fsc
->fs
.data_mask
);
1179 p
+= ETH_GSTRING_LEN
;
1181 if (fsc
->fs
.action
== ETHTOOL_RXNTUPLE_ACTION_DROP
)
1182 sprintf(p
, "\tAction: Drop\n");
1184 sprintf(p
, "\tAction: Direct to queue %d\n",
1186 p
+= ETH_GSTRING_LEN
;
1192 /* indicate to userspace how many strings we actually have */
1193 gstrings
.len
= num_strings
;
1195 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
1197 useraddr
+= sizeof(gstrings
);
1198 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
1207 static int ethtool_get_regs(struct net_device
*dev
, char __user
*useraddr
)
1209 struct ethtool_regs regs
;
1210 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1214 if (!ops
->get_regs
|| !ops
->get_regs_len
)
1217 if (copy_from_user(®s
, useraddr
, sizeof(regs
)))
1220 reglen
= ops
->get_regs_len(dev
);
1221 if (regs
.len
> reglen
)
1224 regbuf
= vzalloc(reglen
);
1228 ops
->get_regs(dev
, ®s
, regbuf
);
1231 if (copy_to_user(useraddr
, ®s
, sizeof(regs
)))
1233 useraddr
+= offsetof(struct ethtool_regs
, data
);
1234 if (copy_to_user(useraddr
, regbuf
, regs
.len
))
1243 static int ethtool_reset(struct net_device
*dev
, char __user
*useraddr
)
1245 struct ethtool_value reset
;
1248 if (!dev
->ethtool_ops
->reset
)
1251 if (copy_from_user(&reset
, useraddr
, sizeof(reset
)))
1254 ret
= dev
->ethtool_ops
->reset(dev
, &reset
.data
);
1258 if (copy_to_user(useraddr
, &reset
, sizeof(reset
)))
1263 static int ethtool_get_wol(struct net_device
*dev
, char __user
*useraddr
)
1265 struct ethtool_wolinfo wol
= { .cmd
= ETHTOOL_GWOL
};
1267 if (!dev
->ethtool_ops
->get_wol
)
1270 dev
->ethtool_ops
->get_wol(dev
, &wol
);
1272 if (copy_to_user(useraddr
, &wol
, sizeof(wol
)))
1277 static int ethtool_set_wol(struct net_device
*dev
, char __user
*useraddr
)
1279 struct ethtool_wolinfo wol
;
1281 if (!dev
->ethtool_ops
->set_wol
)
1284 if (copy_from_user(&wol
, useraddr
, sizeof(wol
)))
1287 return dev
->ethtool_ops
->set_wol(dev
, &wol
);
1290 static int ethtool_nway_reset(struct net_device
*dev
)
1292 if (!dev
->ethtool_ops
->nway_reset
)
1295 return dev
->ethtool_ops
->nway_reset(dev
);
1298 static int ethtool_get_link(struct net_device
*dev
, char __user
*useraddr
)
1300 struct ethtool_value edata
= { .cmd
= ETHTOOL_GLINK
};
1302 if (!dev
->ethtool_ops
->get_link
)
1305 edata
.data
= netif_running(dev
) && dev
->ethtool_ops
->get_link(dev
);
1307 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1312 static int ethtool_get_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1314 struct ethtool_eeprom eeprom
;
1315 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1316 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1317 u32 bytes_remaining
;
1321 if (!ops
->get_eeprom
|| !ops
->get_eeprom_len
)
1324 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1327 /* Check for wrap and zero */
1328 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1331 /* Check for exceeding total eeprom len */
1332 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
1335 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1339 bytes_remaining
= eeprom
.len
;
1340 while (bytes_remaining
> 0) {
1341 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1343 ret
= ops
->get_eeprom(dev
, &eeprom
, data
);
1346 if (copy_to_user(userbuf
, data
, eeprom
.len
)) {
1350 userbuf
+= eeprom
.len
;
1351 eeprom
.offset
+= eeprom
.len
;
1352 bytes_remaining
-= eeprom
.len
;
1355 eeprom
.len
= userbuf
- (useraddr
+ sizeof(eeprom
));
1356 eeprom
.offset
-= eeprom
.len
;
1357 if (copy_to_user(useraddr
, &eeprom
, sizeof(eeprom
)))
1364 static int ethtool_set_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1366 struct ethtool_eeprom eeprom
;
1367 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1368 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1369 u32 bytes_remaining
;
1373 if (!ops
->set_eeprom
|| !ops
->get_eeprom_len
)
1376 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1379 /* Check for wrap and zero */
1380 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1383 /* Check for exceeding total eeprom len */
1384 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
1387 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1391 bytes_remaining
= eeprom
.len
;
1392 while (bytes_remaining
> 0) {
1393 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1395 if (copy_from_user(data
, userbuf
, eeprom
.len
)) {
1399 ret
= ops
->set_eeprom(dev
, &eeprom
, data
);
1402 userbuf
+= eeprom
.len
;
1403 eeprom
.offset
+= eeprom
.len
;
1404 bytes_remaining
-= eeprom
.len
;
1411 static noinline_for_stack
int ethtool_get_coalesce(struct net_device
*dev
,
1412 void __user
*useraddr
)
1414 struct ethtool_coalesce coalesce
= { .cmd
= ETHTOOL_GCOALESCE
};
1416 if (!dev
->ethtool_ops
->get_coalesce
)
1419 dev
->ethtool_ops
->get_coalesce(dev
, &coalesce
);
1421 if (copy_to_user(useraddr
, &coalesce
, sizeof(coalesce
)))
1426 static noinline_for_stack
int ethtool_set_coalesce(struct net_device
*dev
,
1427 void __user
*useraddr
)
1429 struct ethtool_coalesce coalesce
;
1431 if (!dev
->ethtool_ops
->set_coalesce
)
1434 if (copy_from_user(&coalesce
, useraddr
, sizeof(coalesce
)))
1437 return dev
->ethtool_ops
->set_coalesce(dev
, &coalesce
);
1440 static int ethtool_get_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1442 struct ethtool_ringparam ringparam
= { .cmd
= ETHTOOL_GRINGPARAM
};
1444 if (!dev
->ethtool_ops
->get_ringparam
)
1447 dev
->ethtool_ops
->get_ringparam(dev
, &ringparam
);
1449 if (copy_to_user(useraddr
, &ringparam
, sizeof(ringparam
)))
1454 static int ethtool_set_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1456 struct ethtool_ringparam ringparam
;
1458 if (!dev
->ethtool_ops
->set_ringparam
)
1461 if (copy_from_user(&ringparam
, useraddr
, sizeof(ringparam
)))
1464 return dev
->ethtool_ops
->set_ringparam(dev
, &ringparam
);
1467 static int ethtool_get_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1469 struct ethtool_pauseparam pauseparam
= { ETHTOOL_GPAUSEPARAM
};
1471 if (!dev
->ethtool_ops
->get_pauseparam
)
1474 dev
->ethtool_ops
->get_pauseparam(dev
, &pauseparam
);
1476 if (copy_to_user(useraddr
, &pauseparam
, sizeof(pauseparam
)))
1481 static int ethtool_set_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1483 struct ethtool_pauseparam pauseparam
;
1485 if (!dev
->ethtool_ops
->set_pauseparam
)
1488 if (copy_from_user(&pauseparam
, useraddr
, sizeof(pauseparam
)))
1491 return dev
->ethtool_ops
->set_pauseparam(dev
, &pauseparam
);
1494 static int __ethtool_set_sg(struct net_device
*dev
, u32 data
)
1498 if (!dev
->ethtool_ops
->set_sg
)
1501 if (data
&& !(dev
->features
& NETIF_F_ALL_CSUM
))
1504 if (!data
&& dev
->ethtool_ops
->set_tso
) {
1505 err
= dev
->ethtool_ops
->set_tso(dev
, 0);
1510 if (!data
&& dev
->ethtool_ops
->set_ufo
) {
1511 err
= dev
->ethtool_ops
->set_ufo(dev
, 0);
1515 return dev
->ethtool_ops
->set_sg(dev
, data
);
1518 static int __ethtool_set_tx_csum(struct net_device
*dev
, u32 data
)
1522 if (!dev
->ethtool_ops
->set_tx_csum
)
1525 if (!data
&& dev
->ethtool_ops
->set_sg
) {
1526 err
= __ethtool_set_sg(dev
, 0);
1531 return dev
->ethtool_ops
->set_tx_csum(dev
, data
);
1534 static int __ethtool_set_rx_csum(struct net_device
*dev
, u32 data
)
1536 if (!dev
->ethtool_ops
->set_rx_csum
)
1540 dev
->features
&= ~NETIF_F_GRO
;
1542 return dev
->ethtool_ops
->set_rx_csum(dev
, data
);
1545 static int __ethtool_set_tso(struct net_device
*dev
, u32 data
)
1547 if (!dev
->ethtool_ops
->set_tso
)
1550 if (data
&& !(dev
->features
& NETIF_F_SG
))
1553 return dev
->ethtool_ops
->set_tso(dev
, data
);
1556 static int __ethtool_set_ufo(struct net_device
*dev
, u32 data
)
1558 if (!dev
->ethtool_ops
->set_ufo
)
1560 if (data
&& !(dev
->features
& NETIF_F_SG
))
1562 if (data
&& !((dev
->features
& NETIF_F_GEN_CSUM
) ||
1563 (dev
->features
& (NETIF_F_IP_CSUM
|NETIF_F_IPV6_CSUM
))
1564 == (NETIF_F_IP_CSUM
|NETIF_F_IPV6_CSUM
)))
1566 return dev
->ethtool_ops
->set_ufo(dev
, data
);
1569 static int ethtool_self_test(struct net_device
*dev
, char __user
*useraddr
)
1571 struct ethtool_test test
;
1572 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1576 if (!ops
->self_test
|| !ops
->get_sset_count
)
1579 test_len
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
1582 WARN_ON(test_len
== 0);
1584 if (copy_from_user(&test
, useraddr
, sizeof(test
)))
1587 test
.len
= test_len
;
1588 data
= kmalloc(test_len
* sizeof(u64
), GFP_USER
);
1592 ops
->self_test(dev
, &test
, data
);
1595 if (copy_to_user(useraddr
, &test
, sizeof(test
)))
1597 useraddr
+= sizeof(test
);
1598 if (copy_to_user(useraddr
, data
, test
.len
* sizeof(u64
)))
1607 static int ethtool_get_strings(struct net_device
*dev
, void __user
*useraddr
)
1609 struct ethtool_gstrings gstrings
;
1613 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
1616 ret
= __ethtool_get_sset_count(dev
, gstrings
.string_set
);
1622 data
= kmalloc(gstrings
.len
* ETH_GSTRING_LEN
, GFP_USER
);
1626 __ethtool_get_strings(dev
, gstrings
.string_set
, data
);
1629 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
1631 useraddr
+= sizeof(gstrings
);
1632 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
1641 static int ethtool_phys_id(struct net_device
*dev
, void __user
*useraddr
)
1643 struct ethtool_value id
;
1645 if (!dev
->ethtool_ops
->phys_id
)
1648 if (copy_from_user(&id
, useraddr
, sizeof(id
)))
1651 return dev
->ethtool_ops
->phys_id(dev
, id
.data
);
1654 static int ethtool_get_stats(struct net_device
*dev
, void __user
*useraddr
)
1656 struct ethtool_stats stats
;
1657 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1661 if (!ops
->get_ethtool_stats
|| !ops
->get_sset_count
)
1664 n_stats
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
1667 WARN_ON(n_stats
== 0);
1669 if (copy_from_user(&stats
, useraddr
, sizeof(stats
)))
1672 stats
.n_stats
= n_stats
;
1673 data
= kmalloc(n_stats
* sizeof(u64
), GFP_USER
);
1677 ops
->get_ethtool_stats(dev
, &stats
, data
);
1680 if (copy_to_user(useraddr
, &stats
, sizeof(stats
)))
1682 useraddr
+= sizeof(stats
);
1683 if (copy_to_user(useraddr
, data
, stats
.n_stats
* sizeof(u64
)))
1692 static int ethtool_get_perm_addr(struct net_device
*dev
, void __user
*useraddr
)
1694 struct ethtool_perm_addr epaddr
;
1696 if (copy_from_user(&epaddr
, useraddr
, sizeof(epaddr
)))
1699 if (epaddr
.size
< dev
->addr_len
)
1701 epaddr
.size
= dev
->addr_len
;
1703 if (copy_to_user(useraddr
, &epaddr
, sizeof(epaddr
)))
1705 useraddr
+= sizeof(epaddr
);
1706 if (copy_to_user(useraddr
, dev
->perm_addr
, epaddr
.size
))
1711 static int ethtool_get_value(struct net_device
*dev
, char __user
*useraddr
,
1712 u32 cmd
, u32 (*actor
)(struct net_device
*))
1714 struct ethtool_value edata
= { .cmd
= cmd
};
1719 edata
.data
= actor(dev
);
1721 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1726 static int ethtool_set_value_void(struct net_device
*dev
, char __user
*useraddr
,
1727 void (*actor
)(struct net_device
*, u32
))
1729 struct ethtool_value edata
;
1734 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1737 actor(dev
, edata
.data
);
1741 static int ethtool_set_value(struct net_device
*dev
, char __user
*useraddr
,
1742 int (*actor
)(struct net_device
*, u32
))
1744 struct ethtool_value edata
;
1749 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1752 return actor(dev
, edata
.data
);
1755 static noinline_for_stack
int ethtool_flash_device(struct net_device
*dev
,
1756 char __user
*useraddr
)
1758 struct ethtool_flash efl
;
1760 if (copy_from_user(&efl
, useraddr
, sizeof(efl
)))
1763 if (!dev
->ethtool_ops
->flash_device
)
1766 return dev
->ethtool_ops
->flash_device(dev
, &efl
);
1769 /* The main entry point in this file. Called from net/core/dev.c */
1771 int dev_ethtool(struct net
*net
, struct ifreq
*ifr
)
1773 struct net_device
*dev
= __dev_get_by_name(net
, ifr
->ifr_name
);
1774 void __user
*useraddr
= ifr
->ifr_data
;
1779 if (!dev
|| !netif_device_present(dev
))
1782 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
1785 if (!dev
->ethtool_ops
) {
1786 /* ETHTOOL_GDRVINFO does not require any driver support.
1787 * It is also unprivileged and does not change anything,
1788 * so we can take a shortcut to it. */
1789 if (ethcmd
== ETHTOOL_GDRVINFO
)
1790 return ethtool_get_drvinfo(dev
, useraddr
);
1795 /* Allow some commands to be done by anyone */
1798 case ETHTOOL_GDRVINFO
:
1799 case ETHTOOL_GMSGLVL
:
1800 case ETHTOOL_GCOALESCE
:
1801 case ETHTOOL_GRINGPARAM
:
1802 case ETHTOOL_GPAUSEPARAM
:
1803 case ETHTOOL_GRXCSUM
:
1804 case ETHTOOL_GTXCSUM
:
1806 case ETHTOOL_GSTRINGS
:
1808 case ETHTOOL_GPERMADDR
:
1812 case ETHTOOL_GFLAGS
:
1813 case ETHTOOL_GPFLAGS
:
1815 case ETHTOOL_GRXRINGS
:
1816 case ETHTOOL_GRXCLSRLCNT
:
1817 case ETHTOOL_GRXCLSRULE
:
1818 case ETHTOOL_GRXCLSRLALL
:
1819 case ETHTOOL_GFEATURES
:
1822 if (!capable(CAP_NET_ADMIN
))
1826 if (dev
->ethtool_ops
->begin
) {
1827 rc
= dev
->ethtool_ops
->begin(dev
);
1831 old_features
= dev
->features
;
1835 rc
= ethtool_get_settings(dev
, useraddr
);
1838 rc
= ethtool_set_settings(dev
, useraddr
);
1840 case ETHTOOL_GDRVINFO
:
1841 rc
= ethtool_get_drvinfo(dev
, useraddr
);
1844 rc
= ethtool_get_regs(dev
, useraddr
);
1847 rc
= ethtool_get_wol(dev
, useraddr
);
1850 rc
= ethtool_set_wol(dev
, useraddr
);
1852 case ETHTOOL_GMSGLVL
:
1853 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1854 dev
->ethtool_ops
->get_msglevel
);
1856 case ETHTOOL_SMSGLVL
:
1857 rc
= ethtool_set_value_void(dev
, useraddr
,
1858 dev
->ethtool_ops
->set_msglevel
);
1860 case ETHTOOL_NWAY_RST
:
1861 rc
= ethtool_nway_reset(dev
);
1864 rc
= ethtool_get_link(dev
, useraddr
);
1866 case ETHTOOL_GEEPROM
:
1867 rc
= ethtool_get_eeprom(dev
, useraddr
);
1869 case ETHTOOL_SEEPROM
:
1870 rc
= ethtool_set_eeprom(dev
, useraddr
);
1872 case ETHTOOL_GCOALESCE
:
1873 rc
= ethtool_get_coalesce(dev
, useraddr
);
1875 case ETHTOOL_SCOALESCE
:
1876 rc
= ethtool_set_coalesce(dev
, useraddr
);
1878 case ETHTOOL_GRINGPARAM
:
1879 rc
= ethtool_get_ringparam(dev
, useraddr
);
1881 case ETHTOOL_SRINGPARAM
:
1882 rc
= ethtool_set_ringparam(dev
, useraddr
);
1884 case ETHTOOL_GPAUSEPARAM
:
1885 rc
= ethtool_get_pauseparam(dev
, useraddr
);
1887 case ETHTOOL_SPAUSEPARAM
:
1888 rc
= ethtool_set_pauseparam(dev
, useraddr
);
1891 rc
= ethtool_self_test(dev
, useraddr
);
1893 case ETHTOOL_GSTRINGS
:
1894 rc
= ethtool_get_strings(dev
, useraddr
);
1896 case ETHTOOL_PHYS_ID
:
1897 rc
= ethtool_phys_id(dev
, useraddr
);
1899 case ETHTOOL_GSTATS
:
1900 rc
= ethtool_get_stats(dev
, useraddr
);
1902 case ETHTOOL_GPERMADDR
:
1903 rc
= ethtool_get_perm_addr(dev
, useraddr
);
1905 case ETHTOOL_GFLAGS
:
1906 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1907 (dev
->ethtool_ops
->get_flags
?
1908 dev
->ethtool_ops
->get_flags
:
1909 ethtool_op_get_flags
));
1911 case ETHTOOL_SFLAGS
:
1912 rc
= ethtool_set_value(dev
, useraddr
, __ethtool_set_flags
);
1914 case ETHTOOL_GPFLAGS
:
1915 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
1916 dev
->ethtool_ops
->get_priv_flags
);
1918 case ETHTOOL_SPFLAGS
:
1919 rc
= ethtool_set_value(dev
, useraddr
,
1920 dev
->ethtool_ops
->set_priv_flags
);
1923 case ETHTOOL_GRXRINGS
:
1924 case ETHTOOL_GRXCLSRLCNT
:
1925 case ETHTOOL_GRXCLSRULE
:
1926 case ETHTOOL_GRXCLSRLALL
:
1927 rc
= ethtool_get_rxnfc(dev
, ethcmd
, useraddr
);
1930 case ETHTOOL_SRXCLSRLDEL
:
1931 case ETHTOOL_SRXCLSRLINS
:
1932 rc
= ethtool_set_rxnfc(dev
, ethcmd
, useraddr
);
1934 case ETHTOOL_FLASHDEV
:
1935 rc
= ethtool_flash_device(dev
, useraddr
);
1938 rc
= ethtool_reset(dev
, useraddr
);
1940 case ETHTOOL_SRXNTUPLE
:
1941 rc
= ethtool_set_rx_ntuple(dev
, useraddr
);
1943 case ETHTOOL_GRXNTUPLE
:
1944 rc
= ethtool_get_rx_ntuple(dev
, useraddr
);
1946 case ETHTOOL_GSSET_INFO
:
1947 rc
= ethtool_get_sset_info(dev
, useraddr
);
1949 case ETHTOOL_GRXFHINDIR
:
1950 rc
= ethtool_get_rxfh_indir(dev
, useraddr
);
1952 case ETHTOOL_SRXFHINDIR
:
1953 rc
= ethtool_set_rxfh_indir(dev
, useraddr
);
1955 case ETHTOOL_GFEATURES
:
1956 rc
= ethtool_get_features(dev
, useraddr
);
1958 case ETHTOOL_SFEATURES
:
1959 rc
= ethtool_set_features(dev
, useraddr
);
1961 case ETHTOOL_GTXCSUM
:
1962 case ETHTOOL_GRXCSUM
:
1968 rc
= ethtool_get_one_feature(dev
, useraddr
, ethcmd
);
1970 case ETHTOOL_STXCSUM
:
1971 case ETHTOOL_SRXCSUM
:
1977 rc
= ethtool_set_one_feature(dev
, useraddr
, ethcmd
);
1983 if (dev
->ethtool_ops
->complete
)
1984 dev
->ethtool_ops
->complete(dev
);
1986 if (old_features
!= dev
->features
)
1987 netdev_features_change(dev
);