ReactOS 0.4.16-dev-1946-g52006dd
FxUsbPipeContinuousReader Struct Reference

#include <fxusbpipe.hpp>

Inheritance diagram for FxUsbPipeContinuousReader:
Collaboration diagram for FxUsbPipeContinuousReader:

Public Member Functions

 FxUsbPipeContinuousReader (__in FxUsbPipe *Pipe, __in UCHAR NumReaders)
 
 ~FxUsbPipeContinuousReader ()
 
_Must_inspect_result_ NTSTATUS Config (__in PWDF_USB_CONTINUOUS_READER_CONFIG Config, __in size_t TotalBufferLength)
 
PVOID operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __range(1, NUM_PENDING_READS_MAX) ULONG NumReaders)
 
_Must_inspect_result_ NTSTATUS FormatRepeater (__in FxUsbPipeRepeatReader *Repeater)
 
VOID CancelRepeaters (VOID)
 
ULONG ResubmitRepeater (__in FxUsbPipeRepeatReader *Repeater, __out NTSTATUS *Status)
 
- Public Member Functions inherited from FxStump
PVOID operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
PVOID operator new (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals, __in POOL_TYPE PoolType)
 
VOID operator delete (__in PVOID pointer)
 
PVOID operator new[] (__in size_t Size, __in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
VOID operator delete[] (__in PVOID pointer)
 

Public Attributes

PFN_WDF_USB_READER_COMPLETION_ROUTINE m_ReadCompleteCallback
 
WDFCONTEXT m_ReadCompleteContext
 
PFN_WDF_USB_READERS_FAILED m_ReadersFailedCallback
 
FxUsbPipem_Pipe
 
FxLookasideListm_Lookaside
 
MdDeviceObject m_TargetDevice
 
WDFMEMORY_OFFSET m_Offsets
 
FxSystemWorkItemm_WorkItem
 
PVOID m_WorkItemRerunContext
 
volatile POINTER_ALIGNMENT MxThread m_WorkItemThread
 
ULONG m_WorkItemFlags
 
UCHAR m_NumFailedReaders
 
UCHAR m_NumReaders
 
BOOLEAN m_WorkItemQueued
 
BOOLEAN m_ReadersSubmitted
 
FxUsbPipeRepeatReader m_Readers [1]
 

Protected Member Functions

VOID DeleteMemory (__in FxRequestBase *Request)
 
BOOLEAN QueueWorkItemLocked (__in FxUsbPipeRepeatReader *Repeater)
 
__inline VOID FxUsbPipeRequestWorkItemHandler (__in FxUsbPipeRepeatReader *FailedRepeater)
 
- Protected Member Functions inherited from FxStump
 FxStump (VOID)
 

Static Protected Attributes

static MdDeferredRoutineType _FxUsbPipeContinuousReadDpc
 
static MX_WORKITEM_ROUTINE _ReadWorkItem
 
static EVT_WDF_REQUEST_COMPLETION_ROUTINE _FxUsbPipeRequestComplete
 
static EVT_SYSTEMWORKITEM _FxUsbPipeRequestWorkItemThunk
 

Detailed Description

Definition at line 234 of file fxusbpipe.hpp.

Constructor & Destructor Documentation

◆ FxUsbPipeContinuousReader()

FxUsbPipeContinuousReader::FxUsbPipeContinuousReader ( __in FxUsbPipe Pipe,
__in UCHAR  NumReaders 
)

Definition at line 32 of file fxusbpipe.cpp.

35 :
36 m_NumReaders(NumReaders),
38{
45
47 m_Pipe = Pipe;
48
50
52}
__inline MdDeviceObject GetTargetDevice(VOID)
Definition: fxiotarget.hpp:272
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
FxUsbPipeRepeatReader m_Readers[1]
Definition: fxusbpipe.hpp:406
MdDeviceObject m_TargetDevice
Definition: fxusbpipe.hpp:350
FxLookasideList * m_Lookaside
Definition: fxusbpipe.hpp:345
volatile POINTER_ALIGNMENT MxThread m_WorkItemThread
Definition: fxusbpipe.hpp:372
FxSystemWorkItem * m_WorkItem
Definition: fxusbpipe.hpp:360
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ WDFUSBPIPE Pipe
Definition: wdfusb.h:1741

◆ ~FxUsbPipeContinuousReader()

FxUsbPipeContinuousReader::~FxUsbPipeContinuousReader ( )

Definition at line 54 of file fxusbpipe.cpp.

55{
56 LONG i;
57
59
60 //
61 // It is impoortant to delete the requests before the lookaside because the
62 // requests may have outstanding references on memory objects allocated by
63 // the lookaside. The lookaside will not be truly deleted until the oustanding
64 // memory object allocations are also freed.
65 //
66 for (i = 0; i < m_NumReaders; i++) {
67 if (reader[i].Request != NULL) {
69
70 reader[i].Request->DeleteObject();
71 reader[i].Request = NULL;
72 }
73
74#if (FX_CORE_MODE == FX_CORE_USER_MODE)
75 reader[i].ReadCompletedEvent.Uninitialize();
76 reader[i].m_ReadWorkItem.Free();
77#endif
78 }
79
80 if (m_Lookaside != NULL) {
82 }
83
84 if (m_WorkItem != NULL) {
87 }
88}
virtual VOID DeleteObject(VOID)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
VOID DeleteMemory(__in FxRequestBase *Request)
Definition: fxusbpipe.hpp:276
Definition: reader.h:84
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Member Function Documentation

◆ CancelRepeaters()

VOID FxUsbPipeContinuousReader::CancelRepeaters ( VOID  )

Definition at line 770 of file fxusbpipe.cpp.

773{
774 LONG i;
775
776 Mx::MxEnterCriticalRegion();
777
778 for (i = 0; i < m_NumReaders; i++) {
781 m_Readers[i].ReadCompletedEvent.GetSelfPointer(),
782 "waiting for continuous reader to finish, WDFUSBPIPE",
783 m_Pipe->GetHandle(),
786
787 }
788
789 Mx::MxLeaveCriticalRegion();
790 //
791 // Checking for IO Count <= 1 is not a good idea here because there could be always other IO
792 // besides that from the continous reader going on the Read Pipe.
793 //
794}
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
BOOLEAN Cancel(VOID)
WDFUSBPIPE GetHandle(VOID)
Definition: fxusbpipe.hpp:504
@ WaitSignalBreakUnderVerifier
Definition: fxglobals.h:84
ULONG FxVerifierDbgWaitForSignalTimeoutInSec
Definition: fxglobals.h:527
VOID WaitForSignal(__in MxEvent *Event, __in PCSTR ReasonForWaiting, __in PVOID Handle, __in ULONG WarningTimeoutInSec, __in ULONG WaitSignalFlags)
Definition: globals.cpp:1703

Referenced by FxUsbPipeRequestWorkItemHandler(), FxUsbPipe::Reset(), and FxUsbPipe::WaitForSentIoToComplete().

◆ Config()

_Must_inspect_result_ NTSTATUS FxUsbPipeContinuousReader::Config ( __in PWDF_USB_CONTINUOUS_READER_CONFIG  Config,
__in size_t  TotalBufferLength 
)

Definition at line 92 of file fxusbpipekm.cpp.

96{
98 WDF_OBJECT_ATTRIBUTES attributes;
100 LONG i;
101
103
104 if (TotalBufferLength <= MAXUSHORT) {
107 }
108 else {
111 }
112
113 if (m_Lookaside == NULL) {
115 }
116
117 if (Config->BufferAttributes == NULL) {
118 WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
119 }
120 else {
121 RtlCopyMemory(&attributes,
122 Config->BufferAttributes,
123 sizeof(WDF_OBJECT_ATTRIBUTES));
124 }
125
126 //
127 // By specifying the loookaside as the parent for the memory objects that
128 // will be created, when we destroy the lookaside list, we will destroy any
129 // outstanding memory objects that have been allocated. This can happen if
130 // we initialize the repeater, but never send any i/o. (Normally the
131 // memory object would be freed when the read completes.)
132 //
134
135 status = m_Lookaside->Initialize(TotalBufferLength, &attributes);
136 if (!NT_SUCCESS(status)) {
137 return status;
138 }
139
143 );
144 if (!NT_SUCCESS(status)) {
146 "Could not allocate workitem: %!STATUS!", status);
147 return status;
148 }
149
150 m_Offsets.BufferLength = Config->TransferLength;
151 m_Offsets.BufferOffset = Config->HeaderLength;
152
153 for (i = 0; i < m_NumReaders; i++) {
154 FxUsbPipeRepeatReader* pRepeater;
155
156 pRepeater = &m_Readers[i];
157
158 pRepeater->Parent = this;
159
161
162 //
163 // This will allocate the PIRP
164 //
167 NULL,
168 m_Pipe,
171 &pRepeater->Request);
172
173 if (!NT_SUCCESS(status)) {
174 return status;
175 }
176
177 pRepeater->RequestIrp = pRepeater->Request->GetSubmitIrp();
178
179 //
180 // Initialize the event before FormatRepeater clears it
181 //
183
184 if (!NT_SUCCESS(status)) {
187 "Could not initialize ReadCompletedEvent: %!STATUS!",
188 status);
189
190 return status;
191 }
192
193 //
194 // This will allocate the context
195 //
196 status = FormatRepeater(pRepeater);
197
198 if (!NT_SUCCESS(status)) {
199 return status;
200 }
201 }
202
203 return STATUS_SUCCESS;
204}
LONG NTSTATUS
Definition: precomp.h:26
MdDeviceObject __inline GetDeviceObject(VOID)
Definition: fxdevice.hpp:174
virtual _Must_inspect_result_ NTSTATUS Initialize(__in size_t BufferSize, __in PWDF_OBJECT_ATTRIBUTES MemoryAttributes)=0
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
CfxDevice * m_Device
Definition: fxobject.hpp:329
__inline MdIrp GetSubmitIrp(VOID)
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES RequestAttributes, __in_opt MdIrp Irp, __in_opt FxIoTarget *Target, __in FxRequestIrpOwnership Ownership, __in FxRequestConstructorCaller Caller, __deref_out FxRequest **Request)
Definition: fxrequest.cpp:161
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID WdmObject, __out FxSystemWorkItem **pObject)
CHECK_RETURN_IF_USER_MODE __inline NTSTATUS Initialize(__in EVENT_TYPE Type, __in BOOLEAN InitialState)
Definition: mxeventkm.h:55
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define TRACINGIO
Definition: dbgtrace.h:66
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
@ FxRequestConstructorCallerIsFx
@ FxRequestOwnsIrp
@ NotificationEvent
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
_Must_inspect_result_ NTSTATUS FormatRepeater(__in FxUsbPipeRepeatReader *Repeater)
Definition: fxusbpipe.cpp:689
static MdDeferredRoutineType _FxUsbPipeContinuousReadDpc
Definition: fxusbpipe.hpp:306
WDFMEMORY_OFFSET m_Offsets
Definition: fxusbpipe.hpp:355
FxUsbPipeContinuousReader * Parent
Definition: fxusbpipe.hpp:194
size_t BufferOffset
Definition: wdfmemory.h:65
size_t BufferLength
Definition: wdfmemory.h:72
WDFOBJECT ParentObject
Definition: wdfobject.h:130
Definition: ps.c:97
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define MAXUSHORT
Definition: typedefs.h:83
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476
FORCEINLINE VOID WDF_OBJECT_ATTRIBUTES_INIT(_Out_ PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: wdfobject.h:147
#define WDF_NO_OBJECT_ATTRIBUTES
Definition: wdftypes.h:105

Referenced by FxUsbPipe::InitContinuousReader().

◆ DeleteMemory()

VOID FxUsbPipeContinuousReader::DeleteMemory ( __in FxRequestBase Request)
inlineprotected

Definition at line 276 of file fxusbpipe.hpp.

279 {
280 FxRequestContext* pContext;
281
282 pContext = Request->GetContext();
283 if (pContext != NULL && pContext->m_RequestMemory != NULL) {
284 pContext->m_RequestMemory->Delete();
285 //
286 // NOTE: Don't NULL out the m_RequestMemory member as this will
287 // prevent Reuse from releasing a reference on the m_RequestMemory object
288 // and hence these memory objects will not be freed.
289 //
290 }
291 }
virtual VOID Delete(VOID)=0
IFxMemory * m_RequestMemory

Referenced by FormatRepeater(), and ~FxUsbPipeContinuousReader().

◆ FormatRepeater()

_Must_inspect_result_ NTSTATUS FxUsbPipeContinuousReader::FormatRepeater ( __in FxUsbPipeRepeatReader Repeater)

Definition at line 689 of file fxusbpipe.cpp.

692{
695 FxUsbPipeTransferContext* pContext;
699
700 pRequest = Repeater->Request;
701 //
702 // The repeater owns the request memory. If there is a memory on the
703 // context, delete it now. the memory will still be referencable since
704 // it will still have a reference against it until FormatTransferRequest is
705 // called or the request is freed and the context releases its references
706 //
708
710
712
713 //
714 // pMemory will be deleted when either
715 // a) The request completes
716 // or
717 // b) The continuous reader is destroyed and we delete the lookaside. since
718 // the lookaside is the parent object for pMemory, pMemory will be disposed
719 // of when the parent is Disposed
720 //
722 if (!NT_SUCCESS(status)) {
723 FxRequestContext* pContext;
724
725 pContext = pRequest->GetContext();
726 if (pContext != NULL ) {
727 pContext->m_RequestMemory = NULL;
728 }
729
731 }
732
734
735 buf.SetMemory(pMemory, &m_Offsets);
736
738 pRequest,
739 &buf,
741 );
742
743 if (!NT_SUCCESS(status)) {
744 //
745 // In the case of failure, the context in the request will delete the
746 // memory. If there is no context, delete the memory here.
747 //
748 if (pRequest->GetContext() == NULL) {
749 //
750 // Use DeleteFromFailedCreate because the driver never saw the
751 // buffer, so they shouldn't be told about it going away.
752 //
754 }
755
756 return status;
757 }
758
760 pContext->SetUsbType(WdfUsbRequestTypePipeRead);
761 pContext->m_UsbParameters.Parameters.PipeRead.Buffer = (WDFMEMORY)
763
765 return status;
766}
virtual _Must_inspect_result_ NTSTATUS Allocate(__out FxMemoryObject **PPMemory)=0
virtual size_t GetBufferSize(VOID)
VOID DeleteFromFailedCreate(VOID)
Definition: fxobject.cpp:391
__inline FxRequestContext * GetContext(VOID)
__inline VOID SetCompletionRoutine(__in_opt PFN_WDF_REQUEST_COMPLETION_ROUTINE CompletionRoutine=NULL, __in_opt WDFCONTEXT CompletionContext=NULL)
_Must_inspect_result_ NTSTATUS Reuse(__in PWDF_REQUEST_REUSE_PARAMS ReuseParams)
Definition: fxrequest.cpp:2136
_Must_inspect_result_ NTSTATUS FormatTransferRequest(__in FxRequestBase *Request, __in FxRequestBuffer *Buffer, __in ULONG TransferFlags=0)
virtual PVOID GetBuffer(VOID)=0
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
FxRequest * pRequest
FxMemoryObject * pMemory
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static EVT_WDF_REQUEST_COMPLETION_ROUTINE _FxUsbPipeRequestComplete
Definition: fxusbpipe.hpp:315
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
FORCEINLINE VOID WDF_REQUEST_REUSE_PARAMS_INIT(_Out_ PWDF_REQUEST_REUSE_PARAMS Params, _In_ ULONG Flags, _In_ NTSTATUS Status)
Definition: wdfrequest.h:364
@ WdfUsbRequestTypePipeRead
Definition: wdfusb.h:93

