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