From fc74a9f93a5fbc83262aa12084404ac953c854b5 Mon Sep 17 00:00:00 2001 From: Brooks Davis 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/dev/owi/if_owi.c | 41 +++++++++++++++++++++++++---------------- sys/dev/owi/if_wivar.h | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'sys/dev/owi') diff --git a/sys/dev/owi/if_owi.c b/sys/dev/owi/if_owi.c index b33da65059cf3..18a1e0988f6ee 100644 --- a/sys/dev/owi/if_owi.c +++ b/sys/dev/owi/if_owi.c @@ -154,7 +154,7 @@ owi_generic_detach(dev) sc = device_get_softc(dev); WI_LOCK(sc, s); - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; if (sc->wi_gone) { device_printf(dev, "already unloaded\n"); @@ -191,7 +191,13 @@ owi_generic_attach(device_t dev) /* XXX maybe we need the splimp stuff here XXX */ sc = device_get_softc(dev); - ifp = &sc->arpcom.ac_if; + + ifp = sc->ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + device_printf(dev, "can not if_alloc()\n"); + owi_free(dev); + return (ENOSPC); + } error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET, wi_intr, sc, &sc->wi_intrhand); @@ -223,8 +229,6 @@ owi_generic_attach(device_t dev) owi_free(dev); return (error); } - bcopy((char *)&mac.wi_mac_addr, - (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); owi_get_id(sc); @@ -379,7 +383,7 @@ owi_generic_attach(device_t dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, mac.wi_mac_addr); callout_handle_init(&sc->wi_stat_ch); WI_UNLOCK(sc, s); @@ -448,7 +452,7 @@ wi_rxeof(sc) WI_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; id = CSR_READ_2(sc, WI_RX_FID); @@ -662,7 +666,7 @@ wi_txeof(sc, status) { struct ifnet *ifp; - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; ifp->if_timer = 0; ifp->if_flags &= ~IFF_OACTIVE; @@ -684,7 +688,7 @@ wi_inquire(xsc) int s; sc = xsc; - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; sc->wi_stat_ch = timeout(wi_inquire, sc, hz * 60); @@ -710,7 +714,7 @@ wi_update_stats(sc) int len, i; u_int16_t t; - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; id = CSR_READ_2(sc, WI_INFO_FID); @@ -763,7 +767,7 @@ wi_intr(xsc) WI_LOCK(sc, s); - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; if (sc->wi_gone || !(ifp->if_flags & IFF_UP)) { CSR_WRITE_2(sc, WI_EVENT_ACK, 0xFFFF); @@ -1197,7 +1201,7 @@ wi_setmulti(sc) struct ifmultiaddr *ifma; struct wi_ltv_mcast mcast; - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; bzero((char *)&mcast, sizeof(mcast)); @@ -1237,13 +1241,13 @@ wi_setdef(sc, wreq) struct ifaddr *ifa; struct ifnet *ifp; - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; switch(wreq->wi_type) { case WI_RID_MAC_NODE: ifa = ifaddr_byindex(ifp->if_index); sdl = (struct sockaddr_dl *)ifa->ifa_addr; - bcopy((char *)&wreq->wi_val, (char *)&sc->arpcom.ac_enaddr, + bcopy((char *)&wreq->wi_val, (char *)&IFP2ENADDR(sc->ifp), ETHER_ADDR_LEN); bcopy((char *)&wreq->wi_val, LLADDR(sdl), ETHER_ADDR_LEN); break; @@ -1686,7 +1690,7 @@ wi_init(xsc) void *xsc; { struct wi_softc *sc = xsc; - struct ifnet *ifp = &sc->arpcom.ac_if; + struct ifnet *ifp = sc->ifp; struct wi_ltv_macaddr mac; int id = 0; int s; @@ -1748,7 +1752,7 @@ wi_init(xsc) /* Set our MAC address. */ mac.wi_len = 4; mac.wi_type = WI_RID_MAC_NODE; - bcopy((char *)&sc->arpcom.ac_enaddr, + bcopy((char *)&IFP2ENADDR(sc->ifp), (char *)&mac.wi_mac_addr, ETHER_ADDR_LEN); wi_write_record(sc, (struct wi_ltv_gen *)&mac); @@ -1909,7 +1913,7 @@ owi_stop(sc) return; } - ifp = &sc->arpcom.ac_if; + ifp = sc->ifp; /* * If the card is gone and the memory port isn't mapped, we will @@ -2015,6 +2019,11 @@ owi_free(dev) sc->mem = NULL; } + if (sc->ifp != NULL) { + if_free(sc->ifp); + sc->ifp = NULL; + } + return; } diff --git a/sys/dev/owi/if_wivar.h b/sys/dev/owi/if_wivar.h index a439949e59162..dfdb6ea6bd846 100644 --- a/sys/dev/owi/if_wivar.h +++ b/sys/dev/owi/if_wivar.h @@ -58,7 +58,7 @@ #define WI_RID_CUR_TX_RATE 0xFD44 /* current TX rate */ struct wi_softc { - struct arpcom arpcom; + struct ifnet *ifp; struct ifmedia ifmedia; device_t dev; int wi_unit; -- cgit v1.3