Referenced by Config(), FxUsbPipe::GotoStartState(), and ResubmitRepeater().

◆ FxUsbPipeRequestWorkItemHandler()

VOID FxUsbPipeContinuousReader::FxUsbPipeRequestWorkItemHandler ( __in FxUsbPipeRepeatReader FailedRepeater)
protected

Definition at line 397 of file fxusbpipe.cpp.

400{
402 NTSTATUS status, failedStatus;
403 USBD_STATUS usbdStatus;
404 LONG i;
405 KIRQL irql;
408 PWDF_USB_REQUEST_COMPLETION_PARAMS usbCompletionParams;
410
412
413 //
414 // Get failed info.
415 //
416 failedStatus = FailedRepeater->Request->GetStatus();
417
418 //
419 // Context is allocated at config time and gets reused so context
420 // will never be NULL.
421 //
422 context = FailedRepeater->Request->GetContext();
423 usbCompletionParams = context->m_CompletionParams.Parameters.Usb.Completion;
424
425 //
426 // In case FormatRepeater fails to allocate memory usbCompletionParams
427 // pointer is not set.
428 //
429 // usbCompletionParams are part of the context and
430 // not really allocated at the time of every Format but
431 // the pointer gets cleared by request->Reuse and gets set again by
432 // context->SetUsbType.
433 //
434 // In FormatRepeater, context->SetUsbType is skipped
435 // if a memory failure occurs before this step.
436 //
437 // Hence retrieve usbdStatus only when usbCompletionParams is set.
438 //
439 if (usbCompletionParams) {
440 usbdStatus = usbCompletionParams->UsbdStatus;
441 }
442 else {
443 //
444 // Set usbdStatus to success as we didn't receive a failure from
445 // USB stack.
446 //
447 // This path is reached during memory allocation failure. In such
448 // case failedStatus would already be set appropriately. (usbdStatus
449 // and failedStatus are passed to m_ReadersFailedCallback below.)
450 //
451 usbdStatus = STATUS_SUCCESS;
452 }
453
454 //
455 // No read requests should be in progress when the framework calls the
456 // EvtUsbTargetPipeReadersFailed callback function. This is part of the
457 // contract so that the Driver doesn't need to bother with the
458 // Completion calllback while taking corrective action.
459 //
462
464 //
465 // Save the current thread object pointer. This value is
466 // used for not deadlocking when misbehaved drivers (< v1.9) call
467 // WdfIoTargetStop from EvtUsbTargetPipeReadersFailed callback
468 //
471
473 (WDFUSBPIPE) m_Pipe->GetHandle(),
474 failedStatus,
475 usbdStatus
476 );
477
479 }
480 else {
481 //
482 // By default, we restart the readers
483 //
484 restart = TRUE;
485 }
486
487 if (restart) {
488 status = pDevice->IsConnected();
489
490 if (NT_SUCCESS(status)) {
491
492 //
493 // for v1.9 or higher use the error recovery procedure prescribed
494 // by the USB team.
495 //
497
498 if (pDevice->IsEnabled()) {
499 //
500 // Reset the pipe if port status is enabled
501 //
502 m_Pipe->Reset();
503 }
504 else {
505 //
506 // Reset the device if port status is disabled
507 //
508 status = pDevice->Reset();
509 }
510 }
511 else {
512 //
513 // Reset the device if port status is disabled
514 //
515 status = pDevice->Reset();
516 }
517 }
518 else {
519 //
520 // if port status is disconnected we would get back
521 // a !NT_SUCCESS. This would mean that we would not
522 // send the readers again and treat it like a failed reader.
523 //
524 DO_NOTHING();
525 }
526
527 }
528 else {
529 //
530 // By setting status to !NT_SUCCESS, we will not send the readers
531 // again and treat it like a failed reader.
532 //
534 }
535
536 //
537 // Work item is no longer queued. We set this before resubmitting the
538 // repeaters so that if they all complete and fail, we will requeue the
539 // work item.
540 //
541 m_Pipe->Lock(&irql);
544
545 if (NT_SUCCESS(status)) {
547
548 //
549 // Reset the count to zero. This is safe since we stopped all the
550 // readers at the beginning of this function.
551 //
553
554 //
555 // restart the readers
556 //
557 for (i = 0; i < m_NumReaders; i++) {
558 FxUsbPipeRepeatReader* pRepeater;
559
560 pRepeater = &m_Readers[i];
561
562 action = ResubmitRepeater(pRepeater, &status);
563
564 if (action & SubmitSend) {
565 //
566 // Ignore the return value because once we have sent the
567 // request, we want all processing to be done in the
568 // completion routine.
569 //
571 }
572 }
573 }
574}
unsigned char BOOLEAN
void restart(int argc, const char *argv[])
Definition: cmds.c:2115
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
NTSTATUS CallDriver(__in MdDeviceObject DeviceObject)
Definition: fxirpum.cpp:36
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
__inline FxIrp * GetSubmitFxIrp(VOID)
FxUsbDevice * m_UsbDevice
Definition: fxusbpipe.hpp:698
NTSTATUS Reset(VOID)
Definition: fxusbpipe.cpp:1860
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
action
Definition: namespace.c:707
KIRQL irql
Definition: wave.h:1
UCHAR KIRQL
Definition: env_spec_w32.h:591
FxDevice * pDevice
@ SubmitSend
Definition: fxiotarget.hpp:202
#define ASSERT(a)
Definition: mode.c:44
#define DO_NOTHING()
Definition: mxgeneral.h:32
PFN_WDF_USB_READERS_FAILED m_ReadersFailedCallback
Definition: fxusbpipe.hpp:335
ULONG ResubmitRepeater(__in FxUsbPipeRepeatReader *Repeater, __out NTSTATUS *Status)
Definition: fxusbpipe.cpp:137
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
Definition: http.c:7252
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
LONG USBD_STATUS
Definition: usb.h:165

