Deleted Added
full compact
xmphy.c (95722) xmphy.c (96026)
1/*
2 * Copyright (c) 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
1/*
2 * Copyright (c) 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: head/sys/dev/mii/xmphy.c 95722 2002-04-29 13:07:38Z phk $
32 * $FreeBSD: head/sys/dev/mii/xmphy.c 96026 2002-05-04 11:00:30Z phk $
33 */
34
35/*
36 * driver for the XaQti XMAC II's internal PHY. This is sort of
37 * like a 10/100 PHY, except the only thing we're really autoselecting
38 * here is full/half duplex. Speed is always 1000mbps.
39 */
40

--- 13 unchanged lines hidden (view full) ---

54#include <dev/mii/miidevs.h>
55
56#include <dev/mii/xmphyreg.h>
57
58#include "miibus_if.h"
59
60#if !defined(lint)
61static const char rcsid[] =
33 */
34
35/*
36 * driver for the XaQti XMAC II's internal PHY. This is sort of
37 * like a 10/100 PHY, except the only thing we're really autoselecting
38 * here is full/half duplex. Speed is always 1000mbps.
39 */
40

--- 13 unchanged lines hidden (view full) ---

54#include <dev/mii/miidevs.h>
55
56#include <dev/mii/xmphyreg.h>
57
58#include "miibus_if.h"
59
60#if !defined(lint)
61static const char rcsid[] =
62 "$FreeBSD: head/sys/dev/mii/xmphy.c 95722 2002-04-29 13:07:38Z phk $";
62 "$FreeBSD: head/sys/dev/mii/xmphy.c 96026 2002-05-04 11:00:30Z phk $";
63#endif
64
65static int xmphy_probe (device_t);
66static int xmphy_attach (device_t);
67
68static device_method_t xmphy_methods[] = {
69 /* device interface */
70 DEVMETHOD(device_probe, xmphy_probe),

--- 10 unchanged lines hidden (view full) ---

81 xmphy_methods,
82 sizeof(struct mii_softc)
83};
84
85DRIVER_MODULE(xmphy, miibus, xmphy_driver, xmphy_devclass, 0, 0);
86
87static int xmphy_service(struct mii_softc *, struct mii_data *, int);
88static void xmphy_status(struct mii_softc *);
63#endif
64
65static int xmphy_probe (device_t);
66static int xmphy_attach (device_t);
67
68static device_method_t xmphy_methods[] = {
69 /* device interface */
70 DEVMETHOD(device_probe, xmphy_probe),

--- 10 unchanged lines hidden (view full) ---

81 xmphy_methods,
82 sizeof(struct mii_softc)
83};
84
85DRIVER_MODULE(xmphy, miibus, xmphy_driver, xmphy_devclass, 0, 0);
86
87static int xmphy_service(struct mii_softc *, struct mii_data *, int);
88static void xmphy_status(struct mii_softc *);
89static int xmphy_mii_phy_auto(struct mii_softc *, int);
90extern void mii_phy_auto_timeout(void *);
89static int xmphy_mii_phy_auto(struct mii_softc *);
91
92static int xmphy_probe(dev)
93 device_t dev;
94{
95 struct mii_attach_args *ma;
96
97 ma = device_get_ivars(dev);
98

--- 102 unchanged lines hidden (view full) ---

201 case IFM_AUTO:
202#ifdef foo
203 /*
204 * If we're already in auto mode, just return.
205 */
206 if (PHY_READ(sc, XMPHY_MII_BMCR) & XMPHY_BMCR_AUTOEN)
207 return (0);
208#endif
90
91static int xmphy_probe(dev)
92 device_t dev;
93{
94 struct mii_attach_args *ma;
95
96 ma = device_get_ivars(dev);
97

--- 102 unchanged lines hidden (view full) ---

200 case IFM_AUTO:
201#ifdef foo
202 /*
203 * If we're already in auto mode, just return.
204 */
205 if (PHY_READ(sc, XMPHY_MII_BMCR) & XMPHY_BMCR_AUTOEN)
206 return (0);
207#endif
209 (void) xmphy_mii_phy_auto(sc, 1);
208 (void) xmphy_mii_phy_auto(sc);
210 break;
211 case IFM_1000_SX:
212 mii_phy_reset(sc);
213 if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
214 PHY_WRITE(sc, XMPHY_MII_ANAR, XMPHY_ANAR_FDX);
215 PHY_WRITE(sc, XMPHY_MII_BMCR, XMPHY_BMCR_FDX);
216 } else {
217 PHY_WRITE(sc, XMPHY_MII_ANAR, XMPHY_ANAR_HDX);

--- 40 unchanged lines hidden (view full) ---

258 * Only retry autonegotiation every 5 seconds.
259 */
260 if (++sc->mii_ticks != 5)
261 return (0);
262
263 sc->mii_ticks = 0;
264
265 mii_phy_reset(sc);
209 break;
210 case IFM_1000_SX:
211 mii_phy_reset(sc);
212 if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
213 PHY_WRITE(sc, XMPHY_MII_ANAR, XMPHY_ANAR_FDX);
214 PHY_WRITE(sc, XMPHY_MII_BMCR, XMPHY_BMCR_FDX);
215 } else {
216 PHY_WRITE(sc, XMPHY_MII_ANAR, XMPHY_ANAR_HDX);

--- 40 unchanged lines hidden (view full) ---

257 * Only retry autonegotiation every 5 seconds.
258 */
259 if (++sc->mii_ticks != 5)
260 return (0);
261
262 sc->mii_ticks = 0;
263
264 mii_phy_reset(sc);
266 if (xmphy_mii_phy_auto(sc, 0) == EJUSTRETURN)
267 return(0);
268 break;
265 xmphy_mii_phy_auto(sc);
266 return(0);
269 }
270
271 /* Update the media status. */
272 xmphy_status(sc);
273
274 /* Callback if something changed. */
275 mii_phy_update(sc, cmd);
276 return (0);

--- 50 unchanged lines hidden (view full) ---

327 else
328 mii->mii_media_active |= IFM_HDX;
329
330 return;
331}
332
333
334static int
267 }
268
269 /* Update the media status. */
270 xmphy_status(sc);
271
272 /* Callback if something changed. */
273 mii_phy_update(sc, cmd);
274 return (0);

