Home | History | Annotate | Line # | Download | only in mii
brgphy.c revision 1.43
      1  1.43   msaitoh /*	$NetBSD: brgphy.c,v 1.43 2009/04/19 11:10:36 msaitoh Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.1   thorpej  * Copyright (c) 1998, 1999, 2000, 2001 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  *
     20   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31   1.1   thorpej  */
     32   1.1   thorpej 
     33   1.1   thorpej /*
     34   1.1   thorpej  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
     35   1.1   thorpej  *
     36   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     37   1.1   thorpej  * modification, are permitted provided that the following conditions
     38   1.1   thorpej  * are met:
     39   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     40   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     41   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     42   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     43   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     44   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     45   1.1   thorpej  *    must display the following acknowledgement:
     46   1.1   thorpej  *	This product includes software developed by Manuel Bouyer.
     47   1.1   thorpej  * 4. The name of the author may not be used to endorse or promote products
     48   1.1   thorpej  *    derived from this software without specific prior written permission.
     49   1.1   thorpej  *
     50   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     51   1.1   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     52   1.1   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     53   1.1   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     54   1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     55   1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     56   1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     57   1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     58   1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     59   1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     60   1.1   thorpej  */
     61   1.1   thorpej 
     62   1.1   thorpej /*
     63   1.1   thorpej  * driver for the Broadcom BCM5400 Gig-E PHY.
     64   1.1   thorpej  *
     65   1.1   thorpej  * Programming information for this PHY was gleaned from FreeBSD
     66   1.1   thorpej  * (they were apparently able to get a datasheet from Broadcom).
     67   1.1   thorpej  */
     68   1.5     lukem 
     69   1.5     lukem #include <sys/cdefs.h>
     70  1.43   msaitoh __KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.43 2009/04/19 11:10:36 msaitoh Exp $");
     71   1.1   thorpej 
     72   1.1   thorpej #include <sys/param.h>
     73   1.1   thorpej #include <sys/systm.h>
     74   1.1   thorpej #include <sys/kernel.h>
     75   1.1   thorpej #include <sys/device.h>
     76   1.1   thorpej #include <sys/socket.h>
     77   1.1   thorpej #include <sys/errno.h>
     78   1.1   thorpej 
     79   1.1   thorpej #include <net/if.h>
     80   1.1   thorpej #include <net/if_media.h>
     81   1.1   thorpej 
     82   1.1   thorpej #include <dev/mii/mii.h>
     83   1.1   thorpej #include <dev/mii/miivar.h>
     84   1.1   thorpej #include <dev/mii/miidevs.h>
     85   1.1   thorpej 
     86   1.1   thorpej #include <dev/mii/brgphyreg.h>
     87   1.1   thorpej 
     88  1.43   msaitoh #include <dev/pci/if_bgereg.h>
     89  1.43   msaitoh #if 0
     90  1.43   msaitoh #include <dev/pci/if_bnxreg.h>
     91  1.43   msaitoh #endif
     92  1.43   msaitoh 
     93  1.39   xtraeme static int	brgphymatch(device_t, cfdata_t, void *);
     94  1.39   xtraeme static void	brgphyattach(device_t, device_t, void *);
     95   1.1   thorpej 
     96  1.42    dyoung CFATTACH_DECL3_NEW(brgphy, sizeof(struct mii_softc),
     97  1.42    dyoung     brgphymatch, brgphyattach, mii_phy_detach, mii_phy_activate, NULL, NULL,
     98  1.42    dyoung     DVF_DETACH_SHUTDOWN);
     99   1.1   thorpej 
    100  1.21   thorpej static int	brgphy_service(struct mii_softc *, struct mii_data *, int);
    101  1.21   thorpej static void	brgphy_status(struct mii_softc *);
    102  1.32   msaitoh static int	brgphy_mii_phy_auto(struct mii_softc *);
    103  1.32   msaitoh static void	brgphy_loop(struct mii_softc *);
    104  1.43   msaitoh static void	brgphy_reset(struct mii_softc *);
    105  1.43   msaitoh static void	brgphy_bcm5401_dspcode(struct mii_softc *);
    106  1.43   msaitoh static void	brgphy_bcm5411_dspcode(struct mii_softc *);
    107  1.43   msaitoh static void	brgphy_bcm5421_dspcode(struct mii_softc *);
    108  1.43   msaitoh static void	brgphy_bcm54k2_dspcode(struct mii_softc *);
    109  1.43   msaitoh static void	brgphy_adc_bug(struct mii_softc *);
    110  1.43   msaitoh static void	brgphy_5704_a0_bug(struct mii_softc *);
    111  1.43   msaitoh static void	brgphy_ber_bug(struct mii_softc *);
    112  1.43   msaitoh static void	brgphy_crc_bug(struct mii_softc *);
    113   1.1   thorpej 
    114  1.10   thorpej 
    115  1.21   thorpej static const struct mii_phy_funcs brgphy_funcs = {
    116  1.43   msaitoh 	brgphy_service, brgphy_status, brgphy_reset,
    117  1.34     markd };
    118  1.34     markd 
    119  1.21   thorpej static const struct mii_phydesc brgphys[] = {
    120   1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5400,
    121   1.1   thorpej 	  MII_STR_BROADCOM_BCM5400 },
    122   1.2   thorpej 
    123   1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5401,
    124   1.1   thorpej 	  MII_STR_BROADCOM_BCM5401 },
    125   1.2   thorpej 
    126   1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5411,
    127   1.1   thorpej 	  MII_STR_BROADCOM_BCM5411 },
    128   1.9   thorpej 
    129   1.9   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5421,
    130   1.9   thorpej 	  MII_STR_BROADCOM_BCM5421 },
    131   1.7      fvdl 
    132  1.43   msaitoh 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM54K2,
    133  1.43   msaitoh 	  MII_STR_BROADCOM_BCM54K2 },
    134  1.43   msaitoh 
    135  1.43   msaitoh 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5462,
    136  1.43   msaitoh 	  MII_STR_BROADCOM_BCM5462 },
    137  1.43   msaitoh 
    138   1.7      fvdl 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5701,
    139   1.7      fvdl 	  MII_STR_BROADCOM_BCM5701 },
    140  1.14      matt 
    141  1.14      matt 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5703,
    142  1.14      matt 	  MII_STR_BROADCOM_BCM5703 },
    143   1.1   thorpej 
    144  1.15  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5704,
    145  1.15  jonathan 	  MII_STR_BROADCOM_BCM5704 },
    146  1.15  jonathan 
    147  1.25  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5705,
    148  1.25  jonathan 	  MII_STR_BROADCOM_BCM5705 },
    149  1.25  jonathan 
    150  1.24  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5714,
    151  1.24  jonathan 	  MII_STR_BROADCOM_BCM5714 },
    152  1.18   hannken 
    153  1.22      cube 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5750,
    154  1.22      cube 	  MII_STR_BROADCOM_BCM5750 },
    155  1.22      cube 
    156  1.31   tsutsui 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5752,
    157  1.31   tsutsui 	  MII_STR_BROADCOM_BCM5752 },
    158  1.31   tsutsui 
    159  1.27  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5780,
    160  1.27  jonathan 	  MII_STR_BROADCOM_BCM5780 },
    161  1.27  jonathan 
    162  1.36     markd 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5708C,
    163  1.36     markd 	  MII_STR_BROADCOM_BCM5708C },
    164  1.36     markd 
    165  1.43   msaitoh 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5722,
    166  1.43   msaitoh 	  MII_STR_BROADCOM2_BCM5722 },
    167  1.43   msaitoh 
    168  1.34     markd 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5755,
    169  1.34     markd 	  MII_STR_BROADCOM2_BCM5755 },
    170  1.34     markd 
    171  1.34     markd 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5754,
    172  1.34     markd 	  MII_STR_BROADCOM2_BCM5754 },
    173  1.34     markd 
    174  1.40    cegger 	{ MII_OUI_xxBROADCOM_ALT1,	MII_MODEL_xxBROADCOM_ALT1_BCM5906,
    175  1.40    cegger 	  MII_STR_xxBROADCOM_ALT1_BCM5906 },
    176  1.40    cegger 
    177   1.1   thorpej 	{ 0,				0,
    178   1.1   thorpej 	  NULL },
    179   1.1   thorpej };
    180   1.1   thorpej 
    181  1.21   thorpej static int
    182  1.29  christos brgphymatch(struct device *parent, struct cfdata *match,
    183  1.28  christos     void *aux)
    184   1.1   thorpej {
    185   1.1   thorpej 	struct mii_attach_args *ma = aux;
    186   1.1   thorpej 
    187   1.2   thorpej 	if (mii_phy_match(ma, brgphys) != NULL)
    188   1.1   thorpej 		return (10);
    189   1.1   thorpej 
    190   1.1   thorpej 	return (0);
    191   1.1   thorpej }
    192   1.1   thorpej 
    193  1.21   thorpej static void
    194  1.29  christos brgphyattach(struct device *parent, struct device *self, void *aux)
    195   1.1   thorpej {
    196  1.26   thorpej 	struct mii_softc *sc = device_private(self);
    197   1.1   thorpej 	struct mii_attach_args *ma = aux;
    198   1.1   thorpej 	struct mii_data *mii = ma->mii_data;
    199   1.2   thorpej 	const struct mii_phydesc *mpd;
    200   1.1   thorpej 
    201   1.2   thorpej 	mpd = mii_phy_match(ma, brgphys);
    202  1.17   thorpej 	aprint_naive(": Media interface\n");
    203  1.17   thorpej 	aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
    204   1.1   thorpej 
    205  1.39   xtraeme 	sc->mii_dev = self;
    206   1.1   thorpej 	sc->mii_inst = mii->mii_instance;
    207   1.1   thorpej 	sc->mii_phy = ma->mii_phyno;
    208  1.32   msaitoh 	sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
    209  1.43   msaitoh 	sc->mii_mpd_rev = MII_REV(ma->mii_id2);
    210   1.1   thorpej 	sc->mii_pdata = mii;
    211   1.6   thorpej 	sc->mii_flags = ma->mii_flags;
    212  1.30  christos 	sc->mii_anegticks = MII_ANEGTICKS;
    213  1.43   msaitoh 	sc->mii_funcs = &brgphy_funcs;
    214  1.10   thorpej 
    215   1.1   thorpej 	PHY_RESET(sc);
    216   1.1   thorpej 
    217   1.1   thorpej 	sc->mii_capabilities =
    218   1.1   thorpej 	    PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
    219   1.1   thorpej 	if (sc->mii_capabilities & BMSR_EXTSTAT)
    220   1.1   thorpej 		sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
    221   1.1   thorpej 
    222  1.39   xtraeme 	aprint_normal_dev(self, "");
    223   1.1   thorpej 	if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
    224   1.1   thorpej 	    (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
    225  1.17   thorpej 		aprint_error("no media present");
    226   1.1   thorpej 	else
    227   1.1   thorpej 		mii_phy_add_media(sc);
    228  1.17   thorpej 	aprint_normal("\n");
    229   1.1   thorpej }
    230   1.1   thorpej 
    231  1.21   thorpej static int
    232   1.4   thorpej brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
    233   1.1   thorpej {
    234   1.1   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    235  1.32   msaitoh 	int reg, speed, gig;
    236   1.1   thorpej 
    237   1.1   thorpej 	switch (cmd) {
    238   1.1   thorpej 	case MII_POLLSTAT:
    239   1.1   thorpej 		/*
    240   1.1   thorpej 		 * If we're not polling our PHY instance, just return.
    241   1.1   thorpej 		 */
    242   1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    243   1.1   thorpej 			return (0);
    244   1.1   thorpej 		break;
    245   1.1   thorpej 
    246   1.1   thorpej 	case MII_MEDIACHG:
    247   1.1   thorpej 		/*
    248   1.1   thorpej 		 * If the media indicates a different PHY instance,
    249   1.1   thorpej 		 * isolate ourselves.
    250   1.1   thorpej 		 */
    251   1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
    252   1.1   thorpej 			reg = PHY_READ(sc, MII_BMCR);
    253   1.1   thorpej 			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
    254   1.1   thorpej 			return (0);
    255   1.1   thorpej 		}
    256   1.1   thorpej 
    257   1.1   thorpej 		/*
    258   1.1   thorpej 		 * If the interface is not up, don't do anything.
    259   1.1   thorpej 		 */
    260   1.1   thorpej 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    261   1.1   thorpej 			break;
    262   1.1   thorpej 
    263  1.32   msaitoh 		PHY_RESET(sc); /* XXX hardware bug work-around */
    264  1.32   msaitoh 
    265  1.32   msaitoh 		switch (IFM_SUBTYPE(ife->ifm_media)) {
    266  1.32   msaitoh 		case IFM_AUTO:
    267  1.32   msaitoh 			(void) brgphy_mii_phy_auto(sc);
    268  1.32   msaitoh 			break;
    269  1.32   msaitoh 		case IFM_1000_T:
    270  1.32   msaitoh 			speed = BMCR_S1000;
    271  1.32   msaitoh 			goto setit;
    272  1.32   msaitoh 		case IFM_100_TX:
    273  1.32   msaitoh 			speed = BMCR_S100;
    274  1.32   msaitoh 			goto setit;
    275  1.32   msaitoh 		case IFM_10_T:
    276  1.32   msaitoh 			speed = BMCR_S10;
    277  1.32   msaitoh setit:
    278  1.32   msaitoh 			brgphy_loop(sc);
    279  1.32   msaitoh 			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
    280  1.32   msaitoh 				speed |= BMCR_FDX;
    281  1.32   msaitoh 				gig = GTCR_ADV_1000TFDX;
    282  1.32   msaitoh 			} else {
    283  1.32   msaitoh 				gig = GTCR_ADV_1000THDX;
    284  1.32   msaitoh 			}
    285  1.32   msaitoh 
    286  1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, 0);
    287  1.32   msaitoh 			PHY_WRITE(sc, MII_BMCR, speed);
    288  1.32   msaitoh 			PHY_WRITE(sc, MII_ANAR, ANAR_CSMA);
    289  1.32   msaitoh 
    290  1.32   msaitoh 			if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
    291  1.32   msaitoh 				break;
    292  1.32   msaitoh 
    293  1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, gig);
    294  1.32   msaitoh 			PHY_WRITE(sc, MII_BMCR,
    295  1.32   msaitoh 			    speed|BMCR_AUTOEN|BMCR_STARTNEG);
    296  1.32   msaitoh 
    297  1.32   msaitoh 			if (sc->mii_mpd_model != MII_MODEL_BROADCOM_BCM5701)
    298  1.33   msaitoh 				break;
    299  1.32   msaitoh 
    300  1.32   msaitoh 			if (mii->mii_media.ifm_media & IFM_ETH_MASTER)
    301  1.32   msaitoh 				gig |= GTCR_MAN_MS | GTCR_ADV_MS;
    302  1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, gig);
    303  1.32   msaitoh 			break;
    304  1.32   msaitoh 		default:
    305  1.32   msaitoh 			return (EINVAL);
    306  1.32   msaitoh 		}
    307   1.1   thorpej 		break;
    308   1.1   thorpej 
    309   1.1   thorpej 	case MII_TICK:
    310   1.1   thorpej 		/*
    311   1.1   thorpej 		 * If we're not currently selected, just return.
    312   1.1   thorpej 		 */
    313   1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    314   1.1   thorpej 			return (0);
    315   1.1   thorpej 
    316   1.1   thorpej 		if (mii_phy_tick(sc) == EJUSTRETURN)
    317   1.1   thorpej 			return (0);
    318   1.1   thorpej 		break;
    319   1.1   thorpej 
    320   1.1   thorpej 	case MII_DOWN:
    321   1.1   thorpej 		mii_phy_down(sc);
    322   1.1   thorpej 		return (0);
    323   1.1   thorpej 	}
    324   1.1   thorpej 
    325   1.1   thorpej 	/* Update the media status. */
    326   1.1   thorpej 	mii_phy_status(sc);
    327   1.1   thorpej 
    328  1.10   thorpej 	/*
    329  1.32   msaitoh 	 * Callback if something changed. Note that we need to poke the DSP on
    330  1.32   msaitoh 	 * the Broadcom PHYs if the media changes.
    331  1.10   thorpej 	 */
    332  1.23     perry 	if (sc->mii_media_active != mii->mii_media_active ||
    333  1.10   thorpej 	    sc->mii_media_status != mii->mii_media_status ||
    334  1.10   thorpej 	    cmd == MII_MEDIACHG) {
    335  1.43   msaitoh 		switch (sc->mii_mpd_model) {
    336  1.43   msaitoh 		case MII_MODEL_BROADCOM_BCM5400:
    337  1.43   msaitoh 			brgphy_bcm5401_dspcode(sc);
    338  1.43   msaitoh 			break;
    339  1.43   msaitoh 		case MII_MODEL_BROADCOM_BCM5401:
    340  1.43   msaitoh 			if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
    341  1.43   msaitoh 				brgphy_bcm5401_dspcode(sc);
    342  1.43   msaitoh 			break;
    343  1.43   msaitoh 		case MII_MODEL_BROADCOM_BCM5411:
    344  1.43   msaitoh 			brgphy_bcm5411_dspcode(sc);
    345  1.43   msaitoh 			break;
    346  1.43   msaitoh 		}
    347  1.10   thorpej 	}
    348  1.43   msaitoh 
    349  1.43   msaitoh 	/* Callback if something changed. */
    350  1.43   msaitoh 	mii_phy_update(sc, cmd);
    351   1.1   thorpej 	return (0);
    352   1.1   thorpej }
    353   1.1   thorpej 
    354  1.21   thorpej static void
    355   1.4   thorpej brgphy_status(struct mii_softc *sc)
    356   1.1   thorpej {
    357   1.1   thorpej 	struct mii_data *mii = sc->mii_pdata;
    358   1.1   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    359   1.1   thorpej 	int bmcr, auxsts, gtsr;
    360   1.1   thorpej 
    361   1.1   thorpej 	mii->mii_media_status = IFM_AVALID;
    362   1.1   thorpej 	mii->mii_media_active = IFM_ETHER;
    363   1.1   thorpej 
    364   1.1   thorpej 	auxsts = PHY_READ(sc, BRGPHY_MII_AUXSTS);
    365   1.1   thorpej 
    366   1.1   thorpej 	if (auxsts & BRGPHY_AUXSTS_LINK)
    367   1.1   thorpej 		mii->mii_media_status |= IFM_ACTIVE;
    368   1.1   thorpej 
    369   1.1   thorpej 	bmcr = PHY_READ(sc, MII_BMCR);
    370   1.1   thorpej 	if (bmcr & BMCR_ISO) {
    371   1.1   thorpej 		mii->mii_media_active |= IFM_NONE;
    372   1.1   thorpej 		mii->mii_media_status = 0;
    373   1.1   thorpej 		return;
    374   1.1   thorpej 	}
    375   1.1   thorpej 
    376   1.1   thorpej 	if (bmcr & BMCR_LOOP)
    377   1.1   thorpej 		mii->mii_media_active |= IFM_LOOP;
    378   1.1   thorpej 
    379   1.1   thorpej 	if (bmcr & BMCR_AUTOEN) {
    380   1.1   thorpej 		/*
    381   1.1   thorpej 		 * The media status bits are only valid of autonegotiation
    382   1.1   thorpej 		 * has completed (or it's disabled).
    383   1.1   thorpej 		 */
    384   1.1   thorpej 		if ((auxsts & BRGPHY_AUXSTS_ACOMP) == 0) {
    385   1.1   thorpej 			/* Erg, still trying, I guess... */
    386   1.1   thorpej 			mii->mii_media_active |= IFM_NONE;
    387   1.1   thorpej 			return;
    388   1.1   thorpej 		}
    389   1.1   thorpej 
    390   1.1   thorpej 		switch (auxsts & BRGPHY_AUXSTS_AN_RES) {
    391   1.1   thorpej 		case BRGPHY_RES_1000FD:
    392   1.3     bjh21 			mii->mii_media_active |= IFM_1000_T|IFM_FDX;
    393   1.1   thorpej 			gtsr = PHY_READ(sc, MII_100T2SR);
    394   1.1   thorpej 			if (gtsr & GTSR_MS_RES)
    395   1.1   thorpej 				mii->mii_media_active |= IFM_ETH_MASTER;
    396   1.1   thorpej 			break;
    397   1.1   thorpej 
    398   1.1   thorpej 		case BRGPHY_RES_1000HD:
    399   1.3     bjh21 			mii->mii_media_active |= IFM_1000_T;
    400   1.1   thorpej 			gtsr = PHY_READ(sc, MII_100T2SR);
    401   1.1   thorpej 			if (gtsr & GTSR_MS_RES)
    402   1.1   thorpej 				mii->mii_media_active |= IFM_ETH_MASTER;
    403   1.1   thorpej 			break;
    404   1.1   thorpej 
    405   1.1   thorpej 		case BRGPHY_RES_100FD:
    406   1.1   thorpej 			mii->mii_media_active |= IFM_100_TX|IFM_FDX;
    407   1.1   thorpej 			break;
    408   1.1   thorpej 
    409   1.1   thorpej 		case BRGPHY_RES_100T4:
    410   1.1   thorpej 			mii->mii_media_active |= IFM_100_T4;
    411   1.1   thorpej 			break;
    412   1.1   thorpej 
    413   1.1   thorpej 		case BRGPHY_RES_100HD:
    414   1.1   thorpej 			mii->mii_media_active |= IFM_100_TX;
    415   1.1   thorpej 			break;
    416   1.1   thorpej 
    417   1.1   thorpej 		case BRGPHY_RES_10FD:
    418   1.1   thorpej 			mii->mii_media_active |= IFM_10_T|IFM_FDX;
    419   1.1   thorpej 			break;
    420   1.1   thorpej 
    421   1.1   thorpej 		case BRGPHY_RES_10HD:
    422   1.1   thorpej 			mii->mii_media_active |= IFM_10_T;
    423   1.1   thorpej 			break;
    424   1.1   thorpej 
    425   1.1   thorpej 		default:
    426   1.1   thorpej 			mii->mii_media_active |= IFM_NONE;
    427   1.1   thorpej 			mii->mii_media_status = 0;
    428   1.1   thorpej 		}
    429  1.19   thorpej 		if (mii->mii_media_active & IFM_FDX)
    430  1.20   thorpej 			mii->mii_media_active |= mii_phy_flowstatus(sc);
    431   1.1   thorpej 	} else
    432   1.1   thorpej 		mii->mii_media_active = ife->ifm_media;
    433  1.10   thorpej }
    434  1.10   thorpej 
    435  1.32   msaitoh int
    436  1.32   msaitoh brgphy_mii_phy_auto(struct mii_softc *sc)
    437  1.32   msaitoh {
    438  1.32   msaitoh 	int anar, ktcr = 0;
    439  1.32   msaitoh 
    440  1.32   msaitoh 	brgphy_loop(sc);
    441  1.32   msaitoh 	PHY_RESET(sc);
    442  1.32   msaitoh 	ktcr = GTCR_ADV_1000TFDX|GTCR_ADV_1000THDX;
    443  1.32   msaitoh 	if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701)
    444  1.32   msaitoh 		ktcr |= GTCR_MAN_MS|GTCR_ADV_MS;
    445  1.32   msaitoh 	PHY_WRITE(sc, MII_100T2CR, ktcr);
    446  1.32   msaitoh 	ktcr = PHY_READ(sc, MII_100T2CR);
    447  1.32   msaitoh 	DELAY(1000);
    448  1.32   msaitoh 	anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
    449  1.32   msaitoh 	if (sc->mii_flags & MIIF_DOPAUSE)
    450  1.32   msaitoh 		anar |= ANAR_FC| ANAR_X_PAUSE_ASYM;
    451  1.32   msaitoh 
    452  1.32   msaitoh 	PHY_WRITE(sc, MII_ANAR, anar);
    453  1.32   msaitoh 	DELAY(1000);
    454  1.32   msaitoh 	PHY_WRITE(sc, MII_BMCR,
    455  1.32   msaitoh 	    BMCR_AUTOEN | BMCR_STARTNEG);
    456  1.32   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00);
    457  1.32   msaitoh 
    458  1.32   msaitoh 	return (EJUSTRETURN);
    459  1.32   msaitoh }
    460  1.32   msaitoh 
    461  1.32   msaitoh void
    462  1.32   msaitoh brgphy_loop(struct mii_softc *sc)
    463  1.32   msaitoh {
    464  1.32   msaitoh 	u_int32_t bmsr;
    465  1.32   msaitoh 	int i;
    466  1.32   msaitoh 
    467  1.32   msaitoh 	PHY_WRITE(sc, MII_BMCR, BMCR_LOOP);
    468  1.33   msaitoh 	for (i = 0; i < 15000; i++) {
    469  1.32   msaitoh 		bmsr = PHY_READ(sc, MII_BMSR);
    470  1.32   msaitoh 		if (!(bmsr & BMSR_LINK))
    471  1.32   msaitoh 			break;
    472  1.32   msaitoh 		DELAY(10);
    473  1.32   msaitoh 	}
    474  1.32   msaitoh }
    475  1.32   msaitoh 
    476  1.21   thorpej static void
    477  1.43   msaitoh brgphy_reset(struct mii_softc *sc)
    478  1.10   thorpej {
    479  1.43   msaitoh 	struct bge_softc *bge_sc = NULL;
    480  1.43   msaitoh #if 0
    481  1.43   msaitoh 	struct bnx_softc *bnx_sc = NULL;
    482  1.43   msaitoh #endif
    483  1.43   msaitoh 	const char *devname;
    484  1.10   thorpej 
    485  1.43   msaitoh 	devname = device_parent(sc->mii_dev)->dv_cfdriver->cd_name;
    486  1.10   thorpej 
    487  1.10   thorpej 	mii_phy_reset(sc);
    488  1.10   thorpej 
    489  1.43   msaitoh 	switch (sc->mii_mpd_model) {
    490  1.43   msaitoh 	case MII_MODEL_BROADCOM_BCM5400:
    491  1.43   msaitoh 		brgphy_bcm5401_dspcode(sc);
    492  1.43   msaitoh 		break;
    493  1.43   msaitoh 	case MII_MODEL_BROADCOM_BCM5401:
    494  1.43   msaitoh 		if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
    495  1.43   msaitoh 			brgphy_bcm5401_dspcode(sc);
    496  1.43   msaitoh 		break;
    497  1.43   msaitoh 	case MII_MODEL_BROADCOM_BCM5411:
    498  1.43   msaitoh 		brgphy_bcm5411_dspcode(sc);
    499  1.43   msaitoh 		break;
    500  1.43   msaitoh 	case MII_MODEL_BROADCOM_BCM5421:
    501  1.43   msaitoh 		brgphy_bcm5421_dspcode(sc);
    502  1.43   msaitoh 		break;
    503  1.43   msaitoh 	case MII_MODEL_BROADCOM_BCM54K2:
    504  1.43   msaitoh 		brgphy_bcm54k2_dspcode(sc);
    505  1.43   msaitoh 		break;
    506  1.43   msaitoh 	}
    507  1.15  jonathan 
    508  1.43   msaitoh 	/* Handle any bge (NetXtreme/NetLink) workarounds. */
    509  1.43   msaitoh 	if (strcmp(devname, "bge") == 0) {
    510  1.43   msaitoh 		if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
    511  1.43   msaitoh 			bge_sc = sc->mii_pdata->mii_ifp->if_softc;
    512  1.43   msaitoh 
    513  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_PHY_ADC_BUG)
    514  1.43   msaitoh 				brgphy_adc_bug(sc);
    515  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_PHY_5704_A0_BUG)
    516  1.43   msaitoh 				brgphy_5704_a0_bug(sc);
    517  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_PHY_BER_BUG)
    518  1.43   msaitoh 				brgphy_ber_bug(sc);
    519  1.43   msaitoh 			else if (bge_sc->bge_flags & BGE_PHY_JITTER_BUG) {
    520  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0c00);
    521  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG,
    522  1.43   msaitoh 				    0x000a);
    523  1.43   msaitoh 
    524  1.43   msaitoh 				if (bge_sc->bge_flags & BGE_PHY_ADJUST_TRIM) {
    525  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
    526  1.43   msaitoh 					    0x110b);
    527  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_TEST1,
    528  1.43   msaitoh 					    BRGPHY_TEST1_TRIM_EN | 0x4);
    529  1.43   msaitoh 				} else {
    530  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
    531  1.43   msaitoh 					    0x010b);
    532  1.43   msaitoh 				}
    533  1.15  jonathan 
    534  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0400);
    535  1.43   msaitoh 			}
    536  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_PHY_CRC_BUG)
    537  1.43   msaitoh 				brgphy_crc_bug(sc);
    538  1.15  jonathan 
    539  1.43   msaitoh #if 0
    540  1.43   msaitoh 			/* Set Jumbo frame settings in the PHY. */
    541  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_JUMBO_CAP)
    542  1.43   msaitoh 				brgphy_jumbo_settings(sc);
    543  1.43   msaitoh #endif
    544  1.43   msaitoh 
    545  1.43   msaitoh 			/* Adjust output voltage */
    546  1.43   msaitoh 			if (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5906)
    547  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_EPHY_PTEST, 0x12);
    548  1.43   msaitoh 
    549  1.43   msaitoh #if 0
    550  1.43   msaitoh 			/* Enable Ethernet@Wirespeed */
    551  1.43   msaitoh 			if (!(bge_sc->bge_flags & BGE_NO_ETH_WIRE_SPEED))
    552  1.43   msaitoh 				brgphy_eth_wirespeed(sc);
    553  1.43   msaitoh 
    554  1.43   msaitoh 			/* Enable Link LED on Dell boxes */
    555  1.43   msaitoh 			if (bge_sc->bge_flags & BGE_NO_3LED) {
    556  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
    557  1.43   msaitoh 				PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL)
    558  1.43   msaitoh 					& ~BRGPHY_PHY_EXTCTL_3_LED);
    559  1.43   msaitoh 			}
    560  1.43   msaitoh #endif
    561  1.43   msaitoh 		}
    562  1.43   msaitoh #if 0 /* not yet */
    563  1.43   msaitoh 	/* Handle any bnx (NetXtreme II) workarounds. */
    564  1.43   msaitoh 	} else if (strcmp(devname, "bnx") == 0) {
    565  1.43   msaitoh 		bnx_sc = sc->mii_pdata->mii_ifp->if_softc;
    566  1.43   msaitoh 
    567  1.43   msaitoh 		if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM2_BCM5708S) {
    568  1.43   msaitoh 			/* Store autoneg capabilities/results in digital block (Page 0) */
    569  1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG3_PG2);
    570  1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG2_DIGCTL_3_0,
    571  1.43   msaitoh 				BRGPHY_5708S_PG2_DIGCTL_3_0_USE_IEEE);
    572  1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG_PG0);
    573  1.43   msaitoh 
    574  1.43   msaitoh 			/* Enable fiber mode and autodetection */
    575  1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL1,
    576  1.43   msaitoh 				PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL1) |
    577  1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL1_AUTODET_EN |
    578  1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL1_FIBER_MODE);
    579  1.43   msaitoh 
    580  1.43   msaitoh 			/* Enable parallel detection */
    581  1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL2,
    582  1.43   msaitoh 				PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL2) |
    583  1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL2_PAR_DET_EN);
    584  1.43   msaitoh 
    585  1.43   msaitoh 			/* Advertise 2.5G support through next page during autoneg */
    586  1.43   msaitoh 			if (bnx_sc->bnx_phy_flags & BNX_PHY_2_5G_CAPABLE_FLAG)
    587  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1,
    588  1.43   msaitoh 					PHY_READ(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1) |
    589  1.43   msaitoh 					BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
    590  1.43   msaitoh 
    591  1.43   msaitoh 			/* Increase TX signal amplitude */
    592  1.43   msaitoh 			if ((BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_A0) ||
    593  1.43   msaitoh 			    (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B0) ||
    594  1.43   msaitoh 			    (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B1)) {
    595  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    596  1.43   msaitoh 					BRGPHY_5708S_TX_MISC_PG5);
    597  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL1,
    598  1.43   msaitoh 					PHY_READ(sc, BRGPHY_5708S_PG5_TXACTL1) &
    599  1.43   msaitoh 					~BRGPHY_5708S_PG5_TXACTL1_VCM);
    600  1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    601  1.43   msaitoh 					BRGPHY_5708S_DIG_PG0);
    602  1.43   msaitoh 			}
    603  1.15  jonathan 
    604  1.43   msaitoh 			/* Backplanes use special driver/pre-driver/pre-emphasis values. */
    605  1.43   msaitoh 			if ((bnx_sc->bnx_shared_hw_cfg & BNX_SHARED_HW_CFG_PHY_BACKPLANE) &&
    606  1.43   msaitoh 			    (bnx_sc->bnx_port_hw_cfg & BNX_PORT_HW_CFG_CFG_TXCTL3_MASK)) {
    607  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    608  1.43   msaitoh 						BRGPHY_5708S_TX_MISC_PG5);
    609  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL3,
    610  1.43   msaitoh 						bnx_sc->bnx_port_hw_cfg &
    611  1.43   msaitoh 						BNX_PORT_HW_CFG_CFG_TXCTL3_MASK);
    612  1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    613  1.43   msaitoh 						BRGPHY_5708S_DIG_PG0);
    614  1.43   msaitoh 			}
    615  1.43   msaitoh 		} else {
    616  1.43   msaitoh 			if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
    617  1.43   msaitoh 				brgphy_ber_bug(sc);
    618  1.18   hannken 
    619  1.43   msaitoh 				/* Set Jumbo frame settings in the PHY. */
    620  1.43   msaitoh 				brgphy_jumbo_settings(sc);
    621  1.18   hannken 
    622  1.43   msaitoh 				/* Enable Ethernet@Wirespeed */
    623  1.43   msaitoh 				brgphy_eth_wirespeed(sc);
    624  1.43   msaitoh 			}
    625  1.43   msaitoh 		}
    626  1.43   msaitoh #endif
    627  1.43   msaitoh 	}
    628  1.34     markd }
    629  1.34     markd 
    630  1.16  jonathan /* Turn off tap power management on 5401. */
    631  1.10   thorpej static void
    632  1.43   msaitoh brgphy_bcm5401_dspcode(struct mii_softc *sc)
    633  1.10   thorpej {
    634  1.10   thorpej 	static const struct {
    635  1.10   thorpej 		int		reg;
    636  1.10   thorpej 		uint16_t	val;
    637  1.10   thorpej 	} dspcode[] = {
    638  1.16  jonathan 		{ BRGPHY_MII_AUXCTL,		0x0c20 },
    639  1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0012 },
    640  1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x1804 },
    641  1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0013 },
    642  1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x1204 },
    643  1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x8006 },
    644  1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0132 },
    645  1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x8006 },
    646  1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0232 },
    647  1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
    648  1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0a20 },
    649  1.10   thorpej 		{ 0,				0 },
    650  1.10   thorpej 	};
    651  1.10   thorpej 	int i;
    652  1.10   thorpej 
    653  1.10   thorpej 	for (i = 0; dspcode[i].reg != 0; i++)
    654  1.10   thorpej 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    655  1.16  jonathan     delay(40);
    656  1.10   thorpej }
    657  1.10   thorpej 
    658  1.10   thorpej static void
    659  1.43   msaitoh brgphy_bcm5411_dspcode(struct mii_softc *sc)
    660  1.10   thorpej {
    661  1.10   thorpej 	static const struct {
    662  1.10   thorpej 		int		reg;
    663  1.10   thorpej 		uint16_t	val;
    664  1.10   thorpej 	} dspcode[] = {
    665  1.10   thorpej 		{ 0x1c,				0x8c23 },
    666  1.10   thorpej 		{ 0x1c,				0x8ca3 },
    667  1.10   thorpej 		{ 0x1c,				0x8c23 },
    668  1.15  jonathan 		{ 0,				0 },
    669  1.15  jonathan 	};
    670  1.15  jonathan 	int i;
    671  1.15  jonathan 
    672  1.15  jonathan 	for (i = 0; dspcode[i].reg != 0; i++)
    673  1.15  jonathan 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    674  1.15  jonathan }
    675  1.15  jonathan 
    676  1.43   msaitoh void
    677  1.43   msaitoh brgphy_bcm5421_dspcode(struct mii_softc *sc)
    678  1.43   msaitoh {
    679  1.43   msaitoh 	uint16_t data;
    680  1.43   msaitoh 
    681  1.43   msaitoh 	/* Set Class A mode */
    682  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x1007);
    683  1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
    684  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0400);
    685  1.43   msaitoh 
    686  1.43   msaitoh 	/* Set FFE gamma override to -0.125 */
    687  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0007);
    688  1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
    689  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0800);
    690  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x000a);
    691  1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
    692  1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, data | 0x0200);
    693  1.43   msaitoh }
    694  1.43   msaitoh 
    695  1.43   msaitoh void
    696  1.43   msaitoh brgphy_bcm54k2_dspcode(struct mii_softc *sc)
    697  1.43   msaitoh {
    698  1.43   msaitoh 	static const struct {
    699  1.43   msaitoh 		int		reg;
    700  1.43   msaitoh 		uint16_t	val;
    701  1.43   msaitoh 	} dspcode[] = {
    702  1.43   msaitoh 		{ 4,				0x01e1 },
    703  1.43   msaitoh 		{ 9,				0x0300 },
    704  1.43   msaitoh 		{ 0,				0 },
    705  1.43   msaitoh 	};
    706  1.43   msaitoh 	int i;
    707  1.43   msaitoh 
    708  1.43   msaitoh 	for (i = 0; dspcode[i].reg != 0; i++)
    709  1.43   msaitoh 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    710  1.43   msaitoh }
    711  1.43   msaitoh 
    712  1.15  jonathan static void
    713  1.43   msaitoh brgphy_adc_bug(struct mii_softc *sc)
    714  1.15  jonathan {
    715  1.15  jonathan 	static const struct {
    716  1.15  jonathan 		int		reg;
    717  1.15  jonathan 		uint16_t	val;
    718  1.15  jonathan 	} dspcode[] = {
    719  1.15  jonathan 		{ BRGPHY_MII_AUXCTL,		0x0c00 },
    720  1.15  jonathan 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
    721  1.15  jonathan 		{ BRGPHY_MII_DSP_RW_PORT,	0x2aaa },
    722  1.43   msaitoh 		{ BRGPHY_MII_DSP_ADDR_REG,	0x000a },
    723  1.43   msaitoh 		{ BRGPHY_MII_DSP_RW_PORT,	0x0323 },
    724  1.43   msaitoh 		{ BRGPHY_MII_AUXCTL,		0x0400 },
    725  1.15  jonathan 		{ 0,				0 },
    726  1.15  jonathan 	};
    727  1.15  jonathan 	int i;
    728  1.15  jonathan 
    729  1.15  jonathan 	for (i = 0; dspcode[i].reg != 0; i++)
    730  1.15  jonathan 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    731  1.15  jonathan }
    732  1.15  jonathan 
    733  1.15  jonathan static void
    734  1.43   msaitoh brgphy_5704_a0_bug(struct mii_softc *sc)
    735  1.15  jonathan {
    736  1.15  jonathan 	static const struct {
    737  1.15  jonathan 		int		reg;
    738  1.15  jonathan 		uint16_t	val;
    739  1.15  jonathan 	} dspcode[] = {
    740  1.15  jonathan 		{ 0x1c,				0x8d68 },
    741  1.33   msaitoh 		{ 0x1c,				0x8d68 },
    742  1.10   thorpej 		{ 0,				0 },
    743  1.10   thorpej 	};
    744  1.10   thorpej 	int i;
    745  1.10   thorpej 
    746  1.10   thorpej 	for (i = 0; dspcode[i].reg != 0; i++)
    747  1.10   thorpej 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    748   1.1   thorpej }
    749  1.22      cube 
    750  1.22      cube static void
    751  1.43   msaitoh brgphy_ber_bug(struct mii_softc *sc)
    752  1.22      cube {
    753  1.22      cube 	static const struct {
    754  1.22      cube 		int		reg;
    755  1.22      cube 		uint16_t	val;
    756  1.22      cube 	} dspcode[] = {
    757  1.22      cube 		{ BRGPHY_MII_AUXCTL,		0x0c00 },
    758  1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x000a },
    759  1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x310b },
    760  1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
    761  1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x9506 },
    762  1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x401f },
    763  1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x14e2 },
    764  1.22      cube 		{ BRGPHY_MII_AUXCTL,		0x0400 },
    765  1.22      cube 		{ 0,				0 },
    766  1.22      cube 	};
    767  1.22      cube 	int i;
    768  1.22      cube 
    769  1.22      cube 	for (i = 0; dspcode[i].reg != 0; i++)
    770  1.22      cube 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    771  1.22      cube }
    772  1.34     markd 
    773  1.43   msaitoh /* BCM5701 A0/B0 CRC bug workaround */
    774  1.43   msaitoh void
    775  1.43   msaitoh brgphy_crc_bug(struct mii_softc *sc)
    776  1.34     markd {
    777  1.34     markd 	static const struct {
    778  1.34     markd 		int		reg;
    779  1.34     markd 		uint16_t	val;
    780  1.34     markd 	} dspcode[] = {
    781  1.43   msaitoh 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0a75 },
    782  1.43   msaitoh 		{ 0x1c,				0x8c68 },
    783  1.43   msaitoh 		{ 0x1c,				0x8d68 },
    784  1.43   msaitoh 		{ 0x1c,				0x8c68 },
    785  1.34     markd 		{ 0,				0 },
    786  1.34     markd 	};
    787  1.34     markd 	int i;
    788  1.34     markd 
    789  1.34     markd 	for (i = 0; dspcode[i].reg != 0; i++)
    790  1.34     markd 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    791  1.34     markd }
    792