usbdi.h revision 1.13 1 /* $NetBSD: usbdi.h,v 1.13 1998/12/29 03:09:48 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) carlstedt.se) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 typedef struct usbd_bus *usbd_bus_handle;
41 typedef struct usbd_device *usbd_device_handle;
42 typedef struct usbd_interface *usbd_interface_handle;
43 typedef struct usbd_pipe *usbd_pipe_handle;
44 typedef struct usbd_request *usbd_request_handle;
45 typedef void *usbd_private_handle;
46
47 typedef enum {
48 USBD_ENDPOINT_ACTIVE,
49 USBD_ENDPOINT_STALLED,
50 } usbd_endpoint_state;
51
52 typedef enum {
53 USBD_PIPE_ACTIVE,
54 USBD_PIPE_STALLED,
55 USBD_PIPE_IDLE,
56 } usbd_pipe_state;
57
58 typedef enum {
59 USBD_INTERFACE_ACTIVE,
60 USBD_INTERFACE_STALLED,
61 USBD_INTERFACE_IDLE,
62 } usbd_interface_state;
63
64 typedef enum {
65 USBD_DEVICE_ATTACHED,
66 USBD_DEVICE_POWERED,
67 USBD_DEVICE_DEFAULT,
68 USBD_DEVICE_ADDRESSED,
69 USBD_DEVICE_CONFIGURED,
70 USBD_DEVICE_SUSPENDED,
71 } usbd_device_state;
72
73 typedef enum {
74 USBD_NORMAL_COMPLETION = 0,
75 USBD_IN_PROGRESS,
76 /* errors */
77 USBD_PENDING_REQUESTS,
78 USBD_NOT_STARTED,
79 USBD_INVAL,
80 USBD_IS_IDLE,
81 USBD_NOMEM,
82 USBD_CANCELLED,
83 USBD_BAD_ADDRESS,
84 USBD_IN_USE,
85 USBD_INTERFACE_NOT_ACTIVE,
86 USBD_NO_ADDR,
87 USBD_SET_ADDR_FAILED,
88 USBD_NO_POWER,
89 USBD_TOO_DEEP,
90 USBD_IOERROR,
91 USBD_NOT_CONFIGURED,
92 USBD_TIMEOUT,
93 USBD_SHORT_XFER,
94 USBD_STALLED,
95
96 USBD_XXX,
97 } usbd_status;
98
99 typedef int usbd_lock_token;
100
101 typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle,
102 usbd_status));
103
104 /* Open flags */
105 #define USBD_EXCLUSIVE_USE 0x01
106
107 /* Request flags */
108 #define USBD_XFER_OUT 0x01
109 #define USBD_XFER_IN 0x02
110 #define USBD_SHORT_XFER_OK 0x04
111
112 #define USBD_NO_TIMEOUT 0
113 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
114
115 usbd_status usbd_open_pipe
116 __P((usbd_interface_handle iface, u_int8_t address,
117 u_int8_t flags, usbd_pipe_handle *pipe));
118 usbd_status usbd_close_pipe __P((usbd_pipe_handle pipe));
119 usbd_status usbd_transfer __P((usbd_request_handle req));
120 usbd_request_handle usbd_alloc_request __P((void));
121 usbd_status usbd_free_request __P((usbd_request_handle reqh));
122 usbd_status usbd_setup_request
123 __P((usbd_request_handle reqh, usbd_pipe_handle pipe,
124 usbd_private_handle priv, void *buffer,
125 u_int32_t length, u_int16_t flags, u_int32_t timeout,
126 usbd_callback));
127 usbd_status usbd_setup_device_request
128 __P((usbd_request_handle reqh, usb_device_request_t *req));
129 usbd_status usbd_setup_default_request
130 __P((usbd_request_handle reqh, usbd_device_handle dev,
131 usbd_private_handle priv, u_int32_t timeout,
132 usb_device_request_t *req, void *buffer,
133 u_int32_t length, u_int16_t flags, usbd_callback));
134 usbd_status usbd_set_request_timeout
135 __P((usbd_request_handle reqh, u_int32_t timeout));
136 usbd_status usbd_get_request_status
137 __P((usbd_request_handle reqh, usbd_private_handle *priv,
138 void **buffer, u_int32_t *count, usbd_status *status));
139 usbd_status usbd_request_device_data
140 __P((usbd_request_handle reqh, usb_device_request_t *req));
141 usb_descriptor_t *usbd_get_descriptor
142 __P((usbd_interface_handle *iface, u_int8_t desc_type));
143 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
144 __P((usbd_interface_handle iface, u_int8_t address));
145 usbd_status usbd_set_configuration
146 __P((usbd_device_handle dev, u_int8_t conf));
147 usbd_status usbd_retry_request
148 __P((usbd_request_handle reqh, u_int32_t retry_count));
149 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
150 usbd_status usbd_abort_interface __P((usbd_interface_handle iface));
151 usbd_status usbd_reset_pipe __P((usbd_pipe_handle pipe));
152 usbd_status usbd_reset_interface __P((usbd_interface_handle iface));
153 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
154 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe));
155 usbd_status usbd_set_pipe_state
156 __P((usbd_pipe_handle pipe, usbd_pipe_state state));
157 usbd_status usbd_get_pipe_state
158 __P((usbd_pipe_handle pipe, usbd_pipe_state *state,
159 u_int32_t *endpoint_state, u_int32_t *request_count));
160 usbd_status usbd_set_interface_state
161 __P((usbd_interface_handle iface, usbd_interface_state state));
162 usbd_status usbd_get_interface_state
163 __P((usbd_interface_handle iface, usbd_interface_state *state));
164 usbd_status usbd_get_device_state
165 __P((usbd_device_handle dev, usbd_device_state *state));
166 usbd_status usbd_set_device_state
167 __P((usbd_device_handle dev, usbd_device_state state));
168 usbd_status usbd_device_address
169 __P((usbd_device_handle dev, u_int8_t *address));
170 usbd_status usbd_endpoint_address
171 __P((usbd_pipe_handle dev, u_int8_t *address));
172 usbd_status usbd_endpoint_count
173 __P((usbd_interface_handle dev, u_int8_t *count));
174 usbd_status usbd_interface_count
175 __P((usbd_device_handle dev, u_int8_t *count));
176 u_int8_t usbd_bus_count __P((void));
177 usbd_status usbd_get_bus_handle __P((u_int8_t index, usbd_bus_handle *bus));
178 usbd_status usbd_get_root_hub
179 __P((usbd_bus_handle bus, usbd_device_handle *dev));
180 usbd_status usbd_port_count __P((usbd_device_handle hub, u_int8_t *nports));
181 usbd_status usbd_hub2device_handle
182 __P((usbd_device_handle hub, u_int8_t port, usbd_device_handle *dev));
183 usbd_status usbd_request2pipe_handle
184 __P((usbd_request_handle reqh, usbd_pipe_handle *pipe));
185 usbd_status usbd_pipe2interface_handle
186 __P((usbd_pipe_handle pipe, usbd_interface_handle *iface));
187 usbd_status usbd_interface2device_handle
188 __P((usbd_interface_handle iface, usbd_device_handle *dev));
189 usbd_status usbd_device2bus_handle
190 __P((usbd_device_handle dev, usbd_bus_handle *bus));
191 usbd_status usbd_device2interface_handle
192 __P((usbd_device_handle dev, u_int8_t ifaceno,
193 usbd_interface_handle *iface));
194 usbd_status usbd_set_interface_private_handle
195 __P((usbd_interface_handle iface, usbd_private_handle priv));
196 usbd_status usbd_get_interface_private_handle
197 __P((usbd_interface_handle iface, usbd_private_handle *priv));
198 usbd_status usbd_reference_pipe __P((usbd_pipe_handle pipe));
199 usbd_status usbd_dereference_pipe __P((usbd_pipe_handle pipe));
200 usbd_lock_token usbd_lock __P((void));
201 void usbd_unlock __P((usbd_lock_token tok));
202
203 /* Non-standard */
204 usbd_status usbd_sync_transfer __P((usbd_request_handle req));
205 usbd_status usbd_open_pipe_intr
206 __P((usbd_interface_handle iface, u_int8_t address,
207 u_int8_t flags, usbd_pipe_handle *pipe,
208 usbd_private_handle priv, void *buffer,
209 u_int32_t length, usbd_callback));
210 usbd_status usbd_open_pipe_iso
211 __P((usbd_interface_handle iface, u_int8_t address,
212 u_int8_t flags, usbd_pipe_handle *pipe,
213 usbd_private_handle priv, u_int32_t bufsize, u_int32_t nbuf,
214 usbd_callback));
215 usbd_status usbd_do_request
216 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
217 usbd_status usbd_do_request_async
218 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
219 usbd_status usbd_do_request_flags
220 __P((usbd_device_handle pipe, usb_device_request_t *req,
221 void *data, u_int16_t flags));
222 usb_interface_descriptor_t *usbd_get_interface_descriptor
223 __P((usbd_interface_handle iface));
224 usb_config_descriptor_t *usbd_get_config_descriptor
225 __P((usbd_device_handle dev));
226 usb_device_descriptor_t *usbd_get_device_descriptor
227 __P((usbd_device_handle dev));
228 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
229 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
230 usbd_status usbd_get_interface
231 __P((usbd_interface_handle iface, u_int8_t *aiface));
232 void usbd_fill_deviceinfo
233 __P((usbd_device_handle dev, struct usb_device_info *di));
234 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
235
236 usb_interface_descriptor_t *usbd_find_idesc
237 __P((usb_config_descriptor_t *cd, int iindex, int ano));
238 usb_endpoint_descriptor_t *usbd_find_edesc
239 __P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
240 int endptidx));
241
242 void usbd_dopoll __P((usbd_interface_handle));
243 void usbd_set_polling __P((usbd_interface_handle iface, int on));
244
245 /* NetBSD attachment information */
246
247 /* Attach data */
248 struct usb_attach_arg {
249 int port;
250 int configno;
251 int ifaceno;
252 usbd_device_handle device; /* current device */
253 usbd_interface_handle iface; /* current interface */
254 int usegeneric;
255 usbd_interface_handle *ifaces; /* all interfaces */
256 int nifaces; /* number of interfaces */
257 };
258
259 #if defined(__NetBSD__)
260 /* Match codes. */
261 /* First five codes is for a whole device. */
262 #define UMATCH_VENDOR_PRODUCT_REV 14
263 #define UMATCH_VENDOR_PRODUCT 13
264 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
265 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
266 #define UMATCH_DEVCLASS_DEVSUBCLASS 10
267 /* Next six codes are for interfaces. */
268 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
269 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
270 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
271 #define UMATCH_VENDOR_IFACESUBCLASS 6
272 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
273 #define UMATCH_IFACECLASS_IFACESUBCLASS 4
274 #define UMATCH_IFACECLASS 3
275 #define UMATCH_IFACECLASS_GENERIC 2
276 /* Generic driver */
277 #define UMATCH_GENERIC 1
278 /* No match */
279 #define UMATCH_NONE 0
280
281 #elif defined(__FreeBSD__)
282 /* FreeBSD needs values less than zero */
283 /* for the moment disabled
284 #define UMATCH_VENDOR_PRODUCT_REV -14
285 #define UMATCH_VENDOR_PRODUCT -13
286 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO -12
287 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO -11
288 #define UMATCH_DEVCLASS_DEVSUBCLASS -10
289 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE -9
290 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE -8
291 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO -7
292 #define UMATCH_VENDOR_IFACESUBCLASS -6
293 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO -5
294 #define UMATCH_IFACECLASS_IFACESUBCLASS -4
295 #define UMATCH_IFACECLASS -3
296 #define UMATCH_IFACECLASS_GENERIC -2
297 #define UMATCH_GENERIC -1
298 #define UMATCH_NONE ENXIO
299
300 * For the moment we use Yes/No answers with appropriate
301 * sorting in the config file
302 */
303 #define UMATCH_VENDOR_PRODUCT_REV 0
304 #define UMATCH_VENDOR_PRODUCT 0
305 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 0
306 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 0
307 #define UMATCH_DEVCLASS_DEVSUBCLASS 0
308 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 0
309 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 0
310 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 0
311 #define UMATCH_VENDOR_IFACESUBCLASS 0
312 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 0
313 #define UMATCH_IFACECLASS_IFACESUBCLASS 0
314 #define UMATCH_IFACECLASS 0
315 #define UMATCH_IFACECLASS_GENERIC 0
316 #define UMATCH_GENERIC 0
317 #define UMATCH_NONE ENXIO
318
319
320 #endif
321
322 void usbd_devinfo __P((usbd_device_handle, int, char *));
323 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
324 void usbd_set_disco __P((usbd_pipe_handle, void (*)(void *), void *));
325 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
326 __P((usbd_interface_handle iface, u_int8_t address));
327
328 /* XXX */
329 #define splusb splbio
330 #define IPL_USB IPL_BIO
331 /* XXX */
332
333