Esempio n. 1
0
static void ufoma_msg(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
	usb_device_request_t req;
	struct ufoma_softc *sc = priv;
	int actlen,i;
	struct ucom_softc *ucom= &sc->sc_ucom;
	usbd_get_xfer_status(xfer, NULL, NULL, &actlen ,NULL);
	ufoma_setup_msg_req(sc, &req);
	mtx_lock(&sc->sc_mtx);
	for(i = 0;i < actlen; i++){
		if(sc->sc_ucom.sc_tty->t_state & TS_ISOPEN)
			ttyld_rint(sc->sc_ucom.sc_tty, sc->sc_resbuffer[i]);
	}
	sc->sc_nummsg--;
	if(sc->sc_nummsg){
		usbd_setup_default_xfer(sc->sc_msgxf, ucom->sc_udev, 
		    priv, USBD_DEFAULT_TIMEOUT, &req,
		    sc->sc_resbuffer,
		    UFOMA_CMD_BUF_SIZE,
		    0, ufoma_msg);
		usbd_transfer(sc->sc_msgxf);
	}
	mtx_unlock(&sc->sc_mtx);

}
Esempio n. 2
0
File: umidi.c Progetto: bluhm/sys
static void
in_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
{
	int cn, evlen, remain, i;
	unsigned char *buf;
	struct umidi_endpoint *ep = (struct umidi_endpoint *)priv;
	struct umidi_jack *jack;

	if (usbd_is_dying(ep->sc->sc_udev))
		return;

	usbd_get_xfer_status(xfer, NULL, NULL, &remain, NULL);
	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF(("%s: abnormal status: %s\n", __func__, usbd_errstr(status)));
		return;
	}
	buf = ep->buffer;
	while (remain >= UMIDI_PACKET_SIZE) {
		cn = GET_CN(buf[0]);
		if (cn < ep->num_jacks && (jack = ep->jacks[cn]) &&
		    jack->binded && jack->opened &&  jack->u.in.intr) {
		    	evlen = packet_length[GET_CIN(buf[0])];
			mtx_enter(&audio_lock);
			for (i=0; i<evlen; i++)
				(*jack->u.in.intr)(jack->arg, buf[i+1]);
			mtx_leave(&audio_lock);
		}
		buf += UMIDI_PACKET_SIZE;
		remain -= UMIDI_PACKET_SIZE;
	}
	(void)start_input_transfer(ep);
}
Esempio n. 3
0
void
ugenintr(struct usbd_xfer *xfer, void *addr, usbd_status status)
{
	struct ugen_endpoint *sce = addr;
	/*struct ugen_softc *sc = sce->sc;*/
	u_int32_t count;
	u_char *ibuf;

	if (status == USBD_CANCELLED)
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF(("ugenintr: status=%d\n", status));
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall_async(sce->pipeh);
		return;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);
	ibuf = sce->ibuf;

	DPRINTFN(5, ("ugenintr: xfer=%p status=%d count=%d\n",
		     xfer, status, count));
	DPRINTFN(5, ("          data = %02x %02x %02x\n",
		     ibuf[0], ibuf[1], ibuf[2]));

	(void)b_to_q(ibuf, count, &sce->q);

	if (sce->state & UGEN_ASLP) {
		sce->state &= ~UGEN_ASLP;
		DPRINTFN(5, ("ugen_intr: waking %p\n", sce));
		wakeup(sce);
	}
	selwakeup(&sce->rsel);
}
Esempio n. 4
0
/*
 * End of sending
 */
static void
lgue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
	struct ifnet *ifp;
	struct lgue_softc *sc;
	usbd_status err;

	sc = priv;
	if (sc->lgue_dying)
		return;

	ifp = &sc->lgue_arpcom.ac_if;

	if (status != USBD_NORMAL_COMPLETION) {
		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
			return;
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall(sc->lgue_ep[LGUE_ENDPT_TX]);
		return;
	}
	usbd_get_xfer_status(sc->lgue_tx_xfer, NULL, NULL, NULL,&err);
	if (err)
		ifp->if_oerrors++;
	else
		ifp->if_opackets++;

	if (!STAILQ_EMPTY(&sc->lgue_tx_queue)) {
		lgue_start_schedule(ifp);
	}

	ifp->if_timer = 0;
	ifp->if_flags &= ~IFF_OACTIVE;
}
Esempio n. 5
0
/*
 * End of sending
 */
