]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/core/ethtool.c
ixgbe: Bump driver version up
[net-next-2.6.git] / net / core / ethtool.c
CommitLineData
1da177e4
LT
1/*
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
61a44b9c 6 * the information ethtool needs.
1da177e4 7 *
61a44b9c
MW
8 * 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.
1da177e4
LT
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
4fc268d2 16#include <linux/capability.h>
1da177e4
LT
17#include <linux/errno.h>
18#include <linux/ethtool.h>
19#include <linux/netdevice.h>
20#include <asm/uaccess.h>
21
4ec93edb 22/*
1da177e4
LT
23 * 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
1896e61f
SS
33u32 ethtool_op_get_rx_csum(struct net_device *dev)
34{
35 return (dev->features & NETIF_F_ALL_CSUM) != 0;
36}
8a729fce 37EXPORT_SYMBOL(ethtool_op_get_rx_csum);
1896e61f 38
1da177e4
LT
39u32 ethtool_op_get_tx_csum(struct net_device *dev)
40{
8648b305 41 return (dev->features & NETIF_F_ALL_CSUM) != 0;
1da177e4 42}
8a729fce 43EXPORT_SYMBOL(ethtool_op_get_tx_csum);
1da177e4
LT
44
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
69f6a0fa
JM
55int 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}
6460d948
MC
64
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
1da177e4
LT
75u32 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
e89e9cf5
AR
105u32 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
3ae7c0b2
JG
119/* 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 =
15682bc4 123 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
3ae7c0b2
JG
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
15682bc4
PWJ
142 if (data & ETH_FLAG_NTUPLE)
143 dev->features |= NETIF_F_NTUPLE;
144 else
145 dev->features &= ~NETIF_F_NTUPLE;
146
3ae7c0b2
JG
147 return 0;
148}
149
15682bc4
PWJ
150void ethtool_ntuple_flush(struct net_device *dev)
151{
152 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
153
154 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
155 list_del(&fsc->list);
156 kfree(fsc);
157 }
158 dev->ethtool_ntuple_list.count = 0;
159}
160EXPORT_SYMBOL(ethtool_ntuple_flush);
161
1da177e4
LT
162/* Handlers for each ethtool command */
163
164static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
165{
166 struct ethtool_cmd cmd = { ETHTOOL_GSET };
167 int err;
168
169 if (!dev->ethtool_ops->get_settings)
170 return -EOPNOTSUPP;
171
172 err = dev->ethtool_ops->get_settings(dev, &cmd);
173 if (err < 0)
174 return err;
175
176 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
177 return -EFAULT;
178 return 0;
179}
180
181static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
182{
183 struct ethtool_cmd cmd;
184
185 if (!dev->ethtool_ops->set_settings)
186 return -EOPNOTSUPP;
187
188 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
189 return -EFAULT;
190
191 return dev->ethtool_ops->set_settings(dev, &cmd);
192}
193
194static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
195{
196 struct ethtool_drvinfo info;
76fd8593 197 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
198
199 if (!ops->get_drvinfo)
200 return -EOPNOTSUPP;
201
202 memset(&info, 0, sizeof(info));
203 info.cmd = ETHTOOL_GDRVINFO;
204 ops->get_drvinfo(dev, &info);
205
ff03d49f
JG
206 if (ops->get_sset_count) {
207 int rc;
208
209 rc = ops->get_sset_count(dev, ETH_SS_TEST);
210 if (rc >= 0)
211 info.testinfo_len = rc;
212 rc = ops->get_sset_count(dev, ETH_SS_STATS);
213 if (rc >= 0)
214 info.n_stats = rc;
339bf024
JG
215 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
216 if (rc >= 0)
217 info.n_priv_flags = rc;
ff03d49f 218 }
1da177e4
LT
219 if (ops->get_regs_len)
220 info.regdump_len = ops->get_regs_len(dev);
221 if (ops->get_eeprom_len)
222 info.eedump_len = ops->get_eeprom_len(dev);
223
224 if (copy_to_user(useraddr, &info, sizeof(info)))
225 return -EFAULT;
226 return 0;
227}
228
59089d8d 229static int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
0853ad66
SB
230{
231 struct ethtool_rxnfc cmd;
232
59089d8d 233 if (!dev->ethtool_ops->set_rxnfc)
0853ad66
SB
234 return -EOPNOTSUPP;
235
236 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
237 return -EFAULT;
238
59089d8d 239 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
0853ad66
SB
240}
241
59089d8d 242static int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
0853ad66
SB
243{
244 struct ethtool_rxnfc info;
59089d8d
SB
245 const struct ethtool_ops *ops = dev->ethtool_ops;
246 int ret;
247 void *rule_buf = NULL;
0853ad66 248
59089d8d 249 if (!ops->get_rxnfc)
0853ad66
SB
250 return -EOPNOTSUPP;
251
252 if (copy_from_user(&info, useraddr, sizeof(info)))
253 return -EFAULT;
254
59089d8d
SB
255 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
256 if (info.rule_cnt > 0) {
257 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
258 GFP_USER);
259 if (!rule_buf)
260 return -ENOMEM;
261 }
262 }
0853ad66 263
59089d8d
SB
264 ret = ops->get_rxnfc(dev, &info, rule_buf);
265 if (ret < 0)
266 goto err_out;
267
268 ret = -EFAULT;
0853ad66 269 if (copy_to_user(useraddr, &info, sizeof(info)))
59089d8d
SB
270 goto err_out;
271
272 if (rule_buf) {
273 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
274 if (copy_to_user(useraddr, rule_buf,
275 info.rule_cnt * sizeof(u32)))
276 goto err_out;
277 }
278 ret = 0;
279
280err_out:
c9caceca 281 kfree(rule_buf);
59089d8d
SB
282
283 return ret;
0853ad66
SB
284}
285
15682bc4
PWJ
286static int __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
287 struct ethtool_rx_ntuple_flow_spec *spec)
288{
289 struct ethtool_rx_ntuple_flow_spec_container *fsc;
290
291 /* don't add filters forever */
292 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY)
293 return 0;
294
295 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
296 if (!fsc)
297 return -ENOMEM;
298
299 /* Copy the whole filter over */
300 fsc->fs.flow_type = spec->flow_type;
301 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
302 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
303
304 fsc->fs.vlan_tag = spec->vlan_tag;
305 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
306 fsc->fs.data = spec->data;
307 fsc->fs.data_mask = spec->data_mask;
308 fsc->fs.action = spec->action;
309
310 /* add to the list */
311 list_add_tail_rcu(&fsc->list, &list->list);
312 list->count++;
313
314 return 0;
315}
316
317static int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
318{
319 struct ethtool_rx_ntuple cmd;
320 const struct ethtool_ops *ops = dev->ethtool_ops;
321 int ret;
322
323 if (!ops->set_rx_ntuple)
324 return -EOPNOTSUPP;
325
326 if (!(dev->features & NETIF_F_NTUPLE))
327 return -EINVAL;
328
329 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
330 return -EFAULT;
331
332 ret = ops->set_rx_ntuple(dev, &cmd);
333
334 /*
335 * Cache filter in dev struct for GET operation only if
336 * the underlying driver doesn't have its own GET operation, and
337 * only if the filter was added successfully.
338 */
339 if (!ops->get_rx_ntuple && !ret)
340 if (__rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs))
341 return -ENOMEM;
342
343 return ret;
344}
345
346static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
347{
348 struct ethtool_gstrings gstrings;
349 const struct ethtool_ops *ops = dev->ethtool_ops;
350 struct ethtool_rx_ntuple_flow_spec_container *fsc;
351 u8 *data;
352 char *p;
353 int ret, i, num_strings = 0;
354
355 if (!ops->get_sset_count)
356 return -EOPNOTSUPP;
357
358 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
359 return -EFAULT;
360
361 ret = ops->get_sset_count(dev, gstrings.string_set);
362 if (ret < 0)
363 return ret;
364
365 gstrings.len = ret;
366
367 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
368 if (!data)
369 return -ENOMEM;
370
371 if (ops->get_rx_ntuple) {
372 /* driver-specific filter grab */
373 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
374 goto copy;
375 }
376
377 /* default ethtool filter grab */
378 i = 0;
379 p = (char *)data;
380 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
381 sprintf(p, "Filter %d:\n", i);
382 p += ETH_GSTRING_LEN;
383 num_strings++;
384
385 switch (fsc->fs.flow_type) {
386 case TCP_V4_FLOW:
387 sprintf(p, "\tFlow Type: TCP\n");
388 p += ETH_GSTRING_LEN;
389 num_strings++;
390 break;
391 case UDP_V4_FLOW:
392 sprintf(p, "\tFlow Type: UDP\n");
393 p += ETH_GSTRING_LEN;
394 num_strings++;
395 break;
396 case SCTP_V4_FLOW:
397 sprintf(p, "\tFlow Type: SCTP\n");
398 p += ETH_GSTRING_LEN;
399 num_strings++;
400 break;
401 case AH_ESP_V4_FLOW:
402 sprintf(p, "\tFlow Type: AH ESP\n");
403 p += ETH_GSTRING_LEN;
404 num_strings++;
405 break;
406 case ESP_V4_FLOW:
407 sprintf(p, "\tFlow Type: ESP\n");
408 p += ETH_GSTRING_LEN;
409 num_strings++;
410 break;
411 case IP_USER_FLOW:
412 sprintf(p, "\tFlow Type: Raw IP\n");
413 p += ETH_GSTRING_LEN;
414 num_strings++;
415 break;
416 case IPV4_FLOW:
417 sprintf(p, "\tFlow Type: IPv4\n");
418 p += ETH_GSTRING_LEN;
419 num_strings++;
420 break;
421 default:
422 sprintf(p, "\tFlow Type: Unknown\n");
423 p += ETH_GSTRING_LEN;
424 num_strings++;
425 goto unknown_filter;
426 };
427
428 /* now the rest of the filters */
429 switch (fsc->fs.flow_type) {
430 case TCP_V4_FLOW:
431 case UDP_V4_FLOW:
432 case SCTP_V4_FLOW:
433 sprintf(p, "\tSrc IP addr: 0x%x\n",
434 fsc->fs.h_u.tcp_ip4_spec.ip4src);
435 p += ETH_GSTRING_LEN;
436 num_strings++;
437 sprintf(p, "\tSrc IP mask: 0x%x\n",
438 fsc->fs.m_u.tcp_ip4_spec.ip4src);
439 p += ETH_GSTRING_LEN;
440 num_strings++;
441 sprintf(p, "\tDest IP addr: 0x%x\n",
442 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
443 p += ETH_GSTRING_LEN;
444 num_strings++;
445 sprintf(p, "\tDest IP mask: 0x%x\n",
446 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
447 p += ETH_GSTRING_LEN;
448 num_strings++;
449 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
450 fsc->fs.h_u.tcp_ip4_spec.psrc,
451 fsc->fs.m_u.tcp_ip4_spec.psrc);
452 p += ETH_GSTRING_LEN;
453 num_strings++;
454 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
455 fsc->fs.h_u.tcp_ip4_spec.pdst,
456 fsc->fs.m_u.tcp_ip4_spec.pdst);
457 p += ETH_GSTRING_LEN;
458 num_strings++;
459 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
460 fsc->fs.h_u.tcp_ip4_spec.tos,
461 fsc->fs.m_u.tcp_ip4_spec.tos);
462 p += ETH_GSTRING_LEN;
463 num_strings++;
464 break;
465 case AH_ESP_V4_FLOW:
466 case ESP_V4_FLOW:
467 sprintf(p, "\tSrc IP addr: 0x%x\n",
468 fsc->fs.h_u.ah_ip4_spec.ip4src);
469 p += ETH_GSTRING_LEN;
470 num_strings++;
471 sprintf(p, "\tSrc IP mask: 0x%x\n",
472 fsc->fs.m_u.ah_ip4_spec.ip4src);
473 p += ETH_GSTRING_LEN;
474 num_strings++;
475 sprintf(p, "\tDest IP addr: 0x%x\n",
476 fsc->fs.h_u.ah_ip4_spec.ip4dst);
477 p += ETH_GSTRING_LEN;
478 num_strings++;
479 sprintf(p, "\tDest IP mask: 0x%x\n",
480 fsc->fs.m_u.ah_ip4_spec.ip4dst);
481 p += ETH_GSTRING_LEN;
482 num_strings++;
483 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
484 fsc->fs.h_u.ah_ip4_spec.spi,
485 fsc->fs.m_u.ah_ip4_spec.spi);
486 p += ETH_GSTRING_LEN;
487 num_strings++;
488 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
489 fsc->fs.h_u.ah_ip4_spec.tos,
490 fsc->fs.m_u.ah_ip4_spec.tos);
491 p += ETH_GSTRING_LEN;
492 num_strings++;
493 break;
494 case IP_USER_FLOW:
495 sprintf(p, "\tSrc IP addr: 0x%x\n",
496 fsc->fs.h_u.raw_ip4_spec.ip4src);
497 p += ETH_GSTRING_LEN;
498 num_strings++;
499 sprintf(p, "\tSrc IP mask: 0x%x\n",
500 fsc->fs.m_u.raw_ip4_spec.ip4src);
501 p += ETH_GSTRING_LEN;
502 num_strings++;
503 sprintf(p, "\tDest IP addr: 0x%x\n",
504 fsc->fs.h_u.raw_ip4_spec.ip4dst);
505 p += ETH_GSTRING_LEN;
506 num_strings++;
507 sprintf(p, "\tDest IP mask: 0x%x\n",
508 fsc->fs.m_u.raw_ip4_spec.ip4dst);
509 p += ETH_GSTRING_LEN;
510 num_strings++;
511 break;
512 case IPV4_FLOW:
513 sprintf(p, "\tSrc IP addr: 0x%x\n",
514 fsc->fs.h_u.usr_ip4_spec.ip4src);
515 p += ETH_GSTRING_LEN;
516 num_strings++;
517 sprintf(p, "\tSrc IP mask: 0x%x\n",
518 fsc->fs.m_u.usr_ip4_spec.ip4src);
519 p += ETH_GSTRING_LEN;
520 num_strings++;
521 sprintf(p, "\tDest IP addr: 0x%x\n",
522 fsc->fs.h_u.usr_ip4_spec.ip4dst);
523 p += ETH_GSTRING_LEN;
524 num_strings++;
525 sprintf(p, "\tDest IP mask: 0x%x\n",
526 fsc->fs.m_u.usr_ip4_spec.ip4dst);
527 p += ETH_GSTRING_LEN;
528 num_strings++;
529 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
530 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
531 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
532 p += ETH_GSTRING_LEN;
533 num_strings++;
534 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
535 fsc->fs.h_u.usr_ip4_spec.tos,
536 fsc->fs.m_u.usr_ip4_spec.tos);
537 p += ETH_GSTRING_LEN;
538 num_strings++;
539 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
540 fsc->fs.h_u.usr_ip4_spec.ip_ver,
541 fsc->fs.m_u.usr_ip4_spec.ip_ver);
542 p += ETH_GSTRING_LEN;
543 num_strings++;
544 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
545 fsc->fs.h_u.usr_ip4_spec.proto,
546 fsc->fs.m_u.usr_ip4_spec.proto);
547 p += ETH_GSTRING_LEN;
548 num_strings++;
549 break;
550 };
551 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
552 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
553 p += ETH_GSTRING_LEN;
554 num_strings++;
555 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
556 p += ETH_GSTRING_LEN;
557 num_strings++;
558 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
559 p += ETH_GSTRING_LEN;
560 num_strings++;
561 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
562 sprintf(p, "\tAction: Drop\n");
563 else
564 sprintf(p, "\tAction: Direct to queue %d\n",
565 fsc->fs.action);
566 p += ETH_GSTRING_LEN;
567 num_strings++;
568unknown_filter:
569 i++;
570 }
571copy:
572 /* indicate to userspace how many strings we actually have */
573 gstrings.len = num_strings;
574 ret = -EFAULT;
575 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
576 goto out;
577 useraddr += sizeof(gstrings);
578 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
579 goto out;
580 ret = 0;
581
582out:
583 kfree(data);
584 return ret;
585}
586
1da177e4
LT
587static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
588{
589 struct ethtool_regs regs;
76fd8593 590 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
591 void *regbuf;
592 int reglen, ret;
593
594 if (!ops->get_regs || !ops->get_regs_len)
595 return -EOPNOTSUPP;
596
597 if (copy_from_user(&regs, useraddr, sizeof(regs)))
598 return -EFAULT;
599
600 reglen = ops->get_regs_len(dev);
601 if (regs.len > reglen)
602 regs.len = reglen;
603
604 regbuf = kmalloc(reglen, GFP_USER);
605 if (!regbuf)
606 return -ENOMEM;
607
608 ops->get_regs(dev, &regs, regbuf);
609
610 ret = -EFAULT;
611 if (copy_to_user(useraddr, &regs, sizeof(regs)))
612 goto out;
613 useraddr += offsetof(struct ethtool_regs, data);
614 if (copy_to_user(useraddr, regbuf, regs.len))
615 goto out;
616 ret = 0;
617
618 out:
619 kfree(regbuf);
620 return ret;
621}
622
d73d3a8c
BH
623static int ethtool_reset(struct net_device *dev, char __user *useraddr)
624{
625 struct ethtool_value reset;
626 int ret;
627
628 if (!dev->ethtool_ops->reset)
629 return -EOPNOTSUPP;
630
631 if (copy_from_user(&reset, useraddr, sizeof(reset)))
632 return -EFAULT;
633
15682bc4
PWJ
634 /* Clear ethtool n-tuple list */
635 ethtool_ntuple_flush(dev);
636
d73d3a8c
BH
637 ret = dev->ethtool_ops->reset(dev, &reset.data);
638 if (ret)
639 return ret;
640
641 if (copy_to_user(useraddr, &reset, sizeof(reset)))
642 return -EFAULT;
643 return 0;
644}
645
1da177e4
LT
646static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
647{
648 struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
649
650 if (!dev->ethtool_ops->get_wol)
651 return -EOPNOTSUPP;
652
653 dev->ethtool_ops->get_wol(dev, &wol);
654
655 if (copy_to_user(useraddr, &wol, sizeof(wol)))
656 return -EFAULT;
657 return 0;
658}
659
660static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
661{
662 struct ethtool_wolinfo wol;
663
664 if (!dev->ethtool_ops->set_wol)
665 return -EOPNOTSUPP;
666
667 if (copy_from_user(&wol, useraddr, sizeof(wol)))
668 return -EFAULT;
669
670 return dev->ethtool_ops->set_wol(dev, &wol);
671}
672
1da177e4
LT
673static int ethtool_nway_reset(struct net_device *dev)
674{
675 if (!dev->ethtool_ops->nway_reset)
676 return -EOPNOTSUPP;
677
678 return dev->ethtool_ops->nway_reset(dev);
679}
680
1da177e4
LT
681static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
682{
683 struct ethtool_eeprom eeprom;
76fd8593 684 const struct ethtool_ops *ops = dev->ethtool_ops;
b131dd5d
MSB
685 void __user *userbuf = useraddr + sizeof(eeprom);
686 u32 bytes_remaining;
1da177e4 687 u8 *data;
b131dd5d 688 int ret = 0;
1da177e4
LT
689
690 if (!ops->get_eeprom || !ops->get_eeprom_len)
691 return -EOPNOTSUPP;
692
693 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
694 return -EFAULT;
695
696 /* Check for wrap and zero */
697 if (eeprom.offset + eeprom.len <= eeprom.offset)
698 return -EINVAL;
699
700 /* Check for exceeding total eeprom len */
701 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
702 return -EINVAL;
703
b131dd5d 704 data = kmalloc(PAGE_SIZE, GFP_USER);
1da177e4
LT
705 if (!data)
706 return -ENOMEM;
707
b131dd5d
MSB
708 bytes_remaining = eeprom.len;
709 while (bytes_remaining > 0) {
710 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
711
712 ret = ops->get_eeprom(dev, &eeprom, data);
713 if (ret)
714 break;
715 if (copy_to_user(userbuf, data, eeprom.len)) {
716 ret = -EFAULT;
717 break;
718 }
719 userbuf += eeprom.len;
720 eeprom.offset += eeprom.len;
721 bytes_remaining -= eeprom.len;
722 }
1da177e4 723
c5835df9
MSB
724 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
725 eeprom.offset -= eeprom.len;
726 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
727 ret = -EFAULT;
728
1da177e4
LT
729 kfree(data);
730 return ret;
731}
732
733static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
734{
735 struct ethtool_eeprom eeprom;
76fd8593 736 const struct ethtool_ops *ops = dev->ethtool_ops;
b131dd5d
MSB
737 void __user *userbuf = useraddr + sizeof(eeprom);
738 u32 bytes_remaining;
1da177e4 739 u8 *data;
b131dd5d 740 int ret = 0;
1da177e4
LT
741
742 if (!ops->set_eeprom || !ops->get_eeprom_len)
743 return -EOPNOTSUPP;
744
745 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
746 return -EFAULT;
747
748 /* Check for wrap and zero */
749 if (eeprom.offset + eeprom.len <= eeprom.offset)
750 return -EINVAL;
751
752 /* Check for exceeding total eeprom len */
753 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
754 return -EINVAL;
755
b131dd5d 756 data = kmalloc(PAGE_SIZE, GFP_USER);
1da177e4
LT
757 if (!data)
758 return -ENOMEM;
759
b131dd5d
MSB
760 bytes_remaining = eeprom.len;
761 while (bytes_remaining > 0) {
762 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
763
764 if (copy_from_user(data, userbuf, eeprom.len)) {
765 ret = -EFAULT;
766 break;
767 }
768 ret = ops->set_eeprom(dev, &eeprom, data);
769 if (ret)
770 break;
771 userbuf += eeprom.len;
772 eeprom.offset += eeprom.len;
773 bytes_remaining -= eeprom.len;
774 }
1da177e4 775
1da177e4
LT
776 kfree(data);
777 return ret;
778}
779
780static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
781{
782 struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
783
784 if (!dev->ethtool_ops->get_coalesce)
785 return -EOPNOTSUPP;
786
787 dev->ethtool_ops->get_coalesce(dev, &coalesce);
788
789 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
790 return -EFAULT;
791 return 0;
792}
793
794static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
795{
796 struct ethtool_coalesce coalesce;
797
fa04ae5c 798 if (!dev->ethtool_ops->set_coalesce)
1da177e4
LT
799 return -EOPNOTSUPP;
800
801 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
802 return -EFAULT;
803
804 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
805}
806
807static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
808{
809 struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
810
811 if (!dev->ethtool_ops->get_ringparam)
812 return -EOPNOTSUPP;
813
814 dev->ethtool_ops->get_ringparam(dev, &ringparam);
815
816 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
817 return -EFAULT;
818 return 0;
819}
820
821static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
822{
823 struct ethtool_ringparam ringparam;
824
825 if (!dev->ethtool_ops->set_ringparam)
826 return -EOPNOTSUPP;
827
828 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
829 return -EFAULT;
830
831 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
832}
833
834static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
835{
836 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
837
838 if (!dev->ethtool_ops->get_pauseparam)
839 return -EOPNOTSUPP;
840
841 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
842
843 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
844 return -EFAULT;
845 return 0;
846}
847
848static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
849{
850 struct ethtool_pauseparam pauseparam;
851
e1b90c41 852 if (!dev->ethtool_ops->set_pauseparam)
1da177e4
LT
853 return -EOPNOTSUPP;
854
855 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
856 return -EFAULT;
857
858 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
859}
860
1da177e4
LT
861static int __ethtool_set_sg(struct net_device *dev, u32 data)
862{
863 int err;
864
865 if (!data && dev->ethtool_ops->set_tso) {
866 err = dev->ethtool_ops->set_tso(dev, 0);
867 if (err)
868 return err;
869 }
870
e89e9cf5
AR
871 if (!data && dev->ethtool_ops->set_ufo) {
872 err = dev->ethtool_ops->set_ufo(dev, 0);
873 if (err)
874 return err;
875 }
1da177e4
LT
876 return dev->ethtool_ops->set_sg(dev, data);
877}
878
879static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
880{
881 struct ethtool_value edata;
882 int err;
883
884 if (!dev->ethtool_ops->set_tx_csum)
885 return -EOPNOTSUPP;
886
887 if (copy_from_user(&edata, useraddr, sizeof(edata)))
888 return -EFAULT;
889
890 if (!edata.data && dev->ethtool_ops->set_sg) {
891 err = __ethtool_set_sg(dev, 0);
892 if (err)
893 return err;
894 }
895
896 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
897}
898
b240a0e5
HX
899static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
900{
901 struct ethtool_value edata;
902
903 if (!dev->ethtool_ops->set_rx_csum)
904 return -EOPNOTSUPP;
905
906 if (copy_from_user(&edata, useraddr, sizeof(edata)))
907 return -EFAULT;
908
909 if (!edata.data && dev->ethtool_ops->set_sg)
910 dev->features &= ~NETIF_F_GRO;
911
912 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
913}
914
1da177e4
LT
915static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
916{
917 struct ethtool_value edata;
918
919 if (!dev->ethtool_ops->set_sg)
920 return -EOPNOTSUPP;
921
922 if (copy_from_user(&edata, useraddr, sizeof(edata)))
923 return -EFAULT;
924
4ec93edb 925 if (edata.data &&
8648b305 926 !(dev->features & NETIF_F_ALL_CSUM))
1da177e4
LT
927 return -EINVAL;
928
929 return __ethtool_set_sg(dev, edata.data);
930}
931
1da177e4
LT
932static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
933{
934 struct ethtool_value edata;
935
936 if (!dev->ethtool_ops->set_tso)
937 return -EOPNOTSUPP;
938
939 if (copy_from_user(&edata, useraddr, sizeof(edata)))
940 return -EFAULT;
941
942 if (edata.data && !(dev->features & NETIF_F_SG))
943 return -EINVAL;
944
945 return dev->ethtool_ops->set_tso(dev, edata.data);
946}
947
e89e9cf5
AR
948static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
949{
950 struct ethtool_value edata;
951
952 if (!dev->ethtool_ops->set_ufo)
953 return -EOPNOTSUPP;
954 if (copy_from_user(&edata, useraddr, sizeof(edata)))
955 return -EFAULT;
956 if (edata.data && !(dev->features & NETIF_F_SG))
957 return -EINVAL;
958 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
959 return -EINVAL;
960 return dev->ethtool_ops->set_ufo(dev, edata.data);
961}
962
37c3185a
HX
963static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
964{
965 struct ethtool_value edata = { ETHTOOL_GGSO };
966
967 edata.data = dev->features & NETIF_F_GSO;
968 if (copy_to_user(useraddr, &edata, sizeof(edata)))
969 return -EFAULT;
970 return 0;
971}
972
973static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
974{
975 struct ethtool_value edata;
976
977 if (copy_from_user(&edata, useraddr, sizeof(edata)))
978 return -EFAULT;
979 if (edata.data)
980 dev->features |= NETIF_F_GSO;
981 else
982 dev->features &= ~NETIF_F_GSO;
983 return 0;
984}
985
b240a0e5
HX
986static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
987{
988 struct ethtool_value edata = { ETHTOOL_GGRO };
989
990 edata.data = dev->features & NETIF_F_GRO;
991 if (copy_to_user(useraddr, &edata, sizeof(edata)))
992 return -EFAULT;
993 return 0;
994}
995
996static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
997{
998 struct ethtool_value edata;
999
1000 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1001 return -EFAULT;
1002
1003 if (edata.data) {
1004 if (!dev->ethtool_ops->get_rx_csum ||
1005 !dev->ethtool_ops->get_rx_csum(dev))
1006 return -EINVAL;
1007 dev->features |= NETIF_F_GRO;
1008 } else
1009 dev->features &= ~NETIF_F_GRO;
1010
1011 return 0;
1012}
1013
1da177e4
LT
1014static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1015{
1016 struct ethtool_test test;
76fd8593 1017 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4 1018 u64 *data;
ff03d49f 1019 int ret, test_len;
1da177e4 1020
a9828ec6 1021 if (!ops->self_test || !ops->get_sset_count)
1da177e4
LT
1022 return -EOPNOTSUPP;
1023
a9828ec6 1024 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
ff03d49f
JG
1025 if (test_len < 0)
1026 return test_len;
1027 WARN_ON(test_len == 0);
1028
1da177e4
LT
1029 if (copy_from_user(&test, useraddr, sizeof(test)))
1030 return -EFAULT;
1031
ff03d49f
JG
1032 test.len = test_len;
1033 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1da177e4
LT
1034 if (!data)
1035 return -ENOMEM;
1036
1037 ops->self_test(dev, &test, data);
1038
1039 ret = -EFAULT;
1040 if (copy_to_user(useraddr, &test, sizeof(test)))
1041 goto out;
1042 useraddr += sizeof(test);
1043 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1044 goto out;
1045 ret = 0;
1046
1047 out:
1048 kfree(data);
1049 return ret;
1050}
1051
1052static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1053{
1054 struct ethtool_gstrings gstrings;
76fd8593 1055 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4
LT
1056 u8 *data;
1057 int ret;
1058
a9828ec6 1059 if (!ops->get_strings || !ops->get_sset_count)
1da177e4
LT
1060 return -EOPNOTSUPP;
1061
1062 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1063 return -EFAULT;
1064
a9828ec6
BH
1065 ret = ops->get_sset_count(dev, gstrings.string_set);
1066 if (ret < 0)
1067 return ret;
1068
1069 gstrings.len = ret;
1da177e4
LT
1070
1071 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1072 if (!data)
1073 return -ENOMEM;
1074
1075 ops->get_strings(dev, gstrings.string_set, data);
1076
1077 ret = -EFAULT;
1078 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1079 goto out;
1080 useraddr += sizeof(gstrings);
1081 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1082 goto out;
1083 ret = 0;
1084
1085 out:
1086 kfree(data);
1087 return ret;
1088}
1089
1090static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1091{
1092 struct ethtool_value id;
1093
1094 if (!dev->ethtool_ops->phys_id)
1095 return -EOPNOTSUPP;
1096
1097 if (copy_from_user(&id, useraddr, sizeof(id)))
1098 return -EFAULT;
1099
1100 return dev->ethtool_ops->phys_id(dev, id.data);
1101}
1102
1103static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1104{
1105 struct ethtool_stats stats;
76fd8593 1106 const struct ethtool_ops *ops = dev->ethtool_ops;
1da177e4 1107 u64 *data;
ff03d49f 1108 int ret, n_stats;
1da177e4 1109
a9828ec6 1110 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1da177e4
LT
1111 return -EOPNOTSUPP;
1112
a9828ec6 1113 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
ff03d49f
JG
1114 if (n_stats < 0)
1115 return n_stats;
1116 WARN_ON(n_stats == 0);
1117
1da177e4
LT
1118 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1119 return -EFAULT;
1120
ff03d49f
JG
1121 stats.n_stats = n_stats;
1122 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1da177e4
LT
1123 if (!data)
1124 return -ENOMEM;
1125
1126 ops->get_ethtool_stats(dev, &stats, data);
1127
1128 ret = -EFAULT;
1129 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1130 goto out;
1131 useraddr += sizeof(stats);
1132 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1133 goto out;
1134 ret = 0;
1135
1136 out:
1137 kfree(data);
1138 return ret;
1139}
1140
0bf0519d 1141static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
a6f9a705
JW
1142{
1143 struct ethtool_perm_addr epaddr;
a6f9a705 1144
313674af 1145 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
a6f9a705
JW
1146 return -EFAULT;
1147
313674af
MW
1148 if (epaddr.size < dev->addr_len)
1149 return -ETOOSMALL;
1150 epaddr.size = dev->addr_len;
a6f9a705 1151
a6f9a705 1152 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
313674af 1153 return -EFAULT;
a6f9a705 1154 useraddr += sizeof(epaddr);
313674af
MW
1155 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1156 return -EFAULT;
1157 return 0;
a6f9a705
JW
1158}
1159
13c99b24
JG
1160static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1161 u32 cmd, u32 (*actor)(struct net_device *))
3ae7c0b2 1162{
13c99b24 1163 struct ethtool_value edata = { cmd };
3ae7c0b2 1164
13c99b24 1165 if (!actor)
3ae7c0b2
JG
1166 return -EOPNOTSUPP;
1167
13c99b24 1168 edata.data = actor(dev);
3ae7c0b2
JG
1169
1170 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1171 return -EFAULT;
1172 return 0;
1173}
1174
13c99b24
JG
1175static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1176 void (*actor)(struct net_device *, u32))
3ae7c0b2
JG
1177{
1178 struct ethtool_value edata;
1179
13c99b24 1180 if (!actor)
3ae7c0b2
JG
1181 return -EOPNOTSUPP;
1182
1183 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1184 return -EFAULT;
1185
13c99b24 1186 actor(dev, edata.data);
339bf024
JG
1187 return 0;
1188}
1189
13c99b24
JG
1190static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1191 int (*actor)(struct net_device *, u32))
339bf024
JG
1192{
1193 struct ethtool_value edata;
1194
13c99b24 1195 if (!actor)
339bf024
JG
1196 return -EOPNOTSUPP;
1197
1198 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1199 return -EFAULT;
1200
13c99b24 1201 return actor(dev, edata.data);
339bf024
JG
1202}
1203
05c6a8d7
AK
1204static int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
1205{
1206 struct ethtool_flash efl;
1207
1208 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1209 return -EFAULT;
1210
1211 if (!dev->ethtool_ops->flash_device)
1212 return -EOPNOTSUPP;
1213
1214 return dev->ethtool_ops->flash_device(dev, &efl);
1215}
1216
1da177e4
LT
1217/* The main entry point in this file. Called from net/core/dev.c */
1218
881d966b 1219int dev_ethtool(struct net *net, struct ifreq *ifr)
1da177e4 1220{
881d966b 1221 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1da177e4
LT
1222 void __user *useraddr = ifr->ifr_data;
1223 u32 ethcmd;
1224 int rc;
81e81575 1225 unsigned long old_features;
1da177e4 1226
1da177e4
LT
1227 if (!dev || !netif_device_present(dev))
1228 return -ENODEV;
1229
1230 if (!dev->ethtool_ops)
61a44b9c 1231 return -EOPNOTSUPP;
1da177e4
LT
1232
1233 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1234 return -EFAULT;
1235
75f3123c
SH
1236 /* Allow some commands to be done by anyone */
1237 switch(ethcmd) {
75f3123c 1238 case ETHTOOL_GDRVINFO:
75f3123c 1239 case ETHTOOL_GMSGLVL:
75f3123c
SH
1240 case ETHTOOL_GCOALESCE:
1241 case ETHTOOL_GRINGPARAM:
1242 case ETHTOOL_GPAUSEPARAM:
1243 case ETHTOOL_GRXCSUM:
1244 case ETHTOOL_GTXCSUM:
1245 case ETHTOOL_GSG:
1246 case ETHTOOL_GSTRINGS:
75f3123c
SH
1247 case ETHTOOL_GTSO:
1248 case ETHTOOL_GPERMADDR:
1249 case ETHTOOL_GUFO:
1250 case ETHTOOL_GGSO:
339bf024
JG
1251 case ETHTOOL_GFLAGS:
1252 case ETHTOOL_GPFLAGS:
0853ad66 1253 case ETHTOOL_GRXFH:
59089d8d
SB
1254 case ETHTOOL_GRXRINGS:
1255 case ETHTOOL_GRXCLSRLCNT:
1256 case ETHTOOL_GRXCLSRULE:
1257 case ETHTOOL_GRXCLSRLALL:
75f3123c
SH
1258 break;
1259 default:
1260 if (!capable(CAP_NET_ADMIN))
1261 return -EPERM;
1262 }
1263
e71a4783 1264 if (dev->ethtool_ops->begin)
1da177e4
LT
1265 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1266 return rc;
1267
d8a33ac4
SH
1268 old_features = dev->features;
1269
1da177e4
LT
1270 switch (ethcmd) {
1271 case ETHTOOL_GSET:
1272 rc = ethtool_get_settings(dev, useraddr);
1273 break;
1274 case ETHTOOL_SSET:
1275 rc = ethtool_set_settings(dev, useraddr);
1276 break;
1277 case ETHTOOL_GDRVINFO:
1278 rc = ethtool_get_drvinfo(dev, useraddr);
1da177e4
LT
1279 break;
1280 case ETHTOOL_GREGS:
1281 rc = ethtool_get_regs(dev, useraddr);
1282 break;
1283 case ETHTOOL_GWOL:
1284 rc = ethtool_get_wol(dev, useraddr);
1285 break;
1286 case ETHTOOL_SWOL:
1287 rc = ethtool_set_wol(dev, useraddr);
1288 break;
1289 case ETHTOOL_GMSGLVL:
13c99b24
JG
1290 rc = ethtool_get_value(dev, useraddr, ethcmd,
1291 dev->ethtool_ops->get_msglevel);
1da177e4
LT
1292 break;
1293 case ETHTOOL_SMSGLVL:
13c99b24
JG
1294 rc = ethtool_set_value_void(dev, useraddr,
1295 dev->ethtool_ops->set_msglevel);
1da177e4
LT
1296 break;
1297 case ETHTOOL_NWAY_RST:
1298 rc = ethtool_nway_reset(dev);
1299 break;
1300 case ETHTOOL_GLINK:
13c99b24
JG
1301 rc = ethtool_get_value(dev, useraddr, ethcmd,
1302 dev->ethtool_ops->get_link);
1da177e4
LT
1303 break;
1304 case ETHTOOL_GEEPROM:
1305 rc = ethtool_get_eeprom(dev, useraddr);
1306 break;
1307 case ETHTOOL_SEEPROM:
1308 rc = ethtool_set_eeprom(dev, useraddr);
1309 break;
1310 case ETHTOOL_GCOALESCE:
1311 rc = ethtool_get_coalesce(dev, useraddr);
1312 break;
1313 case ETHTOOL_SCOALESCE:
1314 rc = ethtool_set_coalesce(dev, useraddr);
1315 break;
1316 case ETHTOOL_GRINGPARAM:
1317 rc = ethtool_get_ringparam(dev, useraddr);
1318 break;
1319 case ETHTOOL_SRINGPARAM:
1320 rc = ethtool_set_ringparam(dev, useraddr);
1321 break;
1322 case ETHTOOL_GPAUSEPARAM:
1323 rc = ethtool_get_pauseparam(dev, useraddr);
1324 break;
1325 case ETHTOOL_SPAUSEPARAM:
1326 rc = ethtool_set_pauseparam(dev, useraddr);
1327 break;
1328 case ETHTOOL_GRXCSUM:
13c99b24 1329 rc = ethtool_get_value(dev, useraddr, ethcmd,
1896e61f
SS
1330 (dev->ethtool_ops->get_rx_csum ?
1331 dev->ethtool_ops->get_rx_csum :
1332 ethtool_op_get_rx_csum));
1da177e4
LT
1333 break;
1334 case ETHTOOL_SRXCSUM:
b240a0e5 1335 rc = ethtool_set_rx_csum(dev, useraddr);
1da177e4
LT
1336 break;
1337 case ETHTOOL_GTXCSUM:
13c99b24 1338 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1339 (dev->ethtool_ops->get_tx_csum ?
1340 dev->ethtool_ops->get_tx_csum :
1341 ethtool_op_get_tx_csum));
1da177e4
LT
1342 break;
1343 case ETHTOOL_STXCSUM:
1344 rc = ethtool_set_tx_csum(dev, useraddr);
1345 break;
1346 case ETHTOOL_GSG:
13c99b24 1347 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1348 (dev->ethtool_ops->get_sg ?
1349 dev->ethtool_ops->get_sg :
1350 ethtool_op_get_sg));
1da177e4
LT
1351 break;
1352 case ETHTOOL_SSG:
1353 rc = ethtool_set_sg(dev, useraddr);
1354 break;
1355 case ETHTOOL_GTSO:
13c99b24 1356 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1357 (dev->ethtool_ops->get_tso ?
1358 dev->ethtool_ops->get_tso :
1359 ethtool_op_get_tso));
1da177e4
LT
1360 break;
1361 case ETHTOOL_STSO:
1362 rc = ethtool_set_tso(dev, useraddr);
1363 break;
1364 case ETHTOOL_TEST:
1365 rc = ethtool_self_test(dev, useraddr);
1366 break;
1367 case ETHTOOL_GSTRINGS:
1368 rc = ethtool_get_strings(dev, useraddr);
1369 break;
1370 case ETHTOOL_PHYS_ID:
1371 rc = ethtool_phys_id(dev, useraddr);
1372 break;
1373 case ETHTOOL_GSTATS:
1374 rc = ethtool_get_stats(dev, useraddr);
1375 break;
a6f9a705
JW
1376 case ETHTOOL_GPERMADDR:
1377 rc = ethtool_get_perm_addr(dev, useraddr);
1378 break;
e89e9cf5 1379 case ETHTOOL_GUFO:
13c99b24 1380 rc = ethtool_get_value(dev, useraddr, ethcmd,
88d3aafd
JG
1381 (dev->ethtool_ops->get_ufo ?
1382 dev->ethtool_ops->get_ufo :
1383 ethtool_op_get_ufo));
e89e9cf5
AR
1384 break;
1385 case ETHTOOL_SUFO:
1386 rc = ethtool_set_ufo(dev, useraddr);
1387 break;
37c3185a
HX
1388 case ETHTOOL_GGSO:
1389 rc = ethtool_get_gso(dev, useraddr);
1390 break;
1391 case ETHTOOL_SGSO:
1392 rc = ethtool_set_gso(dev, useraddr);
1393 break;
3ae7c0b2 1394 case ETHTOOL_GFLAGS:
13c99b24 1395 rc = ethtool_get_value(dev, useraddr, ethcmd,
1896e61f
SS
1396 (dev->ethtool_ops->get_flags ?
1397 dev->ethtool_ops->get_flags :
1398 ethtool_op_get_flags));
3ae7c0b2
JG
1399 break;
1400 case ETHTOOL_SFLAGS:
13c99b24
JG
1401 rc = ethtool_set_value(dev, useraddr,
1402 dev->ethtool_ops->set_flags);
3ae7c0b2 1403 break;
339bf024 1404 case ETHTOOL_GPFLAGS:
13c99b24
JG
1405 rc = ethtool_get_value(dev, useraddr, ethcmd,
1406 dev->ethtool_ops->get_priv_flags);
339bf024
JG
1407 break;
1408 case ETHTOOL_SPFLAGS:
13c99b24
JG
1409 rc = ethtool_set_value(dev, useraddr,
1410 dev->ethtool_ops->set_priv_flags);
339bf024 1411 break;
0853ad66 1412 case ETHTOOL_GRXFH:
59089d8d
SB
1413 case ETHTOOL_GRXRINGS:
1414 case ETHTOOL_GRXCLSRLCNT:
1415 case ETHTOOL_GRXCLSRULE:
1416 case ETHTOOL_GRXCLSRLALL:
1417 rc = ethtool_get_rxnfc(dev, useraddr);
0853ad66
SB
1418 break;
1419 case ETHTOOL_SRXFH:
59089d8d
SB
1420 case ETHTOOL_SRXCLSRLDEL:
1421 case ETHTOOL_SRXCLSRLINS:
1422 rc = ethtool_set_rxnfc(dev, useraddr);
0853ad66 1423 break;
b240a0e5
HX
1424 case ETHTOOL_GGRO:
1425 rc = ethtool_get_gro(dev, useraddr);
1426 break;
1427 case ETHTOOL_SGRO:
1428 rc = ethtool_set_gro(dev, useraddr);
1429 break;
05c6a8d7
AK
1430 case ETHTOOL_FLASHDEV:
1431 rc = ethtool_flash_device(dev, useraddr);
1432 break;
d73d3a8c
BH
1433 case ETHTOOL_RESET:
1434 rc = ethtool_reset(dev, useraddr);
1435 break;
15682bc4
PWJ
1436 case ETHTOOL_SRXNTUPLE:
1437 rc = ethtool_set_rx_ntuple(dev, useraddr);
1438 break;
1439 case ETHTOOL_GRXNTUPLE:
1440 rc = ethtool_get_rx_ntuple(dev, useraddr);
1441 break;
1da177e4 1442 default:
61a44b9c 1443 rc = -EOPNOTSUPP;
1da177e4 1444 }
4ec93edb 1445
e71a4783 1446 if (dev->ethtool_ops->complete)
1da177e4 1447 dev->ethtool_ops->complete(dev);
d8a33ac4
SH
1448
1449 if (old_features != dev->features)
1450 netdev_features_change(dev);
1451
1da177e4 1452 return rc;
1da177e4
LT
1453}
1454
1da177e4
LT
1455EXPORT_SYMBOL(ethtool_op_get_link);
1456EXPORT_SYMBOL(ethtool_op_get_sg);
1457EXPORT_SYMBOL(ethtool_op_get_tso);
1da177e4
LT
1458EXPORT_SYMBOL(ethtool_op_set_sg);
1459EXPORT_SYMBOL(ethtool_op_set_tso);
1460EXPORT_SYMBOL(ethtool_op_set_tx_csum);
69f6a0fa 1461EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
6460d948 1462EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
e89e9cf5
AR
1463EXPORT_SYMBOL(ethtool_op_set_ufo);
1464EXPORT_SYMBOL(ethtool_op_get_ufo);
3ae7c0b2
JG
1465EXPORT_SYMBOL(ethtool_op_set_flags);
1466EXPORT_SYMBOL(ethtool_op_get_flags);