usbdi.h revision 1.65 1 1.65 augustss /* $NetBSD: usbdi.h,v 1.65 2005/05/11 10:02:29 augustss Exp $ */
2 1.34 augustss /* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
3 1.1 augustss
4 1.1 augustss /*
5 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 1.1 augustss * All rights reserved.
7 1.1 augustss *
8 1.7 augustss * This code is derived from software contributed to The NetBSD Foundation
9 1.42 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
10 1.7 augustss * Carlstedt Research & Technology.
11 1.1 augustss *
12 1.1 augustss * Redistribution and use in source and binary forms, with or without
13 1.1 augustss * modification, are permitted provided that the following conditions
14 1.1 augustss * are met:
15 1.1 augustss * 1. Redistributions of source code must retain the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer.
17 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 augustss * notice, this list of conditions and the following disclaimer in the
19 1.1 augustss * documentation and/or other materials provided with the distribution.
20 1.1 augustss * 3. All advertising materials mentioning features or use of this software
21 1.1 augustss * must display the following acknowledgement:
22 1.1 augustss * This product includes software developed by the NetBSD
23 1.1 augustss * Foundation, Inc. and its contributors.
24 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
25 1.1 augustss * contributors may be used to endorse or promote products derived
26 1.1 augustss * from this software without specific prior written permission.
27 1.1 augustss *
28 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
39 1.1 augustss */
40 1.1 augustss
41 1.1 augustss typedef struct usbd_bus *usbd_bus_handle;
42 1.1 augustss typedef struct usbd_device *usbd_device_handle;
43 1.1 augustss typedef struct usbd_interface *usbd_interface_handle;
44 1.1 augustss typedef struct usbd_pipe *usbd_pipe_handle;
45 1.32 augustss typedef struct usbd_xfer *usbd_xfer_handle;
46 1.1 augustss typedef void *usbd_private_handle;
47 1.1 augustss
48 1.62 augustss typedef enum { /* keep in sync with usbd_status_msgs */
49 1.23 augustss USBD_NORMAL_COMPLETION = 0, /* must be 0 */
50 1.58 augustss USBD_IN_PROGRESS, /* 1 */
51 1.1 augustss /* errors */
52 1.58 augustss USBD_PENDING_REQUESTS, /* 2 */
53 1.58 augustss USBD_NOT_STARTED, /* 3 */
54 1.58 augustss USBD_INVAL, /* 4 */
55 1.58 augustss USBD_NOMEM, /* 5 */
56 1.58 augustss USBD_CANCELLED, /* 6 */
57 1.58 augustss USBD_BAD_ADDRESS, /* 7 */
58 1.58 augustss USBD_IN_USE, /* 8 */
59 1.58 augustss USBD_NO_ADDR, /* 9 */
60 1.58 augustss USBD_SET_ADDR_FAILED, /* 10 */
61 1.58 augustss USBD_NO_POWER, /* 11 */
62 1.58 augustss USBD_TOO_DEEP, /* 12 */
63 1.58 augustss USBD_IOERROR, /* 13 */
64 1.58 augustss USBD_NOT_CONFIGURED, /* 14 */
65 1.58 augustss USBD_TIMEOUT, /* 15 */
66 1.58 augustss USBD_SHORT_XFER, /* 16 */
67 1.58 augustss USBD_STALLED, /* 17 */
68 1.58 augustss USBD_INTERRUPTED, /* 18 */
69 1.1 augustss
70 1.52 lukem USBD_ERROR_MAX /* must be last */
71 1.1 augustss } usbd_status;
72 1.1 augustss
73 1.43 augustss typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
74 1.43 augustss usbd_status);
75 1.1 augustss
76 1.1 augustss /* Open flags */
77 1.1 augustss #define USBD_EXCLUSIVE_USE 0x01
78 1.1 augustss
79 1.39 augustss /* Use default (specified by ep. desc.) interval on interrupt pipe */
80 1.39 augustss #define USBD_DEFAULT_INTERVAL (-1)
81 1.39 augustss
82 1.1 augustss /* Request flags */
83 1.29 augustss #define USBD_NO_COPY 0x01 /* do not copy data to DMA buffer */
84 1.29 augustss #define USBD_SYNCHRONOUS 0x02 /* wait for completion */
85 1.28 augustss /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/ /* allow short reads */
86 1.37 augustss #define USBD_FORCE_SHORT_XFER 0x08 /* force last short packet on write */
87 1.1 augustss
88 1.1 augustss #define USBD_NO_TIMEOUT 0
89 1.1 augustss #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
90 1.1 augustss
91 1.31 augustss #if defined(__FreeBSD__)
92 1.31 augustss #define USB_CDEV_MAJOR 108
93 1.31 augustss #endif
94 1.31 augustss
95 1.63 itojun usbd_status usbd_open_pipe(usbd_interface_handle, u_int8_t,
96 1.63 itojun u_int8_t, usbd_pipe_handle *);
97 1.63 itojun usbd_status usbd_close_pipe(usbd_pipe_handle);
98 1.63 itojun usbd_status usbd_transfer(usbd_xfer_handle);
99 1.43 augustss usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
100 1.63 itojun usbd_status usbd_free_xfer(usbd_xfer_handle);
101 1.63 itojun void usbd_setup_xfer(usbd_xfer_handle, usbd_pipe_handle,
102 1.63 itojun usbd_private_handle, void *,
103 1.63 itojun u_int32_t, u_int16_t, u_int32_t,
104 1.43 augustss usbd_callback);
105 1.63 itojun void usbd_setup_default_xfer(usbd_xfer_handle, usbd_device_handle,
106 1.63 itojun usbd_private_handle, u_int32_t,
107 1.63 itojun usb_device_request_t *, void *,
108 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
109 1.63 itojun void usbd_setup_isoc_xfer(usbd_xfer_handle, usbd_pipe_handle,
110 1.63 itojun usbd_private_handle, u_int16_t *,
111 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
112 1.63 itojun void usbd_get_xfer_status(usbd_xfer_handle, usbd_private_handle *,
113 1.63 itojun void **, u_int32_t *, usbd_status *);
114 1.1 augustss usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
115 1.63 itojun (usbd_interface_handle, u_int8_t);
116 1.63 itojun usbd_status usbd_abort_pipe(usbd_pipe_handle);
117 1.63 itojun usbd_status usbd_clear_endpoint_stall(usbd_pipe_handle);
118 1.63 itojun usbd_status usbd_clear_endpoint_stall_async(usbd_pipe_handle);
119 1.63 itojun void usbd_clear_endpoint_toggle(usbd_pipe_handle);
120 1.63 itojun usbd_status usbd_endpoint_count(usbd_interface_handle, u_int8_t *);
121 1.63 itojun usbd_status usbd_interface_count(usbd_device_handle, u_int8_t *);
122 1.63 itojun void usbd_interface2device_handle(usbd_interface_handle,
123 1.63 itojun usbd_device_handle *);
124 1.63 itojun usbd_status usbd_device2interface_handle(usbd_device_handle,
125 1.63 itojun u_int8_t, usbd_interface_handle *);
126 1.43 augustss
127 1.43 augustss usbd_device_handle usbd_pipe2device_handle(usbd_pipe_handle);
128 1.63 itojun void *usbd_alloc_buffer(usbd_xfer_handle, u_int32_t);
129 1.63 itojun void usbd_free_buffer(usbd_xfer_handle);
130 1.63 itojun void *usbd_get_buffer(usbd_xfer_handle);
131 1.63 itojun usbd_status usbd_sync_transfer(usbd_xfer_handle);
132 1.63 itojun usbd_status usbd_open_pipe_intr(usbd_interface_handle, u_int8_t,
133 1.63 itojun u_int8_t, usbd_pipe_handle *,
134 1.63 itojun usbd_private_handle, void *,
135 1.63 itojun u_int32_t, usbd_callback, int);
136 1.63 itojun usbd_status usbd_do_request(usbd_device_handle, usb_device_request_t *, void *);
137 1.63 itojun usbd_status usbd_do_request_async(usbd_device_handle,
138 1.63 itojun usb_device_request_t *, void *);
139 1.63 itojun usbd_status usbd_do_request_flags(usbd_device_handle, usb_device_request_t *,
140 1.63 itojun void *, u_int16_t, int*, u_int32_t);
141 1.63 itojun usbd_status usbd_do_request_flags_pipe(usbd_device_handle, usbd_pipe_handle,
142 1.63 itojun usb_device_request_t *, void *, u_int16_t, int *, u_int32_t);
143 1.1 augustss usb_interface_descriptor_t *usbd_get_interface_descriptor
144 1.63 itojun (usbd_interface_handle);
145 1.63 itojun usb_config_descriptor_t *usbd_get_config_descriptor(usbd_device_handle);
146 1.63 itojun usb_device_descriptor_t *usbd_get_device_descriptor(usbd_device_handle);
147 1.43 augustss usbd_status usbd_set_interface(usbd_interface_handle, int);
148 1.43 augustss int usbd_get_no_alts(usb_config_descriptor_t *, int);
149 1.63 itojun usbd_status usbd_get_interface(usbd_interface_handle, u_int8_t *);
150 1.61 augustss void usbd_fill_deviceinfo(usbd_device_handle, struct usb_device_info *, int);
151 1.63 itojun int usbd_get_interface_altindex(usbd_interface_handle);
152 1.43 augustss
153 1.63 itojun usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
154 1.63 itojun int, int);
155 1.63 itojun usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *,
156 1.63 itojun int, int, int);
157 1.43 augustss
158 1.43 augustss void usbd_dopoll(usbd_interface_handle);
159 1.63 itojun void usbd_set_polling(usbd_device_handle, int);
160 1.23 augustss
161 1.63 itojun const char *usbd_errstr(usbd_status);
162 1.30 augustss
163 1.43 augustss void usbd_add_dev_event(int, usbd_device_handle);
164 1.43 augustss void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
165 1.1 augustss
166 1.65 augustss char *usbd_devinfo_alloc(usbd_device_handle dev, int showclass);
167 1.65 augustss void usbd_devinfo_free(char *devinfop);
168 1.65 augustss
169 1.46 jdolecek const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
170 1.38 augustss usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
171 1.63 itojun (usbd_interface_handle, u_int8_t);
172 1.38 augustss
173 1.43 augustss usbd_status usbd_reload_device_desc(usbd_device_handle);
174 1.41 augustss
175 1.43 augustss int usbd_ratecheck(struct timeval *last);
176 1.48 augustss
177 1.64 augustss usbd_status usbd_get_string(usbd_device_handle dev, int si, char *buf);
178 1.64 augustss
179 1.64 augustss /* An iterator for descriptors. */
180 1.64 augustss typedef struct {
181 1.64 augustss const uByte *cur;
182 1.64 augustss const uByte *end;
183 1.64 augustss } usbd_desc_iter_t;
184 1.64 augustss void usb_desc_iter_init(usbd_device_handle dev, usbd_desc_iter_t *iter);
185 1.64 augustss const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *iter);
186 1.64 augustss
187 1.48 augustss /*
188 1.48 augustss * The usb_task structs form a queue of things to run in the USB event
189 1.48 augustss * thread. Normally this is just device discovery when a connect/disconnect
190 1.48 augustss * has been detected. But it may also be used by drivers that need to
191 1.48 augustss * perform (short) tasks that must have a process context.
192 1.48 augustss */
193 1.48 augustss struct usb_task {
194 1.49 augustss TAILQ_ENTRY(usb_task) next;
195 1.48 augustss void (*fun)(void *);
196 1.48 augustss void *arg;
197 1.48 augustss char onqueue;
198 1.48 augustss };
199 1.48 augustss
200 1.63 itojun void usb_add_task(usbd_device_handle, struct usb_task *);
201 1.63 itojun void usb_rem_task(usbd_device_handle, struct usb_task *);
202 1.49 augustss #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->onqueue = 0)
203 1.55 augustss
204 1.55 augustss struct usb_devno {
205 1.55 augustss u_int16_t ud_vendor;
206 1.55 augustss u_int16_t ud_product;
207 1.55 augustss };
208 1.63 itojun const struct usb_devno *usb_match_device(const struct usb_devno *,
209 1.63 itojun u_int, u_int, u_int16_t, u_int16_t);
210 1.56 augustss #define usb_lookup(tbl, vendor, product) \
211 1.56 augustss usb_match_device((const struct usb_devno *)(tbl), sizeof (tbl) / sizeof ((tbl)[0]), sizeof ((tbl)[0]), (vendor), (product))
212 1.59 augustss #define USB_PRODUCT_ANY 0xffff
213 1.38 augustss
214 1.1 augustss /* NetBSD attachment information */
215 1.1 augustss
216 1.1 augustss /* Attach data */
217 1.1 augustss struct usb_attach_arg {
218 1.1 augustss int port;
219 1.8 augustss int configno;
220 1.8 augustss int ifaceno;
221 1.18 augustss int vendor;
222 1.18 augustss int product;
223 1.18 augustss int release;
224 1.53 augustss int matchlvl;
225 1.13 augustss usbd_device_handle device; /* current device */
226 1.13 augustss usbd_interface_handle iface; /* current interface */
227 1.1 augustss int usegeneric;
228 1.13 augustss usbd_interface_handle *ifaces; /* all interfaces */
229 1.13 augustss int nifaces; /* number of interfaces */
230 1.1 augustss };
231 1.1 augustss
232 1.22 augustss #if defined(__NetBSD__) || defined(__OpenBSD__)
233 1.1 augustss /* Match codes. */
234 1.1 augustss /* First five codes is for a whole device. */
235 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV 14
236 1.1 augustss #define UMATCH_VENDOR_PRODUCT 13
237 1.1 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
238 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
239 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS 10
240 1.1 augustss /* Next six codes are for interfaces. */
241 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
242 1.1 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
243 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
244 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS 6
245 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
246 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS 4
247 1.1 augustss #define UMATCH_IFACECLASS 3
248 1.1 augustss #define UMATCH_IFACECLASS_GENERIC 2
249 1.1 augustss /* Generic driver */
250 1.1 augustss #define UMATCH_GENERIC 1
251 1.1 augustss /* No match */
252 1.1 augustss #define UMATCH_NONE 0
253 1.12 augustss
254 1.12 augustss #elif defined(__FreeBSD__)
255 1.12 augustss /* FreeBSD needs values less than zero */
256 1.31 augustss #define UMATCH_VENDOR_PRODUCT_REV (-10)
257 1.31 augustss #define UMATCH_VENDOR_PRODUCT (-20)
258 1.31 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO (-30)
259 1.31 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO (-40)
260 1.31 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS (-50)
261 1.31 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE (-60)
262 1.31 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE (-70)
263 1.31 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO (-80)
264 1.31 augustss #define UMATCH_VENDOR_IFACESUBCLASS (-90)
265 1.31 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO (-100)
266 1.31 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS (-110)
267 1.31 augustss #define UMATCH_IFACECLASS (-120)
268 1.31 augustss #define UMATCH_IFACECLASS_GENERIC (-130)
269 1.31 augustss #define UMATCH_GENERIC (-140)
270 1.31 augustss #define UMATCH_NONE (ENXIO)
271 1.12 augustss
272 1.12 augustss #endif
273 1.16 augustss
274 1.16 augustss #if defined(__FreeBSD__)
275 1.43 augustss int usbd_driver_load(module_t mod, int what, void *arg);
276 1.16 augustss #endif
277 1.10 augustss
278 1.47 augustss /* XXX Perhaps USB should have its own levels? */
279 1.47 augustss #ifdef USB_USE_SOFTINTR
280 1.50 thorpej #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
281 1.47 augustss #define splusb splsoftnet
282 1.47 augustss #else
283 1.50 thorpej #define splusb splsoftclock
284 1.50 thorpej #endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
285 1.50 thorpej #else
286 1.10 augustss #define splusb splbio
287 1.50 thorpej #endif /* USB_USE_SOFTINTR */
288 1.40 augustss #define splhardusb splbio
289 1.10 augustss #define IPL_USB IPL_BIO
290