blob: d8aee584e8d1fe17edc534e2aba7c27b080bfa8b [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}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000037EXPORT_SYMBOL(ethtool_op_get_rx_csum);
Sridhar Samudrala1896e612009-07-22 13:38:22 +000038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039u32 ethtool_op_get_tx_csum(struct net_device *dev)
40{
Herbert Xu8648b302006-06-17 22:06:05 -070041 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
Eric Dumazet8a729fc2009-07-26 23:18:11 +000043EXPORT_SYMBOL(ethtool_op_get_tx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
46{
47 if (data)
48 dev->features |= NETIF_F_IP_CSUM;
49 else
50 dev->features &= ~NETIF_F_IP_CSUM;
51
52 return 0;
53}
54
Jon Mason69f6a0f2005-05-29 20:27:24 -070055int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
56{
57 if (data)
58 dev->features |= NETIF_F_HW_CSUM;
59 else
60 dev->features &= ~NETIF_F_HW_CSUM;
61
62 return 0;
63}
Michael Chan6460d942007-07-14 19:07:52 -070064
65int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
66{
67 if (data)
68 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
69 else
70 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
71
72 return 0;
73}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075u32 ethtool_op_get_sg(struct net_device *dev)
76{
77 return (dev->features & NETIF_F_SG) != 0;
78}
79
80int ethtool_op_set_sg(struct net_device *dev, u32 data)
81{
82 if (data)
83 dev->features |= NETIF_F_SG;
84 else
85 dev->features &= ~NETIF_F_SG;
86
87 return 0;
88}
89
90u32 ethtool_op_get_tso(struct net_device *dev)
91{
92 return (dev->features & NETIF_F_TSO) != 0;
93}
94
95int ethtool_op_set_tso(struct net_device *dev, u32 data)
96{
97 if (data)
98 dev->features |= NETIF_F_TSO;
99 else
100 dev->features &= ~NETIF_F_TSO;
101
102 return 0;
103}
104
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700105u32 ethtool_op_get_ufo(struct net_device *dev)
106{
107 return (dev->features & NETIF_F_UFO) != 0;
108}
109
110int ethtool_op_set_ufo(struct net_device *dev, u32 data)
111{
112 if (data)
113 dev->features |= NETIF_F_UFO;
114 else
115 dev->features &= ~NETIF_F_UFO;
116 return 0;
117}
118
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700119/* the following list of flags are the same as their associated
120 * NETIF_F_xxx values in include/linux/netdevice.h
121 */
122static const u32 flags_dup_features =
123 ETH_FLAG_LRO;
124
125u32 ethtool_op_get_flags(struct net_device *dev)
126{
127 /* in the future, this function will probably contain additional
128 * handling for flags which are not so easily handled
129 * by a simple masking operation
130 */
131
132 return dev->features & flags_dup_features;
133}
134
135int ethtool_op_set_flags(struct net_device *dev, u32 data)
136{
137 if (data & ETH_FLAG_LRO)
138 dev->features |= NETIF_F_LRO;
139 else
140 dev->features &= ~NETIF_F_LRO;
141
142 return 0;
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* Handlers for each ethtool command */
146
147static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
148{
149 struct ethtool_cmd cmd = { ETHTOOL_GSET };
150 int err;
151
152 if (!dev->ethtool_ops->get_settings)
153 return -EOPNOTSUPP;
154
155 err = dev->ethtool_ops->get_settings(dev, &cmd);
156 if (err < 0)
157 return err;
158
159 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
160 return -EFAULT;
161 return 0;
162}
163
164static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
165{
166 struct ethtool_cmd cmd;
167
168 if (!dev->ethtool_ops->set_settings)
169 return -EOPNOTSUPP;
170
171 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
172 return -EFAULT;
173
174 return dev->ethtool_ops->set_settings(dev, &cmd);
175}
176
177static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
178{
179 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700180 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 if (!ops->get_drvinfo)
183 return -EOPNOTSUPP;
184
185 memset(&info, 0, sizeof(info));
186 info.cmd = ETHTOOL_GDRVINFO;
187 ops->get_drvinfo(dev, &info);
188
Jeff Garzikff03d492007-08-15 16:01:08 -0700189 if (ops->get_sset_count) {
190 int rc;
191
192 rc = ops->get_sset_count(dev, ETH_SS_TEST);
193 if (rc >= 0)
194 info.testinfo_len = rc;
195 rc = ops->get_sset_count(dev, ETH_SS_STATS);
196 if (rc >= 0)
197 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700198 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
199 if (rc >= 0)
200 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (ops->get_regs_len)
203 info.regdump_len = ops->get_regs_len(dev);
204 if (ops->get_eeprom_len)
205 info.eedump_len = ops->get_eeprom_len(dev);
206
207 if (copy_to_user(useraddr, &info, sizeof(info)))
208 return -EFAULT;
209 return 0;
210}
211
Santwona Behera59089d82009-02-20 00:58:13 -0800212static int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700213{
214 struct ethtool_rxnfc cmd;
215
Santwona Behera59089d82009-02-20 00:58:13 -0800216 if (!dev->ethtool_ops->set_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700217 return -EOPNOTSUPP;
218
219 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
220 return -EFAULT;
221
Santwona Behera59089d82009-02-20 00:58:13 -0800222 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
Santwona Behera0853ad62008-07-02 03:47:41 -0700223}
224
Santwona Behera59089d82009-02-20 00:58:13 -0800225static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
Santwona Behera0853ad62008-07-02 03:47:41 -0700226{
227 struct ethtool_rxnfc info;
Santwona Behera59089d82009-02-20 00:58:13 -0800228 const struct ethtool_ops *ops = dev->ethtool_ops;
229 int ret;
230 void *rule_buf = NULL;
Santwona Behera0853ad62008-07-02 03:47:41 -0700231
Santwona Behera59089d82009-02-20 00:58:13 -0800232 if (!ops->get_rxnfc)
Santwona Behera0853ad62008-07-02 03:47:41 -0700233 return -EOPNOTSUPP;
234
235 if (copy_from_user(&info, useraddr, sizeof(info)))
236 return -EFAULT;
237
Santwona Behera59089d82009-02-20 00:58:13 -0800238 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
239 if (info.rule_cnt > 0) {
240 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
241 GFP_USER);
242 if (!rule_buf)
243 return -ENOMEM;
244 }
245 }
Santwona Behera0853ad62008-07-02 03:47:41 -0700246
Santwona Behera59089d82009-02-20 00:58:13 -0800247 ret = ops->get_rxnfc(dev, &info, rule_buf);
248 if (ret < 0)
249 goto err_out;
250
251 ret = -EFAULT;
Santwona Behera0853ad62008-07-02 03:47:41 -0700252 if (copy_to_user(useraddr, &info, sizeof(info)))
Santwona Behera59089d82009-02-20 00:58:13 -0800253 goto err_out;
254
255 if (rule_buf) {
256 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
257 if (copy_to_user(useraddr, rule_buf,
258 info.rule_cnt * sizeof(u32)))
259 goto err_out;
260 }
261 ret = 0;
262
263err_out:
Wei Yongjunc9cacec2009-03-31 15:06:26 -0700264 kfree(rule_buf);
Santwona Behera59089d82009-02-20 00:58:13 -0800265
266 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
270{
271 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700272 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 void *regbuf;
274 int reglen, ret;
275
276 if (!ops->get_regs || !ops->get_regs_len)
277 return -EOPNOTSUPP;
278
279 if (copy_from_user(&regs, useraddr, sizeof(regs)))
280 return -EFAULT;
281
282 reglen = ops->get_regs_len(dev);
283 if (regs.len > reglen)
284 regs.len = reglen;
285
286 regbuf = kmalloc(reglen, GFP_USER);
287 if (!regbuf)
288 return -ENOMEM;
289
290 ops->get_regs(dev, &regs, regbuf);
291
292 ret = -EFAULT;
293 if (copy_to_user(useraddr, &regs, sizeof(regs)))
294 goto out;
295 useraddr += offsetof(struct ethtool_regs, data);
296 if (copy_to_user(useraddr, regbuf, regs.len))
297 goto out;
298 ret = 0;
299
300 out:
301 kfree(regbuf);
302 return ret;
303}
304
Ben Hutchingsd73d3a82009-10-05 10:59:58 +0000305static int ethtool_reset(struct net_device *dev, char __user *useraddr)
306{
307 struct ethtool_value reset;
308 int ret;
309
310 if (!dev->ethtool_ops->reset)
311 return -EOPNOTSUPP;
312
313 if (copy_from_user(&reset, useraddr, sizeof(reset)))
314 return -EFAULT;
315
316 ret = dev->ethtool_ops->reset(dev, &reset.data);
317 if (ret)
318 return ret;
319
320 if (copy_to_user(useraddr, &reset, sizeof(reset)))
321 return -EFAULT;
322 return 0;
323}
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
326{
327 struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
328
329 if (!dev->ethtool_ops->get_wol)
330 return -EOPNOTSUPP;
331
332 dev->ethtool_ops->get_wol(dev, &wol);
333
334 if (copy_to_user(useraddr, &wol, sizeof(wol)))
335 return -EFAULT;
336 return 0;
337}
338
339static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
340{
341 struct ethtool_wolinfo wol;
342
343 if (!dev->ethtool_ops->set_wol)
344 return -EOPNOTSUPP;
345
346 if (copy_from_user(&wol, useraddr, sizeof(wol)))
347 return -EFAULT;
348
349 return dev->ethtool_ops->set_wol(dev, &wol);
350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352static int ethtool_nway_reset(struct net_device *dev)
353{
354 if (!dev->ethtool_ops->nway_reset)
355 return -EOPNOTSUPP;
356
357 return dev->ethtool_ops->nway_reset(dev);
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
361{
362 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700363 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700364 void __user *userbuf = useraddr + sizeof(eeprom);
365 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700367 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 if (!ops->get_eeprom || !ops->get_eeprom_len)
370 return -EOPNOTSUPP;
371
372 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
373 return -EFAULT;
374
375 /* Check for wrap and zero */
376 if (eeprom.offset + eeprom.len <= eeprom.offset)
377 return -EINVAL;
378
379 /* Check for exceeding total eeprom len */
380 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
381 return -EINVAL;
382
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700383 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (!data)
385 return -ENOMEM;
386
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700387 bytes_remaining = eeprom.len;
388 while (bytes_remaining > 0) {
389 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700391 ret = ops->get_eeprom(dev, &eeprom, data);
392 if (ret)
393 break;
394 if (copy_to_user(userbuf, data, eeprom.len)) {
395 ret = -EFAULT;
396 break;
397 }
398 userbuf += eeprom.len;
399 eeprom.offset += eeprom.len;
400 bytes_remaining -= eeprom.len;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700403 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
404 eeprom.offset -= eeprom.len;
405 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
406 ret = -EFAULT;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 kfree(data);
409 return ret;
410}
411
412static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
413{
414 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700415 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700416 void __user *userbuf = useraddr + sizeof(eeprom);
417 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700419 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 if (!ops->set_eeprom || !ops->get_eeprom_len)
422 return -EOPNOTSUPP;
423
424 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
425 return -EFAULT;
426
427 /* Check for wrap and zero */
428 if (eeprom.offset + eeprom.len <= eeprom.offset)
429 return -EINVAL;
430
431 /* Check for exceeding total eeprom len */
432 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
433 return -EINVAL;
434
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700435 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 if (!data)
437 return -ENOMEM;
438
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700439 bytes_remaining = eeprom.len;
440 while (bytes_remaining > 0) {
441 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700443 if (copy_from_user(data, userbuf, eeprom.len)) {
444 ret = -EFAULT;
445 break;
446 }
447 ret = ops->set_eeprom(dev, &eeprom, data);
448 if (ret)
449 break;
450 userbuf += eeprom.len;
451 eeprom.offset += eeprom.len;
452 bytes_remaining -= eeprom.len;
453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 kfree(data);
456 return ret;
457}
458
459static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
460{
461 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
462
463 if (!dev->ethtool_ops->get_coalesce)
464 return -EOPNOTSUPP;
465
466 dev->ethtool_ops->get_coalesce(dev, &coalesce);
467
468 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
469 return -EFAULT;
470 return 0;
471}
472
473static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
474{
475 struct ethtool_coalesce coalesce;
476
David S. Millerfa04ae52005-06-06 15:07:19 -0700477 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return -EOPNOTSUPP;
479
480 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
481 return -EFAULT;
482
483 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
484}
485
486static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
487{
488 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
489
490 if (!dev->ethtool_ops->get_ringparam)
491 return -EOPNOTSUPP;
492
493 dev->ethtool_ops->get_ringparam(dev, &ringparam);
494
495 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
496 return -EFAULT;
497 return 0;
498}
499
500static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
501{
502 struct ethtool_ringparam ringparam;
503
504 if (!dev->ethtool_ops->set_ringparam)
505 return -EOPNOTSUPP;
506
507 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
508 return -EFAULT;
509
510 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
511}
512
513static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
514{
515 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
516
517 if (!dev->ethtool_ops->get_pauseparam)
518 return -EOPNOTSUPP;
519
520 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
521
522 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
523 return -EFAULT;
524 return 0;
525}
526
527static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
528{
529 struct ethtool_pauseparam pauseparam;
530
Jeff Garzike1b90c42006-07-17 12:54:40 -0400531 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 return -EOPNOTSUPP;
533
534 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
535 return -EFAULT;
536
537 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
538}
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540static int __ethtool_set_sg(struct net_device *dev, u32 data)
541{
542 int err;
543
544 if (!data && dev->ethtool_ops->set_tso) {
545 err = dev->ethtool_ops->set_tso(dev, 0);
546 if (err)
547 return err;
548 }
549
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700550 if (!data && dev->ethtool_ops->set_ufo) {
551 err = dev->ethtool_ops->set_ufo(dev, 0);
552 if (err)
553 return err;
554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return dev->ethtool_ops->set_sg(dev, data);
556}
557
558static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
559{
560 struct ethtool_value edata;
561 int err;
562
563 if (!dev->ethtool_ops->set_tx_csum)
564 return -EOPNOTSUPP;
565
566 if (copy_from_user(&edata, useraddr, sizeof(edata)))
567 return -EFAULT;
568
569 if (!edata.data && dev->ethtool_ops->set_sg) {
570 err = __ethtool_set_sg(dev, 0);
571 if (err)
572 return err;
573 }
574
575 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
576}
577
Herbert Xub240a0e2008-12-15 23:44:31 -0800578static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
579{
580 struct ethtool_value edata;
581
582 if (!dev->ethtool_ops->set_rx_csum)
583 return -EOPNOTSUPP;
584
585 if (copy_from_user(&edata, useraddr, sizeof(edata)))
586 return -EFAULT;
587
588 if (!edata.data && dev->ethtool_ops->set_sg)
589 dev->features &= ~NETIF_F_GRO;
590
591 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
595{
596 struct ethtool_value edata;
597
598 if (!dev->ethtool_ops->set_sg)
599 return -EOPNOTSUPP;
600
601 if (copy_from_user(&edata, useraddr, sizeof(edata)))
602 return -EFAULT;
603
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900604 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -0700605 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 return -EINVAL;
607
608 return __ethtool_set_sg(dev, edata.data);
609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
612{
613 struct ethtool_value edata;
614
615 if (!dev->ethtool_ops->set_tso)
616 return -EOPNOTSUPP;
617
618 if (copy_from_user(&edata, useraddr, sizeof(edata)))
619 return -EFAULT;
620
621 if (edata.data && !(dev->features & NETIF_F_SG))
622 return -EINVAL;
623
624 return dev->ethtool_ops->set_tso(dev, edata.data);
625}
626
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700627static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
628{
629 struct ethtool_value edata;
630
631 if (!dev->ethtool_ops->set_ufo)
632 return -EOPNOTSUPP;
633 if (copy_from_user(&edata, useraddr, sizeof(edata)))
634 return -EFAULT;
635 if (edata.data && !(dev->features & NETIF_F_SG))
636 return -EINVAL;
637 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
638 return -EINVAL;
639 return dev->ethtool_ops->set_ufo(dev, edata.data);
640}
641
Herbert Xu37c31852006-06-22 03:07:29 -0700642static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
643{
644 struct ethtool_value edata = { ETHTOOL_GGSO };
645
646 edata.data = dev->features & NETIF_F_GSO;
647 if (copy_to_user(useraddr, &edata, sizeof(edata)))
648 return -EFAULT;
649 return 0;
650}
651
652static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
653{
654 struct ethtool_value edata;
655
656 if (copy_from_user(&edata, useraddr, sizeof(edata)))
657 return -EFAULT;
658 if (edata.data)
659 dev->features |= NETIF_F_GSO;
660 else
661 dev->features &= ~NETIF_F_GSO;
662 return 0;
663}
664
Herbert Xub240a0e2008-12-15 23:44:31 -0800665static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
666{
667 struct ethtool_value edata = { ETHTOOL_GGRO };
668
669 edata.data = dev->features & NETIF_F_GRO;
670 if (copy_to_user(useraddr, &edata, sizeof(edata)))
671 return -EFAULT;
672 return 0;
673}
674
675static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
676{
677 struct ethtool_value edata;
678
679 if (copy_from_user(&edata, useraddr, sizeof(edata)))
680 return -EFAULT;
681
682 if (edata.data) {
683 if (!dev->ethtool_ops->get_rx_csum ||
684 !dev->ethtool_ops->get_rx_csum(dev))
685 return -EINVAL;
686 dev->features |= NETIF_F_GRO;
687 } else
688 dev->features &= ~NETIF_F_GRO;
689
690 return 0;
691}
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
694{
695 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700696 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700698 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000700 if (!ops->self_test || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700701 return -EOPNOTSUPP;
702
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000703 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
Jeff Garzikff03d492007-08-15 16:01:08 -0700704 if (test_len < 0)
705 return test_len;
706 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
708 if (copy_from_user(&test, useraddr, sizeof(test)))
709 return -EFAULT;
710
Jeff Garzikff03d492007-08-15 16:01:08 -0700711 test.len = test_len;
712 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (!data)
714 return -ENOMEM;
715
716 ops->self_test(dev, &test, data);
717
718 ret = -EFAULT;
719 if (copy_to_user(useraddr, &test, sizeof(test)))
720 goto out;
721 useraddr += sizeof(test);
722 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
723 goto out;
724 ret = 0;
725
726 out:
727 kfree(data);
728 return ret;
729}
730
731static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
732{
733 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700734 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 u8 *data;
736 int ret;
737
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000738 if (!ops->get_strings || !ops->get_sset_count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 return -EOPNOTSUPP;
740
741 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
742 return -EFAULT;
743
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000744 ret = ops->get_sset_count(dev, gstrings.string_set);
745 if (ret < 0)
746 return ret;
Jeff Garzikff03d492007-08-15 16:01:08 -0700747
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000748 gstrings.len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
751 if (!data)
752 return -ENOMEM;
753
754 ops->get_strings(dev, gstrings.string_set, data);
755
756 ret = -EFAULT;
757 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
758 goto out;
759 useraddr += sizeof(gstrings);
760 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
761 goto out;
762 ret = 0;
763
764 out:
765 kfree(data);
766 return ret;
767}
768
769static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
770{
771 struct ethtool_value id;
772
773 if (!dev->ethtool_ops->phys_id)
774 return -EOPNOTSUPP;
775
776 if (copy_from_user(&id, useraddr, sizeof(id)))
777 return -EFAULT;
778
779 return dev->ethtool_ops->phys_id(dev, id.data);
780}
781
782static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
783{
784 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700785 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700787 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000789 if (!ops->get_ethtool_stats || !ops->get_sset_count)
Jeff Garzikff03d492007-08-15 16:01:08 -0700790 return -EOPNOTSUPP;
791
Ben Hutchingsa9828ec2009-10-01 11:33:03 +0000792 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
Jeff Garzikff03d492007-08-15 16:01:08 -0700793 if (n_stats < 0)
794 return n_stats;
795 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (copy_from_user(&stats, useraddr, sizeof(stats)))
798 return -EFAULT;
799
Jeff Garzikff03d492007-08-15 16:01:08 -0700800 stats.n_stats = n_stats;
801 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 if (!data)
803 return -ENOMEM;
804
805 ops->get_ethtool_stats(dev, &stats, data);
806
807 ret = -EFAULT;
808 if (copy_to_user(useraddr, &stats, sizeof(stats)))
809 goto out;
810 useraddr += sizeof(stats);
811 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
812 goto out;
813 ret = 0;
814
815 out:
816 kfree(data);
817 return ret;
818}
819
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +0100820static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -0700821{
822 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700823
Matthew Wilcox313674a2007-07-31 14:00:29 -0700824 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -0700825 return -EFAULT;
826
Matthew Wilcox313674a2007-07-31 14:00:29 -0700827 if (epaddr.size < dev->addr_len)
828 return -ETOOSMALL;
829 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700830
Jon Wetzela6f9a702005-08-20 17:15:54 -0700831 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -0700832 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700833 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -0700834 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
835 return -EFAULT;
836 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700837}
838
Jeff Garzik13c99b22007-08-15 16:01:56 -0700839static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
840 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700841{
Jeff Garzik13c99b22007-08-15 16:01:56 -0700842 struct ethtool_value edata = { cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700843
Jeff Garzik13c99b22007-08-15 16:01:56 -0700844 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700845 return -EOPNOTSUPP;
846
Jeff Garzik13c99b22007-08-15 16:01:56 -0700847 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700848
849 if (copy_to_user(useraddr, &edata, sizeof(edata)))
850 return -EFAULT;
851 return 0;
852}
853
Jeff Garzik13c99b22007-08-15 16:01:56 -0700854static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
855 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700856{
857 struct ethtool_value edata;
858
Jeff Garzik13c99b22007-08-15 16:01:56 -0700859 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700860 return -EOPNOTSUPP;
861
862 if (copy_from_user(&edata, useraddr, sizeof(edata)))
863 return -EFAULT;
864
Jeff Garzik13c99b22007-08-15 16:01:56 -0700865 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700866 return 0;
867}
868
Jeff Garzik13c99b22007-08-15 16:01:56 -0700869static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
870 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -0700871{
872 struct ethtool_value edata;
873
Jeff Garzik13c99b22007-08-15 16:01:56 -0700874 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -0700875 return -EOPNOTSUPP;
876
877 if (copy_from_user(&edata, useraddr, sizeof(edata)))
878 return -EFAULT;
879
Jeff Garzik13c99b22007-08-15 16:01:56 -0700880 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700881}
882
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +0000883static int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
884{
885 struct ethtool_flash efl;
886
887 if (copy_from_user(&efl, useraddr, sizeof(efl)))
888 return -EFAULT;
889
890 if (!dev->ethtool_ops->flash_device)
891 return -EOPNOTSUPP;
892
893 return dev->ethtool_ops->flash_device(dev, &efl);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896/* The main entry point in this file. Called from net/core/dev.c */
897
Eric W. Biederman881d9662007-09-17 11:56:21 -0700898int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Eric W. Biederman881d9662007-09-17 11:56:21 -0700900 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 void __user *useraddr = ifr->ifr_data;
902 u32 ethcmd;
903 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -0700904 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (!dev || !netif_device_present(dev))
907 return -ENODEV;
908
909 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -0700910 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
913 return -EFAULT;
914
Stephen Hemminger75f31232006-09-28 15:13:37 -0700915 /* Allow some commands to be done by anyone */
916 switch(ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -0700917 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700918 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700919 case ETHTOOL_GCOALESCE:
920 case ETHTOOL_GRINGPARAM:
921 case ETHTOOL_GPAUSEPARAM:
922 case ETHTOOL_GRXCSUM:
923 case ETHTOOL_GTXCSUM:
924 case ETHTOOL_GSG:
925 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700926 case ETHTOOL_GTSO:
927 case ETHTOOL_GPERMADDR:
928 case ETHTOOL_GUFO:
929 case ETHTOOL_GGSO:
Jeff Garzik339bf022007-08-15 16:01:32 -0700930 case ETHTOOL_GFLAGS:
931 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -0700932 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -0800933 case ETHTOOL_GRXRINGS:
934 case ETHTOOL_GRXCLSRLCNT:
935 case ETHTOOL_GRXCLSRULE:
936 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700937 break;
938 default:
939 if (!capable(CAP_NET_ADMIN))
940 return -EPERM;
941 }
942
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700943 if (dev->ethtool_ops->begin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
945 return rc;
946
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -0700947 old_features = dev->features;
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 switch (ethcmd) {
950 case ETHTOOL_GSET:
951 rc = ethtool_get_settings(dev, useraddr);
952 break;
953 case ETHTOOL_SSET:
954 rc = ethtool_set_settings(dev, useraddr);
955 break;
956 case ETHTOOL_GDRVINFO:
957 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 break;
959 case ETHTOOL_GREGS:
960 rc = ethtool_get_regs(dev, useraddr);
961 break;
962 case ETHTOOL_GWOL:
963 rc = ethtool_get_wol(dev, useraddr);
964 break;
965 case ETHTOOL_SWOL:
966 rc = ethtool_set_wol(dev, useraddr);
967 break;
968 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700969 rc = ethtool_get_value(dev, useraddr, ethcmd,
970 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 break;
972 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700973 rc = ethtool_set_value_void(dev, useraddr,
974 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
976 case ETHTOOL_NWAY_RST:
977 rc = ethtool_nway_reset(dev);
978 break;
979 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700980 rc = ethtool_get_value(dev, useraddr, ethcmd,
981 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 break;
983 case ETHTOOL_GEEPROM:
984 rc = ethtool_get_eeprom(dev, useraddr);
985 break;
986 case ETHTOOL_SEEPROM:
987 rc = ethtool_set_eeprom(dev, useraddr);
988 break;
989 case ETHTOOL_GCOALESCE:
990 rc = ethtool_get_coalesce(dev, useraddr);
991 break;
992 case ETHTOOL_SCOALESCE:
993 rc = ethtool_set_coalesce(dev, useraddr);
994 break;
995 case ETHTOOL_GRINGPARAM:
996 rc = ethtool_get_ringparam(dev, useraddr);
997 break;
998 case ETHTOOL_SRINGPARAM:
999 rc = ethtool_set_ringparam(dev, useraddr);
1000 break;
1001 case ETHTOOL_GPAUSEPARAM:
1002 rc = ethtool_get_pauseparam(dev, useraddr);
1003 break;
1004 case ETHTOOL_SPAUSEPARAM:
1005 rc = ethtool_set_pauseparam(dev, useraddr);
1006 break;
1007 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001008 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001009 (dev->ethtool_ops->get_rx_csum ?
1010 dev->ethtool_ops->get_rx_csum :
1011 ethtool_op_get_rx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 break;
1013 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001014 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 break;
1016 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001017 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001018 (dev->ethtool_ops->get_tx_csum ?
1019 dev->ethtool_ops->get_tx_csum :
1020 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 break;
1022 case ETHTOOL_STXCSUM:
1023 rc = ethtool_set_tx_csum(dev, useraddr);
1024 break;
1025 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001026 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001027 (dev->ethtool_ops->get_sg ?
1028 dev->ethtool_ops->get_sg :
1029 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 break;
1031 case ETHTOOL_SSG:
1032 rc = ethtool_set_sg(dev, useraddr);
1033 break;
1034 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001035 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001036 (dev->ethtool_ops->get_tso ?
1037 dev->ethtool_ops->get_tso :
1038 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 break;
1040 case ETHTOOL_STSO:
1041 rc = ethtool_set_tso(dev, useraddr);
1042 break;
1043 case ETHTOOL_TEST:
1044 rc = ethtool_self_test(dev, useraddr);
1045 break;
1046 case ETHTOOL_GSTRINGS:
1047 rc = ethtool_get_strings(dev, useraddr);
1048 break;
1049 case ETHTOOL_PHYS_ID:
1050 rc = ethtool_phys_id(dev, useraddr);
1051 break;
1052 case ETHTOOL_GSTATS:
1053 rc = ethtool_get_stats(dev, useraddr);
1054 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001055 case ETHTOOL_GPERMADDR:
1056 rc = ethtool_get_perm_addr(dev, useraddr);
1057 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001058 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001059 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001060 (dev->ethtool_ops->get_ufo ?
1061 dev->ethtool_ops->get_ufo :
1062 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001063 break;
1064 case ETHTOOL_SUFO:
1065 rc = ethtool_set_ufo(dev, useraddr);
1066 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001067 case ETHTOOL_GGSO:
1068 rc = ethtool_get_gso(dev, useraddr);
1069 break;
1070 case ETHTOOL_SGSO:
1071 rc = ethtool_set_gso(dev, useraddr);
1072 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001073 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001074 rc = ethtool_get_value(dev, useraddr, ethcmd,
Sridhar Samudrala1896e612009-07-22 13:38:22 +00001075 (dev->ethtool_ops->get_flags ?
1076 dev->ethtool_ops->get_flags :
1077 ethtool_op_get_flags));
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001078 break;
1079 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001080 rc = ethtool_set_value(dev, useraddr,
1081 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001082 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001083 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001084 rc = ethtool_get_value(dev, useraddr, ethcmd,
1085 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001086 break;
1087 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001088 rc = ethtool_set_value(dev, useraddr,
1089 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001090 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001091 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001092 case ETHTOOL_GRXRINGS:
1093 case ETHTOOL_GRXCLSRLCNT:
1094 case ETHTOOL_GRXCLSRULE:
1095 case ETHTOOL_GRXCLSRLALL:
1096 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001097 break;
1098 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001099 case ETHTOOL_SRXCLSRLDEL:
1100 case ETHTOOL_SRXCLSRLINS:
1101 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001102 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001103 case ETHTOOL_GGRO:
1104 rc = ethtool_get_gro(dev, useraddr);
1105 break;
1106 case ETHTOOL_SGRO:
1107 rc = ethtool_set_gro(dev, useraddr);
1108 break;
Ajit Khaparde05c6a8d2009-09-02 17:02:55 +00001109 case ETHTOOL_FLASHDEV:
1110 rc = ethtool_flash_device(dev, useraddr);
1111 break;
Ben Hutchingsd73d3a82009-10-05 10:59:58 +00001112 case ETHTOOL_RESET:
1113 rc = ethtool_reset(dev, useraddr);
1114 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001116 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001118
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001119 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001121
1122 if (old_features != dev->features)
1123 netdev_features_change(dev);
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128EXPORT_SYMBOL(ethtool_op_get_link);
1129EXPORT_SYMBOL(ethtool_op_get_sg);
1130EXPORT_SYMBOL(ethtool_op_get_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131EXPORT_SYMBOL(ethtool_op_set_sg);
1132EXPORT_SYMBOL(ethtool_op_set_tso);
1133EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Jon Mason69f6a0f2005-05-29 20:27:24 -07001134EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -07001135EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001136EXPORT_SYMBOL(ethtool_op_set_ufo);
1137EXPORT_SYMBOL(ethtool_op_get_ufo);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001138EXPORT_SYMBOL(ethtool_op_set_flags);
1139EXPORT_SYMBOL(ethtool_op_get_flags);