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