[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 15:52:43 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/c9ac20d16b36
changeset: 275:c9ac20d16b36
user:      ray at terran.dlink.ua
date:      Wed Jan 11 17:53:39 2012 +0200
description:
Tidy up.

diffstat:

 head/sys/dev/switch/floatphy.c |  84 +++++++++++++++---------------------------
 1 files changed, 30 insertions(+), 54 deletions(-)

diffs (185 lines):

diff -r 011d31c185b6 -r c9ac20d16b36 head/sys/dev/switch/floatphy.c
--- a/head/sys/dev/switch/floatphy.c	Wed Jan 11 17:33:01 2012 +0200
+++ b/head/sys/dev/switch/floatphy.c	Wed Jan 11 17:53:39 2012 +0200
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2011, Aleksandr Rybalko
+ * Copyright (c) 2012, Aleksandr Rybalko
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,6 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -101,43 +102,29 @@
 	floatphy_status,
 	mii_phy_reset
 };
-#if 0
-static void
-floatphy_speedtocap(struct floatphy_softc *sc)
-{
-	struct mii_softc *miisc;
 
-	miisc = (struct mii_softc *)sc;
-	/* limit capability to hinted speed value */
-	switch (sc->speed) {
-	case 1000:
-		miisc->mii_capabilities = BMSR_EXTCAP;
-		miisc->mii_extcapabilities = EXTSR_1000TFDX;
-		break;
-	case 100:
-		miisc->mii_capabilities = BMSR_100TXFDX;
-		miisc->mii_extcapabilities = 0;
-		break;
-	case 10:
-		miisc->mii_capabilities = BMSR_10TFDX;
-		miisc->mii_extcapabilities = 0;
-		break;
-	/* Do nothing if not hinted (0 value) */
-	}
-}
-#endif
+#define	SWITCH_PHY_REG(_p, _r)	(0x40000000 + ((_p) << 8) + (_r))
+
+#define	FLOATPHY_DEBUG_PHYREG	0x00000001
+#define	FLOATPHY_DEBUG_LINK	0x00000002
+#define	FLOATPHY_DEBUG_SPEED	0x00000002
+
+#define	FLOATPHY_FLAGS_LINK_TYPE_MASK		0x00000003
+#define		FLOATPHY_FLAGS_LINK_TYPE_ANY	0x00000000
+#define		FLOATPHY_FLAGS_LINK_TYPE_ALL	0x00000001
+#define	FLOATPHY_FLAGS_LOCK_SPEED		0x00000004
 
 static void
 floatphy_sysctl(struct floatphy_softc *sc)
 {
-        struct sysctl_ctx_list *ctx;
-        struct sysctl_oid *tree;
+	struct sysctl_ctx_list *ctx;
+	struct sysctl_oid *tree;
 
 	ctx = device_get_sysctl_ctx(sc->dev);
 	tree = device_get_sysctl_tree(sc->dev);
-        SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
-                "debug", CTLFLAG_RW, &sc->debug, 0,
-                "enable watchdog debugging");
+	SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+	    "debug", CTLFLAG_RW, &sc->debug, 0,
+	    "enable watchdog debugging");
 }
 
 static int
@@ -169,30 +156,25 @@
 	 *	0x00000000	Notify parent about link up if any of PHYs in
 	 *		master_phys mask stay in link.
 	 *	0x00000001	Same, but if all in link.
-	 *	0x00000002	???
-	 *	0x00000003	???
 	 *	0x00000004	use hint .speed always, otherwise if master
 	 *		is found, use master info.
-	 *	0x00000008	???
 	 */
 	devname = device_get_name(dev);
 	devunit = device_get_unit(dev);
+	/* Default to switch0 */
 	sc->master_name = "switch";
 	/* master_unit, master_phys, flags, speed is 0 */
 	resource_string_value(devname, devunit, "master", &sc->master_name);
 	resource_int_value(devname, devunit, "master_unit", &sc->master_unit);
 	resource_int_value(devname, devunit, "master_phys", &sc->master_phys);
-	resource_int_value(devname, devunit,"flags", &sc->flags);
-	resource_int_value(devname, devunit,"speed", &sc->speed);
+	resource_int_value(devname, devunit, "flags", &sc->flags);
+	resource_int_value(devname, devunit, "speed", &sc->speed);
 
 	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, " ");
@@ -225,15 +207,6 @@
 	return (ENXIO);
 }
 
-#define	BMSR_MEDIAMASK100	(BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
-				    BMSR_100T2FDX|BMSR_100T2HDX)
-#define	BMSR_MEDIAMASK10	(BMSR_10TFDX|BMSR_10THDX)
-
-#define	SWITCH_PHY_REG(_p, _r)	(0x40000000 + ((_p) << 8) + (_r))
-#define	FLOATPHY_DEBUG_PHYREG	0x00000001
-#define	FLOATPHY_DEBUG_LINK	0x00000002
-#define	FLOATPHY_DEBUG_SPEED	0x00000002
-
 static int
 floatphy_query_link(struct floatphy_softc *sc)
 {
@@ -270,7 +243,9 @@
 
 		/* Update speed only if linked */
 		/* TODO: better on linkup event, to reduce MDIO access */
-		if (((sc->flags & 0x00000004) == 0) && (status & BMSR_LINK)) {
+		/* TODO: move to separate sub */
+		if (((sc->flags & FLOATPHY_FLAGS_LOCK_SPEED) == 0) &&
+		    (status & BMSR_LINK)) {
 			/*
 			 * Speed setting not locked and port linked, so we can
 			 * update speed.
@@ -301,8 +276,8 @@
 				    "DEBUG: PHY(%d) speed=%d\n",
 				    p, sc->speed);
 		}
-		switch (sc->flags & 0x00000003) {
-		case 0:	/* If any ports linkup */
+		switch (sc->flags & FLOATPHY_FLAGS_LINK_TYPE_MASK) {
+		case FLOATPHY_FLAGS_LINK_TYPE_ANY:
 			if (status & BMSR_LINK) {
 				/* First linked sutisfy */
 				if (sc->debug & FLOATPHY_DEBUG_LINK)
@@ -311,13 +286,14 @@
 				return (1);
 			}
 			break;
-		case 1:	/* If all ports linkup */
+		case FLOATPHY_FLAGS_LINK_TYPE_ALL:
 			out &= (status & BMSR_LINK);
 			break;
 		}
 	}
 
-	if (((sc->flags & 0x00000003) == 1) && out) {
+	if (((sc->flags & FLOATPHY_FLAGS_LINK_TYPE_MASK) ==
+	    FLOATPHY_FLAGS_LINK_TYPE_ALL) && out) {
 		if (sc->debug & FLOATPHY_DEBUG_LINK)
 			device_printf(sc->dev, "DEBUG: ALL(0x%08x) linkup\n",
 			    sc->master_phys);
@@ -405,8 +381,8 @@
 floatphy_status(struct mii_softc *miisc)
 {
 	struct floatphy_softc *sc;
+	struct ifmedia_entry *ife;
 	struct mii_data *mii;
-	struct ifmedia_entry *ife;
 	uint32_t media;
 	int link;
 
@@ -423,7 +399,7 @@
 
 	mii->mii_media_status = IFM_AVALID | link;
 
-	if (sc->flags & 0x00000004) {
+	if (sc->flags & FLOATPHY_FLAGS_LOCK_SPEED) {
 		mii->mii_media_active = ife->ifm_media;
 	} else {
 		mii->mii_media_active = IFM_ETHER | media;


More information about the Zrouter-src-freebsd mailing list