コード例 #1
0
ファイル: igphy.c プロジェクト: yazshel/netbsd-kernel
static void
igphy_smartspeed_workaround(struct mii_softc *sc)
{
	struct igphy_softc *igsc = (struct igphy_softc *) sc;
	uint16_t reg, gtsr, gtcr;

	/* This workaround is only for 82541 and 82547 */
	switch (igsc->sc_mactype) {
	case WM_T_82541:
	case WM_T_82541_2:
	case WM_T_82547:
	case WM_T_82547_2:
		break;
	default:
		/* byebye */	
		return;
	}

	if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0)
		return;

	/* XXX Assume 1000TX-FDX is advertized if doing autonegotiation. */

	reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
	if ((reg & BMSR_LINK) == 0) {
		switch (igsc->sc_smartspeed) {
		case 0:
			gtsr = PHY_READ(sc, MII_100T2SR);
			if (!(gtsr & GTSR_MAN_MS_FLT))
				break;
			gtsr = PHY_READ(sc, MII_100T2SR);
			if (gtsr & GTSR_MAN_MS_FLT) {
				gtcr = PHY_READ(sc, MII_100T2CR);
				if (gtcr & GTCR_MAN_MS) {
					gtcr &= ~GTCR_MAN_MS;
					PHY_WRITE(sc, MII_100T2CR,
					    gtcr);
				}
				mii_phy_auto(sc, 0);
			}
			break;
		case IGPHY_TICK_DOWNSHIFT:
			gtcr = PHY_READ(sc, MII_100T2CR);
			gtcr |= GTCR_MAN_MS;
			PHY_WRITE(sc, MII_100T2CR, gtcr);
			mii_phy_auto(sc, 0);
			break;
		default:
			break;
		}
		if (igsc->sc_smartspeed++ == IGPHY_TICK_MAX)
			igsc->sc_smartspeed = 0;
	} else
		igsc->sc_smartspeed = 0;
}
コード例 #2
0
static int
tlphy_auto(struct tlphy_softc *sc, int waitfor)
{
	int error;

	switch ((error = mii_phy_auto(&sc->sc_mii, waitfor))) {
	case EIO:
		/*
		 * Just assume we're not in full-duplex mode.
		 * XXX Check link and try AUI/BNC?
		 */
		PHY_WRITE(&sc->sc_mii, MII_BMCR, 0);
		break;

	case EJUSTRETURN:
		/* Flag that we need to program when it completes. */
		sc->sc_need_acomp = 1;
		break;

	default:
		tlphy_acomp(sc);
	}

	return (error);
}
コード例 #3
0
/*
 * If we negotiate a 10Mbps mode, we need to check for an alternate
 * PHY and make sure it's enabled and set correctly.
 */
