blob: cf36ff44ebb2520339d3ff5045499a3321756239 [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>
20#include <asm/uaccess.h>
21
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +090022/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * Some useful ethtool_ops methods that're device independent.
24 * If we find that all drivers want to do the same thing here,
25 * we can turn these into dev_() function calls.
26 */
27
28u32 ethtool_op_get_link(struct net_device *dev)
29{
30 return netif_carrier_ok(dev) ? 1 : 0;
31}
32
Sridhar Samudrala1896e612009-07-22 13:38:22 +000033u32 ethtool_op_get_rx_csum(struct net_device *dev)
34{
35 return (dev->features & NETIF_F_ALL_CSUM) != 0;
36}
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038u32 ethtool_op_get_tx_csum(struct net_device *dev)
39{
Herbert Xu8648b302006-06-17 22:06:05 -070040 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
44{
45 if (data)
46 dev->features |= NETIF_F_IP_CSUM;
47 else
48 dev->features &= ~NETIF_F_IP_CSUM;
49
50 return 0;
51}
52
Jon Mason69f6a0f2005-05-29 20:27:24 -070053int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
54{
55 if (data)
56 dev->features |= NETIF_F_HW_CSUM;
57 else
58 dev->features &= ~NETIF_F_HW_CSUM;
59
60 return 0;
61}
Michael Chan6460d942007-07-14 19:07:52 -070062
63int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
64{
65 if (data)
66 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
67 else
68 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
69
70 return 0;
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073u32 ethtool_op_get_sg(struct net_device *dev)
74{
75 return (dev->features & NETIF_F_SG) != 0;
76}
77
78int ethtool_op_set_sg(struct net_device *dev, u32 data)
79{
80 if (data)
81 dev->features |= NETIF_F_SG;
82 else
83 dev->features &= ~NETIF_F_SG;
84
85 return 0;
86}
87
88u32 ethtool_op_get_tso(struct net_device *dev)
89{
90 return (dev->features & NETIF_F_TSO) != 0;
91}
92
93int ethtool_op_set_tso(struct net_device *dev, u32 data)
94{
95 if (data)
96 dev->features |= NETIF_F_TSO;
97 else
98 dev->features &= ~NETIF_F_TSO;
99
100 return 0;
101}
102
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700103u32 ethtool_op_get_ufo(struct net_device *dev)
104{
105 return (dev->features & NETIF_F_UFO) != 0;
106}
107
108int ethtool_op_set_ufo(struct net_device *dev, u32 data)
109{
110 if (data)
111 dev->features |= NETIF_F_UFO;
112 else
113 dev->features &= ~NETIF_F_UFO;
114 return 0;
115}
116
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700117/* the following list of flags are the same as their associated
118 * NETIF_F_xxx values in include/linux/netdevice.h
119 */
120static const u32 flags_dup_features =
121 ETH_FLAG_LRO;
122
123u32 ethtool_op_get_flags(struct net_device *dev)
124{
125 /* in the future, this function will probably contain additional
126 * handling for flags which are not so easily handled
127 * by a simple masking operation
128 */
129
130 return dev->features & flags_dup_features;
131}
132
133int ethtool_op_set_flags(struct net_device *dev, u32 data)
134{
135 if (data & ETH_FLAG_LRO)
136 dev->features |= NETIF_F_LRO;
137 else
138 dev->features &= ~NETIF_F_LRO;
139
140 return 0;
141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/* Handlers for each ethtool command */
144
145static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
146{
147 struct ethtool_cmd cmd = { ETHTOOL_GSET };
148 int err;
149
150 if (!dev->ethtool_ops->get_settings)
151 return -EOPNOTSUPP;
152
153 err = dev->ethtool_ops->get_settings(dev, &cmd);
154 if (err < 0)
155 return err;
156
157 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
158 return -EFAULT;
159 return 0;
160}
161
162static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
163{
164 struct ethtool_cmd cmd;
165
166 if (!dev->ethtool_ops->set_settings)
167 return -EOPNOTSUPP;
168
169 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
170 return -EFAULT;
171
172 return dev->ethtool_ops->set_settings(dev, &cmd);
173}
174
175static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
176{
177 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700178 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 if (!ops->get_drvinfo)
181 return -EOPNOTSUPP;
182
183 memset(&info, 0, sizeof(info));
184 info.cmd = ETHTOOL_GDRVINFO;
185 ops->get_drvinfo(dev, &info);
186
Jeff Garzikff03d492007-08-15 16:01:08 -0700187 if (ops->get_sset_count) {
188 int rc;
189
190 rc = ops->get_sset_count(dev, ETH_SS_TEST);
191 if (rc >= 0)
192 info.testinfo_len = rc;
193 rc = ops->get_sset_count(dev, ETH_SS_STATS);
194 if (rc >= 0)
195 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700196 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
197 if (rc >= 0)
198 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700199 } else {
200 /* code path for obsolete hooks */
201
202 if (ops->self_test_count)
203 info.testinfo_len = ops->self_test_count(dev);
204 if (ops->get_stats_count)
205 info.n_stats = ops->get_stats_count(dev);
206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (ops->get_regs_len)
208 info.regdump_len = ops->get_regs_len(dev);
209 if (ops->get_eeprom_len)
210 info.eedump_len = ops->get_eeprom_len(dev);
211
212 if (copy_to_user(useraddr, &info, sizeof(info)))
213 return -EFAULT;
214 return 0;
215}
216
Santwona Behera59089d82009-02-20 00:58:13 -0800217static int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700218{
219 struct ethtool_rxnfc cmd;
220
Santwona Behera59089d82009-02-20 00:58:13 -0800221 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700222 return -EOPNOTSUPP;
223
224 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
225 return -EFAULT;
226
Santwona Behera59089d82009-02-20 00:58:13 -0800227 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700228}
229
Santwona Behera59089d82009-02-20 00:58:13 -0800230static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700231{
232 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800233 const struct ethtool_ops *ops = dev->ethtool_ops;
234 int ret;
235 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700236
Santwona Behera59089d82009-02-20 00:58:13 -0800237 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700238 return -EOPNOTSUPP;
239
240 if (copy_from_user(&info, useraddr, sizeof(info)))
241 return -EFAULT;
242
Santwona Behera59089d82009-02-20 00:58:13 -0800243 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
244 if (info.rule_cnt > 0) {
245 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
246 GFP_USER);
247 if (!rule_buf)
248 return -ENOMEM;
249 }
250 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700251
Santwona Behera59089d82009-02-20 00:58:13 -0800252 ret = ops->get_rxnfc(dev, &info, rule_buf);
253 if (ret < 0)
254 goto err_out;
255
256 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700257 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800258 goto err_out;
259
260 if (rule_buf) {
261 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
262 if (copy_to_user(useraddr, rule_buf,
263 info.rule_cnt * sizeof(u32)))
264 goto err_out;
265 }
266 ret = 0;
267
268err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700269 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800270
271 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700272}
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
275{
276 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700277 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 void *regbuf;
279 int reglen, ret;
280
281 if (!ops->get_regs || !ops->get_regs_len)
282 return -EOPNOTSUPP;
283
284 if (copy_from_user(&regs, useraddr, sizeof(regs)))
285 return -EFAULT;
286
287 reglen = ops->get_regs_len(dev);
288 if (regs.len > reglen)
289 regs.len = reglen;
290
291 regbuf = kmalloc(reglen, GFP_USER);
292 if (!regbuf)
293 return -ENOMEM;
294
295 ops->get_regs(dev, &regs, regbuf);
296
297 ret = -EFAULT;
298 if (copy_to_user(useraddr, &regs, sizeof(regs)))
299 goto out;
300 useraddr += offsetof(struct ethtool_regs, data);
301 if (copy_to_user(useraddr, regbuf, regs.len))
302 goto out;
303 ret = 0;
304
305 out:
306 kfree(regbuf);
307 return ret;
308}
309
310static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
311{
312 struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
313
314 if (!dev->ethtool_ops->get_wol)
315 return -EOPNOTSUPP;
316
317 dev->ethtool_ops->get_wol(dev, &wol);
318
319 if (copy_to_user(useraddr, &wol, sizeof(wol)))
320 return -EFAULT;
321 return 0;
322}
323
324static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
325{
326 struct ethtool_wolinfo wol;
327
328 if (!dev->ethtool_ops->set_wol)
329 return -EOPNOTSUPP;
330
331 if (copy_from_user(&wol, useraddr, sizeof(wol)))
332 return -EFAULT;
333
334 return dev->ethtool_ops->set_wol(dev, &wol);
335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337static int ethtool_nway_reset(struct net_device *dev)
338{
339 if (!dev->ethtool_ops->nway_reset)
340 return -EOPNOTSUPP;
341
342 return dev->ethtool_ops->nway_reset(dev);
343}
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
346{
347 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700348 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700349 void __user *userbuf = useraddr + sizeof(eeprom);
350 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700352 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (!ops->get_eeprom || !ops->get_eeprom_len)
355 return -EOPNOTSUPP;
356
357 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
358 return -EFAULT;
359
360 /* Check for wrap and zero */
361 if (eeprom.offset + eeprom.len <= eeprom.offset)
362 return -EINVAL;
363
364 /* Check for exceeding total eeprom len */
365 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
366 return -EINVAL;
367
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700368 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (!data)
370 return -ENOMEM;
371
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700372 bytes_remaining = eeprom.len;
373 while (bytes_remaining > 0) {
374 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700376 ret = ops->get_eeprom(dev, &eeprom, data);
377 if (ret)
378 break;
379 if (copy_to_user(userbuf, data, eeprom.len)) {
380 ret = -EFAULT;
381 break;
382 }
383 userbuf += eeprom.len;
384 eeprom.offset += eeprom.len;
385 bytes_remaining -= eeprom.len;
386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700388 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
389 eeprom.offset -= eeprom.len;
390 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
391 ret = -EFAULT;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 kfree(data);
394 return ret;
395}
396
397static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
398{
399 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700400 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700401 void __user *userbuf = useraddr + sizeof(eeprom);
402 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700404 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (!ops->set_eeprom || !ops->get_eeprom_len)
407 return -EOPNOTSUPP;
408
409 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
410 return -EFAULT;
411
412 /* Check for wrap and zero */
413 if (eeprom.offset + eeprom.len <= eeprom.offset)
414 return -EINVAL;
415
416 /* Check for exceeding total eeprom len */
417 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
418 return -EINVAL;
419
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700420 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 if (!data)
422 return -ENOMEM;
423
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700424 bytes_remaining = eeprom.len;
425 while (bytes_remaining > 0) {
426 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700428 if (copy_from_user(data, userbuf, eeprom.len)) {
429 ret = -EFAULT;
430 break;
431 }
432 ret = ops->set_eeprom(dev, &eeprom, data);
433 if (ret)
434 break;
435 userbuf += eeprom.len;
436 eeprom.offset += eeprom.len;
437 bytes_remaining -= eeprom.len;
438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 kfree(data);
441 return ret;
442}
443
444static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
445{
446 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
447
448 if (!dev->ethtool_ops->get_coalesce)
449 return -EOPNOTSUPP;
450
451 dev->ethtool_ops->get_coalesce(dev, &coalesce);
452
453 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
454 return -EFAULT;
455 return 0;
456}
457
458static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
459{
460 struct ethtool_coalesce coalesce;
461
David S. Millerfa04ae52005-06-06 15:07:19 -0700462 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 return -EOPNOTSUPP;
464
465 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
466 return -EFAULT;
467
468 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
469}
470
471static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
472{
473 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
474
475 if (!dev->ethtool_ops->get_ringparam)
476 return -EOPNOTSUPP;
477
478 dev->ethtool_ops->get_ringparam(dev, &ringparam);
479
480 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
481 return -EFAULT;
482 return 0;
483}
484
485static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
486{
487 struct ethtool_ringparam ringparam;
488
489 if (!dev->ethtool_ops->set_ringparam)
490 return -EOPNOTSUPP;
491
492 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
493 return -EFAULT;
494
495 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
496}
497
498static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
499{
500 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
501
502 if (!dev->ethtool_ops->get_pauseparam)
503 return -EOPNOTSUPP;
504
505 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
506
507 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
508 return -EFAULT;
509 return 0;
510}
511
512static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
513{
514 struct ethtool_pauseparam pauseparam;
515
Jeff Garzike1b90c42006-07-17 12:54:40 -0400516 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return -EOPNOTSUPP;
518
519 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
520 return -EFAULT;
521
522 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
523}
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525static int __ethtool_set_sg(struct net_device *dev, u32 data)
526{
527 int err;
528
529 if (!data && dev->ethtool_ops->set_tso) {
530 err = dev->ethtool_ops->set_tso(dev, 0);
531 if (err)
532 return err;
533 }
534
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700535 if (!data && dev->ethtool_ops->set_ufo) {
536 err = dev->ethtool_ops->set_ufo(dev, 0);
537 if (err)
538 return err;
539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 return dev->ethtool_ops->set_sg(dev, data);
541}
542
543static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
544{
545 struct ethtool_value edata;
546 int err;
547
548 if (!dev->ethtool_ops->set_tx_csum)
549 return -EOPNOTSUPP;
550
551 if (copy_from_user(&edata, useraddr, sizeof(edata)))
552 return -EFAULT;
553
554 if (!edata.data && dev->ethtool_ops->set_sg) {
555 err = __ethtool_set_sg(dev, 0);
556 if (err)
557 return err;
558 }
559
560 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
561}
562
Herbert Xub240a0e2008-12-15 23:44:31 -0800563static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
564{
565 struct ethtool_value edata;
566
567 if (!dev->ethtool_ops->set_rx_csum)
568 return -EOPNOTSUPP;
569
570 if (copy_from_user(&edata, useraddr, sizeof(edata)))
571 return -EFAULT;
572
573 if (!edata.data && dev->ethtool_ops->set_sg)
574 dev->features &= ~NETIF_F_GRO;
575
576 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
577}
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
580{
581 struct ethtool_value edata;
582
583 if (!dev->ethtool_ops->set_sg)
584 return -EOPNOTSUPP;
585
586 if (copy_from_user(&edata, useraddr, sizeof(edata)))
587 return -EFAULT;
588
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900589 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -0700590 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return -EINVAL;
592
593 return __ethtool_set_sg(dev, edata.data);
594}
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
597{
598 struct ethtool_value edata;
599
600 if (!dev->ethtool_ops->set_tso)
601 return -EOPNOTSUPP;
602
603 if (copy_from_user(&edata, useraddr, sizeof(edata)))
604 return -EFAULT;
605
606 if (edata.data && !(dev->features & NETIF_F_SG))
607 return -EINVAL;
608
609 return dev->ethtool_ops->set_tso(dev, edata.data);
610}
611
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700612static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
613{
614 struct ethtool_value edata;
615
616 if (!dev->ethtool_ops->set_ufo)
617 return -EOPNOTSUPP;
618 if (copy_from_user(&edata, useraddr, sizeof(edata)))
619 return -EFAULT;
620 if (edata.data && !(dev->features & NETIF_F_SG))
621 return -EINVAL;
622 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
623 return -EINVAL;
624 return dev->ethtool_ops->set_ufo(dev, edata.data);
625}
626
Herbert Xu37c31852006-06-22 03:07:29 -0700627static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
628{
629 struct ethtool_value edata = { ETHTOOL_GGSO };
630
631 edata.data = dev->features & NETIF_F_GSO;
632 if (copy_to_user(useraddr, &edata, sizeof(edata)))
633 return -EFAULT;
634 return 0;
635}
636
637static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
638{
639 struct ethtool_value edata;
640
641 if (copy_from_user(&edata, useraddr, sizeof(edata)))
642 return -EFAULT;
643 if (edata.data)
644 dev->features |= NETIF_F_GSO;
645 else
646 dev->features &= ~NETIF_F_GSO;
647 return 0;
648}
649
Herbert Xub240a0e2008-12-15 23:44:31 -0800650static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
651{
652 struct ethtool_value edata = { ETHTOOL_GGRO };
653
654 edata.data = dev->features & NETIF_F_GRO;
655 if (copy_to_user(useraddr, &edata, sizeof(edata)))
656 return -EFAULT;
657 return 0;
658}
659
660static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
661{
662 struct ethtool_value edata;
663
664 if (copy_from_user(&edata, useraddr, sizeof(edata)))
665 return -EFAULT;
666
667 if (edata.data) {
668 if (!dev->ethtool_ops->get_rx_csum ||
669 !dev->ethtool_ops->get_rx_csum(dev))
670 return -EINVAL;
671 dev->features |= NETIF_F_GRO;
672 } else
673 dev->features &= ~NETIF_F_GRO;
674
675 return 0;
676}
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
679{
680 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700681 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700683 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Jeff Garzikff03d492007-08-15 16:01:08 -0700685 if (!ops->self_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 return -EOPNOTSUPP;
Jeff Garzikff03d492007-08-15 16:01:08 -0700687 if (!ops->get_sset_count && !ops->self_test_count)
688 return -EOPNOTSUPP;
689
690 if (ops->get_sset_count)
691 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
692 else
693 /* code path for obsolete hook */
694 test_len = ops->self_test_count(dev);
695 if (test_len < 0)
696 return test_len;
697 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 if (copy_from_user(&test, useraddr, sizeof(test)))
700 return -EFAULT;
701
Jeff Garzikff03d492007-08-15 16:01:08 -0700702 test.len = test_len;
703 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!data)
705 return -ENOMEM;
706
707 ops->self_test(dev, &test, data);
708
709 ret = -EFAULT;
710 if (copy_to_user(useraddr, &test, sizeof(test)))
711 goto out;
712 useraddr += sizeof(test);
713 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
714 goto out;
715 ret = 0;
716
717 out:
718 kfree(data);
719 return ret;
720}
721
722static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
723{
724 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700725 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 u8 *data;
727 int ret;
728
729 if (!ops->get_strings)
730 return -EOPNOTSUPP;
731
732 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
733 return -EFAULT;
734
Jeff Garzikff03d492007-08-15 16:01:08 -0700735 if (ops->get_sset_count) {
736 ret = ops->get_sset_count(dev, gstrings.string_set);
737 if (ret < 0)
738 return ret;
739
740 gstrings.len = ret;
741 } else {
742 /* code path for obsolete hooks */
743
744 switch (gstrings.string_set) {
745 case ETH_SS_TEST:
746 if (!ops->self_test_count)
747 return -EOPNOTSUPP;
748 gstrings.len = ops->self_test_count(dev);
749 break;
750 case ETH_SS_STATS:
751 if (!ops->get_stats_count)
752 return -EOPNOTSUPP;
753 gstrings.len = ops->get_stats_count(dev);
754 break;
755 default:
756 return -EINVAL;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759
760 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
761 if (!data)
762 return -ENOMEM;
763
764 ops->get_strings(dev, gstrings.string_set, data);
765
766 ret = -EFAULT;
767 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
768 goto out;
769 useraddr += sizeof(gstrings);
770 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
771 goto out;
772 ret = 0;
773
774 out:
775 kfree(data);
776 return ret;
777}
778
779static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
780{
781 struct ethtool_value id;
782
783 if (!dev->ethtool_ops->phys_id)
784 return -EOPNOTSUPP;
785
786 if (copy_from_user(&id, useraddr, sizeof(id)))
787 return -EFAULT;
788
789 return dev->ethtool_ops->phys_id(dev, id.data);
790}
791
792static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
793{
794 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700795 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700797 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Jeff Garzikff03d492007-08-15 16:01:08 -0700799 if (!ops->get_ethtool_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return -EOPNOTSUPP;
Jeff Garzikff03d492007-08-15 16:01:08 -0700801 if (!ops->get_sset_count && !ops->get_stats_count)
802 return -EOPNOTSUPP;
803
804 if (ops->get_sset_count)
805 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
806 else
807 /* code path for obsolete hook */
808 n_stats = ops->get_stats_count(dev);
809 if (n_stats < 0)
810 return n_stats;
811 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 if (copy_from_user(&stats, useraddr, sizeof(stats)))
814 return -EFAULT;
815
Jeff Garzikff03d492007-08-15 16:01:08 -0700816 stats.n_stats = n_stats;
817 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (!data)
819 return -ENOMEM;
820
821 ops->get_ethtool_stats(dev, &stats, data);
822
823 ret = -EFAULT;
824 if (copy_to_user(useraddr, &stats, sizeof(stats)))
825 goto out;
826 useraddr += sizeof(stats);
827 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
828 goto out;
829 ret = 0;
830
831 out:
832 kfree(data);
833 return ret;
834}
835
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +0100836static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -0700837{
838 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700839
Matthew Wilcox313674a2007-07-31 14:00:29 -0700840 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -0700841 return -EFAULT;
842
Matthew Wilcox313674a2007-07-31 14:00:29 -0700843 if (epaddr.size < dev->addr_len)
844 return -ETOOSMALL;
845 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700846
Jon Wetzela6f9a702005-08-20 17:15:54 -0700847 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -0700848 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700849 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -0700850 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
851 return -EFAULT;
852 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700853}
854
Jeff Garzik13c99b22007-08-15 16:01:56 -0700855static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
856 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700857{
Jeff Garzik13c99b22007-08-15 16:01:56 -0700858 struct ethtool_value edata = { cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700859
Jeff Garzik13c99b22007-08-15 16:01:56 -0700860 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700861 return -EOPNOTSUPP;
862
Jeff Garzik13c99b22007-08-15 16:01:56 -0700863 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700864
865 if (copy_to_user(useraddr, &edata, sizeof(edata)))
866 return -EFAULT;
867 return 0;
868}
869
Jeff Garzik13c99b22007-08-15 16:01:56 -0700870static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
871 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700872{
873 struct ethtool_value edata;
874
Jeff Garzik13c99b22007-08-15 16:01:56 -0700875 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700876 return -EOPNOTSUPP;
877
878 if (copy_from_user(&edata, useraddr, sizeof(edata)))
879 return -EFAULT;
880
Jeff Garzik13c99b22007-08-15 16:01:56 -0700881 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700882 return 0;
883}
884
Jeff Garzik13c99b22007-08-15 16:01:56 -0700885static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
886 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -0700887{
888 struct ethtool_value edata;
889
Jeff Garzik13c99b22007-08-15 16:01:56 -0700890 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -0700891 return -EOPNOTSUPP;
892
893 if (copy_from_user(&edata, useraddr, sizeof(edata)))
894 return -EFAULT;
895
Jeff Garzik13c99b22007-08-15 16:01:56 -0700896 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700897}
898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899/* The main entry point in this file. Called from net/core/dev.c */
900
Eric W. Biederman881d9662007-09-17 11:56:21 -0700901int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Eric W. Biederman881d9662007-09-17 11:56:21 -0700903 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 void __user *useraddr = ifr->ifr_data;
905 u32 ethcmd;
906 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -0700907 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (!dev || !netif_device_present(dev))
910 return -ENODEV;
911
912 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -0700913 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
916 return -EFAULT;
917
Stephen Hemminger75f31232006-09-28 15:13:37 -0700918 /* Allow some commands to be done by anyone */
919 switch(ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -0700920 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700921 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700922 case ETHTOOL_GCOALESCE:
923 case ETHTOOL_GRINGPARAM:
924 case ETHTOOL_GPAUSEPARAM:
925 case ETHTOOL_GRXCSUM:
926 case ETHTOOL_GTXCSUM:
927 case ETHTOOL_GSG:
928 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700929 case ETHTOOL_GTSO:
930 case ETHTOOL_GPERMADDR:
931 case ETHTOOL_GUFO:
932 case ETHTOOL_GGSO:
Jeff Garzik339bf022007-08-15 16:01:32 -0700933 case ETHTOOL_GFLAGS:
934 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -0700935 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -0800936 case ETHTOOL_GRXRINGS:
937 case ETHTOOL_GRXCLSRLCNT:
938 case ETHTOOL_GRXCLSRULE:
939 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700940 break;
941 default:
942 if (!capable(CAP_NET_ADMIN))
943 return -EPERM;
944 }
945
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700946 if (dev->ethtool_ops->begin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
948 return rc;
949
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -0700950 old_features = dev->features;
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 switch (ethcmd) {
953 case ETHTOOL_GSET:
954 rc = ethtool_get_settings(dev, useraddr);
955 break;
956 case ETHTOOL_SSET:
957 rc = ethtool_set_settings(dev, useraddr);
958 break;
959 case ETHTOOL_GDRVINFO:
960 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 break;
962 case ETHTOOL_GREGS:
963 rc = ethtool_get_regs(dev, useraddr);
964 break;
965 case ETHTOOL_GWOL:
966 rc = ethtool_get_wol(dev, useraddr);
967 break;
968 case ETHTOOL_SWOL:
969 rc = ethtool_set_wol(dev, useraddr);
970 break;
971 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700972 rc = ethtool_get_value(dev, useraddr, ethcmd,
973 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 break;
975 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700976 rc = ethtool_set_value_void(dev, useraddr,
977 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 break;
979 case ETHTOOL_NWAY_RST:
980 rc = ethtool_nway_reset(dev);
981 break;
982 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700983 rc = ethtool_get_value(dev, useraddr, ethcmd,
984 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 break;
986 case ETHTOOL_GEEPROM:
987 rc = ethtool_get_eeprom(dev, useraddr);
988 break;
989 case ETHTOOL_SEEPROM:
990 rc = ethtool_set_eeprom(dev, useraddr);
991 break;
992 case ETHTOOL_GCOALESCE:
993 rc = ethtool_get_coalesce(dev, useraddr);
994 break;
995 case ETHTOOL_SCOALESCE:
996 rc = ethtool_set_coalesce(dev, useraddr);
997 break;
998 case ETHTOOL_GRINGPARAM:
999 rc = ethtool_get_ringparam(dev, useraddr);
1000 break;
1001 case ETHTOOL_SRINGPARAM:
1002 rc = ethtool_set_ringparam(dev, useraddr);
1003 break;
1004 case ETHTOOL_GPAUSEPARAM:
1005 rc = ethtool_get_pauseparam(dev, useraddr);
1006 break;
1007 case ETHTOOL_SPAUSEPARAM:
1008 rc = ethtool_set_pauseparam(dev, useraddr);
1009 break;
1010 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001011 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001012 (dev->ethtool_ops->get_rx_csum ?
1013 dev->ethtool_ops->get_rx_csum :
1014 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 break;
1016 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001017 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 break;
1019 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001020 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001021 (dev->ethtool_ops->get_tx_csum ?
1022 dev->ethtool_ops->get_tx_csum :
1023 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
1025 case ETHTOOL_STXCSUM:
1026 rc = ethtool_set_tx_csum(dev, useraddr);
1027 break;
1028 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001029 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001030 (dev->ethtool_ops->get_sg ?
1031 dev->ethtool_ops->get_sg :
1032 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 break;
1034 case ETHTOOL_SSG:
1035 rc = ethtool_set_sg(dev, useraddr);
1036 break;
1037 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001038 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001039 (dev->ethtool_ops->get_tso ?
1040 dev->ethtool_ops->get_tso :
1041 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 break;
1043 case ETHTOOL_STSO:
1044 rc = ethtool_set_tso(dev, useraddr);
1045 break;
1046 case ETHTOOL_TEST:
1047 rc = ethtool_self_test(dev, useraddr);
1048 break;
1049 case ETHTOOL_GSTRINGS:
1050 rc = ethtool_get_strings(dev, useraddr);
1051 break;
1052 case ETHTOOL_PHYS_ID:
1053 rc = ethtool_phys_id(dev, useraddr);
1054 break;
1055 case ETHTOOL_GSTATS:
1056 rc = ethtool_get_stats(dev, useraddr);
1057 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001058 case ETHTOOL_GPERMADDR:
1059 rc = ethtool_get_perm_addr(dev, useraddr);
1060 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001061 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001062 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001063 (dev->ethtool_ops->get_ufo ?
1064 dev->ethtool_ops->get_ufo :
1065 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001066 break;
1067 case ETHTOOL_SUFO:
1068 rc = ethtool_set_ufo(dev, useraddr);
1069 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001070 case ETHTOOL_GGSO:
1071 rc = ethtool_get_gso(dev, useraddr);
1072 break;
1073 case ETHTOOL_SGSO:
1074 rc = ethtool_set_gso(dev, useraddr);
1075 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001076 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001077 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001078 (dev->ethtool_ops->get_flags ?
1079 dev->ethtool_ops->get_flags :
1080 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001081 break;
1082 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001083 rc = ethtool_set_value(dev, useraddr,
1084 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001085 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001086 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001087 rc = ethtool_get_value(dev, useraddr, ethcmd,
1088 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001089 break;
1090 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001091 rc = ethtool_set_value(dev, useraddr,
1092 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001093 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001094 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001095 case ETHTOOL_GRXRINGS:
1096 case ETHTOOL_GRXCLSRLCNT:
1097 case ETHTOOL_GRXCLSRULE:
1098 case ETHTOOL_GRXCLSRLALL:
1099 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001100 break;
1101 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001102 case ETHTOOL_SRXCLSRLDEL:
1103 case ETHTOOL_SRXCLSRLINS:
1104 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001105 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001106 case ETHTOOL_GGRO:
1107 rc = ethtool_get_gro(dev, useraddr);
1108 break;
1109 case ETHTOOL_SGRO:
1110 rc = ethtool_set_gro(dev, useraddr);
1111 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001113 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001115
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001116 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001118
1119 if (old_features != dev->features)
1120 netdev_features_change(dev);
1121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125EXPORT_SYMBOL(ethtool_op_get_link);
1126EXPORT_SYMBOL(ethtool_op_get_sg);
1127EXPORT_SYMBOL(ethtool_op_get_tso);
1128EXPORT_SYMBOL(ethtool_op_get_tx_csum);
1129EXPORT_SYMBOL(ethtool_op_set_sg);
1130EXPORT_SYMBOL(ethtool_op_set_tso);
1131EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Jon Mason69f6a0f2005-05-29 20:27:24 -07001132EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -07001133EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001134EXPORT_SYMBOL(ethtool_op_set_ufo);
1135EXPORT_SYMBOL(ethtool_op_get_ufo);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001136EXPORT_SYMBOL(ethtool_op_set_flags);
1137EXPORT_SYMBOL(ethtool_op_get_flags);