- Make struct usb_xfer opaque so that drivers can not access the internals

- Reduce the number of headers needed for a usb driver, the common case is just   usb.h and usbdi.h
This commit is contained in:
Andrew Thompson 2009-06-23 02:19:59 +00:00
parent 8c8fff3177
commit ed6d949afd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194677
124 changed files with 4894 additions and 3347 deletions

View File

@ -40,10 +40,8 @@
#include "libusb20_int.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_revision.h>
static libusb20_init_backend_t ugen20_init_backend;
static libusb20_open_device_t ugen20_open_device;

View File

@ -66,7 +66,7 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_ioctl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <compat/ndis/pe_var.h>
#include <compat/ndis/cfg_var.h>

View File

@ -96,7 +96,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <compat/ndis/pe_var.h>
#include <compat/ndis/cfg_var.h>

View File

@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/condvar.h>
#include <sys/module.h>
#include <sys/conf.h>
#include <sys/mbuf.h>
@ -57,13 +59,10 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_ioctl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_defs.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_request.h>
#include <compat/ndis/pe_var.h>
@ -616,7 +615,7 @@ usbd_setup_endpoint_one(ip, ifidx, ne, epconf)
return (status);
}
xfer = ne->ne_xfer[0];
xfer->priv_fifo = ne;
usbd_xfer_set_priv(xfer, ne);
return (status);
}
@ -688,14 +687,14 @@ usbd_setup_endpoint(ip, ifidx, ep)
return (status);
}
xfer = ne->ne_xfer[0];
xfer->priv_fifo = ne;
usbd_xfer_set_priv(xfer, ne);
if (UE_GET_DIR(ep->bEndpointAddress) == UE_DIR_IN)
xfer->timeout = NDISUSB_NO_TIMEOUT;
usbd_xfer_set_timeout(xfer, NDISUSB_NO_TIMEOUT);
else {
if (UE_GET_XFERTYPE(ep->bmAttributes) == UE_BULK)
xfer->timeout = NDISUSB_TX_TIMEOUT;
usbd_xfer_set_timeout(xfer, NDISUSB_TX_TIMEOUT);
else
xfer->timeout = NDISUSB_INTR_TIMEOUT;
usbd_xfer_set_timeout(xfer, NDISUSB_INTR_TIMEOUT);
}
return (status);
@ -853,34 +852,38 @@ usbd_aq_getfirst(struct ndis_softc *sc, struct ndisusb_ep *ne)
}
static void
usbd_non_isoc_callback(struct usb_xfer *xfer)
usbd_non_isoc_callback(struct usb_xfer *xfer, usb_error_t error)
{
irp *ip;
struct ndis_softc *sc = xfer->priv_sc;
struct ndisusb_ep *ne = xfer->priv_fifo;
struct ndis_softc *sc = usbd_xfer_softc(xfer);
struct ndisusb_ep *ne = usbd_xfer_get_priv(xfer);
struct ndisusb_xfer *nx;
struct usbd_urb_bulk_or_intr_transfer *ubi;
struct usb_page_cache *pc;
uint8_t irql;
uint32_t len;
union usbd_urb *urb;
usb_endpoint_descriptor_t *ep;
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
nx = usbd_aq_getfirst(sc, ne);
pc = usbd_xfer_get_frame(xfer, 0);
if (nx == NULL)
return;
/* copy in data with regard to the URB */
if (ne->ne_dirin != 0)
usbd_copy_out(xfer->frbuffers, 0, nx->nx_urbbuf,
xfer->frlengths[0]);
nx->nx_urbbuf += xfer->frlengths[0];
nx->nx_urbactlen += xfer->frlengths[0];
nx->nx_urblen -= xfer->frlengths[0];
usbd_copy_out(pc, 0, nx->nx_urbbuf, actlen);
nx->nx_urbbuf += actlen;
nx->nx_urbactlen += actlen;
nx->nx_urblen -= actlen;
/* check for short transfer */
if (xfer->actlen < xfer->sumlen)
if (actlen < sumlen)
nx->nx_urblen = 0;
else {
/* check remainder */
@ -897,7 +900,7 @@ usbd_non_isoc_callback(struct usb_xfer *xfer)
}
}
usbd_xfer_complete(sc, ne, nx,
((xfer->actlen < xfer->sumlen) && (nx->nx_shortxfer == 0)) ?
((actlen < sumlen) && (nx->nx_shortxfer == 0)) ?
USB_ERR_SHORT_XFER : USB_ERR_NORMAL_COMPLETION);
/* fall through */
@ -927,41 +930,44 @@ usbd_non_isoc_callback(struct usb_xfer *xfer)
nx->nx_shortxfer = (ubi->ubi_trans_flags &
USBD_SHORT_TRANSFER_OK) ? 1 : 0;
extra:
len = MIN(xfer->max_data_length, nx->nx_urblen);
len = MIN(usbd_xfer_max_len(xfer), nx->nx_urblen);
pc = usbd_xfer_get_frame(xfer, 0);
if (UE_GET_DIR(ep->bEndpointAddress) == UE_DIR_OUT)
usbd_copy_in(xfer->frbuffers, 0, nx->nx_urbbuf, len);
xfer->frlengths[0] = len;
xfer->nframes = 1;
usbd_copy_in(pc, 0, nx->nx_urbbuf, len);
usbd_xfer_set_frame_len(xfer, 0, len);
usbd_xfer_set_frames(xfer, 1);
usbd_transfer_submit(xfer);
break;
default:
nx = usbd_aq_getfirst(sc, ne);
if (nx == NULL)
return;
if (xfer->error != USB_ERR_CANCELLED) {
xfer->flags.stall_pipe = 1;
if (error != USB_ERR_CANCELLED) {
usbd_xfer_set_stall(xfer);
device_printf(sc->ndis_dev, "usb xfer warning (%s)\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
}
usbd_xfer_complete(sc, ne, nx, xfer->error);
if (xfer->error != USB_ERR_CANCELLED)
usbd_xfer_complete(sc, ne, nx, error);
if (error != USB_ERR_CANCELLED)
goto next;
break;
}
}
static void
usbd_ctrl_callback(struct usb_xfer *xfer)
usbd_ctrl_callback(struct usb_xfer *xfer, usb_error_t error)
{
irp *ip;
struct ndis_softc *sc = xfer->priv_sc;
struct ndisusb_ep *ne = xfer->priv_fifo;
struct ndis_softc *sc = usbd_xfer_softc(xfer);
struct ndisusb_ep *ne = usbd_xfer_get_priv(xfer);
struct ndisusb_xfer *nx;
uint8_t irql;
union usbd_urb *urb;
struct usbd_urb_vendor_or_class_request *vcreq;
struct usb_page_cache *pc;
uint8_t type = 0;
struct usb_device_request req;
int len;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -974,9 +980,10 @@ usbd_ctrl_callback(struct usb_xfer *xfer)
vcreq = &urb->uu_vcreq;
if (vcreq->uvc_trans_flags & USBD_TRANSFER_DIRECTION_IN) {
usbd_copy_out(xfer->frbuffers + 1, 0,
vcreq->uvc_trans_buf, xfer->frlengths[1]);
nx->nx_urbactlen += xfer->frlengths[1];
pc = usbd_xfer_get_frame(xfer, 1);
len = usbd_xfer_get_framelen(xfer, 1);
usbd_copy_out(pc, 0, vcreq->uvc_trans_buf, len);
nx->nx_urbactlen += len;
}
usbd_xfer_complete(sc, ne, nx, USB_ERR_NORMAL_COMPLETION);
@ -1044,17 +1051,19 @@ usbd_ctrl_callback(struct usb_xfer *xfer)
nx->nx_urblen = vcreq->uvc_trans_buflen;
nx->nx_urbactlen = 0;
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->nframes = 1;
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frames(xfer, 1);
if (vcreq->uvc_trans_flags & USBD_TRANSFER_DIRECTION_IN) {
if (vcreq->uvc_trans_buflen >= USBD_CTRL_READ_BUFFER_SP)
device_printf(sc->ndis_dev,
"warning: not enough buffer space (%d).\n",
vcreq->uvc_trans_buflen);
xfer->frlengths[1] = MIN(xfer->max_data_length,
vcreq->uvc_trans_buflen);
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 1,
MIN(usbd_xfer_max_len(xfer),
vcreq->uvc_trans_buflen));
usbd_xfer_set_frames(xfer, 2);
} else {
if (nx->nx_urblen > 0)
device_printf(sc->ndis_dev,
@ -1066,10 +1075,11 @@ usbd_ctrl_callback(struct usb_xfer *xfer)
* the future if it needs to be.
*/
if (nx->nx_urblen > 0) {
usbd_copy_in(xfer->frbuffers + 1 , 0,
nx->nx_urbbuf, nx->nx_urblen);
xfer->frlengths[1] = nx->nx_urblen;
xfer->nframes = 2;
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_in(pc, 0, nx->nx_urbbuf,
nx->nx_urblen);
usbd_xfer_set_frame_len(xfer, 1, nx->nx_urblen);
usbd_xfer_set_frames(xfer, 2);
}
}
usbd_transfer_submit(xfer);
@ -1078,13 +1088,13 @@ usbd_ctrl_callback(struct usb_xfer *xfer)
nx = usbd_aq_getfirst(sc, ne);
if (nx == NULL)
return;
if (xfer->error != USB_ERR_CANCELLED) {
xfer->flags.stall_pipe = 1;
if (error != USB_ERR_CANCELLED) {
usbd_xfer_set_stall(xfer);
device_printf(sc->ndis_dev, "usb xfer warning (%s)\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
}
usbd_xfer_complete(sc, ne, nx, xfer->error);
if (xfer->error != USB_ERR_CANCELLED)
usbd_xfer_complete(sc, ne, nx, error);
if (error != USB_ERR_CANCELLED)
goto next;
break;
}

View File

@ -30,18 +30,30 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <machine/bus.h>
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usbdi.h>
#include <sys/ata.h>
#include <sys/bio.h>
@ -145,7 +157,8 @@ static usb_callback_t atausb2_tr_error;
static void atausb2_cancel_request(struct atausb2_softc *sc);
static void atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no);
static void atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer, uint8_t next_xfer, uint8_t stall_xfer);
static void atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error);
static int ata_usbchannel_begin_transaction(struct ata_request *request);
static int ata_usbchannel_end_transaction(struct ata_request *request);
@ -467,10 +480,11 @@ atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no)
}
static void
atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer)
atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -485,40 +499,40 @@ atausb2_t_bbb_reset1_callback(struct usb_xfer *xfer)
req.wIndex[1] = 0;
USETW(req.wLength, 0);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->nframes = 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frames(xfer, 1);
usbd_transfer_submit(xfer);
return;
default: /* Error */
atausb2_tr_error(xfer);
atausb2_tr_error(xfer, error);
return;
}
}
static void
atausb2_t_bbb_reset2_callback(struct usb_xfer *xfer)
atausb2_t_bbb_reset2_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_RESET3,
ATAUSB_T_BBB_DATA_READ);
ATAUSB_T_BBB_DATA_READ, error);
}
static void
atausb2_t_bbb_reset3_callback(struct usb_xfer *xfer)
atausb2_t_bbb_reset3_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_COMMAND,
ATAUSB_T_BBB_DATA_WRITE);
ATAUSB_T_BBB_DATA_WRITE, error);
}
static void
atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
uint8_t next_xfer,
uint8_t stall_xfer)
uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -533,18 +547,19 @@ atausb2_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
return;
default: /* Error */
atausb2_tr_error(xfer);
atausb2_tr_error(xfer, error);
return;
}
}
static void
atausb2_t_bbb_command_callback(struct usb_xfer *xfer)
atausb2_t_bbb_command_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct ata_request *request = sc->ata_request;
struct ata_channel *ch;
struct usb_page_cache *pc;
uint32_t tag;
switch (USB_GET_STATE(xfer)) {
@ -575,37 +590,42 @@ atausb2_t_bbb_command_callback(struct usb_xfer *xfer)
bzero(sc->cbw.cdb, 16);
bcopy(request->u.atapi.ccb, sc->cbw.cdb, 12); /* XXX SOS */
usbd_copy_in(xfer->frbuffers, 0, &sc->cbw, sizeof(sc->cbw));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &sc->cbw, sizeof(sc->cbw));
xfer->frlengths[0] = sizeof(sc->cbw);
usbd_xfer_set_frame_len(xfer, 0, sizeof(sc->cbw));
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
atausb2_tr_error(xfer);
atausb2_tr_error(xfer, error);
return;
}
}
static void
atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
struct usb_page_cache *pc;
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
usbd_copy_out(xfer->frbuffers, 0,
sc->ata_data, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, sc->ata_data, actlen);
sc->ata_bytecount -= xfer->actlen;
sc->ata_data += xfer->actlen;
sc->ata_donecount += xfer->actlen;
sc->ata_bytecount -= actlen;
sc->ata_data += actlen;
sc->ata_donecount += actlen;
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
/* short transfer */
sc->ata_bytecount = 0;
}
@ -622,15 +642,15 @@ atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
if (max_bulk > sc->ata_bytecount) {
max_bulk = sc->ata_bytecount;
}
xfer->timeout = sc->timeout;
xfer->frlengths[0] = max_bulk;
usbd_xfer_set_timeout(xfer, sc->timeout);
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
atausb2_tr_error(xfer);
if (error == USB_ERR_CANCELLED) {
atausb2_tr_error(xfer, error);
} else {
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
}
@ -640,24 +660,28 @@ atausb2_t_bbb_data_read_callback(struct usb_xfer *xfer)
}
static void
atausb2_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer)
atausb2_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
ATAUSB_T_BBB_DATA_READ);
ATAUSB_T_BBB_DATA_READ, error);
}
static void
atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t max_bulk = usbd_xfer_max_len(xfer);
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->ata_bytecount -= xfer->actlen;
sc->ata_data += xfer->actlen;
sc->ata_donecount += xfer->actlen;
sc->ata_bytecount -= actlen;
sc->ata_data += actlen;
sc->ata_donecount += actlen;
case USB_ST_SETUP:
@ -672,18 +696,18 @@ atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
if (max_bulk > sc->ata_bytecount) {
max_bulk = sc->ata_bytecount;
}
xfer->timeout = sc->timeout;
xfer->frlengths[0] = max_bulk;
usbd_copy_in(xfer->frbuffers, 0,
sc->ata_data, max_bulk);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, sc->ata_data, max_bulk);
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
usbd_xfer_set_timeout(xfer, sc->timeout);
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
atausb2_tr_error(xfer);
if (error == USB_ERR_CANCELLED) {
atausb2_tr_error(xfer, error);
} else {
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_WR_CS);
}
@ -693,26 +717,31 @@ atausb2_t_bbb_data_write_callback(struct usb_xfer *xfer)
}
static void
atausb2_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer)
atausb2_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
ATAUSB_T_BBB_DATA_WRITE);
ATAUSB_T_BBB_DATA_WRITE, error);
}
static void
atausb2_t_bbb_status_callback(struct usb_xfer *xfer)
atausb2_t_bbb_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
struct ata_request *request = sc->ata_request;
struct usb_page_cache *pc;
uint32_t residue;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < sizeof(sc->csw)) {
if (actlen < sizeof(sc->csw)) {
bzero(&sc->csw, sizeof(sc->csw));
}
usbd_copy_out(xfer->frbuffers, 0, &sc->csw, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &sc->csw, actlen);
if (request->flags & (ATA_R_READ | ATA_R_WRITE)) {
request->donecount = sc->ata_donecount;
@ -779,15 +808,14 @@ atausb2_t_bbb_status_callback(struct usb_xfer *xfer)
return;
case USB_ST_SETUP:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default:
tr_error:
if ((xfer->error == USB_ERR_CANCELLED) ||
(sc->status_try)) {
atausb2_tr_error(xfer);
if (error == USB_ERR_CANCELLED || sc->status_try) {
atausb2_tr_error(xfer, error);
} else {
sc->status_try = 1;
atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
@ -820,15 +848,15 @@ atausb2_cancel_request(struct atausb2_softc *sc)
}
static void
atausb2_tr_error(struct usb_xfer *xfer)
atausb2_tr_error(struct usb_xfer *xfer, usb_error_t error)
{
struct atausb2_softc *sc = xfer->priv_sc;
struct atausb2_softc *sc = usbd_xfer_softc(xfer);
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
if (atausbdebug) {
device_printf(sc->dev, "transfer failed, %s, in state %d "
"-> BULK reset\n", usbd_errstr(xfer->error),
"-> BULK reset\n", usbd_errstr(error),
sc->last_xfer_no);
}
}

View File

@ -74,7 +74,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <compat/ndis/pe_var.h>
#include <compat/ndis/cfg_var.h>

View File

@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
#include <sys/rman.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <net80211/ieee80211_var.h>

View File

@ -55,7 +55,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <compat/ndis/pe_var.h>
#include <compat/ndis/cfg_var.h>

View File

@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <machine/bus.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <net80211/ieee80211_var.h>

View File

@ -45,23 +45,33 @@
* $NetBSD: uaudio.c,v 1.97 2005/02/24 08:19:38 martin Exp $
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR uaudio_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/quirk/usb_quirk.h>
@ -946,8 +956,6 @@ uaudio_chan_fill_info_sub(struct uaudio_softc *sc, struct usb_device *udev,
bChannels = UAUDIO_MAX_CHAN(asf1d->bNrChannels);
bBitResolution = asf1d->bBitResolution;
DPRINTFN(9, "bChannels=%u\n", bChannels);
if (asf1d->bSamFreqType == 0) {
DPRINTFN(16, "Sample rate: %d-%dHz\n",
UA_SAMP_LO(asf1d), UA_SAMP_HI(asf1d));
@ -1106,14 +1114,17 @@ uaudio_chan_fill_info(struct uaudio_softc *sc, struct usb_device *udev)
}
static void
uaudio_chan_play_callback(struct usb_xfer *xfer)
uaudio_chan_play_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uaudio_chan *ch = xfer->priv_sc;
uint32_t *p_len = xfer->frlengths;
struct uaudio_chan *ch = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t total;
uint32_t blockcount;
uint32_t n;
uint32_t offset;
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
/* allow dynamic sizing of play buffer */
total = ch->intr_size;
@ -1129,8 +1140,8 @@ uaudio_chan_play_callback(struct usb_xfer *xfer)
blockcount = UAUDIO_MINFRAMES;
}
/* range check - max */
if (blockcount > xfer->max_frame_count) {
blockcount = xfer->max_frame_count;
if (blockcount > usbd_xfer_max_frames(xfer)) {
blockcount = usbd_xfer_max_frames(xfer);
}
/* compute the total length */
total = blockcount * ch->bytes_per_frame;
@ -1138,25 +1149,24 @@ uaudio_chan_play_callback(struct usb_xfer *xfer)
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
tr_transferred:
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
DPRINTF("short transfer, "
"%d of %d bytes\n", xfer->actlen, total);
"%d of %d bytes\n", actlen, total);
}
chn_intr(ch->pcm_ch);
case USB_ST_SETUP:
if (ch->bytes_per_frame > xfer->max_frame_size) {
if (ch->bytes_per_frame > usbd_xfer_max_framelen(xfer)) {
DPRINTF("bytes per transfer, %d, "
"exceeds maximum, %d!\n",
ch->bytes_per_frame,
xfer->max_frame_size);
usbd_xfer_max_framelen(xfer));
break;
}
/* setup frame length */
xfer->nframes = blockcount;
for (n = 0; n != blockcount; n++) {
p_len[n] = ch->bytes_per_frame;
}
usbd_xfer_set_frames(xfer, blockcount);
for (n = 0; n != blockcount; n++)
usbd_xfer_set_frame_len(xfer, n, ch->bytes_per_frame);
if (ch->end == ch->start) {
DPRINTF("no buffer!\n");
@ -1166,13 +1176,14 @@ uaudio_chan_play_callback(struct usb_xfer *xfer)
offset = 0;
pc = usbd_xfer_get_frame(xfer, 0);
while (total > 0) {
n = (ch->end - ch->cur);
if (n > total) {
n = total;
}
usbd_copy_in(xfer->frbuffers, offset, ch->cur, n);
usbd_copy_in(pc, offset, ch->cur, n);
total -= n;
ch->cur += n;
@ -1187,7 +1198,7 @@ uaudio_chan_play_callback(struct usb_xfer *xfer)
break;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
goto tr_transferred;
@ -1195,16 +1206,20 @@ uaudio_chan_play_callback(struct usb_xfer *xfer)
}
static void
uaudio_chan_record_callback(struct usb_xfer *xfer)
uaudio_chan_record_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uaudio_chan *ch = xfer->priv_sc;
uint32_t *p_len = xfer->frlengths;
struct uaudio_chan *ch = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t n;
uint32_t m;
uint32_t total;
uint32_t blockcount;
uint32_t offset0;
uint32_t offset1;
int len;
int actlen, nframes;
usbd_xfer_status(xfer, &actlen, NULL, NULL, &nframes);
/* allow dynamic sizing of play buffer */
total = ch->intr_size;
@ -1220,8 +1235,8 @@ uaudio_chan_record_callback(struct usb_xfer *xfer)
blockcount = UAUDIO_MINFRAMES;
}
/* range check - max */
if (blockcount > xfer->max_frame_count) {
blockcount = xfer->max_frame_count;
if (blockcount > usbd_xfer_max_frames(xfer)) {
blockcount = usbd_xfer_max_frames(xfer);
}
/* compute the total length */
total = blockcount * ch->bytes_per_frame;
@ -1229,29 +1244,31 @@ uaudio_chan_record_callback(struct usb_xfer *xfer)
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
tr_transferred:
if (xfer->actlen < total) {
if (actlen < total) {
DPRINTF("short transfer, "
"%d of %d bytes\n", xfer->actlen, total);
"%d of %d bytes\n", actlen, total);
} else {
DPRINTFN(6, "transferred %d bytes\n", xfer->actlen);
DPRINTFN(6, "transferred %d bytes\n", actlen);
}
offset0 = 0;
for (n = 0; n != xfer->nframes; n++) {
for (n = 0; n != nframes; n++) {
offset1 = offset0;
pc = usbd_xfer_get_frame(xfer, n);
len = usbd_xfer_get_framelen(xfer, n);
while (p_len[n] > 0) {
while (len > 0) {
m = (ch->end - ch->cur);
if (m > p_len[n]) {
m = p_len[n];
if (m > len) {
m = len;
}
usbd_copy_out(xfer->frbuffers, offset1, ch->cur, m);
usbd_copy_out(pc, offset1, ch->cur, m);
p_len[n] -= m;
len -= m;
offset1 += m;
ch->cur += m;
@ -1266,16 +1283,16 @@ uaudio_chan_record_callback(struct usb_xfer *xfer)
chn_intr(ch->pcm_ch);
case USB_ST_SETUP:
if (ch->bytes_per_frame > xfer->max_frame_size) {
if (ch->bytes_per_frame > usbd_xfer_max_framelen(xfer)) {
DPRINTF("bytes per transfer, %d, "
"exceeds maximum, %d!\n",
ch->bytes_per_frame,
xfer->max_frame_size);
usbd_xfer_max_framelen(xfer));
return;
}
xfer->nframes = blockcount;
for (n = 0; n != xfer->nframes; n++) {
p_len[n] = ch->bytes_per_frame;
usbd_xfer_set_frames(xfer, blockcount);
for (n = 0; n < blockcount; n++) {
usbd_xfer_set_frame_len(xfer, n, ch->bytes_per_frame);
}
if (ch->end == ch->start) {
@ -1286,7 +1303,7 @@ uaudio_chan_record_callback(struct usb_xfer *xfer)
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
return;
}
goto tr_transferred;
@ -2958,11 +2975,12 @@ uaudio_mixer_get(struct usb_device *udev, uint8_t what,
}
static void
uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer)
uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_device_request req;
struct uaudio_softc *sc = xfer->priv_sc;
struct uaudio_softc *sc = usbd_xfer_softc(xfer);
struct uaudio_mixer_node *mc = sc->sc_mixer_curr;
struct usb_page_cache *pc;
uint16_t len;
uint8_t repeat = 1;
uint8_t update;
@ -3011,12 +3029,14 @@ uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer)
if (len > 1) {
buf[1] = (mc->wData[chan] >> 8) & 0xFF;
}
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(xfer->frbuffers + 1, 0, buf, len);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_in(pc, 0, buf, len);
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = len;
xfer->nframes = xfer->frlengths[1] ? 2 : 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, len);
usbd_xfer_set_frames(xfer, len ? 2 : 1);
usbd_transfer_submit(xfer);
return;
}
@ -3033,8 +3053,8 @@ uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer)
break;
default: /* Error */
DPRINTF("error=%s\n", usbd_errstr(xfer->error));
if (xfer->error == USB_ERR_CANCELLED) {
DPRINTF("error=%s\n", usbd_errstr(error));
if (error == USB_ERR_CANCELLED) {
/* do nothing - we are detaching */
break;
}
@ -3237,9 +3257,9 @@ uaudio_mixer_setrecsrc(struct uaudio_softc *sc, uint32_t src)
*========================================================================*/
static void
umidi_read_clear_stall_callback(struct usb_xfer *xfer)
umidi_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umidi_chan *chan = xfer->priv_sc;
struct umidi_chan *chan = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = chan->xfer[1];
if (usbd_clear_stall_callback(xfer, xfer_other)) {
@ -3250,42 +3270,47 @@ umidi_read_clear_stall_callback(struct usb_xfer *xfer)
}
static void
umidi_bulk_read_callback(struct usb_xfer *xfer)
umidi_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umidi_chan *chan = xfer->priv_sc;
struct umidi_chan *chan = usbd_xfer_softc(xfer);
struct umidi_sub_chan *sub;
struct usb_page_cache *pc;
uint8_t buf[1];
uint8_t cmd_len;
uint8_t cn;
uint16_t pos;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("actlen=%d bytes\n", xfer->actlen);
DPRINTF("actlen=%d bytes\n", actlen);
if (xfer->actlen == 0) {
if (actlen == 0) {
/* should not happen */
goto tr_error;
}
pos = 0;
pc = usbd_xfer_get_frame(xfer, 0);
while (xfer->actlen >= 4) {
while (actlen >= 4) {
usbd_copy_out(xfer->frbuffers, pos, buf, 1);
usbd_copy_out(pc, pos, buf, 1);
cmd_len = umidi_cmd_to_len[buf[0] & 0xF]; /* command length */
cn = buf[0] >> 4; /* cable number */
sub = &chan->sub[cn];
if (cmd_len && (cn < chan->max_cable) && sub->read_open) {
usb_fifo_put_data(sub->fifo.fp[USB_FIFO_RX], xfer->frbuffers,
usb_fifo_put_data(sub->fifo.fp[USB_FIFO_RX], pc,
pos + 1, cmd_len, 1);
} else {
/* ignore the command */
}
xfer->actlen -= 4;
actlen -= 4;
pos += 4;
}
@ -3296,16 +3321,16 @@ umidi_bulk_read_callback(struct usb_xfer *xfer)
usbd_transfer_start(chan->xfer[3]);
return;
}
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default:
tr_error:
DPRINTF("error=%s\n", usbd_errstr(xfer->error));
DPRINTF("error=%s\n", usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
chan->flags |= UMIDI_FLAG_READ_STALL;
usbd_transfer_start(chan->xfer[3]);
@ -3316,9 +3341,9 @@ umidi_bulk_read_callback(struct usb_xfer *xfer)
}
static void
umidi_write_clear_stall_callback(struct usb_xfer *xfer)
umidi_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umidi_chan *chan = xfer->priv_sc;
struct umidi_chan *chan = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = chan->xfer[0];
if (usbd_clear_stall_callback(xfer, xfer_other)) {
@ -3462,19 +3487,23 @@ umidi_convert_to_usb(struct umidi_sub_chan *sub, uint8_t cn, uint8_t b)
}
static void
umidi_bulk_write_callback(struct usb_xfer *xfer)
umidi_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umidi_chan *chan = xfer->priv_sc;
struct umidi_chan *chan = usbd_xfer_softc(xfer);
struct umidi_sub_chan *sub;
struct usb_page_cache *pc;
uint32_t actlen;
uint16_t total_length;
uint8_t buf;
uint8_t start_cable;
uint8_t tr_any;
int len;
usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("actlen=%d bytes\n", xfer->actlen);
DPRINTF("actlen=%d bytes\n", len);
case USB_ST_SETUP:
@ -3485,10 +3514,9 @@ umidi_bulk_write_callback(struct usb_xfer *xfer)
return;
}
total_length = 0; /* reset */
start_cable = chan->curr_cable;
tr_any = 0;
pc = usbd_xfer_get_frame(xfer, 0);
while (1) {
@ -3498,14 +3526,13 @@ umidi_bulk_write_callback(struct usb_xfer *xfer)
if (sub->write_open) {
usb_fifo_get_data(sub->fifo.fp[USB_FIFO_TX],
xfer->frbuffers, total_length,
1, &actlen, 0);
pc, total_length, 1, &actlen, 0);
} else {
actlen = 0;
}
if (actlen) {
usbd_copy_out(xfer->frbuffers, total_length, &buf, 1);
usbd_copy_out(pc, total_length, &buf, 1);
tr_any = 1;
@ -3517,7 +3544,7 @@ umidi_bulk_write_callback(struct usb_xfer *xfer)
sub->temp_cmd[0], sub->temp_cmd[1],
sub->temp_cmd[2], sub->temp_cmd[3]);
usbd_copy_in(xfer->frbuffers, total_length,
usbd_copy_in(pc, total_length,
sub->temp_cmd, 4);
total_length += 4;
@ -3542,16 +3569,16 @@ umidi_bulk_write_callback(struct usb_xfer *xfer)
}
if (total_length) {
xfer->frlengths[0] = total_length;
usbd_xfer_set_frame_len(xfer, 0, total_length);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
DPRINTF("error=%s\n", usbd_errstr(xfer->error));
DPRINTF("error=%s\n", usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
chan->flags |= UMIDI_FLAG_WRITE_STALL;
usbd_transfer_start(chan->xfer[2]);
@ -3564,7 +3591,7 @@ umidi_bulk_write_callback(struct usb_xfer *xfer)
static struct umidi_sub_chan *
umidi_sub_by_fifo(struct usb_fifo *fifo)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
struct umidi_sub_chan *sub;
uint32_t n;
@ -3585,7 +3612,7 @@ umidi_sub_by_fifo(struct usb_fifo *fifo)
static void
umidi_start_read(struct usb_fifo *fifo)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
usbd_transfer_start(chan->xfer[1]);
}
@ -3593,7 +3620,7 @@ umidi_start_read(struct usb_fifo *fifo)
static void
umidi_stop_read(struct usb_fifo *fifo)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
DPRINTF("\n");
@ -3612,7 +3639,7 @@ umidi_stop_read(struct usb_fifo *fifo)
static void
umidi_start_write(struct usb_fifo *fifo)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
usbd_transfer_start(chan->xfer[0]);
}
@ -3620,7 +3647,7 @@ umidi_start_write(struct usb_fifo *fifo)
static void
umidi_stop_write(struct usb_fifo *fifo)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
DPRINTF("\n");
@ -3637,31 +3664,31 @@ umidi_stop_write(struct usb_fifo *fifo)
static int
umidi_open(struct usb_fifo *fifo, int fflags)
{
struct umidi_chan *chan = fifo->priv_sc0;
struct umidi_chan *chan = usb_fifo_softc(fifo);
struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
if (fflags & FREAD) {
if (usb_fifo_alloc_buffer(fifo, 4, (1024 / 4))) {
return (ENOMEM);
}
mtx_lock(fifo->priv_mtx);
mtx_lock(&Giant);
chan->read_open_refcount++;
sub->read_open = 1;
mtx_unlock(fifo->priv_mtx);
mtx_unlock(&Giant);
}
if (fflags & FWRITE) {
if (usb_fifo_alloc_buffer(fifo, 32, (1024 / 32))) {
return (ENOMEM);
}
/* clear stall first */
mtx_lock(fifo->priv_mtx);
mtx_lock(&Giant);
chan->flags |= UMIDI_FLAG_WRITE_STALL;
chan->write_open_refcount++;
sub->write_open = 1;
/* reset */
sub->state = UMIDI_ST_UNKNOWN;
mtx_unlock(fifo->priv_mtx);
mtx_unlock(&Giant);
}
return (0); /* success */
}

View File

@ -44,9 +44,28 @@ __FBSDID("$FreeBSD$");
* endpoints, Function-address and more.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR at91dcidebug
@ -70,7 +89,7 @@ __FBSDID("$FreeBSD$");
#define AT9100_DCI_PC2SC(pc) \
AT9100_DCI_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
#ifdef USB_DEBUG
static int at91dcidebug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, at91dci, CTLFLAG_RW, 0, "USB at91dci");

View File

@ -26,9 +26,28 @@ __FBSDID("$FreeBSD$");
* SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -36,9 +36,28 @@ __FBSDID("$FreeBSD$");
* endpoints, Function-address and more.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR atmegadci_debug
@ -62,7 +81,7 @@ __FBSDID("$FreeBSD$");
#define ATMEGA_PC2SC(pc) \
ATMEGA_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
#ifdef USB_DEBUG
static int atmegadci_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, atmegadci, CTLFLAG_RW, 0, "USB ATMEGA DCI");

View File

@ -26,7 +26,28 @@ __FBSDID("$FreeBSD$");
* SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -36,9 +36,28 @@ __FBSDID("$FreeBSD$");
* endpoints, Function-address and more.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR avr32dci_debug
@ -62,7 +81,7 @@ __FBSDID("$FreeBSD$");
#define AVR32_PC2SC(pc) \
AVR32_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
#ifdef USB_DEBUG
static int avr32dci_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, avr32dci, CTLFLAG_RW, 0, "USB AVR32 DCI");

View File

@ -46,9 +46,28 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR ehcidebug
@ -1133,7 +1152,7 @@ ehci_non_isoc_done_sub(struct usb_xfer *xfer)
td_alt_next = td->alt_next;
if (xfer->aframes != xfer->nframes) {
xfer->frlengths[xfer->aframes] = 0;
usbd_xfer_set_frame_len(xfer, xfer->aframes, 0);
}
while (1) {

View File

@ -31,8 +31,28 @@ __FBSDID("$FreeBSD$");
#include "opt_bus.h"
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -38,8 +38,28 @@ __FBSDID("$FreeBSD$");
#include "opt_bus.h"
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -52,8 +52,28 @@ __FBSDID("$FreeBSD$");
* sharing of code between *BSD's
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -36,9 +36,28 @@
* NOTE: The current implementation only supports Device Side Mode!
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR musbotgdebug
@ -64,7 +83,7 @@
#define MUSBOTG_PC2SC(pc) \
MUSBOTG_BUS2SC(USB_DMATAG_TO_XROOT((pc)->tag_parent)->bus)
#if USB_DEBUG
#ifdef USB_DEBUG
static int musbotgdebug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, musbotg, CTLFLAG_RW, 0, "USB musbotg");

View File

@ -24,8 +24,28 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -35,9 +35,28 @@ __FBSDID("$FreeBSD$");
* USB spec: http://www.usb.org/developers/docs/usbspec.zip
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR ohcidebug
@ -58,7 +77,7 @@ __FBSDID("$FreeBSD$");
((ohci_softc_t *)(((uint8_t *)(bus)) - \
((uint8_t *)&(((ohci_softc_t *)0)->sc_bus))))
#if USB_DEBUG
#ifdef USB_DEBUG
static int ohcidebug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, ohci, CTLFLAG_RW, 0, "USB ohci");
@ -205,7 +224,7 @@ ohci_controller_init(ohci_softc_t *sc)
device_printf(sc->sc_bus.bdev, "reset timeout\n");
return (USB_ERR_IOERROR);
}
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 15) {
ohci_dumpregs(sc);
}
@ -264,7 +283,7 @@ ohci_controller_init(ohci_softc_t *sc)
sc->sc_noport = OHCI_GET_NDP(OREAD4(sc, OHCI_RH_DESCRIPTOR_A));
}
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 5) {
ohci_dumpregs(sc);
}
@ -380,7 +399,7 @@ ohci_init(ohci_softc_t *sc)
usb_callout_init_mtx(&sc->sc_tmo_rhsc, &sc->sc_bus.bus_mtx, 0);
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 15) {
for (i = 0; i != OHCI_NO_EDS; i++) {
printf("ed#%d ", i);
@ -433,7 +452,7 @@ ohci_suspend(ohci_softc_t *sc)
USB_BUS_LOCK(&sc->sc_bus);
#if USB_DEBUG
#ifdef USB_DEBUG
DPRINTF("\n");
if (ohcidebug > 2) {
ohci_dumpregs(sc);
@ -463,7 +482,7 @@ ohci_resume(ohci_softc_t *sc)
{
uint32_t ctl;
#if USB_DEBUG
#ifdef USB_DEBUG
DPRINTF("\n");
if (ohcidebug > 2) {
ohci_dumpregs(sc);
@ -497,7 +516,7 @@ ohci_resume(ohci_softc_t *sc)
ohci_do_poll(&sc->sc_bus);
}
#if USB_DEBUG
#ifdef USB_DEBUG
static void
ohci_dumpregs(ohci_softc_t *sc)
{
@ -744,7 +763,7 @@ ohci_isoc_done(struct usb_xfer *xfer)
panic("%s:%d: out of TD's\n",
__FUNCTION__, __LINE__);
}
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 5) {
DPRINTF("isoc TD\n");
ohci_dump_itd(td);
@ -785,7 +804,7 @@ ohci_isoc_done(struct usb_xfer *xfer)
ohci_device_done(xfer, USB_ERR_NORMAL_COMPLETION);
}
#if USB_DEBUG
#ifdef USB_DEBUG
static const char *const
ohci_cc_strs[] =
{
@ -828,7 +847,7 @@ ohci_non_isoc_done_sub(struct usb_xfer *xfer)
td_flags = 0;
if (xfer->aframes != xfer->nframes) {
xfer->frlengths[xfer->aframes] = 0;
usbd_xfer_set_frame_len(xfer, xfer->aframes, 0);
}
while (1) {
@ -913,7 +932,7 @@ ohci_non_isoc_done(struct usb_xfer *xfer)
DPRINTFN(13, "xfer=%p endpoint=%p transfer done\n",
xfer, xfer->endpoint);
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 10) {
ohci_dump_tds(xfer->td_transfer_first);
}
@ -1138,7 +1157,7 @@ ohci_interrupt(ohci_softc_t *sc)
DPRINTFN(16, "real interrupt\n");
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 15) {
ohci_dumpregs(sc);
}
@ -1564,7 +1583,7 @@ ohci_setup_standard_chain(struct usb_xfer *xfer, ohci_ed_t **ed_last)
xfer->td_transfer_last = td;
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 8) {
DPRINTF("nexttog=%d; data before transfer:\n",
xfer->endpoint->toggle_next);
@ -1995,7 +2014,7 @@ ohci_device_isoc_enter(struct usb_xfer *xfer)
xfer->td_transfer_last = td_last;
#if USB_DEBUG
#ifdef USB_DEBUG
if (ohcidebug > 8) {
DPRINTF("data before transfer:\n");
ohci_dump_itds(xfer->td_transfer_first);

View File

@ -25,8 +25,28 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -49,9 +49,28 @@ __FBSDID("$FreeBSD$");
* sharing of code between *BSD's
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -38,9 +38,28 @@ __FBSDID("$FreeBSD$");
* ftp://download.intel.com/design/intarch/datashts/29056201.pdf
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR uhcidebug
@ -1103,7 +1122,7 @@ uhci_non_isoc_done_sub(struct usb_xfer *xfer)
td_alt_next = td->alt_next;
if (xfer->aframes != xfer->nframes) {
xfer->frlengths[xfer->aframes] = 0;
usbd_xfer_set_frame_len(xfer, xfer->aframes, 0);
}
while (1) {

View File

@ -48,8 +48,28 @@ __FBSDID("$FreeBSD$");
* sharing of code between *BSD's
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>
@ -339,7 +359,7 @@ uhci_pci_attach(device_t self)
* that the BIOS won't touch the keyboard anymore if it is connected
* to the ports of the root hub?
*/
#if USB_DEBUG
#ifdef USB_DEBUG
if (pci_read_config(self, PCI_LEGSUP, 2) != PCI_LEGSUP_USBPIRQDEN) {
device_printf(self, "LegSup = 0x%04x\n",
pci_read_config(self, PCI_LEGSUP, 2));

View File

@ -24,9 +24,28 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR usb_ctrl_debug
@ -52,7 +71,7 @@ static void usb_post_init(void *);
/* static variables */
#if USB_DEBUG
#ifdef USB_DEBUG
static int usb_ctrl_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, ctrl, CTLFLAG_RW, 0, "USB controller");

View File

@ -32,10 +32,28 @@
* NOTE: The datasheet does not document everything.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_revision.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR uss820dcidebug

View File

@ -27,8 +27,28 @@ __FBSDID("$FreeBSD$");
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_busdma.h>

View File

@ -48,29 +48,39 @@ __FBSDID("$FreeBSD$");
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include <dev/usb/usb_ioctl.h>
#define USB_DEBUG_VAR uhid_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_hid.h>
#include <dev/usb/input/usb_rdesc.h>
#include <dev/usb/quirk/usb_quirk.h>
#if USB_DEBUG
@ -150,38 +160,40 @@ static struct usb_fifo_methods uhid_fifo_methods = {
};
static void
uhid_intr_callback(struct usb_xfer *xfer)
uhid_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uhid_softc *sc = xfer->priv_sc;
struct uhid_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("transferred!\n");
if (xfer->actlen >= sc->sc_isize) {
usb_fifo_put_data(
sc->sc_fifo.fp[USB_FIFO_RX],
xfer->frbuffers,
pc = usbd_xfer_get_frame(xfer, 0);
if (actlen >= sc->sc_isize) {
usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc,
0, sc->sc_isize, 1);
} else {
/* ignore it */
DPRINTF("ignored short transfer, "
"%d bytes\n", xfer->actlen);
DPRINTF("ignored short transfer, %d bytes\n", actlen);
}
case USB_ST_SETUP:
re_submit:
if (usb_fifo_put_bytes_max(
sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
xfer->frlengths[0] = sc->sc_isize;
usbd_xfer_set_frame_len(xfer, 0, sc->sc_isize);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto re_submit;
}
return;
@ -213,10 +225,11 @@ uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no,
}
static void
uhid_write_callback(struct usb_xfer *xfer)
uhid_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uhid_softc *sc = xfer->priv_sc;
struct uhid_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
uint32_t size = sc->sc_osize;
uint32_t actlen;
uint8_t id;
@ -226,15 +239,13 @@ uhid_write_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
/* try to extract the ID byte */
if (sc->sc_oid) {
if (usb_fifo_get_data(
sc->sc_fifo.fp[USB_FIFO_TX],
xfer->frbuffers,
pc = usbd_xfer_get_frame(xfer, 0);
if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
0, 1, &actlen, 0)) {
if (actlen != 1) {
goto tr_error;
}
usbd_copy_out(xfer->frbuffers, 0, &id, 1);
usbd_copy_out(pc, 0, &id, 1);
} else {
return;
@ -246,9 +257,8 @@ uhid_write_callback(struct usb_xfer *xfer)
id = 0;
}
if (usb_fifo_get_data(
sc->sc_fifo.fp[USB_FIFO_TX],
xfer->frbuffers + 1,
pc = usbd_xfer_get_frame(xfer, 1);
if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
0, UHID_BSIZE, &actlen, 1)) {
if (actlen != size) {
goto tr_error;
@ -257,11 +267,12 @@ uhid_write_callback(struct usb_xfer *xfer)
(&req, sc->sc_iface_no,
UHID_OUTPUT_REPORT, id, size);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = size;
xfer->nframes = xfer->frlengths[1] ? 2 : 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, size);
usbd_xfer_set_frames(xfer, size ? 2 : 1);
usbd_transfer_submit(xfer);
}
return;
@ -275,15 +286,18 @@ uhid_write_callback(struct usb_xfer *xfer)
}
static void
uhid_read_callback(struct usb_xfer *xfer)
uhid_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uhid_softc *sc = xfer->priv_sc;
struct uhid_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
pc = usbd_xfer_get_frame(xfer, 0);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], xfer->frbuffers,
sizeof(req), sc->sc_isize, 1);
usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc, sizeof(req),
sc->sc_isize, 1);
return;
case USB_ST_SETUP:
@ -294,11 +308,11 @@ uhid_read_callback(struct usb_xfer *xfer)
(&req, sc->sc_iface_no, UHID_INPUT_REPORT,
sc->sc_iid, sc->sc_isize);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = sc->sc_isize;
xfer->nframes = xfer->frlengths[1] ? 2 : 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, sc->sc_isize);
usbd_xfer_set_frames(xfer, sc->sc_isize ? 2 : 1);
usbd_transfer_submit(xfer);
}
return;
@ -343,7 +357,7 @@ static const struct usb_config uhid_config[UHID_N_TRANSFER] = {
static void
uhid_start_read(struct usb_fifo *fifo)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
if (sc->sc_flags & UHID_FLAG_IMMED) {
usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_RD]);
@ -355,7 +369,7 @@ uhid_start_read(struct usb_fifo *fifo)
static void
uhid_stop_read(struct usb_fifo *fifo)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_RD]);
usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_RD]);
@ -364,7 +378,7 @@ uhid_stop_read(struct usb_fifo *fifo)
static void
uhid_start_write(struct usb_fifo *fifo)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_WR]);
}
@ -372,7 +386,7 @@ uhid_start_write(struct usb_fifo *fifo)
static void
uhid_stop_write(struct usb_fifo *fifo)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_WR]);
}
@ -449,7 +463,7 @@ uhid_set_report(struct uhid_softc *sc, uint8_t type,
static int
uhid_open(struct usb_fifo *fifo, int fflags)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
/*
* The buffers are one byte larger than maximum so that one
@ -485,7 +499,7 @@ static int
uhid_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
int fflags)
{
struct uhid_softc *sc = fifo->priv_sc0;
struct uhid_softc *sc = usb_fifo_softc(fifo);
struct usb_gen_descriptor *ugd;
uint32_t size;
int error = 0;
@ -656,7 +670,7 @@ uhid_attach(device_t dev)
if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) {
sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr);
sc->sc_repdesc_ptr = USB_ADD_BYTES(uhid_graphire_report_descr, 0);
sc->sc_repdesc_ptr = &uhid_graphire_report_descr;
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
} else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
@ -677,7 +691,7 @@ uhid_attach(device_t dev)
usbd_errstr(error));
}
sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr);
sc->sc_repdesc_ptr = USB_ADD_BYTES(uhid_graphire3_4x5_report_descr, 0);
sc->sc_repdesc_ptr = &uhid_graphire3_4x5_report_descr;
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
}
} else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) &&
@ -686,7 +700,7 @@ uhid_attach(device_t dev)
/* the Xbox 360 gamepad has no report descriptor */
sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr);
sc->sc_repdesc_ptr = USB_ADD_BYTES(uhid_xb360gp_report_descr, 0);
sc->sc_repdesc_ptr = &uhid_xb360gp_report_descr;
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
}
if (sc->sc_repdesc_ptr == NULL) {

View File

@ -48,22 +48,33 @@ __FBSDID("$FreeBSD$");
#include "opt_kbd.h"
#include "opt_ukbd.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#define USB_DEBUG_VAR ukbd_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_hid.h>
#include <dev/usb/quirk/usb_quirk.h>
@ -304,7 +315,7 @@ ukbd_get_key(struct ukbd_softc *sc, uint8_t wait)
while (sc->sc_inputs == 0) {
usbd_do_poll(sc->sc_xfer, UKBD_N_TRANSFER);
usbd_transfer_poll(sc->sc_xfer, UKBD_N_TRANSFER);
DELAY(1000); /* delay 1 ms */
@ -480,15 +491,19 @@ ukbd_apple_swap(uint8_t keycode) {
}
static void
ukbd_intr_callback(struct usb_xfer *xfer)
ukbd_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ukbd_softc *sc = xfer->priv_sc;
uint16_t len = xfer->actlen;
struct ukbd_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t i;
uint8_t offset;
uint8_t id;
uint8_t apple_fn;
uint8_t apple_eject;
int len;
usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
pc = usbd_xfer_get_frame(xfer, 0);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -501,7 +516,7 @@ ukbd_intr_callback(struct usb_xfer *xfer)
if (sc->sc_kbd_id != 0) {
/* check and remove HID ID byte */
usbd_copy_out(xfer->frbuffers, 0, &id, 1);
usbd_copy_out(pc, 0, &id, 1);
if (id != sc->sc_kbd_id) {
DPRINTF("wrong HID ID\n");
goto tr_setup;
@ -518,8 +533,7 @@ ukbd_intr_callback(struct usb_xfer *xfer)
if (len) {
memset(&sc->sc_ndata, 0, sizeof(sc->sc_ndata));
usbd_copy_out(xfer->frbuffers, offset,
&sc->sc_ndata, len);
usbd_copy_out(pc, offset, &sc->sc_ndata, len);
if ((sc->sc_flags & UKBD_FLAG_APPLE_EJECT) &&
hid_get_data((uint8_t *)&sc->sc_ndata,
@ -567,7 +581,7 @@ ukbd_intr_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
if (sc->sc_inputs < UKBD_IN_BUF_FULL) {
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
} else {
DPRINTF("input queue is full!\n");
@ -575,11 +589,11 @@ ukbd_intr_callback(struct usb_xfer *xfer)
break;
default: /* Error */
DPRINTF("error=%s\n", usbd_errstr(xfer->error));
DPRINTF("error=%s\n", usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -587,11 +601,12 @@ ukbd_intr_callback(struct usb_xfer *xfer)
}
static void
ukbd_set_leds_callback(struct usb_xfer *xfer)
ukbd_set_leds_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_device_request req;
struct usb_page_cache *pc;
uint8_t buf[2];
struct ukbd_softc *sc = xfer->priv_sc;
struct ukbd_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -617,18 +632,20 @@ ukbd_set_leds_callback(struct usb_xfer *xfer)
buf[1] = 0;
}
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(xfer->frbuffers + 1, 0, buf, sizeof(buf));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_in(pc, 0, buf, sizeof(buf));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = req.wLength[0];
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, req.wLength[0]);
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
DPRINTFN(0, "error=%s\n", usbd_errstr(xfer->error));
DPRINTFN(0, "error=%s\n", usbd_errstr(error));
return;
}
}

View File

@ -42,25 +42,36 @@ __FBSDID("$FreeBSD$");
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR ums_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_hid.h>
#include <dev/usb/quirk/usb_quirk.h>
@ -170,12 +181,12 @@ ums_put_queue_timeout(void *__sc)
}
static void
ums_intr_callback(struct usb_xfer *xfer)
ums_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ums_softc *sc = xfer->priv_sc;
struct ums_softc *sc = usbd_xfer_softc(xfer);
struct ums_info *info = &sc->sc_info[0];
struct usb_page_cache *pc;
uint8_t *buf = sc->sc_temp;
uint16_t len = xfer->actlen;
int32_t buttons = 0;
int32_t dw = 0;
int32_t dx = 0;
@ -184,6 +195,9 @@ ums_intr_callback(struct usb_xfer *xfer)
int32_t dt = 0;
uint8_t i;
uint8_t id;
int len;
usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -197,7 +211,8 @@ ums_intr_callback(struct usb_xfer *xfer)
if (len == 0)
goto tr_setup;
usbd_copy_out(xfer->frbuffers, 0, buf, len);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, len);
DPRINTFN(6, "data = %02x %02x %02x %02x "
"%02x %02x %02x %02x\n",
@ -301,15 +316,15 @@ ums_intr_callback(struct usb_xfer *xfer)
/* check if we can put more data into the FIFO */
if (usb_fifo_put_bytes_max(
sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -547,10 +562,10 @@ ums_attach(device_t dev)
/* Some wheels need the Z axis reversed. */
info->sc_flags |= UMS_FLAG_REVZ;
}
if (isize > sc->sc_xfer[UMS_INTR_DT]->max_frame_size) {
if (isize > usbd_xfer_max_framelen(sc->sc_xfer[UMS_INTR_DT])) {
DPRINTF("WARNING: report size, %d bytes, is larger "
"than interrupt size, %d bytes!\n",
isize, sc->sc_xfer[UMS_INTR_DT]->max_frame_size);
"than interrupt size, %d bytes!\n", isize,
usbd_xfer_max_framelen(sc->sc_xfer[UMS_INTR_DT]));
}
free(d_ptr, M_TEMP);
d_ptr = NULL;
@ -637,7 +652,7 @@ ums_detach(device_t self)
static void
ums_start_read(struct usb_fifo *fifo)
{
struct ums_softc *sc = fifo->priv_sc0;
struct ums_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[UMS_INTR_DT]);
}
@ -645,7 +660,7 @@ ums_start_read(struct usb_fifo *fifo)
static void
ums_stop_read(struct usb_fifo *fifo)
{
struct ums_softc *sc = fifo->priv_sc0;
struct ums_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[UMS_INTR_DT]);
usb_callout_stop(&sc->sc_callout);
@ -712,7 +727,7 @@ ums_reset_buf(struct ums_softc *sc)
static int
ums_open(struct usb_fifo *fifo, int fflags)
{
struct ums_softc *sc = fifo->priv_sc0;
struct ums_softc *sc = usb_fifo_softc(fifo);
DPRINTFN(2, "\n");
@ -747,7 +762,7 @@ ums_close(struct usb_fifo *fifo, int fflags)
static int
ums_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags)
{
struct ums_softc *sc = fifo->priv_sc0;
struct ums_softc *sc = usb_fifo_softc(fifo);
mousemode_t mode;
int error = 0;

View File

@ -57,19 +57,33 @@ __FBSDID("$FreeBSD$");
*
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR udbp_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <sys/mbuf.h>
@ -395,10 +409,14 @@ udbp_detach(device_t dev)
}
static void
udbp_bulk_read_callback(struct usb_xfer *xfer)
udbp_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udbp_softc *sc = xfer->priv_sc;
struct udbp_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
struct mbuf *m;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -416,14 +434,14 @@ udbp_bulk_read_callback(struct usb_xfer *xfer)
m_freem(m);
goto tr_setup;
}
m->m_pkthdr.len = m->m_len = xfer->actlen;
m->m_pkthdr.len = m->m_len = actlen;
usbd_copy_out(xfer->frbuffers, 0, m->m_data, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, m->m_data, actlen);
sc->sc_bulk_in_buffer = m;
DPRINTF("received package %d "
"bytes\n", xfer->actlen);
DPRINTF("received package %d bytes\n", actlen);
case USB_ST_SETUP:
tr_setup:
@ -435,12 +453,12 @@ udbp_bulk_read_callback(struct usb_xfer *xfer)
usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
return;
}
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
sc->sc_flags |= UDBP_FLAG_READ_STALL;
usbd_transfer_start(sc->sc_xfer[UDBP_T_RD_CS]);
@ -451,9 +469,9 @@ udbp_bulk_read_callback(struct usb_xfer *xfer)
}
static void
udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer)
udbp_bulk_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udbp_softc *sc = xfer->priv_sc;
struct udbp_softc *sc = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_RD];
if (usbd_clear_stall_callback(xfer, xfer_other)) {
@ -504,9 +522,10 @@ udbp_bulk_read_complete(node_p node, hook_p hook, void *arg1, int arg2)
}
static void
udbp_bulk_write_callback(struct usb_xfer *xfer)
udbp_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udbp_softc *sc = xfer->priv_sc;
struct udbp_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
struct mbuf *m;
switch (USB_GET_STATE(xfer)) {
@ -535,20 +554,20 @@ udbp_bulk_write_callback(struct usb_xfer *xfer)
MCLBYTES);
m->m_pkthdr.len = MCLBYTES;
}
usbd_m_copy_in(xfer->frbuffers, 0, m, 0, m->m_pkthdr.len);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
xfer->frlengths[0] = m->m_pkthdr.len;
usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len);
DPRINTF("packet out: %d bytes\n", m->m_pkthdr.len);
m_freem(m);
DPRINTF("packet out: %d bytes\n",
xfer->frlengths[0]);
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
sc->sc_flags |= UDBP_FLAG_WRITE_STALL;
usbd_transfer_start(sc->sc_xfer[UDBP_T_WR_CS]);
@ -559,9 +578,9 @@ udbp_bulk_write_callback(struct usb_xfer *xfer)
}
static void
udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer)
udbp_bulk_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udbp_softc *sc = xfer->priv_sc;
struct udbp_softc *sc = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = sc->sc_xfer[UDBP_T_WR];
if (usbd_clear_stall_callback(xfer, xfer_other)) {

View File

@ -32,23 +32,36 @@
__FBSDID("$FreeBSD$");
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/ufm_ioctl.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/ufm_ioctl.h>
#define UFM_CMD0 0x00
#define UFM_CMD_SET_FREQ 0x01
@ -299,7 +312,7 @@ static int
ufm_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
int fflags)
{
struct ufm_softc *sc = fifo->priv_sc0;
struct ufm_softc *sc = usb_fifo_softc(fifo);
int error = 0;
switch (cmd) {

View File

@ -68,20 +68,34 @@ __FBSDID("$FreeBSD$");
* transfers are done using usbd_transfer() and friends.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR aue_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_auereg.h>
@ -711,19 +725,24 @@ aue_detach(device_t dev)
}
static void
aue_intr_callback(struct usb_xfer *xfer)
aue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct aue_softc *sc = xfer->priv_sc;
struct aue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct aue_intrpkt pkt;
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) &&
xfer->actlen >= sizeof(pkt)) {
actlen >= sizeof(pkt)) {
usbd_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
if (pkt.aue_txstat0)
ifp->if_oerrors++;
@ -734,14 +753,14 @@ aue_intr_callback(struct usb_xfer *xfer)
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -749,31 +768,36 @@ aue_intr_callback(struct usb_xfer *xfer)
}
static void
aue_bulk_read_callback(struct usb_xfer *xfer)
aue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct aue_softc *sc = xfer->priv_sc;
struct aue_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct aue_rxpkt stat;
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
pc = usbd_xfer_get_frame(xfer, 0);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTFN(11, "received %d bytes\n", xfer->actlen);
DPRINTFN(11, "received %d bytes\n", actlen);
if (sc->sc_flags & AUE_FLAG_VER_2) {
if (xfer->actlen == 0) {
if (actlen == 0) {
ifp->if_ierrors++;
goto tr_setup;
}
} else {
if (xfer->actlen <= (sizeof(stat) + ETHER_CRC_LEN)) {
if (actlen <= sizeof(stat) + ETHER_CRC_LEN) {
ifp->if_ierrors++;
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers,
xfer->actlen - sizeof(stat), &stat, sizeof(stat));
usbd_copy_out(pc, actlen - sizeof(stat), &stat,
sizeof(stat));
/*
* turn off all the non-error bits in the rx status
@ -785,25 +809,25 @@ aue_bulk_read_callback(struct usb_xfer *xfer)
goto tr_setup;
}
/* No errors; receive the packet. */
xfer->actlen -= (sizeof(stat) + ETHER_CRC_LEN);
actlen -= (sizeof(stat) + ETHER_CRC_LEN);
}
uether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen);
uether_rxbuf(ue, pc, 0, actlen);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -811,16 +835,21 @@ aue_bulk_read_callback(struct usb_xfer *xfer)
}
static void
aue_bulk_write_callback(struct usb_xfer *xfer)
aue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct aue_softc *sc = xfer->priv_sc;
struct aue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
uint8_t buf[2];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
pc = usbd_xfer_get_frame(xfer, 0);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTFN(11, "transfer of %d bytes complete\n", xfer->actlen);
DPRINTFN(11, "transfer of %d bytes complete\n", actlen);
ifp->if_opackets++;
/* FALLTHROUGH */
@ -840,14 +869,13 @@ aue_bulk_write_callback(struct usb_xfer *xfer)
m->m_pkthdr.len = MCLBYTES;
if (sc->sc_flags & AUE_FLAG_VER_2) {
xfer->frlengths[0] = m->m_pkthdr.len;
usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len);
usbd_m_copy_in(xfer->frbuffers, 0,
m, 0, m->m_pkthdr.len);
usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
} else {
xfer->frlengths[0] = (m->m_pkthdr.len + 2);
usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2));
/*
* The ADMtek documentation says that the
@ -860,10 +888,8 @@ aue_bulk_write_callback(struct usb_xfer *xfer)
buf[0] = (uint8_t)(m->m_pkthdr.len);
buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
usbd_copy_in(xfer->frbuffers, 0, buf, 2);
usbd_m_copy_in(xfer->frbuffers, 2,
m, 0, m->m_pkthdr.len);
usbd_copy_in(pc, 0, buf, 2);
usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
}
/*
@ -879,13 +905,13 @@ aue_bulk_write_callback(struct usb_xfer *xfer)
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -951,7 +977,7 @@ aue_init(struct usb_ether *ue)
AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
usbd_transfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
aue_start(ue);

View File

@ -76,20 +76,34 @@ __FBSDID("$FreeBSD$");
* http://www.asix.com.tw/FrootAttach/datasheet/AX88772_datasheet_Rev10.pdf
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR axe_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_axereg.h>
@ -731,20 +745,20 @@ axe_detach(device_t dev)
}
static void
axe_intr_callback(struct usb_xfer *xfer)
axe_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -756,56 +770,61 @@ axe_intr_callback(struct usb_xfer *xfer)
#endif
static void
axe_bulk_read_callback(struct usb_xfer *xfer)
axe_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct axe_softc *sc = xfer->priv_sc;
struct axe_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct axe_sframe_hdr hdr;
int error, pos, len, adjust;
struct usb_page_cache *pc;
int err, pos, len, adjust;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
pos = 0;
pc = usbd_xfer_get_frame(xfer, 0);
while (1) {
if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) {
if (xfer->actlen < sizeof(hdr)) {
if (actlen < sizeof(hdr)) {
/* too little data */
break;
}
usbd_copy_out(xfer->frbuffers, pos, &hdr, sizeof(hdr));
usbd_copy_out(pc, pos, &hdr, sizeof(hdr));
if ((hdr.len ^ hdr.ilen) != 0xFFFF) {
/* we lost sync */
break;
}
xfer->actlen -= sizeof(hdr);
actlen -= sizeof(hdr);
pos += sizeof(hdr);
len = le16toh(hdr.len);
if (len > xfer->actlen) {
if (len > actlen) {
/* invalid length */
break;
}
adjust = (len & 1);
} else {
len = xfer->actlen;
len = actlen;
adjust = 0;
}
error = uether_rxbuf(ue, xfer->frbuffers, pos, len);
if (error)
err = uether_rxbuf(ue, pc, pos, len);
if (err)
break;
pos += len;
xfer->actlen -= len;
actlen -= len;
if (xfer->actlen <= adjust) {
if (actlen <= adjust) {
/* we are finished */
goto tr_setup;
}
pos += adjust;
xfer->actlen -= adjust;
actlen -= adjust;
}
/* count an error */
@ -814,18 +833,17 @@ axe_bulk_read_callback(struct usb_xfer *xfer)
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
DPRINTF("bulk read error, %s\n", usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -838,11 +856,12 @@ axe_bulk_read_callback(struct usb_xfer *xfer)
#endif
static void
axe_bulk_write_callback(struct usb_xfer *xfer)
axe_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct axe_softc *sc = xfer->priv_sc;
struct axe_softc *sc = usbd_xfer_softc(xfer);
struct axe_sframe_hdr hdr;
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
int pos;
@ -860,6 +879,7 @@ axe_bulk_write_callback(struct usb_xfer *xfer)
return;
}
pos = 0;
pc = usbd_xfer_get_frame(xfer, 0);
while (1) {
@ -878,7 +898,7 @@ axe_bulk_write_callback(struct usb_xfer *xfer)
hdr.len = htole16(m->m_pkthdr.len);
hdr.ilen = ~hdr.len;
usbd_copy_in(xfer->frbuffers, pos, &hdr, sizeof(hdr));
usbd_copy_in(pc, pos, &hdr, sizeof(hdr));
pos += sizeof(hdr);
@ -890,9 +910,7 @@ axe_bulk_write_callback(struct usb_xfer *xfer)
* USB_FORCE_SHORT_XFER flag instead.
*/
}
usbd_m_copy_in(xfer->frbuffers, pos,
m, 0, m->m_pkthdr.len);
usbd_m_copy_in(pc, pos, m, 0, m->m_pkthdr.len);
pos += m->m_pkthdr.len;
/*
@ -914,19 +932,19 @@ axe_bulk_write_callback(struct usb_xfer *xfer)
}
}
xfer->frlengths[0] = pos;
usbd_xfer_set_frame_len(xfer, 0, pos);
usbd_transfer_submit(xfer);
return;
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -1010,7 +1028,7 @@ axe_init(struct usb_ether *ue)
/* Load the multicast filter. */
axe_setmulti(ue);
usbd_transfer_set_stall(sc->sc_xfer[AXE_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[AXE_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
axe_start(ue);

View File

@ -43,23 +43,36 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR cdce_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_process.h>
#include "usb_if.h"
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_cdcereg.h>
@ -426,22 +439,24 @@ cdce_free_queue(struct mbuf **ppm, uint8_t n)
}
static void
cdce_bulk_write_callback(struct usb_xfer *xfer)
cdce_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct cdce_softc *sc = xfer->priv_sc;
struct cdce_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct mbuf *m;
struct mbuf *mt;
uint32_t crc;
uint8_t x;
int actlen, aframes;
usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL);
DPRINTFN(1, "\n");
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTFN(11, "transfer complete: "
"%u bytes in %u frames\n", xfer->actlen,
xfer->aframes);
DPRINTFN(11, "transfer complete: %u bytes in %u frames\n",
actlen, aframes);
ifp->if_opackets++;
@ -486,8 +501,7 @@ cdce_bulk_write_callback(struct usb_xfer *xfer)
m->m_pkthdr.len = MCLBYTES;
}
sc->sc_tx_buf[x] = m;
xfer->frlengths[x] = m->m_len;
usbd_set_frame_data(xfer, m->m_data, x);
usbd_xfer_set_frame_data(xfer, x, m->m_data, m->m_len);
/*
* If there's a BPF listener, bounce a copy of
@ -496,14 +510,15 @@ cdce_bulk_write_callback(struct usb_xfer *xfer)
BPF_MTAP(ifp, m);
}
if (x != 0) {
xfer->nframes = x;
usbd_xfer_set_frames(xfer, x);
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
/* free all previous TX buffers */
cdce_free_queue(sc->sc_tx_buf, CDCE_FRAMES_MAX);
@ -511,9 +526,9 @@ cdce_bulk_write_callback(struct usb_xfer *xfer)
/* count output errors */
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -554,7 +569,7 @@ cdce_init(struct usb_ether *ue)
usbd_transfer_start(sc->sc_xfer[CDCE_INTR_TX]);
/* stall data write direction, which depends on USB mode */
usbd_transfer_set_stall(sc->sc_xfer[CDCE_BULK_TX]);
usbd_xfer_set_stall(sc->sc_xfer[CDCE_BULK_TX]);
/* start data transfers */
cdce_start(ue);
@ -608,34 +623,36 @@ cdce_resume(device_t dev)
}
static void
cdce_bulk_read_callback(struct usb_xfer *xfer)
cdce_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct cdce_softc *sc = xfer->priv_sc;
struct cdce_softc *sc = usbd_xfer_softc(xfer);
struct mbuf *m;
uint8_t x;
int actlen, aframes, len;
usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("received %u bytes in %u frames\n",
xfer->actlen, xfer->aframes);
DPRINTF("received %u bytes in %u frames\n", actlen, aframes);
for (x = 0; x != xfer->aframes; x++) {
for (x = 0; x != aframes; x++) {
m = sc->sc_rx_buf[x];
sc->sc_rx_buf[x] = NULL;
len = usbd_xfer_get_frame_len(xfer, x);
/* Strip off CRC added by Zaurus, if any */
if ((sc->sc_flags & CDCE_FLAG_ZAURUS) &&
(xfer->frlengths[x] >= 14))
xfer->frlengths[x] -= 4;
if ((sc->sc_flags & CDCE_FLAG_ZAURUS) && len >= 14)
len -= 4;
if (xfer->frlengths[x] < sizeof(struct ether_header)) {
if (len < sizeof(struct ether_header)) {
m_freem(m);
continue;
}
/* queue up mbuf */
uether_rxmbuf(&sc->sc_ue, m, xfer->frlengths[x]);
uether_rxmbuf(&sc->sc_ue, m, len);
}
/* FALLTHROUGH */
@ -654,11 +671,10 @@ cdce_bulk_read_callback(struct usb_xfer *xfer)
m = sc->sc_rx_buf[x];
}
usbd_set_frame_data(xfer, m->m_data, x);
xfer->frlengths[x] = m->m_len;
usbd_xfer_set_frame_data(xfer, x, m->m_data, m->m_len);
}
/* set number of frames and start hardware */
xfer->nframes = x;
usbd_xfer_set_frames(xfer, x);
usbd_transfer_submit(xfer);
/* flush any received frames */
uether_rxflush(&sc->sc_ue);
@ -666,13 +682,13 @@ cdce_bulk_read_callback(struct usb_xfer *xfer)
default: /* Error */
DPRINTF("error = %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
tr_stall:
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
xfer->nframes = 0;
usbd_xfer_set_stall(xfer);
usbd_xfer_set_frames(xfer, 0);
usbd_transfer_submit(xfer);
break;
}
@ -684,28 +700,30 @@ cdce_bulk_read_callback(struct usb_xfer *xfer)
}
static void
cdce_intr_read_callback(struct usb_xfer *xfer)
cdce_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
; /* style fix */
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("Received %d bytes\n",
xfer->actlen);
DPRINTF("Received %d bytes\n", actlen);
/* TODO: decode some indications */
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* start clear stall */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -713,27 +731,30 @@ cdce_intr_read_callback(struct usb_xfer *xfer)
}
static void
cdce_intr_write_callback(struct usb_xfer *xfer)
cdce_intr_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
; /* style fix */
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("Transferred %d bytes\n", xfer->actlen);
DPRINTF("Transferred %d bytes\n", actlen);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
#if 0
xfer->frlengths[0] = XXX;
usbd_xfer_set_frame_len(xfer, 0, XXX);
usbd_transfer_submit(xfer);
#endif
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* start clear stall */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;

View File

@ -51,20 +51,34 @@ __FBSDID("$FreeBSD$");
* transaction, which helps performance a great deal.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR cue_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_cuereg.h>
@ -426,42 +440,47 @@ cue_detach(device_t dev)
}
static void
cue_bulk_read_callback(struct usb_xfer *xfer)
cue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct cue_softc *sc = xfer->priv_sc;
struct cue_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct usb_page_cache *pc;
uint8_t buf[2];
int len;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen <= (2 + sizeof(struct ether_header))) {
if (actlen <= (2 + sizeof(struct ether_header))) {
ifp->if_ierrors++;
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 2);
xfer->actlen -= 2;
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, 2);
actlen -= 2;
len = buf[0] | (buf[1] << 8);
len = min(xfer->actlen, len);
len = min(actlen, len);
uether_rxbuf(ue, xfer->frbuffers, 2, len);
uether_rxbuf(ue, pc, 2, len);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -470,10 +489,11 @@ cue_bulk_read_callback(struct usb_xfer *xfer)
}
static void
cue_bulk_write_callback(struct usb_xfer *xfer)
cue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct cue_softc *sc = xfer->priv_sc;
struct cue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
uint8_t buf[2];
@ -491,17 +511,16 @@ cue_bulk_write_callback(struct usb_xfer *xfer)
return;
if (m->m_pkthdr.len > MCLBYTES)
m->m_pkthdr.len = MCLBYTES;
xfer->frlengths[0] = (m->m_pkthdr.len + 2);
usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2));
/* the first two bytes are the frame length */
buf[0] = (uint8_t)(m->m_pkthdr.len);
buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
usbd_copy_in(xfer->frbuffers, 0, buf, 2);
usbd_m_copy_in(xfer->frbuffers, 2,
m, 0, m->m_pkthdr.len);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, buf, 2);
usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
/*
* If there's a BPF listener, bounce a copy of this frame
@ -517,13 +536,13 @@ cue_bulk_write_callback(struct usb_xfer *xfer)
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -598,7 +617,7 @@ cue_init(struct usb_ether *ue)
/* Program the LED operation. */
cue_csr_write_1(sc, CUE_LEDCTL, CUE_LEDCTL_FOLLOW_LINK);
usbd_transfer_set_stall(sc->sc_xfer[CUE_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[CUE_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
cue_start(ue);

View File

@ -65,20 +65,34 @@ __FBSDID("$FreeBSD$");
* the development of this driver.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR kue_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_kuereg.h>
@ -514,42 +528,47 @@ kue_detach(device_t dev)
* the higher level protocols.
*/
static void
kue_bulk_read_callback(struct usb_xfer *xfer)
kue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct kue_softc *sc = xfer->priv_sc;
struct kue_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct usb_page_cache *pc;
uint8_t buf[2];
int len;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen <= (2 + sizeof(struct ether_header))) {
if (actlen <= (2 + sizeof(struct ether_header))) {
ifp->if_ierrors++;
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 2);
xfer->actlen -= 2;
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, 2);
actlen -= 2;
len = buf[0] | (buf[1] << 8);
len = min(xfer->actlen, len);
len = min(actlen, len);
uether_rxbuf(ue, xfer->frbuffers, 2, len);
uether_rxbuf(ue, pc, 2, len);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -558,10 +577,11 @@ kue_bulk_read_callback(struct usb_xfer *xfer)
}
static void
kue_bulk_write_callback(struct usb_xfer *xfer)
kue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct kue_softc *sc = xfer->priv_sc;
struct kue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
int total_len;
int temp_len;
@ -589,15 +609,12 @@ kue_bulk_write_callback(struct usb_xfer *xfer)
buf[0] = (uint8_t)(m->m_pkthdr.len);
buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
usbd_copy_in(xfer->frbuffers, 0, buf, 2);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, buf, 2);
usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
usbd_m_copy_in(xfer->frbuffers, 2,
m, 0, m->m_pkthdr.len);
usbd_frame_zero(xfer->frbuffers, temp_len,
total_len - temp_len);
xfer->frlengths[0] = total_len;
usbd_frame_zero(pc, temp_len, total_len - temp_len);
usbd_xfer_set_frame_len(xfer, 0, total_len);
/*
* if there's a BPF listener, bounce a copy
@ -613,13 +630,13 @@ kue_bulk_write_callback(struct usb_xfer *xfer)
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -664,7 +681,7 @@ kue_init(struct usb_ether *ue)
/* load the multicast filter */
kue_setpromisc(ue);
usbd_transfer_set_stall(sc->sc_xfer[KUE_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[KUE_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
kue_start(ue);

View File

@ -65,20 +65,34 @@ __FBSDID("$FreeBSD$");
* ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR rue_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_ruereg.h>
@ -613,19 +627,24 @@ rue_detach(device_t dev)
}
static void
rue_intr_callback(struct usb_xfer *xfer)
rue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct rue_softc *sc = xfer->priv_sc;
struct rue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct rue_intrpkt pkt;
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (ifp && (ifp->if_drv_flags & IFF_DRV_RUNNING) &&
(xfer->actlen >= sizeof(pkt))) {
actlen >= sizeof(pkt)) {
usbd_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
ifp->if_ierrors += pkt.rue_rxlost_cnt;
ifp->if_ierrors += pkt.rue_crcerr_cnt;
@ -634,14 +653,14 @@ rue_intr_callback(struct usb_xfer *xfer)
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -649,23 +668,27 @@ rue_intr_callback(struct usb_xfer *xfer)
}
static void
rue_bulk_read_callback(struct usb_xfer *xfer)
rue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct rue_softc *sc = xfer->priv_sc;
struct rue_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct usb_page_cache *pc;
uint16_t status;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 4) {
if (actlen < 4) {
ifp->if_ierrors++;
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, xfer->actlen - 4,
&status, sizeof(status));
xfer->actlen -= 4;
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, actlen - 4, &status, sizeof(status));
actlen -= 4;
/* check recieve packet was valid or not */
status = le16toh(status);
@ -673,22 +696,22 @@ rue_bulk_read_callback(struct usb_xfer *xfer)
ifp->if_ierrors++;
goto tr_setup;
}
uether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen);
uether_rxbuf(ue, pc, 0, actlen);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -696,10 +719,11 @@ rue_bulk_read_callback(struct usb_xfer *xfer)
}
static void
rue_bulk_write_callback(struct usb_xfer *xfer)
rue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct rue_softc *sc = xfer->priv_sc;
struct rue_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
int temp_len;
@ -725,8 +749,8 @@ rue_bulk_write_callback(struct usb_xfer *xfer)
m->m_pkthdr.len = MCLBYTES;
temp_len = m->m_pkthdr.len;
usbd_m_copy_in(xfer->frbuffers, 0,
m, 0, m->m_pkthdr.len);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
/*
* This is an undocumented behavior.
@ -734,11 +758,11 @@ rue_bulk_write_callback(struct usb_xfer *xfer)
* RUE_MIN_FRAMELEN (60) byte packet.
*/
if (temp_len < RUE_MIN_FRAMELEN) {
usbd_frame_zero(xfer->frbuffers, temp_len,
usbd_frame_zero(pc, temp_len,
RUE_MIN_FRAMELEN - temp_len);
temp_len = RUE_MIN_FRAMELEN;
}
xfer->frlengths[0] = temp_len;
usbd_xfer_set_frame_len(xfer, 0, temp_len);
/*
* if there's a BPF listener, bounce a copy
@ -754,13 +778,13 @@ rue_bulk_write_callback(struct usb_xfer *xfer)
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -829,7 +853,7 @@ rue_init(struct usb_ether *ue)
/* Enable RX and TX */
rue_csr_write_1(sc, RUE_CR, (RUE_CR_TE | RUE_CR_RE | RUE_CR_EP3CLREN));
usbd_transfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[RUE_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
rue_start(ue);

View File

@ -46,20 +46,34 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR udav_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/net/usb_ethernet.h>
#include <dev/usb/net/if_udavreg.h>
@ -420,7 +434,7 @@ udav_init(struct usb_ether *ue)
UDAV_SETBIT(sc, UDAV_GPCR, UDAV_GPCR_GEP_CNTL0);
UDAV_CLRBIT(sc, UDAV_GPR, UDAV_GPR_GEPIO0);
usbd_transfer_set_stall(sc->sc_xfer[UDAV_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UDAV_BULK_DT_WR]);
ifp->if_drv_flags |= IFF_DRV_RUNNING;
udav_start(ue);
@ -531,10 +545,11 @@ udav_start(struct usb_ether *ue)
}
static void
udav_bulk_write_callback(struct usb_xfer *xfer)
udav_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udav_softc *sc = xfer->priv_sc;
struct udav_softc *sc = usbd_xfer_softc(xfer);
struct ifnet *ifp = uether_getifp(&sc->sc_ue);
struct usb_page_cache *pc;
struct mbuf *m;
int extra_len;
int temp_len;
@ -577,15 +592,12 @@ udav_bulk_write_callback(struct usb_xfer *xfer)
temp_len += 2;
usbd_copy_in(xfer->frbuffers, 0, buf, 2);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, buf, 2);
usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
usbd_m_copy_in(xfer->frbuffers, 2,
m, 0, m->m_pkthdr.len);
if (extra_len) {
usbd_frame_zero(xfer->frbuffers, temp_len - extra_len,
extra_len);
}
if (extra_len)
usbd_frame_zero(pc, temp_len - extra_len, extra_len);
/*
* if there's a BPF listener, bounce a copy
* of this frame to him:
@ -594,19 +606,19 @@ udav_bulk_write_callback(struct usb_xfer *xfer)
m_freem(m);
xfer->frlengths[0] = temp_len;
usbd_xfer_set_frame_len(xfer, 0, temp_len);
usbd_transfer_submit(xfer);
return;
default: /* Error */
DPRINTFN(11, "transfer error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
ifp->if_oerrors++;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -614,24 +626,29 @@ udav_bulk_write_callback(struct usb_xfer *xfer)
}
static void
udav_bulk_read_callback(struct usb_xfer *xfer)
udav_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct udav_softc *sc = xfer->priv_sc;
struct udav_softc *sc = usbd_xfer_softc(xfer);
struct usb_ether *ue = &sc->sc_ue;
struct ifnet *ifp = uether_getifp(ue);
struct usb_page_cache *pc;
struct udav_rxpkt stat;
int len;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < sizeof(stat) + ETHER_CRC_LEN) {
if (actlen < sizeof(stat) + ETHER_CRC_LEN) {
ifp->if_ierrors++;
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, &stat, sizeof(stat));
xfer->actlen -= sizeof(stat);
len = min(xfer->actlen, le16toh(stat.pktlen));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &stat, sizeof(stat));
actlen -= sizeof(stat);
len = min(actlen, le16toh(stat.pktlen));
len -= ETHER_CRC_LEN;
if (stat.rxstat & UDAV_RSR_LCS) {
@ -642,22 +659,22 @@ udav_bulk_read_callback(struct usb_xfer *xfer)
ifp->if_ierrors++;
goto tr_setup;
}
uether_rxbuf(ue, xfer->frbuffers, sizeof(stat), len);
uether_rxbuf(ue, pc, sizeof(stat), len);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
uether_rxflush(ue);
return;
default: /* Error */
DPRINTF("bulk read error, %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -665,20 +682,20 @@ udav_bulk_read_callback(struct usb_xfer *xfer)
}
static void
udav_intr_callback(struct usb_xfer *xfer)
udav_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -24,17 +24,30 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_endian.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/net/usb_ethernet.h>
SYSCTL_NODE(_net, OID_AUTO, ue, CTLFLAG_RD, 0, "USB Ethernet parameters");

View File

@ -26,15 +26,32 @@
* SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_dynamic.h>

View File

@ -56,4 +56,6 @@ enum { /* keep in sync with usb_quirk_str table */
USB_QUIRK_MAX
};
uint8_t usb_test_quirk(const struct usb_attach_arg *uaa, uint16_t quirk);
#endif /* _USB_QUIRK_H_ */

View File

@ -30,22 +30,37 @@
*
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR u3g_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_msctest.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_msctest.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/serial/usb_serial.h>
@ -501,8 +516,8 @@ u3g_attach(device_t dev)
/* set stall by default */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]);
usbd_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]);
usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]);
usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]);
mtx_unlock(&sc->sc_mtx);
nports++; /* found one port */
@ -588,26 +603,27 @@ u3g_stop_write(struct ucom_softc *ucom)
}
static void
u3g_write_callback(struct usb_xfer *xfer)
u3g_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ucom_softc *ucom = xfer->priv_sc;
struct ucom_softc *ucom = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
if (ucom_get_data(ucom, xfer->frbuffers, 0,
U3G_BSIZE, &actlen)) {
xfer->frlengths[0] = actlen;
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(ucom, pc, 0, U3G_BSIZE, &actlen)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* do a builtin clear-stall */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -616,24 +632,29 @@ u3g_write_callback(struct usb_xfer *xfer)
}
static void
u3g_read_callback(struct usb_xfer *xfer)
u3g_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ucom_softc *ucom = xfer->priv_sc;
struct ucom_softc *ucom = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* do a builtin clear-stall */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;

View File

@ -23,20 +23,36 @@
* be called from within the config thread function !
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/serial/usb_serial.h>
@ -198,8 +214,8 @@ uark_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UARK_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UARK_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -228,26 +244,28 @@ uark_detach(device_t dev)
}
static void
uark_bulk_write_callback(struct usb_xfer *xfer)
uark_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uark_softc *sc = xfer->priv_sc;
struct uark_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UARK_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -256,25 +274,29 @@ uark_bulk_write_callback(struct usb_xfer *xfer)
}
static void
uark_bulk_read_callback(struct usb_xfer *xfer)
uark_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uark_softc *sc = xfer->priv_sc;
struct uark_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0,
xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -62,21 +62,34 @@ __FBSDID("$FreeBSD$");
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR ubsa_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -305,8 +318,8 @@ ubsa_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -537,27 +550,29 @@ ubsa_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr)
}
static void
ubsa_write_callback(struct usb_xfer *xfer)
ubsa_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ubsa_softc *sc = xfer->priv_sc;
struct ubsa_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UBSA_BSIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -566,24 +581,29 @@ ubsa_write_callback(struct usb_xfer *xfer)
}
static void
ubsa_read_callback(struct usb_xfer *xfer)
ubsa_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ubsa_softc *sc = xfer->priv_sc;
struct ubsa_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -592,17 +612,21 @@ ubsa_read_callback(struct usb_xfer *xfer)
}
static void
ubsa_intr_callback(struct usb_xfer *xfer)
ubsa_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ubsa_softc *sc = xfer->priv_sc;
struct ubsa_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[4];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen >= sizeof(buf)) {
usbd_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
if (actlen >= sizeof(buf)) {
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, sizeof(buf));
/*
* incidentally, Belkin adapter status bits match
@ -616,20 +640,19 @@ ubsa_intr_callback(struct usb_xfer *xfer)
ucom_status_change(&sc->sc_ucom);
} else {
DPRINTF("ignoring short packet, %d bytes\n",
xfer->actlen);
DPRINTF("ignoring short packet, %d bytes\n", actlen);
}
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -76,20 +76,34 @@ __FBSDID("$FreeBSD$");
* BWCT serial adapter driver
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR ubser_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/serial/usb_serial.h>
@ -263,7 +277,7 @@ ubser_attach(device_t dev)
if (error) {
goto detach;
}
sc->sc_tx_size = sc->sc_xfer[UBSER_BULK_DT_WR]->max_data_length;
sc->sc_tx_size = usbd_xfer_max_len(sc->sc_xfer[UBSER_BULK_DT_WR]);
if (sc->sc_tx_size == 0) {
DPRINTFN(0, "invalid tx_size!\n");
@ -282,8 +296,8 @@ ubser_attach(device_t dev)
}
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UBSER_BULK_DT_RD]);
usbd_transfer_start(sc->sc_xfer[UBSER_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
@ -367,9 +381,10 @@ ubser_inc_tx_unit(struct ubser_softc *sc)
}
static void
ubser_write_callback(struct usb_xfer *xfer)
ubser_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ubser_softc *sc = xfer->priv_sc;
struct ubser_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[1];
uint8_t first_unit = sc->sc_curr_tx_unit;
uint32_t actlen;
@ -378,16 +393,17 @@ ubser_write_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
pc = usbd_xfer_get_frame(xfer, 0);
do {
if (ucom_get_data(sc->sc_ucom + sc->sc_curr_tx_unit,
xfer->frbuffers, 1, sc->sc_tx_size - 1,
pc, 1, sc->sc_tx_size - 1,
&actlen)) {
buf[0] = sc->sc_curr_tx_unit;
usbd_copy_in(xfer->frbuffers, 0, buf, 1);
usbd_copy_in(pc, 0, buf, 1);
xfer->frlengths[0] = actlen + 1;
usbd_xfer_set_frame_len(xfer, 0, actlen + 1);
usbd_transfer_submit(xfer);
ubser_inc_tx_unit(sc); /* round robin */
@ -401,9 +417,9 @@ ubser_write_callback(struct usb_xfer *xfer)
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -412,36 +428,40 @@ ubser_write_callback(struct usb_xfer *xfer)
}
static void
ubser_read_callback(struct usb_xfer *xfer)
ubser_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ubser_softc *sc = xfer->priv_sc;
struct ubser_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[1];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 1) {
if (actlen < 1) {
DPRINTF("invalid actlen=0!\n");
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 1);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, 1);
if (buf[0] >= sc->sc_numser) {
DPRINTF("invalid serial number!\n");
goto tr_setup;
}
ucom_put_data(sc->sc_ucom + buf[0],
xfer->frbuffers, 1, xfer->actlen - 1);
ucom_put_data(sc->sc_ucom + buf[0], pc, 1, actlen - 1);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -69,22 +69,34 @@ __FBSDID("$FreeBSD$");
* driver for WinChipHead CH341/340, the worst USB-serial chip in the world.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uchcom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -341,8 +353,8 @@ uchcom_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UCHCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -772,19 +784,23 @@ uchcom_stop_write(struct ucom_softc *ucom)
* callback when the modem status is changed.
*/
static void
uchcom_intr_callback(struct usb_xfer *xfer)
uchcom_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uchcom_softc *sc = xfer->priv_sc;
struct uchcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[UCHCOM_INTR_LEAST];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("actlen = %u\n", xfer->actlen);
DPRINTF("actlen = %u\n", actlen);
if (xfer->actlen >= UCHCOM_INTR_LEAST) {
usbd_copy_out(xfer->frbuffers, 0, buf,
UCHCOM_INTR_LEAST);
if (actlen >= UCHCOM_INTR_LEAST) {
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, UCHCOM_INTR_LEAST);
DPRINTF("data = 0x%02X 0x%02X 0x%02X 0x%02X\n",
(unsigned)buf[0], (unsigned)buf[1],
@ -795,14 +811,14 @@ uchcom_intr_callback(struct usb_xfer *xfer)
}
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -810,29 +826,31 @@ uchcom_intr_callback(struct usb_xfer *xfer)
}
static void
uchcom_write_callback(struct usb_xfer *xfer)
uchcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uchcom_softc *sc = xfer->priv_sc;
struct uchcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UCHCOM_BULK_BUF_SIZE, &actlen)) {
DPRINTF("actlen = %d\n", actlen);
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -841,24 +859,29 @@ uchcom_write_callback(struct usb_xfer *xfer)
}
static void
uchcom_read_callback(struct usb_xfer *xfer)
uchcom_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uchcom_softc *sc = xfer->priv_sc;
struct uchcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -34,24 +34,35 @@ __FBSDID("$FreeBSD$");
* RS232 bridges.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_hid.h>
#include <dev/usb/serial/usb_serial.h>
@ -329,14 +340,18 @@ ucycom_stop_write(struct ucom_softc *ucom)
}
static void
ucycom_ctrl_write_callback(struct usb_xfer *xfer)
ucycom_ctrl_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ucycom_softc *sc = xfer->priv_sc;
struct ucycom_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc0, *pc1;
uint8_t data[2];
uint8_t offset;
uint32_t actlen;
pc0 = usbd_xfer_get_frame(xfer, 0);
pc1 = usbd_xfer_get_frame(xfer, 1);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
tr_transferred:
@ -354,7 +369,7 @@ ucycom_ctrl_write_callback(struct usb_xfer *xfer)
break;
}
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers + 1, offset,
if (ucom_get_data(&sc->sc_ucom, pc1, offset,
sc->sc_olen - offset, &actlen)) {
req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
@ -376,22 +391,22 @@ ucycom_ctrl_write_callback(struct usb_xfer *xfer)
break;
}
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(xfer->frbuffers + 1, 0, data, offset);
usbd_copy_in(pc0, 0, &req, sizeof(req));
usbd_copy_in(pc1, 0, data, offset);
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = sc->sc_olen;
xfer->nframes = xfer->frlengths[1] ? 2 : 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, sc->sc_olen);
usbd_xfer_set_frames(xfer, sc->sc_olen ? 2 : 1);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
return;
}
DPRINTF("error=%s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
goto tr_transferred;
}
}
@ -494,42 +509,45 @@ ucycom_cfg_param(struct ucom_softc *ucom, struct termios *t)
}
static void
ucycom_intr_read_callback(struct usb_xfer *xfer)
ucycom_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ucycom_softc *sc = xfer->priv_sc;
struct ucycom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[2];
uint32_t offset;
uint32_t len;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
pc = usbd_xfer_get_frame(xfer, 0);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
switch (sc->sc_model) {
case MODEL_CY7C63743:
if (xfer->actlen < 1) {
if (actlen < 1) {
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 1);
usbd_copy_out(pc, 0, buf, 1);
sc->sc_ist = buf[0] & ~0x07;
len = buf[0] & 0x07;
(xfer->actlen)--;
actlen--;
offset = 1;
break;
case MODEL_CY7C64013:
if (xfer->actlen < 2) {
if (actlen < 2) {
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 2);
usbd_copy_out(pc, 0, buf, 2);
sc->sc_ist = buf[0] & ~0x07;
len = buf[1];
(xfer->actlen) -= 2;
actlen -= 2;
offset = 2;
break;
@ -539,23 +557,21 @@ ucycom_intr_read_callback(struct usb_xfer *xfer)
goto tr_setup;
}
if (len > xfer->actlen) {
len = xfer->actlen;
}
if (len) {
ucom_put_data(&sc->sc_ucom, xfer->frbuffers,
offset, len);
}
if (len > actlen)
len = actlen;
if (len)
ucom_put_data(&sc->sc_ucom, pc, offset, len);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = sc->sc_ilen;
usbd_xfer_set_frame_len(xfer, 0, sc->sc_ilen);
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -82,26 +82,38 @@ __FBSDID("$FreeBSD$");
* be called from within the config thread function !
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/sbuf.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
#include <sys/sysctl.h>
#include <sys/sbuf.h>
typedef struct ufoma_mobile_acm_descriptor {
uint8_t bFunctionLength;
@ -426,8 +438,8 @@ ufoma_attach(device_t dev)
/* clear stall at first run, if any */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]);
usbd_transfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_READ]);
usbd_xfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_WRITE]);
usbd_xfer_set_stall(sc->sc_bulk_xfer[UFOMA_BULK_ENDPT_READ]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -544,21 +556,25 @@ ufoma_cfg_activate_state(struct ufoma_softc *sc, uint16_t state)
}
static void
ufoma_ctrl_read_callback(struct usb_xfer *xfer)
ufoma_ctrl_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ufoma_softc *sc = xfer->priv_sc;
struct ufoma_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc0, *pc1;
int len, aframes, nframes;
usbd_xfer_status(xfer, NULL, NULL, &aframes, &nframes);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
tr_transferred:
if (xfer->aframes != xfer->nframes) {
if (aframes != nframes)
goto tr_setup;
}
if (xfer->frlengths[1] > 0) {
ucom_put_data(&sc->sc_ucom, xfer->frbuffers + 1,
0, xfer->frlengths[1]);
}
pc1 = usbd_xfer_get_frame(xfer, 1);
len = usbd_xfer_get_frame_len(xfer, 1);
if (len > 0)
ucom_put_data(&sc->sc_ucom, pc1, 0, len);
/* FALLTHROUGH */
case USB_ST_SETUP:
tr_setup:
if (sc->sc_num_msg) {
@ -570,20 +586,21 @@ ufoma_ctrl_read_callback(struct usb_xfer *xfer)
USETW(req.wValue, 0);
USETW(req.wLength, UFOMA_CMD_BUF_SIZE);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc0 = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc0, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = UFOMA_CMD_BUF_SIZE;
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, UFOMA_CMD_BUF_SIZE);
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
DPRINTF("error = %s\n",
usbd_errstr(xfer->error));
usbd_errstr(error));
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
return;
} else {
goto tr_setup;
@ -594,10 +611,11 @@ ufoma_ctrl_read_callback(struct usb_xfer *xfer)
}
static void
ufoma_ctrl_write_callback(struct usb_xfer *xfer)
ufoma_ctrl_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ufoma_softc *sc = xfer->priv_sc;
struct ufoma_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
@ -605,8 +623,8 @@ ufoma_ctrl_write_callback(struct usb_xfer *xfer)
tr_transferred:
case USB_ST_SETUP:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers + 1,
0, 1, &actlen)) {
pc = usbd_xfer_get_frame(xfer, 1);
if (ucom_get_data(&sc->sc_ucom, pc, 0, 1, &actlen)) {
req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
req.bRequest = UCDC_SEND_ENCAPSULATED_COMMAND;
@ -614,21 +632,21 @@ ufoma_ctrl_write_callback(struct usb_xfer *xfer)
USETW(req.wValue, 0);
USETW(req.wLength, 1);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = 1;
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, 1);
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
DPRINTF("error = %s\n",
usbd_errstr(xfer->error));
DPRINTF("error = %s\n", usbd_errstr(error));
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
return;
} else {
goto tr_setup;
@ -639,31 +657,36 @@ ufoma_ctrl_write_callback(struct usb_xfer *xfer)
}
static void
ufoma_intr_callback(struct usb_xfer *xfer)
ufoma_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ufoma_softc *sc = xfer->priv_sc;
struct ufoma_softc *sc = usbd_xfer_softc(xfer);
struct usb_cdc_notification pkt;
struct usb_page_cache *pc;
uint16_t wLen;
uint16_t temp;
uint8_t mstatus;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 8) {
if (actlen < 8) {
DPRINTF("too short message\n");
goto tr_setup;
}
if (xfer->actlen > sizeof(pkt)) {
if (actlen > sizeof(pkt)) {
DPRINTF("truncating message\n");
xfer->actlen = sizeof(pkt);
actlen = sizeof(pkt);
}
usbd_copy_out(xfer->frbuffers, 0, &pkt, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &pkt, actlen);
xfer->actlen -= 8;
actlen -= 8;
wLen = UGETW(pkt.wLength);
if (xfer->actlen > wLen) {
xfer->actlen = wLen;
if (actlen > wLen) {
actlen = wLen;
}
if ((pkt.bmRequestType == UT_READ_VENDOR_INTERFACE) &&
(pkt.bNotification == UMCPC_REQUEST_ACKNOWLEDGE)) {
@ -698,9 +721,9 @@ ufoma_intr_callback(struct usb_xfer *xfer)
* Set the serial state in ucom driver based on
* the bits from the notify message
*/
if (xfer->actlen < 2) {
if (actlen < 2) {
DPRINTF("invalid notification "
"length, %d bytes!\n", xfer->actlen);
"length, %d bytes!\n", actlen);
break;
}
DPRINTF("notify bytes = 0x%02x, 0x%02x\n",
@ -730,14 +753,14 @@ ufoma_intr_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -745,26 +768,28 @@ ufoma_intr_callback(struct usb_xfer *xfer)
}
static void
ufoma_bulk_write_callback(struct usb_xfer *xfer)
ufoma_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ufoma_softc *sc = xfer->priv_sc;
struct ufoma_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UFOMA_BULK_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -772,25 +797,29 @@ ufoma_bulk_write_callback(struct usb_xfer *xfer)
}
static void
ufoma_bulk_read_callback(struct usb_xfer *xfer)
ufoma_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ufoma_softc *sc = xfer->priv_sc;
struct ufoma_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0,
xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -48,21 +48,34 @@ __FBSDID("$FreeBSD$");
* FTDI FT8U100AX serial adapter driver
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uftdi_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
#include <dev/usb/serial/uftdi_reg.h>
@ -296,8 +309,8 @@ uftdi_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UFTDI_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
/* set a valid "lcr" value */
@ -368,9 +381,10 @@ uftdi_cfg_open(struct ucom_softc *ucom)
}
static void
uftdi_write_callback(struct usb_xfer *xfer)
uftdi_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uftdi_softc *sc = xfer->priv_sc;
struct uftdi_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
uint8_t buf[1];
@ -378,24 +392,25 @@ uftdi_write_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc,
sc->sc_hdrlen, UFTDI_OBUFSIZE - sc->sc_hdrlen,
&actlen)) {
if (sc->sc_hdrlen > 0) {
buf[0] =
FTDI_OUT_TAG(actlen, sc->sc_ucom.sc_portno);
usbd_copy_in(xfer->frbuffers, 0, buf, 1);
usbd_copy_in(pc, 0, buf, 1);
}
xfer->frlengths[0] = actlen + sc->sc_hdrlen;
usbd_xfer_set_frame_len(xfer, 0, actlen + sc->sc_hdrlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -403,21 +418,26 @@ uftdi_write_callback(struct usb_xfer *xfer)
}
static void
uftdi_read_callback(struct usb_xfer *xfer)
uftdi_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uftdi_softc *sc = xfer->priv_sc;
struct uftdi_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[2];
uint8_t ftdi_msr;
uint8_t msr;
uint8_t lsr;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 2) {
if (actlen < 2) {
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, 2);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, 2);
ftdi_msr = FTDI_GET_MSR(buf);
lsr = FTDI_GET_LSR(buf);
@ -443,22 +463,21 @@ uftdi_read_callback(struct usb_xfer *xfer)
ucom_status_change(&sc->sc_ucom);
}
xfer->actlen -= 2;
actlen -= 2;
if (xfer->actlen > 0) {
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 2,
xfer->actlen);
if (actlen > 0) {
ucom_put_data(&sc->sc_ucom, pc, 2, actlen);
}
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -42,21 +42,33 @@
* be called from within the config thread function !
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/serial/usb_serial.h>
@ -221,8 +233,8 @@ ugensa_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
usbd_transfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
usbd_xfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_WR]);
usbd_xfer_set_stall(ssc->sc_xfer[UGENSA_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
/* initialize port number */
@ -264,26 +276,28 @@ ugensa_detach(device_t dev)
}
static void
ugensa_bulk_write_callback(struct usb_xfer *xfer)
ugensa_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ugensa_sub_softc *ssc = xfer->priv_sc;
struct ugensa_sub_softc *ssc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(ssc->sc_ucom_ptr, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(ssc->sc_ucom_ptr, pc, 0,
UGENSA_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -291,25 +305,29 @@ ugensa_bulk_write_callback(struct usb_xfer *xfer)
}
static void
ugensa_bulk_read_callback(struct usb_xfer *xfer)
ugensa_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ugensa_sub_softc *ssc = xfer->priv_sc;
struct ugensa_sub_softc *ssc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(ssc->sc_ucom_ptr, xfer->frbuffers, 0,
xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(ssc->sc_ucom_ptr, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -51,21 +51,35 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -1136,8 +1150,8 @@ uipaq_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UIPAQ_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -1267,26 +1281,28 @@ uipaq_cfg_set_break(struct ucom_softc *ucom, uint8_t onoff)
}
static void
uipaq_write_callback(struct usb_xfer *xfer)
uipaq_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uipaq_softc *sc = xfer->priv_sc;
struct uipaq_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UIPAQ_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -1294,25 +1310,29 @@ uipaq_write_callback(struct usb_xfer *xfer)
}
static void
uipaq_read_callback(struct usb_xfer *xfer)
uipaq_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uipaq_softc *sc = xfer->priv_sc;
struct uipaq_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0,
xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -45,25 +45,39 @@ __FBSDID("$FreeBSD$");
* Printer Class spec: http://www.usb.org/developers/devclass_docs/usbprint11.pdf
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/syslog.h>
#include <sys/selinfo.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR ulpt_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_parse.h>
#include <sys/syslog.h>
#if USB_DEBUG
static int ulpt_debug = 0;
@ -189,35 +203,38 @@ ulpt_reset(struct ulpt_softc *sc)
}
static void
ulpt_write_callback(struct usb_xfer *xfer)
ulpt_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ulpt_softc *sc = xfer->priv_sc;
struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo_open[USB_FIFO_TX];
uint32_t actlen;
struct usb_page_cache *pc;
int actlen, max;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
if (f == NULL) {
/* should not happen */
DPRINTF("no FIFO\n");
return;
}
DPRINTF("state=0x%x actlen=%u\n",
USB_GET_STATE(xfer), xfer->actlen);
DPRINTF("state=0x%x actlen=%d\n", USB_GET_STATE(xfer), actlen);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
case USB_ST_SETUP:
tr_setup:
if (usb_fifo_get_data(f, xfer->frbuffers,
0, xfer->max_data_length, &actlen, 0)) {
xfer->frlengths[0] = actlen;
pc = usbd_xfer_get_frame(xfer, 0);
max = usbd_xfer_max_len(xfer);
if (usb_fifo_get_data(f, pc, 0, max, &actlen, 0)) {
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -225,10 +242,14 @@ ulpt_write_callback(struct usb_xfer *xfer)
}
static void
ulpt_read_callback(struct usb_xfer *xfer)
ulpt_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ulpt_softc *sc = xfer->priv_sc;
struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo_open[USB_FIFO_RX];
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
if (f == NULL) {
/* should not happen */
@ -240,40 +261,40 @@ ulpt_read_callback(struct usb_xfer *xfer)
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen == 0) {
if (actlen == 0) {
if (sc->sc_zlps == 4) {
/* enable BULK throttle */
xfer->interval = 500; /* ms */
usbd_xfer_set_interval(xfer, 500); /* ms */
} else {
sc->sc_zlps++;
}
} else {
/* disable BULK throttle */
xfer->interval = 0;
usbd_xfer_set_interval(xfer, 0);
sc->sc_zlps = 0;
}
usb_fifo_put_data(f, xfer->frbuffers,
0, xfer->actlen, 1);
pc = usbd_xfer_get_frame(xfer, 0);
usb_fifo_put_data(f, pc, 0, actlen, 1);
case USB_ST_SETUP:
tr_setup:
if (usb_fifo_put_bytes_max(f) != 0) {
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
break;
default: /* Error */
/* disable BULK throttle */
xfer->interval = 0;
usbd_xfer_set_interval(xfer, 0);
sc->sc_zlps = 0;
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
break;
@ -281,17 +302,19 @@ ulpt_read_callback(struct usb_xfer *xfer)
}
static void
ulpt_status_callback(struct usb_xfer *xfer)
ulpt_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ulpt_softc *sc = xfer->priv_sc;
struct ulpt_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
uint8_t cur_status;
uint8_t new_status;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
usbd_copy_out(xfer->frbuffers + 1, 0, &cur_status, 1);
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_out(pc, 0, &cur_status, 1);
cur_status = (cur_status ^ LPS_INVERT) & LPS_MASK;
new_status = cur_status & ~sc->sc_last_status;
@ -316,17 +339,18 @@ ulpt_status_callback(struct usb_xfer *xfer)
req.wIndex[1] = 0;
USETW(req.wLength, 1);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = 1;
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, 1);
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
break;
default: /* Error */
DPRINTF("error=%s\n", usbd_errstr(xfer->error));
if (xfer->error != USB_ERR_CANCELLED) {
DPRINTF("error=%s\n", usbd_errstr(error));
if (error != USB_ERR_CANCELLED) {
/* wait for next watchdog timeout */
}
break;
@ -365,7 +389,7 @@ static const struct usb_config ulpt_config[ULPT_N_TRANSFER] = {
static void
ulpt_start_read(struct usb_fifo *fifo)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[ULPT_BULK_DT_RD]);
}
@ -373,7 +397,7 @@ ulpt_start_read(struct usb_fifo *fifo)
static void
ulpt_stop_read(struct usb_fifo *fifo)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[ULPT_BULK_DT_RD]);
}
@ -381,7 +405,7 @@ ulpt_stop_read(struct usb_fifo *fifo)
static void
ulpt_start_write(struct usb_fifo *fifo)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[ULPT_BULK_DT_WR]);
}
@ -389,7 +413,7 @@ ulpt_start_write(struct usb_fifo *fifo)
static void
ulpt_stop_write(struct usb_fifo *fifo)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[ULPT_BULK_DT_WR]);
}
@ -397,7 +421,7 @@ ulpt_stop_write(struct usb_fifo *fifo)
static int
ulpt_open(struct usb_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
/* we assume that open is a serial process */
@ -410,7 +434,7 @@ ulpt_open(struct usb_fifo *fifo, int fflags)
static int
unlpt_open(struct usb_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
if (sc->sc_fflags & fflags) {
return (EBUSY);
@ -418,10 +442,10 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
if (fflags & FREAD) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
sc->sc_xfer[ULPT_BULK_DT_RD]->max_data_length,
usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_RD]),
ULPT_IFQ_MAXLEN)) {
return (ENOMEM);
}
@ -431,10 +455,10 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
if (fflags & FWRITE) {
/* clear stall first */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[ULPT_BULK_DT_WR]);
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
sc->sc_xfer[ULPT_BULK_DT_WR]->max_data_length,
usbd_xfer_max_len(sc->sc_xfer[ULPT_BULK_DT_WR]),
ULPT_IFQ_MAXLEN)) {
return (ENOMEM);
}
@ -448,7 +472,7 @@ unlpt_open(struct usb_fifo *fifo, int fflags)
static void
ulpt_close(struct usb_fifo *fifo, int fflags)
{
struct ulpt_softc *sc = fifo->priv_sc0;
struct ulpt_softc *sc = usb_fifo_softc(fifo);
sc->sc_fflags &= ~(fflags & (FREAD | FWRITE));

View File

@ -44,22 +44,34 @@ __FBSDID("$FreeBSD$");
* be called from within the config thread function !
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/serial/usb_serial.h>
@ -226,7 +238,7 @@ umct_attach(device_t dev)
struct usb_attach_arg *uaa = device_get_ivars(dev);
struct umct_softc *sc = device_get_softc(dev);
int32_t error;
uint16_t maxp;
//uint16_t maxp;
uint8_t iface_index;
sc->sc_udev = uaa->device;
@ -254,6 +266,7 @@ umct_attach(device_t dev)
* The only way to differentiate it from the real interrupt
* endpoint is to look at the wMaxPacketSize field.
*/
#ifdef XXX
maxp = UGETW(sc->sc_xfer[UMCT_BULK_DT_RD]->endpoint->edesc->wMaxPacketSize);
if (maxp == 0x2) {
@ -267,7 +280,8 @@ umct_attach(device_t dev)
sc->sc_xfer[UMCT_BULK_DT_RD]->callback = &umct_read_callback;
sc->sc_xfer[UMCT_INTR_DT_RD]->callback = &umct_intr_callback;
}
sc->sc_obufsize = sc->sc_xfer[UMCT_BULK_DT_WR]->max_data_length;
#endif
sc->sc_obufsize = usbd_xfer_max_len(sc->sc_xfer[UMCT_BULK_DT_WR]);
if (uaa->info.idProduct == USB_PRODUCT_MCT_SITECOM_USB232) {
if (sc->sc_obufsize > 16) {
@ -326,18 +340,23 @@ umct_cfg_do_request(struct umct_softc *sc, uint8_t request,
}
static void
umct_intr_callback(struct usb_xfer *xfer)
umct_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umct_softc *sc = xfer->priv_sc;
struct umct_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[2];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 2) {
if (actlen < 2) {
DPRINTF("too short message\n");
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, sizeof(buf));
sc->sc_msr = buf[0];
sc->sc_lsr = buf[1];
@ -346,14 +365,14 @@ umct_intr_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -526,27 +545,29 @@ umct_stop_write(struct ucom_softc *ucom)
}
static void
umct_write_callback(struct usb_xfer *xfer)
umct_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umct_softc *sc = xfer->priv_sc;
struct umct_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
sc->sc_obufsize, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -554,25 +575,29 @@ umct_write_callback(struct usb_xfer *xfer)
}
static void
umct_read_callback(struct usb_xfer *xfer)
umct_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umct_softc *sc = xfer->priv_sc;
struct umct_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers,
0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -80,23 +80,38 @@ __FBSDID("$FreeBSD$");
*
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#include <dev/usb/usb_ioctl.h>
#define USB_DEBUG_VAR umodem_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/serial/usb_serial.h>
@ -353,8 +368,8 @@ umodem_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UMODEM_BULK_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UMODEM_BULK_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UMODEM_BULK_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -600,31 +615,36 @@ umodem_cfg_set_break(struct ucom_softc *ucom, uint8_t onoff)
}
static void
umodem_intr_callback(struct usb_xfer *xfer)
umodem_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_cdc_notification pkt;
struct umodem_softc *sc = xfer->priv_sc;
struct umodem_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint16_t wLen;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 8) {
if (actlen < 8) {
DPRINTF("received short packet, "
"%d bytes\n", xfer->actlen);
"%d bytes\n", actlen);
goto tr_setup;
}
if (xfer->actlen > sizeof(pkt)) {
if (actlen > sizeof(pkt)) {
DPRINTF("truncating message\n");
xfer->actlen = sizeof(pkt);
actlen = sizeof(pkt);
}
usbd_copy_out(xfer->frbuffers, 0, &pkt, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &pkt, actlen);
xfer->actlen -= 8;
actlen -= 8;
wLen = UGETW(pkt.wLength);
if (xfer->actlen > wLen) {
xfer->actlen = wLen;
if (actlen > wLen) {
actlen = wLen;
}
if (pkt.bmRequestType != UCDC_NOTIFICATION) {
DPRINTF("unknown message type, "
@ -638,9 +658,9 @@ umodem_intr_callback(struct usb_xfer *xfer)
* Set the serial state in ucom driver based on
* the bits from the notify message
*/
if (xfer->actlen < 2) {
if (actlen < 2) {
DPRINTF("invalid notification "
"length, %d bytes!\n", xfer->actlen);
"length, %d bytes!\n", actlen);
break;
}
DPRINTF("notify bytes = %02x%02x\n",
@ -671,14 +691,14 @@ umodem_intr_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -687,27 +707,29 @@ umodem_intr_callback(struct usb_xfer *xfer)
}
static void
umodem_write_callback(struct usb_xfer *xfer)
umodem_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umodem_softc *sc = xfer->priv_sc;
struct umodem_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UMODEM_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -715,28 +737,32 @@ umodem_write_callback(struct usb_xfer *xfer)
}
static void
umodem_read_callback(struct usb_xfer *xfer)
umodem_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umodem_softc *sc = xfer->priv_sc;
struct umodem_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("actlen=%d\n", xfer->actlen);
DPRINTF("actlen=%d\n", actlen);
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0,
xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -17,21 +17,34 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR umoscom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -313,8 +326,8 @@ umoscom_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UMOSCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -583,9 +596,10 @@ umoscom_stop_write(struct ucom_softc *ucom)
}
static void
umoscom_write_callback(struct usb_xfer *xfer)
umoscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umoscom_softc *sc = xfer->priv_sc;
struct umoscom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
@ -594,19 +608,20 @@ umoscom_write_callback(struct usb_xfer *xfer)
tr_setup:
DPRINTF("\n");
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UMOSCOM_BUFSIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
DPRINTFN(0, "transfer failed\n");
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -614,28 +629,33 @@ umoscom_write_callback(struct usb_xfer *xfer)
}
static void
umoscom_read_callback(struct usb_xfer *xfer)
umoscom_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umoscom_softc *sc = xfer->priv_sc;
struct umoscom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("got %d bytes\n", xfer->actlen);
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
DPRINTF("got %d bytes\n", actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
DPRINTF("\n");
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
DPRINTFN(0, "transfer failed\n");
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -643,13 +663,16 @@ umoscom_read_callback(struct usb_xfer *xfer)
}
static void
umoscom_intr_callback(struct usb_xfer *xfer)
umoscom_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umoscom_softc *sc = xfer->priv_sc;
struct umoscom_softc *sc = usbd_xfer_softc(xfer);
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < 2) {
if (actlen < 2) {
DPRINTF("too short message\n");
goto tr_setup;
}
@ -657,15 +680,15 @@ umoscom_intr_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
DPRINTFN(0, "transfer failed\n");
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -84,21 +84,35 @@ __FBSDID("$FreeBSD$");
* documented in the datasheet.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_cdc.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uplcom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -389,8 +403,8 @@ uplcom_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UPLCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -736,19 +750,24 @@ uplcom_cfg_get_status(struct ucom_softc *ucom, uint8_t *lsr, uint8_t *msr)
}
static void
uplcom_intr_callback(struct usb_xfer *xfer)
uplcom_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uplcom_softc *sc = xfer->priv_sc;
struct uplcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[9];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
DPRINTF("actlen = %u\n", xfer->actlen);
DPRINTF("actlen = %u\n", actlen);
if (xfer->actlen >= 9) {
if (actlen >= 9) {
usbd_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, sizeof(buf));
DPRINTF("status = 0x%02x\n", buf[8]);
@ -768,14 +787,14 @@ uplcom_intr_callback(struct usb_xfer *xfer)
}
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -783,29 +802,31 @@ uplcom_intr_callback(struct usb_xfer *xfer)
}
static void
uplcom_write_callback(struct usb_xfer *xfer)
uplcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uplcom_softc *sc = xfer->priv_sc;
struct uplcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UPLCOM_BULK_BUF_SIZE, &actlen)) {
DPRINTF("actlen = %d\n", actlen);
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -813,24 +834,29 @@ uplcom_write_callback(struct usb_xfer *xfer)
}
static void
uplcom_read_callback(struct usb_xfer *xfer)
uplcom_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uplcom_softc *sc = xfer->priv_sc;
struct uplcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -67,20 +67,34 @@ __FBSDID("$FreeBSD$");
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR ucom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/serial/usb_serial.h>

View File

@ -19,20 +19,34 @@ __FBSDID("$FreeBSD$");
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uslcom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -242,8 +256,8 @@ uslcom_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[USLCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -454,29 +468,31 @@ uslcom_set_break(struct ucom_softc *ucom, uint8_t onoff)
}
static void
uslcom_write_callback(struct usb_xfer *xfer)
uslcom_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uslcom_softc *sc = xfer->priv_sc;
struct uslcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
USLCOM_BULK_BUF_SIZE, &actlen)) {
DPRINTF("actlen = %d\n", actlen);
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -484,24 +500,29 @@ uslcom_write_callback(struct usb_xfer *xfer)
}
static void
uslcom_read_callback(struct usb_xfer *xfer)
uslcom_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uslcom_softc *sc = xfer->priv_sc;
struct uslcom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -54,22 +54,34 @@
* Handspring Visor (Palmpilot compatible PDA) driver
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uvisor_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -324,8 +336,8 @@ uvisor_attach(device_t dev)
}
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UVISOR_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -562,27 +574,29 @@ uvisor_stop_write(struct ucom_softc *ucom)
}
static void
uvisor_write_callback(struct usb_xfer *xfer)
uvisor_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uvisor_softc *sc = xfer->priv_sc;
struct uvisor_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UVISOR_BUFSIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -590,24 +604,29 @@ uvisor_write_callback(struct usb_xfer *xfer)
}
static void
uvisor_read_callback(struct usb_xfer *xfer)
uvisor_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uvisor_softc *sc = xfer->priv_sc;
struct uvisor_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -37,21 +37,34 @@ __FBSDID("$FreeBSD$");
* P-in m@ater and various data communication card adapters.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#define USB_DEBUG_VAR uvscom_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/serial/usb_serial.h>
@ -297,8 +310,8 @@ uvscom_attach(device_t dev)
/* clear stall at first run */
mtx_lock(&sc->sc_mtx);
usbd_transfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_WR]);
usbd_transfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_RD]);
usbd_xfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_WR]);
usbd_xfer_set_stall(sc->sc_xfer[UVSCOM_BULK_DT_RD]);
mtx_unlock(&sc->sc_mtx);
error = ucom_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc,
@ -338,27 +351,29 @@ uvscom_detach(device_t dev)
}
static void
uvscom_write_callback(struct usb_xfer *xfer)
uvscom_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uvscom_softc *sc = xfer->priv_sc;
struct uvscom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
case USB_ST_SETUP:
case USB_ST_TRANSFERRED:
tr_setup:
if (ucom_get_data(&sc->sc_ucom, xfer->frbuffers, 0,
pc = usbd_xfer_get_frame(xfer, 0);
if (ucom_get_data(&sc->sc_ucom, pc, 0,
UVSCOM_BULK_BUF_SIZE, &actlen)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -366,24 +381,29 @@ uvscom_write_callback(struct usb_xfer *xfer)
}
static void
uvscom_read_callback(struct usb_xfer *xfer)
uvscom_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uvscom_softc *sc = xfer->priv_sc;
struct uvscom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
ucom_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
ucom_put_data(&sc->sc_ucom, pc, 0, actlen);
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;
@ -391,16 +411,21 @@ uvscom_read_callback(struct usb_xfer *xfer)
}
static void
uvscom_intr_callback(struct usb_xfer *xfer)
uvscom_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uvscom_softc *sc = xfer->priv_sc;
struct uvscom_softc *sc = usbd_xfer_softc(xfer);
struct usb_page_cache *pc;
uint8_t buf[2];
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen >= 2) {
if (actlen >= 2) {
usbd_copy_out(xfer->frbuffers, 0, buf, sizeof(buf));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, buf, sizeof(buf));
sc->sc_lsr = 0;
sc->sc_msr = 0;
@ -429,14 +454,14 @@ uvscom_intr_callback(struct usb_xfer *xfer)
}
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
goto tr_setup;
}
return;

View File

@ -102,18 +102,29 @@ __FBSDID("$FreeBSD$");
* umass_cam_cb again to complete the CAM command.
*/
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#include <cam/cam.h>
#include <cam/cam_ccb.h>
@ -124,7 +135,8 @@ __FBSDID("$FreeBSD$");
#include <cam/cam_periph.h>
#if 1
#define UMASS_EXT_BUFFER
#ifdef UMASS_EXT_BUFFER
/* this enables loading of virtual buffers into DMA */
#define UMASS_USB_FLAGS .ext_buffer=1,
#else
@ -1041,13 +1053,13 @@ static void umass_cancel_ccb(struct umass_softc *);
static void umass_init_shuttle(struct umass_softc *);
static void umass_reset(struct umass_softc *);
static void umass_t_bbb_data_clear_stall_callback(struct usb_xfer *,
uint8_t, uint8_t);
uint8_t, uint8_t, usb_error_t);
static void umass_command_start(struct umass_softc *, uint8_t, void *,
uint32_t, uint32_t, umass_callback_t *, union ccb *);
static uint8_t umass_bbb_get_max_lun(struct umass_softc *);
static void umass_cbi_start_status(struct umass_softc *);
static void umass_t_cbi_data_clear_stall_callback(struct usb_xfer *,
uint8_t, uint8_t);
uint8_t, uint8_t, usb_error_t);
static int umass_cam_attach_sim(struct umass_softc *);
static void umass_cam_rescan_callback(struct cam_periph *, union ccb *);
static void umass_cam_rescan(struct umass_softc *);
@ -1712,14 +1724,14 @@ umass_cancel_ccb(struct umass_softc *sc)
}
static void
umass_tr_error(struct usb_xfer *xfer)
umass_tr_error(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
DPRINTF(sc, UDMASS_GEN, "transfer error, %s -> "
"reset\n", usbd_errstr(xfer->error));
"reset\n", usbd_errstr(error));
}
umass_cancel_ccb(sc);
}
@ -1729,10 +1741,11 @@ umass_tr_error(struct usb_xfer *xfer)
*/
static void
umass_t_bbb_reset1_callback(struct usb_xfer *xfer)
umass_t_bbb_reset1_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -1763,40 +1776,40 @@ umass_t_bbb_reset1_callback(struct usb_xfer *xfer)
req.wIndex[1] = 0;
USETW(req.wLength, 0);
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
xfer->frlengths[0] = sizeof(req);
xfer->nframes = 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frames(xfer, 1);
usbd_transfer_submit(xfer);
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_bbb_reset2_callback(struct usb_xfer *xfer)
umass_t_bbb_reset2_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_bbb_data_clear_stall_callback(xfer, UMASS_T_BBB_RESET3,
UMASS_T_BBB_DATA_READ);
UMASS_T_BBB_DATA_READ, error);
}
static void
umass_t_bbb_reset3_callback(struct usb_xfer *xfer)
umass_t_bbb_reset3_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_bbb_data_clear_stall_callback(xfer, UMASS_T_BBB_COMMAND,
UMASS_T_BBB_DATA_WRITE);
UMASS_T_BBB_DATA_WRITE, error);
}
static void
umass_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
uint8_t next_xfer,
uint8_t stall_xfer)
uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -1811,17 +1824,18 @@ umass_t_bbb_data_clear_stall_callback(struct usb_xfer *xfer,
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_bbb_command_callback(struct usb_xfer *xfer)
umass_t_bbb_command_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
union ccb *ccb = sc->sc_transfer.ccb;
struct usb_page_cache *pc;
uint32_t tag;
switch (USB_GET_STATE(xfer)) {
@ -1885,37 +1899,44 @@ umass_t_bbb_command_callback(struct usb_xfer *xfer)
DIF(UDMASS_BBB, umass_bbb_dump_cbw(sc, &sc->cbw));
usbd_copy_in(xfer->frbuffers, 0, &sc->cbw, sizeof(sc->cbw));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &sc->cbw, sizeof(sc->cbw));
usbd_xfer_set_frame_len(xfer, 0, sizeof(sc->cbw));
xfer->frlengths[0] = sizeof(sc->cbw);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_bbb_data_read_callback(struct usb_xfer *xfer)
umass_t_bbb_data_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct umass_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
#ifndef UMASS_EXT_BUFFER
struct usb_page_cache *pc;
#endif
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (!xfer->flags.ext_buffer) {
usbd_copy_out(xfer->frbuffers, 0,
sc->sc_transfer.data_ptr, xfer->actlen);
}
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.actlen += xfer->actlen;
#ifndef UMASS_EXT_BUFFER
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, sc->sc_transfer.data_ptr, actlen);
#endif
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.actlen += actlen;
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
/* short transfer */
sc->sc_transfer.data_rem = 0;
}
@ -1930,18 +1951,20 @@ umass_t_bbb_data_read_callback(struct usb_xfer *xfer)
if (max_bulk > sc->sc_transfer.data_rem) {
max_bulk = sc->sc_transfer.data_rem;
}
xfer->timeout = sc->sc_transfer.data_timeout;
xfer->frlengths[0] = max_bulk;
usbd_xfer_set_timeout(xfer, sc->sc_transfer.data_timeout);
if (xfer->flags.ext_buffer) {
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
}
#ifdef UMASS_EXT_BUFFER
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
#else
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
#endif
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
umass_tr_error(xfer);
if (error == USB_ERR_CANCELLED) {
umass_tr_error(xfer, error);
} else {
umass_transfer_start(sc, UMASS_T_BBB_DATA_RD_CS);
}
@ -1951,25 +1974,31 @@ umass_t_bbb_data_read_callback(struct usb_xfer *xfer)
}
static void
umass_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer)
umass_t_bbb_data_rd_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_bbb_data_clear_stall_callback(xfer, UMASS_T_BBB_STATUS,
UMASS_T_BBB_DATA_READ);
UMASS_T_BBB_DATA_READ, error);
}
static void
umass_t_bbb_data_write_callback(struct usb_xfer *xfer)
umass_t_bbb_data_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct umass_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
#ifndef UMASS_EXT_BUFFER
struct usb_page_cache *pc;
#endif
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.actlen += xfer->actlen;
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.actlen += actlen;
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
/* short transfer */
sc->sc_transfer.data_rem = 0;
}
@ -1984,22 +2013,23 @@ umass_t_bbb_data_write_callback(struct usb_xfer *xfer)
if (max_bulk > sc->sc_transfer.data_rem) {
max_bulk = sc->sc_transfer.data_rem;
}
xfer->timeout = sc->sc_transfer.data_timeout;
xfer->frlengths[0] = max_bulk;
usbd_xfer_set_timeout(xfer, sc->sc_transfer.data_timeout);
if (xfer->flags.ext_buffer) {
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
} else {
usbd_copy_in(xfer->frbuffers, 0,
sc->sc_transfer.data_ptr, max_bulk);
}
#ifdef UMASS_EXT_BUFFER
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
#else
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, sc->sc_transfer.data_ptr, max_bulk);
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
#endif
usbd_transfer_submit(xfer);
return;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
umass_tr_error(xfer);
if (error == USB_ERR_CANCELLED) {
umass_tr_error(xfer, error);
} else {
umass_transfer_start(sc, UMASS_T_BBB_DATA_WR_CS);
}
@ -2009,18 +2039,22 @@ umass_t_bbb_data_write_callback(struct usb_xfer *xfer)
}
static void
umass_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer)
umass_t_bbb_data_wr_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_bbb_data_clear_stall_callback(xfer, UMASS_T_BBB_STATUS,
UMASS_T_BBB_DATA_WRITE);
UMASS_T_BBB_DATA_WRITE, error);
}
static void
umass_t_bbb_status_callback(struct usb_xfer *xfer)
umass_t_bbb_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
union ccb *ccb = sc->sc_transfer.ccb;
struct usb_page_cache *pc;
uint32_t residue;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -2032,10 +2066,11 @@ umass_t_bbb_status_callback(struct usb_xfer *xfer)
/* Zero missing parts of the CSW: */
if (xfer->actlen < sizeof(sc->csw)) {
if (actlen < sizeof(sc->csw)) {
bzero(&sc->csw, sizeof(sc->csw));
}
usbd_copy_out(xfer->frbuffers, 0, &sc->csw, xfer->actlen);
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &sc->csw, actlen);
DIF(UDMASS_BBB, umass_bbb_dump_csw(sc, &sc->csw));
@ -2108,18 +2143,18 @@ umass_t_bbb_status_callback(struct usb_xfer *xfer)
return;
case USB_ST_SETUP:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default:
tr_error:
DPRINTF(sc, UDMASS_BBB, "Failed to read CSW: %s, try %d\n",
usbd_errstr(xfer->error), sc->sc_status_try);
usbd_errstr(error), sc->sc_status_try);
if ((xfer->error == USB_ERR_CANCELLED) ||
if ((error == USB_ERR_CANCELLED) ||
(sc->sc_status_try)) {
umass_tr_error(xfer);
umass_tr_error(xfer, error);
} else {
sc->sc_status_try = 1;
umass_transfer_start(sc, UMASS_T_BBB_DATA_RD_CS);
@ -2210,10 +2245,11 @@ umass_cbi_start_status(struct umass_softc *sc)
}
static void
umass_t_cbi_reset1_callback(struct usb_xfer *xfer)
umass_t_cbi_reset1_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
struct usb_device_request req;
struct usb_page_cache *pc;
uint8_t buf[UMASS_CBI_DIAGNOSTIC_CMDLEN];
uint8_t i;
@ -2259,54 +2295,55 @@ umass_t_cbi_reset1_callback(struct usb_xfer *xfer)
buf[i] = 0xff;
}
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(xfer->frbuffers + 1, 0, buf, sizeof(buf));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_in(pc, 0, buf, sizeof(buf));
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = sizeof(buf);
xfer->nframes = 2;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, sizeof(buf));
usbd_xfer_set_frames(xfer, 2);
usbd_transfer_submit(xfer);
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_cbi_reset2_callback(struct usb_xfer *xfer)
umass_t_cbi_reset2_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_cbi_data_clear_stall_callback(xfer, UMASS_T_CBI_RESET3,
UMASS_T_CBI_DATA_READ);
UMASS_T_CBI_DATA_READ, error);
}
static void
umass_t_cbi_reset3_callback(struct usb_xfer *xfer)
umass_t_cbi_reset3_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
umass_t_cbi_data_clear_stall_callback
(xfer, (sc->sc_xfer[UMASS_T_CBI_RESET4] &&
sc->sc_xfer[UMASS_T_CBI_STATUS]) ?
UMASS_T_CBI_RESET4 : UMASS_T_CBI_COMMAND,
UMASS_T_CBI_DATA_WRITE);
UMASS_T_CBI_DATA_WRITE, error);
}
static void
umass_t_cbi_reset4_callback(struct usb_xfer *xfer)
umass_t_cbi_reset4_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_cbi_data_clear_stall_callback(xfer, UMASS_T_CBI_COMMAND,
UMASS_T_CBI_STATUS);
UMASS_T_CBI_STATUS, error);
}
static void
umass_t_cbi_data_clear_stall_callback(struct usb_xfer *xfer,
uint8_t next_xfer,
uint8_t stall_xfer)
uint8_t next_xfer, uint8_t stall_xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -2325,18 +2362,19 @@ umass_t_cbi_data_clear_stall_callback(struct usb_xfer *xfer,
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_cbi_command_callback(struct usb_xfer *xfer)
umass_t_cbi_command_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
union ccb *ccb = sc->sc_transfer.ccb;
struct usb_device_request req;
struct usb_page_cache *pc;
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -2369,13 +2407,16 @@ umass_t_cbi_command_callback(struct usb_xfer *xfer)
req.wLength[0] = sc->sc_transfer.cmd_len;
req.wLength[1] = 0;
usbd_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
usbd_copy_in(xfer->frbuffers + 1, 0, sc->sc_transfer.cmd_data,
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, &req, sizeof(req));
pc = usbd_xfer_get_frame(xfer, 1);
usbd_copy_in(pc, 0, sc->sc_transfer.cmd_data,
sc->sc_transfer.cmd_len);
xfer->frlengths[0] = sizeof(req);
xfer->frlengths[1] = sc->sc_transfer.cmd_len;
xfer->nframes = xfer->frlengths[1] ? 2 : 1;
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
usbd_xfer_set_frame_len(xfer, 1, sc->sc_transfer.cmd_len);
usbd_xfer_set_frames(xfer,
sc->sc_transfer.cmd_len ? 2 : 1);
DIF(UDMASS_CBI,
umass_cbi_dump_cmd(sc,
@ -2387,29 +2428,35 @@ umass_t_cbi_command_callback(struct usb_xfer *xfer)
return;
default: /* Error */
umass_tr_error(xfer);
umass_tr_error(xfer, error);
return;
}
}
static void
umass_t_cbi_data_read_callback(struct usb_xfer *xfer)
umass_t_cbi_data_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct umass_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
#ifndef UMASS_EXT_BUFFER
struct usb_page_cache *pc;
#endif
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (!xfer->flags.ext_buffer) {
usbd_copy_out(xfer->frbuffers, 0,
sc->sc_transfer.data_ptr, xfer->actlen);
}
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.actlen += xfer->actlen;
#ifndef UMASS_EXT_BUFFER
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, sc->sc_transfer.data_ptr, actlen);
#endif
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.actlen += actlen;
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
/* short transfer */
sc->sc_transfer.data_rem = 0;
}
@ -2424,19 +2471,21 @@ umass_t_cbi_data_read_callback(struct usb_xfer *xfer)
if (max_bulk > sc->sc_transfer.data_rem) {
max_bulk = sc->sc_transfer.data_rem;
}
xfer->timeout = sc->sc_transfer.data_timeout;
usbd_xfer_set_timeout(xfer, sc->sc_transfer.data_timeout);
if (xfer->flags.ext_buffer) {
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
}
xfer->frlengths[0] = max_bulk;
#ifdef UMASS_EXT_BUFFER
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
#else
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
#endif
usbd_transfer_submit(xfer);
return;
default: /* Error */
if ((xfer->error == USB_ERR_CANCELLED) ||
if ((error == USB_ERR_CANCELLED) ||
(sc->sc_transfer.callback != &umass_cam_cb)) {
umass_tr_error(xfer);
umass_tr_error(xfer, error);
} else {
umass_transfer_start(sc, UMASS_T_CBI_DATA_RD_CS);
}
@ -2446,25 +2495,31 @@ umass_t_cbi_data_read_callback(struct usb_xfer *xfer)
}
static void
umass_t_cbi_data_rd_cs_callback(struct usb_xfer *xfer)
umass_t_cbi_data_rd_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_cbi_data_clear_stall_callback(xfer, UMASS_T_CBI_STATUS,
UMASS_T_CBI_DATA_READ);
UMASS_T_CBI_DATA_READ, error);
}
static void
umass_t_cbi_data_write_callback(struct usb_xfer *xfer)
umass_t_cbi_data_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct umass_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
#ifndef UMASS_EXT_BUFFER
struct usb_page_cache *pc;
#endif
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.actlen += xfer->actlen;
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.actlen += actlen;
if (xfer->actlen < xfer->sumlen) {
if (actlen < sumlen) {
/* short transfer */
sc->sc_transfer.data_rem = 0;
}
@ -2479,23 +2534,24 @@ umass_t_cbi_data_write_callback(struct usb_xfer *xfer)
if (max_bulk > sc->sc_transfer.data_rem) {
max_bulk = sc->sc_transfer.data_rem;
}
xfer->timeout = sc->sc_transfer.data_timeout;
usbd_xfer_set_timeout(xfer, sc->sc_transfer.data_timeout);
if (xfer->flags.ext_buffer) {
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
} else {
usbd_copy_in(xfer->frbuffers, 0,
sc->sc_transfer.data_ptr, max_bulk);
}
#ifdef UMASS_EXT_BUFFER
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
#else
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_in(pc, 0, sc->sc_transfer.data_ptr, max_bulk);
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
#endif
xfer->frlengths[0] = max_bulk;
usbd_transfer_submit(xfer);
return;
default: /* Error */
if ((xfer->error == USB_ERR_CANCELLED) ||
if ((error == USB_ERR_CANCELLED) ||
(sc->sc_transfer.callback != &umass_cam_cb)) {
umass_tr_error(xfer);
umass_tr_error(xfer, error);
} else {
umass_transfer_start(sc, UMASS_T_CBI_DATA_WR_CS);
}
@ -2505,27 +2561,32 @@ umass_t_cbi_data_write_callback(struct usb_xfer *xfer)
}
static void
umass_t_cbi_data_wr_cs_callback(struct usb_xfer *xfer)
umass_t_cbi_data_wr_cs_callback(struct usb_xfer *xfer, usb_error_t error)
{
umass_t_cbi_data_clear_stall_callback(xfer, UMASS_T_CBI_STATUS,
UMASS_T_CBI_DATA_WRITE);
UMASS_T_CBI_DATA_WRITE, error);
}
static void
umass_t_cbi_status_callback(struct usb_xfer *xfer)
umass_t_cbi_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct umass_softc *sc = xfer->priv_sc;
struct umass_softc *sc = usbd_xfer_softc(xfer);
union ccb *ccb = sc->sc_transfer.ccb;
struct usb_page_cache *pc;
uint32_t residue;
uint8_t status;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
if (xfer->actlen < sizeof(sc->sbl)) {
if (actlen < sizeof(sc->sbl)) {
goto tr_setup;
}
usbd_copy_out(xfer->frbuffers, 0, &sc->sbl, sizeof(sc->sbl));
pc = usbd_xfer_get_frame(xfer, 0);
usbd_copy_out(pc, 0, &sc->sbl, sizeof(sc->sbl));
residue = (sc->sc_transfer.data_len -
sc->sc_transfer.actlen);
@ -2588,14 +2649,14 @@ umass_t_cbi_status_callback(struct usb_xfer *xfer)
case USB_ST_SETUP:
tr_setup:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
return;
default: /* Error */
DPRINTF(sc, UDMASS_CBI, "Failed to read CSW: %s\n",
usbd_errstr(xfer->error));
umass_tr_error(xfer);
usbd_errstr(error));
umass_tr_error(xfer, error);
return;
}
@ -3085,7 +3146,7 @@ umass_cam_poll(struct cam_sim *sim)
DPRINTF(sc, UDMASS_SCSI, "CAM poll\n");
usbd_do_poll(sc->sc_xfer, UMASS_T_MAX);
usbd_transfer_poll(sc->sc_xfer, UMASS_T_MAX);
}

View File

@ -44,25 +44,39 @@ __FBSDID("$FreeBSD$");
* 2000/2/24 first version.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/storage/rio500_usb.h>
#include <dev/usb/usb_generic.h>
#define USB_DEBUG_VAR urio_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_lookup.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_generic.h>
#include <dev/usb/storage/rio500_usb.h>
#if USB_DEBUG
static int urio_debug = 0;
@ -242,10 +256,11 @@ urio_attach(device_t dev)
}
static void
urio_write_callback(struct usb_xfer *xfer)
urio_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct urio_softc *sc = xfer->priv_sc;
struct urio_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_TX];
struct usb_page_cache *pc;
uint32_t actlen;
switch (USB_GET_STATE(xfer)) {
@ -255,16 +270,17 @@ urio_write_callback(struct usb_xfer *xfer)
usbd_transfer_start(sc->sc_xfer[URIO_T_WR_CS]);
return;
}
if (usb_fifo_get_data(f, xfer->frbuffers, 0,
xfer->max_data_length, &actlen, 0)) {
pc = usbd_xfer_get_frame(xfer, 0);
if (usb_fifo_get_data(f, pc, 0,
usbd_xfer_max_len(xfer), &actlen, 0)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
sc->sc_flags |= URIO_FLAG_WRITE_STALL;
usbd_transfer_start(sc->sc_xfer[URIO_T_WR_CS]);
@ -274,9 +290,9 @@ urio_write_callback(struct usb_xfer *xfer)
}
static void
urio_write_clear_stall_callback(struct usb_xfer *xfer)
urio_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct urio_softc *sc = xfer->priv_sc;
struct urio_softc *sc = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_WR];
if (usbd_clear_stall_callback(xfer, xfer_other)) {
@ -287,15 +303,19 @@ urio_write_clear_stall_callback(struct usb_xfer *xfer)
}
static void
urio_read_callback(struct usb_xfer *xfer)
urio_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct urio_softc *sc = xfer->priv_sc;
struct urio_softc *sc = usbd_xfer_softc(xfer);
struct usb_fifo *f = sc->sc_fifo.fp[USB_FIFO_RX];
struct usb_page_cache *pc;
int actlen;
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
usb_fifo_put_data(f, xfer->frbuffers, 0,
xfer->actlen, 1);
pc = usbd_xfer_get_frame(xfer, 0);
usb_fifo_put_data(f, pc, 0, actlen, 1);
case USB_ST_SETUP:
if (sc->sc_flags & URIO_FLAG_READ_STALL) {
@ -303,13 +323,13 @@ urio_read_callback(struct usb_xfer *xfer)
return;
}
if (usb_fifo_put_bytes_max(f) != 0) {
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
return;
default: /* Error */
if (xfer->error != USB_ERR_CANCELLED) {
if (error != USB_ERR_CANCELLED) {
/* try to clear stall first */
sc->sc_flags |= URIO_FLAG_READ_STALL;
usbd_transfer_start(sc->sc_xfer[URIO_T_RD_CS]);
@ -319,9 +339,9 @@ urio_read_callback(struct usb_xfer *xfer)
}
static void
urio_read_clear_stall_callback(struct usb_xfer *xfer)
urio_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct urio_softc *sc = xfer->priv_sc;
struct urio_softc *sc = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = sc->sc_xfer[URIO_T_RD];
if (usbd_clear_stall_callback(xfer, xfer_other)) {
@ -334,7 +354,7 @@ urio_read_clear_stall_callback(struct usb_xfer *xfer)
static void
urio_start_read(struct usb_fifo *fifo)
{
struct urio_softc *sc = fifo->priv_sc0;
struct urio_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[URIO_T_RD]);
}
@ -342,7 +362,7 @@ urio_start_read(struct usb_fifo *fifo)
static void
urio_stop_read(struct usb_fifo *fifo)
{
struct urio_softc *sc = fifo->priv_sc0;
struct urio_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[URIO_T_RD_CS]);
usbd_transfer_stop(sc->sc_xfer[URIO_T_RD]);
@ -351,7 +371,7 @@ urio_stop_read(struct usb_fifo *fifo)
static void
urio_start_write(struct usb_fifo *fifo)
{
struct urio_softc *sc = fifo->priv_sc0;
struct urio_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_start(sc->sc_xfer[URIO_T_WR]);
}
@ -359,7 +379,7 @@ urio_start_write(struct usb_fifo *fifo)
static void
urio_stop_write(struct usb_fifo *fifo)
{
struct urio_softc *sc = fifo->priv_sc0;
struct urio_softc *sc = usb_fifo_softc(fifo);
usbd_transfer_stop(sc->sc_xfer[URIO_T_WR_CS]);
usbd_transfer_stop(sc->sc_xfer[URIO_T_WR]);
@ -368,7 +388,7 @@ urio_stop_write(struct usb_fifo *fifo)
static int
urio_open(struct usb_fifo *fifo, int fflags)
{
struct urio_softc *sc = fifo->priv_sc0;
struct urio_softc *sc = usb_fifo_softc(fifo);
if ((fflags & (FWRITE | FREAD)) != (FWRITE | FREAD)) {
return (EACCES);
@ -380,7 +400,7 @@ urio_open(struct usb_fifo *fifo, int fflags)
mtx_unlock(&sc->sc_mtx);
if (usb_fifo_alloc_buffer(fifo,
sc->sc_xfer[URIO_T_RD]->max_data_length,
usbd_xfer_max_len(sc->sc_xfer[URIO_T_RD]),
URIO_IFQ_MAXLEN)) {
return (ENOMEM);
}
@ -390,7 +410,7 @@ urio_open(struct usb_fifo *fifo, int fflags)
sc->sc_flags |= URIO_FLAG_WRITE_STALL;
if (usb_fifo_alloc_buffer(fifo,
sc->sc_xfer[URIO_T_WR]->max_data_length,
usbd_xfer_max_len(sc->sc_xfer[URIO_T_WR]),
URIO_IFQ_MAXLEN)) {
return (ENOMEM);
}

View File

@ -35,19 +35,34 @@
* NOTE: Much of the SCSI statemachine handling code derives from the
* Linux USB gadget stack.
*/
#include "usbdevs.h"
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include "usbdevs.h"
#include "usb_if.h"
#define USB_DEBUG_VAR ustorage_fs_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#if USB_DEBUG
static int ustorage_fs_debug = 0;
@ -491,11 +506,11 @@ ustorage_fs_handle_request(device_t dev,
}
static void
ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer)
ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ustorage_fs_softc *sc = xfer->priv_sc;
struct ustorage_fs_softc *sc = usbd_xfer_softc(xfer);
uint32_t tag;
uint8_t error = 0;
uint8_t err = 0;
DPRINTF("\n");
@ -547,8 +562,8 @@ ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer)
break;
}
error = ustorage_fs_do_cmd(sc);
if (error) {
err = ustorage_fs_do_cmd(sc);
if (err) {
/* got an error */
DPRINTF("command failed\n");
break;
@ -556,7 +571,7 @@ ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer)
if ((sc->sc_transfer.data_rem > 0) &&
(sc->sc_transfer.cbw_dir != sc->sc_transfer.cmd_dir)) {
/* contradicting data transfer direction */
error = 1;
err = 1;
DPRINTF("data direction mismatch\n");
break;
}
@ -578,30 +593,28 @@ ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer)
tr_setup:
if (sc->sc_transfer.data_error) {
sc->sc_transfer.data_error = 0;
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
DPRINTF("stall pipe\n");
} else {
xfer->flags.stall_pipe = 0;
}
xfer->frlengths[0] = sizeof(sc->sc_cbw);
usbd_set_frame_data(xfer, &sc->sc_cbw, 0);
usbd_xfer_set_frame_data(xfer, 0, &sc->sc_cbw,
sizeof(sc->sc_cbw));
usbd_transfer_submit(xfer);
break;
default: /* Error */
DPRINTF("error\n");
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
/* If the pipe is already stalled, don't do another stall */
if (!xfer->endpoint->is_stalled) {
if (!usbd_xfer_is_stalled(xfer))
sc->sc_transfer.data_error = 1;
}
/* try again */
goto tr_setup;
}
if (error) {
if (err) {
if (sc->sc_csw.bCSWStatus == 0) {
/* set some default error code */
sc->sc_csw.bCSWStatus = CSWSTATUS_FAILED;
@ -621,20 +634,22 @@ ustorage_fs_t_bbb_command_callback(struct usb_xfer *xfer)
}
static void
ustorage_fs_t_bbb_data_dump_callback(struct usb_xfer *xfer)
ustorage_fs_t_bbb_data_dump_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ustorage_fs_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct ustorage_fs_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
DPRINTF("\n");
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.offset += xfer->actlen;
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.offset += actlen;
if ((xfer->actlen != xfer->sumlen) ||
(sc->sc_transfer.data_rem == 0)) {
if (actlen != sumlen || sc->sc_transfer.data_rem == 0) {
/* short transfer or end of data */
ustorage_fs_transfer_start(sc,
USTORAGE_FS_T_BBB_STATUS);
@ -649,45 +664,45 @@ ustorage_fs_t_bbb_data_dump_callback(struct usb_xfer *xfer)
}
if (sc->sc_transfer.data_error) {
sc->sc_transfer.data_error = 0;
xfer->flags.stall_pipe = 1;
} else {
xfer->flags.stall_pipe = 0;
usbd_xfer_set_stall(xfer);
}
xfer->frlengths[0] = max_bulk;
usbd_xfer_set_frame_len(xfer, 0, max_bulk);
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
/*
* If the pipe is already stalled, don't do another stall:
*/
if (!xfer->endpoint->is_stalled) {
if (!usbd_xfer_is_stalled(xfer))
sc->sc_transfer.data_error = 1;
}
/* try again */
goto tr_setup;
}
}
static void
ustorage_fs_t_bbb_data_read_callback(struct usb_xfer *xfer)
ustorage_fs_t_bbb_data_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ustorage_fs_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct ustorage_fs_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
DPRINTF("\n");
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.offset += xfer->actlen;
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.offset += actlen;
if ((xfer->actlen != xfer->sumlen) ||
(sc->sc_transfer.data_rem == 0)) {
if (actlen != sumlen || sc->sc_transfer.data_rem == 0) {
/* short transfer or end of data */
ustorage_fs_transfer_start(sc,
USTORAGE_FS_T_BBB_STATUS);
@ -702,45 +717,45 @@ ustorage_fs_t_bbb_data_read_callback(struct usb_xfer *xfer)
}
if (sc->sc_transfer.data_error) {
sc->sc_transfer.data_error = 0;
xfer->flags.stall_pipe = 1;
} else {
xfer->flags.stall_pipe = 0;
usbd_xfer_set_stall(xfer);
}
xfer->frlengths[0] = max_bulk;
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
/* If the pipe is already stalled, don't do another stall */
if (!xfer->endpoint->is_stalled) {
if (!usbd_xfer_is_stalled(xfer))
sc->sc_transfer.data_error = 1;
}
/* try again */
goto tr_setup;
}
}
static void
ustorage_fs_t_bbb_data_write_callback(struct usb_xfer *xfer)
ustorage_fs_t_bbb_data_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ustorage_fs_softc *sc = xfer->priv_sc;
uint32_t max_bulk = xfer->max_data_length;
struct ustorage_fs_softc *sc = usbd_xfer_softc(xfer);
uint32_t max_bulk = usbd_xfer_max_len(xfer);
int actlen, sumlen;
usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
DPRINTF("\n");
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
sc->sc_transfer.data_rem -= xfer->actlen;
sc->sc_transfer.data_ptr += xfer->actlen;
sc->sc_transfer.offset += xfer->actlen;
sc->sc_transfer.data_rem -= actlen;
sc->sc_transfer.data_ptr += actlen;
sc->sc_transfer.offset += actlen;
if ((xfer->actlen != xfer->sumlen) ||
(sc->sc_transfer.data_rem == 0)) {
if (actlen != sumlen || sc->sc_transfer.data_rem == 0) {
/* short transfer or end of data */
ustorage_fs_transfer_start(sc,
USTORAGE_FS_T_BBB_STATUS);
@ -750,47 +765,43 @@ ustorage_fs_t_bbb_data_write_callback(struct usb_xfer *xfer)
tr_setup:
if (max_bulk >= sc->sc_transfer.data_rem) {
max_bulk = sc->sc_transfer.data_rem;
if (sc->sc_transfer.data_short) {
xfer->flags.force_short_xfer = 1;
} else {
xfer->flags.force_short_xfer = 0;
}
} else {
xfer->flags.force_short_xfer = 0;
}
if (sc->sc_transfer.data_short)
usbd_xfer_set_flag(xfer, USB_FORCE_SHORT_XFER);
else
usbd_xfer_clr_flag(xfer, USB_FORCE_SHORT_XFER);
} else
usbd_xfer_clr_flag(xfer, USB_FORCE_SHORT_XFER);
if (sc->sc_transfer.data_error) {
sc->sc_transfer.data_error = 0;
xfer->flags.stall_pipe = 1;
} else {
xfer->flags.stall_pipe = 0;
usbd_xfer_set_stall(xfer);
}
xfer->frlengths[0] = max_bulk;
usbd_set_frame_data(xfer, sc->sc_transfer.data_ptr, 0);
usbd_xfer_set_frame_data(xfer, 0, sc->sc_transfer.data_ptr,
max_bulk);
usbd_transfer_submit(xfer);
break;
default: /* Error */
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
/*
* If the pipe is already stalled, don't do another
* stall
*/
if (!xfer->endpoint->is_stalled) {
if (!usbd_xfer_is_stalled(xfer))
sc->sc_transfer.data_error = 1;
}
/* try again */
goto tr_setup;
}
}
static void
ustorage_fs_t_bbb_status_callback(struct usb_xfer *xfer)
ustorage_fs_t_bbb_status_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct ustorage_fs_softc *sc = xfer->priv_sc;
struct ustorage_fs_softc *sc = usbd_xfer_softc(xfer);
DPRINTF("\n");
@ -806,24 +817,22 @@ ustorage_fs_t_bbb_status_callback(struct usb_xfer *xfer)
if (sc->sc_transfer.data_error) {
sc->sc_transfer.data_error = 0;
xfer->flags.stall_pipe = 1;
} else {
xfer->flags.stall_pipe = 0;
usbd_xfer_set_stall(xfer);
}
xfer->frlengths[0] = sizeof(sc->sc_csw);
usbd_set_frame_data(xfer, &sc->sc_csw, 0);
usbd_xfer_set_frame_data(xfer, 0, &sc->sc_csw,
sizeof(sc->sc_csw));
usbd_transfer_submit(xfer);
break;
default:
if (xfer->error == USB_ERR_CANCELLED) {
if (error == USB_ERR_CANCELLED) {
break;
}
/* If the pipe is already stalled, don't do another stall */
if (!xfer->endpoint->is_stalled) {
if (!usbd_xfer_is_stalled(xfer))
sc->sc_transfer.data_error = 1;
}
/* try again */
goto tr_setup;
}

View File

@ -29,24 +29,43 @@
* USB templates.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include "usbdevs.h"
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_dynamic.h>
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_controller.h>
#include <dev/usb/usb_bus.h>
#include <dev/usb/template/usb_template.h>
MODULE_DEPEND(usb_template, usb, 1, 1, 1);

View File

@ -31,11 +31,29 @@ __FBSDID("$FreeBSD$");
* This file contains the USB templates for a CDC USB ethernet device.
*/
#include <dev/usb/usb.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_cdc.h>
#include <dev/usb/template/usb_template.h>

View File

@ -31,10 +31,28 @@ __FBSDID("$FreeBSD$");
* This file contains the USB templates for an USB Mass Storage Device.
*/
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/template/usb_template.h>

View File

@ -38,11 +38,28 @@ __FBSDID("$FreeBSD$");
* operating system the VID and PID of your device.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/template/usb_template.h>
#define MTP_BREQUEST 0x08

View File

@ -39,7 +39,45 @@
#ifndef _USB_STANDARD_H_
#define _USB_STANDARD_H_
#if defined(_KERNEL)
#include "opt_usb.h"
/* Declare parent SYSCTL USB node. */
#ifdef SYSCTL_DECL
SYSCTL_DECL(_hw_usb);
#endif
#include <sys/malloc.h>
MALLOC_DECLARE(M_USB);
MALLOC_DECLARE(M_USBDEV);
MALLOC_DECLARE(M_USBHC);
#endif /* _KERNEL */
#include <dev/usb/usb_endian.h>
#include <dev/usb/usb_freebsd.h>
#define USB_STACK_VERSION 2000 /* 2.0 */
/* Definition of some hardcoded USB constants. */
#define USB_MAX_IPACKET 8 /* initial USB packet size */
#define USB_EP_MAX (2*16) /* hardcoded */
#define USB_ROOT_HUB_ADDR 1 /* index */
#define USB_MIN_DEVICES 2 /* unused + root HUB */
#define USB_UNCONFIG_INDEX 0xFF /* internal use only */
#define USB_IFACE_INDEX_ANY 0xFF /* internal use only */
#define USB_START_ADDR 0 /* default USB device BUS address
* after USB bus reset */
#define USB_CONTROL_ENDPOINT 0 /* default control endpoint */
#define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */
#define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */
#define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */
#define USB_HS_MICRO_FRAMES_MAX 8 /* units */
#define USB_ISOC_TIME_MAX 128 /* ms */
/*
* Minimum time a device needs to be powered down to go through a
@ -642,4 +680,51 @@ struct usb_port_status {
} __packed;
typedef struct usb_port_status usb_port_status_t;
/*
* The "USB_SPEED" macros defines all the supported USB speeds.
*/
enum usb_dev_speed {
USB_SPEED_VARIABLE,
USB_SPEED_LOW,
USB_SPEED_FULL,
USB_SPEED_HIGH,
USB_SPEED_SUPER,
};
#define USB_SPEED_MAX (USB_SPEED_SUPER+1)
/*
* The "USB_REV" macros defines all the supported USB revisions.
*/
enum usb_revision {
USB_REV_UNKNOWN,
USB_REV_PRE_1_0,
USB_REV_1_0,
USB_REV_1_1,
USB_REV_2_0,
USB_REV_2_5,
USB_REV_3_0
};
#define USB_REV_MAX (USB_REV_3_0+1)
/*
* Supported host contoller modes.
*/
enum usb_hc_mode {
USB_MODE_HOST, /* initiates transfers */
USB_MODE_DEVICE, /* bus transfer target */
USB_MODE_DUAL /* can be host or device */
};
#define USB_MODE_MAX (USB_MODE_DUAL+1)
/*
* The "USB_MODE" macros defines all the supported device states.
*/
enum usb_dev_state {
USB_STATE_DETACHED,
USB_STATE_ATTACHED,
USB_STATE_POWERED,
USB_STATE_ADDRESSED,
USB_STATE_CONFIGURED,
};
#define USB_STATE_MAX (USB_STATE_CONFIGURED+1)
#endif /* _USB_STANDARD_H_ */

View File

@ -24,9 +24,29 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR usb_debug
@ -419,7 +439,7 @@ usb_pc_common_mem_cb(void *arg, bus_dma_segment_t *segs,
pc->page_offset_buf = rem;
pc->page_offset_end += rem;
nseg--;
#if (USB_DEBUG != 0)
#ifdef USB_DEBUG
if (rem != (USB_P2U(pc->buffer) & (USB_PAGE_SIZE - 1))) {
/*
* This check verifies that the physical address is correct:

View File

@ -149,24 +149,10 @@ void usb_bdma_done_event(struct usb_dma_parent_tag *udpt);
void usb_bdma_post_sync(struct usb_xfer *xfer);
void usb_bdma_pre_sync(struct usb_xfer *xfer);
void usb_bdma_work_loop(struct usb_xfer_queue *pq);
void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
usb_frlength_t len);
void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
const void *ptr, usb_frlength_t len);
int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
const void *ptr, usb_frlength_t len);
void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
void *ptr, usb_frlength_t len);
int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
void *ptr, usb_frlength_t len);
void usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
struct usb_dma_tag *udt, bus_dma_tag_t dmat, struct mtx *mtx,
usb_dma_callback_t *func, uint8_t ndmabits, uint8_t nudt);
void usb_dma_tag_unsetup(struct usb_dma_parent_tag *udpt);
void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
struct usb_page_search *res);
void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
void usb_pc_cpu_flush(struct usb_page_cache *pc);
void usb_pc_cpu_invalidate(struct usb_page_cache *pc);
void usb_pc_dmamap_destroy(struct usb_page_cache *pc);

View File

@ -25,10 +25,30 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR usb_debug
@ -39,7 +59,6 @@
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_hub.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_debug.h>
@ -1265,8 +1284,8 @@ usb_linux_complete(struct usb_xfer *xfer)
{
struct urb *urb;
urb = xfer->priv_fifo;
xfer->priv_fifo = NULL;
urb = usbd_xfer_get_priv(xfer);
usbd_xfer_set_priv(xfer, NULL);
if (urb->complete) {
(urb->complete) (urb);
}
@ -1281,13 +1300,13 @@ usb_linux_complete(struct usb_xfer *xfer)
* used.
*------------------------------------------------------------------------*/
static void
usb_linux_isoc_callback(struct usb_xfer *xfer)
usb_linux_isoc_callback(struct usb_xfer *xfer, usb_error_t error)
{
usb_frlength_t max_frame = xfer->max_frame_size;
usb_frlength_t offset;
usb_frcount_t x;
struct urb *urb = xfer->priv_fifo;
struct usb_host_endpoint *uhe = xfer->priv_sc;
struct urb *urb = usbd_xfer_get_priv(xfer);
struct usb_host_endpoint *uhe = usbd_xfer_softc(xfer);
struct usb_iso_packet_descriptor *uipd;
DPRINTF("\n");
@ -1362,11 +1381,15 @@ usb_linux_isoc_callback(struct usb_xfer *xfer)
DPRINTF("Already got a transfer\n");
/* already got a transfer (should not happen) */
urb = xfer->priv_fifo;
urb = usbd_xfer_get_priv(xfer);
}
urb->bsd_isread = (uhe->desc.bEndpointAddress & UE_DIR_IN) ? 1 : 0;
if (xfer->flags.ext_buffer) {
/* set virtual address to load */
usbd_xfer_set_frame_data(xfer, 0, urb->transfer_buffer, 0);
}
if (!(urb->bsd_isread)) {
/* copy out data with regard to the URB */
@ -1375,7 +1398,7 @@ usb_linux_isoc_callback(struct usb_xfer *xfer)
for (x = 0; x < urb->number_of_packets; x++) {
uipd = urb->iso_frame_desc + x;
xfer->frlengths[x] = uipd->length;
usbd_xfer_set_frame_len(xfer, x, uipd->length);
if (!xfer->flags.ext_buffer) {
usbd_copy_in(xfer->frbuffers, offset,
USB_ADD_BYTES(urb->transfer_buffer,
@ -1396,16 +1419,10 @@ usb_linux_isoc_callback(struct usb_xfer *xfer)
for (x = 0; x < urb->number_of_packets; x++) {
uipd = urb->iso_frame_desc + x;
xfer->frlengths[x] = max_frame;
usbd_xfer_set_frame_len(xfer, x, max_frame);
}
}
if (xfer->flags.ext_buffer) {
/* set virtual address to load */
usbd_set_frame_data(xfer,
urb->transfer_buffer, 0);
}
xfer->priv_fifo = urb;
usbd_xfer_set_priv(xfer, urb);
xfer->flags.force_short_xfer = 0;
xfer->timeout = urb->timeout;
xfer->nframes = urb->number_of_packets;
@ -1449,15 +1466,15 @@ usb_linux_isoc_callback(struct usb_xfer *xfer)
* callback is called.
*------------------------------------------------------------------------*/
static void
usb_linux_non_isoc_callback(struct usb_xfer *xfer)
usb_linux_non_isoc_callback(struct usb_xfer *xfer, usb_error_t error)
{
enum {
REQ_SIZE = sizeof(struct usb_device_request)
};
struct urb *urb = xfer->priv_fifo;
struct usb_host_endpoint *uhe = xfer->priv_sc;
struct urb *urb = usbd_xfer_get_priv(xfer);
struct usb_host_endpoint *uhe = usbd_xfer_softc(xfer);
uint8_t *ptr;
usb_frlength_t max_bulk = xfer->max_data_length;
usb_frlength_t max_bulk = usbd_xfer_max_len(xfer);
uint8_t data_frame = xfer->flags_int.control_xfr ? 1 : 0;
DPRINTF("\n");
@ -1469,7 +1486,7 @@ usb_linux_non_isoc_callback(struct usb_xfer *xfer)
/* don't transfer the setup packet again: */
xfer->frlengths[0] = 0;
usbd_xfer_set_frame_len(xfer, 0, 0);
}
if (urb->bsd_isread && (!xfer->flags.ext_buffer)) {
/* copy in data with regard to the URB */
@ -1513,7 +1530,7 @@ usb_linux_non_isoc_callback(struct usb_xfer *xfer)
TAILQ_REMOVE(&uhe->bsd_urb_list, urb, bsd_urb_list);
urb->bsd_urb_list.tqe_prev = NULL;
xfer->priv_fifo = urb;
usbd_xfer_set_priv(xfer, urb);
xfer->flags.force_short_xfer = 0;
xfer->timeout = urb->timeout;
@ -1526,14 +1543,13 @@ usb_linux_non_isoc_callback(struct usb_xfer *xfer)
if (!xfer->flags.ext_buffer) {
usbd_copy_in(xfer->frbuffers, 0,
urb->setup_packet, REQ_SIZE);
usbd_xfer_set_frame_len(xfer, 0, REQ_SIZE);
} else {
/* set virtual address to load */
usbd_set_frame_data(xfer,
urb->setup_packet, 0);
usbd_xfer_set_frame_data(xfer, 0,
urb->setup_packet, REQ_SIZE);
}
xfer->frlengths[0] = REQ_SIZE;
ptr = urb->setup_packet;
/* setup data transfer direction and length */
@ -1567,14 +1583,14 @@ usb_linux_non_isoc_callback(struct usb_xfer *xfer)
if (xfer->flags.ext_buffer) {
/* set virtual address to load */
usbd_set_frame_data(xfer, urb->bsd_data_ptr,
data_frame);
usbd_xfer_set_frame_data(xfer, data_frame,
urb->bsd_data_ptr, max_bulk);
} else if (!urb->bsd_isread) {
/* copy out data with regard to the URB */
usbd_copy_in(xfer->frbuffers + data_frame, 0,
urb->bsd_data_ptr, max_bulk);
usbd_xfer_set_frame_len(xfer, data_frame, max_bulk);
}
xfer->frlengths[data_frame] = max_bulk;
if (xfer->flags_int.control_xfr) {
if (max_bulk > 0) {
xfer->nframes = 2;

View File

@ -39,46 +39,6 @@ typedef void (usb_complete_t)(struct urb *);
#define USB_MAX_FULL_SPEED_ISOC_FRAMES (60 * 1)
#define USB_MAX_HIGH_SPEED_ISOC_FRAMES (60 * 8)
/*
* Linux compatible USB device drivers put their device information
* into the "usb_device_id" structure using the "USB_DEVICE()" macro.
* The "MODULE_DEVICE_TABLE()" macro can be used to export this
* information to userland.
*/
struct usb_device_id {
/* which fields to match against */
uint16_t match_flags;
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
/* Used for product specific matches; the BCD range is inclusive */
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice_lo;
uint16_t bcdDevice_hi;
/* Used for device class matches */
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
/* Used for interface class matches */
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
/* Hook for driver specific information */
unsigned long driver_info;
};
#define USB_DEVICE_ID_MATCH_DEVICE \
(USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)

View File

@ -109,11 +109,11 @@ struct usb_pipe_methods {
/* Mandatory USB Device and Host mode callbacks: */
usb_callback_t *open;
usb_callback_t *close;
void (*open)(struct usb_xfer *);
void (*close)(struct usb_xfer *);
usb_callback_t *enter;
usb_callback_t *start;
void (*enter)(struct usb_xfer *);
void (*start)(struct usb_xfer *);
/* Optional */

View File

@ -30,8 +30,28 @@
* http://www.usb.org/developers/devclass_docs/
*/
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_mbuf.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
MALLOC_DEFINE(M_USB, "USB", "USB");
MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");

View File

@ -31,193 +31,6 @@
#ifndef _USB_CORE_H_
#define _USB_CORE_H_
#define USB_STACK_VERSION 2000 /* 2.0 */
/* Allow defines in "opt_usb.h" to override configuration */
#include "opt_usb.h"
#include "opt_bus.h"
/* Default USB configuration */
/*
* The following macro defines if the code shall support
* /dev/usb/x.y.z.
*/
#ifndef USB_HAVE_UGEN
#define USB_HAVE_UGEN 1
#endif
/*
* The following macro defines if the code shall support BUS-DMA.
*/
#ifndef USB_HAVE_BUSDMA
#define USB_HAVE_BUSDMA 1
#endif
/*
* The following macro defines if the code shall support the Linux
* compatibility layer.
*/
#ifndef USB_HAVE_COMPAT_LINUX
#define USB_HAVE_COMPAT_LINUX 1
#endif
/*
* The following macro defines if the code shall support
* userland data transfer via copyin() and copyout()
*/
#ifndef USB_HAVE_USER_IO
#define USB_HAVE_USER_IO 1
#endif
/*
* The following macro defines if the code shall support copy in via
* bsd-mbufs to USB.
*/
#ifndef USB_HAVE_MBUF
#define USB_HAVE_MBUF 1
#endif
/*
* The following macro defines if the code shall compile a table
* describing USB vendor and product IDs.
*/
#ifndef USB_VERBOSE
#define USB_VERBOSE 1
#endif
/*
* The following macro defines if USB debugging support shall be
* compiled for the USB core and all drivers.
*/
#ifndef USB_DEBUG
#define USB_DEBUG 1
#endif
/*
* The following macro defines if USB transaction translator support
* shall be supported for the USB HUB and USB controller drivers.
*/
#ifndef USB_HAVE_TT_SUPPORT
#define USB_HAVE_TT_SUPPORT 1
#endif
/*
* The following macro defines if the USB power daemon shall
* be supported in the USB core.
*/
#ifndef USB_HAVE_POWERD
#define USB_HAVE_POWERD 1
#endif
/*
* The following macro defines if the USB autoinstall detection shall
* be supported in the USB core.
*/
#ifndef USB_HAVE_MSCTEST
#define USB_HAVE_MSCTEST 1
#endif
#ifndef USB_TD_GET_PROC
#define USB_TD_GET_PROC(td) (td)->td_proc
#endif
#ifndef USB_PROC_GET_GID
#define USB_PROC_GET_GID(td) (td)->p_pgid
#endif
/* Include files */
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_defs.h>
#include <dev/usb/usb_revision.h>
#include "usb_if.h"
#ifndef USB_HOST_ALIGN
#define USB_HOST_ALIGN 8 /* bytes, must be power of two */
#endif
#ifndef USB_FS_ISOC_UFRAME_MAX
#define USB_FS_ISOC_UFRAME_MAX 4 /* exclusive unit */
#endif
#if (USB_FS_ISOC_UFRAME_MAX > 6)
#error "USB_FS_ISOC_UFRAME_MAX cannot be set higher than 6"
#endif
#ifndef USB_BUS_MAX
#define USB_BUS_MAX 256 /* units */
#endif
#ifndef USB_MAX_DEVICES
#define USB_MAX_DEVICES 128 /* units */
#endif
#if (USB_MAX_DEVICES < USB_MIN_DEVICES)
#error "Minimum number of devices is greater than maximum number of devices."
#endif
#ifndef USB_IFACE_MAX
#define USB_IFACE_MAX 32 /* units */
#endif
#ifndef USB_FIFO_MAX
#define USB_FIFO_MAX 128 /* units */
#endif
#if (USB_FIFO_MAX & 1)
#error "Number of FIFOs must be odd."
#endif
#define USB_MAX_FS_ISOC_FRAMES_PER_XFER (120) /* units */
#define USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120) /* units */
#ifndef USB_HUB_MAX_DEPTH
#define USB_HUB_MAX_DEPTH 5
#endif
#ifndef USB_EP0_BUFSIZE
#define USB_EP0_BUFSIZE 1024 /* bytes */
#endif
/* USB transfer states */
#define USB_ST_SETUP 0
#define USB_ST_TRANSFERRED 1
#define USB_ST_ERROR 2
/* USB handle request states */
#define USB_HR_NOT_COMPLETE 0
#define USB_HR_COMPLETE_OK 1
#define USB_HR_COMPLETE_ERR 2
/*
* The following macro will return the current state of an USB
* transfer like defined by the "USB_ST_XXX" enums.
*/
#define USB_GET_STATE(xfer) ((xfer)->usb_state)
/*
* The following macro will tell if an USB transfer is currently
* receiving or transferring data.
@ -226,30 +39,26 @@
USB_MODE_DEVICE ? (((xfer)->endpointno & UE_DIR_IN) ? 0 : 1) : \
(((xfer)->endpointno & UE_DIR_IN) ? 1 : 0))
/*
* The following macros are used used to convert milliseconds into
* HZ. We use 1024 instead of 1000 milliseconds per second to save a
* full division.
*/
#define USB_MS_HZ 1024
#define USB_MS_TO_TICKS(ms) \
(((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
/* macros */
#define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
#define usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
#define usb_callout_stop(c) callout_stop(&(c)->co)
#define usb_callout_drain(c) callout_drain(&(c)->co)
#define usb_callout_pending(c) callout_pending(&(c)->co)
#define USB_BUS_LOCK(_b) mtx_lock(&(_b)->bus_mtx)
#define USB_BUS_UNLOCK(_b) mtx_unlock(&(_b)->bus_mtx)
#define USB_BUS_LOCK_ASSERT(_b, _t) mtx_assert(&(_b)->bus_mtx, _t)
#define USB_XFER_LOCK(_x) mtx_lock((_x)->xroot->xfer_mtx)
#define USB_XFER_UNLOCK(_x) mtx_unlock((_x)->xroot->xfer_mtx)
#define USB_XFER_LOCK_ASSERT(_x, _t) mtx_assert((_x)->xroot->xfer_mtx, _t)
/* helper for converting pointers to integers */
#define USB_P2U(ptr) \
(((const uint8_t *)(ptr)) - ((const uint8_t *)0))
/* helper for computing offsets */
#define USB_ADD_BYTES(ptr,size) \
((void *)(USB_P2U(ptr) + (size)))
/* debug macro */
#define USB_ASSERT KASSERT
/* structure prototypes */
struct file;
@ -263,81 +72,8 @@ struct usb_xfer_root;
/* typedefs */
typedef void (usb_callback_t)(struct usb_xfer *);
#ifndef USB_HAVE_USB_ERROR_T
typedef uint8_t usb_error_t; /* see "USB_ERR_XXX" */
#endif
#ifndef USB_HAVE_TIMEOUT_T
typedef uint32_t usb_timeout_t; /* milliseconds */
#endif
#ifndef USB_HAVE_FRLENGTH_T
typedef uint32_t usb_frlength_t; /* bytes */
#endif
#ifndef USB_HAVE_FRCOUNT_T
typedef uint32_t usb_frcount_t; /* units */
#endif
#ifndef USB_HAVE_SIZE_T
typedef uint32_t usb_size_t; /* bytes */
#endif
#ifndef USB_HAVE_TICKS_T
typedef uint32_t usb_ticks_t; /* system defined */
#endif
#ifndef USB_HAVE_POWER_MASK_T
typedef uint16_t usb_power_mask_t; /* see "USB_HW_POWER_XXX" */
#endif
typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
struct usb_device_request *, const void **, uint16_t *);
/* structures */
/*
* Common queue structure for USB transfers.
*/
struct usb_xfer_queue {
TAILQ_HEAD(, usb_xfer) head;
struct usb_xfer *curr; /* current USB transfer processed */
void (*command) (struct usb_xfer_queue *pq);
uint8_t recurse_1:1;
uint8_t recurse_2:1;
};
/*
* The following is a wrapper for the callout structure to ease
* porting the code to other platforms.
*/
struct usb_callout {
struct callout co;
};
/*
* The following structure defines a set of USB transfer flags.
*/
struct usb_xfer_flags {
uint8_t force_short_xfer:1; /* force a short transmit transfer
* last */
uint8_t short_xfer_ok:1; /* allow short receive transfers */
uint8_t short_frames_ok:1; /* allow short frames */
uint8_t pipe_bof:1; /* block pipe on failure */
uint8_t proxy_buffer:1; /* makes buffer size a factor of
* "max_frame_size" */
uint8_t ext_buffer:1; /* uses external DMA buffer */
uint8_t manual_status:1; /* non automatic status stage on
* control transfers */
uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can
* be ignored */
uint8_t stall_pipe:1; /* set if the endpoint belonging to
* this USB transfer should be stalled
* before starting this transfer! */
};
/*
* The following structure defines a set of internal USB transfer
* flags.
@ -378,26 +114,6 @@ struct usb_xfer_flags_int {
* cancelled immediately */
};
/*
* The following structure define an USB configuration, that basically
* is used when setting up an USB transfer.
*/
struct usb_config {
usb_callback_t *callback; /* USB transfer callback */
usb_frlength_t bufsize; /* total pipe buffer size in bytes */
usb_frcount_t frames; /* maximum number of USB frames */
usb_timeout_t interval; /* interval in milliseconds */
#define USB_DEFAULT_INTERVAL 0
usb_timeout_t timeout; /* transfer timeout in milliseconds */
struct usb_xfer_flags flags; /* transfer flags */
enum usb_hc_mode usb_mode; /* host or device mode */
uint8_t type; /* pipe type */
uint8_t endpoint; /* pipe number */
uint8_t direction; /* pipe direction */
uint8_t ep_index; /* pipe index match to use */
uint8_t if_index; /* "ifaces" index to use */
};
/*
* The following structure defines an USB transfer.
*/
@ -428,8 +144,6 @@ struct usb_xfer {
usb_frlength_t sumlen; /* sum of all lengths in bytes */
usb_frlength_t actlen; /* actual length in bytes */
usb_timeout_t timeout; /* milliseconds */
#define USB_NO_TIMEOUT 0
#define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */
usb_frcount_t max_frame_count; /* initial value of "nframes" after
* setup */
@ -457,89 +171,14 @@ struct usb_xfer {
struct usb_xfer_flags_int flags_int;
};
/*
* The following structure keeps information that is used to match
* against an array of "usb_device_id" elements.
*/
struct usbd_lookup_info {
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t bIfaceIndex;
uint8_t bIfaceNum;
uint8_t bConfigIndex;
uint8_t bConfigNum;
};
/* Structure used by probe and attach */
struct usb_attach_arg {
struct usbd_lookup_info info;
device_t temp_dev; /* for internal use */
unsigned long driver_info; /* for internal use */
void *driver_ivar;
struct usb_device *device; /* current device */
struct usb_interface *iface; /* current interface */
enum usb_hc_mode usb_mode; /* host or device mode */
uint8_t port;
uint8_t use_generic; /* hint for generic drivers */
};
/* external variables */
MALLOC_DECLARE(M_USB);
MALLOC_DECLARE(M_USBDEV);
MALLOC_DECLARE(M_USBHC);
extern struct mtx usb_ref_lock;
/* typedefs */
typedef struct malloc_type *usb_malloc_type;
/* prototypes */
const char *usbd_errstr(usb_error_t error);
const char *usb_statestr(enum usb_dev_state state);
struct usb_config_descriptor *usbd_get_config_descriptor(
struct usb_device *udev);
struct usb_device_descriptor *usbd_get_device_descriptor(
struct usb_device *udev);
struct usb_interface *usbd_get_iface(struct usb_device *udev,
uint8_t iface_index);
struct usb_interface_descriptor *usbd_get_interface_descriptor(
struct usb_interface *iface);
uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1,
struct usb_xfer *xfer2);
uint8_t usbd_get_interface_altindex(struct usb_interface *iface);
usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
uint8_t iface_index, uint8_t alt_index);
enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
uint32_t usbd_get_isoc_fps(struct usb_device *udev);
usb_error_t usbd_transfer_setup(struct usb_device *udev,
const uint8_t *ifaces, struct usb_xfer **pxfer,
const struct usb_config *setup_start, uint16_t n_setup,
void *priv_sc, struct mtx *priv_mtx);
void usbd_set_frame_data(struct usb_xfer *xfer, void *ptr,
usb_frcount_t frindex);
void usbd_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
usb_frcount_t frindex);
void usbd_transfer_submit(struct usb_xfer *xfer);
void usbd_transfer_clear_stall(struct usb_xfer *xfer);
void usbd_transfer_drain(struct usb_xfer *xfer);
void usbd_transfer_set_stall(struct usb_xfer *xfer);
uint8_t usbd_transfer_pending(struct usb_xfer *xfer);
void usbd_transfer_start(struct usb_xfer *xfer);
void usbd_transfer_stop(struct usb_xfer *xfer);
void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
uint8_t parent_index);
uint8_t usbd_get_bus_index(struct usb_device *udev);
uint8_t usbd_get_device_index(struct usb_device *udev);
void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
uint8_t usbd_device_attached(struct usb_device *udev);
#endif /* _USB_CORE_H_ */

View File

@ -24,7 +24,28 @@
* SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
@ -33,6 +54,9 @@
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_transfer.h>
#include <ddb/ddb.h>
#include <ddb/db_sym.h>
/*
* Define this unconditionally in case a kernel module is loaded that
* has been compiled with debugging options.

View File

@ -29,9 +29,6 @@
#ifndef _USB_DEBUG_H_
#define _USB_DEBUG_H_
/* Declare parent SYSCTL USB node. */
SYSCTL_DECL(_hw_usb);
/* Declare global USB debug variable. */
extern int usb_debug;

View File

@ -27,16 +27,39 @@
* usb_dev.c - An abstraction layer for creating devices under /dev/...
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/vnode.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR usb_fifo_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_debug.h>
@ -56,7 +79,7 @@
#if USB_HAVE_UGEN
#if USB_DEBUG
#ifdef USB_DEBUG
static int usb_fifo_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, dev, CTLFLAG_RW, 0, "USB device");
@ -2196,4 +2219,10 @@ usb_fifo_set_close_zlp(struct usb_fifo *f, uint8_t onoff)
/* send a Zero Length Packet, ZLP, before close */
f->flag_short = onoff;
}
void *
usb_fifo_softc(struct usb_fifo *f)
{
return (f->priv_sc0);
}
#endif /* USB_HAVE_UGEN */

View File

@ -28,25 +28,14 @@
#define _USB_DEV_H_
#include <sys/file.h>
#include <sys/vnode.h>
#include <sys/selinfo.h>
#include <sys/poll.h>
#include <sys/signalvar.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/proc.h>
#define USB_FIFO_TX 0
#define USB_FIFO_RX 1
struct usb_fifo;
struct usb_mbuf;
typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
struct usb_symlink {
TAILQ_ENTRY(usb_symlink) sym_entry;
char src_path[32]; /* Source path - including terminating
@ -57,30 +46,6 @@ struct usb_symlink {
uint8_t dst_len; /* String length */
};
/*
* Locking note for the following functions. All the
* "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
* locked. The others are called unlocked.
*/
struct usb_fifo_methods {
usb_fifo_open_t *f_open;
usb_fifo_close_t *f_close;
usb_fifo_ioctl_t *f_ioctl;
/*
* NOTE: The post-ioctl callback is called after the USB reference
* gets locked in the IOCTL handler:
*/
usb_fifo_ioctl_t *f_ioctl_post;
usb_fifo_cmd_t *f_start_read;
usb_fifo_cmd_t *f_stop_read;
usb_fifo_cmd_t *f_start_write;
usb_fifo_cmd_t *f_stop_write;
usb_fifo_filter_t *f_filter_read;
usb_fifo_filter_t *f_filter_write;
const char *basename[4];
const char *postfix[4];
};
/*
* Private per-device information.
*/
@ -95,6 +60,18 @@ struct usb_cdev_privdata {
uint8_t fifo_index; /* FIFO index */
};
/*
* The following structure defines a minimum re-implementation of the
* ifqueue structure in the kernel.
*/
struct usb_ifqueue {
struct usb_mbuf *ifq_head;
struct usb_mbuf *ifq_tail;
usb_size_t ifq_len;
usb_size_t ifq_maxlen;
};
/*
* Private per-device and per-thread reference information
*/
@ -162,42 +139,12 @@ struct usb_fifo {
#define USB_FIFO_REF_MAX 0xFF
};
struct usb_fifo_sc {
struct usb_fifo *fp[2];
struct cdev* dev;
};
extern struct cdevsw usb_devsw;
int usb_fifo_wait(struct usb_fifo *fifo);
void usb_fifo_signal(struct usb_fifo *fifo);
int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
uint16_t nbuf);
void usb_fifo_free_buffer(struct usb_fifo *f);
int usb_fifo_attach(struct usb_device *udev, void *priv_sc,
struct mtx *priv_mtx, struct usb_fifo_methods *pm,
struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
uint8_t iface_index, uid_t uid, gid_t gid, int mode);
void usb_fifo_detach(struct usb_fifo_sc *f_sc);
uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
usb_frlength_t offset, usb_frlength_t len, uint8_t what);
void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
usb_size_t len, uint8_t what);
uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
void usb_fifo_put_data_error(struct usb_fifo *fifo);
uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
uint8_t what);
uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
usb_size_t len, usb_size_t *actlen, uint8_t what);
uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
usb_size_t *plen);
void usb_fifo_get_data_error(struct usb_fifo *fifo);
uint8_t usb_fifo_opened(struct usb_fifo *fifo);
void usb_fifo_free(struct usb_fifo *f);
void usb_fifo_reset(struct usb_fifo *f);
void usb_fifo_wakeup(struct usb_fifo *f);
struct usb_symlink *usb_alloc_symlink(const char *target);
void usb_free_symlink(struct usb_symlink *ps);
int usb_read_symlink(uint8_t *user_ptr, uint32_t startentry,

View File

@ -24,9 +24,31 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_ioctl.h>
#include "usbdevs.h"
@ -38,12 +60,10 @@
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_hub.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_msctest.h>
#if USB_HAVE_UGEN
#include <dev/usb/usb_dev.h>
@ -277,7 +297,7 @@ usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
}
/*------------------------------------------------------------------------*
* usb_interface_count
* usbd_interface_count
*
* This function stores the number of USB interfaces excluding
* alternate settings, which the USB config descriptor reports into
@ -288,7 +308,7 @@ usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
* Else: Failure
*------------------------------------------------------------------------*/
usb_error_t
usb_interface_count(struct usb_device *udev, uint8_t *count)
usbd_interface_count(struct usb_device *udev, uint8_t *count)
{
if (udev->cdesc == NULL) {
*count = 0;
@ -2105,7 +2125,7 @@ usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len)
}
}
#if USB_VERBOSE
#ifdef USB_VERBOSE
/*
* Descriptions of of known vendors and devices ("products").
*/
@ -2127,7 +2147,7 @@ static void
usbd_set_device_strings(struct usb_device *udev)
{
struct usb_device_descriptor *udd = &udev->ddesc;
#if USB_VERBOSE
#ifdef USB_VERBOSE
const struct usb_knowndev *kdp;
#endif
char temp[64];
@ -2159,7 +2179,7 @@ usbd_set_device_strings(struct usb_device *udev)
if (temp[0] != '\0')
udev->product = strdup(temp, M_USB);
#if USB_VERBOSE
#ifdef USB_VERBOSE
if (udev->manufacturer == NULL || udev->product == NULL) {
for (kdp = usb_knowndevs; kdp->vendorname != NULL; kdp++) {
if (kdp->vendor == vendor_id &&

View File

@ -76,44 +76,6 @@ struct usb_host_interface {
uint8_t bsd_iface_index;
} __aligned(USB_HOST_ALIGN);
/*
* The following structure defines an USB endpoint
* USB endpoint.
*/
struct usb_endpoint {
struct usb_xfer_queue endpoint_q; /* queue of USB transfers */
struct usb_endpoint_descriptor *edesc;
struct usb_pipe_methods *methods; /* set by HC driver */
uint16_t isoc_next;
uint16_t refcount;
uint8_t toggle_next:1; /* next data toggle value */
uint8_t is_stalled:1; /* set if endpoint is stalled */
uint8_t is_synced:1; /* set if we a synchronised */
uint8_t unused:5;
uint8_t iface_index; /* not used by "default endpoint" */
};
/*
* The following structure defines an USB interface.
*/
struct usb_interface {
struct usb_interface_descriptor *idesc;
device_t subdev;
uint8_t alt_index;
uint8_t parent_iface_index;
/* Linux compat */
struct usb_host_interface *altsetting;
struct usb_host_interface *cur_altsetting;
struct usb_device *linux_udev;
void *bsd_priv_sc; /* device specific information */
uint8_t num_altsetting; /* number of alternate settings */
uint8_t bsd_iface_index;
};
/*
* The following structure defines the USB device flags.
*/
@ -228,14 +190,11 @@ extern int usb_template;
/* function prototypes */
const char *usb_statestr(enum usb_dev_state state);
struct usb_device *usb_alloc_device(device_t parent_dev, struct usb_bus *bus,
struct usb_device *parent_hub, uint8_t depth,
uint8_t port_index, uint8_t port_no,
enum usb_dev_speed speed, enum usb_hc_mode mode);
struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
const struct usb_config *setup);
struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
usb_error_t usb_interface_count(struct usb_device *udev, uint8_t *count);
usb_error_t usb_probe_and_attach(struct usb_device *udev,
uint8_t iface_index);
usb_error_t usb_reset_iface_endpoints(struct usb_device *udev,
@ -247,9 +206,6 @@ usb_error_t usb_suspend_resume(struct usb_device *udev,
uint8_t do_suspend);
void usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len);
void usb_free_device(struct usb_device *, uint8_t);
void *usbd_find_descriptor(struct usb_device *udev, void *id,
uint8_t iface_index, uint8_t type, uint8_t type_mask,
uint8_t subtype, uint8_t subtype_mask);
void usb_linux_free_device(struct usb_device *dev);
uint8_t usb_peer_can_wakeup(struct usb_device *udev);
struct usb_endpoint *usb_endpoint_foreach(struct usb_device *udev, struct usb_endpoint *ep);

View File

@ -24,9 +24,28 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_process.h>
@ -86,7 +105,7 @@ usb_temp_unsetup_w(struct usb_device *udev)
}
}
static uint8_t
static usb_error_t
usb_test_huawei_autoinst_w(struct usb_device *udev,
struct usb_attach_arg *uaa)
{

View File

@ -62,6 +62,4 @@ void usb_temp_unload(void *);
void usb_quirk_unload(void *);
void usb_bus_unload(void *);
uint8_t usb_test_quirk(const struct usb_attach_arg *uaa, uint16_t quirk);
#endif /* _USB_DYNAMIC_H_ */

View File

@ -24,10 +24,28 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
static const char* usb_errstr_table[USB_ERR_MAX] = {
[USB_ERR_NORMAL_COMPLETION] = "USB_ERR_NORMAL_COMPLETION",

View File

@ -1,63 +0,0 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _USB_ERROR_H_
#define _USB_ERROR_H_
enum { /* keep in sync with usb_errstr_table */
USB_ERR_NORMAL_COMPLETION = 0,
USB_ERR_PENDING_REQUESTS, /* 1 */
USB_ERR_NOT_STARTED, /* 2 */
USB_ERR_INVAL, /* 3 */
USB_ERR_NOMEM, /* 4 */
USB_ERR_CANCELLED, /* 5 */
USB_ERR_BAD_ADDRESS, /* 6 */
USB_ERR_BAD_BUFSIZE, /* 7 */
USB_ERR_BAD_FLAG, /* 8 */
USB_ERR_NO_CALLBACK, /* 9 */
USB_ERR_IN_USE, /* 10 */
USB_ERR_NO_ADDR, /* 11 */
USB_ERR_NO_PIPE, /* 12 */
USB_ERR_ZERO_NFRAMES, /* 13 */
USB_ERR_ZERO_MAXP, /* 14 */
USB_ERR_SET_ADDR_FAILED, /* 15 */
USB_ERR_NO_POWER, /* 16 */
USB_ERR_TOO_DEEP, /* 17 */
USB_ERR_IOERROR, /* 18 */
USB_ERR_NOT_CONFIGURED, /* 19 */
USB_ERR_TIMEOUT, /* 20 */
USB_ERR_SHORT_XFER, /* 21 */
USB_ERR_STALLED, /* 22 */
USB_ERR_INTERRUPTED, /* 23 */
USB_ERR_DMA_LOAD_FAILED, /* 24 */
USB_ERR_BAD_CONTEXT, /* 25 */
USB_ERR_NO_ROOT_HUB, /* 26 */
USB_ERR_NO_INTR_THREAD, /* 27 */
USB_ERR_NOT_LOCKED, /* 28 */
USB_ERR_MAX
};
#endif /* _USB_ERROR_H_ */

View File

@ -24,38 +24,48 @@
* SUCH DAMAGE.
*/
#ifndef _USB_DEFS_H_
#define _USB_DEFS_H_
/*
* Including this file is mandatory for all USB related c-files in the kernel.
*/
/* Definition of some hardcoded USB constants. */
#ifndef _USB_FREEBSD_H_
#define _USB_FREEBSD_H_
#define USB_MAX_IPACKET 8 /* initial USB packet size */
/* Default USB configuration */
#define USB_HAVE_UGEN 1
#define USB_HAVE_BUSDMA 1
#define USB_HAVE_COMPAT_LINUX 1
#define USB_HAVE_USER_IO 1
#define USB_HAVE_MBUF 1
#define USB_HAVE_TT_SUPPORT 1
#define USB_HAVE_POWERD 1
#define USB_HAVE_MSCTEST 1
#define USB_EP_MAX (2*16) /* hardcoded */
#define USB_TD_GET_PROC(td) (td)->td_proc
#define USB_PROC_GET_GID(td) (td)->p_pgid
#define USB_ROOT_HUB_ADDR 1 /* index */
#define USB_HOST_ALIGN 8 /* bytes, must be power of two */
#define USB_FS_ISOC_UFRAME_MAX 4 /* exclusive unit */
#define USB_BUS_MAX 256 /* units */
#define USB_MAX_DEVICES 128 /* units */
#define USB_IFACE_MAX 32 /* units */
#define USB_FIFO_MAX 128 /* units */
#define USB_MIN_DEVICES 2 /* unused + root HUB */
#define USB_MAX_FS_ISOC_FRAMES_PER_XFER (120) /* units */
#define USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120) /* units */
#define USB_UNCONFIG_INDEX 0xFF /* internal use only */
#define USB_IFACE_INDEX_ANY 0xFF /* internal use only */
#define USB_HUB_MAX_DEPTH 5
#define USB_EP0_BUFSIZE 1024 /* bytes */
#define USB_START_ADDR 0 /* default USB device BUS address
* after USB bus reset */
#define USB_CONTROL_ENDPOINT 0 /* default control endpoint */
#define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */
#define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */
#define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */
#define USB_HS_MICRO_FRAMES_MAX 8 /* units */
#define USB_ISOC_TIME_MAX 128 /* ms */
/* sanity checks */
#if (USB_ROOT_HUB_ADDR >= USB_MIN_DEVICES)
#error "The root hub address must be less than USB_MIN_DEVICES."
#ifndef USB_DEBUG
#define USB_DEBUG 1
#endif
#endif /* _USB_DEFS_H_ */
typedef uint32_t usb_timeout_t; /* milliseconds */
typedef uint32_t usb_frlength_t; /* bytes */
typedef uint32_t usb_frcount_t; /* units */
typedef uint32_t usb_size_t; /* bytes */
typedef uint32_t usb_ticks_t; /* system defined */
typedef uint16_t usb_power_mask_t; /* see "USB_HW_POWER_XXX" */
#endif /* _USB_FREEBSD_H_ */

View File

@ -24,16 +24,38 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#define USB_DEBUG_VAR ugen_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_mbuf.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_debug.h>
@ -102,7 +124,7 @@ struct usb_fifo_methods usb_ugen_methods = {
.f_stop_write = &ugen_stop_io,
};
#if USB_DEBUG
#ifdef USB_DEBUG
static int ugen_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, ugen, CTLFLAG_RW, 0, "USB generic");
@ -117,7 +139,7 @@ static int
ugen_transfer_setup(struct usb_fifo *f,
const struct usb_config *setup, uint8_t n_setup)
{
struct usb_endpoint *ep = f->priv_sc0;
struct usb_endpoint *ep = usb_fifo_softc(f);
struct usb_device *udev = f->udev;
uint8_t iface_index = ep->iface_index;
int error;
@ -152,7 +174,7 @@ ugen_transfer_setup(struct usb_fifo *f,
static int
ugen_open(struct usb_fifo *f, int fflags)
{
struct usb_endpoint *ep = f->priv_sc0;
struct usb_endpoint *ep = usb_fifo_softc(f);
struct usb_endpoint_descriptor *ed = ep->edesc;
uint8_t type;
@ -208,7 +230,7 @@ static int
ugen_open_pipe_write(struct usb_fifo *f)
{
struct usb_config usb_config[2];
struct usb_endpoint *ep = f->priv_sc0;
struct usb_endpoint *ep = usb_fifo_softc(f);
struct usb_endpoint_descriptor *ed = ep->edesc;
mtx_assert(f->priv_mtx, MA_OWNED);
@ -276,7 +298,7 @@ static int
ugen_open_pipe_read(struct usb_fifo *f)
{
struct usb_config usb_config[2];
struct usb_endpoint *ep = f->priv_sc0;
struct usb_endpoint *ep = usb_fifo_softc(f);
struct usb_endpoint_descriptor *ed = ep->edesc;
mtx_assert(f->priv_mtx, MA_OWNED);
@ -377,9 +399,9 @@ ugen_stop_io(struct usb_fifo *f)
}
static void
ugen_default_read_callback(struct usb_xfer *xfer)
ugen_default_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
struct usb_mbuf *m;
DPRINTFN(4, "actlen=%u, aframes=%u\n", xfer->actlen, xfer->aframes);
@ -411,7 +433,7 @@ ugen_default_read_callback(struct usb_xfer *xfer)
}
USB_IF_POLL(&f->free_q, m);
if (m) {
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
break;
@ -429,9 +451,9 @@ ugen_default_read_callback(struct usb_xfer *xfer)
}
static void
ugen_default_write_callback(struct usb_xfer *xfer)
ugen_default_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
usb_frlength_t actlen;
DPRINTFN(4, "actlen=%u, aframes=%u\n", xfer->actlen, xfer->aframes);
@ -452,7 +474,7 @@ ugen_default_write_callback(struct usb_xfer *xfer)
*/
if (usb_fifo_get_data(f, xfer->frbuffers, 0,
xfer->max_data_length, &actlen, 0)) {
xfer->frlengths[0] = actlen;
usbd_xfer_set_frame_len(xfer, 0, actlen);
usbd_transfer_submit(xfer);
}
break;
@ -467,9 +489,9 @@ ugen_default_write_callback(struct usb_xfer *xfer)
}
static void
ugen_read_clear_stall_callback(struct usb_xfer *xfer)
ugen_read_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = f->xfer[0];
if (f->flag_stall == 0) {
@ -484,9 +506,9 @@ ugen_read_clear_stall_callback(struct usb_xfer *xfer)
}
static void
ugen_write_clear_stall_callback(struct usb_xfer *xfer)
ugen_write_clear_stall_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
struct usb_xfer *xfer_other = f->xfer[0];
if (f->flag_stall == 0) {
@ -501,9 +523,9 @@ ugen_write_clear_stall_callback(struct usb_xfer *xfer)
}
static void
ugen_isoc_read_callback(struct usb_xfer *xfer)
ugen_isoc_read_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
usb_frlength_t offset;
usb_frcount_t n;
@ -526,7 +548,7 @@ ugen_isoc_read_callback(struct usb_xfer *xfer)
tr_setup:
for (n = 0; n != xfer->nframes; n++) {
/* setup size for next transfer */
xfer->frlengths[n] = xfer->max_frame_size;
usbd_xfer_set_frame_len(xfer, n, xfer->max_frame_size);
}
usbd_transfer_submit(xfer);
break;
@ -540,9 +562,9 @@ ugen_isoc_read_callback(struct usb_xfer *xfer)
}
static void
ugen_isoc_write_callback(struct usb_xfer *xfer)
ugen_isoc_write_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct usb_fifo *f = xfer->priv_sc;
struct usb_fifo *f = usbd_xfer_softc(xfer);
usb_frlength_t actlen;
usb_frlength_t offset;
usb_frcount_t n;
@ -557,7 +579,7 @@ ugen_isoc_write_callback(struct usb_xfer *xfer)
for (n = 0; n != xfer->nframes; n++) {
if (usb_fifo_get_data(f, xfer->frbuffers, offset,
xfer->max_frame_size, &actlen, 1)) {
xfer->frlengths[n] = actlen;
usbd_xfer_set_frame_len(xfer, n, actlen);
offset += actlen;
} else {
break;
@ -566,7 +588,7 @@ ugen_isoc_write_callback(struct usb_xfer *xfer)
for (; n != xfer->nframes; n++) {
/* fill in zero frames */
xfer->frlengths[n] = 0;
usbd_xfer_set_frame_len(xfer, n, 0);
}
usbd_transfer_submit(xfer);
break;
@ -1059,7 +1081,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
return (error);
}
/* reset first frame */
usbd_set_frame_offset(xfer, 0, 0);
usbd_xfer_set_frame_offset(xfer, 0, 0);
if (xfer->flags_int.control_xfr) {
@ -1084,7 +1106,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
xfer->error = USB_ERR_INVAL;
goto complete;
}
xfer->frlengths[0] = length;
usbd_xfer_set_frame_len(xfer, 0, length);
/* Host mode only ! */
if ((req->bmRequestType &
@ -1107,7 +1129,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
offset = 0;
}
rem = xfer->max_data_length;
rem = usbd_xfer_max_len(xfer);
xfer->nframes = fs_ep.nFrames;
xfer->timeout = fs_ep.timeout;
if (xfer->timeout > 65535) {
@ -1129,7 +1151,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
xfer->flags.force_short_xfer = 0;
if (fs_ep.flags & USB_FS_FLAG_CLEAR_STALL)
xfer->flags.stall_pipe = 1;
usbd_xfer_set_stall(xfer);
else
xfer->flags.stall_pipe = 0;
@ -1140,7 +1162,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
if (error) {
break;
}
xfer->frlengths[n] = length;
usbd_xfer_set_frame_len(xfer, n, length);
if (length > rem) {
xfer->error = USB_ERR_INVAL;
@ -1162,7 +1184,7 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
kaddr = USB_ADD_BYTES(kaddr, offset);
} else {
/* set current frame offset */
usbd_set_frame_offset(xfer, offset, n);
usbd_xfer_set_frame_offset(xfer, offset, n);
/* get kernel buffer address */
kaddr = xfer->frbuffers[n].buffer;
@ -1252,7 +1274,7 @@ ugen_fs_copy_out(struct usb_fifo *f, uint8_t ep_index)
/* Update lengths and copy out data */
rem = xfer->max_data_length;
rem = usbd_xfer_max_len(xfer);
offset = 0;
for (; n != xfer->nframes; n++) {
@ -1660,7 +1682,7 @@ ugen_get_endpoint_desc(struct usb_fifo *f,
{
struct usb_endpoint *ep;
ep = f->priv_sc0;
ep = usb_fifo_softc(f);
if (ep && ep->edesc) {
*ed = *ep->edesc;
@ -2162,7 +2184,7 @@ ugen_ioctl_post(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
}
static void
ugen_default_fs_callback(struct usb_xfer *xfer)
ugen_default_fs_callback(struct usb_xfer *xfer, usb_error_t error)
{
; /* workaround for a bug in "indent" */

View File

@ -24,9 +24,29 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include "usb_if.h"
#define USB_DEBUG_VAR usb_debug
@ -61,7 +81,7 @@ static usb_error_t usb_handle_iface_request(struct usb_xfer *, void **,
* transfers.
*------------------------------------------------------------------------*/
void
usb_handle_request_callback(struct usb_xfer *xfer)
usb_handle_request_callback(struct usb_xfer *xfer, usb_error_t error)
{
usb_error_t err;
@ -105,11 +125,11 @@ usb_handle_request_callback(struct usb_xfer *xfer)
* If a control transfer is active, stall it, and wait for the
* next control transfer.
*/
xfer->frlengths[0] = sizeof(struct usb_device_request);
usbd_xfer_set_frame_len(xfer, 0, sizeof(struct usb_device_request));
xfer->nframes = 1;
xfer->flags.manual_status = 1;
xfer->flags.force_short_xfer = 0;
xfer->flags.stall_pipe = 1; /* cancel previous transfer, if any */
usbd_xfer_set_stall(xfer); /* cancel previous transfer, if any */
usbd_transfer_submit(xfer);
}
@ -458,10 +478,10 @@ usb_handle_request(struct usb_xfer *xfer)
/* reset frame stuff */
xfer->frlengths[0] = 0;
usbd_xfer_set_frame_len(xfer, 0, 0);
usbd_set_frame_offset(xfer, 0, 0);
usbd_set_frame_offset(xfer, sizeof(req), 1);
usbd_xfer_set_frame_offset(xfer, 0, 0);
usbd_xfer_set_frame_offset(xfer, sizeof(req), 1);
/* get the current request, if any */
@ -702,7 +722,7 @@ usb_handle_request(struct usb_xfer *xfer)
/* Compute the real maximum data length */
if (max_len > xfer->max_data_length) {
max_len = xfer->max_data_length;
max_len = usbd_xfer_max_len(xfer);
}
if (max_len > rem) {
max_len = rem;
@ -713,7 +733,7 @@ usb_handle_request(struct usb_xfer *xfer)
* comparison below:
*/
if (rem > xfer->max_data_length) {
rem = xfer->max_data_length;
rem = usbd_xfer_max_len(xfer);
}
if (rem != max_len) {
/*
@ -734,15 +754,15 @@ usb_handle_request(struct usb_xfer *xfer)
src_mcopy = USB_ADD_BYTES(src_mcopy, off);
usbd_copy_in(xfer->frbuffers + 1, 0,
src_mcopy, max_len);
usbd_xfer_set_frame_len(xfer, 1, max_len);
} else {
usbd_set_frame_data(xfer,
USB_ADD_BYTES(src_zcopy, off), 1);
usbd_xfer_set_frame_data(xfer, 1,
USB_ADD_BYTES(src_zcopy, off), max_len);
}
xfer->frlengths[1] = max_len;
} else {
/* the end is reached, send status */
xfer->flags.manual_status = 0;
xfer->frlengths[1] = 0;
usbd_xfer_set_frame_len(xfer, 1, 0);
}
DPRINTF("success\n");
return (0); /* success */

View File

@ -1,30 +0,0 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _USB_HANDLE_REQUEST_H_
#define _USB_HANDLE_REQUEST_H_
#endif /* _USB_HANDLE_REQUEST_H_ */

View File

@ -40,20 +40,38 @@ __FBSDID("$FreeBSD$");
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_parse.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_hid.h>
static void hid_clear_local(struct hid_item *);
static uint8_t hid_get_byte(struct hid_data *s, const uint16_t wSize);

View File

@ -1,95 +0,0 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
* Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
* Copyright (c) 1998 Lennart Augustsson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _USB_CORE_HID_H_
#define _USB_CORE_HID_H_
struct usb_hid_descriptor;
struct usb_config_descriptor;
enum hid_kind {
hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
};
struct hid_location {
uint32_t size;
uint32_t count;
uint32_t pos;
};
struct hid_item {
/* Global */
int32_t _usage_page;
int32_t logical_minimum;
int32_t logical_maximum;
int32_t physical_minimum;
int32_t physical_maximum;
int32_t unit_exponent;
int32_t unit;
int32_t report_ID;
/* Local */
int32_t usage;
int32_t usage_minimum;
int32_t usage_maximum;
int32_t designator_index;
int32_t designator_minimum;
int32_t designator_maximum;
int32_t string_index;
int32_t string_minimum;
int32_t string_maximum;
int32_t set_delimiter;
/* Misc */
int32_t collection;
int collevel;
enum hid_kind kind;
uint32_t flags;
/* Location */
struct hid_location loc;
};
/* prototypes from "usb_hid.c" */
struct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset);
void hid_end_parse(struct hid_data *s);
int hid_get_item(struct hid_data *s, struct hid_item *h);
int hid_report_size(const void *buf, usb_size_t len, enum hid_kind k,
uint8_t *id);
int hid_locate(const void *desc, usb_size_t size, uint32_t usage,
enum hid_kind kind, uint8_t index, struct hid_location *loc,
uint32_t *flags, uint8_t *id);
uint32_t hid_get_data(const uint8_t *buf, usb_size_t len,
struct hid_location *loc);
int hid_is_collection(const void *desc, usb_size_t size, uint32_t usage);
struct usb_hid_descriptor *hid_get_descriptor_from_usb(
struct usb_config_descriptor *cd,
struct usb_interface_descriptor *id);
usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
void **descp, uint16_t *sizep, struct malloc_type *mem,
uint8_t iface_index);
#endif /* _USB_CORE_HID_H_ */

View File

@ -30,10 +30,29 @@
* USB spec: http://www.usb.org/developers/docs/usbspec.zip
*/
#include <dev/usb/usb_mfunc.h>
#include <dev/usb/usb_error.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR uhub_debug
@ -54,7 +73,7 @@
#define UHUB_INTR_INTERVAL 250 /* ms */
#define UHUB_N_TRANSFER 1
#if USB_DEBUG
#ifdef USB_DEBUG
static int uhub_debug = 0;
SYSCTL_NODE(_hw_usb, OID_AUTO, uhub, CTLFLAG_RW, 0, "USB HUB");
@ -149,9 +168,9 @@ DRIVER_MODULE(uhub, usbus, uhub_driver, uhub_devclass, 0, 0);
DRIVER_MODULE(uhub, uhub, uhub_driver, uhub_devclass, NULL, 0);
static void
uhub_intr_callback(struct usb_xfer *xfer)
uhub_intr_callback(struct usb_xfer *xfer, usb_error_t error)
{
struct uhub_softc *sc = xfer->priv_sc;
struct uhub_softc *sc = usbd_xfer_softc(xfer);
switch (USB_GET_STATE(xfer)) {
case USB_ST_TRANSFERRED:
@ -165,7 +184,7 @@ uhub_intr_callback(struct usb_xfer *xfer)
usb_needs_explore(sc->sc_udev->bus, 0);
case USB_ST_SETUP:
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
break;
@ -176,8 +195,8 @@ uhub_intr_callback(struct usb_xfer *xfer)
* will get cleared before next callback by
* the USB stack.
*/
xfer->flags.stall_pipe = 1;
xfer->frlengths[0] = xfer->max_data_length;
usbd_xfer_set_stall(xfer);
usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
usbd_transfer_submit(xfer);
}
break;

View File

@ -49,9 +49,6 @@ struct usb_read_dir {
struct usb_ctl_request {
void *ucr_data;
uint16_t ucr_flags;
#define USB_SHORT_XFER_OK 0x0004 /* allow short reads */
#define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */
#define USB_USER_DATA_PTR 0x0020 /* internal flag */
uint16_t ucr_actlen; /* actual length transferred */
uint8_t ucr_addr; /* zero - currently not used */
struct usb_device_request ucr_request;
@ -148,7 +145,7 @@ struct usb_fs_endpoint {
uint16_t isoc_time_complete;
/* timeout value for no timeout */
#define USB_FS_TIMEOUT_NONE 0
uint8_t status; /* see USB_ERR_XXX */
int status; /* see USB_ERR_XXX */
};
struct usb_fs_init {

View File

@ -24,8 +24,28 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_lookup.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
/*------------------------------------------------------------------------*
* usbd_lookup_id_by_info

View File

@ -1,122 +0,0 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _USB_LOOKUP_H_
#define _USB_LOOKUP_H_
struct usb_attach_arg;
/*
* The following structure is used when looking up an USB driver for
* an USB device. It is inspired by the Linux structure called
* "usb_device_id".
*/
struct usb_device_id {
/* Hook for driver specific information */
unsigned long driver_info;
/* Used for product specific matches; the BCD range is inclusive */
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice_lo;
uint16_t bcdDevice_hi;
/* Used for device class matches */
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
/* Used for interface class matches */
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
/* Select which fields to match against */
uint8_t match_flag_vendor:1;
uint8_t match_flag_product:1;
uint8_t match_flag_dev_lo:1;
uint8_t match_flag_dev_hi:1;
uint8_t match_flag_dev_class:1;
uint8_t match_flag_dev_subclass:1;
uint8_t match_flag_dev_protocol:1;
uint8_t match_flag_int_class:1;
uint8_t match_flag_int_subclass:1;
uint8_t match_flag_int_protocol:1;
};
#define USB_VENDOR(vend) \
.match_flag_vendor = 1, .idVendor = (vend)
#define USB_PRODUCT(prod) \
.match_flag_product = 1, .idProduct = (prod)
#define USB_VP(vend,prod) \
USB_VENDOR(vend), USB_PRODUCT(prod)
#define USB_VPI(vend,prod,info) \
USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
#define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \
.match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
#define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \
.match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
#define USB_DEV_CLASS(dc) \
.match_flag_dev_class = 1, .bDeviceClass = (dc)
#define USB_DEV_SUBCLASS(dsc) \
.match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
#define USB_DEV_PROTOCOL(dp) \
.match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
#define USB_IFACE_CLASS(ic) \
.match_flag_int_class = 1, .bInterfaceClass = (ic)
#define USB_IFACE_SUBCLASS(isc) \
.match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
#define USB_IFACE_PROTOCOL(ip) \
.match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
#define USB_IF_CSI(class,subclass,info) \
USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
#define USB_DRIVER_INFO(n) \
.driver_info = (n)
#define USB_GET_DRIVER_INFO(did) \
(did)->driver_info
const struct usb_device_id *usbd_lookup_id_by_info(
const struct usb_device_id *id, usb_size_t sizeof_id,
const struct usbd_lookup_info *info);
int usbd_lookup_id_by_uaa(const struct usb_device_id *id,
usb_size_t sizeof_id, struct usb_attach_arg *uaa);
#endif /* _USB_LOOKUP_H_ */

View File

@ -24,7 +24,29 @@
* SUCH DAMAGE.
*/
#include <dev/usb/usb_core.h>
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/linker_set.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_dev.h>
#include <dev/usb/usb_mbuf.h>
/*------------------------------------------------------------------------*

View File

@ -43,18 +43,6 @@ struct usb_mbuf {
uint8_t unused:7;
};
/*
* The following structure defines a minimum re-implementation of the
* ifqueue structure in the kernel.
*/
struct usb_ifqueue {
struct usb_mbuf *ifq_head;
struct usb_mbuf *ifq_tail;
usb_size_t ifq_len;
usb_size_t ifq_maxlen;
};
#define USB_IF_ENQUEUE(ifq, m) do { \
(m)->usb_nextpkt = NULL; \
if ((ifq)->ifq_tail == NULL) \

Some files were not shown because too many files have changed in this diff Show More