aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-08-15 19:01:56 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:48:09 -0400
commit13c99b248f06e0b71d925f162d8e3b0084886a21 (patch)
treed1fa5d91673a3325eea68487838d53f156f99e0c /net/core
parent339bf024756690949f536777b921f34186eaa8b4 (diff)
[ETHTOOL]: Internal cleanup of ethtool_value-related handlers
Several get/set functions can be handled by a passing the ethtool_op function pointer directly to a generic function. This permits deletion of a fair bit of redundant code. Signed-off-by: Jeff Garzik <jeff@garzik.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/ethtool.c199
1 files changed, 39 insertions, 160 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index d255209dc110..7c43f032a7f9 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -272,34 +272,6 @@ static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
272 return dev->ethtool_ops->set_wol(dev, &wol); 272 return dev->ethtool_ops->set_wol(dev, &wol);
273} 273}
274 274
275static int ethtool_get_msglevel(struct net_device *dev, char __user *useraddr)
276{
277 struct ethtool_value edata = { ETHTOOL_GMSGLVL };
278
279 if (!dev->ethtool_ops->get_msglevel)
280 return -EOPNOTSUPP;
281
282 edata.data = dev->ethtool_ops->get_msglevel(dev);
283
284 if (copy_to_user(useraddr, &edata, sizeof(edata)))
285 return -EFAULT;
286 return 0;
287}
288
289static int ethtool_set_msglevel(struct net_device *dev, char __user *useraddr)
290{
291 struct ethtool_value edata;
292
293 if (!dev->ethtool_ops->set_msglevel)
294 return -EOPNOTSUPP;
295
296 if (copy_from_user(&edata, useraddr, sizeof(edata)))
297 return -EFAULT;
298
299 dev->ethtool_ops->set_msglevel(dev, edata.data);
300 return 0;
301}
302
303static int ethtool_nway_reset(struct net_device *dev) 275static int ethtool_nway_reset(struct net_device *dev)
304{ 276{
305 if (!dev->ethtool_ops->nway_reset) 277 if (!dev->ethtool_ops->nway_reset)
@@ -308,20 +280,6 @@ static int ethtool_nway_reset(struct net_device *dev)
308 return dev->ethtool_ops->nway_reset(dev); 280 return dev->ethtool_ops->nway_reset(dev);
309} 281}
310 282
311static int ethtool_get_link(struct net_device *dev, void __user *useraddr)
312{
313 struct ethtool_value edata = { ETHTOOL_GLINK };
314
315 if (!dev->ethtool_ops->get_link)
316 return -EOPNOTSUPP;
317
318 edata.data = dev->ethtool_ops->get_link(dev);
319
320 if (copy_to_user(useraddr, &edata, sizeof(edata)))
321 return -EFAULT;
322 return 0;
323}
324
325static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr) 283static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
326{ 284{
327 struct ethtool_eeprom eeprom; 285 struct ethtool_eeprom eeprom;
@@ -489,48 +447,6 @@ static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
489 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam); 447 return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
490} 448}
491 449
492static int ethtool_get_rx_csum(struct net_device *dev, char __user *useraddr)
493{
494 struct ethtool_value edata = { ETHTOOL_GRXCSUM };
495
496 if (!dev->ethtool_ops->get_rx_csum)
497 return -EOPNOTSUPP;
498
499 edata.data = dev->ethtool_ops->get_rx_csum(dev);
500
501 if (copy_to_user(useraddr, &edata, sizeof(edata)))
502 return -EFAULT;
503 return 0;
504}
505
506static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
507{
508 struct ethtool_value edata;
509
510 if (!dev->ethtool_ops->set_rx_csum)
511 return -EOPNOTSUPP;
512
513 if (copy_from_user(&edata, useraddr, sizeof(edata)))
514 return -EFAULT;
515
516 dev->ethtool_ops->set_rx_csum(dev, edata.data);
517 return 0;
518}
519
520static int ethtool_get_tx_csum(struct net_device *dev, char __user *useraddr)
521{
522 struct ethtool_value edata = { ETHTOOL_GTXCSUM };
523
524 if (!dev->ethtool_ops->get_tx_csum)
525 return -EOPNOTSUPP;
526
527 edata.data = dev->ethtool_ops->get_tx_csum(dev);
528
529 if (copy_to_user(useraddr, &edata, sizeof(edata)))
530 return -EFAULT;
531 return 0;
532}
533
534static int __ethtool_set_sg(struct net_device *dev, u32 data) 450static int __ethtool_set_sg(struct net_device *dev, u32 data)
535{ 451{
536 int err; 452 int err;
@@ -569,20 +485,6 @@ static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
569 return dev->ethtool_ops->set_tx_csum(dev, edata.data); 485 return dev->ethtool_ops->set_tx_csum(dev, edata.data);
570} 486}
571 487
572static int ethtool_get_sg(struct net_device *dev, char __user *useraddr)
573{
574 struct ethtool_value edata = { ETHTOOL_GSG };
575
576 if (!dev->ethtool_ops->get_sg)
577 return -EOPNOTSUPP;
578
579 edata.data = dev->ethtool_ops->get_sg(dev);
580
581 if (copy_to_user(useraddr, &edata, sizeof(edata)))
582 return -EFAULT;
583 return 0;
584}
585
586static int ethtool_set_sg(struct net_device *dev, char __user *useraddr) 488static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
587{ 489{
588 struct ethtool_value edata; 490 struct ethtool_value edata;
@@ -600,20 +502,6 @@ static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
600 return __ethtool_set_sg(dev, edata.data); 502 return __ethtool_set_sg(dev, edata.data);
601} 503}
602 504
603static int ethtool_get_tso(struct net_device *dev, char __user *useraddr)
604{
605 struct ethtool_value edata = { ETHTOOL_GTSO };
606
607 if (!dev->ethtool_ops->get_tso)
608 return -EOPNOTSUPP;
609
610 edata.data = dev->ethtool_ops->get_tso(dev);
611
612 if (copy_to_user(useraddr, &edata, sizeof(edata)))
613 return -EFAULT;
614 return 0;
615}
616
617static int ethtool_set_tso(struct net_device *dev, char __user *useraddr) 505static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
618{ 506{
619 struct ethtool_value edata; 507 struct ethtool_value edata;
@@ -630,18 +518,6 @@ static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
630 return dev->ethtool_ops->set_tso(dev, edata.data); 518 return dev->ethtool_ops->set_tso(dev, edata.data);
631} 519}
632 520
633static int ethtool_get_ufo(struct net_device *dev, char __user *useraddr)
634{
635 struct ethtool_value edata = { ETHTOOL_GUFO };
636
637 if (!dev->ethtool_ops->get_ufo)
638 return -EOPNOTSUPP;
639 edata.data = dev->ethtool_ops->get_ufo(dev);
640 if (copy_to_user(useraddr, &edata, sizeof(edata)))
641 return -EFAULT;
642 return 0;
643}
644
645static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr) 521static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
646{ 522{
647 struct ethtool_value edata; 523 struct ethtool_value edata;
@@ -857,58 +733,48 @@ static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
857 return 0; 733 return 0;
858} 734}
859 735
860static int ethtool_get_flags(struct net_device *dev, char __user *useraddr) 736static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
737 u32 cmd, u32 (*actor)(struct net_device *))
861{ 738{
862 struct ethtool_value edata = { ETHTOOL_GFLAGS }; 739 struct ethtool_value edata = { cmd };
863 740
864 if (!dev->ethtool_ops->get_flags) 741 if (!actor)
865 return -EOPNOTSUPP; 742 return -EOPNOTSUPP;
866 743
867 edata.data = dev->ethtool_ops->get_flags(dev); 744 edata.data = actor(dev);
868 745
869 if (copy_to_user(useraddr, &edata, sizeof(edata))) 746 if (copy_to_user(useraddr, &edata, sizeof(edata)))
870 return -EFAULT; 747 return -EFAULT;
871 return 0; 748 return 0;
872} 749}
873 750
874static int ethtool_set_flags(struct net_device *dev, char __user *useraddr) 751static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
752 void (*actor)(struct net_device *, u32))
875{ 753{
876 struct ethtool_value edata; 754 struct ethtool_value edata;
877 755
878 if (!dev->ethtool_ops->set_flags) 756 if (!actor)
879 return -EOPNOTSUPP; 757 return -EOPNOTSUPP;
880 758
881 if (copy_from_user(&edata, useraddr, sizeof(edata))) 759 if (copy_from_user(&edata, useraddr, sizeof(edata)))
882 return -EFAULT; 760 return -EFAULT;
883 761
884 return dev->ethtool_ops->set_flags(dev, edata.data); 762 actor(dev, edata.data);
885}
886
887static int ethtool_get_priv_flags(struct net_device *dev, char __user *useraddr)
888{
889 struct ethtool_value edata = { ETHTOOL_GPFLAGS };
890
891 if (!dev->ethtool_ops->get_priv_flags)
892 return -EOPNOTSUPP;
893
894 edata.data = dev->ethtool_ops->get_priv_flags(dev);
895
896 if (copy_to_user(useraddr, &edata, sizeof(edata)))
897 return -EFAULT;
898 return 0; 763 return 0;
899} 764}
900 765
901static int ethtool_set_priv_flags(struct net_device *dev, char __user *useraddr) 766static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
767 int (*actor)(struct net_device *, u32))
902{ 768{
903 struct ethtool_value edata; 769 struct ethtool_value edata;
904 770
905 if (!dev->ethtool_ops->set_priv_flags) 771 if (!actor)
906 return -EOPNOTSUPP; 772 return -EOPNOTSUPP;
907 773
908 if (copy_from_user(&edata, useraddr, sizeof(edata))) 774 if (copy_from_user(&edata, useraddr, sizeof(edata)))
909 return -EFAULT; 775 return -EFAULT;
910 776
911 return dev->ethtool_ops->set_priv_flags(dev, edata.data); 777 return actor(dev, edata.data);
912} 778}
913 779
914/* The main entry point in this file. Called from net/core/dev.c */ 780/* The main entry point in this file. Called from net/core/dev.c */
@@ -979,16 +845,19 @@ int dev_ethtool(struct ifreq *ifr)
979 rc = ethtool_set_wol(dev, useraddr); 845 rc = ethtool_set_wol(dev, useraddr);
980 break; 846 break;
981 case ETHTOOL_GMSGLVL: 847 case ETHTOOL_GMSGLVL:
982 rc = ethtool_get_msglevel(dev, useraddr); 848 rc = ethtool_get_value(dev, useraddr, ethcmd,
849 dev->ethtool_ops->get_msglevel);
983 break; 850 break;
984 case ETHTOOL_SMSGLVL: 851 case ETHTOOL_SMSGLVL:
985 rc = ethtool_set_msglevel(dev, useraddr); 852 rc = ethtool_set_value_void(dev, useraddr,
853 dev->ethtool_ops->set_msglevel);
986 break; 854 break;
987 case ETHTOOL_NWAY_RST: 855 case ETHTOOL_NWAY_RST:
988 rc = ethtool_nway_reset(dev); 856 rc = ethtool_nway_reset(dev);
989 break; 857 break;
990 case ETHTOOL_GLINK: 858 case ETHTOOL_GLINK:
991 rc = ethtool_get_link(dev, useraddr); 859 rc = ethtool_get_value(dev, useraddr, ethcmd,
860 dev->ethtool_ops->get_link);
992 break; 861 break;
993 case ETHTOOL_GEEPROM: 862 case ETHTOOL_GEEPROM:
994 rc = ethtool_get_eeprom(dev, useraddr); 863 rc = ethtool_get_eeprom(dev, useraddr);
@@ -1015,25 +884,30 @@ int dev_ethtool(struct ifreq *ifr)
1015 rc = ethtool_set_pauseparam(dev, useraddr); 884 rc = ethtool_set_pauseparam(dev, useraddr);
1016 break; 885 break;
1017 case ETHTOOL_GRXCSUM: 886 case ETHTOOL_GRXCSUM:
1018 rc = ethtool_get_rx_csum(dev, useraddr); 887 rc = ethtool_get_value(dev, useraddr, ethcmd,
888 dev->ethtool_ops->get_rx_csum);
1019 break; 889 break;
1020 case ETHTOOL_SRXCSUM: 890 case ETHTOOL_SRXCSUM:
1021 rc = ethtool_set_rx_csum(dev, useraddr); 891 rc = ethtool_set_value(dev, useraddr,
892 dev->ethtool_ops->set_rx_csum);
1022 break; 893 break;
1023 case ETHTOOL_GTXCSUM: 894 case ETHTOOL_GTXCSUM:
1024 rc = ethtool_get_tx_csum(dev, useraddr); 895 rc = ethtool_get_value(dev, useraddr, ethcmd,
896 dev->ethtool_ops->get_tx_csum);
1025 break; 897 break;
1026 case ETHTOOL_STXCSUM: 898 case ETHTOOL_STXCSUM:
1027 rc = ethtool_set_tx_csum(dev, useraddr); 899 rc = ethtool_set_tx_csum(dev, useraddr);
1028 break; 900 break;
1029 case ETHTOOL_GSG: 901 case ETHTOOL_GSG:
1030 rc = ethtool_get_sg(dev, useraddr); 902 rc = ethtool_get_value(dev, useraddr, ethcmd,
903 dev->ethtool_ops->get_sg);
1031 break; 904 break;
1032 case ETHTOOL_SSG: 905 case ETHTOOL_SSG:
1033 rc = ethtool_set_sg(dev, useraddr); 906 rc = ethtool_set_sg(dev, useraddr);
1034 break; 907 break;
1035 case ETHTOOL_GTSO: 908 case ETHTOOL_GTSO:
1036 rc = ethtool_get_tso(dev, useraddr); 909 rc = ethtool_get_value(dev, useraddr, ethcmd,
910 dev->ethtool_ops->get_tso);
1037 break; 911 break;
1038 case ETHTOOL_STSO: 912 case ETHTOOL_STSO:
1039 rc = ethtool_set_tso(dev, useraddr); 913 rc = ethtool_set_tso(dev, useraddr);
@@ -1054,7 +928,8 @@ int dev_ethtool(struct ifreq *ifr)
1054 rc = ethtool_get_perm_addr(dev, useraddr); 928 rc = ethtool_get_perm_addr(dev, useraddr);
1055 break; 929 break;
1056 case ETHTOOL_GUFO: 930 case ETHTOOL_GUFO:
1057 rc = ethtool_get_ufo(dev, useraddr); 931 rc = ethtool_get_value(dev, useraddr, ethcmd,
932 dev->ethtool_ops->get_ufo);
1058 break; 933 break;
1059 case ETHTOOL_SUFO: 934 case ETHTOOL_SUFO:
1060 rc = ethtool_set_ufo(dev, useraddr); 935 rc = ethtool_set_ufo(dev, useraddr);
@@ -1066,16 +941,20 @@ int dev_ethtool(struct ifreq *ifr)
1066 rc = ethtool_set_gso(dev, useraddr); 941 rc = ethtool_set_gso(dev, useraddr);
1067 break; 942 break;
1068 case ETHTOOL_GFLAGS: 943 case ETHTOOL_GFLAGS:
1069 rc = ethtool_get_flags(dev, useraddr); 944 rc = ethtool_get_value(dev, useraddr, ethcmd,
945 dev->ethtool_ops->get_flags);
1070 break; 946 break;
1071 case ETHTOOL_SFLAGS: 947 case ETHTOOL_SFLAGS:
1072 rc = ethtool_set_flags(dev, useraddr); 948 rc = ethtool_set_value(dev, useraddr,
949 dev->ethtool_ops->set_flags);
1073 break; 950 break;
1074 case ETHTOOL_GPFLAGS: 951 case ETHTOOL_GPFLAGS:
1075 rc = ethtool_get_priv_flags(dev, useraddr); 952 rc = ethtool_get_value(dev, useraddr, ethcmd,
953 dev->ethtool_ops->get_priv_flags);
1076 break; 954 break;
1077 case ETHTOOL_SPFLAGS: 955 case ETHTOOL_SPFLAGS:
1078 rc = ethtool_set_priv_flags(dev, useraddr); 956 rc = ethtool_set_value(dev, useraddr,
957 dev->ethtool_ops->set_priv_flags);
1079 break; 958 break;
1080 default: 959 default:
1081 rc = -EOPNOTSUPP; 960 rc = -EOPNOTSUPP;