diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-07-22 11:50:54 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-07-22 11:50:54 +0000 |
commit | a22210d5d06467ea4ad1f935fe012848b4324a93 (patch) | |
tree | fba2b1f7438740ff64e198674f242236526ce286 /sys/dev/mii/mii.c | |
parent | c27cf3f11701633df387ec2429c65e22b58a230d (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/dev/mii/mii.c')
-rw-r--r-- | sys/dev/mii/mii.c | 24 |
1 files changed, 23 insertions, 1 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)); +} |