ReactOS 0.4.15-dev-5896-g3f5bcf5
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 30 of file fxusbpipe.cpp.

33 :
34 m_NumReaders(NumReaders),
36{
43
45 m_Pipe = Pipe;
46
48
50}
__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 52 of file fxusbpipe.cpp.

53{
54 LONG i;
55
57
58 //
59 // It is impoortant to delete the requests before the lookaside because the
60 // requests may have outstanding references on memory objects allocated by
61 // the lookaside. The lookaside will not be truly deleted until the oustanding
62 // memory object allocations are also freed.
63 //
64 for (i = 0; i < m_NumReaders; i++) {
65 if (reader[i].Request != NULL) {
67
68 reader[i].Request->DeleteObject();
69 reader[i].Request = NULL;
70 }
71
72#if (FX_CORE_MODE == FX_CORE_USER_MODE)
73 reader[i].ReadCompletedEvent.Uninitialize();
74 reader[i].m_ReadWorkItem.Free();
75#endif
76 }
77
78 if (m_Lookaside != NULL) {
80 }
81
82 if (m_WorkItem != NULL) {
85 }
86}
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 768 of file fxusbpipe.cpp.

771{
772 LONG i;
773
774 Mx::MxEnterCriticalRegion();
775
776 for (i = 0; i < m_NumReaders; i++) {
779 m_Readers[i].ReadCompletedEvent.GetSelfPointer(),
780 "waiting for continuous reader to finish, WDFUSBPIPE",
781 m_Pipe->GetHandle(),
784
785 }
786
787 Mx::MxLeaveCriticalRegion();
788 //
789 // Checking for IO Count <= 1 is not a good idea here because there could be always other IO
790 // besides that from the continous reader going on the Read Pipe.
791 //
792}
__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:1705

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 88 of file fxusbpipekm.cpp.

92{
94 WDF_OBJECT_ATTRIBUTES attributes;
96 LONG i;
97
99
100 if (TotalBufferLength <= MAXUSHORT) {
103 }
104 else {
107 }
108
109 if (m_Lookaside == NULL) {
111 }
112
113 if (Config->BufferAttributes == NULL) {
114 WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
115 }
116 else {
117 RtlCopyMemory(&attributes,
118 Config->BufferAttributes,
119 sizeof(WDF_OBJECT_ATTRIBUTES));
120 }
121
122 //
123 // By specifying the loookaside as the parent for the memory objects that
124 // will be created, when we destroy the lookaside list, we will destroy any
125 // outstanding memory objects that have been allocated. This can happen if
126 // we initialize the repeater, but never send any i/o. (Normally the
127 // memory object would be freed when the read completes.)
128 //
130
131 status = m_Lookaside->Initialize(TotalBufferLength, &attributes);
132 if (!NT_SUCCESS(status)) {
133 return status;
134 }
135
139 );
140 if (!NT_SUCCESS(status)) {
142 "Could not allocate workitem: %!STATUS!", status);
143 return status;
144 }
145
146 m_Offsets.BufferLength = Config->TransferLength;
147 m_Offsets.BufferOffset = Config->HeaderLength;
148
149 for (i = 0; i < m_NumReaders; i++) {
150 FxUsbPipeRepeatReader* pRepeater;
151
152 pRepeater = &m_Readers[i];
153
154 pRepeater->Parent = this;
155
157
158 //
159 // This will allocate the PIRP
160 //
163 NULL,
164 m_Pipe,
167 &pRepeater->Request);
168
169 if (!NT_SUCCESS(status)) {
170 return status;
171 }
172
173 pRepeater->RequestIrp = pRepeater->Request->GetSubmitIrp();
174
175 //
176 // Initialize the event before FormatRepeater clears it
177 //
179
180 if (!NT_SUCCESS(status)) {
183 "Could not initialize ReadCompletedEvent: %!STATUS!",
184 status);
185
186 return status;
187 }
188
189 //
190 // This will allocate the context
191 //
192 status = FormatRepeater(pRepeater);
193
194 if (!NT_SUCCESS(status)) {
195 return status;
196 }
197 }
198
199 return STATUS_SUCCESS;
200}
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:32
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:687
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 687 of file fxusbpipe.cpp.