static void
lgue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
	struct ifnet *ifp;
	struct lgue_softc *sc;
	usbd_status err;

	sc = priv;
	if (sc->lgue_dying)
		return;

	ifp = &sc->lgue_arpcom.ac_if;

	if (status != USBD_NORMAL_COMPLETION) {
		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
			return;
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall(sc->lgue_ep[LGUE_ENDPT_TX]);
		return;
	}
	usbd_get_xfer_status(sc->lgue_tx_xfer, NULL, NULL, NULL,&err);
	if (err)
		IFNET_STAT_INC(ifp, oerrors, 1);
	else
		IFNET_STAT_INC(ifp, opackets, 1);

	if (!STAILQ_EMPTY(&sc->lgue_tx_queue)) {
		if_devstart_sched(ifp);
	}

	ifp->if_timer = 0;
	ifq_clr_oactive(&ifp->if_snd);
}
Esempio n. 6
0
usbd_status
usbd_intr_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
    u_int16_t flags, u_int32_t timeout, void *buf, u_int32_t *size, char *lbl)
{
	usbd_status err;
	int s, error;

	usbd_setup_xfer(xfer, pipe, 0, buf, *size, flags, timeout,
	    usbd_intr_transfer_cb);
	DPRINTFN(1, ("usbd_intr_transfer: start transfer %d bytes\n", *size));
	s = splusb();		/* don't want callback until tsleep() */
	err = usbd_transfer(xfer);
	if (err != USBD_IN_PROGRESS) {
		splx(s);
		return (err);
	}
	error = tsleep(xfer, PZERO | PCATCH, lbl, 0);
	splx(s);
	if (error) {
		DPRINTF(("usbd_intr_transfer: tsleep=%d\n", error));
		usbd_abort_pipe(pipe);
		return (USBD_INTERRUPTED);
	}
	usbd_get_xfer_status(xfer, NULL, NULL, size, &err);
	DPRINTFN(1,("usbd_intr_transfer: transferred %d\n", *size));
	if (err) {
		DPRINTF(("usbd_intr_transfer: error=%d\n", err));
		usbd_clear_endpoint_stall(pipe);
	}
	return (err);
}
Esempio n. 7
0
void
kue_watchdog(struct ifnet *ifp)
{
	struct kue_softc	*sc = ifp->if_softc;
	struct kue_chain	*c;
	usbd_status		stat;
	int			s;

	DPRINTFN(5,("%s: %s: enter\n", sc->kue_dev.dv_xname,__func__));

	if (sc->kue_dying)
		return;

	ifp->if_oerrors++;
	printf("%s: watchdog timeout\n", sc->kue_dev.dv_xname);

	s = splusb();
	c = &sc->kue_cdata.kue_tx_chain[0];
	usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &stat);
	kue_txeof(c->kue_xfer, c, stat);

	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
		kue_start(ifp);
	splx(s);
}
Esempio n. 8
0
void
ubt_recv_event(usbd_xfer_handle xfer, usbd_private_handle h, usbd_status status)
{
	struct ubt_softc *sc = h;
	struct mbuf *m;
	uint32_t count;
	void *buf;

	DPRINTFN(15, "sc=%p status=%s (%d)\n",
		    sc, usbd_errstr(status), status);

	if (status != USBD_NORMAL_COMPLETION || sc->sc_dying)
		return;

	usbd_get_xfer_status(xfer, NULL, &buf, &count, NULL);

	if (count < sizeof(hci_event_hdr_t) - 1) {
		DPRINTF("dumped undersized event (count = %d)\n", count);
		sc->sc_stats.err_rx++;
		return;
	}

	sc->sc_stats.evt_rx++;
	sc->sc_stats.byte_rx += count;

	m = ubt_mbufload(buf, count, HCI_EVENT_PKT);
	if (m == NULL || !hci_input_event(sc->sc_unit, m))
		sc->sc_stats.err_rx++;
}
Esempio n. 9
0
usbd_status
usbd_intr_transfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
		   u_int16_t flags, u_int32_t timeout, void *buf,
		   u_int32_t *size, const char *lbl)
{
	usbd_status err;

	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);

	usbd_setup_xfer(xfer, pipe, 0, buf, *size, flags, timeout, NULL);

	DPRINTFN(1, ("usbd_intr_transfer: start transfer %d bytes\n", *size));
	err = usbd_sync_transfer_sig(xfer);

	usbd_get_xfer_status(xfer, NULL, NULL, size, NULL);

	DPRINTFN(1,("usbd_intr_transfer: transferred %d\n", *size));
	if (err) {
		DPRINTF(("usbd_intr_transfer: error=%d\n", err));
		usbd_clear_endpoint_stall(pipe);
	}
	USBHIST_LOG(usbdebug, "<- done err %d", xfer, err, 0, 0);

	return (err);
}
Esempio n. 10
0
void
ucomreadcb(struct usbd_xfer *xfer, void *p, usbd_status status)
{
	struct ucom_softc *sc = (struct ucom_softc *)p;
	struct tty *tp = sc->sc_tty;
	int (*rint)(int c, struct tty *tp) = LINESW(tp, l_rint);
	usbd_status err;
	u_int32_t cc;
	u_char *cp;
	int s;

	DPRINTFN(5,("ucomreadcb: status=%d\n", status));

	if (status == USBD_CANCELLED || status == USBD_IOERROR ||
	    usbd_is_dying(sc->sc_uparent)) {
		DPRINTF(("ucomreadcb: dying\n"));
		/* Send something to wake upper layer */
		s = spltty();
		(*rint)('\n', tp);
		ttwakeup(tp);
		splx(s);
		return;
	}

	if (status) {
		if (sc->sc_bulkin_pipe != NULL) {
			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
			/* XXX we should restart after some delay. */
			return;
		}
	}

	usbd_get_xfer_status(xfer, NULL, (void *)&cp, &cc, NULL);
	DPRINTFN(5,("ucomreadcb: got %d chars, tp=%p\n", cc, tp));
	if (sc->sc_methods->ucom_read != NULL)
		sc->sc_methods->ucom_read(sc->sc_parent, sc->sc_portno,
					  &cp, &cc);

	s = spltty();
	/* Give characters to tty layer. */
	while (cc-- > 0) {
		DPRINTFN(7,("ucomreadcb: char=0x%02x\n", *cp));
		if ((*rint)(*cp++, tp) == -1) {
			/* XXX what should we do? */
			printf("%s: lost %d chars\n", sc->sc_dev.dv_xname,
			       cc);
			break;
		}
	}
	splx(s);

	err = ucomstartread(sc);
	if (err) {
		printf("%s: read start failed\n", sc->sc_dev.dv_xname);
		/* XXX what should we dow now? */
	}
}
Esempio n. 11
0
/*
 * A frame has been uploaded: pass the resulting mbuf up to
 * the higher level protocols.
 */
