1 /* $NetBSD: usbdi.h,v 1.64 2004/10/23 13:26:34 augustss Exp $ */
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
41 typedef struct usbd_bus *usbd_bus_handle;
42 typedef struct usbd_device *usbd_device_handle;
43 typedef struct usbd_interface *usbd_interface_handle;
44 typedef struct usbd_pipe *usbd_pipe_handle;
45 typedef struct usbd_xfer *usbd_xfer_handle;
46 typedef void *usbd_private_handle;
48 typedef enum { /* keep in sync with usbd_status_msgs */
49 USBD_NORMAL_COMPLETION = 0, /* must be 0 */
50 USBD_IN_PROGRESS, /* 1 */
52 USBD_PENDING_REQUESTS, /* 2 */
53 USBD_NOT_STARTED, /* 3 */
56 USBD_CANCELLED, /* 6 */
57 USBD_BAD_ADDRESS, /* 7 */
60 USBD_SET_ADDR_FAILED, /* 10 */
61 USBD_NO_POWER, /* 11 */
62 USBD_TOO_DEEP, /* 12 */
63 USBD_IOERROR, /* 13 */
64 USBD_NOT_CONFIGURED, /* 14 */
65 USBD_TIMEOUT, /* 15 */
66 USBD_SHORT_XFER, /* 16 */
67 USBD_STALLED, /* 17 */
68 USBD_INTERRUPTED, /* 18 */
70 USBD_ERROR_MAX /* must be last */
73 typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
77 #define USBD_EXCLUSIVE_USE 0x01
79 /* Use default (specified by ep. desc.) interval on interrupt pipe */
80 #define USBD_DEFAULT_INTERVAL (-1)
83 #define USBD_NO_COPY 0x01 /* do not copy data to DMA buffer */
84 #define USBD_SYNCHRONOUS 0x02 /* wait for completion */
85 /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/ /* allow short reads */
86 #define USBD_FORCE_SHORT_XFER 0x08 /* force last short packet on write */
88 #define USBD_NO_TIMEOUT 0
89 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
91 usbd_status usbd_open_pipe(usbd_interface_handle, u_int8_t,
92 u_int8_t, usbd_pipe_handle *);
93 usbd_status usbd_close_pipe(usbd_pipe_handle);
94 usbd_status usbd_transfer(usbd_xfer_handle);
95 usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
96 usbd_status usbd_free_xfer(usbd_xfer_handle);
97 void usbd_setup_xfer(usbd_xfer_handle, usbd_pipe_handle,
98 usbd_private_handle, void *,
99 u_int32_t, u_int16_t, u_int32_t,
101 void usbd_setup_default_xfer(usbd_xfer_handle, usbd_device_handle,
102 usbd_private_handle, u_int32_t,
103 usb_device_request_t *, void *,
104 u_int32_t, u_int16_t, usbd_callback);
105 void usbd_setup_isoc_xfer(usbd_xfer_handle, usbd_pipe_handle,
106 usbd_private_handle, u_int16_t *,
107 u_int32_t, u_int16_t, usbd_callback);
108 void usbd_get_xfer_status(usbd_xfer_handle, usbd_private_handle *,
109 void **, u_int32_t *, usbd_status *);
110 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
111 (usbd_interface_handle, u_int8_t);
112 usbd_status usbd_abort_pipe(usbd_pipe_handle);
113 usbd_status usbd_clear_endpoint_stall(usbd_pipe_handle);
114 usbd_status usbd_clear_endpoint_stall_async(usbd_pipe_handle);
115 void usbd_clear_endpoint_toggle(usbd_pipe_handle);
116 usbd_status usbd_endpoint_count(usbd_interface_handle, u_int8_t *);
117 usbd_status usbd_interface_count(usbd_device_handle, u_int8_t *);
118 void usbd_interface2device_handle(usbd_interface_handle,
119 usbd_device_handle *);
120 usbd_status usbd_device2interface_handle(usbd_device_handle,
121 u_int8_t, usbd_interface_handle *);
123 usbd_device_handle usbd_pipe2device_handle(usbd_pipe_handle);
124 void *usbd_alloc_buffer(usbd_xfer_handle, u_int32_t);
125 void usbd_free_buffer(usbd_xfer_handle);
126 void *usbd_get_buffer(usbd_xfer_handle);
127 usbd_status usbd_sync_transfer(usbd_xfer_handle);
128 usbd_status usbd_open_pipe_intr(usbd_interface_handle, u_int8_t,
129 u_int8_t, usbd_pipe_handle *,
130 usbd_private_handle, void *,
131 u_int32_t, usbd_callback, int);
132 usbd_status usbd_do_request(usbd_device_handle, usb_device_request_t *, void *);
133 usbd_status usbd_do_request_async(usbd_device_handle,
134 usb_device_request_t *, void *);
135 usbd_status usbd_do_request_flags(usbd_device_handle, usb_device_request_t *,
136 void *, u_int16_t, int*, u_int32_t);
137 usbd_status usbd_do_request_flags_pipe(usbd_device_handle, usbd_pipe_handle,
138 usb_device_request_t *, void *, u_int16_t, int *, u_int32_t);
139 usb_interface_descriptor_t *usbd_get_interface_descriptor
140 (usbd_interface_handle);
141 usb_config_descriptor_t *usbd_get_config_descriptor(usbd_device_handle);
142 usb_device_descriptor_t *usbd_get_device_descriptor(usbd_device_handle);
143 usbd_status usbd_set_interface(usbd_interface_handle, int);
144 int usbd_get_no_alts(usb_config_descriptor_t *, int);
145 usbd_status usbd_get_interface(usbd_interface_handle, u_int8_t *);
146 void usbd_fill_deviceinfo(usbd_device_handle, struct usb_device_info *, int);
147 int usbd_get_interface_altindex(usbd_interface_handle);
149 usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
151 usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *,
154 void usbd_dopoll(usbd_interface_handle);
155 void usbd_set_polling(usbd_device_handle, int);
157 const char *usbd_errstr(usbd_status);
159 void usbd_add_dev_event(int, usbd_device_handle);
160 void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
162 void usbd_devinfo(usbd_device_handle, int, char *);
163 const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
164 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
165 (usbd_interface_handle, u_int8_t);
167 usbd_status usbd_reload_device_desc(usbd_device_handle);
169 int usbd_ratecheck(struct timeval *last);
172 * The usb_task structs form a queue of things to run in the USB event
173 * thread. Normally this is just device discovery when a connect/disconnect
174 * has been detected. But it may also be used by drivers that need to
175 * perform (short) tasks that must have a process context.
178 TAILQ_ENTRY(usb_task) next;
184 void usb_add_task(usbd_device_handle, struct usb_task *);
185 void usb_rem_task(usbd_device_handle, struct usb_task *);
186 #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->onqueue = 0)
190 u_int16_t ud_product;
192 const struct usb_devno *usb_match_device(const struct usb_devno *,
193 u_int, u_int, u_int16_t, u_int16_t);
194 #define usb_lookup(tbl, vendor, product) \
195 usb_match_device((const struct usb_devno *)(tbl), sizeof (tbl) / sizeof ((tbl)[0]), sizeof ((tbl)[0]), (vendor), (product))
196 #define USB_PRODUCT_ANY 0xffff
198 /* NetBSD attachment information */
201 struct usb_attach_arg {
209 usbd_device_handle device; /* current device */
210 usbd_interface_handle iface; /* current interface */
212 usbd_interface_handle *ifaces; /* all interfaces */
213 int nifaces; /* number of interfaces */
216 #if defined(__NetBSD__) || defined(__OpenBSD__)
218 /* First five codes is for a whole device. */
219 #define UMATCH_VENDOR_PRODUCT_REV 14
220 #define UMATCH_VENDOR_PRODUCT 13
221 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
222 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
223 #define UMATCH_DEVCLASS_DEVSUBCLASS 10
224 /* Next six codes are for interfaces. */
225 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
226 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
227 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
228 #define UMATCH_VENDOR_IFACESUBCLASS 6
229 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
230 #define UMATCH_IFACECLASS_IFACESUBCLASS 4
231 #define UMATCH_IFACECLASS 3
232 #define UMATCH_IFACECLASS_GENERIC 2
234 #define UMATCH_GENERIC 1
236 #define UMATCH_NONE 0
238 #elif defined(__FreeBSD__)
239 /* FreeBSD needs values less than zero */
240 #define UMATCH_VENDOR_PRODUCT_REV (-10)
241 #define UMATCH_VENDOR_PRODUCT (-20)
242 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO (-30)
243 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO (-40)
244 #define UMATCH_DEVCLASS_DEVSUBCLASS (-50)
245 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE (-60)
246 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE (-70)
247 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO (-80)
248 #define UMATCH_VENDOR_IFACESUBCLASS (-90)
249 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO (-100)
250 #define UMATCH_IFACECLASS_IFACESUBCLASS (-110)
251 #define UMATCH_IFACECLASS (-120)
252 #define UMATCH_IFACECLASS_GENERIC (-130)
253 #define UMATCH_GENERIC (-140)
254 #define UMATCH_NONE (ENXIO)
258 #define USBD_SHOW_DEVICE_CLASS 0x1
259 #define USBD_SHOW_INTERFACE_CLASS 0x2
261 #if defined(__FreeBSD__)
262 int usbd_driver_load(module_t mod, int what, void *arg);
265 /* XXX Perhaps USB should have its own levels? */
266 #ifdef USB_USE_SOFTINTR
267 #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
268 #define splusb splsoftnet
270 #define splusb splsoftclock
271 #endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
273 #define splusb splbio
274 #endif /* USB_USE_SOFTINTR */
275 #define splhardusb splbio
276 #define IPL_USB IPL_BIO