blob: 06dfb293e5aafa10ab2754bfb80d29ad29f2db95 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Wilcox61a44b92007-07-31 14:00:02 -07006 * the information ethtool needs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Matthew Wilcox61a44b92007-07-31 14:00:02 -07008 * 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 Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14#include <linux/module.h>
15#include <linux/types.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080016#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
Richard Cochranc8f3a8c2012-04-03 22:59:17 +000020#include <linux/net_tstamp.h>
21#include <linux/phy.h>
Jeff Garzikd17792e2010-03-04 08:21:53 +000022#include <linux/bitops.h>
chavey97f8aef2010-04-07 21:54:42 -070023#include <linux/uaccess.h>
David S. Miller73da16c2010-09-21 16:12:11 -070024#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Ben Hutchings68f512f2011-04-02 00:35:15 +010026#include <linux/rtnetlink.h>
27#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * Some useful ethtool_ops methods that're device independent.
31 * If we find that all drivers want to do the same thing here,
32 * we can turn these into dev_() function calls.
33 */
34
35u32 ethtool_op_get_link(struct net_device *dev)
36{
37 return netif_carrier_ok(dev) ? 1 : 0;
38}
chavey97f8aef2010-04-07 21:54:42 -070039EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Richard Cochran02eacbd2012-04-03 22:59:22 +000041int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
42{
43 info->so_timestamping =
44 SOF_TIMESTAMPING_TX_SOFTWARE |
45 SOF_TIMESTAMPING_RX_SOFTWARE |
46 SOF_TIMESTAMPING_SOFTWARE;
47 info->phc_index = -1;
48 return 0;
49}
50EXPORT_SYMBOL(ethtool_op_get_ts_info);
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/* Handlers for each ethtool command */
53
Michał Mirosław475414f2011-11-15 15:29:55 +000054#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
Michał Mirosław5455c692011-02-15 16:59:17 +000055
Michał Mirosław9d921542011-11-15 15:29:55 +000056static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
57 [NETIF_F_SG_BIT] = "tx-scatter-gather",
58 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
Michał Mirosław9d921542011-11-15 15:29:55 +000059 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
60 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
61 [NETIF_F_HIGHDMA_BIT] = "highdma",
62 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090063 [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
Michał Mirosław9d921542011-11-15 15:29:55 +000064
Fernando Luis Vazquez Cao788dfca2013-06-17 11:28:03 +090065 [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
66 [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
David S. Miller2d6577f2013-04-19 16:08:23 -040067 [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
68 [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
69 [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
Michał Mirosław9d921542011-11-15 15:29:55 +000070 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
71 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
72 [NETIF_F_LLTX_BIT] = "tx-lockless",
73 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
74 [NETIF_F_GRO_BIT] = "rx-gro",
75 [NETIF_F_LRO_BIT] = "rx-lro",
76
77 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
78 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
79 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
80 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
81 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
82 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
Pravin B Shelar68c33162013-02-14 14:02:41 +000083 [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
Eric Dumazetcb32f512013-10-19 11:42:57 -070084 [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
Eric Dumazet61c1db72013-10-20 20:47:30 -070085 [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
Pravin B Shelar73136262013-03-07 13:21:51 +000086 [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
Simon Horman0d89d202013-05-23 21:02:52 +000087 [NETIF_F_GSO_MPLS_BIT] = "tx-mpls-segmentation",
Michał Mirosław9d921542011-11-15 15:29:55 +000088
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 Greear36eabda32012-02-11 15:39:14 +000097 [NETIF_F_RXFCS_BIT] = "rx-fcs",
Ben Greear5e0c03c2012-02-11 15:39:45 +000098 [NETIF_F_RXALL_BIT] = "rx-all",
John Fastabenda6cc0cf2013-11-06 09:54:46 -080099 [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
Jiri Pirkod0290212014-04-02 23:09:31 +0200100 [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
Michał Mirosław9d921542011-11-15 15:29:55 +0000101};
102
Michał Mirosław5455c692011-02-15 16:59:17 +0000103static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
104{
105 struct ethtool_gfeatures cmd = {
106 .cmd = ETHTOOL_GFEATURES,
107 .size = ETHTOOL_DEV_FEATURE_WORDS,
108 };
Michał Mirosław475414f2011-11-15 15:29:55 +0000109 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +0000110 u32 __user *sizeaddr;
111 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +0000112 int i;
113
114 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +0000115 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +0000116
117 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000118 features[i].available = (u32)(dev->hw_features >> (32 * i));
119 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
120 features[i].active = (u32)(dev->features >> (32 * i));
121 features[i].never_changed =
122 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +0000123 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000124
125 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
126 if (get_user(copy_size, sizeaddr))
127 return -EFAULT;
128
129 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
130 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
131
132 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
133 return -EFAULT;
134 useraddr += sizeof(cmd);
135 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
136 return -EFAULT;
137
138 return 0;
139}
140
141static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
142{
143 struct ethtool_sfeatures cmd;
144 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000145 netdev_features_t wanted = 0, valid = 0;
146 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000147
148 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
149 return -EFAULT;
150 useraddr += sizeof(cmd);
151
152 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
153 return -EINVAL;
154
155 if (copy_from_user(features, useraddr, sizeof(features)))
156 return -EFAULT;
157
Michał Mirosław475414f2011-11-15 15:29:55 +0000158 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000159 valid |= (netdev_features_t)features[i].valid << (32 * i);
160 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000161 }
162
163 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000164 return -EINVAL;
165
Michał Mirosław475414f2011-11-15 15:29:55 +0000166 if (valid & ~dev->hw_features) {
167 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000168 ret |= ETHTOOL_F_UNSUPPORTED;
169 }
170
Michał Mirosław475414f2011-11-15 15:29:55 +0000171 dev->wanted_features &= ~valid;
172 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700173 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000174
Michał Mirosław475414f2011-11-15 15:29:55 +0000175 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000176 ret |= ETHTOOL_F_WISH;
177
178 return ret;
179}
180
Michał Mirosław340ae162011-02-15 16:59:16 +0000181static int __ethtool_get_sset_count(struct net_device *dev, int sset)
182{
183 const struct ethtool_ops *ops = dev->ethtool_ops;
184
Michał Mirosław5455c692011-02-15 16:59:17 +0000185 if (sset == ETH_SS_FEATURES)
186 return ARRAY_SIZE(netdev_features_strings);
187
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000188 if (ops->get_sset_count && ops->get_strings)
Michał Mirosław340ae162011-02-15 16:59:16 +0000189 return ops->get_sset_count(dev, sset);
190 else
191 return -EOPNOTSUPP;
192}
193
194static void __ethtool_get_strings(struct net_device *dev,
195 u32 stringset, u8 *data)
196{
197 const struct ethtool_ops *ops = dev->ethtool_ops;
198
Michał Mirosław5455c692011-02-15 16:59:17 +0000199 if (stringset == ETH_SS_FEATURES)
200 memcpy(data, netdev_features_strings,
201 sizeof(netdev_features_strings));
202 else
203 /* ops->get_strings is valid because checked earlier */
204 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000205}
206
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000207static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000208{
209 /* feature masks of legacy discrete ethtool ops */
210
211 switch (eth_cmd) {
212 case ETHTOOL_GTXCSUM:
213 case ETHTOOL_STXCSUM:
214 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000215 case ETHTOOL_GRXCSUM:
216 case ETHTOOL_SRXCSUM:
217 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000218 case ETHTOOL_GSG:
219 case ETHTOOL_SSG:
220 return NETIF_F_SG;
221 case ETHTOOL_GTSO:
222 case ETHTOOL_STSO:
223 return NETIF_F_ALL_TSO;
224 case ETHTOOL_GUFO:
225 case ETHTOOL_SUFO:
226 return NETIF_F_UFO;
227 case ETHTOOL_GGSO:
228 case ETHTOOL_SGSO:
229 return NETIF_F_GSO;
230 case ETHTOOL_GGRO:
231 case ETHTOOL_SGRO:
232 return NETIF_F_GRO;
233 default:
234 BUG();
235 }
236}
237
Michał Mirosław0a417702011-02-15 16:59:17 +0000238static int ethtool_get_one_feature(struct net_device *dev,
239 char __user *useraddr, u32 ethcmd)
240{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000241 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000242 struct ethtool_value edata = {
243 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000244 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000245 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000246
Michał Mirosław0a417702011-02-15 16:59:17 +0000247 if (copy_to_user(useraddr, &edata, sizeof(edata)))
248 return -EFAULT;
249 return 0;
250}
251
Michał Mirosław0a417702011-02-15 16:59:17 +0000252static int ethtool_set_one_feature(struct net_device *dev,
253 void __user *useraddr, u32 ethcmd)
254{
255 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000256 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000257
258 if (copy_from_user(&edata, useraddr, sizeof(edata)))
259 return -EFAULT;
260
Michał Mirosław86794882011-02-15 16:59:17 +0000261 mask = ethtool_get_feature_mask(ethcmd);
262 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000263 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000264 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000265
266 if (edata.data)
267 dev->wanted_features |= mask;
268 else
269 dev->wanted_features &= ~mask;
270
271 __netdev_update_features(dev);
272
273 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000274}
275
Michał Mirosław02b3a552011-11-15 15:29:55 +0000276#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
277 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
Patrick McHardyf6469682013-04-19 02:04:27 +0000278#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
279 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
280 NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000281
282static u32 __ethtool_get_flags(struct net_device *dev)
283{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000284 u32 flags = 0;
285
Dragos Foianu8a731252013-07-13 14:43:00 +0100286 if (dev->features & NETIF_F_LRO)
287 flags |= ETH_FLAG_LRO;
288 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
289 flags |= ETH_FLAG_RXVLAN;
290 if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
291 flags |= ETH_FLAG_TXVLAN;
292 if (dev->features & NETIF_F_NTUPLE)
293 flags |= ETH_FLAG_NTUPLE;
294 if (dev->features & NETIF_F_RXHASH)
295 flags |= ETH_FLAG_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000296
297 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000298}
299
300static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000301{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000302 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000303
Michał Mirosław02b3a552011-11-15 15:29:55 +0000304 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000305 return -EINVAL;
306
Dragos Foianu8a731252013-07-13 14:43:00 +0100307 if (data & ETH_FLAG_LRO)
308 features |= NETIF_F_LRO;
309 if (data & ETH_FLAG_RXVLAN)
310 features |= NETIF_F_HW_VLAN_CTAG_RX;
311 if (data & ETH_FLAG_TXVLAN)
312 features |= NETIF_F_HW_VLAN_CTAG_TX;
313 if (data & ETH_FLAG_NTUPLE)
314 features |= NETIF_F_NTUPLE;
315 if (data & ETH_FLAG_RXHASH)
316 features |= NETIF_F_RXHASH;
Michał Mirosław02b3a552011-11-15 15:29:55 +0000317
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000318 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000319 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000320 if (changed & ~dev->hw_features)
321 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
322
323 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000324 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000325
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700326 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000327
328 return 0;
329}
330
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000331int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000333 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000335 if (!dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return -EOPNOTSUPP;
337
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000338 memset(cmd, 0, sizeof(struct ethtool_cmd));
339 cmd->cmd = ETHTOOL_GSET;
340 return dev->ethtool_ops->get_settings(dev, cmd);
341}
342EXPORT_SYMBOL(__ethtool_get_settings);
343
344static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
345{
346 int err;
347 struct ethtool_cmd cmd;
348
349 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (err < 0)
351 return err;
352
353 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
354 return -EFAULT;
355 return 0;
356}
357
358static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
359{
360 struct ethtool_cmd cmd;
361
362 if (!dev->ethtool_ops->set_settings)
363 return -EOPNOTSUPP;
364
365 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
366 return -EFAULT;
367
368 return dev->ethtool_ops->set_settings(dev, &cmd);
369}
370
chavey97f8aef2010-04-07 21:54:42 -0700371static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
372 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700375 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 memset(&info, 0, sizeof(info));
378 info.cmd = ETHTOOL_GDRVINFO;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000379 if (ops->get_drvinfo) {
Ben Hutchings01414802010-08-17 02:31:15 -0700380 ops->get_drvinfo(dev, &info);
381 } else if (dev->dev.parent && dev->dev.parent->driver) {
382 strlcpy(info.bus_info, dev_name(dev->dev.parent),
383 sizeof(info.bus_info));
384 strlcpy(info.driver, dev->dev.parent->driver->name,
385 sizeof(info.driver));
386 } else {
387 return -EOPNOTSUPP;
388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Jeff Garzik723b2f52010-03-03 22:51:50 +0000390 /*
391 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000392 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000393 */
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000394 if (ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700395 int rc;
396
397 rc = ops->get_sset_count(dev, ETH_SS_TEST);
398 if (rc >= 0)
399 info.testinfo_len = rc;
400 rc = ops->get_sset_count(dev, ETH_SS_STATS);
401 if (rc >= 0)
402 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700403 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
404 if (rc >= 0)
405 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700406 }
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000407 if (ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 info.regdump_len = ops->get_regs_len(dev);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000409 if (ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 info.eedump_len = ops->get_eeprom_len(dev);
411
412 if (copy_to_user(useraddr, &info, sizeof(info)))
413 return -EFAULT;
414 return 0;
415}
416
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800417static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700418 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000419{
420 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000421 u64 sset_mask;
422 int i, idx = 0, n_bits = 0, ret, rc;
423 u32 *info_buf = NULL;
424
Jeff Garzik723b2f52010-03-03 22:51:50 +0000425 if (copy_from_user(&info, useraddr, sizeof(info)))
426 return -EFAULT;
427
428 /* store copy of mask, because we zero struct later on */
429 sset_mask = info.sset_mask;
430 if (!sset_mask)
431 return 0;
432
433 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000434 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000435
436 memset(&info, 0, sizeof(info));
437 info.cmd = ETHTOOL_GSSET_INFO;
438
439 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
440 if (!info_buf)
441 return -ENOMEM;
442
443 /*
444 * fill return buffer based on input bitmask and successful
445 * get_sset_count return
446 */
447 for (i = 0; i < 64; i++) {
448 if (!(sset_mask & (1ULL << i)))
449 continue;
450
Michał Mirosław340ae162011-02-15 16:59:16 +0000451 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000452 if (rc >= 0) {
453 info.sset_mask |= (1ULL << i);
454 info_buf[idx++] = rc;
455 }
456 }
457
458 ret = -EFAULT;
459 if (copy_to_user(useraddr, &info, sizeof(info)))
460 goto out;
461
462 useraddr += offsetof(struct ethtool_sset_info, data);
463 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
464 goto out;
465
466 ret = 0;
467
468out:
469 kfree(info_buf);
470 return ret;
471}
472
chavey97f8aef2010-04-07 21:54:42 -0700473static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000474 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700475{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000476 struct ethtool_rxnfc info;
477 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000478 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700479
Santwona Behera59089d82009-02-20 00:58:13 -0800480 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700481 return -EOPNOTSUPP;
482
Ben Hutchingsbf988432010-06-28 08:45:58 +0000483 /* struct ethtool_rxnfc was originally defined for
484 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
485 * members. User-space might still be using that
486 * definition. */
487 if (cmd == ETHTOOL_SRXFH)
488 info_size = (offsetof(struct ethtool_rxnfc, data) +
489 sizeof(info.data));
490
491 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700492 return -EFAULT;
493
Ben Hutchings55664f32012-01-03 12:04:51 +0000494 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
495 if (rc)
496 return rc;
497
498 if (cmd == ETHTOOL_SRXCLSRLINS &&
499 copy_to_user(useraddr, &info, info_size))
500 return -EFAULT;
501
502 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700503}
504
chavey97f8aef2010-04-07 21:54:42 -0700505static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000506 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700507{
508 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000509 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800510 const struct ethtool_ops *ops = dev->ethtool_ops;
511 int ret;
512 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700513
Santwona Behera59089d82009-02-20 00:58:13 -0800514 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700515 return -EOPNOTSUPP;
516
Ben Hutchingsbf988432010-06-28 08:45:58 +0000517 /* struct ethtool_rxnfc was originally defined for
518 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
519 * members. User-space might still be using that
520 * definition. */
521 if (cmd == ETHTOOL_GRXFH)
522 info_size = (offsetof(struct ethtool_rxnfc, data) +
523 sizeof(info.data));
524
525 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700526 return -EFAULT;
527
Santwona Behera59089d82009-02-20 00:58:13 -0800528 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
529 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000530 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000531 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000532 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800533 if (!rule_buf)
534 return -ENOMEM;
535 }
536 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700537
Santwona Behera59089d82009-02-20 00:58:13 -0800538 ret = ops->get_rxnfc(dev, &info, rule_buf);
539 if (ret < 0)
540 goto err_out;
541
542 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000543 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800544 goto err_out;
545
546 if (rule_buf) {
547 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
548 if (copy_to_user(useraddr, rule_buf,
549 info.rule_cnt * sizeof(u32)))
550 goto err_out;
551 }
552 ret = 0;
553
554err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700555 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800556
557 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700558}
559
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530560static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
561 struct ethtool_rxnfc *rx_rings,
562 u32 size)
563{
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100564 int i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530565
566 if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100567 return -EFAULT;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530568
569 /* Validate ring indices */
Ben Hutchingsfb95cd82014-05-15 00:46:45 +0100570 for (i = 0; i < size; i++)
571 if (indir[i] >= rx_rings->data)
572 return -EINVAL;
573
574 return 0;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530575}
576
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000577static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
578 void __user *useraddr)
579{
Ben Hutchings7850f632011-12-15 13:55:01 +0000580 u32 user_size, dev_size;
581 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000582 int ret;
583
Ben Hutchings7850f632011-12-15 13:55:01 +0000584 if (!dev->ethtool_ops->get_rxfh_indir_size ||
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100585 !dev->ethtool_ops->get_rxfh)
Ben Hutchings7850f632011-12-15 13:55:01 +0000586 return -EOPNOTSUPP;
587 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
588 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000589 return -EOPNOTSUPP;
590
Ben Hutchings7850f632011-12-15 13:55:01 +0000591 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000592 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000593 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000594 return -EFAULT;
595
Ben Hutchings7850f632011-12-15 13:55:01 +0000596 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
597 &dev_size, sizeof(dev_size)))
598 return -EFAULT;
599
600 /* If the user buffer size is 0, this is just a query for the
601 * device table size. Otherwise, if it's smaller than the
602 * device table size it's an error.
603 */
604 if (user_size < dev_size)
605 return user_size == 0 ? 0 : -EINVAL;
606
607 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000608 if (!indir)
609 return -ENOMEM;
610
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100611 ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000612 if (ret)
613 goto out;
614
Ben Hutchings7850f632011-12-15 13:55:01 +0000615 if (copy_to_user(useraddr +
616 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
617 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000618 ret = -EFAULT;
619
620out:
621 kfree(indir);
622 return ret;
623}
624
625static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
626 void __user *useraddr)
627{
Ben Hutchings7850f632011-12-15 13:55:01 +0000628 struct ethtool_rxnfc rx_rings;
629 u32 user_size, dev_size, i;
630 u32 *indir;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000631 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000632 int ret;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530633 u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000634
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100635 if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000636 !ops->get_rxnfc)
Ben Hutchings7850f632011-12-15 13:55:01 +0000637 return -EOPNOTSUPP;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000638
639 dev_size = ops->get_rxfh_indir_size(dev);
Ben Hutchings7850f632011-12-15 13:55:01 +0000640 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000641 return -EOPNOTSUPP;
642
Ben Hutchings7850f632011-12-15 13:55:01 +0000643 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000644 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000645 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000646 return -EFAULT;
647
Ben Hutchings278bc422011-12-15 13:56:49 +0000648 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000649 return -EINVAL;
650
651 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000652 if (!indir)
653 return -ENOMEM;
654
Ben Hutchings7850f632011-12-15 13:55:01 +0000655 rx_rings.cmd = ETHTOOL_GRXRINGS;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +0000656 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
Ben Hutchings7850f632011-12-15 13:55:01 +0000657 if (ret)
658 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000659
660 if (user_size == 0) {
661 for (i = 0; i < dev_size; i++)
662 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
663 } else {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530664 ret = ethtool_copy_validate_indir(indir,
665 useraddr + ringidx_offset,
666 &rx_rings,
667 dev_size);
668 if (ret)
Ben Hutchings7850f632011-12-15 13:55:01 +0000669 goto out;
Ben Hutchings7850f632011-12-15 13:55:01 +0000670 }
671
Ben Hutchingsfe62d002014-05-15 01:25:27 +0100672 ret = ops->set_rxfh(dev, indir, NULL);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000673
674out:
675 kfree(indir);
676 return ret;
677}
678
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530679static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
680 void __user *useraddr)
681{
682 int ret;
683 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100684 u32 user_indir_size, user_key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530685 u32 dev_indir_size = 0, dev_key_size = 0;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100686 struct ethtool_rxfh rxfh;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530687 u32 total_size;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100688 u32 indir_bytes;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530689 u32 *indir = NULL;
690 u8 *hkey = NULL;
691 u8 *rss_config;
692
693 if (!(dev->ethtool_ops->get_rxfh_indir_size ||
694 dev->ethtool_ops->get_rxfh_key_size) ||
695 !dev->ethtool_ops->get_rxfh)
696 return -EOPNOTSUPP;
697
698 if (ops->get_rxfh_indir_size)
699 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530700 if (ops->get_rxfh_key_size)
701 dev_key_size = ops->get_rxfh_key_size(dev);
702
703 if ((dev_key_size + dev_indir_size) == 0)
704 return -EOPNOTSUPP;
705
Ben Hutchingsf062a382014-05-15 16:28:07 +0100706 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530707 return -EFAULT;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100708 user_indir_size = rxfh.indir_size;
709 user_key_size = rxfh.key_size;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530710
Ben Hutchingsf062a382014-05-15 16:28:07 +0100711 /* Check that reserved fields are 0 for now */
712 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
713 return -EINVAL;
714
715 rxfh.indir_size = dev_indir_size;
716 rxfh.key_size = dev_key_size;
717 if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530718 return -EFAULT;
719
720 /* If the user buffer size is 0, this is just a query for the
721 * device table size and key size. Otherwise, if the User size is
722 * not equal to device table size or key size it's an error.
723 */
724 if (!user_indir_size && !user_key_size)
725 return 0;
726
727 if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
728 (user_key_size && (user_key_size != dev_key_size)))
729 return -EINVAL;
730
731 indir_bytes = user_indir_size * sizeof(indir[0]);
732 total_size = indir_bytes + user_key_size;
733 rss_config = kzalloc(total_size, GFP_USER);
734 if (!rss_config)
735 return -ENOMEM;
736
737 if (user_indir_size)
738 indir = (u32 *)rss_config;
739
740 if (user_key_size)
741 hkey = rss_config + indir_bytes;
742
743 ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey);
744 if (!ret) {
745 if (copy_to_user(useraddr +
746 offsetof(struct ethtool_rxfh, rss_config[0]),
747 rss_config, total_size))
748 ret = -EFAULT;
749 }
750
751 kfree(rss_config);
752
753 return ret;
754}
755
756static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
757 void __user *useraddr)
758{
759 int ret;
760 const struct ethtool_ops *ops = dev->ethtool_ops;
761 struct ethtool_rxnfc rx_rings;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100762 struct ethtool_rxfh rxfh;
763 u32 dev_indir_size = 0, dev_key_size = 0, i;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530764 u32 *indir = NULL, indir_bytes = 0;
765 u8 *hkey = NULL;
766 u8 *rss_config;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530767 u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
768
769 if (!(ops->get_rxfh_indir_size || ops->get_rxfh_key_size) ||
770 !ops->get_rxnfc || !ops->set_rxfh)
771 return -EOPNOTSUPP;
772
773 if (ops->get_rxfh_indir_size)
774 dev_indir_size = ops->get_rxfh_indir_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530775 if (ops->get_rxfh_key_size)
776 dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530777 if ((dev_key_size + dev_indir_size) == 0)
778 return -EOPNOTSUPP;
779
Ben Hutchingsf062a382014-05-15 16:28:07 +0100780 if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530781 return -EFAULT;
782
Ben Hutchingsf062a382014-05-15 16:28:07 +0100783 /* Check that reserved fields are 0 for now */
784 if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
785 return -EINVAL;
786
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530787 /* If either indir or hash key is valid, proceed further.
Ben Hutchings61d88c62014-05-19 01:29:42 +0100788 * It is not valid to request that both be unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530789 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100790 if ((rxfh.indir_size &&
791 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
792 rxfh.indir_size != dev_indir_size) ||
793 (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
794 (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
795 rxfh.key_size == 0))
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530796 return -EINVAL;
797
Ben Hutchingsf062a382014-05-15 16:28:07 +0100798 if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530799 indir_bytes = dev_indir_size * sizeof(indir[0]);
800
Ben Hutchingsf062a382014-05-15 16:28:07 +0100801 rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530802 if (!rss_config)
803 return -ENOMEM;
804
805 rx_rings.cmd = ETHTOOL_GRXRINGS;
806 ret = ops->get_rxnfc(dev, &rx_rings, NULL);
807 if (ret)
808 goto out;
809
Ben Hutchingsf062a382014-05-15 16:28:07 +0100810 /* rxfh.indir_size == 0 means reset the indir table to default.
811 * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530812 */
Ben Hutchingsf062a382014-05-15 16:28:07 +0100813 if (rxfh.indir_size &&
814 rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530815 indir = (u32 *)rss_config;
816 ret = ethtool_copy_validate_indir(indir,
817 useraddr + rss_cfg_offset,
818 &rx_rings,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100819 rxfh.indir_size);
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530820 if (ret)
821 goto out;
Ben Hutchingsf062a382014-05-15 16:28:07 +0100822 } else if (rxfh.indir_size == 0) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530823 indir = (u32 *)rss_config;
824 for (i = 0; i < dev_indir_size; i++)
825 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
826 }
827
Ben Hutchingsf062a382014-05-15 16:28:07 +0100828 if (rxfh.key_size) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530829 hkey = rss_config + indir_bytes;
830 if (copy_from_user(hkey,
831 useraddr + rss_cfg_offset + indir_bytes,
Ben Hutchingsf062a382014-05-15 16:28:07 +0100832 rxfh.key_size)) {
Venkata Duvvuru3de0b592014-04-21 15:37:59 +0530833 ret = -EFAULT;
834 goto out;
835 }
836 }
837
838 ret = ops->set_rxfh(dev, indir, hkey);
839
840out:
841 kfree(rss_config);
842 return ret;
843}
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
846{
847 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700848 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 void *regbuf;
850 int reglen, ret;
851
852 if (!ops->get_regs || !ops->get_regs_len)
853 return -EOPNOTSUPP;
854
855 if (copy_from_user(&regs, useraddr, sizeof(regs)))
856 return -EFAULT;
857
858 reglen = ops->get_regs_len(dev);
859 if (regs.len > reglen)
860 regs.len = reglen;
861
Eugene Teob7c7d012011-01-24 21:05:17 -0800862 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700863 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return -ENOMEM;
865
866 ops->get_regs(dev, &regs, regbuf);
867
868 ret = -EFAULT;
869 if (copy_to_user(useraddr, &regs, sizeof(regs)))
870 goto out;
871 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700872 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 goto out;
874 ret = 0;
875
876 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000877 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 return ret;
879}
880
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000881static int ethtool_reset(struct net_device *dev, char __user *useraddr)
882{
883 struct ethtool_value reset;
884 int ret;
885
886 if (!dev->ethtool_ops->reset)
887 return -EOPNOTSUPP;
888
889 if (copy_from_user(&reset, useraddr, sizeof(reset)))
890 return -EFAULT;
891
892 ret = dev->ethtool_ops->reset(dev, &reset.data);
893 if (ret)
894 return ret;
895
896 if (copy_to_user(useraddr, &reset, sizeof(reset)))
897 return -EFAULT;
898 return 0;
899}
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
902{
Roland Dreier8e557422010-02-11 12:14:23 -0800903 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 if (!dev->ethtool_ops->get_wol)
906 return -EOPNOTSUPP;
907
908 dev->ethtool_ops->get_wol(dev, &wol);
909
910 if (copy_to_user(useraddr, &wol, sizeof(wol)))
911 return -EFAULT;
912 return 0;
913}
914
915static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
916{
917 struct ethtool_wolinfo wol;
918
919 if (!dev->ethtool_ops->set_wol)
920 return -EOPNOTSUPP;
921
922 if (copy_from_user(&wol, useraddr, sizeof(wol)))
923 return -EFAULT;
924
925 return dev->ethtool_ops->set_wol(dev, &wol);
926}
927
Yuval Mintz80f12ec2012-06-06 17:13:06 +0000928static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
929{
930 struct ethtool_eee edata;
931 int rc;
932
933 if (!dev->ethtool_ops->get_eee)
934 return -EOPNOTSUPP;
935
936 memset(&edata, 0, sizeof(struct ethtool_eee));
937 edata.cmd = ETHTOOL_GEEE;
938 rc = dev->ethtool_ops->get_eee(dev, &edata);
939
940 if (rc)
941 return rc;
942
943 if (copy_to_user(useraddr, &edata, sizeof(edata)))
944 return -EFAULT;
945
946 return 0;
947}
948
949static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
950{
951 struct ethtool_eee edata;
952
953 if (!dev->ethtool_ops->set_eee)
954 return -EOPNOTSUPP;
955
956 if (copy_from_user(&edata, useraddr, sizeof(edata)))
957 return -EFAULT;
958
959 return dev->ethtool_ops->set_eee(dev, &edata);
960}
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962static int ethtool_nway_reset(struct net_device *dev)
963{
964 if (!dev->ethtool_ops->nway_reset)
965 return -EOPNOTSUPP;
966
967 return dev->ethtool_ops->nway_reset(dev);
968}
969
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000970static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
971{
972 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
973
974 if (!dev->ethtool_ops->get_link)
975 return -EOPNOTSUPP;
976
977 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
978
979 if (copy_to_user(useraddr, &edata, sizeof(edata)))
980 return -EFAULT;
981 return 0;
982}
983
Ben Hutchings081d0942012-04-12 00:42:12 +0000984static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
985 int (*getter)(struct net_device *,
986 struct ethtool_eeprom *, u8 *),
987 u32 total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 struct ethtool_eeprom eeprom;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700990 void __user *userbuf = useraddr + sizeof(eeprom);
991 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700993 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
996 return -EFAULT;
997
998 /* Check for wrap and zero */
999 if (eeprom.offset + eeprom.len <= eeprom.offset)
1000 return -EINVAL;
1001
1002 /* Check for exceeding total eeprom len */
Ben Hutchings081d0942012-04-12 00:42:12 +00001003 if (eeprom.offset + eeprom.len > total_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 return -EINVAL;
1005
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001006 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (!data)
1008 return -ENOMEM;
1009
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001010 bytes_remaining = eeprom.len;
1011 while (bytes_remaining > 0) {
1012 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Ben Hutchings081d0942012-04-12 00:42:12 +00001014 ret = getter(dev, &eeprom, data);
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001015 if (ret)
1016 break;
1017 if (copy_to_user(userbuf, data, eeprom.len)) {
1018 ret = -EFAULT;
1019 break;
1020 }
1021 userbuf += eeprom.len;
1022 eeprom.offset += eeprom.len;
1023 bytes_remaining -= eeprom.len;
1024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -07001026 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1027 eeprom.offset -= eeprom.len;
1028 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1029 ret = -EFAULT;
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 kfree(data);
1032 return ret;
1033}
1034
Ben Hutchings081d0942012-04-12 00:42:12 +00001035static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1036{
1037 const struct ethtool_ops *ops = dev->ethtool_ops;
1038
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001039 if (!ops->get_eeprom || !ops->get_eeprom_len ||
1040 !ops->get_eeprom_len(dev))
Ben Hutchings081d0942012-04-12 00:42:12 +00001041 return -EOPNOTSUPP;
1042
1043 return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
1044 ops->get_eeprom_len(dev));
1045}
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1048{
1049 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001050 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001051 void __user *userbuf = useraddr + sizeof(eeprom);
1052 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001054 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Guenter Roecke0fb6fb2014-10-30 20:50:15 -07001056 if (!ops->set_eeprom || !ops->get_eeprom_len ||
1057 !ops->get_eeprom_len(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 return -EOPNOTSUPP;
1059
1060 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1061 return -EFAULT;
1062
1063 /* Check for wrap and zero */
1064 if (eeprom.offset + eeprom.len <= eeprom.offset)
1065 return -EINVAL;
1066
1067 /* Check for exceeding total eeprom len */
1068 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1069 return -EINVAL;
1070
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001071 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 if (!data)
1073 return -ENOMEM;
1074
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001075 bytes_remaining = eeprom.len;
1076 while (bytes_remaining > 0) {
1077 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001079 if (copy_from_user(data, userbuf, eeprom.len)) {
1080 ret = -EFAULT;
1081 break;
1082 }
1083 ret = ops->set_eeprom(dev, &eeprom, data);
1084 if (ret)
1085 break;
1086 userbuf += eeprom.len;
1087 eeprom.offset += eeprom.len;
1088 bytes_remaining -= eeprom.len;
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 kfree(data);
1092 return ret;
1093}
1094
chavey97f8aef2010-04-07 21:54:42 -07001095static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1096 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Roland Dreier8e557422010-02-11 12:14:23 -08001098 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 if (!dev->ethtool_ops->get_coalesce)
1101 return -EOPNOTSUPP;
1102
1103 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1104
1105 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1106 return -EFAULT;
1107 return 0;
1108}
1109
chavey97f8aef2010-04-07 21:54:42 -07001110static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1111 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
1113 struct ethtool_coalesce coalesce;
1114
David S. Millerfa04ae52005-06-06 15:07:19 -07001115 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 return -EOPNOTSUPP;
1117
1118 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1119 return -EFAULT;
1120
1121 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1122}
1123
1124static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1125{
Roland Dreier8e557422010-02-11 12:14:23 -08001126 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 if (!dev->ethtool_ops->get_ringparam)
1129 return -EOPNOTSUPP;
1130
1131 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1132
1133 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1134 return -EFAULT;
1135 return 0;
1136}
1137
1138static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1139{
1140 struct ethtool_ringparam ringparam;
1141
1142 if (!dev->ethtool_ops->set_ringparam)
1143 return -EOPNOTSUPP;
1144
1145 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1146 return -EFAULT;
1147
1148 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1149}
1150
amit salecha8b5933c2011-04-07 01:58:42 +00001151static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
1152 void __user *useraddr)
1153{
1154 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
1155
1156 if (!dev->ethtool_ops->get_channels)
1157 return -EOPNOTSUPP;
1158
1159 dev->ethtool_ops->get_channels(dev, &channels);
1160
1161 if (copy_to_user(useraddr, &channels, sizeof(channels)))
1162 return -EFAULT;
1163 return 0;
1164}
1165
1166static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
1167 void __user *useraddr)
1168{
1169 struct ethtool_channels channels;
1170
1171 if (!dev->ethtool_ops->set_channels)
1172 return -EOPNOTSUPP;
1173
1174 if (copy_from_user(&channels, useraddr, sizeof(channels)))
1175 return -EFAULT;
1176
1177 return dev->ethtool_ops->set_channels(dev, &channels);
1178}
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1181{
1182 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1183
1184 if (!dev->ethtool_ops->get_pauseparam)
1185 return -EOPNOTSUPP;
1186
1187 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1188
1189 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1190 return -EFAULT;
1191 return 0;
1192}
1193
1194static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1195{
1196 struct ethtool_pauseparam pauseparam;
1197
Jeff Garzike1b90c42006-07-17 12:54:40 -04001198 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 return -EOPNOTSUPP;
1200
1201 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1202 return -EFAULT;
1203
1204 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1205}
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1208{
1209 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001210 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001212 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001214 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001215 return -EOPNOTSUPP;
1216
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001217 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001218 if (test_len < 0)
1219 return test_len;
1220 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 if (copy_from_user(&test, useraddr, sizeof(test)))
1223 return -EFAULT;
1224
Jeff Garzikff03d492007-08-15 16:01:08 -07001225 test.len = test_len;
1226 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 if (!data)
1228 return -ENOMEM;
1229
1230 ops->self_test(dev, &test, data);
1231
1232 ret = -EFAULT;
1233 if (copy_to_user(useraddr, &test, sizeof(test)))
1234 goto out;
1235 useraddr += sizeof(test);
1236 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1237 goto out;
1238 ret = 0;
1239
1240 out:
1241 kfree(data);
1242 return ret;
1243}
1244
1245static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1246{
1247 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 u8 *data;
1249 int ret;
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1252 return -EFAULT;
1253
Michał Mirosław340ae162011-02-15 16:59:16 +00001254 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001255 if (ret < 0)
1256 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001257
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001258 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1261 if (!data)
1262 return -ENOMEM;
1263
Michał Mirosław340ae162011-02-15 16:59:16 +00001264 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 ret = -EFAULT;
1267 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1268 goto out;
1269 useraddr += sizeof(gstrings);
1270 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1271 goto out;
1272 ret = 0;
1273
Michał Mirosław340ae162011-02-15 16:59:16 +00001274out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 kfree(data);
1276 return ret;
1277}
1278
1279static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1280{
1281 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001282 static bool busy;
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001283 const struct ethtool_ops *ops = dev->ethtool_ops;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001284 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001286 if (!ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 return -EOPNOTSUPP;
1288
Ben Hutchings68f512f2011-04-02 00:35:15 +01001289 if (busy)
1290 return -EBUSY;
1291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 if (copy_from_user(&id, useraddr, sizeof(id)))
1293 return -EFAULT;
1294
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001295 rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001296 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001297 return rc;
1298
1299 /* Drop the RTNL lock while waiting, but prevent reentry or
1300 * removal of the device.
1301 */
1302 busy = true;
1303 dev_hold(dev);
1304 rtnl_unlock();
1305
1306 if (rc == 0) {
1307 /* Driver will handle this itself */
1308 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001309 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001310 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001311 /* Driver expects to be called at twice the frequency in rc */
1312 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001313
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001314 /* Count down seconds */
1315 do {
1316 /* Count down iterations per second */
1317 i = n;
1318 do {
1319 rtnl_lock();
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001320 rc = ops->set_phys_id(dev,
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001321 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1322 rtnl_unlock();
1323 if (rc)
1324 break;
1325 schedule_timeout_interruptible(interval);
1326 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001327 } while (!signal_pending(current) &&
1328 (id.data == 0 || --id.data != 0));
1329 }
1330
1331 rtnl_lock();
1332 dev_put(dev);
1333 busy = false;
1334
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001335 (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001336 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
1339static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1340{
1341 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001342 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001344 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001346 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001347 return -EOPNOTSUPP;
1348
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001349 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001350 if (n_stats < 0)
1351 return n_stats;
1352 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
1354 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1355 return -EFAULT;
1356
Jeff Garzikff03d492007-08-15 16:01:08 -07001357 stats.n_stats = n_stats;
1358 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 if (!data)
1360 return -ENOMEM;
1361
1362 ops->get_ethtool_stats(dev, &stats, data);
1363
1364 ret = -EFAULT;
1365 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1366 goto out;
1367 useraddr += sizeof(stats);
1368 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1369 goto out;
1370 ret = 0;
1371
1372 out:
1373 kfree(data);
1374 return ret;
1375}
1376
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001377static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001378{
1379 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001380
Matthew Wilcox313674a2007-07-31 14:00:29 -07001381 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001382 return -EFAULT;
1383
Matthew Wilcox313674a2007-07-31 14:00:29 -07001384 if (epaddr.size < dev->addr_len)
1385 return -ETOOSMALL;
1386 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001387
Jon Wetzela6f9a702005-08-20 17:15:54 -07001388 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001389 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001390 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001391 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1392 return -EFAULT;
1393 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001394}
1395
Jeff Garzik13c99b22007-08-15 16:01:56 -07001396static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1397 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001398{
Roland Dreier8e557422010-02-11 12:14:23 -08001399 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001400
Jeff Garzik13c99b22007-08-15 16:01:56 -07001401 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001402 return -EOPNOTSUPP;
1403
Jeff Garzik13c99b22007-08-15 16:01:56 -07001404 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001405
1406 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1407 return -EFAULT;
1408 return 0;
1409}
1410
Jeff Garzik13c99b22007-08-15 16:01:56 -07001411static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1412 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001413{
1414 struct ethtool_value edata;
1415
Jeff Garzik13c99b22007-08-15 16:01:56 -07001416 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001417 return -EOPNOTSUPP;
1418
1419 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1420 return -EFAULT;
1421
Jeff Garzik13c99b22007-08-15 16:01:56 -07001422 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001423 return 0;
1424}
1425
Jeff Garzik13c99b22007-08-15 16:01:56 -07001426static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1427 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001428{
1429 struct ethtool_value edata;
1430
Jeff Garzik13c99b22007-08-15 16:01:56 -07001431 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001432 return -EOPNOTSUPP;
1433
1434 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1435 return -EFAULT;
1436
Jeff Garzik13c99b22007-08-15 16:01:56 -07001437 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001438}
1439
chavey97f8aef2010-04-07 21:54:42 -07001440static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1441 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001442{
1443 struct ethtool_flash efl;
1444
1445 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1446 return -EFAULT;
1447
1448 if (!dev->ethtool_ops->flash_device)
1449 return -EOPNOTSUPP;
1450
Ben Hutchings786f5282012-02-01 09:32:25 +00001451 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1452
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001453 return dev->ethtool_ops->flash_device(dev, &efl);
1454}
1455
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001456static int ethtool_set_dump(struct net_device *dev,
1457 void __user *useraddr)
1458{
1459 struct ethtool_dump dump;
1460
1461 if (!dev->ethtool_ops->set_dump)
1462 return -EOPNOTSUPP;
1463
1464 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1465 return -EFAULT;
1466
1467 return dev->ethtool_ops->set_dump(dev, &dump);
1468}
1469
1470static int ethtool_get_dump_flag(struct net_device *dev,
1471 void __user *useraddr)
1472{
1473 int ret;
1474 struct ethtool_dump dump;
1475 const struct ethtool_ops *ops = dev->ethtool_ops;
1476
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001477 if (!ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001478 return -EOPNOTSUPP;
1479
1480 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1481 return -EFAULT;
1482
1483 ret = ops->get_dump_flag(dev, &dump);
1484 if (ret)
1485 return ret;
1486
1487 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1488 return -EFAULT;
1489 return 0;
1490}
1491
1492static int ethtool_get_dump_data(struct net_device *dev,
1493 void __user *useraddr)
1494{
1495 int ret;
1496 __u32 len;
1497 struct ethtool_dump dump, tmp;
1498 const struct ethtool_ops *ops = dev->ethtool_ops;
1499 void *data = NULL;
1500
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001501 if (!ops->get_dump_data || !ops->get_dump_flag)
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001502 return -EOPNOTSUPP;
1503
1504 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1505 return -EFAULT;
1506
1507 memset(&tmp, 0, sizeof(tmp));
1508 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1509 ret = ops->get_dump_flag(dev, &tmp);
1510 if (ret)
1511 return ret;
1512
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001513 len = min(tmp.len, dump.len);
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001514 if (!len)
1515 return -EFAULT;
1516
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001517 /* Don't ever let the driver think there's more space available
1518 * than it requested with .get_dump_flag().
1519 */
1520 dump.len = len;
1521
1522 /* Always allocate enough space to hold the whole thing so that the
1523 * driver does not need to check the length and bother with partial
1524 * dumping.
1525 */
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001526 data = vzalloc(tmp.len);
1527 if (!data)
1528 return -ENOMEM;
1529 ret = ops->get_dump_data(dev, &dump, data);
1530 if (ret)
1531 goto out;
1532
Michal Schmidtc590b5e2013-07-01 17:23:30 +02001533 /* There are two sane possibilities:
1534 * 1. The driver's .get_dump_data() does not touch dump.len.
1535 * 2. Or it may set dump.len to how much it really writes, which
1536 * should be tmp.len (or len if it can do a partial dump).
1537 * In any case respond to userspace with the actual length of data
1538 * it's receiving.
1539 */
1540 WARN_ON(dump.len != len && dump.len != tmp.len);
1541 dump.len = len;
1542
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001543 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1544 ret = -EFAULT;
1545 goto out;
1546 }
1547 useraddr += offsetof(struct ethtool_dump, data);
1548 if (copy_to_user(useraddr, data, len))
1549 ret = -EFAULT;
1550out:
1551 vfree(data);
1552 return ret;
1553}
1554
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001555static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1556{
1557 int err = 0;
1558 struct ethtool_ts_info info;
1559 const struct ethtool_ops *ops = dev->ethtool_ops;
1560 struct phy_device *phydev = dev->phydev;
1561
1562 memset(&info, 0, sizeof(info));
1563 info.cmd = ETHTOOL_GET_TS_INFO;
1564
1565 if (phydev && phydev->drv && phydev->drv->ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001566 err = phydev->drv->ts_info(phydev, &info);
Jiri Pirkoc03a14e2013-01-07 09:02:08 +00001567 } else if (ops->get_ts_info) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001568 err = ops->get_ts_info(dev, &info);
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001569 } else {
1570 info.so_timestamping =
1571 SOF_TIMESTAMPING_RX_SOFTWARE |
1572 SOF_TIMESTAMPING_SOFTWARE;
1573 info.phc_index = -1;
1574 }
1575
1576 if (err)
1577 return err;
1578
1579 if (copy_to_user(useraddr, &info, sizeof(info)))
1580 err = -EFAULT;
1581
1582 return err;
1583}
1584
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001585static int ethtool_get_module_info(struct net_device *dev,
1586 void __user *useraddr)
1587{
1588 int ret;
1589 struct ethtool_modinfo modinfo;
1590 const struct ethtool_ops *ops = dev->ethtool_ops;
1591
1592 if (!ops->get_module_info)
1593 return -EOPNOTSUPP;
1594
1595 if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
1596 return -EFAULT;
1597
1598 ret = ops->get_module_info(dev, &modinfo);
1599 if (ret)
1600 return ret;
1601
1602 if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
1603 return -EFAULT;
1604
1605 return 0;
1606}
1607
1608static int ethtool_get_module_eeprom(struct net_device *dev,
1609 void __user *useraddr)
1610{
1611 int ret;
1612 struct ethtool_modinfo modinfo;
1613 const struct ethtool_ops *ops = dev->ethtool_ops;
1614
1615 if (!ops->get_module_info || !ops->get_module_eeprom)
1616 return -EOPNOTSUPP;
1617
1618 ret = ops->get_module_info(dev, &modinfo);
1619 if (ret)
1620 return ret;
1621
1622 return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
1623 modinfo.eeprom_len);
1624}
1625
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301626static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
1627{
1628 switch (tuna->id) {
1629 case ETHTOOL_RX_COPYBREAK:
Eric Dumazet1255a502014-10-05 12:35:21 +03001630 case ETHTOOL_TX_COPYBREAK:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301631 if (tuna->len != sizeof(u32) ||
1632 tuna->type_id != ETHTOOL_TUNABLE_U32)
1633 return -EINVAL;
1634 break;
1635 default:
1636 return -EINVAL;
1637 }
1638
1639 return 0;
1640}
1641
1642static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
1643{
1644 int ret;
1645 struct ethtool_tunable tuna;
1646 const struct ethtool_ops *ops = dev->ethtool_ops;
1647 void *data;
1648
1649 if (!ops->get_tunable)
1650 return -EOPNOTSUPP;
1651 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1652 return -EFAULT;
1653 ret = ethtool_tunable_valid(&tuna);
1654 if (ret)
1655 return ret;
1656 data = kmalloc(tuna.len, GFP_USER);
1657 if (!data)
1658 return -ENOMEM;
1659 ret = ops->get_tunable(dev, &tuna, data);
1660 if (ret)
1661 goto out;
1662 useraddr += sizeof(tuna);
1663 ret = -EFAULT;
1664 if (copy_to_user(useraddr, data, tuna.len))
1665 goto out;
1666 ret = 0;
1667
1668out:
1669 kfree(data);
1670 return ret;
1671}
1672
1673static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
1674{
1675 int ret;
1676 struct ethtool_tunable tuna;
1677 const struct ethtool_ops *ops = dev->ethtool_ops;
1678 void *data;
1679
1680 if (!ops->set_tunable)
1681 return -EOPNOTSUPP;
1682 if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
1683 return -EFAULT;
1684 ret = ethtool_tunable_valid(&tuna);
1685 if (ret)
1686 return ret;
1687 data = kmalloc(tuna.len, GFP_USER);
1688 if (!data)
1689 return -ENOMEM;
1690 useraddr += sizeof(tuna);
1691 ret = -EFAULT;
1692 if (copy_from_user(data, useraddr, tuna.len))
1693 goto out;
1694 ret = ops->set_tunable(dev, &tuna, data);
1695
1696out:
1697 kfree(data);
1698 return ret;
1699}
1700
Yan Burman600fed52013-06-03 02:03:34 +00001701/* The main entry point in this file. Called from net/core/dev_ioctl.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Eric W. Biederman881d9662007-09-17 11:56:21 -07001703int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001705 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 void __user *useraddr = ifr->ifr_data;
1707 u32 ethcmd;
1708 int rc;
Bjørn Morkb29d3142013-05-01 23:06:42 +00001709 netdev_features_t old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 if (!dev || !netif_device_present(dev))
1712 return -ENODEV;
1713
chavey97f8aef2010-04-07 21:54:42 -07001714 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 return -EFAULT;
1716
Stephen Hemminger75f31232006-09-28 15:13:37 -07001717 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001718 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001719 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001720 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001721 case ETHTOOL_GMSGLVL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001722 case ETHTOOL_GLINK:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001723 case ETHTOOL_GCOALESCE:
1724 case ETHTOOL_GRINGPARAM:
1725 case ETHTOOL_GPAUSEPARAM:
1726 case ETHTOOL_GRXCSUM:
1727 case ETHTOOL_GTXCSUM:
1728 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001729 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001730 case ETHTOOL_GSTRINGS:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001731 case ETHTOOL_GSTATS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001732 case ETHTOOL_GTSO:
1733 case ETHTOOL_GPERMADDR:
1734 case ETHTOOL_GUFO:
1735 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001736 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001737 case ETHTOOL_GFLAGS:
1738 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001739 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001740 case ETHTOOL_GRXRINGS:
1741 case ETHTOOL_GRXCLSRLCNT:
1742 case ETHTOOL_GRXCLSRULE:
1743 case ETHTOOL_GRXCLSRLALL:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001744 case ETHTOOL_GRXFHINDIR:
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301745 case ETHTOOL_GRSSH:
Michał Mirosław5455c692011-02-15 16:59:17 +00001746 case ETHTOOL_GFEATURES:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001747 case ETHTOOL_GCHANNELS:
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001748 case ETHTOOL_GET_TS_INFO:
Ben Hutchings2da45db2012-06-12 13:05:41 +00001749 case ETHTOOL_GEEE:
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301750 case ETHTOOL_GTUNABLE:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001751 break;
1752 default:
Eric W. Biederman5e1fccc2012-11-16 03:03:04 +00001753 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
Stephen Hemminger75f31232006-09-28 15:13:37 -07001754 return -EPERM;
1755 }
1756
chavey97f8aef2010-04-07 21:54:42 -07001757 if (dev->ethtool_ops->begin) {
1758 rc = dev->ethtool_ops->begin(dev);
1759 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001761 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001762 old_features = dev->features;
1763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 switch (ethcmd) {
1765 case ETHTOOL_GSET:
1766 rc = ethtool_get_settings(dev, useraddr);
1767 break;
1768 case ETHTOOL_SSET:
1769 rc = ethtool_set_settings(dev, useraddr);
1770 break;
1771 case ETHTOOL_GDRVINFO:
1772 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 break;
1774 case ETHTOOL_GREGS:
1775 rc = ethtool_get_regs(dev, useraddr);
1776 break;
1777 case ETHTOOL_GWOL:
1778 rc = ethtool_get_wol(dev, useraddr);
1779 break;
1780 case ETHTOOL_SWOL:
1781 rc = ethtool_set_wol(dev, useraddr);
1782 break;
1783 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001784 rc = ethtool_get_value(dev, useraddr, ethcmd,
1785 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 break;
1787 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001788 rc = ethtool_set_value_void(dev, useraddr,
1789 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 break;
Yuval Mintz80f12ec2012-06-06 17:13:06 +00001791 case ETHTOOL_GEEE:
1792 rc = ethtool_get_eee(dev, useraddr);
1793 break;
1794 case ETHTOOL_SEEE:
1795 rc = ethtool_set_eee(dev, useraddr);
1796 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 case ETHTOOL_NWAY_RST:
1798 rc = ethtool_nway_reset(dev);
1799 break;
1800 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001801 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 break;
1803 case ETHTOOL_GEEPROM:
1804 rc = ethtool_get_eeprom(dev, useraddr);
1805 break;
1806 case ETHTOOL_SEEPROM:
1807 rc = ethtool_set_eeprom(dev, useraddr);
1808 break;
1809 case ETHTOOL_GCOALESCE:
1810 rc = ethtool_get_coalesce(dev, useraddr);
1811 break;
1812 case ETHTOOL_SCOALESCE:
1813 rc = ethtool_set_coalesce(dev, useraddr);
1814 break;
1815 case ETHTOOL_GRINGPARAM:
1816 rc = ethtool_get_ringparam(dev, useraddr);
1817 break;
1818 case ETHTOOL_SRINGPARAM:
1819 rc = ethtool_set_ringparam(dev, useraddr);
1820 break;
1821 case ETHTOOL_GPAUSEPARAM:
1822 rc = ethtool_get_pauseparam(dev, useraddr);
1823 break;
1824 case ETHTOOL_SPAUSEPARAM:
1825 rc = ethtool_set_pauseparam(dev, useraddr);
1826 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 case ETHTOOL_TEST:
1828 rc = ethtool_self_test(dev, useraddr);
1829 break;
1830 case ETHTOOL_GSTRINGS:
1831 rc = ethtool_get_strings(dev, useraddr);
1832 break;
1833 case ETHTOOL_PHYS_ID:
1834 rc = ethtool_phys_id(dev, useraddr);
1835 break;
1836 case ETHTOOL_GSTATS:
1837 rc = ethtool_get_stats(dev, useraddr);
1838 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001839 case ETHTOOL_GPERMADDR:
1840 rc = ethtool_get_perm_addr(dev, useraddr);
1841 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001842 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001843 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001844 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001845 break;
1846 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001847 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001848 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001849 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001850 rc = ethtool_get_value(dev, useraddr, ethcmd,
1851 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001852 break;
1853 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001854 rc = ethtool_set_value(dev, useraddr,
1855 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001856 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001857 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001858 case ETHTOOL_GRXRINGS:
1859 case ETHTOOL_GRXCLSRLCNT:
1860 case ETHTOOL_GRXCLSRULE:
1861 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001862 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001863 break;
1864 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001865 case ETHTOOL_SRXCLSRLDEL:
1866 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001867 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001868 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001869 case ETHTOOL_FLASHDEV:
1870 rc = ethtool_flash_device(dev, useraddr);
1871 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001872 case ETHTOOL_RESET:
1873 rc = ethtool_reset(dev, useraddr);
1874 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001875 case ETHTOOL_GSSET_INFO:
1876 rc = ethtool_get_sset_info(dev, useraddr);
1877 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001878 case ETHTOOL_GRXFHINDIR:
1879 rc = ethtool_get_rxfh_indir(dev, useraddr);
1880 break;
1881 case ETHTOOL_SRXFHINDIR:
1882 rc = ethtool_set_rxfh_indir(dev, useraddr);
1883 break;
Venkata Duvvuru3de0b592014-04-21 15:37:59 +05301884 case ETHTOOL_GRSSH:
1885 rc = ethtool_get_rxfh(dev, useraddr);
1886 break;
1887 case ETHTOOL_SRSSH:
1888 rc = ethtool_set_rxfh(dev, useraddr);
1889 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001890 case ETHTOOL_GFEATURES:
1891 rc = ethtool_get_features(dev, useraddr);
1892 break;
1893 case ETHTOOL_SFEATURES:
1894 rc = ethtool_set_features(dev, useraddr);
1895 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001896 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001897 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001898 case ETHTOOL_GSG:
1899 case ETHTOOL_GTSO:
1900 case ETHTOOL_GUFO:
1901 case ETHTOOL_GGSO:
1902 case ETHTOOL_GGRO:
1903 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1904 break;
1905 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001906 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001907 case ETHTOOL_SSG:
1908 case ETHTOOL_STSO:
1909 case ETHTOOL_SUFO:
1910 case ETHTOOL_SGSO:
1911 case ETHTOOL_SGRO:
1912 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1913 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001914 case ETHTOOL_GCHANNELS:
1915 rc = ethtool_get_channels(dev, useraddr);
1916 break;
1917 case ETHTOOL_SCHANNELS:
1918 rc = ethtool_set_channels(dev, useraddr);
1919 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001920 case ETHTOOL_SET_DUMP:
1921 rc = ethtool_set_dump(dev, useraddr);
1922 break;
1923 case ETHTOOL_GET_DUMP_FLAG:
1924 rc = ethtool_get_dump_flag(dev, useraddr);
1925 break;
1926 case ETHTOOL_GET_DUMP_DATA:
1927 rc = ethtool_get_dump_data(dev, useraddr);
1928 break;
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001929 case ETHTOOL_GET_TS_INFO:
1930 rc = ethtool_get_ts_info(dev, useraddr);
1931 break;
Stuart Hodgson41c3cb62012-04-19 09:44:42 +01001932 case ETHTOOL_GMODULEINFO:
1933 rc = ethtool_get_module_info(dev, useraddr);
1934 break;
1935 case ETHTOOL_GMODULEEEPROM:
1936 rc = ethtool_get_module_eeprom(dev, useraddr);
1937 break;
Govindarajulu Varadarajanf0db9b02014-09-03 03:17:20 +05301938 case ETHTOOL_GTUNABLE:
1939 rc = ethtool_get_tunable(dev, useraddr);
1940 break;
1941 case ETHTOOL_STUNABLE:
1942 rc = ethtool_set_tunable(dev, useraddr);
1943 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001945 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001947
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001948 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001950
1951 if (old_features != dev->features)
1952 netdev_features_change(dev);
1953
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}