svn commit: r277121 - projects/ifnet/sys/dev/mii
Gleb Smirnoff
glebius at FreeBSD.org
Tue Jan 13 08:32:44 UTC 2015
Author: glebius
Date: Tue Jan 13 08:32:41 2015
New Revision: 277121
URL: https://svnweb.freebsd.org/changeset/base/277121
Log:
Make miibus(4) fully ifnet(9) agnostic, removing layering violation.
This allows to mii_attach() in drivers prior to if_attach(), but on the
other hand puts some extra work on drivers.
Drivers now should:
- Do mii_attach() before if_attach().
- Do baudrate management theirselves in miibus_statchg devmethod.
- Do link state management theirselves in miibus_linkchg devmethod.
Some PHYs require to obtain MTU of the interface. Instead of doing it
via ifnet(9) layer, provide new miibus method miibus_readvar. Drivers
that expect such PHYs must implement this method and return IF_MTU.
Sponsored by: Nginx, Inc.
Modified:
projects/ifnet/sys/dev/mii/brgphy.c
projects/ifnet/sys/dev/mii/mii.c
projects/ifnet/sys/dev/mii/miibus_if.m
projects/ifnet/sys/dev/mii/miivar.h
projects/ifnet/sys/dev/mii/truephy.c
Modified: projects/ifnet/sys/dev/mii/brgphy.c
==============================================================================
--- projects/ifnet/sys/dev/mii/brgphy.c Tue Jan 13 08:27:43 2015 (r277120)
+++ projects/ifnet/sys/dev/mii/brgphy.c Tue Jan 13 08:32:41 2015 (r277121)
@@ -40,13 +40,14 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#include <sys/lock.h> /* XXXGL: if_b[cg]ereg.h contamination */
+#include <sys/mutex.h> /* XXXGL: if_b[cg]ereg.h contamination */
#include <sys/module.h>
#include <sys/socket.h>
#include <sys/bus.h>
#include <sys/taskqueue.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/ethernet.h>
#include <net/if_media.h>
@@ -55,7 +56,6 @@ __FBSDID("$FreeBSD$");
#include "miidevs.h"
#include <dev/mii/brgphyreg.h>
-#include <net/if_arp.h>
#include <machine/bus.h>
#include <dev/bge/if_bgereg.h>
#include <dev/bce/if_bcereg.h>
@@ -878,7 +878,7 @@ brgphy_reset(struct mii_softc *sc)
{
struct bge_softc *bge_sc = NULL;
struct bce_softc *bce_sc = NULL;
- if_t ifp;
+ u_int mtu;
int i, val;
/*
@@ -928,7 +928,7 @@ brgphy_reset(struct mii_softc *sc)
return;
}
- ifp = sc->mii_pdata->mii_ifp;
+ mtu = MIIBUS_READVAR(sc->mii_dev, IF_MTU);
/* Find the driver associated with this PHY. */
if (mii_phy_mac_match(sc, "bge"))
@@ -952,7 +952,7 @@ brgphy_reset(struct mii_softc *sc)
brgphy_fixup_jitter_bug(sc);
if (bge_sc->bge_flags & BGE_FLAG_JUMBO)
- brgphy_jumbo_settings(sc, if_getmtu(ifp));
+ brgphy_jumbo_settings(sc, mtu);
if ((bge_sc->bge_phy_flags & BGE_PHY_NO_WIRESPEED) == 0)
brgphy_ethernet_wirespeed(sc);
@@ -1063,11 +1063,11 @@ brgphy_reset(struct mii_softc *sc)
(BCE_CHIP_REV(bce_sc) == BCE_CHIP_REV_Bx))
brgphy_fixup_disable_early_dac(sc);
- brgphy_jumbo_settings(sc, if_getmtu(ifp));
+ brgphy_jumbo_settings(sc, mtu);
brgphy_ethernet_wirespeed(sc);
} else {
brgphy_fixup_ber_bug(sc);
- brgphy_jumbo_settings(sc, if_getmtu(ifp));
+ brgphy_jumbo_settings(sc, mtu);
brgphy_ethernet_wirespeed(sc);
}
}
Modified: projects/ifnet/sys/dev/mii/mii.c
==============================================================================
--- projects/ifnet/sys/dev/mii/mii.c Tue Jan 13 08:27:43 2015 (r277120)
+++ projects/ifnet/sys/dev/mii/mii.c Tue Jan 13 08:32:41 2015 (r277121)
@@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/if_media.h>
#include <dev/mii/mii.h>
@@ -69,6 +68,7 @@ static miibus_readreg_t miibus_readreg;
static miibus_statchg_t miibus_statchg;
static miibus_writereg_t miibus_writereg;
static miibus_linkchg_t miibus_linkchg;
+static miibus_readvar_t miibus_readvar;
static miibus_mediainit_t miibus_mediainit;
static unsigned char mii_bitreverse(unsigned char x);
@@ -92,6 +92,7 @@ static device_method_t miibus_methods[]
DEVMETHOD(miibus_writereg, miibus_writereg),
DEVMETHOD(miibus_statchg, miibus_statchg),
DEVMETHOD(miibus_linkchg, miibus_linkchg),
+ DEVMETHOD(miibus_readvar, miibus_readvar),
DEVMETHOD(miibus_mediainit, miibus_mediainit),
DEVMETHOD_END
@@ -106,7 +107,6 @@ driver_t miibus_driver = {
};
struct miibus_ivars {
- if_t ifp;
ifm_change_cb_t ifmedia_upd;
ifm_stat_cb_t ifmedia_sts;
u_int mii_flags;
@@ -146,9 +146,6 @@ miibus_attach(device_t dev)
ivars = device_get_ivars(dev);
ifmedia_init(&mii->mii_media, IFM_IMASK, ivars->ifmedia_upd,
ivars->ifmedia_sts);
- mii->mii_ifp = ivars->ifp;
- if_setcapabilitiesbit(mii->mii_ifp, IFCAP_LINKSTATE, 0);
- if_setcapenablebit(mii->mii_ifp, IFCAP_LINKSTATE, 0);
LIST_INIT(&mii->mii_phys);
return (bus_generic_attach(dev));
@@ -162,7 +159,6 @@ miibus_detach(device_t dev)
bus_generic_detach(dev);
mii = device_get_softc(dev);
ifmedia_removeall(&mii->mii_media);
- mii->mii_ifp = NULL;
return (0);
}
@@ -280,57 +276,42 @@ miibus_hinted_child(device_t dev, const
ma->mii_capmask = val;
}
+/*
+ * The miibus just relays most devmethods to the parent.
+ */
static int
miibus_readreg(device_t dev, int phy, int reg)
{
- device_t parent;
- parent = device_get_parent(dev);
- return (MIIBUS_READREG(parent, phy, reg));
+ return (MIIBUS_READREG(device_get_parent(dev), phy, reg));
}
static int
miibus_writereg(device_t dev, int phy, int reg, int data)
{
- device_t parent;
- parent = device_get_parent(dev);
- return (MIIBUS_WRITEREG(parent, phy, reg, data));
+ return (MIIBUS_WRITEREG(device_get_parent(dev), phy, reg, data));
}
static void
miibus_statchg(device_t dev)
{
- device_t parent;
- struct mii_data *mii;
- parent = device_get_parent(dev);
- MIIBUS_STATCHG(parent);
-
- mii = device_get_softc(dev);
- if_setbaudrate(mii->mii_ifp, ifmedia_baudrate(mii->mii_media_active));
+ MIIBUS_STATCHG(device_get_parent(dev));
}
static void
miibus_linkchg(device_t dev)
{
- struct mii_data *mii;
- device_t parent;
- int link_state;
- parent = device_get_parent(dev);
- MIIBUS_LINKCHG(parent);
+ MIIBUS_LINKCHG(device_get_parent(dev));
+}
- mii = device_get_softc(dev);
+static uint64_t
+miibus_readvar(device_t dev, int var)
+{
- if (mii->mii_media_status & IFM_AVALID) {
- if (mii->mii_media_status & IFM_ACTIVE)
- link_state = LINK_STATE_UP;
- else
- link_state = LINK_STATE_DOWN;
- } else
- link_state = LINK_STATE_UNKNOWN;
- if_link_state_change(mii->mii_ifp, link_state);
+ return (MIIBUS_READVAR(device_get_parent(dev), var));
}
static void
@@ -358,9 +339,8 @@ miibus_mediainit(device_t dev)
* the PHYs to the network interface driver parent.
*/
int
-mii_attach(device_t dev, device_t *miibus, if_t ifp,
- ifm_change_cb_t ifmedia_upd, ifm_stat_cb_t ifmedia_sts, int capmask,
- int phyloc, int offloc, int flags)
+mii_attach(device_t dev, device_t *miibus, ifm_change_cb_t ifmedia_upd,
+ ifm_stat_cb_t ifmedia_sts, int capmask, int phyloc, int offloc, int flags)
{
struct miibus_ivars *ivars;
struct mii_attach_args *args, ma;
@@ -395,7 +375,6 @@ mii_attach(device_t dev, device_t *miibu
ivars = malloc(sizeof(*ivars), M_DEVBUF, M_NOWAIT);
if (ivars == NULL)
return (ENOMEM);
- ivars->ifp = ifp;
ivars->ifmedia_upd = ifmedia_upd;
ivars->ifmedia_sts = ifmedia_sts;
ivars->mii_flags = flags;
@@ -407,7 +386,7 @@ mii_attach(device_t dev, device_t *miibu
device_set_ivars(*miibus, ivars);
} else {
ivars = device_get_ivars(*miibus);
- if (ivars->ifp != ifp || ivars->ifmedia_upd != ifmedia_upd ||
+ if (ivars->ifmedia_upd != ifmedia_upd ||
ivars->ifmedia_sts != ifmedia_sts ||
ivars->mii_flags != flags) {
printf("%s: non-matching invariant\n", __func__);
Modified: projects/ifnet/sys/dev/mii/miibus_if.m
==============================================================================
--- projects/ifnet/sys/dev/mii/miibus_if.m Tue Jan 13 08:27:43 2015 (r277120)
+++ projects/ifnet/sys/dev/mii/miibus_if.m Tue Jan 13 08:32:41 2015 (r277121)
@@ -38,6 +38,14 @@ METHOD void linkchg {
};
#
+# Read software configuration data from device on MII bus.
+#
+METHOD uint64_t readvar {
+ device_t dev;
+ int var;
+};
+
+#
# Notify bus that media has been set.
#
METHOD void mediainit {
Modified: projects/ifnet/sys/dev/mii/miivar.h
==============================================================================
--- projects/ifnet/sys/dev/mii/miivar.h Tue Jan 13 08:27:43 2015 (r277120)
+++ projects/ifnet/sys/dev/mii/miivar.h Tue Jan 13 08:32:41 2015 (r277121)
@@ -36,7 +36,6 @@
#define _DEV_MII_MIIVAR_H_
#include <sys/queue.h>
-#include <net/if_var.h> /* XXX driver API temporary */
/*
* Media Independent Interface data structure defintions
@@ -51,7 +50,6 @@ struct mii_softc;
*/
struct mii_data {
struct ifmedia mii_media; /* media information */
- if_t mii_ifp; /* pointer back to network interface */
/*
* For network interfaces with multiple PHYs, a list of all
@@ -233,8 +231,8 @@ MIIBUS_ACCESSOR(flags, FLAGS, u_int)
extern devclass_t miibus_devclass;
extern driver_t miibus_driver;
-int mii_attach(device_t, device_t *, if_t, ifm_change_cb_t,
- ifm_stat_cb_t, int, int, int, int);
+int mii_attach(device_t, device_t *, ifm_change_cb_t, ifm_stat_cb_t,
+ int, int, int, int);
void mii_down(struct mii_data *);
int mii_mediachg(struct mii_data *);
void mii_tick(struct mii_data *);
Modified: projects/ifnet/sys/dev/mii/truephy.c
==============================================================================
--- projects/ifnet/sys/dev/mii/truephy.c Tue Jan 13 08:27:43 2015 (r277120)
+++ projects/ifnet/sys/dev/mii/truephy.c Tue Jan 13 08:32:41 2015 (r277121)
@@ -44,11 +44,8 @@
#include <sys/bus.h>
#include <net/if.h>
-#include <net/if_var.h>
#include <net/if_media.h>
-#include <net/if_arp.h>
#include <net/ethernet.h>
-#include <net/if_vlan_var.h>
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
@@ -261,7 +258,7 @@ truephy_reset(struct mii_softc *sc)
mii_phy_reset(sc);
- if (TRUEPHY_FRAMELEN((if_getmtu(sc->mii_pdata->mii_ifp)) > 2048)) {
+ if (TRUEPHY_FRAMELEN((MIIBUS_READVAR(sc->mii_dev, IF_MTU)) > 2048)) {
int conf;
conf = PHY_READ(sc, TRUEPHY_CONF);
More information about the svn-src-projects
mailing list