aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/mii/atphy.c
diff options
context:
space:
mode:
authorMarius Strobl <marius@FreeBSD.org>2011-05-03 19:51:29 +0000
committerMarius Strobl <marius@FreeBSD.org>2011-05-03 19:51:29 +0000
commit3fcb7a5365f9de7824a2b5f8e8ab159c8d3d79a0 (patch)
treefe53a4391d1d2bae36941fd16b2470c7f5559e9f /sys/dev/mii/atphy.c
parent5b5140322dc804072d957f1157ac0e4ec6261e7b (diff)
downloadsrc-3fcb7a5365f9de7824a2b5f8e8ab159c8d3d79a0.tar.gz
src-3fcb7a5365f9de7824a2b5f8e8ab159c8d3d79a0.zip
- 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@
Notes
Notes: svn path=/head/; revision=221407
Diffstat (limited to 'sys/dev/mii/atphy.c')
-rw-r--r--sys/dev/mii/atphy.c63
1 files changed, 13 insertions, 50 deletions
diff --git a/sys/dev/mii/atphy.c b/sys/dev/mii/atphy.c
index 6e261a52fb8c..0d80ba120e6e 100644
--- a/sys/dev/mii/atphy.c
+++ b/sys/dev/mii/atphy.c
@@ -53,13 +53,6 @@ __FBSDID("$FreeBSD$");
static int atphy_probe(device_t);
static int atphy_attach(device_t);
-struct atphy_softc {
- struct mii_softc mii_sc;
- int mii_oui;
- int mii_model;
- int mii_rev;
-};
-
static device_method_t atphy_methods[] = {
/* Device interface. */
DEVMETHOD(device_probe, atphy_probe),
@@ -73,7 +66,7 @@ static devclass_t atphy_devclass;
static driver_t atphy_driver = {
"atphy",
atphy_methods,
- sizeof(struct atphy_softc)
+ sizeof(struct mii_softc)
};
DRIVER_MODULE(atphy, miibus, atphy_driver, atphy_devclass, 0, 0);
@@ -85,12 +78,18 @@ static uint16_t atphy_anar(struct ifmedia_entry *);
static int atphy_setmedia(struct mii_softc *, int);
static const struct mii_phydesc atphys[] = {
- MII_PHY_DESC(ATHEROS, F1),
- MII_PHY_DESC(ATHEROS, F1_7),
- MII_PHY_DESC(ATHEROS, F2),
+ MII_PHY_DESC(xxATHEROS, F1),
+ MII_PHY_DESC(xxATHEROS, F1_7),
+ MII_PHY_DESC(xxATHEROS, F2),
MII_PHY_END
};
+static const struct mii_phy_funcs atphy_funcs = {
+ atphy_service,
+ atphy_status,
+ atphy_reset
+};
+
static int
atphy_probe(device_t dev)
{
@@ -101,41 +100,8 @@ atphy_probe(device_t dev)
static int
atphy_attach(device_t dev)
{
- struct atphy_softc *asc;
- struct mii_softc *sc;
- struct mii_attach_args *ma;
- struct mii_data *mii;
-
- asc = device_get_softc(dev);
- sc = &asc->mii_sc;
- ma = device_get_ivars(dev);
- sc->mii_dev = device_get_parent(dev);
- mii = ma->mii_data;
- LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
-
- sc->mii_flags = miibus_get_flags(dev);
- sc->mii_inst = mii->mii_instance++;
- sc->mii_phy = ma->mii_phyno;
- sc->mii_service = atphy_service;
- sc->mii_pdata = mii;
-
- asc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
- asc->mii_model = MII_MODEL(ma->mii_id2);
- asc->mii_rev = MII_REV(ma->mii_id2);
- if (bootverbose)
- device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n",
- asc->mii_oui, asc->mii_model, asc->mii_rev);
-
- atphy_reset(sc);
-
- sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
- if (sc->mii_capabilities & BMSR_EXTSTAT)
- sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
- device_printf(dev, " ");
- mii_phy_add_media(sc);
- printf("\n");
-
- MIIBUS_MEDIAINIT(sc->mii_dev);
+
+ mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &atphy_funcs, 1);
return (0);
}
@@ -244,7 +210,7 @@ done:
}
/* Update the media status. */
- atphy_status(sc);
+ PHY_STATUS(sc);
/* Callback if something changed. */
mii_phy_update(sc, cmd);
@@ -318,12 +284,9 @@ static void
atphy_reset(struct mii_softc *sc)
{
struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur;
- struct atphy_softc *asc;
uint32_t reg;
int i;
- asc = (struct atphy_softc *)sc;
-
/* Take PHY out of power down mode. */
PHY_WRITE(sc, 29, 0x29);
PHY_WRITE(sc, 30, 0);