Page MenuHomeFreeBSD

D55631.id174395.diff
No OneTemporary

D55631.id174395.diff

diff --git a/sys/dev/usb/net/if_axge.c b/sys/dev/usb/net/if_axge.c
--- a/sys/dev/usb/net/if_axge.c
+++ b/sys/dev/usb/net/if_axge.c
@@ -107,6 +107,7 @@
static miibus_readreg_t axge_miibus_readreg;
static miibus_writereg_t axge_miibus_writereg;
static miibus_statchg_t axge_miibus_statchg;
+static miibus_linkchg_t axge_miibus_linkchg;
static uether_fn_t axge_attach_post;
static uether_fn_t axge_init;
@@ -181,6 +182,7 @@
DEVMETHOD(miibus_readreg, axge_miibus_readreg),
DEVMETHOD(miibus_writereg, axge_miibus_writereg),
DEVMETHOD(miibus_statchg, axge_miibus_statchg),
+ DEVMETHOD(miibus_linkchg, axge_miibus_linkchg),
DEVMETHOD_END
};
@@ -329,9 +331,10 @@
struct axge_softc *sc;
struct mii_data *mii;
if_t ifp;
- uint8_t link_status, tmp[5];
- uint16_t val;
int locked;
+ uint16_t bmsr, val;
+ uint8_t link_status, tmp[5];
+ bool new_link, old_link;
sc = device_get_softc(dev);
mii = GET_MII(sc);
@@ -344,6 +347,7 @@
(if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0)
goto done;
+ old_link = (sc->sc_flags & AXGE_FLAG_LINK) ? true : false;
sc->sc_flags &= ~AXGE_FLAG_LINK;
if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) ==
(IFM_ACTIVE | IFM_AVALID)) {
@@ -358,6 +362,43 @@
}
}
+ new_link = (sc->sc_flags & AXGE_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.
+ */
+ (void)axge_read_cmd_2(sc, AXGE_ACCESS_PHY,
+ MII_BMSR, AXGE_PHY_ADDR);
+ bmsr = axge_read_cmd_2(sc, AXGE_ACCESS_PHY,
+ MII_BMSR, AXGE_PHY_ADDR);
+
+ 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 |= AXGE_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 & AXGE_FLAG_LINK) == 0)
goto done;
@@ -402,6 +443,40 @@
AXGE_UNLOCK(sc);
}
+static void
+axge_miibus_linkchg(device_t dev)
+{
+ struct axge_softc *sc;
+ struct mii_data *mii;
+ int locked;
+ uint16_t bmsr;
+
+ sc = device_get_softc(dev);
+ mii = GET_MII(sc);
+ locked = mtx_owned(&sc->sc_mtx);
+ if (locked == 0)
+ AXGE_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) {
+ (void)axge_read_cmd_2(sc, AXGE_ACCESS_PHY,
+ MII_BMSR, AXGE_PHY_ADDR);
+ bmsr = axge_read_cmd_2(sc, AXGE_ACCESS_PHY,
+ MII_BMSR, AXGE_PHY_ADDR);
+ if ((bmsr & BMSR_LINK) == BMSR_LINK)
+ mii->mii_media_status |= IFM_ACTIVE;
+ }
+
+ if (locked == 0)
+ AXGE_UNLOCK(sc);
+}
+
static void
axge_chip_init(struct axge_softc *sc)
{
@@ -507,10 +582,17 @@
mii = GET_MII(sc);
AXGE_LOCK_ASSERT(sc, MA_OWNED);
+ AXGE_UNLOCK(sc);
+ AXGE_MII_LOCK(sc);
+ AXGE_LOCK(sc);
+
LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
PHY_RESET(miisc);
error = mii_mediachg(mii);
+ AXGE_UNLOCK(sc);
+ AXGE_MII_UNLOCK(sc);
+ AXGE_LOCK(sc);
return (error);
}
@@ -525,11 +607,13 @@
sc = if_getsoftc(ifp);
mii = GET_MII(sc);
+ AXGE_MII_LOCK(sc);
AXGE_LOCK(sc);
mii_pollstat(mii);
ifmr->ifm_active = mii->mii_media_active;
ifmr->ifm_status = mii->mii_media_status;
AXGE_UNLOCK(sc);
+ AXGE_MII_UNLOCK(sc);
}
/*
@@ -570,6 +654,7 @@
device_set_usb_desc(dev);
mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
+ sx_init(&sc->sc_mii_lock, "axgemii");
sc->sc_flags = USB_GET_DRIVER_INFO(uaa);
@@ -631,6 +716,7 @@
}
usbd_transfer_unsetup(sc->sc_xfer, AXGE_N_TRANSFER);
uether_ifdetach(ue);
+ sx_destroy(&sc->sc_mii_lock);
mtx_destroy(&sc->sc_mtx);
return (0);
@@ -768,7 +854,23 @@
mii = GET_MII(sc);
AXGE_LOCK_ASSERT(sc, MA_OWNED);
+ AXGE_UNLOCK(sc);
+ if (!AXGE_MII_TRYLOCK(sc)) {
+ AXGE_LOCK(sc);
+ return;
+ }
+ AXGE_LOCK(sc);
+
mii_tick(mii);
+ if ((sc->sc_flags & AXGE_FLAG_LINK) == 0) {
+ axge_miibus_statchg(ue->ue_dev);
+ if ((sc->sc_flags & AXGE_FLAG_LINK) != 0)
+ axge_start(ue);
+ }
+
+ AXGE_UNLOCK(sc);
+ AXGE_MII_UNLOCK(sc);
+ AXGE_LOCK(sc);
}
static u_int
diff --git a/sys/dev/usb/net/if_axgereg.h b/sys/dev/usb/net/if_axgereg.h
--- a/sys/dev/usb/net/if_axgereg.h
+++ b/sys/dev/usb/net/if_axgereg.h
@@ -202,6 +202,7 @@
struct axge_softc {
struct usb_ether sc_ue;
struct mtx sc_mtx;
+ struct sx sc_mii_lock;
struct usb_xfer *sc_xfer[AXGE_N_TRANSFER];
int sc_flags;
@@ -214,3 +215,6 @@
#define AXGE_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define AXGE_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define AXGE_LOCK_ASSERT(_sc, t) mtx_assert(&(_sc)->sc_mtx, t)
+#define AXGE_MII_LOCK(_sc) sx_xlock(&(_sc)->sc_mii_lock)
+#define AXGE_MII_UNLOCK(_sc) sx_xunlock(&(_sc)->sc_mii_lock)
+#define AXGE_MII_TRYLOCK(_sc) sx_try_xlock(&(_sc)->sc_mii_lock)

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 16, 12:14 PM (15 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31602430
Default Alt Text
D55631.id174395.diff (5 KB)

Event Timeline