ReactOS  0.4.13-dev-982-g9853eab
queue.c File Reference
#include "usbport.h"
#include <debug.h>
#include "usbdebug.h"
Include dependency graph for queue.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBPORT_CORE
 
#define NDEBUG_USBPORT_QUEUE
 
#define NDEBUG_USBPORT_URB
 

Functions

VOID NTAPI USBPORT_InsertIdleIrp (IN PIO_CSQ Csq, IN PIRP Irp)
 
VOID NTAPI USBPORT_RemoveIdleIrp (IN PIO_CSQ Csq, IN PIRP Irp)
 
PIRP NTAPI USBPORT_PeekNextIdleIrp (IN PIO_CSQ Csq, IN PIRP Irp, IN PVOID PeekContext)
 
VOID NTAPI USBPORT_AcquireIdleLock (IN PIO_CSQ Csq, IN PKIRQL Irql)
 
VOID NTAPI USBPORT_ReleaseIdleLock (IN PIO_CSQ Csq, IN KIRQL Irql)
 
VOID NTAPI USBPORT_CompleteCanceledIdleIrp (IN PIO_CSQ Csq, IN PIRP Irp)
 
VOID NTAPI USBPORT_InsertBadRequest (IN PIO_CSQ Csq, IN PIRP Irp)
 
VOID NTAPI USBPORT_RemoveBadRequest (IN PIO_CSQ Csq, IN PIRP Irp)
 
PIRP NTAPI USBPORT_PeekNextBadRequest (IN PIO_CSQ Csq, IN PIRP Irp, IN PVOID PeekContext)
 
VOID NTAPI USBPORT_AcquireBadRequestLock (IN PIO_CSQ Csq, IN PKIRQL Irql)
 
VOID NTAPI USBPORT_ReleaseBadRequestLock (IN PIO_CSQ Csq, IN KIRQL Irql)
 
VOID NTAPI USBPORT_CompleteCanceledBadRequest (IN PIO_CSQ Csq, IN PIRP Irp)
 
