PERFORCE change 89201 for review
Warner Losh
imp at FreeBSD.org
Thu Jan 5 00:33:05 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=89201
Change 89201 by imp at imp_hammer on 2006/01/05 08:32:59
More MII support goo.
Also, update the stats while I'm not hammered with other things,
lest I forget later.
Affected files ...
.. //depot/projects/arm/src/sys/arm/at91/if_ate.c#8 edit
Differences ...
==== //depot/projects/arm/src/sys/arm/at91/if_ate.c#8 (text+ko) ====
@@ -122,6 +122,8 @@
/* helper routines */
static int ate_activate(device_t dev);
static void ate_deactivate(device_t dev);
+static int ate_ifmedia_upd(struct ifnet *ifp);
+static void ate_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr);
/*
* The AT91 family of products has the ethernet called EMAC. However,
@@ -154,6 +156,12 @@
ATE_LOCK_INIT(sc);
callout_init_mtx(&sc->tick_ch, &sc->sc_mtx, 0);
+ if (mii_phy_probe(dev, &sc->miibus, ate_ifmedia_upd, ate_ifmedia_sts)) {
+ device_printf(dev, "Cannot find my PHY.\n");
+ err = ENXIO;
+ goto out;
+ }
+
sc->ifp = ifp = if_alloc(IFT_ETHER);
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
@@ -242,6 +250,39 @@
return;
}
+/*
+ * Change media according to request.
+ */
+static int
+ate_ifmedia_upd(struct ifnet *ifp)
+{
+ struct ate_softc *sc = ifp->if_softc;
+ struct mii_data *mii;
+
+ mii = device_get_softc(sc->miibus);
+ ATE_LOCK(sc);
+ mii_mediachg(mii);
+ ATE_UNLOCK(sc);
+ return (0);
+}
+
+/*
+ * Notify the world which media we're using.
+ */
+static void
+ate_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
+{
+ struct ate_softc *sc = ifp->if_softc;
+ struct mii_data *mii;
+
+ mii = device_get_softc(sc->miibus);
+ ATE_LOCK(sc);
+ mii_pollstat(mii);
+ ifmr->ifm_active = mii->mii_media_active;
+ ifmr->ifm_status = mii->mii_media_status;
+ ATE_UNLOCK(sc);
+}
+
static void
ate_tick(void *xsc)
{
@@ -275,6 +316,35 @@
~ETH_CFG_FD);
}
}
+
+ /*
+ * Update the stats as best we can. When we're done, clear
+ * the status counters and start over. We're supposed to read these
+ * registers often enough that they won't overflow. Hopefully
+ * once a second is often enough. Some don't map well to
+ * the dot3Stats mib, so for those we just count them as general
+ * errors. Stats for iframes, ibutes, oframes and obytes are
+ * collected elsewhere.
+ */
+ sc->mibdata.dot3StatsAlignmentErrors += RD4(sc, ETH_ALE);
+ sc->mibdata.dot3StatsFCSErrors += RD4(sc, ETH_SEQE);
+ sc->mibdata.dot3StatsSingleColliionsFrames += RD4(sc, ETH_SCOL);
+ sc->mibdata.dot3StatsMultipleColliionsFrames += RD4(sc, ETH_MCOL);
+ sc->mibdata.dot3StatsSQETestErrors += RD4(sc, ETH_SEQEE);
+ sc->mibdata.dot3StatsDeferredTransmissions += RD4(sc, ETH_DTE);
+ sc->mibdata.dot3StatsLateCollisions += RD4(sc, ETH_LCOL);
+ sc->mibdata.dot3StatsExcessiveCollisions += RD4(sc, ETH_ECOL);
+ sc->mibdata.dot3StatsCarrierSenseErrors += RD4(sc, ETH_CSE);
+ sc->mibdata.dot3StatsFrameTooLongs += RD4(sc, ETH_EJR);
+ sc->mibdata.dot3StatsInternalMacReceiveErrors += RD4(sc, ETH_DRFC);
+ /*
+ * not sure where to lump these, so count them against the errors
+ * for the interface.
+ */
+ sc->if_oerrors += RD4(sc, ETH_CSE) + RD4(sc, ETH_TUE);
+ sc->if_ierrors += RD4(sc, ETH_CDE) + RD4(sc, ETH_RJB) +
+ RD4(sc, ETH_USF);
+ WR4(sc, ETH_CTL, RD4(sc, ETH_CTL) | ETH_CTL_CSR);
}
More information about the p4-projects
mailing list