PERFORCE change 107765 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Thu Oct 12 09:11:05 PDT 2006
http://perforce.freebsd.org/chv.cgi?CH=107765
Change 107765 by hselasky at hselasky_mini_itx on 2006/10/12 16:09:11
Remove the compatibility layer for the old USB drivers,
hence no USB device drivers in the tree are using it.
If you have a driver that still uses the old USB API
I recommend that you update your code.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/usb_port.h#11 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_requests.c#4 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.c#20 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#24 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_transfer.c#18 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/usb_port.h#11 (text+ko) ====
@@ -224,11 +224,6 @@
SYSCTL_DECL(_hw_usb);
#endif
-#if 0
-/* enable support for the old USB interface: */
-#define USB_COMPAT_OLD
-#endif
-
/* force debugging until further */
#ifndef USB_DEBUG
#define USB_DEBUG
@@ -295,163 +290,4 @@
*/
#define msleep(i,m,p,w,t) msleep(i,(((m) == &Giant) ? NULL : (m)),p,w,t)
-#ifdef USB_COMPAT_OLD
-
-/*
- * NOTE: All macros in this section
- * should be expanded in new drivers.
- * One day USB_COMPAT_OLD will
- * be undefined!
- */
-
-typedef struct thread *usb_proc_ptr;
-
-#define device_ptr_t device_t
-#define USBBASEDEVICE device_t
-#define USBDEV(bdev) (bdev)
-#define USBDEVNAME(bdev) device_get_nameunit(bdev)
-#define USBDEVPTRNAME(bdev) device_get_nameunit(bdev)
-#define USBDEVUNIT(bdev) device_get_unit(bdev)
-#define USBGETSOFTC(bdev) device_get_softc(bdev)
-#define USB_DNAME(dname) dname
-
-typedef struct __callout usb_callout_t;
-#define usb_callout_init(h) __callout_init_mtx(&(h), &Giant, 0)
-#define usb_callout(h, t, f, d) __callout_reset(&(h), (t), (f), (d))
-#define usb_uncallout(h, f, d) __callout_stop(&(h))
-#define usb_uncallout_drain(h, f, d) __callout_stop(&(h))
-
-#define USB_DECLARE_DRIVER_INIT(dname, init...) \
- Static device_probe_t __CONCAT(dname,_match); \
- Static device_attach_t __CONCAT(dname,_attach); \
- Static device_detach_t __CONCAT(dname,_detach); \
- \
- Static devclass_t __CONCAT(dname,_devclass); \
- \
- Static device_method_t __CONCAT(dname,_methods)[] = { \
- DEVMETHOD(device_probe, __CONCAT(dname,_match)), \
- DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \
- DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \
- init, \
- {0,0} \
- }; \
- \
- Static driver_t __CONCAT(dname,_driver) = { \
- #dname, \
- __CONCAT(dname,_methods), \
- sizeof(struct __CONCAT(dname,_softc)) \
- }; \
- MODULE_DEPEND(dname, usb, 1, 1, 1)
-
-#define METHODS_NONE \
- {0,0}
-
-#define USB_DECLARE_DRIVER(dname) \
- USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE)
-
-#define USB_MATCH(dname) \
- Static int \
- __CONCAT(dname,_match)(device_t self)
-
-#define USB_MATCH_START(dname, uaa) \
- struct usb_attach_arg *uaa = device_get_ivars(self)
-
-#define USB_MATCH_SETUP \
- sc->sc_dev = self
-
-#define USB_ATTACH(dname) \
- Static int \
- __CONCAT(dname,_attach)(device_t self)
-
-#define USB_ATTACH_START(dname, sc, uaa) \
- struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \
- struct usb_attach_arg *uaa = device_get_ivars(self)
-
-#define USB_ATTACH_SETUP \
- sc->sc_dev = self; \
- device_set_desc_copy(self, devinfo)
-
-#define USB_ATTACH_ERROR_RETURN \
- return ENXIO
-
-#define USB_ATTACH_SUCCESS_RETURN \
- return 0
-
-#define USB_DETACH(dname) \
- Static int \
- __CONCAT(dname,_detach)(device_t self)
-
-#define USB_DETACH_START(dname, sc) \
- struct __CONCAT(dname,_softc) *sc = device_get_softc(self)
-
-#define USB_GET_SC_OPEN(dname, unit, sc) \
- (sc) = devclass_get_softc(__CONCAT(dname,_devclass), unit); \
- if ((sc) == NULL) \
- return (ENXIO)
-
-#define USB_GET_SC(dname, unit, sc) \
- (sc) = devclass_get_softc(__CONCAT(dname,_devclass), unit)
-
-#define USBD_IN_PROGRESS USBD_NORMAL_COMPLETION
-#define USBD_NO_COPY 0
-#define USBD_EXCLUSIVE_USE 0
-#define USBD_SHOW_INTERFACE_CLASS 0
-#define splusb splbio
-#define usb_find_desc(udev, type, subtype) usbd_find_descriptor(usbd_get_config_descriptor(udev), type, subtype)
-#define usbd_get_desc usbreq_get_desc
-#define usbd_get_string(udev, si, ptr) usbreq_get_string_any(udev, si, ptr, USB_MAX_STRING_LEN)
-#define usbd_get_string_desc usbreq_get_string_desc
-#define usbd_get_config_desc usbreq_get_config_desc
-#define usbd_get_config_desc_full usbreq_get_config_desc_full
-#define usbd_get_device_desc usbreq_get_device_desc
-#define usbd_get_interface(iface,args...) usbreq_get_interface((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_set_interface(iface,args...) usbreq_set_interface((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_get_device_status usbreq_get_device_status
-#define usbd_get_hub_descriptor usbreq_get_hub_descriptor
-#define usbd_get_hub_status usbreq_get_hub_status
-#define usbd_set_address usbreq_set_address
-#define usbd_get_port_status usbreq_get_port_status
-#define usbd_clear_hub_feature usbreq_clear_hub_feature
-#define usbd_set_hub_feature usbreq_set_hub_feature
-#define usbd_clear_port_feature usbreq_clear_port_feature
-#define usbd_set_port_feature usbreq_set_port_feature
-#define usbd_set_protocol(iface,args...) usbreq_set_protocol((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_set_report(iface,args...) usbreq_set_report((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_set_report_async(iface,args...) usbreq_set_report_async((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_get_report(iface,args...) usbreq_get_report((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_set_idle(iface,args...) usbreq_set_idle((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_get_report_descriptor usbreq_get_report_descriptor
-#define usbd_read_report_desc(iface,args...) usbreq_read_report_desc((iface)->udev, (iface) - &(iface)->udev->ifaces[0], args)
-#define usbd_set_config usbreq_set_config
-#define usbd_get_config usbreq_get_config
-#define usbd_dopoll(iface) usbd_do_poll((iface)->udev)
-#define ifaceno iface_index /* umass.c */
-#define usbd_do_request_async(udev, req, data) \
-usbd_do_request_flags(udev, req, data, USBD_USE_POLLING, 0, 500 /* ms */)
-
-/*
- * depreciated Giant locked task-queue
- * (only used by if_udav.c)
- */
-struct usb_task {
-
-#ifdef __FreeBSD__
- struct task task;
-#endif
- void (*func)(void *);
- void *arg;
-};
-
-void
-usb_call_task(void *arg, int count);
-
-#define usb_init_task(_task, _func, _arg) \
-{ (_task)->func = (_func); (_task)->arg = (_arg); \
- TASK_INIT(&(_task)->task, 0, &usb_call_task, (_task)); }
-#define usb_add_task(udev, _task) \
-taskqueue_enqueue(taskqueue_swi_giant, &(_task)->task)
-#define usb_rem_task(udev, _task) \
-taskqueue_drain(taskqueue_swi_giant, &(_task)->task)
-
-#endif /* USB_COMPAT_OLD */
#endif /* _USB_PORT_H */
==== //depot/projects/usb/src/sys/dev/usb/usb_requests.c#4 (text+ko) ====
@@ -477,40 +477,6 @@
return (usbd_do_request(udev, &req, 0));
}
-#ifdef USB_COMPAT_OLD
-usbd_status
-usbreq_set_report_async(struct usbd_device *udev, u_int8_t iface_index,
- u_int8_t type, u_int8_t id, void *data, int len)
-{
- struct usbd_interface *iface = usbd_get_iface(udev,iface_index);
- usb_device_request_t req;
-
- if((iface == NULL) || (iface->idesc == NULL))
- {
- return (USBD_INVAL);
- }
- /* this function call should be replaced by an allocated
- * transfer that is started when a transfer is needed, and
- * stopped when the device is detached. This implementation
- * use polling because it may be called from an interrupt
- * context.
- */
-
- PRINTF(("this function is depreceated"));
-
- PRINTFN(4, ("len=%d\n", len));
-
- req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
- req.bRequest = UR_SET_REPORT;
- USETW2(req.wValue, type, id);
- USETW(req.wIndex, iface->idesc->bInterfaceNumber);
- USETW(req.wLength, len);
-
- return (usbd_do_request_flags
- (udev, &req, data, USBD_USE_POLLING, 0, 500 /* ms */));
-}
-#endif
-
usbd_status
usbreq_set_report(struct usbd_device *udev, u_int8_t iface_index,
u_int8_t type, u_int8_t id, void *data, int len)
==== //depot/projects/usb/src/sys/dev/usb/usb_subr.c#20 (text+ko) ====
@@ -402,9 +402,7 @@
usb_endpoint_descriptor_t *edesc, struct usbd_pipe *pipe)
{
bzero(pipe, sizeof(*pipe));
-#ifdef USB_COMPAT_OLD
- pipe->udev = udev;
-#endif
+
pipe->edesc = edesc;
pipe->iface_index = iface_index;
LIST_INIT(&pipe->list_head);
@@ -481,9 +479,6 @@
{
return (USBD_INVAL);
}
-#ifdef USB_COMPAT_OLD
- iface->udev = udev;
-#endif
iface->idesc = id;
iface->alt_index = alt_index;
@@ -990,17 +985,7 @@
uaa.configno = udev->cdesc->bConfigurationValue;
uaa.ifaces_start = &udev->ifaces[0];
uaa.ifaces_end = &udev->ifaces[udev->cdesc->bNumInterface];
-#ifdef USB_COMPAT_OLD
- uaa.nifaces = udev->cdesc->bNumInterface;
- for(i = 0; i < uaa.nifaces; i++)
- {
- if(USBD_GET_IFACE_NO_PROBE(udev, i))
- uaa.ifaces[i] = NULL;
- else
- uaa.ifaces[i] = &udev->ifaces[i];
- }
-#endif
for(iface = uaa.ifaces_start;
iface < uaa.ifaces_end;
iface++)
@@ -1015,9 +1000,7 @@
"Too many subdevices\n");
break;
}
-#ifdef USB_COMPAT_OLD
- if(uaa.ifaces[i])
-#endif
+
if((USBD_GET_IFACE_NO_PROBE(udev, i) == 0) &&
(udev->subdevs[i] == NULL) &&
(device_probe_and_attach(bdev) == 0))
@@ -1045,20 +1028,6 @@
if(udev->probed == USBD_PROBED_IFACE_AND_FOUND)
{
-#ifdef USB_COMPAT_OLD
- uaa.nifaces = udev->cdesc->bNumInterface;
-
- for(i = 0; i < uaa.nifaces; i++)
- {
- /* mark ifaces that should
- * not be probed
- */
- if(uaa.ifaces[i] == NULL)
- {
- USBD_SET_IFACE_NO_PROBE(udev, i);
- }
- }
-#endif
break;
}
}
==== //depot/projects/usb/src/sys/dev/usb/usb_subr.h#24 (text+ko) ====
@@ -86,14 +86,6 @@
typedef u_int8_t usbd_status;
typedef void (*usbd_callback_t)(struct usbd_xfer *);
-#ifdef USB_COMPAT_OLD
-typedef void (*usbd_callback)(struct usbd_xfer *, void *, usbd_status);
-typedef struct usbd_xfer *usbd_xfer_handle;
-typedef struct usbd_device *usbd_device_handle;
-typedef struct usbd_pipe *usbd_pipe_handle;
-typedef struct usbd_interface *usbd_interface_handle;
-typedef void *usbd_private_handle;
-#endif
struct usbd_bus_methods {
void (*pipe_init)(struct usbd_device *udev,
@@ -203,9 +195,6 @@
};
struct usbd_interface {
-#ifdef USB_COMPAT_OLD
- struct usbd_device *udev;
-#endif
usb_interface_descriptor_t *idesc;
u_int8_t alt_index;
};
@@ -214,10 +203,6 @@
(pipe)->clearstall = 0; (pipe)->toggle_next = 0; }
struct usbd_pipe {
-#ifdef USB_COMPAT_OLD
- struct usbd_device * udev;
- struct usbd_xfer * alloc_xfer;
-#endif
usb_endpoint_descriptor_t *edesc;
LIST_HEAD(, usbd_xfer) list_head;
u_int16_t isoc_next;
@@ -315,12 +300,10 @@
* flag is also exported by usb.h
*/
#endif
-#if (defined(USB_COMPAT_OLD) || 1)
#define USBD_CUSTOM_CLEARSTALL 0x0008 /* used to disable automatic clear-stall
* when a device reset request is needed
* in addition to the clear stall request
*/
-#endif
#define USBD_DEV_OPEN 0x0010
#define USBD_DEV_RECURSED_1 0x0020
#define USBD_DEV_RECURSED_2 0x0040
@@ -407,22 +390,6 @@
void *td_transfer_first;
void *td_transfer_last;
void *td_transfer_cache;
-
-#ifdef USB_COMPAT_OLD
- struct usbd_xfer * alloc_xfer; /* the real transfer */
- void * alloc_ptr;
- u_int32_t alloc_len;
- void * d_copy_ptr;
- void * d_copy_src;
- void * d_copy_dst;
- u_int32_t d_copy_len;
- usbd_callback d_callback;
-
- void * f_copy_ptr;
- void * f_copy_src;
- void * f_copy_dst;
- u_int32_t f_copy_len;
-#endif
};
struct usbd_memory_info {
@@ -570,10 +537,6 @@
int usegeneric;
struct usbd_interface *ifaces_start; /* all interfaces */
struct usbd_interface *ifaces_end; /* exclusive */
-#ifdef USB_COMPAT_OLD
- int nifaces;
- struct usbd_interface * ifaces[USB_MAX_ENDPOINTS];
-#endif
};
/* return values for device_probe() method: */
@@ -936,101 +899,6 @@
int
usbd_driver_load(struct module *mod, int what, void *arg);
-#ifdef USB_COMPAT_OLD
-usbd_status
-usbd_transfer(struct usbd_xfer *xfer);
-
-usbd_status
-usbd_sync_transfer(struct usbd_xfer *xfer);
-
-void *
-usbd_alloc_buffer(struct usbd_xfer *xfer, u_int32_t size);
-
-void
-usbd_free_buffer(struct usbd_xfer *xfer);
-
-void
-usbd_get_xfer_status(struct usbd_xfer *xfer, void **priv,
- void **buffer, u_int32_t *count, usbd_status *status);
-
-struct usbd_xfer *
-usbd_alloc_xfer(struct usbd_device *dev);
-
-usbd_status
-usbd_free_xfer(struct usbd_xfer *xfer);
-
-usbd_status
-usbd_open_pipe(struct usbd_interface *iface, u_int8_t address,
- u_int8_t flags, struct usbd_pipe **pipe);
-
-usbd_status
-usbd_open_pipe_intr(struct usbd_interface *iface, u_int8_t address,
- u_int8_t flags, struct usbd_pipe **pipe,
- void *priv, void *buffer, u_int32_t len,
- usbd_callback callback, int ival);
-
-usbd_status
-usbd_setup_xfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- void *priv, void *buffer, u_int32_t length,
- u_int32_t flags, u_int32_t timeout,
- usbd_callback callback);
-
-usbd_status
-usbd_setup_default_xfer(struct usbd_xfer *xfer, struct usbd_device *dev,
- void *priv, u_int32_t timeout,
- usb_device_request_t *req, void *buffer,
- u_int32_t length, u_int16_t flags,
- usbd_callback callback);
-
-usbd_status
-usbd_setup_isoc_xfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- void *priv, u_int16_t *frlengths, u_int32_t nframes,
- u_int16_t flags, usbd_callback callback);
-
-usbd_status
-usbd_bulk_transfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- u_int16_t flags, u_int32_t timeout, void *buf,
- u_int32_t *size, char *lbl);
-
-#define usbd_intr_transfer usbd_bulk_transfer
-
-usbd_status
-usbd_abort_pipe(struct usbd_pipe *pipe);
-
-usbd_status
-usbd_abort_default_pipe(struct usbd_device *udev);
-
-usbd_status
-usbd_close_pipe(struct usbd_pipe *pipe);
-
-usbd_status
-usbd_clear_endpoint_stall(struct usbd_pipe *pipe);
-
-usbd_status
-usbd_clear_endpoint_stall_async(struct usbd_pipe *pipe);
-
-usbd_status
-usbd_endpoint_count(struct usbd_interface *iface, u_int8_t *count);
-
-void
-usbd_interface2device_handle(struct usbd_interface *iface,
- struct usbd_device **udev);
-
-struct usbd_device *
-usbd_pipe2device_handle(struct usbd_pipe *pipe);
-
-usbd_status
-usbd_device2interface_handle(struct usbd_device *udev,
- u_int8_t iface_index, struct usbd_interface **iface);
-
-usb_endpoint_descriptor_t *
-usbd_interface2endpoint_descriptor(struct usbd_interface *iface, u_int8_t index);
-
-usb_endpoint_descriptor_t *
-usbd_get_endpoint_descriptor(struct usbd_interface *iface, u_int8_t address);
-
-#endif /* USB_COMPAT_OLD */
-
/* routines from usb_requests.c */
usbd_status
@@ -1096,12 +964,6 @@
usbreq_set_protocol(struct usbd_device *udev, u_int8_t iface_index,
u_int16_t report);
-#ifdef USB_COMPAT_OLD
-usbd_status
-usbreq_set_report_async(struct usbd_device *udev, u_int8_t iface_index,
- u_int8_t type, u_int8_t id, void *data, int len);
-#endif
-
usbd_status
usbreq_set_report(struct usbd_device *udev, u_int8_t iface_index,
u_int8_t type, u_int8_t id, void *data, int len);
==== //depot/projects/usb/src/sys/dev/usb/usb_transfer.c#18 (text+ko) ====
@@ -680,18 +680,6 @@
}
else
{
-#ifdef USB_COMPAT_OLD
- if(xfer->d_copy_src)
- {
- bcopy(xfer->d_copy_src, xfer->d_copy_ptr,
- xfer->d_copy_len);
- }
- if(xfer->f_copy_src)
- {
- bcopy(xfer->f_copy_src, xfer->f_copy_ptr,
- xfer->f_copy_len);
- }
-#endif
if(!(xfer->flags & USBD_USE_DMA)) {
/* copy in data */
(xfer->pipe->methods->copy_in)(xfer);
@@ -1111,33 +1099,6 @@
{
wakeup(xfer);
}
-
-#ifdef USB_COMPAT_OLD
-
- if(xfer->d_copy_dst)
- {
- bcopy(xfer->d_copy_ptr, xfer->d_copy_dst, xfer->d_copy_len);
- }
-
- if(xfer->f_copy_dst)
- {
- bcopy(xfer->f_copy_ptr, xfer->f_copy_dst, xfer->f_copy_len);
- }
-
- if(xfer->d_callback)
- {
- PRINTFN(3,("xfer=%p, error=0x%x(%s)\n", xfer,
- xfer->error, usbd_errstr(xfer->error)));
-
- (xfer->d_callback)(xfer->priv_fifo, xfer->priv_sc, xfer->error);
-
- if(((void *)(xfer->pipe->alloc_xfer)) == xfer->priv_fifo)
- {
- /* restart transfer */
- usbd_start_hardware(xfer);
- }
- }
-#endif
return;
}
@@ -1447,597 +1408,3 @@
return (0);
}
-
-#ifdef USB_COMPAT_OLD
-
-/*****************************************************************************
- * compatibility layer for the old USB drivers
- *****************************************************************************/
-
-usbd_status
-usbd_transfer(struct usbd_xfer *xfer)
-{
- if(xfer->alloc_xfer)
- {
- usbd_transfer_start_safe(xfer->alloc_xfer);
- return USBD_NORMAL_COMPLETION;
- }
- else
- {
- return USBD_NOMEM;
- }
-}
-
-usbd_status
-usbd_sync_transfer(struct usbd_xfer *xfer)
-{
- if(xfer->alloc_xfer)
- {
- /* XXX USBD_SYNCHRONOUS should be set in struct usbd_config
- * passed to usbd_transfer_setup (!)
- */
- xfer->alloc_xfer->flags |= USBD_SYNCHRONOUS;
- }
- return usbd_transfer(xfer);
-}
-
-void *
-usbd_alloc_buffer(struct usbd_xfer *xfer, u_int32_t size)
-{
- if(xfer->alloc_ptr)
- {
- printf("%s: buffer already "
- "allocated\n", __FUNCTION__);
- return NULL;
- }
-
- xfer->alloc_ptr = malloc(size, M_USBDEV, M_NOWAIT);
- xfer->alloc_len = size;
-
- return xfer->alloc_ptr;
-}
-
-void
-usbd_free_buffer(struct usbd_xfer *xfer)
-{
- if(xfer->alloc_ptr)
- {
- free(xfer->alloc_ptr, M_USBDEV);
- xfer->alloc_ptr = NULL;
- }
- return;
-}
-
-void
-usbd_get_xfer_status(struct usbd_xfer *xfer, void **priv,
- void **buffer, u_int32_t *count, usbd_status *status)
-{
- PRINTFN(8, ("\n"));
-
- if(xfer->alloc_xfer)
- {
- if(priv != NULL)
- *priv = xfer->alloc_xfer->priv_sc;
- if(buffer != NULL)
- *buffer = xfer->alloc_xfer->buffer;
- if(count != NULL)
- *count = xfer->alloc_xfer->actlen;
- if(status != NULL)
- *status = xfer->alloc_xfer->error;
- }
- else
- {
- if(priv != NULL)
- *priv = xfer->priv_sc;
- if(buffer != NULL)
- *buffer = xfer->buffer;
- if(count != NULL)
- *count = xfer->actlen;
- if(status != NULL)
- *status = xfer->error;
- }
- return;
-}
-
-struct usbd_xfer *
-usbd_alloc_xfer(struct usbd_device *dev)
-{
- struct usbd_xfer *xfer;
-
- xfer = malloc(sizeof(*xfer), M_USBDEV, M_NOWAIT);
-
- if(xfer)
- {
- bzero(xfer, sizeof(*xfer));
- }
- return xfer;
-}
-
-static void
-__usbd_free_xfer(struct usbd_xfer *xfer)
-{
- if(xfer)
- {
- if(xfer->clearstall_xfer)
- {
- usbd_transfer_unsetup(&xfer->clearstall_xfer, 1);
- }
- usbd_transfer_unsetup(&xfer, 1);
- }
- return;
-}
-
-usbd_status
-usbd_free_xfer(struct usbd_xfer *xfer)
-{
- if(xfer)
- {
- usbd_free_buffer(xfer);
-
- __usbd_free_xfer(xfer->alloc_xfer);
-
- free(xfer, M_USBDEV);
- }
- return USBD_NORMAL_COMPLETION;
-}
-
-usbd_status
-usbd_open_pipe(struct usbd_interface *iface, u_int8_t address,
- u_int8_t flags, struct usbd_pipe **pp)
-{
- u_int8_t iface_index = iface - &iface->udev->ifaces[0];
- struct usbd_pipe *pipe = &iface->udev->pipes[0];
- struct usbd_pipe *pipe_end = &iface->udev->pipes_end[0];
-
- while(pipe < pipe_end)
- {
- if((pipe->iface_index == iface_index) &&
- (pipe->edesc) &&
- (pipe->edesc->bEndpointAddress == address))
- {
- (*pp) = pipe;
- return USBD_NORMAL_COMPLETION;
- }
- pipe++;
- }
- (*pp) = NULL;
- return USBD_INVAL;
-}
-
-usbd_status
-usbd_open_pipe_intr(struct usbd_interface *iface, u_int8_t address,
- u_int8_t flags, struct usbd_pipe **pipe,
- void *priv, void *buffer, u_int32_t len,
- usbd_callback callback, int ival)
-{
- usbd_status error;
-
- if(usbd_open_pipe(iface, address, 0, pipe))
- {
- return USBD_INVAL;
- }
-
- if((*pipe)->alloc_xfer)
- {
- printf("%s: warning: pipe already opened\n",
- __FUNCTION__);
- }
-
- (*pipe)->alloc_xfer = usbd_alloc_xfer(NULL);
-
- if(!(*pipe)->alloc_xfer)
- {
- return USBD_NOMEM;
- }
-
- error = usbd_setup_xfer((*pipe)->alloc_xfer, *pipe, priv, buffer, len, flags,
- USBD_NO_TIMEOUT, callback);
- if(error == 0)
- {
- error = usbd_transfer((*pipe)->alloc_xfer);
- }
- if(error)
- {
- usbd_free_xfer((*pipe)->alloc_xfer);
- (*pipe)->alloc_xfer = 0;
- *pipe = NULL;
- }
- return error;
-}
-
-usbd_status
-usbd_setup_xfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- void *priv, void *buffer, u_int32_t length,
- u_int32_t flags, u_int32_t timeout,
- usbd_callback callback)
-{
- struct usbd_config usbd_config[2] = { /* zero */ };
- struct usbd_xfer *__xfer[2];
-
- /* free current transfer, if any */
- if(xfer->alloc_xfer)
- {
- if(xfer->alloc_xfer->flags & USBD_DEV_TRANSFERRING)
- {
- /* transfer is in progress */
- PRINTFN(3,("transfer is already in progress\n"));
- return USBD_NORMAL_COMPLETION;
- }
-
- __usbd_free_xfer(xfer->alloc_xfer);
- xfer->alloc_xfer = NULL;
- }
-
- usbd_config[1].type = UE_CONTROL;
- usbd_config[1].endpoint = 0;
- usbd_config[1].direction = -1;
- usbd_config[1].timeout = USBD_DEFAULT_TIMEOUT;
- usbd_config[1].flags = USBD_SELF_DESTRUCT;
- usbd_config[1].bufsize = sizeof(usb_device_request_t);
- usbd_config[1].callback = &usbd_clearstall_callback;
-
- usbd_config[0].type = pipe->edesc->bmAttributes & UE_XFERTYPE;
- usbd_config[0].endpoint = pipe->edesc->bEndpointAddress & UE_ADDR;
- usbd_config[0].direction = pipe->edesc->bEndpointAddress & (UE_DIR_IN|UE_DIR_OUT);
- usbd_config[0].callback = usbd_default_callback;
- usbd_config[0].interval = USBD_DEFAULT_INTERVAL;
- usbd_config[0].timeout = timeout;
- usbd_config[0].flags = flags|USBD_SELF_DESTRUCT;
- usbd_config[0].bufsize = length;
-
- if(usbd_transfer_setup(pipe->udev, pipe->iface_index,
- &__xfer[0], &usbd_config[0],
- (flags & USBD_CUSTOM_CLEARSTALL) ? 1 : 2,
- priv, NULL))
- {
- PRINTFN(3,("USBD_NOMEM\n"));
- return USBD_NOMEM;
- }
-
- xfer->alloc_xfer = __xfer[0];
-
- /* automatic clear-stall */
- xfer->alloc_xfer->clearstall_xfer =
- (flags & USBD_CUSTOM_CLEARSTALL) ? NULL : __xfer[1];
-
- xfer->alloc_xfer->priv_fifo = xfer; /* used by callback */
- xfer->alloc_xfer->d_copy_ptr = xfer->alloc_xfer->buffer;
- xfer->alloc_xfer->d_copy_len = length;
- xfer->alloc_xfer->d_callback = callback;
-
- if(length && buffer)
- {
- if(usbd_config[0].direction == UE_DIR_IN)
- {
- xfer->alloc_xfer->d_copy_dst = buffer;
- }
- else
- {
- xfer->alloc_xfer->d_copy_src = buffer;
- }
- }
- return USBD_NORMAL_COMPLETION;
-}
-
-usbd_status
-usbd_setup_default_xfer(struct usbd_xfer *xfer, struct usbd_device *udev,
- void *priv, u_int32_t timeout,
- usb_device_request_t *req, void *buffer,
- u_int32_t length, u_int16_t flags,
- usbd_callback callback)
-{
- struct usbd_config usbd_config[1] = { /* zero */ };
-
- /* free current transfer, if any */
- if(xfer->alloc_xfer)
- {
- if(xfer->alloc_xfer->flags & USBD_DEV_TRANSFERRING)
- {
- /* transfer is in progress */
- PRINTFN(3,("transfer is already in progress\n"));
- return USBD_NORMAL_COMPLETION;
- }
-
- __usbd_free_xfer(xfer->alloc_xfer);
- xfer->alloc_xfer = NULL;
- }
-
- usbd_config[0].type = UE_CONTROL;
- usbd_config[0].endpoint = 0;
- usbd_config[0].direction = -1;
- usbd_config[0].timeout = timeout;
- usbd_config[0].flags = flags|USBD_SELF_DESTRUCT;
- usbd_config[0].bufsize = sizeof(usb_device_request_t) + length;
- usbd_config[0].callback = usbd_default_callback;
-
- if(usbd_transfer_setup(udev, 0,
- &xfer->alloc_xfer, &usbd_config[0], 1,
- priv, NULL))
- {
- PRINTFN(3,("USBD_NOMEM\n"));
- return USBD_NOMEM;
- }
-
- bcopy(req, xfer->alloc_xfer->buffer, sizeof(*req));
-
- xfer->alloc_xfer->priv_fifo = xfer; /* used by callback */
- xfer->alloc_xfer->d_copy_ptr = ((u_int8_t *)(xfer->alloc_xfer->buffer)) + sizeof(*req);
- xfer->alloc_xfer->d_copy_len = length;
- xfer->alloc_xfer->d_callback = callback;
-
- if(length && buffer)
- {
- if(req->bmRequestType & UT_READ)
- {
- xfer->alloc_xfer->d_copy_dst = buffer;
- }
- else
- {
- xfer->alloc_xfer->d_copy_src = buffer;
- }
- }
- return USBD_NORMAL_COMPLETION;
-}
-
-usbd_status
-usbd_setup_isoc_xfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- void *priv, u_int16_t *frlengths, u_int32_t nframes,
- u_int16_t flags, usbd_callback callback)
-{
- struct usbd_config usbd_config[1] = { /* zero */ };
-
- /* free current transfer, if any */
- if(xfer->alloc_xfer)
- {
- if(xfer->alloc_xfer->flags & USBD_DEV_TRANSFERRING)
- {
- /* transfer is in progress */
- PRINTFN(3,("transfer is already in progress\n"));
- return USBD_NORMAL_COMPLETION;
- }
- __usbd_free_xfer(xfer->alloc_xfer);
- xfer->alloc_xfer = NULL;
- }
-
- if(xfer->alloc_ptr == NULL)
- {
- /* no data-buffer allocated */
- return USBD_NOMEM;
- }
-
- usbd_config[0].type = pipe->edesc->bmAttributes & UE_XFERTYPE;
- usbd_config[0].endpoint = pipe->edesc->bEndpointAddress & UE_ADDR;
- usbd_config[0].direction = pipe->edesc->bEndpointAddress & (UE_DIR_IN|UE_DIR_OUT);
- usbd_config[0].callback = usbd_default_callback;
- usbd_config[0].interval = USBD_DEFAULT_INTERVAL;
- usbd_config[0].flags = flags|USBD_SELF_DESTRUCT;
- usbd_config[0].bufsize = xfer->alloc_len;
- usbd_config[0].frames = nframes;
-
- if(usbd_transfer_setup(pipe->udev, pipe->iface_index,
- &xfer->alloc_xfer, &usbd_config[0], 1,
- priv, NULL))
- {
- return USBD_NOMEM;
- }
-
- xfer->alloc_xfer->priv_fifo = xfer; /* used by callback */
- xfer->alloc_xfer->d_copy_ptr = xfer->alloc_xfer->buffer;
- xfer->alloc_xfer->d_copy_len = xfer->alloc_len;
- xfer->alloc_xfer->f_copy_ptr = &xfer->alloc_xfer->frlengths[0];
- xfer->alloc_xfer->f_copy_len = nframes*sizeof(xfer->alloc_xfer->frlengths[0]);
- xfer->alloc_xfer->d_callback = callback;
-
- xfer->alloc_xfer->f_copy_src = frlengths;
- xfer->alloc_xfer->f_copy_dst = frlengths;
-
- if(usbd_config[0].direction == UE_DIR_IN)
- {
- xfer->alloc_xfer->d_copy_dst = xfer->alloc_ptr;
- }
- else
- {
- xfer->alloc_xfer->d_copy_src = xfer->alloc_ptr;
- }
- return USBD_NORMAL_COMPLETION;
-}
-
-usbd_status
-usbd_bulk_transfer(struct usbd_xfer *xfer, struct usbd_pipe *pipe,
- u_int16_t flags, u_int32_t timeout, void *buf,
- u_int32_t *size, char *lbl)
-{
- usbd_status err;
-
- if(usbd_setup_xfer(xfer, pipe, 0, buf, *size,
- flags|USBD_SYNCHRONOUS, timeout, NULL))
- {
- return USBD_NOMEM;
- }
-
- if(usbd_transfer(xfer))
- {
- return USBD_NOMEM;
- }
-
- usbd_get_xfer_status(xfer, NULL, NULL, size, &err);
- return (err);
-}
-
-usbd_status
-usbd_abort_pipe(struct usbd_pipe *pipe)
-{
- enum { FINISH_LIST_MAX = 16 };
-
- struct usbd_xfer * finish_list[FINISH_LIST_MAX];
- struct usbd_xfer **ptr;
-
- ptr = &finish_list[0];
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list