usbdi.h revision 1.78 1 1.78 martin /* $NetBSD: usbdi.h,v 1.78 2009/08/16 13:20:40 martin 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 *
21 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
32 1.1 augustss */
33 1.1 augustss
34 1.74 drochner #ifndef _USBDI_H_
35 1.74 drochner #define _USBDI_H_
36 1.74 drochner
37 1.1 augustss typedef struct usbd_bus *usbd_bus_handle;
38 1.1 augustss typedef struct usbd_device *usbd_device_handle;
39 1.1 augustss typedef struct usbd_interface *usbd_interface_handle;
40 1.1 augustss typedef struct usbd_pipe *usbd_pipe_handle;
41 1.32 augustss typedef struct usbd_xfer *usbd_xfer_handle;
42 1.1 augustss typedef void *usbd_private_handle;
43 1.1 augustss
44 1.62 augustss typedef enum { /* keep in sync with usbd_status_msgs */
45 1.23 augustss USBD_NORMAL_COMPLETION = 0, /* must be 0 */
46 1.58 augustss USBD_IN_PROGRESS, /* 1 */
47 1.1 augustss /* errors */
48 1.58 augustss USBD_PENDING_REQUESTS, /* 2 */
49 1.58 augustss USBD_NOT_STARTED, /* 3 */
50 1.58 augustss USBD_INVAL, /* 4 */
51 1.58 augustss USBD_NOMEM, /* 5 */
52 1.58 augustss USBD_CANCELLED, /* 6 */
53 1.58 augustss USBD_BAD_ADDRESS, /* 7 */
54 1.58 augustss USBD_IN_USE, /* 8 */
55 1.58 augustss USBD_NO_ADDR, /* 9 */
56 1.58 augustss USBD_SET_ADDR_FAILED, /* 10 */
57 1.58 augustss USBD_NO_POWER, /* 11 */
58 1.58 augustss USBD_TOO_DEEP, /* 12 */
59 1.58 augustss USBD_IOERROR, /* 13 */
60 1.58 augustss USBD_NOT_CONFIGURED, /* 14 */
61 1.58 augustss USBD_TIMEOUT, /* 15 */
62 1.58 augustss USBD_SHORT_XFER, /* 16 */
63 1.58 augustss USBD_STALLED, /* 17 */
64 1.58 augustss USBD_INTERRUPTED, /* 18 */
65 1.1 augustss
66 1.52 lukem USBD_ERROR_MAX /* must be last */
67 1.1 augustss } usbd_status;
68 1.1 augustss
69 1.43 augustss typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
70 1.43 augustss usbd_status);
71 1.1 augustss
72 1.1 augustss /* Open flags */
73 1.1 augustss #define USBD_EXCLUSIVE_USE 0x01
74 1.1 augustss
75 1.39 augustss /* Use default (specified by ep. desc.) interval on interrupt pipe */
76 1.39 augustss #define USBD_DEFAULT_INTERVAL (-1)
77 1.39 augustss
78 1.1 augustss /* Request flags */
79 1.29 augustss #define USBD_NO_COPY 0x01 /* do not copy data to DMA buffer */
80 1.29 augustss #define USBD_SYNCHRONOUS 0x02 /* wait for completion */
81 1.28 augustss /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/ /* allow short reads */
82 1.37 augustss #define USBD_FORCE_SHORT_XFER 0x08 /* force last short packet on write */
83 1.1 augustss
84 1.1 augustss #define USBD_NO_TIMEOUT 0
85 1.1 augustss #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
86 1.78 martin #define USBD_CONFIG_TIMEOUT (3*USBD_DEFAULT_TIMEOUT)
87 1.1 augustss
88 1.31 augustss #if defined(__FreeBSD__)
89 1.31 augustss #define USB_CDEV_MAJOR 108
90 1.31 augustss #endif
91 1.31 augustss
92 1.66 soren #define DEVINFOSIZE 1024
93 1.66 soren
94 1.63 itojun usbd_status usbd_open_pipe(usbd_interface_handle, u_int8_t,
95 1.63 itojun u_int8_t, usbd_pipe_handle *);
96 1.63 itojun usbd_status usbd_close_pipe(usbd_pipe_handle);
97 1.63 itojun usbd_status usbd_transfer(usbd_xfer_handle);
98 1.43 augustss usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
99 1.63 itojun usbd_status usbd_free_xfer(usbd_xfer_handle);
100 1.63 itojun void usbd_setup_xfer(usbd_xfer_handle, usbd_pipe_handle,
101 1.63 itojun usbd_private_handle, void *,
102 1.63 itojun u_int32_t, u_int16_t, u_int32_t,
103 1.43 augustss usbd_callback);
104 1.63 itojun void usbd_setup_default_xfer(usbd_xfer_handle, usbd_device_handle,
105 1.63 itojun usbd_private_handle, u_int32_t,
106 1.63 itojun usb_device_request_t *, void *,
107 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
108 1.63 itojun void usbd_setup_isoc_xfer(usbd_xfer_handle, usbd_pipe_handle,
109 1.63 itojun usbd_private_handle, u_int16_t *,
110 1.63 itojun u_int32_t, u_int16_t, usbd_callback);
111 1.63 itojun void usbd_get_xfer_status(usbd_xfer_handle, usbd_private_handle *,
112 1.63 itojun void **, u_int32_t *, usbd_status *);
113 1.1 augustss usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
114 1.63 itojun (usbd_interface_handle, u_int8_t);
115 1.63 itojun usbd_status usbd_abort_pipe(usbd_pipe_handle);
116 1.77 jmorse usbd_status usbd_abort_default_pipe(usbd_device_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.72 christos #ifdef COMPAT_30
152 1.72 christos void usbd_fill_deviceinfo_old(usbd_device_handle, struct usb_device_info_old *,
153 1.72 christos int);
154 1.72 christos #endif
155 1.63 itojun int usbd_get_interface_altindex(usbd_interface_handle);
156 1.43 augustss
157 1.63 itojun usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *,
158 1.63 itojun int, int);
159 1.63 itojun usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *,
160 1.63 itojun int, int, int);
161 1.43 augustss
162 1.43 augustss void usbd_dopoll(usbd_interface_handle);
163 1.63 itojun void usbd_set_polling(usbd_device_handle, int);
164 1.23 augustss
165 1.63 itojun const char *usbd_errstr(usbd_status);
166 1.30 augustss
167 1.43 augustss void usbd_add_dev_event(int, usbd_device_handle);
168 1.43 augustss void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
169 1.1 augustss
170 1.67 christos char *usbd_devinfo_alloc(usbd_device_handle, int);
171 1.67 christos void usbd_devinfo_free(char *);
172 1.65 augustss
173 1.46 jdolecek const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
174 1.38 augustss usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
175 1.63 itojun (usbd_interface_handle, u_int8_t);
176 1.38 augustss
177 1.43 augustss usbd_status usbd_reload_device_desc(usbd_device_handle);
178 1.41 augustss
179 1.67 christos int usbd_ratecheck(struct timeval *);
180 1.48 augustss
181 1.67 christos usbd_status usbd_get_string(usbd_device_handle, int, char *);
182 1.71 pavel usbd_status usbd_get_string0(usbd_device_handle, int, char *, int);
183 1.64 augustss
184 1.64 augustss /* An iterator for descriptors. */
185 1.64 augustss typedef struct {
186 1.64 augustss const uByte *cur;
187 1.64 augustss const uByte *end;
188 1.64 augustss } usbd_desc_iter_t;
189 1.67 christos void usb_desc_iter_init(usbd_device_handle, usbd_desc_iter_t *);
190 1.67 christos const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
191 1.64 augustss
192 1.48 augustss /*
193 1.48 augustss * The usb_task structs form a queue of things to run in the USB event
194 1.48 augustss * thread. Normally this is just device discovery when a connect/disconnect
195 1.48 augustss * has been detected. But it may also be used by drivers that need to
196 1.48 augustss * perform (short) tasks that must have a process context.
197 1.48 augustss */
198 1.48 augustss struct usb_task {
199 1.49 augustss TAILQ_ENTRY(usb_task) next;
200 1.48 augustss void (*fun)(void *);
201 1.48 augustss void *arg;
202 1.70 joerg int queue;
203 1.48 augustss };
204 1.70 joerg #define USB_TASKQ_HC 0
205 1.70 joerg #define USB_TASKQ_DRIVER 1
206 1.70 joerg #define USB_NUM_TASKQS 2
207 1.70 joerg #define USB_TASKQ_NAMES {"usbtask-hc", "usbtask-dr"}
208 1.48 augustss
209 1.70 joerg void usb_add_task(usbd_device_handle, struct usb_task *, int);
210 1.63 itojun void usb_rem_task(usbd_device_handle, struct usb_task *);
211 1.70 joerg #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->queue = -1)
212 1.55 augustss
213 1.55 augustss struct usb_devno {
214 1.55 augustss u_int16_t ud_vendor;
215 1.55 augustss u_int16_t ud_product;
216 1.55 augustss };
217 1.63 itojun const struct usb_devno *usb_match_device(const struct usb_devno *,
218 1.63 itojun u_int, u_int, u_int16_t, u_int16_t);
219 1.56 augustss #define usb_lookup(tbl, vendor, product) \
220 1.56 augustss usb_match_device((const struct usb_devno *)(tbl), sizeof (tbl) / sizeof ((tbl)[0]), sizeof ((tbl)[0]), (vendor), (product))
221 1.59 augustss #define USB_PRODUCT_ANY 0xffff
222 1.38 augustss
223 1.1 augustss /* NetBSD attachment information */
224 1.1 augustss
225 1.1 augustss /* Attach data */
226 1.1 augustss struct usb_attach_arg {
227 1.1 augustss int port;
228 1.73 drochner int vendor;
229 1.73 drochner int product;
230 1.73 drochner int release;
231 1.73 drochner usbd_device_handle device; /* current device */
232 1.73 drochner int class, subclass, proto;
233 1.73 drochner int usegeneric;
234 1.73 drochner };
235 1.73 drochner
236 1.73 drochner struct usbif_attach_arg {
237 1.73 drochner int port;
238 1.8 augustss int configno;
239 1.8 augustss int ifaceno;
240 1.18 augustss int vendor;
241 1.18 augustss int product;
242 1.18 augustss int release;
243 1.13 augustss usbd_device_handle device; /* current device */
244 1.73 drochner
245 1.13 augustss usbd_interface_handle iface; /* current interface */
246 1.73 drochner int class, subclass, proto;
247 1.73 drochner
248 1.73 drochner /* XXX need accounting for interfaces not matched to */
249 1.73 drochner
250 1.13 augustss usbd_interface_handle *ifaces; /* all interfaces */
251 1.13 augustss int nifaces; /* number of interfaces */
252 1.1 augustss };
253 1.1 augustss
254 1.1 augustss /* Match codes. */
255 1.69 augustss #define UMATCH_HIGHEST 15
256 1.1 augustss /* First five codes is for a whole device. */
257 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV 14
258 1.1 augustss #define UMATCH_VENDOR_PRODUCT 13
259 1.1 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
260 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
261 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS 10
262 1.1 augustss /* Next six codes are for interfaces. */
263 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
264 1.1 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
265 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
266 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS 6
267 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
268 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS 4
269 1.1 augustss #define UMATCH_IFACECLASS 3
270 1.1 augustss #define UMATCH_IFACECLASS_GENERIC 2
271 1.1 augustss /* Generic driver */
272 1.1 augustss #define UMATCH_GENERIC 1
273 1.1 augustss /* No match */
274 1.1 augustss #define UMATCH_NONE 0
275 1.12 augustss
276 1.47 augustss /* XXX Perhaps USB should have its own levels? */
277 1.47 augustss #define splusb splsoftnet
278 1.40 augustss #define splhardusb splbio
279 1.10 augustss #define IPL_USB IPL_BIO
280 1.75 kiyohara #define splsoftusb splusb
281 1.75 kiyohara #define IPL_SOFTUSB IPL_SOFTNET
282 1.75 kiyohara #define IPL_HARDUSB IPL_USB
283 1.75 kiyohara
284 1.74 drochner
285 1.74 drochner #endif /* _USBDI_H_ */
286