blob: 65999974f7431c167e9950fb924905402701db6f [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090025/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 * Some useful ethtool_ops methods that're device independent.
27 * If we find that all drivers want to do the same thing here,
28 * we can turn these into dev_() function calls.
29 */
30
31u32 ethtool_op_get_link(struct net_device *dev)
32{
33 return netif_carrier_ok(dev) ? 1 : 0;
34}
chavey97f8aef2010-04-07 21:54:42 -070035EXPORT_SYMBOL(ethtool_op_get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Sridhar Samudrala1896e612009-07-22 13:38:22 +000037u32 ethtool_op_get_rx_csum(struct net_device *dev)
38{
39 return (dev->features & NETIF_F_ALL_CSUM) != 0;
40}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000041EXPORT_SYMBOL(ethtool_op_get_rx_csum);
Sridhar Samudrala1896e612009-07-22 13:38:22 +000042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043u32 ethtool_op_get_tx_csum(struct net_device *dev)
44{
Herbert Xu8648b302006-06-17 22:06:05 -070045 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000047EXPORT_SYMBOL(ethtool_op_get_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
50{
51 if (data)
52 dev->features |= NETIF_F_IP_CSUM;
53 else
54 dev->features &= ~NETIF_F_IP_CSUM;
55
56 return 0;
57}
Michał Mirosław9a279ea2011-02-15 16:59:16 +000058EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Jon Mason69f6a0f2005-05-29 20:27:24 -070060int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
61{
62 if (data)
63 dev->features |= NETIF_F_HW_CSUM;
64 else
65 dev->features &= ~NETIF_F_HW_CSUM;
66
67 return 0;
68}
chavey97f8aef2010-04-07 21:54:42 -070069EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -070070
71int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
72{
73 if (data)
74 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
75 else
76 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
77
78 return 0;
79}
chavey97f8aef2010-04-07 21:54:42 -070080EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Michael Chan6460d942007-07-14 19:07:52 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082u32 ethtool_op_get_sg(struct net_device *dev)
83{
84 return (dev->features & NETIF_F_SG) != 0;
85}
chavey97f8aef2010-04-07 21:54:42 -070086EXPORT_SYMBOL(ethtool_op_get_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88int ethtool_op_set_sg(struct net_device *dev, u32 data)
89{
90 if (data)
91 dev->features |= NETIF_F_SG;
92 else
93 dev->features &= ~NETIF_F_SG;
94
95 return 0;
96}
chavey97f8aef2010-04-07 21:54:42 -070097EXPORT_SYMBOL(ethtool_op_set_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99u32 ethtool_op_get_tso(struct net_device *dev)
100{
101 return (dev->features & NETIF_F_TSO) != 0;
102}
chavey97f8aef2010-04-07 21:54:42 -0700103EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105int ethtool_op_set_tso(struct net_device *dev, u32 data)
106{
107 if (data)
108 dev->features |= NETIF_F_TSO;
109 else
110 dev->features &= ~NETIF_F_TSO;
111
112 return 0;
113}
chavey97f8aef2010-04-07 21:54:42 -0700114EXPORT_SYMBOL(ethtool_op_set_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700116u32 ethtool_op_get_ufo(struct net_device *dev)
117{
118 return (dev->features & NETIF_F_UFO) != 0;
119}
chavey97f8aef2010-04-07 21:54:42 -0700120EXPORT_SYMBOL(ethtool_op_get_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700121
122int ethtool_op_set_ufo(struct net_device *dev, u32 data)
123{
124 if (data)
125 dev->features |= NETIF_F_UFO;
126 else
127 dev->features &= ~NETIF_F_UFO;
128 return 0;
129}
chavey97f8aef2010-04-07 21:54:42 -0700130EXPORT_SYMBOL(ethtool_op_set_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700131
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700132/* the following list of flags are the same as their associated
133 * NETIF_F_xxx values in include/linux/netdevice.h
134 */
135static const u32 flags_dup_features =
Jesse Grossd5dbda22010-10-20 13:56:07 +0000136 (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | ETH_FLAG_NTUPLE |
137 ETH_FLAG_RXHASH);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700138
139u32 ethtool_op_get_flags(struct net_device *dev)
140{
141 /* in the future, this function will probably contain additional
142 * handling for flags which are not so easily handled
143 * by a simple masking operation
144 */
145
146 return dev->features & flags_dup_features;
147}
chavey97f8aef2010-04-07 21:54:42 -0700148EXPORT_SYMBOL(ethtool_op_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700149
Ben Hutchings1437ce32010-06-30 02:44:32 +0000150int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700151{
Ben Hutchings1437ce32010-06-30 02:44:32 +0000152 if (data & ~supported)
153 return -EINVAL;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000154
Ben Hutchings1437ce32010-06-30 02:44:32 +0000155 dev->features = ((dev->features & ~flags_dup_features) |
156 (data & flags_dup_features));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700157 return 0;
158}
chavey97f8aef2010-04-07 21:54:42 -0700159EXPORT_SYMBOL(ethtool_op_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700160
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800161void ethtool_ntuple_flush(struct net_device *dev)
162{
163 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
164
165 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
166 list_del(&fsc->list);
167 kfree(fsc);
168 }
169 dev->ethtool_ntuple_list.count = 0;
170}
171EXPORT_SYMBOL(ethtool_ntuple_flush);
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* Handlers for each ethtool command */
174
Michał Mirosław5455c692011-02-15 16:59:17 +0000175#define ETHTOOL_DEV_FEATURE_WORDS 1
176
177static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
178{
179 struct ethtool_gfeatures cmd = {
180 .cmd = ETHTOOL_GFEATURES,
181 .size = ETHTOOL_DEV_FEATURE_WORDS,
182 };
183 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = {
184 {
185 .available = dev->hw_features,
186 .requested = dev->wanted_features,
187 .active = dev->features,
188 .never_changed = NETIF_F_NEVER_CHANGE,
189 },
190 };
191 u32 __user *sizeaddr;
192 u32 copy_size;
193
194 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
195 if (get_user(copy_size, sizeaddr))
196 return -EFAULT;
197
198 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
199 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
200
201 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
202 return -EFAULT;
203 useraddr += sizeof(cmd);
204 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
205 return -EFAULT;
206
207 return 0;
208}
209
210static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
211{
212 struct ethtool_sfeatures cmd;
213 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
214 int ret = 0;
215
216 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
217 return -EFAULT;
218 useraddr += sizeof(cmd);
219
220 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
221 return -EINVAL;
222
223 if (copy_from_user(features, useraddr, sizeof(features)))
224 return -EFAULT;
225
226 if (features[0].valid & ~NETIF_F_ETHTOOL_BITS)
227 return -EINVAL;
228
229 if (features[0].valid & ~dev->hw_features) {
230 features[0].valid &= dev->hw_features;
231 ret |= ETHTOOL_F_UNSUPPORTED;
232 }
233
234 dev->wanted_features &= ~features[0].valid;
235 dev->wanted_features |= features[0].valid & features[0].requested;
236 netdev_update_features(dev);
237
238 if ((dev->wanted_features ^ dev->features) & features[0].valid)
239 ret |= ETHTOOL_F_WISH;
240
241 return ret;
242}
243
244static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = {
245 /* NETIF_F_SG */ "tx-scatter-gather",
246 /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
247 /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
248 /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
249 /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6",
250 /* NETIF_F_HIGHDMA */ "highdma",
251 /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
252 /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
253
254 /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
255 /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
256 /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
257 /* NETIF_F_GSO */ "tx-generic-segmentation",
258 /* NETIF_F_LLTX */ "tx-lockless",
259 /* NETIF_F_NETNS_LOCAL */ "netns-local",
260 /* NETIF_F_GRO */ "rx-gro",
261 /* NETIF_F_LRO */ "rx-lro",
262
263 /* NETIF_F_TSO */ "tx-tcp-segmentation",
264 /* NETIF_F_UFO */ "tx-udp-fragmentation",
265 /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
266 /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
267 /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
268 /* NETIF_F_FSO */ "tx-fcoe-segmentation",
269 "",
270 "",
271
272 /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
273 /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
274 /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
275 /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
276 /* NETIF_F_RXHASH */ "rx-hashing",
277 "",
278 "",
279 "",
280};
281
Michał Mirosław340ae162011-02-15 16:59:16 +0000282static int __ethtool_get_sset_count(struct net_device *dev, int sset)
283{
284 const struct ethtool_ops *ops = dev->ethtool_ops;
285
Michał Mirosław5455c692011-02-15 16:59:17 +0000286 if (sset == ETH_SS_FEATURES)
287 return ARRAY_SIZE(netdev_features_strings);
288
Michał Mirosław340ae162011-02-15 16:59:16 +0000289 if (ops && ops->get_sset_count && ops->get_strings)
290 return ops->get_sset_count(dev, sset);
291 else
292 return -EOPNOTSUPP;
293}
294
295static void __ethtool_get_strings(struct net_device *dev,
296 u32 stringset, u8 *data)
297{
298 const struct ethtool_ops *ops = dev->ethtool_ops;
299
Michał Mirosław5455c692011-02-15 16:59:17 +0000300 if (stringset == ETH_SS_FEATURES)
301 memcpy(data, netdev_features_strings,
302 sizeof(netdev_features_strings));
303 else
304 /* ops->get_strings is valid because checked earlier */
305 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000306}
307
Michał Mirosław0a417702011-02-15 16:59:17 +0000308static u32 ethtool_get_feature_mask(u32 eth_cmd)
309{
310 /* feature masks of legacy discrete ethtool ops */
311
312 switch (eth_cmd) {
313 case ETHTOOL_GTXCSUM:
314 case ETHTOOL_STXCSUM:
315 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
316 case ETHTOOL_GSG:
317 case ETHTOOL_SSG:
318 return NETIF_F_SG;
319 case ETHTOOL_GTSO:
320 case ETHTOOL_STSO:
321 return NETIF_F_ALL_TSO;
322 case ETHTOOL_GUFO:
323 case ETHTOOL_SUFO:
324 return NETIF_F_UFO;
325 case ETHTOOL_GGSO:
326 case ETHTOOL_SGSO:
327 return NETIF_F_GSO;
328 case ETHTOOL_GGRO:
329 case ETHTOOL_SGRO:
330 return NETIF_F_GRO;
331 default:
332 BUG();
333 }
334}
335
336static void *__ethtool_get_one_feature_actor(struct net_device *dev, u32 ethcmd)
337{
338 const struct ethtool_ops *ops = dev->ethtool_ops;
339
340 if (!ops)
341 return NULL;
342
343 switch (ethcmd) {
344 case ETHTOOL_GTXCSUM:
345 return ops->get_tx_csum;
346 case ETHTOOL_SSG:
347 return ops->get_sg;
348 case ETHTOOL_STSO:
349 return ops->get_tso;
350 case ETHTOOL_SUFO:
351 return ops->get_ufo;
352 default:
353 return NULL;
354 }
355}
356
357static int ethtool_get_one_feature(struct net_device *dev,
358 char __user *useraddr, u32 ethcmd)
359{
Michał Mirosław86794882011-02-15 16:59:17 +0000360 u32 mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000361 struct ethtool_value edata = {
362 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000363 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000364 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000365
Michał Mirosław86794882011-02-15 16:59:17 +0000366 /* compatibility with discrete get_ ops */
367 if (!(dev->hw_features & mask)) {
368 u32 (*actor)(struct net_device *);
369
370 actor = __ethtool_get_one_feature_actor(dev, ethcmd);
371
372 if (actor)
373 edata.data = actor(dev);
374 }
Michał Mirosław0a417702011-02-15 16:59:17 +0000375
376 if (copy_to_user(useraddr, &edata, sizeof(edata)))
377 return -EFAULT;
378 return 0;
379}
380
381static int __ethtool_set_tx_csum(struct net_device *dev, u32 data);
382static int __ethtool_set_sg(struct net_device *dev, u32 data);
383static int __ethtool_set_tso(struct net_device *dev, u32 data);
384static int __ethtool_set_ufo(struct net_device *dev, u32 data);
385
386static int ethtool_set_one_feature(struct net_device *dev,
387 void __user *useraddr, u32 ethcmd)
388{
389 struct ethtool_value edata;
390 u32 mask;
391
392 if (copy_from_user(&edata, useraddr, sizeof(edata)))
393 return -EFAULT;
394
Michał Mirosław86794882011-02-15 16:59:17 +0000395 mask = ethtool_get_feature_mask(ethcmd);
396 mask &= dev->hw_features;
397 if (mask) {
398 if (edata.data)
399 dev->wanted_features |= mask;
400 else
401 dev->wanted_features &= ~mask;
402
403 netdev_update_features(dev);
404 return 0;
405 }
406
407 /* Driver is not converted to ndo_fix_features or does not
408 * support changing this offload. In the latter case it won't
409 * have corresponding ethtool_ops field set.
410 *
411 * Following part is to be removed after all drivers advertise
412 * their changeable features in netdev->hw_features and stop
413 * using discrete offload setting ops.
414 */
415
Michał Mirosław0a417702011-02-15 16:59:17 +0000416 switch (ethcmd) {
417 case ETHTOOL_STXCSUM:
418 return __ethtool_set_tx_csum(dev, edata.data);
419 case ETHTOOL_SSG:
420 return __ethtool_set_sg(dev, edata.data);
421 case ETHTOOL_STSO:
422 return __ethtool_set_tso(dev, edata.data);
423 case ETHTOOL_SUFO:
424 return __ethtool_set_ufo(dev, edata.data);
Michał Mirosław0a417702011-02-15 16:59:17 +0000425 default:
426 return -EOPNOTSUPP;
427 }
428}
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
431{
Roland Dreier8e557422010-02-11 12:14:23 -0800432 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 int err;
434
435 if (!dev->ethtool_ops->get_settings)
436 return -EOPNOTSUPP;
437
438 err = dev->ethtool_ops->get_settings(dev, &cmd);
439 if (err < 0)
440 return err;
441
442 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
443 return -EFAULT;
444 return 0;
445}
446
447static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
448{
449 struct ethtool_cmd cmd;
450
451 if (!dev->ethtool_ops->set_settings)
452 return -EOPNOTSUPP;
453
454 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
455 return -EFAULT;
456
457 return dev->ethtool_ops->set_settings(dev, &cmd);
458}
459
chavey97f8aef2010-04-07 21:54:42 -0700460static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
461 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700464 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 memset(&info, 0, sizeof(info));
467 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700468 if (ops && ops->get_drvinfo) {
469 ops->get_drvinfo(dev, &info);
470 } else if (dev->dev.parent && dev->dev.parent->driver) {
471 strlcpy(info.bus_info, dev_name(dev->dev.parent),
472 sizeof(info.bus_info));
473 strlcpy(info.driver, dev->dev.parent->driver->name,
474 sizeof(info.driver));
475 } else {
476 return -EOPNOTSUPP;
477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Jeff Garzik723b2f52010-03-03 22:51:50 +0000479 /*
480 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000481 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000482 */
Ben Hutchings01414802010-08-17 02:31:15 -0700483 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700484 int rc;
485
486 rc = ops->get_sset_count(dev, ETH_SS_TEST);
487 if (rc >= 0)
488 info.testinfo_len = rc;
489 rc = ops->get_sset_count(dev, ETH_SS_STATS);
490 if (rc >= 0)
491 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700492 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
493 if (rc >= 0)
494 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700495 }
Ben Hutchings01414802010-08-17 02:31:15 -0700496 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700498 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 info.eedump_len = ops->get_eeprom_len(dev);
500
501 if (copy_to_user(useraddr, &info, sizeof(info)))
502 return -EFAULT;
503 return 0;
504}
505
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800506static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700507 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000508{
509 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000510 u64 sset_mask;
511 int i, idx = 0, n_bits = 0, ret, rc;
512 u32 *info_buf = NULL;
513
Jeff Garzik723b2f52010-03-03 22:51:50 +0000514 if (copy_from_user(&info, useraddr, sizeof(info)))
515 return -EFAULT;
516
517 /* store copy of mask, because we zero struct later on */
518 sset_mask = info.sset_mask;
519 if (!sset_mask)
520 return 0;
521
522 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000523 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000524
525 memset(&info, 0, sizeof(info));
526 info.cmd = ETHTOOL_GSSET_INFO;
527
528 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
529 if (!info_buf)
530 return -ENOMEM;
531
532 /*
533 * fill return buffer based on input bitmask and successful
534 * get_sset_count return
535 */
536 for (i = 0; i < 64; i++) {
537 if (!(sset_mask & (1ULL << i)))
538 continue;
539
Michał Mirosław340ae162011-02-15 16:59:16 +0000540 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000541 if (rc >= 0) {
542 info.sset_mask |= (1ULL << i);
543 info_buf[idx++] = rc;
544 }
545 }
546
547 ret = -EFAULT;
548 if (copy_to_user(useraddr, &info, sizeof(info)))
549 goto out;
550
551 useraddr += offsetof(struct ethtool_sset_info, data);
552 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
553 goto out;
554
555 ret = 0;
556
557out:
558 kfree(info_buf);
559 return ret;
560}
561
chavey97f8aef2010-04-07 21:54:42 -0700562static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000563 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700564{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000565 struct ethtool_rxnfc info;
566 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700567
Santwona Behera59089d82009-02-20 00:58:13 -0800568 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700569 return -EOPNOTSUPP;
570
Ben Hutchingsbf988432010-06-28 08:45:58 +0000571 /* struct ethtool_rxnfc was originally defined for
572 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
573 * members. User-space might still be using that
574 * definition. */
575 if (cmd == ETHTOOL_SRXFH)
576 info_size = (offsetof(struct ethtool_rxnfc, data) +
577 sizeof(info.data));
578
579 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700580 return -EFAULT;
581
Ben Hutchingsbf988432010-06-28 08:45:58 +0000582 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700583}
584
chavey97f8aef2010-04-07 21:54:42 -0700585static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000586 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700587{
588 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000589 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800590 const struct ethtool_ops *ops = dev->ethtool_ops;
591 int ret;
592 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700593
Santwona Behera59089d82009-02-20 00:58:13 -0800594 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700595 return -EOPNOTSUPP;
596
Ben Hutchingsbf988432010-06-28 08:45:58 +0000597 /* struct ethtool_rxnfc was originally defined for
598 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
599 * members. User-space might still be using that
600 * definition. */
601 if (cmd == ETHTOOL_GRXFH)
602 info_size = (offsetof(struct ethtool_rxnfc, data) +
603 sizeof(info.data));
604
605 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700606 return -EFAULT;
607
Santwona Behera59089d82009-02-20 00:58:13 -0800608 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
609 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000610 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000611 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000612 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800613 if (!rule_buf)
614 return -ENOMEM;
615 }
616 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700617
Santwona Behera59089d82009-02-20 00:58:13 -0800618 ret = ops->get_rxnfc(dev, &info, rule_buf);
619 if (ret < 0)
620 goto err_out;
621
622 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000623 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800624 goto err_out;
625
626 if (rule_buf) {
627 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
628 if (copy_to_user(useraddr, rule_buf,
629 info.rule_cnt * sizeof(u32)))
630 goto err_out;
631 }
632 ret = 0;
633
634err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700635 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800636
637 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700638}
639
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000640static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
641 void __user *useraddr)
642{
643 struct ethtool_rxfh_indir *indir;
644 u32 table_size;
645 size_t full_size;
646 int ret;
647
648 if (!dev->ethtool_ops->get_rxfh_indir)
649 return -EOPNOTSUPP;
650
651 if (copy_from_user(&table_size,
652 useraddr + offsetof(struct ethtool_rxfh_indir, size),
653 sizeof(table_size)))
654 return -EFAULT;
655
656 if (table_size >
657 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
658 return -ENOMEM;
659 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
Kees Cookb00916b2010-10-11 12:23:25 -0700660 indir = kzalloc(full_size, GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000661 if (!indir)
662 return -ENOMEM;
663
664 indir->cmd = ETHTOOL_GRXFHINDIR;
665 indir->size = table_size;
666 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
667 if (ret)
668 goto out;
669
670 if (copy_to_user(useraddr, indir, full_size))
671 ret = -EFAULT;
672
673out:
674 kfree(indir);
675 return ret;
676}
677
678static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
679 void __user *useraddr)
680{
681 struct ethtool_rxfh_indir *indir;
682 u32 table_size;
683 size_t full_size;
684 int ret;
685
686 if (!dev->ethtool_ops->set_rxfh_indir)
687 return -EOPNOTSUPP;
688
689 if (copy_from_user(&table_size,
690 useraddr + offsetof(struct ethtool_rxfh_indir, size),
691 sizeof(table_size)))
692 return -EFAULT;
693
694 if (table_size >
695 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
696 return -ENOMEM;
697 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
698 indir = kmalloc(full_size, GFP_USER);
699 if (!indir)
700 return -ENOMEM;
701
702 if (copy_from_user(indir, useraddr, full_size)) {
703 ret = -EFAULT;
704 goto out;
705 }
706
707 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
708
709out:
710 kfree(indir);
711 return ret;
712}
713
Peter Waskiewicze8589112010-02-12 13:48:05 +0000714static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
chavey97f8aef2010-04-07 21:54:42 -0700715 struct ethtool_rx_ntuple_flow_spec *spec,
716 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800717{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800718
719 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000720 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
721 /* free the container */
722 kfree(fsc);
723 return;
724 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800725
726 /* Copy the whole filter over */
727 fsc->fs.flow_type = spec->flow_type;
728 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
729 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
730
731 fsc->fs.vlan_tag = spec->vlan_tag;
732 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
733 fsc->fs.data = spec->data;
734 fsc->fs.data_mask = spec->data_mask;
735 fsc->fs.action = spec->action;
736
737 /* add to the list */
738 list_add_tail_rcu(&fsc->list, &list->list);
739 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800740}
741
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000742/*
743 * ethtool does not (or did not) set masks for flow parameters that are
744 * not specified, so if both value and mask are 0 then this must be
745 * treated as equivalent to a mask with all bits set. Implement that
746 * here rather than in drivers.
747 */
748static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
749{
750 struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
751 struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
752
753 if (fs->flow_type != TCP_V4_FLOW &&
754 fs->flow_type != UDP_V4_FLOW &&
755 fs->flow_type != SCTP_V4_FLOW)
756 return;
757
758 if (!(entry->ip4src | mask->ip4src))
759 mask->ip4src = htonl(0xffffffff);
760 if (!(entry->ip4dst | mask->ip4dst))
761 mask->ip4dst = htonl(0xffffffff);
762 if (!(entry->psrc | mask->psrc))
763 mask->psrc = htons(0xffff);
764 if (!(entry->pdst | mask->pdst))
765 mask->pdst = htons(0xffff);
766 if (!(entry->tos | mask->tos))
767 mask->tos = 0xff;
768 if (!(fs->vlan_tag | fs->vlan_tag_mask))
769 fs->vlan_tag_mask = 0xffff;
770 if (!(fs->data | fs->data_mask))
771 fs->data_mask = 0xffffffffffffffffULL;
772}
773
chavey97f8aef2010-04-07 21:54:42 -0700774static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
775 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800776{
777 struct ethtool_rx_ntuple cmd;
778 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000779 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800780 int ret;
781
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800782 if (!(dev->features & NETIF_F_NTUPLE))
783 return -EINVAL;
784
785 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
786 return -EFAULT;
787
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000788 rx_ntuple_fix_masks(&cmd.fs);
789
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800790 /*
791 * Cache filter in dev struct for GET operation only if
792 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000793 * only if the filter was added successfully. First make sure we
794 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800795 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000796 if (!ops->get_rx_ntuple) {
797 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
798 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800799 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000800 }
801
802 ret = ops->set_rx_ntuple(dev, &cmd);
803 if (ret) {
804 kfree(fsc);
805 return ret;
806 }
807
808 if (!ops->get_rx_ntuple)
809 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800810
811 return ret;
812}
813
814static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
815{
816 struct ethtool_gstrings gstrings;
817 const struct ethtool_ops *ops = dev->ethtool_ops;
818 struct ethtool_rx_ntuple_flow_spec_container *fsc;
819 u8 *data;
820 char *p;
821 int ret, i, num_strings = 0;
822
823 if (!ops->get_sset_count)
824 return -EOPNOTSUPP;
825
826 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
827 return -EFAULT;
828
829 ret = ops->get_sset_count(dev, gstrings.string_set);
830 if (ret < 0)
831 return ret;
832
833 gstrings.len = ret;
834
Kees Cookb00916b2010-10-11 12:23:25 -0700835 data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800836 if (!data)
837 return -ENOMEM;
838
839 if (ops->get_rx_ntuple) {
840 /* driver-specific filter grab */
841 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
842 goto copy;
843 }
844
845 /* default ethtool filter grab */
846 i = 0;
847 p = (char *)data;
848 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
849 sprintf(p, "Filter %d:\n", i);
850 p += ETH_GSTRING_LEN;
851 num_strings++;
852
853 switch (fsc->fs.flow_type) {
854 case TCP_V4_FLOW:
855 sprintf(p, "\tFlow Type: TCP\n");
856 p += ETH_GSTRING_LEN;
857 num_strings++;
858 break;
859 case UDP_V4_FLOW:
860 sprintf(p, "\tFlow Type: UDP\n");
861 p += ETH_GSTRING_LEN;
862 num_strings++;
863 break;
864 case SCTP_V4_FLOW:
865 sprintf(p, "\tFlow Type: SCTP\n");
866 p += ETH_GSTRING_LEN;
867 num_strings++;
868 break;
869 case AH_ESP_V4_FLOW:
870 sprintf(p, "\tFlow Type: AH ESP\n");
871 p += ETH_GSTRING_LEN;
872 num_strings++;
873 break;
874 case ESP_V4_FLOW:
875 sprintf(p, "\tFlow Type: ESP\n");
876 p += ETH_GSTRING_LEN;
877 num_strings++;
878 break;
879 case IP_USER_FLOW:
880 sprintf(p, "\tFlow Type: Raw IP\n");
881 p += ETH_GSTRING_LEN;
882 num_strings++;
883 break;
884 case IPV4_FLOW:
885 sprintf(p, "\tFlow Type: IPv4\n");
886 p += ETH_GSTRING_LEN;
887 num_strings++;
888 break;
889 default:
890 sprintf(p, "\tFlow Type: Unknown\n");
891 p += ETH_GSTRING_LEN;
892 num_strings++;
893 goto unknown_filter;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000894 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800895
896 /* now the rest of the filters */
897 switch (fsc->fs.flow_type) {
898 case TCP_V4_FLOW:
899 case UDP_V4_FLOW:
900 case SCTP_V4_FLOW:
901 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700902 fsc->fs.h_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800903 p += ETH_GSTRING_LEN;
904 num_strings++;
905 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700906 fsc->fs.m_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800907 p += ETH_GSTRING_LEN;
908 num_strings++;
909 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700910 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800911 p += ETH_GSTRING_LEN;
912 num_strings++;
913 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700914 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800915 p += ETH_GSTRING_LEN;
916 num_strings++;
917 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700918 fsc->fs.h_u.tcp_ip4_spec.psrc,
919 fsc->fs.m_u.tcp_ip4_spec.psrc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800920 p += ETH_GSTRING_LEN;
921 num_strings++;
922 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700923 fsc->fs.h_u.tcp_ip4_spec.pdst,
924 fsc->fs.m_u.tcp_ip4_spec.pdst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800925 p += ETH_GSTRING_LEN;
926 num_strings++;
927 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700928 fsc->fs.h_u.tcp_ip4_spec.tos,
929 fsc->fs.m_u.tcp_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800930 p += ETH_GSTRING_LEN;
931 num_strings++;
932 break;
933 case AH_ESP_V4_FLOW:
934 case ESP_V4_FLOW:
935 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700936 fsc->fs.h_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800937 p += ETH_GSTRING_LEN;
938 num_strings++;
939 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700940 fsc->fs.m_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800941 p += ETH_GSTRING_LEN;
942 num_strings++;
943 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700944 fsc->fs.h_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800945 p += ETH_GSTRING_LEN;
946 num_strings++;
947 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700948 fsc->fs.m_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800949 p += ETH_GSTRING_LEN;
950 num_strings++;
951 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700952 fsc->fs.h_u.ah_ip4_spec.spi,
953 fsc->fs.m_u.ah_ip4_spec.spi);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800954 p += ETH_GSTRING_LEN;
955 num_strings++;
956 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700957 fsc->fs.h_u.ah_ip4_spec.tos,
958 fsc->fs.m_u.ah_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800959 p += ETH_GSTRING_LEN;
960 num_strings++;
961 break;
962 case IP_USER_FLOW:
963 sprintf(p, "\tSrc IP addr: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +0000964 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800965 p += ETH_GSTRING_LEN;
966 num_strings++;
967 sprintf(p, "\tSrc IP mask: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +0000968 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800969 p += ETH_GSTRING_LEN;
970 num_strings++;
971 sprintf(p, "\tDest IP addr: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +0000972 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800973 p += ETH_GSTRING_LEN;
974 num_strings++;
975 sprintf(p, "\tDest IP mask: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +0000976 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800977 p += ETH_GSTRING_LEN;
978 num_strings++;
979 break;
980 case IPV4_FLOW:
981 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700982 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800983 p += ETH_GSTRING_LEN;
984 num_strings++;
985 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700986 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800987 p += ETH_GSTRING_LEN;
988 num_strings++;
989 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700990 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800991 p += ETH_GSTRING_LEN;
992 num_strings++;
993 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700994 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800995 p += ETH_GSTRING_LEN;
996 num_strings++;
997 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700998 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
999 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001000 p += ETH_GSTRING_LEN;
1001 num_strings++;
1002 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001003 fsc->fs.h_u.usr_ip4_spec.tos,
1004 fsc->fs.m_u.usr_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001005 p += ETH_GSTRING_LEN;
1006 num_strings++;
1007 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001008 fsc->fs.h_u.usr_ip4_spec.ip_ver,
1009 fsc->fs.m_u.usr_ip4_spec.ip_ver);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001010 p += ETH_GSTRING_LEN;
1011 num_strings++;
1012 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001013 fsc->fs.h_u.usr_ip4_spec.proto,
1014 fsc->fs.m_u.usr_ip4_spec.proto);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001015 p += ETH_GSTRING_LEN;
1016 num_strings++;
1017 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +00001018 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001019 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001020 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001021 p += ETH_GSTRING_LEN;
1022 num_strings++;
1023 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
1024 p += ETH_GSTRING_LEN;
1025 num_strings++;
1026 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
1027 p += ETH_GSTRING_LEN;
1028 num_strings++;
1029 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
1030 sprintf(p, "\tAction: Drop\n");
1031 else
1032 sprintf(p, "\tAction: Direct to queue %d\n",
chavey97f8aef2010-04-07 21:54:42 -07001033 fsc->fs.action);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001034 p += ETH_GSTRING_LEN;
1035 num_strings++;
1036unknown_filter:
1037 i++;
1038 }
1039copy:
1040 /* indicate to userspace how many strings we actually have */
1041 gstrings.len = num_strings;
1042 ret = -EFAULT;
1043 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1044 goto out;
1045 useraddr += sizeof(gstrings);
1046 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1047 goto out;
1048 ret = 0;
1049
1050out:
1051 kfree(data);
1052 return ret;
1053}
1054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
1056{
1057 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001058 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 void *regbuf;
1060 int reglen, ret;
1061
1062 if (!ops->get_regs || !ops->get_regs_len)
1063 return -EOPNOTSUPP;
1064
1065 if (copy_from_user(&regs, useraddr, sizeof(regs)))
1066 return -EFAULT;
1067
1068 reglen = ops->get_regs_len(dev);
1069 if (regs.len > reglen)
1070 regs.len = reglen;
1071
Eugene Teob7c7d012011-01-24 21:05:17 -08001072 regbuf = vzalloc(reglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 if (!regbuf)
1074 return -ENOMEM;
1075
1076 ops->get_regs(dev, &regs, regbuf);
1077
1078 ret = -EFAULT;
1079 if (copy_to_user(useraddr, &regs, sizeof(regs)))
1080 goto out;
1081 useraddr += offsetof(struct ethtool_regs, data);
1082 if (copy_to_user(useraddr, regbuf, regs.len))
1083 goto out;
1084 ret = 0;
1085
1086 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +00001087 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 return ret;
1089}
1090
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001091static int ethtool_reset(struct net_device *dev, char __user *useraddr)
1092{
1093 struct ethtool_value reset;
1094 int ret;
1095
1096 if (!dev->ethtool_ops->reset)
1097 return -EOPNOTSUPP;
1098
1099 if (copy_from_user(&reset, useraddr, sizeof(reset)))
1100 return -EFAULT;
1101
1102 ret = dev->ethtool_ops->reset(dev, &reset.data);
1103 if (ret)
1104 return ret;
1105
1106 if (copy_to_user(useraddr, &reset, sizeof(reset)))
1107 return -EFAULT;
1108 return 0;
1109}
1110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
1112{
Roland Dreier8e557422010-02-11 12:14:23 -08001113 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 if (!dev->ethtool_ops->get_wol)
1116 return -EOPNOTSUPP;
1117
1118 dev->ethtool_ops->get_wol(dev, &wol);
1119
1120 if (copy_to_user(useraddr, &wol, sizeof(wol)))
1121 return -EFAULT;
1122 return 0;
1123}
1124
1125static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
1126{
1127 struct ethtool_wolinfo wol;
1128
1129 if (!dev->ethtool_ops->set_wol)
1130 return -EOPNOTSUPP;
1131
1132 if (copy_from_user(&wol, useraddr, sizeof(wol)))
1133 return -EFAULT;
1134
1135 return dev->ethtool_ops->set_wol(dev, &wol);
1136}
1137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138static int ethtool_nway_reset(struct net_device *dev)
1139{
1140 if (!dev->ethtool_ops->nway_reset)
1141 return -EOPNOTSUPP;
1142
1143 return dev->ethtool_ops->nway_reset(dev);
1144}
1145
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001146static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
1147{
1148 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
1149
1150 if (!dev->ethtool_ops->get_link)
1151 return -EOPNOTSUPP;
1152
1153 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
1154
1155 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1156 return -EFAULT;
1157 return 0;
1158}
1159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1161{
1162 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001163 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001164 void __user *userbuf = useraddr + sizeof(eeprom);
1165 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001167 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 if (!ops->get_eeprom || !ops->get_eeprom_len)
1170 return -EOPNOTSUPP;
1171
1172 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1173 return -EFAULT;
1174
1175 /* Check for wrap and zero */
1176 if (eeprom.offset + eeprom.len <= eeprom.offset)
1177 return -EINVAL;
1178
1179 /* Check for exceeding total eeprom len */
1180 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1181 return -EINVAL;
1182
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001183 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (!data)
1185 return -ENOMEM;
1186
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001187 bytes_remaining = eeprom.len;
1188 while (bytes_remaining > 0) {
1189 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001191 ret = ops->get_eeprom(dev, &eeprom, data);
1192 if (ret)
1193 break;
1194 if (copy_to_user(userbuf, data, eeprom.len)) {
1195 ret = -EFAULT;
1196 break;
1197 }
1198 userbuf += eeprom.len;
1199 eeprom.offset += eeprom.len;
1200 bytes_remaining -= eeprom.len;
1201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -07001203 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1204 eeprom.offset -= eeprom.len;
1205 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1206 ret = -EFAULT;
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 kfree(data);
1209 return ret;
1210}
1211
1212static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1213{
1214 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001215 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001216 void __user *userbuf = useraddr + sizeof(eeprom);
1217 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001219 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 if (!ops->set_eeprom || !ops->get_eeprom_len)
1222 return -EOPNOTSUPP;
1223
1224 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1225 return -EFAULT;
1226
1227 /* Check for wrap and zero */
1228 if (eeprom.offset + eeprom.len <= eeprom.offset)
1229 return -EINVAL;
1230
1231 /* Check for exceeding total eeprom len */
1232 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1233 return -EINVAL;
1234
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001235 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (!data)
1237 return -ENOMEM;
1238
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001239 bytes_remaining = eeprom.len;
1240 while (bytes_remaining > 0) {
1241 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001243 if (copy_from_user(data, userbuf, eeprom.len)) {
1244 ret = -EFAULT;
1245 break;
1246 }
1247 ret = ops->set_eeprom(dev, &eeprom, data);
1248 if (ret)
1249 break;
1250 userbuf += eeprom.len;
1251 eeprom.offset += eeprom.len;
1252 bytes_remaining -= eeprom.len;
1253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 kfree(data);
1256 return ret;
1257}
1258
chavey97f8aef2010-04-07 21:54:42 -07001259static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1260 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Roland Dreier8e557422010-02-11 12:14:23 -08001262 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 if (!dev->ethtool_ops->get_coalesce)
1265 return -EOPNOTSUPP;
1266
1267 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1268
1269 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1270 return -EFAULT;
1271 return 0;
1272}
1273
chavey97f8aef2010-04-07 21:54:42 -07001274static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1275 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
1277 struct ethtool_coalesce coalesce;
1278
David S. Millerfa04ae52005-06-06 15:07:19 -07001279 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 return -EOPNOTSUPP;
1281
1282 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1283 return -EFAULT;
1284
1285 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1286}
1287
1288static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1289{
Roland Dreier8e557422010-02-11 12:14:23 -08001290 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 if (!dev->ethtool_ops->get_ringparam)
1293 return -EOPNOTSUPP;
1294
1295 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1296
1297 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1298 return -EFAULT;
1299 return 0;
1300}
1301
1302static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1303{
1304 struct ethtool_ringparam ringparam;
1305
1306 if (!dev->ethtool_ops->set_ringparam)
1307 return -EOPNOTSUPP;
1308
1309 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1310 return -EFAULT;
1311
1312 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1313}
1314
1315static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1316{
1317 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1318
1319 if (!dev->ethtool_ops->get_pauseparam)
1320 return -EOPNOTSUPP;
1321
1322 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1323
1324 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1325 return -EFAULT;
1326 return 0;
1327}
1328
1329static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1330{
1331 struct ethtool_pauseparam pauseparam;
1332
Jeff Garzike1b90c42006-07-17 12:54:40 -04001333 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return -EOPNOTSUPP;
1335
1336 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1337 return -EFAULT;
1338
1339 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1340}
1341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342static int __ethtool_set_sg(struct net_device *dev, u32 data)
1343{
1344 int err;
1345
Michał Mirosław0a417702011-02-15 16:59:17 +00001346 if (data && !(dev->features & NETIF_F_ALL_CSUM))
1347 return -EINVAL;
1348
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (!data && dev->ethtool_ops->set_tso) {
1350 err = dev->ethtool_ops->set_tso(dev, 0);
1351 if (err)
1352 return err;
1353 }
1354
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001355 if (!data && dev->ethtool_ops->set_ufo) {
1356 err = dev->ethtool_ops->set_ufo(dev, 0);
1357 if (err)
1358 return err;
1359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return dev->ethtool_ops->set_sg(dev, data);
1361}
1362
Michał Mirosław0a417702011-02-15 16:59:17 +00001363static int __ethtool_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 int err;
1366
1367 if (!dev->ethtool_ops->set_tx_csum)
1368 return -EOPNOTSUPP;
1369
Michał Mirosław0a417702011-02-15 16:59:17 +00001370 if (!data && dev->ethtool_ops->set_sg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 err = __ethtool_set_sg(dev, 0);
1372 if (err)
1373 return err;
1374 }
1375
Michał Mirosław0a417702011-02-15 16:59:17 +00001376 return dev->ethtool_ops->set_tx_csum(dev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
Herbert Xub240a0e2008-12-15 23:44:31 -08001379static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
1380{
1381 struct ethtool_value edata;
1382
1383 if (!dev->ethtool_ops->set_rx_csum)
1384 return -EOPNOTSUPP;
1385
1386 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1387 return -EFAULT;
1388
1389 if (!edata.data && dev->ethtool_ops->set_sg)
1390 dev->features &= ~NETIF_F_GRO;
1391
1392 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
1393}
1394
Michał Mirosław0a417702011-02-15 16:59:17 +00001395static int __ethtool_set_tso(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (!dev->ethtool_ops->set_tso)
1398 return -EOPNOTSUPP;
1399
Michał Mirosław0a417702011-02-15 16:59:17 +00001400 if (data && !(dev->features & NETIF_F_SG))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 return -EINVAL;
1402
Michał Mirosław0a417702011-02-15 16:59:17 +00001403 return dev->ethtool_ops->set_tso(dev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
Michał Mirosław0a417702011-02-15 16:59:17 +00001406static int __ethtool_set_ufo(struct net_device *dev, u32 data)
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001407{
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001408 if (!dev->ethtool_ops->set_ufo)
1409 return -EOPNOTSUPP;
Michał Mirosław0a417702011-02-15 16:59:17 +00001410 if (data && !(dev->features & NETIF_F_SG))
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001411 return -EINVAL;
Michał Mirosław0a417702011-02-15 16:59:17 +00001412 if (data && !((dev->features & NETIF_F_GEN_CSUM) ||
Michał Mirosław79032642010-11-30 06:38:00 +00001413 (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
1414 == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)))
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001415 return -EINVAL;
Michał Mirosław0a417702011-02-15 16:59:17 +00001416 return dev->ethtool_ops->set_ufo(dev, data);
Herbert Xub240a0e2008-12-15 23:44:31 -08001417}
1418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1420{
1421 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001422 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001424 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001426 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001427 return -EOPNOTSUPP;
1428
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001429 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001430 if (test_len < 0)
1431 return test_len;
1432 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 if (copy_from_user(&test, useraddr, sizeof(test)))
1435 return -EFAULT;
1436
Jeff Garzikff03d492007-08-15 16:01:08 -07001437 test.len = test_len;
1438 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (!data)
1440 return -ENOMEM;
1441
1442 ops->self_test(dev, &test, data);
1443
1444 ret = -EFAULT;
1445 if (copy_to_user(useraddr, &test, sizeof(test)))
1446 goto out;
1447 useraddr += sizeof(test);
1448 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1449 goto out;
1450 ret = 0;
1451
1452 out:
1453 kfree(data);
1454 return ret;
1455}
1456
1457static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1458{
1459 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 u8 *data;
1461 int ret;
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1464 return -EFAULT;
1465
Michał Mirosław340ae162011-02-15 16:59:16 +00001466 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001467 if (ret < 0)
1468 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001469
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001470 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1473 if (!data)
1474 return -ENOMEM;
1475
Michał Mirosław340ae162011-02-15 16:59:16 +00001476 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 ret = -EFAULT;
1479 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1480 goto out;
1481 useraddr += sizeof(gstrings);
1482 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1483 goto out;
1484 ret = 0;
1485
Michał Mirosław340ae162011-02-15 16:59:16 +00001486out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 kfree(data);
1488 return ret;
1489}
1490
1491static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1492{
1493 struct ethtool_value id;
1494
1495 if (!dev->ethtool_ops->phys_id)
1496 return -EOPNOTSUPP;
1497
1498 if (copy_from_user(&id, useraddr, sizeof(id)))
1499 return -EFAULT;
1500
1501 return dev->ethtool_ops->phys_id(dev, id.data);
1502}
1503
1504static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1505{
1506 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001507 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001509 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001511 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001512 return -EOPNOTSUPP;
1513
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001514 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001515 if (n_stats < 0)
1516 return n_stats;
1517 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1520 return -EFAULT;
1521
Jeff Garzikff03d492007-08-15 16:01:08 -07001522 stats.n_stats = n_stats;
1523 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 if (!data)
1525 return -ENOMEM;
1526
1527 ops->get_ethtool_stats(dev, &stats, data);
1528
1529 ret = -EFAULT;
1530 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1531 goto out;
1532 useraddr += sizeof(stats);
1533 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1534 goto out;
1535 ret = 0;
1536
1537 out:
1538 kfree(data);
1539 return ret;
1540}
1541
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001542static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001543{
1544 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001545
Matthew Wilcox313674a2007-07-31 14:00:29 -07001546 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001547 return -EFAULT;
1548
Matthew Wilcox313674a2007-07-31 14:00:29 -07001549 if (epaddr.size < dev->addr_len)
1550 return -ETOOSMALL;
1551 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001552
Jon Wetzela6f9a702005-08-20 17:15:54 -07001553 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001554 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001555 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001556 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1557 return -EFAULT;
1558 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001559}
1560
Jeff Garzik13c99b22007-08-15 16:01:56 -07001561static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1562 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001563{
Roland Dreier8e557422010-02-11 12:14:23 -08001564 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001565
Jeff Garzik13c99b22007-08-15 16:01:56 -07001566 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001567 return -EOPNOTSUPP;
1568
Jeff Garzik13c99b22007-08-15 16:01:56 -07001569 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001570
1571 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1572 return -EFAULT;
1573 return 0;
1574}
1575
Jeff Garzik13c99b22007-08-15 16:01:56 -07001576static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1577 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001578{
1579 struct ethtool_value edata;
1580
Jeff Garzik13c99b22007-08-15 16:01:56 -07001581 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001582 return -EOPNOTSUPP;
1583
1584 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1585 return -EFAULT;
1586
Jeff Garzik13c99b22007-08-15 16:01:56 -07001587 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001588 return 0;
1589}
1590
Jeff Garzik13c99b22007-08-15 16:01:56 -07001591static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1592 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001593{
1594 struct ethtool_value edata;
1595
Jeff Garzik13c99b22007-08-15 16:01:56 -07001596 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001597 return -EOPNOTSUPP;
1598
1599 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1600 return -EFAULT;
1601
Jeff Garzik13c99b22007-08-15 16:01:56 -07001602 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001603}
1604
chavey97f8aef2010-04-07 21:54:42 -07001605static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1606 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001607{
1608 struct ethtool_flash efl;
1609
1610 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1611 return -EFAULT;
1612
1613 if (!dev->ethtool_ops->flash_device)
1614 return -EOPNOTSUPP;
1615
1616 return dev->ethtool_ops->flash_device(dev, &efl);
1617}
1618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619/* The main entry point in this file. Called from net/core/dev.c */
1620
Eric W. Biederman881d9662007-09-17 11:56:21 -07001621int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001623 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 void __user *useraddr = ifr->ifr_data;
1625 u32 ethcmd;
1626 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001627 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 if (!dev || !netif_device_present(dev))
1630 return -ENODEV;
1631
chavey97f8aef2010-04-07 21:54:42 -07001632 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 return -EFAULT;
1634
Ben Hutchings01414802010-08-17 02:31:15 -07001635 if (!dev->ethtool_ops) {
1636 /* ETHTOOL_GDRVINFO does not require any driver support.
1637 * It is also unprivileged and does not change anything,
1638 * so we can take a shortcut to it. */
1639 if (ethcmd == ETHTOOL_GDRVINFO)
1640 return ethtool_get_drvinfo(dev, useraddr);
1641 else
1642 return -EOPNOTSUPP;
1643 }
1644
Stephen Hemminger75f31232006-09-28 15:13:37 -07001645 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001646 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001647 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001648 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001649 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001650 case ETHTOOL_GCOALESCE:
1651 case ETHTOOL_GRINGPARAM:
1652 case ETHTOOL_GPAUSEPARAM:
1653 case ETHTOOL_GRXCSUM:
1654 case ETHTOOL_GTXCSUM:
1655 case ETHTOOL_GSG:
1656 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001657 case ETHTOOL_GTSO:
1658 case ETHTOOL_GPERMADDR:
1659 case ETHTOOL_GUFO:
1660 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001661 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001662 case ETHTOOL_GFLAGS:
1663 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001664 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001665 case ETHTOOL_GRXRINGS:
1666 case ETHTOOL_GRXCLSRLCNT:
1667 case ETHTOOL_GRXCLSRULE:
1668 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001669 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001670 break;
1671 default:
1672 if (!capable(CAP_NET_ADMIN))
1673 return -EPERM;
1674 }
1675
chavey97f8aef2010-04-07 21:54:42 -07001676 if (dev->ethtool_ops->begin) {
1677 rc = dev->ethtool_ops->begin(dev);
1678 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001680 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001681 old_features = dev->features;
1682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 switch (ethcmd) {
1684 case ETHTOOL_GSET:
1685 rc = ethtool_get_settings(dev, useraddr);
1686 break;
1687 case ETHTOOL_SSET:
1688 rc = ethtool_set_settings(dev, useraddr);
1689 break;
1690 case ETHTOOL_GDRVINFO:
1691 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 break;
1693 case ETHTOOL_GREGS:
1694 rc = ethtool_get_regs(dev, useraddr);
1695 break;
1696 case ETHTOOL_GWOL:
1697 rc = ethtool_get_wol(dev, useraddr);
1698 break;
1699 case ETHTOOL_SWOL:
1700 rc = ethtool_set_wol(dev, useraddr);
1701 break;
1702 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001703 rc = ethtool_get_value(dev, useraddr, ethcmd,
1704 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 break;
1706 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001707 rc = ethtool_set_value_void(dev, useraddr,
1708 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 break;
1710 case ETHTOOL_NWAY_RST:
1711 rc = ethtool_nway_reset(dev);
1712 break;
1713 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001714 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 break;
1716 case ETHTOOL_GEEPROM:
1717 rc = ethtool_get_eeprom(dev, useraddr);
1718 break;
1719 case ETHTOOL_SEEPROM:
1720 rc = ethtool_set_eeprom(dev, useraddr);
1721 break;
1722 case ETHTOOL_GCOALESCE:
1723 rc = ethtool_get_coalesce(dev, useraddr);
1724 break;
1725 case ETHTOOL_SCOALESCE:
1726 rc = ethtool_set_coalesce(dev, useraddr);
1727 break;
1728 case ETHTOOL_GRINGPARAM:
1729 rc = ethtool_get_ringparam(dev, useraddr);
1730 break;
1731 case ETHTOOL_SRINGPARAM:
1732 rc = ethtool_set_ringparam(dev, useraddr);
1733 break;
1734 case ETHTOOL_GPAUSEPARAM:
1735 rc = ethtool_get_pauseparam(dev, useraddr);
1736 break;
1737 case ETHTOOL_SPAUSEPARAM:
1738 rc = ethtool_set_pauseparam(dev, useraddr);
1739 break;
1740 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001741 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001742 (dev->ethtool_ops->get_rx_csum ?
1743 dev->ethtool_ops->get_rx_csum :
1744 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 break;
1746 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001747 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 case ETHTOOL_TEST:
1750 rc = ethtool_self_test(dev, useraddr);
1751 break;
1752 case ETHTOOL_GSTRINGS:
1753 rc = ethtool_get_strings(dev, useraddr);
1754 break;
1755 case ETHTOOL_PHYS_ID:
1756 rc = ethtool_phys_id(dev, useraddr);
1757 break;
1758 case ETHTOOL_GSTATS:
1759 rc = ethtool_get_stats(dev, useraddr);
1760 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001761 case ETHTOOL_GPERMADDR:
1762 rc = ethtool_get_perm_addr(dev, useraddr);
1763 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001764 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001765 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001766 (dev->ethtool_ops->get_flags ?
1767 dev->ethtool_ops->get_flags :
1768 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001769 break;
1770 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001771 rc = ethtool_set_value(dev, useraddr,
1772 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001773 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001774 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001775 rc = ethtool_get_value(dev, useraddr, ethcmd,
1776 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001777 break;
1778 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001779 rc = ethtool_set_value(dev, useraddr,
1780 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001781 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001782 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001783 case ETHTOOL_GRXRINGS:
1784 case ETHTOOL_GRXCLSRLCNT:
1785 case ETHTOOL_GRXCLSRULE:
1786 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001787 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001788 break;
1789 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001790 case ETHTOOL_SRXCLSRLDEL:
1791 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001792 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001793 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001794 case ETHTOOL_FLASHDEV:
1795 rc = ethtool_flash_device(dev, useraddr);
1796 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001797 case ETHTOOL_RESET:
1798 rc = ethtool_reset(dev, useraddr);
1799 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001800 case ETHTOOL_SRXNTUPLE:
1801 rc = ethtool_set_rx_ntuple(dev, useraddr);
1802 break;
1803 case ETHTOOL_GRXNTUPLE:
1804 rc = ethtool_get_rx_ntuple(dev, useraddr);
1805 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001806 case ETHTOOL_GSSET_INFO:
1807 rc = ethtool_get_sset_info(dev, useraddr);
1808 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001809 case ETHTOOL_GRXFHINDIR:
1810 rc = ethtool_get_rxfh_indir(dev, useraddr);
1811 break;
1812 case ETHTOOL_SRXFHINDIR:
1813 rc = ethtool_set_rxfh_indir(dev, useraddr);
1814 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001815 case ETHTOOL_GFEATURES:
1816 rc = ethtool_get_features(dev, useraddr);
1817 break;
1818 case ETHTOOL_SFEATURES:
1819 rc = ethtool_set_features(dev, useraddr);
1820 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001821 case ETHTOOL_GTXCSUM:
1822 case ETHTOOL_GSG:
1823 case ETHTOOL_GTSO:
1824 case ETHTOOL_GUFO:
1825 case ETHTOOL_GGSO:
1826 case ETHTOOL_GGRO:
1827 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1828 break;
1829 case ETHTOOL_STXCSUM:
1830 case ETHTOOL_SSG:
1831 case ETHTOOL_STSO:
1832 case ETHTOOL_SUFO:
1833 case ETHTOOL_SGSO:
1834 case ETHTOOL_SGRO:
1835 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1836 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001838 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001840
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001841 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001843
1844 if (old_features != dev->features)
1845 netdev_features_change(dev);
1846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848}