Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/mii Update link status quickly. This change is a par...



details:   https://anonhg.NetBSD.org/src/rev/4a8ae4e1cd82
branches:  trunk
changeset: 787283:4a8ae4e1cd82
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Sun Jun 09 09:31:32 2013 +0000

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

diffstat:

 sys/dev/mii/ciphy.c       |  21 +++++++++++++++++----
 sys/dev/mii/ihphy.c       |  12 +++++++++---
 sys/dev/mii/mii_physubr.c |  34 +++++++++++++++++++++++++++-------
 sys/dev/mii/rgephy.c      |  12 +++++++++---
 sys/dev/mii/urlphy.c      |  26 ++++++++++++++++++++++----
 5 files changed, 84 insertions(+), 21 deletions(-)

diffs (243 lines):

diff -r b6486d91d006 -r 4a8ae4e1cd82 sys/dev/mii/ciphy.c
--- a/sys/dev/mii/ciphy.c       Sun Jun 09 09:24:29 2013 +0000
+++ b/sys/dev/mii/ciphy.c       Sun Jun 09 09:31:32 2013 +0000
@@ -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 @@
                 * 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 @@
                 * 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.
diff -r b6486d91d006 -r 4a8ae4e1cd82 sys/dev/mii/ihphy.c
--- a/sys/dev/mii/ihphy.c       Sun Jun 09 09:24:29 2013 +0000
+++ b/sys/dev/mii/ihphy.c       Sun Jun 09 09:31:32 2013 +0000
@@ -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 @@
                 * 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;
diff -r b6486d91d006 -r 4a8ae4e1cd82 sys/dev/mii/mii_physubr.c
--- a/sys/dev/mii/mii_physubr.c Sun Jun 09 09:24:29 2013 +0000
+++ b/sys/dev/mii/mii_physubr.c Sun Jun 09 09:31:32 2013 +0000
@@ -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 @@
        /*
         * 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);
diff -r b6486d91d006 -r 4a8ae4e1cd82 sys/dev/mii/rgephy.c
--- a/sys/dev/mii/rgephy.c      Sun Jun 09 09:24:29 2013 +0000
+++ b/sys/dev/mii/rgephy.c      Sun Jun 09 09:31:32 2013 +0000
@@ -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 @@
                 * 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
diff -r b6486d91d006 -r 4a8ae4e1cd82 sys/dev/mii/urlphy.c
--- a/sys/dev/mii/urlphy.c      Sun Jun 09 09:24:29 2013 +0000
+++ b/sys/dev/mii/urlphy.c      Sun Jun 09 09:31:32 2013 +0000
@@ -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@localhost>.  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 @@
 
                /* 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);



Home | Main Index | Thread Index | Old Index