Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/mii Fix a bug when a media is changed to IFM_AUTO.



details:   https://anonhg.NetBSD.org/src/rev/dd9aca97fafc
branches:  trunk
changeset: 375916:dd9aca97fafc
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon May 22 02:12:13 2023 +0000

description:
Fix a bug when a media is changed to IFM_AUTO.

 Fix a bug that ifconfig ifN media auto doesn't change the setting when
the previous media setting used autonego. When the mii_phy_setmedia()
function is called to change the media to IFM_AUTO, the BMCR_AUTOEN bit was
used to check if the previous setting was IFM_AUTO. It's not correct.
IFM_1000_T also uses autonego. So if a previous setting is IFM_1000_T and
the next setting is IFM_AUTO, mii_phy_auto() is not called if neither
MIIF_FORCEANEG nor MIIF_DOPAUSE are set. As a result, after changing
IFM_AUTO, neither 10Mbps nor 100Mbps are not advertised.

Note that almost all drivers uses MIIF_DOPAUSE flags.

TODO: cleanup ciphy.c and rgephy.c. Those have #ifdef foo.

diffstat:

 sys/dev/mii/mii_physubr.c |  27 ++++++++-------------------
 1 files changed, 8 insertions(+), 19 deletions(-)

diffs (66 lines):

diff -r 8e60fefd8b39 -r dd9aca97fafc sys/dev/mii/mii_physubr.c
--- a/sys/dev/mii/mii_physubr.c Sun May 21 18:01:38 2023 +0000
+++ b/sys/dev/mii/mii_physubr.c Mon May 22 02:12:13 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mii_physubr.c,v 1.102 2023/02/22 08:09:09 msaitoh Exp $        */
+/*     $NetBSD: mii_physubr.c,v 1.103 2023/05/22 02:12:13 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.102 2023/02/22 08:09:09 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.103 2023/05/22 02:12:13 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -138,22 +138,14 @@ mii_phy_setmedia(struct mii_softc *sc)
 {
        struct mii_data *mii = sc->mii_pdata;
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
+       u_int subtype;
        uint16_t bmcr, anar, gtcr;
 
        KASSERT(mii_locked(mii));
 
-       if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
-               /*
-                * Force renegotiation if MIIF_DOPAUSE.
-                *
-                * XXX This is only necessary because many NICs don't
-                * XXX advertise PAUSE capabilities at boot time.  Maybe
-                * XXX we should force this only once?
-                */
-               PHY_READ(sc, MII_BMCR, &bmcr);
-               if ((bmcr & BMCR_AUTOEN) == 0 ||
-                   (sc->mii_flags & (MIIF_FORCEANEG | MIIF_DOPAUSE)))
-                       (void) mii_phy_auto(sc);
+       subtype = IFM_SUBTYPE(ife->ifm_media);
+       if ((subtype == IFM_AUTO) || (subtype == IFM_1000_T)) {
+               (void) mii_phy_auto(sc);
                return;
        }
 
@@ -169,7 +161,7 @@ mii_phy_setmedia(struct mii_softc *sc)
        gtcr = mii_media_table[ife->ifm_data].mm_gtcr;
 
        if (mii->mii_media.ifm_media & IFM_ETH_MASTER) {
-               switch (IFM_SUBTYPE(ife->ifm_media)) {
+               switch (subtype) {
                case IFM_1000_T:
                        gtcr |= GTCR_MAN_MS | GTCR_ADV_MS;
                        break;
@@ -198,10 +190,7 @@ mii_phy_setmedia(struct mii_softc *sc)
        PHY_WRITE(sc, MII_ANAR, anar);
        if (sc->mii_flags & MIIF_HAVE_GTCR)
                PHY_WRITE(sc, MII_100T2CR, gtcr);
-       if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T)
-               mii_phy_auto(sc);
-       else
-               PHY_WRITE(sc, MII_BMCR, bmcr);
+       PHY_WRITE(sc, MII_BMCR, bmcr);
 }
 
 /* Setup autonegotiation and start it. */



Home | Main Index | Thread Index | Old Index