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