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