ReactOS 0.4.17-dev-1196-gb6224c3
endpoint.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for endpoint.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_CORE
 

Functions

ULONG NTAPI USBPORT_CalculateUsbBandwidth (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
BOOLEAN NTAPI USBPORT_AllocateBandwidth (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_FreeBandwidth (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
UCHAR NTAPI USBPORT_NormalizeHsInterval (UCHAR Interval)
 
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
 
VOID NTAPI USBPORT_NukeAllEndpoints (IN PDEVICE_OBJECT FdoDevice)
 
ULONG NTAPI USBPORT_GetEndpointState (IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_SetEndpointState (IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
 
VOID NTAPI USBPORT_AddPipeHandle (IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
 
VOID NTAPI USBPORT_RemovePipeHandle (IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
 
BOOLEAN NTAPI USBPORT_ValidatePipeHandle (IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
 
BOOLEAN NTAPI USBPORT_DeleteEndpoint (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI MiniportCloseEndpoint (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_ClosePipe (IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_PIPE_HANDLE PipeHandle)
 
MPSTATUS NTAPI MiniportOpenEndpoint (IN PDEVICE_OBJECT FdoDevice, 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)
 
NTSTATUS NTAPI USBPORT_ReopenPipe (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_FlushClosedEndpointList (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_InvalidateEndpointHandler (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
 
ULONG NTAPI USBPORT_DmaEndpointPaused (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
ULONG NTAPI USBPORT_DmaEndpointActive (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_DmaEndpointWorker (IN PUSBPORT_ENDPOINT Endpoint)
 
BOOLEAN NTAPI USBPORT_EndpointWorker (IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file endpoint.c.

◆ NDEBUG_USBPORT_CORE

#define NDEBUG_USBPORT_CORE

Definition at line 13 of file endpoint.c.

Function Documentation

◆ MiniportCloseEndpoint()

VOID NTAPI MiniportCloseEndpoint ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 575 of file endpoint.c.

577{
580 BOOLEAN IsDoDisablePeriodic;
581 ULONG TransferType;
583
584 DPRINT("MiniportCloseEndpoint: Endpoint - %p\n", Endpoint);
585
586 FdoExtension = FdoDevice->DeviceExtension;
587 Packet = &FdoExtension->MiniPortInterface->Packet;
588
589 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
590
591 if (Endpoint->Flags & ENDPOINT_FLAG_OPENED)
592 {
593 TransferType = Endpoint->EndpointProperties.TransferType;
594
595 if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT ||
596 TransferType == USBPORT_TRANSFER_TYPE_ISOCHRONOUS)
597 {
598 --FdoExtension->PeriodicEndpoints;
599 }
600
601 IsDoDisablePeriodic = FdoExtension->PeriodicEndpoints == 0;
602
603 Packet->CloseEndpoint(FdoExtension->MiniPortExt,
604 Endpoint + 1,
605 IsDoDisablePeriodic);
606
607 Endpoint->Flags &= ~ENDPOINT_FLAG_OPENED;
609 }
610
611 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
612}
unsigned char BOOLEAN
Definition: actypes.h:127
@ FdoExtension
Definition: precomp.h:60
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_In_ UCXHUB_DEVICE_CONTEXT _In_ UCXENDPOINT Endpoint
Definition: hubucx.h:238
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define DPRINT
Definition: sndvol32.h:73
uint32_t ULONG
Definition: typedefs.h:59
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
#define ENDPOINT_FLAG_CLOSED
Definition: usbport.h:118
#define ENDPOINT_FLAG_OPENED
Definition: usbport.h:117
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by USBPORT_DeleteEndpoint(), USBPORT_OpenPipe(), USBPORT_ReopenPipe(), and USBPORT_RestoreDevice().

◆ MiniportOpenEndpoint()

MPSTATUS NTAPI MiniportOpenEndpoint ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 748 of file endpoint.c.

750{
754 ULONG TransferType;
755 MPSTATUS MpStatus;
756
757 DPRINT("MiniportOpenEndpoint: Endpoint - %p\n", Endpoint);
758
759 FdoExtension = FdoDevice->DeviceExtension;
760 Packet = &FdoExtension->MiniPortInterface->Packet;
761
762 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
763
764 Endpoint->Flags &= ~ENDPOINT_FLAG_CLOSED;
765
766 MpStatus = Packet->OpenEndpoint(FdoExtension->MiniPortExt,
767 &Endpoint->EndpointProperties,
768 Endpoint + 1);
769
770 if (!MpStatus)
771 {
772 TransferType = Endpoint->EndpointProperties.TransferType;
773
774 if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT ||
775 TransferType == USBPORT_TRANSFER_TYPE_ISOCHRONOUS)
776 {
777 ++FdoExtension->PeriodicEndpoints;
778 }
779
781 }
782
783 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
784 return MpStatus;
785}
ULONG MPSTATUS
Definition: usbmport.h:131

Referenced by USBPORT_OpenPipe(), USBPORT_ReopenPipe(), and USBPORT_RestoreDevice().

◆ USBPORT_AddPipeHandle()

VOID NTAPI USBPORT_AddPipeHandle ( IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PUSBPORT_PIPE_HANDLE  PipeHandle 
)

Definition at line 452 of file endpoint.c.

454{
455 DPRINT("USBPORT_AddPipeHandle: DeviceHandle - %p, PipeHandle - %p\n",
457 PipeHandle);
458
459 InsertTailList(&DeviceHandle->PipeHandleList, &PipeHandle->PipeLink);
460}
#define InsertTailList(ListHead, Entry)
_In_ PIOMMU_DEVICE_PATH _In_ PIOMMU_SVM_CAPABILITIES _Out_ PVOID * DeviceHandle
Definition: haltypes.h:1894

Referenced by USBPORT_OpenPipe(), and USBPORT_RestoreDevice().

◆ USBPORT_AllocateBandwidth()

BOOLEAN NTAPI USBPORT_AllocateBandwidth ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 63 of file endpoint.c.

65{
67 PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties;
68 ULONG TransferType;
69 ULONG TotalBusBandwidth;
70 ULONG EndpointBandwidth;
71 ULONG MinBandwidth;
72 PULONG Bandwidth;
73 ULONG MaxBandwidth = 0;
74 ULONG ix;
76 LONG ScheduleOffset = -1;
78 ULONG Factor;
79 UCHAR Bit;
80
81 DPRINT("USBPORT_AllocateBandwidth: FdoDevice - %p, Endpoint - %p\n",
82 FdoDevice,
83 Endpoint);
84
85 FdoExtension = FdoDevice->DeviceExtension;
86 EndpointProperties = &Endpoint->EndpointProperties;
87 TransferType = EndpointProperties->TransferType;
88
89 if (TransferType == USBPORT_TRANSFER_TYPE_BULK ||
90 TransferType == USBPORT_TRANSFER_TYPE_CONTROL ||
92 {
93 EndpointProperties->ScheduleOffset = 0;
94 return TRUE;
95 }
96
97 TotalBusBandwidth = FdoExtension->TotalBusBandwidth;
98 EndpointBandwidth = EndpointProperties->UsbBandwidth;
99
100 Period = EndpointProperties->Period;
101 ASSERT(Period != 0);
102 Factor = USB2_FRAMES / Period;
103
104 for (Offset = 0; Offset < Period; Offset++)
105 {
106 MinBandwidth = TotalBusBandwidth;
107 Bandwidth = &FdoExtension->Bandwidth[Offset * Factor];
108
109 for (ix = 1; *Bandwidth >= EndpointBandwidth; ix++)
110 {
111 MinBandwidth = min(MinBandwidth, *Bandwidth);
112
113 Bandwidth++;
114
115 if (Factor <= ix)
116 {
117 if (MinBandwidth > MaxBandwidth)
118 {
119 MaxBandwidth = MinBandwidth;
120 ScheduleOffset = Offset;
121
122 DPRINT("USBPORT_AllocateBandwidth: ScheduleOffset - %X\n",
123 ScheduleOffset);
124 }
125
126 break;
127 }
128 }
129 }
130
131 DPRINT("USBPORT_AllocateBandwidth: ScheduleOffset - %X\n", ScheduleOffset);
132
133 if (ScheduleOffset != -1)
134 {
135 EndpointProperties->ScheduleOffset = ScheduleOffset;
136
137 Bandwidth = &FdoExtension->Bandwidth[ScheduleOffset * Factor];
138
139 for (Factor = USB2_FRAMES / Period; Factor; Factor--)
140 {
141 FdoExtension->Bandwidth[ScheduleOffset * Factor] -= EndpointBandwidth;
142 }
143
144 if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
145 {
146 for (Bit = 0x80; Bit != 0; Bit >>= 1)
147 {
148 if ((Period & Bit) != 0)
149 {
150 Period = Bit;
151 break;
152 }
153 }
154
155 DPRINT("USBPORT_AllocateBandwidth: FIXME AllocatedInterrupt_XXms\n");
156 }
157 else
158 {
159 DPRINT("USBPORT_AllocateBandwidth: FIXME AllocatedIso\n");
160 }
161 }
162
163 DPRINT("USBPORT_AllocateBandwidth: FIXME USBPORT_UpdateAllocatedBw\n");
164
165 DPRINT("USBPORT_AllocateBandwidth: ScheduleOffset - %X\n", ScheduleOffset);
166 return ScheduleOffset != -1;
167}
#define TRUE
Definition: types.h:120
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
long LONG
Definition: pedump.c:60
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define USBPORT_TRANSFER_TYPE_BULK
Definition: usbmport.h:9
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:112
#define USB2_FRAMES
Definition: usbport.h:452
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1304

Referenced by USBPORT_OpenPipe().

◆ USBPORT_CalculateUsbBandwidth()

ULONG NTAPI USBPORT_CalculateUsbBandwidth ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 18 of file endpoint.c.

20{
21 PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties;
22 ULONG Bandwidth;
23 ULONG Overhead;
24
25 DPRINT("USBPORT_CalculateUsbBandwidth ... \n");
26
27 EndpointProperties = &Endpoint->EndpointProperties;
28
29 switch (EndpointProperties->TransferType)
30 {
33 break;
34
37 break;
38
39 default: //USBPORT_TRANSFER_TYPE_CONTROL or USBPORT_TRANSFER_TYPE_BULK
40 Overhead = 0;
41 break;
42 }
43
44 if (Overhead == 0)
45 {
46 Bandwidth = 0;
47 }
48 else
49 {
50 Bandwidth = (EndpointProperties->TotalMaxPacketSize + Overhead) * USB2_BIT_STUFFING_OVERHEAD;
51 }
52
53 if (EndpointProperties->DeviceSpeed == UsbLowSpeed)
54 {
55 Bandwidth *= 8;
56 }
57
58 return Bandwidth;
59}
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
@ UsbLowSpeed
Definition: usb200.h:42
#define USB2_BIT_STUFFING_OVERHEAD
Definition: usbport.h:483
#define USB2_FS_INTERRUPT_OVERHEAD
Definition: usbport.h:467
#define USB2_FS_ISOCHRONOUS_OVERHEAD
Definition: usbport.h:470

Referenced by USBPORT_OpenPipe().

◆ USBPORT_ClosePipe()

VOID NTAPI USBPORT_ClosePipe ( IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_PIPE_HANDLE  PipeHandle 
)

Definition at line 616 of file endpoint.c.

619{
624 PUSB2_TT_EXTENSION TtExtension;
625 ULONG ix;
626 BOOLEAN IsReady;
628
629 DPRINT1("USBPORT_ClosePipe \n");
630
631 FdoExtension = FdoDevice->DeviceExtension;
632
633 if (PipeHandle->Flags & PIPE_HANDLE_FLAG_CLOSED)
634 return;
635
637
638 PipeHandle->Flags |= PIPE_HANDLE_FLAG_CLOSED;
639
640 if (PipeHandle->Flags & PIPE_HANDLE_FLAG_NULL_PACKET_SIZE)
641 {
642 PipeHandle->Flags &= ~PIPE_HANDLE_FLAG_NULL_PACKET_SIZE;
643 return;
644 }
645
646 Endpoint = PipeHandle->Endpoint;
647
648 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
649
650 if ((Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0) &&
651 (Endpoint->EndpointProperties.TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT))
652 {
653 PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
654 PdoExtension->Endpoint = NULL;
655 }
656
657 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
658
659 while (TRUE)
660 {
661 IsReady = TRUE;
662
663 KeAcquireSpinLock(&Endpoint->EndpointSpinLock,
664 &Endpoint->EndpointOldIrql);
665
666 if (!IsListEmpty(&Endpoint->PendingTransferList))
667 IsReady = FALSE;
668
669 if (!IsListEmpty(&Endpoint->TransferList))
670 IsReady = FALSE;
671
672 if (!IsListEmpty(&Endpoint->CancelList))
673 IsReady = FALSE;
674
675 if (!IsListEmpty(&Endpoint->AbortList))
676 IsReady = FALSE;
677
678 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
679 if (Endpoint->StateLast != Endpoint->StateNext)
680 IsReady = FALSE;
681 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
682
683 KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
684 Endpoint->EndpointOldIrql);
685
686 if (InterlockedIncrement(&Endpoint->LockCounter))
687 IsReady = FALSE;
688 InterlockedDecrement(&Endpoint->LockCounter);
689
690 if (IsReady == TRUE)
691 break;
692
693 USBPORT_Wait(FdoDevice, 1);
694 }
695
696 Endpoint->DeviceHandle = NULL;
697 Packet = &FdoExtension->MiniPortInterface->Packet;
698
699 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
700 {
702
703 KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
704
705 TtExtension = Endpoint->TtExtension;
706 DPRINT1("USBPORT_ClosePipe: TtExtension - %p\n", TtExtension);
707
708 if (TtExtension)
709 {
710 RemoveEntryList(&Endpoint->TtLink);
711
712 Endpoint->TtLink.Flink = NULL;
713 Endpoint->TtLink.Blink = NULL;
714
715 if (TtExtension->Flags & USB2_TT_EXTENSION_FLAG_DELETED)
716 {
717 if (IsListEmpty(&TtExtension->EndpointList))
718 {
719 USBPORT_UpdateAllocatedBwTt(TtExtension);
720
721 for (ix = 0; ix < USB2_FRAMES; ix++)
722 {
723 FdoExtension->Bandwidth[ix] += TtExtension->MaxBandwidth;
724 }
725
726 DPRINT1("USBPORT_ClosePipe: ExFreePoolWithTag TtExtension - %p\n", TtExtension);
727 ExFreePoolWithTag(TtExtension, USB_PORT_TAG);
728 }
729 }
730 }
731
733 }
734 else
735 {
737 }
738
739 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
741 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
742
744}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
@ PdoExtension
Definition: precomp.h:61
VOID NTAPI USBPORT_RemovePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:464
VOID NTAPI USBPORT_FreeBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:171
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
ULONG MaxBandwidth
Definition: usbport.h:553
LIST_ENTRY EndpointList
Definition: usbport.h:557
VOID NTAPI USBPORT_UpdateAllocatedBwTt(IN PUSB2_TT_EXTENSION TtExtension)
Definition: usb2.c:1768
VOID NTAPI USBPORT_FreeBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: usb2.c:2040
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1146
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define PIPE_HANDLE_FLAG_CLOSED
Definition: usbport.h:126
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:127
#define USB2_TT_EXTENSION_FLAG_DELETED
Definition: usbport.h:546
#define USB_PORT_TAG
Definition: usbport.h:44

Referenced by USBPORT_CloseConfiguration(), USBPORT_CreateDevice(), USBPORT_HandleSelectInterface(), USBPORT_RemoveDevice(), and USBPORT_RestoreDevice().

◆ USBPORT_DeleteEndpoint()

BOOLEAN NTAPI USBPORT_DeleteEndpoint ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 506 of file endpoint.c.

508{
512
513 DPRINT1("USBPORT_DeleteEndpoint: Endpoint - %p\n", Endpoint);
514
515 FdoExtension = FdoDevice->DeviceExtension;
516
517 /*
518 * Remove endpoint from EpStateChangeList if it's still there.
519 * This prevents the DPC handler from accessing a deleted endpoint.
520 */
521 KIRQL StateChangeOldIrql;
522 KeAcquireSpinLock(&FdoExtension->EpStateChangeSpinLock, &StateChangeOldIrql);
523
524 if (Endpoint->StateChangeLink.Flink != NULL &&
525 Endpoint->StateChangeLink.Blink != NULL)
526 {
527 RemoveEntryList(&Endpoint->StateChangeLink);
528 }
529
530 Endpoint->StateChangeLink.Flink = NULL;
531 Endpoint->StateChangeLink.Blink = NULL;
532
533 KeReleaseSpinLock(&FdoExtension->EpStateChangeSpinLock, StateChangeOldIrql);
534
535 if ((Endpoint->WorkerLink.Flink && Endpoint->WorkerLink.Blink) ||
536 Endpoint->LockCounter != -1)
537 {
538 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
539
540 ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
541 &Endpoint->CloseLink,
542 &FdoExtension->EndpointClosedSpinLock);
543
544 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
545
546 Result = FALSE;
547 }
548 else
549 {
550 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
551
552 RemoveEntryList(&Endpoint->EndpointLink);
553 Endpoint->EndpointLink.Flink = NULL;
554 Endpoint->EndpointLink.Blink = NULL;
555
556 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
557
559
560 if (Endpoint->HeaderBuffer)
561 {
562 USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
563 }
564
566
567 Result = TRUE;
568 }
569
570 return Result;
571}
VOID NTAPI MiniportCloseEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:575
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1805
_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
Definition: wsk.h:409

Referenced by USBPORT_FlushClosedEndpointList().

◆ USBPORT_DmaEndpointActive()

ULONG NTAPI USBPORT_DmaEndpointActive ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 1559 of file endpoint.c.

1561{
1565 PUSBPORT_TRANSFER Transfer;
1566 LARGE_INTEGER TimeOut;
1567 MPSTATUS MpStatus;
1568 KIRQL OldIrql;
1569
1570 DPRINT_CORE("USBPORT_DmaEndpointActive \n");
1571
1572 FdoExtension = FdoDevice->DeviceExtension;
1573
1574 Entry = Endpoint->TransferList.Flink;
1575
1576 while (Entry && Entry != &Endpoint->TransferList)
1577 {
1578 Transfer = CONTAINING_RECORD(Entry,
1580 TransferLink);
1581
1582 if (!(Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1583 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1584 {
1585 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1586
1587 Packet = &FdoExtension->MiniPortInterface->Packet;
1588
1589 if (Transfer->Flags & TRANSFER_FLAG_ISO)
1590 {
1591 DPRINT1("USBPORT_DmaEndpointActive: FIXME call SubmitIsoTransfer\n");
1592
1593 MpStatus = Packet->SubmitIsoTransfer(FdoExtension->MiniPortExt,
1594 Endpoint + 1,
1595 &Transfer->TransferParameters,
1596 Transfer->MiniportTransfer,
1597 NULL);//&Transfer->IsoTransferParameters);
1598 }
1599 else
1600 {
1601 MpStatus = Packet->SubmitTransfer(FdoExtension->MiniPortExt,
1602 Endpoint + 1,
1603 &Transfer->TransferParameters,
1604 Transfer->MiniportTransfer,
1605 &Transfer->SgList);
1606 }
1607
1608 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1609
1610 if (MpStatus)
1611 {
1612 if ((MpStatus != MP_STATUS_FAILURE) && Transfer->Flags & TRANSFER_FLAG_ISO)
1613 {
1614 DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_ErrorCompleteIsoTransfer\n");
1615 ASSERT(FALSE); //USBPORT_ErrorCompleteIsoTransfer();
1616 }
1617
1619 }
1620
1621 Transfer->Flags |= TRANSFER_FLAG_SUBMITED;
1622 KeQuerySystemTime(&Transfer->Time);
1623
1624 TimeOut.QuadPart = 10000 * Transfer->TimeOut;
1625 Transfer->Time.QuadPart += TimeOut.QuadPart;
1626 }
1627
1629 {
1631 }
1632
1633 Entry = Transfer->TransferLink.Flink;
1634 }
1635
1637}
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
Entry
Definition: section.c:5216
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PVOID MiniportTransfer
Definition: usbport.h:250
LARGE_INTEGER Time
Definition: usbport.h:263
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
LIST_ENTRY TransferLink
Definition: usbport.h:257
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:271
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
LONGLONG QuadPart
Definition: typedefs.h:114
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
#define MP_STATUS_FAILURE
Definition: usbmport.h:135
#define TRANSFER_FLAG_CANCELED
Definition: usbport.h:130
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:133
#define TRANSFER_FLAG_ISO
Definition: usbport.h:135
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:113
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:134

Referenced by USBPORT_DmaEndpointWorker().

◆ USBPORT_DmaEndpointPaused()

ULONG NTAPI USBPORT_DmaEndpointPaused ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 1463 of file endpoint.c.

1465{
1469 PUSBPORT_TRANSFER Transfer;
1470 PURB Urb;
1471 ULONG Frame;
1472 ULONG CurrentFrame;
1473 ULONG CompletedLen = 0;
1474 KIRQL OldIrql;
1475
1476 DPRINT_CORE("USBPORT_DmaEndpointPaused \n");
1477
1478 FdoExtension = FdoDevice->DeviceExtension;
1479 Packet = &FdoExtension->MiniPortInterface->Packet;
1480
1481 Entry = Endpoint->TransferList.Flink;
1482
1483 if (Entry == &Endpoint->TransferList)
1485
1486 while (Entry && Entry != &Endpoint->TransferList)
1487 {
1488 Transfer = CONTAINING_RECORD(Entry,
1490 TransferLink);
1491
1493 {
1494 if (Transfer->Flags & TRANSFER_FLAG_ISO &&
1495 Transfer->Flags & TRANSFER_FLAG_SUBMITED &&
1496 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1497 {
1498 Urb = Transfer->Urb;
1499
1500 Frame = Urb->UrbIsochronousTransfer.StartFrame +
1501 Urb->UrbIsochronousTransfer.NumberOfPackets;
1502
1503 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1504 CurrentFrame = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
1505 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1506
1507 if (Frame + 1 > CurrentFrame)
1508 {
1510 }
1511 }
1512
1513 if ((Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1514 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1515 {
1516 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1517
1518 Packet->AbortTransfer(FdoExtension->MiniPortExt,
1519 Endpoint + 1,
1520 Transfer->MiniportTransfer,
1521 &CompletedLen);
1522
1523 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1524
1525 if (Transfer->Flags & TRANSFER_FLAG_ISO)
1526 {
1527 DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_FlushIsoTransfer\n");
1528 ASSERT(FALSE); //USBPORT_FlushIsoTransfer();
1529 }
1530 else
1531 {
1532 Transfer->CompletedTransferLen = CompletedLen;
1533 }
1534 }
1535
1536 RemoveEntryList(&Transfer->TransferLink);
1537 Entry = Transfer->TransferLink.Flink;
1538
1539 if (Transfer->Flags & TRANSFER_FLAG_SPLITED)
1540 {
1542 }
1543 else
1544 {
1545 InsertTailList(&Endpoint->CancelList, &Transfer->TransferLink);
1546 }
1547 }
1548 else
1549 {
1550 Entry = Transfer->TransferLink.Flink;
1551 }
1552 }
1553
1555}
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
Definition: usb.h:557
ULONG CompletedTransferLen
Definition: usbport.h:259
VOID NTAPI USBPORT_CancelSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:314
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:294
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:137

Referenced by USBPORT_DmaEndpointWorker().

◆ USBPORT_DmaEndpointWorker()

VOID NTAPI USBPORT_DmaEndpointWorker ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 1641 of file endpoint.c.

1642{
1643 PDEVICE_OBJECT FdoDevice;
1644 ULONG PrevState;
1645 ULONG EndpointState;
1646 BOOLEAN IsPaused = FALSE;
1647
1648 DPRINT_CORE("USBPORT_DmaEndpointWorker ... \n");
1649
1650 FdoDevice = Endpoint->FdoDevice;
1651
1652 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1653
1655
1656 if (PrevState == USBPORT_ENDPOINT_PAUSED)
1657 {
1658 EndpointState = USBPORT_DmaEndpointPaused(FdoDevice, Endpoint);
1659 }
1660 else if (PrevState == USBPORT_ENDPOINT_ACTIVE)
1661 {
1662 EndpointState = USBPORT_DmaEndpointActive(FdoDevice, Endpoint);
1663 }
1664 else
1665 {
1666#ifndef NDEBUG_USBPORT_CORE
1667 DPRINT1("USBPORT_DmaEndpointWorker: DbgBreakPoint. EndpointState - %x\n",
1668 EndpointState);
1669 DbgBreakPoint();
1670#endif
1671 EndpointState = USBPORT_ENDPOINT_UNKNOWN;
1672 }
1673
1674 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1675
1677
1678 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1679
1680 if (EndpointState == PrevState)
1681 {
1682 if (EndpointState == USBPORT_ENDPOINT_PAUSED)
1683 {
1684 IsPaused = TRUE;
1685 }
1686 }
1687 else
1688 {
1689 USBPORT_SetEndpointState(Endpoint, EndpointState);
1690 }
1691
1692 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1693
1694 if (IsPaused)
1695 {
1697 Endpoint,
1699 }
1700
1701 DPRINT_CORE("USBPORT_DmaEndpointWorker exit \n");
1702}
VOID NTAPI USBPORT_FlushCancelList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:714
ULONG NTAPI USBPORT_DmaEndpointPaused(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1463
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1367
ULONG NTAPI USBPORT_DmaEndpointActive(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1559
#define USBPORT_ENDPOINT_UNKNOWN
Definition: usbmport.h:13
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
NTSYSAPI void WINAPI DbgBreakPoint(void)

Referenced by USBPORT_EndpointWorker().

◆ USBPORT_EndpointHasQueuedTransfers()

BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint,
IN PULONG  TransferCount 
)

Definition at line 254 of file endpoint.c.

257{
259 PUSBPORT_TRANSFER Transfer;
261
262 DPRINT_CORE("USBPORT_EndpointHasQueuedTransfers: ... \n");
263
264 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
265
266 if (!IsListEmpty(&Endpoint->PendingTransferList))
267 Result = TRUE;
268
269 if (!IsListEmpty(&Endpoint->TransferList))
270 {
271 Result = TRUE;
272
273 if (TransferCount)
274 {
275 *TransferCount = 0;
276
277 for (Entry = Endpoint->TransferList.Flink;
278 Entry && Entry != &Endpoint->TransferList;
279 Entry = Transfer->TransferLink.Flink)
280 {
281 Transfer = CONTAINING_RECORD(Entry,
283 TransferLink);
284
285 if (Transfer->Flags & TRANSFER_FLAG_SUBMITED)
286 {
287 ++*TransferCount;
288 }
289 }
290 }
291 }
292
293 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
294
295 return Result;
296}

Referenced by USBPORT_DeviceHasTransfers(), and USBPORT_FlushDoneTransfers().

◆ USBPORT_EndpointWorker()

BOOLEAN NTAPI USBPORT_EndpointWorker ( IN PUSBPORT_ENDPOINT  Endpoint,
IN BOOLEAN  LockNotChecked 
)

Definition at line 1706 of file endpoint.c.

1708{
1709 PDEVICE_OBJECT FdoDevice;
1712 ULONG EndpointState;
1713
1714 DPRINT_CORE("USBPORT_EndpointWorker: Endpoint - %p, LockNotChecked - %x\n",
1715 Endpoint,
1716 LockNotChecked);
1717
1718 FdoDevice = Endpoint->FdoDevice;
1719 FdoExtension = FdoDevice->DeviceExtension;
1720 Packet = &FdoExtension->MiniPortInterface->Packet;
1721
1722 if (LockNotChecked == FALSE)
1723 {
1724 if (InterlockedIncrement(&Endpoint->LockCounter))
1725 {
1726 InterlockedDecrement(&Endpoint->LockCounter);
1727 DPRINT_CORE("USBPORT_EndpointWorker: LockCounter > 0\n");
1728 return TRUE;
1729 }
1730 }
1731
1733
1734 KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
1735
1737 {
1738 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1739 InterlockedDecrement(&Endpoint->LockCounter);
1740 DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_CLOSED. return FALSE\n");
1741 return FALSE;
1742 }
1743
1745 {
1746 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1747 Packet->PollEndpoint(FdoExtension->MiniPortExt, Endpoint + 1);
1748 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1749 }
1750
1751 EndpointState = USBPORT_GetEndpointState(Endpoint);
1752
1753 if (EndpointState == USBPORT_ENDPOINT_REMOVE)
1754 {
1755 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1756 Endpoint->StateLast = USBPORT_ENDPOINT_CLOSED;
1757 Endpoint->StateNext = USBPORT_ENDPOINT_CLOSED;
1758 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1759
1760 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1761
1762 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1763
1764 ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
1765 &Endpoint->CloseLink,
1766 &FdoExtension->EndpointClosedSpinLock);
1767
1768 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1769
1770 InterlockedDecrement(&Endpoint->LockCounter);
1771 DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_REMOVE. return FALSE\n");
1772 return FALSE;
1773 }
1774
1775 if (!IsListEmpty(&Endpoint->PendingTransferList) ||
1776 !IsListEmpty(&Endpoint->TransferList) ||
1777 !IsListEmpty(&Endpoint->CancelList))
1778 {
1779 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1780
1781 EndpointState = USBPORT_GetEndpointState(Endpoint);
1782
1783 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1784 if (EndpointState == Endpoint->StateNext)
1785 {
1786 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1787
1788 if (Endpoint->EndpointWorker)
1789 {
1791 }
1792 else
1793 {
1795 }
1796
1798
1799 InterlockedDecrement(&Endpoint->LockCounter);
1800 DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1801 return FALSE;
1802 }
1803
1804 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1805 InterlockedDecrement(&Endpoint->LockCounter);
1806
1807 DPRINT_CORE("USBPORT_EndpointWorker: return TRUE\n");
1808 return TRUE;
1809 }
1810
1811 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1812
1814
1815 InterlockedDecrement(&Endpoint->LockCounter);
1816 DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1817 return FALSE;
1818}
VOID NTAPI USBPORT_FlushAbortList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:605
VOID NTAPI USBPORT_DmaEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1641
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define USBPORT_ENDPOINT_CLOSED
Definition: usbmport.h:17
VOID NTAPI USBPORT_RootHubEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
Definition: roothub.c:663

Referenced by USBPORT_DpcHandler(), USBPORT_FlushPendingTransfers(), USBPORT_MapTransfer(), and USBPORT_WorkerThreadHandler().

◆ USBPORT_FlushClosedEndpointList()

VOID NTAPI USBPORT_FlushClosedEndpointList ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1331 of file endpoint.c.

1332{
1334 KIRQL OldIrql;
1335 PLIST_ENTRY ClosedList;
1337
1338 DPRINT_CORE("USBPORT_FlushClosedEndpointList: ... \n");
1339
1340 FdoExtension = FdoDevice->DeviceExtension;
1341
1342 KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1343 ClosedList = &FdoExtension->EndpointClosedList;
1344
1345 while (!IsListEmpty(ClosedList))
1346 {
1347 Endpoint = CONTAINING_RECORD(ClosedList->Flink,
1349 CloseLink);
1350
1351 RemoveHeadList(ClosedList);
1352 Endpoint->CloseLink.Flink = NULL;
1353 Endpoint->CloseLink.Blink = NULL;
1354
1355 KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1356
1357 USBPORT_DeleteEndpoint(FdoDevice, Endpoint);
1358
1359 KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1360 }
1361
1362 KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1363}
BOOLEAN NTAPI USBPORT_DeleteEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:506
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964

Referenced by USBPORT_WorkerThreadHandler().

◆ USBPORT_FreeBandwidth()

VOID NTAPI USBPORT_FreeBandwidth ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 171 of file endpoint.c.

173{
175 PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties;
176 ULONG TransferType;
178 ULONG EndpointBandwidth;
180 ULONG Factor;
181 UCHAR Bit;
182
183 DPRINT("USBPORT_FreeBandwidth: FdoDevice - %p, Endpoint - %p\n",
184 FdoDevice,
185 Endpoint);
186
187 FdoExtension = FdoDevice->DeviceExtension;
188
189 EndpointProperties = &Endpoint->EndpointProperties;
190 TransferType = EndpointProperties->TransferType;
191
192 if (TransferType == USBPORT_TRANSFER_TYPE_BULK ||
193 TransferType == USBPORT_TRANSFER_TYPE_CONTROL ||
195 {
196 return;
197 }
198
199 Offset = Endpoint->EndpointProperties.ScheduleOffset;
200 EndpointBandwidth = Endpoint->EndpointProperties.UsbBandwidth;
201
202 Period = Endpoint->EndpointProperties.Period;
203 ASSERT(Period != 0);
204
205 for (Factor = USB2_FRAMES / Period; Factor; Factor--)
206 {
207 FdoExtension->Bandwidth[Offset * Factor] += EndpointBandwidth;
208 }
209
210 if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
211 {
212 for (Bit = 0x80; Bit != 0; Bit >>= 1)
213 {
214 if ((Period & Bit) != 0)
215 {
216 Period = Bit;
217 break;
218 }
219 }
220
221 ASSERT(Period != 0);
222
223 DPRINT("USBPORT_AllocateBandwidth: FIXME AllocatedInterrupt_XXms\n");
224 }
225 else
226 {
227 DPRINT("USBPORT_AllocateBandwidth: FIXME AllocatedIso\n");
228 }
229
230 DPRINT1("USBPORT_FreeBandwidth: FIXME USBPORT_UpdateAllocatedBw\n");
231}

Referenced by USBPORT_ClosePipe(), and USBPORT_OpenPipe().

◆ USBPORT_GetEndpointState()

ULONG NTAPI USBPORT_GetEndpointState ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 332 of file endpoint.c.

333{
334 ULONG State;
335
336 //DPRINT("USBPORT_GetEndpointState \n");
337
338 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
339
340 if (Endpoint->StateLast != Endpoint->StateNext)
341 {
343 }
344 else
345 {
346 State = Endpoint->StateLast;
347 }
348
349 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
350
352 {
353 DPRINT("USBPORT_GetEndpointState: Endpoint - %p, State - %x\n",
354 Endpoint,
355 State);
356 }
357
358 return State;
359}

Referenced by USBPORT_DmaEndpointPaused(), USBPORT_DmaEndpointWorker(), USBPORT_DpcHandler(), USBPORT_EndpointWorker(), USBPORT_FlushAllEndpoints(), USBPORT_InvalidateEndpointHandler(), USBPORT_OpenPipe(), and USBPORT_SyncResetPipeAndClearStall().

◆ USBPORT_InvalidateEndpointHandler()

VOID NTAPI USBPORT_InvalidateEndpointHandler ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint,
IN ULONG  Type 
)

Definition at line 1367 of file endpoint.c.

1370{
1374 PLIST_ENTRY WorkerLink;
1376 KIRQL OldIrql;
1377 BOOLEAN IsAddEntry = FALSE;
1378
1379 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: Endpoint - %p, Type - %x\n",
1380 Endpoint,
1381 Type);
1382
1383 FdoExtension = FdoDevice->DeviceExtension;
1384 Packet = &FdoExtension->MiniPortInterface->Packet;
1385
1386 if (Endpoint)
1387 {
1388 WorkerLink = &Endpoint->WorkerLink;
1389 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1390 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: KeAcquireSpinLock \n");
1391
1392 if ((!WorkerLink->Flink || !WorkerLink->Blink) &&
1393 !(Endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1395 {
1396 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1397 InsertTailList(&FdoExtension->WorkerList, WorkerLink);
1398 IsAddEntry = TRUE;
1399 }
1400
1401 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1402
1405 }
1406 else
1407 {
1408 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1409
1410 for (Entry = FdoExtension->EndpointList.Flink;
1411 Entry && Entry != &FdoExtension->EndpointList;
1412 Entry = Entry->Flink)
1413 {
1416 EndpointLink);
1417
1418 if (!endpoint->WorkerLink.Flink || !endpoint->WorkerLink.Blink)
1419 {
1420 if (!(endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1421 !(endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0) &&
1423 {
1424 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1425 InsertTailList(&FdoExtension->WorkerList, &endpoint->WorkerLink);
1426 IsAddEntry = TRUE;
1427 }
1428 }
1429 }
1430
1431 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1432 }
1433
1435 {
1437 }
1438 else if (IsAddEntry == FALSE && Type == INVALIDATE_ENDPOINT_INT_NEXT_SOF)
1439 {
1441 }
1442
1443 switch (Type)
1444 {
1446 USBPORT_SignalWorkerThread(FdoDevice);
1447 break;
1448
1450 KeInsertQueueDpc(&FdoExtension->WorkerRequestDpc, NULL, NULL);
1451 break;
1452
1454 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1455 Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
1456 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1457 break;
1458 }
1459}
Type
Definition: Type.h:7
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
Definition: nis.h:10
#define ENDPOINT_FLAG_IDLE
Definition: usbport.h:116
#define INVALIDATE_ENDPOINT_INT_NEXT_SOF
Definition: usbport.h:39
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38

Referenced by USBPORT_AbortEndpoint(), USBPORT_CancelActiveTransferIrp(), USBPORT_DmaEndpointWorker(), USBPORT_FlushDoneTransfers(), USBPORT_FlushPendingTransfers(), USBPORT_InvalidateEndpoint(), USBPORT_InvalidateRootHub(), USBPORT_IsrDpcHandler(), USBPORT_MapTransfer(), and USBPORT_SetEndpointState().

◆ USBPORT_NormalizeHsInterval()

UCHAR NTAPI USBPORT_NormalizeHsInterval ( UCHAR  Interval)

Definition at line 235 of file endpoint.c.

236{
238
239 DPRINT("USBPORT_NormalizeHsInterval: Interval - %x\n", Interval);
240
242
243 if (Interval)
244 interval = Interval - 1;
245
246 if (interval > 5)
247 interval = 5;
248
249 return 1 << interval;
250}
DWORD Interval
Definition: netstat.c:28

Referenced by USBPORT_OpenPipe().

◆ USBPORT_NukeAllEndpoints()

VOID NTAPI USBPORT_NukeAllEndpoints ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 300 of file endpoint.c.

301{
303 PLIST_ENTRY EndpointList;
306
307 DPRINT("USBPORT_NukeAllEndpoints \n");
308
309 FdoExtension = FdoDevice->DeviceExtension;
310
311 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
312
313 EndpointList = FdoExtension->EndpointList.Flink;
314
315 while (EndpointList && (EndpointList != &FdoExtension->EndpointList))
316 {
317 Endpoint = CONTAINING_RECORD(EndpointList,
319 EndpointLink);
320
321 if (!(Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0))
323
324 EndpointList = Endpoint->EndpointLink.Flink;
325 }
326
327 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
328}

Referenced by USBPORT_ResumeController().

◆ USBPORT_OpenPipe()

NTSTATUS NTAPI USBPORT_OpenPipe ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PUSBPORT_PIPE_HANDLE  PipeHandle,
IN OUT PUSBD_STATUS  UsbdStatus 
)

Definition at line 789 of file endpoint.c.

793{
797 SIZE_T EndpointSize;
799 PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties;
800 PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
804 USBPORT_ENDPOINT_REQUIREMENTS EndpointRequirements = {0};
806 MPSTATUS MpStatus;
807 USBD_STATUS USBDStatus = USBD_STATUS_SUCCESS;
811 USHORT AdditionalTransaction;
812 BOOLEAN IsAllocatedBandwidth;
813 ULONG RetryCount;
814
815 DPRINT1("USBPORT_OpenPipe: DeviceHandle - %p, FdoDevice - %p, PipeHandle - %p\n",
817 FdoDevice,
818 PipeHandle);
819
820 FdoExtension = FdoDevice->DeviceExtension;
821 Packet = &FdoExtension->MiniPortInterface->Packet;
822
823 EndpointSize = sizeof(USBPORT_ENDPOINT) + Packet->MiniPortEndpointSize;
824
825 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
826 {
827 EndpointSize += sizeof(USB2_TT_ENDPOINT);
828 }
829
830 if (PipeHandle->EndpointDescriptor.wMaxPacketSize == 0)
831 {
833
834 PipeHandle->Flags = (PipeHandle->Flags & ~PIPE_HANDLE_FLAG_CLOSED) |
836
837 PipeHandle->Endpoint = (PUSBPORT_ENDPOINT)-1;
838
839 return STATUS_SUCCESS;
840 }
841
843
844 if (!Endpoint)
845 {
846 DPRINT1("USBPORT_OpenPipe: Not allocated Endpoint!\n");
848 return Status;
849 }
850
851 RtlZeroMemory(Endpoint, EndpointSize);
852
853 Endpoint->FdoDevice = FdoDevice;
854 Endpoint->DeviceHandle = DeviceHandle;
855 Endpoint->LockCounter = -1;
856
857 Endpoint->TtExtension = DeviceHandle->TtExtension;
858
859 if (DeviceHandle->TtExtension)
860 {
861 ExInterlockedInsertTailList(&DeviceHandle->TtExtension->EndpointList,
862 &Endpoint->TtLink,
863 &FdoExtension->TtSpinLock);
864 }
865
866 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
867 {
869 sizeof(USBPORT_ENDPOINT) +
870 Packet->MiniPortEndpointSize);
871 }
872 else
873 {
874 Endpoint->TtEndpoint = NULL;
875 }
876
877 KeInitializeSpinLock(&Endpoint->EndpointSpinLock);
878 KeInitializeSpinLock(&Endpoint->StateChangeSpinLock);
879
880 InitializeListHead(&Endpoint->PendingTransferList);
881 InitializeListHead(&Endpoint->TransferList);
882 InitializeListHead(&Endpoint->CancelList);
883 InitializeListHead(&Endpoint->AbortList);
884
885 EndpointProperties = &Endpoint->EndpointProperties;
886 EndpointDescriptor = &PipeHandle->EndpointDescriptor;
887
888 MaxPacketSize = EndpointDescriptor->wMaxPacketSize & 0x7FF;
889 AdditionalTransaction = (EndpointDescriptor->wMaxPacketSize >> 11) & 3;
890
891 EndpointProperties->DeviceAddress = DeviceHandle->DeviceAddress;
892 EndpointProperties->DeviceSpeed = DeviceHandle->DeviceSpeed;
893 EndpointProperties->Period = 0;
894 EndpointProperties->EndpointAddress = EndpointDescriptor->bEndpointAddress;
895 EndpointProperties->TransactionPerMicroframe = AdditionalTransaction + 1;
896 EndpointProperties->MaxPacketSize = MaxPacketSize;
897 EndpointProperties->TotalMaxPacketSize = MaxPacketSize *
898 (AdditionalTransaction + 1);
899
900 if (Endpoint->TtExtension)
901 {
902 EndpointProperties->HubAddr = Endpoint->TtExtension->DeviceAddress;
903 }
904 else
905 {
906 EndpointProperties->HubAddr = -1;
907 }
908
909 EndpointProperties->PortNumber = DeviceHandle->PortNumber;
910
911 switch (EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK)
912 {
914 EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_CONTROL;
915
916 if (EndpointProperties->EndpointAddress == 0)
917 {
918 EndpointProperties->MaxTransferSize = 0x1000; // OUT Ep0
919 }
920 else
921 {
922 EndpointProperties->MaxTransferSize = 0x10000;
923 }
924
925 break;
926
928 DPRINT1("USBPORT_OpenPipe: USB_ENDPOINT_TYPE_ISOCHRONOUS UNIMPLEMENTED. FIXME. \n");
930 EndpointProperties->MaxTransferSize = 0x1000000;
931 break;
932
934 EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_BULK;
935 EndpointProperties->MaxTransferSize = 0x10000;
936 break;
937
939 EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_INTERRUPT;
940 EndpointProperties->MaxTransferSize = 0x400;
941 break;
942 }
943
944 if (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
945 {
946 if (EndpointProperties->DeviceSpeed == UsbHighSpeed)
947 {
948 Interval = USBPORT_NormalizeHsInterval(EndpointDescriptor->bInterval);
949 }
950 else
951 {
952 Interval = EndpointDescriptor->bInterval;
953 }
954
955 EndpointProperties->Period = ENDPOINT_INTERRUPT_32ms;
956
957 if (Interval && (Interval < USB2_FRAMES))
958 {
959 if ((EndpointProperties->DeviceSpeed != UsbLowSpeed) ||
961 {
963 {
964 Period = EndpointProperties->Period;
965
966 do
967 {
968 Period >>= 1;
969 }
970 while (!(Period & Interval));
971
972 EndpointProperties->Period = Period;
973 }
974 }
975 else
976 {
977 EndpointProperties->Period = ENDPOINT_INTERRUPT_8ms;
978 }
979 }
980 }
981
982 if (EndpointProperties->TransferType == USB_ENDPOINT_TYPE_ISOCHRONOUS)
983 {
984 if (EndpointProperties->DeviceSpeed == UsbHighSpeed)
985 {
986 EndpointProperties->Period =
987 USBPORT_NormalizeHsInterval(EndpointDescriptor->bInterval);
988 }
989 else
990 {
991 EndpointProperties->Period = ENDPOINT_INTERRUPT_1ms;
992 }
993 }
994
995 if ((DeviceHandle->Flags & DEVICE_HANDLE_FLAG_ROOTHUB) != 0)
996 {
998 }
999
1000 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1001 {
1002 IsAllocatedBandwidth = USBPORT_AllocateBandwidthUSB2(FdoDevice, Endpoint);
1003 }
1004 else
1005 {
1006 EndpointProperties->UsbBandwidth = USBPORT_CalculateUsbBandwidth(FdoDevice,
1007 Endpoint);
1008
1009 IsAllocatedBandwidth = USBPORT_AllocateBandwidth(FdoDevice, Endpoint);
1010 }
1011
1012 if (!IsAllocatedBandwidth)
1013 {
1015
1016 if (UsbdStatus)
1017 {
1019 }
1020
1021 goto ExitWithError;
1022 }
1023
1025 EndpointProperties->Direction = Direction;
1026
1027 if (DeviceHandle->IsRootHub)
1028 {
1029 Endpoint->EndpointWorker = 0; // USBPORT_RootHubEndpointWorker;
1030
1032
1033 Endpoint->StateLast = USBPORT_ENDPOINT_ACTIVE;
1034 Endpoint->StateNext = USBPORT_ENDPOINT_ACTIVE;
1035
1036 PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
1037
1038 if (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
1039 {
1040 PdoExtension->Endpoint = Endpoint;
1041 }
1042
1043 USBDStatus = USBD_STATUS_SUCCESS;
1044 }
1045 else
1046 {
1047 Endpoint->EndpointWorker = 1; // USBPORT_DmaEndpointWorker;
1048
1049 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1050
1051 Packet->QueryEndpointRequirements(FdoExtension->MiniPortExt,
1052 &Endpoint->EndpointProperties,
1053 &EndpointRequirements);
1054
1055 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1056
1057 if ((EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_BULK) ||
1058 (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT))
1059 {
1060 EndpointProperties->MaxTransferSize = EndpointRequirements.MaxTransferSize;
1061 }
1062
1063 if (EndpointRequirements.HeaderBufferSize)
1064 {
1065 HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
1066 EndpointRequirements.HeaderBufferSize);
1067 }
1068 else
1069 {
1070 HeaderBuffer = NULL;
1071 }
1072
1073 if (HeaderBuffer || (EndpointRequirements.HeaderBufferSize == 0))
1074 {
1075 Endpoint->HeaderBuffer = HeaderBuffer;
1076
1077 if (HeaderBuffer)
1078 {
1079 EndpointProperties->BufferVA = HeaderBuffer->VirtualAddress;
1080 EndpointProperties->BufferPA = HeaderBuffer->PhysicalAddress;
1081 EndpointProperties->BufferLength = HeaderBuffer->BufferLength; // BufferLength + LengthPadded;
1082 }
1083
1084 MpStatus = MiniportOpenEndpoint(FdoDevice, Endpoint);
1085
1088
1089 if (MpStatus == 0)
1090 {
1091 ULONG State;
1092
1093 KeAcquireSpinLock(&Endpoint->EndpointSpinLock,
1094 &Endpoint->EndpointOldIrql);
1095
1096 Endpoint->StateLast = USBPORT_ENDPOINT_PAUSED;
1097 Endpoint->StateNext = USBPORT_ENDPOINT_PAUSED;
1098
1100
1101 KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
1102 Endpoint->EndpointOldIrql);
1103
1104 /* Wait maximum 1 second for the endpoint to be active */
1105 for (RetryCount = 0; RetryCount < 1000; RetryCount++)
1106 {
1107 KeAcquireSpinLock(&Endpoint->EndpointSpinLock,
1108 &Endpoint->EndpointOldIrql);
1109
1111
1112 KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
1113 Endpoint->EndpointOldIrql);
1114
1116 {
1117 break;
1118 }
1119
1120 USBPORT_Wait(FdoDevice, 1); // 1 msec.
1121 }
1123 {
1124 DPRINT1("Timeout State %x\n", State);
1125 USBDStatus = USBD_STATUS_TIMEOUT;
1126 }
1127 }
1128 }
1129 else
1130 {
1131 MpStatus = MP_STATUS_NO_RESOURCES;
1132 Endpoint->HeaderBuffer = NULL;
1133 }
1134
1135 if (MpStatus)
1136 {
1138 }
1139 }
1140
1141 if (UsbdStatus)
1142 {
1143 *UsbdStatus = USBDStatus;
1144 }
1145
1147
1148 if (NT_SUCCESS(Status))
1149 {
1151
1153 &Endpoint->EndpointLink,
1154 &FdoExtension->EndpointListSpinLock);
1155
1156 PipeHandle->Endpoint = Endpoint;
1157 PipeHandle->Flags &= ~PIPE_HANDLE_FLAG_CLOSED;
1158
1159 return Status;
1160 }
1161
1162ExitWithError:
1163
1164 if (Endpoint)
1165 {
1166 /* A timed out endpoint is still queued for the ISR DPC and opened in the miniport */
1167 KeAcquireSpinLock(&FdoExtension->EpStateChangeSpinLock, &OldIrql);
1168
1169 if (Endpoint->StateChangeLink.Flink != NULL &&
1170 Endpoint->StateChangeLink.Blink != NULL)
1171 {
1172 RemoveEntryList(&Endpoint->StateChangeLink);
1173 }
1174
1175 Endpoint->StateChangeLink.Flink = NULL;
1176 Endpoint->StateChangeLink.Blink = NULL;
1177
1178 KeReleaseSpinLock(&FdoExtension->EpStateChangeSpinLock, OldIrql);
1179
1180 MiniportCloseEndpoint(FdoDevice, Endpoint);
1181
1182 if (Endpoint->HeaderBuffer)
1183 {
1184 USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
1185 }
1186
1187 if (IsAllocatedBandwidth)
1188 {
1189 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1190 {
1192 }
1193 else
1194 {
1195 USBPORT_FreeBandwidth(FdoDevice, Endpoint);
1196 }
1197 }
1198
1199 if (Endpoint->TtExtension)
1200 {
1201 KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
1202 RemoveEntryList(&Endpoint->TtLink);
1203 KeReleaseSpinLock(&FdoExtension->TtSpinLock, OldIrql);
1204 }
1205
1207 }
1208
1209 DPRINT1("USBPORT_OpenPipe: Status - %lx\n", Status);
1210 return Status;
1211}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG NTAPI USBPORT_CalculateUsbBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:18
VOID NTAPI USBPORT_AddPipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:452
BOOLEAN NTAPI USBPORT_AllocateBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:63
MPSTATUS NTAPI MiniportOpenEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:748
UCHAR NTAPI USBPORT_NormalizeHsInterval(UCHAR Interval)
Definition: endpoint.c:235
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ UCXUSBDEVICE _In_ ULONG MaxPacketSize
Definition: hubucx.h:289
if(dx< 0)
Definition: linetemp.h:194
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb100.h:65
#define USB_ENDPOINT_DIRECTION_OUT(x)
Definition: usb100.h:75
#define USB_ENDPOINT_TYPE_CONTROL
Definition: usb100.h:62
#define USB_ENDPOINT_TYPE_ISOCHRONOUS
Definition: usb100.h:63
#define USB_ENDPOINT_TYPE_MASK
Definition: usb100.h:61
#define USB_ENDPOINT_TYPE_BULK
Definition: usb100.h:64
@ UsbHighSpeed
Definition: usb200.h:44
BOOLEAN NTAPI USBPORT_AllocateBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: usb2.c:1799
#define USBD_STATUS_NO_BANDWIDTH
Definition: usb.h:205
#define USBD_STATUS_SUCCESS
Definition: usb.h:176
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:214
#define USBD_STATUS_TIMEOUT
Definition: usb.h:220
LONG USBD_STATUS
Definition: usb.h:171
#define ENDPOINT_INTERRUPT_32ms
Definition: usbmport.h:30
#define ENDPOINT_INTERRUPT_8ms
Definition: usbmport.h:28
#define ENDPOINT_INTERRUPT_1ms
Definition: usbmport.h:25
#define MP_STATUS_NO_RESOURCES
Definition: usbmport.h:136
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1743
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
struct _USB2_TT_ENDPOINT * PUSB2_TT_ENDPOINT
Definition: usbport.h:160
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:155
#define DEVICE_HANDLE_FLAG_ROOTHUB
Definition: usbport.h:106
struct _USB2_TT_ENDPOINT USB2_TT_ENDPOINT
#define ENDPOINT_FLAG_DMA_TYPE
Definition: usbport.h:111
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
#define ENDPOINT_FLAG_QUEUENE_EMPTY
Definition: usbport.h:114
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION Direction
_In_ NTSTATUS _In_ USBD_STATUS UsbdStatus
Definition: wdfusb.h:403

Referenced by USBPORT_CreateDevice(), USBPORT_OpenInterface(), and USBPORT_RootHubCreateDevice().

◆ USBPORT_RemovePipeHandle()

VOID NTAPI USBPORT_RemovePipeHandle ( IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PUSBPORT_PIPE_HANDLE  PipeHandle 
)

Definition at line 464 of file endpoint.c.

466{
467 DPRINT("USBPORT_RemovePipeHandle: PipeHandle - %p\n", PipeHandle);
468
469 RemoveEntryList(&PipeHandle->PipeLink);
470
471 PipeHandle->PipeLink.Flink = NULL;
472 PipeHandle->PipeLink.Blink = NULL;
473}

Referenced by USBPORT_ClosePipe(), and USBPORT_RestoreDevice().

◆ USBPORT_ReopenPipe()

NTSTATUS NTAPI USBPORT_ReopenPipe ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint 
)

Definition at line 1215 of file endpoint.c.

1217{
1219 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
1220 USBPORT_ENDPOINT_REQUIREMENTS EndpointRequirements = {0};
1222 KIRQL MiniportOldIrql;
1224
1225 DPRINT1("USBPORT_ReopenPipe ... \n");
1226
1227 FdoExtension = FdoDevice->DeviceExtension;
1228 Packet = &FdoExtension->MiniPortInterface->Packet;
1229
1230 while (TRUE)
1231 {
1232 if (!InterlockedIncrement(&Endpoint->LockCounter))
1233 break;
1234
1235 InterlockedDecrement(&Endpoint->LockCounter);
1236 USBPORT_Wait(FdoDevice, 1);
1237 }
1238
1239 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1240 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1241
1242 Packet->SetEndpointState(FdoExtension->MiniPortExt,
1243 Endpoint + 1,
1245
1246 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1247 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1248
1249 USBPORT_Wait(FdoDevice, 2);
1250
1251 MiniportCloseEndpoint(FdoDevice, Endpoint);
1252
1254 Packet->MiniPortEndpointSize);
1255
1256 if (Endpoint->HeaderBuffer)
1257 {
1258 USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
1259 Endpoint->HeaderBuffer = NULL;
1260 }
1261
1262 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &MiniportOldIrql);
1263
1264 Packet->QueryEndpointRequirements(FdoExtension->MiniPortExt,
1265 &Endpoint->EndpointProperties,
1266 &EndpointRequirements);
1267
1268 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, MiniportOldIrql);
1269
1270 if (EndpointRequirements.HeaderBufferSize)
1271 {
1272 HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
1273 EndpointRequirements.HeaderBufferSize);
1274 }
1275 else
1276 {
1277 HeaderBuffer = NULL;
1278 }
1279
1280 if (HeaderBuffer || EndpointRequirements.HeaderBufferSize == 0)
1281 {
1282 Endpoint->HeaderBuffer = HeaderBuffer;
1284 }
1285 else
1286 {
1287 Endpoint->HeaderBuffer = 0;
1289 }
1290
1291 if (Endpoint->HeaderBuffer && HeaderBuffer)
1292 {
1293 Endpoint->EndpointProperties.BufferVA = HeaderBuffer->VirtualAddress;
1294 Endpoint->EndpointProperties.BufferPA = HeaderBuffer->PhysicalAddress;
1295 Endpoint->EndpointProperties.BufferLength = HeaderBuffer->BufferLength;
1296 }
1297
1298 if (NT_SUCCESS(Status))
1299 {
1300 MiniportOpenEndpoint(FdoDevice, Endpoint);
1301
1302 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1303 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1304
1305 if (Endpoint->StateLast == USBPORT_ENDPOINT_ACTIVE)
1306 {
1307 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1308 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1309
1310 Packet->SetEndpointState(FdoExtension->MiniPortExt,
1311 Endpoint + 1,
1313
1314 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1315 }
1316 else
1317 {
1318 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1319 }
1320
1321 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1322 }
1323
1324 InterlockedDecrement(&Endpoint->LockCounter);
1325
1326 return Status;
1327}

Referenced by USBPORT_InitializeDevice().

◆ USBPORT_SetEndpointState()

VOID NTAPI USBPORT_SetEndpointState ( IN PUSBPORT_ENDPOINT  Endpoint,
IN ULONG  State 
)

Definition at line 363 of file endpoint.c.

365{
366 PDEVICE_OBJECT FdoDevice;
370
371 DPRINT("USBPORT_SetEndpointState: Endpoint - %p, State - %x\n",
372 Endpoint,
373 State);
374
375 FdoDevice = Endpoint->FdoDevice;
376 FdoExtension = FdoDevice->DeviceExtension;
377 Packet = &FdoExtension->MiniPortInterface->Packet;
378
379 KeAcquireSpinLock(&Endpoint->StateChangeSpinLock,
380 &Endpoint->EndpointStateOldIrql);
381
382 if (!(Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0))
383 {
384 if (Endpoint->Flags & ENDPOINT_FLAG_NUKE)
385 {
386 Endpoint->StateLast = State;
387 Endpoint->StateNext = State;
388
389 KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
390 Endpoint->EndpointStateOldIrql);
391
393 Endpoint,
395 return;
396 }
397
398 KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
399 Endpoint->EndpointStateOldIrql);
400
401 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
402 Packet->SetEndpointState(FdoExtension->MiniPortExt,
403 Endpoint + 1,
404 State);
405 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
406
407 Endpoint->StateNext = State;
408
409 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
410 Endpoint->FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
411 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
412
413 KIRQL StateChangeOldIrql;
414 KeAcquireSpinLock(&FdoExtension->EpStateChangeSpinLock, &StateChangeOldIrql);
415
416 if (Endpoint->StateChangeLink.Flink == NULL &&
417 Endpoint->StateChangeLink.Blink == NULL)
418 {
419 InsertTailList(&FdoExtension->EpStateChangeList,
420 &Endpoint->StateChangeLink);
421 }
422
423 KeReleaseSpinLock(&FdoExtension->EpStateChangeSpinLock, StateChangeOldIrql);
424
425 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
426 Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
427 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
428 }
429 else
430 {
431 Endpoint->StateLast = State;
432 Endpoint->StateNext = State;
433
435 {
436 KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
437 Endpoint->EndpointStateOldIrql);
438
440 Endpoint,
442 return;
443 }
444
445 KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
446 Endpoint->EndpointStateOldIrql);
447 }
448}

Referenced by USBPORT_ClosePipe(), USBPORT_DmaEndpointWorker(), USBPORT_OpenPipe(), and USBPORT_SyncResetPipeAndClearStall().

◆ USBPORT_ValidatePipeHandle()

BOOLEAN NTAPI USBPORT_ValidatePipeHandle ( IN PUSBPORT_DEVICE_HANDLE  DeviceHandle,
IN PUSBPORT_PIPE_HANDLE  PipeHandle 
)

Definition at line 477 of file endpoint.c.

479{
480 PLIST_ENTRY HandleList;
481 PUSBPORT_PIPE_HANDLE CurrentHandle;
482
483 //DPRINT("USBPORT_ValidatePipeHandle: DeviceHandle - %p, PipeHandle - %p\n",
484 // DeviceHandle,
485 // PipeHandle);
486
487 HandleList = DeviceHandle->PipeHandleList.Flink;
488
489 while (HandleList != &DeviceHandle->PipeHandleList)
490 {
491 CurrentHandle = CONTAINING_RECORD(HandleList,
493 PipeLink);
494
495 HandleList = HandleList->Flink;
496
497 if (CurrentHandle == PipeHandle)
498 return TRUE;
499 }
500
501 return FALSE;
502}

Referenced by USBPORT_AbortPipe(), USBPORT_ClearStall(), USBPORT_ResetPipe(), USBPORT_SyncResetPipeAndClearStall(), and USBPORT_ValidateURB().