blob: d2eff9ec88be7d548dab0a13be6ad070c105828f [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ław475414f2011-11-15 15:29:55 +000041#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
Michał Mirosław5455c692011-02-15 16:59:17 +000042
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",
Michał Mirosław9d921542011-11-15 15:29:55 +000046 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
47 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
48 [NETIF_F_HIGHDMA_BIT] = "highdma",
49 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
50 [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert",
51
52 [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse",
53 [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter",
54 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
55 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
56 [NETIF_F_LLTX_BIT] = "tx-lockless",
57 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
58 [NETIF_F_GRO_BIT] = "rx-gro",
59 [NETIF_F_LRO_BIT] = "rx-lro",
60
61 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
62 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
63 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
64 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
65 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
66 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
67
68 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
69 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
70 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
71 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
72 [NETIF_F_RXHASH_BIT] = "rx-hashing",
73 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
74 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
75 [NETIF_F_LOOPBACK_BIT] = "loopback",
76};
77
Michał Mirosław5455c692011-02-15 16:59:17 +000078static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
79{
80 struct ethtool_gfeatures cmd = {
81 .cmd = ETHTOOL_GFEATURES,
82 .size = ETHTOOL_DEV_FEATURE_WORDS,
83 };
Michał Mirosław475414f2011-11-15 15:29:55 +000084 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +000085 u32 __user *sizeaddr;
86 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +000087 int i;
88
89 /* in case feature bits run out again */
90 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS*sizeof(u32) > sizeof(netdev_features_t));
91
92 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
93 features[i].available = (u32)(dev->hw_features >> (32*i));
94 features[i].requested = (u32)(dev->wanted_features >> (32*i));
95 features[i].active = (u32)(dev->features >> (32*i));
96 features[i].never_changed = (u32)(NETIF_F_NEVER_CHANGE >> (32*i));
97 }
Michał Mirosław5455c692011-02-15 16:59:17 +000098
99 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
100 if (get_user(copy_size, sizeaddr))
101 return -EFAULT;
102
103 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
104 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
105
106 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
107 return -EFAULT;
108 useraddr += sizeof(cmd);
109 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
110 return -EFAULT;
111
112 return 0;
113}
114
115static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
116{
117 struct ethtool_sfeatures cmd;
118 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000119 netdev_features_t wanted = 0, valid = 0;
120 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000121
122 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
123 return -EFAULT;
124 useraddr += sizeof(cmd);
125
126 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
127 return -EINVAL;
128
129 if (copy_from_user(features, useraddr, sizeof(features)))
130 return -EFAULT;
131
Michał Mirosław475414f2011-11-15 15:29:55 +0000132 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
133 valid |= (netdev_features_t)features[i].valid << (32*i);
134 wanted |= (netdev_features_t)features[i].requested << (32*i);
135 }
136
137 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000138 return -EINVAL;
139
Michał Mirosław475414f2011-11-15 15:29:55 +0000140 if (valid & ~dev->hw_features) {
141 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000142 ret |= ETHTOOL_F_UNSUPPORTED;
143 }
144
Michał Mirosław475414f2011-11-15 15:29:55 +0000145 dev->wanted_features &= ~valid;
146 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700147 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000148
Michał Mirosław475414f2011-11-15 15:29:55 +0000149 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000150 ret |= ETHTOOL_F_WISH;
151
152 return ret;
153}
154
Michał Mirosław340ae162011-02-15 16:59:16 +0000155static int __ethtool_get_sset_count(struct net_device *dev, int sset)
156{
157 const struct ethtool_ops *ops = dev->ethtool_ops;
158
Michał Mirosław5455c692011-02-15 16:59:17 +0000159 if (sset == ETH_SS_FEATURES)
160 return ARRAY_SIZE(netdev_features_strings);
161
Michał Mirosław340ae162011-02-15 16:59:16 +0000162 if (ops && ops->get_sset_count && ops->get_strings)
163 return ops->get_sset_count(dev, sset);
164 else
165 return -EOPNOTSUPP;
166}
167
168static void __ethtool_get_strings(struct net_device *dev,
169 u32 stringset, u8 *data)
170{
171 const struct ethtool_ops *ops = dev->ethtool_ops;
172
Michał Mirosław5455c692011-02-15 16:59:17 +0000173 if (stringset == ETH_SS_FEATURES)
174 memcpy(data, netdev_features_strings,
175 sizeof(netdev_features_strings));
176 else
177 /* ops->get_strings is valid because checked earlier */
178 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000179}
180
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000181static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000182{
183 /* feature masks of legacy discrete ethtool ops */
184
185 switch (eth_cmd) {
186 case ETHTOOL_GTXCSUM:
187 case ETHTOOL_STXCSUM:
188 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000189 case ETHTOOL_GRXCSUM:
190 case ETHTOOL_SRXCSUM:
191 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000192 case ETHTOOL_GSG:
193 case ETHTOOL_SSG:
194 return NETIF_F_SG;
195 case ETHTOOL_GTSO:
196 case ETHTOOL_STSO:
197 return NETIF_F_ALL_TSO;
198 case ETHTOOL_GUFO:
199 case ETHTOOL_SUFO:
200 return NETIF_F_UFO;
201 case ETHTOOL_GGSO:
202 case ETHTOOL_SGSO:
203 return NETIF_F_GSO;
204 case ETHTOOL_GGRO:
205 case ETHTOOL_SGRO:
206 return NETIF_F_GRO;
207 default:
208 BUG();
209 }
210}
211
Michał Mirosław0a417702011-02-15 16:59:17 +0000212static int ethtool_get_one_feature(struct net_device *dev,
213 char __user *useraddr, u32 ethcmd)
214{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000215 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000216 struct ethtool_value edata = {
217 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000218 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000219 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000220
Michał Mirosław0a417702011-02-15 16:59:17 +0000221 if (copy_to_user(useraddr, &edata, sizeof(edata)))
222 return -EFAULT;
223 return 0;
224}
225
Michał Mirosław0a417702011-02-15 16:59:17 +0000226static int ethtool_set_one_feature(struct net_device *dev,
227 void __user *useraddr, u32 ethcmd)
228{
229 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000230 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000231
232 if (copy_from_user(&edata, useraddr, sizeof(edata)))
233 return -EFAULT;
234
Michał Mirosław86794882011-02-15 16:59:17 +0000235 mask = ethtool_get_feature_mask(ethcmd);
236 mask &= dev->hw_features;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000237 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000238 return -EOPNOTSUPP;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000239
240 if (edata.data)
241 dev->wanted_features |= mask;
242 else
243 dev->wanted_features &= ~mask;
244
245 __netdev_update_features(dev);
246
247 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000248}
249
Michał Mirosław02b3a552011-11-15 15:29:55 +0000250#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
251 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
252#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
253 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000254
255static u32 __ethtool_get_flags(struct net_device *dev)
256{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000257 u32 flags = 0;
258
259 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
260 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
261 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
262 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
263 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
264
265 return flags;
Michał Mirosławbc5787c2011-11-15 15:29:55 +0000266}
267
268static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000269{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000270 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000271
Michał Mirosław02b3a552011-11-15 15:29:55 +0000272 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000273 return -EINVAL;
274
Michał Mirosław02b3a552011-11-15 15:29:55 +0000275 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
276 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
277 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
278 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
279 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
280
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000281 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000282 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000283 if (changed & ~dev->hw_features)
284 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
285
286 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000287 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000288
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700289 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000290
291 return 0;
292}
293
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000294int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000296 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000298 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return -EOPNOTSUPP;
300
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000301 memset(cmd, 0, sizeof(struct ethtool_cmd));
302 cmd->cmd = ETHTOOL_GSET;
303 return dev->ethtool_ops->get_settings(dev, cmd);
304}
305EXPORT_SYMBOL(__ethtool_get_settings);
306
307static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
308{
309 int err;
310 struct ethtool_cmd cmd;
311
312 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (err < 0)
314 return err;
315
316 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
317 return -EFAULT;
318 return 0;
319}
320
321static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
322{
323 struct ethtool_cmd cmd;
324
325 if (!dev->ethtool_ops->set_settings)
326 return -EOPNOTSUPP;
327
328 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
329 return -EFAULT;
330
331 return dev->ethtool_ops->set_settings(dev, &cmd);
332}
333
chavey97f8aef2010-04-07 21:54:42 -0700334static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
335 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700338 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 memset(&info, 0, sizeof(info));
341 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700342 if (ops && ops->get_drvinfo) {
343 ops->get_drvinfo(dev, &info);
344 } else if (dev->dev.parent && dev->dev.parent->driver) {
345 strlcpy(info.bus_info, dev_name(dev->dev.parent),
346 sizeof(info.bus_info));
347 strlcpy(info.driver, dev->dev.parent->driver->name,
348 sizeof(info.driver));
349 } else {
350 return -EOPNOTSUPP;
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Jeff Garzik723b2f52010-03-03 22:51:50 +0000353 /*
354 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000355 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000356 */
Ben Hutchings01414802010-08-17 02:31:15 -0700357 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700358 int rc;
359
360 rc = ops->get_sset_count(dev, ETH_SS_TEST);
361 if (rc >= 0)
362 info.testinfo_len = rc;
363 rc = ops->get_sset_count(dev, ETH_SS_STATS);
364 if (rc >= 0)
365 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700366 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
367 if (rc >= 0)
368 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700369 }
Ben Hutchings01414802010-08-17 02:31:15 -0700370 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700372 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 info.eedump_len = ops->get_eeprom_len(dev);
374
375 if (copy_to_user(useraddr, &info, sizeof(info)))
376 return -EFAULT;
377 return 0;
378}
379
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800380static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700381 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000382{
383 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000384 u64 sset_mask;
385 int i, idx = 0, n_bits = 0, ret, rc;
386 u32 *info_buf = NULL;
387
Jeff Garzik723b2f52010-03-03 22:51:50 +0000388 if (copy_from_user(&info, useraddr, sizeof(info)))
389 return -EFAULT;
390
391 /* store copy of mask, because we zero struct later on */
392 sset_mask = info.sset_mask;
393 if (!sset_mask)
394 return 0;
395
396 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000397 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000398
399 memset(&info, 0, sizeof(info));
400 info.cmd = ETHTOOL_GSSET_INFO;
401
402 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
403 if (!info_buf)
404 return -ENOMEM;
405
406 /*
407 * fill return buffer based on input bitmask and successful
408 * get_sset_count return
409 */
410 for (i = 0; i < 64; i++) {
411 if (!(sset_mask & (1ULL << i)))
412 continue;
413
Michał Mirosław340ae162011-02-15 16:59:16 +0000414 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000415 if (rc >= 0) {
416 info.sset_mask |= (1ULL << i);
417 info_buf[idx++] = rc;
418 }
419 }
420
421 ret = -EFAULT;
422 if (copy_to_user(useraddr, &info, sizeof(info)))
423 goto out;
424
425 useraddr += offsetof(struct ethtool_sset_info, data);
426 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
427 goto out;
428
429 ret = 0;
430
431out:
432 kfree(info_buf);
433 return ret;
434}
435
chavey97f8aef2010-04-07 21:54:42 -0700436static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000437 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700438{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000439 struct ethtool_rxnfc info;
440 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700441
Santwona Behera59089d82009-02-20 00:58:13 -0800442 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700443 return -EOPNOTSUPP;
444
Ben Hutchingsbf988432010-06-28 08:45:58 +0000445 /* struct ethtool_rxnfc was originally defined for
446 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
447 * members. User-space might still be using that
448 * definition. */
449 if (cmd == ETHTOOL_SRXFH)
450 info_size = (offsetof(struct ethtool_rxnfc, data) +
451 sizeof(info.data));
452
453 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700454 return -EFAULT;
455
Ben Hutchingsbf988432010-06-28 08:45:58 +0000456 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700457}
458
chavey97f8aef2010-04-07 21:54:42 -0700459static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000460 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700461{
462 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000463 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800464 const struct ethtool_ops *ops = dev->ethtool_ops;
465 int ret;
466 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700467
Santwona Behera59089d82009-02-20 00:58:13 -0800468 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700469 return -EOPNOTSUPP;
470
Ben Hutchingsbf988432010-06-28 08:45:58 +0000471 /* struct ethtool_rxnfc was originally defined for
472 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
473 * members. User-space might still be using that
474 * definition. */
475 if (cmd == ETHTOOL_GRXFH)
476 info_size = (offsetof(struct ethtool_rxnfc, data) +
477 sizeof(info.data));
478
479 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700480 return -EFAULT;
481
Santwona Behera59089d82009-02-20 00:58:13 -0800482 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
483 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000484 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000485 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000486 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800487 if (!rule_buf)
488 return -ENOMEM;
489 }
490 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700491
Santwona Behera59089d82009-02-20 00:58:13 -0800492 ret = ops->get_rxnfc(dev, &info, rule_buf);
493 if (ret < 0)
494 goto err_out;
495
496 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000497 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800498 goto err_out;
499
500 if (rule_buf) {
501 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
502 if (copy_to_user(useraddr, rule_buf,
503 info.rule_cnt * sizeof(u32)))
504 goto err_out;
505 }
506 ret = 0;
507
508err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700509 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800510
511 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700512}
513
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000514static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
515 void __user *useraddr)
516{
517 struct ethtool_rxfh_indir *indir;
518 u32 table_size;
519 size_t full_size;
520 int ret;
521
522 if (!dev->ethtool_ops->get_rxfh_indir)
523 return -EOPNOTSUPP;
524
525 if (copy_from_user(&table_size,
526 useraddr + offsetof(struct ethtool_rxfh_indir, size),
527 sizeof(table_size)))
528 return -EFAULT;
529
530 if (table_size >
531 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
532 return -ENOMEM;
533 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
Kees Cookb00916b2010-10-11 12:23:25 -0700534 indir = kzalloc(full_size, GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000535 if (!indir)
536 return -ENOMEM;
537
538 indir->cmd = ETHTOOL_GRXFHINDIR;
539 indir->size = table_size;
540 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
541 if (ret)
542 goto out;
543
544 if (copy_to_user(useraddr, indir, full_size))
545 ret = -EFAULT;
546
547out:
548 kfree(indir);
549 return ret;
550}
551
552static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
553 void __user *useraddr)
554{
555 struct ethtool_rxfh_indir *indir;
556 u32 table_size;
557 size_t full_size;
558 int ret;
559
560 if (!dev->ethtool_ops->set_rxfh_indir)
561 return -EOPNOTSUPP;
562
563 if (copy_from_user(&table_size,
564 useraddr + offsetof(struct ethtool_rxfh_indir, size),
565 sizeof(table_size)))
566 return -EFAULT;
567
568 if (table_size >
569 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
570 return -ENOMEM;
571 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
572 indir = kmalloc(full_size, GFP_USER);
573 if (!indir)
574 return -ENOMEM;
575
576 if (copy_from_user(indir, useraddr, full_size)) {
577 ret = -EFAULT;
578 goto out;
579 }
580
581 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
582
583out:
584 kfree(indir);
585 return ret;
586}
587
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000588/*
589 * ethtool does not (or did not) set masks for flow parameters that are
590 * not specified, so if both value and mask are 0 then this must be
591 * treated as equivalent to a mask with all bits set. Implement that
592 * here rather than in drivers.
593 */
594static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
595{
596 struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
597 struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
598
599 if (fs->flow_type != TCP_V4_FLOW &&
600 fs->flow_type != UDP_V4_FLOW &&
601 fs->flow_type != SCTP_V4_FLOW)
602 return;
603
604 if (!(entry->ip4src | mask->ip4src))
605 mask->ip4src = htonl(0xffffffff);
606 if (!(entry->ip4dst | mask->ip4dst))
607 mask->ip4dst = htonl(0xffffffff);
608 if (!(entry->psrc | mask->psrc))
609 mask->psrc = htons(0xffff);
610 if (!(entry->pdst | mask->pdst))
611 mask->pdst = htons(0xffff);
612 if (!(entry->tos | mask->tos))
613 mask->tos = 0xff;
614 if (!(fs->vlan_tag | fs->vlan_tag_mask))
615 fs->vlan_tag_mask = 0xffff;
616 if (!(fs->data | fs->data_mask))
617 fs->data_mask = 0xffffffffffffffffULL;
618}
619
chavey97f8aef2010-04-07 21:54:42 -0700620static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
621 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800622{
623 struct ethtool_rx_ntuple cmd;
624 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800625
Alexander Duyck5d9f11c2011-04-08 12:07:22 +0000626 if (!ops->set_rx_ntuple)
627 return -EOPNOTSUPP;
628
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800629 if (!(dev->features & NETIF_F_NTUPLE))
630 return -EINVAL;
631
632 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
633 return -EFAULT;
634
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000635 rx_ntuple_fix_masks(&cmd.fs);
636
Alexander Duyckbff55272011-06-08 12:35:08 +0000637 return ops->set_rx_ntuple(dev, &cmd);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
641{
642 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700643 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 void *regbuf;
645 int reglen, ret;
646
647 if (!ops->get_regs || !ops->get_regs_len)
648 return -EOPNOTSUPP;
649
650 if (copy_from_user(&regs, useraddr, sizeof(regs)))
651 return -EFAULT;
652
653 reglen = ops->get_regs_len(dev);
654 if (regs.len > reglen)
655 regs.len = reglen;
656
Eugene Teob7c7d012011-01-24 21:05:17 -0800657 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700658 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 return -ENOMEM;
660
661 ops->get_regs(dev, &regs, regbuf);
662
663 ret = -EFAULT;
664 if (copy_to_user(useraddr, &regs, sizeof(regs)))
665 goto out;
666 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700667 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 goto out;
669 ret = 0;
670
671 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000672 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 return ret;
674}
675
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000676static int ethtool_reset(struct net_device *dev, char __user *useraddr)
677{
678 struct ethtool_value reset;
679 int ret;
680
681 if (!dev->ethtool_ops->reset)
682 return -EOPNOTSUPP;
683
684 if (copy_from_user(&reset, useraddr, sizeof(reset)))
685 return -EFAULT;
686
687 ret = dev->ethtool_ops->reset(dev, &reset.data);
688 if (ret)
689 return ret;
690
691 if (copy_to_user(useraddr, &reset, sizeof(reset)))
692 return -EFAULT;
693 return 0;
694}
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
697{
Roland Dreier8e557422010-02-11 12:14:23 -0800698 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 if (!dev->ethtool_ops->get_wol)
701 return -EOPNOTSUPP;
702
703 dev->ethtool_ops->get_wol(dev, &wol);
704
705 if (copy_to_user(useraddr, &wol, sizeof(wol)))
706 return -EFAULT;
707 return 0;
708}
709
710static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
711{
712 struct ethtool_wolinfo wol;
713
714 if (!dev->ethtool_ops->set_wol)
715 return -EOPNOTSUPP;
716
717 if (copy_from_user(&wol, useraddr, sizeof(wol)))
718 return -EFAULT;
719
720 return dev->ethtool_ops->set_wol(dev, &wol);
721}
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723static int ethtool_nway_reset(struct net_device *dev)
724{
725 if (!dev->ethtool_ops->nway_reset)
726 return -EOPNOTSUPP;
727
728 return dev->ethtool_ops->nway_reset(dev);
729}
730
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000731static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
732{
733 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
734
735 if (!dev->ethtool_ops->get_link)
736 return -EOPNOTSUPP;
737
738 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
739
740 if (copy_to_user(useraddr, &edata, sizeof(edata)))
741 return -EFAULT;
742 return 0;
743}
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
746{
747 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700748 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700749 void __user *userbuf = useraddr + sizeof(eeprom);
750 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 u8 *data;
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700752 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 if (!ops->get_eeprom || !ops->get_eeprom_len)
755 return -EOPNOTSUPP;
756
757 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
758 return -EFAULT;
759
760 /* Check for wrap and zero */
761 if (eeprom.offset + eeprom.len <= eeprom.offset)
762 return -EINVAL;
763
764 /* Check for exceeding total eeprom len */
765 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
766 return -EINVAL;
767
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700768 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 if (!data)
770 return -ENOMEM;
771
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700772 bytes_remaining = eeprom.len;
773 while (bytes_remaining > 0) {
774 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700776 ret = ops->get_eeprom(dev, &eeprom, data);
777 if (ret)
778 break;
779 if (copy_to_user(userbuf, data, eeprom.len)) {
780 ret = -EFAULT;
781 break;
782 }
783 userbuf += eeprom.len;
784 eeprom.offset += eeprom.len;
785 bytes_remaining -= eeprom.len;
786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700788 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
789 eeprom.offset -= eeprom.len;
790 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
791 ret = -EFAULT;
792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 kfree(data);
794 return ret;
795}
796
797static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
798{
799 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700800 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700801 void __user *userbuf = useraddr + sizeof(eeprom);
802 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 u8 *data;
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700804 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (!ops->set_eeprom || !ops->get_eeprom_len)
807 return -EOPNOTSUPP;
808
809 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
810 return -EFAULT;
811
812 /* Check for wrap and zero */
813 if (eeprom.offset + eeprom.len <= eeprom.offset)
814 return -EINVAL;
815
816 /* Check for exceeding total eeprom len */
817 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
818 return -EINVAL;
819
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700820 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (!data)
822 return -ENOMEM;
823
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700824 bytes_remaining = eeprom.len;
825 while (bytes_remaining > 0) {
826 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Mandeep Singh Bainesb131dd5d2008-04-15 19:24:17 -0700828 if (copy_from_user(data, userbuf, eeprom.len)) {
829 ret = -EFAULT;
830 break;
831 }
832 ret = ops->set_eeprom(dev, &eeprom, data);
833 if (ret)
834 break;
835 userbuf += eeprom.len;
836 eeprom.offset += eeprom.len;
837 bytes_remaining -= eeprom.len;
838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 kfree(data);
841 return ret;
842}
843
chavey97f8aef2010-04-07 21:54:42 -0700844static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
845 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Roland Dreier8e557422010-02-11 12:14:23 -0800847 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 if (!dev->ethtool_ops->get_coalesce)
850 return -EOPNOTSUPP;
851
852 dev->ethtool_ops->get_coalesce(dev, &coalesce);
853
854 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
855 return -EFAULT;
856 return 0;
857}
858
chavey97f8aef2010-04-07 21:54:42 -0700859static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
860 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
862 struct ethtool_coalesce coalesce;
863
David S. Millerfa04ae52005-06-06 15:07:19 -0700864 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return -EOPNOTSUPP;
866
867 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
868 return -EFAULT;
869
870 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
871}
872
873static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
874{
Roland Dreier8e557422010-02-11 12:14:23 -0800875 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (!dev->ethtool_ops->get_ringparam)
878 return -EOPNOTSUPP;
879
880 dev->ethtool_ops->get_ringparam(dev, &ringparam);
881
882 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
883 return -EFAULT;
884 return 0;
885}
886
887static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
888{
889 struct ethtool_ringparam ringparam;
890
891 if (!dev->ethtool_ops->set_ringparam)
892 return -EOPNOTSUPP;
893
894 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
895 return -EFAULT;
896
897 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
898}
899
amit salecha8b5933c2011-04-07 01:58:42 +0000900static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
901 void __user *useraddr)
902{
903 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
904
905 if (!dev->ethtool_ops->get_channels)
906 return -EOPNOTSUPP;
907
908 dev->ethtool_ops->get_channels(dev, &channels);
909
910 if (copy_to_user(useraddr, &channels, sizeof(channels)))
911 return -EFAULT;
912 return 0;
913}
914
915static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
916 void __user *useraddr)
917{
918 struct ethtool_channels channels;
919
920 if (!dev->ethtool_ops->set_channels)
921 return -EOPNOTSUPP;
922
923 if (copy_from_user(&channels, useraddr, sizeof(channels)))
924 return -EFAULT;
925
926 return dev->ethtool_ops->set_channels(dev, &channels);
927}
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
930{
931 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
932
933 if (!dev->ethtool_ops->get_pauseparam)
934 return -EOPNOTSUPP;
935
936 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
937
938 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
939 return -EFAULT;
940 return 0;
941}
942
943static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
944{
945 struct ethtool_pauseparam pauseparam;
946
Jeff Garzike1b90c42006-07-17 12:54:40 -0400947 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 return -EOPNOTSUPP;
949
950 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
951 return -EFAULT;
952
953 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
954}
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
957{
958 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700959 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700961 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000963 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700964 return -EOPNOTSUPP;
965
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000966 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700967 if (test_len < 0)
968 return test_len;
969 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 if (copy_from_user(&test, useraddr, sizeof(test)))
972 return -EFAULT;
973
Jeff Garzikff03d492007-08-15 16:01:08 -0700974 test.len = test_len;
975 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (!data)
977 return -ENOMEM;
978
979 ops->self_test(dev, &test, data);
980
981 ret = -EFAULT;
982 if (copy_to_user(useraddr, &test, sizeof(test)))
983 goto out;
984 useraddr += sizeof(test);
985 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
986 goto out;
987 ret = 0;
988
989 out:
990 kfree(data);
991 return ret;
992}
993
994static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
995{
996 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 u8 *data;
998 int ret;
999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1001 return -EFAULT;
1002
Michał Mirosław340ae162011-02-15 16:59:16 +00001003 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001004 if (ret < 0)
1005 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001006
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001007 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1010 if (!data)
1011 return -ENOMEM;
1012
Michał Mirosław340ae162011-02-15 16:59:16 +00001013 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 ret = -EFAULT;
1016 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1017 goto out;
1018 useraddr += sizeof(gstrings);
1019 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1020 goto out;
1021 ret = 0;
1022
Michał Mirosław340ae162011-02-15 16:59:16 +00001023out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 kfree(data);
1025 return ret;
1026}
1027
1028static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1029{
1030 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001031 static bool busy;
1032 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001034 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 return -EOPNOTSUPP;
1036
Ben Hutchings68f512f2011-04-02 00:35:15 +01001037 if (busy)
1038 return -EBUSY;
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (copy_from_user(&id, useraddr, sizeof(id)))
1041 return -EFAULT;
1042
Ben Hutchings68f512f2011-04-02 00:35:15 +01001043 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001044 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001045 return rc;
1046
1047 /* Drop the RTNL lock while waiting, but prevent reentry or
1048 * removal of the device.
1049 */
1050 busy = true;
1051 dev_hold(dev);
1052 rtnl_unlock();
1053
1054 if (rc == 0) {
1055 /* Driver will handle this itself */
1056 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001057 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001058 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001059 /* Driver expects to be called at twice the frequency in rc */
1060 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001061
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001062 /* Count down seconds */
1063 do {
1064 /* Count down iterations per second */
1065 i = n;
1066 do {
1067 rtnl_lock();
1068 rc = dev->ethtool_ops->set_phys_id(dev,
1069 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1070 rtnl_unlock();
1071 if (rc)
1072 break;
1073 schedule_timeout_interruptible(interval);
1074 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001075 } while (!signal_pending(current) &&
1076 (id.data == 0 || --id.data != 0));
1077 }
1078
1079 rtnl_lock();
1080 dev_put(dev);
1081 busy = false;
1082
1083 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1084 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
1087static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1088{
1089 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001090 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001092 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001094 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001095 return -EOPNOTSUPP;
1096
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001097 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001098 if (n_stats < 0)
1099 return n_stats;
1100 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1103 return -EFAULT;
1104
Jeff Garzikff03d492007-08-15 16:01:08 -07001105 stats.n_stats = n_stats;
1106 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (!data)
1108 return -ENOMEM;
1109
1110 ops->get_ethtool_stats(dev, &stats, data);
1111
1112 ret = -EFAULT;
1113 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1114 goto out;
1115 useraddr += sizeof(stats);
1116 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1117 goto out;
1118 ret = 0;
1119
1120 out:
1121 kfree(data);
1122 return ret;
1123}
1124
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001125static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001126{
1127 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001128
Matthew Wilcox313674a2007-07-31 14:00:29 -07001129 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001130 return -EFAULT;
1131
Matthew Wilcox313674a2007-07-31 14:00:29 -07001132 if (epaddr.size < dev->addr_len)
1133 return -ETOOSMALL;
1134 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001135
Jon Wetzela6f9a702005-08-20 17:15:54 -07001136 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001137 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001138 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001139 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1140 return -EFAULT;
1141 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001142}
1143
Jeff Garzik13c99b22007-08-15 16:01:56 -07001144static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1145 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001146{
Roland Dreier8e557422010-02-11 12:14:23 -08001147 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001148
Jeff Garzik13c99b22007-08-15 16:01:56 -07001149 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001150 return -EOPNOTSUPP;
1151
Jeff Garzik13c99b22007-08-15 16:01:56 -07001152 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001153
1154 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1155 return -EFAULT;
1156 return 0;
1157}
1158
Jeff Garzik13c99b22007-08-15 16:01:56 -07001159static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1160 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001161{
1162 struct ethtool_value edata;
1163
Jeff Garzik13c99b22007-08-15 16:01:56 -07001164 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001165 return -EOPNOTSUPP;
1166
1167 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1168 return -EFAULT;
1169
Jeff Garzik13c99b22007-08-15 16:01:56 -07001170 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001171 return 0;
1172}
1173
Jeff Garzik13c99b22007-08-15 16:01:56 -07001174static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1175 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001176{
1177 struct ethtool_value edata;
1178
Jeff Garzik13c99b22007-08-15 16:01:56 -07001179 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001180 return -EOPNOTSUPP;
1181
1182 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1183 return -EFAULT;
1184
Jeff Garzik13c99b22007-08-15 16:01:56 -07001185 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001186}
1187
chavey97f8aef2010-04-07 21:54:42 -07001188static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1189 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001190{
1191 struct ethtool_flash efl;
1192
1193 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1194 return -EFAULT;
1195
1196 if (!dev->ethtool_ops->flash_device)
1197 return -EOPNOTSUPP;
1198
1199 return dev->ethtool_ops->flash_device(dev, &efl);
1200}
1201
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001202static int ethtool_set_dump(struct net_device *dev,
1203 void __user *useraddr)
1204{
1205 struct ethtool_dump dump;
1206
1207 if (!dev->ethtool_ops->set_dump)
1208 return -EOPNOTSUPP;
1209
1210 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1211 return -EFAULT;
1212
1213 return dev->ethtool_ops->set_dump(dev, &dump);
1214}
1215
1216static int ethtool_get_dump_flag(struct net_device *dev,
1217 void __user *useraddr)
1218{
1219 int ret;
1220 struct ethtool_dump dump;
1221 const struct ethtool_ops *ops = dev->ethtool_ops;
1222
1223 if (!dev->ethtool_ops->get_dump_flag)
1224 return -EOPNOTSUPP;
1225
1226 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1227 return -EFAULT;
1228
1229 ret = ops->get_dump_flag(dev, &dump);
1230 if (ret)
1231 return ret;
1232
1233 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1234 return -EFAULT;
1235 return 0;
1236}
1237
1238static int ethtool_get_dump_data(struct net_device *dev,
1239 void __user *useraddr)
1240{
1241 int ret;
1242 __u32 len;
1243 struct ethtool_dump dump, tmp;
1244 const struct ethtool_ops *ops = dev->ethtool_ops;
1245 void *data = NULL;
1246
1247 if (!dev->ethtool_ops->get_dump_data ||
1248 !dev->ethtool_ops->get_dump_flag)
1249 return -EOPNOTSUPP;
1250
1251 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1252 return -EFAULT;
1253
1254 memset(&tmp, 0, sizeof(tmp));
1255 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1256 ret = ops->get_dump_flag(dev, &tmp);
1257 if (ret)
1258 return ret;
1259
1260 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1261 if (!len)
1262 return -EFAULT;
1263
1264 data = vzalloc(tmp.len);
1265 if (!data)
1266 return -ENOMEM;
1267 ret = ops->get_dump_data(dev, &dump, data);
1268 if (ret)
1269 goto out;
1270
1271 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1272 ret = -EFAULT;
1273 goto out;
1274 }
1275 useraddr += offsetof(struct ethtool_dump, data);
1276 if (copy_to_user(useraddr, data, len))
1277 ret = -EFAULT;
1278out:
1279 vfree(data);
1280 return ret;
1281}
1282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283/* The main entry point in this file. Called from net/core/dev.c */
1284
Eric W. Biederman881d9662007-09-17 11:56:21 -07001285int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001287 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 void __user *useraddr = ifr->ifr_data;
1289 u32 ethcmd;
1290 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001291 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 if (!dev || !netif_device_present(dev))
1294 return -ENODEV;
1295
chavey97f8aef2010-04-07 21:54:42 -07001296 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 return -EFAULT;
1298
Ben Hutchings01414802010-08-17 02:31:15 -07001299 if (!dev->ethtool_ops) {
1300 /* ETHTOOL_GDRVINFO does not require any driver support.
1301 * It is also unprivileged and does not change anything,
1302 * so we can take a shortcut to it. */
1303 if (ethcmd == ETHTOOL_GDRVINFO)
1304 return ethtool_get_drvinfo(dev, useraddr);
1305 else
1306 return -EOPNOTSUPP;
1307 }
1308
Stephen Hemminger75f31232006-09-28 15:13:37 -07001309 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001310 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001311 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001312 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001313 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001314 case ETHTOOL_GCOALESCE:
1315 case ETHTOOL_GRINGPARAM:
1316 case ETHTOOL_GPAUSEPARAM:
1317 case ETHTOOL_GRXCSUM:
1318 case ETHTOOL_GTXCSUM:
1319 case ETHTOOL_GSG:
1320 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001321 case ETHTOOL_GTSO:
1322 case ETHTOOL_GPERMADDR:
1323 case ETHTOOL_GUFO:
1324 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001325 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001326 case ETHTOOL_GFLAGS:
1327 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001328 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001329 case ETHTOOL_GRXRINGS:
1330 case ETHTOOL_GRXCLSRLCNT:
1331 case ETHTOOL_GRXCLSRULE:
1332 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001333 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001334 break;
1335 default:
1336 if (!capable(CAP_NET_ADMIN))
1337 return -EPERM;
1338 }
1339
chavey97f8aef2010-04-07 21:54:42 -07001340 if (dev->ethtool_ops->begin) {
1341 rc = dev->ethtool_ops->begin(dev);
1342 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001344 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001345 old_features = dev->features;
1346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 switch (ethcmd) {
1348 case ETHTOOL_GSET:
1349 rc = ethtool_get_settings(dev, useraddr);
1350 break;
1351 case ETHTOOL_SSET:
1352 rc = ethtool_set_settings(dev, useraddr);
1353 break;
1354 case ETHTOOL_GDRVINFO:
1355 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 break;
1357 case ETHTOOL_GREGS:
1358 rc = ethtool_get_regs(dev, useraddr);
1359 break;
1360 case ETHTOOL_GWOL:
1361 rc = ethtool_get_wol(dev, useraddr);
1362 break;
1363 case ETHTOOL_SWOL:
1364 rc = ethtool_set_wol(dev, useraddr);
1365 break;
1366 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001367 rc = ethtool_get_value(dev, useraddr, ethcmd,
1368 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 break;
1370 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001371 rc = ethtool_set_value_void(dev, useraddr,
1372 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 break;
1374 case ETHTOOL_NWAY_RST:
1375 rc = ethtool_nway_reset(dev);
1376 break;
1377 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001378 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 break;
1380 case ETHTOOL_GEEPROM:
1381 rc = ethtool_get_eeprom(dev, useraddr);
1382 break;
1383 case ETHTOOL_SEEPROM:
1384 rc = ethtool_set_eeprom(dev, useraddr);
1385 break;
1386 case ETHTOOL_GCOALESCE:
1387 rc = ethtool_get_coalesce(dev, useraddr);
1388 break;
1389 case ETHTOOL_SCOALESCE:
1390 rc = ethtool_set_coalesce(dev, useraddr);
1391 break;
1392 case ETHTOOL_GRINGPARAM:
1393 rc = ethtool_get_ringparam(dev, useraddr);
1394 break;
1395 case ETHTOOL_SRINGPARAM:
1396 rc = ethtool_set_ringparam(dev, useraddr);
1397 break;
1398 case ETHTOOL_GPAUSEPARAM:
1399 rc = ethtool_get_pauseparam(dev, useraddr);
1400 break;
1401 case ETHTOOL_SPAUSEPARAM:
1402 rc = ethtool_set_pauseparam(dev, useraddr);
1403 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 case ETHTOOL_TEST:
1405 rc = ethtool_self_test(dev, useraddr);
1406 break;
1407 case ETHTOOL_GSTRINGS:
1408 rc = ethtool_get_strings(dev, useraddr);
1409 break;
1410 case ETHTOOL_PHYS_ID:
1411 rc = ethtool_phys_id(dev, useraddr);
1412 break;
1413 case ETHTOOL_GSTATS:
1414 rc = ethtool_get_stats(dev, useraddr);
1415 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001416 case ETHTOOL_GPERMADDR:
1417 rc = ethtool_get_perm_addr(dev, useraddr);
1418 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001419 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001420 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c2011-11-15 15:29:55 +00001421 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001422 break;
1423 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001424 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001425 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001426 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001427 rc = ethtool_get_value(dev, useraddr, ethcmd,
1428 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001429 break;
1430 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001431 rc = ethtool_set_value(dev, useraddr,
1432 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001433 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001434 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001435 case ETHTOOL_GRXRINGS:
1436 case ETHTOOL_GRXCLSRLCNT:
1437 case ETHTOOL_GRXCLSRULE:
1438 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001439 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001440 break;
1441 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001442 case ETHTOOL_SRXCLSRLDEL:
1443 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001444 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001445 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001446 case ETHTOOL_FLASHDEV:
1447 rc = ethtool_flash_device(dev, useraddr);
1448 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001449 case ETHTOOL_RESET:
1450 rc = ethtool_reset(dev, useraddr);
1451 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001452 case ETHTOOL_SRXNTUPLE:
1453 rc = ethtool_set_rx_ntuple(dev, useraddr);
1454 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001455 case ETHTOOL_GSSET_INFO:
1456 rc = ethtool_get_sset_info(dev, useraddr);
1457 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001458 case ETHTOOL_GRXFHINDIR:
1459 rc = ethtool_get_rxfh_indir(dev, useraddr);
1460 break;
1461 case ETHTOOL_SRXFHINDIR:
1462 rc = ethtool_set_rxfh_indir(dev, useraddr);
1463 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001464 case ETHTOOL_GFEATURES:
1465 rc = ethtool_get_features(dev, useraddr);
1466 break;
1467 case ETHTOOL_SFEATURES:
1468 rc = ethtool_set_features(dev, useraddr);
1469 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001470 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001471 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001472 case ETHTOOL_GSG:
1473 case ETHTOOL_GTSO:
1474 case ETHTOOL_GUFO:
1475 case ETHTOOL_GGSO:
1476 case ETHTOOL_GGRO:
1477 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1478 break;
1479 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001480 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001481 case ETHTOOL_SSG:
1482 case ETHTOOL_STSO:
1483 case ETHTOOL_SUFO:
1484 case ETHTOOL_SGSO:
1485 case ETHTOOL_SGRO:
1486 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1487 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001488 case ETHTOOL_GCHANNELS:
1489 rc = ethtool_get_channels(dev, useraddr);
1490 break;
1491 case ETHTOOL_SCHANNELS:
1492 rc = ethtool_set_channels(dev, useraddr);
1493 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001494 case ETHTOOL_SET_DUMP:
1495 rc = ethtool_set_dump(dev, useraddr);
1496 break;
1497 case ETHTOOL_GET_DUMP_FLAG:
1498 rc = ethtool_get_dump_flag(dev, useraddr);
1499 break;
1500 case ETHTOOL_GET_DUMP_DATA:
1501 rc = ethtool_get_dump_data(dev, useraddr);
1502 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001504 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001506
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001507 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001509
1510 if (old_features != dev->features)
1511 netdev_features_change(dev);
1512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514}