xref: /freebsd/sys/dev/dc/dcphy.c (revision d7a9ad568858194afc4cc81ba5df5c9ae3b88845)
1098ca2bdSWarner Losh /*-
296f2e892SBill Paul  * Copyright (c) 1997, 1998, 1999
396f2e892SBill Paul  *	Bill Paul <wpaul@ee.columbia.edu>.  All rights reserved.
496f2e892SBill Paul  *
596f2e892SBill Paul  * Redistribution and use in source and binary forms, with or without
696f2e892SBill Paul  * modification, are permitted provided that the following conditions
796f2e892SBill Paul  * are met:
896f2e892SBill Paul  * 1. Redistributions of source code must retain the above copyright
996f2e892SBill Paul  *    notice, this list of conditions and the following disclaimer.
1096f2e892SBill Paul  * 2. Redistributions in binary form must reproduce the above copyright
1196f2e892SBill Paul  *    notice, this list of conditions and the following disclaimer in the
1296f2e892SBill Paul  *    documentation and/or other materials provided with the distribution.
1396f2e892SBill Paul  * 3. All advertising materials mentioning features or use of this software
1496f2e892SBill Paul  *    must display the following acknowledgement:
1596f2e892SBill Paul  *	This product includes software developed by Bill Paul.
1696f2e892SBill Paul  * 4. Neither the name of the author nor the names of any co-contributors
1796f2e892SBill Paul  *    may be used to endorse or promote products derived from this software
1896f2e892SBill Paul  *    without specific prior written permission.
1996f2e892SBill Paul  *
2096f2e892SBill Paul  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2196f2e892SBill Paul  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2296f2e892SBill Paul  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2396f2e892SBill Paul  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2496f2e892SBill Paul  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2596f2e892SBill Paul  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2696f2e892SBill Paul  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2796f2e892SBill Paul  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2896f2e892SBill Paul  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2996f2e892SBill Paul  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3096f2e892SBill Paul  * THE POSSIBILITY OF SUCH DAMAGE.
3196f2e892SBill Paul  */
3296f2e892SBill Paul 
33aad970f1SDavid E. O'Brien #include <sys/cdefs.h>
34aad970f1SDavid E. O'Brien __FBSDID("$FreeBSD$");
35aad970f1SDavid E. O'Brien 
3696f2e892SBill Paul /*
3796f2e892SBill Paul  * Pseudo-driver for internal NWAY support on DEC 21143 and workalike
3896f2e892SBill Paul  * controllers.  Technically we're abusing the miibus code to handle
3996f2e892SBill Paul  * media selection and NWAY support here since there is no MII
4096f2e892SBill Paul  * interface.  However the logical operations are roughly the same,
4196f2e892SBill Paul  * and the alternative is to create a fake MII interface in the driver,
4296f2e892SBill Paul  * which is harder to do.
4396f2e892SBill Paul  */
4496f2e892SBill Paul 
4596f2e892SBill Paul #include <sys/param.h>
4696f2e892SBill Paul #include <sys/systm.h>
4796f2e892SBill Paul #include <sys/kernel.h>
4896f2e892SBill Paul #include <sys/socket.h>
4996f2e892SBill Paul #include <sys/errno.h>
50f34fa851SJohn Baldwin #include <sys/lock.h>
5196f2e892SBill Paul #include <sys/module.h>
5235e0e5b3SJohn Baldwin #include <sys/mutex.h>
5396f2e892SBill Paul #include <sys/bus.h>
5496f2e892SBill Paul 
5596f2e892SBill Paul #include <net/if.h>
5696f2e892SBill Paul #include <net/if_arp.h>
5796f2e892SBill Paul #include <net/if_media.h>
5896f2e892SBill Paul 
5996f2e892SBill Paul #include <dev/mii/mii.h>
6096f2e892SBill Paul #include <dev/mii/miivar.h>
612d3ce713SDavid E. O'Brien #include "miidevs.h"
6296f2e892SBill Paul 
6396f2e892SBill Paul #include <machine/bus.h>
6496f2e892SBill Paul #include <machine/resource.h>
6596f2e892SBill Paul #include <sys/bus.h>
6696f2e892SBill Paul 
6738d8c994SWarner Losh #include <dev/pci/pcivar.h>
6896f2e892SBill Paul 
696a3033a8SWarner Losh #include <dev/dc/if_dcreg.h>
7096f2e892SBill Paul 
7196f2e892SBill Paul #include "miibus_if.h"
7296f2e892SBill Paul 
7396f2e892SBill Paul #define DC_SETBIT(sc, reg, x)                           \
7496f2e892SBill Paul         CSR_WRITE_4(sc, reg,                            \
7596f2e892SBill Paul                 CSR_READ_4(sc, reg) | x)
7696f2e892SBill Paul 
7796f2e892SBill Paul #define DC_CLRBIT(sc, reg, x)                           \
7896f2e892SBill Paul         CSR_WRITE_4(sc, reg,                            \
7996f2e892SBill Paul                 CSR_READ_4(sc, reg) & ~x)
8096f2e892SBill Paul 
8196f2e892SBill Paul #define MIIF_AUTOTIMEOUT	0x0004
8296f2e892SBill Paul 
8391cc2adbSBill Paul /*
8491cc2adbSBill Paul  * This is the subsystem ID for the built-in 21143 ethernet
8591cc2adbSBill Paul  * in several Compaq Presario systems.  Apparently these are
8691cc2adbSBill Paul  * 10Mbps only, so we need to treat them specially.
8791cc2adbSBill Paul  */
8891cc2adbSBill Paul #define COMPAQ_PRESARIO_ID	0xb0bb0e11
8991cc2adbSBill Paul 
90e51a25f8SAlfred Perlstein static int dcphy_probe(device_t);
91e51a25f8SAlfred Perlstein static int dcphy_attach(device_t);
9296f2e892SBill Paul 
9396f2e892SBill Paul static device_method_t dcphy_methods[] = {
9496f2e892SBill Paul 	/* device interface */
9596f2e892SBill Paul 	DEVMETHOD(device_probe,		dcphy_probe),
9696f2e892SBill Paul 	DEVMETHOD(device_attach,	dcphy_attach),
97279fe8d1SPoul-Henning Kamp 	DEVMETHOD(device_detach,	mii_phy_detach),
9896f2e892SBill Paul 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
9996f2e892SBill Paul 	{ 0, 0 }
10096f2e892SBill Paul };
10196f2e892SBill Paul 
10296f2e892SBill Paul static devclass_t dcphy_devclass;
10396f2e892SBill Paul 
10496f2e892SBill Paul static driver_t dcphy_driver = {
10596f2e892SBill Paul 	"dcphy",
10696f2e892SBill Paul 	dcphy_methods,
10796f2e892SBill Paul 	sizeof(struct mii_softc)
10896f2e892SBill Paul };
10996f2e892SBill Paul 
11096f2e892SBill Paul DRIVER_MODULE(dcphy, miibus, dcphy_driver, dcphy_devclass, 0, 0);
11196f2e892SBill Paul 
112e51a25f8SAlfred Perlstein static int	dcphy_service(struct mii_softc *, struct mii_data *, int);
113e51a25f8SAlfred Perlstein static void	dcphy_status(struct mii_softc *);
114e51a25f8SAlfred Perlstein static void	dcphy_reset(struct mii_softc *);
115fd94424cSPoul-Henning Kamp static int	dcphy_auto(struct mii_softc *);
11696f2e892SBill Paul 
1179c1c2e99SAlfred Perlstein static int
1187d830ac9SWarner Losh dcphy_probe(device_t dev)
11996f2e892SBill Paul {
12096f2e892SBill Paul 	struct mii_attach_args *ma;
12196f2e892SBill Paul 
12296f2e892SBill Paul 	ma = device_get_ivars(dev);
12396f2e892SBill Paul 
12496f2e892SBill Paul 	/*
12596f2e892SBill Paul 	 * The dc driver will report the 21143 vendor and device
12696f2e892SBill Paul 	 * ID to let us know that it wants us to attach.
12796f2e892SBill Paul 	 */
12896f2e892SBill Paul 	if (ma->mii_id1 != DC_VENDORID_DEC ||
12996f2e892SBill Paul 	    ma->mii_id2 != DC_DEVICEID_21143)
13096f2e892SBill Paul 		return (ENXIO);
13196f2e892SBill Paul 
13296f2e892SBill Paul 	device_set_desc(dev, "Intel 21143 NWAY media interface");
13396f2e892SBill Paul 
13407c4a8dfSPyun YongHyeon 	return (BUS_PROBE_DEFAULT);
13596f2e892SBill Paul }
13696f2e892SBill Paul 
1379c1c2e99SAlfred Perlstein static int
1387d830ac9SWarner Losh dcphy_attach(device_t dev)
13996f2e892SBill Paul {
14096f2e892SBill Paul 	struct mii_softc *sc;
14196f2e892SBill Paul 	struct mii_attach_args *ma;
14296f2e892SBill Paul 	struct mii_data *mii;
14396f2e892SBill Paul 	struct dc_softc		*dc_sc;
14434482399SJohn Baldwin 	device_t brdev;
14596f2e892SBill Paul 
14696f2e892SBill Paul 	sc = device_get_softc(dev);
14796f2e892SBill Paul 	ma = device_get_ivars(dev);
14896f2e892SBill Paul 	sc->mii_dev = device_get_parent(dev);
1497b9a15f7SMarius Strobl 	mii = ma->mii_data;
15096f2e892SBill Paul 	LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
15196f2e892SBill Paul 
152de1add1eSMarius Strobl 	sc->mii_inst = mii->mii_instance++;
15396f2e892SBill Paul 	sc->mii_phy = ma->mii_phyno;
15496f2e892SBill Paul 	sc->mii_service = dcphy_service;
15596f2e892SBill Paul 	sc->mii_pdata = mii;
15696f2e892SBill Paul 
157b54282f6SMarius Strobl 	/*
158b54282f6SMarius Strobl 	 * Apparently, we can neither isolate nor do loopback.
159b54282f6SMarius Strobl 	 */
160b54282f6SMarius Strobl 	sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
161b54282f6SMarius Strobl 
16296f2e892SBill Paul 	/*dcphy_reset(sc);*/
16396f2e892SBill Paul 	dc_sc = mii->mii_ifp->if_softc;
16496f2e892SBill Paul 	CSR_WRITE_4(dc_sc, DC_10BTSTAT, 0);
16596f2e892SBill Paul 	CSR_WRITE_4(dc_sc, DC_10BTCTRL, 0);
16696f2e892SBill Paul 
16734482399SJohn Baldwin 	brdev = device_get_parent(sc->mii_dev);
16834482399SJohn Baldwin 	switch (pci_get_subdevice(brdev) << 16 | pci_get_subvendor(brdev)) {
16991cc2adbSBill Paul 	case COMPAQ_PRESARIO_ID:
17096f2e892SBill Paul 		/* Example of how to only allow 10Mbps modes. */
17191cc2adbSBill Paul 		sc->mii_capabilities = BMSR_ANEG | BMSR_10TFDX | BMSR_10THDX;
17296f2e892SBill Paul 		break;
17396f2e892SBill Paul 	default:
17436bef328SMarius Strobl 		if (dc_sc->dc_pmode == DC_PMODE_SIA)
1755c1cfac4SBill Paul 			sc->mii_capabilities =
1765c1cfac4SBill Paul 			    BMSR_ANEG | BMSR_10TFDX | BMSR_10THDX;
17736bef328SMarius Strobl 		else
17896f2e892SBill Paul 			sc->mii_capabilities =
17996f2e892SBill Paul 			    BMSR_ANEG | BMSR_100TXFDX | BMSR_100TXHDX |
18096f2e892SBill Paul 			    BMSR_10TFDX | BMSR_10THDX;
18196f2e892SBill Paul 		break;
18296f2e892SBill Paul 	}
18396f2e892SBill Paul 
18496f2e892SBill Paul 	sc->mii_capabilities &= ma->mii_capmask;
18596f2e892SBill Paul 	device_printf(dev, " ");
186b54282f6SMarius Strobl 	mii_phy_add_media(sc);
18796f2e892SBill Paul 	printf("\n");
18896f2e892SBill Paul 
18996f2e892SBill Paul 	MIIBUS_MEDIAINIT(sc->mii_dev);
19096f2e892SBill Paul 	return (0);
19196f2e892SBill Paul }
19296f2e892SBill Paul 
193d9730b8bSJonathan Lemon static int
1947d830ac9SWarner Losh dcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
19596f2e892SBill Paul {
19696f2e892SBill Paul 	struct dc_softc		*dc_sc;
19796f2e892SBill Paul 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
19896f2e892SBill Paul 	int reg;
19996f2e892SBill Paul 	u_int32_t		mode;
20096f2e892SBill Paul 
20196f2e892SBill Paul 	dc_sc = mii->mii_ifp->if_softc;
20296f2e892SBill Paul 
20396f2e892SBill Paul 	switch (cmd) {
20496f2e892SBill Paul 	case MII_POLLSTAT:
20596f2e892SBill Paul 		break;
20696f2e892SBill Paul 
20796f2e892SBill Paul 	case MII_MEDIACHG:
20896f2e892SBill Paul 		/*
20996f2e892SBill Paul 		 * If the interface is not up, don't do anything.
21096f2e892SBill Paul 		 */
21196f2e892SBill Paul 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
21296f2e892SBill Paul 			break;
21396f2e892SBill Paul 
21496f2e892SBill Paul 		sc->mii_flags = 0;
21596f2e892SBill Paul 		mii->mii_media_active = IFM_NONE;
21696f2e892SBill Paul 		mode = CSR_READ_4(dc_sc, DC_NETCFG);
21796f2e892SBill Paul 		mode &= ~(DC_NETCFG_FULLDUPLEX | DC_NETCFG_PORTSEL |
21896f2e892SBill Paul 		    DC_NETCFG_PCS | DC_NETCFG_SCRAMBLER | DC_NETCFG_SPEEDSEL);
21996f2e892SBill Paul 
22096f2e892SBill Paul 		switch (IFM_SUBTYPE(ife->ifm_media)) {
22196f2e892SBill Paul 		case IFM_AUTO:
22296f2e892SBill Paul 			/*dcphy_reset(sc);*/
223fd94424cSPoul-Henning Kamp 			(void) dcphy_auto(sc);
22496f2e892SBill Paul 			break;
22596f2e892SBill Paul 		case IFM_100_T4:
22696f2e892SBill Paul 			/*
22796f2e892SBill Paul 			 * XXX Not supported as a manual setting right now.
22896f2e892SBill Paul 			 */
22996f2e892SBill Paul 			return (EINVAL);
23096f2e892SBill Paul 		case IFM_100_TX:
23196f2e892SBill Paul 			dcphy_reset(sc);
23296f2e892SBill Paul 			DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
23396f2e892SBill Paul 			mode |= DC_NETCFG_PORTSEL | DC_NETCFG_PCS |
23496f2e892SBill Paul 			    DC_NETCFG_SCRAMBLER;
23596f2e892SBill Paul 			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
23696f2e892SBill Paul 				mode |= DC_NETCFG_FULLDUPLEX;
23796f2e892SBill Paul 			else
23896f2e892SBill Paul 				mode &= ~DC_NETCFG_FULLDUPLEX;
23996f2e892SBill Paul 			CSR_WRITE_4(dc_sc, DC_NETCFG, mode);
24096f2e892SBill Paul 			break;
24196f2e892SBill Paul 		case IFM_10_T:
24296f2e892SBill Paul 			DC_CLRBIT(dc_sc, DC_SIARESET, DC_SIA_RESET);
24396f2e892SBill Paul 			DC_CLRBIT(dc_sc, DC_10BTCTRL, 0xFFFF);
24496f2e892SBill Paul 			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
24596f2e892SBill Paul 				DC_SETBIT(dc_sc, DC_10BTCTRL, 0x7F3D);
24696f2e892SBill Paul 			else
24796f2e892SBill Paul 				DC_SETBIT(dc_sc, DC_10BTCTRL, 0x7F3F);
24896f2e892SBill Paul 			DC_SETBIT(dc_sc, DC_SIARESET, DC_SIA_RESET);
24996f2e892SBill Paul 			DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
25096f2e892SBill Paul 			mode &= ~DC_NETCFG_PORTSEL;
25196f2e892SBill Paul 			mode |= DC_NETCFG_SPEEDSEL;
25296f2e892SBill Paul 			if ((ife->ifm_media & IFM_GMASK) == IFM_FDX)
25396f2e892SBill Paul 				mode |= DC_NETCFG_FULLDUPLEX;
25496f2e892SBill Paul 			else
25596f2e892SBill Paul 				mode &= ~DC_NETCFG_FULLDUPLEX;
25696f2e892SBill Paul 			CSR_WRITE_4(dc_sc, DC_NETCFG, mode);
25796f2e892SBill Paul 			break;
25896f2e892SBill Paul 		default:
25996f2e892SBill Paul 			return (EINVAL);
26096f2e892SBill Paul 		}
26196f2e892SBill Paul 		break;
26296f2e892SBill Paul 
26396f2e892SBill Paul 	case MII_TICK:
26496f2e892SBill Paul 		/*
26596f2e892SBill Paul 		 * Is the interface even up?
26696f2e892SBill Paul 		 */
26796f2e892SBill Paul 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
26896f2e892SBill Paul 			return (0);
26996f2e892SBill Paul 
270d9730b8bSJonathan Lemon 		/*
271d9730b8bSJonathan Lemon 		 * Only used for autonegotiation.
272d9730b8bSJonathan Lemon 		 */
273d9730b8bSJonathan Lemon 		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
274d9730b8bSJonathan Lemon 			break;
275d9730b8bSJonathan Lemon 
276e3c5a449SStephen McKay 		reg = CSR_READ_4(dc_sc, DC_10BTSTAT);
277318b02fdSBill Paul 		if (!(reg & DC_TSTAT_LS10) || !(reg & DC_TSTAT_LS100))
278d9730b8bSJonathan Lemon 			break;
279318b02fdSBill Paul 
280318b02fdSBill Paul                 /*
281318b02fdSBill Paul                  * Only retry autonegotiation every 5 seconds.
282e3c5a449SStephen McKay 		 *
283e3c5a449SStephen McKay 		 * Otherwise, fall through to calling dcphy_status()
284e3c5a449SStephen McKay 		 * since real Intel 21143 chips don't show valid link
285e3c5a449SStephen McKay 		 * status until autonegotiation is switched off, and
286e3c5a449SStephen McKay 		 * that only happens in dcphy_status().  Without this,
287b78791d3SMarius Strobl 		 * successful autonegotiation is never recognised on
288e3c5a449SStephen McKay 		 * these chips.
289318b02fdSBill Paul                  */
2909a54cbb9SAndre Oppermann                 if (++sc->mii_ticks <= 50)
291e3c5a449SStephen McKay 			break;
29296f2e892SBill Paul 
29396f2e892SBill Paul 		sc->mii_ticks = 0;
294fd94424cSPoul-Henning Kamp 		dcphy_auto(sc);
29596f2e892SBill Paul 
29696f2e892SBill Paul 		break;
29796f2e892SBill Paul 	}
29896f2e892SBill Paul 
29996f2e892SBill Paul 	/* Update the media status. */
30096f2e892SBill Paul 	dcphy_status(sc);
30196f2e892SBill Paul 
30296f2e892SBill Paul 	/* Callback if something changed. */
303d9730b8bSJonathan Lemon 	mii_phy_update(sc, cmd);
30496f2e892SBill Paul 	return (0);
30596f2e892SBill Paul }
30696f2e892SBill Paul 
307d9730b8bSJonathan Lemon static void
3087d830ac9SWarner Losh dcphy_status(struct mii_softc *sc)
30996f2e892SBill Paul {
31096f2e892SBill Paul 	struct mii_data *mii = sc->mii_pdata;
311318b02fdSBill Paul 	int reg, anlpar, tstat = 0;
31296f2e892SBill Paul 	struct dc_softc		*dc_sc;
31396f2e892SBill Paul 
31496f2e892SBill Paul 	dc_sc = mii->mii_ifp->if_softc;
31596f2e892SBill Paul 
31696f2e892SBill Paul 	mii->mii_media_status = IFM_AVALID;
31796f2e892SBill Paul 	mii->mii_media_active = IFM_ETHER;
31896f2e892SBill Paul 
319b6a1416dSBill Paul 	if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
320b6a1416dSBill Paul 		return;
321b6a1416dSBill Paul 
322e3c5a449SStephen McKay 	reg = CSR_READ_4(dc_sc, DC_10BTSTAT);
32396f2e892SBill Paul 	if (!(reg & DC_TSTAT_LS10) || !(reg & DC_TSTAT_LS100))
32496f2e892SBill Paul 		mii->mii_media_status |= IFM_ACTIVE;
32596f2e892SBill Paul 
326318b02fdSBill Paul 	if (CSR_READ_4(dc_sc, DC_10BTCTRL) & DC_TCTL_AUTONEGENBL) {
32796f2e892SBill Paul 		/* Erg, still trying, I guess... */
328318b02fdSBill Paul 		tstat = CSR_READ_4(dc_sc, DC_10BTSTAT);
329318b02fdSBill Paul 		if ((tstat & DC_TSTAT_ANEGSTAT) != DC_ASTAT_AUTONEGCMP) {
330318b02fdSBill Paul 			if ((DC_IS_MACRONIX(dc_sc) || DC_IS_PNICII(dc_sc)) &&
331318b02fdSBill Paul 			    (tstat & DC_TSTAT_ANEGSTAT) == DC_ASTAT_DISABLE)
332318b02fdSBill Paul 				goto skip;
33396f2e892SBill Paul 			mii->mii_media_active |= IFM_NONE;
33496f2e892SBill Paul 			return;
33596f2e892SBill Paul 		}
33696f2e892SBill Paul 
337318b02fdSBill Paul 		if (tstat & DC_TSTAT_LP_CAN_NWAY) {
338318b02fdSBill Paul 			anlpar = tstat >> 16;
339d612cc59SPyun YongHyeon 			if (anlpar & ANLPAR_TX_FD &&
340318b02fdSBill Paul 			    sc->mii_capabilities & BMSR_100TXFDX)
34196f2e892SBill Paul 				mii->mii_media_active |= IFM_100_TX | IFM_FDX;
342d612cc59SPyun YongHyeon 			else if (anlpar & ANLPAR_T4 &&
343d612cc59SPyun YongHyeon 			    sc->mii_capabilities & BMSR_100T4)
344*d7a9ad56SMarius Strobl 				mii->mii_media_active |= IFM_100_T4 | IFM_HDX;
34591cc2adbSBill Paul 			else if (anlpar & ANLPAR_TX &&
34691cc2adbSBill Paul 			    sc->mii_capabilities & BMSR_100TXHDX)
347*d7a9ad56SMarius Strobl 				mii->mii_media_active |= IFM_100_TX | IFM_HDX;
34896f2e892SBill Paul 			else if (anlpar & ANLPAR_10_FD)
34996f2e892SBill Paul 				mii->mii_media_active |= IFM_10_T | IFM_FDX;
35096f2e892SBill Paul 			else if (anlpar & ANLPAR_10)
351*d7a9ad56SMarius Strobl 				mii->mii_media_active |= IFM_10_T | IFM_HDX;
35296f2e892SBill Paul 			else
35396f2e892SBill Paul 				mii->mii_media_active |= IFM_NONE;
35496f2e892SBill Paul 			if (DC_IS_INTEL(dc_sc))
35596f2e892SBill Paul 				DC_CLRBIT(dc_sc, DC_10BTCTRL,
35696f2e892SBill Paul 				    DC_TCTL_AUTONEGENBL);
35796f2e892SBill Paul 			return;
35896f2e892SBill Paul 		}
35936bef328SMarius Strobl 
36096f2e892SBill Paul 		/*
36196f2e892SBill Paul 		 * If the other side doesn't support NWAY, then the
36296f2e892SBill Paul 		 * best we can do is determine if we have a 10Mbps or
36396f2e892SBill Paul 		 * 100Mbps link.  There's no way to know if the link
36496f2e892SBill Paul 		 * is full or half duplex, so we default to half duplex
36596f2e892SBill Paul 		 * and hope that the user is clever enough to manually
36696f2e892SBill Paul 		 * change the media settings if we're wrong.
36796f2e892SBill Paul 		 */
36896f2e892SBill Paul 		if (!(reg & DC_TSTAT_LS100))
369*d7a9ad56SMarius Strobl 			mii->mii_media_active |= IFM_100_TX | IFM_HDX;
37096f2e892SBill Paul 		else if (!(reg & DC_TSTAT_LS10))
371*d7a9ad56SMarius Strobl 			mii->mii_media_active |= IFM_10_T | IFM_HDX;
37296f2e892SBill Paul 		else
37396f2e892SBill Paul 			mii->mii_media_active |= IFM_NONE;
37496f2e892SBill Paul 		if (DC_IS_INTEL(dc_sc))
37596f2e892SBill Paul 			DC_CLRBIT(dc_sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
37696f2e892SBill Paul 		return;
37796f2e892SBill Paul 	}
37896f2e892SBill Paul 
379318b02fdSBill Paul skip:
3805c1cfac4SBill Paul 	if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_SPEEDSEL)
38196f2e892SBill Paul 		mii->mii_media_active |= IFM_10_T;
3825c1cfac4SBill Paul 	else
3835c1cfac4SBill Paul 		mii->mii_media_active |= IFM_100_TX;
38496f2e892SBill Paul 	if (CSR_READ_4(dc_sc, DC_NETCFG) & DC_NETCFG_FULLDUPLEX)
38596f2e892SBill Paul 		mii->mii_media_active |= IFM_FDX;
386*d7a9ad56SMarius Strobl 	else
387*d7a9ad56SMarius Strobl 		mii->mii_media_active |= IFM_HDX;
38896f2e892SBill Paul }
38996f2e892SBill Paul 
39096f2e892SBill Paul static int
3917d830ac9SWarner Losh dcphy_auto(struct mii_softc *mii)
39296f2e892SBill Paul {
39396f2e892SBill Paul 	struct dc_softc		*sc;
39496f2e892SBill Paul 
39596f2e892SBill Paul 	sc = mii->mii_pdata->mii_ifp->if_softc;
39696f2e892SBill Paul 
39796f2e892SBill Paul 	DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
39896f2e892SBill Paul 	DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
39996f2e892SBill Paul 	DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
40091cc2adbSBill Paul 	if (mii->mii_capabilities & BMSR_100TXHDX)
40196f2e892SBill Paul 		CSR_WRITE_4(sc, DC_10BTCTRL, 0x3FFFF);
40291cc2adbSBill Paul 	else
40391cc2adbSBill Paul 		CSR_WRITE_4(sc, DC_10BTCTRL, 0xFFFF);
40496f2e892SBill Paul 	DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
40596f2e892SBill Paul 	DC_SETBIT(sc, DC_10BTCTRL, DC_TCTL_AUTONEGENBL);
40696f2e892SBill Paul 	DC_SETBIT(sc, DC_10BTSTAT, DC_ASTAT_TXDISABLE);
40796f2e892SBill Paul 
40896f2e892SBill Paul 	return (EJUSTRETURN);
40996f2e892SBill Paul }
41096f2e892SBill Paul 
41196f2e892SBill Paul static void
4127d830ac9SWarner Losh dcphy_reset(struct mii_softc *mii)
41396f2e892SBill Paul {
41496f2e892SBill Paul 	struct dc_softc		*sc;
41596f2e892SBill Paul 
41696f2e892SBill Paul 	sc = mii->mii_pdata->mii_ifp->if_softc;
41796f2e892SBill Paul 
41896f2e892SBill Paul 	DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
41996f2e892SBill Paul 	DELAY(1000);
42096f2e892SBill Paul 	DC_SETBIT(sc, DC_SIARESET, DC_SIA_RESET);
42196f2e892SBill Paul }
422