ALTPATCH: 8139cp: LinkChg support

3 messages, 2 authors, 2002-09-20 · open the first message on its own page

ALTPATCH: 8139cp: LinkChg support

From: Jeff Garzik <hidden>
Date: 2002-09-20 06:10:41

Felipe,

Here is the patch I just committed, instead of your patch.  I wanted a 
more generic solution, that is easily pluggable into other drivers.

Please test and let me know if you find bugs, or want additions...

	Jeff


Re: ALTPATCH: 8139cp: LinkChg support

From: Felipe W Damasio <hidden>
Date: 2002-09-20 07:01:50

On Fri, 2002-09-20 at 06:15, Jeff Garzik wrote:
quoted hunk
diff -Nru a/drivers/net/mii.c b/drivers/net/mii.c
--- a/drivers/net/mii.c	Fri Sep 20 02:13:15 2002
+++ b/drivers/net/mii.c	Fri Sep 20 02:13:15 2002
@@ -170,6 +170,75 @@
 	return r;
 }
 
+void mii_check_link (struct mii_if_info *mii)
+{
+	if (mii_link_ok(mii))
+		netif_carrier_on(mii->dev);
+	else
+		netif_carrier_off(mii->dev);
+}
+
+unsigned int mii_check_media (struct mii_if_info *mii, unsigned int ok_to_print)
+{
+	unsigned int old_carrier, new_carrier;
+	int advertise, lpa, media, duplex;
	Shouldn't advertise and lpa be either "unsigned short" or u16?
+
+	/* if forced media, go no further */
+	if (mii->duplex_lock)
+		return 0; /* duplex did not change */
+
+	/* check current and old link status */
+	old_carrier = netif_carrier_ok(mii->dev) ? 1 : 0;
+	new_carrier = (unsigned int) mii_link_ok(mii);
+
+	/* if carrier state did not change, this is a "bounce",
+	 * just exit as everything is already set correctly
+	 */
+	if (old_carrier == new_carrier)
+		return 0; /* duplex did not change */
+
+	/* no carrier, nothing much to do */
+	if (!new_carrier) {
+		netif_carrier_off(mii->dev);
+		if (ok_to_print)
+			printk(KERN_INFO "%s: link down\n", mii->dev->name);
+		return 0; /* duplex did not change */
+	}
+
+	/*
+	 * we have carrier, see who's on the other end
+	 */
+	netif_carrier_on(mii->dev);
+
+	/* get MII advertise and LPA values */
+	if (mii->advertising)
+		advertise = mii->advertising;
+	else {
+		advertise = mii->mdio_read(mii->dev, mii->phy_id, MII_ADVERTISE);
+		mii->advertising = advertise;
+	}
+	lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
+
+	/* figure out media and duplex from advertise and LPA values */
+	media = mii_nway_result(lpa & advertise);
        ^^^^^^^^^^^^^^^^^^^^^^^ 

	mii_nway_result returns a "unsigned int", so media also doesn't look
good.
+	duplex = (media & (ADVERTISE_100FULL | ADVERTISE_10FULL)) ? 1 : 0;
	Or we could do

	duplex = (media & ADVERTISE_FULL) ? 1 : 0;

Felipe

Re: ALTPATCH: 8139cp: LinkChg support

From: Jeff Garzik <hidden>
Date: 2002-09-20 13:16:45

Felipe W Damasio wrote:
quoted
+	int advertise, lpa, media, duplex;

	Shouldn't advertise and lpa be either "unsigned short" or u16?
No, they don't need to be.


quoted
+	lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
+
+	/* figure out media and duplex from advertise and LPA values */
+	media = mii_nway_result(lpa & advertise);
        ^^^^^^^^^^^^^^^^^^^^^^^ 

	mii_nway_result returns a "unsigned int", so media also doesn't look
good.
mii_nway_result _really_ returns a small bitmapped value, so it doesn't 
matter.

quoted
+	duplex = (media & (ADVERTISE_100FULL | ADVERTISE_10FULL)) ? 1 : 0;

	Or we could do

	duplex = (media & ADVERTISE_FULL) ? 1 : 0;

True.  I forgot about that constant...

	Jeff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help