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/txp | |
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/txp')
-rw-r--r-- | sys/dev/txp/if_txp.c | 64 | ||||
-rw-r--r-- | sys/dev/txp/if_txpreg.h | 2 |
2 files changed, 40 insertions, 26 deletions
diff --git a/sys/dev/txp/if_txp.c b/sys/dev/txp/if_txp.c index 749ea44..425bbe5 100644 --- a/sys/dev/txp/if_txp.c +++ b/sys/dev/txp/if_txp.c @@ -217,6 +217,7 @@ txp_attach(dev) u_int16_t p1; u_int32_t p2; int unit, error = 0, rid; + u_char eaddr[6]; sc = device_get_softc(dev); unit = device_get_unit(dev); @@ -266,6 +267,7 @@ txp_attach(dev) if (txp_chip_init(sc)) { txp_release_resources(sc); + /* XXX: set error to ??? */ goto fail; } @@ -286,29 +288,32 @@ txp_attach(dev) if (txp_alloc_rings(sc)) { txp_release_resources(sc); + /* XXX: set error to ??? */ goto fail; } if (txp_command(sc, TXP_CMD_MAX_PKT_SIZE_WRITE, TXP_MAX_PKTLEN, 0, 0, NULL, NULL, NULL, 1)) { txp_release_resources(sc); + /* XXX: set error to ??? */ goto fail; } if (txp_command(sc, TXP_CMD_STATION_ADDRESS_READ, 0, 0, 0, &p1, &p2, NULL, 1)) { txp_release_resources(sc); + /* XXX: set error to ??? */ goto fail; } txp_set_filter(sc); - sc->sc_arpcom.ac_enaddr[0] = ((u_int8_t *)&p1)[1]; - sc->sc_arpcom.ac_enaddr[1] = ((u_int8_t *)&p1)[0]; - sc->sc_arpcom.ac_enaddr[2] = ((u_int8_t *)&p2)[3]; - sc->sc_arpcom.ac_enaddr[3] = ((u_int8_t *)&p2)[2]; - sc->sc_arpcom.ac_enaddr[4] = ((u_int8_t *)&p2)[1]; - sc->sc_arpcom.ac_enaddr[5] = ((u_int8_t *)&p2)[0]; + eaddr[0] = ((u_int8_t *)&p1)[1]; + eaddr[1] = ((u_int8_t *)&p1)[0]; + eaddr[2] = ((u_int8_t *)&p2)[3]; + eaddr[3] = ((u_int8_t *)&p2)[2]; + eaddr[4] = ((u_int8_t *)&p2)[1]; + eaddr[5] = ((u_int8_t *)&p2)[0]; sc->sc_cold = 0; @@ -326,7 +331,13 @@ txp_attach(dev) NULL, NULL, NULL, 0); ifmedia_set(&sc->sc_ifmedia, IFM_ETHER|IFM_AUTO); - ifp = &sc->sc_arpcom.ac_if; + ifp = sc->sc_ifp = if_alloc(IFT_ETHER); + if (ifp == NULL) { + txp_release_resources(sc); + device_printf(dev, "couldn't set up irq\n"); + error = ENOSPC; + goto fail; + } ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_mtu = ETHERMTU; @@ -344,7 +355,7 @@ txp_attach(dev) /* * Attach us everywhere */ - ether_ifattach(ifp, sc->sc_arpcom.ac_enaddr); + ether_ifattach(ifp, eaddr); callout_handle_init(&sc->sc_tick); return(0); @@ -363,7 +374,7 @@ txp_detach(dev) int i; sc = device_get_softc(dev); - ifp = &sc->sc_arpcom.ac_if; + ifp = sc->sc_ifp; txp_stop(sc); txp_shutdown(dev); @@ -388,6 +399,9 @@ txp_release_resources(sc) dev = sc->sc_dev; + if (sc->sc_ifp) + if_free(sc->sc_ifp); + if (sc->sc_intrhand != NULL) bus_teardown_intr(dev, sc->sc_irq, sc->sc_intrhand); @@ -682,7 +696,7 @@ txp_intr(vsc) /* unmask all interrupts */ WRITE_REG(sc, TXP_IMR, TXP_INT_A2H_3); - txp_start(&sc->sc_arpcom.ac_if); + txp_start(sc->sc_ifp); return; } @@ -692,7 +706,7 @@ txp_rx_reclaim(sc, r) struct txp_softc *sc; struct txp_rx_ring *r; { - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; struct txp_rx_desc *rxd; struct mbuf *m; struct txp_swdesc *sd = NULL; @@ -791,7 +805,7 @@ static void txp_rxbuf_reclaim(sc) struct txp_softc *sc; { - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; struct txp_hostvar *hv = sc->sc_hostvar; struct txp_rxbuf_desc *rbd; struct txp_swdesc *sd; @@ -849,7 +863,7 @@ txp_tx_reclaim(sc, r) struct txp_softc *sc; struct txp_tx_ring *r; { - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; u_int32_t idx = TXP_OFFSET2IDX(*(r->r_off)); u_int32_t cons = r->r_cons, cnt = r->r_cnt; struct txp_tx_desc *txd = r->r_desc + cons; @@ -1099,7 +1113,7 @@ txp_rxring_fill(sc) struct ifnet *ifp; struct txp_swdesc *sd; - ifp = &sc->sc_arpcom.ac_if; + ifp = sc->sc_ifp; for (i = 0; i < RXBUF_ENTRIES; i++) { sd = sc->sc_rxbufs[i].rb_sd; @@ -1162,7 +1176,7 @@ txp_init(xsc) int s; sc = xsc; - ifp = &sc->sc_arpcom.ac_if; + ifp = sc->sc_ifp; if (ifp->if_flags & IFF_RUNNING) return; @@ -1175,12 +1189,12 @@ txp_init(xsc) NULL, NULL, NULL, 1); /* Set station address. */ - ((u_int8_t *)&p1)[1] = sc->sc_arpcom.ac_enaddr[0]; - ((u_int8_t *)&p1)[0] = sc->sc_arpcom.ac_enaddr[1]; - ((u_int8_t *)&p2)[3] = sc->sc_arpcom.ac_enaddr[2]; - ((u_int8_t *)&p2)[2] = sc->sc_arpcom.ac_enaddr[3]; - ((u_int8_t *)&p2)[1] = sc->sc_arpcom.ac_enaddr[4]; - ((u_int8_t *)&p2)[0] = sc->sc_arpcom.ac_enaddr[5]; + ((u_int8_t *)&p1)[1] = IFP2ENADDR(sc->sc_ifp)[0]; + ((u_int8_t *)&p1)[0] = IFP2ENADDR(sc->sc_ifp)[1]; + ((u_int8_t *)&p2)[3] = IFP2ENADDR(sc->sc_ifp)[2]; + ((u_int8_t *)&p2)[2] = IFP2ENADDR(sc->sc_ifp)[3]; + ((u_int8_t *)&p2)[1] = IFP2ENADDR(sc->sc_ifp)[4]; + ((u_int8_t *)&p2)[0] = IFP2ENADDR(sc->sc_ifp)[5]; txp_command(sc, TXP_CMD_STATION_ADDRESS_WRITE, p1, p2, 0, NULL, NULL, NULL, 1); @@ -1212,7 +1226,7 @@ txp_tick(vsc) void *vsc; { struct txp_softc *sc = vsc; - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; struct txp_rsp_desc *rsp = NULL; struct txp_ext_desc *ext; int s; @@ -1564,7 +1578,7 @@ txp_stop(sc) { struct ifnet *ifp; - ifp = &sc->sc_arpcom.ac_if; + ifp = sc->sc_ifp; ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); @@ -1737,7 +1751,7 @@ static void txp_set_filter(sc) struct txp_softc *sc; { - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; u_int32_t crc, carry, hashbit, hash[2]; u_int16_t filter; u_int8_t octet; @@ -1803,7 +1817,7 @@ static void txp_capabilities(sc) struct txp_softc *sc; { - struct ifnet *ifp = &sc->sc_arpcom.ac_if; + struct ifnet *ifp = sc->sc_ifp; struct txp_rsp_desc *rsp = NULL; struct txp_ext_desc *ext; diff --git a/sys/dev/txp/if_txpreg.h b/sys/dev/txp/if_txpreg.h index 2d88fc9..df37b51 100644 --- a/sys/dev/txp/if_txpreg.h +++ b/sys/dev/txp/if_txpreg.h @@ -591,7 +591,7 @@ struct txp_ldata { }; struct txp_softc { - struct arpcom sc_arpcom; /* ethernet common */ + struct ifnet *sc_ifp; device_t sc_dev; struct txp_hostvar *sc_hostvar; struct txp_boot_record *sc_boot; |