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