Home | History | Annotate | Line # | Download | only in mii
tlphy.c revision 1.50.22.3
      1  1.50.22.3  jmcneill /*	$NetBSD: tlphy.c,v 1.50.22.3 2007/12/08 16:21:20 jmcneill Exp $	*/
      2        1.7   thorpej 
      3        1.7   thorpej /*-
      4       1.26   thorpej  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
      5        1.7   thorpej  * All rights reserved.
      6        1.7   thorpej  *
      7        1.7   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8        1.7   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9        1.7   thorpej  * NASA Ames Research Center.
     10        1.7   thorpej  *
     11        1.7   thorpej  * Redistribution and use in source and binary forms, with or without
     12        1.7   thorpej  * modification, are permitted provided that the following conditions
     13        1.7   thorpej  * are met:
     14        1.7   thorpej  * 1. Redistributions of source code must retain the above copyright
     15        1.7   thorpej  *    notice, this list of conditions and the following disclaimer.
     16        1.7   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17        1.7   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18        1.7   thorpej  *    documentation and/or other materials provided with the distribution.
     19        1.7   thorpej  * 3. All advertising materials mentioning features or use of this software
     20        1.7   thorpej  *    must display the following acknowledgement:
     21        1.7   thorpej  *	This product includes software developed by the NetBSD
     22        1.7   thorpej  *	Foundation, Inc. and its contributors.
     23        1.7   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24        1.7   thorpej  *    contributors may be used to endorse or promote products derived
     25        1.7   thorpej  *    from this software without specific prior written permission.
     26        1.7   thorpej  *
     27        1.7   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28        1.7   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29        1.7   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30        1.7   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31        1.7   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32        1.7   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33        1.7   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34        1.7   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35        1.7   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36        1.7   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37        1.7   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38        1.7   thorpej  */
     39        1.7   thorpej 
     40        1.1    bouyer /*
     41        1.1    bouyer  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
     42        1.1    bouyer  *
     43        1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     44        1.1    bouyer  * modification, are permitted provided that the following conditions
     45        1.1    bouyer  * are met:
     46        1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     47        1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     48        1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     49        1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     50        1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     51        1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     52        1.1    bouyer  *    must display the following acknowledgement:
     53        1.4   thorpej  *	This product includes software developed by Manuel Bouyer.
     54        1.1    bouyer  * 4. The name of the author may not be used to endorse or promote products
     55        1.1    bouyer  *    derived from this software without specific prior written permission.
     56        1.1    bouyer  *
     57        1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58        1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59        1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60        1.1    bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61        1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62        1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63        1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64        1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65        1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66        1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67        1.1    bouyer  */
     68        1.1    bouyer 
     69        1.7   thorpej /*
     70        1.7   thorpej  * Driver for Texas Instruments's ThunderLAN PHYs
     71        1.7   thorpej  */
     72       1.33     lukem 
     73       1.33     lukem #include <sys/cdefs.h>
     74  1.50.22.3  jmcneill __KERNEL_RCSID(0, "$NetBSD: tlphy.c,v 1.50.22.3 2007/12/08 16:21:20 jmcneill Exp $");
     75        1.1    bouyer 
     76        1.1    bouyer #include <sys/param.h>
     77        1.1    bouyer #include <sys/systm.h>
     78        1.1    bouyer #include <sys/kernel.h>
     79        1.1    bouyer #include <sys/device.h>
     80        1.1    bouyer #include <sys/socket.h>
     81       1.17   thorpej #include <sys/errno.h>
     82        1.7   thorpej 
     83  1.50.22.1     joerg #include <sys/bus.h>
     84        1.7   thorpej 
     85        1.1    bouyer #include <net/if.h>
     86        1.1    bouyer #include <net/if_media.h>
     87        1.1    bouyer 
     88        1.7   thorpej #include <net/if_ether.h>
     89        1.1    bouyer 
     90        1.7   thorpej #include <dev/mii/mii.h>
     91        1.7   thorpej #include <dev/mii/miivar.h>
     92        1.7   thorpej #include <dev/mii/miidevs.h>
     93        1.7   thorpej 
     94        1.7   thorpej #include <dev/mii/tlphyreg.h>
     95        1.7   thorpej #include <dev/mii/tlphyvar.h>
     96        1.7   thorpej 
     97        1.7   thorpej /* ThunderLAN PHY can only be on a ThunderLAN */
     98        1.7   thorpej #include <dev/pci/if_tlvar.h>
     99        1.7   thorpej 
    100        1.7   thorpej struct tlphy_softc {
    101        1.7   thorpej 	struct mii_softc sc_mii;		/* generic PHY */
    102        1.7   thorpej 	int sc_tlphycap;
    103       1.17   thorpej 	int sc_need_acomp;
    104        1.7   thorpej };
    105        1.1    bouyer 
    106       1.41   thorpej static int	tlphymatch(struct device *, struct cfdata *, void *);
    107       1.41   thorpej static void	tlphyattach(struct device *, struct device *, void *);
    108        1.1    bouyer 
    109       1.36   thorpej CFATTACH_DECL(tlphy, sizeof(struct tlphy_softc),
    110       1.37   thorpej     tlphymatch, tlphyattach, mii_phy_detach, mii_phy_activate);
    111        1.1    bouyer 
    112       1.41   thorpej static int	tlphy_service(struct mii_softc *, struct mii_data *, int);
    113       1.41   thorpej static int	tlphy_auto(struct tlphy_softc *, int);
    114       1.41   thorpej static void	tlphy_acomp(struct tlphy_softc *);
    115       1.41   thorpej static void	tlphy_status(struct mii_softc *);
    116        1.7   thorpej 
    117       1.41   thorpej static const struct mii_phy_funcs tlphy_funcs = {
    118       1.26   thorpej 	tlphy_service, tlphy_status, mii_phy_reset,
    119       1.26   thorpej };
    120       1.26   thorpej 
    121       1.41   thorpej static const struct mii_phydesc tlphys[] = {
    122       1.30   thorpej 	{ MII_OUI_TI,		MII_MODEL_TI_TLAN10T,
    123       1.30   thorpej 	  MII_STR_TI_TLAN10T },
    124       1.30   thorpej 
    125       1.30   thorpej 	{ 0,			0,
    126       1.30   thorpej 	  NULL },
    127       1.30   thorpej };
    128       1.30   thorpej 
    129       1.41   thorpej static int
    130       1.49  christos tlphymatch(struct device *parent, struct cfdata *match,
    131       1.48  christos     void *aux)
    132        1.1    bouyer {
    133       1.42     perry 	struct mii_attach_args *ma = aux;
    134        1.1    bouyer 
    135       1.30   thorpej 	if (mii_phy_match(ma, tlphys) != NULL)
    136       1.15   thorpej 		return (10);
    137        1.7   thorpej 
    138        1.4   thorpej 	return (0);
    139        1.1    bouyer }
    140        1.1    bouyer 
    141       1.41   thorpej static void
    142       1.49  christos tlphyattach(struct device *parent, struct device *self, void *aux)
    143        1.1    bouyer {
    144       1.46   thorpej 	struct tlphy_softc *sc = device_private(self);
    145       1.46   thorpej 	struct tl_softc *tlsc = device_private(device_parent(self));
    146        1.7   thorpej 	struct mii_attach_args *ma = aux;
    147        1.7   thorpej 	struct mii_data *mii = ma->mii_data;
    148       1.30   thorpej 	const struct mii_phydesc *mpd;
    149        1.7   thorpej 	const char *sep = "";
    150        1.7   thorpej 
    151       1.30   thorpej 	mpd = mii_phy_match(ma, tlphys);
    152       1.39   thorpej 	aprint_naive(": Media interface\n");
    153       1.39   thorpej 	aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
    154        1.7   thorpej 
    155        1.7   thorpej 	sc->sc_mii.mii_inst = mii->mii_instance;
    156        1.7   thorpej 	sc->sc_mii.mii_phy = ma->mii_phyno;
    157       1.26   thorpej 	sc->sc_mii.mii_funcs = &tlphy_funcs;
    158        1.7   thorpej 	sc->sc_mii.mii_pdata = mii;
    159       1.34   thorpej 	sc->sc_mii.mii_flags = ma->mii_flags;
    160       1.50  christos 	sc->sc_mii.mii_anegticks = MII_ANEGTICKS;
    161        1.7   thorpej 
    162       1.26   thorpej 	PHY_RESET(&sc->sc_mii);
    163        1.7   thorpej 
    164        1.7   thorpej 	/*
    165        1.7   thorpej 	 * Note that if we're on a device that also supports 100baseTX,
    166        1.7   thorpej 	 * we are not going to want to use the built-in 10baseT port,
    167        1.7   thorpej 	 * since there will be another PHY on the MII wired up to the
    168        1.7   thorpej 	 * UTP connector.  The parent indicates this to us by specifying
    169        1.7   thorpej 	 * the TLPHY_MEDIA_NO_10_T bit.
    170        1.7   thorpej 	 */
    171        1.7   thorpej 	sc->sc_tlphycap = tlsc->tl_product->tp_tlphymedia;
    172        1.7   thorpej 	if ((sc->sc_tlphycap & TLPHY_MEDIA_NO_10_T) == 0)
    173       1.13   thorpej 		sc->sc_mii.mii_capabilities =
    174       1.12   thorpej 		    PHY_READ(&sc->sc_mii, MII_BMSR) & ma->mii_capmask;
    175        1.7   thorpej 	else
    176       1.13   thorpej 		sc->sc_mii.mii_capabilities = 0;
    177        1.7   thorpej 
    178       1.19   thorpej 
    179        1.7   thorpej #define	ADD(m, c)	ifmedia_add(&mii->mii_media, (m), (c), NULL)
    180       1.39   thorpej #define	PRINT(str)	aprint_normal("%s%s", sep, str); sep = ", "
    181        1.7   thorpej 
    182       1.39   thorpej 	aprint_normal("%s: ", sc->sc_mii.mii_dev.dv_xname);
    183        1.7   thorpej 	if (sc->sc_tlphycap) {
    184       1.10    bouyer 		if (sc->sc_tlphycap & TLPHY_MEDIA_10_2) {
    185        1.7   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0,
    186        1.7   thorpej 			    sc->sc_mii.mii_inst), 0);
    187       1.19   thorpej 			PRINT("10base2");
    188       1.10    bouyer 		} else if (sc->sc_tlphycap & TLPHY_MEDIA_10_5) {
    189        1.7   thorpej 			ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_5, 0,
    190        1.7   thorpej 			    sc->sc_mii.mii_inst), 0);
    191       1.19   thorpej 			PRINT("10base5");
    192        1.7   thorpej 		}
    193        1.7   thorpej 	}
    194       1.13   thorpej 	if (sc->sc_mii.mii_capabilities & BMSR_MEDIAMASK) {
    195       1.39   thorpej 		aprint_normal("%s", sep);
    196       1.22   thorpej 		mii_phy_add_media(&sc->sc_mii);
    197       1.19   thorpej 	} else if ((sc->sc_tlphycap &
    198       1.19   thorpej 		    (TLPHY_MEDIA_10_2 | TLPHY_MEDIA_10_5)) == 0)
    199       1.39   thorpej 		aprint_error("no media present");
    200       1.39   thorpej 	aprint_normal("\n");
    201        1.7   thorpej #undef ADD
    202        1.7   thorpej #undef PRINT
    203  1.50.22.2     joerg 
    204  1.50.22.3  jmcneill 	if (!pmf_device_register(self, NULL, mii_phy_resume))
    205  1.50.22.2     joerg 		aprint_error_dev(self, "couldn't establish power handler\n");
    206        1.7   thorpej }
    207        1.7   thorpej 
    208       1.41   thorpej static int
    209       1.32   thorpej tlphy_service(struct mii_softc *self, struct mii_data *mii, int cmd)
    210        1.7   thorpej {
    211       1.47   thorpej 	struct tlphy_softc *sc = (struct tlphy_softc *) self;
    212       1.11   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    213        1.7   thorpej 	int reg;
    214       1.21   thorpej 
    215       1.44   thorpej 	if (!device_is_active(&sc->sc_mii.mii_dev))
    216       1.21   thorpej 		return (ENXIO);
    217        1.1    bouyer 
    218       1.17   thorpej 	if ((sc->sc_mii.mii_flags & MIIF_DOINGAUTO) == 0 && sc->sc_need_acomp)
    219       1.17   thorpej 		tlphy_acomp(sc);
    220       1.17   thorpej 
    221        1.7   thorpej 	switch (cmd) {
    222        1.7   thorpej 	case MII_POLLSTAT:
    223        1.7   thorpej 		/*
    224        1.7   thorpej 		 * If we're not polling our PHY instance, just return.
    225        1.7   thorpej 		 */
    226       1.11   thorpej 		if (IFM_INST(ife->ifm_media) != sc->sc_mii.mii_inst)
    227        1.7   thorpej 			return (0);
    228        1.1    bouyer 		break;
    229        1.7   thorpej 
    230        1.7   thorpej 	case MII_MEDIACHG:
    231        1.7   thorpej 		/*
    232        1.7   thorpej 		 * If the media indicates a different PHY instance,
    233        1.7   thorpej 		 * isolate ourselves.
    234        1.7   thorpej 		 */
    235       1.11   thorpej 		if (IFM_INST(ife->ifm_media) != sc->sc_mii.mii_inst) {
    236       1.12   thorpej 			reg = PHY_READ(&sc->sc_mii, MII_BMCR);
    237       1.12   thorpej 			PHY_WRITE(&sc->sc_mii, MII_BMCR, reg | BMCR_ISO);
    238        1.7   thorpej 			return (0);
    239        1.7   thorpej 		}
    240       1.42     perry 
    241        1.7   thorpej 		/*
    242        1.7   thorpej 		 * If the interface is not up, don't do anything.
    243        1.7   thorpej 		 */
    244        1.7   thorpej 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    245        1.7   thorpej 			break;
    246        1.7   thorpej 
    247       1.11   thorpej 		switch (IFM_SUBTYPE(ife->ifm_media)) {
    248        1.7   thorpej 		case IFM_AUTO:
    249        1.7   thorpej 			/*
    250        1.7   thorpej 			 * The ThunderLAN PHY doesn't self-configure after
    251        1.7   thorpej 			 * an autonegotiation cycle, so there's no such
    252        1.7   thorpej 			 * thing as "already in auto mode".
    253        1.7   thorpej 			 */
    254       1.17   thorpej 			(void) tlphy_auto(sc, 1);
    255        1.7   thorpej 			break;
    256        1.7   thorpej 		case IFM_10_2:
    257        1.7   thorpej 		case IFM_10_5:
    258       1.12   thorpej 			PHY_WRITE(&sc->sc_mii, MII_BMCR, 0);
    259       1.12   thorpej 			PHY_WRITE(&sc->sc_mii, MII_TLPHY_CTRL, CTRL_AUISEL);
    260        1.7   thorpej 			delay(100000);
    261        1.7   thorpej 			break;
    262        1.7   thorpej 		default:
    263       1.12   thorpej 			PHY_WRITE(&sc->sc_mii, MII_TLPHY_CTRL, 0);
    264        1.7   thorpej 			delay(100000);
    265       1.19   thorpej 			mii_phy_setmedia(&sc->sc_mii);
    266        1.7   thorpej 		}
    267        1.1    bouyer 		break;
    268        1.7   thorpej 
    269        1.7   thorpej 	case MII_TICK:
    270        1.7   thorpej 		/*
    271        1.7   thorpej 		 * If we're not currently selected, just return.
    272        1.7   thorpej 		 */
    273       1.11   thorpej 		if (IFM_INST(ife->ifm_media) != sc->sc_mii.mii_inst)
    274        1.7   thorpej 			return (0);
    275        1.7   thorpej 
    276        1.7   thorpej 		/*
    277        1.7   thorpej 		 * Only used for autonegotiation.
    278        1.7   thorpej 		 */
    279       1.11   thorpej 		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
    280        1.7   thorpej 			return (0);
    281        1.7   thorpej 
    282        1.7   thorpej 		/*
    283        1.7   thorpej 		 * Is the interface even up?
    284        1.7   thorpej 		 */
    285        1.7   thorpej 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    286        1.7   thorpej 			return (0);
    287        1.7   thorpej 
    288        1.7   thorpej 		/*
    289        1.7   thorpej 		 * XXX WHAT ABOUT CHECKING LINK ON THE BNC/AUI?!
    290        1.7   thorpej 		 */
    291        1.7   thorpej 
    292       1.25   thorpej 		if (mii_phy_tick(&sc->sc_mii) == EJUSTRETURN)
    293       1.17   thorpej 			return (0);
    294        1.3  christos 		break;
    295       1.20   thorpej 
    296       1.20   thorpej 	case MII_DOWN:
    297       1.20   thorpej 		mii_phy_down(&sc->sc_mii);
    298       1.20   thorpej 		return (0);
    299        1.1    bouyer 	}
    300        1.1    bouyer 
    301        1.7   thorpej 	/* Update the media status. */
    302       1.24   thorpej 	mii_phy_status(&sc->sc_mii);
    303        1.7   thorpej 
    304        1.7   thorpej 	/* Callback if something changed. */
    305       1.25   thorpej 	mii_phy_update(&sc->sc_mii, cmd);
    306        1.7   thorpej 	return (0);
    307        1.1    bouyer }
    308        1.1    bouyer 
    309       1.41   thorpej static void
    310       1.32   thorpej tlphy_status(struct mii_softc *physc)
    311        1.1    bouyer {
    312       1.24   thorpej 	struct tlphy_softc *sc = (void *) physc;
    313        1.7   thorpej 	struct mii_data *mii = sc->sc_mii.mii_pdata;
    314        1.7   thorpej 	int bmsr, bmcr, tlctrl;
    315        1.4   thorpej 
    316        1.7   thorpej 	mii->mii_media_status = IFM_AVALID;
    317        1.7   thorpej 	mii->mii_media_active = IFM_ETHER;
    318        1.1    bouyer 
    319       1.12   thorpej 	bmcr = PHY_READ(&sc->sc_mii, MII_BMCR);
    320        1.7   thorpej 	if (bmcr & BMCR_ISO) {
    321        1.7   thorpej 		mii->mii_media_active |= IFM_NONE;
    322       1.42     perry 		mii->mii_media_status = 0;
    323        1.7   thorpej 		return;
    324        1.1    bouyer 	}
    325        1.1    bouyer 
    326       1.12   thorpej 	tlctrl = PHY_READ(&sc->sc_mii, MII_TLPHY_CTRL);
    327        1.7   thorpej 	if (tlctrl & CTRL_AUISEL) {
    328       1.10    bouyer 		if (sc->sc_tlphycap & TLPHY_MEDIA_10_2)
    329       1.10    bouyer 			mii->mii_media_active |= IFM_10_2;
    330       1.10    bouyer 		else if (sc->sc_tlphycap & TLPHY_MEDIA_10_5)
    331       1.10    bouyer 			mii->mii_media_active |= IFM_10_5;
    332        1.1    bouyer 		else
    333       1.10    bouyer 			printf("%s: AUI selected with no matching media !\n",
    334       1.10    bouyer 			    sc->sc_mii.mii_dev.dv_xname);
    335       1.31    bouyer 		mii->mii_media_status |= IFM_ACTIVE;
    336        1.7   thorpej 		return;
    337        1.1    bouyer 	}
    338       1.10    bouyer 
    339       1.12   thorpej 	bmsr = PHY_READ(&sc->sc_mii, MII_BMSR) |
    340       1.12   thorpej 	    PHY_READ(&sc->sc_mii, MII_BMSR);
    341       1.42     perry 	if (bmsr & BMSR_LINK)
    342       1.10    bouyer 		mii->mii_media_status |= IFM_ACTIVE;
    343        1.7   thorpej 
    344        1.7   thorpej 	if (bmcr & BMCR_LOOP)
    345        1.7   thorpej 		mii->mii_media_active |= IFM_LOOP;
    346        1.7   thorpej 
    347        1.7   thorpej 	/*
    348        1.7   thorpej 	 * Grr, braindead ThunderLAN PHY doesn't have any way to
    349        1.7   thorpej 	 * tell which media is actually active.  (Note it also
    350        1.7   thorpej 	 * doesn't self-configure after autonegotiation.)  We
    351        1.7   thorpej 	 * just have to report what's in the BMCR.
    352        1.7   thorpej 	 */
    353        1.7   thorpej 	if (bmcr & BMCR_FDX)
    354        1.7   thorpej 		mii->mii_media_active |= IFM_FDX;
    355        1.7   thorpej 	mii->mii_media_active |= IFM_10_T;
    356        1.1    bouyer }
    357        1.1    bouyer 
    358       1.41   thorpej static int
    359       1.32   thorpej tlphy_auto(struct tlphy_softc *sc, int waitfor)
    360       1.17   thorpej {
    361       1.17   thorpej 	int error;
    362       1.17   thorpej 
    363       1.17   thorpej 	switch ((error = mii_phy_auto(&sc->sc_mii, waitfor))) {
    364       1.17   thorpej 	case EIO:
    365       1.17   thorpej 		/*
    366       1.17   thorpej 		 * Just assume we're not in full-duplex mode.
    367       1.17   thorpej 		 * XXX Check link and try AUI/BNC?
    368       1.17   thorpej 		 */
    369       1.17   thorpej 		PHY_WRITE(&sc->sc_mii, MII_BMCR, 0);
    370       1.17   thorpej 		break;
    371       1.17   thorpej 
    372       1.17   thorpej 	case EJUSTRETURN:
    373       1.17   thorpej 		/* Flag that we need to program when it completes. */
    374       1.17   thorpej 		sc->sc_need_acomp = 1;
    375       1.17   thorpej 		break;
    376       1.17   thorpej 
    377       1.17   thorpej 	default:
    378       1.17   thorpej 		tlphy_acomp(sc);
    379       1.17   thorpej 	}
    380       1.17   thorpej 
    381       1.17   thorpej 	return (error);
    382       1.17   thorpej }
    383       1.17   thorpej 
    384       1.41   thorpej static void
    385       1.32   thorpej tlphy_acomp(struct tlphy_softc *sc)
    386        1.1    bouyer {
    387       1.13   thorpej 	int aner, anlpar;
    388        1.1    bouyer 
    389       1.17   thorpej 	sc->sc_need_acomp = 0;
    390        1.7   thorpej 
    391        1.7   thorpej 	/*
    392        1.7   thorpej 	 * Grr, braindead ThunderLAN PHY doesn't self-configure
    393        1.7   thorpej 	 * after autonegotiation.  We have to do it ourselves
    394        1.7   thorpej 	 * based on the link partner status.
    395        1.7   thorpej 	 */
    396        1.7   thorpej 
    397       1.12   thorpej 	aner = PHY_READ(&sc->sc_mii, MII_ANER);
    398        1.7   thorpej 	if (aner & ANER_LPAN) {
    399       1.12   thorpej 		anlpar = PHY_READ(&sc->sc_mii, MII_ANLPAR) &
    400       1.12   thorpej 		    PHY_READ(&sc->sc_mii, MII_ANAR);
    401        1.7   thorpej 		if (anlpar & ANAR_10_FD) {
    402       1.12   thorpej 			PHY_WRITE(&sc->sc_mii, MII_BMCR, BMCR_FDX);
    403        1.7   thorpej 			return;
    404        1.7   thorpej 		}
    405        1.7   thorpej 	}
    406       1.12   thorpej 	PHY_WRITE(&sc->sc_mii, MII_BMCR, 0);
    407        1.1    bouyer }
    408