Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/mii - Call tlphy_auto correctly.



details:   https://anonhg.NetBSD.org/src/rev/616c8bfe717d
branches:  trunk
changeset: 1011719:616c8bfe717d
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Tue Jul 07 08:35:16 2020 +0000

description:
- Call tlphy_auto correctly.
- It's not required to do busy-wait by mii_phy_auto(sc, 1). Now there is
 no any PHY driver which calls mii_phy_auto(sc, 1).

diffstat:

 sys/dev/mii/tlphy.c |  50 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 13 deletions(-)

diffs (96 lines):

diff -r 4329914426d5 -r 616c8bfe717d sys/dev/mii/tlphy.c
--- a/sys/dev/mii/tlphy.c       Tue Jul 07 06:59:22 2020 +0000
+++ b/sys/dev/mii/tlphy.c       Tue Jul 07 08:35:16 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tlphy.c,v 1.69 2020/07/07 06:59:22 msaitoh Exp $       */
+/*     $NetBSD: tlphy.c,v 1.70 2020/07/07 08:35:16 msaitoh Exp $       */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tlphy.c,v 1.69 2020/07/07 06:59:22 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tlphy.c,v 1.70 2020/07/07 08:35:16 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -98,7 +98,7 @@
     tlphymatch, tlphyattach, mii_phy_detach, mii_phy_activate);
 
 static int     tlphy_service(struct mii_softc *, struct mii_data *, int);
-static int     tlphy_auto(struct tlphy_softc *, int);
+static int     tlphy_auto(struct tlphy_softc *);
 static void    tlphy_acomp(struct tlphy_softc *);
 static void    tlphy_status(struct mii_softc *);
 
@@ -239,12 +239,7 @@
 
                switch (IFM_SUBTYPE(ife->ifm_media)) {
                case IFM_AUTO:
-                       /*
-                        * The ThunderLAN PHY doesn't self-configure after
-                        * an autonegotiation cycle, so there's no such
-                        * thing as "already in auto mode".
-                        */
-                       (void) tlphy_auto(tsc, 1);
+                       (void) tlphy_auto(tsc);
                        break;
                case IFM_10_2:
                case IFM_10_5:
@@ -268,8 +263,37 @@
                 * XXX WHAT ABOUT CHECKING LINK ON THE BNC/AUI?!
                 */
 
-               if (mii_phy_tick(sc) == EJUSTRETURN)
-                       return 0;
+               /* Only used for autonegotiation. */
+               if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
+                       sc->mii_ticks = 0;
+                       break;
+               }
+
+               /*
+                * Check for link.
+                * Read the status register twice; BMSR_LINK is latch-low.
+                */
+               PHY_READ(sc, MII_BMSR, &reg);
+               PHY_READ(sc, MII_BMSR, &reg);
+               if (reg & BMSR_LINK) {
+                       sc->mii_ticks = 0;
+                       break;
+               }
+
+               /*
+                * mii_ticks == 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;
+
+               /* Only retry autonegotiation every mii_anegticks seconds. */
+               KASSERT(sc->mii_anegticks != 0);
+               if (sc->mii_ticks <= sc->mii_anegticks)
+                       break;
+
+               tlphy_auto(tsc);
                break;
 
        case MII_DOWN:
@@ -338,12 +362,12 @@
 }
 
 static int
-tlphy_auto(struct tlphy_softc *tsc, int waitfor)
+tlphy_auto(struct tlphy_softc *tsc)
 {
        struct mii_softc *sc = &tsc->sc_mii;
        int error;
 
-       switch ((error = mii_phy_auto(sc, waitfor))) {
+       switch ((error = mii_phy_auto(sc, 0))) {
        case EIO:
                /*
                 * Just assume we're not in full-duplex mode.



Home | Main Index | Thread Index | Old Index