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