int kue_send(struct kue_softc *sc, struct mbuf *m, int idx) { int total_len; struct kue_chain *c; usbd_status err; DPRINTFN(10,("%s: %s: enter\n", sc->kue_dev.dv_xname,__func__)); c = &sc->kue_cdata.kue_tx_chain[idx]; /* * Copy the mbuf data into a contiguous buffer, leaving two * bytes at the beginning to hold the frame length. */ m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2); c->kue_mbuf = m; total_len = m->m_pkthdr.len + 2; /* XXX what's this? */ total_len += 64 - (total_len % 64); /* Frame length is specified in the first 2 bytes of the buffer. */ c->kue_buf[0] = (u_int8_t)m->m_pkthdr.len; c->kue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8); usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX], c, c->kue_buf, total_len, USBD_NO_COPY, USBD_DEFAULT_TIMEOUT, kue_txeof); /* Transmit */ err = usbd_transfer(c->kue_xfer); if (err != USBD_IN_PROGRESS) { printf("%s: kue_send error=%s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); kue_stop(sc); return (EIO); } sc->kue_cdata.kue_tx_cnt++; return (0); }
static int kue_send(struct kue_softc *sc, struct mbuf *m, int idx) { int total_len; struct kue_chain *c; usbd_status err; DPRINTFN(10,("%s: %s: enter\n", device_xname(sc->kue_dev),__func__)); c = &sc->kue_cdata.kue_tx_chain[idx]; /* Frame length is specified in the first 2 bytes of the buffer. */ le16enc(c->kue_buf, (uint16_t)m->m_pkthdr.len); /* * Copy the mbuf data into a contiguous buffer, leaving two * bytes at the beginning to hold the frame length. */ m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2); total_len = 2 + m->m_pkthdr.len; total_len = roundup2(total_len, 64); usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX], c, c->kue_buf, total_len, USBD_NO_COPY, USBD_DEFAULT_TIMEOUT, kue_txeof); /* Transmit */ err = usbd_transfer(c->kue_xfer); if (err != USBD_IN_PROGRESS) { printf("%s: kue_send error=%s\n", device_xname(sc->kue_dev), usbd_errstr(err)); kue_stop(sc); return (EIO); } sc->kue_cdata.kue_tx_cnt++; return (0); }
int kue_detach(device_t self, int flags) { struct kue_softc *sc = device_private(self); struct ifnet *ifp = GET_IFP(sc); int s; s = splusb(); /* XXX why? */ if (sc->kue_mcfilters != NULL) { free(sc->kue_mcfilters, M_USBDEV); sc->kue_mcfilters = NULL; } if (!sc->kue_attached) { /* Detached before attached finished, so just bail out. */ splx(s); return (0); } if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); rnd_detach_source(&sc->rnd_source); ether_ifdetach(ifp); if_detach(ifp); #ifdef DIAGNOSTIC if (sc->kue_ep[KUE_ENDPT_TX] != NULL || sc->kue_ep[KUE_ENDPT_RX] != NULL || sc->kue_ep[KUE_ENDPT_INTR] != NULL) aprint_debug_dev(self, "detach has active endpoints\n"); #endif sc->kue_attached = false; splx(s); return (0); }
int kue_detach(struct device *self, int flags) { struct kue_softc *sc = (struct kue_softc *)self; struct ifnet *ifp = GET_IFP(sc); int s; /* Detached before attached finished, so just bail out. */ if (!sc->kue_attached) return (0); s = splusb(); /* XXX why? */ if (sc->kue_mcfilters != NULL) { free(sc->kue_mcfilters, M_USBDEV); sc->kue_mcfilters = NULL; } if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); if (ifp->if_softc != NULL) { ether_ifdetach(ifp); if_detach(ifp); } #ifdef DIAGNOSTIC if (sc->kue_ep[KUE_ENDPT_TX] != NULL || sc->kue_ep[KUE_ENDPT_RX] != NULL || sc->kue_ep[KUE_ENDPT_INTR] != NULL) printf("%s: detach has active endpoints\n", sc->kue_dev.dv_xname); #endif sc->kue_attached = 0; splx(s); return (0); }
int kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct kue_softc *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr *)data; int s, error = 0; DPRINTFN(5,("%s: %s: enter\n", sc->kue_dev.dv_xname,__func__)); if (sc->kue_dying) return (EIO); #ifdef DIAGNOSTIC if (!curproc) { printf("%s: no proc!!\n", sc->kue_dev.dv_xname); return EIO; } #endif s = splnet(); switch(command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; kue_init(sc); switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: arp_ifinit(&sc->arpcom, ifa); break; #endif /* INET */ } break; case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && !(sc->kue_if_flags & IFF_PROMISC)) { sc->kue_rxfilt |= KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (ifp->if_flags & IFF_RUNNING && !(ifp->if_flags & IFF_PROMISC) && sc->kue_if_flags & IFF_PROMISC) { sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (!(ifp->if_flags & IFF_RUNNING)) kue_init(sc); } else { if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); } sc->kue_if_flags = ifp->if_flags; error = 0; break; default: error = ether_ioctl(ifp, &sc->arpcom, command, data); } if (error == ENETRESET) { if (ifp->if_flags & IFF_RUNNING) kue_setmulti(sc); error = 0; } splx(s); return (error); }
Static int kue_ioctl(struct ifnet *ifp, u_long command, void *data) { struct kue_softc *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; int s, error = 0; DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__func__)); if (sc->kue_dying) return (EIO); #ifdef DIAGNOSTIC if (!curproc) { printf("%s: no proc!!\n", USBDEVNAME(sc->kue_dev)); return EIO; } #endif s = splnet(); switch(command) { case SIOCINITIFADDR: ifp->if_flags |= IFF_UP; kue_init(sc); switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: #if defined(__NetBSD__) arp_ifinit(ifp, ifa); #else arp_ifinit(&sc->arpcom, ifa); #endif break; #endif /* INET */ } break; case SIOCSIFMTU: if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > ETHERMTU) error = EINVAL; else if ((error = ifioctl_common(ifp, command, data)) == ENETRESET) error = 0; break; case SIOCSIFFLAGS: if ((error = ifioctl_common(ifp, command, data)) != 0) break; if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && !(sc->kue_if_flags & IFF_PROMISC)) { sc->kue_rxfilt |= KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (ifp->if_flags & IFF_RUNNING && !(ifp->if_flags & IFF_PROMISC) && sc->kue_if_flags & IFF_PROMISC) { sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (!(ifp->if_flags & IFF_RUNNING)) kue_init(sc); } else { if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); } sc->kue_if_flags = ifp->if_flags; error = 0; break; case SIOCADDMULTI: case SIOCDELMULTI: kue_setmulti(sc); error = 0; break; default: error = ether_ioctl(ifp, command, data); break; } splx(s); return (error); }
Static int kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct kue_softc *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr *)data; struct ifreq *ifr = (struct ifreq *)data; int s, error = 0; DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__func__)); if (sc->kue_dying) return (EIO); #ifdef DIAGNOSTIC if (!curproc) { printf("%s: no proc!!\n", USBDEVNAME(sc->kue_dev)); return EIO; } #endif s = splnet(); switch(command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; kue_init(sc); switch (ifa->ifa_addr->sa_family) { #ifdef INET case AF_INET: #if defined(__NetBSD__) arp_ifinit(ifp, ifa); #else arp_ifinit(&sc->arpcom, ifa); #endif break; #endif /* INET */ #ifdef NS case AF_NS: { struct ns_addr *ina = &IA_SNS(ifa)->sns_addr; if (ns_nullhost(*ina)) ina->x_host = *(union ns_host *) LLADDR(ifp->if_sadl); else memcpy(LLADDR(ifp->if_sadl), ina->x_host.c_host, ifp->if_addrlen); break; } #endif /* NS */ } break; case SIOCSIFMTU: if (ifr->ifr_mtu > ETHERMTU) error = EINVAL; else ifp->if_mtu = ifr->ifr_mtu; break; case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { if (ifp->if_flags & IFF_RUNNING && ifp->if_flags & IFF_PROMISC && !(sc->kue_if_flags & IFF_PROMISC)) { sc->kue_rxfilt |= KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (ifp->if_flags & IFF_RUNNING && !(ifp->if_flags & IFF_PROMISC) && sc->kue_if_flags & IFF_PROMISC) { sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); } else if (!(ifp->if_flags & IFF_RUNNING)) kue_init(sc); } else { if (ifp->if_flags & IFF_RUNNING) kue_stop(sc); } sc->kue_if_flags = ifp->if_flags; error = 0; break; case SIOCADDMULTI: case SIOCDELMULTI: kue_setmulti(sc); error = 0; break; default: error = EINVAL; break; } splx(s); return (error); }