static void
lgue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
{
	struct lgue_softc	*sc;
	struct mbuf		*m;
	struct ifnet	*ifp;
	int			total_len;

	sc = priv;
	if (sc->lgue_dying)
		return;

	ifp = &sc->lgue_arpcom.ac_if;

	total_len = 0;

	if (!(ifp->if_flags & IFF_RUNNING))
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
			return;
		if (usbd_ratecheck(&sc->lgue_rx_notice)) {
			if_printf(ifp, "usb error on rx:%s\n",
			    usbd_errstr(status));
		}
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall(sc->lgue_ep[LGUE_ENDPT_RX]);
		goto done;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);

	if (total_len < sizeof(struct ether_header)) {
		IFNET_STAT_INC(ifp, ierrors, 1);
		goto done;
	}

	if (lgue_newbuf(sc, total_len, &m) == ENOBUFS) {
		IFNET_STAT_INC(ifp, ierrors, 1);
		return;
	}

	IFNET_STAT_INC(ifp, ipackets, 1);
	m_copyback(m, 0, total_len, sc->lgue_rx_buf);
	m->m_pkthdr.rcvif = ifp;
	m->m_pkthdr.len = m->m_len = total_len;

	usb_ether_input(m);
	lgue_rxstart(ifp);
	return;
done:
	usbd_setup_xfer(sc->lgue_rx_xfer, sc->lgue_ep[LGUE_ENDPT_RX], sc,
	    sc->lgue_rx_buf, LGUE_BUFSZ,
	    USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, lgue_rxeof);
	usbd_transfer(sc->lgue_rx_xfer);
}
Esempio n. 12
0
void
ucomwritecb(struct usbd_xfer *xfer, void *p, usbd_status status)
{
	struct ucom_softc *sc = (struct ucom_softc *)p;
	struct tty *tp = sc->sc_tty;
	u_int32_t cc;
	int s;

	DPRINTFN(5,("ucomwritecb: %p %p status=%d\n", xfer, p, status));

	if (status == USBD_CANCELLED || usbd_is_dying(sc->sc_uparent))
		goto error;

	if (sc->sc_bulkin_pipe != NULL) {
		if (status) {
			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
			/* XXX we should restart after some delay. */
			goto error;
		}
		usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
	} else {
		usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
		// XXX above gives me wrong cc, no?
	}

	DPRINTFN(5,("ucomwritecb: cc=%d\n", cc));
	/* convert from USB bytes to tty bytes */
	cc -= sc->sc_opkthdrlen;

	s = spltty();
	CLR(tp->t_state, TS_BUSY);
	if (ISSET(tp->t_state, TS_FLUSH))
		CLR(tp->t_state, TS_FLUSH);
	else
		ndflush(&tp->t_outq, cc);
	(*LINESW(tp, l_start))(tp);
	splx(s);
	return;

error:
	s = spltty();
	CLR(tp->t_state, TS_BUSY);
	splx(s);
}
Esempio n. 13
0
void
ugen_isoc_rintr(struct usbd_xfer *xfer, void *addr, usbd_status status)
{
	struct isoreq *req = addr;
	struct ugen_endpoint *sce = req->sce;
	u_int32_t count, n;
	int i, isize;

	/* Return if we are aborting. */
	if (status == USBD_CANCELLED)
		return;

	usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);
	DPRINTFN(5,("%s: xfer %ld, count=%d\n", __func__, req - sce->isoreqs,
	    count));

	/* throw away oldest input if the buffer is full */
	if(sce->fill < sce->cur && sce->cur <= sce->fill + count) {
		sce->cur += count;
		if(sce->cur >= sce->limit)
			sce->cur = sce->ibuf + (sce->limit - sce->cur);
		DPRINTFN(5, ("%s: throwing away %d bytes\n", __func__, count));
	}

	isize = UGETW(sce->edesc->wMaxPacketSize);
	for (i = 0; i < UGEN_NISORFRMS; i++) {
		u_int32_t actlen = req->sizes[i];
		char const *buf = (char const *)req->dmabuf + isize * i;

		/* copy data to buffer */
		while (actlen > 0) {
			n = min(actlen, sce->limit - sce->fill);
			memcpy(sce->fill, buf, n);

			buf += n;
			actlen -= n;
			sce->fill += n;
			if(sce->fill == sce->limit)
				sce->fill = sce->ibuf;
		}

		/* setup size for next transfer */
		req->sizes[i] = isize;
	}

	usbd_setup_isoc_xfer(xfer, sce->pipeh, req, req->sizes, UGEN_NISORFRMS,
			     USBD_NO_COPY, ugen_isoc_rintr);
	(void)usbd_transfer(xfer);

	if (sce->state & UGEN_ASLP) {
		sce->state &= ~UGEN_ASLP;
		DPRINTFN(5, ("ugen_isoc_rintr: waking %p\n", sce));
		wakeup(sce);
	}
	selwakeup(&sce->rsel);
}
static void
xboxcontroller_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
		    usbd_status status)
{
	struct xboxcontroller_softc *sc;
	unsigned char *data;
	int16_t x, y;
	char btnmask;
	uint32_t len;
	int s;

	sc = (struct xboxcontroller_softc *)priv;
	data = sc->sc_buf;

	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
	if (status == USBD_CANCELLED)
		return;

	x = (int16_t)(((int16_t)data[13] << 8) | data[12]);
	y = (int16_t)(((int16_t)data[15] << 8) | data[14]);
	/* z = (int16_t)(((int16_t)data[17] << 8) | data[16]); */
	/* w = (int16_t)(((int16_t)data[19] << 8) | data[18]); */

	/* de-jitter */
	if (x < 8192 && x > -8192)
		x = 0;
	if (y < 8192 && y > -8192)
		y = 0;

	switch (sc->sc_drvmode) {
	case XBOX_CONTROLLER_MODE_MOUSE:
		if (sc->sc_wsmousedev == NULL)
			goto done;
		btnmask = 0;
		if (data[2] & 0x40) btnmask |= 0x01;	/* thumb press left */
		if (data[2] & 0x80) btnmask |= 0x04;	/* thumb press right */
		if (data[2] & 0x10) btnmask |= 0x02;	/* start button */

		s = spltty();
		wsmouse_input(sc->sc_wsmousedev, btnmask,
			      x / 4096, y / 4096,
			      0, 0, /* z / 4096, w / 4096, */
			      WSMOUSE_INPUT_DELTA);
		splx(s);
		break;
	case XBOX_CONTROLLER_MODE_JOYSTICK:
		/* XXX not implemented */
		break;
	}

done:

	return;
}
Esempio n. 15
0
void
ubt_recv_acl_complete(usbd_xfer_handle xfer,
		usbd_private_handle h, usbd_status status)
{
	struct ubt_softc *sc = h;
	struct mbuf *m;
	uint32_t count;
	void *buf;

	DPRINTFN(15, "sc=%p status=%s (%d)\n",
			sc, usbd_errstr(status), status);

	sc->sc_aclrd_busy = 0;

	if (--sc->sc_refcnt < 0) {
		DPRINTF("refcnt = %d\n", sc->sc_refcnt);
		usb_detach_wakeup(sc->sc_dev);
		return;
	}

	if (sc->sc_dying) {
		DPRINTF("sc_dying\n");
		return;
	}

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF("status=%s (%d)\n",
			usbd_errstr(status), status);

		sc->sc_stats.err_rx++;

		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall_async(sc->sc_aclrd_pipe);
		else
			return;
	} else {
		usbd_get_xfer_status(xfer, NULL, &buf, &count, NULL);

		if (count < sizeof(hci_acldata_hdr_t) - 1) {
			DPRINTF("dumped undersized packet (%d)\n", count);
			sc->sc_stats.err_rx++;
		} else {
			sc->sc_stats.acl_rx++;
			sc->sc_stats.byte_rx += count;

			m = ubt_mbufload(buf, count, HCI_ACL_DATA_PKT);
			if (m == NULL || !hci_input_acl(sc->sc_unit, m))
				sc->sc_stats.err_rx++;
		}
	}

	/* and restart */
	ubt_recv_acl_start(sc);
}
Esempio n. 16
0
void
uhidev_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
{
	struct uhidev_softc *sc = addr;
	struct uhidev *scd;
	u_char *p;
	u_int rep;
	u_int32_t cc;

	usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);

