summaryrefslogtreecommitdiffstats
path: root/sys/dev/mii/mii.c
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2011-05-03 19:51:29 +0000
committermarius <marius@FreeBSD.org>2011-05-03 19:51:29 +0000
commitd0f32374e669176f507d67889e3a92cc6a46232a (patch)
treefe53a4391d1d2bae36941fd16b2470c7f5559e9f /sys/dev/mii/mii.c
parent46eb8f2e89a3a96e1047d23f59fb21f5a8165fe1 (diff)
downloadFreeBSD-src-d0f32374e669176f507d67889e3a92cc6a46232a.zip
FreeBSD-src-d0f32374e669176f507d67889e3a92cc6a46232a.tar.gz
- Remove attempts to implement setting of BMCR_LOOP/MIIF_NOLOOP
(reporting IFM_LOOP based on BMCR_LOOP is left in place though as it might provide useful for debugging). For most mii(4) drivers it was unclear whether the PHYs driven by them actually support loopback or not. Moreover, typically loopback mode also needs to be activated on the MAC, which none of the Ethernet drivers using mii(4) implements. Given that loopback media has no real use (and obviously hardly had a chance to actually work) besides for driver development (which just loopback mode should be sufficient for though, i.e one doesn't necessary need support for loopback media) support for it is just dropped as both NetBSD and OpenBSD already did quite some time ago. - Let mii_phy_add_media() also announce the support of IFM_NONE. - Restructure the PHY entry points to use a structure of entry points instead of discrete function pointers, and extend this to include a "reset" entry point. Make sure any PHY-specific reset routine is always used, and provide one for lxtphy(4) which disables MII interrupts (as is done for a few other PHYs we have drivers for). This includes changing NIC drivers which previously just called the generic mii_phy_reset() to now actually call the PHY-specific reset routine, which might be crucial in some cases. While at it, the redundant checks in these NIC drivers for mii->mii_instance not being zero before calling the reset routines were removed because as soon as one PHY driver attaches mii->mii_instance is incremented and we hardly can end up in their media change callbacks etc if no PHY driver has attached as mii_attach() would have failed in that case and not attach a miibus(4) instance. Consequently, NIC drivers now no longer should call mii_phy_reset() directly, so it was removed from EXPORT_SYMS. - Add a mii_phy_dev_attach() as a companion helper to mii_phy_dev_probe(). The purpose of that function is to perform the common steps to attach a PHY driver instance and to hook it up to the miibus(4) instance and to optionally also handle the probing, addition and initialization of the supported media. So all a PHY driver without any special requirements has to do in its bus attach method is to call mii_phy_dev_attach() along with PHY-specific MIIF_* flags, a pointer to its PHY functions and the add_media set to one. All PHY drivers were updated to take advantage of mii_phy_dev_attach() as appropriate. Along with these changes the capability mask was added to the mii_softc structure so PHY drivers taking advantage of mii_phy_dev_attach() but still handling media on their own do not need to fiddle with the MII attach arguments anyway. - Keep track of the PHY offset in the mii_softc structure. This is done for compatibility with NetBSD/OpenBSD. - Keep track of the PHY's OUI, model and revision in the mii_softc structure. Several PHY drivers require this information also after attaching and previously had to wrap their own softc around mii_softc. NetBSD/OpenBSD also keep track of the model and revision on their mii_softc structure. All PHY drivers were updated to take advantage as appropriate. - Convert the mebers of the MII data structure to unsigned where appropriate. This is partly inspired by NetBSD/OpenBSD. - According to IEEE 802.3-2002 the bits actually have to be reversed when mapping an OUI to the MII ID registers. All PHY drivers and miidevs where changed as necessary. Actually this now again allows to largely share miidevs with NetBSD, which fixed this problem already 9 years ago. Consequently miidevs was synced as far as possible. - Add MIIF_NOMANPAUSE and mii_phy_flowstatus() calls to drivers that weren't explicitly converted to support flow control before. It's unclear whether flow control actually works with these but typically it should and their net behavior should be more correct with these changes in place than without if the MAC driver sets MIIF_DOPAUSE. Obtained from: NetBSD (partially) Reviewed by: yongari (earlier version), silence on arch@ and net@
Diffstat (limited to 'sys/dev/mii/mii.c')
-rw-r--r--sys/dev/mii/mii.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c
index 8485691..fbdd0ea 100644
--- a/sys/dev/mii/mii.c
+++ b/sys/dev/mii/mii.c
@@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/malloc.h>
#include <sys/module.h>
-#include <sys/bus.h>
+#include <sys/bus.h>
#include <net/if.h>
#include <net/if_media.h>
@@ -69,6 +69,7 @@ static int miibus_writereg(device_t, int, int, int);
static void miibus_statchg(device_t);
static void miibus_linkchg(device_t);
static void miibus_mediainit(device_t);
+static unsigned char mii_bitreverse(unsigned char x);
static device_method_t miibus_methods[] = {
/* device interface */
@@ -87,9 +88,9 @@ static device_method_t miibus_methods[] = {
/* MII interface */
DEVMETHOD(miibus_readreg, miibus_readreg),
DEVMETHOD(miibus_writereg, miibus_writereg),
- DEVMETHOD(miibus_statchg, miibus_statchg),
- DEVMETHOD(miibus_linkchg, miibus_linkchg),
- DEVMETHOD(miibus_mediainit, miibus_mediainit),
+ DEVMETHOD(miibus_statchg, miibus_statchg),
+ DEVMETHOD(miibus_linkchg, miibus_linkchg),
+ DEVMETHOD(miibus_mediainit, miibus_mediainit),
{ 0, 0 }
};
@@ -265,7 +266,7 @@ miibus_linkchg(device_t dev)
MIIBUS_LINKCHG(parent);
mii = device_get_softc(dev);
-
+
if (mii->mii_media_status & IFM_AVALID) {
if (mii->mii_media_status & IFM_ACTIVE)
link_state = LINK_STATE_UP;
@@ -361,7 +362,7 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* has been allocated.
*/
ma.mii_data = device_get_softc(*miibus);
- }
+ }
ma.mii_capmask = capmask;
@@ -392,7 +393,7 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* Check to see if there is a PHY at this address. Note,
* many braindead PHYs report 0/0 in their ID registers,
* so we test for media in the BMSR.
- */
+ */
bmsr = MIIBUS_READREG(dev, ma.mii_phyno, MII_BMSR);
if (bmsr == 0 || bmsr == 0xffff ||
(bmsr & (BMSR_EXTSTAT | BMSR_MEDIAMASK)) == 0) {
@@ -411,10 +412,11 @@ mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
* Extract the IDs. Braindead PHYs will be handled by
* the `ukphy' driver, as we have no ID information to
* match on.
- */
+ */
ma.mii_id1 = MIIBUS_READREG(dev, ma.mii_phyno, MII_PHYIDR1);
ma.mii_id2 = MIIBUS_READREG(dev, ma.mii_phyno, MII_PHYIDR2);
+ ma.mii_offset = offset;
args = malloc(sizeof(struct mii_attach_args), M_DEVBUF,
M_NOWAIT);
if (args == NULL)
@@ -486,7 +488,7 @@ mii_mediachg(struct mii_data *mii)
BMCR_ISO);
continue;
}
- rv = (*child->mii_service)(child, mii, MII_MEDIACHG);
+ rv = PHY_SERVICE(child, mii, MII_MEDIACHG);
if (rv)
return (rv);
}
@@ -509,7 +511,7 @@ mii_tick(struct mii_data *mii)
*/
if (IFM_INST(ife->ifm_media) != child->mii_inst)
continue;
- (void)(*child->mii_service)(child, mii, MII_TICK);
+ (void)PHY_SERVICE(child, mii, MII_TICK);
}
}
@@ -531,7 +533,7 @@ mii_pollstat(struct mii_data *mii)
*/
if (IFM_INST(ife->ifm_media) != child->mii_inst)
continue;
- (void)(*child->mii_service)(child, mii, MII_POLLSTAT);
+ (void)PHY_SERVICE(child, mii, MII_POLLSTAT);
}
}
@@ -546,3 +548,25 @@ mii_down(struct mii_data *mii)
LIST_FOREACH(child, &mii->mii_phys, mii_list)
mii_phy_down(child);
}
+
+static unsigned char
+mii_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]);
+}
+
+u_int
+mii_oui(u_int id1, u_int id2)
+{
+ u_int h;
+
+ h = (id1 << 6) | (id2 >> 10);
+
+ return ((mii_bitreverse(h >> 16) << 16) |
+ (mii_bitreverse((h >> 8) & 0xff) << 8) |
+ mii_bitreverse(h & 0xff));
+}
OpenPOWER on IntegriCloud