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