Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/core/ethtool.c - Ethtool ioctl handler |
| 3 | * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx> |
| 4 | * |
| 5 | * 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] | 6 | * the information ethtool needs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/types.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 16 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | #include <linux/ethtool.h> |
| 19 | #include <linux/netdevice.h> |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 20 | #include <linux/net_tstamp.h> |
| 21 | #include <linux/phy.h> |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 22 | #include <linux/bitops.h> |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
David S. Miller | 73da16c | 2010-09-21 16:12:11 -0700 | [diff] [blame] | 24 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 26 | #include <linux/rtnetlink.h> |
| 27 | #include <linux/sched.h> |
Eric Dumazet | 960fb62 | 2014-11-16 06:23:05 -0800 | [diff] [blame] | 28 | #include <linux/net.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 30 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * Some useful ethtool_ops methods that're device independent. |
| 32 | * If we find that all drivers want to do the same thing here, |
| 33 | * we can turn these into dev_() function calls. |
| 34 | */ |
| 35 | |
| 36 | u32 ethtool_op_get_link(struct net_device *dev) |
| 37 | { |
| 38 | return netif_carrier_ok(dev) ? 1 : 0; |
| 39 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 40 | EXPORT_SYMBOL(ethtool_op_get_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Richard Cochran | 02eacbd | 2012-04-03 22:59:22 +0000 | [diff] [blame] | 42 | int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
| 43 | { |
| 44 | info->so_timestamping = |
| 45 | SOF_TIMESTAMPING_TX_SOFTWARE | |
| 46 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 47 | SOF_TIMESTAMPING_SOFTWARE; |
| 48 | info->phc_index = -1; |
| 49 | return 0; |
| 50 | } |
| 51 | EXPORT_SYMBOL(ethtool_op_get_ts_info); |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* Handlers for each ethtool command */ |
| 54 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 55 | #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 56 | |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 57 | static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { |
| 58 | [NETIF_F_SG_BIT] = "tx-scatter-gather", |
| 59 | [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 60 | [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", |
| 61 | [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", |
| 62 | [NETIF_F_HIGHDMA_BIT] = "highdma", |
| 63 | [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", |
Fernando Luis Vazquez Cao | 788dfca | 2013-06-17 11:28:03 +0900 | [diff] [blame] | 64 | [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 65 | |
Fernando Luis Vazquez Cao | 788dfca | 2013-06-17 11:28:03 +0900 | [diff] [blame] | 66 | [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse", |
| 67 | [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter", |
David S. Miller | 2d6577f | 2013-04-19 16:08:23 -0400 | [diff] [blame] | 68 | [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert", |
| 69 | [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse", |
| 70 | [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 71 | [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", |
| 72 | [NETIF_F_GSO_BIT] = "tx-generic-segmentation", |
| 73 | [NETIF_F_LLTX_BIT] = "tx-lockless", |
| 74 | [NETIF_F_NETNS_LOCAL_BIT] = "netns-local", |
| 75 | [NETIF_F_GRO_BIT] = "rx-gro", |
| 76 | [NETIF_F_LRO_BIT] = "rx-lro", |
| 77 | |
| 78 | [NETIF_F_TSO_BIT] = "tx-tcp-segmentation", |
| 79 | [NETIF_F_UFO_BIT] = "tx-udp-fragmentation", |
| 80 | [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", |
| 81 | [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", |
| 82 | [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", |
| 83 | [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", |
Pravin B Shelar | 68c3316 | 2013-02-14 14:02:41 +0000 | [diff] [blame] | 84 | [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation", |
Eric Dumazet | cb32f51 | 2013-10-19 11:42:57 -0700 | [diff] [blame] | 85 | [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation", |
Eric Dumazet | 61c1db7 | 2013-10-20 20:47:30 -0700 | [diff] [blame] | 86 | [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation", |
Pravin B Shelar | 7313626 | 2013-03-07 13:21:51 +0000 | [diff] [blame] | 87 | [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 88 | |
| 89 | [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", |
| 90 | [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp", |
| 91 | [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu", |
| 92 | [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", |
| 93 | [NETIF_F_RXHASH_BIT] = "rx-hashing", |
| 94 | [NETIF_F_RXCSUM_BIT] = "rx-checksum", |
| 95 | [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", |
| 96 | [NETIF_F_LOOPBACK_BIT] = "loopback", |
Ben Greear | 36eabda3 | 2012-02-11 15:39:14 +0000 | [diff] [blame] | 97 | [NETIF_F_RXFCS_BIT] = "rx-fcs", |
Ben Greear | 5e0c03c | 2012-02-11 15:39:45 +0000 | [diff] [blame] | 98 | [NETIF_F_RXALL_BIT] = "rx-all", |
John Fastabend | a6cc0cf | 2013-11-06 09:54:46 -0800 | [diff] [blame] | 99 | [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload", |
Jiri Pirko | d029021 | 2014-04-02 23:09:31 +0200 | [diff] [blame] | 100 | [NETIF_F_BUSY_POLL_BIT] = "busy-poll", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 103 | static const char |
| 104 | rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = { |
| 105 | [ETH_RSS_HASH_TOP_BIT] = "toeplitz", |
| 106 | [ETH_RSS_HASH_XOR_BIT] = "xor", |
| 107 | }; |
| 108 | |
Hadar Hen Zion | a4244b0 | 2015-06-11 10:28:16 +0300 | [diff] [blame] | 109 | static const char |
| 110 | tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = { |
| 111 | [ETHTOOL_ID_UNSPEC] = "Unspec", |
| 112 | [ETHTOOL_RX_COPYBREAK] = "rx-copybreak", |
| 113 | [ETHTOOL_TX_COPYBREAK] = "tx-copybreak", |
| 114 | }; |
| 115 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 116 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
| 117 | { |
| 118 | struct ethtool_gfeatures cmd = { |
| 119 | .cmd = ETHTOOL_GFEATURES, |
| 120 | .size = ETHTOOL_DEV_FEATURE_WORDS, |
| 121 | }; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 122 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 123 | u32 __user *sizeaddr; |
| 124 | u32 copy_size; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 125 | int i; |
| 126 | |
| 127 | /* in case feature bits run out again */ |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 128 | 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] | 129 | |
| 130 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 131 | features[i].available = (u32)(dev->hw_features >> (32 * i)); |
| 132 | features[i].requested = (u32)(dev->wanted_features >> (32 * i)); |
| 133 | features[i].active = (u32)(dev->features >> (32 * i)); |
| 134 | features[i].never_changed = |
| 135 | (u32)(NETIF_F_NEVER_CHANGE >> (32 * i)); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 136 | } |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 137 | |
| 138 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); |
| 139 | if (get_user(copy_size, sizeaddr)) |
| 140 | return -EFAULT; |
| 141 | |
| 142 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) |
| 143 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; |
| 144 | |
| 145 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 146 | return -EFAULT; |
| 147 | useraddr += sizeof(cmd); |
| 148 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) |
| 149 | return -EFAULT; |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) |
| 155 | { |
| 156 | struct ethtool_sfeatures cmd; |
| 157 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 158 | netdev_features_t wanted = 0, valid = 0; |
| 159 | int i, ret = 0; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 160 | |
| 161 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 162 | return -EFAULT; |
| 163 | useraddr += sizeof(cmd); |
| 164 | |
| 165 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) |
| 166 | return -EINVAL; |
| 167 | |
| 168 | if (copy_from_user(features, useraddr, sizeof(features))) |
| 169 | return -EFAULT; |
| 170 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 171 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 172 | valid |= (netdev_features_t)features[i].valid << (32 * i); |
| 173 | wanted |= (netdev_features_t)features[i].requested << (32 * i); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | if (valid & ~NETIF_F_ETHTOOL_BITS) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 177 | return -EINVAL; |
| 178 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 179 | if (valid & ~dev->hw_features) { |
| 180 | valid &= dev->hw_features; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 181 | ret |= ETHTOOL_F_UNSUPPORTED; |
| 182 | } |
| 183 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 184 | dev->wanted_features &= ~valid; |
| 185 | dev->wanted_features |= wanted & valid; |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 186 | __netdev_update_features(dev); |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 187 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 188 | if ((dev->wanted_features ^ dev->features) & valid) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 189 | ret |= ETHTOOL_F_WISH; |
| 190 | |
| 191 | return ret; |
| 192 | } |
| 193 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 194 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
| 195 | { |
| 196 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 197 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 198 | if (sset == ETH_SS_FEATURES) |
| 199 | return ARRAY_SIZE(netdev_features_strings); |
| 200 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 201 | if (sset == ETH_SS_RSS_HASH_FUNCS) |
| 202 | return ARRAY_SIZE(rss_hash_func_strings); |
| 203 | |
Hadar Hen Zion | a4244b0 | 2015-06-11 10:28:16 +0300 | [diff] [blame] | 204 | if (sset == ETH_SS_TUNABLES) |
| 205 | return ARRAY_SIZE(tunable_strings); |
| 206 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 207 | if (ops->get_sset_count && ops->get_strings) |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 208 | return ops->get_sset_count(dev, sset); |
| 209 | else |
| 210 | return -EOPNOTSUPP; |
| 211 | } |
| 212 | |
| 213 | static void __ethtool_get_strings(struct net_device *dev, |
| 214 | u32 stringset, u8 *data) |
| 215 | { |
| 216 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 217 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 218 | if (stringset == ETH_SS_FEATURES) |
| 219 | memcpy(data, netdev_features_strings, |
| 220 | sizeof(netdev_features_strings)); |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 221 | else if (stringset == ETH_SS_RSS_HASH_FUNCS) |
| 222 | memcpy(data, rss_hash_func_strings, |
| 223 | sizeof(rss_hash_func_strings)); |
Hadar Hen Zion | a4244b0 | 2015-06-11 10:28:16 +0300 | [diff] [blame] | 224 | else if (stringset == ETH_SS_TUNABLES) |
| 225 | memcpy(data, tunable_strings, sizeof(tunable_strings)); |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 226 | else |
| 227 | /* ops->get_strings is valid because checked earlier */ |
| 228 | ops->get_strings(dev, stringset, data); |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 231 | static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 232 | { |
| 233 | /* feature masks of legacy discrete ethtool ops */ |
| 234 | |
| 235 | switch (eth_cmd) { |
| 236 | case ETHTOOL_GTXCSUM: |
| 237 | case ETHTOOL_STXCSUM: |
| 238 | return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM; |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 239 | case ETHTOOL_GRXCSUM: |
| 240 | case ETHTOOL_SRXCSUM: |
| 241 | return NETIF_F_RXCSUM; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 242 | case ETHTOOL_GSG: |
| 243 | case ETHTOOL_SSG: |
| 244 | return NETIF_F_SG; |
| 245 | case ETHTOOL_GTSO: |
| 246 | case ETHTOOL_STSO: |
| 247 | return NETIF_F_ALL_TSO; |
| 248 | case ETHTOOL_GUFO: |
| 249 | case ETHTOOL_SUFO: |
| 250 | return NETIF_F_UFO; |
| 251 | case ETHTOOL_GGSO: |
| 252 | case ETHTOOL_SGSO: |
| 253 | return NETIF_F_GSO; |
| 254 | case ETHTOOL_GGRO: |
| 255 | case ETHTOOL_SGRO: |
| 256 | return NETIF_F_GRO; |
| 257 | default: |
| 258 | BUG(); |
| 259 | } |
| 260 | } |
| 261 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 262 | static int ethtool_get_one_feature(struct net_device *dev, |
| 263 | char __user *useraddr, u32 ethcmd) |
| 264 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 265 | netdev_features_t mask = ethtool_get_feature_mask(ethcmd); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 266 | struct ethtool_value edata = { |
| 267 | .cmd = ethcmd, |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 268 | .data = !!(dev->features & mask), |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 269 | }; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 270 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 271 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 272 | return -EFAULT; |
| 273 | return 0; |
| 274 | } |
| 275 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 276 | static int ethtool_set_one_feature(struct net_device *dev, |
| 277 | void __user *useraddr, u32 ethcmd) |
| 278 | { |
| 279 | struct ethtool_value edata; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 280 | netdev_features_t mask; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 281 | |
| 282 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 283 | return -EFAULT; |
| 284 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 285 | mask = ethtool_get_feature_mask(ethcmd); |
| 286 | mask &= dev->hw_features; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 287 | if (!mask) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 288 | return -EOPNOTSUPP; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 289 | |
| 290 | if (edata.data) |
| 291 | dev->wanted_features |= mask; |
| 292 | else |
| 293 | dev->wanted_features &= ~mask; |
| 294 | |
| 295 | __netdev_update_features(dev); |
| 296 | |
| 297 | return 0; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 300 | #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \ |
| 301 | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH) |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 302 | #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \ |
| 303 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \ |
| 304 | NETIF_F_RXHASH) |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 305 | |
| 306 | static u32 __ethtool_get_flags(struct net_device *dev) |
| 307 | { |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 308 | u32 flags = 0; |
| 309 | |
Dragos Foianu | 8a73125 | 2013-07-13 14:43:00 +0100 | [diff] [blame] | 310 | if (dev->features & NETIF_F_LRO) |
| 311 | flags |= ETH_FLAG_LRO; |
| 312 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 313 | flags |= ETH_FLAG_RXVLAN; |
| 314 | if (dev->features & NETIF_F_HW_VLAN_CTAG_TX) |
| 315 | flags |= ETH_FLAG_TXVLAN; |
| 316 | if (dev->features & NETIF_F_NTUPLE) |
| 317 | flags |= ETH_FLAG_NTUPLE; |
| 318 | if (dev->features & NETIF_F_RXHASH) |
| 319 | flags |= ETH_FLAG_RXHASH; |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 320 | |
| 321 | return flags; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 325 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 326 | netdev_features_t features = 0, changed; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 327 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 328 | if (data & ~ETH_ALL_FLAGS) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 329 | return -EINVAL; |
| 330 | |
Dragos Foianu | 8a73125 | 2013-07-13 14:43:00 +0100 | [diff] [blame] | 331 | if (data & ETH_FLAG_LRO) |
| 332 | features |= NETIF_F_LRO; |
| 333 | if (data & ETH_FLAG_RXVLAN) |
| 334 | features |= NETIF_F_HW_VLAN_CTAG_RX; |
| 335 | if (data & ETH_FLAG_TXVLAN) |
| 336 | features |= NETIF_F_HW_VLAN_CTAG_TX; |
| 337 | if (data & ETH_FLAG_NTUPLE) |
| 338 | features |= NETIF_F_NTUPLE; |
| 339 | if (data & ETH_FLAG_RXHASH) |
| 340 | features |= NETIF_F_RXHASH; |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 341 | |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 342 | /* allow changing only bits set in hw_features */ |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 343 | changed = (features ^ dev->features) & ETH_ALL_FEATURES; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 344 | if (changed & ~dev->hw_features) |
| 345 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; |
| 346 | |
| 347 | dev->wanted_features = |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 348 | (dev->wanted_features & ~changed) | (features & changed); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 349 | |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 350 | __netdev_update_features(dev); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 355 | int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 357 | ASSERT_RTNL(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 359 | if (!dev->ethtool_ops->get_settings) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return -EOPNOTSUPP; |
| 361 | |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 362 | memset(cmd, 0, sizeof(struct ethtool_cmd)); |
| 363 | cmd->cmd = ETHTOOL_GSET; |
| 364 | return dev->ethtool_ops->get_settings(dev, cmd); |
| 365 | } |
| 366 | EXPORT_SYMBOL(__ethtool_get_settings); |
| 367 | |
| 368 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
| 369 | { |
| 370 | int err; |
| 371 | struct ethtool_cmd cmd; |
| 372 | |
David S. Miller | 18ec898 | 2015-06-01 14:43:50 -0700 | [diff] [blame] | 373 | err = __ethtool_get_settings(dev, &cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | if (err < 0) |
| 375 | return err; |
| 376 | |
| 377 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 378 | return -EFAULT; |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
| 383 | { |
| 384 | struct ethtool_cmd cmd; |
| 385 | |
| 386 | if (!dev->ethtool_ops->set_settings) |
| 387 | return -EOPNOTSUPP; |
| 388 | |
| 389 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 390 | return -EFAULT; |
| 391 | |
| 392 | return dev->ethtool_ops->set_settings(dev, &cmd); |
| 393 | } |
| 394 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 395 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
| 396 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
| 398 | struct ethtool_drvinfo info; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 399 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | memset(&info, 0, sizeof(info)); |
| 402 | info.cmd = ETHTOOL_GDRVINFO; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 403 | if (ops->get_drvinfo) { |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 404 | ops->get_drvinfo(dev, &info); |
| 405 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
| 406 | strlcpy(info.bus_info, dev_name(dev->dev.parent), |
| 407 | sizeof(info.bus_info)); |
| 408 | strlcpy(info.driver, dev->dev.parent->driver->name, |
| 409 | sizeof(info.driver)); |
| 410 | } else { |
| 411 | return -EOPNOTSUPP; |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 414 | /* |
| 415 | * this method of obtaining string set info is deprecated; |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 416 | * Use ETHTOOL_GSSET_INFO instead. |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 417 | */ |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 418 | if (ops->get_sset_count) { |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 419 | int rc; |
| 420 | |
| 421 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
| 422 | if (rc >= 0) |
| 423 | info.testinfo_len = rc; |
| 424 | rc = ops->get_sset_count(dev, ETH_SS_STATS); |
| 425 | if (rc >= 0) |
| 426 | info.n_stats = rc; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 427 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
| 428 | if (rc >= 0) |
| 429 | info.n_priv_flags = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 430 | } |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 431 | if (ops->get_regs_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | info.regdump_len = ops->get_regs_len(dev); |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 433 | if (ops->get_eeprom_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | info.eedump_len = ops->get_eeprom_len(dev); |
| 435 | |
| 436 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 437 | return -EFAULT; |
| 438 | return 0; |
| 439 | } |
| 440 | |
Eric Dumazet | f5c445e | 2010-03-08 12:17:04 -0800 | [diff] [blame] | 441 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 442 | void __user *useraddr) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 443 | { |
| 444 | struct ethtool_sset_info info; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 445 | u64 sset_mask; |
| 446 | int i, idx = 0, n_bits = 0, ret, rc; |
| 447 | u32 *info_buf = NULL; |
| 448 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 449 | if (copy_from_user(&info, useraddr, sizeof(info))) |
| 450 | return -EFAULT; |
| 451 | |
| 452 | /* store copy of mask, because we zero struct later on */ |
| 453 | sset_mask = info.sset_mask; |
| 454 | if (!sset_mask) |
| 455 | return 0; |
| 456 | |
| 457 | /* calculate size of return buffer */ |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 458 | n_bits = hweight64(sset_mask); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 459 | |
| 460 | memset(&info, 0, sizeof(info)); |
| 461 | info.cmd = ETHTOOL_GSSET_INFO; |
| 462 | |
| 463 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); |
| 464 | if (!info_buf) |
| 465 | return -ENOMEM; |
| 466 | |
| 467 | /* |
| 468 | * fill return buffer based on input bitmask and successful |
| 469 | * get_sset_count return |
| 470 | */ |
| 471 | for (i = 0; i < 64; i++) { |
| 472 | if (!(sset_mask & (1ULL << i))) |
| 473 | continue; |
| 474 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 475 | rc = __ethtool_get_sset_count(dev, i); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 476 | if (rc >= 0) { |
| 477 | info.sset_mask |= (1ULL << i); |
| 478 | info_buf[idx++] = rc; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | ret = -EFAULT; |
| 483 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 484 | goto out; |
| 485 | |
| 486 | useraddr += offsetof(struct ethtool_sset_info, data); |
| 487 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) |
| 488 | goto out; |
| 489 | |
| 490 | ret = 0; |
| 491 | |
| 492 | out: |
| 493 | kfree(info_buf); |
| 494 | return ret; |
| 495 | } |
| 496 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 497 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 498 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 499 | { |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 500 | struct ethtool_rxnfc info; |
| 501 | size_t info_size = sizeof(info); |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 502 | int rc; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 503 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 504 | if (!dev->ethtool_ops->set_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 505 | return -EOPNOTSUPP; |
| 506 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 507 | /* struct ethtool_rxnfc was originally defined for |
| 508 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 509 | * members. User-space might still be using that |
| 510 | * definition. */ |
| 511 | if (cmd == ETHTOOL_SRXFH) |
| 512 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 513 | sizeof(info.data)); |
| 514 | |
| 515 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 516 | return -EFAULT; |
| 517 | |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 518 | rc = dev->ethtool_ops->set_rxnfc(dev, &info); |
| 519 | if (rc) |
| 520 | return rc; |
| 521 | |
| 522 | if (cmd == ETHTOOL_SRXCLSRLINS && |
| 523 | copy_to_user(useraddr, &info, info_size)) |
| 524 | return -EFAULT; |
| 525 | |
| 526 | return 0; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 527 | } |
| 528 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 529 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 530 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 531 | { |
| 532 | struct ethtool_rxnfc info; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 533 | size_t info_size = sizeof(info); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 534 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 535 | int ret; |
| 536 | void *rule_buf = NULL; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 537 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 538 | if (!ops->get_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 539 | return -EOPNOTSUPP; |
| 540 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 541 | /* struct ethtool_rxnfc was originally defined for |
| 542 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 543 | * members. User-space might still be using that |
| 544 | * definition. */ |
| 545 | if (cmd == ETHTOOL_GRXFH) |
| 546 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 547 | sizeof(info.data)); |
| 548 | |
| 549 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 550 | return -EFAULT; |
| 551 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 552 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
| 553 | if (info.rule_cnt > 0) { |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 554 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
Kees Cook | ae6df5f | 2010-10-07 10:03:48 +0000 | [diff] [blame] | 555 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 556 | GFP_USER); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 557 | if (!rule_buf) |
| 558 | return -ENOMEM; |
| 559 | } |
| 560 | } |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 561 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 562 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
| 563 | if (ret < 0) |
| 564 | goto err_out; |
| 565 | |
| 566 | ret = -EFAULT; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 567 | if (copy_to_user(useraddr, &info, info_size)) |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 568 | goto err_out; |
| 569 | |
| 570 | if (rule_buf) { |
| 571 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); |
| 572 | if (copy_to_user(useraddr, rule_buf, |
| 573 | info.rule_cnt * sizeof(u32))) |
| 574 | goto err_out; |
| 575 | } |
| 576 | ret = 0; |
| 577 | |
| 578 | err_out: |
Wei Yongjun | c9cacec | 2009-03-31 15:06:26 -0700 | [diff] [blame] | 579 | kfree(rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 580 | |
| 581 | return ret; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 584 | static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr, |
| 585 | struct ethtool_rxnfc *rx_rings, |
| 586 | u32 size) |
| 587 | { |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 588 | int i; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 589 | |
| 590 | if (copy_from_user(indir, useraddr, size * sizeof(indir[0]))) |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 591 | return -EFAULT; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 592 | |
| 593 | /* Validate ring indices */ |
Ben Hutchings | fb95cd8 | 2014-05-15 00:46:45 +0100 | [diff] [blame] | 594 | for (i = 0; i < size; i++) |
| 595 | if (indir[i] >= rx_rings->data) |
| 596 | return -EINVAL; |
| 597 | |
| 598 | return 0; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 599 | } |
| 600 | |
Eric Dumazet | 960fb62 | 2014-11-16 06:23:05 -0800 | [diff] [blame] | 601 | u8 netdev_rss_key[NETDEV_RSS_KEY_LEN]; |
| 602 | |
| 603 | void netdev_rss_key_fill(void *buffer, size_t len) |
| 604 | { |
| 605 | BUG_ON(len > sizeof(netdev_rss_key)); |
| 606 | net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key)); |
| 607 | memcpy(buffer, netdev_rss_key, len); |
| 608 | } |
| 609 | EXPORT_SYMBOL(netdev_rss_key_fill); |
| 610 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 611 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
| 612 | void __user *useraddr) |
| 613 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 614 | u32 user_size, dev_size; |
| 615 | u32 *indir; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 616 | int ret; |
| 617 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 618 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 619 | !dev->ethtool_ops->get_rxfh) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 620 | return -EOPNOTSUPP; |
| 621 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); |
| 622 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 623 | return -EOPNOTSUPP; |
| 624 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 625 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 626 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 627 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 628 | return -EFAULT; |
| 629 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 630 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 631 | &dev_size, sizeof(dev_size))) |
| 632 | return -EFAULT; |
| 633 | |
| 634 | /* If the user buffer size is 0, this is just a query for the |
| 635 | * device table size. Otherwise, if it's smaller than the |
| 636 | * device table size it's an error. |
| 637 | */ |
| 638 | if (user_size < dev_size) |
| 639 | return user_size == 0 ? 0 : -EINVAL; |
| 640 | |
| 641 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 642 | if (!indir) |
| 643 | return -ENOMEM; |
| 644 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 645 | ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 646 | if (ret) |
| 647 | goto out; |
| 648 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 649 | if (copy_to_user(useraddr + |
| 650 | offsetof(struct ethtool_rxfh_indir, ring_index[0]), |
| 651 | indir, dev_size * sizeof(indir[0]))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 652 | ret = -EFAULT; |
| 653 | |
| 654 | out: |
| 655 | kfree(indir); |
| 656 | return ret; |
| 657 | } |
| 658 | |
| 659 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, |
| 660 | void __user *useraddr) |
| 661 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 662 | struct ethtool_rxnfc rx_rings; |
| 663 | u32 user_size, dev_size, i; |
| 664 | u32 *indir; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 665 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 666 | int ret; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 667 | u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 668 | |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 669 | if (!ops->get_rxfh_indir_size || !ops->set_rxfh || |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 670 | !ops->get_rxnfc) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 671 | return -EOPNOTSUPP; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 672 | |
| 673 | dev_size = ops->get_rxfh_indir_size(dev); |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 674 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 675 | return -EOPNOTSUPP; |
| 676 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 677 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 678 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 679 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 680 | return -EFAULT; |
| 681 | |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 682 | if (user_size != 0 && user_size != dev_size) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | |
| 685 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 686 | if (!indir) |
| 687 | return -ENOMEM; |
| 688 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 689 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 690 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 691 | if (ret) |
| 692 | goto out; |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 693 | |
| 694 | if (user_size == 0) { |
| 695 | for (i = 0; i < dev_size; i++) |
| 696 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); |
| 697 | } else { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 698 | ret = ethtool_copy_validate_indir(indir, |
| 699 | useraddr + ringidx_offset, |
| 700 | &rx_rings, |
| 701 | dev_size); |
| 702 | if (ret) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 703 | goto out; |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 706 | ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 707 | |
| 708 | out: |
| 709 | kfree(indir); |
| 710 | return ret; |
| 711 | } |
| 712 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 713 | static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev, |
| 714 | void __user *useraddr) |
| 715 | { |
| 716 | int ret; |
| 717 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 718 | u32 user_indir_size, user_key_size; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 719 | u32 dev_indir_size = 0, dev_key_size = 0; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 720 | struct ethtool_rxfh rxfh; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 721 | u32 total_size; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 722 | u32 indir_bytes; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 723 | u32 *indir = NULL; |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 724 | u8 dev_hfunc = 0; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 725 | u8 *hkey = NULL; |
| 726 | u8 *rss_config; |
| 727 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 728 | if (!ops->get_rxfh) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 729 | return -EOPNOTSUPP; |
| 730 | |
| 731 | if (ops->get_rxfh_indir_size) |
| 732 | dev_indir_size = ops->get_rxfh_indir_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 733 | if (ops->get_rxfh_key_size) |
| 734 | dev_key_size = ops->get_rxfh_key_size(dev); |
| 735 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 736 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 737 | return -EFAULT; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 738 | user_indir_size = rxfh.indir_size; |
| 739 | user_key_size = rxfh.key_size; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 740 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 741 | /* Check that reserved fields are 0 for now */ |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 742 | if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] || |
| 743 | rxfh.rsvd8[2] || rxfh.rsvd32) |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 744 | return -EINVAL; |
| 745 | |
| 746 | rxfh.indir_size = dev_indir_size; |
| 747 | rxfh.key_size = dev_key_size; |
| 748 | if (copy_to_user(useraddr, &rxfh, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 749 | return -EFAULT; |
| 750 | |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 751 | if ((user_indir_size && (user_indir_size != dev_indir_size)) || |
| 752 | (user_key_size && (user_key_size != dev_key_size))) |
| 753 | return -EINVAL; |
| 754 | |
| 755 | indir_bytes = user_indir_size * sizeof(indir[0]); |
| 756 | total_size = indir_bytes + user_key_size; |
| 757 | rss_config = kzalloc(total_size, GFP_USER); |
| 758 | if (!rss_config) |
| 759 | return -ENOMEM; |
| 760 | |
| 761 | if (user_indir_size) |
| 762 | indir = (u32 *)rss_config; |
| 763 | |
| 764 | if (user_key_size) |
| 765 | hkey = rss_config + indir_bytes; |
| 766 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 767 | ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc); |
| 768 | if (ret) |
| 769 | goto out; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 770 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 771 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc), |
| 772 | &dev_hfunc, sizeof(rxfh.hfunc))) { |
| 773 | ret = -EFAULT; |
| 774 | } else if (copy_to_user(useraddr + |
| 775 | offsetof(struct ethtool_rxfh, rss_config[0]), |
| 776 | rss_config, total_size)) { |
| 777 | ret = -EFAULT; |
| 778 | } |
| 779 | out: |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 780 | kfree(rss_config); |
| 781 | |
| 782 | return ret; |
| 783 | } |
| 784 | |
| 785 | static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, |
| 786 | void __user *useraddr) |
| 787 | { |
| 788 | int ret; |
| 789 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 790 | struct ethtool_rxnfc rx_rings; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 791 | struct ethtool_rxfh rxfh; |
| 792 | u32 dev_indir_size = 0, dev_key_size = 0, i; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 793 | u32 *indir = NULL, indir_bytes = 0; |
| 794 | u8 *hkey = NULL; |
| 795 | u8 *rss_config; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 796 | u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]); |
| 797 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 798 | if (!ops->get_rxnfc || !ops->set_rxfh) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 799 | return -EOPNOTSUPP; |
| 800 | |
| 801 | if (ops->get_rxfh_indir_size) |
| 802 | dev_indir_size = ops->get_rxfh_indir_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 803 | if (ops->get_rxfh_key_size) |
Dan Carpenter | d340c86 | 2015-02-20 13:54:05 +0300 | [diff] [blame] | 804 | dev_key_size = ops->get_rxfh_key_size(dev); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 805 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 806 | if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 807 | return -EFAULT; |
| 808 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 809 | /* Check that reserved fields are 0 for now */ |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 810 | if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] || |
| 811 | rxfh.rsvd8[2] || rxfh.rsvd32) |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 812 | return -EINVAL; |
| 813 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 814 | /* If either indir, hash key or function is valid, proceed further. |
| 815 | * Must request at least one change: indir size, hash key or function. |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 816 | */ |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 817 | if ((rxfh.indir_size && |
| 818 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE && |
| 819 | rxfh.indir_size != dev_indir_size) || |
| 820 | (rxfh.key_size && (rxfh.key_size != dev_key_size)) || |
| 821 | (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE && |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 822 | rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE)) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 823 | return -EINVAL; |
| 824 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 825 | if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 826 | indir_bytes = dev_indir_size * sizeof(indir[0]); |
| 827 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 828 | rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 829 | if (!rss_config) |
| 830 | return -ENOMEM; |
| 831 | |
| 832 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
| 833 | ret = ops->get_rxnfc(dev, &rx_rings, NULL); |
| 834 | if (ret) |
| 835 | goto out; |
| 836 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 837 | /* rxfh.indir_size == 0 means reset the indir table to default. |
| 838 | * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged. |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 839 | */ |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 840 | if (rxfh.indir_size && |
| 841 | rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 842 | indir = (u32 *)rss_config; |
| 843 | ret = ethtool_copy_validate_indir(indir, |
| 844 | useraddr + rss_cfg_offset, |
| 845 | &rx_rings, |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 846 | rxfh.indir_size); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 847 | if (ret) |
| 848 | goto out; |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 849 | } else if (rxfh.indir_size == 0) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 850 | indir = (u32 *)rss_config; |
| 851 | for (i = 0; i < dev_indir_size; i++) |
| 852 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); |
| 853 | } |
| 854 | |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 855 | if (rxfh.key_size) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 856 | hkey = rss_config + indir_bytes; |
| 857 | if (copy_from_user(hkey, |
| 858 | useraddr + rss_cfg_offset + indir_bytes, |
Ben Hutchings | f062a38 | 2014-05-15 16:28:07 +0100 | [diff] [blame] | 859 | rxfh.key_size)) { |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 860 | ret = -EFAULT; |
| 861 | goto out; |
| 862 | } |
| 863 | } |
| 864 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 865 | ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc); |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 866 | |
| 867 | out: |
| 868 | kfree(rss_config); |
| 869 | return ret; |
| 870 | } |
| 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
| 873 | { |
| 874 | struct ethtool_regs regs; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 875 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | void *regbuf; |
| 877 | int reglen, ret; |
| 878 | |
| 879 | if (!ops->get_regs || !ops->get_regs_len) |
| 880 | return -EOPNOTSUPP; |
| 881 | |
| 882 | if (copy_from_user(®s, useraddr, sizeof(regs))) |
| 883 | return -EFAULT; |
| 884 | |
| 885 | reglen = ops->get_regs_len(dev); |
| 886 | if (regs.len > reglen) |
| 887 | regs.len = reglen; |
| 888 | |
Eugene Teo | b7c7d01 | 2011-01-24 21:05:17 -0800 | [diff] [blame] | 889 | regbuf = vzalloc(reglen); |
Ben Hutchings | 67ae7cf | 2011-07-21 15:25:30 -0700 | [diff] [blame] | 890 | if (reglen && !regbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | return -ENOMEM; |
| 892 | |
| 893 | ops->get_regs(dev, ®s, regbuf); |
| 894 | |
| 895 | ret = -EFAULT; |
| 896 | if (copy_to_user(useraddr, ®s, sizeof(regs))) |
| 897 | goto out; |
| 898 | useraddr += offsetof(struct ethtool_regs, data); |
Ben Hutchings | 67ae7cf | 2011-07-21 15:25:30 -0700 | [diff] [blame] | 899 | if (regbuf && copy_to_user(useraddr, regbuf, regs.len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | goto out; |
| 901 | ret = 0; |
| 902 | |
| 903 | out: |
Ben Hutchings | a77f5db | 2010-09-20 08:42:17 +0000 | [diff] [blame] | 904 | vfree(regbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return ret; |
| 906 | } |
| 907 | |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 908 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
| 909 | { |
| 910 | struct ethtool_value reset; |
| 911 | int ret; |
| 912 | |
| 913 | if (!dev->ethtool_ops->reset) |
| 914 | return -EOPNOTSUPP; |
| 915 | |
| 916 | if (copy_from_user(&reset, useraddr, sizeof(reset))) |
| 917 | return -EFAULT; |
| 918 | |
| 919 | ret = dev->ethtool_ops->reset(dev, &reset.data); |
| 920 | if (ret) |
| 921 | return ret; |
| 922 | |
| 923 | if (copy_to_user(useraddr, &reset, sizeof(reset))) |
| 924 | return -EFAULT; |
| 925 | return 0; |
| 926 | } |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
| 929 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 930 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | if (!dev->ethtool_ops->get_wol) |
| 933 | return -EOPNOTSUPP; |
| 934 | |
| 935 | dev->ethtool_ops->get_wol(dev, &wol); |
| 936 | |
| 937 | if (copy_to_user(useraddr, &wol, sizeof(wol))) |
| 938 | return -EFAULT; |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) |
| 943 | { |
| 944 | struct ethtool_wolinfo wol; |
| 945 | |
| 946 | if (!dev->ethtool_ops->set_wol) |
| 947 | return -EOPNOTSUPP; |
| 948 | |
| 949 | if (copy_from_user(&wol, useraddr, sizeof(wol))) |
| 950 | return -EFAULT; |
| 951 | |
| 952 | return dev->ethtool_ops->set_wol(dev, &wol); |
| 953 | } |
| 954 | |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 955 | static int ethtool_get_eee(struct net_device *dev, char __user *useraddr) |
| 956 | { |
| 957 | struct ethtool_eee edata; |
| 958 | int rc; |
| 959 | |
| 960 | if (!dev->ethtool_ops->get_eee) |
| 961 | return -EOPNOTSUPP; |
| 962 | |
| 963 | memset(&edata, 0, sizeof(struct ethtool_eee)); |
| 964 | edata.cmd = ETHTOOL_GEEE; |
| 965 | rc = dev->ethtool_ops->get_eee(dev, &edata); |
| 966 | |
| 967 | if (rc) |
| 968 | return rc; |
| 969 | |
| 970 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 971 | return -EFAULT; |
| 972 | |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static int ethtool_set_eee(struct net_device *dev, char __user *useraddr) |
| 977 | { |
| 978 | struct ethtool_eee edata; |
| 979 | |
| 980 | if (!dev->ethtool_ops->set_eee) |
| 981 | return -EOPNOTSUPP; |
| 982 | |
| 983 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 984 | return -EFAULT; |
| 985 | |
| 986 | return dev->ethtool_ops->set_eee(dev, &edata); |
| 987 | } |
| 988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | static int ethtool_nway_reset(struct net_device *dev) |
| 990 | { |
| 991 | if (!dev->ethtool_ops->nway_reset) |
| 992 | return -EOPNOTSUPP; |
| 993 | |
| 994 | return dev->ethtool_ops->nway_reset(dev); |
| 995 | } |
| 996 | |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 997 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
| 998 | { |
| 999 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; |
| 1000 | |
| 1001 | if (!dev->ethtool_ops->get_link) |
| 1002 | return -EOPNOTSUPP; |
| 1003 | |
| 1004 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); |
| 1005 | |
| 1006 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1007 | return -EFAULT; |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1011 | static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr, |
| 1012 | int (*getter)(struct net_device *, |
| 1013 | struct ethtool_eeprom *, u8 *), |
| 1014 | u32 total_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | { |
| 1016 | struct ethtool_eeprom eeprom; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1017 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1018 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1020 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1023 | return -EFAULT; |
| 1024 | |
| 1025 | /* Check for wrap and zero */ |
| 1026 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1027 | return -EINVAL; |
| 1028 | |
| 1029 | /* Check for exceeding total eeprom len */ |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1030 | if (eeprom.offset + eeprom.len > total_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | return -EINVAL; |
| 1032 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1033 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | if (!data) |
| 1035 | return -ENOMEM; |
| 1036 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1037 | bytes_remaining = eeprom.len; |
| 1038 | while (bytes_remaining > 0) { |
| 1039 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1041 | ret = getter(dev, &eeprom, data); |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1042 | if (ret) |
| 1043 | break; |
| 1044 | if (copy_to_user(userbuf, data, eeprom.len)) { |
| 1045 | ret = -EFAULT; |
| 1046 | break; |
| 1047 | } |
| 1048 | userbuf += eeprom.len; |
| 1049 | eeprom.offset += eeprom.len; |
| 1050 | bytes_remaining -= eeprom.len; |
| 1051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Mandeep Singh Baines | c5835df | 2008-04-24 20:55:56 -0700 | [diff] [blame] | 1053 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
| 1054 | eeprom.offset -= eeprom.len; |
| 1055 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) |
| 1056 | ret = -EFAULT; |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | kfree(data); |
| 1059 | return ret; |
| 1060 | } |
| 1061 | |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1062 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
| 1063 | { |
| 1064 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1065 | |
Guenter Roeck | e0fb6fb | 2014-10-30 20:50:15 -0700 | [diff] [blame] | 1066 | if (!ops->get_eeprom || !ops->get_eeprom_len || |
| 1067 | !ops->get_eeprom_len(dev)) |
Ben Hutchings | 081d094 | 2012-04-12 00:42:12 +0000 | [diff] [blame] | 1068 | return -EOPNOTSUPP; |
| 1069 | |
| 1070 | return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom, |
| 1071 | ops->get_eeprom_len(dev)); |
| 1072 | } |
| 1073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
| 1075 | { |
| 1076 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1077 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1078 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1079 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1081 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
Guenter Roeck | e0fb6fb | 2014-10-30 20:50:15 -0700 | [diff] [blame] | 1083 | if (!ops->set_eeprom || !ops->get_eeprom_len || |
| 1084 | !ops->get_eeprom_len(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | return -EOPNOTSUPP; |
| 1086 | |
| 1087 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1088 | return -EFAULT; |
| 1089 | |
| 1090 | /* Check for wrap and zero */ |
| 1091 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1092 | return -EINVAL; |
| 1093 | |
| 1094 | /* Check for exceeding total eeprom len */ |
| 1095 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1096 | return -EINVAL; |
| 1097 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1098 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | if (!data) |
| 1100 | return -ENOMEM; |
| 1101 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1102 | bytes_remaining = eeprom.len; |
| 1103 | while (bytes_remaining > 0) { |
| 1104 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1106 | if (copy_from_user(data, userbuf, eeprom.len)) { |
| 1107 | ret = -EFAULT; |
| 1108 | break; |
| 1109 | } |
| 1110 | ret = ops->set_eeprom(dev, &eeprom, data); |
| 1111 | if (ret) |
| 1112 | break; |
| 1113 | userbuf += eeprom.len; |
| 1114 | eeprom.offset += eeprom.len; |
| 1115 | bytes_remaining -= eeprom.len; |
| 1116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | kfree(data); |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1122 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
| 1123 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1125 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | if (!dev->ethtool_ops->get_coalesce) |
| 1128 | return -EOPNOTSUPP; |
| 1129 | |
| 1130 | dev->ethtool_ops->get_coalesce(dev, &coalesce); |
| 1131 | |
| 1132 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 1133 | return -EFAULT; |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1137 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
| 1138 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | { |
| 1140 | struct ethtool_coalesce coalesce; |
| 1141 | |
David S. Miller | fa04ae5 | 2005-06-06 15:07:19 -0700 | [diff] [blame] | 1142 | if (!dev->ethtool_ops->set_coalesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | return -EOPNOTSUPP; |
| 1144 | |
| 1145 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) |
| 1146 | return -EFAULT; |
| 1147 | |
| 1148 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); |
| 1149 | } |
| 1150 | |
| 1151 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) |
| 1152 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1153 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
| 1155 | if (!dev->ethtool_ops->get_ringparam) |
| 1156 | return -EOPNOTSUPP; |
| 1157 | |
| 1158 | dev->ethtool_ops->get_ringparam(dev, &ringparam); |
| 1159 | |
| 1160 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) |
| 1161 | return -EFAULT; |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) |
| 1166 | { |
| 1167 | struct ethtool_ringparam ringparam; |
| 1168 | |
| 1169 | if (!dev->ethtool_ops->set_ringparam) |
| 1170 | return -EOPNOTSUPP; |
| 1171 | |
| 1172 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) |
| 1173 | return -EFAULT; |
| 1174 | |
| 1175 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); |
| 1176 | } |
| 1177 | |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1178 | static noinline_for_stack int ethtool_get_channels(struct net_device *dev, |
| 1179 | void __user *useraddr) |
| 1180 | { |
| 1181 | struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; |
| 1182 | |
| 1183 | if (!dev->ethtool_ops->get_channels) |
| 1184 | return -EOPNOTSUPP; |
| 1185 | |
| 1186 | dev->ethtool_ops->get_channels(dev, &channels); |
| 1187 | |
| 1188 | if (copy_to_user(useraddr, &channels, sizeof(channels))) |
| 1189 | return -EFAULT; |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static noinline_for_stack int ethtool_set_channels(struct net_device *dev, |
| 1194 | void __user *useraddr) |
| 1195 | { |
| 1196 | struct ethtool_channels channels; |
| 1197 | |
| 1198 | if (!dev->ethtool_ops->set_channels) |
| 1199 | return -EOPNOTSUPP; |
| 1200 | |
| 1201 | if (copy_from_user(&channels, useraddr, sizeof(channels))) |
| 1202 | return -EFAULT; |
| 1203 | |
| 1204 | return dev->ethtool_ops->set_channels(dev, &channels); |
| 1205 | } |
| 1206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1208 | { |
| 1209 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; |
| 1210 | |
| 1211 | if (!dev->ethtool_ops->get_pauseparam) |
| 1212 | return -EOPNOTSUPP; |
| 1213 | |
| 1214 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); |
| 1215 | |
| 1216 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) |
| 1217 | return -EFAULT; |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1222 | { |
| 1223 | struct ethtool_pauseparam pauseparam; |
| 1224 | |
Jeff Garzik | e1b90c4 | 2006-07-17 12:54:40 -0400 | [diff] [blame] | 1225 | if (!dev->ethtool_ops->set_pauseparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | return -EOPNOTSUPP; |
| 1227 | |
| 1228 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) |
| 1229 | return -EFAULT; |
| 1230 | |
| 1231 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); |
| 1232 | } |
| 1233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
| 1235 | { |
| 1236 | struct ethtool_test test; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1237 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1239 | int ret, test_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1241 | if (!ops->self_test || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1242 | return -EOPNOTSUPP; |
| 1243 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1244 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1245 | if (test_len < 0) |
| 1246 | return test_len; |
| 1247 | WARN_ON(test_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | if (copy_from_user(&test, useraddr, sizeof(test))) |
| 1250 | return -EFAULT; |
| 1251 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1252 | test.len = test_len; |
| 1253 | data = kmalloc(test_len * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | if (!data) |
| 1255 | return -ENOMEM; |
| 1256 | |
| 1257 | ops->self_test(dev, &test, data); |
| 1258 | |
| 1259 | ret = -EFAULT; |
| 1260 | if (copy_to_user(useraddr, &test, sizeof(test))) |
| 1261 | goto out; |
| 1262 | useraddr += sizeof(test); |
| 1263 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) |
| 1264 | goto out; |
| 1265 | ret = 0; |
| 1266 | |
| 1267 | out: |
| 1268 | kfree(data); |
| 1269 | return ret; |
| 1270 | } |
| 1271 | |
| 1272 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
| 1273 | { |
| 1274 | struct ethtool_gstrings gstrings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | u8 *data; |
| 1276 | int ret; |
| 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 1279 | return -EFAULT; |
| 1280 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1281 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1282 | if (ret < 0) |
| 1283 | return ret; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1284 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1285 | gstrings.len = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Joe Perches | 077cb37 | 2015-10-14 01:09:40 -0700 | [diff] [blame] | 1287 | data = kcalloc(gstrings.len, ETH_GSTRING_LEN, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | if (!data) |
| 1289 | return -ENOMEM; |
| 1290 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1291 | __ethtool_get_strings(dev, gstrings.string_set, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
| 1293 | ret = -EFAULT; |
| 1294 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1295 | goto out; |
| 1296 | useraddr += sizeof(gstrings); |
| 1297 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1298 | goto out; |
| 1299 | ret = 0; |
| 1300 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1301 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | kfree(data); |
| 1303 | return ret; |
| 1304 | } |
| 1305 | |
| 1306 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) |
| 1307 | { |
| 1308 | struct ethtool_value id; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1309 | static bool busy; |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1310 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1311 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1313 | if (!ops->set_phys_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | return -EOPNOTSUPP; |
| 1315 | |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1316 | if (busy) |
| 1317 | return -EBUSY; |
| 1318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | if (copy_from_user(&id, useraddr, sizeof(id))) |
| 1320 | return -EFAULT; |
| 1321 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1322 | rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1323 | if (rc < 0) |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1324 | return rc; |
| 1325 | |
| 1326 | /* Drop the RTNL lock while waiting, but prevent reentry or |
| 1327 | * removal of the device. |
| 1328 | */ |
| 1329 | busy = true; |
| 1330 | dev_hold(dev); |
| 1331 | rtnl_unlock(); |
| 1332 | |
| 1333 | if (rc == 0) { |
| 1334 | /* Driver will handle this itself */ |
| 1335 | schedule_timeout_interruptible( |
Allan, Bruce W | 143780c | 2011-04-11 13:01:59 +0000 | [diff] [blame] | 1336 | id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1337 | } else { |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1338 | /* Driver expects to be called at twice the frequency in rc */ |
| 1339 | int n = rc * 2, i, interval = HZ / n; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1340 | |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1341 | /* Count down seconds */ |
| 1342 | do { |
| 1343 | /* Count down iterations per second */ |
| 1344 | i = n; |
| 1345 | do { |
| 1346 | rtnl_lock(); |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1347 | rc = ops->set_phys_id(dev, |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1348 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); |
| 1349 | rtnl_unlock(); |
| 1350 | if (rc) |
| 1351 | break; |
| 1352 | schedule_timeout_interruptible(interval); |
| 1353 | } while (!signal_pending(current) && --i != 0); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1354 | } while (!signal_pending(current) && |
| 1355 | (id.data == 0 || --id.data != 0)); |
| 1356 | } |
| 1357 | |
| 1358 | rtnl_lock(); |
| 1359 | dev_put(dev); |
| 1360 | busy = false; |
| 1361 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1362 | (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1363 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) |
| 1367 | { |
| 1368 | struct ethtool_stats stats; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1369 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1371 | int ret, n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1373 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1374 | return -EOPNOTSUPP; |
| 1375 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1376 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1377 | if (n_stats < 0) |
| 1378 | return n_stats; |
| 1379 | WARN_ON(n_stats == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
| 1381 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 1382 | return -EFAULT; |
| 1383 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1384 | stats.n_stats = n_stats; |
| 1385 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | if (!data) |
| 1387 | return -ENOMEM; |
| 1388 | |
| 1389 | ops->get_ethtool_stats(dev, &stats, data); |
| 1390 | |
| 1391 | ret = -EFAULT; |
| 1392 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 1393 | goto out; |
| 1394 | useraddr += sizeof(stats); |
| 1395 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) |
| 1396 | goto out; |
| 1397 | ret = 0; |
| 1398 | |
| 1399 | out: |
| 1400 | kfree(data); |
| 1401 | return ret; |
| 1402 | } |
| 1403 | |
viro@ftp.linux.org.uk | 0bf0519d | 2005-09-05 03:26:18 +0100 | [diff] [blame] | 1404 | 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] | 1405 | { |
| 1406 | struct ethtool_perm_addr epaddr; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1407 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1408 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1409 | return -EFAULT; |
| 1410 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1411 | if (epaddr.size < dev->addr_len) |
| 1412 | return -ETOOSMALL; |
| 1413 | epaddr.size = dev->addr_len; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1414 | |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1415 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1416 | return -EFAULT; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1417 | useraddr += sizeof(epaddr); |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1418 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
| 1419 | return -EFAULT; |
| 1420 | return 0; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1423 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
| 1424 | u32 cmd, u32 (*actor)(struct net_device *)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1425 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1426 | struct ethtool_value edata = { .cmd = cmd }; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1427 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1428 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1429 | return -EOPNOTSUPP; |
| 1430 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1431 | edata.data = actor(dev); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1432 | |
| 1433 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1434 | return -EFAULT; |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1438 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
| 1439 | void (*actor)(struct net_device *, u32)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1440 | { |
| 1441 | struct ethtool_value edata; |
| 1442 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1443 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1444 | return -EOPNOTSUPP; |
| 1445 | |
| 1446 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1447 | return -EFAULT; |
| 1448 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1449 | actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1450 | return 0; |
| 1451 | } |
| 1452 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1453 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
| 1454 | int (*actor)(struct net_device *, u32)) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1455 | { |
| 1456 | struct ethtool_value edata; |
| 1457 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1458 | if (!actor) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1459 | return -EOPNOTSUPP; |
| 1460 | |
| 1461 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1462 | return -EFAULT; |
| 1463 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1464 | return actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1467 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
| 1468 | char __user *useraddr) |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1469 | { |
| 1470 | struct ethtool_flash efl; |
| 1471 | |
| 1472 | if (copy_from_user(&efl, useraddr, sizeof(efl))) |
| 1473 | return -EFAULT; |
| 1474 | |
| 1475 | if (!dev->ethtool_ops->flash_device) |
| 1476 | return -EOPNOTSUPP; |
| 1477 | |
Ben Hutchings | 786f528 | 2012-02-01 09:32:25 +0000 | [diff] [blame] | 1478 | efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 1479 | |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1480 | return dev->ethtool_ops->flash_device(dev, &efl); |
| 1481 | } |
| 1482 | |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1483 | static int ethtool_set_dump(struct net_device *dev, |
| 1484 | void __user *useraddr) |
| 1485 | { |
| 1486 | struct ethtool_dump dump; |
| 1487 | |
| 1488 | if (!dev->ethtool_ops->set_dump) |
| 1489 | return -EOPNOTSUPP; |
| 1490 | |
| 1491 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1492 | return -EFAULT; |
| 1493 | |
| 1494 | return dev->ethtool_ops->set_dump(dev, &dump); |
| 1495 | } |
| 1496 | |
| 1497 | static int ethtool_get_dump_flag(struct net_device *dev, |
| 1498 | void __user *useraddr) |
| 1499 | { |
| 1500 | int ret; |
| 1501 | struct ethtool_dump dump; |
| 1502 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1503 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1504 | if (!ops->get_dump_flag) |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1505 | return -EOPNOTSUPP; |
| 1506 | |
| 1507 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1508 | return -EFAULT; |
| 1509 | |
| 1510 | ret = ops->get_dump_flag(dev, &dump); |
| 1511 | if (ret) |
| 1512 | return ret; |
| 1513 | |
| 1514 | if (copy_to_user(useraddr, &dump, sizeof(dump))) |
| 1515 | return -EFAULT; |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | static int ethtool_get_dump_data(struct net_device *dev, |
| 1520 | void __user *useraddr) |
| 1521 | { |
| 1522 | int ret; |
| 1523 | __u32 len; |
| 1524 | struct ethtool_dump dump, tmp; |
| 1525 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1526 | void *data = NULL; |
| 1527 | |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1528 | if (!ops->get_dump_data || !ops->get_dump_flag) |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1529 | return -EOPNOTSUPP; |
| 1530 | |
| 1531 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1532 | return -EFAULT; |
| 1533 | |
| 1534 | memset(&tmp, 0, sizeof(tmp)); |
| 1535 | tmp.cmd = ETHTOOL_GET_DUMP_FLAG; |
| 1536 | ret = ops->get_dump_flag(dev, &tmp); |
| 1537 | if (ret) |
| 1538 | return ret; |
| 1539 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 1540 | len = min(tmp.len, dump.len); |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1541 | if (!len) |
| 1542 | return -EFAULT; |
| 1543 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 1544 | /* Don't ever let the driver think there's more space available |
| 1545 | * than it requested with .get_dump_flag(). |
| 1546 | */ |
| 1547 | dump.len = len; |
| 1548 | |
| 1549 | /* Always allocate enough space to hold the whole thing so that the |
| 1550 | * driver does not need to check the length and bother with partial |
| 1551 | * dumping. |
| 1552 | */ |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1553 | data = vzalloc(tmp.len); |
| 1554 | if (!data) |
| 1555 | return -ENOMEM; |
| 1556 | ret = ops->get_dump_data(dev, &dump, data); |
| 1557 | if (ret) |
| 1558 | goto out; |
| 1559 | |
Michal Schmidt | c590b5e | 2013-07-01 17:23:30 +0200 | [diff] [blame] | 1560 | /* There are two sane possibilities: |
| 1561 | * 1. The driver's .get_dump_data() does not touch dump.len. |
| 1562 | * 2. Or it may set dump.len to how much it really writes, which |
| 1563 | * should be tmp.len (or len if it can do a partial dump). |
| 1564 | * In any case respond to userspace with the actual length of data |
| 1565 | * it's receiving. |
| 1566 | */ |
| 1567 | WARN_ON(dump.len != len && dump.len != tmp.len); |
| 1568 | dump.len = len; |
| 1569 | |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1570 | if (copy_to_user(useraddr, &dump, sizeof(dump))) { |
| 1571 | ret = -EFAULT; |
| 1572 | goto out; |
| 1573 | } |
| 1574 | useraddr += offsetof(struct ethtool_dump, data); |
| 1575 | if (copy_to_user(useraddr, data, len)) |
| 1576 | ret = -EFAULT; |
| 1577 | out: |
| 1578 | vfree(data); |
| 1579 | return ret; |
| 1580 | } |
| 1581 | |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1582 | static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) |
| 1583 | { |
| 1584 | int err = 0; |
| 1585 | struct ethtool_ts_info info; |
| 1586 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1587 | struct phy_device *phydev = dev->phydev; |
| 1588 | |
| 1589 | memset(&info, 0, sizeof(info)); |
| 1590 | info.cmd = ETHTOOL_GET_TS_INFO; |
| 1591 | |
| 1592 | if (phydev && phydev->drv && phydev->drv->ts_info) { |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1593 | err = phydev->drv->ts_info(phydev, &info); |
Jiri Pirko | c03a14e | 2013-01-07 09:02:08 +0000 | [diff] [blame] | 1594 | } else if (ops->get_ts_info) { |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1595 | err = ops->get_ts_info(dev, &info); |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1596 | } else { |
| 1597 | info.so_timestamping = |
| 1598 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1599 | SOF_TIMESTAMPING_SOFTWARE; |
| 1600 | info.phc_index = -1; |
| 1601 | } |
| 1602 | |
| 1603 | if (err) |
| 1604 | return err; |
| 1605 | |
| 1606 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 1607 | err = -EFAULT; |
| 1608 | |
| 1609 | return err; |
| 1610 | } |
| 1611 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 1612 | static int __ethtool_get_module_info(struct net_device *dev, |
| 1613 | struct ethtool_modinfo *modinfo) |
| 1614 | { |
| 1615 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1616 | struct phy_device *phydev = dev->phydev; |
| 1617 | |
| 1618 | if (phydev && phydev->drv && phydev->drv->module_info) |
| 1619 | return phydev->drv->module_info(phydev, modinfo); |
| 1620 | |
| 1621 | if (ops->get_module_info) |
| 1622 | return ops->get_module_info(dev, modinfo); |
| 1623 | |
| 1624 | return -EOPNOTSUPP; |
| 1625 | } |
| 1626 | |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1627 | static int ethtool_get_module_info(struct net_device *dev, |
| 1628 | void __user *useraddr) |
| 1629 | { |
| 1630 | int ret; |
| 1631 | struct ethtool_modinfo modinfo; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1632 | |
| 1633 | if (copy_from_user(&modinfo, useraddr, sizeof(modinfo))) |
| 1634 | return -EFAULT; |
| 1635 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 1636 | ret = __ethtool_get_module_info(dev, &modinfo); |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1637 | if (ret) |
| 1638 | return ret; |
| 1639 | |
| 1640 | if (copy_to_user(useraddr, &modinfo, sizeof(modinfo))) |
| 1641 | return -EFAULT; |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 1646 | static int __ethtool_get_module_eeprom(struct net_device *dev, |
| 1647 | struct ethtool_eeprom *ee, u8 *data) |
| 1648 | { |
| 1649 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1650 | struct phy_device *phydev = dev->phydev; |
| 1651 | |
| 1652 | if (phydev && phydev->drv && phydev->drv->module_eeprom) |
| 1653 | return phydev->drv->module_eeprom(phydev, ee, data); |
| 1654 | |
| 1655 | if (ops->get_module_eeprom) |
| 1656 | return ops->get_module_eeprom(dev, ee, data); |
| 1657 | |
| 1658 | return -EOPNOTSUPP; |
| 1659 | } |
| 1660 | |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1661 | static int ethtool_get_module_eeprom(struct net_device *dev, |
| 1662 | void __user *useraddr) |
| 1663 | { |
| 1664 | int ret; |
| 1665 | struct ethtool_modinfo modinfo; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1666 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 1667 | ret = __ethtool_get_module_info(dev, &modinfo); |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1668 | if (ret) |
| 1669 | return ret; |
| 1670 | |
Ed Swierk | 2f43836 | 2015-01-02 17:27:56 -0800 | [diff] [blame] | 1671 | return ethtool_get_any_eeprom(dev, useraddr, |
| 1672 | __ethtool_get_module_eeprom, |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1673 | modinfo.eeprom_len); |
| 1674 | } |
| 1675 | |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 1676 | static int ethtool_tunable_valid(const struct ethtool_tunable *tuna) |
| 1677 | { |
| 1678 | switch (tuna->id) { |
| 1679 | case ETHTOOL_RX_COPYBREAK: |
Eric Dumazet | 1255a50 | 2014-10-05 12:35:21 +0300 | [diff] [blame] | 1680 | case ETHTOOL_TX_COPYBREAK: |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 1681 | if (tuna->len != sizeof(u32) || |
| 1682 | tuna->type_id != ETHTOOL_TUNABLE_U32) |
| 1683 | return -EINVAL; |
| 1684 | break; |
| 1685 | default: |
| 1686 | return -EINVAL; |
| 1687 | } |
| 1688 | |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
| 1692 | static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr) |
| 1693 | { |
| 1694 | int ret; |
| 1695 | struct ethtool_tunable tuna; |
| 1696 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1697 | void *data; |
| 1698 | |
| 1699 | if (!ops->get_tunable) |
| 1700 | return -EOPNOTSUPP; |
| 1701 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 1702 | return -EFAULT; |
| 1703 | ret = ethtool_tunable_valid(&tuna); |
| 1704 | if (ret) |
| 1705 | return ret; |
| 1706 | data = kmalloc(tuna.len, GFP_USER); |
| 1707 | if (!data) |
| 1708 | return -ENOMEM; |
| 1709 | ret = ops->get_tunable(dev, &tuna, data); |
| 1710 | if (ret) |
| 1711 | goto out; |
| 1712 | useraddr += sizeof(tuna); |
| 1713 | ret = -EFAULT; |
| 1714 | if (copy_to_user(useraddr, data, tuna.len)) |
| 1715 | goto out; |
| 1716 | ret = 0; |
| 1717 | |
| 1718 | out: |
| 1719 | kfree(data); |
| 1720 | return ret; |
| 1721 | } |
| 1722 | |
| 1723 | static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr) |
| 1724 | { |
| 1725 | int ret; |
| 1726 | struct ethtool_tunable tuna; |
| 1727 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1728 | void *data; |
| 1729 | |
| 1730 | if (!ops->set_tunable) |
| 1731 | return -EOPNOTSUPP; |
| 1732 | if (copy_from_user(&tuna, useraddr, sizeof(tuna))) |
| 1733 | return -EFAULT; |
| 1734 | ret = ethtool_tunable_valid(&tuna); |
| 1735 | if (ret) |
| 1736 | return ret; |
| 1737 | data = kmalloc(tuna.len, GFP_USER); |
| 1738 | if (!data) |
| 1739 | return -ENOMEM; |
| 1740 | useraddr += sizeof(tuna); |
| 1741 | ret = -EFAULT; |
| 1742 | if (copy_from_user(data, useraddr, tuna.len)) |
| 1743 | goto out; |
| 1744 | ret = ops->set_tunable(dev, &tuna, data); |
| 1745 | |
| 1746 | out: |
| 1747 | kfree(data); |
| 1748 | return ret; |
| 1749 | } |
| 1750 | |
Yan Burman | 600fed5 | 2013-06-03 02:03:34 +0000 | [diff] [blame] | 1751 | /* 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] | 1752 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1753 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1755 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | void __user *useraddr = ifr->ifr_data; |
| 1757 | u32 ethcmd; |
| 1758 | int rc; |
Bjørn Mork | b29d314 | 2013-05-01 23:06:42 +0000 | [diff] [blame] | 1759 | netdev_features_t old_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | if (!dev || !netif_device_present(dev)) |
| 1762 | return -ENODEV; |
| 1763 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1764 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | return -EFAULT; |
| 1766 | |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1767 | /* Allow some commands to be done by anyone */ |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1768 | switch (ethcmd) { |
stephen hemminger | 0fdc100 | 2010-08-23 10:24:18 +0000 | [diff] [blame] | 1769 | case ETHTOOL_GSET: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1770 | case ETHTOOL_GDRVINFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1771 | case ETHTOOL_GMSGLVL: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 1772 | case ETHTOOL_GLINK: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1773 | case ETHTOOL_GCOALESCE: |
| 1774 | case ETHTOOL_GRINGPARAM: |
| 1775 | case ETHTOOL_GPAUSEPARAM: |
| 1776 | case ETHTOOL_GRXCSUM: |
| 1777 | case ETHTOOL_GTXCSUM: |
| 1778 | case ETHTOOL_GSG: |
Michał Mirosław | f80400a | 2012-01-22 00:20:40 +0000 | [diff] [blame] | 1779 | case ETHTOOL_GSSET_INFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1780 | case ETHTOOL_GSTRINGS: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 1781 | case ETHTOOL_GSTATS: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1782 | case ETHTOOL_GTSO: |
| 1783 | case ETHTOOL_GPERMADDR: |
| 1784 | case ETHTOOL_GUFO: |
| 1785 | case ETHTOOL_GGSO: |
stephen hemminger | 1cab819 | 2010-02-11 13:48:29 +0000 | [diff] [blame] | 1786 | case ETHTOOL_GGRO: |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1787 | case ETHTOOL_GFLAGS: |
| 1788 | case ETHTOOL_GPFLAGS: |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1789 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1790 | case ETHTOOL_GRXRINGS: |
| 1791 | case ETHTOOL_GRXCLSRLCNT: |
| 1792 | case ETHTOOL_GRXCLSRULE: |
| 1793 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 1794 | case ETHTOOL_GRXFHINDIR: |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1795 | case ETHTOOL_GRSSH: |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1796 | case ETHTOOL_GFEATURES: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 1797 | case ETHTOOL_GCHANNELS: |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1798 | case ETHTOOL_GET_TS_INFO: |
Ben Hutchings | 2da45db | 2012-06-12 13:05:41 +0000 | [diff] [blame] | 1799 | case ETHTOOL_GEEE: |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 1800 | case ETHTOOL_GTUNABLE: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1801 | break; |
| 1802 | default: |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 1803 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1804 | return -EPERM; |
| 1805 | } |
| 1806 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1807 | if (dev->ethtool_ops->begin) { |
| 1808 | rc = dev->ethtool_ops->begin(dev); |
| 1809 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | return rc; |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1811 | } |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1812 | old_features = dev->features; |
| 1813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | switch (ethcmd) { |
| 1815 | case ETHTOOL_GSET: |
| 1816 | rc = ethtool_get_settings(dev, useraddr); |
| 1817 | break; |
| 1818 | case ETHTOOL_SSET: |
| 1819 | rc = ethtool_set_settings(dev, useraddr); |
| 1820 | break; |
| 1821 | case ETHTOOL_GDRVINFO: |
| 1822 | rc = ethtool_get_drvinfo(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | break; |
| 1824 | case ETHTOOL_GREGS: |
| 1825 | rc = ethtool_get_regs(dev, useraddr); |
| 1826 | break; |
| 1827 | case ETHTOOL_GWOL: |
| 1828 | rc = ethtool_get_wol(dev, useraddr); |
| 1829 | break; |
| 1830 | case ETHTOOL_SWOL: |
| 1831 | rc = ethtool_set_wol(dev, useraddr); |
| 1832 | break; |
| 1833 | case ETHTOOL_GMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1834 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1835 | dev->ethtool_ops->get_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | break; |
| 1837 | case ETHTOOL_SMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1838 | rc = ethtool_set_value_void(dev, useraddr, |
| 1839 | dev->ethtool_ops->set_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | break; |
Yuval Mintz | 80f12ec | 2012-06-06 17:13:06 +0000 | [diff] [blame] | 1841 | case ETHTOOL_GEEE: |
| 1842 | rc = ethtool_get_eee(dev, useraddr); |
| 1843 | break; |
| 1844 | case ETHTOOL_SEEE: |
| 1845 | rc = ethtool_set_eee(dev, useraddr); |
| 1846 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | case ETHTOOL_NWAY_RST: |
| 1848 | rc = ethtool_nway_reset(dev); |
| 1849 | break; |
| 1850 | case ETHTOOL_GLINK: |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1851 | rc = ethtool_get_link(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | break; |
| 1853 | case ETHTOOL_GEEPROM: |
| 1854 | rc = ethtool_get_eeprom(dev, useraddr); |
| 1855 | break; |
| 1856 | case ETHTOOL_SEEPROM: |
| 1857 | rc = ethtool_set_eeprom(dev, useraddr); |
| 1858 | break; |
| 1859 | case ETHTOOL_GCOALESCE: |
| 1860 | rc = ethtool_get_coalesce(dev, useraddr); |
| 1861 | break; |
| 1862 | case ETHTOOL_SCOALESCE: |
| 1863 | rc = ethtool_set_coalesce(dev, useraddr); |
| 1864 | break; |
| 1865 | case ETHTOOL_GRINGPARAM: |
| 1866 | rc = ethtool_get_ringparam(dev, useraddr); |
| 1867 | break; |
| 1868 | case ETHTOOL_SRINGPARAM: |
| 1869 | rc = ethtool_set_ringparam(dev, useraddr); |
| 1870 | break; |
| 1871 | case ETHTOOL_GPAUSEPARAM: |
| 1872 | rc = ethtool_get_pauseparam(dev, useraddr); |
| 1873 | break; |
| 1874 | case ETHTOOL_SPAUSEPARAM: |
| 1875 | rc = ethtool_set_pauseparam(dev, useraddr); |
| 1876 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | case ETHTOOL_TEST: |
| 1878 | rc = ethtool_self_test(dev, useraddr); |
| 1879 | break; |
| 1880 | case ETHTOOL_GSTRINGS: |
| 1881 | rc = ethtool_get_strings(dev, useraddr); |
| 1882 | break; |
| 1883 | case ETHTOOL_PHYS_ID: |
| 1884 | rc = ethtool_phys_id(dev, useraddr); |
| 1885 | break; |
| 1886 | case ETHTOOL_GSTATS: |
| 1887 | rc = ethtool_get_stats(dev, useraddr); |
| 1888 | break; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1889 | case ETHTOOL_GPERMADDR: |
| 1890 | rc = ethtool_get_perm_addr(dev, useraddr); |
| 1891 | break; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1892 | case ETHTOOL_GFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1893 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1894 | __ethtool_get_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1895 | break; |
| 1896 | case ETHTOOL_SFLAGS: |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1897 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1898 | break; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1899 | case ETHTOOL_GPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1900 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1901 | dev->ethtool_ops->get_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1902 | break; |
| 1903 | case ETHTOOL_SPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1904 | rc = ethtool_set_value(dev, useraddr, |
| 1905 | dev->ethtool_ops->set_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1906 | break; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1907 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1908 | case ETHTOOL_GRXRINGS: |
| 1909 | case ETHTOOL_GRXCLSRLCNT: |
| 1910 | case ETHTOOL_GRXCLSRULE: |
| 1911 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1912 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1913 | break; |
| 1914 | case ETHTOOL_SRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1915 | case ETHTOOL_SRXCLSRLDEL: |
| 1916 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1917 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1918 | break; |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1919 | case ETHTOOL_FLASHDEV: |
| 1920 | rc = ethtool_flash_device(dev, useraddr); |
| 1921 | break; |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1922 | case ETHTOOL_RESET: |
| 1923 | rc = ethtool_reset(dev, useraddr); |
| 1924 | break; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 1925 | case ETHTOOL_GSSET_INFO: |
| 1926 | rc = ethtool_get_sset_info(dev, useraddr); |
| 1927 | break; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1928 | case ETHTOOL_GRXFHINDIR: |
| 1929 | rc = ethtool_get_rxfh_indir(dev, useraddr); |
| 1930 | break; |
| 1931 | case ETHTOOL_SRXFHINDIR: |
| 1932 | rc = ethtool_set_rxfh_indir(dev, useraddr); |
| 1933 | break; |
Venkata Duvvuru | 3de0b59 | 2014-04-21 15:37:59 +0530 | [diff] [blame] | 1934 | case ETHTOOL_GRSSH: |
| 1935 | rc = ethtool_get_rxfh(dev, useraddr); |
| 1936 | break; |
| 1937 | case ETHTOOL_SRSSH: |
| 1938 | rc = ethtool_set_rxfh(dev, useraddr); |
| 1939 | break; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1940 | case ETHTOOL_GFEATURES: |
| 1941 | rc = ethtool_get_features(dev, useraddr); |
| 1942 | break; |
| 1943 | case ETHTOOL_SFEATURES: |
| 1944 | rc = ethtool_set_features(dev, useraddr); |
| 1945 | break; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1946 | case ETHTOOL_GTXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1947 | case ETHTOOL_GRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1948 | case ETHTOOL_GSG: |
| 1949 | case ETHTOOL_GTSO: |
| 1950 | case ETHTOOL_GUFO: |
| 1951 | case ETHTOOL_GGSO: |
| 1952 | case ETHTOOL_GGRO: |
| 1953 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); |
| 1954 | break; |
| 1955 | case ETHTOOL_STXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1956 | case ETHTOOL_SRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1957 | case ETHTOOL_SSG: |
| 1958 | case ETHTOOL_STSO: |
| 1959 | case ETHTOOL_SUFO: |
| 1960 | case ETHTOOL_SGSO: |
| 1961 | case ETHTOOL_SGRO: |
| 1962 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); |
| 1963 | break; |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1964 | case ETHTOOL_GCHANNELS: |
| 1965 | rc = ethtool_get_channels(dev, useraddr); |
| 1966 | break; |
| 1967 | case ETHTOOL_SCHANNELS: |
| 1968 | rc = ethtool_set_channels(dev, useraddr); |
| 1969 | break; |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1970 | case ETHTOOL_SET_DUMP: |
| 1971 | rc = ethtool_set_dump(dev, useraddr); |
| 1972 | break; |
| 1973 | case ETHTOOL_GET_DUMP_FLAG: |
| 1974 | rc = ethtool_get_dump_flag(dev, useraddr); |
| 1975 | break; |
| 1976 | case ETHTOOL_GET_DUMP_DATA: |
| 1977 | rc = ethtool_get_dump_data(dev, useraddr); |
| 1978 | break; |
Richard Cochran | c8f3a8c | 2012-04-03 22:59:17 +0000 | [diff] [blame] | 1979 | case ETHTOOL_GET_TS_INFO: |
| 1980 | rc = ethtool_get_ts_info(dev, useraddr); |
| 1981 | break; |
Stuart Hodgson | 41c3cb6 | 2012-04-19 09:44:42 +0100 | [diff] [blame] | 1982 | case ETHTOOL_GMODULEINFO: |
| 1983 | rc = ethtool_get_module_info(dev, useraddr); |
| 1984 | break; |
| 1985 | case ETHTOOL_GMODULEEEPROM: |
| 1986 | rc = ethtool_get_module_eeprom(dev, useraddr); |
| 1987 | break; |
Govindarajulu Varadarajan | f0db9b0 | 2014-09-03 03:17:20 +0530 | [diff] [blame] | 1988 | case ETHTOOL_GTUNABLE: |
| 1989 | rc = ethtool_get_tunable(dev, useraddr); |
| 1990 | break; |
| 1991 | case ETHTOOL_STUNABLE: |
| 1992 | rc = ethtool_set_tunable(dev, useraddr); |
| 1993 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | default: |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 1995 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | } |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1997 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1998 | if (dev->ethtool_ops->complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | dev->ethtool_ops->complete(dev); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 2000 | |
| 2001 | if (old_features != dev->features) |
| 2002 | netdev_features_change(dev); |
| 2003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | } |