diff options
author | glebius <glebius@FreeBSD.org> | 2015-01-12 22:27:38 +0000 |
---|---|---|
committer | glebius <glebius@FreeBSD.org> | 2015-01-12 22:27:38 +0000 |
commit | 360e8758b24e9bfdf37d37fc84f0d003a876b186 (patch) | |
tree | 2ebdcab3a6a9c5b84714d1641f3f96996eccb9e3 /sys/dev/mii | |
parent | c3135c03925ede4077aa3906d9513f436f36d18e (diff) | |
download | FreeBSD-src-360e8758b24e9bfdf37d37fc84f0d003a876b186.zip FreeBSD-src-360e8758b24e9bfdf37d37fc84f0d003a876b186.tar.gz |
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
Diffstat (limited to 'sys/dev/mii')
-rw-r--r-- | sys/dev/mii/brgphy.c | 19 | ||||
-rw-r--r-- | sys/dev/mii/ciphy.c | 3 | ||||
-rw-r--r-- | sys/dev/mii/e1000phy.c | 3 | ||||
-rw-r--r-- | sys/dev/mii/ip1000phy.c | 2 | ||||
-rw-r--r-- | sys/dev/mii/jmphy.c | 2 | ||||
-rw-r--r-- | sys/dev/mii/mii.c | 30 | ||||
-rw-r--r-- | sys/dev/mii/miivar.h | 4 | ||||
-rw-r--r-- | sys/dev/mii/mlphy.c | 3 | ||||
-rw-r--r-- | sys/dev/mii/nsphy.c | 6 | ||||
-rw-r--r-- | sys/dev/mii/rgephy.c | 2 | ||||
-rw-r--r-- | sys/dev/mii/rlphy.c | 4 | ||||
-rw-r--r-- | sys/dev/mii/tlphy.c | 3 |
12 files changed, 52 insertions, 29 deletions
diff --git a/sys/dev/mii/brgphy.c b/sys/dev/mii/brgphy.c index dba35a0..54beed4 100644 --- a/sys/dev/mii/brgphy.c +++ b/sys/dev/mii/brgphy.c @@ -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 */ diff --git a/sys/dev/mii/ciphy.c b/sys/dev/mii/ciphy.c index 1b7eb77..2d2816c 100644 --- a/sys/dev/mii/ciphy.c +++ b/sys/dev/mii/ciphy.c @@ -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); diff --git a/sys/dev/mii/e1000phy.c b/sys/dev/mii/e1000phy.c index 468b718..3396d93 100644 --- a/sys/dev/mii/e1000phy.c +++ b/sys/dev/mii/e1000phy.c @@ -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) { diff --git a/sys/dev/mii/ip1000phy.c b/sys/dev/mii/ip1000phy.c index ba98286..284af49 100644 --- a/sys/dev/mii/ip1000phy.c +++ b/sys/dev/mii/ip1000phy.c @@ -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); diff --git a/sys/dev/mii/jmphy.c b/sys/dev/mii/jmphy.c index a61670e..1cb1b56 100644 --- a/sys/dev/mii/jmphy.c +++ b/sys/dev/mii/jmphy.c @@ -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); diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c index 555dc05..77c1347 100644 --- a/sys/dev/mii/mii.c +++ b/sys/dev/mii/mii.c @@ -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)))); +} diff --git a/sys/dev/mii/miivar.h b/sys/dev/mii/miivar.h index 52a9abc..2956b6b 100644 --- a/sys/dev/mii/miivar.h +++ b/sys/dev/mii/miivar.h @@ -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); diff --git a/sys/dev/mii/mlphy.c b/sys/dev/mii/mlphy.c index eb6aa4c..fbb3481 100644 --- a/sys/dev/mii/mlphy.c +++ b/sys/dev/mii/mlphy.c @@ -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"); diff --git a/sys/dev/mii/nsphy.c b/sys/dev/mii/nsphy.c index fd5472c..748e02a 100644 --- a/sys/dev/mii/nsphy.c +++ b/sys/dev/mii/nsphy.c @@ -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); diff --git a/sys/dev/mii/rgephy.c b/sys/dev/mii/rgephy.c index 381ca47..899ca04 100644 --- a/sys/dev/mii/rgephy.c +++ b/sys/dev/mii/rgephy.c @@ -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); diff --git a/sys/dev/mii/rlphy.c b/sys/dev/mii/rlphy.c index 21c9a66..782fc3c 100644 --- a/sys/dev/mii/rlphy.c +++ b/sys/dev/mii/rlphy.c @@ -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); } diff --git a/sys/dev/mii/tlphy.c b/sys/dev/mii/tlphy.c index 52300db..9f6f8ce 100644 --- a/sys/dev/mii/tlphy.c +++ b/sys/dev/mii/tlphy.c @@ -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)); } |