blob: a723b132169122a6ffcadbcfff9268ef036b90ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
4 *
5 * This file is where we call all the ethtool_ops commands to get
Matthew Wilcox61a44b92007-07-31 14:00:02 -07006 * the information ethtool needs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Matthew Wilcox61a44b92007-07-31 14:00:02 -07008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
14#include <linux/module.h>
15#include <linux/types.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080016#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
Richard Cochranc8f3a8c2012-04-03 22:59:17 +000020#include <linux/net_tstamp.h>
21#include <linux/phy.h>
Jeff Garzikd17792e2010-03-04 08:21:53 +000022#include <linux/bitops.h>
chavey97f8aef2010-04-07 21:54:42 -070023#include <linux/uaccess.h>
David S. Miller73da16c2010-09-21 16:12:11 -070024#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Ben Hutchings68f512f2011-04-02 00:35:15 +010026#include <linux/rtnetlink.h>
27#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * Some useful ethtool_ops methods that're device independent.
31 * If we find that all drivers want to do the same thing here,
32 * we can turn these into dev_() function calls.
33 */
34
35u32 ethtool_op_get_link(struct net_device *dev)
36{
37 return netif_carrier_ok(dev) ? 1 : 0;
38}
chavey97f8aef2010-04-07 21:54:42 -070039EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/* Handlers for each ethtool command */
42
Michał Mirosław475414f2011-11-15 15:29:55 +000043#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
Michał Mirosław5455c692011-02-15 16:59:17 +000044
Michał Mirosław9d921542011-11-15 15:29:55 +000045static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
46 [NETIF_F_SG_BIT] = "tx-scatter-gather",
47 [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
Michał Mirosław9d921542011-11-15 15:29:55 +000048 [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
49 [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
50 [NETIF_F_HIGHDMA_BIT] = "highdma",
51 [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
52 [NETIF_F_HW_VLAN_TX_BIT] = "tx-vlan-hw-insert",
53
54 [NETIF_F_HW_VLAN_RX_BIT] = "rx-vlan-hw-parse",
55 [NETIF_F_HW_VLAN_FILTER_BIT] = "rx-vlan-filter",
56 [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
57 [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
58 [NETIF_F_LLTX_BIT] = "tx-lockless",
59 [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
60 [NETIF_F_GRO_BIT] = "rx-gro",
61 [NETIF_F_LRO_BIT] = "rx-lro",
62
63 [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
64 [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
65 [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
66 [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
67 [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
68 [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
69
70 [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
71 [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
72 [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
73 [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
74 [NETIF_F_RXHASH_BIT] = "rx-hashing",
75 [NETIF_F_RXCSUM_BIT] = "rx-checksum",
76 [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
77 [NETIF_F_LOOPBACK_BIT] = "loopback",
Ben Greear36eabda32012-02-11 15:39:14 +000078 [NETIF_F_RXFCS_BIT] = "rx-fcs",
Ben Greear5e0c03c2012-02-11 15:39:45 +000079 [NETIF_F_RXALL_BIT] = "rx-all",
Michał Mirosław9d921542011-11-15 15:29:55 +000080};
81
Michał Mirosław5455c692011-02-15 16:59:17 +000082static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
83{
84 struct ethtool_gfeatures cmd = {
85 .cmd = ETHTOOL_GFEATURES,
86 .size = ETHTOOL_DEV_FEATURE_WORDS,
87 };
Michał Mirosław475414f2011-11-15 15:29:55 +000088 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +000089 u32 __user *sizeaddr;
90 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +000091 int i;
92
93 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +000094 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +000095
96 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +000097 features[i].available = (u32)(dev->hw_features >> (32 * i));
98 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
99 features[i].active = (u32)(dev->features >> (32 * i));
100 features[i].never_changed =
101 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +0000102 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000103
104 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
105 if (get_user(copy_size, sizeaddr))
106 return -EFAULT;
107
108 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
109 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
110
111 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
112 return -EFAULT;
113 useraddr += sizeof(cmd);
114 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
115 return -EFAULT;
116
117 return 0;
118}
119
120static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
121{
122 struct ethtool_sfeatures cmd;
123 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000124 netdev_features_t wanted = 0, valid = 0;
125 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000126
127 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
128 return -EFAULT;
129 useraddr += sizeof(cmd);
130
131 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
132 return -EINVAL;
133
134 if (copy_from_user(features, useraddr, sizeof(features)))
135 return -EFAULT;
136
Michał Mirosław475414f2011-11-15 15:29:55 +0000137 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000138 valid |= (netdev_features_t)features[i].valid << (32 * i);
139 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000140 }
141
142 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000143 return -EINVAL;
144
Michał Mirosław475414f2011-11-15 15:29:55 +0000145 if (valid & ~dev->hw_features) {
146 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000147 ret |= ETHTOOL_F_UNSUPPORTED;
148 }
149
Michał Mirosław475414f2011-11-15 15:29:55 +0000150 dev->wanted_features &= ~valid;
151 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700152 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000153
Michał Mirosław475414f2011-11-15 15:29:55 +0000154 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000155 ret |= ETHTOOL_F_WISH;
156
157 return ret;
158}
159
Michał Mirosław340ae162011-02-15 16:59:16 +0000160static int __ethtool_get_sset_count(struct net_device *dev, int sset)
161{
162 const struct ethtool_ops *ops = dev->ethtool_ops;
163
Michał Mirosław5455c692011-02-15 16:59:17 +0000164 if (sset == ETH_SS_FEATURES)
165 return ARRAY_SIZE(netdev_features_strings);
166
Michał Mirosław340ae162011-02-15 16:59:16 +0000167 if (ops && ops->get_sset_count && ops->get_strings)
168 return ops->get_sset_count(dev, sset);
169 else
170 return -EOPNOTSUPP;
171}
172
173static void __ethtool_get_strings(struct net_device *dev,
174 u32 stringset, u8 *data)
175{
176 const struct ethtool_ops *ops = dev->ethtool_ops;
177
Michał Mirosław5455c692011-02-15 16:59:17 +0000178 if (stringset == ETH_SS_FEATURES)
179 memcpy(data, netdev_features_strings,
180 sizeof(netdev_features_strings));
181 else
182 /* ops->get_strings is valid because checked earlier */
183 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000184}
185
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000186static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000187{
188 /* feature masks of legacy discrete ethtool ops */
189
190 switch (eth_cmd) {
191 case ETHTOOL_GTXCSUM:
192 case ETHTOOL_STXCSUM:
193 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000194 case ETHTOOL_GRXCSUM:
195 case ETHTOOL_SRXCSUM:
196 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000197 case ETHTOOL_GSG:
198 case ETHTOOL_SSG:
199 return NETIF_F_SG;
200 case ETHTOOL_GTSO:
201 case ETHTOOL_STSO:
202 return NETIF_F_ALL_TSO;
203 case ETHTOOL_GUFO:
204 case ETHTOOL_SUFO:
205 return NETIF_F_UFO;
206 case ETHTOOL_GGSO:
207 case ETHTOOL_SGSO:
208 return NETIF_F_GSO;
209 case ETHTOOL_GGRO:
210 case ETHTOOL_SGRO:
211 return NETIF_F_GRO;
212 default:
213 BUG();
214 }
215}
216
Michał Mirosław0a417702011-02-15 16:59:17 +0000217static int ethtool_get_one_feature(struct net_device *dev,
218 char __user *useraddr, u32 ethcmd)
219{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000220 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000221 struct ethtool_value edata = {
222 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000223 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000224 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000225
Michał Mirosław0a417702011-02-15 16:59:17 +0000226 if (copy_to_user(useraddr, &edata, sizeof(edata)))
227 return -EFAULT;
228 return 0;
229}
230
Michał Mirosław0a417702011-02-15 16:59:17 +0000231static int ethtool_set_one_feature(struct net_device *dev,
232 void __user *useraddr, u32 ethcmd)
233{
234 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000235 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000236
237 if (copy_from_user(&edata, useraddr, sizeof(edata)))
238 return -EFAULT;
239
Michał Mirosław86794882011-02-15 16:59:17 +0000240 mask = ethtool_get_feature_mask(ethcmd);
241 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000242 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000243 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000244
245 if (edata.data)
246 dev->wanted_features |= mask;
247 else
248 dev->wanted_features &= ~mask;
249
250 __netdev_update_features(dev);
251
252 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000253}
254
Michał Mirosław02b3a552011-11-15 15:29:55 +0000255#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
256 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
257#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
258 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000259
260static u32 __ethtool_get_flags(struct net_device *dev)
261{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000262 u32 flags = 0;
263
264 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
265 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
266 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
267 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
268 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
269
270 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000271}
272
273static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000274{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000275 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000276
Michał Mirosław02b3a552011-11-15 15:29:55 +0000277 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000278 return -EINVAL;
279
Michał Mirosław02b3a552011-11-15 15:29:55 +0000280 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
281 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
282 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
283 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
284 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
285
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000286 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000287 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000288 if (changed & ~dev->hw_features)
289 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
290
291 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000292 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000293
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700294 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000295
296 return 0;
297}
298
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000299int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000301 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000303 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return -EOPNOTSUPP;
305
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000306 memset(cmd, 0, sizeof(struct ethtool_cmd));
307 cmd->cmd = ETHTOOL_GSET;
308 return dev->ethtool_ops->get_settings(dev, cmd);
309}
310EXPORT_SYMBOL(__ethtool_get_settings);
311
312static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
313{
314 int err;
315 struct ethtool_cmd cmd;
316
317 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (err < 0)
319 return err;
320
321 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
322 return -EFAULT;
323 return 0;
324}
325
326static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
327{
328 struct ethtool_cmd cmd;
329
330 if (!dev->ethtool_ops->set_settings)
331 return -EOPNOTSUPP;
332
333 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
334 return -EFAULT;
335
336 return dev->ethtool_ops->set_settings(dev, &cmd);
337}
338
chavey97f8aef2010-04-07 21:54:42 -0700339static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
340 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
342 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700343 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 memset(&info, 0, sizeof(info));
346 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700347 if (ops && ops->get_drvinfo) {
348 ops->get_drvinfo(dev, &info);
349 } else if (dev->dev.parent && dev->dev.parent->driver) {
350 strlcpy(info.bus_info, dev_name(dev->dev.parent),
351 sizeof(info.bus_info));
352 strlcpy(info.driver, dev->dev.parent->driver->name,
353 sizeof(info.driver));
354 } else {
355 return -EOPNOTSUPP;
356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Jeff Garzik723b2f52010-03-03 22:51:50 +0000358 /*
359 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000360 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000361 */
Ben Hutchings01414802010-08-17 02:31:15 -0700362 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700363 int rc;
364
365 rc = ops->get_sset_count(dev, ETH_SS_TEST);
366 if (rc >= 0)
367 info.testinfo_len = rc;
368 rc = ops->get_sset_count(dev, ETH_SS_STATS);
369 if (rc >= 0)
370 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700371 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
372 if (rc >= 0)
373 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700374 }
Ben Hutchings01414802010-08-17 02:31:15 -0700375 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700377 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 info.eedump_len = ops->get_eeprom_len(dev);
379
380 if (copy_to_user(useraddr, &info, sizeof(info)))
381 return -EFAULT;
382 return 0;
383}
384
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800385static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700386 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000387{
388 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000389 u64 sset_mask;
390 int i, idx = 0, n_bits = 0, ret, rc;
391 u32 *info_buf = NULL;
392
Jeff Garzik723b2f52010-03-03 22:51:50 +0000393 if (copy_from_user(&info, useraddr, sizeof(info)))
394 return -EFAULT;
395
396 /* store copy of mask, because we zero struct later on */
397 sset_mask = info.sset_mask;
398 if (!sset_mask)
399 return 0;
400
401 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000402 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000403
404 memset(&info, 0, sizeof(info));
405 info.cmd = ETHTOOL_GSSET_INFO;
406
407 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
408 if (!info_buf)
409 return -ENOMEM;
410
411 /*
412 * fill return buffer based on input bitmask and successful
413 * get_sset_count return
414 */
415 for (i = 0; i < 64; i++) {
416 if (!(sset_mask & (1ULL << i)))
417 continue;
418
Michał Mirosław340ae162011-02-15 16:59:16 +0000419 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000420 if (rc >= 0) {
421 info.sset_mask |= (1ULL << i);
422 info_buf[idx++] = rc;
423 }
424 }
425
426 ret = -EFAULT;
427 if (copy_to_user(useraddr, &info, sizeof(info)))
428 goto out;
429
430 useraddr += offsetof(struct ethtool_sset_info, data);
431 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
432 goto out;
433
434 ret = 0;
435
436out:
437 kfree(info_buf);
438 return ret;
439}
440
chavey97f8aef2010-04-07 21:54:42 -0700441static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000442 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700443{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000444 struct ethtool_rxnfc info;
445 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000446 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700447
Santwona Behera59089d82009-02-20 00:58:13 -0800448 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700449 return -EOPNOTSUPP;
450
Ben Hutchingsbf988432010-06-28 08:45:58 +0000451 /* struct ethtool_rxnfc was originally defined for
452 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
453 * members. User-space might still be using that
454 * definition. */
455 if (cmd == ETHTOOL_SRXFH)
456 info_size = (offsetof(struct ethtool_rxnfc, data) +
457 sizeof(info.data));
458
459 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700460 return -EFAULT;
461
Ben Hutchings55664f32012-01-03 12:04:51 +0000462 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
463 if (rc)
464 return rc;
465
466 if (cmd == ETHTOOL_SRXCLSRLINS &&
467 copy_to_user(useraddr, &info, info_size))
468 return -EFAULT;
469
470 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700471}
472
chavey97f8aef2010-04-07 21:54:42 -0700473static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000474 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700475{
476 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000477 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800478 const struct ethtool_ops *ops = dev->ethtool_ops;
479 int ret;
480 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700481
Santwona Behera59089d82009-02-20 00:58:13 -0800482 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700483 return -EOPNOTSUPP;
484
Ben Hutchingsbf988432010-06-28 08:45:58 +0000485 /* struct ethtool_rxnfc was originally defined for
486 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
487 * members. User-space might still be using that
488 * definition. */
489 if (cmd == ETHTOOL_GRXFH)
490 info_size = (offsetof(struct ethtool_rxnfc, data) +
491 sizeof(info.data));
492
493 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700494 return -EFAULT;
495
Santwona Behera59089d82009-02-20 00:58:13 -0800496 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
497 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000498 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000499 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000500 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800501 if (!rule_buf)
502 return -ENOMEM;
503 }
504 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700505
Santwona Behera59089d82009-02-20 00:58:13 -0800506 ret = ops->get_rxnfc(dev, &info, rule_buf);
507 if (ret < 0)
508 goto err_out;
509
510 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000511 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800512 goto err_out;
513
514 if (rule_buf) {
515 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
516 if (copy_to_user(useraddr, rule_buf,
517 info.rule_cnt * sizeof(u32)))
518 goto err_out;
519 }
520 ret = 0;
521
522err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700523 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800524
525 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700526}
527
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000528static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
529 void __user *useraddr)
530{
Ben Hutchings7850f632011-12-15 13:55:01 +0000531 u32 user_size, dev_size;
532 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000533 int ret;
534
Ben Hutchings7850f632011-12-15 13:55:01 +0000535 if (!dev->ethtool_ops->get_rxfh_indir_size ||
536 !dev->ethtool_ops->get_rxfh_indir)
537 return -EOPNOTSUPP;
538 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
539 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000540 return -EOPNOTSUPP;
541
Ben Hutchings7850f632011-12-15 13:55:01 +0000542 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000543 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000544 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000545 return -EFAULT;
546
Ben Hutchings7850f632011-12-15 13:55:01 +0000547 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
548 &dev_size, sizeof(dev_size)))
549 return -EFAULT;
550
551 /* If the user buffer size is 0, this is just a query for the
552 * device table size. Otherwise, if it's smaller than the
553 * device table size it's an error.
554 */
555 if (user_size < dev_size)
556 return user_size == 0 ? 0 : -EINVAL;
557
558 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000559 if (!indir)
560 return -ENOMEM;
561
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000562 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
563 if (ret)
564 goto out;
565
Ben Hutchings7850f632011-12-15 13:55:01 +0000566 if (copy_to_user(useraddr +
567 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
568 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000569 ret = -EFAULT;
570
571out:
572 kfree(indir);
573 return ret;
574}
575
576static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
577 void __user *useraddr)
578{
Ben Hutchings7850f632011-12-15 13:55:01 +0000579 struct ethtool_rxnfc rx_rings;
580 u32 user_size, dev_size, i;
581 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000582 int ret;
583
Ben Hutchings7850f632011-12-15 13:55:01 +0000584 if (!dev->ethtool_ops->get_rxfh_indir_size ||
585 !dev->ethtool_ops->set_rxfh_indir ||
586 !dev->ethtool_ops->get_rxnfc)
587 return -EOPNOTSUPP;
588 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
589 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000590 return -EOPNOTSUPP;
591
Ben Hutchings7850f632011-12-15 13:55:01 +0000592 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000593 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000594 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000595 return -EFAULT;
596
Ben Hutchings278bc422011-12-15 13:56:49 +0000597 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000598 return -EINVAL;
599
600 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000601 if (!indir)
602 return -ENOMEM;
603
Ben Hutchings7850f632011-12-15 13:55:01 +0000604 rx_rings.cmd = ETHTOOL_GRXRINGS;
605 ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
606 if (ret)
607 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000608
609 if (user_size == 0) {
610 for (i = 0; i < dev_size; i++)
611 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
612 } else {
613 if (copy_from_user(indir,
614 useraddr +
615 offsetof(struct ethtool_rxfh_indir,
616 ring_index[0]),
617 dev_size * sizeof(indir[0]))) {
618 ret = -EFAULT;
Ben Hutchings7850f632011-12-15 13:55:01 +0000619 goto out;
620 }
Ben Hutchings278bc422011-12-15 13:56:49 +0000621
622 /* Validate ring indices */
623 for (i = 0; i < dev_size; i++) {
624 if (indir[i] >= rx_rings.data) {
625 ret = -EINVAL;
626 goto out;
627 }
628 }
Ben Hutchings7850f632011-12-15 13:55:01 +0000629 }
630
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000631 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
632
633out:
634 kfree(indir);
635 return ret;
636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
639{
640 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700641 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 void *regbuf;
643 int reglen, ret;
644
645 if (!ops->get_regs || !ops->get_regs_len)
646 return -EOPNOTSUPP;
647
648 if (copy_from_user(&regs, useraddr, sizeof(regs)))
649 return -EFAULT;
650
651 reglen = ops->get_regs_len(dev);
652 if (regs.len > reglen)
653 regs.len = reglen;
654
Eugene Teob7c7d012011-01-24 21:05:17 -0800655 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700656 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return -ENOMEM;
658
659 ops->get_regs(dev, &regs, regbuf);
660
661 ret = -EFAULT;
662 if (copy_to_user(useraddr, &regs, sizeof(regs)))
663 goto out;
664 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700665 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 goto out;
667 ret = 0;
668
669 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000670 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 return ret;
672}
673
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000674static int ethtool_reset(struct net_device *dev, char __user *useraddr)
675{
676 struct ethtool_value reset;
677 int ret;
678
679 if (!dev->ethtool_ops->reset)
680 return -EOPNOTSUPP;
681
682 if (copy_from_user(&reset, useraddr, sizeof(reset)))
683 return -EFAULT;
684
685 ret = dev->ethtool_ops->reset(dev, &reset.data);
686 if (ret)
687 return ret;
688
689 if (copy_to_user(useraddr, &reset, sizeof(reset)))
690 return -EFAULT;
691 return 0;
692}
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
695{
Roland Dreier8e557422010-02-11 12:14:23 -0800696 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 if (!dev->ethtool_ops->get_wol)
699 return -EOPNOTSUPP;
700
701 dev->ethtool_ops->get_wol(dev, &wol);
702
703 if (copy_to_user(useraddr, &wol, sizeof(wol)))
704 return -EFAULT;
705 return 0;
706}
707
708static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
709{
710 struct ethtool_wolinfo wol;
711
712 if (!dev->ethtool_ops->set_wol)
713 return -EOPNOTSUPP;
714
715 if (copy_from_user(&wol, useraddr, sizeof(wol)))
716 return -EFAULT;
717
718 return dev->ethtool_ops->set_wol(dev, &wol);
719}
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721static int ethtool_nway_reset(struct net_device *dev)
722{
723 if (!dev->ethtool_ops->nway_reset)
724 return -EOPNOTSUPP;
725
726 return dev->ethtool_ops->nway_reset(dev);
727}
728
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000729static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
730{
731 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
732
733 if (!dev->ethtool_ops->get_link)
734 return -EOPNOTSUPP;
735
736 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
737
738 if (copy_to_user(useraddr, &edata, sizeof(edata)))
739 return -EFAULT;
740 return 0;
741}
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
744{
745 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700746 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700747 void __user *userbuf = useraddr + sizeof(eeprom);
748 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700750 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 if (!ops->get_eeprom || !ops->get_eeprom_len)
753 return -EOPNOTSUPP;
754
755 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
756 return -EFAULT;
757
758 /* Check for wrap and zero */
759 if (eeprom.offset + eeprom.len <= eeprom.offset)
760 return -EINVAL;
761
762 /* Check for exceeding total eeprom len */
763 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
764 return -EINVAL;
765
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700766 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (!data)
768 return -ENOMEM;
769
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700770 bytes_remaining = eeprom.len;
771 while (bytes_remaining > 0) {
772 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700774 ret = ops->get_eeprom(dev, &eeprom, data);
775 if (ret)
776 break;
777 if (copy_to_user(userbuf, data, eeprom.len)) {
778 ret = -EFAULT;
779 break;
780 }
781 userbuf += eeprom.len;
782 eeprom.offset += eeprom.len;
783 bytes_remaining -= eeprom.len;
784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700786 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
787 eeprom.offset -= eeprom.len;
788 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
789 ret = -EFAULT;
790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 kfree(data);
792 return ret;
793}
794
795static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
796{
797 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700798 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700799 void __user *userbuf = useraddr + sizeof(eeprom);
800 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700802 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 if (!ops->set_eeprom || !ops->get_eeprom_len)
805 return -EOPNOTSUPP;
806
807 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
808 return -EFAULT;
809
810 /* Check for wrap and zero */
811 if (eeprom.offset + eeprom.len <= eeprom.offset)
812 return -EINVAL;
813
814 /* Check for exceeding total eeprom len */
815 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
816 return -EINVAL;
817
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700818 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 if (!data)
820 return -ENOMEM;
821
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700822 bytes_remaining = eeprom.len;
823 while (bytes_remaining > 0) {
824 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700826 if (copy_from_user(data, userbuf, eeprom.len)) {
827 ret = -EFAULT;
828 break;
829 }
830 ret = ops->set_eeprom(dev, &eeprom, data);
831 if (ret)
832 break;
833 userbuf += eeprom.len;
834 eeprom.offset += eeprom.len;
835 bytes_remaining -= eeprom.len;
836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 kfree(data);
839 return ret;
840}
841
chavey97f8aef2010-04-07 21:54:42 -0700842static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
843 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Roland Dreier8e557422010-02-11 12:14:23 -0800845 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (!dev->ethtool_ops->get_coalesce)
848 return -EOPNOTSUPP;
849
850 dev->ethtool_ops->get_coalesce(dev, &coalesce);
851
852 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
853 return -EFAULT;
854 return 0;
855}
856
chavey97f8aef2010-04-07 21:54:42 -0700857static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
858 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 struct ethtool_coalesce coalesce;
861
David S. Millerfa04ae52005-06-06 15:07:19 -0700862 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return -EOPNOTSUPP;
864
865 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
866 return -EFAULT;
867
868 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
869}
870
871static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
872{
Roland Dreier8e557422010-02-11 12:14:23 -0800873 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (!dev->ethtool_ops->get_ringparam)
876 return -EOPNOTSUPP;
877
878 dev->ethtool_ops->get_ringparam(dev, &ringparam);
879
880 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
881 return -EFAULT;
882 return 0;
883}
884
885static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
886{
887 struct ethtool_ringparam ringparam;
888
889 if (!dev->ethtool_ops->set_ringparam)
890 return -EOPNOTSUPP;
891
892 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
893 return -EFAULT;
894
895 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
896}
897
amit salecha8b5933c32011-04-07 01:58:42 +0000898static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
899 void __user *useraddr)
900{
901 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
902
903 if (!dev->ethtool_ops->get_channels)
904 return -EOPNOTSUPP;
905
906 dev->ethtool_ops->get_channels(dev, &channels);
907
908 if (copy_to_user(useraddr, &channels, sizeof(channels)))
909 return -EFAULT;
910 return 0;
911}
912
913static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
914 void __user *useraddr)
915{
916 struct ethtool_channels channels;
917
918 if (!dev->ethtool_ops->set_channels)
919 return -EOPNOTSUPP;
920
921 if (copy_from_user(&channels, useraddr, sizeof(channels)))
922 return -EFAULT;
923
924 return dev->ethtool_ops->set_channels(dev, &channels);
925}
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
928{
929 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
930
931 if (!dev->ethtool_ops->get_pauseparam)
932 return -EOPNOTSUPP;
933
934 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
935
936 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
937 return -EFAULT;
938 return 0;
939}
940
941static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
942{
943 struct ethtool_pauseparam pauseparam;
944
Jeff Garzike1b90c42006-07-17 12:54:40 -0400945 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 return -EOPNOTSUPP;
947
948 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
949 return -EFAULT;
950
951 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
952}
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
955{
956 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700957 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700959 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000961 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700962 return -EOPNOTSUPP;
963
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000964 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700965 if (test_len < 0)
966 return test_len;
967 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 if (copy_from_user(&test, useraddr, sizeof(test)))
970 return -EFAULT;
971
Jeff Garzikff03d492007-08-15 16:01:08 -0700972 test.len = test_len;
973 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (!data)
975 return -ENOMEM;
976
977 ops->self_test(dev, &test, data);
978
979 ret = -EFAULT;
980 if (copy_to_user(useraddr, &test, sizeof(test)))
981 goto out;
982 useraddr += sizeof(test);
983 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
984 goto out;
985 ret = 0;
986
987 out:
988 kfree(data);
989 return ret;
990}
991
992static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
993{
994 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 u8 *data;
996 int ret;
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
999 return -EFAULT;
1000
Michał Mirosław340ae162011-02-15 16:59:16 +00001001 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001002 if (ret < 0)
1003 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001004
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001005 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1008 if (!data)
1009 return -ENOMEM;
1010
Michał Mirosław340ae162011-02-15 16:59:16 +00001011 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013 ret = -EFAULT;
1014 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1015 goto out;
1016 useraddr += sizeof(gstrings);
1017 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1018 goto out;
1019 ret = 0;
1020
Michał Mirosław340ae162011-02-15 16:59:16 +00001021out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 kfree(data);
1023 return ret;
1024}
1025
1026static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1027{
1028 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001029 static bool busy;
1030 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001032 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 return -EOPNOTSUPP;
1034
Ben Hutchings68f512f2011-04-02 00:35:15 +01001035 if (busy)
1036 return -EBUSY;
1037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (copy_from_user(&id, useraddr, sizeof(id)))
1039 return -EFAULT;
1040
Ben Hutchings68f512f2011-04-02 00:35:15 +01001041 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001042 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001043 return rc;
1044
1045 /* Drop the RTNL lock while waiting, but prevent reentry or
1046 * removal of the device.
1047 */
1048 busy = true;
1049 dev_hold(dev);
1050 rtnl_unlock();
1051
1052 if (rc == 0) {
1053 /* Driver will handle this itself */
1054 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001055 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001056 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001057 /* Driver expects to be called at twice the frequency in rc */
1058 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001059
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001060 /* Count down seconds */
1061 do {
1062 /* Count down iterations per second */
1063 i = n;
1064 do {
1065 rtnl_lock();
1066 rc = dev->ethtool_ops->set_phys_id(dev,
1067 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1068 rtnl_unlock();
1069 if (rc)
1070 break;
1071 schedule_timeout_interruptible(interval);
1072 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001073 } while (!signal_pending(current) &&
1074 (id.data == 0 || --id.data != 0));
1075 }
1076
1077 rtnl_lock();
1078 dev_put(dev);
1079 busy = false;
1080
1081 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1082 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
1085static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1086{
1087 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001088 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001090 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001092 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001093 return -EOPNOTSUPP;
1094
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001095 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001096 if (n_stats < 0)
1097 return n_stats;
1098 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1101 return -EFAULT;
1102
Jeff Garzikff03d492007-08-15 16:01:08 -07001103 stats.n_stats = n_stats;
1104 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 if (!data)
1106 return -ENOMEM;
1107
1108 ops->get_ethtool_stats(dev, &stats, data);
1109
1110 ret = -EFAULT;
1111 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1112 goto out;
1113 useraddr += sizeof(stats);
1114 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1115 goto out;
1116 ret = 0;
1117
1118 out:
1119 kfree(data);
1120 return ret;
1121}
1122
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001123static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001124{
1125 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001126
Matthew Wilcox313674a2007-07-31 14:00:29 -07001127 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001128 return -EFAULT;
1129
Matthew Wilcox313674a2007-07-31 14:00:29 -07001130 if (epaddr.size < dev->addr_len)
1131 return -ETOOSMALL;
1132 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001133
Jon Wetzela6f9a702005-08-20 17:15:54 -07001134 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001135 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001136 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001137 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1138 return -EFAULT;
1139 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001140}
1141
Jeff Garzik13c99b22007-08-15 16:01:56 -07001142static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1143 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001144{
Roland Dreier8e557422010-02-11 12:14:23 -08001145 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001146
Jeff Garzik13c99b22007-08-15 16:01:56 -07001147 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001148 return -EOPNOTSUPP;
1149
Jeff Garzik13c99b22007-08-15 16:01:56 -07001150 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001151
1152 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1153 return -EFAULT;
1154 return 0;
1155}
1156
Jeff Garzik13c99b22007-08-15 16:01:56 -07001157static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1158 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001159{
1160 struct ethtool_value edata;
1161
Jeff Garzik13c99b22007-08-15 16:01:56 -07001162 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001163 return -EOPNOTSUPP;
1164
1165 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1166 return -EFAULT;
1167
Jeff Garzik13c99b22007-08-15 16:01:56 -07001168 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001169 return 0;
1170}
1171
Jeff Garzik13c99b22007-08-15 16:01:56 -07001172static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1173 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001174{
1175 struct ethtool_value edata;
1176
Jeff Garzik13c99b22007-08-15 16:01:56 -07001177 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001178 return -EOPNOTSUPP;
1179
1180 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1181 return -EFAULT;
1182
Jeff Garzik13c99b22007-08-15 16:01:56 -07001183 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001184}
1185
chavey97f8aef2010-04-07 21:54:42 -07001186static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1187 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001188{
1189 struct ethtool_flash efl;
1190
1191 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1192 return -EFAULT;
1193
1194 if (!dev->ethtool_ops->flash_device)
1195 return -EOPNOTSUPP;
1196
Ben Hutchings786f5282012-02-01 09:32:25 +00001197 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1198
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001199 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
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001283static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
1284{
1285 int err = 0;
1286 struct ethtool_ts_info info;
1287 const struct ethtool_ops *ops = dev->ethtool_ops;
1288 struct phy_device *phydev = dev->phydev;
1289
1290 memset(&info, 0, sizeof(info));
1291 info.cmd = ETHTOOL_GET_TS_INFO;
1292
1293 if (phydev && phydev->drv && phydev->drv->ts_info) {
1294
1295 err = phydev->drv->ts_info(phydev, &info);
1296
1297 } else if (dev->ethtool_ops && dev->ethtool_ops->get_ts_info) {
1298
1299 err = ops->get_ts_info(dev, &info);
1300
1301 } else {
1302 info.so_timestamping =
1303 SOF_TIMESTAMPING_RX_SOFTWARE |
1304 SOF_TIMESTAMPING_SOFTWARE;
1305 info.phc_index = -1;
1306 }
1307
1308 if (err)
1309 return err;
1310
1311 if (copy_to_user(useraddr, &info, sizeof(info)))
1312 err = -EFAULT;
1313
1314 return err;
1315}
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317/* The main entry point in this file. Called from net/core/dev.c */
1318
Eric W. Biederman881d9662007-09-17 11:56:21 -07001319int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001321 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 void __user *useraddr = ifr->ifr_data;
1323 u32 ethcmd;
1324 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001325 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (!dev || !netif_device_present(dev))
1328 return -ENODEV;
1329
chavey97f8aef2010-04-07 21:54:42 -07001330 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 return -EFAULT;
1332
Ben Hutchings01414802010-08-17 02:31:15 -07001333 if (!dev->ethtool_ops) {
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001334 /* A few commands do not require any driver support,
1335 * are unprivileged, and do not change anything, so we
1336 * can take a shortcut to them. */
Ben Hutchings01414802010-08-17 02:31:15 -07001337 if (ethcmd == ETHTOOL_GDRVINFO)
1338 return ethtool_get_drvinfo(dev, useraddr);
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001339 else if (ethcmd == ETHTOOL_GET_TS_INFO)
1340 return ethtool_get_ts_info(dev, useraddr);
Ben Hutchings01414802010-08-17 02:31:15 -07001341 else
1342 return -EOPNOTSUPP;
1343 }
1344
Stephen Hemminger75f31232006-09-28 15:13:37 -07001345 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001346 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001347 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001348 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001349 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001350 case ETHTOOL_GCOALESCE:
1351 case ETHTOOL_GRINGPARAM:
1352 case ETHTOOL_GPAUSEPARAM:
1353 case ETHTOOL_GRXCSUM:
1354 case ETHTOOL_GTXCSUM:
1355 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001356 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001357 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001358 case ETHTOOL_GTSO:
1359 case ETHTOOL_GPERMADDR:
1360 case ETHTOOL_GUFO:
1361 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001362 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001363 case ETHTOOL_GFLAGS:
1364 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001365 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001366 case ETHTOOL_GRXRINGS:
1367 case ETHTOOL_GRXCLSRLCNT:
1368 case ETHTOOL_GRXCLSRULE:
1369 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001370 case ETHTOOL_GFEATURES:
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001371 case ETHTOOL_GET_TS_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001372 break;
1373 default:
1374 if (!capable(CAP_NET_ADMIN))
1375 return -EPERM;
1376 }
1377
chavey97f8aef2010-04-07 21:54:42 -07001378 if (dev->ethtool_ops->begin) {
1379 rc = dev->ethtool_ops->begin(dev);
1380 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001382 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001383 old_features = dev->features;
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 switch (ethcmd) {
1386 case ETHTOOL_GSET:
1387 rc = ethtool_get_settings(dev, useraddr);
1388 break;
1389 case ETHTOOL_SSET:
1390 rc = ethtool_set_settings(dev, useraddr);
1391 break;
1392 case ETHTOOL_GDRVINFO:
1393 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 break;
1395 case ETHTOOL_GREGS:
1396 rc = ethtool_get_regs(dev, useraddr);
1397 break;
1398 case ETHTOOL_GWOL:
1399 rc = ethtool_get_wol(dev, useraddr);
1400 break;
1401 case ETHTOOL_SWOL:
1402 rc = ethtool_set_wol(dev, useraddr);
1403 break;
1404 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001405 rc = ethtool_get_value(dev, useraddr, ethcmd,
1406 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 break;
1408 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001409 rc = ethtool_set_value_void(dev, useraddr,
1410 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 break;
1412 case ETHTOOL_NWAY_RST:
1413 rc = ethtool_nway_reset(dev);
1414 break;
1415 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001416 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 break;
1418 case ETHTOOL_GEEPROM:
1419 rc = ethtool_get_eeprom(dev, useraddr);
1420 break;
1421 case ETHTOOL_SEEPROM:
1422 rc = ethtool_set_eeprom(dev, useraddr);
1423 break;
1424 case ETHTOOL_GCOALESCE:
1425 rc = ethtool_get_coalesce(dev, useraddr);
1426 break;
1427 case ETHTOOL_SCOALESCE:
1428 rc = ethtool_set_coalesce(dev, useraddr);
1429 break;
1430 case ETHTOOL_GRINGPARAM:
1431 rc = ethtool_get_ringparam(dev, useraddr);
1432 break;
1433 case ETHTOOL_SRINGPARAM:
1434 rc = ethtool_set_ringparam(dev, useraddr);
1435 break;
1436 case ETHTOOL_GPAUSEPARAM:
1437 rc = ethtool_get_pauseparam(dev, useraddr);
1438 break;
1439 case ETHTOOL_SPAUSEPARAM:
1440 rc = ethtool_set_pauseparam(dev, useraddr);
1441 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 case ETHTOOL_TEST:
1443 rc = ethtool_self_test(dev, useraddr);
1444 break;
1445 case ETHTOOL_GSTRINGS:
1446 rc = ethtool_get_strings(dev, useraddr);
1447 break;
1448 case ETHTOOL_PHYS_ID:
1449 rc = ethtool_phys_id(dev, useraddr);
1450 break;
1451 case ETHTOOL_GSTATS:
1452 rc = ethtool_get_stats(dev, useraddr);
1453 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001454 case ETHTOOL_GPERMADDR:
1455 rc = ethtool_get_perm_addr(dev, useraddr);
1456 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001457 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001458 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001459 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001460 break;
1461 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001462 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001463 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001464 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001465 rc = ethtool_get_value(dev, useraddr, ethcmd,
1466 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001467 break;
1468 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001469 rc = ethtool_set_value(dev, useraddr,
1470 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001471 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001472 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001473 case ETHTOOL_GRXRINGS:
1474 case ETHTOOL_GRXCLSRLCNT:
1475 case ETHTOOL_GRXCLSRULE:
1476 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001477 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001478 break;
1479 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001480 case ETHTOOL_SRXCLSRLDEL:
1481 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001482 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001483 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001484 case ETHTOOL_FLASHDEV:
1485 rc = ethtool_flash_device(dev, useraddr);
1486 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001487 case ETHTOOL_RESET:
1488 rc = ethtool_reset(dev, useraddr);
1489 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001490 case ETHTOOL_GSSET_INFO:
1491 rc = ethtool_get_sset_info(dev, useraddr);
1492 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001493 case ETHTOOL_GRXFHINDIR:
1494 rc = ethtool_get_rxfh_indir(dev, useraddr);
1495 break;
1496 case ETHTOOL_SRXFHINDIR:
1497 rc = ethtool_set_rxfh_indir(dev, useraddr);
1498 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001499 case ETHTOOL_GFEATURES:
1500 rc = ethtool_get_features(dev, useraddr);
1501 break;
1502 case ETHTOOL_SFEATURES:
1503 rc = ethtool_set_features(dev, useraddr);
1504 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001505 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001506 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001507 case ETHTOOL_GSG:
1508 case ETHTOOL_GTSO:
1509 case ETHTOOL_GUFO:
1510 case ETHTOOL_GGSO:
1511 case ETHTOOL_GGRO:
1512 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1513 break;
1514 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001515 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001516 case ETHTOOL_SSG:
1517 case ETHTOOL_STSO:
1518 case ETHTOOL_SUFO:
1519 case ETHTOOL_SGSO:
1520 case ETHTOOL_SGRO:
1521 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1522 break;
amit salecha8b5933c32011-04-07 01:58:42 +00001523 case ETHTOOL_GCHANNELS:
1524 rc = ethtool_get_channels(dev, useraddr);
1525 break;
1526 case ETHTOOL_SCHANNELS:
1527 rc = ethtool_set_channels(dev, useraddr);
1528 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001529 case ETHTOOL_SET_DUMP:
1530 rc = ethtool_set_dump(dev, useraddr);
1531 break;
1532 case ETHTOOL_GET_DUMP_FLAG:
1533 rc = ethtool_get_dump_flag(dev, useraddr);
1534 break;
1535 case ETHTOOL_GET_DUMP_DATA:
1536 rc = ethtool_get_dump_data(dev, useraddr);
1537 break;
Richard Cochranc8f3a8c2012-04-03 22:59:17 +00001538 case ETHTOOL_GET_TS_INFO:
1539 rc = ethtool_get_ts_info(dev, useraddr);
1540 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001542 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001544
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001545 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001547
1548 if (old_features != dev->features)
1549 netdev_features_change(dev);
1550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}