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