usbdi.h revision 1.27 1 /* $NetBSD: usbdi.h,v 1.27 1999/09/09 12:26: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_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((usbd_device_handle));
97 usbd_status usbd_free_request __P((usbd_request_handle reqh));
98 void 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 void 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_setup_isoc_request
109 __P((usbd_request_handle reqh, usbd_pipe_handle pipe,
110 usbd_private_handle priv, u_int16_t *frlengths,
111 u_int32_t nframes, usbd_callback));
112 void usbd_get_request_status
113 __P((usbd_request_handle reqh, usbd_private_handle *priv,
114 void **buffer, u_int32_t *count, usbd_status *status));
115 usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
116 __P((usbd_interface_handle iface, u_int8_t address));
117 usbd_status usbd_abort_pipe __P((usbd_pipe_handle pipe));
118 usbd_status usbd_clear_endpoint_stall __P((usbd_pipe_handle pipe));
119 usbd_status usbd_clear_endpoint_stall_async __P((usbd_pipe_handle pipe));
120 usbd_status usbd_endpoint_count
121 __P((usbd_interface_handle dev, u_int8_t *count));
122 usbd_status usbd_interface_count
123 __P((usbd_device_handle dev, u_int8_t *count));
124 usbd_status usbd_interface2device_handle
125 __P((usbd_interface_handle iface, usbd_device_handle *dev));
126 usbd_status usbd_device2interface_handle
127 __P((usbd_device_handle dev, u_int8_t ifaceno, usbd_interface_handle *iface));
128
129 usbd_device_handle usbd_pipe2device_handle __P((usbd_pipe_handle));
130 void *usbd_alloc_buffer __P((usbd_request_handle req, u_int32_t size));
131 void usbd_free_buffer __P((usbd_request_handle req));
132 usbd_status usbd_sync_transfer __P((usbd_request_handle req));
133 usbd_status usbd_open_pipe_intr
134 __P((usbd_interface_handle iface, u_int8_t address,
135 u_int8_t flags, usbd_pipe_handle *pipe,
136 usbd_private_handle priv, void *buffer,
137 u_int32_t length, usbd_callback));
138 usbd_status usbd_do_request
139 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
140 usbd_status usbd_do_request_async
141 __P((usbd_device_handle pipe, usb_device_request_t *req, void *data));
142 usbd_status usbd_do_request_flags
143 __P((usbd_device_handle pipe, usb_device_request_t *req,
144 void *data, u_int16_t flags, int *));
145 usb_interface_descriptor_t *usbd_get_interface_descriptor
146 __P((usbd_interface_handle iface));
147 usb_config_descriptor_t *usbd_get_config_descriptor
148 __P((usbd_device_handle dev));
149 usb_device_descriptor_t *usbd_get_device_descriptor
150 __P((usbd_device_handle dev));
151 usbd_status usbd_set_interface __P((usbd_interface_handle, int));
152 int usbd_get_no_alts __P((usb_config_descriptor_t *, int));
153 usbd_status usbd_get_interface
154 __P((usbd_interface_handle iface, u_int8_t *aiface));
155 void usbd_fill_deviceinfo
156 __P((usbd_device_handle dev, struct usb_device_info *di));
157 int usbd_get_interface_altindex __P((usbd_interface_handle iface));
158
159 usb_interface_descriptor_t *usbd_find_idesc
160 __P((usb_config_descriptor_t *cd, int iindex, int ano));
161 usb_endpoint_descriptor_t *usbd_find_edesc
162 __P((usb_config_descriptor_t *cd, int ifaceidx, int altidx,
163 int endptidx));
164
165 void usbd_dopoll __P((usbd_interface_handle));
166 void usbd_set_polling __P((usbd_interface_handle iface, int on));
167
168 const char *usbd_errstr __P((usbd_status err));
169
170 /* NetBSD attachment information */
171
172 /* Attach data */
173 struct usb_attach_arg {
174 int port;
175 int configno;
176 int ifaceno;
177 int vendor;
178 int product;
179 int release;
180 usbd_device_handle device; /* current device */
181 usbd_interface_handle iface; /* current interface */
182 int usegeneric;
183 usbd_interface_handle *ifaces; /* all interfaces */
184 int nifaces; /* number of interfaces */
185 };
186
187 #if defined(__NetBSD__) || defined(__OpenBSD__)
188 /* Match codes. */
189 /* First five codes is for a whole device. */
190 #define UMATCH_VENDOR_PRODUCT_REV 14
191 #define UMATCH_VENDOR_PRODUCT 13
192 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
193 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
194 #define UMATCH_DEVCLASS_DEVSUBCLASS 10
195 /* Next six codes are for interfaces. */
196 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
197 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
198 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
199 #define UMATCH_VENDOR_IFACESUBCLASS 6
200 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
201 #define UMATCH_IFACECLASS_IFACESUBCLASS 4
202 #define UMATCH_IFACECLASS 3
203 #define UMATCH_IFACECLASS_GENERIC 2
204 /* Generic driver */
205 #define UMATCH_GENERIC 1
206 /* No match */
207 #define UMATCH_NONE 0
208
209 #elif defined(__FreeBSD__)
210 /* FreeBSD needs values less than zero */
211 /* for the moment disabled
212 #define UMATCH_VENDOR_PRODUCT_REV -14
213 #define UMATCH_VENDOR_PRODUCT -13
214 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO -12
215 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO -11
216 #define UMATCH_DEVCLASS_DEVSUBCLASS -10
217 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE -9
218 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE -8
219 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO -7
220 #define UMATCH_VENDOR_IFACESUBCLASS -6
221 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO -5
222 #define UMATCH_IFACECLASS_IFACESUBCLASS -4
223 #define UMATCH_IFACECLASS -3
224 #define UMATCH_IFACECLASS_GENERIC -2
225 #define UMATCH_GENERIC -1
226 #define UMATCH_NONE ENXIO
227
228 * For the moment we use Yes/No answers with appropriate
229 * sorting in the config file
230 */
231 #define UMATCH_VENDOR_PRODUCT_REV 0
232 #define UMATCH_VENDOR_PRODUCT 0
233 #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 0
234 #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 0
235 #define UMATCH_DEVCLASS_DEVSUBCLASS 0
236 #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 0
237 #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 0
238 #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 0
239 #define UMATCH_VENDOR_IFACESUBCLASS 0
240 #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 0
241 #define UMATCH_IFACECLASS_IFACESUBCLASS 0
242 #define UMATCH_IFACECLASS 0
243 #define UMATCH_IFACECLASS_GENERIC 0
244 #define UMATCH_GENERIC 0
245 #define UMATCH_NONE ENXIO
246
247
248 #endif
249
250 void usbd_devinfo __P((usbd_device_handle, int, char *));
251 struct usbd_quirks *usbd_get_quirks __P((usbd_device_handle));
252 usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
253 __P((usbd_interface_handle iface, u_int8_t address));
254
255 #if defined(__FreeBSD__)
256 int usbd_driver_load __P((module_t mod, int what, void *arg));
257 void usbd_device_set_desc __P((device_t device, char *devinfo));
258 char *usbd_devname(device_t *bdev);
259 bus_print_child_t usbd_print_child;
260 #endif
261
262 /* XXX */
263 #define splusb splbio
264 #define IPL_USB IPL_BIO
265 /* XXX */
266
267