blob: 66cdc76770ce7c1c1cfd83810f33bb0ee75fa9f4 [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
37u32 ethtool_op_get_tx_csum(struct net_device *dev)
38{
Herbert Xu8648b302006-06-17 22:06:05 -070039 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000041EXPORT_SYMBOL(ethtool_op_get_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
44{
45 if (data)
46 dev->features |= NETIF_F_IP_CSUM;
47 else
48 dev->features &= ~NETIF_F_IP_CSUM;
49
50 return 0;
51}
Michał Mirosław9a279ea2011-02-15 16:59:16 +000052EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Jon Mason69f6a0f2005-05-29 20:27:24 -070054int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
55{
56 if (data)
57 dev->features |= NETIF_F_HW_CSUM;
58 else
59 dev->features &= ~NETIF_F_HW_CSUM;
60
61 return 0;
62}
chavey97f8aef2010-04-07 21:54:42 -070063EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -070064
65int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
66{
67 if (data)
68 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
69 else
70 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
71
72 return 0;
73}
chavey97f8aef2010-04-07 21:54:42 -070074EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Michael Chan6460d942007-07-14 19:07:52 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076u32 ethtool_op_get_sg(struct net_device *dev)
77{
78 return (dev->features & NETIF_F_SG) != 0;
79}
chavey97f8aef2010-04-07 21:54:42 -070080EXPORT_SYMBOL(ethtool_op_get_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82int ethtool_op_set_sg(struct net_device *dev, u32 data)
83{
84 if (data)
85 dev->features |= NETIF_F_SG;
86 else
87 dev->features &= ~NETIF_F_SG;
88
89 return 0;
90}
chavey97f8aef2010-04-07 21:54:42 -070091EXPORT_SYMBOL(ethtool_op_set_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93u32 ethtool_op_get_tso(struct net_device *dev)
94{
95 return (dev->features & NETIF_F_TSO) != 0;
96}
chavey97f8aef2010-04-07 21:54:42 -070097EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99int ethtool_op_set_tso(struct net_device *dev, u32 data)
100{
101 if (data)
102 dev->features |= NETIF_F_TSO;
103 else
104 dev->features &= ~NETIF_F_TSO;
105
106 return 0;
107}
chavey97f8aef2010-04-07 21:54:42 -0700108EXPORT_SYMBOL(ethtool_op_set_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700110u32 ethtool_op_get_ufo(struct net_device *dev)
111{
112 return (dev->features & NETIF_F_UFO) != 0;
113}
chavey97f8aef2010-04-07 21:54:42 -0700114EXPORT_SYMBOL(ethtool_op_get_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700115
116int ethtool_op_set_ufo(struct net_device *dev, u32 data)
117{
118 if (data)
119 dev->features |= NETIF_F_UFO;
120 else
121 dev->features &= ~NETIF_F_UFO;
122 return 0;
123}
chavey97f8aef2010-04-07 21:54:42 -0700124EXPORT_SYMBOL(ethtool_op_set_ufo);
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700125
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700126/* the following list of flags are the same as their associated
127 * NETIF_F_xxx values in include/linux/netdevice.h
128 */
129static const u32 flags_dup_features =
Jesse Grossd5dbda22010-10-20 13:56:07 +0000130 (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | ETH_FLAG_NTUPLE |
131 ETH_FLAG_RXHASH);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700132
133u32 ethtool_op_get_flags(struct net_device *dev)
134{
135 /* in the future, this function will probably contain additional
136 * handling for flags which are not so easily handled
137 * by a simple masking operation
138 */
139
140 return dev->features & flags_dup_features;
141}
chavey97f8aef2010-04-07 21:54:42 -0700142EXPORT_SYMBOL(ethtool_op_get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700143
Ben Hutchings1437ce32010-06-30 02:44:32 +0000144int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700145{
Ben Hutchings1437ce32010-06-30 02:44:32 +0000146 if (data & ~supported)
147 return -EINVAL;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000148
Ben Hutchings1437ce32010-06-30 02:44:32 +0000149 dev->features = ((dev->features & ~flags_dup_features) |
150 (data & flags_dup_features));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700151 return 0;
152}
chavey97f8aef2010-04-07 21:54:42 -0700153EXPORT_SYMBOL(ethtool_op_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700154
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800155void ethtool_ntuple_flush(struct net_device *dev)
156{
157 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
158
159 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
160 list_del(&fsc->list);
161 kfree(fsc);
162 }
163 dev->ethtool_ntuple_list.count = 0;
164}
165EXPORT_SYMBOL(ethtool_ntuple_flush);
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/* Handlers for each ethtool command */
168
Michał Mirosław5455c692011-02-15 16:59:17 +0000169#define ETHTOOL_DEV_FEATURE_WORDS 1
170
171static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
172{
173 struct ethtool_gfeatures cmd = {
174 .cmd = ETHTOOL_GFEATURES,
175 .size = ETHTOOL_DEV_FEATURE_WORDS,
176 };
177 struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = {
178 {
179 .available = dev->hw_features,
180 .requested = dev->wanted_features,
181 .active = dev->features,
182 .never_changed = NETIF_F_NEVER_CHANGE,
183 },
184 };
185 u32 __user *sizeaddr;
186 u32 copy_size;
187
188 sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
189 if (get_user(copy_size, sizeaddr))
190 return -EFAULT;
191
192 if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
193 copy_size = ETHTOOL_DEV_FEATURE_WORDS;
194
195 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
196 return -EFAULT;
197 useraddr += sizeof(cmd);
198 if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
199 return -EFAULT;
200
201 return 0;
202}
203
204static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
205{
206 struct ethtool_sfeatures cmd;
207 struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
208 int ret = 0;
209
210 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
211 return -EFAULT;
212 useraddr += sizeof(cmd);
213
214 if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
215 return -EINVAL;
216
217 if (copy_from_user(features, useraddr, sizeof(features)))
218 return -EFAULT;
219
220 if (features[0].valid & ~NETIF_F_ETHTOOL_BITS)
221 return -EINVAL;
222
223 if (features[0].valid & ~dev->hw_features) {
224 features[0].valid &= dev->hw_features;
225 ret |= ETHTOOL_F_UNSUPPORTED;
226 }
227
228 dev->wanted_features &= ~features[0].valid;
229 dev->wanted_features |= features[0].valid & features[0].requested;
230 netdev_update_features(dev);
231
232 if ((dev->wanted_features ^ dev->features) & features[0].valid)
233 ret |= ETHTOOL_F_WISH;
234
235 return ret;
236}
237
238static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = {
239 /* NETIF_F_SG */ "tx-scatter-gather",
240 /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
241 /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
242 /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
243 /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6",
244 /* NETIF_F_HIGHDMA */ "highdma",
245 /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
246 /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
247
248 /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
249 /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
250 /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
251 /* NETIF_F_GSO */ "tx-generic-segmentation",
252 /* NETIF_F_LLTX */ "tx-lockless",
253 /* NETIF_F_NETNS_LOCAL */ "netns-local",
254 /* NETIF_F_GRO */ "rx-gro",
255 /* NETIF_F_LRO */ "rx-lro",
256
257 /* NETIF_F_TSO */ "tx-tcp-segmentation",
258 /* NETIF_F_UFO */ "tx-udp-fragmentation",
259 /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
260 /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
261 /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
262 /* NETIF_F_FSO */ "tx-fcoe-segmentation",
263 "",
264 "",
265
266 /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
267 /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
268 /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
269 /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
270 /* NETIF_F_RXHASH */ "rx-hashing",
Michał Mirosławe83d3602011-02-15 16:59:18 +0000271 /* NETIF_F_RXCSUM */ "rx-checksum",
Michał Mirosław5455c692011-02-15 16:59:17 +0000272 "",
273 "",
274};
275
Michał Mirosław340ae162011-02-15 16:59:16 +0000276static int __ethtool_get_sset_count(struct net_device *dev, int sset)
277{
278 const struct ethtool_ops *ops = dev->ethtool_ops;
279
Michał Mirosław5455c692011-02-15 16:59:17 +0000280 if (sset == ETH_SS_FEATURES)
281 return ARRAY_SIZE(netdev_features_strings);
282
Michał Mirosław340ae162011-02-15 16:59:16 +0000283 if (ops && ops->get_sset_count && ops->get_strings)
284 return ops->get_sset_count(dev, sset);
285 else
286 return -EOPNOTSUPP;
287}
288
289static void __ethtool_get_strings(struct net_device *dev,
290 u32 stringset, u8 *data)
291{
292 const struct ethtool_ops *ops = dev->ethtool_ops;
293
Michał Mirosław5455c692011-02-15 16:59:17 +0000294 if (stringset == ETH_SS_FEATURES)
295 memcpy(data, netdev_features_strings,
296 sizeof(netdev_features_strings));
297 else
298 /* ops->get_strings is valid because checked earlier */
299 ops->get_strings(dev, stringset, data);
Michał Mirosław340ae162011-02-15 16:59:16 +0000300}
301
Michał Mirosław0a417702011-02-15 16:59:17 +0000302static u32 ethtool_get_feature_mask(u32 eth_cmd)
303{
304 /* feature masks of legacy discrete ethtool ops */
305
306 switch (eth_cmd) {
307 case ETHTOOL_GTXCSUM:
308 case ETHTOOL_STXCSUM:
309 return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000310 case ETHTOOL_GRXCSUM:
311 case ETHTOOL_SRXCSUM:
312 return NETIF_F_RXCSUM;
Michał Mirosław0a417702011-02-15 16:59:17 +0000313 case ETHTOOL_GSG:
314 case ETHTOOL_SSG:
315 return NETIF_F_SG;
316 case ETHTOOL_GTSO:
317 case ETHTOOL_STSO:
318 return NETIF_F_ALL_TSO;
319 case ETHTOOL_GUFO:
320 case ETHTOOL_SUFO:
321 return NETIF_F_UFO;
322 case ETHTOOL_GGSO:
323 case ETHTOOL_SGSO:
324 return NETIF_F_GSO;
325 case ETHTOOL_GGRO:
326 case ETHTOOL_SGRO:
327 return NETIF_F_GRO;
328 default:
329 BUG();
330 }
331}
332
333static void *__ethtool_get_one_feature_actor(struct net_device *dev, u32 ethcmd)
334{
335 const struct ethtool_ops *ops = dev->ethtool_ops;
336
337 if (!ops)
338 return NULL;
339
340 switch (ethcmd) {
341 case ETHTOOL_GTXCSUM:
342 return ops->get_tx_csum;
Michał Mirosławe83d3602011-02-15 16:59:18 +0000343 case ETHTOOL_GRXCSUM:
344 return ops->get_rx_csum;
Michał Mirosław0a417702011-02-15 16:59:17 +0000345 case ETHTOOL_SSG:
346 return ops->get_sg;
347 case ETHTOOL_STSO:
348 return ops->get_tso;
349 case ETHTOOL_SUFO:
350 return ops->get_ufo;
351 default:
352 return NULL;
353 }
354}
355
Michał Mirosławe83d3602011-02-15 16:59:18 +0000356static u32 __ethtool_get_rx_csum_oldbug(struct net_device *dev)
357{
358 return !!(dev->features & NETIF_F_ALL_CSUM);
359}
360
Michał Mirosław0a417702011-02-15 16:59:17 +0000361static int ethtool_get_one_feature(struct net_device *dev,
362 char __user *useraddr, u32 ethcmd)
363{
Michał Mirosław86794882011-02-15 16:59:17 +0000364 u32 mask = ethtool_get_feature_mask(ethcmd);
Michał Mirosław0a417702011-02-15 16:59:17 +0000365 struct ethtool_value edata = {
366 .cmd = ethcmd,
Michał Mirosław86794882011-02-15 16:59:17 +0000367 .data = !!(dev->features & mask),
Michał Mirosław0a417702011-02-15 16:59:17 +0000368 };
Michał Mirosław0a417702011-02-15 16:59:17 +0000369
Michał Mirosław86794882011-02-15 16:59:17 +0000370 /* compatibility with discrete get_ ops */
371 if (!(dev->hw_features & mask)) {
372 u32 (*actor)(struct net_device *);
373
374 actor = __ethtool_get_one_feature_actor(dev, ethcmd);
375
Michał Mirosławe83d3602011-02-15 16:59:18 +0000376 /* bug compatibility with old get_rx_csum */
377 if (ethcmd == ETHTOOL_GRXCSUM && !actor)
378 actor = __ethtool_get_rx_csum_oldbug;
379
Michał Mirosław86794882011-02-15 16:59:17 +0000380 if (actor)
381 edata.data = actor(dev);
382 }
Michał Mirosław0a417702011-02-15 16:59:17 +0000383
384 if (copy_to_user(useraddr, &edata, sizeof(edata)))
385 return -EFAULT;
386 return 0;
387}
388
389static int __ethtool_set_tx_csum(struct net_device *dev, u32 data);
Michał Mirosławe83d3602011-02-15 16:59:18 +0000390static int __ethtool_set_rx_csum(struct net_device *dev, u32 data);
Michał Mirosław0a417702011-02-15 16:59:17 +0000391static int __ethtool_set_sg(struct net_device *dev, u32 data);
392static int __ethtool_set_tso(struct net_device *dev, u32 data);
393static int __ethtool_set_ufo(struct net_device *dev, u32 data);
394
395static int ethtool_set_one_feature(struct net_device *dev,
396 void __user *useraddr, u32 ethcmd)
397{
398 struct ethtool_value edata;
399 u32 mask;
400
401 if (copy_from_user(&edata, useraddr, sizeof(edata)))
402 return -EFAULT;
403
Michał Mirosław86794882011-02-15 16:59:17 +0000404 mask = ethtool_get_feature_mask(ethcmd);
405 mask &= dev->hw_features;
406 if (mask) {
407 if (edata.data)
408 dev->wanted_features |= mask;
409 else
410 dev->wanted_features &= ~mask;
411
412 netdev_update_features(dev);
413 return 0;
414 }
415
416 /* Driver is not converted to ndo_fix_features or does not
417 * support changing this offload. In the latter case it won't
418 * have corresponding ethtool_ops field set.
419 *
420 * Following part is to be removed after all drivers advertise
421 * their changeable features in netdev->hw_features and stop
422 * using discrete offload setting ops.
423 */
424
Michał Mirosław0a417702011-02-15 16:59:17 +0000425 switch (ethcmd) {
426 case ETHTOOL_STXCSUM:
427 return __ethtool_set_tx_csum(dev, edata.data);
Michał Mirosławe83d3602011-02-15 16:59:18 +0000428 case ETHTOOL_SRXCSUM:
429 return __ethtool_set_rx_csum(dev, edata.data);
Michał Mirosław0a417702011-02-15 16:59:17 +0000430 case ETHTOOL_SSG:
431 return __ethtool_set_sg(dev, edata.data);
432 case ETHTOOL_STSO:
433 return __ethtool_set_tso(dev, edata.data);
434 case ETHTOOL_SUFO:
435 return __ethtool_set_ufo(dev, edata.data);
Michał Mirosław0a417702011-02-15 16:59:17 +0000436 default:
437 return -EOPNOTSUPP;
438 }
439}
440
Michał Mirosławda8ac86c2011-02-15 16:59:18 +0000441static int __ethtool_set_flags(struct net_device *dev, u32 data)
442{
443 u32 changed;
444
445 if (data & ~flags_dup_features)
446 return -EINVAL;
447
448 /* legacy set_flags() op */
449 if (dev->ethtool_ops->set_flags) {
450 if (unlikely(dev->hw_features & flags_dup_features))
451 netdev_warn(dev,
452 "driver BUG: mixed hw_features and set_flags()\n");
453 return dev->ethtool_ops->set_flags(dev, data);
454 }
455
456 /* allow changing only bits set in hw_features */
457 changed = (data ^ dev->wanted_features) & flags_dup_features;
458 if (changed & ~dev->hw_features)
459 return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
460
461 dev->wanted_features =
462 (dev->wanted_features & ~changed) | data;
463
464 netdev_update_features(dev);
465
466 return 0;
467}
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
470{
Roland Dreier8e557422010-02-11 12:14:23 -0800471 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 int err;
473
474 if (!dev->ethtool_ops->get_settings)
475 return -EOPNOTSUPP;
476
477 err = dev->ethtool_ops->get_settings(dev, &cmd);
478 if (err < 0)
479 return err;
480
481 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
482 return -EFAULT;
483 return 0;
484}
485
486static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
487{
488 struct ethtool_cmd cmd;
489
490 if (!dev->ethtool_ops->set_settings)
491 return -EOPNOTSUPP;
492
493 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
494 return -EFAULT;
495
496 return dev->ethtool_ops->set_settings(dev, &cmd);
497}
498
chavey97f8aef2010-04-07 21:54:42 -0700499static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
500 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700503 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 memset(&info, 0, sizeof(info));
506 info.cmd = ETHTOOL_GDRVINFO;
Ben Hutchings01414802010-08-17 02:31:15 -0700507 if (ops && ops->get_drvinfo) {
508 ops->get_drvinfo(dev, &info);
509 } else if (dev->dev.parent && dev->dev.parent->driver) {
510 strlcpy(info.bus_info, dev_name(dev->dev.parent),
511 sizeof(info.bus_info));
512 strlcpy(info.driver, dev->dev.parent->driver->name,
513 sizeof(info.driver));
514 } else {
515 return -EOPNOTSUPP;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Jeff Garzik723b2f52010-03-03 22:51:50 +0000518 /*
519 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000520 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000521 */
Ben Hutchings01414802010-08-17 02:31:15 -0700522 if (ops && ops->get_sset_count) {
Jeff Garzikff03d492007-08-15 16:01:08 -0700523 int rc;
524
525 rc = ops->get_sset_count(dev, ETH_SS_TEST);
526 if (rc >= 0)
527 info.testinfo_len = rc;
528 rc = ops->get_sset_count(dev, ETH_SS_STATS);
529 if (rc >= 0)
530 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700531 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
532 if (rc >= 0)
533 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700534 }
Ben Hutchings01414802010-08-17 02:31:15 -0700535 if (ops && ops->get_regs_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 info.regdump_len = ops->get_regs_len(dev);
Ben Hutchings01414802010-08-17 02:31:15 -0700537 if (ops && ops->get_eeprom_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 info.eedump_len = ops->get_eeprom_len(dev);
539
540 if (copy_to_user(useraddr, &info, sizeof(info)))
541 return -EFAULT;
542 return 0;
543}
544
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800545static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
chavey97f8aef2010-04-07 21:54:42 -0700546 void __user *useraddr)
Jeff Garzik723b2f52010-03-03 22:51:50 +0000547{
548 struct ethtool_sset_info info;
Jeff Garzik723b2f52010-03-03 22:51:50 +0000549 u64 sset_mask;
550 int i, idx = 0, n_bits = 0, ret, rc;
551 u32 *info_buf = NULL;
552
Jeff Garzik723b2f52010-03-03 22:51:50 +0000553 if (copy_from_user(&info, useraddr, sizeof(info)))
554 return -EFAULT;
555
556 /* store copy of mask, because we zero struct later on */
557 sset_mask = info.sset_mask;
558 if (!sset_mask)
559 return 0;
560
561 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000562 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000563
564 memset(&info, 0, sizeof(info));
565 info.cmd = ETHTOOL_GSSET_INFO;
566
567 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
568 if (!info_buf)
569 return -ENOMEM;
570
571 /*
572 * fill return buffer based on input bitmask and successful
573 * get_sset_count return
574 */
575 for (i = 0; i < 64; i++) {
576 if (!(sset_mask & (1ULL << i)))
577 continue;
578
Michał Mirosław340ae162011-02-15 16:59:16 +0000579 rc = __ethtool_get_sset_count(dev, i);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000580 if (rc >= 0) {
581 info.sset_mask |= (1ULL << i);
582 info_buf[idx++] = rc;
583 }
584 }
585
586 ret = -EFAULT;
587 if (copy_to_user(useraddr, &info, sizeof(info)))
588 goto out;
589
590 useraddr += offsetof(struct ethtool_sset_info, data);
591 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
592 goto out;
593
594 ret = 0;
595
596out:
597 kfree(info_buf);
598 return ret;
599}
600
chavey97f8aef2010-04-07 21:54:42 -0700601static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000602 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700603{
Ben Hutchingsbf988432010-06-28 08:45:58 +0000604 struct ethtool_rxnfc info;
605 size_t info_size = sizeof(info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700606
Santwona Behera59089d82009-02-20 00:58:13 -0800607 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700608 return -EOPNOTSUPP;
609
Ben Hutchingsbf988432010-06-28 08:45:58 +0000610 /* struct ethtool_rxnfc was originally defined for
611 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
612 * members. User-space might still be using that
613 * definition. */
614 if (cmd == ETHTOOL_SRXFH)
615 info_size = (offsetof(struct ethtool_rxnfc, data) +
616 sizeof(info.data));
617
618 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700619 return -EFAULT;
620
Ben Hutchingsbf988432010-06-28 08:45:58 +0000621 return dev->ethtool_ops->set_rxnfc(dev, &info);
Santwona Behera0853ad62008-07-02 03:47:41 -0700622}
623
chavey97f8aef2010-04-07 21:54:42 -0700624static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
Ben Hutchingsbf988432010-06-28 08:45:58 +0000625 u32 cmd, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700626{
627 struct ethtool_rxnfc info;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000628 size_t info_size = sizeof(info);
Santwona Behera59089d82009-02-20 00:58:13 -0800629 const struct ethtool_ops *ops = dev->ethtool_ops;
630 int ret;
631 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700632
Santwona Behera59089d82009-02-20 00:58:13 -0800633 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700634 return -EOPNOTSUPP;
635
Ben Hutchingsbf988432010-06-28 08:45:58 +0000636 /* struct ethtool_rxnfc was originally defined for
637 * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
638 * members. User-space might still be using that
639 * definition. */
640 if (cmd == ETHTOOL_GRXFH)
641 info_size = (offsetof(struct ethtool_rxnfc, data) +
642 sizeof(info.data));
643
644 if (copy_from_user(&info, useraddr, info_size))
Santwona Behera0853ad62008-07-02 03:47:41 -0700645 return -EFAULT;
646
Santwona Behera59089d82009-02-20 00:58:13 -0800647 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
648 if (info.rule_cnt > 0) {
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000649 if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
Kees Cookae6df5f2010-10-07 10:03:48 +0000650 rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
Ben Hutchingsdb048b62010-06-28 08:44:07 +0000651 GFP_USER);
Santwona Behera59089d82009-02-20 00:58:13 -0800652 if (!rule_buf)
653 return -ENOMEM;
654 }
655 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700656
Santwona Behera59089d82009-02-20 00:58:13 -0800657 ret = ops->get_rxnfc(dev, &info, rule_buf);
658 if (ret < 0)
659 goto err_out;
660
661 ret = -EFAULT;
Ben Hutchingsbf988432010-06-28 08:45:58 +0000662 if (copy_to_user(useraddr, &info, info_size))
Santwona Behera59089d82009-02-20 00:58:13 -0800663 goto err_out;
664
665 if (rule_buf) {
666 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
667 if (copy_to_user(useraddr, rule_buf,
668 info.rule_cnt * sizeof(u32)))
669 goto err_out;
670 }
671 ret = 0;
672
673err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700674 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800675
676 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700677}
678
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000679static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
680 void __user *useraddr)
681{
682 struct ethtool_rxfh_indir *indir;
683 u32 table_size;
684 size_t full_size;
685 int ret;
686
687 if (!dev->ethtool_ops->get_rxfh_indir)
688 return -EOPNOTSUPP;
689
690 if (copy_from_user(&table_size,
691 useraddr + offsetof(struct ethtool_rxfh_indir, size),
692 sizeof(table_size)))
693 return -EFAULT;
694
695 if (table_size >
696 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
697 return -ENOMEM;
698 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
Kees Cookb00916b2010-10-11 12:23:25 -0700699 indir = kzalloc(full_size, GFP_USER);
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +0000700 if (!indir)
701 return -ENOMEM;
702
703 indir->cmd = ETHTOOL_GRXFHINDIR;
704 indir->size = table_size;
705 ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
706 if (ret)
707 goto out;
708
709 if (copy_to_user(useraddr, indir, full_size))
710 ret = -EFAULT;
711
712out:
713 kfree(indir);
714 return ret;
715}
716
717static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
718 void __user *useraddr)
719{
720 struct ethtool_rxfh_indir *indir;
721 u32 table_size;
722 size_t full_size;
723 int ret;
724
725 if (!dev->ethtool_ops->set_rxfh_indir)
726 return -EOPNOTSUPP;
727
728 if (copy_from_user(&table_size,
729 useraddr + offsetof(struct ethtool_rxfh_indir, size),
730 sizeof(table_size)))
731 return -EFAULT;
732
733 if (table_size >
734 (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
735 return -ENOMEM;
736 full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
737 indir = kmalloc(full_size, GFP_USER);
738 if (!indir)
739 return -ENOMEM;
740
741 if (copy_from_user(indir, useraddr, full_size)) {
742 ret = -EFAULT;
743 goto out;
744 }
745
746 ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
747
748out:
749 kfree(indir);
750 return ret;
751}
752
Peter Waskiewicze8589112010-02-12 13:48:05 +0000753static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
chavey97f8aef2010-04-07 21:54:42 -0700754 struct ethtool_rx_ntuple_flow_spec *spec,
755 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800756{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800757
758 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000759 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
760 /* free the container */
761 kfree(fsc);
762 return;
763 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800764
765 /* Copy the whole filter over */
766 fsc->fs.flow_type = spec->flow_type;
767 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
768 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
769
770 fsc->fs.vlan_tag = spec->vlan_tag;
771 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
772 fsc->fs.data = spec->data;
773 fsc->fs.data_mask = spec->data_mask;
774 fsc->fs.action = spec->action;
775
776 /* add to the list */
777 list_add_tail_rcu(&fsc->list, &list->list);
778 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800779}
780
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000781/*
782 * ethtool does not (or did not) set masks for flow parameters that are
783 * not specified, so if both value and mask are 0 then this must be
784 * treated as equivalent to a mask with all bits set. Implement that
785 * here rather than in drivers.
786 */
787static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
788{
789 struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
790 struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
791
792 if (fs->flow_type != TCP_V4_FLOW &&
793 fs->flow_type != UDP_V4_FLOW &&
794 fs->flow_type != SCTP_V4_FLOW)
795 return;
796
797 if (!(entry->ip4src | mask->ip4src))
798 mask->ip4src = htonl(0xffffffff);
799 if (!(entry->ip4dst | mask->ip4dst))
800 mask->ip4dst = htonl(0xffffffff);
801 if (!(entry->psrc | mask->psrc))
802 mask->psrc = htons(0xffff);
803 if (!(entry->pdst | mask->pdst))
804 mask->pdst = htons(0xffff);
805 if (!(entry->tos | mask->tos))
806 mask->tos = 0xff;
807 if (!(fs->vlan_tag | fs->vlan_tag_mask))
808 fs->vlan_tag_mask = 0xffff;
809 if (!(fs->data | fs->data_mask))
810 fs->data_mask = 0xffffffffffffffffULL;
811}
812
chavey97f8aef2010-04-07 21:54:42 -0700813static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
814 void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800815{
816 struct ethtool_rx_ntuple cmd;
817 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000818 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800819 int ret;
820
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800821 if (!(dev->features & NETIF_F_NTUPLE))
822 return -EINVAL;
823
824 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
825 return -EFAULT;
826
Ben Hutchingsbe2902d2010-09-16 11:28:07 +0000827 rx_ntuple_fix_masks(&cmd.fs);
828
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800829 /*
830 * Cache filter in dev struct for GET operation only if
831 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000832 * only if the filter was added successfully. First make sure we
833 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800834 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000835 if (!ops->get_rx_ntuple) {
836 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
837 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800838 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000839 }
840
841 ret = ops->set_rx_ntuple(dev, &cmd);
842 if (ret) {
843 kfree(fsc);
844 return ret;
845 }
846
847 if (!ops->get_rx_ntuple)
848 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800849
850 return ret;
851}
852
853static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
854{
855 struct ethtool_gstrings gstrings;
856 const struct ethtool_ops *ops = dev->ethtool_ops;
857 struct ethtool_rx_ntuple_flow_spec_container *fsc;
858 u8 *data;
859 char *p;
860 int ret, i, num_strings = 0;
861
862 if (!ops->get_sset_count)
863 return -EOPNOTSUPP;
864
865 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
866 return -EFAULT;
867
868 ret = ops->get_sset_count(dev, gstrings.string_set);
869 if (ret < 0)
870 return ret;
871
872 gstrings.len = ret;
873
Kees Cookb00916b2010-10-11 12:23:25 -0700874 data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800875 if (!data)
876 return -ENOMEM;
877
878 if (ops->get_rx_ntuple) {
879 /* driver-specific filter grab */
880 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
881 goto copy;
882 }
883
884 /* default ethtool filter grab */
885 i = 0;
886 p = (char *)data;
887 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
888 sprintf(p, "Filter %d:\n", i);
889 p += ETH_GSTRING_LEN;
890 num_strings++;
891
892 switch (fsc->fs.flow_type) {
893 case TCP_V4_FLOW:
894 sprintf(p, "\tFlow Type: TCP\n");
895 p += ETH_GSTRING_LEN;
896 num_strings++;
897 break;
898 case UDP_V4_FLOW:
899 sprintf(p, "\tFlow Type: UDP\n");
900 p += ETH_GSTRING_LEN;
901 num_strings++;
902 break;
903 case SCTP_V4_FLOW:
904 sprintf(p, "\tFlow Type: SCTP\n");
905 p += ETH_GSTRING_LEN;
906 num_strings++;
907 break;
908 case AH_ESP_V4_FLOW:
909 sprintf(p, "\tFlow Type: AH ESP\n");
910 p += ETH_GSTRING_LEN;
911 num_strings++;
912 break;
913 case ESP_V4_FLOW:
914 sprintf(p, "\tFlow Type: ESP\n");
915 p += ETH_GSTRING_LEN;
916 num_strings++;
917 break;
918 case IP_USER_FLOW:
919 sprintf(p, "\tFlow Type: Raw IP\n");
920 p += ETH_GSTRING_LEN;
921 num_strings++;
922 break;
923 case IPV4_FLOW:
924 sprintf(p, "\tFlow Type: IPv4\n");
925 p += ETH_GSTRING_LEN;
926 num_strings++;
927 break;
928 default:
929 sprintf(p, "\tFlow Type: Unknown\n");
930 p += ETH_GSTRING_LEN;
931 num_strings++;
932 goto unknown_filter;
Joe Perchesccbd6a52010-05-14 10:58:26 +0000933 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800934
935 /* now the rest of the filters */
936 switch (fsc->fs.flow_type) {
937 case TCP_V4_FLOW:
938 case UDP_V4_FLOW:
939 case SCTP_V4_FLOW:
940 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700941 fsc->fs.h_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800942 p += ETH_GSTRING_LEN;
943 num_strings++;
944 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700945 fsc->fs.m_u.tcp_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800946 p += ETH_GSTRING_LEN;
947 num_strings++;
948 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700949 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800950 p += ETH_GSTRING_LEN;
951 num_strings++;
952 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700953 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800954 p += ETH_GSTRING_LEN;
955 num_strings++;
956 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700957 fsc->fs.h_u.tcp_ip4_spec.psrc,
958 fsc->fs.m_u.tcp_ip4_spec.psrc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800959 p += ETH_GSTRING_LEN;
960 num_strings++;
961 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700962 fsc->fs.h_u.tcp_ip4_spec.pdst,
963 fsc->fs.m_u.tcp_ip4_spec.pdst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800964 p += ETH_GSTRING_LEN;
965 num_strings++;
966 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700967 fsc->fs.h_u.tcp_ip4_spec.tos,
968 fsc->fs.m_u.tcp_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800969 p += ETH_GSTRING_LEN;
970 num_strings++;
971 break;
972 case AH_ESP_V4_FLOW:
973 case ESP_V4_FLOW:
974 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700975 fsc->fs.h_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800976 p += ETH_GSTRING_LEN;
977 num_strings++;
978 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700979 fsc->fs.m_u.ah_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800980 p += ETH_GSTRING_LEN;
981 num_strings++;
982 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700983 fsc->fs.h_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800984 p += ETH_GSTRING_LEN;
985 num_strings++;
986 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700987 fsc->fs.m_u.ah_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800988 p += ETH_GSTRING_LEN;
989 num_strings++;
990 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700991 fsc->fs.h_u.ah_ip4_spec.spi,
992 fsc->fs.m_u.ah_ip4_spec.spi);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800993 p += ETH_GSTRING_LEN;
994 num_strings++;
995 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -0700996 fsc->fs.h_u.ah_ip4_spec.tos,
997 fsc->fs.m_u.ah_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800998 p += ETH_GSTRING_LEN;
999 num_strings++;
1000 break;
1001 case IP_USER_FLOW:
1002 sprintf(p, "\tSrc IP addr: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +00001003 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001004 p += ETH_GSTRING_LEN;
1005 num_strings++;
1006 sprintf(p, "\tSrc IP mask: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +00001007 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001008 p += ETH_GSTRING_LEN;
1009 num_strings++;
1010 sprintf(p, "\tDest IP addr: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +00001011 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001012 p += ETH_GSTRING_LEN;
1013 num_strings++;
1014 sprintf(p, "\tDest IP mask: 0x%x\n",
Ben Hutchingse0de7c92010-09-14 09:13:08 +00001015 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001016 p += ETH_GSTRING_LEN;
1017 num_strings++;
1018 break;
1019 case IPV4_FLOW:
1020 sprintf(p, "\tSrc IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001021 fsc->fs.h_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001022 p += ETH_GSTRING_LEN;
1023 num_strings++;
1024 sprintf(p, "\tSrc IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001025 fsc->fs.m_u.usr_ip4_spec.ip4src);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001026 p += ETH_GSTRING_LEN;
1027 num_strings++;
1028 sprintf(p, "\tDest IP addr: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001029 fsc->fs.h_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001030 p += ETH_GSTRING_LEN;
1031 num_strings++;
1032 sprintf(p, "\tDest IP mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001033 fsc->fs.m_u.usr_ip4_spec.ip4dst);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001034 p += ETH_GSTRING_LEN;
1035 num_strings++;
1036 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001037 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
1038 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001039 p += ETH_GSTRING_LEN;
1040 num_strings++;
1041 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001042 fsc->fs.h_u.usr_ip4_spec.tos,
1043 fsc->fs.m_u.usr_ip4_spec.tos);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001044 p += ETH_GSTRING_LEN;
1045 num_strings++;
1046 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001047 fsc->fs.h_u.usr_ip4_spec.ip_ver,
1048 fsc->fs.m_u.usr_ip4_spec.ip_ver);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001049 p += ETH_GSTRING_LEN;
1050 num_strings++;
1051 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001052 fsc->fs.h_u.usr_ip4_spec.proto,
1053 fsc->fs.m_u.usr_ip4_spec.proto);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001054 p += ETH_GSTRING_LEN;
1055 num_strings++;
1056 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +00001057 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001058 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
chavey97f8aef2010-04-07 21:54:42 -07001059 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001060 p += ETH_GSTRING_LEN;
1061 num_strings++;
1062 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
1063 p += ETH_GSTRING_LEN;
1064 num_strings++;
1065 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
1066 p += ETH_GSTRING_LEN;
1067 num_strings++;
1068 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
1069 sprintf(p, "\tAction: Drop\n");
1070 else
1071 sprintf(p, "\tAction: Direct to queue %d\n",
chavey97f8aef2010-04-07 21:54:42 -07001072 fsc->fs.action);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001073 p += ETH_GSTRING_LEN;
1074 num_strings++;
1075unknown_filter:
1076 i++;
1077 }
1078copy:
1079 /* indicate to userspace how many strings we actually have */
1080 gstrings.len = num_strings;
1081 ret = -EFAULT;
1082 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1083 goto out;
1084 useraddr += sizeof(gstrings);
1085 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1086 goto out;
1087 ret = 0;
1088
1089out:
1090 kfree(data);
1091 return ret;
1092}
1093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
1095{
1096 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001097 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 void *regbuf;
1099 int reglen, ret;
1100
1101 if (!ops->get_regs || !ops->get_regs_len)
1102 return -EOPNOTSUPP;
1103
1104 if (copy_from_user(&regs, useraddr, sizeof(regs)))
1105 return -EFAULT;
1106
1107 reglen = ops->get_regs_len(dev);
1108 if (regs.len > reglen)
1109 regs.len = reglen;
1110
Eugene Teob7c7d012011-01-24 21:05:17 -08001111 regbuf = vzalloc(reglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (!regbuf)
1113 return -ENOMEM;
1114
1115 ops->get_regs(dev, &regs, regbuf);
1116
1117 ret = -EFAULT;
1118 if (copy_to_user(useraddr, &regs, sizeof(regs)))
1119 goto out;
1120 useraddr += offsetof(struct ethtool_regs, data);
1121 if (copy_to_user(useraddr, regbuf, regs.len))
1122 goto out;
1123 ret = 0;
1124
1125 out:
Ben Hutchingsa77f5db2010-09-20 08:42:17 +00001126 vfree(regbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return ret;
1128}
1129
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001130static int ethtool_reset(struct net_device *dev, char __user *useraddr)
1131{
1132 struct ethtool_value reset;
1133 int ret;
1134
1135 if (!dev->ethtool_ops->reset)
1136 return -EOPNOTSUPP;
1137
1138 if (copy_from_user(&reset, useraddr, sizeof(reset)))
1139 return -EFAULT;
1140
1141 ret = dev->ethtool_ops->reset(dev, &reset.data);
1142 if (ret)
1143 return ret;
1144
1145 if (copy_to_user(useraddr, &reset, sizeof(reset)))
1146 return -EFAULT;
1147 return 0;
1148}
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
1151{
Roland Dreier8e557422010-02-11 12:14:23 -08001152 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 if (!dev->ethtool_ops->get_wol)
1155 return -EOPNOTSUPP;
1156
1157 dev->ethtool_ops->get_wol(dev, &wol);
1158
1159 if (copy_to_user(useraddr, &wol, sizeof(wol)))
1160 return -EFAULT;
1161 return 0;
1162}
1163
1164static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
1165{
1166 struct ethtool_wolinfo wol;
1167
1168 if (!dev->ethtool_ops->set_wol)
1169 return -EOPNOTSUPP;
1170
1171 if (copy_from_user(&wol, useraddr, sizeof(wol)))
1172 return -EFAULT;
1173
1174 return dev->ethtool_ops->set_wol(dev, &wol);
1175}
1176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177static int ethtool_nway_reset(struct net_device *dev)
1178{
1179 if (!dev->ethtool_ops->nway_reset)
1180 return -EOPNOTSUPP;
1181
1182 return dev->ethtool_ops->nway_reset(dev);
1183}
1184
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001185static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
1186{
1187 struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
1188
1189 if (!dev->ethtool_ops->get_link)
1190 return -EOPNOTSUPP;
1191
1192 edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
1193
1194 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1195 return -EFAULT;
1196 return 0;
1197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
1200{
1201 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001202 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001203 void __user *userbuf = useraddr + sizeof(eeprom);
1204 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001206 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 if (!ops->get_eeprom || !ops->get_eeprom_len)
1209 return -EOPNOTSUPP;
1210
1211 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1212 return -EFAULT;
1213
1214 /* Check for wrap and zero */
1215 if (eeprom.offset + eeprom.len <= eeprom.offset)
1216 return -EINVAL;
1217
1218 /* Check for exceeding total eeprom len */
1219 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1220 return -EINVAL;
1221
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001222 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 if (!data)
1224 return -ENOMEM;
1225
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001226 bytes_remaining = eeprom.len;
1227 while (bytes_remaining > 0) {
1228 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001230 ret = ops->get_eeprom(dev, &eeprom, data);
1231 if (ret)
1232 break;
1233 if (copy_to_user(userbuf, data, eeprom.len)) {
1234 ret = -EFAULT;
1235 break;
1236 }
1237 userbuf += eeprom.len;
1238 eeprom.offset += eeprom.len;
1239 bytes_remaining -= eeprom.len;
1240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -07001242 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
1243 eeprom.offset -= eeprom.len;
1244 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
1245 ret = -EFAULT;
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 kfree(data);
1248 return ret;
1249}
1250
1251static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
1252{
1253 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001254 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001255 void __user *userbuf = useraddr + sizeof(eeprom);
1256 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001258 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 if (!ops->set_eeprom || !ops->get_eeprom_len)
1261 return -EOPNOTSUPP;
1262
1263 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
1264 return -EFAULT;
1265
1266 /* Check for wrap and zero */
1267 if (eeprom.offset + eeprom.len <= eeprom.offset)
1268 return -EINVAL;
1269
1270 /* Check for exceeding total eeprom len */
1271 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
1272 return -EINVAL;
1273
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001274 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if (!data)
1276 return -ENOMEM;
1277
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001278 bytes_remaining = eeprom.len;
1279 while (bytes_remaining > 0) {
1280 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -07001282 if (copy_from_user(data, userbuf, eeprom.len)) {
1283 ret = -EFAULT;
1284 break;
1285 }
1286 ret = ops->set_eeprom(dev, &eeprom, data);
1287 if (ret)
1288 break;
1289 userbuf += eeprom.len;
1290 eeprom.offset += eeprom.len;
1291 bytes_remaining -= eeprom.len;
1292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 kfree(data);
1295 return ret;
1296}
1297
chavey97f8aef2010-04-07 21:54:42 -07001298static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
1299 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Roland Dreier8e557422010-02-11 12:14:23 -08001301 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 if (!dev->ethtool_ops->get_coalesce)
1304 return -EOPNOTSUPP;
1305
1306 dev->ethtool_ops->get_coalesce(dev, &coalesce);
1307
1308 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
1309 return -EFAULT;
1310 return 0;
1311}
1312
chavey97f8aef2010-04-07 21:54:42 -07001313static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
1314 void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 struct ethtool_coalesce coalesce;
1317
David S. Millerfa04ae52005-06-06 15:07:19 -07001318 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 return -EOPNOTSUPP;
1320
1321 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
1322 return -EFAULT;
1323
1324 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
1325}
1326
1327static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
1328{
Roland Dreier8e557422010-02-11 12:14:23 -08001329 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
1331 if (!dev->ethtool_ops->get_ringparam)
1332 return -EOPNOTSUPP;
1333
1334 dev->ethtool_ops->get_ringparam(dev, &ringparam);
1335
1336 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
1337 return -EFAULT;
1338 return 0;
1339}
1340
1341static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
1342{
1343 struct ethtool_ringparam ringparam;
1344
1345 if (!dev->ethtool_ops->set_ringparam)
1346 return -EOPNOTSUPP;
1347
1348 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
1349 return -EFAULT;
1350
1351 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
1352}
1353
1354static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
1355{
1356 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
1357
1358 if (!dev->ethtool_ops->get_pauseparam)
1359 return -EOPNOTSUPP;
1360
1361 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
1362
1363 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
1364 return -EFAULT;
1365 return 0;
1366}
1367
1368static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
1369{
1370 struct ethtool_pauseparam pauseparam;
1371
Jeff Garzike1b90c42006-07-17 12:54:40 -04001372 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 return -EOPNOTSUPP;
1374
1375 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
1376 return -EFAULT;
1377
1378 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
1379}
1380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381static int __ethtool_set_sg(struct net_device *dev, u32 data)
1382{
1383 int err;
1384
Michał Mirosław0a417702011-02-15 16:59:17 +00001385 if (data && !(dev->features & NETIF_F_ALL_CSUM))
1386 return -EINVAL;
1387
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 if (!data && dev->ethtool_ops->set_tso) {
1389 err = dev->ethtool_ops->set_tso(dev, 0);
1390 if (err)
1391 return err;
1392 }
1393
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001394 if (!data && dev->ethtool_ops->set_ufo) {
1395 err = dev->ethtool_ops->set_ufo(dev, 0);
1396 if (err)
1397 return err;
1398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 return dev->ethtool_ops->set_sg(dev, data);
1400}
1401
Michał Mirosław0a417702011-02-15 16:59:17 +00001402static int __ethtool_set_tx_csum(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 int err;
1405
1406 if (!dev->ethtool_ops->set_tx_csum)
1407 return -EOPNOTSUPP;
1408
Michał Mirosław0a417702011-02-15 16:59:17 +00001409 if (!data && dev->ethtool_ops->set_sg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 err = __ethtool_set_sg(dev, 0);
1411 if (err)
1412 return err;
1413 }
1414
Michał Mirosław0a417702011-02-15 16:59:17 +00001415 return dev->ethtool_ops->set_tx_csum(dev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Michał Mirosławe83d3602011-02-15 16:59:18 +00001418static int __ethtool_set_rx_csum(struct net_device *dev, u32 data)
Herbert Xub240a0e2008-12-15 23:44:31 -08001419{
Herbert Xub240a0e2008-12-15 23:44:31 -08001420 if (!dev->ethtool_ops->set_rx_csum)
1421 return -EOPNOTSUPP;
1422
Michał Mirosławe83d3602011-02-15 16:59:18 +00001423 if (!data)
Herbert Xub240a0e2008-12-15 23:44:31 -08001424 dev->features &= ~NETIF_F_GRO;
1425
Michał Mirosławe83d3602011-02-15 16:59:18 +00001426 return dev->ethtool_ops->set_rx_csum(dev, data);
Herbert Xub240a0e2008-12-15 23:44:31 -08001427}
1428
Michał Mirosław0a417702011-02-15 16:59:17 +00001429static int __ethtool_set_tso(struct net_device *dev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 if (!dev->ethtool_ops->set_tso)
1432 return -EOPNOTSUPP;
1433
Michał Mirosław0a417702011-02-15 16:59:17 +00001434 if (data && !(dev->features & NETIF_F_SG))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return -EINVAL;
1436
Michał Mirosław0a417702011-02-15 16:59:17 +00001437 return dev->ethtool_ops->set_tso(dev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Michał Mirosław0a417702011-02-15 16:59:17 +00001440static int __ethtool_set_ufo(struct net_device *dev, u32 data)
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001441{
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001442 if (!dev->ethtool_ops->set_ufo)
1443 return -EOPNOTSUPP;
Michał Mirosław0a417702011-02-15 16:59:17 +00001444 if (data && !(dev->features & NETIF_F_SG))
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001445 return -EINVAL;
Michał Mirosław0a417702011-02-15 16:59:17 +00001446 if (data && !((dev->features & NETIF_F_GEN_CSUM) ||
Michał Mirosław79032642010-11-30 06:38:00 +00001447 (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
1448 == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)))
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001449 return -EINVAL;
Michał Mirosław0a417702011-02-15 16:59:17 +00001450 return dev->ethtool_ops->set_ufo(dev, data);
Herbert Xub240a0e2008-12-15 23:44:31 -08001451}
1452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1454{
1455 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001456 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001458 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001460 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001461 return -EOPNOTSUPP;
1462
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001463 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001464 if (test_len < 0)
1465 return test_len;
1466 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 if (copy_from_user(&test, useraddr, sizeof(test)))
1469 return -EFAULT;
1470
Jeff Garzikff03d492007-08-15 16:01:08 -07001471 test.len = test_len;
1472 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 if (!data)
1474 return -ENOMEM;
1475
1476 ops->self_test(dev, &test, data);
1477
1478 ret = -EFAULT;
1479 if (copy_to_user(useraddr, &test, sizeof(test)))
1480 goto out;
1481 useraddr += sizeof(test);
1482 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1483 goto out;
1484 ret = 0;
1485
1486 out:
1487 kfree(data);
1488 return ret;
1489}
1490
1491static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1492{
1493 struct ethtool_gstrings gstrings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 u8 *data;
1495 int ret;
1496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1498 return -EFAULT;
1499
Michał Mirosław340ae162011-02-15 16:59:16 +00001500 ret = __ethtool_get_sset_count(dev, gstrings.string_set);
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001501 if (ret < 0)
1502 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001503
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001504 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1507 if (!data)
1508 return -ENOMEM;
1509
Michał Mirosław340ae162011-02-15 16:59:16 +00001510 __ethtool_get_strings(dev, gstrings.string_set, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 ret = -EFAULT;
1513 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1514 goto out;
1515 useraddr += sizeof(gstrings);
1516 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1517 goto out;
1518 ret = 0;
1519
Michał Mirosław340ae162011-02-15 16:59:16 +00001520out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 kfree(data);
1522 return ret;
1523}
1524
1525static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1526{
1527 struct ethtool_value id;
1528
1529 if (!dev->ethtool_ops->phys_id)
1530 return -EOPNOTSUPP;
1531
1532 if (copy_from_user(&id, useraddr, sizeof(id)))
1533 return -EFAULT;
1534
1535 return dev->ethtool_ops->phys_id(dev, id.data);
1536}
1537
1538static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1539{
1540 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001541 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001543 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001545 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001546 return -EOPNOTSUPP;
1547
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001548 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001549 if (n_stats < 0)
1550 return n_stats;
1551 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1554 return -EFAULT;
1555
Jeff Garzikff03d492007-08-15 16:01:08 -07001556 stats.n_stats = n_stats;
1557 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 if (!data)
1559 return -ENOMEM;
1560
1561 ops->get_ethtool_stats(dev, &stats, data);
1562
1563 ret = -EFAULT;
1564 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1565 goto out;
1566 useraddr += sizeof(stats);
1567 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1568 goto out;
1569 ret = 0;
1570
1571 out:
1572 kfree(data);
1573 return ret;
1574}
1575
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001576static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001577{
1578 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001579
Matthew Wilcox313674a2007-07-31 14:00:29 -07001580 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001581 return -EFAULT;
1582
Matthew Wilcox313674a2007-07-31 14:00:29 -07001583 if (epaddr.size < dev->addr_len)
1584 return -ETOOSMALL;
1585 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001586
Jon Wetzela6f9a702005-08-20 17:15:54 -07001587 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001588 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001589 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001590 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1591 return -EFAULT;
1592 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001593}
1594
Jeff Garzik13c99b22007-08-15 16:01:56 -07001595static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1596 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001597{
Roland Dreier8e557422010-02-11 12:14:23 -08001598 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001599
Jeff Garzik13c99b22007-08-15 16:01:56 -07001600 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001601 return -EOPNOTSUPP;
1602
Jeff Garzik13c99b22007-08-15 16:01:56 -07001603 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001604
1605 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1606 return -EFAULT;
1607 return 0;
1608}
1609
Jeff Garzik13c99b22007-08-15 16:01:56 -07001610static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1611 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001612{
1613 struct ethtool_value edata;
1614
Jeff Garzik13c99b22007-08-15 16:01:56 -07001615 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001616 return -EOPNOTSUPP;
1617
1618 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1619 return -EFAULT;
1620
Jeff Garzik13c99b22007-08-15 16:01:56 -07001621 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001622 return 0;
1623}
1624
Jeff Garzik13c99b22007-08-15 16:01:56 -07001625static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1626 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001627{
1628 struct ethtool_value edata;
1629
Jeff Garzik13c99b22007-08-15 16:01:56 -07001630 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001631 return -EOPNOTSUPP;
1632
1633 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1634 return -EFAULT;
1635
Jeff Garzik13c99b22007-08-15 16:01:56 -07001636 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001637}
1638
chavey97f8aef2010-04-07 21:54:42 -07001639static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
1640 char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001641{
1642 struct ethtool_flash efl;
1643
1644 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1645 return -EFAULT;
1646
1647 if (!dev->ethtool_ops->flash_device)
1648 return -EOPNOTSUPP;
1649
1650 return dev->ethtool_ops->flash_device(dev, &efl);
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/* The main entry point in this file. Called from net/core/dev.c */
1654
Eric W. Biederman881d9662007-09-17 11:56:21 -07001655int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001657 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 void __user *useraddr = ifr->ifr_data;
1659 u32 ethcmd;
1660 int rc;
Michał Mirosław04ed3e72011-01-24 15:32:47 -08001661 u32 old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 if (!dev || !netif_device_present(dev))
1664 return -ENODEV;
1665
chavey97f8aef2010-04-07 21:54:42 -07001666 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 return -EFAULT;
1668
Ben Hutchings01414802010-08-17 02:31:15 -07001669 if (!dev->ethtool_ops) {
1670 /* ETHTOOL_GDRVINFO does not require any driver support.
1671 * It is also unprivileged and does not change anything,
1672 * so we can take a shortcut to it. */
1673 if (ethcmd == ETHTOOL_GDRVINFO)
1674 return ethtool_get_drvinfo(dev, useraddr);
1675 else
1676 return -EOPNOTSUPP;
1677 }
1678
Stephen Hemminger75f31232006-09-28 15:13:37 -07001679 /* Allow some commands to be done by anyone */
chavey97f8aef2010-04-07 21:54:42 -07001680 switch (ethcmd) {
stephen hemminger0fdc1002010-08-23 10:24:18 +00001681 case ETHTOOL_GSET:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001682 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001683 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001684 case ETHTOOL_GCOALESCE:
1685 case ETHTOOL_GRINGPARAM:
1686 case ETHTOOL_GPAUSEPARAM:
1687 case ETHTOOL_GRXCSUM:
1688 case ETHTOOL_GTXCSUM:
1689 case ETHTOOL_GSG:
1690 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001691 case ETHTOOL_GTSO:
1692 case ETHTOOL_GPERMADDR:
1693 case ETHTOOL_GUFO:
1694 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001695 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001696 case ETHTOOL_GFLAGS:
1697 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001698 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001699 case ETHTOOL_GRXRINGS:
1700 case ETHTOOL_GRXCLSRLCNT:
1701 case ETHTOOL_GRXCLSRULE:
1702 case ETHTOOL_GRXCLSRLALL:
Michał Mirosław5455c692011-02-15 16:59:17 +00001703 case ETHTOOL_GFEATURES:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001704 break;
1705 default:
1706 if (!capable(CAP_NET_ADMIN))
1707 return -EPERM;
1708 }
1709
chavey97f8aef2010-04-07 21:54:42 -07001710 if (dev->ethtool_ops->begin) {
1711 rc = dev->ethtool_ops->begin(dev);
1712 if (rc < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return rc;
chavey97f8aef2010-04-07 21:54:42 -07001714 }
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001715 old_features = dev->features;
1716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 switch (ethcmd) {
1718 case ETHTOOL_GSET:
1719 rc = ethtool_get_settings(dev, useraddr);
1720 break;
1721 case ETHTOOL_SSET:
1722 rc = ethtool_set_settings(dev, useraddr);
1723 break;
1724 case ETHTOOL_GDRVINFO:
1725 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 break;
1727 case ETHTOOL_GREGS:
1728 rc = ethtool_get_regs(dev, useraddr);
1729 break;
1730 case ETHTOOL_GWOL:
1731 rc = ethtool_get_wol(dev, useraddr);
1732 break;
1733 case ETHTOOL_SWOL:
1734 rc = ethtool_set_wol(dev, useraddr);
1735 break;
1736 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001737 rc = ethtool_get_value(dev, useraddr, ethcmd,
1738 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 break;
1740 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001741 rc = ethtool_set_value_void(dev, useraddr,
1742 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 break;
1744 case ETHTOOL_NWAY_RST:
1745 rc = ethtool_nway_reset(dev);
1746 break;
1747 case ETHTOOL_GLINK:
Ben Hutchingse596e6e2010-12-09 12:08:35 +00001748 rc = ethtool_get_link(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 break;
1750 case ETHTOOL_GEEPROM:
1751 rc = ethtool_get_eeprom(dev, useraddr);
1752 break;
1753 case ETHTOOL_SEEPROM:
1754 rc = ethtool_set_eeprom(dev, useraddr);
1755 break;
1756 case ETHTOOL_GCOALESCE:
1757 rc = ethtool_get_coalesce(dev, useraddr);
1758 break;
1759 case ETHTOOL_SCOALESCE:
1760 rc = ethtool_set_coalesce(dev, useraddr);
1761 break;
1762 case ETHTOOL_GRINGPARAM:
1763 rc = ethtool_get_ringparam(dev, useraddr);
1764 break;
1765 case ETHTOOL_SRINGPARAM:
1766 rc = ethtool_set_ringparam(dev, useraddr);
1767 break;
1768 case ETHTOOL_GPAUSEPARAM:
1769 rc = ethtool_get_pauseparam(dev, useraddr);
1770 break;
1771 case ETHTOOL_SPAUSEPARAM:
1772 rc = ethtool_set_pauseparam(dev, useraddr);
1773 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 case ETHTOOL_TEST:
1775 rc = ethtool_self_test(dev, useraddr);
1776 break;
1777 case ETHTOOL_GSTRINGS:
1778 rc = ethtool_get_strings(dev, useraddr);
1779 break;
1780 case ETHTOOL_PHYS_ID:
1781 rc = ethtool_phys_id(dev, useraddr);
1782 break;
1783 case ETHTOOL_GSTATS:
1784 rc = ethtool_get_stats(dev, useraddr);
1785 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001786 case ETHTOOL_GPERMADDR:
1787 rc = ethtool_get_perm_addr(dev, useraddr);
1788 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001789 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001790 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001791 (dev->ethtool_ops->get_flags ?
1792 dev->ethtool_ops->get_flags :
1793 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001794 break;
1795 case ETHTOOL_SFLAGS:
Michał Mirosławda8ac86c2011-02-15 16:59:18 +00001796 rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001797 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001798 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001799 rc = ethtool_get_value(dev, useraddr, ethcmd,
1800 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001801 break;
1802 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001803 rc = ethtool_set_value(dev, useraddr,
1804 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001805 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001806 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001807 case ETHTOOL_GRXRINGS:
1808 case ETHTOOL_GRXCLSRLCNT:
1809 case ETHTOOL_GRXCLSRULE:
1810 case ETHTOOL_GRXCLSRLALL:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001811 rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001812 break;
1813 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001814 case ETHTOOL_SRXCLSRLDEL:
1815 case ETHTOOL_SRXCLSRLINS:
Ben Hutchingsbf988432010-06-28 08:45:58 +00001816 rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001817 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001818 case ETHTOOL_FLASHDEV:
1819 rc = ethtool_flash_device(dev, useraddr);
1820 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001821 case ETHTOOL_RESET:
1822 rc = ethtool_reset(dev, useraddr);
1823 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001824 case ETHTOOL_SRXNTUPLE:
1825 rc = ethtool_set_rx_ntuple(dev, useraddr);
1826 break;
1827 case ETHTOOL_GRXNTUPLE:
1828 rc = ethtool_get_rx_ntuple(dev, useraddr);
1829 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001830 case ETHTOOL_GSSET_INFO:
1831 rc = ethtool_get_sset_info(dev, useraddr);
1832 break;
Ben Hutchingsa5b6ee22010-06-30 05:05:23 +00001833 case ETHTOOL_GRXFHINDIR:
1834 rc = ethtool_get_rxfh_indir(dev, useraddr);
1835 break;
1836 case ETHTOOL_SRXFHINDIR:
1837 rc = ethtool_set_rxfh_indir(dev, useraddr);
1838 break;
Michał Mirosław5455c692011-02-15 16:59:17 +00001839 case ETHTOOL_GFEATURES:
1840 rc = ethtool_get_features(dev, useraddr);
1841 break;
1842 case ETHTOOL_SFEATURES:
1843 rc = ethtool_set_features(dev, useraddr);
1844 break;
Michał Mirosław0a417702011-02-15 16:59:17 +00001845 case ETHTOOL_GTXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001846 case ETHTOOL_GRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001847 case ETHTOOL_GSG:
1848 case ETHTOOL_GTSO:
1849 case ETHTOOL_GUFO:
1850 case ETHTOOL_GGSO:
1851 case ETHTOOL_GGRO:
1852 rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
1853 break;
1854 case ETHTOOL_STXCSUM:
Michał Mirosławe83d3602011-02-15 16:59:18 +00001855 case ETHTOOL_SRXCSUM:
Michał Mirosław0a417702011-02-15 16:59:17 +00001856 case ETHTOOL_SSG:
1857 case ETHTOOL_STSO:
1858 case ETHTOOL_SUFO:
1859 case ETHTOOL_SGSO:
1860 case ETHTOOL_SGRO:
1861 rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
1862 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001864 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001866
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001867 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001869
1870 if (old_features != dev->features)
1871 netdev_features_change(dev);
1872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874}