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