690{
693 FxUsbPipeTransferContext* pContext;
697
698 pRequest = Repeater->Request;
699 //
700 // The repeater owns the request memory. If there is a memory on the
701 // context, delete it now. the memory will still be referencable since
702 // it will still have a reference against it until FormatTransferRequest is
703 // called or the request is freed and the context releases its references
704 //
706
708
710
711 //
712 // pMemory will be deleted when either
713 // a) The request completes
714 // or
715 // b) The continuous reader is destroyed and we delete the lookaside. since
716 // the lookaside is the parent object for pMemory, pMemory will be disposed
717 // of when the parent is Disposed
718 //
720 if (!NT_SUCCESS(status)) {
721 FxRequestContext* pContext;
722
723 pContext = pRequest->GetContext();
724 if (pContext != NULL ) {
725 pContext->m_RequestMemory = NULL;
726 }
727
729 }
730
732
733 buf.SetMemory(pMemory, &m_Offsets);
734
736 pRequest,
737 &buf,
739 );
740
741 if (!NT_SUCCESS(status)) {
742 //
743 // In the case of failure, the context in the request will delete the
744 // memory. If there is no context, delete the memory here.
745 //
746 if (pRequest->GetContext() == NULL) {
747 //
748 // Use DeleteFromFailedCreate because the driver never saw the
749 // buffer, so they shouldn't be told about it going away.
750 //
752 }
753
754 return status;
755 }
756
758 pContext->SetUsbType(WdfUsbRequestTypePipeRead);
759 pContext->m_UsbParameters.Parameters.PipeRead.Buffer = (WDFMEMORY)
761
763 return status;
764}
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
FxRequest * pRequest
FxMemoryObject * pMemory
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
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 395 of file fxusbpipe.cpp.

398{
400 NTSTATUS status, failedStatus;
401 USBD_STATUS usbdStatus;
402 LONG i;
403 KIRQL irql;
406 PWDF_USB_REQUEST_COMPLETION_PARAMS usbCompletionParams;
408
410
411 //
412 // Get failed info.
413 //
414 failedStatus = FailedRepeater->Request->GetStatus();
415
416 //
417 // Context is allocated at config time and gets reused so context
418 // will never be NULL.
419 //
420 context = FailedRepeater->Request->GetContext();
421 usbCompletionParams = context->m_CompletionParams.Parameters.Usb.Completion;
422
423 //
424 // In case FormatRepeater fails to allocate memory usbCompletionParams
425 // pointer is not set.
426 //
427 // usbCompletionParams are part of the context and
428 // not really allocated at the time of every Format but
429 // the pointer gets cleared by request->Reuse and gets set again by
430 // context->SetUsbType.
431 //
432 // In FormatRepeater, context->SetUsbType is skipped
433 // if a memory failure occurs before this step.
434 //
435 // Hence retrieve usbdStatus only when usbCompletionParams is set.
436 //
437 if (usbCompletionParams) {
438 usbdStatus = usbCompletionParams->UsbdStatus;
439 }
440 else {
441 //
442 // Set usbdStatus to success as we didn't receive a failure from
443 // USB stack.
444 //
445 // This path is reached during memory allocation failure. In such
446 // case failedStatus would already be set appropriately. (usbdStatus
447 // and failedStatus are passed to m_ReadersFailedCallback below.)
448 //
449 usbdStatus = STATUS_SUCCESS;
450 }
451
452 //
453 // No read requests should be in progress when the framework calls the
454 // EvtUsbTargetPipeReadersFailed callback function. This is part of the
455 // contract so that the Driver doesn't need to bother with the
456 // Completion calllback while taking corrective action.
457 //
460
462 //
463 // Save the current thread object pointer. This value is
464 // used for not deadlocking when misbehaved drivers (< v1.9) call
465 // WdfIoTargetStop from EvtUsbTargetPipeReadersFailed callback
466 //
469
471 (WDFUSBPIPE) m_Pipe->GetHandle(),
472 failedStatus,
473 usbdStatus
474 );
475
477 }
478 else {
479 //
480 // By default, we restart the readers
481 //
482 restart = TRUE;
483 }
484
485 if (restart) {
486 status = pDevice->IsConnected();
487
488 if (NT_SUCCESS(status)) {
489
490 //
491 // for v1.9 or higher use the error recovery procedure prescribed
492 // by the USB team.
493 //
495
496 if (pDevice->IsEnabled()) {
497 //
498 // Reset the pipe if port status is enabled
499 //
500 m_Pipe->Reset();
501 }
502 else {
503 //
504 // Reset the device if port status is disabled
505 //
506 status = pDevice->Reset();
507 }
508 }
509 else {
510 //
511 // Reset the device if port status is disabled
512 //
513 status = pDevice->Reset();
514 }
515 }
516 else {
517 //
518 // if port status is disconnected we would get back
519 // a !NT_SUCCESS. This would mean that we would not
520 // send the readers again and treat it like a failed reader.
521 //
522 DO_NOTHING();
523 }
524
525 }
526 else {
527 //
528 // By setting status to !NT_SUCCESS, we will not send the readers
529 // again and treat it like a failed reader.
530 //
532 }
533
534 //
535 // Work item is no longer queued. We set this before resubmitting the
536 // repeaters so that if they all complete and fail, we will requeue the
537 // work item.
538 //
539 m_Pipe->Lock(&irql);
542
543 if (NT_SUCCESS(status)) {
545
546 //
547 // Reset the count to zero. This is safe since we stopped all the
548 // readers at the beginning of this function.
549 //
551
552 //
553 // restart the readers
554 //
555 for (i = 0; i < m_NumReaders; i++) {
556 FxUsbPipeRepeatReader* pRepeater;
557
558 pRepeater = &m_Readers[i];
559
560 action = ResubmitRepeater(pRepeater, &status);
561
562 if (action & SubmitSend) {
563 //
564 // Ignore the return value because once we have sent the
565 // request, we want all processing to be done in the
566 // completion routine.
567 //
569 }
570 }
571 }
572}
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:1858
static __inline MxThread MxGetCurrentThread()
Definition: mxgeneralkm.h:61
const WCHAR * action
Definition: action.c:7479
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:135
_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 670 of file fxusbpipe.cpp.

