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