Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50500155 authored by Dan Nicholson's avatar Dan Nicholson Committed by Jeff Garzik
Browse files

sundance: set carrier status on link change events

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: default avatarDan Nicholson <dbn.lists@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent b39d66a8
Loading
Loading
Loading
Loading
+62 −33
Original line number Diff line number Diff line
@@ -409,6 +409,7 @@ static int change_mtu(struct net_device *dev, int new_mtu);
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 *dev, int phy_id, int location, int val
	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,11 +1412,15 @@ static void netdev_error(struct net_device *dev, int intr_status)
	int speed;

	if (intr_status & LinkChange) {
		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_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);
				printk(KERN_INFO "%s: Link changed: ",
					dev->name);
				if (mii_advertise & ADVERTISE_100FULL) {
					np->speed = 100;
					printk("100Mbps, full duplex\n");
@@ -1419,7 +1442,8 @@ static void netdev_error(struct net_device *dev, int intr_status)
				np->speed = speed;
				printk(KERN_INFO "%s: Link changed: %dMbps ,",
					dev->name, speed);
			printk ("%s duplex.\n", (mii_ctl & BMCR_FULLDPLX) ?
				printk("%s duplex.\n",
					(mii_ctl & BMCR_FULLDPLX) ?
						"full" : "half");
			}
			check_duplex(dev);
@@ -1429,6 +1453,11 @@ static void netdev_error(struct net_device *dev, int intr_status)
				iowrite16(ioread16(ioaddr + MACCtrl0) | EnbFlowCtrl,
					ioaddr + MACCtrl0);
			}
			netif_carrier_on(dev);
		} else {
			printk(KERN_INFO "%s: Link down\n", dev->name);
			netif_carrier_off(dev);
		}
	}
	if (intr_status & StatsMax) {
		get_stats(dev);