◆ operator new()

PVOID FxUsbPipeContinuousReader::operator new ( __in size_t  Size,
__in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__range(1, NUM_PENDING_READS_MAX) ULONG  NumReaders 
)

Definition at line 672 of file fxusbpipe.cpp.

677{
678 ASSERT(NumReaders >= 1);
679
680 return FxPoolAllocate(
681 FxDriverGlobals,
683 Size + (NumReaders-1) * sizeof(FxUsbPipeRepeatReader)
684 );
685}
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

◆ QueueWorkItemLocked()

BOOLEAN FxUsbPipeContinuousReader::QueueWorkItemLocked ( __in FxUsbPipeRepeatReader Repeater)
protected

Definition at line 91 of file fxusbpipe.cpp.

94{
95 BOOLEAN queued;
97
98 queued = FALSE;
100
102 //
103 // No item queued, queue it up now.
104 //
107 "WDFUSBPIPE %p continuous reader queueing work item to recover "
108 "from failed allocation", m_Pipe->GetHandle());
109
112 queued = TRUE;
113 }
114 else {
116 "Could not Queue workitem");
117 }
118 }
119
120 //
121 // We only want to queue the work item while the target is in the
122 // started state. If it is not started, then we are no longer sending
123 // i/o and we should not queue the work item to try to restart.
124 //
125 if (FALSE == queued) {
128 "WDFUSBPIPE %p continuous reader not queueing work item,"
129 "WorkItemQueued = %d, target state %!WDF_IO_TARGET_STATE!",
131 }
132
133 return queued;
134}
WDF_IO_TARGET_STATE m_State
Definition: fxiotarget.hpp:928
__inline BOOLEAN Enqueue(__in PFN_WDF_SYSTEMWORKITEM CallbackFunc, __in PVOID Parameter)
PFX_DRIVER_GLOBALS fxDriverGlobals
static EVT_SYSTEMWORKITEM _FxUsbPipeRequestWorkItemThunk
Definition: fxusbpipe.hpp:319
@ WdfIoTargetStarted
Definition: wdfiotarget.h:53

