Home | History | Annotate | Line # | Download | only in mii
brgphy.c revision 1.59.8.3
      1  1.59.8.3    bouyer /*	$NetBSD: brgphy.c,v 1.59.8.3 2013/11/17 18:24:05 bouyer 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.57       jym  * driver for the Broadcom BCM5400 and BCM5700 Gig-E PHYs.
     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.59.8.3    bouyer __KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.59.8.3 2013/11/17 18:24:05 bouyer 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 #include <dev/pci/if_bnxreg.h>
     85      1.43   msaitoh 
     86      1.39   xtraeme static int	brgphymatch(device_t, cfdata_t, void *);
     87      1.39   xtraeme static void	brgphyattach(device_t, device_t, void *);
     88       1.1   thorpej 
     89      1.44   msaitoh struct brgphy_softc {
     90      1.44   msaitoh 	struct mii_softc sc_mii;
     91      1.54    dyoung 	bool sc_isbge;
     92      1.54    dyoung 	bool sc_isbnx;
     93      1.58       jym 	uint32_t sc_chipid;    /* parent's chipid */
     94      1.58       jym 	uint32_t sc_phyflags;  /* parent's phyflags */
     95      1.44   msaitoh };
     96      1.44   msaitoh 
     97      1.44   msaitoh CFATTACH_DECL3_NEW(brgphy, sizeof(struct brgphy_softc),
     98      1.42    dyoung     brgphymatch, brgphyattach, mii_phy_detach, mii_phy_activate, NULL, NULL,
     99      1.42    dyoung     DVF_DETACH_SHUTDOWN);
    100       1.1   thorpej 
    101      1.21   thorpej static int	brgphy_service(struct mii_softc *, struct mii_data *, int);
    102      1.21   thorpej static void	brgphy_status(struct mii_softc *);
    103      1.32   msaitoh static int	brgphy_mii_phy_auto(struct mii_softc *);
    104      1.32   msaitoh static void	brgphy_loop(struct mii_softc *);
    105      1.43   msaitoh static void	brgphy_reset(struct mii_softc *);
    106      1.43   msaitoh static void	brgphy_bcm5401_dspcode(struct mii_softc *);
    107      1.43   msaitoh static void	brgphy_bcm5411_dspcode(struct mii_softc *);
    108      1.43   msaitoh static void	brgphy_bcm5421_dspcode(struct mii_softc *);
    109      1.43   msaitoh static void	brgphy_bcm54k2_dspcode(struct mii_softc *);
    110      1.43   msaitoh static void	brgphy_adc_bug(struct mii_softc *);
    111      1.43   msaitoh static void	brgphy_5704_a0_bug(struct mii_softc *);
    112      1.43   msaitoh static void	brgphy_ber_bug(struct mii_softc *);
    113      1.43   msaitoh static void	brgphy_crc_bug(struct mii_softc *);
    114      1.58       jym static void	brgphy_disable_early_dac(struct mii_softc *);
    115      1.52   msaitoh static void	brgphy_jumbo_settings(struct mii_softc *);
    116      1.52   msaitoh static void	brgphy_eth_wirespeed(struct mii_softc *);
    117       1.1   thorpej 
    118      1.10   thorpej 
    119      1.21   thorpej static const struct mii_phy_funcs brgphy_funcs = {
    120      1.43   msaitoh 	brgphy_service, brgphy_status, brgphy_reset,
    121      1.34     markd };
    122      1.34     markd 
    123      1.21   thorpej static const struct mii_phydesc brgphys[] = {
    124       1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5400,
    125       1.1   thorpej 	  MII_STR_BROADCOM_BCM5400 },
    126       1.2   thorpej 
    127       1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5401,
    128       1.1   thorpej 	  MII_STR_BROADCOM_BCM5401 },
    129       1.2   thorpej 
    130       1.1   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5411,
    131       1.1   thorpej 	  MII_STR_BROADCOM_BCM5411 },
    132       1.9   thorpej 
    133       1.9   thorpej 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5421,
    134       1.9   thorpej 	  MII_STR_BROADCOM_BCM5421 },
    135       1.7      fvdl 
    136      1.53  kiyohara 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5462,
    137      1.53  kiyohara 	  MII_STR_BROADCOM_BCM5462 },
    138      1.43   msaitoh 
    139      1.52   msaitoh 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5461,
    140      1.52   msaitoh 	  MII_STR_BROADCOM_BCM5461 },
    141      1.49    simonb 
    142      1.53  kiyohara 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM54K2,
    143      1.53  kiyohara 	  MII_STR_BROADCOM_BCM54K2 },
    144      1.43   msaitoh 
    145      1.52   msaitoh 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5464,
    146      1.52   msaitoh 	  MII_STR_BROADCOM_BCM5464 },
    147      1.52   msaitoh 
    148       1.7      fvdl 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5701,
    149       1.7      fvdl 	  MII_STR_BROADCOM_BCM5701 },
    150      1.14      matt 
    151      1.14      matt 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5703,
    152      1.14      matt 	  MII_STR_BROADCOM_BCM5703 },
    153       1.1   thorpej 
    154      1.15  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5704,
    155      1.15  jonathan 	  MII_STR_BROADCOM_BCM5704 },
    156      1.15  jonathan 
    157      1.25  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5705,
    158      1.25  jonathan 	  MII_STR_BROADCOM_BCM5705 },
    159      1.25  jonathan 
    160      1.24  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5714,
    161      1.24  jonathan 	  MII_STR_BROADCOM_BCM5714 },
    162      1.18   hannken 
    163      1.22      cube 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5750,
    164      1.22      cube 	  MII_STR_BROADCOM_BCM5750 },
    165      1.22      cube 
    166      1.31   tsutsui 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5752,
    167      1.31   tsutsui 	  MII_STR_BROADCOM_BCM5752 },
    168      1.31   tsutsui 
    169      1.27  jonathan 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5780,
    170      1.27  jonathan 	  MII_STR_BROADCOM_BCM5780 },
    171      1.27  jonathan 
    172      1.36     markd 	{ MII_OUI_BROADCOM,		MII_MODEL_BROADCOM_BCM5708C,
    173      1.36     markd 	  MII_STR_BROADCOM_BCM5708C },
    174      1.36     markd 
    175      1.55  pgoyette 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5481,
    176      1.55  pgoyette 	  MII_STR_BROADCOM2_BCM5481 },
    177      1.55  pgoyette 
    178      1.53  kiyohara 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5482,
    179      1.53  kiyohara 	  MII_STR_BROADCOM2_BCM5482 },
    180      1.53  kiyohara 
    181      1.51    bouyer 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5709C,
    182      1.51    bouyer 	  MII_STR_BROADCOM2_BCM5709C },
    183      1.51    bouyer 
    184      1.57       jym 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5709S,
    185      1.57       jym 	  MII_STR_BROADCOM2_BCM5709S },
    186      1.57       jym 
    187      1.51    bouyer 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5709CAX,
    188      1.51    bouyer 	  MII_STR_BROADCOM2_BCM5709CAX },
    189      1.51    bouyer 
    190      1.43   msaitoh 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5722,
    191      1.43   msaitoh 	  MII_STR_BROADCOM2_BCM5722 },
    192      1.43   msaitoh 
    193      1.53  kiyohara 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5754,
    194      1.53  kiyohara 	  MII_STR_BROADCOM2_BCM5754 },
    195      1.53  kiyohara 
    196      1.34     markd 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5755,
    197      1.34     markd 	  MII_STR_BROADCOM2_BCM5755 },
    198      1.34     markd 
    199  1.59.8.2    bouyer 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5756,
    200  1.59.8.2    bouyer 	  MII_STR_BROADCOM2_BCM5756 },
    201  1.59.8.2    bouyer 
    202      1.52   msaitoh 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5761,
    203      1.52   msaitoh 	  MII_STR_BROADCOM2_BCM5761 },
    204      1.52   msaitoh 
    205      1.52   msaitoh 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5784,
    206      1.52   msaitoh 	  MII_STR_BROADCOM2_BCM5784 },
    207      1.52   msaitoh 
    208      1.59    cegger 	{ MII_OUI_BROADCOM2,		MII_MODEL_BROADCOM2_BCM5785,
    209      1.59    cegger 	  MII_STR_BROADCOM2_BCM5785 },
    210      1.59    cegger 
    211  1.59.8.2    bouyer 	{ MII_OUI_BROADCOM3,		MII_MODEL_BROADCOM3_BCM5717C,
    212  1.59.8.2    bouyer 	  MII_STR_BROADCOM3_BCM5717C },
    213  1.59.8.2    bouyer 
    214  1.59.8.2    bouyer 	{ MII_OUI_BROADCOM3,		MII_MODEL_BROADCOM3_BCM5719C,
    215  1.59.8.2    bouyer 	  MII_STR_BROADCOM3_BCM5719C },
    216  1.59.8.2    bouyer 
    217  1.59.8.2    bouyer 	{ MII_OUI_BROADCOM3,		MII_MODEL_BROADCOM3_BCM5720C,
    218  1.59.8.2    bouyer 	  MII_STR_BROADCOM3_BCM5720C },
    219  1.59.8.2    bouyer 
    220  1.59.8.1   msaitoh 	{ MII_OUI_BROADCOM3,		MII_MODEL_BROADCOM3_BCM57765,
    221  1.59.8.1   msaitoh 	  MII_STR_BROADCOM3_BCM57765 },
    222  1.59.8.1   msaitoh 
    223  1.59.8.2    bouyer 	{ MII_OUI_BROADCOM3,		MII_MODEL_BROADCOM3_BCM57780,
    224  1.59.8.2    bouyer 	  MII_STR_BROADCOM3_BCM57780 },
    225  1.59.8.2    bouyer 
    226      1.40    cegger 	{ MII_OUI_xxBROADCOM_ALT1,	MII_MODEL_xxBROADCOM_ALT1_BCM5906,
    227      1.40    cegger 	  MII_STR_xxBROADCOM_ALT1_BCM5906 },
    228      1.40    cegger 
    229       1.1   thorpej 	{ 0,				0,
    230       1.1   thorpej 	  NULL },
    231       1.1   thorpej };
    232       1.1   thorpej 
    233      1.21   thorpej static int
    234      1.48   tsutsui brgphymatch(device_t parent, cfdata_t match, void *aux)
    235       1.1   thorpej {
    236       1.1   thorpej 	struct mii_attach_args *ma = aux;
    237       1.1   thorpej 
    238       1.2   thorpej 	if (mii_phy_match(ma, brgphys) != NULL)
    239       1.1   thorpej 		return (10);
    240       1.1   thorpej 
    241       1.1   thorpej 	return (0);
    242       1.1   thorpej }
    243       1.1   thorpej 
    244      1.21   thorpej static void
    245      1.46    cegger brgphyattach(device_t parent, device_t self, void *aux)
    246       1.1   thorpej {
    247      1.44   msaitoh 	struct brgphy_softc *bsc = device_private(self);
    248      1.44   msaitoh 	struct mii_softc *sc = &bsc->sc_mii;
    249       1.1   thorpej 	struct mii_attach_args *ma = aux;
    250       1.1   thorpej 	struct mii_data *mii = ma->mii_data;
    251       1.2   thorpej 	const struct mii_phydesc *mpd;
    252      1.44   msaitoh 	prop_dictionary_t dict;
    253       1.1   thorpej 
    254       1.2   thorpej 	mpd = mii_phy_match(ma, brgphys);
    255      1.17   thorpej 	aprint_naive(": Media interface\n");
    256      1.17   thorpej 	aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
    257       1.1   thorpej 
    258      1.39   xtraeme 	sc->mii_dev = self;
    259       1.1   thorpej 	sc->mii_inst = mii->mii_instance;
    260       1.1   thorpej 	sc->mii_phy = ma->mii_phyno;
    261  1.59.8.2    bouyer 	sc->mii_mpd_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
    262      1.32   msaitoh 	sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
    263      1.43   msaitoh 	sc->mii_mpd_rev = MII_REV(ma->mii_id2);
    264       1.1   thorpej 	sc->mii_pdata = mii;
    265       1.6   thorpej 	sc->mii_flags = ma->mii_flags;
    266      1.30  christos 	sc->mii_anegticks = MII_ANEGTICKS;
    267      1.43   msaitoh 	sc->mii_funcs = &brgphy_funcs;
    268      1.10   thorpej 
    269      1.58       jym 	if (device_is_a(parent, "bge"))
    270      1.54    dyoung 		bsc->sc_isbge = true;
    271      1.58       jym 	else if (device_is_a(parent, "bnx"))
    272      1.54    dyoung 		bsc->sc_isbnx = true;
    273      1.58       jym 
    274      1.58       jym 	if (bsc->sc_isbge || bsc->sc_isbnx) {
    275      1.44   msaitoh 		dict = device_properties(parent);
    276      1.57       jym 		if (!prop_dictionary_get_uint32(dict, "phyflags",
    277      1.58       jym 		    &bsc->sc_phyflags))
    278      1.58       jym 			aprint_error_dev(self, "failed to get phyflags\n");
    279      1.58       jym 		if (!prop_dictionary_get_uint32(dict, "chipid",
    280      1.58       jym 		    &bsc->sc_chipid))
    281      1.58       jym 			aprint_error_dev(self, "failed to get chipid\n");
    282      1.44   msaitoh 	}
    283      1.57       jym 
    284  1.59.8.2    bouyer 	PHY_RESET(sc);
    285  1.59.8.2    bouyer 
    286  1.59.8.2    bouyer 	sc->mii_capabilities =
    287  1.59.8.2    bouyer 	    PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
    288  1.59.8.2    bouyer 	if (sc->mii_capabilities & BMSR_EXTSTAT)
    289  1.59.8.2    bouyer 		sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
    290  1.59.8.2    bouyer 
    291      1.57       jym 	aprint_normal_dev(self, "");
    292      1.57       jym 	if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
    293      1.57       jym 	    (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
    294      1.57       jym 		aprint_error("no media present");
    295      1.57       jym 	else {
    296      1.57       jym 		if (sc->mii_flags & MIIF_HAVEFIBER) {
    297      1.57       jym 			sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
    298      1.57       jym 
    299      1.57       jym 			/*
    300      1.57       jym 			 * Set the proper bits for capabilities so that the
    301      1.57       jym 			 * correct media get selected by mii_phy_add_media()
    302      1.57       jym 			 */
    303      1.57       jym 			sc->mii_capabilities |= BMSR_ANEG;
    304      1.57       jym 			sc->mii_capabilities &= ~BMSR_100T4;
    305      1.57       jym 			sc->mii_extcapabilities |= EXTSR_1000XFDX;
    306      1.57       jym 
    307      1.57       jym 			if (bsc->sc_isbnx) {
    308      1.57       jym 				/*
    309      1.57       jym 				 * 2.5Gb support is a software enabled feature
    310      1.57       jym 				 * on the BCM5708S and BCM5709S controllers.
    311      1.57       jym 				 */
    312      1.57       jym #define	ADD(m, c)	ifmedia_add(&mii->mii_media, (m), (c), NULL)
    313      1.58       jym 				if (bsc->sc_phyflags
    314      1.57       jym 				    & BNX_PHY_2_5G_CAPABLE_FLAG) {
    315      1.57       jym 					ADD(IFM_MAKEWORD(IFM_ETHER, IFM_2500_SX,
    316      1.57       jym 					    IFM_FDX, sc->mii_inst), 0);
    317      1.57       jym 					aprint_normal("2500baseSX-FDX, ");
    318      1.57       jym #undef ADD
    319      1.57       jym 				}
    320      1.57       jym 			}
    321      1.57       jym 		}
    322      1.57       jym 		mii_phy_add_media(sc);
    323      1.57       jym 	}
    324      1.57       jym 	aprint_normal("\n");
    325      1.57       jym 
    326       1.1   thorpej }
    327       1.1   thorpej 
    328      1.21   thorpej static int
    329       1.4   thorpej brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
    330       1.1   thorpej {
    331       1.1   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    332      1.32   msaitoh 	int reg, speed, gig;
    333       1.1   thorpej 
    334       1.1   thorpej 	switch (cmd) {
    335       1.1   thorpej 	case MII_POLLSTAT:
    336       1.1   thorpej 		/*
    337       1.1   thorpej 		 * If we're not polling our PHY instance, just return.
    338       1.1   thorpej 		 */
    339       1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    340       1.1   thorpej 			return (0);
    341       1.1   thorpej 		break;
    342       1.1   thorpej 
    343       1.1   thorpej 	case MII_MEDIACHG:
    344       1.1   thorpej 		/*
    345       1.1   thorpej 		 * If the media indicates a different PHY instance,
    346       1.1   thorpej 		 * isolate ourselves.
    347       1.1   thorpej 		 */
    348       1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
    349       1.1   thorpej 			reg = PHY_READ(sc, MII_BMCR);
    350       1.1   thorpej 			PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
    351       1.1   thorpej 			return (0);
    352       1.1   thorpej 		}
    353       1.1   thorpej 
    354       1.1   thorpej 		/*
    355       1.1   thorpej 		 * If the interface is not up, don't do anything.
    356       1.1   thorpej 		 */
    357       1.1   thorpej 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    358       1.1   thorpej 			break;
    359       1.1   thorpej 
    360      1.32   msaitoh 		PHY_RESET(sc); /* XXX hardware bug work-around */
    361      1.32   msaitoh 
    362      1.32   msaitoh 		switch (IFM_SUBTYPE(ife->ifm_media)) {
    363      1.32   msaitoh 		case IFM_AUTO:
    364      1.32   msaitoh 			(void) brgphy_mii_phy_auto(sc);
    365      1.32   msaitoh 			break;
    366      1.32   msaitoh 		case IFM_1000_T:
    367      1.32   msaitoh 			speed = BMCR_S1000;
    368      1.32   msaitoh 			goto setit;
    369      1.32   msaitoh 		case IFM_100_TX:
    370      1.32   msaitoh 			speed = BMCR_S100;
    371      1.32   msaitoh 			goto setit;
    372      1.32   msaitoh 		case IFM_10_T:
    373      1.32   msaitoh 			speed = BMCR_S10;
    374      1.32   msaitoh setit:
    375      1.32   msaitoh 			brgphy_loop(sc);
    376      1.32   msaitoh 			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
    377      1.32   msaitoh 				speed |= BMCR_FDX;
    378      1.32   msaitoh 				gig = GTCR_ADV_1000TFDX;
    379      1.32   msaitoh 			} else {
    380      1.32   msaitoh 				gig = GTCR_ADV_1000THDX;
    381      1.32   msaitoh 			}
    382      1.32   msaitoh 
    383      1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, 0);
    384      1.51    bouyer 			PHY_WRITE(sc, MII_ANAR, ANAR_CSMA);
    385      1.32   msaitoh 			PHY_WRITE(sc, MII_BMCR, speed);
    386      1.32   msaitoh 
    387      1.32   msaitoh 			if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
    388      1.32   msaitoh 				break;
    389      1.32   msaitoh 
    390      1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, gig);
    391      1.32   msaitoh 			PHY_WRITE(sc, MII_BMCR,
    392  1.59.8.2    bouyer 			    speed | BMCR_AUTOEN | BMCR_STARTNEG);
    393      1.32   msaitoh 
    394  1.59.8.2    bouyer 			if ((sc->mii_mpd_oui != MII_OUI_BROADCOM)
    395  1.59.8.2    bouyer 			    || (sc->mii_mpd_model != MII_MODEL_BROADCOM_BCM5701))
    396      1.33   msaitoh 				break;
    397      1.32   msaitoh 
    398      1.32   msaitoh 			if (mii->mii_media.ifm_media & IFM_ETH_MASTER)
    399      1.32   msaitoh 				gig |= GTCR_MAN_MS | GTCR_ADV_MS;
    400      1.32   msaitoh 			PHY_WRITE(sc, MII_100T2CR, gig);
    401      1.32   msaitoh 			break;
    402      1.32   msaitoh 		default:
    403      1.32   msaitoh 			return (EINVAL);
    404      1.32   msaitoh 		}
    405       1.1   thorpej 		break;
    406       1.1   thorpej 
    407       1.1   thorpej 	case MII_TICK:
    408       1.1   thorpej 		/*
    409       1.1   thorpej 		 * If we're not currently selected, just return.
    410       1.1   thorpej 		 */
    411       1.1   thorpej 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
    412       1.1   thorpej 			return (0);
    413       1.1   thorpej 
    414  1.59.8.2    bouyer 		/*
    415  1.59.8.2    bouyer 		 * Is the interface even up?
    416  1.59.8.2    bouyer 		 */
    417  1.59.8.2    bouyer 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
    418  1.59.8.2    bouyer 			return 0;
    419  1.59.8.2    bouyer 
    420  1.59.8.2    bouyer 		/*
    421  1.59.8.2    bouyer 		 * Only used for autonegotiation.
    422  1.59.8.2    bouyer 		 */
    423  1.59.8.2    bouyer 		if ((IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) &&
    424  1.59.8.2    bouyer 		    (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)) {
    425  1.59.8.2    bouyer 			sc->mii_ticks = 0;
    426  1.59.8.2    bouyer 			break;
    427  1.59.8.2    bouyer 		}
    428  1.59.8.2    bouyer 
    429  1.59.8.2    bouyer 		/*
    430  1.59.8.2    bouyer 		 * Check for link.
    431  1.59.8.2    bouyer 		 * Read the status register twice; BMSR_LINK is latch-low.
    432  1.59.8.2    bouyer 		 */
    433  1.59.8.2    bouyer 		reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
    434  1.59.8.2    bouyer 		if (reg & BMSR_LINK) {
    435  1.59.8.2    bouyer 			sc->mii_ticks = 0;
    436  1.59.8.2    bouyer 			break;
    437  1.59.8.2    bouyer 		}
    438  1.59.8.2    bouyer 
    439  1.59.8.2    bouyer 		/*
    440  1.59.8.2    bouyer 		 * mii_ticks == 0 means it's the first tick after changing the
    441  1.59.8.2    bouyer 		 * media or the link became down since the last tick
    442  1.59.8.2    bouyer 		 * (see above), so break to update the status.
    443  1.59.8.2    bouyer 		 */
    444  1.59.8.2    bouyer 		if (sc->mii_ticks++ == 0)
    445  1.59.8.2    bouyer 			break;
    446  1.59.8.2    bouyer 
    447  1.59.8.2    bouyer 		/*
    448  1.59.8.2    bouyer 		 * Only retry autonegotiation every mii_anegticks seconds.
    449  1.59.8.2    bouyer 		 */
    450  1.59.8.2    bouyer 		KASSERT(sc->mii_anegticks != 0);
    451  1.59.8.2    bouyer 		if (sc->mii_ticks <= sc->mii_anegticks)
    452  1.59.8.2    bouyer 			break;
    453  1.59.8.2    bouyer 
    454  1.59.8.2    bouyer 		brgphy_mii_phy_auto(sc);
    455       1.1   thorpej 		break;
    456       1.1   thorpej 
    457       1.1   thorpej 	case MII_DOWN:
    458       1.1   thorpej 		mii_phy_down(sc);
    459       1.1   thorpej 		return (0);
    460       1.1   thorpej 	}
    461       1.1   thorpej 
    462       1.1   thorpej 	/* Update the media status. */
    463       1.1   thorpej 	mii_phy_status(sc);
    464       1.1   thorpej 
    465      1.10   thorpej 	/*
    466      1.32   msaitoh 	 * Callback if something changed. Note that we need to poke the DSP on
    467      1.32   msaitoh 	 * the Broadcom PHYs if the media changes.
    468      1.10   thorpej 	 */
    469      1.23     perry 	if (sc->mii_media_active != mii->mii_media_active ||
    470      1.10   thorpej 	    sc->mii_media_status != mii->mii_media_status ||
    471      1.10   thorpej 	    cmd == MII_MEDIACHG) {
    472  1.59.8.2    bouyer 		switch (sc->mii_mpd_oui) {
    473  1.59.8.2    bouyer 		case MII_OUI_BROADCOM:
    474  1.59.8.2    bouyer 			switch (sc->mii_mpd_model) {
    475  1.59.8.2    bouyer 			case MII_MODEL_BROADCOM_BCM5400:
    476      1.43   msaitoh 				brgphy_bcm5401_dspcode(sc);
    477  1.59.8.2    bouyer 				break;
    478  1.59.8.2    bouyer 			case MII_MODEL_BROADCOM_BCM5401:
    479  1.59.8.2    bouyer 				if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
    480  1.59.8.2    bouyer 					brgphy_bcm5401_dspcode(sc);
    481  1.59.8.2    bouyer 				break;
    482  1.59.8.2    bouyer 			case MII_MODEL_BROADCOM_BCM5411:
    483  1.59.8.2    bouyer 				brgphy_bcm5411_dspcode(sc);
    484  1.59.8.2    bouyer 				break;
    485  1.59.8.2    bouyer 			}
    486      1.43   msaitoh 			break;
    487      1.43   msaitoh 		}
    488      1.10   thorpej 	}
    489      1.43   msaitoh 
    490      1.43   msaitoh 	/* Callback if something changed. */
    491      1.43   msaitoh 	mii_phy_update(sc, cmd);
    492       1.1   thorpej 	return (0);
    493       1.1   thorpej }
    494       1.1   thorpej 
    495      1.21   thorpej static void
    496       1.4   thorpej brgphy_status(struct mii_softc *sc)
    497       1.1   thorpej {
    498       1.1   thorpej 	struct mii_data *mii = sc->mii_pdata;
    499       1.1   thorpej 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
    500      1.57       jym 	int bmcr, bmsr, auxsts, gtsr;
    501       1.1   thorpej 
    502       1.1   thorpej 	mii->mii_media_status = IFM_AVALID;
    503       1.1   thorpej 	mii->mii_media_active = IFM_ETHER;
    504       1.1   thorpej 
    505      1.57       jym 	bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
    506      1.57       jym 	if (bmsr & BMSR_LINK)
    507       1.1   thorpej 		mii->mii_media_status |= IFM_ACTIVE;
    508       1.1   thorpej 
    509       1.1   thorpej 	bmcr = PHY_READ(sc, MII_BMCR);
    510       1.1   thorpej 	if (bmcr & BMCR_ISO) {
    511       1.1   thorpej 		mii->mii_media_active |= IFM_NONE;
    512       1.1   thorpej 		mii->mii_media_status = 0;
    513       1.1   thorpej 		return;
    514       1.1   thorpej 	}
    515       1.1   thorpej 
    516       1.1   thorpej 	if (bmcr & BMCR_LOOP)
    517       1.1   thorpej 		mii->mii_media_active |= IFM_LOOP;
    518       1.1   thorpej 
    519       1.1   thorpej 	if (bmcr & BMCR_AUTOEN) {
    520       1.1   thorpej 		/*
    521       1.1   thorpej 		 * The media status bits are only valid of autonegotiation
    522       1.1   thorpej 		 * has completed (or it's disabled).
    523       1.1   thorpej 		 */
    524      1.57       jym 		if ((bmsr & BMSR_ACOMP) == 0) {
    525       1.1   thorpej 			/* Erg, still trying, I guess... */
    526       1.1   thorpej 			mii->mii_media_active |= IFM_NONE;
    527       1.1   thorpej 			return;
    528       1.1   thorpej 		}
    529       1.1   thorpej 
    530  1.59.8.2    bouyer 		if ((sc->mii_mpd_oui == MII_OUI_BROADCOM2)
    531  1.59.8.2    bouyer 		    && (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5709S)) {
    532  1.59.8.2    bouyer 			/*
    533  1.59.8.2    bouyer 			 * 5709S has its own general purpose status registers
    534  1.59.8.2    bouyer 			 */
    535      1.57       jym 			PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    536      1.57       jym 			    BRGPHY_BLOCK_ADDR_GP_STATUS);
    537      1.57       jym 
    538      1.57       jym 			auxsts = PHY_READ(sc, BRGPHY_GP_STATUS_TOP_ANEG_STATUS);
    539      1.57       jym 
    540      1.57       jym 			PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    541      1.57       jym 			    BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
    542      1.57       jym 
    543      1.57       jym 			switch (auxsts & BRGPHY_GP_STATUS_TOP_ANEG_SPEED_MASK) {
    544      1.57       jym 			case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_10:
    545      1.57       jym 				mii->mii_media_active |= IFM_10_FL;
    546      1.57       jym 				break;
    547      1.57       jym 			case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_100:
    548      1.57       jym 				mii->mii_media_active |= IFM_100_FX;
    549      1.57       jym 				break;
    550      1.57       jym 			case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_1G:
    551      1.57       jym 				mii->mii_media_active |= IFM_1000_SX;
    552      1.57       jym 				break;
    553      1.57       jym 			case BRGPHY_GP_STATUS_TOP_ANEG_SPEED_25G:
    554      1.57       jym 				mii->mii_media_active |= IFM_2500_SX;
    555      1.57       jym 				break;
    556      1.57       jym 			default:
    557      1.57       jym 				mii->mii_media_active |= IFM_NONE;
    558      1.57       jym 				mii->mii_media_status = 0;
    559      1.57       jym 				break;
    560      1.57       jym 			}
    561      1.57       jym 
    562      1.57       jym 			if (auxsts & BRGPHY_GP_STATUS_TOP_ANEG_FDX)
    563      1.57       jym 				mii->mii_media_active |= IFM_FDX;
    564      1.57       jym 			else
    565      1.57       jym 				mii->mii_media_active |= IFM_HDX;
    566      1.57       jym 
    567      1.57       jym 		} else {
    568      1.57       jym 			auxsts = PHY_READ(sc, BRGPHY_MII_AUXSTS);
    569      1.57       jym 
    570      1.57       jym 			switch (auxsts & BRGPHY_AUXSTS_AN_RES) {
    571      1.57       jym 			case BRGPHY_RES_1000FD:
    572  1.59.8.2    bouyer 				mii->mii_media_active |= IFM_1000_T | IFM_FDX;
    573      1.57       jym 				gtsr = PHY_READ(sc, MII_100T2SR);
    574      1.57       jym 				if (gtsr & GTSR_MS_RES)
    575      1.57       jym 					mii->mii_media_active |= IFM_ETH_MASTER;
    576      1.57       jym 				break;
    577       1.1   thorpej 
    578      1.57       jym 			case BRGPHY_RES_1000HD:
    579      1.57       jym 				mii->mii_media_active |= IFM_1000_T;
    580      1.57       jym 				gtsr = PHY_READ(sc, MII_100T2SR);
    581      1.57       jym 				if (gtsr & GTSR_MS_RES)
    582      1.57       jym 					mii->mii_media_active |= IFM_ETH_MASTER;
    583      1.57       jym 				break;
    584       1.1   thorpej 
    585      1.57       jym 			case BRGPHY_RES_100FD:
    586  1.59.8.2    bouyer 				mii->mii_media_active |= IFM_100_TX | IFM_FDX;
    587      1.57       jym 				break;
    588       1.1   thorpej 
    589      1.57       jym 			case BRGPHY_RES_100T4:
    590      1.57       jym 				mii->mii_media_active |= IFM_100_T4;
    591      1.57       jym 				break;
    592       1.1   thorpej 
    593      1.57       jym 			case BRGPHY_RES_100HD:
    594      1.57       jym 				mii->mii_media_active |= IFM_100_TX;
    595      1.57       jym 				break;
    596       1.1   thorpej 
    597      1.57       jym 			case BRGPHY_RES_10FD:
    598  1.59.8.2    bouyer 				mii->mii_media_active |= IFM_10_T | IFM_FDX;
    599      1.57       jym 				break;
    600       1.1   thorpej 
    601      1.57       jym 			case BRGPHY_RES_10HD:
    602      1.57       jym 				mii->mii_media_active |= IFM_10_T;
    603      1.57       jym 				break;
    604       1.1   thorpej 
    605      1.57       jym 			default:
    606      1.57       jym 				mii->mii_media_active |= IFM_NONE;
    607      1.57       jym 				mii->mii_media_status = 0;
    608      1.57       jym 			}
    609       1.1   thorpej 		}
    610      1.57       jym 
    611      1.19   thorpej 		if (mii->mii_media_active & IFM_FDX)
    612      1.20   thorpej 			mii->mii_media_active |= mii_phy_flowstatus(sc);
    613      1.57       jym 
    614       1.1   thorpej 	} else
    615       1.1   thorpej 		mii->mii_media_active = ife->ifm_media;
    616      1.10   thorpej }
    617      1.10   thorpej 
    618      1.32   msaitoh int
    619      1.32   msaitoh brgphy_mii_phy_auto(struct mii_softc *sc)
    620      1.32   msaitoh {
    621      1.32   msaitoh 	int anar, ktcr = 0;
    622      1.32   msaitoh 
    623      1.32   msaitoh 	brgphy_loop(sc);
    624      1.32   msaitoh 	PHY_RESET(sc);
    625      1.57       jym 
    626  1.59.8.2    bouyer 	ktcr = GTCR_ADV_1000TFDX | GTCR_ADV_1000THDX;
    627  1.59.8.2    bouyer 	if ((sc->mii_mpd_oui == MII_OUI_BROADCOM)
    628  1.59.8.2    bouyer 	    && (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701))
    629  1.59.8.2    bouyer 		ktcr |= GTCR_MAN_MS | GTCR_ADV_MS;
    630      1.32   msaitoh 	PHY_WRITE(sc, MII_100T2CR, ktcr);
    631      1.32   msaitoh 	ktcr = PHY_READ(sc, MII_100T2CR);
    632      1.32   msaitoh 	DELAY(1000);
    633      1.32   msaitoh 
    634      1.57       jym 	if (sc->mii_flags & MIIF_HAVEFIBER) {
    635      1.57       jym 		anar = ANAR_X_FD | ANAR_X_HD;
    636      1.57       jym 		if (sc->mii_flags & MIIF_DOPAUSE)
    637      1.57       jym 			anar |= BRGPHY_SERDES_ANAR_BOTH_PAUSE;
    638      1.57       jym 	} else {
    639      1.57       jym 		anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
    640      1.57       jym 		if (sc->mii_flags & MIIF_DOPAUSE)
    641      1.57       jym 			anar |= ANAR_FC | ANAR_X_PAUSE_ASYM;
    642      1.57       jym 	}
    643      1.32   msaitoh 	PHY_WRITE(sc, MII_ANAR, anar);
    644      1.32   msaitoh 	DELAY(1000);
    645      1.57       jym 
    646      1.57       jym 	/* Start autonegotiation */
    647      1.32   msaitoh 	PHY_WRITE(sc, MII_BMCR,
    648      1.32   msaitoh 	    BMCR_AUTOEN | BMCR_STARTNEG);
    649      1.32   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00);
    650      1.32   msaitoh 
    651      1.32   msaitoh 	return (EJUSTRETURN);
    652      1.32   msaitoh }
    653      1.32   msaitoh 
    654      1.32   msaitoh void
    655      1.32   msaitoh brgphy_loop(struct mii_softc *sc)
    656      1.32   msaitoh {
    657      1.32   msaitoh 	u_int32_t bmsr;
    658      1.32   msaitoh 	int i;
    659      1.32   msaitoh 
    660      1.32   msaitoh 	PHY_WRITE(sc, MII_BMCR, BMCR_LOOP);
    661      1.33   msaitoh 	for (i = 0; i < 15000; i++) {
    662      1.32   msaitoh 		bmsr = PHY_READ(sc, MII_BMSR);
    663      1.32   msaitoh 		if (!(bmsr & BMSR_LINK))
    664      1.32   msaitoh 			break;
    665      1.32   msaitoh 		DELAY(10);
    666      1.32   msaitoh 	}
    667      1.32   msaitoh }
    668      1.32   msaitoh 
    669      1.21   thorpej static void
    670      1.43   msaitoh brgphy_reset(struct mii_softc *sc)
    671      1.10   thorpej {
    672      1.56       jym 	struct brgphy_softc *bsc = device_private(sc->mii_dev);
    673      1.10   thorpej 
    674      1.10   thorpej 	mii_phy_reset(sc);
    675  1.59.8.2    bouyer 	switch (sc->mii_mpd_oui) {
    676  1.59.8.2    bouyer 	case MII_OUI_BROADCOM:
    677  1.59.8.2    bouyer 		switch (sc->mii_mpd_model) {
    678  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM_BCM5400:
    679      1.43   msaitoh 			brgphy_bcm5401_dspcode(sc);
    680  1.59.8.2    bouyer 			break;
    681  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM_BCM5401:
    682  1.59.8.2    bouyer 			if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
    683  1.59.8.2    bouyer 				brgphy_bcm5401_dspcode(sc);
    684  1.59.8.2    bouyer 			break;
    685  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM_BCM5411:
    686  1.59.8.2    bouyer 			brgphy_bcm5411_dspcode(sc);
    687  1.59.8.2    bouyer 			break;
    688  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM_BCM5421:
    689  1.59.8.2    bouyer 			brgphy_bcm5421_dspcode(sc);
    690  1.59.8.2    bouyer 			break;
    691  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM_BCM54K2:
    692  1.59.8.2    bouyer 			brgphy_bcm54k2_dspcode(sc);
    693  1.59.8.2    bouyer 			break;
    694  1.59.8.2    bouyer 		}
    695      1.43   msaitoh 		break;
    696  1.59.8.2    bouyer 	case MII_OUI_BROADCOM3:
    697  1.59.8.2    bouyer 		switch (sc->mii_mpd_model) {
    698  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM3_BCM5717C:
    699  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM3_BCM5719C:
    700  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM3_BCM5720C:
    701  1.59.8.2    bouyer 		case MII_MODEL_BROADCOM3_BCM57765:
    702  1.59.8.2    bouyer 			return;
    703  1.59.8.2    bouyer 		}
    704      1.43   msaitoh 		break;
    705  1.59.8.2    bouyer 	default:
    706      1.43   msaitoh 		break;
    707      1.43   msaitoh 	}
    708      1.15  jonathan 
    709      1.43   msaitoh 	/* Handle any bge (NetXtreme/NetLink) workarounds. */
    710      1.54    dyoung 	if (bsc->sc_isbge) {
    711      1.43   msaitoh 		if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
    712      1.43   msaitoh 
    713      1.58       jym 			if (bsc->sc_phyflags & BGE_PHY_ADC_BUG)
    714      1.43   msaitoh 				brgphy_adc_bug(sc);
    715      1.58       jym 			if (bsc->sc_phyflags & BGE_PHY_5704_A0_BUG)
    716      1.43   msaitoh 				brgphy_5704_a0_bug(sc);
    717      1.58       jym 			if (bsc->sc_phyflags & BGE_PHY_BER_BUG)
    718      1.43   msaitoh 				brgphy_ber_bug(sc);
    719      1.58       jym 			else if (bsc->sc_phyflags & BGE_PHY_JITTER_BUG) {
    720      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0c00);
    721      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG,
    722      1.43   msaitoh 				    0x000a);
    723      1.43   msaitoh 
    724      1.58       jym 				if (bsc->sc_phyflags
    725      1.58       jym 				    & BGE_PHY_ADJUST_TRIM) {
    726      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
    727      1.43   msaitoh 					    0x110b);
    728      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_TEST1,
    729      1.43   msaitoh 					    BRGPHY_TEST1_TRIM_EN | 0x4);
    730      1.43   msaitoh 				} else {
    731      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
    732      1.43   msaitoh 					    0x010b);
    733      1.43   msaitoh 				}
    734      1.15  jonathan 
    735      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0400);
    736      1.43   msaitoh 			}
    737  1.59.8.3    bouyer 			if (bsc->sc_phyflags & BGEPHYF_CRC_BUG)
    738      1.43   msaitoh 				brgphy_crc_bug(sc);
    739      1.15  jonathan 
    740      1.43   msaitoh 			/* Set Jumbo frame settings in the PHY. */
    741  1.59.8.3    bouyer 			if (bsc->sc_phyflags & BGEPHYF_JUMBO_CAPABLE)
    742      1.43   msaitoh 				brgphy_jumbo_settings(sc);
    743      1.43   msaitoh 
    744      1.43   msaitoh 			/* Adjust output voltage */
    745  1.59.8.2    bouyer 			if ((sc->mii_mpd_oui == MII_OUI_BROADCOM2)
    746  1.59.8.2    bouyer 			    && (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5906))
    747      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_EPHY_PTEST, 0x12);
    748      1.43   msaitoh 
    749      1.43   msaitoh 			/* Enable Ethernet@Wirespeed */
    750  1.59.8.2    bouyer 			if (!(bsc->sc_phyflags & BGE_PHY_NO_WIRESPEED))
    751      1.43   msaitoh 				brgphy_eth_wirespeed(sc);
    752      1.43   msaitoh 
    753      1.52   msaitoh #if 0
    754      1.43   msaitoh 			/* Enable Link LED on Dell boxes */
    755  1.59.8.2    bouyer 			if (bsc->sc_phyflags & BGE_PHY_NO_3LED) {
    756      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
    757      1.43   msaitoh 				PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL)
    758      1.43   msaitoh 					& ~BRGPHY_PHY_EXTCTL_3_LED);
    759      1.43   msaitoh 			}
    760      1.43   msaitoh #endif
    761      1.43   msaitoh 		}
    762      1.57       jym 	/* Handle any bnx (NetXtreme II) workarounds. */
    763      1.57       jym 	} else if (bsc->sc_isbnx) {
    764      1.43   msaitoh #if 0 /* not yet */
    765  1.59.8.2    bouyer 		if ((sc->mii_mpd_oui == MII_OUI_BROADCOM2)
    766  1.59.8.2    bouyer 		    && sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5708S) {
    767      1.43   msaitoh 			/* Store autoneg capabilities/results in digital block (Page 0) */
    768      1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG3_PG2);
    769      1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG2_DIGCTL_3_0,
    770      1.43   msaitoh 				BRGPHY_5708S_PG2_DIGCTL_3_0_USE_IEEE);
    771      1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG_PG0);
    772      1.43   msaitoh 
    773      1.43   msaitoh 			/* Enable fiber mode and autodetection */
    774      1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL1,
    775      1.43   msaitoh 				PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL1) |
    776      1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL1_AUTODET_EN |
    777      1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL1_FIBER_MODE);
    778      1.43   msaitoh 
    779      1.43   msaitoh 			/* Enable parallel detection */
    780      1.43   msaitoh 			PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL2,
    781      1.43   msaitoh 				PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL2) |
    782      1.43   msaitoh 				BRGPHY_5708S_PG0_1000X_CTL2_PAR_DET_EN);
    783      1.43   msaitoh 
    784      1.43   msaitoh 			/* Advertise 2.5G support through next page during autoneg */
    785      1.43   msaitoh 			if (bnx_sc->bnx_phy_flags & BNX_PHY_2_5G_CAPABLE_FLAG)
    786      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1,
    787      1.43   msaitoh 					PHY_READ(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1) |
    788      1.43   msaitoh 					BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
    789      1.43   msaitoh 
    790      1.43   msaitoh 			/* Increase TX signal amplitude */
    791      1.43   msaitoh 			if ((BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_A0) ||
    792      1.43   msaitoh 			    (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B0) ||
    793      1.43   msaitoh 			    (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B1)) {
    794      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    795      1.43   msaitoh 					BRGPHY_5708S_TX_MISC_PG5);
    796      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL1,
    797      1.43   msaitoh 					PHY_READ(sc, BRGPHY_5708S_PG5_TXACTL1) &
    798      1.43   msaitoh 					~BRGPHY_5708S_PG5_TXACTL1_VCM);
    799      1.43   msaitoh 				PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    800      1.43   msaitoh 					BRGPHY_5708S_DIG_PG0);
    801      1.43   msaitoh 			}
    802      1.15  jonathan 
    803      1.43   msaitoh 			/* Backplanes use special driver/pre-driver/pre-emphasis values. */
    804      1.43   msaitoh 			if ((bnx_sc->bnx_shared_hw_cfg & BNX_SHARED_HW_CFG_PHY_BACKPLANE) &&
    805      1.43   msaitoh 			    (bnx_sc->bnx_port_hw_cfg & BNX_PORT_HW_CFG_CFG_TXCTL3_MASK)) {
    806      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    807      1.43   msaitoh 						BRGPHY_5708S_TX_MISC_PG5);
    808      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL3,
    809      1.43   msaitoh 						bnx_sc->bnx_port_hw_cfg &
    810      1.43   msaitoh 						BNX_PORT_HW_CFG_CFG_TXCTL3_MASK);
    811      1.43   msaitoh 					PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
    812      1.43   msaitoh 						BRGPHY_5708S_DIG_PG0);
    813      1.43   msaitoh 			}
    814      1.57       jym 		} else
    815      1.57       jym #endif
    816  1.59.8.2    bouyer 		if ((sc->mii_mpd_oui == MII_OUI_BROADCOM2)
    817  1.59.8.2    bouyer 		    && (sc->mii_mpd_model ==  MII_MODEL_BROADCOM2_BCM5709S)) {
    818      1.57       jym 			/* Select the SerDes Digital block of the AN MMD. */
    819      1.57       jym 			PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    820      1.57       jym 			    BRGPHY_BLOCK_ADDR_SERDES_DIG);
    821      1.57       jym 
    822      1.57       jym 			PHY_WRITE(sc, BRGPHY_SERDES_DIG_1000X_CTL1,
    823      1.57       jym 			    (PHY_READ(sc, BRGPHY_SERDES_DIG_1000X_CTL1) &
    824      1.57       jym 			    ~BRGPHY_SD_DIG_1000X_CTL1_AUTODET) |
    825      1.57       jym 			    BRGPHY_SD_DIG_1000X_CTL1_FIBER);
    826      1.57       jym 
    827      1.58       jym 			if (bsc->sc_phyflags & BNX_PHY_2_5G_CAPABLE_FLAG) {
    828      1.57       jym 				/* Select the Over 1G block of the AN MMD. */
    829      1.57       jym 				PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    830      1.57       jym 				    BRGPHY_BLOCK_ADDR_OVER_1G);
    831      1.57       jym 
    832      1.57       jym 				/*
    833      1.57       jym 				 * Enable autoneg "Next Page" to advertise
    834      1.57       jym 				 * 2.5G support.
    835      1.57       jym 				 */
    836      1.57       jym 				PHY_WRITE(sc, BRGPHY_OVER_1G_UNFORMAT_PG1,
    837      1.57       jym 				    PHY_READ(sc, BRGPHY_OVER_1G_UNFORMAT_PG1) |
    838      1.57       jym 				    BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
    839      1.57       jym 			}
    840      1.57       jym 
    841      1.57       jym                         /*
    842      1.57       jym                          * Select the Multi-Rate Backplane Ethernet block of
    843      1.57       jym                          * the AN MMD.
    844      1.57       jym                          */
    845      1.57       jym                         PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    846      1.57       jym                             BRGPHY_BLOCK_ADDR_MRBE);
    847      1.57       jym 
    848      1.57       jym                         /* Enable MRBE speed autoneg. */
    849      1.57       jym                         PHY_WRITE(sc, BRGPHY_MRBE_MSG_PG5_NP,
    850      1.57       jym                             PHY_READ(sc, BRGPHY_MRBE_MSG_PG5_NP) |
    851      1.57       jym                             BRGPHY_MRBE_MSG_PG5_NP_MBRE |
    852      1.57       jym                             BRGPHY_MRBE_MSG_PG5_NP_T2);
    853      1.57       jym 
    854      1.57       jym                         /* Select the Clause 73 User B0 block of the AN MMD. */
    855      1.57       jym                         PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    856      1.57       jym                             BRGPHY_BLOCK_ADDR_CL73_USER_B0);
    857      1.57       jym 
    858      1.57       jym                         /* Enable MRBE speed autoneg. */
    859      1.57       jym                         PHY_WRITE(sc, BRGPHY_CL73_USER_B0_MBRE_CTL1,
    860      1.57       jym                             BRGPHY_CL73_USER_B0_MBRE_CTL1_NP_AFT_BP |
    861      1.57       jym                             BRGPHY_CL73_USER_B0_MBRE_CTL1_STA_MGR |
    862      1.57       jym                             BRGPHY_CL73_USER_B0_MBRE_CTL1_ANEG);
    863      1.57       jym 
    864      1.57       jym                         PHY_WRITE(sc, BRGPHY_BLOCK_ADDR,
    865      1.57       jym                             BRGPHY_BLOCK_ADDR_COMBO_IEEE0);
    866      1.57       jym 
    867      1.58       jym 		} else if (_BNX_CHIP_NUM(bsc->sc_chipid) == BNX_CHIP_NUM_5709) {
    868      1.58       jym 			if (_BNX_CHIP_REV(bsc->sc_chipid) == BNX_CHIP_REV_Ax ||
    869      1.58       jym 			    _BNX_CHIP_REV(bsc->sc_chipid) == BNX_CHIP_REV_Bx)
    870      1.58       jym 				brgphy_disable_early_dac(sc);
    871      1.58       jym 
    872      1.58       jym 			/* Set Jumbo frame settings in the PHY. */
    873      1.58       jym 			brgphy_jumbo_settings(sc);
    874      1.58       jym 
    875      1.58       jym 			/* Enable Ethernet@Wirespeed */
    876      1.58       jym 			brgphy_eth_wirespeed(sc);
    877      1.43   msaitoh 		} else {
    878      1.43   msaitoh 			if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
    879      1.43   msaitoh 				brgphy_ber_bug(sc);
    880      1.18   hannken 
    881      1.43   msaitoh 				/* Set Jumbo frame settings in the PHY. */
    882      1.43   msaitoh 				brgphy_jumbo_settings(sc);
    883      1.18   hannken 
    884      1.43   msaitoh 				/* Enable Ethernet@Wirespeed */
    885      1.43   msaitoh 				brgphy_eth_wirespeed(sc);
    886      1.43   msaitoh 			}
    887      1.43   msaitoh 		}
    888      1.43   msaitoh 	}
    889      1.34     markd }
    890      1.34     markd 
    891      1.16  jonathan /* Turn off tap power management on 5401. */
    892      1.10   thorpej static void
    893      1.43   msaitoh brgphy_bcm5401_dspcode(struct mii_softc *sc)
    894      1.10   thorpej {
    895      1.10   thorpej 	static const struct {
    896      1.10   thorpej 		int		reg;
    897      1.10   thorpej 		uint16_t	val;
    898      1.10   thorpej 	} dspcode[] = {
    899      1.16  jonathan 		{ BRGPHY_MII_AUXCTL,		0x0c20 },
    900      1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0012 },
    901      1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x1804 },
    902      1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0013 },
    903      1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x1204 },
    904      1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x8006 },
    905      1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0132 },
    906      1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x8006 },
    907      1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0232 },
    908      1.10   thorpej 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
    909      1.10   thorpej 		{ BRGPHY_MII_DSP_RW_PORT,	0x0a20 },
    910      1.10   thorpej 		{ 0,				0 },
    911      1.10   thorpej 	};
    912      1.10   thorpej 	int i;
    913      1.10   thorpej 
    914      1.10   thorpej 	for (i = 0; dspcode[i].reg != 0; i++)
    915      1.10   thorpej 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    916  1.59.8.2    bouyer 	delay(40);
    917      1.10   thorpej }
    918      1.10   thorpej 
    919      1.10   thorpej static void
    920      1.43   msaitoh brgphy_bcm5411_dspcode(struct mii_softc *sc)
    921      1.10   thorpej {
    922      1.10   thorpej 	static const struct {
    923      1.10   thorpej 		int		reg;
    924      1.10   thorpej 		uint16_t	val;
    925      1.10   thorpej 	} dspcode[] = {
    926      1.10   thorpej 		{ 0x1c,				0x8c23 },
    927      1.10   thorpej 		{ 0x1c,				0x8ca3 },
    928      1.10   thorpej 		{ 0x1c,				0x8c23 },
    929      1.15  jonathan 		{ 0,				0 },
    930      1.15  jonathan 	};
    931      1.15  jonathan 	int i;
    932      1.15  jonathan 
    933      1.15  jonathan 	for (i = 0; dspcode[i].reg != 0; i++)
    934      1.15  jonathan 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    935      1.15  jonathan }
    936      1.15  jonathan 
    937      1.43   msaitoh void
    938      1.43   msaitoh brgphy_bcm5421_dspcode(struct mii_softc *sc)
    939      1.43   msaitoh {
    940      1.43   msaitoh 	uint16_t data;
    941      1.43   msaitoh 
    942      1.43   msaitoh 	/* Set Class A mode */
    943      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x1007);
    944      1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
    945      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0400);
    946      1.43   msaitoh 
    947      1.43   msaitoh 	/* Set FFE gamma override to -0.125 */
    948      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0007);
    949      1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
    950      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0800);
    951      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x000a);
    952      1.43   msaitoh 	data = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
    953      1.43   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, data | 0x0200);
    954      1.43   msaitoh }
    955      1.43   msaitoh 
    956      1.43   msaitoh void
    957      1.43   msaitoh brgphy_bcm54k2_dspcode(struct mii_softc *sc)
    958      1.43   msaitoh {
    959      1.43   msaitoh 	static const struct {
    960      1.43   msaitoh 		int		reg;
    961      1.43   msaitoh 		uint16_t	val;
    962      1.43   msaitoh 	} dspcode[] = {
    963      1.43   msaitoh 		{ 4,				0x01e1 },
    964      1.43   msaitoh 		{ 9,				0x0300 },
    965      1.43   msaitoh 		{ 0,				0 },
    966      1.43   msaitoh 	};
    967      1.43   msaitoh 	int i;
    968      1.43   msaitoh 
    969      1.43   msaitoh 	for (i = 0; dspcode[i].reg != 0; i++)
    970      1.43   msaitoh 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    971      1.43   msaitoh }
    972      1.43   msaitoh 
    973      1.15  jonathan static void
    974      1.43   msaitoh brgphy_adc_bug(struct mii_softc *sc)
    975      1.15  jonathan {
    976      1.15  jonathan 	static const struct {
    977      1.15  jonathan 		int		reg;
    978      1.15  jonathan 		uint16_t	val;
    979      1.15  jonathan 	} dspcode[] = {
    980      1.15  jonathan 		{ BRGPHY_MII_AUXCTL,		0x0c00 },
    981      1.15  jonathan 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
    982      1.15  jonathan 		{ BRGPHY_MII_DSP_RW_PORT,	0x2aaa },
    983      1.43   msaitoh 		{ BRGPHY_MII_DSP_ADDR_REG,	0x000a },
    984      1.43   msaitoh 		{ BRGPHY_MII_DSP_RW_PORT,	0x0323 },
    985      1.43   msaitoh 		{ BRGPHY_MII_AUXCTL,		0x0400 },
    986      1.15  jonathan 		{ 0,				0 },
    987      1.15  jonathan 	};
    988      1.15  jonathan 	int i;
    989      1.15  jonathan 
    990      1.15  jonathan 	for (i = 0; dspcode[i].reg != 0; i++)
    991      1.15  jonathan 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
    992      1.15  jonathan }
    993      1.15  jonathan 
    994      1.15  jonathan static void
    995      1.43   msaitoh brgphy_5704_a0_bug(struct mii_softc *sc)
    996      1.15  jonathan {
    997      1.15  jonathan 	static const struct {
    998      1.15  jonathan 		int		reg;
    999      1.15  jonathan 		uint16_t	val;
   1000      1.15  jonathan 	} dspcode[] = {
   1001      1.15  jonathan 		{ 0x1c,				0x8d68 },
   1002      1.33   msaitoh 		{ 0x1c,				0x8d68 },
   1003      1.10   thorpej 		{ 0,				0 },
   1004      1.10   thorpej 	};
   1005      1.10   thorpej 	int i;
   1006      1.10   thorpej 
   1007      1.10   thorpej 	for (i = 0; dspcode[i].reg != 0; i++)
   1008      1.10   thorpej 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
   1009       1.1   thorpej }
   1010      1.22      cube 
   1011      1.22      cube static void
   1012      1.43   msaitoh brgphy_ber_bug(struct mii_softc *sc)
   1013      1.22      cube {
   1014      1.22      cube 	static const struct {
   1015      1.22      cube 		int		reg;
   1016      1.22      cube 		uint16_t	val;
   1017      1.22      cube 	} dspcode[] = {
   1018      1.22      cube 		{ BRGPHY_MII_AUXCTL,		0x0c00 },
   1019      1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x000a },
   1020      1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x310b },
   1021      1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x201f },
   1022      1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x9506 },
   1023      1.22      cube 		{ BRGPHY_MII_DSP_ADDR_REG,	0x401f },
   1024      1.22      cube 		{ BRGPHY_MII_DSP_RW_PORT,	0x14e2 },
   1025      1.22      cube 		{ BRGPHY_MII_AUXCTL,		0x0400 },
   1026      1.22      cube 		{ 0,				0 },
   1027      1.22      cube 	};
   1028      1.22      cube 	int i;
   1029      1.22      cube 
   1030      1.22      cube 	for (i = 0; dspcode[i].reg != 0; i++)
   1031      1.22      cube 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
   1032      1.22      cube }
   1033      1.34     markd 
   1034      1.43   msaitoh /* BCM5701 A0/B0 CRC bug workaround */
   1035      1.43   msaitoh void
   1036      1.43   msaitoh brgphy_crc_bug(struct mii_softc *sc)
   1037      1.34     markd {
   1038      1.34     markd 	static const struct {
   1039      1.34     markd 		int		reg;
   1040      1.34     markd 		uint16_t	val;
   1041      1.34     markd 	} dspcode[] = {
   1042      1.43   msaitoh 		{ BRGPHY_MII_DSP_ADDR_REG,	0x0a75 },
   1043      1.43   msaitoh 		{ 0x1c,				0x8c68 },
   1044      1.43   msaitoh 		{ 0x1c,				0x8d68 },
   1045      1.43   msaitoh 		{ 0x1c,				0x8c68 },
   1046      1.34     markd 		{ 0,				0 },
   1047      1.34     markd 	};
   1048      1.34     markd 	int i;
   1049      1.34     markd 
   1050      1.34     markd 	for (i = 0; dspcode[i].reg != 0; i++)
   1051      1.34     markd 		PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
   1052      1.34     markd }
   1053      1.52   msaitoh 
   1054      1.52   msaitoh static void
   1055      1.58       jym brgphy_disable_early_dac(struct mii_softc *sc)
   1056      1.58       jym {
   1057      1.58       jym 	uint32_t val;
   1058      1.58       jym 
   1059      1.58       jym 	PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x0f08);
   1060      1.58       jym 	val = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
   1061      1.58       jym 	val &= ~(1 << 8);
   1062      1.58       jym 	PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, val);
   1063      1.58       jym 
   1064      1.58       jym }
   1065      1.58       jym 
   1066      1.58       jym static void
   1067      1.52   msaitoh brgphy_jumbo_settings(struct mii_softc *sc)
   1068      1.52   msaitoh {
   1069      1.52   msaitoh 	u_int32_t val;
   1070      1.52   msaitoh 
   1071      1.52   msaitoh 	/* Set Jumbo frame settings in the PHY. */
   1072  1.59.8.2    bouyer 	if ((sc->mii_mpd_oui == MII_OUI_BROADCOM)
   1073  1.59.8.2    bouyer 	    && (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5401)) {
   1074      1.52   msaitoh 		/* Cannot do read-modify-write on the BCM5401 */
   1075      1.52   msaitoh 		PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x4c20);
   1076      1.52   msaitoh 	} else {
   1077      1.52   msaitoh 		PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7);
   1078      1.52   msaitoh 		val = PHY_READ(sc, BRGPHY_MII_AUXCTL);
   1079      1.52   msaitoh 		PHY_WRITE(sc, BRGPHY_MII_AUXCTL,
   1080      1.52   msaitoh 			val & ~(BRGPHY_AUXCTL_LONG_PKT | 0x7));
   1081      1.52   msaitoh 	}
   1082      1.52   msaitoh 
   1083      1.52   msaitoh 	val = PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL);
   1084      1.52   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
   1085      1.52   msaitoh 		val & ~BRGPHY_PHY_EXTCTL_HIGH_LA);
   1086      1.52   msaitoh }
   1087      1.52   msaitoh 
   1088      1.52   msaitoh static void
   1089      1.52   msaitoh brgphy_eth_wirespeed(struct mii_softc *sc)
   1090      1.52   msaitoh {
   1091      1.52   msaitoh 	u_int32_t val;
   1092      1.52   msaitoh 
   1093      1.52   msaitoh 	/* Enable Ethernet@Wirespeed */
   1094      1.52   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7007);
   1095      1.52   msaitoh 	val = PHY_READ(sc, BRGPHY_MII_AUXCTL);
   1096      1.52   msaitoh 	PHY_WRITE(sc, BRGPHY_MII_AUXCTL,
   1097      1.52   msaitoh 		(val | (1 << 15) | (1 << 4)));
   1098      1.52   msaitoh }
   1099