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> |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 24 | #include <linux/rtnetlink.h> |
| 25 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Some useful ethtool_ops methods that're device independent. |
| 29 | * If we find that all drivers want to do the same thing here, |
| 30 | * we can turn these into dev_() function calls. |
| 31 | */ |
| 32 | |
| 33 | u32 ethtool_op_get_link(struct net_device *dev) |
| 34 | { |
| 35 | return netif_carrier_ok(dev) ? 1 : 0; |
| 36 | } |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 37 | EXPORT_SYMBOL(ethtool_op_get_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* Handlers for each ethtool command */ |
| 40 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 41 | #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 42 | |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 43 | static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { |
| 44 | [NETIF_F_SG_BIT] = "tx-scatter-gather", |
| 45 | [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 46 | [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", |
| 47 | [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", |
| 48 | [NETIF_F_HIGHDMA_BIT] = "highdma", |
| 49 | [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", |
| 50 | [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert", |
| 51 | |
| 52 | [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse", |
| 53 | [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter", |
| 54 | [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", |
| 55 | [NETIF_F_GSO_BIT] = "tx-generic-segmentation", |
| 56 | [NETIF_F_LLTX_BIT] = "tx-lockless", |
| 57 | [NETIF_F_NETNS_LOCAL_BIT] = "netns-local", |
| 58 | [NETIF_F_GRO_BIT] = "rx-gro", |
| 59 | [NETIF_F_LRO_BIT] = "rx-lro", |
| 60 | |
| 61 | [NETIF_F_TSO_BIT] = "tx-tcp-segmentation", |
| 62 | [NETIF_F_UFO_BIT] = "tx-udp-fragmentation", |
| 63 | [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", |
| 64 | [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", |
| 65 | [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", |
| 66 | [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", |
| 67 | |
| 68 | [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", |
| 69 | [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp", |
| 70 | [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu", |
| 71 | [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", |
| 72 | [NETIF_F_RXHASH_BIT] = "rx-hashing", |
| 73 | [NETIF_F_RXCSUM_BIT] = "rx-checksum", |
| 74 | [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", |
| 75 | [NETIF_F_LOOPBACK_BIT] = "loopback", |
Ben Greear | 36eabda3 | 2012-02-11 15:39:14 +0000 | [diff] [blame^] | 76 | [NETIF_F_RXFCS_BIT] = "rx-fcs", |
Michał Mirosław | 9d92154 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 79 | static int ethtool_get_features(struct net_device *dev, void __user *useraddr) |
| 80 | { |
| 81 | struct ethtool_gfeatures cmd = { |
| 82 | .cmd = ETHTOOL_GFEATURES, |
| 83 | .size = ETHTOOL_DEV_FEATURE_WORDS, |
| 84 | }; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 85 | struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 86 | u32 __user *sizeaddr; |
| 87 | u32 copy_size; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 88 | int i; |
| 89 | |
| 90 | /* in case feature bits run out again */ |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 91 | BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t)); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 92 | |
| 93 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 94 | features[i].available = (u32)(dev->hw_features >> (32 * i)); |
| 95 | features[i].requested = (u32)(dev->wanted_features >> (32 * i)); |
| 96 | features[i].active = (u32)(dev->features >> (32 * i)); |
| 97 | features[i].never_changed = |
| 98 | (u32)(NETIF_F_NEVER_CHANGE >> (32 * i)); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 99 | } |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 100 | |
| 101 | sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size); |
| 102 | if (get_user(copy_size, sizeaddr)) |
| 103 | return -EFAULT; |
| 104 | |
| 105 | if (copy_size > ETHTOOL_DEV_FEATURE_WORDS) |
| 106 | copy_size = ETHTOOL_DEV_FEATURE_WORDS; |
| 107 | |
| 108 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 109 | return -EFAULT; |
| 110 | useraddr += sizeof(cmd); |
| 111 | if (copy_to_user(useraddr, features, copy_size * sizeof(*features))) |
| 112 | return -EFAULT; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int ethtool_set_features(struct net_device *dev, void __user *useraddr) |
| 118 | { |
| 119 | struct ethtool_sfeatures cmd; |
| 120 | struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS]; |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 121 | netdev_features_t wanted = 0, valid = 0; |
| 122 | int i, ret = 0; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 123 | |
| 124 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 125 | return -EFAULT; |
| 126 | useraddr += sizeof(cmd); |
| 127 | |
| 128 | if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS) |
| 129 | return -EINVAL; |
| 130 | |
| 131 | if (copy_from_user(features, useraddr, sizeof(features))) |
| 132 | return -EFAULT; |
| 133 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 134 | for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) { |
Michał Mirosław | 09da71b | 2011-11-16 14:32:03 +0000 | [diff] [blame] | 135 | valid |= (netdev_features_t)features[i].valid << (32 * i); |
| 136 | wanted |= (netdev_features_t)features[i].requested << (32 * i); |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | if (valid & ~NETIF_F_ETHTOOL_BITS) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 140 | return -EINVAL; |
| 141 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 142 | if (valid & ~dev->hw_features) { |
| 143 | valid &= dev->hw_features; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 144 | ret |= ETHTOOL_F_UNSUPPORTED; |
| 145 | } |
| 146 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 147 | dev->wanted_features &= ~valid; |
| 148 | dev->wanted_features |= wanted & valid; |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 149 | __netdev_update_features(dev); |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 150 | |
Michał Mirosław | 475414f | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 151 | if ((dev->wanted_features ^ dev->features) & valid) |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 152 | ret |= ETHTOOL_F_WISH; |
| 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 157 | static int __ethtool_get_sset_count(struct net_device *dev, int sset) |
| 158 | { |
| 159 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 160 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 161 | if (sset == ETH_SS_FEATURES) |
| 162 | return ARRAY_SIZE(netdev_features_strings); |
| 163 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 164 | if (ops && ops->get_sset_count && ops->get_strings) |
| 165 | return ops->get_sset_count(dev, sset); |
| 166 | else |
| 167 | return -EOPNOTSUPP; |
| 168 | } |
| 169 | |
| 170 | static void __ethtool_get_strings(struct net_device *dev, |
| 171 | u32 stringset, u8 *data) |
| 172 | { |
| 173 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 174 | |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 175 | if (stringset == ETH_SS_FEATURES) |
| 176 | memcpy(data, netdev_features_strings, |
| 177 | sizeof(netdev_features_strings)); |
| 178 | else |
| 179 | /* ops->get_strings is valid because checked earlier */ |
| 180 | ops->get_strings(dev, stringset, data); |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 183 | static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 184 | { |
| 185 | /* feature masks of legacy discrete ethtool ops */ |
| 186 | |
| 187 | switch (eth_cmd) { |
| 188 | case ETHTOOL_GTXCSUM: |
| 189 | case ETHTOOL_STXCSUM: |
| 190 | return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM; |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 191 | case ETHTOOL_GRXCSUM: |
| 192 | case ETHTOOL_SRXCSUM: |
| 193 | return NETIF_F_RXCSUM; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 194 | case ETHTOOL_GSG: |
| 195 | case ETHTOOL_SSG: |
| 196 | return NETIF_F_SG; |
| 197 | case ETHTOOL_GTSO: |
| 198 | case ETHTOOL_STSO: |
| 199 | return NETIF_F_ALL_TSO; |
| 200 | case ETHTOOL_GUFO: |
| 201 | case ETHTOOL_SUFO: |
| 202 | return NETIF_F_UFO; |
| 203 | case ETHTOOL_GGSO: |
| 204 | case ETHTOOL_SGSO: |
| 205 | return NETIF_F_GSO; |
| 206 | case ETHTOOL_GGRO: |
| 207 | case ETHTOOL_SGRO: |
| 208 | return NETIF_F_GRO; |
| 209 | default: |
| 210 | BUG(); |
| 211 | } |
| 212 | } |
| 213 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 214 | static int ethtool_get_one_feature(struct net_device *dev, |
| 215 | char __user *useraddr, u32 ethcmd) |
| 216 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 217 | netdev_features_t mask = ethtool_get_feature_mask(ethcmd); |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 218 | struct ethtool_value edata = { |
| 219 | .cmd = ethcmd, |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 220 | .data = !!(dev->features & mask), |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 221 | }; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 222 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 223 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 224 | return -EFAULT; |
| 225 | return 0; |
| 226 | } |
| 227 | |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 228 | static int ethtool_set_one_feature(struct net_device *dev, |
| 229 | void __user *useraddr, u32 ethcmd) |
| 230 | { |
| 231 | struct ethtool_value edata; |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 232 | netdev_features_t mask; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 233 | |
| 234 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 235 | return -EFAULT; |
| 236 | |
Michał Mirosław | 8679488 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 237 | mask = ethtool_get_feature_mask(ethcmd); |
| 238 | mask &= dev->hw_features; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 239 | if (!mask) |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 240 | return -EOPNOTSUPP; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 241 | |
| 242 | if (edata.data) |
| 243 | dev->wanted_features |= mask; |
| 244 | else |
| 245 | dev->wanted_features &= ~mask; |
| 246 | |
| 247 | __netdev_update_features(dev); |
| 248 | |
| 249 | return 0; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 252 | #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \ |
| 253 | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH) |
| 254 | #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \ |
| 255 | NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH) |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 256 | |
| 257 | static u32 __ethtool_get_flags(struct net_device *dev) |
| 258 | { |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 259 | u32 flags = 0; |
| 260 | |
| 261 | if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO; |
| 262 | if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN; |
| 263 | if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN; |
| 264 | if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE; |
| 265 | if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH; |
| 266 | |
| 267 | return flags; |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int __ethtool_set_flags(struct net_device *dev, u32 data) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 271 | { |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 272 | netdev_features_t features = 0, changed; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 273 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 274 | if (data & ~ETH_ALL_FLAGS) |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 275 | return -EINVAL; |
| 276 | |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 277 | if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO; |
| 278 | if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX; |
| 279 | if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX; |
| 280 | if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE; |
| 281 | if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH; |
| 282 | |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 283 | /* allow changing only bits set in hw_features */ |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 284 | changed = (features ^ dev->features) & ETH_ALL_FEATURES; |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 285 | if (changed & ~dev->hw_features) |
| 286 | return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP; |
| 287 | |
| 288 | dev->wanted_features = |
Michał Mirosław | 02b3a55 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 289 | (dev->wanted_features & ~changed) | (features & changed); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 290 | |
Michał Mirosław | 6cb6a27 | 2011-04-02 22:48:47 -0700 | [diff] [blame] | 291 | __netdev_update_features(dev); |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 296 | int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 298 | ASSERT_RTNL(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 300 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | return -EOPNOTSUPP; |
| 302 | |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 303 | memset(cmd, 0, sizeof(struct ethtool_cmd)); |
| 304 | cmd->cmd = ETHTOOL_GSET; |
| 305 | return dev->ethtool_ops->get_settings(dev, cmd); |
| 306 | } |
| 307 | EXPORT_SYMBOL(__ethtool_get_settings); |
| 308 | |
| 309 | static int ethtool_get_settings(struct net_device *dev, void __user *useraddr) |
| 310 | { |
| 311 | int err; |
| 312 | struct ethtool_cmd cmd; |
| 313 | |
| 314 | err = __ethtool_get_settings(dev, &cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | if (err < 0) |
| 316 | return err; |
| 317 | |
| 318 | if (copy_to_user(useraddr, &cmd, sizeof(cmd))) |
| 319 | return -EFAULT; |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) |
| 324 | { |
| 325 | struct ethtool_cmd cmd; |
| 326 | |
| 327 | if (!dev->ethtool_ops->set_settings) |
| 328 | return -EOPNOTSUPP; |
| 329 | |
| 330 | if (copy_from_user(&cmd, useraddr, sizeof(cmd))) |
| 331 | return -EFAULT; |
| 332 | |
| 333 | return dev->ethtool_ops->set_settings(dev, &cmd); |
| 334 | } |
| 335 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 336 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
| 337 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | struct ethtool_drvinfo info; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 340 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | memset(&info, 0, sizeof(info)); |
| 343 | info.cmd = ETHTOOL_GDRVINFO; |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 344 | if (ops && ops->get_drvinfo) { |
| 345 | ops->get_drvinfo(dev, &info); |
| 346 | } else if (dev->dev.parent && dev->dev.parent->driver) { |
| 347 | strlcpy(info.bus_info, dev_name(dev->dev.parent), |
| 348 | sizeof(info.bus_info)); |
| 349 | strlcpy(info.driver, dev->dev.parent->driver->name, |
| 350 | sizeof(info.driver)); |
| 351 | } else { |
| 352 | return -EOPNOTSUPP; |
| 353 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 355 | /* |
| 356 | * this method of obtaining string set info is deprecated; |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 357 | * Use ETHTOOL_GSSET_INFO instead. |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 358 | */ |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 359 | if (ops && ops->get_sset_count) { |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 360 | int rc; |
| 361 | |
| 362 | rc = ops->get_sset_count(dev, ETH_SS_TEST); |
| 363 | if (rc >= 0) |
| 364 | info.testinfo_len = rc; |
| 365 | rc = ops->get_sset_count(dev, ETH_SS_STATS); |
| 366 | if (rc >= 0) |
| 367 | info.n_stats = rc; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 368 | rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS); |
| 369 | if (rc >= 0) |
| 370 | info.n_priv_flags = rc; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 371 | } |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 372 | if (ops && ops->get_regs_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | info.regdump_len = ops->get_regs_len(dev); |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 374 | if (ops && ops->get_eeprom_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | info.eedump_len = ops->get_eeprom_len(dev); |
| 376 | |
| 377 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 378 | return -EFAULT; |
| 379 | return 0; |
| 380 | } |
| 381 | |
Eric Dumazet | f5c445e | 2010-03-08 12:17:04 -0800 | [diff] [blame] | 382 | static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev, |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 383 | void __user *useraddr) |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 384 | { |
| 385 | struct ethtool_sset_info info; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 386 | u64 sset_mask; |
| 387 | int i, idx = 0, n_bits = 0, ret, rc; |
| 388 | u32 *info_buf = NULL; |
| 389 | |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 390 | if (copy_from_user(&info, useraddr, sizeof(info))) |
| 391 | return -EFAULT; |
| 392 | |
| 393 | /* store copy of mask, because we zero struct later on */ |
| 394 | sset_mask = info.sset_mask; |
| 395 | if (!sset_mask) |
| 396 | return 0; |
| 397 | |
| 398 | /* calculate size of return buffer */ |
Jeff Garzik | d17792e | 2010-03-04 08:21:53 +0000 | [diff] [blame] | 399 | n_bits = hweight64(sset_mask); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 400 | |
| 401 | memset(&info, 0, sizeof(info)); |
| 402 | info.cmd = ETHTOOL_GSSET_INFO; |
| 403 | |
| 404 | info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER); |
| 405 | if (!info_buf) |
| 406 | return -ENOMEM; |
| 407 | |
| 408 | /* |
| 409 | * fill return buffer based on input bitmask and successful |
| 410 | * get_sset_count return |
| 411 | */ |
| 412 | for (i = 0; i < 64; i++) { |
| 413 | if (!(sset_mask & (1ULL << i))) |
| 414 | continue; |
| 415 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 416 | rc = __ethtool_get_sset_count(dev, i); |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 417 | if (rc >= 0) { |
| 418 | info.sset_mask |= (1ULL << i); |
| 419 | info_buf[idx++] = rc; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | ret = -EFAULT; |
| 424 | if (copy_to_user(useraddr, &info, sizeof(info))) |
| 425 | goto out; |
| 426 | |
| 427 | useraddr += offsetof(struct ethtool_sset_info, data); |
| 428 | if (copy_to_user(useraddr, info_buf, idx * sizeof(u32))) |
| 429 | goto out; |
| 430 | |
| 431 | ret = 0; |
| 432 | |
| 433 | out: |
| 434 | kfree(info_buf); |
| 435 | return ret; |
| 436 | } |
| 437 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 438 | static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 439 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 440 | { |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 441 | struct ethtool_rxnfc info; |
| 442 | size_t info_size = sizeof(info); |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 443 | int rc; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 444 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 445 | if (!dev->ethtool_ops->set_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 446 | return -EOPNOTSUPP; |
| 447 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 448 | /* struct ethtool_rxnfc was originally defined for |
| 449 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 450 | * members. User-space might still be using that |
| 451 | * definition. */ |
| 452 | if (cmd == ETHTOOL_SRXFH) |
| 453 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 454 | sizeof(info.data)); |
| 455 | |
| 456 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 457 | return -EFAULT; |
| 458 | |
Ben Hutchings | 55664f3 | 2012-01-03 12:04:51 +0000 | [diff] [blame] | 459 | rc = dev->ethtool_ops->set_rxnfc(dev, &info); |
| 460 | if (rc) |
| 461 | return rc; |
| 462 | |
| 463 | if (cmd == ETHTOOL_SRXCLSRLINS && |
| 464 | copy_to_user(useraddr, &info, info_size)) |
| 465 | return -EFAULT; |
| 466 | |
| 467 | return 0; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 468 | } |
| 469 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 470 | static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 471 | u32 cmd, void __user *useraddr) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 472 | { |
| 473 | struct ethtool_rxnfc info; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 474 | size_t info_size = sizeof(info); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 475 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 476 | int ret; |
| 477 | void *rule_buf = NULL; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 478 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 479 | if (!ops->get_rxnfc) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 480 | return -EOPNOTSUPP; |
| 481 | |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 482 | /* struct ethtool_rxnfc was originally defined for |
| 483 | * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data |
| 484 | * members. User-space might still be using that |
| 485 | * definition. */ |
| 486 | if (cmd == ETHTOOL_GRXFH) |
| 487 | info_size = (offsetof(struct ethtool_rxnfc, data) + |
| 488 | sizeof(info.data)); |
| 489 | |
| 490 | if (copy_from_user(&info, useraddr, info_size)) |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 491 | return -EFAULT; |
| 492 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 493 | if (info.cmd == ETHTOOL_GRXCLSRLALL) { |
| 494 | if (info.rule_cnt > 0) { |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 495 | if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32)) |
Kees Cook | ae6df5f | 2010-10-07 10:03:48 +0000 | [diff] [blame] | 496 | rule_buf = kzalloc(info.rule_cnt * sizeof(u32), |
Ben Hutchings | db048b6 | 2010-06-28 08:44:07 +0000 | [diff] [blame] | 497 | GFP_USER); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 498 | if (!rule_buf) |
| 499 | return -ENOMEM; |
| 500 | } |
| 501 | } |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 502 | |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 503 | ret = ops->get_rxnfc(dev, &info, rule_buf); |
| 504 | if (ret < 0) |
| 505 | goto err_out; |
| 506 | |
| 507 | ret = -EFAULT; |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 508 | if (copy_to_user(useraddr, &info, info_size)) |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 509 | goto err_out; |
| 510 | |
| 511 | if (rule_buf) { |
| 512 | useraddr += offsetof(struct ethtool_rxnfc, rule_locs); |
| 513 | if (copy_to_user(useraddr, rule_buf, |
| 514 | info.rule_cnt * sizeof(u32))) |
| 515 | goto err_out; |
| 516 | } |
| 517 | ret = 0; |
| 518 | |
| 519 | err_out: |
Wei Yongjun | c9cacec | 2009-03-31 15:06:26 -0700 | [diff] [blame] | 520 | kfree(rule_buf); |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 521 | |
| 522 | return ret; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 525 | static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev, |
| 526 | void __user *useraddr) |
| 527 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 528 | u32 user_size, dev_size; |
| 529 | u32 *indir; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 530 | int ret; |
| 531 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 532 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
| 533 | !dev->ethtool_ops->get_rxfh_indir) |
| 534 | return -EOPNOTSUPP; |
| 535 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); |
| 536 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 537 | return -EOPNOTSUPP; |
| 538 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 539 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 540 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 541 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 542 | return -EFAULT; |
| 543 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 544 | if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size), |
| 545 | &dev_size, sizeof(dev_size))) |
| 546 | return -EFAULT; |
| 547 | |
| 548 | /* If the user buffer size is 0, this is just a query for the |
| 549 | * device table size. Otherwise, if it's smaller than the |
| 550 | * device table size it's an error. |
| 551 | */ |
| 552 | if (user_size < dev_size) |
| 553 | return user_size == 0 ? 0 : -EINVAL; |
| 554 | |
| 555 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 556 | if (!indir) |
| 557 | return -ENOMEM; |
| 558 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 559 | ret = dev->ethtool_ops->get_rxfh_indir(dev, indir); |
| 560 | if (ret) |
| 561 | goto out; |
| 562 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 563 | if (copy_to_user(useraddr + |
| 564 | offsetof(struct ethtool_rxfh_indir, ring_index[0]), |
| 565 | indir, dev_size * sizeof(indir[0]))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 566 | ret = -EFAULT; |
| 567 | |
| 568 | out: |
| 569 | kfree(indir); |
| 570 | return ret; |
| 571 | } |
| 572 | |
| 573 | static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev, |
| 574 | void __user *useraddr) |
| 575 | { |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 576 | struct ethtool_rxnfc rx_rings; |
| 577 | u32 user_size, dev_size, i; |
| 578 | u32 *indir; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 579 | int ret; |
| 580 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 581 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
| 582 | !dev->ethtool_ops->set_rxfh_indir || |
| 583 | !dev->ethtool_ops->get_rxnfc) |
| 584 | return -EOPNOTSUPP; |
| 585 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); |
| 586 | if (dev_size == 0) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 587 | return -EOPNOTSUPP; |
| 588 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 589 | if (copy_from_user(&user_size, |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 590 | useraddr + offsetof(struct ethtool_rxfh_indir, size), |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 591 | sizeof(user_size))) |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 592 | return -EFAULT; |
| 593 | |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 594 | if (user_size != 0 && user_size != dev_size) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 595 | return -EINVAL; |
| 596 | |
| 597 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 598 | if (!indir) |
| 599 | return -ENOMEM; |
| 600 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 601 | rx_rings.cmd = ETHTOOL_GRXRINGS; |
| 602 | ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL); |
| 603 | if (ret) |
| 604 | goto out; |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 605 | |
| 606 | if (user_size == 0) { |
| 607 | for (i = 0; i < dev_size; i++) |
| 608 | indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data); |
| 609 | } else { |
| 610 | if (copy_from_user(indir, |
| 611 | useraddr + |
| 612 | offsetof(struct ethtool_rxfh_indir, |
| 613 | ring_index[0]), |
| 614 | dev_size * sizeof(indir[0]))) { |
| 615 | ret = -EFAULT; |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 616 | goto out; |
| 617 | } |
Ben Hutchings | 278bc42 | 2011-12-15 13:56:49 +0000 | [diff] [blame] | 618 | |
| 619 | /* Validate ring indices */ |
| 620 | for (i = 0; i < dev_size; i++) { |
| 621 | if (indir[i] >= rx_rings.data) { |
| 622 | ret = -EINVAL; |
| 623 | goto out; |
| 624 | } |
| 625 | } |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 628 | ret = dev->ethtool_ops->set_rxfh_indir(dev, indir); |
| 629 | |
| 630 | out: |
| 631 | kfree(indir); |
| 632 | return ret; |
| 633 | } |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | static int ethtool_get_regs(struct net_device *dev, char __user *useraddr) |
| 636 | { |
| 637 | struct ethtool_regs regs; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 638 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | void *regbuf; |
| 640 | int reglen, ret; |
| 641 | |
| 642 | if (!ops->get_regs || !ops->get_regs_len) |
| 643 | return -EOPNOTSUPP; |
| 644 | |
| 645 | if (copy_from_user(®s, useraddr, sizeof(regs))) |
| 646 | return -EFAULT; |
| 647 | |
| 648 | reglen = ops->get_regs_len(dev); |
| 649 | if (regs.len > reglen) |
| 650 | regs.len = reglen; |
| 651 | |
Eugene Teo | b7c7d01 | 2011-01-24 21:05:17 -0800 | [diff] [blame] | 652 | regbuf = vzalloc(reglen); |
Ben Hutchings | 67ae7cf | 2011-07-21 15:25:30 -0700 | [diff] [blame] | 653 | if (reglen && !regbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | return -ENOMEM; |
| 655 | |
| 656 | ops->get_regs(dev, ®s, regbuf); |
| 657 | |
| 658 | ret = -EFAULT; |
| 659 | if (copy_to_user(useraddr, ®s, sizeof(regs))) |
| 660 | goto out; |
| 661 | useraddr += offsetof(struct ethtool_regs, data); |
Ben Hutchings | 67ae7cf | 2011-07-21 15:25:30 -0700 | [diff] [blame] | 662 | if (regbuf && copy_to_user(useraddr, regbuf, regs.len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | goto out; |
| 664 | ret = 0; |
| 665 | |
| 666 | out: |
Ben Hutchings | a77f5db | 2010-09-20 08:42:17 +0000 | [diff] [blame] | 667 | vfree(regbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return ret; |
| 669 | } |
| 670 | |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 671 | static int ethtool_reset(struct net_device *dev, char __user *useraddr) |
| 672 | { |
| 673 | struct ethtool_value reset; |
| 674 | int ret; |
| 675 | |
| 676 | if (!dev->ethtool_ops->reset) |
| 677 | return -EOPNOTSUPP; |
| 678 | |
| 679 | if (copy_from_user(&reset, useraddr, sizeof(reset))) |
| 680 | return -EFAULT; |
| 681 | |
| 682 | ret = dev->ethtool_ops->reset(dev, &reset.data); |
| 683 | if (ret) |
| 684 | return ret; |
| 685 | |
| 686 | if (copy_to_user(useraddr, &reset, sizeof(reset))) |
| 687 | return -EFAULT; |
| 688 | return 0; |
| 689 | } |
| 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) |
| 692 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 693 | struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | if (!dev->ethtool_ops->get_wol) |
| 696 | return -EOPNOTSUPP; |
| 697 | |
| 698 | dev->ethtool_ops->get_wol(dev, &wol); |
| 699 | |
| 700 | if (copy_to_user(useraddr, &wol, sizeof(wol))) |
| 701 | return -EFAULT; |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) |
| 706 | { |
| 707 | struct ethtool_wolinfo wol; |
| 708 | |
| 709 | if (!dev->ethtool_ops->set_wol) |
| 710 | return -EOPNOTSUPP; |
| 711 | |
| 712 | if (copy_from_user(&wol, useraddr, sizeof(wol))) |
| 713 | return -EFAULT; |
| 714 | |
| 715 | return dev->ethtool_ops->set_wol(dev, &wol); |
| 716 | } |
| 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | static int ethtool_nway_reset(struct net_device *dev) |
| 719 | { |
| 720 | if (!dev->ethtool_ops->nway_reset) |
| 721 | return -EOPNOTSUPP; |
| 722 | |
| 723 | return dev->ethtool_ops->nway_reset(dev); |
| 724 | } |
| 725 | |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 726 | static int ethtool_get_link(struct net_device *dev, char __user *useraddr) |
| 727 | { |
| 728 | struct ethtool_value edata = { .cmd = ETHTOOL_GLINK }; |
| 729 | |
| 730 | if (!dev->ethtool_ops->get_link) |
| 731 | return -EOPNOTSUPP; |
| 732 | |
| 733 | edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev); |
| 734 | |
| 735 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 736 | return -EFAULT; |
| 737 | return 0; |
| 738 | } |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) |
| 741 | { |
| 742 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 743 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 744 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 745 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 747 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (!ops->get_eeprom || !ops->get_eeprom_len) |
| 750 | return -EOPNOTSUPP; |
| 751 | |
| 752 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 753 | return -EFAULT; |
| 754 | |
| 755 | /* Check for wrap and zero */ |
| 756 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 757 | return -EINVAL; |
| 758 | |
| 759 | /* Check for exceeding total eeprom len */ |
| 760 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 761 | return -EINVAL; |
| 762 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 763 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (!data) |
| 765 | return -ENOMEM; |
| 766 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 767 | bytes_remaining = eeprom.len; |
| 768 | while (bytes_remaining > 0) { |
| 769 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 771 | ret = ops->get_eeprom(dev, &eeprom, data); |
| 772 | if (ret) |
| 773 | break; |
| 774 | if (copy_to_user(userbuf, data, eeprom.len)) { |
| 775 | ret = -EFAULT; |
| 776 | break; |
| 777 | } |
| 778 | userbuf += eeprom.len; |
| 779 | eeprom.offset += eeprom.len; |
| 780 | bytes_remaining -= eeprom.len; |
| 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Mandeep Singh Baines | c5835df | 2008-04-24 20:55:56 -0700 | [diff] [blame] | 783 | eeprom.len = userbuf - (useraddr + sizeof(eeprom)); |
| 784 | eeprom.offset -= eeprom.len; |
| 785 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom))) |
| 786 | ret = -EFAULT; |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | kfree(data); |
| 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr) |
| 793 | { |
| 794 | struct ethtool_eeprom eeprom; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 795 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 796 | void __user *userbuf = useraddr + sizeof(eeprom); |
| 797 | u32 bytes_remaining; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | u8 *data; |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 799 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
| 801 | if (!ops->set_eeprom || !ops->get_eeprom_len) |
| 802 | return -EOPNOTSUPP; |
| 803 | |
| 804 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom))) |
| 805 | return -EFAULT; |
| 806 | |
| 807 | /* Check for wrap and zero */ |
| 808 | if (eeprom.offset + eeprom.len <= eeprom.offset) |
| 809 | return -EINVAL; |
| 810 | |
| 811 | /* Check for exceeding total eeprom len */ |
| 812 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev)) |
| 813 | return -EINVAL; |
| 814 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 815 | data = kmalloc(PAGE_SIZE, GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if (!data) |
| 817 | return -ENOMEM; |
| 818 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 819 | bytes_remaining = eeprom.len; |
| 820 | while (bytes_remaining > 0) { |
| 821 | eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Mandeep Singh Baines | b131dd5 | 2008-04-15 19:24:17 -0700 | [diff] [blame] | 823 | if (copy_from_user(data, userbuf, eeprom.len)) { |
| 824 | ret = -EFAULT; |
| 825 | break; |
| 826 | } |
| 827 | ret = ops->set_eeprom(dev, &eeprom, data); |
| 828 | if (ret) |
| 829 | break; |
| 830 | userbuf += eeprom.len; |
| 831 | eeprom.offset += eeprom.len; |
| 832 | bytes_remaining -= eeprom.len; |
| 833 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | kfree(data); |
| 836 | return ret; |
| 837 | } |
| 838 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 839 | static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, |
| 840 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 842 | struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | if (!dev->ethtool_ops->get_coalesce) |
| 845 | return -EOPNOTSUPP; |
| 846 | |
| 847 | dev->ethtool_ops->get_coalesce(dev, &coalesce); |
| 848 | |
| 849 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce))) |
| 850 | return -EFAULT; |
| 851 | return 0; |
| 852 | } |
| 853 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 854 | static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, |
| 855 | void __user *useraddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | { |
| 857 | struct ethtool_coalesce coalesce; |
| 858 | |
David S. Miller | fa04ae5 | 2005-06-06 15:07:19 -0700 | [diff] [blame] | 859 | if (!dev->ethtool_ops->set_coalesce) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | return -EOPNOTSUPP; |
| 861 | |
| 862 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce))) |
| 863 | return -EFAULT; |
| 864 | |
| 865 | return dev->ethtool_ops->set_coalesce(dev, &coalesce); |
| 866 | } |
| 867 | |
| 868 | static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) |
| 869 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 870 | struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
| 872 | if (!dev->ethtool_ops->get_ringparam) |
| 873 | return -EOPNOTSUPP; |
| 874 | |
| 875 | dev->ethtool_ops->get_ringparam(dev, &ringparam); |
| 876 | |
| 877 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam))) |
| 878 | return -EFAULT; |
| 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) |
| 883 | { |
| 884 | struct ethtool_ringparam ringparam; |
| 885 | |
| 886 | if (!dev->ethtool_ops->set_ringparam) |
| 887 | return -EOPNOTSUPP; |
| 888 | |
| 889 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) |
| 890 | return -EFAULT; |
| 891 | |
| 892 | return dev->ethtool_ops->set_ringparam(dev, &ringparam); |
| 893 | } |
| 894 | |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 895 | static noinline_for_stack int ethtool_get_channels(struct net_device *dev, |
| 896 | void __user *useraddr) |
| 897 | { |
| 898 | struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS }; |
| 899 | |
| 900 | if (!dev->ethtool_ops->get_channels) |
| 901 | return -EOPNOTSUPP; |
| 902 | |
| 903 | dev->ethtool_ops->get_channels(dev, &channels); |
| 904 | |
| 905 | if (copy_to_user(useraddr, &channels, sizeof(channels))) |
| 906 | return -EFAULT; |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | static noinline_for_stack int ethtool_set_channels(struct net_device *dev, |
| 911 | void __user *useraddr) |
| 912 | { |
| 913 | struct ethtool_channels channels; |
| 914 | |
| 915 | if (!dev->ethtool_ops->set_channels) |
| 916 | return -EOPNOTSUPP; |
| 917 | |
| 918 | if (copy_from_user(&channels, useraddr, sizeof(channels))) |
| 919 | return -EFAULT; |
| 920 | |
| 921 | return dev->ethtool_ops->set_channels(dev, &channels); |
| 922 | } |
| 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr) |
| 925 | { |
| 926 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM }; |
| 927 | |
| 928 | if (!dev->ethtool_ops->get_pauseparam) |
| 929 | return -EOPNOTSUPP; |
| 930 | |
| 931 | dev->ethtool_ops->get_pauseparam(dev, &pauseparam); |
| 932 | |
| 933 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam))) |
| 934 | return -EFAULT; |
| 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr) |
| 939 | { |
| 940 | struct ethtool_pauseparam pauseparam; |
| 941 | |
Jeff Garzik | e1b90c4 | 2006-07-17 12:54:40 -0400 | [diff] [blame] | 942 | if (!dev->ethtool_ops->set_pauseparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | return -EOPNOTSUPP; |
| 944 | |
| 945 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam))) |
| 946 | return -EFAULT; |
| 947 | |
| 948 | return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); |
| 949 | } |
| 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | static int ethtool_self_test(struct net_device *dev, char __user *useraddr) |
| 952 | { |
| 953 | struct ethtool_test test; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 954 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 956 | int ret, test_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 958 | if (!ops->self_test || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 959 | return -EOPNOTSUPP; |
| 960 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 961 | test_len = ops->get_sset_count(dev, ETH_SS_TEST); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 962 | if (test_len < 0) |
| 963 | return test_len; |
| 964 | WARN_ON(test_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | if (copy_from_user(&test, useraddr, sizeof(test))) |
| 967 | return -EFAULT; |
| 968 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 969 | test.len = test_len; |
| 970 | data = kmalloc(test_len * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | if (!data) |
| 972 | return -ENOMEM; |
| 973 | |
| 974 | ops->self_test(dev, &test, data); |
| 975 | |
| 976 | ret = -EFAULT; |
| 977 | if (copy_to_user(useraddr, &test, sizeof(test))) |
| 978 | goto out; |
| 979 | useraddr += sizeof(test); |
| 980 | if (copy_to_user(useraddr, data, test.len * sizeof(u64))) |
| 981 | goto out; |
| 982 | ret = 0; |
| 983 | |
| 984 | out: |
| 985 | kfree(data); |
| 986 | return ret; |
| 987 | } |
| 988 | |
| 989 | static int ethtool_get_strings(struct net_device *dev, void __user *useraddr) |
| 990 | { |
| 991 | struct ethtool_gstrings gstrings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | u8 *data; |
| 993 | int ret; |
| 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings))) |
| 996 | return -EFAULT; |
| 997 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 998 | ret = __ethtool_get_sset_count(dev, gstrings.string_set); |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 999 | if (ret < 0) |
| 1000 | return ret; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1001 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1002 | gstrings.len = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | |
| 1004 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER); |
| 1005 | if (!data) |
| 1006 | return -ENOMEM; |
| 1007 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1008 | __ethtool_get_strings(dev, gstrings.string_set, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
| 1010 | ret = -EFAULT; |
| 1011 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings))) |
| 1012 | goto out; |
| 1013 | useraddr += sizeof(gstrings); |
| 1014 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) |
| 1015 | goto out; |
| 1016 | ret = 0; |
| 1017 | |
Michał Mirosław | 340ae16 | 2011-02-15 16:59:16 +0000 | [diff] [blame] | 1018 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | kfree(data); |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static int ethtool_phys_id(struct net_device *dev, void __user *useraddr) |
| 1024 | { |
| 1025 | struct ethtool_value id; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1026 | static bool busy; |
| 1027 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Stephen Hemminger | 1ab7b6a | 2011-04-14 23:46:06 -0700 | [diff] [blame] | 1029 | if (!dev->ethtool_ops->set_phys_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | return -EOPNOTSUPP; |
| 1031 | |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1032 | if (busy) |
| 1033 | return -EBUSY; |
| 1034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | if (copy_from_user(&id, useraddr, sizeof(id))) |
| 1036 | return -EFAULT; |
| 1037 | |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1038 | rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1039 | if (rc < 0) |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1040 | return rc; |
| 1041 | |
| 1042 | /* Drop the RTNL lock while waiting, but prevent reentry or |
| 1043 | * removal of the device. |
| 1044 | */ |
| 1045 | busy = true; |
| 1046 | dev_hold(dev); |
| 1047 | rtnl_unlock(); |
| 1048 | |
| 1049 | if (rc == 0) { |
| 1050 | /* Driver will handle this itself */ |
| 1051 | schedule_timeout_interruptible( |
Allan, Bruce W | 143780c | 2011-04-11 13:01:59 +0000 | [diff] [blame] | 1052 | id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1053 | } else { |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1054 | /* Driver expects to be called at twice the frequency in rc */ |
| 1055 | int n = rc * 2, i, interval = HZ / n; |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1056 | |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 1057 | /* Count down seconds */ |
| 1058 | do { |
| 1059 | /* Count down iterations per second */ |
| 1060 | i = n; |
| 1061 | do { |
| 1062 | rtnl_lock(); |
| 1063 | rc = dev->ethtool_ops->set_phys_id(dev, |
| 1064 | (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON); |
| 1065 | rtnl_unlock(); |
| 1066 | if (rc) |
| 1067 | break; |
| 1068 | schedule_timeout_interruptible(interval); |
| 1069 | } while (!signal_pending(current) && --i != 0); |
Ben Hutchings | 68f512f | 2011-04-02 00:35:15 +0100 | [diff] [blame] | 1070 | } while (!signal_pending(current) && |
| 1071 | (id.data == 0 || --id.data != 0)); |
| 1072 | } |
| 1073 | |
| 1074 | rtnl_lock(); |
| 1075 | dev_put(dev); |
| 1076 | busy = false; |
| 1077 | |
| 1078 | (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE); |
| 1079 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static int ethtool_get_stats(struct net_device *dev, void __user *useraddr) |
| 1083 | { |
| 1084 | struct ethtool_stats stats; |
Stephen Hemminger | 76fd859 | 2006-09-08 11:16:13 -0700 | [diff] [blame] | 1085 | const struct ethtool_ops *ops = dev->ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | u64 *data; |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1087 | int ret, n_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1089 | if (!ops->get_ethtool_stats || !ops->get_sset_count) |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1090 | return -EOPNOTSUPP; |
| 1091 | |
Ben Hutchings | a9828ec | 2009-10-01 11:33:03 +0000 | [diff] [blame] | 1092 | n_stats = ops->get_sset_count(dev, ETH_SS_STATS); |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1093 | if (n_stats < 0) |
| 1094 | return n_stats; |
| 1095 | WARN_ON(n_stats == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | if (copy_from_user(&stats, useraddr, sizeof(stats))) |
| 1098 | return -EFAULT; |
| 1099 | |
Jeff Garzik | ff03d49 | 2007-08-15 16:01:08 -0700 | [diff] [blame] | 1100 | stats.n_stats = n_stats; |
| 1101 | data = kmalloc(n_stats * sizeof(u64), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | if (!data) |
| 1103 | return -ENOMEM; |
| 1104 | |
| 1105 | ops->get_ethtool_stats(dev, &stats, data); |
| 1106 | |
| 1107 | ret = -EFAULT; |
| 1108 | if (copy_to_user(useraddr, &stats, sizeof(stats))) |
| 1109 | goto out; |
| 1110 | useraddr += sizeof(stats); |
| 1111 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64))) |
| 1112 | goto out; |
| 1113 | ret = 0; |
| 1114 | |
| 1115 | out: |
| 1116 | kfree(data); |
| 1117 | return ret; |
| 1118 | } |
| 1119 | |
viro@ftp.linux.org.uk | 0bf0519d | 2005-09-05 03:26:18 +0100 | [diff] [blame] | 1120 | 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] | 1121 | { |
| 1122 | struct ethtool_perm_addr epaddr; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1123 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1124 | if (copy_from_user(&epaddr, useraddr, sizeof(epaddr))) |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1125 | return -EFAULT; |
| 1126 | |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1127 | if (epaddr.size < dev->addr_len) |
| 1128 | return -ETOOSMALL; |
| 1129 | epaddr.size = dev->addr_len; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1130 | |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1131 | if (copy_to_user(useraddr, &epaddr, sizeof(epaddr))) |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1132 | return -EFAULT; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1133 | useraddr += sizeof(epaddr); |
Matthew Wilcox | 313674a | 2007-07-31 14:00:29 -0700 | [diff] [blame] | 1134 | if (copy_to_user(useraddr, dev->perm_addr, epaddr.size)) |
| 1135 | return -EFAULT; |
| 1136 | return 0; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1139 | static int ethtool_get_value(struct net_device *dev, char __user *useraddr, |
| 1140 | u32 cmd, u32 (*actor)(struct net_device *)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1141 | { |
Roland Dreier | 8e55742 | 2010-02-11 12:14:23 -0800 | [diff] [blame] | 1142 | struct ethtool_value edata = { .cmd = cmd }; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1143 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1144 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1145 | return -EOPNOTSUPP; |
| 1146 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1147 | edata.data = actor(dev); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1148 | |
| 1149 | if (copy_to_user(useraddr, &edata, sizeof(edata))) |
| 1150 | return -EFAULT; |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1154 | static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr, |
| 1155 | void (*actor)(struct net_device *, u32)) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1156 | { |
| 1157 | struct ethtool_value edata; |
| 1158 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1159 | if (!actor) |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1160 | return -EOPNOTSUPP; |
| 1161 | |
| 1162 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1163 | return -EFAULT; |
| 1164 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1165 | actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1169 | static int ethtool_set_value(struct net_device *dev, char __user *useraddr, |
| 1170 | int (*actor)(struct net_device *, u32)) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1171 | { |
| 1172 | struct ethtool_value edata; |
| 1173 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1174 | if (!actor) |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1175 | return -EOPNOTSUPP; |
| 1176 | |
| 1177 | if (copy_from_user(&edata, useraddr, sizeof(edata))) |
| 1178 | return -EFAULT; |
| 1179 | |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1180 | return actor(dev, edata.data); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1183 | static noinline_for_stack int ethtool_flash_device(struct net_device *dev, |
| 1184 | char __user *useraddr) |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1185 | { |
| 1186 | struct ethtool_flash efl; |
| 1187 | |
| 1188 | if (copy_from_user(&efl, useraddr, sizeof(efl))) |
| 1189 | return -EFAULT; |
| 1190 | |
| 1191 | if (!dev->ethtool_ops->flash_device) |
| 1192 | return -EOPNOTSUPP; |
| 1193 | |
Ben Hutchings | 786f528 | 2012-02-01 09:32:25 +0000 | [diff] [blame] | 1194 | efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 1195 | |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1196 | return dev->ethtool_ops->flash_device(dev, &efl); |
| 1197 | } |
| 1198 | |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1199 | static int ethtool_set_dump(struct net_device *dev, |
| 1200 | void __user *useraddr) |
| 1201 | { |
| 1202 | struct ethtool_dump dump; |
| 1203 | |
| 1204 | if (!dev->ethtool_ops->set_dump) |
| 1205 | return -EOPNOTSUPP; |
| 1206 | |
| 1207 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1208 | return -EFAULT; |
| 1209 | |
| 1210 | return dev->ethtool_ops->set_dump(dev, &dump); |
| 1211 | } |
| 1212 | |
| 1213 | static int ethtool_get_dump_flag(struct net_device *dev, |
| 1214 | void __user *useraddr) |
| 1215 | { |
| 1216 | int ret; |
| 1217 | struct ethtool_dump dump; |
| 1218 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1219 | |
| 1220 | if (!dev->ethtool_ops->get_dump_flag) |
| 1221 | return -EOPNOTSUPP; |
| 1222 | |
| 1223 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1224 | return -EFAULT; |
| 1225 | |
| 1226 | ret = ops->get_dump_flag(dev, &dump); |
| 1227 | if (ret) |
| 1228 | return ret; |
| 1229 | |
| 1230 | if (copy_to_user(useraddr, &dump, sizeof(dump))) |
| 1231 | return -EFAULT; |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | static int ethtool_get_dump_data(struct net_device *dev, |
| 1236 | void __user *useraddr) |
| 1237 | { |
| 1238 | int ret; |
| 1239 | __u32 len; |
| 1240 | struct ethtool_dump dump, tmp; |
| 1241 | const struct ethtool_ops *ops = dev->ethtool_ops; |
| 1242 | void *data = NULL; |
| 1243 | |
| 1244 | if (!dev->ethtool_ops->get_dump_data || |
| 1245 | !dev->ethtool_ops->get_dump_flag) |
| 1246 | return -EOPNOTSUPP; |
| 1247 | |
| 1248 | if (copy_from_user(&dump, useraddr, sizeof(dump))) |
| 1249 | return -EFAULT; |
| 1250 | |
| 1251 | memset(&tmp, 0, sizeof(tmp)); |
| 1252 | tmp.cmd = ETHTOOL_GET_DUMP_FLAG; |
| 1253 | ret = ops->get_dump_flag(dev, &tmp); |
| 1254 | if (ret) |
| 1255 | return ret; |
| 1256 | |
| 1257 | len = (tmp.len > dump.len) ? dump.len : tmp.len; |
| 1258 | if (!len) |
| 1259 | return -EFAULT; |
| 1260 | |
| 1261 | data = vzalloc(tmp.len); |
| 1262 | if (!data) |
| 1263 | return -ENOMEM; |
| 1264 | ret = ops->get_dump_data(dev, &dump, data); |
| 1265 | if (ret) |
| 1266 | goto out; |
| 1267 | |
| 1268 | if (copy_to_user(useraddr, &dump, sizeof(dump))) { |
| 1269 | ret = -EFAULT; |
| 1270 | goto out; |
| 1271 | } |
| 1272 | useraddr += offsetof(struct ethtool_dump, data); |
| 1273 | if (copy_to_user(useraddr, data, len)) |
| 1274 | ret = -EFAULT; |
| 1275 | out: |
| 1276 | vfree(data); |
| 1277 | return ret; |
| 1278 | } |
| 1279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | /* The main entry point in this file. Called from net/core/dev.c */ |
| 1281 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1282 | int dev_ethtool(struct net *net, struct ifreq *ifr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 1284 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | void __user *useraddr = ifr->ifr_data; |
| 1286 | u32 ethcmd; |
| 1287 | int rc; |
Michał Mirosław | 04ed3e7 | 2011-01-24 15:32:47 -0800 | [diff] [blame] | 1288 | u32 old_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | if (!dev || !netif_device_present(dev)) |
| 1291 | return -ENODEV; |
| 1292 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1293 | if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | return -EFAULT; |
| 1295 | |
Ben Hutchings | 0141480 | 2010-08-17 02:31:15 -0700 | [diff] [blame] | 1296 | if (!dev->ethtool_ops) { |
| 1297 | /* ETHTOOL_GDRVINFO does not require any driver support. |
| 1298 | * It is also unprivileged and does not change anything, |
| 1299 | * so we can take a shortcut to it. */ |
| 1300 | if (ethcmd == ETHTOOL_GDRVINFO) |
| 1301 | return ethtool_get_drvinfo(dev, useraddr); |
| 1302 | else |
| 1303 | return -EOPNOTSUPP; |
| 1304 | } |
| 1305 | |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1306 | /* Allow some commands to be done by anyone */ |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1307 | switch (ethcmd) { |
stephen hemminger | 0fdc100 | 2010-08-23 10:24:18 +0000 | [diff] [blame] | 1308 | case ETHTOOL_GSET: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1309 | case ETHTOOL_GDRVINFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1310 | case ETHTOOL_GMSGLVL: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1311 | case ETHTOOL_GCOALESCE: |
| 1312 | case ETHTOOL_GRINGPARAM: |
| 1313 | case ETHTOOL_GPAUSEPARAM: |
| 1314 | case ETHTOOL_GRXCSUM: |
| 1315 | case ETHTOOL_GTXCSUM: |
| 1316 | case ETHTOOL_GSG: |
Michał Mirosław | f80400a | 2012-01-22 00:20:40 +0000 | [diff] [blame] | 1317 | case ETHTOOL_GSSET_INFO: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1318 | case ETHTOOL_GSTRINGS: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1319 | case ETHTOOL_GTSO: |
| 1320 | case ETHTOOL_GPERMADDR: |
| 1321 | case ETHTOOL_GUFO: |
| 1322 | case ETHTOOL_GGSO: |
stephen hemminger | 1cab819 | 2010-02-11 13:48:29 +0000 | [diff] [blame] | 1323 | case ETHTOOL_GGRO: |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1324 | case ETHTOOL_GFLAGS: |
| 1325 | case ETHTOOL_GPFLAGS: |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1326 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1327 | case ETHTOOL_GRXRINGS: |
| 1328 | case ETHTOOL_GRXCLSRLCNT: |
| 1329 | case ETHTOOL_GRXCLSRULE: |
| 1330 | case ETHTOOL_GRXCLSRLALL: |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1331 | case ETHTOOL_GFEATURES: |
Stephen Hemminger | 75f3123 | 2006-09-28 15:13:37 -0700 | [diff] [blame] | 1332 | break; |
| 1333 | default: |
| 1334 | if (!capable(CAP_NET_ADMIN)) |
| 1335 | return -EPERM; |
| 1336 | } |
| 1337 | |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1338 | if (dev->ethtool_ops->begin) { |
| 1339 | rc = dev->ethtool_ops->begin(dev); |
| 1340 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | return rc; |
chavey | 97f8aef | 2010-04-07 21:54:42 -0700 | [diff] [blame] | 1342 | } |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1343 | old_features = dev->features; |
| 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | switch (ethcmd) { |
| 1346 | case ETHTOOL_GSET: |
| 1347 | rc = ethtool_get_settings(dev, useraddr); |
| 1348 | break; |
| 1349 | case ETHTOOL_SSET: |
| 1350 | rc = ethtool_set_settings(dev, useraddr); |
| 1351 | break; |
| 1352 | case ETHTOOL_GDRVINFO: |
| 1353 | rc = ethtool_get_drvinfo(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | break; |
| 1355 | case ETHTOOL_GREGS: |
| 1356 | rc = ethtool_get_regs(dev, useraddr); |
| 1357 | break; |
| 1358 | case ETHTOOL_GWOL: |
| 1359 | rc = ethtool_get_wol(dev, useraddr); |
| 1360 | break; |
| 1361 | case ETHTOOL_SWOL: |
| 1362 | rc = ethtool_set_wol(dev, useraddr); |
| 1363 | break; |
| 1364 | case ETHTOOL_GMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1365 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1366 | dev->ethtool_ops->get_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | break; |
| 1368 | case ETHTOOL_SMSGLVL: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1369 | rc = ethtool_set_value_void(dev, useraddr, |
| 1370 | dev->ethtool_ops->set_msglevel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | break; |
| 1372 | case ETHTOOL_NWAY_RST: |
| 1373 | rc = ethtool_nway_reset(dev); |
| 1374 | break; |
| 1375 | case ETHTOOL_GLINK: |
Ben Hutchings | e596e6e | 2010-12-09 12:08:35 +0000 | [diff] [blame] | 1376 | rc = ethtool_get_link(dev, useraddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | break; |
| 1378 | case ETHTOOL_GEEPROM: |
| 1379 | rc = ethtool_get_eeprom(dev, useraddr); |
| 1380 | break; |
| 1381 | case ETHTOOL_SEEPROM: |
| 1382 | rc = ethtool_set_eeprom(dev, useraddr); |
| 1383 | break; |
| 1384 | case ETHTOOL_GCOALESCE: |
| 1385 | rc = ethtool_get_coalesce(dev, useraddr); |
| 1386 | break; |
| 1387 | case ETHTOOL_SCOALESCE: |
| 1388 | rc = ethtool_set_coalesce(dev, useraddr); |
| 1389 | break; |
| 1390 | case ETHTOOL_GRINGPARAM: |
| 1391 | rc = ethtool_get_ringparam(dev, useraddr); |
| 1392 | break; |
| 1393 | case ETHTOOL_SRINGPARAM: |
| 1394 | rc = ethtool_set_ringparam(dev, useraddr); |
| 1395 | break; |
| 1396 | case ETHTOOL_GPAUSEPARAM: |
| 1397 | rc = ethtool_get_pauseparam(dev, useraddr); |
| 1398 | break; |
| 1399 | case ETHTOOL_SPAUSEPARAM: |
| 1400 | rc = ethtool_set_pauseparam(dev, useraddr); |
| 1401 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | case ETHTOOL_TEST: |
| 1403 | rc = ethtool_self_test(dev, useraddr); |
| 1404 | break; |
| 1405 | case ETHTOOL_GSTRINGS: |
| 1406 | rc = ethtool_get_strings(dev, useraddr); |
| 1407 | break; |
| 1408 | case ETHTOOL_PHYS_ID: |
| 1409 | rc = ethtool_phys_id(dev, useraddr); |
| 1410 | break; |
| 1411 | case ETHTOOL_GSTATS: |
| 1412 | rc = ethtool_get_stats(dev, useraddr); |
| 1413 | break; |
Jon Wetzel | a6f9a70 | 2005-08-20 17:15:54 -0700 | [diff] [blame] | 1414 | case ETHTOOL_GPERMADDR: |
| 1415 | rc = ethtool_get_perm_addr(dev, useraddr); |
| 1416 | break; |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1417 | case ETHTOOL_GFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1418 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
Michał Mirosław | bc5787c6 | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1419 | __ethtool_get_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | case ETHTOOL_SFLAGS: |
Michał Mirosław | da8ac86c | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1422 | rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags); |
Jeff Garzik | 3ae7c0b | 2007-08-15 16:00:51 -0700 | [diff] [blame] | 1423 | break; |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1424 | case ETHTOOL_GPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1425 | rc = ethtool_get_value(dev, useraddr, ethcmd, |
| 1426 | dev->ethtool_ops->get_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1427 | break; |
| 1428 | case ETHTOOL_SPFLAGS: |
Jeff Garzik | 13c99b2 | 2007-08-15 16:01:56 -0700 | [diff] [blame] | 1429 | rc = ethtool_set_value(dev, useraddr, |
| 1430 | dev->ethtool_ops->set_priv_flags); |
Jeff Garzik | 339bf02 | 2007-08-15 16:01:32 -0700 | [diff] [blame] | 1431 | break; |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1432 | case ETHTOOL_GRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1433 | case ETHTOOL_GRXRINGS: |
| 1434 | case ETHTOOL_GRXCLSRLCNT: |
| 1435 | case ETHTOOL_GRXCLSRULE: |
| 1436 | case ETHTOOL_GRXCLSRLALL: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1437 | rc = ethtool_get_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | case ETHTOOL_SRXFH: |
Santwona Behera | 59089d8 | 2009-02-20 00:58:13 -0800 | [diff] [blame] | 1440 | case ETHTOOL_SRXCLSRLDEL: |
| 1441 | case ETHTOOL_SRXCLSRLINS: |
Ben Hutchings | bf98843 | 2010-06-28 08:45:58 +0000 | [diff] [blame] | 1442 | rc = ethtool_set_rxnfc(dev, ethcmd, useraddr); |
Santwona Behera | 0853ad6 | 2008-07-02 03:47:41 -0700 | [diff] [blame] | 1443 | break; |
Ajit Khaparde | 05c6a8d | 2009-09-02 17:02:55 +0000 | [diff] [blame] | 1444 | case ETHTOOL_FLASHDEV: |
| 1445 | rc = ethtool_flash_device(dev, useraddr); |
| 1446 | break; |
Ben Hutchings | d73d3a8 | 2009-10-05 10:59:58 +0000 | [diff] [blame] | 1447 | case ETHTOOL_RESET: |
| 1448 | rc = ethtool_reset(dev, useraddr); |
| 1449 | break; |
Jeff Garzik | 723b2f5 | 2010-03-03 22:51:50 +0000 | [diff] [blame] | 1450 | case ETHTOOL_GSSET_INFO: |
| 1451 | rc = ethtool_get_sset_info(dev, useraddr); |
| 1452 | break; |
Ben Hutchings | a5b6ee2 | 2010-06-30 05:05:23 +0000 | [diff] [blame] | 1453 | case ETHTOOL_GRXFHINDIR: |
| 1454 | rc = ethtool_get_rxfh_indir(dev, useraddr); |
| 1455 | break; |
| 1456 | case ETHTOOL_SRXFHINDIR: |
| 1457 | rc = ethtool_set_rxfh_indir(dev, useraddr); |
| 1458 | break; |
Michał Mirosław | 5455c69 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1459 | case ETHTOOL_GFEATURES: |
| 1460 | rc = ethtool_get_features(dev, useraddr); |
| 1461 | break; |
| 1462 | case ETHTOOL_SFEATURES: |
| 1463 | rc = ethtool_set_features(dev, useraddr); |
| 1464 | break; |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1465 | case ETHTOOL_GTXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1466 | case ETHTOOL_GRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1467 | case ETHTOOL_GSG: |
| 1468 | case ETHTOOL_GTSO: |
| 1469 | case ETHTOOL_GUFO: |
| 1470 | case ETHTOOL_GGSO: |
| 1471 | case ETHTOOL_GGRO: |
| 1472 | rc = ethtool_get_one_feature(dev, useraddr, ethcmd); |
| 1473 | break; |
| 1474 | case ETHTOOL_STXCSUM: |
Michał Mirosław | e83d360 | 2011-02-15 16:59:18 +0000 | [diff] [blame] | 1475 | case ETHTOOL_SRXCSUM: |
Michał Mirosław | 0a41770 | 2011-02-15 16:59:17 +0000 | [diff] [blame] | 1476 | case ETHTOOL_SSG: |
| 1477 | case ETHTOOL_STSO: |
| 1478 | case ETHTOOL_SUFO: |
| 1479 | case ETHTOOL_SGSO: |
| 1480 | case ETHTOOL_SGRO: |
| 1481 | rc = ethtool_set_one_feature(dev, useraddr, ethcmd); |
| 1482 | break; |
amit salecha | 8b5933c | 2011-04-07 01:58:42 +0000 | [diff] [blame] | 1483 | case ETHTOOL_GCHANNELS: |
| 1484 | rc = ethtool_get_channels(dev, useraddr); |
| 1485 | break; |
| 1486 | case ETHTOOL_SCHANNELS: |
| 1487 | rc = ethtool_set_channels(dev, useraddr); |
| 1488 | break; |
Anirban Chakraborty | 29dd54b | 2011-05-12 12:48:32 +0000 | [diff] [blame] | 1489 | case ETHTOOL_SET_DUMP: |
| 1490 | rc = ethtool_set_dump(dev, useraddr); |
| 1491 | break; |
| 1492 | case ETHTOOL_GET_DUMP_FLAG: |
| 1493 | rc = ethtool_get_dump_flag(dev, useraddr); |
| 1494 | break; |
| 1495 | case ETHTOOL_GET_DUMP_DATA: |
| 1496 | rc = ethtool_get_dump_data(dev, useraddr); |
| 1497 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | default: |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 1499 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1501 | |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1502 | if (dev->ethtool_ops->complete) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | dev->ethtool_ops->complete(dev); |
Stephen Hemminger | d8a33ac | 2005-05-29 14:13:47 -0700 | [diff] [blame] | 1504 | |
| 1505 | if (old_features != dev->features) |
| 1506 | netdev_features_change(dev); |
| 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | } |