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