usb_core.h revision 190185
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usb_core.h 190185 2009-03-20 22:04:33Z 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/*
28184610Salfred * Including this file is mandatory for all USB related c-files in the
29184610Salfred * kernel.
30184610Salfred */
31184610Salfred
32184610Salfred#ifndef _USB2_CORE_H_
33184610Salfred#define	_USB2_CORE_H_
34184610Salfred
35190185Sthompsa#define	USB_STACK_VERSION 2000		/* 2.0 */
36190185Sthompsa
37190180Sthompsa/* Allow defines in "opt_usb.h" to override configuration */
38190180Sthompsa
39190180Sthompsa#include "opt_usb.h"
40190180Sthompsa#include "opt_bus.h"
41190180Sthompsa
42184610Salfred/* Default USB configuration */
43184610Salfred
44190180Sthompsa/*
45190180Sthompsa * The following macro defines if the code shall use cv_xxx() instead
46190180Sthompsa * of msleep() and wakeup().
47190180Sthompsa */
48190180Sthompsa#ifndef USB_HAVE_CONDVAR
49190180Sthompsa#define	USB_HAVE_CONDVAR 0
50184610Salfred#endif
51184610Salfred
52190180Sthompsa/*
53190180Sthompsa * The following macro defines if the code shall support
54190180Sthompsa * /dev/usb/x.y.z.
55190180Sthompsa */
56189599Sthompsa#ifndef USB_HAVE_UGEN
57189599Sthompsa#define	USB_HAVE_UGEN 1
58189599Sthompsa#endif
59189599Sthompsa
60190180Sthompsa/*
61190180Sthompsa * The following macro defines if the code shall support any forms of
62190180Sthompsa * ASCII strings.
63190180Sthompsa */
64190180Sthompsa#ifndef USB_HAVE_STRINGS
65190180Sthompsa#define	USB_HAVE_STRINGS 1
66190180Sthompsa#endif
67190180Sthompsa
68190180Sthompsa/*
69190180Sthompsa * The following macro defines if the code shall support BUS-DMA.
70190180Sthompsa */
71190180Sthompsa#ifndef USB_HAVE_BUSDMA
72190180Sthompsa#define	USB_HAVE_BUSDMA 1
73190180Sthompsa#endif
74190180Sthompsa
75190180Sthompsa/*
76190180Sthompsa * The following macro defines if the code shall support the Linux
77190180Sthompsa * compatibility layer.
78190180Sthompsa */
79190180Sthompsa#ifndef USB_HAVE_COMPAT_LINUX
80190180Sthompsa#define	USB_HAVE_COMPAT_LINUX 1
81190180Sthompsa#endif
82190180Sthompsa
83190180Sthompsa/*
84190180Sthompsa * The following macro defines if the code shall support
85190180Sthompsa * userland data transfer via copyin() and copyout()
86190180Sthompsa */
87190180Sthompsa#ifndef USB_HAVE_USER_IO
88190180Sthompsa#define	USB_HAVE_USER_IO 1
89190180Sthompsa#endif
90190180Sthompsa
91190180Sthompsa/*
92190180Sthompsa * The following macro defines if the code shall support copy in via
93190180Sthompsa * bsd-mbufs to USB.
94190180Sthompsa */
95190180Sthompsa#ifndef USB_HAVE_MBUF
96190180Sthompsa#define	USB_HAVE_MBUF 1
97190180Sthompsa#endif
98190180Sthompsa
99190180Sthompsa/*
100190180Sthompsa * The following macro defines if the code shall compile a table
101190180Sthompsa * describing USB vendor and product IDs.
102190180Sthompsa */
103190180Sthompsa#ifndef USB_VERBOSE
104190180Sthompsa#define	USB_VERBOSE 1
105190180Sthompsa#endif
106190180Sthompsa
107190180Sthompsa/*
108190180Sthompsa * The following macro defines if USB debugging support shall be
109190180Sthompsa * compiled for the USB core and all drivers.
110190180Sthompsa */
111190180Sthompsa#ifndef USB_DEBUG
112190180Sthompsa#define	USB_DEBUG 1
113190180Sthompsa#endif
114190180Sthompsa
115184610Salfred#ifndef USB_TD_GET_PROC
116184610Salfred#define	USB_TD_GET_PROC(td) (td)->td_proc
117184610Salfred#endif
118184610Salfred
119184610Salfred#ifndef USB_PROC_GET_GID
120184610Salfred#define	USB_PROC_GET_GID(td) (td)->p_pgid
121184610Salfred#endif
122184610Salfred
123184610Salfred/* Include files */
124184610Salfred
125184610Salfred#include <sys/stdint.h>
126184610Salfred#include <sys/stddef.h>
127184610Salfred#include <sys/param.h>
128184610Salfred#include <sys/queue.h>
129184610Salfred#include <sys/types.h>
130184610Salfred#include <sys/systm.h>
131184610Salfred#include <sys/kernel.h>
132184610Salfred#include <sys/bus.h>
133184610Salfred#include <sys/linker_set.h>
134184610Salfred#include <sys/module.h>
135184610Salfred#include <sys/lock.h>
136184610Salfred#include <sys/mutex.h>
137184610Salfred#include <sys/condvar.h>
138184610Salfred#include <sys/sysctl.h>
139184610Salfred#include <sys/sx.h>
140184610Salfred#include <sys/unistd.h>
141184610Salfred#include <sys/callout.h>
142184610Salfred#include <sys/malloc.h>
143184610Salfred#include <sys/priv.h>
144184610Salfred
145190185Sthompsa#include <dev/usb/usb_defs.h>
146188942Sthompsa#include <dev/usb/usb_revision.h>
147184610Salfred
148188942Sthompsa#include "usb_if.h"
149184610Salfred
150190185Sthompsa#ifndef USB_HOST_ALIGN
151184610Salfred#define	USB_HOST_ALIGN    8		/* bytes, must be power of two */
152190185Sthompsa#endif
153184610Salfred
154190185Sthompsa#ifndef USB_FS_ISOC_UFRAME_MAX
155184610Salfred#define	USB_FS_ISOC_UFRAME_MAX 4	/* exclusive unit */
156190185Sthompsa#endif
157184610Salfred
158184610Salfred#if (USB_FS_ISOC_UFRAME_MAX > 6)
159184610Salfred#error "USB_FS_ISOC_UFRAME_MAX cannot be set higher than 6"
160184610Salfred#endif
161184610Salfred
162190185Sthompsa#ifndef USB_BUS_MAX
163190185Sthompsa#define	USB_BUS_MAX 256			/* units */
164190185Sthompsa#endif
165190185Sthompsa
166190185Sthompsa#ifndef USB_MAX_DEVICES
167190185Sthompsa#define	USB_MAX_DEVICES 128		/* units */
168190185Sthompsa#endif
169190185Sthompsa
170190185Sthompsa#if (USB_MAX_DEVICES < USB_MIN_DEVICES)
171190185Sthompsa#error "Minimum number of devices is greater than maximum number of devices."
172190185Sthompsa#endif
173190185Sthompsa
174190185Sthompsa#ifndef USB_IFACE_MAX
175190185Sthompsa#define	USB_IFACE_MAX 32		/* units */
176190185Sthompsa#endif
177190185Sthompsa
178190185Sthompsa#ifndef USB_FIFO_MAX
179190185Sthompsa#define	USB_FIFO_MAX 128		/* units */
180190185Sthompsa#endif
181190185Sthompsa
182190185Sthompsa#if (USB_FIFO_MAX & 1)
183190185Sthompsa#error "Number of FIFOs must be odd."
184190185Sthompsa#endif
185190185Sthompsa
186184610Salfred#define	USB_MAX_FS_ISOC_FRAMES_PER_XFER (120)	/* units */
187184610Salfred#define	USB_MAX_HS_ISOC_FRAMES_PER_XFER (8*120)	/* units */
188184610Salfred
189190185Sthompsa#ifndef USB_HUB_MAX_DEPTH
190190185Sthompsa#define	USB_HUB_MAX_DEPTH	5
191190185Sthompsa#endif
192184610Salfred
193190181Sthompsa#ifndef USB_EP0_BUFSIZE
194190181Sthompsa#define	USB_EP0_BUFSIZE		1024	/* bytes */
195190181Sthompsa#endif
196190181Sthompsa
197184610Salfred/* USB transfer states */
198184610Salfred
199184610Salfred#define	USB_ST_SETUP       0
200184610Salfred#define	USB_ST_TRANSFERRED 1
201184610Salfred#define	USB_ST_ERROR       2
202184610Salfred
203184610Salfred/*
204184610Salfred * The following macro will return the current state of an USB
205184610Salfred * transfer like defined by the "USB_ST_XXX" enums.
206184610Salfred */
207184610Salfred#define	USB_GET_STATE(xfer) ((xfer)->usb2_state)
208184610Salfred
209184610Salfred/*
210184610Salfred * The following macro will tell if an USB transfer is currently
211184610Salfred * receiving or transferring data.
212184610Salfred */
213184610Salfred#define	USB_GET_DATA_ISREAD(xfer) (((xfer)->flags_int.usb2_mode == \
214184610Salfred	USB_MODE_DEVICE) ? ((xfer->endpoint & UE_DIR_IN) ? 0 : 1) : \
215184610Salfred	((xfer->endpoint & UE_DIR_IN) ? 1 : 0))
216184610Salfred
217184610Salfred/*
218184610Salfred * The following macros are used used to convert milliseconds into
219184610Salfred * HZ. We use 1024 instead of 1000 milliseconds per second to save a
220184610Salfred * full division.
221184610Salfred */
222184610Salfred#define	USB_MS_HZ 1024
223184610Salfred
224184610Salfred#define	USB_MS_TO_TICKS(ms) \
225184610Salfred  (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
226184610Salfred
227184610Salfred/* macros */
228184610Salfred
229184610Salfred#define	usb2_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f)
230184610Salfred#define	usb2_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d)
231184610Salfred#define	usb2_callout_stop(c) callout_stop(&(c)->co)
232184610Salfred#define	usb2_callout_drain(c) callout_drain(&(c)->co)
233184610Salfred#define	usb2_callout_pending(c) callout_pending(&(c)->co)
234184610Salfred
235185087Salfred#define	USB_BUS_LOCK(_b)		mtx_lock(&(_b)->bus_mtx)
236185087Salfred#define	USB_BUS_UNLOCK(_b)		mtx_unlock(&(_b)->bus_mtx)
237185087Salfred#define	USB_BUS_LOCK_ASSERT(_b, _t)	mtx_assert(&(_b)->bus_mtx, _t)
238187173Sthompsa#define	USB_XFER_LOCK(_x)		mtx_lock((_x)->xroot->xfer_mtx)
239187173Sthompsa#define	USB_XFER_UNLOCK(_x)		mtx_unlock((_x)->xroot->xfer_mtx)
240187173Sthompsa#define	USB_XFER_LOCK_ASSERT(_x, _t)	mtx_assert((_x)->xroot->xfer_mtx, _t)
241184610Salfred/* structure prototypes */
242184610Salfred
243184610Salfredstruct file;
244184610Salfredstruct usb2_bus;
245184610Salfredstruct usb2_device;
246184610Salfredstruct usb2_page;
247184610Salfredstruct usb2_page_cache;
248184610Salfredstruct usb2_xfer;
249184610Salfredstruct usb2_xfer_root;
250184610Salfred
251184610Salfred/* typedefs */
252184610Salfred
253184610Salfredtypedef void (usb2_callback_t)(struct usb2_xfer *);
254184610Salfred
255190174Sthompsa#ifndef USB_HAVE_USB_ERROR_T
256190174Sthompsatypedef uint8_t usb2_error_t;		/* see "USB_ERR_XXX" */
257190174Sthompsa#endif
258190174Sthompsa
259190174Sthompsa#ifndef USB_HAVE_TIMEOUT_T
260190174Sthompsatypedef uint32_t usb2_timeout_t;	/* milliseconds */
261190174Sthompsa#endif
262190174Sthompsa
263190181Sthompsa#ifndef USB_HAVE_FRLENGTH_T
264190181Sthompsatypedef uint32_t usb2_frlength_t;	/* bytes */
265190174Sthompsa#endif
266190174Sthompsa
267190181Sthompsa#ifndef USB_HAVE_FRCOUNT_T
268190181Sthompsatypedef uint32_t usb2_frcount_t;	/* units */
269190174Sthompsa#endif
270190174Sthompsa
271190174Sthompsa#ifndef USB_HAVE_SIZE_T
272190174Sthompsatypedef uint32_t usb2_size_t;		/* bytes */
273190174Sthompsa#endif
274190174Sthompsa
275190174Sthompsa#ifndef USB_HAVE_TICKS_T
276190174Sthompsatypedef uint32_t usb2_ticks_t;		/* system defined */
277190174Sthompsa#endif
278190174Sthompsa
279190181Sthompsa#ifndef USB_HAVE_POWER_MASK_T
280190181Sthompsatypedef uint32_t usb2_power_mask_t;	/* see "USB_HW_POWER_XXX" */
281190181Sthompsa#endif
282190181Sthompsa
283184610Salfred/* structures */
284184610Salfred
285184610Salfred/*
286184610Salfred * Common queue structure for USB transfers.
287184610Salfred */
288184610Salfredstruct usb2_xfer_queue {
289184610Salfred	TAILQ_HEAD(, usb2_xfer) head;
290184610Salfred	struct usb2_xfer *curr;		/* current USB transfer processed */
291184610Salfred	void    (*command) (struct usb2_xfer_queue *pq);
292184610Salfred	uint8_t	recurse_1:1;
293184610Salfred	uint8_t	recurse_2:1;
294184610Salfred};
295184610Salfred
296184610Salfred/*
297184610Salfred * The following is a wrapper for the callout structure to ease
298184610Salfred * porting the code to other platforms.
299184610Salfred */
300184610Salfredstruct usb2_callout {
301184610Salfred	struct callout co;
302184610Salfred};
303184610Salfred
304184610Salfred/*
305184610Salfred * The following structure defines a set of USB transfer flags.
306184610Salfred */
307184610Salfredstruct usb2_xfer_flags {
308184610Salfred	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
309184610Salfred					 * last */
310184610Salfred	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
311184610Salfred	uint8_t	short_frames_ok:1;	/* allow short frames */
312184610Salfred	uint8_t	pipe_bof:1;		/* block pipe on failure */
313184610Salfred	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
314184610Salfred					 * "max_frame_size" */
315184610Salfred	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
316184610Salfred	uint8_t	manual_status:1;	/* non automatic status stage on
317184610Salfred					 * control transfers */
318184610Salfred	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
319184610Salfred					 * be ignored */
320184610Salfred	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
321184610Salfred					 * this USB transfer should be stalled
322184610Salfred					 * before starting this transfer! */
323184610Salfred};
324184610Salfred
325184610Salfred/*
326184610Salfred * The following structure defines a set of internal USB transfer
327184610Salfred * flags.
328184610Salfred */
329184610Salfredstruct usb2_xfer_flags_int {
330184610Salfred	uint16_t control_rem;		/* remainder in bytes */
331184610Salfred
332184610Salfred	uint8_t	open:1;			/* set if USB pipe has been opened */
333184610Salfred	uint8_t	transferring:1;		/* set if an USB transfer is in
334184610Salfred					 * progress */
335184610Salfred	uint8_t	did_dma_delay:1;	/* set if we waited for HW DMA */
336184610Salfred	uint8_t	did_close:1;		/* set if we closed the USB transfer */
337184610Salfred	uint8_t	draining:1;		/* set if we are draining an USB
338184610Salfred					 * transfer */
339184610Salfred	uint8_t	started:1;		/* keeps track of started or stopped */
340184610Salfred	uint8_t	bandwidth_reclaimed:1;
341184610Salfred	uint8_t	control_xfr:1;		/* set if control transfer */
342184610Salfred	uint8_t	control_hdr:1;		/* set if control header should be
343184610Salfred					 * sent */
344184610Salfred	uint8_t	control_act:1;		/* set if control transfer is active */
345184610Salfred
346184610Salfred	uint8_t	short_frames_ok:1;	/* filtered version */
347184610Salfred	uint8_t	short_xfer_ok:1;	/* filtered version */
348190180Sthompsa#if USB_HAVE_BUSDMA
349184610Salfred	uint8_t	bdma_enable:1;		/* filtered version (only set if
350184610Salfred					 * hardware supports DMA) */
351184610Salfred	uint8_t	bdma_no_post_sync:1;	/* set if the USB callback wrapper
352184610Salfred					 * should not do the BUS-DMA post sync
353184610Salfred					 * operation */
354184610Salfred	uint8_t	bdma_setup:1;		/* set if BUS-DMA has been setup */
355190180Sthompsa#endif
356184610Salfred	uint8_t	isochronous_xfr:1;	/* set if isochronous transfer */
357184610Salfred	uint8_t	usb2_mode:1;		/* shadow copy of "udev->usb2_mode" */
358184610Salfred	uint8_t	curr_dma_set:1;		/* used by USB HC/DC driver */
359184610Salfred	uint8_t	can_cancel_immed:1;	/* set if USB transfer can be
360184610Salfred					 * cancelled immediately */
361184610Salfred};
362184610Salfred
363184610Salfred/*
364184610Salfred * The following structure defines the symmetric part of an USB config
365184610Salfred * structure.
366184610Salfred */
367184610Salfredstruct usb2_config_sub {
368184610Salfred	usb2_callback_t *callback;	/* USB transfer callback */
369190181Sthompsa	usb2_frlength_t bufsize;	/* total pipe buffer size in bytes */
370190181Sthompsa	usb2_frcount_t frames;		/* maximum number of USB frames */
371190181Sthompsa	usb2_timeout_t interval;	/* interval in milliseconds */
372184610Salfred#define	USB_DEFAULT_INTERVAL	0
373190181Sthompsa	usb2_timeout_t timeout;		/* transfer timeout in milliseconds */
374184610Salfred	struct usb2_xfer_flags flags;	/* transfer flags */
375184610Salfred};
376184610Salfred
377184610Salfred/*
378184610Salfred * The following structure define an USB configuration, that basically
379184610Salfred * is used when setting up an USB transfer.
380184610Salfred */
381184610Salfredstruct usb2_config {
382184610Salfred	struct usb2_config_sub mh;	/* parameters for USB_MODE_HOST */
383184610Salfred	struct usb2_config_sub md;	/* parameters for USB_MODE_DEVICE */
384184610Salfred	uint8_t	type;			/* pipe type */
385184610Salfred	uint8_t	endpoint;		/* pipe number */
386184610Salfred	uint8_t	direction;		/* pipe direction */
387184610Salfred	uint8_t	ep_index;		/* pipe index match to use */
388184610Salfred	uint8_t	if_index;		/* "ifaces" index to use */
389184610Salfred};
390184610Salfred
391184610Salfred/*
392184610Salfred * The following structure defines an USB transfer.
393184610Salfred */
394184610Salfredstruct usb2_xfer {
395184610Salfred	struct usb2_callout timeout_handle;
396184610Salfred	TAILQ_ENTRY(usb2_xfer) wait_entry;	/* used at various places */
397184610Salfred
398184610Salfred	struct usb2_page_cache *buf_fixup;	/* fixup buffer(s) */
399184610Salfred	struct usb2_xfer_queue *wait_queue;	/* pointer to queue that we
400184610Salfred						 * are waiting on */
401184610Salfred	struct usb2_page *dma_page_ptr;
402184610Salfred	struct usb2_pipe *pipe;		/* our USB pipe */
403187173Sthompsa	struct usb2_xfer_root *xroot;	/* used by HC driver */
404184610Salfred	void   *qh_start[2];		/* used by HC driver */
405184610Salfred	void   *td_start[2];		/* used by HC driver */
406184610Salfred	void   *td_transfer_first;	/* used by HC driver */
407184610Salfred	void   *td_transfer_last;	/* used by HC driver */
408184610Salfred	void   *td_transfer_cache;	/* used by HC driver */
409184610Salfred	void   *priv_sc;		/* device driver data pointer 1 */
410184610Salfred	void   *priv_fifo;		/* device driver data pointer 2 */
411184610Salfred	void   *local_buffer;
412190181Sthompsa	usb2_frlength_t *frlengths;
413184610Salfred	struct usb2_page_cache *frbuffers;
414184610Salfred	usb2_callback_t *callback;
415184610Salfred
416190181Sthompsa	usb2_frlength_t max_hc_frame_size;
417190181Sthompsa	usb2_frlength_t max_data_length;
418190181Sthompsa	usb2_frlength_t sumlen;		/* sum of all lengths in bytes */
419190181Sthompsa	usb2_frlength_t actlen;		/* actual length in bytes */
420190181Sthompsa	usb2_timeout_t timeout;		/* milliseconds */
421184610Salfred#define	USB_NO_TIMEOUT 0
422184610Salfred#define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */
423184610Salfred
424190181Sthompsa	usb2_frcount_t max_frame_count;	/* initial value of "nframes" after
425184610Salfred					 * setup */
426190181Sthompsa	usb2_frcount_t nframes;		/* number of USB frames to transfer */
427190181Sthompsa	usb2_frcount_t aframes;		/* actual number of USB frames
428184610Salfred					 * transferred */
429184610Salfred
430184610Salfred	uint16_t max_packet_size;
431184610Salfred	uint16_t max_frame_size;
432184610Salfred	uint16_t qh_pos;
433184610Salfred	uint16_t isoc_time_complete;	/* in ms */
434190181Sthompsa	usb2_timeout_t interval;	/* milliseconds */
435184610Salfred
436184610Salfred	uint8_t	address;		/* physical USB address */
437184610Salfred	uint8_t	endpoint;		/* physical USB endpoint */
438184610Salfred	uint8_t	max_packet_count;
439184610Salfred	uint8_t	usb2_smask;
440184610Salfred	uint8_t	usb2_cmask;
441184610Salfred	uint8_t	usb2_uframe;
442184610Salfred	uint8_t	usb2_state;
443184610Salfred
444184610Salfred	usb2_error_t error;
445184610Salfred
446184610Salfred	struct usb2_xfer_flags flags;
447184610Salfred	struct usb2_xfer_flags_int flags_int;
448184610Salfred};
449184610Salfred
450184610Salfred/*
451184610Salfred * The following structure keeps information that is used to match
452184610Salfred * against an array of "usb2_device_id" elements.
453184610Salfred */
454184610Salfredstruct usb2_lookup_info {
455184610Salfred	uint16_t idVendor;
456184610Salfred	uint16_t idProduct;
457184610Salfred	uint16_t bcdDevice;
458184610Salfred	uint8_t	bDeviceClass;
459184610Salfred	uint8_t	bDeviceSubClass;
460184610Salfred	uint8_t	bDeviceProtocol;
461184610Salfred	uint8_t	bInterfaceClass;
462184610Salfred	uint8_t	bInterfaceSubClass;
463184610Salfred	uint8_t	bInterfaceProtocol;
464184610Salfred	uint8_t	bIfaceIndex;
465184610Salfred	uint8_t	bIfaceNum;
466184610Salfred	uint8_t	bConfigIndex;
467184610Salfred	uint8_t	bConfigNum;
468184610Salfred};
469184610Salfred
470184610Salfred/* Structure used by probe and attach */
471184610Salfred
472184610Salfredstruct usb2_attach_arg {
473184610Salfred	struct usb2_lookup_info info;
474184610Salfred	device_t temp_dev;		/* for internal use */
475184610Salfred	const void *driver_info;	/* for internal use */
476184610Salfred	struct usb2_device *device;	/* current device */
477184610Salfred	struct usb2_interface *iface;	/* current interface */
478184610Salfred	uint8_t	usb2_mode;		/* see USB_MODE_XXX */
479184610Salfred	uint8_t	port;
480184610Salfred	uint8_t	use_generic;		/* hint for generic drivers */
481184610Salfred};
482184610Salfred
483184610Salfred/* external variables */
484184610Salfred
485184610SalfredMALLOC_DECLARE(M_USB);
486184610SalfredMALLOC_DECLARE(M_USBDEV);
487184610SalfredMALLOC_DECLARE(M_USBHC);
488184610Salfred
489184610Salfredextern struct mtx usb2_ref_lock;
490184610Salfred
491184610Salfred/* typedefs */
492184610Salfred
493184610Salfredtypedef struct malloc_type *usb2_malloc_type;
494184610Salfred
495184610Salfred/* prototypes */
496184610Salfred
497184610Salfredconst char *usb2_errstr(usb2_error_t error);
498185948Sthompsastruct usb2_config_descriptor *usb2_get_config_descriptor(
499185948Sthompsa	    struct usb2_device *udev);
500185948Sthompsastruct usb2_device_descriptor *usb2_get_device_descriptor(
501185948Sthompsa	    struct usb2_device *udev);
502185948Sthompsastruct usb2_interface *usb2_get_iface(struct usb2_device *udev,
503185948Sthompsa	    uint8_t iface_index);
504185948Sthompsastruct usb2_interface_descriptor *usb2_get_interface_descriptor(
505185948Sthompsa	    struct usb2_interface *iface);
506185948Sthompsauint8_t	usb2_clear_stall_callback(struct usb2_xfer *xfer1,
507185948Sthompsa	    struct usb2_xfer *xfer2);
508184610Salfreduint8_t	usb2_get_interface_altindex(struct usb2_interface *iface);
509185948Sthompsausb2_error_t usb2_set_alt_interface_index(struct usb2_device *udev,
510185948Sthompsa	    uint8_t iface_index, uint8_t alt_index);
511188411Sthompsauint8_t	usb2_get_mode(struct usb2_device *udev);
512184610Salfreduint8_t	usb2_get_speed(struct usb2_device *udev);
513186730Salfreduint32_t usb2_get_isoc_fps(struct usb2_device *udev);
514185948Sthompsausb2_error_t usb2_transfer_setup(struct usb2_device *udev,
515185948Sthompsa	    const uint8_t *ifaces, struct usb2_xfer **pxfer,
516185948Sthompsa	    const struct usb2_config *setup_start, uint16_t n_setup,
517185948Sthompsa	    void *priv_sc, struct mtx *priv_mtx);
518185948Sthompsavoid	usb2_set_frame_data(struct usb2_xfer *xfer, void *ptr,
519190181Sthompsa	    usb2_frcount_t frindex);
520190181Sthompsavoid	usb2_set_frame_offset(struct usb2_xfer *xfer, usb2_frlength_t offset,
521190181Sthompsa	    usb2_frcount_t frindex);
522184610Salfredvoid	usb2_start_hardware(struct usb2_xfer *xfer);
523184610Salfredvoid	usb2_transfer_clear_stall(struct usb2_xfer *xfer);
524184610Salfredvoid	usb2_transfer_drain(struct usb2_xfer *xfer);
525184610Salfredvoid	usb2_transfer_set_stall(struct usb2_xfer *xfer);
526188600Sthompsauint8_t	usb2_transfer_pending(struct usb2_xfer *xfer);
527184610Salfredvoid	usb2_transfer_start(struct usb2_xfer *xfer);
528184610Salfredvoid	usb2_transfer_stop(struct usb2_xfer *xfer);
529184610Salfredvoid	usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup);
530185948Sthompsavoid	usb2_set_parent_iface(struct usb2_device *udev, uint8_t iface_index,
531185948Sthompsa	    uint8_t parent_index);
532184610Salfreduint8_t	usb2_get_bus_index(struct usb2_device *udev);
533184610Salfreduint8_t	usb2_get_device_index(struct usb2_device *udev);
534186730Salfredvoid	usb2_set_power_mode(struct usb2_device *udev, uint8_t power_mode);
535184610Salfred
536184610Salfred#endif					/* _USB2_CORE_H_ */
537