#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_media.h>
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <dev/mii/miidevs.h>
int mtdphymatch(struct device *, void *, void *);
void mtdphyattach(struct device *, struct device *, void *);
const struct cfattach mtdphy_ca = {
sizeof(struct mii_softc), mtdphymatch, mtdphyattach, mii_phy_detach
};
struct cfdriver mtdphy_cd = {
NULL, "mtdphy", DV_DULL
};
int mtdphy_service(struct mii_softc *, struct mii_data *, int);
const struct mii_phy_funcs mtdphy_funcs = {
mtdphy_service, ukphy_status, mii_phy_reset,
};
static const struct mii_phydesc mtdphys[] = {
{ MII_OUI_MYSON, MII_MODEL_MYSON_MTD972,
MII_STR_MYSON_MTD972 },
{ 0, 0,
NULL },
};
int
mtdphymatch(struct device *parent, void *match, void *aux)
{
struct mii_attach_args *ma = aux;
if (mii_phy_match(ma, mtdphys) != NULL)
return (10);
return (0);
}
void
mtdphyattach(struct device *parent, struct device *self, void *aux)
{
struct mii_softc *sc = (struct mii_softc *)self;
struct mii_attach_args *ma = aux;
struct mii_data *mii = ma->mii_data;
const struct mii_phydesc *mpd;
mpd = mii_phy_match(ma, mtdphys);
printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
sc->mii_inst = mii->mii_instance;
sc->mii_phy = ma->mii_phyno;
sc->mii_funcs = &mtdphy_funcs;
sc->mii_pdata = mii;
sc->mii_flags = ma->mii_flags;
PHY_RESET(sc);
sc->mii_capabilities =
PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
if (sc->mii_capabilities & BMSR_MEDIAMASK)
mii_phy_add_media(sc);
}
int
mtdphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
int reg;
if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
return (ENXIO);
switch (cmd) {
case MII_POLLSTAT:
if (IFM_INST(ife->ifm_media) != sc->mii_inst)
return (0);
break;
case MII_MEDIACHG:
if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
reg = PHY_READ(sc, MII_BMCR);
PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
return (0);
}
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
break;
mii_phy_setmedia(sc);
break;
case MII_TICK:
if (IFM_INST(ife->ifm_media) != sc->mii_inst)
return (0);
if (mii_phy_tick(sc) == EJUSTRETURN)
return (0);
break;
case MII_DOWN:
mii_phy_down(sc);
return (0);
}
mii_phy_status(sc);
mii_phy_update(sc, cmd);
return (0);
}