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/net_tstamp.h>
21 #include <linux/phy.h>
22 #include <linux/bitops.h>
23 #include <linux/uaccess.h>
24 #include <linux/vmalloc.h>
25 #include <linux/slab.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/sched.h>
28 #include <linux/net.h>
31 * Some useful ethtool_ops methods that're device independent.
32 * If we find that all drivers want to do the same thing here,
33 * we can turn these into dev_() function calls.
36 u32
ethtool_op_get_link(struct net_device
*dev
)
38 return netif_carrier_ok(dev
) ? 1 : 0;
40 EXPORT_SYMBOL(ethtool_op_get_link
);
42 int ethtool_op_get_ts_info(struct net_device
*dev
, struct ethtool_ts_info
*info
)
44 info
->so_timestamping
=
45 SOF_TIMESTAMPING_TX_SOFTWARE
|
46 SOF_TIMESTAMPING_RX_SOFTWARE
|
47 SOF_TIMESTAMPING_SOFTWARE
;
51 EXPORT_SYMBOL(ethtool_op_get_ts_info
);
53 /* Handlers for each ethtool command */
55 #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
57 static const char netdev_features_strings
[NETDEV_FEATURE_COUNT
][ETH_GSTRING_LEN
] = {
58 [NETIF_F_SG_BIT
] = "tx-scatter-gather",
59 [NETIF_F_IP_CSUM_BIT
] = "tx-checksum-ipv4",
60 [NETIF_F_HW_CSUM_BIT
] = "tx-checksum-ip-generic",
61 [NETIF_F_IPV6_CSUM_BIT
] = "tx-checksum-ipv6",
62 [NETIF_F_HIGHDMA_BIT
] = "highdma",
63 [NETIF_F_FRAGLIST_BIT
] = "tx-scatter-gather-fraglist",
64 [NETIF_F_HW_VLAN_CTAG_TX_BIT
] = "tx-vlan-hw-insert",
66 [NETIF_F_HW_VLAN_CTAG_RX_BIT
] = "rx-vlan-hw-parse",
67 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT
] = "rx-vlan-filter",
68 [NETIF_F_HW_VLAN_STAG_TX_BIT
] = "tx-vlan-stag-hw-insert",
69 [NETIF_F_HW_VLAN_STAG_RX_BIT
] = "rx-vlan-stag-hw-parse",
70 [NETIF_F_HW_VLAN_STAG_FILTER_BIT
] = "rx-vlan-stag-filter",
71 [NETIF_F_VLAN_CHALLENGED_BIT
] = "vlan-challenged",
72 [NETIF_F_GSO_BIT
] = "tx-generic-segmentation",
73 [NETIF_F_LLTX_BIT
] = "tx-lockless",
74 [NETIF_F_NETNS_LOCAL_BIT
] = "netns-local",
75 [NETIF_F_GRO_BIT
] = "rx-gro",
76 [NETIF_F_LRO_BIT
] = "rx-lro",
78 [NETIF_F_TSO_BIT
] = "tx-tcp-segmentation",
79 [NETIF_F_UFO_BIT
] = "tx-udp-fragmentation",
80 [NETIF_F_GSO_ROBUST_BIT
] = "tx-gso-robust",
81 [NETIF_F_TSO_ECN_BIT
] = "tx-tcp-ecn-segmentation",
82 [NETIF_F_TSO6_BIT
] = "tx-tcp6-segmentation",
83 [NETIF_F_FSO_BIT
] = "tx-fcoe-segmentation",
84 [NETIF_F_GSO_GRE_BIT
] = "tx-gre-segmentation",
85 [NETIF_F_GSO_GRE_CSUM_BIT
] = "tx-gre-csum-segmentation",
86 [NETIF_F_GSO_IPIP_BIT
] = "tx-ipip-segmentation",
87 [NETIF_F_GSO_SIT_BIT
] = "tx-sit-segmentation",
88 [NETIF_F_GSO_UDP_TUNNEL_BIT
] = "tx-udp_tnl-segmentation",
89 [NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT
] = "tx-udp_tnl-csum-segmentation",
91 [NETIF_F_FCOE_CRC_BIT
] = "tx-checksum-fcoe-crc",
92 [NETIF_F_SCTP_CRC_BIT
] = "tx-checksum-sctp",
93 [NETIF_F_FCOE_MTU_BIT
] = "fcoe-mtu",
94 [NETIF_F_NTUPLE_BIT
] = "rx-ntuple-filter",
95 [NETIF_F_RXHASH_BIT
] = "rx-hashing",
96 [NETIF_F_RXCSUM_BIT
] = "rx-checksum",
97 [NETIF_F_NOCACHE_COPY_BIT
] = "tx-nocache-copy",
98 [NETIF_F_LOOPBACK_BIT
] = "loopback",
99 [NETIF_F_RXFCS_BIT
] = "rx-fcs",
100 [NETIF_F_RXALL_BIT
] = "rx-all",
101 [NETIF_F_HW_L2FW_DOFFLOAD_BIT
] = "l2-fwd-offload",
102 [NETIF_F_BUSY_POLL_BIT
] = "busy-poll",
103 [NETIF_F_HW_TC_BIT
] = "hw-tc-offload",
107 rss_hash_func_strings
[ETH_RSS_HASH_FUNCS_COUNT
][ETH_GSTRING_LEN
] = {
108 [ETH_RSS_HASH_TOP_BIT
] = "toeplitz",
109 [ETH_RSS_HASH_XOR_BIT
] = "xor",
113 tunable_strings
[__ETHTOOL_TUNABLE_COUNT
][ETH_GSTRING_LEN
] = {
114 [ETHTOOL_ID_UNSPEC
] = "Unspec",
115 [ETHTOOL_RX_COPYBREAK
] = "rx-copybreak",
116 [ETHTOOL_TX_COPYBREAK
] = "tx-copybreak",
119 static int ethtool_get_features(struct net_device
*dev
, void __user
*useraddr
)
121 struct ethtool_gfeatures cmd
= {
122 .cmd
= ETHTOOL_GFEATURES
,
123 .size
= ETHTOOL_DEV_FEATURE_WORDS
,
125 struct ethtool_get_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
];
126 u32 __user
*sizeaddr
;
130 /* in case feature bits run out again */
131 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS
* sizeof(u32
) > sizeof(netdev_features_t
));
133 for (i
= 0; i
< ETHTOOL_DEV_FEATURE_WORDS
; ++i
) {
134 features
[i
].available
= (u32
)(dev
->hw_features
>> (32 * i
));
135 features
[i
].requested
= (u32
)(dev
->wanted_features
>> (32 * i
));
136 features
[i
].active
= (u32
)(dev
->features
>> (32 * i
));
137 features
[i
].never_changed
=
138 (u32
)(NETIF_F_NEVER_CHANGE
>> (32 * i
));
141 sizeaddr
= useraddr
+ offsetof(struct ethtool_gfeatures
, size
);
142 if (get_user(copy_size
, sizeaddr
))
145 if (copy_size
> ETHTOOL_DEV_FEATURE_WORDS
)
146 copy_size
= ETHTOOL_DEV_FEATURE_WORDS
;
148 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
150 useraddr
+= sizeof(cmd
);
151 if (copy_to_user(useraddr
, features
, copy_size
* sizeof(*features
)))
157 static int ethtool_set_features(struct net_device
*dev
, void __user
*useraddr
)
159 struct ethtool_sfeatures cmd
;
160 struct ethtool_set_features_block features
[ETHTOOL_DEV_FEATURE_WORDS
];
161 netdev_features_t wanted
= 0, valid
= 0;
164 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
166 useraddr
+= sizeof(cmd
);
168 if (cmd
.size
!= ETHTOOL_DEV_FEATURE_WORDS
)
171 if (copy_from_user(features
, useraddr
, sizeof(features
)))
174 for (i
= 0; i
< ETHTOOL_DEV_FEATURE_WORDS
; ++i
) {
175 valid
|= (netdev_features_t
)features
[i
].valid
<< (32 * i
);
176 wanted
|= (netdev_features_t
)features
[i
].requested
<< (32 * i
);
179 if (valid
& ~NETIF_F_ETHTOOL_BITS
)
182 if (valid
& ~dev
->hw_features
) {
183 valid
&= dev
->hw_features
;
184 ret
|= ETHTOOL_F_UNSUPPORTED
;
187 dev
->wanted_features
&= ~valid
;
188 dev
->wanted_features
|= wanted
& valid
;
189 __netdev_update_features(dev
);
191 if ((dev
->wanted_features
^ dev
->features
) & valid
)
192 ret
|= ETHTOOL_F_WISH
;
197 static int phy_get_sset_count(struct phy_device
*phydev
)
201 if (phydev
->drv
->get_sset_count
&&
202 phydev
->drv
->get_strings
&&
203 phydev
->drv
->get_stats
) {
204 mutex_lock(&phydev
->lock
);
205 ret
= phydev
->drv
->get_sset_count(phydev
);
206 mutex_unlock(&phydev
->lock
);
214 static int __ethtool_get_sset_count(struct net_device
*dev
, int sset
)
216 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
218 if (sset
== ETH_SS_FEATURES
)
219 return ARRAY_SIZE(netdev_features_strings
);
221 if (sset
== ETH_SS_RSS_HASH_FUNCS
)
222 return ARRAY_SIZE(rss_hash_func_strings
);
224 if (sset
== ETH_SS_TUNABLES
)
225 return ARRAY_SIZE(tunable_strings
);
227 if (sset
== ETH_SS_PHY_STATS
) {
229 return phy_get_sset_count(dev
->phydev
);
234 if (ops
->get_sset_count
&& ops
->get_strings
)
235 return ops
->get_sset_count(dev
, sset
);
240 static void __ethtool_get_strings(struct net_device
*dev
,
241 u32 stringset
, u8
*data
)
243 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
245 if (stringset
== ETH_SS_FEATURES
)
246 memcpy(data
, netdev_features_strings
,
247 sizeof(netdev_features_strings
));
248 else if (stringset
== ETH_SS_RSS_HASH_FUNCS
)
249 memcpy(data
, rss_hash_func_strings
,
250 sizeof(rss_hash_func_strings
));
251 else if (stringset
== ETH_SS_TUNABLES
)
252 memcpy(data
, tunable_strings
, sizeof(tunable_strings
));
253 else if (stringset
== ETH_SS_PHY_STATS
) {
254 struct phy_device
*phydev
= dev
->phydev
;
257 mutex_lock(&phydev
->lock
);
258 phydev
->drv
->get_strings(phydev
, data
);
259 mutex_unlock(&phydev
->lock
);
264 /* ops->get_strings is valid because checked earlier */
265 ops
->get_strings(dev
, stringset
, data
);
268 static netdev_features_t
ethtool_get_feature_mask(u32 eth_cmd
)
270 /* feature masks of legacy discrete ethtool ops */
273 case ETHTOOL_GTXCSUM
:
274 case ETHTOOL_STXCSUM
:
275 return NETIF_F_CSUM_MASK
| NETIF_F_SCTP_CRC
;
276 case ETHTOOL_GRXCSUM
:
277 case ETHTOOL_SRXCSUM
:
278 return NETIF_F_RXCSUM
;
284 return NETIF_F_ALL_TSO
;
299 static int ethtool_get_one_feature(struct net_device
*dev
,
300 char __user
*useraddr
, u32 ethcmd
)
302 netdev_features_t mask
= ethtool_get_feature_mask(ethcmd
);
303 struct ethtool_value edata
= {
305 .data
= !!(dev
->features
& mask
),
308 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
313 static int ethtool_set_one_feature(struct net_device
*dev
,
314 void __user
*useraddr
, u32 ethcmd
)
316 struct ethtool_value edata
;
317 netdev_features_t mask
;
319 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
322 mask
= ethtool_get_feature_mask(ethcmd
);
323 mask
&= dev
->hw_features
;
328 dev
->wanted_features
|= mask
;
330 dev
->wanted_features
&= ~mask
;
332 __netdev_update_features(dev
);
337 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
338 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
339 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
340 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
343 static u32
__ethtool_get_flags(struct net_device
*dev
)
347 if (dev
->features
& NETIF_F_LRO
)
348 flags
|= ETH_FLAG_LRO
;
349 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
350 flags
|= ETH_FLAG_RXVLAN
;
351 if (dev
->features
& NETIF_F_HW_VLAN_CTAG_TX
)
352 flags
|= ETH_FLAG_TXVLAN
;
353 if (dev
->features
& NETIF_F_NTUPLE
)
354 flags
|= ETH_FLAG_NTUPLE
;
355 if (dev
->features
& NETIF_F_RXHASH
)
356 flags
|= ETH_FLAG_RXHASH
;
361 static int __ethtool_set_flags(struct net_device
*dev
, u32 data
)
363 netdev_features_t features
= 0, changed
;
365 if (data
& ~ETH_ALL_FLAGS
)
368 if (data
& ETH_FLAG_LRO
)
369 features
|= NETIF_F_LRO
;
370 if (data
& ETH_FLAG_RXVLAN
)
371 features
|= NETIF_F_HW_VLAN_CTAG_RX
;
372 if (data
& ETH_FLAG_TXVLAN
)
373 features
|= NETIF_F_HW_VLAN_CTAG_TX
;
374 if (data
& ETH_FLAG_NTUPLE
)
375 features
|= NETIF_F_NTUPLE
;
376 if (data
& ETH_FLAG_RXHASH
)
377 features
|= NETIF_F_RXHASH
;
379 /* allow changing only bits set in hw_features */
380 changed
= (features
^ dev
->features
) & ETH_ALL_FEATURES
;
381 if (changed
& ~dev
->hw_features
)
382 return (changed
& dev
->hw_features
) ? -EINVAL
: -EOPNOTSUPP
;
384 dev
->wanted_features
=
385 (dev
->wanted_features
& ~changed
) | (features
& changed
);
387 __netdev_update_features(dev
);
392 static void convert_legacy_u32_to_link_mode(unsigned long *dst
, u32 legacy_u32
)
394 bitmap_zero(dst
, __ETHTOOL_LINK_MODE_MASK_NBITS
);
398 /* return false if src had higher bits set. lower bits always updated. */
399 static bool convert_link_mode_to_legacy_u32(u32
*legacy_u32
,
400 const unsigned long *src
)
404 /* TODO: following test will soon always be true */
405 if (__ETHTOOL_LINK_MODE_MASK_NBITS
> 32) {
406 __ETHTOOL_DECLARE_LINK_MODE_MASK(ext
);
408 bitmap_zero(ext
, __ETHTOOL_LINK_MODE_MASK_NBITS
);
409 bitmap_fill(ext
, 32);
410 bitmap_complement(ext
, ext
, __ETHTOOL_LINK_MODE_MASK_NBITS
);
411 if (bitmap_intersects(ext
, src
,
412 __ETHTOOL_LINK_MODE_MASK_NBITS
)) {
413 /* src mask goes beyond bit 31 */
417 *legacy_u32
= src
[0];
421 /* return false if legacy contained non-0 deprecated fields
422 * transceiver/maxtxpkt/maxrxpkt. rest of ksettings always updated
425 convert_legacy_settings_to_link_ksettings(
426 struct ethtool_link_ksettings
*link_ksettings
,
427 const struct ethtool_cmd
*legacy_settings
)
431 memset(link_ksettings
, 0, sizeof(*link_ksettings
));
433 /* This is used to tell users that driver is still using these
434 * deprecated legacy fields, and they should not use
435 * %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS
437 if (legacy_settings
->transceiver
||
438 legacy_settings
->maxtxpkt
||
439 legacy_settings
->maxrxpkt
)
442 convert_legacy_u32_to_link_mode(
443 link_ksettings
->link_modes
.supported
,
444 legacy_settings
->supported
);
445 convert_legacy_u32_to_link_mode(
446 link_ksettings
->link_modes
.advertising
,
447 legacy_settings
->advertising
);
448 convert_legacy_u32_to_link_mode(
449 link_ksettings
->link_modes
.lp_advertising
,
450 legacy_settings
->lp_advertising
);
451 link_ksettings
->base
.speed
452 = ethtool_cmd_speed(legacy_settings
);
453 link_ksettings
->base
.duplex
454 = legacy_settings
->duplex
;
455 link_ksettings
->base
.port
456 = legacy_settings
->port
;
457 link_ksettings
->base
.phy_address
458 = legacy_settings
->phy_address
;
459 link_ksettings
->base
.autoneg
460 = legacy_settings
->autoneg
;
461 link_ksettings
->base
.mdio_support
462 = legacy_settings
->mdio_support
;
463 link_ksettings
->base
.eth_tp_mdix
464 = legacy_settings
->eth_tp_mdix
;
465 link_ksettings
->base
.eth_tp_mdix_ctrl
466 = legacy_settings
->eth_tp_mdix_ctrl
;
470 /* return false if ksettings link modes had higher bits
471 * set. legacy_settings always updated (best effort)
474 convert_link_ksettings_to_legacy_settings(
475 struct ethtool_cmd
*legacy_settings
,
476 const struct ethtool_link_ksettings
*link_ksettings
)
480 memset(legacy_settings
, 0, sizeof(*legacy_settings
));
481 /* this also clears the deprecated fields in legacy structure:
487 retval
&= convert_link_mode_to_legacy_u32(
488 &legacy_settings
->supported
,
489 link_ksettings
->link_modes
.supported
);
490 retval
&= convert_link_mode_to_legacy_u32(
491 &legacy_settings
->advertising
,
492 link_ksettings
->link_modes
.advertising
);
493 retval
&= convert_link_mode_to_legacy_u32(
494 &legacy_settings
->lp_advertising
,
495 link_ksettings
->link_modes
.lp_advertising
);
496 ethtool_cmd_speed_set(legacy_settings
, link_ksettings
->base
.speed
);
497 legacy_settings
->duplex
498 = link_ksettings
->base
.duplex
;
499 legacy_settings
->port
500 = link_ksettings
->base
.port
;
501 legacy_settings
->phy_address
502 = link_ksettings
->base
.phy_address
;
503 legacy_settings
->autoneg
504 = link_ksettings
->base
.autoneg
;
505 legacy_settings
->mdio_support
506 = link_ksettings
->base
.mdio_support
;
507 legacy_settings
->eth_tp_mdix
508 = link_ksettings
->base
.eth_tp_mdix
;
509 legacy_settings
->eth_tp_mdix_ctrl
510 = link_ksettings
->base
.eth_tp_mdix_ctrl
;
514 /* number of 32-bit words to store the user's link mode bitmaps */
515 #define __ETHTOOL_LINK_MODE_MASK_NU32 \
516 DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
518 /* layout of the struct passed from/to userland */
519 struct ethtool_link_usettings
{
520 struct ethtool_link_settings base
;
522 __u32 supported
[__ETHTOOL_LINK_MODE_MASK_NU32
];
523 __u32 advertising
[__ETHTOOL_LINK_MODE_MASK_NU32
];
524 __u32 lp_advertising
[__ETHTOOL_LINK_MODE_MASK_NU32
];
528 /* Internal kernel helper to query a device ethtool_link_settings.
530 * Backward compatibility note: for compatibility with legacy drivers
531 * that implement only the ethtool_cmd API, this has to work with both
532 * drivers implementing get_link_ksettings API and drivers
533 * implementing get_settings API. When drivers implement get_settings
534 * and report ethtool_cmd deprecated fields
535 * (transceiver/maxrxpkt/maxtxpkt), these fields are silently ignored
536 * because the resulting struct ethtool_link_settings does not report them.
538 int __ethtool_get_link_ksettings(struct net_device
*dev
,
539 struct ethtool_link_ksettings
*link_ksettings
)
542 struct ethtool_cmd cmd
;
546 if (dev
->ethtool_ops
->get_link_ksettings
) {
547 memset(link_ksettings
, 0, sizeof(*link_ksettings
));
548 return dev
->ethtool_ops
->get_link_ksettings(dev
,
552 /* driver doesn't support %ethtool_link_ksettings API. revert to
553 * legacy %ethtool_cmd API, unless it's not supported either.
554 * TODO: remove when ethtool_ops::get_settings disappears internally
556 if (!dev
->ethtool_ops
->get_settings
)
559 memset(&cmd
, 0, sizeof(cmd
));
560 cmd
.cmd
= ETHTOOL_GSET
;
561 err
= dev
->ethtool_ops
->get_settings(dev
, &cmd
);
565 /* we ignore deprecated fields transceiver/maxrxpkt/maxtxpkt
567 convert_legacy_settings_to_link_ksettings(link_ksettings
, &cmd
);
570 EXPORT_SYMBOL(__ethtool_get_link_ksettings
);
572 /* convert ethtool_link_usettings in user space to a kernel internal
573 * ethtool_link_ksettings. return 0 on success, errno on error.
575 static int load_link_ksettings_from_user(struct ethtool_link_ksettings
*to
,
576 const void __user
*from
)
578 struct ethtool_link_usettings link_usettings
;
580 if (copy_from_user(&link_usettings
, from
, sizeof(link_usettings
)))
583 memcpy(&to
->base
, &link_usettings
.base
, sizeof(to
->base
));
584 bitmap_from_u32array(to
->link_modes
.supported
,
585 __ETHTOOL_LINK_MODE_MASK_NBITS
,
586 link_usettings
.link_modes
.supported
,
587 __ETHTOOL_LINK_MODE_MASK_NU32
);
588 bitmap_from_u32array(to
->link_modes
.advertising
,
589 __ETHTOOL_LINK_MODE_MASK_NBITS
,
590 link_usettings
.link_modes
.advertising
,
591 __ETHTOOL_LINK_MODE_MASK_NU32
);
592 bitmap_from_u32array(to
->link_modes
.lp_advertising
,
593 __ETHTOOL_LINK_MODE_MASK_NBITS
,
594 link_usettings
.link_modes
.lp_advertising
,
595 __ETHTOOL_LINK_MODE_MASK_NU32
);
600 /* convert a kernel internal ethtool_link_ksettings to
601 * ethtool_link_usettings in user space. return 0 on success, errno on
605 store_link_ksettings_for_user(void __user
*to
,
606 const struct ethtool_link_ksettings
*from
)
608 struct ethtool_link_usettings link_usettings
;
610 memcpy(&link_usettings
.base
, &from
->base
, sizeof(link_usettings
));
611 bitmap_to_u32array(link_usettings
.link_modes
.supported
,
612 __ETHTOOL_LINK_MODE_MASK_NU32
,
613 from
->link_modes
.supported
,
614 __ETHTOOL_LINK_MODE_MASK_NBITS
);
615 bitmap_to_u32array(link_usettings
.link_modes
.advertising
,
616 __ETHTOOL_LINK_MODE_MASK_NU32
,
617 from
->link_modes
.advertising
,
618 __ETHTOOL_LINK_MODE_MASK_NBITS
);
619 bitmap_to_u32array(link_usettings
.link_modes
.lp_advertising
,
620 __ETHTOOL_LINK_MODE_MASK_NU32
,
621 from
->link_modes
.lp_advertising
,
622 __ETHTOOL_LINK_MODE_MASK_NBITS
);
624 if (copy_to_user(to
, &link_usettings
, sizeof(link_usettings
)))
630 /* Query device for its ethtool_link_settings.
632 * Backward compatibility note: this function must fail when driver
633 * does not implement ethtool::get_link_ksettings, even if legacy
634 * ethtool_ops::get_settings is implemented. This tells new versions
635 * of ethtool that they should use the legacy API %ETHTOOL_GSET for
636 * this driver, so that they can correctly access the ethtool_cmd
637 * deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver
638 * implements ethtool_ops::get_settings anymore.
640 static int ethtool_get_link_ksettings(struct net_device
*dev
,
641 void __user
*useraddr
)
644 struct ethtool_link_ksettings link_ksettings
;
648 if (!dev
->ethtool_ops
->get_link_ksettings
)
651 /* handle bitmap nbits handshake */
652 if (copy_from_user(&link_ksettings
.base
, useraddr
,
653 sizeof(link_ksettings
.base
)))
656 if (__ETHTOOL_LINK_MODE_MASK_NU32
657 != link_ksettings
.base
.link_mode_masks_nwords
) {
658 /* wrong link mode nbits requested */
659 memset(&link_ksettings
, 0, sizeof(link_ksettings
));
660 link_ksettings
.base
.cmd
= ETHTOOL_GLINKSETTINGS
;
661 /* send back number of words required as negative val */
662 compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32
<= S8_MAX
,
663 "need too many bits for link modes!");
664 link_ksettings
.base
.link_mode_masks_nwords
665 = -((s8
)__ETHTOOL_LINK_MODE_MASK_NU32
);
667 /* copy the base fields back to user, not the link
670 if (copy_to_user(useraddr
, &link_ksettings
.base
,
671 sizeof(link_ksettings
.base
)))
677 /* handshake successful: user/kernel agree on
678 * link_mode_masks_nwords
681 memset(&link_ksettings
, 0, sizeof(link_ksettings
));
682 err
= dev
->ethtool_ops
->get_link_ksettings(dev
, &link_ksettings
);
686 /* make sure we tell the right values to user */
687 link_ksettings
.base
.cmd
= ETHTOOL_GLINKSETTINGS
;
688 link_ksettings
.base
.link_mode_masks_nwords
689 = __ETHTOOL_LINK_MODE_MASK_NU32
;
691 return store_link_ksettings_for_user(useraddr
, &link_ksettings
);
694 /* Update device ethtool_link_settings.
696 * Backward compatibility note: this function must fail when driver
697 * does not implement ethtool::set_link_ksettings, even if legacy
698 * ethtool_ops::set_settings is implemented. This tells new versions
699 * of ethtool that they should use the legacy API %ETHTOOL_SSET for
700 * this driver, so that they can correctly update the ethtool_cmd
701 * deprecated fields (transceiver/maxrxpkt/maxtxpkt), until no driver
702 * implements ethtool_ops::get_settings anymore.
704 static int ethtool_set_link_ksettings(struct net_device
*dev
,
705 void __user
*useraddr
)
708 struct ethtool_link_ksettings link_ksettings
;
712 if (!dev
->ethtool_ops
->set_link_ksettings
)
715 /* make sure nbits field has expected value */
716 if (copy_from_user(&link_ksettings
.base
, useraddr
,
717 sizeof(link_ksettings
.base
)))
720 if (__ETHTOOL_LINK_MODE_MASK_NU32
721 != link_ksettings
.base
.link_mode_masks_nwords
)
724 /* copy the whole structure, now that we know it has expected
727 err
= load_link_ksettings_from_user(&link_ksettings
, useraddr
);
731 /* re-check nwords field, just in case */
732 if (__ETHTOOL_LINK_MODE_MASK_NU32
733 != link_ksettings
.base
.link_mode_masks_nwords
)
736 return dev
->ethtool_ops
->set_link_ksettings(dev
, &link_ksettings
);
740 warn_incomplete_ethtool_legacy_settings_conversion(const char *details
)
742 char name
[sizeof(current
->comm
)];
744 pr_info_once("warning: `%s' uses legacy ethtool link settings API, %s\n",
745 get_task_comm(name
, current
), details
);
748 /* Query device for its ethtool_cmd settings.
750 * Backward compatibility note: for compatibility with legacy ethtool,
751 * this has to work with both drivers implementing get_link_ksettings
752 * API and drivers implementing get_settings API. When drivers
753 * implement get_link_ksettings and report higher link mode bits, a
754 * kernel warning is logged once (with name of 1st driver/device) to
755 * recommend user to upgrade ethtool, but the command is successful
756 * (only the lower link mode bits reported back to user).
758 static int ethtool_get_settings(struct net_device
*dev
, void __user
*useraddr
)
760 struct ethtool_cmd cmd
;
764 if (dev
->ethtool_ops
->get_link_ksettings
) {
765 /* First, use link_ksettings API if it is supported */
767 struct ethtool_link_ksettings link_ksettings
;
769 memset(&link_ksettings
, 0, sizeof(link_ksettings
));
770 err
= dev
->ethtool_ops
->get_link_ksettings(dev
,
774 if (!convert_link_ksettings_to_legacy_settings(&cmd
,
776 warn_incomplete_ethtool_legacy_settings_conversion(
777 "link modes are only partially reported");
779 /* send a sensible cmd tag back to user */
780 cmd
.cmd
= ETHTOOL_GSET
;
782 /* driver doesn't support %ethtool_link_ksettings
783 * API. revert to legacy %ethtool_cmd API, unless it's
784 * not supported either.
788 if (!dev
->ethtool_ops
->get_settings
)
791 memset(&cmd
, 0, sizeof(cmd
));
792 cmd
.cmd
= ETHTOOL_GSET
;
793 err
= dev
->ethtool_ops
->get_settings(dev
, &cmd
);
798 if (copy_to_user(useraddr
, &cmd
, sizeof(cmd
)))
804 /* Update device link settings with given ethtool_cmd.
806 * Backward compatibility note: for compatibility with legacy ethtool,
807 * this has to work with both drivers implementing set_link_ksettings
808 * API and drivers implementing set_settings API. When drivers
809 * implement set_link_ksettings and user's request updates deprecated
810 * ethtool_cmd fields (transceiver/maxrxpkt/maxtxpkt), a kernel
811 * warning is logged once (with name of 1st driver/device) to
812 * recommend user to upgrade ethtool, and the request is rejected.
814 static int ethtool_set_settings(struct net_device
*dev
, void __user
*useraddr
)
816 struct ethtool_cmd cmd
;
820 if (copy_from_user(&cmd
, useraddr
, sizeof(cmd
)))
823 /* first, try new %ethtool_link_ksettings API. */
824 if (dev
->ethtool_ops
->set_link_ksettings
) {
825 struct ethtool_link_ksettings link_ksettings
;
827 if (!convert_legacy_settings_to_link_ksettings(&link_ksettings
,
831 link_ksettings
.base
.cmd
= ETHTOOL_SLINKSETTINGS
;
832 link_ksettings
.base
.link_mode_masks_nwords
833 = __ETHTOOL_LINK_MODE_MASK_NU32
;
834 return dev
->ethtool_ops
->set_link_ksettings(dev
,
838 /* legacy %ethtool_cmd API */
840 /* TODO: return -EOPNOTSUPP when ethtool_ops::get_settings
841 * disappears internally
844 if (!dev
->ethtool_ops
->set_settings
)
847 return dev
->ethtool_ops
->set_settings(dev
, &cmd
);
850 static noinline_for_stack
int ethtool_get_drvinfo(struct net_device
*dev
,
851 void __user
*useraddr
)
853 struct ethtool_drvinfo info
;
854 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
856 memset(&info
, 0, sizeof(info
));
857 info
.cmd
= ETHTOOL_GDRVINFO
;
858 if (ops
->get_drvinfo
) {
859 ops
->get_drvinfo(dev
, &info
);
860 } else if (dev
->dev
.parent
&& dev
->dev
.parent
->driver
) {
861 strlcpy(info
.bus_info
, dev_name(dev
->dev
.parent
),
862 sizeof(info
.bus_info
));
863 strlcpy(info
.driver
, dev
->dev
.parent
->driver
->name
,
864 sizeof(info
.driver
));
870 * this method of obtaining string set info is deprecated;
871 * Use ETHTOOL_GSSET_INFO instead.
873 if (ops
->get_sset_count
) {
876 rc
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
878 info
.testinfo_len
= rc
;
879 rc
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
882 rc
= ops
->get_sset_count(dev
, ETH_SS_PRIV_FLAGS
);
884 info
.n_priv_flags
= rc
;
886 if (ops
->get_regs_len
)
887 info
.regdump_len
= ops
->get_regs_len(dev
);
888 if (ops
->get_eeprom_len
)
889 info
.eedump_len
= ops
->get_eeprom_len(dev
);
891 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
896 static noinline_for_stack
int ethtool_get_sset_info(struct net_device
*dev
,
897 void __user
*useraddr
)
899 struct ethtool_sset_info info
;
901 int i
, idx
= 0, n_bits
= 0, ret
, rc
;
902 u32
*info_buf
= NULL
;
904 if (copy_from_user(&info
, useraddr
, sizeof(info
)))
907 /* store copy of mask, because we zero struct later on */
908 sset_mask
= info
.sset_mask
;
912 /* calculate size of return buffer */
913 n_bits
= hweight64(sset_mask
);
915 memset(&info
, 0, sizeof(info
));
916 info
.cmd
= ETHTOOL_GSSET_INFO
;
918 info_buf
= kzalloc(n_bits
* sizeof(u32
), GFP_USER
);
923 * fill return buffer based on input bitmask and successful
924 * get_sset_count return
926 for (i
= 0; i
< 64; i
++) {
927 if (!(sset_mask
& (1ULL << i
)))
930 rc
= __ethtool_get_sset_count(dev
, i
);
932 info
.sset_mask
|= (1ULL << i
);
933 info_buf
[idx
++] = rc
;
938 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
941 useraddr
+= offsetof(struct ethtool_sset_info
, data
);
942 if (copy_to_user(useraddr
, info_buf
, idx
* sizeof(u32
)))
952 static noinline_for_stack
int ethtool_set_rxnfc(struct net_device
*dev
,
953 u32 cmd
, void __user
*useraddr
)
955 struct ethtool_rxnfc info
;
956 size_t info_size
= sizeof(info
);
959 if (!dev
->ethtool_ops
->set_rxnfc
)
962 /* struct ethtool_rxnfc was originally defined for
963 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
964 * members. User-space might still be using that
966 if (cmd
== ETHTOOL_SRXFH
)
967 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
970 if (copy_from_user(&info
, useraddr
, info_size
))
973 rc
= dev
->ethtool_ops
->set_rxnfc(dev
, &info
);
977 if (cmd
== ETHTOOL_SRXCLSRLINS
&&
978 copy_to_user(useraddr
, &info
, info_size
))
984 static noinline_for_stack
int ethtool_get_rxnfc(struct net_device
*dev
,
985 u32 cmd
, void __user
*useraddr
)
987 struct ethtool_rxnfc info
;
988 size_t info_size
= sizeof(info
);
989 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
991 void *rule_buf
= NULL
;
996 /* struct ethtool_rxnfc was originally defined for
997 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
998 * members. User-space might still be using that
1000 if (cmd
== ETHTOOL_GRXFH
)
1001 info_size
= (offsetof(struct ethtool_rxnfc
, data
) +
1004 if (copy_from_user(&info
, useraddr
, info_size
))
1007 if (info
.cmd
== ETHTOOL_GRXCLSRLALL
) {
1008 if (info
.rule_cnt
> 0) {
1009 if (info
.rule_cnt
<= KMALLOC_MAX_SIZE
/ sizeof(u32
))
1010 rule_buf
= kzalloc(info
.rule_cnt
* sizeof(u32
),
1017 ret
= ops
->get_rxnfc(dev
, &info
, rule_buf
);
1022 if (copy_to_user(useraddr
, &info
, info_size
))
1026 useraddr
+= offsetof(struct ethtool_rxnfc
, rule_locs
);
1027 if (copy_to_user(useraddr
, rule_buf
,
1028 info
.rule_cnt
* sizeof(u32
)))
1039 static int ethtool_copy_validate_indir(u32
*indir
, void __user
*useraddr
,
1040 struct ethtool_rxnfc
*rx_rings
,
1045 if (copy_from_user(indir
, useraddr
, size
* sizeof(indir
[0])))
1048 /* Validate ring indices */
1049 for (i
= 0; i
< size
; i
++)
1050 if (indir
[i
] >= rx_rings
->data
)
1056 u8 netdev_rss_key
[NETDEV_RSS_KEY_LEN
] __read_mostly
;
1058 void netdev_rss_key_fill(void *buffer
, size_t len
)
1060 BUG_ON(len
> sizeof(netdev_rss_key
));
1061 net_get_random_once(netdev_rss_key
, sizeof(netdev_rss_key
));
1062 memcpy(buffer
, netdev_rss_key
, len
);
1064 EXPORT_SYMBOL(netdev_rss_key_fill
);
1066 static int ethtool_get_max_rxfh_channel(struct net_device
*dev
, u32
*max
)
1068 u32 dev_size
, current_max
= 0;
1072 if (!dev
->ethtool_ops
->get_rxfh_indir_size
||
1073 !dev
->ethtool_ops
->get_rxfh
)
1075 dev_size
= dev
->ethtool_ops
->get_rxfh_indir_size(dev
);
1079 indir
= kcalloc(dev_size
, sizeof(indir
[0]), GFP_USER
);
1083 ret
= dev
->ethtool_ops
->get_rxfh(dev
, indir
, NULL
, NULL
);
1088 current_max
= max(current_max
, indir
[dev_size
]);
1097 static noinline_for_stack
int ethtool_get_rxfh_indir(struct net_device
*dev
,
1098 void __user
*useraddr
)
1100 u32 user_size
, dev_size
;
1104 if (!dev
->ethtool_ops
->get_rxfh_indir_size
||
1105 !dev
->ethtool_ops
->get_rxfh
)
1107 dev_size
= dev
->ethtool_ops
->get_rxfh_indir_size(dev
);
1111 if (copy_from_user(&user_size
,
1112 useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
1116 if (copy_to_user(useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
1117 &dev_size
, sizeof(dev_size
)))
1120 /* If the user buffer size is 0, this is just a query for the
1121 * device table size. Otherwise, if it's smaller than the
1122 * device table size it's an error.
1124 if (user_size
< dev_size
)
1125 return user_size
== 0 ? 0 : -EINVAL
;
1127 indir
= kcalloc(dev_size
, sizeof(indir
[0]), GFP_USER
);
1131 ret
= dev
->ethtool_ops
->get_rxfh(dev
, indir
, NULL
, NULL
);
1135 if (copy_to_user(useraddr
+
1136 offsetof(struct ethtool_rxfh_indir
, ring_index
[0]),
1137 indir
, dev_size
* sizeof(indir
[0])))
1145 static noinline_for_stack
int ethtool_set_rxfh_indir(struct net_device
*dev
,
1146 void __user
*useraddr
)
1148 struct ethtool_rxnfc rx_rings
;
1149 u32 user_size
, dev_size
, i
;
1151 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1153 u32 ringidx_offset
= offsetof(struct ethtool_rxfh_indir
, ring_index
[0]);
1155 if (!ops
->get_rxfh_indir_size
|| !ops
->set_rxfh
||
1159 dev_size
= ops
->get_rxfh_indir_size(dev
);
1163 if (copy_from_user(&user_size
,
1164 useraddr
+ offsetof(struct ethtool_rxfh_indir
, size
),
1168 if (user_size
!= 0 && user_size
!= dev_size
)
1171 indir
= kcalloc(dev_size
, sizeof(indir
[0]), GFP_USER
);
1175 rx_rings
.cmd
= ETHTOOL_GRXRINGS
;
1176 ret
= ops
->get_rxnfc(dev
, &rx_rings
, NULL
);
1180 if (user_size
== 0) {
1181 for (i
= 0; i
< dev_size
; i
++)
1182 indir
[i
] = ethtool_rxfh_indir_default(i
, rx_rings
.data
);
1184 ret
= ethtool_copy_validate_indir(indir
,
1185 useraddr
+ ringidx_offset
,
1192 ret
= ops
->set_rxfh(dev
, indir
, NULL
, ETH_RSS_HASH_NO_CHANGE
);
1196 /* indicate whether rxfh was set to default */
1198 dev
->priv_flags
&= ~IFF_RXFH_CONFIGURED
;
1200 dev
->priv_flags
|= IFF_RXFH_CONFIGURED
;
1207 static noinline_for_stack
int ethtool_get_rxfh(struct net_device
*dev
,
1208 void __user
*useraddr
)
1211 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1212 u32 user_indir_size
, user_key_size
;
1213 u32 dev_indir_size
= 0, dev_key_size
= 0;
1214 struct ethtool_rxfh rxfh
;
1225 if (ops
->get_rxfh_indir_size
)
1226 dev_indir_size
= ops
->get_rxfh_indir_size(dev
);
1227 if (ops
->get_rxfh_key_size
)
1228 dev_key_size
= ops
->get_rxfh_key_size(dev
);
1230 if (copy_from_user(&rxfh
, useraddr
, sizeof(rxfh
)))
1232 user_indir_size
= rxfh
.indir_size
;
1233 user_key_size
= rxfh
.key_size
;
1235 /* Check that reserved fields are 0 for now */
1236 if (rxfh
.rss_context
|| rxfh
.rsvd8
[0] || rxfh
.rsvd8
[1] ||
1237 rxfh
.rsvd8
[2] || rxfh
.rsvd32
)
1240 rxfh
.indir_size
= dev_indir_size
;
1241 rxfh
.key_size
= dev_key_size
;
1242 if (copy_to_user(useraddr
, &rxfh
, sizeof(rxfh
)))
1245 if ((user_indir_size
&& (user_indir_size
!= dev_indir_size
)) ||
1246 (user_key_size
&& (user_key_size
!= dev_key_size
)))
1249 indir_bytes
= user_indir_size
* sizeof(indir
[0]);
1250 total_size
= indir_bytes
+ user_key_size
;
1251 rss_config
= kzalloc(total_size
, GFP_USER
);
1255 if (user_indir_size
)
1256 indir
= (u32
*)rss_config
;
1259 hkey
= rss_config
+ indir_bytes
;
1261 ret
= dev
->ethtool_ops
->get_rxfh(dev
, indir
, hkey
, &dev_hfunc
);
1265 if (copy_to_user(useraddr
+ offsetof(struct ethtool_rxfh
, hfunc
),
1266 &dev_hfunc
, sizeof(rxfh
.hfunc
))) {
1268 } else if (copy_to_user(useraddr
+
1269 offsetof(struct ethtool_rxfh
, rss_config
[0]),
1270 rss_config
, total_size
)) {
1279 static noinline_for_stack
int ethtool_set_rxfh(struct net_device
*dev
,
1280 void __user
*useraddr
)
1283 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1284 struct ethtool_rxnfc rx_rings
;
1285 struct ethtool_rxfh rxfh
;
1286 u32 dev_indir_size
= 0, dev_key_size
= 0, i
;
1287 u32
*indir
= NULL
, indir_bytes
= 0;
1290 u32 rss_cfg_offset
= offsetof(struct ethtool_rxfh
, rss_config
[0]);
1292 if (!ops
->get_rxnfc
|| !ops
->set_rxfh
)
1295 if (ops
->get_rxfh_indir_size
)
1296 dev_indir_size
= ops
->get_rxfh_indir_size(dev
);
1297 if (ops
->get_rxfh_key_size
)
1298 dev_key_size
= ops
->get_rxfh_key_size(dev
);
1300 if (copy_from_user(&rxfh
, useraddr
, sizeof(rxfh
)))
1303 /* Check that reserved fields are 0 for now */
1304 if (rxfh
.rss_context
|| rxfh
.rsvd8
[0] || rxfh
.rsvd8
[1] ||
1305 rxfh
.rsvd8
[2] || rxfh
.rsvd32
)
1308 /* If either indir, hash key or function is valid, proceed further.
1309 * Must request at least one change: indir size, hash key or function.
1311 if ((rxfh
.indir_size
&&
1312 rxfh
.indir_size
!= ETH_RXFH_INDIR_NO_CHANGE
&&
1313 rxfh
.indir_size
!= dev_indir_size
) ||
1314 (rxfh
.key_size
&& (rxfh
.key_size
!= dev_key_size
)) ||
1315 (rxfh
.indir_size
== ETH_RXFH_INDIR_NO_CHANGE
&&
1316 rxfh
.key_size
== 0 && rxfh
.hfunc
== ETH_RSS_HASH_NO_CHANGE
))
1319 if (rxfh
.indir_size
!= ETH_RXFH_INDIR_NO_CHANGE
)
1320 indir_bytes
= dev_indir_size
* sizeof(indir
[0]);
1322 rss_config
= kzalloc(indir_bytes
+ rxfh
.key_size
, GFP_USER
);
1326 rx_rings
.cmd
= ETHTOOL_GRXRINGS
;
1327 ret
= ops
->get_rxnfc(dev
, &rx_rings
, NULL
);
1331 /* rxfh.indir_size == 0 means reset the indir table to default.
1332 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
1334 if (rxfh
.indir_size
&&
1335 rxfh
.indir_size
!= ETH_RXFH_INDIR_NO_CHANGE
) {
1336 indir
= (u32
*)rss_config
;
1337 ret
= ethtool_copy_validate_indir(indir
,
1338 useraddr
+ rss_cfg_offset
,
1343 } else if (rxfh
.indir_size
== 0) {
1344 indir
= (u32
*)rss_config
;
1345 for (i
= 0; i
< dev_indir_size
; i
++)
1346 indir
[i
] = ethtool_rxfh_indir_default(i
, rx_rings
.data
);
1349 if (rxfh
.key_size
) {
1350 hkey
= rss_config
+ indir_bytes
;
1351 if (copy_from_user(hkey
,
1352 useraddr
+ rss_cfg_offset
+ indir_bytes
,
1359 ret
= ops
->set_rxfh(dev
, indir
, hkey
, rxfh
.hfunc
);
1363 /* indicate whether rxfh was set to default */
1364 if (rxfh
.indir_size
== 0)
1365 dev
->priv_flags
&= ~IFF_RXFH_CONFIGURED
;
1366 else if (rxfh
.indir_size
!= ETH_RXFH_INDIR_NO_CHANGE
)
1367 dev
->priv_flags
|= IFF_RXFH_CONFIGURED
;
1374 static int ethtool_get_regs(struct net_device
*dev
, char __user
*useraddr
)
1376 struct ethtool_regs regs
;
1377 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1381 if (!ops
->get_regs
|| !ops
->get_regs_len
)
1384 if (copy_from_user(®s
, useraddr
, sizeof(regs
)))
1387 reglen
= ops
->get_regs_len(dev
);
1388 if (regs
.len
> reglen
)
1391 regbuf
= vzalloc(reglen
);
1392 if (reglen
&& !regbuf
)
1395 ops
->get_regs(dev
, ®s
, regbuf
);
1398 if (copy_to_user(useraddr
, ®s
, sizeof(regs
)))
1400 useraddr
+= offsetof(struct ethtool_regs
, data
);
1401 if (regbuf
&& copy_to_user(useraddr
, regbuf
, regs
.len
))
1410 static int ethtool_reset(struct net_device
*dev
, char __user
*useraddr
)
1412 struct ethtool_value reset
;
1415 if (!dev
->ethtool_ops
->reset
)
1418 if (copy_from_user(&reset
, useraddr
, sizeof(reset
)))
1421 ret
= dev
->ethtool_ops
->reset(dev
, &reset
.data
);
1425 if (copy_to_user(useraddr
, &reset
, sizeof(reset
)))
1430 static int ethtool_get_wol(struct net_device
*dev
, char __user
*useraddr
)
1432 struct ethtool_wolinfo wol
= { .cmd
= ETHTOOL_GWOL
};
1434 if (!dev
->ethtool_ops
->get_wol
)
1437 dev
->ethtool_ops
->get_wol(dev
, &wol
);
1439 if (copy_to_user(useraddr
, &wol
, sizeof(wol
)))
1444 static int ethtool_set_wol(struct net_device
*dev
, char __user
*useraddr
)
1446 struct ethtool_wolinfo wol
;
1448 if (!dev
->ethtool_ops
->set_wol
)
1451 if (copy_from_user(&wol
, useraddr
, sizeof(wol
)))
1454 return dev
->ethtool_ops
->set_wol(dev
, &wol
);
1457 static int ethtool_get_eee(struct net_device
*dev
, char __user
*useraddr
)
1459 struct ethtool_eee edata
;
1462 if (!dev
->ethtool_ops
->get_eee
)
1465 memset(&edata
, 0, sizeof(struct ethtool_eee
));
1466 edata
.cmd
= ETHTOOL_GEEE
;
1467 rc
= dev
->ethtool_ops
->get_eee(dev
, &edata
);
1472 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1478 static int ethtool_set_eee(struct net_device
*dev
, char __user
*useraddr
)
1480 struct ethtool_eee edata
;
1482 if (!dev
->ethtool_ops
->set_eee
)
1485 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1488 return dev
->ethtool_ops
->set_eee(dev
, &edata
);
1491 static int ethtool_nway_reset(struct net_device
*dev
)
1493 if (!dev
->ethtool_ops
->nway_reset
)
1496 return dev
->ethtool_ops
->nway_reset(dev
);
1499 static int ethtool_get_link(struct net_device
*dev
, char __user
*useraddr
)
1501 struct ethtool_value edata
= { .cmd
= ETHTOOL_GLINK
};
1503 if (!dev
->ethtool_ops
->get_link
)
1506 edata
.data
= netif_running(dev
) && dev
->ethtool_ops
->get_link(dev
);
1508 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1513 static int ethtool_get_any_eeprom(struct net_device
*dev
, void __user
*useraddr
,
1514 int (*getter
)(struct net_device
*,
1515 struct ethtool_eeprom
*, u8
*),
1518 struct ethtool_eeprom eeprom
;
1519 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1520 u32 bytes_remaining
;
1524 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1527 /* Check for wrap and zero */
1528 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1531 /* Check for exceeding total eeprom len */
1532 if (eeprom
.offset
+ eeprom
.len
> total_len
)
1535 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1539 bytes_remaining
= eeprom
.len
;
1540 while (bytes_remaining
> 0) {
1541 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1543 ret
= getter(dev
, &eeprom
, data
);
1546 if (copy_to_user(userbuf
, data
, eeprom
.len
)) {
1550 userbuf
+= eeprom
.len
;
1551 eeprom
.offset
+= eeprom
.len
;
1552 bytes_remaining
-= eeprom
.len
;
1555 eeprom
.len
= userbuf
- (useraddr
+ sizeof(eeprom
));
1556 eeprom
.offset
-= eeprom
.len
;
1557 if (copy_to_user(useraddr
, &eeprom
, sizeof(eeprom
)))
1564 static int ethtool_get_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1566 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1568 if (!ops
->get_eeprom
|| !ops
->get_eeprom_len
||
1569 !ops
->get_eeprom_len(dev
))
1572 return ethtool_get_any_eeprom(dev
, useraddr
, ops
->get_eeprom
,
1573 ops
->get_eeprom_len(dev
));
1576 static int ethtool_set_eeprom(struct net_device
*dev
, void __user
*useraddr
)
1578 struct ethtool_eeprom eeprom
;
1579 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1580 void __user
*userbuf
= useraddr
+ sizeof(eeprom
);
1581 u32 bytes_remaining
;
1585 if (!ops
->set_eeprom
|| !ops
->get_eeprom_len
||
1586 !ops
->get_eeprom_len(dev
))
1589 if (copy_from_user(&eeprom
, useraddr
, sizeof(eeprom
)))
1592 /* Check for wrap and zero */
1593 if (eeprom
.offset
+ eeprom
.len
<= eeprom
.offset
)
1596 /* Check for exceeding total eeprom len */
1597 if (eeprom
.offset
+ eeprom
.len
> ops
->get_eeprom_len(dev
))
1600 data
= kmalloc(PAGE_SIZE
, GFP_USER
);
1604 bytes_remaining
= eeprom
.len
;
1605 while (bytes_remaining
> 0) {
1606 eeprom
.len
= min(bytes_remaining
, (u32
)PAGE_SIZE
);
1608 if (copy_from_user(data
, userbuf
, eeprom
.len
)) {
1612 ret
= ops
->set_eeprom(dev
, &eeprom
, data
);
1615 userbuf
+= eeprom
.len
;
1616 eeprom
.offset
+= eeprom
.len
;
1617 bytes_remaining
-= eeprom
.len
;
1624 static noinline_for_stack
int ethtool_get_coalesce(struct net_device
*dev
,
1625 void __user
*useraddr
)
1627 struct ethtool_coalesce coalesce
= { .cmd
= ETHTOOL_GCOALESCE
};
1629 if (!dev
->ethtool_ops
->get_coalesce
)
1632 dev
->ethtool_ops
->get_coalesce(dev
, &coalesce
);
1634 if (copy_to_user(useraddr
, &coalesce
, sizeof(coalesce
)))
1639 static noinline_for_stack
int ethtool_set_coalesce(struct net_device
*dev
,
1640 void __user
*useraddr
)
1642 struct ethtool_coalesce coalesce
;
1644 if (!dev
->ethtool_ops
->set_coalesce
)
1647 if (copy_from_user(&coalesce
, useraddr
, sizeof(coalesce
)))
1650 return dev
->ethtool_ops
->set_coalesce(dev
, &coalesce
);
1653 static int ethtool_get_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1655 struct ethtool_ringparam ringparam
= { .cmd
= ETHTOOL_GRINGPARAM
};
1657 if (!dev
->ethtool_ops
->get_ringparam
)
1660 dev
->ethtool_ops
->get_ringparam(dev
, &ringparam
);
1662 if (copy_to_user(useraddr
, &ringparam
, sizeof(ringparam
)))
1667 static int ethtool_set_ringparam(struct net_device
*dev
, void __user
*useraddr
)
1669 struct ethtool_ringparam ringparam
;
1671 if (!dev
->ethtool_ops
->set_ringparam
)
1674 if (copy_from_user(&ringparam
, useraddr
, sizeof(ringparam
)))
1677 return dev
->ethtool_ops
->set_ringparam(dev
, &ringparam
);
1680 static noinline_for_stack
int ethtool_get_channels(struct net_device
*dev
,
1681 void __user
*useraddr
)
1683 struct ethtool_channels channels
= { .cmd
= ETHTOOL_GCHANNELS
};
1685 if (!dev
->ethtool_ops
->get_channels
)
1688 dev
->ethtool_ops
->get_channels(dev
, &channels
);
1690 if (copy_to_user(useraddr
, &channels
, sizeof(channels
)))
1695 static noinline_for_stack
int ethtool_set_channels(struct net_device
*dev
,
1696 void __user
*useraddr
)
1698 struct ethtool_channels channels
, max
;
1699 u32 max_rx_in_use
= 0;
1701 if (!dev
->ethtool_ops
->set_channels
|| !dev
->ethtool_ops
->get_channels
)
1704 if (copy_from_user(&channels
, useraddr
, sizeof(channels
)))
1707 dev
->ethtool_ops
->get_channels(dev
, &max
);
1709 /* ensure new counts are within the maximums */
1710 if ((channels
.rx_count
> max
.max_rx
) ||
1711 (channels
.tx_count
> max
.max_tx
) ||
1712 (channels
.combined_count
> max
.max_combined
) ||
1713 (channels
.other_count
> max
.max_other
))
1716 /* ensure the new Rx count fits within the configured Rx flow
1717 * indirection table settings */
1718 if (netif_is_rxfh_configured(dev
) &&
1719 !ethtool_get_max_rxfh_channel(dev
, &max_rx_in_use
) &&
1720 (channels
.combined_count
+ channels
.rx_count
) <= max_rx_in_use
)
1723 return dev
->ethtool_ops
->set_channels(dev
, &channels
);
1726 static int ethtool_get_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1728 struct ethtool_pauseparam pauseparam
= { ETHTOOL_GPAUSEPARAM
};
1730 if (!dev
->ethtool_ops
->get_pauseparam
)
1733 dev
->ethtool_ops
->get_pauseparam(dev
, &pauseparam
);
1735 if (copy_to_user(useraddr
, &pauseparam
, sizeof(pauseparam
)))
1740 static int ethtool_set_pauseparam(struct net_device
*dev
, void __user
*useraddr
)
1742 struct ethtool_pauseparam pauseparam
;
1744 if (!dev
->ethtool_ops
->set_pauseparam
)
1747 if (copy_from_user(&pauseparam
, useraddr
, sizeof(pauseparam
)))
1750 return dev
->ethtool_ops
->set_pauseparam(dev
, &pauseparam
);
1753 static int ethtool_self_test(struct net_device
*dev
, char __user
*useraddr
)
1755 struct ethtool_test test
;
1756 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1760 if (!ops
->self_test
|| !ops
->get_sset_count
)
1763 test_len
= ops
->get_sset_count(dev
, ETH_SS_TEST
);
1766 WARN_ON(test_len
== 0);
1768 if (copy_from_user(&test
, useraddr
, sizeof(test
)))
1771 test
.len
= test_len
;
1772 data
= kmalloc(test_len
* sizeof(u64
), GFP_USER
);
1776 ops
->self_test(dev
, &test
, data
);
1779 if (copy_to_user(useraddr
, &test
, sizeof(test
)))
1781 useraddr
+= sizeof(test
);
1782 if (copy_to_user(useraddr
, data
, test
.len
* sizeof(u64
)))
1791 static int ethtool_get_strings(struct net_device
*dev
, void __user
*useraddr
)
1793 struct ethtool_gstrings gstrings
;
1797 if (copy_from_user(&gstrings
, useraddr
, sizeof(gstrings
)))
1800 ret
= __ethtool_get_sset_count(dev
, gstrings
.string_set
);
1806 data
= kcalloc(gstrings
.len
, ETH_GSTRING_LEN
, GFP_USER
);
1810 __ethtool_get_strings(dev
, gstrings
.string_set
, data
);
1813 if (copy_to_user(useraddr
, &gstrings
, sizeof(gstrings
)))
1815 useraddr
+= sizeof(gstrings
);
1816 if (copy_to_user(useraddr
, data
, gstrings
.len
* ETH_GSTRING_LEN
))
1825 static int ethtool_phys_id(struct net_device
*dev
, void __user
*useraddr
)
1827 struct ethtool_value id
;
1829 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1832 if (!ops
->set_phys_id
)
1838 if (copy_from_user(&id
, useraddr
, sizeof(id
)))
1841 rc
= ops
->set_phys_id(dev
, ETHTOOL_ID_ACTIVE
);
1845 /* Drop the RTNL lock while waiting, but prevent reentry or
1846 * removal of the device.
1853 /* Driver will handle this itself */
1854 schedule_timeout_interruptible(
1855 id
.data
? (id
.data
* HZ
) : MAX_SCHEDULE_TIMEOUT
);
1857 /* Driver expects to be called at twice the frequency in rc */
1858 int n
= rc
* 2, i
, interval
= HZ
/ n
;
1860 /* Count down seconds */
1862 /* Count down iterations per second */
1866 rc
= ops
->set_phys_id(dev
,
1867 (i
& 1) ? ETHTOOL_ID_OFF
: ETHTOOL_ID_ON
);
1871 schedule_timeout_interruptible(interval
);
1872 } while (!signal_pending(current
) && --i
!= 0);
1873 } while (!signal_pending(current
) &&
1874 (id
.data
== 0 || --id
.data
!= 0));
1881 (void) ops
->set_phys_id(dev
, ETHTOOL_ID_INACTIVE
);
1885 static int ethtool_get_stats(struct net_device
*dev
, void __user
*useraddr
)
1887 struct ethtool_stats stats
;
1888 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
1892 if (!ops
->get_ethtool_stats
|| !ops
->get_sset_count
)
1895 n_stats
= ops
->get_sset_count(dev
, ETH_SS_STATS
);
1898 WARN_ON(n_stats
== 0);
1900 if (copy_from_user(&stats
, useraddr
, sizeof(stats
)))
1903 stats
.n_stats
= n_stats
;
1904 data
= kmalloc(n_stats
* sizeof(u64
), GFP_USER
);
1908 ops
->get_ethtool_stats(dev
, &stats
, data
);
1911 if (copy_to_user(useraddr
, &stats
, sizeof(stats
)))
1913 useraddr
+= sizeof(stats
);
1914 if (copy_to_user(useraddr
, data
, stats
.n_stats
* sizeof(u64
)))
1923 static int ethtool_get_phy_stats(struct net_device
*dev
, void __user
*useraddr
)
1925 struct ethtool_stats stats
;
1926 struct phy_device
*phydev
= dev
->phydev
;
1933 n_stats
= phy_get_sset_count(phydev
);
1937 WARN_ON(n_stats
== 0);
1939 if (copy_from_user(&stats
, useraddr
, sizeof(stats
)))
1942 stats
.n_stats
= n_stats
;
1943 data
= kmalloc_array(n_stats
, sizeof(u64
), GFP_USER
);
1947 mutex_lock(&phydev
->lock
);
1948 phydev
->drv
->get_stats(phydev
, &stats
, data
);
1949 mutex_unlock(&phydev
->lock
);
1952 if (copy_to_user(useraddr
, &stats
, sizeof(stats
)))
1954 useraddr
+= sizeof(stats
);
1955 if (copy_to_user(useraddr
, data
, stats
.n_stats
* sizeof(u64
)))
1964 static int ethtool_get_perm_addr(struct net_device
*dev
, void __user
*useraddr
)
1966 struct ethtool_perm_addr epaddr
;
1968 if (copy_from_user(&epaddr
, useraddr
, sizeof(epaddr
)))
1971 if (epaddr
.size
< dev
->addr_len
)
1973 epaddr
.size
= dev
->addr_len
;
1975 if (copy_to_user(useraddr
, &epaddr
, sizeof(epaddr
)))
1977 useraddr
+= sizeof(epaddr
);
1978 if (copy_to_user(useraddr
, dev
->perm_addr
, epaddr
.size
))
1983 static int ethtool_get_value(struct net_device
*dev
, char __user
*useraddr
,
1984 u32 cmd
, u32 (*actor
)(struct net_device
*))
1986 struct ethtool_value edata
= { .cmd
= cmd
};
1991 edata
.data
= actor(dev
);
1993 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1998 static int ethtool_set_value_void(struct net_device
*dev
, char __user
*useraddr
,
1999 void (*actor
)(struct net_device
*, u32
))
2001 struct ethtool_value edata
;
2006 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
2009 actor(dev
, edata
.data
);
2013 static int ethtool_set_value(struct net_device
*dev
, char __user
*useraddr
,
2014 int (*actor
)(struct net_device
*, u32
))
2016 struct ethtool_value edata
;
2021 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
2024 return actor(dev
, edata
.data
);
2027 static noinline_for_stack
int ethtool_flash_device(struct net_device
*dev
,
2028 char __user
*useraddr
)
2030 struct ethtool_flash efl
;
2032 if (copy_from_user(&efl
, useraddr
, sizeof(efl
)))
2035 if (!dev
->ethtool_ops
->flash_device
)
2038 efl
.data
[ETHTOOL_FLASH_MAX_FILENAME
- 1] = 0;
2040 return dev
->ethtool_ops
->flash_device(dev
, &efl
);
2043 static int ethtool_set_dump(struct net_device
*dev
,
2044 void __user
*useraddr
)
2046 struct ethtool_dump dump
;
2048 if (!dev
->ethtool_ops
->set_dump
)
2051 if (copy_from_user(&dump
, useraddr
, sizeof(dump
)))
2054 return dev
->ethtool_ops
->set_dump(dev
, &dump
);
2057 static int ethtool_get_dump_flag(struct net_device
*dev
,
2058 void __user
*useraddr
)
2061 struct ethtool_dump dump
;
2062 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2064 if (!ops
->get_dump_flag
)
2067 if (copy_from_user(&dump
, useraddr
, sizeof(dump
)))
2070 ret
= ops
->get_dump_flag(dev
, &dump
);
2074 if (copy_to_user(useraddr
, &dump
, sizeof(dump
)))
2079 static int ethtool_get_dump_data(struct net_device
*dev
,
2080 void __user
*useraddr
)
2084 struct ethtool_dump dump
, tmp
;
2085 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2088 if (!ops
->get_dump_data
|| !ops
->get_dump_flag
)
2091 if (copy_from_user(&dump
, useraddr
, sizeof(dump
)))
2094 memset(&tmp
, 0, sizeof(tmp
));
2095 tmp
.cmd
= ETHTOOL_GET_DUMP_FLAG
;
2096 ret
= ops
->get_dump_flag(dev
, &tmp
);
2100 len
= min(tmp
.len
, dump
.len
);
2104 /* Don't ever let the driver think there's more space available
2105 * than it requested with .get_dump_flag().
2109 /* Always allocate enough space to hold the whole thing so that the
2110 * driver does not need to check the length and bother with partial
2113 data
= vzalloc(tmp
.len
);
2116 ret
= ops
->get_dump_data(dev
, &dump
, data
);
2120 /* There are two sane possibilities:
2121 * 1. The driver's .get_dump_data() does not touch dump.len.
2122 * 2. Or it may set dump.len to how much it really writes, which
2123 * should be tmp.len (or len if it can do a partial dump).
2124 * In any case respond to userspace with the actual length of data
2127 WARN_ON(dump
.len
!= len
&& dump
.len
!= tmp
.len
);
2130 if (copy_to_user(useraddr
, &dump
, sizeof(dump
))) {
2134 useraddr
+= offsetof(struct ethtool_dump
, data
);
2135 if (copy_to_user(useraddr
, data
, len
))
2142 static int ethtool_get_ts_info(struct net_device
*dev
, void __user
*useraddr
)
2145 struct ethtool_ts_info info
;
2146 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2147 struct phy_device
*phydev
= dev
->phydev
;
2149 memset(&info
, 0, sizeof(info
));
2150 info
.cmd
= ETHTOOL_GET_TS_INFO
;
2152 if (phydev
&& phydev
->drv
&& phydev
->drv
->ts_info
) {
2153 err
= phydev
->drv
->ts_info(phydev
, &info
);
2154 } else if (ops
->get_ts_info
) {
2155 err
= ops
->get_ts_info(dev
, &info
);
2157 info
.so_timestamping
=
2158 SOF_TIMESTAMPING_RX_SOFTWARE
|
2159 SOF_TIMESTAMPING_SOFTWARE
;
2160 info
.phc_index
= -1;
2166 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
2172 static int __ethtool_get_module_info(struct net_device
*dev
,
2173 struct ethtool_modinfo
*modinfo
)
2175 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2176 struct phy_device
*phydev
= dev
->phydev
;
2178 if (phydev
&& phydev
->drv
&& phydev
->drv
->module_info
)
2179 return phydev
->drv
->module_info(phydev
, modinfo
);
2181 if (ops
->get_module_info
)
2182 return ops
->get_module_info(dev
, modinfo
);
2187 static int ethtool_get_module_info(struct net_device
*dev
,
2188 void __user
*useraddr
)
2191 struct ethtool_modinfo modinfo
;
2193 if (copy_from_user(&modinfo
, useraddr
, sizeof(modinfo
)))
2196 ret
= __ethtool_get_module_info(dev
, &modinfo
);
2200 if (copy_to_user(useraddr
, &modinfo
, sizeof(modinfo
)))
2206 static int __ethtool_get_module_eeprom(struct net_device
*dev
,
2207 struct ethtool_eeprom
*ee
, u8
*data
)
2209 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2210 struct phy_device
*phydev
= dev
->phydev
;
2212 if (phydev
&& phydev
->drv
&& phydev
->drv
->module_eeprom
)
2213 return phydev
->drv
->module_eeprom(phydev
, ee
, data
);
2215 if (ops
->get_module_eeprom
)
2216 return ops
->get_module_eeprom(dev
, ee
, data
);
2221 static int ethtool_get_module_eeprom(struct net_device
*dev
,
2222 void __user
*useraddr
)
2225 struct ethtool_modinfo modinfo
;
2227 ret
= __ethtool_get_module_info(dev
, &modinfo
);
2231 return ethtool_get_any_eeprom(dev
, useraddr
,
2232 __ethtool_get_module_eeprom
,
2233 modinfo
.eeprom_len
);
2236 static int ethtool_tunable_valid(const struct ethtool_tunable
*tuna
)
2239 case ETHTOOL_RX_COPYBREAK
:
2240 case ETHTOOL_TX_COPYBREAK
:
2241 if (tuna
->len
!= sizeof(u32
) ||
2242 tuna
->type_id
!= ETHTOOL_TUNABLE_U32
)
2252 static int ethtool_get_tunable(struct net_device
*dev
, void __user
*useraddr
)
2255 struct ethtool_tunable tuna
;
2256 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2259 if (!ops
->get_tunable
)
2261 if (copy_from_user(&tuna
, useraddr
, sizeof(tuna
)))
2263 ret
= ethtool_tunable_valid(&tuna
);
2266 data
= kmalloc(tuna
.len
, GFP_USER
);
2269 ret
= ops
->get_tunable(dev
, &tuna
, data
);
2272 useraddr
+= sizeof(tuna
);
2274 if (copy_to_user(useraddr
, data
, tuna
.len
))
2283 static int ethtool_set_tunable(struct net_device
*dev
, void __user
*useraddr
)
2286 struct ethtool_tunable tuna
;
2287 const struct ethtool_ops
*ops
= dev
->ethtool_ops
;
2290 if (!ops
->set_tunable
)
2292 if (copy_from_user(&tuna
, useraddr
, sizeof(tuna
)))
2294 ret
= ethtool_tunable_valid(&tuna
);
2297 data
= kmalloc(tuna
.len
, GFP_USER
);
2300 useraddr
+= sizeof(tuna
);
2302 if (copy_from_user(data
, useraddr
, tuna
.len
))
2304 ret
= ops
->set_tunable(dev
, &tuna
, data
);
2311 static int ethtool_get_per_queue_coalesce(struct net_device
*dev
,
2312 void __user
*useraddr
,
2313 struct ethtool_per_queue_op
*per_queue_opt
)
2317 DECLARE_BITMAP(queue_mask
, MAX_NUM_QUEUE
);
2319 if (!dev
->ethtool_ops
->get_per_queue_coalesce
)
2322 useraddr
+= sizeof(*per_queue_opt
);
2324 bitmap_from_u32array(queue_mask
,
2326 per_queue_opt
->queue_mask
,
2327 DIV_ROUND_UP(MAX_NUM_QUEUE
, 32));
2329 for_each_set_bit(bit
, queue_mask
, MAX_NUM_QUEUE
) {
2330 struct ethtool_coalesce coalesce
= { .cmd
= ETHTOOL_GCOALESCE
};
2332 ret
= dev
->ethtool_ops
->get_per_queue_coalesce(dev
, bit
, &coalesce
);
2335 if (copy_to_user(useraddr
, &coalesce
, sizeof(coalesce
)))
2337 useraddr
+= sizeof(coalesce
);
2343 static int ethtool_set_per_queue_coalesce(struct net_device
*dev
,
2344 void __user
*useraddr
,
2345 struct ethtool_per_queue_op
*per_queue_opt
)
2350 struct ethtool_coalesce
*backup
= NULL
, *tmp
= NULL
;
2351 DECLARE_BITMAP(queue_mask
, MAX_NUM_QUEUE
);
2353 if ((!dev
->ethtool_ops
->set_per_queue_coalesce
) ||
2354 (!dev
->ethtool_ops
->get_per_queue_coalesce
))
2357 useraddr
+= sizeof(*per_queue_opt
);
2359 bitmap_from_u32array(queue_mask
,
2361 per_queue_opt
->queue_mask
,
2362 DIV_ROUND_UP(MAX_NUM_QUEUE
, 32));
2363 n_queue
= bitmap_weight(queue_mask
, MAX_NUM_QUEUE
);
2364 tmp
= backup
= kmalloc_array(n_queue
, sizeof(*backup
), GFP_KERNEL
);
2368 for_each_set_bit(bit
, queue_mask
, MAX_NUM_QUEUE
) {
2369 struct ethtool_coalesce coalesce
;
2371 ret
= dev
->ethtool_ops
->get_per_queue_coalesce(dev
, bit
, tmp
);
2377 if (copy_from_user(&coalesce
, useraddr
, sizeof(coalesce
))) {
2382 ret
= dev
->ethtool_ops
->set_per_queue_coalesce(dev
, bit
, &coalesce
);
2386 useraddr
+= sizeof(coalesce
);
2392 for_each_set_bit(i
, queue_mask
, bit
) {
2393 dev
->ethtool_ops
->set_per_queue_coalesce(dev
, i
, tmp
);
2402 static int ethtool_set_per_queue(struct net_device
*dev
, void __user
*useraddr
)
2404 struct ethtool_per_queue_op per_queue_opt
;
2406 if (copy_from_user(&per_queue_opt
, useraddr
, sizeof(per_queue_opt
)))
2409 switch (per_queue_opt
.sub_command
) {
2410 case ETHTOOL_GCOALESCE
:
2411 return ethtool_get_per_queue_coalesce(dev
, useraddr
, &per_queue_opt
);
2412 case ETHTOOL_SCOALESCE
:
2413 return ethtool_set_per_queue_coalesce(dev
, useraddr
, &per_queue_opt
);
2419 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
2421 int dev_ethtool(struct net
*net
, struct ifreq
*ifr
)
2423 struct net_device
*dev
= __dev_get_by_name(net
, ifr
->ifr_name
);
2424 void __user
*useraddr
= ifr
->ifr_data
;
2425 u32 ethcmd
, sub_cmd
;
2427 netdev_features_t old_features
;
2429 if (!dev
|| !netif_device_present(dev
))
2432 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
2435 if (ethcmd
== ETHTOOL_PERQUEUE
) {
2436 if (copy_from_user(&sub_cmd
, useraddr
+ sizeof(ethcmd
), sizeof(sub_cmd
)))
2441 /* Allow some commands to be done by anyone */
2444 case ETHTOOL_GDRVINFO
:
2445 case ETHTOOL_GMSGLVL
:
2447 case ETHTOOL_GCOALESCE
:
2448 case ETHTOOL_GRINGPARAM
:
2449 case ETHTOOL_GPAUSEPARAM
:
2450 case ETHTOOL_GRXCSUM
:
2451 case ETHTOOL_GTXCSUM
:
2453 case ETHTOOL_GSSET_INFO
:
2454 case ETHTOOL_GSTRINGS
:
2455 case ETHTOOL_GSTATS
:
2456 case ETHTOOL_GPHYSTATS
:
2458 case ETHTOOL_GPERMADDR
:
2462 case ETHTOOL_GFLAGS
:
2463 case ETHTOOL_GPFLAGS
:
2465 case ETHTOOL_GRXRINGS
:
2466 case ETHTOOL_GRXCLSRLCNT
:
2467 case ETHTOOL_GRXCLSRULE
:
2468 case ETHTOOL_GRXCLSRLALL
:
2469 case ETHTOOL_GRXFHINDIR
:
2471 case ETHTOOL_GFEATURES
:
2472 case ETHTOOL_GCHANNELS
:
2473 case ETHTOOL_GET_TS_INFO
:
2475 case ETHTOOL_GTUNABLE
:
2478 if (!ns_capable(net
->user_ns
, CAP_NET_ADMIN
))
2482 if (dev
->ethtool_ops
->begin
) {
2483 rc
= dev
->ethtool_ops
->begin(dev
);
2487 old_features
= dev
->features
;
2491 rc
= ethtool_get_settings(dev
, useraddr
);
2494 rc
= ethtool_set_settings(dev
, useraddr
);
2496 case ETHTOOL_GDRVINFO
:
2497 rc
= ethtool_get_drvinfo(dev
, useraddr
);
2500 rc
= ethtool_get_regs(dev
, useraddr
);
2503 rc
= ethtool_get_wol(dev
, useraddr
);
2506 rc
= ethtool_set_wol(dev
, useraddr
);
2508 case ETHTOOL_GMSGLVL
:
2509 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
2510 dev
->ethtool_ops
->get_msglevel
);
2512 case ETHTOOL_SMSGLVL
:
2513 rc
= ethtool_set_value_void(dev
, useraddr
,
2514 dev
->ethtool_ops
->set_msglevel
);
2517 rc
= ethtool_get_eee(dev
, useraddr
);
2520 rc
= ethtool_set_eee(dev
, useraddr
);
2522 case ETHTOOL_NWAY_RST
:
2523 rc
= ethtool_nway_reset(dev
);
2526 rc
= ethtool_get_link(dev
, useraddr
);
2528 case ETHTOOL_GEEPROM
:
2529 rc
= ethtool_get_eeprom(dev
, useraddr
);
2531 case ETHTOOL_SEEPROM
:
2532 rc
= ethtool_set_eeprom(dev
, useraddr
);
2534 case ETHTOOL_GCOALESCE
:
2535 rc
= ethtool_get_coalesce(dev
, useraddr
);
2537 case ETHTOOL_SCOALESCE
:
2538 rc
= ethtool_set_coalesce(dev
, useraddr
);
2540 case ETHTOOL_GRINGPARAM
:
2541 rc
= ethtool_get_ringparam(dev
, useraddr
);
2543 case ETHTOOL_SRINGPARAM
:
2544 rc
= ethtool_set_ringparam(dev
, useraddr
);
2546 case ETHTOOL_GPAUSEPARAM
:
2547 rc
= ethtool_get_pauseparam(dev
, useraddr
);
2549 case ETHTOOL_SPAUSEPARAM
:
2550 rc
= ethtool_set_pauseparam(dev
, useraddr
);
2553 rc
= ethtool_self_test(dev
, useraddr
);
2555 case ETHTOOL_GSTRINGS
:
2556 rc
= ethtool_get_strings(dev
, useraddr
);
2558 case ETHTOOL_PHYS_ID
:
2559 rc
= ethtool_phys_id(dev
, useraddr
);
2561 case ETHTOOL_GSTATS
:
2562 rc
= ethtool_get_stats(dev
, useraddr
);
2564 case ETHTOOL_GPERMADDR
:
2565 rc
= ethtool_get_perm_addr(dev
, useraddr
);
2567 case ETHTOOL_GFLAGS
:
2568 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
2569 __ethtool_get_flags
);
2571 case ETHTOOL_SFLAGS
:
2572 rc
= ethtool_set_value(dev
, useraddr
, __ethtool_set_flags
);
2574 case ETHTOOL_GPFLAGS
:
2575 rc
= ethtool_get_value(dev
, useraddr
, ethcmd
,
2576 dev
->ethtool_ops
->get_priv_flags
);
2578 case ETHTOOL_SPFLAGS
:
2579 rc
= ethtool_set_value(dev
, useraddr
,
2580 dev
->ethtool_ops
->set_priv_flags
);
2583 case ETHTOOL_GRXRINGS
:
2584 case ETHTOOL_GRXCLSRLCNT
:
2585 case ETHTOOL_GRXCLSRULE
:
2586 case ETHTOOL_GRXCLSRLALL
:
2587 rc
= ethtool_get_rxnfc(dev
, ethcmd
, useraddr
);
2590 case ETHTOOL_SRXCLSRLDEL
:
2591 case ETHTOOL_SRXCLSRLINS
:
2592 rc
= ethtool_set_rxnfc(dev
, ethcmd
, useraddr
);
2594 case ETHTOOL_FLASHDEV
:
2595 rc
= ethtool_flash_device(dev
, useraddr
);
2598 rc
= ethtool_reset(dev
, useraddr
);
2600 case ETHTOOL_GSSET_INFO
:
2601 rc
= ethtool_get_sset_info(dev
, useraddr
);
2603 case ETHTOOL_GRXFHINDIR
:
2604 rc
= ethtool_get_rxfh_indir(dev
, useraddr
);
2606 case ETHTOOL_SRXFHINDIR
:
2607 rc
= ethtool_set_rxfh_indir(dev
, useraddr
);
2610 rc
= ethtool_get_rxfh(dev
, useraddr
);
2613 rc
= ethtool_set_rxfh(dev
, useraddr
);
2615 case ETHTOOL_GFEATURES
:
2616 rc
= ethtool_get_features(dev
, useraddr
);
2618 case ETHTOOL_SFEATURES
:
2619 rc
= ethtool_set_features(dev
, useraddr
);
2621 case ETHTOOL_GTXCSUM
:
2622 case ETHTOOL_GRXCSUM
:
2628 rc
= ethtool_get_one_feature(dev
, useraddr
, ethcmd
);
2630 case ETHTOOL_STXCSUM
:
2631 case ETHTOOL_SRXCSUM
:
2637 rc
= ethtool_set_one_feature(dev
, useraddr
, ethcmd
);
2639 case ETHTOOL_GCHANNELS
:
2640 rc
= ethtool_get_channels(dev
, useraddr
);
2642 case ETHTOOL_SCHANNELS
:
2643 rc
= ethtool_set_channels(dev
, useraddr
);
2645 case ETHTOOL_SET_DUMP
:
2646 rc
= ethtool_set_dump(dev
, useraddr
);
2648 case ETHTOOL_GET_DUMP_FLAG
:
2649 rc
= ethtool_get_dump_flag(dev
, useraddr
);
2651 case ETHTOOL_GET_DUMP_DATA
:
2652 rc
= ethtool_get_dump_data(dev
, useraddr
);
2654 case ETHTOOL_GET_TS_INFO
:
2655 rc
= ethtool_get_ts_info(dev
, useraddr
);
2657 case ETHTOOL_GMODULEINFO
:
2658 rc
= ethtool_get_module_info(dev
, useraddr
);
2660 case ETHTOOL_GMODULEEEPROM
:
2661 rc
= ethtool_get_module_eeprom(dev
, useraddr
);
2663 case ETHTOOL_GTUNABLE
:
2664 rc
= ethtool_get_tunable(dev
, useraddr
);
2666 case ETHTOOL_STUNABLE
:
2667 rc
= ethtool_set_tunable(dev
, useraddr
);
2669 case ETHTOOL_GPHYSTATS
:
2670 rc
= ethtool_get_phy_stats(dev
, useraddr
);
2672 case ETHTOOL_PERQUEUE
:
2673 rc
= ethtool_set_per_queue(dev
, useraddr
);
2675 case ETHTOOL_GLINKSETTINGS
:
2676 rc
= ethtool_get_link_ksettings(dev
, useraddr
);
2678 case ETHTOOL_SLINKSETTINGS
:
2679 rc
= ethtool_set_link_ksettings(dev
, useraddr
);
2685 if (dev
->ethtool_ops
->complete
)
2686 dev
->ethtool_ops
->complete(dev
);
2688 if (old_features
!= dev
->features
)
2689 netdev_features_change(dev
);