summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2005-07-22 11:50:54 +0000
committerBrad Smith <brad@cvs.openbsd.org>2005-07-22 11:50:54 +0000
commita22210d5d06467ea4ad1f935fe012848b4324a93 (patch)
treefba2b1f7438740ff64e198674f242236526ce286 /sys
parentc27cf3f11701633df387ec2429c65e22b58a230d (diff)
Reading the IEEE specs shows that the bits have to be reversed when
mapping an OUI to the MII id registers. From drochner NetBSD
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/mii/mii.c24
-rw-r--r--sys/dev/mii/mii.h6
-rw-r--r--sys/dev/mii/miivar.h9
3 files changed, 31 insertions, 8 deletions
diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c
index 686b4d59bb3..911db2409fa 100644
--- a/sys/dev/mii/mii.c
+++ b/sys/dev/mii/mii.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mii.c,v 1.16 2005/07/09 21:32:06 brad Exp $ */
+/* $OpenBSD: mii.c,v 1.17 2005/07/22 11:50:53 brad Exp $ */
/* $NetBSD: mii.c,v 1.19 2000/02/02 17:09:44 thorpej Exp $ */
/*-
@@ -304,3 +304,25 @@ mii_down(struct mii_data *mii)
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(int id1, int id2)
+{
+ int h;
+
+ h = (id1 << 6) | (id2 >> 10);
+
+ return ((bitreverse(h >> 16) << 16) |
+ (bitreverse((h >> 8) & 255) << 8) |
+ bitreverse(h & 255));
+}
diff --git a/sys/dev/mii/mii.h b/sys/dev/mii/mii.h
index e074317a866..a68f8447cba 100644
--- a/sys/dev/mii/mii.h
+++ b/sys/dev/mii/mii.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mii.h,v 1.7 2004/10/07 22:18:48 brad Exp $ */
+/* $OpenBSD: mii.h,v 1.8 2005/07/22 11:50:53 brad Exp $ */
/* $NetBSD: mii.h,v 1.8 2001/05/31 03:06:46 thorpej Exp $ */
/*
@@ -108,10 +108,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) */
/* section 28.2.4.1 and 37.2.6.1 */
#define ANAR_NP 0x8000 /* Next page (ro) */
diff --git a/sys/dev/mii/miivar.h b/sys/dev/mii/miivar.h
index 7cda8632145..2f24cbcad9f 100644
--- a/sys/dev/mii/miivar.h
+++ b/sys/dev/mii/miivar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: miivar.h,v 1.23 2005/03/26 04:40:09 krw Exp $ */
+/* $OpenBSD: miivar.h,v 1.24 2005/07/22 11:50:53 brad Exp $ */
/* $NetBSD: miivar.h,v 1.17 2000/03/06 20:56:57 thorpej Exp $ */
/*-
@@ -243,6 +243,7 @@ int mii_mediachg(struct mii_data *);
void mii_tick(struct mii_data *);
void mii_pollstat(struct mii_data *);
void mii_down(struct mii_data *);
+int mii_anar(int);
int mii_phy_activate(struct device *, enum devact);
int mii_phy_detach(struct device *, int);
@@ -266,7 +267,11 @@ int mii_phy_statusmsg(struct mii_softc *);
void ukphy_status(struct mii_softc *);
-int mii_anar(int);
+int mii_oui(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_ */