blob: 244ca56dffac3eb57536142f5aa36e2f4a6f12a5 [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
33u32 ethtool_op_get_tx_csum(struct net_device *dev)
34{
Herbert Xu8648b302006-06-17 22:06:05 -070035 return (dev->features & NETIF_F_ALL_CSUM) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
39{
40 if (data)
41 dev->features |= NETIF_F_IP_CSUM;
42 else
43 dev->features &= ~NETIF_F_IP_CSUM;
44
45 return 0;
46}
47
Jon Mason69f6a0f2005-05-29 20:27:24 -070048int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
49{
50 if (data)
51 dev->features |= NETIF_F_HW_CSUM;
52 else
53 dev->features &= ~NETIF_F_HW_CSUM;
54
55 return 0;
56}
Michael Chan6460d942007-07-14 19:07:52 -070057
58int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
59{
60 if (data)
61 dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
62 else
63 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
64
65 return 0;
66}
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068u32 ethtool_op_get_sg(struct net_device *dev)
69{
70 return (dev->features & NETIF_F_SG) != 0;
71}
72
73int ethtool_op_set_sg(struct net_device *dev, u32 data)
74{
75 if (data)
76 dev->features |= NETIF_F_SG;
77 else
78 dev->features &= ~NETIF_F_SG;
79
80 return 0;
81}
82
83u32 ethtool_op_get_tso(struct net_device *dev)
84{
85 return (dev->features & NETIF_F_TSO) != 0;
86}
87
88int ethtool_op_set_tso(struct net_device *dev, u32 data)
89{
90 if (data)
91 dev->features |= NETIF_F_TSO;
92 else
93 dev->features &= ~NETIF_F_TSO;
94
95 return 0;
96}
97
Ananda Rajue89e9cf2005-10-18 15:46:41 -070098u32 ethtool_op_get_ufo(struct net_device *dev)
99{
100 return (dev->features & NETIF_F_UFO) != 0;
101}
102
103int ethtool_op_set_ufo(struct net_device *dev, u32 data)
104{
105 if (data)
106 dev->features |= NETIF_F_UFO;
107 else
108 dev->features &= ~NETIF_F_UFO;
109 return 0;
110}
111
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700112/* the following list of flags are the same as their associated
113 * NETIF_F_xxx values in include/linux/netdevice.h
114 */
115static const u32 flags_dup_features =
116 ETH_FLAG_LRO;
117
118u32 ethtool_op_get_flags(struct net_device *dev)
119{
120 /* in the future, this function will probably contain additional
121 * handling for flags which are not so easily handled
122 * by a simple masking operation
123 */
124
125 return dev->features & flags_dup_features;
126}
127
128int ethtool_op_set_flags(struct net_device *dev, u32 data)
129{
130 if (data & ETH_FLAG_LRO)
131 dev->features |= NETIF_F_LRO;
132 else
133 dev->features &= ~NETIF_F_LRO;
134
135 return 0;
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Handlers for each ethtool command */
139
140static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
141{
142 struct ethtool_cmd cmd = { ETHTOOL_GSET };
143 int err;
144
145 if (!dev->ethtool_ops->get_settings)
146 return -EOPNOTSUPP;
147
148 err = dev->ethtool_ops->get_settings(dev, &cmd);
149 if (err < 0)
150 return err;
151
152 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
153 return -EFAULT;
154 return 0;
155}
156
157static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
158{
159 struct ethtool_cmd cmd;
160
161 if (!dev->ethtool_ops->set_settings)
162 return -EOPNOTSUPP;
163
164 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
165 return -EFAULT;
166
167 return dev->ethtool_ops->set_settings(dev, &cmd);
168}
169
170static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
171{
172 struct ethtool_drvinfo info;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700173 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 if (!ops->get_drvinfo)
176 return -EOPNOTSUPP;
177
178 memset(&info, 0, sizeof(info));
179 info.cmd = ETHTOOL_GDRVINFO;
180 ops->get_drvinfo(dev, &info);
181
Jeff Garzikff03d492007-08-15 16:01:08 -0700182 if (ops->get_sset_count) {
183 int rc;
184
185 rc = ops->get_sset_count(dev, ETH_SS_TEST);
186 if (rc >= 0)
187 info.testinfo_len = rc;
188 rc = ops->get_sset_count(dev, ETH_SS_STATS);
189 if (rc >= 0)
190 info.n_stats = rc;
Jeff Garzik339bf022007-08-15 16:01:32 -0700191 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
192 if (rc >= 0)
193 info.n_priv_flags = rc;
Jeff Garzikff03d492007-08-15 16:01:08 -0700194 } else {
195 /* code path for obsolete hooks */
196
197 if (ops->self_test_count)
198 info.testinfo_len = ops->self_test_count(dev);
199 if (ops->get_stats_count)
200 info.n_stats = ops->get_stats_count(dev);
201 }
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:
264 if (rule_buf)
265 kfree(rule_buf);
266
267 return ret;
Santwona Behera0853ad62008-07-02 03:47:41 -0700268}
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
271{
272 struct ethtool_regs regs;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700273 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 void *regbuf;
275 int reglen, ret;
276
277 if (!ops->get_regs || !ops->get_regs_len)
278 return -EOPNOTSUPP;
279
280 if (copy_from_user(&regs, useraddr, sizeof(regs)))
281 return -EFAULT;
282
283 reglen = ops->get_regs_len(dev);
284 if (regs.len > reglen)
285 regs.len = reglen;
286
287 regbuf = kmalloc(reglen, GFP_USER);
288 if (!regbuf)
289 return -ENOMEM;
290
291 ops->get_regs(dev, &regs, regbuf);
292
293 ret = -EFAULT;
294 if (copy_to_user(useraddr, &regs, sizeof(regs)))
295 goto out;
296 useraddr += offsetof(struct ethtool_regs, data);
297 if (copy_to_user(useraddr, regbuf, regs.len))
298 goto out;
299 ret = 0;
300
301 out:
302 kfree(regbuf);
303 return ret;
304}
305
306static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
307{
308 struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
309
310 if (!dev->ethtool_ops->get_wol)
311 return -EOPNOTSUPP;
312
313 dev->ethtool_ops->get_wol(dev, &wol);
314
315 if (copy_to_user(useraddr, &wol, sizeof(wol)))
316 return -EFAULT;
317 return 0;
318}
319
320static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
321{
322 struct ethtool_wolinfo wol;
323
324 if (!dev->ethtool_ops->set_wol)
325 return -EOPNOTSUPP;
326
327 if (copy_from_user(&wol, useraddr, sizeof(wol)))
328 return -EFAULT;
329
330 return dev->ethtool_ops->set_wol(dev, &wol);
331}
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333static int ethtool_nway_reset(struct net_device *dev)
334{
335 if (!dev->ethtool_ops->nway_reset)
336 return -EOPNOTSUPP;
337
338 return dev->ethtool_ops->nway_reset(dev);
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
342{
343 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700344 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700345 void __user *userbuf = useraddr + sizeof(eeprom);
346 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700348 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 if (!ops->get_eeprom || !ops->get_eeprom_len)
351 return -EOPNOTSUPP;
352
353 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
354 return -EFAULT;
355
356 /* Check for wrap and zero */
357 if (eeprom.offset + eeprom.len <= eeprom.offset)
358 return -EINVAL;
359
360 /* Check for exceeding total eeprom len */
361 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
362 return -EINVAL;
363
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700364 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (!data)
366 return -ENOMEM;
367
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700368 bytes_remaining = eeprom.len;
369 while (bytes_remaining > 0) {
370 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700372 ret = ops->get_eeprom(dev, &eeprom, data);
373 if (ret)
374 break;
375 if (copy_to_user(userbuf, data, eeprom.len)) {
376 ret = -EFAULT;
377 break;
378 }
379 userbuf += eeprom.len;
380 eeprom.offset += eeprom.len;
381 bytes_remaining -= eeprom.len;
382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Mandeep Singh Bainesc5835df2008-04-24 20:55:56 -0700384 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
385 eeprom.offset -= eeprom.len;
386 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
387 ret = -EFAULT;
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 kfree(data);
390 return ret;
391}
392
393static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
394{
395 struct ethtool_eeprom eeprom;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700396 const struct ethtool_ops *ops = dev->ethtool_ops;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700397 void __user *userbuf = useraddr + sizeof(eeprom);
398 u32 bytes_remaining;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 u8 *data;
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700400 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 if (!ops->set_eeprom || !ops->get_eeprom_len)
403 return -EOPNOTSUPP;
404
405 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
406 return -EFAULT;
407
408 /* Check for wrap and zero */
409 if (eeprom.offset + eeprom.len <= eeprom.offset)
410 return -EINVAL;
411
412 /* Check for exceeding total eeprom len */
413 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
414 return -EINVAL;
415
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700416 data = kmalloc(PAGE_SIZE, GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (!data)
418 return -ENOMEM;
419
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700420 bytes_remaining = eeprom.len;
421 while (bytes_remaining > 0) {
422 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Mandeep Singh Bainesb131dd52008-04-15 19:24:17 -0700424 if (copy_from_user(data, userbuf, eeprom.len)) {
425 ret = -EFAULT;
426 break;
427 }
428 ret = ops->set_eeprom(dev, &eeprom, data);
429 if (ret)
430 break;
431 userbuf += eeprom.len;
432 eeprom.offset += eeprom.len;
433 bytes_remaining -= eeprom.len;
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 kfree(data);
437 return ret;
438}
439
440static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
441{
442 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
443
444 if (!dev->ethtool_ops->get_coalesce)
445 return -EOPNOTSUPP;
446
447 dev->ethtool_ops->get_coalesce(dev, &coalesce);
448
449 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
450 return -EFAULT;
451 return 0;
452}
453
454static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
455{
456 struct ethtool_coalesce coalesce;
457
David S. Millerfa04ae52005-06-06 15:07:19 -0700458 if (!dev->ethtool_ops->set_coalesce)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 return -EOPNOTSUPP;
460
461 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
462 return -EFAULT;
463
464 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
465}
466
467static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
468{
469 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
470
471 if (!dev->ethtool_ops->get_ringparam)
472 return -EOPNOTSUPP;
473
474 dev->ethtool_ops->get_ringparam(dev, &ringparam);
475
476 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
477 return -EFAULT;
478 return 0;
479}
480
481static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
482{
483 struct ethtool_ringparam ringparam;
484
485 if (!dev->ethtool_ops->set_ringparam)
486 return -EOPNOTSUPP;
487
488 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
489 return -EFAULT;
490
491 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
492}
493
494static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
495{
496 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
497
498 if (!dev->ethtool_ops->get_pauseparam)
499 return -EOPNOTSUPP;
500
501 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
502
503 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
504 return -EFAULT;
505 return 0;
506}
507
508static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
509{
510 struct ethtool_pauseparam pauseparam;
511
Jeff Garzike1b90c42006-07-17 12:54:40 -0400512 if (!dev->ethtool_ops->set_pauseparam)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return -EOPNOTSUPP;
514
515 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
516 return -EFAULT;
517
518 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521static int __ethtool_set_sg(struct net_device *dev, u32 data)
522{
523 int err;
524
525 if (!data && dev->ethtool_ops->set_tso) {
526 err = dev->ethtool_ops->set_tso(dev, 0);
527 if (err)
528 return err;
529 }
530
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700531 if (!data && dev->ethtool_ops->set_ufo) {
532 err = dev->ethtool_ops->set_ufo(dev, 0);
533 if (err)
534 return err;
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 return dev->ethtool_ops->set_sg(dev, data);
537}
538
539static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
540{
541 struct ethtool_value edata;
542 int err;
543
544 if (!dev->ethtool_ops->set_tx_csum)
545 return -EOPNOTSUPP;
546
547 if (copy_from_user(&edata, useraddr, sizeof(edata)))
548 return -EFAULT;
549
550 if (!edata.data && dev->ethtool_ops->set_sg) {
551 err = __ethtool_set_sg(dev, 0);
552 if (err)
553 return err;
554 }
555
556 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
557}
558
Herbert Xub240a0e2008-12-15 23:44:31 -0800559static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
560{
561 struct ethtool_value edata;
562
563 if (!dev->ethtool_ops->set_rx_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 dev->features &= ~NETIF_F_GRO;
571
572 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
573}
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
576{
577 struct ethtool_value edata;
578
579 if (!dev->ethtool_ops->set_sg)
580 return -EOPNOTSUPP;
581
582 if (copy_from_user(&edata, useraddr, sizeof(edata)))
583 return -EFAULT;
584
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +0900585 if (edata.data &&
Herbert Xu8648b302006-06-17 22:06:05 -0700586 !(dev->features & NETIF_F_ALL_CSUM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 return -EINVAL;
588
589 return __ethtool_set_sg(dev, edata.data);
590}
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
593{
594 struct ethtool_value edata;
595
596 if (!dev->ethtool_ops->set_tso)
597 return -EOPNOTSUPP;
598
599 if (copy_from_user(&edata, useraddr, sizeof(edata)))
600 return -EFAULT;
601
602 if (edata.data && !(dev->features & NETIF_F_SG))
603 return -EINVAL;
604
605 return dev->ethtool_ops->set_tso(dev, edata.data);
606}
607
Ananda Rajue89e9cf2005-10-18 15:46:41 -0700608static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
609{
610 struct ethtool_value edata;
611
612 if (!dev->ethtool_ops->set_ufo)
613 return -EOPNOTSUPP;
614 if (copy_from_user(&edata, useraddr, sizeof(edata)))
615 return -EFAULT;
616 if (edata.data && !(dev->features & NETIF_F_SG))
617 return -EINVAL;
618 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
619 return -EINVAL;
620 return dev->ethtool_ops->set_ufo(dev, edata.data);
621}
622
Herbert Xu37c31852006-06-22 03:07:29 -0700623static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
624{
625 struct ethtool_value edata = { ETHTOOL_GGSO };
626
627 edata.data = dev->features & NETIF_F_GSO;
628 if (copy_to_user(useraddr, &edata, sizeof(edata)))
629 return -EFAULT;
630 return 0;
631}
632
633static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
634{
635 struct ethtool_value edata;
636
637 if (copy_from_user(&edata, useraddr, sizeof(edata)))
638 return -EFAULT;
639 if (edata.data)
640 dev->features |= NETIF_F_GSO;
641 else
642 dev->features &= ~NETIF_F_GSO;
643 return 0;
644}
645
Herbert Xub240a0e2008-12-15 23:44:31 -0800646static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
647{
648 struct ethtool_value edata = { ETHTOOL_GGRO };
649
650 edata.data = dev->features & NETIF_F_GRO;
651 if (copy_to_user(useraddr, &edata, sizeof(edata)))
652 return -EFAULT;
653 return 0;
654}
655
656static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
657{
658 struct ethtool_value edata;
659
660 if (copy_from_user(&edata, useraddr, sizeof(edata)))
661 return -EFAULT;
662
663 if (edata.data) {
664 if (!dev->ethtool_ops->get_rx_csum ||
665 !dev->ethtool_ops->get_rx_csum(dev))
666 return -EINVAL;
667 dev->features |= NETIF_F_GRO;
668 } else
669 dev->features &= ~NETIF_F_GRO;
670
671 return 0;
672}
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
675{
676 struct ethtool_test test;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700677 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700679 int ret, test_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Jeff Garzikff03d492007-08-15 16:01:08 -0700681 if (!ops->self_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 return -EOPNOTSUPP;
Jeff Garzikff03d492007-08-15 16:01:08 -0700683 if (!ops->get_sset_count && !ops->self_test_count)
684 return -EOPNOTSUPP;
685
686 if (ops->get_sset_count)
687 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
688 else
689 /* code path for obsolete hook */
690 test_len = ops->self_test_count(dev);
691 if (test_len < 0)
692 return test_len;
693 WARN_ON(test_len == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 if (copy_from_user(&test, useraddr, sizeof(test)))
696 return -EFAULT;
697
Jeff Garzikff03d492007-08-15 16:01:08 -0700698 test.len = test_len;
699 data = kmalloc(test_len * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (!data)
701 return -ENOMEM;
702
703 ops->self_test(dev, &test, data);
704
705 ret = -EFAULT;
706 if (copy_to_user(useraddr, &test, sizeof(test)))
707 goto out;
708 useraddr += sizeof(test);
709 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
710 goto out;
711 ret = 0;
712
713 out:
714 kfree(data);
715 return ret;
716}
717
718static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
719{
720 struct ethtool_gstrings gstrings;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700721 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 u8 *data;
723 int ret;
724
725 if (!ops->get_strings)
726 return -EOPNOTSUPP;
727
728 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
729 return -EFAULT;
730
Jeff Garzikff03d492007-08-15 16:01:08 -0700731 if (ops->get_sset_count) {
732 ret = ops->get_sset_count(dev, gstrings.string_set);
733 if (ret < 0)
734 return ret;
735
736 gstrings.len = ret;
737 } else {
738 /* code path for obsolete hooks */
739
740 switch (gstrings.string_set) {
741 case ETH_SS_TEST:
742 if (!ops->self_test_count)
743 return -EOPNOTSUPP;
744 gstrings.len = ops->self_test_count(dev);
745 break;
746 case ETH_SS_STATS:
747 if (!ops->get_stats_count)
748 return -EOPNOTSUPP;
749 gstrings.len = ops->get_stats_count(dev);
750 break;
751 default:
752 return -EINVAL;
753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755
756 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
757 if (!data)
758 return -ENOMEM;
759
760 ops->get_strings(dev, gstrings.string_set, data);
761
762 ret = -EFAULT;
763 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
764 goto out;
765 useraddr += sizeof(gstrings);
766 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
767 goto out;
768 ret = 0;
769
770 out:
771 kfree(data);
772 return ret;
773}
774
775static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
776{
777 struct ethtool_value id;
778
779 if (!dev->ethtool_ops->phys_id)
780 return -EOPNOTSUPP;
781
782 if (copy_from_user(&id, useraddr, sizeof(id)))
783 return -EFAULT;
784
785 return dev->ethtool_ops->phys_id(dev, id.data);
786}
787
788static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
789{
790 struct ethtool_stats stats;
Stephen Hemminger76fd8592006-09-08 11:16:13 -0700791 const struct ethtool_ops *ops = dev->ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 u64 *data;
Jeff Garzikff03d492007-08-15 16:01:08 -0700793 int ret, n_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Jeff Garzikff03d492007-08-15 16:01:08 -0700795 if (!ops->get_ethtool_stats)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 return -EOPNOTSUPP;
Jeff Garzikff03d492007-08-15 16:01:08 -0700797 if (!ops->get_sset_count && !ops->get_stats_count)
798 return -EOPNOTSUPP;
799
800 if (ops->get_sset_count)
801 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
802 else
803 /* code path for obsolete hook */
804 n_stats = ops->get_stats_count(dev);
805 if (n_stats < 0)
806 return n_stats;
807 WARN_ON(n_stats == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 if (copy_from_user(&stats, useraddr, sizeof(stats)))
810 return -EFAULT;
811
Jeff Garzikff03d492007-08-15 16:01:08 -0700812 stats.n_stats = n_stats;
813 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (!data)
815 return -ENOMEM;
816
817 ops->get_ethtool_stats(dev, &stats, data);
818
819 ret = -EFAULT;
820 if (copy_to_user(useraddr, &stats, sizeof(stats)))
821 goto out;
822 useraddr += sizeof(stats);
823 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
824 goto out;
825 ret = 0;
826
827 out:
828 kfree(data);
829 return ret;
830}
831
viro@ftp.linux.org.uk0bf0519d2005-09-05 03:26:18 +0100832static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
Jon Wetzela6f9a702005-08-20 17:15:54 -0700833{
834 struct ethtool_perm_addr epaddr;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700835
Matthew Wilcox313674a2007-07-31 14:00:29 -0700836 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
Jon Wetzela6f9a702005-08-20 17:15:54 -0700837 return -EFAULT;
838
Matthew Wilcox313674a2007-07-31 14:00:29 -0700839 if (epaddr.size < dev->addr_len)
840 return -ETOOSMALL;
841 epaddr.size = dev->addr_len;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700842
Jon Wetzela6f9a702005-08-20 17:15:54 -0700843 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
Matthew Wilcox313674a2007-07-31 14:00:29 -0700844 return -EFAULT;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700845 useraddr += sizeof(epaddr);
Matthew Wilcox313674a2007-07-31 14:00:29 -0700846 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
847 return -EFAULT;
848 return 0;
Jon Wetzela6f9a702005-08-20 17:15:54 -0700849}
850
Jeff Garzik13c99b22007-08-15 16:01:56 -0700851static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
852 u32 cmd, u32 (*actor)(struct net_device *))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700853{
Jeff Garzik13c99b22007-08-15 16:01:56 -0700854 struct ethtool_value edata = { cmd };
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700855
Jeff Garzik13c99b22007-08-15 16:01:56 -0700856 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700857 return -EOPNOTSUPP;
858
Jeff Garzik13c99b22007-08-15 16:01:56 -0700859 edata.data = actor(dev);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700860
861 if (copy_to_user(useraddr, &edata, sizeof(edata)))
862 return -EFAULT;
863 return 0;
864}
865
Jeff Garzik13c99b22007-08-15 16:01:56 -0700866static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
867 void (*actor)(struct net_device *, u32))
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700868{
869 struct ethtool_value edata;
870
Jeff Garzik13c99b22007-08-15 16:01:56 -0700871 if (!actor)
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -0700872 return -EOPNOTSUPP;
873
874 if (copy_from_user(&edata, useraddr, sizeof(edata)))
875 return -EFAULT;
876
Jeff Garzik13c99b22007-08-15 16:01:56 -0700877 actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700878 return 0;
879}
880
Jeff Garzik13c99b22007-08-15 16:01:56 -0700881static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
882 int (*actor)(struct net_device *, u32))
Jeff Garzik339bf022007-08-15 16:01:32 -0700883{
884 struct ethtool_value edata;
885
Jeff Garzik13c99b22007-08-15 16:01:56 -0700886 if (!actor)
Jeff Garzik339bf022007-08-15 16:01:32 -0700887 return -EOPNOTSUPP;
888
889 if (copy_from_user(&edata, useraddr, sizeof(edata)))
890 return -EFAULT;
891
Jeff Garzik13c99b22007-08-15 16:01:56 -0700892 return actor(dev, edata.data);
Jeff Garzik339bf022007-08-15 16:01:32 -0700893}
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895/* The main entry point in this file. Called from net/core/dev.c */
896
Eric W. Biederman881d9662007-09-17 11:56:21 -0700897int dev_ethtool(struct net *net, struct ifreq *ifr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Eric W. Biederman881d9662007-09-17 11:56:21 -0700899 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 void __user *useraddr = ifr->ifr_data;
901 u32 ethcmd;
902 int rc;
Stephen Hemminger81e81572005-05-29 14:14:35 -0700903 unsigned long old_features;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (!dev || !netif_device_present(dev))
906 return -ENODEV;
907
908 if (!dev->ethtool_ops)
Matthew Wilcox61a44b92007-07-31 14:00:02 -0700909 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
912 return -EFAULT;
913
Stephen Hemminger75f31232006-09-28 15:13:37 -0700914 /* Allow some commands to be done by anyone */
915 switch(ethcmd) {
Stephen Hemminger75f31232006-09-28 15:13:37 -0700916 case ETHTOOL_GDRVINFO:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700917 case ETHTOOL_GMSGLVL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700918 case ETHTOOL_GCOALESCE:
919 case ETHTOOL_GRINGPARAM:
920 case ETHTOOL_GPAUSEPARAM:
921 case ETHTOOL_GRXCSUM:
922 case ETHTOOL_GTXCSUM:
923 case ETHTOOL_GSG:
924 case ETHTOOL_GSTRINGS:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700925 case ETHTOOL_GTSO:
926 case ETHTOOL_GPERMADDR:
927 case ETHTOOL_GUFO:
928 case ETHTOOL_GGSO:
Jeff Garzik339bf022007-08-15 16:01:32 -0700929 case ETHTOOL_GFLAGS:
930 case ETHTOOL_GPFLAGS:
Santwona Behera0853ad62008-07-02 03:47:41 -0700931 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -0800932 case ETHTOOL_GRXRINGS:
933 case ETHTOOL_GRXCLSRLCNT:
934 case ETHTOOL_GRXCLSRULE:
935 case ETHTOOL_GRXCLSRLALL:
Stephen Hemminger75f31232006-09-28 15:13:37 -0700936 break;
937 default:
938 if (!capable(CAP_NET_ADMIN))
939 return -EPERM;
940 }
941
Stephen Hemmingere71a4782007-04-10 20:10:33 -0700942 if (dev->ethtool_ops->begin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
944 return rc;
945
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -0700946 old_features = dev->features;
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 switch (ethcmd) {
949 case ETHTOOL_GSET:
950 rc = ethtool_get_settings(dev, useraddr);
951 break;
952 case ETHTOOL_SSET:
953 rc = ethtool_set_settings(dev, useraddr);
954 break;
955 case ETHTOOL_GDRVINFO:
956 rc = ethtool_get_drvinfo(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 break;
958 case ETHTOOL_GREGS:
959 rc = ethtool_get_regs(dev, useraddr);
960 break;
961 case ETHTOOL_GWOL:
962 rc = ethtool_get_wol(dev, useraddr);
963 break;
964 case ETHTOOL_SWOL:
965 rc = ethtool_set_wol(dev, useraddr);
966 break;
967 case ETHTOOL_GMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700968 rc = ethtool_get_value(dev, useraddr, ethcmd,
969 dev->ethtool_ops->get_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 break;
971 case ETHTOOL_SMSGLVL:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700972 rc = ethtool_set_value_void(dev, useraddr,
973 dev->ethtool_ops->set_msglevel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 break;
975 case ETHTOOL_NWAY_RST:
976 rc = ethtool_nway_reset(dev);
977 break;
978 case ETHTOOL_GLINK:
Jeff Garzik13c99b22007-08-15 16:01:56 -0700979 rc = ethtool_get_value(dev, useraddr, ethcmd,
980 dev->ethtool_ops->get_link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 break;
982 case ETHTOOL_GEEPROM:
983 rc = ethtool_get_eeprom(dev, useraddr);
984 break;
985 case ETHTOOL_SEEPROM:
986 rc = ethtool_set_eeprom(dev, useraddr);
987 break;
988 case ETHTOOL_GCOALESCE:
989 rc = ethtool_get_coalesce(dev, useraddr);
990 break;
991 case ETHTOOL_SCOALESCE:
992 rc = ethtool_set_coalesce(dev, useraddr);
993 break;
994 case ETHTOOL_GRINGPARAM:
995 rc = ethtool_get_ringparam(dev, useraddr);
996 break;
997 case ETHTOOL_SRINGPARAM:
998 rc = ethtool_set_ringparam(dev, useraddr);
999 break;
1000 case ETHTOOL_GPAUSEPARAM:
1001 rc = ethtool_get_pauseparam(dev, useraddr);
1002 break;
1003 case ETHTOOL_SPAUSEPARAM:
1004 rc = ethtool_set_pauseparam(dev, useraddr);
1005 break;
1006 case ETHTOOL_GRXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001007 rc = ethtool_get_value(dev, useraddr, ethcmd,
1008 dev->ethtool_ops->get_rx_csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 break;
1010 case ETHTOOL_SRXCSUM:
Herbert Xub240a0e2008-12-15 23:44:31 -08001011 rc = ethtool_set_rx_csum(dev, useraddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 break;
1013 case ETHTOOL_GTXCSUM:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001014 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001015 (dev->ethtool_ops->get_tx_csum ?
1016 dev->ethtool_ops->get_tx_csum :
1017 ethtool_op_get_tx_csum));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 break;
1019 case ETHTOOL_STXCSUM:
1020 rc = ethtool_set_tx_csum(dev, useraddr);
1021 break;
1022 case ETHTOOL_GSG:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001023 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001024 (dev->ethtool_ops->get_sg ?
1025 dev->ethtool_ops->get_sg :
1026 ethtool_op_get_sg));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 break;
1028 case ETHTOOL_SSG:
1029 rc = ethtool_set_sg(dev, useraddr);
1030 break;
1031 case ETHTOOL_GTSO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001032 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001033 (dev->ethtool_ops->get_tso ?
1034 dev->ethtool_ops->get_tso :
1035 ethtool_op_get_tso));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 break;
1037 case ETHTOOL_STSO:
1038 rc = ethtool_set_tso(dev, useraddr);
1039 break;
1040 case ETHTOOL_TEST:
1041 rc = ethtool_self_test(dev, useraddr);
1042 break;
1043 case ETHTOOL_GSTRINGS:
1044 rc = ethtool_get_strings(dev, useraddr);
1045 break;
1046 case ETHTOOL_PHYS_ID:
1047 rc = ethtool_phys_id(dev, useraddr);
1048 break;
1049 case ETHTOOL_GSTATS:
1050 rc = ethtool_get_stats(dev, useraddr);
1051 break;
Jon Wetzela6f9a702005-08-20 17:15:54 -07001052 case ETHTOOL_GPERMADDR:
1053 rc = ethtool_get_perm_addr(dev, useraddr);
1054 break;
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001055 case ETHTOOL_GUFO:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001056 rc = ethtool_get_value(dev, useraddr, ethcmd,
Jeff Garzik88d3aaf2007-09-15 14:41:06 -07001057 (dev->ethtool_ops->get_ufo ?
1058 dev->ethtool_ops->get_ufo :
1059 ethtool_op_get_ufo));
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001060 break;
1061 case ETHTOOL_SUFO:
1062 rc = ethtool_set_ufo(dev, useraddr);
1063 break;
Herbert Xu37c31852006-06-22 03:07:29 -07001064 case ETHTOOL_GGSO:
1065 rc = ethtool_get_gso(dev, useraddr);
1066 break;
1067 case ETHTOOL_SGSO:
1068 rc = ethtool_set_gso(dev, useraddr);
1069 break;
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001070 case ETHTOOL_GFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001071 rc = ethtool_get_value(dev, useraddr, ethcmd,
1072 dev->ethtool_ops->get_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001073 break;
1074 case ETHTOOL_SFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001075 rc = ethtool_set_value(dev, useraddr,
1076 dev->ethtool_ops->set_flags);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001077 break;
Jeff Garzik339bf022007-08-15 16:01:32 -07001078 case ETHTOOL_GPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001079 rc = ethtool_get_value(dev, useraddr, ethcmd,
1080 dev->ethtool_ops->get_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001081 break;
1082 case ETHTOOL_SPFLAGS:
Jeff Garzik13c99b22007-08-15 16:01:56 -07001083 rc = ethtool_set_value(dev, useraddr,
1084 dev->ethtool_ops->set_priv_flags);
Jeff Garzik339bf022007-08-15 16:01:32 -07001085 break;
Santwona Behera0853ad62008-07-02 03:47:41 -07001086 case ETHTOOL_GRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001087 case ETHTOOL_GRXRINGS:
1088 case ETHTOOL_GRXCLSRLCNT:
1089 case ETHTOOL_GRXCLSRULE:
1090 case ETHTOOL_GRXCLSRLALL:
1091 rc = ethtool_get_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001092 break;
1093 case ETHTOOL_SRXFH:
Santwona Behera59089d82009-02-20 00:58:13 -08001094 case ETHTOOL_SRXCLSRLDEL:
1095 case ETHTOOL_SRXCLSRLINS:
1096 rc = ethtool_set_rxnfc(dev, useraddr);
Santwona Behera0853ad62008-07-02 03:47:41 -07001097 break;
Herbert Xub240a0e2008-12-15 23:44:31 -08001098 case ETHTOOL_GGRO:
1099 rc = ethtool_get_gro(dev, useraddr);
1100 break;
1101 case ETHTOOL_SGRO:
1102 rc = ethtool_set_gro(dev, useraddr);
1103 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 default:
Matthew Wilcox61a44b92007-07-31 14:00:02 -07001105 rc = -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 }
YOSHIFUJI Hideaki4ec93ed2007-02-09 23:24:36 +09001107
Stephen Hemmingere71a4782007-04-10 20:10:33 -07001108 if (dev->ethtool_ops->complete)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 dev->ethtool_ops->complete(dev);
Stephen Hemmingerd8a33ac2005-05-29 14:13:47 -07001110
1111 if (old_features != dev->features)
1112 netdev_features_change(dev);
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117EXPORT_SYMBOL(ethtool_op_get_link);
1118EXPORT_SYMBOL(ethtool_op_get_sg);
1119EXPORT_SYMBOL(ethtool_op_get_tso);
1120EXPORT_SYMBOL(ethtool_op_get_tx_csum);
1121EXPORT_SYMBOL(ethtool_op_set_sg);
1122EXPORT_SYMBOL(ethtool_op_set_tso);
1123EXPORT_SYMBOL(ethtool_op_set_tx_csum);
Jon Mason69f6a0f2005-05-29 20:27:24 -07001124EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
Michael Chan6460d942007-07-14 19:07:52 -07001125EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
Ananda Rajue89e9cf2005-10-18 15:46:41 -07001126EXPORT_SYMBOL(ethtool_op_set_ufo);
1127EXPORT_SYMBOL(ethtool_op_get_ufo);
Jeff Garzik3ae7c0b2007-08-15 16:00:51 -07001128EXPORT_SYMBOL(ethtool_op_set_flags);
1129EXPORT_SYMBOL(ethtool_op_get_flags);