Skip to content

Commit

Permalink
make CompleteRequest function global
Browse files Browse the repository at this point in the history
Signed-off-by: Vadim Rozenfeld <[email protected]>
  • Loading branch information
vrozenfe authored and YanVugenfirer committed Nov 30, 2021
1 parent 7dc052d commit f1338bb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 78 deletions.
104 changes: 48 additions & 56 deletions vioscsi/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,88 +43,80 @@
VOID
SendSRB(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb,
IN BOOLEAN isr,
IN ULONG MessageID
IN PSRB_TYPE Srb
)
{
PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension;
PSRB_EXTENSION srbExt = NULL;
PVOID va = NULL;
ULONGLONG pa = 0;
ULONG QueueNumber = 0;
ULONG OldIrql = 0;
BOOLEAN notify = FALSE;
ULONG QueueNumber = VIRTIO_SCSI_REQUEST_QUEUE_0;
STOR_LOCK_HANDLE LockHandle = { 0 };
ULONG status = STOR_STATUS_SUCCESS;
PREQUEST_LIST element = NULL;

ULONG MessageID;
int res = 0;
PREQUEST_LIST element;
ULONG index;
ENTER_FN_SRB();

RhelDbgPrint(TRACE_LEVEL_INFORMATION, " SRB %p isr %d, MessageId %x.\n", Srb, isr, MessageID);
RhelDbgPrint(TRACE_LEVEL_INFORMATION, " SRB %p.\n", Srb);

if (Srb) {
if (adaptExt->num_queues > 1) {
STARTIO_PERFORMANCE_PARAMETERS param;
param.Size = sizeof(STARTIO_PERFORMANCE_PARAMETERS);
status = StorPortGetStartIoPerfParams(DeviceExtension, (PSCSI_REQUEST_BLOCK)Srb, &param);
if (status == STOR_STATUS_SUCCESS && param.MessageNumber != 0) {
QueueNumber = MESSAGE_TO_QUEUE(param.MessageNumber);
}
else {
RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortGetStartIoPerfParams failed srb %p status 0x%x MessageNumber %d.\n", Srb, status, param.MessageNumber);
QueueNumber = VIRTIO_SCSI_REQUEST_QUEUE_0;
}
}
else {
QueueNumber = VIRTIO_SCSI_REQUEST_QUEUE_0;
if (!Srb)
return;

if (adaptExt->num_queues > 1) {
STARTIO_PERFORMANCE_PARAMETERS param;
param.Size = sizeof(STARTIO_PERFORMANCE_PARAMETERS);
status = StorPortGetStartIoPerfParams(DeviceExtension, (PSCSI_REQUEST_BLOCK)Srb, &param);
if (status == STOR_STATUS_SUCCESS && param.MessageNumber != 0) {
QueueNumber = MESSAGE_TO_QUEUE(param.MessageNumber);
} else {
RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortGetStartIoPerfParams failed srb %p status 0x%x MessageNumber %d.\n", Srb, status, param.MessageNumber);
}
srbExt = SRB_EXTENSION(Srb);
srbExt->vq_num = QueueNumber;
element = &adaptExt->pending_list[QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0];
ExInterlockedInsertTailList(&element->srb_list, &srbExt->list_entry, &element->srb_list_lock);
}
else {
QueueNumber = MESSAGE_TO_QUEUE(MessageID);
element = &adaptExt->pending_list[QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0];
}

srbExt = (PSRB_EXTENSION)ExInterlockedRemoveHeadList(&element->srb_list, &element->srb_list_lock);
srbExt = SRB_EXTENSION(Srb);

if (!srbExt) {
RhelDbgPrint(TRACE_LEVEL_INFORMATION, " No SRB Ext after ExInterlockedRemoveHeadList QueueNumber (%d) \n", QueueNumber);
return;
}

RhelDbgPrint(TRACE_LEVEL_INFORMATION, " ExInterlockedRemoveHeadList SRB %p srbExt %p, QueueNumber %d vq_num %d.\n", srbExt->Srb, srbExt, QueueNumber, srbExt->vq_num);

MessageID = QUEUE_TO_MESSAGE(QueueNumber);
index = QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0;

VioScsiVQLock(DeviceExtension, MessageID, &LockHandle, isr);

while (srbExt) {
RhelDbgPrint(TRACE_LEVEL_INFORMATION, " add packet to queue (%d) SRB = %p isr = %d.\n", QueueNumber, srbExt->Srb, isr);
SET_VA_PA();
if (virtqueue_add_buf(adaptExt->vq[QueueNumber],
srbExt->psgl,
srbExt->out, srbExt->in,
&srbExt->cmd, va, pa) >= 0){
notify = virtqueue_kick_prepare(adaptExt->vq[QueueNumber]) ? TRUE : notify;
srbExt = (PSRB_EXTENSION)ExInterlockedRemoveHeadList(&element->srb_list, &element->srb_list_lock);
}
else {
RhelDbgPrint(TRACE_LEVEL_FATAL, " can not add packet to queue (%d) SRB = %p .\n", QueueNumber, srbExt->Srb);
ExInterlockedInsertHeadList(&element->srb_list, &srbExt->list_entry, &element->srb_list_lock);
notify = TRUE;
srbExt = NULL;
}
if (adaptExt->reset_in_progress) {
RhelDbgPrint(TRACE_LEVEL_FATAL, "WHAT ATE YOU DOING SPB = %p ??\n", Srb);
SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUS_RESET);
CompleteRequest(DeviceExtension, Srb);
return;
}

VioScsiVQUnlock(DeviceExtension, MessageID, &LockHandle, isr);

if (notify) {
VioScsiVQLock(DeviceExtension, MessageID, &LockHandle, FALSE);
SET_VA_PA();
res = virtqueue_add_buf(adaptExt->vq[QueueNumber],
srbExt->psgl,
srbExt->out, srbExt->in,
&srbExt->cmd, va, pa);

if (res >= 0) {
element = &adaptExt->processing_srbs[index];
InsertTailList(&element->srb_list, &srbExt->list_entry);
element->srb_cnt++;
}
VioScsiVQUnlock(DeviceExtension, MessageID, &LockHandle, FALSE);
if ( res >= 0){
if (virtqueue_kick_prepare(adaptExt->vq[QueueNumber])) {
virtqueue_notify(adaptExt->vq[QueueNumber]);
}
} else {
virtqueue_notify(adaptExt->vq[QueueNumber]);
SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY);
StorPortBusy(DeviceExtension, 10);
CompleteRequest(DeviceExtension, Srb);
RhelDbgPrint(TRACE_LEVEL_FATAL, " CompleteRequest queue (%d) SRB = %p Lun = %d TimeOut = %d.\n", QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue);
}

EXIT_FN_SRB();
}

Expand Down
10 changes: 7 additions & 3 deletions vioscsi/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ SrbGetPnpInfo(_In_ PVOID Srb, ULONG* PnPFlags, ULONG* PnPAction) {
VOID
SendSRB(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb,
IN BOOLEAN isr,
IN ULONG MessageID
IN PSRB_TYPE Srb
);

BOOLEAN
Expand Down Expand Up @@ -208,6 +206,12 @@ VioScsiPoolAlloc(
IN SIZE_T size
);

VOID
CompleteRequest(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb
);

#if (NTDDI_VERSION >= NTDDI_WINTHRESHOLD)
VOID FirmwareRequest(
IN PVOID DeviceExtension,
Expand Down
21 changes: 2 additions & 19 deletions vioscsi/vioscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ PostProcessRequest(
IN PSRB_TYPE Srb
);

VOID
FORCEINLINE
CompleteRequest(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb
);

VOID
FORCEINLINE
DispatchQueue(
Expand Down Expand Up @@ -872,7 +865,7 @@ ENTER_FN_SRB();
}
else
{
SendSRB(DeviceExtension, (PSRB_TYPE)Srb, FALSE, -1);
SendSRB(DeviceExtension, (PSRB_TYPE)Srb);
}
EXIT_FN_SRB();
return TRUE;
Expand Down Expand Up @@ -1350,13 +1343,10 @@ ProcessQueue(
STOR_LOCK_HANDLE queueLock = { 0 };
struct virtqueue *vq;
adaptExt = (PADAPTER_EXTENSION)DeviceExtension;
LIST_ENTRY complete_list;
PSRB_TYPE Srb = NULL;
PSRB_EXTENSION srbExt = NULL;
ENTER_FN();

vq = adaptExt->vq[VIRTIO_SCSI_REQUEST_QUEUE_0 + index];
InitializeListHead(&complete_list);

VioScsiVQLock(DeviceExtension, MessageID, &queueLock, isr);

Expand All @@ -1365,19 +1355,12 @@ ENTER_FN();
while ((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(vq, &len)) != NULL) {
Srb = (PSRB_TYPE)(cmd->srb);
srbExt = SRB_EXTENSION(Srb);
InsertTailList(&complete_list, &srbExt->list_entry);
HandleResponse(DeviceExtension, cmd);
}
} while (!virtqueue_enable_cb(vq));

VioScsiVQUnlock(DeviceExtension, MessageID, &queueLock, isr);

SendSRB(DeviceExtension, NULL, isr, MessageID);

while (!IsListEmpty(&complete_list)) {
srbExt = (PSRB_EXTENSION)RemoveHeadList(&complete_list);
HandleResponse(DeviceExtension, &srbExt->cmd);
}

EXIT_FN();
}

Expand Down

0 comments on commit f1338bb

Please sign in to comment.