diff options
author | brooks <brooks@FreeBSD.org> | 2005-06-10 16:49:24 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2005-06-10 16:49:24 +0000 |
commit | 567ba9b00a248431e7c1147c4e079fd7a11b9ecf (patch) | |
tree | f65b6d7834b40dfcd48534829a0a1e9529ab87ee /sys/dev/nge | |
parent | 3eaa67c3ad947d85be5350e0e184cd6ee5b93a52 (diff) | |
download | FreeBSD-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/nge')
-rw-r--r-- | sys/dev/nge/if_nge.c | 38 | ||||
-rw-r--r-- | sys/dev/nge/if_ngereg.h | 2 |
2 files changed, 24 insertions, 16 deletions
diff --git a/sys/dev/nge/if_nge.c b/sys/dev/nge/if_nge.c index f480cb5..43cd378 100644 --- a/sys/dev/nge/if_nge.c +++ b/sys/dev/nge/if_nge.c @@ -672,7 +672,7 @@ nge_setmulti(sc) int bit, index; NGE_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { NGE_CLRBIT(sc, NGE_RXFILT_CTL, @@ -834,8 +834,8 @@ nge_attach(dev) nge_read_eeprom(sc, (caddr_t)&eaddr[0], NGE_EE_NODEADDR + 2, 1, 0); sc->nge_unit = unit; - bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); + /* XXX: leaked on error */ sc->nge_ldata = contigmalloc(sizeof(struct nge_list_data), M_DEVBUF, M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); @@ -846,9 +846,15 @@ nge_attach(dev) error = ENXIO; goto fail; } - bzero(sc->nge_ldata, sizeof(struct nge_list_data)); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + printf("nge%d: can not if_alloc()\n", unit); + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq); + bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res); + error = ENOSPC; + goto fail; + } ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_mtu = ETHERMTU; @@ -924,6 +930,7 @@ nge_attach(dev) error = bus_setup_intr(dev, sc->nge_irq, INTR_TYPE_NET | INTR_MPSAFE, nge_intr, sc, &sc->nge_intrhand); if (error) { + /* XXX: resource leaks */ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq); bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res); printf("nge%d: couldn't set up irq\n", unit); @@ -944,13 +951,14 @@ nge_detach(dev) struct ifnet *ifp; sc = device_get_softc(dev); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; NGE_LOCK(sc); nge_reset(sc); nge_stop(sc); NGE_UNLOCK(sc); ether_ifdetach(ifp); + if_free(ifp); bus_generic_detach(dev); if (!sc->nge_tbi) { @@ -1106,7 +1114,7 @@ nge_rxeof(sc) u_int32_t rxstat; NGE_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; i = sc->nge_cdata.nge_rx_prod; while(NGE_OWNDESC(&sc->nge_ldata->nge_rx_list[i])) { @@ -1247,7 +1255,7 @@ nge_txeof(sc) u_int32_t idx; NGE_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; /* * Go through our tx list and free mbufs for those @@ -1317,7 +1325,7 @@ nge_tick_locked(sc) struct ifnet *ifp; NGE_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; if (sc->nge_tbi) { if (!sc->nge_link) { @@ -1416,7 +1424,7 @@ nge_intr(arg) u_int32_t status; sc = arg; - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; NGE_LOCK(sc); #ifdef DEVICE_POLLING @@ -1563,7 +1571,7 @@ nge_encap(sc, m_head, txidx) NGE_TXEXTSTS_UDPCSUM; } - mtag = VLAN_OUTPUT_TAG(&sc->arpcom.ac_if, m_head); + mtag = VLAN_OUTPUT_TAG(sc->nge_ifp, m_head); if (mtag != NULL) { sc->nge_ldata->nge_tx_list[cur].nge_extsts |= (NGE_TXEXTSTS_VLANPKT|htons(VLAN_TAG_VALUE(mtag))); @@ -1661,7 +1669,7 @@ static void nge_init_locked(sc) struct nge_softc *sc; { - struct ifnet *ifp = &sc->arpcom.ac_if; + struct ifnet *ifp = sc->nge_ifp; struct mii_data *mii; NGE_LOCK_ASSERT(sc); @@ -1683,13 +1691,13 @@ nge_init_locked(sc) /* Set MAC address */ CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR0); CSR_WRITE_4(sc, NGE_RXFILT_DATA, - ((u_int16_t *)sc->arpcom.ac_enaddr)[0]); + ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[0]); CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR1); CSR_WRITE_4(sc, NGE_RXFILT_DATA, - ((u_int16_t *)sc->arpcom.ac_enaddr)[1]); + ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[1]); CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR2); CSR_WRITE_4(sc, NGE_RXFILT_DATA, - ((u_int16_t *)sc->arpcom.ac_enaddr)[2]); + ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[2]); /* Init circular RX list. */ if (nge_list_rx_init(sc) == ENOBUFS) { @@ -2083,7 +2091,7 @@ nge_stop(sc) struct mii_data *mii; NGE_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->nge_ifp; ifp->if_timer = 0; if (sc->nge_tbi) { mii = NULL; diff --git a/sys/dev/nge/if_ngereg.h b/sys/dev/nge/if_ngereg.h index 5a46aa6..91b191f 100644 --- a/sys/dev/nge/if_ngereg.h +++ b/sys/dev/nge/if_ngereg.h @@ -648,7 +648,7 @@ struct nge_ring_data { }; struct nge_softc { - struct arpcom arpcom; /* interface info */ + struct ifnet *nge_ifp; bus_space_handle_t nge_bhandle; bus_space_tag_t nge_btag; struct resource *nge_res; |