blob: 080161924a0d499359dd8d2f00404ac276783c17 [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",
Ben Greear36eabda32012-02-11 15:39:14 +000076 [NETIF_F_RXFCS_BIT] = "rx-fcs",
Michał Mirosław9d921542011-11-15 15:29:55 +000077};
78
Michał Mirosław5455c692011-02-15 16:59:17 +000079static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
80{
81 struct ethtool_gfeatures cmd = {
82 .cmd = ETHTOOL_GFEATURES,
83 .size = ETHTOOL_DEV_FEATURE_WORDS,
84 };
Michał Mirosław475414f2011-11-15 15:29:55 +000085 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +000086 u32 __user *sizeaddr;
87 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +000088 int i;
89
90 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +000091 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +000092
93 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +000094 features[i].available = (u32)(dev->hw_features >> (32 * i));
95 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
96 features[i].active = (u32)(dev->features >> (32 * i));
97 features[i].never_changed =
98 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +000099 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000100
101 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
102 if (get_user(copy_size, sizeaddr))
103 return -EFAULT;
104
105 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
106 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
107
108 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
109 return -EFAULT;
110 useraddr += sizeof(cmd);
111 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
112 return -EFAULT;
113
114 return 0;
115}
116
117static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
118{
119 struct ethtool_sfeatures cmd;
120 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000121 netdev_features_t wanted = 0, valid = 0;
122 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000123
124 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
125 return -EFAULT;
126 useraddr += sizeof(cmd);
127
128 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
129 return -EINVAL;
130
131 if (copy_from_user(features, useraddr, sizeof(features)))
132 return -EFAULT;
133
Michał Mirosław475414f2011-11-15 15:29:55 +0000134 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000135 valid |= (netdev_features_t)features[i].valid << (32 * i);
136 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000137 }
138
139 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000140 return -EINVAL;
141
Michał Mirosław475414f2011-11-15 15:29:55 +0000142 if (valid & ~dev->hw_features) {
143 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000144 ret |= ETHTOOL_F_UNSUPPORTED;
145 }
146
Michał Mirosław475414f2011-11-15 15:29:55 +0000147 dev->wanted_features &= ~valid;
148 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700149 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000150
Michał Mirosław475414f2011-11-15 15:29:55 +0000151 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000152 ret |= ETHTOOL_F_WISH;
153
154 return ret;
155}
156
Michał Mirosław340ae162011-02-15 16:59:16 +0000157static int __ethtool_get_sset_count(struct net_device *dev, int sset)
158{
159 const struct ethtool_ops *ops = dev->ethtool_ops;
160
Michał Mirosław5455c692011-02-15 16:59:17 +0000161 if (sset == ETH_SS_FEATURES)
162 return ARRAY_SIZE(netdev_features_strings);
163
Michał Mirosław340ae162011-02-15 16:59:16 +0000164 if (ops && ops->get_sset_count && ops->get_strings)
165 return ops->get_sset_count(dev, sset);
166 else
167 return -EOPNOTSUPP;
168}
169
170static void __ethtool_get_strings(struct net_device *dev,
171 u32 stringset, u8 *data)
172{
173 const struct ethtool_ops *ops = dev->ethtool_ops;
174
Michał Mirosław5455c692011-02-15 16:59:17 +0000175 if (stringset == ETH_SS_FEATURES)
176 memcpy(data, netdev_features_strings,
177 sizeof(netdev_features_strings));
178 else
179 /* ops->get_strings is valid because checked earlier */
180 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000181}
182
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000183static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000184{
185 /* feature masks of legacy discrete ethtool ops */
186
187 switch (eth_cmd) {
188 case ETHTOOL_GTXCSUM:
189 case ETHTOOL_STXCSUM:
190 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000191 case ETHTOOL_GRXCSUM:
192 case ETHTOOL_SRXCSUM:
193 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000194 case ETHTOOL_GSG:
195 case ETHTOOL_SSG:
196 return NETIF_F_SG;
197 case ETHTOOL_GTSO:
198 case ETHTOOL_STSO:
199 return NETIF_F_ALL_TSO;
200 case ETHTOOL_GUFO:
201 case ETHTOOL_SUFO:
202 return NETIF_F_UFO;
203 case ETHTOOL_GGSO:
204 case ETHTOOL_SGSO:
205 return NETIF_F_GSO;
206 case ETHTOOL_GGRO:
207 case ETHTOOL_SGRO:
208 return NETIF_F_GRO;
209 default:
210 BUG();
211 }
212}
213
Michał Mirosław0a417702011-02-15 16:59:17 +0000214static int ethtool_get_one_feature(struct net_device *dev,
215 char __user *useraddr, u32 ethcmd)
216{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000217 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000218 struct ethtool_value edata = {
219 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000220 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000221 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000222
Michał Mirosław0a417702011-02-15 16:59:17 +0000223 if (copy_to_user(useraddr, &edata, sizeof(edata)))
224 return -EFAULT;
225 return 0;
226}
227
Michał Mirosław0a417702011-02-15 16:59:17 +0000228static int ethtool_set_one_feature(struct net_device *dev,
229 void __user *useraddr, u32 ethcmd)
230{
231 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000232 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000233
234 if (copy_from_user(&edata, useraddr, sizeof(edata)))
235 return -EFAULT;
236
Michał Mirosław86794882011-02-15 16:59:17 +0000237 mask = ethtool_get_feature_mask(ethcmd);
238 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000239 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000240 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000241
242 if (edata.data)
243 dev->wanted_features |= mask;
244 else
245 dev->wanted_features &= ~mask;
246
247 __netdev_update_features(dev);
248
249 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000250}
251
Michał Mirosław02b3a552011-11-15 15:29:55 +0000252#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
253 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
254#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
255 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000256
257static u32 __ethtool_get_flags(struct net_device *dev)
258{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000259 u32 flags = 0;
260
261 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
262 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
263 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
264 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
265 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
266
267 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000268}
269
270static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000271{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000272 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000273
Michał Mirosław02b3a552011-11-15 15:29:55 +0000274 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000275 return -EINVAL;
276
Michał Mirosław02b3a552011-11-15 15:29:55 +0000277 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
278 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
279 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
280 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
281 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
282
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000283 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000284 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000285 if (changed & ~dev->hw_features)
286 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
287
288 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000289 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000290
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700291 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000292
293 return 0;
294}
295
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000296int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000298 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000300 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return -EOPNOTSUPP;
302
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000303 memset(cmd, 0, sizeof(struct ethtool_cmd));
304 cmd->cmd = ETHTOOL_GSET;
305 return dev->ethtool_ops->get_settings(dev, cmd);
306}
307EXPORT_SYMBOL(__ethtool_get_settings);
308
309static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
310{
311 int err;
312 struct ethtool_cmd cmd;
313
314 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (err < 0)
316 return err;
317
318 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
319 return -EFAULT;
320 return 0;
321}
322
323static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
324{
325 struct ethtool_cmd cmd;
326
327 if (!dev->ethtool_ops->set_settings)
328 return -EOPNOTSUPP;
329
330 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
331 return -EFAULT;
332
333 return dev->ethtool_ops->set_settings(dev, &cmd);
334}
335
chavey97f8aef2010-04-07 21:54:42 -0700336static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
337 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700340 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 memset(&info, 0, sizeof(info));
343 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700344 if (ops && ops->get_drvinfo) {
345 ops->get_drvinfo(dev, &info);
346 } else if (dev->dev.parent && dev->dev.parent->driver) {
347 strlcpy(info.bus_info, dev_name(dev->dev.parent),
348 sizeof(info.bus_info));
349 strlcpy(info.driver, dev->dev.parent->driver->name,
350 sizeof(info.driver));
351 } else {
352 return -EOPNOTSUPP;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Jeff Garzik723b2f52010-03-03 22:51:50 +0000355 /*
356 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000357 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000358 */
Ben Hutchings01414802010-08-17 02:31:15 -0700359 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700360 int rc;
361
362 rc = ops->get_sset_count(dev, ETH_SS_TEST);
363 if (rc >= 0)
364 info.testinfo_len = rc;
365 rc = ops->get_sset_count(dev, ETH_SS_STATS);
366 if (rc >= 0)
367 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700368 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
369 if (rc >= 0)
370 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700371 }
Ben Hutchings01414802010-08-17 02:31:15 -0700372 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700374 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 info.eedump_len = ops->get_eeprom_len(dev);
376
377 if (copy_to_user(useraddr, &info, sizeof(info)))
378 return -EFAULT;
379 return 0;
380}
381
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800382static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700383 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000384{
385 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000386 u64 sset_mask;
387 int i, idx = 0, n_bits = 0, ret, rc;
388 u32 *info_buf = NULL;
389
Jeff Garzik723b2f52010-03-03 22:51:50 +0000390 if (copy_from_user(&info, useraddr, sizeof(info)))
391 return -EFAULT;
392
393 /* store copy of mask, because we zero struct later on */
394 sset_mask = info.sset_mask;
395 if (!sset_mask)
396 return 0;
397
398 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000399 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000400
401 memset(&info, 0, sizeof(info));
402 info.cmd = ETHTOOL_GSSET_INFO;
403
404 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
405 if (!info_buf)
406 return -ENOMEM;
407
408 /*
409 * fill return buffer based on input bitmask and successful
410 * get_sset_count return
411 */
412 for (i = 0; i < 64; i++) {
413 if (!(sset_mask & (1ULL << i)))
414 continue;
415
Michał Mirosław340ae162011-02-15 16:59:16 +0000416 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000417 if (rc >= 0) {
418 info.sset_mask |= (1ULL << i);
419 info_buf[idx++] = rc;
420 }
421 }
422
423 ret = -EFAULT;
424 if (copy_to_user(useraddr, &info, sizeof(info)))
425 goto out;
426
427 useraddr += offsetof(struct ethtool_sset_info, data);
428 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
429 goto out;
430
431 ret = 0;
432
433out:
434 kfree(info_buf);
435 return ret;
436}
437
chavey97f8aef2010-04-07 21:54:42 -0700438static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000439 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700440{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000441 struct ethtool_rxnfc info;
442 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000443 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700444
Santwona Behera59089d82009-02-20 00:58:13 -0800445 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700446 return -EOPNOTSUPP;
447
Ben Hutchingsbf988432010-06-28 08:45:58 +0000448 /* struct ethtool_rxnfc was originally defined for
449 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
450 * members. User-space might still be using that
451 * definition. */
452 if (cmd == ETHTOOL_SRXFH)
453 info_size = (offsetof(struct ethtool_rxnfc, data) +
454 sizeof(info.data));
455
456 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700457 return -EFAULT;
458
Ben Hutchings55664f32012-01-03 12:04:51 +0000459 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
460 if (rc)
461 return rc;
462
463 if (cmd == ETHTOOL_SRXCLSRLINS &&
464 copy_to_user(useraddr, &info, info_size))
465 return -EFAULT;
466
467 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700468}
469
chavey97f8aef2010-04-07 21:54:42 -0700470static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000471 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700472{
473 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000474 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800475 const struct ethtool_ops *ops = dev->ethtool_ops;
476 int ret;
477 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700478
Santwona Behera59089d82009-02-20 00:58:13 -0800479 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700480 return -EOPNOTSUPP;
481
Ben Hutchingsbf988432010-06-28 08:45:58 +0000482 /* struct ethtool_rxnfc was originally defined for
483 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
484 * members. User-space might still be using that
485 * definition. */
486 if (cmd == ETHTOOL_GRXFH)
487 info_size = (offsetof(struct ethtool_rxnfc, data) +
488 sizeof(info.data));
489
490 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700491 return -EFAULT;
492
Santwona Behera59089d82009-02-20 00:58:13 -0800493 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
494 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000495 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000496 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000497 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800498 if (!rule_buf)
499 return -ENOMEM;
500 }
501 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700502
Santwona Behera59089d82009-02-20 00:58:13 -0800503 ret = ops->get_rxnfc(dev, &info, rule_buf);
504 if (ret < 0)
505 goto err_out;
506
507 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000508 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800509 goto err_out;
510
511 if (rule_buf) {
512 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
513 if (copy_to_user(useraddr, rule_buf,
514 info.rule_cnt * sizeof(u32)))
515 goto err_out;
516 }
517 ret = 0;
518
519err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700520 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800521
522 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700523}
524
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000525static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
526 void __user *useraddr)
527{
Ben Hutchings7850f632011-12-15 13:55:01 +0000528 u32 user_size, dev_size;
529 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000530 int ret;
531
Ben Hutchings7850f632011-12-15 13:55:01 +0000532 if (!dev->ethtool_ops->get_rxfh_indir_size ||
533 !dev->ethtool_ops->get_rxfh_indir)
534 return -EOPNOTSUPP;
535 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
536 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000537 return -EOPNOTSUPP;
538
Ben Hutchings7850f632011-12-15 13:55:01 +0000539 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000540 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000541 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000542 return -EFAULT;
543
Ben Hutchings7850f632011-12-15 13:55:01 +0000544 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
545 &dev_size, sizeof(dev_size)))
546 return -EFAULT;
547
548 /* If the user buffer size is 0, this is just a query for the
549 * device table size. Otherwise, if it's smaller than the
550 * device table size it's an error.
551 */
552 if (user_size < dev_size)
553 return user_size == 0 ? 0 : -EINVAL;
554
555 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000556 if (!indir)
557 return -ENOMEM;
558
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000559 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
560 if (ret)
561 goto out;
562
Ben Hutchings7850f632011-12-15 13:55:01 +0000563 if (copy_to_user(useraddr +
564 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
565 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000566 ret = -EFAULT;
567
568out:
569 kfree(indir);
570 return ret;
571}
572
573static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
574 void __user *useraddr)
575{
Ben Hutchings7850f632011-12-15 13:55:01 +0000576 struct ethtool_rxnfc rx_rings;
577 u32 user_size, dev_size, i;
578 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000579 int ret;
580
Ben Hutchings7850f632011-12-15 13:55:01 +0000581 if (!dev->ethtool_ops->get_rxfh_indir_size ||
582 !dev->ethtool_ops->set_rxfh_indir ||
583 !dev->ethtool_ops->get_rxnfc)
584 return -EOPNOTSUPP;
585 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
586 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000587 return -EOPNOTSUPP;
588
Ben Hutchings7850f632011-12-15 13:55:01 +0000589 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000590 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000591 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000592 return -EFAULT;
593
Ben Hutchings278bc422011-12-15 13:56:49 +0000594 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000595 return -EINVAL;
596
597 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000598 if (!indir)
599 return -ENOMEM;
600
Ben Hutchings7850f632011-12-15 13:55:01 +0000601 rx_rings.cmd = ETHTOOL_GRXRINGS;
602 ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
603 if (ret)
604 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000605
606 if (user_size == 0) {
607 for (i = 0; i < dev_size; i++)
608 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
609 } else {
610 if (copy_from_user(indir,
611 useraddr +
612 offsetof(struct ethtool_rxfh_indir,
613 ring_index[0]),
614 dev_size * sizeof(indir[0]))) {
615 ret = -EFAULT;
Ben Hutchings7850f632011-12-15 13:55:01 +0000616 goto out;
617 }
Ben Hutchings278bc422011-12-15 13:56:49 +0000618
619 /* Validate ring indices */
620 for (i = 0; i < dev_size; i++) {
621 if (indir[i] >= rx_rings.data) {
622 ret = -EINVAL;
623 goto out;
624 }
625 }
Ben Hutchings7850f632011-12-15 13:55:01 +0000626 }
627
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000628 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
629
630out:
631 kfree(indir);
632 return ret;
633}
634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
636{
637 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700638 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 void *regbuf;
640 int reglen, ret;
641
642 if (!ops->get_regs || !ops->get_regs_len)
643 return -EOPNOTSUPP;
644
645 if (copy_from_user(&regs, useraddr, sizeof(regs)))
646 return -EFAULT;
647
648 reglen = ops->get_regs_len(dev);
649 if (regs.len > reglen)
650 regs.len = reglen;
651
Eugene Teob7c7d012011-01-24 21:05:17 -0800652 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700653 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return -ENOMEM;
655
656 ops->get_regs(dev, &regs, regbuf);
657
658 ret = -EFAULT;
659 if (copy_to_user(useraddr, &regs, sizeof(regs)))
660 goto out;
661 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700662 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 goto out;
664 ret = 0;
665
666 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000667 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return ret;
669}
670
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000671static int ethtool_reset(struct net_device *dev, char __user *useraddr)
672{
673 struct ethtool_value reset;
674 int ret;
675
676 if (!dev->ethtool_ops->reset)
677 return -EOPNOTSUPP;
678
679 if (copy_from_user(&reset, useraddr, sizeof(reset)))
680 return -EFAULT;
681
682 ret = dev->ethtool_ops->reset(dev, &reset.data);
683 if (ret)
684 return ret;
685
686 if (copy_to_user(useraddr, &reset, sizeof(reset)))
687 return -EFAULT;
688 return 0;
689}
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
692{
Roland Dreier8e557422010-02-11 12:14:23 -0800693 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 if (!dev->ethtool_ops->get_wol)
696 return -EOPNOTSUPP;
697
698 dev->ethtool_ops->get_wol(dev, &wol);
699
700 if (copy_to_user(useraddr, &wol, sizeof(wol)))
701 return -EFAULT;
702 return 0;
703}
704
705static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
706{
707 struct ethtool_wolinfo wol;
708
709 if (!dev->ethtool_ops->set_wol)
710 return -EOPNOTSUPP;
711
712 if (copy_from_user(&wol, useraddr, sizeof(wol)))
713 return -EFAULT;
714
715 return dev->ethtool_ops->set_wol(dev, &wol);
716}
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718static int ethtool_nway_reset(struct net_device *dev)
719{
720 if (!dev->ethtool_ops->nway_reset)
721 return -EOPNOTSUPP;
722
723 return dev->ethtool_ops->nway_reset(dev);
724}
725
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000726static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
727{
728 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
729
730 if (!dev->ethtool_ops->get_link)
731 return -EOPNOTSUPP;
732
733 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
734
735 if (copy_to_user(useraddr, &edata, sizeof(edata)))
736 return -EFAULT;
737 return 0;
738}
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
741{
742 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700743 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700744 void __user *userbuf = useraddr + sizeof(eeprom);
745 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700747 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 if (!ops->get_eeprom || !ops->get_eeprom_len)
750 return -EOPNOTSUPP;
751
752 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
753 return -EFAULT;
754
755 /* Check for wrap and zero */
756 if (eeprom.offset + eeprom.len <= eeprom.offset)
757 return -EINVAL;
758
759 /* Check for exceeding total eeprom len */
760 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
761 return -EINVAL;
762
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700763 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 if (!data)
765 return -ENOMEM;
766
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700767 bytes_remaining = eeprom.len;
768 while (bytes_remaining > 0) {
769 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700771 ret = ops->get_eeprom(dev, &eeprom, data);
772 if (ret)
773 break;
774 if (copy_to_user(userbuf, data, eeprom.len)) {
775 ret = -EFAULT;
776 break;
777 }
778 userbuf += eeprom.len;
779 eeprom.offset += eeprom.len;
780 bytes_remaining -= eeprom.len;
781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700783 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
784 eeprom.offset -= eeprom.len;
785 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
786 ret = -EFAULT;
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 kfree(data);
789 return ret;
790}
791
792static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
793{
794 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700795 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700796 void __user *userbuf = useraddr + sizeof(eeprom);
797 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700799 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 if (!ops->set_eeprom || !ops->get_eeprom_len)
802 return -EOPNOTSUPP;
803
804 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
805 return -EFAULT;
806
807 /* Check for wrap and zero */
808 if (eeprom.offset + eeprom.len <= eeprom.offset)
809 return -EINVAL;
810
811 /* Check for exceeding total eeprom len */
812 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
813 return -EINVAL;
814
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700815 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 if (!data)
817 return -ENOMEM;
818
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700819 bytes_remaining = eeprom.len;
820 while (bytes_remaining > 0) {
821 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700823 if (copy_from_user(data, userbuf, eeprom.len)) {
824 ret = -EFAULT;
825 break;
826 }
827 ret = ops->set_eeprom(dev, &eeprom, data);
828 if (ret)
829 break;
830 userbuf += eeprom.len;
831 eeprom.offset += eeprom.len;
832 bytes_remaining -= eeprom.len;
833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 kfree(data);
836 return ret;
837}
838
chavey97f8aef2010-04-07 21:54:42 -0700839static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
840 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Roland Dreier8e557422010-02-11 12:14:23 -0800842 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 if (!dev->ethtool_ops->get_coalesce)
845 return -EOPNOTSUPP;
846
847 dev->ethtool_ops->get_coalesce(dev, &coalesce);
848
849 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
850 return -EFAULT;
851 return 0;
852}
853
chavey97f8aef2010-04-07 21:54:42 -0700854static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
855 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857 struct ethtool_coalesce coalesce;
858
David S. Millerfa04ae52005-06-06 15:07:19 -0700859 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return -EOPNOTSUPP;
861
862 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
863 return -EFAULT;
864
865 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
866}
867
868static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
869{
Roland Dreier8e557422010-02-11 12:14:23 -0800870 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 if (!dev->ethtool_ops->get_ringparam)
873 return -EOPNOTSUPP;
874
875 dev->ethtool_ops->get_ringparam(dev, &ringparam);
876
877 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
878 return -EFAULT;
879 return 0;
880}
881
882static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
883{
884 struct ethtool_ringparam ringparam;
885
886 if (!dev->ethtool_ops->set_ringparam)
887 return -EOPNOTSUPP;
888
889 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
890 return -EFAULT;
891
892 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
893}
894
amit salecha8b5933c2011-04-07 01:58:42 +0000895static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
896 void __user *useraddr)
897{
898 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
899
900 if (!dev->ethtool_ops->get_channels)
901 return -EOPNOTSUPP;
902
903 dev->ethtool_ops->get_channels(dev, &channels);
904
905 if (copy_to_user(useraddr, &channels, sizeof(channels)))
906 return -EFAULT;
907 return 0;
908}
909
910static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
911 void __user *useraddr)
912{
913 struct ethtool_channels channels;
914
915 if (!dev->ethtool_ops->set_channels)
916 return -EOPNOTSUPP;
917
918 if (copy_from_user(&channels, useraddr, sizeof(channels)))
919 return -EFAULT;
920
921 return dev->ethtool_ops->set_channels(dev, &channels);
922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
925{
926 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
927
928 if (!dev->ethtool_ops->get_pauseparam)
929 return -EOPNOTSUPP;
930
931 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
932
933 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
934 return -EFAULT;
935 return 0;
936}
937
938static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
939{
940 struct ethtool_pauseparam pauseparam;
941
Jeff Garzike1b90c42006-07-17 12:54:40 -0400942 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return -EOPNOTSUPP;
944
945 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
946 return -EFAULT;
947
948 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
949}
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
952{
953 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700954 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700956 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000958 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700959 return -EOPNOTSUPP;
960
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000961 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700962 if (test_len < 0)
963 return test_len;
964 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966 if (copy_from_user(&test, useraddr, sizeof(test)))
967 return -EFAULT;
968
Jeff Garzikff03d492007-08-15 16:01:08 -0700969 test.len = test_len;
970 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 if (!data)
972 return -ENOMEM;
973
974 ops->self_test(dev, &test, data);
975
976 ret = -EFAULT;
977 if (copy_to_user(useraddr, &test, sizeof(test)))
978 goto out;
979 useraddr += sizeof(test);
980 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
981 goto out;
982 ret = 0;
983
984 out:
985 kfree(data);
986 return ret;
987}
988
989static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
990{
991 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 u8 *data;
993 int ret;
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
996 return -EFAULT;
997
Michał Mirosław340ae162011-02-15 16:59:16 +0000998 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000999 if (ret < 0)
1000 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001001
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001002 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1005 if (!data)
1006 return -ENOMEM;
1007
Michał Mirosław340ae162011-02-15 16:59:16 +00001008 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 ret = -EFAULT;
1011 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1012 goto out;
1013 useraddr += sizeof(gstrings);
1014 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1015 goto out;
1016 ret = 0;
1017
Michał Mirosław340ae162011-02-15 16:59:16 +00001018out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 kfree(data);
1020 return ret;
1021}
1022
1023static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1024{
1025 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001026 static bool busy;
1027 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001029 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 return -EOPNOTSUPP;
1031
Ben Hutchings68f512f2011-04-02 00:35:15 +01001032 if (busy)
1033 return -EBUSY;
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (copy_from_user(&id, useraddr, sizeof(id)))
1036 return -EFAULT;
1037
Ben Hutchings68f512f2011-04-02 00:35:15 +01001038 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001039 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001040 return rc;
1041
1042 /* Drop the RTNL lock while waiting, but prevent reentry or
1043 * removal of the device.
1044 */
1045 busy = true;
1046 dev_hold(dev);
1047 rtnl_unlock();
1048
1049 if (rc == 0) {
1050 /* Driver will handle this itself */
1051 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001052 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001053 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001054 /* Driver expects to be called at twice the frequency in rc */
1055 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001056
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001057 /* Count down seconds */
1058 do {
1059 /* Count down iterations per second */
1060 i = n;
1061 do {
1062 rtnl_lock();
1063 rc = dev->ethtool_ops->set_phys_id(dev,
1064 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1065 rtnl_unlock();
1066 if (rc)
1067 break;
1068 schedule_timeout_interruptible(interval);
1069 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001070 } while (!signal_pending(current) &&
1071 (id.data == 0 || --id.data != 0));
1072 }
1073
1074 rtnl_lock();
1075 dev_put(dev);
1076 busy = false;
1077
1078 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1079 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
1082static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1083{
1084 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001085 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001087 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001089 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001090 return -EOPNOTSUPP;
1091
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001092 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001093 if (n_stats < 0)
1094 return n_stats;
1095 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1098 return -EFAULT;
1099
Jeff Garzikff03d492007-08-15 16:01:08 -07001100 stats.n_stats = n_stats;
1101 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 if (!data)
1103 return -ENOMEM;
1104
1105 ops->get_ethtool_stats(dev, &stats, data);
1106
1107 ret = -EFAULT;
1108 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1109 goto out;
1110 useraddr += sizeof(stats);
1111 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1112 goto out;
1113 ret = 0;
1114
1115 out:
1116 kfree(data);
1117 return ret;
1118}
1119
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001120static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001121{
1122 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001123
Matthew Wilcox313674a2007-07-31 14:00:29 -07001124 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001125 return -EFAULT;
1126
Matthew Wilcox313674a2007-07-31 14:00:29 -07001127 if (epaddr.size < dev->addr_len)
1128 return -ETOOSMALL;
1129 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001130
Jon Wetzela6f9a702005-08-20 17:15:54 -07001131 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001132 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001133 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001134 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1135 return -EFAULT;
1136 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001137}
1138
Jeff Garzik13c99b22007-08-15 16:01:56 -07001139static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1140 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001141{
Roland Dreier8e557422010-02-11 12:14:23 -08001142 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001143
Jeff Garzik13c99b22007-08-15 16:01:56 -07001144 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001145 return -EOPNOTSUPP;
1146
Jeff Garzik13c99b22007-08-15 16:01:56 -07001147 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001148
1149 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1150 return -EFAULT;
1151 return 0;
1152}
1153
Jeff Garzik13c99b22007-08-15 16:01:56 -07001154static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1155 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001156{
1157 struct ethtool_value edata;
1158
Jeff Garzik13c99b22007-08-15 16:01:56 -07001159 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001160 return -EOPNOTSUPP;
1161
1162 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1163 return -EFAULT;
1164
Jeff Garzik13c99b22007-08-15 16:01:56 -07001165 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001166 return 0;
1167}
1168
Jeff Garzik13c99b22007-08-15 16:01:56 -07001169static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1170 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001171{
1172 struct ethtool_value edata;
1173
Jeff Garzik13c99b22007-08-15 16:01:56 -07001174 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001175 return -EOPNOTSUPP;
1176
1177 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1178 return -EFAULT;
1179
Jeff Garzik13c99b22007-08-15 16:01:56 -07001180 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001181}
1182
chavey97f8aef2010-04-07 21:54:42 -07001183static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1184 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001185{
1186 struct ethtool_flash efl;
1187
1188 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1189 return -EFAULT;
1190
1191 if (!dev->ethtool_ops->flash_device)
1192 return -EOPNOTSUPP;
1193
Ben Hutchings786f5282012-02-01 09:32:25 +00001194 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1195
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001196 return dev->ethtool_ops->flash_device(dev, &efl);
1197}
1198
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001199static int ethtool_set_dump(struct net_device *dev,
1200 void __user *useraddr)
1201{
1202 struct ethtool_dump dump;
1203
1204 if (!dev->ethtool_ops->set_dump)
1205 return -EOPNOTSUPP;
1206
1207 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1208 return -EFAULT;
1209
1210 return dev->ethtool_ops->set_dump(dev, &dump);
1211}
1212
1213static int ethtool_get_dump_flag(struct net_device *dev,
1214 void __user *useraddr)
1215{
1216 int ret;
1217 struct ethtool_dump dump;
1218 const struct ethtool_ops *ops = dev->ethtool_ops;
1219
1220 if (!dev->ethtool_ops->get_dump_flag)
1221 return -EOPNOTSUPP;
1222
1223 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1224 return -EFAULT;
1225
1226 ret = ops->get_dump_flag(dev, &dump);
1227 if (ret)
1228 return ret;
1229
1230 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1231 return -EFAULT;
1232 return 0;
1233}
1234
1235static int ethtool_get_dump_data(struct net_device *dev,
1236 void __user *useraddr)
1237{
1238 int ret;
1239 __u32 len;
1240 struct ethtool_dump dump, tmp;
1241 const struct ethtool_ops *ops = dev->ethtool_ops;
1242 void *data = NULL;
1243
1244 if (!dev->ethtool_ops->get_dump_data ||
1245 !dev->ethtool_ops->get_dump_flag)
1246 return -EOPNOTSUPP;
1247
1248 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1249 return -EFAULT;
1250
1251 memset(&tmp, 0, sizeof(tmp));
1252 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1253 ret = ops->get_dump_flag(dev, &tmp);
1254 if (ret)
1255 return ret;
1256
1257 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1258 if (!len)
1259 return -EFAULT;
1260
1261 data = vzalloc(tmp.len);
1262 if (!data)
1263 return -ENOMEM;
1264 ret = ops->get_dump_data(dev, &dump, data);
1265 if (ret)
1266 goto out;
1267
1268 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1269 ret = -EFAULT;
1270 goto out;
1271 }
1272 useraddr += offsetof(struct ethtool_dump, data);
1273 if (copy_to_user(useraddr, data, len))
1274 ret = -EFAULT;
1275out:
1276 vfree(data);
1277 return ret;
1278}
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280/* The main entry point in this file. Called from net/core/dev.c */
1281
Eric W. Biederman881d9662007-09-17 11:56:21 -07001282int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001284 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 void __user *useraddr = ifr->ifr_data;
1286 u32 ethcmd;
1287 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001288 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 if (!dev || !netif_device_present(dev))
1291 return -ENODEV;
1292
chavey97f8aef2010-04-07 21:54:42 -07001293 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 return -EFAULT;
1295
Ben Hutchings01414802010-08-17 02:31:15 -07001296 if (!dev->ethtool_ops) {
1297 /* ETHTOOL_GDRVINFO does not require any driver support.
1298 * It is also unprivileged and does not change anything,
1299 * so we can take a shortcut to it. */
1300 if (ethcmd == ETHTOOL_GDRVINFO)
1301 return ethtool_get_drvinfo(dev, useraddr);
1302 else
1303 return -EOPNOTSUPP;
1304 }
1305
Stephen Hemminger75f31232006-09-28 15:13:37 -07001306 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001307 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001308 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001309 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001310 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001311 case ETHTOOL_GCOALESCE:
1312 case ETHTOOL_GRINGPARAM:
1313 case ETHTOOL_GPAUSEPARAM:
1314 case ETHTOOL_GRXCSUM:
1315 case ETHTOOL_GTXCSUM:
1316 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001317 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001318 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001319 case ETHTOOL_GTSO:
1320 case ETHTOOL_GPERMADDR:
1321 case ETHTOOL_GUFO:
1322 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001323 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001324 case ETHTOOL_GFLAGS:
1325 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001326 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001327 case ETHTOOL_GRXRINGS:
1328 case ETHTOOL_GRXCLSRLCNT:
1329 case ETHTOOL_GRXCLSRULE:
1330 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001331 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001332 break;
1333 default:
1334 if (!capable(CAP_NET_ADMIN))
1335 return -EPERM;
1336 }
1337
chavey97f8aef2010-04-07 21:54:42 -07001338 if (dev->ethtool_ops->begin) {
1339 rc = dev->ethtool_ops->begin(dev);
1340 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001342 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001343 old_features = dev->features;
1344
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 switch (ethcmd) {
1346 case ETHTOOL_GSET:
1347 rc = ethtool_get_settings(dev, useraddr);
1348 break;
1349 case ETHTOOL_SSET:
1350 rc = ethtool_set_settings(dev, useraddr);
1351 break;
1352 case ETHTOOL_GDRVINFO:
1353 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 break;
1355 case ETHTOOL_GREGS:
1356 rc = ethtool_get_regs(dev, useraddr);
1357 break;
1358 case ETHTOOL_GWOL:
1359 rc = ethtool_get_wol(dev, useraddr);
1360 break;
1361 case ETHTOOL_SWOL:
1362 rc = ethtool_set_wol(dev, useraddr);
1363 break;
1364 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001365 rc = ethtool_get_value(dev, useraddr, ethcmd,
1366 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 break;
1368 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001369 rc = ethtool_set_value_void(dev, useraddr,
1370 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 break;
1372 case ETHTOOL_NWAY_RST:
1373 rc = ethtool_nway_reset(dev);
1374 break;
1375 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001376 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 break;
1378 case ETHTOOL_GEEPROM:
1379 rc = ethtool_get_eeprom(dev, useraddr);
1380 break;
1381 case ETHTOOL_SEEPROM:
1382 rc = ethtool_set_eeprom(dev, useraddr);
1383 break;
1384 case ETHTOOL_GCOALESCE:
1385 rc = ethtool_get_coalesce(dev, useraddr);
1386 break;
1387 case ETHTOOL_SCOALESCE:
1388 rc = ethtool_set_coalesce(dev, useraddr);
1389 break;
1390 case ETHTOOL_GRINGPARAM:
1391 rc = ethtool_get_ringparam(dev, useraddr);
1392 break;
1393 case ETHTOOL_SRINGPARAM:
1394 rc = ethtool_set_ringparam(dev, useraddr);
1395 break;
1396 case ETHTOOL_GPAUSEPARAM:
1397 rc = ethtool_get_pauseparam(dev, useraddr);
1398 break;
1399 case ETHTOOL_SPAUSEPARAM:
1400 rc = ethtool_set_pauseparam(dev, useraddr);
1401 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 case ETHTOOL_TEST:
1403 rc = ethtool_self_test(dev, useraddr);
1404 break;
1405 case ETHTOOL_GSTRINGS:
1406 rc = ethtool_get_strings(dev, useraddr);
1407 break;
1408 case ETHTOOL_PHYS_ID:
1409 rc = ethtool_phys_id(dev, useraddr);
1410 break;
1411 case ETHTOOL_GSTATS:
1412 rc = ethtool_get_stats(dev, useraddr);
1413 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001414 case ETHTOOL_GPERMADDR:
1415 rc = ethtool_get_perm_addr(dev, useraddr);
1416 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001417 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001418 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001419 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001420 break;
1421 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001422 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001423 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001424 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001425 rc = ethtool_get_value(dev, useraddr, ethcmd,
1426 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001427 break;
1428 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001429 rc = ethtool_set_value(dev, useraddr,
1430 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001431 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001432 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001433 case ETHTOOL_GRXRINGS:
1434 case ETHTOOL_GRXCLSRLCNT:
1435 case ETHTOOL_GRXCLSRULE:
1436 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001437 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001438 break;
1439 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001440 case ETHTOOL_SRXCLSRLDEL:
1441 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001442 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001443 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001444 case ETHTOOL_FLASHDEV:
1445 rc = ethtool_flash_device(dev, useraddr);
1446 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001447 case ETHTOOL_RESET:
1448 rc = ethtool_reset(dev, useraddr);
1449 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001450 case ETHTOOL_GSSET_INFO:
1451 rc = ethtool_get_sset_info(dev, useraddr);
1452 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001453 case ETHTOOL_GRXFHINDIR:
1454 rc = ethtool_get_rxfh_indir(dev, useraddr);
1455 break;
1456 case ETHTOOL_SRXFHINDIR:
1457 rc = ethtool_set_rxfh_indir(dev, useraddr);
1458 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001459 case ETHTOOL_GFEATURES:
1460 rc = ethtool_get_features(dev, useraddr);
1461 break;
1462 case ETHTOOL_SFEATURES:
1463 rc = ethtool_set_features(dev, useraddr);
1464 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001465 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001466 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001467 case ETHTOOL_GSG:
1468 case ETHTOOL_GTSO:
1469 case ETHTOOL_GUFO:
1470 case ETHTOOL_GGSO:
1471 case ETHTOOL_GGRO:
1472 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1473 break;
1474 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001475 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001476 case ETHTOOL_SSG:
1477 case ETHTOOL_STSO:
1478 case ETHTOOL_SUFO:
1479 case ETHTOOL_SGSO:
1480 case ETHTOOL_SGRO:
1481 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1482 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001483 case ETHTOOL_GCHANNELS:
1484 rc = ethtool_get_channels(dev, useraddr);
1485 break;
1486 case ETHTOOL_SCHANNELS:
1487 rc = ethtool_set_channels(dev, useraddr);
1488 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001489 case ETHTOOL_SET_DUMP:
1490 rc = ethtool_set_dump(dev, useraddr);
1491 break;
1492 case ETHTOOL_GET_DUMP_FLAG:
1493 rc = ethtool_get_dump_flag(dev, useraddr);
1494 break;
1495 case ETHTOOL_GET_DUMP_DATA:
1496 rc = ethtool_get_dump_data(dev, useraddr);
1497 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001499 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001501
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001502 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001504
1505 if (old_features != dev->features)
1506 netdev_features_change(dev);
1507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}