Introduce NetBSD's mii_phy_match() API and use it in the nsgphy to

get a description printed.
This commit is contained in:
Poul-Henning Kamp 2002-04-29 14:09:10 +00:00
parent e5fbad8bca
commit 875525d517
3 changed files with 45 additions and 10 deletions

View File

@ -593,3 +593,15 @@ mii_phy_detach(device_t dev)
return(0);
}
const struct mii_phydesc *
mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd)
{
for (; mpd->mpd_name != NULL; mpd++) {
if (MII_OUI(ma->mii_id1, ma->mii_id2) == mpd->mpd_oui &&
MII_MODEL(ma->mii_id2) == mpd->mpd_model)
return (mpd);
}
return (NULL);
}

View File

@ -155,6 +155,15 @@ struct mii_attach_args {
};
typedef struct mii_attach_args mii_attach_args_t;
/*
* Used to match a PHY.
*/
struct mii_phydesc {
u_int32_t mpd_oui; /* the PHY's OUI */
u_int32_t mpd_model; /* the PHY's model */
const char *mpd_name; /* the PHY's name */
};
/*
* An array of these structures map MII media types to BMCR/ANAR settings.
*/
@ -210,6 +219,8 @@ void mii_phy_setmedia(struct mii_softc *sc);
void mii_phy_update(struct mii_softc *, int);
int mii_phy_tick(struct mii_softc *);
const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd);
void ukphy_status(struct mii_softc *);
#endif /* _KERNEL */

View File

@ -98,28 +98,35 @@ static driver_t nsgphy_driver = {
sizeof(struct mii_softc)
};
DRIVER_MODULE(nsgphy, miibus, nsgphy_driver, nsgphy_devclass, 0, 0);
static int nsgphy_service(struct mii_softc *, struct mii_data *,int);
static void nsgphy_status(struct mii_softc *);
extern void mii_phy_auto_timeout(void *);
const struct mii_phydesc gphyters[] = {
{ MII_OUI_NATSEMI, MII_MODEL_NATSEMI_DP83861,
MII_STR_NATSEMI_DP83861 },
{ MII_OUI_NATSEMI, MII_MODEL_NATSEMI_DP83891,
MII_STR_NATSEMI_DP83891 },
{ 0, 0,
NULL },
};
static int
nsgphy_probe(device_t dev)
{
struct mii_attach_args *ma;
const struct mii_phydesc *mpd;
ma = device_get_ivars(dev);
if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_NATSEMI) {
if (MII_MODEL(ma->mii_id2) == MII_MODEL_NATSEMI_DP83891) {
device_set_desc(dev, MII_STR_NATSEMI_DP83891);
return(0);
}
if (MII_MODEL(ma->mii_id2) == MII_MODEL_NATSEMI_DP83861) {
device_set_desc(dev, MII_STR_NATSEMI_DP83861);
return(0);
}
mpd = mii_phy_match(ma, gphyters);
if (mpd != NULL) {
device_set_desc(dev, mpd->mpd_name);
return(0);
}
return(ENXIO);
@ -131,9 +138,14 @@ nsgphy_attach(device_t dev)
struct mii_softc *sc;
struct mii_attach_args *ma;
struct mii_data *mii;
const struct mii_phydesc *mpd;
sc = device_get_softc(dev);
ma = device_get_ivars(dev);
mpd = mii_phy_match(ma, gphyters);
if (bootverbose)
device_printf(dev, "<rev. %d>\n", MII_REV(ma->mii_id2));
device_printf(dev, " ");
sc->mii_dev = device_get_parent(dev);
mii = device_get_softc(sc->mii_dev);
LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);