blob: 817ad4b2b9dbfc0d51afc89fab63fb51f2767c49 [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
Michał Mirosław9d921542011-11-15 15:29:55 +000043static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
44 [NETIF_F_SG_BIT] = "tx-scatter-gather",
45 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
46 [NETIF_F_NO_CSUM_BIT] = "tx-checksum-unneeded",
47 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
48 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
49 [NETIF_F_HIGHDMA_BIT] = "highdma",
50 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
51 [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert",
52
53 [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse",
54 [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter",
55 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
56 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
57 [NETIF_F_LLTX_BIT] = "tx-lockless",
58 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
59 [NETIF_F_GRO_BIT] = "rx-gro",
60 [NETIF_F_LRO_BIT] = "rx-lro",
61
62 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
63 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
64 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
65 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
66 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
67 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
68
69 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
70 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
71 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
72 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
73 [NETIF_F_RXHASH_BIT] = "rx-hashing",
74 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
75 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
76 [NETIF_F_LOOPBACK_BIT] = "loopback",
77};
78
Michał Mirosław5455c692011-02-15 16:59:17 +000079static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
80{
81 struct ethtool_gfeatures cmd = {
82 .cmd = ETHTOOL_GFEATURES,
83 .size = ETHTOOL_DEV_FEATURE_WORDS,
84 };
85 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = {
86 {
87 .available = dev->hw_features,
88 .requested = dev->wanted_features,
89 .active = dev->features,
90 .never_changed = NETIF_F_NEVER_CHANGE,
91 },
92 };
93 u32 __user *sizeaddr;
94 u32 copy_size;
95
96 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
97 if (get_user(copy_size, sizeaddr))
98 return -EFAULT;
99
100 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
101 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
102
103 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
104 return -EFAULT;
105 useraddr += sizeof(cmd);
106 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
107 return -EFAULT;
108
109 return 0;
110}
111
112static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
113{
114 struct ethtool_sfeatures cmd;
115 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
116 int ret = 0;
117
118 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
119 return -EFAULT;
120 useraddr += sizeof(cmd);
121
122 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
123 return -EINVAL;
124
125 if (copy_from_user(features, useraddr, sizeof(features)))
126 return -EFAULT;
127
128 if (features[0].valid & ~NETIF_F_ETHTOOL_BITS)
129 return -EINVAL;
130
131 if (features[0].valid & ~dev->hw_features) {
132 features[0].valid &= dev->hw_features;
133 ret |= ETHTOOL_F_UNSUPPORTED;
134 }
135
136 dev->wanted_features &= ~features[0].valid;
137 dev->wanted_features |= features[0].valid & features[0].requested;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700138 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000139
140 if ((dev->wanted_features ^ dev->features) & features[0].valid)
141 ret |= ETHTOOL_F_WISH;
142
143 return ret;
144}
145
Michał Mirosław340ae162011-02-15 16:59:16 +0000146static int __ethtool_get_sset_count(struct net_device *dev, int sset)
147{
148 const struct ethtool_ops *ops = dev->ethtool_ops;
149
Michał Mirosław5455c692011-02-15 16:59:17 +0000150 if (sset == ETH_SS_FEATURES)
151 return ARRAY_SIZE(netdev_features_strings);
152
Michał Mirosław340ae162011-02-15 16:59:16 +0000153 if (ops && ops->get_sset_count && ops->get_strings)
154 return ops->get_sset_count(dev, sset);
155 else
156 return -EOPNOTSUPP;
157}
158
159static void __ethtool_get_strings(struct net_device *dev,
160 u32 stringset, u8 *data)
161{
162 const struct ethtool_ops *ops = dev->ethtool_ops;
163
Michał Mirosław5455c692011-02-15 16:59:17 +0000164 if (stringset == ETH_SS_FEATURES)
165 memcpy(data, netdev_features_strings,
166 sizeof(netdev_features_strings));
167 else
168 /* ops->get_strings is valid because checked earlier */
169 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000170}
171
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000172static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000173{
174 /* feature masks of legacy discrete ethtool ops */
175
176 switch (eth_cmd) {
177 case ETHTOOL_GTXCSUM:
178 case ETHTOOL_STXCSUM:
179 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000180 case ETHTOOL_GRXCSUM:
181 case ETHTOOL_SRXCSUM:
182 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000183 case ETHTOOL_GSG:
184 case ETHTOOL_SSG:
185 return NETIF_F_SG;
186 case ETHTOOL_GTSO:
187 case ETHTOOL_STSO:
188 return NETIF_F_ALL_TSO;
189 case ETHTOOL_GUFO:
190 case ETHTOOL_SUFO:
191 return NETIF_F_UFO;
192 case ETHTOOL_GGSO:
193 case ETHTOOL_SGSO:
194 return NETIF_F_GSO;
195 case ETHTOOL_GGRO:
196 case ETHTOOL_SGRO:
197 return NETIF_F_GRO;
198 default:
199 BUG();
200 }
201}
202
Michał Mirosław0a417702011-02-15 16:59:17 +0000203static int ethtool_get_one_feature(struct net_device *dev,
204 char __user *useraddr, u32 ethcmd)
205{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000206 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000207 struct ethtool_value edata = {
208 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000209 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000210 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000211
Michał Mirosław0a417702011-02-15 16:59:17 +0000212 if (copy_to_user(useraddr, &edata, sizeof(edata)))
213 return -EFAULT;
214 return 0;
215}
216
Michał Mirosław0a417702011-02-15 16:59:17 +0000217static int ethtool_set_one_feature(struct net_device *dev,
218 void __user *useraddr, u32 ethcmd)
219{
220 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000221 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000222
223 if (copy_from_user(&edata, useraddr, sizeof(edata)))
224 return -EFAULT;
225
Michał Mirosław86794882011-02-15 16:59:17 +0000226 mask = ethtool_get_feature_mask(ethcmd);
227 mask &= dev->hw_features;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000228 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000229 return -EOPNOTSUPP;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000230
231 if (edata.data)
232 dev->wanted_features |= mask;
233 else
234 dev->wanted_features &= ~mask;
235
236 __netdev_update_features(dev);
237
238 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000239}
240
Michał Mirosław02b3a552011-11-15 15:29:55 +0000241#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
242 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
243#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
244 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000245
246static u32 __ethtool_get_flags(struct net_device *dev)
247{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000248 u32 flags = 0;
249
250 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
251 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
252 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
253 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
254 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
255
256 return flags;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000257}
258
259static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000260{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000261 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000262
Michał Mirosław02b3a552011-11-15 15:29:55 +0000263 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000264 return -EINVAL;
265
Michał Mirosław02b3a552011-11-15 15:29:55 +0000266 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
267 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
268 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
269 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
270 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
271
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000272 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000273 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000274 if (changed & ~dev->hw_features)
275 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
276
277 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000278 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000279
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700280 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000281
282 return 0;
283}
284
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000285int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000287 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000289 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return -EOPNOTSUPP;
291
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000292 memset(cmd, 0, sizeof(struct ethtool_cmd));
293 cmd->cmd = ETHTOOL_GSET;
294 return dev->ethtool_ops->get_settings(dev, cmd);
295}
296EXPORT_SYMBOL(__ethtool_get_settings);
297
298static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
299{
300 int err;
301 struct ethtool_cmd cmd;
302
303 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (err < 0)
305 return err;
306
307 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
308 return -EFAULT;
309 return 0;
310}
311
312static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
313{
314 struct ethtool_cmd cmd;
315
316 if (!dev->ethtool_ops->set_settings)
317 return -EOPNOTSUPP;
318
319 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
320 return -EFAULT;
321
322 return dev->ethtool_ops->set_settings(dev, &cmd);
323}
324
chavey97f8aef2010-04-07 21:54:42 -0700325static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
326 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700329 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 memset(&info, 0, sizeof(info));
332 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700333 if (ops && ops->get_drvinfo) {
334 ops->get_drvinfo(dev, &info);
335 } else if (dev->dev.parent && dev->dev.parent->driver) {
336 strlcpy(info.bus_info, dev_name(dev->dev.parent),
337 sizeof(info.bus_info));
338 strlcpy(info.driver, dev->dev.parent->driver->name,
339 sizeof(info.driver));
340 } else {
341 return -EOPNOTSUPP;
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Jeff Garzik723b2f52010-03-03 22:51:50 +0000344 /*
345 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000346 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000347 */
Ben Hutchings01414802010-08-17 02:31:15 -0700348 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700349 int rc;
350
351 rc = ops->get_sset_count(dev, ETH_SS_TEST);
352 if (rc >= 0)
353 info.testinfo_len = rc;
354 rc = ops->get_sset_count(dev, ETH_SS_STATS);
355 if (rc >= 0)
356 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700357 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
358 if (rc >= 0)
359 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700360 }
Ben Hutchings01414802010-08-17 02:31:15 -0700361 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700363 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 info.eedump_len = ops->get_eeprom_len(dev);
365
366 if (copy_to_user(useraddr, &info, sizeof(info)))
367 return -EFAULT;
368 return 0;
369}
370
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800371static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700372 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000373{
374 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000375 u64 sset_mask;
376 int i, idx = 0, n_bits = 0, ret, rc;
377 u32 *info_buf = NULL;
378
Jeff Garzik723b2f52010-03-03 22:51:50 +0000379 if (copy_from_user(&info, useraddr, sizeof(info)))
380 return -EFAULT;
381
382 /* store copy of mask, because we zero struct later on */
383 sset_mask = info.sset_mask;
384 if (!sset_mask)
385 return 0;
386
387 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000388 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000389
390 memset(&info, 0, sizeof(info));
391 info.cmd = ETHTOOL_GSSET_INFO;
392
393 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
394 if (!info_buf)
395 return -ENOMEM;
396
397 /*
398 * fill return buffer based on input bitmask and successful
399 * get_sset_count return
400 */
401 for (i = 0; i < 64; i++) {
402 if (!(sset_mask & (1ULL << i)))
403 continue;
404
Michał Mirosław340ae162011-02-15 16:59:16 +0000405 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000406 if (rc >= 0) {
407 info.sset_mask |= (1ULL << i);
408 info_buf[idx++] = rc;
409 }
410 }
411
412 ret = -EFAULT;
413 if (copy_to_user(useraddr, &info, sizeof(info)))
414 goto out;
415
416 useraddr += offsetof(struct ethtool_sset_info, data);
417 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
418 goto out;
419
420 ret = 0;
421
422out:
423 kfree(info_buf);
424 return ret;
425}
426
chavey97f8aef2010-04-07 21:54:42 -0700427static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000428 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700429{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000430 struct ethtool_rxnfc info;
431 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700432
Santwona Behera59089d82009-02-20 00:58:13 -0800433 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700434 return -EOPNOTSUPP;
435
Ben Hutchingsbf988432010-06-28 08:45:58 +0000436 /* struct ethtool_rxnfc was originally defined for
437 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
438 * members. User-space might still be using that
439 * definition. */
440 if (cmd == ETHTOOL_SRXFH)
441 info_size = (offsetof(struct ethtool_rxnfc, data) +
442 sizeof(info.data));
443
444 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700445 return -EFAULT;
446
Ben Hutchingsbf988432010-06-28 08:45:58 +0000447 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700448}
449
chavey97f8aef2010-04-07 21:54:42 -0700450static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000451 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700452{
453 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000454 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800455 const struct ethtool_ops *ops = dev->ethtool_ops;
456 int ret;
457 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700458
Santwona Behera59089d82009-02-20 00:58:13 -0800459 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700460 return -EOPNOTSUPP;
461
Ben Hutchingsbf988432010-06-28 08:45:58 +0000462 /* struct ethtool_rxnfc was originally defined for
463 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
464 * members. User-space might still be using that
465 * definition. */
466 if (cmd == ETHTOOL_GRXFH)
467 info_size = (offsetof(struct ethtool_rxnfc, data) +
468 sizeof(info.data));
469
470 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700471 return -EFAULT;
472
Santwona Behera59089d82009-02-20 00:58:13 -0800473 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
474 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000475 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000476 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000477 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800478 if (!rule_buf)
479 return -ENOMEM;
480 }
481 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700482
Santwona Behera59089d82009-02-20 00:58:13 -0800483 ret = ops->get_rxnfc(dev, &info, rule_buf);
484 if (ret < 0)
485 goto err_out;
486
487 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000488 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800489 goto err_out;
490
491 if (rule_buf) {
492 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
493 if (copy_to_user(useraddr, rule_buf,
494 info.rule_cnt * sizeof(u32)))
495 goto err_out;
496 }
497 ret = 0;
498
499err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700500 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800501
502 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700503}
504
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000505static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
506 void __user *useraddr)
507{
508 struct ethtool_rxfh_indir *indir;
509 u32 table_size;
510 size_t full_size;
511 int ret;
512
513 if (!dev->ethtool_ops->get_rxfh_indir)
514 return -EOPNOTSUPP;
515
516 if (copy_from_user(&table_size,
517 useraddr + offsetof(struct ethtool_rxfh_indir, size),
518 sizeof(table_size)))
519 return -EFAULT;
520
521 if (table_size >
522 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
523 return -ENOMEM;
524 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
Kees Cookb00916b2010-10-11 12:23:25 -0700525 indir = kzalloc(full_size, GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000526 if (!indir)
527 return -ENOMEM;
528
529 indir->cmd = ETHTOOL_GRXFHINDIR;
530 indir->size = table_size;
531 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
532 if (ret)
533 goto out;
534
535 if (copy_to_user(useraddr, indir, full_size))
536 ret = -EFAULT;
537
538out:
539 kfree(indir);
540 return ret;
541}
542
543static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
544 void __user *useraddr)
545{
546 struct ethtool_rxfh_indir *indir;
547 u32 table_size;
548 size_t full_size;
549 int ret;
550
551 if (!dev->ethtool_ops->set_rxfh_indir)
552 return -EOPNOTSUPP;
553
554 if (copy_from_user(&table_size,
555 useraddr + offsetof(struct ethtool_rxfh_indir, size),
556 sizeof(table_size)))
557 return -EFAULT;
558
559 if (table_size >
560 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
561 return -ENOMEM;
562 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
563 indir = kmalloc(full_size, GFP_USER);
564 if (!indir)
565 return -ENOMEM;
566
567 if (copy_from_user(indir, useraddr, full_size)) {
568 ret = -EFAULT;
569 goto out;
570 }
571
572 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
573
574out:
575 kfree(indir);
576 return ret;
577}
578
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000579/*
580 * ethtool does not (or did not) set masks for flow parameters that are
581 * not specified, so if both value and mask are 0 then this must be
582 * treated as equivalent to a mask with all bits set. Implement that
583 * here rather than in drivers.
584 */
585static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
586{
587 struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
588 struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
589
590 if (fs->flow_type != TCP_V4_FLOW &&
591 fs->flow_type != UDP_V4_FLOW &&
592 fs->flow_type != SCTP_V4_FLOW)
593 return;
594
595 if (!(entry->ip4src | mask->ip4src))
596 mask->ip4src = htonl(0xffffffff);
597 if (!(entry->ip4dst | mask->ip4dst))
598 mask->ip4dst = htonl(0xffffffff);
599 if (!(entry->psrc | mask->psrc))
600 mask->psrc = htons(0xffff);
601 if (!(entry->pdst | mask->pdst))
602 mask->pdst = htons(0xffff);
603 if (!(entry->tos | mask->tos))
604 mask->tos = 0xff;
605 if (!(fs->vlan_tag | fs->vlan_tag_mask))
606 fs->vlan_tag_mask = 0xffff;
607 if (!(fs->data | fs->data_mask))
608 fs->data_mask = 0xffffffffffffffffULL;
609}
610
chavey97f8aef2010-04-07 21:54:42 -0700611static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
612 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800613{
614 struct ethtool_rx_ntuple cmd;
615 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800616
Alexander Duyck5d9f11c2011-04-08 12:07:22 +0000617 if (!ops->set_rx_ntuple)
618 return -EOPNOTSUPP;
619
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800620 if (!(dev->features & NETIF_F_NTUPLE))
621 return -EINVAL;
622
623 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
624 return -EFAULT;
625
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000626 rx_ntuple_fix_masks(&cmd.fs);
627
Alexander Duyckbff55272011-06-08 12:35:08 +0000628 return ops->set_rx_ntuple(dev, &cmd);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
632{
633 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700634 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 void *regbuf;
636 int reglen, ret;
637
638 if (!ops->get_regs || !ops->get_regs_len)
639 return -EOPNOTSUPP;
640
641 if (copy_from_user(&regs, useraddr, sizeof(regs)))
642 return -EFAULT;
643
644 reglen = ops->get_regs_len(dev);
645 if (regs.len > reglen)
646 regs.len = reglen;
647
Eugene Teob7c7d012011-01-24 21:05:17 -0800648 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700649 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 return -ENOMEM;
651
652 ops->get_regs(dev, &regs, regbuf);
653
654 ret = -EFAULT;
655 if (copy_to_user(useraddr, &regs, sizeof(regs)))
656 goto out;
657 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700658 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 goto out;
660 ret = 0;
661
662 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000663 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return ret;
665}
666
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000667static int ethtool_reset(struct net_device *dev, char __user *useraddr)
668{
669 struct ethtool_value reset;
670 int ret;
671
672 if (!dev->ethtool_ops->reset)
673 return -EOPNOTSUPP;
674
675 if (copy_from_user(&reset, useraddr, sizeof(reset)))
676 return -EFAULT;
677
678 ret = dev->ethtool_ops->reset(dev, &reset.data);
679 if (ret)
680 return ret;
681
682 if (copy_to_user(useraddr, &reset, sizeof(reset)))
683 return -EFAULT;
684 return 0;
685}
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
688{
Roland Dreier8e557422010-02-11 12:14:23 -0800689 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 if (!dev->ethtool_ops->get_wol)
692 return -EOPNOTSUPP;
693
694 dev->ethtool_ops->get_wol(dev, &wol);
695
696 if (copy_to_user(useraddr, &wol, sizeof(wol)))
697 return -EFAULT;
698 return 0;
699}
700
701static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
702{
703 struct ethtool_wolinfo wol;
704
705 if (!dev->ethtool_ops->set_wol)
706 return -EOPNOTSUPP;
707
708 if (copy_from_user(&wol, useraddr, sizeof(wol)))
709 return -EFAULT;
710
711 return dev->ethtool_ops->set_wol(dev, &wol);
712}
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714static int ethtool_nway_reset(struct net_device *dev)
715{
716 if (!dev->ethtool_ops->nway_reset)
717 return -EOPNOTSUPP;
718
719 return dev->ethtool_ops->nway_reset(dev);
720}
721
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000722static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
723{
724 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
725
726 if (!dev->ethtool_ops->get_link)
727 return -EOPNOTSUPP;
728
729 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
730
731 if (copy_to_user(useraddr, &edata, sizeof(edata)))
732 return -EFAULT;
733 return 0;
734}
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
737{
738 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700739 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700740 void __user *userbuf = useraddr + sizeof(eeprom);
741 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700743 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 if (!ops->get_eeprom || !ops->get_eeprom_len)
746 return -EOPNOTSUPP;
747
748 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
749 return -EFAULT;
750
751 /* Check for wrap and zero */
752 if (eeprom.offset + eeprom.len <= eeprom.offset)
753 return -EINVAL;
754
755 /* Check for exceeding total eeprom len */
756 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
757 return -EINVAL;
758
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700759 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 if (!data)
761 return -ENOMEM;
762
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700763 bytes_remaining = eeprom.len;
764 while (bytes_remaining > 0) {
765 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700767 ret = ops->get_eeprom(dev, &eeprom, data);
768 if (ret)
769 break;
770 if (copy_to_user(userbuf, data, eeprom.len)) {
771 ret = -EFAULT;
772 break;
773 }
774 userbuf += eeprom.len;
775 eeprom.offset += eeprom.len;
776 bytes_remaining -= eeprom.len;
777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700779 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
780 eeprom.offset -= eeprom.len;
781 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
782 ret = -EFAULT;
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 kfree(data);
785 return ret;
786}
787
788static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
789{
790 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700791 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700792 void __user *userbuf = useraddr + sizeof(eeprom);
793 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700795 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (!ops->set_eeprom || !ops->get_eeprom_len)
798 return -EOPNOTSUPP;
799
800 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
801 return -EFAULT;
802
803 /* Check for wrap and zero */
804 if (eeprom.offset + eeprom.len <= eeprom.offset)
805 return -EINVAL;
806
807 /* Check for exceeding total eeprom len */
808 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
809 return -EINVAL;
810
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700811 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 if (!data)
813 return -ENOMEM;
814
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700815 bytes_remaining = eeprom.len;
816 while (bytes_remaining > 0) {
817 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700819 if (copy_from_user(data, userbuf, eeprom.len)) {
820 ret = -EFAULT;
821 break;
822 }
823 ret = ops->set_eeprom(dev, &eeprom, data);
824 if (ret)
825 break;
826 userbuf += eeprom.len;
827 eeprom.offset += eeprom.len;
828 bytes_remaining -= eeprom.len;
829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 kfree(data);
832 return ret;
833}
834
chavey97f8aef2010-04-07 21:54:42 -0700835static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
836 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Roland Dreier8e557422010-02-11 12:14:23 -0800838 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (!dev->ethtool_ops->get_coalesce)
841 return -EOPNOTSUPP;
842
843 dev->ethtool_ops->get_coalesce(dev, &coalesce);
844
845 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
846 return -EFAULT;
847 return 0;
848}
849
chavey97f8aef2010-04-07 21:54:42 -0700850static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
851 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 struct ethtool_coalesce coalesce;
854
David S. Millerfa04ae52005-06-06 15:07:19 -0700855 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return -EOPNOTSUPP;
857
858 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
859 return -EFAULT;
860
861 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
862}
863
864static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
865{
Roland Dreier8e557422010-02-11 12:14:23 -0800866 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (!dev->ethtool_ops->get_ringparam)
869 return -EOPNOTSUPP;
870
871 dev->ethtool_ops->get_ringparam(dev, &ringparam);
872
873 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
874 return -EFAULT;
875 return 0;
876}
877
878static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
879{
880 struct ethtool_ringparam ringparam;
881
882 if (!dev->ethtool_ops->set_ringparam)
883 return -EOPNOTSUPP;
884
885 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
886 return -EFAULT;
887
888 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
889}
890
amit salecha8b5933c2011-04-07 01:58:42 +0000891static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
892 void __user *useraddr)
893{
894 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
895
896 if (!dev->ethtool_ops->get_channels)
897 return -EOPNOTSUPP;
898
899 dev->ethtool_ops->get_channels(dev, &channels);
900
901 if (copy_to_user(useraddr, &channels, sizeof(channels)))
902 return -EFAULT;
903 return 0;
904}
905
906static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
907 void __user *useraddr)
908{
909 struct ethtool_channels channels;
910
911 if (!dev->ethtool_ops->set_channels)
912 return -EOPNOTSUPP;
913
914 if (copy_from_user(&channels, useraddr, sizeof(channels)))
915 return -EFAULT;
916
917 return dev->ethtool_ops->set_channels(dev, &channels);
918}
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
921{
922 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
923
924 if (!dev->ethtool_ops->get_pauseparam)
925 return -EOPNOTSUPP;
926
927 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
928
929 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
930 return -EFAULT;
931 return 0;
932}
933
934static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
935{
936 struct ethtool_pauseparam pauseparam;
937
Jeff Garzike1b90c42006-07-17 12:54:40 -0400938 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return -EOPNOTSUPP;
940
941 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
942 return -EFAULT;
943
944 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
945}
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
948{
949 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700950 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700952 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000954 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700955 return -EOPNOTSUPP;
956
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000957 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700958 if (test_len < 0)
959 return test_len;
960 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 if (copy_from_user(&test, useraddr, sizeof(test)))
963 return -EFAULT;
964
Jeff Garzikff03d492007-08-15 16:01:08 -0700965 test.len = test_len;
966 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (!data)
968 return -ENOMEM;
969
970 ops->self_test(dev, &test, data);
971
972 ret = -EFAULT;
973 if (copy_to_user(useraddr, &test, sizeof(test)))
974 goto out;
975 useraddr += sizeof(test);
976 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
977 goto out;
978 ret = 0;
979
980 out:
981 kfree(data);
982 return ret;
983}
984
985static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
986{
987 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 u8 *data;
989 int ret;
990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
992 return -EFAULT;
993
Michał Mirosław340ae162011-02-15 16:59:16 +0000994 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000995 if (ret < 0)
996 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -0700997
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000998 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1001 if (!data)
1002 return -ENOMEM;
1003
Michał Mirosław340ae162011-02-15 16:59:16 +00001004 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 ret = -EFAULT;
1007 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1008 goto out;
1009 useraddr += sizeof(gstrings);
1010 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1011 goto out;
1012 ret = 0;
1013
Michał Mirosław340ae162011-02-15 16:59:16 +00001014out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 kfree(data);
1016 return ret;
1017}
1018
1019static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1020{
1021 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001022 static bool busy;
1023 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001025 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 return -EOPNOTSUPP;
1027
Ben Hutchings68f512f2011-04-02 00:35:15 +01001028 if (busy)
1029 return -EBUSY;
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (copy_from_user(&id, useraddr, sizeof(id)))
1032 return -EFAULT;
1033
Ben Hutchings68f512f2011-04-02 00:35:15 +01001034 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001035 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001036 return rc;
1037
1038 /* Drop the RTNL lock while waiting, but prevent reentry or
1039 * removal of the device.
1040 */
1041 busy = true;
1042 dev_hold(dev);
1043 rtnl_unlock();
1044
1045 if (rc == 0) {
1046 /* Driver will handle this itself */
1047 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001048 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001049 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001050 /* Driver expects to be called at twice the frequency in rc */
1051 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001052
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001053 /* Count down seconds */
1054 do {
1055 /* Count down iterations per second */
1056 i = n;
1057 do {
1058 rtnl_lock();
1059 rc = dev->ethtool_ops->set_phys_id(dev,
1060 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1061 rtnl_unlock();
1062 if (rc)
1063 break;
1064 schedule_timeout_interruptible(interval);
1065 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001066 } while (!signal_pending(current) &&
1067 (id.data == 0 || --id.data != 0));
1068 }
1069
1070 rtnl_lock();
1071 dev_put(dev);
1072 busy = false;
1073
1074 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1075 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
1078static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1079{
1080 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001081 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001083 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001085 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001086 return -EOPNOTSUPP;
1087
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001088 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001089 if (n_stats < 0)
1090 return n_stats;
1091 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1094 return -EFAULT;
1095
Jeff Garzikff03d492007-08-15 16:01:08 -07001096 stats.n_stats = n_stats;
1097 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (!data)
1099 return -ENOMEM;
1100
1101 ops->get_ethtool_stats(dev, &stats, data);
1102
1103 ret = -EFAULT;
1104 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1105 goto out;
1106 useraddr += sizeof(stats);
1107 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1108 goto out;
1109 ret = 0;
1110
1111 out:
1112 kfree(data);
1113 return ret;
1114}
1115
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001116static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001117{
1118 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001119
Matthew Wilcox313674a2007-07-31 14:00:29 -07001120 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001121 return -EFAULT;
1122
Matthew Wilcox313674a2007-07-31 14:00:29 -07001123 if (epaddr.size < dev->addr_len)
1124 return -ETOOSMALL;
1125 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001126
Jon Wetzela6f9a702005-08-20 17:15:54 -07001127 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001128 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001129 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001130 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1131 return -EFAULT;
1132 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001133}
1134
Jeff Garzik13c99b22007-08-15 16:01:56 -07001135static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1136 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001137{
Roland Dreier8e557422010-02-11 12:14:23 -08001138 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001139
Jeff Garzik13c99b22007-08-15 16:01:56 -07001140 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001141 return -EOPNOTSUPP;
1142
Jeff Garzik13c99b22007-08-15 16:01:56 -07001143 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001144
1145 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1146 return -EFAULT;
1147 return 0;
1148}
1149
Jeff Garzik13c99b22007-08-15 16:01:56 -07001150static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1151 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001152{
1153 struct ethtool_value edata;
1154
Jeff Garzik13c99b22007-08-15 16:01:56 -07001155 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001156 return -EOPNOTSUPP;
1157
1158 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1159 return -EFAULT;
1160
Jeff Garzik13c99b22007-08-15 16:01:56 -07001161 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001162 return 0;
1163}
1164
Jeff Garzik13c99b22007-08-15 16:01:56 -07001165static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1166 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001167{
1168 struct ethtool_value edata;
1169
Jeff Garzik13c99b22007-08-15 16:01:56 -07001170 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001171 return -EOPNOTSUPP;
1172
1173 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1174 return -EFAULT;
1175
Jeff Garzik13c99b22007-08-15 16:01:56 -07001176 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001177}
1178
chavey97f8aef2010-04-07 21:54:42 -07001179static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1180 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001181{
1182 struct ethtool_flash efl;
1183
1184 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1185 return -EFAULT;
1186
1187 if (!dev->ethtool_ops->flash_device)
1188 return -EOPNOTSUPP;
1189
1190 return dev->ethtool_ops->flash_device(dev, &efl);
1191}
1192
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001193static int ethtool_set_dump(struct net_device *dev,
1194 void __user *useraddr)
1195{
1196 struct ethtool_dump dump;
1197
1198 if (!dev->ethtool_ops->set_dump)
1199 return -EOPNOTSUPP;
1200
1201 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1202 return -EFAULT;
1203
1204 return dev->ethtool_ops->set_dump(dev, &dump);
1205}
1206
1207static int ethtool_get_dump_flag(struct net_device *dev,
1208 void __user *useraddr)
1209{
1210 int ret;
1211 struct ethtool_dump dump;
1212 const struct ethtool_ops *ops = dev->ethtool_ops;
1213
1214 if (!dev->ethtool_ops->get_dump_flag)
1215 return -EOPNOTSUPP;
1216
1217 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1218 return -EFAULT;
1219
1220 ret = ops->get_dump_flag(dev, &dump);
1221 if (ret)
1222 return ret;
1223
1224 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1225 return -EFAULT;
1226 return 0;
1227}
1228
1229static int ethtool_get_dump_data(struct net_device *dev,
1230 void __user *useraddr)
1231{
1232 int ret;
1233 __u32 len;
1234 struct ethtool_dump dump, tmp;
1235 const struct ethtool_ops *ops = dev->ethtool_ops;
1236 void *data = NULL;
1237
1238 if (!dev->ethtool_ops->get_dump_data ||
1239 !dev->ethtool_ops->get_dump_flag)
1240 return -EOPNOTSUPP;
1241
1242 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1243 return -EFAULT;
1244
1245 memset(&tmp, 0, sizeof(tmp));
1246 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1247 ret = ops->get_dump_flag(dev, &tmp);
1248 if (ret)
1249 return ret;
1250
1251 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1252 if (!len)
1253 return -EFAULT;
1254
1255 data = vzalloc(tmp.len);
1256 if (!data)
1257 return -ENOMEM;
1258 ret = ops->get_dump_data(dev, &dump, data);
1259 if (ret)
1260 goto out;
1261
1262 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1263 ret = -EFAULT;
1264 goto out;
1265 }
1266 useraddr += offsetof(struct ethtool_dump, data);
1267 if (copy_to_user(useraddr, data, len))
1268 ret = -EFAULT;
1269out:
1270 vfree(data);
1271 return ret;
1272}
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274/* The main entry point in this file. Called from net/core/dev.c */
1275
Eric W. Biederman881d9662007-09-17 11:56:21 -07001276int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001278 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 void __user *useraddr = ifr->ifr_data;
1280 u32 ethcmd;
1281 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001282 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 if (!dev || !netif_device_present(dev))
1285 return -ENODEV;
1286
chavey97f8aef2010-04-07 21:54:42 -07001287 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 return -EFAULT;
1289
Ben Hutchings01414802010-08-17 02:31:15 -07001290 if (!dev->ethtool_ops) {
1291 /* ETHTOOL_GDRVINFO does not require any driver support.
1292 * It is also unprivileged and does not change anything,
1293 * so we can take a shortcut to it. */
1294 if (ethcmd == ETHTOOL_GDRVINFO)
1295 return ethtool_get_drvinfo(dev, useraddr);
1296 else
1297 return -EOPNOTSUPP;
1298 }
1299
Stephen Hemminger75f31232006-09-28 15:13:37 -07001300 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001301 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001302 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001303 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001304 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001305 case ETHTOOL_GCOALESCE:
1306 case ETHTOOL_GRINGPARAM:
1307 case ETHTOOL_GPAUSEPARAM:
1308 case ETHTOOL_GRXCSUM:
1309 case ETHTOOL_GTXCSUM:
1310 case ETHTOOL_GSG:
1311 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001312 case ETHTOOL_GTSO:
1313 case ETHTOOL_GPERMADDR:
1314 case ETHTOOL_GUFO:
1315 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001316 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001317 case ETHTOOL_GFLAGS:
1318 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001319 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001320 case ETHTOOL_GRXRINGS:
1321 case ETHTOOL_GRXCLSRLCNT:
1322 case ETHTOOL_GRXCLSRULE:
1323 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001324 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001325 break;
1326 default:
1327 if (!capable(CAP_NET_ADMIN))
1328 return -EPERM;
1329 }
1330
chavey97f8aef2010-04-07 21:54:42 -07001331 if (dev->ethtool_ops->begin) {
1332 rc = dev->ethtool_ops->begin(dev);
1333 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001335 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001336 old_features = dev->features;
1337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 switch (ethcmd) {
1339 case ETHTOOL_GSET:
1340 rc = ethtool_get_settings(dev, useraddr);
1341 break;
1342 case ETHTOOL_SSET:
1343 rc = ethtool_set_settings(dev, useraddr);
1344 break;
1345 case ETHTOOL_GDRVINFO:
1346 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 break;
1348 case ETHTOOL_GREGS:
1349 rc = ethtool_get_regs(dev, useraddr);
1350 break;
1351 case ETHTOOL_GWOL:
1352 rc = ethtool_get_wol(dev, useraddr);
1353 break;
1354 case ETHTOOL_SWOL:
1355 rc = ethtool_set_wol(dev, useraddr);
1356 break;
1357 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001358 rc = ethtool_get_value(dev, useraddr, ethcmd,
1359 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 break;
1361 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001362 rc = ethtool_set_value_void(dev, useraddr,
1363 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 break;
1365 case ETHTOOL_NWAY_RST:
1366 rc = ethtool_nway_reset(dev);
1367 break;
1368 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001369 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 break;
1371 case ETHTOOL_GEEPROM:
1372 rc = ethtool_get_eeprom(dev, useraddr);
1373 break;
1374 case ETHTOOL_SEEPROM:
1375 rc = ethtool_set_eeprom(dev, useraddr);
1376 break;
1377 case ETHTOOL_GCOALESCE:
1378 rc = ethtool_get_coalesce(dev, useraddr);
1379 break;
1380 case ETHTOOL_SCOALESCE:
1381 rc = ethtool_set_coalesce(dev, useraddr);
1382 break;
1383 case ETHTOOL_GRINGPARAM:
1384 rc = ethtool_get_ringparam(dev, useraddr);
1385 break;
1386 case ETHTOOL_SRINGPARAM:
1387 rc = ethtool_set_ringparam(dev, useraddr);
1388 break;
1389 case ETHTOOL_GPAUSEPARAM:
1390 rc = ethtool_get_pauseparam(dev, useraddr);
1391 break;
1392 case ETHTOOL_SPAUSEPARAM:
1393 rc = ethtool_set_pauseparam(dev, useraddr);
1394 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 case ETHTOOL_TEST:
1396 rc = ethtool_self_test(dev, useraddr);
1397 break;
1398 case ETHTOOL_GSTRINGS:
1399 rc = ethtool_get_strings(dev, useraddr);
1400 break;
1401 case ETHTOOL_PHYS_ID:
1402 rc = ethtool_phys_id(dev, useraddr);
1403 break;
1404 case ETHTOOL_GSTATS:
1405 rc = ethtool_get_stats(dev, useraddr);
1406 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001407 case ETHTOOL_GPERMADDR:
1408 rc = ethtool_get_perm_addr(dev, useraddr);
1409 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001410 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001411 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c2011-11-15 15:29:55 +00001412 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001413 break;
1414 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001415 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001416 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001417 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001418 rc = ethtool_get_value(dev, useraddr, ethcmd,
1419 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001420 break;
1421 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001422 rc = ethtool_set_value(dev, useraddr,
1423 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001424 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001425 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001426 case ETHTOOL_GRXRINGS:
1427 case ETHTOOL_GRXCLSRLCNT:
1428 case ETHTOOL_GRXCLSRULE:
1429 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001430 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001431 break;
1432 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001433 case ETHTOOL_SRXCLSRLDEL:
1434 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001435 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001436 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001437 case ETHTOOL_FLASHDEV:
1438 rc = ethtool_flash_device(dev, useraddr);
1439 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001440 case ETHTOOL_RESET:
1441 rc = ethtool_reset(dev, useraddr);
1442 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001443 case ETHTOOL_SRXNTUPLE:
1444 rc = ethtool_set_rx_ntuple(dev, useraddr);
1445 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001446 case ETHTOOL_GSSET_INFO:
1447 rc = ethtool_get_sset_info(dev, useraddr);
1448 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001449 case ETHTOOL_GRXFHINDIR:
1450 rc = ethtool_get_rxfh_indir(dev, useraddr);
1451 break;
1452 case ETHTOOL_SRXFHINDIR:
1453 rc = ethtool_set_rxfh_indir(dev, useraddr);
1454 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001455 case ETHTOOL_GFEATURES:
1456 rc = ethtool_get_features(dev, useraddr);
1457 break;
1458 case ETHTOOL_SFEATURES:
1459 rc = ethtool_set_features(dev, useraddr);
1460 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001461 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001462 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001463 case ETHTOOL_GSG:
1464 case ETHTOOL_GTSO:
1465 case ETHTOOL_GUFO:
1466 case ETHTOOL_GGSO:
1467 case ETHTOOL_GGRO:
1468 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1469 break;
1470 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001471 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001472 case ETHTOOL_SSG:
1473 case ETHTOOL_STSO:
1474 case ETHTOOL_SUFO:
1475 case ETHTOOL_SGSO:
1476 case ETHTOOL_SGRO:
1477 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1478 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001479 case ETHTOOL_GCHANNELS:
1480 rc = ethtool_get_channels(dev, useraddr);
1481 break;
1482 case ETHTOOL_SCHANNELS:
1483 rc = ethtool_set_channels(dev, useraddr);
1484 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001485 case ETHTOOL_SET_DUMP:
1486 rc = ethtool_set_dump(dev, useraddr);
1487 break;
1488 case ETHTOOL_GET_DUMP_FLAG:
1489 rc = ethtool_get_dump_flag(dev, useraddr);
1490 break;
1491 case ETHTOOL_GET_DUMP_DATA:
1492 rc = ethtool_get_dump_data(dev, useraddr);
1493 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001495 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001497
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001498 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001500
1501 if (old_features != dev->features)
1502 netdev_features_change(dev);
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}