Referenced by ResubmitRepeater().

◆ ResubmitRepeater()

ULONG FxUsbPipeContinuousReader::ResubmitRepeater ( __in FxUsbPipeRepeatReader Repeater,
__out NTSTATUS Status 
)

Definition at line 137 of file fxusbpipe.cpp.

141{
145 KIRQL irql;
146
147 action = 0;
150
151 //
152 // Reformat and allocate any new needed buffers
153 //
154 status = FormatRepeater(Repeater);
155
156 m_Pipe->Lock(&irql);
157
158 //
159 // Do not re-submit repeaters if there is a queued/running work-item to
160 // reset pipe. Work-item will restart this repeater later.
161 // This check needs to be done after the FormatRepeater() call above to
162 // prevent a race condition where we are not detecting when the repeater
163 // is cancelled.
164 //
165 if (m_WorkItemQueued) {
166 //
167 // Return an error and no action flags to let the caller know that
168 // this request was not sent.
169 //
171
174 "WDFUSBPIPE %p is being reset, continuous reader %p FxRequest %p"
175 " PIRP %p is deferred for later.",
176 m_Pipe->GetHandle(), Repeater, Repeater->Request,
177 Repeater->RequestIrp);
178 }
179 else if (NT_SUCCESS(status)) {
180 //
181 // Get ready to re-submit the repeater.
182 //
184 Repeater->Request,
185 NULL,
187 );
188
189 if (action & SubmitSend) {
190 //
191 // Clear the event only if we are going to send the request
192 //
193 Repeater->ReadCompletedEvent.Clear();
194 }
195 else if (action & SubmitQueued) {
196 //
197 // Request got canceled asynchronously. The other thread is now
198 // responsible for calling its completion callback.
199 //
201 }
202 else {
203 //
204 // Submit failed (which is expected when we are changing the target
205 // state or when the request is canceled). It should always be an
206 // error.
207 //
208 status = Repeater->Request->GetFxIrp()->GetStatus();
210 }
211 }
212 else {
213 //
214 // Could not allocate a new buffer
215 //
216 Repeater->Request->GetFxIrp()->SetStatus(status);
217
220 "WDFUSBPIPE %p continuous reader, format failed, %!STATUS!, "
221 "repeater %p", m_Pipe->GetHandle(), status, Repeater);
222
226
228 //
229 // Queue a work item to clear problem.
230 //
231 QueueWorkItemLocked(Repeater);
232 }
233 else {
236 "WDFUSBPIPE %p continuous reader, buffer alloc failed, but "
237 "there are %d readers left out of a max of %d",
240
241 //
242 // There are still other pending readers, just use those for
243 // now.
244 //
245 DO_NOTHING();
246 }
247 }
248 else {
251 "WDFUSBPIPE %p continuous reader, buffer alloc failed, but not "
252 "in started state", m_Pipe->GetHandle());
253 }
254 }
255
257
258 *Status = status;
259
260 return action;
261}
ULONG SubmitLocked(__in FxRequestBase *Request, __in_opt PWDF_REQUEST_SEND_OPTIONS Options, __in ULONG Flags)
@ SubmitQueued
Definition: fxiotarget.hpp:203
#define WDF_REQUEST_SEND_INTERNAL_OPTION_FAIL_ON_PEND
Status
Definition: gdiplustypes.h:25
BOOLEAN QueueWorkItemLocked(__in FxUsbPipeRepeatReader *Repeater)
Definition: fxusbpipe.cpp:91
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