void
mlphy_status(struct mii_softc *sc)
{
    struct mlphy_softc *msc = (struct mlphy_softc *)sc;
    struct mii_data *mii = sc->mii_pdata;
    struct mii_softc *other = NULL;

    /* See if there's another PHY on the bus with us. */
    LIST_FOREACH(other, &mii->mii_phys, mii_list)
    if (other != sc)
        break;

    ukphy_status(sc);

    if (IFM_SUBTYPE(mii->mii_media_active) != IFM_10_T) {
        msc->ml_state = ML_STATE_AUTO_SELF;
        if (other != NULL) {
            mii_phy_reset(other);
            PHY_WRITE(other, MII_BMCR, BMCR_ISO);
        }
    }

    if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) {
        msc->ml_state = ML_STATE_AUTO_OTHER;
        mlphy_reset(&msc->ml_mii);
        PHY_WRITE(&msc->ml_mii, MII_BMCR, BMCR_ISO);
        if (other != NULL) {
            mii_phy_reset(other);
            mii_phy_auto(other, 1);
        }
    }
}
コード例 #4
0
void
mii_phy_setmedia(struct mii_softc *sc)
{
	struct mii_data *mii = sc->mii_pdata;
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int bmcr, anar, gtcr;

	if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
		/*
		 * Force renegotiation if MIIF_DOPAUSE or MIIF_FORCEANEG.
		 * The former is necessary as we might switch from flow-
		 * control advertisment being off to on or vice versa.
		 */
		if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0 ||
		    (sc->mii_flags & (MIIF_DOPAUSE | MIIF_FORCEANEG)) != 0)
			(void)mii_phy_auto(sc);
		return;
	}

	/*
	 * Table index is stored in the media entry.
	 */

	KASSERT(ife->ifm_data >=0 && ife->ifm_data < MII_NMEDIA,
	    ("invalid ife->ifm_data (0x%x) in mii_phy_setmedia",
	    ife->ifm_data));

	anar = mii_media_table[ife->ifm_data].mm_anar;
	bmcr = mii_media_table[ife->ifm_data].mm_bmcr;
	gtcr = mii_media_table[ife->ifm_data].mm_gtcr;

	if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
		gtcr |= GTCR_MAN_MS;
		if ((ife->ifm_media & IFM_ETH_MASTER) != 0)
			gtcr |= GTCR_ADV_MS;
	}

	if ((ife->ifm_media & IFM_GMASK) == (IFM_FDX | IFM_FLOW) ||
	    (sc->mii_flags & MIIF_FORCEPAUSE) != 0) {
		if ((sc->mii_flags & MIIF_IS_1000X) != 0)
			anar |= ANAR_X_PAUSE_TOWARDS;
		else {
			anar |= ANAR_FC;
			/* XXX Only 1000BASE-T has PAUSE_ASYM? */
			if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0 &&
			    (sc->mii_extcapabilities &
			    (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0)
				anar |= ANAR_X_PAUSE_ASYM;
		}
	}

	if ((ife->ifm_media & IFM_LOOP) != 0)
		bmcr |= BMCR_LOOP;

	PHY_WRITE(sc, MII_ANAR, anar);
	PHY_WRITE(sc, MII_BMCR, bmcr);
	if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0)
		PHY_WRITE(sc, MII_100T2CR, gtcr);
}
コード例 #5
0
ファイル: fbsd_mii_physubr.c プロジェクト: mariuz/haiku
int
mii_phy_tick(struct mii_softc *sc)
{
	struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur;
	struct ifnet *ifp = sc->mii_pdata->mii_ifp;
	int reg;

	/* Just bail now if the interface is down. */
	if ((ifp->if_flags & IFF_UP) == 0)
		return (EJUSTRETURN);

	/*
	 * If we're not doing autonegotiation, we don't need to do
	 * any extra work here.  However, we need to check the link
	 * status so we can generate an announcement if the status
	 * changes.
	 */
	if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) {
		sc->mii_ticks = 0;	/* reset autonegotiation timer. */
		return (0);
	}

	/* Read the status register twice; BMSR_LINK is latch-low. */
	reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
	if (reg & BMSR_LINK) {
		sc->mii_ticks = 0;	/* reset autonegotiation timer. */
		/* See above. */
		return (0);
	}

	/* Announce link loss right after it happens */
	if (sc->mii_ticks++ == 0)
		return (0);

	/* XXX: use default value if phy driver did not set mii_anegticks */
	if (sc->mii_anegticks == 0)
		sc->mii_anegticks = MII_ANEGTICKS_GIGE;

	/* Only retry autonegotiation every mii_anegticks ticks. */
	if (sc->mii_ticks <= sc->mii_anegticks)
		return (EJUSTRETURN);

	sc->mii_ticks = 0;
	mii_phy_reset(sc);
	mii_phy_auto(sc);
	return (0);
}
コード例 #6
0
void
mii_phy_setmedia(struct mii_softc *sc)
{
	struct mii_data *mii = sc->mii_pdata;
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int bmcr, anar, gtcr;

	if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
		if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0 ||
		    (sc->mii_flags & MIIF_FORCEANEG))
			(void) mii_phy_auto(sc, 1);
		return;
	}

	/*
	 * Table index is stored in the media entry.
	 */
#ifdef DIAGNOSTIC
	if (ife->ifm_data < 0 || ife->ifm_data >= MII_NMEDIA)
		panic("mii_phy_setmedia");
#endif

	anar = mii_media_table[ife->ifm_data].mm_anar;
	bmcr = mii_media_table[ife->ifm_data].mm_bmcr;
	gtcr = mii_media_table[ife->ifm_data].mm_gtcr;

	if (mii->mii_media.ifm_media & IFM_ETH_MASTER) {
		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_1000_T:
			gtcr |= GTCR_MAN_MS|GTCR_ADV_MS;
			break;

		default:
			panic("mii_phy_setmedia: MASTER on wrong media");
		}
	}

	if (ife->ifm_media & IFM_LOOP)
		bmcr |= BMCR_LOOP;

	PHY_WRITE(sc, MII_ANAR, anar);
	PHY_WRITE(sc, MII_BMCR, bmcr);
	if (sc->mii_flags & MIIF_HAVE_GTCR)
		PHY_WRITE(sc, MII_100T2CR, gtcr);
}
コード例 #7
0
ファイル: mlphy.c プロジェクト: Gwenio/DragonFlyBSD
/*
 * If we negotiate a 10Mbps mode, we need to check for an alternate
 * PHY and make sure it's enabled and set correctly.
 */
