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