675{
676 ASSERT(NumReaders >= 1);
677
678 return FxPoolAllocate(
679 FxDriverGlobals,
681 Size + (NumReaders-1) * sizeof(FxUsbPipeRepeatReader)
682 );
683}
#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:4533

◆ QueueWorkItemLocked()

BOOLEAN FxUsbPipeContinuousReader::QueueWorkItemLocked ( __in FxUsbPipeRepeatReader Repeater)
protected

Definition at line 89 of file fxusbpipe.cpp.

92{
93 BOOLEAN queued;
95
96 queued = FALSE;
98
100 //
101 // No item queued, queue it up now.
102 //
105 "WDFUSBPIPE %p continuous reader queueing work item to recover "
106 "from failed allocation", m_Pipe->GetHandle());
107
110 queued = TRUE;
111 }
112 else {
114 "Could not Queue workitem");
115 }
116 }
117
118 //
119 // We only want to queue the work item while the target is in the
120 // started state. If it is not started, then we are no longer sending
121 // i/o and we should not queue the work item to try to restart.
122 //
123 if (FALSE == queued) {
126 "WDFUSBPIPE %p continuous reader not queueing work item,"
127 "WorkItemQueued = %d, target state %!WDF_IO_TARGET_STATE!",
129 }
130
131 return queued;
132}
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 135 of file fxusbpipe.cpp.

139{
143 KIRQL irql;
144
145 action = 0;
148
149 //
150 // Reformat and allocate any new needed buffers
151 //
152 status = FormatRepeater(Repeater);
153
154 m_Pipe->Lock(&irql);
155
156 //
157 // Do not re-submit repeaters if there is a queued/running work-item to
158 // reset pipe. Work-item will restart this repeater later.
159 // This check needs to be done after the FormatRepeater() call above to
160 // prevent a race condition where we are not detecting when the repeater
161 // is cancelled.
162 //
163 if (m_WorkItemQueued) {
164 //
165 // Return an error and no action flags to let the caller know that
166 // this request was not sent.
167 //
169
172 "WDFUSBPIPE %p is being reset, continuous reader %p FxRequest %p"
173 " PIRP %p is deferred for later.",
174 m_Pipe->GetHandle(), Repeater, Repeater->Request,
175 Repeater->RequestIrp);
176 }
177 else if (NT_SUCCESS(status)) {
178 //
179 // Get ready to re-submit the repeater.
180 //
182 Repeater->Request,
183 NULL,
185 );
186
187 if (action & SubmitSend) {
188 //
189 // Clear the event only if we are going to send the request
190 //
191 Repeater->ReadCompletedEvent.Clear();
192 }
193 else if (action & SubmitQueued) {
194 //
195 // Request got canceled asynchronously. The other thread is now
196 // responsible for calling its completion callback.
197 //
199 }
200 else {
201 //
202 // Submit failed (which is expected when we are changing the target
203 // state or when the request is canceled). It should always be an
204 // error.
205 //
206 status = Repeater->Request->GetFxIrp()->GetStatus();
208 }
209 }
210 else {
211 //
212 // Could not allocate a new buffer
213 //
214 Repeater->Request->GetFxIrp()->SetStatus(status);
215
218 "WDFUSBPIPE %p continuous reader, format failed, %!STATUS!, "
219 "repeater %p", m_Pipe->GetHandle(), status, Repeater);
220
224
226 //
227 // Queue a work item to clear problem.
228 //
229 QueueWorkItemLocked(Repeater);
230 }
231 else {
234 "WDFUSBPIPE %p continuous reader, buffer alloc failed, but "
235 "there are %d readers left out of a max of %d",
238
239 //
240 // There are still other pending readers, just use those for
241 // now.
242 //
243 DO_NOTHING();
244 }
245 }
246 else {
249 "WDFUSBPIPE %p continuous reader, buffer alloc failed, but not "
250 "in started state", m_Pipe->GetHandle());
251 }
252 }
253
255
256 *Status = status;
257
258 return action;
259}
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:89
#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: