Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * net/core/ethtool.c - Ethtool ioctl handler |
| 4 | * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx> |
| 5 | * |
| 6 | * This file is where we call all the ethtool_ops commands to get |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 7 | * the information ethtool needs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 10 | #include <linux/compat.h> |
Jakub Kicinski | b645941 | 2021-12-28 16:49:13 -0800 | [diff] [blame] | 11 | #include <linux/etherdevice.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/types.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 14 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | #include <linux/ethtool.h> |
| 17 | #include <linux/netdevice.h> |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 18 | #include <linux/net_tstamp.h> |
| 19 | #include <linux/phy.h> |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 20 | #include <linux/bitops.h> |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
David S. Miller | 73da16c | 2010-09-21 16:12:11 -0700 | [diff] [blame] | 22 | #include <linux/vmalloc.h> |
Russell King | e679c9c | 2018-03-28 15:44:16 -0700 | [diff] [blame] | 23 | #include <linux/sfp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 25 | #include <linux/rtnetlink.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 26 | #include <linux/sched/signal.h> |
Eric Dumazet | 960fb62 | 2014-11-16 06:23:05 -0800 | [diff] [blame] | 27 | #include <linux/net.h> |
Heiner Kallweit | f32a213 | 2021-08-01 12:36:48 +0200 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
Jakub Kicinski | ddb6e99 | 2019-01-31 10:50:47 -0800 | [diff] [blame] | 29 | #include <net/devlink.h> |
Magnus Karlsson | a71506a | 2020-05-20 21:20:51 +0200 | [diff] [blame] | 30 | #include <net/xdp_sock_drv.h> |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 31 | #include <net/flow_offload.h> |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 32 | #include <linux/ethtool_netlink.h> |
Leon Romanovsky | 1c79031 | 2020-04-19 17:18:47 +0300 | [diff] [blame] | 33 | #include <generated/utsrelease.h> |
Michal Kubecek | d44e131 | 2019-12-11 10:58:29 +0100 | [diff] [blame] | 34 | #include "common.h" |
| 35 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 36 | /* State held across locks and calls for commands which have devlink fallback */ |
| 37 | struct ethtool_devlink_compat { |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 38 | struct devlink *devlink; |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 39 | union { |
| 40 | struct ethtool_flash efl; |
| 41 | struct ethtool_drvinfo info; |
| 42 | }; |
| 43 | }; |
| 44 | |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 45 | static struct devlink *netdev_to_devlink_get(struct net_device *dev) |
| 46 | { |
| 47 | struct devlink_port *devlink_port; |
| 48 | |
| 49 | if (!dev->netdev_ops->ndo_get_devlink_port) |
| 50 | return NULL; |
| 51 | |
| 52 | devlink_port = dev->netdev_ops->ndo_get_devlink_port(dev); |
| 53 | if (!devlink_port) |
| 54 | return NULL; |
| 55 | |
| 56 | return devlink_try_get(devlink_port->devlink); |
| 57 | } |
| 58 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 59 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * Some useful ethtool_ops methods that're device independent. |
| 61 | * If we find that all drivers want to do the same thing here, |
| 62 | * we can turn these into dev_() function calls. |
| 63 | */ |
| 64 | |
| 65 | u32 ethtool_op_get_link(struct net_device *dev) |
| 66 | { |
| 67 | return netif_carrier_ok(dev) ? 1 : 0; |
| 68 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 69 | EXPORT_SYMBOL(ethtool_op_get_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Richard Cochran | 02eacbd | 2012-04-03 22:59:22 +0000 | [diff] [blame] | 71 | int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
| 72 | { |
| 73 | info->so_timestamping = |
| 74 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 75 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 76 | SOF_TIMESTAMPING_SOFTWARE; |
| 77 | info->phc_index = -1; |
| 78 | return 0; |
| 79 | } |
| 80 | EXPORT_SYMBOL(ethtool_op_get_ts_info); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Handlers for each ethtool command */ |
| 83 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 84 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
| 85 | { |
| 86 | struct ethtool_gfeatures cmd = { |
| 87 | .cmd = ETHTOOL_GFEATURES, |
| 88 | .size = ETHTOOL_DEV_FEATURE_WORDS, |
| 89 | }; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 90 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 91 | u32 __user *sizeaddr; |
| 92 | u32 copy_size; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 93 | int i; |
| 94 | |
| 95 | /* in case feature bits run out again */ |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 96 | BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t)); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 97 | |
| 98 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 99 | features[i].available = (u32)(dev->hw_features >> (32 * i)); |
| 100 | features[i].requested = (u32)(dev->wanted_features >> (32 * i)); |
| 101 | features[i].active = (u32)(dev->features >> (32 * i)); |
| 102 | features[i].never_changed = |
| 103 | (u32)(NETIF_F_NEVER_CHANGE >> (32 * i)); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 104 | } |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 105 | |
| 106 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); |
| 107 | if (get_user(copy_size, sizeaddr)) |
| 108 | return -EFAULT; |
| 109 | |
| 110 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) |
| 111 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; |
| 112 | |
| 113 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 114 | return -EFAULT; |
| 115 | useraddr += sizeof(cmd); |
Gustavo A. R. Silva | ed71761 | 2021-09-28 14:57:35 -0500 | [diff] [blame] | 116 | if (copy_to_user(useraddr, features, |
| 117 | array_size(copy_size, sizeof(*features)))) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 118 | return -EFAULT; |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) |
| 124 | { |
| 125 | struct ethtool_sfeatures cmd; |
| 126 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 127 | netdev_features_t wanted = 0, valid = 0; |
| 128 | int i, ret = 0; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 129 | |
| 130 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 131 | return -EFAULT; |
| 132 | useraddr += sizeof(cmd); |
| 133 | |
| 134 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | if (copy_from_user(features, useraddr, sizeof(features))) |
| 138 | return -EFAULT; |
| 139 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 140 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 141 | valid |= (netdev_features_t)features[i].valid << (32 * i); |
| 142 | wanted |= (netdev_features_t)features[i].requested << (32 * i); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if (valid & ~NETIF_F_ETHTOOL_BITS) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 146 | return -EINVAL; |
| 147 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 148 | if (valid & ~dev->hw_features) { |
| 149 | valid &= dev->hw_features; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 150 | ret |= ETHTOOL_F_UNSUPPORTED; |
| 151 | } |
| 152 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 153 | dev->wanted_features &= ~valid; |
| 154 | dev->wanted_features |= wanted & valid; |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 155 | __netdev_update_features(dev); |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 156 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 157 | if ((dev->wanted_features ^ dev->features) & valid) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 158 | ret |= ETHTOOL_F_WISH; |
| 159 | |
| 160 | return ret; |
| 161 | } |
| 162 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 163 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
| 164 | { |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 165 | const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops; |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 166 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 167 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 168 | if (sset == ETH_SS_FEATURES) |
| 169 | return ARRAY_SIZE(netdev_features_strings); |
| 170 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 171 | if (sset == ETH_SS_RSS_HASH_FUNCS) |
| 172 | return ARRAY_SIZE(rss_hash_func_strings); |
| 173 | |
Hadar Hen Zion | a4244b0 | 2015-06-11 10:28:16 +0300 | [diff] [blame] | 174 | if (sset == ETH_SS_TUNABLES) |
| 175 | return ARRAY_SIZE(tunable_strings); |
| 176 | |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 177 | if (sset == ETH_SS_PHY_TUNABLES) |
| 178 | return ARRAY_SIZE(phy_tunable_strings); |
| 179 | |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 180 | if (sset == ETH_SS_PHY_STATS && dev->phydev && |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 181 | !ops->get_ethtool_phy_stats && |
| 182 | phy_ops && phy_ops->get_sset_count) |
| 183 | return phy_ops->get_sset_count(dev->phydev); |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 184 | |
Michal Kubecek | 428c122 | 2019-12-11 10:58:34 +0100 | [diff] [blame] | 185 | if (sset == ETH_SS_LINK_MODES) |
| 186 | return __ETHTOOL_LINK_MODE_MASK_NBITS; |
| 187 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 188 | if (ops->get_sset_count && ops->get_strings) |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 189 | return ops->get_sset_count(dev, sset); |
| 190 | else |
| 191 | return -EOPNOTSUPP; |
| 192 | } |
| 193 | |
| 194 | static void __ethtool_get_strings(struct net_device *dev, |
| 195 | u32 stringset, u8 *data) |
| 196 | { |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 197 | const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops; |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 198 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 199 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 200 | if (stringset == ETH_SS_FEATURES) |
| 201 | memcpy(data, netdev_features_strings, |
| 202 | sizeof(netdev_features_strings)); |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 203 | else if (stringset == ETH_SS_RSS_HASH_FUNCS) |
| 204 | memcpy(data, rss_hash_func_strings, |
| 205 | sizeof(rss_hash_func_strings)); |
Hadar Hen Zion | a4244b0 | 2015-06-11 10:28:16 +0300 | [diff] [blame] | 206 | else if (stringset == ETH_SS_TUNABLES) |
| 207 | memcpy(data, tunable_strings, sizeof(tunable_strings)); |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 208 | else if (stringset == ETH_SS_PHY_TUNABLES) |
| 209 | memcpy(data, phy_tunable_strings, sizeof(phy_tunable_strings)); |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 210 | else if (stringset == ETH_SS_PHY_STATS && dev->phydev && |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 211 | !ops->get_ethtool_phy_stats && phy_ops && |
| 212 | phy_ops->get_strings) |
| 213 | phy_ops->get_strings(dev->phydev, data); |
Michal Kubecek | 428c122 | 2019-12-11 10:58:34 +0100 | [diff] [blame] | 214 | else if (stringset == ETH_SS_LINK_MODES) |
| 215 | memcpy(data, link_mode_names, |
| 216 | __ETHTOOL_LINK_MODE_MASK_NBITS * ETH_GSTRING_LEN); |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 217 | else |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 218 | /* ops->get_strings is valid because checked earlier */ |
| 219 | ops->get_strings(dev, stringset, data); |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 222 | static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 223 | { |
| 224 | /* feature masks of legacy discrete ethtool ops */ |
| 225 | |
| 226 | switch (eth_cmd) { |
| 227 | case ETHTOOL_GTXCSUM: |
| 228 | case ETHTOOL_STXCSUM: |
Vladyslav Tarasiuk | 9d648fb | 2020-03-24 13:57:08 +0200 | [diff] [blame] | 229 | return NETIF_F_CSUM_MASK | NETIF_F_FCOE_CRC | |
Michal Kubecek | f70bb06 | 2020-03-12 21:07:43 +0100 | [diff] [blame] | 230 | NETIF_F_SCTP_CRC; |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 231 | case ETHTOOL_GRXCSUM: |
| 232 | case ETHTOOL_SRXCSUM: |
| 233 | return NETIF_F_RXCSUM; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 234 | case ETHTOOL_GSG: |
| 235 | case ETHTOOL_SSG: |
Michal Kubecek | f70bb06 | 2020-03-12 21:07:43 +0100 | [diff] [blame] | 236 | return NETIF_F_SG | NETIF_F_FRAGLIST; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 237 | case ETHTOOL_GTSO: |
| 238 | case ETHTOOL_STSO: |
| 239 | return NETIF_F_ALL_TSO; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 240 | case ETHTOOL_GGSO: |
| 241 | case ETHTOOL_SGSO: |
| 242 | return NETIF_F_GSO; |
| 243 | case ETHTOOL_GGRO: |
| 244 | case ETHTOOL_SGRO: |
| 245 | return NETIF_F_GRO; |
| 246 | default: |
| 247 | BUG(); |
| 248 | } |
| 249 | } |
| 250 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 251 | static int ethtool_get_one_feature(struct net_device *dev, |
| 252 | char __user *useraddr, u32 ethcmd) |
| 253 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 254 | netdev_features_t mask = ethtool_get_feature_mask(ethcmd); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 255 | struct ethtool_value edata = { |
| 256 | .cmd = ethcmd, |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 257 | .data = !!(dev->features & mask), |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 258 | }; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 259 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 260 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 261 | return -EFAULT; |
| 262 | return 0; |
| 263 | } |
| 264 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 265 | static int ethtool_set_one_feature(struct net_device *dev, |
| 266 | void __user *useraddr, u32 ethcmd) |
| 267 | { |
| 268 | struct ethtool_value edata; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 269 | netdev_features_t mask; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 270 | |
| 271 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 272 | return -EFAULT; |
| 273 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 274 | mask = ethtool_get_feature_mask(ethcmd); |
| 275 | mask &= dev->hw_features; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 276 | if (!mask) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 277 | return -EOPNOTSUPP; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 278 | |
| 279 | if (edata.data) |
| 280 | dev->wanted_features |= mask; |
| 281 | else |
| 282 | dev->wanted_features &= ~mask; |
| 283 | |
| 284 | __netdev_update_features(dev); |
| 285 | |
| 286 | return 0; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 289 | #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \ |
| 290 | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH) |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 291 | #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \ |
| 292 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \ |
| 293 | NETIF_F_RXHASH) |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 294 | |
| 295 | static u32 __ethtool_get_flags(struct net_device *dev) |
| 296 | { |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 297 | u32 flags = 0; |
| 298 | |
Dragos Foianu | 8a73125 | 2013-07-13 14:43:00 +0100 | [diff] [blame] | 299 | if (dev->features & NETIF_F_LRO) |
| 300 | flags |= ETH_FLAG_LRO; |
| 301 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 302 | flags |= ETH_FLAG_RXVLAN; |
| 303 | if (dev->features & NETIF_F_HW_VLAN_CTAG_TX) |
| 304 | flags |= ETH_FLAG_TXVLAN; |
| 305 | if (dev->features & NETIF_F_NTUPLE) |
| 306 | flags |= ETH_FLAG_NTUPLE; |
| 307 | if (dev->features & NETIF_F_RXHASH) |
| 308 | flags |= ETH_FLAG_RXHASH; |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 309 | |
| 310 | return flags; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 314 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 315 | netdev_features_t features = 0, changed; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 316 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 317 | if (data & ~ETH_ALL_FLAGS) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | |
Dragos Foianu | 8a73125 | 2013-07-13 14:43:00 +0100 | [diff] [blame] | 320 | if (data & ETH_FLAG_LRO) |
| 321 | features |= NETIF_F_LRO; |
| 322 | if (data & ETH_FLAG_RXVLAN) |
| 323 | features |= NETIF_F_HW_VLAN_CTAG_RX; |
| 324 | if (data & ETH_FLAG_TXVLAN) |
| 325 | features |= NETIF_F_HW_VLAN_CTAG_TX; |
| 326 | if (data & ETH_FLAG_NTUPLE) |
| 327 | features |= NETIF_F_NTUPLE; |
| 328 | if (data & ETH_FLAG_RXHASH) |
| 329 | features |= NETIF_F_RXHASH; |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 330 | |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 331 | /* allow changing only bits set in hw_features */ |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 332 | changed = (features ^ dev->features) & ETH_ALL_FEATURES; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 333 | if (changed & ~dev->hw_features) |
| 334 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; |
| 335 | |
| 336 | dev->wanted_features = |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 337 | (dev->wanted_features & ~changed) | (features & changed); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 338 | |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 339 | __netdev_update_features(dev); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
Alan Brady | 5a6cd6d | 2017-10-05 14:53:40 -0700 | [diff] [blame] | 344 | /* Given two link masks, AND them together and save the result in dst. */ |
| 345 | void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst, |
| 346 | struct ethtool_link_ksettings *src) |
| 347 | { |
| 348 | unsigned int size = BITS_TO_LONGS(__ETHTOOL_LINK_MODE_MASK_NBITS); |
| 349 | unsigned int idx = 0; |
| 350 | |
| 351 | for (; idx < size; idx++) { |
| 352 | dst->link_modes.supported[idx] &= |
| 353 | src->link_modes.supported[idx]; |
| 354 | dst->link_modes.advertising[idx] &= |
| 355 | src->link_modes.advertising[idx]; |
| 356 | } |
| 357 | } |
| 358 | EXPORT_SYMBOL(ethtool_intersect_link_masks); |
| 359 | |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 360 | void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst, |
| 361 | u32 legacy_u32) |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 362 | { |
Sean Anderson | 4973056 | 2021-10-22 18:41:04 -0400 | [diff] [blame] | 363 | linkmode_zero(dst); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 364 | dst[0] = legacy_u32; |
| 365 | } |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 366 | EXPORT_SYMBOL(ethtool_convert_legacy_u32_to_link_mode); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 367 | |
| 368 | /* return false if src had higher bits set. lower bits always updated. */ |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 369 | bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, |
| 370 | const unsigned long *src) |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 371 | { |
| 372 | bool retval = true; |
| 373 | |
| 374 | /* TODO: following test will soon always be true */ |
| 375 | if (__ETHTOOL_LINK_MODE_MASK_NBITS > 32) { |
| 376 | __ETHTOOL_DECLARE_LINK_MODE_MASK(ext); |
| 377 | |
Sean Anderson | 4973056 | 2021-10-22 18:41:04 -0400 | [diff] [blame] | 378 | linkmode_zero(ext); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 379 | bitmap_fill(ext, 32); |
| 380 | bitmap_complement(ext, ext, __ETHTOOL_LINK_MODE_MASK_NBITS); |
Sean Anderson | 4973056 | 2021-10-22 18:41:04 -0400 | [diff] [blame] | 381 | if (linkmode_intersects(ext, src)) { |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 382 | /* src mask goes beyond bit 31 */ |
| 383 | retval = false; |
| 384 | } |
| 385 | } |
| 386 | *legacy_u32 = src[0]; |
| 387 | return retval; |
| 388 | } |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 389 | EXPORT_SYMBOL(ethtool_convert_link_mode_to_legacy_u32); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 390 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 391 | /* return false if ksettings link modes had higher bits |
| 392 | * set. legacy_settings always updated (best effort) |
| 393 | */ |
| 394 | static bool |
| 395 | convert_link_ksettings_to_legacy_settings( |
| 396 | struct ethtool_cmd *legacy_settings, |
| 397 | const struct ethtool_link_ksettings *link_ksettings) |
| 398 | { |
| 399 | bool retval = true; |
| 400 | |
| 401 | memset(legacy_settings, 0, sizeof(*legacy_settings)); |
| 402 | /* this also clears the deprecated fields in legacy structure: |
| 403 | * __u8 transceiver; |
| 404 | * __u32 maxtxpkt; |
| 405 | * __u32 maxrxpkt; |
| 406 | */ |
| 407 | |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 408 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 409 | &legacy_settings->supported, |
| 410 | link_ksettings->link_modes.supported); |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 411 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 412 | &legacy_settings->advertising, |
| 413 | link_ksettings->link_modes.advertising); |
Philippe Reynes | 6d62b4d | 2016-04-15 00:34:59 +0200 | [diff] [blame] | 414 | retval &= ethtool_convert_link_mode_to_legacy_u32( |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 415 | &legacy_settings->lp_advertising, |
| 416 | link_ksettings->link_modes.lp_advertising); |
| 417 | ethtool_cmd_speed_set(legacy_settings, link_ksettings->base.speed); |
| 418 | legacy_settings->duplex |
| 419 | = link_ksettings->base.duplex; |
| 420 | legacy_settings->port |
| 421 | = link_ksettings->base.port; |
| 422 | legacy_settings->phy_address |
| 423 | = link_ksettings->base.phy_address; |
| 424 | legacy_settings->autoneg |
| 425 | = link_ksettings->base.autoneg; |
| 426 | legacy_settings->mdio_support |
| 427 | = link_ksettings->base.mdio_support; |
| 428 | legacy_settings->eth_tp_mdix |
| 429 | = link_ksettings->base.eth_tp_mdix; |
| 430 | legacy_settings->eth_tp_mdix_ctrl |
| 431 | = link_ksettings->base.eth_tp_mdix_ctrl; |
Florian Fainelli | 19cab88 | 2017-09-20 15:52:13 -0700 | [diff] [blame] | 432 | legacy_settings->transceiver |
| 433 | = link_ksettings->base.transceiver; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 434 | return retval; |
| 435 | } |
| 436 | |
| 437 | /* number of 32-bit words to store the user's link mode bitmaps */ |
| 438 | #define __ETHTOOL_LINK_MODE_MASK_NU32 \ |
| 439 | DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32) |
| 440 | |
| 441 | /* layout of the struct passed from/to userland */ |
| 442 | struct ethtool_link_usettings { |
| 443 | struct ethtool_link_settings base; |
| 444 | struct { |
| 445 | __u32 supported[__ETHTOOL_LINK_MODE_MASK_NU32]; |
| 446 | __u32 advertising[__ETHTOOL_LINK_MODE_MASK_NU32]; |
| 447 | __u32 lp_advertising[__ETHTOOL_LINK_MODE_MASK_NU32]; |
| 448 | } link_modes; |
| 449 | }; |
| 450 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 451 | /* Internal kernel helper to query a device ethtool_link_settings. */ |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 452 | int __ethtool_get_link_ksettings(struct net_device *dev, |
| 453 | struct ethtool_link_ksettings *link_ksettings) |
| 454 | { |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 455 | ASSERT_RTNL(); |
| 456 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 457 | if (!dev->ethtool_ops->get_link_ksettings) |
David Decotigny | 3237fc6 | 2016-02-24 10:58:11 -0800 | [diff] [blame] | 458 | return -EOPNOTSUPP; |
| 459 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 460 | memset(link_ksettings, 0, sizeof(*link_ksettings)); |
Danielle Ratson | a975d7d | 2021-04-07 13:06:51 +0300 | [diff] [blame] | 461 | return dev->ethtool_ops->get_link_ksettings(dev, link_ksettings); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 462 | } |
| 463 | EXPORT_SYMBOL(__ethtool_get_link_ksettings); |
| 464 | |
| 465 | /* convert ethtool_link_usettings in user space to a kernel internal |
| 466 | * ethtool_link_ksettings. return 0 on success, errno on error. |
| 467 | */ |
| 468 | static int load_link_ksettings_from_user(struct ethtool_link_ksettings *to, |
| 469 | const void __user *from) |
| 470 | { |
| 471 | struct ethtool_link_usettings link_usettings; |
| 472 | |
| 473 | if (copy_from_user(&link_usettings, from, sizeof(link_usettings))) |
| 474 | return -EFAULT; |
| 475 | |
| 476 | memcpy(&to->base, &link_usettings.base, sizeof(to->base)); |
Yury Norov | 3aa5688 | 2018-02-06 15:38:06 -0800 | [diff] [blame] | 477 | bitmap_from_arr32(to->link_modes.supported, |
| 478 | link_usettings.link_modes.supported, |
| 479 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 480 | bitmap_from_arr32(to->link_modes.advertising, |
| 481 | link_usettings.link_modes.advertising, |
| 482 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 483 | bitmap_from_arr32(to->link_modes.lp_advertising, |
| 484 | link_usettings.link_modes.lp_advertising, |
| 485 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
Cris Forno | 70ae1e1 | 2020-02-28 14:12:04 -0600 | [diff] [blame] | 490 | /* Check if the user is trying to change anything besides speed/duplex */ |
| 491 | bool ethtool_virtdev_validate_cmd(const struct ethtool_link_ksettings *cmd) |
| 492 | { |
| 493 | struct ethtool_link_settings base2 = {}; |
| 494 | |
| 495 | base2.speed = cmd->base.speed; |
| 496 | base2.port = PORT_OTHER; |
| 497 | base2.duplex = cmd->base.duplex; |
| 498 | base2.cmd = cmd->base.cmd; |
| 499 | base2.link_mode_masks_nwords = cmd->base.link_mode_masks_nwords; |
| 500 | |
| 501 | return !memcmp(&base2, &cmd->base, sizeof(base2)) && |
| 502 | bitmap_empty(cmd->link_modes.supported, |
| 503 | __ETHTOOL_LINK_MODE_MASK_NBITS) && |
| 504 | bitmap_empty(cmd->link_modes.lp_advertising, |
| 505 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 506 | } |
| 507 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 508 | /* convert a kernel internal ethtool_link_ksettings to |
| 509 | * ethtool_link_usettings in user space. return 0 on success, errno on |
| 510 | * error. |
| 511 | */ |
| 512 | static int |
| 513 | store_link_ksettings_for_user(void __user *to, |
| 514 | const struct ethtool_link_ksettings *from) |
| 515 | { |
| 516 | struct ethtool_link_usettings link_usettings; |
| 517 | |
Gustavo A. R. Silva | c1d9e34 | 2021-04-16 15:15:40 -0500 | [diff] [blame] | 518 | memcpy(&link_usettings, from, sizeof(link_usettings)); |
Yury Norov | 3aa5688 | 2018-02-06 15:38:06 -0800 | [diff] [blame] | 519 | bitmap_to_arr32(link_usettings.link_modes.supported, |
| 520 | from->link_modes.supported, |
| 521 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 522 | bitmap_to_arr32(link_usettings.link_modes.advertising, |
| 523 | from->link_modes.advertising, |
| 524 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
| 525 | bitmap_to_arr32(link_usettings.link_modes.lp_advertising, |
| 526 | from->link_modes.lp_advertising, |
| 527 | __ETHTOOL_LINK_MODE_MASK_NBITS); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 528 | |
| 529 | if (copy_to_user(to, &link_usettings, sizeof(link_usettings))) |
| 530 | return -EFAULT; |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 535 | /* Query device for its ethtool_link_settings. */ |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 536 | static int ethtool_get_link_ksettings(struct net_device *dev, |
| 537 | void __user *useraddr) |
| 538 | { |
| 539 | int err = 0; |
| 540 | struct ethtool_link_ksettings link_ksettings; |
| 541 | |
| 542 | ASSERT_RTNL(); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 543 | if (!dev->ethtool_ops->get_link_ksettings) |
| 544 | return -EOPNOTSUPP; |
| 545 | |
| 546 | /* handle bitmap nbits handshake */ |
| 547 | if (copy_from_user(&link_ksettings.base, useraddr, |
| 548 | sizeof(link_ksettings.base))) |
| 549 | return -EFAULT; |
| 550 | |
| 551 | if (__ETHTOOL_LINK_MODE_MASK_NU32 |
| 552 | != link_ksettings.base.link_mode_masks_nwords) { |
| 553 | /* wrong link mode nbits requested */ |
| 554 | memset(&link_ksettings, 0, sizeof(link_ksettings)); |
Ben Hutchings | 793cf87 | 2016-03-14 01:05:38 +0000 | [diff] [blame] | 555 | link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 556 | /* send back number of words required as negative val */ |
| 557 | compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32 <= S8_MAX, |
| 558 | "need too many bits for link modes!"); |
| 559 | link_ksettings.base.link_mode_masks_nwords |
| 560 | = -((s8)__ETHTOOL_LINK_MODE_MASK_NU32); |
| 561 | |
| 562 | /* copy the base fields back to user, not the link |
| 563 | * mode bitmaps |
| 564 | */ |
| 565 | if (copy_to_user(useraddr, &link_ksettings.base, |
| 566 | sizeof(link_ksettings.base))) |
| 567 | return -EFAULT; |
| 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | /* handshake successful: user/kernel agree on |
| 573 | * link_mode_masks_nwords |
| 574 | */ |
| 575 | |
| 576 | memset(&link_ksettings, 0, sizeof(link_ksettings)); |
| 577 | err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings); |
| 578 | if (err < 0) |
| 579 | return err; |
| 580 | |
| 581 | /* make sure we tell the right values to user */ |
| 582 | link_ksettings.base.cmd = ETHTOOL_GLINKSETTINGS; |
| 583 | link_ksettings.base.link_mode_masks_nwords |
| 584 | = __ETHTOOL_LINK_MODE_MASK_NU32; |
Oleksij Rempel | bdbdac7 | 2020-05-05 08:35:05 +0200 | [diff] [blame] | 585 | link_ksettings.base.master_slave_cfg = MASTER_SLAVE_CFG_UNSUPPORTED; |
| 586 | link_ksettings.base.master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 587 | |
| 588 | return store_link_ksettings_for_user(useraddr, &link_ksettings); |
| 589 | } |
| 590 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 591 | /* Update device ethtool_link_settings. */ |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 592 | static int ethtool_set_link_ksettings(struct net_device *dev, |
| 593 | void __user *useraddr) |
| 594 | { |
| 595 | int err; |
| 596 | struct ethtool_link_ksettings link_ksettings; |
| 597 | |
| 598 | ASSERT_RTNL(); |
| 599 | |
| 600 | if (!dev->ethtool_ops->set_link_ksettings) |
| 601 | return -EOPNOTSUPP; |
| 602 | |
| 603 | /* make sure nbits field has expected value */ |
| 604 | if (copy_from_user(&link_ksettings.base, useraddr, |
| 605 | sizeof(link_ksettings.base))) |
| 606 | return -EFAULT; |
| 607 | |
| 608 | if (__ETHTOOL_LINK_MODE_MASK_NU32 |
| 609 | != link_ksettings.base.link_mode_masks_nwords) |
| 610 | return -EINVAL; |
| 611 | |
| 612 | /* copy the whole structure, now that we know it has expected |
| 613 | * format |
| 614 | */ |
| 615 | err = load_link_ksettings_from_user(&link_ksettings, useraddr); |
| 616 | if (err) |
| 617 | return err; |
| 618 | |
| 619 | /* re-check nwords field, just in case */ |
| 620 | if (__ETHTOOL_LINK_MODE_MASK_NU32 |
| 621 | != link_ksettings.base.link_mode_masks_nwords) |
| 622 | return -EINVAL; |
| 623 | |
Oleksij Rempel | bdbdac7 | 2020-05-05 08:35:05 +0200 | [diff] [blame] | 624 | if (link_ksettings.base.master_slave_cfg || |
| 625 | link_ksettings.base.master_slave_state) |
| 626 | return -EINVAL; |
| 627 | |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 628 | err = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 629 | if (err >= 0) { |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 630 | ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL); |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 631 | ethtool_notify(dev, ETHTOOL_MSG_LINKMODES_NTF, NULL); |
| 632 | } |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 633 | return err; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 634 | } |
| 635 | |
Cris Forno | 70ae1e1 | 2020-02-28 14:12:04 -0600 | [diff] [blame] | 636 | int ethtool_virtdev_set_link_ksettings(struct net_device *dev, |
| 637 | const struct ethtool_link_ksettings *cmd, |
| 638 | u32 *dev_speed, u8 *dev_duplex) |
| 639 | { |
| 640 | u32 speed; |
| 641 | u8 duplex; |
| 642 | |
| 643 | speed = cmd->base.speed; |
| 644 | duplex = cmd->base.duplex; |
| 645 | /* don't allow custom speed and duplex */ |
| 646 | if (!ethtool_validate_speed(speed) || |
| 647 | !ethtool_validate_duplex(duplex) || |
| 648 | !ethtool_virtdev_validate_cmd(cmd)) |
| 649 | return -EINVAL; |
| 650 | *dev_speed = speed; |
| 651 | *dev_duplex = duplex; |
| 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | EXPORT_SYMBOL(ethtool_virtdev_set_link_ksettings); |
| 656 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 657 | /* Query device for its ethtool_cmd settings. |
| 658 | * |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 659 | * Backward compatibility note: for compatibility with legacy ethtool, this is |
| 660 | * now implemented via get_link_ksettings. When driver reports higher link mode |
| 661 | * bits, a kernel warning is logged once (with name of 1st driver/device) to |
| 662 | * recommend user to upgrade ethtool, but the command is successful (only the |
| 663 | * lower link mode bits reported back to user). Deprecated fields from |
| 664 | * ethtool_cmd (transceiver/maxrxpkt/maxtxpkt) are always set to zero. |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 665 | */ |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 666 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
| 667 | { |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 668 | struct ethtool_link_ksettings link_ksettings; |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 669 | struct ethtool_cmd cmd; |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 670 | int err; |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 671 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 672 | ASSERT_RTNL(); |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 673 | if (!dev->ethtool_ops->get_link_ksettings) |
| 674 | return -EOPNOTSUPP; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 675 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 676 | memset(&link_ksettings, 0, sizeof(link_ksettings)); |
| 677 | err = dev->ethtool_ops->get_link_ksettings(dev, &link_ksettings); |
| 678 | if (err < 0) |
| 679 | return err; |
| 680 | convert_link_ksettings_to_legacy_settings(&cmd, &link_ksettings); |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 681 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 682 | /* send a sensible cmd tag back to user */ |
| 683 | cmd.cmd = ETHTOOL_GSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
| 685 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 686 | return -EFAULT; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return 0; |
| 689 | } |
| 690 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 691 | /* Update device link settings with given ethtool_cmd. |
| 692 | * |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 693 | * Backward compatibility note: for compatibility with legacy ethtool, this is |
| 694 | * now always implemented via set_link_settings. When user's request updates |
| 695 | * deprecated ethtool_cmd fields (transceiver/maxrxpkt/maxtxpkt), a kernel |
| 696 | * warning is logged once (with name of 1st driver/device) to recommend user to |
| 697 | * upgrade ethtool, and the request is rejected. |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 698 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
| 700 | { |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 701 | struct ethtool_link_ksettings link_ksettings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | struct ethtool_cmd cmd; |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 703 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 705 | ASSERT_RTNL(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 708 | return -EFAULT; |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 709 | if (!dev->ethtool_ops->set_link_ksettings) |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 710 | return -EOPNOTSUPP; |
| 711 | |
Michal Kubecek | 9b30049 | 2018-08-28 19:56:58 +0200 | [diff] [blame] | 712 | if (!convert_legacy_settings_to_link_ksettings(&link_ksettings, &cmd)) |
| 713 | return -EINVAL; |
| 714 | link_ksettings.base.link_mode_masks_nwords = |
| 715 | __ETHTOOL_LINK_MODE_MASK_NU32; |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 716 | ret = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 717 | if (ret >= 0) { |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 718 | ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL); |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 719 | ethtool_notify(dev, ETHTOOL_MSG_LINKMODES_NTF, NULL); |
| 720 | } |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 721 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 724 | static int |
| 725 | ethtool_get_drvinfo(struct net_device *dev, struct ethtool_devlink_compat *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 727 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 729 | rsp->info.cmd = ETHTOOL_GDRVINFO; |
| 730 | strlcpy(rsp->info.version, UTS_RELEASE, sizeof(rsp->info.version)); |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 731 | if (ops->get_drvinfo) { |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 732 | ops->get_drvinfo(dev, &rsp->info); |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 733 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 734 | strlcpy(rsp->info.bus_info, dev_name(dev->dev.parent), |
| 735 | sizeof(rsp->info.bus_info)); |
| 736 | strlcpy(rsp->info.driver, dev->dev.parent->driver->name, |
| 737 | sizeof(rsp->info.driver)); |
Tonghao Zhang | bde3b0f | 2021-11-26 00:30:49 +0800 | [diff] [blame] | 738 | } else if (dev->rtnl_link_ops) { |
| 739 | strlcpy(rsp->info.driver, dev->rtnl_link_ops->kind, |
| 740 | sizeof(rsp->info.driver)); |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 741 | } else { |
| 742 | return -EOPNOTSUPP; |
| 743 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 745 | /* |
| 746 | * this method of obtaining string set info is deprecated; |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 747 | * Use ETHTOOL_GSSET_INFO instead. |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 748 | */ |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 749 | if (ops->get_sset_count) { |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 750 | int rc; |
| 751 | |
| 752 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
| 753 | if (rc >= 0) |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 754 | rsp->info.testinfo_len = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 755 | rc = ops->get_sset_count(dev, ETH_SS_STATS); |
| 756 | if (rc >= 0) |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 757 | rsp->info.n_stats = rc; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 758 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
| 759 | if (rc >= 0) |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 760 | rsp->info.n_priv_flags = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 761 | } |
Yunsheng Lin | f9fc54d | 2018-12-26 19:51:46 +0800 | [diff] [blame] | 762 | if (ops->get_regs_len) { |
| 763 | int ret = ops->get_regs_len(dev); |
| 764 | |
| 765 | if (ret > 0) |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 766 | rsp->info.regdump_len = ret; |
Yunsheng Lin | f9fc54d | 2018-12-26 19:51:46 +0800 | [diff] [blame] | 767 | } |
| 768 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 769 | if (ops->get_eeprom_len) |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 770 | rsp->info.eedump_len = ops->get_eeprom_len(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 772 | if (!rsp->info.fw_version[0]) |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 773 | rsp->devlink = netdev_to_devlink_get(dev); |
| 774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | return 0; |
| 776 | } |
| 777 | |
Eric Dumazet | f5c445e | 2010-03-08 12:17:04 -0800 | [diff] [blame] | 778 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 779 | void __user *useraddr) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 780 | { |
| 781 | struct ethtool_sset_info info; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 782 | u64 sset_mask; |
| 783 | int i, idx = 0, n_bits = 0, ret, rc; |
| 784 | u32 *info_buf = NULL; |
| 785 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 786 | if (copy_from_user(&info, useraddr, sizeof(info))) |
| 787 | return -EFAULT; |
| 788 | |
| 789 | /* store copy of mask, because we zero struct later on */ |
| 790 | sset_mask = info.sset_mask; |
| 791 | if (!sset_mask) |
| 792 | return 0; |
| 793 | |
| 794 | /* calculate size of return buffer */ |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 795 | n_bits = hweight64(sset_mask); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 796 | |
| 797 | memset(&info, 0, sizeof(info)); |
| 798 | info.cmd = ETHTOOL_GSSET_INFO; |
| 799 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 800 | info_buf = kcalloc(n_bits, sizeof(u32), GFP_USER); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 801 | if (!info_buf) |
| 802 | return -ENOMEM; |
| 803 | |
| 804 | /* |
| 805 | * fill return buffer based on input bitmask and successful |
| 806 | * get_sset_count return |
| 807 | */ |
| 808 | for (i = 0; i < 64; i++) { |
| 809 | if (!(sset_mask & (1ULL << i))) |
| 810 | continue; |
| 811 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 812 | rc = __ethtool_get_sset_count(dev, i); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 813 | if (rc >= 0) { |
| 814 | info.sset_mask |= (1ULL << i); |
| 815 | info_buf[idx++] = rc; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | ret = -EFAULT; |
| 820 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 821 | goto out; |
| 822 | |
| 823 | useraddr += offsetof(struct ethtool_sset_info, data); |
Gustavo A. R. Silva | ed71761 | 2021-09-28 14:57:35 -0500 | [diff] [blame] | 824 | if (copy_to_user(useraddr, info_buf, array_size(idx, sizeof(u32)))) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 825 | goto out; |
| 826 | |
| 827 | ret = 0; |
| 828 | |
| 829 | out: |
| 830 | kfree(info_buf); |
| 831 | return ret; |
| 832 | } |
| 833 | |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 834 | static noinline_for_stack int |
| 835 | ethtool_rxnfc_copy_from_compat(struct ethtool_rxnfc *rxnfc, |
| 836 | const struct compat_ethtool_rxnfc __user *useraddr, |
| 837 | size_t size) |
| 838 | { |
| 839 | struct compat_ethtool_rxnfc crxnfc = {}; |
| 840 | |
| 841 | /* We expect there to be holes between fs.m_ext and |
| 842 | * fs.ring_cookie and at the end of fs, but nowhere else. |
| 843 | * On non-x86, no conversion should be needed. |
| 844 | */ |
| 845 | BUILD_BUG_ON(!IS_ENABLED(CONFIG_X86_64) && |
| 846 | sizeof(struct compat_ethtool_rxnfc) != |
| 847 | sizeof(struct ethtool_rxnfc)); |
| 848 | BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.m_ext) + |
| 849 | sizeof(useraddr->fs.m_ext) != |
| 850 | offsetof(struct ethtool_rxnfc, fs.m_ext) + |
| 851 | sizeof(rxnfc->fs.m_ext)); |
| 852 | BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.location) - |
| 853 | offsetof(struct compat_ethtool_rxnfc, fs.ring_cookie) != |
| 854 | offsetof(struct ethtool_rxnfc, fs.location) - |
| 855 | offsetof(struct ethtool_rxnfc, fs.ring_cookie)); |
| 856 | |
| 857 | if (copy_from_user(&crxnfc, useraddr, min(size, sizeof(crxnfc)))) |
| 858 | return -EFAULT; |
| 859 | |
| 860 | *rxnfc = (struct ethtool_rxnfc) { |
| 861 | .cmd = crxnfc.cmd, |
| 862 | .flow_type = crxnfc.flow_type, |
| 863 | .data = crxnfc.data, |
| 864 | .fs = { |
| 865 | .flow_type = crxnfc.fs.flow_type, |
| 866 | .h_u = crxnfc.fs.h_u, |
| 867 | .h_ext = crxnfc.fs.h_ext, |
| 868 | .m_u = crxnfc.fs.m_u, |
| 869 | .m_ext = crxnfc.fs.m_ext, |
| 870 | .ring_cookie = crxnfc.fs.ring_cookie, |
| 871 | .location = crxnfc.fs.location, |
| 872 | }, |
| 873 | .rule_cnt = crxnfc.rule_cnt, |
| 874 | }; |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static int ethtool_rxnfc_copy_from_user(struct ethtool_rxnfc *rxnfc, |
| 880 | const void __user *useraddr, |
| 881 | size_t size) |
| 882 | { |
| 883 | if (compat_need_64bit_alignment_fixup()) |
| 884 | return ethtool_rxnfc_copy_from_compat(rxnfc, useraddr, size); |
| 885 | |
| 886 | if (copy_from_user(rxnfc, useraddr, size)) |
| 887 | return -EFAULT; |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static int ethtool_rxnfc_copy_to_compat(void __user *useraddr, |
| 893 | const struct ethtool_rxnfc *rxnfc, |
| 894 | size_t size, const u32 *rule_buf) |
| 895 | { |
| 896 | struct compat_ethtool_rxnfc crxnfc; |
| 897 | |
| 898 | memset(&crxnfc, 0, sizeof(crxnfc)); |
| 899 | crxnfc = (struct compat_ethtool_rxnfc) { |
| 900 | .cmd = rxnfc->cmd, |
| 901 | .flow_type = rxnfc->flow_type, |
| 902 | .data = rxnfc->data, |
| 903 | .fs = { |
| 904 | .flow_type = rxnfc->fs.flow_type, |
| 905 | .h_u = rxnfc->fs.h_u, |
| 906 | .h_ext = rxnfc->fs.h_ext, |
| 907 | .m_u = rxnfc->fs.m_u, |
| 908 | .m_ext = rxnfc->fs.m_ext, |
| 909 | .ring_cookie = rxnfc->fs.ring_cookie, |
| 910 | .location = rxnfc->fs.location, |
| 911 | }, |
| 912 | .rule_cnt = rxnfc->rule_cnt, |
| 913 | }; |
| 914 | |
| 915 | if (copy_to_user(useraddr, &crxnfc, min(size, sizeof(crxnfc)))) |
| 916 | return -EFAULT; |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static int ethtool_rxnfc_copy_to_user(void __user *useraddr, |
| 922 | const struct ethtool_rxnfc *rxnfc, |
| 923 | size_t size, const u32 *rule_buf) |
| 924 | { |
| 925 | int ret; |
| 926 | |
| 927 | if (compat_need_64bit_alignment_fixup()) { |
| 928 | ret = ethtool_rxnfc_copy_to_compat(useraddr, rxnfc, size, |
| 929 | rule_buf); |
| 930 | useraddr += offsetof(struct compat_ethtool_rxnfc, rule_locs); |
| 931 | } else { |
Saeed Mahameed | 9b29a16 | 2021-07-26 15:15:39 -0700 | [diff] [blame] | 932 | ret = copy_to_user(useraddr, rxnfc, size); |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 933 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); |
| 934 | } |
| 935 | |
| 936 | if (ret) |
| 937 | return -EFAULT; |
| 938 | |
| 939 | if (rule_buf) { |
| 940 | if (copy_to_user(useraddr, rule_buf, |
| 941 | rxnfc->rule_cnt * sizeof(u32))) |
| 942 | return -EFAULT; |
| 943 | } |
| 944 | |
| 945 | return 0; |
| 946 | } |
| 947 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 948 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 949 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 950 | { |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 951 | struct ethtool_rxnfc info; |
| 952 | size_t info_size = sizeof(info); |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 953 | int rc; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 954 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 955 | if (!dev->ethtool_ops->set_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 956 | return -EOPNOTSUPP; |
| 957 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 958 | /* struct ethtool_rxnfc was originally defined for |
| 959 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 960 | * members. User-space might still be using that |
| 961 | * definition. */ |
| 962 | if (cmd == ETHTOOL_SRXFH) |
| 963 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 964 | sizeof(info.data)); |
| 965 | |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 966 | if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 967 | return -EFAULT; |
| 968 | |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 969 | rc = dev->ethtool_ops->set_rxnfc(dev, &info); |
| 970 | if (rc) |
| 971 | return rc; |
| 972 | |
| 973 | if (cmd == ETHTOOL_SRXCLSRLINS && |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 974 | ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, NULL)) |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 975 | return -EFAULT; |
| 976 | |
| 977 | return 0; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 978 | } |
| 979 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 980 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 981 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 982 | { |
| 983 | struct ethtool_rxnfc info; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 984 | size_t info_size = sizeof(info); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 985 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 986 | int ret; |
| 987 | void *rule_buf = NULL; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 988 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 989 | if (!ops->get_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 990 | return -EOPNOTSUPP; |
| 991 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 992 | /* struct ethtool_rxnfc was originally defined for |
| 993 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 994 | * members. User-space might still be using that |
| 995 | * definition. */ |
| 996 | if (cmd == ETHTOOL_GRXFH) |
| 997 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 998 | sizeof(info.data)); |
| 999 | |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 1000 | if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1001 | return -EFAULT; |
| 1002 | |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1003 | /* If FLOW_RSS was requested then user-space must be using the |
| 1004 | * new definition, as FLOW_RSS is newer. |
| 1005 | */ |
| 1006 | if (cmd == ETHTOOL_GRXFH && info.flow_type & FLOW_RSS) { |
| 1007 | info_size = sizeof(info); |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 1008 | if (ethtool_rxnfc_copy_from_user(&info, useraddr, info_size)) |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1009 | return -EFAULT; |
Wenwen Wang | d656fe4 | 2018-04-30 12:31:13 -0500 | [diff] [blame] | 1010 | /* Since malicious users may modify the original data, |
| 1011 | * we need to check whether FLOW_RSS is still requested. |
| 1012 | */ |
| 1013 | if (!(info.flow_type & FLOW_RSS)) |
| 1014 | return -EINVAL; |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Wenwen Wang | 2bb3207 | 2018-10-09 08:15:38 -0500 | [diff] [blame] | 1017 | if (info.cmd != cmd) |
| 1018 | return -EINVAL; |
| 1019 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1020 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
| 1021 | if (info.rule_cnt > 0) { |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 1022 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 1023 | rule_buf = kcalloc(info.rule_cnt, sizeof(u32), |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 1024 | GFP_USER); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1025 | if (!rule_buf) |
| 1026 | return -ENOMEM; |
| 1027 | } |
| 1028 | } |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1029 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1030 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
| 1031 | if (ret < 0) |
| 1032 | goto err_out; |
| 1033 | |
Arnd Bergmann | dd98d28 | 2021-07-22 16:28:59 +0200 | [diff] [blame] | 1034 | ret = ethtool_rxnfc_copy_to_user(useraddr, &info, info_size, rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1035 | err_out: |
Wei Yongjun | c9cacec | 2009-03-31 15:06:26 -0700 | [diff] [blame] | 1036 | kfree(rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1037 | |
| 1038 | return ret; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1041 | static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr, |
| 1042 | struct ethtool_rxnfc *rx_rings, |
| 1043 | u32 size) |
| 1044 | { |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 1045 | int i; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1046 | |
Gustavo A. R. Silva | ed71761 | 2021-09-28 14:57:35 -0500 | [diff] [blame] | 1047 | if (copy_from_user(indir, useraddr, array_size(size, sizeof(indir[0])))) |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 1048 | return -EFAULT; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1049 | |
| 1050 | /* Validate ring indices */ |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 1051 | for (i = 0; i < size; i++) |
| 1052 | if (indir[i] >= rx_rings->data) |
| 1053 | return -EINVAL; |
| 1054 | |
| 1055 | return 0; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1056 | } |
| 1057 | |
Kim Jones | ba905f5 | 2016-02-02 03:51:16 +0000 | [diff] [blame] | 1058 | u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly; |
Eric Dumazet | 960fb62 | 2014-11-16 06:23:05 -0800 | [diff] [blame] | 1059 | |
| 1060 | void netdev_rss_key_fill(void *buffer, size_t len) |
| 1061 | { |
| 1062 | BUG_ON(len > sizeof(netdev_rss_key)); |
| 1063 | net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key)); |
| 1064 | memcpy(buffer, netdev_rss_key, len); |
| 1065 | } |
| 1066 | EXPORT_SYMBOL(netdev_rss_key_fill); |
| 1067 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1068 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
| 1069 | void __user *useraddr) |
| 1070 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1071 | u32 user_size, dev_size; |
| 1072 | u32 *indir; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1073 | int ret; |
| 1074 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1075 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 1076 | !dev->ethtool_ops->get_rxfh) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1077 | return -EOPNOTSUPP; |
| 1078 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); |
| 1079 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1080 | return -EOPNOTSUPP; |
| 1081 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1082 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1083 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1084 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1085 | return -EFAULT; |
| 1086 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1087 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 1088 | &dev_size, sizeof(dev_size))) |
| 1089 | return -EFAULT; |
| 1090 | |
| 1091 | /* If the user buffer size is 0, this is just a query for the |
| 1092 | * device table size. Otherwise, if it's smaller than the |
| 1093 | * device table size it's an error. |
| 1094 | */ |
| 1095 | if (user_size < dev_size) |
| 1096 | return user_size == 0 ? 0 : -EINVAL; |
| 1097 | |
| 1098 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1099 | if (!indir) |
| 1100 | return -ENOMEM; |
| 1101 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1102 | ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1103 | if (ret) |
| 1104 | goto out; |
| 1105 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1106 | if (copy_to_user(useraddr + |
| 1107 | offsetof(struct ethtool_rxfh_indir, ring_index[0]), |
| 1108 | indir, dev_size * sizeof(indir[0]))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1109 | ret = -EFAULT; |
| 1110 | |
| 1111 | out: |
| 1112 | kfree(indir); |
| 1113 | return ret; |
| 1114 | } |
| 1115 | |
| 1116 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, |
| 1117 | void __user *useraddr) |
| 1118 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1119 | struct ethtool_rxnfc rx_rings; |
| 1120 | u32 user_size, dev_size, i; |
| 1121 | u32 *indir; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1122 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1123 | int ret; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1124 | u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1125 | |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 1126 | if (!ops->get_rxfh_indir_size || !ops->set_rxfh || |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1127 | !ops->get_rxnfc) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1128 | return -EOPNOTSUPP; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1129 | |
| 1130 | dev_size = ops->get_rxfh_indir_size(dev); |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1131 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1132 | return -EOPNOTSUPP; |
| 1133 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1134 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1135 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1136 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1137 | return -EFAULT; |
| 1138 | |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 1139 | if (user_size != 0 && user_size != dev_size) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1140 | return -EINVAL; |
| 1141 | |
| 1142 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1143 | if (!indir) |
| 1144 | return -ENOMEM; |
| 1145 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1146 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1147 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1148 | if (ret) |
| 1149 | goto out; |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 1150 | |
| 1151 | if (user_size == 0) { |
| 1152 | for (i = 0; i < dev_size; i++) |
| 1153 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); |
| 1154 | } else { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1155 | ret = ethtool_copy_validate_indir(indir, |
| 1156 | useraddr + ringidx_offset, |
| 1157 | &rx_rings, |
| 1158 | dev_size); |
| 1159 | if (ret) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1160 | goto out; |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1163 | ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE); |
Keller, Jacob E | d4ab428 | 2016-02-08 16:05:03 -0800 | [diff] [blame] | 1164 | if (ret) |
| 1165 | goto out; |
| 1166 | |
| 1167 | /* indicate whether rxfh was set to default */ |
| 1168 | if (user_size == 0) |
| 1169 | dev->priv_flags &= ~IFF_RXFH_CONFIGURED; |
| 1170 | else |
| 1171 | dev->priv_flags |= IFF_RXFH_CONFIGURED; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1172 | |
| 1173 | out: |
| 1174 | kfree(indir); |
| 1175 | return ret; |
| 1176 | } |
| 1177 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1178 | static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev, |
| 1179 | void __user *useraddr) |
| 1180 | { |
| 1181 | int ret; |
| 1182 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1183 | u32 user_indir_size, user_key_size; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1184 | u32 dev_indir_size = 0, dev_key_size = 0; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1185 | struct ethtool_rxfh rxfh; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1186 | u32 total_size; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1187 | u32 indir_bytes; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1188 | u32 *indir = NULL; |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1189 | u8 dev_hfunc = 0; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1190 | u8 *hkey = NULL; |
| 1191 | u8 *rss_config; |
| 1192 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1193 | if (!ops->get_rxfh) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1194 | return -EOPNOTSUPP; |
| 1195 | |
| 1196 | if (ops->get_rxfh_indir_size) |
| 1197 | dev_indir_size = ops->get_rxfh_indir_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1198 | if (ops->get_rxfh_key_size) |
| 1199 | dev_key_size = ops->get_rxfh_key_size(dev); |
| 1200 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1201 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1202 | return -EFAULT; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1203 | user_indir_size = rxfh.indir_size; |
| 1204 | user_key_size = rxfh.key_size; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1205 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1206 | /* Check that reserved fields are 0 for now */ |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1207 | if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32) |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1208 | return -EINVAL; |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1209 | /* Most drivers don't handle rss_context, check it's 0 as well */ |
| 1210 | if (rxfh.rss_context && !ops->get_rxfh_context) |
| 1211 | return -EOPNOTSUPP; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1212 | |
| 1213 | rxfh.indir_size = dev_indir_size; |
| 1214 | rxfh.key_size = dev_key_size; |
| 1215 | if (copy_to_user(useraddr, &rxfh, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1216 | return -EFAULT; |
| 1217 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1218 | if ((user_indir_size && (user_indir_size != dev_indir_size)) || |
| 1219 | (user_key_size && (user_key_size != dev_key_size))) |
| 1220 | return -EINVAL; |
| 1221 | |
| 1222 | indir_bytes = user_indir_size * sizeof(indir[0]); |
| 1223 | total_size = indir_bytes + user_key_size; |
| 1224 | rss_config = kzalloc(total_size, GFP_USER); |
| 1225 | if (!rss_config) |
| 1226 | return -ENOMEM; |
| 1227 | |
| 1228 | if (user_indir_size) |
| 1229 | indir = (u32 *)rss_config; |
| 1230 | |
| 1231 | if (user_key_size) |
| 1232 | hkey = rss_config + indir_bytes; |
| 1233 | |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1234 | if (rxfh.rss_context) |
| 1235 | ret = dev->ethtool_ops->get_rxfh_context(dev, indir, hkey, |
| 1236 | &dev_hfunc, |
| 1237 | rxfh.rss_context); |
| 1238 | else |
| 1239 | ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc); |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1240 | if (ret) |
| 1241 | goto out; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1242 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1243 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc), |
| 1244 | &dev_hfunc, sizeof(rxfh.hfunc))) { |
| 1245 | ret = -EFAULT; |
| 1246 | } else if (copy_to_user(useraddr + |
| 1247 | offsetof(struct ethtool_rxfh, rss_config[0]), |
| 1248 | rss_config, total_size)) { |
| 1249 | ret = -EFAULT; |
| 1250 | } |
| 1251 | out: |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1252 | kfree(rss_config); |
| 1253 | |
| 1254 | return ret; |
| 1255 | } |
| 1256 | |
| 1257 | static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, |
| 1258 | void __user *useraddr) |
| 1259 | { |
| 1260 | int ret; |
| 1261 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1262 | struct ethtool_rxnfc rx_rings; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1263 | struct ethtool_rxfh rxfh; |
| 1264 | u32 dev_indir_size = 0, dev_key_size = 0, i; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1265 | u32 *indir = NULL, indir_bytes = 0; |
| 1266 | u8 *hkey = NULL; |
| 1267 | u8 *rss_config; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1268 | u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]); |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1269 | bool delete = false; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1270 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1271 | if (!ops->get_rxnfc || !ops->set_rxfh) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1272 | return -EOPNOTSUPP; |
| 1273 | |
| 1274 | if (ops->get_rxfh_indir_size) |
| 1275 | dev_indir_size = ops->get_rxfh_indir_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1276 | if (ops->get_rxfh_key_size) |
Dan Carpenter | d340c86 | 2015-02-20 13:54:05 +0300 | [diff] [blame] | 1277 | dev_key_size = ops->get_rxfh_key_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1278 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1279 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1280 | return -EFAULT; |
| 1281 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1282 | /* Check that reserved fields are 0 for now */ |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1283 | if (rxfh.rsvd8[0] || rxfh.rsvd8[1] || rxfh.rsvd8[2] || rxfh.rsvd32) |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1284 | return -EINVAL; |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1285 | /* Most drivers don't handle rss_context, check it's 0 as well */ |
| 1286 | if (rxfh.rss_context && !ops->set_rxfh_context) |
| 1287 | return -EOPNOTSUPP; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1288 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1289 | /* If either indir, hash key or function is valid, proceed further. |
| 1290 | * Must request at least one change: indir size, hash key or function. |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1291 | */ |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1292 | if ((rxfh.indir_size && |
| 1293 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE && |
| 1294 | rxfh.indir_size != dev_indir_size) || |
| 1295 | (rxfh.key_size && (rxfh.key_size != dev_key_size)) || |
| 1296 | (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE && |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1297 | rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE)) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1298 | return -EINVAL; |
| 1299 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1300 | if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1301 | indir_bytes = dev_indir_size * sizeof(indir[0]); |
| 1302 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1303 | rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1304 | if (!rss_config) |
| 1305 | return -ENOMEM; |
| 1306 | |
| 1307 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
| 1308 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
| 1309 | if (ret) |
| 1310 | goto out; |
| 1311 | |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1312 | /* rxfh.indir_size == 0 means reset the indir table to default (master |
| 1313 | * context) or delete the context (other RSS contexts). |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1314 | * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged. |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1315 | */ |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1316 | if (rxfh.indir_size && |
| 1317 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1318 | indir = (u32 *)rss_config; |
| 1319 | ret = ethtool_copy_validate_indir(indir, |
| 1320 | useraddr + rss_cfg_offset, |
| 1321 | &rx_rings, |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1322 | rxfh.indir_size); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1323 | if (ret) |
| 1324 | goto out; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1325 | } else if (rxfh.indir_size == 0) { |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1326 | if (rxfh.rss_context == 0) { |
| 1327 | indir = (u32 *)rss_config; |
| 1328 | for (i = 0; i < dev_indir_size; i++) |
| 1329 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); |
| 1330 | } else { |
| 1331 | delete = true; |
| 1332 | } |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1333 | } |
| 1334 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1335 | if (rxfh.key_size) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1336 | hkey = rss_config + indir_bytes; |
| 1337 | if (copy_from_user(hkey, |
| 1338 | useraddr + rss_cfg_offset + indir_bytes, |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 1339 | rxfh.key_size)) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1340 | ret = -EFAULT; |
| 1341 | goto out; |
| 1342 | } |
| 1343 | } |
| 1344 | |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1345 | if (rxfh.rss_context) |
| 1346 | ret = ops->set_rxfh_context(dev, indir, hkey, rxfh.hfunc, |
| 1347 | &rxfh.rss_context, delete); |
| 1348 | else |
| 1349 | ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc); |
Keller, Jacob E | d4ab428 | 2016-02-08 16:05:03 -0800 | [diff] [blame] | 1350 | if (ret) |
| 1351 | goto out; |
| 1352 | |
Edward Cree | 84a1d9c4 | 2018-03-08 15:45:03 +0000 | [diff] [blame] | 1353 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, rss_context), |
| 1354 | &rxfh.rss_context, sizeof(rxfh.rss_context))) |
| 1355 | ret = -EFAULT; |
| 1356 | |
| 1357 | if (!rxfh.rss_context) { |
| 1358 | /* indicate whether rxfh was set to default */ |
| 1359 | if (rxfh.indir_size == 0) |
| 1360 | dev->priv_flags &= ~IFF_RXFH_CONFIGURED; |
| 1361 | else if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) |
| 1362 | dev->priv_flags |= IFF_RXFH_CONFIGURED; |
| 1363 | } |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1364 | |
| 1365 | out: |
| 1366 | kfree(rss_config); |
| 1367 | return ret; |
| 1368 | } |
| 1369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
| 1371 | { |
| 1372 | struct ethtool_regs regs; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1373 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | void *regbuf; |
| 1375 | int reglen, ret; |
| 1376 | |
| 1377 | if (!ops->get_regs || !ops->get_regs_len) |
| 1378 | return -EOPNOTSUPP; |
| 1379 | |
| 1380 | if (copy_from_user(®s, useraddr, sizeof(regs))) |
| 1381 | return -EFAULT; |
| 1382 | |
| 1383 | reglen = ops->get_regs_len(dev); |
Yunsheng Lin | f9fc54d | 2018-12-26 19:51:46 +0800 | [diff] [blame] | 1384 | if (reglen <= 0) |
| 1385 | return reglen; |
| 1386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | if (regs.len > reglen) |
| 1388 | regs.len = reglen; |
| 1389 | |
Dan Carpenter | ef76c77 | 2019-02-01 11:24:06 +0300 | [diff] [blame] | 1390 | regbuf = vzalloc(reglen); |
| 1391 | if (!regbuf) |
| 1392 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Vivien Didelot | 0ee4e76 | 2019-06-03 16:57:13 -0400 | [diff] [blame] | 1394 | if (regs.len < reglen) |
| 1395 | reglen = regs.len; |
| 1396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | ops->get_regs(dev, ®s, regbuf); |
| 1398 | |
| 1399 | ret = -EFAULT; |
| 1400 | if (copy_to_user(useraddr, ®s, sizeof(regs))) |
| 1401 | goto out; |
| 1402 | useraddr += offsetof(struct ethtool_regs, data); |
Vivien Didelot | 0ee4e76 | 2019-06-03 16:57:13 -0400 | [diff] [blame] | 1403 | if (copy_to_user(useraddr, regbuf, reglen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | goto out; |
| 1405 | ret = 0; |
| 1406 | |
| 1407 | out: |
Ben Hutchings | a77f5db | 2010-09-20 08:42:17 +0000 | [diff] [blame] | 1408 | vfree(regbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | return ret; |
| 1410 | } |
| 1411 | |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1412 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
| 1413 | { |
| 1414 | struct ethtool_value reset; |
| 1415 | int ret; |
| 1416 | |
| 1417 | if (!dev->ethtool_ops->reset) |
| 1418 | return -EOPNOTSUPP; |
| 1419 | |
| 1420 | if (copy_from_user(&reset, useraddr, sizeof(reset))) |
| 1421 | return -EFAULT; |
| 1422 | |
| 1423 | ret = dev->ethtool_ops->reset(dev, &reset.data); |
| 1424 | if (ret) |
| 1425 | return ret; |
| 1426 | |
| 1427 | if (copy_to_user(useraddr, &reset, sizeof(reset))) |
| 1428 | return -EFAULT; |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
| 1433 | { |
zhanglin | 5ff223e8 | 2019-10-26 15:54:16 +0800 | [diff] [blame] | 1434 | struct ethtool_wolinfo wol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | |
| 1436 | if (!dev->ethtool_ops->get_wol) |
| 1437 | return -EOPNOTSUPP; |
| 1438 | |
zhanglin | 5ff223e8 | 2019-10-26 15:54:16 +0800 | [diff] [blame] | 1439 | memset(&wol, 0, sizeof(struct ethtool_wolinfo)); |
| 1440 | wol.cmd = ETHTOOL_GWOL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | dev->ethtool_ops->get_wol(dev, &wol); |
| 1442 | |
| 1443 | if (copy_to_user(useraddr, &wol, sizeof(wol))) |
| 1444 | return -EFAULT; |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
| 1448 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) |
| 1449 | { |
| 1450 | struct ethtool_wolinfo wol; |
Heiner Kallweit | 6194114 | 2018-09-24 21:58:59 +0200 | [diff] [blame] | 1451 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
| 1453 | if (!dev->ethtool_ops->set_wol) |
| 1454 | return -EOPNOTSUPP; |
| 1455 | |
| 1456 | if (copy_from_user(&wol, useraddr, sizeof(wol))) |
| 1457 | return -EFAULT; |
| 1458 | |
Heiner Kallweit | 6194114 | 2018-09-24 21:58:59 +0200 | [diff] [blame] | 1459 | ret = dev->ethtool_ops->set_wol(dev, &wol); |
| 1460 | if (ret) |
| 1461 | return ret; |
| 1462 | |
| 1463 | dev->wol_enabled = !!wol.wolopts; |
Michal Kubecek | 67bffa7 | 2020-01-26 23:11:19 +0100 | [diff] [blame] | 1464 | ethtool_notify(dev, ETHTOOL_MSG_WOL_NTF, NULL); |
Heiner Kallweit | 6194114 | 2018-09-24 21:58:59 +0200 | [diff] [blame] | 1465 | |
| 1466 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 1469 | static int ethtool_get_eee(struct net_device *dev, char __user *useraddr) |
| 1470 | { |
| 1471 | struct ethtool_eee edata; |
| 1472 | int rc; |
| 1473 | |
| 1474 | if (!dev->ethtool_ops->get_eee) |
| 1475 | return -EOPNOTSUPP; |
| 1476 | |
| 1477 | memset(&edata, 0, sizeof(struct ethtool_eee)); |
| 1478 | edata.cmd = ETHTOOL_GEEE; |
| 1479 | rc = dev->ethtool_ops->get_eee(dev, &edata); |
| 1480 | |
| 1481 | if (rc) |
| 1482 | return rc; |
| 1483 | |
| 1484 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1485 | return -EFAULT; |
| 1486 | |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
| 1490 | static int ethtool_set_eee(struct net_device *dev, char __user *useraddr) |
| 1491 | { |
| 1492 | struct ethtool_eee edata; |
Michal Kubecek | 6c5bc8f | 2020-03-28 00:01:48 +0100 | [diff] [blame] | 1493 | int ret; |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 1494 | |
| 1495 | if (!dev->ethtool_ops->set_eee) |
| 1496 | return -EOPNOTSUPP; |
| 1497 | |
| 1498 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1499 | return -EFAULT; |
| 1500 | |
Michal Kubecek | 6c5bc8f | 2020-03-28 00:01:48 +0100 | [diff] [blame] | 1501 | ret = dev->ethtool_ops->set_eee(dev, &edata); |
| 1502 | if (!ret) |
| 1503 | ethtool_notify(dev, ETHTOOL_MSG_EEE_NTF, NULL); |
| 1504 | return ret; |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | static int ethtool_nway_reset(struct net_device *dev) |
| 1508 | { |
| 1509 | if (!dev->ethtool_ops->nway_reset) |
| 1510 | return -EOPNOTSUPP; |
| 1511 | |
| 1512 | return dev->ethtool_ops->nway_reset(dev); |
| 1513 | } |
| 1514 | |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1515 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
| 1516 | { |
| 1517 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 1518 | int link = __ethtool_get_link(dev); |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1519 | |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 1520 | if (link < 0) |
| 1521 | return link; |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1522 | |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 1523 | edata.data = link; |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1524 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1525 | return -EFAULT; |
| 1526 | return 0; |
| 1527 | } |
| 1528 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1529 | static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr, |
| 1530 | int (*getter)(struct net_device *, |
| 1531 | struct ethtool_eeprom *, u8 *), |
| 1532 | u32 total_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
| 1534 | struct ethtool_eeprom eeprom; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1535 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1536 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1538 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1541 | return -EFAULT; |
| 1542 | |
| 1543 | /* Check for wrap and zero */ |
| 1544 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1545 | return -EINVAL; |
| 1546 | |
| 1547 | /* Check for exceeding total eeprom len */ |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1548 | if (eeprom.offset + eeprom.len > total_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | return -EINVAL; |
| 1550 | |
Austin Kim | 80ec82e | 2021-06-09 03:34:25 +0100 | [diff] [blame] | 1551 | data = kzalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | if (!data) |
| 1553 | return -ENOMEM; |
| 1554 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1555 | bytes_remaining = eeprom.len; |
| 1556 | while (bytes_remaining > 0) { |
| 1557 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1559 | ret = getter(dev, &eeprom, data); |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1560 | if (ret) |
| 1561 | break; |
Heiner Kallweit | b9bbc4c | 2021-09-13 21:58:26 +0200 | [diff] [blame] | 1562 | if (!eeprom.len) { |
| 1563 | ret = -EIO; |
| 1564 | break; |
| 1565 | } |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1566 | if (copy_to_user(userbuf, data, eeprom.len)) { |
| 1567 | ret = -EFAULT; |
| 1568 | break; |
| 1569 | } |
| 1570 | userbuf += eeprom.len; |
| 1571 | eeprom.offset += eeprom.len; |
| 1572 | bytes_remaining -= eeprom.len; |
| 1573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | |
Mandeep Singh Baines | c5835df | 2008-04-24 20:55:56 -0700 | [diff] [blame] | 1575 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
| 1576 | eeprom.offset -= eeprom.len; |
| 1577 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) |
| 1578 | ret = -EFAULT; |
| 1579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | kfree(data); |
| 1581 | return ret; |
| 1582 | } |
| 1583 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1584 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
| 1585 | { |
| 1586 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1587 | |
Guenter Roeck | e0fb6fb | 2014-10-30 20:50:15 -0700 | [diff] [blame] | 1588 | if (!ops->get_eeprom || !ops->get_eeprom_len || |
| 1589 | !ops->get_eeprom_len(dev)) |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1590 | return -EOPNOTSUPP; |
| 1591 | |
| 1592 | return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom, |
| 1593 | ops->get_eeprom_len(dev)); |
| 1594 | } |
| 1595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
| 1597 | { |
| 1598 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1599 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1600 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1601 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1603 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
Guenter Roeck | e0fb6fb | 2014-10-30 20:50:15 -0700 | [diff] [blame] | 1605 | if (!ops->set_eeprom || !ops->get_eeprom_len || |
| 1606 | !ops->get_eeprom_len(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | return -EOPNOTSUPP; |
| 1608 | |
| 1609 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1610 | return -EFAULT; |
| 1611 | |
| 1612 | /* Check for wrap and zero */ |
| 1613 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1614 | return -EINVAL; |
| 1615 | |
| 1616 | /* Check for exceeding total eeprom len */ |
| 1617 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1618 | return -EINVAL; |
| 1619 | |
Austin Kim | 80ec82e | 2021-06-09 03:34:25 +0100 | [diff] [blame] | 1620 | data = kzalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | if (!data) |
| 1622 | return -ENOMEM; |
| 1623 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1624 | bytes_remaining = eeprom.len; |
| 1625 | while (bytes_remaining > 0) { |
| 1626 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1628 | if (copy_from_user(data, userbuf, eeprom.len)) { |
| 1629 | ret = -EFAULT; |
| 1630 | break; |
| 1631 | } |
| 1632 | ret = ops->set_eeprom(dev, &eeprom, data); |
| 1633 | if (ret) |
| 1634 | break; |
| 1635 | userbuf += eeprom.len; |
| 1636 | eeprom.offset += eeprom.len; |
| 1637 | bytes_remaining -= eeprom.len; |
| 1638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | kfree(data); |
| 1641 | return ret; |
| 1642 | } |
| 1643 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1644 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
| 1645 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1647 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
Yufeng Mo | f3ccfda1 | 2021-08-20 15:35:18 +0800 | [diff] [blame] | 1648 | struct kernel_ethtool_coalesce kernel_coalesce = {}; |
Heiner Kallweit | 3161071 | 2020-05-23 17:40:25 +0200 | [diff] [blame] | 1649 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | |
| 1651 | if (!dev->ethtool_ops->get_coalesce) |
| 1652 | return -EOPNOTSUPP; |
| 1653 | |
Yufeng Mo | f3ccfda1 | 2021-08-20 15:35:18 +0800 | [diff] [blame] | 1654 | ret = dev->ethtool_ops->get_coalesce(dev, &coalesce, &kernel_coalesce, |
| 1655 | NULL); |
Heiner Kallweit | 3161071 | 2020-05-23 17:40:25 +0200 | [diff] [blame] | 1656 | if (ret) |
| 1657 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
| 1659 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 1660 | return -EFAULT; |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
Jakub Kicinski | 95cddcb | 2020-03-04 21:15:31 -0800 | [diff] [blame] | 1664 | static bool |
| 1665 | ethtool_set_coalesce_supported(struct net_device *dev, |
| 1666 | struct ethtool_coalesce *coalesce) |
| 1667 | { |
| 1668 | u32 supported_params = dev->ethtool_ops->supported_coalesce_params; |
| 1669 | u32 nonzero_params = 0; |
| 1670 | |
Jakub Kicinski | 95cddcb | 2020-03-04 21:15:31 -0800 | [diff] [blame] | 1671 | if (coalesce->rx_coalesce_usecs) |
| 1672 | nonzero_params |= ETHTOOL_COALESCE_RX_USECS; |
| 1673 | if (coalesce->rx_max_coalesced_frames) |
| 1674 | nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES; |
| 1675 | if (coalesce->rx_coalesce_usecs_irq) |
| 1676 | nonzero_params |= ETHTOOL_COALESCE_RX_USECS_IRQ; |
| 1677 | if (coalesce->rx_max_coalesced_frames_irq) |
| 1678 | nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ; |
| 1679 | if (coalesce->tx_coalesce_usecs) |
| 1680 | nonzero_params |= ETHTOOL_COALESCE_TX_USECS; |
| 1681 | if (coalesce->tx_max_coalesced_frames) |
| 1682 | nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES; |
| 1683 | if (coalesce->tx_coalesce_usecs_irq) |
| 1684 | nonzero_params |= ETHTOOL_COALESCE_TX_USECS_IRQ; |
| 1685 | if (coalesce->tx_max_coalesced_frames_irq) |
| 1686 | nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ; |
| 1687 | if (coalesce->stats_block_coalesce_usecs) |
| 1688 | nonzero_params |= ETHTOOL_COALESCE_STATS_BLOCK_USECS; |
| 1689 | if (coalesce->use_adaptive_rx_coalesce) |
| 1690 | nonzero_params |= ETHTOOL_COALESCE_USE_ADAPTIVE_RX; |
| 1691 | if (coalesce->use_adaptive_tx_coalesce) |
| 1692 | nonzero_params |= ETHTOOL_COALESCE_USE_ADAPTIVE_TX; |
| 1693 | if (coalesce->pkt_rate_low) |
| 1694 | nonzero_params |= ETHTOOL_COALESCE_PKT_RATE_LOW; |
| 1695 | if (coalesce->rx_coalesce_usecs_low) |
| 1696 | nonzero_params |= ETHTOOL_COALESCE_RX_USECS_LOW; |
| 1697 | if (coalesce->rx_max_coalesced_frames_low) |
| 1698 | nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW; |
| 1699 | if (coalesce->tx_coalesce_usecs_low) |
| 1700 | nonzero_params |= ETHTOOL_COALESCE_TX_USECS_LOW; |
| 1701 | if (coalesce->tx_max_coalesced_frames_low) |
| 1702 | nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW; |
| 1703 | if (coalesce->pkt_rate_high) |
| 1704 | nonzero_params |= ETHTOOL_COALESCE_PKT_RATE_HIGH; |
| 1705 | if (coalesce->rx_coalesce_usecs_high) |
| 1706 | nonzero_params |= ETHTOOL_COALESCE_RX_USECS_HIGH; |
| 1707 | if (coalesce->rx_max_coalesced_frames_high) |
| 1708 | nonzero_params |= ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH; |
| 1709 | if (coalesce->tx_coalesce_usecs_high) |
| 1710 | nonzero_params |= ETHTOOL_COALESCE_TX_USECS_HIGH; |
| 1711 | if (coalesce->tx_max_coalesced_frames_high) |
| 1712 | nonzero_params |= ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH; |
| 1713 | if (coalesce->rate_sample_interval) |
| 1714 | nonzero_params |= ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL; |
| 1715 | |
| 1716 | return (supported_params & nonzero_params) == nonzero_params; |
| 1717 | } |
| 1718 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1719 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
| 1720 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | { |
Yufeng Mo | f3ccfda1 | 2021-08-20 15:35:18 +0800 | [diff] [blame] | 1722 | struct kernel_ethtool_coalesce kernel_coalesce = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | struct ethtool_coalesce coalesce; |
Michal Kubecek | 0cf3eac | 2020-03-28 00:01:18 +0100 | [diff] [blame] | 1724 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
Julian Wiedmann | 0276af2 | 2021-11-26 18:55:43 +0100 | [diff] [blame] | 1726 | if (!dev->ethtool_ops->set_coalesce || !dev->ethtool_ops->get_coalesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | return -EOPNOTSUPP; |
| 1728 | |
Yufeng Mo | f3ccfda1 | 2021-08-20 15:35:18 +0800 | [diff] [blame] | 1729 | ret = dev->ethtool_ops->get_coalesce(dev, &coalesce, &kernel_coalesce, |
| 1730 | NULL); |
| 1731 | if (ret) |
| 1732 | return ret; |
| 1733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) |
| 1735 | return -EFAULT; |
| 1736 | |
Jakub Kicinski | 95cddcb | 2020-03-04 21:15:31 -0800 | [diff] [blame] | 1737 | if (!ethtool_set_coalesce_supported(dev, &coalesce)) |
| 1738 | return -EOPNOTSUPP; |
| 1739 | |
Yufeng Mo | f3ccfda1 | 2021-08-20 15:35:18 +0800 | [diff] [blame] | 1740 | ret = dev->ethtool_ops->set_coalesce(dev, &coalesce, &kernel_coalesce, |
| 1741 | NULL); |
Michal Kubecek | 0cf3eac | 2020-03-28 00:01:18 +0100 | [diff] [blame] | 1742 | if (!ret) |
| 1743 | ethtool_notify(dev, ETHTOOL_MSG_COALESCE_NTF, NULL); |
| 1744 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) |
| 1748 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1749 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 1750 | struct kernel_ethtool_ringparam kernel_ringparam = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | |
| 1752 | if (!dev->ethtool_ops->get_ringparam) |
| 1753 | return -EOPNOTSUPP; |
| 1754 | |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 1755 | dev->ethtool_ops->get_ringparam(dev, &ringparam, |
| 1756 | &kernel_ringparam, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | |
| 1758 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) |
| 1759 | return -EFAULT; |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) |
| 1764 | { |
Eugenia Emantayev | 37e2d99 | 2018-01-08 16:00:24 +0200 | [diff] [blame] | 1765 | struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM }; |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 1766 | struct kernel_ethtool_ringparam kernel_ringparam; |
Michal Kubecek | bc9d1c9 | 2020-03-12 21:08:33 +0100 | [diff] [blame] | 1767 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | |
Eugenia Emantayev | 37e2d99 | 2018-01-08 16:00:24 +0200 | [diff] [blame] | 1769 | if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return -EOPNOTSUPP; |
| 1771 | |
| 1772 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) |
| 1773 | return -EFAULT; |
| 1774 | |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 1775 | dev->ethtool_ops->get_ringparam(dev, &max, &kernel_ringparam, NULL); |
Eugenia Emantayev | 37e2d99 | 2018-01-08 16:00:24 +0200 | [diff] [blame] | 1776 | |
| 1777 | /* ensure new ring parameters are within the maximums */ |
| 1778 | if (ringparam.rx_pending > max.rx_max_pending || |
| 1779 | ringparam.rx_mini_pending > max.rx_mini_max_pending || |
| 1780 | ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending || |
| 1781 | ringparam.tx_pending > max.tx_max_pending) |
| 1782 | return -EINVAL; |
| 1783 | |
Hao Chen | 7462494 | 2021-11-18 20:12:43 +0800 | [diff] [blame] | 1784 | ret = dev->ethtool_ops->set_ringparam(dev, &ringparam, |
| 1785 | &kernel_ringparam, NULL); |
Michal Kubecek | bc9d1c9 | 2020-03-12 21:08:33 +0100 | [diff] [blame] | 1786 | if (!ret) |
| 1787 | ethtool_notify(dev, ETHTOOL_MSG_RINGS_NTF, NULL); |
| 1788 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1791 | static noinline_for_stack int ethtool_get_channels(struct net_device *dev, |
| 1792 | void __user *useraddr) |
| 1793 | { |
| 1794 | struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; |
| 1795 | |
| 1796 | if (!dev->ethtool_ops->get_channels) |
| 1797 | return -EOPNOTSUPP; |
| 1798 | |
| 1799 | dev->ethtool_ops->get_channels(dev, &channels); |
| 1800 | |
| 1801 | if (copy_to_user(useraddr, &channels, sizeof(channels))) |
| 1802 | return -EFAULT; |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static noinline_for_stack int ethtool_set_channels(struct net_device *dev, |
| 1807 | void __user *useraddr) |
| 1808 | { |
Jakub Kicinski | b8c8a2e | 2018-10-01 14:51:35 +0200 | [diff] [blame] | 1809 | struct ethtool_channels channels, curr = { .cmd = ETHTOOL_GCHANNELS }; |
Jakub Kicinski | 1661d34 | 2018-10-01 14:51:36 +0200 | [diff] [blame] | 1810 | u16 from_channel, to_channel; |
Keller, Jacob E | d4ab428 | 2016-02-08 16:05:03 -0800 | [diff] [blame] | 1811 | u32 max_rx_in_use = 0; |
Jakub Kicinski | 1661d34 | 2018-10-01 14:51:36 +0200 | [diff] [blame] | 1812 | unsigned int i; |
Michal Kubecek | 546379b | 2020-03-12 21:08:48 +0100 | [diff] [blame] | 1813 | int ret; |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1814 | |
Keller, Jacob E | 8bf3686 | 2016-02-08 16:05:04 -0800 | [diff] [blame] | 1815 | if (!dev->ethtool_ops->set_channels || !dev->ethtool_ops->get_channels) |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1816 | return -EOPNOTSUPP; |
| 1817 | |
| 1818 | if (copy_from_user(&channels, useraddr, sizeof(channels))) |
| 1819 | return -EFAULT; |
| 1820 | |
Jakub Kicinski | b8c8a2e | 2018-10-01 14:51:35 +0200 | [diff] [blame] | 1821 | dev->ethtool_ops->get_channels(dev, &curr); |
Keller, Jacob E | 8bf3686 | 2016-02-08 16:05:04 -0800 | [diff] [blame] | 1822 | |
Jakub Kicinski | 75c36db | 2020-05-15 12:49:02 -0700 | [diff] [blame] | 1823 | if (channels.rx_count == curr.rx_count && |
| 1824 | channels.tx_count == curr.tx_count && |
| 1825 | channels.combined_count == curr.combined_count && |
| 1826 | channels.other_count == curr.other_count) |
| 1827 | return 0; |
| 1828 | |
Keller, Jacob E | 8bf3686 | 2016-02-08 16:05:04 -0800 | [diff] [blame] | 1829 | /* ensure new counts are within the maximums */ |
Jakub Kicinski | b8c8a2e | 2018-10-01 14:51:35 +0200 | [diff] [blame] | 1830 | if (channels.rx_count > curr.max_rx || |
| 1831 | channels.tx_count > curr.max_tx || |
| 1832 | channels.combined_count > curr.max_combined || |
| 1833 | channels.other_count > curr.max_other) |
Keller, Jacob E | 8bf3686 | 2016-02-08 16:05:04 -0800 | [diff] [blame] | 1834 | return -EINVAL; |
| 1835 | |
Jakub Kicinski | 7be9251 | 2020-05-15 12:49:00 -0700 | [diff] [blame] | 1836 | /* ensure there is at least one RX and one TX channel */ |
| 1837 | if (!channels.combined_count && |
| 1838 | (!channels.rx_count || !channels.tx_count)) |
| 1839 | return -EINVAL; |
| 1840 | |
Keller, Jacob E | d4ab428 | 2016-02-08 16:05:03 -0800 | [diff] [blame] | 1841 | /* ensure the new Rx count fits within the configured Rx flow |
| 1842 | * indirection table settings */ |
| 1843 | if (netif_is_rxfh_configured(dev) && |
| 1844 | !ethtool_get_max_rxfh_channel(dev, &max_rx_in_use) && |
| 1845 | (channels.combined_count + channels.rx_count) <= max_rx_in_use) |
| 1846 | return -EINVAL; |
| 1847 | |
Jakub Kicinski | 1661d34 | 2018-10-01 14:51:36 +0200 | [diff] [blame] | 1848 | /* Disabling channels, query zero-copy AF_XDP sockets */ |
| 1849 | from_channel = channels.combined_count + |
| 1850 | min(channels.rx_count, channels.tx_count); |
| 1851 | to_channel = curr.combined_count + max(curr.rx_count, curr.tx_count); |
| 1852 | for (i = from_channel; i < to_channel; i++) |
Magnus Karlsson | c465576 | 2020-08-28 10:26:16 +0200 | [diff] [blame] | 1853 | if (xsk_get_pool_from_qid(dev, i)) |
Jakub Kicinski | 1661d34 | 2018-10-01 14:51:36 +0200 | [diff] [blame] | 1854 | return -EINVAL; |
| 1855 | |
Michal Kubecek | 546379b | 2020-03-12 21:08:48 +0100 | [diff] [blame] | 1856 | ret = dev->ethtool_ops->set_channels(dev, &channels); |
| 1857 | if (!ret) |
| 1858 | ethtool_notify(dev, ETHTOOL_MSG_CHANNELS_NTF, NULL); |
| 1859 | return ret; |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1863 | { |
Li RongQing | e83887f | 2019-02-27 20:47:57 +0800 | [diff] [blame] | 1864 | struct ethtool_pauseparam pauseparam = { .cmd = ETHTOOL_GPAUSEPARAM }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
| 1866 | if (!dev->ethtool_ops->get_pauseparam) |
| 1867 | return -EOPNOTSUPP; |
| 1868 | |
| 1869 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); |
| 1870 | |
| 1871 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) |
| 1872 | return -EFAULT; |
| 1873 | return 0; |
| 1874 | } |
| 1875 | |
| 1876 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1877 | { |
| 1878 | struct ethtool_pauseparam pauseparam; |
Michal Kubecek | bf37faa | 2020-03-28 00:01:33 +0100 | [diff] [blame] | 1879 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
Jeff Garzik | e1b90c4 | 2006-07-17 12:54:40 -0400 | [diff] [blame] | 1881 | if (!dev->ethtool_ops->set_pauseparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | return -EOPNOTSUPP; |
| 1883 | |
| 1884 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) |
| 1885 | return -EFAULT; |
| 1886 | |
Michal Kubecek | bf37faa | 2020-03-28 00:01:33 +0100 | [diff] [blame] | 1887 | ret = dev->ethtool_ops->set_pauseparam(dev, &pauseparam); |
| 1888 | if (!ret) |
| 1889 | ethtool_notify(dev, ETHTOOL_MSG_PAUSE_NTF, NULL); |
| 1890 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
| 1894 | { |
| 1895 | struct ethtool_test test; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1896 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1898 | int ret, test_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1900 | if (!ops->self_test || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1901 | return -EOPNOTSUPP; |
| 1902 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1903 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1904 | if (test_len < 0) |
| 1905 | return test_len; |
| 1906 | WARN_ON(test_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
| 1908 | if (copy_from_user(&test, useraddr, sizeof(test))) |
| 1909 | return -EFAULT; |
| 1910 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1911 | test.len = test_len; |
Austin Kim | 80ec82e | 2021-06-09 03:34:25 +0100 | [diff] [blame] | 1912 | data = kcalloc(test_len, sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | if (!data) |
| 1914 | return -ENOMEM; |
| 1915 | |
Andrew Lunn | 77e9b2a | 2020-04-20 00:11:52 +0200 | [diff] [blame] | 1916 | netif_testing_on(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | ops->self_test(dev, &test, data); |
Andrew Lunn | 77e9b2a | 2020-04-20 00:11:52 +0200 | [diff] [blame] | 1918 | netif_testing_off(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
| 1920 | ret = -EFAULT; |
| 1921 | if (copy_to_user(useraddr, &test, sizeof(test))) |
| 1922 | goto out; |
| 1923 | useraddr += sizeof(test); |
Gustavo A. R. Silva | ed71761 | 2021-09-28 14:57:35 -0500 | [diff] [blame] | 1924 | if (copy_to_user(useraddr, data, array_size(test.len, sizeof(u64)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | goto out; |
| 1926 | ret = 0; |
| 1927 | |
| 1928 | out: |
| 1929 | kfree(data); |
| 1930 | return ret; |
| 1931 | } |
| 1932 | |
| 1933 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
| 1934 | { |
| 1935 | struct ethtool_gstrings gstrings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | u8 *data; |
| 1937 | int ret; |
| 1938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 1940 | return -EFAULT; |
| 1941 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1942 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1943 | if (ret < 0) |
| 1944 | return ret; |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 1945 | if (ret > S32_MAX / ETH_GSTRING_LEN) |
| 1946 | return -ENOMEM; |
| 1947 | WARN_ON_ONCE(!ret); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1948 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1949 | gstrings.len = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | |
Li RongQing | 3d88302 | 2019-03-29 09:18:02 +0800 | [diff] [blame] | 1951 | if (gstrings.len) { |
| 1952 | data = vzalloc(array_size(gstrings.len, ETH_GSTRING_LEN)); |
| 1953 | if (!data) |
| 1954 | return -ENOMEM; |
| 1955 | |
| 1956 | __ethtool_get_strings(dev, gstrings.string_set, data); |
| 1957 | } else { |
| 1958 | data = NULL; |
| 1959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
| 1961 | ret = -EFAULT; |
| 1962 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1963 | goto out; |
| 1964 | useraddr += sizeof(gstrings); |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 1965 | if (gstrings.len && |
Gustavo A. R. Silva | ed71761 | 2021-09-28 14:57:35 -0500 | [diff] [blame] | 1966 | copy_to_user(useraddr, data, |
| 1967 | array_size(gstrings.len, ETH_GSTRING_LEN))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | goto out; |
| 1969 | ret = 0; |
| 1970 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1971 | out: |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 1972 | vfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | return ret; |
| 1974 | } |
| 1975 | |
Alexander Duyck | 7888fe5 | 2021-03-16 17:30:36 -0700 | [diff] [blame] | 1976 | __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...) |
| 1977 | { |
| 1978 | va_list args; |
| 1979 | |
| 1980 | va_start(args, fmt); |
| 1981 | vsnprintf(*data, ETH_GSTRING_LEN, fmt, args); |
| 1982 | va_end(args); |
| 1983 | |
| 1984 | *data += ETH_GSTRING_LEN; |
| 1985 | } |
| 1986 | EXPORT_SYMBOL(ethtool_sprintf); |
| 1987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) |
| 1989 | { |
| 1990 | struct ethtool_value id; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1991 | static bool busy; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1992 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Eric Dumazet | 5ae2195 | 2021-12-04 20:22:00 -0800 | [diff] [blame] | 1993 | netdevice_tracker dev_tracker; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1994 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1996 | if (!ops->set_phys_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | return -EOPNOTSUPP; |
| 1998 | |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1999 | if (busy) |
| 2000 | return -EBUSY; |
| 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | if (copy_from_user(&id, useraddr, sizeof(id))) |
| 2003 | return -EFAULT; |
| 2004 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 2005 | rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 2006 | if (rc < 0) |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2007 | return rc; |
| 2008 | |
| 2009 | /* Drop the RTNL lock while waiting, but prevent reentry or |
| 2010 | * removal of the device. |
| 2011 | */ |
| 2012 | busy = true; |
Eric Dumazet | 5ae2195 | 2021-12-04 20:22:00 -0800 | [diff] [blame] | 2013 | dev_hold_track(dev, &dev_tracker, GFP_KERNEL); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2014 | rtnl_unlock(); |
| 2015 | |
| 2016 | if (rc == 0) { |
| 2017 | /* Driver will handle this itself */ |
| 2018 | schedule_timeout_interruptible( |
Allan, Bruce W | 143780c | 2011-04-11 13:01:59 +0000 | [diff] [blame] | 2019 | id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2020 | } else { |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 2021 | /* Driver expects to be called at twice the frequency in rc */ |
Edward Cree | 2adc6ed | 2020-09-01 18:52:32 +0100 | [diff] [blame] | 2022 | int n = rc * 2, interval = HZ / n; |
| 2023 | u64 count = n * id.data, i = 0; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2024 | |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 2025 | do { |
Edward Cree | 2adc6ed | 2020-09-01 18:52:32 +0100 | [diff] [blame] | 2026 | rtnl_lock(); |
| 2027 | rc = ops->set_phys_id(dev, |
| 2028 | (i++ & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); |
| 2029 | rtnl_unlock(); |
| 2030 | if (rc) |
| 2031 | break; |
| 2032 | schedule_timeout_interruptible(interval); |
| 2033 | } while (!signal_pending(current) && (!id.data || i < count)); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | rtnl_lock(); |
Eric Dumazet | 5ae2195 | 2021-12-04 20:22:00 -0800 | [diff] [blame] | 2037 | dev_put_track(dev, &dev_tracker); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2038 | busy = false; |
| 2039 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 2040 | (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 2041 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) |
| 2045 | { |
| 2046 | struct ethtool_stats stats; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 2047 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 2049 | int ret, n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 2051 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 2052 | return -EOPNOTSUPP; |
| 2053 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 2054 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 2055 | if (n_stats < 0) |
| 2056 | return n_stats; |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 2057 | if (n_stats > S32_MAX / sizeof(u64)) |
| 2058 | return -ENOMEM; |
| 2059 | WARN_ON_ONCE(!n_stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 2061 | return -EFAULT; |
| 2062 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 2063 | stats.n_stats = n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Li RongQing | 3d88302 | 2019-03-29 09:18:02 +0800 | [diff] [blame] | 2065 | if (n_stats) { |
| 2066 | data = vzalloc(array_size(n_stats, sizeof(u64))); |
| 2067 | if (!data) |
| 2068 | return -ENOMEM; |
| 2069 | ops->get_ethtool_stats(dev, &stats, data); |
| 2070 | } else { |
| 2071 | data = NULL; |
| 2072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
| 2074 | ret = -EFAULT; |
| 2075 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 2076 | goto out; |
| 2077 | useraddr += sizeof(stats); |
Gustavo A. R. Silva | 3dd1499 | 2020-06-15 18:01:07 -0500 | [diff] [blame] | 2078 | if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | goto out; |
| 2080 | ret = 0; |
| 2081 | |
| 2082 | out: |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 2083 | vfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | return ret; |
| 2085 | } |
| 2086 | |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2087 | static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr) |
| 2088 | { |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 2089 | const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops; |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2090 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2091 | struct phy_device *phydev = dev->phydev; |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2092 | struct ethtool_stats stats; |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2093 | u64 *data; |
| 2094 | int ret, n_stats; |
| 2095 | |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2096 | if (!phydev && (!ops->get_ethtool_phy_stats || !ops->get_sset_count)) |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2097 | return -EOPNOTSUPP; |
| 2098 | |
Tom Rix | ccd21ec | 2022-01-05 06:10:20 -0800 | [diff] [blame] | 2099 | if (phydev && !ops->get_ethtool_phy_stats && |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 2100 | phy_ops && phy_ops->get_sset_count) |
Tom Rix | ccd21ec | 2022-01-05 06:10:20 -0800 | [diff] [blame] | 2101 | n_stats = phy_ops->get_sset_count(phydev); |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2102 | else |
| 2103 | n_stats = ops->get_sset_count(dev, ETH_SS_PHY_STATS); |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2104 | if (n_stats < 0) |
| 2105 | return n_stats; |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 2106 | if (n_stats > S32_MAX / sizeof(u64)) |
| 2107 | return -ENOMEM; |
| 2108 | WARN_ON_ONCE(!n_stats); |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2109 | |
| 2110 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 2111 | return -EFAULT; |
| 2112 | |
| 2113 | stats.n_stats = n_stats; |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2114 | |
Li RongQing | 3d88302 | 2019-03-29 09:18:02 +0800 | [diff] [blame] | 2115 | if (n_stats) { |
| 2116 | data = vzalloc(array_size(n_stats, sizeof(u64))); |
| 2117 | if (!data) |
| 2118 | return -ENOMEM; |
| 2119 | |
Tom Rix | ccd21ec | 2022-01-05 06:10:20 -0800 | [diff] [blame] | 2120 | if (phydev && !ops->get_ethtool_phy_stats && |
Florian Fainelli | 1780951 | 2020-07-08 09:46:25 -0700 | [diff] [blame] | 2121 | phy_ops && phy_ops->get_stats) { |
Tom Rix | ccd21ec | 2022-01-05 06:10:20 -0800 | [diff] [blame] | 2122 | ret = phy_ops->get_stats(phydev, &stats, data); |
Li RongQing | 3d88302 | 2019-03-29 09:18:02 +0800 | [diff] [blame] | 2123 | if (ret < 0) |
| 2124 | goto out; |
| 2125 | } else { |
| 2126 | ops->get_ethtool_phy_stats(dev, &stats, data); |
| 2127 | } |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2128 | } else { |
Li RongQing | 3d88302 | 2019-03-29 09:18:02 +0800 | [diff] [blame] | 2129 | data = NULL; |
Florian Fainelli | 9994338 | 2018-04-25 12:12:48 -0700 | [diff] [blame] | 2130 | } |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2131 | |
| 2132 | ret = -EFAULT; |
| 2133 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 2134 | goto out; |
| 2135 | useraddr += sizeof(stats); |
Gustavo A. R. Silva | 3dd1499 | 2020-06-15 18:01:07 -0500 | [diff] [blame] | 2136 | if (n_stats && copy_to_user(useraddr, data, array_size(n_stats, sizeof(u64)))) |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2137 | goto out; |
| 2138 | ret = 0; |
| 2139 | |
| 2140 | out: |
Alexei Starovoitov | 4d1ceea | 2017-01-30 18:25:18 -0800 | [diff] [blame] | 2141 | vfree(data); |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2142 | return ret; |
| 2143 | } |
| 2144 | |
viro@ftp.linux.org.uk | 0bf0519d | 2005-09-05 03:26:18 +0100 | [diff] [blame] | 2145 | static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2146 | { |
| 2147 | struct ethtool_perm_addr epaddr; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2148 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 2149 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2150 | return -EFAULT; |
| 2151 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 2152 | if (epaddr.size < dev->addr_len) |
| 2153 | return -ETOOSMALL; |
| 2154 | epaddr.size = dev->addr_len; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2155 | |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2156 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 2157 | return -EFAULT; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2158 | useraddr += sizeof(epaddr); |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 2159 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
| 2160 | return -EFAULT; |
| 2161 | return 0; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2164 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
| 2165 | u32 cmd, u32 (*actor)(struct net_device *)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2166 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 2167 | struct ethtool_value edata = { .cmd = cmd }; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2168 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2169 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2170 | return -EOPNOTSUPP; |
| 2171 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2172 | edata.data = actor(dev); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2173 | |
| 2174 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 2175 | return -EFAULT; |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2179 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
| 2180 | void (*actor)(struct net_device *, u32)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2181 | { |
| 2182 | struct ethtool_value edata; |
| 2183 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2184 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2185 | return -EOPNOTSUPP; |
| 2186 | |
| 2187 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 2188 | return -EFAULT; |
| 2189 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2190 | actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2191 | return 0; |
| 2192 | } |
| 2193 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2194 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
| 2195 | int (*actor)(struct net_device *, u32)) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2196 | { |
| 2197 | struct ethtool_value edata; |
| 2198 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2199 | if (!actor) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2200 | return -EOPNOTSUPP; |
| 2201 | |
| 2202 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 2203 | return -EFAULT; |
| 2204 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2205 | return actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2208 | static int |
| 2209 | ethtool_flash_device(struct net_device *dev, struct ethtool_devlink_compat *req) |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 2210 | { |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 2211 | if (!dev->ethtool_ops->flash_device) { |
| 2212 | req->devlink = netdev_to_devlink_get(dev); |
| 2213 | return 0; |
| 2214 | } |
Jakub Kicinski | 4eceba1 | 2019-02-14 13:40:45 -0800 | [diff] [blame] | 2215 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2216 | return dev->ethtool_ops->flash_device(dev, &req->efl); |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2219 | static int ethtool_set_dump(struct net_device *dev, |
| 2220 | void __user *useraddr) |
| 2221 | { |
| 2222 | struct ethtool_dump dump; |
| 2223 | |
| 2224 | if (!dev->ethtool_ops->set_dump) |
| 2225 | return -EOPNOTSUPP; |
| 2226 | |
| 2227 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 2228 | return -EFAULT; |
| 2229 | |
| 2230 | return dev->ethtool_ops->set_dump(dev, &dump); |
| 2231 | } |
| 2232 | |
| 2233 | static int ethtool_get_dump_flag(struct net_device *dev, |
| 2234 | void __user *useraddr) |
| 2235 | { |
| 2236 | int ret; |
| 2237 | struct ethtool_dump dump; |
| 2238 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2239 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 2240 | if (!ops->get_dump_flag) |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2241 | return -EOPNOTSUPP; |
| 2242 | |
| 2243 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 2244 | return -EFAULT; |
| 2245 | |
| 2246 | ret = ops->get_dump_flag(dev, &dump); |
| 2247 | if (ret) |
| 2248 | return ret; |
| 2249 | |
| 2250 | if (copy_to_user(useraddr, &dump, sizeof(dump))) |
| 2251 | return -EFAULT; |
| 2252 | return 0; |
| 2253 | } |
| 2254 | |
| 2255 | static int ethtool_get_dump_data(struct net_device *dev, |
| 2256 | void __user *useraddr) |
| 2257 | { |
| 2258 | int ret; |
| 2259 | __u32 len; |
| 2260 | struct ethtool_dump dump, tmp; |
| 2261 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2262 | void *data = NULL; |
| 2263 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 2264 | if (!ops->get_dump_data || !ops->get_dump_flag) |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2265 | return -EOPNOTSUPP; |
| 2266 | |
| 2267 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 2268 | return -EFAULT; |
| 2269 | |
| 2270 | memset(&tmp, 0, sizeof(tmp)); |
| 2271 | tmp.cmd = ETHTOOL_GET_DUMP_FLAG; |
| 2272 | ret = ops->get_dump_flag(dev, &tmp); |
| 2273 | if (ret) |
| 2274 | return ret; |
| 2275 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 2276 | len = min(tmp.len, dump.len); |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2277 | if (!len) |
| 2278 | return -EFAULT; |
| 2279 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 2280 | /* Don't ever let the driver think there's more space available |
| 2281 | * than it requested with .get_dump_flag(). |
| 2282 | */ |
| 2283 | dump.len = len; |
| 2284 | |
| 2285 | /* Always allocate enough space to hold the whole thing so that the |
| 2286 | * driver does not need to check the length and bother with partial |
| 2287 | * dumping. |
| 2288 | */ |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2289 | data = vzalloc(tmp.len); |
| 2290 | if (!data) |
| 2291 | return -ENOMEM; |
| 2292 | ret = ops->get_dump_data(dev, &dump, data); |
| 2293 | if (ret) |
| 2294 | goto out; |
| 2295 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 2296 | /* There are two sane possibilities: |
| 2297 | * 1. The driver's .get_dump_data() does not touch dump.len. |
| 2298 | * 2. Or it may set dump.len to how much it really writes, which |
| 2299 | * should be tmp.len (or len if it can do a partial dump). |
| 2300 | * In any case respond to userspace with the actual length of data |
| 2301 | * it's receiving. |
| 2302 | */ |
| 2303 | WARN_ON(dump.len != len && dump.len != tmp.len); |
| 2304 | dump.len = len; |
| 2305 | |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2306 | if (copy_to_user(useraddr, &dump, sizeof(dump))) { |
| 2307 | ret = -EFAULT; |
| 2308 | goto out; |
| 2309 | } |
| 2310 | useraddr += offsetof(struct ethtool_dump, data); |
| 2311 | if (copy_to_user(useraddr, data, len)) |
| 2312 | ret = -EFAULT; |
| 2313 | out: |
| 2314 | vfree(data); |
| 2315 | return ret; |
| 2316 | } |
| 2317 | |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2318 | static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) |
| 2319 | { |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2320 | struct ethtool_ts_info info; |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 2321 | int err; |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2322 | |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 2323 | err = __ethtool_get_ts_info(dev, &info); |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2324 | if (err) |
| 2325 | return err; |
| 2326 | |
| 2327 | if (copy_to_user(useraddr, &info, sizeof(info))) |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 2328 | return -EFAULT; |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2329 | |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 2330 | return 0; |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
Andrew Lunn | 95dfc7e | 2021-04-09 11:06:38 +0300 | [diff] [blame] | 2333 | int ethtool_get_module_info_call(struct net_device *dev, |
| 2334 | struct ethtool_modinfo *modinfo) |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 2335 | { |
| 2336 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2337 | struct phy_device *phydev = dev->phydev; |
| 2338 | |
Russell King | e679c9c | 2018-03-28 15:44:16 -0700 | [diff] [blame] | 2339 | if (dev->sfp_bus) |
| 2340 | return sfp_get_module_info(dev->sfp_bus, modinfo); |
| 2341 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 2342 | if (phydev && phydev->drv && phydev->drv->module_info) |
| 2343 | return phydev->drv->module_info(phydev, modinfo); |
| 2344 | |
| 2345 | if (ops->get_module_info) |
| 2346 | return ops->get_module_info(dev, modinfo); |
| 2347 | |
| 2348 | return -EOPNOTSUPP; |
| 2349 | } |
| 2350 | |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2351 | static int ethtool_get_module_info(struct net_device *dev, |
| 2352 | void __user *useraddr) |
| 2353 | { |
| 2354 | int ret; |
| 2355 | struct ethtool_modinfo modinfo; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2356 | |
| 2357 | if (copy_from_user(&modinfo, useraddr, sizeof(modinfo))) |
| 2358 | return -EFAULT; |
| 2359 | |
Andrew Lunn | 95dfc7e | 2021-04-09 11:06:38 +0300 | [diff] [blame] | 2360 | ret = ethtool_get_module_info_call(dev, &modinfo); |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2361 | if (ret) |
| 2362 | return ret; |
| 2363 | |
| 2364 | if (copy_to_user(useraddr, &modinfo, sizeof(modinfo))) |
| 2365 | return -EFAULT; |
| 2366 | |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
Andrew Lunn | 95dfc7e | 2021-04-09 11:06:38 +0300 | [diff] [blame] | 2370 | int ethtool_get_module_eeprom_call(struct net_device *dev, |
| 2371 | struct ethtool_eeprom *ee, u8 *data) |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 2372 | { |
| 2373 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2374 | struct phy_device *phydev = dev->phydev; |
| 2375 | |
Russell King | e679c9c | 2018-03-28 15:44:16 -0700 | [diff] [blame] | 2376 | if (dev->sfp_bus) |
| 2377 | return sfp_get_module_eeprom(dev->sfp_bus, ee, data); |
| 2378 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 2379 | if (phydev && phydev->drv && phydev->drv->module_eeprom) |
| 2380 | return phydev->drv->module_eeprom(phydev, ee, data); |
| 2381 | |
| 2382 | if (ops->get_module_eeprom) |
| 2383 | return ops->get_module_eeprom(dev, ee, data); |
| 2384 | |
| 2385 | return -EOPNOTSUPP; |
| 2386 | } |
| 2387 | |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2388 | static int ethtool_get_module_eeprom(struct net_device *dev, |
| 2389 | void __user *useraddr) |
| 2390 | { |
| 2391 | int ret; |
| 2392 | struct ethtool_modinfo modinfo; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2393 | |
Andrew Lunn | 95dfc7e | 2021-04-09 11:06:38 +0300 | [diff] [blame] | 2394 | ret = ethtool_get_module_info_call(dev, &modinfo); |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2395 | if (ret) |
| 2396 | return ret; |
| 2397 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 2398 | return ethtool_get_any_eeprom(dev, useraddr, |
Andrew Lunn | 95dfc7e | 2021-04-09 11:06:38 +0300 | [diff] [blame] | 2399 | ethtool_get_module_eeprom_call, |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2400 | modinfo.eeprom_len); |
| 2401 | } |
| 2402 | |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2403 | static int ethtool_tunable_valid(const struct ethtool_tunable *tuna) |
| 2404 | { |
| 2405 | switch (tuna->id) { |
| 2406 | case ETHTOOL_RX_COPYBREAK: |
Eric Dumazet | 1255a50 | 2014-10-05 12:35:21 +0300 | [diff] [blame] | 2407 | case ETHTOOL_TX_COPYBREAK: |
Hao Chen | 448f413 | 2021-11-18 20:12:40 +0800 | [diff] [blame] | 2408 | case ETHTOOL_TX_COPYBREAK_BUF_SIZE: |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2409 | if (tuna->len != sizeof(u32) || |
| 2410 | tuna->type_id != ETHTOOL_TUNABLE_U32) |
| 2411 | return -EINVAL; |
| 2412 | break; |
Inbar Karmy | e1577c1 | 2017-11-20 16:14:30 +0200 | [diff] [blame] | 2413 | case ETHTOOL_PFC_PREVENTION_TOUT: |
| 2414 | if (tuna->len != sizeof(u16) || |
| 2415 | tuna->type_id != ETHTOOL_TUNABLE_U16) |
| 2416 | return -EINVAL; |
| 2417 | break; |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2418 | default: |
| 2419 | return -EINVAL; |
| 2420 | } |
| 2421 | |
| 2422 | return 0; |
| 2423 | } |
| 2424 | |
| 2425 | static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr) |
| 2426 | { |
| 2427 | int ret; |
| 2428 | struct ethtool_tunable tuna; |
| 2429 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2430 | void *data; |
| 2431 | |
| 2432 | if (!ops->get_tunable) |
| 2433 | return -EOPNOTSUPP; |
| 2434 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 2435 | return -EFAULT; |
| 2436 | ret = ethtool_tunable_valid(&tuna); |
| 2437 | if (ret) |
| 2438 | return ret; |
Austin Kim | 80ec82e | 2021-06-09 03:34:25 +0100 | [diff] [blame] | 2439 | data = kzalloc(tuna.len, GFP_USER); |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2440 | if (!data) |
| 2441 | return -ENOMEM; |
| 2442 | ret = ops->get_tunable(dev, &tuna, data); |
| 2443 | if (ret) |
| 2444 | goto out; |
| 2445 | useraddr += sizeof(tuna); |
| 2446 | ret = -EFAULT; |
| 2447 | if (copy_to_user(useraddr, data, tuna.len)) |
| 2448 | goto out; |
| 2449 | ret = 0; |
| 2450 | |
| 2451 | out: |
| 2452 | kfree(data); |
| 2453 | return ret; |
| 2454 | } |
| 2455 | |
| 2456 | static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr) |
| 2457 | { |
| 2458 | int ret; |
| 2459 | struct ethtool_tunable tuna; |
| 2460 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 2461 | void *data; |
| 2462 | |
| 2463 | if (!ops->set_tunable) |
| 2464 | return -EOPNOTSUPP; |
| 2465 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 2466 | return -EFAULT; |
| 2467 | ret = ethtool_tunable_valid(&tuna); |
| 2468 | if (ret) |
| 2469 | return ret; |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2470 | useraddr += sizeof(tuna); |
Al Viro | 30e7e3e | 2017-05-13 18:31:26 -0400 | [diff] [blame] | 2471 | data = memdup_user(useraddr, tuna.len); |
| 2472 | if (IS_ERR(data)) |
| 2473 | return PTR_ERR(data); |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2474 | ret = ops->set_tunable(dev, &tuna, data); |
| 2475 | |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2476 | kfree(data); |
| 2477 | return ret; |
| 2478 | } |
| 2479 | |
Arnd Bergmann | 3499e87 | 2019-03-07 16:58:35 +0100 | [diff] [blame] | 2480 | static noinline_for_stack int |
| 2481 | ethtool_get_per_queue_coalesce(struct net_device *dev, |
| 2482 | void __user *useraddr, |
| 2483 | struct ethtool_per_queue_op *per_queue_opt) |
Kan Liang | 421797b | 2016-02-19 09:24:02 -0500 | [diff] [blame] | 2484 | { |
| 2485 | u32 bit; |
| 2486 | int ret; |
| 2487 | DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); |
| 2488 | |
| 2489 | if (!dev->ethtool_ops->get_per_queue_coalesce) |
| 2490 | return -EOPNOTSUPP; |
| 2491 | |
| 2492 | useraddr += sizeof(*per_queue_opt); |
| 2493 | |
Yury Norov | 3aa5688 | 2018-02-06 15:38:06 -0800 | [diff] [blame] | 2494 | bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, |
| 2495 | MAX_NUM_QUEUE); |
Kan Liang | 421797b | 2016-02-19 09:24:02 -0500 | [diff] [blame] | 2496 | |
| 2497 | for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { |
| 2498 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
| 2499 | |
| 2500 | ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, &coalesce); |
| 2501 | if (ret != 0) |
| 2502 | return ret; |
| 2503 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 2504 | return -EFAULT; |
| 2505 | useraddr += sizeof(coalesce); |
| 2506 | } |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Arnd Bergmann | 3499e87 | 2019-03-07 16:58:35 +0100 | [diff] [blame] | 2511 | static noinline_for_stack int |
| 2512 | ethtool_set_per_queue_coalesce(struct net_device *dev, |
| 2513 | void __user *useraddr, |
| 2514 | struct ethtool_per_queue_op *per_queue_opt) |
Kan Liang | f38d138 | 2016-02-19 09:24:03 -0500 | [diff] [blame] | 2515 | { |
| 2516 | u32 bit; |
| 2517 | int i, ret = 0; |
| 2518 | int n_queue; |
| 2519 | struct ethtool_coalesce *backup = NULL, *tmp = NULL; |
| 2520 | DECLARE_BITMAP(queue_mask, MAX_NUM_QUEUE); |
| 2521 | |
| 2522 | if ((!dev->ethtool_ops->set_per_queue_coalesce) || |
| 2523 | (!dev->ethtool_ops->get_per_queue_coalesce)) |
| 2524 | return -EOPNOTSUPP; |
| 2525 | |
| 2526 | useraddr += sizeof(*per_queue_opt); |
| 2527 | |
Yury Norov | 3aa5688 | 2018-02-06 15:38:06 -0800 | [diff] [blame] | 2528 | bitmap_from_arr32(queue_mask, per_queue_opt->queue_mask, MAX_NUM_QUEUE); |
Kan Liang | f38d138 | 2016-02-19 09:24:03 -0500 | [diff] [blame] | 2529 | n_queue = bitmap_weight(queue_mask, MAX_NUM_QUEUE); |
| 2530 | tmp = backup = kmalloc_array(n_queue, sizeof(*backup), GFP_KERNEL); |
| 2531 | if (!backup) |
| 2532 | return -ENOMEM; |
| 2533 | |
| 2534 | for_each_set_bit(bit, queue_mask, MAX_NUM_QUEUE) { |
| 2535 | struct ethtool_coalesce coalesce; |
| 2536 | |
| 2537 | ret = dev->ethtool_ops->get_per_queue_coalesce(dev, bit, tmp); |
| 2538 | if (ret != 0) |
| 2539 | goto roll_back; |
| 2540 | |
| 2541 | tmp++; |
| 2542 | |
| 2543 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) { |
| 2544 | ret = -EFAULT; |
| 2545 | goto roll_back; |
| 2546 | } |
| 2547 | |
Jakub Kicinski | 95cddcb | 2020-03-04 21:15:31 -0800 | [diff] [blame] | 2548 | if (!ethtool_set_coalesce_supported(dev, &coalesce)) { |
| 2549 | ret = -EOPNOTSUPP; |
| 2550 | goto roll_back; |
| 2551 | } |
| 2552 | |
Kan Liang | f38d138 | 2016-02-19 09:24:03 -0500 | [diff] [blame] | 2553 | ret = dev->ethtool_ops->set_per_queue_coalesce(dev, bit, &coalesce); |
| 2554 | if (ret != 0) |
| 2555 | goto roll_back; |
| 2556 | |
| 2557 | useraddr += sizeof(coalesce); |
| 2558 | } |
| 2559 | |
| 2560 | roll_back: |
| 2561 | if (ret != 0) { |
| 2562 | tmp = backup; |
| 2563 | for_each_set_bit(i, queue_mask, bit) { |
| 2564 | dev->ethtool_ops->set_per_queue_coalesce(dev, i, tmp); |
| 2565 | tmp++; |
| 2566 | } |
| 2567 | } |
| 2568 | kfree(backup); |
| 2569 | |
| 2570 | return ret; |
| 2571 | } |
| 2572 | |
Arnd Bergmann | 3499e87 | 2019-03-07 16:58:35 +0100 | [diff] [blame] | 2573 | static int noinline_for_stack ethtool_set_per_queue(struct net_device *dev, |
Wenwen Wang | 58f5bbe | 2018-10-08 10:49:35 -0500 | [diff] [blame] | 2574 | void __user *useraddr, u32 sub_cmd) |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2575 | { |
| 2576 | struct ethtool_per_queue_op per_queue_opt; |
| 2577 | |
| 2578 | if (copy_from_user(&per_queue_opt, useraddr, sizeof(per_queue_opt))) |
| 2579 | return -EFAULT; |
| 2580 | |
Wenwen Wang | 58f5bbe | 2018-10-08 10:49:35 -0500 | [diff] [blame] | 2581 | if (per_queue_opt.sub_command != sub_cmd) |
| 2582 | return -EINVAL; |
| 2583 | |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2584 | switch (per_queue_opt.sub_command) { |
Kan Liang | 421797b | 2016-02-19 09:24:02 -0500 | [diff] [blame] | 2585 | case ETHTOOL_GCOALESCE: |
| 2586 | return ethtool_get_per_queue_coalesce(dev, useraddr, &per_queue_opt); |
Kan Liang | f38d138 | 2016-02-19 09:24:03 -0500 | [diff] [blame] | 2587 | case ETHTOOL_SCOALESCE: |
| 2588 | return ethtool_set_per_queue_coalesce(dev, useraddr, &per_queue_opt); |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2589 | default: |
| 2590 | return -EOPNOTSUPP; |
Tom Rix | 9d253c0 | 2020-11-01 07:56:01 -0800 | [diff] [blame] | 2591 | } |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2592 | } |
| 2593 | |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2594 | static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna) |
| 2595 | { |
| 2596 | switch (tuna->id) { |
Raju Lakkaraju | 65feddd | 2016-11-17 13:07:23 +0100 | [diff] [blame] | 2597 | case ETHTOOL_PHY_DOWNSHIFT: |
Heiner Kallweit | 3aeb080 | 2019-03-25 19:34:58 +0100 | [diff] [blame] | 2598 | case ETHTOOL_PHY_FAST_LINK_DOWN: |
Raju Lakkaraju | 65feddd | 2016-11-17 13:07:23 +0100 | [diff] [blame] | 2599 | if (tuna->len != sizeof(u8) || |
| 2600 | tuna->type_id != ETHTOOL_TUNABLE_U8) |
| 2601 | return -EINVAL; |
| 2602 | break; |
Alexandru Ardelean | 9f2f13f | 2019-09-16 10:35:25 +0300 | [diff] [blame] | 2603 | case ETHTOOL_PHY_EDPD: |
| 2604 | if (tuna->len != sizeof(u16) || |
| 2605 | tuna->type_id != ETHTOOL_TUNABLE_U16) |
| 2606 | return -EINVAL; |
| 2607 | break; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2608 | default: |
| 2609 | return -EINVAL; |
| 2610 | } |
| 2611 | |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
| 2615 | static int get_phy_tunable(struct net_device *dev, void __user *useraddr) |
| 2616 | { |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2617 | struct phy_device *phydev = dev->phydev; |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2618 | struct ethtool_tunable tuna; |
| 2619 | bool phy_drv_tunable; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2620 | void *data; |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2621 | int ret; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2622 | |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2623 | phy_drv_tunable = phydev && phydev->drv && phydev->drv->get_tunable; |
| 2624 | if (!phy_drv_tunable && !dev->ethtool_ops->get_phy_tunable) |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2625 | return -EOPNOTSUPP; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2626 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 2627 | return -EFAULT; |
| 2628 | ret = ethtool_phy_tunable_valid(&tuna); |
| 2629 | if (ret) |
| 2630 | return ret; |
Austin Kim | 80ec82e | 2021-06-09 03:34:25 +0100 | [diff] [blame] | 2631 | data = kzalloc(tuna.len, GFP_USER); |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2632 | if (!data) |
| 2633 | return -ENOMEM; |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2634 | if (phy_drv_tunable) { |
| 2635 | mutex_lock(&phydev->lock); |
| 2636 | ret = phydev->drv->get_tunable(phydev, &tuna, data); |
| 2637 | mutex_unlock(&phydev->lock); |
| 2638 | } else { |
| 2639 | ret = dev->ethtool_ops->get_phy_tunable(dev, &tuna, data); |
| 2640 | } |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2641 | if (ret) |
| 2642 | goto out; |
| 2643 | useraddr += sizeof(tuna); |
| 2644 | ret = -EFAULT; |
| 2645 | if (copy_to_user(useraddr, data, tuna.len)) |
| 2646 | goto out; |
| 2647 | ret = 0; |
| 2648 | |
| 2649 | out: |
| 2650 | kfree(data); |
| 2651 | return ret; |
| 2652 | } |
| 2653 | |
| 2654 | static int set_phy_tunable(struct net_device *dev, void __user *useraddr) |
| 2655 | { |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2656 | struct phy_device *phydev = dev->phydev; |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2657 | struct ethtool_tunable tuna; |
| 2658 | bool phy_drv_tunable; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2659 | void *data; |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2660 | int ret; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2661 | |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2662 | phy_drv_tunable = phydev && phydev->drv && phydev->drv->get_tunable; |
| 2663 | if (!phy_drv_tunable && !dev->ethtool_ops->set_phy_tunable) |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2664 | return -EOPNOTSUPP; |
| 2665 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 2666 | return -EFAULT; |
| 2667 | ret = ethtool_phy_tunable_valid(&tuna); |
| 2668 | if (ret) |
| 2669 | return ret; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2670 | useraddr += sizeof(tuna); |
Al Viro | 30e7e3e | 2017-05-13 18:31:26 -0400 | [diff] [blame] | 2671 | data = memdup_user(useraddr, tuna.len); |
| 2672 | if (IS_ERR(data)) |
| 2673 | return PTR_ERR(data); |
Igor Russkikh | c6db31f | 2020-10-05 18:39:37 +0300 | [diff] [blame] | 2674 | if (phy_drv_tunable) { |
| 2675 | mutex_lock(&phydev->lock); |
| 2676 | ret = phydev->drv->set_tunable(phydev, &tuna, data); |
| 2677 | mutex_unlock(&phydev->lock); |
| 2678 | } else { |
| 2679 | ret = dev->ethtool_ops->set_phy_tunable(dev, &tuna, data); |
| 2680 | } |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2681 | |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2682 | kfree(data); |
| 2683 | return ret; |
| 2684 | } |
| 2685 | |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2686 | static int ethtool_get_fecparam(struct net_device *dev, void __user *useraddr) |
| 2687 | { |
Li RongQing | e83887f | 2019-02-27 20:47:57 +0800 | [diff] [blame] | 2688 | struct ethtool_fecparam fecparam = { .cmd = ETHTOOL_GFECPARAM }; |
Edward Cree | a6d5051 | 2018-02-28 19:15:58 +0000 | [diff] [blame] | 2689 | int rc; |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2690 | |
| 2691 | if (!dev->ethtool_ops->get_fecparam) |
| 2692 | return -EOPNOTSUPP; |
| 2693 | |
Edward Cree | a6d5051 | 2018-02-28 19:15:58 +0000 | [diff] [blame] | 2694 | rc = dev->ethtool_ops->get_fecparam(dev, &fecparam); |
| 2695 | if (rc) |
| 2696 | return rc; |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2697 | |
Jakub Kicinski | 240e1144 | 2021-03-24 18:11:57 -0700 | [diff] [blame] | 2698 | if (WARN_ON_ONCE(fecparam.reserved)) |
| 2699 | fecparam.reserved = 0; |
| 2700 | |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2701 | if (copy_to_user(useraddr, &fecparam, sizeof(fecparam))) |
| 2702 | return -EFAULT; |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
| 2706 | static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr) |
| 2707 | { |
| 2708 | struct ethtool_fecparam fecparam; |
| 2709 | |
| 2710 | if (!dev->ethtool_ops->set_fecparam) |
| 2711 | return -EOPNOTSUPP; |
| 2712 | |
| 2713 | if (copy_from_user(&fecparam, useraddr, sizeof(fecparam))) |
| 2714 | return -EFAULT; |
| 2715 | |
Jakub Kicinski | cf2cc0b | 2021-03-26 13:22:22 -0700 | [diff] [blame] | 2716 | if (!fecparam.fec || fecparam.fec & ETHTOOL_FEC_NONE) |
Jakub Kicinski | 42ce127 | 2021-03-24 18:11:59 -0700 | [diff] [blame] | 2717 | return -EINVAL; |
| 2718 | |
Jakub Kicinski | d3b37fc | 2021-03-24 18:11:58 -0700 | [diff] [blame] | 2719 | fecparam.active_fec = 0; |
Jakub Kicinski | 240e1144 | 2021-03-24 18:11:57 -0700 | [diff] [blame] | 2720 | fecparam.reserved = 0; |
| 2721 | |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2722 | return dev->ethtool_ops->set_fecparam(dev, &fecparam); |
| 2723 | } |
| 2724 | |
Yan Burman | 600fed5 | 2013-06-03 02:03:34 +0000 | [diff] [blame] | 2725 | /* The main entry point in this file. Called from net/core/dev_ioctl.c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | |
Jakub Kicinski | f49deaa | 2021-10-30 10:18:48 -0700 | [diff] [blame] | 2727 | static int |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2728 | __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr, |
| 2729 | u32 ethcmd, struct ethtool_devlink_compat *devlink_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | { |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2731 | struct net_device *dev; |
| 2732 | u32 sub_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | int rc; |
Bjørn Mork | b29d314 | 2013-05-01 23:06:42 +0000 | [diff] [blame] | 2734 | netdev_features_t old_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2736 | dev = __dev_get_by_name(net, ifr->ifr_name); |
Heiner Kallweit | f32a213 | 2021-08-01 12:36:48 +0200 | [diff] [blame] | 2737 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | return -ENODEV; |
| 2739 | |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2740 | if (ethcmd == ETHTOOL_PERQUEUE) { |
| 2741 | if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd))) |
| 2742 | return -EFAULT; |
| 2743 | } else { |
| 2744 | sub_cmd = ethcmd; |
| 2745 | } |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2746 | /* Allow some commands to be done by anyone */ |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2747 | switch (sub_cmd) { |
stephen hemminger | 0fdc100 | 2010-08-23 10:24:18 +0000 | [diff] [blame] | 2748 | case ETHTOOL_GSET: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2749 | case ETHTOOL_GDRVINFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2750 | case ETHTOOL_GMSGLVL: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 2751 | case ETHTOOL_GLINK: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2752 | case ETHTOOL_GCOALESCE: |
| 2753 | case ETHTOOL_GRINGPARAM: |
| 2754 | case ETHTOOL_GPAUSEPARAM: |
| 2755 | case ETHTOOL_GRXCSUM: |
| 2756 | case ETHTOOL_GTXCSUM: |
| 2757 | case ETHTOOL_GSG: |
Michał Mirosław | f80400a | 2012-01-22 00:20:40 +0000 | [diff] [blame] | 2758 | case ETHTOOL_GSSET_INFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2759 | case ETHTOOL_GSTRINGS: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 2760 | case ETHTOOL_GSTATS: |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2761 | case ETHTOOL_GPHYSTATS: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2762 | case ETHTOOL_GTSO: |
| 2763 | case ETHTOOL_GPERMADDR: |
Maciej Żenczykowski | 474ff26 | 2018-09-22 01:34:01 -0700 | [diff] [blame] | 2764 | case ETHTOOL_GUFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2765 | case ETHTOOL_GGSO: |
stephen hemminger | 1cab819 | 2010-02-11 13:48:29 +0000 | [diff] [blame] | 2766 | case ETHTOOL_GGRO: |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2767 | case ETHTOOL_GFLAGS: |
| 2768 | case ETHTOOL_GPFLAGS: |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 2769 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 2770 | case ETHTOOL_GRXRINGS: |
| 2771 | case ETHTOOL_GRXCLSRLCNT: |
| 2772 | case ETHTOOL_GRXCLSRULE: |
| 2773 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 2774 | case ETHTOOL_GRXFHINDIR: |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 2775 | case ETHTOOL_GRSSH: |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2776 | case ETHTOOL_GFEATURES: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 2777 | case ETHTOOL_GCHANNELS: |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2778 | case ETHTOOL_GET_TS_INFO: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 2779 | case ETHTOOL_GEEE: |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2780 | case ETHTOOL_GTUNABLE: |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2781 | case ETHTOOL_PHY_GTUNABLE: |
Miroslav Lichvar | 8006f6b | 2016-11-24 10:55:06 +0100 | [diff] [blame] | 2782 | case ETHTOOL_GLINKSETTINGS: |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 2783 | case ETHTOOL_GFECPARAM: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2784 | break; |
| 2785 | default: |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 2786 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 2787 | return -EPERM; |
| 2788 | } |
| 2789 | |
Heiner Kallweit | f32a213 | 2021-08-01 12:36:48 +0200 | [diff] [blame] | 2790 | if (dev->dev.parent) |
| 2791 | pm_runtime_get_sync(dev->dev.parent); |
| 2792 | |
| 2793 | if (!netif_device_present(dev)) { |
| 2794 | rc = -ENODEV; |
| 2795 | goto out; |
| 2796 | } |
| 2797 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 2798 | if (dev->ethtool_ops->begin) { |
| 2799 | rc = dev->ethtool_ops->begin(dev); |
Heiner Kallweit | f32a213 | 2021-08-01 12:36:48 +0200 | [diff] [blame] | 2800 | if (rc < 0) |
| 2801 | goto out; |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 2802 | } |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 2803 | old_features = dev->features; |
| 2804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | switch (ethcmd) { |
| 2806 | case ETHTOOL_GSET: |
| 2807 | rc = ethtool_get_settings(dev, useraddr); |
| 2808 | break; |
| 2809 | case ETHTOOL_SSET: |
| 2810 | rc = ethtool_set_settings(dev, useraddr); |
| 2811 | break; |
| 2812 | case ETHTOOL_GDRVINFO: |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2813 | rc = ethtool_get_drvinfo(dev, devlink_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | break; |
| 2815 | case ETHTOOL_GREGS: |
| 2816 | rc = ethtool_get_regs(dev, useraddr); |
| 2817 | break; |
| 2818 | case ETHTOOL_GWOL: |
| 2819 | rc = ethtool_get_wol(dev, useraddr); |
| 2820 | break; |
| 2821 | case ETHTOOL_SWOL: |
| 2822 | rc = ethtool_set_wol(dev, useraddr); |
| 2823 | break; |
| 2824 | case ETHTOOL_GMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2825 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 2826 | dev->ethtool_ops->get_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | break; |
| 2828 | case ETHTOOL_SMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2829 | rc = ethtool_set_value_void(dev, useraddr, |
| 2830 | dev->ethtool_ops->set_msglevel); |
Michal Kubecek | 0bda7af | 2020-01-26 23:11:10 +0100 | [diff] [blame] | 2831 | if (!rc) |
| 2832 | ethtool_notify(dev, ETHTOOL_MSG_DEBUG_NTF, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | break; |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 2834 | case ETHTOOL_GEEE: |
| 2835 | rc = ethtool_get_eee(dev, useraddr); |
| 2836 | break; |
| 2837 | case ETHTOOL_SEEE: |
| 2838 | rc = ethtool_set_eee(dev, useraddr); |
| 2839 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | case ETHTOOL_NWAY_RST: |
| 2841 | rc = ethtool_nway_reset(dev); |
| 2842 | break; |
| 2843 | case ETHTOOL_GLINK: |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 2844 | rc = ethtool_get_link(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | break; |
| 2846 | case ETHTOOL_GEEPROM: |
| 2847 | rc = ethtool_get_eeprom(dev, useraddr); |
| 2848 | break; |
| 2849 | case ETHTOOL_SEEPROM: |
| 2850 | rc = ethtool_set_eeprom(dev, useraddr); |
| 2851 | break; |
| 2852 | case ETHTOOL_GCOALESCE: |
| 2853 | rc = ethtool_get_coalesce(dev, useraddr); |
| 2854 | break; |
| 2855 | case ETHTOOL_SCOALESCE: |
| 2856 | rc = ethtool_set_coalesce(dev, useraddr); |
| 2857 | break; |
| 2858 | case ETHTOOL_GRINGPARAM: |
| 2859 | rc = ethtool_get_ringparam(dev, useraddr); |
| 2860 | break; |
| 2861 | case ETHTOOL_SRINGPARAM: |
| 2862 | rc = ethtool_set_ringparam(dev, useraddr); |
| 2863 | break; |
| 2864 | case ETHTOOL_GPAUSEPARAM: |
| 2865 | rc = ethtool_get_pauseparam(dev, useraddr); |
| 2866 | break; |
| 2867 | case ETHTOOL_SPAUSEPARAM: |
| 2868 | rc = ethtool_set_pauseparam(dev, useraddr); |
| 2869 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | case ETHTOOL_TEST: |
| 2871 | rc = ethtool_self_test(dev, useraddr); |
| 2872 | break; |
| 2873 | case ETHTOOL_GSTRINGS: |
| 2874 | rc = ethtool_get_strings(dev, useraddr); |
| 2875 | break; |
| 2876 | case ETHTOOL_PHYS_ID: |
| 2877 | rc = ethtool_phys_id(dev, useraddr); |
| 2878 | break; |
| 2879 | case ETHTOOL_GSTATS: |
| 2880 | rc = ethtool_get_stats(dev, useraddr); |
| 2881 | break; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 2882 | case ETHTOOL_GPERMADDR: |
| 2883 | rc = ethtool_get_perm_addr(dev, useraddr); |
| 2884 | break; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2885 | case ETHTOOL_GFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2886 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 2887 | __ethtool_get_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2888 | break; |
| 2889 | case ETHTOOL_SFLAGS: |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 2890 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 2891 | break; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2892 | case ETHTOOL_GPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2893 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 2894 | dev->ethtool_ops->get_priv_flags); |
Michal Kubecek | 111dcba | 2020-03-12 21:08:18 +0100 | [diff] [blame] | 2895 | if (!rc) |
| 2896 | ethtool_notify(dev, ETHTOOL_MSG_PRIVFLAGS_NTF, NULL); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2897 | break; |
| 2898 | case ETHTOOL_SPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 2899 | rc = ethtool_set_value(dev, useraddr, |
| 2900 | dev->ethtool_ops->set_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 2901 | break; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 2902 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 2903 | case ETHTOOL_GRXRINGS: |
| 2904 | case ETHTOOL_GRXCLSRLCNT: |
| 2905 | case ETHTOOL_GRXCLSRULE: |
| 2906 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 2907 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 2908 | break; |
| 2909 | case ETHTOOL_SRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 2910 | case ETHTOOL_SRXCLSRLDEL: |
| 2911 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 2912 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 2913 | break; |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 2914 | case ETHTOOL_FLASHDEV: |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 2915 | rc = ethtool_flash_device(dev, devlink_state); |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 2916 | break; |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 2917 | case ETHTOOL_RESET: |
| 2918 | rc = ethtool_reset(dev, useraddr); |
| 2919 | break; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 2920 | case ETHTOOL_GSSET_INFO: |
| 2921 | rc = ethtool_get_sset_info(dev, useraddr); |
| 2922 | break; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 2923 | case ETHTOOL_GRXFHINDIR: |
| 2924 | rc = ethtool_get_rxfh_indir(dev, useraddr); |
| 2925 | break; |
| 2926 | case ETHTOOL_SRXFHINDIR: |
| 2927 | rc = ethtool_set_rxfh_indir(dev, useraddr); |
| 2928 | break; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 2929 | case ETHTOOL_GRSSH: |
| 2930 | rc = ethtool_get_rxfh(dev, useraddr); |
| 2931 | break; |
| 2932 | case ETHTOOL_SRSSH: |
| 2933 | rc = ethtool_set_rxfh(dev, useraddr); |
| 2934 | break; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2935 | case ETHTOOL_GFEATURES: |
| 2936 | rc = ethtool_get_features(dev, useraddr); |
| 2937 | break; |
| 2938 | case ETHTOOL_SFEATURES: |
| 2939 | rc = ethtool_set_features(dev, useraddr); |
| 2940 | break; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2941 | case ETHTOOL_GTXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 2942 | case ETHTOOL_GRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2943 | case ETHTOOL_GSG: |
| 2944 | case ETHTOOL_GTSO: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2945 | case ETHTOOL_GGSO: |
| 2946 | case ETHTOOL_GGRO: |
| 2947 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); |
| 2948 | break; |
| 2949 | case ETHTOOL_STXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 2950 | case ETHTOOL_SRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2951 | case ETHTOOL_SSG: |
| 2952 | case ETHTOOL_STSO: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 2953 | case ETHTOOL_SGSO: |
| 2954 | case ETHTOOL_SGRO: |
| 2955 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); |
| 2956 | break; |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 2957 | case ETHTOOL_GCHANNELS: |
| 2958 | rc = ethtool_get_channels(dev, useraddr); |
| 2959 | break; |
| 2960 | case ETHTOOL_SCHANNELS: |
| 2961 | rc = ethtool_set_channels(dev, useraddr); |
| 2962 | break; |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 2963 | case ETHTOOL_SET_DUMP: |
| 2964 | rc = ethtool_set_dump(dev, useraddr); |
| 2965 | break; |
| 2966 | case ETHTOOL_GET_DUMP_FLAG: |
| 2967 | rc = ethtool_get_dump_flag(dev, useraddr); |
| 2968 | break; |
| 2969 | case ETHTOOL_GET_DUMP_DATA: |
| 2970 | rc = ethtool_get_dump_data(dev, useraddr); |
| 2971 | break; |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 2972 | case ETHTOOL_GET_TS_INFO: |
| 2973 | rc = ethtool_get_ts_info(dev, useraddr); |
| 2974 | break; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 2975 | case ETHTOOL_GMODULEINFO: |
| 2976 | rc = ethtool_get_module_info(dev, useraddr); |
| 2977 | break; |
| 2978 | case ETHTOOL_GMODULEEEPROM: |
| 2979 | rc = ethtool_get_module_eeprom(dev, useraddr); |
| 2980 | break; |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 2981 | case ETHTOOL_GTUNABLE: |
| 2982 | rc = ethtool_get_tunable(dev, useraddr); |
| 2983 | break; |
| 2984 | case ETHTOOL_STUNABLE: |
| 2985 | rc = ethtool_set_tunable(dev, useraddr); |
| 2986 | break; |
Andrew Lunn | f3a4094 | 2015-12-30 16:28:25 +0100 | [diff] [blame] | 2987 | case ETHTOOL_GPHYSTATS: |
| 2988 | rc = ethtool_get_phy_stats(dev, useraddr); |
| 2989 | break; |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2990 | case ETHTOOL_PERQUEUE: |
Wenwen Wang | 58f5bbe | 2018-10-08 10:49:35 -0500 | [diff] [blame] | 2991 | rc = ethtool_set_per_queue(dev, useraddr, sub_cmd); |
Kan Liang | ac2c7ad | 2016-02-19 09:24:01 -0500 | [diff] [blame] | 2992 | break; |
David Decotigny | 3f1ac7a | 2016-02-24 10:57:59 -0800 | [diff] [blame] | 2993 | case ETHTOOL_GLINKSETTINGS: |
| 2994 | rc = ethtool_get_link_ksettings(dev, useraddr); |
| 2995 | break; |
| 2996 | case ETHTOOL_SLINKSETTINGS: |
| 2997 | rc = ethtool_set_link_ksettings(dev, useraddr); |
| 2998 | break; |
Raju Lakkaraju | 968ad9d | 2016-11-17 13:07:21 +0100 | [diff] [blame] | 2999 | case ETHTOOL_PHY_GTUNABLE: |
| 3000 | rc = get_phy_tunable(dev, useraddr); |
| 3001 | break; |
| 3002 | case ETHTOOL_PHY_STUNABLE: |
| 3003 | rc = set_phy_tunable(dev, useraddr); |
| 3004 | break; |
Vidya Sagar Ravipati | 1a5f3da | 2017-07-27 16:47:26 -0700 | [diff] [blame] | 3005 | case ETHTOOL_GFECPARAM: |
| 3006 | rc = ethtool_get_fecparam(dev, useraddr); |
| 3007 | break; |
| 3008 | case ETHTOOL_SFECPARAM: |
| 3009 | rc = ethtool_set_fecparam(dev, useraddr); |
| 3010 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | default: |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 3012 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 3014 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 3015 | if (dev->ethtool_ops->complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | dev->ethtool_ops->complete(dev); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 3017 | |
| 3018 | if (old_features != dev->features) |
| 3019 | netdev_features_change(dev); |
Heiner Kallweit | f32a213 | 2021-08-01 12:36:48 +0200 | [diff] [blame] | 3020 | out: |
| 3021 | if (dev->dev.parent) |
| 3022 | pm_runtime_put(dev->dev.parent); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 3023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | } |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3026 | |
Jakub Kicinski | f49deaa | 2021-10-30 10:18:48 -0700 | [diff] [blame] | 3027 | int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr) |
| 3028 | { |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3029 | struct ethtool_devlink_compat *state; |
| 3030 | u32 ethcmd; |
Jakub Kicinski | f49deaa | 2021-10-30 10:18:48 -0700 | [diff] [blame] | 3031 | int rc; |
| 3032 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3033 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
| 3034 | return -EFAULT; |
Jakub Kicinski | f49deaa | 2021-10-30 10:18:48 -0700 | [diff] [blame] | 3035 | |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3036 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 3037 | if (!state) |
| 3038 | return -ENOMEM; |
| 3039 | |
| 3040 | switch (ethcmd) { |
| 3041 | case ETHTOOL_FLASHDEV: |
| 3042 | if (copy_from_user(&state->efl, useraddr, sizeof(state->efl))) { |
| 3043 | rc = -EFAULT; |
| 3044 | goto exit_free; |
| 3045 | } |
| 3046 | state->efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 3047 | break; |
| 3048 | } |
| 3049 | |
| 3050 | rtnl_lock(); |
| 3051 | rc = __dev_ethtool(net, ifr, useraddr, ethcmd, state); |
| 3052 | rtnl_unlock(); |
| 3053 | if (rc) |
| 3054 | goto exit_free; |
| 3055 | |
| 3056 | switch (ethcmd) { |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 3057 | case ETHTOOL_FLASHDEV: |
| 3058 | if (state->devlink) |
| 3059 | rc = devlink_compat_flash_update(state->devlink, |
| 3060 | state->efl.data); |
| 3061 | break; |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3062 | case ETHTOOL_GDRVINFO: |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 3063 | if (state->devlink) |
| 3064 | devlink_compat_running_version(state->devlink, |
| 3065 | state->info.fw_version, |
| 3066 | sizeof(state->info.fw_version)); |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3067 | if (copy_to_user(useraddr, &state->info, sizeof(state->info))) { |
| 3068 | rc = -EFAULT; |
| 3069 | goto exit_free; |
| 3070 | } |
| 3071 | break; |
| 3072 | } |
| 3073 | |
| 3074 | exit_free: |
Jakub Kicinski | 1af0a09 | 2021-10-30 10:18:51 -0700 | [diff] [blame] | 3075 | if (state->devlink) |
| 3076 | devlink_put(state->devlink); |
Jakub Kicinski | 095cfcf | 2021-10-30 10:18:49 -0700 | [diff] [blame] | 3077 | kfree(state); |
Jakub Kicinski | f49deaa | 2021-10-30 10:18:48 -0700 | [diff] [blame] | 3078 | return rc; |
| 3079 | } |
| 3080 | |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3081 | struct ethtool_rx_flow_key { |
| 3082 | struct flow_dissector_key_basic basic; |
| 3083 | union { |
| 3084 | struct flow_dissector_key_ipv4_addrs ipv4; |
| 3085 | struct flow_dissector_key_ipv6_addrs ipv6; |
| 3086 | }; |
| 3087 | struct flow_dissector_key_ports tp; |
| 3088 | struct flow_dissector_key_ip ip; |
| 3089 | struct flow_dissector_key_vlan vlan; |
| 3090 | struct flow_dissector_key_eth_addrs eth_addrs; |
| 3091 | } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */ |
| 3092 | |
| 3093 | struct ethtool_rx_flow_match { |
| 3094 | struct flow_dissector dissector; |
| 3095 | struct ethtool_rx_flow_key key; |
| 3096 | struct ethtool_rx_flow_key mask; |
| 3097 | }; |
| 3098 | |
| 3099 | struct ethtool_rx_flow_rule * |
| 3100 | ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input) |
| 3101 | { |
| 3102 | const struct ethtool_rx_flow_spec *fs = input->fs; |
| 3103 | static struct in6_addr zero_addr = {}; |
| 3104 | struct ethtool_rx_flow_match *match; |
| 3105 | struct ethtool_rx_flow_rule *flow; |
| 3106 | struct flow_action_entry *act; |
| 3107 | |
| 3108 | flow = kzalloc(sizeof(struct ethtool_rx_flow_rule) + |
| 3109 | sizeof(struct ethtool_rx_flow_match), GFP_KERNEL); |
| 3110 | if (!flow) |
| 3111 | return ERR_PTR(-ENOMEM); |
| 3112 | |
| 3113 | /* ethtool_rx supports only one single action per rule. */ |
| 3114 | flow->rule = flow_rule_alloc(1); |
| 3115 | if (!flow->rule) { |
| 3116 | kfree(flow); |
| 3117 | return ERR_PTR(-ENOMEM); |
| 3118 | } |
| 3119 | |
| 3120 | match = (struct ethtool_rx_flow_match *)flow->priv; |
| 3121 | flow->rule->match.dissector = &match->dissector; |
| 3122 | flow->rule->match.mask = &match->mask; |
| 3123 | flow->rule->match.key = &match->key; |
| 3124 | |
| 3125 | match->mask.basic.n_proto = htons(0xffff); |
| 3126 | |
| 3127 | switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) { |
Maxime Chevallier | 5b9469a | 2019-06-27 10:52:26 +0200 | [diff] [blame] | 3128 | case ETHER_FLOW: { |
| 3129 | const struct ethhdr *ether_spec, *ether_m_spec; |
| 3130 | |
| 3131 | ether_spec = &fs->h_u.ether_spec; |
| 3132 | ether_m_spec = &fs->m_u.ether_spec; |
| 3133 | |
| 3134 | if (!is_zero_ether_addr(ether_m_spec->h_source)) { |
| 3135 | ether_addr_copy(match->key.eth_addrs.src, |
| 3136 | ether_spec->h_source); |
| 3137 | ether_addr_copy(match->mask.eth_addrs.src, |
| 3138 | ether_m_spec->h_source); |
| 3139 | } |
| 3140 | if (!is_zero_ether_addr(ether_m_spec->h_dest)) { |
| 3141 | ether_addr_copy(match->key.eth_addrs.dst, |
| 3142 | ether_spec->h_dest); |
| 3143 | ether_addr_copy(match->mask.eth_addrs.dst, |
| 3144 | ether_m_spec->h_dest); |
| 3145 | } |
| 3146 | if (ether_m_spec->h_proto) { |
| 3147 | match->key.basic.n_proto = ether_spec->h_proto; |
| 3148 | match->mask.basic.n_proto = ether_m_spec->h_proto; |
| 3149 | } |
| 3150 | } |
| 3151 | break; |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3152 | case TCP_V4_FLOW: |
| 3153 | case UDP_V4_FLOW: { |
| 3154 | const struct ethtool_tcpip4_spec *v4_spec, *v4_m_spec; |
| 3155 | |
| 3156 | match->key.basic.n_proto = htons(ETH_P_IP); |
| 3157 | |
| 3158 | v4_spec = &fs->h_u.tcp_ip4_spec; |
| 3159 | v4_m_spec = &fs->m_u.tcp_ip4_spec; |
| 3160 | |
| 3161 | if (v4_m_spec->ip4src) { |
| 3162 | match->key.ipv4.src = v4_spec->ip4src; |
| 3163 | match->mask.ipv4.src = v4_m_spec->ip4src; |
| 3164 | } |
| 3165 | if (v4_m_spec->ip4dst) { |
| 3166 | match->key.ipv4.dst = v4_spec->ip4dst; |
| 3167 | match->mask.ipv4.dst = v4_m_spec->ip4dst; |
| 3168 | } |
| 3169 | if (v4_m_spec->ip4src || |
| 3170 | v4_m_spec->ip4dst) { |
| 3171 | match->dissector.used_keys |= |
| 3172 | BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS); |
| 3173 | match->dissector.offset[FLOW_DISSECTOR_KEY_IPV4_ADDRS] = |
| 3174 | offsetof(struct ethtool_rx_flow_key, ipv4); |
| 3175 | } |
| 3176 | if (v4_m_spec->psrc) { |
| 3177 | match->key.tp.src = v4_spec->psrc; |
| 3178 | match->mask.tp.src = v4_m_spec->psrc; |
| 3179 | } |
| 3180 | if (v4_m_spec->pdst) { |
| 3181 | match->key.tp.dst = v4_spec->pdst; |
| 3182 | match->mask.tp.dst = v4_m_spec->pdst; |
| 3183 | } |
| 3184 | if (v4_m_spec->psrc || |
| 3185 | v4_m_spec->pdst) { |
| 3186 | match->dissector.used_keys |= |
| 3187 | BIT(FLOW_DISSECTOR_KEY_PORTS); |
| 3188 | match->dissector.offset[FLOW_DISSECTOR_KEY_PORTS] = |
| 3189 | offsetof(struct ethtool_rx_flow_key, tp); |
| 3190 | } |
| 3191 | if (v4_m_spec->tos) { |
| 3192 | match->key.ip.tos = v4_spec->tos; |
| 3193 | match->mask.ip.tos = v4_m_spec->tos; |
| 3194 | match->dissector.used_keys |= |
| 3195 | BIT(FLOW_DISSECTOR_KEY_IP); |
| 3196 | match->dissector.offset[FLOW_DISSECTOR_KEY_IP] = |
| 3197 | offsetof(struct ethtool_rx_flow_key, ip); |
| 3198 | } |
| 3199 | } |
| 3200 | break; |
| 3201 | case TCP_V6_FLOW: |
| 3202 | case UDP_V6_FLOW: { |
| 3203 | const struct ethtool_tcpip6_spec *v6_spec, *v6_m_spec; |
| 3204 | |
| 3205 | match->key.basic.n_proto = htons(ETH_P_IPV6); |
| 3206 | |
| 3207 | v6_spec = &fs->h_u.tcp_ip6_spec; |
| 3208 | v6_m_spec = &fs->m_u.tcp_ip6_spec; |
| 3209 | if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr))) { |
| 3210 | memcpy(&match->key.ipv6.src, v6_spec->ip6src, |
| 3211 | sizeof(match->key.ipv6.src)); |
| 3212 | memcpy(&match->mask.ipv6.src, v6_m_spec->ip6src, |
| 3213 | sizeof(match->mask.ipv6.src)); |
| 3214 | } |
| 3215 | if (memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) { |
| 3216 | memcpy(&match->key.ipv6.dst, v6_spec->ip6dst, |
| 3217 | sizeof(match->key.ipv6.dst)); |
| 3218 | memcpy(&match->mask.ipv6.dst, v6_m_spec->ip6dst, |
| 3219 | sizeof(match->mask.ipv6.dst)); |
| 3220 | } |
| 3221 | if (memcmp(v6_m_spec->ip6src, &zero_addr, sizeof(zero_addr)) || |
Gaurav Singh | 21a739c | 2020-06-21 11:30:17 -0400 | [diff] [blame] | 3222 | memcmp(v6_m_spec->ip6dst, &zero_addr, sizeof(zero_addr))) { |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3223 | match->dissector.used_keys |= |
| 3224 | BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS); |
| 3225 | match->dissector.offset[FLOW_DISSECTOR_KEY_IPV6_ADDRS] = |
| 3226 | offsetof(struct ethtool_rx_flow_key, ipv6); |
| 3227 | } |
| 3228 | if (v6_m_spec->psrc) { |
| 3229 | match->key.tp.src = v6_spec->psrc; |
| 3230 | match->mask.tp.src = v6_m_spec->psrc; |
| 3231 | } |
| 3232 | if (v6_m_spec->pdst) { |
| 3233 | match->key.tp.dst = v6_spec->pdst; |
| 3234 | match->mask.tp.dst = v6_m_spec->pdst; |
| 3235 | } |
| 3236 | if (v6_m_spec->psrc || |
| 3237 | v6_m_spec->pdst) { |
| 3238 | match->dissector.used_keys |= |
| 3239 | BIT(FLOW_DISSECTOR_KEY_PORTS); |
| 3240 | match->dissector.offset[FLOW_DISSECTOR_KEY_PORTS] = |
| 3241 | offsetof(struct ethtool_rx_flow_key, tp); |
| 3242 | } |
| 3243 | if (v6_m_spec->tclass) { |
| 3244 | match->key.ip.tos = v6_spec->tclass; |
| 3245 | match->mask.ip.tos = v6_m_spec->tclass; |
| 3246 | match->dissector.used_keys |= |
| 3247 | BIT(FLOW_DISSECTOR_KEY_IP); |
| 3248 | match->dissector.offset[FLOW_DISSECTOR_KEY_IP] = |
| 3249 | offsetof(struct ethtool_rx_flow_key, ip); |
| 3250 | } |
| 3251 | } |
| 3252 | break; |
| 3253 | default: |
| 3254 | ethtool_rx_flow_rule_destroy(flow); |
| 3255 | return ERR_PTR(-EINVAL); |
| 3256 | } |
| 3257 | |
| 3258 | switch (fs->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) { |
| 3259 | case TCP_V4_FLOW: |
| 3260 | case TCP_V6_FLOW: |
| 3261 | match->key.basic.ip_proto = IPPROTO_TCP; |
Vishal Kulkarni | d0a84e1 | 2020-08-19 00:25:03 +0530 | [diff] [blame] | 3262 | match->mask.basic.ip_proto = 0xff; |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3263 | break; |
| 3264 | case UDP_V4_FLOW: |
| 3265 | case UDP_V6_FLOW: |
| 3266 | match->key.basic.ip_proto = IPPROTO_UDP; |
Vishal Kulkarni | d0a84e1 | 2020-08-19 00:25:03 +0530 | [diff] [blame] | 3267 | match->mask.basic.ip_proto = 0xff; |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3268 | break; |
| 3269 | } |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3270 | |
| 3271 | match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_BASIC); |
| 3272 | match->dissector.offset[FLOW_DISSECTOR_KEY_BASIC] = |
| 3273 | offsetof(struct ethtool_rx_flow_key, basic); |
| 3274 | |
| 3275 | if (fs->flow_type & FLOW_EXT) { |
| 3276 | const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext; |
| 3277 | const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext; |
| 3278 | |
Maxime Chevallier | b73484b | 2019-05-30 16:08:40 +0200 | [diff] [blame] | 3279 | if (ext_m_spec->vlan_etype) { |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3280 | match->key.vlan.vlan_tpid = ext_h_spec->vlan_etype; |
| 3281 | match->mask.vlan.vlan_tpid = ext_m_spec->vlan_etype; |
Maxime Chevallier | b73484b | 2019-05-30 16:08:40 +0200 | [diff] [blame] | 3282 | } |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3283 | |
Maxime Chevallier | b73484b | 2019-05-30 16:08:40 +0200 | [diff] [blame] | 3284 | if (ext_m_spec->vlan_tci) { |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3285 | match->key.vlan.vlan_id = |
| 3286 | ntohs(ext_h_spec->vlan_tci) & 0x0fff; |
| 3287 | match->mask.vlan.vlan_id = |
| 3288 | ntohs(ext_m_spec->vlan_tci) & 0x0fff; |
| 3289 | |
Maxime Chevallier | f0d2ca1 | 2019-06-12 17:18:38 +0200 | [diff] [blame] | 3290 | match->key.vlan.vlan_dei = |
| 3291 | !!(ext_h_spec->vlan_tci & htons(0x1000)); |
| 3292 | match->mask.vlan.vlan_dei = |
| 3293 | !!(ext_m_spec->vlan_tci & htons(0x1000)); |
| 3294 | |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3295 | match->key.vlan.vlan_priority = |
| 3296 | (ntohs(ext_h_spec->vlan_tci) & 0xe000) >> 13; |
| 3297 | match->mask.vlan.vlan_priority = |
| 3298 | (ntohs(ext_m_spec->vlan_tci) & 0xe000) >> 13; |
Maxime Chevallier | b73484b | 2019-05-30 16:08:40 +0200 | [diff] [blame] | 3299 | } |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3300 | |
Maxime Chevallier | b73484b | 2019-05-30 16:08:40 +0200 | [diff] [blame] | 3301 | if (ext_m_spec->vlan_etype || |
| 3302 | ext_m_spec->vlan_tci) { |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3303 | match->dissector.used_keys |= |
| 3304 | BIT(FLOW_DISSECTOR_KEY_VLAN); |
| 3305 | match->dissector.offset[FLOW_DISSECTOR_KEY_VLAN] = |
| 3306 | offsetof(struct ethtool_rx_flow_key, vlan); |
| 3307 | } |
| 3308 | } |
| 3309 | if (fs->flow_type & FLOW_MAC_EXT) { |
| 3310 | const struct ethtool_flow_ext *ext_h_spec = &fs->h_ext; |
| 3311 | const struct ethtool_flow_ext *ext_m_spec = &fs->m_ext; |
| 3312 | |
Nathan Chancellor | 8b34ec6 | 2019-02-07 21:46:53 -0700 | [diff] [blame] | 3313 | memcpy(match->key.eth_addrs.dst, ext_h_spec->h_dest, |
| 3314 | ETH_ALEN); |
| 3315 | memcpy(match->mask.eth_addrs.dst, ext_m_spec->h_dest, |
| 3316 | ETH_ALEN); |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3317 | |
Nathan Chancellor | 8b34ec6 | 2019-02-07 21:46:53 -0700 | [diff] [blame] | 3318 | match->dissector.used_keys |= |
| 3319 | BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS); |
| 3320 | match->dissector.offset[FLOW_DISSECTOR_KEY_ETH_ADDRS] = |
| 3321 | offsetof(struct ethtool_rx_flow_key, eth_addrs); |
Pablo Neira Ayuso | eca4205 | 2019-02-02 12:50:51 +0100 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | act = &flow->rule->action.entries[0]; |
| 3325 | switch (fs->ring_cookie) { |
| 3326 | case RX_CLS_FLOW_DISC: |
| 3327 | act->id = FLOW_ACTION_DROP; |
| 3328 | break; |
| 3329 | case RX_CLS_FLOW_WAKE: |
| 3330 | act->id = FLOW_ACTION_WAKE; |
| 3331 | break; |
| 3332 | default: |
| 3333 | act->id = FLOW_ACTION_QUEUE; |
| 3334 | if (fs->flow_type & FLOW_RSS) |
| 3335 | act->queue.ctx = input->rss_ctx; |
| 3336 | |
| 3337 | act->queue.vf = ethtool_get_flow_spec_ring_vf(fs->ring_cookie); |
| 3338 | act->queue.index = ethtool_get_flow_spec_ring(fs->ring_cookie); |
| 3339 | break; |
| 3340 | } |
| 3341 | |
| 3342 | return flow; |
| 3343 | } |
| 3344 | EXPORT_SYMBOL(ethtool_rx_flow_rule_create); |
| 3345 | |
| 3346 | void ethtool_rx_flow_rule_destroy(struct ethtool_rx_flow_rule *flow) |
| 3347 | { |
| 3348 | kfree(flow->rule); |
| 3349 | kfree(flow); |
| 3350 | } |
| 3351 | EXPORT_SYMBOL(ethtool_rx_flow_rule_destroy); |