usbdi.h revision 1.49 1 1.49 augustss /* $NetBSD: usbdi.h,v 1.49 2001/01/23 17:04:30 augustss Exp $ */
2 1.34 augustss /* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
3 1.1 augustss
4 1.1 augustss /*
5 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 1.1 augustss * All rights reserved.
7 1.1 augustss *
8 1.7 augustss * This code is derived from software contributed to The NetBSD Foundation
9 1.42 augustss * by Lennart Augustsson (lennart (at) augustsson.net) at
10 1.7 augustss * Carlstedt Research & Technology.
11 1.1 augustss *
12 1.1 augustss * Redistribution and use in source and binary forms, with or without
13 1.1 augustss * modification, are permitted provided that the following conditions
14 1.1 augustss * are met:
15 1.1 augustss * 1. Redistributions of source code must retain the above copyright
16 1.1 augustss * notice, this list of conditions and the following disclaimer.
17 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 augustss * notice, this list of conditions and the following disclaimer in the
19 1.1 augustss * documentation and/or other materials provided with the distribution.
20 1.1 augustss * 3. All advertising materials mentioning features or use of this software
21 1.1 augustss * must display the following acknowledgement:
22 1.1 augustss * This product includes software developed by the NetBSD
23 1.1 augustss * Foundation, Inc. and its contributors.
24 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
25 1.1 augustss * contributors may be used to endorse or promote products derived
26 1.1 augustss * from this software without specific prior written permission.
27 1.1 augustss *
28 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
39 1.1 augustss */
40 1.1 augustss
41 1.1 augustss typedef struct usbd_bus *usbd_bus_handle;
42 1.1 augustss typedef struct usbd_device *usbd_device_handle;
43 1.1 augustss typedef struct usbd_interface *usbd_interface_handle;
44 1.1 augustss typedef struct usbd_pipe *usbd_pipe_handle;
45 1.32 augustss typedef struct usbd_xfer *usbd_xfer_handle;
46 1.1 augustss typedef void *usbd_private_handle;
47 1.1 augustss
48 1.31 augustss typedef enum { /* keep in sync with usbd_status_msgs */
49 1.23 augustss USBD_NORMAL_COMPLETION = 0, /* must be 0 */
50 1.1 augustss USBD_IN_PROGRESS,
51 1.1 augustss /* errors */
52 1.1 augustss USBD_PENDING_REQUESTS,
53 1.1 augustss USBD_NOT_STARTED,
54 1.1 augustss USBD_INVAL,
55 1.1 augustss USBD_NOMEM,
56 1.1 augustss USBD_CANCELLED,
57 1.1 augustss USBD_BAD_ADDRESS,
58 1.1 augustss USBD_IN_USE,
59 1.1 augustss USBD_NO_ADDR,
60 1.1 augustss USBD_SET_ADDR_FAILED,
61 1.1 augustss USBD_NO_POWER,
62 1.1 augustss USBD_TOO_DEEP,
63 1.1 augustss USBD_IOERROR,
64 1.1 augustss USBD_NOT_CONFIGURED,
65 1.1 augustss USBD_TIMEOUT,
66 1.1 augustss USBD_SHORT_XFER,
67 1.1 augustss USBD_STALLED,
68 1.14 augustss USBD_INTERRUPTED,
69 1.1 augustss
70 1.23 augustss USBD_ERROR_MAX, /* must be last */
71 1.1 augustss } usbd_status;
72 1.1 augustss
73 1.43 augustss typedef void (*usbd_callback)(usbd_xfer_handle, usbd_private_handle,
74 1.43 augustss usbd_status);
75 1.1 augustss
76 1.1 augustss /* Open flags */
77 1.1 augustss #define USBD_EXCLUSIVE_USE 0x01
78 1.1 augustss
79 1.39 augustss /* Use default (specified by ep. desc.) interval on interrupt pipe */
80 1.39 augustss #define USBD_DEFAULT_INTERVAL (-1)
81 1.39 augustss
82 1.1 augustss /* Request flags */
83 1.29 augustss #define USBD_NO_COPY 0x01 /* do not copy data to DMA buffer */
84 1.29 augustss #define USBD_SYNCHRONOUS 0x02 /* wait for completion */
85 1.28 augustss /* in usb.h #define USBD_SHORT_XFER_OK 0x04*/ /* allow short reads */
86 1.37 augustss #define USBD_FORCE_SHORT_XFER 0x08 /* force last short packet on write */
87 1.37 augustss
88 1.37 augustss /* XXX Temporary hack XXX */
89 1.37 augustss #define USBD_NO_TSLEEP 0x80 /* XXX use busy wait */
90 1.1 augustss
91 1.1 augustss #define USBD_NO_TIMEOUT 0
92 1.1 augustss #define USBD_DEFAULT_TIMEOUT 5000 /* ms = 5 s */
93 1.1 augustss
94 1.31 augustss #if defined(__FreeBSD__)
95 1.31 augustss #define USB_CDEV_MAJOR 108
96 1.31 augustss #endif
97 1.31 augustss
98 1.43 augustss usbd_status usbd_open_pipe(usbd_interface_handle iface, u_int8_t address,
99 1.43 augustss u_int8_t flags, usbd_pipe_handle *pipe);
100 1.43 augustss usbd_status usbd_close_pipe(usbd_pipe_handle pipe);
101 1.43 augustss usbd_status usbd_transfer(usbd_xfer_handle req);
102 1.43 augustss usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle);
103 1.43 augustss usbd_status usbd_free_xfer(usbd_xfer_handle xfer);
104 1.43 augustss void usbd_setup_xfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
105 1.43 augustss usbd_private_handle priv, void *buffer,
106 1.43 augustss u_int32_t length, u_int16_t flags, u_int32_t timeout,
107 1.43 augustss usbd_callback);
108 1.43 augustss void usbd_setup_default_xfer(usbd_xfer_handle xfer, usbd_device_handle dev,
109 1.43 augustss usbd_private_handle priv, u_int32_t timeout,
110 1.43 augustss usb_device_request_t *req, void *buffer,
111 1.43 augustss u_int32_t length, u_int16_t flags, usbd_callback);
112 1.43 augustss void usbd_setup_isoc_xfer(usbd_xfer_handle xfer, usbd_pipe_handle pipe,
113 1.43 augustss usbd_private_handle priv, u_int16_t *frlengths,
114 1.43 augustss u_int32_t nframes, u_int16_t flags, usbd_callback);
115 1.43 augustss void usbd_get_xfer_status(usbd_xfer_handle xfer, usbd_private_handle *priv,
116 1.43 augustss void **buffer, u_int32_t *count, usbd_status *status);
117 1.1 augustss usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor
118 1.43 augustss (usbd_interface_handle iface, u_int8_t address);
119 1.43 augustss usbd_status usbd_abort_pipe(usbd_pipe_handle pipe);
120 1.43 augustss usbd_status usbd_clear_endpoint_stall(usbd_pipe_handle pipe);
121 1.43 augustss usbd_status usbd_clear_endpoint_stall_async(usbd_pipe_handle pipe);
122 1.43 augustss usbd_status usbd_endpoint_count(usbd_interface_handle dev, u_int8_t *count);
123 1.43 augustss usbd_status usbd_interface_count(usbd_device_handle dev, u_int8_t *count);
124 1.43 augustss usbd_status usbd_interface2device_handle(usbd_interface_handle iface,
125 1.43 augustss usbd_device_handle *dev);
126 1.43 augustss usbd_status usbd_device2interface_handle(usbd_device_handle dev,
127 1.43 augustss u_int8_t ifaceno, usbd_interface_handle *iface);
128 1.43 augustss
129 1.43 augustss usbd_device_handle usbd_pipe2device_handle(usbd_pipe_handle);
130 1.43 augustss void *usbd_alloc_buffer(usbd_xfer_handle req, u_int32_t size);
131 1.43 augustss void usbd_free_buffer(usbd_xfer_handle req);
132 1.43 augustss void *usbd_get_buffer(usbd_xfer_handle xfer);
133 1.43 augustss usbd_status usbd_sync_transfer(usbd_xfer_handle req);
134 1.43 augustss usbd_status usbd_open_pipe_intr(usbd_interface_handle iface, u_int8_t address,
135 1.43 augustss u_int8_t flags, usbd_pipe_handle *pipe,
136 1.43 augustss usbd_private_handle priv, void *buffer,
137 1.43 augustss u_int32_t length, usbd_callback, int);
138 1.43 augustss usbd_status usbd_do_request(usbd_device_handle pipe, usb_device_request_t *req,
139 1.43 augustss void *data);
140 1.43 augustss usbd_status usbd_do_request_async(usbd_device_handle pipe,
141 1.43 augustss usb_device_request_t *req, void *data);
142 1.43 augustss usbd_status usbd_do_request_flags(usbd_device_handle pipe,
143 1.43 augustss usb_device_request_t *req,
144 1.43 augustss void *data, u_int16_t flags, int *);
145 1.44 augustss usbd_status usbd_do_request_flags_pipe(
146 1.44 augustss usbd_device_handle dev, usbd_pipe_handle pipe,
147 1.44 augustss usb_device_request_t *req, void *data, u_int16_t flags, int *actlen);
148 1.1 augustss usb_interface_descriptor_t *usbd_get_interface_descriptor
149 1.43 augustss (usbd_interface_handle iface);
150 1.43 augustss usb_config_descriptor_t *usbd_get_config_descriptor(usbd_device_handle dev);
151 1.43 augustss usb_device_descriptor_t *usbd_get_device_descriptor(usbd_device_handle dev);
152 1.43 augustss usbd_status usbd_set_interface(usbd_interface_handle, int);
153 1.43 augustss int usbd_get_no_alts(usb_config_descriptor_t *, int);
154 1.43 augustss usbd_status usbd_get_interface(usbd_interface_handle iface, u_int8_t *aiface);
155 1.45 augustss void usbd_fill_deviceinfo(usbd_device_handle dev, struct usb_device_info *di, int);
156 1.43 augustss int usbd_get_interface_altindex(usbd_interface_handle iface);
157 1.43 augustss
158 1.43 augustss usb_interface_descriptor_t *usbd_find_idesc(usb_config_descriptor_t *cd,
159 1.43 augustss int iindex, int ano);
160 1.43 augustss usb_endpoint_descriptor_t *usbd_find_edesc(usb_config_descriptor_t *cd,
161 1.43 augustss int ifaceidx, int altidx,
162 1.43 augustss int endptidx);
163 1.43 augustss
164 1.43 augustss void usbd_dopoll(usbd_interface_handle);
165 1.43 augustss void usbd_set_polling(usbd_device_handle iface, int on);
166 1.23 augustss
167 1.43 augustss const char *usbd_errstr(usbd_status err);
168 1.30 augustss
169 1.43 augustss void usbd_add_dev_event(int, usbd_device_handle);
170 1.43 augustss void usbd_add_drv_event(int, usbd_device_handle, device_ptr_t);
171 1.1 augustss
172 1.43 augustss void usbd_devinfo(usbd_device_handle, int, char *);
173 1.46 jdolecek const struct usbd_quirks *usbd_get_quirks(usbd_device_handle);
174 1.38 augustss usb_endpoint_descriptor_t *usbd_get_endpoint_descriptor
175 1.43 augustss (usbd_interface_handle iface, u_int8_t address);
176 1.38 augustss
177 1.43 augustss usbd_status usbd_reload_device_desc(usbd_device_handle);
178 1.41 augustss
179 1.43 augustss int usbd_ratecheck(struct timeval *last);
180 1.48 augustss
181 1.48 augustss /*
182 1.48 augustss * The usb_task structs form a queue of things to run in the USB event
183 1.48 augustss * thread. Normally this is just device discovery when a connect/disconnect
184 1.48 augustss * has been detected. But it may also be used by drivers that need to
185 1.48 augustss * perform (short) tasks that must have a process context.
186 1.48 augustss */
187 1.48 augustss struct usb_task {
188 1.49 augustss TAILQ_ENTRY(usb_task) next;
189 1.48 augustss void (*fun)(void *);
190 1.48 augustss void *arg;
191 1.48 augustss char onqueue;
192 1.48 augustss };
193 1.48 augustss
194 1.48 augustss void usb_add_task(usbd_device_handle dev, struct usb_task *task);
195 1.49 augustss void usb_rem_task(usbd_device_handle dev, struct usb_task *task);
196 1.49 augustss #define usb_init_task(t, f, a) ((t)->fun = (f), (t)->arg = (a), (t)->onqueue = 0)
197 1.38 augustss
198 1.1 augustss /* NetBSD attachment information */
199 1.1 augustss
200 1.1 augustss /* Attach data */
201 1.1 augustss struct usb_attach_arg {
202 1.1 augustss int port;
203 1.8 augustss int configno;
204 1.8 augustss int ifaceno;
205 1.18 augustss int vendor;
206 1.18 augustss int product;
207 1.18 augustss int release;
208 1.13 augustss usbd_device_handle device; /* current device */
209 1.13 augustss usbd_interface_handle iface; /* current interface */
210 1.1 augustss int usegeneric;
211 1.13 augustss usbd_interface_handle *ifaces; /* all interfaces */
212 1.13 augustss int nifaces; /* number of interfaces */
213 1.1 augustss };
214 1.1 augustss
215 1.22 augustss #if defined(__NetBSD__) || defined(__OpenBSD__)
216 1.1 augustss /* Match codes. */
217 1.1 augustss /* First five codes is for a whole device. */
218 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV 14
219 1.1 augustss #define UMATCH_VENDOR_PRODUCT 13
220 1.1 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO 12
221 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO 11
222 1.1 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS 10
223 1.1 augustss /* Next six codes are for interfaces. */
224 1.1 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE 9
225 1.1 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE 8
226 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO 7
227 1.1 augustss #define UMATCH_VENDOR_IFACESUBCLASS 6
228 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO 5
229 1.1 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS 4
230 1.1 augustss #define UMATCH_IFACECLASS 3
231 1.1 augustss #define UMATCH_IFACECLASS_GENERIC 2
232 1.1 augustss /* Generic driver */
233 1.1 augustss #define UMATCH_GENERIC 1
234 1.1 augustss /* No match */
235 1.1 augustss #define UMATCH_NONE 0
236 1.12 augustss
237 1.12 augustss #elif defined(__FreeBSD__)
238 1.12 augustss /* FreeBSD needs values less than zero */
239 1.31 augustss #define UMATCH_VENDOR_PRODUCT_REV (-10)
240 1.31 augustss #define UMATCH_VENDOR_PRODUCT (-20)
241 1.31 augustss #define UMATCH_VENDOR_DEVCLASS_DEVPROTO (-30)
242 1.31 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO (-40)
243 1.31 augustss #define UMATCH_DEVCLASS_DEVSUBCLASS (-50)
244 1.31 augustss #define UMATCH_VENDOR_PRODUCT_REV_CONF_IFACE (-60)
245 1.31 augustss #define UMATCH_VENDOR_PRODUCT_CONF_IFACE (-70)
246 1.31 augustss #define UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO (-80)
247 1.31 augustss #define UMATCH_VENDOR_IFACESUBCLASS (-90)
248 1.31 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO (-100)
249 1.31 augustss #define UMATCH_IFACECLASS_IFACESUBCLASS (-110)
250 1.31 augustss #define UMATCH_IFACECLASS (-120)
251 1.31 augustss #define UMATCH_IFACECLASS_GENERIC (-130)
252 1.31 augustss #define UMATCH_GENERIC (-140)
253 1.31 augustss #define UMATCH_NONE (ENXIO)
254 1.12 augustss
255 1.12 augustss #endif
256 1.16 augustss
257 1.16 augustss #if defined(__FreeBSD__)
258 1.43 augustss int usbd_driver_load(module_t mod, int what, void *arg);
259 1.16 augustss #endif
260 1.10 augustss
261 1.47 augustss /* XXX Perhaps USB should have its own levels? */
262 1.47 augustss #ifdef USB_USE_SOFTINTR
263 1.47 augustss #define splusb splsoftnet
264 1.47 augustss #else
265 1.10 augustss #define splusb splbio
266 1.47 augustss #endif
267 1.40 augustss #define splhardusb splbio
268 1.10 augustss #define IPL_USB IPL_BIO
269