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