ReactOS  0.4.14-dev-358-gbef841c
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 549 of file endpoint.c.

551 {
554  BOOLEAN IsDoDisablePeriodic;
555  ULONG TransferType;
556  KIRQL OldIrql;
557 
558  DPRINT("MiniportCloseEndpoint: Endpoint - %p\n", Endpoint);
559 
560  FdoExtension = FdoDevice->DeviceExtension;
561  Packet = &FdoExtension->MiniPortInterface->Packet;
562 
563  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
564 
565  if (Endpoint->Flags & ENDPOINT_FLAG_OPENED)
566  {
567  TransferType = Endpoint->EndpointProperties.TransferType;
568 
569  if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT ||
570  TransferType == USBPORT_TRANSFER_TYPE_ISOCHRONOUS)
571  {
572  --FdoExtension->PeriodicEndpoints;
573  }
574 
575  IsDoDisablePeriodic = FdoExtension->PeriodicEndpoints == 0;
576 
577  Packet->CloseEndpoint(FdoExtension->MiniPortExt,
578  Endpoint + 1,
579  IsDoDisablePeriodic);
580 
581  Endpoint->Flags &= ~ENDPOINT_FLAG_OPENED;
582  Endpoint->Flags |= ENDPOINT_FLAG_CLOSED;
583  }
584 
585  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
586 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define ENDPOINT_FLAG_OPENED
Definition: usbport.h:116
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define ENDPOINT_FLAG_CLOSED
Definition: usbport.h:117

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

◆ MiniportOpenEndpoint()

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

Definition at line 722 of file endpoint.c.

724 {
727  KIRQL OldIrql;
728  ULONG TransferType;
729  MPSTATUS MpStatus;
730 
731  DPRINT("MiniportOpenEndpoint: Endpoint - %p\n", Endpoint);
732 
733  FdoExtension = FdoDevice->DeviceExtension;
734  Packet = &FdoExtension->MiniPortInterface->Packet;
735 
736  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
737 
738  Endpoint->Flags &= ~ENDPOINT_FLAG_CLOSED;
739 
740  MpStatus = Packet->OpenEndpoint(FdoExtension->MiniPortExt,
741  &Endpoint->EndpointProperties,
742  Endpoint + 1);
743 
744  if (!MpStatus)
745  {
746  TransferType = Endpoint->EndpointProperties.TransferType;
747 
748  if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT ||
749  TransferType == USBPORT_TRANSFER_TYPE_ISOCHRONOUS)
750  {
751  ++FdoExtension->PeriodicEndpoints;
752  }
753 
754  Endpoint->Flags |= ENDPOINT_FLAG_OPENED;
755  }
756 
757  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
758  return MpStatus;
759 }
ULONG MPSTATUS
Definition: usbmport.h:131
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define ENDPOINT_FLAG_OPENED
Definition: usbport.h:116
UCHAR KIRQL
Definition: env_spec_w32.h:591
void DPRINT(...)
Definition: polytest.cpp:61
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define ENDPOINT_FLAG_CLOSED
Definition: usbport.h:117

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

446 {
447  DPRINT("USBPORT_AddPipeHandle: DeviceHandle - %p, PipeHandle - %p\n",
448  DeviceHandle,
449  PipeHandle);
450 
451  InsertTailList(&DeviceHandle->PipeHandleList, &PipeHandle->PipeLink);
452 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define InsertTailList(ListHead, Entry)
void DPRINT(...)
Definition: polytest.cpp:61
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21

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;
75  ULONG Offset;
76  LONG ScheduleOffset = -1;
77  ULONG Period;
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 USBPORT_TRANSFER_TYPE_BULK
Definition: usbmport.h:9
#define TRUE
Definition: types.h:120
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
long LONG
Definition: pedump.c:60
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
#define USB2_FRAMES
Definition: usbport.h:451
unsigned int ULONG
Definition: retypes.h:1

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 
36  Overhead = USB2_FS_INTERRUPT_OVERHEAD;
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 }
#define USB2_FS_INTERRUPT_OVERHEAD
Definition: usbport.h:466
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
#define USB2_FS_ISOCHRONOUS_OVERHEAD
Definition: usbport.h:469
void DPRINT(...)
Definition: polytest.cpp:61
#define USB2_BIT_STUFFING_OVERHEAD
Definition: usbport.h:482
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
unsigned int ULONG
Definition: retypes.h:1

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

