usb_core.h revision 194230
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usb_core.h 194230 2009-06-15 01:09:19Z thompsa $ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24184610Salfred * SUCH DAMAGE. 25184610Salfred */ 26184610Salfred 27184610Salfred/* 28190754Sthompsa * Including this file is mandatory for all USB related c-files in the kernel. 29184610Salfred */ 30184610Salfred 31194230Sthompsa#ifndef _USB_CORE_H_ 32194230Sthompsa#define _USB_CORE_H_ 33184610Salfred 34190185Sthompsa#define USB_STACK_VERSION 2000 /* 2.0 */ 35190185Sthompsa 36190180Sthompsa/* Allow defines in "opt_usb.h" to override configuration */ 37190180Sthompsa 38190180Sthompsa#include "opt_usb.h" 39190180Sthompsa#include "opt_bus.h" 40190180Sthompsa 41184610Salfred/* Default USB configuration */ 42184610Salfred 43190180Sthompsa/* 44190180Sthompsa * The following macro defines if the code shall support 45190180Sthompsa * /dev/usb/x.y.z. 46190180Sthompsa */ 47189599Sthompsa#ifndef USB_HAVE_UGEN 48189599Sthompsa#define USB_HAVE_UGEN 1 49189599Sthompsa#endif 50189599Sthompsa 51190180Sthompsa/* 52190180Sthompsa * The following macro defines if the code shall support BUS-DMA. 53190180Sthompsa */ 54190180Sthompsa#ifndef USB_HAVE_BUSDMA 55190180Sthompsa#define USB_HAVE_BUSDMA 1 56190180Sthompsa#endif 57190180Sthompsa 58190180Sthompsa/* 59190180Sthompsa * The following macro defines if the code shall support the Linux 60190180Sthompsa * compatibility layer. 61190180Sthompsa */ 62190180Sthompsa#ifndef USB_HAVE_COMPAT_LINUX 63190180Sthompsa#define USB_HAVE_COMPAT_LINUX 1 64190180Sthompsa#endif 65190180Sthompsa 66190180Sthompsa/* 67190180Sthompsa * The following macro defines if the code shall support 68190180Sthompsa * userland data transfer via copyin() and copyout() 69190180Sthompsa */ 70190180Sthompsa#ifndef USB_HAVE_USER_IO 71190180Sthompsa#define USB_HAVE_USER_IO 1 72190180Sthompsa#endif 73190180Sthompsa 74190180Sthompsa/* 75190180Sthompsa * The following macro defines if the code shall support copy in via 76190180Sthompsa * bsd-mbufs to USB. 77190180Sthompsa */ 78190180Sthompsa#ifndef USB_HAVE_MBUF 79190180Sthompsa#define USB_HAVE_MBUF 1 80190180Sthompsa#endif 81190180Sthompsa 82190180Sthompsa/* 83190180Sthompsa * The following macro defines if the code shall compile a table 84190180Sthompsa * describing USB vendor and product IDs. 85190180Sthompsa */ 86190180Sthompsa#ifndef USB_VERBOSE 87190180Sthompsa#define USB_VERBOSE 1 88190180Sthompsa#endif 89190180Sthompsa 90190180Sthompsa/* 91190180Sthompsa * The following macro defines if USB debugging support shall be 92190180Sthompsa * compiled for the USB core and all drivers. 93190180Sthompsa */ 94190180Sthompsa#ifndef USB_DEBUG 95190180Sthompsa#define USB_DEBUG 1 96190180Sthompsa#endif 97190180Sthompsa 98190734Sthompsa/* 99190734Sthompsa * The following macro defines if USB transaction translator support 100190735Sthompsa * shall be supported for the USB HUB and USB controller drivers. 101190734Sthompsa */ 102190734Sthompsa#ifndef USB_HAVE_TT_SUPPORT 103190734Sthompsa#define USB_HAVE_TT_SUPPORT 1 104190734Sthompsa#endif 105190734Sthompsa 106190734Sthompsa/* 107190734Sthompsa * The following macro defines if the USB power daemon shall 108190735Sthompsa * be supported in the USB core. 109190734Sthompsa */ 110190734Sthompsa#ifndef USB_HAVE_POWERD 111190734Sthompsa#define USB_HAVE_POWERD 1 112190734Sthompsa#endif 113190734Sthompsa 114190735Sthompsa/* 115190735Sthompsa * The following macro defines if the USB autoinstall detection shall 116190735Sthompsa * be supported in the USB core. 117190735Sthompsa */ 118190735Sthompsa#ifndef USB_HAVE_MSCTEST 119190735Sthompsa#define USB_HAVE_MSCTEST 1 120190735Sthompsa#endif 121190735Sthompsa 122184610Salfred#ifndef USB_TD_GET_PROC 123184610Salfred#define USB_TD_GET_PROC(td) (td)->td_proc 124184610Salfred#endif 125184610Salfred 126184610Salfred#ifndef USB_PROC_GET_GID 127184610Salfred#define USB_PROC_GET_GID(td) (td)->p_pgid 128184610Salfred#endif 129184610Salfred 130184610Salfred/* Include files */ 131184610Salfred 132184610Salfred#include <sys/stdint.h> 133184610Salfred#include <sys/stddef.h> 134184610Salfred#include <sys/param.h> 135184610Salfred#include <sys/queue.h> 136184610Salfred#include <sys/types.h> 137184610Salfred#include <sys/systm.h> 138184610Salfred#include <sys/kernel.h> 139184610Salfred#include <sys/bus.h> 140184610Salfred#include <sys/linker_set.h> 141184610Salfred#include <sys/module.h> 142184610Salfred#include <sys/lock.h> 143184610Salfred#include <sys/mutex.h> 144184610Salfred#include <sys/condvar.h> 145184610Salfred#include <sys/sysctl.h> 146184610Salfred#include <sys/sx.h> 147184610Salfred#include <sys/unistd.h> 148184610Salfred#include <sys/callout.h> 149184610Salfred#include <sys/malloc.h> 150184610Salfred#include <sys/priv.h> 151184610Salfred 152190185Sthompsa#include <dev/usb/usb_defs.h> 153188942Sthompsa#include <dev/usb/usb_revision.h> 154184610Salfred 155188942Sthompsa#include "usb_if.h" 156184610Salfred 157190185Sthompsa#ifndef USB_HOST_ALIGN 158184610Salfred#define USB_HOST_ALIGN 8 /* bytes, must be power of two */ 159190185Sthompsa#endif 160184610Salfred 161190185Sthompsa#ifndef USB_FS_ISOC_UFRAME_MAX 162184610Salfred#define USB_FS_ISOC_UFRAME_MAX 4 /* exclusive unit */ 163190185Sthompsa#endif 164184610Salfred 165184610Salfred#if (USB_FS_ISOC_UFRAME_MAX > 6) 166184610Salfred#error "USB_FS_ISOC_UFRAME_MAX cannot be set higher than 6" 167184610Salfred#endif 168184610Salfred 169190185Sthompsa#ifndef USB_BUS_MAX 170190185Sthompsa#define USB_BUS_MAX 256 /* units */ 171190185Sthompsa#endif 172190185Sthompsa 173190185Sthompsa#ifndef USB_MAX_DEVICES 174190185Sthompsa#define USB_MAX_DEVICES 128 /* units */ 175190185Sthompsa#endif 176190185Sthompsa 177190185Sthompsa#if (USB_MAX_DEVICES < USB_MIN_DEVICES) 178190185Sthompsa#error "Minimum number of devices is greater than maximum number of devices." 179190185Sthompsa#endif 180190185Sthompsa 181190185Sthompsa#ifndef USB_IFACE_MAX 182190185Sthompsa#define USB_IFACE_MAX 32 /* units */ 183190185Sthompsa#endif 184190185Sthompsa 185190185Sthompsa#ifndef USB_FIFO_MAX 186190185Sthompsa#define USB_FIFO_MAX 128 /* units */ 187190185Sthompsa#endif 188190185Sthompsa 189190185Sthompsa#if (USB_FIFO_MAX & 1) 190190185Sthompsa#error "Number of FIFOs must be odd." 191190185Sthompsa#endif 192190185Sthompsa 193184610Salfred#define USB_MAX_FS_ISOC_FRAMES_PER_XFER (120) /* units */ 194184610Salfred#define USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120) /* units */ 195184610Salfred 196190185Sthompsa#ifndef USB_HUB_MAX_DEPTH 197190185Sthompsa#define USB_HUB_MAX_DEPTH 5 198190185Sthompsa#endif 199184610Salfred 200190181Sthompsa#ifndef USB_EP0_BUFSIZE 201190181Sthompsa#define USB_EP0_BUFSIZE 1024 /* bytes */ 202190181Sthompsa#endif 203190181Sthompsa 204184610Salfred/* USB transfer states */ 205184610Salfred 206184610Salfred#define USB_ST_SETUP 0 207184610Salfred#define USB_ST_TRANSFERRED 1 208184610Salfred#define USB_ST_ERROR 2 209184610Salfred 210194064Sthompsa/* USB handle request states */ 211194064Sthompsa#define USB_HR_NOT_COMPLETE 0 212194064Sthompsa#define USB_HR_COMPLETE_OK 1 213194064Sthompsa#define USB_HR_COMPLETE_ERR 2 214194064Sthompsa 215184610Salfred/* 216184610Salfred * The following macro will return the current state of an USB 217184610Salfred * transfer like defined by the "USB_ST_XXX" enums. 218184610Salfred */ 219194228Sthompsa#define USB_GET_STATE(xfer) ((xfer)->usb_state) 220184610Salfred 221184610Salfred/* 222184610Salfred * The following macro will tell if an USB transfer is currently 223184610Salfred * receiving or transferring data. 224184610Salfred */ 225192499Sthompsa#define USB_GET_DATA_ISREAD(xfer) ((xfer)->flags_int.usb_mode == \ 226193644Sthompsa USB_MODE_DEVICE ? (((xfer)->endpointno & UE_DIR_IN) ? 0 : 1) : \ 227193644Sthompsa (((xfer)->endpointno & UE_DIR_IN) ? 1 : 0)) 228184610Salfred 229184610Salfred/* 230184610Salfred * The following macros are used used to convert milliseconds into 231184610Salfred * HZ. We use 1024 instead of 1000 milliseconds per second to save a 232184610Salfred * full division. 233184610Salfred */ 234184610Salfred#define USB_MS_HZ 1024 235184610Salfred 236184610Salfred#define USB_MS_TO_TICKS(ms) \ 237184610Salfred (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ) 238184610Salfred 239184610Salfred/* macros */ 240184610Salfred 241194228Sthompsa#define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f) 242194228Sthompsa#define usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d) 243194228Sthompsa#define usb_callout_stop(c) callout_stop(&(c)->co) 244194228Sthompsa#define usb_callout_drain(c) callout_drain(&(c)->co) 245194228Sthompsa#define usb_callout_pending(c) callout_pending(&(c)->co) 246184610Salfred 247185087Salfred#define USB_BUS_LOCK(_b) mtx_lock(&(_b)->bus_mtx) 248185087Salfred#define USB_BUS_UNLOCK(_b) mtx_unlock(&(_b)->bus_mtx) 249185087Salfred#define USB_BUS_LOCK_ASSERT(_b, _t) mtx_assert(&(_b)->bus_mtx, _t) 250187173Sthompsa#define USB_XFER_LOCK(_x) mtx_lock((_x)->xroot->xfer_mtx) 251187173Sthompsa#define USB_XFER_UNLOCK(_x) mtx_unlock((_x)->xroot->xfer_mtx) 252187173Sthompsa#define USB_XFER_LOCK_ASSERT(_x, _t) mtx_assert((_x)->xroot->xfer_mtx, _t) 253184610Salfred/* structure prototypes */ 254184610Salfred 255184610Salfredstruct file; 256192984Sthompsastruct usb_bus; 257192984Sthompsastruct usb_device; 258192984Sthompsastruct usb_device_request; 259192984Sthompsastruct usb_page; 260192984Sthompsastruct usb_page_cache; 261192984Sthompsastruct usb_xfer; 262192984Sthompsastruct usb_xfer_root; 263184610Salfred 264184610Salfred/* typedefs */ 265184610Salfred 266193045Sthompsatypedef void (usb_callback_t)(struct usb_xfer *); 267184610Salfred 268190174Sthompsa#ifndef USB_HAVE_USB_ERROR_T 269193045Sthompsatypedef uint8_t usb_error_t; /* see "USB_ERR_XXX" */ 270190174Sthompsa#endif 271190174Sthompsa 272190174Sthompsa#ifndef USB_HAVE_TIMEOUT_T 273193045Sthompsatypedef uint32_t usb_timeout_t; /* milliseconds */ 274190174Sthompsa#endif 275190174Sthompsa 276190181Sthompsa#ifndef USB_HAVE_FRLENGTH_T 277193045Sthompsatypedef uint32_t usb_frlength_t; /* bytes */ 278190174Sthompsa#endif 279190174Sthompsa 280190181Sthompsa#ifndef USB_HAVE_FRCOUNT_T 281193045Sthompsatypedef uint32_t usb_frcount_t; /* units */ 282190174Sthompsa#endif 283190174Sthompsa 284193074Sthompsa#ifndef USB_HAVE_SIZE_T 285193074Sthompsatypedef uint32_t usb_size_t; /* bytes */ 286193074Sthompsa#endif 287193074Sthompsa 288190174Sthompsa#ifndef USB_HAVE_TICKS_T 289193045Sthompsatypedef uint32_t usb_ticks_t; /* system defined */ 290190174Sthompsa#endif 291190174Sthompsa 292190181Sthompsa#ifndef USB_HAVE_POWER_MASK_T 293193045Sthompsatypedef uint16_t usb_power_mask_t; /* see "USB_HW_POWER_XXX" */ 294190181Sthompsa#endif 295190181Sthompsa 296193045Sthompsatypedef usb_error_t (usb_handle_req_t)(struct usb_device *, 297192984Sthompsa struct usb_device_request *, const void **, uint16_t *); 298191402Sthompsa 299184610Salfred/* structures */ 300184610Salfred 301184610Salfred/* 302184610Salfred * Common queue structure for USB transfers. 303184610Salfred */ 304192984Sthompsastruct usb_xfer_queue { 305192984Sthompsa TAILQ_HEAD(, usb_xfer) head; 306192984Sthompsa struct usb_xfer *curr; /* current USB transfer processed */ 307192984Sthompsa void (*command) (struct usb_xfer_queue *pq); 308184610Salfred uint8_t recurse_1:1; 309184610Salfred uint8_t recurse_2:1; 310184610Salfred}; 311184610Salfred 312184610Salfred/* 313184610Salfred * The following is a wrapper for the callout structure to ease 314184610Salfred * porting the code to other platforms. 315184610Salfred */ 316192984Sthompsastruct usb_callout { 317184610Salfred struct callout co; 318184610Salfred}; 319184610Salfred 320184610Salfred/* 321184610Salfred * The following structure defines a set of USB transfer flags. 322184610Salfred */ 323192984Sthompsastruct usb_xfer_flags { 324184610Salfred uint8_t force_short_xfer:1; /* force a short transmit transfer 325184610Salfred * last */ 326184610Salfred uint8_t short_xfer_ok:1; /* allow short receive transfers */ 327184610Salfred uint8_t short_frames_ok:1; /* allow short frames */ 328184610Salfred uint8_t pipe_bof:1; /* block pipe on failure */ 329184610Salfred uint8_t proxy_buffer:1; /* makes buffer size a factor of 330184610Salfred * "max_frame_size" */ 331184610Salfred uint8_t ext_buffer:1; /* uses external DMA buffer */ 332184610Salfred uint8_t manual_status:1; /* non automatic status stage on 333184610Salfred * control transfers */ 334184610Salfred uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can 335184610Salfred * be ignored */ 336184610Salfred uint8_t stall_pipe:1; /* set if the endpoint belonging to 337184610Salfred * this USB transfer should be stalled 338184610Salfred * before starting this transfer! */ 339184610Salfred}; 340184610Salfred 341184610Salfred/* 342184610Salfred * The following structure defines a set of internal USB transfer 343184610Salfred * flags. 344184610Salfred */ 345192984Sthompsastruct usb_xfer_flags_int { 346192499Sthompsa 347192499Sthompsa enum usb_hc_mode usb_mode; /* shadow copy of "udev->usb_mode" */ 348184610Salfred uint16_t control_rem; /* remainder in bytes */ 349184610Salfred 350184610Salfred uint8_t open:1; /* set if USB pipe has been opened */ 351184610Salfred uint8_t transferring:1; /* set if an USB transfer is in 352184610Salfred * progress */ 353184610Salfred uint8_t did_dma_delay:1; /* set if we waited for HW DMA */ 354184610Salfred uint8_t did_close:1; /* set if we closed the USB transfer */ 355184610Salfred uint8_t draining:1; /* set if we are draining an USB 356184610Salfred * transfer */ 357184610Salfred uint8_t started:1; /* keeps track of started or stopped */ 358184610Salfred uint8_t bandwidth_reclaimed:1; 359184610Salfred uint8_t control_xfr:1; /* set if control transfer */ 360184610Salfred uint8_t control_hdr:1; /* set if control header should be 361184610Salfred * sent */ 362184610Salfred uint8_t control_act:1; /* set if control transfer is active */ 363192552Sthompsa uint8_t control_stall:1; /* set if control transfer should be stalled */ 364184610Salfred 365184610Salfred uint8_t short_frames_ok:1; /* filtered version */ 366184610Salfred uint8_t short_xfer_ok:1; /* filtered version */ 367190180Sthompsa#if USB_HAVE_BUSDMA 368184610Salfred uint8_t bdma_enable:1; /* filtered version (only set if 369184610Salfred * hardware supports DMA) */ 370184610Salfred uint8_t bdma_no_post_sync:1; /* set if the USB callback wrapper 371184610Salfred * should not do the BUS-DMA post sync 372184610Salfred * operation */ 373184610Salfred uint8_t bdma_setup:1; /* set if BUS-DMA has been setup */ 374190180Sthompsa#endif 375184610Salfred uint8_t isochronous_xfr:1; /* set if isochronous transfer */ 376184610Salfred uint8_t curr_dma_set:1; /* used by USB HC/DC driver */ 377184610Salfred uint8_t can_cancel_immed:1; /* set if USB transfer can be 378184610Salfred * cancelled immediately */ 379184610Salfred}; 380184610Salfred 381184610Salfred/* 382190734Sthompsa * The following structure define an USB configuration, that basically 383190734Sthompsa * is used when setting up an USB transfer. 384184610Salfred */ 385192984Sthompsastruct usb_config { 386193045Sthompsa usb_callback_t *callback; /* USB transfer callback */ 387193045Sthompsa usb_frlength_t bufsize; /* total pipe buffer size in bytes */ 388193045Sthompsa usb_frcount_t frames; /* maximum number of USB frames */ 389193045Sthompsa usb_timeout_t interval; /* interval in milliseconds */ 390184610Salfred#define USB_DEFAULT_INTERVAL 0 391193045Sthompsa usb_timeout_t timeout; /* transfer timeout in milliseconds */ 392192984Sthompsa struct usb_xfer_flags flags; /* transfer flags */ 393192499Sthompsa enum usb_hc_mode usb_mode; /* host or device mode */ 394184610Salfred uint8_t type; /* pipe type */ 395184610Salfred uint8_t endpoint; /* pipe number */ 396184610Salfred uint8_t direction; /* pipe direction */ 397184610Salfred uint8_t ep_index; /* pipe index match to use */ 398184610Salfred uint8_t if_index; /* "ifaces" index to use */ 399184610Salfred}; 400184610Salfred 401184610Salfred/* 402184610Salfred * The following structure defines an USB transfer. 403184610Salfred */ 404192984Sthompsastruct usb_xfer { 405192984Sthompsa struct usb_callout timeout_handle; 406192984Sthompsa TAILQ_ENTRY(usb_xfer) wait_entry; /* used at various places */ 407184610Salfred 408192984Sthompsa struct usb_page_cache *buf_fixup; /* fixup buffer(s) */ 409192984Sthompsa struct usb_xfer_queue *wait_queue; /* pointer to queue that we 410184610Salfred * are waiting on */ 411192984Sthompsa struct usb_page *dma_page_ptr; 412193644Sthompsa struct usb_endpoint *endpoint; /* our USB endpoint */ 413192984Sthompsa struct usb_xfer_root *xroot; /* used by HC driver */ 414184610Salfred void *qh_start[2]; /* used by HC driver */ 415184610Salfred void *td_start[2]; /* used by HC driver */ 416184610Salfred void *td_transfer_first; /* used by HC driver */ 417184610Salfred void *td_transfer_last; /* used by HC driver */ 418184610Salfred void *td_transfer_cache; /* used by HC driver */ 419184610Salfred void *priv_sc; /* device driver data pointer 1 */ 420184610Salfred void *priv_fifo; /* device driver data pointer 2 */ 421184610Salfred void *local_buffer; 422193045Sthompsa usb_frlength_t *frlengths; 423192984Sthompsa struct usb_page_cache *frbuffers; 424193045Sthompsa usb_callback_t *callback; 425184610Salfred 426193045Sthompsa usb_frlength_t max_hc_frame_size; 427193045Sthompsa usb_frlength_t max_data_length; 428193045Sthompsa usb_frlength_t sumlen; /* sum of all lengths in bytes */ 429193045Sthompsa usb_frlength_t actlen; /* actual length in bytes */ 430193045Sthompsa usb_timeout_t timeout; /* milliseconds */ 431184610Salfred#define USB_NO_TIMEOUT 0 432184610Salfred#define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */ 433184610Salfred 434193045Sthompsa usb_frcount_t max_frame_count; /* initial value of "nframes" after 435184610Salfred * setup */ 436193045Sthompsa usb_frcount_t nframes; /* number of USB frames to transfer */ 437193045Sthompsa usb_frcount_t aframes; /* actual number of USB frames 438184610Salfred * transferred */ 439184610Salfred 440184610Salfred uint16_t max_packet_size; 441184610Salfred uint16_t max_frame_size; 442184610Salfred uint16_t qh_pos; 443184610Salfred uint16_t isoc_time_complete; /* in ms */ 444193045Sthompsa usb_timeout_t interval; /* milliseconds */ 445184610Salfred 446184610Salfred uint8_t address; /* physical USB address */ 447193644Sthompsa uint8_t endpointno; /* physical USB endpoint */ 448184610Salfred uint8_t max_packet_count; 449194228Sthompsa uint8_t usb_smask; 450194228Sthompsa uint8_t usb_cmask; 451194228Sthompsa uint8_t usb_uframe; 452194228Sthompsa uint8_t usb_state; 453184610Salfred 454193045Sthompsa usb_error_t error; 455184610Salfred 456192984Sthompsa struct usb_xfer_flags flags; 457192984Sthompsa struct usb_xfer_flags_int flags_int; 458184610Salfred}; 459184610Salfred 460184610Salfred/* 461184610Salfred * The following structure keeps information that is used to match 462192984Sthompsa * against an array of "usb_device_id" elements. 463184610Salfred */ 464194228Sthompsastruct usbd_lookup_info { 465184610Salfred uint16_t idVendor; 466184610Salfred uint16_t idProduct; 467184610Salfred uint16_t bcdDevice; 468184610Salfred uint8_t bDeviceClass; 469184610Salfred uint8_t bDeviceSubClass; 470184610Salfred uint8_t bDeviceProtocol; 471184610Salfred uint8_t bInterfaceClass; 472184610Salfred uint8_t bInterfaceSubClass; 473184610Salfred uint8_t bInterfaceProtocol; 474184610Salfred uint8_t bIfaceIndex; 475184610Salfred uint8_t bIfaceNum; 476184610Salfred uint8_t bConfigIndex; 477184610Salfred uint8_t bConfigNum; 478184610Salfred}; 479184610Salfred 480184610Salfred/* Structure used by probe and attach */ 481184610Salfred 482192984Sthompsastruct usb_attach_arg { 483194228Sthompsa struct usbd_lookup_info info; 484184610Salfred device_t temp_dev; /* for internal use */ 485193733Sthompsa unsigned long driver_info; /* for internal use */ 486193733Sthompsa void *driver_ivar; 487192984Sthompsa struct usb_device *device; /* current device */ 488192984Sthompsa struct usb_interface *iface; /* current interface */ 489192499Sthompsa enum usb_hc_mode usb_mode; /* host or device mode */ 490184610Salfred uint8_t port; 491184610Salfred uint8_t use_generic; /* hint for generic drivers */ 492184610Salfred}; 493184610Salfred 494184610Salfred/* external variables */ 495184610Salfred 496184610SalfredMALLOC_DECLARE(M_USB); 497184610SalfredMALLOC_DECLARE(M_USBDEV); 498184610SalfredMALLOC_DECLARE(M_USBHC); 499184610Salfred 500194228Sthompsaextern struct mtx usb_ref_lock; 501184610Salfred 502184610Salfred/* prototypes */ 503184610Salfred 504194228Sthompsaconst char *usbd_errstr(usb_error_t error); 505194228Sthompsaconst char *usb_statestr(enum usb_dev_state state); 506194228Sthompsastruct usb_config_descriptor *usbd_get_config_descriptor( 507192984Sthompsa struct usb_device *udev); 508194228Sthompsastruct usb_device_descriptor *usbd_get_device_descriptor( 509192984Sthompsa struct usb_device *udev); 510194228Sthompsastruct usb_interface *usbd_get_iface(struct usb_device *udev, 511185948Sthompsa uint8_t iface_index); 512194228Sthompsastruct usb_interface_descriptor *usbd_get_interface_descriptor( 513192984Sthompsa struct usb_interface *iface); 514194228Sthompsauint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, 515192984Sthompsa struct usb_xfer *xfer2); 516194228Sthompsauint8_t usbd_get_interface_altindex(struct usb_interface *iface); 517194228Sthompsausb_error_t usbd_set_alt_interface_index(struct usb_device *udev, 518185948Sthompsa uint8_t iface_index, uint8_t alt_index); 519194228Sthompsaenum usb_hc_mode usbd_get_mode(struct usb_device *udev); 520194228Sthompsaenum usb_dev_speed usbd_get_speed(struct usb_device *udev); 521194228Sthompsauint32_t usbd_get_isoc_fps(struct usb_device *udev); 522194228Sthompsausb_error_t usbd_transfer_setup(struct usb_device *udev, 523192984Sthompsa const uint8_t *ifaces, struct usb_xfer **pxfer, 524192984Sthompsa const struct usb_config *setup_start, uint16_t n_setup, 525185948Sthompsa void *priv_sc, struct mtx *priv_mtx); 526194228Sthompsavoid usbd_set_frame_data(struct usb_xfer *xfer, void *ptr, 527193045Sthompsa usb_frcount_t frindex); 528194228Sthompsavoid usbd_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, 529193045Sthompsa usb_frcount_t frindex); 530194228Sthompsavoid usbd_transfer_submit(struct usb_xfer *xfer); 531194228Sthompsavoid usbd_transfer_clear_stall(struct usb_xfer *xfer); 532194228Sthompsavoid usbd_transfer_drain(struct usb_xfer *xfer); 533194228Sthompsavoid usbd_transfer_set_stall(struct usb_xfer *xfer); 534194228Sthompsauint8_t usbd_transfer_pending(struct usb_xfer *xfer); 535194228Sthompsavoid usbd_transfer_start(struct usb_xfer *xfer); 536194228Sthompsavoid usbd_transfer_stop(struct usb_xfer *xfer); 537194228Sthompsavoid usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup); 538194228Sthompsavoid usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, 539185948Sthompsa uint8_t parent_index); 540194228Sthompsauint8_t usbd_get_bus_index(struct usb_device *udev); 541194228Sthompsauint8_t usbd_get_device_index(struct usb_device *udev); 542194228Sthompsavoid usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode); 543194228Sthompsauint8_t usbd_device_attached(struct usb_device *udev); 544184610Salfred 545194230Sthompsa#endif /* _USB_CORE_H_ */ 546