Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/mii Reading the IEEE specs shows that the bits have ...



details:   https://anonhg.NetBSD.org/src/rev/bdba14fc02f8
branches:  trunk
changeset: 507650:bdba14fc02f8
user:      drochner <drochner%NetBSD.org@localhost>
date:      Wed Mar 28 14:13:06 2001 +0000

description:
Reading the IEEE specs shows that the bits have to be reversed when
mapping an OUI to the MII id registers.
Doing this in the MII_OUI() macro would be too complex, so put it into
a helper function and move the MII id register interpretation stuff
into miivar.h.

diffstat:

 sys/dev/mii/mii.c    |  25 ++++++++++++++++++++++++-
 sys/dev/mii/mii.h    |   6 +-----
 sys/dev/mii/miivar.h |   8 +++++++-
 3 files changed, 32 insertions(+), 7 deletions(-)

diffs (78 lines):

diff -r 3938ae62bb5f -r bdba14fc02f8 sys/dev/mii/mii.c
--- a/sys/dev/mii/mii.c Wed Mar 28 13:47:58 2001 +0000
+++ b/sys/dev/mii/mii.c Wed Mar 28 14:13:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mii.c,v 1.22 2001/03/24 20:44:26 thorpej Exp $ */
+/*     $NetBSD: mii.c,v 1.23 2001/03/28 14:13:06 drochner Exp $        */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -315,3 +315,26 @@
             child = LIST_NEXT(child, mii_list))
                (void) PHY_SERVICE(child, mii, MII_DOWN);
 }
+
+static unsigned char
+bitreverse(unsigned char x)
+{
+       static unsigned char nibbletab[16] = {
+               0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
+       };
+
+       return ((nibbletab[x & 15] << 4) | nibbletab[x >> 4]);
+}
+
+int
+mii_oui(id1, id2)
+       int id1, id2;
+{
+       int h;
+
+       h = (id1 << 6) | (id2 >> 10);
+
+       return ((bitreverse(h >> 16) << 16) |
+               (bitreverse((h >> 8) & 255) << 8) |
+               bitreverse(h & 255));
+}
diff -r 3938ae62bb5f -r bdba14fc02f8 sys/dev/mii/mii.h
--- a/sys/dev/mii/mii.h Wed Mar 28 13:47:58 2001 +0000
+++ b/sys/dev/mii/mii.h Wed Mar 28 14:13:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mii.h,v 1.3 2000/02/02 08:05:33 thorpej Exp $  */
+/*     $NetBSD: mii.h,v 1.4 2001/03/28 14:13:06 drochner Exp $ */
  
 /*
  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
@@ -91,10 +91,6 @@
 #define        IDR2_MODEL      0x03f0  /* vendor model */
 #define        IDR2_REV        0x000f  /* vendor revision */
 
-#define        MII_OUI(id1, id2)       (((id1) << 6) | ((id2) >> 10))
-#define        MII_MODEL(id2)          (((id2) & IDR2_MODEL) >> 4)
-#define        MII_REV(id2)            ((id2) & IDR2_REV)
-
 #define        MII_ANAR        0x04    /* Autonegotiation advertisement (rw) */
 #define ANAR_NP                0x8000  /* Next page (ro) */
 #define        ANAR_ACK        0x4000  /* link partner abilities acknowledged (ro) */
diff -r 3938ae62bb5f -r bdba14fc02f8 sys/dev/mii/miivar.h
--- a/sys/dev/mii/miivar.h      Wed Mar 28 13:47:58 2001 +0000
+++ b/sys/dev/mii/miivar.h      Wed Mar 28 14:13:06 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: miivar.h,v 1.19 2000/07/04 03:28:59 thorpej Exp $      */
+/*     $NetBSD: miivar.h,v 1.20 2001/03/28 14:13:07 drochner Exp $     */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -229,6 +229,12 @@
 void   mii_phy_statusmsg __P((struct mii_softc *));
 
 void   ukphy_status __P((struct mii_softc *));
+
+int mii_oui __P((int, int));
+#define        MII_OUI(id1, id2)       mii_oui(id1, id2)
+#define        MII_MODEL(id2)          (((id2) & IDR2_MODEL) >> 4)
+#define        MII_REV(id2)            ((id2) & IDR2_REV)
+
 #endif /* _KERNEL */
 
 #endif /* _DEV_MII_MIIVAR_H_ */



Home | Main Index | Thread Index | Old Index