Module Name: src Committed By: msaitoh Date: Sun Jun 9 09:31:32 UTC 2013
Modified Files: src/sys/dev/mii: ciphy.c ihphy.c mii_physubr.c rgephy.c urlphy.c Log Message: Update link status quickly. This change is a part of FreeBSD's mii_physubr.c r158649. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/dev/mii/ciphy.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/mii/ihphy.c cvs rdiff -u -r1.76 -r1.77 src/sys/dev/mii/mii_physubr.c cvs rdiff -u -r1.31 -r1.32 src/sys/dev/mii/rgephy.c cvs rdiff -u -r1.27 -r1.28 src/sys/dev/mii/urlphy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/mii/ciphy.c diff -u src/sys/dev/mii/ciphy.c:1.22 src/sys/dev/mii/ciphy.c:1.23 --- src/sys/dev/mii/ciphy.c:1.22 Sun Jun 9 08:45:32 2013 +++ src/sys/dev/mii/ciphy.c Sun Jun 9 09:31:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ciphy.c,v 1.22 2013/06/09 08:45:32 msaitoh Exp $ */ +/* $NetBSD: ciphy.c,v 1.23 2013/06/09 09:31:32 msaitoh Exp $ */ /*- * Copyright (c) 2004 @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ciphy.c,v 1.22 2013/06/09 08:45:32 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ciphy.c,v 1.23 2013/06/09 09:31:32 msaitoh Exp $"); /* * Driver for the Cicada CS8201 10/100/1000 copper PHY. @@ -258,8 +258,14 @@ setit: * Only used for autonegotiation. */ if ((IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) && - (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) + (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) { + /* + * Reset autonegotiation timer to 0 just to make sure + * the future autonegotiation start with 0. + */ + sc->mii_ticks = 0; break; + } /* * Check to see if we have link. If we do, we don't @@ -267,8 +273,15 @@ setit: * the BMSR twice in case it's latched. */ reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); - if (reg & BMSR_LINK) + if (reg & BMSR_LINK) { + /* + * Reset autonegotiation timer to 0 in case the link + * goes down in the next tick. + */ + sc->mii_ticks = 0; + /* See above. */ break; + } /* * Only retry autonegotiation every N seconds. Index: src/sys/dev/mii/ihphy.c diff -u src/sys/dev/mii/ihphy.c:1.4 src/sys/dev/mii/ihphy.c:1.5 --- src/sys/dev/mii/ihphy.c:1.4 Sun Jun 9 09:15:51 2013 +++ src/sys/dev/mii/ihphy.c Sun Jun 9 09:31:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ihphy.c,v 1.4 2013/06/09 09:15:51 msaitoh Exp $ */ +/* $NetBSD: ihphy.c,v 1.5 2013/06/09 09:31:32 msaitoh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ihphy.c,v 1.4 2013/06/09 09:15:51 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihphy.c,v 1.5 2013/06/09 09:31:32 msaitoh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -218,8 +218,14 @@ ihphy_service(struct mii_softc *sc, stru * Only used for autonegotiation. */ if ((IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) && - (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) + (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) { + /* + * Reset autonegotiation timer to 0 just to make sure + * the future autonegotiation start with 0. + */ + sc->mii_ticks = 0; break; + } if (mii_phy_tick(sc) == EJUSTRETURN) return 0; Index: src/sys/dev/mii/mii_physubr.c diff -u src/sys/dev/mii/mii_physubr.c:1.76 src/sys/dev/mii/mii_physubr.c:1.77 --- src/sys/dev/mii/mii_physubr.c:1.76 Thu Jun 6 03:10:48 2013 +++ src/sys/dev/mii/mii_physubr.c Sun Jun 9 09:31:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mii_physubr.c,v 1.76 2013/06/06 03:10:48 msaitoh Exp $ */ +/* $NetBSD: mii_physubr.c,v 1.77 2013/06/09 09:31:32 msaitoh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.76 2013/06/06 03:10:48 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.77 2013/06/09 09:31:32 msaitoh Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -324,27 +324,47 @@ mii_phy_tick(struct mii_softc *sc) /* * If we're not doing autonegotiation, we don't need to do * any extra work here. However, we need to check the link - * status so we can generate an announcement if the status - * changes. + * status so we can generate an announcement by returning + * with 0 if the status changes. */ if ((IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) && - (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) + (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) { + /* + * Reset autonegotiation timer to 0 just to make sure + * the future autonegotiation start with 0. + */ + sc->mii_ticks = 0; return (0); + } /* Read the status register twice; BMSR_LINK is latch-low. */ reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); if (reg & BMSR_LINK) { /* - * See above. + * Reset autonegotiation timer to 0 in case the link + * goes down in the next tick. */ + sc->mii_ticks = 0; + /* See above. */ return (0); } /* + * mii_tick == 0 means it's the first tick after changing the media or + * the link became down since the last tick (see above), so return with + * 0 to update the status. + */ + if (sc->mii_ticks == 0) + return (0); + + /* Now increment the tick */ + sc->mii_ticks++; + + /* * Only retry autonegotiation every N seconds. */ KASSERT(sc->mii_anegticks != 0); - if (++sc->mii_ticks <= sc->mii_anegticks) + if (sc->mii_ticks <= sc->mii_anegticks) return (EJUSTRETURN); PHY_RESET(sc); Index: src/sys/dev/mii/rgephy.c diff -u src/sys/dev/mii/rgephy.c:1.31 src/sys/dev/mii/rgephy.c:1.32 --- src/sys/dev/mii/rgephy.c:1.31 Sun Jun 9 08:42:16 2013 +++ src/sys/dev/mii/rgephy.c Sun Jun 9 09:31:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rgephy.c,v 1.31 2013/06/09 08:42:16 msaitoh Exp $ */ +/* $NetBSD: rgephy.c,v 1.32 2013/06/09 09:31:32 msaitoh Exp $ */ /* * Copyright (c) 2003 @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.31 2013/06/09 08:42:16 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.32 2013/06/09 09:31:32 msaitoh Exp $"); /* @@ -289,8 +289,14 @@ rgephy_service(struct mii_softc *sc, str * Only used for autonegotiation. */ if ((IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) && - (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) + (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) { + /* + * Reset autonegotiation timer to 0 to make sure + * the future autonegotiation start with 0. + */ + sc->mii_ticks = 0; break; + } /* * Check to see if we have link. If we do, we don't Index: src/sys/dev/mii/urlphy.c diff -u src/sys/dev/mii/urlphy.c:1.27 src/sys/dev/mii/urlphy.c:1.28 --- src/sys/dev/mii/urlphy.c:1.27 Sun Jun 9 09:15:51 2013 +++ src/sys/dev/mii/urlphy.c Sun Jun 9 09:31:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: urlphy.c,v 1.27 2013/06/09 09:15:51 msaitoh Exp $ */ +/* $NetBSD: urlphy.c,v 1.28 2013/06/09 09:31:32 msaitoh Exp $ */ /* * Copyright (c) 2001, 2002 * Shingo WATANABE <n...@nabechan.org>. All rights reserved. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: urlphy.c,v 1.27 2013/06/09 09:15:51 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: urlphy.c,v 1.28 2013/06/09 09:31:32 msaitoh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -186,14 +186,32 @@ urlphy_service(struct mii_softc *sc, str /* Read the status register twice; MSR_LINK is latch-low. */ reg = PHY_READ(sc, URLPHY_MSR) | PHY_READ(sc, URLPHY_MSR); - if (reg & URLPHY_MSR_LINK) + if (reg & URLPHY_MSR_LINK) { + /* + * Reset autonegotiation timer to 0 in case the link + * goes down in the next tick. + */ + sc->mii_ticks = 0; + /* See above. */ break; + } + + /* + * mii_tick == 0 means it's the first tick after changing the + * media or the link became down since the last tick (see + * above), so break to update the status. + */ + if (sc->mii_ticks == 0) + break; + + /* Now increment the tick */ + sc->mii_ticks++; /* * Only retry autonegotiation every N seconds. */ KASSERT(sc->mii_anegticks != 0); - if (++sc->mii_ticks <= sc->mii_anegticks) + if (sc->mii_ticks <= sc->mii_anegticks) return (0); PHY_RESET(sc);