ReactOS 0.4.16-dev-2208-g6350669
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;
608 Endpoint->Flags |= ENDPOINT_FLAG_CLOSED;
609 }
610
611 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
612}
unsigned char BOOLEAN
@ FdoExtension
Definition: precomp.h:48
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_ 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_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
780 Endpoint->Flags |= ENDPOINT_FLAG_OPENED;
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)
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121

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 ||
91 Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0)
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
#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:1313
unsigned char UCHAR
Definition: xmlstorage.h:181

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{
622 PUSBPORT_ENDPOINT Endpoint;
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) &&
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
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
679 if (Endpoint->StateLast != Endpoint->StateNext)
680 IsReady = FALSE;
682
684 Endpoint->EndpointOldIrql);
685
686 if (InterlockedIncrement(&Endpoint->LockCounter))
687 IsReady = FALSE;
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 {
701 USBPORT_FreeBandwidthUSB2(FdoDevice, Endpoint);
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 {
736 USBPORT_FreeBandwidth(FdoDevice, Endpoint);
737 }
738
739 KeAcquireSpinLock(&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:49
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
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
ULONG MaxBandwidth
Definition: usbport.h:553
LIST_ENTRY EndpointList
Definition: usbport.h:557
KIRQL EndpointOldIrql
Definition: usbport.h:216
PUSBPORT_DEVICE_HANDLE DeviceHandle
Definition: usbport.h:208
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:225
LIST_ENTRY CancelList
Definition: usbport.h:229
LIST_ENTRY PendingTransferList
Definition: usbport.h:227
LIST_ENTRY TransferList
Definition: usbport.h:228
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
LIST_ENTRY TtLink
Definition: usbport.h:239
PUSB2_TT_EXTENSION TtExtension
Definition: usbport.h:209
LIST_ENTRY AbortList
Definition: usbport.h:230
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:211
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
558 MiniportCloseEndpoint(FdoDevice, Endpoint);
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 1538 of file endpoint.c.

1540{
1544 PUSBPORT_TRANSFER Transfer;
1545 LARGE_INTEGER TimeOut;
1546 MPSTATUS MpStatus;
1547 KIRQL OldIrql;
1548
1549 DPRINT_CORE("USBPORT_DmaEndpointActive \n");
1550
1551 FdoExtension = FdoDevice->DeviceExtension;
1552
1553 Entry = Endpoint->TransferList.Flink;
1554
1555 while (Entry && Entry != &Endpoint->TransferList)
1556 {
1557 Transfer = CONTAINING_RECORD(Entry,
1559 TransferLink);
1560
1561 if (!(Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1562 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1563 {
1564 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1565
1566 Packet = &FdoExtension->MiniPortInterface->Packet;
1567
1568 if (Transfer->Flags & TRANSFER_FLAG_ISO)
1569 {
1570 DPRINT1("USBPORT_DmaEndpointActive: FIXME call SubmitIsoTransfer\n");
1571
1572 MpStatus = Packet->SubmitIsoTransfer(FdoExtension->MiniPortExt,
1573 Endpoint + 1,
1574 &Transfer->TransferParameters,
1575 Transfer->MiniportTransfer,
1576 NULL);//&Transfer->IsoTransferParameters);
1577 }
1578 else
1579 {
1580 MpStatus = Packet->SubmitTransfer(FdoExtension->MiniPortExt,
1581 Endpoint + 1,
1582 &Transfer->TransferParameters,
1583 Transfer->MiniportTransfer,
1584 &Transfer->SgList);
1585 }
1586
1587 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1588
1589 if (MpStatus)
1590 {
1591 if ((MpStatus != MP_STATUS_FAILURE) && Transfer->Flags & TRANSFER_FLAG_ISO)
1592 {
1593 DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_ErrorCompleteIsoTransfer\n");
1594 ASSERT(FALSE); //USBPORT_ErrorCompleteIsoTransfer();
1595 }
1596
1598 }
1599
1600 Transfer->Flags |= TRANSFER_FLAG_SUBMITED;
1601 KeQuerySystemTime(&Transfer->Time);
1602
1603 TimeOut.QuadPart = 10000 * Transfer->TimeOut;
1604 Transfer->Time.QuadPart += TimeOut.QuadPart;
1605 }
1606
1608 {
1610 }
1611
1612 Entry = Transfer->TransferLink.Flink;
1613 }
1614
1616}
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
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 1442 of file endpoint.c.

1444{
1448 PUSBPORT_TRANSFER Transfer;
1449 PURB Urb;
1450 ULONG Frame;
1451 ULONG CurrentFrame;
1452 ULONG CompletedLen = 0;
1453 KIRQL OldIrql;
1454
1455 DPRINT_CORE("USBPORT_DmaEndpointPaused \n");
1456
1457 FdoExtension = FdoDevice->DeviceExtension;
1458 Packet = &FdoExtension->MiniPortInterface->Packet;
1459
1460 Entry = Endpoint->TransferList.Flink;
1461
1462 if (Entry == &Endpoint->TransferList)
1464
1465 while (Entry && Entry != &Endpoint->TransferList)
1466 {
1467 Transfer = CONTAINING_RECORD(Entry,
1469 TransferLink);
1470
1472 {
1473 if (Transfer->Flags & TRANSFER_FLAG_ISO &&
1474 Transfer->Flags & TRANSFER_FLAG_SUBMITED &&
1475 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1476 {
1477 Urb = Transfer->Urb;
1478
1479 Frame = Urb->UrbIsochronousTransfer.StartFrame +
1480 Urb->UrbIsochronousTransfer.NumberOfPackets;
1481
1482 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1483 CurrentFrame = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
1484 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1485
1486 if (Frame + 1 > CurrentFrame)
1487 {
1488 return USBPORT_GetEndpointState(Endpoint);
1489 }
1490 }
1491
1492 if ((Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1493 !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1494 {
1495 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1496
1497 Packet->AbortTransfer(FdoExtension->MiniPortExt,
1498 Endpoint + 1,
1499 Transfer->MiniportTransfer,
1500 &CompletedLen);
1501
1502 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1503
1504 if (Transfer->Flags & TRANSFER_FLAG_ISO)
1505 {
1506 DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_FlushIsoTransfer\n");
1507 ASSERT(FALSE); //USBPORT_FlushIsoTransfer();
1508 }
1509 else
1510 {
1511 Transfer->CompletedTransferLen = CompletedLen;
1512 }
1513 }
1514
1515 RemoveEntryList(&Transfer->TransferLink);
1516 Entry = Transfer->TransferLink.Flink;
1517
1518 if (Transfer->Flags & TRANSFER_FLAG_SPLITED)
1519 {
1521 }
1522 else
1523 {
1524 InsertTailList(&Endpoint->CancelList, &Transfer->TransferLink);
1525 }
1526 }
1527 else
1528 {
1529 Entry = Transfer->TransferLink.Flink;
1530 }
1531 }
1532
1534}
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
Definition: usb.h:529
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:267
#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 1620 of file endpoint.c.

1621{
1622 PDEVICE_OBJECT FdoDevice;
1623 ULONG PrevState;
1624 ULONG EndpointState;
1625 BOOLEAN IsPaused = FALSE;
1626
1627 DPRINT_CORE("USBPORT_DmaEndpointWorker ... \n");
1628
1629 FdoDevice = Endpoint->FdoDevice;
1630
1631 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1632
1633 PrevState = USBPORT_GetEndpointState(Endpoint);
1634
1635 if (PrevState == USBPORT_ENDPOINT_PAUSED)
1636 {
1637 EndpointState = USBPORT_DmaEndpointPaused(FdoDevice, Endpoint);
1638 }
1639 else if (PrevState == USBPORT_ENDPOINT_ACTIVE)
1640 {
1641 EndpointState = USBPORT_DmaEndpointActive(FdoDevice, Endpoint);
1642 }
1643 else
1644 {
1645#ifndef NDEBUG_USBPORT_CORE
1646 DPRINT1("USBPORT_DmaEndpointWorker: DbgBreakPoint. EndpointState - %x\n",
1647 EndpointState);
1648 DbgBreakPoint();
1649#endif
1650 EndpointState = USBPORT_ENDPOINT_UNKNOWN;
1651 }
1652
1653 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1654
1655 USBPORT_FlushCancelList(Endpoint);
1656
1657 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1658
1659 if (EndpointState == PrevState)
1660 {
1661 if (EndpointState == USBPORT_ENDPOINT_PAUSED)
1662 {
1663 IsPaused = TRUE;
1664 }
1665 }
1666 else
1667 {
1668 USBPORT_SetEndpointState(Endpoint, EndpointState);
1669 }
1670
1671 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1672
1673 if (IsPaused)
1674 {
1676 Endpoint,
1678 }
1679
1680 DPRINT_CORE("USBPORT_DmaEndpointWorker exit \n");
1681}
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:1442
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1346
ULONG NTAPI USBPORT_DmaEndpointActive(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1538
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define USBPORT_ENDPOINT_UNKNOWN
Definition: usbmport.h:13
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37

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 1685 of file endpoint.c.

1687{
1688 PDEVICE_OBJECT FdoDevice;
1691 ULONG EndpointState;
1692
1693 DPRINT_CORE("USBPORT_EndpointWorker: Endpoint - %p, LockNotChecked - %x\n",
1694 Endpoint,
1695 LockNotChecked);
1696
1697 FdoDevice = Endpoint->FdoDevice;
1698 FdoExtension = FdoDevice->DeviceExtension;
1699 Packet = &FdoExtension->MiniPortInterface->Packet;
1700
1701 if (LockNotChecked == FALSE)
1702 {
1703 if (InterlockedIncrement(&Endpoint->LockCounter))
1704 {
1705 InterlockedDecrement(&Endpoint->LockCounter);
1706 DPRINT_CORE("USBPORT_EndpointWorker: LockCounter > 0\n");
1707 return TRUE;
1708 }
1709 }
1710
1712
1713 KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
1714
1716 {
1717 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1718 InterlockedDecrement(&Endpoint->LockCounter);
1719 DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_CLOSED. return FALSE\n");
1720 return FALSE;
1721 }
1722
1723 if ((Endpoint->Flags & (ENDPOINT_FLAG_ROOTHUB_EP0 | ENDPOINT_FLAG_NUKE)) == 0)
1724 {
1725 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1726 Packet->PollEndpoint(FdoExtension->MiniPortExt, Endpoint + 1);
1727 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1728 }
1729
1730 EndpointState = USBPORT_GetEndpointState(Endpoint);
1731
1732 if (EndpointState == USBPORT_ENDPOINT_REMOVE)
1733 {
1734 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1735 Endpoint->StateLast = USBPORT_ENDPOINT_CLOSED;
1736 Endpoint->StateNext = USBPORT_ENDPOINT_CLOSED;
1737 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1738
1739 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1740
1741 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1742
1743 ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
1744 &Endpoint->CloseLink,
1745 &FdoExtension->EndpointClosedSpinLock);
1746
1747 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1748
1749 InterlockedDecrement(&Endpoint->LockCounter);
1750 DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_REMOVE. return FALSE\n");
1751 return FALSE;
1752 }
1753
1754 if (!IsListEmpty(&Endpoint->PendingTransferList) ||
1755 !IsListEmpty(&Endpoint->TransferList) ||
1756 !IsListEmpty(&Endpoint->CancelList))
1757 {
1758 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1759
1760 EndpointState = USBPORT_GetEndpointState(Endpoint);
1761
1762 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1763 if (EndpointState == Endpoint->StateNext)
1764 {
1765 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1766
1767 if (Endpoint->EndpointWorker)
1768 {
1769 USBPORT_DmaEndpointWorker(Endpoint);
1770 }
1771 else
1772 {
1774 }
1775
1776 USBPORT_FlushAbortList(Endpoint);
1777
1778 InterlockedDecrement(&Endpoint->LockCounter);
1779 DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1780 return FALSE;
1781 }
1782
1783 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1784 InterlockedDecrement(&Endpoint->LockCounter);
1785
1786 DPRINT_CORE("USBPORT_EndpointWorker: return TRUE\n");
1787 return TRUE;
1788 }
1789
1790 KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1791
1792 USBPORT_FlushAbortList(Endpoint);
1793
1794 InterlockedDecrement(&Endpoint->LockCounter);
1795 DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1796 return FALSE;
1797}
VOID NTAPI USBPORT_FlushAbortList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:605
VOID NTAPI USBPORT_DmaEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1620
#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 1310 of file endpoint.c.

1311{
1313 KIRQL OldIrql;
1314 PLIST_ENTRY ClosedList;
1315 PUSBPORT_ENDPOINT Endpoint;
1316
1317 DPRINT_CORE("USBPORT_FlushClosedEndpointList: ... \n");
1318
1319 FdoExtension = FdoDevice->DeviceExtension;
1320
1321 KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1322 ClosedList = &FdoExtension->EndpointClosedList;
1323
1324 while (!IsListEmpty(ClosedList))
1325 {
1326 Endpoint = CONTAINING_RECORD(ClosedList->Flink,
1328 CloseLink);
1329
1330 RemoveHeadList(ClosedList);
1331 Endpoint->CloseLink.Flink = NULL;
1332 Endpoint->CloseLink.Blink = NULL;
1333
1334 KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1335
1336 USBPORT_DeleteEndpoint(FdoDevice, Endpoint);
1337
1338 KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1339 }
1340
1341 KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1342}
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
LIST_ENTRY CloseLink
Definition: usbport.h:234

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 ||
194 (Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0))
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 1346 of file endpoint.c.

1349{
1353 PLIST_ENTRY WorkerLink;
1355 KIRQL OldIrql;
1356 BOOLEAN IsAddEntry = FALSE;
1357
1358 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: Endpoint - %p, Type - %x\n",
1359 Endpoint,
1360 Type);
1361
1362 FdoExtension = FdoDevice->DeviceExtension;
1363 Packet = &FdoExtension->MiniPortInterface->Packet;
1364
1365 if (Endpoint)
1366 {
1367 WorkerLink = &Endpoint->WorkerLink;
1368 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1369 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: KeAcquireSpinLock \n");
1370
1371 if ((!WorkerLink->Flink || !WorkerLink->Blink) &&
1372 !(Endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1374 {
1375 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1376 InsertTailList(&FdoExtension->WorkerList, WorkerLink);
1377 IsAddEntry = TRUE;
1378 }
1379
1380 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1381
1382 if (Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0)
1384 }
1385 else
1386 {
1387 KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1388
1389 for (Entry = FdoExtension->EndpointList.Flink;
1390 Entry && Entry != &FdoExtension->EndpointList;
1391 Entry = Entry->Flink)
1392 {
1395 EndpointLink);
1396
1397 if (!endpoint->WorkerLink.Flink || !endpoint->WorkerLink.Blink)
1398 {
1399 if (!(endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1400 !(endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0) &&
1402 {
1403 DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1404 InsertTailList(&FdoExtension->WorkerList, &endpoint->WorkerLink);
1405 IsAddEntry = TRUE;
1406 }
1407 }
1408 }
1409
1410 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1411 }
1412
1414 {
1416 }
1417 else if (IsAddEntry == FALSE && Type == INVALIDATE_ENDPOINT_INT_NEXT_SOF)
1418 {
1420 }
1421
1422 switch (Type)
1423 {
1425 USBPORT_SignalWorkerThread(FdoDevice);
1426 break;
1427
1429 KeInsertQueueDpc(&FdoExtension->WorkerRequestDpc, NULL, NULL);
1430 break;
1431
1433 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1434 Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
1435 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1436 break;
1437 }
1438}
Type
Definition: Type.h:7
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
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:30

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;
304 PUSBPORT_ENDPOINT Endpoint;
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))
322 Endpoint->Flags |= ENDPOINT_FLAG_NUKE;
323
324 EndpointList = Endpoint->EndpointLink.Flink;
325 }
326
327 KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
328}
LIST_ENTRY EndpointLink
Definition: usbport.h:232

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;
798 PUSBPORT_ENDPOINT Endpoint;
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;
810 USHORT MaxPacketSize;
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
842 Endpoint = ExAllocatePoolWithTag(NonPagedPool, EndpointSize, USB_PORT_TAG);
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 {
868 Endpoint->TtEndpoint = (PUSB2_TT_ENDPOINT)((ULONG_PTR)Endpoint +
869 sizeof(USBPORT_ENDPOINT) +
870 Packet->MiniPortEndpointSize);
871 }
872 else
873 {
874 Endpoint->TtEndpoint = NULL;
875 }
876
879
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 {
997 Endpoint->Flags |= ENDPOINT_FLAG_ROOTHUB_EP0;
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
1031 Endpoint->Flags |= ENDPOINT_FLAG_ROOTHUB_EP0;
1032
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
1086 Endpoint->Flags |= ENDPOINT_FLAG_DMA_TYPE;
1088
1089 if (MpStatus == 0)
1090 {
1091 ULONG State;
1092
1094 &Endpoint->EndpointOldIrql);
1095
1098
1100
1102 Endpoint->EndpointOldIrql);
1103
1104 /* Wait maximum 1 second for the endpoint to be active */
1105 for (RetryCount = 0; RetryCount < 1000; RetryCount++)
1106 {
1108 &Endpoint->EndpointOldIrql);
1109
1110 State = USBPORT_GetEndpointState(Endpoint);
1111
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 if (IsAllocatedBandwidth)
1167 {
1168 if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1169 {
1170 USBPORT_FreeBandwidthUSB2(FdoDevice, Endpoint);
1171 }
1172 else
1173 {
1174 USBPORT_FreeBandwidth(FdoDevice, Endpoint);
1175 }
1176 }
1177
1178 if (Endpoint->TtExtension)
1179 {
1180 KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
1181 RemoveEntryList(&Endpoint->TtLink);
1182 KeReleaseSpinLock(&FdoExtension->TtSpinLock, OldIrql);
1183 }
1184
1186 }
1187
1188 DPRINT1("USBPORT_OpenPipe: Status - %lx\n", Status);
1189 return Status;
1190}
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:25
if(dx< 0)
Definition: linetemp.h:194
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT DeviceAddress
Definition: usbport.h:555
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
ULONG EndpointWorker
Definition: usbport.h:212
PUSB2_TT_ENDPOINT TtEndpoint
Definition: usbport.h:210
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:207
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:195
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
#define USBD_STATUS_TIMEOUT
Definition: usb.h:209
LONG USBD_STATUS
Definition: usb.h:165
#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 1194 of file endpoint.c.

1196{
1198 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
1199 USBPORT_ENDPOINT_REQUIREMENTS EndpointRequirements = {0};
1201 KIRQL MiniportOldIrql;
1203
1204 DPRINT1("USBPORT_ReopenPipe ... \n");
1205
1206 FdoExtension = FdoDevice->DeviceExtension;
1207 Packet = &FdoExtension->MiniPortInterface->Packet;
1208
1209 while (TRUE)
1210 {
1211 if (!InterlockedIncrement(&Endpoint->LockCounter))
1212 break;
1213
1214 InterlockedDecrement(&Endpoint->LockCounter);
1215 USBPORT_Wait(FdoDevice, 1);
1216 }
1217
1218 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1219 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1220
1221 Packet->SetEndpointState(FdoExtension->MiniPortExt,
1222 Endpoint + 1,
1224
1225 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1226 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1227
1228 USBPORT_Wait(FdoDevice, 2);
1229
1230 MiniportCloseEndpoint(FdoDevice, Endpoint);
1231
1232 RtlZeroMemory(Endpoint + 1,
1233 Packet->MiniPortEndpointSize);
1234
1235 if (Endpoint->HeaderBuffer)
1236 {
1237 USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
1238 Endpoint->HeaderBuffer = NULL;
1239 }
1240
1241 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &MiniportOldIrql);
1242
1243 Packet->QueryEndpointRequirements(FdoExtension->MiniPortExt,
1244 &Endpoint->EndpointProperties,
1245 &EndpointRequirements);
1246
1247 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, MiniportOldIrql);
1248
1249 if (EndpointRequirements.HeaderBufferSize)
1250 {
1251 HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
1252 EndpointRequirements.HeaderBufferSize);
1253 }
1254 else
1255 {
1256 HeaderBuffer = NULL;
1257 }
1258
1259 if (HeaderBuffer || EndpointRequirements.HeaderBufferSize == 0)
1260 {
1261 Endpoint->HeaderBuffer = HeaderBuffer;
1263 }
1264 else
1265 {
1266 Endpoint->HeaderBuffer = 0;
1268 }
1269
1270 if (Endpoint->HeaderBuffer && HeaderBuffer)
1271 {
1272 Endpoint->EndpointProperties.BufferVA = HeaderBuffer->VirtualAddress;
1273 Endpoint->EndpointProperties.BufferPA = HeaderBuffer->PhysicalAddress;
1274 Endpoint->EndpointProperties.BufferLength = HeaderBuffer->BufferLength;
1275 }
1276
1277 if (NT_SUCCESS(Status))
1278 {
1279 MiniportOpenEndpoint(FdoDevice, Endpoint);
1280
1281 KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1282 KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1283
1284 if (Endpoint->StateLast == USBPORT_ENDPOINT_ACTIVE)
1285 {
1286 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1287 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1288
1289 Packet->SetEndpointState(FdoExtension->MiniPortExt,
1290 Endpoint + 1,
1292
1293 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1294 }
1295 else
1296 {
1297 KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1298 }
1299
1300 KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1301 }
1302
1303 InterlockedDecrement(&Endpoint->LockCounter);
1304
1305 return Status;
1306}

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().