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