Home | History | Annotate | Line # | Download | only in mii
mii_physubr.c revision 1.21
      1  1.21   thorpej /*	$NetBSD: mii_physubr.c,v 1.21 2001/04/30 19:49:08 thorpej Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4  1.15   thorpej  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9   1.1   thorpej  * NASA Ames Research Center.
     10   1.1   thorpej  *
     11   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12   1.1   thorpej  * modification, are permitted provided that the following conditions
     13   1.1   thorpej  * are met:
     14   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     20   1.1   thorpej  *    must display the following acknowledgement:
     21   1.1   thorpej  *	This product includes software developed by the NetBSD
     22   1.1   thorpej  *	Foundation, Inc. and its contributors.
     23   1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24   1.1   thorpej  *    contributors may be used to endorse or promote products derived
     25   1.1   thorpej  *    from this software without specific prior written permission.
     26   1.1   thorpej  *
     27   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38   1.1   thorpej  */
     39   1.1   thorpej 
     40   1.1   thorpej /*
     41   1.1   thorpej  * Subroutines common to all PHYs.
     42   1.1   thorpej  */
     43   1.1   thorpej 
     44   1.1   thorpej #include <sys/param.h>
     45   1.1   thorpej #include <sys/device.h>
     46   1.1   thorpej #include <sys/systm.h>
     47   1.3   thorpej #include <sys/kernel.h>
     48   1.1   thorpej #include <sys/socket.h>
     49   1.3   thorpej #include <sys/errno.h>
     50  1.19  augustss #include <sys/proc.h>
     51   1.1   thorpej 
     52   1.1   thorpej #include <net/if.h>
     53   1.1   thorpej #include <net/if_media.h>
     54  1.15   thorpej #include <net/route.h>
     55   1.1   thorpej 
     56   1.1   thorpej #include <dev/mii/mii.h>
     57   1.1   thorpej #include <dev/mii/miivar.h>
     58   1.1   thorpej 
     59   1.6   thorpej /*
     60   1.6   thorpej  * Media to register setting conversion table.  Order matters.
     61  1.21   thorpej  * XXX 802.3 doesn't specify ANAR or ANLPAR bits for 1000base.
     62   1.6   thorpej  */
     63   1.6   thorpej const struct mii_media mii_media_table[] = {
     64   1.6   thorpej 	{ BMCR_ISO,		ANAR_CSMA },		/* None */
     65  1.21   thorpej 	{ BMCR_S10,		ANAR_CSMA|ANAR_10 },	/* 10baseT */
     66  1.21   thorpej 	{ BMCR_S10|BMCR_FDX,	ANAR_CSMA|ANAR_10_FD },	/* 10baseT-FDX */
     67   1.6   thorpej 	{ BMCR_S100,		ANAR_CSMA|ANAR_T4 },	/* 100baseT4 */
     68   1.6   thorpej 	{ BMCR_S100,		ANAR_CSMA|ANAR_TX },	/* 100baseTX */
     69   1.6   thorpej 	{ BMCR_S100|BMCR_FDX,	ANAR_CSMA|ANAR_TX_FD },	/* 100baseTX-FDX */
     70  1.21   thorpej 	{ BMCR_S1000,		ANAR_CSMA },		/* 1000base */
     71  1.21   thorpej 	{ BMCR_S1000|BMCR_FDX,	ANAR_CSMA },		/* 1000base-FDX */
     72   1.6   thorpej };
     73   1.6   thorpej 
     74   1.3   thorpej void	mii_phy_auto_timeout __P((void *));
     75   1.3   thorpej 
     76   1.6   thorpej void
     77   1.6   thorpej mii_phy_setmedia(sc)
     78   1.6   thorpej 	struct mii_softc *sc;
     79   1.6   thorpej {
     80   1.6   thorpej 	struct mii_data *mii = sc->mii_pdata;
     81   1.6   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
     82   1.6   thorpej 	int bmcr, anar;
     83  1.12   thorpej 
     84  1.13   thorpej 	if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
     85  1.14   thorpej 		if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0)
     86  1.14   thorpej 			(void) mii_phy_auto(sc, 1);
     87  1.13   thorpej 		return;
     88  1.13   thorpej 	}
     89   1.6   thorpej 
     90   1.6   thorpej 	/*
     91   1.6   thorpej 	 * Table index is stored in the media entry.
     92   1.6   thorpej 	 */
     93   1.6   thorpej 
     94   1.6   thorpej #ifdef DIAGNOSTIC
     95   1.6   thorpej 	if (ife->ifm_data < 0 || ife->ifm_data >= MII_NMEDIA)
     96   1.6   thorpej 		panic("mii_phy_setmedia");
     97   1.6   thorpej #endif
     98   1.6   thorpej 
     99   1.6   thorpej 	anar = mii_media_table[ife->ifm_data].mm_anar;
    100   1.6   thorpej 	bmcr = mii_media_table[ife->ifm_data].mm_bmcr;
    101   1.6   thorpej 
    102   1.6   thorpej 	if (ife->ifm_media & IFM_LOOP)
    103   1.6   thorpej 		bmcr |= BMCR_LOOP;
    104   1.6   thorpej 
    105   1.6   thorpej 	PHY_WRITE(sc, MII_ANAR, anar);
    106   1.6   thorpej 	PHY_WRITE(sc, MII_BMCR, bmcr);
    107   1.6   thorpej }
    108   1.6   thorpej 
    109   1.1   thorpej int
    110   1.6   thorpej mii_phy_auto(sc, waitfor)
    111   1.6   thorpej 	struct mii_softc *sc;
    112   1.4    kleink 	int waitfor;
    113   1.1   thorpej {
    114   1.1   thorpej 	int bmsr, i;
    115   1.1   thorpej 
    116   1.6   thorpej 	if ((sc->mii_flags & MIIF_DOINGAUTO) == 0) {
    117   1.6   thorpej 		PHY_WRITE(sc, MII_ANAR,
    118   1.6   thorpej 		    BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA);
    119   1.6   thorpej 		PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG);
    120   1.3   thorpej 	}
    121   1.3   thorpej 
    122   1.3   thorpej 	if (waitfor) {
    123   1.3   thorpej 		/* Wait 500ms for it to complete. */
    124   1.3   thorpej 		for (i = 0; i < 500; i++) {
    125   1.6   thorpej 			if ((bmsr = PHY_READ(sc, MII_BMSR)) & BMSR_ACOMP)
    126   1.3   thorpej 				return (0);
    127   1.3   thorpej 			delay(1000);
    128   1.3   thorpej 		}
    129   1.3   thorpej 
    130   1.3   thorpej 		/*
    131   1.3   thorpej 		 * Don't need to worry about clearing MIIF_DOINGAUTO.
    132   1.3   thorpej 		 * If that's set, a timeout is pending, and it will
    133   1.3   thorpej 		 * clear the flag.
    134   1.3   thorpej 		 */
    135   1.3   thorpej 		return (EIO);
    136   1.1   thorpej 	}
    137   1.3   thorpej 
    138   1.3   thorpej 	/*
    139   1.3   thorpej 	 * Just let it finish asynchronously.  This is for the benefit of
    140   1.3   thorpej 	 * the tick handler driving autonegotiation.  Don't want 500ms
    141   1.3   thorpej 	 * delays all the time while the system is running!
    142   1.3   thorpej 	 */
    143  1.19  augustss 	if (sc->mii_flags & MIIF_AUTOTSLEEP) {
    144  1.19  augustss 		sc->mii_flags |= MIIF_DOINGAUTO;
    145  1.19  augustss 		tsleep(&sc->mii_flags, PZERO, "miiaut", hz >> 1);
    146  1.19  augustss 		mii_phy_auto_timeout(sc);
    147  1.19  augustss 	} else if ((sc->mii_flags & MIIF_DOINGAUTO) == 0) {
    148   1.6   thorpej 		sc->mii_flags |= MIIF_DOINGAUTO;
    149  1.17   thorpej 		callout_reset(&sc->mii_nway_ch, hz >> 1,
    150  1.17   thorpej 		    mii_phy_auto_timeout, sc);
    151   1.3   thorpej 	}
    152   1.3   thorpej 	return (EJUSTRETURN);
    153   1.3   thorpej }
    154   1.3   thorpej 
    155   1.3   thorpej void
    156   1.3   thorpej mii_phy_auto_timeout(arg)
    157   1.3   thorpej 	void *arg;
    158   1.3   thorpej {
    159   1.6   thorpej 	struct mii_softc *sc = arg;
    160   1.3   thorpej 	int s, bmsr;
    161   1.3   thorpej 
    162   1.9   thorpej 	if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
    163   1.9   thorpej 		return;
    164   1.9   thorpej 
    165   1.3   thorpej 	s = splnet();
    166   1.6   thorpej 	sc->mii_flags &= ~MIIF_DOINGAUTO;
    167   1.6   thorpej 	bmsr = PHY_READ(sc, MII_BMSR);
    168   1.3   thorpej 
    169   1.3   thorpej 	/* Update the media status. */
    170  1.18   thorpej 	(void) PHY_SERVICE(sc, sc->mii_pdata, MII_POLLSTAT);
    171   1.3   thorpej 	splx(s);
    172   1.2   thorpej }
    173   1.2   thorpej 
    174  1.15   thorpej int
    175  1.15   thorpej mii_phy_tick(sc)
    176  1.15   thorpej 	struct mii_softc *sc;
    177  1.15   thorpej {
    178  1.15   thorpej 	struct mii_data *mii = sc->mii_pdata;
    179  1.15   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    180  1.15   thorpej 	int reg;
    181  1.15   thorpej 
    182  1.15   thorpej 	/* Just bail now if the interface is down. */
    183  1.15   thorpej 	if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    184  1.15   thorpej 		return (EJUSTRETURN);
    185  1.15   thorpej 
    186  1.15   thorpej 	/*
    187  1.15   thorpej 	 * If we're not doing autonegotiation, we don't need to do
    188  1.15   thorpej 	 * any extra work here.  However, we need to check the link
    189  1.15   thorpej 	 * status so we can generate an announcement if the status
    190  1.15   thorpej 	 * changes.
    191  1.15   thorpej 	 */
    192  1.15   thorpej 	if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
    193  1.15   thorpej 		return (0);
    194  1.15   thorpej 
    195  1.15   thorpej 	/* Read the status register twice; BMSR_LINK is latch-low. */
    196  1.15   thorpej 	reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
    197  1.15   thorpej 	if (reg & BMSR_LINK) {
    198  1.15   thorpej 		/*
    199  1.15   thorpej 		 * See above.
    200  1.15   thorpej 		 */
    201  1.15   thorpej 		return (0);
    202  1.15   thorpej 	}
    203  1.15   thorpej 
    204  1.15   thorpej 	/*
    205  1.15   thorpej 	 * Only retry autonegotiation every 5 seconds.
    206  1.15   thorpej 	 */
    207  1.15   thorpej 	if (++sc->mii_ticks != 5)
    208  1.15   thorpej 		return (EJUSTRETURN);
    209  1.15   thorpej 
    210  1.15   thorpej 	sc->mii_ticks = 0;
    211  1.18   thorpej 	PHY_RESET(sc);
    212  1.15   thorpej 
    213  1.15   thorpej 	if (mii_phy_auto(sc, 0) == EJUSTRETURN)
    214  1.15   thorpej 		return (EJUSTRETURN);
    215  1.15   thorpej 
    216  1.15   thorpej 	/*
    217  1.15   thorpej 	 * Might need to generate a status message if autonegotiation
    218  1.15   thorpej 	 * failed.
    219  1.15   thorpej 	 */
    220  1.15   thorpej 	return (0);
    221  1.15   thorpej }
    222  1.15   thorpej 
    223   1.2   thorpej void
    224   1.6   thorpej mii_phy_reset(sc)
    225   1.6   thorpej 	struct mii_softc *sc;
    226   1.2   thorpej {
    227   1.2   thorpej 	int reg, i;
    228   1.2   thorpej 
    229   1.6   thorpej 	if (sc->mii_flags & MIIF_NOISOLATE)
    230   1.2   thorpej 		reg = BMCR_RESET;
    231   1.2   thorpej 	else
    232   1.2   thorpej 		reg = BMCR_RESET | BMCR_ISO;
    233   1.6   thorpej 	PHY_WRITE(sc, MII_BMCR, reg);
    234   1.2   thorpej 
    235   1.2   thorpej 	/* Wait 100ms for it to complete. */
    236   1.2   thorpej 	for (i = 0; i < 100; i++) {
    237   1.6   thorpej 		reg = PHY_READ(sc, MII_BMCR);
    238   1.2   thorpej 		if ((reg & BMCR_RESET) == 0)
    239   1.2   thorpej 			break;
    240   1.2   thorpej 		delay(1000);
    241   1.2   thorpej 	}
    242   1.2   thorpej 
    243   1.6   thorpej 	if (sc->mii_inst != 0 && ((sc->mii_flags & MIIF_NOISOLATE) == 0))
    244   1.6   thorpej 		PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
    245   1.8   thorpej }
    246   1.8   thorpej 
    247   1.8   thorpej void
    248   1.8   thorpej mii_phy_down(sc)
    249   1.8   thorpej 	struct mii_softc *sc;
    250   1.8   thorpej {
    251   1.8   thorpej 
    252   1.8   thorpej 	if (sc->mii_flags & MIIF_DOINGAUTO) {
    253   1.8   thorpej 		sc->mii_flags &= ~MIIF_DOINGAUTO;
    254  1.17   thorpej 		callout_stop(&sc->mii_nway_ch);
    255   1.8   thorpej 	}
    256  1.11   thorpej }
    257  1.11   thorpej 
    258  1.11   thorpej void
    259  1.11   thorpej mii_phy_status(sc)
    260  1.11   thorpej 	struct mii_softc *sc;
    261  1.11   thorpej {
    262  1.11   thorpej 
    263  1.18   thorpej 	PHY_STATUS(sc);
    264  1.15   thorpej }
    265  1.15   thorpej 
    266  1.15   thorpej void
    267  1.15   thorpej mii_phy_update(sc, cmd)
    268  1.15   thorpej 	struct mii_softc *sc;
    269  1.15   thorpej 	int cmd;
    270  1.15   thorpej {
    271  1.15   thorpej 	struct mii_data *mii = sc->mii_pdata;
    272  1.15   thorpej 
    273  1.15   thorpej 	if (sc->mii_media_active != mii->mii_media_active ||
    274  1.15   thorpej 	    sc->mii_media_status != mii->mii_media_status ||
    275  1.15   thorpej 	    cmd == MII_MEDIACHG) {
    276  1.15   thorpej 		(*mii->mii_statchg)(sc->mii_dev.dv_parent);
    277  1.15   thorpej 		mii_phy_statusmsg(sc);
    278  1.15   thorpej 		sc->mii_media_active = mii->mii_media_active;
    279  1.15   thorpej 		sc->mii_media_status = mii->mii_media_status;
    280  1.15   thorpej 	}
    281  1.15   thorpej }
    282  1.15   thorpej 
    283  1.15   thorpej void
    284  1.15   thorpej mii_phy_statusmsg(sc)
    285  1.15   thorpej 	struct mii_softc *sc;
    286  1.15   thorpej {
    287  1.15   thorpej 	struct mii_data *mii = sc->mii_pdata;
    288  1.15   thorpej 	struct ifnet *ifp = mii->mii_ifp;
    289  1.16   thorpej 	int s, baudrate, link_state, announce = 0;
    290  1.15   thorpej 
    291  1.15   thorpej 	if (mii->mii_media_status & IFM_AVALID) {
    292  1.15   thorpej 		if (mii->mii_media_status & IFM_ACTIVE)
    293  1.15   thorpej 			link_state = LINK_STATE_UP;
    294  1.15   thorpej 		else
    295  1.15   thorpej 			link_state = LINK_STATE_DOWN;
    296  1.15   thorpej 	} else
    297  1.15   thorpej 		link_state = LINK_STATE_UNKNOWN;
    298  1.15   thorpej 
    299  1.15   thorpej 	baudrate = ifmedia_baudrate(mii->mii_media_active);
    300  1.15   thorpej 
    301  1.15   thorpej 	if (link_state != ifp->if_link_state) {
    302  1.15   thorpej 		ifp->if_link_state = link_state;
    303  1.16   thorpej 		/*
    304  1.16   thorpej 		 * XXX Right here we'd like to notify protocols
    305  1.16   thorpej 		 * XXX that the link status has changed, so that
    306  1.16   thorpej 		 * XXX e.g. Duplicate Address Detection can restart.
    307  1.16   thorpej 		 */
    308  1.15   thorpej 		announce = 1;
    309  1.15   thorpej 	}
    310  1.15   thorpej 
    311  1.15   thorpej 	if (baudrate != ifp->if_baudrate) {
    312  1.15   thorpej 		ifp->if_baudrate = baudrate;
    313  1.15   thorpej 		announce = 1;
    314  1.15   thorpej 	}
    315  1.15   thorpej 
    316  1.16   thorpej 	if (announce) {
    317  1.20   thorpej 		s = splnet();
    318  1.15   thorpej 		rt_ifmsg(ifp);
    319  1.16   thorpej 		splx(s);
    320  1.16   thorpej 	}
    321   1.5  drochner }
    322   1.5  drochner 
    323   1.5  drochner /*
    324   1.5  drochner  * Initialize generic PHY media based on BMSR, called when a PHY is
    325   1.5  drochner  * attached.  We expect to be set up to print a comma-separated list
    326   1.5  drochner  * of media names.  Does not print a newline.
    327   1.5  drochner  */
    328   1.5  drochner void
    329  1.10   thorpej mii_phy_add_media(sc)
    330   1.6   thorpej 	struct mii_softc *sc;
    331   1.5  drochner {
    332   1.6   thorpej 	struct mii_data *mii = sc->mii_pdata;
    333   1.5  drochner 	const char *sep = "";
    334   1.5  drochner 
    335   1.5  drochner #define	ADD(m, c)	ifmedia_add(&mii->mii_media, (m), (c), NULL)
    336   1.5  drochner #define	PRINT(s)	printf("%s%s", sep, s); sep = ", "
    337   1.5  drochner 
    338   1.6   thorpej 	if ((sc->mii_flags & MIIF_NOISOLATE) == 0)
    339   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst),
    340   1.6   thorpej 		    MII_MEDIA_NONE);
    341   1.6   thorpej 
    342   1.6   thorpej 	if (sc->mii_capabilities & BMSR_10THDX) {
    343   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, sc->mii_inst),
    344   1.6   thorpej 		    MII_MEDIA_10_T);
    345   1.5  drochner 		PRINT("10baseT");
    346   1.5  drochner 	}
    347   1.6   thorpej 	if (sc->mii_capabilities & BMSR_10TFDX) {
    348   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, sc->mii_inst),
    349   1.6   thorpej 		    MII_MEDIA_10_T_FDX);
    350   1.5  drochner 		PRINT("10baseT-FDX");
    351   1.5  drochner 	}
    352   1.6   thorpej 	if (sc->mii_capabilities & BMSR_100TXHDX) {
    353   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, sc->mii_inst),
    354   1.6   thorpej 		    MII_MEDIA_100_TX);
    355   1.5  drochner 		PRINT("100baseTX");
    356   1.5  drochner 	}
    357   1.6   thorpej 	if (sc->mii_capabilities & BMSR_100TXFDX) {
    358   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, sc->mii_inst),
    359   1.6   thorpej 		    MII_MEDIA_100_TX_FDX);
    360   1.5  drochner 		PRINT("100baseTX-FDX");
    361   1.5  drochner 	}
    362   1.6   thorpej 	if (sc->mii_capabilities & BMSR_100T4) {
    363   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_T4, 0, sc->mii_inst),
    364   1.6   thorpej 		    MII_MEDIA_100_T4);
    365   1.5  drochner 		PRINT("100baseT4");
    366   1.5  drochner 	}
    367  1.21   thorpej 
    368  1.21   thorpej 	if (sc->mii_extcapabilities & EXTSR_MEDIAMASK) {
    369  1.21   thorpej 		/*
    370  1.21   thorpej 		 * XXX Right now only handle 1000SX and 1000TX.  Need
    371  1.21   thorpej 		 * XXX to hnalde 1000LX and 1000CX some how.
    372  1.21   thorpej 		 */
    373  1.21   thorpej 		if (sc->mii_extcapabilities & EXTSR_1000XHDX) {
    374  1.21   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, 0,
    375  1.21   thorpej 			    sc->mii_inst), MII_MEDIA_1000);
    376  1.21   thorpej 			PRINT("1000baseSX");
    377  1.21   thorpej 		}
    378  1.21   thorpej 		if (sc->mii_extcapabilities & EXTSR_1000XFDX) {
    379  1.21   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, IFM_FDX,
    380  1.21   thorpej 			    sc->mii_inst), MII_MEDIA_1000_FDX);
    381  1.21   thorpej 			PRINT("1000baseSX-FDX");
    382  1.21   thorpej 		}
    383  1.21   thorpej 		if (sc->mii_extcapabilities & EXTSR_1000THDX) {
    384  1.21   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_TX, 0,
    385  1.21   thorpej 			    sc->mii_inst), MII_MEDIA_1000);
    386  1.21   thorpej 			PRINT("1000baseTX");
    387  1.21   thorpej 		}
    388  1.21   thorpej 		if (sc->mii_extcapabilities & EXTSR_1000TFDX) {
    389  1.21   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_TX, IFM_FDX,
    390  1.21   thorpej 			    sc->mii_inst), MII_MEDIA_1000_FDX);
    391  1.21   thorpej 			PRINT("1000baseTX-FDX");
    392  1.21   thorpej 		}
    393  1.21   thorpej 	}
    394  1.21   thorpej 
    395   1.6   thorpej 	if (sc->mii_capabilities & BMSR_ANEG) {
    396   1.6   thorpej 		ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst),
    397   1.6   thorpej 		    MII_NMEDIA);	/* intentionally invalid index */
    398   1.5  drochner 		PRINT("auto");
    399   1.5  drochner 	}
    400   1.5  drochner #undef ADD
    401   1.5  drochner #undef PRINT
    402   1.9   thorpej }
    403   1.9   thorpej 
    404   1.9   thorpej void
    405  1.10   thorpej mii_phy_delete_media(sc)
    406   1.9   thorpej 	struct mii_softc *sc;
    407   1.9   thorpej {
    408   1.9   thorpej 	struct mii_data *mii = sc->mii_pdata;
    409   1.9   thorpej 
    410   1.9   thorpej 	ifmedia_delete_instance(&mii->mii_media, sc->mii_inst);
    411   1.9   thorpej }
    412   1.9   thorpej 
    413   1.9   thorpej int
    414  1.10   thorpej mii_phy_activate(self, act)
    415   1.9   thorpej 	struct device *self;
    416   1.9   thorpej 	enum devact act;
    417   1.9   thorpej {
    418   1.9   thorpej 	int rv = 0;
    419   1.9   thorpej 
    420   1.9   thorpej 	switch (act) {
    421   1.9   thorpej 	case DVACT_ACTIVATE:
    422   1.9   thorpej 		rv = EOPNOTSUPP;
    423   1.9   thorpej 		break;
    424   1.9   thorpej 
    425   1.9   thorpej 	case DVACT_DEACTIVATE:
    426   1.9   thorpej 		/* Nothing special to do. */
    427   1.9   thorpej 		break;
    428   1.9   thorpej 	}
    429   1.9   thorpej 
    430   1.9   thorpej 	return (rv);
    431   1.9   thorpej }
    432   1.9   thorpej 
    433   1.9   thorpej int
    434  1.10   thorpej mii_phy_detach(self, flags)
    435   1.9   thorpej 	struct device *self;
    436   1.9   thorpej 	int flags;
    437   1.9   thorpej {
    438   1.9   thorpej 	struct mii_softc *sc = (void *) self;
    439   1.9   thorpej 
    440   1.9   thorpej 	if (sc->mii_flags & MIIF_DOINGAUTO)
    441  1.17   thorpej 		callout_stop(&sc->mii_nway_ch);
    442   1.9   thorpej 
    443  1.10   thorpej 	mii_phy_delete_media(sc);
    444   1.9   thorpej 
    445   1.9   thorpej 	return (0);
    446   1.1   thorpej }
    447