593 {
596  PUSBPORT_ENDPOINT Endpoint;
598  PUSB2_TT_EXTENSION TtExtension;
599  ULONG ix;
600  BOOLEAN IsReady;
601  KIRQL OldIrql;
602 
603  DPRINT1("USBPORT_ClosePipe \n");
604 
605  FdoExtension = FdoDevice->DeviceExtension;
606 
607  if (PipeHandle->Flags & PIPE_HANDLE_FLAG_CLOSED)
608  return;
609 
611 
613 
615  {
617  return;
618  }
619 
620  Endpoint = PipeHandle->Endpoint;
621 
622  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
623 
624  if ((Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0) &&
626  {
627  PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
628  PdoExtension->Endpoint = NULL;
629  }
630 
631  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
632 
633  while (TRUE)
634  {
635  IsReady = TRUE;
636 
638  &Endpoint->EndpointOldIrql);
639 
640  if (!IsListEmpty(&Endpoint->PendingTransferList))
641  IsReady = FALSE;
642 
643  if (!IsListEmpty(&Endpoint->TransferList))
644  IsReady = FALSE;
645 
646  if (!IsListEmpty(&Endpoint->CancelList))
647  IsReady = FALSE;
648 
649  if (!IsListEmpty(&Endpoint->AbortList))
650  IsReady = FALSE;
651 
653  if (Endpoint->StateLast != Endpoint->StateNext)
654  IsReady = FALSE;
656 
658  Endpoint->EndpointOldIrql);
659 
660  if (InterlockedIncrement(&Endpoint->LockCounter))
661  IsReady = FALSE;
662  InterlockedDecrement(&Endpoint->LockCounter);
663 
664  if (IsReady == TRUE)
665  break;
666 
667  USBPORT_Wait(FdoDevice, 1);
668  }
669 
670  Endpoint->DeviceHandle = NULL;
671  Packet = &FdoExtension->MiniPortInterface->Packet;
672 
673  if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
674  {
675  USBPORT_FreeBandwidthUSB2(FdoDevice, Endpoint);
676 
677  KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
678 
679  TtExtension = Endpoint->TtExtension;
680  DPRINT1("USBPORT_ClosePipe: TtExtension - %p\n", TtExtension);
681 
682  if (TtExtension)
683  {
684  RemoveEntryList(&Endpoint->TtLink);
685 
686  Endpoint->TtLink.Flink = NULL;
687  Endpoint->TtLink.Blink = NULL;
688 
689  if (TtExtension->Flags & USB2_TT_EXTENSION_FLAG_DELETED)
690  {
691  if (IsListEmpty(&TtExtension->EndpointList))
692  {
693  USBPORT_UpdateAllocatedBwTt(TtExtension);
694 
695  for (ix = 0; ix < USB2_FRAMES; ix++)
696  {
697  FdoExtension->Bandwidth[ix] += TtExtension->MaxBandwidth;
698  }
699 
700  DPRINT1("USBPORT_ClosePipe: ExFreePoolWithTag TtExtension - %p\n", TtExtension);
701  ExFreePoolWithTag(TtExtension, USB_PORT_TAG);
702  }
703  }
704  }
705 
706  KeReleaseSpinLock(&FdoExtension->TtSpinLock, OldIrql);
707  }
708  else
709  {
710  USBPORT_FreeBandwidth(FdoDevice, Endpoint);
711  }
712 
713  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
715  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
716 
717  USBPORT_SignalWorkerThread(FdoDevice);
718 }
#define PIPE_HANDLE_FLAG_CLOSED
Definition: usbport.h:125
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
VOID NTAPI USBPORT_FreeBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:171
VOID NTAPI USBPORT_FreeBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: usb2.c:2040
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:126
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
ULONG MaxBandwidth
Definition: usbport.h:552
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
LIST_ENTRY AbortList
Definition: usbport.h:229
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:224
PUSB2_TT_EXTENSION TtExtension
Definition: usbport.h:208
#define USB2_TT_EXTENSION_FLAG_DELETED
Definition: usbport.h:545
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define USB_PORT_TAG
Definition: usbport.h:44
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY EndpointList
Definition: usbport.h:556
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
LIST_ENTRY PendingTransferList
Definition: usbport.h:226
LIST_ENTRY TransferList
Definition: usbport.h:227
KIRQL EndpointOldIrql
Definition: usbport.h:215
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI USBPORT_RemovePipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:456
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PUSBPORT_DEVICE_HANDLE DeviceHandle
Definition: usbport.h:207
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
#define InterlockedIncrement
Definition: armddk.h:53
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
VOID NTAPI USBPORT_UpdateAllocatedBwTt(IN PUSB2_TT_EXTENSION TtExtension)
Definition: usb2.c:1768
#define DPRINT1
Definition: precomp.h:8
#define USB2_FRAMES
Definition: usbport.h:451
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
LIST_ENTRY TtLink
Definition: usbport.h:238
LIST_ENTRY CancelList
Definition: usbport.h:228
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214

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

500 {
502  BOOLEAN Result;
503  KIRQL OldIrql;
504 
505  DPRINT1("USBPORT_DeleteEndpoint: Endpoint - %p\n", Endpoint);
506 
507  FdoExtension = FdoDevice->DeviceExtension;
508 
509  if ((Endpoint->WorkerLink.Flink && Endpoint->WorkerLink.Blink) ||
510  Endpoint->LockCounter != -1)
511  {
512  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
513 
514  ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
515  &Endpoint->CloseLink,
516  &FdoExtension->EndpointClosedSpinLock);
517 
518  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
519 
520  Result = FALSE;
521  }
522  else
523  {
524  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
525 
526  RemoveEntryList(&Endpoint->EndpointLink);
527  Endpoint->EndpointLink.Flink = NULL;
528  Endpoint->EndpointLink.Blink = NULL;
529 
530  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
531 
532  MiniportCloseEndpoint(FdoDevice, Endpoint);
533 
534  if (Endpoint->HeaderBuffer)
535  {
536  USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
537  }
538 
539  ExFreePoolWithTag(Endpoint, USB_PORT_TAG);
540 
541  Result = TRUE;
542  }
543 
544  return Result;
545 }
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1748
#define TRUE
Definition: types.h:120
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define USB_PORT_TAG
Definition: usbport.h:44
UCHAR KIRQL
Definition: env_spec_w32.h:591
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
VOID NTAPI MiniportCloseEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:549
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by USBPORT_FlushClosedEndpointList().

◆ USBPORT_DmaEndpointActive()

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

Definition at line 1509 of file endpoint.c.

