diff options
| author | mycroft <mycroft@NetBSD.org> | 1994-05-13 06:13:43 +0000 |
|---|---|---|
| committer | mycroft <mycroft@NetBSD.org> | 1994-05-13 06:13:43 +0000 |
| commit | 949b970c958bb22017fe8aa08dd011a0a9ffefd1 (patch) | |
| tree | 794fdfa78ab7d9f4ec7fc2e7840f196a11345757 /sys/dev | |
| parent | 0ae81ecb6b01e9bd2ab5d3d50f0aa7f6f4463225 (diff) | |
Use ether_ifattach() rather than doing the same thing in each driver.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/isa/if_ed.c | 166 | ||||
| -rw-r--r-- | sys/dev/isa/if_el.c | 144 | ||||
| -rw-r--r-- | sys/dev/isa/if_ep.c | 222 | ||||
| -rw-r--r-- | sys/dev/isa/if_ie.c | 53 |
4 files changed, 101 insertions, 484 deletions
diff --git a/sys/dev/isa/if_ed.c b/sys/dev/isa/if_ed.c index 4b2215c2b07..571b845c6dc 100644 --- a/sys/dev/isa/if_ed.c +++ b/sys/dev/isa/if_ed.c @@ -13,7 +13,7 @@ * Currently supports the Western Digital/SMC 8003 and 8013 series, the 3Com * 3c503, the NE1000 and NE2000, and a variety of similar clones. * - * $Id: if_ed.c,v 1.46 1994/05/11 12:09:17 mycroft Exp $ + * $Id: if_ed.c,v 1.47 1994/05/13 06:13:43 mycroft Exp $ */ #include "bpfilter.h" @@ -87,7 +87,6 @@ struct ed_softc { u_char isa16bit; /* width of access to card 0=8 or 1=16 */ u_char is790; /* set by probe if NIC is a 790 */ - caddr_t bpf; /* BPF "magic cookie" */ caddr_t mem_start; /* NIC memory start address */ caddr_t mem_end; /* NIC memory end address */ u_long mem_size; /* total NIC memory size */ @@ -130,11 +129,6 @@ void ed_pio_readmem __P((/* struct ed_softc *, u_short, caddr_t, u_short */)); void ed_pio_writemem __P((/* struct ed_softc *, caddr_t, u_short, u_short */)); u_short ed_pio_write_mbufs __P((/* struct ed_softc *, struct mbuf *, u_short */)); -struct trailer_header { - u_short ether_type; - u_short ether_residual; -}; - struct cfdriver edcd = { NULL, "ed", edprobe, edattach, DV_IFNET, sizeof(struct ed_softc) }; @@ -1005,8 +999,6 @@ edattach(parent, self, aux) struct isa_attach_args *ia = aux; struct cfdata *cf = sc->sc_dev.dv_cfdata; struct ifnet *ifp = &sc->sc_arpcom.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; /* Set interface to stopped condition (reset). */ ed_stop(sc); @@ -1014,10 +1006,6 @@ edattach(parent, self, aux) /* Initialize ifnet structure. */ ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_name = edcd.cd_name; - ifp->if_type = IFT_ETHER; - ifp->if_addrlen = ETHER_ADDR_LEN; - ifp->if_hdrlen = 14; - ifp->if_mtu = ETHERMTU; ifp->if_output = ether_output; ifp->if_start = ed_start; ifp->if_ioctl = ed_ioctl; @@ -1044,27 +1032,7 @@ edattach(parent, self, aux) /* Attach the interface. */ if_attach(ifp); - - /* - * Search down the ifa address list looking for the AF_LINK type entry - * and initialize it. - */ - ifa = ifp->if_addrlist; - while (ifa && ifa->ifa_addr) { - if (ifa->ifa_addr->sa_family == AF_LINK) { - /* - * Fill in the link-level address for this interface. - */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(sc->sc_arpcom.ac_enaddr, LLADDR(sdl), - ETHER_ADDR_LEN); - break; - } else - ifa = ifa->ifa_next; - } + ether_ifattach(ifp); /* Print additional info when attached. */ printf(": address %s, ", ether_sprintf(sc->sc_arpcom.ac_enaddr)); @@ -1091,7 +1059,7 @@ edattach(parent, self, aux) printf("\n"); #if NBPFILTER > 0 - bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); + bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif sc->sc_ih.ih_fun = edintr; @@ -1471,67 +1439,9 @@ outloop: ed_xmit(sc); #if NBPFILTER > 0 - /* - * If there is BPF support in the configuration, tap off here. - * The following has support for converting trailer packets back to - * normal. - * XXX - Support for trailer packets in BPF should be moved into the - * bpf code proper to avoid code duplication in all of the drivers. - */ - if (sc->bpf) { - u_short etype; - int off, datasize, resid; - struct ether_header *eh; - struct trailer_header trailer_header; - u_char ether_packet[ETHER_MAX_LEN], *ep; - - ep = ether_packet; - - /* - * We handle trailers below: - * Copy ether header first, then residual data, then data. Put - * all this in a temporary buffer 'ether_packet' and send off - * to bpf. Since the system has generated this packet, we - * assume that all of the offsets in the packet are correct; if - * they're not, the system will almost certainly crash in - * m_copydata. We make no assumptions about how the data is - * arranged in the mbuf chain (i.e. how much data is in each - * mbuf, if mbuf clusters are used, etc.), which is why we use - * m_copydata to get the ether header rather than assume that - * this is located in the first mbuf. - */ - /* copy ether header */ - m_copydata(m0, 0, sizeof(struct ether_header), ep); - eh = (struct ether_header *) ep; - ep += sizeof(struct ether_header); - etype = ntohs(eh->ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - datasize = (etype - ETHERTYPE_TRAIL) << 9; - off = datasize + sizeof(struct ether_header); - - /* copy trailer_header into a data structure */ - m_copydata(m0, off, sizeof(struct trailer_header), - &trailer_header.ether_type); - - /* copy residual data */ - m_copydata(m0, off+sizeof(struct trailer_header), - resid = ntohs(trailer_header.ether_residual) - - sizeof(struct trailer_header), ep); - ep += resid; - - /* copy data */ - m_copydata(m0, sizeof(struct ether_header), datasize, - ep); - ep += datasize; - - /* restore original ether packet type */ - eh->ether_type = trailer_header.ether_type; - - bpf_tap(sc->bpf, ether_packet, ep - ether_packet); - } else - bpf_mtap(sc->bpf, m0); - } + /* If there is BPF support in the configuration, tap off here. */ + if (sc->sc_arpcom.ac_if.if_bpf) + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m0); #endif m_freem(m0); @@ -1952,10 +1862,6 @@ ed_get_packet(sc, buf, len) { struct ether_header *eh; struct mbuf *m, *head = 0, *ed_ring_to_mbuf(); - u_short off; - int resid; - u_short etype; - struct trailer_header trailer_header; /* Allocate a header mbuf. */ MGETHDR(m, M_DONTWAIT, MT_DATA); @@ -1986,68 +1892,18 @@ ed_get_packet(sc, buf, len) head->m_len += sizeof(struct ether_header); len -= sizeof(struct ether_header); - etype = ntohs(eh->ether_type); - - /* - * Deal with trailer protocol: - * If trailer protocol, calculate the datasize as 'off', which is also - * the offset to the trailer header. Set resid to the amount of packet - * data following the trailer header. Finally, copy residual data into - * mbuf chain. - */ - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - off = (etype - ETHERTYPE_TRAIL) << 9; - if ((off + sizeof(struct trailer_header)) > len) - goto bad; /* insanity */ - - /* - * If we have shared memory, we can get info directly from the - * stored packet, otherwise we must get a local copy of the - * trailer header using PIO. - */ - if (sc->mem_shared) { - eh->ether_type = *ringoffset(sc, buf, off, u_short *); - resid = ntohs(*ringoffset(sc, buf, off+2, u_short *)); - } else { - struct trailer_header trailer_header; - ed_pio_readmem(sc, - (u_short)ringoffset(sc, buf, off, caddr_t), - (caddr_t) &trailer_header, sizeof(trailer_header)); - eh->ether_type = trailer_header.ether_type; - resid = trailer_header.ether_residual; - } - - if ((off + resid) > len) - goto bad; /* insanity */ - - resid -= sizeof(struct trailer_header); - if (resid < 0) - goto bad; /* insanity */ - - m = ed_ring_to_mbuf(sc, ringoffset(sc, buf, off+4, caddr_t), - head, resid); - if (m == 0) - goto bad; - - len = off; - head->m_pkthdr.len -= 4; /* subtract trailer header */ - } - - /* - * Pull packet off interface. Or if this was a trailer packet, the - * data portion is appended. - */ + /* Pull packet off interface. */ m = ed_ring_to_mbuf(sc, buf, m, len); - if (m == 0) goto bad; + if (m == 0) + goto bad; #if NBPFILTER > 0 /* * Check if there's a BPF listener on this interface. If so, hand off * the raw packet to bpf. */ - if (sc->bpf) { - bpf_mtap(sc->bpf, head); + if (sc->sc_arpcom.ac_if.if_bpf) { + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, head); /* * Note that the interface cannot be in promiscuous mode if diff --git a/sys/dev/isa/if_el.c b/sys/dev/isa/if_el.c index 745867e4a55..0d6d28e08a9 100644 --- a/sys/dev/isa/if_el.c +++ b/sys/dev/isa/if_el.c @@ -9,7 +9,7 @@ /* * 3COM Etherlink 3C501 device driver * - * $Id: if_el.c,v 1.12 1994/05/11 12:09:21 mycroft Exp $ + * $Id: if_el.c,v 1.13 1994/05/13 06:13:48 mycroft Exp $ */ /* @@ -77,7 +77,6 @@ struct el_softc { struct arpcom sc_arpcom; /* ethernet common */ u_short sc_iobase; /* base I/O addr */ - caddr_t sc_bpf; /* BPF magic cookie */ char sc_pktbuf[EL_BUFSIZ]; /* frame buffer */ }; @@ -93,7 +92,7 @@ static void el_reset __P((struct el_softc *)); static void el_stop __P((struct el_softc *)); static int el_xmit __P((struct el_softc *, int)); static inline void elread __P((struct el_softc *, caddr_t, int)); -static struct mbuf *elget __P((caddr_t, int, int, struct ifnet *)); +static struct mbuf *elget __P((caddr_t, int, struct ifnet *)); static inline void el_hardreset __P((struct el_softc *)); int elprobe(); @@ -104,11 +103,6 @@ struct cfdriver elcd = { NULL, "el", elprobe, elattach, DV_IFNET, sizeof(struct el_softc) }; -struct trailer_header { - u_short ether_type; - u_short ether_residual; -}; - /* * Probe routine. * @@ -185,8 +179,6 @@ elattach(parent, self, aux) struct el_softc *sc = (void *)self; struct isa_attach_args *ia = aux; struct ifnet *ifp = &sc->sc_arpcom.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; dprintf(("Attaching %s...\n", sc->sc_dev.dv_xname)); @@ -196,10 +188,6 @@ elattach(parent, self, aux) /* Initialize ifnet structure. */ ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_name = elcd.cd_name; - ifp->if_type = IFT_ETHER; - ifp->if_addrlen = ETHER_ADDR_LEN; - ifp->if_hdrlen = 14; - ifp->if_mtu = ETHERMTU; ifp->if_output = ether_output; ifp->if_start = el_start; ifp->if_ioctl = el_ioctl; @@ -209,27 +197,7 @@ elattach(parent, self, aux) /* Now we can attach the interface. */ dprintf(("Attaching interface...\n")); if_attach(ifp); - - /* - * Put the station address in the ifa address list's AF_LINK entry, if - * any. - */ - ifa = ifp->if_addrlist; - while (ifa && ifa->ifa_addr) { - if (ifa->ifa_addr->sa_family == AF_LINK) { - /* - * Fill in the link-level address for this interface. - */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(sc->sc_arpcom.ac_enaddr, LLADDR(sdl), - ETHER_ADDR_LEN); - break; - } else - ifa = ifa->ifa_next; - } + ether_ifattach(ifp); /* Print out some information for the user. */ printf("%s: address %s\n", sc->sc_dev.dv_xname, @@ -238,7 +206,7 @@ elattach(parent, self, aux) /* Finally, attach to bpf filter if it is present. */ #if NBPFILTER > 0 dprintf(("Attaching to BPF...\n")); - bpfattach(&sc->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); + bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif sc->sc_ih.ih_fun = elintr; @@ -396,8 +364,8 @@ el_start(ifp) /* Give the packet to the bpf, if any. */ #if NBPFILTER > 0 - if (sc->sc_bpf) - bpf_tap(sc->sc_bpf, sc->sc_pktbuf, len); + if (sc->sc_arpcom.ac_if.if_bpf) + bpf_tap(sc->sc_arpcom.ac_if.if_bpf, sc->sc_pktbuf, len); #endif /* Transfer datagram to board. */ @@ -561,7 +529,6 @@ elintr(sc) dprintf(("%s\n", ether_sprintf(sc->sc_pktbuf))); /* Pass data up to upper levels. */ - len -= sizeof(struct ether_header); elread(sc, (caddr_t)sc->sc_pktbuf, len); /* Is there another packet? */ @@ -580,7 +547,7 @@ elintr(sc) } /* - * Pass a packet up to the higher levels. Deal with trailer protocol. + * Pass a packet up to the higher levels. */ static inline void elread(sc, buf, len) @@ -590,90 +557,56 @@ elread(sc, buf, len) { register struct ether_header *eh; struct mbuf *m; - int off, resid; - u_short etype; - /* - * Deal with trailer protocol: if type is trailer type get true type - * from first 16-bit word past data. Remember that type was trailer by - * setting off. - */ eh = (struct ether_header *)buf; - etype = ntohs(eh->ether_type); -#define eldataaddr(eh, off, type) ((type)(((caddr_t)((eh)+1)+(off)))) - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { - off = (etype - ETHERTYPE_TRAIL) << 9; - if ((off + sizeof(struct trailer_header)) > len) - return; - eh->ether_type = *eldataaddr(eh, off, u_short *); - resid = ntohs(*eldataaddr(eh, off+2, u_short *)); - if ((off + resid) > len) - return; - len = off + resid; - } else - off = 0; - + len -= sizeof(struct ether_header); if (len <= 0) return; + /* Pull packet off interface. */ + m = elget(buf, len, &sc->sc_arpcom.ac_if); + if (m == 0) + return; + #if NBPFILTER > 0 /* - * Check if there's a bpf filter listening on this interface. If so, - * hand off the raw packet to bpf, which must deal with trailers in its - * own way. - * - * Comparing to if_ed, this code does bpf on trailer packets - * incorrectly -- the ether type's already been copied over... - * XXX - cgd + * Check if there's a BPF listener on this interface. + * If so, hand off the raw packet to bpf. */ - if (sc->sc_bpf) { - bpf_tap(sc->sc_bpf, buf, len + sizeof(struct ether_header)); + if (sc->sc_arpcom.ac_if.if_bpf) { + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m); /* * Note that the interface cannot be in promiscuous mode if - * there are no bpf listeners. And if el are in promiscuous - * mode, el have to check if this packet is really ours. - * - * XXX This test does not support multicasts. + * there are no BPF listeners. And if we are in promiscuous + * mode, we have to check if this packet is really ours. */ if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) && + (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */ bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr, - sizeof(eh->ether_dhost)) != 0 && - bcmp(eh->ether_dhost, etherbroadcastaddr, - sizeof(eh->ether_dhost)) != 0) + sizeof(eh->ether_dhost)) != 0) { + m_freem(m); return; + } } #endif - /* - * Pull packet off interface. Off is nonzero if packet has trailing - * header; neget will then force this header information to be at the - * front, but we still have to drop the type and length which are at - * the front of any trailer data. - */ - m = elget(buf, len, off, &sc->sc_arpcom.ac_if); - if (!m) - return; - ether_input(&sc->sc_arpcom.ac_if, eh, m); } /* * Pull read data off a interface. Len is length of data, with local net - * header stripped. Off is non-zero if a trailer protocol was used, and gives - * the offset of the trailer information. We copy the trailer information and - * then all the normal data into mbufs. When full cluster sized units are - * present we copy into clusters. + * header stripped. We copy the data into mbufs. When full cluster sized + * units are present we copy into clusters. */ struct mbuf * -elget(buf, totlen, off0, ifp) +elget(buf, totlen, ifp) caddr_t buf; - int totlen, off0; + int totlen; struct ifnet *ifp; { struct mbuf *top, **mp, *m, *p; - int off = off0, len; + int len; register caddr_t cp = buf; char *epkt; @@ -681,19 +614,15 @@ elget(buf, totlen, off0, ifp) cp = buf; epkt = cp + totlen; - if (off) { - cp += off + 2 * sizeof(u_short); - totlen -= 2 * sizeof(u_short); - } - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (!m) + if (m == 0) return 0; m->m_pkthdr.rcvif = ifp; m->m_pkthdr.len = totlen; m->m_len = MHLEN; top = 0; mp = ⊤ + while (totlen > 0) { if (top) { MGET(m, M_DONTWAIT, MT_DATA); @@ -729,6 +658,7 @@ elget(buf, totlen, off0, ifp) if (cp == epkt) cp = buf; } + return top; } @@ -736,19 +666,19 @@ elget(buf, totlen, off0, ifp) * Process an ioctl request. This code needs some work - it looks pretty ugly. */ static int -el_ioctl(ifp, command, data) +el_ioctl(ifp, cmd, data) register struct ifnet *ifp; - int command; + int cmd; caddr_t data; { struct el_softc *sc = elcd.cd_devs[ifp->if_unit]; - register struct ifaddr *ifa = (struct ifaddr *)data; + struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; int s, error = 0; s = splimp(); - switch (command) { + switch (cmd) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; @@ -799,14 +729,14 @@ el_ioctl(ifp, command, data) case SIOCSIFFLAGS: if ((ifp->if_flags & IFF_UP) == 0 && - (ifp->if_flags & IFF_RUNNING)) { + (ifp->if_flags & IFF_RUNNING) != 0) { /* * If interface is marked down and it is running, then * stop it. */ el_stop(sc); ifp->if_flags &= ~IFF_RUNNING; - } else if ((ifp->if_flags & IFF_UP) && + } else if ((ifp->if_flags & IFF_UP) != 0 && (ifp->if_flags & IFF_RUNNING) == 0) { /* * If interface is marked up and it is stopped, then diff --git a/sys/dev/isa/if_ep.c b/sys/dev/isa/if_ep.c index e2415438398..128f303797f 100644 --- a/sys/dev/isa/if_ep.c +++ b/sys/dev/isa/if_ep.c @@ -21,7 +21,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: if_ep.c,v 1.36 1994/05/11 12:09:23 mycroft Exp $ + * $Id: if_ep.c,v 1.37 1994/05/13 06:13:52 mycroft Exp $ */ #include "bpfilter.h" @@ -76,7 +76,7 @@ struct ep_softc { struct device sc_dev; struct intrhand sc_ih; - struct arpcom ep_ac; /* Ethernet common part */ + struct arpcom sc_arpcom; /* Ethernet common part */ short ep_iobase; /* i/o bus address */ char ep_connectors; /* Connectors on this card. */ #define MAX_MBS 8 /* # of mbufs we keep around */ @@ -85,7 +85,6 @@ struct ep_softc { int last_mb; /* Last mbuf. */ int tx_start_thresh; /* Current TX_start_thresh. */ int tx_succ_ok; /* # packets sent in sequence w/o underrun */ - caddr_t bpf; /* BPF "magic cookie" */ char bus32bit; /* 32bit access possible */ }; @@ -273,9 +272,7 @@ epattach(parent, self, aux) { struct ep_softc *sc = (void *)self; struct isa_attach_args *ia = aux; - struct ifnet *ifp = &sc->ep_ac.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; u_short i; printf(": "); @@ -314,50 +311,27 @@ epattach(parent, self, aux) outw(BASE + EP_W0_EEPROM_COMMAND, READ_EEPROM | i); if (epbusyeeprom(sc)) return; - p = (u_short *) & sc->ep_ac.ac_enaddr[i * 2]; + p = (u_short *) & sc->sc_arpcom.ac_enaddr[i * 2]; *p = htons(inw(BASE + EP_W0_EEPROM_DATA)); GO_WINDOW(2); outw(BASE + EP_W2_ADDR_0 + (i * 2), ntohs(*p)); } - printf(" address %s\n", ether_sprintf(sc->ep_ac.ac_enaddr)); + printf(" address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_name = epcd.cd_name; - ifp->if_type = IFT_ETHER; - ifp->if_addrlen = ETHER_ADDR_LEN; - ifp->if_hdrlen = 14; - ifp->if_mtu = ETHERMTU; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | - IFF_MULTICAST; + ifp->if_flags = + IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; ifp->if_output = ether_output; ifp->if_start = epstart; ifp->if_ioctl = epioctl; ifp->if_watchdog = epwatchdog; if_attach(ifp); - - /* - * Search down the ifa address list looking for the AF_LINK type entry - * and initialize it. - */ - ifa = ifp->if_addrlist; - while (ifa && ifa->ifa_addr) { - if (ifa->ifa_addr->sa_family == AF_LINK) { - /* - * Fill in the link-level address for this interface. - */ - sdl = (struct sockaddr_dl *) ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(sc->ep_ac.ac_enaddr, LLADDR(sdl), ETHER_ADDR_LEN); - break; - } else - ifa = ifa->ifa_next; - } + ether_ifattach(ifp); #if NBPFILTER > 0 - bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); + bpfattach(&sc->sc_arpcom.ac_if.if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif sc->tx_start_thresh = 20; /* probably a good starting point. */ @@ -376,7 +350,7 @@ static void epinit(sc) register struct ep_softc *sc; { - register struct ifnet *ifp = &sc->ep_ac.ac_if; + register struct ifnet *ifp = &sc->sc_arpcom.ac_if; int s, i; if (ifp->if_addrlist == 0) @@ -393,7 +367,7 @@ epinit(sc) GO_WINDOW(2); for (i = 0; i < 6; i++) /* Reload the ether_addr. */ - outb(BASE + EP_W2_ADDR_0 + i, sc->ep_ac.ac_enaddr[i]); + outb(BASE + EP_W2_ADDR_0 + i, sc->sc_arpcom.ac_enaddr[i]); outw(BASE + EP_COMMAND, RX_RESET); outw(BASE + EP_COMMAND, TX_RESET); @@ -430,7 +404,7 @@ static void epsetfilter(sc) register struct ep_softc *sc; { - register struct ifnet *ifp = &sc->ep_ac.ac_if; + register struct ifnet *ifp = &sc->sc_arpcom.ac_if; GO_WINDOW(1); /* Window 1 is operating window */ outw(BASE + EP_COMMAND, SET_RX_FILTER | @@ -443,7 +417,7 @@ static void epsetlink(sc) register struct ep_softc *sc; { - register struct ifnet *ifp = &sc->ep_ac.ac_if; + register struct ifnet *ifp = &sc->sc_arpcom.ac_if; /* * you can `ifconfig (link0|-link0) ep0' to get the following @@ -482,14 +456,14 @@ epstart(ifp) int s, len, pad; s = splimp(); - if (sc->ep_ac.ac_if.if_flags & IFF_OACTIVE) { + if (sc->sc_arpcom.ac_if.if_flags & IFF_OACTIVE) { splx(s); return (0); } startagain: /* Sneak a peek at the next packet */ - m = sc->ep_ac.ac_if.if_snd.ifq_head; + m = sc->sc_arpcom.ac_if.if_snd.ifq_head; if (m == 0) { splx(s); return (0); @@ -510,8 +484,8 @@ startagain: */ if (len + pad > ETHER_MAX_LEN) { /* packet is obviously too large: toss it */ - +sc->ep_ac.ac_if.if_oerrors; - IF_DEQUEUE(&sc->ep_ac.ac_if.if_snd, m); + +sc->sc_arpcom.ac_if.if_oerrors; + IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m); m_freem(m); goto readcheck; } @@ -519,7 +493,7 @@ startagain: outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4)); if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) { /* not enough room in FIFO */ - sc->ep_ac.ac_if.if_flags |= IFF_OACTIVE; + sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE; splx(s); return (0); } else { @@ -527,7 +501,7 @@ startagain: outw(BASE + EP_COMMAND, ACK_INTR | S_TX_AVAIL); } - IF_DEQUEUE(&sc->ep_ac.ac_if.if_snd, m); + IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m); if (m == 0) { /* not really needed */ splx(s); return (0); @@ -557,73 +531,12 @@ startagain: outb(BASE + EP_W1_TX_PIO_WR_1, 0); /* Padding */ #if NBPFILTER > 0 - if (sc->bpf) { - u_short etype; - int off, datasize, resid; - struct ether_header *eh; - struct trailer_header { - u_short ether_type; - u_short ether_residual; - } trailer_header; - char ether_packet[ETHER_MAX_LEN]; - char *ep; - - ep = ether_packet; - - /* - * We handle trailers below: - * Copy ether header first, then residual data, - * then data. Put all this in a temporary buffer - * 'ether_packet' and send off to bpf. Since the - * system has generated this packet, we assume - * that all of the offsets in the packet are - * correct; if they're not, the system will almost - * certainly crash in m_copydata. - * We make no assumptions about how the data is - * arranged in the mbuf chain (i.e. how much - * data is in each mbuf, if mbuf clusters are - * used, etc.), which is why we use m_copydata - * to get the ether header rather than assume - * that this is located in the first mbuf. - */ - /* copy ether header */ - m_copydata(top, 0, sizeof(struct ether_header), ep); - eh = (struct ether_header *) ep; - ep += sizeof(struct ether_header); - etype = ntohs(eh->ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER) { - datasize = ((etype - ETHERTYPE_TRAIL) << 9); - off = datasize + sizeof(struct ether_header); - - /* copy trailer_header into a data structure */ - m_copydata(top, off, sizeof(struct trailer_header), - &trailer_header.ether_type); - - /* copy residual data */ - resid = trailer_header.ether_residual - - sizeof(struct trailer_header); - resid = ntohs(resid); - m_copydata(top, off + sizeof(struct trailer_header), - resid, ep); - ep += resid; - - /* copy data */ - m_copydata(top, sizeof(struct ether_header), - datasize, ep); - ep += datasize; - - /* restore original ether packet type */ - eh->ether_type = trailer_header.ether_type; - - bpf_tap(sc->bpf, ether_packet, ep - ether_packet); - } else - bpf_mtap(sc->bpf, top); - } + if (sc->sc_arpcom.ac_if.if_bpf) + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, top); #endif m_freem(top); - ++sc->ep_ac.ac_if.if_opackets; + ++sc->sc_arpcom.ac_if.if_opackets; /* * Is another packet coming in? We don't want to overflow the @@ -641,7 +554,7 @@ int epintr(sc) register struct ep_softc *sc; { - struct ifnet *ifp = &sc->ep_ac.ac_if; + struct ifnet *ifp = &sc->sc_arpcom.ac_if; u_short status; int i, ret = 0; @@ -656,8 +569,8 @@ epintr(sc) epread(sc); if (status & S_TX_AVAIL) { inw(BASE + EP_W1_FREE_TX); - sc->ep_ac.ac_if.if_flags &= ~IFF_OACTIVE; - epstart(&sc->ep_ac.ac_if); + sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE; + epstart(&sc->sc_arpcom.ac_if); } if (status & S_CARD_FAILURE) { printf("%s: adapter failure (%x)\n", @@ -675,13 +588,13 @@ epintr(sc) outw(BASE + EP_W1_TX_STATUS, 0x0); if (i & TXS_JABBER) { - ++sc->ep_ac.ac_if.if_oerrors; + ++sc->sc_arpcom.ac_if.if_oerrors; untimeout(epmbuffill, sc); printf("%s: jabber (%x %x)\n", sc->sc_dev.dv_xname, status, i); epreset(sc); } else if (i & TXS_UNDERRUN) { - ++sc->ep_ac.ac_if.if_oerrors; + ++sc->sc_arpcom.ac_if.if_oerrors; untimeout(epmbuffill, sc); printf("%s: fifo underrun (%x %x), correcting\n", sc->sc_dev.dv_xname, status, i); @@ -691,9 +604,9 @@ epintr(sc) sc->tx_succ_ok = 0; epreset(sc); } else if (i & TXS_MAX_COLLISION) { - ++sc->ep_ac.ac_if.if_collisions; + ++sc->sc_arpcom.ac_if.if_collisions; outw(BASE + EP_COMMAND, TX_ENABLE); - sc->ep_ac.ac_if.if_flags &= ~IFF_OACTIVE; + sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE; } else sc->tx_succ_ok = (sc->tx_succ_ok+1) & 128; @@ -715,15 +628,13 @@ epread(sc) struct ether_header *eh; struct mbuf *mcur, *m, *m0, *top; int totlen, lenthisone; - int save_totlen, off; - u_short etype; + int save_totlen; totlen = inw(BASE + EP_W1_RX_STATUS); - off = 0; top = 0; if (totlen & ERR_RX) { - ++sc->ep_ac.ac_if.if_ierrors; + ++sc->sc_arpcom.ac_if.if_ierrors; goto out; } save_totlen = totlen &= RX_BYTES_MASK; /* Lower 11 bits = RX bytes. */ @@ -750,29 +661,7 @@ epread(sc) mtod(m0, caddr_t), sizeof(struct ether_header) / 2); m->m_len = sizeof(struct ether_header); totlen -= sizeof(struct ether_header); - /* - * mostly deal with trailer here. (untested) - * We do this in a couple of parts. First we check for a trailer, if - * we have one we convert the mbuf back to a regular mbuf and set the offset and - * subtract sizeof(struct ether_header) from the pktlen. - * After we've read the packet off the interface (all except for the trailer - * header, we then get a header mbuf, read the trailer into it, and fix up - * the mbuf pointer chain. - */ eh = mtod(m, struct ether_header *); - etype = ntohs((u_short) eh->ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER) { - m->m_data = m->m_dat; /* Convert back to regular mbuf. */ - m->m_flags = 0; /* This sucks but non-trailers are the norm */ - off = (etype - ETHERTYPE_TRAIL) * 512; - if (off >= ETHERMTU) { - m_freem(m); - return; /* sanity */ - } - totlen -= sizeof(struct ether_header); /* We don't read the trailer */ - m->m_data += 2 * sizeof(u_short); /* Get rid of type & len */ - } while (totlen > 0) { lenthisone = min(totlen, M_TRAILINGSPACE(m)); if (lenthisone == 0) { /* no room in this one */ @@ -811,50 +700,25 @@ epread(sc) } totlen -= lenthisone; } - if (off) { - top = sc->mb[sc->next_mb]; - sc->mb[sc->next_mb] = 0; - if (top == 0) { - MGETHDR(top, M_DONTWAIT, MT_DATA); - if (top == 0) { - top = m0; /* Fix up the chain so we can free it */ - goto out; - } - } else { /* Convert one of our saved mbuf's */ - sc->next_mb = (sc->next_mb + 1) % MAX_MBS; - top->m_data = top->m_pktdat; - top->m_flags = M_PKTHDR; - } - insw(BASE + EP_W1_RX_PIO_RD_1, mtod(top, caddr_t), - sizeof(struct ether_header) / 2); - top->m_next = m0; - top->m_len = sizeof(struct ether_header); - /* XXX Accomodate for type and len from beginning of trailer */ - top->m_pkthdr.len = save_totlen - (2 * sizeof(u_short)); - } else { - top = m0; - top->m_pkthdr.len = save_totlen; - } - - top->m_pkthdr.rcvif = &sc->ep_ac.ac_if; + top = m0; + top->m_pkthdr.len = save_totlen; + top->m_pkthdr.rcvif = &sc->sc_arpcom.ac_if; outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK); while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS) ; - ++sc->ep_ac.ac_if.if_ipackets; + ++sc->sc_arpcom.ac_if.if_ipackets; #if NBPFILTER > 0 - if (sc->bpf) { - bpf_mtap(sc->bpf, top); + if (sc->sc_arpcom.ac_if.if_bpf) { + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, top); /* * Note that the interface cannot be in promiscuous mode if * there are no BPF listeners. And if we are in promiscuous * mode, we have to check if this packet is really ours. */ - if ((sc->ep_ac.ac_if.if_flags & IFF_PROMISC) && + if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) && (eh->ether_dhost[0] & 1) == 0 && - bcmp(eh->ether_dhost, sc->ep_ac.ac_enaddr, - sizeof(eh->ether_dhost)) != 0 && - bcmp(eh->ether_dhost, etherbroadcastaddr, + bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr, sizeof(eh->ether_dhost)) != 0) { m_freem(top); return; @@ -862,7 +726,7 @@ epread(sc) } #endif m_adj(top, sizeof(struct ether_header)); - ether_input(&sc->ep_ac.ac_if, eh, top); + ether_input(&sc->sc_arpcom.ac_if, eh, top); return; out: outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK); @@ -905,12 +769,12 @@ epioctl(ifp, cmd, data) if (ns_nullhost(*ina)) ina->x_host = - *(union ns_host *)(sc->ep_ac.ac_enaddr); + *(union ns_host *)(sc->sc_arpcom.ac_enaddr); else { ifp->if_flags &= ~IFF_RUNNING; bcopy(ina->x_host.c_host, - sc->ep_ac.ac_enaddr, - sizeof(sc->ep_ac.ac_enaddr)); + sc->sc_arpcom.ac_enaddr, + sizeof(sc->sc_arpcom.ac_enaddr)); } epinit(sc); break; diff --git a/sys/dev/isa/if_ie.c b/sys/dev/isa/if_ie.c index 9e89816aab1..46510a16f6d 100644 --- a/sys/dev/isa/if_ie.c +++ b/sys/dev/isa/if_ie.c @@ -40,7 +40,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: if_ie.c,v 1.10 1994/05/11 12:09:25 mycroft Exp $ + * $Id: if_ie.c,v 1.11 1994/05/13 06:13:55 mycroft Exp $ */ /* @@ -246,9 +246,6 @@ struct ie_softc { #ifdef IEDEBUG int sc_debug; #endif -#if NBPFILTER > 0 - caddr_t sc_bpf; -#endif }; int iewatchdog __P((/* short */)); @@ -523,15 +520,9 @@ ieattach(parent, self, aux) struct ie_softc *sc = (void *)self; struct isa_attach_args *ia = aux; struct ifnet *ifp = &sc->sc_arpcom.ac_if; - struct ifaddr *ifa; - struct sockaddr_dl *sdl; ifp->if_unit = sc->sc_dev.dv_unit; ifp->if_name = iecd.cd_name; - ifp->if_type = IFT_ETHER; - ifp->if_addrlen = ETHER_ADDR_LEN; - ifp->if_hdrlen = 14; - ifp->if_mtu = ETHERMTU; ifp->if_output = ether_output; ifp->if_start = iestart; ifp->if_ioctl = ieioctl; @@ -541,33 +532,14 @@ ieattach(parent, self, aux) /* Attach the interface. */ if_attach(ifp); - - /* - * Search down the ifa address list looking for the AF_LINK type entry. - */ - ifa = ifp->if_addrlist; - while (ifa && ifa->ifa_addr) { - if (ifa->ifa_addr->sa_family == AF_LINK) { - /* - * Fill in the link level address for this interface. - */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ETHER; - sdl->sdl_alen = ETHER_ADDR_LEN; - sdl->sdl_slen = 0; - bcopy(sc->sc_arpcom.ac_enaddr, LLADDR(sdl), - ETHER_ADDR_LEN); - break; - } else - ifa = ifa->ifa_next; - } + ether_ifattach(ifp); printf(": address %s, type %s R%d\n", ether_sprintf(sc->sc_arpcom.ac_enaddr), ie_hardware_names[sc->hard_type], sc->hard_vers + 1); #if NBPFILTER > 0 - bpfattach(&sc->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); + bpfattach(&sc->sc_arpcom.ac_if.if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif sc->sc_ih.ih_fun = ieintr; @@ -823,7 +795,7 @@ check_eh(sc, eh, to_bpf) * Receiving all multicasts, but no unicasts except those destined for us. */ #if NBPFILTER > 0 - *to_bpf = (sc->sc_bpf != 0); /* BPF gets this packet if anybody cares */ + *to_bpf = (sc->sc_arpcom.ac_if.if_bpf != 0); /* BPF gets this packet if anybody cares */ #endif if (eh->ether_dhost[0] & 1) return 1; @@ -835,7 +807,7 @@ check_eh(sc, eh, to_bpf) * Receiving all packets. These need to be passed on to BPF. */ #if NBPFILTER > 0 - *to_bpf = (sc->sc_bpf != 0); + *to_bpf = (sc->sc_arpcom.ac_if.if_bpf != 0); #endif /* If for us, accept and hand up to BPF */ if (ether_equal(eh->ether_dhost, sc->sc_arpcom.ac_enaddr)) return 1; @@ -872,7 +844,7 @@ check_eh(sc, eh, to_bpf) * Whew! (Hope this is a fast machine...) */ #if NBPFILTER > 0 - *to_bpf = (sc->sc_bpf != 0); + *to_bpf = (sc->sc_arpcom.ac_if.if_bpf != 0); #endif /* We want to see multicasts. */ if (eh->ether_dhost[0] & 1) @@ -898,7 +870,7 @@ check_eh(sc, eh, to_bpf) * as quickly as possible. */ #if NBPFILTER > 0 - *to_bpf = (sc->sc_bpf != 0); + *to_bpf = (sc->sc_arpcom.ac_if.if_bpf != 0); #endif return 1; } @@ -1139,7 +1111,6 @@ ie_readframe(sc, num) struct ie_recv_frame_desc rfd; struct mbuf *m = 0; struct ether_header eh; - u_short etype; #if NBPFILTER > 0 int bpf_gets_it = 0; #endif @@ -1169,10 +1140,6 @@ ie_readframe(sc, num) if (sc->sc_debug & IED_READFRAME) printf("%s: frame from ether %s type %x\n", sc->sc_dev.dv_xname, ether_sprintf(eh.ether_shost), (u_int)eh.ether_type); - etype = ntohs(eh.ether_type); - if (etype >= ETHERTYPE_TRAIL && - etype < ETHERTYPE_TRAIL + ETHERTYPE_NTRAILER) - printf("%s: received trailer!\n", sc->sc_dev.dv_xname); #endif if (!m) @@ -1199,7 +1166,7 @@ ie_readframe(sc, num) m0.m_next = m; /* Pass it up */ - bpf_mtap(sc->sc_bpf, &m0); + bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, &m0); } /* * A signal passed up from the filtering code indicating that the @@ -1297,8 +1264,8 @@ iestart(ifp) * See if bpf is listening on this interface, let it see the packet * before we commit it to the wire. */ - if (sc->sc_bpf) - bpf_tap(sc->sc_bpf, sc->xmit_cbuffs[sc->xmit_count], + if (sc->sc_arpcom.ac_if.if_bpf) + bpf_tap(sc->sc_arpcom.ac_if.if_bpf, sc->xmit_cbuffs[sc->xmit_count], len); #endif |
