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