Revert "ethtool: Add n-tuple string length to drvinfo and return it"
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / core / ethtool.c
blob31b1eddc1b84cbb5e42fea62cad9a8da2db712cd
1 /*
2 * net/core/ethtool.c - Ethtool ioctl handler
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs.
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.
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/capability.h>
17 #include <linux/errno.h>
18 #include <linux/ethtool.h>
19 #include <linux/netdevice.h>
20 #include <asm/uaccess.h>
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.
28 u32 ethtool_op_get_link(struct net_device *dev)
30 return netif_carrier_ok(dev) ? 1 : 0;
33 u32 ethtool_op_get_rx_csum(struct net_device *dev)
35 return (dev->features & NETIF_F_ALL_CSUM) != 0;
37 EXPORT_SYMBOL(ethtool_op_get_rx_csum);
39 u32 ethtool_op_get_tx_csum(struct net_device *dev)
41 return (dev->features & NETIF_F_ALL_CSUM) != 0;
43 EXPORT_SYMBOL(ethtool_op_get_tx_csum);
45 int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
47 if (data)
48 dev->features |= NETIF_F_IP_CSUM;
49 else
50 dev->features &= ~NETIF_F_IP_CSUM;
52 return 0;
55 int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
57 if (data)
58 dev->features |= NETIF_F_HW_CSUM;
59 else
60 dev->features &= ~NETIF_F_HW_CSUM;
62 return 0;
65 int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
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);
72 return 0;
75 u32 ethtool_op_get_sg(struct net_device *dev)
77 return (dev->features & NETIF_F_SG) != 0;
80 int ethtool_op_set_sg(struct net_device *dev, u32 data)
82 if (data)
83 dev->features |= NETIF_F_SG;
84 else
85 dev->features &= ~NETIF_F_SG;
87 return 0;
90 u32 ethtool_op_get_tso(struct net_device *dev)
92 return (dev->features & NETIF_F_TSO) != 0;
95 int ethtool_op_set_tso(struct net_device *dev, u32 data)
97 if (data)
98 dev->features |= NETIF_F_TSO;
99 else
100 dev->features &= ~NETIF_F_TSO;
102 return 0;
105 u32 ethtool_op_get_ufo(struct net_device *dev)
107 return (dev->features & NETIF_F_UFO) != 0;
110 int ethtool_op_set_ufo(struct net_device *dev, u32 data)
112 if (data)
113 dev->features |= NETIF_F_UFO;
114 else
115 dev->features &= ~NETIF_F_UFO;
116 return 0;
119 /* the following list of flags are the same as their associated
120 * NETIF_F_xxx values in include/linux/netdevice.h
122 static const u32 flags_dup_features =
123 (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
125 u32 ethtool_op_get_flags(struct net_device *dev)
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
132 return dev->features & flags_dup_features;
135 int ethtool_op_set_flags(struct net_device *dev, u32 data)
137 const struct ethtool_ops *ops = dev->ethtool_ops;
139 if (data & ETH_FLAG_LRO)
140 dev->features |= NETIF_F_LRO;
141 else
142 dev->features &= ~NETIF_F_LRO;
144 if (data & ETH_FLAG_NTUPLE) {
145 if (!ops->set_rx_ntuple)
146 return -EOPNOTSUPP;
147 dev->features |= NETIF_F_NTUPLE;
148 } else {
149 /* safe to clear regardless */
150 dev->features &= ~NETIF_F_NTUPLE;
153 return 0;
156 void ethtool_ntuple_flush(struct net_device *dev)
158 struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
160 list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
161 list_del(&fsc->list);
162 kfree(fsc);
164 dev->ethtool_ntuple_list.count = 0;
166 EXPORT_SYMBOL(ethtool_ntuple_flush);
168 /* Handlers for each ethtool command */
170 static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
172 struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
173 int err;
175 if (!dev->ethtool_ops->get_settings)
176 return -EOPNOTSUPP;
178 err = dev->ethtool_ops->get_settings(dev, &cmd);
179 if (err < 0)
180 return err;
182 if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
183 return -EFAULT;
184 return 0;
187 static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
189 struct ethtool_cmd cmd;
191 if (!dev->ethtool_ops->set_settings)
192 return -EOPNOTSUPP;
194 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
195 return -EFAULT;
197 return dev->ethtool_ops->set_settings(dev, &cmd);
201 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
203 static noinline int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
205 struct ethtool_drvinfo info;
206 const struct ethtool_ops *ops = dev->ethtool_ops;
208 if (!ops->get_drvinfo)
209 return -EOPNOTSUPP;
211 memset(&info, 0, sizeof(info));
212 info.cmd = ETHTOOL_GDRVINFO;
213 ops->get_drvinfo(dev, &info);
215 if (ops->get_sset_count) {
216 int rc;
218 rc = ops->get_sset_count(dev, ETH_SS_TEST);
219 if (rc >= 0)
220 info.testinfo_len = rc;
221 rc = ops->get_sset_count(dev, ETH_SS_STATS);
222 if (rc >= 0)
223 info.n_stats = rc;
224 rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
225 if (rc >= 0)
226 info.n_priv_flags = rc;
228 if (ops->get_regs_len)
229 info.regdump_len = ops->get_regs_len(dev);
230 if (ops->get_eeprom_len)
231 info.eedump_len = ops->get_eeprom_len(dev);
233 if (copy_to_user(useraddr, &info, sizeof(info)))
234 return -EFAULT;
235 return 0;
239 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
241 static noinline int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
243 struct ethtool_rxnfc cmd;
245 if (!dev->ethtool_ops->set_rxnfc)
246 return -EOPNOTSUPP;
248 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
249 return -EFAULT;
251 return dev->ethtool_ops->set_rxnfc(dev, &cmd);
255 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
257 static noinline int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
259 struct ethtool_rxnfc info;
260 const struct ethtool_ops *ops = dev->ethtool_ops;
261 int ret;
262 void *rule_buf = NULL;
264 if (!ops->get_rxnfc)
265 return -EOPNOTSUPP;
267 if (copy_from_user(&info, useraddr, sizeof(info)))
268 return -EFAULT;
270 if (info.cmd == ETHTOOL_GRXCLSRLALL) {
271 if (info.rule_cnt > 0) {
272 rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
273 GFP_USER);
274 if (!rule_buf)
275 return -ENOMEM;
279 ret = ops->get_rxnfc(dev, &info, rule_buf);
280 if (ret < 0)
281 goto err_out;
283 ret = -EFAULT;
284 if (copy_to_user(useraddr, &info, sizeof(info)))
285 goto err_out;
287 if (rule_buf) {
288 useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
289 if (copy_to_user(useraddr, rule_buf,
290 info.rule_cnt * sizeof(u32)))
291 goto err_out;
293 ret = 0;
295 err_out:
296 kfree(rule_buf);
298 return ret;
301 static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
302 struct ethtool_rx_ntuple_flow_spec *spec,
303 struct ethtool_rx_ntuple_flow_spec_container *fsc)
306 /* don't add filters forever */
307 if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
308 /* free the container */
309 kfree(fsc);
310 return;
313 /* Copy the whole filter over */
314 fsc->fs.flow_type = spec->flow_type;
315 memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
316 memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
318 fsc->fs.vlan_tag = spec->vlan_tag;
319 fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
320 fsc->fs.data = spec->data;
321 fsc->fs.data_mask = spec->data_mask;
322 fsc->fs.action = spec->action;
324 /* add to the list */
325 list_add_tail_rcu(&fsc->list, &list->list);
326 list->count++;
330 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
332 static noinline int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
334 struct ethtool_rx_ntuple cmd;
335 const struct ethtool_ops *ops = dev->ethtool_ops;
336 struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
337 int ret;
339 if (!(dev->features & NETIF_F_NTUPLE))
340 return -EINVAL;
342 if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
343 return -EFAULT;
346 * Cache filter in dev struct for GET operation only if
347 * the underlying driver doesn't have its own GET operation, and
348 * only if the filter was added successfully. First make sure we
349 * can allocate the filter, then continue if successful.
351 if (!ops->get_rx_ntuple) {
352 fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
353 if (!fsc)
354 return -ENOMEM;
357 ret = ops->set_rx_ntuple(dev, &cmd);
358 if (ret) {
359 kfree(fsc);
360 return ret;
363 if (!ops->get_rx_ntuple)
364 __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
366 return ret;
369 static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
371 struct ethtool_gstrings gstrings;
372 const struct ethtool_ops *ops = dev->ethtool_ops;
373 struct ethtool_rx_ntuple_flow_spec_container *fsc;
374 u8 *data;
375 char *p;
376 int ret, i, num_strings = 0;
378 if (!ops->get_sset_count)
379 return -EOPNOTSUPP;
381 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
382 return -EFAULT;
384 ret = ops->get_sset_count(dev, gstrings.string_set);
385 if (ret < 0)
386 return ret;
388 gstrings.len = ret;
390 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
391 if (!data)
392 return -ENOMEM;
394 if (ops->get_rx_ntuple) {
395 /* driver-specific filter grab */
396 ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
397 goto copy;
400 /* default ethtool filter grab */
401 i = 0;
402 p = (char *)data;
403 list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
404 sprintf(p, "Filter %d:\n", i);
405 p += ETH_GSTRING_LEN;
406 num_strings++;
408 switch (fsc->fs.flow_type) {
409 case TCP_V4_FLOW:
410 sprintf(p, "\tFlow Type: TCP\n");
411 p += ETH_GSTRING_LEN;
412 num_strings++;
413 break;
414 case UDP_V4_FLOW:
415 sprintf(p, "\tFlow Type: UDP\n");
416 p += ETH_GSTRING_LEN;
417 num_strings++;
418 break;
419 case SCTP_V4_FLOW:
420 sprintf(p, "\tFlow Type: SCTP\n");
421 p += ETH_GSTRING_LEN;
422 num_strings++;
423 break;
424 case AH_ESP_V4_FLOW:
425 sprintf(p, "\tFlow Type: AH ESP\n");
426 p += ETH_GSTRING_LEN;
427 num_strings++;
428 break;
429 case ESP_V4_FLOW:
430 sprintf(p, "\tFlow Type: ESP\n");
431 p += ETH_GSTRING_LEN;
432 num_strings++;
433 break;
434 case IP_USER_FLOW:
435 sprintf(p, "\tFlow Type: Raw IP\n");
436 p += ETH_GSTRING_LEN;
437 num_strings++;
438 break;
439 case IPV4_FLOW:
440 sprintf(p, "\tFlow Type: IPv4\n");
441 p += ETH_GSTRING_LEN;
442 num_strings++;
443 break;
444 default:
445 sprintf(p, "\tFlow Type: Unknown\n");
446 p += ETH_GSTRING_LEN;
447 num_strings++;
448 goto unknown_filter;
451 /* now the rest of the filters */
452 switch (fsc->fs.flow_type) {
453 case TCP_V4_FLOW:
454 case UDP_V4_FLOW:
455 case SCTP_V4_FLOW:
456 sprintf(p, "\tSrc IP addr: 0x%x\n",
457 fsc->fs.h_u.tcp_ip4_spec.ip4src);
458 p += ETH_GSTRING_LEN;
459 num_strings++;
460 sprintf(p, "\tSrc IP mask: 0x%x\n",
461 fsc->fs.m_u.tcp_ip4_spec.ip4src);
462 p += ETH_GSTRING_LEN;
463 num_strings++;
464 sprintf(p, "\tDest IP addr: 0x%x\n",
465 fsc->fs.h_u.tcp_ip4_spec.ip4dst);
466 p += ETH_GSTRING_LEN;
467 num_strings++;
468 sprintf(p, "\tDest IP mask: 0x%x\n",
469 fsc->fs.m_u.tcp_ip4_spec.ip4dst);
470 p += ETH_GSTRING_LEN;
471 num_strings++;
472 sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
473 fsc->fs.h_u.tcp_ip4_spec.psrc,
474 fsc->fs.m_u.tcp_ip4_spec.psrc);
475 p += ETH_GSTRING_LEN;
476 num_strings++;
477 sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
478 fsc->fs.h_u.tcp_ip4_spec.pdst,
479 fsc->fs.m_u.tcp_ip4_spec.pdst);
480 p += ETH_GSTRING_LEN;
481 num_strings++;
482 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
483 fsc->fs.h_u.tcp_ip4_spec.tos,
484 fsc->fs.m_u.tcp_ip4_spec.tos);
485 p += ETH_GSTRING_LEN;
486 num_strings++;
487 break;
488 case AH_ESP_V4_FLOW:
489 case ESP_V4_FLOW:
490 sprintf(p, "\tSrc IP addr: 0x%x\n",
491 fsc->fs.h_u.ah_ip4_spec.ip4src);
492 p += ETH_GSTRING_LEN;
493 num_strings++;
494 sprintf(p, "\tSrc IP mask: 0x%x\n",
495 fsc->fs.m_u.ah_ip4_spec.ip4src);
496 p += ETH_GSTRING_LEN;
497 num_strings++;
498 sprintf(p, "\tDest IP addr: 0x%x\n",
499 fsc->fs.h_u.ah_ip4_spec.ip4dst);
500 p += ETH_GSTRING_LEN;
501 num_strings++;
502 sprintf(p, "\tDest IP mask: 0x%x\n",
503 fsc->fs.m_u.ah_ip4_spec.ip4dst);
504 p += ETH_GSTRING_LEN;
505 num_strings++;
506 sprintf(p, "\tSPI: %d, mask: 0x%x\n",
507 fsc->fs.h_u.ah_ip4_spec.spi,
508 fsc->fs.m_u.ah_ip4_spec.spi);
509 p += ETH_GSTRING_LEN;
510 num_strings++;
511 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
512 fsc->fs.h_u.ah_ip4_spec.tos,
513 fsc->fs.m_u.ah_ip4_spec.tos);
514 p += ETH_GSTRING_LEN;
515 num_strings++;
516 break;
517 case IP_USER_FLOW:
518 sprintf(p, "\tSrc IP addr: 0x%x\n",
519 fsc->fs.h_u.raw_ip4_spec.ip4src);
520 p += ETH_GSTRING_LEN;
521 num_strings++;
522 sprintf(p, "\tSrc IP mask: 0x%x\n",
523 fsc->fs.m_u.raw_ip4_spec.ip4src);
524 p += ETH_GSTRING_LEN;
525 num_strings++;
526 sprintf(p, "\tDest IP addr: 0x%x\n",
527 fsc->fs.h_u.raw_ip4_spec.ip4dst);
528 p += ETH_GSTRING_LEN;
529 num_strings++;
530 sprintf(p, "\tDest IP mask: 0x%x\n",
531 fsc->fs.m_u.raw_ip4_spec.ip4dst);
532 p += ETH_GSTRING_LEN;
533 num_strings++;
534 break;
535 case IPV4_FLOW:
536 sprintf(p, "\tSrc IP addr: 0x%x\n",
537 fsc->fs.h_u.usr_ip4_spec.ip4src);
538 p += ETH_GSTRING_LEN;
539 num_strings++;
540 sprintf(p, "\tSrc IP mask: 0x%x\n",
541 fsc->fs.m_u.usr_ip4_spec.ip4src);
542 p += ETH_GSTRING_LEN;
543 num_strings++;
544 sprintf(p, "\tDest IP addr: 0x%x\n",
545 fsc->fs.h_u.usr_ip4_spec.ip4dst);
546 p += ETH_GSTRING_LEN;
547 num_strings++;
548 sprintf(p, "\tDest IP mask: 0x%x\n",
549 fsc->fs.m_u.usr_ip4_spec.ip4dst);
550 p += ETH_GSTRING_LEN;
551 num_strings++;
552 sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
553 fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
554 fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
555 p += ETH_GSTRING_LEN;
556 num_strings++;
557 sprintf(p, "\tTOS: %d, mask: 0x%x\n",
558 fsc->fs.h_u.usr_ip4_spec.tos,
559 fsc->fs.m_u.usr_ip4_spec.tos);
560 p += ETH_GSTRING_LEN;
561 num_strings++;
562 sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
563 fsc->fs.h_u.usr_ip4_spec.ip_ver,
564 fsc->fs.m_u.usr_ip4_spec.ip_ver);
565 p += ETH_GSTRING_LEN;
566 num_strings++;
567 sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
568 fsc->fs.h_u.usr_ip4_spec.proto,
569 fsc->fs.m_u.usr_ip4_spec.proto);
570 p += ETH_GSTRING_LEN;
571 num_strings++;
572 break;
574 sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
575 fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
576 p += ETH_GSTRING_LEN;
577 num_strings++;
578 sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
579 p += ETH_GSTRING_LEN;
580 num_strings++;
581 sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
582 p += ETH_GSTRING_LEN;
583 num_strings++;
584 if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
585 sprintf(p, "\tAction: Drop\n");
586 else
587 sprintf(p, "\tAction: Direct to queue %d\n",
588 fsc->fs.action);
589 p += ETH_GSTRING_LEN;
590 num_strings++;
591 unknown_filter:
592 i++;
594 copy:
595 /* indicate to userspace how many strings we actually have */
596 gstrings.len = num_strings;
597 ret = -EFAULT;
598 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
599 goto out;
600 useraddr += sizeof(gstrings);
601 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
602 goto out;
603 ret = 0;
605 out:
606 kfree(data);
607 return ret;
610 static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
612 struct ethtool_regs regs;
613 const struct ethtool_ops *ops = dev->ethtool_ops;
614 void *regbuf;
615 int reglen, ret;
617 if (!ops->get_regs || !ops->get_regs_len)
618 return -EOPNOTSUPP;
620 if (copy_from_user(&regs, useraddr, sizeof(regs)))
621 return -EFAULT;
623 reglen = ops->get_regs_len(dev);
624 if (regs.len > reglen)
625 regs.len = reglen;
627 regbuf = kmalloc(reglen, GFP_USER);
628 if (!regbuf)
629 return -ENOMEM;
631 ops->get_regs(dev, &regs, regbuf);
633 ret = -EFAULT;
634 if (copy_to_user(useraddr, &regs, sizeof(regs)))
635 goto out;
636 useraddr += offsetof(struct ethtool_regs, data);
637 if (copy_to_user(useraddr, regbuf, regs.len))
638 goto out;
639 ret = 0;
641 out:
642 kfree(regbuf);
643 return ret;
646 static int ethtool_reset(struct net_device *dev, char __user *useraddr)
648 struct ethtool_value reset;
649 int ret;
651 if (!dev->ethtool_ops->reset)
652 return -EOPNOTSUPP;
654 if (copy_from_user(&reset, useraddr, sizeof(reset)))
655 return -EFAULT;
657 ret = dev->ethtool_ops->reset(dev, &reset.data);
658 if (ret)
659 return ret;
661 if (copy_to_user(useraddr, &reset, sizeof(reset)))
662 return -EFAULT;
663 return 0;
666 static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
668 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
670 if (!dev->ethtool_ops->get_wol)
671 return -EOPNOTSUPP;
673 dev->ethtool_ops->get_wol(dev, &wol);
675 if (copy_to_user(useraddr, &wol, sizeof(wol)))
676 return -EFAULT;
677 return 0;
680 static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
682 struct ethtool_wolinfo wol;
684 if (!dev->ethtool_ops->set_wol)
685 return -EOPNOTSUPP;
687 if (copy_from_user(&wol, useraddr, sizeof(wol)))
688 return -EFAULT;
690 return dev->ethtool_ops->set_wol(dev, &wol);
693 static int ethtool_nway_reset(struct net_device *dev)
695 if (!dev->ethtool_ops->nway_reset)
696 return -EOPNOTSUPP;
698 return dev->ethtool_ops->nway_reset(dev);
701 static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
703 struct ethtool_eeprom eeprom;
704 const struct ethtool_ops *ops = dev->ethtool_ops;
705 void __user *userbuf = useraddr + sizeof(eeprom);
706 u32 bytes_remaining;
707 u8 *data;
708 int ret = 0;
710 if (!ops->get_eeprom || !ops->get_eeprom_len)
711 return -EOPNOTSUPP;
713 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
714 return -EFAULT;
716 /* Check for wrap and zero */
717 if (eeprom.offset + eeprom.len <= eeprom.offset)
718 return -EINVAL;
720 /* Check for exceeding total eeprom len */
721 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
722 return -EINVAL;
724 data = kmalloc(PAGE_SIZE, GFP_USER);
725 if (!data)
726 return -ENOMEM;
728 bytes_remaining = eeprom.len;
729 while (bytes_remaining > 0) {
730 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
732 ret = ops->get_eeprom(dev, &eeprom, data);
733 if (ret)
734 break;
735 if (copy_to_user(userbuf, data, eeprom.len)) {
736 ret = -EFAULT;
737 break;
739 userbuf += eeprom.len;
740 eeprom.offset += eeprom.len;
741 bytes_remaining -= eeprom.len;
744 eeprom.len = userbuf - (useraddr + sizeof(eeprom));
745 eeprom.offset -= eeprom.len;
746 if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
747 ret = -EFAULT;
749 kfree(data);
750 return ret;
753 static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
755 struct ethtool_eeprom eeprom;
756 const struct ethtool_ops *ops = dev->ethtool_ops;
757 void __user *userbuf = useraddr + sizeof(eeprom);
758 u32 bytes_remaining;
759 u8 *data;
760 int ret = 0;
762 if (!ops->set_eeprom || !ops->get_eeprom_len)
763 return -EOPNOTSUPP;
765 if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
766 return -EFAULT;
768 /* Check for wrap and zero */
769 if (eeprom.offset + eeprom.len <= eeprom.offset)
770 return -EINVAL;
772 /* Check for exceeding total eeprom len */
773 if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
774 return -EINVAL;
776 data = kmalloc(PAGE_SIZE, GFP_USER);
777 if (!data)
778 return -ENOMEM;
780 bytes_remaining = eeprom.len;
781 while (bytes_remaining > 0) {
782 eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
784 if (copy_from_user(data, userbuf, eeprom.len)) {
785 ret = -EFAULT;
786 break;
788 ret = ops->set_eeprom(dev, &eeprom, data);
789 if (ret)
790 break;
791 userbuf += eeprom.len;
792 eeprom.offset += eeprom.len;
793 bytes_remaining -= eeprom.len;
796 kfree(data);
797 return ret;
801 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
803 static noinline int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
805 struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
807 if (!dev->ethtool_ops->get_coalesce)
808 return -EOPNOTSUPP;
810 dev->ethtool_ops->get_coalesce(dev, &coalesce);
812 if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
813 return -EFAULT;
814 return 0;
818 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
820 static noinline int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
822 struct ethtool_coalesce coalesce;
824 if (!dev->ethtool_ops->set_coalesce)
825 return -EOPNOTSUPP;
827 if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
828 return -EFAULT;
830 return dev->ethtool_ops->set_coalesce(dev, &coalesce);
833 static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
835 struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
837 if (!dev->ethtool_ops->get_ringparam)
838 return -EOPNOTSUPP;
840 dev->ethtool_ops->get_ringparam(dev, &ringparam);
842 if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
843 return -EFAULT;
844 return 0;
847 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
849 struct ethtool_ringparam ringparam;
851 if (!dev->ethtool_ops->set_ringparam)
852 return -EOPNOTSUPP;
854 if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
855 return -EFAULT;
857 return dev->ethtool_ops->set_ringparam(dev, &ringparam);
860 static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
862 struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
864 if (!dev->ethtool_ops->get_pauseparam)
865 return -EOPNOTSUPP;
867 dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
869 if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
870 return -EFAULT;
871 return 0;
874 static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
876 struct ethtool_pauseparam pauseparam;
878 if (!dev->ethtool_ops->set_pauseparam)
879 return -EOPNOTSUPP;
881 if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
882 return -EFAULT;
884 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
887 static int __ethtool_set_sg(struct net_device *dev, u32 data)
889 int err;
891 if (!data && dev->ethtool_ops->set_tso) {
892 err = dev->ethtool_ops->set_tso(dev, 0);
893 if (err)
894 return err;
897 if (!data && dev->ethtool_ops->set_ufo) {
898 err = dev->ethtool_ops->set_ufo(dev, 0);
899 if (err)
900 return err;
902 return dev->ethtool_ops->set_sg(dev, data);
905 static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
907 struct ethtool_value edata;
908 int err;
910 if (!dev->ethtool_ops->set_tx_csum)
911 return -EOPNOTSUPP;
913 if (copy_from_user(&edata, useraddr, sizeof(edata)))
914 return -EFAULT;
916 if (!edata.data && dev->ethtool_ops->set_sg) {
917 err = __ethtool_set_sg(dev, 0);
918 if (err)
919 return err;
922 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
925 static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
927 struct ethtool_value edata;
929 if (!dev->ethtool_ops->set_rx_csum)
930 return -EOPNOTSUPP;
932 if (copy_from_user(&edata, useraddr, sizeof(edata)))
933 return -EFAULT;
935 if (!edata.data && dev->ethtool_ops->set_sg)
936 dev->features &= ~NETIF_F_GRO;
938 return dev->ethtool_ops->set_rx_csum(dev, edata.data);
941 static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
943 struct ethtool_value edata;
945 if (!dev->ethtool_ops->set_sg)
946 return -EOPNOTSUPP;
948 if (copy_from_user(&edata, useraddr, sizeof(edata)))
949 return -EFAULT;
951 if (edata.data &&
952 !(dev->features & NETIF_F_ALL_CSUM))
953 return -EINVAL;
955 return __ethtool_set_sg(dev, edata.data);
958 static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
960 struct ethtool_value edata;
962 if (!dev->ethtool_ops->set_tso)
963 return -EOPNOTSUPP;
965 if (copy_from_user(&edata, useraddr, sizeof(edata)))
966 return -EFAULT;
968 if (edata.data && !(dev->features & NETIF_F_SG))
969 return -EINVAL;
971 return dev->ethtool_ops->set_tso(dev, edata.data);
974 static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
976 struct ethtool_value edata;
978 if (!dev->ethtool_ops->set_ufo)
979 return -EOPNOTSUPP;
980 if (copy_from_user(&edata, useraddr, sizeof(edata)))
981 return -EFAULT;
982 if (edata.data && !(dev->features & NETIF_F_SG))
983 return -EINVAL;
984 if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
985 return -EINVAL;
986 return dev->ethtool_ops->set_ufo(dev, edata.data);
989 static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
991 struct ethtool_value edata = { ETHTOOL_GGSO };
993 edata.data = dev->features & NETIF_F_GSO;
994 if (copy_to_user(useraddr, &edata, sizeof(edata)))
995 return -EFAULT;
996 return 0;
999 static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
1001 struct ethtool_value edata;
1003 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1004 return -EFAULT;
1005 if (edata.data)
1006 dev->features |= NETIF_F_GSO;
1007 else
1008 dev->features &= ~NETIF_F_GSO;
1009 return 0;
1012 static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
1014 struct ethtool_value edata = { ETHTOOL_GGRO };
1016 edata.data = dev->features & NETIF_F_GRO;
1017 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1018 return -EFAULT;
1019 return 0;
1022 static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
1024 struct ethtool_value edata;
1026 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1027 return -EFAULT;
1029 if (edata.data) {
1030 if (!dev->ethtool_ops->get_rx_csum ||
1031 !dev->ethtool_ops->get_rx_csum(dev))
1032 return -EINVAL;
1033 dev->features |= NETIF_F_GRO;
1034 } else
1035 dev->features &= ~NETIF_F_GRO;
1037 return 0;
1040 static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
1042 struct ethtool_test test;
1043 const struct ethtool_ops *ops = dev->ethtool_ops;
1044 u64 *data;
1045 int ret, test_len;
1047 if (!ops->self_test || !ops->get_sset_count)
1048 return -EOPNOTSUPP;
1050 test_len = ops->get_sset_count(dev, ETH_SS_TEST);
1051 if (test_len < 0)
1052 return test_len;
1053 WARN_ON(test_len == 0);
1055 if (copy_from_user(&test, useraddr, sizeof(test)))
1056 return -EFAULT;
1058 test.len = test_len;
1059 data = kmalloc(test_len * sizeof(u64), GFP_USER);
1060 if (!data)
1061 return -ENOMEM;
1063 ops->self_test(dev, &test, data);
1065 ret = -EFAULT;
1066 if (copy_to_user(useraddr, &test, sizeof(test)))
1067 goto out;
1068 useraddr += sizeof(test);
1069 if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
1070 goto out;
1071 ret = 0;
1073 out:
1074 kfree(data);
1075 return ret;
1078 static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
1080 struct ethtool_gstrings gstrings;
1081 const struct ethtool_ops *ops = dev->ethtool_ops;
1082 u8 *data;
1083 int ret;
1085 if (!ops->get_strings || !ops->get_sset_count)
1086 return -EOPNOTSUPP;
1088 if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
1089 return -EFAULT;
1091 ret = ops->get_sset_count(dev, gstrings.string_set);
1092 if (ret < 0)
1093 return ret;
1095 gstrings.len = ret;
1097 data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
1098 if (!data)
1099 return -ENOMEM;
1101 ops->get_strings(dev, gstrings.string_set, data);
1103 ret = -EFAULT;
1104 if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
1105 goto out;
1106 useraddr += sizeof(gstrings);
1107 if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
1108 goto out;
1109 ret = 0;
1111 out:
1112 kfree(data);
1113 return ret;
1116 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
1118 struct ethtool_value id;
1120 if (!dev->ethtool_ops->phys_id)
1121 return -EOPNOTSUPP;
1123 if (copy_from_user(&id, useraddr, sizeof(id)))
1124 return -EFAULT;
1126 return dev->ethtool_ops->phys_id(dev, id.data);
1129 static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
1131 struct ethtool_stats stats;
1132 const struct ethtool_ops *ops = dev->ethtool_ops;
1133 u64 *data;
1134 int ret, n_stats;
1136 if (!ops->get_ethtool_stats || !ops->get_sset_count)
1137 return -EOPNOTSUPP;
1139 n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
1140 if (n_stats < 0)
1141 return n_stats;
1142 WARN_ON(n_stats == 0);
1144 if (copy_from_user(&stats, useraddr, sizeof(stats)))
1145 return -EFAULT;
1147 stats.n_stats = n_stats;
1148 data = kmalloc(n_stats * sizeof(u64), GFP_USER);
1149 if (!data)
1150 return -ENOMEM;
1152 ops->get_ethtool_stats(dev, &stats, data);
1154 ret = -EFAULT;
1155 if (copy_to_user(useraddr, &stats, sizeof(stats)))
1156 goto out;
1157 useraddr += sizeof(stats);
1158 if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
1159 goto out;
1160 ret = 0;
1162 out:
1163 kfree(data);
1164 return ret;
1167 static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
1169 struct ethtool_perm_addr epaddr;
1171 if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
1172 return -EFAULT;
1174 if (epaddr.size < dev->addr_len)
1175 return -ETOOSMALL;
1176 epaddr.size = dev->addr_len;
1178 if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
1179 return -EFAULT;
1180 useraddr += sizeof(epaddr);
1181 if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
1182 return -EFAULT;
1183 return 0;
1186 static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
1187 u32 cmd, u32 (*actor)(struct net_device *))
1189 struct ethtool_value edata = { .cmd = cmd };
1191 if (!actor)
1192 return -EOPNOTSUPP;
1194 edata.data = actor(dev);
1196 if (copy_to_user(useraddr, &edata, sizeof(edata)))
1197 return -EFAULT;
1198 return 0;
1201 static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
1202 void (*actor)(struct net_device *, u32))
1204 struct ethtool_value edata;
1206 if (!actor)
1207 return -EOPNOTSUPP;
1209 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1210 return -EFAULT;
1212 actor(dev, edata.data);
1213 return 0;
1216 static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
1217 int (*actor)(struct net_device *, u32))
1219 struct ethtool_value edata;
1221 if (!actor)
1222 return -EOPNOTSUPP;
1224 if (copy_from_user(&edata, useraddr, sizeof(edata)))
1225 return -EFAULT;
1227 return actor(dev, edata.data);
1231 * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
1233 static noinline int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
1235 struct ethtool_flash efl;
1237 if (copy_from_user(&efl, useraddr, sizeof(efl)))
1238 return -EFAULT;
1240 if (!dev->ethtool_ops->flash_device)
1241 return -EOPNOTSUPP;
1243 return dev->ethtool_ops->flash_device(dev, &efl);
1246 /* The main entry point in this file. Called from net/core/dev.c */
1248 int dev_ethtool(struct net *net, struct ifreq *ifr)
1250 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
1251 void __user *useraddr = ifr->ifr_data;
1252 u32 ethcmd;
1253 int rc;
1254 unsigned long old_features;
1256 if (!dev || !netif_device_present(dev))
1257 return -ENODEV;
1259 if (!dev->ethtool_ops)
1260 return -EOPNOTSUPP;
1262 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
1263 return -EFAULT;
1265 /* Allow some commands to be done by anyone */
1266 switch(ethcmd) {
1267 case ETHTOOL_GDRVINFO:
1268 case ETHTOOL_GMSGLVL:
1269 case ETHTOOL_GCOALESCE:
1270 case ETHTOOL_GRINGPARAM:
1271 case ETHTOOL_GPAUSEPARAM:
1272 case ETHTOOL_GRXCSUM:
1273 case ETHTOOL_GTXCSUM:
1274 case ETHTOOL_GSG:
1275 case ETHTOOL_GSTRINGS:
1276 case ETHTOOL_GTSO:
1277 case ETHTOOL_GPERMADDR:
1278 case ETHTOOL_GUFO:
1279 case ETHTOOL_GGSO:
1280 case ETHTOOL_GGRO:
1281 case ETHTOOL_GFLAGS:
1282 case ETHTOOL_GPFLAGS:
1283 case ETHTOOL_GRXFH:
1284 case ETHTOOL_GRXRINGS:
1285 case ETHTOOL_GRXCLSRLCNT:
1286 case ETHTOOL_GRXCLSRULE:
1287 case ETHTOOL_GRXCLSRLALL:
1288 break;
1289 default:
1290 if (!capable(CAP_NET_ADMIN))
1291 return -EPERM;
1294 if (dev->ethtool_ops->begin)
1295 if ((rc = dev->ethtool_ops->begin(dev)) < 0)
1296 return rc;
1298 old_features = dev->features;
1300 switch (ethcmd) {
1301 case ETHTOOL_GSET:
1302 rc = ethtool_get_settings(dev, useraddr);
1303 break;
1304 case ETHTOOL_SSET:
1305 rc = ethtool_set_settings(dev, useraddr);
1306 break;
1307 case ETHTOOL_GDRVINFO:
1308 rc = ethtool_get_drvinfo(dev, useraddr);
1309 break;
1310 case ETHTOOL_GREGS:
1311 rc = ethtool_get_regs(dev, useraddr);
1312 break;
1313 case ETHTOOL_GWOL:
1314 rc = ethtool_get_wol(dev, useraddr);
1315 break;
1316 case ETHTOOL_SWOL:
1317 rc = ethtool_set_wol(dev, useraddr);
1318 break;
1319 case ETHTOOL_GMSGLVL:
1320 rc = ethtool_get_value(dev, useraddr, ethcmd,
1321 dev->ethtool_ops->get_msglevel);
1322 break;
1323 case ETHTOOL_SMSGLVL:
1324 rc = ethtool_set_value_void(dev, useraddr,
1325 dev->ethtool_ops->set_msglevel);
1326 break;
1327 case ETHTOOL_NWAY_RST:
1328 rc = ethtool_nway_reset(dev);
1329 break;
1330 case ETHTOOL_GLINK:
1331 rc = ethtool_get_value(dev, useraddr, ethcmd,
1332 dev->ethtool_ops->get_link);
1333 break;
1334 case ETHTOOL_GEEPROM:
1335 rc = ethtool_get_eeprom(dev, useraddr);
1336 break;
1337 case ETHTOOL_SEEPROM:
1338 rc = ethtool_set_eeprom(dev, useraddr);
1339 break;
1340 case ETHTOOL_GCOALESCE:
1341 rc = ethtool_get_coalesce(dev, useraddr);
1342 break;
1343 case ETHTOOL_SCOALESCE:
1344 rc = ethtool_set_coalesce(dev, useraddr);
1345 break;
1346 case ETHTOOL_GRINGPARAM:
1347 rc = ethtool_get_ringparam(dev, useraddr);
1348 break;
1349 case ETHTOOL_SRINGPARAM:
1350 rc = ethtool_set_ringparam(dev, useraddr);
1351 break;
1352 case ETHTOOL_GPAUSEPARAM:
1353 rc = ethtool_get_pauseparam(dev, useraddr);
1354 break;
1355 case ETHTOOL_SPAUSEPARAM:
1356 rc = ethtool_set_pauseparam(dev, useraddr);
1357 break;
1358 case ETHTOOL_GRXCSUM:
1359 rc = ethtool_get_value(dev, useraddr, ethcmd,
1360 (dev->ethtool_ops->get_rx_csum ?
1361 dev->ethtool_ops->get_rx_csum :
1362 ethtool_op_get_rx_csum));
1363 break;
1364 case ETHTOOL_SRXCSUM:
1365 rc = ethtool_set_rx_csum(dev, useraddr);
1366 break;
1367 case ETHTOOL_GTXCSUM:
1368 rc = ethtool_get_value(dev, useraddr, ethcmd,
1369 (dev->ethtool_ops->get_tx_csum ?
1370 dev->ethtool_ops->get_tx_csum :
1371 ethtool_op_get_tx_csum));
1372 break;
1373 case ETHTOOL_STXCSUM:
1374 rc = ethtool_set_tx_csum(dev, useraddr);
1375 break;
1376 case ETHTOOL_GSG:
1377 rc = ethtool_get_value(dev, useraddr, ethcmd,
1378 (dev->ethtool_ops->get_sg ?
1379 dev->ethtool_ops->get_sg :
1380 ethtool_op_get_sg));
1381 break;
1382 case ETHTOOL_SSG:
1383 rc = ethtool_set_sg(dev, useraddr);
1384 break;
1385 case ETHTOOL_GTSO:
1386 rc = ethtool_get_value(dev, useraddr, ethcmd,
1387 (dev->ethtool_ops->get_tso ?
1388 dev->ethtool_ops->get_tso :
1389 ethtool_op_get_tso));
1390 break;
1391 case ETHTOOL_STSO:
1392 rc = ethtool_set_tso(dev, useraddr);
1393 break;
1394 case ETHTOOL_TEST:
1395 rc = ethtool_self_test(dev, useraddr);
1396 break;
1397 case ETHTOOL_GSTRINGS:
1398 rc = ethtool_get_strings(dev, useraddr);
1399 break;
1400 case ETHTOOL_PHYS_ID:
1401 rc = ethtool_phys_id(dev, useraddr);
1402 break;
1403 case ETHTOOL_GSTATS:
1404 rc = ethtool_get_stats(dev, useraddr);
1405 break;
1406 case ETHTOOL_GPERMADDR:
1407 rc = ethtool_get_perm_addr(dev, useraddr);
1408 break;
1409 case ETHTOOL_GUFO:
1410 rc = ethtool_get_value(dev, useraddr, ethcmd,
1411 (dev->ethtool_ops->get_ufo ?
1412 dev->ethtool_ops->get_ufo :
1413 ethtool_op_get_ufo));
1414 break;
1415 case ETHTOOL_SUFO:
1416 rc = ethtool_set_ufo(dev, useraddr);
1417 break;
1418 case ETHTOOL_GGSO:
1419 rc = ethtool_get_gso(dev, useraddr);
1420 break;
1421 case ETHTOOL_SGSO:
1422 rc = ethtool_set_gso(dev, useraddr);
1423 break;
1424 case ETHTOOL_GFLAGS:
1425 rc = ethtool_get_value(dev, useraddr, ethcmd,
1426 (dev->ethtool_ops->get_flags ?
1427 dev->ethtool_ops->get_flags :
1428 ethtool_op_get_flags));
1429 break;
1430 case ETHTOOL_SFLAGS:
1431 rc = ethtool_set_value(dev, useraddr,
1432 dev->ethtool_ops->set_flags);
1433 break;
1434 case ETHTOOL_GPFLAGS:
1435 rc = ethtool_get_value(dev, useraddr, ethcmd,
1436 dev->ethtool_ops->get_priv_flags);
1437 break;
1438 case ETHTOOL_SPFLAGS:
1439 rc = ethtool_set_value(dev, useraddr,
1440 dev->ethtool_ops->set_priv_flags);
1441 break;
1442 case ETHTOOL_GRXFH:
1443 case ETHTOOL_GRXRINGS:
1444 case ETHTOOL_GRXCLSRLCNT:
1445 case ETHTOOL_GRXCLSRULE:
1446 case ETHTOOL_GRXCLSRLALL:
1447 rc = ethtool_get_rxnfc(dev, useraddr);
1448 break;
1449 case ETHTOOL_SRXFH:
1450 case ETHTOOL_SRXCLSRLDEL:
1451 case ETHTOOL_SRXCLSRLINS:
1452 rc = ethtool_set_rxnfc(dev, useraddr);
1453 break;
1454 case ETHTOOL_GGRO:
1455 rc = ethtool_get_gro(dev, useraddr);
1456 break;
1457 case ETHTOOL_SGRO:
1458 rc = ethtool_set_gro(dev, useraddr);
1459 break;
1460 case ETHTOOL_FLASHDEV:
1461 rc = ethtool_flash_device(dev, useraddr);
1462 break;
1463 case ETHTOOL_RESET:
1464 rc = ethtool_reset(dev, useraddr);
1465 break;
1466 case ETHTOOL_SRXNTUPLE:
1467 rc = ethtool_set_rx_ntuple(dev, useraddr);
1468 break;
1469 case ETHTOOL_GRXNTUPLE:
1470 rc = ethtool_get_rx_ntuple(dev, useraddr);
1471 break;
1472 default:
1473 rc = -EOPNOTSUPP;
1476 if (dev->ethtool_ops->complete)
1477 dev->ethtool_ops->complete(dev);
1479 if (old_features != dev->features)
1480 netdev_features_change(dev);
1482 return rc;
1485 EXPORT_SYMBOL(ethtool_op_get_link);
1486 EXPORT_SYMBOL(ethtool_op_get_sg);
1487 EXPORT_SYMBOL(ethtool_op_get_tso);
1488 EXPORT_SYMBOL(ethtool_op_set_sg);
1489 EXPORT_SYMBOL(ethtool_op_set_tso);
1490 EXPORT_SYMBOL(ethtool_op_set_tx_csum);
1491 EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
1492 EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
1493 EXPORT_SYMBOL(ethtool_op_set_ufo);
1494 EXPORT_SYMBOL(ethtool_op_get_ufo);
1495 EXPORT_SYMBOL(ethtool_op_set_flags);
1496 EXPORT_SYMBOL(ethtool_op_get_flags);