blob: f4cb6b6299d9ad833c442455944133c5c55868dd [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 =
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800124 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
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
Jeff Garzik96754782010-02-26 21:43:38 +0000155 dev->features = features;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700156 return 0;
157}
158
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800159void ethtool_ntuple_flush(struct net_device *dev)
160{
161 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
162
163 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
164 list_del(&fsc->list);
165 kfree(fsc);
166 }
167 dev->ethtool_ntuple_list.count = 0;
168}
169EXPORT_SYMBOL(ethtool_ntuple_flush);
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/* Handlers for each ethtool command */
172
173static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
174{
Roland Dreier8e557422010-02-11 12:14:23 -0800175 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 int err;
177
178 if (!dev->ethtool_ops->get_settings)
179 return -EOPNOTSUPP;
180
181 err = dev->ethtool_ops->get_settings(dev, &cmd);
182 if (err < 0)
183 return err;
184
185 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
186 return -EFAULT;
187 return 0;
188}
189
190static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
191{
192 struct ethtool_cmd cmd;
193
194 if (!dev->ethtool_ops->set_settings)
195 return -EOPNOTSUPP;
196
197 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
198 return -EFAULT;
199
200 return dev->ethtool_ops->set_settings(dev, &cmd);
201}
202
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800203static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700206 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 if (!ops->get_drvinfo)
209 return -EOPNOTSUPP;
210
211 memset(&info, 0, sizeof(info));
212 info.cmd = ETHTOOL_GDRVINFO;
213 ops->get_drvinfo(dev, &info);
214
Jeff Garzik723b2f52010-03-03 22:51:50 +0000215 /*
216 * this method of obtaining string set info is deprecated;
Jeff Garzikd17792e2010-03-04 08:21:53 +0000217 * Use ETHTOOL_GSSET_INFO instead.
Jeff Garzik723b2f52010-03-03 22:51:50 +0000218 */
Jeff Garzikff03d492007-08-15 16:01:08 -0700219 if (ops->get_sset_count) {
220 int rc;
221
222 rc = ops->get_sset_count(dev, ETH_SS_TEST);
223 if (rc >= 0)
224 info.testinfo_len = rc;
225 rc = ops->get_sset_count(dev, ETH_SS_STATS);
226 if (rc >= 0)
227 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700228 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
229 if (rc >= 0)
230 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 if (ops->get_regs_len)
233 info.regdump_len = ops->get_regs_len(dev);
234 if (ops->get_eeprom_len)
235 info.eedump_len = ops->get_eeprom_len(dev);
236
237 if (copy_to_user(useraddr, &info, sizeof(info)))
238 return -EFAULT;
239 return 0;
240}
241
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800242static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
Jeff Garzik723b2f52010-03-03 22:51:50 +0000243 void __user *useraddr)
244{
245 struct ethtool_sset_info info;
246 const struct ethtool_ops *ops = dev->ethtool_ops;
247 u64 sset_mask;
248 int i, idx = 0, n_bits = 0, ret, rc;
249 u32 *info_buf = NULL;
250
251 if (!ops->get_sset_count)
252 return -EOPNOTSUPP;
253
254 if (copy_from_user(&info, useraddr, sizeof(info)))
255 return -EFAULT;
256
257 /* store copy of mask, because we zero struct later on */
258 sset_mask = info.sset_mask;
259 if (!sset_mask)
260 return 0;
261
262 /* calculate size of return buffer */
Jeff Garzikd17792e2010-03-04 08:21:53 +0000263 n_bits = hweight64(sset_mask);
Jeff Garzik723b2f52010-03-03 22:51:50 +0000264
265 memset(&info, 0, sizeof(info));
266 info.cmd = ETHTOOL_GSSET_INFO;
267
268 info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
269 if (!info_buf)
270 return -ENOMEM;
271
272 /*
273 * fill return buffer based on input bitmask and successful
274 * get_sset_count return
275 */
276 for (i = 0; i < 64; i++) {
277 if (!(sset_mask & (1ULL << i)))
278 continue;
279
280 rc = ops->get_sset_count(dev, i);
281 if (rc >= 0) {
282 info.sset_mask |= (1ULL << i);
283 info_buf[idx++] = rc;
284 }
285 }
286
287 ret = -EFAULT;
288 if (copy_to_user(useraddr, &info, sizeof(info)))
289 goto out;
290
291 useraddr += offsetof(struct ethtool_sset_info, data);
292 if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
293 goto out;
294
295 ret = 0;
296
297out:
298 kfree(info_buf);
299 return ret;
300}
301
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800302static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700303{
304 struct ethtool_rxnfc cmd;
305
Santwona Behera59089d82009-02-20 00:58:13 -0800306 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700307 return -EOPNOTSUPP;
308
309 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
310 return -EFAULT;
311
Santwona Behera59089d82009-02-20 00:58:13 -0800312 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700313}
314
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800315static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700316{
317 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800318 const struct ethtool_ops *ops = dev->ethtool_ops;
319 int ret;
320 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700321
Santwona Behera59089d82009-02-20 00:58:13 -0800322 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700323 return -EOPNOTSUPP;
324
325 if (copy_from_user(&info, useraddr, sizeof(info)))
326 return -EFAULT;
327
Santwona Behera59089d82009-02-20 00:58:13 -0800328 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
329 if (info.rule_cnt > 0) {
330 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
331 GFP_USER);
332 if (!rule_buf)
333 return -ENOMEM;
334 }
335 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700336
Santwona Behera59089d82009-02-20 00:58:13 -0800337 ret = ops->get_rxnfc(dev, &info, rule_buf);
338 if (ret < 0)
339 goto err_out;
340
341 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700342 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800343 goto err_out;
344
345 if (rule_buf) {
346 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
347 if (copy_to_user(useraddr, rule_buf,
348 info.rule_cnt * sizeof(u32)))
349 goto err_out;
350 }
351 ret = 0;
352
353err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700354 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800355
356 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700357}
358
Peter Waskiewicze8589112010-02-12 13:48:05 +0000359static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
360 struct ethtool_rx_ntuple_flow_spec *spec,
361 struct ethtool_rx_ntuple_flow_spec_container *fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800362{
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800363
364 /* don't add filters forever */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000365 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
366 /* free the container */
367 kfree(fsc);
368 return;
369 }
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800370
371 /* Copy the whole filter over */
372 fsc->fs.flow_type = spec->flow_type;
373 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
374 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
375
376 fsc->fs.vlan_tag = spec->vlan_tag;
377 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
378 fsc->fs.data = spec->data;
379 fsc->fs.data_mask = spec->data_mask;
380 fsc->fs.action = spec->action;
381
382 /* add to the list */
383 list_add_tail_rcu(&fsc->list, &list->list);
384 list->count++;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800385}
386
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800387static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800388{
389 struct ethtool_rx_ntuple cmd;
390 const struct ethtool_ops *ops = dev->ethtool_ops;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000391 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800392 int ret;
393
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800394 if (!(dev->features & NETIF_F_NTUPLE))
395 return -EINVAL;
396
397 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
398 return -EFAULT;
399
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800400 /*
401 * Cache filter in dev struct for GET operation only if
402 * the underlying driver doesn't have its own GET operation, and
Peter Waskiewicze8589112010-02-12 13:48:05 +0000403 * only if the filter was added successfully. First make sure we
404 * can allocate the filter, then continue if successful.
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800405 */
Peter Waskiewicze8589112010-02-12 13:48:05 +0000406 if (!ops->get_rx_ntuple) {
407 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
408 if (!fsc)
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800409 return -ENOMEM;
Peter Waskiewicze8589112010-02-12 13:48:05 +0000410 }
411
412 ret = ops->set_rx_ntuple(dev, &cmd);
413 if (ret) {
414 kfree(fsc);
415 return ret;
416 }
417
418 if (!ops->get_rx_ntuple)
419 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -0800420
421 return ret;
422}
423
424static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
425{
426 struct ethtool_gstrings gstrings;
427 const struct ethtool_ops *ops = dev->ethtool_ops;
428 struct ethtool_rx_ntuple_flow_spec_container *fsc;
429 u8 *data;
430 char *p;
431 int ret, i, num_strings = 0;
432
433 if (!ops->get_sset_count)
434 return -EOPNOTSUPP;
435
436 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
437 return -EFAULT;
438
439 ret = ops->get_sset_count(dev, gstrings.string_set);
440 if (ret < 0)
441 return ret;
442
443 gstrings.len = ret;
444
445 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
446 if (!data)
447 return -ENOMEM;
448
449 if (ops->get_rx_ntuple) {
450 /* driver-specific filter grab */
451 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
452 goto copy;
453 }
454
455 /* default ethtool filter grab */
456 i = 0;
457 p = (char *)data;
458 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
459 sprintf(p, "Filter %d:\n", i);
460 p += ETH_GSTRING_LEN;
461 num_strings++;
462
463 switch (fsc->fs.flow_type) {
464 case TCP_V4_FLOW:
465 sprintf(p, "\tFlow Type: TCP\n");
466 p += ETH_GSTRING_LEN;
467 num_strings++;
468 break;
469 case UDP_V4_FLOW:
470 sprintf(p, "\tFlow Type: UDP\n");
471 p += ETH_GSTRING_LEN;
472 num_strings++;
473 break;
474 case SCTP_V4_FLOW:
475 sprintf(p, "\tFlow Type: SCTP\n");
476 p += ETH_GSTRING_LEN;
477 num_strings++;
478 break;
479 case AH_ESP_V4_FLOW:
480 sprintf(p, "\tFlow Type: AH ESP\n");
481 p += ETH_GSTRING_LEN;
482 num_strings++;
483 break;
484 case ESP_V4_FLOW:
485 sprintf(p, "\tFlow Type: ESP\n");
486 p += ETH_GSTRING_LEN;
487 num_strings++;
488 break;
489 case IP_USER_FLOW:
490 sprintf(p, "\tFlow Type: Raw IP\n");
491 p += ETH_GSTRING_LEN;
492 num_strings++;
493 break;
494 case IPV4_FLOW:
495 sprintf(p, "\tFlow Type: IPv4\n");
496 p += ETH_GSTRING_LEN;
497 num_strings++;
498 break;
499 default:
500 sprintf(p, "\tFlow Type: Unknown\n");
501 p += ETH_GSTRING_LEN;
502 num_strings++;
503 goto unknown_filter;
504 };
505
506 /* now the rest of the filters */
507 switch (fsc->fs.flow_type) {
508 case TCP_V4_FLOW:
509 case UDP_V4_FLOW:
510 case SCTP_V4_FLOW:
511 sprintf(p, "\tSrc IP addr: 0x%x\n",
512 fsc->fs.h_u.tcp_ip4_spec.ip4src);
513 p += ETH_GSTRING_LEN;
514 num_strings++;
515 sprintf(p, "\tSrc IP mask: 0x%x\n",
516 fsc->fs.m_u.tcp_ip4_spec.ip4src);
517 p += ETH_GSTRING_LEN;
518 num_strings++;
519 sprintf(p, "\tDest IP addr: 0x%x\n",
520 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
521 p += ETH_GSTRING_LEN;
522 num_strings++;
523 sprintf(p, "\tDest IP mask: 0x%x\n",
524 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
525 p += ETH_GSTRING_LEN;
526 num_strings++;
527 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
528 fsc->fs.h_u.tcp_ip4_spec.psrc,
529 fsc->fs.m_u.tcp_ip4_spec.psrc);
530 p += ETH_GSTRING_LEN;
531 num_strings++;
532 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
533 fsc->fs.h_u.tcp_ip4_spec.pdst,
534 fsc->fs.m_u.tcp_ip4_spec.pdst);
535 p += ETH_GSTRING_LEN;
536 num_strings++;
537 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
538 fsc->fs.h_u.tcp_ip4_spec.tos,
539 fsc->fs.m_u.tcp_ip4_spec.tos);
540 p += ETH_GSTRING_LEN;
541 num_strings++;
542 break;
543 case AH_ESP_V4_FLOW:
544 case ESP_V4_FLOW:
545 sprintf(p, "\tSrc IP addr: 0x%x\n",
546 fsc->fs.h_u.ah_ip4_spec.ip4src);
547 p += ETH_GSTRING_LEN;
548 num_strings++;
549 sprintf(p, "\tSrc IP mask: 0x%x\n",
550 fsc->fs.m_u.ah_ip4_spec.ip4src);
551 p += ETH_GSTRING_LEN;
552 num_strings++;
553 sprintf(p, "\tDest IP addr: 0x%x\n",
554 fsc->fs.h_u.ah_ip4_spec.ip4dst);
555 p += ETH_GSTRING_LEN;
556 num_strings++;
557 sprintf(p, "\tDest IP mask: 0x%x\n",
558 fsc->fs.m_u.ah_ip4_spec.ip4dst);
559 p += ETH_GSTRING_LEN;
560 num_strings++;
561 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
562 fsc->fs.h_u.ah_ip4_spec.spi,
563 fsc->fs.m_u.ah_ip4_spec.spi);
564 p += ETH_GSTRING_LEN;
565 num_strings++;
566 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
567 fsc->fs.h_u.ah_ip4_spec.tos,
568 fsc->fs.m_u.ah_ip4_spec.tos);
569 p += ETH_GSTRING_LEN;
570 num_strings++;
571 break;
572 case IP_USER_FLOW:
573 sprintf(p, "\tSrc IP addr: 0x%x\n",
574 fsc->fs.h_u.raw_ip4_spec.ip4src);
575 p += ETH_GSTRING_LEN;
576 num_strings++;
577 sprintf(p, "\tSrc IP mask: 0x%x\n",
578 fsc->fs.m_u.raw_ip4_spec.ip4src);
579 p += ETH_GSTRING_LEN;
580 num_strings++;
581 sprintf(p, "\tDest IP addr: 0x%x\n",
582 fsc->fs.h_u.raw_ip4_spec.ip4dst);
583 p += ETH_GSTRING_LEN;
584 num_strings++;
585 sprintf(p, "\tDest IP mask: 0x%x\n",
586 fsc->fs.m_u.raw_ip4_spec.ip4dst);
587 p += ETH_GSTRING_LEN;
588 num_strings++;
589 break;
590 case IPV4_FLOW:
591 sprintf(p, "\tSrc IP addr: 0x%x\n",
592 fsc->fs.h_u.usr_ip4_spec.ip4src);
593 p += ETH_GSTRING_LEN;
594 num_strings++;
595 sprintf(p, "\tSrc IP mask: 0x%x\n",
596 fsc->fs.m_u.usr_ip4_spec.ip4src);
597 p += ETH_GSTRING_LEN;
598 num_strings++;
599 sprintf(p, "\tDest IP addr: 0x%x\n",
600 fsc->fs.h_u.usr_ip4_spec.ip4dst);
601 p += ETH_GSTRING_LEN;
602 num_strings++;
603 sprintf(p, "\tDest IP mask: 0x%x\n",
604 fsc->fs.m_u.usr_ip4_spec.ip4dst);
605 p += ETH_GSTRING_LEN;
606 num_strings++;
607 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
608 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
609 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
610 p += ETH_GSTRING_LEN;
611 num_strings++;
612 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
613 fsc->fs.h_u.usr_ip4_spec.tos,
614 fsc->fs.m_u.usr_ip4_spec.tos);
615 p += ETH_GSTRING_LEN;
616 num_strings++;
617 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
618 fsc->fs.h_u.usr_ip4_spec.ip_ver,
619 fsc->fs.m_u.usr_ip4_spec.ip_ver);
620 p += ETH_GSTRING_LEN;
621 num_strings++;
622 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
623 fsc->fs.h_u.usr_ip4_spec.proto,
624 fsc->fs.m_u.usr_ip4_spec.proto);
625 p += ETH_GSTRING_LEN;
626 num_strings++;
627 break;
628 };
629 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
630 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
631 p += ETH_GSTRING_LEN;
632 num_strings++;
633 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
634 p += ETH_GSTRING_LEN;
635 num_strings++;
636 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
637 p += ETH_GSTRING_LEN;
638 num_strings++;
639 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
640 sprintf(p, "\tAction: Drop\n");
641 else
642 sprintf(p, "\tAction: Direct to queue %d\n",
643 fsc->fs.action);
644 p += ETH_GSTRING_LEN;
645 num_strings++;
646unknown_filter:
647 i++;
648 }
649copy:
650 /* indicate to userspace how many strings we actually have */
651 gstrings.len = num_strings;
652 ret = -EFAULT;
653 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
654 goto out;
655 useraddr += sizeof(gstrings);
656 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
657 goto out;
658 ret = 0;
659
660out:
661 kfree(data);
662 return ret;
663}
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
666{
667 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700668 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 void *regbuf;
670 int reglen, ret;
671
672 if (!ops->get_regs || !ops->get_regs_len)
673 return -EOPNOTSUPP;
674
675 if (copy_from_user(&regs, useraddr, sizeof(regs)))
676 return -EFAULT;
677
678 reglen = ops->get_regs_len(dev);
679 if (regs.len > reglen)
680 regs.len = reglen;
681
682 regbuf = kmalloc(reglen, GFP_USER);
683 if (!regbuf)
684 return -ENOMEM;
685
686 ops->get_regs(dev, &regs, regbuf);
687
688 ret = -EFAULT;
689 if (copy_to_user(useraddr, &regs, sizeof(regs)))
690 goto out;
691 useraddr += offsetof(struct ethtool_regs, data);
692 if (copy_to_user(useraddr, regbuf, regs.len))
693 goto out;
694 ret = 0;
695
696 out:
697 kfree(regbuf);
698 return ret;
699}
700
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000701static int ethtool_reset(struct net_device *dev, char __user *useraddr)
702{
703 struct ethtool_value reset;
704 int ret;
705
706 if (!dev->ethtool_ops->reset)
707 return -EOPNOTSUPP;
708
709 if (copy_from_user(&reset, useraddr, sizeof(reset)))
710 return -EFAULT;
711
712 ret = dev->ethtool_ops->reset(dev, &reset.data);
713 if (ret)
714 return ret;
715
716 if (copy_to_user(useraddr, &reset, sizeof(reset)))
717 return -EFAULT;
718 return 0;
719}
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
722{
Roland Dreier8e557422010-02-11 12:14:23 -0800723 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 if (!dev->ethtool_ops->get_wol)
726 return -EOPNOTSUPP;
727
728 dev->ethtool_ops->get_wol(dev, &wol);
729
730 if (copy_to_user(useraddr, &wol, sizeof(wol)))
731 return -EFAULT;
732 return 0;
733}
734
735static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
736{
737 struct ethtool_wolinfo wol;
738
739 if (!dev->ethtool_ops->set_wol)
740 return -EOPNOTSUPP;
741
742 if (copy_from_user(&wol, useraddr, sizeof(wol)))
743 return -EFAULT;
744
745 return dev->ethtool_ops->set_wol(dev, &wol);
746}
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748static int ethtool_nway_reset(struct net_device *dev)
749{
750 if (!dev->ethtool_ops->nway_reset)
751 return -EOPNOTSUPP;
752
753 return dev->ethtool_ops->nway_reset(dev);
754}
755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
757{
758 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700759 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700760 void __user *userbuf = useraddr + sizeof(eeprom);
761 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700763 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (!ops->get_eeprom || !ops->get_eeprom_len)
766 return -EOPNOTSUPP;
767
768 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
769 return -EFAULT;
770
771 /* Check for wrap and zero */
772 if (eeprom.offset + eeprom.len <= eeprom.offset)
773 return -EINVAL;
774
775 /* Check for exceeding total eeprom len */
776 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
777 return -EINVAL;
778
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700779 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (!data)
781 return -ENOMEM;
782
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700783 bytes_remaining = eeprom.len;
784 while (bytes_remaining > 0) {
785 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700787 ret = ops->get_eeprom(dev, &eeprom, data);
788 if (ret)
789 break;
790 if (copy_to_user(userbuf, data, eeprom.len)) {
791 ret = -EFAULT;
792 break;
793 }
794 userbuf += eeprom.len;
795 eeprom.offset += eeprom.len;
796 bytes_remaining -= eeprom.len;
797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700799 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
800 eeprom.offset -= eeprom.len;
801 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
802 ret = -EFAULT;
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 kfree(data);
805 return ret;
806}
807
808static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
809{
810 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700811 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700812 void __user *userbuf = useraddr + sizeof(eeprom);
813 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700815 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 if (!ops->set_eeprom || !ops->get_eeprom_len)
818 return -EOPNOTSUPP;
819
820 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
821 return -EFAULT;
822
823 /* Check for wrap and zero */
824 if (eeprom.offset + eeprom.len <= eeprom.offset)
825 return -EINVAL;
826
827 /* Check for exceeding total eeprom len */
828 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
829 return -EINVAL;
830
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700831 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (!data)
833 return -ENOMEM;
834
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700835 bytes_remaining = eeprom.len;
836 while (bytes_remaining > 0) {
837 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700839 if (copy_from_user(data, userbuf, eeprom.len)) {
840 ret = -EFAULT;
841 break;
842 }
843 ret = ops->set_eeprom(dev, &eeprom, data);
844 if (ret)
845 break;
846 userbuf += eeprom.len;
847 eeprom.offset += eeprom.len;
848 bytes_remaining -= eeprom.len;
849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 kfree(data);
852 return ret;
853}
854
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800855static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Roland Dreier8e557422010-02-11 12:14:23 -0800857 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 if (!dev->ethtool_ops->get_coalesce)
860 return -EOPNOTSUPP;
861
862 dev->ethtool_ops->get_coalesce(dev, &coalesce);
863
864 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
865 return -EFAULT;
866 return 0;
867}
868
Eric Dumazetf5c445e2010-03-08 12:17:04 -0800869static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
871 struct ethtool_coalesce coalesce;
872
David S. Millerfa04ae52005-06-06 15:07:19 -0700873 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 return -EOPNOTSUPP;
875
876 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
877 return -EFAULT;
878
879 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
880}
881
882static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
883{
Roland Dreier8e557422010-02-11 12:14:23 -0800884 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 if (!dev->ethtool_ops->get_ringparam)
887 return -EOPNOTSUPP;
888
889 dev->ethtool_ops->get_ringparam(dev, &ringparam);
890
891 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
892 return -EFAULT;
893 return 0;
894}
895
896static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
897{
898 struct ethtool_ringparam ringparam;
899
900 if (!dev->ethtool_ops->set_ringparam)
901 return -EOPNOTSUPP;
902
903 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
904 return -EFAULT;
905
906 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
907}
908
909static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
910{
911 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
912
913 if (!dev->ethtool_ops->get_pauseparam)
914 return -EOPNOTSUPP;
915
916 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
917
918 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
919 return -EFAULT;
920 return 0;
921}
922
923static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
924{
925 struct ethtool_pauseparam pauseparam;
926
Jeff Garzike1b90c42006-07-17 12:54:40 -0400927 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return -EOPNOTSUPP;
929
930 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
931 return -EFAULT;
932
933 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
934}
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936static int __ethtool_set_sg(struct net_device *dev, u32 data)
937{
938 int err;
939
940 if (!data && dev->ethtool_ops->set_tso) {
941 err = dev->ethtool_ops->set_tso(dev, 0);
942 if (err)
943 return err;
944 }
945
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700946 if (!data && dev->ethtool_ops->set_ufo) {
947 err = dev->ethtool_ops->set_ufo(dev, 0);
948 if (err)
949 return err;
950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return dev->ethtool_ops->set_sg(dev, data);
952}
953
954static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
955{
956 struct ethtool_value edata;
957 int err;
958
959 if (!dev->ethtool_ops->set_tx_csum)
960 return -EOPNOTSUPP;
961
962 if (copy_from_user(&edata, useraddr, sizeof(edata)))
963 return -EFAULT;
964
965 if (!edata.data && dev->ethtool_ops->set_sg) {
966 err = __ethtool_set_sg(dev, 0);
967 if (err)
968 return err;
969 }
970
971 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
972}
973
Herbert Xub240a0e2008-12-15 23:44:31 -0800974static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
975{
976 struct ethtool_value edata;
977
978 if (!dev->ethtool_ops->set_rx_csum)
979 return -EOPNOTSUPP;
980
981 if (copy_from_user(&edata, useraddr, sizeof(edata)))
982 return -EFAULT;
983
984 if (!edata.data && dev->ethtool_ops->set_sg)
985 dev->features &= ~NETIF_F_GRO;
986
987 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
988}
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
991{
992 struct ethtool_value edata;
993
994 if (!dev->ethtool_ops->set_sg)
995 return -EOPNOTSUPP;
996
997 if (copy_from_user(&edata, useraddr, sizeof(edata)))
998 return -EFAULT;
999
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001000 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -07001001 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 return -EINVAL;
1003
1004 return __ethtool_set_sg(dev, edata.data);
1005}
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
1008{
1009 struct ethtool_value edata;
1010
1011 if (!dev->ethtool_ops->set_tso)
1012 return -EOPNOTSUPP;
1013
1014 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1015 return -EFAULT;
1016
1017 if (edata.data && !(dev->features & NETIF_F_SG))
1018 return -EINVAL;
1019
1020 return dev->ethtool_ops->set_tso(dev, edata.data);
1021}
1022
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001023static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
1024{
1025 struct ethtool_value edata;
1026
1027 if (!dev->ethtool_ops->set_ufo)
1028 return -EOPNOTSUPP;
1029 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1030 return -EFAULT;
1031 if (edata.data && !(dev->features & NETIF_F_SG))
1032 return -EINVAL;
1033 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
1034 return -EINVAL;
1035 return dev->ethtool_ops->set_ufo(dev, edata.data);
1036}
1037
Herbert Xu37c31852006-06-22 03:07:29 -07001038static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
1039{
1040 struct ethtool_value edata = { ETHTOOL_GGSO };
1041
1042 edata.data = dev->features & NETIF_F_GSO;
1043 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1044 return -EFAULT;
1045 return 0;
1046}
1047
1048static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1049{
1050 struct ethtool_value edata;
1051
1052 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1053 return -EFAULT;
1054 if (edata.data)
1055 dev->features |= NETIF_F_GSO;
1056 else
1057 dev->features &= ~NETIF_F_GSO;
1058 return 0;
1059}
1060
Herbert Xub240a0e2008-12-15 23:44:31 -08001061static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1062{
1063 struct ethtool_value edata = { ETHTOOL_GGRO };
1064
1065 edata.data = dev->features & NETIF_F_GRO;
1066 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1067 return -EFAULT;
1068 return 0;
1069}
1070
1071static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1072{
1073 struct ethtool_value edata;
1074
1075 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1076 return -EFAULT;
1077
1078 if (edata.data) {
1079 if (!dev->ethtool_ops->get_rx_csum ||
1080 !dev->ethtool_ops->get_rx_csum(dev))
1081 return -EINVAL;
1082 dev->features |= NETIF_F_GRO;
1083 } else
1084 dev->features &= ~NETIF_F_GRO;
1085
1086 return 0;
1087}
1088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1090{
1091 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001092 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001094 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001096 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001097 return -EOPNOTSUPP;
1098
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001099 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -07001100 if (test_len < 0)
1101 return test_len;
1102 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 if (copy_from_user(&test, useraddr, sizeof(test)))
1105 return -EFAULT;
1106
Jeff Garzikff03d492007-08-15 16:01:08 -07001107 test.len = test_len;
1108 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 if (!data)
1110 return -ENOMEM;
1111
1112 ops->self_test(dev, &test, data);
1113
1114 ret = -EFAULT;
1115 if (copy_to_user(useraddr, &test, sizeof(test)))
1116 goto out;
1117 useraddr += sizeof(test);
1118 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1119 goto out;
1120 ret = 0;
1121
1122 out:
1123 kfree(data);
1124 return ret;
1125}
1126
1127static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1128{
1129 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001130 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 u8 *data;
1132 int ret;
1133
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001134 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 return -EOPNOTSUPP;
1136
1137 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1138 return -EFAULT;
1139
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001140 ret = ops->get_sset_count(dev, gstrings.string_set);
1141 if (ret < 0)
1142 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -07001143
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001144 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1147 if (!data)
1148 return -ENOMEM;
1149
1150 ops->get_strings(dev, gstrings.string_set, data);
1151
1152 ret = -EFAULT;
1153 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1154 goto out;
1155 useraddr += sizeof(gstrings);
1156 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1157 goto out;
1158 ret = 0;
1159
1160 out:
1161 kfree(data);
1162 return ret;
1163}
1164
1165static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1166{
1167 struct ethtool_value id;
1168
1169 if (!dev->ethtool_ops->phys_id)
1170 return -EOPNOTSUPP;
1171
1172 if (copy_from_user(&id, useraddr, sizeof(id)))
1173 return -EFAULT;
1174
1175 return dev->ethtool_ops->phys_id(dev, id.data);
1176}
1177
1178static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1179{
1180 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -07001181 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -07001183 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001185 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -07001186 return -EOPNOTSUPP;
1187
Ben Hutchingsa9828ec2009-10-01 11:33:03 +00001188 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -07001189 if (n_stats < 0)
1190 return n_stats;
1191 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
1193 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1194 return -EFAULT;
1195
Jeff Garzikff03d492007-08-15 16:01:08 -07001196 stats.n_stats = n_stats;
1197 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (!data)
1199 return -ENOMEM;
1200
1201 ops->get_ethtool_stats(dev, &stats, data);
1202
1203 ret = -EFAULT;
1204 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1205 goto out;
1206 useraddr += sizeof(stats);
1207 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1208 goto out;
1209 ret = 0;
1210
1211 out:
1212 kfree(data);
1213 return ret;
1214}
1215
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +01001216static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -07001217{
1218 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001219
Matthew Wilcox313674a2007-07-31 14:00:29 -07001220 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -07001221 return -EFAULT;
1222
Matthew Wilcox313674a2007-07-31 14:00:29 -07001223 if (epaddr.size < dev->addr_len)
1224 return -ETOOSMALL;
1225 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001226
Jon Wetzela6f9a702005-08-20 17:15:54 -07001227 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -07001228 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001229 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -07001230 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1231 return -EFAULT;
1232 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001233}
1234
Jeff Garzik13c99b22007-08-15 16:01:56 -07001235static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1236 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001237{
Roland Dreier8e557422010-02-11 12:14:23 -08001238 struct ethtool_value edata = { .cmd = cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001239
Jeff Garzik13c99b22007-08-15 16:01:56 -07001240 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001241 return -EOPNOTSUPP;
1242
Jeff Garzik13c99b22007-08-15 16:01:56 -07001243 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001244
1245 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1246 return -EFAULT;
1247 return 0;
1248}
1249
Jeff Garzik13c99b22007-08-15 16:01:56 -07001250static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1251 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001252{
1253 struct ethtool_value edata;
1254
Jeff Garzik13c99b22007-08-15 16:01:56 -07001255 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001256 return -EOPNOTSUPP;
1257
1258 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1259 return -EFAULT;
1260
Jeff Garzik13c99b22007-08-15 16:01:56 -07001261 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001262 return 0;
1263}
1264
Jeff Garzik13c99b22007-08-15 16:01:56 -07001265static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1266 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -07001267{
1268 struct ethtool_value edata;
1269
Jeff Garzik13c99b22007-08-15 16:01:56 -07001270 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -07001271 return -EOPNOTSUPP;
1272
1273 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1274 return -EFAULT;
1275
Jeff Garzik13c99b22007-08-15 16:01:56 -07001276 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -07001277}
1278
Eric Dumazetf5c445e2010-03-08 12:17:04 -08001279static noinline_for_stack int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001280{
1281 struct ethtool_flash efl;
1282
1283 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1284 return -EFAULT;
1285
1286 if (!dev->ethtool_ops->flash_device)
1287 return -EOPNOTSUPP;
1288
1289 return dev->ethtool_ops->flash_device(dev, &efl);
1290}
1291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292/* The main entry point in this file. Called from net/core/dev.c */
1293
Eric W. Biederman881d9662007-09-17 11:56:21 -07001294int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Eric W. Biederman881d9662007-09-17 11:56:21 -07001296 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 void __user *useraddr = ifr->ifr_data;
1298 u32 ethcmd;
1299 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -07001300 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 if (!dev || !netif_device_present(dev))
1303 return -ENODEV;
1304
1305 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001306 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1309 return -EFAULT;
1310
Stephen Hemminger75f31232006-09-28 15:13:37 -07001311 /* Allow some commands to be done by anyone */
1312 switch(ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -07001313 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001314 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001315 case ETHTOOL_GCOALESCE:
1316 case ETHTOOL_GRINGPARAM:
1317 case ETHTOOL_GPAUSEPARAM:
1318 case ETHTOOL_GRXCSUM:
1319 case ETHTOOL_GTXCSUM:
1320 case ETHTOOL_GSG:
1321 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001322 case ETHTOOL_GTSO:
1323 case ETHTOOL_GPERMADDR:
1324 case ETHTOOL_GUFO:
1325 case ETHTOOL_GGSO:
stephen hemminger1cab8192010-02-11 13:48:29 +00001326 case ETHTOOL_GGRO:
Jeff Garzik339bf022007-08-15 16:01:32 -07001327 case ETHTOOL_GFLAGS:
1328 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -07001329 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001330 case ETHTOOL_GRXRINGS:
1331 case ETHTOOL_GRXCLSRLCNT:
1332 case ETHTOOL_GRXCLSRULE:
1333 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -07001334 break;
1335 default:
1336 if (!capable(CAP_NET_ADMIN))
1337 return -EPERM;
1338 }
1339
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001340 if (dev->ethtool_ops->begin)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1342 return rc;
1343
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001344 old_features = dev->features;
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 switch (ethcmd) {
1347 case ETHTOOL_GSET:
1348 rc = ethtool_get_settings(dev, useraddr);
1349 break;
1350 case ETHTOOL_SSET:
1351 rc = ethtool_set_settings(dev, useraddr);
1352 break;
1353 case ETHTOOL_GDRVINFO:
1354 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 break;
1356 case ETHTOOL_GREGS:
1357 rc = ethtool_get_regs(dev, useraddr);
1358 break;
1359 case ETHTOOL_GWOL:
1360 rc = ethtool_get_wol(dev, useraddr);
1361 break;
1362 case ETHTOOL_SWOL:
1363 rc = ethtool_set_wol(dev, useraddr);
1364 break;
1365 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001366 rc = ethtool_get_value(dev, useraddr, ethcmd,
1367 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 break;
1369 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001370 rc = ethtool_set_value_void(dev, useraddr,
1371 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 break;
1373 case ETHTOOL_NWAY_RST:
1374 rc = ethtool_nway_reset(dev);
1375 break;
1376 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001377 rc = ethtool_get_value(dev, useraddr, ethcmd,
1378 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 break;
1380 case ETHTOOL_GEEPROM:
1381 rc = ethtool_get_eeprom(dev, useraddr);
1382 break;
1383 case ETHTOOL_SEEPROM:
1384 rc = ethtool_set_eeprom(dev, useraddr);
1385 break;
1386 case ETHTOOL_GCOALESCE:
1387 rc = ethtool_get_coalesce(dev, useraddr);
1388 break;
1389 case ETHTOOL_SCOALESCE:
1390 rc = ethtool_set_coalesce(dev, useraddr);
1391 break;
1392 case ETHTOOL_GRINGPARAM:
1393 rc = ethtool_get_ringparam(dev, useraddr);
1394 break;
1395 case ETHTOOL_SRINGPARAM:
1396 rc = ethtool_set_ringparam(dev, useraddr);
1397 break;
1398 case ETHTOOL_GPAUSEPARAM:
1399 rc = ethtool_get_pauseparam(dev, useraddr);
1400 break;
1401 case ETHTOOL_SPAUSEPARAM:
1402 rc = ethtool_set_pauseparam(dev, useraddr);
1403 break;
1404 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001405 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001406 (dev->ethtool_ops->get_rx_csum ?
1407 dev->ethtool_ops->get_rx_csum :
1408 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 break;
1410 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001411 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 break;
1413 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001414 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001415 (dev->ethtool_ops->get_tx_csum ?
1416 dev->ethtool_ops->get_tx_csum :
1417 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 break;
1419 case ETHTOOL_STXCSUM:
1420 rc = ethtool_set_tx_csum(dev, useraddr);
1421 break;
1422 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001423 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001424 (dev->ethtool_ops->get_sg ?
1425 dev->ethtool_ops->get_sg :
1426 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 break;
1428 case ETHTOOL_SSG:
1429 rc = ethtool_set_sg(dev, useraddr);
1430 break;
1431 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001432 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001433 (dev->ethtool_ops->get_tso ?
1434 dev->ethtool_ops->get_tso :
1435 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 break;
1437 case ETHTOOL_STSO:
1438 rc = ethtool_set_tso(dev, useraddr);
1439 break;
1440 case ETHTOOL_TEST:
1441 rc = ethtool_self_test(dev, useraddr);
1442 break;
1443 case ETHTOOL_GSTRINGS:
1444 rc = ethtool_get_strings(dev, useraddr);
1445 break;
1446 case ETHTOOL_PHYS_ID:
1447 rc = ethtool_phys_id(dev, useraddr);
1448 break;
1449 case ETHTOOL_GSTATS:
1450 rc = ethtool_get_stats(dev, useraddr);
1451 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001452 case ETHTOOL_GPERMADDR:
1453 rc = ethtool_get_perm_addr(dev, useraddr);
1454 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001455 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001456 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001457 (dev->ethtool_ops->get_ufo ?
1458 dev->ethtool_ops->get_ufo :
1459 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001460 break;
1461 case ETHTOOL_SUFO:
1462 rc = ethtool_set_ufo(dev, useraddr);
1463 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001464 case ETHTOOL_GGSO:
1465 rc = ethtool_get_gso(dev, useraddr);
1466 break;
1467 case ETHTOOL_SGSO:
1468 rc = ethtool_set_gso(dev, useraddr);
1469 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001470 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001471 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001472 (dev->ethtool_ops->get_flags ?
1473 dev->ethtool_ops->get_flags :
1474 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001475 break;
1476 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001477 rc = ethtool_set_value(dev, useraddr,
1478 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001479 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001480 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001481 rc = ethtool_get_value(dev, useraddr, ethcmd,
1482 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001483 break;
1484 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001485 rc = ethtool_set_value(dev, useraddr,
1486 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001487 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001488 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001489 case ETHTOOL_GRXRINGS:
1490 case ETHTOOL_GRXCLSRLCNT:
1491 case ETHTOOL_GRXCLSRULE:
1492 case ETHTOOL_GRXCLSRLALL:
1493 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001494 break;
1495 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001496 case ETHTOOL_SRXCLSRLDEL:
1497 case ETHTOOL_SRXCLSRLINS:
1498 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001499 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001500 case ETHTOOL_GGRO:
1501 rc = ethtool_get_gro(dev, useraddr);
1502 break;
1503 case ETHTOOL_SGRO:
1504 rc = ethtool_set_gro(dev, useraddr);
1505 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001506 case ETHTOOL_FLASHDEV:
1507 rc = ethtool_flash_device(dev, useraddr);
1508 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001509 case ETHTOOL_RESET:
1510 rc = ethtool_reset(dev, useraddr);
1511 break;
Peter P Waskiewicz Jr15682bc2010-02-10 20:03:05 -08001512 case ETHTOOL_SRXNTUPLE:
1513 rc = ethtool_set_rx_ntuple(dev, useraddr);
1514 break;
1515 case ETHTOOL_GRXNTUPLE:
1516 rc = ethtool_get_rx_ntuple(dev, useraddr);
1517 break;
Jeff Garzik723b2f52010-03-03 22:51:50 +00001518 case ETHTOOL_GSSET_INFO:
1519 rc = ethtool_get_sset_info(dev, useraddr);
1520 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001522 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001524
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001525 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001527
1528 if (old_features != dev->features)
1529 netdev_features_change(dev);
1530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534EXPORT_SYMBOL(ethtool_op_get_link);
1535EXPORT_SYMBOL(ethtool_op_get_sg);
1536EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537EXPORT_SYMBOL(ethtool_op_set_sg);
1538EXPORT_SYMBOL(ethtool_op_set_tso);
1539EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Jon Mason69f6a0f2005-05-29 20:27:24 -07001540EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -07001541EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001542EXPORT_SYMBOL(ethtool_op_set_ufo);
1543EXPORT_SYMBOL(ethtool_op_get_ufo);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001544EXPORT_SYMBOL(ethtool_op_set_flags);
1545EXPORT_SYMBOL(ethtool_op_get_flags);