Update link status quickly. This change is a part of FreeBSD's mii_physubr.c

r158649.
This commit is contained in:
msaitoh 2013-06-09 09:31:32 +00:00
parent 23515adb99
commit 307e621cc0
5 changed files with 84 additions and 21 deletions

View File

@ -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.

View File

@ -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, struct mii_data *mii, int cmd)
* 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;

View File

@ -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);

View File

@ -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, struct mii_data *mii, int cmd)
* 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

View File

@ -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 <nabe@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, struct mii_data *mii, int cmd)
/* 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);