Referenced by FxUsbPipeRequestWorkItemHandler().

Member Data Documentation

◆ _FxUsbPipeContinuousReadDpc

MdDeferredRoutineType FxUsbPipeContinuousReader::_FxUsbPipeContinuousReadDpc
staticprotected

Definition at line 306 of file fxusbpipe.hpp.

Referenced by Config().

◆ _FxUsbPipeRequestComplete

VOID FxUsbPipeContinuousReader::_FxUsbPipeRequestComplete
staticprotected

Definition at line 315 of file fxusbpipe.hpp.

Referenced by FormatRepeater().

◆ _FxUsbPipeRequestWorkItemThunk

VOID FxUsbPipeContinuousReader::_FxUsbPipeRequestWorkItemThunk
staticprotected

Definition at line 319 of file fxusbpipe.hpp.

Referenced by QueueWorkItemLocked().

◆ _ReadWorkItem

VOID FxUsbPipeContinuousReader::_ReadWorkItem
staticprotected

Definition at line 310 of file fxusbpipe.hpp.

◆ m_Lookaside

FxLookasideList* FxUsbPipeContinuousReader::m_Lookaside

◆ m_NumFailedReaders

UCHAR FxUsbPipeContinuousReader::m_NumFailedReaders

◆ m_NumReaders

