1 /*
2  * Copyright (c) 1998 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Lennart Augustsson (lennart@augustsson.net) at
7  * Carlstedt Research & Technology.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *        This product includes software developed by the NetBSD
20  *        Foundation, Inc. and its contributors.
21  * 4. Neither the name of The NetBSD Foundation nor the names of its
22  *    contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 /* Modified by Synopsys, Inc, 12/12/2007 */
39 
40 
41 #ifndef _USB_H_
42 #define _USB_H_
43 #include "basic_types.h"
44 #include "dwc_os.h"
45 #if defined(DWC_WITH_WLAN_OSDEP)
46 #include "osdep_service.h"
47 #else
48 #endif
49 
50 #include "usb_errno.h"
51 #include "diag.h"
52 #include "usb_ch9.h"
53 #include "usb_defs.h"
54 
55 //#define  DWC_HOST_ONLY 1
56 //#define  DWC_DEVICE_ONLY 1
57 
58 #define USB_FAST_HUB_ENUM   1
59 
60 #define	prvStrLen			_strlen
61 /*
62  * The USB records contain some unaligned little-endian word
63  * components.  The U[SG]ETW macros take care of both the alignment
64  * and endian problem and should always be used to access non-byte
65  * values.
66  */
67 typedef u8  uByte;
68 typedef u8  uWord[2];
69 typedef u8  uDWord[4];
70 
71 struct LIST_HEADER {
72 	struct LIST_HEADER *Next, *Prev;
73 };
74 typedef	struct  LIST_HEADER		_LIST;
75 
76 typedef	xSemaphoreHandle				_Sema;
77 typedef	xSemaphoreHandle				_Mutex;
78 typedef	u32								_Lock;
79 
80 #define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
81 #define UCONSTW(x)	{ (x) & 0xff, ((x) >> 8) & 0xff }
82 #define UCONSTDW(x)	{ (x) & 0xff, ((x) >> 8) & 0xff, \
83 			  ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
84 
85 #if 1
86 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
87 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
88 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
89 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
90 		     (w)[1] = (u_int8_t)((v) >> 8), \
91 		     (w)[2] = (u_int8_t)((v) >> 16), \
92 		     (w)[3] = (u_int8_t)((v) >> 24))
93 #else
94 /*
95  * On little-endian machines that can handle unanliged accesses
96  * (e.g. i386) these macros can be replaced by the following.
97  */
98 #define UGETW(w) (*(u_int16_t *)(w))
99 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
100 #define UGETDW(w) (*(u_int32_t *)(w))
101 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
102 #endif
103 
104 /*
105  * Macros for accessing UAS IU fields, which are big-endian
106  */
107 #define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
108 #define IUCONSTW(x)	{ ((x) >> 8) & 0xff, (x) & 0xff }
109 #define IUCONSTDW(x)	{ ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
110 			((x) >> 8) & 0xff, (x) & 0xff }
111 #define IUGETW(w) (((w)[0] << 8) | (w)[1])
112 #define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
113 #define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
114 #define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
115 		      (w)[1] = (u_int8_t)((v) >> 16), \
116 		      (w)[2] = (u_int8_t)((v) >> 8), \
117 		      (w)[3] = (u_int8_t)(v))
118 
119 //#define UPACKED __attribute__((__packed__))
120 #define UPACKED
121 typedef struct {
122 	uByte		bmRequestType;
123 	uByte		bRequest;
124 	uWord		wValue;
125 	uWord		wIndex;
126 	uWord		wLength;
127 } UPACKED usb_device_request_t;
128 
129 #define UT_GET_DIR(a) ((a) & 0x80)
130 #define UT_WRITE		0x00
131 #define UT_READ			0x80
132 
133 #define UT_GET_TYPE(a) ((a) & 0x60)
134 #define UT_STANDARD		0x00
135 #define UT_CLASS		0x20
136 #define UT_VENDOR		0x40
137 
138 #define UT_GET_RECIPIENT(a) ((a) & 0x1f)
139 #define UT_DEVICE		0x00
140 #define UT_INTERFACE		0x01
141 #define UT_ENDPOINT		0x02
142 #define UT_OTHER		0x03
143 
144 #define UT_READ_DEVICE		(UT_READ  | UT_STANDARD | UT_DEVICE)
145 #define UT_READ_INTERFACE	(UT_READ  | UT_STANDARD | UT_INTERFACE)
146 #define UT_READ_ENDPOINT	(UT_READ  | UT_STANDARD | UT_ENDPOINT)
147 #define UT_WRITE_DEVICE		(UT_WRITE | UT_STANDARD | UT_DEVICE)
148 #define UT_WRITE_INTERFACE	(UT_WRITE | UT_STANDARD | UT_INTERFACE)
149 #define UT_WRITE_ENDPOINT	(UT_WRITE | UT_STANDARD | UT_ENDPOINT)
150 #define UT_READ_CLASS_DEVICE	(UT_READ  | UT_CLASS | UT_DEVICE)
151 #define UT_READ_CLASS_INTERFACE	(UT_READ  | UT_CLASS | UT_INTERFACE)
152 #define UT_READ_CLASS_OTHER	(UT_READ  | UT_CLASS | UT_OTHER)
153 #define UT_READ_CLASS_ENDPOINT	(UT_READ  | UT_CLASS | UT_ENDPOINT)
154 #define UT_WRITE_CLASS_DEVICE	(UT_WRITE | UT_CLASS | UT_DEVICE)
155 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
156 #define UT_WRITE_CLASS_OTHER	(UT_WRITE | UT_CLASS | UT_OTHER)
157 #define UT_WRITE_CLASS_ENDPOINT	(UT_WRITE | UT_CLASS | UT_ENDPOINT)
158 #define UT_READ_VENDOR_DEVICE	(UT_READ  | UT_VENDOR | UT_DEVICE)
159 #define UT_READ_VENDOR_INTERFACE (UT_READ  | UT_VENDOR | UT_INTERFACE)
160 #define UT_READ_VENDOR_OTHER	(UT_READ  | UT_VENDOR | UT_OTHER)
161 #define UT_READ_VENDOR_ENDPOINT	(UT_READ  | UT_VENDOR | UT_ENDPOINT)
162 #define UT_WRITE_VENDOR_DEVICE	(UT_WRITE | UT_VENDOR | UT_DEVICE)
163 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
164 #define UT_WRITE_VENDOR_OTHER	(UT_WRITE | UT_VENDOR | UT_OTHER)
165 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
166 
167 /* Requests */
168 #define UR_GET_STATUS		0x00
169 #define  USTAT_STANDARD_STATUS  0x00
170 #define  WUSTAT_WUSB_FEATURE    0x01
171 #define  WUSTAT_CHANNEL_INFO    0x02
172 #define  WUSTAT_RECEIVED_DATA   0x03
173 #define  WUSTAT_MAS_AVAILABILITY 0x04
174 #define  WUSTAT_CURRENT_TRANSMIT_POWER 0x05
175 #define UR_CLEAR_FEATURE	0x01
176 #define UR_SET_FEATURE		0x03
177 #define UR_SET_AND_TEST_FEATURE 0x0c
178 #define UR_SET_ADDRESS		0x05
179 #define UR_GET_DESCRIPTOR	0x06
180 #define  UDESC_DEVICE		0x01
181 #define  UDESC_CONFIG		0x02
182 #define  UDESC_STRING		0x03
183 #define  UDESC_INTERFACE	0x04
184 #define  UDESC_ENDPOINT		0x05
185 #define  UDESC_SS_USB_COMPANION	0x30
186 #define  UDESC_DEVICE_QUALIFIER	0x06
187 #define  UDESC_OTHER_SPEED_CONFIGURATION 0x07
188 #define  UDESC_INTERFACE_POWER	0x08
189 #define  UDESC_OTG		0x09
190 #define  WUDESC_SECURITY	0x0c
191 #define  WUDESC_KEY		0x0d
192 #define   WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
193 #define   WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
194 #define    WUD_KEY_TYPE_ASSOC    0x01
195 #define    WUD_KEY_TYPE_GTK      0x02
196 #define   WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
197 #define    WUD_KEY_ORIGIN_HOST   0x00
198 #define    WUD_KEY_ORIGIN_DEVICE 0x01
199 #define  WUDESC_ENCRYPTION_TYPE	0x0e
200 #define  WUDESC_BOS		0x0f
201 #define  WUDESC_DEVICE_CAPABILITY 0x10
202 #define  WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
203 #define  UDESC_BOS		0x0f
204 #define  UDESC_DEVICE_CAPABILITY 0x10
205 #define  UDESC_CS_DEVICE	0x21	/* class specific */
206 #define  UDESC_CS_CONFIG	0x22
207 #define  UDESC_CS_STRING	0x23
208 #define  UDESC_CS_INTERFACE	0x24
209 #define  UDESC_CS_ENDPOINT	0x25
210 #define  UDESC_HUB		0x29
211 #define UR_SET_DESCRIPTOR	0x07
212 #define UR_GET_CONFIG		0x08
213 #define UR_SET_CONFIG		0x09
214 #define UR_GET_INTERFACE	0x0a
215 #define UR_SET_INTERFACE	0x0b
216 #define UR_SYNCH_FRAME		0x0c
217 #define WUR_SET_ENCRYPTION      0x0d
218 #define WUR_GET_ENCRYPTION	0x0e
219 #define WUR_SET_HANDSHAKE	0x0f
220 #define WUR_GET_HANDSHAKE	0x10
221 #define WUR_SET_CONNECTION	0x11
222 #define WUR_SET_SECURITY_DATA	0x12
223 #define WUR_GET_SECURITY_DATA	0x13
224 #define WUR_SET_WUSB_DATA	0x14
225 #define  WUDATA_DRPIE_INFO	0x01
226 #define  WUDATA_TRANSMIT_DATA	0x02
227 #define  WUDATA_TRANSMIT_PARAMS	0x03
228 #define  WUDATA_RECEIVE_PARAMS	0x04
229 #define  WUDATA_TRANSMIT_POWER	0x05
230 #define WUR_LOOPBACK_DATA_WRITE	0x15
231 #define WUR_LOOPBACK_DATA_READ	0x16
232 #define WUR_SET_INTERFACE_DS	0x17
233 
234 /* Feature numbers */
235 #define UF_ENDPOINT_HALT	0
236 #define UF_DEVICE_REMOTE_WAKEUP	1
237 #define UF_TEST_MODE		2
238 #define UF_DEVICE_B_HNP_ENABLE	3
239 #define UF_DEVICE_A_HNP_SUPPORT	4
240 #define UF_DEVICE_A_ALT_HNP_SUPPORT 5
241 #define WUF_WUSB		3
242 #define  WUF_TX_DRPIE		0x0
243 #define  WUF_DEV_XMIT_PACKET	0x1
244 #define  WUF_COUNT_PACKETS	0x2
245 #define  WUF_CAPTURE_PACKETS	0x3
246 #define UF_FUNCTION_SUSPEND	0
247 #define UF_U1_ENABLE		48
248 #define UF_U2_ENABLE		49
249 #define UF_LTM_ENABLE		50
250 
251 /* Class requests from the USB 2.0 hub spec, table 11-15 */
252 #define UCR_CLEAR_HUB_FEATURE		(0x2000 | UR_CLEAR_FEATURE)
253 #define UCR_CLEAR_PORT_FEATURE		(0x2300 | UR_CLEAR_FEATURE)
254 #define UCR_GET_HUB_DESCRIPTOR		(0xa000 | UR_GET_DESCRIPTOR)
255 #define UCR_GET_HUB_STATUS		(0xa000 | UR_GET_STATUS)
256 #define UCR_GET_PORT_STATUS		(0xa300 | UR_GET_STATUS)
257 #define UCR_SET_HUB_FEATURE		(0x2000 | UR_SET_FEATURE)
258 #define UCR_SET_PORT_FEATURE		(0x2300 | UR_SET_FEATURE)
259 #define UCR_SET_AND_TEST_PORT_FEATURE	(0xa300 | UR_SET_AND_TEST_FEATURE)
260 
261 
262 
263 
264 
265 
266 
267 
268 #define USB_MAX_STRING_LEN 128
269 #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
270 
271 /* Hub specific request */
272 #define UR_GET_BUS_STATE	0x02
273 #define UR_CLEAR_TT_BUFFER	0x08
274 #define UR_RESET_TT		0x09
275 #define UR_GET_TT_STATE		0x0a
276 #define UR_STOP_TT		0x0b
277 
278 /* Hub features */
279 #define UHF_C_HUB_LOCAL_POWER	0
280 #define UHF_C_HUB_OVER_CURRENT	1
281 #define UHF_PORT_CONNECTION	0
282 #define UHF_PORT_ENABLE		1
283 #define UHF_PORT_SUSPEND	2
284 #define UHF_PORT_OVER_CURRENT	3
285 #define UHF_PORT_RESET		4
286 #define UHF_PORT_L1		5
287 #define UHF_PORT_POWER		8
288 #define UHF_PORT_LOW_SPEED	9
289 #define UHF_PORT_HIGH_SPEED	10
290 #define UHF_C_PORT_CONNECTION	16
291 #define UHF_C_PORT_ENABLE	17
292 #define UHF_C_PORT_SUSPEND	18
293 #define UHF_C_PORT_OVER_CURRENT	19
294 #define UHF_C_PORT_RESET	20
295 #define UHF_C_PORT_L1		23
296 #define UHF_PORT_TEST		21
297 #define UHF_PORT_INDICATOR	22
298 
299 
300 
301 
302 typedef struct {
303 	uByte		bLength;
304 	uByte		bDescriptorType;
305 	uWord		bcdUSB;
306 	uByte		bDeviceClass;
307 	uByte		bDeviceSubClass;
308 	uByte		bDeviceProtocol;
309 	uByte		bMaxPacketSize0;
310 	uByte		bNumConfigurations;
311 	uByte		bReserved;
312 } UPACKED usb_device_qualifier_t;
313 #define USB_DEVICE_QUALIFIER_SIZE 10
314 
315 typedef struct {
316 	uByte		bLength;
317 	uByte		bDescriptorType;
318 	uByte		bmAttributes;
319 #define UOTG_SRP	0x01
320 #define UOTG_HNP	0x02
321 } UPACKED usb_otg_descriptor_t;
322 
323 /* OTG feature selectors */
324 #define UOTG_B_HNP_ENABLE	3
325 #define UOTG_A_HNP_SUPPORT	4
326 #define UOTG_A_ALT_HNP_SUPPORT	5
327 
328 typedef struct {
329 	uWord		wStatus;
330 /* Device status flags */
331 #define UDS_SELF_POWERED		0x0001
332 #define UDS_REMOTE_WAKEUP		0x0002
333 /* Endpoint status flags */
334 #define UES_HALT			0x0001
335 } UPACKED usb_status_t;
336 
337 typedef struct {
338 	uWord		wHubStatus;
339 #define UHS_LOCAL_POWER			0x0001
340 #define UHS_OVER_CURRENT		0x0002
341 	uWord		wHubChange;
342 } UPACKED usb_hub_status_t;
343 
344 typedef struct {
345 	uWord		wPortStatus;
346 #define UPS_CURRENT_CONNECT_STATUS	0x0001
347 #define UPS_PORT_ENABLED		0x0002
348 #define UPS_SUSPEND			0x0004
349 #define UPS_OVERCURRENT_INDICATOR	0x0008
350 #define UPS_RESET			0x0010
351 #define UPS_PORT_POWER			0x0100
352 #define UPS_LOW_SPEED			0x0200
353 #define UPS_HIGH_SPEED			0x0400
354 #define UPS_PORT_TEST			0x0800
355 #define UPS_PORT_INDICATOR		0x1000
356 	uWord		wPortChange;
357 #define UPS_C_CONNECT_STATUS		0x0001
358 #define UPS_C_PORT_ENABLED		0x0002
359 #define UPS_C_SUSPEND			0x0004
360 #define UPS_C_OVERCURRENT_INDICATOR	0x0008
361 #define UPS_C_PORT_RESET		0x0010
362 } UPACKED usb_port_status_t;
363 
364 
365 /* Device class codes */
366 #define UDCLASS_IN_INTERFACE	0x00
367 #define UDCLASS_COMM		0x02
368 #define UDCLASS_HUB		0x09
369 #define  UDSUBCLASS_HUB		0x00
370 #define  UDPROTO_FSHUB		0x00
371 #define  UDPROTO_HSHUBSTT	0x01
372 #define  UDPROTO_HSHUBMTT	0x02
373 #define UDCLASS_DIAGNOSTIC	0xdc
374 #define UDCLASS_WIRELESS	0xe0
375 #define  UDSUBCLASS_RF		0x01
376 #define   UDPROTO_BLUETOOTH	0x01
377 #define UDCLASS_VENDOR		0xff
378 
379 /* Interface class codes */
380 #define UICLASS_UNSPEC		0x00
381 
382 #define UICLASS_AUDIO		0x01
383 #define  UISUBCLASS_AUDIOCONTROL	1
384 #define  UISUBCLASS_AUDIOSTREAM		2
385 #define  UISUBCLASS_MIDISTREAM		3
386 
387 #define UICLASS_CDC		0x02 /* communication */
388 #define  UISUBCLASS_DIRECT_LINE_CONTROL_MODEL	1
389 #define  UISUBCLASS_ABSTRACT_CONTROL_MODEL	2
390 #define  UISUBCLASS_TELEPHONE_CONTROL_MODEL	3
391 #define  UISUBCLASS_MULTICHANNEL_CONTROL_MODEL	4
392 #define  UISUBCLASS_CAPI_CONTROLMODEL		5
393 #define  UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
394 #define  UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
395 #define   UIPROTO_CDC_AT			1
396 
397 #define UICLASS_HID		0x03
398 #define  UISUBCLASS_BOOT	1
399 #define  UIPROTO_BOOT_KEYBOARD	1
400 
401 #define UICLASS_PHYSICAL	0x05
402 
403 #define UICLASS_IMAGE		0x06
404 
405 #define UICLASS_PRINTER		0x07
406 #define  UISUBCLASS_PRINTER	1
407 #define  UIPROTO_PRINTER_UNI	1
408 #define  UIPROTO_PRINTER_BI	2
409 #define  UIPROTO_PRINTER_1284	3
410 
411 #define UICLASS_MASS		0x08
412 #define  UISUBCLASS_RBC		1
413 #define  UISUBCLASS_SFF8020I	2
414 #define  UISUBCLASS_QIC157	3
415 #define  UISUBCLASS_UFI		4
416 #define  UISUBCLASS_SFF8070I	5
417 #define  UISUBCLASS_SCSI	6
418 #define  UIPROTO_MASS_CBI_I	0
419 #define  UIPROTO_MASS_CBI	1
420 #define  UIPROTO_MASS_BBB_OLD	2	/* Not in the spec anymore */
421 #define  UIPROTO_MASS_BBB	80	/* 'P' for the Iomega Zip drive */
422 
423 #define UICLASS_HUB		0x09
424 #define  UISUBCLASS_HUB		0
425 #define  UIPROTO_FSHUB		0
426 #define  UIPROTO_HSHUBSTT	0 /* Yes, same as previous */
427 #define  UIPROTO_HSHUBMTT	1
428 
429 #define UICLASS_CDC_DATA	0x0a
430 #define  UISUBCLASS_DATA		0
431 #define   UIPROTO_DATA_ISDNBRI		0x30    /* Physical iface */
432 #define   UIPROTO_DATA_HDLC		0x31    /* HDLC */
433 #define   UIPROTO_DATA_TRANSPARENT	0x32    /* Transparent */
434 #define   UIPROTO_DATA_Q921M		0x50    /* Management for Q921 */
435 #define   UIPROTO_DATA_Q921		0x51    /* Data for Q921 */
436 #define   UIPROTO_DATA_Q921TM		0x52    /* TEI multiplexer for Q921 */
437 #define   UIPROTO_DATA_V42BIS		0x90    /* Data compression */
438 #define   UIPROTO_DATA_Q931		0x91    /* Euro-ISDN */
439 #define   UIPROTO_DATA_V120		0x92    /* V.24 rate adaption */
440 #define   UIPROTO_DATA_CAPI		0x93    /* CAPI 2.0 commands */
441 #define   UIPROTO_DATA_HOST_BASED	0xfd    /* Host based driver */
442 #define   UIPROTO_DATA_PUF		0xfe    /* see Prot. Unit Func. Desc.*/
443 #define   UIPROTO_DATA_VENDOR		0xff    /* Vendor specific */
444 
445 #define UICLASS_SMARTCARD	0x0b
446 
447 /*#define UICLASS_FIRM_UPD	0x0c*/
448 
449 #define UICLASS_SECURITY	0x0d
450 
451 #define UICLASS_DIAGNOSTIC	0xdc
452 
453 #define UICLASS_WIRELESS	0xe0
454 #define  UISUBCLASS_RF			0x01
455 #define   UIPROTO_BLUETOOTH		0x01
456 
457 #define UICLASS_APPL_SPEC	0xfe
458 #define  UISUBCLASS_FIRMWARE_DOWNLOAD	1
459 #define  UISUBCLASS_IRDA		2
460 #define  UIPROTO_IRDA			0
461 
462 #define UICLASS_VENDOR		0xff
463 
464 #define USB_HUB_MAX_DEPTH 5
465 
466 /*
467  * Minimum time a device needs to be powered down to go through
468  * a power cycle.  XXX Are these time in the spec?
469  */
470 #define USB_POWER_DOWN_TIME	200 /* ms */
471 #define USB_PORT_POWER_DOWN_TIME	100 /* ms */
472 
473 #if 0
474 /* These are the values from the spec. */
475 #define USB_PORT_RESET_DELAY	10  /* ms */
476 #define USB_PORT_ROOT_RESET_DELAY 50  /* ms */
477 #define USB_PORT_RESET_RECOVERY	10  /* ms */
478 #define USB_PORT_POWERUP_DELAY	100 /* ms */
479 #define USB_SET_ADDRESS_SETTLE	2   /* ms */
480 #define USB_RESUME_DELAY	(20*5)  /* ms */
481 #define USB_RESUME_WAIT		10  /* ms */
482 #define USB_RESUME_RECOVERY	10  /* ms */
483 #define USB_EXTRA_POWER_UP_TIME	0   /* ms */
484 #else
485 /* Allow for marginal (i.e. non-conforming) devices. */
486 #define USB_PORT_RESET_DELAY	50  /* ms */
487 #define USB_PORT_ROOT_RESET_DELAY 250  /* ms */
488 #define USB_PORT_RESET_RECOVERY	250  /* ms */
489 #define USB_PORT_POWERUP_DELAY	300 /* ms */
490 #define USB_SET_ADDRESS_SETTLE	10  /* ms */
491 #define USB_RESUME_DELAY	(50*5)  /* ms */
492 #define USB_RESUME_WAIT		50  /* ms */
493 #define USB_RESUME_RECOVERY	50  /* ms */
494 #define USB_EXTRA_POWER_UP_TIME	20  /* ms */
495 #endif
496 
497 #define USB_MIN_POWER		100 /* mA */
498 #define USB_MAX_POWER		500 /* mA */
499 
500 #define USB_BUS_RESET_DELAY	100 /* ms XXX?*/
501 
502 #define USB_UNCONFIG_NO 0
503 #define USB_UNCONFIG_INDEX (-1)
504 
505 /*** ioctl() related stuff ***/
506 
507 struct usb_ctl_request {
508 	int	ucr_addr;
509 	usb_device_request_t ucr_request;
510 	void	*ucr_data;
511 	int	ucr_flags;
512 #define USBD_SHORT_XFER_OK	0x04	/* allow short reads */
513 	int	ucr_actlen;		/* actual length transferred */
514 };
515 
516 struct usb_alt_interface {
517 	int	uai_config_index;
518 	int	uai_interface_index;
519 	int	uai_alt_no;
520 };
521 
522 #define USB_CURRENT_CONFIG_INDEX (-1)
523 #define USB_CURRENT_ALT_INDEX (-1)
524 
525 
526 
527 struct usb_full_desc {
528 	int	ufd_config_index;
529 	u16 ufd_size;
530 	u8  *ufd_data;
531 };
532 
533 
534 struct usb_ctl_report_desc {
535 	int	ucrd_size;
536 	u8	ucrd_data[1024];	/* filled data size will vary */
537 };
538 
539 typedef struct { u32 cookie; } usb_event_cookie_t;
540 
541 #define USB_MAX_DEVNAMES 4
542 #define USB_MAX_DEVNAMELEN 16
543 struct usb_device_info {
544 	u8	udi_bus;
545 	u8	udi_addr;	/* device address */
546 	usb_event_cookie_t udi_cookie;
547 	char		udi_product[USB_MAX_STRING_LEN];
548 	char		udi_vendor[USB_MAX_STRING_LEN];
549 	char		udi_release[8];
550 	u16	udi_productNo;
551 	u16	udi_vendorNo;
552 	u16	udi_releaseNo;
553 	u8	udi_class;
554 	u8	udi_subclass;
555 	u8	udi_protocol;
556 	u8	udi_config;
557 	u8	udi_speed;
558 #if 0
559 #define USB_SPEED_UNKNOWN	0
560 #define USB_SPEED_LOW		1
561 #define USB_SPEED_FULL		2
562 #define USB_SPEED_HIGH		3
563 #define USB_SPEED_VARIABLE	4
564 #define USB_SPEED_SUPER		5
565 #endif
566 	int		udi_power;	/* power consumption in mA, 0 if selfpowered */
567 	int		udi_nports;
568 	char		udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
569 	u8	udi_ports[16];/* hub only: addresses of devices on ports */
570 #define USB_PORT_ENABLED 0xff
571 #define USB_PORT_SUSPENDED 0xfe
572 #define USB_PORT_POWERED 0xfd
573 #define USB_PORT_DISABLED 0xfc
574 };
575 
576 struct usb_ctl_report {
577 	int	ucr_report;
578 	u8	ucr_data[1024];	/* filled data size will vary */
579 };
580 
581 struct usb_device_stats {
582 	u32	uds_requests[4];	/* indexed by transfer type UE_* */
583 };
584 
585 #define WUSB_MIN_IE			0x80
586 #define WUSB_WCTA_IE			0x80
587 #define WUSB_WCONNECTACK_IE		0x81
588 #define WUSB_WHOSTINFO_IE		0x82
589 #define  WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
590 #define   WUHI_CA_RECONN		0x00
591 #define   WUHI_CA_LIMITED		0x01
592 #define   WUHI_CA_ALL			0x03
593 #define  WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
594 #define WUSB_WCHCHANGEANNOUNCE_IE	0x83
595 #define WUSB_WDEV_DISCONNECT_IE		0x84
596 #define WUSB_WHOST_DISCONNECT_IE	0x85
597 #define WUSB_WRELEASE_CHANNEL_IE	0x86
598 #define WUSB_WWORK_IE			0x87
599 #define WUSB_WCHANNEL_STOP_IE		0x88
600 #define WUSB_WDEV_KEEPALIVE_IE		0x89
601 #define WUSB_WISOCH_DISCARD_IE		0x8A
602 #define WUSB_WRESETDEVICE_IE		0x8B
603 #define WUSB_WXMIT_PACKET_ADJUST_IE	0x8C
604 #define WUSB_MAX_IE			0x8C
605 
606 /* Device Notification Types */
607 
608 #define WUSB_DN_MIN			0x01
609 #define WUSB_DN_CONNECT			0x01
610 # define WUSB_DA_OLDCONN	0x00
611 # define WUSB_DA_NEWCONN	0x01
612 # define WUSB_DA_SELF_BEACON	0x02
613 # define WUSB_DA_DIR_BEACON	0x04
614 # define WUSB_DA_NO_BEACON	0x06
615 #define WUSB_DN_DISCONNECT		0x02
616 #define WUSB_DN_EPRDY			0x03
617 #define WUSB_DN_MASAVAILCHANGED		0x04
618 #define WUSB_DN_REMOTEWAKEUP		0x05
619 #define WUSB_DN_SLEEP			0x06
620 #define WUSB_DN_ALIVE			0x07
621 #define WUSB_DN_MAX			0x07
622 
623 
624 /* WUSB Handshake Data.  Used during the SET/GET HANDSHAKE requests */
625 typedef struct wusb_hndshk_data {
626 	uByte bMessageNumber;
627 	uByte bStatus;
628 	uByte tTKID[3];
629 	uByte bReserved;
630 	uByte CDID[16];
631 	uByte Nonce[16];
632 	uByte MIC[8];
633 } UPACKED wusb_hndshk_data_t;
634 #define WUSB_HANDSHAKE_LEN_FOR_MIC	38
635 
636 /* WUSB Connection Context */
637 typedef struct wusb_conn_context {
638 	uByte CHID [16];
639 	uByte CDID [16];
640 	uByte CK [16];
641 } UPACKED wusb_conn_context_t;
642 
643 /* WUSB Security Descriptor */
644 typedef struct wusb_security_desc {
645 	uByte bLength;
646 	uByte bDescriptorType;
647 	uWord wTotalLength;
648 	uByte bNumEncryptionTypes;
649 } UPACKED wusb_security_desc_t;
650 
651 /* WUSB Encryption Type Descriptor */
652 typedef struct wusb_encrypt_type_desc {
653 	uByte bLength;
654 	uByte bDescriptorType;
655 
656 	uByte bEncryptionType;
657 #define WUETD_UNSECURE		0
658 #define WUETD_WIRED		1
659 #define WUETD_CCM_1		2
660 #define WUETD_RSA_1		3
661 
662 	uByte bEncryptionValue;
663 	uByte bAuthKeyIndex;
664 } UPACKED wusb_encrypt_type_desc_t;
665 
666 /* WUSB Key Descriptor */
667 typedef struct wusb_key_desc {
668 	uByte bLength;
669 	uByte bDescriptorType;
670 	uByte tTKID[3];
671 	uByte bReserved;
672 	uByte KeyData[1];	/* variable length */
673 } UPACKED wusb_key_desc_t;
674 
675 /* WUSB BOS Descriptor (Binary device Object Store) */
676 typedef struct wusb_bos_desc {
677 	uByte bLength;
678 	uByte bDescriptorType;
679 	uWord wTotalLength;
680 	uByte bNumDeviceCaps;
681 } UPACKED wusb_bos_desc_t;
682 
683 #define USB_DEVICE_CAPABILITY_20_EXTENSION	0x02
684 typedef struct usb_dev_cap_20_ext_desc {
685 	uByte bLength;
686 	uByte bDescriptorType;
687 	uByte bDevCapabilityType;
688 #define USB_20_EXT_LPM				0x02
689 	uDWord bmAttributes;
690 } UPACKED usb_dev_cap_20_ext_desc_t;
691 
692 #define USB_DEVICE_CAPABILITY_SS_USB		0x03
693 typedef struct usb_dev_cap_ss_usb {
694 	uByte bLength;
695 	uByte bDescriptorType;
696 	uByte bDevCapabilityType;
697 #define USB_DC_SS_USB_LTM_CAPABLE		0x02
698 	uByte bmAttributes;
699 #define USB_DC_SS_USB_SPEED_SUPPORT_LOW		0x01
700 #define USB_DC_SS_USB_SPEED_SUPPORT_FULL	0x02
701 #define USB_DC_SS_USB_SPEED_SUPPORT_HIGH	0x04
702 #define USB_DC_SS_USB_SPEED_SUPPORT_SS		0x08
703 	uWord wSpeedsSupported;
704 	uByte bFunctionalitySupport;
705 	uByte bU1DevExitLat;
706 	uWord wU2DevExitLat;
707 } UPACKED usb_dev_cap_ss_usb_t;
708 
709 #define USB_DEVICE_CAPABILITY_CONTAINER_ID	0x04
710 typedef struct usb_dev_cap_container_id {
711 	uByte bLength;
712 	uByte bDescriptorType;
713 	uByte bDevCapabilityType;
714 	uByte bReserved;
715 	uByte containerID[16];
716 } UPACKED usb_dev_cap_container_id_t;
717 
718 /* Device Capability Type Codes */
719 #define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
720 
721 /* Device Capability Descriptor */
722 typedef struct wusb_dev_cap_desc {
723 	uByte bLength;
724 	uByte bDescriptorType;
725 	uByte bDevCapabilityType;
726 	uByte caps[1];	/* Variable length */
727 } UPACKED wusb_dev_cap_desc_t;
728 
729 /* Device Capability Descriptor */
730 typedef struct wusb_dev_cap_uwb_desc {
731 	uByte bLength;
732 	uByte bDescriptorType;
733 	uByte bDevCapabilityType;
734 	uByte bmAttributes;
735 	uWord wPHYRates;	/* Bitmap */
736 	uByte bmTFITXPowerInfo;
737 	uByte bmFFITXPowerInfo;
738 	uWord bmBandGroup;
739 	uByte bReserved;
740 } UPACKED wusb_dev_cap_uwb_desc_t;
741 
742 /* Wireless USB Endpoint Companion Descriptor */
743 typedef struct wusb_endpoint_companion_desc {
744 	uByte bLength;
745 	uByte bDescriptorType;
746 	uByte bMaxBurst;
747 	uByte bMaxSequence;
748 	uWord wMaxStreamDelay;
749 	uWord wOverTheAirPacketSize;
750 	uByte bOverTheAirInterval;
751 	uByte bmCompAttributes;
752 } UPACKED wusb_endpoint_companion_desc_t;
753 
754 /* Wireless USB Numeric Association M1 Data Structure */
755 typedef struct wusb_m1_data {
756 	uByte version;
757 	uWord langId;
758 	uByte deviceFriendlyNameLength;
759 	uByte sha_256_m3[32];
760 	uByte deviceFriendlyName[256];
761 } UPACKED wusb_m1_data_t;
762 
763 typedef struct wusb_m2_data {
764 	uByte version;
765 	uWord langId;
766 	uByte hostFriendlyNameLength;
767 	uByte pkh[384];
768 	uByte hostFriendlyName[256];
769 } UPACKED wusb_m2_data_t;
770 
771 typedef struct wusb_m3_data {
772 	uByte pkd[384];
773 	uByte nd;
774 } UPACKED wusb_m3_data_t;
775 
776 typedef struct wusb_m4_data {
777 	uDWord _attributeTypeIdAndLength_1;
778 	uWord  associationTypeId;
779 
780 	uDWord _attributeTypeIdAndLength_2;
781 	uWord  associationSubTypeId;
782 
783 	uDWord _attributeTypeIdAndLength_3;
784 	uDWord length;
785 
786 	uDWord _attributeTypeIdAndLength_4;
787 	uDWord associationStatus;
788 
789 	uDWord _attributeTypeIdAndLength_5;
790 	uByte  chid[16];
791 
792 	uDWord _attributeTypeIdAndLength_6;
793 	uByte  cdid[16];
794 
795 	uDWord _attributeTypeIdAndLength_7;
796 	uByte  bandGroups[2];
797 } UPACKED wusb_m4_data_t;
798 
799 
800 
801 /* Original Host */
802 /* USB directions */
803 #define USB_DIR_OUT           0
804 #define USB_DIR_IN            0x80
805 
806 /* Endpoints */
807 #define USB_ENDPOINT_NUMBER_MASK  0x0f	/* in bEndpointAddress */
808 #define USB_ENDPOINT_DIR_MASK     0x80
809 
810 #define USB_ENDPOINT_XFERTYPE_MASK 0x03	/* in bmAttributes */
811 #define USB_ENDPOINT_XFER_CONTROL  0
812 #define USB_ENDPOINT_XFER_ISOC     1
813 #define USB_ENDPOINT_XFER_BULK     2
814 #define USB_ENDPOINT_XFER_INT      3
815 
816 #define USB_ENDPOINT_HALT		   0	/* IN/OUT will STALL */
817 
818 
819 
820 
821 
822 #if 1
823 #define UGETW(w) ((w)[0] | ((w)[1] << 8))
824 #define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
825 #define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
826 #define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
827 		     (w)[1] = (u_int8_t)((v) >> 8), \
828 		     (w)[2] = (u_int8_t)((v) >> 16), \
829 		     (w)[3] = (u_int8_t)((v) >> 24))
830 #else
831 /*
832  * On little-endian machines that can handle unanliged accesses
833  * (e.g. i386) these macros can be replaced by the following.
834  */
835 #define UGETW(w) (*(u_int16_t *)(w))
836 #define USETW(w,v) (*(u_int16_t *)(w) = (v))
837 #define UGETDW(w) (*(u_int32_t *)(w))
838 #define USETDW(w,v) (*(u_int32_t *)(w) = (v))
839 #endif
840 
841 //#define UPACKED __attribute__((__packed__))
842 
843 
844 
845 
846 
847 
848 /* Everything is aribtrary */
849 #define USB_ALTSETTINGALLOC		4
850 #define USB_MAXALTSETTING		128	/* Hard limit */
851 
852 #define USB_MAX_DEVICE			2       // at least 2: 1 for the root hub device, 1 for usb device
853 #define USB_MAXCONFIG			8
854 #define USB_MAXINTERFACES		8
855 #define USB_MAXENDPOINTS		16
856 #define USB_MAXCHILDREN			8	/* This is arbitrary */
857 #define USB_MAX_HUB			    2
858 
859 #define USB_MAXIADS		        (USB_MAXINTERFACES/2)
860 
861 #define USB_CNTL_TIMEOUT 5000 /* 100ms timeout */
862 
863 
864 
865 
866 /* Requests */
867 #define UR_GET_STATUS		0x00
868 #define  USTAT_STANDARD_STATUS  0x00
869 #define  WUSTAT_WUSB_FEATURE    0x01
870 #define  WUSTAT_CHANNEL_INFO    0x02
871 #define  WUSTAT_RECEIVED_DATA   0x03
872 #define  WUSTAT_MAS_AVAILABILITY 0x04
873 #define  WUSTAT_CURRENT_TRANSMIT_POWER 0x05
874 #define UR_CLEAR_FEATURE	0x01
875 #define UR_SET_FEATURE		0x03
876 #define UR_SET_AND_TEST_FEATURE 0x0c
877 #define UR_SET_ADDRESS		0x05
878 #define UR_GET_DESCRIPTOR	0x06
879 #define  UDESC_DEVICE		0x01
880 #define  UDESC_CONFIG		0x02
881 #define  UDESC_STRING		0x03
882 #define  UDESC_INTERFACE	0x04
883 #define  UDESC_ENDPOINT		0x05
884 #define  UDESC_SS_USB_COMPANION	0x30
885 #define  UDESC_DEVICE_QUALIFIER	0x06
886 #define  UDESC_OTHER_SPEED_CONFIGURATION 0x07
887 #define  UDESC_INTERFACE_POWER	0x08
888 #define  UDESC_OTG		0x09
889 #define  WUDESC_SECURITY	0x0c
890 #define  WUDESC_KEY		0x0d
891 #define   WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
892 #define   WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
893 #define    WUD_KEY_TYPE_ASSOC    0x01
894 #define    WUD_KEY_TYPE_GTK      0x02
895 #define   WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
896 #define    WUD_KEY_ORIGIN_HOST   0x00
897 #define    WUD_KEY_ORIGIN_DEVICE 0x01
898 #define  WUDESC_ENCRYPTION_TYPE	0x0e
899 #define  WUDESC_BOS		0x0f
900 #define  WUDESC_DEVICE_CAPABILITY 0x10
901 #define  WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
902 #define  UDESC_BOS		0x0f
903 #define  UDESC_DEVICE_CAPABILITY 0x10
904 #define  UDESC_CS_DEVICE	0x21	/* class specific */
905 #define  UDESC_CS_CONFIG	0x22
906 #define  UDESC_CS_STRING	0x23
907 #define  UDESC_CS_INTERFACE	0x24
908 #define  UDESC_CS_ENDPOINT	0x25
909 #define  UDESC_HUB		0x29
910 #define UR_SET_DESCRIPTOR	0x07
911 #define UR_GET_CONFIG		0x08
912 #define UR_SET_CONFIG		0x09
913 #define UR_GET_INTERFACE	0x0a
914 #define UR_SET_INTERFACE	0x0b
915 #define UR_SYNCH_FRAME		0x0c
916 #define WUR_SET_ENCRYPTION      0x0d
917 #define WUR_GET_ENCRYPTION	0x0e
918 #define WUR_SET_HANDSHAKE	0x0f
919 #define WUR_GET_HANDSHAKE	0x10
920 #define WUR_SET_CONNECTION	0x11
921 #define WUR_SET_SECURITY_DATA	0x12
922 #define WUR_GET_SECURITY_DATA	0x13
923 #define WUR_SET_WUSB_DATA	0x14
924 #define  WUDATA_DRPIE_INFO	0x01
925 #define  WUDATA_TRANSMIT_DATA	0x02
926 #define  WUDATA_TRANSMIT_PARAMS	0x03
927 #define  WUDATA_RECEIVE_PARAMS	0x04
928 #define  WUDATA_TRANSMIT_POWER	0x05
929 #define WUR_LOOPBACK_DATA_WRITE	0x15
930 #define WUR_LOOPBACK_DATA_READ	0x16
931 #define WUR_SET_INTERFACE_DS	0x17
932 
933 
934 /* Hub features */
935 #define UHF_C_HUB_LOCAL_POWER	0
936 #define UHF_C_HUB_OVER_CURRENT	1
937 #define UHF_PORT_CONNECTION	0
938 #define UHF_PORT_ENABLE		1
939 #define UHF_PORT_SUSPEND	2
940 #define UHF_PORT_OVER_CURRENT	3
941 #define UHF_PORT_RESET		4
942 #define UHF_PORT_L1		5
943 #define UHF_PORT_POWER		8
944 #define UHF_PORT_LOW_SPEED	9
945 #define UHF_PORT_HIGH_SPEED	10
946 #define UHF_C_PORT_CONNECTION	16
947 #define UHF_C_PORT_ENABLE	17
948 #define UHF_C_PORT_SUSPEND	18
949 #define UHF_C_PORT_OVER_CURRENT	19
950 #define UHF_C_PORT_RESET	20
951 #define UHF_C_PORT_L1		23
952 #define UHF_PORT_TEST		21
953 #define UHF_PORT_INDICATOR	22
954 
955 
956 typedef struct {
957 	uByte		bLength;
958 	uByte		bDescriptorType;
959 	uByte		bDescriptorSubtype;
960 } UPACKED usb_descriptor_t;
961 
962 typedef struct {
963 	uByte		bLength;
964 	uByte		bDescriptorType;
965 } UPACKED usb_descriptor_header_t;
966 
967 typedef struct {
968 	uByte		bLength;
969 	uByte		bDescriptorType;
970 	uWord		bcdUSB;
971 #define UD_USB_2_0		0x0200
972 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
973 	uByte		bDeviceClass;
974 	uByte		bDeviceSubClass;
975 	uByte		bDeviceProtocol;
976 	uByte		bMaxPacketSize;
977 	/* The fields below are not part of the initial descriptor. */
978 	uWord		idVendor;
979 	uWord		idProduct;
980 	uWord		bcdDevice;
981 	uByte		iManufacturer;
982 	uByte		iProduct;
983 	uByte		iSerialNumber;
984 	uByte		bNumConfigurations;
985 } UPACKED usb_device_descriptor_t;
986 
987 typedef struct {
988 	uByte		bLength;
989 	uByte		bDescriptorType;
990 	uWord		wTotalLength;
991 	uByte		bNumInterface;
992 	uByte		bConfigurationValue;
993 	uByte		iConfiguration;
994 #define UC_ATT_ONE		(1 << 7)	/* must be set */
995 #define UC_ATT_SELFPOWER	(1 << 6)	/* self powered */
996 #define UC_ATT_WAKEUP		(1 << 5)	/* can wakeup */
997 #define UC_ATT_BATTERY		(1 << 4)	/* battery powered */
998 	uByte		bmAttributes;
999 #define UC_BUS_POWERED		0x80
1000 #define UC_SELF_POWERED		0x40
1001 #define UC_REMOTE_WAKEUP	0x20
1002 	uByte		bMaxPower; /* max current in 2 mA units */
1003 #define UC_POWER_FACTOR 2
1004 } UPACKED usb_config_descriptor_t;
1005 #define USB_CONFIG_DESCRIPTOR_SIZE 9
1006 
1007 typedef struct {
1008 	uByte		bLength;
1009 	uByte		bDescriptorType;
1010 	uByte		bInterfaceNumber;
1011 	uByte		bAlternateSetting;
1012 	uByte		bNumEndpoints;
1013 	uByte		bInterfaceClass;
1014 	uByte		bInterfaceSubClass;
1015 	uByte		bInterfaceProtocol;
1016 	uByte		iInterface;
1017 } UPACKED usb_interface_descriptor_t;
1018 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
1019 
1020 
1021 
1022 /* String descriptor */
1023 
1024 
1025 /* device request (setup) */
1026 struct devrequest {
1027 	unsigned char	requesttype;
1028 	unsigned char	request;
1029 	unsigned short	value;
1030 	unsigned short	index;
1031 	unsigned short	length;
1032 } UPACKED;
1033 
1034 /* All standard descriptors have these 2 fields in common */
1035 
1036 
1037 /* Device descriptor */
1038 
1039 
1040 /* Endpoint descriptor */
1041 
1042 
1043 /* Interface descriptor */
1044 
1045 
1046 /* Configuration descriptor information.. */
1047 
1048 
1049 /* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
1050 
1051 enum {
1052 	/* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
1053 	PACKET_SIZE_8   = 0,
1054 	PACKET_SIZE_16  = 1,
1055 	PACKET_SIZE_32  = 2,
1056 	PACKET_SIZE_64  = 3,
1057 };
1058 
1059 
1060 
1061 
1062 struct usb_host_endpoint {
1063 	struct usb_endpoint_descriptor		desc;
1064 #if defined(DWC_WITH_WLAN_OSDEP)
1065 	_list		urb_list;
1066 #else
1067     _LIST		urb_list;
1068 #endif
1069 	void				*hcpriv;
1070 	unsigned char *extra;   /* Extra descriptors */
1071 	int extralen;
1072 	int enabled;
1073 };
1074 
1075 /* host-side wrapper for one interface setting's parsed descriptors */
1076 struct usb_host_interface {
1077 	struct usb_interface_descriptor	desc;
1078 
1079 	int extralen;
1080 	unsigned char *extra;   /* Extra descriptors */
1081 
1082 	/* array of desc.bNumEndpoint endpoints associated with this
1083 	 * interface setting.  these will be in no particular order.
1084 	 */
1085 	struct usb_host_endpoint *endpoint;
1086 
1087 	char *string;		/* iInterface string, if present */
1088 };
1089 
1090 struct usb_interface {
1091 	/* array of alternate settings for this interface,
1092 	 * stored in no particular order */
1093 	struct usb_host_interface *altsetting;
1094 
1095 	struct usb_host_interface *cur_altsetting;	/* the currently
1096 					 * active alternate setting */
1097 	unsigned num_altsetting;	/* number of alternate settings */
1098 
1099 	/* If there is an interface association descriptor then it will list
1100 	 * the associated interfaces */
1101 	struct usb_interface_assoc_descriptor *intf_assoc;
1102 
1103 //	int minor;			/* minor number this interface is
1104 //					 * bound to */
1105 	unsigned ep_devs_created:1;	/* endpoint "devices" exist */
1106 	unsigned unregistering:1;	/* unregistration is in progress */
1107 	unsigned needs_altsetting0:1;	/* switch to altsetting 0 is pending */
1108 	unsigned reset_running:1;
1109 	unsigned resetting_device:1;	/* true: bandwidth alloc after reset */
1110 
1111 	void *dev_prive_data;/* interface specific device info i.e struct v4l2_device pointer */
1112 
1113 	void *driver;
1114     void *drv_priv;     // functional driver priv data
1115 	void *usb_dev;
1116 };
1117 #define	to_usb_interface(d) container_of(d, struct usb_interface, usb_dev)
1118 
1119 struct usb_interface_cache {
1120 	unsigned num_altsetting;	/* number of alternate settings */
1121 
1122 	/* variable-length array of alternate settings for this interface,
1123 	 * stored in no particular order */
1124 	struct usb_host_interface altsetting[0];
1125 };
1126 
1127 struct usb_host_config {
1128 	struct usb_config_descriptor	desc;
1129 
1130 	char *string;		/* iConfiguration string, if present */
1131 
1132 	/* List of any Interface Association Descriptors in this
1133 	 * configuration. */
1134 	struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];
1135 
1136 	/* the interfaces associated with this configuration,
1137 	 * stored in no particular order */
1138 	struct usb_interface *interface[USB_MAXINTERFACES];
1139 
1140 	/* Interface information available even when this is not the
1141 	 * active configuration */
1142 	struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];
1143 
1144 	unsigned char *extra;   /* Extra descriptors */
1145 	int extralen;
1146 };
1147 
1148 
1149 
1150 struct usb_device {
1151 	int		devnum;
1152 	u32		route;
1153 	enum usb_device_state	state;
1154 	enum usb_device_speed	speed;
1155 
1156 	unsigned int toggle[2];
1157 
1158 	struct usb_device *parent;
1159 	struct usb_device *children[USB_MAXCHILDREN];
1160     void *hcd;
1161 	struct usb_host_endpoint ep0;
1162 
1163 	struct usb_device_descriptor descriptor;
1164 	struct usb_host_config *config;
1165 
1166 	struct usb_host_config *actconfig;
1167 	struct usb_host_endpoint *ep_in[16];
1168 	struct usb_host_endpoint *ep_out[16];
1169 	int configno;			/* selected config number */
1170 
1171 	char **rawdescriptors;
1172     unsigned int rawdeslen[USB_MAXCONFIG];
1173 
1174 //	unsigned short bus_mA;
1175 	u8 portnum;
1176 	u8 level;
1177 
1178 	unsigned can_submit:1;
1179 	unsigned persist_enabled:1;
1180 	unsigned have_langid:1;
1181 	unsigned authorized:1;
1182 	unsigned authenticated:1;
1183 	int string_langid;
1184 
1185 	/* static strings from the device */
1186 //	char *product;
1187 //	char *manufacturer;
1188 //	char *serial;
1189 
1190 	int maxchild;
1191 
1192 	u32 quirks;
1193 	atomic_t urbnum;
1194 
1195 //	unsigned long active_duration;
1196 
1197 	char mf[32];			/* manufacturer */
1198 	char prod[32];		/* product */
1199 	char serial[32];		/* serial number */
1200 #if defined(DWC_WITH_WLAN_OSDEP)
1201     _mutex Mutex;
1202 #else
1203 	_Mutex Mutex;
1204 #endif
1205 };
1206 
1207 /*
1208  * urb->transfer_flags:
1209  *
1210  * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb().
1211  */
1212 #define URB_SHORT_NOT_OK	0x0001	/* report short reads as errors */
1213 #define URB_ISO_ASAP		0x0002	/* iso-only, urb->start_frame
1214 					 * ignored */
1215 #define URB_NO_TRANSFER_DMA_MAP	0x0004	/* urb->transfer_dma valid on submit */
1216 #define URB_NO_FSBR		0x0020	/* UHCI-specific */
1217 #define URB_ZERO_PACKET		0x0040	/* Finish bulk OUT with short packet */
1218 #define URB_NO_INTERRUPT	0x0080	/* HINT: no non-error interrupt
1219 					 * needed */
1220 #define URB_FREE_BUFFER		0x0100	/* Free transfer buffer with the URB */
1221 
1222 /* The following flags are used internally by usbcore and HCDs */
1223 #define URB_DIR_IN		0x0200	/* Transfer from device to host */
1224 #define URB_DIR_OUT		0
1225 #define URB_DIR_MASK		URB_DIR_IN
1226 
1227 #define URB_DMA_MAP_SINGLE	0x00010000	/* Non-scatter-gather mapping */
1228 #define URB_DMA_MAP_PAGE	0x00020000	/* HCD-unsupported S-G */
1229 #define URB_DMA_MAP_SG		0x00040000	/* HCD-supported S-G */
1230 #define URB_MAP_LOCAL		0x00080000	/* HCD-local-memory mapping */
1231 #define URB_SETUP_MAP_SINGLE	0x00100000	/* Setup packet DMA mapped */
1232 #define URB_SETUP_MAP_LOCAL	0x00200000	/* HCD-local setup packet */
1233 #define URB_DMA_SG_COMBINED	0x00400000	/* S-G entries were combined */
1234 #define URB_ALIGNED_TEMP_BUFFER	0x00800000	/* Temp buffer was alloc'd */
1235 
1236 struct usb_iso_packet_descriptor {
1237 	unsigned int offset;
1238 	unsigned int length;		/* expected length */
1239 	unsigned int actual_length;
1240 	int status;
1241 };
1242 
1243 struct urb;
1244 
1245 typedef void (*usb_complete_t)(struct urb *);
1246 
1247 struct urb {
1248 	/* private: usb core and host controller only fields in the urb */
1249 	void *hcpriv;			/* private data for host controller */
1250 	atomic_t use_count;		/* concurrent submissions counter */
1251 	atomic_t reject;		/* submissions will fail */
1252 	int unlinked;			/* unlink error code */
1253 
1254 	/* public: documented fields in the urb that can be used by drivers */
1255 #if defined(DWC_WITH_WLAN_OSDEP)
1256 	_list urb_list;	/* list head for use by the urb's
1257 
1258 					 * current owner */
1259 //	_list anchor_list;	/* the URB may be anchored */
1260 #else
1261     _LIST urb_list;	/* list head for use by the urb's
1262 					 * current owner */
1263 //	_LIST anchor_list;	/* the URB may be anchored */
1264 #endif
1265 //	struct usb_anchor *anchor;
1266 	struct usb_device *dev;		/* (in) pointer to associated device */
1267 	struct usb_host_endpoint *ep;	/* (internal) pointer to endpoint */
1268 	unsigned int pipe;		/* (in) pipe information */
1269 	unsigned int stream_id;		/* (in) stream ID */
1270 	int status;			/* (return) non-ISO status */
1271 	unsigned int transfer_flags;	/* (in) URB_SHORT_NOT_OK | ...*/
1272 	void *transfer_buffer;		/* (in) associated data buffer */
1273 	dma_addr_t transfer_dma;	/* (in) dma addr for transfer_buffer */
1274 	u32 transfer_buffer_length;	/* (in) data buffer length */
1275 	u32 actual_length;		/* (return) actual transfer length */
1276 	unsigned char *setup_packet;	/* (in) setup packet (control only) */
1277 
1278 	int start_frame;		/* (modify) start frame (ISO) */
1279 	int number_of_packets;		/* (in) number of ISO packets */
1280 	int interval;			/* (modify) transfer interval
1281 					 * (INT/ISO) */
1282 	int error_count;		/* (return) number of ISO errors */
1283 	void *context;			/* (in) context for completion */
1284 #if defined(DWC_WITH_WLAN_OSDEP)
1285     _mutex Mutex;   // mutext for atomic or link-list operation
1286 #else
1287     _Mutex Mutex;   // mutext for atomic or link-list operation
1288 #endif
1289 	usb_complete_t complete;	/* (in) completion routine */
1290     unsigned int iso_packets;
1291 	struct usb_iso_packet_descriptor iso_frame_desc[0];
1292 					/* (in) ISO ONLY */
1293 };
1294 
1295 struct usb_hcd {
1296 
1297 	/*
1298 	 * housekeeping
1299 	 */
1300 	void *rhdev;        /* self usb_dev */
1301 	const char *product_desc;	/* product/vendor string */
1302 	int	speed;		/* Speed for this roothub.
1303 						 * May be different from
1304 						 * hcd->driver->flags & HCD_MASK
1305 						 */
1306 
1307 	struct urb *status_urb;	/* the current status urb */
1308 
1309 	/*
1310 	 * hardware info/state
1311 	 */
1312 
1313 
1314 
1315 	/* Flags that need to be manipulated atomically because they can
1316 	 * change while the host controller is running.  Always use
1317 	 * set_bit() or clear_bit() to change their values.
1318 	 */
1319 	unsigned long flags;
1320 
1321 	/* Flags that get set only during HCD registration or removal. */
1322 	unsigned rh_registered:1;/* is root hub registered? */
1323 	unsigned rh_pollable:1;	/* may we poll the root hub? */
1324 	unsigned msix_enabled:1;	/* driver has MSI-X enabled? */
1325 
1326 	/* The next flag is a stopgap, to be removed when all the HCDs
1327 	 * support the new root-hub polling mechanism. */
1328 	unsigned uses_new_polling:1;
1329 	unsigned authorized_default:1;
1330 	unsigned has_tt:1;	/* Integrated TT in root hub */
1331 
1332 
1333 	/* bandwidth_mutex should be taken before adding or removing
1334 	 * any new bus bandwidth constraints:
1335 	 *   1. Before adding a configuration for a new device.
1336 	 *   2. Before removing the configuration to put the device into
1337 	 *      the addressed state.
1338 	 *   3. Before selecting a different configuration.
1339 	 *   4. Before selecting an alternate interface setting.
1340 	 *
1341 	 * bandwidth_mutex should be dropped after a successful control message
1342 	 * to the device, or resetting the bandwidth after a failed attempt.
1343 	 */
1344 #if defined(DWC_WITH_WLAN_OSDEP)
1345 	_mutex		bandwidth_mutex;
1346 #else
1347     _Mutex		bandwidth_mutex;
1348 #endif
1349 
1350 	int	state;
1351 
1352     int devnum_next;        /* Next open device number in
1353                              * round-robin allocation */
1354 #if defined(DWC_WITH_WLAN_OSDEP)
1355     _mutex hcd_urb_list_lock;
1356     _mutex hcd_urb_unlink_lock;
1357     _mutex hcd_root_hub_lock;   // mutext for atomic or link-list operation
1358 #else
1359     _Mutex hcd_urb_list_lock;
1360     _Mutex hcd_urb_unlink_lock;
1361     _Mutex hcd_root_hub_lock;   // mutext for atomic or link-list operation
1362 #endif
1363 
1364 	/* The HC driver's private data is stored at the end of
1365 	 * this structure.
1366 	 */
1367 #ifdef __ICCARM__
1368     #pragma pack(64)
1369     unsigned long hcd_priv[0];
1370 #elif defined (__GNUC__)
1371 	unsigned long hcd_priv[0]
1372 	__attribute__ ((aligned(sizeof(s64))));
1373 #endif
1374 };
1375 
1376 
1377 #define le16_to_cpu rtk_le16_to_cpu
1378 #define cpu_to_le16 rtk_cpu_to_le16
1379 
1380 #if 0
1381 /*
1382  * Calling this entity a "pipe" is glorifying it. A USB pipe
1383  * is something embarrassingly simple: it basically consists
1384  * of the following information:
1385  *  - device number (7 bits)
1386  *  - endpoint number (4 bits)
1387  *  - current Data0/1 state (1 bit)
1388  *  - direction (1 bit)
1389  *  - speed (2 bits)
1390  *  - max packet size (2 bits: 8, 16, 32 or 64)
1391  *  - pipe type (2 bits: control, interrupt, bulk, isochronous)
1392  *
1393  * That's 18 bits. Really. Nothing more. And the USB people have
1394  * documented these eighteen bits as some kind of glorious
1395  * virtual data structure.
1396  *
1397  * Let's not fall in that trap. We'll just encode it as a simple
1398  * unsigned int. The encoding is:
1399  *
1400  *  - max size:		bits 0-1	(00 = 8, 01 = 16, 10 = 32, 11 = 64)
1401  *  - direction:	bit 7		(0 = Host-to-Device [Out],
1402  *					(1 = Device-to-Host [In])
1403  *  - device:		bits 8-14
1404  *  - endpoint:		bits 15-18
1405  *  - Data0/1:		bit 19
1406  *  - speed:		bit 26		(0 = Full, 1 = Low Speed, 2 = High)
1407  *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt,
1408  *					 10 = control, 11 = bulk)
1409  *
1410  * Why? Because it's arbitrary, and whatever encoding we select is really
1411  * up to us. This one happens to share a lot of bit positions with the UHCI
1412  * specification, so that much of the uhci driver can just mask the bits
1413  * appropriately.
1414  */
1415 /* Create various pipes... */
1416 #define create_pipe(dev,endpoint) \
1417 		(((dev)->devnum << 8) | (endpoint << 15) | \
1418 		((dev)->speed << 26) | (dev)->maxpacketsize)
1419 #define default_pipe(dev) ((dev)->speed << 26)
1420 
1421 #define usb_sndctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
1422 					 create_pipe(dev, endpoint))
1423 #define usb_rcvctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
1424 					 create_pipe(dev, endpoint) | \
1425 					 USB_DIR_IN)
1426 #define usb_sndisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
1427 					 create_pipe(dev, endpoint))
1428 #define usb_rcvisocpipe(dev, endpoint)	((PIPE_ISOCHRONOUS << 30) | \
1429 					 create_pipe(dev, endpoint) | \
1430 					 USB_DIR_IN)
1431 #define usb_sndbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
1432 					 create_pipe(dev, endpoint))
1433 #define usb_rcvbulkpipe(dev, endpoint)	((PIPE_BULK << 30) | \
1434 					 create_pipe(dev, endpoint) | \
1435 					 USB_DIR_IN)
1436 #define usb_sndintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
1437 					 create_pipe(dev, endpoint))
1438 #define usb_rcvintpipe(dev, endpoint)	((PIPE_INTERRUPT << 30) | \
1439 					 create_pipe(dev, endpoint) | \
1440 					 USB_DIR_IN)
1441 #define usb_snddefctrl(dev)		((PIPE_CONTROL << 30) | \
1442 					 default_pipe(dev))
1443 #define usb_rcvdefctrl(dev)		((PIPE_CONTROL << 30) | \
1444 					 default_pipe(dev) | \
1445 					 USB_DIR_IN)
1446 
1447 /* The D0/D1 toggle bits */
1448 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
1449 #define usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << ep))
1450 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
1451 						((dev)->toggle[out] & \
1452 						 ~(1 << ep)) | ((bit) << ep))
1453 
1454 /* Endpoint halt control/status */
1455 #define usb_endpoint_out(ep_dir)	(((ep_dir >> 7) & 1) ^ 1)
1456 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
1457 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
1458 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
1459 
1460 #define usb_packetid(pipe)	(((pipe) & USB_DIR_IN) ? USB_PID_IN : \
1461 				 USB_PID_OUT)
1462 
1463 #define usb_pipeout(pipe)	((((pipe) >> 7) & 1) ^ 1)
1464 #define usb_pipein(pipe)	(((pipe) >> 7) & 1)
1465 #define usb_pipedevice(pipe)	(((pipe) >> 8) & 0x7f)
1466 #define usb_pipe_endpdev(pipe)	(((pipe) >> 8) & 0x7ff)
1467 #define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)
1468 #define usb_pipedata(pipe)	(((pipe) >> 19) & 1)
1469 #define usb_pipespeed(pipe)	(((pipe) >> 26) & 3)
1470 #define usb_pipeslow(pipe)	(usb_pipespeed(pipe) == USB_SPEED_LOW)
1471 #define usb_pipetype(pipe)	(((pipe) >> 30) & 3)
1472 #define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
1473 #define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)
1474 #define usb_pipecontrol(pipe)	(usb_pipetype((pipe)) == PIPE_CONTROL)
1475 #define usb_pipebulk(pipe)	(usb_pipetype((pipe)) == PIPE_BULK)
1476 
1477 #else
1478 /* ----------------------------------------------------------------------- */
1479 
1480 /*
1481  * For various legacy reasons, Linux has a small cookie that's paired with
1482  * a struct usb_device to identify an endpoint queue.  Queue characteristics
1483  * are defined by the endpoint's descriptor.  This cookie is called a "pipe",
1484  * an unsigned int encoded as:
1485  *
1486  *  - direction:	bit 7		(0 = Host-to-Device [Out],
1487  *					 1 = Device-to-Host [In] ...
1488  *					like endpoint bEndpointAddress)
1489  *  - device address:	bits 8-14       ... bit positions known to uhci-hcd
1490  *  - endpoint:		bits 15-18      ... bit positions known to uhci-hcd
1491  *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt,
1492  *					 10 = control, 11 = bulk)
1493  *
1494  * Given the device address and endpoint descriptor, pipes are redundant.
1495  */
1496 
1497 /* NOTE:  these are not the standard USB_ENDPOINT_XFER_* values!! */
1498 /* (yet ... they're the values used by usbfs) */
1499 
1500 #define usb_pipein(pipe)	(((pipe) & USB_DIR_IN) >> 7)
1501 #define usb_pipeout(pipe)	(!usb_pipein(pipe))
1502 
1503 #define usb_pipedevice(pipe)	(((pipe) >> 8) & 0x7f)
1504 #define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)
1505 
1506 #define usb_pipetype(pipe)	(((pipe) >> 30) & 3)
1507 #define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
1508 #define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)
1509 #define usb_pipecontrol(pipe)	(usb_pipetype((pipe)) == PIPE_CONTROL)
1510 #define usb_pipebulk(pipe)	(usb_pipetype((pipe)) == PIPE_BULK)
1511 
__create_pipe(struct usb_device * dev,unsigned int endpoint)1512 static inline unsigned int __create_pipe(struct usb_device *dev,
1513 		unsigned int endpoint)
1514 {
1515 	return (dev->devnum << 8) | (endpoint << 15);
1516 }
1517 
1518 #define usb_sndaddr0pipe()	(PIPE_CONTROL << 30)
1519 #define usb_rcvaddr0pipe()	((PIPE_CONTROL << 30) | USB_DIR_IN)
1520 
1521 /* Create various pipes... */
1522 #define usb_sndctrlpipe(dev, endpoint)	\
1523 	((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
1524 #define usb_rcvctrlpipe(dev, endpoint)	\
1525 	((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1526 #define usb_sndisocpipe(dev, endpoint)	\
1527 	((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
1528 #define usb_rcvisocpipe(dev, endpoint)	\
1529 	((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1530 #define usb_sndbulkpipe(dev, endpoint)	\
1531 	((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
1532 #define usb_rcvbulkpipe(dev, endpoint)	\
1533 	((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1534 #define usb_sndintpipe(dev, endpoint)	\
1535 	((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
1536 #define usb_rcvintpipe(dev, endpoint)	\
1537 	((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1538 
1539 static inline struct usb_host_endpoint *
usb_pipe_endpoint(struct usb_device * dev,unsigned int pipe)1540 usb_pipe_endpoint(struct usb_device *dev, unsigned int pipe)
1541 {
1542 	struct usb_host_endpoint **eps;
1543 	eps = usb_pipein(pipe) ? dev->ep_in : dev->ep_out;
1544 	return eps[usb_pipeendpoint(pipe)];
1545 }
1546 
1547 /* The D0/D1 toggle bits ... USE WITH CAUTION (they're almost hcd-internal) */
1548 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
1549 #define	usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << (ep)))
1550 #define usb_settoggle(dev, ep, out, bit) \
1551 		((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | \
1552 		 ((bit) << (ep)))
1553 #endif
1554 
1555 /*************************************************************************
1556  * Hub Stuff
1557  */
1558 struct usb_port_status {
1559 	unsigned short wPortStatus;
1560 	unsigned short wPortChange;
1561 } UPACKED;
1562 
1563 struct usb_hub_status {
1564 	unsigned short wHubStatus;
1565 	unsigned short wHubChange;
1566 }UPACKED;
1567 
1568 
1569 /* Hub descriptor */
1570 struct usb_hub_descriptor {
1571 	unsigned char  bLength;
1572 	unsigned char  bDescriptorType;
1573 	unsigned char  bNbrPorts;
1574 	unsigned short wHubCharacteristics;
1575 	unsigned char  bPwrOn2PwrGood;
1576 	unsigned char  bHubContrCurrent;
1577 	unsigned char  DeviceRemovable[(USB_MAXCHILDREN+1+7)/8];
1578 	unsigned char  PortPowerCtrlMask[(USB_MAXCHILDREN+1+7)/8];
1579 	/* DeviceRemovable and PortPwrCtrlMask want to be variable-length
1580 	   bitmaps that hold max 255 entries. (bit0 is ignored) */
1581 }UPACKED;
1582 
1583 
1584 struct usb_hub_device {
1585 	struct usb_device *pusb_dev;
1586 	struct usb_hub_descriptor desc;
1587 };
1588 
1589 /*-------------------------------------------------------------------------*/
1590 
1591 /**
1592  * usb_endpoint_num - get the endpoint's number
1593  * @epd: endpoint to be checked
1594  *
1595  * Returns @epd's number: 0 to 15.
1596  */
usb_endpoint_num(const struct usb_endpoint_descriptor * epd)1597 static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
1598 {
1599 	return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
1600 }
1601 
1602 /**
1603  * usb_endpoint_type - get the endpoint's transfer type
1604  * @epd: endpoint to be checked
1605  *
1606  * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
1607  * to @epd's transfer type.
1608  */
usb_endpoint_type(const struct usb_endpoint_descriptor * epd)1609 static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
1610 {
1611 	return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
1612 }
1613 
1614 /**
1615  * usb_endpoint_dir_in - check if the endpoint has IN direction
1616  * @epd: endpoint to be checked
1617  *
1618  * Returns true if the endpoint is of type IN, otherwise it returns false.
1619  */
usb_endpoint_dir_in(const struct usb_endpoint_descriptor * epd)1620 static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
1621 {
1622 	return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
1623 }
1624 
1625 /**
1626  * usb_endpoint_dir_out - check if the endpoint has OUT direction
1627  * @epd: endpoint to be checked
1628  *
1629  * Returns true if the endpoint is of type OUT, otherwise it returns false.
1630  */
usb_endpoint_dir_out(const struct usb_endpoint_descriptor * epd)1631 static inline int usb_endpoint_dir_out(
1632 				const struct usb_endpoint_descriptor *epd)
1633 {
1634 	return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
1635 }
1636 
1637 #define usb_endpoint_out(ep_dir)	(!((ep_dir) & USB_DIR_IN))
1638 
1639 /**
1640  * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
1641  * @epd: endpoint to be checked
1642  *
1643  * Returns true if the endpoint is of type bulk, otherwise it returns false.
1644  */
usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor * epd)1645 static inline int usb_endpoint_xfer_bulk(
1646 				const struct usb_endpoint_descriptor *epd)
1647 {
1648 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
1649 		USB_ENDPOINT_XFER_BULK);
1650 }
1651 
1652 /**
1653  * usb_endpoint_xfer_control - check if the endpoint has control transfer type
1654  * @epd: endpoint to be checked
1655  *
1656  * Returns true if the endpoint is of type control, otherwise it returns false.
1657  */
usb_endpoint_xfer_control(const struct usb_endpoint_descriptor * epd)1658 static inline int usb_endpoint_xfer_control(
1659 				const struct usb_endpoint_descriptor *epd)
1660 {
1661 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
1662 		USB_ENDPOINT_XFER_CONTROL);
1663 }
1664 
1665 /**
1666  * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
1667  * @epd: endpoint to be checked
1668  *
1669  * Returns true if the endpoint is of type interrupt, otherwise it returns
1670  * false.
1671  */
usb_endpoint_xfer_int(const struct usb_endpoint_descriptor * epd)1672 static inline int usb_endpoint_xfer_int(
1673 				const struct usb_endpoint_descriptor *epd)
1674 {
1675 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
1676 		USB_ENDPOINT_XFER_INT);
1677 }
1678 
1679 /**
1680  * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
1681  * @epd: endpoint to be checked
1682  *
1683  * Returns true if the endpoint is of type isochronous, otherwise it returns
1684  * false.
1685  */
usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor * epd)1686 static inline int usb_endpoint_xfer_isoc(
1687 				const struct usb_endpoint_descriptor *epd)
1688 {
1689 	return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
1690 		USB_ENDPOINT_XFER_ISOC);
1691 }
1692 
1693 /**
1694  * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
1695  * @epd: endpoint to be checked
1696  *
1697  * Returns true if the endpoint has bulk transfer type and IN direction,
1698  * otherwise it returns false.
1699  */
usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor * epd)1700 static inline int usb_endpoint_is_bulk_in(
1701 				const struct usb_endpoint_descriptor *epd)
1702 {
1703 	return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
1704 }
1705 
1706 /**
1707  * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
1708  * @epd: endpoint to be checked
1709  *
1710  * Returns true if the endpoint has bulk transfer type and OUT direction,
1711  * otherwise it returns false.
1712  */
usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor * epd)1713 static inline int usb_endpoint_is_bulk_out(
1714 				const struct usb_endpoint_descriptor *epd)
1715 {
1716 	return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
1717 }
1718 
1719 /**
1720  * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
1721  * @epd: endpoint to be checked
1722  *
1723  * Returns true if the endpoint has interrupt transfer type and IN direction,
1724  * otherwise it returns false.
1725  */
usb_endpoint_is_int_in(const struct usb_endpoint_descriptor * epd)1726 static inline int usb_endpoint_is_int_in(
1727 				const struct usb_endpoint_descriptor *epd)
1728 {
1729 	return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
1730 }
1731 
1732 /**
1733  * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
1734  * @epd: endpoint to be checked
1735  *
1736  * Returns true if the endpoint has interrupt transfer type and OUT direction,
1737  * otherwise it returns false.
1738  */
usb_endpoint_is_int_out(const struct usb_endpoint_descriptor * epd)1739 static inline int usb_endpoint_is_int_out(
1740 				const struct usb_endpoint_descriptor *epd)
1741 {
1742 	return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
1743 }
1744 
1745 /**
1746  * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
1747  * @epd: endpoint to be checked
1748  *
1749  * Returns true if the endpoint has isochronous transfer type and IN direction,
1750  * otherwise it returns false.
1751  */
usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor * epd)1752 static inline int usb_endpoint_is_isoc_in(
1753 				const struct usb_endpoint_descriptor *epd)
1754 {
1755 	return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
1756 }
1757 
1758 /**
1759  * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
1760  * @epd: endpoint to be checked
1761  *
1762  * Returns true if the endpoint has isochronous transfer type and OUT direction,
1763  * otherwise it returns false.
1764  */
usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * epd)1765 static inline int usb_endpoint_is_isoc_out(
1766 				const struct usb_endpoint_descriptor *epd)
1767 {
1768 	return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
1769 }
1770 
1771 /**
1772  * usb_endpoint_maxp - get endpoint's max packet size
1773  * @epd: endpoint to be checked
1774  *
1775  * Returns @epd's max packet
1776  */
usb_endpoint_maxp(const struct usb_endpoint_descriptor * epd)1777 static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
1778 {
1779 	return rtk_le16_to_cpu(epd->wMaxPacketSize);
1780 }
1781 
1782 /**
1783  * usb_urb_dir_in - check if an URB describes an IN transfer
1784  * @urb: URB to be checked
1785  *
1786  * Returns 1 if @urb describes an IN transfer (device-to-host),
1787  * otherwise 0.
1788  */
usb_urb_dir_in(struct urb * urb)1789 static inline int usb_urb_dir_in(struct urb *urb)
1790 {
1791 	return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN;
1792 }
1793 
1794 /**
1795  * usb_urb_dir_out - check if an URB describes an OUT transfer
1796  * @urb: URB to be checked
1797  *
1798  * Returns 1 if @urb describes an OUT transfer (host-to-device),
1799  * otherwise 0.
1800  */
usb_urb_dir_out(struct urb * urb)1801 static inline int usb_urb_dir_out(struct urb *urb)
1802 {
1803 	return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT;
1804 }
1805 
1806 /**
1807  * usb_get_dev - increments the reference count of the usb device structure
1808  * @dev: the device being referenced
1809  *
1810  * Each live reference to a device should be refcounted.
1811  *
1812  * Drivers for USB interfaces should normally record such references in
1813  * their probe() methods, when they bind to an interface, and release
1814  * them by calling usb_put_dev(), in their disconnect() methods.
1815  *
1816  * A pointer to the device with the incremented reference counter is returned.
1817  */
usb_get_dev(struct usb_device * dev)1818 static inline void *usb_get_dev(struct usb_device *dev)
1819 {
1820 	return dev;
1821 }
1822 
1823 /**
1824  * usb_put_dev - release a use of the usb device structure
1825  * @dev: device that's been disconnected
1826  *
1827  * Must be called when a user of a device is finished with it.  When the last
1828  * user of the device calls this function, the memory of the device is freed.
1829  */
usb_put_dev(struct usb_device * dev)1830 static inline void usb_put_dev(struct usb_device *dev)
1831 {
1832 	/* To avoid gcc warnings */
1833 	( void ) dev;
1834 }
1835 
1836 /**
1837  * usb_get_intf - increments the reference count of the usb interface structure
1838  * @intf: the interface being referenced
1839  *
1840  * Each live reference to a interface must be refcounted.
1841  *
1842  * Drivers for USB interfaces should normally record such references in
1843  * their probe() methods, when they bind to an interface, and release
1844  * them by calling usb_put_intf(), in their disconnect() methods.
1845  *
1846  * A pointer to the interface with the incremented reference counter is
1847  * returned.
1848  */
usb_get_intf(struct usb_interface * intf)1849 static inline void *usb_get_intf(struct usb_interface *intf)
1850 {
1851 	return intf;
1852 }
1853 
1854 /**
1855  * usb_put_intf - release a use of the usb interface structure
1856  * @intf: interface that's been decremented
1857  *
1858  * Must be called when a user of an interface is finished with it.  When the
1859  * last user of the interface calls this function, the memory of the interface
1860  * is freed.
1861  */
usb_put_intf(struct usb_interface * intf)1862 static inline void usb_put_intf(struct usb_interface *intf)
1863 {
1864 	/* To avoid gcc warnings */
1865 	( void ) intf;
1866 }
1867 
usb_get_intfdata(struct usb_interface * intf)1868 static inline void *usb_get_intfdata(struct usb_interface *intf)
1869 {
1870     return (intf->drv_priv);
1871 }
1872 
usb_set_intfdata(struct usb_interface * intf,void * data)1873 static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
1874 {
1875     intf->drv_priv = data;
1876 }
1877 
interface_to_usbdev(struct usb_interface * intf)1878 static inline struct usb_device *interface_to_usbdev(struct usb_interface *intf)
1879 {
1880 	return (struct usb_device *)(intf->usb_dev);
1881 }
1882 
interface_to_usbdri(struct usb_interface * intf)1883 static inline struct usb_driver *interface_to_usbdri(struct usb_interface *intf)
1884 {
1885 	return (struct usb_driver *)(intf->driver);
1886 }
1887 
1888 /*-------------------------------------------------------------------------*/
1889 
1890 /*=====================================================*/
1891 
1892 
1893 #ifdef DWC_HOST_ONLY
1894 typedef struct {
1895 	uByte		bLength;
1896 	uByte		bDescriptorType;
1897 	uByte		bEndpointAddress;
1898 #define UE_GET_DIR(a)	((a) & 0x80)
1899 #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
1900 #define UE_DIR_IN	0x01
1901 #define UE_DIR_OUT	0x00
1902 #define UE_ADDR		0x0f
1903 #define UE_GET_ADDR(a)	((a) & UE_ADDR)
1904 	uByte		bmAttributes;
1905 #define UE_XFERTYPE	0x03
1906 #define  UE_CONTROL	0x00
1907 #define  UE_ISOCHRONOUS	0x01
1908 #define  UE_BULK	0x02
1909 #define  UE_INTERRUPT	0x03
1910 #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
1911 #if 0
1912 #define UE_ISO_TYPE	0x0c
1913 #define  UE_ISO_ASYNC	0x04
1914 #define  UE_ISO_ADAPT	0x08
1915 #define  UE_ISO_SYNC	0x0c
1916 #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
1917 #endif
1918 	uWord		wMaxPacketSize;
1919 	uByte		bInterval;
1920 } usb_endpoint_descriptor_t;//UPACKED usb_endpoint_descriptor_t;
1921 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
1922 #endif
1923 #ifdef DWC_DEVICE_ONLY
1924 typedef struct {
1925 	uByte		bLength;
1926 	uByte		bDescriptorType;
1927 	uByte		bEndpointAddress;
1928 #define UE_GET_DIR(a)	((a) & 0x80)
1929 #define UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
1930 #define UE_DIR_IN	0x80
1931 #define UE_DIR_OUT	0x00
1932 #define UE_ADDR		0x0f
1933 #define UE_GET_ADDR(a)	((a) & UE_ADDR)
1934 	uByte		bmAttributes;
1935 #define UE_XFERTYPE	0x03
1936 #define  UE_CONTROL	0x00
1937 #define  UE_ISOCHRONOUS	0x01
1938 #define  UE_BULK	0x02
1939 #define  UE_INTERRUPT	0x03
1940 #define UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
1941 #define UE_ISO_TYPE	0x0c
1942 #define  UE_ISO_ASYNC	0x04
1943 #define  UE_ISO_ADAPT	0x08
1944 #define  UE_ISO_SYNC	0x0c
1945 #define UE_GET_ISO_TYPE(a)	((a) & UE_ISO_TYPE)
1946 	uWord		wMaxPacketSize;
1947 	uByte		bInterval;
1948 } UPACKED usb_endpoint_descriptor_t;
1949 #endif
1950 
1951 typedef struct ss_endpoint_companion_descriptor {
1952 	uByte bLength;
1953 	uByte bDescriptorType;
1954 	uByte bMaxBurst;
1955 #define USSE_GET_MAX_STREAMS(a)		((a) & 0x1f)
1956 #define USSE_SET_MAX_STREAMS(a, b)	((a) | ((b) & 0x1f))
1957 #define USSE_GET_MAX_PACKET_NUM(a)	((a) & 0x03)
1958 #define USSE_SET_MAX_PACKET_NUM(a, b)	((a) | ((b) & 0x03))
1959 	uByte bmAttributes;
1960 	uWord wBytesPerInterval;
1961 } UPACKED ss_endpoint_companion_descriptor_t;
1962 #define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
1963 
1964 typedef struct {
1965 	uByte		bLength;
1966 	uByte		bDescriptorType;
1967 	uWord		bString[127];
1968 } UPACKED usb_string_descriptor_t;
1969 #define USB_MAX_STRING_LEN 128
1970 #define USB_LANGUAGE_TABLE 0	/* # of the string language id table */
1971 
1972 
1973 /* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
1974 
1975 /* USB_DT_OTG (from OTG 1.0a supplement) */
1976 
1977 /* from usb_otg_descriptor.bmAttributes */
1978 #define USB_OTG_SRP		(1 << 0)
1979 #define USB_OTG_HNP		(1 << 1)	/* swap host/device roles */
1980 
1981 
1982 extern void _usb_init(void);
1983 extern void _usb_deinit(void);
1984 extern int wait_usb_ready(void);
1985 extern void usb_disable_asynch(int disable);
1986 extern unsigned short usb_maxpacket(struct usb_device *udev, int pipe, int is_out);
1987 extern int usb_set_interface(struct usb_device *dev, int interface, int alternate);
1988 extern int usb_set_configuration(struct usb_device *dev, int configuration);
1989 
1990 extern int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
1991 extern int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id);
1992 extern int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
1993         unsigned char id, void *buf, int size);
1994 extern int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
1995 		unsigned char type, unsigned char id, void *buf, int size);
1996 extern int usb_string(struct usb_device *dev, int index, char *buf, int size);
1997 
1998 extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status);
1999 extern struct usb_hcd *usb_create_hcd(unsigned int priv_size);
2000 extern int usb_add_hcd(struct usb_hcd *hcd);
2001 
2002 extern struct urb *usb_alloc_urb(int iso_packets);
2003 extern void usb_free_urb(struct urb *urb);
2004 extern void usb_kill_urb(struct urb *urb);
2005 extern void usb_fill_control_urb(struct urb *urb,
2006 					struct usb_device *dev,
2007 					unsigned int pipe,
2008 					unsigned char *setup_packet,
2009 					void *transfer_buffer,
2010 					int buffer_length,
2011 					usb_complete_t complete_fn,
2012 					void *context);
2013 extern void usb_fill_bulk_urb(struct urb *urb,
2014 				     struct usb_device *dev,
2015 				     unsigned int pipe,
2016 				     void *transfer_buffer,
2017 				     int buffer_length,
2018 				     usb_complete_t complete_fn,
2019 				     void *context);
2020 extern void usb_fill_int_urb(struct urb *urb,
2021 				    struct usb_device *dev,
2022 				    unsigned int pipe,
2023 				    void *transfer_buffer,
2024 				    int buffer_length,
2025 				    usb_complete_t complete_fn,
2026 				    void *context,
2027 				    int interval);
2028 extern int usb_submit_urb(struct urb *urb);
2029 
2030 extern void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr);
2031 extern void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
2032 		bool reset_hardware);
2033 extern void usb_enable_interface(struct usb_device *dev,
2034 		struct usb_interface *intf, bool reset_eps);
2035 
2036 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe, u8 request,
2037 		    u8 requesttype, u16 value, u16 index, void *data,
2038 		    u16 size, int timeout);
2039 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
2040 		 void *data, int len, int *actual_length, int timeout);
2041 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
2042 		      void *data, int len, int *actual_length, int timeout);
2043 extern int usb_get_descriptor(struct usb_device *dev, unsigned char type,
2044 		       unsigned char index, void *buf, int size);
2045 extern int usb_get_device_descriptor(struct usb_device *dev, unsigned int size);
2046 extern int usb_clear_halt(struct usb_device *dev, int pipe);
2047 #if defined(DWC_WITH_WLAN_OSDEP)
2048 extern _sema  CtrlUrbCompSema;  /* Semaphore for for Control URB Complete waiting */
2049 extern _sema  UrbKillSema;  /* Semaphore for for URB Kill waiting */
2050 #else
2051 extern _Sema  CtrlUrbCompSema;  /* Semaphore for for Control URB Complete waiting */
2052 extern _Sema  UrbKillSema;  /* Semaphore for for URB Kill waiting */
2053 #endif
2054 typedef unsigned long kernel_ulong_t;
2055 extern int usb_deinit(void);
2056 
2057 struct usb_device_id {
2058 	/* which fields to match against? */
2059 	u16		match_flags;
2060 
2061 	/* Used for product specific matches; range is inclusive */
2062 	u16		idVendor;
2063 	u16		idProduct;
2064 	u16		bcdDevice_lo;
2065 	u16		bcdDevice_hi;
2066 
2067 	/* Used for device class matches */
2068 	u8		bDeviceClass;
2069 	u8		bDeviceSubClass;
2070 	u8		bDeviceProtocol;
2071 
2072 	/* Used for interface class matches */
2073 	u8		bInterfaceClass;
2074 	u8		bInterfaceSubClass;
2075 	u8		bInterfaceProtocol;
2076 
2077 	/* Used for vendor-specific interface matches */
2078 	u8		bInterfaceNumber;
2079 
2080 	/* not matched against */
2081 #ifdef __ICCARM__
2082         #pragma pack(64)
2083         kernel_ulong_t	driver_info;
2084 #elif defined (__GNUC__)
2085 	kernel_ulong_t	driver_info
2086 	__attribute__((aligned(sizeof(kernel_ulong_t))));
2087 #endif
2088 };
2089 
2090 /* Some useful macros to use to create struct usb_device_id */
2091 #define USB_DEVICE_ID_MATCH_VENDOR		0x0001
2092 #define USB_DEVICE_ID_MATCH_PRODUCT		0x0002
2093 #define USB_DEVICE_ID_MATCH_DEV_LO		0x0004
2094 #define USB_DEVICE_ID_MATCH_DEV_HI		0x0008
2095 #define USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
2096 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
2097 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
2098 #define USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
2099 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
2100 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
2101 #define USB_DEVICE_ID_MATCH_INT_NUMBER		0x0400
2102 
2103 #define USB_DEVICE_ID_MATCH_DEVICE \
2104 		(USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
2105 #define USB_DEVICE_ID_MATCH_DEV_RANGE \
2106 		(USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
2107 #define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
2108 		(USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
2109 #define USB_DEVICE_ID_MATCH_DEV_INFO \
2110 		(USB_DEVICE_ID_MATCH_DEV_CLASS | \
2111 		USB_DEVICE_ID_MATCH_DEV_SUBCLASS | \
2112 		USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
2113 #define USB_DEVICE_ID_MATCH_INT_INFO \
2114 		(USB_DEVICE_ID_MATCH_INT_CLASS | \
2115 		USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
2116 		USB_DEVICE_ID_MATCH_INT_PROTOCOL)
2117 /**
2118  * USB_DEVICE - macro used to describe a specific usb device
2119  * @vend: the 16 bit USB Vendor ID
2120  * @prod: the 16 bit USB Product ID
2121  *
2122  * This macro is used to create a struct usb_device_id that matches a
2123  * specific device.
2124  */
2125 #define USB_DEVICE(vend, prod) \
2126 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
2127 	.idVendor = (vend), \
2128 	.idProduct = (prod)
2129 
2130 /**
2131  * USB_DEVICE_VER - describe a specific usb device with a version range
2132  * @vend: the 16 bit USB Vendor ID
2133  * @prod: the 16 bit USB Product ID
2134  * @lo: the bcdDevice_lo value
2135  * @hi: the bcdDevice_hi value
2136  *
2137  * This macro is used to create a struct usb_device_id that matches a
2138  * specific device, with a version range.
2139  */
2140 #define USB_DEVICE_VER(vend, prod, lo, hi) \
2141 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \
2142 	.idVendor = (vend), \
2143 	.idProduct = (prod), \
2144 	.bcdDevice_lo = (lo), \
2145 	.bcdDevice_hi = (hi)
2146 
2147 /**
2148  * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces
2149  * @cl: bInterfaceClass value
2150  * @sc: bInterfaceSubClass value
2151  * @pr: bInterfaceProtocol value
2152  *
2153  * This macro is used to create a struct usb_device_id that matches a
2154  * specific class of interfaces.
2155  */
2156 #define USB_INTERFACE_INFO(cl, sc, pr) \
2157 	.match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \
2158 	.bInterfaceClass = (cl), \
2159 	.bInterfaceSubClass = (sc), \
2160 	.bInterfaceProtocol = (pr)
2161 
2162 typedef enum{
2163 	USB_INIT_NONE = -1,
2164 	USB_INIT_OK = 0,
2165 	USB_INIT_FAIL = 1,
2166 	USB_NOT_ATTACHED = 2
2167 }_usb_init_s;
2168 
2169 struct usb_driver {
2170 	const char *name;
2171 
2172 	int (*probe) (struct usb_interface *intf);
2173 
2174 	void (*disconnect) (struct usb_interface *intf);
2175 
2176 	int (*resume) (struct usb_interface *intf);
2177 	int (*reset_resume)(struct usb_interface *intf);
2178 
2179 	int (*pre_reset)(struct usb_interface *intf);
2180 	int (*post_reset)(struct usb_interface *intf);
2181 
2182 	const struct usb_device_id *id_table;
2183     _list list;
2184 };
2185 
2186 int usb_register_class_driver(struct usb_driver *driver);
2187 #endif /* _USB_H_ */
2188