#ifdef UHIDEV_DEBUG
	if (uhidevdebug > 5) {
		u_int32_t i;

		DPRINTF(("uhidev_intr: status=%d cc=%d\n", status, cc));
		DPRINTF(("uhidev_intr: data ="));
		for (i = 0; i < cc; i++)
			DPRINTF((" %02x", sc->sc_ibuf[i]));
		DPRINTF(("\n"));
	}
#endif

	if (status == USBD_CANCELLED)
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF(("%s: interrupt status=%d\n", sc->sc_dev.dv_xname,
			 status));
		usbd_clear_endpoint_stall_async(sc->sc_ipipe);
		return;
	}

	p = sc->sc_ibuf;
	if (sc->sc_nrepid != 1)
		rep = *p++, cc--;
	else
		rep = 0;
	if (rep >= sc->sc_nrepid) {
		printf("uhidev_intr: bad repid %d\n", rep);
		return;
	}
	scd = sc->sc_subdevs[rep];
	DPRINTFN(5,("uhidev_intr: rep=%d, scd=%p state=0x%x\n",
		    rep, scd, scd ? scd->sc_state : 0));
	if (scd == NULL || !(scd->sc_state & UHIDEV_OPEN))
		return;
#ifdef UHIDEV_DEBUG
	if (scd->sc_in_rep_size != cc)
		printf("%s: bad input length %d != %d\n",sc->sc_dev.dv_xname,
		       scd->sc_in_rep_size, cc);
