summaryrefslogtreecommitdiffstats
path: root/sys/dev/mii
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2010-10-24 12:51:02 +0000
committermarius <marius@FreeBSD.org>2010-10-24 12:51:02 +0000
commit528da28c69d8d91f4821e446dfab3b9d8701857c (patch)
tree3a99214e2bf91c6201a9888bd1895b2da197a9fa /sys/dev/mii
parent211ad2b3d37af0cd970ea0a19d1d82177744010e (diff)
downloadFreeBSD-src-528da28c69d8d91f4821e446dfab3b9d8701857c.zip
FreeBSD-src-528da28c69d8d91f4821e446dfab3b9d8701857c.tar.gz
- Add IFM_10_2 and IFM_10_5 media via tlphy(4) only in case the respective
interface also has such connectors. - In tl_attach() unify three different ways of obtaining the device and vendor IDs and remove the now obsolete tl_dinfo from tl_softc. - Given that tlphy(4) only handles the integrated PHYs of NICs driven by tl(4) make it only probe on the latter. - Switch mlphy(4) and tlphy(4) to use mii_phy_add_media()/mii_phy_setmedia(). - Simplify looking for the respective companion PHY in mlphy(4) and tlphy(4) by ignoring the native one by just comparing the device_t's directly rather than the device name.
Diffstat (limited to 'sys/dev/mii')
-rw-r--r--sys/dev/mii/mlphy.c41
-rw-r--r--sys/dev/mii/tlphy.c61
2 files changed, 52 insertions, 50 deletions
diff --git a/sys/dev/mii/mlphy.c b/sys/dev/mii/mlphy.c
index 04e4b80..ccfcd79 100644
--- a/sys/dev/mii/mlphy.c
+++ b/sys/dev/mii/mlphy.c
@@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$");
struct mlphy_softc {
struct mii_softc ml_mii;
+ device_t ml_dev;
int ml_state;
int ml_linked;
};
@@ -96,6 +97,7 @@ static driver_t mlphy_driver = {
DRIVER_MODULE(mlphy, miibus, mlphy_driver, mlphy_devclass, 0, 0);
+static struct mii_softc *mlphy_find_other(struct mlphy_softc *);
static int mlphy_service(struct mii_softc *, struct mii_data *, int);
static void mlphy_reset(struct mii_softc *);
static void mlphy_status(struct mii_softc *);
@@ -105,10 +107,8 @@ mlphy_probe(dev)
device_t dev;
{
struct mii_attach_args *ma;
- device_t parent;
ma = device_get_ivars(dev);
- parent = device_get_parent(device_get_parent(dev));
/*
* Micro Linear PHY reports oui == 0 model == 0
@@ -122,7 +122,8 @@ mlphy_probe(dev)
* encountered the 6692 on an Olicom card with a ThunderLAN
* controller chip.
*/
- if (strcmp(device_get_name(parent), "tl") != 0)
+ if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
+ "tl") != 0)
return (ENXIO);
device_set_desc(dev, "Micro Linear 6692 media interface");
@@ -141,6 +142,7 @@ mlphy_attach(dev)
msc = device_get_softc(dev);
sc = &msc->ml_mii;
+ msc->ml_dev = dev;
ma = device_get_ivars(dev);
sc->mii_dev = device_get_parent(dev);
mii = ma->mii_data;
@@ -155,14 +157,15 @@ mlphy_attach(dev)
#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
- BMCR_LOOP|BMCR_S100);
+ MII_MEDIA_100_TX);
mii_phy_reset(sc);
sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ /* Let the companion PHY (if any) only handle the media we don't. */
ma->mii_capmask = ~sc->mii_capabilities;
device_printf(dev, " ");
- mii_add_media(sc);
+ mii_phy_add_media(sc);
printf("\n");
#undef ADD
MIIBUS_MEDIAINIT(sc->mii_dev);
@@ -170,20 +173,21 @@ mlphy_attach(dev)
}
static struct mii_softc *
-mlphy_find_other(device_t mii)
+mlphy_find_other(struct mlphy_softc *msc)
{
device_t *devlist;
struct mii_softc *retval;
int i, devs;
retval = NULL;
- if (device_get_children(mii, &devlist, &devs))
+ if (device_get_children(msc->ml_mii.mii_dev, &devlist, &devs) != 0)
return (NULL);
- for (i = 0; i < devs; i++)
- if (strcmp(device_get_name(devlist[i]), "mlphy")) {
+ for (i = 0; i < devs; i++) {
+ if (devlist[i] != msc->ml_dev) {
retval = device_get_softc(devlist[i]);
break;
}
+ }
free(devlist, M_TEMP);
return (retval);
}
@@ -204,7 +208,7 @@ mlphy_service(xsc, mii, cmd)
* See if there's another PHY on this bus with us.
* If so, we may need it for 10Mbps modes.
*/
- other = mlphy_find_other(msc->ml_mii.mii_dev);
+ other = mlphy_find_other(msc);
switch (cmd) {
case MII_POLLSTAT:
@@ -229,7 +233,7 @@ mlphy_service(xsc, mii, cmd)
mii_phy_reset(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
- (void) mii_phy_auto(sc);
+ (void)mii_phy_auto(sc);
msc->ml_linked = 0;
return (0);
case IFM_10_T:
@@ -246,8 +250,7 @@ mlphy_service(xsc, mii, cmd)
mii_phy_reset(other);
PHY_WRITE(other, MII_BMCR, ife->ifm_data);
}
- PHY_WRITE(sc, MII_ANAR, mii_anar(ife->ifm_media));
- PHY_WRITE(sc, MII_BMCR, ife->ifm_data);
+ mii_phy_setmedia(sc);
msc->ml_state = 0;
break;
case IFM_100_TX:
@@ -262,17 +265,11 @@ mlphy_service(xsc, mii, cmd)
mii_phy_reset(other);
PHY_WRITE(other, MII_BMCR, BMCR_ISO);
}
- PHY_WRITE(sc, MII_ANAR, mii_anar(ife->ifm_media));
- PHY_WRITE(sc, MII_BMCR, ife->ifm_data);
+ mii_phy_setmedia(sc);
msc->ml_state = 0;
break;
- case IFM_100_T4:
- /*
- * XXX Not supported as a manual setting right now.
- */
- return (EINVAL);
default:
- break;
+ return (EINVAL);
}
break;
@@ -381,7 +378,7 @@ mlphy_status(sc)
struct mii_softc *other = NULL;
/* See if there's another PHY on the bus with us. */
- other = mlphy_find_other(msc->ml_mii.mii_dev);
+ other = mlphy_find_other(msc);
if (other == NULL)
return;
diff --git a/sys/dev/mii/tlphy.c b/sys/dev/mii/tlphy.c
index e618611..d23cfb3 100644
--- a/sys/dev/mii/tlphy.c
+++ b/sys/dev/mii/tlphy.c
@@ -124,6 +124,9 @@ static int
tlphy_probe(device_t dev)
{
+ if (strcmp(device_get_name(device_get_parent(device_get_parent(dev))),
+ "tl") != 0)
+ return (ENXIO);
return (mii_phy_dev_probe(dev, tlphys, BUS_PROBE_DEFAULT));
}
@@ -150,11 +153,17 @@ tlphy_attach(device_t dev)
sc->sc_mii.mii_service = tlphy_service;
sc->sc_mii.mii_pdata = mii;
+ /*
+ * Note that if we're on a device that also supports 100baseTX,
+ * we are not going to want to use the built-in 10baseT port,
+ * since there will be another PHY on the MII wired up to the
+ * UTP connector.
+ */
capmask = BMSR_DEFCAPMASK;
if (mii->mii_instance &&
device_get_children(sc->sc_mii.mii_dev, &devlist, &devs) == 0) {
for (i = 0; i < devs; i++) {
- if (strcmp(device_get_name(devlist[i]), "tlphy")) {
+ if (devlist[i] != dev) {
other = device_get_softc(devlist[i]);
capmask &= ~other->mii_capabilities;
break;
@@ -167,38 +176,36 @@ tlphy_attach(device_t dev)
mii_phy_reset(&sc->sc_mii);
- /*
- * Note that if we're on a device that also supports 100baseTX,
- * we are not going to want to use the built-in 10baseT port,
- * since there will be another PHY on the MII wired up to the
- * UTP connector. The parent indicates this to us by specifying
- * the TLPHY_MEDIA_NO_10_T bit.
- */
sc->sc_mii.mii_capabilities =
PHY_READ(&sc->sc_mii, MII_BMSR) & capmask;
#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->sc_mii.mii_inst),
- BMCR_ISO);
-
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_LOOP,
- sc->sc_mii.mii_inst), BMCR_LOOP);
+ ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_LOOP, sc->sc_mii.mii_inst),
+ MII_MEDIA_100_TX);
#define PRINT(s) printf("%s%s", sep, s); sep = ", "
- device_printf(dev, " ");
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->sc_mii.mii_inst), 0);
- PRINT("10base2/BNC");
- ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc->sc_mii.mii_inst), 0);
- PRINT("10base5/AUI");
-
- if (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) {
+ if ((sc->sc_mii.mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
+ (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0)
+ device_printf(dev, " ");
+ if ((sc->sc_mii.mii_flags & MIIF_MACPRIV0) != 0) {
+ ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->sc_mii.mii_inst),
+ 0);
+ PRINT("10base2/BNC");
+ }
+ if ((sc->sc_mii.mii_flags & MIIF_MACPRIV1) != 0) {
+ ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0, sc->sc_mii.mii_inst),
+ 0);
+ PRINT("10base5/AUI");
+ }
+ if ((sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0) {
printf("%s", sep);
- mii_add_media(&sc->sc_mii);
+ mii_phy_add_media(&sc->sc_mii);
}
-
- printf("\n");
+ if ((sc->sc_mii.mii_flags & (MIIF_MACPRIV0 | MIIF_MACPRIV1)) != 0 &&
+ (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) != 0)
+ printf("\n");
#undef ADD
#undef PRINT
MIIBUS_MEDIAINIT(sc->sc_mii.mii_dev);
@@ -233,7 +240,7 @@ tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
* an autonegotiation cycle, so there's no such
* thing as "already in auto mode".
*/
- (void) tlphy_auto(sc);
+ (void)tlphy_auto(sc);
break;
case IFM_10_2:
case IFM_10_5:
@@ -244,9 +251,7 @@ tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
default:
PHY_WRITE(&sc->sc_mii, MII_TLPHY_CTRL, 0);
DELAY(100000);
- PHY_WRITE(&sc->sc_mii, MII_ANAR,
- mii_anar(ife->ifm_media));
- PHY_WRITE(&sc->sc_mii, MII_BMCR, ife->ifm_data);
+ mii_phy_setmedia(&sc->sc_mii);
}
break;
@@ -283,7 +288,7 @@ tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
sc->sc_mii.mii_ticks = 0;
mii_phy_reset(&sc->sc_mii);
- tlphy_auto(sc);
+ (void)tlphy_auto(sc);
return (0);
}
OpenPOWER on IntegriCloud