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