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> |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 20 | #include <linux/bitops.h> |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
David S. Miller | 73da16c | 2010-09-21 16:12:11 -0700 | [diff] [blame] | 22 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 25 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Some useful ethtool_ops methods that're device independent. |
| 27 | * If we find that all drivers want to do the same thing here, |
| 28 | * we can turn these into dev_() function calls. |
| 29 | */ |
| 30 | |
| 31 | u32 ethtool_op_get_link(struct net_device *dev) |
| 32 | { |
| 33 | return netif_carrier_ok(dev) ? 1 : 0; |
| 34 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 35 | EXPORT_SYMBOL(ethtool_op_get_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | u32 ethtool_op_get_tx_csum(struct net_device *dev) |
| 38 | { |
Herbert Xu | 8648b30 | 2006-06-17 22:06:05 -0700 | [diff] [blame] | 39 | return (dev->features & NETIF_F_ALL_CSUM) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
Eric Dumazet | 8a729fc | 2009-07-26 23:18:11 +0000 | [diff] [blame] | 41 | EXPORT_SYMBOL(ethtool_op_get_tx_csum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | int ethtool_op_set_tx_csum(struct net_device *dev, u32 data) |
| 44 | { |
| 45 | if (data) |
| 46 | dev->features |= NETIF_F_IP_CSUM; |
| 47 | else |
| 48 | dev->features &= ~NETIF_F_IP_CSUM; |
| 49 | |
| 50 | return 0; |
| 51 | } |
Michał Mirosław | 9a279ea | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 52 | EXPORT_SYMBOL(ethtool_op_set_tx_csum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Jon Mason | 69f6a0f | 2005-05-29 20:27:24 -0700 | [diff] [blame] | 54 | int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data) |
| 55 | { |
| 56 | if (data) |
| 57 | dev->features |= NETIF_F_HW_CSUM; |
| 58 | else |
| 59 | dev->features &= ~NETIF_F_HW_CSUM; |
| 60 | |
| 61 | return 0; |
| 62 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 63 | EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum); |
Michael Chan | 6460d94 | 2007-07-14 19:07:52 -0700 | [diff] [blame] | 64 | |
| 65 | int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data) |
| 66 | { |
| 67 | if (data) |
| 68 | dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; |
| 69 | else |
| 70 | dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); |
| 71 | |
| 72 | return 0; |
| 73 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 74 | EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum); |
Michael Chan | 6460d94 | 2007-07-14 19:07:52 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | u32 ethtool_op_get_sg(struct net_device *dev) |
| 77 | { |
| 78 | return (dev->features & NETIF_F_SG) != 0; |
| 79 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 80 | EXPORT_SYMBOL(ethtool_op_get_sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | int ethtool_op_set_sg(struct net_device *dev, u32 data) |
| 83 | { |
| 84 | if (data) |
| 85 | dev->features |= NETIF_F_SG; |
| 86 | else |
| 87 | dev->features &= ~NETIF_F_SG; |
| 88 | |
| 89 | return 0; |
| 90 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 91 | EXPORT_SYMBOL(ethtool_op_set_sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | u32 ethtool_op_get_tso(struct net_device *dev) |
| 94 | { |
| 95 | return (dev->features & NETIF_F_TSO) != 0; |
| 96 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 97 | EXPORT_SYMBOL(ethtool_op_get_tso); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | int ethtool_op_set_tso(struct net_device *dev, u32 data) |
| 100 | { |
| 101 | if (data) |
| 102 | dev->features |= NETIF_F_TSO; |
| 103 | else |
| 104 | dev->features &= ~NETIF_F_TSO; |
| 105 | |
| 106 | return 0; |
| 107 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 108 | EXPORT_SYMBOL(ethtool_op_set_tso); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 110 | u32 ethtool_op_get_ufo(struct net_device *dev) |
| 111 | { |
| 112 | return (dev->features & NETIF_F_UFO) != 0; |
| 113 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 114 | EXPORT_SYMBOL(ethtool_op_get_ufo); |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 115 | |
| 116 | int ethtool_op_set_ufo(struct net_device *dev, u32 data) |
| 117 | { |
| 118 | if (data) |
| 119 | dev->features |= NETIF_F_UFO; |
| 120 | else |
| 121 | dev->features &= ~NETIF_F_UFO; |
| 122 | return 0; |
| 123 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 124 | EXPORT_SYMBOL(ethtool_op_set_ufo); |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 125 | |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 126 | /* the following list of flags are the same as their associated |
| 127 | * NETIF_F_xxx values in include/linux/netdevice.h |
| 128 | */ |
| 129 | static const u32 flags_dup_features = |
Jesse Gross | d5dbda2 | 2010-10-20 13:56:07 +0000 | [diff] [blame] | 130 | (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | ETH_FLAG_NTUPLE | |
| 131 | ETH_FLAG_RXHASH); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 132 | |
| 133 | u32 ethtool_op_get_flags(struct net_device *dev) |
| 134 | { |
| 135 | /* in the future, this function will probably contain additional |
| 136 | * handling for flags which are not so easily handled |
| 137 | * by a simple masking operation |
| 138 | */ |
| 139 | |
| 140 | return dev->features & flags_dup_features; |
| 141 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 142 | EXPORT_SYMBOL(ethtool_op_get_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 143 | |
Ben Hutchings | 1437ce3 | 2010-06-30 02:44:32 +0000 | [diff] [blame] | 144 | int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 145 | { |
Ben Hutchings | 1437ce3 | 2010-06-30 02:44:32 +0000 | [diff] [blame] | 146 | if (data & ~supported) |
| 147 | return -EINVAL; |
Peter Waskiewicz | 0d643e1 | 2010-02-12 13:48:25 +0000 | [diff] [blame] | 148 | |
Ben Hutchings | 1437ce3 | 2010-06-30 02:44:32 +0000 | [diff] [blame] | 149 | dev->features = ((dev->features & ~flags_dup_features) | |
| 150 | (data & flags_dup_features)); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 153 | EXPORT_SYMBOL(ethtool_op_set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 154 | |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 155 | void ethtool_ntuple_flush(struct net_device *dev) |
| 156 | { |
| 157 | struct ethtool_rx_ntuple_flow_spec_container *fsc, *f; |
| 158 | |
| 159 | list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) { |
| 160 | list_del(&fsc->list); |
| 161 | kfree(fsc); |
| 162 | } |
| 163 | dev->ethtool_ntuple_list.count = 0; |
| 164 | } |
| 165 | EXPORT_SYMBOL(ethtool_ntuple_flush); |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Handlers for each ethtool command */ |
| 168 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 169 | #define ETHTOOL_DEV_FEATURE_WORDS 1 |
| 170 | |
| 171 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
| 172 | { |
| 173 | struct ethtool_gfeatures cmd = { |
| 174 | .cmd = ETHTOOL_GFEATURES, |
| 175 | .size = ETHTOOL_DEV_FEATURE_WORDS, |
| 176 | }; |
| 177 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = { |
| 178 | { |
| 179 | .available = dev->hw_features, |
| 180 | .requested = dev->wanted_features, |
| 181 | .active = dev->features, |
| 182 | .never_changed = NETIF_F_NEVER_CHANGE, |
| 183 | }, |
| 184 | }; |
| 185 | u32 __user *sizeaddr; |
| 186 | u32 copy_size; |
| 187 | |
| 188 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); |
| 189 | if (get_user(copy_size, sizeaddr)) |
| 190 | return -EFAULT; |
| 191 | |
| 192 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) |
| 193 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; |
| 194 | |
| 195 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 196 | return -EFAULT; |
| 197 | useraddr += sizeof(cmd); |
| 198 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) |
| 199 | return -EFAULT; |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) |
| 205 | { |
| 206 | struct ethtool_sfeatures cmd; |
| 207 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
| 208 | int ret = 0; |
| 209 | |
| 210 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 211 | return -EFAULT; |
| 212 | useraddr += sizeof(cmd); |
| 213 | |
| 214 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) |
| 215 | return -EINVAL; |
| 216 | |
| 217 | if (copy_from_user(features, useraddr, sizeof(features))) |
| 218 | return -EFAULT; |
| 219 | |
| 220 | if (features[0].valid & ~NETIF_F_ETHTOOL_BITS) |
| 221 | return -EINVAL; |
| 222 | |
| 223 | if (features[0].valid & ~dev->hw_features) { |
| 224 | features[0].valid &= dev->hw_features; |
| 225 | ret |= ETHTOOL_F_UNSUPPORTED; |
| 226 | } |
| 227 | |
| 228 | dev->wanted_features &= ~features[0].valid; |
| 229 | dev->wanted_features |= features[0].valid & features[0].requested; |
| 230 | netdev_update_features(dev); |
| 231 | |
| 232 | if ((dev->wanted_features ^ dev->features) & features[0].valid) |
| 233 | ret |= ETHTOOL_F_WISH; |
| 234 | |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = { |
| 239 | /* NETIF_F_SG */ "tx-scatter-gather", |
| 240 | /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4", |
| 241 | /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded", |
| 242 | /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic", |
| 243 | /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6", |
| 244 | /* NETIF_F_HIGHDMA */ "highdma", |
| 245 | /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist", |
| 246 | /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert", |
| 247 | |
| 248 | /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse", |
| 249 | /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter", |
| 250 | /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged", |
| 251 | /* NETIF_F_GSO */ "tx-generic-segmentation", |
| 252 | /* NETIF_F_LLTX */ "tx-lockless", |
| 253 | /* NETIF_F_NETNS_LOCAL */ "netns-local", |
| 254 | /* NETIF_F_GRO */ "rx-gro", |
| 255 | /* NETIF_F_LRO */ "rx-lro", |
| 256 | |
| 257 | /* NETIF_F_TSO */ "tx-tcp-segmentation", |
| 258 | /* NETIF_F_UFO */ "tx-udp-fragmentation", |
| 259 | /* NETIF_F_GSO_ROBUST */ "tx-gso-robust", |
| 260 | /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation", |
| 261 | /* NETIF_F_TSO6 */ "tx-tcp6-segmentation", |
| 262 | /* NETIF_F_FSO */ "tx-fcoe-segmentation", |
| 263 | "", |
| 264 | "", |
| 265 | |
| 266 | /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc", |
| 267 | /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp", |
| 268 | /* NETIF_F_FCOE_MTU */ "fcoe-mtu", |
| 269 | /* NETIF_F_NTUPLE */ "rx-ntuple-filter", |
| 270 | /* NETIF_F_RXHASH */ "rx-hashing", |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 271 | /* NETIF_F_RXCSUM */ "rx-checksum", |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 272 | "", |
| 273 | "", |
| 274 | }; |
| 275 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 276 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
| 277 | { |
| 278 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 279 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 280 | if (sset == ETH_SS_FEATURES) |
| 281 | return ARRAY_SIZE(netdev_features_strings); |
| 282 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 283 | if (ops && ops->get_sset_count && ops->get_strings) |
| 284 | return ops->get_sset_count(dev, sset); |
| 285 | else |
| 286 | return -EOPNOTSUPP; |
| 287 | } |
| 288 | |
| 289 | static void __ethtool_get_strings(struct net_device *dev, |
| 290 | u32 stringset, u8 *data) |
| 291 | { |
| 292 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 293 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 294 | if (stringset == ETH_SS_FEATURES) |
| 295 | memcpy(data, netdev_features_strings, |
| 296 | sizeof(netdev_features_strings)); |
| 297 | else |
| 298 | /* ops->get_strings is valid because checked earlier */ |
| 299 | ops->get_strings(dev, stringset, data); |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 302 | static u32 ethtool_get_feature_mask(u32 eth_cmd) |
| 303 | { |
| 304 | /* feature masks of legacy discrete ethtool ops */ |
| 305 | |
| 306 | switch (eth_cmd) { |
| 307 | case ETHTOOL_GTXCSUM: |
| 308 | case ETHTOOL_STXCSUM: |
| 309 | return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM; |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 310 | case ETHTOOL_GRXCSUM: |
| 311 | case ETHTOOL_SRXCSUM: |
| 312 | return NETIF_F_RXCSUM; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 313 | case ETHTOOL_GSG: |
| 314 | case ETHTOOL_SSG: |
| 315 | return NETIF_F_SG; |
| 316 | case ETHTOOL_GTSO: |
| 317 | case ETHTOOL_STSO: |
| 318 | return NETIF_F_ALL_TSO; |
| 319 | case ETHTOOL_GUFO: |
| 320 | case ETHTOOL_SUFO: |
| 321 | return NETIF_F_UFO; |
| 322 | case ETHTOOL_GGSO: |
| 323 | case ETHTOOL_SGSO: |
| 324 | return NETIF_F_GSO; |
| 325 | case ETHTOOL_GGRO: |
| 326 | case ETHTOOL_SGRO: |
| 327 | return NETIF_F_GRO; |
| 328 | default: |
| 329 | BUG(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | static void *__ethtool_get_one_feature_actor(struct net_device *dev, u32 ethcmd) |
| 334 | { |
| 335 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 336 | |
| 337 | if (!ops) |
| 338 | return NULL; |
| 339 | |
| 340 | switch (ethcmd) { |
| 341 | case ETHTOOL_GTXCSUM: |
| 342 | return ops->get_tx_csum; |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 343 | case ETHTOOL_GRXCSUM: |
| 344 | return ops->get_rx_csum; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 345 | case ETHTOOL_SSG: |
| 346 | return ops->get_sg; |
| 347 | case ETHTOOL_STSO: |
| 348 | return ops->get_tso; |
| 349 | case ETHTOOL_SUFO: |
| 350 | return ops->get_ufo; |
| 351 | default: |
| 352 | return NULL; |
| 353 | } |
| 354 | } |
| 355 | |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 356 | static u32 __ethtool_get_rx_csum_oldbug(struct net_device *dev) |
| 357 | { |
| 358 | return !!(dev->features & NETIF_F_ALL_CSUM); |
| 359 | } |
| 360 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 361 | static int ethtool_get_one_feature(struct net_device *dev, |
| 362 | char __user *useraddr, u32 ethcmd) |
| 363 | { |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 364 | u32 mask = ethtool_get_feature_mask(ethcmd); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 365 | struct ethtool_value edata = { |
| 366 | .cmd = ethcmd, |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 367 | .data = !!(dev->features & mask), |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 368 | }; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 369 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 370 | /* compatibility with discrete get_ ops */ |
| 371 | if (!(dev->hw_features & mask)) { |
| 372 | u32 (*actor)(struct net_device *); |
| 373 | |
| 374 | actor = __ethtool_get_one_feature_actor(dev, ethcmd); |
| 375 | |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 376 | /* bug compatibility with old get_rx_csum */ |
| 377 | if (ethcmd == ETHTOOL_GRXCSUM && !actor) |
| 378 | actor = __ethtool_get_rx_csum_oldbug; |
| 379 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 380 | if (actor) |
| 381 | edata.data = actor(dev); |
| 382 | } |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 383 | |
| 384 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 385 | return -EFAULT; |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static int __ethtool_set_tx_csum(struct net_device *dev, u32 data); |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 390 | static int __ethtool_set_rx_csum(struct net_device *dev, u32 data); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 391 | static int __ethtool_set_sg(struct net_device *dev, u32 data); |
| 392 | static int __ethtool_set_tso(struct net_device *dev, u32 data); |
| 393 | static int __ethtool_set_ufo(struct net_device *dev, u32 data); |
| 394 | |
| 395 | static int ethtool_set_one_feature(struct net_device *dev, |
| 396 | void __user *useraddr, u32 ethcmd) |
| 397 | { |
| 398 | struct ethtool_value edata; |
| 399 | u32 mask; |
| 400 | |
| 401 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 402 | return -EFAULT; |
| 403 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 404 | mask = ethtool_get_feature_mask(ethcmd); |
| 405 | mask &= dev->hw_features; |
| 406 | if (mask) { |
| 407 | if (edata.data) |
| 408 | dev->wanted_features |= mask; |
| 409 | else |
| 410 | dev->wanted_features &= ~mask; |
| 411 | |
| 412 | netdev_update_features(dev); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | /* Driver is not converted to ndo_fix_features or does not |
| 417 | * support changing this offload. In the latter case it won't |
| 418 | * have corresponding ethtool_ops field set. |
| 419 | * |
| 420 | * Following part is to be removed after all drivers advertise |
| 421 | * their changeable features in netdev->hw_features and stop |
| 422 | * using discrete offload setting ops. |
| 423 | */ |
| 424 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 425 | switch (ethcmd) { |
| 426 | case ETHTOOL_STXCSUM: |
| 427 | return __ethtool_set_tx_csum(dev, edata.data); |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 428 | case ETHTOOL_SRXCSUM: |
| 429 | return __ethtool_set_rx_csum(dev, edata.data); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 430 | case ETHTOOL_SSG: |
| 431 | return __ethtool_set_sg(dev, edata.data); |
| 432 | case ETHTOOL_STSO: |
| 433 | return __ethtool_set_tso(dev, edata.data); |
| 434 | case ETHTOOL_SUFO: |
| 435 | return __ethtool_set_ufo(dev, edata.data); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 436 | default: |
| 437 | return -EOPNOTSUPP; |
| 438 | } |
| 439 | } |
| 440 | |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 441 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
| 442 | { |
| 443 | u32 changed; |
| 444 | |
| 445 | if (data & ~flags_dup_features) |
| 446 | return -EINVAL; |
| 447 | |
| 448 | /* legacy set_flags() op */ |
| 449 | if (dev->ethtool_ops->set_flags) { |
| 450 | if (unlikely(dev->hw_features & flags_dup_features)) |
| 451 | netdev_warn(dev, |
| 452 | "driver BUG: mixed hw_features and set_flags()\n"); |
| 453 | return dev->ethtool_ops->set_flags(dev, data); |
| 454 | } |
| 455 | |
| 456 | /* allow changing only bits set in hw_features */ |
| 457 | changed = (data ^ dev->wanted_features) & flags_dup_features; |
| 458 | if (changed & ~dev->hw_features) |
| 459 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; |
| 460 | |
| 461 | dev->wanted_features = |
| 462 | (dev->wanted_features & ~changed) | data; |
| 463 | |
| 464 | netdev_update_features(dev); |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
| 470 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 471 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | int err; |
| 473 | |
| 474 | if (!dev->ethtool_ops->get_settings) |
| 475 | return -EOPNOTSUPP; |
| 476 | |
| 477 | err = dev->ethtool_ops->get_settings(dev, &cmd); |
| 478 | if (err < 0) |
| 479 | return err; |
| 480 | |
| 481 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 482 | return -EFAULT; |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
| 487 | { |
| 488 | struct ethtool_cmd cmd; |
| 489 | |
| 490 | if (!dev->ethtool_ops->set_settings) |
| 491 | return -EOPNOTSUPP; |
| 492 | |
| 493 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 494 | return -EFAULT; |
| 495 | |
| 496 | return dev->ethtool_ops->set_settings(dev, &cmd); |
| 497 | } |
| 498 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 499 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
| 500 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
| 502 | struct ethtool_drvinfo info; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 503 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | memset(&info, 0, sizeof(info)); |
| 506 | info.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 507 | if (ops && ops->get_drvinfo) { |
| 508 | ops->get_drvinfo(dev, &info); |
| 509 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
| 510 | strlcpy(info.bus_info, dev_name(dev->dev.parent), |
| 511 | sizeof(info.bus_info)); |
| 512 | strlcpy(info.driver, dev->dev.parent->driver->name, |
| 513 | sizeof(info.driver)); |
| 514 | } else { |
| 515 | return -EOPNOTSUPP; |
| 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 518 | /* |
| 519 | * this method of obtaining string set info is deprecated; |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 520 | * Use ETHTOOL_GSSET_INFO instead. |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 521 | */ |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 522 | if (ops && ops->get_sset_count) { |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 523 | int rc; |
| 524 | |
| 525 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
| 526 | if (rc >= 0) |
| 527 | info.testinfo_len = rc; |
| 528 | rc = ops->get_sset_count(dev, ETH_SS_STATS); |
| 529 | if (rc >= 0) |
| 530 | info.n_stats = rc; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 531 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
| 532 | if (rc >= 0) |
| 533 | info.n_priv_flags = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 534 | } |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 535 | if (ops && ops->get_regs_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | info.regdump_len = ops->get_regs_len(dev); |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 537 | if (ops && ops->get_eeprom_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | info.eedump_len = ops->get_eeprom_len(dev); |
| 539 | |
| 540 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 541 | return -EFAULT; |
| 542 | return 0; |
| 543 | } |
| 544 | |
Eric Dumazet | f5c445e | 2010-03-08 12:17:04 -0800 | [diff] [blame] | 545 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 546 | void __user *useraddr) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 547 | { |
| 548 | struct ethtool_sset_info info; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 549 | u64 sset_mask; |
| 550 | int i, idx = 0, n_bits = 0, ret, rc; |
| 551 | u32 *info_buf = NULL; |
| 552 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 553 | if (copy_from_user(&info, useraddr, sizeof(info))) |
| 554 | return -EFAULT; |
| 555 | |
| 556 | /* store copy of mask, because we zero struct later on */ |
| 557 | sset_mask = info.sset_mask; |
| 558 | if (!sset_mask) |
| 559 | return 0; |
| 560 | |
| 561 | /* calculate size of return buffer */ |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 562 | n_bits = hweight64(sset_mask); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 563 | |
| 564 | memset(&info, 0, sizeof(info)); |
| 565 | info.cmd = ETHTOOL_GSSET_INFO; |
| 566 | |
| 567 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); |
| 568 | if (!info_buf) |
| 569 | return -ENOMEM; |
| 570 | |
| 571 | /* |
| 572 | * fill return buffer based on input bitmask and successful |
| 573 | * get_sset_count return |
| 574 | */ |
| 575 | for (i = 0; i < 64; i++) { |
| 576 | if (!(sset_mask & (1ULL << i))) |
| 577 | continue; |
| 578 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 579 | rc = __ethtool_get_sset_count(dev, i); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 580 | if (rc >= 0) { |
| 581 | info.sset_mask |= (1ULL << i); |
| 582 | info_buf[idx++] = rc; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | ret = -EFAULT; |
| 587 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 588 | goto out; |
| 589 | |
| 590 | useraddr += offsetof(struct ethtool_sset_info, data); |
| 591 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) |
| 592 | goto out; |
| 593 | |
| 594 | ret = 0; |
| 595 | |
| 596 | out: |
| 597 | kfree(info_buf); |
| 598 | return ret; |
| 599 | } |
| 600 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 601 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 602 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 603 | { |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 604 | struct ethtool_rxnfc info; |
| 605 | size_t info_size = sizeof(info); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 606 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 607 | if (!dev->ethtool_ops->set_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 608 | return -EOPNOTSUPP; |
| 609 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 610 | /* struct ethtool_rxnfc was originally defined for |
| 611 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 612 | * members. User-space might still be using that |
| 613 | * definition. */ |
| 614 | if (cmd == ETHTOOL_SRXFH) |
| 615 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 616 | sizeof(info.data)); |
| 617 | |
| 618 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 619 | return -EFAULT; |
| 620 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 621 | return dev->ethtool_ops->set_rxnfc(dev, &info); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 622 | } |
| 623 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 624 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 625 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 626 | { |
| 627 | struct ethtool_rxnfc info; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 628 | size_t info_size = sizeof(info); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 629 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 630 | int ret; |
| 631 | void *rule_buf = NULL; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 632 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 633 | if (!ops->get_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 634 | return -EOPNOTSUPP; |
| 635 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 636 | /* struct ethtool_rxnfc was originally defined for |
| 637 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 638 | * members. User-space might still be using that |
| 639 | * definition. */ |
| 640 | if (cmd == ETHTOOL_GRXFH) |
| 641 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 642 | sizeof(info.data)); |
| 643 | |
| 644 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 645 | return -EFAULT; |
| 646 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 647 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
| 648 | if (info.rule_cnt > 0) { |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 649 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
Kees Cook | ae6df5f | 2010-10-07 10:03:48 +0000 | [diff] [blame] | 650 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 651 | GFP_USER); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 652 | if (!rule_buf) |
| 653 | return -ENOMEM; |
| 654 | } |
| 655 | } |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 656 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 657 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
| 658 | if (ret < 0) |
| 659 | goto err_out; |
| 660 | |
| 661 | ret = -EFAULT; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 662 | if (copy_to_user(useraddr, &info, info_size)) |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 663 | goto err_out; |
| 664 | |
| 665 | if (rule_buf) { |
| 666 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); |
| 667 | if (copy_to_user(useraddr, rule_buf, |
| 668 | info.rule_cnt * sizeof(u32))) |
| 669 | goto err_out; |
| 670 | } |
| 671 | ret = 0; |
| 672 | |
| 673 | err_out: |
Wei Yongjun | c9cacec | 2009-03-31 15:06:26 -0700 | [diff] [blame] | 674 | kfree(rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 675 | |
| 676 | return ret; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 679 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
| 680 | void __user *useraddr) |
| 681 | { |
| 682 | struct ethtool_rxfh_indir *indir; |
| 683 | u32 table_size; |
| 684 | size_t full_size; |
| 685 | int ret; |
| 686 | |
| 687 | if (!dev->ethtool_ops->get_rxfh_indir) |
| 688 | return -EOPNOTSUPP; |
| 689 | |
| 690 | if (copy_from_user(&table_size, |
| 691 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 692 | sizeof(table_size))) |
| 693 | return -EFAULT; |
| 694 | |
| 695 | if (table_size > |
| 696 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) |
| 697 | return -ENOMEM; |
| 698 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; |
Kees Cook | b00916b | 2010-10-11 12:23:25 -0700 | [diff] [blame] | 699 | indir = kzalloc(full_size, GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 700 | if (!indir) |
| 701 | return -ENOMEM; |
| 702 | |
| 703 | indir->cmd = ETHTOOL_GRXFHINDIR; |
| 704 | indir->size = table_size; |
| 705 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); |
| 706 | if (ret) |
| 707 | goto out; |
| 708 | |
| 709 | if (copy_to_user(useraddr, indir, full_size)) |
| 710 | ret = -EFAULT; |
| 711 | |
| 712 | out: |
| 713 | kfree(indir); |
| 714 | return ret; |
| 715 | } |
| 716 | |
| 717 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, |
| 718 | void __user *useraddr) |
| 719 | { |
| 720 | struct ethtool_rxfh_indir *indir; |
| 721 | u32 table_size; |
| 722 | size_t full_size; |
| 723 | int ret; |
| 724 | |
| 725 | if (!dev->ethtool_ops->set_rxfh_indir) |
| 726 | return -EOPNOTSUPP; |
| 727 | |
| 728 | if (copy_from_user(&table_size, |
| 729 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 730 | sizeof(table_size))) |
| 731 | return -EFAULT; |
| 732 | |
| 733 | if (table_size > |
| 734 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) |
| 735 | return -ENOMEM; |
| 736 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; |
| 737 | indir = kmalloc(full_size, GFP_USER); |
| 738 | if (!indir) |
| 739 | return -ENOMEM; |
| 740 | |
| 741 | if (copy_from_user(indir, useraddr, full_size)) { |
| 742 | ret = -EFAULT; |
| 743 | goto out; |
| 744 | } |
| 745 | |
| 746 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); |
| 747 | |
| 748 | out: |
| 749 | kfree(indir); |
| 750 | return ret; |
| 751 | } |
| 752 | |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 753 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 754 | struct ethtool_rx_ntuple_flow_spec *spec, |
| 755 | struct ethtool_rx_ntuple_flow_spec_container *fsc) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 756 | { |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 757 | |
| 758 | /* don't add filters forever */ |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 759 | if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) { |
| 760 | /* free the container */ |
| 761 | kfree(fsc); |
| 762 | return; |
| 763 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 764 | |
| 765 | /* Copy the whole filter over */ |
| 766 | fsc->fs.flow_type = spec->flow_type; |
| 767 | memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u)); |
| 768 | memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u)); |
| 769 | |
| 770 | fsc->fs.vlan_tag = spec->vlan_tag; |
| 771 | fsc->fs.vlan_tag_mask = spec->vlan_tag_mask; |
| 772 | fsc->fs.data = spec->data; |
| 773 | fsc->fs.data_mask = spec->data_mask; |
| 774 | fsc->fs.action = spec->action; |
| 775 | |
| 776 | /* add to the list */ |
| 777 | list_add_tail_rcu(&fsc->list, &list->list); |
| 778 | list->count++; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Ben Hutchings | be2902d | 2010-09-16 11:28:07 +0000 | [diff] [blame] | 781 | /* |
| 782 | * ethtool does not (or did not) set masks for flow parameters that are |
| 783 | * not specified, so if both value and mask are 0 then this must be |
| 784 | * treated as equivalent to a mask with all bits set. Implement that |
| 785 | * here rather than in drivers. |
| 786 | */ |
| 787 | static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs) |
| 788 | { |
| 789 | struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec; |
| 790 | struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec; |
| 791 | |
| 792 | if (fs->flow_type != TCP_V4_FLOW && |
| 793 | fs->flow_type != UDP_V4_FLOW && |
| 794 | fs->flow_type != SCTP_V4_FLOW) |
| 795 | return; |
| 796 | |
| 797 | if (!(entry->ip4src | mask->ip4src)) |
| 798 | mask->ip4src = htonl(0xffffffff); |
| 799 | if (!(entry->ip4dst | mask->ip4dst)) |
| 800 | mask->ip4dst = htonl(0xffffffff); |
| 801 | if (!(entry->psrc | mask->psrc)) |
| 802 | mask->psrc = htons(0xffff); |
| 803 | if (!(entry->pdst | mask->pdst)) |
| 804 | mask->pdst = htons(0xffff); |
| 805 | if (!(entry->tos | mask->tos)) |
| 806 | mask->tos = 0xff; |
| 807 | if (!(fs->vlan_tag | fs->vlan_tag_mask)) |
| 808 | fs->vlan_tag_mask = 0xffff; |
| 809 | if (!(fs->data | fs->data_mask)) |
| 810 | fs->data_mask = 0xffffffffffffffffULL; |
| 811 | } |
| 812 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 813 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
| 814 | void __user *useraddr) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 815 | { |
| 816 | struct ethtool_rx_ntuple cmd; |
| 817 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 818 | struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 819 | int ret; |
| 820 | |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 821 | if (!(dev->features & NETIF_F_NTUPLE)) |
| 822 | return -EINVAL; |
| 823 | |
| 824 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 825 | return -EFAULT; |
| 826 | |
Ben Hutchings | be2902d | 2010-09-16 11:28:07 +0000 | [diff] [blame] | 827 | rx_ntuple_fix_masks(&cmd.fs); |
| 828 | |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 829 | /* |
| 830 | * Cache filter in dev struct for GET operation only if |
| 831 | * the underlying driver doesn't have its own GET operation, and |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 832 | * only if the filter was added successfully. First make sure we |
| 833 | * can allocate the filter, then continue if successful. |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 834 | */ |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 835 | if (!ops->get_rx_ntuple) { |
| 836 | fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); |
| 837 | if (!fsc) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 838 | return -ENOMEM; |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | ret = ops->set_rx_ntuple(dev, &cmd); |
| 842 | if (ret) { |
| 843 | kfree(fsc); |
| 844 | return ret; |
| 845 | } |
| 846 | |
| 847 | if (!ops->get_rx_ntuple) |
| 848 | __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 849 | |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) |
| 854 | { |
| 855 | struct ethtool_gstrings gstrings; |
| 856 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 857 | struct ethtool_rx_ntuple_flow_spec_container *fsc; |
| 858 | u8 *data; |
| 859 | char *p; |
| 860 | int ret, i, num_strings = 0; |
| 861 | |
| 862 | if (!ops->get_sset_count) |
| 863 | return -EOPNOTSUPP; |
| 864 | |
| 865 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 866 | return -EFAULT; |
| 867 | |
| 868 | ret = ops->get_sset_count(dev, gstrings.string_set); |
| 869 | if (ret < 0) |
| 870 | return ret; |
| 871 | |
| 872 | gstrings.len = ret; |
| 873 | |
Kees Cook | b00916b | 2010-10-11 12:23:25 -0700 | [diff] [blame] | 874 | data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 875 | if (!data) |
| 876 | return -ENOMEM; |
| 877 | |
| 878 | if (ops->get_rx_ntuple) { |
| 879 | /* driver-specific filter grab */ |
| 880 | ret = ops->get_rx_ntuple(dev, gstrings.string_set, data); |
| 881 | goto copy; |
| 882 | } |
| 883 | |
| 884 | /* default ethtool filter grab */ |
| 885 | i = 0; |
| 886 | p = (char *)data; |
| 887 | list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) { |
| 888 | sprintf(p, "Filter %d:\n", i); |
| 889 | p += ETH_GSTRING_LEN; |
| 890 | num_strings++; |
| 891 | |
| 892 | switch (fsc->fs.flow_type) { |
| 893 | case TCP_V4_FLOW: |
| 894 | sprintf(p, "\tFlow Type: TCP\n"); |
| 895 | p += ETH_GSTRING_LEN; |
| 896 | num_strings++; |
| 897 | break; |
| 898 | case UDP_V4_FLOW: |
| 899 | sprintf(p, "\tFlow Type: UDP\n"); |
| 900 | p += ETH_GSTRING_LEN; |
| 901 | num_strings++; |
| 902 | break; |
| 903 | case SCTP_V4_FLOW: |
| 904 | sprintf(p, "\tFlow Type: SCTP\n"); |
| 905 | p += ETH_GSTRING_LEN; |
| 906 | num_strings++; |
| 907 | break; |
| 908 | case AH_ESP_V4_FLOW: |
| 909 | sprintf(p, "\tFlow Type: AH ESP\n"); |
| 910 | p += ETH_GSTRING_LEN; |
| 911 | num_strings++; |
| 912 | break; |
| 913 | case ESP_V4_FLOW: |
| 914 | sprintf(p, "\tFlow Type: ESP\n"); |
| 915 | p += ETH_GSTRING_LEN; |
| 916 | num_strings++; |
| 917 | break; |
| 918 | case IP_USER_FLOW: |
| 919 | sprintf(p, "\tFlow Type: Raw IP\n"); |
| 920 | p += ETH_GSTRING_LEN; |
| 921 | num_strings++; |
| 922 | break; |
| 923 | case IPV4_FLOW: |
| 924 | sprintf(p, "\tFlow Type: IPv4\n"); |
| 925 | p += ETH_GSTRING_LEN; |
| 926 | num_strings++; |
| 927 | break; |
| 928 | default: |
| 929 | sprintf(p, "\tFlow Type: Unknown\n"); |
| 930 | p += ETH_GSTRING_LEN; |
| 931 | num_strings++; |
| 932 | goto unknown_filter; |
Joe Perches | ccbd6a5 | 2010-05-14 10:58:26 +0000 | [diff] [blame] | 933 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 934 | |
| 935 | /* now the rest of the filters */ |
| 936 | switch (fsc->fs.flow_type) { |
| 937 | case TCP_V4_FLOW: |
| 938 | case UDP_V4_FLOW: |
| 939 | case SCTP_V4_FLOW: |
| 940 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 941 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 942 | p += ETH_GSTRING_LEN; |
| 943 | num_strings++; |
| 944 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 945 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 946 | p += ETH_GSTRING_LEN; |
| 947 | num_strings++; |
| 948 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 949 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 950 | p += ETH_GSTRING_LEN; |
| 951 | num_strings++; |
| 952 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 953 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 954 | p += ETH_GSTRING_LEN; |
| 955 | num_strings++; |
| 956 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 957 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
| 958 | fsc->fs.m_u.tcp_ip4_spec.psrc); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 959 | p += ETH_GSTRING_LEN; |
| 960 | num_strings++; |
| 961 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 962 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
| 963 | fsc->fs.m_u.tcp_ip4_spec.pdst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 964 | p += ETH_GSTRING_LEN; |
| 965 | num_strings++; |
| 966 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 967 | fsc->fs.h_u.tcp_ip4_spec.tos, |
| 968 | fsc->fs.m_u.tcp_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 969 | p += ETH_GSTRING_LEN; |
| 970 | num_strings++; |
| 971 | break; |
| 972 | case AH_ESP_V4_FLOW: |
| 973 | case ESP_V4_FLOW: |
| 974 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 975 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 976 | p += ETH_GSTRING_LEN; |
| 977 | num_strings++; |
| 978 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 979 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 980 | p += ETH_GSTRING_LEN; |
| 981 | num_strings++; |
| 982 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 983 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 984 | p += ETH_GSTRING_LEN; |
| 985 | num_strings++; |
| 986 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 987 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 988 | p += ETH_GSTRING_LEN; |
| 989 | num_strings++; |
| 990 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 991 | fsc->fs.h_u.ah_ip4_spec.spi, |
| 992 | fsc->fs.m_u.ah_ip4_spec.spi); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 993 | p += ETH_GSTRING_LEN; |
| 994 | num_strings++; |
| 995 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 996 | fsc->fs.h_u.ah_ip4_spec.tos, |
| 997 | fsc->fs.m_u.ah_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 998 | p += ETH_GSTRING_LEN; |
| 999 | num_strings++; |
| 1000 | break; |
| 1001 | case IP_USER_FLOW: |
| 1002 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 1003 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1004 | p += ETH_GSTRING_LEN; |
| 1005 | num_strings++; |
| 1006 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 1007 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1008 | p += ETH_GSTRING_LEN; |
| 1009 | num_strings++; |
| 1010 | sprintf(p, "\tDest IP addr: 0x%x\n", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 1011 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1012 | p += ETH_GSTRING_LEN; |
| 1013 | num_strings++; |
| 1014 | sprintf(p, "\tDest IP mask: 0x%x\n", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 1015 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1016 | p += ETH_GSTRING_LEN; |
| 1017 | num_strings++; |
| 1018 | break; |
| 1019 | case IPV4_FLOW: |
| 1020 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1021 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1022 | p += ETH_GSTRING_LEN; |
| 1023 | num_strings++; |
| 1024 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1025 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1026 | p += ETH_GSTRING_LEN; |
| 1027 | num_strings++; |
| 1028 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1029 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1030 | p += ETH_GSTRING_LEN; |
| 1031 | num_strings++; |
| 1032 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1033 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1034 | p += ETH_GSTRING_LEN; |
| 1035 | num_strings++; |
| 1036 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1037 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
| 1038 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1039 | p += ETH_GSTRING_LEN; |
| 1040 | num_strings++; |
| 1041 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1042 | fsc->fs.h_u.usr_ip4_spec.tos, |
| 1043 | fsc->fs.m_u.usr_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1044 | p += ETH_GSTRING_LEN; |
| 1045 | num_strings++; |
| 1046 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1047 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
| 1048 | fsc->fs.m_u.usr_ip4_spec.ip_ver); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1049 | p += ETH_GSTRING_LEN; |
| 1050 | num_strings++; |
| 1051 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1052 | fsc->fs.h_u.usr_ip4_spec.proto, |
| 1053 | fsc->fs.m_u.usr_ip4_spec.proto); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1054 | p += ETH_GSTRING_LEN; |
| 1055 | num_strings++; |
| 1056 | break; |
Joe Perches | ccbd6a5 | 2010-05-14 10:58:26 +0000 | [diff] [blame] | 1057 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1058 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1059 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1060 | p += ETH_GSTRING_LEN; |
| 1061 | num_strings++; |
| 1062 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); |
| 1063 | p += ETH_GSTRING_LEN; |
| 1064 | num_strings++; |
| 1065 | sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask); |
| 1066 | p += ETH_GSTRING_LEN; |
| 1067 | num_strings++; |
| 1068 | if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) |
| 1069 | sprintf(p, "\tAction: Drop\n"); |
| 1070 | else |
| 1071 | sprintf(p, "\tAction: Direct to queue %d\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1072 | fsc->fs.action); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1073 | p += ETH_GSTRING_LEN; |
| 1074 | num_strings++; |
| 1075 | unknown_filter: |
| 1076 | i++; |
| 1077 | } |
| 1078 | copy: |
| 1079 | /* indicate to userspace how many strings we actually have */ |
| 1080 | gstrings.len = num_strings; |
| 1081 | ret = -EFAULT; |
| 1082 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1083 | goto out; |
| 1084 | useraddr += sizeof(gstrings); |
| 1085 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1086 | goto out; |
| 1087 | ret = 0; |
| 1088 | |
| 1089 | out: |
| 1090 | kfree(data); |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
| 1095 | { |
| 1096 | struct ethtool_regs regs; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1097 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | void *regbuf; |
| 1099 | int reglen, ret; |
| 1100 | |
| 1101 | if (!ops->get_regs || !ops->get_regs_len) |
| 1102 | return -EOPNOTSUPP; |
| 1103 | |
| 1104 | if (copy_from_user(®s, useraddr, sizeof(regs))) |
| 1105 | return -EFAULT; |
| 1106 | |
| 1107 | reglen = ops->get_regs_len(dev); |
| 1108 | if (regs.len > reglen) |
| 1109 | regs.len = reglen; |
| 1110 | |
Eugene Teo | b7c7d01 | 2011-01-24 21:05:17 -0800 | [diff] [blame] | 1111 | regbuf = vzalloc(reglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | if (!regbuf) |
| 1113 | return -ENOMEM; |
| 1114 | |
| 1115 | ops->get_regs(dev, ®s, regbuf); |
| 1116 | |
| 1117 | ret = -EFAULT; |
| 1118 | if (copy_to_user(useraddr, ®s, sizeof(regs))) |
| 1119 | goto out; |
| 1120 | useraddr += offsetof(struct ethtool_regs, data); |
| 1121 | if (copy_to_user(useraddr, regbuf, regs.len)) |
| 1122 | goto out; |
| 1123 | ret = 0; |
| 1124 | |
| 1125 | out: |
Ben Hutchings | a77f5db | 2010-09-20 08:42:17 +0000 | [diff] [blame] | 1126 | vfree(regbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | return ret; |
| 1128 | } |
| 1129 | |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1130 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
| 1131 | { |
| 1132 | struct ethtool_value reset; |
| 1133 | int ret; |
| 1134 | |
| 1135 | if (!dev->ethtool_ops->reset) |
| 1136 | return -EOPNOTSUPP; |
| 1137 | |
| 1138 | if (copy_from_user(&reset, useraddr, sizeof(reset))) |
| 1139 | return -EFAULT; |
| 1140 | |
| 1141 | ret = dev->ethtool_ops->reset(dev, &reset.data); |
| 1142 | if (ret) |
| 1143 | return ret; |
| 1144 | |
| 1145 | if (copy_to_user(useraddr, &reset, sizeof(reset))) |
| 1146 | return -EFAULT; |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
| 1151 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1152 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
| 1154 | if (!dev->ethtool_ops->get_wol) |
| 1155 | return -EOPNOTSUPP; |
| 1156 | |
| 1157 | dev->ethtool_ops->get_wol(dev, &wol); |
| 1158 | |
| 1159 | if (copy_to_user(useraddr, &wol, sizeof(wol))) |
| 1160 | return -EFAULT; |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) |
| 1165 | { |
| 1166 | struct ethtool_wolinfo wol; |
| 1167 | |
| 1168 | if (!dev->ethtool_ops->set_wol) |
| 1169 | return -EOPNOTSUPP; |
| 1170 | |
| 1171 | if (copy_from_user(&wol, useraddr, sizeof(wol))) |
| 1172 | return -EFAULT; |
| 1173 | |
| 1174 | return dev->ethtool_ops->set_wol(dev, &wol); |
| 1175 | } |
| 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | static int ethtool_nway_reset(struct net_device *dev) |
| 1178 | { |
| 1179 | if (!dev->ethtool_ops->nway_reset) |
| 1180 | return -EOPNOTSUPP; |
| 1181 | |
| 1182 | return dev->ethtool_ops->nway_reset(dev); |
| 1183 | } |
| 1184 | |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1185 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
| 1186 | { |
| 1187 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; |
| 1188 | |
| 1189 | if (!dev->ethtool_ops->get_link) |
| 1190 | return -EOPNOTSUPP; |
| 1191 | |
| 1192 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); |
| 1193 | |
| 1194 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1195 | return -EFAULT; |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
| 1200 | { |
| 1201 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1202 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1203 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1204 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1206 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
| 1208 | if (!ops->get_eeprom || !ops->get_eeprom_len) |
| 1209 | return -EOPNOTSUPP; |
| 1210 | |
| 1211 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1212 | return -EFAULT; |
| 1213 | |
| 1214 | /* Check for wrap and zero */ |
| 1215 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | /* Check for exceeding total eeprom len */ |
| 1219 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1220 | return -EINVAL; |
| 1221 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1222 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | if (!data) |
| 1224 | return -ENOMEM; |
| 1225 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1226 | bytes_remaining = eeprom.len; |
| 1227 | while (bytes_remaining > 0) { |
| 1228 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1230 | ret = ops->get_eeprom(dev, &eeprom, data); |
| 1231 | if (ret) |
| 1232 | break; |
| 1233 | if (copy_to_user(userbuf, data, eeprom.len)) { |
| 1234 | ret = -EFAULT; |
| 1235 | break; |
| 1236 | } |
| 1237 | userbuf += eeprom.len; |
| 1238 | eeprom.offset += eeprom.len; |
| 1239 | bytes_remaining -= eeprom.len; |
| 1240 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Mandeep Singh Baines | c5835df | 2008-04-24 20:55:56 -0700 | [diff] [blame] | 1242 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
| 1243 | eeprom.offset -= eeprom.len; |
| 1244 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) |
| 1245 | ret = -EFAULT; |
| 1246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | kfree(data); |
| 1248 | return ret; |
| 1249 | } |
| 1250 | |
| 1251 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
| 1252 | { |
| 1253 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1254 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1255 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1256 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1258 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | if (!ops->set_eeprom || !ops->get_eeprom_len) |
| 1261 | return -EOPNOTSUPP; |
| 1262 | |
| 1263 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1264 | return -EFAULT; |
| 1265 | |
| 1266 | /* Check for wrap and zero */ |
| 1267 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1268 | return -EINVAL; |
| 1269 | |
| 1270 | /* Check for exceeding total eeprom len */ |
| 1271 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1272 | return -EINVAL; |
| 1273 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1274 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | if (!data) |
| 1276 | return -ENOMEM; |
| 1277 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1278 | bytes_remaining = eeprom.len; |
| 1279 | while (bytes_remaining > 0) { |
| 1280 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1282 | if (copy_from_user(data, userbuf, eeprom.len)) { |
| 1283 | ret = -EFAULT; |
| 1284 | break; |
| 1285 | } |
| 1286 | ret = ops->set_eeprom(dev, &eeprom, data); |
| 1287 | if (ret) |
| 1288 | break; |
| 1289 | userbuf += eeprom.len; |
| 1290 | eeprom.offset += eeprom.len; |
| 1291 | bytes_remaining -= eeprom.len; |
| 1292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | kfree(data); |
| 1295 | return ret; |
| 1296 | } |
| 1297 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1298 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
| 1299 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1301 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (!dev->ethtool_ops->get_coalesce) |
| 1304 | return -EOPNOTSUPP; |
| 1305 | |
| 1306 | dev->ethtool_ops->get_coalesce(dev, &coalesce); |
| 1307 | |
| 1308 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 1309 | return -EFAULT; |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1313 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
| 1314 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | { |
| 1316 | struct ethtool_coalesce coalesce; |
| 1317 | |
David S. Miller | fa04ae5 | 2005-06-06 15:07:19 -0700 | [diff] [blame] | 1318 | if (!dev->ethtool_ops->set_coalesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | return -EOPNOTSUPP; |
| 1320 | |
| 1321 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) |
| 1322 | return -EFAULT; |
| 1323 | |
| 1324 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); |
| 1325 | } |
| 1326 | |
| 1327 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) |
| 1328 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1329 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | |
| 1331 | if (!dev->ethtool_ops->get_ringparam) |
| 1332 | return -EOPNOTSUPP; |
| 1333 | |
| 1334 | dev->ethtool_ops->get_ringparam(dev, &ringparam); |
| 1335 | |
| 1336 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) |
| 1337 | return -EFAULT; |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) |
| 1342 | { |
| 1343 | struct ethtool_ringparam ringparam; |
| 1344 | |
| 1345 | if (!dev->ethtool_ops->set_ringparam) |
| 1346 | return -EOPNOTSUPP; |
| 1347 | |
| 1348 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) |
| 1349 | return -EFAULT; |
| 1350 | |
| 1351 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); |
| 1352 | } |
| 1353 | |
| 1354 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1355 | { |
| 1356 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; |
| 1357 | |
| 1358 | if (!dev->ethtool_ops->get_pauseparam) |
| 1359 | return -EOPNOTSUPP; |
| 1360 | |
| 1361 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); |
| 1362 | |
| 1363 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) |
| 1364 | return -EFAULT; |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1369 | { |
| 1370 | struct ethtool_pauseparam pauseparam; |
| 1371 | |
Jeff Garzik | e1b90c4 | 2006-07-17 12:54:40 -0400 | [diff] [blame] | 1372 | if (!dev->ethtool_ops->set_pauseparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | return -EOPNOTSUPP; |
| 1374 | |
| 1375 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) |
| 1376 | return -EFAULT; |
| 1377 | |
| 1378 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); |
| 1379 | } |
| 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | static int __ethtool_set_sg(struct net_device *dev, u32 data) |
| 1382 | { |
| 1383 | int err; |
| 1384 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1385 | if (data && !(dev->features & NETIF_F_ALL_CSUM)) |
| 1386 | return -EINVAL; |
| 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | if (!data && dev->ethtool_ops->set_tso) { |
| 1389 | err = dev->ethtool_ops->set_tso(dev, 0); |
| 1390 | if (err) |
| 1391 | return err; |
| 1392 | } |
| 1393 | |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1394 | if (!data && dev->ethtool_ops->set_ufo) { |
| 1395 | err = dev->ethtool_ops->set_ufo(dev, 0); |
| 1396 | if (err) |
| 1397 | return err; |
| 1398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | return dev->ethtool_ops->set_sg(dev, data); |
| 1400 | } |
| 1401 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1402 | static int __ethtool_set_tx_csum(struct net_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | int err; |
| 1405 | |
| 1406 | if (!dev->ethtool_ops->set_tx_csum) |
| 1407 | return -EOPNOTSUPP; |
| 1408 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1409 | if (!data && dev->ethtool_ops->set_sg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | err = __ethtool_set_sg(dev, 0); |
| 1411 | if (err) |
| 1412 | return err; |
| 1413 | } |
| 1414 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1415 | return dev->ethtool_ops->set_tx_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 1418 | static int __ethtool_set_rx_csum(struct net_device *dev, u32 data) |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1419 | { |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1420 | if (!dev->ethtool_ops->set_rx_csum) |
| 1421 | return -EOPNOTSUPP; |
| 1422 | |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 1423 | if (!data) |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1424 | dev->features &= ~NETIF_F_GRO; |
| 1425 | |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 1426 | return dev->ethtool_ops->set_rx_csum(dev, data); |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1429 | static int __ethtool_set_tso(struct net_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | if (!dev->ethtool_ops->set_tso) |
| 1432 | return -EOPNOTSUPP; |
| 1433 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1434 | if (data && !(dev->features & NETIF_F_SG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | return -EINVAL; |
| 1436 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1437 | return dev->ethtool_ops->set_tso(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1440 | static int __ethtool_set_ufo(struct net_device *dev, u32 data) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1441 | { |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1442 | if (!dev->ethtool_ops->set_ufo) |
| 1443 | return -EOPNOTSUPP; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1444 | if (data && !(dev->features & NETIF_F_SG)) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1445 | return -EINVAL; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1446 | if (data && !((dev->features & NETIF_F_GEN_CSUM) || |
Michał Mirosław | 7903264 | 2010-11-30 06:38:00 +0000 | [diff] [blame] | 1447 | (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)) |
| 1448 | == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1449 | return -EINVAL; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1450 | return dev->ethtool_ops->set_ufo(dev, data); |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
| 1454 | { |
| 1455 | struct ethtool_test test; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1456 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1458 | int ret, test_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1460 | if (!ops->self_test || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1461 | return -EOPNOTSUPP; |
| 1462 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1463 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1464 | if (test_len < 0) |
| 1465 | return test_len; |
| 1466 | WARN_ON(test_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
| 1468 | if (copy_from_user(&test, useraddr, sizeof(test))) |
| 1469 | return -EFAULT; |
| 1470 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1471 | test.len = test_len; |
| 1472 | data = kmalloc(test_len * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | if (!data) |
| 1474 | return -ENOMEM; |
| 1475 | |
| 1476 | ops->self_test(dev, &test, data); |
| 1477 | |
| 1478 | ret = -EFAULT; |
| 1479 | if (copy_to_user(useraddr, &test, sizeof(test))) |
| 1480 | goto out; |
| 1481 | useraddr += sizeof(test); |
| 1482 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) |
| 1483 | goto out; |
| 1484 | ret = 0; |
| 1485 | |
| 1486 | out: |
| 1487 | kfree(data); |
| 1488 | return ret; |
| 1489 | } |
| 1490 | |
| 1491 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
| 1492 | { |
| 1493 | struct ethtool_gstrings gstrings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | u8 *data; |
| 1495 | int ret; |
| 1496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 1498 | return -EFAULT; |
| 1499 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1500 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1501 | if (ret < 0) |
| 1502 | return ret; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1503 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1504 | gstrings.len = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
| 1506 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
| 1507 | if (!data) |
| 1508 | return -ENOMEM; |
| 1509 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1510 | __ethtool_get_strings(dev, gstrings.string_set, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
| 1512 | ret = -EFAULT; |
| 1513 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1514 | goto out; |
| 1515 | useraddr += sizeof(gstrings); |
| 1516 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1517 | goto out; |
| 1518 | ret = 0; |
| 1519 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1520 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | kfree(data); |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| 1525 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) |
| 1526 | { |
| 1527 | struct ethtool_value id; |
| 1528 | |
| 1529 | if (!dev->ethtool_ops->phys_id) |
| 1530 | return -EOPNOTSUPP; |
| 1531 | |
| 1532 | if (copy_from_user(&id, useraddr, sizeof(id))) |
| 1533 | return -EFAULT; |
| 1534 | |
| 1535 | return dev->ethtool_ops->phys_id(dev, id.data); |
| 1536 | } |
| 1537 | |
| 1538 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) |
| 1539 | { |
| 1540 | struct ethtool_stats stats; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1541 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1543 | int ret, n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1545 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1546 | return -EOPNOTSUPP; |
| 1547 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1548 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1549 | if (n_stats < 0) |
| 1550 | return n_stats; |
| 1551 | WARN_ON(n_stats == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
| 1553 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 1554 | return -EFAULT; |
| 1555 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1556 | stats.n_stats = n_stats; |
| 1557 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | if (!data) |
| 1559 | return -ENOMEM; |
| 1560 | |
| 1561 | ops->get_ethtool_stats(dev, &stats, data); |
| 1562 | |
| 1563 | ret = -EFAULT; |
| 1564 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 1565 | goto out; |
| 1566 | useraddr += sizeof(stats); |
| 1567 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) |
| 1568 | goto out; |
| 1569 | ret = 0; |
| 1570 | |
| 1571 | out: |
| 1572 | kfree(data); |
| 1573 | return ret; |
| 1574 | } |
| 1575 | |
viro@ftp.linux.org.uk | 0bf0519d | 2005-09-05 03:26:18 +0100 | [diff] [blame] | 1576 | 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] | 1577 | { |
| 1578 | struct ethtool_perm_addr epaddr; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1579 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1580 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1581 | return -EFAULT; |
| 1582 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1583 | if (epaddr.size < dev->addr_len) |
| 1584 | return -ETOOSMALL; |
| 1585 | epaddr.size = dev->addr_len; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1586 | |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1587 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1588 | return -EFAULT; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1589 | useraddr += sizeof(epaddr); |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1590 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
| 1591 | return -EFAULT; |
| 1592 | return 0; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1595 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
| 1596 | u32 cmd, u32 (*actor)(struct net_device *)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1597 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1598 | struct ethtool_value edata = { .cmd = cmd }; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1599 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1600 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1601 | return -EOPNOTSUPP; |
| 1602 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1603 | edata.data = actor(dev); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1604 | |
| 1605 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1606 | return -EFAULT; |
| 1607 | return 0; |
| 1608 | } |
| 1609 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1610 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
| 1611 | void (*actor)(struct net_device *, u32)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1612 | { |
| 1613 | struct ethtool_value edata; |
| 1614 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1615 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1616 | return -EOPNOTSUPP; |
| 1617 | |
| 1618 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1619 | return -EFAULT; |
| 1620 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1621 | actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1622 | return 0; |
| 1623 | } |
| 1624 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1625 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
| 1626 | int (*actor)(struct net_device *, u32)) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1627 | { |
| 1628 | struct ethtool_value edata; |
| 1629 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1630 | if (!actor) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1631 | return -EOPNOTSUPP; |
| 1632 | |
| 1633 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1634 | return -EFAULT; |
| 1635 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1636 | return actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1639 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
| 1640 | char __user *useraddr) |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1641 | { |
| 1642 | struct ethtool_flash efl; |
| 1643 | |
| 1644 | if (copy_from_user(&efl, useraddr, sizeof(efl))) |
| 1645 | return -EFAULT; |
| 1646 | |
| 1647 | if (!dev->ethtool_ops->flash_device) |
| 1648 | return -EOPNOTSUPP; |
| 1649 | |
| 1650 | return dev->ethtool_ops->flash_device(dev, &efl); |
| 1651 | } |
| 1652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | /* The main entry point in this file. Called from net/core/dev.c */ |
| 1654 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1655 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1657 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | void __user *useraddr = ifr->ifr_data; |
| 1659 | u32 ethcmd; |
| 1660 | int rc; |
Michał Mirosław | 04ed3e7 | 2011-01-24 15:32:47 -0800 | [diff] [blame] | 1661 | u32 old_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | if (!dev || !netif_device_present(dev)) |
| 1664 | return -ENODEV; |
| 1665 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1666 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | return -EFAULT; |
| 1668 | |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 1669 | if (!dev->ethtool_ops) { |
| 1670 | /* ETHTOOL_GDRVINFO does not require any driver support. |
| 1671 | * It is also unprivileged and does not change anything, |
| 1672 | * so we can take a shortcut to it. */ |
| 1673 | if (ethcmd == ETHTOOL_GDRVINFO) |
| 1674 | return ethtool_get_drvinfo(dev, useraddr); |
| 1675 | else |
| 1676 | return -EOPNOTSUPP; |
| 1677 | } |
| 1678 | |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1679 | /* Allow some commands to be done by anyone */ |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1680 | switch (ethcmd) { |
stephen hemminger | 0fdc100 | 2010-08-23 10:24:18 +0000 | [diff] [blame] | 1681 | case ETHTOOL_GSET: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1682 | case ETHTOOL_GDRVINFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1683 | case ETHTOOL_GMSGLVL: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1684 | case ETHTOOL_GCOALESCE: |
| 1685 | case ETHTOOL_GRINGPARAM: |
| 1686 | case ETHTOOL_GPAUSEPARAM: |
| 1687 | case ETHTOOL_GRXCSUM: |
| 1688 | case ETHTOOL_GTXCSUM: |
| 1689 | case ETHTOOL_GSG: |
| 1690 | case ETHTOOL_GSTRINGS: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1691 | case ETHTOOL_GTSO: |
| 1692 | case ETHTOOL_GPERMADDR: |
| 1693 | case ETHTOOL_GUFO: |
| 1694 | case ETHTOOL_GGSO: |
stephen hemminger | 1cab819 | 2010-02-11 13:48:29 +0000 | [diff] [blame] | 1695 | case ETHTOOL_GGRO: |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1696 | case ETHTOOL_GFLAGS: |
| 1697 | case ETHTOOL_GPFLAGS: |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1698 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1699 | case ETHTOOL_GRXRINGS: |
| 1700 | case ETHTOOL_GRXCLSRLCNT: |
| 1701 | case ETHTOOL_GRXCLSRULE: |
| 1702 | case ETHTOOL_GRXCLSRLALL: |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1703 | case ETHTOOL_GFEATURES: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1704 | break; |
| 1705 | default: |
| 1706 | if (!capable(CAP_NET_ADMIN)) |
| 1707 | return -EPERM; |
| 1708 | } |
| 1709 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1710 | if (dev->ethtool_ops->begin) { |
| 1711 | rc = dev->ethtool_ops->begin(dev); |
| 1712 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | return rc; |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1714 | } |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1715 | old_features = dev->features; |
| 1716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | switch (ethcmd) { |
| 1718 | case ETHTOOL_GSET: |
| 1719 | rc = ethtool_get_settings(dev, useraddr); |
| 1720 | break; |
| 1721 | case ETHTOOL_SSET: |
| 1722 | rc = ethtool_set_settings(dev, useraddr); |
| 1723 | break; |
| 1724 | case ETHTOOL_GDRVINFO: |
| 1725 | rc = ethtool_get_drvinfo(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | case ETHTOOL_GREGS: |
| 1728 | rc = ethtool_get_regs(dev, useraddr); |
| 1729 | break; |
| 1730 | case ETHTOOL_GWOL: |
| 1731 | rc = ethtool_get_wol(dev, useraddr); |
| 1732 | break; |
| 1733 | case ETHTOOL_SWOL: |
| 1734 | rc = ethtool_set_wol(dev, useraddr); |
| 1735 | break; |
| 1736 | case ETHTOOL_GMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1737 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1738 | dev->ethtool_ops->get_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | break; |
| 1740 | case ETHTOOL_SMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1741 | rc = ethtool_set_value_void(dev, useraddr, |
| 1742 | dev->ethtool_ops->set_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | break; |
| 1744 | case ETHTOOL_NWAY_RST: |
| 1745 | rc = ethtool_nway_reset(dev); |
| 1746 | break; |
| 1747 | case ETHTOOL_GLINK: |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1748 | rc = ethtool_get_link(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | break; |
| 1750 | case ETHTOOL_GEEPROM: |
| 1751 | rc = ethtool_get_eeprom(dev, useraddr); |
| 1752 | break; |
| 1753 | case ETHTOOL_SEEPROM: |
| 1754 | rc = ethtool_set_eeprom(dev, useraddr); |
| 1755 | break; |
| 1756 | case ETHTOOL_GCOALESCE: |
| 1757 | rc = ethtool_get_coalesce(dev, useraddr); |
| 1758 | break; |
| 1759 | case ETHTOOL_SCOALESCE: |
| 1760 | rc = ethtool_set_coalesce(dev, useraddr); |
| 1761 | break; |
| 1762 | case ETHTOOL_GRINGPARAM: |
| 1763 | rc = ethtool_get_ringparam(dev, useraddr); |
| 1764 | break; |
| 1765 | case ETHTOOL_SRINGPARAM: |
| 1766 | rc = ethtool_set_ringparam(dev, useraddr); |
| 1767 | break; |
| 1768 | case ETHTOOL_GPAUSEPARAM: |
| 1769 | rc = ethtool_get_pauseparam(dev, useraddr); |
| 1770 | break; |
| 1771 | case ETHTOOL_SPAUSEPARAM: |
| 1772 | rc = ethtool_set_pauseparam(dev, useraddr); |
| 1773 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | case ETHTOOL_TEST: |
| 1775 | rc = ethtool_self_test(dev, useraddr); |
| 1776 | break; |
| 1777 | case ETHTOOL_GSTRINGS: |
| 1778 | rc = ethtool_get_strings(dev, useraddr); |
| 1779 | break; |
| 1780 | case ETHTOOL_PHYS_ID: |
| 1781 | rc = ethtool_phys_id(dev, useraddr); |
| 1782 | break; |
| 1783 | case ETHTOOL_GSTATS: |
| 1784 | rc = ethtool_get_stats(dev, useraddr); |
| 1785 | break; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1786 | case ETHTOOL_GPERMADDR: |
| 1787 | rc = ethtool_get_perm_addr(dev, useraddr); |
| 1788 | break; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1789 | case ETHTOOL_GFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1790 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Sridhar Samudrala | 1896e61 | 2009-07-22 13:38:22 +0000 | [diff] [blame] | 1791 | (dev->ethtool_ops->get_flags ? |
| 1792 | dev->ethtool_ops->get_flags : |
| 1793 | ethtool_op_get_flags)); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1794 | break; |
| 1795 | case ETHTOOL_SFLAGS: |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1796 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1797 | break; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1798 | case ETHTOOL_GPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1799 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1800 | dev->ethtool_ops->get_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1801 | break; |
| 1802 | case ETHTOOL_SPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1803 | rc = ethtool_set_value(dev, useraddr, |
| 1804 | dev->ethtool_ops->set_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1805 | break; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1806 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1807 | case ETHTOOL_GRXRINGS: |
| 1808 | case ETHTOOL_GRXCLSRLCNT: |
| 1809 | case ETHTOOL_GRXCLSRULE: |
| 1810 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1811 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1812 | break; |
| 1813 | case ETHTOOL_SRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1814 | case ETHTOOL_SRXCLSRLDEL: |
| 1815 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1816 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1817 | break; |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1818 | case ETHTOOL_FLASHDEV: |
| 1819 | rc = ethtool_flash_device(dev, useraddr); |
| 1820 | break; |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1821 | case ETHTOOL_RESET: |
| 1822 | rc = ethtool_reset(dev, useraddr); |
| 1823 | break; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1824 | case ETHTOOL_SRXNTUPLE: |
| 1825 | rc = ethtool_set_rx_ntuple(dev, useraddr); |
| 1826 | break; |
| 1827 | case ETHTOOL_GRXNTUPLE: |
| 1828 | rc = ethtool_get_rx_ntuple(dev, useraddr); |
| 1829 | break; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 1830 | case ETHTOOL_GSSET_INFO: |
| 1831 | rc = ethtool_get_sset_info(dev, useraddr); |
| 1832 | break; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1833 | case ETHTOOL_GRXFHINDIR: |
| 1834 | rc = ethtool_get_rxfh_indir(dev, useraddr); |
| 1835 | break; |
| 1836 | case ETHTOOL_SRXFHINDIR: |
| 1837 | rc = ethtool_set_rxfh_indir(dev, useraddr); |
| 1838 | break; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1839 | case ETHTOOL_GFEATURES: |
| 1840 | rc = ethtool_get_features(dev, useraddr); |
| 1841 | break; |
| 1842 | case ETHTOOL_SFEATURES: |
| 1843 | rc = ethtool_set_features(dev, useraddr); |
| 1844 | break; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1845 | case ETHTOOL_GTXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 1846 | case ETHTOOL_GRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1847 | case ETHTOOL_GSG: |
| 1848 | case ETHTOOL_GTSO: |
| 1849 | case ETHTOOL_GUFO: |
| 1850 | case ETHTOOL_GGSO: |
| 1851 | case ETHTOOL_GGRO: |
| 1852 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); |
| 1853 | break; |
| 1854 | case ETHTOOL_STXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame^] | 1855 | case ETHTOOL_SRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1856 | case ETHTOOL_SSG: |
| 1857 | case ETHTOOL_STSO: |
| 1858 | case ETHTOOL_SUFO: |
| 1859 | case ETHTOOL_SGSO: |
| 1860 | case ETHTOOL_SGRO: |
| 1861 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); |
| 1862 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | default: |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 1864 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1866 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1867 | if (dev->ethtool_ops->complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | dev->ethtool_ops->complete(dev); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1869 | |
| 1870 | if (old_features != dev->features) |
| 1871 | netdev_features_change(dev); |
| 1872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |