Page MenuHomeFreeBSD

D55925.id173866.diff
No OneTemporary

D55925.id173866.diff

diff --git a/sys/dev/usb/net/if_axe.c b/sys/dev/usb/net/if_axe.c
--- a/sys/dev/usb/net/if_axe.c
+++ b/sys/dev/usb/net/if_axe.c
@@ -192,6 +192,7 @@
static miibus_readreg_t axe_miibus_readreg;
static miibus_writereg_t axe_miibus_writereg;
static miibus_statchg_t axe_miibus_statchg;
+static miibus_linkchg_t axe_miibus_linkchg;
static uether_fn_t axe_attach_post;
static uether_fn_t axe_init;
@@ -261,6 +262,7 @@
DEVMETHOD(miibus_readreg, axe_miibus_readreg),
DEVMETHOD(miibus_writereg, axe_miibus_writereg),
DEVMETHOD(miibus_statchg, axe_miibus_statchg),
+ DEVMETHOD(miibus_linkchg, axe_miibus_linkchg),
DEVMETHOD_END
};
@@ -371,8 +373,9 @@
struct axe_softc *sc = device_get_softc(dev);
struct mii_data *mii = GET_MII(sc);
if_t ifp;
- uint16_t val;
int err, locked;
+ uint16_t bmsr, val;
+ bool new_link, old_link;
locked = mtx_owned(&sc->sc_mtx);
if (!locked)
@@ -383,6 +386,7 @@
(if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0)
goto done;
+ old_link = (sc->sc_flags & AXE_FLAG_LINK) ? true : false;
sc->sc_flags &= ~AXE_FLAG_LINK;
if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
(IFM_ACTIVE | IFM_AVALID)) {
@@ -401,6 +405,46 @@
}
}
+ new_link = (sc->sc_flags & AXE_FLAG_LINK) ? true : false;
+ if (old_link != new_link) {
+ if (!new_link) {
+ /*
+ * MII layer reports link down. Verify by
+ * reading the PHY BMSR register directly.
+ * BMSR link status is latched-low, so read
+ * twice: first clears any stale latch,
+ * second gives current state.
+ */
+ axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
+ axe_cmd(sc, AXE_CMD_MII_READ_REG, MII_BMSR,
+ sc->sc_phyno, &val);
+ axe_cmd(sc, AXE_CMD_MII_READ_REG, MII_BMSR,
+ sc->sc_phyno, &val);
+ axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
+ bmsr = le16toh(val);
+
+ if ((bmsr & BMSR_LINK) == BMSR_LINK) {
+ /*
+ * PHY still has link. This is a
+ * spurious link-down event from the
+ * MII polling race (see PR 252165).
+ * Restore IFM_ACTIVE so the
+ * subsequent MIIBUS_LINKCHG check in
+ * mii_phy_update sees no status
+ * change and doesn't fire.
+ */
+ device_printf(dev,
+ "spurious link down (PHY link up), overriding\n");
+ sc->sc_flags |= AXE_FLAG_LINK;
+ mii->mii_media_status |= IFM_ACTIVE;
+ goto done;
+ }
+
+ /* PHY confirms link is genuinely down. */
+ goto done;
+ }
+ }
+
/* Lost link, do nothing. */
if ((sc->sc_flags & AXE_FLAG_LINK) == 0)
goto done;
@@ -441,6 +485,43 @@
AXE_UNLOCK(sc);
}
+static void
+axe_miibus_linkchg(device_t dev)
+{
+ struct axe_softc *sc;
+ struct mii_data *mii;
+ int locked;
+ uint16_t bmsr, val;
+
+ sc = device_get_softc(dev);
+ mii = GET_MII(sc);
+ locked = mtx_owned(&sc->sc_mtx);
+ if (locked == 0)
+ AXE_LOCK(sc);
+
+ /*
+ * This is called by the default miibus linkchg handler
+ * before it calls if_link_state_change(). If the PHY
+ * still has link but the MII layer lost IFM_ACTIVE due
+ * to the polling race (see PR 252165), restore it so the
+ * notification goes out as LINK_STATE_UP rather than DOWN.
+ */
+ if (mii != NULL && (mii->mii_media_status & IFM_ACTIVE) == 0) {
+ axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
+ axe_cmd(sc, AXE_CMD_MII_READ_REG, MII_BMSR,
+ sc->sc_phyno, &val);
+ axe_cmd(sc, AXE_CMD_MII_READ_REG, MII_BMSR,
+ sc->sc_phyno, &val);
+ axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
+ bmsr = le16toh(val);
+ if ((bmsr & BMSR_LINK) == BMSR_LINK)
+ mii->mii_media_status |= IFM_ACTIVE;
+ }
+
+ if (locked == 0)
+ AXE_UNLOCK(sc);
+}
+
/*
* Set media options.
*/

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 26, 11:25 PM (6 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29974957
Default Alt Text
D55925.id173866.diff (3 KB)

Event Timeline