#endif
	scd->sc_intr(scd, p, cc);
}
Esempio n. 17
0
void
uhidev_intr(struct usbd_xfer *xfer, void *addr, usbd_status status)
{
	struct uhidev_softc *sc = addr;
	struct uhidev *scd;
	u_char *p;
	u_int rep;
	u_int32_t cc;

	if (usbd_is_dying(sc->sc_udev))
		return;

	usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);

#ifdef UHIDEV_DEBUG
	if (uhidevdebug > 5) {
		u_int32_t i;

		DPRINTF(("uhidev_intr: status=%d cc=%d\n", status, cc));
		DPRINTF(("uhidev_intr: data ="));
		for (i = 0; i < cc; i++)
			DPRINTF((" %02x", sc->sc_ibuf[i]));
		DPRINTF(("\n"));
	}
#endif

	if (status == USBD_CANCELLED || status == USBD_IOERROR)
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF(("%s: interrupt status=%d\n", DEVNAME(sc), status));
		usbd_clear_endpoint_stall_async(sc->sc_ipipe);
		return;
	}

	p = sc->sc_ibuf;
	if (sc->sc_nrepid != 1)
		rep = *p++, cc--;
	else
		rep = 0;
	if (rep >= sc->sc_nrepid) {
		printf("uhidev_intr: bad repid %d\n", rep);
		return;
	}
	scd = sc->sc_subdevs[rep];
	DPRINTFN(5,("uhidev_intr: rep=%d, scd=%p state=0x%x\n",
		    rep, scd, scd ? scd->sc_state : 0));
	if (scd == NULL || !(scd->sc_state & UHIDEV_OPEN))
		return;

	scd->sc_intr(scd, p, cc);
}
Esempio n. 18
0
Static void
ucomwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
{
	struct ucom_softc *sc = (struct ucom_softc *)p;
	struct tty *tp = sc->sc_tty;
	u_int32_t cc;
	int s;

	DPRINTF(("ucomwritecb: status = %d\n", status));

	if (status == USBD_CANCELLED || sc->sc_dying)
		goto error;

	if (status != USBD_NORMAL_COMPLETION) {
		printf("%s: ucomwritecb: %s\n",
		       USBDEVNAME(sc->sc_dev), usbd_errstr(status));
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
		/* XXX we should restart after some delay. */
		goto error;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
	DPRINTF(("ucomwritecb: cc = %d\n", cc));
	if (cc <= sc->sc_opkthdrlen) {
		printf("%s: sent size too small, cc = %d\n",
		       USBDEVNAME(sc->sc_dev), cc);
		goto error;
	}

	/* convert from USB bytes to tty bytes */
	cc -= sc->sc_opkthdrlen;

	s = spltty();
	CLR(tp->t_state, TS_BUSY);
	if (ISSET(tp->t_state, TS_FLUSH))
		CLR(tp->t_state, TS_FLUSH);
	else
		ndflush(&tp->t_outq, cc);
	(*linesw[tp->t_line].l_start)(tp);
	splx(s);

	return;

  error:
	s = spltty();
	CLR(tp->t_state, TS_BUSY);
	splx(s);
	return;
}
Esempio n. 19
0
static void
emdtv_ir_intr(struct usbd_xfer *xfer, void * priv,
    usbd_status status)
{
	struct emdtv_softc *sc = priv;
	uint32_t len;

	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);
	if (status == USBD_CANCELLED)
		return;

	if (sc->sc_ir_wq)
		workqueue_enqueue(sc->sc_ir_wq, &sc->sc_ir_work, NULL);
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
static void
emdtv_dtv_isoc(struct usbd_xfer *xfer, void * priv,
    usbd_status err)
{
	struct emdtv_isoc_xfer *ix = priv;
	struct emdtv_softc *sc = ix->ix_sc;
	struct dtv_payload payload;
	struct usbd_pipe *isoc = sc->sc_isoc_pipe;
	uint32_t len;
	uint8_t *buf;
	int i;

	KASSERT(xfer == ix->ix_xfer);

	if (sc->sc_dying || sc->sc_dtvsubmitcb == NULL)
		return;

	if (err) {
		if (err == USBD_STALLED) {
			usbd_clear_endpoint_stall_async(isoc);
			goto resched;
		}
		return;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);

	if (len == 0)
		goto resched;

	buf = usbd_get_buffer(xfer);
	if (buf == NULL)
		goto resched;

	for (i = 0; i < EMDTV_NFRAMES; i++, buf += sc->sc_isoc_maxpacketsize) {
		if (ix->ix_frlengths[i] == 0)
			continue;
		payload.data = buf;
		payload.size = ix->ix_frlengths[i];
		sc->sc_dtvsubmitcb(sc->sc_dtvsubmitarg, &payload);
	}

resched:
	emdtv_dtv_isoc_start(sc, ix->ix_altix);
}
Esempio n. 22
0
/* hardware button interrupt */
void
ubcmtp_bt_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
{
	struct ubcmtp_softc *sc = priv;
	struct ubcmtp_button *pkt;
	u_int32_t len;

	if (usbd_is_dying(sc->sc_udev) || !(sc->sc_status & UBCMTP_ENABLED))
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
			return;
		if (status == USBD_STALLED)
			usbd_clear_endpoint_stall_async(sc->sc_tp_pipe);
		return;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);

	if (sc->bt_pkt == NULL || len < sizeof(struct ubcmtp_button))
		return;

	pkt = (struct ubcmtp_button *)(sc->bt_pkt);

	DPRINTF("%s: button interrupt (%d, %d, %d, %d)", sc->sc_dev.dv_xname,
	    pkt->unused, pkt->button, pkt->rel_x, pkt->rel_y);

	if (pkt->button != sc->btn) {
		sc->btn = pkt->button;

		if (sc->wsmode == WSMOUSE_NATIVE)
			wsmouse_input(sc->sc_wsmousedev, sc->btn, sc->pos[0].x,
			    sc->pos[0].y, 50 /* fake z for now */,
			    1,
			    WSMOUSE_INPUT_ABSOLUTE_X |
			    WSMOUSE_INPUT_ABSOLUTE_Y |
			    WSMOUSE_INPUT_ABSOLUTE_Z |
			    WSMOUSE_INPUT_ABSOLUTE_W);
		else
			wsmouse_input(sc->sc_wsmousedev, sc->btn,
			    0, 0, 0, 0, WSMOUSE_INPUT_DELTA);
	}
}
Esempio n. 23
0
File: uhid.c Progetto: MarginC/kame
void
uhid_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
{
	struct uhid_softc *sc = addr;

#ifdef USB_DEBUG
	if (uhiddebug > 5) {
		u_int32_t cc, i;
		
		usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
		DPRINTF(("uhid_intr: status=%d cc=%d\n", status, cc));
		DPRINTF(("uhid_intr: data ="));
		for (i = 0; i < cc; i++)
			DPRINTF((" %02x", sc->sc_ibuf[i]));
		DPRINTF(("\n"));
	}
#endif

	if (status == USBD_CANCELLED)
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF(("uhid_intr: status=%d\n", status));
		if (status == USBD_STALLED)
		    sc->sc_state |= UHID_NEEDCLEAR;
		return;
	}

	(void) b_to_q(sc->sc_ibuf, sc->sc_isize, &sc->sc_q);
		
	if (sc->sc_state & UHID_ASLP) {
		sc->sc_state &= ~UHID_ASLP;
		DPRINTFN(5, ("uhid_intr: waking %p\n", &sc->sc_q));
		wakeup(&sc->sc_q);
	}
	selwakeup(&sc->sc_rsel);
	if (sc->sc_async != NULL) {
		DPRINTFN(3, ("uhid_intr: sending SIGIO %p\n", sc->sc_async));
		PROC_LOCK(sc->sc_async);
		psignal(sc->sc_async, SIGIO);
		PROC_UNLOCK(sc->sc_async);
	}
}
Esempio n. 24
0
static void
ucom_write_status(struct ucom_softc *sc, struct ucom_buffer *ub,
    usbd_status err)
{
	struct tty *tp = sc->sc_tty;
	uint32_t cc = ub->ub_len;

	switch (err) {
	case USBD_IN_PROGRESS:
		ub->ub_index = ub->ub_len;
		break;
	case USBD_STALLED:
		ub->ub_index = 0;
		softint_schedule(sc->sc_si);
		break;
	case USBD_NORMAL_COMPLETION:
		usbd_get_xfer_status(ub->ub_xfer, NULL, NULL, &cc, NULL);
#if defined(__NetBSD__) && NRND > 0
		rnd_add_uint32(&sc->sc_rndsource, cc);
#endif
		/*FALLTHROUGH*/
	default:
		SIMPLEQ_REMOVE_HEAD(&sc->sc_obuff_full, ub_link);
		SIMPLEQ_INSERT_TAIL(&sc->sc_obuff_free, ub, ub_link);
		cc -= sc->sc_opkthdrlen;

		CLR(tp->t_state, TS_BUSY);
		if (ISSET(tp->t_state, TS_FLUSH))
			CLR(tp->t_state, TS_FLUSH);
		else
			ndflush(&tp->t_outq, cc);

		if (err != USBD_CANCELLED && err != USBD_IOERROR &&
		    !sc->sc_dying) {
			if ((ub = SIMPLEQ_FIRST(&sc->sc_obuff_full)) != NULL)
				ucom_submit_write(sc, ub);

			(*tp->t_linesw->l_start)(tp);
		}
		break;
	}
}
Esempio n. 25
0
void
uts_intr(usbd_xfer_handle xfer, usbd_private_handle addr, usbd_status status)
{
    struct uts_softc *sc = addr;
    u_int32_t len;
    int s;
    struct uts_pos tp;

    if (status == USBD_CANCELLED)
        return;

    if (status != USBD_NORMAL_COMPLETION) {
        printf("%s: status %d\n", sc->sc_dev.dv_xname, status);
        if (status == USBD_STALLED)
            usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
        return;
    }

    usbd_get_xfer_status(xfer, NULL, NULL, &len, NULL);

    s = spltty();

    uts_get_pos(sc, &tp);

    if (len != sc->sc_pkts) {
        DPRINTF(("%s: bad input length %d != %d\n",
                 sc->sc_dev.dv_xname, len, sc->sc_isize));
        splx(s);
        return;
    }

    DPRINTF(("%s: tp.down = %d, tp.z = %d, tp.x = %d, tp.y = %d\n",
             sc->sc_dev.dv_xname, tp.down, tp.z, tp.x, tp.y));

    wsmouse_input(sc->sc_wsmousedev, tp.down, tp.x, tp.y, tp.z, 0,
                  WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y |
                  WSMOUSE_INPUT_ABSOLUTE_Z);
    sc->sc_oldy = tp.y;
    sc->sc_oldx = tp.x;

    splx(s);
}
Esempio n. 26
0
usbd_status
usbd_bulk_transfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
    uint16_t flags, uint32_t timeout, void *buf, uint32_t *size)
{
	usbd_status err;

	USBHIST_FUNC(); USBHIST_CALLED(usbdebug);

	usbd_setup_xfer(xfer, 0, buf, *size, flags, timeout, NULL);
	DPRINTFN(1, "start transfer %d bytes", *size, 0, 0, 0);
	err = usbd_sync_transfer_sig(xfer);

	usbd_get_xfer_status(xfer, NULL, NULL, size, NULL);
	DPRINTFN(1, "transferred %d", *size, 0, 0, 0);
	if (err) {
		usbd_clear_endpoint_stall(pipe);
	}
	USBHIST_LOG(usbdebug, "<- done xfer %p err %d", xfer, err, 0, 0);

	return err;
}
Esempio n. 27
0
Static void
url_watchdog(struct ifnet *ifp)
{
	struct url_softc *sc = ifp->if_softc;
	struct url_chain *c;
	usbd_status stat;
	int s;

	DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->sc_dev), __func__));

	ifp->if_oerrors++;
	printf("%s: watchdog timeout\n", USBDEVNAME(sc->sc_dev));

	s = splusb();
	c = &sc->sc_cdata.url_tx_chain[0];
	usbd_get_xfer_status(c->url_xfer, NULL, NULL, NULL, &stat);
	url_txeof(c->url_xfer, c, stat);

	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
		url_start(ifp);
	splx(s);
}
Esempio n. 28
0
static void
auvitek_isoc_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
    usbd_status status)
{
	struct auvitek_isoc *isoc = priv;
	struct auvitek_xfer *ax = isoc->i_ax;
	struct auvitek_softc *sc = ax->ax_sc;
	uint32_t count;
	uint8_t *buf;
	unsigned int i;

	if (sc->sc_dying)
		return;

	if (status != USBD_NORMAL_COMPLETION) {
		if (status == USBD_STALLED) {
			usbd_clear_endpoint_stall_async(ax->ax_pipe);
			goto next;
		}
		return;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);

	if (count == 0)
		goto next;

	for (i = 0, buf = isoc->i_buf;
	     i < ax->ax_nframes;
	     ++i, buf += ax->ax_uframe_len) {
		status = auvitek_isoc_process(sc, buf, isoc->i_frlengths[i]);
		if (status == USBD_IOERROR)
			break;
	}

next:
	auvitek_isoc_start1(isoc);
}
Esempio n. 29
0
void
uirda_rd_cb(usbd_xfer_handle xfer, usbd_private_handle priv,
	    usbd_status status)
{
	struct uirda_softc *sc = priv;
	u_int32_t size;

	DPRINTFN(1,("%s: sc=%p\n", __func__, sc));

	if (status == USBD_CANCELLED) /* this is normal */
		return;
	if (status) {
		size = sc->sc_hdszi;
		sc->sc_rd_err = 1;
	} else {
		usbd_get_xfer_status(xfer, NULL, NULL, &size, NULL);
	}
	DPRINTFN(1,("%s: sc=%p size=%u, err=%d\n", __func__, sc, size,
		    sc->sc_rd_err));
	sc->sc_rd_count = size;
	wakeup(&sc->sc_rd_count); /* XXX should use flag */
	selnotify(&sc->sc_rd_sel, 0, 0);
}
Esempio n. 30
0
void
ubt_xmit_cmd_complete(usbd_xfer_handle xfer,
			usbd_private_handle h, usbd_status status)
{
	struct ubt_softc *sc = h;
	uint32_t count;

	DPRINTFN(15, " %s: CMD complete status=%s (%d)\n",
	    device_get_nameunit(sc->sc_dev), usbd_errstr(status), status);

	sc->sc_cmd_busy = 0;

	if (--sc->sc_refcnt < 0) {
		DPRINTF("sc_refcnt=%d\n", sc->sc_refcnt);
		usb_detach_wakeup(sc->sc_dev);
		return;
	}

	if (sc->sc_dying) {
		DPRINTF("sc_dying\n");
		return;
	}

	if (status != USBD_NORMAL_COMPLETION) {
		DPRINTF("status=%s (%d)\n",
			usbd_errstr(status), status);
		sc->sc_stats.err_tx++;
		return;
	}

	usbd_get_xfer_status(xfer, NULL, NULL, &count, NULL);
	sc->sc_stats.cmd_tx++;
	sc->sc_stats.byte_tx += count;

	ubt_xmit_cmd_start(sc);
}