In miibus(4) drivers provide functions that allow to get NIC

driver name and NIC driver softc via the device(9) tree,
instead of going dirty through the ifnet(9) layer.

Differential Revision:	D1506
Reviewed by:		imp, jhb
This commit is contained in:
Gleb Smirnoff 2015-01-12 22:27:38 +00:00
parent 4882501b5c
commit 7e310d2d50
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=277093
12 changed files with 52 additions and 29 deletions

View File

@ -198,7 +198,6 @@ brgphy_attach(device_t dev)
struct bge_softc *bge_sc = NULL;
struct bce_softc *bce_sc = NULL;
struct mii_softc *sc;
if_t ifp;
bsc = device_get_softc(dev);
sc = &bsc->mii_sc;
@ -207,13 +206,12 @@ brgphy_attach(device_t dev)
&brgphy_funcs, 0);
bsc->serdes_flags = 0;
ifp = sc->mii_pdata->mii_ifp;
/* Find the MAC driver associated with this PHY. */
if (strcmp(if_getdname(ifp), "bge") == 0)
bge_sc = if_getsoftc(ifp);
else if (strcmp(if_getdname(ifp), "bce") == 0)
bce_sc = if_getsoftc(ifp);
if (mii_dev_mac_match(dev, "bge"))
bge_sc = mii_dev_mac_softc(dev);
else if (mii_dev_mac_match(dev, "bce"))
bce_sc = mii_dev_mac_softc(dev);
/* Handle any special cases based on the PHY ID */
switch (sc->mii_mpd_oui) {
@ -933,11 +931,10 @@ brgphy_reset(struct mii_softc *sc)
ifp = sc->mii_pdata->mii_ifp;
/* Find the driver associated with this PHY. */
if (strcmp(if_getdname(ifp), "bge") == 0) {
bge_sc = if_getsoftc(ifp);
} else if (strcmp(if_getdname(ifp), "bce") == 0) {
bce_sc = if_getsoftc(ifp);
}
if (mii_phy_mac_match(sc, "bge"))
bge_sc = mii_phy_mac_softc(sc);
else if (mii_phy_mac_match(sc, "bce"))
bce_sc = mii_phy_mac_softc(sc);
if (bge_sc) {
/* Fix up various bugs */

View File

@ -303,8 +303,7 @@ ciphy_fixup(struct mii_softc *sc)
status = PHY_READ(sc, CIPHY_MII_AUXCSR);
speed = status & CIPHY_AUXCSR_SPEED;
if (strcmp(device_get_name(device_get_parent(sc->mii_dev)),
"nfe") == 0) {
if (mii_phy_mac_match(sc, "nfe")) {
/* need to set for 2.5V RGMII for NVIDIA adapters */
val = PHY_READ(sc, CIPHY_MII_ECTL1);
val &= ~(CIPHY_ECTL1_IOVOL | CIPHY_ECTL1_INTSEL);

View File

@ -139,8 +139,7 @@ e1000phy_attach(device_t dev)
mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &e1000phy_funcs, 0);
ifp = sc->mii_pdata->mii_ifp;
if (strcmp(if_getdname(ifp), "msk") == 0 &&
(sc->mii_flags & MIIF_MACPRIV0) != 0)
if (mii_dev_mac_match(dev, "msk") && (sc->mii_flags & MIIF_MACPRIV0) != 0)
sc->mii_flags |= MIIF_PHYPRIV0;
switch (sc->mii_mpd_model) {

View File

@ -110,7 +110,7 @@ ip1000phy_attach(device_t dev)
ma = device_get_ivars(dev);
flags = MIIF_NOISOLATE | MIIF_NOMANPAUSE;
if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxICPLUS_IP1000A &&
strcmp(if_getdname(ma->mii_data->mii_ifp), "stge") == 0 &&
mii_dev_mac_match(dev, "stge") &&
(miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
flags |= MIIF_PHYPRIV0;
mii_phy_dev_attach(dev, flags, &ip1000phy_funcs, 1);

View File

@ -105,7 +105,7 @@ jmphy_attach(device_t dev)
ma = device_get_ivars(dev);
flags = 0;
if (strcmp(if_getdname(ma->mii_data->mii_ifp), "jme") == 0 &&
if (mii_dev_mac_match(dev, "jme") &&
(miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
flags |= MIIF_PHYPRIV0;
mii_phy_dev_attach(dev, flags, &jmphy_funcs, 1);

View File

@ -645,3 +645,33 @@ mii_oui(u_int id1, u_int id2)
(mii_bitreverse((h >> 8) & 0xff) << 8) |
mii_bitreverse(h & 0xff));
}
int
mii_phy_mac_match(struct mii_softc *mii, const char *name)
{
return (strcmp(device_get_name(device_get_parent(mii->mii_dev)),
name) == 0);
}
int
mii_dev_mac_match(device_t parent, const char *name)
{
return (strcmp(device_get_name(device_get_parent(
device_get_parent(parent))), name) == 0);
}
void *
mii_phy_mac_softc(struct mii_softc *mii)
{
return (device_get_softc(device_get_parent(mii->mii_dev)));
}
void *
mii_dev_mac_softc(device_t parent)
{
return (device_get_softc(device_get_parent(device_get_parent(parent))));
}

View File

@ -263,6 +263,10 @@ void mii_phy_reset(struct mii_softc *);
void mii_phy_setmedia(struct mii_softc *sc);
void mii_phy_update(struct mii_softc *, int);
int mii_phy_tick(struct mii_softc *);
int mii_phy_mac_match(struct mii_softc *, const char *);
int mii_dev_mac_match(device_t, const char *);
void *mii_phy_mac_softc(struct mii_softc *);
void *mii_dev_mac_softc(device_t);
const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma,
const struct mii_phydesc *mpd);

View File

@ -128,8 +128,7 @@ mlphy_probe(dev)
* encountered the 6692 on an Olicom card with a ThunderLAN
* controller chip.
*/
if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
"tl") != 0)
if (!mii_dev_mac_match(dev, "tl"))
return (ENXIO);
device_set_desc(dev, "Micro Linear 6692 media interface");

View File

@ -129,15 +129,13 @@ nsphy_probe(device_t dev)
static int
nsphy_attach(device_t dev)
{
const char *nic;
u_int flags;
nic = device_get_name(device_get_parent(device_get_parent(dev)));
flags = MIIF_NOMANPAUSE;
/*
* Am79C971 wedge when isolating all of their external PHYs.
*/
if (strcmp(nic, "pcn") == 0)
if (mii_dev_mac_match(dev,"pcn"))
flags |= MIIF_NOISOLATE;
mii_phy_dev_attach(dev, flags, &nsphy_funcs, 1);
return (0);
@ -186,7 +184,7 @@ nsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
*/
reg |= 0x0100 | 0x0400;
if (strcmp(if_getdname(mii->mii_ifp), "fxp") == 0)
if (mii_phy_mac_match(sc, "fxp"))
PHY_WRITE(sc, MII_NSPHY_PCR, reg);
mii_phy_setmedia(sc);

View File

@ -119,7 +119,7 @@ rgephy_attach(device_t dev)
sc = device_get_softc(dev);
ma = device_get_ivars(dev);
flags = 0;
if (strcmp(if_getdname(ma->mii_data->mii_ifp), "re") == 0)
if (mii_dev_mac_match(dev, "re"))
flags |= MIIF_PHYPRIV0;
mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);

View File

@ -108,15 +108,13 @@ static const struct mii_phy_funcs rlphy_funcs = {
static int
rlphy_probe(device_t dev)
{
const char *nic;
int rv;
rv = mii_phy_dev_probe(dev, rlphys, BUS_PROBE_DEFAULT);
if (rv <= 0)
return (rv);
nic = device_get_name(device_get_parent(device_get_parent(dev)));
if (strcmp(nic, "rl") == 0 || strcmp(nic, "re") == 0)
if (mii_dev_mac_match(dev, "rl") || mii_dev_mac_match(dev, "re"))
return (mii_phy_dev_probe(dev, rlintphys, BUS_PROBE_DEFAULT));
return (ENXIO);
}

View File

@ -130,8 +130,7 @@ static int
tlphy_probe(device_t dev)
{
if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
"tl") != 0)
if (!mii_dev_mac_match(dev, "tl"))
return (ENXIO);
return (mii_phy_dev_probe(dev, tlphys, BUS_PROBE_DEFAULT));
}