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