xref: /freebsd/sys/dev/usb/usbdi.h (revision eb6219e337483cb80eccb6f2b4ad649bc1d751ec)
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_interface;
33 struct usb_endpoint;
34 struct usb_page_cache;
35 struct usb_page_search;
36 struct usb_process;
37 struct usb_proc_msg;
38 struct usb_mbuf;
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 
82 #define	USB_NO_TIMEOUT 0
83 #define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */
84 
85 #if defined(_KERNEL)
86 /* typedefs */
87 
88 typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
89 typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
90 typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
91     struct usb_device_request *, const void **, uint16_t *);
92 
93 typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
94 typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
95 typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
96 typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
97 typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
98 
99 /*
100  * The following macros are used used to convert milliseconds into
101  * HZ. We use 1024 instead of 1000 milliseconds per second to save a
102  * full division.
103  */
104 #define	USB_MS_HZ 1024
105 
106 #define	USB_MS_TO_TICKS(ms) \
107   (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
108 
109 /*
110  * Common queue structure for USB transfers.
111  */
112 struct usb_xfer_queue {
113 	TAILQ_HEAD(, usb_xfer) head;
114 	struct usb_xfer *curr;		/* current USB transfer processed */
115 	void    (*command) (struct usb_xfer_queue *pq);
116 	uint8_t	recurse_1:1;
117 	uint8_t	recurse_2:1;
118 };
119 
120 /*
121  * The following structure defines an USB endpoint
122  * USB endpoint.
123  */
124 struct usb_endpoint {
125 	struct usb_xfer_queue endpoint_q;	/* queue of USB transfers */
126 
127 	struct usb_endpoint_descriptor *edesc;
128 	struct usb_pipe_methods *methods;	/* set by HC driver */
129 
130 	uint16_t isoc_next;
131 	uint16_t refcount;
132 
133 	uint8_t	toggle_next:1;		/* next data toggle value */
134 	uint8_t	is_stalled:1;		/* set if endpoint is stalled */
135 	uint8_t	is_synced:1;		/* set if we a synchronised */
136 	uint8_t	unused:5;
137 	uint8_t	iface_index;		/* not used by "default endpoint" */
138 };
139 
140 /*
141  * The following structure defines an USB interface.
142  */
143 struct usb_interface {
144 	struct usb_interface_descriptor *idesc;
145 	device_t subdev;
146 	uint8_t	alt_index;
147 	uint8_t	parent_iface_index;
148 
149 	/* Linux compat */
150 	struct usb_host_interface *altsetting;
151 	struct usb_host_interface *cur_altsetting;
152 	struct usb_device *linux_udev;
153 	void   *bsd_priv_sc;		/* device specific information */
154 	uint8_t	num_altsetting;		/* number of alternate settings */
155 	uint8_t	bsd_iface_index;
156 };
157 
158 /*
159  * The following structure defines a set of USB transfer flags.
160  */
161 struct usb_xfer_flags {
162 	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
163 					 * last */
164 	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
165 	uint8_t	short_frames_ok:1;	/* allow short frames */
166 	uint8_t	pipe_bof:1;		/* block pipe on failure */
167 	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
168 					 * "max_frame_size" */
169 	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
170 	uint8_t	manual_status:1;	/* non automatic status stage on
171 					 * control transfers */
172 	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
173 					 * be ignored */
174 	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
175 					 * this USB transfer should be stalled
176 					 * before starting this transfer! */
177 };
178 
179 /*
180  * The following structure define an USB configuration, that basically
181  * is used when setting up an USB transfer.
182  */
183 struct usb_config {
184 	usb_callback_t *callback;	/* USB transfer callback */
185 	usb_frlength_t bufsize;	/* total pipe buffer size in bytes */
186 	usb_frcount_t frames;		/* maximum number of USB frames */
187 	usb_timeout_t interval;	/* interval in milliseconds */
188 #define	USB_DEFAULT_INTERVAL	0
189 	usb_timeout_t timeout;		/* transfer timeout in milliseconds */
190 	struct usb_xfer_flags flags;	/* transfer flags */
191 	enum usb_hc_mode usb_mode;	/* host or device mode */
192 	uint8_t	type;			/* pipe type */
193 	uint8_t	endpoint;		/* pipe number */
194 	uint8_t	direction;		/* pipe direction */
195 	uint8_t	ep_index;		/* pipe index match to use */
196 	uint8_t	if_index;		/* "ifaces" index to use */
197 };
198 
199 /*
200  * The following structure is used when looking up an USB driver for
201  * an USB device. It is inspired by the Linux structure called
202  * "usb_device_id".
203  */
204 struct usb_device_id {
205 
206 	/* Hook for driver specific information */
207 	unsigned long driver_info;
208 
209 	/* Used for product specific matches; the BCD range is inclusive */
210 	uint16_t idVendor;
211 	uint16_t idProduct;
212 	uint16_t bcdDevice_lo;
213 	uint16_t bcdDevice_hi;
214 
215 	/* Used for device class matches */
216 	uint8_t	bDeviceClass;
217 	uint8_t	bDeviceSubClass;
218 	uint8_t	bDeviceProtocol;
219 
220 	/* Used for interface class matches */
221 	uint8_t	bInterfaceClass;
222 	uint8_t	bInterfaceSubClass;
223 	uint8_t	bInterfaceProtocol;
224 
225 	/* Select which fields to match against */
226 	uint8_t	match_flag_vendor:1;
227 	uint8_t	match_flag_product:1;
228 	uint8_t	match_flag_dev_lo:1;
229 	uint8_t	match_flag_dev_hi:1;
230 	uint8_t	match_flag_dev_class:1;
231 	uint8_t	match_flag_dev_subclass:1;
232 	uint8_t	match_flag_dev_protocol:1;
233 	uint8_t	match_flag_int_class:1;
234 	uint8_t	match_flag_int_subclass:1;
235 	uint8_t	match_flag_int_protocol:1;
236 
237 #if USB_HAVE_COMPAT_LINUX
238 	/* which fields to match against */
239 	uint16_t match_flags;
240 #define	USB_DEVICE_ID_MATCH_VENDOR		0x0001
241 #define	USB_DEVICE_ID_MATCH_PRODUCT		0x0002
242 #define	USB_DEVICE_ID_MATCH_DEV_LO		0x0004
243 #define	USB_DEVICE_ID_MATCH_DEV_HI		0x0008
244 #define	USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
245 #define	USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
246 #define	USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
247 #define	USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
248 #define	USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
249 #define	USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
250 #endif
251 };
252 
253 #define	USB_VENDOR(vend)			\
254   .match_flag_vendor = 1, .idVendor = (vend)
255 
256 #define	USB_PRODUCT(prod)			\
257   .match_flag_product = 1, .idProduct = (prod)
258 
259 #define	USB_VP(vend,prod)			\
260   USB_VENDOR(vend), USB_PRODUCT(prod)
261 
262 #define	USB_VPI(vend,prod,info)			\
263   USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
264 
265 #define	USB_DEV_BCD_GTEQ(lo)	/* greater than or equal */ \
266   .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
267 
268 #define	USB_DEV_BCD_LTEQ(hi)	/* less than or equal */ \
269   .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
270 
271 #define	USB_DEV_CLASS(dc)			\
272   .match_flag_dev_class = 1, .bDeviceClass = (dc)
273 
274 #define	USB_DEV_SUBCLASS(dsc)			\
275   .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
276 
277 #define	USB_DEV_PROTOCOL(dp)			\
278   .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
279 
280 #define	USB_IFACE_CLASS(ic)			\
281   .match_flag_int_class = 1, .bInterfaceClass = (ic)
282 
283 #define	USB_IFACE_SUBCLASS(isc)			\
284   .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
285 
286 #define	USB_IFACE_PROTOCOL(ip)			\
287   .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
288 
289 #define	USB_IF_CSI(class,subclass,info)			\
290   USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
291 
292 #define	USB_DRIVER_INFO(n)			\
293   .driver_info = (n)
294 
295 #define	USB_GET_DRIVER_INFO(did)		\
296   (did)->driver_info
297 
298 /*
299  * The following structure keeps information that is used to match
300  * against an array of "usb_device_id" elements.
301  */
302 struct usbd_lookup_info {
303 	uint16_t idVendor;
304 	uint16_t idProduct;
305 	uint16_t bcdDevice;
306 	uint8_t	bDeviceClass;
307 	uint8_t	bDeviceSubClass;
308 	uint8_t	bDeviceProtocol;
309 	uint8_t	bInterfaceClass;
310 	uint8_t	bInterfaceSubClass;
311 	uint8_t	bInterfaceProtocol;
312 	uint8_t	bIfaceIndex;
313 	uint8_t	bIfaceNum;
314 	uint8_t	bConfigIndex;
315 	uint8_t	bConfigNum;
316 };
317 
318 /* Structure used by probe and attach */
319 
320 struct usb_attach_arg {
321 	struct usbd_lookup_info info;
322 	device_t temp_dev;		/* for internal use */
323 	unsigned long driver_info;	/* for internal use */
324 	void *driver_ivar;
325 	struct usb_device *device;	/* current device */
326 	struct usb_interface *iface;	/* current interface */
327 	enum usb_hc_mode usb_mode;	/* host or device mode */
328 	uint8_t	port;
329 	uint8_t	use_generic;		/* hint for generic drivers */
330 };
331 
332 /*
333  * The following is a wrapper for the callout structure to ease
334  * porting the code to other platforms.
335  */
336 struct usb_callout {
337 	struct callout co;
338 };
339 #define	usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
340 #define	usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
341 #define	usb_callout_stop(c) callout_stop(&(c)->co)
342 #define	usb_callout_drain(c) callout_drain(&(c)->co)
343 #define	usb_callout_pending(c) callout_pending(&(c)->co)
344 
345 /* USB transfer states */
346 
347 #define	USB_ST_SETUP       0
348 #define	USB_ST_TRANSFERRED 1
349 #define	USB_ST_ERROR       2
350 
351 /* USB handle request states */
352 #define	USB_HR_NOT_COMPLETE	0
353 #define	USB_HR_COMPLETE_OK	1
354 #define	USB_HR_COMPLETE_ERR	2
355 
356 /*
357  * The following macro will return the current state of an USB
358  * transfer like defined by the "USB_ST_XXX" enums.
359  */
360 #define	USB_GET_STATE(xfer) (usbd_xfer_state(xfer))
361 
362 /*
363  * The following structure defines the USB process message header.
364  */
365 struct usb_proc_msg {
366 	TAILQ_ENTRY(usb_proc_msg) pm_qentry;
367 	usb_proc_callback_t *pm_callback;
368 	usb_size_t pm_num;
369 };
370 
371 #define	USB_FIFO_TX 0
372 #define	USB_FIFO_RX 1
373 
374 /*
375  * Locking note for the following functions.  All the
376  * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
377  * locked. The others are called unlocked.
378  */
379 struct usb_fifo_methods {
380 	usb_fifo_open_t *f_open;
381 	usb_fifo_close_t *f_close;
382 	usb_fifo_ioctl_t *f_ioctl;
383 	/*
384 	 * NOTE: The post-ioctl callback is called after the USB reference
385 	 * gets locked in the IOCTL handler:
386 	 */
387 	usb_fifo_ioctl_t *f_ioctl_post;
388 	usb_fifo_cmd_t *f_start_read;
389 	usb_fifo_cmd_t *f_stop_read;
390 	usb_fifo_cmd_t *f_start_write;
391 	usb_fifo_cmd_t *f_stop_write;
392 	usb_fifo_filter_t *f_filter_read;
393 	usb_fifo_filter_t *f_filter_write;
394 	const char *basename[4];
395 	const char *postfix[4];
396 };
397 
398 struct usb_fifo_sc {
399 	struct usb_fifo *fp[2];
400 	struct cdev* dev;
401 };
402 
403 const char *usbd_errstr(usb_error_t error);
404 void	*usbd_find_descriptor(struct usb_device *udev, void *id,
405 	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
406 	    uint8_t subtype, uint8_t subtype_mask);
407 struct usb_config_descriptor *usbd_get_config_descriptor(
408 	    struct usb_device *udev);
409 struct usb_device_descriptor *usbd_get_device_descriptor(
410 	    struct usb_device *udev);
411 struct usb_interface *usbd_get_iface(struct usb_device *udev,
412 	    uint8_t iface_index);
413 struct usb_interface_descriptor *usbd_get_interface_descriptor(
414 	    struct usb_interface *iface);
415 struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
416 		    const struct usb_config *setup);
417 struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
418 usb_error_t	usbd_interface_count(struct usb_device *udev, uint8_t *count);
419 enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
420 enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
421 void	device_set_usb_desc(device_t dev);
422 void	usb_pause_mtx(struct mtx *mtx, int _ticks);
423 
424 const struct usb_device_id *usbd_lookup_id_by_info(
425 	    const struct usb_device_id *id, usb_size_t sizeof_id,
426 	    const struct usbd_lookup_info *info);
427 int	usbd_lookup_id_by_uaa(const struct usb_device_id *id,
428 	    usb_size_t sizeof_id, struct usb_attach_arg *uaa);
429 
430 usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
431 		    struct usb_device_request *req, void *data, uint16_t flags,
432 		    uint16_t *actlen, usb_timeout_t timeout);
433 #define	usbd_do_request(u,m,r,d) \
434   usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)
435 
436 uint8_t	usbd_clear_stall_callback(struct usb_xfer *xfer1,
437 	    struct usb_xfer *xfer2);
438 uint8_t	usbd_get_interface_altindex(struct usb_interface *iface);
439 usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
440 	    uint8_t iface_index, uint8_t alt_index);
441 uint32_t usbd_get_isoc_fps(struct usb_device *udev);
442 usb_error_t usbd_transfer_setup(struct usb_device *udev,
443 	    const uint8_t *ifaces, struct usb_xfer **pxfer,
444 	    const struct usb_config *setup_start, uint16_t n_setup,
445 	    void *priv_sc, struct mtx *priv_mtx);
446 void	usbd_transfer_submit(struct usb_xfer *xfer);
447 void	usbd_transfer_clear_stall(struct usb_xfer *xfer);
448 void	usbd_transfer_drain(struct usb_xfer *xfer);
449 uint8_t	usbd_transfer_pending(struct usb_xfer *xfer);
450 void	usbd_transfer_start(struct usb_xfer *xfer);
451 void	usbd_transfer_stop(struct usb_xfer *xfer);
452 void	usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
453 void	usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
454 void	usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
455 	    uint8_t parent_index);
456 uint8_t	usbd_get_bus_index(struct usb_device *udev);
457 uint8_t	usbd_get_device_index(struct usb_device *udev);
458 void	usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
459 uint8_t	usbd_device_attached(struct usb_device *udev);
460 
461 void	usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
462 	    int *aframes, int *nframes);
463 struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *xfer,
464 	    usb_frcount_t frindex);
465 void	*usbd_xfer_softc(struct usb_xfer *xfer);
466 void	*usbd_xfer_get_priv(struct usb_xfer *xfer);
467 void	usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
468 void	usbd_xfer_set_interval(struct usb_xfer *xfer, int);
469 uint8_t	usbd_xfer_state(struct usb_xfer *xfer);
470 void	usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
471 	    void *ptr, usb_frlength_t len);
472 void	usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
473 	    void **ptr, int *len);
474 void	usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
475 	    usb_frcount_t frindex);
476 usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
477 usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
478 usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
479 usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
480 	    usb_frcount_t frindex);
481 void	usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
482 	    usb_frlength_t len);
483 void	usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
484 void	usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
485 void	usbd_xfer_set_stall(struct usb_xfer *xfer);
486 int	usbd_xfer_is_stalled(struct usb_xfer *xfer);
487 void	usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
488 void	usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
489 
490 void	usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
491 	    const void *ptr, usb_frlength_t len);
492 int	usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
493 	    const void *ptr, usb_frlength_t len);
494 void	usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
495 	    void *ptr, usb_frlength_t len);
496 int	usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
497 	    void *ptr, usb_frlength_t len);
498 void	usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
499 	    struct usb_page_search *res);
500 void	usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
501 	    struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
502 void	usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
503 	    usb_frlength_t len);
504 
505 int	usb_fifo_attach(struct usb_device *udev, void *priv_sc,
506 	    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
507 	    struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
508 	    uint8_t iface_index, uid_t uid, gid_t gid, int mode);
509 void	usb_fifo_detach(struct usb_fifo_sc *f_sc);
510 int	usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
511 	    uint16_t nbuf);
512 void	usb_fifo_free_buffer(struct usb_fifo *f);
513 uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
514 void	usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
515 	    usb_frlength_t offset, usb_frlength_t len, uint8_t what);
516 void	usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
517 	    usb_size_t len, uint8_t what);
518 uint8_t	usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
519 void	usb_fifo_put_data_error(struct usb_fifo *fifo);
520 uint8_t	usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
521 	    usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
522 	    uint8_t what);
523 uint8_t	usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
524 	    usb_size_t len, usb_size_t *actlen, uint8_t what);
525 uint8_t	usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
526 	    usb_size_t *plen);
527 void	usb_fifo_reset(struct usb_fifo *f);
528 void	usb_fifo_wakeup(struct usb_fifo *f);
529 void	usb_fifo_get_data_error(struct usb_fifo *fifo);
530 void	*usb_fifo_softc(struct usb_fifo *fifo);
531 #endif /* _KERNEL */
532 #endif /* _USB_USBDI_H_ */
533