--- 50 unchanged lines hidden (view full) ---

325 else
326 mii->mii_media_active |= IFM_HDX;
327
328 return;
329}
330
331
332static int
335xmphy_mii_phy_auto(mii, waitfor)
333xmphy_mii_phy_auto(mii)
336 struct mii_softc *mii;
334 struct mii_softc *mii;
337 int waitfor;
338{
335{
339 int bmsr, anar = 0, i;
336 int anar = 0;
340
337
341 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
342 anar = PHY_READ(mii, XMPHY_MII_ANAR);
343 anar |= XMPHY_ANAR_FDX|XMPHY_ANAR_HDX;
344 PHY_WRITE(mii, XMPHY_MII_ANAR, anar);
345 DELAY(1000);
346 PHY_WRITE(mii, XMPHY_MII_BMCR,
347 XMPHY_BMCR_AUTOEN | XMPHY_BMCR_STARTNEG);
348 }
338 anar = PHY_READ(mii, XMPHY_MII_ANAR);
339 anar |= XMPHY_ANAR_FDX|XMPHY_ANAR_HDX;
340 PHY_WRITE(mii, XMPHY_MII_ANAR, anar);
341 DELAY(1000);
342 PHY_WRITE(mii, XMPHY_MII_BMCR,
343 XMPHY_BMCR_AUTOEN | XMPHY_BMCR_STARTNEG);
349
344
350 if (waitfor) {
351 /* Wait 500ms for it to complete. */
352 for (i = 0; i < 500; i++) {
353 if ((bmsr = PHY_READ(mii, XMPHY_MII_BMSR)) &
354 XMPHY_BMSR_ACOMP)
355 return (0);
356 DELAY(1000);
357#if 0
358 if ((bmsr & BMSR_ACOMP) == 0)
359 printf("%s: autonegotiation failed to complete\n",
360 mii->mii_dev.dv_xname);
361#endif
362 }
363
364 /*
365 * Don't need to worry about clearing MIIF_DOINGAUTO.
366 * If that's set, a timeout is pending, and it will
367 * clear the flag.
368 */
369 return (EIO);
370 }
371
372 /*
373 * Just let it finish asynchronously. This is for the benefit of
374 * the tick handler driving autonegotiation. Don't want 500ms
375 * delays all the time while the system is running!
376 */
377 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
378 mii->mii_flags |= MIIF_DOINGAUTO;
379 mii->mii_auto_ch = timeout(mii_phy_auto_timeout, mii, hz >> 1);
380 }
381 return (EJUSTRETURN);
382}
345 return (EJUSTRETURN);
346}