static void
mlphy_status(struct mii_softc *sc)
{
	struct mlphy_softc	*msc = (struct mlphy_softc *)sc;
	struct mii_data		*mii = msc->ml_mii.mii_pdata;
	struct mii_softc	*other = NULL;
	device_t		*devlist;
	int			devs, i;

	/* See if there's another PHY on the bus with us. */
	device_get_children(msc->ml_mii.mii_dev, &devlist, &devs);
	for (i = 0; i < devs; i++) {
		if (strcmp(device_get_name(devlist[i]), "mlphy")) {
			other = device_get_softc(devlist[i]);
			break;
		}
	}
	kfree(devlist, M_TEMP);

	if (other == NULL)
		return;

	ukphy_status(sc);

	if (IFM_SUBTYPE(mii->mii_media_active) != IFM_10_T) {
		msc->ml_state = ML_STATE_AUTO_SELF;
		mii_phy_reset(other);
		PHY_WRITE(other, MII_BMCR, BMCR_ISO);
	}

	if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) {
		msc->ml_state = ML_STATE_AUTO_OTHER;
		mlphy_reset(&msc->ml_mii);
		PHY_WRITE(&msc->ml_mii, MII_BMCR, BMCR_ISO);
		mii_phy_reset(other);
		mii_phy_auto(other, 1);
	}
}
コード例 #8
0
ファイル: mii_physubr.c プロジェクト: hmatyschok/MeshBSD
void
mii_phy_setmedia(struct mii_softc *sc)
{
	struct mii_data *mii = sc->mii_pdata;
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int bmcr, anar, gtcr;
	int index = -1;

	switch (IFM_SUBTYPE(ife->ifm_media)) {
	case IFM_AUTO:
		/*
		 * Force renegotiation if MIIF_DOPAUSE or MIIF_FORCEANEG.
		 * The former is necessary as we might switch from flow-
		 * control advertisement being off to on or vice versa.
		 */
		if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0 ||
		    (sc->mii_flags & (MIIF_DOPAUSE | MIIF_FORCEANEG)) != 0)
			(void)mii_phy_auto(sc);
		return;

	case IFM_NONE:
		index = MII_MEDIA_NONE;
		break;

	case IFM_HPNA_1:
		index = MII_MEDIA_10_T;
		break;

	case IFM_10_T:
		switch (IFM_OPTIONS(ife->ifm_media)) {
		case 0:
			index = MII_MEDIA_10_T;
			break;
		case IFM_FDX:
		case (IFM_FDX | IFM_FLOW):
			index = MII_MEDIA_10_T_FDX;
			break;
		}
		break;

	case IFM_100_TX:
	case IFM_100_FX:
		switch (IFM_OPTIONS(ife->ifm_media)) {
		case 0:
			index = MII_MEDIA_100_TX;
			break;
		case IFM_FDX:
		case (IFM_FDX | IFM_FLOW):
			index = MII_MEDIA_100_TX_FDX;
			break;
		}
		break;

	case IFM_100_T4:
		index = MII_MEDIA_100_T4;
		break;

	case IFM_1000_SX:
		switch (IFM_OPTIONS(ife->ifm_media)) {
		case 0:
			index = MII_MEDIA_1000_X;
			break;
		case IFM_FDX:
		case (IFM_FDX | IFM_FLOW):
			index = MII_MEDIA_1000_X_FDX;
			break;
		}
		break;

	case IFM_1000_T:
		switch (IFM_OPTIONS(ife->ifm_media)) {
		case 0:
		case IFM_ETH_MASTER:
			index = MII_MEDIA_1000_T;
			break;
		case IFM_FDX:
		case (IFM_FDX | IFM_ETH_MASTER):
		case (IFM_FDX | IFM_FLOW):
		case (IFM_FDX | IFM_FLOW | IFM_ETH_MASTER):
			index = MII_MEDIA_1000_T_FDX;
			break;
		}
		break;
	}

	KASSERT(index != -1, ("%s: failed to map media word %d",
	    __func__, ife->ifm_media));

	anar = mii_media_table[index].mm_anar;
	bmcr = mii_media_table[index].mm_bmcr;
	gtcr = mii_media_table[index].mm_gtcr;

	if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
		gtcr |= GTCR_MAN_MS;
		if ((ife->ifm_media & IFM_ETH_MASTER) != 0)
			gtcr |= GTCR_ADV_MS;
	}

	if ((ife->ifm_media & IFM_FDX) != 0 &&
	    ((ife->ifm_media & IFM_FLOW) != 0 ||
	    (sc->mii_flags & MIIF_FORCEPAUSE) != 0)) {
		if ((sc->mii_flags & MIIF_IS_1000X) != 0)
			anar |= ANAR_X_PAUSE_TOWARDS;
		else {
			anar |= ANAR_FC;
			/* XXX Only 1000BASE-T has PAUSE_ASYM? */
			if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0 &&
			    (sc->mii_extcapabilities &
			    (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0)
				anar |= ANAR_X_PAUSE_ASYM;
		}
	}

	PHY_WRITE(sc, MII_ANAR, anar);
	PHY_WRITE(sc, MII_BMCR, bmcr);
	if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0)
		PHY_WRITE(sc, MII_100T2CR, gtcr);
}
コード例 #9
0
ファイル: rlphy.c プロジェクト: Tommmster/netbsd-avr32
int
rlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;

	int rv;

	/*
	 * Can't isolate the RTL8139 phy, so it has to be the only one.
	 */
	if (IFM_INST(ife->ifm_media) != sc->mii_inst)
		panic("rlphy_service: attempt to isolate phy");

	switch (cmd) {
	case MII_POLLSTAT:
		break;

	case MII_MEDIACHG:
		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_AUTO:
			/*
			 * If we're already in auto mode, just return.
			 */
			if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
				return (0);
			(void) mii_phy_auto(sc, 0);
			break;
		case IFM_100_T4:
			/*
			 * XXX Not supported as a manual setting right now.
			 */
			return (EINVAL);
		default:
			/*
			 * BMCR data is stored in the ifmedia entry.
			 */
			switch (ife->ifm_media &
			    (IFM_TMASK|IFM_NMASK|IFM_FDX)) {
				case IFM_ETHER|IFM_10_T:
					rv = ANAR_10|ANAR_CSMA;
					break;
				case IFM_ETHER|IFM_10_T|IFM_FDX:
					rv = ANAR_10_FD|ANAR_CSMA;
					break;
				case IFM_ETHER|IFM_100_TX:
					rv = ANAR_TX|ANAR_CSMA;
					break;
				case IFM_ETHER|IFM_100_TX|IFM_FDX:
					rv = ANAR_TX_FD|ANAR_CSMA;
					break;
				case IFM_ETHER|IFM_100_T4:
					rv = ANAR_T4|ANAR_CSMA;
					break;
				default:
					rv = 0;
					break;
			}

			PHY_WRITE(sc, MII_ANAR, rv);
			PHY_WRITE(sc, MII_BMCR, ife->ifm_data);
		}
		break;

	case MII_TICK:
		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * The RealTek PHY's autonegotiation doesn't need to be
		 * kicked; it continues in the background.
		 */
		break;

	case MII_DOWN:
		mii_phy_down(sc);
		return (0);
	}

	/* Update the media status. */
	mii_phy_status(sc);

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);
	return (0);
}
コード例 #10
0
ファイル: ruephy.c プロジェクト: edgar-pek/PerspicuOS
static int
ruephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg;

	switch (cmd) {
	case MII_POLLSTAT:
		break;

	case MII_MEDIACHG:
		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		mii_phy_setmedia(sc);
		break;

	case MII_TICK:
		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * Check to see if we have link.  If we do, we don't
		 * need to restart the autonegotiation process.  Read
		 * the MSR twice in case it's latched.
		 */
		reg = PHY_READ(sc, RUEPHY_MII_MSR) |
		    PHY_READ(sc, RUEPHY_MII_MSR);
		if (reg & RUEPHY_MSR_LINK)
			break;

		/* Only retry autonegotiation every mii_anegticks seconds. */
		if (sc->mii_ticks <= sc->mii_anegticks)
			break;

		sc->mii_ticks = 0;
		PHY_RESET(sc);
		if (mii_phy_auto(sc) == EJUSTRETURN)
			return (0);
		break;
	}

	/* Update the media status. */
	PHY_STATUS(sc);

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);

	return (0);
}
コード例 #11
0
ファイル: ciphy.c プロジェクト: ChaosJohn/freebsd
static int
ciphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg, speed, gig;

	switch (cmd) {
	case MII_POLLSTAT:
		break;

	case MII_MEDIACHG:
		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		ciphy_fixup(sc);	/* XXX hardware bug work-around */

		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_AUTO:
#ifdef foo
			/*
			 * If we're already in auto mode, just return.
			 */
			if (PHY_READ(sc, CIPHY_MII_BMCR) & CIPHY_BMCR_AUTOEN)
				return (0);
#endif
			(void)mii_phy_auto(sc);
			break;
		case IFM_1000_T:
			speed = CIPHY_S1000;
			goto setit;
		case IFM_100_TX:
			speed = CIPHY_S100;
			goto setit;
		case IFM_10_T:
			speed = CIPHY_S10;
setit:
			if ((ife->ifm_media & IFM_FDX) != 0) {
				speed |= CIPHY_BMCR_FDX;
				gig = CIPHY_1000CTL_AFD;
			} else
				gig = CIPHY_1000CTL_AHD;

			if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
				gig |= CIPHY_1000CTL_MSE;
				if ((ife->ifm_media & IFM_ETH_MASTER) != 0)
					gig |= CIPHY_1000CTL_MSC;
				speed |=
				    CIPHY_BMCR_AUTOEN | CIPHY_BMCR_STARTNEG;
			} else
				gig = 0;
			PHY_WRITE(sc, CIPHY_MII_1000CTL, gig);
			PHY_WRITE(sc, CIPHY_MII_BMCR, speed);
			PHY_WRITE(sc, CIPHY_MII_ANAR, CIPHY_SEL_TYPE);
			break;
		case IFM_NONE:
			PHY_WRITE(sc, MII_BMCR, BMCR_ISO | BMCR_PDOWN);
			break;
		default:
			return (EINVAL);
		}
		break;

	case MII_TICK:
		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * Check to see if we have link.  If we do, we don't
		 * need to restart the autonegotiation process.  Read
		 * the BMSR twice in case it's latched.
		 */
		reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
		if (reg & BMSR_LINK)
			break;

		/* Announce link loss right after it happens. */
		if (++sc->mii_ticks == 0)
			break;
		/*
		 * Only retry autonegotiation every mii_anegticks seconds.
		 */
		if (sc->mii_ticks <= sc->mii_anegticks)
			break;

		sc->mii_ticks = 0;
		mii_phy_auto(sc);
		break;
	}

	/* Update the media status. */
	PHY_STATUS(sc);

	/*
	 * Callback if something changed. Note that we need to poke
	 * apply fixups for certain PHY revs.
	 */
	if (sc->mii_media_active != mii->mii_media_active ||
	    sc->mii_media_status != mii->mii_media_status ||
	    cmd == MII_MEDIACHG) {
		ciphy_fixup(sc);
	}
	mii_phy_update(sc, cmd);
	return (0);
}
コード例 #12
0
ファイル: ruephy.c プロジェクト: AhmadTux/DragonFlyBSD
static int
ruephy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg;

	/*
	 * We can't isolate the RealTek RTL8150 PHY,
	 * so it has to be the only one!
	 */
	KASSERT(IFM_INST(ife->ifm_media) == sc->mii_inst,
		("ruephy_service: can't isolate RealTek RTL8150 PHY"));

	switch (cmd) {
	case MII_POLLSTAT:
		break;

	case MII_MEDIACHG:
		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		if (IFM_SUBTYPE(ife->ifm_media) == IFM_100_T4) {
			/*
			 * XXX Not supported as a manual setting right now.
			 */
			return (EINVAL);
		}

		mii_phy_set_media(sc);
		break;

	case MII_TICK:
		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * Check to see if we have link.  If we do, we don't
		 * need to restart the autonegotiation process.  Read
		 * the MSR twice in case it's latched.
		 */
		reg = PHY_READ(sc, RUEPHY_MII_MSR) |
		      PHY_READ(sc, RUEPHY_MII_MSR);
		if (reg & RUEPHY_MSR_LINK) {
			sc->mii_ticks = 0;
			break;
		}

		/*
		 * Only retry autonegotiation every 5 seconds.
		 */
		if (++sc->mii_ticks != 5)
			return (0);

		sc->mii_ticks = 0;
		ruephy_reset(sc);

		if (mii_phy_auto(sc, 0) == EJUSTRETURN)
			return (0);
		break;
	}

	/* Update the media status. */
	ruephy_status(sc);

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);
	return (0);
}
コード例 #13
0
static int
ciphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg, speed, gig;

	switch (cmd) {
	case MII_POLLSTAT:
		/*
		 * If we're not polling our PHY instance, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);
		break;

	case MII_MEDIACHG:
		/*
		 * If the media indicates a different PHY instance,
		 * isolate ourselves.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
			reg = PHY_READ(sc, MII_BMCR);
			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
			return (0);
		}

		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		ciphy_fixup(sc);	/* XXX hardware bug work-around */

		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_AUTO:
#ifdef foo
			/*
			 * If we're already in auto mode, just return.
			 */
			if (PHY_READ(sc, CIPHY_MII_BMCR) & CIPHY_BMCR_AUTOEN)
				return (0);
#endif
			(void) mii_phy_auto(sc);
			break;
		case IFM_1000_T:
			speed = CIPHY_S1000;
			goto setit;
		case IFM_100_TX:
			speed = CIPHY_S100;
			goto setit;
		case IFM_10_T:
			speed = CIPHY_S10;
setit:
			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
				speed |= CIPHY_BMCR_FDX;
				gig = CIPHY_1000CTL_AFD;
			} else {
				gig = CIPHY_1000CTL_AHD;
			}

			PHY_WRITE(sc, CIPHY_MII_1000CTL, 0);
			PHY_WRITE(sc, CIPHY_MII_BMCR, speed);
			PHY_WRITE(sc, CIPHY_MII_ANAR, CIPHY_SEL_TYPE);

			if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
				break;

			PHY_WRITE(sc, CIPHY_MII_1000CTL, gig);
			PHY_WRITE(sc, CIPHY_MII_BMCR,
			    speed|CIPHY_BMCR_AUTOEN|CIPHY_BMCR_STARTNEG);

			/*
			 * When setting the link manually, one side must
			 * be the master and the other the slave. However
			 * ifmedia doesn't give us a good way to specify
			 * this, so we fake it by using one of the LINK
			 * flags. If LINK0 is set, we program the PHY to
			 * be a master, otherwise it's a slave.
			 */
			if ((mii->mii_ifp->if_flags & IFF_LINK0)) {
				PHY_WRITE(sc, CIPHY_MII_1000CTL,
				    gig|CIPHY_1000CTL_MSE|CIPHY_1000CTL_MSC);
			} else {
				PHY_WRITE(sc, CIPHY_MII_1000CTL,
				    gig|CIPHY_1000CTL_MSE);
			}
			break;
		case IFM_NONE:
			PHY_WRITE(sc, MII_BMCR, BMCR_ISO|BMCR_PDOWN);
			break;
		case IFM_100_T4:
		default:
			return (EINVAL);
		}
		break;

	case MII_TICK:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * Check to see if we have link.  If we do, we don't
		 * need to restart the autonegotiation process.  Read
		 * the BMSR twice in case it's latched.
		 */
		reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
		if (reg & BMSR_LINK)
			break;

		/* Announce link loss right after it happens. */
		if (++sc->mii_ticks == 0)
			break;
		/*
		 * Only retry autonegotiation every mii_anegticks seconds.
		 */
		if (sc->mii_ticks <= sc->mii_anegticks)
			break;

		sc->mii_ticks = 0;
		mii_phy_auto(sc);
		break;
	}

	/* Update the media status. */
	ciphy_status(sc);

	/*
	 * Callback if something changed. Note that we need to poke
	 * apply fixups for certain PHY revs.
	 */
	if (sc->mii_media_active != mii->mii_media_active ||
	    sc->mii_media_status != mii->mii_media_status ||
	    cmd == MII_MEDIACHG) {
		ciphy_fixup(sc);
	}
	mii_phy_update(sc, cmd);
	return (0);
}
コード例 #14
0
ファイル: urlphy.c プロジェクト: SylvestreG/bitrig
int
urlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg;

	DPRINTF(("%s: %s: enter\n", sc->mii_dev.dv_xname, __func__));

	if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
		return (ENXIO);

	switch (cmd) {
	case MII_POLLSTAT:
		/*
		 * If we're not polling our PHY instance, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);
		break;

	case MII_MEDIACHG:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/* If the interface is not up, don't do anything. */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		mii_phy_setmedia(sc);
		break;

	case MII_TICK:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/* Just bail now if the interface is down. */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * If we're not doing autonegotiation, we don't need to do
		 * any extra work here.  However, we need to check the link
		 * status so we can generate an announcement if the status
		 * changes.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			return (0);

		/* Read the status register twice; MSR_LINK is latch-low. */
		reg = PHY_READ(sc, URLPHY_MSR) | PHY_READ(sc, URLPHY_MSR);
		if (reg & URLPHY_MSR_LINK) {
			sc->mii_ticks = 0;
			break;
		}

		/*
	 	 * Only retry autonegotiation every mii_anegticks seconds.
		 */
		if (++sc->mii_ticks <= sc->mii_anegticks)
			return (0);

		sc->mii_ticks = 0;
		PHY_RESET(sc);

		if (mii_phy_auto(sc, 0) == EJUSTRETURN)
			return (0);

		break;

	case MII_DOWN:
		mii_phy_down(sc);
		return (0);
	}

	/* Update the media status. */
	mii_phy_status(sc);

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);

	return (0);
}
コード例 #15
0
ファイル: mii_physubr.c プロジェクト: lacombar/netbsd-alc
void
mii_phy_setmedia(struct mii_softc *sc)
{
	struct mii_data *mii = sc->mii_pdata;
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int bmcr, anar, gtcr;

	if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
		/*
		 * Force renegotiation if MIIF_DOPAUSE.
		 *
		 * XXX This is only necessary because many NICs don't
		 * XXX advertise PAUSE capabilities at boot time.  Maybe
		 * XXX we should force this only once?
		 */
		if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0 ||
		    (sc->mii_flags & (MIIF_FORCEANEG|MIIF_DOPAUSE)))
			(void) mii_phy_auto(sc, 1);
		return;
	}

	/*
	 * Table index is stored in the media entry.
	 */

