xref: /illumos-gate/usr/src/contrib/bhyve/dev/usb/usbdi.h (revision fc910014e8a32a65612105835a10995f2c13d942)
1 /*-
2  * Copyright (c) 2009 Andrew Thompson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 #ifndef _USB_USBDI_H_
25 #define _USB_USBDI_H_
26 
27 struct usb_fifo;
28 struct usb_xfer;
29 struct usb_device;
30 struct usb_attach_arg;
31 struct usb_interface;
32 struct usb_endpoint;
33 struct usb_page_cache;
34 struct usb_page_search;
35 struct usb_process;
36 struct usb_proc_msg;
37 struct usb_mbuf;
38 struct usb_fs_privdata;
39 struct mbuf;
40 
41 typedef enum {	/* keep in sync with usb_errstr_table */
42 	USB_ERR_NORMAL_COMPLETION = 0,
43 	USB_ERR_PENDING_REQUESTS,	/* 1 */
44 	USB_ERR_NOT_STARTED,		/* 2 */
45 	USB_ERR_INVAL,			/* 3 */
46 	USB_ERR_NOMEM,			/* 4 */
47 	USB_ERR_CANCELLED,		/* 5 */
48 	USB_ERR_BAD_ADDRESS,		/* 6 */
49 	USB_ERR_BAD_BUFSIZE,		/* 7 */
50 	USB_ERR_BAD_FLAG,		/* 8 */
51 	USB_ERR_NO_CALLBACK,		/* 9 */
52 	USB_ERR_IN_USE,			/* 10 */
53 	USB_ERR_NO_ADDR,		/* 11 */
54 	USB_ERR_NO_PIPE,		/* 12 */
55 	USB_ERR_ZERO_NFRAMES,		/* 13 */
56 	USB_ERR_ZERO_MAXP,		/* 14 */
57 	USB_ERR_SET_ADDR_FAILED,	/* 15 */
58 	USB_ERR_NO_POWER,		/* 16 */
59 	USB_ERR_TOO_DEEP,		/* 17 */
60 	USB_ERR_IOERROR,		/* 18 */
61 	USB_ERR_NOT_CONFIGURED,		/* 19 */
62 	USB_ERR_TIMEOUT,		/* 20 */
63 	USB_ERR_SHORT_XFER,		/* 21 */
64 	USB_ERR_STALLED,		/* 22 */
65 	USB_ERR_INTERRUPTED,		/* 23 */
66 	USB_ERR_DMA_LOAD_FAILED,	/* 24 */
67 	USB_ERR_BAD_CONTEXT,		/* 25 */
68 	USB_ERR_NO_ROOT_HUB,		/* 26 */
69 	USB_ERR_NO_INTR_THREAD,		/* 27 */
70 	USB_ERR_NOT_LOCKED,		/* 28 */
71 	USB_ERR_MAX
72 } usb_error_t;
73 
74 /*
75  * Flags for transfers
76  */
77 #define	USB_FORCE_SHORT_XFER	0x0001	/* force a short transmit last */
78 #define	USB_SHORT_XFER_OK	0x0004	/* allow short reads */
79 #define	USB_DELAY_STATUS_STAGE	0x0010	/* insert delay before STATUS stage */
80 #define	USB_USER_DATA_PTR	0x0020	/* internal flag */
81 #define	USB_MULTI_SHORT_OK	0x0040	/* allow multiple short frames */
82 #define	USB_MANUAL_STATUS	0x0080	/* manual ctrl status */
83 
84 #define	USB_NO_TIMEOUT 0
85 #define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */
86 
87 #if defined(_KERNEL)
88 /* typedefs */
89 
90 typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
91 typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
92 typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
93     struct usb_device_request *, const void **, uint16_t *);
94 
95 typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
96 typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
97 typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
98 typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
99 typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
100 
101 
102 /* USB events */
103 #ifndef USB_GLOBAL_INCLUDE_FILE
104 #include <sys/eventhandler.h>
105 #endif
106 typedef void (*usb_dev_configured_t)(void *, struct usb_device *,
107     struct usb_attach_arg *);
108 EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t);
109 
110 /*
111  * The following macros are used used to convert milliseconds into
112  * HZ. We use 1024 instead of 1000 milliseconds per second to save a
113  * full division.
114  */
115 #define	USB_MS_HZ 1024
116 
117 #define	USB_MS_TO_TICKS(ms) \
118   (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
119 
120 /*
121  * Common queue structure for USB transfers.
122  */
123 struct usb_xfer_queue {
124 	TAILQ_HEAD(, usb_xfer) head;
125 	struct usb_xfer *curr;		/* current USB transfer processed */
126 	void    (*command) (struct usb_xfer_queue *pq);
127 	uint8_t	recurse_1:1;
128 	uint8_t	recurse_2:1;
129 	uint8_t	recurse_3:1;
130 	uint8_t	reserved:5;
131 };
132 
133 /*
134  * The following structure defines an USB endpoint
135  * USB endpoint.
136  */
137 struct usb_endpoint {
138 	/* queue of USB transfers */
139 	struct usb_xfer_queue endpoint_q[USB_MAX_EP_STREAMS];
140 
141 	struct usb_endpoint_descriptor *edesc;
142 	struct usb_endpoint_ss_comp_descriptor *ecomp;
143 	const struct usb_pipe_methods *methods;	/* set by HC driver */
144 
145 	uint16_t isoc_next;
146 
147 	uint8_t	toggle_next:1;		/* next data toggle value */
148 	uint8_t	is_stalled:1;		/* set if endpoint is stalled */
149 	uint8_t	is_synced:1;		/* set if we a synchronised */
150 	uint8_t	unused:5;
151 	uint8_t	iface_index;		/* not used by "default endpoint" */
152 
153 	uint8_t refcount_alloc;		/* allocation refcount */
154 	uint8_t refcount_bw;		/* bandwidth refcount */
155 #define	USB_EP_REF_MAX 0x3f
156 
157 	/* High-Speed resource allocation (valid if "refcount_bw" > 0) */
158 
159 	uint8_t	usb_smask;		/* USB start mask */
160 	uint8_t	usb_cmask;		/* USB complete mask */
161 	uint8_t	usb_uframe;		/* USB microframe */
162 
163 	/* USB endpoint mode, see USB_EP_MODE_XXX */
164 
165 	uint8_t ep_mode;
166 };
167 
168 /*
169  * The following structure defines an USB interface.
170  */
171 struct usb_interface {
172 	struct usb_interface_descriptor *idesc;
173 	device_t subdev;
174 	uint8_t	alt_index;
175 	uint8_t	parent_iface_index;
176 
177 	/* Linux compat */
178 	struct usb_host_interface *altsetting;
179 	struct usb_host_interface *cur_altsetting;
180 	struct usb_device *linux_udev;
181 	void   *bsd_priv_sc;		/* device specific information */
182 	char   *pnpinfo;		/* additional PnP-info for this interface */
183 	uint8_t	num_altsetting;		/* number of alternate settings */
184 	uint8_t	bsd_iface_index;
185 };
186 
187 /*
188  * The following structure defines a set of USB transfer flags.
189  */
190 struct usb_xfer_flags {
191 	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
192 					 * last */
193 	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
194 	uint8_t	short_frames_ok:1;	/* allow short frames */
195 	uint8_t	pipe_bof:1;		/* block pipe on failure */
196 	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
197 					 * "max_frame_size" */
198 	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
199 	uint8_t	manual_status:1;	/* non automatic status stage on
200 					 * control transfers */
201 	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
202 					 * be ignored */
203 	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
204 					 * this USB transfer should be stalled
205 					 * before starting this transfer! */
206 	uint8_t pre_scale_frames:1;	/* "usb_config->frames" is
207 					 * assumed to give the
208 					 * buffering time in
209 					 * milliseconds and is
210 					 * converted into the nearest
211 					 * number of frames when the
212 					 * USB transfer is setup. This
213 					 * option only has effect for
214 					 * ISOCHRONOUS transfers.
215 					 */
216 };
217 
218 /*
219  * The following structure define an USB configuration, that basically
220  * is used when setting up an USB transfer.
221  */
222 struct usb_config {
223 	usb_callback_t *callback;	/* USB transfer callback */
224 	usb_frlength_t bufsize;	/* total pipe buffer size in bytes */
225 	usb_frcount_t frames;		/* maximum number of USB frames */
226 	usb_timeout_t interval;	/* interval in milliseconds */
227 #define	USB_DEFAULT_INTERVAL	0
228 	usb_timeout_t timeout;		/* transfer timeout in milliseconds */
229 	struct usb_xfer_flags flags;	/* transfer flags */
230 	usb_stream_t stream_id;		/* USB3.0 specific */
231 	enum usb_hc_mode usb_mode;	/* host or device mode */
232 	uint8_t	type;			/* pipe type */
233 	uint8_t	endpoint;		/* pipe number */
234 	uint8_t	direction;		/* pipe direction */
235 	uint8_t	ep_index;		/* pipe index match to use */
236 	uint8_t	if_index;		/* "ifaces" index to use */
237 };
238 
239 /*
240  * Use these macro when defining USB device ID arrays if you want to
241  * have your driver module automatically loaded in host, device or
242  * both modes respectively:
243  */
244 #if USB_HAVE_ID_SECTION
245 #define	STRUCT_USB_HOST_ID \
246     struct usb_device_id __section("usb_host_id")
247 #define	STRUCT_USB_DEVICE_ID \
248     struct usb_device_id __section("usb_device_id")
249 #define	STRUCT_USB_DUAL_ID \
250     struct usb_device_id __section("usb_dual_id")
251 #else
252 #define	STRUCT_USB_HOST_ID \
253     struct usb_device_id
254 #define	STRUCT_USB_DEVICE_ID \
255     struct usb_device_id
256 #define	STRUCT_USB_DUAL_ID \
257     struct usb_device_id
258 #endif			/* USB_HAVE_ID_SECTION */
259 
260 /*
261  * The following structure is used when looking up an USB driver for
262  * an USB device. It is inspired by the Linux structure called
263  * "usb_device_id".
264  */
265 struct usb_device_id {
266 
267 	/* Select which fields to match against */
268 #if BYTE_ORDER == LITTLE_ENDIAN
269 	uint16_t
270 		match_flag_vendor:1,
271 		match_flag_product:1,
272 		match_flag_dev_lo:1,
273 		match_flag_dev_hi:1,
274 
275 		match_flag_dev_class:1,
276 		match_flag_dev_subclass:1,
277 		match_flag_dev_protocol:1,
278 		match_flag_int_class:1,
279 
280 		match_flag_int_subclass:1,
281 		match_flag_int_protocol:1,
282 		match_flag_unused:6;
283 #else
284 	uint16_t
285 		match_flag_unused:6,
286 		match_flag_int_protocol:1,
287 		match_flag_int_subclass:1,
288 
289 		match_flag_int_class:1,
290 		match_flag_dev_protocol:1,
291 		match_flag_dev_subclass:1,
292 		match_flag_dev_class:1,
293 
294 		match_flag_dev_hi:1,
295 		match_flag_dev_lo:1,
296 		match_flag_product:1,
297 		match_flag_vendor:1;
298 #endif
299 
300 	/* Used for product specific matches; the BCD range is inclusive */
301 	uint16_t idVendor;
302 	uint16_t idProduct;
303 	uint16_t bcdDevice_lo;
304 	uint16_t bcdDevice_hi;
305 
306 	/* Used for device class matches */
307 	uint8_t	bDeviceClass;
308 	uint8_t	bDeviceSubClass;
309 	uint8_t	bDeviceProtocol;
310 
311 	/* Used for interface class matches */
312 	uint8_t	bInterfaceClass;
313 	uint8_t	bInterfaceSubClass;
314 	uint8_t	bInterfaceProtocol;
315 
316 #if USB_HAVE_COMPAT_LINUX
317 	/* which fields to match against */
318 	uint16_t match_flags;
319 #define	USB_DEVICE_ID_MATCH_VENDOR		0x0001
320 #define	USB_DEVICE_ID_MATCH_PRODUCT		0x0002
321 #define	USB_DEVICE_ID_MATCH_DEV_LO		0x0004
322 #define	USB_DEVICE_ID_MATCH_DEV_HI		0x0008
323 #define	USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
324 #define	USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
325 #define	USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
326 #define	USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
327 #define	USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
328 #define	USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
329 #endif
330 
331 	/* Hook for driver specific information */
332 	unsigned long driver_info;
333 } __aligned(32);
334 
335 #define USB_STD_PNP_INFO "M16:mask;U16:vendor;U16:product;L16:product;G16:product;" \
336 	"U8:devclass;U8:devsubclass;U8:devprotocol;" \
337 	"U8:intclass;U8:intsubclass;U8:intprotocol;"
338 #define USB_STD_PNP_HOST_INFO USB_STD_PNP_INFO "T:mode=host;"
339 #define USB_STD_PNP_DEVICE_INFO USB_STD_PNP_INFO "T:mode=device;"
340 #define USB_PNP_HOST_INFO(table)					\
341 	MODULE_PNP_INFO(USB_STD_PNP_HOST_INFO, usb, table, table, sizeof(table[0]), \
342 	    sizeof(table) / sizeof(table[0]))
343 #define USB_PNP_DEVICE_INFO(table)					\
344 	MODULE_PNP_INFO(USB_STD_PNP_DEVICE_INFO, usb, table, table, sizeof(table[0]), \
345 	    sizeof(table) / sizeof(table[0]))
346 #define USB_PNP_DUAL_INFO(table)					\
347 	MODULE_PNP_INFO(USB_STD_PNP_INFO, usb, table, table, sizeof(table[0]), \
348 	    sizeof(table) / sizeof(table[0]))
349 
350 /* check that the size of the structure above is correct */
351 extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1];
352 
353 #define	USB_VENDOR(vend)			\
354   .match_flag_vendor = 1, .idVendor = (vend)
355 
356 #define	USB_PRODUCT(prod)			\
357   .match_flag_product = 1, .idProduct = (prod)
358 
359 #define	USB_VP(vend,prod)			\
360   USB_VENDOR(vend), USB_PRODUCT(prod)
361 
362 #define	USB_VPI(vend,prod,info)			\
363   USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
364 
365 #define	USB_DEV_BCD_GTEQ(lo)	/* greater than or equal */ \
366   .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
367 
368 #define	USB_DEV_BCD_LTEQ(hi)	/* less than or equal */ \
369   .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
370 
371 #define	USB_DEV_CLASS(dc)			\
372   .match_flag_dev_class = 1, .bDeviceClass = (dc)
373 
374 #define	USB_DEV_SUBCLASS(dsc)			\
375   .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
376 
377 #define	USB_DEV_PROTOCOL(dp)			\
378   .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
379 
380 #define	USB_IFACE_CLASS(ic)			\
381   .match_flag_int_class = 1, .bInterfaceClass = (ic)
382 
383 #define	USB_IFACE_SUBCLASS(isc)			\
384   .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
385 
386 #define	USB_IFACE_PROTOCOL(ip)			\
387   .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
388 
389 #define	USB_IF_CSI(class,subclass,info)			\
390   USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
391 
392 #define	USB_DRIVER_INFO(n)			\
393   .driver_info = (n)
394 
395 #define	USB_GET_DRIVER_INFO(did)		\
396   (did)->driver_info
397 
398 /*
399  * The following structure keeps information that is used to match
400  * against an array of "usb_device_id" elements.
401  */
402 struct usbd_lookup_info {
403 	uint16_t idVendor;
404 	uint16_t idProduct;
405 	uint16_t bcdDevice;
406 	uint8_t	bDeviceClass;
407 	uint8_t	bDeviceSubClass;
408 	uint8_t	bDeviceProtocol;
409 	uint8_t	bInterfaceClass;
410 	uint8_t	bInterfaceSubClass;
411 	uint8_t	bInterfaceProtocol;
412 	uint8_t	bIfaceIndex;
413 	uint8_t	bIfaceNum;
414 	uint8_t	bConfigIndex;
415 	uint8_t	bConfigNum;
416 };
417 
418 /* Structure used by probe and attach */
419 
420 struct usb_attach_arg {
421 	struct usbd_lookup_info info;
422 	device_t temp_dev;		/* for internal use */
423 	unsigned long driver_info;	/* for internal use */
424 	void *driver_ivar;
425 	struct usb_device *device;	/* current device */
426 	struct usb_interface *iface;	/* current interface */
427 	enum usb_hc_mode usb_mode;	/* host or device mode */
428 	uint8_t	port;
429 	uint8_t dev_state;
430 #define UAA_DEV_READY		0
431 #define UAA_DEV_DISABLED	1
432 #define UAA_DEV_EJECTING	2
433 };
434 
435 /*
436  * The following is a wrapper for the callout structure to ease
437  * porting the code to other platforms.
438  */
439 struct usb_callout {
440 	struct callout co;
441 };
442 #define	usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
443 #define	usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
444 #define	usb_callout_stop(c) callout_stop(&(c)->co)
445 #define	usb_callout_drain(c) callout_drain(&(c)->co)
446 #define	usb_callout_pending(c) callout_pending(&(c)->co)
447 
448 /* USB transfer states */
449 
450 #define	USB_ST_SETUP       0
451 #define	USB_ST_TRANSFERRED 1
452 #define	USB_ST_ERROR       2
453 
454 /* USB handle request states */
455 #define	USB_HR_NOT_COMPLETE	0
456 #define	USB_HR_COMPLETE_OK	1
457 #define	USB_HR_COMPLETE_ERR	2
458 
459 /*
460  * The following macro will return the current state of an USB
461  * transfer like defined by the "USB_ST_XXX" enums.
462  */
463 #define	USB_GET_STATE(xfer) (usbd_xfer_state(xfer))
464 
465 /*
466  * The following structure defines the USB process message header.
467  */
468 struct usb_proc_msg {
469 	TAILQ_ENTRY(usb_proc_msg) pm_qentry;
470 	usb_proc_callback_t *pm_callback;
471 	usb_size_t pm_num;
472 };
473 
474 #define	USB_FIFO_TX 0
475 #define	USB_FIFO_RX 1
476 
477 /*
478  * Locking note for the following functions.  All the
479  * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
480  * locked. The others are called unlocked.
481  */
482 struct usb_fifo_methods {
483 	usb_fifo_open_t *f_open;
484 	usb_fifo_close_t *f_close;
485 	usb_fifo_ioctl_t *f_ioctl;
486 	/*
487 	 * NOTE: The post-ioctl callback is called after the USB reference
488 	 * gets locked in the IOCTL handler:
489 	 */
490 	usb_fifo_ioctl_t *f_ioctl_post;
491 	usb_fifo_cmd_t *f_start_read;
492 	usb_fifo_cmd_t *f_stop_read;
493 	usb_fifo_cmd_t *f_start_write;
494 	usb_fifo_cmd_t *f_stop_write;
495 	usb_fifo_filter_t *f_filter_read;
496 	usb_fifo_filter_t *f_filter_write;
497 	const char *basename[4];
498 	const char *postfix[4];
499 };
500 
501 struct usb_fifo_sc {
502 	struct usb_fifo *fp[2];
503 	struct usb_fs_privdata *dev;
504 };
505 
506 const char *usbd_errstr(usb_error_t error);
507 void	*usbd_find_descriptor(struct usb_device *udev, void *id,
508 	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
509 	    uint8_t subtype, uint8_t subtype_mask);
510 struct usb_config_descriptor *usbd_get_config_descriptor(
511 	    struct usb_device *udev);
512 struct usb_device_descriptor *usbd_get_device_descriptor(
513 	    struct usb_device *udev);
514 struct usb_interface *usbd_get_iface(struct usb_device *udev,
515 	    uint8_t iface_index);
516 struct usb_interface_descriptor *usbd_get_interface_descriptor(
517 	    struct usb_interface *iface);
518 struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
519 		    const struct usb_config *setup);
520 struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
521 usb_error_t	usbd_interface_count(struct usb_device *udev, uint8_t *count);
522 enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
523 enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
524 void	device_set_usb_desc(device_t dev);
525 void	usb_pause_mtx(struct mtx *mtx, int _ticks);
526 usb_error_t	usbd_set_pnpinfo(struct usb_device *udev,
527 			uint8_t iface_index, const char *pnpinfo);
528 usb_error_t	usbd_add_dynamic_quirk(struct usb_device *udev,
529 			uint16_t quirk);
530 usb_error_t	usbd_set_endpoint_mode(struct usb_device *udev,
531 			struct usb_endpoint *ep, uint8_t ep_mode);
532 uint8_t		usbd_get_endpoint_mode(struct usb_device *udev,
533 			struct usb_endpoint *ep);
534 
535 const struct usb_device_id *usbd_lookup_id_by_info(
536 	    const struct usb_device_id *id, usb_size_t sizeof_id,
537 	    const struct usbd_lookup_info *info);
538 int	usbd_lookup_id_by_uaa(const struct usb_device_id *id,
539 	    usb_size_t sizeof_id, struct usb_attach_arg *uaa);
540 
541 usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
542 		    struct usb_device_request *req, void *data, uint16_t flags,
543 		    uint16_t *actlen, usb_timeout_t timeout);
544 #define	usbd_do_request(u,m,r,d) \
545   usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)
546 
547 uint8_t	usbd_clear_stall_callback(struct usb_xfer *xfer1,
548 	    struct usb_xfer *xfer2);
549 uint8_t	usbd_get_interface_altindex(struct usb_interface *iface);
550 usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
551 	    uint8_t iface_index, uint8_t alt_index);
552 uint32_t usbd_get_isoc_fps(struct usb_device *udev);
553 usb_error_t usbd_transfer_setup(struct usb_device *udev,
554 	    const uint8_t *ifaces, struct usb_xfer **pxfer,
555 	    const struct usb_config *setup_start, uint16_t n_setup,
556 	    void *priv_sc, struct mtx *priv_mtx);
557 void	usbd_transfer_submit(struct usb_xfer *xfer);
558 void	usbd_transfer_clear_stall(struct usb_xfer *xfer);
559 void	usbd_transfer_drain(struct usb_xfer *xfer);
560 uint8_t	usbd_transfer_pending(struct usb_xfer *xfer);
561 void	usbd_transfer_start(struct usb_xfer *xfer);
562 void	usbd_transfer_stop(struct usb_xfer *xfer);
563 void	usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
564 void	usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
565 void	usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
566 	    uint8_t parent_index);
567 uint8_t	usbd_get_bus_index(struct usb_device *udev);
568 uint8_t	usbd_get_device_index(struct usb_device *udev);
569 void	usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
570 uint8_t	usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode);
571 uint8_t	usbd_device_attached(struct usb_device *udev);
572 
573 usb_frlength_t
574 	usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex);
575 void	usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
576 	    int *aframes, int *nframes);
577 struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t);
578 void	*usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t);
579 void	*usbd_xfer_softc(struct usb_xfer *xfer);
580 void	*usbd_xfer_get_priv(struct usb_xfer *xfer);
581 void	usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
582 void	usbd_xfer_set_interval(struct usb_xfer *xfer, int);
583 uint8_t	usbd_xfer_state(struct usb_xfer *xfer);
584 void	usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
585 	    void *ptr, usb_frlength_t len);
586 void	usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
587 	    void **ptr, int *len);
588 void	usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
589 	    usb_frcount_t frindex);
590 usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
591 usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
592 usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
593 uint8_t	usbd_xfer_get_fps_shift(struct usb_xfer *xfer);
594 usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
595 	    usb_frcount_t frindex);
596 void	usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
597 	    usb_frlength_t len);
598 void	usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
599 void	usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
600 void	usbd_xfer_set_stall(struct usb_xfer *xfer);
601 int	usbd_xfer_is_stalled(struct usb_xfer *xfer);
602 void	usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
603 void	usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
604 uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer);
605 uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer);
606 
607 void	usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
608 	    const void *ptr, usb_frlength_t len);
609 int	usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
610 	    const void *ptr, usb_frlength_t len);
611 void	usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
612 	    void *ptr, usb_frlength_t len);
613 int	usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
614 	    void *ptr, usb_frlength_t len);
615 void	usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
616 	    struct usb_page_search *res);
617 void	usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
618 	    struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
619 void	usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
620 	    usb_frlength_t len);
621 void	usbd_start_re_enumerate(struct usb_device *udev);
622 usb_error_t
623 	usbd_start_set_config(struct usb_device *, uint8_t);
624 
625 int	usb_fifo_attach(struct usb_device *udev, void *priv_sc,
626 	    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
627 	    struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit,
628 	    uint8_t iface_index, uid_t uid, gid_t gid, int mode);
629 void	usb_fifo_detach(struct usb_fifo_sc *f_sc);
630 int	usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
631 	    uint16_t nbuf);
632 void	usb_fifo_free_buffer(struct usb_fifo *f);
633 uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
634 void	usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
635 	    usb_frlength_t offset, usb_frlength_t len, uint8_t what);
636 void	usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
637 	    usb_size_t len, uint8_t what);
638 uint8_t	usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
639 void	usb_fifo_put_data_error(struct usb_fifo *fifo);
640 uint8_t	usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
641 	    usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
642 	    uint8_t what);
643 uint8_t	usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
644 	    usb_size_t len, usb_size_t *actlen, uint8_t what);
645 uint8_t	usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
646 	    usb_size_t *plen);
647 void	usb_fifo_reset(struct usb_fifo *f);
648 void	usb_fifo_wakeup(struct usb_fifo *f);
649 void	usb_fifo_get_data_error(struct usb_fifo *fifo);
650 void	*usb_fifo_softc(struct usb_fifo *fifo);
651 void	usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
652 void	usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
653 void	usb_fifo_free(struct usb_fifo *f);
654 #endif /* _KERNEL */
655 #endif /* _USB_USBDI_H_ */
656