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