summaryrefslogtreecommitdiffstats
path: root/sys/dev/an/if_an.c
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2005-06-10 16:49:24 +0000
committerbrooks <brooks@FreeBSD.org>2005-06-10 16:49:24 +0000
commit567ba9b00a248431e7c1147c4e079fd7a11b9ecf (patch)
treef65b6d7834b40dfcd48534829a0a1e9529ab87ee /sys/dev/an/if_an.c
parent3eaa67c3ad947d85be5350e0e184cd6ee5b93a52 (diff)
downloadFreeBSD-src-567ba9b00a248431e7c1147c4e079fd7a11b9ecf.zip
FreeBSD-src-567ba9b00a248431e7c1147c4e079fd7a11b9ecf.tar.gz
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
Diffstat (limited to 'sys/dev/an/if_an.c')
-rw-r--r--sys/dev/an/if_an.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/sys/dev/an/if_an.c b/sys/dev/an/if_an.c
index e8fffbf..0aae094 100644
--- a/sys/dev/an/if_an.c
+++ b/sys/dev/an/if_an.c
@@ -669,14 +669,19 @@ an_attach(sc, unit, flags)
int unit;
int flags;
{
- struct ifnet *ifp = &sc->arpcom.ac_if;
+ struct ifnet *ifp;
int error = EIO;
int i, nrate, mword;
u_int8_t r;
mtx_init(&sc->an_mtx, device_get_nameunit(sc->an_dev), MTX_NETWORK_LOCK,
MTX_DEF | MTX_RECURSE);
-
+ ifp = if_alloc(IFT_ETHER);
+ if (ifp == NULL) {
+ printf("an%d: can not if_alloc()\n", sc->an_unit);
+ goto fail;
+ }
+
sc->an_gone = 0;
sc->an_associated = 0;
sc->an_monitor = 0;
@@ -746,9 +751,6 @@ an_attach(sc, unit, flags)
}
#endif
- bcopy((char *)&sc->an_caps.an_oemaddr,
- (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
-
ifp->if_softc = sc;
sc->an_unit = unit;
if_initname(ifp, device_get_name(sc->an_dev),
@@ -806,12 +808,15 @@ an_attach(sc, unit, flags)
/*
* Call MI attach routine.
*/
- ether_ifattach(ifp, sc->arpcom.ac_enaddr);
+
+ ether_ifattach(ifp, sc->an_caps.an_oemaddr);
callout_handle_init(&sc->an_stat_ch);
return(0);
fail:;
mtx_destroy(&sc->an_mtx);
+ if (ifp != NULL)
+ if_free(ifp);
return(error);
}
@@ -819,7 +824,7 @@ int
an_detach(device_t dev)
{
struct an_softc *sc = device_get_softc(dev);
- struct ifnet *ifp = &sc->arpcom.ac_if;
+ struct ifnet *ifp = sc->an_ifp;
if (sc->an_gone) {
device_printf(dev,"already unloaded\n");
@@ -830,6 +835,7 @@ an_detach(device_t dev)
ifmedia_removeall(&sc->an_ifmedia);
ifp->if_flags &= ~IFF_RUNNING;
ether_ifdetach(ifp);
+ if_free(ifp);
sc->an_gone = 1;
AN_UNLOCK(sc);
bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
@@ -857,7 +863,7 @@ an_rxeof(sc)
AN_LOCK_ASSERT(sc);
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
if (!sc->mpi350) {
id = CSR_READ_2(sc, AN_RX_FID);
@@ -1109,7 +1115,7 @@ an_txeof(sc, status)
struct ifnet *ifp;
int id, i;
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
ifp->if_timer = 0;
ifp->if_flags &= ~IFF_OACTIVE;
@@ -1162,7 +1168,7 @@ an_stats_update(xsc)
sc = xsc;
AN_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
sc->an_status.an_type = AN_RID_STATUS;
sc->an_status.an_len = sizeof(struct an_ltv_status);
@@ -1207,7 +1213,7 @@ an_intr(xsc)
return;
}
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
/* Disable interrupts. */
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
@@ -1784,7 +1790,7 @@ an_setdef(sc, areq)
struct an_ltv_aplist *ap;
struct an_ltv_gen *sp;
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
switch (areq->an_type) {
case AN_RID_GENCONFIG:
@@ -1792,7 +1798,7 @@ an_setdef(sc, areq)
ifa = ifaddr_byindex(ifp->if_index);
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
- bcopy((char *)&cfg->an_macaddr, (char *)&sc->arpcom.ac_enaddr,
+ bcopy((char *)&cfg->an_macaddr, IFP2ENADDR(sc->an_ifp),
ETHER_ADDR_LEN);
bcopy((char *)&cfg->an_macaddr, LLADDR(sdl), ETHER_ADDR_LEN);
@@ -2529,7 +2535,7 @@ an_init(xsc)
void *xsc;
{
struct an_softc *sc = xsc;
- struct ifnet *ifp = &sc->arpcom.ac_if;
+ struct ifnet *ifp = sc->an_ifp;
AN_LOCK(sc);
@@ -2557,7 +2563,7 @@ an_init(xsc)
}
/* Set our MAC address. */
- bcopy((char *)&sc->arpcom.ac_enaddr,
+ bcopy((char *)IFP2ENADDR(sc->an_ifp),
(char *)&sc->an_config.an_macaddr, ETHER_ADDR_LEN);
if (ifp->if_flags & IFF_BROADCAST)
@@ -2834,7 +2840,7 @@ an_stop(sc)
return;
}
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0);
CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
@@ -2907,7 +2913,7 @@ an_resume(dev)
sc = device_get_softc(dev);
AN_LOCK(sc);
- ifp = &sc->arpcom.ac_if;
+ ifp = sc->an_ifp;
sc->an_gone = 0;
an_reset(sc);
OpenPOWER on IntegriCloud