Index: conf/files =================================================================== --- conf/files (revision 242382) +++ conf/files (working copy) @@ -2872,6 +2872,7 @@ net/if_clone.c standard net/if_dead.c standard net/if_debug.c optional ddb +net/if_device.c standard net/if_disc.c optional disc net/if_edsc.c optional edsc net/if_ef.c optional ef Index: net/if_device.c =================================================================== --- net/if_device.c (revision 0) +++ net/if_device.c (working copy) @@ -0,0 +1,319 @@ +#include +#include +#include +#include +#include +#include + +u_long +if_set_baudrate(struct ifnet *ifp, u_long baudrate) +{ + u_long ret; + + ret = ifp->if_data.ifi_baudrate; + ifp->if_data.ifi_baudrate = baudrate; + return (ret); +} + +u_long +if_get_baudrate(struct ifnet *ifp) +{ + + return (ifp->if_data.ifi_baudrate); +} + +int +if_set_capabilities(struct ifnet *ifp, int capabilities) +{ + int ret; + + ret = ifp->if_capabilities; + ifp->if_capabilities = capabilities; + return (ret); +} + +int +if_capabilities(struct ifnet *ifp, int setbit, int clearbit) +{ + int ret; + + ret = ifp->if_capabilities; + ifp->if_capabilities = (ret | setbit) & ~clearbit; + return (ret); +} + +int +if_get_capabilities(struct ifnet *ifp) +{ + + return (ifp->if_capabilities); +} + +int +if_set_capenable(struct ifnet *ifp, int capabilities) +{ + ifp->if_capenable = capabilities; + return 0; +} + +int +if_capenable(struct ifnet *ifp, int setcap, int clearcap) +{ + if(setcap) + ifp->if_capenable |= setcap; + if(clearcap) + ifp->if_capenable &= ~clearcap; + return 0; +} + +int +if_toggle_capenable(struct ifnet *ifp, int togglecap) +{ + ifp->if_capenable ^= togglecap; + return 0; +} + +int +if_get_capenable(struct ifnet *ifp) +{ + return ifp->if_capenable; +} + +int +if_drvflags(struct ifnet *ifp, int on, int off) +{ + ifp->if_drv_flags |= on; + ifp->if_drv_flags &= ~off; + return 0; +} + +int +if_get_drvflags(struct ifnet *ifp) +{ + return ifp->if_drv_flags; +} + +int +if_set_flags(struct ifnet *ifp, int flags) +{ + ifp->if_flags = flags; + return 0; +} + +int +if_flags(struct ifnet *ifp, int on, int off) +{ + ifp->if_flags |= on; + ifp->if_flags &= ~off; + return 0; +} + +int +if_get_flags(struct ifnet *ifp) +{ + return ifp->if_flags; +} + +int +if_clear_hwassist(struct ifnet *ifp) +{ + ifp->if_hwassist = 0; + return 0; +} + +int +if_set_hwassist(struct ifnet *ifp, int on) +{ + ifp->if_hwassist |= on; + return 0; +} + +int +if_get_hwassist(struct ifnet *ifp) +{ + return ifp->if_hwassist; +} + +int +if_set_mtu(struct ifnet *ifp, int mtu) +{ + ifp->if_mtu = mtu; + return 0; +} + +int +if_get_mtu(struct ifnet *ifp) +{ + return ifp->if_mtu; +} + +int +if_set_softc(struct ifnet *ifp, void *softc) +{ + ifp->if_softc = softc; + return 0; +} + +void * +if_get_softc(struct ifnet *ifp) +{ + return ifp->if_softc; +} + +void +if_set_rcvif(struct mbuf *m, struct ifnet *ifp) +{ + m->m_pkthdr.rcvif = ifp; +} + +void +if_set_vtag(struct mbuf *m, u_int16_t tag) +{ + m->m_pkthdr.ether_vtag = tag; +} + +u_int16_t +if_get_vtag(struct mbuf *m) +{ + return m->m_pkthdr.ether_vtag; +} + +/* Statistics */ +int +if_inc_ipackets(struct ifnet *ifp, int pkts) +{ + ifp->if_ipackets += pkts; + return 0; +} + +int +if_inc_opackets(struct ifnet *ifp, int pkts) +{ + ifp->if_opackets += pkts; + return 0; +} + +int +if_inc_ierrors(struct ifnet *ifp, int ierrors) +{ + ifp->if_ierrors += ierrors; + return 0; +} + +int +if_set_ierrors(struct ifnet *ifp, int ierrors) +{ + ifp->if_ierrors = ierrors; + return 0; +} + +int +if_set_oerrors(struct ifnet *ifp, int oerrors) +{ + ifp->if_oerrors = oerrors; + return 0; +} + +int +if_inc_oerrors(struct ifnet *ifp, int oerrors) +{ + ifp->if_oerrors += oerrors; + return 0; +} + +int +if_inc_iqdrops(struct ifnet *ifp, int val) +{ + ifp->if_iqdrops += val; + return 0; +} + +int +if_set_collisions(struct ifnet *ifp, int collisions) +{ + ifp->if_collisions = collisions; + return 0; +} + +int +if_sendq_empty(struct ifnet *ifp) +{ + return IFQ_DRV_IS_EMPTY(&ifp->if_snd); +} + +int +if_set_sendq_ready(struct ifnet *ifp) +{ + IFQ_SET_READY(&ifp->if_snd); + return 0; +} + +int +if_set_sendq_len(struct ifnet *ifp, int tx_desc_count) +{ + IFQ_SET_MAXLEN(&ifp->if_snd, tx_desc_count); + ifp->if_snd.ifq_drv_maxlen = tx_desc_count; + return 0; +} + +int +if_vlan_trunk_inuse(struct ifnet *ifp) +{ + return ifp->if_vlantrunk != NULL?1:0; +} + +int +if_input(struct ifnet *ifp, struct mbuf* sendmp) +{ + (*ifp->if_input)(ifp, sendmp); + return 0; + +} + +/* XXX */ +#ifndef ETH_ADDR_LEN +#define ETH_ADDR_LEN 6 +#endif + +int +if_setup_multiaddr(struct ifnet *ifp, u_int8_t *mta, int *cnt, int max) +{ + struct ifmultiaddr *ifma; + int mcnt = 0; + + TAILQ_FOREACH(ifma, &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), + &mta[mcnt * ETH_ADDR_LEN], ETH_ADDR_LEN); + mcnt++; + } + *cnt = mcnt; + return 0; +} + +struct mbuf * +if_dequeue(struct ifnet *ifp) +{ + struct mbuf *m; + IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + return m; +} + +int +if_sendq_prepend(struct ifnet *ifp, struct mbuf *m) +{ + IFQ_DRV_PREPEND(&ifp->if_snd, m); + return 0; +} + +int +if_set_hdrlen(struct ifnet *ifp, int len) +{ + ifp->if_data.ifi_hdrlen = len; + return 0; +} Index: net/if_device.h =================================================================== --- net/if_device.h (revision 0) +++ net/if_device.h (working copy) @@ -0,0 +1,67 @@ +#ifndef _NET_IF_DEVICE_H_ +#define _NET_IF_DEVICE_H_ + +u_long if_set_baudrate(struct ifnet *ifp, u_long baudrate); +u_long if_get_baudrate(struct ifnet *ifp); + +int if_set_capabilities(struct ifnet *ifp, int capabilities); +int if_get_capabilities(struct ifnet *ifp); +int if_capabilities(struct ifnet *ifp, int on, int off); + +int if_toggle_capenable(struct ifnet *ifp, int toggle); +int if_set_capenable(struct ifnet *ifp, int capenable); +int if_capenable(struct ifnet *ifp, int on, int off); +int if_get_capenable(struct ifnet *ifp); + +int if_drvflags(struct ifnet *ifp, int on, int off); +int if_get_drvflags(struct ifnet *ifp); + +int if_set_hwassist(struct ifnet *ifp, int bit); +int if_get_hwassist(struct ifnet *ifp); +int if_clear_hwassist(struct ifnet *ifp); + +int if_set_softc(struct ifnet *ifp, void *softc); +void *if_get_softc(struct ifnet *ifp); + +int if_set_flags(struct ifnet *ifp, int flags); +int if_flags(struct ifnet *ifp, int on, int off); +int if_get_flags(struct ifnet *ifp); + +int if_set_mtu(struct ifnet *ifp, int mtu); +int if_get_mtu(struct ifnet *ifp); + +int if_sendq_empty(struct ifnet *ifp); +int if_set_sendq_ready(struct ifnet *ifp); +int if_set_sendq_len(struct ifnet *ifp, int tx_desc_count); +int if_sendq_prepend(struct ifnet *ifp, struct mbuf *m); + +int if_input(struct ifnet *ifp, struct mbuf* sendmp); +int if_setup_multiaddr(struct ifnet *ifp, u_int8_t *mta, int *cnt, int max); +struct mbuf *if_dequeue(struct ifnet *ifp); + +int if_set_hdrlen(struct ifnet *ifp, int len); +void if_set_rcvif(struct mbuf *m, struct ifnet *ifp); +void if_set_vtag(struct mbuf *m, u_int16_t tag); +u_int16_t if_get_vtag(struct mbuf *m); + +#define if_setinputfn(ifp, input) do { ifp->if_input = input; } while(0) +#define if_setinitfn(ifp, init) do { ifp->if_init = init; } while(0) +#define if_setioctlfn(ifp, ioctl) do { ifp->if_ioctl = ioctl; } while(0) +#define if_setqflushfn(ifp, qflush) do { ifp->if_qflush = qflush; } while(0) +#define if_setstartfn(ifp, start) do { ifp->if_start = start; } while(0) +#define if_settransmitfn(ifp, transmit) do { ifp->if_transmit = transmit; } while(0) + +int if_vlan_trunk_inuse(struct ifnet *ifp); + +/* Statistics */ + +int if_inc_ipackets(struct ifnet *ifp, int pkt); +int if_inc_opackets(struct ifnet *ifp, int pkts); +int if_inc_ierrors(struct ifnet *ifp, int ierrors); +int if_inc_oerrors(struct ifnet *ifp, int oerrors); +int if_inc_iqdrops(struct ifnet *ifp, int val); +int if_set_ierrors(struct ifnet *ifp, int ierrors); +int if_set_oerrors(struct ifnet *ifp, int oerrors); +int if_set_collisions(struct ifnet *ifp, int collisions); + +#endif /* _NET_IF_DEVICE_H_ */