1511 {
1515  PUSBPORT_TRANSFER Transfer;
1516  LARGE_INTEGER TimeOut;
1517  MPSTATUS MpStatus;
1518  KIRQL OldIrql;
1519 
1520  DPRINT_CORE("USBPORT_DmaEndpointActive \n");
1521 
1522  FdoExtension = FdoDevice->DeviceExtension;
1523 
1524  Entry = Endpoint->TransferList.Flink;
1525 
1526  while (Entry && Entry != &Endpoint->TransferList)
1527  {
1528  Transfer = CONTAINING_RECORD(Entry,
1530  TransferLink);
1531 
1532  if (!(Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1533  !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1534  {
1535  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1536 
1537  Packet = &FdoExtension->MiniPortInterface->Packet;
1538 
1539  if (Transfer->Flags & TRANSFER_FLAG_ISO)
1540  {
1541  DPRINT1("USBPORT_DmaEndpointActive: FIXME call SubmitIsoTransfer\n");
1542 
1543  MpStatus = Packet->SubmitIsoTransfer(FdoExtension->MiniPortExt,
1544  Endpoint + 1,
1545  &Transfer->TransferParameters,
1546  Transfer->MiniportTransfer,
1547  NULL);//&Transfer->IsoTransferParameters);
1548  }
1549  else
1550  {
1551  MpStatus = Packet->SubmitTransfer(FdoExtension->MiniPortExt,
1552  Endpoint + 1,
1553  &Transfer->TransferParameters,
1554  Transfer->MiniportTransfer,
1555  &Transfer->SgList);
1556  }
1557 
1558  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1559 
1560  if (MpStatus)
1561  {
1562  if ((MpStatus != MP_STATUS_FAILURE) && Transfer->Flags & TRANSFER_FLAG_ISO)
1563  {
1564  DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_ErrorCompleteIsoTransfer\n");
1565  ASSERT(FALSE); //USBPORT_ErrorCompleteIsoTransfer();
1566  }
1567 
1568  return USBPORT_ENDPOINT_ACTIVE;
1569  }
1570 
1571  Transfer->Flags |= TRANSFER_FLAG_SUBMITED;
1572  KeQuerySystemTime(&Transfer->Time);
1573 
1574  TimeOut.QuadPart = 10000 * Transfer->TimeOut;
1575  Transfer->Time.QuadPart += TimeOut.QuadPart;
1576  }
1577 
1579  {
1580  return USBPORT_ENDPOINT_PAUSED;
1581  }
1582 
1583  Entry = Transfer->TransferLink.Flink;
1584  }
1585 
1586  return USBPORT_ENDPOINT_ACTIVE;
1587 }
#define TRANSFER_FLAG_CANCELED
Definition: usbport.h:129
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
ULONG MPSTATUS
Definition: usbmport.h:131
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:270
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
struct _Entry Entry
Definition: kefuncs.h:640
LARGE_INTEGER Time
Definition: usbport.h:262
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:253
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define MP_STATUS_FAILURE
Definition: usbmport.h:135
LIST_ENTRY TransferLink
Definition: usbport.h:256
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PVOID MiniportTransfer
Definition: usbport.h:249
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define TRANSFER_FLAG_ISO
Definition: usbport.h:134
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
base of all file and directory entries
Definition: entries.h:82
LONGLONG QuadPart
Definition: typedefs.h:112
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:132

Referenced by USBPORT_DmaEndpointWorker().

◆ USBPORT_DmaEndpointPaused()

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

Definition at line 1413 of file endpoint.c.

1415 {
1419  PUSBPORT_TRANSFER Transfer;
1420  PURB Urb;
1421  ULONG Frame;
1422  ULONG CurrentFrame;
1423  ULONG CompletedLen = 0;
1424  KIRQL OldIrql;
1425 
1426  DPRINT_CORE("USBPORT_DmaEndpointPaused \n");
1427 
1428  FdoExtension = FdoDevice->DeviceExtension;
1429  Packet = &FdoExtension->MiniPortInterface->Packet;
1430 
1431  Entry = Endpoint->TransferList.Flink;
1432 
1433  if (Entry == &Endpoint->TransferList)
1434  return USBPORT_ENDPOINT_ACTIVE;
1435 
1436  while (Entry && Entry != &Endpoint->TransferList)
1437  {
1438  Transfer = CONTAINING_RECORD(Entry,
1440  TransferLink);
1441 
1443  {
1444  if (Transfer->Flags & TRANSFER_FLAG_ISO &&
1445  Transfer->Flags & TRANSFER_FLAG_SUBMITED &&
1446  !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1447  {
1448  Urb = Transfer->Urb;
1449 
1450  Frame = Urb->UrbIsochronousTransfer.StartFrame +
1451  Urb->UrbIsochronousTransfer.NumberOfPackets;
1452 
1453  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1454  CurrentFrame = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
1455  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1456 
1457  if (Frame + 1 > CurrentFrame)
1458  {
1459  return USBPORT_GetEndpointState(Endpoint);
1460  }
1461  }
1462 
1463  if ((Transfer->Flags & TRANSFER_FLAG_SUBMITED) &&
1464  !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1465  {
1466  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1467 
1468  Packet->AbortTransfer(FdoExtension->MiniPortExt,
1469  Endpoint + 1,
1470  Transfer->MiniportTransfer,
1471  &CompletedLen);
1472 
1473  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1474 
1475  if (Transfer->Flags & TRANSFER_FLAG_ISO)
1476  {
1477  DPRINT1("USBPORT_DmaEndpointActive: FIXME call USBPORT_FlushIsoTransfer\n");
1478  ASSERT(FALSE); //USBPORT_FlushIsoTransfer();
1479  }
1480  else
1481  {
1482  Transfer->CompletedTransferLen = CompletedLen;
1483  }
1484  }
1485 
1486  RemoveEntryList(&Transfer->TransferLink);
1487  Entry = Transfer->TransferLink.Flink;
1488 
1489  if (Transfer->Flags & TRANSFER_FLAG_SPLITED)
1490  {
1491  USBPORT_CancelSplitTransfer(Transfer);
1492  }
1493  else
1494  {
1495  InsertTailList(&Endpoint->CancelList, &Transfer->TransferLink);
1496  }
1497  }
1498  else
1499  {
1500  Entry = Transfer->TransferLink.Flink;
1501  }
1502  }
1503 
1504  return USBPORT_ENDPOINT_ACTIVE;
1505 }
#define TRANSFER_FLAG_CANCELED
Definition: usbport.h:129
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
struct _Entry Entry
Definition: kefuncs.h:640
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY TransferLink
Definition: usbport.h:256
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PVOID MiniportTransfer
Definition: usbport.h:249
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define TRANSFER_FLAG_ISO
Definition: usbport.h:134
struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer
Definition: usb.h:544
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:136
Definition: usb.h:529
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI USBPORT_CancelSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:314
unsigned int ULONG
Definition: retypes.h:1
ULONG CompletedTransferLen
Definition: usbport.h:258
base of all file and directory entries
Definition: entries.h:82
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:132

Referenced by USBPORT_DmaEndpointWorker().

◆ USBPORT_DmaEndpointWorker()

VOID NTAPI USBPORT_DmaEndpointWorker ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 1591 of file endpoint.c.

1592 {
1593  PDEVICE_OBJECT FdoDevice;
1594  ULONG PrevState;
1595  ULONG EndpointState;
1596  BOOLEAN IsPaused = FALSE;
1597 
1598  DPRINT_CORE("USBPORT_DmaEndpointWorker ... \n");
1599 
1600  FdoDevice = Endpoint->FdoDevice;
1601 
1602  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1603 
1604  PrevState = USBPORT_GetEndpointState(Endpoint);
1605 
1606  if (PrevState == USBPORT_ENDPOINT_PAUSED)
1607  {
1608  EndpointState = USBPORT_DmaEndpointPaused(FdoDevice, Endpoint);
1609  }
1610  else if (PrevState == USBPORT_ENDPOINT_ACTIVE)
1611  {
1612  EndpointState = USBPORT_DmaEndpointActive(FdoDevice, Endpoint);
1613  }
1614  else
1615  {
1616 #ifndef NDEBUG_USBPORT_CORE
1617  DPRINT1("USBPORT_DmaEndpointWorker: DbgBreakPoint. EndpointState - %x\n",
1618  EndpointState);
1619  DbgBreakPoint();
1620 #endif
1621  EndpointState = USBPORT_ENDPOINT_UNKNOWN;
1622  }
1623 
1624  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1625 
1626  USBPORT_FlushCancelList(Endpoint);
1627 
1628  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1629 
1630  if (EndpointState == PrevState)
1631  {
1632  if (EndpointState == USBPORT_ENDPOINT_PAUSED)
1633  {
1634  IsPaused = TRUE;
1635  }
1636  }
1637  else
1638  {
1639  USBPORT_SetEndpointState(Endpoint, EndpointState);
1640  }
1641 
1642  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1643 
1644  if (IsPaused)
1645  {
1647  Endpoint,
1649  }
1650 
1651  DPRINT_CORE("USBPORT_DmaEndpointWorker exit \n");
1652 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
void DbgBreakPoint()
Definition: mach.c:553
unsigned char BOOLEAN
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ULONG NTAPI USBPORT_DmaEndpointActive(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1509
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define USBPORT_ENDPOINT_UNKNOWN
Definition: usbmport.h:13
ULONG NTAPI USBPORT_DmaEndpointPaused(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1413
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
VOID NTAPI USBPORT_FlushCancelList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:714

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;
260  BOOLEAN Result = FALSE;
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 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
unsigned char BOOLEAN
_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:426
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY TransferLink
Definition: usbport.h:256
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: typedefs.h:117
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
base of all file and directory entries
Definition: entries.h:82
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:132

Referenced by USBPORT_DeviceHasTransfers(), and USBPORT_FlushDoneTransfers().

◆ USBPORT_EndpointWorker()

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

Definition at line 1656 of file endpoint.c.

1658 {
1659  PDEVICE_OBJECT FdoDevice;
1662  ULONG EndpointState;
1663 
1664  DPRINT_CORE("USBPORT_EndpointWorker: Endpoint - %p, LockNotChecked - %x\n",
1665  Endpoint,
1666  LockNotChecked);
1667 
1668  FdoDevice = Endpoint->FdoDevice;
1669  FdoExtension = FdoDevice->DeviceExtension;
1670  Packet = &FdoExtension->MiniPortInterface->Packet;
1671 
1672  if (LockNotChecked == FALSE)
1673  {
1674  if (InterlockedIncrement(&Endpoint->LockCounter))
1675  {
1676  InterlockedDecrement(&Endpoint->LockCounter);
1677  DPRINT_CORE("USBPORT_EndpointWorker: LockCounter > 0\n");
1678  return TRUE;
1679  }
1680  }
1681 
1683 
1684  KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
1685 
1687  {
1688  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1689  InterlockedDecrement(&Endpoint->LockCounter);
1690  DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_CLOSED. return FALSE\n");
1691  return FALSE;
1692  }
1693 
1694  if ((Endpoint->Flags & (ENDPOINT_FLAG_ROOTHUB_EP0 | ENDPOINT_FLAG_NUKE)) == 0)
1695  {
1696  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1697  Packet->PollEndpoint(FdoExtension->MiniPortExt, Endpoint + 1);
1698  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1699  }
1700 
1701  EndpointState = USBPORT_GetEndpointState(Endpoint);
1702 
1703  if (EndpointState == USBPORT_ENDPOINT_REMOVE)
1704  {
1705  KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1706  Endpoint->StateLast = USBPORT_ENDPOINT_CLOSED;
1707  Endpoint->StateNext = USBPORT_ENDPOINT_CLOSED;
1708  KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1709 
1710  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1711 
1712  KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1713 
1714  ExInterlockedInsertTailList(&FdoExtension->EndpointClosedList,
1715  &Endpoint->CloseLink,
1716  &FdoExtension->EndpointClosedSpinLock);
1717 
1718  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1719 
1720  InterlockedDecrement(&Endpoint->LockCounter);
1721  DPRINT_CORE("USBPORT_EndpointWorker: State == USBPORT_ENDPOINT_REMOVE. return FALSE\n");
1722  return FALSE;
1723  }
1724 
1725  if (!IsListEmpty(&Endpoint->PendingTransferList) ||
1726  !IsListEmpty(&Endpoint->TransferList) ||
1727  !IsListEmpty(&Endpoint->CancelList))
1728  {
1729  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1730 
1731  EndpointState = USBPORT_GetEndpointState(Endpoint);
1732 
1733  KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1734  if (EndpointState == Endpoint->StateNext)
1735  {
1736  KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1737 
1738  if (Endpoint->EndpointWorker)
1739  {
1740  USBPORT_DmaEndpointWorker(Endpoint);
1741  }
1742  else
1743  {
1745  }
1746 
1747  USBPORT_FlushAbortList(Endpoint);
1748 
1749  InterlockedDecrement(&Endpoint->LockCounter);
1750  DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1751  return FALSE;
1752  }
1753 
1754  KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1755  InterlockedDecrement(&Endpoint->LockCounter);
1756 
1757  DPRINT_CORE("USBPORT_EndpointWorker: return TRUE\n");
1758  return TRUE;
1759  }
1760 
1761  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
1762 
1763  USBPORT_FlushAbortList(Endpoint);
1764 
1765  InterlockedDecrement(&Endpoint->LockCounter);
1766  DPRINT_CORE("USBPORT_EndpointWorker: return FALSE\n");
1767  return FALSE;
1768 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_DmaEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:1591
#define TRUE
Definition: types.h:120
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI USBPORT_RootHubEndpointWorker(IN PUSBPORT_ENDPOINT Endpoint)
Definition: roothub.c:664
VOID NTAPI USBPORT_FlushAbortList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:605
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 KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define InterlockedDecrement
Definition: armddk.h:52
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1
#define USBPORT_ENDPOINT_CLOSED
Definition: usbmport.h:17

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

◆ USBPORT_FlushClosedEndpointList()

VOID NTAPI USBPORT_FlushClosedEndpointList ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1281 of file endpoint.c.

1282 {
1284  KIRQL OldIrql;
1285  PLIST_ENTRY ClosedList;
1286  PUSBPORT_ENDPOINT Endpoint;
1287 
1288  DPRINT_CORE("USBPORT_FlushClosedEndpointList: ... \n");
1289 
1290  FdoExtension = FdoDevice->DeviceExtension;
1291 
1292  KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1293  ClosedList = &FdoExtension->EndpointClosedList;
1294 
1295  while (!IsListEmpty(ClosedList))
1296  {
1297  Endpoint = CONTAINING_RECORD(ClosedList->Flink,
1299  CloseLink);
1300 
1301  RemoveHeadList(ClosedList);
1302  Endpoint->CloseLink.Flink = NULL;
1303  Endpoint->CloseLink.Blink = NULL;
1304 
1305  KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1306 
1307  USBPORT_DeleteEndpoint(FdoDevice, Endpoint);
1308 
1309  KeAcquireSpinLock(&FdoExtension->EndpointClosedSpinLock, &OldIrql);
1310  }
1311 
1312  KeReleaseSpinLock(&FdoExtension->EndpointClosedSpinLock, OldIrql);
1313 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
BOOLEAN NTAPI USBPORT_DeleteEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:498
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
LIST_ENTRY CloseLink
Definition: usbport.h:233
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

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;
177  ULONG Offset;
178  ULONG EndpointBandwidth;
179  ULONG Period;
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 }
#define USBPORT_TRANSFER_TYPE_BULK
Definition: usbmport.h:9
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
#define DPRINT1
Definition: precomp.h:8
#define USB2_FRAMES
Definition: usbport.h:451
unsigned int ULONG
Definition: retypes.h:1

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 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define USBPORT_ENDPOINT_UNKNOWN
Definition: usbmport.h:13
enum State_ State
Definition: pofuncs.h:54
unsigned int ULONG
Definition: retypes.h:1

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

1320 {
1324  PLIST_ENTRY WorkerLink;
1326  KIRQL OldIrql;
1327  BOOLEAN IsAddEntry = FALSE;
1328 
1329  DPRINT_CORE("USBPORT_InvalidateEndpointHandler: Endpoint - %p, Type - %x\n",
1330  Endpoint,
1331  Type);
1332 
1333  FdoExtension = FdoDevice->DeviceExtension;
1334  Packet = &FdoExtension->MiniPortInterface->Packet;
1335 
1336  if (Endpoint)
1337  {
1338  WorkerLink = &Endpoint->WorkerLink;
1339  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1340  DPRINT_CORE("USBPORT_InvalidateEndpointHandler: KeAcquireSpinLock \n");
1341 
1342  if ((!WorkerLink->Flink || !WorkerLink->Blink) &&
1343  !(Endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1345  {
1346  DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1347  InsertTailList(&FdoExtension->WorkerList, WorkerLink);
1348  IsAddEntry = TRUE;
1349  }
1350 
1351  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1352 
1353  if (Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0)
1355  }
1356  else
1357  {
1358  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1359 
1360  for (Entry = FdoExtension->EndpointList.Flink;
1361  Entry && Entry != &FdoExtension->EndpointList;
1362  Entry = Entry->Flink)
1363  {
1366  EndpointLink);
1367 
1368  if (!endpoint->WorkerLink.Flink || !endpoint->WorkerLink.Blink)
1369  {
1370  if (!(endpoint->Flags & ENDPOINT_FLAG_IDLE) &&
1371  !(endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0) &&
1373  {
1374  DPRINT_CORE("USBPORT_InvalidateEndpointHandler: InsertTailList \n");
1375  InsertTailList(&FdoExtension->WorkerList, &endpoint->WorkerLink);
1376  IsAddEntry = TRUE;
1377  }
1378  }
1379  }
1380 
1381  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1382  }
1383 
1385  {
1387  }
1388  else if (IsAddEntry == FALSE && Type == INVALIDATE_ENDPOINT_INT_NEXT_SOF)
1389  {
1391  }
1392 
1393  switch (Type)
1394  {
1396  USBPORT_SignalWorkerThread(FdoDevice);
1397  break;
1398 
1400  KeInsertQueueDpc(&FdoExtension->WorkerRequestDpc, NULL, NULL);
1401  break;
1402 
1404  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1405  Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
1406  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1407  break;
1408  }
1409 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
struct _Entry Entry
Definition: kefuncs.h:640
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
#define ENDPOINT_FLAG_IDLE
Definition: usbport.h:115
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define INVALIDATE_ENDPOINT_INT_NEXT_SOF
Definition: usbport.h:39
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
struct endpoint endpoint
Definition: nis.h:15
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:70
Definition: nis.h:10
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38
base of all file and directory entries
Definition: entries.h:82
#define USBPORT_ENDPOINT_CLOSED
Definition: usbmport.h:17

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 {
237  UCHAR interval;
238 
239  DPRINT("USBPORT_NormalizeHsInterval: Interval - %x\n", Interval);
240 
241  interval = Interval;
242 
243  if (Interval)
244  interval = Interval - 1;
245 
246  if (interval > 5)
247  interval = 5;
248 
249  return 1 << interval;
250 }
void DPRINT(...)
Definition: polytest.cpp:61
DWORD Interval
Definition: netstat.c:33
unsigned char UCHAR
Definition: xmlstorage.h:181

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;
305  KIRQL OldIrql;
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:231
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
UCHAR KIRQL
Definition: env_spec_w32.h:591
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

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

767 {
771  SIZE_T EndpointSize;
772  PUSBPORT_ENDPOINT Endpoint;
773  PUSBPORT_ENDPOINT_PROPERTIES EndpointProperties;
774  PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
776  UCHAR Interval;
777  UCHAR Period;
778  USBPORT_ENDPOINT_REQUIREMENTS EndpointRequirements = {0};
779  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
780  MPSTATUS MpStatus;
781  USBD_STATUS USBDStatus;
783  KIRQL OldIrql;
784  USHORT MaxPacketSize;
785  USHORT AdditionalTransaction;
786  BOOLEAN IsAllocatedBandwidth;
787 
788  DPRINT1("USBPORT_OpenPipe: DeviceHandle - %p, FdoDevice - %p, PipeHandle - %p\n",
789  DeviceHandle,
790  FdoDevice,
791  PipeHandle);
792 
793  FdoExtension = FdoDevice->DeviceExtension;
794  Packet = &FdoExtension->MiniPortInterface->Packet;
795 
796  EndpointSize = sizeof(USBPORT_ENDPOINT) + Packet->MiniPortEndpointSize;
797 
798  if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
799  {
800  EndpointSize += sizeof(USB2_TT_ENDPOINT);
801  }
802 
803  if (PipeHandle->EndpointDescriptor.wMaxPacketSize == 0)
804  {
806 
807  PipeHandle->Flags = (PipeHandle->Flags & ~PIPE_HANDLE_FLAG_CLOSED) |
809 
810  PipeHandle->Endpoint = (PUSBPORT_ENDPOINT)-1;
811 
812  return STATUS_SUCCESS;
813  }
814 
815  Endpoint = ExAllocatePoolWithTag(NonPagedPool, EndpointSize, USB_PORT_TAG);
816 
817  if (!Endpoint)
818  {
819  DPRINT1("USBPORT_OpenPipe: Not allocated Endpoint!\n");
821  return Status;
822  }
823 
824  RtlZeroMemory(Endpoint, EndpointSize);
825 
826  Endpoint->FdoDevice = FdoDevice;
827  Endpoint->DeviceHandle = DeviceHandle;
828  Endpoint->LockCounter = -1;
829 
830  Endpoint->TtExtension = DeviceHandle->TtExtension;
831 
832  if (DeviceHandle->TtExtension)
833  {
834  ExInterlockedInsertTailList(&DeviceHandle->TtExtension->EndpointList,
835  &Endpoint->TtLink,
836  &FdoExtension->TtSpinLock);
837  }
838 
839  if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
840  {
841  Endpoint->TtEndpoint = (PUSB2_TT_ENDPOINT)((ULONG_PTR)Endpoint +
842  sizeof(USBPORT_ENDPOINT) +
843  Packet->MiniPortEndpointSize);
844  }
845  else
846  {
847  Endpoint->TtEndpoint = NULL;
848  }
849 
852 
854  InitializeListHead(&Endpoint->TransferList);
855  InitializeListHead(&Endpoint->CancelList);
856  InitializeListHead(&Endpoint->AbortList);
857 
858  EndpointProperties = &Endpoint->EndpointProperties;
859  EndpointDescriptor = &PipeHandle->EndpointDescriptor;
860 
861  MaxPacketSize = EndpointDescriptor->wMaxPacketSize & 0x7FF;
862  AdditionalTransaction = (EndpointDescriptor->wMaxPacketSize >> 11) & 3;
863 
864  EndpointProperties->DeviceAddress = DeviceHandle->DeviceAddress;
865  EndpointProperties->DeviceSpeed = DeviceHandle->DeviceSpeed;
866  EndpointProperties->Period = 0;
867  EndpointProperties->EndpointAddress = EndpointDescriptor->bEndpointAddress;
868  EndpointProperties->TransactionPerMicroframe = AdditionalTransaction + 1;
869  EndpointProperties->MaxPacketSize = MaxPacketSize;
870  EndpointProperties->TotalMaxPacketSize = MaxPacketSize *
871  (AdditionalTransaction + 1);
872 
873  if (Endpoint->TtExtension)
874  {
875  EndpointProperties->HubAddr = Endpoint->TtExtension->DeviceAddress;
876  }
877  else
878  {
879  EndpointProperties->HubAddr = -1;
880  }
881 
882  EndpointProperties->PortNumber = DeviceHandle->PortNumber;
883 
884  switch (EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK)
885  {
887  EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_CONTROL;
888 
889  if (EndpointProperties->EndpointAddress == 0)
890  {
891  EndpointProperties->MaxTransferSize = 0x1000; // OUT Ep0
892  }
893  else
894  {
895  EndpointProperties->MaxTransferSize = 0x10000;
896  }
897 
898  break;
899 
901  DPRINT1("USBPORT_OpenPipe: USB_ENDPOINT_TYPE_ISOCHRONOUS UNIMPLEMENTED. FIXME. \n");
902  EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_ISOCHRONOUS;
903  EndpointProperties->MaxTransferSize = 0x1000000;
904  break;
905 
907  EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_BULK;
908  EndpointProperties->MaxTransferSize = 0x10000;
909  break;
910 
912  EndpointProperties->TransferType = USBPORT_TRANSFER_TYPE_INTERRUPT;
913  EndpointProperties->MaxTransferSize = 0x400;
914  break;
915  }
916 
917  if (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
918  {
919  if (EndpointProperties->DeviceSpeed == UsbHighSpeed)
920  {
921  Interval = USBPORT_NormalizeHsInterval(EndpointDescriptor->bInterval);
922  }
923  else
924  {
925  Interval = EndpointDescriptor->bInterval;
926  }
927 
928  EndpointProperties->Period = ENDPOINT_INTERRUPT_32ms;
929 
930  if (Interval && (Interval < USB2_FRAMES))
931  {
932  if ((EndpointProperties->DeviceSpeed != UsbLowSpeed) ||
934  {
936  {
937  Period = EndpointProperties->Period;
938 
939  do
940  {
941  Period >>= 1;
942  }
943  while (!(Period & Interval));
944 
945  EndpointProperties->Period = Period;
946  }
947  }
948  else
949  {
950  EndpointProperties->Period = ENDPOINT_INTERRUPT_8ms;
951  }
952  }
953  }
954 
955  if (EndpointProperties->TransferType == USB_ENDPOINT_TYPE_ISOCHRONOUS)
956  {
957  if (EndpointProperties->DeviceSpeed == UsbHighSpeed)
958  {
959  EndpointProperties->Period =
960  USBPORT_NormalizeHsInterval(EndpointDescriptor->bInterval);
961  }
962  else
963  {
964  EndpointProperties->Period = ENDPOINT_INTERRUPT_1ms;
965  }
966  }
967 
968  if ((DeviceHandle->Flags & DEVICE_HANDLE_FLAG_ROOTHUB) != 0)
969  {
970  Endpoint->Flags |= ENDPOINT_FLAG_ROOTHUB_EP0;
971  }
972 
973  if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
974  {
975  IsAllocatedBandwidth = USBPORT_AllocateBandwidthUSB2(FdoDevice, Endpoint);
976  }
977  else
978  {
979  EndpointProperties->UsbBandwidth = USBPORT_CalculateUsbBandwidth(FdoDevice,
980  Endpoint);
981 
982  IsAllocatedBandwidth = USBPORT_AllocateBandwidth(FdoDevice, Endpoint);
983  }
984 
985  if (!IsAllocatedBandwidth)
986  {
988 
989  if (UsbdStatus)
990  {
991  *UsbdStatus = USBD_STATUS_NO_BANDWIDTH;
992  }
993 
994  goto ExitWithError;
995  }
996 
998  EndpointProperties->Direction = Direction;
999 
1000  if (DeviceHandle->IsRootHub)
1001  {
1002  Endpoint->EndpointWorker = 0; // USBPORT_RootHubEndpointWorker;
1003 
1004  Endpoint->Flags |= ENDPOINT_FLAG_ROOTHUB_EP0;
1005 
1006  Endpoint->StateLast = USBPORT_ENDPOINT_ACTIVE;
1007  Endpoint->StateNext = USBPORT_ENDPOINT_ACTIVE;
1008 
1009  PdoExtension = FdoExtension->RootHubPdo->DeviceExtension;
1010 
1011  if (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT)
1012  {
1013  PdoExtension->Endpoint = Endpoint;
1014  }
1015 
1016  USBDStatus = USBD_STATUS_SUCCESS;
1017  }
1018  else
1019  {
1020  Endpoint->EndpointWorker = 1; // USBPORT_DmaEndpointWorker;
1021 
1022  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1023 
1024  Packet->QueryEndpointRequirements(FdoExtension->MiniPortExt,
1025  &Endpoint->EndpointProperties,
1026  &EndpointRequirements);
1027 
1028  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1029 
1030  if ((EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_BULK) ||
1031  (EndpointProperties->TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT))
1032  {
1033  EndpointProperties->MaxTransferSize = EndpointRequirements.MaxTransferSize;
1034  }
1035 
1036  if (EndpointRequirements.HeaderBufferSize)
1037  {
1038  HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
1039  EndpointRequirements.HeaderBufferSize);
1040  }
1041  else
1042  {
1043  HeaderBuffer = NULL;
1044  }
1045 
1046  if (HeaderBuffer || (EndpointRequirements.HeaderBufferSize == 0))
1047  {
1048  Endpoint->HeaderBuffer = HeaderBuffer;
1049 
1050  if (HeaderBuffer)
1051  {
1052  EndpointProperties->BufferVA = HeaderBuffer->VirtualAddress;
1053  EndpointProperties->BufferPA = HeaderBuffer->PhysicalAddress;
1054  EndpointProperties->BufferLength = HeaderBuffer->BufferLength; // BufferLength + LengthPadded;
1055  }
1056 
1057  MpStatus = MiniportOpenEndpoint(FdoDevice, Endpoint);
1058 
1059  Endpoint->Flags |= ENDPOINT_FLAG_DMA_TYPE;
1060  Endpoint->Flags |= ENDPOINT_FLAG_QUEUENE_EMPTY;
1061 
1062  if (MpStatus == 0)
1063  {
1064  ULONG State;
1065 
1067  &Endpoint->EndpointOldIrql);
1068 
1069  Endpoint->StateLast = USBPORT_ENDPOINT_PAUSED;
1070  Endpoint->StateNext = USBPORT_ENDPOINT_PAUSED;
1071 
1073 
1075  Endpoint->EndpointOldIrql);
1076 
1077  while (TRUE)
1078  {
1080  &Endpoint->EndpointOldIrql);
1081 
1082  State = USBPORT_GetEndpointState(Endpoint);
1083 
1085  Endpoint->EndpointOldIrql);
1086 
1088  {
1089  break;
1090  }
1091 
1092  USBPORT_Wait(FdoDevice, 1); // 1 msec.
1093  }
1094  }
1095  }
1096  else
1097  {
1098  MpStatus = MP_STATUS_NO_RESOURCES;
1099  Endpoint->HeaderBuffer = NULL;
1100  }
1101 
1102  if (MpStatus)
1103  {
1105  }
1106  else
1107  {
1108  USBDStatus = USBD_STATUS_SUCCESS;
1109  }
1110  }
1111 
1112  if (UsbdStatus)
1113  {
1114  *UsbdStatus = USBDStatus;
1115  }
1116 
1117  Status = USBPORT_USBDStatusToNtStatus(NULL, USBDStatus);
1118 
1119  if (NT_SUCCESS(Status))
1120  {
1122 
1124  &Endpoint->EndpointLink,
1125  &FdoExtension->EndpointListSpinLock);
1126 
1127  PipeHandle->Endpoint = Endpoint;
1129 
1130  return Status;
1131  }
1132 
1133 ExitWithError:
1134 
1135  if (Endpoint)
1136  {
1137  if (IsAllocatedBandwidth)
1138  {
1139  if (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1140  {
1141  USBPORT_FreeBandwidthUSB2(FdoDevice, Endpoint);
1142  }
1143  else
1144  {
1145  USBPORT_FreeBandwidth(FdoDevice, Endpoint);
1146  }
1147  }
1148 
1149  if (Endpoint->TtExtension)
1150  {
1151  KeAcquireSpinLock(&FdoExtension->TtSpinLock, &OldIrql);
1152  RemoveEntryList(&Endpoint->TtLink);
1153  KeReleaseSpinLock(&FdoExtension->TtSpinLock, OldIrql);
1154  }
1155 
1156  ExFreePoolWithTag(Endpoint, USB_PORT_TAG);
1157  }
1158 
1159  DPRINT1("USBPORT_OpenPipe: Status - %lx\n", Status);
1160  return Status;
1161 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
ULONG MPSTATUS
Definition: usbmport.h:131
#define PIPE_HANDLE_FLAG_CLOSED
Definition: usbport.h:125
#define USBPORT_TRANSFER_TYPE_BULK
Definition: usbmport.h:9
PUSB2_TT_ENDPOINT TtEndpoint
Definition: usbport.h:209
LIST_ENTRY EndpointLink
Definition: usbport.h:231
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
VOID NTAPI USBPORT_FreeBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:171
VOID NTAPI USBPORT_FreeBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: usb2.c:2040
#define ENDPOINT_INTERRUPT_1ms
Definition: usbmport.h:25
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE
Definition: usbport.h:126
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define ENDPOINT_FLAG_QUEUENE_EMPTY
Definition: usbport.h:113
LONG NTSTATUS
Definition: precomp.h:26
_In_ LARGE_INTEGER _In_ ULONG Period
Definition: kefuncs.h:1268
#define USB_ENDPOINT_TYPE_CONTROL
Definition: usb100.h:62
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
LIST_ENTRY AbortList
Definition: usbport.h:229
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
MPSTATUS NTAPI MiniportOpenEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:722
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:224
PUSB2_TT_EXTENSION TtExtension
Definition: usbport.h:208
UCHAR NTAPI USBPORT_NormalizeHsInterval(UCHAR Interval)
Definition: endpoint.c:235
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
struct _USB2_TT_ENDPOINT USB2_TT_ENDPOINT
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
#define USB_PORT_TAG
Definition: usbport.h:44
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1686
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:205
LIST_ENTRY PendingTransferList
Definition: usbport.h:226
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:206
LIST_ENTRY TransferList
Definition: usbport.h:227
KIRQL EndpointOldIrql
Definition: usbport.h:215
#define MP_STATUS_NO_RESOURCES
Definition: usbmport.h:136
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define USBPORT_ENDPOINT_PAUSED
Definition: usbmport.h:14
#define ENDPOINT_FLAG_DMA_TYPE
Definition: usbport.h:110
struct _USB2_TT_ENDPOINT * PUSB2_TT_ENDPOINT
Definition: usbport.h:159
VOID NTAPI USBPORT_SetEndpointState(IN PUSBPORT_ENDPOINT Endpoint, IN ULONG State)
Definition: endpoint.c:363
#define ENDPOINT_INTERRUPT_32ms
Definition: usbmport.h:30
DWORD Interval
Definition: netstat.c:33
#define USB_ENDPOINT_TYPE_MASK
Definition: usb100.h:61
#define ENDPOINT_INTERRUPT_8ms
Definition: usbmport.h:28
if(!(yy_init))
Definition: macro.lex.yy.c:714
ULONG EndpointWorker
Definition: usbport.h:211
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
_Inout_ PSIZE_T _In_opt_ PMDLX _In_ MM_ROTATE_DIRECTION Direction
Definition: mmfuncs.h:773
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:154
PUSBPORT_DEVICE_HANDLE DeviceHandle
Definition: usbport.h:207
#define DEVICE_HANDLE_FLAG_ROOTHUB
Definition: usbport.h:105
VOID NTAPI USBPORT_AddPipeHandle(IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PUSBPORT_PIPE_HANDLE PipeHandle)
Definition: endpoint.c:444
#define USB_ENDPOINT_TYPE_ISOCHRONOUS
Definition: usb100.h:63
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
unsigned char UCHAR
Definition: xmlstorage.h:181
BOOLEAN NTAPI USBPORT_AllocateBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:63
#define USBPORT_TRANSFER_TYPE_INTERRUPT
Definition: usbmport.h:10
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LONG USBD_STATUS
Definition: usb.h:165
ULONG NTAPI USBPORT_CalculateUsbBandwidth(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:18
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
#define USB_ENDPOINT_TYPE_BULK
Definition: usb100.h:64
#define USBPORT_TRANSFER_TYPE_ISOCHRONOUS
Definition: usbmport.h:7
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
enum State_ State
Definition: pofuncs.h:54
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define USB2_FRAMES
Definition: usbport.h:451
USHORT DeviceAddress
Definition: usbport.h:554
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define USB_ENDPOINT_DIRECTION_OUT(x)
Definition: usb100.h:75
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938
LIST_ENTRY TtLink
Definition: usbport.h:238
LIST_ENTRY CancelList
Definition: usbport.h:228
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214
#define USBD_STATUS_NO_BANDWIDTH
Definition: usb.h:195
#define USB_ENDPOINT_TYPE_INTERRUPT
Definition: usb100.h:65
BOOLEAN NTAPI USBPORT_AllocateBandwidthUSB2(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: usb2.c:1799

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

458 {
459  DPRINT("USBPORT_RemovePipeHandle: PipeHandle - %p\n", PipeHandle);
460 
461  RemoveEntryList(&PipeHandle->PipeLink);
462 
463  PipeHandle->PipeLink.Flink = NULL;
464  PipeHandle->PipeLink.Blink = NULL;
465 }
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21

Referenced by USBPORT_ClosePipe(), and USBPORT_RestoreDevice().

◆ USBPORT_ReopenPipe()

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

Definition at line 1165 of file endpoint.c.

1167 {
1169  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
1170  USBPORT_ENDPOINT_REQUIREMENTS EndpointRequirements = {0};
1172  KIRQL MiniportOldIrql;
1173  NTSTATUS Status;
1174 
1175  DPRINT1("USBPORT_ReopenPipe ... \n");
1176 
1177  FdoExtension = FdoDevice->DeviceExtension;
1178  Packet = &FdoExtension->MiniPortInterface->Packet;
1179 
1180  while (TRUE)
1181  {
1182  if (!InterlockedIncrement(&Endpoint->LockCounter))
1183  break;
1184 
1185  InterlockedDecrement(&Endpoint->LockCounter);
1186  USBPORT_Wait(FdoDevice, 1);
1187  }
1188 
1189  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1190  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1191 
1192  Packet->SetEndpointState(FdoExtension->MiniPortExt,
1193  Endpoint + 1,
1195 
1196  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1197  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1198 
1199  USBPORT_Wait(FdoDevice, 2);
1200 
1201  MiniportCloseEndpoint(FdoDevice, Endpoint);
1202 
1203  RtlZeroMemory(Endpoint + 1,
1204  Packet->MiniPortEndpointSize);
1205 
1206  if (Endpoint->HeaderBuffer)
1207  {
1208  USBPORT_FreeCommonBuffer(FdoDevice, Endpoint->HeaderBuffer);
1209  Endpoint->HeaderBuffer = NULL;
1210  }
1211 
1212  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &MiniportOldIrql);
1213 
1214  Packet->QueryEndpointRequirements(FdoExtension->MiniPortExt,
1215  &Endpoint->EndpointProperties,
1216  &EndpointRequirements);
1217 
1218  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, MiniportOldIrql);
1219 
1220  if (EndpointRequirements.HeaderBufferSize)
1221  {
1222  HeaderBuffer = USBPORT_AllocateCommonBuffer(FdoDevice,
1223  EndpointRequirements.HeaderBufferSize);
1224  }
1225  else
1226  {
1227  HeaderBuffer = NULL;
1228  }
1229 
1230  if (HeaderBuffer || EndpointRequirements.HeaderBufferSize == 0)
1231  {
1232  Endpoint->HeaderBuffer = HeaderBuffer;
1234  }
1235  else
1236  {
1237  Endpoint->HeaderBuffer = 0;
1239  }
1240 
1241  if (Endpoint->HeaderBuffer && HeaderBuffer)
1242  {
1243  Endpoint->EndpointProperties.BufferVA = HeaderBuffer->VirtualAddress;
1244  Endpoint->EndpointProperties.BufferPA = HeaderBuffer->PhysicalAddress;
1245  Endpoint->EndpointProperties.BufferLength = HeaderBuffer->BufferLength;
1246  }
1247 
1248  if (NT_SUCCESS(Status))
1249  {
1250  MiniportOpenEndpoint(FdoDevice, Endpoint);
1251 
1252  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1253  KeAcquireSpinLockAtDpcLevel(&Endpoint->StateChangeSpinLock);
1254 
1255  if (Endpoint->StateLast == USBPORT_ENDPOINT_ACTIVE)
1256  {
1257  KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1258  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1259 
1260  Packet->SetEndpointState(FdoExtension->MiniPortExt,
1261  Endpoint + 1,
1263 
1264  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1265  }
1266  else
1267  {
1268  KeReleaseSpinLockFromDpcLevel(&Endpoint->StateChangeSpinLock);
1269  }
1270 
1271  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1272  }
1273 
1274  InterlockedDecrement(&Endpoint->LockCounter);
1275 
1276  return Status;
1277 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1748
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
MPSTATUS NTAPI MiniportOpenEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:722
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1686
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
smooth NULL
Definition: ftsmooth.c:416
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define InterlockedDecrement
Definition: armddk.h:52
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
VOID NTAPI MiniportCloseEndpoint(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:549
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2938

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;
369  KIRQL OldIrql;
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  ExInterlockedInsertTailList(&FdoExtension->EpStateChangeList,
414  &Endpoint->StateChangeLink,
415  &FdoExtension->EpStateChangeSpinLock);
416 
417  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
418  Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
419  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
420  }
421  else
422  {
423  Endpoint->StateLast = State;
424  Endpoint->StateNext = State;
425 
427  {
428  KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
429  Endpoint->EndpointStateOldIrql);
430 
432  Endpoint,
434  return;
435  }
436 
437  KeReleaseSpinLock(&Endpoint->StateChangeSpinLock,
438  Endpoint->EndpointStateOldIrql);
439  }
440 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
#define USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
enum State_ State
Definition: pofuncs.h:54
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317

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

471 {
472  PLIST_ENTRY HandleList;
473  PUSBPORT_PIPE_HANDLE CurrentHandle;
474 
475  //DPRINT("USBPORT_ValidatePipeHandle: DeviceHandle - %p, PipeHandle - %p\n",
476  // DeviceHandle,
477  // PipeHandle);
478 
479  HandleList = DeviceHandle->PipeHandleList.Flink;
480 
481  while (HandleList != &DeviceHandle->PipeHandleList)
482  {
483  CurrentHandle = CONTAINING_RECORD(HandleList,
485  PipeLink);
486 
487  HandleList = HandleList->Flink;
488 
489  if (CurrentHandle == PipeHandle)
490  return TRUE;
491  }
492 
493  return FALSE;
494 }
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21

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