aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <matthew@wil.cx>2007-07-31 17:00:02 -0400
committerDavid S. Miller <davem@davemloft.net>2007-07-31 17:00:02 -0400
commit61a44b9c4b20d40c41fd1b70a4ceb13b75ea79a4 (patch)
tree26c97ff8b3b5e3827ba927bf5738baa092146d85
parentf1543f8b8316f49b318ac6cd8c78a7fd18509311 (diff)
[NET]: ethtool ops are the only way
During the transition to the ethtool_ops way of doing things, we supported calling the device's ->do_ioctl method to allow unconverted drivers to continue working. Those days are long behind us, all in-tree drivers use the ethtool_ops way, and so we no longer need to support this. The bonding driver is the biggest beneficiary of this; it no longer needs to call ioctl() as a fallback if ethtool_ops aren't supported. Also put a proper copyright statement on ethtool.c. Signed-off-by: Matthew Wilcox <matthew@wil.cx> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_main.c52
-rw-r--r--net/8021q/vlan_dev.c3
-rw-r--r--net/bridge/br_if.c41
-rw-r--r--net/core/ethtool.c21
4 files changed, 32 insertions, 85 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index cb9cb3013f42..070b78d959cc 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -613,38 +613,20 @@ down:
613static int bond_update_speed_duplex(struct slave *slave) 613static int bond_update_speed_duplex(struct slave *slave)
614{ 614{
615 struct net_device *slave_dev = slave->dev; 615 struct net_device *slave_dev = slave->dev;
616 static int (* ioctl)(struct net_device *, struct ifreq *, int);
617 struct ifreq ifr;
618 struct ethtool_cmd etool; 616 struct ethtool_cmd etool;
617 int res;
619 618
620 /* Fake speed and duplex */ 619 /* Fake speed and duplex */
621 slave->speed = SPEED_100; 620 slave->speed = SPEED_100;
622 slave->duplex = DUPLEX_FULL; 621 slave->duplex = DUPLEX_FULL;
623 622
624 if (slave_dev->ethtool_ops) { 623 if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings)
625 int res; 624 return -1;
626
627 if (!slave_dev->ethtool_ops->get_settings) {
628 return -1;
629 }
630
631 res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
632 if (res < 0) {
633 return -1;
634 }
635
636 goto verify;
637 }
638 625
639 ioctl = slave_dev->do_ioctl; 626 res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
640 strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ); 627 if (res < 0)
641 etool.cmd = ETHTOOL_GSET;
642 ifr.ifr_data = (char*)&etool;
643 if (!ioctl || (IOCTL(slave_dev, &ifr, SIOCETHTOOL) < 0)) {
644 return -1; 628 return -1;
645 }
646 629
647verify:
648 switch (etool.speed) { 630 switch (etool.speed) {
649 case SPEED_10: 631 case SPEED_10:
650 case SPEED_100: 632 case SPEED_100:
@@ -690,7 +672,6 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
690 static int (* ioctl)(struct net_device *, struct ifreq *, int); 672 static int (* ioctl)(struct net_device *, struct ifreq *, int);
691 struct ifreq ifr; 673 struct ifreq ifr;
692 struct mii_ioctl_data *mii; 674 struct mii_ioctl_data *mii;
693 struct ethtool_value etool;
694 675
695 if (bond->params.use_carrier) { 676 if (bond->params.use_carrier) {
696 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0; 677 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
@@ -721,9 +702,10 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
721 } 702 }
722 } 703 }
723 704
724 /* try SIOCETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */ 705 /*
725 /* for a period of time so we attempt to get link status */ 706 * Some drivers cache ETHTOOL_GLINK for a period of time so we only
726 /* from it last if the above MII ioctls fail... */ 707 * attempt to get link status from it if the above MII ioctls fail.
708 */
727 if (slave_dev->ethtool_ops) { 709 if (slave_dev->ethtool_ops) {
728 if (slave_dev->ethtool_ops->get_link) { 710 if (slave_dev->ethtool_ops->get_link) {
729 u32 link; 711 u32 link;
@@ -734,23 +716,9 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
734 } 716 }
735 } 717 }
736 718
737 if (ioctl) {
738 strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
739 etool.cmd = ETHTOOL_GLINK;
740 ifr.ifr_data = (char*)&etool;
741 if (IOCTL(slave_dev, &ifr, SIOCETHTOOL) == 0) {
742 if (etool.data == 1) {
743 return BMSR_LSTATUS;
744 } else {
745 dprintk("SIOCETHTOOL shows link down\n");
746 return 0;
747 }
748 }
749 }
750
751 /* 719 /*
752 * If reporting, report that either there's no dev->do_ioctl, 720 * If reporting, report that either there's no dev->do_ioctl,
753 * or both SIOCGMIIREG and SIOCETHTOOL failed (meaning that we 721 * or both SIOCGMIIREG and get_link failed (meaning that we
754 * cannot report link status). If not reporting, pretend 722 * cannot report link status). If not reporting, pretend
755 * we're ok. 723 * we're ok.
756 */ 724 */
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 4d2aa4dd42ac..4bab322c9f8f 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -668,9 +668,6 @@ int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
668 if (real_dev->do_ioctl && netif_device_present(real_dev)) 668 if (real_dev->do_ioctl && netif_device_present(real_dev))
669 err = real_dev->do_ioctl(real_dev, &ifrr, cmd); 669 err = real_dev->do_ioctl(real_dev, &ifrr, cmd);
670 break; 670 break;
671
672 case SIOCETHTOOL:
673 err = dev_ethtool(&ifrr);
674 } 671 }
675 672
676 if (!err) 673 if (!err)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 7b4ce9113be2..b40dada002bf 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -29,35 +29,24 @@
29 * Determine initial path cost based on speed. 29 * Determine initial path cost based on speed.
30 * using recommendations from 802.1d standard 30 * using recommendations from 802.1d standard
31 * 31 *
32 * Need to simulate user ioctl because not all device's that support 32 * Since driver might sleep need to not be holding any locks.
33 * ethtool, use ethtool_ops. Also, since driver might sleep need to
34 * not be holding any locks.
35 */ 33 */
36static int port_cost(struct net_device *dev) 34static int port_cost(struct net_device *dev)
37{ 35{
38 struct ethtool_cmd ecmd = { ETHTOOL_GSET }; 36 if (dev->ethtool_ops->get_settings) {
39 struct ifreq ifr; 37 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
40 mm_segment_t old_fs; 38 int err = dev->ethtool_ops->get_settings(dev, &ecmd);
41 int err; 39 if (!err) {
42 40 switch(ecmd.speed) {
43 strncpy(ifr.ifr_name, dev->name, IFNAMSIZ); 41 case SPEED_100:
44 ifr.ifr_data = (void __user *) &ecmd; 42 return 19;
45 43 case SPEED_1000:
46 old_fs = get_fs(); 44 return 4;
47 set_fs(KERNEL_DS); 45 case SPEED_10000:
48 err = dev_ethtool(&ifr); 46 return 2;
49 set_fs(old_fs); 47 case SPEED_10:
50 48 return 100;
51 if (!err) { 49 }
52 switch(ecmd.speed) {
53 case SPEED_100:
54 return 19;
55 case SPEED_1000:
56 return 4;
57 case SPEED_10000:
58 return 2;
59 case SPEED_10:
60 return 100;
61 } 50 }
62 } 51 }
63 52
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 0b531e98ec33..2bf565e8d0b3 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -3,10 +3,12 @@
3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx> 3 * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
4 * 4 *
5 * This file is where we call all the ethtool_ops commands to get 5 * This file is where we call all the ethtool_ops commands to get
6 * the information ethtool needs. We fall back to calling do_ioctl() 6 * the information ethtool needs.
7 * for drivers which haven't been converted to ethtool_ops yet.
8 * 7 *
9 * It's GPL, stupid. 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.
10 */ 12 */
11 13
12#include <linux/module.h> 14#include <linux/module.h>
@@ -821,7 +823,7 @@ int dev_ethtool(struct ifreq *ifr)
821 return -ENODEV; 823 return -ENODEV;
822 824
823 if (!dev->ethtool_ops) 825 if (!dev->ethtool_ops)
824 goto ioctl; 826 return -EOPNOTSUPP;
825 827
826 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd))) 828 if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
827 return -EFAULT; 829 return -EFAULT;
@@ -960,7 +962,7 @@ int dev_ethtool(struct ifreq *ifr)
960 rc = ethtool_set_gso(dev, useraddr); 962 rc = ethtool_set_gso(dev, useraddr);
961 break; 963 break;
962 default: 964 default:
963 rc = -EOPNOTSUPP; 965 rc = -EOPNOTSUPP;
964 } 966 }
965 967
966 if (dev->ethtool_ops->complete) 968 if (dev->ethtool_ops->complete)
@@ -970,15 +972,6 @@ int dev_ethtool(struct ifreq *ifr)
970 netdev_features_change(dev); 972 netdev_features_change(dev);
971 973
972 return rc; 974 return rc;
973
974 ioctl:
975 /* Keep existing behaviour for the moment. */
976 if (!capable(CAP_NET_ADMIN))
977 return -EPERM;
978
979 if (dev->do_ioctl)
980 return dev->do_ioctl(dev, ifr, SIOCETHTOOL);
981 return -EOPNOTSUPP;
982} 975}
983 976
984EXPORT_SYMBOL(dev_ethtool); 977EXPORT_SYMBOL(dev_ethtool);