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