VOID NTAPI USBPORT_InsertIrpInTable (IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
 
PIRP NTAPI USBPORT_RemoveIrpFromTable (IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
 
PIRP NTAPI USBPORT_RemoveActiveTransferIrp (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
PIRP NTAPI USBPORT_RemovePendingTransferIrp (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
VOID NTAPI USBPORT_FindUrbInIrpTable (IN PUSBPORT_IRP_TABLE IrpTable, IN PURB Urb, IN PIRP Irp)
 
PIRP NTAPI USBPORT_FindIrpInTable (IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
 
PIRP NTAPI USBPORT_FindActiveTransferIrp (IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
 
VOID NTAPI USBPORT_CancelPendingTransferIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI USBPORT_CancelActiveTransferIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI USBPORT_FlushAbortList (IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_FlushCancelList (IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_FlushPendingTransfers (IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_QueuePendingUrbToEndpoint (IN PUSBPORT_ENDPOINT Endpoint, IN PURB Urb)
 
BOOLEAN NTAPI USBPORT_QueueActiveUrbToEndpoint (IN PUSBPORT_ENDPOINT Endpoint, IN PURB Urb)
 
VOID NTAPI USBPORT_QueuePendingTransferIrp (IN PIRP Irp)
 
VOID NTAPI USBPORT_QueueTransferUrb (IN PURB Urb)
 
VOID NTAPI USBPORT_FlushAllEndpoints (IN PDEVICE_OBJECT FdoDevice)
 
ULONG NTAPI USBPORT_KillEndpointActiveTransfers (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
 
VOID NTAPI USBPORT_FlushController (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_BadRequestFlush (IN PDEVICE_OBJECT FdoDevice)
 
VOID NTAPI USBPORT_AbortEndpoint (IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file queue.c.

◆ NDEBUG_USBPORT_CORE

#define NDEBUG_USBPORT_CORE

Definition at line 13 of file queue.c.

◆ NDEBUG_USBPORT_QUEUE

#define NDEBUG_USBPORT_QUEUE

Definition at line 14 of file queue.c.

◆ NDEBUG_USBPORT_URB

#define NDEBUG_USBPORT_URB

Definition at line 15 of file queue.c.

Function Documentation

◆ USBPORT_AbortEndpoint()

VOID NTAPI USBPORT_AbortEndpoint ( IN PDEVICE_OBJECT  FdoDevice,
IN PUSBPORT_ENDPOINT  Endpoint,
IN PIRP  Irp 
)

Definition at line 1354 of file queue.c.

1357 {
1358  PLIST_ENTRY PendingList;
1359  PUSBPORT_TRANSFER PendingTransfer;
1360  PLIST_ENTRY ActiveList;
1361  PUSBPORT_TRANSFER ActiveTransfer;
1362 
1363  DPRINT_CORE("USBPORT_AbortEndpoint: Irp - %p\n", Irp);
1364 
1365  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
1366 
1367  if (Irp)
1368  {
1369  InsertTailList(&Endpoint->AbortList, &Irp->Tail.Overlay.ListEntry);
1370  }
1371 
1372  PendingList = Endpoint->PendingTransferList.Flink;
1373 
1374  while (PendingList && PendingList != &Endpoint->PendingTransferList)
1375  {
1376  PendingTransfer = CONTAINING_RECORD(PendingList,
1378  TransferLink);
1379 
1380  DPRINT_CORE("USBPORT_AbortEndpoint: Abort PendingTransfer - %p\n",
1381  PendingTransfer);
1382 
1383  PendingTransfer->Flags |= TRANSFER_FLAG_ABORTED;
1384 
1385  PendingList = PendingTransfer->TransferLink.Flink;
1386  }
1387 
1388  ActiveList = Endpoint->TransferList.Flink;
1389 
1390  while (ActiveList && ActiveList != &Endpoint->TransferList)
1391  {
1392  ActiveTransfer = CONTAINING_RECORD(ActiveList,
1394  TransferLink);
1395 
1396  DPRINT_CORE("USBPORT_AbortEndpoint: Abort ActiveTransfer - %p\n",
1397  ActiveTransfer);
1398 
1399  ActiveTransfer->Flags |= TRANSFER_FLAG_ABORTED;
1400 
1401  if (Endpoint->Flags & ENDPOINT_FLAG_ABORTING)
1402  {
1403  ActiveTransfer->Flags |= TRANSFER_FLAG_DEVICE_GONE;
1404  }
1405 
1406  ActiveList = ActiveTransfer->TransferLink.Flink;
1407  }
1408 
1409  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1410 
1412  Endpoint,
1414 
1416  USBPORT_FlushCancelList(Endpoint);
1417 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIRP Irp
Definition: csq.h:116
#define TRANSFER_FLAG_DEVICE_GONE
Definition: usbport.h:135
#define InsertTailList(ListHead, Entry)
#define INVALIDATE_ENDPOINT_INT_NEXT_SOF
Definition: usbport.h:39
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
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
Definition: typedefs.h:117
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define ENDPOINT_FLAG_ABORTING
Definition: usbport.h:114
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_AbortPipe(), and USBPORT_AbortTransfers().

◆ USBPORT_AcquireBadRequestLock()

VOID NTAPI USBPORT_AcquireBadRequestLock ( IN PIO_CSQ  Csq,
IN PKIRQL  Irql 
)

Definition at line 214 of file queue.c.

216 {
218 
219  DPRINT_QUEUE("USBPORT_AcquireBadRequestLock: ... \n");
220 
223  BadRequestIoCsq);
224 
225  KeAcquireSpinLock(&FdoExtension->BadRequestIoCsqSpinLock, Irql);
226 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_Out_ PKIRQL Irql
Definition: csq.h:179
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 KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_AcquireIdleLock()

VOID NTAPI USBPORT_AcquireIdleLock ( IN PIO_CSQ  Csq,
IN PKIRQL  Irql 
)

Definition at line 91 of file queue.c.

93 {
95 
96  DPRINT_QUEUE("USBPORT_AcquireIdleLock: ... \n");
97 
100  IdleIoCsq);
101 
102  KeAcquireSpinLock(&FdoExtension->IdleIoCsqSpinLock, Irql);
103 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_Out_ PKIRQL Irql
Definition: csq.h:179
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 KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_BadRequestFlush()

VOID NTAPI USBPORT_BadRequestFlush ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1328 of file queue.c.

1329 {
1331  PIRP Irp;
1332 
1333  DPRINT_QUEUE("USBPORT_BadRequestFlush: ... \n");
1334 
1335  FdoExtension = FdoDevice->DeviceExtension;
1336 
1337  while (TRUE)
1338  {
1339  Irp = IoCsqRemoveNextIrp(&FdoExtension->BadRequestIoCsq, 0);
1340 
1341  if (!Irp)
1342  break;
1343 
1344  DPRINT1("USBPORT_BadRequestFlush: Irp - %p\n", Irp);
1345 
1346  Irp->IoStatus.Status = STATUS_DEVICE_NOT_CONNECTED;
1347  Irp->IoStatus.Information = 0;
1349  }
1350 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
#define TRUE
Definition: types.h:120
NTKERNELAPI PIRP NTAPI IoCsqRemoveNextIrp(_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext)
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
Definition: csq.c:398
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:565

Referenced by USBHI_FlushTransfers(), and USBPORT_TimerDpc().

◆ USBPORT_CancelActiveTransferIrp()

VOID NTAPI USBPORT_CancelActiveTransferIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 529 of file queue.c.

531 {
533  PDEVICE_OBJECT FdoDevice;
535  PURB Urb;
536  PUSBPORT_TRANSFER Transfer;
537  PUSBPORT_ENDPOINT Endpoint;
538  PIRP irp;
539  PUSBPORT_TRANSFER SplitTransfer;
541  KIRQL OldIrql;
542 
543  DPRINT_CORE("USBPORT_CancelActiveTransferIrp: Irp - %p\n", Irp);
544 
546  FdoDevice = PdoExtension->FdoDevice;
547  FdoExtension = FdoDevice->DeviceExtension;
548 
549  IoReleaseCancelSpinLock(Irp->CancelIrql);
550 
551  KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
552 
553  irp = USBPORT_FindActiveTransferIrp(FdoDevice, Irp);
554 
555  if (!irp)
556  {
557  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
558  return;
559  }
560 
561  Urb = URB_FROM_IRP(irp);
562  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
563  Endpoint = Transfer->Endpoint;
564 
565  DPRINT_CORE("USBPORT_CancelActiveTransferIrp: irp - %p, Urb - %p, Transfer - %p\n",
566  irp,
567  Urb,
568  Transfer);
569 
571 
572  Transfer->Flags |= TRANSFER_FLAG_CANCELED;
573 
574  if (Transfer->Flags & TRANSFER_FLAG_PARENT)
575  {
577 
578  Entry = Transfer->SplitTransfersList.Flink;
579 
580  while (Entry && Entry != &Transfer->SplitTransfersList)
581  {
582  SplitTransfer = CONTAINING_RECORD(Entry,
584  SplitLink);
585 
586  SplitTransfer->Flags |= TRANSFER_FLAG_CANCELED;
587 
588  Entry = Entry->Flink;
589  }
590 
592  }
593 
595  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
596 
598  Endpoint,
600  return;
601 }
#define TRANSFER_FLAG_CANCELED
Definition: usbport.h:129
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
#define TRANSFER_FLAG_PARENT
Definition: usbport.h:138
PIRP NTAPI USBPORT_FindActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:467
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:252
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#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
Definition: typedefs.h:117
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: usb.h:529
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
LIST_ENTRY SplitTransfersList
Definition: usbport.h:265
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:264
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214
base of all file and directory entries
Definition: entries.h:82

Referenced by USBPORT_FlushPendingTransfers().

◆ USBPORT_CancelPendingTransferIrp()

VOID NTAPI USBPORT_CancelPendingTransferIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 479 of file queue.c.

481 {
482  PURB Urb;
483  PUSBPORT_TRANSFER Transfer;
484  PUSBPORT_ENDPOINT Endpoint;
485  PDEVICE_OBJECT FdoDevice;
487  KIRQL OldIrql;
488  PIRP irp;
489 
490  DPRINT_CORE("USBPORT_CancelPendingTransferIrp: DeviceObject - %p, Irp - %p\n",
491  DeviceObject,
492  Irp);
493 
494  Urb = URB_FROM_IRP(Irp);
495  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
496  Endpoint = Transfer->Endpoint;
497 
498  FdoDevice = Endpoint->FdoDevice;
500 
501  IoReleaseCancelSpinLock(Irp->CancelIrql);
502 
503  KeAcquireSpinLock(&FdoExtension->FlushPendingTransferSpinLock, &OldIrql);
504 
505  irp = USBPORT_RemovePendingTransferIrp(FdoDevice, Irp);
506 
507  if (!irp)
508  {
509  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
510  OldIrql);
511  return;
512  }
513 
515 
516  RemoveEntryList(&Transfer->TransferLink);
517 
518  Transfer->TransferLink.Flink = NULL;
519  Transfer->TransferLink.Blink = NULL;
520 
522  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock, OldIrql);
523 
525 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2176
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
_In_ PIRP Irp
Definition: csq.h:116
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:205
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:252
LIST_ENTRY TransferLink
Definition: usbport.h:256
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#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
PIRP NTAPI USBPORT_RemovePendingTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:369
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
Definition: usb.h:529
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBD_STATUS_CANCELED
Definition: usb.h:213
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214

Referenced by USBPORT_QueuePendingTransferIrp().

◆ USBPORT_CompleteCanceledBadRequest()

VOID NTAPI USBPORT_CompleteCanceledBadRequest ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 246 of file queue.c.

248 {
250 
251  DPRINT_QUEUE("USBPORT_CompleteCanceledBadRequest: Irp - %p\n", Irp);
252 
255  BadRequestIoCsq);
256 
257  InterlockedDecrement(&FdoExtension->BadRequestLockCounter);
258 
259  Irp->IoStatus.Status = STATUS_CANCELLED;
260  Irp->IoStatus.Information = 0;
262 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
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 STATUS_CANCELLED
Definition: udferr_usr.h:170
#define InterlockedDecrement
Definition: armddk.h:52
IO_CSQ Csq
Definition: csqrtns.c:46
#define IO_NO_INCREMENT
Definition: iotypes.h:565

Referenced by USBPORT_StartDevice().

◆ USBPORT_CompleteCanceledIdleIrp()

VOID NTAPI USBPORT_CompleteCanceledIdleIrp ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 123 of file queue.c.

125 {
127 
128  DPRINT_QUEUE("USBPORT_CompleteCanceledIdleIrp: ... \n");
129 
132  IdleIoCsq);
133 
134  InterlockedDecrement(&FdoExtension->IdleLockCounter);
135 
136  Irp->IoStatus.Status = STATUS_CANCELLED;
137  Irp->IoStatus.Information = 0;
139 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
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 STATUS_CANCELLED
Definition: udferr_usr.h:170
#define InterlockedDecrement
Definition: armddk.h:52
IO_CSQ Csq
Definition: csqrtns.c:46
#define IO_NO_INCREMENT
Definition: iotypes.h:565

Referenced by USBPORT_StartDevice().

◆ USBPORT_FindActiveTransferIrp()

PIRP NTAPI USBPORT_FindActiveTransferIrp ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 467 of file queue.c.

469 {
471 
472  DPRINT_CORE("USBPORT_FindActiveTransferIrp: Irp - %p\n", Irp);
473  FdoExtension = FdoDevice->DeviceExtension;
474  return USBPORT_FindIrpInTable(FdoExtension->ActiveIrpTable, Irp);
475 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIRP Irp
Definition: csq.h:116
PIRP NTAPI USBPORT_FindIrpInTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
Definition: queue.c:433

Referenced by USBPORT_CancelActiveTransferIrp().

◆ USBPORT_FindIrpInTable()

PIRP NTAPI USBPORT_FindIrpInTable ( IN PUSBPORT_IRP_TABLE  IrpTable,
IN PIRP  Irp 
)

Definition at line 433 of file queue.c.

435 {
436  ULONG ix;
437  PIRP irp;
438 
439  DPRINT_CORE("USBPORT_FindIrpInTable: IrpTable - %p, Irp - %p\n",
440  IrpTable,
441  Irp);
442 
443  ASSERT(IrpTable != NULL);
444 
445  do
446  {
447  for (ix = 0; ix < 0x200; ix++)
448  {
449  irp = IrpTable->irp[ix];
450 
451  if (irp && irp == Irp)
452  {
453  return irp;
454  }
455  }
456 
457  IrpTable = IrpTable->LinkNextTable;
458  }
459  while (IrpTable->LinkNextTable);
460 
461  DPRINT_CORE("USBPORT_FindIrpInTable: Not found!!!\n");
462  return NULL;
463 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIRP Irp
Definition: csq.h:116
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBPORT_FindActiveTransferIrp().

◆ USBPORT_FindUrbInIrpTable()

VOID NTAPI USBPORT_FindUrbInIrpTable ( IN PUSBPORT_IRP_TABLE  IrpTable,
IN PURB  Urb,
IN PIRP  Irp 
)

Definition at line 381 of file queue.c.

384 {
385  ULONG ix;
386  PIRP irp;
387  PURB urbIn;
388 
389  DPRINT_CORE("USBPORT_FindUrbInIrpTable: IrpTable - %p, Urb - %p, Irp - %p\n",
390  IrpTable,
391  Urb,
392  Irp);
393 
394  ASSERT(IrpTable != NULL);
395 
396  do
397  {
398  for (ix = 0; ix < 0x200; ix++)
399  {
400  irp = IrpTable->irp[ix];
401 
402  if (irp)
403  {
404  urbIn = URB_FROM_IRP(irp);
405 
406  if (urbIn == Urb)
407  {
408  if (irp == Irp)
409  {
410  KeBugCheckEx(BUGCODE_USB_DRIVER,
411  4,
412  (ULONG_PTR)irp,
413  (ULONG_PTR)urbIn,
414  0);
415  }
416 
417  KeBugCheckEx(BUGCODE_USB_DRIVER,
418  2,
419  (ULONG_PTR)irp,
420  (ULONG_PTR)Irp,
421  (ULONG_PTR)urbIn);
422  }
423  }
424  }
425 
426  IrpTable = IrpTable->LinkNextTable;
427  }
428  while (IrpTable);
429 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
_In_ PIRP Irp
Definition: csq.h:116
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: usb.h:529
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

Referenced by USBPORT_FlushPendingTransfers().

◆ USBPORT_FlushAbortList()

VOID NTAPI USBPORT_FlushAbortList ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 605 of file queue.c.

606 {
608  PUSBPORT_TRANSFER Transfer;
609  PLIST_ENTRY AbortList;
612  PIRP Irp;
613  PURB Urb;
615 
616  DPRINT_CORE("USBPORT_FlushAbortList: Endpoint - %p\n", Endpoint);
617 
619 
620  KeAcquireSpinLock(&Endpoint->EndpointSpinLock, &Endpoint->EndpointOldIrql);
621 
622  if (IsListEmpty(&Endpoint->AbortList))
623  {
624  KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
625  Endpoint->EndpointOldIrql);
626  return;
627  }
628 
629  Entry = Endpoint->PendingTransferList.Flink;
630 
631  while (Entry && Entry != &Endpoint->PendingTransferList)
632  {
633  Transfer = CONTAINING_RECORD(Entry,
635  TransferLink);
636 
637  if (Transfer->Flags & TRANSFER_FLAG_ABORTED)
638  {
639  DPRINT_CORE("USBPORT_FlushAbortList: Aborted PendingTransfer - %p\n",
640  Transfer);
641 
642  KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
643  Endpoint->EndpointOldIrql);
644  return;
645  }
646 
647  Entry = Transfer->TransferLink.Flink;
648  }
649 
650  Entry = Endpoint->TransferList.Flink;
651 
652  while (Entry && Entry != &Endpoint->TransferList)
653  {
654  Transfer = CONTAINING_RECORD(Entry,
656  TransferLink);
657 
658  if (Transfer->Flags & TRANSFER_FLAG_ABORTED)
659  {
660  DPRINT_CORE("USBPORT_FlushAbortList: Aborted ActiveTransfer - %p\n",
661  Transfer);
662 
663  KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
664  Endpoint->EndpointOldIrql);
665  return;
666  }
667 
668  Entry = Transfer->TransferLink.Flink;
669  }
670 
671  AbortList = &Endpoint->AbortList;
672 
673  while (!IsListEmpty(AbortList))
674  {
675  //DbgBreakPoint();
676 
677  Irp = CONTAINING_RECORD(AbortList->Flink,
678  IRP,
679  Tail.Overlay.ListEntry);
680 
681  RemoveHeadList(AbortList);
682  InsertTailList(&List, &Irp->Tail.Overlay.ListEntry);
683  }
684 
685  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
686 
687  while (!IsListEmpty(&List))
688  {
689  //DbgBreakPoint();
690 
692  IRP,
693  Tail.Overlay.ListEntry);
694 
696 
697  Urb = URB_FROM_IRP(Irp);
698 
699  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
700  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
701 
703 
704  DPRINT_CORE("USBPORT_FlushAbortList: complete Irp - %p\n", Irp);
705 
706  Irp->IoStatus.Status = Status;
707  Irp->IoStatus.Information = 0;
709  }
710 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
IRP
Definition: iotypes.h:2462
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
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 _URB_HEADER UrbHeader
Definition: usb.h:531
LIST_ENTRY TransferLink
Definition: usbport.h:256
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define InterlockedDecrement
Definition: armddk.h:52
Definition: typedefs.h:117
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
Status
Definition: gdiplustypes.h:24
Definition: usb.h:529
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define IO_NO_INCREMENT
Definition: iotypes.h:565
base of all file and directory entries
Definition: entries.h:82

Referenced by USBPORT_EndpointWorker(), and USBPORT_FlushCancelList().

◆ USBPORT_FlushAllEndpoints()

VOID NTAPI USBPORT_FlushAllEndpoints ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1171 of file queue.c.

1172 {
1175  PUSBPORT_ENDPOINT Endpoint;
1176  LIST_ENTRY List;
1177  KIRQL OldIrql;
1178 
1179  DPRINT_CORE("USBPORT_FlushAllEndpoints: ... \n");
1180 
1181  FdoExtension = FdoDevice->DeviceExtension;
1182 
1183  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1184 
1186 
1187  Entry = FdoExtension->EndpointList.Flink;
1188 
1189  while (Entry && Entry != &FdoExtension->EndpointList)
1190  {
1191  Endpoint = CONTAINING_RECORD(Entry,
1193  EndpointLink);
1194 
1196  {
1197  InsertTailList(&List, &Endpoint->FlushLink);
1198  }
1199 
1200  Entry = Endpoint->EndpointLink.Flink;
1201  }
1202 
1203  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1204 
1205  while (!IsListEmpty(&List))
1206  {
1207  Endpoint = CONTAINING_RECORD(List.Flink,
1209  FlushLink);
1210 
1211  RemoveHeadList(&List);
1212 
1213  Endpoint->FlushLink.Flink = NULL;
1214  Endpoint->FlushLink.Blink = NULL;
1215 
1216  if (!IsListEmpty(&Endpoint->PendingTransferList))
1217  {
1219  }
1220  }
1221 
1222  DPRINT_CORE("USBPORT_FlushAllEndpoints: exit\n");
1223 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
LIST_ENTRY EndpointLink
Definition: usbport.h:231
LIST_ENTRY FlushLink
Definition: usbport.h:235
struct _Entry Entry
Definition: kefuncs.h:640
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY PendingTransferList
Definition: usbport.h:226
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
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
LIST_ENTRY List
Definition: psmgr.c:57
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
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 InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
base of all file and directory entries
Definition: entries.h:82
#define USBPORT_ENDPOINT_CLOSED
Definition: usbmport.h:17

Referenced by USBPORT_WorkerThreadHandler().

◆ USBPORT_FlushCancelList()

VOID NTAPI USBPORT_FlushCancelList ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 714 of file queue.c.

715 {
716  PDEVICE_OBJECT FdoDevice;
718  PUSBPORT_TRANSFER Transfer;
719  PIRP Irp;
720  KIRQL OldIrql;
721  KIRQL PrevIrql;
722 
723  DPRINT_CORE("USBPORT_FlushCancelList: ... \n");
724 
725  FdoDevice = Endpoint->FdoDevice;
726  FdoExtension = FdoDevice->DeviceExtension;
727 
728  KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
729  KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
730 
731  while (!IsListEmpty(&Endpoint->CancelList))
732  {
733  Transfer = CONTAINING_RECORD(Endpoint->CancelList.Flink,
735  TransferLink);
736 
737  RemoveHeadList(&Endpoint->CancelList);
738 
739  Irp = Transfer->Irp;
740 
741  if (Irp)
742  {
743  DPRINT("USBPORT_FlushCancelList: Irp - %p\n", Irp);
744 
745  IoAcquireCancelSpinLock(&PrevIrql);
747  IoReleaseCancelSpinLock(PrevIrql);
748 
750  }
751 
752  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
753  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
754 
755  if (Endpoint->Flags & ENDPOINT_FLAG_NUKE)
756  {
758  }
759  else
760  {
761  if (Transfer->Flags & TRANSFER_FLAG_DEVICE_GONE)
762  {
763  USBPORT_CompleteTransfer(Transfer->Urb,
765  }
766  else
767  {
768  USBPORT_CompleteTransfer(Transfer->Urb,
770  }
771  }
772 
773  KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
774  KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
775  }
776 
777  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
778  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
779 
780  USBPORT_FlushAbortList(Endpoint);
781 }
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2176
_In_ PIRP Irp
Definition: csq.h:116
#define TRANSFER_FLAG_DEVICE_GONE
Definition: usbport.h:135
VOID NTAPI USBPORT_FlushAbortList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:605
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#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
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBD_STATUS_CANCELED
Definition: usb.h:213
PIRP NTAPI USBPORT_RemoveActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:357

Referenced by USBPORT_AbortEndpoint(), USBPORT_DmaEndpointWorker(), USBPORT_KillEndpointActiveTransfers(), and USBPORT_RootHubEndpointWorker().

◆ USBPORT_FlushController()

VOID NTAPI USBPORT_FlushController ( IN PDEVICE_OBJECT  FdoDevice)

Definition at line 1259 of file queue.c.

1260 {
1263  PUSBPORT_ENDPOINT Endpoint;
1264  ULONG KilledTransfers;
1265  PLIST_ENTRY EndpointList;
1266  KIRQL OldIrql;
1268 
1269  DPRINT_CORE("USBPORT_FlushController \n");
1270 
1271  FdoExtension = FdoDevice->DeviceExtension;
1272 
1273  EndpointList = &FdoExtension->EndpointList;
1274 
1275  while (TRUE)
1276  {
1277  KeAcquireSpinLock(&FdoExtension->EndpointListSpinLock, &OldIrql);
1278 
1280 
1281  Entry = EndpointList->Flink;
1282 
1283  if (!IsListEmpty(EndpointList))
1284  {
1285  while (Entry && Entry != EndpointList)
1286  {
1287  Endpoint = CONTAINING_RECORD(Entry,
1289  EndpointLink);
1290 
1291  if (Endpoint->StateLast != USBPORT_ENDPOINT_REMOVE &&
1292  Endpoint->StateLast != USBPORT_ENDPOINT_CLOSED)
1293  {
1294  InterlockedIncrement(&Endpoint->LockCounter);
1296  }
1297 
1298  Entry = Endpoint->EndpointLink.Flink;
1299  }
1300  }
1301 
1302  KeReleaseSpinLock(&FdoExtension->EndpointListSpinLock, OldIrql);
1303 
1304  KilledTransfers = 0;
1305  while (!IsListEmpty(&FlushList))
1306  {
1307  Endpoint = CONTAINING_RECORD(FlushList.Flink,
1309  FlushControllerLink);
1310 
1312 
1313  KilledTransfers += USBPORT_KillEndpointActiveTransfers(FdoDevice,
1314  Endpoint);
1315 
1316  InterlockedDecrement(&Endpoint->LockCounter);
1317  }
1318 
1319  if (!KilledTransfers)
1320  break;
1321 
1322  USBPORT_Wait(FdoDevice, 100);
1323  }
1324 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
LIST_ENTRY EndpointLink
Definition: usbport.h:231
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
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 USBPORT_ENDPOINT_REMOVE
Definition: usbmport.h:16
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
LIST_ENTRY FlushControllerLink
Definition: usbport.h:236
PSINGLE_LIST_ENTRY FlushList(PSINGLE_LIST_ENTRY ListHead)
Definition: ExSingleList.c:24
Definition: typedefs.h:117
#define InterlockedIncrement
Definition: armddk.h:53
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
ULONG NTAPI USBPORT_KillEndpointActiveTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:1227
base of all file and directory entries
Definition: entries.h:82
#define USBPORT_ENDPOINT_CLOSED
Definition: usbmport.h:17

Referenced by USBPORT_SuspendController().

◆ USBPORT_FlushPendingTransfers()

VOID NTAPI USBPORT_FlushPendingTransfers ( IN PUSBPORT_ENDPOINT  Endpoint)

Definition at line 785 of file queue.c.

786 {
787  PDEVICE_OBJECT FdoDevice;
789  BOOLEAN IsMapTransfer;
790  BOOLEAN IsEnd = FALSE;
792  PUSBPORT_TRANSFER Transfer;
793  PURB Urb;
794  PIRP Irp;
795  KIRQL OldIrql;
796  BOOLEAN Result;
797 
798  DPRINT_CORE("USBPORT_FlushPendingTransfers: Endpoint - %p\n", Endpoint);
799 
800  FdoDevice = Endpoint->FdoDevice;
801  FdoExtension = FdoDevice->DeviceExtension;
802 
803  if (InterlockedCompareExchange(&Endpoint->FlushPendingLock, 1, 0))
804  {
805  DPRINT_CORE("USBPORT_FlushPendingTransfers: Endpoint Locked \n");
806  return;
807  }
808 
809  while (TRUE)
810  {
811  IsMapTransfer = 0;
812 
813  KeAcquireSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
814  &OldIrql);
815 
816  KeAcquireSpinLockAtDpcLevel(&Endpoint->EndpointSpinLock);
817 
819  {
820  IsEnd = TRUE;
821 
822  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
823  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
824  OldIrql);
825  goto Next;
826  }
827 
828  if (!(Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0))
829  {
830  if (!IsListEmpty(&Endpoint->TransferList))
831  {
832  List = Endpoint->TransferList.Flink;
833 
834  while (List && List != &Endpoint->TransferList)
835  {
836  Transfer = CONTAINING_RECORD(List,
838  TransferLink);
839 
840  if (!(Transfer->Flags & TRANSFER_FLAG_SUBMITED))
841  {
842  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
843  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
844  OldIrql);
845 
846  IsEnd = TRUE;
847  goto Worker;
848  }
849 
850  List = Transfer->TransferLink.Flink;
851  }
852  }
853  }
854 
855  List = Endpoint->PendingTransferList.Flink;
856 
857  if (List == NULL || IsListEmpty(&Endpoint->PendingTransferList))
858  {
859  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
860  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
861  OldIrql);
862 
863  IsEnd = TRUE;
864  goto Worker;
865  }
866 
867  Transfer = CONTAINING_RECORD(List,
869  TransferLink);
870 
871  if (Transfer->Irp)
872  {
873  DPRINT_CORE("USBPORT_FlushPendingTransfers: Transfer->Irp->CancelRoutine - %p\n",
874  Transfer->Irp->CancelRoutine);
875  }
876 
877  if (Transfer->Irp &&
878  (IoSetCancelRoutine(Transfer->Irp, NULL) == NULL))
879  {
880  DPRINT_CORE("USBPORT_FlushPendingTransfers: Transfer->Irp - %p\n",
881  Transfer->Irp);
882 
883  Transfer = NULL;
884  IsEnd = TRUE;
885  }
886 
887  if (!Transfer)
888  {
889  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
890  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
891  OldIrql);
892 
893  if (IsMapTransfer)
894  {
895  USBPORT_FlushMapTransfers(FdoDevice);
896  goto Next;
897  }
898 
899  goto Worker;
900  }
901 
902  Irp = Transfer->Irp;
903  Urb = Transfer->Urb;
904 
905  RemoveEntryList(&Transfer->TransferLink);
906  Transfer->TransferLink.Flink = NULL;
907  Transfer->TransferLink.Blink = NULL;
908 
909  if (Irp)
910  {
912  }
913 
914  KeReleaseSpinLockFromDpcLevel(&Endpoint->EndpointSpinLock);
915  KeReleaseSpinLock(&FdoExtension->FlushPendingTransferSpinLock,
916  OldIrql);
917 
918  KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
919 
920  if (Irp)
921  {
923 
924  if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
925  {
926  DPRINT_CORE("USBPORT_FlushPendingTransfers: irp - %p\n", Irp);
927 
928  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock,
929  OldIrql);
930 
932  goto Worker;
933  }
934 
935  USBPORT_FindUrbInIrpTable(FdoExtension->ActiveIrpTable, Urb, Irp);
936  USBPORT_InsertIrpInTable(FdoExtension->ActiveIrpTable, Irp);
937  }
938 
939  IsMapTransfer = USBPORT_QueueActiveUrbToEndpoint(Endpoint, Urb);
940 
941  KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
942 
943  if (IsMapTransfer)
944  {
945  USBPORT_FlushMapTransfers(FdoDevice);
946  goto Next;
947  }
948 
949 Worker:
951  Result = USBPORT_EndpointWorker(Endpoint, FALSE);
953 
954  if (Result)
956  Endpoint,
958 
959 Next:
960  if (IsEnd)
961  {
962  InterlockedDecrement(&Endpoint->FlushPendingLock);
963  DPRINT_CORE("USBPORT_FlushPendingTransfers: Endpoint Unlocked. Exit\n");
964  return;
965  }
966  }
967 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2176
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
VOID NTAPI USBPORT_InsertIrpInTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
Definition: queue.c:266
_In_ PIRP Irp
Definition: csq.h:116
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
#define InterlockedCompareExchange
Definition: interlocked.h:104
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1658
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
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
BOOLEAN NTAPI USBPORT_QueueActiveUrbToEndpoint(IN PUSBPORT_ENDPOINT Endpoint, IN PURB Urb)
Definition: queue.c:988
LIST_ENTRY List
Definition: psmgr.c:57
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
VOID NTAPI USBPORT_FindUrbInIrpTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PURB Urb, IN PIRP Irp)
Definition: queue.c:381
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
PIRP NTAPI USBPORT_RemovePendingTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:369
Definition: typedefs.h:117
VOID NTAPI USBPORT_FlushMapTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:2461
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:70
Definition: usb.h:529
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define USBD_STATUS_CANCELED
Definition: usb.h:213
#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_CancelActiveTransferIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:529
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:132

Referenced by USBPORT_AbortEndpoint(), USBPORT_DpcHandler(), USBPORT_FlushAllEndpoints(), USBPORT_KillEndpointActiveTransfers(), and USBPORT_QueueTransferUrb().

◆ USBPORT_InsertBadRequest()

VOID NTAPI USBPORT_InsertBadRequest ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 143 of file queue.c.

145 {
147 
148  DPRINT_QUEUE("USBPORT_InsertBadRequest: Irp - %p\n", Irp);
149 
152  BadRequestIoCsq);
153 
154  InsertTailList(&FdoExtension->BadRequestList,
155  &Irp->Tail.Overlay.ListEntry);
156 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
#define InsertTailList(ListHead, Entry)
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
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_InsertIdleIrp()

VOID NTAPI USBPORT_InsertIdleIrp ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 20 of file queue.c.

22 {
24 
25  DPRINT_QUEUE("USBPORT_InsertIdleIrp: Irp - %p\n", Irp);
26 
29  IdleIoCsq);
30 
31  InsertTailList(&FdoExtension->IdleIrpList,
32  &Irp->Tail.Overlay.ListEntry);
33 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
#define InsertTailList(ListHead, Entry)
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
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_InsertIrpInTable()

VOID NTAPI USBPORT_InsertIrpInTable ( IN PUSBPORT_IRP_TABLE  IrpTable,
IN PIRP  Irp 
)

Definition at line 266 of file queue.c.

268 {
269  ULONG ix;
270 
271  DPRINT_CORE("USBPORT_InsertIrpInTable: IrpTable - %p, Irp - %p\n",
272  IrpTable,
273  Irp);
274 
275  ASSERT(IrpTable != NULL);
276 
277  while (TRUE)
278  {
279  for (ix = 0; ix < 0x200; ix++)
280  {
281  if (IrpTable->irp[ix] == NULL)
282  {
283  IrpTable->irp[ix] = Irp;
284 
285  if (ix > 0)
286  {
287  DPRINT_CORE("USBPORT_InsertIrpInTable: ix - %x\n", ix);
288  }
289 
290  return;
291  }
292  }
293 
294  if (ix != 0x200)
295  {
296  KeBugCheckEx(BUGCODE_USB_DRIVER, 1, 0, 0, 0);
297  }
298 
299  IrpTable->LinkNextTable = ExAllocatePoolWithTag(NonPagedPool,
300  sizeof(USBPORT_IRP_TABLE),
301  USB_PORT_TAG);
302 
303  if (IrpTable->LinkNextTable == NULL)
304  {
305  KeBugCheckEx(BUGCODE_USB_DRIVER, 1, 0, 0, 0);
306  }
307 
308  RtlZeroMemory(IrpTable->LinkNextTable, sizeof(USBPORT_IRP_TABLE));
309 
310  IrpTable = IrpTable->LinkNextTable;
311  }
312 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
#define USB_PORT_TAG
Definition: usbport.h:44
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

Referenced by USBPORT_FlushPendingTransfers(), and USBPORT_QueuePendingTransferIrp().

◆ USBPORT_KillEndpointActiveTransfers()

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

Definition at line 1227 of file queue.c.

1229 {
1230  PLIST_ENTRY ActiveList;
1231  PUSBPORT_TRANSFER Transfer;
1232  ULONG KilledTransfers = 0;
1233 
1234  DPRINT_CORE("USBPORT_KillEndpointActiveTransfers \n");
1235 
1236  ActiveList = Endpoint->TransferList.Flink;
1237 
1238  while (ActiveList && ActiveList != &Endpoint->TransferList)
1239  {
1240  ++KilledTransfers;
1241 
1242  Transfer = CONTAINING_RECORD(ActiveList,
1244  TransferLink);
1245 
1246  Transfer->Flags |= TRANSFER_FLAG_ABORTED;
1247 
1248  ActiveList = Transfer->TransferLink.Flink;
1249  }
1250 
1252  USBPORT_FlushCancelList(Endpoint);
1253 
1254  return KilledTransfers;
1255 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
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
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
Definition: typedefs.h:117
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI USBPORT_FlushCancelList(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:714

Referenced by USBPORT_FlushController().

◆ USBPORT_PeekNextBadRequest()

PIRP NTAPI USBPORT_PeekNextBadRequest ( IN PIO_CSQ  Csq,
IN PIRP  Irp,
IN PVOID  PeekContext 
)

Definition at line 169 of file queue.c.

172 {
174  PLIST_ENTRY NextEntry;
175  PLIST_ENTRY ListHead;
176  PIRP NextIrp = NULL;
177 
178  DPRINT_QUEUE("USBPORT_PeekNextBadRequest: Irp - %p, PeekContext - %p\n",
179  Irp,
180  PeekContext);
181 
184  BadRequestIoCsq);
185 
186  ListHead = &FdoExtension->BadRequestList;
187 
188  if (Irp)
189  {
190  NextEntry = Irp->Tail.Overlay.ListEntry.Flink;
191  }
192  else
193  {
194  NextEntry = ListHead->Flink;
195  }
196 
197  while (NextEntry != ListHead)
198  {
199  NextIrp = CONTAINING_RECORD(NextEntry,
200  IRP,
201  Tail.Overlay.ListEntry);
202 
203  if (!PeekContext)
204  break;
205 
206  NextEntry = NextEntry->Flink;
207  }
208 
209  return NextIrp;
210 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
IRP
Definition: iotypes.h:2462
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:159
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_PeekNextIdleIrp()

PIRP NTAPI USBPORT_PeekNextIdleIrp ( IN PIO_CSQ  Csq,
IN PIRP  Irp,
IN PVOID  PeekContext 
)

Definition at line 46 of file queue.c.

49 {
51  PLIST_ENTRY NextEntry;
52  PLIST_ENTRY ListHead;
53  PIRP NextIrp = NULL;
54 
55  DPRINT_QUEUE("USBPORT_PeekNextIdleIrp: Irp - %p, PeekContext - %p\n",
56  Irp,
57  PeekContext);
58 
61  IdleIoCsq);
62 
63  ListHead = &FdoExtension->IdleIrpList;
64 
65  if (Irp)
66  {
67  NextEntry = Irp->Tail.Overlay.ListEntry.Flink;
68  }
69  else
70  {
71  NextEntry = ListHead->Flink;
72  }
73 
74  while (NextEntry != ListHead)
75  {
76  NextIrp = CONTAINING_RECORD(NextEntry,
77  IRP,
78  Tail.Overlay.ListEntry);
79 
80  if (!PeekContext)
81  break;
82 
83  NextEntry = NextEntry->Flink;
84  }
85 
86  return NextIrp;
87 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
IRP
Definition: iotypes.h:2462
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:159
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_QueueActiveUrbToEndpoint()

BOOLEAN NTAPI USBPORT_QueueActiveUrbToEndpoint ( IN PUSBPORT_ENDPOINT  Endpoint,
IN PURB  Urb 
)

Definition at line 988 of file queue.c.

990 {
991  PUSBPORT_TRANSFER Transfer;
992  PDEVICE_OBJECT FdoDevice;
995  KIRQL OldIrql;
996 
997  DPRINT_CORE("USBPORT_QueueActiveUrbToEndpoint: Endpoint - %p, Urb - %p\n",
998  Endpoint,
999  Urb);
1000 
1001  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
1002  FdoDevice = Endpoint->FdoDevice;
1003  FdoExtension = FdoDevice->DeviceExtension;
1004 
1005  KeAcquireSpinLock(&Endpoint->EndpointSpinLock,
1006  &Endpoint->EndpointOldIrql);
1007 
1008  if ((Endpoint->Flags & ENDPOINT_FLAG_NUKE) ||
1009  (Transfer->Flags & TRANSFER_FLAG_ABORTED))
1010  {
1011  InsertTailList(&Endpoint->CancelList, &Transfer->TransferLink);
1012 
1013  KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
1014  Endpoint->EndpointOldIrql);
1015 
1016  //DPRINT_CORE("USBPORT_QueueActiveUrbToEndpoint: return FALSE\n");
1017  return FALSE;
1018  }
1019 
1020  if (Transfer->TransferParameters.TransferBufferLength == 0 ||
1021  !(Endpoint->Flags & ENDPOINT_FLAG_DMA_TYPE))
1022  {
1023  InsertTailList(&Endpoint->TransferList, &Transfer->TransferLink);
1024 
1025  KeReleaseSpinLock(&Endpoint->EndpointSpinLock,
1026  Endpoint->EndpointOldIrql);
1027 
1028  //DPRINT_CORE("USBPORT_QueueActiveUrbToEndpoint: return FALSE\n");
1029  return FALSE;
1030  }
1031 
1032  KeReleaseSpinLock(&Endpoint->EndpointSpinLock, Endpoint->EndpointOldIrql);
1033 
1034  KeAcquireSpinLock(&FdoExtension->MapTransferSpinLock, &OldIrql);
1035 
1036  InsertTailList(&FdoExtension->MapTransferList, &Transfer->TransferLink);
1037 
1038  DeviceHandle = Transfer->Urb->UrbHeader.UsbdDeviceHandle;
1039  InterlockedIncrement(&DeviceHandle->DeviceHandleLock);
1040 
1041  KeReleaseSpinLock(&FdoExtension->MapTransferSpinLock, OldIrql);
1042 
1043  //DPRINT_CORE("USBPORT_QueueActiveUrbToEndpoint: return TRUE\n");
1044  return TRUE;
1045 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:253
#define InsertTailList(ListHead, Entry)
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define ENDPOINT_FLAG_DMA_TYPE
Definition: usbport.h:110
struct _URB_HEADER UrbHeader
Definition: usb.h:531
LIST_ENTRY TransferLink
Definition: usbport.h:256
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define TRANSFER_FLAG_ABORTED
Definition: usbport.h:133
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define InterlockedIncrement
Definition: armddk.h:53
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by USBPORT_FlushPendingTransfers().

◆ USBPORT_QueuePendingTransferIrp()

VOID NTAPI USBPORT_QueuePendingTransferIrp ( IN PIRP  Irp)

Definition at line 1049 of file queue.c.

1050 {
1051  PURB Urb;
1052  PUSBPORT_TRANSFER Transfer;
1053  PUSBPORT_ENDPOINT Endpoint;
1054  PDEVICE_OBJECT FdoDevice;
1056 
1057  DPRINT_CORE("USBPORT_QueuePendingTransferIrp: Irp - %p\n", Irp);
1058 
1059  Urb = URB_FROM_IRP(Irp);
1060 
1061  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
1062  Endpoint = Transfer->Endpoint;
1063 
1064  FdoDevice = Endpoint->FdoDevice;
1065  FdoExtension = FdoDevice->DeviceExtension;
1066 
1067  Irp->IoStatus.Status = STATUS_PENDING;
1069 
1071 
1072  if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
1073  {
1075  }
1076  else
1077  {
1078  USBPORT_InsertIrpInTable(FdoExtension->PendingIrpTable, Irp);
1079  USBPORT_QueuePendingUrbToEndpoint(Endpoint, Urb);
1080  }
1081 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2176
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
VOID NTAPI USBPORT_InsertIrpInTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
Definition: queue.c:266
_In_ PIRP Irp
Definition: csq.h:116
IoSetCancelRoutine(Irp, CancelRoutine)
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:205
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI USBPORT_QueuePendingUrbToEndpoint(IN PUSBPORT_ENDPOINT Endpoint, IN PURB Urb)
Definition: queue.c:971
VOID NTAPI USBPORT_CancelPendingTransferIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:479
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:252
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
Definition: usb.h:529
#define USBD_STATUS_CANCELED
Definition: usb.h:213
IoMarkIrpPending(Irp)

Referenced by USBPORT_QueueTransferUrb().

◆ USBPORT_QueuePendingUrbToEndpoint()

VOID NTAPI USBPORT_QueuePendingUrbToEndpoint ( IN PUSBPORT_ENDPOINT  Endpoint,
IN PURB  Urb 
)

Definition at line 971 of file queue.c.

973 {
974  PUSBPORT_TRANSFER Transfer;
975 
976  DPRINT_CORE("USBPORT_QueuePendingUrbToEndpoint: Endpoint - %p, Urb - %p\n",
977  Endpoint,
978  Urb);
979 
980  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
981  //FIXME USBPORT_ResetEndpointIdle();
982  InsertTailList(&Endpoint->PendingTransferList, &Transfer->TransferLink);
983  Urb->UrbHeader.Status = USBD_STATUS_PENDING;
984 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define USBD_STATUS_PENDING
Definition: usb.h:171
#define InsertTailList(ListHead, Entry)
LIST_ENTRY TransferLink
Definition: usbport.h:256

Referenced by USBPORT_QueuePendingTransferIrp(), and USBPORT_QueueTransferUrb().

◆ USBPORT_QueueTransferUrb()

VOID NTAPI USBPORT_QueueTransferUrb ( IN PURB  Urb)

Definition at line 1085 of file queue.c.

1086 {
1087  PUSBPORT_TRANSFER Transfer;
1088  PUSBPORT_ENDPOINT Endpoint;
1089  PIRP Irp;
1092 
1093  DPRINT_CORE("USBPORT_QueueTransferUrb: Urb - %p\n", Urb);
1094 
1095  if (Urb->UrbControlTransfer.TransferFlags & USBD_DEFAULT_PIPE_TRANSFER)
1096  Urb->UrbHeader.Function = URB_FUNCTION_CONTROL_TRANSFER;
1097 
1098  Transfer = Urb->UrbControlTransfer.hca.Reserved8[0];
1099  Parameters = &Transfer->TransferParameters;
1100 
1101  Endpoint = Transfer->Endpoint;
1102  Endpoint->Flags &= ~ENDPOINT_FLAG_QUEUENE_EMPTY;
1103 
1104  Parameters->TransferBufferLength = Urb->UrbControlTransfer.TransferBufferLength;
1105  Parameters->TransferFlags = Urb->UrbControlTransfer.TransferFlags;
1106 
1107  Transfer->TransferBufferMDL = Urb->UrbControlTransfer.TransferBufferMDL;
1108 
1109  if (Urb->UrbControlTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
1110  {
1112  }
1113  else
1114  {
1116  }
1117 
1119  {
1120  RtlCopyMemory(&Parameters->SetupPacket,
1121  Urb->UrbControlTransfer.SetupPacket,
1123  }
1124 
1125  DPRINT_URB("... URB TransferBufferLength - %x\n",
1126  Urb->UrbControlTransfer.TransferBufferLength);
1127 
1128  Urb->UrbControlTransfer.TransferBufferLength = 0;
1129 
1130  Irp = Transfer->Irp;
1131 
1132  if (Irp)
1133  {
1135  }
1136  else
1137  {
1138  USBPORT_QueuePendingUrbToEndpoint(Endpoint, Urb);
1139  }
1140 
1141  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
1142  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
1143 
1145 
1146  DPRINT_URB("... URB TransferBufferLength - %x\n",
1147  Urb->UrbControlTransfer.TransferBufferLength);
1148 
1149  if (Urb->UrbControlTransfer.TransferBufferLength)
1150  {
1151  PULONG Buffer;
1154  ULONG ix;
1155 
1156  Buffer = Urb->UrbControlTransfer.TransferBuffer;
1157  BufferLength = Urb->UrbControlTransfer.TransferBufferLength;
1159 
1160  DPRINT_URB("URB TransferBuffer - %p\n", Buffer);
1161 
1162  for (ix = 0; (ULONG_PTR)(Buffer + ix) < BufferEnd; ix++)
1163  {
1164  DPRINT_URB("Buffer[%02X] - %p\n", ix, Buffer[ix]);
1165  }
1166  }
1167 }
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI USBPORT_QueuePendingTransferIrp(IN PIRP Irp)
Definition: queue.c:1049
#define DPRINT_URB(...)
Definition: usbdebug.h:145
#define ENDPOINT_FLAG_QUEUENE_EMPTY
Definition: usbport.h:113
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:253
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
PMDL TransferBufferMDL
Definition: usbport.h:254
#define USBPORT_TRANSFER_TYPE_CONTROL
Definition: usbmport.h:8
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG BufferLength
Definition: usbdlib.h:225
VOID NTAPI USBPORT_QueuePendingUrbToEndpoint(IN PUSBPORT_ENDPOINT Endpoint, IN PURB Urb)
Definition: queue.c:971
Definition: bufpool.h:45
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:252
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:871
#define InterlockedDecrement
Definition: armddk.h:52
_In_ PUCHAR BufferEnd
Definition: usbdlib.h:176
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
#define USBD_DEFAULT_PIPE_TRANSFER
Definition: usb.h:156
unsigned int * PULONG
Definition: retypes.h:1
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define USBPORT_DMA_DIRECTION_FROM_DEVICE
Definition: usbport.h:41

Referenced by USBPORT_HandleDataTransfers(), USBPORT_HandleGetConfiguration(), USBPORT_HandleGetSetDescriptor(), USBPORT_HandleGetStatus(), USBPORT_HandleSetOrClearFeature(), USBPORT_HandleVendorOrClass(), and USBPORT_SendSetupPacket().

◆ USBPORT_ReleaseBadRequestLock()

VOID NTAPI USBPORT_ReleaseBadRequestLock ( IN PIO_CSQ  Csq,
IN KIRQL  Irql 
)

Definition at line 230 of file queue.c.

232 {
234 
235  DPRINT_QUEUE("USBPORT_ReleaseBadRequestLock: ... \n");
236 
239  BadRequestIoCsq);
240 
241  KeReleaseSpinLock(&FdoExtension->BadRequestIoCsqSpinLock, Irql);
242 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_Out_ PKIRQL Irql
Definition: csq.h:179
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 KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_ReleaseIdleLock()

VOID NTAPI USBPORT_ReleaseIdleLock ( IN PIO_CSQ  Csq,
IN KIRQL  Irql 
)

Definition at line 107 of file queue.c.

109 {
111 
112  DPRINT_QUEUE("USBPORT_ReleaseIdleLock: ... \n");
113 
116  IdleIoCsq);
117 
118  KeReleaseSpinLock(&FdoExtension->IdleIoCsqSpinLock, Irql);
119 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_Out_ PKIRQL Irql
Definition: csq.h:179
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 KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
IO_CSQ Csq
Definition: csqrtns.c:46

Referenced by USBPORT_StartDevice().

◆ USBPORT_RemoveActiveTransferIrp()

PIRP NTAPI USBPORT_RemoveActiveTransferIrp ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 357 of file queue.c.

359 {
361 
362  DPRINT_CORE("USBPORT_RemoveActiveTransferIrp: Irp - %p\n", Irp);
363  FdoExtension = FdoDevice->DeviceExtension;
364  return USBPORT_RemoveIrpFromTable(FdoExtension->ActiveIrpTable, Irp);
365 }
PIRP NTAPI USBPORT_RemoveIrpFromTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
Definition: queue.c:316
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIRP Irp
Definition: csq.h:116

Referenced by USBPORT_DoneTransfer(), and USBPORT_FlushCancelList().

◆ USBPORT_RemoveBadRequest()

VOID NTAPI USBPORT_RemoveBadRequest ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 160 of file queue.c.

162 {
163  DPRINT_QUEUE("USBPORT_RemoveBadRequest: Irp - %p\n", Irp);
164  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
165 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105

Referenced by USBPORT_StartDevice().

◆ USBPORT_RemoveIdleIrp()

VOID NTAPI USBPORT_RemoveIdleIrp ( IN PIO_CSQ  Csq,
IN PIRP  Irp 
)

Definition at line 37 of file queue.c.

39 {
40  DPRINT_QUEUE("USBPORT_RemoveIdleIrp: Irp - %p\n", Irp);
41  RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
42 }
#define DPRINT_QUEUE(...)
Definition: usbdebug.h:148
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105

Referenced by USBPORT_StartDevice().

◆ USBPORT_RemoveIrpFromTable()

PIRP NTAPI USBPORT_RemoveIrpFromTable ( IN PUSBPORT_IRP_TABLE  IrpTable,
IN PIRP  Irp 
)

Definition at line 316 of file queue.c.

318 {
319  ULONG ix;
320 
321  DPRINT_CORE("USBPORT_RemoveIrpFromTable: IrpTable - %p, Irp - %p\n",
322  IrpTable,
323  Irp);
324 
325  ASSERT(IrpTable != NULL);
326 
327  while (TRUE)
328  {
329  for (ix = 0; ix < 0x200; ix++)
330  {
331  if (IrpTable->irp[ix] == Irp)
332  {
333  IrpTable->irp[ix] = NULL;
334 
335  if (ix > 0)
336  {
337  DPRINT_CORE("USBPORT_RemoveIrpFromTable: ix - %x\n", ix);
338  }
339 
340  return Irp;
341  }
342  }
343 
344  if (IrpTable->LinkNextTable == NULL)
345  break;
346 
347  IrpTable = IrpTable->LinkNextTable;
348  continue;
349  }
350 
351  DPRINT1("USBPORT_RemoveIrpFromTable: return NULL. ix - %x\n", ix);
352  return NULL;
353 }
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBPORT_RemoveActiveTransferIrp(), and USBPORT_RemovePendingTransferIrp().

◆ USBPORT_RemovePendingTransferIrp()

PIRP NTAPI USBPORT_RemovePendingTransferIrp ( IN PDEVICE_OBJECT  FdoDevice,
IN PIRP  Irp 
)

Definition at line 369 of file queue.c.

371 {
373 
374  DPRINT_CORE("USBPORT_RemovePendingTransferIrp: Irp - %p\n", Irp);
375  FdoExtension = FdoDevice->DeviceExtension;
376  return USBPORT_RemoveIrpFromTable(FdoExtension->PendingIrpTable, Irp);
377 }
PIRP NTAPI USBPORT_RemoveIrpFromTable(IN PUSBPORT_IRP_TABLE IrpTable, IN PIRP Irp)
Definition: queue.c:316
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
_In_ PIRP Irp
Definition: csq.h:116

Referenced by USBPORT_CancelPendingTransferIrp(), and USBPORT_FlushPendingTransfers().