Home | History | Annotate | Line # | Download | only in mii
igphy.c revision 1.19
      1  1.19   msaitoh /*	$NetBSD: igphy.c,v 1.19 2009/12/16 04:50:35 msaitoh Exp $	*/
      2   1.1      fvdl 
      3   1.1      fvdl /*
      4   1.1      fvdl  * The Intel copyright applies to the analog register setup, and the
      5   1.1      fvdl  * (currently disabled) SmartSpeed workaround code.
      6   1.1      fvdl  */
      7   1.1      fvdl 
      8   1.1      fvdl /*******************************************************************************
      9   1.1      fvdl 
     10   1.1      fvdl   Copyright (c) 2001-2003, Intel Corporation
     11   1.1      fvdl   All rights reserved.
     12   1.1      fvdl 
     13   1.1      fvdl   Redistribution and use in source and binary forms, with or without
     14   1.1      fvdl   modification, are permitted provided that the following conditions are met:
     15   1.1      fvdl 
     16   1.1      fvdl    1. Redistributions of source code must retain the above copyright notice,
     17   1.1      fvdl       this list of conditions and the following disclaimer.
     18   1.1      fvdl 
     19   1.1      fvdl    2. Redistributions in binary form must reproduce the above copyright
     20   1.1      fvdl       notice, this list of conditions and the following disclaimer in the
     21   1.1      fvdl       documentation and/or other materials provided with the distribution.
     22   1.1      fvdl 
     23   1.1      fvdl    3. Neither the name of the Intel Corporation nor the names of its
     24   1.1      fvdl       contributors may be used to endorse or promote products derived from
     25   1.1      fvdl       this software without specific prior written permission.
     26   1.1      fvdl 
     27   1.1      fvdl   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     28   1.1      fvdl   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29   1.1      fvdl   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30   1.1      fvdl   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     31   1.1      fvdl   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.1      fvdl   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.1      fvdl   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.1      fvdl   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.1      fvdl   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.1      fvdl   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.1      fvdl   POSSIBILITY OF SUCH DAMAGE.
     38   1.1      fvdl 
     39   1.1      fvdl *******************************************************************************/
     40   1.1      fvdl 
     41   1.1      fvdl 
     42   1.1      fvdl /*-
     43   1.1      fvdl  * Copyright (c) 1998, 1999, 2000, 2003 The NetBSD Foundation, Inc.
     44   1.1      fvdl  * All rights reserved.
     45   1.1      fvdl  *
     46   1.1      fvdl  * This code is derived from software contributed to The NetBSD Foundation
     47   1.1      fvdl  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     48   1.1      fvdl  * NASA Ames Research Center, and by Frank van der Linden.
     49   1.1      fvdl  *
     50   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     51   1.1      fvdl  * modification, are permitted provided that the following conditions
     52   1.1      fvdl  * are met:
     53   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     54   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     55   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     56   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     57   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     58   1.1      fvdl  *
     59   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     60   1.1      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     61   1.1      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     62   1.1      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     63   1.1      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     64   1.1      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     65   1.1      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     66   1.1      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     67   1.1      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     68   1.1      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69   1.1      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     70   1.1      fvdl  */
     71   1.1      fvdl 
     72   1.1      fvdl #include <sys/cdefs.h>
     73  1.19   msaitoh __KERNEL_RCSID(0, "$NetBSD: igphy.c,v 1.19 2009/12/16 04:50:35 msaitoh Exp $");
     74   1.1      fvdl 
     75   1.1      fvdl #include "opt_mii.h"
     76   1.1      fvdl 
     77   1.1      fvdl #include <sys/param.h>
     78   1.1      fvdl #include <sys/systm.h>
     79   1.1      fvdl #include <sys/kernel.h>
     80   1.1      fvdl #include <sys/device.h>
     81   1.1      fvdl #include <sys/socket.h>
     82   1.1      fvdl #include <sys/errno.h>
     83   1.1      fvdl 
     84   1.1      fvdl #include <net/if.h>
     85   1.1      fvdl #include <net/if_media.h>
     86   1.1      fvdl 
     87   1.1      fvdl #include <dev/mii/mii.h>
     88   1.1      fvdl #include <dev/mii/miivar.h>
     89   1.1      fvdl #include <dev/mii/miidevs.h>
     90   1.1      fvdl #include <dev/mii/igphyreg.h>
     91  1.19   msaitoh #include <dev/pci/if_wmvar.h>
     92   1.1      fvdl 
     93   1.5   thorpej struct igphy_softc {
     94   1.5   thorpej 	struct mii_softc sc_mii;
     95   1.5   thorpej 	int sc_smartspeed;
     96  1.19   msaitoh 	uint32_t sc_mactype;
     97   1.5   thorpej };
     98   1.5   thorpej 
     99   1.1      fvdl static void igphy_reset(struct mii_softc *);
    100   1.1      fvdl static void igphy_load_dspcode(struct mii_softc *);
    101   1.1      fvdl static void igphy_smartspeed_workaround(struct mii_softc *sc);
    102   1.1      fvdl 
    103  1.16   xtraeme static int	igphymatch(device_t, cfdata_t, void *);
    104  1.16   xtraeme static void	igphyattach(device_t, device_t, void *);
    105   1.1      fvdl 
    106  1.16   xtraeme CFATTACH_DECL_NEW(igphy, sizeof(struct igphy_softc),
    107   1.1      fvdl     igphymatch, igphyattach, mii_phy_detach, mii_phy_activate);
    108   1.1      fvdl 
    109   1.4   thorpej static int	igphy_service(struct mii_softc *, struct mii_data *, int);
    110   1.4   thorpej static void	igphy_status(struct mii_softc *);
    111   1.1      fvdl 
    112   1.4   thorpej static const struct mii_phy_funcs igphy_funcs = {
    113   1.1      fvdl 	igphy_service, igphy_status, igphy_reset,
    114   1.1      fvdl };
    115   1.1      fvdl 
    116   1.4   thorpej static const struct mii_phydesc igphys[] = {
    117   1.1      fvdl 	{ MII_OUI_yyINTEL,		MII_MODEL_yyINTEL_IGP01E1000,
    118   1.1      fvdl 	  MII_STR_yyINTEL_IGP01E1000 },
    119   1.1      fvdl 
    120  1.19   msaitoh 	{ MII_OUI_yyINTEL,		MII_MODEL_yyINTEL_I82566,
    121  1.19   msaitoh 	  MII_STR_yyINTEL_I82566 },
    122  1.19   msaitoh 
    123   1.1      fvdl 	{0,				0,
    124   1.1      fvdl 	 NULL },
    125   1.1      fvdl };
    126   1.1      fvdl 
    127   1.4   thorpej static int
    128  1.16   xtraeme igphymatch(device_t parent, cfdata_t match, void *aux)
    129   1.1      fvdl {
    130   1.1      fvdl 	struct mii_attach_args *ma = aux;
    131   1.1      fvdl 
    132   1.1      fvdl 	if (mii_phy_match(ma, igphys) != NULL)
    133   1.1      fvdl 		return 10;
    134   1.1      fvdl 
    135   1.1      fvdl 	return 0;
    136   1.1      fvdl }
    137   1.1      fvdl 
    138   1.4   thorpej static void
    139  1.16   xtraeme igphyattach(device_t parent, device_t self, void *aux)
    140   1.1      fvdl {
    141   1.7   thorpej 	struct mii_softc *sc = device_private(self);
    142   1.1      fvdl 	struct mii_attach_args *ma = aux;
    143   1.1      fvdl 	struct mii_data *mii = ma->mii_data;
    144   1.1      fvdl 	const struct mii_phydesc *mpd;
    145  1.19   msaitoh 	struct igphy_softc *igsc = (struct igphy_softc *) sc;
    146  1.19   msaitoh 	prop_dictionary_t dict;
    147   1.1      fvdl 
    148   1.1      fvdl 	mpd = mii_phy_match(ma, igphys);
    149   1.1      fvdl 	aprint_naive(": Media interface\n");
    150   1.1      fvdl 	aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
    151   1.1      fvdl 
    152  1.19   msaitoh 	dict = device_properties(parent);
    153  1.19   msaitoh 	if (!prop_dictionary_get_uint32(dict, "mactype", &igsc->sc_mactype))
    154  1.19   msaitoh 		aprint_error("WARNING! Failed to get mactype\n");
    155  1.19   msaitoh 
    156  1.16   xtraeme 	sc->mii_dev = self;
    157   1.1      fvdl 	sc->mii_inst = mii->mii_instance;
    158   1.1      fvdl 	sc->mii_phy = ma->mii_phyno;
    159   1.1      fvdl 	sc->mii_funcs = &igphy_funcs;
    160   1.1      fvdl 	sc->mii_pdata = mii;
    161   1.1      fvdl 	sc->mii_flags = ma->mii_flags;
    162  1.10  christos 	sc->mii_anegticks = MII_ANEGTICKS_GIGE;
    163   1.1      fvdl 
    164   1.1      fvdl 	PHY_RESET(sc);
    165   1.1      fvdl 
    166   1.1      fvdl 	sc->mii_capabilities =
    167   1.1      fvdl 	    PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
    168   1.1      fvdl 	if (sc->mii_capabilities & BMSR_EXTSTAT)
    169   1.1      fvdl 		sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
    170  1.16   xtraeme 	aprint_normal_dev(self, "");
    171   1.1      fvdl 	if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
    172   1.1      fvdl 	    (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
    173   1.1      fvdl 		aprint_error("no media present");
    174   1.1      fvdl 	else
    175   1.1      fvdl 		mii_phy_add_media(sc);
    176   1.1      fvdl 	aprint_normal("\n");
    177   1.1      fvdl }
    178   1.1      fvdl 
    179   1.1      fvdl static void
    180   1.1      fvdl igphy_load_dspcode(struct mii_softc *sc)
    181   1.1      fvdl {
    182  1.19   msaitoh 	struct igphy_softc *igsc = (struct igphy_softc *) sc;
    183   1.1      fvdl 	static const struct {
    184   1.1      fvdl 		int reg;
    185   1.1      fvdl 		uint16_t val;
    186   1.1      fvdl 	} dspcode[] = {
    187   1.1      fvdl 		{ 0x1f95, 0x0001 },
    188   1.1      fvdl 		{ 0x1f71, 0xbd21 },
    189   1.1      fvdl 		{ 0x1f79, 0x0018 },
    190   1.1      fvdl 		{ 0x1f30, 0x1600 },
    191   1.1      fvdl 		{ 0x1f31, 0x0014 },
    192   1.1      fvdl 		{ 0x1f32, 0x161c },
    193   1.1      fvdl 		{ 0x1f94, 0x0003 },
    194   1.1      fvdl 		{ 0x1f96, 0x003f },
    195   1.1      fvdl 		{ 0x2010, 0x0008 },
    196   1.1      fvdl 		{ 0, 0 },
    197   1.1      fvdl 	};
    198   1.1      fvdl 	int i;
    199   1.1      fvdl 
    200  1.19   msaitoh 	/* This workaround is only for 82541 and 82547 */
    201  1.19   msaitoh 	switch (igsc->sc_mactype) {
    202  1.19   msaitoh 	case WM_T_82541:
    203  1.19   msaitoh 	case WM_T_82547:
    204  1.19   msaitoh 	case WM_T_82541_2:
    205  1.19   msaitoh 	case WM_T_82547_2:
    206  1.19   msaitoh 		break;
    207  1.19   msaitoh 	default:
    208  1.19   msaitoh 		/* byebye */
    209  1.19   msaitoh 		return;
    210  1.19   msaitoh 	}
    211  1.19   msaitoh 
    212   1.1      fvdl 	delay(10);
    213   1.1      fvdl 
    214   1.1      fvdl 	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT, 0x0000);
    215   1.1      fvdl 	PHY_WRITE(sc, 0x0000, 0x0140);
    216   1.1      fvdl 
    217   1.1      fvdl 	delay(5);
    218   1.1      fvdl 
    219  1.19   msaitoh 	switch (igsc->sc_mactype) {
    220  1.19   msaitoh 	case WM_T_82541:
    221  1.19   msaitoh 	case WM_T_82547:
    222  1.19   msaitoh 		for (i = 0; dspcode[i].reg != 0; i++)
    223  1.19   msaitoh 			IGPHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    224  1.19   msaitoh 		break;
    225  1.19   msaitoh 	case WM_T_82541_2:
    226  1.19   msaitoh 	case WM_T_82547_2:
    227  1.19   msaitoh 		IGPHY_WRITE(sc, 0x1f73, 0x0099);
    228  1.19   msaitoh 		break;
    229  1.19   msaitoh 	default:
    230  1.19   msaitoh 		break;
    231  1.19   msaitoh 	}
    232   1.1      fvdl 
    233   1.1      fvdl 	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT,0x0000);
    234   1.1      fvdl 	PHY_WRITE(sc, 0x0000, 0x3300);
    235   1.1      fvdl }
    236   1.1      fvdl 
    237   1.1      fvdl static void
    238   1.1      fvdl igphy_reset(struct mii_softc *sc)
    239   1.1      fvdl {
    240  1.19   msaitoh 	struct igphy_softc *igsc = (struct igphy_softc *) sc;
    241   1.1      fvdl 	uint16_t fused, fine, coarse;
    242   1.1      fvdl 
    243   1.1      fvdl 	mii_phy_reset(sc);
    244   1.1      fvdl 	igphy_load_dspcode(sc);
    245   1.1      fvdl 
    246  1.19   msaitoh 	if (igsc->sc_mactype == WM_T_82547) {
    247  1.19   msaitoh 		fused = IGPHY_READ(sc, MII_IGPHY_ANALOG_SPARE_FUSE_STATUS);
    248  1.19   msaitoh 		if ((fused & ANALOG_SPARE_FUSE_ENABLED) == 0) {
    249  1.19   msaitoh 			fused = IGPHY_READ(sc, MII_IGPHY_ANALOG_FUSE_STATUS);
    250  1.19   msaitoh 
    251  1.19   msaitoh 			fine = fused & ANALOG_FUSE_FINE_MASK;
    252  1.19   msaitoh 			coarse = fused & ANALOG_FUSE_COARSE_MASK;
    253  1.19   msaitoh 
    254  1.19   msaitoh 			if (coarse > ANALOG_FUSE_COARSE_THRESH) {
    255  1.19   msaitoh 				coarse -= ANALOG_FUSE_COARSE_10;
    256  1.19   msaitoh 				fine -= ANALOG_FUSE_FINE_1;
    257  1.19   msaitoh 			} else if (coarse == ANALOG_FUSE_COARSE_THRESH)
    258  1.19   msaitoh 				fine -= ANALOG_FUSE_FINE_10;
    259  1.19   msaitoh 
    260  1.19   msaitoh 			fused = (fused & ANALOG_FUSE_POLY_MASK) |
    261  1.19   msaitoh 			    (fine & ANALOG_FUSE_FINE_MASK) |
    262  1.19   msaitoh 			    (coarse & ANALOG_FUSE_COARSE_MASK);
    263  1.19   msaitoh 
    264  1.19   msaitoh 			IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_CONTROL, fused);
    265  1.19   msaitoh 			IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_BYPASS,
    266  1.19   msaitoh 			    ANALOG_FUSE_ENABLE_SW_CONTROL);
    267  1.19   msaitoh 		}
    268   1.1      fvdl 	}
    269   1.1      fvdl 	PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT,0x0000);
    270   1.1      fvdl }
    271   1.1      fvdl 
    272   1.1      fvdl 
    273   1.4   thorpej static int
    274   1.1      fvdl igphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
    275   1.1      fvdl {
    276   1.1      fvdl 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    277   1.1      fvdl 	uint16_t reg;
    278   1.1      fvdl 
    279   1.1      fvdl 	switch (cmd) {
    280   1.1      fvdl 	case MII_POLLSTAT:
    281   1.1      fvdl 		/*
    282   1.1      fvdl 		 * If we're not polling our PHY instance, just return.
    283   1.1      fvdl 		 */
    284   1.1      fvdl 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    285   1.1      fvdl 			return (0);
    286   1.1      fvdl 		break;
    287   1.1      fvdl 
    288   1.1      fvdl 	case MII_MEDIACHG:
    289   1.1      fvdl 		/*
    290   1.1      fvdl 		 * If the media indicates a different PHY instance,
    291   1.1      fvdl 		 * isolate ourselves.
    292   1.1      fvdl 		 */
    293   1.1      fvdl 		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
    294   1.1      fvdl 			reg = PHY_READ(sc, MII_BMCR);
    295   1.1      fvdl 			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
    296   1.1      fvdl 			return (0);
    297   1.1      fvdl 		}
    298   1.1      fvdl 
    299   1.1      fvdl 		/*
    300   1.1      fvdl 		 * If the interface is not up, don't do anything.
    301   1.1      fvdl 		 */
    302   1.1      fvdl 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    303   1.1      fvdl 			break;
    304   1.1      fvdl 
    305  1.11   msaitoh 		reg = PHY_READ(sc, MII_IGPHY_PORT_CTRL);
    306  1.11   msaitoh 		if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) {
    307  1.11   msaitoh 			reg |= PSCR_AUTO_MDIX;
    308  1.11   msaitoh 			reg &= ~PSCR_FORCE_MDI_MDIX;
    309  1.11   msaitoh 			PHY_WRITE(sc, MII_IGPHY_PORT_CTRL, reg);
    310  1.11   msaitoh 		} else {
    311  1.11   msaitoh 			reg &= ~(PSCR_AUTO_MDIX | PSCR_FORCE_MDI_MDIX);
    312  1.11   msaitoh 			PHY_WRITE(sc, MII_IGPHY_PORT_CTRL, reg);
    313  1.11   msaitoh 		}
    314  1.11   msaitoh 
    315   1.1      fvdl 		mii_phy_setmedia(sc);
    316   1.1      fvdl 		break;
    317   1.1      fvdl 
    318   1.1      fvdl 	case MII_TICK:
    319   1.1      fvdl 		/*
    320   1.1      fvdl 		 * If we're not currently selected, just return.
    321   1.1      fvdl 		 */
    322   1.1      fvdl 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    323   1.1      fvdl 			return (0);
    324   1.1      fvdl 
    325   1.1      fvdl 		igphy_smartspeed_workaround(sc);
    326   1.1      fvdl 
    327   1.1      fvdl 		if (mii_phy_tick(sc) == EJUSTRETURN)
    328   1.1      fvdl 			return (0);
    329   1.1      fvdl 		break;
    330   1.1      fvdl 
    331   1.1      fvdl 	case MII_DOWN:
    332   1.1      fvdl 		mii_phy_down(sc);
    333   1.1      fvdl 		return (0);
    334   1.1      fvdl 	}
    335   1.1      fvdl 
    336   1.1      fvdl 	/* Update the media status. */
    337   1.1      fvdl 	mii_phy_status(sc);
    338   1.1      fvdl 
    339   1.1      fvdl 	/* Callback if something changed. */
    340   1.1      fvdl 	mii_phy_update(sc, cmd);
    341   1.1      fvdl 	return (0);
    342   1.1      fvdl }
    343   1.1      fvdl 
    344   1.1      fvdl 
    345   1.4   thorpej static void
    346   1.1      fvdl igphy_status(struct mii_softc *sc)
    347   1.1      fvdl {
    348   1.1      fvdl 	struct mii_data *mii = sc->mii_pdata;
    349   1.1      fvdl 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    350   1.1      fvdl 	uint16_t bmcr, pssr, gtsr, bmsr;
    351   1.1      fvdl 
    352   1.1      fvdl 	mii->mii_media_status = IFM_AVALID;
    353   1.1      fvdl 	mii->mii_media_active = IFM_ETHER;
    354   1.1      fvdl 
    355   1.1      fvdl 	pssr = PHY_READ(sc, MII_IGPHY_PORT_STATUS);
    356   1.1      fvdl 
    357   1.1      fvdl 	if (pssr & PSSR_LINK_UP)
    358   1.1      fvdl 		mii->mii_media_status |= IFM_ACTIVE;
    359   1.1      fvdl 
    360   1.1      fvdl 	bmcr = PHY_READ(sc, MII_BMCR);
    361   1.1      fvdl 	if (bmcr & BMCR_ISO) {
    362   1.1      fvdl 		mii->mii_media_active |= IFM_NONE;
    363   1.1      fvdl 		mii->mii_media_status = 0;
    364   1.1      fvdl 		return;
    365   1.1      fvdl 	}
    366   1.1      fvdl 
    367   1.1      fvdl 	if (bmcr & BMCR_LOOP)
    368   1.1      fvdl 		mii->mii_media_active |= IFM_LOOP;
    369   1.1      fvdl 
    370   1.1      fvdl 	bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
    371   1.1      fvdl 
    372   1.1      fvdl 	/*
    373   1.1      fvdl 	 * XXX can't check if the info is valid, no
    374   1.1      fvdl 	 * 'negotiation done' bit?
    375   1.1      fvdl 	 */
    376   1.1      fvdl 	if (bmcr & BMCR_AUTOEN) {
    377   1.1      fvdl 		if ((bmsr & BMSR_ACOMP) == 0) {
    378   1.1      fvdl 			mii->mii_media_active |= IFM_NONE;
    379   1.1      fvdl 			return;
    380   1.1      fvdl 		}
    381   1.1      fvdl 		switch (pssr & PSSR_SPEED_MASK) {
    382   1.1      fvdl 		case PSSR_SPEED_1000MBPS:
    383   1.1      fvdl 			mii->mii_media_active |= IFM_1000_T;
    384   1.1      fvdl 			gtsr = PHY_READ(sc, MII_100T2SR);
    385   1.1      fvdl 			if (gtsr & GTSR_MS_RES)
    386   1.1      fvdl 				mii->mii_media_active |= IFM_ETH_MASTER;
    387   1.1      fvdl 			break;
    388   1.1      fvdl 
    389   1.1      fvdl 		case PSSR_SPEED_100MBPS:
    390   1.1      fvdl 			mii->mii_media_active |= IFM_100_TX;
    391   1.1      fvdl 			break;
    392   1.1      fvdl 
    393   1.1      fvdl 		case PSSR_SPEED_10MBPS:
    394   1.1      fvdl 			mii->mii_media_active |= IFM_10_T;
    395   1.1      fvdl 			break;
    396   1.1      fvdl 
    397   1.1      fvdl 		default:
    398   1.1      fvdl 			mii->mii_media_active |= IFM_NONE;
    399   1.1      fvdl 			mii->mii_media_status = 0;
    400   1.1      fvdl 			return;
    401   1.1      fvdl 		}
    402   1.1      fvdl 
    403   1.1      fvdl 		if (pssr & PSSR_FULL_DUPLEX)
    404   1.2   thorpej 			mii->mii_media_active |=
    405   1.3   thorpej 			    IFM_FDX | mii_phy_flowstatus(sc);
    406   1.1      fvdl 	} else
    407   1.1      fvdl 		mii->mii_media_active = ife->ifm_media;
    408   1.1      fvdl }
    409   1.1      fvdl 
    410   1.1      fvdl static void
    411   1.1      fvdl igphy_smartspeed_workaround(struct mii_softc *sc)
    412   1.1      fvdl {
    413   1.5   thorpej 	struct igphy_softc *igsc = (struct igphy_softc *) sc;
    414   1.5   thorpej 	uint16_t reg, gtsr, gtcr;
    415   1.5   thorpej 
    416  1.19   msaitoh 
    417  1.19   msaitoh 	/* This workaround is only for 82541 and 82547 */
    418  1.19   msaitoh 	switch (igsc->sc_mactype) {
    419  1.19   msaitoh 	case WM_T_82541:
    420  1.19   msaitoh 	case WM_T_82541_2:
    421  1.19   msaitoh 	case WM_T_82547:
    422  1.19   msaitoh 	case WM_T_82547_2:
    423  1.19   msaitoh 		break;
    424  1.19   msaitoh 	default:
    425  1.19   msaitoh 		/* byebye */
    426  1.19   msaitoh 		return;
    427  1.19   msaitoh 	}
    428  1.19   msaitoh 
    429   1.5   thorpej 	if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0)
    430   1.5   thorpej 		return;
    431   1.5   thorpej 
    432   1.5   thorpej 	/* XXX Assume 1000TX-FDX is advertized if doing autonegotiation. */
    433   1.1      fvdl 
    434   1.1      fvdl 	reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
    435   1.5   thorpej 	if ((reg & BMSR_LINK) == 0) {
    436   1.5   thorpej 		switch (igsc->sc_smartspeed) {
    437   1.1      fvdl 		case 0:
    438   1.1      fvdl 			gtsr = PHY_READ(sc, MII_100T2SR);
    439   1.1      fvdl 			if (!(gtsr & GTSR_MAN_MS_FLT))
    440   1.1      fvdl 				break;
    441   1.1      fvdl 			gtsr = PHY_READ(sc, MII_100T2SR);
    442   1.1      fvdl 			if (gtsr & GTSR_MAN_MS_FLT) {
    443   1.1      fvdl 				gtcr = PHY_READ(sc, MII_100T2CR);
    444   1.1      fvdl 				if (gtcr & GTCR_MAN_MS) {
    445   1.1      fvdl 					gtcr &= ~GTCR_MAN_MS;
    446   1.1      fvdl 					PHY_WRITE(sc, MII_100T2CR,
    447   1.1      fvdl 					    gtcr);
    448   1.1      fvdl 				}
    449   1.1      fvdl 				mii_phy_auto(sc, 0);
    450   1.1      fvdl 			}
    451   1.1      fvdl 			break;
    452   1.1      fvdl 		case IGPHY_TICK_DOWNSHIFT:
    453   1.1      fvdl 			gtcr = PHY_READ(sc, MII_100T2CR);
    454   1.1      fvdl 			gtcr |= GTCR_MAN_MS;
    455   1.1      fvdl 			PHY_WRITE(sc, MII_100T2CR, gtcr);
    456   1.1      fvdl 			mii_phy_auto(sc, 0);
    457   1.1      fvdl 			break;
    458   1.1      fvdl 		default:
    459   1.1      fvdl 			break;
    460   1.1      fvdl 		}
    461   1.5   thorpej 		if (igsc->sc_smartspeed++ == IGPHY_TICK_MAX)
    462   1.5   thorpej 			igsc->sc_smartspeed = 0;
    463   1.5   thorpej 	} else
    464   1.5   thorpej 		igsc->sc_smartspeed = 0;
    465   1.1      fvdl }
    466