1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * net/core/ethtool.c - Ethtool ioctl handler
4 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
6 * This file is where we call all the ethtool_ops commands to get
7 * the information ethtool needs.
10 #include <linux/compat.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/capability.h>
14 #include <linux/errno.h>
15 #include <linux/ethtool.h>
16 #include <linux/netdevice.h>
17 #include <linux/net_tstamp.h>
18 #include <linux/phy.h>
19 #include <linux/bitops.h>
20 #include <linux/uaccess.h>
21 #include <linux/vmalloc.h>
22 #include <linux/sfp.h>
23 #include <linux/slab.h>
24 #include <linux/rtnetlink.h>
25 #include <linux/sched/signal.h>
26 #include <linux/net.h>
27 #include <net/devlink.h>
28 #include <net/xdp_sock_drv.h>
29 #include <net/flow_offload.h>
30 #include <linux/ethtool_netlink.h>
31 #include <generated/utsrelease.h>
35 * Some useful ethtool_ops methods that're device independent.
36 * If we find that all drivers want to do the same thing here,
37 * we can turn these into dev_() function calls.
40 u32 ethtool_op_get_link(struct net_device *dev)
42 return netif_carrier_ok(dev) ? 1 : 0;
44 EXPORT_SYMBOL(ethtool_op_get_link);
46 int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
48 info->so_timestamping =
49 SOF_TIMESTAMPING_TX_SOFTWARE |
50 SOF_TIMESTAMPING_RX_SOFTWARE |
51 SOF_TIMESTAMPING_SOFTWARE;
55 EXPORT_SYMBOL(ethtool_op_get_ts_info);
57 /* Handlers for each ethtool command */
59 static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
61 struct ethtool_gfeatures cmd = {
62 .cmd = ETHTOOL_GFEATURES,
63 .size = ETHTOOL_DEV_FEATURE_WORDS,
65 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
70 /* in case feature bits run out again */
71 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
73 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
74 features[i].available = (u32)(dev->hw_features >> (32 * i));
75 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
76 features[i].active = (u32)(dev->features >> (32 * i));
77 features[i].never_changed =
78 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
81 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
82 if (get_user(copy_size, sizeaddr))
85 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
86 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
88 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
90 useraddr += sizeof(cmd);
91 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
97 static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
99 struct ethtool_sfeatures cmd;
100 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
101 netdev_features_t wanted = 0, valid = 0;
104 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
106 useraddr += sizeof(cmd);
108 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
111 if (copy_from_user(features, useraddr, sizeof(features)))
114 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
115 valid |= (netdev_features_t)features[i].valid << (32 * i);
116 wanted |= (netdev_features_t)features[i].requested << (32 * i);
119 if (valid & ~NETIF_F_ETHTOOL_BITS)
122 if (valid & ~dev->hw_features) {
123 valid &= dev->hw_features;
124 ret |= ETHTOOL_F_UNSUPPORTED;
127 dev->wanted_features &= ~valid;
128 dev->wanted_features |= wanted & valid;
129 __netdev_update_features(dev);
131 if ((dev->wanted_features ^ dev->features) & valid)
132 ret |= ETHTOOL_F_WISH;
137 static int __ethtool_get_sset_count(struct net_device *dev, int sset)
139 const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops;
140 const struct ethtool_ops *ops = dev->ethtool_ops;
142 if (sset == ETH_SS_FEATURES)
143 return ARRAY_SIZE(netdev_features_strings);
145 if (sset == ETH_SS_RSS_HASH_FUNCS)
146 return ARRAY_SIZE(rss_hash_func_strings);
148 if (sset == ETH_SS_TUNABLES)
149 return ARRAY_SIZE(tunable_strings);
151 if (sset == ETH_SS_PHY_TUNABLES)
152 return ARRAY_SIZE(phy_tunable_strings);
154 if (sset == ETH_SS_PHY_STATS && dev->phydev &&
155 !ops->get_ethtool_phy_stats &&
156 phy_ops && phy_ops->get_sset_count)
157 return phy_ops->get_sset_count(dev->phydev);
159 if (sset == ETH_SS_LINK_MODES)
160 return __ETHTOOL_LINK_MODE_MASK_NBITS;
162 if (ops->get_sset_count && ops->get_strings)
163 return ops->get_sset_count(dev, sset);
168 static void __ethtool_get_strings(struct net_device *dev,
169 u32 stringset, u8 *data)
171 const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops;
172 const struct ethtool_ops *ops = dev->ethtool_ops;
174 if (stringset == ETH_SS_FEATURES)
175 memcpy(data, netdev_features_strings,
176 sizeof(netdev_features_strings));
177 else if (stringset == ETH_SS_RSS_HASH_FUNCS)
178 memcpy(data, rss_hash_func_strings,
179 sizeof(rss_hash_func_strings));
180 else if (stringset == ETH_SS_TUNABLES)
181 memcpy(data, tunable_strings, sizeof(tunable_strings));
182 else if (stringset == ETH_SS_PHY_TUNABLES)
183 memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings));
184 else if (stringset == ETH_SS_PHY_STATS && dev->phydev &&
185 !ops->get_ethtool_phy_stats && phy_ops &&
186 phy_ops->get_strings)
187 phy_ops->get_strings(dev->phydev, data);
188 else if (stringset == ETH_SS_LINK_MODES)
189 memcpy(data, link_mode_names,
190 __ETHTOOL_LINK_MODE_MASK_NBITS * ETH_GSTRING_LEN);
192 /* ops->get_strings is valid because checked earlier */
193 ops->get_strings(dev, stringset, data);
196 static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
198 /* feature masks of legacy discrete ethtool ops */
201 case ETHTOOL_GTXCSUM:
202 case ETHTOOL_STXCSUM:
203 return NETIF_F_CSUM_MASK | NETIF_F_FCOE_CRC |
205 case ETHTOOL_GRXCSUM:
206 case ETHTOOL_SRXCSUM:
207 return NETIF_F_RXCSUM;
210 return NETIF_F_SG | NETIF_F_FRAGLIST;
213 return NETIF_F_ALL_TSO;
225 static int ethtool_get_one_feature(struct net_device *dev,
226 char __user *useraddr, u32 ethcmd)
228 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
229 struct ethtool_value edata = {
231 .data = !!(dev->features & mask),
234 if (copy_to_user(useraddr, &edata, sizeof(edata)))
239 static int ethtool_set_one_feature(struct net_device *dev,
240 void __user *useraddr, u32 ethcmd)
242 struct ethtool_value edata;
243 netdev_features_t mask;
245 if (copy_from_user(&edata, useraddr, sizeof(edata)))
248 mask = ethtool_get_feature_mask(ethcmd);
249 mask &= dev->hw_features;
254 dev->wanted_features |= mask;
256 dev->wanted_features &= ~mask;
258 __netdev_update_features(dev);
263 #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
264 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
265 #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
266 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
269 static u32 __ethtool_get_flags(struct net_device *dev)
273 if (dev->features & NETIF_F_LRO)
274 flags |= ETH_FLAG_LRO;
275 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
276 flags |= ETH_FLAG_RXVLAN;
277 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
278 flags |= ETH_FLAG_TXVLAN;
279 if (dev->features & NETIF_F_NTUPLE)
280 flags |= ETH_FLAG_NTUPLE;
281 if (dev->features & NETIF_F_RXHASH)
282 flags |= ETH_FLAG_RXHASH;
287 static int __ethtool_set_flags(struct net_device *dev, u32 data)
289 netdev_features_t features = 0, changed;
291 if (data & ~ETH_ALL_FLAGS)
294 if (data & ETH_FLAG_LRO)
295 features |= NETIF_F_LRO;
296 if (data & ETH_FLAG_RXVLAN)
297 features |= NETIF_F_HW_VLAN_CTAG_RX;
298 if (data & ETH_FLAG_TXVLAN)
299 features |= NETIF_F_HW_VLAN_CTAG_TX;
300 if (data & ETH_FLAG_NTUPLE)
301 features |= NETIF_F_NTUPLE;
302 if (data & ETH_FLAG_RXHASH)
303 features |= NETIF_F_RXHASH;
305 /* allow changing only bits set in hw_features */
306 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
307 if (changed & ~dev->hw_features)
308 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
310 dev->wanted_features =
311 (dev->wanted_features & ~changed) | (features & changed);
313 __netdev_update_features(dev);
318 /* Given two link masks, AND them together and save the result in dst. */
319 void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst,
320 struct ethtool_link_ksettings *src)
322 unsigned int size = BITS_TO_LONGS(__ETHTOOL_LINK_MODE_MASK_NBITS);
323 unsigned int idx = 0;
325 for (; idx < size; idx++) {
326 dst->link_modes.supported[idx] &=
327 src->link_modes.supported[idx];
328 dst->link_modes.advertising[idx] &=
329 src->link_modes.advertising[idx];
332 EXPORT_SYMBOL(ethtool_intersect_link_masks);
334 void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
337 bitmap_zero(dst, __ETHTOOL_LINK_MODE_MASK_NBITS);
340 EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode);
342 /* return false if src had higher bits set. lower bits always updated. */
343 bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
344 const unsigned long *src)
348 /* TODO: following test will soon always be true */
349 if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) {
350 __ETHTOOL_DECLARE_LINK_MODE_MASK(ext);
352 bitmap_zero(ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
353 bitmap_fill(ext, 32);
354 bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS);
355 if (bitmap_intersects(ext, src,
356 __ETHTOOL_LINK_MODE_MASK_NBITS)) {
357 /* src mask goes beyond bit 31 */
361 *legacy_u32 = src[0];
364 EXPORT_SYMBOL(ethtool_convert_link_mode_to_legacy_u32);
366 /* return false if ksettings link modes had higher bits
367 * set. legacy_settings always updated (best effort)
370 convert_link_ksettings_to_legacy_settings(
371 struct ethtool_cmd *legacy_settings,
372 const struct ethtool_link_ksettings *link_ksettings)
376 memset(legacy_settings, 0, sizeof(*legacy_settings));
377 /* this also clears the deprecated fields in legacy structure:
383 retval &= ethtool_convert_link_mode_to_legacy_u32(
384 &legacy_settings->supported,
385 link_ksettings->link_modes.supported);
386 retval &= ethtool_convert_link_mode_to_legacy_u32(
387 &legacy_settings->advertising,
388 link_ksettings->link_modes.advertising);
389 retval &= ethtool_convert_link_mode_to_legacy_u32(
390 &legacy_settings->lp_advertising,
391 link_ksettings->link_modes.lp_advertising);
392 ethtool_cmd_speed_set(legacy_settings, link_ksettings->base.speed);
393 legacy_settings->duplex
394 = link_ksettings->base.duplex;
395 legacy_settings->port
396 = link_ksettings->base.port;
397 legacy_settings->phy_address
398 = link_ksettings->base.phy_address;
399 legacy_settings->autoneg
400 = link_ksettings->base.autoneg;
401 legacy_settings->mdio_support
402 = link_ksettings->base.mdio_support;
403 legacy_settings->eth_tp_mdix
404 = link_ksettings->base.eth_tp_mdix;
405 legacy_settings->eth_tp_mdix_ctrl
406 = link_ksettings->base.eth_tp_mdix_ctrl;
407 legacy_settings->transceiver
408 = link_ksettings->base.transceiver;
412 /* number of 32-bit words to store the user's link mode bitmaps */
413 #define __ETHTOOL_LINK_MODE_MASK_NU32 \
414 DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
416 /* layout of the struct passed from/to userland */
417 struct ethtool_link_usettings {
418 struct ethtool_link_settings base;
420 __u32 supported[__ETHTOOL_LINK_MODE_MASK_NU32];
421 __u32 advertising[__ETHTOOL_LINK_MODE_MASK_NU32];
422 __u32 lp_advertising[__ETHTOOL_LINK_MODE_MASK_NU32];
426 /* Internal kernel helper to query a device ethtool_link_settings. */
427 int __ethtool_get_link_ksettings(struct net_device *dev,
428 struct ethtool_link_ksettings *link_ksettings)
432 if (!dev->ethtool_ops->get_link_ksettings)
435 memset(link_ksettings, 0, sizeof(*link_ksettings));
436 return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings);
438 EXPORT_SYMBOL(__ethtool_get_link_ksettings);
440 /* convert ethtool_link_usettings in user space to a kernel internal
441 * ethtool_link_ksettings. return 0 on success, errno on error.
443 static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to,
444 const void __user *from)
446 struct ethtool_link_usettings link_usettings;
448 if (copy_from_user(&link_usettings, from, sizeof(link_usettings)))
451 memcpy(&to->base, &link_usettings.base, sizeof(to->base));
452 bitmap_from_arr32(to->link_modes.supported,
453 link_usettings.link_modes.supported,
454 __ETHTOOL_LINK_MODE_MASK_NBITS);
455 bitmap_from_arr32(to->link_modes.advertising,
456 link_usettings.link_modes.advertising,
457 __ETHTOOL_LINK_MODE_MASK_NBITS);
458 bitmap_from_arr32(to->link_modes.lp_advertising,
459 link_usettings.link_modes.lp_advertising,
460 __ETHTOOL_LINK_MODE_MASK_NBITS);
465 /* Check if the user is trying to change anything besides speed/duplex */
466 bool ethtool_virtdev_validate_cmd(const struct ethtool_link_ksettings *cmd)
468 struct ethtool_link_settings base2 = {};
470 base2.speed = cmd->base.speed;
471 base2.port = PORT_OTHER;
472 base2.duplex = cmd->base.duplex;
473 base2.cmd = cmd->base.cmd;
474 base2.link_mode_masks_nwords = cmd->base.link_mode_masks_nwords;
476 return !memcmp(&base2, &cmd->base, sizeof(base2)) &&
477 bitmap_empty(cmd->link_modes.supported,
478 __ETHTOOL_LINK_MODE_MASK_NBITS) &&
479 bitmap_empty(cmd->link_modes.lp_advertising,
480 __ETHTOOL_LINK_MODE_MASK_NBITS);
483 /* convert a kernel internal ethtool_link_ksettings to
484 * ethtool_link_usettings in user space. return 0 on success, errno on
488 store_link_ksettings_for_user(void __user *to,
489 const struct ethtool_link_ksettings *from)
491 struct ethtool_link_usettings link_usettings;
493 memcpy(&link_usettings, from, sizeof(link_usettings));
494 bitmap_to_arr32(link_usettings.link_modes.supported,
495 from->link_modes.supported,
496 __ETHTOOL_LINK_MODE_MASK_NBITS);
497 bitmap_to_arr32(link_usettings.link_modes.advertising,
498 from->link_modes.advertising,
499 __ETHTOOL_LINK_MODE_MASK_NBITS);
500 bitmap_to_arr32(link_usettings.link_modes.lp_advertising,
501 from->link_modes.lp_advertising,
502 __ETHTOOL_LINK_MODE_MASK_NBITS);
504 if (copy_to_user(to, &link_usettings, sizeof(link_usettings)))
510 /* Query device for its ethtool_link_settings. */
511 static int ethtool_get_link_ksettings(struct net_device *dev,
512 void __user *useraddr)
515 struct ethtool_link_ksettings link_ksettings;
518 if (!dev->ethtool_ops->get_link_ksettings)
521 /* handle bitmap nbits handshake */
522 if (copy_from_user(&link_ksettings.base, useraddr,
523 sizeof(link_ksettings.base)))
526 if (__ETHTOOL_LINK_MODE_MASK_NU32
527 != link_ksettings.base.link_mode_masks_nwords) {
528 /* wrong link mode nbits requested */
529 memset(&link_ksettings, 0, sizeof(link_ksettings));
530 link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS;
531 /* send back number of words required as negative val */
532 compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32 <= S8_MAX,
533 "need too many bits for link modes!");
534 link_ksettings.base.link_mode_masks_nwords
535 = -((s8)__ETHTOOL_LINK_MODE_MASK_NU32);
537 /* copy the base fields back to user, not the link
540 if (copy_to_user(useraddr, &link_ksettings.base,
541 sizeof(link_ksettings.base)))
547 /* handshake successful: user/kernel agree on
548 * link_mode_masks_nwords
551 memset(&link_ksettings, 0, sizeof(link_ksettings));
552 err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings);
556 /* make sure we tell the right values to user */
557 link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS;
558 link_ksettings.base.link_mode_masks_nwords
559 = __ETHTOOL_LINK_MODE_MASK_NU32;
560 link_ksettings.base.master_slave_cfg = MASTER_SLAVE_CFG_UNSUPPORTED;
561 link_ksettings.base.master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED;
563 return store_link_ksettings_for_user(useraddr, &link_ksettings);
566 /* Update device ethtool_link_settings. */
567 static int ethtool_set_link_ksettings(struct net_device *dev,
568 void __user *useraddr)
571 struct ethtool_link_ksettings link_ksettings;
575 if (!dev->ethtool_ops->set_link_ksettings)
578 /* make sure nbits field has expected value */
579 if (copy_from_user(&link_ksettings.base, useraddr,
580 sizeof(link_ksettings.base)))
583 if (__ETHTOOL_LINK_MODE_MASK_NU32
584 != link_ksettings.base.link_mode_masks_nwords)
587 /* copy the whole structure, now that we know it has expected
590 err = load_link_ksettings_from_user(&link_ksettings, useraddr);
594 /* re-check nwords field, just in case */
595 if (__ETHTOOL_LINK_MODE_MASK_NU32
596 != link_ksettings.base.link_mode_masks_nwords)
599 if (link_ksettings.base.master_slave_cfg ||
600 link_ksettings.base.master_slave_state)
603 err = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
605 ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL);
606 ethtool_notify(dev, ETHTOOL_MSG_LINKMODES_NTF, NULL);
611 int ethtool_virtdev_set_link_ksettings(struct net_device *dev,
612 const struct ethtool_link_ksettings *cmd,
613 u32 *dev_speed, u8 *dev_duplex)
618 speed = cmd->base.speed;
619 duplex = cmd->base.duplex;
620 /* don't allow custom speed and duplex */
621 if (!ethtool_validate_speed(speed) ||
622 !ethtool_validate_duplex(duplex) ||
623 !ethtool_virtdev_validate_cmd(cmd))
626 *dev_duplex = duplex;
630 EXPORT_SYMBOL(ethtool_virtdev_set_link_ksettings);
632 /* Query device for its ethtool_cmd settings.
634 * Backward compatibility note: for compatibility with legacy ethtool, this is
635 * now implemented via get_link_ksettings. When driver reports higher link mode
636 * bits, a kernel warning is logged once (with name of 1st driver/device) to
637 * recommend user to upgrade ethtool, but the command is successful (only the
638 * lower link mode bits reported back to user). Deprecated fields from
639 * ethtool_cmd (transceiver/maxrxpkt/maxtxpkt) are always set to zero.
641 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
643 struct ethtool_link_ksettings link_ksettings;
644 struct ethtool_cmd cmd;
648 if (!dev->ethtool_ops->get_link_ksettings)
651 memset(&link_ksettings, 0, sizeof(link_ksettings));
652 err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings);
655 convert_link_ksettings_to_legacy_settings(&cmd, &link_ksettings);
657 /* send a sensible cmd tag back to user */
658 cmd.cmd = ETHTOOL_GSET;
660 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
666 /* Update device link settings with given ethtool_cmd.
668 * Backward compatibility note: for compatibility with legacy ethtool, this is
669 * now always implemented via set_link_settings. When user's request updates
670 * deprecated ethtool_cmd fields (transceiver/maxrxpkt/maxtxpkt), a kernel
671 * warning is logged once (with name of 1st driver/device) to recommend user to
672 * upgrade ethtool, and the request is rejected.
674 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
676 struct ethtool_link_ksettings link_ksettings;
677 struct ethtool_cmd cmd;
682 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
684 if (!dev->ethtool_ops->set_link_ksettings)
687 if (!convert_legacy_settings_to_link_ksettings(&link_ksettings, &cmd))
689 link_ksettings.base.link_mode_masks_nwords =
690 __ETHTOOL_LINK_MODE_MASK_NU32;
691 ret = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings);
693 ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL);
694 ethtool_notify(dev, ETHTOOL_MSG_LINKMODES_NTF, NULL);
699 static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
700 void __user *useraddr)
702 struct ethtool_drvinfo info;
703 const struct ethtool_ops *ops = dev->ethtool_ops;
705 memset(&info, 0, sizeof(info));
706 info.cmd = ETHTOOL_GDRVINFO;
707 strlcpy(info.version, UTS_RELEASE, sizeof(info.version));
708 if (ops->get_drvinfo) {
709 ops->get_drvinfo(dev, &info);
710 } else if (dev->dev.parent && dev->dev.parent->driver) {
711 strlcpy(info.bus_info, dev_name(dev->dev.parent),
712 sizeof(info.bus_info));
713 strlcpy(info.driver, dev->dev.parent->driver->name,
714 sizeof(info.driver));
720 * this method of obtaining string set info is deprecated;
721 * Use ETHTOOL_GSSET_INFO instead.
723 if (ops->get_sset_count) {
726 rc = ops->get_sset_count(dev, ETH_SS_TEST);
728 info.testinfo_len = rc;
729 rc = ops->get_sset_count(dev, ETH_SS_STATS);
732 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
734 info.n_priv_flags = rc;
736 if (ops->get_regs_len) {
737 int ret = ops->get_regs_len(dev);
740 info.regdump_len = ret;
743 if (ops->get_eeprom_len)
744 info.eedump_len = ops->get_eeprom_len(dev);
746 if (!info.fw_version[0])
747 devlink_compat_running_version(dev, info.fw_version,
748 sizeof(info.fw_version));
750 if (copy_to_user(useraddr, &info, sizeof(info)))
755 static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
756 void __user *useraddr)
758 struct ethtool_sset_info info;
760 int i, idx = 0, n_bits = 0, ret, rc;
761 u32 *info_buf = NULL;
763 if (copy_from_user(&info, useraddr, sizeof(info)))
766 /* store copy of mask, because we zero struct later on */
767 sset_mask = info.sset_mask;
771 /* calculate size of return buffer */
772 n_bits = hweight64(sset_mask);
774 memset(&info, 0, sizeof(info));
775 info.cmd = ETHTOOL_GSSET_INFO;
777 info_buf = kcalloc(n_bits, sizeof(u32), GFP_USER);
782 * fill return buffer based on input bitmask and successful
783 * get_sset_count return
785 for (i = 0; i < 64; i++) {
786 if (!(sset_mask & (1ULL << i)))
789 rc = __ethtool_get_sset_count(dev, i);
791 info.sset_mask |= (1ULL << i);
792 info_buf[idx++] = rc;
797 if (copy_to_user(useraddr, &info, sizeof(info)))
800 useraddr += offsetof(struct ethtool_sset_info, data);
801 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
811 static noinline_for_stack int
812 ethtool_rxnfc_copy_from_compat(struct ethtool_rxnfc *rxnfc,
813 const struct compat_ethtool_rxnfc __user *useraddr,
816 struct compat_ethtool_rxnfc crxnfc = {};
818 /* We expect there to be holes between fs.m_ext and
819 * fs.ring_cookie and at the end of fs, but nowhere else.
820 * On non-x86, no conversion should be needed.
822 BUILD_BUG_ON(!IS_ENABLED(CONFIG_X86_64) &&
823 sizeof(struct compat_ethtool_rxnfc) !=
824 sizeof(struct ethtool_rxnfc));
825 BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.m_ext) +
826 sizeof(useraddr->fs.m_ext) !=
827 offsetof(struct ethtool_rxnfc, fs.m_ext) +
828 sizeof(rxnfc->fs.m_ext));
829 BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.location) -
830 offsetof(struct compat_ethtool_rxnfc, fs.ring_cookie) !=
831 offsetof(struct ethtool_rxnfc, fs.location) -
832 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
834 if (copy_from_user(&crxnfc, useraddr, min(size, sizeof(crxnfc))))
837 *rxnfc = (struct ethtool_rxnfc) {
839 .flow_type = crxnfc.flow_type,
842 .flow_type = crxnfc.fs.flow_type,
843 .h_u = crxnfc.fs.h_u,
844 .h_ext = crxnfc.fs.h_ext,
845 .m_u = crxnfc.fs.m_u,
846 .m_ext = crxnfc.fs.m_ext,
847 .ring_cookie = crxnfc.fs.ring_cookie,
848 .location = crxnfc.fs.location,
850 .rule_cnt = crxnfc.rule_cnt,
856 static int ethtool_rxnfc_copy_from_user(struct ethtool_rxnfc *rxnfc,
857 const void __user *useraddr,
860 if (compat_need_64bit_alignment_fixup())
861 return ethtool_rxnfc_copy_from_compat(rxnfc, useraddr, size);
863 if (copy_from_user(rxnfc, useraddr, size))
869 static int ethtool_rxnfc_copy_to_compat(void __user *useraddr,
870 const struct ethtool_rxnfc *rxnfc,
871 size_t size, const u32 *rule_buf)
873 struct compat_ethtool_rxnfc crxnfc;
875 memset(&crxnfc, 0, sizeof(crxnfc));
876 crxnfc = (struct compat_ethtool_rxnfc) {
878 .flow_type = rxnfc->flow_type,
881 .flow_type = rxnfc->fs.flow_type,
882 .h_u = rxnfc->fs.h_u,
883 .h_ext = rxnfc->fs.h_ext,
884 .m_u = rxnfc->fs.m_u,
885 .m_ext = rxnfc->fs.m_ext,
886 .ring_cookie = rxnfc->fs.ring_cookie,
887 .location = rxnfc->fs.location,
889 .rule_cnt = rxnfc->rule_cnt,
892 if (copy_to_user(useraddr, &crxnfc, min(size, sizeof(crxnfc))))
898 static int ethtool_rxnfc_copy_to_user(void __user *useraddr,
899 const struct ethtool_rxnfc *rxnfc,
900 size_t size, const u32 *rule_buf)
904 if (compat_need_64bit_alignment_fixup()) {
905 ret = ethtool_rxnfc_copy_to_compat(useraddr, rxnfc, size,
907 useraddr += offsetof(struct compat_ethtool_rxnfc, rule_locs);
909 ret = copy_to_user(useraddr, rxnfc, size);
910 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
917 if (copy_to_user(useraddr, rule_buf,
918 rxnfc->rule_cnt * sizeof(u32)))
925 static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
926 u32 cmd, void __user *useraddr)
928 struct ethtool_rxnfc info;
929 size_t info_size = sizeof(info);
932 if (!dev->ethtool_ops->set_rxnfc)
935 /* struct ethtool_rxnfc was originally defined for
936 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
937 * members. User-space might still be using that
939 if (cmd == ETHTOOL_SRXFH)
940 info_size = (offsetof(struct ethtool_rxnfc, data) +
943 if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size))
946 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
950 if (cmd == ETHTOOL_SRXCLSRLINS &&
951 ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, NULL))
957 static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
958 u32 cmd, void __user *useraddr)
960 struct ethtool_rxnfc info;
961 size_t info_size = sizeof(info);
962 const struct ethtool_ops *ops = dev->ethtool_ops;
964 void *rule_buf = NULL;
969 /* struct ethtool_rxnfc was originally defined for
970 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
971 * members. User-space might still be using that
973 if (cmd == ETHTOOL_GRXFH)
974 info_size = (offsetof(struct ethtool_rxnfc, data) +
977 if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size))
980 /* If FLOW_RSS was requested then user-space must be using the
981 * new definition, as FLOW_RSS is newer.
983 if (cmd == ETHTOOL_GRXFH && info.flow_type & FLOW_RSS) {
984 info_size = sizeof(info);
985 if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size))
987 /* Since malicious users may modify the original data,
988 * we need to check whether FLOW_RSS is still requested.
990 if (!(info.flow_type & FLOW_RSS))
997 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
998 if (info.rule_cnt > 0) {
999 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
1000 rule_buf = kcalloc(info.rule_cnt, sizeof(u32),
1007 ret = ops->get_rxnfc(dev, &info, rule_buf);
1011 ret = ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, rule_buf);
1018 static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
1019 struct ethtool_rxnfc *rx_rings,
1024 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
1027 /* Validate ring indices */
1028 for (i = 0; i < size; i++)
1029 if (indir[i] >= rx_rings->data)
1035 u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
1037 void netdev_rss_key_fill(void *buffer, size_t len)
1039 BUG_ON(len > sizeof(netdev_rss_key));
1040 net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
1041 memcpy(buffer, netdev_rss_key, len);
1043 EXPORT_SYMBOL(netdev_rss_key_fill);
1045 static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
1046 void __user *useraddr)
1048 u32 user_size, dev_size;
1052 if (!dev->ethtool_ops->get_rxfh_indir_size ||
1053 !dev->ethtool_ops->get_rxfh)
1055 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
1059 if (copy_from_user(&user_size,
1060 useraddr + offsetof(struct ethtool_rxfh_indir, size),
1064 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
1065 &dev_size, sizeof(dev_size)))
1068 /* If the user buffer size is 0, this is just a query for the
1069 * device table size. Otherwise, if it's smaller than the
1070 * device table size it's an error.
1072 if (user_size < dev_size)
1073 return user_size == 0 ? 0 : -EINVAL;
1075 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
1079 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
1083 if (copy_to_user(useraddr +
1084 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
1085 indir, dev_size * sizeof(indir[0])))
1093 static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
1094 void __user *useraddr)
1096 struct ethtool_rxnfc rx_rings;
1097 u32 user_size, dev_size, i;
1099 const struct ethtool_ops *ops = dev->ethtool_ops;
1101 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
1103 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
1107 dev_size = ops->get_rxfh_indir_size(dev);
1111 if (copy_from_user(&user_size,
1112 useraddr + offsetof(struct ethtool_rxfh_indir, size),
1116 if (user_size != 0 && user_size != dev_size)
1119 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
1123 rx_rings.cmd = ETHTOOL_GRXRINGS;
1124 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
1128 if (user_size == 0) {
1129 for (i = 0; i < dev_size; i++)
1130 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
1132 ret = ethtool_copy_validate_indir(indir,
1133 useraddr + ringidx_offset,
1140 ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE);
1144 /* indicate whether rxfh was set to default */
1146 dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
1148 dev->priv_flags |= IFF_RXFH_CONFIGURED;
1155 static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
1156 void __user *useraddr)
1159 const struct ethtool_ops *ops = dev->ethtool_ops;
1160 u32 user_indir_size, user_key_size;
1161 u32 dev_indir_size = 0, dev_key_size = 0;
1162 struct ethtool_rxfh rxfh;
1173 if (ops->get_rxfh_indir_size)
1174 dev_indir_size = ops->get_rxfh_indir_size(dev);
1175 if (ops->get_rxfh_key_size)
1176 dev_key_size = ops->get_rxfh_key_size(dev);
1178 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
1180 user_indir_size = rxfh.indir_size;
1181 user_key_size = rxfh.key_size;
1183 /* Check that reserved fields are 0 for now */
1184 if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32)
1186 /* Most drivers don't handle rss_context, check it's 0 as well */
1187 if (rxfh.rss_context && !ops->get_rxfh_context)
1190 rxfh.indir_size = dev_indir_size;
1191 rxfh.key_size = dev_key_size;
1192 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
1195 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
1196 (user_key_size && (user_key_size != dev_key_size)))
1199 indir_bytes = user_indir_size * sizeof(indir[0]);
1200 total_size = indir_bytes + user_key_size;
1201 rss_config = kzalloc(total_size, GFP_USER);
1205 if (user_indir_size)
1206 indir = (u32 *)rss_config;
1209 hkey = rss_config + indir_bytes;
1211 if (rxfh.rss_context)
1212 ret = dev->ethtool_ops->get_rxfh_context(dev, indir, hkey,
1216 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc);
1220 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc),
1221 &dev_hfunc, sizeof(rxfh.hfunc))) {
1223 } else if (copy_to_user(useraddr +
1224 offsetof(struct ethtool_rxfh, rss_config[0]),
1225 rss_config, total_size)) {
1234 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
1235 void __user *useraddr)
1238 const struct ethtool_ops *ops = dev->ethtool_ops;
1239 struct ethtool_rxnfc rx_rings;
1240 struct ethtool_rxfh rxfh;
1241 u32 dev_indir_size = 0, dev_key_size = 0, i;
1242 u32 *indir = NULL, indir_bytes = 0;
1245 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
1246 bool delete = false;
1248 if (!ops->get_rxnfc || !ops->set_rxfh)
1251 if (ops->get_rxfh_indir_size)
1252 dev_indir_size = ops->get_rxfh_indir_size(dev);
1253 if (ops->get_rxfh_key_size)
1254 dev_key_size = ops->get_rxfh_key_size(dev);
1256 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
1259 /* Check that reserved fields are 0 for now */
1260 if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32)
1262 /* Most drivers don't handle rss_context, check it's 0 as well */
1263 if (rxfh.rss_context && !ops->set_rxfh_context)
1266 /* If either indir, hash key or function is valid, proceed further.
1267 * Must request at least one change: indir size, hash key or function.
1269 if ((rxfh.indir_size &&
1270 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
1271 rxfh.indir_size != dev_indir_size) ||
1272 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
1273 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
1274 rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
1277 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
1278 indir_bytes = dev_indir_size * sizeof(indir[0]);
1280 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
1284 rx_rings.cmd = ETHTOOL_GRXRINGS;
1285 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
1289 /* rxfh.indir_size == 0 means reset the indir table to default (master
1290 * context) or delete the context (other RSS contexts).
1291 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
1293 if (rxfh.indir_size &&
1294 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
1295 indir = (u32 *)rss_config;
1296 ret = ethtool_copy_validate_indir(indir,
1297 useraddr + rss_cfg_offset,
1302 } else if (rxfh.indir_size == 0) {
1303 if (rxfh.rss_context == 0) {
1304 indir = (u32 *)rss_config;
1305 for (i = 0; i < dev_indir_size; i++)
1306 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
1312 if (rxfh.key_size) {
1313 hkey = rss_config + indir_bytes;
1314 if (copy_from_user(hkey,
1315 useraddr + rss_cfg_offset + indir_bytes,
1322 if (rxfh.rss_context)
1323 ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc,
1324 &rxfh.rss_context, delete);
1326 ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc);
1330 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, rss_context),
1331 &rxfh.rss_context, sizeof(rxfh.rss_context)))
1334 if (!rxfh.rss_context) {
1335 /* indicate whether rxfh was set to default */
1336 if (rxfh.indir_size == 0)
1337 dev->priv_flags &= ~IFF_RXFH_CONFIGURED;
1338 else if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
1339 dev->priv_flags |= IFF_RXFH_CONFIGURED;
1347 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
1349 struct ethtool_regs regs;
1350 const struct ethtool_ops *ops = dev->ethtool_ops;
1354 if (!ops->get_regs || !ops->get_regs_len)
1357 if (copy_from_user(®s, useraddr, sizeof(regs)))
1360 reglen = ops->get_regs_len(dev);
1364 if (regs.len > reglen)
1367 regbuf = vzalloc(reglen);
1371 if (regs.len < reglen)
1374 ops->get_regs(dev, ®s, regbuf);
1377 if (copy_to_user(useraddr, ®s, sizeof(regs)))
1379 useraddr += offsetof(struct ethtool_regs, data);
1380 if (copy_to_user(useraddr, regbuf, reglen))
1389 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
1391 struct ethtool_value reset;
1394 if (!dev->ethtool_ops->reset)
1397 if (copy_from_user(&reset, useraddr, sizeof(reset)))
1400 ret = dev->ethtool_ops->reset(dev, &reset.data);
1404 if (copy_to_user(useraddr, &reset, sizeof(reset)))
1409 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
1411 struct ethtool_wolinfo wol;
1413 if (!dev->ethtool_ops->get_wol)
1416 memset(&wol, 0, sizeof(struct ethtool_wolinfo));
1417 wol.cmd = ETHTOOL_GWOL;
1418 dev->ethtool_ops->get_wol(dev, &wol);
1420 if (copy_to_user(useraddr, &wol, sizeof(wol)))
1425 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
1427 struct ethtool_wolinfo wol;
1430 if (!dev->ethtool_ops->set_wol)
1433 if (copy_from_user(&wol, useraddr, sizeof(wol)))
1436 ret = dev->ethtool_ops->set_wol(dev, &wol);
1440 dev->wol_enabled = !!wol.wolopts;
1441 ethtool_notify(dev, ETHTOOL_MSG_WOL_NTF, NULL);
1446 static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
1448 struct ethtool_eee edata;
1451 if (!dev->ethtool_ops->get_eee)
1454 memset(&edata, 0, sizeof(struct ethtool_eee));
1455 edata.cmd = ETHTOOL_GEEE;
1456 rc = dev->ethtool_ops->get_eee(dev, &edata);
1461 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1467 static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
1469 struct ethtool_eee edata;
1472 if (!dev->ethtool_ops->set_eee)
1475 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1478 ret = dev->ethtool_ops->set_eee(dev, &edata);
1480 ethtool_notify(dev, ETHTOOL_MSG_EEE_NTF, NULL);
1484 static int ethtool_nway_reset(struct net_device *dev)
1486 if (!dev->ethtool_ops->nway_reset)
1489 return dev->ethtool_ops->nway_reset(dev);
1492 static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
1494 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
1495 int link = __ethtool_get_link(dev);
1501 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1506 static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
1507 int (*getter)(struct net_device *,
1508 struct ethtool_eeprom *, u8 *),
1511 struct ethtool_eeprom eeprom;
1512 void __user *userbuf = useraddr + sizeof(eeprom);
1513 u32 bytes_remaining;
1517 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1520 /* Check for wrap and zero */
1521 if (eeprom.offset + eeprom.len <= eeprom.offset)
1524 /* Check for exceeding total eeprom len */
1525 if (eeprom.offset + eeprom.len > total_len)
1528 data = kzalloc(PAGE_SIZE, GFP_USER);
1532 bytes_remaining = eeprom.len;
1533 while (bytes_remaining > 0) {
1534 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1536 ret = getter(dev, &eeprom, data);
1539 if (copy_to_user(userbuf, data, eeprom.len)) {
1543 userbuf += eeprom.len;
1544 eeprom.offset += eeprom.len;
1545 bytes_remaining -= eeprom.len;
1548 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1549 eeprom.offset -= eeprom.len;
1550 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1557 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1559 const struct ethtool_ops *ops = dev->ethtool_ops;
1561 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1562 !ops->get_eeprom_len(dev))
1565 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1566 ops->get_eeprom_len(dev));
1569 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1571 struct ethtool_eeprom eeprom;
1572 const struct ethtool_ops *ops = dev->ethtool_ops;
1573 void __user *userbuf = useraddr + sizeof(eeprom);
1574 u32 bytes_remaining;
1578 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1579 !ops->get_eeprom_len(dev))
1582 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1585 /* Check for wrap and zero */
1586 if (eeprom.offset + eeprom.len <= eeprom.offset)
1589 /* Check for exceeding total eeprom len */
1590 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1593 data = kzalloc(PAGE_SIZE, GFP_USER);
1597 bytes_remaining = eeprom.len;
1598 while (bytes_remaining > 0) {
1599 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
1601 if (copy_from_user(data, userbuf, eeprom.len)) {
1605 ret = ops->set_eeprom(dev, &eeprom, data);
1608 userbuf += eeprom.len;
1609 eeprom.offset += eeprom.len;
1610 bytes_remaining -= eeprom.len;
1617 static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1618 void __user *useraddr)
1620 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
1623 if (!dev->ethtool_ops->get_coalesce)
1626 ret = dev->ethtool_ops->get_coalesce(dev, &coalesce);
1630 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1636 ethtool_set_coalesce_supported(struct net_device *dev,
1637 struct ethtool_coalesce *coalesce)
1639 u32 supported_params = dev->ethtool_ops->supported_coalesce_params;
1640 u32 nonzero_params = 0;
1642 if (coalesce->rx_coalesce_usecs)
1643 nonzero_params |= ETHTOOL_COALESCE_RX_USECS;
1644 if (coalesce->rx_max_coalesced_frames)
1645 nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES;
1646 if (coalesce->rx_coalesce_usecs_irq)
1647 nonzero_params |= ETHTOOL_COALESCE_RX_USECS_IRQ;
1648 if (coalesce->rx_max_coalesced_frames_irq)
1649 nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ;
1650 if (coalesce->tx_coalesce_usecs)
1651 nonzero_params |= ETHTOOL_COALESCE_TX_USECS;
1652 if (coalesce->tx_max_coalesced_frames)
1653 nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES;
1654 if (coalesce->tx_coalesce_usecs_irq)
1655 nonzero_params |= ETHTOOL_COALESCE_TX_USECS_IRQ;
1656 if (coalesce->tx_max_coalesced_frames_irq)
1657 nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ;
1658 if (coalesce->stats_block_coalesce_usecs)
1659 nonzero_params |= ETHTOOL_COALESCE_STATS_BLOCK_USECS;
1660 if (coalesce->use_adaptive_rx_coalesce)
1661 nonzero_params |= ETHTOOL_COALESCE_USE_ADAPTIVE_RX;
1662 if (coalesce->use_adaptive_tx_coalesce)
1663 nonzero_params |= ETHTOOL_COALESCE_USE_ADAPTIVE_TX;
1664 if (coalesce->pkt_rate_low)
1665 nonzero_params |= ETHTOOL_COALESCE_PKT_RATE_LOW;
1666 if (coalesce->rx_coalesce_usecs_low)
1667 nonzero_params |= ETHTOOL_COALESCE_RX_USECS_LOW;
1668 if (coalesce->rx_max_coalesced_frames_low)
1669 nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW;
1670 if (coalesce->tx_coalesce_usecs_low)
1671 nonzero_params |= ETHTOOL_COALESCE_TX_USECS_LOW;
1672 if (coalesce->tx_max_coalesced_frames_low)
1673 nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW;
1674 if (coalesce->pkt_rate_high)
1675 nonzero_params |= ETHTOOL_COALESCE_PKT_RATE_HIGH;
1676 if (coalesce->rx_coalesce_usecs_high)
1677 nonzero_params |= ETHTOOL_COALESCE_RX_USECS_HIGH;
1678 if (coalesce->rx_max_coalesced_frames_high)
1679 nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH;
1680 if (coalesce->tx_coalesce_usecs_high)
1681 nonzero_params |= ETHTOOL_COALESCE_TX_USECS_HIGH;
1682 if (coalesce->tx_max_coalesced_frames_high)
1683 nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH;
1684 if (coalesce->rate_sample_interval)
1685 nonzero_params |= ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL;
1687 return (supported_params & nonzero_params) == nonzero_params;
1690 static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1691 void __user *useraddr)
1693 struct ethtool_coalesce coalesce;
1696 if (!dev->ethtool_ops->set_coalesce)
1699 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1702 if (!ethtool_set_coalesce_supported(dev, &coalesce))
1705 ret = dev->ethtool_ops->set_coalesce(dev, &coalesce);
1707 ethtool_notify(dev, ETHTOOL_MSG_COALESCE_NTF, NULL);
1711 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1713 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
1715 if (!dev->ethtool_ops->get_ringparam)
1718 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1720 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1725 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1727 struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
1730 if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
1733 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1736 dev->ethtool_ops->get_ringparam(dev, &max);
1738 /* ensure new ring parameters are within the maximums */
1739 if (ringparam.rx_pending > max.rx_max_pending ||
1740 ringparam.rx_mini_pending > max.rx_mini_max_pending ||
1741 ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending ||
1742 ringparam.tx_pending > max.tx_max_pending)
1745 ret = dev->ethtool_ops->set_ringparam(dev, &ringparam);
1747 ethtool_notify(dev, ETHTOOL_MSG_RINGS_NTF, NULL);
1751 static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1752 void __user *useraddr)
1754 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1756 if (!dev->ethtool_ops->get_channels)
1759 dev->ethtool_ops->get_channels(dev, &channels);
1761 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1766 static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1767 void __user *useraddr)
1769 struct ethtool_channels channels, curr = { .cmd = ETHTOOL_GCHANNELS };
1770 u16 from_channel, to_channel;
1771 u32 max_rx_in_use = 0;
1775 if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels)
1778 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1781 dev->ethtool_ops->get_channels(dev, &curr);
1783 if (channels.rx_count == curr.rx_count &&
1784 channels.tx_count == curr.tx_count &&
1785 channels.combined_count == curr.combined_count &&
1786 channels.other_count == curr.other_count)
1789 /* ensure new counts are within the maximums */
1790 if (channels.rx_count > curr.max_rx ||
1791 channels.tx_count > curr.max_tx ||
1792 channels.combined_count > curr.max_combined ||
1793 channels.other_count > curr.max_other)
1796 /* ensure there is at least one RX and one TX channel */
1797 if (!channels.combined_count &&
1798 (!channels.rx_count || !channels.tx_count))
1801 /* ensure the new Rx count fits within the configured Rx flow
1802 * indirection table settings */
1803 if (netif_is_rxfh_configured(dev) &&
1804 !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) &&
1805 (channels.combined_count + channels.rx_count) <= max_rx_in_use)
1808 /* Disabling channels, query zero-copy AF_XDP sockets */
1809 from_channel = channels.combined_count +
1810 min(channels.rx_count, channels.tx_count);
1811 to_channel = curr.combined_count + max(curr.rx_count, curr.tx_count);
1812 for (i = from_channel; i < to_channel; i++)
1813 if (xsk_get_pool_from_qid(dev, i))
1816 ret = dev->ethtool_ops->set_channels(dev, &channels);
1818 ethtool_notify(dev, ETHTOOL_MSG_CHANNELS_NTF, NULL);
1822 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1824 struct ethtool_pauseparam pauseparam = { .cmd = ETHTOOL_GPAUSEPARAM };
1826 if (!dev->ethtool_ops->get_pauseparam)
1829 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1831 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1836 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1838 struct ethtool_pauseparam pauseparam;
1841 if (!dev->ethtool_ops->set_pauseparam)
1844 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1847 ret = dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1849 ethtool_notify(dev, ETHTOOL_MSG_PAUSE_NTF, NULL);
1853 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1855 struct ethtool_test test;
1856 const struct ethtool_ops *ops = dev->ethtool_ops;
1860 if (!ops->self_test || !ops->get_sset_count)
1863 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1866 WARN_ON(test_len == 0);
1868 if (copy_from_user(&test, useraddr, sizeof(test)))
1871 test.len = test_len;
1872 data = kcalloc(test_len, sizeof(u64), GFP_USER);
1876 netif_testing_on(dev);
1877 ops->self_test(dev, &test, data);
1878 netif_testing_off(dev);
1881 if (copy_to_user(useraddr, &test, sizeof(test)))
1883 useraddr += sizeof(test);
1884 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1893 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1895 struct ethtool_gstrings gstrings;
1899 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1902 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
1905 if (ret > S32_MAX / ETH_GSTRING_LEN)
1912 data = vzalloc(array_size(gstrings.len, ETH_GSTRING_LEN));
1916 __ethtool_get_strings(dev, gstrings.string_set, data);
1922 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1924 useraddr += sizeof(gstrings);
1926 copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1935 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1937 struct ethtool_value id;
1939 const struct ethtool_ops *ops = dev->ethtool_ops;
1942 if (!ops->set_phys_id)
1948 if (copy_from_user(&id, useraddr, sizeof(id)))
1951 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
1955 /* Drop the RTNL lock while waiting, but prevent reentry or
1956 * removal of the device.
1963 /* Driver will handle this itself */
1964 schedule_timeout_interruptible(
1965 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
1967 /* Driver expects to be called at twice the frequency in rc */
1968 int n = rc * 2, interval = HZ / n;
1969 u64 count = mul_u32_u32(n, id.data);
1974 rc = ops->set_phys_id(dev,
1975 (i++ & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1979 schedule_timeout_interruptible(interval);
1980 } while (!signal_pending(current) && (!id.data || i < count));
1987 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1991 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1993 struct ethtool_stats stats;
1994 const struct ethtool_ops *ops = dev->ethtool_ops;
1998 if (!ops->get_ethtool_stats || !ops->get_sset_count)
2001 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
2004 if (n_stats > S32_MAX / sizeof(u64))
2006 WARN_ON_ONCE(!n_stats);
2007 if (copy_from_user(&stats, useraddr, sizeof(stats)))
2010 stats.n_stats = n_stats;
2013 data = vzalloc(array_size(n_stats, sizeof(u64)));
2016 ops->get_ethtool_stats(dev, &stats, data);
2022 if (copy_to_user(useraddr, &stats, sizeof(stats)))
2024 useraddr += sizeof(stats);
2025 if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64))))
2034 static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
2036 const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops;
2037 const struct ethtool_ops *ops = dev->ethtool_ops;
2038 struct phy_device *phydev = dev->phydev;
2039 struct ethtool_stats stats;
2043 if (!phydev && (!ops->get_ethtool_phy_stats || !ops->get_sset_count))
2046 if (dev->phydev && !ops->get_ethtool_phy_stats &&
2047 phy_ops && phy_ops->get_sset_count)
2048 n_stats = phy_ops->get_sset_count(dev->phydev);
2050 n_stats = ops->get_sset_count(dev, ETH_SS_PHY_STATS);
2053 if (n_stats > S32_MAX / sizeof(u64))
2055 if (WARN_ON_ONCE(!n_stats))
2058 if (copy_from_user(&stats, useraddr, sizeof(stats)))
2061 stats.n_stats = n_stats;
2064 data = vzalloc(array_size(n_stats, sizeof(u64)));
2068 if (dev->phydev && !ops->get_ethtool_phy_stats &&
2069 phy_ops && phy_ops->get_stats) {
2070 ret = phy_ops->get_stats(dev->phydev, &stats, data);
2074 ops->get_ethtool_phy_stats(dev, &stats, data);
2081 if (copy_to_user(useraddr, &stats, sizeof(stats)))
2083 useraddr += sizeof(stats);
2084 if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64))))
2093 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
2095 struct ethtool_perm_addr epaddr;
2097 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
2100 if (epaddr.size < dev->addr_len)
2102 epaddr.size = dev->addr_len;
2104 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
2106 useraddr += sizeof(epaddr);
2107 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
2112 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
2113 u32 cmd, u32 (*actor)(struct net_device *))
2115 struct ethtool_value edata = { .cmd = cmd };
2120 edata.data = actor(dev);
2122 if (copy_to_user(useraddr, &edata, sizeof(edata)))
2127 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
2128 void (*actor)(struct net_device *, u32))
2130 struct ethtool_value edata;
2135 if (copy_from_user(&edata, useraddr, sizeof(edata)))
2138 actor(dev, edata.data);
2142 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
2143 int (*actor)(struct net_device *, u32))
2145 struct ethtool_value edata;
2150 if (copy_from_user(&edata, useraddr, sizeof(edata)))
2153 return actor(dev, edata.data);
2156 static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
2157 char __user *useraddr)
2159 struct ethtool_flash efl;
2161 if (copy_from_user(&efl, useraddr, sizeof(efl)))
2163 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
2165 if (!dev->ethtool_ops->flash_device)
2166 return devlink_compat_flash_update(dev, efl.data);
2168 return dev->ethtool_ops->flash_device(dev, &efl);
2171 static int ethtool_set_dump(struct net_device *dev,
2172 void __user *useraddr)
2174 struct ethtool_dump dump;
2176 if (!dev->ethtool_ops->set_dump)
2179 if (copy_from_user(&dump, useraddr, sizeof(dump)))
2182 return dev->ethtool_ops->set_dump(dev, &dump);
2185 static int ethtool_get_dump_flag(struct net_device *dev,
2186 void __user *useraddr)
2189 struct ethtool_dump dump;
2190 const struct ethtool_ops *ops = dev->ethtool_ops;
2192 if (!ops->get_dump_flag)
2195 if (copy_from_user(&dump, useraddr, sizeof(dump)))
2198 ret = ops->get_dump_flag(dev, &dump);
2202 if (copy_to_user(useraddr, &dump, sizeof(dump)))
2207 static int ethtool_get_dump_data(struct net_device *dev,
2208 void __user *useraddr)
2212 struct ethtool_dump dump, tmp;
2213 const struct ethtool_ops *ops = dev->ethtool_ops;
2216 if (!ops->get_dump_data || !ops->get_dump_flag)
2219 if (copy_from_user(&dump, useraddr, sizeof(dump)))
2222 memset(&tmp, 0, sizeof(tmp));
2223 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
2224 ret = ops->get_dump_flag(dev, &tmp);
2228 len = min(tmp.len, dump.len);
2232 /* Don't ever let the driver think there's more space available
2233 * than it requested with .get_dump_flag().
2237 /* Always allocate enough space to hold the whole thing so that the
2238 * driver does not need to check the length and bother with partial
2241 data = vzalloc(tmp.len);
2244 ret = ops->get_dump_data(dev, &dump, data);
2248 /* There are two sane possibilities:
2249 * 1. The driver's .get_dump_data() does not touch dump.len.
2250 * 2. Or it may set dump.len to how much it really writes, which
2251 * should be tmp.len (or len if it can do a partial dump).
2252 * In any case respond to userspace with the actual length of data
2255 WARN_ON(dump.len != len && dump.len != tmp.len);
2258 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
2262 useraddr += offsetof(struct ethtool_dump, data);
2263 if (copy_to_user(useraddr, data, len))
2270 static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
2272 struct ethtool_ts_info info;
2275 err = __ethtool_get_ts_info(dev, &info);
2279 if (copy_to_user(useraddr, &info, sizeof(info)))
2285 static int __ethtool_get_module_info(struct net_device *dev,
2286 struct ethtool_modinfo *modinfo)
2288 const struct ethtool_ops *ops = dev->ethtool_ops;
2289 struct phy_device *phydev = dev->phydev;
2292 return sfp_get_module_info(dev->sfp_bus, modinfo);
2294 if (phydev && phydev->drv && phydev->drv->module_info)
2295 return phydev->drv->module_info(phydev, modinfo);
2297 if (ops->get_module_info)
2298 return ops->get_module_info(dev, modinfo);
2303 static int ethtool_get_module_info(struct net_device *dev,
2304 void __user *useraddr)
2307 struct ethtool_modinfo modinfo;
2309 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
2312 ret = __ethtool_get_module_info(dev, &modinfo);
2316 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
2322 static int __ethtool_get_module_eeprom(struct net_device *dev,
2323 struct ethtool_eeprom *ee, u8 *data)
2325 const struct ethtool_ops *ops = dev->ethtool_ops;
2326 struct phy_device *phydev = dev->phydev;
2329 return sfp_get_module_eeprom(dev->sfp_bus, ee, data);
2331 if (phydev && phydev->drv && phydev->drv->module_eeprom)
2332 return phydev->drv->module_eeprom(phydev, ee, data);
2334 if (ops->get_module_eeprom)
2335 return ops->get_module_eeprom(dev, ee, data);
2340 static int ethtool_get_module_eeprom(struct net_device *dev,
2341 void __user *useraddr)
2344 struct ethtool_modinfo modinfo;
2346 ret = __ethtool_get_module_info(dev, &modinfo);
2350 return ethtool_get_any_eeprom(dev, useraddr,
2351 __ethtool_get_module_eeprom,
2352 modinfo.eeprom_len);
2355 static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
2358 case ETHTOOL_RX_COPYBREAK:
2359 case ETHTOOL_TX_COPYBREAK:
2360 if (tuna->len != sizeof(u32) ||
2361 tuna->type_id != ETHTOOL_TUNABLE_U32)
2364 case ETHTOOL_PFC_PREVENTION_TOUT:
2365 if (tuna->len != sizeof(u16) ||
2366 tuna->type_id != ETHTOOL_TUNABLE_U16)
2376 static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
2379 struct ethtool_tunable tuna;
2380 const struct ethtool_ops *ops = dev->ethtool_ops;
2383 if (!ops->get_tunable)
2385 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
2387 ret = ethtool_tunable_valid(&tuna);
2390 data = kzalloc(tuna.len, GFP_USER);
2393 ret = ops->get_tunable(dev, &tuna, data);
2396 useraddr += sizeof(tuna);
2398 if (copy_to_user(useraddr, data, tuna.len))
2407 static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
2410 struct ethtool_tunable tuna;
2411 const struct ethtool_ops *ops = dev->ethtool_ops;
2414 if (!ops->set_tunable)
2416 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
2418 ret = ethtool_tunable_valid(&tuna);
2421 useraddr += sizeof(tuna);
2422 data = memdup_user(useraddr, tuna.len);
2424 return PTR_ERR(data);
2425 ret = ops->set_tunable(dev, &tuna, data);
2431 static noinline_for_stack int
2432 ethtool_get_per_queue_coalesce(struct net_device *dev,
2433 void __user *useraddr,
2434 struct ethtool_per_queue_op *per_queue_opt)
2438 DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE);
2440 if (!dev->ethtool_ops->get_per_queue_coalesce)
2443 useraddr += sizeof(*per_queue_opt);
2445 bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask,
2448 for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) {
2449 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
2451 ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, &coalesce);
2454 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
2456 useraddr += sizeof(coalesce);
2462 static noinline_for_stack int
2463 ethtool_set_per_queue_coalesce(struct net_device *dev,
2464 void __user *useraddr,
2465 struct ethtool_per_queue_op *per_queue_opt)
2470 struct ethtool_coalesce *backup = NULL, *tmp = NULL;
2471 DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE);
2473 if ((!dev->ethtool_ops->set_per_queue_coalesce) ||
2474 (!dev->ethtool_ops->get_per_queue_coalesce))
2477 useraddr += sizeof(*per_queue_opt);
2479 bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, MAX_NUM_QUEUE);
2480 n_queue = bitmap_weight(queue_mask, MAX_NUM_QUEUE);
2481 tmp = backup = kmalloc_array(n_queue, sizeof(*backup), GFP_KERNEL);
2485 for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) {
2486 struct ethtool_coalesce coalesce;
2488 ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, tmp);
2494 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) {
2499 if (!ethtool_set_coalesce_supported(dev, &coalesce)) {
2504 ret = dev->ethtool_ops->set_per_queue_coalesce(dev, bit, &coalesce);
2508 useraddr += sizeof(coalesce);
2514 for_each_set_bit(i, queue_mask, bit) {
2515 dev->ethtool_ops->set_per_queue_coalesce(dev, i, tmp);
2524 static int noinline_for_stack ethtool_set_per_queue(struct net_device *dev,
2525 void __user *useraddr, u32 sub_cmd)
2527 struct ethtool_per_queue_op per_queue_opt;
2529 if (copy_from_user(&per_queue_opt, useraddr, sizeof(per_queue_opt)))
2532 if (per_queue_opt.sub_command != sub_cmd)
2535 switch (per_queue_opt.sub_command) {
2536 case ETHTOOL_GCOALESCE:
2537 return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt);
2538 case ETHTOOL_SCOALESCE:
2539 return ethtool_set_per_queue_coalesce(dev, useraddr, &per_queue_opt);
2545 static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna)
2548 case ETHTOOL_PHY_DOWNSHIFT:
2549 case ETHTOOL_PHY_FAST_LINK_DOWN:
2550 if (tuna->len != sizeof(u8) ||
2551 tuna->type_id != ETHTOOL_TUNABLE_U8)
2554 case ETHTOOL_PHY_EDPD:
2555 if (tuna->len != sizeof(u16) ||
2556 tuna->type_id != ETHTOOL_TUNABLE_U16)
2566 static int get_phy_tunable(struct net_device *dev, void __user *useraddr)
2568 struct phy_device *phydev = dev->phydev;
2569 struct ethtool_tunable tuna;
2570 bool phy_drv_tunable;
2574 phy_drv_tunable = phydev && phydev->drv && phydev->drv->get_tunable;
2575 if (!phy_drv_tunable && !dev->ethtool_ops->get_phy_tunable)
2577 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
2579 ret = ethtool_phy_tunable_valid(&tuna);
2582 data = kzalloc(tuna.len, GFP_USER);
2585 if (phy_drv_tunable) {
2586 mutex_lock(&phydev->lock);
2587 ret = phydev->drv->get_tunable(phydev, &tuna, data);
2588 mutex_unlock(&phydev->lock);
2590 ret = dev->ethtool_ops->get_phy_tunable(dev, &tuna, data);
2594 useraddr += sizeof(tuna);
2596 if (copy_to_user(useraddr, data, tuna.len))
2605 static int set_phy_tunable(struct net_device *dev, void __user *useraddr)
2607 struct phy_device *phydev = dev->phydev;
2608 struct ethtool_tunable tuna;
2609 bool phy_drv_tunable;
2613 phy_drv_tunable = phydev && phydev->drv && phydev->drv->get_tunable;
2614 if (!phy_drv_tunable && !dev->ethtool_ops->set_phy_tunable)
2616 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
2618 ret = ethtool_phy_tunable_valid(&tuna);
2621 useraddr += sizeof(tuna);
2622 data = memdup_user(useraddr, tuna.len);
2624 return PTR_ERR(data);
2625 if (phy_drv_tunable) {
2626 mutex_lock(&phydev->lock);
2627 ret = phydev->drv->set_tunable(phydev, &tuna, data);
2628 mutex_unlock(&phydev->lock);
2630 ret = dev->ethtool_ops->set_phy_tunable(dev, &tuna, data);
2637 static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr)
2639 struct ethtool_fecparam fecparam = { .cmd = ETHTOOL_GFECPARAM };
2642 if (!dev->ethtool_ops->get_fecparam)
2645 rc = dev->ethtool_ops->get_fecparam(dev, &fecparam);
2649 if (copy_to_user(useraddr, &fecparam, sizeof(fecparam)))
2654 static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
2656 struct ethtool_fecparam fecparam;
2658 if (!dev->ethtool_ops->set_fecparam)
2661 if (copy_from_user(&fecparam, useraddr, sizeof(fecparam)))
2664 return dev->ethtool_ops->set_fecparam(dev, &fecparam);
2667 /* The main entry point in this file. Called from net/core/dev_ioctl.c */
2669 int dev_ethtool(struct net *net, struct ifreq *ifr)
2671 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
2672 void __user *useraddr = ifr->ifr_data;
2673 u32 ethcmd, sub_cmd;
2675 netdev_features_t old_features;
2677 if (!dev || !netif_device_present(dev))
2680 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
2683 if (ethcmd == ETHTOOL_PERQUEUE) {
2684 if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd)))
2689 /* Allow some commands to be done by anyone */
2692 case ETHTOOL_GDRVINFO:
2693 case ETHTOOL_GMSGLVL:
2695 case ETHTOOL_GCOALESCE:
2696 case ETHTOOL_GRINGPARAM:
2697 case ETHTOOL_GPAUSEPARAM:
2698 case ETHTOOL_GRXCSUM:
2699 case ETHTOOL_GTXCSUM:
2701 case ETHTOOL_GSSET_INFO:
2702 case ETHTOOL_GSTRINGS:
2703 case ETHTOOL_GSTATS:
2704 case ETHTOOL_GPHYSTATS:
2706 case ETHTOOL_GPERMADDR:
2710 case ETHTOOL_GFLAGS:
2711 case ETHTOOL_GPFLAGS:
2713 case ETHTOOL_GRXRINGS:
2714 case ETHTOOL_GRXCLSRLCNT:
2715 case ETHTOOL_GRXCLSRULE:
2716 case ETHTOOL_GRXCLSRLALL:
2717 case ETHTOOL_GRXFHINDIR:
2719 case ETHTOOL_GFEATURES:
2720 case ETHTOOL_GCHANNELS:
2721 case ETHTOOL_GET_TS_INFO:
2723 case ETHTOOL_GTUNABLE:
2724 case ETHTOOL_PHY_GTUNABLE:
2725 case ETHTOOL_GLINKSETTINGS:
2726 case ETHTOOL_GFECPARAM:
2729 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
2733 if (dev->ethtool_ops->begin) {
2734 rc = dev->ethtool_ops->begin(dev);
2738 old_features = dev->features;
2742 rc = ethtool_get_settings(dev, useraddr);
2745 rc = ethtool_set_settings(dev, useraddr);
2747 case ETHTOOL_GDRVINFO:
2748 rc = ethtool_get_drvinfo(dev, useraddr);
2751 rc = ethtool_get_regs(dev, useraddr);
2754 rc = ethtool_get_wol(dev, useraddr);
2757 rc = ethtool_set_wol(dev, useraddr);
2759 case ETHTOOL_GMSGLVL:
2760 rc = ethtool_get_value(dev, useraddr, ethcmd,
2761 dev->ethtool_ops->get_msglevel);
2763 case ETHTOOL_SMSGLVL:
2764 rc = ethtool_set_value_void(dev, useraddr,
2765 dev->ethtool_ops->set_msglevel);
2767 ethtool_notify(dev, ETHTOOL_MSG_DEBUG_NTF, NULL);
2770 rc = ethtool_get_eee(dev, useraddr);
2773 rc = ethtool_set_eee(dev, useraddr);
2775 case ETHTOOL_NWAY_RST:
2776 rc = ethtool_nway_reset(dev);
2779 rc = ethtool_get_link(dev, useraddr);
2781 case ETHTOOL_GEEPROM:
2782 rc = ethtool_get_eeprom(dev, useraddr);
2784 case ETHTOOL_SEEPROM:
2785 rc = ethtool_set_eeprom(dev, useraddr);
2787 case ETHTOOL_GCOALESCE:
2788 rc = ethtool_get_coalesce(dev, useraddr);
2790 case ETHTOOL_SCOALESCE:
2791 rc = ethtool_set_coalesce(dev, useraddr);
2793 case ETHTOOL_GRINGPARAM:
2794 rc = ethtool_get_ringparam(dev, useraddr);
2796 case ETHTOOL_SRINGPARAM:
2797 rc = ethtool_set_ringparam(dev, useraddr);
2799 case ETHTOOL_GPAUSEPARAM:
2800 rc = ethtool_get_pauseparam(dev, useraddr);
2802 case ETHTOOL_SPAUSEPARAM:
2803 rc = ethtool_set_pauseparam(dev, useraddr);
2806 rc = ethtool_self_test(dev, useraddr);
2808 case ETHTOOL_GSTRINGS:
2809 rc = ethtool_get_strings(dev, useraddr);
2811 case ETHTOOL_PHYS_ID:
2812 rc = ethtool_phys_id(dev, useraddr);
2814 case ETHTOOL_GSTATS:
2815 rc = ethtool_get_stats(dev, useraddr);
2817 case ETHTOOL_GPERMADDR:
2818 rc = ethtool_get_perm_addr(dev, useraddr);
2820 case ETHTOOL_GFLAGS:
2821 rc = ethtool_get_value(dev, useraddr, ethcmd,
2822 __ethtool_get_flags);
2824 case ETHTOOL_SFLAGS:
2825 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
2827 case ETHTOOL_GPFLAGS:
2828 rc = ethtool_get_value(dev, useraddr, ethcmd,
2829 dev->ethtool_ops->get_priv_flags);
2831 ethtool_notify(dev, ETHTOOL_MSG_PRIVFLAGS_NTF, NULL);
2833 case ETHTOOL_SPFLAGS:
2834 rc = ethtool_set_value(dev, useraddr,
2835 dev->ethtool_ops->set_priv_flags);
2838 case ETHTOOL_GRXRINGS:
2839 case ETHTOOL_GRXCLSRLCNT:
2840 case ETHTOOL_GRXCLSRULE:
2841 case ETHTOOL_GRXCLSRLALL:
2842 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
2845 case ETHTOOL_SRXCLSRLDEL:
2846 case ETHTOOL_SRXCLSRLINS:
2847 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
2849 case ETHTOOL_FLASHDEV:
2850 rc = ethtool_flash_device(dev, useraddr);
2853 rc = ethtool_reset(dev, useraddr);
2855 case ETHTOOL_GSSET_INFO:
2856 rc = ethtool_get_sset_info(dev, useraddr);
2858 case ETHTOOL_GRXFHINDIR:
2859 rc = ethtool_get_rxfh_indir(dev, useraddr);
2861 case ETHTOOL_SRXFHINDIR:
2862 rc = ethtool_set_rxfh_indir(dev, useraddr);
2865 rc = ethtool_get_rxfh(dev, useraddr);
2868 rc = ethtool_set_rxfh(dev, useraddr);
2870 case ETHTOOL_GFEATURES:
2871 rc = ethtool_get_features(dev, useraddr);
2873 case ETHTOOL_SFEATURES:
2874 rc = ethtool_set_features(dev, useraddr);
2876 case ETHTOOL_GTXCSUM:
2877 case ETHTOOL_GRXCSUM:
2882 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
2884 case ETHTOOL_STXCSUM:
2885 case ETHTOOL_SRXCSUM:
2890 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
2892 case ETHTOOL_GCHANNELS:
2893 rc = ethtool_get_channels(dev, useraddr);
2895 case ETHTOOL_SCHANNELS:
2896 rc = ethtool_set_channels(dev, useraddr);
2898 case ETHTOOL_SET_DUMP:
2899 rc = ethtool_set_dump(dev, useraddr);
2901 case ETHTOOL_GET_DUMP_FLAG:
2902 rc = ethtool_get_dump_flag(dev, useraddr);
2904 case ETHTOOL_GET_DUMP_DATA:
2905 rc = ethtool_get_dump_data(dev, useraddr);
2907 case ETHTOOL_GET_TS_INFO:
2908 rc = ethtool_get_ts_info(dev, useraddr);
2910 case ETHTOOL_GMODULEINFO:
2911 rc = ethtool_get_module_info(dev, useraddr);
2913 case ETHTOOL_GMODULEEEPROM:
2914 rc = ethtool_get_module_eeprom(dev, useraddr);
2916 case ETHTOOL_GTUNABLE:
2917 rc = ethtool_get_tunable(dev, useraddr);
2919 case ETHTOOL_STUNABLE:
2920 rc = ethtool_set_tunable(dev, useraddr);
2922 case ETHTOOL_GPHYSTATS:
2923 rc = ethtool_get_phy_stats(dev, useraddr);
2925 case ETHTOOL_PERQUEUE:
2926 rc = ethtool_set_per_queue(dev, useraddr, sub_cmd);
2928 case ETHTOOL_GLINKSETTINGS:
2929 rc = ethtool_get_link_ksettings(dev, useraddr);
2931 case ETHTOOL_SLINKSETTINGS:
2932 rc = ethtool_set_link_ksettings(dev, useraddr);
2934 case ETHTOOL_PHY_GTUNABLE:
2935 rc = get_phy_tunable(dev, useraddr);
2937 case ETHTOOL_PHY_STUNABLE:
2938 rc = set_phy_tunable(dev, useraddr);
2940 case ETHTOOL_GFECPARAM:
2941 rc = ethtool_get_fecparam(dev, useraddr);
2943 case ETHTOOL_SFECPARAM:
2944 rc = ethtool_set_fecparam(dev, useraddr);
2950 if (dev->ethtool_ops->complete)
2951 dev->ethtool_ops->complete(dev);
2953 if (old_features != dev->features)
2954 netdev_features_change(dev);
2959 struct ethtool_rx_flow_key {
2960 struct flow_dissector_key_basic basic;
2962 struct flow_dissector_key_ipv4_addrs ipv4;
2963 struct flow_dissector_key_ipv6_addrs ipv6;
2965 struct flow_dissector_key_ports tp;
2966 struct flow_dissector_key_ip ip;
2967 struct flow_dissector_key_vlan vlan;
2968 struct flow_dissector_key_eth_addrs eth_addrs;
2969 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
2971 struct ethtool_rx_flow_match {
2972 struct flow_dissector dissector;
2973 struct ethtool_rx_flow_key key;
2974 struct ethtool_rx_flow_key mask;
2977 struct ethtool_rx_flow_rule *
2978 ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input)
2980 const struct ethtool_rx_flow_spec *fs = input->fs;
2981 static struct in6_addr zero_addr = {};
2982 struct ethtool_rx_flow_match *match;
2983 struct ethtool_rx_flow_rule *flow;
2984 struct flow_action_entry *act;
2986 flow = kzalloc(sizeof(struct ethtool_rx_flow_rule) +
2987 sizeof(struct ethtool_rx_flow_match), GFP_KERNEL);
2989 return ERR_PTR(-ENOMEM);
2991 /* ethtool_rx supports only one single action per rule. */
2992 flow->rule = flow_rule_alloc(1);
2995 return ERR_PTR(-ENOMEM);
2998 match = (struct ethtool_rx_flow_match *)flow->priv;
2999 flow->rule->match.dissector = &match->dissector;
3000 flow->rule->match.mask = &match->mask;
3001 flow->rule->match.key = &match->key;
3003 match->mask.basic.n_proto = htons(0xffff);
3005 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) {
3007 const struct ethhdr *ether_spec, *ether_m_spec;
3009 ether_spec = &fs->h_u.ether_spec;
3010 ether_m_spec = &fs->m_u.ether_spec;
3012 if (!is_zero_ether_addr(ether_m_spec->h_source)) {
3013 ether_addr_copy(match->key.eth_addrs.src,
3014 ether_spec->h_source);
3015 ether_addr_copy(match->mask.eth_addrs.src,
3016 ether_m_spec->h_source);
3018 if (!is_zero_ether_addr(ether_m_spec->h_dest)) {
3019 ether_addr_copy(match->key.eth_addrs.dst,
3020 ether_spec->h_dest);
3021 ether_addr_copy(match->mask.eth_addrs.dst,
3022 ether_m_spec->h_dest);
3024 if (ether_m_spec->h_proto) {
3025 match->key.basic.n_proto = ether_spec->h_proto;
3026 match->mask.basic.n_proto = ether_m_spec->h_proto;
3032 const struct ethtool_tcpip4_spec *v4_spec, *v4_m_spec;
3034 match->key.basic.n_proto = htons(ETH_P_IP);
3036 v4_spec = &fs->h_u.tcp_ip4_spec;
3037 v4_m_spec = &fs->m_u.tcp_ip4_spec;
3039 if (v4_m_spec->ip4src) {
3040 match->key.ipv4.src = v4_spec->ip4src;
3041 match->mask.ipv4.src = v4_m_spec->ip4src;
3043 if (v4_m_spec->ip4dst) {
3044 match->key.ipv4.dst = v4_spec->ip4dst;
3045 match->mask.ipv4.dst = v4_m_spec->ip4dst;
3047 if (v4_m_spec->ip4src ||
3048 v4_m_spec->ip4dst) {
3049 match->dissector.used_keys |=
3050 BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS);
3051 match->dissector.offset[FLOW_DISSECTOR_KEY_IPV4_ADDRS] =
3052 offsetof(struct ethtool_rx_flow_key, ipv4);
3054 if (v4_m_spec->psrc) {
3055 match->key.tp.src = v4_spec->psrc;
3056 match->mask.tp.src = v4_m_spec->psrc;
3058 if (v4_m_spec->pdst) {
3059 match->key.tp.dst = v4_spec->pdst;
3060 match->mask.tp.dst = v4_m_spec->pdst;
3062 if (v4_m_spec->psrc ||
3064 match->dissector.used_keys |=
3065 BIT(FLOW_DISSECTOR_KEY_PORTS);
3066 match->dissector.offset[FLOW_DISSECTOR_KEY_PORTS] =
3067 offsetof(struct ethtool_rx_flow_key, tp);
3069 if (v4_m_spec->tos) {
3070 match->key.ip.tos = v4_spec->tos;
3071 match->mask.ip.tos = v4_m_spec->tos;
3072 match->dissector.used_keys |=
3073 BIT(FLOW_DISSECTOR_KEY_IP);
3074 match->dissector.offset[FLOW_DISSECTOR_KEY_IP] =
3075 offsetof(struct ethtool_rx_flow_key, ip);
3081 const struct ethtool_tcpip6_spec *v6_spec, *v6_m_spec;
3083 match->key.basic.n_proto = htons(ETH_P_IPV6);
3085 v6_spec = &fs->h_u.tcp_ip6_spec;
3086 v6_m_spec = &fs->m_u.tcp_ip6_spec;
3087 if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr))) {
3088 memcpy(&match->key.ipv6.src, v6_spec->ip6src,
3089 sizeof(match->key.ipv6.src));
3090 memcpy(&match->mask.ipv6.src, v6_m_spec->ip6src,
3091 sizeof(match->mask.ipv6.src));
3093 if (memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) {
3094 memcpy(&match->key.ipv6.dst, v6_spec->ip6dst,
3095 sizeof(match->key.ipv6.dst));
3096 memcpy(&match->mask.ipv6.dst, v6_m_spec->ip6dst,
3097 sizeof(match->mask.ipv6.dst));
3099 if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr)) ||
3100 memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) {
3101 match->dissector.used_keys |=
3102 BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS);
3103 match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] =
3104 offsetof(struct ethtool_rx_flow_key, ipv6);
3106 if (v6_m_spec->psrc) {
3107 match->key.tp.src = v6_spec->psrc;
3108 match->mask.tp.src = v6_m_spec->psrc;
3110 if (v6_m_spec->pdst) {
3111 match->key.tp.dst = v6_spec->pdst;
3112 match->mask.tp.dst = v6_m_spec->pdst;
3114 if (v6_m_spec->psrc ||
3116 match->dissector.used_keys |=
3117 BIT(FLOW_DISSECTOR_KEY_PORTS);
3118 match->dissector.offset[FLOW_DISSECTOR_KEY_PORTS] =
3119 offsetof(struct ethtool_rx_flow_key, tp);
3121 if (v6_m_spec->tclass) {
3122 match->key.ip.tos = v6_spec->tclass;
3123 match->mask.ip.tos = v6_m_spec->tclass;
3124 match->dissector.used_keys |=
3125 BIT(FLOW_DISSECTOR_KEY_IP);
3126 match->dissector.offset[FLOW_DISSECTOR_KEY_IP] =
3127 offsetof(struct ethtool_rx_flow_key, ip);
3132 ethtool_rx_flow_rule_destroy(flow);
3133 return ERR_PTR(-EINVAL);
3136 switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) {
3139 match->key.basic.ip_proto = IPPROTO_TCP;
3140 match->mask.basic.ip_proto = 0xff;
3144 match->key.basic.ip_proto = IPPROTO_UDP;
3145 match->mask.basic.ip_proto = 0xff;
3149 match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_BASIC);
3150 match->dissector.offset[FLOW_DISSECTOR_KEY_BASIC] =
3151 offsetof(struct ethtool_rx_flow_key, basic);
3153 if (fs->flow_type & FLOW_EXT) {
3154 const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext;
3155 const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext;
3157 if (ext_m_spec->vlan_etype) {
3158 match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype;
3159 match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype;
3162 if (ext_m_spec->vlan_tci) {
3163 match->key.vlan.vlan_id =
3164 ntohs(ext_h_spec->vlan_tci) & 0x0fff;
3165 match->mask.vlan.vlan_id =
3166 ntohs(ext_m_spec->vlan_tci) & 0x0fff;
3168 match->key.vlan.vlan_dei =
3169 !!(ext_h_spec->vlan_tci & htons(0x1000));
3170 match->mask.vlan.vlan_dei =
3171 !!(ext_m_spec->vlan_tci & htons(0x1000));
3173 match->key.vlan.vlan_priority =
3174 (ntohs(ext_h_spec->vlan_tci) & 0xe000) >> 13;
3175 match->mask.vlan.vlan_priority =
3176 (ntohs(ext_m_spec->vlan_tci) & 0xe000) >> 13;
3179 if (ext_m_spec->vlan_etype ||
3180 ext_m_spec->vlan_tci) {
3181 match->dissector.used_keys |=
3182 BIT(FLOW_DISSECTOR_KEY_VLAN);
3183 match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] =
3184 offsetof(struct ethtool_rx_flow_key, vlan);
3187 if (fs->flow_type & FLOW_MAC_EXT) {
3188 const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext;
3189 const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext;
3191 memcpy(match->key.eth_addrs.dst, ext_h_spec->h_dest,
3193 memcpy(match->mask.eth_addrs.dst, ext_m_spec->h_dest,
3196 match->dissector.used_keys |=
3197 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS);
3198 match->dissector.offset[FLOW_DISSECTOR_KEY_ETH_ADDRS] =
3199 offsetof(struct ethtool_rx_flow_key, eth_addrs);
3202 act = &flow->rule->action.entries[0];
3203 switch (fs->ring_cookie) {
3204 case RX_CLS_FLOW_DISC:
3205 act->id = FLOW_ACTION_DROP;
3207 case RX_CLS_FLOW_WAKE:
3208 act->id = FLOW_ACTION_WAKE;
3211 act->id = FLOW_ACTION_QUEUE;
3212 if (fs->flow_type & FLOW_RSS)
3213 act->queue.ctx = input->rss_ctx;
3215 act->queue.vf = ethtool_get_flow_spec_ring_vf(fs->ring_cookie);
3216 act->queue.index = ethtool_get_flow_spec_ring(fs->ring_cookie);
3222 EXPORT_SYMBOL(ethtool_rx_flow_rule_create);
3224 void ethtool_rx_flow_rule_destroy(struct ethtool_rx_flow_rule *flow)
3229 EXPORT_SYMBOL(ethtool_rx_flow_rule_destroy);