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