◆ m_Offsets

WDFMEMORY_OFFSET FxUsbPipeContinuousReader::m_Offsets

Definition at line 355 of file fxusbpipe.hpp.

Referenced by Config(), and FormatRepeater().

◆ m_Pipe

◆ m_ReadCompleteCallback

PFN_WDF_USB_READER_COMPLETION_ROUTINE FxUsbPipeContinuousReader::m_ReadCompleteCallback

Definition at line 325 of file fxusbpipe.hpp.

Referenced by FxUsbPipe::InitContinuousReader().

◆ m_ReadCompleteContext

WDFCONTEXT FxUsbPipeContinuousReader::m_ReadCompleteContext

Definition at line 330 of file fxusbpipe.hpp.

Referenced by FxUsbPipe::InitContinuousReader().

◆ m_Readers

◆ m_ReadersFailedCallback

PFN_WDF_USB_READERS_FAILED FxUsbPipeContinuousReader::m_ReadersFailedCallback

◆ m_ReadersSubmitted

BOOLEAN FxUsbPipeContinuousReader::m_ReadersSubmitted

◆ m_TargetDevice

MdDeviceObject FxUsbPipeContinuousReader::m_TargetDevice

Definition at line 350 of file fxusbpipe.hpp.

Referenced by FxUsbPipeContinuousReader().

◆ m_WorkItem

◆ m_WorkItemFlags

ULONG FxUsbPipeContinuousReader::m_WorkItemFlags

Definition at line 377 of file fxusbpipe.hpp.

Referenced by FxUsbPipeContinuousReader().

◆ m_WorkItemQueued

BOOLEAN FxUsbPipeContinuousReader::m_WorkItemQueued

◆ m_WorkItemRerunContext

PVOID FxUsbPipeContinuousReader::m_WorkItemRerunContext

Definition at line 365 of file fxusbpipe.hpp.

Referenced by FxUsbPipeContinuousReader().

◆ m_WorkItemThread


The documentation for this struct was generated from the following files: