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