blob: a354919a32ac8948f0c2c61a86e4972b9aef0f9e [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>
Jeff Garzikd17792e2010-03-04 08:21:53 +000020#include <linux/bitops.h>
chavey97f8aef2010-04-07 21:54:42 -070021#include <linux/uaccess.h>
David S. Miller73da16c2010-09-21 16:12:11 -070022#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Ben Hutchings68f512f2011-04-02 00:35:15 +010024#include <linux/rtnetlink.h>
25#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090027/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * Some useful ethtool_ops methods that're device independent.
29 * If we find that all drivers want to do the same thing here,
30 * we can turn these into dev_() function calls.
31 */
32
33u32 ethtool_op_get_link(struct net_device *dev)
34{
35 return netif_carrier_ok(dev) ? 1 : 0;
36}
chavey97f8aef2010-04-07 21:54:42 -070037EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/* Handlers for each ethtool command */
40
Michał Mirosław5455c692011-02-15 16:59:17 +000041#define ETHTOOL_DEV_FEATURE_WORDS 1
42
43static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
44{
45 struct ethtool_gfeatures cmd = {
46 .cmd = ETHTOOL_GFEATURES,
47 .size = ETHTOOL_DEV_FEATURE_WORDS,
48 };
49 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = {
50 {
51 .available = dev->hw_features,
52 .requested = dev->wanted_features,
53 .active = dev->features,
54 .never_changed = NETIF_F_NEVER_CHANGE,
55 },
56 };
57 u32 __user *sizeaddr;
58 u32 copy_size;
59
60 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
61 if (get_user(copy_size, sizeaddr))
62 return -EFAULT;
63
64 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
65 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
66
67 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
68 return -EFAULT;
69 useraddr += sizeof(cmd);
70 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
71 return -EFAULT;
72
73 return 0;
74}
75
76static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
77{
78 struct ethtool_sfeatures cmd;
79 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
80 int ret = 0;
81
82 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
83 return -EFAULT;
84 useraddr += sizeof(cmd);
85
86 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
87 return -EINVAL;
88
89 if (copy_from_user(features, useraddr, sizeof(features)))
90 return -EFAULT;
91
92 if (features[0].valid & ~NETIF_F_ETHTOOL_BITS)
93 return -EINVAL;
94
95 if (features[0].valid & ~dev->hw_features) {
96 features[0].valid &= dev->hw_features;
97 ret |= ETHTOOL_F_UNSUPPORTED;
98 }
99
100 dev->wanted_features &= ~features[0].valid;
101 dev->wanted_features |= features[0].valid & features[0].requested;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700102 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000103
104 if ((dev->wanted_features ^ dev->features) & features[0].valid)
105 ret |= ETHTOOL_F_WISH;
106
107 return ret;
108}
109
110static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = {
111 /* NETIF_F_SG */ "tx-scatter-gather",
112 /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
113 /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
114 /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
Michał Mirosław7cc31a92011-05-17 16:50:02 -0400115 /* NETIF_F_IPV6_CSUM */ "tx-checksum-ipv6",
Michał Mirosław5455c692011-02-15 16:59:17 +0000116 /* NETIF_F_HIGHDMA */ "highdma",
117 /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
118 /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
119
120 /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
121 /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
122 /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
123 /* NETIF_F_GSO */ "tx-generic-segmentation",
124 /* NETIF_F_LLTX */ "tx-lockless",
125 /* NETIF_F_NETNS_LOCAL */ "netns-local",
126 /* NETIF_F_GRO */ "rx-gro",
127 /* NETIF_F_LRO */ "rx-lro",
128
129 /* NETIF_F_TSO */ "tx-tcp-segmentation",
130 /* NETIF_F_UFO */ "tx-udp-fragmentation",
131 /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
132 /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
133 /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
134 /* NETIF_F_FSO */ "tx-fcoe-segmentation",
135 "",
136 "",
137
138 /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
139 /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
140 /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
141 /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
142 /* NETIF_F_RXHASH */ "rx-hashing",
Michał Mirosławe83d3602011-02-15 16:59:18 +0000143 /* NETIF_F_RXCSUM */ "rx-checksum",
Franco Fichtner864b54182011-05-12 06:42:04 +0000144 /* NETIF_F_NOCACHE_COPY */ "tx-nocache-copy",
Mahesh Bandewareed2a122011-05-04 15:30:11 +0000145 /* NETIF_F_LOOPBACK */ "loopback",
Michał Mirosław5455c692011-02-15 16:59:17 +0000146};
147
Michał Mirosław340ae162011-02-15 16:59:16 +0000148static int __ethtool_get_sset_count(struct net_device *dev, int sset)
149{
150 const struct ethtool_ops *ops = dev->ethtool_ops;
151
Michał Mirosław5455c692011-02-15 16:59:17 +0000152 if (sset == ETH_SS_FEATURES)
153 return ARRAY_SIZE(netdev_features_strings);
154
Michał Mirosław340ae162011-02-15 16:59:16 +0000155 if (ops && ops->get_sset_count && ops->get_strings)
156 return ops->get_sset_count(dev, sset);
157 else
158 return -EOPNOTSUPP;
159}
160
161static void __ethtool_get_strings(struct net_device *dev,
162 u32 stringset, u8 *data)
163{
164 const struct ethtool_ops *ops = dev->ethtool_ops;
165
Michał Mirosław5455c692011-02-15 16:59:17 +0000166 if (stringset == ETH_SS_FEATURES)
167 memcpy(data, netdev_features_strings,
168 sizeof(netdev_features_strings));
169 else
170 /* ops->get_strings is valid because checked earlier */
171 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000172}
173
Michał Mirosław0a417702011-02-15 16:59:17 +0000174static u32 ethtool_get_feature_mask(u32 eth_cmd)
175{
176 /* feature masks of legacy discrete ethtool ops */
177
178 switch (eth_cmd) {
179 case ETHTOOL_GTXCSUM:
180 case ETHTOOL_STXCSUM:
181 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000182 case ETHTOOL_GRXCSUM:
183 case ETHTOOL_SRXCSUM:
184 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000185 case ETHTOOL_GSG:
186 case ETHTOOL_SSG:
187 return NETIF_F_SG;
188 case ETHTOOL_GTSO:
189 case ETHTOOL_STSO:
190 return NETIF_F_ALL_TSO;
191 case ETHTOOL_GUFO:
192 case ETHTOOL_SUFO:
193 return NETIF_F_UFO;
194 case ETHTOOL_GGSO:
195 case ETHTOOL_SGSO:
196 return NETIF_F_GSO;
197 case ETHTOOL_GGRO:
198 case ETHTOOL_SGRO:
199 return NETIF_F_GRO;
200 default:
201 BUG();
202 }
203}
204
Michał Mirosław0a417702011-02-15 16:59:17 +0000205static int ethtool_get_one_feature(struct net_device *dev,
206 char __user *useraddr, u32 ethcmd)
207{
Michał Mirosław86794882011-02-15 16:59:17 +0000208 u32 mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000209 struct ethtool_value edata = {
210 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000211 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000212 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000213
Michał Mirosław0a417702011-02-15 16:59:17 +0000214 if (copy_to_user(useraddr, &edata, sizeof(edata)))
215 return -EFAULT;
216 return 0;
217}
218
Michał Mirosław0a417702011-02-15 16:59:17 +0000219static int ethtool_set_one_feature(struct net_device *dev,
220 void __user *useraddr, u32 ethcmd)
221{
222 struct ethtool_value edata;
223 u32 mask;
224
225 if (copy_from_user(&edata, useraddr, sizeof(edata)))
226 return -EFAULT;
227
Michał Mirosław86794882011-02-15 16:59:17 +0000228 mask = ethtool_get_feature_mask(ethcmd);
229 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000230 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000231 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000232
233 if (edata.data)
234 dev->wanted_features |= mask;
235 else
236 dev->wanted_features &= ~mask;
237
238 __netdev_update_features(dev);
239
240 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000241}
242
Michał Mirosław02b3a552011-11-15 15:29:55 +0000243#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
244 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
245#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
246 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000247
248static u32 __ethtool_get_flags(struct net_device *dev)
249{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000250 u32 flags = 0;
251
252 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
253 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
254 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
255 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
256 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
257
258 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000259}
260
261static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000262{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000263 u32 features = 0;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000264 u32 changed;
265
Michał Mirosław02b3a552011-11-15 15:29:55 +0000266 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000267 return -EINVAL;
268
Michał Mirosław02b3a552011-11-15 15:29:55 +0000269 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
270 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
271 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
272 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
273 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
274
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000275 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000276 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000277 if (changed & ~dev->hw_features)
278 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
279
280 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000281 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000282
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700283 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000284
285 return 0;
286}
287
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000288int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000290 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000292 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return -EOPNOTSUPP;
294
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000295 memset(cmd, 0, sizeof(struct ethtool_cmd));
296 cmd->cmd = ETHTOOL_GSET;
297 return dev->ethtool_ops->get_settings(dev, cmd);
298}
299EXPORT_SYMBOL(__ethtool_get_settings);
300
301static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
302{
303 int err;
304 struct ethtool_cmd cmd;
305
306 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (err < 0)
308 return err;
309
310 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
311 return -EFAULT;
312 return 0;
313}
314
315static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
316{
317 struct ethtool_cmd cmd;
318
319 if (!dev->ethtool_ops->set_settings)
320 return -EOPNOTSUPP;
321
322 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
323 return -EFAULT;
324
325 return dev->ethtool_ops->set_settings(dev, &cmd);
326}
327
chavey97f8aef2010-04-07 21:54:42 -0700328static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
329 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700332 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 memset(&info, 0, sizeof(info));
335 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700336 if (ops && ops->get_drvinfo) {
337 ops->get_drvinfo(dev, &info);
338 } else if (dev->dev.parent && dev->dev.parent->driver) {
339 strlcpy(info.bus_info, dev_name(dev->dev.parent),
340 sizeof(info.bus_info));
341 strlcpy(info.driver, dev->dev.parent->driver->name,
342 sizeof(info.driver));
343 } else {
344 return -EOPNOTSUPP;
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Jeff Garzik723b2f52010-03-03 22:51:50 +0000347 /*
348 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000349 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000350 */
Ben Hutchings01414802010-08-17 02:31:15 -0700351 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700352 int rc;
353
354 rc = ops->get_sset_count(dev, ETH_SS_TEST);
355 if (rc >= 0)
356 info.testinfo_len = rc;
357 rc = ops->get_sset_count(dev, ETH_SS_STATS);
358 if (rc >= 0)
359 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700360 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
361 if (rc >= 0)
362 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700363 }
Ben Hutchings01414802010-08-17 02:31:15 -0700364 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700366 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 info.eedump_len = ops->get_eeprom_len(dev);
368
369 if (copy_to_user(useraddr, &info, sizeof(info)))
370 return -EFAULT;
371 return 0;
372}
373
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800374static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700375 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000376{
377 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000378 u64 sset_mask;
379 int i, idx = 0, n_bits = 0, ret, rc;
380 u32 *info_buf = NULL;
381
Jeff Garzik723b2f52010-03-03 22:51:50 +0000382 if (copy_from_user(&info, useraddr, sizeof(info)))
383 return -EFAULT;
384
385 /* store copy of mask, because we zero struct later on */
386 sset_mask = info.sset_mask;
387 if (!sset_mask)
388 return 0;
389
390 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000391 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000392
393 memset(&info, 0, sizeof(info));
394 info.cmd = ETHTOOL_GSSET_INFO;
395
396 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
397 if (!info_buf)
398 return -ENOMEM;
399
400 /*
401 * fill return buffer based on input bitmask and successful
402 * get_sset_count return
403 */
404 for (i = 0; i < 64; i++) {
405 if (!(sset_mask & (1ULL << i)))
406 continue;
407
Michał Mirosław340ae162011-02-15 16:59:16 +0000408 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000409 if (rc >= 0) {
410 info.sset_mask |= (1ULL << i);
411 info_buf[idx++] = rc;
412 }
413 }
414
415 ret = -EFAULT;
416 if (copy_to_user(useraddr, &info, sizeof(info)))
417 goto out;
418
419 useraddr += offsetof(struct ethtool_sset_info, data);
420 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
421 goto out;
422
423 ret = 0;
424
425out:
426 kfree(info_buf);
427 return ret;
428}
429
chavey97f8aef2010-04-07 21:54:42 -0700430static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000431 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700432{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000433 struct ethtool_rxnfc info;
434 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700435
Santwona Behera59089d82009-02-20 00:58:13 -0800436 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700437 return -EOPNOTSUPP;
438
Ben Hutchingsbf988432010-06-28 08:45:58 +0000439 /* struct ethtool_rxnfc was originally defined for
440 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
441 * members. User-space might still be using that
442 * definition. */
443 if (cmd == ETHTOOL_SRXFH)
444 info_size = (offsetof(struct ethtool_rxnfc, data) +
445 sizeof(info.data));
446
447 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700448 return -EFAULT;
449
Ben Hutchingsbf988432010-06-28 08:45:58 +0000450 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700451}
452
chavey97f8aef2010-04-07 21:54:42 -0700453static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000454 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700455{
456 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000457 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800458 const struct ethtool_ops *ops = dev->ethtool_ops;
459 int ret;
460 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700461
Santwona Behera59089d82009-02-20 00:58:13 -0800462 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700463 return -EOPNOTSUPP;
464
Ben Hutchingsbf988432010-06-28 08:45:58 +0000465 /* struct ethtool_rxnfc was originally defined for
466 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
467 * members. User-space might still be using that
468 * definition. */
469 if (cmd == ETHTOOL_GRXFH)
470 info_size = (offsetof(struct ethtool_rxnfc, data) +
471 sizeof(info.data));
472
473 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700474 return -EFAULT;
475
Santwona Behera59089d82009-02-20 00:58:13 -0800476 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
477 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000478 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000479 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000480 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800481 if (!rule_buf)
482 return -ENOMEM;
483 }
484 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700485
Santwona Behera59089d82009-02-20 00:58:13 -0800486 ret = ops->get_rxnfc(dev, &info, rule_buf);
487 if (ret < 0)
488 goto err_out;
489
490 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000491 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800492 goto err_out;
493
494 if (rule_buf) {
495 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
496 if (copy_to_user(useraddr, rule_buf,
497 info.rule_cnt * sizeof(u32)))
498 goto err_out;
499 }
500 ret = 0;
501
502err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700503 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800504
505 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700506}
507
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000508static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
509 void __user *useraddr)
510{
511 struct ethtool_rxfh_indir *indir;
512 u32 table_size;
513 size_t full_size;
514 int ret;
515
516 if (!dev->ethtool_ops->get_rxfh_indir)
517 return -EOPNOTSUPP;
518
519 if (copy_from_user(&table_size,
520 useraddr + offsetof(struct ethtool_rxfh_indir, size),
521 sizeof(table_size)))
522 return -EFAULT;
523
524 if (table_size >
525 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
526 return -ENOMEM;
527 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
Kees Cookb00916b2010-10-11 12:23:25 -0700528 indir = kzalloc(full_size, GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000529 if (!indir)
530 return -ENOMEM;
531
532 indir->cmd = ETHTOOL_GRXFHINDIR;
533 indir->size = table_size;
534 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
535 if (ret)
536 goto out;
537
538 if (copy_to_user(useraddr, indir, full_size))
539 ret = -EFAULT;
540
541out:
542 kfree(indir);
543 return ret;
544}
545
546static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
547 void __user *useraddr)
548{
549 struct ethtool_rxfh_indir *indir;
550 u32 table_size;
551 size_t full_size;
552 int ret;
553
554 if (!dev->ethtool_ops->set_rxfh_indir)
555 return -EOPNOTSUPP;
556
557 if (copy_from_user(&table_size,
558 useraddr + offsetof(struct ethtool_rxfh_indir, size),
559 sizeof(table_size)))
560 return -EFAULT;
561
562 if (table_size >
563 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
564 return -ENOMEM;
565 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
566 indir = kmalloc(full_size, GFP_USER);
567 if (!indir)
568 return -ENOMEM;
569
570 if (copy_from_user(indir, useraddr, full_size)) {
571 ret = -EFAULT;
572 goto out;
573 }
574
575 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
576
577out:
578 kfree(indir);
579 return ret;
580}
581
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000582/*
583 * ethtool does not (or did not) set masks for flow parameters that are
584 * not specified, so if both value and mask are 0 then this must be
585 * treated as equivalent to a mask with all bits set. Implement that
586 * here rather than in drivers.
587 */
588static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
589{
590 struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
591 struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
592
593 if (fs->flow_type != TCP_V4_FLOW &&
594 fs->flow_type != UDP_V4_FLOW &&
595 fs->flow_type != SCTP_V4_FLOW)
596 return;
597
598 if (!(entry->ip4src | mask->ip4src))
599 mask->ip4src = htonl(0xffffffff);
600 if (!(entry->ip4dst | mask->ip4dst))
601 mask->ip4dst = htonl(0xffffffff);
602 if (!(entry->psrc | mask->psrc))
603 mask->psrc = htons(0xffff);
604 if (!(entry->pdst | mask->pdst))
605 mask->pdst = htons(0xffff);
606 if (!(entry->tos | mask->tos))
607 mask->tos = 0xff;
608 if (!(fs->vlan_tag | fs->vlan_tag_mask))
609 fs->vlan_tag_mask = 0xffff;
610 if (!(fs->data | fs->data_mask))
611 fs->data_mask = 0xffffffffffffffffULL;
612}
613
chavey97f8aef2010-04-07 21:54:42 -0700614static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
615 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800616{
617 struct ethtool_rx_ntuple cmd;
618 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800619
Alexander Duyck5d9f11c2011-04-08 12:07:22 +0000620 if (!ops->set_rx_ntuple)
621 return -EOPNOTSUPP;
622
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800623 if (!(dev->features & NETIF_F_NTUPLE))
624 return -EINVAL;
625
626 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
627 return -EFAULT;
628
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000629 rx_ntuple_fix_masks(&cmd.fs);
630
Alexander Duyckbff55272011-06-08 12:35:08 +0000631 return ops->set_rx_ntuple(dev, &cmd);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800632}
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
635{
636 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700637 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 void *regbuf;
639 int reglen, ret;
640
641 if (!ops->get_regs || !ops->get_regs_len)
642 return -EOPNOTSUPP;
643
644 if (copy_from_user(&regs, useraddr, sizeof(regs)))
645 return -EFAULT;
646
647 reglen = ops->get_regs_len(dev);
648 if (regs.len > reglen)
649 regs.len = reglen;
650
Eugene Teob7c7d012011-01-24 21:05:17 -0800651 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700652 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return -ENOMEM;
654
655 ops->get_regs(dev, &regs, regbuf);
656
657 ret = -EFAULT;
658 if (copy_to_user(useraddr, &regs, sizeof(regs)))
659 goto out;
660 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700661 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 goto out;
663 ret = 0;
664
665 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000666 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return ret;
668}
669
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000670static int ethtool_reset(struct net_device *dev, char __user *useraddr)
671{
672 struct ethtool_value reset;
673 int ret;
674
675 if (!dev->ethtool_ops->reset)
676 return -EOPNOTSUPP;
677
678 if (copy_from_user(&reset, useraddr, sizeof(reset)))
679 return -EFAULT;
680
681 ret = dev->ethtool_ops->reset(dev, &reset.data);
682 if (ret)
683 return ret;
684
685 if (copy_to_user(useraddr, &reset, sizeof(reset)))
686 return -EFAULT;
687 return 0;
688}
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
691{
Roland Dreier8e557422010-02-11 12:14:23 -0800692 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 if (!dev->ethtool_ops->get_wol)
695 return -EOPNOTSUPP;
696
697 dev->ethtool_ops->get_wol(dev, &wol);
698
699 if (copy_to_user(useraddr, &wol, sizeof(wol)))
700 return -EFAULT;
701 return 0;
702}
703
704static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
705{
706 struct ethtool_wolinfo wol;
707
708 if (!dev->ethtool_ops->set_wol)
709 return -EOPNOTSUPP;
710
711 if (copy_from_user(&wol, useraddr, sizeof(wol)))
712 return -EFAULT;
713
714 return dev->ethtool_ops->set_wol(dev, &wol);
715}
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717static int ethtool_nway_reset(struct net_device *dev)
718{
719 if (!dev->ethtool_ops->nway_reset)
720 return -EOPNOTSUPP;
721
722 return dev->ethtool_ops->nway_reset(dev);
723}
724
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000725static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
726{
727 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
728
729 if (!dev->ethtool_ops->get_link)
730 return -EOPNOTSUPP;
731
732 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
733
734 if (copy_to_user(useraddr, &edata, sizeof(edata)))
735 return -EFAULT;
736 return 0;
737}
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
740{
741 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700742 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700743 void __user *userbuf = useraddr + sizeof(eeprom);
744 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700746 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 if (!ops->get_eeprom || !ops->get_eeprom_len)
749 return -EOPNOTSUPP;
750
751 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
752 return -EFAULT;
753
754 /* Check for wrap and zero */
755 if (eeprom.offset + eeprom.len <= eeprom.offset)
756 return -EINVAL;
757
758 /* Check for exceeding total eeprom len */
759 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
760 return -EINVAL;
761
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700762 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 if (!data)
764 return -ENOMEM;
765
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700766 bytes_remaining = eeprom.len;
767 while (bytes_remaining > 0) {
768 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700770 ret = ops->get_eeprom(dev, &eeprom, data);
771 if (ret)
772 break;
773 if (copy_to_user(userbuf, data, eeprom.len)) {
774 ret = -EFAULT;
775 break;
776 }
777 userbuf += eeprom.len;
778 eeprom.offset += eeprom.len;
779 bytes_remaining -= eeprom.len;
780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700782 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
783 eeprom.offset -= eeprom.len;
784 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
785 ret = -EFAULT;
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 kfree(data);
788 return ret;
789}
790
791static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
792{
793 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700794 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700795 void __user *userbuf = useraddr + sizeof(eeprom);
796 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700798 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 if (!ops->set_eeprom || !ops->get_eeprom_len)
801 return -EOPNOTSUPP;
802
803 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
804 return -EFAULT;
805
806 /* Check for wrap and zero */
807 if (eeprom.offset + eeprom.len <= eeprom.offset)
808 return -EINVAL;
809
810 /* Check for exceeding total eeprom len */
811 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
812 return -EINVAL;
813
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700814 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (!data)
816 return -ENOMEM;
817
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700818 bytes_remaining = eeprom.len;
819 while (bytes_remaining > 0) {
820 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700822 if (copy_from_user(data, userbuf, eeprom.len)) {
823 ret = -EFAULT;
824 break;
825 }
826 ret = ops->set_eeprom(dev, &eeprom, data);
827 if (ret)
828 break;
829 userbuf += eeprom.len;
830 eeprom.offset += eeprom.len;
831 bytes_remaining -= eeprom.len;
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 kfree(data);
835 return ret;
836}
837
chavey97f8aef2010-04-07 21:54:42 -0700838static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
839 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Roland Dreier8e557422010-02-11 12:14:23 -0800841 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 if (!dev->ethtool_ops->get_coalesce)
844 return -EOPNOTSUPP;
845
846 dev->ethtool_ops->get_coalesce(dev, &coalesce);
847
848 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
849 return -EFAULT;
850 return 0;
851}
852
chavey97f8aef2010-04-07 21:54:42 -0700853static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
854 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 struct ethtool_coalesce coalesce;
857
David S. Millerfa04ae52005-06-06 15:07:19 -0700858 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 return -EOPNOTSUPP;
860
861 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
862 return -EFAULT;
863
864 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
865}
866
867static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
868{
Roland Dreier8e557422010-02-11 12:14:23 -0800869 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 if (!dev->ethtool_ops->get_ringparam)
872 return -EOPNOTSUPP;
873
874 dev->ethtool_ops->get_ringparam(dev, &ringparam);
875
876 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
877 return -EFAULT;
878 return 0;
879}
880
881static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
882{
883 struct ethtool_ringparam ringparam;
884
885 if (!dev->ethtool_ops->set_ringparam)
886 return -EOPNOTSUPP;
887
888 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
889 return -EFAULT;
890
891 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
892}
893
amit salecha8b5933c2011-04-07 01:58:42 +0000894static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
895 void __user *useraddr)
896{
897 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
898
899 if (!dev->ethtool_ops->get_channels)
900 return -EOPNOTSUPP;
901
902 dev->ethtool_ops->get_channels(dev, &channels);
903
904 if (copy_to_user(useraddr, &channels, sizeof(channels)))
905 return -EFAULT;
906 return 0;
907}
908
909static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
910 void __user *useraddr)
911{
912 struct ethtool_channels channels;
913
914 if (!dev->ethtool_ops->set_channels)
915 return -EOPNOTSUPP;
916
917 if (copy_from_user(&channels, useraddr, sizeof(channels)))
918 return -EFAULT;
919
920 return dev->ethtool_ops->set_channels(dev, &channels);
921}
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
924{
925 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
926
927 if (!dev->ethtool_ops->get_pauseparam)
928 return -EOPNOTSUPP;
929
930 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
931
932 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
933 return -EFAULT;
934 return 0;
935}
936
937static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
938{
939 struct ethtool_pauseparam pauseparam;
940
Jeff Garzike1b90c42006-07-17 12:54:40 -0400941 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return -EOPNOTSUPP;
943
944 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
945 return -EFAULT;
946
947 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
948}
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
951{
952 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700953 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700955 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000957 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700958 return -EOPNOTSUPP;
959
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000960 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700961 if (test_len < 0)
962 return test_len;
963 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 if (copy_from_user(&test, useraddr, sizeof(test)))
966 return -EFAULT;
967
Jeff Garzikff03d492007-08-15 16:01:08 -0700968 test.len = test_len;
969 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 if (!data)
971 return -ENOMEM;
972
973 ops->self_test(dev, &test, data);
974
975 ret = -EFAULT;
976 if (copy_to_user(useraddr, &test, sizeof(test)))
977 goto out;
978 useraddr += sizeof(test);
979 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
980 goto out;
981 ret = 0;
982
983 out:
984 kfree(data);
985 return ret;
986}
987
988static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
989{
990 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 u8 *data;
992 int ret;
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
995 return -EFAULT;
996
Michał Mirosław340ae162011-02-15 16:59:16 +0000997 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000998 if (ret < 0)
999 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001000
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001001 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1004 if (!data)
1005 return -ENOMEM;
1006
Michał Mirosław340ae162011-02-15 16:59:16 +00001007 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 ret = -EFAULT;
1010 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1011 goto out;
1012 useraddr += sizeof(gstrings);
1013 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1014 goto out;
1015 ret = 0;
1016
Michał Mirosław340ae162011-02-15 16:59:16 +00001017out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 kfree(data);
1019 return ret;
1020}
1021
1022static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1023{
1024 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001025 static bool busy;
1026 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001028 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 return -EOPNOTSUPP;
1030
Ben Hutchings68f512f2011-04-02 00:35:15 +01001031 if (busy)
1032 return -EBUSY;
1033
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (copy_from_user(&id, useraddr, sizeof(id)))
1035 return -EFAULT;
1036
Ben Hutchings68f512f2011-04-02 00:35:15 +01001037 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001038 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001039 return rc;
1040
1041 /* Drop the RTNL lock while waiting, but prevent reentry or
1042 * removal of the device.
1043 */
1044 busy = true;
1045 dev_hold(dev);
1046 rtnl_unlock();
1047
1048 if (rc == 0) {
1049 /* Driver will handle this itself */
1050 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001051 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001052 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001053 /* Driver expects to be called at twice the frequency in rc */
1054 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001055
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001056 /* Count down seconds */
1057 do {
1058 /* Count down iterations per second */
1059 i = n;
1060 do {
1061 rtnl_lock();
1062 rc = dev->ethtool_ops->set_phys_id(dev,
1063 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1064 rtnl_unlock();
1065 if (rc)
1066 break;
1067 schedule_timeout_interruptible(interval);
1068 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001069 } while (!signal_pending(current) &&
1070 (id.data == 0 || --id.data != 0));
1071 }
1072
1073 rtnl_lock();
1074 dev_put(dev);
1075 busy = false;
1076
1077 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1078 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079}
1080
1081static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1082{
1083 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001084 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001086 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001088 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001089 return -EOPNOTSUPP;
1090
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001091 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001092 if (n_stats < 0)
1093 return n_stats;
1094 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1097 return -EFAULT;
1098
Jeff Garzikff03d492007-08-15 16:01:08 -07001099 stats.n_stats = n_stats;
1100 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 if (!data)
1102 return -ENOMEM;
1103
1104 ops->get_ethtool_stats(dev, &stats, data);
1105
1106 ret = -EFAULT;
1107 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1108 goto out;
1109 useraddr += sizeof(stats);
1110 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1111 goto out;
1112 ret = 0;
1113
1114 out:
1115 kfree(data);
1116 return ret;
1117}
1118
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001119static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001120{
1121 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001122
Matthew Wilcox313674a2007-07-31 14:00:29 -07001123 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001124 return -EFAULT;
1125
Matthew Wilcox313674a2007-07-31 14:00:29 -07001126 if (epaddr.size < dev->addr_len)
1127 return -ETOOSMALL;
1128 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001129
Jon Wetzela6f9a702005-08-20 17:15:54 -07001130 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001131 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001132 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001133 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1134 return -EFAULT;
1135 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001136}
1137
Jeff Garzik13c99b22007-08-15 16:01:56 -07001138static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1139 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001140{
Roland Dreier8e557422010-02-11 12:14:23 -08001141 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001142
Jeff Garzik13c99b22007-08-15 16:01:56 -07001143 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001144 return -EOPNOTSUPP;
1145
Jeff Garzik13c99b22007-08-15 16:01:56 -07001146 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001147
1148 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1149 return -EFAULT;
1150 return 0;
1151}
1152
Jeff Garzik13c99b22007-08-15 16:01:56 -07001153static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1154 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001155{
1156 struct ethtool_value edata;
1157
Jeff Garzik13c99b22007-08-15 16:01:56 -07001158 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001159 return -EOPNOTSUPP;
1160
1161 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1162 return -EFAULT;
1163
Jeff Garzik13c99b22007-08-15 16:01:56 -07001164 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001165 return 0;
1166}
1167
Jeff Garzik13c99b22007-08-15 16:01:56 -07001168static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1169 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001170{
1171 struct ethtool_value edata;
1172
Jeff Garzik13c99b22007-08-15 16:01:56 -07001173 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001174 return -EOPNOTSUPP;
1175
1176 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1177 return -EFAULT;
1178
Jeff Garzik13c99b22007-08-15 16:01:56 -07001179 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001180}
1181
chavey97f8aef2010-04-07 21:54:42 -07001182static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1183 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001184{
1185 struct ethtool_flash efl;
1186
1187 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1188 return -EFAULT;
1189
1190 if (!dev->ethtool_ops->flash_device)
1191 return -EOPNOTSUPP;
1192
1193 return dev->ethtool_ops->flash_device(dev, &efl);
1194}
1195
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001196static int ethtool_set_dump(struct net_device *dev,
1197 void __user *useraddr)
1198{
1199 struct ethtool_dump dump;
1200
1201 if (!dev->ethtool_ops->set_dump)
1202 return -EOPNOTSUPP;
1203
1204 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1205 return -EFAULT;
1206
1207 return dev->ethtool_ops->set_dump(dev, &dump);
1208}
1209
1210static int ethtool_get_dump_flag(struct net_device *dev,
1211 void __user *useraddr)
1212{
1213 int ret;
1214 struct ethtool_dump dump;
1215 const struct ethtool_ops *ops = dev->ethtool_ops;
1216
1217 if (!dev->ethtool_ops->get_dump_flag)
1218 return -EOPNOTSUPP;
1219
1220 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1221 return -EFAULT;
1222
1223 ret = ops->get_dump_flag(dev, &dump);
1224 if (ret)
1225 return ret;
1226
1227 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1228 return -EFAULT;
1229 return 0;
1230}
1231
1232static int ethtool_get_dump_data(struct net_device *dev,
1233 void __user *useraddr)
1234{
1235 int ret;
1236 __u32 len;
1237 struct ethtool_dump dump, tmp;
1238 const struct ethtool_ops *ops = dev->ethtool_ops;
1239 void *data = NULL;
1240
1241 if (!dev->ethtool_ops->get_dump_data ||
1242 !dev->ethtool_ops->get_dump_flag)
1243 return -EOPNOTSUPP;
1244
1245 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1246 return -EFAULT;
1247
1248 memset(&tmp, 0, sizeof(tmp));
1249 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1250 ret = ops->get_dump_flag(dev, &tmp);
1251 if (ret)
1252 return ret;
1253
1254 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1255 if (!len)
1256 return -EFAULT;
1257
1258 data = vzalloc(tmp.len);
1259 if (!data)
1260 return -ENOMEM;
1261 ret = ops->get_dump_data(dev, &dump, data);
1262 if (ret)
1263 goto out;
1264
1265 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1266 ret = -EFAULT;
1267 goto out;
1268 }
1269 useraddr += offsetof(struct ethtool_dump, data);
1270 if (copy_to_user(useraddr, data, len))
1271 ret = -EFAULT;
1272out:
1273 vfree(data);
1274 return ret;
1275}
1276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277/* The main entry point in this file. Called from net/core/dev.c */
1278
Eric W. Biederman881d9662007-09-17 11:56:21 -07001279int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001281 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 void __user *useraddr = ifr->ifr_data;
1283 u32 ethcmd;
1284 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001285 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 if (!dev || !netif_device_present(dev))
1288 return -ENODEV;
1289
chavey97f8aef2010-04-07 21:54:42 -07001290 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 return -EFAULT;
1292
Ben Hutchings01414802010-08-17 02:31:15 -07001293 if (!dev->ethtool_ops) {
1294 /* ETHTOOL_GDRVINFO does not require any driver support.
1295 * It is also unprivileged and does not change anything,
1296 * so we can take a shortcut to it. */
1297 if (ethcmd == ETHTOOL_GDRVINFO)
1298 return ethtool_get_drvinfo(dev, useraddr);
1299 else
1300 return -EOPNOTSUPP;
1301 }
1302
Stephen Hemminger75f31232006-09-28 15:13:37 -07001303 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001304 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001305 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001306 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001307 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001308 case ETHTOOL_GCOALESCE:
1309 case ETHTOOL_GRINGPARAM:
1310 case ETHTOOL_GPAUSEPARAM:
1311 case ETHTOOL_GRXCSUM:
1312 case ETHTOOL_GTXCSUM:
1313 case ETHTOOL_GSG:
1314 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001315 case ETHTOOL_GTSO:
1316 case ETHTOOL_GPERMADDR:
1317 case ETHTOOL_GUFO:
1318 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001319 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001320 case ETHTOOL_GFLAGS:
1321 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001322 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001323 case ETHTOOL_GRXRINGS:
1324 case ETHTOOL_GRXCLSRLCNT:
1325 case ETHTOOL_GRXCLSRULE:
1326 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001327 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001328 break;
1329 default:
1330 if (!capable(CAP_NET_ADMIN))
1331 return -EPERM;
1332 }
1333
chavey97f8aef2010-04-07 21:54:42 -07001334 if (dev->ethtool_ops->begin) {
1335 rc = dev->ethtool_ops->begin(dev);
1336 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001338 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001339 old_features = dev->features;
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 switch (ethcmd) {
1342 case ETHTOOL_GSET:
1343 rc = ethtool_get_settings(dev, useraddr);
1344 break;
1345 case ETHTOOL_SSET:
1346 rc = ethtool_set_settings(dev, useraddr);
1347 break;
1348 case ETHTOOL_GDRVINFO:
1349 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 break;
1351 case ETHTOOL_GREGS:
1352 rc = ethtool_get_regs(dev, useraddr);
1353 break;
1354 case ETHTOOL_GWOL:
1355 rc = ethtool_get_wol(dev, useraddr);
1356 break;
1357 case ETHTOOL_SWOL:
1358 rc = ethtool_set_wol(dev, useraddr);
1359 break;
1360 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001361 rc = ethtool_get_value(dev, useraddr, ethcmd,
1362 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 break;
1364 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001365 rc = ethtool_set_value_void(dev, useraddr,
1366 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 break;
1368 case ETHTOOL_NWAY_RST:
1369 rc = ethtool_nway_reset(dev);
1370 break;
1371 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001372 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 break;
1374 case ETHTOOL_GEEPROM:
1375 rc = ethtool_get_eeprom(dev, useraddr);
1376 break;
1377 case ETHTOOL_SEEPROM:
1378 rc = ethtool_set_eeprom(dev, useraddr);
1379 break;
1380 case ETHTOOL_GCOALESCE:
1381 rc = ethtool_get_coalesce(dev, useraddr);
1382 break;
1383 case ETHTOOL_SCOALESCE:
1384 rc = ethtool_set_coalesce(dev, useraddr);
1385 break;
1386 case ETHTOOL_GRINGPARAM:
1387 rc = ethtool_get_ringparam(dev, useraddr);
1388 break;
1389 case ETHTOOL_SRINGPARAM:
1390 rc = ethtool_set_ringparam(dev, useraddr);
1391 break;
1392 case ETHTOOL_GPAUSEPARAM:
1393 rc = ethtool_get_pauseparam(dev, useraddr);
1394 break;
1395 case ETHTOOL_SPAUSEPARAM:
1396 rc = ethtool_set_pauseparam(dev, useraddr);
1397 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 case ETHTOOL_TEST:
1399 rc = ethtool_self_test(dev, useraddr);
1400 break;
1401 case ETHTOOL_GSTRINGS:
1402 rc = ethtool_get_strings(dev, useraddr);
1403 break;
1404 case ETHTOOL_PHYS_ID:
1405 rc = ethtool_phys_id(dev, useraddr);
1406 break;
1407 case ETHTOOL_GSTATS:
1408 rc = ethtool_get_stats(dev, useraddr);
1409 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001410 case ETHTOOL_GPERMADDR:
1411 rc = ethtool_get_perm_addr(dev, useraddr);
1412 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001413 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001414 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001415 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001416 break;
1417 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001418 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001419 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001420 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001421 rc = ethtool_get_value(dev, useraddr, ethcmd,
1422 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001423 break;
1424 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001425 rc = ethtool_set_value(dev, useraddr,
1426 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001427 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001428 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001429 case ETHTOOL_GRXRINGS:
1430 case ETHTOOL_GRXCLSRLCNT:
1431 case ETHTOOL_GRXCLSRULE:
1432 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001433 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001434 break;
1435 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001436 case ETHTOOL_SRXCLSRLDEL:
1437 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001438 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001439 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001440 case ETHTOOL_FLASHDEV:
1441 rc = ethtool_flash_device(dev, useraddr);
1442 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001443 case ETHTOOL_RESET:
1444 rc = ethtool_reset(dev, useraddr);
1445 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001446 case ETHTOOL_SRXNTUPLE:
1447 rc = ethtool_set_rx_ntuple(dev, useraddr);
1448 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001449 case ETHTOOL_GSSET_INFO:
1450 rc = ethtool_get_sset_info(dev, useraddr);
1451 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001452 case ETHTOOL_GRXFHINDIR:
1453 rc = ethtool_get_rxfh_indir(dev, useraddr);
1454 break;
1455 case ETHTOOL_SRXFHINDIR:
1456 rc = ethtool_set_rxfh_indir(dev, useraddr);
1457 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001458 case ETHTOOL_GFEATURES:
1459 rc = ethtool_get_features(dev, useraddr);
1460 break;
1461 case ETHTOOL_SFEATURES:
1462 rc = ethtool_set_features(dev, useraddr);
1463 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001464 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001465 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001466 case ETHTOOL_GSG:
1467 case ETHTOOL_GTSO:
1468 case ETHTOOL_GUFO:
1469 case ETHTOOL_GGSO:
1470 case ETHTOOL_GGRO:
1471 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1472 break;
1473 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001474 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001475 case ETHTOOL_SSG:
1476 case ETHTOOL_STSO:
1477 case ETHTOOL_SUFO:
1478 case ETHTOOL_SGSO:
1479 case ETHTOOL_SGRO:
1480 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1481 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001482 case ETHTOOL_GCHANNELS:
1483 rc = ethtool_get_channels(dev, useraddr);
1484 break;
1485 case ETHTOOL_SCHANNELS:
1486 rc = ethtool_set_channels(dev, useraddr);
1487 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001488 case ETHTOOL_SET_DUMP:
1489 rc = ethtool_set_dump(dev, useraddr);
1490 break;
1491 case ETHTOOL_GET_DUMP_FLAG:
1492 rc = ethtool_get_dump_flag(dev, useraddr);
1493 break;
1494 case ETHTOOL_GET_DUMP_DATA:
1495 rc = ethtool_get_dump_data(dev, useraddr);
1496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001498 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001500
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001501 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001503
1504 if (old_features != dev->features)
1505 netdev_features_change(dev);
1506
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}