1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2009 Andrew Thompson
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 usb_device_info;
42struct mbuf;
43
44typedef enum { /* keep in sync with usb_errstr_table */
45 USB_ERR_NORMAL_COMPLETION = 0,
46 USB_ERR_PENDING_REQUESTS, /* 1 */
47 USB_ERR_NOT_STARTED, /* 2 */
48 USB_ERR_INVAL, /* 3 */
49 USB_ERR_NOMEM, /* 4 */
50 USB_ERR_CANCELLED, /* 5 */
51 USB_ERR_BAD_ADDRESS, /* 6 */
52 USB_ERR_BAD_BUFSIZE, /* 7 */
53 USB_ERR_BAD_FLAG, /* 8 */
54 USB_ERR_NO_CALLBACK, /* 9 */
55 USB_ERR_IN_USE, /* 10 */
56 USB_ERR_NO_ADDR, /* 11 */
57 USB_ERR_NO_PIPE, /* 12 */
58 USB_ERR_ZERO_NFRAMES, /* 13 */
59 USB_ERR_ZERO_MAXP, /* 14 */
60 USB_ERR_SET_ADDR_FAILED, /* 15 */
61 USB_ERR_NO_POWER, /* 16 */
62 USB_ERR_TOO_DEEP, /* 17 */
63 USB_ERR_IOERROR, /* 18 */
64 USB_ERR_NOT_CONFIGURED, /* 19 */
65 USB_ERR_TIMEOUT, /* 20 */
66 USB_ERR_SHORT_XFER, /* 21 */
67 USB_ERR_STALLED, /* 22 */
68 USB_ERR_INTERRUPTED, /* 23 */
69 USB_ERR_DMA_LOAD_FAILED, /* 24 */
70 USB_ERR_BAD_CONTEXT, /* 25 */
71 USB_ERR_NO_ROOT_HUB, /* 26 */
72 USB_ERR_NO_INTR_THREAD, /* 27 */
73 USB_ERR_NOT_LOCKED, /* 28 */
74 USB_ERR_MAX
75} usb_error_t;
76
77/*
78 * Flags for transfers
79 */
80#define USB_FORCE_SHORT_XFER 0x0001 /* force a short transmit last */
81#define USB_SHORT_XFER_OK 0x0004 /* allow short reads */
82#define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */
83#define USB_USER_DATA_PTR 0x0020 /* internal flag */
84#define USB_MULTI_SHORT_OK 0x0040 /* allow multiple short frames */
85#define USB_MANUAL_STATUS 0x0080 /* manual ctrl status */
86
87#define USB_NO_TIMEOUT 0
88#define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */
89
90#if defined(_KERNEL) || defined(_STANDALONE)
91/* typedefs */
92
93typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
94typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
95typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
96 struct usb_device_request *, const void **, uint16_t *);
97
98typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
99typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
100typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
101typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
102typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
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 const 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 /* Total number of alternate settings, from 1 to 256 */
177 uint16_t num_altsetting;
178 /* Current alternate interface index, from 0 to 255 */
179 uint8_t alt_index;
180 uint8_t parent_iface_index;
181
182 /* Linux compat */
183 struct usb_host_interface *altsetting;
184 struct usb_host_interface *cur_altsetting;
185 struct usb_device *linux_udev;
186 void *bsd_priv_sc; /* device specific information */
187 char *pnpinfo; /* additional PnP-info for this interface */
188 uint8_t bsd_iface_index;
189};
190
191/*
192 * The following structure defines a set of USB transfer flags.
193 */
194struct usb_xfer_flags {
195 uint8_t force_short_xfer:1; /* force a short transmit transfer
196 * last */
197 uint8_t short_xfer_ok:1; /* allow short receive transfers */
198 uint8_t short_frames_ok:1; /* allow short frames */
199 uint8_t pipe_bof:1; /* block pipe on failure */
200 uint8_t proxy_buffer:1; /* makes buffer size a factor of
201 * "max_frame_size" */
202 uint8_t ext_buffer:1; /* uses external DMA buffer */
203 uint8_t manual_status:1; /* non automatic status stage on
204 * control transfers */
205 uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can
206 * be ignored */
207 uint8_t stall_pipe:1; /* set if the endpoint belonging to
208 * this USB transfer should be stalled
209 * before starting this transfer! */
210 uint8_t pre_scale_frames:1; /* "usb_config->frames" is
211 * assumed to give the
212 * buffering time in
213 * milliseconds and is
214 * converted into the nearest
215 * number of frames when the
216 * USB transfer is setup. This
217 * option only has effect for
218 * ISOCHRONOUS transfers.
219 */
220 uint8_t send_zlp:1; /* send a zero length packet first */
221};
222
223/*
224 * The following structure define an USB configuration, that basically
225 * is used when setting up an USB transfer.
226 */
227struct usb_config {
228 usb_callback_t *callback; /* USB transfer callback */
229 usb_frlength_t bufsize; /* total pipe buffer size in bytes */
230 usb_frcount_t frames; /* maximum number of USB frames */
231 usb_timeout_t interval; /* interval in milliseconds */
232#define USB_DEFAULT_INTERVAL 0
233 usb_timeout_t timeout; /* transfer timeout in milliseconds */
234 struct usb_xfer_flags flags; /* transfer flags */
235 usb_stream_t stream_id; /* USB3.0 specific */
236 enum usb_hc_mode usb_mode; /* host or device mode */
237 uint8_t type; /* pipe type */
238 uint8_t endpoint; /* pipe number */
239 uint8_t direction; /* pipe direction */
240 uint8_t ep_index; /* pipe index match to use */
241 uint8_t if_index; /* "ifaces" index to use */
242};
243
244/*
245 * Use these macro when defining USB device ID arrays if you want to
246 * have your driver module automatically loaded in host, device or
247 * both modes respectively:
248 */
249#if USB_HAVE_ID_SECTION
250#define STRUCT_USB_HOST_ID \
251 struct usb_device_id __section("usb_host_id")
252#define STRUCT_USB_DEVICE_ID \
253 struct usb_device_id __section("usb_device_id")
254#define STRUCT_USB_DUAL_ID \
255 struct usb_device_id __section("usb_dual_id")
256#else
257#define STRUCT_USB_HOST_ID \
258 struct usb_device_id
259#define STRUCT_USB_DEVICE_ID \
260 struct usb_device_id
261#define STRUCT_USB_DUAL_ID \
262 struct usb_device_id
263#endif /* USB_HAVE_ID_SECTION */
264
265/*
266 * The following structure is used when looking up an USB driver for
267 * an USB device. It is inspired by the Linux structure called
268 * "usb_device_id".
269 */
270struct usb_device_id {
271 /* Select which fields to match against */
272#if BYTE_ORDER == LITTLE_ENDIAN
273 uint16_t
274 match_flag_vendor:1,
275 match_flag_product:1,
276 match_flag_dev_lo:1,
277 match_flag_dev_hi:1,
278
279 match_flag_dev_class:1,
280 match_flag_dev_subclass:1,
281 match_flag_dev_protocol:1,
282 match_flag_int_class:1,
283
284 match_flag_int_subclass:1,
285 match_flag_int_protocol:1,
286 match_flag_unused:6;
287#else
288 uint16_t
289 match_flag_unused:6,
290 match_flag_int_protocol:1,
291 match_flag_int_subclass:1,
292
293 match_flag_int_class:1,
294 match_flag_dev_protocol:1,
295 match_flag_dev_subclass:1,
296 match_flag_dev_class:1,
297
298 match_flag_dev_hi:1,
299 match_flag_dev_lo:1,
300 match_flag_product:1,
301 match_flag_vendor:1;
302#endif
303
304 /* Used for product specific matches; the BCD range is inclusive */
305 uint16_t idVendor;
306 uint16_t idProduct;
307 uint16_t bcdDevice_lo;
308 uint16_t bcdDevice_hi;
309
310 /* Used for device class matches */
311 uint8_t bDeviceClass;
312 uint8_t bDeviceSubClass;
313 uint8_t bDeviceProtocol;
314
315 /* Used for interface class matches */
316 uint8_t bInterfaceClass;
317 uint8_t bInterfaceSubClass;
318 uint8_t bInterfaceProtocol;
319
320#if USB_HAVE_COMPAT_LINUX
321 /* which fields to match against */
322 uint16_t match_flags;
323#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
324#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
325#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
326#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
327#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
328#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
329#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
330#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
331#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
332#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
333#endif
334
335 /* Hook for driver specific information */
336 unsigned long driver_info;
337} __aligned(32);
338
339#define USB_STD_PNP_INFO "M16:mask;U16:vendor;U16:product;L16:release;G16:release;" \
340 "U8:devclass;U8:devsubclass;U8:devproto;" \
341 "U8:intclass;U8:intsubclass;U8:intprotocol;"
342#define USB_STD_PNP_HOST_INFO USB_STD_PNP_INFO "T:mode=host;"
343#define USB_STD_PNP_DEVICE_INFO USB_STD_PNP_INFO "T:mode=device;"
344#define USB_PNP_HOST_INFO(table) \
345 MODULE_PNP_INFO(USB_STD_PNP_HOST_INFO, uhub, table, table, \
346 sizeof(table) / sizeof(table[0]))
347#define USB_PNP_DEVICE_INFO(table) \
348 MODULE_PNP_INFO(USB_STD_PNP_DEVICE_INFO, uhub, table, table, \
349 sizeof(table) / sizeof(table[0]))
350#define USB_PNP_DUAL_INFO(table) \
351 MODULE_PNP_INFO(USB_STD_PNP_INFO, uhub, table, table, \
352 sizeof(table) / sizeof(table[0]))
353
354/* check that the size of the structure above is correct */
355extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1];
356
357#define USB_VENDOR(vend) \
358 .match_flag_vendor = 1, .idVendor = (vend)
359
360#define USB_PRODUCT(prod) \
361 .match_flag_product = 1, .idProduct = (prod)
362
363#define USB_VP(vend,prod) \
364 USB_VENDOR(vend), USB_PRODUCT(prod)
365
366#define USB_VPI(vend,prod,info) \
367 USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
368
369#define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \
370 .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
371
372#define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \
373 .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
374
375#define USB_DEV_CLASS(dc) \
376 .match_flag_dev_class = 1, .bDeviceClass = (dc)
377
378#define USB_DEV_SUBCLASS(dsc) \
379 .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
380
381#define USB_DEV_PROTOCOL(dp) \
382 .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
383
384#define USB_IFACE_CLASS(ic) \
385 .match_flag_int_class = 1, .bInterfaceClass = (ic)
386
387#define USB_IFACE_SUBCLASS(isc) \
388 .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
389
390#define USB_IFACE_PROTOCOL(ip) \
391 .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
392
393#define USB_IF_CSI(class,subclass,info) \
394 USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
395
396#define USB_DRIVER_INFO(n) \
397 .driver_info = (n)
398
399#define USB_GET_DRIVER_INFO(did) \
400 (did)->driver_info
401
402/*
403 * The following structure keeps information that is used to match
404 * against an array of "usb_device_id" elements.
405 */
406struct usbd_lookup_info {
407 uint16_t idVendor;
408 uint16_t idProduct;
409 uint16_t bcdDevice;
410 uint8_t bDeviceClass;
411 uint8_t bDeviceSubClass;
412 uint8_t bDeviceProtocol;
413 uint8_t bInterfaceClass;
414 uint8_t bInterfaceSubClass;
415 uint8_t bInterfaceProtocol;
416 uint8_t bIfaceIndex;
417 uint8_t bIfaceNum;
418 uint8_t bConfigIndex;
419 uint8_t bConfigNum;
420};
421
422/* Structure used by probe and attach */
423
424struct usb_attach_arg {
425 struct usbd_lookup_info info;
426 device_t temp_dev; /* for internal use */
427 unsigned long driver_info; /* for internal use */
428 void *driver_ivar;
429 struct usb_device *device; /* current device */
430 struct usb_interface *iface; /* current interface */
431 enum usb_hc_mode usb_mode; /* host or device mode */
432 uint8_t port;
433 uint8_t dev_state;
434#define UAA_DEV_READY 0
435#define UAA_DEV_DISABLED 1
436#define UAA_DEV_EJECTING 2
437};
438
439/*
440 * General purpose locking wrappers to ease supporting
441 * USB polled mode:
442 */
443#ifdef INVARIANTS
444#define USB_MTX_ASSERT(_m, _t) do { \
445 if (!USB_IN_POLLING_MODE_FUNC()) \
446 mtx_assert(_m, _t); \
447} while (0)
448#else
449#define USB_MTX_ASSERT(_m, _t) do { } while (0)
450#endif
451
452#define USB_MTX_LOCK(_m) do { \
453 if (!USB_IN_POLLING_MODE_FUNC()) \
454 mtx_lock(_m); \
455} while (0)
456
457#define USB_MTX_UNLOCK(_m) do { \
458 if (!USB_IN_POLLING_MODE_FUNC()) \
459 mtx_unlock(_m); \
460} while (0)
461
462#define USB_MTX_LOCK_SPIN(_m) do { \
463 if (!USB_IN_POLLING_MODE_FUNC()) \
464 mtx_lock_spin(_m); \
465} while (0)
466
467#define USB_MTX_UNLOCK_SPIN(_m) do { \
468 if (!USB_IN_POLLING_MODE_FUNC()) \
469 mtx_unlock_spin(_m); \
470} while (0)
471
472/*
473 * The following is a wrapper for the callout structure to ease
474 * porting the code to other platforms.
475 */
476struct usb_callout {
477 struct callout co;
478};
479#define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
480#define usb_callout_reset(c,...) do { \
481 if (!USB_IN_POLLING_MODE_FUNC()) \
482 callout_reset(&(c)->co, __VA_ARGS__); \
483} while (0)
484#define usb_callout_reset_sbt(c,...) do { \
485 if (!USB_IN_POLLING_MODE_FUNC()) \
486 callout_reset_sbt(&(c)->co, __VA_ARGS__); \
487} while (0)
488#define usb_callout_stop(c) do { \
489 if (!USB_IN_POLLING_MODE_FUNC()) { \
490 callout_stop(&(c)->co); \
491 } else { \
492 /* \
493 * Cannot stop callout when \
494 * polling. Set dummy callback \
495 * function instead: \
496 */ \
497 (c)->co.c_func = &usbd_dummy_timeout; \
498 } \
499} while (0)
500#define usb_callout_drain(c) callout_drain(&(c)->co)
501#define usb_callout_pending(c) callout_pending(&(c)->co)
502
503/* USB transfer states */
504
505#define USB_ST_SETUP 0
506#define USB_ST_TRANSFERRED 1
507#define USB_ST_ERROR 2
508
509/* USB handle request states */
510#define USB_HR_NOT_COMPLETE 0
511#define USB_HR_COMPLETE_OK 1
512#define USB_HR_COMPLETE_ERR 2
513
514/*
515 * The following macro will return the current state of an USB
516 * transfer like defined by the "USB_ST_XXX" enums.
517 */
518#define USB_GET_STATE(xfer) (usbd_xfer_state(xfer))
519
520/*
521 * The following structure defines the USB process message header.
522 */
523struct usb_proc_msg {
524 TAILQ_ENTRY(usb_proc_msg) pm_qentry;
525 usb_proc_callback_t *pm_callback;
526 usb_size_t pm_num;
527};
528
529#define USB_PROC_MSG_ENQUEUED(msg) ((msg)->pm_qentry.tqe_prev != NULL)
530
531#define USB_FIFO_TX 0
532#define USB_FIFO_RX 1
533
534/*
535 * Locking note for the following functions. All the
536 * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
537 * locked. The others are called unlocked.
538 */
539struct usb_fifo_methods {
540 usb_fifo_open_t *f_open;
541 usb_fifo_close_t *f_close;
542 usb_fifo_ioctl_t *f_ioctl;
543 /*
544 * NOTE: The post-ioctl callback is called after the USB reference
545 * gets locked in the IOCTL handler:
546 */
547 usb_fifo_ioctl_t *f_ioctl_post;
548 usb_fifo_cmd_t *f_start_read;
549 usb_fifo_cmd_t *f_stop_read;
550 usb_fifo_cmd_t *f_start_write;
551 usb_fifo_cmd_t *f_stop_write;
552 usb_fifo_filter_t *f_filter_read;
553 usb_fifo_filter_t *f_filter_write;
554 const char *basename[4];
555 const char *postfix[4];
556};
557
558struct usb_fifo_sc {
559 struct usb_fifo *fp[2];
560 struct usb_fs_privdata *dev;
561};
562
563const char *usbd_errstr(usb_error_t error);
564void *usbd_find_descriptor(struct usb_device *udev, void *id,
565 uint8_t iface_index, uint8_t type, uint8_t type_mask,
566 uint8_t subtype, uint8_t subtype_mask);
567struct usb_config_descriptor *usbd_get_config_descriptor(
568 struct usb_device *udev);
569struct usb_device_descriptor *usbd_get_device_descriptor(
570 struct usb_device *udev);
571struct usb_interface *usbd_get_iface(struct usb_device *udev,
572 uint8_t iface_index);
573struct usb_interface_descriptor *usbd_get_interface_descriptor(
574 struct usb_interface *iface);
575struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
576 const struct usb_config *setup);
577struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
578usb_error_t usbd_interface_count(struct usb_device *udev, uint8_t *count);
579enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
580enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
581void device_set_usb_desc(device_t dev);
582void usb_pause_mtx(struct mtx *mtx, int _ticks);
583usb_error_t usbd_set_pnpinfo(struct usb_device *udev,
584 uint8_t iface_index, const char *pnpinfo);
585usb_error_t usbd_add_dynamic_quirk(struct usb_device *udev,
586 uint16_t quirk);
587usb_error_t usbd_set_endpoint_mode(struct usb_device *udev,
588 struct usb_endpoint *ep, uint8_t ep_mode);
589uint8_t usbd_get_endpoint_mode(struct usb_device *udev,
590 struct usb_endpoint *ep);
591int usbd_fill_deviceinfo(struct usb_device *udev,
592 struct usb_device_info *di);
593
594const struct usb_device_id *usbd_lookup_id_by_info(
595 const struct usb_device_id *id, usb_size_t sizeof_id,
596 const struct usbd_lookup_info *info);
597int usbd_lookup_id_by_uaa(const struct usb_device_id *id,
598 usb_size_t sizeof_id, struct usb_attach_arg *uaa);
599
600usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
601 struct usb_device_request *req, void *data, uint16_t flags,
602 uint16_t *actlen, usb_timeout_t timeout);
603#define usbd_do_request(u,m,r,d) \
604 usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)
605
606uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1,
607 struct usb_xfer *xfer2);
608uint8_t usbd_get_interface_altindex(struct usb_interface *iface);
609usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
610 uint8_t iface_index, uint8_t alt_index);
611uint32_t usbd_get_isoc_fps(struct usb_device *udev);
612uint32_t usbd_get_max_frame_length(const struct usb_endpoint_descriptor *,
613 const struct usb_endpoint_ss_comp_descriptor *,
614 enum usb_dev_speed);
615usb_error_t usbd_transfer_setup(struct usb_device *udev,
616 const uint8_t *ifaces, struct usb_xfer **pxfer,
617 const struct usb_config *setup_start, uint16_t n_setup,
618 void *priv_sc, struct mtx *priv_mtx);
619void usbd_transfer_submit(struct usb_xfer *xfer);
620void usbd_transfer_clear_stall(struct usb_xfer *xfer);
621void usbd_transfer_drain(struct usb_xfer *xfer);
622uint8_t usbd_transfer_pending(struct usb_xfer *xfer);
623void usbd_transfer_start(struct usb_xfer *xfer);
624void usbd_transfer_stop(struct usb_xfer *xfer);
625void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
626void usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
627void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
628 uint8_t parent_index);
629uint8_t usbd_get_bus_index(struct usb_device *udev);
630uint8_t usbd_get_device_index(struct usb_device *udev);
631void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
632uint8_t usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode);
633uint8_t usbd_device_attached(struct usb_device *udev);
634
635usb_frlength_t
636 usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex);
637void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
638 int *aframes, int *nframes);
639struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t);
640void *usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t);
641void *usbd_xfer_softc(struct usb_xfer *xfer);
642void *usbd_xfer_get_priv(struct usb_xfer *xfer);
643void usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
644void usbd_xfer_set_interval(struct usb_xfer *xfer, int);
645uint8_t usbd_xfer_state(struct usb_xfer *xfer);
646void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
647 void *ptr, usb_frlength_t len);
648void usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
649 void **ptr, int *len);
650void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
651 usb_frcount_t frindex);
652usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
653usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
654usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
655uint8_t usbd_xfer_get_fps_shift(struct usb_xfer *xfer);
656usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
657 usb_frcount_t frindex);
658void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
659 usb_frlength_t len);
660void usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
661void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
662void usbd_xfer_set_zlp(struct usb_xfer *xfer);
663uint8_t usbd_xfer_get_and_clr_zlp(struct usb_xfer *xfer);
664void usbd_xfer_set_stall(struct usb_xfer *xfer);
665int usbd_xfer_is_stalled(struct usb_xfer *xfer);
666void usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
667void usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
668uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer);
669uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer);
670
671void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
672 const void *ptr, usb_frlength_t len);
673int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
674 const void *ptr, usb_frlength_t len);
675void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
676 void *ptr, usb_frlength_t len);
677int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
678 void *ptr, usb_frlength_t len);
679void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
680 struct usb_page_search *res);
681void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
682 struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
683void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
684 usb_frlength_t len);
685void usbd_start_re_enumerate(struct usb_device *udev);
686usb_error_t
687 usbd_start_set_config(struct usb_device *, uint8_t);
688int usbd_in_polling_mode(void);
689void usbd_dummy_timeout(void *);
690
691int usb_fifo_attach(struct usb_device *udev, void *priv_sc,
692 struct mtx *priv_mtx, struct usb_fifo_methods *pm,
693 struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit,
694 uint8_t iface_index, uid_t uid, gid_t gid, int mode);
695void usb_fifo_detach(struct usb_fifo_sc *f_sc);
696int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
697 uint16_t nbuf);
698void usb_fifo_free_buffer(struct usb_fifo *f);
699uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
700void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
701 usb_frlength_t offset, usb_frlength_t len, uint8_t what);
702void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
703 usb_size_t len, uint8_t what);
704uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
705void usb_fifo_put_data_error(struct usb_fifo *fifo);
706uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
707 usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
708 uint8_t what);
709uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
710 usb_size_t len, usb_size_t *actlen, uint8_t what);
711uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
712 usb_size_t *plen);
713void usb_fifo_reset(struct usb_fifo *f);
714void usb_fifo_wakeup(struct usb_fifo *f);
715void usb_fifo_get_data_error(struct usb_fifo *fifo);
716void *usb_fifo_softc(struct usb_fifo *fifo);
717void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
718void usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
719void usb_fifo_free(struct usb_fifo *f);
720#endif /* _KERNEL || _STANDALONE */
721#endif /* _USB_USBDI_H_ */