1142399Swpaul/*-
2142399Swpaul * Copyright (c) 2003
3142399Swpaul *      Bill Paul <wpaul@windriver.com>.  All rights reserved.
4142399Swpaul *
5142399Swpaul * Redistribution and use in source and binary forms, with or without
6142399Swpaul * modification, are permitted provided that the following conditions
7142399Swpaul * are met:
8142399Swpaul * 1. Redistributions of source code must retain the above copyright
9142399Swpaul *    notice, this list of conditions and the following disclaimer.
10142399Swpaul * 2. Redistributions in binary form must reproduce the above copyright
11142399Swpaul *    notice, this list of conditions and the following disclaimer in the
12142399Swpaul *    documentation and/or other materials provided with the distribution.
13142399Swpaul * 3. All advertising materials mentioning features or use of this software
14142399Swpaul *    must display the following acknowledgement:
15142399Swpaul *      This product includes software developed by Bill Paul.
16142399Swpaul * 4. Neither the name of the author nor the names of any co-contributors
17142399Swpaul *    may be used to endorse or promote products derived from this software
18142399Swpaul *    without specific prior written permission.
19142399Swpaul *
20142399Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21142399Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22142399Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23142399Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24142399Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25142399Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26142399Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27142399Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28142399Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29142399Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30142399Swpaul * THE POSSIBILITY OF SUCH DAMAGE.
31142399Swpaul *
32142399Swpaul * $FreeBSD$
33142399Swpaul */
34142399Swpaul
35142399Swpaul#ifndef _USBD_VAR_H_
36142399Swpaul#define _USBD_VAR_H_
37142399Swpaul
38186507Sweongyo#define	IOCTL_INTERNAL_USB_SUBMIT_URB			0x00220003
39142399Swpaul
40186507Sweongyo#define	URB_FUNCTION_SELECT_CONFIGURATION		0x0000
41189488Sweongyo#define	URB_FUNCTION_ABORT_PIPE				0x0002
42186507Sweongyo#define	URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER		0x0009
43186507Sweongyo#define	URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE		0x000B
44186507Sweongyo#define	URB_FUNCTION_VENDOR_DEVICE			0x0017
45186507Sweongyo#define	URB_FUNCTION_VENDOR_INTERFACE			0x0018
46186507Sweongyo#define	URB_FUNCTION_VENDOR_ENDPOINT			0x0019
47186507Sweongyo#define	URB_FUNCTION_CLASS_DEVICE			0x001A
48186507Sweongyo#define	URB_FUNCTION_CLASS_INTERFACE			0x001B
49186507Sweongyo#define	URB_FUNCTION_CLASS_ENDPOINT			0x001C
50186507Sweongyo#define	URB_FUNCTION_CLASS_OTHER			0x001F
51186507Sweongyo#define	URB_FUNCTION_VENDOR_OTHER			0x0020
52186507Sweongyo
53186507Sweongyo#define	USBD_STATUS_SUCCESS				0x00000000
54186507Sweongyo#define	USBD_STATUS_CANCELED				0x00010000
55186507Sweongyo#define	USBD_STATUS_PENDING				0x40000000
56186507Sweongyo#define	USBD_STATUS_NO_MEMORY				0x80000100
57186507Sweongyo#define	USBD_STATUS_REQUEST_FAILED			0x80000500
58186507Sweongyo#define	USBD_STATUS_INVALID_PIPE_HANDLE			0x80000600
59186507Sweongyo#define	USBD_STATUS_ERROR_SHORT_TRANSFER		0x80000900
60186507Sweongyo#define	USBD_STATUS_CRC					0xC0000001
61186507Sweongyo#define	USBD_STATUS_BTSTUFF				0xC0000002
62186507Sweongyo#define	USBD_STATUS_DATA_TOGGLE_MISMATCH		0xC0000003
63186507Sweongyo#define	USBD_STATUS_STALL_PID				0xC0000004
64186507Sweongyo#define	USBD_STATUS_DEV_NOT_RESPONDING			0xC0000005
65186507Sweongyo#define	USBD_STATUS_PID_CHECK_FAILURE			0xC0000006
66186507Sweongyo#define	USBD_STATUS_UNEXPECTED_PID			0xC0000007
67186507Sweongyo#define	USBD_STATUS_DATA_OVERRUN			0xC0000008
68186507Sweongyo#define	USBD_STATUS_DATA_UNDERRUN			0xC0000009
69186507Sweongyo#define	USBD_STATUS_RESERVED1				0xC000000A
70186507Sweongyo#define	USBD_STATUS_RESERVED2				0xC000000B
71186507Sweongyo#define	USBD_STATUS_BUFFER_OVERRUN			0xC000000C
72186507Sweongyo#define	USBD_STATUS_BUFFER_UNDERRUN			0xC000000D
73186507Sweongyo#define	USBD_STATUS_NOT_ACCESSED			0xC000000F
74186507Sweongyo#define	USBD_STATUS_FIFO				0xC0000010
75186507Sweongyo#define	USBD_STATUS_XACT_ERROR				0xC0000011
76186507Sweongyo#define	USBD_STATUS_BABBLE_DETECTED			0xC0000012
77186507Sweongyo#define	USBD_STATUS_DATA_BUFFER_ERROR			0xC0000013
78186507Sweongyo#define	USBD_STATUS_NOT_SUPPORTED			0xC0000E00
79186507Sweongyo#define	USBD_STATUS_TIMEOUT				0xC0006000
80186507Sweongyo#define	USBD_STATUS_DEVICE_GONE				0xC0007000
81186507Sweongyo
82186507Sweongyostruct usbd_urb_header {
83186507Sweongyo	uint16_t		uuh_len;
84186507Sweongyo	uint16_t		uuh_func;
85186507Sweongyo	int32_t			uuh_status;
86186507Sweongyo	void			*uuh_handle;
87186507Sweongyo	uint32_t		uuh_flags;
88186507Sweongyo};
89186507Sweongyo
90186507Sweongyoenum usbd_pipe_type {
91186507Sweongyo	UsbdPipeTypeControl	= UE_CONTROL,
92186507Sweongyo	UsbdPipeTypeIsochronous	= UE_ISOCHRONOUS,
93186507Sweongyo	UsbdPipeTypeBulk	= UE_BULK,
94186507Sweongyo	UsbdPipeTypeInterrupt	= UE_INTERRUPT
95186507Sweongyo};
96186507Sweongyo
97186507Sweongyostruct usbd_pipe_information {
98186507Sweongyo	uint16_t		upi_maxpktsize;
99186507Sweongyo	uint8_t			upi_epaddr;
100186507Sweongyo	uint8_t			upi_interval;
101186507Sweongyo	enum usbd_pipe_type	upi_type;
102186507Sweongyo	usb_endpoint_descriptor_t *upi_handle;
103186507Sweongyo	uint32_t		upi_maxtxsize;
104186507Sweongyo#define	USBD_DEFAULT_MAXIMUM_TRANSFER_SIZE		PAGE_SIZE
105186507Sweongyo	uint32_t		upi_flags;
106186507Sweongyo};
107186507Sweongyo
108186507Sweongyostruct usbd_interface_information {
109186507Sweongyo	uint16_t		uii_len;
110186507Sweongyo	uint8_t			uii_intfnum;
111186507Sweongyo	uint8_t			uii_altset;
112186507Sweongyo	uint8_t			uii_intfclass;
113186507Sweongyo	uint8_t			uii_intfsubclass;
114186507Sweongyo	uint8_t			uii_intfproto;
115186507Sweongyo	uint8_t			uii_reserved;
116186507Sweongyo	void			*uii_handle;
117186507Sweongyo	uint32_t		uii_numeps;
118186507Sweongyo	struct usbd_pipe_information uii_pipes[1];
119186507Sweongyo};
120186507Sweongyo
121186507Sweongyostruct usbd_urb_select_interface {
122186507Sweongyo	struct usbd_urb_header	usi_hdr;
123189488Sweongyo	void			*usi_handle;
124189488Sweongyo	struct usbd_interface_information uusi_intf;
125186507Sweongyo};
126186507Sweongyo
127186507Sweongyostruct usbd_urb_select_configuration {
128186507Sweongyo	struct usbd_urb_header	usc_hdr;
129189488Sweongyo	usb_config_descriptor_t *usc_conf;
130189488Sweongyo	void			*usc_handle;
131189488Sweongyo	struct usbd_interface_information usc_intf;
132186507Sweongyo};
133186507Sweongyo
134189488Sweongyostruct usbd_urb_pipe_request {
135189488Sweongyo	struct usbd_urb_header		upr_hdr;
136189488Sweongyo	usb_endpoint_descriptor_t	*upr_handle;
137189488Sweongyo};
138189488Sweongyo
139186507Sweongyostruct usbd_hcd_area {
140186507Sweongyo	void			*reserved8[8];
141186507Sweongyo};
142186507Sweongyo
143186507Sweongyostruct usbd_urb_bulk_or_intr_transfer {
144186507Sweongyo	struct usbd_urb_header	ubi_hdr;
145189488Sweongyo	usb_endpoint_descriptor_t *ubi_epdesc;
146189488Sweongyo	uint32_t		ubi_trans_flags;
147186507Sweongyo#define	USBD_SHORT_TRANSFER_OK		0x00000002
148189488Sweongyo	uint32_t		ubi_trans_buflen;
149189488Sweongyo	void			*ubi_trans_buf;
150189488Sweongyo	struct mdl		*ubi_mdl;
151189488Sweongyo	union usbd_urb		*ubi_urblink;
152189488Sweongyo	struct usbd_hcd_area	ubi_hca;
153186507Sweongyo};
154186507Sweongyo
155186507Sweongyostruct usbd_urb_control_descriptor_request {
156186507Sweongyo	struct usbd_urb_header	ucd_hdr;
157189488Sweongyo	void			*ucd_reserved0;
158189488Sweongyo	uint32_t		ucd_reserved1;
159189488Sweongyo	uint32_t		ucd_trans_buflen;
160189488Sweongyo	void			*ucd_trans_buf;
161189488Sweongyo	struct mdl		*ucd_mdl;
162189488Sweongyo	union nt_urb		*ucd_urblink;
163189488Sweongyo	struct usbd_hcd_area	ucd_hca;
164189488Sweongyo	uint16_t		ucd_reserved2;
165189488Sweongyo	uint8_t			ucd_idx;
166189488Sweongyo	uint8_t			ucd_desctype;
167189488Sweongyo	uint16_t		ucd_langid;
168189488Sweongyo	uint16_t		ucd_reserved3;
169186507Sweongyo};
170186507Sweongyo
171186507Sweongyostruct usbd_urb_vendor_or_class_request {
172186507Sweongyo	struct usbd_urb_header	uvc_hdr;
173189488Sweongyo	void			*uvc_reserved0;
174189488Sweongyo	uint32_t		uvc_trans_flags;
175186507Sweongyo#define	USBD_TRANSFER_DIRECTION_IN	1
176189488Sweongyo	uint32_t		uvc_trans_buflen;
177189488Sweongyo	void			*uvc_trans_buf;
178189488Sweongyo	struct mdl		*uvc_mdl;
179189488Sweongyo	union nt_urb		*uvc_urblink;
180186507Sweongyo	struct usbd_hcd_area	uvc_hca;
181189488Sweongyo	uint8_t			uvc_reserved1;
182189488Sweongyo	uint8_t			uvc_req;
183189488Sweongyo	uint16_t		uvc_value;
184189488Sweongyo	uint16_t		uvc_idx;
185189488Sweongyo	uint16_t		uvc_reserved2;
186186507Sweongyo};
187186507Sweongyo
188186507Sweongyostruct usbd_interface_list_entry {
189186507Sweongyo	usb_interface_descriptor_t		*uil_intfdesc;
190186507Sweongyo	struct usbd_interface_information	*uil_intf;
191186507Sweongyo};
192186507Sweongyo
193186507Sweongyounion usbd_urb {
194186507Sweongyo	struct usbd_urb_header			uu_hdr;
195189488Sweongyo	struct usbd_urb_select_configuration	uu_selconf;
196189488Sweongyo	struct usbd_urb_bulk_or_intr_transfer	uu_bulkintr;
197189488Sweongyo	struct usbd_urb_control_descriptor_request	uu_ctldesc;
198189488Sweongyo	struct usbd_urb_vendor_or_class_request	uu_vcreq;
199189488Sweongyo	struct usbd_urb_pipe_request		uu_pipe;
200186507Sweongyo};
201186507Sweongyo
202186507Sweongyo#define	USBD_URB_STATUS(urb)	((urb)->uu_hdr.uuh_status)
203186507Sweongyo
204186507Sweongyo#define	USBDI_VERSION		0x00000500
205186507Sweongyo#define	USB_VER_1_1		0x00000110
206186507Sweongyo#define	USB_VER_2_0		0x00000200
207186507Sweongyo
208142399Swpaulstruct usbd_version_info {
209142399Swpaul	uint32_t		uvi_usbdi_vers;
210142399Swpaul	uint32_t		uvi_supported_vers;
211142399Swpaul};
212142399Swpaul
213142399Swpaultypedef struct usbd_version_info usbd_version_info;
214142399Swpaul
215142399Swpaulextern image_patch_table usbd_functbl[];
216142399Swpaul
217142399Swpaul__BEGIN_DECLS
218142399Swpaulextern int usbd_libinit(void);
219142399Swpaulextern int usbd_libfini(void);
220142399Swpaul__END_DECLS
221142399Swpaul
222142399Swpaul#endif /* _USBD_VAR_H_ */
223