xref: /reactos/drivers/usb/usbport/usbport.h (revision 58aee30e)
1 /*
2  * PROJECT:     ReactOS USB Port Driver
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     USBPort declarations
5  * COPYRIGHT:   Copyright 2017 Vadim Galyant <vgal@rambler.ru>
6  */
7 
8 #ifndef USBPORT_H__
9 #define USBPORT_H__
10 
11 #include <ntddk.h>
12 #include <windef.h>
13 #include <stdio.h>
14 #include <wdmguid.h>
15 #include <ntstrsafe.h>
16 #include <usb.h>
17 #include <hubbusif.h>
18 #include <usbbusif.h>
19 #include <usbdlib.h>
20 #include <usbuser.h>
21 #include <drivers/usbport/usbmport.h>
22 
23 #define PCI_INTERFACE_USB_ID_UHCI 0x00
24 #define PCI_INTERFACE_USB_ID_OHCI 0x10
25 #define PCI_INTERFACE_USB_ID_EHCI 0x20
26 #define PCI_INTERFACE_USB_ID_XHCI 0x30
27 
28 #ifdef USBD_TRANSFER_DIRECTION // due hubbusif.h included usbdi.h (Which overwrites...)
29 #undef USBD_TRANSFER_DIRECTION
30 #define USBD_TRANSFER_DIRECTION 0x00000001
31 #endif
32 
33 #define USBPORT_RECIPIENT_HUB  BMREQUEST_TO_DEVICE
34 #define USBPORT_RECIPIENT_PORT BMREQUEST_TO_OTHER
35 
36 #define INVALIDATE_ENDPOINT_ONLY           0
37 #define INVALIDATE_ENDPOINT_WORKER_THREAD  1
38 #define INVALIDATE_ENDPOINT_WORKER_DPC     2
39 #define INVALIDATE_ENDPOINT_INT_NEXT_SOF   3
40 
41 #define USBPORT_DMA_DIRECTION_FROM_DEVICE 1
42 #define USBPORT_DMA_DIRECTION_TO_DEVICE   2
43 
44 #define USB_PORT_TAG 'pbsu'
45 #define URB_FUNCTION_MAX 0x31
46 
47 /* Hub Class Feature Selectors (Recipient - Port) */
48 #define FEATURE_PORT_CONNECTION     0
49 #define FEATURE_PORT_ENABLE         1
50 #define FEATURE_PORT_SUSPEND        2
51 #define FEATURE_PORT_OVER_CURRENT   3
52 #define FEATURE_PORT_RESET          4
53 #define FEATURE_PORT_POWER          8
54 #define FEATURE_PORT_LOW_SPEED      9
55 #define FEATURE_C_PORT_CONNECTION   16
56 #define FEATURE_C_PORT_ENABLE       17
57 #define FEATURE_C_PORT_SUSPEND      18
58 #define FEATURE_C_PORT_OVER_CURRENT 19
59 #define FEATURE_C_PORT_RESET        20
60 
61 /* Hub Class Feature Selectors (Recipient - Hub) */
62 #define FEATURE_C_HUB_LOCAL_POWER  0
63 #define FEATURE_C_HUB_OVER_CURRENT 1
64 
65 /* Flags */
66 #define USBPORT_FLAG_INT_CONNECTED     0x00000001
67 #define USBPORT_FLAG_HC_STARTED        0x00000002
68 #define USBPORT_FLAG_HC_POLLING        0x00000004
69 #define USBPORT_FLAG_WORKER_THREAD_ON  0x00000008
70 #define USBPORT_FLAG_HC_SUSPEND        0x00000100
71 #define USBPORT_FLAG_INTERRUPT_ENABLED 0x00000400
72 #define USBPORT_FLAG_SELECTIVE_SUSPEND 0x00000800
73 #define USBPORT_FLAG_DOS_SYMBOLIC_NAME 0x00010000
74 #define USBPORT_FLAG_LEGACY_SUPPORT    0x00080000
75 #define USBPORT_FLAG_HC_WAKE_SUPPORT   0x00200000
76 #define USBPORT_FLAG_DIAGNOSTIC_MODE   0x00800000 //IOCTL_USB_DIAGNOSTIC_MODE_ON
77 #define USBPORT_FLAG_COMPANION_HC      0x01000000
78 #define USBPORT_FLAG_REGISTERED_FDO    0x02000000
79 #define USBPORT_FLAG_NO_HACTION        0x04000000
80 #define USBPORT_FLAG_BIOS_DISABLE_SS   0x08000000 //Selective Suspend
81 #define USBPORT_FLAG_PWR_AND_CHIRP_LOCK 0x10000000
82 #define USBPORT_FLAG_POWER_AND_CHIRP_OK 0x40000000
83 #define USBPORT_FLAG_RH_INIT_CALLBACK  0x80000000
84 
85 /* PnP state Flags */
86 #define USBPORT_PNP_STATE_NOT_INIT  0x00000001
87 #define USBPORT_PNP_STATE_STARTED   0x00000002
88 #define USBPORT_PNP_STATE_FAILED    0x00000004
89 #define USBPORT_PNP_STATE_STOPPED   0x00000008
90 
91 /* Timer Flags */
92 #define USBPORT_TMFLAG_TIMER_QUEUED       0x00000001
93 #define USBPORT_TMFLAG_HC_SUSPENDED       0x00000002
94 #define USBPORT_TMFLAG_HC_RESUME          0x00000004
95 #define USBPORT_TMFLAG_RH_SUSPENDED       0x00000008
96 #define USBPORT_TMFLAG_TIMER_STARTED      0x00000010
97 #define USBPORT_TMFLAG_WAKE               0x00000020
98 #define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON  0x00000040
99 
100 /* Miniport Flags */
101 #define USBPORT_MPFLAG_INTERRUPTS_ENABLED  0x00000001
102 #define USBPORT_MPFLAG_SUSPENDED           0x00000002
103 
104 /* Device handle Flags (USBPORT_DEVICE_HANDLE) */
105 #define DEVICE_HANDLE_FLAG_ROOTHUB     0x00000002
106 #define DEVICE_HANDLE_FLAG_REMOVED     0x00000008
107 #define DEVICE_HANDLE_FLAG_USB2HUB     0x00000010
108 
109 /* Endpoint Flags (USBPORT_ENDPOINT) */
110 #define ENDPOINT_FLAG_DMA_TYPE      0x00000001
111 #define ENDPOINT_FLAG_ROOTHUB_EP0   0x00000002
112 #define ENDPOINT_FLAG_NUKE          0x00000008
113 #define ENDPOINT_FLAG_QUEUENE_EMPTY 0x00000010
114 #define ENDPOINT_FLAG_ABORTING      0x00000020
115 #define ENDPOINT_FLAG_IDLE          0x00000100
116 #define ENDPOINT_FLAG_OPENED        0x00000200
117 #define ENDPOINT_FLAG_CLOSED        0x00000400
118 
119 /* UsbdFlags Flags (URB) */
120 #define USBD_FLAG_ALLOCATED_MDL      0x00000002
121 #define USBD_FLAG_NOT_ISO_TRANSFER   0x00000010
122 #define USBD_FLAG_ALLOCATED_TRANSFER 0x00000020
123 
124 /* Pipe handle Flags (USBPORT_PIPE_HANDLE) */
125 #define PIPE_HANDLE_FLAG_CLOSED 0x00000001
126 #define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE 0x00000002
127 
128 /* Transfer Flags (USBPORT_TRANSFER) */
129 #define TRANSFER_FLAG_CANCELED   0x00000001
130 #define TRANSFER_FLAG_DMA_MAPPED 0x00000002
131 #define TRANSFER_FLAG_HIGH_SPEED 0x00000004
132 #define TRANSFER_FLAG_SUBMITED   0x00000008
133 #define TRANSFER_FLAG_ABORTED    0x00000010
134 #define TRANSFER_FLAG_ISO        0x00000020
135 #define TRANSFER_FLAG_DEVICE_GONE 0x00000080
136 #define TRANSFER_FLAG_SPLITED    0x00000100
137 #define TRANSFER_FLAG_COMPLETED  0x00000200
138 #define TRANSFER_FLAG_PARENT     0x00000400
139 
140 extern KSPIN_LOCK USBPORT_SpinLock;
141 extern LIST_ENTRY USBPORT_MiniPortDrivers;
142 
143 typedef USBD_STATUS* PUSBD_STATUS;
144 
145 typedef struct _USBPORT_COMMON_BUFFER_HEADER {
146   ULONG Length;
147   ULONG_PTR BaseVA;
148   PHYSICAL_ADDRESS LogicalAddress;
149   SIZE_T BufferLength;
150   ULONG_PTR VirtualAddress;
151   ULONG PhysicalAddress;
152 } USBPORT_COMMON_BUFFER_HEADER, *PUSBPORT_COMMON_BUFFER_HEADER;
153 
154 typedef struct _USBPORT_ENDPOINT *PUSBPORT_ENDPOINT;
155 
156 typedef struct _USB2_HC_EXTENSION *PUSB2_HC_EXTENSION;
157 typedef struct _USB2_TT_EXTENSION *PUSB2_TT_EXTENSION;
158 typedef struct _USB2_TT *PUSB2_TT;
159 typedef struct _USB2_TT_ENDPOINT *PUSB2_TT_ENDPOINT;
160 
161 typedef struct _USBPORT_PIPE_HANDLE {
162   ULONG Flags;
163   ULONG PipeFlags;
164   USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
165   UCHAR Padded;
166   PUSBPORT_ENDPOINT Endpoint;
167   LIST_ENTRY PipeLink;
168 } USBPORT_PIPE_HANDLE, *PUSBPORT_PIPE_HANDLE;
169 
170 typedef struct _USBPORT_CONFIGURATION_HANDLE {
171   PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
172   LIST_ENTRY InterfaceHandleList;
173   //USB_CONFIGURATION_DESCRIPTOR CfgDescriptor; // Body.
174 } USBPORT_CONFIGURATION_HANDLE, *PUSBPORT_CONFIGURATION_HANDLE;
175 
176 typedef struct _USBPORT_INTERFACE_HANDLE {
177   LIST_ENTRY InterfaceLink;
178   UCHAR AlternateSetting;
179   UCHAR Pad1[3];
180   USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
181   UCHAR Pad2[3];
182   USBPORT_PIPE_HANDLE PipeHandle[1];
183 } USBPORT_INTERFACE_HANDLE, *PUSBPORT_INTERFACE_HANDLE;
184 
185 typedef struct _USBPORT_DEVICE_HANDLE {
186   ULONG Flags;
187   USHORT DeviceAddress;
188   USHORT PortNumber;
189   USBPORT_PIPE_HANDLE PipeHandle;
190   ULONG DeviceSpeed;
191   BOOL IsRootHub;
192   LIST_ENTRY PipeHandleList;
193   PUSBPORT_CONFIGURATION_HANDLE ConfigHandle;
194   struct _USBPORT_DEVICE_HANDLE *HubDeviceHandle;
195   USB_DEVICE_DESCRIPTOR DeviceDescriptor;
196   LIST_ENTRY DeviceHandleLink;
197   LONG DeviceHandleLock;
198   ULONG TtCount;
199   PUSB2_TT_EXTENSION TtExtension; // Transaction Translator
200   LIST_ENTRY TtList;
201 } USBPORT_DEVICE_HANDLE, *PUSBPORT_DEVICE_HANDLE;
202 
203 typedef struct _USBPORT_ENDPOINT {
204   ULONG Flags;
205   PDEVICE_OBJECT FdoDevice;
206   PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
207   PUSBPORT_DEVICE_HANDLE DeviceHandle;
208   PUSB2_TT_EXTENSION TtExtension; // Transaction Translator
209   PUSB2_TT_ENDPOINT TtEndpoint;
210   USBPORT_ENDPOINT_PROPERTIES EndpointProperties;
211   ULONG EndpointWorker;
212   ULONG FrameNumber;
213   /* Locks */
214   KSPIN_LOCK EndpointSpinLock;
215   KIRQL EndpointOldIrql;
216   KIRQL EndpointStateOldIrql;
217   UCHAR Padded[2];
218   LONG LockCounter;
219   LONG FlushPendingLock;
220   /* State */
221   ULONG StateLast;
222   ULONG StateNext;
223   LIST_ENTRY StateChangeLink;
224   KSPIN_LOCK StateChangeSpinLock;
225   /* Transfer lists */
226   LIST_ENTRY PendingTransferList;
227   LIST_ENTRY TransferList;
228   LIST_ENTRY CancelList;
229   LIST_ENTRY AbortList;
230   /* Links */
231   LIST_ENTRY EndpointLink;
232   LIST_ENTRY WorkerLink;
233   LIST_ENTRY CloseLink;
234   LIST_ENTRY DispatchLink;
235   LIST_ENTRY FlushLink;
236   LIST_ENTRY FlushControllerLink;
237   LIST_ENTRY FlushAbortLink;
238   LIST_ENTRY TtLink;
239   LIST_ENTRY RebalanceLink;
240 } USBPORT_ENDPOINT, *PUSBPORT_ENDPOINT;
241 
242 typedef struct _USBPORT_ISO_BLOCK *PUSBPORT_ISO_BLOCK;
243 
244 typedef struct _USBPORT_TRANSFER {
245   ULONG Flags;
246   PIRP Irp;
247   PURB Urb;
248   PRKEVENT Event;
249   PVOID MiniportTransfer;
250   SIZE_T PortTransferLength; // Only port part
251   SIZE_T FullTransferLength; // Port + miniport
252   PUSBPORT_ENDPOINT Endpoint;
253   USBPORT_TRANSFER_PARAMETERS TransferParameters;
254   PMDL TransferBufferMDL;
255   ULONG Direction;
256   LIST_ENTRY TransferLink;
257   USBD_STATUS USBDStatus;
258   ULONG CompletedTransferLen;
259   ULONG NumberOfMapRegisters;
260   PVOID MapRegisterBase;
261   ULONG TimeOut;
262   LARGE_INTEGER Time;
263   struct _USBPORT_TRANSFER * ParentTransfer;
264   KSPIN_LOCK TransferSpinLock;
265   LIST_ENTRY SplitTransfersList; // for parent transfers
266   LIST_ENTRY SplitLink; // for splitted transfers
267   ULONG Period;
268   PUSBPORT_ISO_BLOCK IsoBlockPtr; // pointer on IsoBlock
269   // SgList should be LAST field
270   USBPORT_SCATTER_GATHER_LIST SgList; // variable length
271   //USBPORT_ISO_BLOCK IsoBlock; // variable length
272 } USBPORT_TRANSFER, *PUSBPORT_TRANSFER;
273 
274 typedef struct _USBPORT_IRP_TABLE {
275   struct _USBPORT_IRP_TABLE * LinkNextTable;
276   PIRP irp[0X200];
277 } USBPORT_IRP_TABLE, *PUSBPORT_IRP_TABLE;
278 
279 typedef struct _USBPORT_COMMON_DEVICE_EXTENSION {
280   PDEVICE_OBJECT SelfDevice;
281   PDEVICE_OBJECT LowerPdoDevice; // PhysicalDeviceObject
282   PDEVICE_OBJECT LowerDevice; // TopOfStackDeviceObject
283   ULONG IsPDO;
284   UNICODE_STRING SymbolicLinkName;
285   BOOL IsInterfaceEnabled;
286   DEVICE_POWER_STATE DevicePowerState;
287   ULONG PnpStateFlags;
288 } USBPORT_COMMON_DEVICE_EXTENSION, *PUSBPORT_COMMON_DEVICE_EXTENSION;
289 
290 typedef struct _USBPORT_DEVICE_EXTENSION {
291   USBPORT_COMMON_DEVICE_EXTENSION CommonExtension;
292   ULONG Flags;
293   PDEVICE_OBJECT RootHubPdo; // RootHubDeviceObject
294   KSPIN_LOCK RootHubCallbackSpinLock;
295   LONG RHInitCallBackLock;
296   LONG ChirpRootPortLock;
297   KSEMAPHORE ControllerSemaphore;
298   ULONG FdoNameNumber;
299   UNICODE_STRING DosDeviceSymbolicName;
300   ULONG UsbBIOSx;
301   LIST_ENTRY ControllerLink;
302   ULONG CommonBufferLimit;
303   /* Miniport */
304   ULONG MiniPortFlags;
305   PVOID MiniPortExt;
306   PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
307   USBPORT_RESOURCES UsbPortResources;
308   PUSBPORT_COMMON_BUFFER_HEADER MiniPortCommonBuffer;
309   KSPIN_LOCK MiniportSpinLock;
310   /* Bus Interface */
311   BUS_INTERFACE_STANDARD BusInterface;
312   USHORT VendorID;
313   USHORT DeviceID;
314   UCHAR RevisionID;
315   UCHAR ProgIf;
316   UCHAR SubClass;
317   UCHAR BaseClass;
318   /* Dma Adapter */
319   PDMA_ADAPTER DmaAdapter;
320   ULONG NumberMapRegs;
321   /* Interrupt */
322   PKINTERRUPT InterruptObject;
323   KDPC IsrDpc;
324   LONG IsrDpcCounter;
325   LONG IsrDpcHandlerCounter;
326   KSPIN_LOCK MiniportInterruptsSpinLock;
327   KTIMER TimerSoftInterrupt;
328   KDPC SoftInterruptDpc;
329   /* Endpoints */
330   ULONG PeriodicEndpoints;
331   LIST_ENTRY EndpointList;
332   KSPIN_LOCK EndpointListSpinLock;
333   LIST_ENTRY EpStateChangeList;
334   KSPIN_LOCK EpStateChangeSpinLock;
335   LIST_ENTRY EndpointClosedList;
336   KSPIN_LOCK EndpointClosedSpinLock;
337   LIST_ENTRY WorkerList;
338   /* Transfers */
339   LIST_ENTRY MapTransferList;
340   KSPIN_LOCK MapTransferSpinLock;
341   LIST_ENTRY DoneTransferList;
342   KSPIN_LOCK DoneTransferSpinLock;
343   KDPC TransferFlushDpc;
344   KSPIN_LOCK FlushTransferSpinLock;
345   KSPIN_LOCK FlushPendingTransferSpinLock;
346   /* Timer */
347   ULONG TimerValue; // Timer period (500) msec. default
348   ULONG TimerFlags;
349   KTIMER TimerObject;
350   KDPC TimerDpc;
351   KSPIN_LOCK TimerFlagsSpinLock;
352   /* Worker Thread */
353   PRKTHREAD WorkerThread;
354   HANDLE WorkerThreadHandle;
355   KEVENT WorkerThreadEvent;
356   KSPIN_LOCK WorkerThreadEventSpinLock;
357   /* Usb Devices */
358   ULONG UsbAddressBitMap[4];
359   LIST_ENTRY DeviceHandleList;
360   KSPIN_LOCK DeviceHandleSpinLock;
361   KSEMAPHORE DeviceSemaphore;
362   /* Device Capabilities */
363   DEVICE_CAPABILITIES Capabilities;
364   ULONG BusNumber;
365   ULONG PciDeviceNumber;
366   ULONG PciFunctionNumber;
367   ULONG TotalBusBandwidth;
368   /* Idle */
369   LARGE_INTEGER IdleTime;
370   IO_CSQ IdleIoCsq;
371   KSPIN_LOCK IdleIoCsqSpinLock;
372   LIST_ENTRY IdleIrpList;
373   LONG IdleLockCounter;
374   /* Bad Requests */
375   IO_CSQ BadRequestIoCsq;
376   KSPIN_LOCK BadRequestIoCsqSpinLock;
377   LIST_ENTRY BadRequestList;
378   LONG BadRequestLockCounter;
379   /* Irp Queues */
380   PUSBPORT_IRP_TABLE PendingIrpTable;
381   PUSBPORT_IRP_TABLE ActiveIrpTable;
382   /* Power */
383   LONG SetPowerLockCounter;
384   KSPIN_LOCK PowerWakeSpinLock;
385   KSPIN_LOCK SetPowerD0SpinLock;
386   KDPC WorkerRequestDpc;
387   KDPC HcWakeDpc;
388   /* Usb 2.0 HC Extension */
389   PUSB2_HC_EXTENSION Usb2Extension;
390   ULONG Bandwidth[32];
391   KSPIN_LOCK TtSpinLock;
392 
393   /* Miniport extension should be aligned on 0x100 */
394 #if !defined(_M_X64)
395   ULONG Padded[64];
396 #else
397   ULONG Padded[30];
398 #endif
399 
400 } USBPORT_DEVICE_EXTENSION, *PUSBPORT_DEVICE_EXTENSION;
401 
402 #if !defined(_M_X64)
403 C_ASSERT(sizeof(USBPORT_DEVICE_EXTENSION) == 0x500);
404 #else
405 C_ASSERT(sizeof(USBPORT_DEVICE_EXTENSION) == 0x700);
406 #endif
407 
408 typedef struct _USBPORT_RH_DESCRIPTORS {
409   USB_DEVICE_DESCRIPTOR DeviceDescriptor;
410   USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
411   USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
412   USB_ENDPOINT_DESCRIPTOR EndPointDescriptor;
413   USB_HUB_DESCRIPTOR Descriptor; // Size may be: 7 + 2[1..32] (7 + 2..64)
414 } USBPORT_RH_DESCRIPTORS, *PUSBPORT_RH_DESCRIPTORS;
415 
416 typedef struct _USBPORT_RHDEVICE_EXTENSION {
417   USBPORT_COMMON_DEVICE_EXTENSION CommonExtension;
418   ULONG Flags;
419   PDEVICE_OBJECT FdoDevice;
420   ULONG PdoNameNumber;
421   USBPORT_DEVICE_HANDLE DeviceHandle;
422   PUSBPORT_RH_DESCRIPTORS RootHubDescriptors;
423   PUSBPORT_ENDPOINT Endpoint;
424   ULONG ConfigurationValue;
425   PRH_INIT_CALLBACK RootHubInitCallback;
426   PVOID RootHubInitContext;
427   DEVICE_CAPABILITIES Capabilities;
428   PIRP WakeIrp;
429 } USBPORT_RHDEVICE_EXTENSION, *PUSBPORT_RHDEVICE_EXTENSION;
430 
431 typedef struct _USBPORT_ASYNC_CALLBACK_DATA {
432   ULONG Reserved;
433   PDEVICE_OBJECT FdoDevice;
434   KTIMER AsyncTimer;
435   KDPC AsyncTimerDpc;
436   ASYNC_TIMER_CALLBACK *CallbackFunction;
437   ULONG CallbackContext;
438 } USBPORT_ASYNC_CALLBACK_DATA, *PUSBPORT_ASYNC_CALLBACK_DATA;
439 
440 C_ASSERT(sizeof(USBPORT_ASYNC_CALLBACK_DATA) == 16 + 18 * sizeof(PVOID));
441 
442 typedef struct _TIMER_WORK_QUEUE_ITEM {
443   WORK_QUEUE_ITEM WqItem;
444   PDEVICE_OBJECT FdoDevice;
445   ULONG Context;
446 } TIMER_WORK_QUEUE_ITEM, *PTIMER_WORK_QUEUE_ITEM;
447 
448 /* Transaction Translator */
449 /* See Chapter 5 - USB Data Flow Model and Chapter 11 - Hub Specification */
450 
451 #define USB2_FRAMES           32
452 #define USB2_MICROFRAMES      8
453 #define USB2_MAX_MICROFRAMES  (USB2_FRAMES * USB2_MICROFRAMES)
454 #define USB2_PREV_MICROFRAME  0xFF
455 
456 #define USB2_MAX_MICROFRAME_ALLOCATION         7000 // bytes
457 #define USB2_CONTROLLER_DELAY                  100
458 #define USB2_FS_MAX_PERIODIC_ALLOCATION        1157 // ((12000 / 8 bits) * 0.9) / (7/6) - 90% max, and bits stuffing
459 #define USB2_FS_SOF_TIME                       6
460 #define USB2_HUB_DELAY                         30
461 #define USB2_MAX_FS_LS_TRANSACTIONS_IN_UFRAME  16
462 #define USB2_FS_RAW_BYTES_IN_MICROFRAME        188  // (12000 / 8 bits / USB2_MICROFRAMES) = 187,5. But we use "best case budget"
463 
464 /* Overheads */
465 #define USB2_LS_INTERRUPT_OVERHEAD             117 // FS-bytes
466 #define USB2_FS_INTERRUPT_OVERHEAD             13
467 #define USB2_HS_INTERRUPT_OUT_OVERHEAD         45
468 #define USB2_HS_INTERRUPT_IN_OVERHEAD          25
469 #define USB2_FS_ISOCHRONOUS_OVERHEAD           9
470 #define USB2_HS_ISOCHRONOUS_OUT_OVERHEAD       38
471 #define USB2_HS_ISOCHRONOUS_IN_OVERHEAD        18
472 
473 #define USB2_HS_SS_INTERRUPT_OUT_OVERHEAD      58
474 #define USB2_HS_CS_INTERRUPT_OUT_OVERHEAD      36
475 #define USB2_HS_SS_INTERRUPT_IN_OVERHEAD       39
476 #define USB2_HS_CS_INTERRUPT_IN_OVERHEAD       38
477 
478 #define USB2_HS_SS_ISOCHRONOUS_OUT_OVERHEAD    58
479 #define USB2_HS_SS_ISOCHRONOUS_IN_OVERHEAD     39
480 #define USB2_HS_CS_ISOCHRONOUS_IN_OVERHEAD     38
481 
482 #define USB2_BIT_STUFFING_OVERHEAD  (8 * (7/6)) // 7.1.9 Bit Stuffing
483 
484 typedef union _USB2_TT_ENDPOINT_PARAMS {
485   struct {
486     ULONG TransferType           : 4;
487     ULONG Direction              : 1;
488     USB_DEVICE_SPEED DeviceSpeed : 2;
489     BOOL EndpointMoved           : 1;
490     ULONG Reserved               : 24;
491   };
492   ULONG AsULONG;
493 } USB2_TT_ENDPOINT_PARAMS;
494 
495 C_ASSERT(sizeof(USB2_TT_ENDPOINT_PARAMS) == sizeof(ULONG));
496 
497 typedef union _USB2_TT_ENDPOINT_NUMS {
498   struct {
499     ULONG NumStarts     : 4;
500     ULONG NumCompletes  : 4;
501     ULONG Reserved      : 24;
502   };
503   ULONG AsULONG;
504 } USB2_TT_ENDPOINT_NUMS;
505 
506 C_ASSERT(sizeof(USB2_TT_ENDPOINT_NUMS) == sizeof(ULONG));
507 
508 typedef struct _USB2_TT_ENDPOINT {
509   PUSB2_TT Tt;
510   PUSBPORT_ENDPOINT Endpoint;
511   struct _USB2_TT_ENDPOINT * NextTtEndpoint;
512   USB2_TT_ENDPOINT_PARAMS TtEndpointParams;
513   USB2_TT_ENDPOINT_NUMS Nums;
514   BOOL IsPromoted;
515   USHORT MaxPacketSize;
516   USHORT PreviosPeriod;
517   USHORT Period;
518   USHORT ActualPeriod;
519   USHORT CalcBusTime;
520   USHORT StartTime;
521   USHORT Reserved2;
522   UCHAR StartFrame;
523   UCHAR StartMicroframe;
524 } USB2_TT_ENDPOINT, *PUSB2_TT_ENDPOINT;
525 
526 typedef struct _USB2_FRAME_BUDGET {
527   PUSB2_TT_ENDPOINT IsoEndpoint;
528   PUSB2_TT_ENDPOINT IntEndpoint;
529   PUSB2_TT_ENDPOINT AltEndpoint;
530   USHORT TimeUsed;
531   USHORT Reserved2;
532 } USB2_FRAME_BUDGET, *PUSB2_FRAME_BUDGET;
533 
534 typedef struct _USB2_TT {
535   PUSB2_HC_EXTENSION HcExtension;
536   ULONG DelayTime;
537   ULONG MaxTime;
538   USB2_TT_ENDPOINT IntEndpoint[USB2_FRAMES];
539   USB2_TT_ENDPOINT IsoEndpoint[USB2_FRAMES];
540   USB2_FRAME_BUDGET FrameBudget[USB2_FRAMES];
541   ULONG NumStartSplits[USB2_FRAMES][USB2_MICROFRAMES];
542   ULONG TimeCS[USB2_FRAMES][USB2_MICROFRAMES];
543 } USB2_TT, *PUSB2_TT;
544 
545 #define USB2_TT_EXTENSION_FLAG_DELETED  1
546 
547 typedef struct _USB2_TT_EXTENSION {
548   PDEVICE_OBJECT RootHubPdo;
549   ULONG Flags;
550   ULONG BusBandwidth;
551   ULONG Bandwidth[USB2_FRAMES];
552   ULONG MaxBandwidth;
553   ULONG MinBandwidth;
554   USHORT DeviceAddress;
555   USHORT TtNumber;
556   LIST_ENTRY EndpointList;
557   LIST_ENTRY Link;
558   USB2_TT Tt;
559 } USB2_TT_EXTENSION, *PUSB2_TT_EXTENSION;
560 
561 typedef struct _USB2_HC_EXTENSION {
562   ULONG MaxHsBusAllocation;
563   ULONG HcDelayTime;
564   ULONG TimeUsed[USB2_FRAMES][USB2_MICROFRAMES];
565   USB2_TT HcTt;
566 } USB2_HC_EXTENSION, *PUSB2_HC_EXTENSION;
567 
568 typedef struct _USB2_REBALANCE {
569   PUSB2_TT_ENDPOINT RebalanceEndpoint[USB2_FRAMES - 2];
570 } USB2_REBALANCE, *PUSB2_REBALANCE;
571 
572 /* usbport.c */
573 NTSTATUS
574 NTAPI
575 USBPORT_USBDStatusToNtStatus(
576   IN PURB Urb,
577   IN USBD_STATUS USBDStatus);
578 
579 NTSTATUS
580 NTAPI
581 USBPORT_Wait(
582   IN PVOID MiniPortExtension,
583   IN ULONG Milliseconds);
584 
585 VOID
586 NTAPI
587 USBPORT_TransferFlushDpc(
588   IN PRKDPC Dpc,
589   IN PVOID DeferredContext,
590   IN PVOID SystemArgument1,
591   IN PVOID SystemArgument2);
592 
593 NTSTATUS
594 NTAPI
595 USBPORT_CreateWorkerThread(
596   IN PDEVICE_OBJECT FdoDevice);
597 
598 BOOLEAN
599 NTAPI
600 USBPORT_StartTimer(
601   IN PDEVICE_OBJECT FdoDevice,
602   IN ULONG Time);
603 
604 PUSBPORT_COMMON_BUFFER_HEADER
605 NTAPI
606 USBPORT_AllocateCommonBuffer(
607   IN PDEVICE_OBJECT FdoDevice,
608   IN SIZE_T BufferLength);
609 
610 VOID
611 NTAPI
612 USBPORT_FreeCommonBuffer(
613   IN PDEVICE_OBJECT FdoDevice,
614   IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer);
615 
616 USBD_STATUS
617 NTAPI
618 USBPORT_AllocateTransfer(
619   IN PDEVICE_OBJECT FdoDevice,
620   IN PURB Urb,
621   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
622   IN PIRP Irp,
623   IN PRKEVENT Event);
624 
625 VOID
626 NTAPI
627 USBPORT_FlushMapTransfers(
628   IN PDEVICE_OBJECT FdoDevice);
629 
630 VOID
631 NTAPI
632 USBPORT_IsrDpc(
633   IN PRKDPC Dpc,
634   IN PVOID DeferredContext,
635   IN PVOID SystemArgument1,
636   IN PVOID SystemArgument2);
637 
638 BOOLEAN
639 NTAPI
640 USBPORT_InterruptService(
641   IN PKINTERRUPT Interrupt,
642   IN PVOID ServiceContext);
643 
644 VOID
645 NTAPI
646 USBPORT_SignalWorkerThread(
647   IN PDEVICE_OBJECT FdoDevice);
648 
649 VOID
650 NTAPI
651 USBPORT_CompleteTransfer(
652   IN PURB Urb,
653   IN USBD_STATUS TransferStatus);
654 
655 VOID
656 NTAPI
657 USBPORT_DpcHandler(
658   IN PDEVICE_OBJECT FdoDevice);
659 
660 VOID
661 NTAPI
662 USBPORT_WorkerRequestDpc(
663   IN PRKDPC Dpc,
664   IN PVOID DeferredContext,
665   IN PVOID SystemArgument1,
666   IN PVOID SystemArgument2);
667 
668 BOOLEAN
669 NTAPI
670 USBPORT_QueueDoneTransfer(
671   IN PUSBPORT_TRANSFER Transfer,
672   IN USBD_STATUS USBDStatus);
673 
674 VOID
675 NTAPI
676 USBPORT_MiniportInterrupts(
677   IN PDEVICE_OBJECT FdoDevice,
678   IN BOOLEAN IsEnable);
679 
680 NTSTATUS
681 NTAPI
682 USBPORT_SetRegistryKeyValue(
683   IN PDEVICE_OBJECT DeviceObject,
684   IN BOOL UseDriverKey,
685   IN ULONG Type,
686   IN PCWSTR ValueNameString,
687   IN PVOID Data,
688   IN ULONG DataSize);
689 
690 NTSTATUS
691 NTAPI
692 USBPORT_GetRegistryKeyValueFullInfo(
693   IN PDEVICE_OBJECT FdoDevice,
694   IN PDEVICE_OBJECT PdoDevice,
695   IN BOOL UseDriverKey,
696   IN PCWSTR SourceString,
697   IN ULONG LengthStr,
698   IN PVOID Buffer,
699   IN ULONG NumberOfBytes);
700 
701 VOID
702 NTAPI
703 USBPORT_AddUSB1Fdo(
704   IN PDEVICE_OBJECT FdoDevice);
705 
706 VOID
707 NTAPI
708 USBPORT_AddUSB2Fdo(
709   IN PDEVICE_OBJECT FdoDevice);
710 
711 VOID
712 NTAPI
713 USBPORT_RemoveUSBxFdo(
714   IN PDEVICE_OBJECT FdoDevice);
715 
716 PDEVICE_OBJECT
717 NTAPI
718 USBPORT_FindUSB2Controller(
719   IN PDEVICE_OBJECT FdoDevice);
720 
721 PDEVICE_RELATIONS
722 NTAPI
723 USBPORT_FindCompanionControllers(
724   IN PDEVICE_OBJECT USB2FdoDevice,
725   IN BOOLEAN IsObRefer,
726   IN BOOLEAN IsFDOsReturned);
727 
728 VOID
729 NTAPI
730 USBPORT_InvalidateControllerHandler(
731   IN PDEVICE_OBJECT FdoDevice,
732   IN ULONG Type);
733 
734 VOID
735 NTAPI
736 USBPORT_DoneTransfer(
737   IN PUSBPORT_TRANSFER Transfer);
738 
739 /* debug.c */
740 ULONG
741 NTAPI
742 USBPORT_DbgPrint(
743   IN PVOID MiniPortExtension,
744   IN ULONG Level,
745   IN PCH Format,
746   ...);
747 
748 ULONG
749 NTAPI
750 USBPORT_TestDebugBreak(
751   IN PVOID MiniPortExtension);
752 
753 ULONG
754 NTAPI
755 USBPORT_AssertFailure(
756   PVOID MiniPortExtension,
757   PVOID FailedAssertion,
758   PVOID FileName,
759   ULONG LineNumber,
760   PCHAR Message);
761 
762 VOID
763 NTAPI
764 USBPORT_BugCheck(
765   IN PVOID MiniPortExtension);
766 
767 ULONG
768 NTAPI
769 USBPORT_LogEntry(
770   IN PVOID MiniPortExtension,
771   IN ULONG DriverTag,
772   IN ULONG EnumTag,
773   IN ULONG P1,
774   IN ULONG P2,
775   IN ULONG P3);
776 
777 VOID
778 NTAPI
779 USBPORT_DumpingDeviceDescriptor(
780   IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
781 
782 VOID
783 NTAPI
784 USBPORT_DumpingConfiguration(
785   IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor);
786 
787 VOID
788 NTAPI
789 USBPORT_DumpingCapabilities(
790   IN PDEVICE_CAPABILITIES Capabilities);
791 
792 VOID
793 NTAPI
794 USBPORT_DumpingSetupPacket(
795   IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket);
796 
797 VOID
798 NTAPI
799 USBPORT_DumpingURB(
800   IN PURB Urb);
801 
802 VOID
803 NTAPI
804 USBPORT_DumpingIDs(
805   IN PVOID Buffer);
806 
807 /* device.c */
808 NTSTATUS
809 NTAPI
810 USBPORT_HandleSelectConfiguration(
811   IN PDEVICE_OBJECT FdoDevice,
812   IN PIRP Irp,
813   IN PURB Urb);
814 
815 VOID
816 NTAPI
817 USBPORT_AddDeviceHandle(
818   IN PDEVICE_OBJECT FdoDevice,
819   IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
820 
821 VOID
822 NTAPI
823 USBPORT_RemoveDeviceHandle(
824   IN PDEVICE_OBJECT FdoDevice,
825   IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
826 
827 BOOLEAN
828 NTAPI
829 USBPORT_ValidateDeviceHandle(
830   IN PDEVICE_OBJECT FdoDevice,
831   IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
832 
833 NTSTATUS
834 NTAPI
835 USBPORT_CreateDevice(
836   IN OUT PUSB_DEVICE_HANDLE *pUsbdDeviceHandle,
837   IN PDEVICE_OBJECT FdoDevice,
838   IN PUSBPORT_DEVICE_HANDLE HubDeviceHandle,
839   IN USHORT PortStatus,
840   IN USHORT Port);
841 
842 NTSTATUS
843 NTAPI
844 USBPORT_InitializeDevice(
845   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
846   IN PDEVICE_OBJECT FdoDevice);
847 
848 NTSTATUS
849 NTAPI
850 USBPORT_GetUsbDescriptor(
851   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
852   IN PDEVICE_OBJECT FdoDevice,
853   IN UCHAR Type,
854   IN PUCHAR ConfigDesc,
855   IN PULONG ConfigDescSize);
856 
857 NTSTATUS
858 NTAPI
859 USBPORT_HandleSelectInterface(
860   IN PDEVICE_OBJECT FdoDevice,
861   IN PIRP Irp,
862   IN PURB Urb);
863 
864 NTSTATUS
865 NTAPI
866 USBPORT_RemoveDevice(
867   IN PDEVICE_OBJECT FdoDevice,
868   IN OUT PUSBPORT_DEVICE_HANDLE DeviceHandle,
869   IN ULONG Flags);
870 
871 NTSTATUS
872 NTAPI
873 USBPORT_SendSetupPacket(
874   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
875   IN PDEVICE_OBJECT FdoDevice,
876   IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket,
877   IN PVOID Buffer,
878   IN ULONG Length,
879   IN OUT PULONG TransferedLen,
880   IN OUT PUSBD_STATUS pUSBDStatus);
881 
882 NTSTATUS
883 NTAPI
884 USBPORT_RestoreDevice(
885   IN PDEVICE_OBJECT FdoDevice,
886   IN OUT PUSBPORT_DEVICE_HANDLE OldDeviceHandle,
887   IN OUT PUSBPORT_DEVICE_HANDLE NewDeviceHandle);
888 
889 NTSTATUS
890 NTAPI
891 USBPORT_Initialize20Hub(
892   IN PDEVICE_OBJECT FdoDevice,
893   IN PUSBPORT_DEVICE_HANDLE HubDeviceHandle,
894   IN ULONG TtCount);
895 
896 /* endpoint.c */
897 NTSTATUS
898 NTAPI
899 USBPORT_OpenPipe(
900   IN PDEVICE_OBJECT FdoDevice,
901   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
902   IN PUSBPORT_PIPE_HANDLE PipeHandle,
903   IN PUSBD_STATUS UsbdStatus);
904 
905 MPSTATUS
906 NTAPI
907 MiniportOpenEndpoint(
908   IN PDEVICE_OBJECT FdoDevice,
909   IN PUSBPORT_ENDPOINT Endpoint);
910 
911 NTSTATUS
912 NTAPI
913 USBPORT_ReopenPipe(
914   IN PDEVICE_OBJECT FdoDevice,
915   IN PUSBPORT_ENDPOINT Endpoint);
916 
917 VOID
918 NTAPI
919 USBPORT_ClosePipe(
920   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
921   IN PDEVICE_OBJECT FdoDevice,
922   IN PUSBPORT_PIPE_HANDLE PipeHandle);
923 
924 VOID
925 NTAPI
926 MiniportCloseEndpoint(
927   IN PDEVICE_OBJECT FdoDevice,
928   IN PUSBPORT_ENDPOINT Endpoint);
929 
930 VOID
931 NTAPI
932 USBPORT_AddPipeHandle(
933   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
934   IN PUSBPORT_PIPE_HANDLE PipeHandle);
935 
936 VOID
937 NTAPI
938 USBPORT_RemovePipeHandle(
939   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
940   IN PUSBPORT_PIPE_HANDLE PipeHandle);
941 
942 BOOLEAN
943 NTAPI
944 USBPORT_ValidatePipeHandle(
945   IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
946   IN PUSBPORT_PIPE_HANDLE PipeHandle);
947 
948 VOID
949 NTAPI
950 USBPORT_FlushClosedEndpointList(
951   IN PDEVICE_OBJECT FdoDevice);
952 
953 VOID
954 NTAPI
955 USBPORT_SetEndpointState(
956   IN PUSBPORT_ENDPOINT Endpoint,
957   IN ULONG State);
958 
959 ULONG
960 NTAPI
961 USBPORT_GetEndpointState(
962   IN PUSBPORT_ENDPOINT Endpoint);
963 
964 VOID
965 NTAPI
966 USBPORT_InvalidateEndpointHandler(
967   IN PDEVICE_OBJECT FdoDevice,
968   IN PUSBPORT_ENDPOINT Endpoint,
969   IN ULONG Type);
970 
971 BOOLEAN
972 NTAPI
973 USBPORT_EndpointWorker(
974   IN PUSBPORT_ENDPOINT Endpoint,
975   IN BOOLEAN Flag);
976 
977 VOID
978 NTAPI
979 USBPORT_NukeAllEndpoints(
980   IN PDEVICE_OBJECT FdoDevice);
981 
982 BOOLEAN
983 NTAPI
984 USBPORT_EndpointHasQueuedTransfers(
985   IN PDEVICE_OBJECT FdoDevice,
986   IN PUSBPORT_ENDPOINT Endpoint,
987   IN PULONG TransferCount);
988 
989 /* iface.c */
990 NTSTATUS
991 NTAPI
992 USBPORT_PdoQueryInterface(
993   IN PDEVICE_OBJECT FdoDevice,
994   IN PDEVICE_OBJECT PdoDevice,
995   IN PIRP Irp);
996 
997 /* ioctl.c */
998 NTSTATUS
999 NTAPI
1000 USBPORT_PdoDeviceControl(
1001   PDEVICE_OBJECT PdoDevice,
1002   PIRP Irp);
1003 
1004 NTSTATUS
1005 NTAPI
1006 USBPORT_FdoDeviceControl(
1007   PDEVICE_OBJECT FdoDevice,
1008   PIRP Irp);
1009 
1010 NTSTATUS
1011 NTAPI
1012 USBPORT_FdoInternalDeviceControl(
1013   IN PDEVICE_OBJECT FdoDevice,
1014   IN PIRP Irp);
1015 
1016 NTSTATUS
1017 NTAPI
1018 USBPORT_PdoInternalDeviceControl(
1019   IN PDEVICE_OBJECT FdoDevice,
1020   IN PIRP Irp);
1021 
1022 NTSTATUS
1023 NTAPI
1024 USBPORT_GetSymbolicName(
1025   IN PDEVICE_OBJECT RootHubPdo,
1026   IN PUNICODE_STRING DestinationString);
1027 
1028 /* iso.c */
1029 USBD_STATUS
1030 NTAPI
1031 USBPORT_InitializeIsoTransfer(
1032   IN PDEVICE_OBJECT FdoDevice,
1033   IN struct _URB_ISOCH_TRANSFER * Urb,
1034   IN PUSBPORT_TRANSFER Transfer);
1035 
1036 ULONG
1037 NTAPI
1038 USBPORT_CompleteIsoTransfer(
1039   IN PVOID MiniPortExtension,
1040   IN PVOID MiniPortEndpoint,
1041   IN PVOID TransferParameters,
1042   IN ULONG TransferLength);
1043 
1044 /* pnp.c */
1045 NTSTATUS
1046 NTAPI
1047 USBPORT_FdoPnP(
1048   IN PDEVICE_OBJECT FdoDevice,
1049   IN PIRP Irp);
1050 
1051 NTSTATUS
1052 NTAPI
1053 USBPORT_PdoPnP(
1054   IN PDEVICE_OBJECT FdoDevice,
1055   IN PIRP Irp);
1056 
1057 /* power.c */
1058 NTSTATUS
1059 NTAPI
1060 USBPORT_PdoPower(
1061   IN PDEVICE_OBJECT PdoDevice,
1062   IN PIRP Irp);
1063 
1064 NTSTATUS
1065 NTAPI
1066 USBPORT_FdoPower(
1067   IN PDEVICE_OBJECT FdoDevice,
1068   IN PIRP Irp);
1069 
1070 NTSTATUS
1071 NTAPI
1072 USBPORT_IdleNotification(
1073   IN PDEVICE_OBJECT PdoDevice,
1074   IN PIRP Irp);
1075 
1076 VOID
1077 NTAPI
1078 USBPORT_AdjustDeviceCapabilities(
1079   IN PDEVICE_OBJECT FdoDevice,
1080   IN PDEVICE_OBJECT PdoDevice);
1081 
1082 VOID
1083 NTAPI
1084 USBPORT_DoIdleNotificationCallback(
1085   IN PVOID Context);
1086 
1087 VOID
1088 NTAPI
1089 USBPORT_CompletePdoWaitWake(
1090   IN PDEVICE_OBJECT FdoDevice);
1091 
1092 VOID
1093 NTAPI
1094 USBPORT_DoSetPowerD0(
1095   IN PDEVICE_OBJECT FdoDevice);
1096 
1097 VOID
1098 NTAPI
1099 USBPORT_HcWakeDpc(
1100   IN PRKDPC Dpc,
1101   IN PVOID DeferredContext,
1102   IN PVOID SystemArgument1,
1103   IN PVOID SystemArgument2);
1104 
1105 VOID
1106 NTAPI
1107 USBPORT_HcQueueWakeDpc(
1108   IN PDEVICE_OBJECT FdoDevice);
1109 
1110 /* queue.c */
1111 VOID
1112 NTAPI
1113 USBPORT_InsertIdleIrp(
1114   IN PIO_CSQ Csq,
1115   IN PIRP Irp);
1116 
1117 VOID
1118 NTAPI
1119 USBPORT_RemoveIdleIrp(
1120   IN PIO_CSQ Csq,
1121   IN PIRP Irp);
1122 
1123 PIRP
1124 NTAPI
1125 USBPORT_PeekNextIdleIrp(
1126   IN PIO_CSQ Csq,
1127   IN PIRP Irp,
1128   IN PVOID PeekContext);
1129 
1130 VOID
1131 NTAPI
1132 USBPORT_AcquireIdleLock(
1133   IN PIO_CSQ Csq,
1134   IN PKIRQL Irql);
1135 
1136 VOID
1137 NTAPI
1138 USBPORT_ReleaseIdleLock(
1139   IN PIO_CSQ Csq,
1140   IN KIRQL Irql);
1141 
1142 VOID
1143 NTAPI
1144 USBPORT_CompleteCanceledIdleIrp(
1145   IN PIO_CSQ Csq,
1146   IN PIRP Irp);
1147 
1148 VOID
1149 NTAPI
1150 USBPORT_InsertBadRequest(
1151   IN PIO_CSQ Csq,
1152   IN PIRP Irp);
1153 
1154 VOID
1155 NTAPI
1156 USBPORT_RemoveBadRequest(
1157   IN PIO_CSQ Csq,
1158   IN PIRP Irp);
1159 
1160 PIRP
1161 NTAPI
1162 USBPORT_PeekNextBadRequest(
1163   IN PIO_CSQ Csq,
1164   IN PIRP Irp,
1165   IN PVOID PeekContext);
1166 
1167 VOID
1168 NTAPI
1169 USBPORT_AcquireBadRequestLock(
1170   IN PIO_CSQ Csq,
1171   IN PKIRQL Irql);
1172 
1173 VOID
1174 NTAPI
1175 USBPORT_ReleaseBadRequestLock(
1176   IN PIO_CSQ Csq,
1177   IN KIRQL Irql);
1178 
1179 VOID
1180 NTAPI
1181 USBPORT_CompleteCanceledBadRequest(
1182   IN PIO_CSQ Csq,
1183   IN PIRP Irp);
1184 
1185 VOID
1186 NTAPI
1187 USBPORT_InsertIrpInTable(
1188   IN PUSBPORT_IRP_TABLE IrpTable,
1189   IN PIRP Irp);
1190 
1191 PIRP
1192 NTAPI
1193 USBPORT_RemovePendingTransferIrp(
1194   IN PDEVICE_OBJECT FdoDevice,
1195   IN PIRP Irp);
1196 
1197 PIRP
1198 NTAPI
1199 USBPORT_RemoveActiveTransferIrp(
1200   IN PDEVICE_OBJECT FdoDevice,
1201   IN PIRP Irp);
1202 
1203 VOID
1204 NTAPI
1205 USBPORT_FindUrbInIrpTable(
1206   IN PUSBPORT_IRP_TABLE IrpTable,
1207   IN PURB Urb,
1208   IN PIRP Irp);
1209 
1210 VOID
1211 NTAPI
1212 USBPORT_CancelActiveTransferIrp(
1213   IN PDEVICE_OBJECT DeviceObject,
1214   IN PIRP Irp);
1215 
1216 VOID
1217 NTAPI
1218 USBPORT_FlushAbortList(
1219   IN PUSBPORT_ENDPOINT Endpoint);
1220 
1221 VOID
1222 NTAPI
1223 USBPORT_FlushCancelList(
1224   IN PUSBPORT_ENDPOINT Endpoint);
1225 
1226 VOID
1227 NTAPI
1228 USBPORT_QueueTransferUrb(
1229   IN PURB Urb);
1230 
1231 VOID
1232 NTAPI
1233 USBPORT_FlushAllEndpoints(
1234   IN PDEVICE_OBJECT FdoDevice);
1235 
1236 VOID
1237 NTAPI
1238 USBPORT_FlushPendingTransfers(
1239   IN PUSBPORT_ENDPOINT Endpoint);
1240 
1241 BOOLEAN
1242 NTAPI
1243 USBPORT_QueueActiveUrbToEndpoint(
1244   IN PUSBPORT_ENDPOINT Endpoint,
1245   IN PURB Urb);
1246 
1247 VOID
1248 NTAPI
1249 USBPORT_FlushController(
1250   IN PDEVICE_OBJECT FdoDevice);
1251 
1252 VOID
1253 NTAPI
1254 USBPORT_BadRequestFlush(
1255   IN PDEVICE_OBJECT FdoDevice);
1256 
1257 VOID
1258 NTAPI
1259 USBPORT_AbortEndpoint(
1260   IN PDEVICE_OBJECT FdoDevice,
1261   IN PUSBPORT_ENDPOINT Endpoint,
1262   IN PIRP Irp);
1263 
1264 /* roothub.c */
1265 VOID
1266 NTAPI
1267 USBPORT_RootHubEndpointWorker(
1268   PUSBPORT_ENDPOINT Endpoint);
1269 
1270 NTSTATUS
1271 NTAPI
1272 USBPORT_RootHubCreateDevice(
1273   IN PDEVICE_OBJECT FdoDevice,
1274   IN PDEVICE_OBJECT PdoDevice);
1275 
1276 ULONG
1277 NTAPI
1278 USBPORT_InvalidateRootHub(
1279   PVOID MiniPortExtension);
1280 
1281 VOID
1282 NTAPI
1283 USBPORT_RootHubPowerAndChirpAllCcPorts(
1284   IN PDEVICE_OBJECT FdoDevice);
1285 
1286 /* trfsplit.c */
1287 VOID
1288 NTAPI
1289 USBPORT_SplitTransfer(
1290   IN PDEVICE_OBJECT FdoDevice,
1291   IN PUSBPORT_ENDPOINT Endpoint,
1292   IN PUSBPORT_TRANSFER Transfer,
1293   IN PLIST_ENTRY List);
1294 
1295 VOID
1296 NTAPI
1297 USBPORT_DoneSplitTransfer(
1298   IN PUSBPORT_TRANSFER SplitTransfer);
1299 
1300 VOID
1301 NTAPI
1302 USBPORT_CancelSplitTransfer(
1303   IN PUSBPORT_TRANSFER SplitTransfer);
1304 
1305 /* urb.c */
1306 NTSTATUS
1307 NTAPI
1308 USBPORT_HandleSubmitURB(
1309   IN PDEVICE_OBJECT PdoDevice,
1310   IN PIRP Irp,
1311   IN PURB Urb);
1312 
1313 /* usb2.c */
1314 BOOLEAN
1315 NTAPI
1316 USBPORT_AllocateBandwidthUSB2(
1317   IN PDEVICE_OBJECT FdoDevice,
1318   IN PUSBPORT_ENDPOINT Endpoint);
1319 
1320 VOID
1321 NTAPI
1322 USBPORT_FreeBandwidthUSB2(
1323   IN PDEVICE_OBJECT FdoDevice,
1324   IN PUSBPORT_ENDPOINT Endpoint);
1325 
1326 VOID
1327 NTAPI
1328 USBPORT_UpdateAllocatedBwTt(
1329   IN PUSB2_TT_EXTENSION TtExtension);
1330 
1331 VOID
1332 NTAPI
1333 USB2_InitTT(
1334   IN PUSB2_HC_EXTENSION HcExtension,
1335   IN PUSB2_TT Tt);
1336 
1337 VOID
1338 NTAPI
1339 USB2_InitController(
1340   IN PUSB2_HC_EXTENSION HcExtension);
1341 
1342 VOID
1343 NTAPI
1344 USBPORT_DumpingEndpointProperties(
1345   IN PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties);
1346 
1347 VOID
1348 NTAPI
1349 USBPORT_DumpingTtEndpoint(
1350   IN PUSB2_TT_ENDPOINT TtEndpoint);
1351 
1352 #endif /* USBPORT_H__ */
1353