1ed6d949aSAndrew Thompson /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4ed6d949aSAndrew Thompson * Copyright (c) 2009 Andrew Thompson 5ed6d949aSAndrew Thompson * 6ed6d949aSAndrew Thompson * Redistribution and use in source and binary forms, with or without 7ed6d949aSAndrew Thompson * modification, are permitted provided that the following conditions 8ed6d949aSAndrew Thompson * are met: 9ed6d949aSAndrew Thompson * 1. Redistributions of source code must retain the above copyright 10ed6d949aSAndrew Thompson * notice, this list of conditions and the following disclaimer. 11ed6d949aSAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 12ed6d949aSAndrew Thompson * notice, this list of conditions and the following disclaimer in the 13ed6d949aSAndrew Thompson * documentation and/or other materials provided with the distribution. 14ed6d949aSAndrew Thompson * 15ed6d949aSAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16ed6d949aSAndrew Thompson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17ed6d949aSAndrew Thompson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18ed6d949aSAndrew Thompson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19ed6d949aSAndrew Thompson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20ed6d949aSAndrew Thompson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21ed6d949aSAndrew Thompson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22ed6d949aSAndrew Thompson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23ed6d949aSAndrew Thompson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24ed6d949aSAndrew Thompson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25ed6d949aSAndrew Thompson */ 26ed6d949aSAndrew Thompson #ifndef _USB_USBDI_H_ 27ed6d949aSAndrew Thompson #define _USB_USBDI_H_ 28ed6d949aSAndrew Thompson 29ed6d949aSAndrew Thompson struct usb_fifo; 30ed6d949aSAndrew Thompson struct usb_xfer; 31ed6d949aSAndrew Thompson struct usb_device; 322a4c6157SAndrew Thompson struct usb_attach_arg; 33ed6d949aSAndrew Thompson struct usb_interface; 34ed6d949aSAndrew Thompson struct usb_endpoint; 35ed6d949aSAndrew Thompson struct usb_page_cache; 36ed6d949aSAndrew Thompson struct usb_page_search; 37ed6d949aSAndrew Thompson struct usb_process; 38ed6d949aSAndrew Thompson struct usb_proc_msg; 39ed6d949aSAndrew Thompson struct usb_mbuf; 402ffd5fdcSHans Petter Selasky struct usb_fs_privdata; 41ed6d949aSAndrew Thompson struct mbuf; 42ed6d949aSAndrew Thompson 43ed6d949aSAndrew Thompson typedef enum { /* keep in sync with usb_errstr_table */ 44ed6d949aSAndrew Thompson USB_ERR_NORMAL_COMPLETION = 0, 45ed6d949aSAndrew Thompson USB_ERR_PENDING_REQUESTS, /* 1 */ 46ed6d949aSAndrew Thompson USB_ERR_NOT_STARTED, /* 2 */ 47ed6d949aSAndrew Thompson USB_ERR_INVAL, /* 3 */ 48ed6d949aSAndrew Thompson USB_ERR_NOMEM, /* 4 */ 49ed6d949aSAndrew Thompson USB_ERR_CANCELLED, /* 5 */ 50ed6d949aSAndrew Thompson USB_ERR_BAD_ADDRESS, /* 6 */ 51ed6d949aSAndrew Thompson USB_ERR_BAD_BUFSIZE, /* 7 */ 52ed6d949aSAndrew Thompson USB_ERR_BAD_FLAG, /* 8 */ 53ed6d949aSAndrew Thompson USB_ERR_NO_CALLBACK, /* 9 */ 54ed6d949aSAndrew Thompson USB_ERR_IN_USE, /* 10 */ 55ed6d949aSAndrew Thompson USB_ERR_NO_ADDR, /* 11 */ 56ed6d949aSAndrew Thompson USB_ERR_NO_PIPE, /* 12 */ 57ed6d949aSAndrew Thompson USB_ERR_ZERO_NFRAMES, /* 13 */ 58ed6d949aSAndrew Thompson USB_ERR_ZERO_MAXP, /* 14 */ 59ed6d949aSAndrew Thompson USB_ERR_SET_ADDR_FAILED, /* 15 */ 60ed6d949aSAndrew Thompson USB_ERR_NO_POWER, /* 16 */ 61ed6d949aSAndrew Thompson USB_ERR_TOO_DEEP, /* 17 */ 62ed6d949aSAndrew Thompson USB_ERR_IOERROR, /* 18 */ 63ed6d949aSAndrew Thompson USB_ERR_NOT_CONFIGURED, /* 19 */ 64ed6d949aSAndrew Thompson USB_ERR_TIMEOUT, /* 20 */ 65ed6d949aSAndrew Thompson USB_ERR_SHORT_XFER, /* 21 */ 66ed6d949aSAndrew Thompson USB_ERR_STALLED, /* 22 */ 67ed6d949aSAndrew Thompson USB_ERR_INTERRUPTED, /* 23 */ 68ed6d949aSAndrew Thompson USB_ERR_DMA_LOAD_FAILED, /* 24 */ 69ed6d949aSAndrew Thompson USB_ERR_BAD_CONTEXT, /* 25 */ 70ed6d949aSAndrew Thompson USB_ERR_NO_ROOT_HUB, /* 26 */ 71ed6d949aSAndrew Thompson USB_ERR_NO_INTR_THREAD, /* 27 */ 72ed6d949aSAndrew Thompson USB_ERR_NOT_LOCKED, /* 28 */ 73ed6d949aSAndrew Thompson USB_ERR_MAX 74ed6d949aSAndrew Thompson } usb_error_t; 75ed6d949aSAndrew Thompson 76ed6d949aSAndrew Thompson /* 77ed6d949aSAndrew Thompson * Flags for transfers 78ed6d949aSAndrew Thompson */ 79ed6d949aSAndrew Thompson #define USB_FORCE_SHORT_XFER 0x0001 /* force a short transmit last */ 80ed6d949aSAndrew Thompson #define USB_SHORT_XFER_OK 0x0004 /* allow short reads */ 81ed6d949aSAndrew Thompson #define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */ 82ed6d949aSAndrew Thompson #define USB_USER_DATA_PTR 0x0020 /* internal flag */ 8329bd7d7eSAndrew Thompson #define USB_MULTI_SHORT_OK 0x0040 /* allow multiple short frames */ 8429bd7d7eSAndrew Thompson #define USB_MANUAL_STATUS 0x0080 /* manual ctrl status */ 85ed6d949aSAndrew Thompson 86ed6d949aSAndrew Thompson #define USB_NO_TIMEOUT 0 87ed6d949aSAndrew Thompson #define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */ 88ed6d949aSAndrew Thompson 89a2dd1caaSHans Petter Selasky #if defined(_KERNEL) || defined(_STANDALONE) 90ed6d949aSAndrew Thompson /* typedefs */ 91ed6d949aSAndrew Thompson 92ed6d949aSAndrew Thompson typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t); 93ed6d949aSAndrew Thompson typedef void (usb_proc_callback_t)(struct usb_proc_msg *); 94ed6d949aSAndrew Thompson typedef usb_error_t (usb_handle_req_t)(struct usb_device *, 95ed6d949aSAndrew Thompson struct usb_device_request *, const void **, uint16_t *); 96ed6d949aSAndrew Thompson 97ed6d949aSAndrew Thompson typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags); 98ed6d949aSAndrew Thompson typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags); 99ed6d949aSAndrew Thompson typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags); 100ed6d949aSAndrew Thompson typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo); 101ed6d949aSAndrew Thompson typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m); 102ed6d949aSAndrew Thompson 1032a4c6157SAndrew Thompson /* USB events */ 104d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE 105e2e050c8SConrad Meyer #include <sys/_eventhandler.h> 106d2b99310SHans Petter Selasky #endif 1072a4c6157SAndrew Thompson typedef void (*usb_dev_configured_t)(void *, struct usb_device *, 1082a4c6157SAndrew Thompson struct usb_attach_arg *); 1092a4c6157SAndrew Thompson EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t); 1102a4c6157SAndrew Thompson 111ed6d949aSAndrew Thompson /* 112ed6d949aSAndrew Thompson * The following macros are used used to convert milliseconds into 113ed6d949aSAndrew Thompson * HZ. We use 1024 instead of 1000 milliseconds per second to save a 114ed6d949aSAndrew Thompson * full division. 115ed6d949aSAndrew Thompson */ 116ed6d949aSAndrew Thompson #define USB_MS_HZ 1024 117ed6d949aSAndrew Thompson 118ed6d949aSAndrew Thompson #define USB_MS_TO_TICKS(ms) \ 119ed6d949aSAndrew Thompson (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ) 120ed6d949aSAndrew Thompson 121ed6d949aSAndrew Thompson /* 122ed6d949aSAndrew Thompson * Common queue structure for USB transfers. 123ed6d949aSAndrew Thompson */ 124ed6d949aSAndrew Thompson struct usb_xfer_queue { 125ed6d949aSAndrew Thompson TAILQ_HEAD(, usb_xfer) head; 126ed6d949aSAndrew Thompson struct usb_xfer *curr; /* current USB transfer processed */ 127ed6d949aSAndrew Thompson void (*command) (struct usb_xfer_queue *pq); 128ed6d949aSAndrew Thompson uint8_t recurse_1:1; 129ed6d949aSAndrew Thompson uint8_t recurse_2:1; 13043ea03d7SHans Petter Selasky uint8_t recurse_3:1; 13143ea03d7SHans Petter Selasky uint8_t reserved:5; 132ed6d949aSAndrew Thompson }; 133ed6d949aSAndrew Thompson 134ed6d949aSAndrew Thompson /* 135ed6d949aSAndrew Thompson * The following structure defines an USB endpoint 136ed6d949aSAndrew Thompson * USB endpoint. 137ed6d949aSAndrew Thompson */ 138ed6d949aSAndrew Thompson struct usb_endpoint { 139a5cf1aaaSHans Petter Selasky /* queue of USB transfers */ 140a5cf1aaaSHans Petter Selasky struct usb_xfer_queue endpoint_q[USB_MAX_EP_STREAMS]; 141ed6d949aSAndrew Thompson 142ed6d949aSAndrew Thompson struct usb_endpoint_descriptor *edesc; 143963169b4SHans Petter Selasky struct usb_endpoint_ss_comp_descriptor *ecomp; 144e892b3feSHans Petter Selasky const struct usb_pipe_methods *methods; /* set by HC driver */ 145ed6d949aSAndrew Thompson 146ed6d949aSAndrew Thompson uint16_t isoc_next; 147ed6d949aSAndrew Thompson 148ed6d949aSAndrew Thompson uint8_t toggle_next:1; /* next data toggle value */ 149ed6d949aSAndrew Thompson uint8_t is_stalled:1; /* set if endpoint is stalled */ 150ed6d949aSAndrew Thompson uint8_t is_synced:1; /* set if we a synchronised */ 151ed6d949aSAndrew Thompson uint8_t unused:5; 152ed6d949aSAndrew Thompson uint8_t iface_index; /* not used by "default endpoint" */ 153f12c6c29SAndrew Thompson 154f12c6c29SAndrew Thompson uint8_t refcount_alloc; /* allocation refcount */ 155f12c6c29SAndrew Thompson uint8_t refcount_bw; /* bandwidth refcount */ 156f12c6c29SAndrew Thompson #define USB_EP_REF_MAX 0x3f 157f12c6c29SAndrew Thompson 158f12c6c29SAndrew Thompson /* High-Speed resource allocation (valid if "refcount_bw" > 0) */ 159f12c6c29SAndrew Thompson 160f12c6c29SAndrew Thompson uint8_t usb_smask; /* USB start mask */ 161f12c6c29SAndrew Thompson uint8_t usb_cmask; /* USB complete mask */ 162f12c6c29SAndrew Thompson uint8_t usb_uframe; /* USB microframe */ 163a5cf1aaaSHans Petter Selasky 164a5cf1aaaSHans Petter Selasky /* USB endpoint mode, see USB_EP_MODE_XXX */ 165a5cf1aaaSHans Petter Selasky 166a5cf1aaaSHans Petter Selasky uint8_t ep_mode; 167ed6d949aSAndrew Thompson }; 168ed6d949aSAndrew Thompson 169ed6d949aSAndrew Thompson /* 170ed6d949aSAndrew Thompson * The following structure defines an USB interface. 171ed6d949aSAndrew Thompson */ 172ed6d949aSAndrew Thompson struct usb_interface { 173ed6d949aSAndrew Thompson struct usb_interface_descriptor *idesc; 174ed6d949aSAndrew Thompson device_t subdev; 175b8b3f4fdSHans Petter Selasky /* Total number of alternate settings, from 1 to 256 */ 176b8b3f4fdSHans Petter Selasky uint16_t num_altsetting; 177b8b3f4fdSHans Petter Selasky /* Current alternate interface index, from 0 to 255 */ 178ed6d949aSAndrew Thompson uint8_t alt_index; 179ed6d949aSAndrew Thompson uint8_t parent_iface_index; 180ed6d949aSAndrew Thompson 181ed6d949aSAndrew Thompson /* Linux compat */ 182ed6d949aSAndrew Thompson struct usb_host_interface *altsetting; 183ed6d949aSAndrew Thompson struct usb_host_interface *cur_altsetting; 184ed6d949aSAndrew Thompson struct usb_device *linux_udev; 185ed6d949aSAndrew Thompson void *bsd_priv_sc; /* device specific information */ 1868427ed84SHans Petter Selasky char *pnpinfo; /* additional PnP-info for this interface */ 187ed6d949aSAndrew Thompson uint8_t bsd_iface_index; 188ed6d949aSAndrew Thompson }; 189ed6d949aSAndrew Thompson 190ed6d949aSAndrew Thompson /* 191ed6d949aSAndrew Thompson * The following structure defines a set of USB transfer flags. 192ed6d949aSAndrew Thompson */ 193ed6d949aSAndrew Thompson struct usb_xfer_flags { 194ed6d949aSAndrew Thompson uint8_t force_short_xfer:1; /* force a short transmit transfer 195ed6d949aSAndrew Thompson * last */ 196ed6d949aSAndrew Thompson uint8_t short_xfer_ok:1; /* allow short receive transfers */ 197ed6d949aSAndrew Thompson uint8_t short_frames_ok:1; /* allow short frames */ 198ed6d949aSAndrew Thompson uint8_t pipe_bof:1; /* block pipe on failure */ 199ed6d949aSAndrew Thompson uint8_t proxy_buffer:1; /* makes buffer size a factor of 200ed6d949aSAndrew Thompson * "max_frame_size" */ 201ed6d949aSAndrew Thompson uint8_t ext_buffer:1; /* uses external DMA buffer */ 202ed6d949aSAndrew Thompson uint8_t manual_status:1; /* non automatic status stage on 203ed6d949aSAndrew Thompson * control transfers */ 204ed6d949aSAndrew Thompson uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can 205ed6d949aSAndrew Thompson * be ignored */ 206ed6d949aSAndrew Thompson uint8_t stall_pipe:1; /* set if the endpoint belonging to 207ed6d949aSAndrew Thompson * this USB transfer should be stalled 208ed6d949aSAndrew Thompson * before starting this transfer! */ 2091c497368SHans Petter Selasky uint8_t pre_scale_frames:1; /* "usb_config->frames" is 2101c497368SHans Petter Selasky * assumed to give the 2111c497368SHans Petter Selasky * buffering time in 2121c497368SHans Petter Selasky * milliseconds and is 2131c497368SHans Petter Selasky * converted into the nearest 2141c497368SHans Petter Selasky * number of frames when the 2151c497368SHans Petter Selasky * USB transfer is setup. This 2161c497368SHans Petter Selasky * option only has effect for 2171c497368SHans Petter Selasky * ISOCHRONOUS transfers. 2181c497368SHans Petter Selasky */ 219f83f5d58SHans Petter Selasky uint8_t send_zlp:1; /* send a zero length packet first */ 220ed6d949aSAndrew Thompson }; 221ed6d949aSAndrew Thompson 222ed6d949aSAndrew Thompson /* 223ed6d949aSAndrew Thompson * The following structure define an USB configuration, that basically 224ed6d949aSAndrew Thompson * is used when setting up an USB transfer. 225ed6d949aSAndrew Thompson */ 226ed6d949aSAndrew Thompson struct usb_config { 227ed6d949aSAndrew Thompson usb_callback_t *callback; /* USB transfer callback */ 228ed6d949aSAndrew Thompson usb_frlength_t bufsize; /* total pipe buffer size in bytes */ 229ed6d949aSAndrew Thompson usb_frcount_t frames; /* maximum number of USB frames */ 230ed6d949aSAndrew Thompson usb_timeout_t interval; /* interval in milliseconds */ 231ed6d949aSAndrew Thompson #define USB_DEFAULT_INTERVAL 0 232ed6d949aSAndrew Thompson usb_timeout_t timeout; /* transfer timeout in milliseconds */ 233ed6d949aSAndrew Thompson struct usb_xfer_flags flags; /* transfer flags */ 234a5cf1aaaSHans Petter Selasky usb_stream_t stream_id; /* USB3.0 specific */ 235ed6d949aSAndrew Thompson enum usb_hc_mode usb_mode; /* host or device mode */ 236ed6d949aSAndrew Thompson uint8_t type; /* pipe type */ 237ed6d949aSAndrew Thompson uint8_t endpoint; /* pipe number */ 238ed6d949aSAndrew Thompson uint8_t direction; /* pipe direction */ 239ed6d949aSAndrew Thompson uint8_t ep_index; /* pipe index match to use */ 240ed6d949aSAndrew Thompson uint8_t if_index; /* "ifaces" index to use */ 241ed6d949aSAndrew Thompson }; 242ed6d949aSAndrew Thompson 243ed6d949aSAndrew Thompson /* 244f1a16106SHans Petter Selasky * Use these macro when defining USB device ID arrays if you want to 245f1a16106SHans Petter Selasky * have your driver module automatically loaded in host, device or 24620733245SPedro F. Giffuni * both modes respectively: 247f1a16106SHans Petter Selasky */ 2487b0866b0SHans Petter Selasky #if USB_HAVE_ID_SECTION 249f1a16106SHans Petter Selasky #define STRUCT_USB_HOST_ID \ 250f1a16106SHans Petter Selasky struct usb_device_id __section("usb_host_id") 251f1a16106SHans Petter Selasky #define STRUCT_USB_DEVICE_ID \ 252f1a16106SHans Petter Selasky struct usb_device_id __section("usb_device_id") 253f1a16106SHans Petter Selasky #define STRUCT_USB_DUAL_ID \ 254f1a16106SHans Petter Selasky struct usb_device_id __section("usb_dual_id") 2557b0866b0SHans Petter Selasky #else 2567b0866b0SHans Petter Selasky #define STRUCT_USB_HOST_ID \ 2577b0866b0SHans Petter Selasky struct usb_device_id 2587b0866b0SHans Petter Selasky #define STRUCT_USB_DEVICE_ID \ 2597b0866b0SHans Petter Selasky struct usb_device_id 2607b0866b0SHans Petter Selasky #define STRUCT_USB_DUAL_ID \ 2617b0866b0SHans Petter Selasky struct usb_device_id 2627b0866b0SHans Petter Selasky #endif /* USB_HAVE_ID_SECTION */ 263f1a16106SHans Petter Selasky 264f1a16106SHans Petter Selasky /* 265ed6d949aSAndrew Thompson * The following structure is used when looking up an USB driver for 266ed6d949aSAndrew Thompson * an USB device. It is inspired by the Linux structure called 267ed6d949aSAndrew Thompson * "usb_device_id". 268ed6d949aSAndrew Thompson */ 269ed6d949aSAndrew Thompson struct usb_device_id { 270f809f280SWarner Losh /* Select which fields to match against */ 271f9e8f40dSHans Petter Selasky #if BYTE_ORDER == LITTLE_ENDIAN 272f809f280SWarner Losh uint16_t 273f809f280SWarner Losh match_flag_vendor:1, 274f809f280SWarner Losh match_flag_product:1, 275f809f280SWarner Losh match_flag_dev_lo:1, 276f809f280SWarner Losh match_flag_dev_hi:1, 277f809f280SWarner Losh 278f809f280SWarner Losh match_flag_dev_class:1, 279f809f280SWarner Losh match_flag_dev_subclass:1, 280f809f280SWarner Losh match_flag_dev_protocol:1, 281f809f280SWarner Losh match_flag_int_class:1, 282f809f280SWarner Losh 283f809f280SWarner Losh match_flag_int_subclass:1, 284f809f280SWarner Losh match_flag_int_protocol:1, 285f809f280SWarner Losh match_flag_unused:6; 286f809f280SWarner Losh #else 287f809f280SWarner Losh uint16_t 288f809f280SWarner Losh match_flag_unused:6, 289f809f280SWarner Losh match_flag_int_protocol:1, 290f809f280SWarner Losh match_flag_int_subclass:1, 291f809f280SWarner Losh 292f809f280SWarner Losh match_flag_int_class:1, 293f809f280SWarner Losh match_flag_dev_protocol:1, 294f809f280SWarner Losh match_flag_dev_subclass:1, 295f809f280SWarner Losh match_flag_dev_class:1, 296f809f280SWarner Losh 297f809f280SWarner Losh match_flag_dev_hi:1, 298f809f280SWarner Losh match_flag_dev_lo:1, 299f809f280SWarner Losh match_flag_product:1, 300f809f280SWarner Losh match_flag_vendor:1; 301f809f280SWarner Losh #endif 302ed6d949aSAndrew Thompson 303ed6d949aSAndrew Thompson /* Used for product specific matches; the BCD range is inclusive */ 304ed6d949aSAndrew Thompson uint16_t idVendor; 305ed6d949aSAndrew Thompson uint16_t idProduct; 306ed6d949aSAndrew Thompson uint16_t bcdDevice_lo; 307ed6d949aSAndrew Thompson uint16_t bcdDevice_hi; 308ed6d949aSAndrew Thompson 309ed6d949aSAndrew Thompson /* Used for device class matches */ 310ed6d949aSAndrew Thompson uint8_t bDeviceClass; 311ed6d949aSAndrew Thompson uint8_t bDeviceSubClass; 312ed6d949aSAndrew Thompson uint8_t bDeviceProtocol; 313ed6d949aSAndrew Thompson 314ed6d949aSAndrew Thompson /* Used for interface class matches */ 315ed6d949aSAndrew Thompson uint8_t bInterfaceClass; 316ed6d949aSAndrew Thompson uint8_t bInterfaceSubClass; 317ed6d949aSAndrew Thompson uint8_t bInterfaceProtocol; 318ed6d949aSAndrew Thompson 319ed6d949aSAndrew Thompson #if USB_HAVE_COMPAT_LINUX 320ed6d949aSAndrew Thompson /* which fields to match against */ 321ed6d949aSAndrew Thompson uint16_t match_flags; 322ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_VENDOR 0x0001 323ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002 324ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004 325ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008 326ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010 327ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020 328ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040 329ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080 330ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 331ed6d949aSAndrew Thompson #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 332ed6d949aSAndrew Thompson #endif 333f9e8f40dSHans Petter Selasky 334f9e8f40dSHans Petter Selasky /* Hook for driver specific information */ 335f9e8f40dSHans Petter Selasky unsigned long driver_info; 3361d63770bSHans Petter Selasky } __aligned(32); 3371d63770bSHans Petter Selasky 3389ce3abcfSHans Petter Selasky #define USB_STD_PNP_INFO "M16:mask;U16:vendor;U16:product;L16:release;G16:release;" \ 3391e7e4fd2SWarner Losh "U8:devclass;U8:devsubclass;U8:devproto;" \ 340f809f280SWarner Losh "U8:intclass;U8:intsubclass;U8:intprotocol;" 341f809f280SWarner Losh #define USB_STD_PNP_HOST_INFO USB_STD_PNP_INFO "T:mode=host;" 342f809f280SWarner Losh #define USB_STD_PNP_DEVICE_INFO USB_STD_PNP_INFO "T:mode=device;" 343f809f280SWarner Losh #define USB_PNP_HOST_INFO(table) \ 344329e817fSWarner Losh MODULE_PNP_INFO(USB_STD_PNP_HOST_INFO, uhub, table, table, \ 345f809f280SWarner Losh sizeof(table) / sizeof(table[0])) 346f809f280SWarner Losh #define USB_PNP_DEVICE_INFO(table) \ 347329e817fSWarner Losh MODULE_PNP_INFO(USB_STD_PNP_DEVICE_INFO, uhub, table, table, \ 348f809f280SWarner Losh sizeof(table) / sizeof(table[0])) 349f809f280SWarner Losh #define USB_PNP_DUAL_INFO(table) \ 350329e817fSWarner Losh MODULE_PNP_INFO(USB_STD_PNP_INFO, uhub, table, table, \ 351f809f280SWarner Losh sizeof(table) / sizeof(table[0])) 352f809f280SWarner Losh 3531d63770bSHans Petter Selasky /* check that the size of the structure above is correct */ 3541d63770bSHans Petter Selasky extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1]; 355ed6d949aSAndrew Thompson 356ed6d949aSAndrew Thompson #define USB_VENDOR(vend) \ 357ed6d949aSAndrew Thompson .match_flag_vendor = 1, .idVendor = (vend) 358ed6d949aSAndrew Thompson 359ed6d949aSAndrew Thompson #define USB_PRODUCT(prod) \ 360ed6d949aSAndrew Thompson .match_flag_product = 1, .idProduct = (prod) 361ed6d949aSAndrew Thompson 362ed6d949aSAndrew Thompson #define USB_VP(vend,prod) \ 363ed6d949aSAndrew Thompson USB_VENDOR(vend), USB_PRODUCT(prod) 364ed6d949aSAndrew Thompson 365ed6d949aSAndrew Thompson #define USB_VPI(vend,prod,info) \ 366ed6d949aSAndrew Thompson USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info) 367ed6d949aSAndrew Thompson 368ed6d949aSAndrew Thompson #define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \ 369ed6d949aSAndrew Thompson .match_flag_dev_lo = 1, .bcdDevice_lo = (lo) 370ed6d949aSAndrew Thompson 371ed6d949aSAndrew Thompson #define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \ 372ed6d949aSAndrew Thompson .match_flag_dev_hi = 1, .bcdDevice_hi = (hi) 373ed6d949aSAndrew Thompson 374ed6d949aSAndrew Thompson #define USB_DEV_CLASS(dc) \ 375ed6d949aSAndrew Thompson .match_flag_dev_class = 1, .bDeviceClass = (dc) 376ed6d949aSAndrew Thompson 377ed6d949aSAndrew Thompson #define USB_DEV_SUBCLASS(dsc) \ 378ed6d949aSAndrew Thompson .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc) 379ed6d949aSAndrew Thompson 380ed6d949aSAndrew Thompson #define USB_DEV_PROTOCOL(dp) \ 381ed6d949aSAndrew Thompson .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp) 382ed6d949aSAndrew Thompson 383ed6d949aSAndrew Thompson #define USB_IFACE_CLASS(ic) \ 384ed6d949aSAndrew Thompson .match_flag_int_class = 1, .bInterfaceClass = (ic) 385ed6d949aSAndrew Thompson 386ed6d949aSAndrew Thompson #define USB_IFACE_SUBCLASS(isc) \ 387ed6d949aSAndrew Thompson .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc) 388ed6d949aSAndrew Thompson 389ed6d949aSAndrew Thompson #define USB_IFACE_PROTOCOL(ip) \ 390ed6d949aSAndrew Thompson .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip) 391ed6d949aSAndrew Thompson 392ed6d949aSAndrew Thompson #define USB_IF_CSI(class,subclass,info) \ 393ed6d949aSAndrew Thompson USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info) 394ed6d949aSAndrew Thompson 395ed6d949aSAndrew Thompson #define USB_DRIVER_INFO(n) \ 396ed6d949aSAndrew Thompson .driver_info = (n) 397ed6d949aSAndrew Thompson 398ed6d949aSAndrew Thompson #define USB_GET_DRIVER_INFO(did) \ 399ed6d949aSAndrew Thompson (did)->driver_info 400ed6d949aSAndrew Thompson 401ed6d949aSAndrew Thompson /* 402ed6d949aSAndrew Thompson * The following structure keeps information that is used to match 403ed6d949aSAndrew Thompson * against an array of "usb_device_id" elements. 404ed6d949aSAndrew Thompson */ 405ed6d949aSAndrew Thompson struct usbd_lookup_info { 406ed6d949aSAndrew Thompson uint16_t idVendor; 407ed6d949aSAndrew Thompson uint16_t idProduct; 408ed6d949aSAndrew Thompson uint16_t bcdDevice; 409ed6d949aSAndrew Thompson uint8_t bDeviceClass; 410ed6d949aSAndrew Thompson uint8_t bDeviceSubClass; 411ed6d949aSAndrew Thompson uint8_t bDeviceProtocol; 412ed6d949aSAndrew Thompson uint8_t bInterfaceClass; 413ed6d949aSAndrew Thompson uint8_t bInterfaceSubClass; 414ed6d949aSAndrew Thompson uint8_t bInterfaceProtocol; 415ed6d949aSAndrew Thompson uint8_t bIfaceIndex; 416ed6d949aSAndrew Thompson uint8_t bIfaceNum; 417ed6d949aSAndrew Thompson uint8_t bConfigIndex; 418ed6d949aSAndrew Thompson uint8_t bConfigNum; 419ed6d949aSAndrew Thompson }; 420ed6d949aSAndrew Thompson 421ed6d949aSAndrew Thompson /* Structure used by probe and attach */ 422ed6d949aSAndrew Thompson 423ed6d949aSAndrew Thompson struct usb_attach_arg { 424ed6d949aSAndrew Thompson struct usbd_lookup_info info; 425ed6d949aSAndrew Thompson device_t temp_dev; /* for internal use */ 426ed6d949aSAndrew Thompson unsigned long driver_info; /* for internal use */ 427ed6d949aSAndrew Thompson void *driver_ivar; 428ed6d949aSAndrew Thompson struct usb_device *device; /* current device */ 429ed6d949aSAndrew Thompson struct usb_interface *iface; /* current interface */ 430ed6d949aSAndrew Thompson enum usb_hc_mode usb_mode; /* host or device mode */ 431ed6d949aSAndrew Thompson uint8_t port; 4322a4c6157SAndrew Thompson uint8_t dev_state; 4332a4c6157SAndrew Thompson #define UAA_DEV_READY 0 4342a4c6157SAndrew Thompson #define UAA_DEV_DISABLED 1 4352a4c6157SAndrew Thompson #define UAA_DEV_EJECTING 2 436ed6d949aSAndrew Thompson }; 437ed6d949aSAndrew Thompson 438ed6d949aSAndrew Thompson /* 4390eb8d462SHans Petter Selasky * General purpose locking wrappers to ease supporting 4400eb8d462SHans Petter Selasky * USB polled mode: 4410eb8d462SHans Petter Selasky */ 4420eb8d462SHans Petter Selasky #ifdef INVARIANTS 4430eb8d462SHans Petter Selasky #define USB_MTX_ASSERT(_m, _t) do { \ 4440eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4450eb8d462SHans Petter Selasky mtx_assert(_m, _t); \ 4460eb8d462SHans Petter Selasky } while (0) 4470eb8d462SHans Petter Selasky #else 4480eb8d462SHans Petter Selasky #define USB_MTX_ASSERT(_m, _t) do { } while (0) 4490eb8d462SHans Petter Selasky #endif 4500eb8d462SHans Petter Selasky 4510eb8d462SHans Petter Selasky #define USB_MTX_LOCK(_m) do { \ 4520eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4530eb8d462SHans Petter Selasky mtx_lock(_m); \ 4540eb8d462SHans Petter Selasky } while (0) 4550eb8d462SHans Petter Selasky 4560eb8d462SHans Petter Selasky #define USB_MTX_UNLOCK(_m) do { \ 4570eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4580eb8d462SHans Petter Selasky mtx_unlock(_m); \ 4590eb8d462SHans Petter Selasky } while (0) 4600eb8d462SHans Petter Selasky 4610eb8d462SHans Petter Selasky #define USB_MTX_LOCK_SPIN(_m) do { \ 4620eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4630eb8d462SHans Petter Selasky mtx_lock_spin(_m); \ 4640eb8d462SHans Petter Selasky } while (0) 4650eb8d462SHans Petter Selasky 4660eb8d462SHans Petter Selasky #define USB_MTX_UNLOCK_SPIN(_m) do { \ 4670eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4680eb8d462SHans Petter Selasky mtx_unlock_spin(_m); \ 4690eb8d462SHans Petter Selasky } while (0) 4700eb8d462SHans Petter Selasky 4710eb8d462SHans Petter Selasky /* 472ed6d949aSAndrew Thompson * The following is a wrapper for the callout structure to ease 473ed6d949aSAndrew Thompson * porting the code to other platforms. 474ed6d949aSAndrew Thompson */ 475ed6d949aSAndrew Thompson struct usb_callout { 476ed6d949aSAndrew Thompson struct callout co; 477ed6d949aSAndrew Thompson }; 478ed6d949aSAndrew Thompson #define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f) 4790eb8d462SHans Petter Selasky #define usb_callout_reset(c,...) do { \ 4800eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4810eb8d462SHans Petter Selasky callout_reset(&(c)->co, __VA_ARGS__); \ 4820eb8d462SHans Petter Selasky } while (0) 4830eb8d462SHans Petter Selasky #define usb_callout_reset_sbt(c,...) do { \ 4840eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) \ 4850eb8d462SHans Petter Selasky callout_reset_sbt(&(c)->co, __VA_ARGS__); \ 4860eb8d462SHans Petter Selasky } while (0) 4870eb8d462SHans Petter Selasky #define usb_callout_stop(c) do { \ 4880eb8d462SHans Petter Selasky if (!USB_IN_POLLING_MODE_FUNC()) { \ 4890eb8d462SHans Petter Selasky callout_stop(&(c)->co); \ 4900eb8d462SHans Petter Selasky } else { \ 4910eb8d462SHans Petter Selasky /* \ 4920eb8d462SHans Petter Selasky * Cannot stop callout when \ 4930eb8d462SHans Petter Selasky * polling. Set dummy callback \ 4940eb8d462SHans Petter Selasky * function instead: \ 4950eb8d462SHans Petter Selasky */ \ 4960eb8d462SHans Petter Selasky (c)->co.c_func = &usbd_dummy_timeout; \ 4970eb8d462SHans Petter Selasky } \ 4980eb8d462SHans Petter Selasky } while (0) 499ed6d949aSAndrew Thompson #define usb_callout_drain(c) callout_drain(&(c)->co) 500ed6d949aSAndrew Thompson #define usb_callout_pending(c) callout_pending(&(c)->co) 501ed6d949aSAndrew Thompson 502ed6d949aSAndrew Thompson /* USB transfer states */ 503ed6d949aSAndrew Thompson 504ed6d949aSAndrew Thompson #define USB_ST_SETUP 0 505ed6d949aSAndrew Thompson #define USB_ST_TRANSFERRED 1 506ed6d949aSAndrew Thompson #define USB_ST_ERROR 2 507ed6d949aSAndrew Thompson 508ed6d949aSAndrew Thompson /* USB handle request states */ 509ed6d949aSAndrew Thompson #define USB_HR_NOT_COMPLETE 0 510ed6d949aSAndrew Thompson #define USB_HR_COMPLETE_OK 1 511ed6d949aSAndrew Thompson #define USB_HR_COMPLETE_ERR 2 512ed6d949aSAndrew Thompson 513ed6d949aSAndrew Thompson /* 514ed6d949aSAndrew Thompson * The following macro will return the current state of an USB 515ed6d949aSAndrew Thompson * transfer like defined by the "USB_ST_XXX" enums. 516ed6d949aSAndrew Thompson */ 517ed6d949aSAndrew Thompson #define USB_GET_STATE(xfer) (usbd_xfer_state(xfer)) 518ed6d949aSAndrew Thompson 519ed6d949aSAndrew Thompson /* 520ed6d949aSAndrew Thompson * The following structure defines the USB process message header. 521ed6d949aSAndrew Thompson */ 522ed6d949aSAndrew Thompson struct usb_proc_msg { 523ed6d949aSAndrew Thompson TAILQ_ENTRY(usb_proc_msg) pm_qentry; 524ed6d949aSAndrew Thompson usb_proc_callback_t *pm_callback; 525ed6d949aSAndrew Thompson usb_size_t pm_num; 526ed6d949aSAndrew Thompson }; 527ed6d949aSAndrew Thompson 528*729eb176SKyle Evans #define USB_PROC_MSG_ENQUEUED(msg) ((msg)->pm_qentry.tqe_prev != NULL) 529*729eb176SKyle Evans 530ed6d949aSAndrew Thompson #define USB_FIFO_TX 0 531ed6d949aSAndrew Thompson #define USB_FIFO_RX 1 532ed6d949aSAndrew Thompson 533ed6d949aSAndrew Thompson /* 534ed6d949aSAndrew Thompson * Locking note for the following functions. All the 535ed6d949aSAndrew Thompson * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called 536ed6d949aSAndrew Thompson * locked. The others are called unlocked. 537ed6d949aSAndrew Thompson */ 538ed6d949aSAndrew Thompson struct usb_fifo_methods { 539ed6d949aSAndrew Thompson usb_fifo_open_t *f_open; 540ed6d949aSAndrew Thompson usb_fifo_close_t *f_close; 541ed6d949aSAndrew Thompson usb_fifo_ioctl_t *f_ioctl; 542ed6d949aSAndrew Thompson /* 543ed6d949aSAndrew Thompson * NOTE: The post-ioctl callback is called after the USB reference 544ed6d949aSAndrew Thompson * gets locked in the IOCTL handler: 545ed6d949aSAndrew Thompson */ 546ed6d949aSAndrew Thompson usb_fifo_ioctl_t *f_ioctl_post; 547ed6d949aSAndrew Thompson usb_fifo_cmd_t *f_start_read; 548ed6d949aSAndrew Thompson usb_fifo_cmd_t *f_stop_read; 549ed6d949aSAndrew Thompson usb_fifo_cmd_t *f_start_write; 550ed6d949aSAndrew Thompson usb_fifo_cmd_t *f_stop_write; 551ed6d949aSAndrew Thompson usb_fifo_filter_t *f_filter_read; 552ed6d949aSAndrew Thompson usb_fifo_filter_t *f_filter_write; 553ed6d949aSAndrew Thompson const char *basename[4]; 554ed6d949aSAndrew Thompson const char *postfix[4]; 555ed6d949aSAndrew Thompson }; 556ed6d949aSAndrew Thompson 557ed6d949aSAndrew Thompson struct usb_fifo_sc { 558ed6d949aSAndrew Thompson struct usb_fifo *fp[2]; 5592ffd5fdcSHans Petter Selasky struct usb_fs_privdata *dev; 560ed6d949aSAndrew Thompson }; 561ed6d949aSAndrew Thompson 562ed6d949aSAndrew Thompson const char *usbd_errstr(usb_error_t error); 563ed6d949aSAndrew Thompson void *usbd_find_descriptor(struct usb_device *udev, void *id, 564ed6d949aSAndrew Thompson uint8_t iface_index, uint8_t type, uint8_t type_mask, 565ed6d949aSAndrew Thompson uint8_t subtype, uint8_t subtype_mask); 566ed6d949aSAndrew Thompson struct usb_config_descriptor *usbd_get_config_descriptor( 567ed6d949aSAndrew Thompson struct usb_device *udev); 568ed6d949aSAndrew Thompson struct usb_device_descriptor *usbd_get_device_descriptor( 569ed6d949aSAndrew Thompson struct usb_device *udev); 570ed6d949aSAndrew Thompson struct usb_interface *usbd_get_iface(struct usb_device *udev, 571ed6d949aSAndrew Thompson uint8_t iface_index); 572ed6d949aSAndrew Thompson struct usb_interface_descriptor *usbd_get_interface_descriptor( 573ed6d949aSAndrew Thompson struct usb_interface *iface); 574ed6d949aSAndrew Thompson struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index, 575ed6d949aSAndrew Thompson const struct usb_config *setup); 576ed6d949aSAndrew Thompson struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val); 577ed6d949aSAndrew Thompson usb_error_t usbd_interface_count(struct usb_device *udev, uint8_t *count); 578ed6d949aSAndrew Thompson enum usb_hc_mode usbd_get_mode(struct usb_device *udev); 579ed6d949aSAndrew Thompson enum usb_dev_speed usbd_get_speed(struct usb_device *udev); 580ed6d949aSAndrew Thompson void device_set_usb_desc(device_t dev); 581ed6d949aSAndrew Thompson void usb_pause_mtx(struct mtx *mtx, int _ticks); 5828427ed84SHans Petter Selasky usb_error_t usbd_set_pnpinfo(struct usb_device *udev, 5838427ed84SHans Petter Selasky uint8_t iface_index, const char *pnpinfo); 584d46dc4adSHans Petter Selasky usb_error_t usbd_add_dynamic_quirk(struct usb_device *udev, 585d46dc4adSHans Petter Selasky uint16_t quirk); 586a5cf1aaaSHans Petter Selasky usb_error_t usbd_set_endpoint_mode(struct usb_device *udev, 587a5cf1aaaSHans Petter Selasky struct usb_endpoint *ep, uint8_t ep_mode); 588a5cf1aaaSHans Petter Selasky uint8_t usbd_get_endpoint_mode(struct usb_device *udev, 589a5cf1aaaSHans Petter Selasky struct usb_endpoint *ep); 590ed6d949aSAndrew Thompson 591ed6d949aSAndrew Thompson const struct usb_device_id *usbd_lookup_id_by_info( 592ed6d949aSAndrew Thompson const struct usb_device_id *id, usb_size_t sizeof_id, 593ed6d949aSAndrew Thompson const struct usbd_lookup_info *info); 594ed6d949aSAndrew Thompson int usbd_lookup_id_by_uaa(const struct usb_device_id *id, 595ed6d949aSAndrew Thompson usb_size_t sizeof_id, struct usb_attach_arg *uaa); 596ed6d949aSAndrew Thompson 597ed6d949aSAndrew Thompson usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, 598ed6d949aSAndrew Thompson struct usb_device_request *req, void *data, uint16_t flags, 599ed6d949aSAndrew Thompson uint16_t *actlen, usb_timeout_t timeout); 600ed6d949aSAndrew Thompson #define usbd_do_request(u,m,r,d) \ 601ed6d949aSAndrew Thompson usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT) 602ed6d949aSAndrew Thompson 603ed6d949aSAndrew Thompson uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, 604ed6d949aSAndrew Thompson struct usb_xfer *xfer2); 605ed6d949aSAndrew Thompson uint8_t usbd_get_interface_altindex(struct usb_interface *iface); 606ed6d949aSAndrew Thompson usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, 607ed6d949aSAndrew Thompson uint8_t iface_index, uint8_t alt_index); 608ed6d949aSAndrew Thompson uint32_t usbd_get_isoc_fps(struct usb_device *udev); 609506a911bSHans Petter Selasky uint32_t usbd_get_max_frame_length(const struct usb_endpoint_descriptor *, 610506a911bSHans Petter Selasky const struct usb_endpoint_ss_comp_descriptor *, 611506a911bSHans Petter Selasky enum usb_dev_speed); 612ed6d949aSAndrew Thompson usb_error_t usbd_transfer_setup(struct usb_device *udev, 613ed6d949aSAndrew Thompson const uint8_t *ifaces, struct usb_xfer **pxfer, 614ed6d949aSAndrew Thompson const struct usb_config *setup_start, uint16_t n_setup, 615ed6d949aSAndrew Thompson void *priv_sc, struct mtx *priv_mtx); 616ed6d949aSAndrew Thompson void usbd_transfer_submit(struct usb_xfer *xfer); 617ed6d949aSAndrew Thompson void usbd_transfer_clear_stall(struct usb_xfer *xfer); 618ed6d949aSAndrew Thompson void usbd_transfer_drain(struct usb_xfer *xfer); 619ed6d949aSAndrew Thompson uint8_t usbd_transfer_pending(struct usb_xfer *xfer); 620ed6d949aSAndrew Thompson void usbd_transfer_start(struct usb_xfer *xfer); 621ed6d949aSAndrew Thompson void usbd_transfer_stop(struct usb_xfer *xfer); 622ed6d949aSAndrew Thompson void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup); 623ed6d949aSAndrew Thompson void usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max); 624ed6d949aSAndrew Thompson void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, 625ed6d949aSAndrew Thompson uint8_t parent_index); 626ed6d949aSAndrew Thompson uint8_t usbd_get_bus_index(struct usb_device *udev); 627ed6d949aSAndrew Thompson uint8_t usbd_get_device_index(struct usb_device *udev); 628ed6d949aSAndrew Thompson void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode); 629d2d71ce7SAndrew Thompson uint8_t usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode); 630ed6d949aSAndrew Thompson uint8_t usbd_device_attached(struct usb_device *udev); 631ed6d949aSAndrew Thompson 63231a11691SHans Petter Selasky usb_frlength_t 63331a11691SHans Petter Selasky usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex); 634ed6d949aSAndrew Thompson void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, 635ed6d949aSAndrew Thompson int *aframes, int *nframes); 636a6d2f40eSHans Petter Selasky struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t); 637a6d2f40eSHans Petter Selasky void *usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t); 638ed6d949aSAndrew Thompson void *usbd_xfer_softc(struct usb_xfer *xfer); 639ed6d949aSAndrew Thompson void *usbd_xfer_get_priv(struct usb_xfer *xfer); 640ed6d949aSAndrew Thompson void usbd_xfer_set_priv(struct usb_xfer *xfer, void *); 641ed6d949aSAndrew Thompson void usbd_xfer_set_interval(struct usb_xfer *xfer, int); 642ed6d949aSAndrew Thompson uint8_t usbd_xfer_state(struct usb_xfer *xfer); 643ed6d949aSAndrew Thompson void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 644ed6d949aSAndrew Thompson void *ptr, usb_frlength_t len); 6458f9e0ef9SAndrew Thompson void usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 646ed6d949aSAndrew Thompson void **ptr, int *len); 647ed6d949aSAndrew Thompson void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, 648ed6d949aSAndrew Thompson usb_frcount_t frindex); 649ed6d949aSAndrew Thompson usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer); 650ed6d949aSAndrew Thompson usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer); 651ed6d949aSAndrew Thompson usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer); 652883bb300SAndrew Thompson uint8_t usbd_xfer_get_fps_shift(struct usb_xfer *xfer); 6538f9e0ef9SAndrew Thompson usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer, 654ed6d949aSAndrew Thompson usb_frcount_t frindex); 655ed6d949aSAndrew Thompson void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, 656ed6d949aSAndrew Thompson usb_frlength_t len); 657ed6d949aSAndrew Thompson void usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout); 658ed6d949aSAndrew Thompson void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n); 659f83f5d58SHans Petter Selasky void usbd_xfer_set_zlp(struct usb_xfer *xfer); 660f83f5d58SHans Petter Selasky uint8_t usbd_xfer_get_and_clr_zlp(struct usb_xfer *xfer); 661ed6d949aSAndrew Thompson void usbd_xfer_set_stall(struct usb_xfer *xfer); 662ed6d949aSAndrew Thompson int usbd_xfer_is_stalled(struct usb_xfer *xfer); 663ed6d949aSAndrew Thompson void usbd_xfer_set_flag(struct usb_xfer *xfer, int flag); 664ed6d949aSAndrew Thompson void usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag); 66529bd7d7eSAndrew Thompson uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer); 666e91fe3a9SHans Petter Selasky uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer); 667ed6d949aSAndrew Thompson 668ed6d949aSAndrew Thompson void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, 669ed6d949aSAndrew Thompson const void *ptr, usb_frlength_t len); 670ed6d949aSAndrew Thompson int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset, 671ed6d949aSAndrew Thompson const void *ptr, usb_frlength_t len); 672ed6d949aSAndrew Thompson void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, 673ed6d949aSAndrew Thompson void *ptr, usb_frlength_t len); 674ed6d949aSAndrew Thompson int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset, 675ed6d949aSAndrew Thompson void *ptr, usb_frlength_t len); 676ed6d949aSAndrew Thompson void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, 677ed6d949aSAndrew Thompson struct usb_page_search *res); 678ed6d949aSAndrew Thompson void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, 679ed6d949aSAndrew Thompson struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len); 680ed6d949aSAndrew Thompson void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset, 681ed6d949aSAndrew Thompson usb_frlength_t len); 6829eb0d702SHans Petter Selasky void usbd_start_re_enumerate(struct usb_device *udev); 683d64e9217SHans Petter Selasky usb_error_t 684d64e9217SHans Petter Selasky usbd_start_set_config(struct usb_device *, uint8_t); 6850eb8d462SHans Petter Selasky int usbd_in_polling_mode(void); 6860eb8d462SHans Petter Selasky void usbd_dummy_timeout(void *); 687ed6d949aSAndrew Thompson 688ed6d949aSAndrew Thompson int usb_fifo_attach(struct usb_device *udev, void *priv_sc, 689ed6d949aSAndrew Thompson struct mtx *priv_mtx, struct usb_fifo_methods *pm, 6906d917491SHans Petter Selasky struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit, 691ed6d949aSAndrew Thompson uint8_t iface_index, uid_t uid, gid_t gid, int mode); 692ed6d949aSAndrew Thompson void usb_fifo_detach(struct usb_fifo_sc *f_sc); 693ed6d949aSAndrew Thompson int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, 694ed6d949aSAndrew Thompson uint16_t nbuf); 695ed6d949aSAndrew Thompson void usb_fifo_free_buffer(struct usb_fifo *f); 696ed6d949aSAndrew Thompson uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo); 697ed6d949aSAndrew Thompson void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 698ed6d949aSAndrew Thompson usb_frlength_t offset, usb_frlength_t len, uint8_t what); 699ed6d949aSAndrew Thompson void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr, 700ed6d949aSAndrew Thompson usb_size_t len, uint8_t what); 701ed6d949aSAndrew Thompson uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len); 702ed6d949aSAndrew Thompson void usb_fifo_put_data_error(struct usb_fifo *fifo); 703ed6d949aSAndrew Thompson uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 704ed6d949aSAndrew Thompson usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, 705ed6d949aSAndrew Thompson uint8_t what); 706ed6d949aSAndrew Thompson uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr, 707ed6d949aSAndrew Thompson usb_size_t len, usb_size_t *actlen, uint8_t what); 708ed6d949aSAndrew Thompson uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr, 709ed6d949aSAndrew Thompson usb_size_t *plen); 710ed6d949aSAndrew Thompson void usb_fifo_reset(struct usb_fifo *f); 711ed6d949aSAndrew Thompson void usb_fifo_wakeup(struct usb_fifo *f); 712ed6d949aSAndrew Thompson void usb_fifo_get_data_error(struct usb_fifo *fifo); 713ed6d949aSAndrew Thompson void *usb_fifo_softc(struct usb_fifo *fifo); 7149e90dc16SAlfred Perlstein void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t); 7159e90dc16SAlfred Perlstein void usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t); 7169e90dc16SAlfred Perlstein void usb_fifo_free(struct usb_fifo *f); 717a2dd1caaSHans Petter Selasky #endif /* _KERNEL || _STANDALONE */ 718ed6d949aSAndrew Thompson #endif /* _USB_USBDI_H_ */ 719