[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Wed Jan 11 14:12:35 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/18da06af7932
changeset: 271:18da06af7932
user:      ray at terran.dlink.ua
date:      Wed Jan 11 16:12:06 2012 +0200
description:
Update autoselect.
Fix mistake in speed checking.

diffstat:

 head/sys/dev/switch/floatphy.c |  69 +++++++++++++++++++++++++++++++----------
 1 files changed, 51 insertions(+), 18 deletions(-)

diffs (149 lines):

diff -r d793615e8de2 -r 18da06af7932 head/sys/dev/switch/floatphy.c
--- a/head/sys/dev/switch/floatphy.c	Wed Jan 11 00:14:18 2012 +0200
+++ b/head/sys/dev/switch/floatphy.c	Wed Jan 11 16:12:06 2012 +0200
@@ -101,7 +101,7 @@
 	floatphy_status,
 	mii_phy_reset
 };
-
+#if 0
 static void
 floatphy_speedtocap(struct floatphy_softc *sc)
 {
@@ -125,6 +125,7 @@
 	/* Do nothing if not hinted (0 value) */
 	}
 }
+#endif
 
 static void
 floatphy_sysctl(struct floatphy_softc *sc)
@@ -184,12 +185,14 @@
 	resource_int_value(devname, devunit,"flags", &sc->flags);
 	resource_int_value(devname, devunit,"speed", &sc->speed);
 
-	miisc->mii_capabilities = BMSR_100TXFDX | BMSR_100TXHDX |
-	    BMSR_EXTCAP | BMSR_ANEG;
+	miisc->mii_capabilities = BMSR_10THDX | BMSR_10TFDX | BMSR_100TXHDX |
+	    BMSR_100TXFDX | BMSR_EXTCAP | BMSR_ANEG;
 	miisc->mii_extcapabilities = EXTSR_1000TFDX | EXTSR_1000THDX |
 	    EXTSR_1000XFDX | EXTSR_1000XHDX;
 
+#if 0
 	floatphy_speedtocap(sc);
+#endif
 	floatphy_sysctl(sc);
 
 	device_printf(dev, " ");
@@ -234,7 +237,7 @@
 static int
 floatphy_query_link(struct floatphy_softc *sc)
 {
-	uint32_t reg, value, out;
+	uint32_t reg, status, control, out;
 	int error, p;
 
 	/* TODO: Check if we lost master */
@@ -252,26 +255,46 @@
 			continue;
 
 		reg = SWITCH_PHY_REG(p, MII_BMSR);
-		error = SWITCHPUB_GET_REG(sc->master, reg,
-		    &value);
+		error = SWITCHPUB_GET_REG(sc->master, reg, &status);
+		if (error) {
+			return (-1);
+		}
 		/* TODO: handle error */
-		if ((value & 0xffff) == 0xffff)
+		if ((status & 0xffff) == 0xffff)
 			/* Isolated or NC PHY */
 			continue;
 
 		if (sc->debug & FLOATPHY_DEBUG_PHYREG)
 			device_printf(sc->dev, "DEBUG: PHY(%d) BMSR=%04x\n",
-			    p, value);
+			    p, status);
 
-		if ((sc->flags & 0x00000004) == 0) {
-			/* We can update speed */
-			if (value & BMSR_MEDIAMASK10)
+		/* Update speed only if linked */
+		/* TODO: better on linkup event, to reduce MDIO access */
+		if (((sc->flags & 0x00000004) == 0) && (status & BMSR_LINK)) {
+			/*
+			 * Speed setting not locked and port linked, so we can
+			 * update speed.
+			 */
+			reg = SWITCH_PHY_REG(p, MII_BMCR);
+			error = SWITCHPUB_GET_REG(sc->master, reg, &control);
+			if (error) {
+				return (-1);
+			}
+
+			switch (control & (BMCR_S100 | BMCR_S1000)) {
+			case 0:
 				sc->speed = 10;
-			if (value & BMSR_MEDIAMASK100)
+				break;
+			case BMCR_S100:
 				sc->speed = 100;
-			if (value & BMSR_EXTCAP)
-				/* XXX: hope EXTCAP reg will not have 10G */
+				break;
+			case BMCR_S1000:
 				sc->speed = 1000;
+				break;
+			case (BMCR_S100|BMCR_S1000):
+				/* Here is we catch 0xffff */
+				break;
+			}
 
 			if (sc->debug & FLOATPHY_DEBUG_SPEED)
 				device_printf(sc->dev,
@@ -280,7 +303,7 @@
 		}
 		switch (sc->flags & 0x00000003) {
 		case 0:	/* If any ports linkup */
-			if (value & BMSR_LINK) {
+			if (status & BMSR_LINK) {
 				/* First linked sutisfy */
 				if (sc->debug & FLOATPHY_DEBUG_LINK)
 					device_printf(sc->dev, 
@@ -289,7 +312,7 @@
 			}
 			break;
 		case 1:	/* If all ports linkup */
-			out &= (value & BMSR_LINK);
+			out &= (status & BMSR_LINK);
 			break;
 		}
 	}
@@ -339,7 +362,12 @@
 	case MII_POLLSTAT:
 		break;
 	case MII_MEDIACHG:
-		link = (floatphy_query_link(sc) == 1) ? IFM_ACTIVE : 0;
+		link = floatphy_query_link(sc);
+		if (link == -1) {
+			/* Error detected, no update */
+			return (0);
+		}
+		link = (link == 1) ? IFM_ACTIVE : 0;
 		/* XXX: get FDX link status */
 		media = floatphy_speed_to_media(sc->speed, IFM_FDX);
 
@@ -385,7 +413,12 @@
 	sc = (struct floatphy_softc *)miisc;
 	mii = miisc->mii_pdata;
 	ife = mii->mii_media.ifm_cur;
-	link = (floatphy_query_link(sc) == 1) ? IFM_ACTIVE : 0;
+	link = floatphy_query_link(sc);
+	if (link == -1) {
+		/* Error detected, no update */
+		return;
+	}
+	link = (link == 1) ? IFM_ACTIVE : 0;
 	media = floatphy_speed_to_media(sc->speed, IFM_FDX);
 
 	mii->mii_media_status = IFM_AVALID | link;


More information about the Zrouter-src-freebsd mailing list