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/sf | |
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/sf')
-rw-r--r-- | sys/dev/sf/if_sf.c | 37 | ||||
-rw-r--r-- | sys/dev/sf/if_sfreg.h | 2 |
2 files changed, 24 insertions, 15 deletions
diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c index 5593d52..85d6819 100644 --- a/sys/dev/sf/if_sf.c +++ b/sys/dev/sf/if_sf.c @@ -93,6 +93,7 @@ __FBSDID("$FreeBSD$"); #include <net/ethernet.h> #include <net/if_dl.h> #include <net/if_media.h> +#include <net/if_types.h> #include <net/bpf.h> @@ -415,7 +416,7 @@ sf_setmulti(sc) struct ifmultiaddr *ifma; u_int8_t dummy[] = { 0, 0, 0, 0, 0, 0 }; - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; /* First zot all the existing filters. */ for (i = 1; i < SF_RXFILT_PERFECT_CNT; i++) @@ -641,6 +642,7 @@ sf_attach(dev) struct sf_softc *sc; struct ifnet *ifp; int unit, rid, error = 0; + u_char eaddr[6]; sc = device_get_softc(dev); unit = device_get_unit(dev); @@ -683,7 +685,7 @@ sf_attach(dev) * Get station address from the EEPROM. */ for (i = 0; i < ETHER_ADDR_LEN; i++) - sc->arpcom.ac_enaddr[i] = + eaddr[i] = sf_read_eeprom(sc, SF_EE_NODEADDR + ETHER_ADDR_LEN - i); sc->sf_unit = unit; @@ -708,7 +710,12 @@ sf_attach(dev) goto fail; } - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + printf("sf%d: can not if_alloc()\n", sc->sf_unit); + error = ENOSPC; + goto fail; + } ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_mtu = ETHERMTU; @@ -730,7 +737,7 @@ sf_attach(dev) /* * Call MI attach routine. */ - ether_ifattach(ifp, sc->arpcom.ac_enaddr); + ether_ifattach(ifp, eaddr); /* Hook interrupt last to avoid having to lock softc */ error = bus_setup_intr(dev, sc->sf_irq, INTR_TYPE_NET, @@ -739,6 +746,7 @@ sf_attach(dev) if (error) { printf("sf%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); + if_free(ifp); goto fail; } @@ -766,12 +774,13 @@ sf_detach(dev) sc = device_get_softc(dev); KASSERT(mtx_initialized(&sc->sf_mtx), ("sf mutex not initialized")); SF_LOCK(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; /* These should only be active if attach succeeded */ if (device_is_attached(dev)) { sf_stop(sc); ether_ifdetach(ifp); + if_free(ifp); } if (sc->sf_miibus) device_delete_child(dev, sc->sf_miibus); @@ -904,7 +913,7 @@ sf_rxeof(sc) SF_LOCK_ASSERT(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; rxcons = csr_read_4(sc, SF_CQ_CONSIDX); rxprod = csr_read_4(sc, SF_RXDQ_PTR_Q1); @@ -973,7 +982,7 @@ sf_txeof(sc) struct sf_tx_bufdesc_type0 *cur_tx; struct ifnet *ifp; - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; txcons = csr_read_4(sc, SF_CQ_CONSIDX); cmpprodidx = SF_IDX_HI(csr_read_4(sc, SF_CQ_PRODIDX)); @@ -1098,7 +1107,7 @@ sf_intr(arg) sc = arg; SF_LOCK(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; #ifdef DEVICE_POLLING if (ifp->if_flags & IFF_POLLING) @@ -1173,7 +1182,7 @@ sf_init(xsc) sc = xsc; SF_LOCK(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; mii = device_get_softc(sc->sf_miibus); sf_stop(sc); @@ -1190,9 +1199,9 @@ sf_init(xsc) (i + sizeof(u_int32_t)), 0); /* Init our MAC address */ - csr_write_4(sc, SF_PAR0, *(u_int32_t *)(&sc->arpcom.ac_enaddr[0])); - csr_write_4(sc, SF_PAR1, *(u_int32_t *)(&sc->arpcom.ac_enaddr[4])); - sf_setperf(sc, 0, (caddr_t)&sc->arpcom.ac_enaddr); + csr_write_4(sc, SF_PAR0, *(u_int32_t *)(&IFP2ENADDR(sc->sf_ifp)[0])); + csr_write_4(sc, SF_PAR1, *(u_int32_t *)(&IFP2ENADDR(sc->sf_ifp)[4])); + sf_setperf(sc, 0, (caddr_t)&IFP2ENADDR(sc->sf_ifp)); if (sf_init_rx_ring(sc) == ENOBUFS) { printf("sf%d: initialization failed: no " @@ -1435,7 +1444,7 @@ sf_stop(sc) SF_LOCK(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; untimeout(sf_stats_update, sc, sc->sf_stat_ch); @@ -1494,7 +1503,7 @@ sf_stats_update(xsc) sc = xsc; SF_LOCK(sc); - ifp = &sc->arpcom.ac_if; + ifp = sc->sf_ifp; mii = device_get_softc(sc->sf_miibus); ptr = (u_int32_t *)&stats; diff --git a/sys/dev/sf/if_sfreg.h b/sys/dev/sf/if_sfreg.h index 4738f46..bbd704c 100644 --- a/sys/dev/sf/if_sfreg.h +++ b/sys/dev/sf/if_sfreg.h @@ -1031,7 +1031,7 @@ struct sf_list_data { }; struct sf_softc { - struct arpcom arpcom; /* interface info */ + struct ifnet *sf_ifp; /* interface info */ bus_space_handle_t sf_bhandle; /* bus space handle */ bus_space_tag_t sf_btag; /* bus space tag */ void *sf_intrhand; /* interrupt handler cookie */ |