problem with ethtool API

Konstantinos Koukopoulos <[email protected]> Mon, 24 Jan 2005 11:57:37 +0200
Newsgroups gmane.linux.drivers.eepro100.devel,gmane.linux.drivers.eepro100.user
Organization University of Athens
Message-ID <[email protected]>
--Boundary-00=_SaM9BY49YdeHruy
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello,
I'm running kernel 2.6.8 from Debian on a thinkpad R40. I'm sorry if this 
problem has been officialy fixed in a later kernel version.

I first noticed this problem when I tried to run ifplugd [1] in a mode where 
it uses the ethtool api to monitor the link status of the eepro100
card without bringing the interface up (-a). 

The daemon would detect the link going up fine. When I would remove the cable  
it would momentarily say that the link went down and then immediately say 
that the link went up again. Of course the cable was still unplugged but 
ifplugd would try, unsuccesfully, to bring the network up and then remain in 
the "link up" state.

By explicitly telling ifplugd to use the mii api the problem would go away.
I next used ethtool [2] and discovered that it too would report the link 
status as still being up after I had unplugged the cable. Mii-tool (from 
net-tools package) on the other hand would correctly report the link status 
as down. Interestingly, after running mii-tool, ethtool would report the 
correct link status. 

To summarize, after unplugging the network cable, programs that use 
SIOCETHTOOL falsely report the link status as up, while programs that use the 
SIOCGMIIREG  api report it correctly, causing subsequent ETHTOOL_GLINK 
ethtool ioctls to work from then on.

Although I doubt I have found the correct solution, I have attached a patch 
that fixes the problem for me. I would be interested in an expanation of the 
problem and what a better solution might be.

Thank you for your time,
Kostas Koukopoulos

P.S. please CC me in your response as I am not subscribed to the list

1.  http://www.stud.uni-hamburg.de/users/lennart/projects/ifplugd/
2.  http://sourceforge.net/projects/gkernel/

--Boundary-00=_SaM9BY49YdeHruy
Content-Type: text/x-diff;
  charset="us-ascii";
  name="eepro100.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="eepro100.c.diff"

--- eepro100.c	2004-08-14 08:37:25.000000000 +0300
+++ eepro100.c.kouk	2005-01-22 18:47:23.000000000 +0200
@@ -2094,6 +2094,7 @@
 	int phy = sp->phy[0] & 0x1f;
 	int saved_acpi;
 	int t;
+   int ret;
 
     switch(cmd) {
 	case SIOCGMIIPHY:		/* Get address of MII PHY in use. */
@@ -2123,7 +2124,13 @@
 		pci_set_power_state(sp->pdev, saved_acpi);
 		return 0;
 	case SIOCETHTOOL:
-		return netdev_ethtool_ioctl(dev, rq->ifr_data);
+		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		t = del_timer_sync(&sp->timer);
+		ret =  netdev_ethtool_ioctl(dev, rq->ifr_data);
+		if (t)
+			add_timer(&sp->timer); /* may be set to the past  --SAW */
+		pci_set_power_state(sp->pdev, saved_acpi);
+      return ret;
 	default:
 		return -EOPNOTSUPP;
 	}

--Boundary-00=_SaM9BY49YdeHruy
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
eepro100 mailing list
[email protected]
http://www.scyld.com/mailman/listinfo/eepro100

--Boundary-00=_SaM9BY49YdeHruy--