/* Pass a packet up to the higher levels. */ static inline void elread(struct el_softc *sc,caddr_t buf,int len) { register struct ether_header *eh; struct mbuf *m; eh = (struct ether_header *)buf; #if NBPFILTER > 0 /* * Check if there's a bpf filter listening on this interface. * If so, hand off the raw packet to bpf. */ if(sc->bpf) { bpf_tap(sc->bpf,buf,len+sizeof(struct ether_header)); /* * 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. * * This test does not support multicasts. */ if((sc->arpcom.ac_if.if_flags & IFF_PROMISC) && bcmp(eh->ether_dhost,sc->arpcom.ac_enaddr, sizeof(eh->ether_dhost)) != 0 && bcmp(eh->ether_dhost,etherbroadcastaddr, sizeof(eh->ether_dhost)) != 0) return; } #endif /* * Pull packet off interface. */ m = elget(buf,len,0,&sc->arpcom.ac_if); if(m == 0) return; ether_input(&sc->arpcom.ac_if,eh,m); }
/* * icintr() */ static void icintr (device_t dev, int event, char *ptr) { struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev); int unit = device_get_unit(dev); int s, len; struct mbuf *top; s = splhigh(); switch (event) { case INTR_GENERAL: case INTR_START: sc->ic_cp = sc->ic_ifbuf; sc->ic_xfercnt = 0; break; case INTR_STOP: /* if any error occured during transfert, * drop the packet */ if (sc->ic_iferrs) goto err; if ((len = sc->ic_xfercnt) == 0) break; /* ignore */ if (len <= ICHDRLEN) goto err; if (IF_QFULL(&ipintrq)) { IF_DROP(&ipintrq); break; } len -= ICHDRLEN; sc->ic_if.if_ipackets ++; sc->ic_if.if_ibytes += len; if (sc->ic_if.if_bpf) bpf_tap(&sc->ic_if, sc->ic_ifbuf, len + ICHDRLEN); top = m_devget(sc->ic_ifbuf + ICHDRLEN, len, 0, &sc->ic_if, 0); if (top) { IF_ENQUEUE(&ipintrq, top); schednetisr(NETISR_IP); } break; err: printf("ic%d: errors (%d)!\n", unit, sc->ic_iferrs); sc->ic_iferrs = 0; /* reset error count */ sc->ic_if.if_ierrors ++; break; case INTR_RECEIVE: if (sc->ic_xfercnt >= sc->ic_if.if_mtu+ICHDRLEN) { sc->ic_iferrs ++; } else { *sc->ic_cp++ = *ptr; sc->ic_xfercnt ++; } break; case INTR_NOACK: /* xfer terminated by master */ break; case INTR_TRANSMIT: *ptr = 0xff; /* XXX */ break; case INTR_ERROR: sc->ic_iferrs ++; break; default: panic("%s: unknown event (%d)!", __FUNCTION__, event); } splx(s); return; }
void usbpf_xfertap(struct usb_xfer *xfer, int type) { struct usb_bus *bus; struct usbpf_pkthdr *up; struct usbpf_framehdr *uf; usb_frlength_t offset; uint32_t totlen; uint32_t frame; uint32_t temp; uint32_t nframes; uint32_t x; uint8_t *buf; uint8_t *ptr; bus = xfer->xroot->bus; /* sanity checks */ if (bus->ifp == NULL || bus->ifp->if_bpf == NULL) return; if (!bpf_peers_present(bus->ifp->if_bpf)) return; totlen = usbpf_xfer_precompute_size(xfer, type); if (type == USBPF_XFERTAP_SUBMIT) nframes = xfer->nframes; else nframes = xfer->aframes; /* * XXX TODO XXX * * When BPF supports it we could pass a fragmented array of * buffers avoiding the data copy operation here. */ buf = ptr = malloc(totlen, M_TEMP, M_NOWAIT); if (buf == NULL) { device_printf(bus->parent, "usbpf: Out of memory\n"); return; } up = (struct usbpf_pkthdr *)ptr; ptr += USBPF_HDR_LEN; /* fill out header */ temp = device_get_unit(bus->bdev); up->up_totlen = htole32(totlen); up->up_busunit = htole32(temp); up->up_address = xfer->xroot->udev->device_index; if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) up->up_mode = USBPF_MODE_DEVICE; else up->up_mode = USBPF_MODE_HOST; up->up_type = type; up->up_xfertype = xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE; temp = usbpf_aggregate_xferflags(&xfer->flags); up->up_flags = htole32(temp); temp = usbpf_aggregate_status(&xfer->flags_int); up->up_status = htole32(temp); temp = xfer->error; up->up_error = htole32(temp); temp = xfer->interval; up->up_interval = htole32(temp); up->up_frames = htole32(nframes); temp = xfer->max_packet_size; up->up_packet_size = htole32(temp); temp = xfer->max_packet_count; up->up_packet_count = htole32(temp); temp = xfer->endpointno; up->up_endpoint = htole32(temp); up->up_speed = xfer->xroot->udev->speed; /* clear reserved area */ memset(up->up_reserved, 0, sizeof(up->up_reserved)); /* init offset and frame */ offset = 0; frame = 0; /* iterate all the USB frames and copy data, if any */ for (x = 0; x != nframes; x++) { uint32_t length; int isread; /* get length */ length = xfer->frlengths[x]; /* get frame header pointer */ uf = (struct usbpf_framehdr *)ptr; ptr += USBPF_FRAME_HDR_LEN; /* fill out packet header */ uf->length = htole32(length); uf->flags = 0; /* get information about data read/write */ isread = usbpf_xfer_frame_is_read(xfer, x); /* check if we need to copy any data */ if (isread) { if (type == USBPF_XFERTAP_SUBMIT) length = 0; else { uf->flags |= htole32( USBPF_FRAMEFLAG_DATA_FOLLOWS); } } else { if (type != USBPF_XFERTAP_SUBMIT) length = 0; else { uf->flags |= htole32( USBPF_FRAMEFLAG_DATA_FOLLOWS); } } /* check if data is read direction */ if (isread) uf->flags |= htole32(USBPF_FRAMEFLAG_READ); /* copy USB data, if any */ if (length != 0) { /* copy data */ usbd_copy_out(&xfer->frbuffers[frame], offset, ptr, length); /* align length */ temp = USBPF_FRAME_ALIGN(length); /* zero pad */ if (temp != length) memset(ptr + length, 0, temp - length); ptr += temp; } if (xfer->flags_int.isochronous_xfr) { offset += usbd_xfer_old_frame_length(xfer, x); } else { frame ++; } } bpf_tap(bus->ifp->if_bpf, buf, totlen); free(buf, M_TEMP); }
/* Start output on interface. Get datagrams from the queue and output * them, giving the receiver a chance between datagrams. Call only * from splimp or interrupt level! */ void el_start(struct ifnet *ifp) { struct el_softc *sc; u_short base; struct mbuf *m, *m0; int s, i, len, retries, done; /* Get things pointing in the right directions */ sc = &el_softc[ifp->if_unit]; base = sc->el_base; dprintf(("el_start()...\n")); s = splimp(); /* Don't do anything if output is active */ if(sc->arpcom.ac_if.if_flags & IFF_OACTIVE) return; sc->arpcom.ac_if.if_flags |= IFF_OACTIVE; /* The main loop. They warned me against endless loops, but * would I listen? NOOO.... */ while(1) { /* Dequeue the next datagram */ IF_DEQUEUE(&sc->arpcom.ac_if.if_snd,m0); /* If there's nothing to send, return. */ if(m0 == NULL) { sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; splx(s); return; } /* Disable the receiver */ outb(base+EL_AC,EL_AC_HOST); outb(base+EL_RBC,0); /* Copy the datagram to the buffer. */ len = 0; for(m = m0; m != NULL; m = m->m_next) { if(m->m_len == 0) continue; bcopy(mtod(m,caddr_t),sc->el_pktbuf+len,m->m_len); len += m->m_len; } m_freem(m0); len = max(len,ETHER_MIN_LEN); /* Give the packet to the bpf, if any */ #if NBPFILTER > 0 if(sc->bpf) bpf_tap(sc->bpf,sc->el_pktbuf,len); #endif /* Transfer datagram to board */ dprintf(("el: xfr pkt length=%d...\n",len)); i = EL_BUFSIZ - len; outb(base+EL_GPBL,(i & 0xff)); outb(base+EL_GPBH,((i>>8)&0xff)); outsb(base+EL_BUF,sc->el_pktbuf,len); /* Now transmit the datagram */ retries=0; done=0; while(!done) { if(el_xmit(sc,len)) { /* Something went wrong */ done = -1; break; } /* Check out status */ i = inb(base+EL_TXS); dprintf(("tx status=0x%x\n",i)); if(!(i & EL_TXS_READY)) { dprintf(("el: err txs=%x\n",i)); sc->arpcom.ac_if.if_oerrors++; if(i & (EL_TXS_COLL|EL_TXS_COLL16)) { if((!(i & EL_TXC_DCOLL16)) && retries < 15) { retries++; outb(base+EL_AC,EL_AC_HOST); } } else done = 1; } else { sc->arpcom.ac_if.if_opackets++; done = 1; } } if(done == -1) /* Packet not transmitted */ continue; /* Now give the card a chance to receive. * Gotta love 3c501s... */ (void)inb(base+EL_AS); outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX)); splx(s); /* Interrupt here */ s = splimp(); } }