From 567ba9b00a248431e7c1147c4e079fd7a11b9ecf Mon Sep 17 00:00:00 2001 From: brooks Date: Fri, 10 Jun 2005 16:49:24 +0000 Subject: Stop embedding struct ifnet at the top of driver softcs. Instead the struct ifnet or the layer 2 common structure it was embedded in have been replaced with a struct ifnet pointer to be filled by a call to the new function, if_alloc(). The layer 2 common structure is also allocated via if_alloc() based on the interface type. It is hung off the new struct ifnet member, if_l2com. This change removes the size of these structures from the kernel ABI and will allow us to better manage them as interfaces come and go. Other changes of note: - Struct arpcom is no longer referenced in normal interface code. Instead the Ethernet address is accessed via the IFP2ENADDR() macro. To enforce this ac_enaddr has been renamed to _ac_enaddr. - The second argument to ether_ifattach is now always the mac address from driver private storage rather than sometimes being ac_enaddr. Reviewed by: sobomax, sam --- sys/net/if_arcsubr.c | 58 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'sys/net/if_arcsubr.c') diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c index 39022ef..e944f49 100644 --- a/sys/net/if_arcsubr.c +++ b/sys/net/if_arcsubr.c @@ -80,8 +80,6 @@ #include #endif -MODULE_VERSION(arcnet, 1); - #define ARCNET_ALLOW_BROKEN_ARP static struct mbuf *arc_defrag(struct ifnet *, struct mbuf *); @@ -254,7 +252,7 @@ arc_frag_init(ifp) { struct arccom *ac; - ac = (struct arccom *)ifp; + ac = (struct arccom *)ifp->if_l2com; ac->curr_frag = 0; } @@ -266,7 +264,7 @@ arc_frag_next(ifp) struct mbuf *m; struct arc_header *ah; - ac = (struct arccom *)ifp; + ac = (struct arccom *)ifp->if_l2com; if ((m = ac->curr_frag) == 0) { int tfrags; @@ -367,7 +365,7 @@ arc_defrag(ifp, m) int newflen; u_char src,dst,typ; - ac = (struct arccom *)ifp; + ac = (struct arccom *)ifp->if_l2com; if (m->m_len < ARC_HDRNEWLEN) { m = m_pullup(m, ARC_HDRNEWLEN); @@ -641,7 +639,6 @@ arc_ifattach(ifp, lla) struct arccom *ac; if_attach(ifp); - ifp->if_type = IFT_ARCNET; ifp->if_addrlen = 1; ifp->if_hdrlen = ARC_HDRLEN; ifp->if_mtu = 1500; @@ -661,7 +658,7 @@ arc_ifattach(ifp, lla) if (ifp->if_flags & IFF_BROADCAST) ifp->if_flags |= IFF_MULTICAST|IFF_ALLMULTI; - ac = (struct arccom *)ifp; + ac = (struct arccom *)ifp->if_l2com; ac->ac_seqid = (time_second) & 0xFFFF; /* try to make seqid unique */ if (lla == 0) { /* XXX this message isn't entirely clear, to me -- cgd */ @@ -846,3 +843,50 @@ arc_resolvemulti(ifp, llsa, sa) return EAFNOSUPPORT; } } + +MALLOC_DEFINE(M_ARCCOM, "arccom", "ARCNET interface internals"); + +static void* +arc_alloc(u_char type, struct ifnet *ifp) +{ + struct arccom *ac; + + ac = malloc(sizeof(struct arccom), M_ARCCOM, M_WAITOK | M_ZERO); + ac->ac_ifp = ifp; + + return (ac); +} + +static void +arc_free(void *com, u_char type) +{ + + free(com, M_ARCCOM); +} + +static int +arc_modevent(module_t mod, int type, void *data) +{ + + switch (type) { + case MOD_LOAD: + if_register_com_alloc(IFT_ARCNET, arc_alloc, arc_free); + break; + case MOD_UNLOAD: + if_deregister_com_alloc(IFT_ARCNET); + break; + default: + return EOPNOTSUPP; + } + + return (0); +} + +static moduledata_t arc_mod = { + "arcnet", + arc_modevent, + 0 +}; + +DECLARE_MODULE(arcnet, arc_mod, SI_SUB_INIT_IF, SI_ORDER_ANY); +MODULE_VERSION(arcnet, 1); -- cgit v1.1