Date: Sun, 26 Apr 2015 16:45:00 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r282026 - projects/ifnet/sys/dev/mii Message-ID: <201504261645.t3QGj0KZ031336@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Sun Apr 26 16:44:59 2015 New Revision: 282026 URL: https://svnweb.freebsd.org/changeset/base/282026 Log: Convert miibus(4) to new ifmedia KPI. This requires some changes. o miibus(4) gets rid of interface knowledge entirely. It includes only if_media.h, to get media macros. It doesn't include if.h. o Argument list to mii_attach() is reduced by the function pointers, that now live in ifops. o struct mii_data now stores mii_media, which caches value of currently selected media. XXX: it might be, that mii_media, mii_media_active and mii_media_status can be collapsed into one word, but that's not entirely clear. So take conservative approach. o struct mii_data now stores array of available mediae, accessible by the NIC driver. XXX: since miibus can hold several phys, the array is allocated dynamically. The size of array MII_MAX_MEDIAE might need a bump in future, in case if new phys ever appear. Or a more smart allocation method should be coded. However, it looks like future NICs aren't going to use miibus(4), and definitely aren't going to carry > 1 phys. o phy_status, phy_service and phy_reset now take media as argument, and so do some internal functions. Before, this functions used to take current media from struct ifmedia, and ifmedia_ioctl() used to restore it to previous value, in case of and error. Sponsored by: Netflix Sponsored by: Nginx, Inc. Modified: projects/ifnet/sys/dev/mii/acphy.c projects/ifnet/sys/dev/mii/amphy.c projects/ifnet/sys/dev/mii/atphy.c projects/ifnet/sys/dev/mii/axphy.c projects/ifnet/sys/dev/mii/bmtphy.c projects/ifnet/sys/dev/mii/brgphy.c projects/ifnet/sys/dev/mii/ciphy.c projects/ifnet/sys/dev/mii/e1000phy.c projects/ifnet/sys/dev/mii/gentbi.c projects/ifnet/sys/dev/mii/icsphy.c projects/ifnet/sys/dev/mii/ip1000phy.c projects/ifnet/sys/dev/mii/jmphy.c projects/ifnet/sys/dev/mii/lxtphy.c projects/ifnet/sys/dev/mii/micphy.c projects/ifnet/sys/dev/mii/mii.c projects/ifnet/sys/dev/mii/mii_physubr.c projects/ifnet/sys/dev/mii/miivar.h projects/ifnet/sys/dev/mii/mlphy.c projects/ifnet/sys/dev/mii/nsgphy.c projects/ifnet/sys/dev/mii/nsphy.c projects/ifnet/sys/dev/mii/nsphyter.c projects/ifnet/sys/dev/mii/pnaphy.c projects/ifnet/sys/dev/mii/qsphy.c projects/ifnet/sys/dev/mii/rdcphy.c projects/ifnet/sys/dev/mii/rgephy.c projects/ifnet/sys/dev/mii/rlphy.c projects/ifnet/sys/dev/mii/rlswitch.c projects/ifnet/sys/dev/mii/smcphy.c projects/ifnet/sys/dev/mii/smscphy.c projects/ifnet/sys/dev/mii/tdkphy.c projects/ifnet/sys/dev/mii/tlphy.c projects/ifnet/sys/dev/mii/truephy.c projects/ifnet/sys/dev/mii/ukphy.c projects/ifnet/sys/dev/mii/ukphy_subr.c projects/ifnet/sys/dev/mii/xmphy.c Modified: projects/ifnet/sys/dev/mii/acphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/acphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/acphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -67,7 +67,6 @@ __FBSDID("$FreeBSD$"); #include <sys/module.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -100,9 +99,10 @@ static driver_t acphy_driver = { DRIVER_MODULE(acphy, miibus, acphy_driver, acphy_devclass, 0, 0); -static int acphy_service(struct mii_softc *, struct mii_data *, int); -static void acphy_reset(struct mii_softc *); -static void acphy_status(struct mii_softc *); +static int acphy_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void acphy_reset(struct mii_softc *, if_media_t); +static void acphy_status(struct mii_softc *, if_media_t); static const struct mii_phydesc acphys[] = { MII_PHY_DESC(ALTIMA, AC101), @@ -134,22 +134,22 @@ acphy_attach(device_t dev) mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &acphy_funcs, 0); - PHY_RESET(sc); + PHY_RESET(sc, 0); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; device_printf(dev, " "); -#define ADD(m) ifmedia_add(&sc->mii_pdata->mii_media, (m), 0, NULL) if ((PHY_READ(sc, MII_ACPHY_MCTL) & AC_MCTL_FX_SEL) != 0) { sc->mii_flags |= MIIF_HAVEFIBER; - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst)); + mii_phy_add_media(sc->mii_pdata, IFM_MAKEWORD(IFM_ETHER, + IFM_100_FX, 0, sc->mii_inst)); printf("100baseFX, "); - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst)); + mii_phy_add_media(sc->mii_pdata, IFM_MAKEWORD(IFM_ETHER, + IFM_100_FX, IFM_FDX, sc->mii_inst)); printf("100baseFX-FDX, "); } -#undef ADD - mii_phy_add_media(sc); + mii_phy_generic_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); @@ -157,7 +157,8 @@ acphy_attach(device_t dev) } static int -acphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +acphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { int reg; @@ -171,7 +172,7 @@ acphy_service(struct mii_softc *sc, stru if (reg & (BMCR_ISO | BMCR_PDOWN)) PHY_WRITE(sc, MII_BMCR, reg & ~(BMCR_ISO | BMCR_PDOWN)); - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, media); break; case MII_TICK: @@ -182,7 +183,7 @@ acphy_service(struct mii_softc *sc, stru } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -190,10 +191,9 @@ acphy_service(struct mii_softc *sc, stru } static void -acphy_status(struct mii_softc *sc) +acphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmsr, bmcr, diag; mii->mii_media_status = IFM_AVALID; @@ -232,13 +232,13 @@ acphy_status(struct mii_softc *sc) else mii->mii_media_active |= IFM_HDX; } else - mii->mii_media_active = ife->ifm_media; + mii->mii_media_active = media; } static void -acphy_reset(struct mii_softc *sc) +acphy_reset(struct mii_softc *sc, if_media_t media) { - mii_phy_reset(sc); + mii_phy_reset(sc, media); PHY_WRITE(sc, MII_ACPHY_INT, 0); } Modified: projects/ifnet/sys/dev/mii/amphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/amphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/amphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -79,8 +78,9 @@ static driver_t amphy_driver = { DRIVER_MODULE(amphy, miibus, amphy_driver, amphy_devclass, 0, 0); -static int amphy_service(struct mii_softc *, struct mii_data *, int); -static void amphy_status(struct mii_softc *); +static int amphy_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void amphy_status(struct mii_softc *, if_media_t); static const struct mii_phydesc amphys[] = { MII_PHY_DESC(xxDAVICOM, DM9102), @@ -111,7 +111,8 @@ amphy_attach(device_t dev) } static int -amphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +amphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { switch (cmd) { @@ -119,7 +120,7 @@ amphy_service(struct mii_softc *sc, stru break; case MII_MEDIACHG: - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, media); break; case MII_TICK: @@ -129,7 +130,7 @@ amphy_service(struct mii_softc *sc, stru } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -137,10 +138,9 @@ amphy_service(struct mii_softc *sc, stru } static void -amphy_status(struct mii_softc *sc) +amphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmsr, bmcr, par, anlpar; mii->mii_media_status = IFM_AVALID; @@ -205,5 +205,5 @@ amphy_status(struct mii_softc *sc) if ((mii->mii_media_active & IFM_FDX) != 0) mii->mii_media_active |= mii_phy_flowstatus(sc); } else - mii->mii_media_active = ife->ifm_media; + mii->mii_media_active = media; } Modified: projects/ifnet/sys/dev/mii/atphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/atphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/atphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -71,11 +70,12 @@ static driver_t atphy_driver = { DRIVER_MODULE(atphy, miibus, atphy_driver, atphy_devclass, 0, 0); -static int atphy_service(struct mii_softc *, struct mii_data *, int); -static void atphy_status(struct mii_softc *); -static void atphy_reset(struct mii_softc *); -static uint16_t atphy_anar(struct ifmedia_entry *); -static int atphy_setmedia(struct mii_softc *, int); +static int atphy_service(struct mii_softc *, struct mii_data *, mii_cmd_t, + if_media_t); +static void atphy_status(struct mii_softc *, if_media_t); +static void atphy_reset(struct mii_softc *, if_media_t); +static uint16_t atphy_anar(if_media_t); +static int atphy_setmedia(struct mii_softc *, if_media_t); static const struct mii_phydesc atphys[] = { MII_PHY_DESC(xxATHEROS, F1), @@ -107,9 +107,9 @@ atphy_attach(device_t dev) } static int -atphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +atphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; uint16_t anar, bmcr, bmsr; switch (cmd) { @@ -117,14 +117,14 @@ atphy_service(struct mii_softc *sc, stru break; case MII_MEDIACHG: - if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO || - IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { - atphy_setmedia(sc, ife->ifm_media); + if (IFM_SUBTYPE(media) == IFM_AUTO || + IFM_SUBTYPE(media) == IFM_1000_T) { + atphy_setmedia(sc, media); break; } bmcr = 0; - switch (IFM_SUBTYPE(ife->ifm_media)) { + switch (IFM_SUBTYPE(media)) { case IFM_100_TX: bmcr = BMCR_S100; break; @@ -147,10 +147,10 @@ atphy_service(struct mii_softc *sc, stru return (EINVAL); } - anar = atphy_anar(ife); - if ((ife->ifm_media & IFM_FDX) != 0) { + anar = atphy_anar(media); + if ((media & IFM_FDX) != 0) { bmcr |= BMCR_FDX; - if ((ife->ifm_media & IFM_FLOW) != 0 || + if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) anar |= ANAR_PAUSE_TOWARDS; } @@ -172,7 +172,7 @@ done: /* * Only used for autonegotiation. */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) { + if (IFM_SUBTYPE(media) != IFM_AUTO) { sc->mii_ticks = 0; break; } @@ -194,12 +194,12 @@ done: return (0); sc->mii_ticks = 0; - atphy_setmedia(sc, ife->ifm_media); + atphy_setmedia(sc, media); break; } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -207,7 +207,7 @@ done: } static void -atphy_status(struct mii_softc *sc) +atphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; uint32_t bmsr, bmcr, ssr; @@ -270,9 +270,8 @@ atphy_status(struct mii_softc *sc) } static void -atphy_reset(struct mii_softc *sc) +atphy_reset(struct mii_softc *sc, if_media_t media) { - struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur; uint32_t reg; int i; @@ -292,7 +291,7 @@ atphy_reset(struct mii_softc *sc) PHY_WRITE(sc, ATPHY_SCR, reg); /* Workaround F1 bug to reset phy. */ - atphy_setmedia(sc, ife == NULL ? IFM_AUTO : ife->ifm_media); + atphy_setmedia(sc, media); for (i = 0; i < 1000; i++) { DELAY(1); @@ -302,12 +301,12 @@ atphy_reset(struct mii_softc *sc) } static uint16_t -atphy_anar(struct ifmedia_entry *ife) +atphy_anar(if_media_t media) { uint16_t anar; anar = 0; - switch (IFM_SUBTYPE(ife->ifm_media)) { + switch (IFM_SUBTYPE(media)) { case IFM_AUTO: anar |= ANAR_TX_FD | ANAR_TX | ANAR_10_FD | ANAR_10; return (anar); @@ -323,8 +322,8 @@ atphy_anar(struct ifmedia_entry *ife) return (0); } - if ((ife->ifm_media & IFM_FDX) != 0) { - if (IFM_SUBTYPE(ife->ifm_media) == IFM_100_TX) + if ((media & IFM_FDX) != 0) { + if (IFM_SUBTYPE(media) == IFM_100_TX) anar |= ANAR_TX_FD; else anar |= ANAR_10_FD; @@ -334,7 +333,7 @@ atphy_anar(struct ifmedia_entry *ife) } static int -atphy_setmedia(struct mii_softc *sc, int media) +atphy_setmedia(struct mii_softc *sc, if_media_t media) { uint16_t anar; Modified: projects/ifnet/sys/dev/mii/axphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/axphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/axphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -69,8 +68,9 @@ static driver_t axphy_driver = { DRIVER_MODULE(axphy, miibus, axphy_driver, axphy_devclass, 0, 0); -static int axphy_service(struct mii_softc *, struct mii_data *, int); -static void axphy_status(struct mii_softc *); +static int axphy_service(struct mii_softc *, struct mii_data *, mii_cmd_t, + if_media_t); +static void axphy_status(struct mii_softc *, if_media_t); static const struct mii_phydesc axphys[] = { MII_PHY_DESC(xxASIX, AX88X9X), @@ -99,13 +99,14 @@ axphy_attach(device_t dev) mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE, &axphy_funcs, 1); - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, (IFM_ETHER | IFM_AUTO)); return (0); } static int -axphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +axphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { switch (cmd) { @@ -113,7 +114,7 @@ axphy_service(struct mii_softc *sc, stru break; case MII_MEDIACHG: - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, media); break; case MII_TICK: @@ -123,7 +124,7 @@ axphy_service(struct mii_softc *sc, stru } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -131,10 +132,9 @@ axphy_service(struct mii_softc *sc, stru } static void -axphy_status(struct mii_softc *sc) +axphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmsr, bmcr; mii->mii_media_status = IFM_AVALID; @@ -173,5 +173,5 @@ axphy_status(struct mii_softc *sc) mii->mii_media_active |= IFM_HDX; #endif } else - mii->mii_media_active = ife->ifm_media; + mii->mii_media_active = media; } Modified: projects/ifnet/sys/dev/mii/bmtphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/bmtphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/bmtphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -71,7 +71,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -104,9 +103,10 @@ static driver_t bmtphy_driver = { DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0); -static int bmtphy_service(struct mii_softc *, struct mii_data *, int); -static void bmtphy_status(struct mii_softc *); -static void bmtphy_reset(struct mii_softc *); +static int bmtphy_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void bmtphy_status(struct mii_softc *, if_media_t); +static void bmtphy_reset(struct mii_softc *, if_media_t); static const struct mii_phydesc bmtphys_dp[] = { MII_PHY_DESC(xxBROADCOM, BCM4401), @@ -151,7 +151,8 @@ bmtphy_attach(device_t dev) } static int -bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +bmtphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { switch (cmd) { @@ -159,7 +160,7 @@ bmtphy_service(struct mii_softc *sc, str break; case MII_MEDIACHG: - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, media); break; case MII_TICK: @@ -169,7 +170,7 @@ bmtphy_service(struct mii_softc *sc, str } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -177,14 +178,12 @@ bmtphy_service(struct mii_softc *sc, str } static void -bmtphy_status(struct mii_softc *sc) +bmtphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii; - struct ifmedia_entry *ife; int bmsr, bmcr, aux_csr; mii = sc->mii_pdata; - ife = mii->mii_media.ifm_cur; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; @@ -226,15 +225,15 @@ bmtphy_status(struct mii_softc *sc) else mii->mii_media_active |= IFM_HDX; } else - mii->mii_media_active = ife->ifm_media; + mii->mii_media_active = media; } static void -bmtphy_reset(struct mii_softc *sc) +bmtphy_reset(struct mii_softc *sc, if_media_t media) { u_int16_t data; - mii_phy_reset(sc); + mii_phy_reset(sc, media); if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM_BCM5221) { /* Enable shadow register mode. */ Modified: projects/ifnet/sys/dev/mii/brgphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/brgphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/brgphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -47,8 +47,8 @@ __FBSDID("$FreeBSD$"); #include <sys/bus.h> #include <sys/taskqueue.h> -#include <net/if.h> #include <net/ethernet.h> +#include <net/if.h> /* XXXGL: if_b[cg]ereg.h contamination */ #include <net/if_media.h> #include <dev/mii/mii.h> @@ -97,11 +97,12 @@ static driver_t brgphy_driver = { DRIVER_MODULE(brgphy, miibus, brgphy_driver, brgphy_devclass, 0, 0); -static int brgphy_service(struct mii_softc *, struct mii_data *, int); -static void brgphy_setmedia(struct mii_softc *, int); -static void brgphy_status(struct mii_softc *); -static void brgphy_mii_phy_auto(struct mii_softc *, int); -static void brgphy_reset(struct mii_softc *); +static int brgphy_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void brgphy_setmedia(struct mii_softc *, if_media_t); +static void brgphy_status(struct mii_softc *, if_media_t); +static void brgphy_mii_phy_auto(struct mii_softc *, if_media_t); +static void brgphy_reset(struct mii_softc *, if_media_t); static void brgphy_enable_loopback(struct mii_softc *); static void bcm5401_load_dspcode(struct mii_softc *); static void bcm5411_load_dspcode(struct mii_softc *); @@ -266,7 +267,7 @@ brgphy_attach(device_t dev) break; } - PHY_RESET(sc); + PHY_RESET(sc, 0); /* Read the PHY's capabilities. */ sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; @@ -276,13 +277,12 @@ brgphy_attach(device_t dev) /* Add the supported media types */ if ((sc->mii_flags & MIIF_HAVEFIBER) == 0) { - mii_phy_add_media(sc); + mii_phy_generic_media(sc); printf("\n"); } else { sc->mii_anegticks = MII_ANEGTICKS_GIGE; - ifmedia_add(&sc->mii_pdata->mii_media, - IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, IFM_FDX, sc->mii_inst), - 0, NULL); + mii_phy_add_media(sc->mii_pdata, IFM_MAKEWORD(IFM_ETHER, + IFM_1000_SX, IFM_FDX, sc->mii_inst)); printf("1000baseSX-FDX, "); /* * 2.5G support is a software enabled feature @@ -290,9 +290,9 @@ brgphy_attach(device_t dev) */ if (bce_sc && (bce_sc->bce_phy_flags & BCE_PHY_2_5G_CAPABLE_FLAG)) { - ifmedia_add(&sc->mii_pdata->mii_media, + mii_phy_add_media(sc->mii_pdata, IFM_MAKEWORD(IFM_ETHER, IFM_2500_SX, IFM_FDX, - sc->mii_inst), 0, NULL); + sc->mii_inst)); printf("2500baseSX-FDX, "); } else if ((bsc->serdes_flags & BRGPHY_5708S) && bce_sc && (detect_hs21(bce_sc) != 0)) { @@ -308,8 +308,8 @@ brgphy_attach(device_t dev) printf("auto-neg workaround, "); bsc->serdes_flags |= BRGPHY_NOANWAIT; } - ifmedia_add(&sc->mii_pdata->mii_media, IFM_MAKEWORD(IFM_ETHER, - IFM_AUTO, 0, sc->mii_inst), 0, NULL); + mii_phy_add_media(sc->mii_pdata, IFM_MAKEWORD(IFM_ETHER, + IFM_AUTO, 0, sc->mii_inst)); printf("auto\n"); } @@ -318,9 +318,9 @@ brgphy_attach(device_t dev) } static int -brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +brgphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int val; switch (cmd) { @@ -328,18 +328,18 @@ brgphy_service(struct mii_softc *sc, str break; case MII_MEDIACHG: /* Todo: Why is this here? Is it really needed? */ - PHY_RESET(sc); /* XXX hardware bug work-around */ + PHY_RESET(sc, media); /* XXX hardware bug work-around */ - switch (IFM_SUBTYPE(ife->ifm_media)) { + switch (IFM_SUBTYPE(media)) { case IFM_AUTO: - brgphy_mii_phy_auto(sc, ife->ifm_media); + brgphy_mii_phy_auto(sc, media); break; case IFM_2500_SX: case IFM_1000_SX: case IFM_1000_T: case IFM_100_TX: case IFM_10_T: - brgphy_setmedia(sc, ife->ifm_media); + brgphy_setmedia(sc, media); break; default: return (EINVAL); @@ -347,7 +347,7 @@ brgphy_service(struct mii_softc *sc, str break; case MII_TICK: /* Bail if autoneg isn't in process. */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) { + if (IFM_SUBTYPE(media) != IFM_AUTO) { sc->mii_ticks = 0; break; } @@ -373,12 +373,12 @@ brgphy_service(struct mii_softc *sc, str /* Retry autonegotiation */ sc->mii_ticks = 0; - brgphy_mii_phy_auto(sc, ife->ifm_media); + brgphy_mii_phy_auto(sc, media); break; } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* * Callback if something changed. Note that we need to poke @@ -418,7 +418,7 @@ brgphy_service(struct mii_softc *sc, str /* None */ /****************************************************************************/ static void -brgphy_setmedia(struct mii_softc *sc, int media) +brgphy_setmedia(struct mii_softc *sc, if_media_t media) { int bmcr = 0, gig; @@ -474,7 +474,7 @@ brgphy_setmedia(struct mii_softc *sc, in /* None */ /****************************************************************************/ static void -brgphy_status(struct mii_softc *sc) +brgphy_status(struct mii_softc *sc, if_media_t media) { struct brgphy_softc *bsc = (struct brgphy_softc *)sc; struct mii_data *mii = sc->mii_pdata; @@ -611,7 +611,7 @@ brgphy_mii_phy_auto(struct mii_softc *sc { int anar, ktcr = 0; - PHY_RESET(sc); + PHY_RESET(sc, media); if ((sc->mii_flags & MIIF_HAVEFIBER) == 0) { anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA; @@ -887,7 +887,7 @@ brgphy_jumbo_settings(struct mii_softc * } static void -brgphy_reset(struct mii_softc *sc) +brgphy_reset(struct mii_softc *sc, if_media_t media) { struct bge_softc *bge_sc = NULL; struct bce_softc *bce_sc = NULL; Modified: projects/ifnet/sys/dev/mii/ciphy.c ============================================================================== --- projects/ifnet/sys/dev/mii/ciphy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/ciphy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -79,9 +78,10 @@ static driver_t ciphy_driver = { DRIVER_MODULE(ciphy, miibus, ciphy_driver, ciphy_devclass, 0, 0); -static int ciphy_service(struct mii_softc *, struct mii_data *, int); -static void ciphy_status(struct mii_softc *); -static void ciphy_reset(struct mii_softc *); +static int ciphy_service(struct mii_softc *, struct mii_data *, mii_cmd_t, + if_media_t); +static void ciphy_status(struct mii_softc *, if_media_t); +static void ciphy_reset(struct mii_softc *, if_media_t); static void ciphy_fixup(struct mii_softc *); static const struct mii_phydesc ciphys[] = { @@ -120,9 +120,9 @@ ciphy_attach(device_t dev) } static int -ciphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +ciphy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int reg, speed, gig; switch (cmd) { @@ -132,7 +132,7 @@ ciphy_service(struct mii_softc *sc, stru case MII_MEDIACHG: ciphy_fixup(sc); /* XXX hardware bug work-around */ - switch (IFM_SUBTYPE(ife->ifm_media)) { + switch (IFM_SUBTYPE(media)) { case IFM_AUTO: #ifdef foo /* @@ -141,7 +141,7 @@ ciphy_service(struct mii_softc *sc, stru if (PHY_READ(sc, CIPHY_MII_BMCR) & CIPHY_BMCR_AUTOEN) return (0); #endif - (void)mii_phy_auto(sc); + (void)mii_phy_auto(sc, media); break; case IFM_1000_T: speed = CIPHY_S1000; @@ -152,15 +152,15 @@ ciphy_service(struct mii_softc *sc, stru case IFM_10_T: speed = CIPHY_S10; setit: - if ((ife->ifm_media & IFM_FDX) != 0) { + if ((media & IFM_FDX) != 0) { speed |= CIPHY_BMCR_FDX; gig = CIPHY_1000CTL_AFD; } else gig = CIPHY_1000CTL_AHD; - if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { + if (IFM_SUBTYPE(media) == IFM_1000_T) { gig |= CIPHY_1000CTL_MSE; - if ((ife->ifm_media & IFM_ETH_MASTER) != 0) + if ((media & IFM_ETH_MASTER) != 0) gig |= CIPHY_1000CTL_MSC; speed |= CIPHY_BMCR_AUTOEN | CIPHY_BMCR_STARTNEG; @@ -182,7 +182,7 @@ setit: /* * Only used for autonegotiation. */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) + if (IFM_SUBTYPE(media) != IFM_AUTO) break; /* @@ -204,12 +204,12 @@ setit: break; sc->mii_ticks = 0; - mii_phy_auto(sc); + mii_phy_auto(sc, media); break; } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* * Callback if something changed. Note that we need to poke @@ -225,7 +225,7 @@ setit: } static void -ciphy_status(struct mii_softc *sc) +ciphy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; int bmsr, bmcr; @@ -279,10 +279,10 @@ ciphy_status(struct mii_softc *sc) } static void -ciphy_reset(struct mii_softc *sc) +ciphy_reset(struct mii_softc *sc, if_media_t media) { - mii_phy_reset(sc); + mii_phy_reset(sc, media); DELAY(1000); } Modified: projects/ifnet/sys/dev/mii/e1000phy.c ============================================================================== --- projects/ifnet/sys/dev/mii/e1000phy.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/e1000phy.c Sun Apr 26 16:44:59 2015 (r282026) @@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -82,10 +81,11 @@ static driver_t e1000phy_driver = { DRIVER_MODULE(e1000phy, miibus, e1000phy_driver, e1000phy_devclass, 0, 0); -static int e1000phy_service(struct mii_softc *, struct mii_data *, int); -static void e1000phy_status(struct mii_softc *); -static void e1000phy_reset(struct mii_softc *); -static int e1000phy_mii_phy_auto(struct mii_softc *, int); +static int e1000phy_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void e1000phy_status(struct mii_softc *, if_media_t); +static void e1000phy_reset(struct mii_softc *, if_media_t); +static int e1000phy_mii_phy_auto(struct mii_softc *, if_media_t); static const struct mii_phydesc e1000phys[] = { MII_PHY_DESC(MARVELL, E1000), @@ -163,7 +163,7 @@ e1000phy_attach(device_t dev) break; } - PHY_RESET(sc); + PHY_RESET(sc, 0); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; if (sc->mii_capabilities & BMSR_EXTSTAT) { @@ -173,7 +173,7 @@ e1000phy_attach(device_t dev) sc->mii_flags |= MIIF_HAVE_GTCR; } device_printf(dev, " "); - mii_phy_add_media(sc); + mii_phy_generic_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); @@ -181,7 +181,7 @@ e1000phy_attach(device_t dev) } static void -e1000phy_reset(struct mii_softc *sc) +e1000phy_reset(struct mii_softc *sc, if_media_t media) { uint16_t reg, page; @@ -301,9 +301,9 @@ e1000phy_reset(struct mii_softc *sc) } static int -e1000phy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +e1000phy_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { - struct ifmedia_entry *ife = mii->mii_media.ifm_cur; uint16_t speed, gig; int reg; @@ -312,13 +312,13 @@ e1000phy_service(struct mii_softc *sc, s break; case MII_MEDIACHG: - if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { - e1000phy_mii_phy_auto(sc, ife->ifm_media); + if (IFM_SUBTYPE(media) == IFM_AUTO) { + e1000phy_mii_phy_auto(sc, media); break; } speed = 0; - switch (IFM_SUBTYPE(ife->ifm_media)) { + switch (IFM_SUBTYPE(media)) { case IFM_1000_T: if ((sc->mii_flags & MIIF_HAVE_GTCR) == 0) return (EINVAL); @@ -345,7 +345,7 @@ e1000phy_service(struct mii_softc *sc, s return (EINVAL); } - if ((ife->ifm_media & IFM_FDX) != 0) { + if ((media & IFM_FDX) != 0) { speed |= E1000_CR_FULL_DUPLEX; gig = E1000_1GCR_1000T_FD; } else @@ -355,9 +355,9 @@ e1000phy_service(struct mii_softc *sc, s reg &= ~E1000_CR_AUTO_NEG_ENABLE; PHY_WRITE(sc, E1000_CR, reg | E1000_CR_RESET); - if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { + if (IFM_SUBTYPE(media) == IFM_1000_T) { gig |= E1000_1GCR_MS_ENABLE; - if ((ife->ifm_media & IFM_ETH_MASTER) != 0) + if ((media & IFM_ETH_MASTER) != 0) gig |= E1000_1GCR_MS_VALUE; } else if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) gig = 0; @@ -370,7 +370,7 @@ done: /* * Only used for autonegotiation. */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) { + if (IFM_SUBTYPE(media) != IFM_AUTO) { sc->mii_ticks = 0; break; } @@ -392,13 +392,13 @@ done: break; sc->mii_ticks = 0; - PHY_RESET(sc); - e1000phy_mii_phy_auto(sc, ife->ifm_media); + PHY_RESET(sc, media); + e1000phy_mii_phy_auto(sc, media); break; } /* Update the media status. */ - PHY_STATUS(sc); + PHY_STATUS(sc, media); /* Callback if something changed. */ mii_phy_update(sc, cmd); @@ -406,7 +406,7 @@ done: } static void -e1000phy_status(struct mii_softc *sc) +e1000phy_status(struct mii_softc *sc, if_media_t media) { struct mii_data *mii = sc->mii_pdata; int bmcr, bmsr, ssr; @@ -469,7 +469,7 @@ e1000phy_status(struct mii_softc *sc) } static int -e1000phy_mii_phy_auto(struct mii_softc *sc, int media) +e1000phy_mii_phy_auto(struct mii_softc *sc, if_media_t media) { uint16_t reg; Modified: projects/ifnet/sys/dev/mii/gentbi.c ============================================================================== --- projects/ifnet/sys/dev/mii/gentbi.c Sun Apr 26 16:37:27 2015 (r282025) +++ projects/ifnet/sys/dev/mii/gentbi.c Sun Apr 26 16:44:59 2015 (r282026) @@ -77,7 +77,6 @@ __FBSDID("$FreeBSD$"); #include <sys/errno.h> #include <sys/bus.h> -#include <net/if.h> #include <net/if_media.h> #include <dev/mii/mii.h> @@ -108,8 +107,9 @@ static driver_t gentbi_driver = { DRIVER_MODULE(gentbi, miibus, gentbi_driver, gentbi_devclass, 0, 0); -static int gentbi_service(struct mii_softc *, struct mii_data *, int); -static void gentbi_status(struct mii_softc *); +static int gentbi_service(struct mii_softc *, struct mii_data *, + mii_cmd_t, if_media_t); +static void gentbi_status(struct mii_softc *, if_media_t); static const struct mii_phy_funcs gentbi_funcs = { gentbi_service, @@ -163,7 +163,7 @@ gentbi_attach(device_t dev) mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &gentbi_funcs, 0); - PHY_RESET(sc); + PHY_RESET(sc, 0); /* * Mask out all media in the BMSR. We only are really interested @@ -175,7 +175,7 @@ gentbi_attach(device_t dev) sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); device_printf(dev, " "); - mii_phy_add_media(sc); + mii_phy_generic_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); @@ -183,7 +183,8 @@ gentbi_attach(device_t dev) } static int -gentbi_service(struct mii_softc *sc, struct mii_data *mii, int cmd) +gentbi_service(struct mii_softc *sc, struct mii_data *mii, mii_cmd_t cmd, + if_media_t media) { switch (cmd) { @@ -191,7 +192,7 @@ gentbi_service(struct mii_softc *sc, str break; case MII_MEDIACHG: - mii_phy_setmedia(sc); + mii_phy_setmedia(sc, media); break; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504261645.t3QGj0KZ031336>