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