usbdi.h revision 1.75 1 1.75 kiyohara /* $NetBSD: usbdi.h,v 1.75 2007/08/15 04:00:34 kiyohara 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.74 drochner #ifndef _USBDI_H_
42 1.74 drochner #define _USBDI_H_
43 1.74 drochner
44 1.1 augustss typedef struct usbd_bus *usbd_bus_handle;
45 1.1 augustss typedef struct usbd_device *usbd_device_handle;
46 1.1 augustss typedef struct usbd_interface *usbd_interface_handle;
47 1.1 augustss typedef struct usbd_pipe *usbd_pipe_handle;
48 1.32 augustss typedef struct usbd_xfer *usbd_xfer_handle;
49 1.1 augustss typedef void *usbd_private_handle;
50 1.1 augustss
51 1.62 augustss typedef enum { /* keep in sync with usbd_status_msgs */
52 1.23 augustss USBD_NORMAL_COMPLETION = 0, /* must be 0 */
53 1.58 augustss USBD_IN_PROGRESS, /* 1 */
54 1.1 augustss /* errors */
55 1.58 augustss USBD_PENDING_REQUESTS, /* 2 */
56 1.58 augustss USBD_NOT_STARTED, /* 3 */
57 1.58 augustss USBD_INVAL, /* 4 */
58 1.58 augustss USBD_NOMEM, /* 5 */
59 1.58 augustss USBD_CANCELLED, /* 6 */
60 1.58 augustss USBD_BAD_ADDRESS, /* 7 */
61 1.58 augustss USBD_IN_USE, /* 8 */
62 1.58 augustss USBD_NO_ADDR, /* 9 */
63 1.58 augustss USBD_SET_ADDR_FAILED, /* 10 */
64 1.58 augustss USBD_NO_POWER, /* 11 */
65 1.58 augustss USBD_TOO_DEEP, /* 12 */
66 1.58 augustss USBD_IOERROR, /* 13 */
67 1.58 augustss USBD_NOT_CONFIGURED, /* 14 */
68 1.58 augustss USBD_TIMEOUT, /* 15 */
69 1.58 augustss USBD_SHORT_XFER, /* 16 */
70 1.58 augustss USBD_STALLED, /* 17 */
71 1.58 augustss USBD_INTERRUPTED, /* 18 */
72 1.1 augustss
73 1.52 lukem USBD_ERROR_MAX /* must be last */
74 1.1 augustss } usbd_status;
75 1.1 augustss
76 1.43 augustss typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
77 1.43 augustss usbd_status);
78 1.1 augustss
79 1.1 augustss /* Open flags */
80 1.1 augustss #define USBD_EXCLUSIVE_USE 0x01
81 1.1 augustss
82 1.39 augustss /* Use default (specified by ep. desc.) interval on interrupt pipe */
83 1.39 augustss #define USBD_DEFAULT_INTERVAL (-1)
84 1.39 augustss
85 1.1 augustss /* Request flags */
86 1.29 augustss #define USBD_NO_COPY 0x01 /* do not copy data to DMA buffer */
87 1.29 augustss #define USBD_SYNCHRONOUS 0x02 /* wait for completion */
88 1.28 augustss /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/ /* allow short reads */
89 1.37 augustss #define USBD_FORCE_SHORT_XFER 0x08 /* force last short packet on write */
90 1.1 augustss
91 1.1 augustss #define USBD_NO_TIMEOUT 0
92 1.1 augustss #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
93 1.1 augustss
94 1.31 augustss #if defined(__FreeBSD__)
95 1.31 augustss #define USB_CDEV_MAJOR 108
96 1.31 augustss #endif
97 1.31 augustss
98 1.66 soren #define DEVINFOSIZE 1024
99 1.66 soren
100 1.63 itojun usbd_status usbd_open_pipe(usbd_interface_handle, u_int8_t,
101 1.63 itojun u_int8_t, usbd_pipe_handle *);
102 1.63 itojun usbd_status usbd_close_pipe(usbd_pipe_handle);
103 1.63 itojun usbd_status usbd_transfer(usbd_xfer_handle);
104 1.43 augustss usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
105 1.63 itojun usbd_status usbd_free_xfer(usbd_xfer_handle);
106 1.63 itojun void usbd_setup_xfer(usbd_xfer_handle, usbd_pipe_handle,
107 1.63 itojun usbd_private_handle, void *,
108 1.63 itojun u_int32_t, u_int16_t, u_int32_t,
109 1.43 augustss usbd_callback);
110 1.63 itojun void usbd_setup_default_xfer(usbd_xfer_handle, usbd_device_handle,
111 1.63 itojun usbd_private_handle, u_int32_t,
112 1.63 itojun usb_device_request_t *, void *,
113 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
114 1.63 itojun void usbd_setup_isoc_xfer(usbd_xfer_handle, usbd_pipe_handle,
115 1.63 itojun usbd_private_handle, u_int16_t *,
116 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
117 1.63 itojun void usbd_get_xfer_status(usbd_xfer_handle, usbd_private_handle *,
118 1.63 itojun void **, u_int32_t *, usbd_status *);
119 1.1 augustss usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
120 1.63 itojun (usbd_interface_handle, u_int8_t);
121 1.63 itojun usbd_status usbd_abort_pipe(usbd_pipe_handle);
122 1.63 itojun usbd_status usbd_clear_endpoint_stall(usbd_pipe_handle);
123 1.63 itojun usbd_status usbd_clear_endpoint_stall_async(usbd_pipe_handle);
124 1.63 itojun void usbd_clear_endpoint_toggle(usbd_pipe_handle);
125 1.63 itojun usbd_status usbd_endpoint_count(usbd_interface_handle, u_int8_t *);
126 1.63 itojun usbd_status usbd_interface_count(usbd_device_handle, u_int8_t *);
127 1.63 itojun void usbd_interface2device_handle(usbd_interface_handle,
128 1.63 itojun usbd_device_handle *);
129 1.63 itojun usbd_status usbd_device2interface_handle(usbd_device_handle,
130 1.63 itojun u_int8_t, usbd_interface_handle *);
131 1.43 augustss
132 1.43 augustss usbd_device_handle usbd_pipe2device_handle(usbd_pipe_handle);
133 1.63 itojun void *usbd_alloc_buffer(usbd_xfer_handle, u_int32_t);
134 1.63 itojun void usbd_free_buffer(usbd_xfer_handle);
135 1.63 itojun void *usbd_get_buffer(usbd_xfer_handle);
136 1.63 itojun usbd_status usbd_sync_transfer(usbd_xfer_handle);
137 1.63 itojun usbd_status usbd_open_pipe_intr(usbd_interface_handle, u_int8_t,
138 1.63 itojun u_int8_t, usbd_pipe_handle *,
139 1.63 itojun usbd_private_handle, void *,
140 1.63 itojun u_int32_t, usbd_callback, int);
141 1.63 itojun usbd_status usbd_do_request(usbd_device_handle, usb_device_request_t *, void *);
142 1.63 itojun usbd_status usbd_do_request_async(usbd_device_handle,
143 1.63 itojun usb_device_request_t *, void *);
144 1.63 itojun usbd_status usbd_do_request_flags(usbd_device_handle, usb_device_request_t *,
145 1.63 itojun void *, u_int16_t, int*, u_int32_t);
146 1.63 itojun usbd_status usbd_do_request_flags_pipe(usbd_device_handle, usbd_pipe_handle,
147 1.63 itojun usb_device_request_t *, void *, u_int16_t, int *, u_int32_t);
148 1.1 augustss usb_interface_descriptor_t *usbd_get_interface_descriptor
149 1.63 itojun (usbd_interface_handle);
150 1.63 itojun usb_config_descriptor_t *usbd_get_config_descriptor(usbd_device_handle);
151 1.63 itojun usb_device_descriptor_t *usbd_get_device_descriptor(usbd_device_handle);
152 1.43 augustss usbd_status usbd_set_interface(usbd_interface_handle, int);
153 1.43 augustss int usbd_get_no_alts(usb_config_descriptor_t *, int);
154 1.63 itojun usbd_status usbd_get_interface(usbd_interface_handle, u_int8_t *);
155 1.61 augustss void usbd_fill_deviceinfo(usbd_device_handle, struct usb_device_info *, int);
156 1.72 christos #ifdef COMPAT_30
157 1.72 christos void usbd_fill_deviceinfo_old(usbd_device_handle, struct usb_device_info_old *,
158 1.72 christos int);
159 1.72 christos #endif
160 1.63 itojun int usbd_get_interface_altindex(usbd_interface_handle);
161 1.43 augustss
162 1.63 itojun usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
163 1.63 itojun int, int);
164 1.63 itojun usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *,
165 1.63 itojun int, int, int);
166 1.43 augustss
167 1.43 augustss void usbd_dopoll(usbd_interface_handle);
168 1.63 itojun void usbd_set_polling(usbd_device_handle, int);
169 1.23 augustss
170 1.63 itojun const char *usbd_errstr(usbd_status);
171 1.30 augustss
172 1.43 augustss void usbd_add_dev_event(int, usbd_device_handle);
173 1.43 augustss void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
174 1.1 augustss
175 1.67 christos char *usbd_devinfo_alloc(usbd_device_handle, int);
176 1.67 christos void usbd_devinfo_free(char *);
177 1.65 augustss
178 1.46 jdolecek const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
179 1.38 augustss usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
180 1.63 itojun (usbd_interface_handle, u_int8_t);
181 1.38 augustss
182 1.43 augustss usbd_status usbd_reload_device_desc(usbd_device_handle);
183 1.41 augustss
184 1.67 christos int usbd_ratecheck(struct timeval *);
185 1.48 augustss
186 1.67 christos usbd_status usbd_get_string(usbd_device_handle, int, char *);
187 1.71 pavel usbd_status usbd_get_string0(usbd_device_handle, int, char *, int);
188 1.64 augustss
189 1.64 augustss /* An iterator for descriptors. */
190 1.64 augustss typedef struct {
191 1.64 augustss const uByte *cur;
192 1.64 augustss const uByte *end;
193 1.64 augustss } usbd_desc_iter_t;
194 1.67 christos void usb_desc_iter_init(usbd_device_handle, usbd_desc_iter_t *);
195 1.67 christos const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
196 1.64 augustss
197 1.48 augustss /*
198 1.48 augustss * The usb_task structs form a queue of things to run in the USB event
199 1.48 augustss * thread. Normally this is just device discovery when a connect/disconnect
200 1.48 augustss * has been detected. But it may also be used by drivers that need to
201 1.48 augustss * perform (short) tasks that must have a process context.
202 1.48 augustss */
203 1.48 augustss struct usb_task {
204 1.49 augustss TAILQ_ENTRY(usb_task) next;
205 1.48 augustss void (*fun)(void *);
206 1.48 augustss void *arg;
207 1.70 joerg int queue;
208 1.48 augustss };
209 1.70 joerg #define USB_TASKQ_HC 0
210 1.70 joerg #define USB_TASKQ_DRIVER 1
211 1.70 joerg #define USB_NUM_TASKQS 2
212 1.70 joerg #define USB_TASKQ_NAMES {"usbtask-hc", "usbtask-dr"}
213 1.48 augustss
214 1.70 joerg void usb_add_task(usbd_device_handle, struct usb_task *, int);
215 1.63 itojun void usb_rem_task(usbd_device_handle, struct usb_task *);
216 1.70 joerg #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->queue = -1)
217 1.55 augustss
218 1.55 augustss struct usb_devno {
219 1.55 augustss u_int16_t ud_vendor;
220 1.55 augustss u_int16_t ud_product;
221 1.55 augustss };
222 1.63 itojun const struct usb_devno *usb_match_device(const struct usb_devno *,
223 1.63 itojun u_int, u_int, u_int16_t, u_int16_t);
224 1.56 augustss #define usb_lookup(tbl, vendor, product) \
225 1.56 augustss usb_match_device((const struct usb_devno *)(tbl), sizeof (tbl) / sizeof ((tbl)[0]), sizeof ((tbl)[0]), (vendor), (product))
226 1.59 augustss #define USB_PRODUCT_ANY 0xffff
227 1.38 augustss
228 1.1 augustss /* NetBSD attachment information */
229 1.1 augustss
230 1.1 augustss /* Attach data */
231 1.1 augustss struct usb_attach_arg {
232 1.1 augustss int port;
233 1.73 drochner int vendor;
234 1.73 drochner int product;
235 1.73 drochner int release;
236 1.73 drochner usbd_device_handle device; /* current device */
237 1.73 drochner int class, subclass, proto;
238 1.73 drochner int usegeneric;
239 1.73 drochner };
240 1.73 drochner
241 1.73 drochner struct usbif_attach_arg {
242 1.73 drochner int port;
243 1.8 augustss int configno;
244 1.8 augustss int ifaceno;
245 1.18 augustss int vendor;
246 1.18 augustss int product;
247 1.18 augustss int release;
248 1.13 augustss usbd_device_handle device; /* current device */
249 1.73 drochner
250 1.13 augustss usbd_interface_handle iface; /* current interface */
251 1.73 drochner int class, subclass, proto;
252 1.73 drochner
253 1.73 drochner /* XXX need accounting for interfaces not matched to */
254 1.73 drochner
255 1.13 augustss usbd_interface_handle *ifaces; /* all interfaces */
256 1.13 augustss int nifaces; /* number of interfaces */
257 1.1 augustss };
258 1.1 augustss
259 1.1 augustss /* Match codes. */
260 1.69 augustss #define UMATCH_HIGHEST 15
261 1.1 augustss /* First five codes is for a whole device. */
262 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV 14
263 1.1 augustss #define UMATCH_VENDOR_PRODUCT 13
264 1.1 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
265 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
266 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS 10
267 1.1 augustss /* Next six codes are for interfaces. */
268 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
269 1.1 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
270 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
271 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS 6
272 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
273 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS 4
274 1.1 augustss #define UMATCH_IFACECLASS 3
275 1.1 augustss #define UMATCH_IFACECLASS_GENERIC 2
276 1.1 augustss /* Generic driver */
277 1.1 augustss #define UMATCH_GENERIC 1
278 1.1 augustss /* No match */
279 1.1 augustss #define UMATCH_NONE 0
280 1.12 augustss
281 1.47 augustss /* XXX Perhaps USB should have its own levels? */
282 1.47 augustss #define splusb splsoftnet
283 1.40 augustss #define splhardusb splbio
284 1.10 augustss #define IPL_USB IPL_BIO
285 1.75 kiyohara #define splsoftusb splusb
286 1.75 kiyohara #define IPL_SOFTUSB IPL_SOFTNET
287 1.75 kiyohara #define IPL_HARDUSB IPL_USB
288 1.75 kiyohara
289 1.74 drochner
290 1.74 drochner #endif /* _USBDI_H_ */
291