#ifdef DIAGNOSTIC
	if (/* ife->ifm_data < 0 || */ ife->ifm_data >= MII_NMEDIA)
		panic("mii_phy_setmedia");
#endif

	anar = mii_media_table[ife->ifm_data].mm_anar;
	bmcr = mii_media_table[ife->ifm_data].mm_bmcr;
	gtcr = mii_media_table[ife->ifm_data].mm_gtcr;

	if (mii->mii_media.ifm_media & IFM_ETH_MASTER) {
		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_1000_T:
			gtcr |= GTCR_MAN_MS|GTCR_ADV_MS;
			break;

		default:
			panic("mii_phy_setmedia: MASTER on wrong media");
		}
	}

	if (mii->mii_media.ifm_media & IFM_FLOW) {
		if (sc->mii_flags & MIIF_IS_1000X)
			anar |= ANAR_X_PAUSE_SYM | ANAR_X_PAUSE_ASYM;
		else {
			anar |= ANAR_FC;
			/* XXX Only 1000BASE-T has PAUSE_ASYM? */
			if ((sc->mii_flags & MIIF_HAVE_GTCR) &&
			    (sc->mii_extcapabilities &
			     (EXTSR_1000THDX|EXTSR_1000TFDX)))
				anar |= ANAR_X_PAUSE_ASYM;
		}
	}

	if (ife->ifm_media & IFM_LOOP)
		bmcr |= BMCR_LOOP;

	PHY_WRITE(sc, MII_ANAR, anar);
	PHY_WRITE(sc, MII_BMCR, bmcr);
	if (sc->mii_flags & MIIF_HAVE_GTCR)
		PHY_WRITE(sc, MII_100T2CR, gtcr);
}
コード例 #16
0
int
mlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
    struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    struct mii_softc *other = NULL;
    struct mlphy_softc *msc = (struct mlphy_softc *)sc;
    int other_inst, reg;

    LIST_FOREACH(other, &mii->mii_phys, mii_list)
    if (other != sc)
        break;

    if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
        return (ENXIO);

    switch (cmd) {
    case MII_POLLSTAT:
        /*
         * If we're not polling our PHY instance, just return.
         */
        if (IFM_INST(ife->ifm_media) != sc->mii_inst)
            return (0);
        break;

    case MII_MEDIACHG:
        /*
         * If the interface is not up, don't do anything.
         */
        if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
            break;

        switch (IFM_SUBTYPE(ife->ifm_media)) {
        case IFM_AUTO:
            msc->ml_state = ML_STATE_AUTO_SELF;
            if (other != NULL) {
                mii_phy_reset(other);
                PHY_WRITE(other, MII_BMCR, BMCR_ISO);
            }
            (void)mii_phy_auto(sc, 0);
            msc->ml_linked = 0;
            break;
        case IFM_10_T:
            /*
             * For 10baseT modes, reset and program the
             * companion PHY (of any), then setup ourselves
             * to match. This will put us in pass-through
             * mode and let the companion PHY do all the
             * work.
             * BMCR data is stored in the ifmedia entry.
             */
            if (other != NULL) {
                mii_phy_reset(other);
                PHY_WRITE(other, MII_BMCR, ife->ifm_data);
            }
            mii_phy_setmedia(sc);
            msc->ml_state = 0;
            break;
        case IFM_100_TX:
            /*
             * For 100baseTX modes, reset and isolate the
             * companion PHY (if any), then setup ourselves
             * accordingly.
             *
             * BMCR data is stored in the ifmedia entry.
             */
            if (other != NULL) {
                mii_phy_reset(other);
                PHY_WRITE(other, MII_BMCR, BMCR_ISO);
            }
            mii_phy_setmedia(sc);
            msc->ml_state = 0;
            break;
        default:
            return (EINVAL);
        }
        break;
    case MII_TICK:
        /*
         * If interface is not up, don't do anything
         */
        if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
            return (0);
        /*
         * Only used for autonegotiation.
         */
        if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
            break;
        /*
         * Check to see if we have link.  If we do, we don't
         * need to restart the autonegotiation process.  Read
         * the BMSR twice in case it's latched.
         * If we're in a 10Mbps mode, check the link of the
         * 10Mbps PHY. Sometimes the Micro Linear PHY's
         * linkstat bit will clear while the linkstat bit of
         * the companion PHY will remain set.
         */
        if (msc->ml_state == ML_STATE_AUTO_OTHER) {
            reg = PHY_READ(other, MII_BMSR) |
                  PHY_READ(other, MII_BMSR);
        } else {
            reg = PHY_READ(sc, MII_BMSR) |
                  PHY_READ(sc, MII_BMSR);
        }

        if (reg & BMSR_LINK) {
            if (!msc->ml_linked) {
                msc->ml_linked = 1;
                mlphy_status(sc);
            }
            sc->mii_ticks = 0;
            break;
        }
        /*
         * Only retry autonegotiation every 5 seconds.
         */
        if (++sc->mii_ticks <= MII_ANEGTICKS)
            break;

        sc->mii_ticks = 0;
        msc->ml_linked = 0;
        mii->mii_media_active = IFM_NONE;
        mii_phy_reset(sc);
        msc->ml_state = ML_STATE_AUTO_SELF;
        if (other != NULL) {
            mii_phy_reset(other);
            PHY_WRITE(other, MII_BMCR, BMCR_ISO);
        }
        mii_phy_auto(sc, 0);
        break;

    case MII_DOWN:
        mii_phy_down(sc);
        return (0);
    }

    /* Update the media status. */
    if (msc->ml_state == ML_STATE_AUTO_OTHER && other != NULL) {
        other_inst = other->mii_inst;
        other->mii_inst = sc->mii_inst;
        if (IFM_INST(ife->ifm_media) == other->mii_inst)
            (void) PHY_SERVICE(other, mii, MII_POLLSTAT);
        other->mii_inst = other_inst;
        sc->mii_media_active = other->mii_media_active;
        sc->mii_media_status = other->mii_media_status;
    } else
        ukphy_status(sc);

    /* Callback if something changed. */
    mii_phy_update(sc, cmd);
    return (0);
}
コード例 #17
0
ファイル: mlphy.c プロジェクト: Gwenio/DragonFlyBSD
static int
mlphy_service(struct mii_softc *xsc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry	*ife = mii->mii_media.ifm_cur;
	int			reg;
	struct mii_softc	*other = NULL;
	struct mlphy_softc	*msc = (struct mlphy_softc *)xsc;
	struct mii_softc	*sc = &msc->ml_mii;
	device_t		*devlist;
	int			devs, i;
	const struct mii_media	*mm;

	/*
	 * See if there's another PHY on this bus with us.
	 * If so, we may need it for 10Mbps modes.
	 */
	device_get_children(msc->ml_mii.mii_dev, &devlist, &devs);
	for (i = 0; i < devs; i++) {
		if (strcmp(device_get_name(devlist[i]), "mlphy")) {
			other = device_get_softc(devlist[i]);
			break;
		}
	}
	kfree(devlist, M_TEMP);

	KKASSERT(ife->ifm_data >= 0 && ife->ifm_data < MII_NMEDIA);
	mm = &mii_media_table[ife->ifm_data];

	switch (cmd) {
	case MII_POLLSTAT:
		/*
		 * If we're not polling our PHY instance, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);
		break;

	case MII_MEDIACHG:
		/*
		 * If the media indicates a different PHY instance,
		 * isolate ourselves.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
			reg = PHY_READ(sc, MII_BMCR);
			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
			return (0);
		}

		/*
		 * If the interface is not up, don't do anything.
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		switch (IFM_SUBTYPE(ife->ifm_media)) {
		case IFM_AUTO:
			/*
			 * For autonegotiation, reset and isolate the
			 * companion PHY (if any) and then do NWAY
			 * autonegotiation ourselves.
			 */
			msc->ml_state = ML_STATE_AUTO_SELF;
			if (other != NULL) {
				mii_phy_reset(other);
				PHY_WRITE(other, MII_BMCR, BMCR_ISO);
			}
			mii_phy_auto(sc, 1);
			msc->ml_linked = 0;
			return(0);

		case IFM_10_T:
			/*
			 * For 10baseT modes, reset and program the
			 * companion PHY (of any), then program ourselves
			 * to match. This will put us in pass-through
			 * mode and let the companion PHY do all the
			 * work.
			 */
			if (other != NULL) {
				mii_phy_reset(other);
				PHY_WRITE(other, MII_BMCR, mm->mm_bmcr);
			}
			PHY_WRITE(sc, MII_ANAR, mm->mm_anar);
			PHY_WRITE(sc, MII_BMCR, mm->mm_bmcr);
			msc->ml_state = 0;
			break;

		case IFM_100_TX:
			/*
			 * For 100baseTX modes, reset and isolate the
			 * companion PHY (if any), then program ourselves
			 * accordingly.
			 */
			if (other != NULL) {
				mii_phy_reset(other);
				PHY_WRITE(other, MII_BMCR, BMCR_ISO);
			}
			PHY_WRITE(sc, MII_ANAR, mm->mm_anar);
			PHY_WRITE(sc, MII_BMCR, mm->mm_bmcr);
			msc->ml_state = 0;
			break;

		case IFM_100_T4:
			/*
			 * XXX Not supported as a manual setting right now.
			 */
			return (EINVAL);
		default:
			break;
		}
		break;

	case MII_TICK:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/*
		 * Is the interface even up?
		 */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * Only used for autonegotiation.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/*
		 * Check to see if we have link.  If we do, we don't
		 * need to restart the autonegotiation process.  Read
		 * the BMSR twice in case it's latched.
		 * If we're in a 10Mbps mode, check the link of the
		 * 10Mbps PHY. Sometimes the Micro Linear PHY's
		 * linkstat bit will clear while the linkstat bit of
		 * the companion PHY will remain set.
		 */
		if (msc->ml_state == ML_STATE_AUTO_OTHER) {
			reg = PHY_READ(other, MII_BMSR) |
			    PHY_READ(other, MII_BMSR);
		} else {
			reg = PHY_READ(sc, MII_BMSR) |
			    PHY_READ(sc, MII_BMSR);
		}
		if (reg & BMSR_LINK) {
			if (!msc->ml_linked) {
				msc->ml_linked = 1;
				mlphy_status(sc);
			}
			sc->mii_ticks = 0;
			break;
		}

		/*
		 * Only retry autonegotiation every 5 seconds.
		 */
		if (++sc->mii_ticks <= sc->mii_anegticks)
			return (0);
		
		sc->mii_ticks = 0;
		msc->ml_linked = 0;
		mii->mii_media_active = IFM_NONE;
		mii_phy_reset(sc);
		msc->ml_state = ML_STATE_AUTO_SELF;
		if (other != NULL) {
			mii_phy_reset(other);
			PHY_WRITE(other, MII_BMCR, BMCR_ISO);
		}
		if (mii_phy_auto(sc, 0) == EJUSTRETURN)
			return(0);
		break;
	}

	/* Update the media status. */
	if (msc->ml_state == ML_STATE_AUTO_OTHER) {
		int other_inst;

		other_inst = other->mii_inst;
		other->mii_inst = sc->mii_inst;
		other->mii_service(other, mii, MII_POLLSTAT);
		other->mii_inst = other_inst;
		sc->mii_media_active = other->mii_media_active;
		sc->mii_media_status = other->mii_media_status;
	} else {
		ukphy_status(sc);
	}

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);
	return (0);
}
コード例 #18
0
ファイル: urlphy.c プロジェクト: ryoon/netbsd-xhci
static int
urlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
{
	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
	int reg;

	DPRINTF(("%s: %s: enter\n", device_xname(sc->mii_dev), __func__));

	switch (cmd) {
	case MII_POLLSTAT:
		/*
		 * If we're not polling our PHY instance, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);
		break;

	case MII_MEDIACHG:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/* If the interface is not up, don't do anything. */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			break;

		mii_phy_setmedia(sc);
		break;

	case MII_TICK:
		/*
		 * If we're not currently selected, just return.
		 */
		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
			return (0);

		/* Just bail now if the interface is down. */
		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
			return (0);

		/*
		 * If we're not doing autonegotiation, we don't need to do
		 * any extra work here.  However, we need to check the link
		 * status so we can generate an announcement if the status
		 * changes.
		 */
		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
			break;

		/* Read the status register twice; MSR_LINK is latch-low. */
		reg = PHY_READ(sc, URLPHY_MSR) | PHY_READ(sc, URLPHY_MSR);
		if (reg & URLPHY_MSR_LINK) {
			/*
			 * Reset autonegotiation timer to 0 in case the link
			 * goes down in the next tick.
			 */
			sc->mii_ticks = 0;
			/* See above. */
			break;
		}

		/*
		 * mii_ticks == 0 means it's the first tick after changing the
		 * media or the link became down since the last tick (see
		 * above), so break to update the status.
		 */
		if (sc->mii_ticks++ == 0)
			break;

		/*
		 * Only retry autonegotiation every N seconds.
		 */
		KASSERT(sc->mii_anegticks != 0);
		if (sc->mii_ticks <= sc->mii_anegticks)
			return (0);

		PHY_RESET(sc);

		if (mii_phy_auto(sc, 0) == EJUSTRETURN)
			return (0);

		break;

	case MII_DOWN:
		mii_phy_down(sc);
		return (0);
	}

	/* Update the media status. */
	mii_phy_status(sc);

	/* Callback if something changed. */
	mii_phy_update(sc, cmd);

	return (0);
}