aboutsummaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/mii/brgphy.c19
-rw-r--r--sys/dev/mii/ciphy.c3
-rw-r--r--sys/dev/mii/e1000phy.c3
-rw-r--r--sys/dev/mii/ip1000phy.c2
-rw-r--r--sys/dev/mii/jmphy.c2
-rw-r--r--sys/dev/mii/mii.c30
-rw-r--r--sys/dev/mii/miivar.h4
-rw-r--r--sys/dev/mii/mlphy.c3
-rw-r--r--sys/dev/mii/nsphy.c6
-rw-r--r--sys/dev/mii/rgephy.c2
-rw-r--r--sys/dev/mii/rlphy.c4
-rw-r--r--sys/dev/mii/tlphy.c3
12 files changed, 52 insertions, 29 deletions
diff --git a/sys/dev/mii/brgphy.c b/sys/dev/mii/brgphy.c
index dba35a02224db..54beed471133b 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 1b7eb7747b9d2..2d2816cddf0ab 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 468b718ab71b1..3396d93eaba08 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 ba98286d630c1..284af49b1e04b 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 a61670e7a81ab..1cb1b56f13ad5 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 555dc0599d1ca..77c13470db1b1 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 52a9abcf7dd98..2956b6b2f15da 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 eb6aa4c660746..fbb34819a96d8 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 fd5472c09078a..748e02a419916 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 381ca47452c26..899ca0425df03 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 21c9a66f6cf4f..782fc3c807b53 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 52300db389dd7..9f6f8cea408c6 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));
}