netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 03/12] sundance: set carrier status on link change events
@ 2008-07-30 19:38 akpm
  0 siblings, 0 replies; 4+ messages in thread
From: akpm @ 2008-07-30 19:38 UTC (permalink / raw)
  To: jeff; +Cc: netdev, akpm, dbn.lists

From: Dan Nicholson <dbn.lists@gmail.com>

Check if the link is available when a changed interrupt has been received and
set the carrier status appropriately.  The code is copied nearly verbatim from
the dl2k module.  The link status could be used in more places in the driver,
but this is enough to get the carrier status reported to userspace.  Fixes
kernel bug #7487:

    http://bugzilla.kernel.org/show_bug.cgi?id=7487

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/net/sundance.c |   95 +++++++++++++++++++++++++--------------
 1 file changed, 62 insertions(+), 33 deletions(-)

diff -puN drivers/net/sundance.c~sundance-set-carrier-status-on-link-change-events drivers/net/sundance.c
--- a/drivers/net/sundance.c~sundance-set-carrier-status-on-link-change-events
+++ a/drivers/net/sundance.c
@@ -409,6 +409,7 @@ static int  change_mtu(struct net_device
 static int  eeprom_read(void __iomem *ioaddr, int location);
 static int  mdio_read(struct net_device *dev, int phy_id, int location);
 static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
+static int  mdio_wait_link(struct net_device *dev, int wait);
 static int  netdev_open(struct net_device *dev);
 static void check_duplex(struct net_device *dev);
 static void netdev_timer(unsigned long data);
@@ -785,6 +786,24 @@ static void mdio_write(struct net_device
 	return;
 }
 
+static int mdio_wait_link(struct net_device *dev, int wait)
+{
+	int bmsr;
+	int phy_id;
+	struct netdev_private *np;
+
+	np = netdev_priv(dev);
+	phy_id = np->phys[0];
+
+	do {
+		bmsr = mdio_read(dev, phy_id, MII_BMSR);
+		if (bmsr & 0x0004)
+			return 0;
+		mdelay(1);
+	} while (--wait > 0);
+	return -1;
+}
+
 static int netdev_open(struct net_device *dev)
 {
 	struct netdev_private *np = netdev_priv(dev);
@@ -1393,41 +1412,51 @@ static void netdev_error(struct net_devi
 	int speed;
 
 	if (intr_status & LinkChange) {
-		if (np->an_enable) {
-			mii_advertise = mdio_read (dev, np->phys[0], MII_ADVERTISE);
-			mii_lpa= mdio_read (dev, np->phys[0], MII_LPA);
-			mii_advertise &= mii_lpa;
-			printk (KERN_INFO "%s: Link changed: ", dev->name);
-			if (mii_advertise & ADVERTISE_100FULL) {
-				np->speed = 100;
-				printk ("100Mbps, full duplex\n");
-			} else if (mii_advertise & ADVERTISE_100HALF) {
-				np->speed = 100;
-				printk ("100Mbps, half duplex\n");
-			} else if (mii_advertise & ADVERTISE_10FULL) {
-				np->speed = 10;
-				printk ("10Mbps, full duplex\n");
-			} else if (mii_advertise & ADVERTISE_10HALF) {
-				np->speed = 10;
-				printk ("10Mbps, half duplex\n");
-			} else
-				printk ("\n");
+		if (mdio_wait_link(dev, 10) == 0) {
+			printk(KERN_INFO "%s: Link up\n", dev->name);
+			if (np->an_enable) {
+				mii_advertise = mdio_read(dev, np->phys[0],
+							   MII_ADVERTISE);
+				mii_lpa = mdio_read(dev, np->phys[0], MII_LPA);
+				mii_advertise &= mii_lpa;
+				printk(KERN_INFO "%s: Link changed: ",
+					dev->name);
+				if (mii_advertise & ADVERTISE_100FULL) {
+					np->speed = 100;
+					printk("100Mbps, full duplex\n");
+				} else if (mii_advertise & ADVERTISE_100HALF) {
+					np->speed = 100;
+					printk("100Mbps, half duplex\n");
+				} else if (mii_advertise & ADVERTISE_10FULL) {
+					np->speed = 10;
+					printk("10Mbps, full duplex\n");
+				} else if (mii_advertise & ADVERTISE_10HALF) {
+					np->speed = 10;
+					printk("10Mbps, half duplex\n");
+				} else
+					printk("\n");
 
+			} else {
+				mii_ctl = mdio_read(dev, np->phys[0], MII_BMCR);
+				speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10;
+				np->speed = speed;
+				printk(KERN_INFO "%s: Link changed: %dMbps ,",
+					dev->name, speed);
+				printk("%s duplex.\n",
+					(mii_ctl & BMCR_FULLDPLX) ?
+						"full" : "half");
+			}
+			check_duplex(dev);
+			if (np->flowctrl && np->mii_if.full_duplex) {
+				iowrite16(ioread16(ioaddr + MulticastFilter1+2) | 0x0200,
+					ioaddr + MulticastFilter1+2);
+				iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl,
+					ioaddr + MACCtrl0);
+			}
+			netif_carrier_on(dev);
 		} else {
-			mii_ctl = mdio_read (dev, np->phys[0], MII_BMCR);
-			speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10;
-			np->speed = speed;
-			printk (KERN_INFO "%s: Link changed: %dMbps ,",
-				dev->name, speed);
-			printk ("%s duplex.\n", (mii_ctl & BMCR_FULLDPLX) ?
-				"full" : "half");
-		}
-		check_duplex (dev);
-		if (np->flowctrl && np->mii_if.full_duplex) {
-			iowrite16(ioread16(ioaddr + MulticastFilter1+2) | 0x0200,
-				ioaddr + MulticastFilter1+2);
-			iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl,
-				ioaddr + MACCtrl0);
+			printk(KERN_INFO "%s: Link down\n", dev->name);
+			netif_carrier_off(dev);
 		}
 	}
 	if (intr_status & StatsMax) {
_

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [patch 03/12] sundance: set carrier status on link change events
@ 2008-08-20 23:51 akpm
  2008-09-14  0:13 ` Jeff Garzik
  0 siblings, 1 reply; 4+ messages in thread
From: akpm @ 2008-08-20 23:51 UTC (permalink / raw)
  To: jeff; +Cc: netdev, akpm, dbn.lists

From: Dan Nicholson <dbn.lists@gmail.com>

Check if the link is available when a changed interrupt has been received and
set the carrier status appropriately.  The code is copied nearly verbatim from
the dl2k module.  The link status could be used in more places in the driver,
but this is enough to get the carrier status reported to userspace.  Fixes
kernel bug #7487:

    http://bugzilla.kernel.org/show_bug.cgi?id=7487

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/net/sundance.c |   95 +++++++++++++++++++++++++--------------
 1 file changed, 62 insertions(+), 33 deletions(-)

diff -puN drivers/net/sundance.c~sundance-set-carrier-status-on-link-change-events drivers/net/sundance.c
--- a/drivers/net/sundance.c~sundance-set-carrier-status-on-link-change-events
+++ a/drivers/net/sundance.c
@@ -409,6 +409,7 @@ static int  change_mtu(struct net_device
 static int  eeprom_read(void __iomem *ioaddr, int location);
 static int  mdio_read(struct net_device *dev, int phy_id, int location);
 static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
+static int  mdio_wait_link(struct net_device *dev, int wait);
 static int  netdev_open(struct net_device *dev);
 static void check_duplex(struct net_device *dev);
 static void netdev_timer(unsigned long data);
@@ -785,6 +786,24 @@ static void mdio_write(struct net_device
 	return;
 }
 
+static int mdio_wait_link(struct net_device *dev, int wait)
+{
+	int bmsr;
+	int phy_id;
+	struct netdev_private *np;
+
+	np = netdev_priv(dev);
+	phy_id = np->phys[0];
+
+	do {
+		bmsr = mdio_read(dev, phy_id, MII_BMSR);
+		if (bmsr & 0x0004)
+			return 0;
+		mdelay(1);
+	} while (--wait > 0);
+	return -1;
+}
+
 static int netdev_open(struct net_device *dev)
 {
 	struct netdev_private *np = netdev_priv(dev);
@@ -1393,41 +1412,51 @@ static void netdev_error(struct net_devi
 	int speed;
 
 	if (intr_status & LinkChange) {
-		if (np->an_enable) {
-			mii_advertise = mdio_read (dev, np->phys[0], MII_ADVERTISE);
-			mii_lpa= mdio_read (dev, np->phys[0], MII_LPA);
-			mii_advertise &= mii_lpa;
-			printk (KERN_INFO "%s: Link changed: ", dev->name);
-			if (mii_advertise & ADVERTISE_100FULL) {
-				np->speed = 100;
-				printk ("100Mbps, full duplex\n");
-			} else if (mii_advertise & ADVERTISE_100HALF) {
-				np->speed = 100;
-				printk ("100Mbps, half duplex\n");
-			} else if (mii_advertise & ADVERTISE_10FULL) {
-				np->speed = 10;
-				printk ("10Mbps, full duplex\n");
-			} else if (mii_advertise & ADVERTISE_10HALF) {
-				np->speed = 10;
-				printk ("10Mbps, half duplex\n");
-			} else
-				printk ("\n");
+		if (mdio_wait_link(dev, 10) == 0) {
+			printk(KERN_INFO "%s: Link up\n", dev->name);
+			if (np->an_enable) {
+				mii_advertise = mdio_read(dev, np->phys[0],
+							   MII_ADVERTISE);
+				mii_lpa = mdio_read(dev, np->phys[0], MII_LPA);
+				mii_advertise &= mii_lpa;
+				printk(KERN_INFO "%s: Link changed: ",
+					dev->name);
+				if (mii_advertise & ADVERTISE_100FULL) {
+					np->speed = 100;
+					printk("100Mbps, full duplex\n");
+				} else if (mii_advertise & ADVERTISE_100HALF) {
+					np->speed = 100;
+					printk("100Mbps, half duplex\n");
+				} else if (mii_advertise & ADVERTISE_10FULL) {
+					np->speed = 10;
+					printk("10Mbps, full duplex\n");
+				} else if (mii_advertise & ADVERTISE_10HALF) {
+					np->speed = 10;
+					printk("10Mbps, half duplex\n");
+				} else
+					printk("\n");
 
+			} else {
+				mii_ctl = mdio_read(dev, np->phys[0], MII_BMCR);
+				speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10;
+				np->speed = speed;
+				printk(KERN_INFO "%s: Link changed: %dMbps ,",
+					dev->name, speed);
+				printk("%s duplex.\n",
+					(mii_ctl & BMCR_FULLDPLX) ?
+						"full" : "half");
+			}
+			check_duplex(dev);
+			if (np->flowctrl && np->mii_if.full_duplex) {
+				iowrite16(ioread16(ioaddr + MulticastFilter1+2) | 0x0200,
+					ioaddr + MulticastFilter1+2);
+				iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl,
+					ioaddr + MACCtrl0);
+			}
+			netif_carrier_on(dev);
 		} else {
-			mii_ctl = mdio_read (dev, np->phys[0], MII_BMCR);
-			speed = (mii_ctl & BMCR_SPEED100) ? 100 : 10;
-			np->speed = speed;
-			printk (KERN_INFO "%s: Link changed: %dMbps ,",
-				dev->name, speed);
-			printk ("%s duplex.\n", (mii_ctl & BMCR_FULLDPLX) ?
-				"full" : "half");
-		}
-		check_duplex (dev);
-		if (np->flowctrl && np->mii_if.full_duplex) {
-			iowrite16(ioread16(ioaddr + MulticastFilter1+2) | 0x0200,
-				ioaddr + MulticastFilter1+2);
-			iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl,
-				ioaddr + MACCtrl0);
+			printk(KERN_INFO "%s: Link down\n", dev->name);
+			netif_carrier_off(dev);
 		}
 	}
 	if (intr_status & StatsMax) {
_

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch 03/12] sundance: set carrier status on link change events
  2008-08-20 23:51 [patch 03/12] sundance: set carrier status on link change events akpm
@ 2008-09-14  0:13 ` Jeff Garzik
  2008-09-15 12:56   ` Dan Nicholson
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Garzik @ 2008-09-14  0:13 UTC (permalink / raw)
  To: akpm; +Cc: netdev, dbn.lists

akpm@linux-foundation.org wrote:
> From: Dan Nicholson <dbn.lists@gmail.com>
> 
> Check if the link is available when a changed interrupt has been received and
> set the carrier status appropriately.  The code is copied nearly verbatim from
> the dl2k module.  The link status could be used in more places in the driver,
> but this is enough to get the carrier status reported to userspace.  Fixes
> kernel bug #7487:
> 
>     http://bugzilla.kernel.org/show_bug.cgi?id=7487
> 
> [akpm@linux-foundation.org: coding-style fixes]
> Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  drivers/net/sundance.c |   95 +++++++++++++++++++++++++--------------
>  1 file changed, 62 insertions(+), 33 deletions(-)

applied



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch 03/12] sundance: set carrier status on link change events
  2008-09-14  0:13 ` Jeff Garzik
@ 2008-09-15 12:56   ` Dan Nicholson
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Nicholson @ 2008-09-15 12:56 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: akpm, netdev

On Sat, Sep 13, 2008 at 5:13 PM, Jeff Garzik <jeff@garzik.org> wrote:
> akpm@linux-foundation.org wrote:
>>
>> From: Dan Nicholson <dbn.lists@gmail.com>
>>
>> Check if the link is available when a changed interrupt has been received
>> and
>> set the carrier status appropriately.  The code is copied nearly verbatim
>> from
>> the dl2k module.  The link status could be used in more places in the
>> driver,
>> but this is enough to get the carrier status reported to userspace.  Fixes
>> kernel bug #7487:
>>
>>    http://bugzilla.kernel.org/show_bug.cgi?id=7487
>>
>> [akpm@linux-foundation.org: coding-style fixes]
>> Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
>> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>> ---
>>
>>  drivers/net/sundance.c |   95 +++++++++++++++++++++++++--------------
>>  1 file changed, 62 insertions(+), 33 deletions(-)
>
> applied

Thanks, Jeff (and Andrew for carrying this along). I was starting to
suspect that it would never get out of mm.

--
Dan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-15 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-20 23:51 [patch 03/12] sundance: set carrier status on link change events akpm
2008-09-14  0:13 ` Jeff Garzik
2008-09-15 12:56   ` Dan Nicholson
  -- strict thread matches above, loose matches on Subject: below --
2008-07-30 19:38 akpm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).