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