usbdi.h revision 1.26 1 /* $NetBSD: usbdi.h,v 1.26 1999/09/05 19:32:19 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_NORMAL_COMPLETION = 0, /* must be 0 */
49 USBD_IN_PROGRESS,
50 /* errors */
51 USBD_PENDING_REQUESTS,
52 USBD_NOT_STARTED,
53 USBD_INVAL,
54 USBD_NOMEM,
55 USBD_CANCELLED,
56 USBD_BAD_ADDRESS,
57 USBD_IN_USE,
58 USBD_NO_ADDR,
59 USBD_SET_ADDR_FAILED,
60 USBD_NO_POWER,
61 USBD_TOO_DEEP,
62 USBD_IOERROR,
63 USBD_NOT_CONFIGURED,
64 USBD_TIMEOUT,
65 USBD_SHORT_XFER,
66 USBD_STALLED,
67 USBD_INTERRUPTED,
68
69 USBD_XXX,
70
71 USBD_ERROR_MAX, /* must be last */
72 } usbd_status;
73
74 typedef int usbd_lock_token;
75
76 typedef void (*usbd_callback) __P((usbd_request_handle, usbd_private_handle,
77 usbd_status));
78
79 /* Open flags */
80 #define USBD_EXCLUSIVE_USE 0x01
81
82 /* Request flags */
83 #define USBD_XFER_OUT 0x01
84 #define USBD_XFER_IN 0x02
85 #define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
86 #define USBD_SYNCHRONOUS 0x08 /* wait for completion */
87
88 #define USBD_NO_TIMEOUT 0
89 #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
90
91 usbd_status usbd_open_pipe
92 __P((usbd_interface_handle iface, u_int8_t address,
93 u_int8_t flags, usbd_pipe_handle *pipe));
94 usbd_status usbd_close_pipe __P((usbd_pipe_handle pipe));
95 usbd_status usbd_transfer __P((usbd_request_handle req));
96 usbd_request_handle usbd_alloc_request __P((void));
97 usbd_status usbd_free_request __P((usbd_request_handle reqh));
98 usbd_status usbd_setup_request
99 __P((usbd_request_handle reqh, usbd_pipe_handle pipe,
100 usbd_private_handle priv, void *buffer,
101 u_int32_t length, u_int16_t flags, u_int32_t timeout,
102 usbd_callback));
103 usbd_status usbd_setup_default_request
104 __P((usbd_request_handle reqh, usbd_device_handle dev,
105 usbd_private_handle priv, u_int32_t timeout,
106 usb_device_request_t *req, void *buffer,
107 u_int32_t length, u_int16_t flags, usbd_callback));
108 void usbd_get_request_status
109 __P((usbd_request_handle reqh, usbd_private_handle *priv,
110 void **buffer, u_int32_t *count, usbd_status *status));
111 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
112 __P((usbd_interface_handle iface, u_int8_t address));
113 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
114 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
115 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe));
116 usbd_status usbd_endpoint_count
117 __P((usbd_interface_handle dev, u_int8_t *count));
118 usbd_status usbd_interface_count
119 __P((usbd_device_handle dev, u_int8_t *count));
120 usbd_status usbd_interface2device_handle
121 __P((usbd_interface_handle iface, usbd_device_handle *dev));
122 usbd_status usbd_device2interface_handle
123 __P((usbd_device_handle dev, u_int8_t ifaceno, usbd_interface_handle *iface));
124
125 /* Non-standard */
126 usbd_status usbd_sync_transfer __P((usbd_request_handle req));
127 usbd_status usbd_open_pipe_intr
128 __P((usbd_interface_handle iface, u_int8_t address,
129 u_int8_t flags, usbd_pipe_handle *pipe,
130 usbd_private_handle priv, void *buffer,
131 u_int32_t length, usbd_callback));
132 usbd_status usbd_open_pipe_iso
133 __P((usbd_interface_handle iface, u_int8_t address,
134 u_int8_t flags, usbd_pipe_handle *pipe,
135 usbd_private_handle priv, u_int32_t bufsize, u_int32_t nbuf));
136 usbd_status usbd_do_request
137 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
138 usbd_status usbd_do_request_async
139 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
140 usbd_status usbd_do_request_flags
141 __P((usbd_device_handle pipe, usb_device_request_t *req,
142 void *data, u_int16_t flags, int *));
143 usb_interface_descriptor_t *usbd_get_interface_descriptor
144 __P((usbd_interface_handle iface));
145 usb_config_descriptor_t *usbd_get_config_descriptor
146 __P((usbd_device_handle dev));
147 usb_device_descriptor_t *usbd_get_device_descriptor
148 __P((usbd_device_handle dev));
149 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
150 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
151 usbd_status usbd_get_interface
152 __P((usbd_interface_handle iface, u_int8_t *aiface));
153 void usbd_fill_deviceinfo
154 __P((usbd_device_handle dev, struct usb_device_info *di));
155 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
156
157 usb_interface_descriptor_t *usbd_find_idesc
158 __P((usb_config_descriptor_t *cd, int iindex, int ano));
159 usb_endpoint_descriptor_t *usbd_find_edesc
160 __P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
161 int endptidx));
162
163 void usbd_dopoll __P((usbd_interface_handle));
164 void usbd_set_polling __P((usbd_interface_handle iface, int on));
165
166 const char *usbd_errstr __P((usbd_status err));
167
168 /* NetBSD attachment information */
169
170 /* Attach data */
171 struct usb_attach_arg {
172 int port;
173 int configno;
174 int ifaceno;
175 int vendor;
176 int product;
177 int release;
178 usbd_device_handle device; /* current device */
179 usbd_interface_handle iface; /* current interface */
180 int usegeneric;
181 usbd_interface_handle *ifaces; /* all interfaces */
182 int nifaces; /* number of interfaces */
183 };
184
185 #if defined(__NetBSD__) || defined(__OpenBSD__)
186 /* Match codes. */
187 /* First five codes is for a whole device. */
188 #define UMATCH_VENDOR_PRODUCT_REV 14
189 #define UMATCH_VENDOR_PRODUCT 13
190 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
191 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
192 #define UMATCH_DEVCLASS_DEVSUBCLASS 10
193 /* Next six codes are for interfaces. */
194 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
195 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
196 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
197 #define UMATCH_VENDOR_IFACESUBCLASS 6
198 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
199 #define UMATCH_IFACECLASS_IFACESUBCLASS 4
200 #define UMATCH_IFACECLASS 3
201 #define UMATCH_IFACECLASS_GENERIC 2
202 /* Generic driver */
203 #define UMATCH_GENERIC 1
204 /* No match */
205 #define UMATCH_NONE 0
206
207 #elif defined(__FreeBSD__)
208 /* FreeBSD needs values less than zero */
209 /* for the moment disabled
210 #define UMATCH_VENDOR_PRODUCT_REV -14
211 #define UMATCH_VENDOR_PRODUCT -13
212 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO -12
213 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO -11
214 #define UMATCH_DEVCLASS_DEVSUBCLASS -10
215 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE -9
216 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE -8
217 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO -7
218 #define UMATCH_VENDOR_IFACESUBCLASS -6
219 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO -5
220 #define UMATCH_IFACECLASS_IFACESUBCLASS -4
221 #define UMATCH_IFACECLASS -3
222 #define UMATCH_IFACECLASS_GENERIC -2
223 #define UMATCH_GENERIC -1
224 #define UMATCH_NONE ENXIO
225
226 * For the moment we use Yes/No answers with appropriate
227 * sorting in the config file
228 */
229 #define UMATCH_VENDOR_PRODUCT_REV 0
230 #define UMATCH_VENDOR_PRODUCT 0
231 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 0
232 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 0
233 #define UMATCH_DEVCLASS_DEVSUBCLASS 0
234 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 0
235 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 0
236 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 0
237 #define UMATCH_VENDOR_IFACESUBCLASS 0
238 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 0
239 #define UMATCH_IFACECLASS_IFACESUBCLASS 0
240 #define UMATCH_IFACECLASS 0
241 #define UMATCH_IFACECLASS_GENERIC 0
242 #define UMATCH_GENERIC 0
243 #define UMATCH_NONE ENXIO
244
245
246 #endif
247
248 void usbd_devinfo __P((usbd_device_handle, int, char *));
249 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
250 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
251 __P((usbd_interface_handle iface, u_int8_t address));
252
253 #if defined(__FreeBSD__)
254 int usbd_driver_load __P((module_t mod, int what, void *arg));
255 void usbd_device_set_desc __P((device_t device, char *devinfo));
256 char *usbd_devname(device_t *bdev);
257 bus_print_child_t usbd_print_child;
258 #endif
259
260 /* XXX */
261 #define splusb splbio
262 #define IPL_USB IPL_BIO
263 /* XXX */
264
265