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