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