Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/mii Implement asynchronous autonegotiation when driv...
details: https://anonhg.NetBSD.org/src/rev/d62d32831dff
branches: trunk
changeset: 472148:d62d32831dff
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Apr 23 04:24:32 1999 +0000
description:
Implement asynchronous autonegotiation when driven by the MII tick
(one-second clock). Prevents .5s delays every 5 seconds when the interface
is up but there is no link. Fixes PR 7361.
diffstat:
sys/dev/mii/exphy.c | 6 +-
sys/dev/mii/icsphy.c | 6 +-
sys/dev/mii/inphy.c | 10 +++--
sys/dev/mii/lxtphy.c | 10 +++--
sys/dev/mii/mii_physubr.c | 72 ++++++++++++++++++++++++++++++++++++++--------
sys/dev/mii/miivar.h | 7 ++-
sys/dev/mii/nsphy.c | 10 +++--
sys/dev/mii/qsphy.c | 6 +-
sys/dev/mii/sqphy.c | 10 +++--
sys/dev/mii/tlphy.c | 56 +++++++++++++++++++++++++++---------
sys/dev/mii/ukphy.c | 10 +++--
11 files changed, 144 insertions(+), 59 deletions(-)
diffs (truncated from 528 to 300 lines):
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/exphy.c
--- a/sys/dev/mii/exphy.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/exphy.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: exphy.c,v 1.15 1998/11/05 00:19:32 thorpej Exp $ */
+/* $NetBSD: exphy.c,v 1.16 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -201,7 +201,7 @@
*/
if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
return (0);
- (void) mii_phy_auto(sc);
+ (void) mii_phy_auto(sc, 1);
break;
case IFM_100_T4:
/*
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/icsphy.c
--- a/sys/dev/mii/icsphy.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/icsphy.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: icsphy.c,v 1.8 1998/11/05 04:08:01 thorpej Exp $ */
+/* $NetBSD: icsphy.c,v 1.9 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -193,7 +193,7 @@
*/
if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
return (0);
- (void) mii_phy_auto(sc);
+ (void) mii_phy_auto(sc, 1);
break;
case IFM_100_T4:
/*
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/inphy.c
--- a/sys/dev/mii/inphy.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/inphy.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: inphy.c,v 1.10 1998/11/05 04:08:02 thorpej Exp $ */
+/* $NetBSD: inphy.c,v 1.11 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -77,6 +77,7 @@
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/socket.h>
+#include <sys/errno.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -201,7 +202,7 @@
*/
if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
return (0);
- (void) mii_phy_auto(sc);
+ (void) mii_phy_auto(sc, 1);
break;
case IFM_100_T4:
/*
@@ -255,7 +256,8 @@
sc->mii_ticks = 0;
mii_phy_reset(sc);
- (void) mii_phy_auto(sc);
+ if (mii_phy_auto(sc, 0) == EJUSTRETURN)
+ return (0);
break;
}
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/lxtphy.c
--- a/sys/dev/mii/lxtphy.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/lxtphy.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: lxtphy.c,v 1.9 1998/11/05 04:08:02 thorpej Exp $ */
+/* $NetBSD: lxtphy.c,v 1.10 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -77,6 +77,7 @@
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/socket.h>
+#include <sys/errno.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -192,7 +193,7 @@
*/
if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
return (0);
- (void) mii_phy_auto(sc);
+ (void) mii_phy_auto(sc, 1);
break;
case IFM_100_T4:
/*
@@ -247,7 +248,8 @@
sc->mii_ticks = 0;
mii_phy_reset(sc);
- (void) mii_phy_auto(sc);
+ if (mii_phy_auto(sc, 0) == EJUSTRETURN)
+ return (0);
break;
}
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/mii_physubr.c
--- a/sys/dev/mii/mii_physubr.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/mii_physubr.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: mii_physubr.c,v 1.2 1998/11/04 23:28:15 thorpej Exp $ */
+/* $NetBSD: mii_physubr.c,v 1.3 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -44,7 +44,9 @@
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
+#include <sys/kernel.h>
#include <sys/socket.h>
+#include <sys/errno.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -52,28 +54,72 @@
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
+void mii_phy_auto_timeout __P((void *));
+
int
-mii_phy_auto(mii)
+mii_phy_auto(mii, waitfor)
struct mii_softc *mii;
{
int bmsr, i;
- PHY_WRITE(mii, MII_ANAR,
- BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA);
- PHY_WRITE(mii, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG);
+ if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
+ PHY_WRITE(mii, MII_ANAR,
+ BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA);
+ PHY_WRITE(mii, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG);
+ }
+
+ if (waitfor) {
+ /* Wait 500ms for it to complete. */
+ for (i = 0; i < 500; i++) {
+ if ((bmsr = PHY_READ(mii, MII_BMSR)) & BMSR_ACOMP)
+ return (0);
+ delay(1000);
+#if 0
+ if ((bmsr & BMSR_ACOMP) == 0)
+ printf("%s: autonegotiation failed to complete\n",
+ mii->mii_dev.dv_xname);
+#endif
+ }
- /* Wait 500ms for it to complete. */
- for (i = 0; i < 500; i++) {
- if ((bmsr = PHY_READ(mii, MII_BMSR)) & BMSR_ACOMP)
- return (1);
- delay(1000);
+ /*
+ * Don't need to worry about clearing MIIF_DOINGAUTO.
+ * If that's set, a timeout is pending, and it will
+ * clear the flag.
+ */
+ return (EIO);
}
+
+ /*
+ * Just let it finish asynchronously. This is for the benefit of
+ * the tick handler driving autonegotiation. Don't want 500ms
+ * delays all the time while the system is running!
+ */
+ if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
+ mii->mii_flags |= MIIF_DOINGAUTO;
+ timeout(mii_phy_auto_timeout, mii, hz >> 1);
+ }
+ return (EJUSTRETURN);
+}
+
+void
+mii_phy_auto_timeout(arg)
+ void *arg;
+{
+ struct mii_softc *mii = arg;
+ int s, bmsr;
+
+ s = splnet();
+ mii->mii_flags &= ~MIIF_DOINGAUTO;
+ bmsr = PHY_READ(mii, MII_BMSR);
#if 0
if ((bmsr & BMSR_ACOMP) == 0)
printf("%s: autonegotiation failed to complete\n",
- mii->mii_dev.dv_xname);
+ sc->sc_dev.dv_xname);
#endif
- return (0);
+
+ /* Update the media status. */
+ (void) (*mii->mii_service)(mii, mii->mii_pdata, MII_POLLSTAT);
+ splx(s);
}
void
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/miivar.h
--- a/sys/dev/mii/miivar.h Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/miivar.h Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: miivar.h,v 1.7 1998/11/05 04:08:02 thorpej Exp $ */
+/* $NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -128,6 +128,7 @@
/* mii_flags */
#define MIIF_NOISOLATE 0x0001 /* do not isolate the PHY */
+#define MIIF_DOINGAUTO 0x0002 /* doing autonegotiation */
/*
* Used to attach a PHY to a parent.
@@ -161,7 +162,7 @@
int mii_media_from_bmcr __P((int));
-int mii_phy_auto __P((struct mii_softc *));
+int mii_phy_auto __P((struct mii_softc *, int));
void mii_phy_reset __P((struct mii_softc *));
void ukphy_status __P((struct mii_softc *));
diff -r 7f68f1ceae67 -r d62d32831dff sys/dev/mii/nsphy.c
--- a/sys/dev/mii/nsphy.c Fri Apr 23 01:38:35 1999 +0000
+++ b/sys/dev/mii/nsphy.c Fri Apr 23 04:24:32 1999 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: nsphy.c,v 1.16 1998/11/05 04:08:02 thorpej Exp $ */
+/* $NetBSD: nsphy.c,v 1.17 1999/04/23 04:24:32 thorpej Exp $ */
/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -77,6 +77,7 @@
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/socket.h>
+#include <sys/errno.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -235,7 +236,7 @@
*/
if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN)
return (0);
- (void) mii_phy_auto(sc);
+ (void) mii_phy_auto(sc, 1);
break;
case IFM_100_T4:
/*
@@ -289,7 +290,8 @@
sc->mii_ticks = 0;
mii_phy_reset(sc);
- (void) mii_phy_auto(sc);
+ if (mii_phy_auto(sc, 0) == EJUSTRETURN)
+ return (0);
break;
}
Home |
Main Index |
Thread Index |
Old Index