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