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