ReactOS 0.4.17-dev-1133-gc25e4fd
inline.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Storport Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Storport driver - inlined helper utilities
5 * COPYRIGHT: Copyright 2024 Wu Haotian (rigoligo03@gmail.com)
6 */
7
8#pragma once
9
10#include "precomp.h"
11#include "storport.h"
12
18VOID
21 _In_ UCHAR SrbStatus,
22 _In_ NTSTATUS IrpStatus)
23{
24 IoGetCurrentIrpStackLocation(Irp)->Parameters.Scsi.Srb->SrbStatus = SrbStatus;
25 Irp->IoStatus.Status = IrpStatus;
26 Irp->IoStatus.Information = 0;
27
29}
30
40 _In_ PVOID HwDeviceExtension
41)
42{
43 PMINIPORT_DEVICE_EXTENSION MiniportExtension;
44
45 NT_ASSERT(HwDeviceExtension);
46
47 MiniportExtension = CONTAINING_RECORD(HwDeviceExtension,
49 HwDeviceExtension);
50
51 return MiniportExtension->Miniport->DeviceExtension;
52}
53
54/*
55 Convenient counted linked list manipulation. In ReactOS Storport there are linked lists whose
56 item count is kept alongside the list. This function provides a cleaner implementation to
57 reduce complexity in functional code.
58*/
59
73 _In_ PLIST_ENTRY ListHead,
76)
77{
79
81 InsertHeadList(ListHead, Entry);
82 ++(*Counter);
84
85 return (*Counter);
86}
87
101 _In_ PLIST_ENTRY ListHead,
104)
105{
107
109 InsertTailList(ListHead, Entry);
110 ++(*Counter);
112
113 return (*Counter);
114}
115
130{
133
136 --(*Counter);
137
138 NT_ASSERT(Empty == (*Counter == 0));
139
141
142 return Empty;
143}
144
157 _In_ PLIST_ENTRY ListHead,
159{
162
164
165 NT_ASSERT(IsListEmpty(ListHead) == (*Counter == 0));
166
167 Entry = RemoveHeadList(ListHead);
168 --(*Counter);
170
171 return Entry;
172}
173
186 _In_ PLIST_ENTRY ListHead,
188{
191
193
194 NT_ASSERT(IsListEmpty(ListHead) == (*Counter == 0));
195
196 Entry = RemoveTailList(ListHead);
197 --(*Counter);
199
200 return Entry;
201}
202
203
204
205#ifdef DBG
213VOID
216{
219 PFDO_IO_FLOW_CONTROL FdoFlowControl;
220 PPDO_IO_FLOW_CONTROL PdoFlowControl;
221 PLIST_ENTRY PdoEntry;
222 ULONG PdoOutstandingSum = 0;
223 ULONG PdoStrongOrderedSum = 0;
224
225 FdoFlowControl = &FdoExtension->FlowControl;
226
228 PdoEntry = FdoExtension->PdoListHead.Flink;
229
230 while (PdoEntry != &FdoExtension->PdoListHead)
231 {
232 /* Obtain PDO extension and flow control */
233 PdoExtension = CONTAINING_RECORD(PdoEntry, PDO_DEVICE_EXTENSION, PdoListEntry);
234 PdoFlowControl = &PdoExtension->FlowControl;
235
236 /* Accumulate important values and compare to FDO record */
237 PdoOutstandingSum += PdoFlowControl->OutstandingRequestCount;
238 PdoStrongOrderedSum += PdoFlowControl->StrongOrderedCount;
239
240 /* Next element */
241 PdoEntry = PdoEntry->Flink;
242 }
243
244 UNREFERENCED_PARAMETER(PdoStrongOrderedSum); /* Don't know what to do with it */
245
246 /* Compare */
247 NT_ASSERT(PdoOutstandingSum == FdoFlowControl->OutstandingRequestCount);
248
250}
251#else
252#define StorpCheckFlowControl(...)
253#endif
254
255
256// FORCEINLINE
257// VOID
258// StorpDumpRequest(
259// _In_ PQUEUED_REQUEST_REFERENCE RequestReference)
260// {
261// PPDO_DEVICE_EXTENSION PdoExtension = RequestReference->PdoExtension;
262// CHAR HexBuf[50] = {0};
263
264// RequestReference->SpecialRequestId = InterlockedIncrement(&PdoExtension->SpecialRequestCounter);
265
266// DPRINT1("\n\n");
267// DPRINT1("Storport SPECIAL REQUEST %d Before Issued\n", RequestReference->SpecialRequestId);
268// DPRINT1("Bus:Target:Lun (%d:%d:%d) CDB %d\n",
269// PdoExtension->Bus,
270// PdoExtension->Target,
271// PdoExtension->Lun,
272// RequestReference->Srb->CdbLength);
273// for (int i = 0; i < RequestReference->Srb->CdbLength; i++)
274// {
275// CHAR Tmp[3];
276// sprintf(Tmp, "%02X", RequestReference->Srb->Cdb[i]);
277// strcat(HexBuf, Tmp);
278// if (i == 7 && RequestReference->Srb->CdbLength != 7)
279// strcat(HexBuf, "-");
280// else
281// strcat(HexBuf, " ");
282// }
283// DPRINT1("CDB: %s\n\n", HexBuf);
284// }
285
286
287// FORCEINLINE
288// VOID
289// StorpDumpRequestResponse(
290// _In_ PQUEUED_REQUEST_REFERENCE RequestReference)
291// {
292// PPDO_DEVICE_EXTENSION PdoExtension = RequestReference->PdoExtension;
293// CHAR HexBuf[50] = {0};
294// ULONG BytesLeft = RequestReference->Srb->DataTransferLength;
295// ULONG Offset = 0;
296
297// DPRINT1("\n\n");
298// DPRINT1("Storport SPECIAL REQUEST %d Completion\n\n", RequestReference->SpecialRequestId);
299// DPRINT1("Bus:Target:Lun (%d:%d:%d) CDB %d (%02X) ReturnLength %d\n",
300// PdoExtension->Bus,
301// PdoExtension->Target,
302// PdoExtension->Lun,
303// RequestReference->Srb->CdbLength,
304// RequestReference->Srb->Cdb[0],
305// BytesLeft);
306
307// DPRINT1("Returned Data:\n");
308// while (BytesLeft)
309// {
310// /* Print in 16 byte groups */
311// ULONG BytesToPrint = (BytesLeft > 16) ? 16 : BytesLeft;
312// HexBuf[0] = '\0';
313// for (int i = 0; i < BytesToPrint; i++)
314// {
315// CHAR Tmp[3];
316// sprintf(Tmp, "%02X", ((PUCHAR)RequestReference->Srb->DataBuffer)[Offset + i]);
317// strcat(HexBuf, Tmp);
318// if (i == 7 && RequestReference->Srb->CdbLength != 7)
319// strcat(HexBuf, "-");
320// else
321// strcat(HexBuf, " ");
322// }
323// DPRINT1("%s\n", HexBuf);
324// BytesLeft -= BytesToPrint;
325// Offset += BytesToPrint;
326// }
327// DPRINT1("\n\n");
328// }
329
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
@ Empty
Definition: npfs.h:126
@ PdoExtension
Definition: precomp.h:61
@ FdoExtension
Definition: precomp.h:60
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define RemoveTailList(ListHead)
Definition: env_spec_w32.h:975
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
FORCEINLINE PLIST_ENTRY StorpInterlockedRemoveHeadListCounted(_In_ PKSPIN_LOCK SpinLock, _In_ PLIST_ENTRY ListHead, _In_ PULONG Counter)
RemoveHeadList and decrement element counter with a corresponding spin lock held.
Definition: inline.h:155
FORCEINLINE PFDO_DEVICE_EXTENSION StorpGetMiniportFdo(_In_ PVOID HwDeviceExtension)
For use in Storport API exposed to miniports; gets FDO extension with HwDeviceExtension.
Definition: inline.h:39
FORCEINLINE PLIST_ENTRY StorpInterlockedRemoveTailListCounted(_In_ PKSPIN_LOCK SpinLock, _In_ PLIST_ENTRY ListHead, _In_ PULONG Counter)
RemoveTailList and decrement element counter with a corresponding spin lock held.
Definition: inline.h:184
FORCEINLINE ULONG StorpInterlockedInsertHeadListCounted(_In_ PKSPIN_LOCK SpinLock, _In_ PLIST_ENTRY ListHead, _In_ PLIST_ENTRY Entry, _In_ PULONG Counter)
InsertHeadList and increment element counter with a corresponding spin lock held.
Definition: inline.h:71
FORCEINLINE ULONG StorpInterlockedInsertTailListCounted(_In_ PKSPIN_LOCK SpinLock, _In_ PLIST_ENTRY ListHead, _In_ PLIST_ENTRY Entry, _In_ PULONG Counter)
InsertTailList and increment element counter with a corresponding spin lock held.
Definition: inline.h:99
FORCEINLINE BOOLEAN StorpInterlockedRemoveEntryListCounted(_In_ PKSPIN_LOCK SpinLock, _In_ PLIST_ENTRY Entry, _In_ PULONG Counter)
RemoveEntryList and decrement element counter with a corresponding spin lock held.
Definition: inline.h:126
#define StorpCheckFlowControl(...)
Definition: inline.h:252
FORCEINLINE VOID StorpCompleteRequest(_In_ PIRP Irp, _In_ UCHAR SrbStatus, _In_ NTSTATUS IrpStatus)
Completes a request with specified SRB status and IRP status.
Definition: inline.h:19
#define _In_
Definition: no_sal2.h:158
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
#define IoCompleteRequest
Definition: irp.c:1272
Entry
Definition: section.c:5216
ULONG OutstandingRequestCount
Definition: precomp.h:208
union _IO_STACK_LOCATION::@1813 Parameters
struct _IO_STACK_LOCATION::@5016::@5038 Scsi
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
struct _MINIPORT * Miniport
Definition: precomp.h:84
ULONG OutstandingRequestCount
Definition: precomp.h:171
ULONG StrongOrderedCount
Definition: precomp.h:168
static LARGE_INTEGER Counter
Definition: clock.c:43
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
#define FORCEINLINE
Definition: wdftypes.h:67
#define IO_NO_INCREMENT
Definition: iotypes.h:598
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:717
#define NT_ASSERT
Definition: rtlfuncs.h:3334