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