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