svn commit: r266974 - in head/sys: dev/dc dev/fxp dev/mii dev/netmap kern net
Adrian Chadd
adrian at freebsd.org
Mon Jun 2 18:26:11 UTC 2014
Woo!
Would you mind doing up a 30 second "what convert X to Y" document so
I can do the driveby on the wireless stack and drivers?
I'll look at the script but since the wifi stack sits in between the
normal network stack layering, I just want to make sure I get all of
the right bits converted over all at the same time and have it have a
good chance of working.
Thanks!
-a
On 2 June 2014 10:54, Marcel Moolenaar <marcel at freebsd.org> wrote:
> Author: marcel
> Date: Mon Jun 2 17:54:39 2014
> New Revision: 266974
> URL: http://svnweb.freebsd.org/changeset/base/266974
>
> Log:
> Introduce a procedural interface to the ifnet structure. The new
> interface allows the ifnet structure to be defined as an opaque
> type in NIC drivers. This then allows the ifnet structure to be
> changed without a need to change or recompile NIC drivers.
>
> Put differently, NIC drivers can be written and compiled once and
> be used with different network stack implementations, provided of
> course that those network stack implementations have an API and
> ABI compatible interface.
>
> This commit introduces the 'if_t' type to replace 'struct ifnet *'
> as the type of a network interface. The 'if_t' type is defined as
> 'void *' to enable the compiler to perform type conversion to
> 'struct ifnet *' and vice versa where needed and without warnings.
> The functions that implement the API are the only functions that
> need to have an explicit cast.
>
> The MII code has been converted to use the driver API to avoid
> unnecessary code churn. Code churn comes from having to work with
> both converted and unconverted drivers in correlation with having
> callback functions that take an interface. By converting the MII
> code first, the callback functions can be defined so that the
> compiler will perform the typecasts automatically.
>
> As soon as all drivers have been converted, the if_t type can be
> redefined as needed and the API functions can be fix to not need
> an explicit cast.
>
> The immediate benefactors of this change are:
> 1. Juniper Networks - The network stack implementation in Junos
> is entirely different from FreeBSD's one and this change
> allows Juniper to build "stock" NIC drivers that can be used
> in combination with both the FreeBSD and Junos stacks.
> 2. FreeBSD - This change opens the door towards changing ifnet
> and implementing new features and optimizations in the network
> stack without it requiring a change in the many NIC drivers
> FreeBSD has.
>
> Submitted by: Anuranjan Shukla <anshukla at juniper.net>
> Reviewed by: glebius@
> Obtained from: Juniper Networks, Inc.
>
> Modified:
> head/sys/dev/dc/dcphy.c
> head/sys/dev/dc/pnphy.c
> head/sys/dev/fxp/inphy.c
> head/sys/dev/mii/brgphy.c
> head/sys/dev/mii/e1000phy.c
> head/sys/dev/mii/ip1000phy.c
> head/sys/dev/mii/jmphy.c
> head/sys/dev/mii/mii.c
> head/sys/dev/mii/miivar.h
> head/sys/dev/mii/nsphy.c
> head/sys/dev/mii/rgephy.c
> head/sys/dev/mii/truephy.c
> head/sys/dev/netmap/netmap_generic.c
> head/sys/dev/netmap/netmap_kern.h
> head/sys/kern/kern_poll.c
> head/sys/net/if.c
> head/sys/net/if_media.h
> head/sys/net/if_var.h
> head/sys/net/ifq.h
>
> Modified: head/sys/dev/dc/dcphy.c
> ==============================================================================
> --- head/sys/dev/dc/dcphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/dc/dcphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -153,7 +153,7 @@ dcphy_attach(device_t dev)
> &dcphy_funcs, 0);
>
> /*PHY_RESET(sc);*/
> - dc_sc = sc->mii_pdata->mii_ifp->if_softc;
> + dc_sc = if_getsoftc(sc->mii_pdata->mii_ifp);
> CSR_WRITE_4(dc_sc, DC_10BTSTAT, 0);
> CSR_WRITE_4(dc_sc, DC_10BTCTRL, 0);
>
> @@ -191,7 +191,7 @@ dcphy_service(struct mii_softc *sc, stru
> int reg;
> u_int32_t mode;
>
> - dc_sc = mii->mii_ifp->if_softc;
> + dc_sc = if_getsoftc(mii->mii_ifp);
>
> switch (cmd) {
> case MII_POLLSTAT:
> @@ -201,7 +201,7 @@ dcphy_service(struct mii_softc *sc, stru
> /*
> * If the interface is not up, don't do anything.
> */
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> break;
>
> mii->mii_media_active = IFM_NONE;
> @@ -251,7 +251,7 @@ dcphy_service(struct mii_softc *sc, stru
> /*
> * Is the interface even up?
> */
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> return (0);
>
> /*
> @@ -298,12 +298,12 @@ dcphy_status(struct mii_softc *sc)
> int anlpar, tstat;
> struct dc_softc *dc_sc;
>
> - dc_sc = mii->mii_ifp->if_softc;
> + dc_sc = if_getsoftc(mii->mii_ifp);
>
> mii->mii_media_status = IFM_AVALID;
> mii->mii_media_active = IFM_ETHER;
>
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> return;
>
> tstat = CSR_READ_4(dc_sc, DC_10BTSTAT);
> @@ -378,7 +378,7 @@ dcphy_auto(struct mii_softc *mii)
> {
> struct dc_softc *sc;
>
> - sc = mii->mii_pdata->mii_ifp->if_softc;
> + sc = if_getsoftc(mii->mii_pdata->mii_ifp);
>
> DC_CLRBIT(sc, DC_NETCFG, DC_NETCFG_PORTSEL);
> DC_SETBIT(sc, DC_NETCFG, DC_NETCFG_FULLDUPLEX);
> @@ -399,7 +399,7 @@ dcphy_reset(struct mii_softc *mii)
> {
> struct dc_softc *sc;
>
> - sc = mii->mii_pdata->mii_ifp->if_softc;
> + sc = if_getsoftc(mii->mii_pdata->mii_ifp);
>
> DC_CLRBIT(sc, DC_SIARESET, DC_SIA_RESET);
> DELAY(1000);
>
> Modified: head/sys/dev/dc/pnphy.c
> ==============================================================================
> --- head/sys/dev/dc/pnphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/dc/pnphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -152,7 +152,7 @@ pnphy_service(struct mii_softc *sc, stru
> /*
> * If the interface is not up, don't do anything.
> */
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> break;
>
> /*
> @@ -180,7 +180,7 @@ pnphy_service(struct mii_softc *sc, stru
> /*
> * Is the interface even up?
> */
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> return (0);
>
> break;
> @@ -201,7 +201,7 @@ pnphy_status(struct mii_softc *sc)
> int reg;
> struct dc_softc *dc_sc;
>
> - dc_sc = mii->mii_ifp->if_softc;
> + dc_sc = if_getsoftc(mii->mii_ifp);
>
> mii->mii_media_status = IFM_AVALID;
> mii->mii_media_active = IFM_ETHER;
>
> Modified: head/sys/dev/fxp/inphy.c
> ==============================================================================
> --- head/sys/dev/fxp/inphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/fxp/inphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -122,7 +122,7 @@ inphy_service(struct mii_softc *sc, stru
> /*
> * If the interface is not up, don't do anything.
> */
> - if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
> + if ((if_getflags(mii->mii_ifp) & IFF_UP) == 0)
> break;
>
> mii_phy_setmedia(sc);
>
> Modified: head/sys/dev/mii/brgphy.c
> ==============================================================================
> --- head/sys/dev/mii/brgphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/brgphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
> #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>
> @@ -197,7 +198,7 @@ brgphy_attach(device_t dev)
> struct bge_softc *bge_sc = NULL;
> struct bce_softc *bce_sc = NULL;
> struct mii_softc *sc;
> - struct ifnet *ifp;
> + if_t ifp;
>
> bsc = device_get_softc(dev);
> sc = &bsc->mii_sc;
> @@ -209,10 +210,10 @@ brgphy_attach(device_t dev)
> ifp = sc->mii_pdata->mii_ifp;
>
> /* Find the MAC driver associated with this PHY. */
> - if (strcmp(ifp->if_dname, "bge") == 0)
> - bge_sc = ifp->if_softc;
> - else if (strcmp(ifp->if_dname, "bce") == 0)
> - bce_sc = ifp->if_softc;
> + if (strcmp(if_getdname(ifp), "bge") == 0)
> + bge_sc = if_getsoftc(ifp);
> + else if (strcmp(if_getdname(ifp), "bce") == 0)
> + bce_sc = if_getsoftc(ifp);
>
> /* Handle any special cases based on the PHY ID */
> switch (sc->mii_mpd_oui) {
> @@ -879,7 +880,7 @@ brgphy_reset(struct mii_softc *sc)
> {
> struct bge_softc *bge_sc = NULL;
> struct bce_softc *bce_sc = NULL;
> - struct ifnet *ifp;
> + if_t ifp;
> int i, val;
>
> /*
> @@ -932,10 +933,10 @@ brgphy_reset(struct mii_softc *sc)
> ifp = sc->mii_pdata->mii_ifp;
>
> /* Find the driver associated with this PHY. */
> - if (strcmp(ifp->if_dname, "bge") == 0) {
> - bge_sc = ifp->if_softc;
> - } else if (strcmp(ifp->if_dname, "bce") == 0) {
> - bce_sc = ifp->if_softc;
> + if (strcmp(if_getdname(ifp), "bge") == 0) {
> + bge_sc = if_getsoftc(ifp);
> + } else if (strcmp(if_getdname(ifp), "bce") == 0) {
> + bce_sc = if_getsoftc(ifp);
> }
>
> if (bge_sc) {
> @@ -954,7 +955,7 @@ brgphy_reset(struct mii_softc *sc)
> brgphy_fixup_jitter_bug(sc);
>
> if (bge_sc->bge_flags & BGE_FLAG_JUMBO)
> - brgphy_jumbo_settings(sc, ifp->if_mtu);
> + brgphy_jumbo_settings(sc, if_getmtu(ifp));
>
> if ((bge_sc->bge_phy_flags & BGE_PHY_NO_WIRESPEED) == 0)
> brgphy_ethernet_wirespeed(sc);
> @@ -1065,11 +1066,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, ifp->if_mtu);
> + brgphy_jumbo_settings(sc, if_getmtu(ifp));
> brgphy_ethernet_wirespeed(sc);
> } else {
> brgphy_fixup_ber_bug(sc);
> - brgphy_jumbo_settings(sc, ifp->if_mtu);
> + brgphy_jumbo_settings(sc, if_getmtu(ifp));
> brgphy_ethernet_wirespeed(sc);
> }
> }
>
> Modified: head/sys/dev/mii/e1000phy.c
> ==============================================================================
> --- head/sys/dev/mii/e1000phy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/e1000phy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -132,14 +132,14 @@ static int
> e1000phy_attach(device_t dev)
> {
> struct mii_softc *sc;
> - struct ifnet *ifp;
> + if_t ifp;
>
> sc = device_get_softc(dev);
>
> mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &e1000phy_funcs, 0);
>
> ifp = sc->mii_pdata->mii_ifp;
> - if (strcmp(ifp->if_dname, "msk") == 0 &&
> + if (strcmp(if_getdname(ifp), "msk") == 0 &&
> (sc->mii_flags & MIIF_MACPRIV0) != 0)
> sc->mii_flags |= MIIF_PHYPRIV0;
>
>
> Modified: head/sys/dev/mii/ip1000phy.c
> ==============================================================================
> --- head/sys/dev/mii/ip1000phy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/ip1000phy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
> #include <sys/kernel.h>
> #include <sys/module.h>
> #include <sys/socket.h>
> +#include <sys/taskqueue.h>
> #include <sys/bus.h>
>
> #include <net/if.h>
> @@ -109,7 +110,7 @@ ip1000phy_attach(device_t dev)
> ma = device_get_ivars(dev);
> flags = MIIF_NOISOLATE | MIIF_NOMANPAUSE;
> if (MII_MODEL(ma->mii_id2) == MII_MODEL_xxICPLUS_IP1000A &&
> - strcmp(ma->mii_data->mii_ifp->if_dname, "stge") == 0 &&
> + strcmp(if_getdname(ma->mii_data->mii_ifp), "stge") == 0 &&
> (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
> flags |= MIIF_PHYPRIV0;
> mii_phy_dev_attach(dev, flags, &ip1000phy_funcs, 1);
>
> Modified: head/sys/dev/mii/jmphy.c
> ==============================================================================
> --- head/sys/dev/mii/jmphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/jmphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -105,7 +105,7 @@ jmphy_attach(device_t dev)
>
> ma = device_get_ivars(dev);
> flags = 0;
> - if (strcmp(ma->mii_data->mii_ifp->if_dname, "jme") == 0 &&
> + if (strcmp(if_getdname(ma->mii_data->mii_ifp), "jme") == 0 &&
> (miibus_get_flags(dev) & MIIF_MACPRIV0) != 0)
> flags |= MIIF_PHYPRIV0;
> mii_phy_dev_attach(dev, flags, &jmphy_funcs, 1);
>
> Modified: head/sys/dev/mii/mii.c
> ==============================================================================
> --- head/sys/dev/mii/mii.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/mii.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -106,7 +106,7 @@ driver_t miibus_driver = {
> };
>
> struct miibus_ivars {
> - struct ifnet *ifp;
> + if_t ifp;
> ifm_change_cb_t ifmedia_upd;
> ifm_stat_cb_t ifmedia_sts;
> u_int mii_flags;
> @@ -147,8 +147,8 @@ miibus_attach(device_t dev)
> ifmedia_init(&mii->mii_media, IFM_IMASK, ivars->ifmedia_upd,
> ivars->ifmedia_sts);
> mii->mii_ifp = ivars->ifp;
> - mii->mii_ifp->if_capabilities |= IFCAP_LINKSTATE;
> - mii->mii_ifp->if_capenable |= IFCAP_LINKSTATE;
> + 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));
> @@ -308,7 +308,7 @@ miibus_statchg(device_t dev)
> MIIBUS_STATCHG(parent);
>
> mii = device_get_softc(dev);
> - mii->mii_ifp->if_baudrate = ifmedia_baudrate(mii->mii_media_active);
> + if_setbaudrate(mii->mii_ifp, ifmedia_baudrate(mii->mii_media_active));
> }
>
> static void
> @@ -330,7 +330,7 @@ miibus_linkchg(device_t dev)
> link_state = LINK_STATE_DOWN;
> } else
> link_state = LINK_STATE_UNKNOWN;
> - if_link_state_change(mii->mii_ifp, link_state);
> + if_linkstate_change_drv(mii->mii_ifp, link_state);
> }
>
> static void
> @@ -358,7 +358,7 @@ miibus_mediainit(device_t dev)
> * the PHYs to the network interface driver parent.
> */
> int
> -mii_attach(device_t dev, device_t *miibus, struct ifnet *ifp,
> +mii_attach(device_t dev, device_t *miibus, void *ifp,
> ifm_change_cb_t ifmedia_upd, ifm_stat_cb_t ifmedia_sts, int capmask,
> int phyloc, int offloc, int flags)
> {
>
> Modified: head/sys/dev/mii/miivar.h
> ==============================================================================
> --- head/sys/dev/mii/miivar.h Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/miivar.h Mon Jun 2 17:54:39 2014 (r266974)
> @@ -36,6 +36,7 @@
> #define _DEV_MII_MIIVAR_H_
>
> #include <sys/queue.h>
> +#include <net/if_var.h> /* XXX driver API temporary */
>
> /*
> * Media Independent Interface data structure defintions
> @@ -57,7 +58,7 @@ typedef void (*mii_statchg_t)(struct dev
> */
> struct mii_data {
> struct ifmedia mii_media; /* media information */
> - struct ifnet *mii_ifp; /* pointer back to network interface */
> + if_t mii_ifp; /* pointer back to network interface */
>
> /*
> * For network interfaces with multiple PHYs, a list of all
> @@ -246,7 +247,7 @@ MIIBUS_ACCESSOR(flags, FLAGS, u_int)
> extern devclass_t miibus_devclass;
> extern driver_t miibus_driver;
>
> -int mii_attach(device_t, device_t *, struct ifnet *, ifm_change_cb_t,
> +int mii_attach(device_t, device_t *, if_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 *);
>
> Modified: head/sys/dev/mii/nsphy.c
> ==============================================================================
> --- head/sys/dev/mii/nsphy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/nsphy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -186,7 +186,7 @@ nsphy_service(struct mii_softc *sc, stru
> */
> reg |= 0x0100 | 0x0400;
>
> - if (strcmp(mii->mii_ifp->if_dname, "fxp") == 0)
> + if (strcmp(if_getdname(mii->mii_ifp), "fxp") == 0)
> PHY_WRITE(sc, MII_NSPHY_PCR, reg);
>
> mii_phy_setmedia(sc);
>
> Modified: head/sys/dev/mii/rgephy.c
> ==============================================================================
> --- head/sys/dev/mii/rgephy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/rgephy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
> #include <sys/kernel.h>
> #include <sys/module.h>
> #include <sys/socket.h>
> +#include <sys/taskqueue.h>
> #include <sys/bus.h>
>
> #include <net/if.h>
> @@ -118,7 +119,7 @@ rgephy_attach(device_t dev)
> sc = device_get_softc(dev);
> ma = device_get_ivars(dev);
> flags = 0;
> - if (strcmp(ma->mii_data->mii_ifp->if_dname, "re") == 0)
> + if (strcmp(if_getdname(ma->mii_data->mii_ifp), "re") == 0)
> flags |= MIIF_PHYPRIV0;
> mii_phy_dev_attach(dev, flags, &rgephy_funcs, 0);
>
>
> Modified: head/sys/dev/mii/truephy.c
> ==============================================================================
> --- head/sys/dev/mii/truephy.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/mii/truephy.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -265,7 +265,7 @@ truephy_reset(struct mii_softc *sc)
>
> mii_phy_reset(sc);
>
> - if (TRUEPHY_FRAMELEN(sc->mii_pdata->mii_ifp->if_mtu) > 2048) {
> + if (TRUEPHY_FRAMELEN((if_getmtu(sc->mii_pdata->mii_ifp)) > 2048)) {
> int conf;
>
> conf = PHY_READ(sc, TRUEPHY_CONF);
>
> Modified: head/sys/dev/netmap/netmap_generic.c
> ==============================================================================
> --- head/sys/dev/netmap/netmap_generic.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/netmap/netmap_generic.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -804,3 +804,9 @@ generic_netmap_attach(struct ifnet *ifp)
>
> return retval;
> }
> +
> +struct netmap_adapter *
> +netmap_getna(if_t ifp)
> +{
> + return (NA((struct ifnet *)ifp));
> +}
>
> Modified: head/sys/dev/netmap/netmap_kern.h
> ==============================================================================
> --- head/sys/dev/netmap/netmap_kern.h Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/dev/netmap/netmap_kern.h Mon Jun 2 17:54:39 2014 (r266974)
> @@ -1262,6 +1262,7 @@ void netmap_catch_tx(struct netmap_gener
> int generic_xmit_frame(struct ifnet *ifp, struct mbuf *m, void *addr, u_int len, u_int ring_nr);
> int generic_find_num_desc(struct ifnet *ifp, u_int *tx, u_int *rx);
> void generic_find_num_queues(struct ifnet *ifp, u_int *txq, u_int *rxq);
> +struct netmap_adapter *netmap_getna(if_t ifp);
>
> /*
> * netmap_mitigation API. This is used by the generic adapter
> @@ -1376,5 +1377,4 @@ void bdg_mismatch_datapath(struct netmap
> struct netmap_vp_adapter *dst_na,
> struct nm_bdg_fwd *ft_p, struct netmap_ring *ring,
> u_int *j, u_int lim, u_int *howmany);
> -
> #endif /* _NET_NETMAP_KERN_H_ */
>
> Modified: head/sys/kern/kern_poll.c
> ==============================================================================
> --- head/sys/kern/kern_poll.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/kern/kern_poll.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -451,6 +451,19 @@ netisr_poll(void)
> mtx_unlock(&poll_mtx);
> }
>
> +/* The following should be temporary, till all drivers use the driver API */
> +int
> +ether_poll_register_drv(poll_handler_drv_t *h, if_t ifh)
> +{
> + return (ether_poll_register((poll_handler_t *)h, (struct ifnet *)ifh));
> +}
> +
> +int
> +ether_poll_deregister_drv(if_t ifh)
> +{
> + return (ether_poll_deregister((struct ifnet *)ifh));
> +}
> +
> /*
> * Try to register routine for polling. Returns 0 if successful
> * (and polling should be enabled), error code otherwise.
>
> Modified: head/sys/net/if.c
> ==============================================================================
> --- head/sys/net/if.c Mon Jun 2 17:34:08 2014 (r266973)
> +++ head/sys/net/if.c Mon Jun 2 17:54:39 2014 (r266974)
> @@ -63,12 +63,16 @@
> #include <machine/stdarg.h>
> #include <vm/uma.h>
>
> +#include <net/bpf.h>
> +#include <net/ethernet.h>
> #include <net/if.h>
> #include <net/if_arp.h>
> #include <net/if_clone.h>
> #include <net/if_dl.h>
> #include <net/if_types.h>
> #include <net/if_var.h>
> +#include <net/if_media.h>
> +#include <net/if_vlan_var.h>
> #include <net/radix.h>
> #include <net/route.h>
> #include <net/vnet.h>
> @@ -1400,17 +1404,17 @@ if_addr_runlock(struct ifnet *ifp)
> }
>
> void
> -if_maddr_rlock(struct ifnet *ifp)
> +if_maddr_rlock(if_t ifp)
> {
>
> - IF_ADDR_RLOCK(ifp);
> + IF_ADDR_RLOCK((struct ifnet *)ifp);
> }
>
> void
> -if_maddr_runlock(struct ifnet *ifp)
> +if_maddr_runlock(if_t ifp)
> {
>
> - IF_ADDR_RUNLOCK(ifp);
> + IF_ADDR_RUNLOCK((struct ifnet *)ifp);
> }
>
> /*
> @@ -3461,3 +3465,644 @@ if_deregister_com_alloc(u_char type)
> if_com_alloc[type] = NULL;
> if_com_free[type] = NULL;
> }
> +
> +/* API for driver access to network stack owned ifnet.*/
> +uint64_t
> +if_setbaudrate(void *arg, uint64_t baudrate)
> +{
> + struct ifnet *ifp = arg;
> + uint64_t oldbrate;
> +
> + oldbrate = ifp->if_baudrate;
> + ifp->if_baudrate = baudrate;
> + return (oldbrate);
> +}
> +
> +uint64_t
> +if_getbaudrate(if_t ifp)
> +{
> +
> + return (((struct ifnet *)ifp)->if_baudrate);
> +}
> +
> +int
> +if_setcapabilities(if_t ifp, int capabilities)
> +{
> + ((struct ifnet *)ifp)->if_capabilities = capabilities;
> + return (0);
> +}
> +
> +int
> +if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit)
> +{
> + ((struct ifnet *)ifp)->if_capabilities |= setbit;
> + ((struct ifnet *)ifp)->if_capabilities &= ~clearbit;
> +
> + return (0);
> +}
> +
> +int
> +if_getcapabilities(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_capabilities;
> +}
> +
> +int
> +if_setcapenable(if_t ifp, int capabilities)
> +{
> + ((struct ifnet *)ifp)->if_capenable = capabilities;
> + return (0);
> +}
> +
> +int
> +if_setcapenablebit(if_t ifp, int setcap, int clearcap)
> +{
> + if(setcap)
> + ((struct ifnet *)ifp)->if_capenable |= setcap;
> + if(clearcap)
> + ((struct ifnet *)ifp)->if_capenable &= ~clearcap;
> +
> + return (0);
> +}
> +
> +const char *
> +if_getdname(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_dname;
> +}
> +
> +int
> +if_togglecapenable(if_t ifp, int togglecap)
> +{
> + ((struct ifnet *)ifp)->if_capenable ^= togglecap;
> + return (0);
> +}
> +
> +int
> +if_getcapenable(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_capenable;
> +}
> +
> +/*
> + * This is largely undesirable because it ties ifnet to a device, but does
> + * provide flexiblity for an embedded product vendor. Should be used with
> + * the understanding that it violates the interface boundaries, and should be
> + * a last resort only.
> + */
> +int
> +if_setdev(if_t ifp, void *dev)
> +{
> + return (0);
> +}
> +
> +int
> +if_setdrvflagbits(if_t ifp, int set_flags, int clear_flags)
> +{
> + ((struct ifnet *)ifp)->if_drv_flags |= set_flags;
> + ((struct ifnet *)ifp)->if_drv_flags &= ~clear_flags;
> +
> + return (0);
> +}
> +
> +int
> +if_getdrvflags(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_drv_flags;
> +}
> +
> +int
> +if_setdrvflags(if_t ifp, int flags)
> +{
> + ((struct ifnet *)ifp)->if_drv_flags = flags;
> + return (0);
> +}
> +
> +
> +int
> +if_setflags(if_t ifp, int flags)
> +{
> + ((struct ifnet *)ifp)->if_flags = flags;
> + return (0);
> +}
> +
> +int
> +if_setflagbits(if_t ifp, int set, int clear)
> +{
> + ((struct ifnet *)ifp)->if_flags |= set;
> + ((struct ifnet *)ifp)->if_flags &= ~clear;
> +
> + return (0);
> +}
> +
> +int
> +if_getflags(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_flags;
> +}
> +
> +int
> +if_clearhwassist(if_t ifp)
> +{
> + ((struct ifnet *)ifp)->if_hwassist = 0;
> + return (0);
> +}
> +
> +int
> +if_sethwassistbits(if_t ifp, int toset, int toclear)
> +{
> + ((struct ifnet *)ifp)->if_hwassist |= toset;
> + ((struct ifnet *)ifp)->if_hwassist &= ~toclear;
> +
> + return (0);
> +}
> +
> +int
> +if_sethwassist(if_t ifp, int hwassist_bit)
> +{
> + ((struct ifnet *)ifp)->if_hwassist = hwassist_bit;
> + return (0);
> +}
> +
> +int
> +if_gethwassist(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_hwassist;
> +}
> +
> +int
> +if_setmtu(if_t ifp, int mtu)
> +{
> + ((struct ifnet *)ifp)->if_mtu = mtu;
> + return (0);
> +}
> +
> +int
> +if_getmtu(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_mtu;
> +}
> +
> +int
> +if_setsoftc(if_t ifp, void *softc)
> +{
> + ((struct ifnet *)ifp)->if_softc = softc;
> + return (0);
> +}
> +
> +void *
> +if_getsoftc(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_softc;
> +}
> +
> +void
> +if_setrcvif(struct mbuf *m, if_t ifp)
> +{
> + m->m_pkthdr.rcvif = (struct ifnet *)ifp;
> +}
> +
> +void
> +if_setvtag(struct mbuf *m, uint16_t tag)
> +{
> + m->m_pkthdr.ether_vtag = tag;
> +}
> +
> +uint16_t
> +if_getvtag(struct mbuf *m)
> +{
> +
> + return (m->m_pkthdr.ether_vtag);
> +}
> +
> +/* Statistics */
> +int
> +if_incipackets(if_t ifp, int pkts)
> +{
> + ((struct ifnet *)ifp)->if_ipackets += pkts;
> + return (0);
> +}
> +
> +int
> +if_incopackets(if_t ifp, int pkts)
> +{
> + ((struct ifnet *)ifp)->if_opackets += pkts;
> + return (0);
> +}
> +
> +int
> +if_incierrors(if_t ifp, int ierrors)
> +{
> + ((struct ifnet *)ifp)->if_ierrors += ierrors;
> + return (0);
> +}
> +
> +
> +int
> +if_setierrors(if_t ifp, int ierrors)
> +{
> + ((struct ifnet *)ifp)->if_ierrors = ierrors;
> + return (0);
> +}
> +
> +int
> +if_setoerrors(if_t ifp, int oerrors)
> +{
> + ((struct ifnet *)ifp)->if_oerrors = oerrors;
> + return (0);
> +}
> +
> +int if_incoerrors(if_t ifp, int oerrors)
> +{
> + ((struct ifnet *)ifp)->if_oerrors += oerrors;
> + return (0);
> +}
> +
> +int if_inciqdrops(if_t ifp, int val)
> +{
> + ((struct ifnet *)ifp)->if_iqdrops += val;
> + return (0);
> +}
> +
> +int
> +if_setcollisions(if_t ifp, int collisions)
> +{
> + ((struct ifnet *)ifp)->if_collisions = collisions;
> + return (0);
> +}
> +
> +int
> +if_inccollisions(if_t ifp, int collisions)
> +{
> + ((struct ifnet *)ifp)->if_collisions += collisions;
> + return (0);
> +}
> +
> +int
> +if_setipackets(if_t ifp, int pkts)
> +{
> + ((struct ifnet *)ifp)->if_ipackets = pkts;
> + return (0);
> +}
> +
> +int
> +if_setopackets(if_t ifp, int pkts)
> +{
> + ((struct ifnet *)ifp)->if_opackets = pkts;
> + return (0);
> +}
> +
> +int
> +if_incobytes(if_t ifp, int bytes)
> +{
> + ((struct ifnet *)ifp)->if_obytes += bytes;
> + return (0);
> +}
> +
> +int
> +if_setibytes(if_t ifp, int bytes)
> +{
> + ((struct ifnet *)ifp)->if_ibytes = bytes;
> + return (0);
> +}
> +
> +int
> +if_setobytes(if_t ifp, int bytes)
> +{
> + ((struct ifnet *)ifp)->if_obytes = bytes;
> + return (0);
> +}
> +
> +
> +int
> +if_sendq_empty(if_t ifp)
> +{
> + return IFQ_DRV_IS_EMPTY(&((struct ifnet *)ifp)->if_snd);
> +}
> +
> +int if_getiqdrops(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_iqdrops;
> +}
> +
> +int
> +if_incimcasts(if_t ifp, int mcast)
> +{
> + ((struct ifnet *)ifp)->if_imcasts += mcast;
> + return (0);
> +}
> +
> +
> +int
> +if_incomcasts(if_t ifp, int mcast)
> +{
> + ((struct ifnet *)ifp)->if_omcasts += mcast;
> + return (0);
> +}
> +
> +int
> +if_setimcasts(if_t ifp, int mcast)
> +{
> + ((struct ifnet *)ifp)->if_imcasts = mcast;
> + return (0);
> +}
> +
> +
> +struct ifaddr *
> +if_getifaddr(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_addr;
> +}
> +
> +int
> +if_getamcount(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_amcount;
> +}
> +
> +
> +int
> +if_setsendqready(if_t ifp)
> +{
> + IFQ_SET_READY(&((struct ifnet *)ifp)->if_snd);
> + return (0);
> +}
> +
> +int
> +if_setsendqlen(if_t ifp, int tx_desc_count)
> +{
> + IFQ_SET_MAXLEN(&((struct ifnet *)ifp)->if_snd, tx_desc_count);
> + ((struct ifnet *)ifp)->if_snd.ifq_drv_maxlen = tx_desc_count;
> +
> + return (0);
> +}
> +
> +int
> +if_vlantrunkinuse(if_t ifp)
> +{
> + return ((struct ifnet *)ifp)->if_vlantrunk != NULL?1:0;
> +}
> +
> +int
> +if_input(if_t ifp, struct mbuf* sendmp)
> +{
> + (*((struct ifnet *)ifp)->if_input)((struct ifnet *)ifp, sendmp);
> + return (0);
> +
> +}
> +
> +/* XXX */
> +#ifndef ETH_ADDR_LEN
> +#define ETH_ADDR_LEN 6
> +#endif
> +
> +int
> +if_setupmultiaddr(if_t ifp, void *mta, int *cnt, int max)
> +{
> + struct ifmultiaddr *ifma;
> + uint8_t *lmta = (uint8_t *)mta;
> + int mcnt = 0;
> +
> + TAILQ_FOREACH(ifma, &((struct ifnet *)ifp)->if_multiaddrs, ifma_link) {
> + if (ifma->ifma_addr->sa_family != AF_LINK)
> + continue;
> +
> + if (mcnt == max)
> + break;
> +
> + bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
> + &lmta[mcnt * ETH_ADDR_LEN], ETH_ADDR_LEN);
> + mcnt++;
> + }
> + *cnt = mcnt;
> +
> + return (0);
> +}
> +
> +int
> +if_multiaddr_array(if_t ifp, void *mta, int *cnt, int max)
> +{
> + int error;
> +
> + if_maddr_rlock(ifp);
> + error = if_setupmultiaddr(ifp, mta, cnt, max);
> + if_maddr_runlock(ifp);
> + return (error);
> +}
> +
> +int
> +if_multiaddr_count(if_t ifp, int max)
> +{
> + struct ifmultiaddr *ifma;
> + int count;
> +
> + count = 0;
> + if_maddr_rlock(ifp);
> + TAILQ_FOREACH(ifma, &((struct ifnet *)ifp)->if_multiaddrs, ifma_link) {
> + if (ifma->ifma_addr->sa_family != AF_LINK)
> + continue;
> + count++;
> + if (count == max)
> + break;
> + }
> + if_maddr_runlock(ifp);
> + return (count);
> +}
> +
> +struct mbuf *
> +if_dequeue(if_t ifp)
> +{
> + struct mbuf *m;
> + IFQ_DRV_DEQUEUE(&((struct ifnet *)ifp)->if_snd, m);
> +
> + return (m);
> +}
> +
> +int
> +if_sendq_prepend(if_t ifp, struct mbuf *m)
> +{
> + IFQ_DRV_PREPEND(&((struct ifnet *)ifp)->if_snd, m);
> + return (0);
> +}
> +
> +int
> +if_setifheaderlen(if_t ifp, int len)
> +{
> + ((struct ifnet *)ifp)->if_data.ifi_hdrlen = len;
> + return (0);
> +}
> +
> +caddr_t
> +if_getlladdr(if_t ifp)
> +{
> + return (IF_LLADDR((struct ifnet *)ifp));
> +}
> +
> +void *
> +if_gethandle(u_char type)
> +{
> + return (if_alloc(type));
> +}
> +
> +void
> +if_bpfmtap(if_t ifh, struct mbuf *m)
> +{
> + struct ifnet *ifp = (struct ifnet *)ifh;
> +
> + BPF_MTAP(ifp, m);
> +}
> +
> +void
> +if_etherbpfmtap(if_t ifh, struct mbuf *m)
> +{
> + struct ifnet *ifp = (struct ifnet *)ifh;
> +
> + ETHER_BPF_MTAP(ifp, m);
> +}
> +
> +void
> +if_vlancap(if_t ifh)
> +{
> + struct ifnet *ifp = (struct ifnet *)ifh;
> + VLAN_CAPABILITIES(ifp);
> +}
> +
> +void
> +if_setinitfn(if_t ifp, void (*init_fn)(void *))
> +{
> + ((struct ifnet *)ifp)->if_init = init_fn;
> +}
> +
> +void
> +if_setioctlfn(if_t ifp, int (*ioctl_fn)(void *, u_long, caddr_t))
> +{
> + ((struct ifnet *)ifp)->if_ioctl = (void *)ioctl_fn;
> +}
> +
> +void
> +if_setstartfn(if_t ifp, void (*start_fn)(void *))
> +{
> + ((struct ifnet *)ifp)->if_start = (void *)start_fn;
> +}
> +
> +void
> +if_settransmitfn(if_t ifp, if_transmit_fn_t start_fn)
> +{
> + ((struct ifnet *)ifp)->if_transmit = start_fn;
> +}
> +
> +void if_setqflushfn(if_t ifp, if_qflush_fn_t flush_fn)
> +{
> + ((struct ifnet *)ifp)->if_qflush = flush_fn;
> +
> +}
> +
> +/* These wrappers are hopefully temporary, till all drivers use drvapi */
> +#ifdef INET
> +void
> +arp_ifinit_drv(if_t ifh, struct ifaddr *ifa)
> +{
> + arp_ifinit((struct ifnet *)ifh, ifa);
> +}
> +#endif
> +
> +void
> +ether_ifattach_drv(if_t ifh, const u_int8_t *lla)
> +{
> + ether_ifattach((struct ifnet *)ifh, lla);
> +}
>
> *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
>
More information about the svn-src-head
mailing list