xref: /illumos-gate/usr/src/contrib/bhyve/dev/usb/usbdi.h (revision d0b3c59b)
14c87aefeSPatrick Mooney /*-
24c87aefeSPatrick Mooney  * Copyright (c) 2009 Andrew Thompson
34c87aefeSPatrick Mooney  *
44c87aefeSPatrick Mooney  * Redistribution and use in source and binary forms, with or without
54c87aefeSPatrick Mooney  * modification, are permitted provided that the following conditions
64c87aefeSPatrick Mooney  * are met:
74c87aefeSPatrick Mooney  * 1. Redistributions of source code must retain the above copyright
84c87aefeSPatrick Mooney  *    notice, this list of conditions and the following disclaimer.
94c87aefeSPatrick Mooney  * 2. Redistributions in binary form must reproduce the above copyright
104c87aefeSPatrick Mooney  *    notice, this list of conditions and the following disclaimer in the
114c87aefeSPatrick Mooney  *    documentation and/or other materials provided with the distribution.
124c87aefeSPatrick Mooney  *
234c87aefeSPatrick Mooney  *
244c87aefeSPatrick Mooney  * $FreeBSD$
254c87aefeSPatrick Mooney  */
264c87aefeSPatrick Mooney #ifndef _USB_USBDI_H_
274c87aefeSPatrick Mooney #define _USB_USBDI_H_
284c87aefeSPatrick Mooney 
294c87aefeSPatrick Mooney struct usb_fifo;
304c87aefeSPatrick Mooney struct usb_xfer;
314c87aefeSPatrick Mooney struct usb_device;
324c87aefeSPatrick Mooney struct usb_attach_arg;
334c87aefeSPatrick Mooney struct usb_interface;
344c87aefeSPatrick Mooney struct usb_endpoint;
354c87aefeSPatrick Mooney struct usb_page_cache;
364c87aefeSPatrick Mooney struct usb_page_search;
374c87aefeSPatrick Mooney struct usb_process;
384c87aefeSPatrick Mooney struct usb_proc_msg;
394c87aefeSPatrick Mooney struct usb_mbuf;
404c87aefeSPatrick Mooney struct usb_fs_privdata;
414c87aefeSPatrick Mooney struct mbuf;
424c87aefeSPatrick Mooney 
434c87aefeSPatrick Mooney typedef enum {	/* keep in sync with usb_errstr_table */
444c87aefeSPatrick Mooney 	USB_ERR_NORMAL_COMPLETION = 0,
454c87aefeSPatrick Mooney 	USB_ERR_PENDING_REQUESTS,	/* 1 */
464c87aefeSPatrick Mooney 	USB_ERR_NOT_STARTED,		/* 2 */
474c87aefeSPatrick Mooney 	USB_ERR_INVAL,			/* 3 */
484c87aefeSPatrick Mooney 	USB_ERR_NOMEM,			/* 4 */
494c87aefeSPatrick Mooney 	USB_ERR_CANCELLED,		/* 5 */
504c87aefeSPatrick Mooney 	USB_ERR_BAD_ADDRESS,		/* 6 */
514c87aefeSPatrick Mooney 	USB_ERR_BAD_BUFSIZE,		/* 7 */
524c87aefeSPatrick Mooney 	USB_ERR_BAD_FLAG,		/* 8 */
534c87aefeSPatrick Mooney 	USB_ERR_NO_CALLBACK,		/* 9 */
544c87aefeSPatrick Mooney 	USB_ERR_IN_USE,			/* 10 */
554c87aefeSPatrick Mooney 	USB_ERR_NO_ADDR,		/* 11 */
564c87aefeSPatrick Mooney 	USB_ERR_NO_PIPE,		/* 12 */
574c87aefeSPatrick Mooney 	USB_ERR_ZERO_NFRAMES,		/* 13 */
584c87aefeSPatrick Mooney 	USB_ERR_ZERO_MAXP,		/* 14 */
594c87aefeSPatrick Mooney 	USB_ERR_SET_ADDR_FAILED,	/* 15 */
604c87aefeSPatrick Mooney 	USB_ERR_NO_POWER,		/* 16 */
614c87aefeSPatrick Mooney 	USB_ERR_TOO_DEEP,		/* 17 */
624c87aefeSPatrick Mooney 	USB_ERR_IOERROR,		/* 18 */
634c87aefeSPatrick Mooney 	USB_ERR_NOT_CONFIGURED,		/* 19 */
644c87aefeSPatrick Mooney 	USB_ERR_TIMEOUT,		/* 20 */
654c87aefeSPatrick Mooney 	USB_ERR_SHORT_XFER,		/* 21 */
664c87aefeSPatrick Mooney 	USB_ERR_STALLED,		/* 22 */
674c87aefeSPatrick Mooney 	USB_ERR_INTERRUPTED,		/* 23 */
684c87aefeSPatrick Mooney 	USB_ERR_DMA_LOAD_FAILED,	/* 24 */
694c87aefeSPatrick Mooney 	USB_ERR_BAD_CONTEXT,		/* 25 */
704c87aefeSPatrick Mooney 	USB_ERR_NO_ROOT_HUB,		/* 26 */
714c87aefeSPatrick Mooney 	USB_ERR_NO_INTR_THREAD,		/* 27 */
724c87aefeSPatrick Mooney 	USB_ERR_NOT_LOCKED,		/* 28 */
734c87aefeSPatrick Mooney 	USB_ERR_MAX
744c87aefeSPatrick Mooney } usb_error_t;
754c87aefeSPatrick Mooney 
764c87aefeSPatrick Mooney /*
774c87aefeSPatrick Mooney  * Flags for transfers
784c87aefeSPatrick Mooney  */
794c87aefeSPatrick Mooney #define	USB_FORCE_SHORT_XFER	0x0001	/* force a short transmit last */
804c87aefeSPatrick Mooney #define	USB_SHORT_XFER_OK	0x0004	/* allow short reads */
814c87aefeSPatrick Mooney #define	USB_DELAY_STATUS_STAGE	0x0010	/* insert delay before STATUS stage */
824c87aefeSPatrick Mooney #define	USB_USER_DATA_PTR	0x0020	/* internal flag */
834c87aefeSPatrick Mooney #define	USB_MULTI_SHORT_OK	0x0040	/* allow multiple short frames */
844c87aefeSPatrick Mooney #define	USB_MANUAL_STATUS	0x0080	/* manual ctrl status */
854c87aefeSPatrick Mooney 
864c87aefeSPatrick Mooney #define	USB_NO_TIMEOUT 0
874c87aefeSPatrick Mooney #define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */
884c87aefeSPatrick Mooney 
894c87aefeSPatrick Mooney #if defined(_KERNEL)
904c87aefeSPatrick Mooney /* typedefs */
914c87aefeSPatrick Mooney 
924c87aefeSPatrick Mooney typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
934c87aefeSPatrick Mooney typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
944c87aefeSPatrick Mooney typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
954c87aefeSPatrick Mooney     struct usb_device_request *, const void **, uint16_t *);
964c87aefeSPatrick Mooney 
974c87aefeSPatrick Mooney typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
984c87aefeSPatrick Mooney typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
994c87aefeSPatrick Mooney typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
1004c87aefeSPatrick Mooney typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
1014c87aefeSPatrick Mooney typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
1024c87aefeSPatrick Mooney 
1034c87aefeSPatrick Mooney 
1044c87aefeSPatrick Mooney /* USB events */
1054c87aefeSPatrick Mooney #ifndef USB_GLOBAL_INCLUDE_FILE
1064c87aefeSPatrick Mooney #include <sys/eventhandler.h>
1074c87aefeSPatrick Mooney #endif
1084c87aefeSPatrick Mooney typedef void (*usb_dev_configured_t)(void *, struct usb_device *,
1094c87aefeSPatrick Mooney     struct usb_attach_arg *);
1104c87aefeSPatrick Mooney EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t);
1114c87aefeSPatrick Mooney 
1124c87aefeSPatrick Mooney /*
1134c87aefeSPatrick Mooney  * The following macros are used used to convert milliseconds into
1144c87aefeSPatrick Mooney  * HZ. We use 1024 instead of 1000 milliseconds per second to save a
1154c87aefeSPatrick Mooney  * full division.
1164c87aefeSPatrick Mooney  */
1174c87aefeSPatrick Mooney #define	USB_MS_HZ 1024
1184c87aefeSPatrick Mooney 
1194c87aefeSPatrick Mooney #define	USB_MS_TO_TICKS(ms) \
1204c87aefeSPatrick Mooney   (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
1214c87aefeSPatrick Mooney 
1224c87aefeSPatrick Mooney /*
1234c87aefeSPatrick Mooney  * Common queue structure for USB transfers.
1244c87aefeSPatrick Mooney  */
1254c87aefeSPatrick Mooney struct usb_xfer_queue {
1264c87aefeSPatrick Mooney 	TAILQ_HEAD(, usb_xfer) head;
1274c87aefeSPatrick Mooney 	struct usb_xfer *curr;		/* current USB transfer processed */
1284c87aefeSPatrick Mooney 	void    (*command) (struct usb_xfer_queue *pq);
1294c87aefeSPatrick Mooney 	uint8_t	recurse_1:1;
1304c87aefeSPatrick Mooney 	uint8_t	recurse_2:1;
1314c87aefeSPatrick Mooney 	uint8_t	recurse_3:1;
1324c87aefeSPatrick Mooney 	uint8_t	reserved:5;
1334c87aefeSPatrick Mooney };
1344c87aefeSPatrick Mooney 
1354c87aefeSPatrick Mooney /*
1364c87aefeSPatrick Mooney  * The following structure defines an USB endpoint
1374c87aefeSPatrick Mooney  * USB endpoint.
1384c87aefeSPatrick Mooney  */
1394c87aefeSPatrick Mooney struct usb_endpoint {
1404c87aefeSPatrick Mooney 	/* queue of USB transfers */
1414c87aefeSPatrick Mooney 	struct usb_xfer_queue endpoint_q[USB_MAX_EP_STREAMS];
1424c87aefeSPatrick Mooney 
1434c87aefeSPatrick Mooney 	struct usb_endpoint_descriptor *edesc;
1444c87aefeSPatrick Mooney 	struct usb_endpoint_ss_comp_descriptor *ecomp;
1454c87aefeSPatrick Mooney 	const struct usb_pipe_methods *methods;	/* set by HC driver */
1464c87aefeSPatrick Mooney 
1474c87aefeSPatrick Mooney 	uint16_t isoc_next;
1484c87aefeSPatrick Mooney 
1494c87aefeSPatrick Mooney 	uint8_t	toggle_next:1;		/* next data toggle value */
1504c87aefeSPatrick Mooney 	uint8_t	is_stalled:1;		/* set if endpoint is stalled */
1514c87aefeSPatrick Mooney 	uint8_t	is_synced:1;		/* set if we a synchronised */
1524c87aefeSPatrick Mooney 	uint8_t	unused:5;
1534c87aefeSPatrick Mooney 	uint8_t	iface_index;		/* not used by "default endpoint" */
1544c87aefeSPatrick Mooney 
1554c87aefeSPatrick Mooney 	uint8_t refcount_alloc;		/* allocation refcount */
1564c87aefeSPatrick Mooney 	uint8_t refcount_bw;		/* bandwidth refcount */
1574c87aefeSPatrick Mooney #define	USB_EP_REF_MAX 0x3f
1584c87aefeSPatrick Mooney 
1594c87aefeSPatrick Mooney 	/* High-Speed resource allocation (valid if "refcount_bw" > 0) */
1604c87aefeSPatrick Mooney 
1614c87aefeSPatrick Mooney 	uint8_t	usb_smask;		/* USB start mask */
1624c87aefeSPatrick Mooney 	uint8_t	usb_cmask;		/* USB complete mask */
1634c87aefeSPatrick Mooney 	uint8_t	usb_uframe;		/* USB microframe */
1644c87aefeSPatrick Mooney 
1654c87aefeSPatrick Mooney 	/* USB endpoint mode, see USB_EP_MODE_XXX */
1664c87aefeSPatrick Mooney 
1674c87aefeSPatrick Mooney 	uint8_t ep_mode;
1684c87aefeSPatrick Mooney };
1694c87aefeSPatrick Mooney 
1704c87aefeSPatrick Mooney /*
1714c87aefeSPatrick Mooney  * The following structure defines an USB interface.
1724c87aefeSPatrick Mooney  */
1734c87aefeSPatrick Mooney struct usb_interface {
1744c87aefeSPatrick Mooney 	struct usb_interface_descriptor *idesc;
1754c87aefeSPatrick Mooney 	device_t subdev;
1764c87aefeSPatrick Mooney 	uint8_t	alt_index;
1774c87aefeSPatrick Mooney 	uint8_t	parent_iface_index;
1784c87aefeSPatrick Mooney 
1794c87aefeSPatrick Mooney 	/* Linux compat */
1804c87aefeSPatrick Mooney 	struct usb_host_interface *altsetting;
1814c87aefeSPatrick Mooney 	struct usb_host_interface *cur_altsetting;
1824c87aefeSPatrick Mooney 	struct usb_device *linux_udev;
1834c87aefeSPatrick Mooney 	void   *bsd_priv_sc;		/* device specific information */
1844c87aefeSPatrick Mooney 	char   *pnpinfo;		/* additional PnP-info for this interface */
1854c87aefeSPatrick Mooney 	uint8_t	num_altsetting;		/* number of alternate settings */
1864c87aefeSPatrick Mooney 	uint8_t	bsd_iface_index;
1874c87aefeSPatrick Mooney };
1884c87aefeSPatrick Mooney 
1894c87aefeSPatrick Mooney /*
1904c87aefeSPatrick Mooney  * The following structure defines a set of USB transfer flags.
1914c87aefeSPatrick Mooney  */
1924c87aefeSPatrick Mooney struct usb_xfer_flags {
1934c87aefeSPatrick Mooney 	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
1944c87aefeSPatrick Mooney 					 * last */
1954c87aefeSPatrick Mooney 	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
1964c87aefeSPatrick Mooney 	uint8_t	short_frames_ok:1;	/* allow short frames */
1974c87aefeSPatrick Mooney 	uint8_t	pipe_bof:1;		/* block pipe on failure */
1984c87aefeSPatrick Mooney 	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
1994c87aefeSPatrick Mooney 					 * "max_frame_size" */
2004c87aefeSPatrick Mooney 	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
2014c87aefeSPatrick Mooney 	uint8_t	manual_status:1;	/* non automatic status stage on
2024c87aefeSPatrick Mooney 					 * control transfers */
2034c87aefeSPatrick Mooney 	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
2044c87aefeSPatrick Mooney 					 * be ignored */
2054c87aefeSPatrick Mooney 	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
2064c87aefeSPatrick Mooney 					 * this USB transfer should be stalled
2074c87aefeSPatrick Mooney 					 * before starting this transfer! */
2084c87aefeSPatrick Mooney 	uint8_t pre_scale_frames:1;	/* "usb_config->frames" is
2094c87aefeSPatrick Mooney 					 * assumed to give the
2104c87aefeSPatrick Mooney 					 * buffering time in
2114c87aefeSPatrick Mooney 					 * milliseconds and is
2124c87aefeSPatrick Mooney 					 * converted into the nearest
2134c87aefeSPatrick Mooney 					 * number of frames when the
2144c87aefeSPatrick Mooney 					 * USB transfer is setup. This
2154c87aefeSPatrick Mooney 					 * option only has effect for
2164c87aefeSPatrick Mooney 					 * ISOCHRONOUS transfers.
2174c87aefeSPatrick Mooney 					 */
2184c87aefeSPatrick Mooney };
2194c87aefeSPatrick Mooney 
2204c87aefeSPatrick Mooney /*
2214c87aefeSPatrick Mooney  * The following structure define an USB configuration, that basically
2224c87aefeSPatrick Mooney  * is used when setting up an USB transfer.
2234c87aefeSPatrick Mooney  */
2244c87aefeSPatrick Mooney struct usb_config {
2254c87aefeSPatrick Mooney 	usb_callback_t *callback;	/* USB transfer callback */
2264c87aefeSPatrick Mooney 	usb_frlength_t bufsize;	/* total pipe buffer size in bytes */
2274c87aefeSPatrick Mooney 	usb_frcount_t frames;		/* maximum number of USB frames */
2284c87aefeSPatrick Mooney 	usb_timeout_t interval;	/* interval in milliseconds */
2294c87aefeSPatrick Mooney #define	USB_DEFAULT_INTERVAL	0
2304c87aefeSPatrick Mooney 	usb_timeout_t timeout;		/* transfer timeout in milliseconds */
2314c87aefeSPatrick Mooney 	struct usb_xfer_flags flags;	/* transfer flags */
2324c87aefeSPatrick Mooney 	usb_stream_t stream_id;		/* USB3.0 specific */
2334c87aefeSPatrick Mooney 	enum usb_hc_mode usb_mode;	/* host or device mode */
2344c87aefeSPatrick Mooney 	uint8_t	type;			/* pipe type */
2354c87aefeSPatrick Mooney 	uint8_t	endpoint;		/* pipe number */
2364c87aefeSPatrick Mooney 	uint8_t	direction;		/* pipe direction */
2374c87aefeSPatrick Mooney 	uint8_t	ep_index;		/* pipe index match to use */
2384c87aefeSPatrick Mooney 	uint8_t	if_index;		/* "ifaces" index to use */
2394c87aefeSPatrick Mooney };
2404c87aefeSPatrick Mooney 
2414c87aefeSPatrick Mooney /*
2424c87aefeSPatrick Mooney  * Use these macro when defining USB device ID arrays if you want to
2434c87aefeSPatrick Mooney  * have your driver module automatically loaded in host, device or
2444c87aefeSPatrick Mooney  * both modes respectively:
2454c87aefeSPatrick Mooney  */
2464c87aefeSPatrick Mooney #if USB_HAVE_ID_SECTION
2474c87aefeSPatrick Mooney #define	STRUCT_USB_HOST_ID \
2484c87aefeSPatrick Mooney     struct usb_device_id __section("usb_host_id")
2494c87aefeSPatrick Mooney #define	STRUCT_USB_DEVICE_ID \
2504c87aefeSPatrick Mooney     struct usb_device_id __section("usb_device_id")
2514c87aefeSPatrick Mooney #define	STRUCT_USB_DUAL_ID \
2524c87aefeSPatrick Mooney     struct usb_device_id __section("usb_dual_id")
2534c87aefeSPatrick Mooney #else
2544c87aefeSPatrick Mooney #define	STRUCT_USB_HOST_ID \
2554c87aefeSPatrick Mooney     struct usb_device_id
2564c87aefeSPatrick Mooney #define	STRUCT_USB_DEVICE_ID \
2574c87aefeSPatrick Mooney     struct usb_device_id
2584c87aefeSPatrick Mooney #define	STRUCT_USB_DUAL_ID \
2594c87aefeSPatrick Mooney     struct usb_device_id
2604c87aefeSPatrick Mooney #endif			/* USB_HAVE_ID_SECTION */
2614c87aefeSPatrick Mooney 
2624c87aefeSPatrick Mooney /*
2634c87aefeSPatrick Mooney  * The following structure is used when looking up an USB driver for
2644c87aefeSPatrick Mooney  * an USB device. It is inspired by the Linux structure called
2654c87aefeSPatrick Mooney  * "usb_device_id".
2664c87aefeSPatrick Mooney  */
2674c87aefeSPatrick Mooney struct usb_device_id {
2684c87aefeSPatrick Mooney 
2694c87aefeSPatrick Mooney 	/* Select which fields to match against */
2704c87aefeSPatrick Mooney #if BYTE_ORDER == LITTLE_ENDIAN
2714c87aefeSPatrick Mooney 	uint16_t
2724c87aefeSPatrick Mooney 		match_flag_vendor:1,
2734c87aefeSPatrick Mooney 		match_flag_product:1,
2744c87aefeSPatrick Mooney 		match_flag_dev_lo:1,
2754c87aefeSPatrick Mooney 		match_flag_dev_hi:1,
2764c87aefeSPatrick Mooney 
2774c87aefeSPatrick Mooney 		match_flag_dev_class:1,
2784c87aefeSPatrick Mooney 		match_flag_dev_subclass:1,
2794c87aefeSPatrick Mooney 		match_flag_dev_protocol:1,
2804c87aefeSPatrick Mooney 		match_flag_int_class:1,
2814c87aefeSPatrick Mooney 
2824c87aefeSPatrick Mooney 		match_flag_int_subclass:1,
2834c87aefeSPatrick Mooney 		match_flag_int_protocol:1,
2844c87aefeSPatrick Mooney 		match_flag_unused:6;
2854c87aefeSPatrick Mooney #else
2864c87aefeSPatrick Mooney 	uint16_t
2874c87aefeSPatrick Mooney 		match_flag_unused:6,
2884c87aefeSPatrick Mooney 		match_flag_int_protocol:1,
2894c87aefeSPatrick Mooney 		match_flag_int_subclass:1,
2904c87aefeSPatrick Mooney 
2914c87aefeSPatrick Mooney 		match_flag_int_class:1,
2924c87aefeSPatrick Mooney 		match_flag_dev_protocol:1,
2934c87aefeSPatrick Mooney 		match_flag_dev_subclass:1,
2944c87aefeSPatrick Mooney 		match_flag_dev_class:1,
2954c87aefeSPatrick Mooney 
2964c87aefeSPatrick Mooney 		match_flag_dev_hi:1,
2974c87aefeSPatrick Mooney 		match_flag_dev_lo:1,
2984c87aefeSPatrick Mooney 		match_flag_product:1,
2994c87aefeSPatrick Mooney 		match_flag_vendor:1;
3004c87aefeSPatrick Mooney #endif
3014c87aefeSPatrick Mooney 
3024c87aefeSPatrick Mooney 	/* Used for product specific matches; the BCD range is inclusive */
3034c87aefeSPatrick Mooney 	uint16_t idVendor;
3044c87aefeSPatrick Mooney 	uint16_t idProduct;
3054c87aefeSPatrick Mooney 	uint16_t bcdDevice_lo;
3064c87aefeSPatrick Mooney 	uint16_t bcdDevice_hi;
3074c87aefeSPatrick Mooney 
3084c87aefeSPatrick Mooney 	/* Used for device class matches */
3094c87aefeSPatrick Mooney 	uint8_t	bDeviceClass;
3104c87aefeSPatrick Mooney 	uint8_t	bDeviceSubClass;
3114c87aefeSPatrick Mooney 	uint8_t	bDeviceProtocol;
3124c87aefeSPatrick Mooney 
3134c87aefeSPatrick Mooney 	/* Used for interface class matches */
3144c87aefeSPatrick Mooney 	uint8_t	bInterfaceClass;
3154c87aefeSPatrick Mooney 	uint8_t	bInterfaceSubClass;
3164c87aefeSPatrick Mooney 	uint8_t	bInterfaceProtocol;
3174c87aefeSPatrick Mooney 
3184c87aefeSPatrick Mooney #if USB_HAVE_COMPAT_LINUX
3194c87aefeSPatrick Mooney 	/* which fields to match against */
3204c87aefeSPatrick Mooney 	uint16_t match_flags;
3214c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_VENDOR		0x0001
3224c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_PRODUCT		0x0002
3234c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_DEV_LO		0x0004
3244c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_DEV_HI		0x0008
3254c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
3264c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
3274c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
3284c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
3294c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
3304c87aefeSPatrick Mooney #define	USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
3314c87aefeSPatrick Mooney #endif
3324c87aefeSPatrick Mooney 
3334c87aefeSPatrick Mooney 	/* Hook for driver specific information */
3344c87aefeSPatrick Mooney 	unsigned long driver_info;
3354c87aefeSPatrick Mooney } __aligned(32);
3364c87aefeSPatrick Mooney 
3374c87aefeSPatrick Mooney #define USB_STD_PNP_INFO "M16:mask;U16:vendor;U16:product;L16:product;G16:product;" \
3384c87aefeSPatrick Mooney 	"U8:devclass;U8:devsubclass;U8:devprotocol;" \
3394c87aefeSPatrick Mooney 	"U8:intclass;U8:intsubclass;U8:intprotocol;"
3404c87aefeSPatrick Mooney #define USB_STD_PNP_HOST_INFO USB_STD_PNP_INFO "T:mode=host;"
3414c87aefeSPatrick Mooney #define USB_STD_PNP_DEVICE_INFO USB_STD_PNP_INFO "T:mode=device;"
3424c87aefeSPatrick Mooney #define USB_PNP_HOST_INFO(table)					\
3434c87aefeSPatrick Mooney 	MODULE_PNP_INFO(USB_STD_PNP_HOST_INFO, usb, table, table, sizeof(table[0]), \
3444c87aefeSPatrick Mooney 	    sizeof(table) / sizeof(table[0]))
3454c87aefeSPatrick Mooney #define USB_PNP_DEVICE_INFO(table)					\
3464c87aefeSPatrick Mooney 	MODULE_PNP_INFO(USB_STD_PNP_DEVICE_INFO, usb, table, table, sizeof(table[0]), \
3474c87aefeSPatrick Mooney 	    sizeof(table) / sizeof(table[0]))
3484c87aefeSPatrick Mooney #define USB_PNP_DUAL_INFO(table)					\
3494c87aefeSPatrick Mooney 	MODULE_PNP_INFO(USB_STD_PNP_INFO, usb, table, table, sizeof(table[0]), \
3504c87aefeSPatrick Mooney 	    sizeof(table) / sizeof(table[0]))
3514c87aefeSPatrick Mooney 
3524c87aefeSPatrick Mooney /* check that the size of the structure above is correct */
3534c87aefeSPatrick Mooney extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1];
3544c87aefeSPatrick Mooney 
3554c87aefeSPatrick Mooney #define	USB_VENDOR(vend)			\
3564c87aefeSPatrick Mooney   .match_flag_vendor = 1, .idVendor = (vend)
3574c87aefeSPatrick Mooney 
3584c87aefeSPatrick Mooney #define	USB_PRODUCT(prod)			\
3594c87aefeSPatrick Mooney   .match_flag_product = 1, .idProduct = (prod)
3604c87aefeSPatrick Mooney 
3614c87aefeSPatrick Mooney #define	USB_VP(vend,prod)			\
3624c87aefeSPatrick Mooney   USB_VENDOR(vend), USB_PRODUCT(prod)
3634c87aefeSPatrick Mooney 
3644c87aefeSPatrick Mooney #define	USB_VPI(vend,prod,info)			\
3654c87aefeSPatrick Mooney   USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
3664c87aefeSPatrick Mooney 
3674c87aefeSPatrick Mooney #define	USB_DEV_BCD_GTEQ(lo)	/* greater than or equal */ \
3684c87aefeSPatrick Mooney   .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
3694c87aefeSPatrick Mooney 
3704c87aefeSPatrick Mooney #define	USB_DEV_BCD_LTEQ(hi)	/* less than or equal */ \
3714c87aefeSPatrick Mooney   .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
3724c87aefeSPatrick Mooney 
3734c87aefeSPatrick Mooney #define	USB_DEV_CLASS(dc)			\
3744c87aefeSPatrick Mooney   .match_flag_dev_class = 1, .bDeviceClass = (dc)
3754c87aefeSPatrick Mooney 
3764c87aefeSPatrick Mooney #define	USB_DEV_SUBCLASS(dsc)			\
3774c87aefeSPatrick Mooney   .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
3784c87aefeSPatrick Mooney 
3794c87aefeSPatrick Mooney #define	USB_DEV_PROTOCOL(dp)			\
3804c87aefeSPatrick Mooney   .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
3814c87aefeSPatrick Mooney 
3824c87aefeSPatrick Mooney #define	USB_IFACE_CLASS(ic)			\
3834c87aefeSPatrick Mooney   .match_flag_int_class = 1, .bInterfaceClass = (ic)
3844c87aefeSPatrick Mooney 
3854c87aefeSPatrick Mooney #define	USB_IFACE_SUBCLASS(isc)			\
3864c87aefeSPatrick Mooney   .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
3874c87aefeSPatrick Mooney 
3884c87aefeSPatrick Mooney #define	USB_IFACE_PROTOCOL(ip)			\
3894c87aefeSPatrick Mooney   .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
3904c87aefeSPatrick Mooney 
3914c87aefeSPatrick Mooney #define	USB_IF_CSI(class,subclass,info)			\
3924c87aefeSPatrick Mooney   USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
3934c87aefeSPatrick Mooney 
3944c87aefeSPatrick Mooney #define	USB_DRIVER_INFO(n)			\
3954c87aefeSPatrick Mooney   .driver_info = (n)
3964c87aefeSPatrick Mooney 
3974c87aefeSPatrick Mooney #define	USB_GET_DRIVER_INFO(did)		\
3984c87aefeSPatrick Mooney   (did)->driver_info
3994c87aefeSPatrick Mooney 
4004c87aefeSPatrick Mooney /*
4014c87aefeSPatrick Mooney  * The following structure keeps information that is used to match
4024c87aefeSPatrick Mooney  * against an array of "usb_device_id" elements.
4034c87aefeSPatrick Mooney  */
4044c87aefeSPatrick Mooney struct usbd_lookup_info {
4054c87aefeSPatrick Mooney 	uint16_t idVendor;
4064c87aefeSPatrick Mooney 	uint16_t idProduct;
4074c87aefeSPatrick Mooney 	uint16_t bcdDevice;
4084c87aefeSPatrick Mooney 	uint8_t	bDeviceClass;
4094c87aefeSPatrick Mooney 	uint8_t	bDeviceSubClass;
4104c87aefeSPatrick Mooney 	uint8_t	bDeviceProtocol;
4114c87aefeSPatrick Mooney 	uint8_t	bInterfaceClass;
4124c87aefeSPatrick Mooney 	uint8_t	bInterfaceSubClass;
4134c87aefeSPatrick Mooney 	uint8_t	bInterfaceProtocol;
4144c87aefeSPatrick Mooney 	uint8_t	bIfaceIndex;
4154c87aefeSPatrick Mooney 	uint8_t	bIfaceNum;
4164c87aefeSPatrick Mooney 	uint8_t	bConfigIndex;
4174c87aefeSPatrick Mooney 	uint8_t	bConfigNum;
4184c87aefeSPatrick Mooney };
4194c87aefeSPatrick Mooney 
4204c87aefeSPatrick Mooney /* Structure used by probe and attach */
4214c87aefeSPatrick Mooney 
4224c87aefeSPatrick Mooney struct usb_attach_arg {
4234c87aefeSPatrick Mooney 	struct usbd_lookup_info info;
4244c87aefeSPatrick Mooney 	device_t temp_dev;		/* for internal use */
4254c87aefeSPatrick Mooney 	unsigned long driver_info;	/* for internal use */
4264c87aefeSPatrick Mooney 	void *driver_ivar;
4274c87aefeSPatrick Mooney 	struct usb_device *device;	/* current device */
4284c87aefeSPatrick Mooney 	struct usb_interface *iface;	/* current interface */
4294c87aefeSPatrick Mooney 	enum usb_hc_mode usb_mode;	/* host or device mode */
4304c87aefeSPatrick Mooney 	uint8_t	port;
4314c87aefeSPatrick Mooney 	uint8_t dev_state;
4324c87aefeSPatrick Mooney #define UAA_DEV_READY		0
4334c87aefeSPatrick Mooney #define UAA_DEV_DISABLED	1
4344c87aefeSPatrick Mooney #define UAA_DEV_EJECTING	2
4354c87aefeSPatrick Mooney };
4364c87aefeSPatrick Mooney 
4374c87aefeSPatrick Mooney /*
4384c87aefeSPatrick Mooney  * The following is a wrapper for the callout structure to ease
4394c87aefeSPatrick Mooney  * porting the code to other platforms.
4404c87aefeSPatrick Mooney  */
4414c87aefeSPatrick Mooney struct usb_callout {
4424c87aefeSPatrick Mooney 	struct callout co;
4434c87aefeSPatrick Mooney };
4444c87aefeSPatrick Mooney #define	usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
4454c87aefeSPatrick Mooney #define	usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
4464c87aefeSPatrick Mooney #define	usb_callout_stop(c) callout_stop(&(c)->co)
4474c87aefeSPatrick Mooney #define	usb_callout_drain(c) callout_drain(&(c)->co)
4484c87aefeSPatrick Mooney #define	usb_callout_pending(c) callout_pending(&(c)->co)
4494c87aefeSPatrick Mooney 
4504c87aefeSPatrick Mooney /* USB transfer states */
4514c87aefeSPatrick Mooney 
4524c87aefeSPatrick Mooney #define	USB_ST_SETUP       0
4534c87aefeSPatrick Mooney #define	USB_ST_TRANSFERRED 1
4544c87aefeSPatrick Mooney #define	USB_ST_ERROR       2
4554c87aefeSPatrick Mooney 
4564c87aefeSPatrick Mooney /* USB handle request states */
4574c87aefeSPatrick Mooney #define	USB_HR_NOT_COMPLETE	0
4584c87aefeSPatrick Mooney #define	USB_HR_COMPLETE_OK	1
4594c87aefeSPatrick Mooney #define	USB_HR_COMPLETE_ERR	2
4604c87aefeSPatrick Mooney 
4614c87aefeSPatrick Mooney /*
4624c87aefeSPatrick Mooney  * The following macro will return the current state of an USB
4634c87aefeSPatrick Mooney  * transfer like defined by the "USB_ST_XXX" enums.
4644c87aefeSPatrick Mooney  */
4654c87aefeSPatrick Mooney #define	USB_GET_STATE(xfer) (usbd_xfer_state(xfer))
4664c87aefeSPatrick Mooney 
4674c87aefeSPatrick Mooney /*
4684c87aefeSPatrick Mooney  * The following structure defines the USB process message header.
4694c87aefeSPatrick Mooney  */
4704c87aefeSPatrick Mooney struct usb_proc_msg {
4714c87aefeSPatrick Mooney 	TAILQ_ENTRY(usb_proc_msg) pm_qentry;
4724c87aefeSPatrick Mooney 	usb_proc_callback_t *pm_callback;
4734c87aefeSPatrick Mooney 	usb_size_t pm_num;
4744c87aefeSPatrick Mooney };
4754c87aefeSPatrick Mooney 
4764c87aefeSPatrick Mooney #define	USB_FIFO_TX 0
4774c87aefeSPatrick Mooney #define	USB_FIFO_RX 1
4784c87aefeSPatrick Mooney 
4794c87aefeSPatrick Mooney /*
4804c87aefeSPatrick Mooney  * Locking note for the following functions.  All the
4814c87aefeSPatrick Mooney  * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
4824c87aefeSPatrick Mooney  * locked. The others are called unlocked.
4834c87aefeSPatrick Mooney  */
4844c87aefeSPatrick Mooney struct usb_fifo_methods {
4854c87aefeSPatrick Mooney 	usb_fifo_open_t *f_open;
4864c87aefeSPatrick Mooney 	usb_fifo_close_t *f_close;
4874c87aefeSPatrick Mooney 	usb_fifo_ioctl_t *f_ioctl;
4884c87aefeSPatrick Mooney 	/*
4894c87aefeSPatrick Mooney 	 * NOTE: The post-ioctl callback is called after the USB reference
4904c87aefeSPatrick Mooney 	 * gets locked in the IOCTL handler:
4914c87aefeSPatrick Mooney 	 */
4924c87aefeSPatrick Mooney 	usb_fifo_ioctl_t *f_ioctl_post;
4934c87aefeSPatrick Mooney 	usb_fifo_cmd_t *f_start_read;
4944c87aefeSPatrick Mooney 	usb_fifo_cmd_t *f_stop_read;
4954c87aefeSPatrick Mooney 	usb_fifo_cmd_t *f_start_write;
4964c87aefeSPatrick Mooney 	usb_fifo_cmd_t *f_stop_write;
4974c87aefeSPatrick Mooney 	usb_fifo_filter_t *f_filter_read;
4984c87aefeSPatrick Mooney 	usb_fifo_filter_t *f_filter_write;
4994c87aefeSPatrick Mooney 	const char *basename[4];
5004c87aefeSPatrick Mooney 	const char *postfix[4];
5014c87aefeSPatrick Mooney };
5024c87aefeSPatrick Mooney 
5034c87aefeSPatrick Mooney struct usb_fifo_sc {
5044c87aefeSPatrick Mooney 	struct usb_fifo *fp[2];
5054c87aefeSPatrick Mooney 	struct usb_fs_privdata *dev;
5064c87aefeSPatrick Mooney };
5074c87aefeSPatrick Mooney 
5084c87aefeSPatrick Mooney const char *usbd_errstr(usb_error_t error);
5094c87aefeSPatrick Mooney void	*usbd_find_descriptor(struct usb_device *udev, void *id,
5104c87aefeSPatrick Mooney 	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
5114c87aefeSPatrick Mooney 	    uint8_t subtype, uint8_t subtype_mask);
5124c87aefeSPatrick Mooney struct usb_config_descriptor *usbd_get_config_descriptor(
5134c87aefeSPatrick Mooney 	    struct usb_device *udev);
5144c87aefeSPatrick Mooney struct usb_device_descriptor *usbd_get_device_descriptor(
5154c87aefeSPatrick Mooney 	    struct usb_device *udev);
5164c87aefeSPatrick Mooney struct usb_interface *usbd_get_iface(struct usb_device *udev,
5174c87aefeSPatrick Mooney 	    uint8_t iface_index);
5184c87aefeSPatrick Mooney struct usb_interface_descriptor *usbd_get_interface_descriptor(
5194c87aefeSPatrick Mooney 	    struct usb_interface *iface);
5204c87aefeSPatrick Mooney struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
5214c87aefeSPatrick Mooney 		    const struct usb_config *setup);
5224c87aefeSPatrick Mooney struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
5234c87aefeSPatrick Mooney usb_error_t	usbd_interface_count(struct usb_device *udev, uint8_t *count);
5244c87aefeSPatrick Mooney enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
5254c87aefeSPatrick Mooney enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
5264c87aefeSPatrick Mooney void	device_set_usb_desc(device_t dev);
5274c87aefeSPatrick Mooney void	usb_pause_mtx(struct mtx *mtx, int _ticks);
5284c87aefeSPatrick Mooney usb_error_t	usbd_set_pnpinfo(struct usb_device *udev,
5294c87aefeSPatrick Mooney 			uint8_t iface_index, const char *pnpinfo);
5304c87aefeSPatrick Mooney usb_error_t	usbd_add_dynamic_quirk(struct usb_device *udev,
5314c87aefeSPatrick Mooney 			uint16_t quirk);
5324c87aefeSPatrick Mooney usb_error_t	usbd_set_endpoint_mode(struct usb_device *udev,
5334c87aefeSPatrick Mooney 			struct usb_endpoint *ep, uint8_t ep_mode);
5344c87aefeSPatrick Mooney uint8_t		usbd_get_endpoint_mode(struct usb_device *udev,
5354c87aefeSPatrick Mooney 			struct usb_endpoint *ep);
5364c87aefeSPatrick Mooney 
5374c87aefeSPatrick Mooney const struct usb_device_id *usbd_lookup_id_by_info(
5384c87aefeSPatrick Mooney 	    const struct usb_device_id *id, usb_size_t sizeof_id,
5394c87aefeSPatrick Mooney 	    const struct usbd_lookup_info *info);
5404c87aefeSPatrick Mooney int	usbd_lookup_id_by_uaa(const struct usb_device_id *id,
5414c87aefeSPatrick Mooney 	    usb_size_t sizeof_id, struct usb_attach_arg *uaa);
5424c87aefeSPatrick Mooney 
5434c87aefeSPatrick Mooney usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
5444c87aefeSPatrick Mooney 		    struct usb_device_request *req, void *data, uint16_t flags,
5454c87aefeSPatrick Mooney 		    uint16_t *actlen, usb_timeout_t timeout);
5464c87aefeSPatrick Mooney #define	usbd_do_request(u,m,r,d) \
5474c87aefeSPatrick Mooney   usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)
5484c87aefeSPatrick Mooney 
5494c87aefeSPatrick Mooney uint8_t	usbd_clear_stall_callback(struct usb_xfer *xfer1,
5504c87aefeSPatrick Mooney 	    struct usb_xfer *xfer2);
5514c87aefeSPatrick Mooney uint8_t	usbd_get_interface_altindex(struct usb_interface *iface);
5524c87aefeSPatrick Mooney usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
5534c87aefeSPatrick Mooney 	    uint8_t iface_index, uint8_t alt_index);
5544c87aefeSPatrick Mooney uint32_t usbd_get_isoc_fps(struct usb_device *udev);
5554c87aefeSPatrick Mooney usb_error_t usbd_transfer_setup(struct usb_device *udev,
5564c87aefeSPatrick Mooney 	    const uint8_t *ifaces, struct usb_xfer **pxfer,
5574c87aefeSPatrick Mooney 	    const struct usb_config *setup_start, uint16_t n_setup,
5584c87aefeSPatrick Mooney 	    void *priv_sc, struct mtx *priv_mtx);
5594c87aefeSPatrick Mooney void	usbd_transfer_submit(struct usb_xfer *xfer);
5604c87aefeSPatrick Mooney void	usbd_transfer_clear_stall(struct usb_xfer *xfer);
5614c87aefeSPatrick Mooney void	usbd_transfer_drain(struct usb_xfer *xfer);
5624c87aefeSPatrick Mooney uint8_t	usbd_transfer_pending(struct usb_xfer *xfer);
5634c87aefeSPatrick Mooney void	usbd_transfer_start(struct usb_xfer *xfer);
5644c87aefeSPatrick Mooney void	usbd_transfer_stop(struct usb_xfer *xfer);
5654c87aefeSPatrick Mooney void	usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
5664c87aefeSPatrick Mooney void	usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
5674c87aefeSPatrick Mooney void	usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
5684c87aefeSPatrick Mooney 	    uint8_t parent_index);
5694c87aefeSPatrick Mooney uint8_t	usbd_get_bus_index(struct usb_device *udev);
5704c87aefeSPatrick Mooney uint8_t	usbd_get_device_index(struct usb_device *udev);
5714c87aefeSPatrick Mooney void	usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
5724c87aefeSPatrick Mooney uint8_t	usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode);
5734c87aefeSPatrick Mooney uint8_t	usbd_device_attached(struct usb_device *udev);
5744c87aefeSPatrick Mooney 
5754c87aefeSPatrick Mooney usb_frlength_t
5764c87aefeSPatrick Mooney 	usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex);
5774c87aefeSPatrick Mooney void	usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
5784c87aefeSPatrick Mooney 	    int *aframes, int *nframes);
5794c87aefeSPatrick Mooney struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t);
5804c87aefeSPatrick Mooney void	*usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t);
5814c87aefeSPatrick Mooney void	*usbd_xfer_softc(struct usb_xfer *xfer);
5824c87aefeSPatrick Mooney void	*usbd_xfer_get_priv(struct usb_xfer *xfer);
5834c87aefeSPatrick Mooney void	usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
5844c87aefeSPatrick Mooney void	usbd_xfer_set_interval(struct usb_xfer *xfer, int);
5854c87aefeSPatrick Mooney uint8_t	usbd_xfer_state(struct usb_xfer *xfer);
5864c87aefeSPatrick Mooney void	usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
5874c87aefeSPatrick Mooney 	    void *ptr, usb_frlength_t len);
5884c87aefeSPatrick Mooney void	usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
5894c87aefeSPatrick Mooney 	    void **ptr, int *len);
5904c87aefeSPatrick Mooney void	usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
5914c87aefeSPatrick Mooney 	    usb_frcount_t frindex);
5924c87aefeSPatrick Mooney usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
5934c87aefeSPatrick Mooney usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
5944c87aefeSPatrick Mooney usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
5954c87aefeSPatrick Mooney uint8_t	usbd_xfer_get_fps_shift(struct usb_xfer *xfer);
5964c87aefeSPatrick Mooney usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
5974c87aefeSPatrick Mooney 	    usb_frcount_t frindex);
5984c87aefeSPatrick Mooney void	usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
5994c87aefeSPatrick Mooney 	    usb_frlength_t len);
6004c87aefeSPatrick Mooney void	usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
6014c87aefeSPatrick Mooney void	usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
6024c87aefeSPatrick Mooney void	usbd_xfer_set_stall(struct usb_xfer *xfer);
6034c87aefeSPatrick Mooney int	usbd_xfer_is_stalled(struct usb_xfer *xfer);
6044c87aefeSPatrick Mooney void	usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
6054c87aefeSPatrick Mooney void	usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
6064c87aefeSPatrick Mooney uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer);
6074c87aefeSPatrick Mooney uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer);
6084c87aefeSPatrick Mooney 
6094c87aefeSPatrick Mooney void	usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
6104c87aefeSPatrick Mooney 	    const void *ptr, usb_frlength_t len);
6114c87aefeSPatrick Mooney int	usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
6124c87aefeSPatrick Mooney 	    const void *ptr, usb_frlength_t len);
6134c87aefeSPatrick Mooney void	usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
6144c87aefeSPatrick Mooney 	    void *ptr, usb_frlength_t len);
6154c87aefeSPatrick Mooney int	usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
6164c87aefeSPatrick Mooney 	    void *ptr, usb_frlength_t len);
6174c87aefeSPatrick Mooney void	usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
6184c87aefeSPatrick Mooney 	    struct usb_page_search *res);
6194c87aefeSPatrick Mooney void	usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
6204c87aefeSPatrick Mooney 	    struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
6214c87aefeSPatrick Mooney void	usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
6224c87aefeSPatrick Mooney 	    usb_frlength_t len);
6234c87aefeSPatrick Mooney void	usbd_start_re_enumerate(struct usb_device *udev);
6244c87aefeSPatrick Mooney usb_error_t
6254c87aefeSPatrick Mooney 	usbd_start_set_config(struct usb_device *, uint8_t);
6264c87aefeSPatrick Mooney 
6274c87aefeSPatrick Mooney int	usb_fifo_attach(struct usb_device *udev, void *priv_sc,
6284c87aefeSPatrick Mooney 	    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
6294c87aefeSPatrick Mooney 	    struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit,
6304c87aefeSPatrick Mooney 	    uint8_t iface_index, uid_t uid, gid_t gid, int mode);
6314c87aefeSPatrick Mooney void	usb_fifo_detach(struct usb_fifo_sc *f_sc);
6324c87aefeSPatrick Mooney int	usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
6334c87aefeSPatrick Mooney 	    uint16_t nbuf);
6344c87aefeSPatrick Mooney void	usb_fifo_free_buffer(struct usb_fifo *f);
6354c87aefeSPatrick Mooney uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
6364c87aefeSPatrick Mooney void	usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
6374c87aefeSPatrick Mooney 	    usb_frlength_t offset, usb_frlength_t len, uint8_t what);
6384c87aefeSPatrick Mooney void	usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
6394c87aefeSPatrick Mooney 	    usb_size_t len, uint8_t what);
6404c87aefeSPatrick Mooney uint8_t	usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
6414c87aefeSPatrick Mooney void	usb_fifo_put_data_error(struct usb_fifo *fifo);
6424c87aefeSPatrick Mooney uint8_t	usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
6434c87aefeSPatrick Mooney 	    usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
6444c87aefeSPatrick Mooney 	    uint8_t what);
6454c87aefeSPatrick Mooney uint8_t	usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
6464c87aefeSPatrick Mooney 	    usb_size_t len, usb_size_t *actlen, uint8_t what);
6474c87aefeSPatrick Mooney uint8_t	usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
6484c87aefeSPatrick Mooney 	    usb_size_t *plen);
6494c87aefeSPatrick Mooney void	usb_fifo_reset(struct usb_fifo *f);
6504c87aefeSPatrick Mooney void	usb_fifo_wakeup(struct usb_fifo *f);
6514c87aefeSPatrick Mooney void	usb_fifo_get_data_error(struct usb_fifo *fifo);
6524c87aefeSPatrick Mooney void	*usb_fifo_softc(struct usb_fifo *fifo);
6534c87aefeSPatrick Mooney void	usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
6544c87aefeSPatrick Mooney void	usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
6554c87aefeSPatrick Mooney void	usb_fifo_free(struct usb_fifo *f);
6564c87aefeSPatrick Mooney #endif /* _KERNEL */
6574c87aefeSPatrick Mooney #endif /* _USB_USBDI_H_ */