xref: /openbsd-src/sys/dev/mii/mlphy.c (revision 471aeecfc619bc9b69519928152daf993376c2a1)
1*471aeecfSnaddy /*	$OpenBSD: mlphy.c,v 1.6 2022/04/06 18:59:29 naddy Exp $	*/
2a8f0da92Sclaudio 
3a8f0da92Sclaudio /*-
4a8f0da92Sclaudio  * Copyright (c) 1997, 1998, 1999
5a8f0da92Sclaudio  *	Bill Paul <wpaul <at> ctr.columbia.edu>.  All rights reserved.
6a8f0da92Sclaudio  *
7a8f0da92Sclaudio  * Redistribution and use in source and binary forms, with or without
8a8f0da92Sclaudio  * modification, are permitted provided that the following conditions
9a8f0da92Sclaudio  * are met:
10a8f0da92Sclaudio  * 1. Redistributions of source code must retain the above copyright
11a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer.
12a8f0da92Sclaudio  * 2. Redistributions in binary form must reproduce the above copyright
13a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer in the
14a8f0da92Sclaudio  *    documentation and/or other materials provided with the distribution.
15a8f0da92Sclaudio  * 3. All advertising materials mentioning features or use of this software
16a8f0da92Sclaudio  *    must display the following acknowledgement:
17a8f0da92Sclaudio  *	This product includes software developed by Bill Paul.
18a8f0da92Sclaudio  * 4. Neither the name of the author nor the names of any co-contributors
19a8f0da92Sclaudio  *    may be used to endorse or promote products derived from this software
20a8f0da92Sclaudio  *    without specific prior written permission.
21a8f0da92Sclaudio  *
22a8f0da92Sclaudio  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23a8f0da92Sclaudio  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24a8f0da92Sclaudio  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25a8f0da92Sclaudio  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26a8f0da92Sclaudio  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27a8f0da92Sclaudio  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28a8f0da92Sclaudio  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29a8f0da92Sclaudio  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30a8f0da92Sclaudio  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31a8f0da92Sclaudio  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32a8f0da92Sclaudio  * THE POSSIBILITY OF SUCH DAMAGE.
33a8f0da92Sclaudio  *
34a8f0da92Sclaudio  */
35a8f0da92Sclaudio 
36a8f0da92Sclaudio /*-
37a8f0da92Sclaudio  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
38a8f0da92Sclaudio  * All rights reserved.
39a8f0da92Sclaudio  *
40a8f0da92Sclaudio  * This code is derived from software contributed to The NetBSD Foundation
41a8f0da92Sclaudio  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
42a8f0da92Sclaudio  * NASA Ames Research Center, and by Frank van der Linden.
43a8f0da92Sclaudio  *
44a8f0da92Sclaudio  * Redistribution and use in source and binary forms, with or without
45a8f0da92Sclaudio  * modification, are permitted provided that the following conditions
46a8f0da92Sclaudio  * are met:
47a8f0da92Sclaudio  * 1. Redistributions of source code must retain the above copyright
48a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer.
49a8f0da92Sclaudio  * 2. Redistributions in binary form must reproduce the above copyright
50a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer in the
51a8f0da92Sclaudio  *    documentation and/or other materials provided with the distribution.
52a8f0da92Sclaudio  *
53a8f0da92Sclaudio  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54a8f0da92Sclaudio  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55a8f0da92Sclaudio  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56a8f0da92Sclaudio  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57a8f0da92Sclaudio  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58a8f0da92Sclaudio  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59a8f0da92Sclaudio  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60a8f0da92Sclaudio  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61a8f0da92Sclaudio  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62a8f0da92Sclaudio  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63a8f0da92Sclaudio  * POSSIBILITY OF SUCH DAMAGE.
64a8f0da92Sclaudio  */
65a8f0da92Sclaudio 
66a8f0da92Sclaudio /*
67a8f0da92Sclaudio  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
68a8f0da92Sclaudio  *
69a8f0da92Sclaudio  * Redistribution and use in source and binary forms, with or without
70a8f0da92Sclaudio  * modification, are permitted provided that the following conditions
71a8f0da92Sclaudio  * are met:
72a8f0da92Sclaudio  * 1. Redistributions of source code must retain the above copyright
73a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer.
74a8f0da92Sclaudio  * 2. Redistributions in binary form must reproduce the above copyright
75a8f0da92Sclaudio  *    notice, this list of conditions and the following disclaimer in the
76a8f0da92Sclaudio  *    documentation and/or other materials provided with the distribution.
77a8f0da92Sclaudio  *
78a8f0da92Sclaudio  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
79a8f0da92Sclaudio  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
80a8f0da92Sclaudio  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81a8f0da92Sclaudio  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
82a8f0da92Sclaudio  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
83a8f0da92Sclaudio  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84a8f0da92Sclaudio  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
85a8f0da92Sclaudio  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
86a8f0da92Sclaudio  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
87a8f0da92Sclaudio  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88a8f0da92Sclaudio  */
89a8f0da92Sclaudio 
90a8f0da92Sclaudio /*
91a8f0da92Sclaudio  * Micro Linear 6692 PHY
9208e363e4Sclaudio  *
9308e363e4Sclaudio  * The Micro Linear 6692 is a strange beast, and dealing with it using
9408e363e4Sclaudio  * this code framework is tricky. The 6692 is actually a 100Mbps-only
9508e363e4Sclaudio  * device, which means that a second PHY is required to support 10Mbps
9608e363e4Sclaudio  * modes. However, even though the 6692 does not support 10Mbps modes,
9708e363e4Sclaudio  * it can still advertise them when performing autonegotiation. If a
9808e363e4Sclaudio  * 10Mbps mode is negotiated, we must program the registers of the
9908e363e4Sclaudio  * companion PHY accordingly in addition to programming the registers
10008e363e4Sclaudio  * of the 6692.
10108e363e4Sclaudio  *
10208e363e4Sclaudio  * This device also does not have vendor/device ID registers.
10308e363e4Sclaudio  *
104a8f0da92Sclaudio  */
105a8f0da92Sclaudio 
106a8f0da92Sclaudio #include <sys/param.h>
107a8f0da92Sclaudio #include <sys/systm.h>
108a8f0da92Sclaudio #include <sys/kernel.h>
109a8f0da92Sclaudio #include <sys/device.h>
110a8f0da92Sclaudio #include <sys/socket.h>
111a8f0da92Sclaudio #include <sys/errno.h>
112a8f0da92Sclaudio 
113a8f0da92Sclaudio #include <net/if.h>
1140deb6685Smpi #include <net/if_var.h>
115a8f0da92Sclaudio #include <net/if_media.h>
116a8f0da92Sclaudio 
117a8f0da92Sclaudio #include <dev/mii/mii.h>
118a8f0da92Sclaudio #include <dev/mii/miivar.h>
119a8f0da92Sclaudio 
120a8f0da92Sclaudio #define ML_STATE_AUTO_SELF      1
121a8f0da92Sclaudio #define ML_STATE_AUTO_OTHER     2
122a8f0da92Sclaudio 
123a8f0da92Sclaudio struct mlphy_softc {
124a8f0da92Sclaudio 	struct mii_softc	 ml_mii;
125a8f0da92Sclaudio 	struct device		*ml_dev;
126a8f0da92Sclaudio 	int			 ml_state;
127a8f0da92Sclaudio 	int			 ml_linked;
128a8f0da92Sclaudio };
129a8f0da92Sclaudio 
130a8f0da92Sclaudio int	mlphy_probe(struct device *, void *, void *);
131a8f0da92Sclaudio void	mlphy_attach(struct device *, struct device *, void *);
132a8f0da92Sclaudio 
133*471aeecfSnaddy const struct cfattach mlphy_ca = {
134fa9fb3edSderaadt 	sizeof(struct mii_softc), mlphy_probe, mlphy_attach, mii_phy_detach
135a8f0da92Sclaudio };
136a8f0da92Sclaudio 
137a8f0da92Sclaudio struct cfdriver mlphy_cd = {
138a8f0da92Sclaudio 	NULL, "mlphy", DV_DULL
139a8f0da92Sclaudio };
140a8f0da92Sclaudio 
141a8f0da92Sclaudio void    mlphy_reset(struct mii_softc *);
142a8f0da92Sclaudio int	mlphy_service(struct mii_softc *, struct mii_data *, int);
143a8f0da92Sclaudio void	mlphy_status(struct mii_softc *);
144a8f0da92Sclaudio 
145a8f0da92Sclaudio const struct mii_phy_funcs mlphy_funcs = {
146a8f0da92Sclaudio 	mlphy_service, mlphy_status, mlphy_reset,
147a8f0da92Sclaudio };
148a8f0da92Sclaudio 
149a8f0da92Sclaudio int
mlphy_probe(struct device * parent,void * match,void * aux)150a8f0da92Sclaudio mlphy_probe(struct device *parent, void *match, void *aux)
151a8f0da92Sclaudio {
152a8f0da92Sclaudio 	struct mii_attach_args  *ma = aux;
153a8f0da92Sclaudio 
154a8f0da92Sclaudio 	/*
155a8f0da92Sclaudio 	 * Micro Linear PHY reports oui == 0 model == 0
156a8f0da92Sclaudio 	 */
157a8f0da92Sclaudio 	if (MII_OUI(ma->mii_id1, ma->mii_id2) != 0 ||
158a8f0da92Sclaudio 	    MII_MODEL(ma->mii_id2) != 0)
159a8f0da92Sclaudio 		return (0);
160a8f0da92Sclaudio 	/*
161a8f0da92Sclaudio 	 * Make sure the parent is a `tl'. So far, I have only
162a8f0da92Sclaudio 	 * encountered the 6692 on an Olicom card with a ThunderLAN
163a8f0da92Sclaudio 	 * controller chip.
164a8f0da92Sclaudio 	 */
165a8f0da92Sclaudio 	if (strcmp(parent->dv_cfdata->cf_driver->cd_name, "tl") != 0)
166a8f0da92Sclaudio 		return (0);
167a8f0da92Sclaudio 
168a8f0da92Sclaudio 	return (10);
169a8f0da92Sclaudio }
170a8f0da92Sclaudio 
171a8f0da92Sclaudio void
mlphy_attach(struct device * parent,struct device * self,void * aux)172a8f0da92Sclaudio mlphy_attach(struct device *parent, struct device *self, void *aux)
173a8f0da92Sclaudio {
174a8f0da92Sclaudio 	struct mlphy_softc *msc = (struct mlphy_softc *)self;
175a8f0da92Sclaudio 	struct mii_softc *sc = (struct mii_softc *)self;
176a8f0da92Sclaudio 	struct mii_attach_args *ma = aux;
177a8f0da92Sclaudio 	struct mii_data *mii = ma->mii_data;
178a8f0da92Sclaudio 
179a8f0da92Sclaudio 	printf(": ML6692 100baseTX PHY\n");
180a8f0da92Sclaudio 
181a8f0da92Sclaudio 	sc->mii_inst = mii->mii_instance;
182a8f0da92Sclaudio 	sc->mii_phy = ma->mii_phyno;
183a8f0da92Sclaudio 	sc->mii_funcs = &mlphy_funcs;
184a8f0da92Sclaudio 	sc->mii_pdata = mii;
185a8f0da92Sclaudio 	sc->mii_flags = ma->mii_flags;
186a8f0da92Sclaudio 	msc->ml_dev = parent;
187a8f0da92Sclaudio 
188fa9fb3edSderaadt 	PHY_RESET(sc);
189a8f0da92Sclaudio 
190a8f0da92Sclaudio 	sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
191a8f0da92Sclaudio #define ADD(m, c)	ifmedia_add(&mii->mii_media, (m), (c), NULL)
192a8f0da92Sclaudio 	ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst),
193a8f0da92Sclaudio 	   MII_MEDIA_100_TX);
194a8f0da92Sclaudio 	ma->mii_capmask = ~sc->mii_capabilities;
195a8f0da92Sclaudio #undef ADD
196a8f0da92Sclaudio 	if(sc->mii_capabilities & BMSR_MEDIAMASK)
197a8f0da92Sclaudio 		mii_phy_add_media(sc);
198a8f0da92Sclaudio }
199a8f0da92Sclaudio 
200a8f0da92Sclaudio int
mlphy_service(struct mii_softc * sc,struct mii_data * mii,int cmd)201a8f0da92Sclaudio mlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
202a8f0da92Sclaudio {
203a8f0da92Sclaudio 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
204a8f0da92Sclaudio 	struct mii_softc *other = NULL;
205a8f0da92Sclaudio 	struct mlphy_softc *msc = (struct mlphy_softc *)sc;
206a8f0da92Sclaudio 	int other_inst, reg;
207a8f0da92Sclaudio 
208a8f0da92Sclaudio 	LIST_FOREACH(other, &mii->mii_phys, mii_list)
209a8f0da92Sclaudio 		if (other != sc)
210a8f0da92Sclaudio 			break;
211a8f0da92Sclaudio 
212a8f0da92Sclaudio 	if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
213a8f0da92Sclaudio 		return (ENXIO);
214a8f0da92Sclaudio 
215a8f0da92Sclaudio 	switch (cmd) {
216a8f0da92Sclaudio 	case MII_POLLSTAT:
217a8f0da92Sclaudio 		/*
218a8f0da92Sclaudio 		 * If we're not polling our PHY instance, just return.
219a8f0da92Sclaudio 		 */
220a8f0da92Sclaudio 		if (IFM_INST(ife->ifm_media) != sc->mii_inst)
221a8f0da92Sclaudio 			return (0);
222a8f0da92Sclaudio 		break;
223a8f0da92Sclaudio 
224a8f0da92Sclaudio 	case MII_MEDIACHG:
225a8f0da92Sclaudio 		/*
226a8f0da92Sclaudio 		 * If the interface is not up, don't do anything.
227a8f0da92Sclaudio 		 */
228a8f0da92Sclaudio 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
229a8f0da92Sclaudio 			break;
230a8f0da92Sclaudio 
231a8f0da92Sclaudio 		switch (IFM_SUBTYPE(ife->ifm_media)) {
232a8f0da92Sclaudio 		case IFM_AUTO:
233a8f0da92Sclaudio 			msc->ml_state = ML_STATE_AUTO_SELF;
234a8f0da92Sclaudio 			if (other != NULL) {
235a8f0da92Sclaudio 				mii_phy_reset(other);
236a8f0da92Sclaudio 				PHY_WRITE(other, MII_BMCR, BMCR_ISO);
237a8f0da92Sclaudio                        	}
238a8f0da92Sclaudio 			(void)mii_phy_auto(sc, 0);
239a8f0da92Sclaudio 			msc->ml_linked = 0;
240a8f0da92Sclaudio 			break;
241a8f0da92Sclaudio 		case IFM_10_T:
242a8f0da92Sclaudio 			/*
243a8f0da92Sclaudio 		 	 * For 10baseT modes, reset and program the
244a8f0da92Sclaudio 		 	 * companion PHY (of any), then setup ourselves
245a8f0da92Sclaudio 			 * to match. This will put us in pass-through
246a8f0da92Sclaudio 		 	 * mode and let the companion PHY do all the
247a8f0da92Sclaudio 		 	 * work.
248a8f0da92Sclaudio 		 	 * BMCR data is stored in the ifmedia entry.
249a8f0da92Sclaudio 		 	 */
250a8f0da92Sclaudio 			if (other != NULL) {
251a8f0da92Sclaudio 				mii_phy_reset(other);
252a8f0da92Sclaudio 				PHY_WRITE(other, MII_BMCR, ife->ifm_data);
253a8f0da92Sclaudio 			}
254a8f0da92Sclaudio 			mii_phy_setmedia(sc);
255a8f0da92Sclaudio 			msc->ml_state = 0;
256a8f0da92Sclaudio 			break;
257a8f0da92Sclaudio 		case IFM_100_TX:
258a8f0da92Sclaudio 			/*
259a8f0da92Sclaudio 		 	 * For 100baseTX modes, reset and isolate the
260a8f0da92Sclaudio 		 	 * companion PHY (if any), then setup ourselves
261a8f0da92Sclaudio 		 	 * accordingly.
262a8f0da92Sclaudio 		 	 *
263a8f0da92Sclaudio 		 	 * BMCR data is stored in the ifmedia entry.
264a8f0da92Sclaudio 		 	 */
265a8f0da92Sclaudio 			if (other != NULL) {
266a8f0da92Sclaudio 				mii_phy_reset(other);
267a8f0da92Sclaudio 				PHY_WRITE(other, MII_BMCR, BMCR_ISO);
268a8f0da92Sclaudio                        	}
269a8f0da92Sclaudio 			mii_phy_setmedia(sc);
270a8f0da92Sclaudio 			msc->ml_state = 0;
271a8f0da92Sclaudio 			break;
272a8f0da92Sclaudio 		default:
273a8f0da92Sclaudio 			return (EINVAL);
274a8f0da92Sclaudio 		}
275a8f0da92Sclaudio 		break;
276a8f0da92Sclaudio 	case MII_TICK:
277a8f0da92Sclaudio 		/*
278a8f0da92Sclaudio 		 * If interface is not up, don't do anything
279a8f0da92Sclaudio 		 */
280a8f0da92Sclaudio 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
281a8f0da92Sclaudio 			return (0);
282a8f0da92Sclaudio 		/*
283a8f0da92Sclaudio 		 * Only used for autonegotiation.
284a8f0da92Sclaudio 		 */
285a8f0da92Sclaudio 		if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
286a8f0da92Sclaudio 			break;
287a8f0da92Sclaudio 		/*
288a8f0da92Sclaudio 		 * Check to see if we have link.  If we do, we don't
289a8f0da92Sclaudio 		 * need to restart the autonegotiation process.  Read
290a8f0da92Sclaudio 		 * the BMSR twice in case it's latched.
291a8f0da92Sclaudio 		 * If we're in a 10Mbps mode, check the link of the
292a8f0da92Sclaudio 		 * 10Mbps PHY. Sometimes the Micro Linear PHY's
293a8f0da92Sclaudio 		 * linkstat bit will clear while the linkstat bit of
294a8f0da92Sclaudio 		 * the companion PHY will remain set.
295a8f0da92Sclaudio 		 */
296a8f0da92Sclaudio 		if (msc->ml_state == ML_STATE_AUTO_OTHER) {
297a8f0da92Sclaudio 			reg = PHY_READ(other, MII_BMSR) |
298a8f0da92Sclaudio 			    PHY_READ(other, MII_BMSR);
299a8f0da92Sclaudio 		} else {
300a8f0da92Sclaudio 			reg = PHY_READ(sc, MII_BMSR) |
301a8f0da92Sclaudio 			    PHY_READ(sc, MII_BMSR);
302a8f0da92Sclaudio                 }
303a8f0da92Sclaudio 
304a8f0da92Sclaudio 		if (reg & BMSR_LINK) {
305a8f0da92Sclaudio 			if (!msc->ml_linked) {
306a8f0da92Sclaudio 				msc->ml_linked = 1;
307a8f0da92Sclaudio 				mlphy_status(sc);
308a8f0da92Sclaudio 			}
3090919571eSmikeb 			sc->mii_ticks = 0;
310a8f0da92Sclaudio 			break;
311a8f0da92Sclaudio 		}
312a8f0da92Sclaudio 		/*
313a8f0da92Sclaudio 		 * Only retry autonegotiation every 5 seconds.
314a8f0da92Sclaudio 		 */
315a8f0da92Sclaudio 		if (++sc->mii_ticks <= MII_ANEGTICKS)
316a8f0da92Sclaudio 			break;
317a8f0da92Sclaudio 
318a8f0da92Sclaudio 		sc->mii_ticks = 0;
319a8f0da92Sclaudio 		msc->ml_linked = 0;
320a8f0da92Sclaudio 		mii->mii_media_active = IFM_NONE;
321a8f0da92Sclaudio 		mii_phy_reset(sc);
322a8f0da92Sclaudio 		msc->ml_state = ML_STATE_AUTO_SELF;
323a8f0da92Sclaudio 		if (other != NULL) {
324a8f0da92Sclaudio 			mii_phy_reset(other);
325a8f0da92Sclaudio 			PHY_WRITE(other, MII_BMCR, BMCR_ISO);
326a8f0da92Sclaudio 		}
327a8f0da92Sclaudio 		mii_phy_auto(sc, 0);
328a8f0da92Sclaudio 		break;
329a8f0da92Sclaudio 
330a8f0da92Sclaudio 	case MII_DOWN:
331a8f0da92Sclaudio 		mii_phy_down(sc);
332a8f0da92Sclaudio 		return (0);
333a8f0da92Sclaudio 	}
334a8f0da92Sclaudio 
335a8f0da92Sclaudio 	/* Update the media status. */
336a8f0da92Sclaudio 	if (msc->ml_state == ML_STATE_AUTO_OTHER && other != NULL) {
337a8f0da92Sclaudio 		other_inst = other->mii_inst;
338a8f0da92Sclaudio 		other->mii_inst = sc->mii_inst;
339a8f0da92Sclaudio 		if (IFM_INST(ife->ifm_media) == other->mii_inst)
340a8f0da92Sclaudio 			(void) PHY_SERVICE(other, mii, MII_POLLSTAT);
341a8f0da92Sclaudio 		other->mii_inst = other_inst;
342a8f0da92Sclaudio 		sc->mii_media_active = other->mii_media_active;
343a8f0da92Sclaudio 		sc->mii_media_status = other->mii_media_status;
344a8f0da92Sclaudio 	} else
345a8f0da92Sclaudio 		ukphy_status(sc);
346a8f0da92Sclaudio 
347a8f0da92Sclaudio 	/* Callback if something changed. */
348a8f0da92Sclaudio 	mii_phy_update(sc, cmd);
349a8f0da92Sclaudio 	return (0);
350a8f0da92Sclaudio }
351a8f0da92Sclaudio 
352a8f0da92Sclaudio void
mlphy_reset(struct mii_softc * sc)353a8f0da92Sclaudio mlphy_reset(struct mii_softc *sc)
354a8f0da92Sclaudio {
355a8f0da92Sclaudio 	int reg;
356a8f0da92Sclaudio 
357a8f0da92Sclaudio 	mii_phy_reset(sc);
358a8f0da92Sclaudio 	reg = PHY_READ(sc, MII_BMCR);
359a8f0da92Sclaudio 	reg &= ~BMCR_AUTOEN;
360a8f0da92Sclaudio 	PHY_WRITE(sc, MII_BMCR, reg);
361a8f0da92Sclaudio }
362a8f0da92Sclaudio 
363a8f0da92Sclaudio /*
364a8f0da92Sclaudio  * If we negotiate a 10Mbps mode, we need to check for an alternate
365a8f0da92Sclaudio  * PHY and make sure it's enabled and set correctly.
366a8f0da92Sclaudio  */
367a8f0da92Sclaudio void
mlphy_status(struct mii_softc * sc)368a8f0da92Sclaudio mlphy_status(struct mii_softc *sc)
369a8f0da92Sclaudio {
370a8f0da92Sclaudio 	struct mlphy_softc *msc = (struct mlphy_softc *)sc;
371a8f0da92Sclaudio 	struct mii_data *mii = sc->mii_pdata;
372a8f0da92Sclaudio 	struct mii_softc *other = NULL;
373a8f0da92Sclaudio 
374a8f0da92Sclaudio 	/* See if there's another PHY on the bus with us. */
375a8f0da92Sclaudio 	LIST_FOREACH(other, &mii->mii_phys, mii_list)
376a8f0da92Sclaudio 		if (other != sc)
377a8f0da92Sclaudio 			break;
378a8f0da92Sclaudio 
379a8f0da92Sclaudio 	ukphy_status(sc);
380a8f0da92Sclaudio 
381a8f0da92Sclaudio 	if (IFM_SUBTYPE(mii->mii_media_active) != IFM_10_T) {
382a8f0da92Sclaudio 		msc->ml_state = ML_STATE_AUTO_SELF;
383a8f0da92Sclaudio 		if (other != NULL) {
384a8f0da92Sclaudio 			mii_phy_reset(other);
385a8f0da92Sclaudio 			PHY_WRITE(other, MII_BMCR, BMCR_ISO);
386a8f0da92Sclaudio 		}
387a8f0da92Sclaudio 	}
388a8f0da92Sclaudio 
389a8f0da92Sclaudio 	if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) {
390a8f0da92Sclaudio 		msc->ml_state = ML_STATE_AUTO_OTHER;
391a8f0da92Sclaudio 		mlphy_reset(&msc->ml_mii);
392a8f0da92Sclaudio 		PHY_WRITE(&msc->ml_mii, MII_BMCR, BMCR_ISO);
393a8f0da92Sclaudio 		if (other != NULL) {
394a8f0da92Sclaudio 			mii_phy_reset(other);
395a8f0da92Sclaudio 			mii_phy_auto(other, 1);
396a8f0da92Sclaudio 		}
397a8f0da92Sclaudio 	}
398a8f0da92Sclaudio }
399