blob: 6d6d7d25caaa30319870c6b1d62b38eb8972e543 [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",
Ben Greear5e0c03c2012-02-11 15:39:45 +000077 [NETIF_F_RXALL_BIT] = "rx-all",
Michał Mirosław9d921542011-11-15 15:29:55 +000078};
79
Michał Mirosław5455c692011-02-15 16:59:17 +000080static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
81{
82 struct ethtool_gfeatures cmd = {
83 .cmd = ETHTOOL_GFEATURES,
84 .size = ETHTOOL_DEV_FEATURE_WORDS,
85 };
Michał Mirosław475414f2011-11-15 15:29:55 +000086 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław5455c692011-02-15 16:59:17 +000087 u32 __user *sizeaddr;
88 u32 copy_size;
Michał Mirosław475414f2011-11-15 15:29:55 +000089 int i;
90
91 /* in case feature bits run out again */
Michał Mirosław09da71b2011-11-16 14:32:03 +000092 BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
Michał Mirosław475414f2011-11-15 15:29:55 +000093
94 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +000095 features[i].available = (u32)(dev->hw_features >> (32 * i));
96 features[i].requested = (u32)(dev->wanted_features >> (32 * i));
97 features[i].active = (u32)(dev->features >> (32 * i));
98 features[i].never_changed =
99 (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
Michał Mirosław475414f2011-11-15 15:29:55 +0000100 }
Michał Mirosław5455c692011-02-15 16:59:17 +0000101
102 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
103 if (get_user(copy_size, sizeaddr))
104 return -EFAULT;
105
106 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
107 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
108
109 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
110 return -EFAULT;
111 useraddr += sizeof(cmd);
112 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
113 return -EFAULT;
114
115 return 0;
116}
117
118static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
119{
120 struct ethtool_sfeatures cmd;
121 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
Michał Mirosław475414f2011-11-15 15:29:55 +0000122 netdev_features_t wanted = 0, valid = 0;
123 int i, ret = 0;
Michał Mirosław5455c692011-02-15 16:59:17 +0000124
125 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
126 return -EFAULT;
127 useraddr += sizeof(cmd);
128
129 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
130 return -EINVAL;
131
132 if (copy_from_user(features, useraddr, sizeof(features)))
133 return -EFAULT;
134
Michał Mirosław475414f2011-11-15 15:29:55 +0000135 for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
Michał Mirosław09da71b2011-11-16 14:32:03 +0000136 valid |= (netdev_features_t)features[i].valid << (32 * i);
137 wanted |= (netdev_features_t)features[i].requested << (32 * i);
Michał Mirosław475414f2011-11-15 15:29:55 +0000138 }
139
140 if (valid & ~NETIF_F_ETHTOOL_BITS)
Michał Mirosław5455c692011-02-15 16:59:17 +0000141 return -EINVAL;
142
Michał Mirosław475414f2011-11-15 15:29:55 +0000143 if (valid & ~dev->hw_features) {
144 valid &= dev->hw_features;
Michał Mirosław5455c692011-02-15 16:59:17 +0000145 ret |= ETHTOOL_F_UNSUPPORTED;
146 }
147
Michał Mirosław475414f2011-11-15 15:29:55 +0000148 dev->wanted_features &= ~valid;
149 dev->wanted_features |= wanted & valid;
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700150 __netdev_update_features(dev);
Michał Mirosław5455c692011-02-15 16:59:17 +0000151
Michał Mirosław475414f2011-11-15 15:29:55 +0000152 if ((dev->wanted_features ^ dev->features) & valid)
Michał Mirosław5455c692011-02-15 16:59:17 +0000153 ret |= ETHTOOL_F_WISH;
154
155 return ret;
156}
157
Michał Mirosław340ae162011-02-15 16:59:16 +0000158static int __ethtool_get_sset_count(struct net_device *dev, int sset)
159{
160 const struct ethtool_ops *ops = dev->ethtool_ops;
161
Michał Mirosław5455c692011-02-15 16:59:17 +0000162 if (sset == ETH_SS_FEATURES)
163 return ARRAY_SIZE(netdev_features_strings);
164
Michał Mirosław340ae162011-02-15 16:59:16 +0000165 if (ops && ops->get_sset_count && ops->get_strings)
166 return ops->get_sset_count(dev, sset);
167 else
168 return -EOPNOTSUPP;
169}
170
171static void __ethtool_get_strings(struct net_device *dev,
172 u32 stringset, u8 *data)
173{
174 const struct ethtool_ops *ops = dev->ethtool_ops;
175
Michał Mirosław5455c692011-02-15 16:59:17 +0000176 if (stringset == ETH_SS_FEATURES)
177 memcpy(data, netdev_features_strings,
178 sizeof(netdev_features_strings));
179 else
180 /* ops->get_strings is valid because checked earlier */
181 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000182}
183
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000184static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
Michał Mirosław0a417702011-02-15 16:59:17 +0000185{
186 /* feature masks of legacy discrete ethtool ops */
187
188 switch (eth_cmd) {
189 case ETHTOOL_GTXCSUM:
190 case ETHTOOL_STXCSUM:
191 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000192 case ETHTOOL_GRXCSUM:
193 case ETHTOOL_SRXCSUM:
194 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000195 case ETHTOOL_GSG:
196 case ETHTOOL_SSG:
197 return NETIF_F_SG;
198 case ETHTOOL_GTSO:
199 case ETHTOOL_STSO:
200 return NETIF_F_ALL_TSO;
201 case ETHTOOL_GUFO:
202 case ETHTOOL_SUFO:
203 return NETIF_F_UFO;
204 case ETHTOOL_GGSO:
205 case ETHTOOL_SGSO:
206 return NETIF_F_GSO;
207 case ETHTOOL_GGRO:
208 case ETHTOOL_SGRO:
209 return NETIF_F_GRO;
210 default:
211 BUG();
212 }
213}
214
Michał Mirosław0a417702011-02-15 16:59:17 +0000215static int ethtool_get_one_feature(struct net_device *dev,
216 char __user *useraddr, u32 ethcmd)
217{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000218 netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000219 struct ethtool_value edata = {
220 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000221 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000222 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000223
Michał Mirosław0a417702011-02-15 16:59:17 +0000224 if (copy_to_user(useraddr, &edata, sizeof(edata)))
225 return -EFAULT;
226 return 0;
227}
228
Michał Mirosław0a417702011-02-15 16:59:17 +0000229static int ethtool_set_one_feature(struct net_device *dev,
230 void __user *useraddr, u32 ethcmd)
231{
232 struct ethtool_value edata;
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000233 netdev_features_t mask;
Michał Mirosław0a417702011-02-15 16:59:17 +0000234
235 if (copy_from_user(&edata, useraddr, sizeof(edata)))
236 return -EFAULT;
237
Michał Mirosław86794882011-02-15 16:59:17 +0000238 mask = ethtool_get_feature_mask(ethcmd);
239 mask &= dev->hw_features;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000240 if (!mask)
Michał Mirosław0a417702011-02-15 16:59:17 +0000241 return -EOPNOTSUPP;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000242
243 if (edata.data)
244 dev->wanted_features |= mask;
245 else
246 dev->wanted_features &= ~mask;
247
248 __netdev_update_features(dev);
249
250 return 0;
Michał Mirosław0a417702011-02-15 16:59:17 +0000251}
252
Michał Mirosław02b3a552011-11-15 15:29:55 +0000253#define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
254 ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
255#define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_RX | \
256 NETIF_F_HW_VLAN_TX | NETIF_F_NTUPLE | NETIF_F_RXHASH)
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000257
258static u32 __ethtool_get_flags(struct net_device *dev)
259{
Michał Mirosław02b3a552011-11-15 15:29:55 +0000260 u32 flags = 0;
261
262 if (dev->features & NETIF_F_LRO) flags |= ETH_FLAG_LRO;
263 if (dev->features & NETIF_F_HW_VLAN_RX) flags |= ETH_FLAG_RXVLAN;
264 if (dev->features & NETIF_F_HW_VLAN_TX) flags |= ETH_FLAG_TXVLAN;
265 if (dev->features & NETIF_F_NTUPLE) flags |= ETH_FLAG_NTUPLE;
266 if (dev->features & NETIF_F_RXHASH) flags |= ETH_FLAG_RXHASH;
267
268 return flags;
Michał Mirosławbc5787c62011-11-15 15:29:55 +0000269}
270
271static int __ethtool_set_flags(struct net_device *dev, u32 data)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000272{
Michał Mirosławc8f44af2011-11-15 15:29:55 +0000273 netdev_features_t features = 0, changed;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000274
Michał Mirosław02b3a552011-11-15 15:29:55 +0000275 if (data & ~ETH_ALL_FLAGS)
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000276 return -EINVAL;
277
Michał Mirosław02b3a552011-11-15 15:29:55 +0000278 if (data & ETH_FLAG_LRO) features |= NETIF_F_LRO;
279 if (data & ETH_FLAG_RXVLAN) features |= NETIF_F_HW_VLAN_RX;
280 if (data & ETH_FLAG_TXVLAN) features |= NETIF_F_HW_VLAN_TX;
281 if (data & ETH_FLAG_NTUPLE) features |= NETIF_F_NTUPLE;
282 if (data & ETH_FLAG_RXHASH) features |= NETIF_F_RXHASH;
283
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000284 /* allow changing only bits set in hw_features */
Michał Mirosław02b3a552011-11-15 15:29:55 +0000285 changed = (features ^ dev->features) & ETH_ALL_FEATURES;
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000286 if (changed & ~dev->hw_features)
287 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
288
289 dev->wanted_features =
Michał Mirosław02b3a552011-11-15 15:29:55 +0000290 (dev->wanted_features & ~changed) | (features & changed);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000291
Michał Mirosław6cb6a272011-04-02 22:48:47 -0700292 __netdev_update_features(dev);
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000293
294 return 0;
295}
296
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000297int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000299 ASSERT_RTNL();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000301 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return -EOPNOTSUPP;
303
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000304 memset(cmd, 0, sizeof(struct ethtool_cmd));
305 cmd->cmd = ETHTOOL_GSET;
306 return dev->ethtool_ops->get_settings(dev, cmd);
307}
308EXPORT_SYMBOL(__ethtool_get_settings);
309
310static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
311{
312 int err;
313 struct ethtool_cmd cmd;
314
315 err = __ethtool_get_settings(dev, &cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (err < 0)
317 return err;
318
319 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
320 return -EFAULT;
321 return 0;
322}
323
324static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
325{
326 struct ethtool_cmd cmd;
327
328 if (!dev->ethtool_ops->set_settings)
329 return -EOPNOTSUPP;
330
331 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
332 return -EFAULT;
333
334 return dev->ethtool_ops->set_settings(dev, &cmd);
335}
336
chavey97f8aef2010-04-07 21:54:42 -0700337static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
338 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
340 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700341 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 memset(&info, 0, sizeof(info));
344 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700345 if (ops && ops->get_drvinfo) {
346 ops->get_drvinfo(dev, &info);
347 } else if (dev->dev.parent && dev->dev.parent->driver) {
348 strlcpy(info.bus_info, dev_name(dev->dev.parent),
349 sizeof(info.bus_info));
350 strlcpy(info.driver, dev->dev.parent->driver->name,
351 sizeof(info.driver));
352 } else {
353 return -EOPNOTSUPP;
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Jeff Garzik723b2f52010-03-03 22:51:50 +0000356 /*
357 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000358 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000359 */
Ben Hutchings01414802010-08-17 02:31:15 -0700360 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700361 int rc;
362
363 rc = ops->get_sset_count(dev, ETH_SS_TEST);
364 if (rc >= 0)
365 info.testinfo_len = rc;
366 rc = ops->get_sset_count(dev, ETH_SS_STATS);
367 if (rc >= 0)
368 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700369 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
370 if (rc >= 0)
371 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700372 }
Ben Hutchings01414802010-08-17 02:31:15 -0700373 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700375 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 info.eedump_len = ops->get_eeprom_len(dev);
377
378 if (copy_to_user(useraddr, &info, sizeof(info)))
379 return -EFAULT;
380 return 0;
381}
382
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800383static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700384 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000385{
386 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000387 u64 sset_mask;
388 int i, idx = 0, n_bits = 0, ret, rc;
389 u32 *info_buf = NULL;
390
Jeff Garzik723b2f52010-03-03 22:51:50 +0000391 if (copy_from_user(&info, useraddr, sizeof(info)))
392 return -EFAULT;
393
394 /* store copy of mask, because we zero struct later on */
395 sset_mask = info.sset_mask;
396 if (!sset_mask)
397 return 0;
398
399 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000400 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000401
402 memset(&info, 0, sizeof(info));
403 info.cmd = ETHTOOL_GSSET_INFO;
404
405 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
406 if (!info_buf)
407 return -ENOMEM;
408
409 /*
410 * fill return buffer based on input bitmask and successful
411 * get_sset_count return
412 */
413 for (i = 0; i < 64; i++) {
414 if (!(sset_mask & (1ULL << i)))
415 continue;
416
Michał Mirosław340ae162011-02-15 16:59:16 +0000417 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000418 if (rc >= 0) {
419 info.sset_mask |= (1ULL << i);
420 info_buf[idx++] = rc;
421 }
422 }
423
424 ret = -EFAULT;
425 if (copy_to_user(useraddr, &info, sizeof(info)))
426 goto out;
427
428 useraddr += offsetof(struct ethtool_sset_info, data);
429 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
430 goto out;
431
432 ret = 0;
433
434out:
435 kfree(info_buf);
436 return ret;
437}
438
chavey97f8aef2010-04-07 21:54:42 -0700439static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000440 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700441{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000442 struct ethtool_rxnfc info;
443 size_t info_size = sizeof(info);
Ben Hutchings55664f32012-01-03 12:04:51 +0000444 int rc;
Santwona Behera0853ad62008-07-02 03:47:41 -0700445
Santwona Behera59089d82009-02-20 00:58:13 -0800446 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700447 return -EOPNOTSUPP;
448
Ben Hutchingsbf988432010-06-28 08:45:58 +0000449 /* struct ethtool_rxnfc was originally defined for
450 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
451 * members. User-space might still be using that
452 * definition. */
453 if (cmd == ETHTOOL_SRXFH)
454 info_size = (offsetof(struct ethtool_rxnfc, data) +
455 sizeof(info.data));
456
457 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700458 return -EFAULT;
459
Ben Hutchings55664f32012-01-03 12:04:51 +0000460 rc = dev->ethtool_ops->set_rxnfc(dev, &info);
461 if (rc)
462 return rc;
463
464 if (cmd == ETHTOOL_SRXCLSRLINS &&
465 copy_to_user(useraddr, &info, info_size))
466 return -EFAULT;
467
468 return 0;
Santwona Behera0853ad62008-07-02 03:47:41 -0700469}
470
chavey97f8aef2010-04-07 21:54:42 -0700471static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000472 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700473{
474 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000475 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800476 const struct ethtool_ops *ops = dev->ethtool_ops;
477 int ret;
478 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700479
Santwona Behera59089d82009-02-20 00:58:13 -0800480 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700481 return -EOPNOTSUPP;
482
Ben Hutchingsbf988432010-06-28 08:45:58 +0000483 /* struct ethtool_rxnfc was originally defined for
484 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
485 * members. User-space might still be using that
486 * definition. */
487 if (cmd == ETHTOOL_GRXFH)
488 info_size = (offsetof(struct ethtool_rxnfc, data) +
489 sizeof(info.data));
490
491 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700492 return -EFAULT;
493
Santwona Behera59089d82009-02-20 00:58:13 -0800494 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
495 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000496 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000497 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000498 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800499 if (!rule_buf)
500 return -ENOMEM;
501 }
502 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700503
Santwona Behera59089d82009-02-20 00:58:13 -0800504 ret = ops->get_rxnfc(dev, &info, rule_buf);
505 if (ret < 0)
506 goto err_out;
507
508 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000509 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800510 goto err_out;
511
512 if (rule_buf) {
513 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
514 if (copy_to_user(useraddr, rule_buf,
515 info.rule_cnt * sizeof(u32)))
516 goto err_out;
517 }
518 ret = 0;
519
520err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700521 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800522
523 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700524}
525
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000526static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
527 void __user *useraddr)
528{
Ben Hutchings7850f632011-12-15 13:55:01 +0000529 u32 user_size, dev_size;
530 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000531 int ret;
532
Ben Hutchings7850f632011-12-15 13:55:01 +0000533 if (!dev->ethtool_ops->get_rxfh_indir_size ||
534 !dev->ethtool_ops->get_rxfh_indir)
535 return -EOPNOTSUPP;
536 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
537 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000538 return -EOPNOTSUPP;
539
Ben Hutchings7850f632011-12-15 13:55:01 +0000540 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000541 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000542 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000543 return -EFAULT;
544
Ben Hutchings7850f632011-12-15 13:55:01 +0000545 if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
546 &dev_size, sizeof(dev_size)))
547 return -EFAULT;
548
549 /* If the user buffer size is 0, this is just a query for the
550 * device table size. Otherwise, if it's smaller than the
551 * device table size it's an error.
552 */
553 if (user_size < dev_size)
554 return user_size == 0 ? 0 : -EINVAL;
555
556 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000557 if (!indir)
558 return -ENOMEM;
559
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000560 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
561 if (ret)
562 goto out;
563
Ben Hutchings7850f632011-12-15 13:55:01 +0000564 if (copy_to_user(useraddr +
565 offsetof(struct ethtool_rxfh_indir, ring_index[0]),
566 indir, dev_size * sizeof(indir[0])))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000567 ret = -EFAULT;
568
569out:
570 kfree(indir);
571 return ret;
572}
573
574static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
575 void __user *useraddr)
576{
Ben Hutchings7850f632011-12-15 13:55:01 +0000577 struct ethtool_rxnfc rx_rings;
578 u32 user_size, dev_size, i;
579 u32 *indir;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000580 int ret;
581
Ben Hutchings7850f632011-12-15 13:55:01 +0000582 if (!dev->ethtool_ops->get_rxfh_indir_size ||
583 !dev->ethtool_ops->set_rxfh_indir ||
584 !dev->ethtool_ops->get_rxnfc)
585 return -EOPNOTSUPP;
586 dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
587 if (dev_size == 0)
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000588 return -EOPNOTSUPP;
589
Ben Hutchings7850f632011-12-15 13:55:01 +0000590 if (copy_from_user(&user_size,
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000591 useraddr + offsetof(struct ethtool_rxfh_indir, size),
Ben Hutchings7850f632011-12-15 13:55:01 +0000592 sizeof(user_size)))
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000593 return -EFAULT;
594
Ben Hutchings278bc422011-12-15 13:56:49 +0000595 if (user_size != 0 && user_size != dev_size)
Ben Hutchings7850f632011-12-15 13:55:01 +0000596 return -EINVAL;
597
598 indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000599 if (!indir)
600 return -ENOMEM;
601
Ben Hutchings7850f632011-12-15 13:55:01 +0000602 rx_rings.cmd = ETHTOOL_GRXRINGS;
603 ret = dev->ethtool_ops->get_rxnfc(dev, &rx_rings, NULL);
604 if (ret)
605 goto out;
Ben Hutchings278bc422011-12-15 13:56:49 +0000606
607 if (user_size == 0) {
608 for (i = 0; i < dev_size; i++)
609 indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
610 } else {
611 if (copy_from_user(indir,
612 useraddr +
613 offsetof(struct ethtool_rxfh_indir,
614 ring_index[0]),
615 dev_size * sizeof(indir[0]))) {
616 ret = -EFAULT;
Ben Hutchings7850f632011-12-15 13:55:01 +0000617 goto out;
618 }
Ben Hutchings278bc422011-12-15 13:56:49 +0000619
620 /* Validate ring indices */
621 for (i = 0; i < dev_size; i++) {
622 if (indir[i] >= rx_rings.data) {
623 ret = -EINVAL;
624 goto out;
625 }
626 }
Ben Hutchings7850f632011-12-15 13:55:01 +0000627 }
628
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000629 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
630
631out:
632 kfree(indir);
633 return ret;
634}
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
637{
638 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700639 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 void *regbuf;
641 int reglen, ret;
642
643 if (!ops->get_regs || !ops->get_regs_len)
644 return -EOPNOTSUPP;
645
646 if (copy_from_user(&regs, useraddr, sizeof(regs)))
647 return -EFAULT;
648
649 reglen = ops->get_regs_len(dev);
650 if (regs.len > reglen)
651 regs.len = reglen;
652
Eugene Teob7c7d012011-01-24 21:05:17 -0800653 regbuf = vzalloc(reglen);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700654 if (reglen && !regbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return -ENOMEM;
656
657 ops->get_regs(dev, &regs, regbuf);
658
659 ret = -EFAULT;
660 if (copy_to_user(useraddr, &regs, sizeof(regs)))
661 goto out;
662 useraddr += offsetof(struct ethtool_regs, data);
Ben Hutchings67ae7cf2011-07-21 15:25:30 -0700663 if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 goto out;
665 ret = 0;
666
667 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +0000668 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 return ret;
670}
671
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000672static int ethtool_reset(struct net_device *dev, char __user *useraddr)
673{
674 struct ethtool_value reset;
675 int ret;
676
677 if (!dev->ethtool_ops->reset)
678 return -EOPNOTSUPP;
679
680 if (copy_from_user(&reset, useraddr, sizeof(reset)))
681 return -EFAULT;
682
683 ret = dev->ethtool_ops->reset(dev, &reset.data);
684 if (ret)
685 return ret;
686
687 if (copy_to_user(useraddr, &reset, sizeof(reset)))
688 return -EFAULT;
689 return 0;
690}
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
693{
Roland Dreier8e557422010-02-11 12:14:23 -0800694 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 if (!dev->ethtool_ops->get_wol)
697 return -EOPNOTSUPP;
698
699 dev->ethtool_ops->get_wol(dev, &wol);
700
701 if (copy_to_user(useraddr, &wol, sizeof(wol)))
702 return -EFAULT;
703 return 0;
704}
705
706static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
707{
708 struct ethtool_wolinfo wol;
709
710 if (!dev->ethtool_ops->set_wol)
711 return -EOPNOTSUPP;
712
713 if (copy_from_user(&wol, useraddr, sizeof(wol)))
714 return -EFAULT;
715
716 return dev->ethtool_ops->set_wol(dev, &wol);
717}
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719static int ethtool_nway_reset(struct net_device *dev)
720{
721 if (!dev->ethtool_ops->nway_reset)
722 return -EOPNOTSUPP;
723
724 return dev->ethtool_ops->nway_reset(dev);
725}
726
Ben Hutchingse596e6e2010-12-09 12:08:35 +0000727static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
728{
729 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
730
731 if (!dev->ethtool_ops->get_link)
732 return -EOPNOTSUPP;
733
734 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
735
736 if (copy_to_user(useraddr, &edata, sizeof(edata)))
737 return -EFAULT;
738 return 0;
739}
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
742{
743 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700744 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700745 void __user *userbuf = useraddr + sizeof(eeprom);
746 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700748 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 if (!ops->get_eeprom || !ops->get_eeprom_len)
751 return -EOPNOTSUPP;
752
753 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
754 return -EFAULT;
755
756 /* Check for wrap and zero */
757 if (eeprom.offset + eeprom.len <= eeprom.offset)
758 return -EINVAL;
759
760 /* Check for exceeding total eeprom len */
761 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
762 return -EINVAL;
763
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700764 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 if (!data)
766 return -ENOMEM;
767
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700768 bytes_remaining = eeprom.len;
769 while (bytes_remaining > 0) {
770 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700772 ret = ops->get_eeprom(dev, &eeprom, data);
773 if (ret)
774 break;
775 if (copy_to_user(userbuf, data, eeprom.len)) {
776 ret = -EFAULT;
777 break;
778 }
779 userbuf += eeprom.len;
780 eeprom.offset += eeprom.len;
781 bytes_remaining -= eeprom.len;
782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700784 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
785 eeprom.offset -= eeprom.len;
786 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
787 ret = -EFAULT;
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 kfree(data);
790 return ret;
791}
792
793static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
794{
795 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700796 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700797 void __user *userbuf = useraddr + sizeof(eeprom);
798 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700800 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 if (!ops->set_eeprom || !ops->get_eeprom_len)
803 return -EOPNOTSUPP;
804
805 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
806 return -EFAULT;
807
808 /* Check for wrap and zero */
809 if (eeprom.offset + eeprom.len <= eeprom.offset)
810 return -EINVAL;
811
812 /* Check for exceeding total eeprom len */
813 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
814 return -EINVAL;
815
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700816 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 if (!data)
818 return -ENOMEM;
819
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700820 bytes_remaining = eeprom.len;
821 while (bytes_remaining > 0) {
822 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700824 if (copy_from_user(data, userbuf, eeprom.len)) {
825 ret = -EFAULT;
826 break;
827 }
828 ret = ops->set_eeprom(dev, &eeprom, data);
829 if (ret)
830 break;
831 userbuf += eeprom.len;
832 eeprom.offset += eeprom.len;
833 bytes_remaining -= eeprom.len;
834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 kfree(data);
837 return ret;
838}
839
chavey97f8aef2010-04-07 21:54:42 -0700840static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
841 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Roland Dreier8e557422010-02-11 12:14:23 -0800843 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 if (!dev->ethtool_ops->get_coalesce)
846 return -EOPNOTSUPP;
847
848 dev->ethtool_ops->get_coalesce(dev, &coalesce);
849
850 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
851 return -EFAULT;
852 return 0;
853}
854
chavey97f8aef2010-04-07 21:54:42 -0700855static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
856 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 struct ethtool_coalesce coalesce;
859
David S. Millerfa04ae52005-06-06 15:07:19 -0700860 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 return -EOPNOTSUPP;
862
863 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
864 return -EFAULT;
865
866 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
867}
868
869static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
870{
Roland Dreier8e557422010-02-11 12:14:23 -0800871 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 if (!dev->ethtool_ops->get_ringparam)
874 return -EOPNOTSUPP;
875
876 dev->ethtool_ops->get_ringparam(dev, &ringparam);
877
878 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
879 return -EFAULT;
880 return 0;
881}
882
883static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
884{
885 struct ethtool_ringparam ringparam;
886
887 if (!dev->ethtool_ops->set_ringparam)
888 return -EOPNOTSUPP;
889
890 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
891 return -EFAULT;
892
893 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
894}
895
amit salecha8b5933c2011-04-07 01:58:42 +0000896static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
897 void __user *useraddr)
898{
899 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
900
901 if (!dev->ethtool_ops->get_channels)
902 return -EOPNOTSUPP;
903
904 dev->ethtool_ops->get_channels(dev, &channels);
905
906 if (copy_to_user(useraddr, &channels, sizeof(channels)))
907 return -EFAULT;
908 return 0;
909}
910
911static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
912 void __user *useraddr)
913{
914 struct ethtool_channels channels;
915
916 if (!dev->ethtool_ops->set_channels)
917 return -EOPNOTSUPP;
918
919 if (copy_from_user(&channels, useraddr, sizeof(channels)))
920 return -EFAULT;
921
922 return dev->ethtool_ops->set_channels(dev, &channels);
923}
924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
926{
927 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
928
929 if (!dev->ethtool_ops->get_pauseparam)
930 return -EOPNOTSUPP;
931
932 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
933
934 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
935 return -EFAULT;
936 return 0;
937}
938
939static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
940{
941 struct ethtool_pauseparam pauseparam;
942
Jeff Garzike1b90c42006-07-17 12:54:40 -0400943 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 return -EOPNOTSUPP;
945
946 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
947 return -EFAULT;
948
949 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
950}
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
953{
954 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700955 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700957 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000959 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700960 return -EOPNOTSUPP;
961
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000962 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700963 if (test_len < 0)
964 return test_len;
965 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 if (copy_from_user(&test, useraddr, sizeof(test)))
968 return -EFAULT;
969
Jeff Garzikff03d492007-08-15 16:01:08 -0700970 test.len = test_len;
971 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (!data)
973 return -ENOMEM;
974
975 ops->self_test(dev, &test, data);
976
977 ret = -EFAULT;
978 if (copy_to_user(useraddr, &test, sizeof(test)))
979 goto out;
980 useraddr += sizeof(test);
981 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
982 goto out;
983 ret = 0;
984
985 out:
986 kfree(data);
987 return ret;
988}
989
990static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
991{
992 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 u8 *data;
994 int ret;
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
997 return -EFAULT;
998
Michał Mirosław340ae162011-02-15 16:59:16 +0000999 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001000 if (ret < 0)
1001 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001002
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001003 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1006 if (!data)
1007 return -ENOMEM;
1008
Michał Mirosław340ae162011-02-15 16:59:16 +00001009 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 ret = -EFAULT;
1012 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1013 goto out;
1014 useraddr += sizeof(gstrings);
1015 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1016 goto out;
1017 ret = 0;
1018
Michał Mirosław340ae162011-02-15 16:59:16 +00001019out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 kfree(data);
1021 return ret;
1022}
1023
1024static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1025{
1026 struct ethtool_value id;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001027 static bool busy;
1028 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Stephen Hemminger1ab7b6a2011-04-14 23:46:06 -07001030 if (!dev->ethtool_ops->set_phys_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return -EOPNOTSUPP;
1032
Ben Hutchings68f512f2011-04-02 00:35:15 +01001033 if (busy)
1034 return -EBUSY;
1035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (copy_from_user(&id, useraddr, sizeof(id)))
1037 return -EFAULT;
1038
Ben Hutchings68f512f2011-04-02 00:35:15 +01001039 rc = dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001040 if (rc < 0)
Ben Hutchings68f512f2011-04-02 00:35:15 +01001041 return rc;
1042
1043 /* Drop the RTNL lock while waiting, but prevent reentry or
1044 * removal of the device.
1045 */
1046 busy = true;
1047 dev_hold(dev);
1048 rtnl_unlock();
1049
1050 if (rc == 0) {
1051 /* Driver will handle this itself */
1052 schedule_timeout_interruptible(
Allan, Bruce W143780c2011-04-11 13:01:59 +00001053 id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001054 } else {
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001055 /* Driver expects to be called at twice the frequency in rc */
1056 int n = rc * 2, i, interval = HZ / n;
Ben Hutchings68f512f2011-04-02 00:35:15 +01001057
Allan, Bruce Wfce55922011-04-13 13:09:10 +00001058 /* Count down seconds */
1059 do {
1060 /* Count down iterations per second */
1061 i = n;
1062 do {
1063 rtnl_lock();
1064 rc = dev->ethtool_ops->set_phys_id(dev,
1065 (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
1066 rtnl_unlock();
1067 if (rc)
1068 break;
1069 schedule_timeout_interruptible(interval);
1070 } while (!signal_pending(current) && --i != 0);
Ben Hutchings68f512f2011-04-02 00:35:15 +01001071 } while (!signal_pending(current) &&
1072 (id.data == 0 || --id.data != 0));
1073 }
1074
1075 rtnl_lock();
1076 dev_put(dev);
1077 busy = false;
1078
1079 (void)dev->ethtool_ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
1080 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
1083static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1084{
1085 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001086 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001088 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001090 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001091 return -EOPNOTSUPP;
1092
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001093 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001094 if (n_stats < 0)
1095 return n_stats;
1096 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1099 return -EFAULT;
1100
Jeff Garzikff03d492007-08-15 16:01:08 -07001101 stats.n_stats = n_stats;
1102 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (!data)
1104 return -ENOMEM;
1105
1106 ops->get_ethtool_stats(dev, &stats, data);
1107
1108 ret = -EFAULT;
1109 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1110 goto out;
1111 useraddr += sizeof(stats);
1112 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1113 goto out;
1114 ret = 0;
1115
1116 out:
1117 kfree(data);
1118 return ret;
1119}
1120
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001121static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001122{
1123 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001124
Matthew Wilcox313674a2007-07-31 14:00:29 -07001125 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001126 return -EFAULT;
1127
Matthew Wilcox313674a2007-07-31 14:00:29 -07001128 if (epaddr.size < dev->addr_len)
1129 return -ETOOSMALL;
1130 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001131
Jon Wetzela6f9a702005-08-20 17:15:54 -07001132 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001133 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001134 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001135 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1136 return -EFAULT;
1137 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001138}
1139
Jeff Garzik13c99b22007-08-15 16:01:56 -07001140static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1141 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001142{
Roland Dreier8e557422010-02-11 12:14:23 -08001143 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001144
Jeff Garzik13c99b22007-08-15 16:01:56 -07001145 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001146 return -EOPNOTSUPP;
1147
Jeff Garzik13c99b22007-08-15 16:01:56 -07001148 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001149
1150 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1151 return -EFAULT;
1152 return 0;
1153}
1154
Jeff Garzik13c99b22007-08-15 16:01:56 -07001155static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1156 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001157{
1158 struct ethtool_value edata;
1159
Jeff Garzik13c99b22007-08-15 16:01:56 -07001160 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001161 return -EOPNOTSUPP;
1162
1163 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1164 return -EFAULT;
1165
Jeff Garzik13c99b22007-08-15 16:01:56 -07001166 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001167 return 0;
1168}
1169
Jeff Garzik13c99b22007-08-15 16:01:56 -07001170static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1171 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001172{
1173 struct ethtool_value edata;
1174
Jeff Garzik13c99b22007-08-15 16:01:56 -07001175 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001176 return -EOPNOTSUPP;
1177
1178 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1179 return -EFAULT;
1180
Jeff Garzik13c99b22007-08-15 16:01:56 -07001181 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001182}
1183
chavey97f8aef2010-04-07 21:54:42 -07001184static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1185 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001186{
1187 struct ethtool_flash efl;
1188
1189 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1190 return -EFAULT;
1191
1192 if (!dev->ethtool_ops->flash_device)
1193 return -EOPNOTSUPP;
1194
Ben Hutchings786f5282012-02-01 09:32:25 +00001195 efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
1196
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001197 return dev->ethtool_ops->flash_device(dev, &efl);
1198}
1199
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001200static int ethtool_set_dump(struct net_device *dev,
1201 void __user *useraddr)
1202{
1203 struct ethtool_dump dump;
1204
1205 if (!dev->ethtool_ops->set_dump)
1206 return -EOPNOTSUPP;
1207
1208 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1209 return -EFAULT;
1210
1211 return dev->ethtool_ops->set_dump(dev, &dump);
1212}
1213
1214static int ethtool_get_dump_flag(struct net_device *dev,
1215 void __user *useraddr)
1216{
1217 int ret;
1218 struct ethtool_dump dump;
1219 const struct ethtool_ops *ops = dev->ethtool_ops;
1220
1221 if (!dev->ethtool_ops->get_dump_flag)
1222 return -EOPNOTSUPP;
1223
1224 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1225 return -EFAULT;
1226
1227 ret = ops->get_dump_flag(dev, &dump);
1228 if (ret)
1229 return ret;
1230
1231 if (copy_to_user(useraddr, &dump, sizeof(dump)))
1232 return -EFAULT;
1233 return 0;
1234}
1235
1236static int ethtool_get_dump_data(struct net_device *dev,
1237 void __user *useraddr)
1238{
1239 int ret;
1240 __u32 len;
1241 struct ethtool_dump dump, tmp;
1242 const struct ethtool_ops *ops = dev->ethtool_ops;
1243 void *data = NULL;
1244
1245 if (!dev->ethtool_ops->get_dump_data ||
1246 !dev->ethtool_ops->get_dump_flag)
1247 return -EOPNOTSUPP;
1248
1249 if (copy_from_user(&dump, useraddr, sizeof(dump)))
1250 return -EFAULT;
1251
1252 memset(&tmp, 0, sizeof(tmp));
1253 tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
1254 ret = ops->get_dump_flag(dev, &tmp);
1255 if (ret)
1256 return ret;
1257
1258 len = (tmp.len > dump.len) ? dump.len : tmp.len;
1259 if (!len)
1260 return -EFAULT;
1261
1262 data = vzalloc(tmp.len);
1263 if (!data)
1264 return -ENOMEM;
1265 ret = ops->get_dump_data(dev, &dump, data);
1266 if (ret)
1267 goto out;
1268
1269 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1270 ret = -EFAULT;
1271 goto out;
1272 }
1273 useraddr += offsetof(struct ethtool_dump, data);
1274 if (copy_to_user(useraddr, data, len))
1275 ret = -EFAULT;
1276out:
1277 vfree(data);
1278 return ret;
1279}
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281/* The main entry point in this file. Called from net/core/dev.c */
1282
Eric W. Biederman881d9662007-09-17 11:56:21 -07001283int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001285 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 void __user *useraddr = ifr->ifr_data;
1287 u32 ethcmd;
1288 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001289 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 if (!dev || !netif_device_present(dev))
1292 return -ENODEV;
1293
chavey97f8aef2010-04-07 21:54:42 -07001294 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 return -EFAULT;
1296
Ben Hutchings01414802010-08-17 02:31:15 -07001297 if (!dev->ethtool_ops) {
1298 /* ETHTOOL_GDRVINFO does not require any driver support.
1299 * It is also unprivileged and does not change anything,
1300 * so we can take a shortcut to it. */
1301 if (ethcmd == ETHTOOL_GDRVINFO)
1302 return ethtool_get_drvinfo(dev, useraddr);
1303 else
1304 return -EOPNOTSUPP;
1305 }
1306
Stephen Hemminger75f31232006-09-28 15:13:37 -07001307 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001308 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001309 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001310 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001311 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001312 case ETHTOOL_GCOALESCE:
1313 case ETHTOOL_GRINGPARAM:
1314 case ETHTOOL_GPAUSEPARAM:
1315 case ETHTOOL_GRXCSUM:
1316 case ETHTOOL_GTXCSUM:
1317 case ETHTOOL_GSG:
Michał Mirosławf80400a2012-01-22 00:20:40 +00001318 case ETHTOOL_GSSET_INFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001319 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001320 case ETHTOOL_GTSO:
1321 case ETHTOOL_GPERMADDR:
1322 case ETHTOOL_GUFO:
1323 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001324 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001325 case ETHTOOL_GFLAGS:
1326 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001327 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001328 case ETHTOOL_GRXRINGS:
1329 case ETHTOOL_GRXCLSRLCNT:
1330 case ETHTOOL_GRXCLSRULE:
1331 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001332 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001333 break;
1334 default:
1335 if (!capable(CAP_NET_ADMIN))
1336 return -EPERM;
1337 }
1338
chavey97f8aef2010-04-07 21:54:42 -07001339 if (dev->ethtool_ops->begin) {
1340 rc = dev->ethtool_ops->begin(dev);
1341 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001343 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001344 old_features = dev->features;
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 switch (ethcmd) {
1347 case ETHTOOL_GSET:
1348 rc = ethtool_get_settings(dev, useraddr);
1349 break;
1350 case ETHTOOL_SSET:
1351 rc = ethtool_set_settings(dev, useraddr);
1352 break;
1353 case ETHTOOL_GDRVINFO:
1354 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 break;
1356 case ETHTOOL_GREGS:
1357 rc = ethtool_get_regs(dev, useraddr);
1358 break;
1359 case ETHTOOL_GWOL:
1360 rc = ethtool_get_wol(dev, useraddr);
1361 break;
1362 case ETHTOOL_SWOL:
1363 rc = ethtool_set_wol(dev, useraddr);
1364 break;
1365 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001366 rc = ethtool_get_value(dev, useraddr, ethcmd,
1367 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 break;
1369 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001370 rc = ethtool_set_value_void(dev, useraddr,
1371 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 break;
1373 case ETHTOOL_NWAY_RST:
1374 rc = ethtool_nway_reset(dev);
1375 break;
1376 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001377 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 break;
1379 case ETHTOOL_GEEPROM:
1380 rc = ethtool_get_eeprom(dev, useraddr);
1381 break;
1382 case ETHTOOL_SEEPROM:
1383 rc = ethtool_set_eeprom(dev, useraddr);
1384 break;
1385 case ETHTOOL_GCOALESCE:
1386 rc = ethtool_get_coalesce(dev, useraddr);
1387 break;
1388 case ETHTOOL_SCOALESCE:
1389 rc = ethtool_set_coalesce(dev, useraddr);
1390 break;
1391 case ETHTOOL_GRINGPARAM:
1392 rc = ethtool_get_ringparam(dev, useraddr);
1393 break;
1394 case ETHTOOL_SRINGPARAM:
1395 rc = ethtool_set_ringparam(dev, useraddr);
1396 break;
1397 case ETHTOOL_GPAUSEPARAM:
1398 rc = ethtool_get_pauseparam(dev, useraddr);
1399 break;
1400 case ETHTOOL_SPAUSEPARAM:
1401 rc = ethtool_set_pauseparam(dev, useraddr);
1402 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 case ETHTOOL_TEST:
1404 rc = ethtool_self_test(dev, useraddr);
1405 break;
1406 case ETHTOOL_GSTRINGS:
1407 rc = ethtool_get_strings(dev, useraddr);
1408 break;
1409 case ETHTOOL_PHYS_ID:
1410 rc = ethtool_phys_id(dev, useraddr);
1411 break;
1412 case ETHTOOL_GSTATS:
1413 rc = ethtool_get_stats(dev, useraddr);
1414 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001415 case ETHTOOL_GPERMADDR:
1416 rc = ethtool_get_perm_addr(dev, useraddr);
1417 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001418 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001419 rc = ethtool_get_value(dev, useraddr, ethcmd,
Michał Mirosławbc5787c62011-11-15 15:29:55 +00001420 __ethtool_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001421 break;
1422 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001423 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001424 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001425 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001426 rc = ethtool_get_value(dev, useraddr, ethcmd,
1427 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001428 break;
1429 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001430 rc = ethtool_set_value(dev, useraddr,
1431 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001432 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001433 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001434 case ETHTOOL_GRXRINGS:
1435 case ETHTOOL_GRXCLSRLCNT:
1436 case ETHTOOL_GRXCLSRULE:
1437 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001438 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001439 break;
1440 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001441 case ETHTOOL_SRXCLSRLDEL:
1442 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001443 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001444 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001445 case ETHTOOL_FLASHDEV:
1446 rc = ethtool_flash_device(dev, useraddr);
1447 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001448 case ETHTOOL_RESET:
1449 rc = ethtool_reset(dev, useraddr);
1450 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001451 case ETHTOOL_GSSET_INFO:
1452 rc = ethtool_get_sset_info(dev, useraddr);
1453 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001454 case ETHTOOL_GRXFHINDIR:
1455 rc = ethtool_get_rxfh_indir(dev, useraddr);
1456 break;
1457 case ETHTOOL_SRXFHINDIR:
1458 rc = ethtool_set_rxfh_indir(dev, useraddr);
1459 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001460 case ETHTOOL_GFEATURES:
1461 rc = ethtool_get_features(dev, useraddr);
1462 break;
1463 case ETHTOOL_SFEATURES:
1464 rc = ethtool_set_features(dev, useraddr);
1465 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001466 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001467 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001468 case ETHTOOL_GSG:
1469 case ETHTOOL_GTSO:
1470 case ETHTOOL_GUFO:
1471 case ETHTOOL_GGSO:
1472 case ETHTOOL_GGRO:
1473 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1474 break;
1475 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001476 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001477 case ETHTOOL_SSG:
1478 case ETHTOOL_STSO:
1479 case ETHTOOL_SUFO:
1480 case ETHTOOL_SGSO:
1481 case ETHTOOL_SGRO:
1482 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1483 break;
amit salecha8b5933c2011-04-07 01:58:42 +00001484 case ETHTOOL_GCHANNELS:
1485 rc = ethtool_get_channels(dev, useraddr);
1486 break;
1487 case ETHTOOL_SCHANNELS:
1488 rc = ethtool_set_channels(dev, useraddr);
1489 break;
Anirban Chakraborty29dd54b2011-05-12 12:48:32 +00001490 case ETHTOOL_SET_DUMP:
1491 rc = ethtool_set_dump(dev, useraddr);
1492 break;
1493 case ETHTOOL_GET_DUMP_FLAG:
1494 rc = ethtool_get_dump_flag(dev, useraddr);
1495 break;
1496 case ETHTOOL_GET_DUMP_DATA:
1497 rc = ethtool_get_dump_data(dev, useraddr);
1498 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001500 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001502
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001503 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001505
1506 if (old_features != dev->features)
1507 netdev_features_change(dev);
1508
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}