/* detach */ int url_detach(device_t self, int flags) { struct url_softc *sc = device_private(self); struct ifnet *ifp = GET_IFP(sc); int s; DPRINTF(("%s: %s: enter\n", device_xname(sc->sc_dev), __func__)); /* Detached before attached finished */ if (!sc->sc_attached) return (0); callout_stop(&sc->sc_stat_ch); /* Remove any pending tasks */ usb_rem_task(sc->sc_udev, &sc->sc_tick_task); usb_rem_task(sc->sc_udev, &sc->sc_stop_task); s = splusb(); if (--sc->sc_refcnt >= 0) { /* Wait for processes to go away */ usb_detach_waitold(sc->sc_dev); } if (ifp->if_flags & IFF_RUNNING) url_stop(GET_IFP(sc), 1); rnd_detach_source(&sc->rnd_source); mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY); ether_ifdetach(ifp); if_detach(ifp); #ifdef DIAGNOSTIC if (sc->sc_pipe_tx != NULL) aprint_debug_dev(self, "detach has active tx endpoint.\n"); if (sc->sc_pipe_rx != NULL) aprint_debug_dev(self, "detach has active rx endpoint.\n"); if (sc->sc_pipe_intr != NULL) aprint_debug_dev(self, "detach has active intr endpoint.\n"); #endif sc->sc_attached = 0; splx(s); rw_destroy(&sc->sc_mii_rwlock); usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev); return (0); }
int ugl_detach(struct device *self, int flags) { struct ugl_softc *sc = (struct ugl_softc *)self; struct ifnet *ifp = GET_IFP(sc); int s; DPRINTFN(2,("%s: %s: enter\n", sc->sc_dev.dv_xname, __func__)); s = splusb(); if (ifp->if_flags & IFF_RUNNING) ugl_stop(sc); if (ifp->if_softc != NULL) if_detach(ifp); #ifdef DIAGNOSTIC if (sc->sc_ep[UGL_ENDPT_TX] != NULL || sc->sc_ep[UGL_ENDPT_RX] != NULL || sc->sc_ep[UGL_ENDPT_INTR] != NULL) printf("%s: detach has active endpoints\n", sc->sc_dev.dv_xname); #endif splx(s); return (0); }
void cdcef_txeof(struct usbf_xfer *xfer, void *priv, usbf_status err) { struct cdcef_softc *sc = priv; struct ifnet *ifp = GET_IFP(sc); int s; s = splnet(); #if 0 printf("cdcef_txeof: xfer=%p, priv=%p, %s\n", xfer, priv, usbf_errstr(err)); #endif ifp->if_timer = 0; ifp->if_flags &= ~IFF_OACTIVE; if (sc->sc_xmit_mbuf != NULL) { m_freem(sc->sc_xmit_mbuf); sc->sc_xmit_mbuf = NULL; } if (err) ifp->if_oerrors++; else ifp->if_opackets++; if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) timeout_add(&sc->start_to, 1); /* XXX */ splx(s); }
Static void url_setmulti(struct url_softc *sc) { struct ifnet *ifp; struct ether_multi *enm; struct ether_multistep step; u_int32_t hashes[2] = { 0, 0 }; int h = 0; int mcnt = 0; DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__)); if (sc->sc_dying) return; ifp = GET_IFP(sc); if (ifp->if_flags & IFF_PROMISC) { URL_SETBIT2(sc, URL_RCR, URL_RCR_AAM|URL_RCR_AAP); return; } else if (ifp->if_flags & IFF_ALLMULTI) { allmulti: ifp->if_flags |= IFF_ALLMULTI; URL_SETBIT2(sc, URL_RCR, URL_RCR_AAM); URL_CLRBIT2(sc, URL_RCR, URL_RCR_AAP); return; } /* first, zot all the existing hash bits */ url_csr_write_4(sc, URL_MAR0, 0); url_csr_write_4(sc, URL_MAR4, 0); /* now program new ones */ ETHER_FIRST_MULTI(step, &sc->sc_ac, enm); while (enm != NULL) { if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN) != 0) goto allmulti; h = url_calchash(enm->enm_addrlo); if (h < 32) hashes[0] |= (1 << h); else hashes[1] |= (1 << (h -32)); mcnt++; ETHER_NEXT_MULTI(step, enm); } ifp->if_flags &= ~IFF_ALLMULTI; URL_CLRBIT2(sc, URL_RCR, URL_RCR_AAM|URL_RCR_AAP); if (mcnt){ URL_SETBIT2(sc, URL_RCR, URL_RCR_AM); } else { URL_CLRBIT2(sc, URL_RCR, URL_RCR_AM); } url_csr_write_4(sc, URL_MAR0, hashes[0]); url_csr_write_4(sc, URL_MAR4, hashes[1]); }
/* * Stop the adapter and free any mbufs allocated to the * RX and TX lists. */ void ugl_stop(struct ugl_softc *sc) { struct ifnet *ifp; int i; DPRINTFN(10,("%s: %s: enter\n", sc->sc_dev.dv_xname,__func__)); ifp = GET_IFP(sc); ifp->if_timer = 0; ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); /* Stop transfers. */ if (sc->sc_ep[UGL_ENDPT_RX] != NULL) { usbd_abort_pipe(sc->sc_ep[UGL_ENDPT_RX]); usbd_close_pipe(sc->sc_ep[UGL_ENDPT_RX]); sc->sc_ep[UGL_ENDPT_RX] = NULL; } if (sc->sc_ep[UGL_ENDPT_TX] != NULL) { usbd_abort_pipe(sc->sc_ep[UGL_ENDPT_TX]); usbd_close_pipe(sc->sc_ep[UGL_ENDPT_TX]); sc->sc_ep[UGL_ENDPT_TX] = NULL; } if (sc->sc_ep[UGL_ENDPT_INTR] != NULL) { usbd_abort_pipe(sc->sc_ep[UGL_ENDPT_INTR]); usbd_close_pipe(sc->sc_ep[UGL_ENDPT_INTR]); sc->sc_ep[UGL_ENDPT_INTR] = NULL; } /* Free RX resources. */ for (i = 0; i < UGL_RX_LIST_CNT; i++) { if (sc->sc_cdata.ugl_rx_chain[i].ugl_mbuf != NULL) { m_freem(sc->sc_cdata.ugl_rx_chain[i].ugl_mbuf); sc->sc_cdata.ugl_rx_chain[i].ugl_mbuf = NULL; } if (sc->sc_cdata.ugl_rx_chain[i].ugl_xfer != NULL) { usbd_free_xfer(sc->sc_cdata.ugl_rx_chain[i].ugl_xfer); sc->sc_cdata.ugl_rx_chain[i].ugl_xfer = NULL; } } /* Free TX resources. */ for (i = 0; i < UGL_TX_LIST_CNT; i++) { if (sc->sc_cdata.ugl_tx_chain[i].ugl_mbuf != NULL) { m_freem(sc->sc_cdata.ugl_tx_chain[i].ugl_mbuf); sc->sc_cdata.ugl_tx_chain[i].ugl_mbuf = NULL; } if (sc->sc_cdata.ugl_tx_chain[i].ugl_xfer != NULL) { usbd_free_xfer(sc->sc_cdata.ugl_tx_chain[i].ugl_xfer); sc->sc_cdata.ugl_tx_chain[i].ugl_xfer = NULL; } } }
void cdcef_start_timeout (void *v) { struct cdcef_softc *sc = v; struct ifnet *ifp = GET_IFP(sc); int s; s = splnet(); cdcef_start(ifp); splx(s); }
void cdcef_init(struct cdcef_softc *sc) { struct ifnet *ifp = GET_IFP(sc); int s; s = splnet(); ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; splx(s); }
Static void cdce_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct ue_chain *c = priv; struct cdce_softc *sc = c->ue_sc; struct ifnet *ifp; usbd_status err; CDCE_LOCK(sc); ifp = GET_IFP(sc); if (sc->cdce_dying || !(ifp->if_flags & IFF_RUNNING)) { CDCE_UNLOCK(sc); return; } if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { CDCE_UNLOCK(sc); return; } ifp->if_oerrors++; printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall(sc->cdce_bulkout_pipe); CDCE_UNLOCK(sc); return; } ifp->if_flags &= ~IFF_OACTIVE; usbd_get_xfer_status(c->ue_xfer, NULL, NULL, NULL, &err); if (c->ue_mbuf != NULL) { c->ue_mbuf->m_pkthdr.rcvif = ifp; usb_tx_done(c->ue_mbuf); c->ue_mbuf = NULL; } if (err) ifp->if_oerrors++; else ifp->if_opackets++; CDCE_UNLOCK(sc); return; }
void cdcef_stop(struct cdcef_softc *sc) { struct ifnet *ifp = GET_IFP(sc); ifp->if_timer = 0; ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); /* cancel receive pipe? */ if (sc->sc_xmit_mbuf != NULL) { m_freem(sc->sc_xmit_mbuf); sc->sc_xmit_mbuf = NULL; } }
Static void url_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct url_chain *c = priv; struct url_softc *sc = c->url_sc; struct ifnet *ifp = GET_IFP(sc); int s; if (sc->sc_dying) return; s = splnet(); DPRINTF(("%s: %s: enter\n", device_xname(sc->sc_dev), __func__)); ifp->if_timer = 0; ifp->if_flags &= ~IFF_OACTIVE; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { splx(s); return; } ifp->if_oerrors++; printf("%s: usb error on tx: %s\n", device_xname(sc->sc_dev), usbd_errstr(status)); if (status == USBD_STALLED) { sc->sc_refcnt++; usbd_clear_endpoint_stall_async(sc->sc_pipe_tx); if (--sc->sc_refcnt < 0) usb_detach_wakeupold(sc->sc_dev); } splx(s); return; } ifp->if_opackets++; m_freem(c->url_mbuf); c->url_mbuf = NULL; if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) url_start(ifp); splx(s); }
Static void kue_setmulti(struct kue_softc *sc) { struct ifnet *ifp = GET_IFP(sc); struct ether_multi *enm; struct ether_multistep step; int i; DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __func__)); if (ifp->if_flags & IFF_PROMISC) { allmulti: ifp->if_flags |= IFF_ALLMULTI; sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI; sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); return; } sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI; i = 0; #if defined (__NetBSD__) ETHER_FIRST_MULTI(step, &sc->kue_ec, enm); #else ETHER_FIRST_MULTI(step, &sc->arpcom, enm); #endif while (enm != NULL) { if (i == KUE_MCFILTCNT(sc) || memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN) != 0) goto allmulti; memcpy(KUE_MCFILT(sc, i), enm->enm_addrlo, ETHER_ADDR_LEN); ETHER_NEXT_MULTI(step, enm); i++; } ifp->if_flags &= ~IFF_ALLMULTI; sc->kue_rxfilt |= KUE_RXFILT_MULTICAST; kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS, i, sc->kue_mcfilters, i * ETHER_ADDR_LEN); kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); }
Static void cdce_stop(struct cdce_softc *sc) { usbd_status err; struct ifnet *ifp; CDCE_LOCK(sc); cdce_reset(sc); ifp = GET_IFP(sc); ifp->if_timer = 0; if (sc->cdce_bulkin_pipe != NULL) { err = usbd_abort_pipe(sc->cdce_bulkin_pipe); if (err) printf("%s: abort rx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); err = usbd_close_pipe(sc->cdce_bulkin_pipe); if (err) printf("%s: close rx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); sc->cdce_bulkin_pipe = NULL; } if (sc->cdce_bulkout_pipe != NULL) { err = usbd_abort_pipe(sc->cdce_bulkout_pipe); if (err) printf("%s: abort tx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); err = usbd_close_pipe(sc->cdce_bulkout_pipe); if (err) printf("%s: close tx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); sc->cdce_bulkout_pipe = NULL; } usb_ether_rx_list_free(&sc->cdce_cdata); usb_ether_tx_list_free(&sc->cdce_cdata); ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); CDCE_UNLOCK(sc); return; }
Static void kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct kue_chain *c = priv; struct kue_softc *sc = c->kue_sc; struct ifnet *ifp = GET_IFP(sc); int s; if (sc->kue_dying) return; s = splnet(); DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->kue_dev), __func__, status)); ifp->if_timer = 0; ifp->if_flags &= ~IFF_OACTIVE; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { splx(s); return; } ifp->if_oerrors++; printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->kue_dev), usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall_async(sc->kue_ep[KUE_ENDPT_TX]); splx(s); return; } ifp->if_opackets++; m_freem(c->kue_mbuf); c->kue_mbuf = NULL; if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) kue_start(ifp); splx(s); }
/* * A frame was downloaded to the chip. It's safe for us to clean up * the list buffers. */ void ugl_txeof(struct usbd_xfer *xfer, void *priv, usbd_status status) { struct ugl_chain *c = priv; struct ugl_softc *sc = c->ugl_sc; struct ifnet *ifp = GET_IFP(sc); int s; if (usbd_is_dying(sc->sc_udev)) return; s = splnet(); DPRINTFN(10,("%s: %s: enter status=%d\n", sc->sc_dev.dv_xname, __func__, status)); ifp->if_timer = 0; ifp->if_flags &= ~IFF_OACTIVE; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { splx(s); return; } ifp->if_oerrors++; printf("%s: usb error on tx: %s\n", sc->sc_dev.dv_xname, usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall_async(sc->sc_ep[UGL_ENDPT_TX]); splx(s); return; } ifp->if_opackets++; m_freem(c->ugl_mbuf); c->ugl_mbuf = NULL; if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) ugl_start(ifp); splx(s); }
Static void url_tick_task(void *xsc) { struct url_softc *sc = xsc; struct ifnet *ifp; struct mii_data *mii; int s; if (sc == NULL) return; DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__)); if (sc->sc_dying) return; ifp = GET_IFP(sc); mii = GET_MII(sc); if (mii == NULL) return; s = splnet(); mii_tick(mii); if (!sc->sc_link) { mii_pollstat(mii); if (mii->mii_media_status & IFM_ACTIVE && IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { DPRINTF(("%s: %s: got link\n", USBDEVNAME(sc->sc_dev), __func__)); sc->sc_link++; if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) url_start(ifp); } } usb_callout(sc->sc_stat_ch, hz, url_tick, sc); splx(s); }
int url_activate(device_ptr_t self, enum devact act) { struct url_softc *sc = (struct url_softc *)self; DPRINTF(("%s: %s: enter, act=%d\n", USBDEVNAME(sc->sc_dev), __func__, act)); switch (act) { case DVACT_ACTIVATE: break; case DVACT_DEACTIVATE: if_deactivate(GET_IFP(sc)); sc->sc_dying = 1; break; } return (0); }
void kue_setmulti(struct kue_softc *sc) { struct arpcom *ac = &sc->arpcom; struct ifnet *ifp = GET_IFP(sc); struct ether_multi *enm; struct ether_multistep step; int i; DPRINTFN(5,("%s: %s: enter\n", sc->kue_dev.dv_xname, __func__)); if (ifp->if_flags & IFF_PROMISC || ac->ac_multirangecnt > 0) { allmulti: ifp->if_flags |= IFF_ALLMULTI; sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI; sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); return; } sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI; i = 0; ETHER_FIRST_MULTI(step, ac, enm); while (enm != NULL) { if (i == KUE_MCFILTCNT(sc)) goto allmulti; memcpy(KUE_MCFILT(sc, i), enm->enm_addrlo, ETHER_ADDR_LEN); ETHER_NEXT_MULTI(step, enm); i++; } ifp->if_flags &= ~IFF_ALLMULTI; sc->kue_rxfilt |= KUE_RXFILT_MULTICAST; kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS, i, sc->kue_mcfilters, i * ETHER_ADDR_LEN); kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); }
void ugl_init(void *xsc) { struct ugl_softc *sc = xsc; struct ifnet *ifp = GET_IFP(sc); int s; if (usbd_is_dying(sc->sc_udev)) return; DPRINTFN(10,("%s: %s: enter\n", sc->sc_dev.dv_xname,__func__)); s = splnet(); /* Init TX ring. */ if (ugl_tx_list_init(sc) == ENOBUFS) { printf("%s: tx list init failed\n", sc->sc_dev.dv_xname); splx(s); return; } /* Init RX ring. */ if (ugl_rx_list_init(sc) == ENOBUFS) { printf("%s: rx list init failed\n", sc->sc_dev.dv_xname); splx(s); return; } if (sc->sc_ep[UGL_ENDPT_RX] == NULL) { if (ugl_openpipes(sc)) { splx(s); return; } } ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; splx(s); }
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); }
void ugl_intr(struct usbd_xfer *xfer, void *priv, usbd_status status) { struct ugl_softc *sc = priv; struct ifnet *ifp = GET_IFP(sc); int i; DPRINTFN(15,("%s: %s: enter\n", sc->sc_dev.dv_xname,__func__)); if (usbd_is_dying(sc->sc_udev)) return; if (!(ifp->if_flags & IFF_RUNNING)) return; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { return; } sc->sc_intr_errs++; if (usbd_ratecheck(&sc->sc_rx_notice)) { printf("%s: %u usb errors on intr: %s\n", sc->sc_dev.dv_xname, sc->sc_rx_errs, usbd_errstr(status)); sc->sc_intr_errs = 0; } if (status == USBD_STALLED) usbd_clear_endpoint_stall_async(sc->sc_ep[UGL_ENDPT_RX]); return; } DPRINTFN(10,("%s: %s:", sc->sc_dev.dv_xname, __func__)); for (i = 0; i < UGL_INTR_PKTLEN; i++) DPRINTFN(10,(" 0x%02x", sc->sc_ibuf[i])); DPRINTFN(10,("\n")); }
void kue_init(void *xsc) { struct kue_softc *sc = xsc; struct ifnet *ifp = GET_IFP(sc); int s; u_char *eaddr; DPRINTFN(5,("%s: %s: enter\n", sc->kue_dev.dv_xname,__func__)); if (ifp->if_flags & IFF_RUNNING) return; s = splnet(); eaddr = sc->arpcom.ac_enaddr; /* Set MAC address */ kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC, 0, eaddr, ETHER_ADDR_LEN); sc->kue_rxfilt = KUE_RXFILT_UNICAST | KUE_RXFILT_BROADCAST; /* If we want promiscuous mode, set the allframes bit. */ if (ifp->if_flags & IFF_PROMISC) sc->kue_rxfilt |= KUE_RXFILT_PROMISC; kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); /* I'm not sure how to tune these. */ #if 0 /* * Leave this one alone for now; setting it * wrong causes lockups on some machines/controllers. */ kue_setword(sc, KUE_CMD_SET_SOFS, 1); #endif kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64); /* Init TX ring. */ if (kue_tx_list_init(sc) == ENOBUFS) { printf("%s: tx list init failed\n", sc->kue_dev.dv_xname); splx(s); return; } /* Init RX ring. */ if (kue_rx_list_init(sc) == ENOBUFS) { printf("%s: rx list init failed\n", sc->kue_dev.dv_xname); splx(s); return; } /* Load the multicast filter. */ kue_setmulti(sc); if (sc->kue_ep[KUE_ENDPT_RX] == NULL) { if (kue_open_pipes(sc)) { splx(s); return; } } ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; splx(s); }
/* * A frame has been uploaded: pass the resulting mbuf chain up to * the higher level protocols. */ void kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct kue_chain *c = priv; struct kue_softc *sc = c->kue_sc; struct ifnet *ifp = GET_IFP(sc); struct mbuf *m; int total_len = 0; int s; DPRINTFN(10,("%s: %s: enter status=%d\n", sc->kue_dev.dv_xname, __func__, status)); if (sc->kue_dying) return; if (!(ifp->if_flags & IFF_RUNNING)) return; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) return; sc->kue_rx_errs++; if (usbd_ratecheck(&sc->kue_rx_notice)) { printf("%s: %u usb errors on rx: %s\n", sc->kue_dev.dv_xname, sc->kue_rx_errs, usbd_errstr(status)); sc->kue_rx_errs = 0; } if (status == USBD_STALLED) usbd_clear_endpoint_stall_async(sc->kue_ep[KUE_ENDPT_RX]); goto done; } usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); DPRINTFN(10,("%s: %s: total_len=%d len=%d\n", sc->kue_dev.dv_xname, __func__, total_len, UGETW(mtod(c->kue_mbuf, u_int8_t *)))); if (total_len <= 1) goto done; m = c->kue_mbuf; /* copy data to mbuf */ memcpy(mtod(m, char *), c->kue_buf, total_len); /* No errors; receive the packet. */ total_len = UGETW(mtod(m, u_int8_t *)); m_adj(m, sizeof(u_int16_t)); if (total_len < sizeof(struct ether_header)) { ifp->if_ierrors++; goto done; } ifp->if_ipackets++; m->m_pkthdr.len = m->m_len = total_len; m->m_pkthdr.rcvif = ifp; s = splnet(); /* XXX ugly */ if (kue_newbuf(sc, c, NULL) == ENOBUFS) { ifp->if_ierrors++; goto done1; } #if NBPFILTER > 0 /* * Handle BPF listeners. Let the BPF user see the packet, but * don't pass it up to the ether_input() layer unless it's * a broadcast packet, multicast packet, matches our ethernet * address or the interface is in promiscuous mode. */ if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_IN); #endif DPRINTFN(10,("%s: %s: deliver %d\n", sc->kue_dev.dv_xname, __func__, m->m_len)); ether_input_mbuf(ifp, m); done1: splx(s); done: /* Setup new transfer. */ usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX], c, c->kue_buf, KUE_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT, kue_rxeof); usbd_transfer(c->kue_xfer); DPRINTFN(10,("%s: %s: start rx\n", sc->kue_dev.dv_xname, __func__)); }
void kue_attachhook(void *xsc) { struct kue_softc *sc = xsc; int s; struct ifnet *ifp; usbd_device_handle dev = sc->kue_udev; usbd_interface_handle iface; usbd_status err; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; int i; /* Load the firmware into the NIC. */ if (kue_load_fw(sc)) { printf("%s: loading firmware failed\n", sc->kue_dev.dv_xname); return; } err = usbd_device2interface_handle(dev, KUE_IFACE_IDX, &iface); if (err) { printf("%s: getting interface handle failed\n", sc->kue_dev.dv_xname); return; } sc->kue_iface = iface; id = usbd_get_interface_descriptor(iface); /* Find endpoints. */ for (i = 0; i < id->bNumEndpoints; i++) { ed = usbd_interface2endpoint_descriptor(iface, i); if (ed == NULL) { printf("%s: couldn't get ep %d\n", sc->kue_dev.dv_xname, i); return; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress; } } if (sc->kue_ed[KUE_ENDPT_RX] == 0 || sc->kue_ed[KUE_ENDPT_TX] == 0) { printf("%s: missing endpoint\n", sc->kue_dev.dv_xname); return; } /* Read ethernet descriptor */ err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR, 0, &sc->kue_desc, sizeof(sc->kue_desc)); if (err) { printf("%s: could not read Ethernet descriptor\n", sc->kue_dev.dv_xname); return; } sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN, M_USBDEV, M_NOWAIT); if (sc->kue_mcfilters == NULL) { printf("%s: no memory for multicast filter buffer\n", sc->kue_dev.dv_xname); return; } s = splnet(); /* * A KLSI chip was detected. Inform the world. */ printf("%s: address %s\n", sc->kue_dev.dv_xname, ether_sprintf(sc->kue_desc.kue_macaddr)); bcopy(sc->kue_desc.kue_macaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); /* Initialize interface info.*/ ifp = GET_IFP(sc); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = kue_ioctl; ifp->if_start = kue_start; ifp->if_watchdog = kue_watchdog; strlcpy(ifp->if_xname, sc->kue_dev.dv_xname, IFNAMSIZ); IFQ_SET_READY(&ifp->if_snd); /* Attach the interface. */ if_attach(ifp); ether_ifattach(ifp); sc->kue_attached = 1; splx(s); }
/* * Stop the adapter and free any mbufs allocated to the * RX and TX lists. */ void kue_stop(struct kue_softc *sc) { usbd_status err; struct ifnet *ifp; int i; DPRINTFN(5,("%s: %s: enter\n", sc->kue_dev.dv_xname,__func__)); ifp = GET_IFP(sc); ifp->if_timer = 0; ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); /* Stop transfers. */ if (sc->kue_ep[KUE_ENDPT_RX] != NULL) { err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]); if (err) { printf("%s: abort rx pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]); if (err) { printf("%s: close rx pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } sc->kue_ep[KUE_ENDPT_RX] = NULL; } if (sc->kue_ep[KUE_ENDPT_TX] != NULL) { err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]); if (err) { printf("%s: abort tx pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]); if (err) { printf("%s: close tx pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } sc->kue_ep[KUE_ENDPT_TX] = NULL; } if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) { err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]); if (err) { printf("%s: abort intr pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]); if (err) { printf("%s: close intr pipe failed: %s\n", sc->kue_dev.dv_xname, usbd_errstr(err)); } sc->kue_ep[KUE_ENDPT_INTR] = NULL; } /* Free RX resources. */ for (i = 0; i < KUE_RX_LIST_CNT; i++) { if (sc->kue_cdata.kue_rx_chain[i].kue_mbuf != NULL) { m_freem(sc->kue_cdata.kue_rx_chain[i].kue_mbuf); sc->kue_cdata.kue_rx_chain[i].kue_mbuf = NULL; } if (sc->kue_cdata.kue_rx_chain[i].kue_xfer != NULL) { usbd_free_xfer(sc->kue_cdata.kue_rx_chain[i].kue_xfer); sc->kue_cdata.kue_rx_chain[i].kue_xfer = NULL; } } /* Free TX resources. */ for (i = 0; i < KUE_TX_LIST_CNT; i++) { if (sc->kue_cdata.kue_tx_chain[i].kue_mbuf != NULL) { m_freem(sc->kue_cdata.kue_tx_chain[i].kue_mbuf); sc->kue_cdata.kue_tx_chain[i].kue_mbuf = NULL; } if (sc->kue_cdata.kue_tx_chain[i].kue_xfer != NULL) { usbd_free_xfer(sc->kue_cdata.kue_tx_chain[i].kue_xfer); sc->kue_cdata.kue_tx_chain[i].kue_xfer = NULL; } } }
Static void cdce_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct ue_chain *c = priv; struct cdce_softc *sc = c->ue_sc; struct ifnet *ifp; struct mbuf *m; int total_len = 0; CDCE_LOCK(sc); ifp = GET_IFP(sc); if (sc->cdce_dying || !(ifp->if_flags & IFF_RUNNING)) { CDCE_UNLOCK(sc); return; } if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { CDCE_UNLOCK(sc); return; } if (sc->cdce_rxeof_errors == 0) printf("%s: usb error on rx: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall(sc->cdce_bulkin_pipe); DELAY(sc->cdce_rxeof_errors * 10000); sc->cdce_rxeof_errors++; goto done; } sc->cdce_rxeof_errors = 0; usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); if (sc->cdce_flags & CDCE_ZAURUS) total_len -= 4; /* Strip off CRC added by Zaurus */ m = c->ue_mbuf; if (total_len < sizeof(struct ether_header)) { ifp->if_ierrors++; goto done; } ifp->if_ipackets++; m->m_pkthdr.rcvif = (struct ifnet *)&sc->q; m->m_pkthdr.len = m->m_len = total_len; /* Put the packet on the special USB input queue. */ usb_ether_input(m); CDCE_UNLOCK(sc); return; done: /* Setup new transfer. */ usbd_setup_xfer(c->ue_xfer, sc->cdce_bulkin_pipe, c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cdce_rxeof); usbd_transfer(c->ue_xfer); CDCE_UNLOCK(sc); return; }
Static void cdce_init(void *xsc) { struct cdce_softc *sc = xsc; struct ifnet *ifp = GET_IFP(sc); struct ue_chain *c; usbd_status err; int i; if (ifp->if_flags & IFF_RUNNING) return; CDCE_LOCK(sc); cdce_reset(sc); if (usb_ether_tx_list_init(sc, &sc->cdce_cdata, sc->cdce_udev) == ENOBUFS) { printf("%s: tx list init failed\n", USBDEVNAME(sc->cdce_dev)); CDCE_UNLOCK(sc); return; } if (usb_ether_rx_list_init(sc, &sc->cdce_cdata, sc->cdce_udev) == ENOBUFS) { printf("%s: rx list init failed\n", USBDEVNAME(sc->cdce_dev)); CDCE_UNLOCK(sc); return; } /* Maybe set multicast / broadcast here??? */ err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkin_no, USBD_EXCLUSIVE_USE, &sc->cdce_bulkin_pipe); if (err) { printf("%s: open rx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); CDCE_UNLOCK(sc); return; } err = usbd_open_pipe(sc->cdce_data_iface, sc->cdce_bulkout_no, USBD_EXCLUSIVE_USE, &sc->cdce_bulkout_pipe); if (err) { printf("%s: open tx pipe failed: %s\n", USBDEVNAME(sc->cdce_dev), usbd_errstr(err)); CDCE_UNLOCK(sc); return; } for (i = 0; i < UE_RX_LIST_CNT; i++) { c = &sc->cdce_cdata.ue_rx_chain[i]; usbd_setup_xfer(c->ue_xfer, sc->cdce_bulkin_pipe, c, mtod(c->ue_mbuf, char *), UE_BUFSZ, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, cdce_rxeof); usbd_transfer(c->ue_xfer); } ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; CDCE_UNLOCK(sc); return; }
Static void url_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) { struct url_chain *c = priv; struct url_softc *sc = c->url_sc; struct ifnet *ifp = GET_IFP(sc); struct mbuf *m; u_int32_t total_len; url_rxhdr_t rxhdr; int s; DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev),__func__)); if (sc->sc_dying) return; if (status != USBD_NORMAL_COMPLETION) { if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) return; sc->sc_rx_errs++; if (usbd_ratecheck(&sc->sc_rx_notice)) { printf("%s: %u usb errors on rx: %s\n", USBDEVNAME(sc->sc_dev), sc->sc_rx_errs, usbd_errstr(status)); sc->sc_rx_errs = 0; } if (status == USBD_STALLED) { sc->sc_refcnt++; usbd_clear_endpoint_stall_async(sc->sc_pipe_rx); if (--sc->sc_refcnt < 0) usb_detach_wakeup(USBDEV(sc->sc_dev)); } goto done; } usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); memcpy(mtod(c->url_mbuf, char *), c->url_buf, total_len); if (total_len <= ETHER_CRC_LEN) { ifp->if_ierrors++; goto done; } memcpy(&rxhdr, c->url_buf + total_len - ETHER_CRC_LEN, sizeof(rxhdr)); DPRINTF(("%s: RX Status: %dbytes%s%s%s%s packets\n", USBDEVNAME(sc->sc_dev), UGETW(rxhdr) & URL_RXHDR_BYTEC_MASK, UGETW(rxhdr) & URL_RXHDR_VALID_MASK ? ", Valid" : "", UGETW(rxhdr) & URL_RXHDR_RUNTPKT_MASK ? ", Runt" : "", UGETW(rxhdr) & URL_RXHDR_PHYPKT_MASK ? ", Physical match" : "", UGETW(rxhdr) & URL_RXHDR_MCASTPKT_MASK ? ", Multicast" : "")); if ((UGETW(rxhdr) & URL_RXHDR_VALID_MASK) == 0) { ifp->if_ierrors++; goto done; } ifp->if_ipackets++; total_len -= ETHER_CRC_LEN; m = c->url_mbuf; m->m_pkthdr.len = m->m_len = total_len; m->m_pkthdr.rcvif = ifp; s = splnet(); if (url_newbuf(sc, c, NULL) == ENOBUFS) { ifp->if_ierrors++; goto done1; } #if NBPFILTER > 0 if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_IN); #endif DPRINTF(("%s: %s: deliver %d\n", USBDEVNAME(sc->sc_dev), __func__, m->m_len)); IF_INPUT(ifp, m); done1: splx(s); done: /* Setup new transfer */ usbd_setup_xfer(xfer, sc->sc_pipe_rx, c, c->url_buf, URL_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT, url_rxeof); sc->sc_refcnt++; usbd_transfer(xfer); if (--sc->sc_refcnt < 0) usb_detach_wakeup(USBDEV(sc->sc_dev)); DPRINTF(("%s: %s: start rx\n", USBDEVNAME(sc->sc_dev), __func__)); }
void cdcef_attach(struct device *parent, struct device *self, void *aux) { struct cdcef_softc *sc = (struct cdcef_softc *)self; struct usbf_attach_arg *uaa = aux; struct usbf_device *dev = uaa->device; struct ifnet *ifp; usbf_status err; struct usb_cdc_union_descriptor udesc; int s; u_int16_t macaddr_hi; /* Set the device identification according to the function. */ usbf_devinfo_setup(dev, UDCLASS_IN_INTERFACE, 0, 0, CDCEF_VENDOR_ID, CDCEF_PRODUCT_ID, CDCEF_DEVICE_CODE, CDCEF_VENDOR_STRING, CDCEF_PRODUCT_STRING, CDCEF_SERIAL_STRING); /* Fill in the fields needed by the parent device. */ sc->sc_dev.methods = &cdcef_methods; /* timeout to start delayed transfers */ timeout_set(&sc->start_to, cdcef_start_timeout, sc); /* * Build descriptors according to the device class specification. */ err = usbf_add_config(dev, &sc->sc_config); if (err) { printf(": usbf_add_config failed\n"); return; } err = usbf_add_interface(sc->sc_config, UICLASS_CDC, UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL, 0, NULL, &sc->sc_iface); if (err) { printf(": usbf_add_interface failed\n"); return; } /* XXX don't use hard-coded values 128 and 16. */ err = usbf_add_endpoint(sc->sc_iface, UE_DIR_IN | 2, UE_BULK, 64, 16, &sc->sc_ep_in) || usbf_add_endpoint(sc->sc_iface, UE_DIR_OUT | 1, UE_BULK, 64, 16, &sc->sc_ep_out); if (err) { printf(": usbf_add_endpoint failed\n"); return; } /* Append a CDC union descriptor. */ bzero(&udesc, sizeof udesc); udesc.bLength = sizeof udesc; udesc.bDescriptorType = UDESC_CS_INTERFACE; udesc.bDescriptorSubtype = UDESCSUB_CDC_UNION; udesc.bSlaveInterface[0] = usbf_interface_number(sc->sc_iface); err = usbf_add_config_desc(sc->sc_config, (usb_descriptor_t *)&udesc, NULL); if (err) { printf(": usbf_add_config_desc failed\n"); return; } /* * Close the configuration and build permanent descriptors. */ err = usbf_end_config(sc->sc_config); if (err) { printf(": usbf_end_config failed\n"); return; } /* Preallocate xfers and data buffers. */ sc->sc_xfer_in = usbf_alloc_xfer(dev); sc->sc_xfer_out = usbf_alloc_xfer(dev); sc->sc_buffer_in = usbf_alloc_buffer(sc->sc_xfer_in, CDCEF_BUFSZ); sc->sc_buffer_out = usbf_alloc_buffer(sc->sc_xfer_out, CDCEF_BUFSZ); if (sc->sc_buffer_in == NULL || sc->sc_buffer_out == NULL) { printf(": usbf_alloc_buffer failed\n"); return; } /* Open the bulk pipes. */ err = usbf_open_pipe(sc->sc_iface, usbf_endpoint_address(sc->sc_ep_out), &sc->sc_pipe_out) || usbf_open_pipe(sc->sc_iface, usbf_endpoint_address(sc->sc_ep_in), &sc->sc_pipe_in); if (err) { printf(": usbf_open_pipe failed\n"); return; } /* Get ready to receive packets. */ usbf_setup_xfer(sc->sc_xfer_out, sc->sc_pipe_out, sc, sc->sc_buffer_out, CDCEF_BUFSZ, USBD_SHORT_XFER_OK, 0, cdcef_rxeof); err = usbf_transfer(sc->sc_xfer_out); if (err && err != USBF_IN_PROGRESS) { printf(": usbf_transfer failed\n"); return; } s = splnet(); macaddr_hi = htons(0x2acb); bcopy(&macaddr_hi, &sc->sc_arpcom.ac_enaddr[0], sizeof(u_int16_t)); bcopy(&ticks, &sc->sc_arpcom.ac_enaddr[2], sizeof(u_int32_t)); sc->sc_arpcom.ac_enaddr[5] = (u_int8_t)(sc->sc_dev.bdev.dv_unit); printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr)); ifp = GET_IFP(sc); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = cdcef_ioctl; ifp->if_start = cdcef_start; ifp->if_watchdog = cdcef_watchdog; strlcpy(ifp->if_xname, DEVNAME(sc), IFNAMSIZ); IFQ_SET_READY(&ifp->if_snd); if_attach(ifp); ether_ifattach(ifp); splx(s); }
void cdcef_rxeof(struct usbf_xfer *xfer, void *priv, usbf_status status) { struct cdcef_softc *sc = priv; int total_len = 0; struct ifnet *ifp = GET_IFP(sc); struct mbuf_list ml = MBUF_LIST_INITIALIZER(); struct mbuf *m = NULL; int s; #if 0 printf("cdcef_rxeof: xfer=%p, priv=%p, %s\n", xfer, priv, usbf_errstr(status)); #endif if (status != USBF_NORMAL_COMPLETION) { if (status == USBF_NOT_STARTED || status == USBF_CANCELLED) return; if (sc->sc_rxeof_errors == 0) printf("%s: usb error on rx: %s\n", DEVNAME(sc), usbf_errstr(status)); /* XXX - no stalls on client */ if (sc->sc_rxeof_errors++ > 10) { printf("%s: too many errors, disabling\n", DEVNAME(sc)); } goto done; } sc->sc_rxeof_errors = 0; /* upon first incoming packet we know the host is listening */ if (sc->sc_listening == 0) { sc->sc_listening = 1; } usbf_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); /* total_len -= 4; Strip off CRC added for Zaurus - XXX*/ if (total_len <= 1) goto done; if (total_len < sizeof(struct ether_header)) { ifp->if_ierrors++; goto done; } if (ifp->if_flags & IFF_RUNNING) { m = cdcef_newbuf(); if (m == NULL) { /* message? */ ifp->if_ierrors++; goto done; } m->m_pkthdr.len = m->m_len = total_len; bcopy(sc->sc_buffer_out, mtod(m, char *), total_len); ml_enqueue(&ml, m); }