13#define NDEBUG_USBPORT_CORE
25 DPRINT(
"USBPORT_CalculateUsbBandwidth ... \n");
27 EndpointProperties = &Endpoint->EndpointProperties;
69 ULONG TotalBusBandwidth;
70 ULONG EndpointBandwidth;
73 ULONG MaxBandwidth = 0;
76 LONG ScheduleOffset = -1;
81 DPRINT(
"USBPORT_AllocateBandwidth: FdoDevice - %p, Endpoint - %p\n",
86 EndpointProperties = &Endpoint->EndpointProperties;
106 MinBandwidth = TotalBusBandwidth;
109 for (ix = 1; *Bandwidth >= EndpointBandwidth; ix++)
111 MinBandwidth =
min(MinBandwidth, *Bandwidth);
117 if (MinBandwidth > MaxBandwidth)
119 MaxBandwidth = MinBandwidth;
122 DPRINT(
"USBPORT_AllocateBandwidth: ScheduleOffset - %X\n",
131 DPRINT(
"USBPORT_AllocateBandwidth: ScheduleOffset - %X\n", ScheduleOffset);
133 if (ScheduleOffset != -1)
137 Bandwidth = &
FdoExtension->Bandwidth[ScheduleOffset * Factor];
141 FdoExtension->Bandwidth[ScheduleOffset * Factor] -= EndpointBandwidth;
146 for (Bit = 0x80; Bit != 0; Bit >>= 1)
155 DPRINT(
"USBPORT_AllocateBandwidth: FIXME AllocatedInterrupt_XXms\n");
159 DPRINT(
"USBPORT_AllocateBandwidth: FIXME AllocatedIso\n");
163 DPRINT(
"USBPORT_AllocateBandwidth: FIXME USBPORT_UpdateAllocatedBw\n");
165 DPRINT(
"USBPORT_AllocateBandwidth: ScheduleOffset - %X\n", ScheduleOffset);
166 return ScheduleOffset != -1;
178 ULONG EndpointBandwidth;
183 DPRINT(
"USBPORT_FreeBandwidth: FdoDevice - %p, Endpoint - %p\n",
189 EndpointProperties = &Endpoint->EndpointProperties;
199 Offset = Endpoint->EndpointProperties.ScheduleOffset;
200 EndpointBandwidth = Endpoint->EndpointProperties.UsbBandwidth;
202 Period = Endpoint->EndpointProperties.Period;
212 for (Bit = 0x80; Bit != 0; Bit >>= 1)
223 DPRINT(
"USBPORT_AllocateBandwidth: FIXME AllocatedInterrupt_XXms\n");
227 DPRINT(
"USBPORT_AllocateBandwidth: FIXME AllocatedIso\n");
230 DPRINT1(
"USBPORT_FreeBandwidth: FIXME USBPORT_UpdateAllocatedBw\n");
262 DPRINT_CORE(
"USBPORT_EndpointHasQueuedTransfers: ... \n");
277 for (
Entry = Endpoint->TransferList.Flink;
307 DPRINT(
"USBPORT_NukeAllEndpoints \n");
315 while (EndpointList && (EndpointList != &
FdoExtension->EndpointList))
340 if (Endpoint->StateLast != Endpoint->StateNext)
346 State = Endpoint->StateLast;
353 DPRINT(
"USBPORT_GetEndpointState: Endpoint - %p, State - %x\n",
371 DPRINT(
"USBPORT_SetEndpointState: Endpoint - %p, State - %x\n",
375 FdoDevice = Endpoint->FdoDevice;
380 &Endpoint->EndpointStateOldIrql);
386 Endpoint->StateLast =
State;
387 Endpoint->StateNext =
State;
390 Endpoint->EndpointStateOldIrql);
399 Endpoint->EndpointStateOldIrql);
407 Endpoint->StateNext =
State;
414 &Endpoint->StateChangeLink,
423 Endpoint->StateLast =
State;
424 Endpoint->StateNext =
State;
429 Endpoint->EndpointStateOldIrql);
438 Endpoint->EndpointStateOldIrql);
447 DPRINT(
"USBPORT_AddPipeHandle: DeviceHandle - %p, PipeHandle - %p\n",
487 HandleList = HandleList->
Flink;
505 DPRINT1(
"USBPORT_DeleteEndpoint: Endpoint - %p\n", Endpoint);
509 if ((Endpoint->WorkerLink.Flink && Endpoint->WorkerLink.Blink) ||
510 Endpoint->LockCounter != -1)
515 &Endpoint->CloseLink,
527 Endpoint->EndpointLink.Flink =
NULL;
528 Endpoint->EndpointLink.Blink =
NULL;
534 if (Endpoint->HeaderBuffer)
558 DPRINT(
"MiniportCloseEndpoint: Endpoint - %p\n", Endpoint);
567 TransferType = Endpoint->EndpointProperties.TransferType;
575 IsDoDisablePeriodic =
FdoExtension->PeriodicEndpoints == 0;
579 IsDoDisablePeriodic);
581 Endpoint->Flags &= ~ENDPOINT_FLAG_OPENED;
603 DPRINT1(
"USBPORT_ClosePipe \n");
616 PipeHandle->Flags &= ~PIPE_HANDLE_FLAG_NULL_PACKET_SIZE;
680 DPRINT1(
"USBPORT_ClosePipe: TtExtension - %p\n", TtExtension);
700 DPRINT1(
"USBPORT_ClosePipe: ExFreePoolWithTag TtExtension - %p\n", TtExtension);
731 DPRINT(
"MiniportOpenEndpoint: Endpoint - %p\n", Endpoint);
738 Endpoint->Flags &= ~ENDPOINT_FLAG_CLOSED;
741 &Endpoint->EndpointProperties,
746 TransferType = Endpoint->EndpointProperties.TransferType;
785 USHORT AdditionalTransaction;
789 DPRINT1(
"USBPORT_OpenPipe: DeviceHandle - %p, FdoDevice - %p, PipeHandle - %p\n",
804 if (
PipeHandle->EndpointDescriptor.wMaxPacketSize == 0)
820 DPRINT1(
"USBPORT_OpenPipe: Not allocated Endpoint!\n");
844 Packet->MiniPortEndpointSize);
860 EndpointDescriptor = &
PipeHandle->EndpointDescriptor;
863 AdditionalTransaction = (EndpointDescriptor->
wMaxPacketSize >> 11) & 3;
867 EndpointProperties->
Period = 0;
872 (AdditionalTransaction + 1);
880 EndpointProperties->
HubAddr = -1;
902 DPRINT1(
"USBPORT_OpenPipe: USB_ENDPOINT_TYPE_ISOCHRONOUS UNIMPLEMENTED. FIXME. \n");
960 EndpointProperties->
Period =
986 if (!IsAllocatedBandwidth)
1027 &EndpointRequirements);
1044 HeaderBuffer =
NULL;
1079 for (RetryCount = 0; RetryCount < 1000; RetryCount++)
1131 PipeHandle->Flags &= ~PIPE_HANDLE_FLAG_CLOSED;
1140 if (IsAllocatedBandwidth)
1175 KIRQL MiniportOldIrql;
1178 DPRINT1(
"USBPORT_ReopenPipe ... \n");
1207 Packet->MiniPortEndpointSize);
1209 if (Endpoint->HeaderBuffer)
1212 Endpoint->HeaderBuffer =
NULL;
1218 &Endpoint->EndpointProperties,
1219 &EndpointRequirements);
1230 HeaderBuffer =
NULL;
1235 Endpoint->HeaderBuffer = HeaderBuffer;
1240 Endpoint->HeaderBuffer = 0;
1244 if (Endpoint->HeaderBuffer && HeaderBuffer)
1246 Endpoint->EndpointProperties.BufferVA = HeaderBuffer->
VirtualAddress;
1247 Endpoint->EndpointProperties.BufferPA = HeaderBuffer->
PhysicalAddress;
1248 Endpoint->EndpointProperties.BufferLength = HeaderBuffer->
BufferLength;
1291 DPRINT_CORE(
"USBPORT_FlushClosedEndpointList: ... \n");
1332 DPRINT_CORE(
"USBPORT_InvalidateEndpointHandler: Endpoint - %p, Type - %x\n",
1341 WorkerLink = &Endpoint->WorkerLink;
1343 DPRINT_CORE(
"USBPORT_InvalidateEndpointHandler: KeAcquireSpinLock \n");
1345 if ((!WorkerLink->
Flink || !WorkerLink->
Blink) &&
1349 DPRINT_CORE(
"USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1377 DPRINT_CORE(
"USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1426 ULONG CompletedLen = 0;
1434 Entry = Endpoint->TransferList.Flink;
1436 if (
Entry == &Endpoint->TransferList)
1439 while (
Entry &&
Entry != &Endpoint->TransferList)
1451 Urb = Transfer->
Urb;
1460 if (Frame + 1 > CurrentFrame)
1480 DPRINT1(
"USBPORT_DmaEndpointActive: FIXME call USBPORT_FlushIsoTransfer\n");
1527 Entry = Endpoint->TransferList.Flink;
1529 while (
Entry &&
Entry != &Endpoint->TransferList)
1544 DPRINT1(
"USBPORT_DmaEndpointActive: FIXME call SubmitIsoTransfer\n");
1567 DPRINT1(
"USBPORT_DmaEndpointActive: FIXME call USBPORT_ErrorCompleteIsoTransfer\n");
1598 ULONG EndpointState;
1603 FdoDevice = Endpoint->FdoDevice;
1619#ifndef NDEBUG_USBPORT_CORE
1620 DPRINT1(
"USBPORT_DmaEndpointWorker: DbgBreakPoint. EndpointState - %x\n",
1633 if (EndpointState == PrevState)
1665 ULONG EndpointState;
1667 DPRINT_CORE(
"USBPORT_EndpointWorker: Endpoint - %p, LockNotChecked - %x\n",
1671 FdoDevice = Endpoint->FdoDevice;
1675 if (LockNotChecked ==
FALSE)
1680 DPRINT_CORE(
"USBPORT_EndpointWorker: LockCounter > 0\n");
1693 DPRINT_CORE(
"USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_CLOSED. return FALSE\n");
1718 &Endpoint->CloseLink,
1724 DPRINT_CORE(
"USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_REMOVE. return FALSE\n");
1728 if (!
IsListEmpty(&Endpoint->PendingTransferList) ||
1737 if (EndpointState == Endpoint->StateNext)
1741 if (Endpoint->EndpointWorker)
1753 DPRINT_CORE(
"USBPORT_EndpointWorker: return FALSE\n");
1760 DPRINT_CORE(
"USBPORT_EndpointWorker: return TRUE\n");
1769 DPRINT_CORE(
"USBPORT_EndpointWorker: return FALSE\n");
#define InterlockedIncrement
#define InterlockedDecrement
#define NT_SUCCESS(StatCode)
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
VOID NTAPI USBPORT_FlushCancelList(IN PUSBPORT_ENDPOINT Endpoint)
VOID NTAPI USBPORT_FlushAbortList(IN PUSBPORT_ENDPOINT Endpoint)
ULONG NTAPI USBPORT_CalculateUsbBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
ULONG NTAPI USBPORT_DmaEndpointPaused(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
VOID NTAPI USBPORT_NukeAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
BOOLEAN NTAPI USBPORT_DeleteEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
VOID NTAPI USBPORT_RemovePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
VOID NTAPI USBPORT_AddPipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
VOID NTAPI USBPORT_ClosePipe(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_PIPE_HANDLE PipeHandle)
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
VOID NTAPI USBPORT_FreeBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
BOOLEAN NTAPI USBPORT_ValidatePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
NTSTATUS NTAPI USBPORT_ReopenPipe(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
VOID NTAPI USBPORT_FlushClosedEndpointList(IN PDEVICE_OBJECT FdoDevice)
BOOLEAN NTAPI USBPORT_AllocateBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
MPSTATUS NTAPI MiniportOpenEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
ULONG NTAPI USBPORT_DmaEndpointActive(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
VOID NTAPI MiniportCloseEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
UCHAR NTAPI USBPORT_NormalizeHsInterval(UCHAR Interval)
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
NTSTATUS NTAPI USBPORT_OpenPipe(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle, IN OUT PUSBD_STATUS UsbdStatus)
VOID NTAPI USBPORT_DmaEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define IsListEmpty(ListHead)
#define KeReleaseSpinLock(sl, irql)
#define KeAcquireSpinLock(sl, irql)
#define KeQuerySystemTime(t)
#define KeGetCurrentIrql()
#define RemoveHeadList(ListHead)
#define InitializeListHead(ListHead)
#define KeInitializeSpinLock(sl)
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
NTSYSAPI void WINAPI DbgBreakPoint(void)
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
#define ExFreePoolWithTag(_P, _T)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
_In_ ULONG _In_ ULONG Offset
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
base of all file and directory entries
struct _LIST_ENTRY * Blink
struct _LIST_ENTRY * Flink
struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer
UCHAR TransactionPerMicroframe
USB_DEVICE_SPEED DeviceSpeed
USHORT TotalMaxPacketSize
PUSBPORT_DEVICE_HANDLE DeviceHandle
KSPIN_LOCK StateChangeSpinLock
LIST_ENTRY PendingTransferList
KSPIN_LOCK EndpointSpinLock
PUSB2_TT_ENDPOINT TtEndpoint
PUSB2_TT_EXTENSION TtExtension
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
ULONG CompletedTransferLen
USBPORT_TRANSFER_PARAMETERS TransferParameters
USBPORT_SCATTER_GATHER_LIST SgList
VOID NTAPI USBPORT_CancelSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
#define RtlZeroMemory(Destination, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_INSUFFICIENT_RESOURCES
#define USB_ENDPOINT_TYPE_INTERRUPT
#define USB_ENDPOINT_DIRECTION_OUT(x)
#define USB_ENDPOINT_TYPE_CONTROL
#define USB_ENDPOINT_TYPE_ISOCHRONOUS
#define USB_ENDPOINT_TYPE_MASK
#define USB_ENDPOINT_TYPE_BULK
BOOLEAN NTAPI USBPORT_AllocateBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
VOID NTAPI USBPORT_UpdateAllocatedBwTt(IN PUSB2_TT_EXTENSION TtExtension)
VOID NTAPI USBPORT_FreeBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
#define USBD_STATUS_NO_BANDWIDTH
#define USBD_STATUS_SUCCESS
#define USBD_STATUS_INSUFFICIENT_RESOURCES
#define USBD_STATUS_TIMEOUT
#define USBPORT_ENDPOINT_REMOVE
#define USBPORT_ENDPOINT_ACTIVE
#define USB_MINIPORT_FLAGS_USB2
#define ENDPOINT_INTERRUPT_32ms
#define ENDPOINT_INTERRUPT_8ms
#define USBPORT_TRANSFER_TYPE_INTERRUPT
#define USBPORT_ENDPOINT_PAUSED
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
#define ENDPOINT_INTERRUPT_1ms
#define MP_STATUS_NO_RESOURCES
#define USBPORT_ENDPOINT_UNKNOWN
#define USBPORT_TRANSFER_TYPE_CONTROL
#define MP_STATUS_FAILURE
#define USBPORT_ENDPOINT_CLOSED
#define USBPORT_TRANSFER_TYPE_BULK
VOID NTAPI USBPORT_RootHubEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
struct _USB2_TT_ENDPOINT * PUSB2_TT_ENDPOINT
#define PIPE_HANDLE_FLAG_CLOSED
#define ENDPOINT_FLAG_IDLE
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
#define INVALIDATE_ENDPOINT_INT_NEXT_SOF
#define USB2_BIT_STUFFING_OVERHEAD
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
#define TRANSFER_FLAG_CANCELED
#define USB2_TT_EXTENSION_FLAG_DELETED
#define ENDPOINT_FLAG_ROOTHUB_EP0
#define DEVICE_HANDLE_FLAG_ROOTHUB
#define USB2_FS_INTERRUPT_OVERHEAD
#define INVALIDATE_ENDPOINT_WORKER_THREAD
struct _USB2_TT_ENDPOINT USB2_TT_ENDPOINT
#define USBPORT_FLAG_HC_SUSPEND
USBD_STATUS * PUSBD_STATUS
#define TRANSFER_FLAG_SUBMITED
#define TRANSFER_FLAG_ISO
#define ENDPOINT_FLAG_DMA_TYPE
#define USB2_FS_ISOCHRONOUS_OVERHEAD
#define ENDPOINT_FLAG_CLOSED
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
#define ENDPOINT_FLAG_NUKE
#define INVALIDATE_ENDPOINT_ONLY
#define TRANSFER_FLAG_SPLITED
#define TRANSFER_FLAG_ABORTED
#define ENDPOINT_FLAG_QUEUENE_EMPTY
#define INVALIDATE_ENDPOINT_WORKER_DPC
#define ENDPOINT_FLAG_OPENED
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION Direction
_In_ NTSTATUS _In_ USBD_STATUS UsbdStatus
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
_In_ LARGE_INTEGER _In_ ULONG Period