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