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