blob: 73c81edde8d98d000e0941eaf98966906e6a7aeb [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/uaccess.h>
22
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090023/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 * Some useful ethtool_ops methods that're device independent.
25 * If we find that all drivers want to do the same thing here,
26 * we can turn these into dev_() function calls.
27 */
28
29u32 ethtool_op_get_link(struct net_device *dev)
30{
31 return netif_carrier_ok(dev) ? 1 : 0;
32}
33
Sridhar Samudrala1896e612009-07-22 13:38:22 +000034u32 ethtool_op_get_rx_csum(struct net_device *dev)
35{
36 return (dev->features & NETIF_F_ALL_CSUM) != 0;
37}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000038EXPORT_SYMBOL(ethtool_op_get_rx_csum);
Sridhar Samudrala1896e612009-07-22 13:38:22 +000039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040u32 ethtool_op_get_tx_csum(struct net_device *dev)
41{
Herbert Xu8648b302006-06-17 22:06:05 -070042 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000044EXPORT_SYMBOL(ethtool_op_get_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
47{
48 if (data)
49 dev->features |= NETIF_F_IP_CSUM;
50 else
51 dev->features &= ~NETIF_F_IP_CSUM;
52
53 return 0;
54}
55
Jon Mason69f6a0f2005-05-29 20:27:24 -070056int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
57{
58 if (data)
59 dev->features |= NETIF_F_HW_CSUM;
60 else
61 dev->features &= ~NETIF_F_HW_CSUM;
62
63 return 0;
64}
Michael Chan6460d942007-07-14 19:07:52 -070065
66int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
67{
68 if (data)
69 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
70 else
71 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
72
73 return 0;
74}
75
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}
80
81int ethtool_op_set_sg(struct net_device *dev, u32 data)
82{
83 if (data)
84 dev->features |= NETIF_F_SG;
85 else
86 dev->features &= ~NETIF_F_SG;
87
88 return 0;
89}
90
91u32 ethtool_op_get_tso(struct net_device *dev)
92{
93 return (dev->features & NETIF_F_TSO) != 0;
94}
95
96int ethtool_op_set_tso(struct net_device *dev, u32 data)
97{
98 if (data)
99 dev->features |= NETIF_F_TSO;
100 else
101 dev->features &= ~NETIF_F_TSO;
102
103 return 0;
104}
105
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700106u32 ethtool_op_get_ufo(struct net_device *dev)
107{
108 return (dev->features & NETIF_F_UFO) != 0;
109}
110
111int ethtool_op_set_ufo(struct net_device *dev, u32 data)
112{
113 if (data)
114 dev->features |= NETIF_F_UFO;
115 else
116 dev->features &= ~NETIF_F_UFO;
117 return 0;
118}
119
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700120/* the following list of flags are the same as their associated
121 * NETIF_F_xxx values in include/linux/netdevice.h
122 */
123static const u32 flags_dup_features =
stephen hemmingerb00fabb2010-03-29 14:47:27 +0000124 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700125
126u32 ethtool_op_get_flags(struct net_device *dev)
127{
128 /* in the future, this function will probably contain additional
129 * handling for flags which are not so easily handled
130 * by a simple masking operation
131 */
132
133 return dev->features & flags_dup_features;
134}
135
136int ethtool_op_set_flags(struct net_device *dev, u32 data)
137{
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000138 const struct ethtool_ops *ops = dev->ethtool_ops;
Jeff Garzik96754782010-02-26 21:43:38 +0000139 unsigned long features = dev->features;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000140
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700141 if (data & ETH_FLAG_LRO)
Jeff Garzik96754782010-02-26 21:43:38 +0000142 features |= NETIF_F_LRO;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700143 else
Jeff Garzik96754782010-02-26 21:43:38 +0000144 features &= ~NETIF_F_LRO;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700145
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000146 if (data & ETH_FLAG_NTUPLE) {
147 if (!ops->set_rx_ntuple)
148 return -EOPNOTSUPP;
Jeff Garzik96754782010-02-26 21:43:38 +0000149 features |= NETIF_F_NTUPLE;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000150 } else {
151 /* safe to clear regardless */
Jeff Garzik96754782010-02-26 21:43:38 +0000152 features &= ~NETIF_F_NTUPLE;
Peter Waskiewicz0d643e12010-02-12 13:48:25 +0000153 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800154
stephen hemmingerb00fabb2010-03-29 14:47:27 +0000155 if (data & ETH_FLAG_RXHASH)
156 features |= NETIF_F_RXHASH;
157 else
158 features &= ~NETIF_F_RXHASH;
159
Jeff Garzik96754782010-02-26 21:43:38 +0000160 dev->features = features;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700161 return 0;
162}
163
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800164void ethtool_ntuple_flush(struct net_device *dev)
165{
166 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
167
168 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
169 list_del(&fsc->list);
170 kfree(fsc);
171 }
172 dev->ethtool_ntuple_list.count = 0;
173}
174EXPORT_SYMBOL(ethtool_ntuple_flush);
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/* Handlers for each ethtool command */
177
178static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
179{
Roland Dreier8e557422010-02-11 12:14:23 -0800180 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 int err;
182
183 if (!dev->ethtool_ops->get_settings)
184 return -EOPNOTSUPP;
185
186 err = dev->ethtool_ops->get_settings(dev, &cmd);
187 if (err < 0)
188 return err;
189
190 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
191 return -EFAULT;
192 return 0;
193}
194
195static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
196{
197 struct ethtool_cmd cmd;
198
199 if (!dev->ethtool_ops->set_settings)
200 return -EOPNOTSUPP;
201
202 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
203 return -EFAULT;
204
205 return dev->ethtool_ops->set_settings(dev, &cmd);
206}
207
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800208static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700211 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 if (!ops->get_drvinfo)
214 return -EOPNOTSUPP;
215
216 memset(&info, 0, sizeof(info));
217 info.cmd = ETHTOOL_GDRVINFO;
218 ops->get_drvinfo(dev, &info);
219
Jeff Garzik723b2f52010-03-03 22:51:50 +0000220 /*
221 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000222 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000223 */
Jeff Garzikff03d492007-08-15 16:01:08 -0700224 if (ops->get_sset_count) {
225 int rc;
226
227 rc = ops->get_sset_count(dev, ETH_SS_TEST);
228 if (rc >= 0)
229 info.testinfo_len = rc;
230 rc = ops->get_sset_count(dev, ETH_SS_STATS);
231 if (rc >= 0)
232 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700233 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
234 if (rc >= 0)
235 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (ops->get_regs_len)
238 info.regdump_len = ops->get_regs_len(dev);
239 if (ops->get_eeprom_len)
240 info.eedump_len = ops->get_eeprom_len(dev);
241
242 if (copy_to_user(useraddr, &info, sizeof(info)))
243 return -EFAULT;
244 return 0;
245}
246
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800247static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
Jeff Garzik723b2f52010-03-03 22:51:50 +0000248 void __user *useraddr)
249{
250 struct ethtool_sset_info info;
251 const struct ethtool_ops *ops = dev->ethtool_ops;
252 u64 sset_mask;
253 int i, idx = 0, n_bits = 0, ret, rc;
254 u32 *info_buf = NULL;
255
256 if (!ops->get_sset_count)
257 return -EOPNOTSUPP;
258
259 if (copy_from_user(&info, useraddr, sizeof(info)))
260 return -EFAULT;
261
262 /* store copy of mask, because we zero struct later on */
263 sset_mask = info.sset_mask;
264 if (!sset_mask)
265 return 0;
266
267 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000268 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000269
270 memset(&info, 0, sizeof(info));
271 info.cmd = ETHTOOL_GSSET_INFO;
272
273 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
274 if (!info_buf)
275 return -ENOMEM;
276
277 /*
278 * fill return buffer based on input bitmask and successful
279 * get_sset_count return
280 */
281 for (i = 0; i < 64; i++) {
282 if (!(sset_mask & (1ULL << i)))
283 continue;
284
285 rc = ops->get_sset_count(dev, i);
286 if (rc >= 0) {
287 info.sset_mask |= (1ULL << i);
288 info_buf[idx++] = rc;
289 }
290 }
291
292 ret = -EFAULT;
293 if (copy_to_user(useraddr, &info, sizeof(info)))
294 goto out;
295
296 useraddr += offsetof(struct ethtool_sset_info, data);
297 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
298 goto out;
299
300 ret = 0;
301
302out:
303 kfree(info_buf);
304 return ret;
305}
306
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800307static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700308{
309 struct ethtool_rxnfc cmd;
310
Santwona Behera59089d82009-02-20 00:58:13 -0800311 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700312 return -EOPNOTSUPP;
313
314 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
315 return -EFAULT;
316
Santwona Behera59089d82009-02-20 00:58:13 -0800317 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700318}
319
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800320static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700321{
322 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800323 const struct ethtool_ops *ops = dev->ethtool_ops;
324 int ret;
325 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700326
Santwona Behera59089d82009-02-20 00:58:13 -0800327 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700328 return -EOPNOTSUPP;
329
330 if (copy_from_user(&info, useraddr, sizeof(info)))
331 return -EFAULT;
332
Santwona Behera59089d82009-02-20 00:58:13 -0800333 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
334 if (info.rule_cnt > 0) {
335 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
336 GFP_USER);
337 if (!rule_buf)
338 return -ENOMEM;
339 }
340 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700341
Santwona Behera59089d82009-02-20 00:58:13 -0800342 ret = ops->get_rxnfc(dev, &info, rule_buf);
343 if (ret < 0)
344 goto err_out;
345
346 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700347 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800348 goto err_out;
349
350 if (rule_buf) {
351 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
352 if (copy_to_user(useraddr, rule_buf,
353 info.rule_cnt * sizeof(u32)))
354 goto err_out;
355 }
356 ret = 0;
357
358err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700359 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800360
361 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700362}
363
Peter Waskiewicze8589112010-02-12 13:48:05 +0000364static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
365 struct ethtool_rx_ntuple_flow_spec *spec,
366 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800367{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800368
369 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000370 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
371 /* free the container */
372 kfree(fsc);
373 return;
374 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800375
376 /* Copy the whole filter over */
377 fsc->fs.flow_type = spec->flow_type;
378 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
379 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
380
381 fsc->fs.vlan_tag = spec->vlan_tag;
382 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
383 fsc->fs.data = spec->data;
384 fsc->fs.data_mask = spec->data_mask;
385 fsc->fs.action = spec->action;
386
387 /* add to the list */
388 list_add_tail_rcu(&fsc->list, &list->list);
389 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800390}
391
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800392static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800393{
394 struct ethtool_rx_ntuple cmd;
395 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000396 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800397 int ret;
398
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800399 if (!(dev->features & NETIF_F_NTUPLE))
400 return -EINVAL;
401
402 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
403 return -EFAULT;
404
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800405 /*
406 * Cache filter in dev struct for GET operation only if
407 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000408 * only if the filter was added successfully. First make sure we
409 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800410 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000411 if (!ops->get_rx_ntuple) {
412 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
413 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800414 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000415 }
416
417 ret = ops->set_rx_ntuple(dev, &cmd);
418 if (ret) {
419 kfree(fsc);
420 return ret;
421 }
422
423 if (!ops->get_rx_ntuple)
424 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800425
426 return ret;
427}
428
429static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
430{
431 struct ethtool_gstrings gstrings;
432 const struct ethtool_ops *ops = dev->ethtool_ops;
433 struct ethtool_rx_ntuple_flow_spec_container *fsc;
434 u8 *data;
435 char *p;
436 int ret, i, num_strings = 0;
437
438 if (!ops->get_sset_count)
439 return -EOPNOTSUPP;
440
441 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
442 return -EFAULT;
443
444 ret = ops->get_sset_count(dev, gstrings.string_set);
445 if (ret < 0)
446 return ret;
447
448 gstrings.len = ret;
449
450 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
451 if (!data)
452 return -ENOMEM;
453
454 if (ops->get_rx_ntuple) {
455 /* driver-specific filter grab */
456 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
457 goto copy;
458 }
459
460 /* default ethtool filter grab */
461 i = 0;
462 p = (char *)data;
463 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
464 sprintf(p, "Filter %d:\n", i);
465 p += ETH_GSTRING_LEN;
466 num_strings++;
467
468 switch (fsc->fs.flow_type) {
469 case TCP_V4_FLOW:
470 sprintf(p, "\tFlow Type: TCP\n");
471 p += ETH_GSTRING_LEN;
472 num_strings++;
473 break;
474 case UDP_V4_FLOW:
475 sprintf(p, "\tFlow Type: UDP\n");
476 p += ETH_GSTRING_LEN;
477 num_strings++;
478 break;
479 case SCTP_V4_FLOW:
480 sprintf(p, "\tFlow Type: SCTP\n");
481 p += ETH_GSTRING_LEN;
482 num_strings++;
483 break;
484 case AH_ESP_V4_FLOW:
485 sprintf(p, "\tFlow Type: AH ESP\n");
486 p += ETH_GSTRING_LEN;
487 num_strings++;
488 break;
489 case ESP_V4_FLOW:
490 sprintf(p, "\tFlow Type: ESP\n");
491 p += ETH_GSTRING_LEN;
492 num_strings++;
493 break;
494 case IP_USER_FLOW:
495 sprintf(p, "\tFlow Type: Raw IP\n");
496 p += ETH_GSTRING_LEN;
497 num_strings++;
498 break;
499 case IPV4_FLOW:
500 sprintf(p, "\tFlow Type: IPv4\n");
501 p += ETH_GSTRING_LEN;
502 num_strings++;
503 break;
504 default:
505 sprintf(p, "\tFlow Type: Unknown\n");
506 p += ETH_GSTRING_LEN;
507 num_strings++;
508 goto unknown_filter;
509 };
510
511 /* now the rest of the filters */
512 switch (fsc->fs.flow_type) {
513 case TCP_V4_FLOW:
514 case UDP_V4_FLOW:
515 case SCTP_V4_FLOW:
516 sprintf(p, "\tSrc IP addr: 0x%x\n",
517 fsc->fs.h_u.tcp_ip4_spec.ip4src);
518 p += ETH_GSTRING_LEN;
519 num_strings++;
520 sprintf(p, "\tSrc IP mask: 0x%x\n",
521 fsc->fs.m_u.tcp_ip4_spec.ip4src);
522 p += ETH_GSTRING_LEN;
523 num_strings++;
524 sprintf(p, "\tDest IP addr: 0x%x\n",
525 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
526 p += ETH_GSTRING_LEN;
527 num_strings++;
528 sprintf(p, "\tDest IP mask: 0x%x\n",
529 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
530 p += ETH_GSTRING_LEN;
531 num_strings++;
532 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
533 fsc->fs.h_u.tcp_ip4_spec.psrc,
534 fsc->fs.m_u.tcp_ip4_spec.psrc);
535 p += ETH_GSTRING_LEN;
536 num_strings++;
537 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
538 fsc->fs.h_u.tcp_ip4_spec.pdst,
539 fsc->fs.m_u.tcp_ip4_spec.pdst);
540 p += ETH_GSTRING_LEN;
541 num_strings++;
542 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
543 fsc->fs.h_u.tcp_ip4_spec.tos,
544 fsc->fs.m_u.tcp_ip4_spec.tos);
545 p += ETH_GSTRING_LEN;
546 num_strings++;
547 break;
548 case AH_ESP_V4_FLOW:
549 case ESP_V4_FLOW:
550 sprintf(p, "\tSrc IP addr: 0x%x\n",
551 fsc->fs.h_u.ah_ip4_spec.ip4src);
552 p += ETH_GSTRING_LEN;
553 num_strings++;
554 sprintf(p, "\tSrc IP mask: 0x%x\n",
555 fsc->fs.m_u.ah_ip4_spec.ip4src);
556 p += ETH_GSTRING_LEN;
557 num_strings++;
558 sprintf(p, "\tDest IP addr: 0x%x\n",
559 fsc->fs.h_u.ah_ip4_spec.ip4dst);
560 p += ETH_GSTRING_LEN;
561 num_strings++;
562 sprintf(p, "\tDest IP mask: 0x%x\n",
563 fsc->fs.m_u.ah_ip4_spec.ip4dst);
564 p += ETH_GSTRING_LEN;
565 num_strings++;
566 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
567 fsc->fs.h_u.ah_ip4_spec.spi,
568 fsc->fs.m_u.ah_ip4_spec.spi);
569 p += ETH_GSTRING_LEN;
570 num_strings++;
571 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
572 fsc->fs.h_u.ah_ip4_spec.tos,
573 fsc->fs.m_u.ah_ip4_spec.tos);
574 p += ETH_GSTRING_LEN;
575 num_strings++;
576 break;
577 case IP_USER_FLOW:
578 sprintf(p, "\tSrc IP addr: 0x%x\n",
579 fsc->fs.h_u.raw_ip4_spec.ip4src);
580 p += ETH_GSTRING_LEN;
581 num_strings++;
582 sprintf(p, "\tSrc IP mask: 0x%x\n",
583 fsc->fs.m_u.raw_ip4_spec.ip4src);
584 p += ETH_GSTRING_LEN;
585 num_strings++;
586 sprintf(p, "\tDest IP addr: 0x%x\n",
587 fsc->fs.h_u.raw_ip4_spec.ip4dst);
588 p += ETH_GSTRING_LEN;
589 num_strings++;
590 sprintf(p, "\tDest IP mask: 0x%x\n",
591 fsc->fs.m_u.raw_ip4_spec.ip4dst);
592 p += ETH_GSTRING_LEN;
593 num_strings++;
594 break;
595 case IPV4_FLOW:
596 sprintf(p, "\tSrc IP addr: 0x%x\n",
597 fsc->fs.h_u.usr_ip4_spec.ip4src);
598 p += ETH_GSTRING_LEN;
599 num_strings++;
600 sprintf(p, "\tSrc IP mask: 0x%x\n",
601 fsc->fs.m_u.usr_ip4_spec.ip4src);
602 p += ETH_GSTRING_LEN;
603 num_strings++;
604 sprintf(p, "\tDest IP addr: 0x%x\n",
605 fsc->fs.h_u.usr_ip4_spec.ip4dst);
606 p += ETH_GSTRING_LEN;
607 num_strings++;
608 sprintf(p, "\tDest IP mask: 0x%x\n",
609 fsc->fs.m_u.usr_ip4_spec.ip4dst);
610 p += ETH_GSTRING_LEN;
611 num_strings++;
612 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
613 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
614 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
615 p += ETH_GSTRING_LEN;
616 num_strings++;
617 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
618 fsc->fs.h_u.usr_ip4_spec.tos,
619 fsc->fs.m_u.usr_ip4_spec.tos);
620 p += ETH_GSTRING_LEN;
621 num_strings++;
622 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
623 fsc->fs.h_u.usr_ip4_spec.ip_ver,
624 fsc->fs.m_u.usr_ip4_spec.ip_ver);
625 p += ETH_GSTRING_LEN;
626 num_strings++;
627 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
628 fsc->fs.h_u.usr_ip4_spec.proto,
629 fsc->fs.m_u.usr_ip4_spec.proto);
630 p += ETH_GSTRING_LEN;
631 num_strings++;
632 break;
633 };
634 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
635 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
636 p += ETH_GSTRING_LEN;
637 num_strings++;
638 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
639 p += ETH_GSTRING_LEN;
640 num_strings++;
641 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
642 p += ETH_GSTRING_LEN;
643 num_strings++;
644 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
645 sprintf(p, "\tAction: Drop\n");
646 else
647 sprintf(p, "\tAction: Direct to queue %d\n",
648 fsc->fs.action);
649 p += ETH_GSTRING_LEN;
650 num_strings++;
651unknown_filter:
652 i++;
653 }
654copy:
655 /* indicate to userspace how many strings we actually have */
656 gstrings.len = num_strings;
657 ret = -EFAULT;
658 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
659 goto out;
660 useraddr += sizeof(gstrings);
661 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
662 goto out;
663 ret = 0;
664
665out:
666 kfree(data);
667 return ret;
668}
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
671{
672 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700673 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 void *regbuf;
675 int reglen, ret;
676
677 if (!ops->get_regs || !ops->get_regs_len)
678 return -EOPNOTSUPP;
679
680 if (copy_from_user(&regs, useraddr, sizeof(regs)))
681 return -EFAULT;
682
683 reglen = ops->get_regs_len(dev);
684 if (regs.len > reglen)
685 regs.len = reglen;
686
687 regbuf = kmalloc(reglen, GFP_USER);
688 if (!regbuf)
689 return -ENOMEM;
690
691 ops->get_regs(dev, &regs, regbuf);
692
693 ret = -EFAULT;
694 if (copy_to_user(useraddr, &regs, sizeof(regs)))
695 goto out;
696 useraddr += offsetof(struct ethtool_regs, data);
697 if (copy_to_user(useraddr, regbuf, regs.len))
698 goto out;
699 ret = 0;
700
701 out:
702 kfree(regbuf);
703 return ret;
704}
705
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000706static int ethtool_reset(struct net_device *dev, char __user *useraddr)
707{
708 struct ethtool_value reset;
709 int ret;
710
711 if (!dev->ethtool_ops->reset)
712 return -EOPNOTSUPP;
713
714 if (copy_from_user(&reset, useraddr, sizeof(reset)))
715 return -EFAULT;
716
717 ret = dev->ethtool_ops->reset(dev, &reset.data);
718 if (ret)
719 return ret;
720
721 if (copy_to_user(useraddr, &reset, sizeof(reset)))
722 return -EFAULT;
723 return 0;
724}
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
727{
Roland Dreier8e557422010-02-11 12:14:23 -0800728 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 if (!dev->ethtool_ops->get_wol)
731 return -EOPNOTSUPP;
732
733 dev->ethtool_ops->get_wol(dev, &wol);
734
735 if (copy_to_user(useraddr, &wol, sizeof(wol)))
736 return -EFAULT;
737 return 0;
738}
739
740static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
741{
742 struct ethtool_wolinfo wol;
743
744 if (!dev->ethtool_ops->set_wol)
745 return -EOPNOTSUPP;
746
747 if (copy_from_user(&wol, useraddr, sizeof(wol)))
748 return -EFAULT;
749
750 return dev->ethtool_ops->set_wol(dev, &wol);
751}
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753static int ethtool_nway_reset(struct net_device *dev)
754{
755 if (!dev->ethtool_ops->nway_reset)
756 return -EOPNOTSUPP;
757
758 return dev->ethtool_ops->nway_reset(dev);
759}
760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
762{
763 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700764 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700765 void __user *userbuf = useraddr + sizeof(eeprom);
766 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700768 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 if (!ops->get_eeprom || !ops->get_eeprom_len)
771 return -EOPNOTSUPP;
772
773 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
774 return -EFAULT;
775
776 /* Check for wrap and zero */
777 if (eeprom.offset + eeprom.len <= eeprom.offset)
778 return -EINVAL;
779
780 /* Check for exceeding total eeprom len */
781 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
782 return -EINVAL;
783
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700784 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if (!data)
786 return -ENOMEM;
787
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700788 bytes_remaining = eeprom.len;
789 while (bytes_remaining > 0) {
790 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700792 ret = ops->get_eeprom(dev, &eeprom, data);
793 if (ret)
794 break;
795 if (copy_to_user(userbuf, data, eeprom.len)) {
796 ret = -EFAULT;
797 break;
798 }
799 userbuf += eeprom.len;
800 eeprom.offset += eeprom.len;
801 bytes_remaining -= eeprom.len;
802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700804 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
805 eeprom.offset -= eeprom.len;
806 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
807 ret = -EFAULT;
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 kfree(data);
810 return ret;
811}
812
813static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
814{
815 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700816 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700817 void __user *userbuf = useraddr + sizeof(eeprom);
818 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700820 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 if (!ops->set_eeprom || !ops->get_eeprom_len)
823 return -EOPNOTSUPP;
824
825 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
826 return -EFAULT;
827
828 /* Check for wrap and zero */
829 if (eeprom.offset + eeprom.len <= eeprom.offset)
830 return -EINVAL;
831
832 /* Check for exceeding total eeprom len */
833 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
834 return -EINVAL;
835
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700836 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 if (!data)
838 return -ENOMEM;
839
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700840 bytes_remaining = eeprom.len;
841 while (bytes_remaining > 0) {
842 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700844 if (copy_from_user(data, userbuf, eeprom.len)) {
845 ret = -EFAULT;
846 break;
847 }
848 ret = ops->set_eeprom(dev, &eeprom, data);
849 if (ret)
850 break;
851 userbuf += eeprom.len;
852 eeprom.offset += eeprom.len;
853 bytes_remaining -= eeprom.len;
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 kfree(data);
857 return ret;
858}
859
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800860static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Roland Dreier8e557422010-02-11 12:14:23 -0800862 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 if (!dev->ethtool_ops->get_coalesce)
865 return -EOPNOTSUPP;
866
867 dev->ethtool_ops->get_coalesce(dev, &coalesce);
868
869 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
870 return -EFAULT;
871 return 0;
872}
873
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800874static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 struct ethtool_coalesce coalesce;
877
David S. Millerfa04ae52005-06-06 15:07:19 -0700878 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 return -EOPNOTSUPP;
880
881 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
882 return -EFAULT;
883
884 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
885}
886
887static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
888{
Roland Dreier8e557422010-02-11 12:14:23 -0800889 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 if (!dev->ethtool_ops->get_ringparam)
892 return -EOPNOTSUPP;
893
894 dev->ethtool_ops->get_ringparam(dev, &ringparam);
895
896 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
897 return -EFAULT;
898 return 0;
899}
900
901static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
902{
903 struct ethtool_ringparam ringparam;
904
905 if (!dev->ethtool_ops->set_ringparam)
906 return -EOPNOTSUPP;
907
908 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
909 return -EFAULT;
910
911 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
912}
913
914static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
915{
916 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
917
918 if (!dev->ethtool_ops->get_pauseparam)
919 return -EOPNOTSUPP;
920
921 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
922
923 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
924 return -EFAULT;
925 return 0;
926}
927
928static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
929{
930 struct ethtool_pauseparam pauseparam;
931
Jeff Garzike1b90c42006-07-17 12:54:40 -0400932 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return -EOPNOTSUPP;
934
935 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
936 return -EFAULT;
937
938 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
939}
940
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941static int __ethtool_set_sg(struct net_device *dev, u32 data)
942{
943 int err;
944
945 if (!data && dev->ethtool_ops->set_tso) {
946 err = dev->ethtool_ops->set_tso(dev, 0);
947 if (err)
948 return err;
949 }
950
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700951 if (!data && dev->ethtool_ops->set_ufo) {
952 err = dev->ethtool_ops->set_ufo(dev, 0);
953 if (err)
954 return err;
955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return dev->ethtool_ops->set_sg(dev, data);
957}
958
959static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
960{
961 struct ethtool_value edata;
962 int err;
963
964 if (!dev->ethtool_ops->set_tx_csum)
965 return -EOPNOTSUPP;
966
967 if (copy_from_user(&edata, useraddr, sizeof(edata)))
968 return -EFAULT;
969
970 if (!edata.data && dev->ethtool_ops->set_sg) {
971 err = __ethtool_set_sg(dev, 0);
972 if (err)
973 return err;
974 }
975
976 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
977}
978
Herbert Xub240a0e2008-12-15 23:44:31 -0800979static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
980{
981 struct ethtool_value edata;
982
983 if (!dev->ethtool_ops->set_rx_csum)
984 return -EOPNOTSUPP;
985
986 if (copy_from_user(&edata, useraddr, sizeof(edata)))
987 return -EFAULT;
988
989 if (!edata.data && dev->ethtool_ops->set_sg)
990 dev->features &= ~NETIF_F_GRO;
991
992 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
993}
994
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
996{
997 struct ethtool_value edata;
998
999 if (!dev->ethtool_ops->set_sg)
1000 return -EOPNOTSUPP;
1001
1002 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1003 return -EFAULT;
1004
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001005 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -07001006 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 return -EINVAL;
1008
1009 return __ethtool_set_sg(dev, edata.data);
1010}
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1013{
1014 struct ethtool_value edata;
1015
1016 if (!dev->ethtool_ops->set_tso)
1017 return -EOPNOTSUPP;
1018
1019 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1020 return -EFAULT;
1021
1022 if (edata.data && !(dev->features & NETIF_F_SG))
1023 return -EINVAL;
1024
1025 return dev->ethtool_ops->set_tso(dev, edata.data);
1026}
1027
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001028static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1029{
1030 struct ethtool_value edata;
1031
1032 if (!dev->ethtool_ops->set_ufo)
1033 return -EOPNOTSUPP;
1034 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1035 return -EFAULT;
1036 if (edata.data && !(dev->features & NETIF_F_SG))
1037 return -EINVAL;
1038 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1039 return -EINVAL;
1040 return dev->ethtool_ops->set_ufo(dev, edata.data);
1041}
1042
Herbert Xu37c31852006-06-22 03:07:29 -07001043static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1044{
1045 struct ethtool_value edata = { ETHTOOL_GGSO };
1046
1047 edata.data = dev->features & NETIF_F_GSO;
1048 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1049 return -EFAULT;
1050 return 0;
1051}
1052
1053static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1054{
1055 struct ethtool_value edata;
1056
1057 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1058 return -EFAULT;
1059 if (edata.data)
1060 dev->features |= NETIF_F_GSO;
1061 else
1062 dev->features &= ~NETIF_F_GSO;
1063 return 0;
1064}
1065
Herbert Xub240a0e2008-12-15 23:44:31 -08001066static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1067{
1068 struct ethtool_value edata = { ETHTOOL_GGRO };
1069
1070 edata.data = dev->features & NETIF_F_GRO;
1071 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1072 return -EFAULT;
1073 return 0;
1074}
1075
1076static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1077{
1078 struct ethtool_value edata;
1079
1080 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1081 return -EFAULT;
1082
1083 if (edata.data) {
1084 if (!dev->ethtool_ops->get_rx_csum ||
1085 !dev->ethtool_ops->get_rx_csum(dev))
1086 return -EINVAL;
1087 dev->features |= NETIF_F_GRO;
1088 } else
1089 dev->features &= ~NETIF_F_GRO;
1090
1091 return 0;
1092}
1093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1095{
1096 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001097 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001099 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001101 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001102 return -EOPNOTSUPP;
1103
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001104 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001105 if (test_len < 0)
1106 return test_len;
1107 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 if (copy_from_user(&test, useraddr, sizeof(test)))
1110 return -EFAULT;
1111
Jeff Garzikff03d492007-08-15 16:01:08 -07001112 test.len = test_len;
1113 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (!data)
1115 return -ENOMEM;
1116
1117 ops->self_test(dev, &test, data);
1118
1119 ret = -EFAULT;
1120 if (copy_to_user(useraddr, &test, sizeof(test)))
1121 goto out;
1122 useraddr += sizeof(test);
1123 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1124 goto out;
1125 ret = 0;
1126
1127 out:
1128 kfree(data);
1129 return ret;
1130}
1131
1132static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1133{
1134 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001135 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 u8 *data;
1137 int ret;
1138
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001139 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 return -EOPNOTSUPP;
1141
1142 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1143 return -EFAULT;
1144
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001145 ret = ops->get_sset_count(dev, gstrings.string_set);
1146 if (ret < 0)
1147 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001148
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001149 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1152 if (!data)
1153 return -ENOMEM;
1154
1155 ops->get_strings(dev, gstrings.string_set, data);
1156
1157 ret = -EFAULT;
1158 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1159 goto out;
1160 useraddr += sizeof(gstrings);
1161 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1162 goto out;
1163 ret = 0;
1164
1165 out:
1166 kfree(data);
1167 return ret;
1168}
1169
1170static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1171{
1172 struct ethtool_value id;
1173
1174 if (!dev->ethtool_ops->phys_id)
1175 return -EOPNOTSUPP;
1176
1177 if (copy_from_user(&id, useraddr, sizeof(id)))
1178 return -EFAULT;
1179
1180 return dev->ethtool_ops->phys_id(dev, id.data);
1181}
1182
1183static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1184{
1185 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001186 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001188 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001190 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001191 return -EOPNOTSUPP;
1192
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001193 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001194 if (n_stats < 0)
1195 return n_stats;
1196 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1199 return -EFAULT;
1200
Jeff Garzikff03d492007-08-15 16:01:08 -07001201 stats.n_stats = n_stats;
1202 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 if (!data)
1204 return -ENOMEM;
1205
1206 ops->get_ethtool_stats(dev, &stats, data);
1207
1208 ret = -EFAULT;
1209 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1210 goto out;
1211 useraddr += sizeof(stats);
1212 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1213 goto out;
1214 ret = 0;
1215
1216 out:
1217 kfree(data);
1218 return ret;
1219}
1220
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001221static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001222{
1223 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001224
Matthew Wilcox313674a2007-07-31 14:00:29 -07001225 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001226 return -EFAULT;
1227
Matthew Wilcox313674a2007-07-31 14:00:29 -07001228 if (epaddr.size < dev->addr_len)
1229 return -ETOOSMALL;
1230 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001231
Jon Wetzela6f9a702005-08-20 17:15:54 -07001232 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001233 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001234 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001235 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1236 return -EFAULT;
1237 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001238}
1239
Jeff Garzik13c99b22007-08-15 16:01:56 -07001240static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1241 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001242{
Roland Dreier8e557422010-02-11 12:14:23 -08001243 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001244
Jeff Garzik13c99b22007-08-15 16:01:56 -07001245 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001246 return -EOPNOTSUPP;
1247
Jeff Garzik13c99b22007-08-15 16:01:56 -07001248 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001249
1250 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1251 return -EFAULT;
1252 return 0;
1253}
1254
Jeff Garzik13c99b22007-08-15 16:01:56 -07001255static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1256 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001257{
1258 struct ethtool_value edata;
1259
Jeff Garzik13c99b22007-08-15 16:01:56 -07001260 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001261 return -EOPNOTSUPP;
1262
1263 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1264 return -EFAULT;
1265
Jeff Garzik13c99b22007-08-15 16:01:56 -07001266 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001267 return 0;
1268}
1269
Jeff Garzik13c99b22007-08-15 16:01:56 -07001270static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1271 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001272{
1273 struct ethtool_value edata;
1274
Jeff Garzik13c99b22007-08-15 16:01:56 -07001275 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001276 return -EOPNOTSUPP;
1277
1278 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1279 return -EFAULT;
1280
Jeff Garzik13c99b22007-08-15 16:01:56 -07001281 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001282}
1283
Eric Dumazetf5c445e2010-03-08 12:17:04 -08001284static noinline_for_stack int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001285{
1286 struct ethtool_flash efl;
1287
1288 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1289 return -EFAULT;
1290
1291 if (!dev->ethtool_ops->flash_device)
1292 return -EOPNOTSUPP;
1293
1294 return dev->ethtool_ops->flash_device(dev, &efl);
1295}
1296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297/* The main entry point in this file. Called from net/core/dev.c */
1298
Eric W. Biederman881d9662007-09-17 11:56:21 -07001299int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001301 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 void __user *useraddr = ifr->ifr_data;
1303 u32 ethcmd;
1304 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -07001305 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 if (!dev || !netif_device_present(dev))
1308 return -ENODEV;
1309
1310 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001311 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
1313 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1314 return -EFAULT;
1315
Stephen Hemminger75f31232006-09-28 15:13:37 -07001316 /* Allow some commands to be done by anyone */
1317 switch(ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -07001318 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001319 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001320 case ETHTOOL_GCOALESCE:
1321 case ETHTOOL_GRINGPARAM:
1322 case ETHTOOL_GPAUSEPARAM:
1323 case ETHTOOL_GRXCSUM:
1324 case ETHTOOL_GTXCSUM:
1325 case ETHTOOL_GSG:
1326 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001327 case ETHTOOL_GTSO:
1328 case ETHTOOL_GPERMADDR:
1329 case ETHTOOL_GUFO:
1330 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001331 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001332 case ETHTOOL_GFLAGS:
1333 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001334 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001335 case ETHTOOL_GRXRINGS:
1336 case ETHTOOL_GRXCLSRLCNT:
1337 case ETHTOOL_GRXCLSRULE:
1338 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001339 break;
1340 default:
1341 if (!capable(CAP_NET_ADMIN))
1342 return -EPERM;
1343 }
1344
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001345 if (dev->ethtool_ops->begin)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1347 return rc;
1348
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001349 old_features = dev->features;
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 switch (ethcmd) {
1352 case ETHTOOL_GSET:
1353 rc = ethtool_get_settings(dev, useraddr);
1354 break;
1355 case ETHTOOL_SSET:
1356 rc = ethtool_set_settings(dev, useraddr);
1357 break;
1358 case ETHTOOL_GDRVINFO:
1359 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 break;
1361 case ETHTOOL_GREGS:
1362 rc = ethtool_get_regs(dev, useraddr);
1363 break;
1364 case ETHTOOL_GWOL:
1365 rc = ethtool_get_wol(dev, useraddr);
1366 break;
1367 case ETHTOOL_SWOL:
1368 rc = ethtool_set_wol(dev, useraddr);
1369 break;
1370 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001371 rc = ethtool_get_value(dev, useraddr, ethcmd,
1372 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 break;
1374 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001375 rc = ethtool_set_value_void(dev, useraddr,
1376 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 break;
1378 case ETHTOOL_NWAY_RST:
1379 rc = ethtool_nway_reset(dev);
1380 break;
1381 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001382 rc = ethtool_get_value(dev, useraddr, ethcmd,
1383 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 break;
1385 case ETHTOOL_GEEPROM:
1386 rc = ethtool_get_eeprom(dev, useraddr);
1387 break;
1388 case ETHTOOL_SEEPROM:
1389 rc = ethtool_set_eeprom(dev, useraddr);
1390 break;
1391 case ETHTOOL_GCOALESCE:
1392 rc = ethtool_get_coalesce(dev, useraddr);
1393 break;
1394 case ETHTOOL_SCOALESCE:
1395 rc = ethtool_set_coalesce(dev, useraddr);
1396 break;
1397 case ETHTOOL_GRINGPARAM:
1398 rc = ethtool_get_ringparam(dev, useraddr);
1399 break;
1400 case ETHTOOL_SRINGPARAM:
1401 rc = ethtool_set_ringparam(dev, useraddr);
1402 break;
1403 case ETHTOOL_GPAUSEPARAM:
1404 rc = ethtool_get_pauseparam(dev, useraddr);
1405 break;
1406 case ETHTOOL_SPAUSEPARAM:
1407 rc = ethtool_set_pauseparam(dev, useraddr);
1408 break;
1409 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001410 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001411 (dev->ethtool_ops->get_rx_csum ?
1412 dev->ethtool_ops->get_rx_csum :
1413 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 break;
1415 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001416 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 break;
1418 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001419 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001420 (dev->ethtool_ops->get_tx_csum ?
1421 dev->ethtool_ops->get_tx_csum :
1422 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 break;
1424 case ETHTOOL_STXCSUM:
1425 rc = ethtool_set_tx_csum(dev, useraddr);
1426 break;
1427 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001428 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001429 (dev->ethtool_ops->get_sg ?
1430 dev->ethtool_ops->get_sg :
1431 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 break;
1433 case ETHTOOL_SSG:
1434 rc = ethtool_set_sg(dev, useraddr);
1435 break;
1436 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001437 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001438 (dev->ethtool_ops->get_tso ?
1439 dev->ethtool_ops->get_tso :
1440 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 break;
1442 case ETHTOOL_STSO:
1443 rc = ethtool_set_tso(dev, useraddr);
1444 break;
1445 case ETHTOOL_TEST:
1446 rc = ethtool_self_test(dev, useraddr);
1447 break;
1448 case ETHTOOL_GSTRINGS:
1449 rc = ethtool_get_strings(dev, useraddr);
1450 break;
1451 case ETHTOOL_PHYS_ID:
1452 rc = ethtool_phys_id(dev, useraddr);
1453 break;
1454 case ETHTOOL_GSTATS:
1455 rc = ethtool_get_stats(dev, useraddr);
1456 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001457 case ETHTOOL_GPERMADDR:
1458 rc = ethtool_get_perm_addr(dev, useraddr);
1459 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001460 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001461 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001462 (dev->ethtool_ops->get_ufo ?
1463 dev->ethtool_ops->get_ufo :
1464 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001465 break;
1466 case ETHTOOL_SUFO:
1467 rc = ethtool_set_ufo(dev, useraddr);
1468 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001469 case ETHTOOL_GGSO:
1470 rc = ethtool_get_gso(dev, useraddr);
1471 break;
1472 case ETHTOOL_SGSO:
1473 rc = ethtool_set_gso(dev, useraddr);
1474 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001475 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001476 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001477 (dev->ethtool_ops->get_flags ?
1478 dev->ethtool_ops->get_flags :
1479 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001480 break;
1481 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001482 rc = ethtool_set_value(dev, useraddr,
1483 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001484 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001485 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001486 rc = ethtool_get_value(dev, useraddr, ethcmd,
1487 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001488 break;
1489 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001490 rc = ethtool_set_value(dev, useraddr,
1491 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001492 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001493 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001494 case ETHTOOL_GRXRINGS:
1495 case ETHTOOL_GRXCLSRLCNT:
1496 case ETHTOOL_GRXCLSRULE:
1497 case ETHTOOL_GRXCLSRLALL:
1498 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001499 break;
1500 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001501 case ETHTOOL_SRXCLSRLDEL:
1502 case ETHTOOL_SRXCLSRLINS:
1503 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001504 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001505 case ETHTOOL_GGRO:
1506 rc = ethtool_get_gro(dev, useraddr);
1507 break;
1508 case ETHTOOL_SGRO:
1509 rc = ethtool_set_gro(dev, useraddr);
1510 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001511 case ETHTOOL_FLASHDEV:
1512 rc = ethtool_flash_device(dev, useraddr);
1513 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001514 case ETHTOOL_RESET:
1515 rc = ethtool_reset(dev, useraddr);
1516 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001517 case ETHTOOL_SRXNTUPLE:
1518 rc = ethtool_set_rx_ntuple(dev, useraddr);
1519 break;
1520 case ETHTOOL_GRXNTUPLE:
1521 rc = ethtool_get_rx_ntuple(dev, useraddr);
1522 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001523 case ETHTOOL_GSSET_INFO:
1524 rc = ethtool_get_sset_info(dev, useraddr);
1525 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001527 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001529
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001530 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001532
1533 if (old_features != dev->features)
1534 netdev_features_change(dev);
1535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539EXPORT_SYMBOL(ethtool_op_get_link);
1540EXPORT_SYMBOL(ethtool_op_get_sg);
1541EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542EXPORT_SYMBOL(ethtool_op_set_sg);
1543EXPORT_SYMBOL(ethtool_op_set_tso);
1544EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Jon Mason69f6a0f2005-05-29 20:27:24 -07001545EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -07001546EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001547EXPORT_SYMBOL(ethtool_op_set_ufo);
1548EXPORT_SYMBOL(ethtool_op_get_ufo);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001549EXPORT_SYMBOL(ethtool_op_set_flags);
1550EXPORT_SYMBOL(ethtool_op_get_flags);