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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
| 431 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 432 | struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | int err; |
| 434 | |
| 435 | if (!dev->ethtool_ops->get_settings) |
| 436 | return -EOPNOTSUPP; |
| 437 | |
| 438 | err = dev->ethtool_ops->get_settings(dev, &cmd); |
| 439 | if (err < 0) |
| 440 | return err; |
| 441 | |
| 442 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 443 | return -EFAULT; |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
| 448 | { |
| 449 | struct ethtool_cmd cmd; |
| 450 | |
| 451 | if (!dev->ethtool_ops->set_settings) |
| 452 | return -EOPNOTSUPP; |
| 453 | |
| 454 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 455 | return -EFAULT; |
| 456 | |
| 457 | return dev->ethtool_ops->set_settings(dev, &cmd); |
| 458 | } |
| 459 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 460 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
| 461 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
| 463 | struct ethtool_drvinfo info; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 464 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | memset(&info, 0, sizeof(info)); |
| 467 | info.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 468 | if (ops && ops->get_drvinfo) { |
| 469 | ops->get_drvinfo(dev, &info); |
| 470 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
| 471 | strlcpy(info.bus_info, dev_name(dev->dev.parent), |
| 472 | sizeof(info.bus_info)); |
| 473 | strlcpy(info.driver, dev->dev.parent->driver->name, |
| 474 | sizeof(info.driver)); |
| 475 | } else { |
| 476 | return -EOPNOTSUPP; |
| 477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 479 | /* |
| 480 | * this method of obtaining string set info is deprecated; |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 481 | * Use ETHTOOL_GSSET_INFO instead. |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 482 | */ |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 483 | if (ops && ops->get_sset_count) { |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 484 | int rc; |
| 485 | |
| 486 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
| 487 | if (rc >= 0) |
| 488 | info.testinfo_len = rc; |
| 489 | rc = ops->get_sset_count(dev, ETH_SS_STATS); |
| 490 | if (rc >= 0) |
| 491 | info.n_stats = rc; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 492 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
| 493 | if (rc >= 0) |
| 494 | info.n_priv_flags = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 495 | } |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 496 | if (ops && ops->get_regs_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | info.regdump_len = ops->get_regs_len(dev); |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 498 | if (ops && ops->get_eeprom_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | info.eedump_len = ops->get_eeprom_len(dev); |
| 500 | |
| 501 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 502 | return -EFAULT; |
| 503 | return 0; |
| 504 | } |
| 505 | |
Eric Dumazet | f5c445e | 2010-03-08 12:17:04 -0800 | [diff] [blame] | 506 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 507 | void __user *useraddr) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 508 | { |
| 509 | struct ethtool_sset_info info; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 510 | u64 sset_mask; |
| 511 | int i, idx = 0, n_bits = 0, ret, rc; |
| 512 | u32 *info_buf = NULL; |
| 513 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 514 | if (copy_from_user(&info, useraddr, sizeof(info))) |
| 515 | return -EFAULT; |
| 516 | |
| 517 | /* store copy of mask, because we zero struct later on */ |
| 518 | sset_mask = info.sset_mask; |
| 519 | if (!sset_mask) |
| 520 | return 0; |
| 521 | |
| 522 | /* calculate size of return buffer */ |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 523 | n_bits = hweight64(sset_mask); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 524 | |
| 525 | memset(&info, 0, sizeof(info)); |
| 526 | info.cmd = ETHTOOL_GSSET_INFO; |
| 527 | |
| 528 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); |
| 529 | if (!info_buf) |
| 530 | return -ENOMEM; |
| 531 | |
| 532 | /* |
| 533 | * fill return buffer based on input bitmask and successful |
| 534 | * get_sset_count return |
| 535 | */ |
| 536 | for (i = 0; i < 64; i++) { |
| 537 | if (!(sset_mask & (1ULL << i))) |
| 538 | continue; |
| 539 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 540 | rc = __ethtool_get_sset_count(dev, i); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 541 | if (rc >= 0) { |
| 542 | info.sset_mask |= (1ULL << i); |
| 543 | info_buf[idx++] = rc; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | ret = -EFAULT; |
| 548 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 549 | goto out; |
| 550 | |
| 551 | useraddr += offsetof(struct ethtool_sset_info, data); |
| 552 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) |
| 553 | goto out; |
| 554 | |
| 555 | ret = 0; |
| 556 | |
| 557 | out: |
| 558 | kfree(info_buf); |
| 559 | return ret; |
| 560 | } |
| 561 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 562 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 563 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 564 | { |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 565 | struct ethtool_rxnfc info; |
| 566 | size_t info_size = sizeof(info); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 567 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 568 | if (!dev->ethtool_ops->set_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 569 | return -EOPNOTSUPP; |
| 570 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 571 | /* struct ethtool_rxnfc was originally defined for |
| 572 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 573 | * members. User-space might still be using that |
| 574 | * definition. */ |
| 575 | if (cmd == ETHTOOL_SRXFH) |
| 576 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 577 | sizeof(info.data)); |
| 578 | |
| 579 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 580 | return -EFAULT; |
| 581 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 582 | return dev->ethtool_ops->set_rxnfc(dev, &info); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 583 | } |
| 584 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 585 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 586 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 587 | { |
| 588 | struct ethtool_rxnfc info; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 589 | size_t info_size = sizeof(info); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 590 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 591 | int ret; |
| 592 | void *rule_buf = NULL; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 593 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 594 | if (!ops->get_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 595 | return -EOPNOTSUPP; |
| 596 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 597 | /* struct ethtool_rxnfc was originally defined for |
| 598 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 599 | * members. User-space might still be using that |
| 600 | * definition. */ |
| 601 | if (cmd == ETHTOOL_GRXFH) |
| 602 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 603 | sizeof(info.data)); |
| 604 | |
| 605 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 606 | return -EFAULT; |
| 607 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 608 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
| 609 | if (info.rule_cnt > 0) { |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 610 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
Kees Cook | ae6df5f | 2010-10-07 10:03:48 +0000 | [diff] [blame] | 611 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 612 | GFP_USER); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 613 | if (!rule_buf) |
| 614 | return -ENOMEM; |
| 615 | } |
| 616 | } |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 617 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 618 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
| 619 | if (ret < 0) |
| 620 | goto err_out; |
| 621 | |
| 622 | ret = -EFAULT; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 623 | if (copy_to_user(useraddr, &info, info_size)) |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 624 | goto err_out; |
| 625 | |
| 626 | if (rule_buf) { |
| 627 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); |
| 628 | if (copy_to_user(useraddr, rule_buf, |
| 629 | info.rule_cnt * sizeof(u32))) |
| 630 | goto err_out; |
| 631 | } |
| 632 | ret = 0; |
| 633 | |
| 634 | err_out: |
Wei Yongjun | c9cacec | 2009-03-31 15:06:26 -0700 | [diff] [blame] | 635 | kfree(rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 636 | |
| 637 | return ret; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 640 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
| 641 | void __user *useraddr) |
| 642 | { |
| 643 | struct ethtool_rxfh_indir *indir; |
| 644 | u32 table_size; |
| 645 | size_t full_size; |
| 646 | int ret; |
| 647 | |
| 648 | if (!dev->ethtool_ops->get_rxfh_indir) |
| 649 | return -EOPNOTSUPP; |
| 650 | |
| 651 | if (copy_from_user(&table_size, |
| 652 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 653 | sizeof(table_size))) |
| 654 | return -EFAULT; |
| 655 | |
| 656 | if (table_size > |
| 657 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) |
| 658 | return -ENOMEM; |
| 659 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; |
Kees Cook | b00916b | 2010-10-11 12:23:25 -0700 | [diff] [blame] | 660 | indir = kzalloc(full_size, GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 661 | if (!indir) |
| 662 | return -ENOMEM; |
| 663 | |
| 664 | indir->cmd = ETHTOOL_GRXFHINDIR; |
| 665 | indir->size = table_size; |
| 666 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); |
| 667 | if (ret) |
| 668 | goto out; |
| 669 | |
| 670 | if (copy_to_user(useraddr, indir, full_size)) |
| 671 | ret = -EFAULT; |
| 672 | |
| 673 | out: |
| 674 | kfree(indir); |
| 675 | return ret; |
| 676 | } |
| 677 | |
| 678 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, |
| 679 | void __user *useraddr) |
| 680 | { |
| 681 | struct ethtool_rxfh_indir *indir; |
| 682 | u32 table_size; |
| 683 | size_t full_size; |
| 684 | int ret; |
| 685 | |
| 686 | if (!dev->ethtool_ops->set_rxfh_indir) |
| 687 | return -EOPNOTSUPP; |
| 688 | |
| 689 | if (copy_from_user(&table_size, |
| 690 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 691 | sizeof(table_size))) |
| 692 | return -EFAULT; |
| 693 | |
| 694 | if (table_size > |
| 695 | (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index)) |
| 696 | return -ENOMEM; |
| 697 | full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size; |
| 698 | indir = kmalloc(full_size, GFP_USER); |
| 699 | if (!indir) |
| 700 | return -ENOMEM; |
| 701 | |
| 702 | if (copy_from_user(indir, useraddr, full_size)) { |
| 703 | ret = -EFAULT; |
| 704 | goto out; |
| 705 | } |
| 706 | |
| 707 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); |
| 708 | |
| 709 | out: |
| 710 | kfree(indir); |
| 711 | return ret; |
| 712 | } |
| 713 | |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 714 | static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 715 | struct ethtool_rx_ntuple_flow_spec *spec, |
| 716 | struct ethtool_rx_ntuple_flow_spec_container *fsc) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 717 | { |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 718 | |
| 719 | /* don't add filters forever */ |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 720 | if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) { |
| 721 | /* free the container */ |
| 722 | kfree(fsc); |
| 723 | return; |
| 724 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 725 | |
| 726 | /* Copy the whole filter over */ |
| 727 | fsc->fs.flow_type = spec->flow_type; |
| 728 | memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u)); |
| 729 | memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u)); |
| 730 | |
| 731 | fsc->fs.vlan_tag = spec->vlan_tag; |
| 732 | fsc->fs.vlan_tag_mask = spec->vlan_tag_mask; |
| 733 | fsc->fs.data = spec->data; |
| 734 | fsc->fs.data_mask = spec->data_mask; |
| 735 | fsc->fs.action = spec->action; |
| 736 | |
| 737 | /* add to the list */ |
| 738 | list_add_tail_rcu(&fsc->list, &list->list); |
| 739 | list->count++; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 740 | } |
| 741 | |
Ben Hutchings | be2902d | 2010-09-16 11:28:07 +0000 | [diff] [blame] | 742 | /* |
| 743 | * ethtool does not (or did not) set masks for flow parameters that are |
| 744 | * not specified, so if both value and mask are 0 then this must be |
| 745 | * treated as equivalent to a mask with all bits set. Implement that |
| 746 | * here rather than in drivers. |
| 747 | */ |
| 748 | static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs) |
| 749 | { |
| 750 | struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec; |
| 751 | struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec; |
| 752 | |
| 753 | if (fs->flow_type != TCP_V4_FLOW && |
| 754 | fs->flow_type != UDP_V4_FLOW && |
| 755 | fs->flow_type != SCTP_V4_FLOW) |
| 756 | return; |
| 757 | |
| 758 | if (!(entry->ip4src | mask->ip4src)) |
| 759 | mask->ip4src = htonl(0xffffffff); |
| 760 | if (!(entry->ip4dst | mask->ip4dst)) |
| 761 | mask->ip4dst = htonl(0xffffffff); |
| 762 | if (!(entry->psrc | mask->psrc)) |
| 763 | mask->psrc = htons(0xffff); |
| 764 | if (!(entry->pdst | mask->pdst)) |
| 765 | mask->pdst = htons(0xffff); |
| 766 | if (!(entry->tos | mask->tos)) |
| 767 | mask->tos = 0xff; |
| 768 | if (!(fs->vlan_tag | fs->vlan_tag_mask)) |
| 769 | fs->vlan_tag_mask = 0xffff; |
| 770 | if (!(fs->data | fs->data_mask)) |
| 771 | fs->data_mask = 0xffffffffffffffffULL; |
| 772 | } |
| 773 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 774 | static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, |
| 775 | void __user *useraddr) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 776 | { |
| 777 | struct ethtool_rx_ntuple cmd; |
| 778 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 779 | struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 780 | int ret; |
| 781 | |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 782 | if (!(dev->features & NETIF_F_NTUPLE)) |
| 783 | return -EINVAL; |
| 784 | |
| 785 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 786 | return -EFAULT; |
| 787 | |
Ben Hutchings | be2902d | 2010-09-16 11:28:07 +0000 | [diff] [blame] | 788 | rx_ntuple_fix_masks(&cmd.fs); |
| 789 | |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 790 | /* |
| 791 | * Cache filter in dev struct for GET operation only if |
| 792 | * the underlying driver doesn't have its own GET operation, and |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 793 | * only if the filter was added successfully. First make sure we |
| 794 | * can allocate the filter, then continue if successful. |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 795 | */ |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 796 | if (!ops->get_rx_ntuple) { |
| 797 | fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC); |
| 798 | if (!fsc) |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 799 | return -ENOMEM; |
Peter Waskiewicz | e858911 | 2010-02-12 13:48:05 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | ret = ops->set_rx_ntuple(dev, &cmd); |
| 803 | if (ret) { |
| 804 | kfree(fsc); |
| 805 | return ret; |
| 806 | } |
| 807 | |
| 808 | if (!ops->get_rx_ntuple) |
| 809 | __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] | 810 | |
| 811 | return ret; |
| 812 | } |
| 813 | |
| 814 | static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr) |
| 815 | { |
| 816 | struct ethtool_gstrings gstrings; |
| 817 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 818 | struct ethtool_rx_ntuple_flow_spec_container *fsc; |
| 819 | u8 *data; |
| 820 | char *p; |
| 821 | int ret, i, num_strings = 0; |
| 822 | |
| 823 | if (!ops->get_sset_count) |
| 824 | return -EOPNOTSUPP; |
| 825 | |
| 826 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 827 | return -EFAULT; |
| 828 | |
| 829 | ret = ops->get_sset_count(dev, gstrings.string_set); |
| 830 | if (ret < 0) |
| 831 | return ret; |
| 832 | |
| 833 | gstrings.len = ret; |
| 834 | |
Kees Cook | b00916b | 2010-10-11 12:23:25 -0700 | [diff] [blame] | 835 | data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 836 | if (!data) |
| 837 | return -ENOMEM; |
| 838 | |
| 839 | if (ops->get_rx_ntuple) { |
| 840 | /* driver-specific filter grab */ |
| 841 | ret = ops->get_rx_ntuple(dev, gstrings.string_set, data); |
| 842 | goto copy; |
| 843 | } |
| 844 | |
| 845 | /* default ethtool filter grab */ |
| 846 | i = 0; |
| 847 | p = (char *)data; |
| 848 | list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) { |
| 849 | sprintf(p, "Filter %d:\n", i); |
| 850 | p += ETH_GSTRING_LEN; |
| 851 | num_strings++; |
| 852 | |
| 853 | switch (fsc->fs.flow_type) { |
| 854 | case TCP_V4_FLOW: |
| 855 | sprintf(p, "\tFlow Type: TCP\n"); |
| 856 | p += ETH_GSTRING_LEN; |
| 857 | num_strings++; |
| 858 | break; |
| 859 | case UDP_V4_FLOW: |
| 860 | sprintf(p, "\tFlow Type: UDP\n"); |
| 861 | p += ETH_GSTRING_LEN; |
| 862 | num_strings++; |
| 863 | break; |
| 864 | case SCTP_V4_FLOW: |
| 865 | sprintf(p, "\tFlow Type: SCTP\n"); |
| 866 | p += ETH_GSTRING_LEN; |
| 867 | num_strings++; |
| 868 | break; |
| 869 | case AH_ESP_V4_FLOW: |
| 870 | sprintf(p, "\tFlow Type: AH ESP\n"); |
| 871 | p += ETH_GSTRING_LEN; |
| 872 | num_strings++; |
| 873 | break; |
| 874 | case ESP_V4_FLOW: |
| 875 | sprintf(p, "\tFlow Type: ESP\n"); |
| 876 | p += ETH_GSTRING_LEN; |
| 877 | num_strings++; |
| 878 | break; |
| 879 | case IP_USER_FLOW: |
| 880 | sprintf(p, "\tFlow Type: Raw IP\n"); |
| 881 | p += ETH_GSTRING_LEN; |
| 882 | num_strings++; |
| 883 | break; |
| 884 | case IPV4_FLOW: |
| 885 | sprintf(p, "\tFlow Type: IPv4\n"); |
| 886 | p += ETH_GSTRING_LEN; |
| 887 | num_strings++; |
| 888 | break; |
| 889 | default: |
| 890 | sprintf(p, "\tFlow Type: Unknown\n"); |
| 891 | p += ETH_GSTRING_LEN; |
| 892 | num_strings++; |
| 893 | goto unknown_filter; |
Joe Perches | ccbd6a5 | 2010-05-14 10:58:26 +0000 | [diff] [blame] | 894 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 895 | |
| 896 | /* now the rest of the filters */ |
| 897 | switch (fsc->fs.flow_type) { |
| 898 | case TCP_V4_FLOW: |
| 899 | case UDP_V4_FLOW: |
| 900 | case SCTP_V4_FLOW: |
| 901 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 902 | fsc->fs.h_u.tcp_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 903 | p += ETH_GSTRING_LEN; |
| 904 | num_strings++; |
| 905 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 906 | fsc->fs.m_u.tcp_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 907 | p += ETH_GSTRING_LEN; |
| 908 | num_strings++; |
| 909 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 910 | fsc->fs.h_u.tcp_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 911 | p += ETH_GSTRING_LEN; |
| 912 | num_strings++; |
| 913 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 914 | fsc->fs.m_u.tcp_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 915 | p += ETH_GSTRING_LEN; |
| 916 | num_strings++; |
| 917 | sprintf(p, "\tSrc Port: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 918 | fsc->fs.h_u.tcp_ip4_spec.psrc, |
| 919 | fsc->fs.m_u.tcp_ip4_spec.psrc); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 920 | p += ETH_GSTRING_LEN; |
| 921 | num_strings++; |
| 922 | sprintf(p, "\tDest Port: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 923 | fsc->fs.h_u.tcp_ip4_spec.pdst, |
| 924 | fsc->fs.m_u.tcp_ip4_spec.pdst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 925 | p += ETH_GSTRING_LEN; |
| 926 | num_strings++; |
| 927 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 928 | fsc->fs.h_u.tcp_ip4_spec.tos, |
| 929 | fsc->fs.m_u.tcp_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 930 | p += ETH_GSTRING_LEN; |
| 931 | num_strings++; |
| 932 | break; |
| 933 | case AH_ESP_V4_FLOW: |
| 934 | case ESP_V4_FLOW: |
| 935 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 936 | fsc->fs.h_u.ah_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 937 | p += ETH_GSTRING_LEN; |
| 938 | num_strings++; |
| 939 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 940 | fsc->fs.m_u.ah_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 941 | p += ETH_GSTRING_LEN; |
| 942 | num_strings++; |
| 943 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 944 | fsc->fs.h_u.ah_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 945 | p += ETH_GSTRING_LEN; |
| 946 | num_strings++; |
| 947 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 948 | fsc->fs.m_u.ah_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 949 | p += ETH_GSTRING_LEN; |
| 950 | num_strings++; |
| 951 | sprintf(p, "\tSPI: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 952 | fsc->fs.h_u.ah_ip4_spec.spi, |
| 953 | fsc->fs.m_u.ah_ip4_spec.spi); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 954 | p += ETH_GSTRING_LEN; |
| 955 | num_strings++; |
| 956 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 957 | fsc->fs.h_u.ah_ip4_spec.tos, |
| 958 | fsc->fs.m_u.ah_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 959 | p += ETH_GSTRING_LEN; |
| 960 | num_strings++; |
| 961 | break; |
| 962 | case IP_USER_FLOW: |
| 963 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 964 | fsc->fs.h_u.usr_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", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 968 | fsc->fs.m_u.usr_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", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 972 | fsc->fs.h_u.usr_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", |
Ben Hutchings | e0de7c9 | 2010-09-14 09:13:08 +0000 | [diff] [blame] | 976 | fsc->fs.m_u.usr_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 | break; |
| 980 | case IPV4_FLOW: |
| 981 | sprintf(p, "\tSrc IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 982 | fsc->fs.h_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 983 | p += ETH_GSTRING_LEN; |
| 984 | num_strings++; |
| 985 | sprintf(p, "\tSrc IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 986 | fsc->fs.m_u.usr_ip4_spec.ip4src); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 987 | p += ETH_GSTRING_LEN; |
| 988 | num_strings++; |
| 989 | sprintf(p, "\tDest IP addr: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 990 | fsc->fs.h_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 991 | p += ETH_GSTRING_LEN; |
| 992 | num_strings++; |
| 993 | sprintf(p, "\tDest IP mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 994 | fsc->fs.m_u.usr_ip4_spec.ip4dst); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 995 | p += ETH_GSTRING_LEN; |
| 996 | num_strings++; |
| 997 | sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 998 | fsc->fs.h_u.usr_ip4_spec.l4_4_bytes, |
| 999 | fsc->fs.m_u.usr_ip4_spec.l4_4_bytes); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1000 | p += ETH_GSTRING_LEN; |
| 1001 | num_strings++; |
| 1002 | sprintf(p, "\tTOS: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1003 | fsc->fs.h_u.usr_ip4_spec.tos, |
| 1004 | fsc->fs.m_u.usr_ip4_spec.tos); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1005 | p += ETH_GSTRING_LEN; |
| 1006 | num_strings++; |
| 1007 | sprintf(p, "\tIP Version: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1008 | fsc->fs.h_u.usr_ip4_spec.ip_ver, |
| 1009 | fsc->fs.m_u.usr_ip4_spec.ip_ver); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1010 | p += ETH_GSTRING_LEN; |
| 1011 | num_strings++; |
| 1012 | sprintf(p, "\tProtocol: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1013 | fsc->fs.h_u.usr_ip4_spec.proto, |
| 1014 | fsc->fs.m_u.usr_ip4_spec.proto); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1015 | p += ETH_GSTRING_LEN; |
| 1016 | num_strings++; |
| 1017 | break; |
Joe Perches | ccbd6a5 | 2010-05-14 10:58:26 +0000 | [diff] [blame] | 1018 | } |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1019 | sprintf(p, "\tVLAN: %d, mask: 0x%x\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1020 | fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1021 | p += ETH_GSTRING_LEN; |
| 1022 | num_strings++; |
| 1023 | sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data); |
| 1024 | p += ETH_GSTRING_LEN; |
| 1025 | num_strings++; |
| 1026 | sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask); |
| 1027 | p += ETH_GSTRING_LEN; |
| 1028 | num_strings++; |
| 1029 | if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) |
| 1030 | sprintf(p, "\tAction: Drop\n"); |
| 1031 | else |
| 1032 | sprintf(p, "\tAction: Direct to queue %d\n", |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1033 | fsc->fs.action); |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1034 | p += ETH_GSTRING_LEN; |
| 1035 | num_strings++; |
| 1036 | unknown_filter: |
| 1037 | i++; |
| 1038 | } |
| 1039 | copy: |
| 1040 | /* indicate to userspace how many strings we actually have */ |
| 1041 | gstrings.len = num_strings; |
| 1042 | ret = -EFAULT; |
| 1043 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1044 | goto out; |
| 1045 | useraddr += sizeof(gstrings); |
| 1046 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1047 | goto out; |
| 1048 | ret = 0; |
| 1049 | |
| 1050 | out: |
| 1051 | kfree(data); |
| 1052 | return ret; |
| 1053 | } |
| 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
| 1056 | { |
| 1057 | struct ethtool_regs regs; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1058 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | void *regbuf; |
| 1060 | int reglen, ret; |
| 1061 | |
| 1062 | if (!ops->get_regs || !ops->get_regs_len) |
| 1063 | return -EOPNOTSUPP; |
| 1064 | |
| 1065 | if (copy_from_user(®s, useraddr, sizeof(regs))) |
| 1066 | return -EFAULT; |
| 1067 | |
| 1068 | reglen = ops->get_regs_len(dev); |
| 1069 | if (regs.len > reglen) |
| 1070 | regs.len = reglen; |
| 1071 | |
Eugene Teo | b7c7d01 | 2011-01-24 21:05:17 -0800 | [diff] [blame] | 1072 | regbuf = vzalloc(reglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | if (!regbuf) |
| 1074 | return -ENOMEM; |
| 1075 | |
| 1076 | ops->get_regs(dev, ®s, regbuf); |
| 1077 | |
| 1078 | ret = -EFAULT; |
| 1079 | if (copy_to_user(useraddr, ®s, sizeof(regs))) |
| 1080 | goto out; |
| 1081 | useraddr += offsetof(struct ethtool_regs, data); |
| 1082 | if (copy_to_user(useraddr, regbuf, regs.len)) |
| 1083 | goto out; |
| 1084 | ret = 0; |
| 1085 | |
| 1086 | out: |
Ben Hutchings | a77f5db | 2010-09-20 08:42:17 +0000 | [diff] [blame] | 1087 | vfree(regbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return ret; |
| 1089 | } |
| 1090 | |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1091 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
| 1092 | { |
| 1093 | struct ethtool_value reset; |
| 1094 | int ret; |
| 1095 | |
| 1096 | if (!dev->ethtool_ops->reset) |
| 1097 | return -EOPNOTSUPP; |
| 1098 | |
| 1099 | if (copy_from_user(&reset, useraddr, sizeof(reset))) |
| 1100 | return -EFAULT; |
| 1101 | |
| 1102 | ret = dev->ethtool_ops->reset(dev, &reset.data); |
| 1103 | if (ret) |
| 1104 | return ret; |
| 1105 | |
| 1106 | if (copy_to_user(useraddr, &reset, sizeof(reset))) |
| 1107 | return -EFAULT; |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
| 1112 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1113 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | if (!dev->ethtool_ops->get_wol) |
| 1116 | return -EOPNOTSUPP; |
| 1117 | |
| 1118 | dev->ethtool_ops->get_wol(dev, &wol); |
| 1119 | |
| 1120 | if (copy_to_user(useraddr, &wol, sizeof(wol))) |
| 1121 | return -EFAULT; |
| 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) |
| 1126 | { |
| 1127 | struct ethtool_wolinfo wol; |
| 1128 | |
| 1129 | if (!dev->ethtool_ops->set_wol) |
| 1130 | return -EOPNOTSUPP; |
| 1131 | |
| 1132 | if (copy_from_user(&wol, useraddr, sizeof(wol))) |
| 1133 | return -EFAULT; |
| 1134 | |
| 1135 | return dev->ethtool_ops->set_wol(dev, &wol); |
| 1136 | } |
| 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | static int ethtool_nway_reset(struct net_device *dev) |
| 1139 | { |
| 1140 | if (!dev->ethtool_ops->nway_reset) |
| 1141 | return -EOPNOTSUPP; |
| 1142 | |
| 1143 | return dev->ethtool_ops->nway_reset(dev); |
| 1144 | } |
| 1145 | |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1146 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
| 1147 | { |
| 1148 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; |
| 1149 | |
| 1150 | if (!dev->ethtool_ops->get_link) |
| 1151 | return -EOPNOTSUPP; |
| 1152 | |
| 1153 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); |
| 1154 | |
| 1155 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1156 | return -EFAULT; |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
| 1161 | { |
| 1162 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1163 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1164 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1165 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1167 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
| 1169 | if (!ops->get_eeprom || !ops->get_eeprom_len) |
| 1170 | return -EOPNOTSUPP; |
| 1171 | |
| 1172 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1173 | return -EFAULT; |
| 1174 | |
| 1175 | /* Check for wrap and zero */ |
| 1176 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1177 | return -EINVAL; |
| 1178 | |
| 1179 | /* Check for exceeding total eeprom len */ |
| 1180 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1181 | return -EINVAL; |
| 1182 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1183 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | if (!data) |
| 1185 | return -ENOMEM; |
| 1186 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1187 | bytes_remaining = eeprom.len; |
| 1188 | while (bytes_remaining > 0) { |
| 1189 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1191 | ret = ops->get_eeprom(dev, &eeprom, data); |
| 1192 | if (ret) |
| 1193 | break; |
| 1194 | if (copy_to_user(userbuf, data, eeprom.len)) { |
| 1195 | ret = -EFAULT; |
| 1196 | break; |
| 1197 | } |
| 1198 | userbuf += eeprom.len; |
| 1199 | eeprom.offset += eeprom.len; |
| 1200 | bytes_remaining -= eeprom.len; |
| 1201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
Mandeep Singh Baines | c5835df | 2008-04-24 20:55:56 -0700 | [diff] [blame] | 1203 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
| 1204 | eeprom.offset -= eeprom.len; |
| 1205 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) |
| 1206 | ret = -EFAULT; |
| 1207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | kfree(data); |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
| 1213 | { |
| 1214 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1215 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1216 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 1217 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1219 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | if (!ops->set_eeprom || !ops->get_eeprom_len) |
| 1222 | return -EOPNOTSUPP; |
| 1223 | |
| 1224 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 1225 | return -EFAULT; |
| 1226 | |
| 1227 | /* Check for wrap and zero */ |
| 1228 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 1229 | return -EINVAL; |
| 1230 | |
| 1231 | /* Check for exceeding total eeprom len */ |
| 1232 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 1233 | return -EINVAL; |
| 1234 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1235 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | if (!data) |
| 1237 | return -ENOMEM; |
| 1238 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1239 | bytes_remaining = eeprom.len; |
| 1240 | while (bytes_remaining > 0) { |
| 1241 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 1243 | if (copy_from_user(data, userbuf, eeprom.len)) { |
| 1244 | ret = -EFAULT; |
| 1245 | break; |
| 1246 | } |
| 1247 | ret = ops->set_eeprom(dev, &eeprom, data); |
| 1248 | if (ret) |
| 1249 | break; |
| 1250 | userbuf += eeprom.len; |
| 1251 | eeprom.offset += eeprom.len; |
| 1252 | bytes_remaining -= eeprom.len; |
| 1253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | kfree(data); |
| 1256 | return ret; |
| 1257 | } |
| 1258 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1259 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
| 1260 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1262 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | if (!dev->ethtool_ops->get_coalesce) |
| 1265 | return -EOPNOTSUPP; |
| 1266 | |
| 1267 | dev->ethtool_ops->get_coalesce(dev, &coalesce); |
| 1268 | |
| 1269 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 1270 | return -EFAULT; |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1274 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
| 1275 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | { |
| 1277 | struct ethtool_coalesce coalesce; |
| 1278 | |
David S. Miller | fa04ae5 | 2005-06-06 15:07:19 -0700 | [diff] [blame] | 1279 | if (!dev->ethtool_ops->set_coalesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | return -EOPNOTSUPP; |
| 1281 | |
| 1282 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) |
| 1283 | return -EFAULT; |
| 1284 | |
| 1285 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); |
| 1286 | } |
| 1287 | |
| 1288 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) |
| 1289 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1290 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
| 1292 | if (!dev->ethtool_ops->get_ringparam) |
| 1293 | return -EOPNOTSUPP; |
| 1294 | |
| 1295 | dev->ethtool_ops->get_ringparam(dev, &ringparam); |
| 1296 | |
| 1297 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) |
| 1298 | return -EFAULT; |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) |
| 1303 | { |
| 1304 | struct ethtool_ringparam ringparam; |
| 1305 | |
| 1306 | if (!dev->ethtool_ops->set_ringparam) |
| 1307 | return -EOPNOTSUPP; |
| 1308 | |
| 1309 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) |
| 1310 | return -EFAULT; |
| 1311 | |
| 1312 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); |
| 1313 | } |
| 1314 | |
| 1315 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1316 | { |
| 1317 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; |
| 1318 | |
| 1319 | if (!dev->ethtool_ops->get_pauseparam) |
| 1320 | return -EOPNOTSUPP; |
| 1321 | |
| 1322 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); |
| 1323 | |
| 1324 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) |
| 1325 | return -EFAULT; |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) |
| 1330 | { |
| 1331 | struct ethtool_pauseparam pauseparam; |
| 1332 | |
Jeff Garzik | e1b90c4 | 2006-07-17 12:54:40 -0400 | [diff] [blame] | 1333 | if (!dev->ethtool_ops->set_pauseparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | return -EOPNOTSUPP; |
| 1335 | |
| 1336 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) |
| 1337 | return -EFAULT; |
| 1338 | |
| 1339 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); |
| 1340 | } |
| 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | static int __ethtool_set_sg(struct net_device *dev, u32 data) |
| 1343 | { |
| 1344 | int err; |
| 1345 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1346 | if (data && !(dev->features & NETIF_F_ALL_CSUM)) |
| 1347 | return -EINVAL; |
| 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | if (!data && dev->ethtool_ops->set_tso) { |
| 1350 | err = dev->ethtool_ops->set_tso(dev, 0); |
| 1351 | if (err) |
| 1352 | return err; |
| 1353 | } |
| 1354 | |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1355 | if (!data && dev->ethtool_ops->set_ufo) { |
| 1356 | err = dev->ethtool_ops->set_ufo(dev, 0); |
| 1357 | if (err) |
| 1358 | return err; |
| 1359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | return dev->ethtool_ops->set_sg(dev, data); |
| 1361 | } |
| 1362 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1363 | static int __ethtool_set_tx_csum(struct net_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | int err; |
| 1366 | |
| 1367 | if (!dev->ethtool_ops->set_tx_csum) |
| 1368 | return -EOPNOTSUPP; |
| 1369 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1370 | if (!data && dev->ethtool_ops->set_sg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | err = __ethtool_set_sg(dev, 0); |
| 1372 | if (err) |
| 1373 | return err; |
| 1374 | } |
| 1375 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1376 | return dev->ethtool_ops->set_tx_csum(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1379 | static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr) |
| 1380 | { |
| 1381 | struct ethtool_value edata; |
| 1382 | |
| 1383 | if (!dev->ethtool_ops->set_rx_csum) |
| 1384 | return -EOPNOTSUPP; |
| 1385 | |
| 1386 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1387 | return -EFAULT; |
| 1388 | |
| 1389 | if (!edata.data && dev->ethtool_ops->set_sg) |
| 1390 | dev->features &= ~NETIF_F_GRO; |
| 1391 | |
| 1392 | return dev->ethtool_ops->set_rx_csum(dev, edata.data); |
| 1393 | } |
| 1394 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1395 | static int __ethtool_set_tso(struct net_device *dev, u32 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | if (!dev->ethtool_ops->set_tso) |
| 1398 | return -EOPNOTSUPP; |
| 1399 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1400 | if (data && !(dev->features & NETIF_F_SG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | return -EINVAL; |
| 1402 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1403 | return dev->ethtool_ops->set_tso(dev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1406 | static int __ethtool_set_ufo(struct net_device *dev, u32 data) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1407 | { |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1408 | if (!dev->ethtool_ops->set_ufo) |
| 1409 | return -EOPNOTSUPP; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1410 | if (data && !(dev->features & NETIF_F_SG)) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1411 | return -EINVAL; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1412 | if (data && !((dev->features & NETIF_F_GEN_CSUM) || |
Michał Mirosław | 7903264 | 2010-11-30 06:38:00 +0000 | [diff] [blame] | 1413 | (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)) |
| 1414 | == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) |
Ananda Raju | e89e9cf | 2005-10-18 15:46:41 -0700 | [diff] [blame] | 1415 | return -EINVAL; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1416 | return dev->ethtool_ops->set_ufo(dev, data); |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1417 | } |
| 1418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
| 1420 | { |
| 1421 | struct ethtool_test test; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1422 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1424 | int ret, test_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1426 | if (!ops->self_test || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1427 | return -EOPNOTSUPP; |
| 1428 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1429 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1430 | if (test_len < 0) |
| 1431 | return test_len; |
| 1432 | WARN_ON(test_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
| 1434 | if (copy_from_user(&test, useraddr, sizeof(test))) |
| 1435 | return -EFAULT; |
| 1436 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1437 | test.len = test_len; |
| 1438 | data = kmalloc(test_len * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | if (!data) |
| 1440 | return -ENOMEM; |
| 1441 | |
| 1442 | ops->self_test(dev, &test, data); |
| 1443 | |
| 1444 | ret = -EFAULT; |
| 1445 | if (copy_to_user(useraddr, &test, sizeof(test))) |
| 1446 | goto out; |
| 1447 | useraddr += sizeof(test); |
| 1448 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) |
| 1449 | goto out; |
| 1450 | ret = 0; |
| 1451 | |
| 1452 | out: |
| 1453 | kfree(data); |
| 1454 | return ret; |
| 1455 | } |
| 1456 | |
| 1457 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
| 1458 | { |
| 1459 | struct ethtool_gstrings gstrings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | u8 *data; |
| 1461 | int ret; |
| 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 1464 | return -EFAULT; |
| 1465 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1466 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1467 | if (ret < 0) |
| 1468 | return ret; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1469 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1470 | gstrings.len = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | |
| 1472 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
| 1473 | if (!data) |
| 1474 | return -ENOMEM; |
| 1475 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1476 | __ethtool_get_strings(dev, gstrings.string_set, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
| 1478 | ret = -EFAULT; |
| 1479 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1480 | goto out; |
| 1481 | useraddr += sizeof(gstrings); |
| 1482 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1483 | goto out; |
| 1484 | ret = 0; |
| 1485 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1486 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | kfree(data); |
| 1488 | return ret; |
| 1489 | } |
| 1490 | |
| 1491 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) |
| 1492 | { |
| 1493 | struct ethtool_value id; |
| 1494 | |
| 1495 | if (!dev->ethtool_ops->phys_id) |
| 1496 | return -EOPNOTSUPP; |
| 1497 | |
| 1498 | if (copy_from_user(&id, useraddr, sizeof(id))) |
| 1499 | return -EFAULT; |
| 1500 | |
| 1501 | return dev->ethtool_ops->phys_id(dev, id.data); |
| 1502 | } |
| 1503 | |
| 1504 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) |
| 1505 | { |
| 1506 | struct ethtool_stats stats; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1507 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1509 | int ret, n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1511 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1512 | return -EOPNOTSUPP; |
| 1513 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1514 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1515 | if (n_stats < 0) |
| 1516 | return n_stats; |
| 1517 | WARN_ON(n_stats == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
| 1519 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 1520 | return -EFAULT; |
| 1521 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1522 | stats.n_stats = n_stats; |
| 1523 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | if (!data) |
| 1525 | return -ENOMEM; |
| 1526 | |
| 1527 | ops->get_ethtool_stats(dev, &stats, data); |
| 1528 | |
| 1529 | ret = -EFAULT; |
| 1530 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 1531 | goto out; |
| 1532 | useraddr += sizeof(stats); |
| 1533 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) |
| 1534 | goto out; |
| 1535 | ret = 0; |
| 1536 | |
| 1537 | out: |
| 1538 | kfree(data); |
| 1539 | return ret; |
| 1540 | } |
| 1541 | |
viro@ftp.linux.org.uk | 0bf0519d | 2005-09-05 03:26:18 +0100 | [diff] [blame] | 1542 | 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] | 1543 | { |
| 1544 | struct ethtool_perm_addr epaddr; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1545 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1546 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1547 | return -EFAULT; |
| 1548 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1549 | if (epaddr.size < dev->addr_len) |
| 1550 | return -ETOOSMALL; |
| 1551 | epaddr.size = dev->addr_len; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1552 | |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1553 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1554 | return -EFAULT; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1555 | useraddr += sizeof(epaddr); |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1556 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
| 1557 | return -EFAULT; |
| 1558 | return 0; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1561 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
| 1562 | u32 cmd, u32 (*actor)(struct net_device *)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1563 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1564 | struct ethtool_value edata = { .cmd = cmd }; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1565 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1566 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1567 | return -EOPNOTSUPP; |
| 1568 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1569 | edata.data = actor(dev); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1570 | |
| 1571 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1572 | return -EFAULT; |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1576 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
| 1577 | void (*actor)(struct net_device *, u32)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1578 | { |
| 1579 | struct ethtool_value edata; |
| 1580 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1581 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1582 | return -EOPNOTSUPP; |
| 1583 | |
| 1584 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1585 | return -EFAULT; |
| 1586 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1587 | actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1588 | return 0; |
| 1589 | } |
| 1590 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1591 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
| 1592 | int (*actor)(struct net_device *, u32)) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1593 | { |
| 1594 | struct ethtool_value edata; |
| 1595 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1596 | if (!actor) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1597 | return -EOPNOTSUPP; |
| 1598 | |
| 1599 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1600 | return -EFAULT; |
| 1601 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1602 | return actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1605 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
| 1606 | char __user *useraddr) |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1607 | { |
| 1608 | struct ethtool_flash efl; |
| 1609 | |
| 1610 | if (copy_from_user(&efl, useraddr, sizeof(efl))) |
| 1611 | return -EFAULT; |
| 1612 | |
| 1613 | if (!dev->ethtool_ops->flash_device) |
| 1614 | return -EOPNOTSUPP; |
| 1615 | |
| 1616 | return dev->ethtool_ops->flash_device(dev, &efl); |
| 1617 | } |
| 1618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | /* The main entry point in this file. Called from net/core/dev.c */ |
| 1620 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1621 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1623 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | void __user *useraddr = ifr->ifr_data; |
| 1625 | u32 ethcmd; |
| 1626 | int rc; |
Michał Mirosław | 04ed3e7 | 2011-01-24 15:32:47 -0800 | [diff] [blame] | 1627 | u32 old_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | if (!dev || !netif_device_present(dev)) |
| 1630 | return -ENODEV; |
| 1631 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1632 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | return -EFAULT; |
| 1634 | |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 1635 | if (!dev->ethtool_ops) { |
| 1636 | /* ETHTOOL_GDRVINFO does not require any driver support. |
| 1637 | * It is also unprivileged and does not change anything, |
| 1638 | * so we can take a shortcut to it. */ |
| 1639 | if (ethcmd == ETHTOOL_GDRVINFO) |
| 1640 | return ethtool_get_drvinfo(dev, useraddr); |
| 1641 | else |
| 1642 | return -EOPNOTSUPP; |
| 1643 | } |
| 1644 | |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1645 | /* Allow some commands to be done by anyone */ |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1646 | switch (ethcmd) { |
stephen hemminger | 0fdc100 | 2010-08-23 10:24:18 +0000 | [diff] [blame] | 1647 | case ETHTOOL_GSET: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1648 | case ETHTOOL_GDRVINFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1649 | case ETHTOOL_GMSGLVL: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1650 | case ETHTOOL_GCOALESCE: |
| 1651 | case ETHTOOL_GRINGPARAM: |
| 1652 | case ETHTOOL_GPAUSEPARAM: |
| 1653 | case ETHTOOL_GRXCSUM: |
| 1654 | case ETHTOOL_GTXCSUM: |
| 1655 | case ETHTOOL_GSG: |
| 1656 | case ETHTOOL_GSTRINGS: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1657 | case ETHTOOL_GTSO: |
| 1658 | case ETHTOOL_GPERMADDR: |
| 1659 | case ETHTOOL_GUFO: |
| 1660 | case ETHTOOL_GGSO: |
stephen hemminger | 1cab819 | 2010-02-11 13:48:29 +0000 | [diff] [blame] | 1661 | case ETHTOOL_GGRO: |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1662 | case ETHTOOL_GFLAGS: |
| 1663 | case ETHTOOL_GPFLAGS: |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1664 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1665 | case ETHTOOL_GRXRINGS: |
| 1666 | case ETHTOOL_GRXCLSRLCNT: |
| 1667 | case ETHTOOL_GRXCLSRULE: |
| 1668 | case ETHTOOL_GRXCLSRLALL: |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1669 | case ETHTOOL_GFEATURES: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1670 | break; |
| 1671 | default: |
| 1672 | if (!capable(CAP_NET_ADMIN)) |
| 1673 | return -EPERM; |
| 1674 | } |
| 1675 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1676 | if (dev->ethtool_ops->begin) { |
| 1677 | rc = dev->ethtool_ops->begin(dev); |
| 1678 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | return rc; |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1680 | } |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1681 | old_features = dev->features; |
| 1682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | switch (ethcmd) { |
| 1684 | case ETHTOOL_GSET: |
| 1685 | rc = ethtool_get_settings(dev, useraddr); |
| 1686 | break; |
| 1687 | case ETHTOOL_SSET: |
| 1688 | rc = ethtool_set_settings(dev, useraddr); |
| 1689 | break; |
| 1690 | case ETHTOOL_GDRVINFO: |
| 1691 | rc = ethtool_get_drvinfo(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | break; |
| 1693 | case ETHTOOL_GREGS: |
| 1694 | rc = ethtool_get_regs(dev, useraddr); |
| 1695 | break; |
| 1696 | case ETHTOOL_GWOL: |
| 1697 | rc = ethtool_get_wol(dev, useraddr); |
| 1698 | break; |
| 1699 | case ETHTOOL_SWOL: |
| 1700 | rc = ethtool_set_wol(dev, useraddr); |
| 1701 | break; |
| 1702 | case ETHTOOL_GMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1703 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1704 | dev->ethtool_ops->get_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | break; |
| 1706 | case ETHTOOL_SMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1707 | rc = ethtool_set_value_void(dev, useraddr, |
| 1708 | dev->ethtool_ops->set_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | break; |
| 1710 | case ETHTOOL_NWAY_RST: |
| 1711 | rc = ethtool_nway_reset(dev); |
| 1712 | break; |
| 1713 | case ETHTOOL_GLINK: |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1714 | rc = ethtool_get_link(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | break; |
| 1716 | case ETHTOOL_GEEPROM: |
| 1717 | rc = ethtool_get_eeprom(dev, useraddr); |
| 1718 | break; |
| 1719 | case ETHTOOL_SEEPROM: |
| 1720 | rc = ethtool_set_eeprom(dev, useraddr); |
| 1721 | break; |
| 1722 | case ETHTOOL_GCOALESCE: |
| 1723 | rc = ethtool_get_coalesce(dev, useraddr); |
| 1724 | break; |
| 1725 | case ETHTOOL_SCOALESCE: |
| 1726 | rc = ethtool_set_coalesce(dev, useraddr); |
| 1727 | break; |
| 1728 | case ETHTOOL_GRINGPARAM: |
| 1729 | rc = ethtool_get_ringparam(dev, useraddr); |
| 1730 | break; |
| 1731 | case ETHTOOL_SRINGPARAM: |
| 1732 | rc = ethtool_set_ringparam(dev, useraddr); |
| 1733 | break; |
| 1734 | case ETHTOOL_GPAUSEPARAM: |
| 1735 | rc = ethtool_get_pauseparam(dev, useraddr); |
| 1736 | break; |
| 1737 | case ETHTOOL_SPAUSEPARAM: |
| 1738 | rc = ethtool_set_pauseparam(dev, useraddr); |
| 1739 | break; |
| 1740 | case ETHTOOL_GRXCSUM: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1741 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Sridhar Samudrala | 1896e61 | 2009-07-22 13:38:22 +0000 | [diff] [blame] | 1742 | (dev->ethtool_ops->get_rx_csum ? |
| 1743 | dev->ethtool_ops->get_rx_csum : |
| 1744 | ethtool_op_get_rx_csum)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | break; |
| 1746 | case ETHTOOL_SRXCSUM: |
Herbert Xu | b240a0e | 2008-12-15 23:44:31 -0800 | [diff] [blame] | 1747 | rc = ethtool_set_rx_csum(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | case ETHTOOL_TEST: |
| 1750 | rc = ethtool_self_test(dev, useraddr); |
| 1751 | break; |
| 1752 | case ETHTOOL_GSTRINGS: |
| 1753 | rc = ethtool_get_strings(dev, useraddr); |
| 1754 | break; |
| 1755 | case ETHTOOL_PHYS_ID: |
| 1756 | rc = ethtool_phys_id(dev, useraddr); |
| 1757 | break; |
| 1758 | case ETHTOOL_GSTATS: |
| 1759 | rc = ethtool_get_stats(dev, useraddr); |
| 1760 | break; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1761 | case ETHTOOL_GPERMADDR: |
| 1762 | rc = ethtool_get_perm_addr(dev, useraddr); |
| 1763 | break; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1764 | case ETHTOOL_GFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1765 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Sridhar Samudrala | 1896e61 | 2009-07-22 13:38:22 +0000 | [diff] [blame] | 1766 | (dev->ethtool_ops->get_flags ? |
| 1767 | dev->ethtool_ops->get_flags : |
| 1768 | ethtool_op_get_flags)); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1769 | break; |
| 1770 | case ETHTOOL_SFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1771 | rc = ethtool_set_value(dev, useraddr, |
| 1772 | dev->ethtool_ops->set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1773 | break; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1774 | case ETHTOOL_GPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1775 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1776 | dev->ethtool_ops->get_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1777 | break; |
| 1778 | case ETHTOOL_SPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1779 | rc = ethtool_set_value(dev, useraddr, |
| 1780 | dev->ethtool_ops->set_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1781 | break; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1782 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1783 | case ETHTOOL_GRXRINGS: |
| 1784 | case ETHTOOL_GRXCLSRLCNT: |
| 1785 | case ETHTOOL_GRXCLSRULE: |
| 1786 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1787 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1788 | break; |
| 1789 | case ETHTOOL_SRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1790 | case ETHTOOL_SRXCLSRLDEL: |
| 1791 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1792 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1793 | break; |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1794 | case ETHTOOL_FLASHDEV: |
| 1795 | rc = ethtool_flash_device(dev, useraddr); |
| 1796 | break; |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1797 | case ETHTOOL_RESET: |
| 1798 | rc = ethtool_reset(dev, useraddr); |
| 1799 | break; |
Peter P Waskiewicz Jr | 15682bc | 2010-02-10 20:03:05 -0800 | [diff] [blame] | 1800 | case ETHTOOL_SRXNTUPLE: |
| 1801 | rc = ethtool_set_rx_ntuple(dev, useraddr); |
| 1802 | break; |
| 1803 | case ETHTOOL_GRXNTUPLE: |
| 1804 | rc = ethtool_get_rx_ntuple(dev, useraddr); |
| 1805 | break; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 1806 | case ETHTOOL_GSSET_INFO: |
| 1807 | rc = ethtool_get_sset_info(dev, useraddr); |
| 1808 | break; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1809 | case ETHTOOL_GRXFHINDIR: |
| 1810 | rc = ethtool_get_rxfh_indir(dev, useraddr); |
| 1811 | break; |
| 1812 | case ETHTOOL_SRXFHINDIR: |
| 1813 | rc = ethtool_set_rxfh_indir(dev, useraddr); |
| 1814 | break; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1815 | case ETHTOOL_GFEATURES: |
| 1816 | rc = ethtool_get_features(dev, useraddr); |
| 1817 | break; |
| 1818 | case ETHTOOL_SFEATURES: |
| 1819 | rc = ethtool_set_features(dev, useraddr); |
| 1820 | break; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1821 | case ETHTOOL_GTXCSUM: |
| 1822 | case ETHTOOL_GSG: |
| 1823 | case ETHTOOL_GTSO: |
| 1824 | case ETHTOOL_GUFO: |
| 1825 | case ETHTOOL_GGSO: |
| 1826 | case ETHTOOL_GGRO: |
| 1827 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); |
| 1828 | break; |
| 1829 | case ETHTOOL_STXCSUM: |
| 1830 | case ETHTOOL_SSG: |
| 1831 | case ETHTOOL_STSO: |
| 1832 | case ETHTOOL_SUFO: |
| 1833 | case ETHTOOL_SGSO: |
| 1834 | case ETHTOOL_SGRO: |
| 1835 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); |
| 1836 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | default: |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 1838 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | } |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1840 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1841 | if (dev->ethtool_ops->complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | dev->ethtool_ops->complete(dev); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1843 | |
| 1844 | if (old_features != dev->features) |
| 1845 | netdev_features_change(dev); |
| 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | } |