Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/dev/usb/usbdi.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/dev/usb/usbdi.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.119.12.8 retrieving revision 1.120 diff -u -p -r1.119.12.8 -r1.120 --- src/sys/dev/usb/usbdi.c 2009/11/12 08:04:04 1.119.12.8 +++ src/sys/dev/usb/usbdi.c 2007/08/15 04:00:34 1.120 @@ -1,7 +1,7 @@ -/* $NetBSD: usbdi.c,v 1.119.12.8 2009/11/12 08:04:04 uebayasi Exp $ */ -/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.99 2006/11/27 18:39:02 marius Exp $ */ +/* $NetBSD: usbdi.c,v 1.120 2007/08/15 04:00:34 kiyohara Exp $ */ +/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */ -/*- +/* * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * @@ -39,12 +39,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.119.12.8 2009/11/12 08:04:04 uebayasi Exp $"); -/* __FBSDID("$FreeBSD: src/sys/dev/usb/usbdi.c,v 1.99 2006/11/27 18:39:02 marius Exp $"); */ +__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.120 2007/08/15 04:00:34 kiyohara Exp $"); -#ifdef __NetBSD__ #include "opt_compat_netbsd.h" -#endif #include #include @@ -54,13 +51,13 @@ __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1. #elif defined(__FreeBSD__) #include #include +#include #include "usb_if.h" #if defined(DIAGNOSTIC) && defined(__i386__) #include #endif #endif #include -#include #include #include @@ -69,14 +66,9 @@ __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1. #include #include #include -/* #include */ +#include #include -#if defined(__FreeBSD__) -#include "usb_if.h" -#define delay(d) DELAY(d) -#endif - /* UTF-8 encoding stuff */ #include @@ -89,20 +81,14 @@ extern int usbdebug; #define DPRINTFN(n,x) #endif -Static usbd_xfer_handle usbd_alloc_xfer_flag(usbd_device_handle, - usbd_pipe_handle pipe, enum usbd_waitflg); -Static void usbd_free_buffer_flag(usbd_xfer_handle, enum usbd_waitflg); -Static usbd_status usbd_free_xfer_flag(usbd_xfer_handle, enum usbd_waitflg); Static usbd_status usbd_ar_pipe(usbd_pipe_handle pipe); -Static void usbd_callback_task(void *); Static void usbd_do_request_async_cb (usbd_xfer_handle, usbd_private_handle, usbd_status); -Static void usbd_do_request_async_task(void *); Static void usbd_start_next(usbd_pipe_handle pipe); Static usbd_status usbd_open_pipe_ival (usbd_interface_handle, u_int8_t, u_int8_t, usbd_pipe_handle *, int); -int +static inline int usbd_xfer_isread(usbd_xfer_handle xfer) { if (xfer->rqflags & URQ_REQUEST) @@ -232,7 +218,7 @@ usbd_open_pipe_intr(usbd_interface_handl &ipipe, ival); if (err) return (err); - xfer = usbd_alloc_xfer(iface->device, ipipe); + xfer = usbd_alloc_xfer(iface->device); if (xfer == NULL) { err = USBD_NOMEM; goto bad1; @@ -243,7 +229,7 @@ usbd_open_pipe_intr(usbd_interface_handl ipipe->repeat = 1; err = usbd_transfer(xfer); *pipe = ipipe; - if (err != USBD_IN_PROGRESS && err) + if (err != USBD_IN_PROGRESS) goto bad2; return (USBD_NORMAL_COMPLETION); @@ -283,11 +269,12 @@ usbd_status usbd_transfer(usbd_xfer_handle xfer) { usbd_pipe_handle pipe = xfer->pipe; + usb_dma_t *dmap = &xfer->dmabuf; usbd_status err; - u_int size, flags; + unsigned int size, flags; int s; - DPRINTFN(5,("usbd_transfer: xfer=%p, flags=%x, pipe=%p, running=%d\n", + DPRINTFN(5,("usbd_transfer: xfer=%p, flags=%#x, pipe=%p, running=%d\n", xfer, xfer->flags, pipe, pipe->running)); #ifdef USB_DEBUG if (usbdebug > 5) @@ -299,74 +286,47 @@ usbd_transfer(usbd_xfer_handle xfer) return (USBD_CANCELLED); size = xfer->length; - flags = xfer->flags; /* If there is no buffer, allocate one. */ - if (!(xfer->rqflags & URQ_MASK_DRV_REQUESTED_BUF) && size != 0) { + if (!(xfer->rqflags & URQ_DEV_DMABUF) && size != 0) { struct usbd_bus *bus = pipe->device->bus; #ifdef DIAGNOSTIC - if (xfer->rqflags & URQ_AUTO_BUF) + if (xfer->rqflags & URQ_AUTO_DMABUF) printf("usbd_transfer: has old buffer!\n"); - if (xfer->device->bus->intr_context) - panic("usbd_transfer: allocm not in process context"); #endif - err = bus->methods->allocm(bus, xfer, - (flags & USBD_NO_COPY) ? xfer->buffer : NULL, - size); + err = bus->methods->allocm(bus, dmap, size); if (err) return (err); - xfer->rqflags |= URQ_AUTO_BUF; + xfer->rqflags |= URQ_AUTO_DMABUF; } -#ifdef DIAGNOSTIC - if ((xfer->rqflags & URQ_MASK_DRV_REQUESTED_BUF) != 0 && - size > xfer->bufsize) { - panic("usbd_transfer: buffer size overrun size=%u bufsize=%lu rqflags=%x", - size, (unsigned long)xfer->bufsize, xfer->rqflags); - } -#endif -#ifdef DIAGNOSTIC - if ((flags & USBD_NO_COPY) == 0 && size != 0) { - if (xfer->rqflags & URQ_DEV_MAP_BUFFER) - printf("usbd_transfer: USBD_NO_COPY recommended with mapped buffer"); - if (xfer->rqflags & URQ_DEV_MAP_MBUF) - panic("usbd_transfer: USBD_NO_COPY required with mapped mbuf"); - } -#endif + flags = xfer->flags; + /* Copy data if going out. */ - if (!(flags & USBD_NO_COPY) && size != 0 && - !usbd_xfer_isread(xfer) && xfer->buffer != xfer->hcbuffer) { - DPRINTFN(5, ("usbd_transfer: copy %p (alloc) <- %p (buffer), %u bytes\n", - xfer->hcbuffer, xfer->buffer, (unsigned)size)); - memcpy(xfer->hcbuffer, xfer->buffer, size); - } + if (!(flags & USBD_NO_COPY) && size != 0 && !usbd_xfer_isread(xfer)) + memcpy(KERNADDR(dmap, 0), xfer->buffer, size); + /* xfer is not valid after the transfer method unless synchronous */ err = pipe->methods->transfer(xfer); - /* - * Note xfer may not be valid after non-error completion - * of the transfer method unless synchronous. - */ if (err != USBD_IN_PROGRESS && err) { /* The transfer has not been queued, so free buffer. */ - if (xfer->rqflags & URQ_AUTO_BUF) { + if (xfer->rqflags & URQ_AUTO_DMABUF) { struct usbd_bus *bus = pipe->device->bus; -#ifdef DIAGNOSTIC - if (bus->intr_context) - panic("usbd_transfer: freem not in process context"); -#endif - bus->methods->freem(bus, xfer, U_WAITOK); - xfer->rqflags &= ~URQ_AUTO_BUF; + bus->methods->freem(bus, &xfer->dmabuf); + xfer->rqflags &= ~URQ_AUTO_DMABUF; } } if (!(flags & USBD_SYNCHRONOUS)) - return (xfer->done ? 0 : USBD_IN_PROGRESS); + return (err); /* Sync transfer, wait for completion. */ + if (err != USBD_IN_PROGRESS) + return (err); s = splusb(); - while (!xfer->done) { + if (!xfer->done) { if (pipe->device->bus->use_polling) panic("usbd_transfer: not done"); tsleep(xfer, PRIBIO, "usbsyn", 0); @@ -389,227 +349,62 @@ usbd_alloc_buffer(usbd_xfer_handle xfer, struct usbd_bus *bus = xfer->device->bus; usbd_status err; - USB_KASSERT2((xfer->rqflags & URQ_MASK_BUF) == 0, - ("usbd_alloc_buffer: xfer already has a buffer")); - #ifdef DIAGNOSTIC - if (xfer->device->bus->intr_context) - panic("usbd_alloc_buffer: allocm not in process context"); + if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF)) + printf("usbd_alloc_buffer: xfer already has a buffer\n"); #endif - err = bus->methods->allocm(bus, xfer, NULL, size); + err = bus->methods->allocm(bus, &xfer->dmabuf, size); if (err) return (NULL); - xfer->bufsize = size; - xfer->rqflags |= URQ_DEV_BUF; - return xfer->hcbuffer; -} - -Static void -usbd_free_buffer_flag(usbd_xfer_handle xfer, enum usbd_waitflg waitflg) -{ - struct usbd_bus *bus; - - USB_KASSERT2((xfer->rqflags & URQ_MASK_BUF) == URQ_DEV_BUF, - ("usbd_free_buffer_flag: no/auto buffer")); - - xfer->rqflags &= ~(URQ_DEV_BUF | URQ_AUTO_BUF); - xfer->bufsize = 0; - bus = xfer->device->bus; -#ifdef DIAGNOSTIC - if (waitflg == U_WAITOK && bus->intr_context) - panic("usbd_free_buffer: freem not in process context"); -#endif - bus->methods->freem(bus, xfer, waitflg); - - xfer->hcbuffer = NULL; + xfer->rqflags |= URQ_DEV_DMABUF; + return (KERNADDR(&xfer->dmabuf, 0)); } void usbd_free_buffer(usbd_xfer_handle xfer) { - usbd_free_buffer_flag(xfer, U_WAITOK); -} - -void * -usbd_get_buffer(usbd_xfer_handle xfer) -{ - if (!(xfer->rqflags & URQ_DEV_BUF)) - return (NULL); - return (xfer->hcbuffer); -} - -/* - * map buffer handlings - */ - -/* Allocate mapping resources to prepare buffer mapping. */ -usbd_status -usbd_map_alloc(usbd_xfer_handle xfer) -{ - struct usbd_bus *bus = xfer->device->bus; - usbd_status err; - #ifdef DIAGNOSTIC - if (bus->intr_context) - panic("usbd_map_alloc: map_alloc not in process context"); -#endif - USB_KASSERT2((xfer->rqflags & URQ_DEV_MAP_PREPARED) == 0, - ("usbd_map_alloc: map already allocated")); - - err = bus->methods->map_alloc(xfer); - if (err != USBD_NORMAL_COMPLETION) - return (err); - - xfer->rqflags |= URQ_DEV_MAP_PREPARED; - - return (USBD_NORMAL_COMPLETION); -} - -/* Free mapping resources. */ -void -usbd_map_free(usbd_xfer_handle xfer) -{ - struct usbd_bus *bus = xfer->device->bus; - -#ifdef DIAGNOSTIC - if (bus->intr_context) - panic("usbd_map_free: map_free not in process context"); + if (!(xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF))) { + printf("usbd_free_buffer: no buffer\n"); + return; + } #endif - USB_KASSERT2((xfer->rqflags & URQ_DEV_MAP_PREPARED), - ("usbd_map_free: map not allocated")); - - bus->methods->map_free(xfer); - - xfer->rqflags &= ~URQ_DEV_MAP_PREPARED; + xfer->rqflags &= ~(URQ_DEV_DMABUF | URQ_AUTO_DMABUF); + xfer->device->bus->methods->freem(xfer->device->bus, &xfer->dmabuf); } -/* Map plain buffer. */ -void -usbd_map_buffer(usbd_xfer_handle xfer, void *buf, u_int32_t size) +void * +usbd_get_buffer(usbd_xfer_handle xfer) { - struct usbd_bus *bus = xfer->device->bus; - -#ifdef DIAGNOSTIC - if ((xfer->rqflags & URQ_MASK_BUF)) - panic("usbd_map_buffer: already has buffer (rqflags=%x)", - xfer->rqflags); - if ((xfer->rqflags & URQ_DEV_MAP_PREPARED) == 0 && bus->intr_context) - panic("usbd_map_buffer: mapm (without map_alloc) not in process context"); -#endif - - bus->methods->mapm(xfer, buf, size); - - xfer->bufsize = size; - xfer->rqflags |= URQ_DEV_MAP_BUFFER; + if (!(xfer->rqflags & URQ_DEV_DMABUF)) + return (0); + return (KERNADDR(&xfer->dmabuf, 0)); } usbd_xfer_handle -/* XXX API change */ -#if 0 usbd_alloc_xfer(usbd_device_handle dev) -#else -usbd_alloc_xfer(usbd_device_handle dev, usbd_pipe_handle pipe) -#endif -{ - return (usbd_alloc_xfer_flag(dev, pipe, U_WAITOK)); -} - -usbd_xfer_handle -usbd_alloc_default_xfer(usbd_device_handle dev) -{ - return (usbd_alloc_xfer_flag(dev, dev->default_pipe, U_WAITOK)); -} - -/* Map mbuf(9) chain. */ -usbd_status -usbd_map_buffer_mbuf(usbd_xfer_handle xfer, struct mbuf *chain) -{ - struct usbd_bus *bus = xfer->device->bus; - usbd_status err; - -#ifdef DIAGNOSTIC - if ((xfer->rqflags & URQ_MASK_BUF)) - panic("usbd_map_buffer_mbuf: already has buffer (rqflags=%x)", - xfer->rqflags); - if ((xfer->rqflags & URQ_DEV_MAP_PREPARED) == 0 && bus->intr_context) - panic("usbd_map_buffer_mbuf: mapm_mbuf (without map_alloc) not in process context"); -#endif - - err = bus->methods->mapm_mbuf(xfer, chain); - if (err != USBD_NORMAL_COMPLETION) - return (err); - - xfer->bufsize = chain->m_pkthdr.len; - xfer->mbuf_chain = chain; - xfer->rqflags |= URQ_DEV_MAP_MBUF; - - return (err); -} - -/* Unmap plain buffer or mbuf(9) chain. */ -void -usbd_unmap_buffer(usbd_xfer_handle xfer) -{ - struct usbd_bus *bus = xfer->device->bus; - - USB_KASSERT2((xfer->rqflags & (URQ_DEV_MAP_BUFFER | URQ_DEV_MAP_MBUF)), - ("usbd_unmap_buffer: no map")); -#ifdef DIAGNOSTIC - if ((xfer->rqflags & URQ_DEV_MAP_PREPARED) == 0 && bus->intr_context) - panic("usbd_unmap_buffer: unmapm (without map_alloc) not in process context"); -#endif - - bus->methods->unmapm(xfer); - - xfer->rqflags &= ~(URQ_DEV_MAP_BUFFER | URQ_DEV_MAP_MBUF); - xfer->bufsize = 0; - xfer->mbuf_chain = NULL; -} - -Static usbd_xfer_handle -usbd_alloc_xfer_flag(usbd_device_handle dev, usbd_pipe_handle pipe, - enum usbd_waitflg waitflg) { usbd_xfer_handle xfer; -#ifdef DIAGNOSTIC - if (waitflg == U_WAITOK && dev->bus->intr_context) - panic("usbd_alloc_xfer: allocx not in process context"); - if (pipe == NULL) - panic("usbd_alloc_xfer: pipe == NULL"); -#endif - xfer = dev->bus->methods->allocx(dev->bus, pipe, waitflg); + xfer = dev->bus->methods->allocx(dev->bus); if (xfer == NULL) return (NULL); - xfer->pipe = pipe; xfer->device = dev; usb_callout_init(xfer->timeout_handle); - DPRINTFN(5,("usbd_alloc_xfer_flag() = %p\n", xfer)); + DPRINTFN(5,("usbd_alloc_xfer() = %p\n", xfer)); return (xfer); } usbd_status usbd_free_xfer(usbd_xfer_handle xfer) { - - return (usbd_free_xfer_flag(xfer, U_WAITOK)); -} - -Static usbd_status -usbd_free_xfer_flag(usbd_xfer_handle xfer, enum usbd_waitflg waitflg) -{ - DPRINTFN(5,("usbd_free_xfer_flag: %p %d\n", xfer, waitflg)); - usb_rem_task(xfer->device, &xfer->task); - if (xfer->rqflags & (URQ_DEV_BUF | URQ_AUTO_BUF)) - usbd_free_buffer_flag(xfer, waitflg); - if (xfer->rqflags & (URQ_DEV_MAP_BUFFER | URQ_DEV_MAP_MBUF)) - usbd_unmap_buffer(xfer); - if (waitflg == U_WAITOK && (xfer->rqflags & URQ_DEV_MAP_PREPARED)) - usbd_map_free(xfer); + DPRINTFN(5,("usbd_free_xfer: %p\n", xfer)); + if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF)) + usbd_free_buffer(xfer); #if defined(__NetBSD__) && defined(DIAGNOSTIC) if (callout_pending(&xfer->timeout_handle)) { callout_stop(&xfer->timeout_handle); - printf("usbd_free_xfer_flag: timout_handle pending"); + printf("usbd_free_xfer: timout_handle pending"); } #endif xfer->device->bus->methods->freex(xfer->device->bus, xfer); @@ -622,7 +417,7 @@ usbd_setup_xfer(usbd_xfer_handle xfer, u u_int16_t flags, u_int32_t timeout, usbd_callback callback) { - USB_KASSERT(xfer->pipe == pipe); /* XXX pipe arg should go */ + xfer->pipe = pipe; xfer->priv = priv; xfer->buffer = buffer; xfer->length = length; @@ -642,7 +437,7 @@ usbd_setup_default_xfer(usbd_xfer_handle u_int32_t length, u_int16_t flags, usbd_callback callback) { - USB_KASSERT(xfer->pipe == dev->default_pipe); /* XXX */ + xfer->pipe = dev->default_pipe; xfer->priv = priv; xfer->buffer = buffer; xfer->length = length; @@ -661,14 +456,10 @@ usbd_setup_isoc_xfer(usbd_xfer_handle xf usbd_private_handle priv, u_int16_t *frlengths, u_int32_t nframes, u_int16_t flags, usbd_callback callback) { - int i; - - USB_KASSERT(xfer->pipe == pipe); /* XXX pipe arg should go */ + xfer->pipe = pipe; xfer->priv = priv; xfer->buffer = 0; xfer->length = 0; - for (i = 0; i < nframes; i++) - xfer->length += frlengths[i]; xfer->actlen = 0; xfer->flags = flags; xfer->timeout = USBD_NO_TIMEOUT; @@ -705,12 +496,6 @@ usbd_get_config_descriptor(usbd_device_h return (dev->cdesc); } -int -usbd_get_speed(usbd_device_handle dev) -{ - return (dev->speed); -} - usb_interface_descriptor_t * usbd_get_interface_descriptor(usbd_interface_handle iface) { @@ -738,12 +523,6 @@ usbd_interface2endpoint_descriptor(usbd_ } usbd_status -usbd_abort_default_pipe(usbd_device_handle device) -{ - return usbd_abort_pipe(device->default_pipe); -} - -usbd_status usbd_abort_pipe(usbd_pipe_handle pipe) { usbd_status err; @@ -751,7 +530,7 @@ usbd_abort_pipe(usbd_pipe_handle pipe) #ifdef DIAGNOSTIC if (pipe == NULL) { - printf("usbd_abort_pipe: pipe==NULL\n"); + printf("usbd_close_pipe: pipe==NULL\n"); return (USBD_NORMAL_COMPLETION); } #endif @@ -957,8 +736,6 @@ usbd_ar_pipe(usbd_pipe_handle pipe) pipe, xfer, pipe->methods)); /* Make the HC abort it (and invoke the callback). */ pipe->methods->abort(xfer); - USB_KASSERT2(SIMPLEQ_FIRST(&pipe->queue) != xfer, - ("usbd_ar_pipe")); /* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */ } pipe->aborting = 0; @@ -970,6 +747,7 @@ void usb_transfer_complete(usbd_xfer_handle xfer) { usbd_pipe_handle pipe = xfer->pipe; + usb_dma_t *dmap = &xfer->dmabuf; int sync = xfer->flags & USBD_SYNCHRONOUS; int erred = xfer->status == USBD_CANCELLED || xfer->status == USBD_TIMEOUT; @@ -988,7 +766,7 @@ usb_transfer_complete(usbd_xfer_handle x #ifdef DIAGNOSTIC if (pipe == NULL) { - printf("usb_transfer_complete: pipe==0, xfer=%p\n", xfer); + printf("usbd_transfer_cb: pipe==0, xfer=%p\n", xfer); return; } #endif @@ -1007,37 +785,26 @@ usb_transfer_complete(usbd_xfer_handle x xfer->actlen = xfer->length; } #endif - /* Copy data if it is not already in the correct buffer. */ - if (!(xfer->flags & USBD_NO_COPY) && xfer->hcbuffer != NULL) { - DPRINTFN(5, ("usb_transfer_complete: copy %p (buffer) <- %p (alloc), %u bytes\n", - xfer->buffer, xfer->hcbuffer, (unsigned)xfer->actlen)); -#ifdef DIAGNOSTIC - if ((xfer->rqflags & (URQ_AUTO_BUF | URQ_DEV_BUF)) == 0) - panic("usb_transfer_complete: USBD_NO_COPY required with mapped buffer"); -#endif - memcpy(xfer->buffer, xfer->hcbuffer, xfer->actlen); - } + memcpy(xfer->buffer, KERNADDR(dmap, 0), xfer->actlen); } - /* - * if we allocated or mapped the buffer in usbd_transfer() - * we unmap it here. - */ - if (xfer->rqflags & URQ_AUTO_BUF) { + /* if we allocated the buffer in usbd_transfer() we free it here. */ + if (xfer->rqflags & URQ_AUTO_DMABUF) { if (!repeat) { struct usbd_bus *bus = pipe->device->bus; - bus->methods->freem(bus, xfer, U_NOWAIT); - xfer->rqflags &= ~URQ_AUTO_BUF; + bus->methods->freem(bus, dmap); + xfer->rqflags &= ~URQ_AUTO_DMABUF; } } if (!repeat) { /* Remove request from queue. */ #ifdef DIAGNOSTIC + if (xfer != SIMPLEQ_FIRST(&pipe->queue)) + printf("usb_transfer_complete: bad dequeue %p != %p\n", + xfer, SIMPLEQ_FIRST(&pipe->queue)); xfer->busy_free = XFER_BUSY; #endif - USB_KASSERT2(SIMPLEQ_FIRST(&pipe->queue) == xfer, - ("usb_transfer_complete: bad dequeue")); SIMPLEQ_REMOVE_HEAD(&pipe->queue, next); } DPRINTFN(5,("usb_transfer_complete: repeat=%d new head=%p\n", @@ -1055,31 +822,17 @@ usb_transfer_complete(usbd_xfer_handle x xfer->status = USBD_SHORT_XFER; } - /* - * For repeat operations, call the callback first, as the xfer - * will not go away and the "done" method may modify it. Otherwise - * reverse the order in case the callback wants to free or reuse - * the xfer. - */ - if (repeat) { - if (xfer->callback) - xfer->callback(xfer, xfer->priv, xfer->status); - pipe->methods->done(xfer); - } else { + if (xfer->callback) + xfer->callback(xfer, xfer->priv, xfer->status); + +#ifdef DIAGNOSTIC + if (pipe->methods->done != NULL) pipe->methods->done(xfer); - if (xfer->callback) { - if (xfer->flags & USBD_CALLBACK_AS_TASK) { - /* - * Callback as a task (in thread context). - */ - usb_init_task(&xfer->task, usbd_callback_task, - xfer); - usb_add_task(xfer->device, &xfer->task, - USB_TASKQ_DRIVER); - } else - xfer->callback(xfer, xfer->priv, xfer->status); - } - } + else + printf("usb_transfer_complete: pipe->methods->done == NULL\n"); +#else + pipe->methods->done(xfer); +#endif if (sync && !polling) wakeup(xfer); @@ -1093,14 +846,6 @@ usb_transfer_complete(usbd_xfer_handle x } } -Static void -usbd_callback_task(void *arg) -{ - usbd_xfer_handle xfer = arg; - - xfer->callback(xfer, xfer->priv, xfer->status); -} - usbd_status usb_insert_transfer(usbd_xfer_handle xfer) { @@ -1119,8 +864,6 @@ usb_insert_transfer(usbd_xfer_handle xfe xfer->busy_free = XFER_ONQU; #endif s = splusb(); - USB_KASSERT2(SIMPLEQ_FIRST(&pipe->queue) != xfer, - ("usb_insert_transfer")); SIMPLEQ_INSERT_TAIL(&pipe->queue, xfer, next); if (pipe->running) err = USBD_IN_PROGRESS; @@ -1192,22 +935,20 @@ usbd_do_request_flags_pipe(usbd_device_h #ifdef DIAGNOSTIC #if defined(__i386__) && defined(__FreeBSD__) - KASSERT(curthread->td_intr_nesting_level == 0, + KASSERT(intr_nesting_level == 0, ("usbd_do_request: in interrupt context")); #endif if (dev->bus->intr_context) { - panic("usbd_do_request: not in process context"); + printf("usbd_do_request: not in process context\n"); + return (USBD_INVAL); } #endif - xfer = usbd_alloc_xfer(dev, pipe); + xfer = usbd_alloc_xfer(dev); if (xfer == NULL) return (USBD_NOMEM); - xfer->pipe = dev->default_pipe; /* XXX */ - /* XXX */ usbd_setup_default_xfer(xfer, dev, 0, timeout, req, data, UGETW(req->wLength), flags, 0); - /* XXX */ xfer->pipe = pipe; err = usbd_sync_transfer(xfer); #if defined(USB_DEBUG) || defined(DIAGNOSTIC) @@ -1282,7 +1023,7 @@ usbd_do_request_async_cb(usbd_xfer_handl xfer->length, xfer->actlen)); } #endif - usbd_free_xfer_flag(xfer, U_NOWAIT); + usbd_free_xfer(xfer); } /* @@ -1294,33 +1035,19 @@ usbd_do_request_async(usbd_device_handle void *data) { usbd_xfer_handle xfer; + usbd_status err; - xfer = usbd_alloc_xfer_flag(dev, dev->default_pipe, U_NOWAIT); + xfer = usbd_alloc_xfer(dev); if (xfer == NULL) return (USBD_NOMEM); usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, req, data, UGETW(req->wLength), 0, usbd_do_request_async_cb); - - /* - * Request will be processed later as a task (in thread context). - */ - usb_init_task(&xfer->task, usbd_do_request_async_task, xfer); - usb_add_task(dev, &xfer->task, USB_TASKQ_HC); - - return (USBD_IN_PROGRESS); -} - -Static void -usbd_do_request_async_task(void *arg) -{ - usbd_xfer_handle xfer = arg; - usbd_status err; - - /* XXX impossible to notify caller the error */ err = usbd_transfer(xfer); - if (err != USBD_IN_PROGRESS && err) { + if (err != USBD_IN_PROGRESS) { usbd_free_xfer(xfer); + return (err); } + return (USBD_NORMAL_COMPLETION); } const struct usbd_quirks * @@ -1382,16 +1109,9 @@ usbd_get_endpoint_descriptor(usbd_interf int usbd_ratecheck(struct timeval *last) { -#if defined(__NetBSD__) static struct timeval errinterval = { 0, 250000 }; /* 0.25 s*/ return (ratecheck(last, &errinterval)); -#elif defined(__FreeBSD__) - if (last->tv_sec == time_second) - return (0); - last->tv_sec = time_second; - return (1); -#endif } /* @@ -1493,7 +1213,7 @@ usbd_get_string0(usbd_device_handle dev, } *s++ = 0; } -#if defined(__NetBSD__) && defined(COMPAT_30) +#ifdef COMPAT_30 else { for (i = 0; i < n; i++) { c = UGETW(us.bString[i]);