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