diff --git a/vioscsi/helper.c b/vioscsi/helper.c old mode 100755 new mode 100644 index d5ecc2db2..440c5682f --- a/vioscsi/helper.c +++ b/vioscsi/helper.c @@ -36,36 +36,38 @@ #include "helper.tmh" #endif -#define SET_VA_PA() { ULONG len; va = adaptExt->indirect ? srbExt->pdesc : NULL; \ - pa = va ? StorPortGetPhysicalAddress(DeviceExtension, NULL, va, &len).QuadPart : 0; \ - } +#define SET_VA_PA() \ + { \ + ULONG len; \ + va = adaptExt->indirect ? srbExt->pdesc : NULL; \ + pa = va ? StorPortGetPhysicalAddress(DeviceExtension, NULL, va, &len).QuadPart : 0; \ + } -VOID -SendSRB( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - PSRB_EXTENSION srbExt = NULL; - PVOID va = NULL; - ULONGLONG pa = 0; - ULONG QueueNumber = VIRTIO_SCSI_REQUEST_QUEUE_0; - BOOLEAN notify = FALSE; - STOR_LOCK_HANDLE LockHandle = { 0 }; - PVOID LockContext; - ULONG status = STOR_STATUS_SUCCESS; - UCHAR ScsiStatus = SCSISTAT_GOOD; - INT add_buffer_req_status = VQ_ADD_BUFFER_SUCCESS; - PREQUEST_LIST element; - ULONG vq_req_idx; - -ENTER_FN_SRB(); + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; + PSRB_EXTENSION srbExt = NULL; + PVOID va = NULL; + ULONGLONG pa = 0; + ULONG QueueNumber = VIRTIO_SCSI_REQUEST_QUEUE_0; + BOOLEAN notify = FALSE; + STOR_LOCK_HANDLE LockHandle = {0}; + PVOID LockContext; + ULONG status = STOR_STATUS_SUCCESS; + UCHAR ScsiStatus = SCSISTAT_GOOD; + INT add_buffer_req_status = VQ_ADD_BUFFER_SUCCESS; + PREQUEST_LIST element; + ULONG vq_req_idx; + + ENTER_FN_SRB(); if (!Srb) + { return; + } - if (adaptExt->bRemoved) { + if (adaptExt->bRemoved) + { SRB_SET_SRB_STATUS(Srb, SRB_STATUS_NO_DEVICE); CompleteRequest(DeviceExtension, Srb); return; @@ -73,23 +75,33 @@ ENTER_FN_SRB(); LOG_SRB_INFO(); - if (adaptExt->num_queues > 1) { + if (adaptExt->num_queues > 1) + { STARTIO_PERFORMANCE_PARAMETERS param; param.Size = sizeof(STARTIO_PERFORMANCE_PARAMETERS); status = StorPortGetStartIoPerfParams(DeviceExtension, (PSCSI_REQUEST_BLOCK)Srb, ¶m); - if (status == STOR_STATUS_SUCCESS && param.MessageNumber != 0) { + if (status == STOR_STATUS_SUCCESS && param.MessageNumber != 0) + { QueueNumber = MESSAGE_TO_QUEUE(param.MessageNumber); - if (QueueNumber >= adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0) { + if (QueueNumber >= adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0) + { QueueNumber %= adaptExt->num_queues; } - } else { - RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortGetStartIoPerfParams failed srb 0x%p status 0x%x MessageNumber %d.\n", Srb, status, param.MessageNumber); + } + else + { + RhelDbgPrint(TRACE_LEVEL_ERROR, + " StorPortGetStartIoPerfParams failed srb 0x%p status 0x%x MessageNumber %d.\n", + Srb, + status, + param.MessageNumber); } } srbExt = SRB_EXTENSION(Srb); - if (!srbExt) { + if (!srbExt) + { RhelDbgPrint(TRACE_LEVEL_INFORMATION, " No SRB Extenstion for SRB 0x%p \n", Srb); return; } @@ -97,7 +109,8 @@ ENTER_FN_SRB(); vq_req_idx = QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0; LockContext = &adaptExt->dpc[vq_req_idx]; - if (adaptExt->reset_in_progress) { + if (adaptExt->reset_in_progress) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " Reset is in progress, completing SRB 0x%p with SRB_STATUS_BUS_RESET.\n", Srb); SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUS_RESET); CompleteRequest(DeviceExtension, Srb); @@ -108,86 +121,96 @@ ENTER_FN_SRB(); SET_VA_PA(); add_buffer_req_status = virtqueue_add_buf(adaptExt->vq[QueueNumber], srbExt->psgl, - srbExt->out, srbExt->in, - &srbExt->cmd, va, pa); + srbExt->out, + srbExt->in, + &srbExt->cmd, + va, + pa); - if (add_buffer_req_status == VQ_ADD_BUFFER_SUCCESS) { + if (add_buffer_req_status == VQ_ADD_BUFFER_SUCCESS) + { notify = virtqueue_kick_prepare(adaptExt->vq[QueueNumber]); element = &adaptExt->processing_srbs[vq_req_idx]; InsertTailList(&element->srb_list, &srbExt->list_entry); element->srb_cnt++; - } else { + } + else + { // virtqueue_add_buf() returned -28 (ENOSPC), i.e. no space for buffer, or some other error ScsiStatus = SCSISTAT_QUEUE_FULL; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY); SRB_SET_SCSI_STATUS(Srb, ScsiStatus); StorPortBusy(DeviceExtension, 10); - RhelDbgPrint(TRACE_LEVEL_WARNING, - " Could not put an SRB into a VQ due to error %s (%i). To be completed with SRB_STATUS_BUSY. QueueNumber = %lu, SRB = 0x%p, Lun = %d, TimeOut = %d.\n", - (add_buffer_req_status == -ENOSPC) ? "ENOSPC" : "UNKNOWN", add_buffer_req_status, QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue); + RhelDbgPrint(TRACE_LEVEL_WARNING, + " Could not put an SRB into a VQ due to error %s (%i). To be completed with SRB_STATUS_BUSY. " + "QueueNumber = %lu, SRB = 0x%p, Lun = %d, TimeOut = %d.\n", + (add_buffer_req_status == -ENOSPC) ? "ENOSPC" : "UNKNOWN", + add_buffer_req_status, + QueueNumber, + srbExt->Srb, + SRB_LUN(Srb), + Srb->TimeOutValue); CompleteRequest(DeviceExtension, Srb); } StorPortReleaseSpinLock(DeviceExtension, &LockHandle); - if (notify){ + if (notify) + { virtqueue_notify(adaptExt->vq[QueueNumber]); } -EXIT_FN_SRB(); + EXIT_FN_SRB(); } BOOLEAN -SynchronizedTMFRoutine( - IN PVOID DeviceExtension, - IN PVOID Context - ) +SynchronizedTMFRoutine(IN PVOID DeviceExtension, IN PVOID Context) { - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - PSCSI_REQUEST_BLOCK Srb = (PSCSI_REQUEST_BLOCK) Context; - PSRB_EXTENSION srbExt = SRB_EXTENSION(Srb); - PVOID va; - ULONGLONG pa; + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; + PSCSI_REQUEST_BLOCK Srb = (PSCSI_REQUEST_BLOCK)Context; + PSRB_EXTENSION srbExt = SRB_EXTENSION(Srb); + PVOID va; + ULONGLONG pa; -ENTER_FN(); + ENTER_FN(); SET_VA_PA(); if (virtqueue_add_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], - srbExt->psgl, - srbExt->out, srbExt->in, - &srbExt->cmd, va, pa) >= 0){ + srbExt->psgl, + srbExt->out, + srbExt->in, + &srbExt->cmd, + va, + pa) >= 0) + { virtqueue_kick(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE]); -EXIT_FN(); + EXIT_FN(); return TRUE; } SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY); StorPortBusy(DeviceExtension, adaptExt->queue_depth); -EXIT_ERR(); + EXIT_ERR(); return FALSE; } BOOLEAN -SendTMF( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ) +SendTMF(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { -ENTER_FN(); + ENTER_FN(); return StorPortSynchronizeAccess(DeviceExtension, SynchronizedTMFRoutine, (PVOID)Srb); -EXIT_FN(); + EXIT_FN(); } BOOLEAN -DeviceReset( - IN PVOID DeviceExtension - ) +DeviceReset(IN PVOID DeviceExtension) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - PSCSI_REQUEST_BLOCK Srb = &adaptExt->tmf_cmd.Srb; - PSRB_EXTENSION srbExt = adaptExt->tmf_cmd.SrbExtension; - VirtIOSCSICmd *cmd = &srbExt->cmd; - ULONG fragLen; - ULONG sgElement; - -ENTER_FN(); - if (adaptExt->dump_mode) { + PSCSI_REQUEST_BLOCK Srb = &adaptExt->tmf_cmd.Srb; + PSRB_EXTENSION srbExt = adaptExt->tmf_cmd.SrbExtension; + VirtIOSCSICmd *cmd = &srbExt->cmd; + ULONG fragLen; + ULONG sgElement; + + ENTER_FN(); + if (adaptExt->dump_mode) + { return TRUE; } ASSERT(adaptExt->tmf_infly == FALSE); @@ -205,7 +228,7 @@ ENTER_FN(); srbExt->pdesc = srbExt->desc_alias; sgElement = 0; srbExt->psgl[sgElement].physAddr = StorPortGetPhysicalAddress(DeviceExtension, NULL, &cmd->req.tmf, &fragLen); - srbExt->psgl[sgElement].length = sizeof(cmd->req.tmf); + srbExt->psgl[sgElement].length = sizeof(cmd->req.tmf); sgElement++; srbExt->out = sgElement; srbExt->psgl[sgElement].physAddr = StorPortGetPhysicalAddress(DeviceExtension, NULL, &cmd->resp.tmf, &fragLen); @@ -213,7 +236,8 @@ ENTER_FN(); sgElement++; srbExt->in = sgElement - srbExt->out; StorPortPause(DeviceExtension, 60); - if (!SendTMF(DeviceExtension, Srb)) { + if (!SendTMF(DeviceExtension, Srb)) + { StorPortResume(DeviceExtension); return FALSE; } @@ -221,137 +245,149 @@ ENTER_FN(); return TRUE; } -VOID -ShutDown( - IN PVOID DeviceExtension - ) +VOID ShutDown(IN PVOID DeviceExtension) { ULONG index; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; -ENTER_FN(); + ENTER_FN(); virtio_device_reset(&adaptExt->vdev); virtio_delete_queues(&adaptExt->vdev); - for (index = VIRTIO_SCSI_CONTROL_QUEUE; index < adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; ++index) { + for (index = VIRTIO_SCSI_CONTROL_QUEUE; index < adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; ++index) + { adaptExt->vq[index] = NULL; } virtio_device_shutdown(&adaptExt->vdev); -EXIT_FN(); + EXIT_FN(); } -VOID -GetScsiConfig( - IN PVOID DeviceExtension -) +VOID GetScsiConfig(IN PVOID DeviceExtension) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; -ENTER_FN(); + ENTER_FN(); adaptExt->features = virtio_get_features(&adaptExt->vdev); adaptExt->indirect = CHECKBIT(adaptExt->features, VIRTIO_RING_F_INDIRECT_DESC); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, seg_max), - &adaptExt->scsi_config.seg_max, sizeof(adaptExt->scsi_config.seg_max)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, seg_max), + &adaptExt->scsi_config.seg_max, + sizeof(adaptExt->scsi_config.seg_max)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " seg_max %lu\n", adaptExt->scsi_config.seg_max); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, num_queues), - &adaptExt->scsi_config.num_queues, sizeof(adaptExt->scsi_config.num_queues)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, num_queues), + &adaptExt->scsi_config.num_queues, + sizeof(adaptExt->scsi_config.num_queues)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " num_queues %lu\n", adaptExt->scsi_config.num_queues); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, max_sectors), - &adaptExt->scsi_config.max_sectors, sizeof(adaptExt->scsi_config.max_sectors)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, max_sectors), + &adaptExt->scsi_config.max_sectors, + sizeof(adaptExt->scsi_config.max_sectors)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_sectors %lu\n", adaptExt->scsi_config.max_sectors); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, cmd_per_lun), - &adaptExt->scsi_config.cmd_per_lun, sizeof(adaptExt->scsi_config.cmd_per_lun)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, cmd_per_lun), + &adaptExt->scsi_config.cmd_per_lun, + sizeof(adaptExt->scsi_config.cmd_per_lun)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " cmd_per_lun %lu\n", adaptExt->scsi_config.cmd_per_lun); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, event_info_size), - &adaptExt->scsi_config.event_info_size, sizeof(adaptExt->scsi_config.event_info_size)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, event_info_size), + &adaptExt->scsi_config.event_info_size, + sizeof(adaptExt->scsi_config.event_info_size)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " event_info_size %lu\n", adaptExt->scsi_config.event_info_size); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, sense_size), - &adaptExt->scsi_config.sense_size, sizeof(adaptExt->scsi_config.sense_size)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, sense_size), + &adaptExt->scsi_config.sense_size, + sizeof(adaptExt->scsi_config.sense_size)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " sense_size %lu\n", adaptExt->scsi_config.sense_size); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, cdb_size), - &adaptExt->scsi_config.cdb_size, sizeof(adaptExt->scsi_config.cdb_size)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, cdb_size), + &adaptExt->scsi_config.cdb_size, + sizeof(adaptExt->scsi_config.cdb_size)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " cdb_size %lu\n", adaptExt->scsi_config.cdb_size); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, max_channel), - &adaptExt->scsi_config.max_channel, sizeof(adaptExt->scsi_config.max_channel)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, max_channel), + &adaptExt->scsi_config.max_channel, + sizeof(adaptExt->scsi_config.max_channel)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_channel %u\n", adaptExt->scsi_config.max_channel); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, max_target), - &adaptExt->scsi_config.max_target, sizeof(adaptExt->scsi_config.max_target)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, max_target), + &adaptExt->scsi_config.max_target, + sizeof(adaptExt->scsi_config.max_target)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_target %u\n", adaptExt->scsi_config.max_target); - virtio_get_config(&adaptExt->vdev, FIELD_OFFSET(VirtIOSCSIConfig, max_lun), - &adaptExt->scsi_config.max_lun, sizeof(adaptExt->scsi_config.max_lun)); + virtio_get_config(&adaptExt->vdev, + FIELD_OFFSET(VirtIOSCSIConfig, max_lun), + &adaptExt->scsi_config.max_lun, + sizeof(adaptExt->scsi_config.max_lun)); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_lun %lu\n", adaptExt->scsi_config.max_lun); -EXIT_FN(); + EXIT_FN(); } - -VOID -SetGuestFeatures( - IN PVOID DeviceExtension -) +VOID SetGuestFeatures(IN PVOID DeviceExtension) { - ULONGLONG guestFeatures = 0; + ULONGLONG guestFeatures = 0; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; -ENTER_FN(); + ENTER_FN(); - if (CHECKBIT(adaptExt->features, VIRTIO_F_VERSION_1)) { + if (CHECKBIT(adaptExt->features, VIRTIO_F_VERSION_1)) + { guestFeatures |= (1ULL << VIRTIO_F_VERSION_1); - if (CHECKBIT(adaptExt->features, VIRTIO_F_RING_PACKED)) { + if (CHECKBIT(adaptExt->features, VIRTIO_F_RING_PACKED)) + { guestFeatures |= (1ULL << VIRTIO_F_RING_PACKED); } } - if (CHECKBIT(adaptExt->features, VIRTIO_F_ANY_LAYOUT)) { + if (CHECKBIT(adaptExt->features, VIRTIO_F_ANY_LAYOUT)) + { guestFeatures |= (1ULL << VIRTIO_F_ANY_LAYOUT); } - if (CHECKBIT(adaptExt->features, VIRTIO_F_ACCESS_PLATFORM)) { + if (CHECKBIT(adaptExt->features, VIRTIO_F_ACCESS_PLATFORM)) + { guestFeatures |= (1ULL << VIRTIO_F_ACCESS_PLATFORM); } - if (CHECKBIT(adaptExt->features, VIRTIO_RING_F_EVENT_IDX)) { + if (CHECKBIT(adaptExt->features, VIRTIO_RING_F_EVENT_IDX)) + { guestFeatures |= (1ULL << VIRTIO_RING_F_EVENT_IDX); } - if (CHECKBIT(adaptExt->features, VIRTIO_RING_F_INDIRECT_DESC)) { + if (CHECKBIT(adaptExt->features, VIRTIO_RING_F_INDIRECT_DESC)) + { guestFeatures |= (1ULL << VIRTIO_RING_F_INDIRECT_DESC); } - if (CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_CHANGE)) { + if (CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_CHANGE)) + { guestFeatures |= (1ULL << VIRTIO_SCSI_F_CHANGE); } - if (CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_HOTPLUG)) { + if (CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_HOTPLUG)) + { guestFeatures |= (1ULL << VIRTIO_SCSI_F_HOTPLUG); } - if (!NT_SUCCESS(virtio_set_features(&adaptExt->vdev, guestFeatures))) { + if (!NT_SUCCESS(virtio_set_features(&adaptExt->vdev, guestFeatures))) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " virtio_set_features failed\n"); } -EXIT_FN(); + EXIT_FN(); } - BOOLEAN -InitVirtIODevice( - IN PVOID DeviceExtension - ) +InitVirtIODevice(IN PVOID DeviceExtension) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; NTSTATUS status; - status = virtio_device_initialize( - &adaptExt->vdev, - &VioScsiSystemOps, - adaptExt, - adaptExt->msix_enabled); - if (!NT_SUCCESS(status)) { - LogError(adaptExt, - SP_INTERNAL_ADAPTER_ERROR, - __LINE__); + status = virtio_device_initialize(&adaptExt->vdev, &VioScsiSystemOps, adaptExt, adaptExt->msix_enabled); + if (!NT_SUCCESS(status)) + { + LogError(adaptExt, SP_INTERNAL_ADAPTER_ERROR, __LINE__); RhelDbgPrint(TRACE_LEVEL_FATAL, " Failed to initialize virtio device, error %x\n", status); return FALSE; } @@ -359,33 +395,28 @@ InitVirtIODevice( } BOOLEAN -InitHW( - IN PVOID DeviceExtension, - IN PPORT_CONFIGURATION_INFORMATION ConfigInfo - ) +InitHW(IN PVOID DeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo) { - PACCESS_RANGE accessRange; + PACCESS_RANGE accessRange; PADAPTER_EXTENSION adaptExt; ULONG pci_cfg_len, i; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; adaptExt->system_io_bus_number = ConfigInfo->SystemIoBusNumber; adaptExt->slot_number = ConfigInfo->SlotNumber; /* read PCI config space */ - pci_cfg_len = StorPortGetBusData( - DeviceExtension, - PCIConfiguration, - ConfigInfo->SystemIoBusNumber, - (ULONG)ConfigInfo->SlotNumber, - (PVOID)&adaptExt->pci_config_buf, - sizeof(adaptExt->pci_config_buf)); - - if (pci_cfg_len != sizeof(adaptExt->pci_config_buf)) { - LogError(DeviceExtension, - SP_INTERNAL_ADAPTER_ERROR, - __LINE__); + pci_cfg_len = StorPortGetBusData(DeviceExtension, + PCIConfiguration, + ConfigInfo->SystemIoBusNumber, + (ULONG)ConfigInfo->SlotNumber, + (PVOID)&adaptExt->pci_config_buf, + sizeof(adaptExt->pci_config_buf)); + + if (pci_cfg_len != sizeof(adaptExt->pci_config_buf)) + { + LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); RhelDbgPrint(TRACE_LEVEL_FATAL, " CANNOT READ PCI CONFIGURATION SPACE %d\n", pci_cfg_len); return FALSE; } @@ -393,7 +424,7 @@ ENTER_FN(); { UCHAR CapOffset; PPCI_MSIX_CAPABILITY pMsixCapOffset; - PPCI_COMMON_HEADER pPciComHeader; + PPCI_COMMON_HEADER pPciComHeader; pPciComHeader = &adaptExt->pci_config; if ((pPciComHeader->Status & PCI_STATUS_CAPABILITIES_LIST) == 0) { @@ -409,21 +440,36 @@ ENTER_FN(); pMsixCapOffset = (PPCI_MSIX_CAPABILITY)&adaptExt->pci_config_buf[CapOffset]; if (pMsixCapOffset->Header.CapabilityID == PCI_CAPABILITY_ID_MSIX) { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, "MessageControl.TableSize = %d\n", pMsixCapOffset->MessageControl.TableSize); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, "MessageControl.FunctionMask = %d\n", pMsixCapOffset->MessageControl.FunctionMask); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, "MessageControl.MSIXEnable = %d\n", pMsixCapOffset->MessageControl.MSIXEnable); - - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MessageTable = %lu\n", pMsixCapOffset->MessageTable.TableOffset); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " PBATable = %lu\n", pMsixCapOffset->PBATable.TableOffset); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + "MessageControl.TableSize = %d\n", + pMsixCapOffset->MessageControl.TableSize); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + "MessageControl.FunctionMask = %d\n", + pMsixCapOffset->MessageControl.FunctionMask); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + "MessageControl.MSIXEnable = %d\n", + pMsixCapOffset->MessageControl.MSIXEnable); + + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " MessageTable = %lu\n", + pMsixCapOffset->MessageTable.TableOffset); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " PBATable = %lu\n", + pMsixCapOffset->PBATable.TableOffset); adaptExt->msix_enabled = (pMsixCapOffset->MessageControl.MSIXEnable == 1); - } else + } + else { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " CapabilityID = %x, Next CapOffset = %x\n", pMsixCapOffset->Header.CapabilityID, CapOffset); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " CapabilityID = %x, Next CapOffset = %x\n", + pMsixCapOffset->Header.CapabilityID, + CapOffset); } CapOffset = pMsixCapOffset->Header.Next; } RhelDbgPrint(TRACE_LEVEL_INFORMATION, " msix_enabled = %d\n", adaptExt->msix_enabled); - } else + } + else { RhelDbgPrint(TRACE_LEVEL_FATAL, " NOT A PCI_DEVICE_TYPE\n"); } @@ -431,13 +477,15 @@ ENTER_FN(); } /* initialize the pci_bars array */ - for (i = 0; i < ConfigInfo->NumberOfAccessRanges; i++) { + for (i = 0; i < ConfigInfo->NumberOfAccessRanges; i++) + { accessRange = *ConfigInfo->AccessRanges + i; - if (accessRange->RangeLength != 0) { + if (accessRange->RangeLength != 0) + { int iBar = virtio_get_bar_index(&adaptExt->pci_config, accessRange->RangeStart); - if (iBar == -1) { - RhelDbgPrint(TRACE_LEVEL_FATAL, - " Cannot get index for BAR %I64d\n", accessRange->RangeStart.QuadPart); + if (iBar == -1) + { + RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot get index for BAR %I64d\n", accessRange->RangeStart.QuadPart); return FALSE; } adaptExt->pci_bars[iBar].BasePA = accessRange->RangeStart; @@ -447,167 +495,175 @@ ENTER_FN(); } /* initialize the virtual device */ - if (!InitVirtIODevice(DeviceExtension)) { + if (!InitVirtIODevice(DeviceExtension)) + { return FALSE; } -EXIT_FN(); + EXIT_FN(); return TRUE; } BOOLEAN -SynchronizedKickEventRoutine( - IN PVOID DeviceExtension, - IN PVOID Context - ) +SynchronizedKickEventRoutine(IN PVOID DeviceExtension, IN PVOID Context) { - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - PVirtIOSCSIEventNode eventNode = (PVirtIOSCSIEventNode) Context; - PVOID va = NULL; - ULONGLONG pa = 0; - -ENTER_FN(); - if (virtqueue_add_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], - &eventNode->sg, - 0, 1, - eventNode, va, pa) >= 0){ + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; + PVirtIOSCSIEventNode eventNode = (PVirtIOSCSIEventNode)Context; + PVOID va = NULL; + ULONGLONG pa = 0; + + ENTER_FN(); + if (virtqueue_add_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], &eventNode->sg, 0, 1, eventNode, va, pa) >= 0) + { virtqueue_kick(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE]); -EXIT_FN(); + EXIT_FN(); return TRUE; } -EXIT_ERR(); + EXIT_ERR(); return FALSE; } - BOOLEAN -KickEvent( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEventNode EventNode - ) +KickEvent(IN PVOID DeviceExtension, IN PVirtIOSCSIEventNode EventNode) { PADAPTER_EXTENSION adaptExt; - ULONG fragLen; + ULONG fragLen; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; RtlZeroMemory((PVOID)EventNode, sizeof(VirtIOSCSIEventNode)); EventNode->sg.physAddr = StorPortGetPhysicalAddress(DeviceExtension, NULL, &EventNode->event, &fragLen); - EventNode->sg.length = sizeof(VirtIOSCSIEvent); + EventNode->sg.length = sizeof(VirtIOSCSIEvent); return SynchronizedKickEventRoutine(DeviceExtension, (PVOID)EventNode); -EXIT_FN(); + EXIT_FN(); } -VOID FirmwareRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { - PADAPTER_EXTENSION adaptExt; - PSRB_EXTENSION srbExt = NULL; - ULONG dataLen = 0; - PSRB_IO_CONTROL srbControl = NULL; + PADAPTER_EXTENSION adaptExt; + PSRB_EXTENSION srbExt = NULL; + ULONG dataLen = 0; + PSRB_IO_CONTROL srbControl = NULL; PFIRMWARE_REQUEST_BLOCK firmwareRequest = NULL; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; srbExt = SRB_EXTENSION(Srb); srbControl = (PSRB_IO_CONTROL)SRB_DATA_BUFFER(Srb); dataLen = SRB_DATA_TRANSFER_LENGTH(Srb); - if (dataLen < (sizeof(SRB_IO_CONTROL) + sizeof(FIRMWARE_REQUEST_BLOCK))) { + if (dataLen < (sizeof(SRB_IO_CONTROL) + sizeof(FIRMWARE_REQUEST_BLOCK))) + { srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); - RhelDbgPrint(TRACE_LEVEL_ERROR, - " FirmwareRequest Bad Block Length %ul\n", dataLen); + RhelDbgPrint(TRACE_LEVEL_ERROR, " FirmwareRequest Bad Block Length %ul\n", dataLen); return; } firmwareRequest = (PFIRMWARE_REQUEST_BLOCK)(srbControl + 1); - switch (firmwareRequest->Function) { - - case FIRMWARE_FUNCTION_GET_INFO: { - PSTORAGE_FIRMWARE_INFO_V2 firmwareInfo; - firmwareInfo = (PSTORAGE_FIRMWARE_INFO_V2)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " FIRMWARE_FUNCTION_GET_INFO \n"); - if ((firmwareInfo->Version >= STORAGE_FIRMWARE_INFO_STRUCTURE_VERSION_V2) || - (firmwareInfo->Size >= sizeof(STORAGE_FIRMWARE_INFO_V2))) { - firmwareInfo->Version = STORAGE_FIRMWARE_INFO_STRUCTURE_VERSION_V2; - firmwareInfo->Size = sizeof(STORAGE_FIRMWARE_INFO_V2); - - firmwareInfo->UpgradeSupport = TRUE; - - firmwareInfo->SlotCount = 1; - firmwareInfo->ActiveSlot = 0; - firmwareInfo->PendingActivateSlot = STORAGE_FIRMWARE_INFO_INVALID_SLOT; - firmwareInfo->FirmwareShared = FALSE; - firmwareInfo->ImagePayloadAlignment = PAGE_SIZE; - firmwareInfo->ImagePayloadMaxSize = PAGE_SIZE; - - if (firmwareRequest->DataBufferLength >= (sizeof(STORAGE_FIRMWARE_INFO_V2) + sizeof(STORAGE_FIRMWARE_SLOT_INFO_V2))) { - firmwareInfo->Slot[0].SlotNumber = 0; - firmwareInfo->Slot[0].ReadOnly = FALSE; - StorPortCopyMemory(&firmwareInfo->Slot[0].Revision, &adaptExt->fw_ver, sizeof (adaptExt->fw_ver)); - srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; - } else { - firmwareRequest->DataBufferLength = sizeof(STORAGE_FIRMWARE_INFO_V2) + sizeof(STORAGE_FIRMWARE_SLOT_INFO_V2); - srbControl->ReturnCode = FIRMWARE_STATUS_OUTPUT_BUFFER_TOO_SMALL; + switch (firmwareRequest->Function) + { + + case FIRMWARE_FUNCTION_GET_INFO: + { + PSTORAGE_FIRMWARE_INFO_V2 firmwareInfo; + firmwareInfo = (PSTORAGE_FIRMWARE_INFO_V2)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " FIRMWARE_FUNCTION_GET_INFO \n"); + if ((firmwareInfo->Version >= STORAGE_FIRMWARE_INFO_STRUCTURE_VERSION_V2) || + (firmwareInfo->Size >= sizeof(STORAGE_FIRMWARE_INFO_V2))) + { + firmwareInfo->Version = STORAGE_FIRMWARE_INFO_STRUCTURE_VERSION_V2; + firmwareInfo->Size = sizeof(STORAGE_FIRMWARE_INFO_V2); + + firmwareInfo->UpgradeSupport = TRUE; + + firmwareInfo->SlotCount = 1; + firmwareInfo->ActiveSlot = 0; + firmwareInfo->PendingActivateSlot = STORAGE_FIRMWARE_INFO_INVALID_SLOT; + firmwareInfo->FirmwareShared = FALSE; + firmwareInfo->ImagePayloadAlignment = PAGE_SIZE; + firmwareInfo->ImagePayloadMaxSize = PAGE_SIZE; + + if (firmwareRequest->DataBufferLength >= + (sizeof(STORAGE_FIRMWARE_INFO_V2) + sizeof(STORAGE_FIRMWARE_SLOT_INFO_V2))) + { + firmwareInfo->Slot[0].SlotNumber = 0; + firmwareInfo->Slot[0].ReadOnly = FALSE; + StorPortCopyMemory(&firmwareInfo->Slot[0].Revision, + &adaptExt->fw_ver, + sizeof(adaptExt->fw_ver)); + srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; + } + else + { + firmwareRequest->DataBufferLength = sizeof(STORAGE_FIRMWARE_INFO_V2) + + sizeof(STORAGE_FIRMWARE_SLOT_INFO_V2); + srbControl->ReturnCode = FIRMWARE_STATUS_OUTPUT_BUFFER_TOO_SMALL; + } + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); + } + else + { + RhelDbgPrint(TRACE_LEVEL_ERROR, + " Wrong Version %ul or Size %ul\n", + firmwareInfo->Version, + firmwareInfo->Size); + srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); + } } - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); - } - else { - RhelDbgPrint(TRACE_LEVEL_ERROR, - " Wrong Version %ul or Size %ul\n", firmwareInfo->Version, firmwareInfo->Size); - srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); - } - } - break; - case FIRMWARE_FUNCTION_DOWNLOAD: { - PSTORAGE_FIRMWARE_DOWNLOAD_V2 firmwareDwnld; - firmwareDwnld = (PSTORAGE_FIRMWARE_DOWNLOAD_V2)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " FIRMWARE_FUNCTION_DOWNLOAD \n"); - if ((firmwareDwnld->Version >= STORAGE_FIRMWARE_DOWNLOAD_STRUCTURE_VERSION_V2) || - (firmwareDwnld->Size >= sizeof(STORAGE_FIRMWARE_DOWNLOAD_V2))) { - firmwareDwnld->Version = STORAGE_FIRMWARE_DOWNLOAD_STRUCTURE_VERSION_V2; - firmwareDwnld->Size = sizeof(STORAGE_FIRMWARE_DOWNLOAD_V2); - adaptExt->fw_ver++; - srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); - } - else { - RhelDbgPrint(TRACE_LEVEL_ERROR, - " Wrong Version %ul or Size %ul\n", firmwareDwnld->Version, firmwareDwnld->Size); - srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); - } - } - break; - case FIRMWARE_FUNCTION_ACTIVATE: { - PSTORAGE_FIRMWARE_ACTIVATE firmwareActivate; - firmwareActivate = (PSTORAGE_FIRMWARE_ACTIVATE)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); - if ((firmwareActivate->Version == STORAGE_FIRMWARE_ACTIVATE_STRUCTURE_VERSION) || - (firmwareActivate->Size >= sizeof(STORAGE_FIRMWARE_ACTIVATE))) { - firmwareActivate->Version = STORAGE_FIRMWARE_ACTIVATE_STRUCTURE_VERSION; - firmwareActivate->Size = sizeof(STORAGE_FIRMWARE_ACTIVATE); - srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); - } - else { - RhelDbgPrint(TRACE_LEVEL_ERROR, - " Wrong Version %ul or Size %ul\n", firmwareActivate->Version, firmwareActivate->Size); - srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); - } - RhelDbgPrint(TRACE_LEVEL_VERBOSE, - " FIRMWARE_FUNCTION_ACTIVATE \n"); - } - break; - default: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " Unsupported Function %ul\n", firmwareRequest->Function); - SRB_SET_SRB_STATUS(Srb, SRB_STATUS_INVALID_REQUEST); - break; + break; + case FIRMWARE_FUNCTION_DOWNLOAD: + { + PSTORAGE_FIRMWARE_DOWNLOAD_V2 firmwareDwnld; + firmwareDwnld = (PSTORAGE_FIRMWARE_DOWNLOAD_V2)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " FIRMWARE_FUNCTION_DOWNLOAD \n"); + if ((firmwareDwnld->Version >= STORAGE_FIRMWARE_DOWNLOAD_STRUCTURE_VERSION_V2) || + (firmwareDwnld->Size >= sizeof(STORAGE_FIRMWARE_DOWNLOAD_V2))) + { + firmwareDwnld->Version = STORAGE_FIRMWARE_DOWNLOAD_STRUCTURE_VERSION_V2; + firmwareDwnld->Size = sizeof(STORAGE_FIRMWARE_DOWNLOAD_V2); + adaptExt->fw_ver++; + srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); + } + else + { + RhelDbgPrint(TRACE_LEVEL_ERROR, + " Wrong Version %ul or Size %ul\n", + firmwareDwnld->Version, + firmwareDwnld->Size); + srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); + } + } + break; + case FIRMWARE_FUNCTION_ACTIVATE: + { + PSTORAGE_FIRMWARE_ACTIVATE firmwareActivate; + firmwareActivate = (PSTORAGE_FIRMWARE_ACTIVATE)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); + if ((firmwareActivate->Version == STORAGE_FIRMWARE_ACTIVATE_STRUCTURE_VERSION) || + (firmwareActivate->Size >= sizeof(STORAGE_FIRMWARE_ACTIVATE))) + { + firmwareActivate->Version = STORAGE_FIRMWARE_ACTIVATE_STRUCTURE_VERSION; + firmwareActivate->Size = sizeof(STORAGE_FIRMWARE_ACTIVATE); + srbControl->ReturnCode = FIRMWARE_STATUS_SUCCESS; + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); + } + else + { + RhelDbgPrint(TRACE_LEVEL_ERROR, + " Wrong Version %ul or Size %ul\n", + firmwareActivate->Version, + firmwareActivate->Size); + srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); + } + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " FIRMWARE_FUNCTION_ACTIVATE \n"); + } + break; + default: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unsupported Function %ul\n", firmwareRequest->Function); + SRB_SET_SRB_STATUS(Srb, SRB_STATUS_INVALID_REQUEST); + break; } -EXIT_FN(); + EXIT_FN(); } diff --git a/vioscsi/helper.h b/vioscsi/helper.h old mode 100755 new mode 100644 index ee00db582..13f2d2e62 --- a/vioscsi/helper.h +++ b/vioscsi/helper.h @@ -32,174 +32,116 @@ #ifndef ___HELPER_H___ #define ___HELPER_H___ - #include #include #include - #include "osdep.h" #include "virtio_pci.h" #include "virtio_ring.h" #include "vioscsi.h" -#define CHECKBIT(value, nbit) virtio_is_feature_enabled(value, nbit) -#define CHECKFLAG(value, flag) ((value & (flag)) == flag) -#define SETFLAG(value, flag) (value |= (flag)) +#define CHECKBIT(value, nbit) virtio_is_feature_enabled(value, nbit) +#define CHECKFLAG(value, flag) ((value & (flag)) == flag) +#define SETFLAG(value, flag) (value |= (flag)) -#define CACHE_LINE_SIZE 64 -#define ROUND_TO_CACHE_LINES(Size) (((ULONG_PTR)(Size) + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)) +#define CACHE_LINE_SIZE 64 +#define ROUND_TO_CACHE_LINES(Size) (((ULONG_PTR)(Size) + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)) #include // Note: SrbGetCdbLength is defined in srbhelper.h -FORCEINLINE ULONG -SrbGetCdbLength32(_In_ PVOID Srb) { +FORCEINLINE ULONG SrbGetCdbLength32(_In_ PVOID Srb) +{ ULONG CdbLen32 = 0; UCHAR CdbLen8 = 0; SrbGetScsiData(Srb, &CdbLen8, &CdbLen32, NULL, NULL, NULL); return (CdbLen8 != 0) ? CdbLen8 : CdbLen32; } -FORCEINLINE VOID -SrbGetPnpInfo(_In_ PVOID Srb, ULONG* PnPFlags, ULONG* PnPAction) { +FORCEINLINE VOID SrbGetPnpInfo(_In_ PVOID Srb, ULONG *PnPFlags, ULONG *PnPAction) +{ PSCSI_PNP_REQUEST_BLOCK pPnpSrb = NULL; PSRBEX_DATA_PNP pSrbExPnp = NULL; - pSrbExPnp = (PSRBEX_DATA_PNP)SrbGetSrbExDataByType( - (PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypePnP); - if (pSrbExPnp != NULL) { + pSrbExPnp = (PSRBEX_DATA_PNP)SrbGetSrbExDataByType((PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypePnP); + if (pSrbExPnp != NULL) + { *PnPFlags = pSrbExPnp->SrbPnPFlags; *PnPAction = pSrbExPnp->PnPAction; } - else { + else + { pPnpSrb = (PSCSI_PNP_REQUEST_BLOCK)Srb; *PnPFlags = pPnpSrb->SrbPnPFlags; *PnPAction = pPnpSrb->PnPAction; } } -#define PSRB_TYPE PSTORAGE_REQUEST_BLOCK -#define PSRB_WMI_DATA PSRBEX_DATA_WMI +#define PSRB_TYPE PSTORAGE_REQUEST_BLOCK +#define PSRB_WMI_DATA PSRBEX_DATA_WMI #define PSTOR_DEVICE_CAPABILITIES_TYPE PSTOR_DEVICE_CAPABILITIES_EX -#define SRB_EXTENSION(Srb) SrbGetMiniportContext(Srb) -#define SRB_FUNCTION(Srb) SrbGetSrbFunction(Srb) -#define SRB_CDB(Srb) SrbGetCdb(Srb) -#define SRB_CDB_LENGTH(Srb) SrbGetCdbLength32(Srb) -#define SRB_FLAGS(Srb) SrbGetSrbFlags(Srb) -#define SRB_PATH_ID(Srb) SrbGetPathId(Srb) -#define SRB_TARGET_ID(Srb) SrbGetTargetId(Srb) -#define SRB_LUN(Srb) SrbGetLun(Srb) -#define SRB_DATA_BUFFER(Srb) SrbGetDataBuffer(Srb) -#define SRB_DATA_TRANSFER_LENGTH(Srb) SrbGetDataTransferLength(Srb) -#define SRB_LENGTH(Srb) SrbGetSrbLength(Srb) -#define SRB_WMI_DATA(Srb) (PSRBEX_DATA_WMI)SrbGetSrbExDataByType((PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypeWmi) -#define SRB_GET_SENSE_INFO(Srb, senseInfoBuffer, senseInfoBufferLen) SrbGetScsiData(Srb, NULL, NULL, NULL, &senseInfoBuffer, &senseInfoBufferLen) +#define SRB_EXTENSION(Srb) SrbGetMiniportContext(Srb) +#define SRB_FUNCTION(Srb) SrbGetSrbFunction(Srb) +#define SRB_CDB(Srb) SrbGetCdb(Srb) +#define SRB_CDB_LENGTH(Srb) SrbGetCdbLength32(Srb) +#define SRB_FLAGS(Srb) SrbGetSrbFlags(Srb) +#define SRB_PATH_ID(Srb) SrbGetPathId(Srb) +#define SRB_TARGET_ID(Srb) SrbGetTargetId(Srb) +#define SRB_LUN(Srb) SrbGetLun(Srb) +#define SRB_DATA_BUFFER(Srb) SrbGetDataBuffer(Srb) +#define SRB_DATA_TRANSFER_LENGTH(Srb) SrbGetDataTransferLength(Srb) +#define SRB_LENGTH(Srb) SrbGetSrbLength(Srb) +#define SRB_WMI_DATA(Srb) (PSRBEX_DATA_WMI) SrbGetSrbExDataByType((PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypeWmi) +#define SRB_GET_SENSE_INFO(Srb, senseInfoBuffer, senseInfoBufferLen) \ + SrbGetScsiData(Srb, NULL, NULL, NULL, &senseInfoBuffer, &senseInfoBufferLen) #define SRB_GET_PNP_INFO(Srb, PnPFlags, PnPAction) SrbGetPnpInfo(Srb, &PnPFlags, &PnPAction) -#define SRB_SET_SCSI_STATUS(Srb, status) SrbSetScsiData(Srb, NULL, NULL, &status, NULL, NULL) -#define SRB_GET_SCSI_STATUS(Srb, status) SrbGetScsiData(Srb, NULL, NULL, &status, NULL, NULL) -#define SRB_SET_SRB_STATUS(Srb, status) SrbSetSrbStatus(Srb, status) -#define SRB_GET_SRB_STATUS(Srb, status) status = SrbSetSrbStatus(Srb) -#define SRB_SET_DATA_TRANSFER_LENGTH(Srb, Len) SrbSetDataTransferLength(Srb, Len) -#define SRB_GET_TIMEOUTVALUE(Srb) SrbGetTimeOutValue(Srb) +#define SRB_SET_SCSI_STATUS(Srb, status) SrbSetScsiData(Srb, NULL, NULL, &status, NULL, NULL) +#define SRB_GET_SCSI_STATUS(Srb, status) SrbGetScsiData(Srb, NULL, NULL, &status, NULL, NULL) +#define SRB_SET_SRB_STATUS(Srb, status) SrbSetSrbStatus(Srb, status) +#define SRB_GET_SRB_STATUS(Srb, status) status = SrbSetSrbStatus(Srb) +#define SRB_SET_DATA_TRANSFER_LENGTH(Srb, Len) SrbSetDataTransferLength(Srb, Len) +#define SRB_GET_TIMEOUTVALUE(Srb) SrbGetTimeOutValue(Srb) -VOID -SendSRB( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ); +VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); BOOLEAN -SendTMF( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ); +SendTMF(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb); -VOID -ShutDown( - IN PVOID DeviceExtension - ); +VOID ShutDown(IN PVOID DeviceExtension); BOOLEAN -DeviceReset( - IN PVOID DeviceExtension - ); +DeviceReset(IN PVOID DeviceExtension); -VOID -GetScsiConfig( - IN PVOID DeviceExtension - ); -VOID -SetGuestFeatures( - IN PVOID DeviceExtension - ); +VOID GetScsiConfig(IN PVOID DeviceExtension); +VOID SetGuestFeatures(IN PVOID DeviceExtension); BOOLEAN -InitVirtIODevice( - IN PVOID DeviceExtension - ); +InitVirtIODevice(IN PVOID DeviceExtension); BOOLEAN -InitHW( - IN PVOID DeviceExtension, - IN PPORT_CONFIGURATION_INFORMATION ConfigInfo - ); +InitHW(IN PVOID DeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo); -VOID -LogError( - IN PVOID HwDeviceExtension, - IN ULONG ErrorCode, - IN ULONG UniqueId - ); +VOID LogError(IN PVOID HwDeviceExtension, IN ULONG ErrorCode, IN ULONG UniqueId); BOOLEAN -KickEvent( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEventNode event - ); +KickEvent(IN PVOID DeviceExtension, IN PVirtIOSCSIEventNode event); BOOLEAN -SynchronizedKickEventRoutine( - IN PVOID DeviceExtension, - IN PVOID Context - ); +SynchronizedKickEventRoutine(IN PVOID DeviceExtension, IN PVOID Context); -VOID -VioScsiCompleteDpcRoutine( - IN PSTOR_DPC Dpc, - IN PVOID Context, - IN PVOID SystemArgument1, - IN PVOID SystemArgument2 -); +VOID VioScsiCompleteDpcRoutine(IN PSTOR_DPC Dpc, IN PVOID Context, IN PVOID SystemArgument1, IN PVOID SystemArgument2); -VOID -ProcessBuffer( - IN PVOID DeviceExtension, - IN ULONG MessageId, - IN STOR_SPINLOCK LockMode - ); +VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOCK LockMode); VOID -//FORCEINLINE -HandleResponse( - IN PVOID DeviceExtension, - IN PVirtIOSCSICmd cmd - ); +// FORCEINLINE +HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd); PVOID -VioScsiPoolAlloc( - IN PVOID DeviceExtension, - IN SIZE_T size - ); +VioScsiPoolAlloc(IN PVOID DeviceExtension, IN SIZE_T size); -VOID -CompleteRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ); - -VOID FirmwareRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ); +VOID CompleteRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); + +VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); extern VirtIOSystemOps VioScsiSystemOps; diff --git a/vioscsi/resources.h b/vioscsi/resources.h index ca80ef2a4..664440448 100644 --- a/vioscsi/resources.h +++ b/vioscsi/resources.h @@ -31,22 +31,22 @@ #ifndef ___RESOURCES_H__ #define ___RESOURCES_H__ -#define VENDORID 0x1AF4 -#define PRODUCTID 0x1004 -#define MANUFACTURER L"Red Hat, Inc." -#define SERIALNUMBER L"" -#define MODEL L"VirtIO-SCSI" -#define MODELDESCRIPTION L"Red Hat VirtIO SCSI pass-through controller" -#define HARDWAREVERSION L"v1.0" -#define DRIVERVERSION L"v1.0" -#define OPTIONROMVERSION L"v1.0" -#define FIRMWAREVERSION L"v1.0" -#define DRIVERNAME L"vioscsi.sys" -#define HBASYMBOLICNAME L"Red Hat VirtIO SCSI pass-through controller" -#define REDUNDANTOPTIONROMVERSION OPTIONROMVERSION -#define REDUNDANTFIRMWAREVERSION FIRMWAREVERSION -#define MFRDOMAIN L"Red Hat, Inc." -#define PORTSYMBOLICNAME L"PortSymbolicName" -#define CLUSDISK L"CLUSDISK" -#define HBA_ID 1234567890987654321ULL +#define VENDORID 0x1AF4 +#define PRODUCTID 0x1004 +#define MANUFACTURER L"Red Hat, Inc." +#define SERIALNUMBER L"" +#define MODEL L"VirtIO-SCSI" +#define MODELDESCRIPTION L"Red Hat VirtIO SCSI pass-through controller" +#define HARDWAREVERSION L"v1.0" +#define DRIVERVERSION L"v1.0" +#define OPTIONROMVERSION L"v1.0" +#define FIRMWAREVERSION L"v1.0" +#define DRIVERNAME L"vioscsi.sys" +#define HBASYMBOLICNAME L"Red Hat VirtIO SCSI pass-through controller" +#define REDUNDANTOPTIONROMVERSION OPTIONROMVERSION +#define REDUNDANTFIRMWAREVERSION FIRMWAREVERSION +#define MFRDOMAIN L"Red Hat, Inc." +#define PORTSYMBOLICNAME L"PortSymbolicName" +#define CLUSDISK L"CLUSDISK" +#define HBA_ID 1234567890987654321ULL #endif //___RESOURCES_H__ diff --git a/vioscsi/utils.c b/vioscsi/utils.c old mode 100755 new mode 100644 index 5a86003ae..e041a5eac --- a/vioscsi/utils.c +++ b/vioscsi/utils.c @@ -34,14 +34,13 @@ int virtioDebugLevel; int bDebugPrint; int nVioscsiDebugLevel; - #if !defined(EVENT_TRACING) #if defined(COM_DEBUG) #include -#define RHEL_DEBUG_PORT ((PUCHAR)0x3F8) -#define TEMP_BUFFER_SIZE 256 +#define RHEL_DEBUG_PORT ((PUCHAR)0x3F8) +#define TEMP_BUFFER_SIZE 256 static void DebugPrintFuncSerial(const char *format, ...) { @@ -79,13 +78,12 @@ static void DebugPrintFunc(const char *format, ...) #else static void NoDebugPrintFunc(const char *format, ...) { - } #endif -void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) +void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { - //TBD - Read nDebugLevel and bDebugPrint from the registry + // TBD - Read nDebugLevel and bDebugPrint from the registry bDebugPrint = 1; virtioDebugLevel = 0; #if !defined(RUN_UNCHECKED) @@ -102,19 +100,22 @@ void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING R } #else -static void NoDebugPrintFunc(const char *format, ...) {} // This is NOT strictly required for ETW -void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) +static void NoDebugPrintFunc(const char *format, ...) +{ +} // This is NOT strictly required for ETW +void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { - VirtioDebugPrintProc = NoDebugPrintFunc; // This is NOT strictly required for ETW - neither DbgPrint nor DbgPrintEx will be called when EVENT_TRACING is defined + VirtioDebugPrintProc = NoDebugPrintFunc; // This is NOT strictly required for ETW - neither DbgPrint nor DbgPrintEx + // will be called when EVENT_TRACING is defined } #endif tDebugPrintFunc VirtioDebugPrintProc; // This is necessary for compilation due to VirtIO\kdebugprint.h requisites #undef MAKE_CASE -#define MAKE_CASE(scsiOpCode) \ - case scsiOpCode: \ - scsiOpStr = #scsiOpCode; \ +#define MAKE_CASE(scsiOpCode) \ + case scsiOpCode: \ + scsiOpStr = #scsiOpCode; \ break; char *DbgGetScsiOpStr(IN UCHAR opCode) @@ -122,31 +123,31 @@ char *DbgGetScsiOpStr(IN UCHAR opCode) char *scsiOpStr = "?"; switch (opCode) { - MAKE_CASE(SCSIOP_TEST_UNIT_READY) // Code 0x00 - MAKE_CASE(SCSIOP_REWIND) // Code 0x01 - MAKE_CASE(SCSIOP_REQUEST_BLOCK_ADDR) // Code 0x02 - MAKE_CASE(SCSIOP_REQUEST_SENSE) // Code 0x03 - MAKE_CASE(SCSIOP_FORMAT_UNIT) // Code 0x04 - MAKE_CASE(SCSIOP_READ_BLOCK_LIMITS) // Code 0x05 - MAKE_CASE(SCSIOP_INIT_ELEMENT_STATUS) // Code 0x07, aka SCSIOP_REASSIGN_BLOCKS - MAKE_CASE(SCSIOP_READ6) // Code 0x08, aka SCSIOP_RECEIVE - MAKE_CASE(SCSIOP_WRITE6) // Code 0x0A, aka SCSIOP_PRINT, SCSIOP_SEND - MAKE_CASE(SCSIOP_SEEK6) // Code 0x0B, aka SCSIOP_SET_CAPACITY, SCSIOP_SLEW_PRINT, SCSIOP_TRACK_SELECT - MAKE_CASE(SCSIOP_SEEK_BLOCK) // Code 0x0C - MAKE_CASE(SCSIOP_PARTITION) // Code 0x0D - MAKE_CASE(SCSIOP_READ_REVERSE) // Code 0x0F - MAKE_CASE(SCSIOP_FLUSH_BUFFER) // Code 0x10, aka SCSIOP_WRITE_FILEMARKS - MAKE_CASE(SCSIOP_SPACE) // Code 0x11 - MAKE_CASE(SCSIOP_INQUIRY) // Code 0x12 - MAKE_CASE(SCSIOP_VERIFY6) // Code 0x13 - MAKE_CASE(SCSIOP_RECOVER_BUF_DATA) // Code 0x14 - MAKE_CASE(SCSIOP_MODE_SELECT) // Code 0x15 - MAKE_CASE(SCSIOP_RESERVE_UNIT) // Code 0x16 - MAKE_CASE(SCSIOP_RELEASE_UNIT) // Code 0x17 - MAKE_CASE(SCSIOP_COPY) // Code 0x18 - MAKE_CASE(SCSIOP_ERASE) // Code 0x19 - MAKE_CASE(SCSIOP_MODE_SENSE) // Code 0x1A - MAKE_CASE(SCSIOP_START_STOP_UNIT) // Code 0x1B, aka SCSIOP_LOAD_UNLOAD, SCSIOP_STOP_PRINT + MAKE_CASE(SCSIOP_TEST_UNIT_READY) // Code 0x00 + MAKE_CASE(SCSIOP_REWIND) // Code 0x01 + MAKE_CASE(SCSIOP_REQUEST_BLOCK_ADDR) // Code 0x02 + MAKE_CASE(SCSIOP_REQUEST_SENSE) // Code 0x03 + MAKE_CASE(SCSIOP_FORMAT_UNIT) // Code 0x04 + MAKE_CASE(SCSIOP_READ_BLOCK_LIMITS) // Code 0x05 + MAKE_CASE(SCSIOP_INIT_ELEMENT_STATUS) // Code 0x07, aka SCSIOP_REASSIGN_BLOCKS + MAKE_CASE(SCSIOP_READ6) // Code 0x08, aka SCSIOP_RECEIVE + MAKE_CASE(SCSIOP_WRITE6) // Code 0x0A, aka SCSIOP_PRINT, SCSIOP_SEND + MAKE_CASE(SCSIOP_SEEK6) // Code 0x0B, aka SCSIOP_SET_CAPACITY, SCSIOP_SLEW_PRINT, SCSIOP_TRACK_SELECT + MAKE_CASE(SCSIOP_SEEK_BLOCK) // Code 0x0C + MAKE_CASE(SCSIOP_PARTITION) // Code 0x0D + MAKE_CASE(SCSIOP_READ_REVERSE) // Code 0x0F + MAKE_CASE(SCSIOP_FLUSH_BUFFER) // Code 0x10, aka SCSIOP_WRITE_FILEMARKS + MAKE_CASE(SCSIOP_SPACE) // Code 0x11 + MAKE_CASE(SCSIOP_INQUIRY) // Code 0x12 + MAKE_CASE(SCSIOP_VERIFY6) // Code 0x13 + MAKE_CASE(SCSIOP_RECOVER_BUF_DATA) // Code 0x14 + MAKE_CASE(SCSIOP_MODE_SELECT) // Code 0x15 + MAKE_CASE(SCSIOP_RESERVE_UNIT) // Code 0x16 + MAKE_CASE(SCSIOP_RELEASE_UNIT) // Code 0x17 + MAKE_CASE(SCSIOP_COPY) // Code 0x18 + MAKE_CASE(SCSIOP_ERASE) // Code 0x19 + MAKE_CASE(SCSIOP_MODE_SENSE) // Code 0x1A + MAKE_CASE(SCSIOP_START_STOP_UNIT) // Code 0x1B, aka SCSIOP_LOAD_UNLOAD, SCSIOP_STOP_PRINT MAKE_CASE(SCSIOP_RECEIVE_DIAGNOSTIC) // Code 0x1C MAKE_CASE(SCSIOP_SEND_DIAGNOSTIC) // Code 0x1D MAKE_CASE(SCSIOP_MEDIUM_REMOVAL) // Code 0x1E @@ -221,41 +222,42 @@ char *DbgGetScsiOpStr(IN UCHAR opCode) MAKE_CASE(SCSIOP_ZBC_OUT) // Code 0x94 MAKE_CASE(SCSIOP_ZBC_IN) // Code 0x95 MAKE_CASE(SCSIOP_READ_DATA_BUFF16) // Code 0x9B - MAKE_CASE(SCSIOP_GET_LBA_STATUS) // Code 0x9E, aka SCSIOP_GET_PHYSICAL_ELEMENT_STATUS, SCSIOP_READ_CAPACITY16, SCSIOP_REMOVE_ELEMENT_AND_TRUNCATE, SCSIOP_SERVICE_ACTION_IN16 - MAKE_CASE(SCSIOP_SERVICE_ACTION_OUT16) // Code 0x9F - MAKE_CASE(SCSIOP_REPORT_LUNS) // Code 0xA0 - MAKE_CASE(SCSIOP_BLANK) // Code 0xA1, aka SCSIOP_ATA_PASSTHROUGH12 - MAKE_CASE(SCSIOP_SEND_EVENT) // Code 0xA2 - MAKE_CASE(SCSIOP_MAINTENANCE_IN) // Code 0xA3, aka SCSIOP_SEND_KEY - MAKE_CASE(SCSIOP_MAINTENANCE_OUT) // Code 0xA4, aka SCSIOP_REPORT_KEY - MAKE_CASE(SCSIOP_MOVE_MEDIUM) // Code 0xA5 - MAKE_CASE(SCSIOP_LOAD_UNLOAD_SLOT) // Code 0xA6 - MAKE_CASE(SCSIOP_SET_READ_AHEAD) // Code 0xA7 - MAKE_CASE(SCSIOP_READ12) // Code 0xA8 - MAKE_CASE(SCSIOP_SERVICE_ACTION_OUT12) // Code 0xA9 - MAKE_CASE(SCSIOP_WRITE12) // Code 0xAA - MAKE_CASE(SCSIOP_SEND_MESSAGE) // Code 0xAB - MAKE_CASE(SCSIOP_GET_PERFORMANCE) // Code 0xAC - MAKE_CASE(SCSIOP_READ_DVD_STRUCTURE) // Code 0xAD - MAKE_CASE(SCSIOP_WRITE_VERIFY12) // Code 0xAE - MAKE_CASE(SCSIOP_VERIFY12) // Code 0xAF - MAKE_CASE(SCSIOP_SEARCH_DATA_HIGH12) // Code 0xB0 - MAKE_CASE(SCSIOP_SEARCH_DATA_EQUAL12) // Code 0xB1 - MAKE_CASE(SCSIOP_SEARCH_DATA_LOW12) // Code 0xB2 - MAKE_CASE(SCSIOP_SET_LIMITS12) // Code 0xB3 - MAKE_CASE(SCSIOP_READ_ELEMENT_STATUS_ATTACHED) // Code 0xB4 - MAKE_CASE(SCSIOP_REQUEST_VOL_ELEMENT) // Code 0xB5, aka SCSIOP_SECURITY_PROTOCOL_OUT - MAKE_CASE(SCSIOP_SEND_VOLUME_TAG) // Code 0xB6 - MAKE_CASE(SCSIOP_READ_DEFECT_DATA) // Code 0xB7 - MAKE_CASE(SCSIOP_READ_ELEMENT_STATUS) // Code 0xB8 - MAKE_CASE(SCSIOP_READ_CD_MSF) // Code 0xB9 - MAKE_CASE(SCSIOP_REDUNDANCY_GROUP_IN) // Code 0xBA - MAKE_CASE(SCSIOP_REDUNDANCY_GROUP_OUT) // Code 0xBB - MAKE_CASE(SCSIOP_SPARE_IN) // Code 0xBC - MAKE_CASE(SCSIOP_SPARE_OUT) // Code 0xBD, aka SCSIOP_MECHANISM_STATUS - MAKE_CASE(SCSIOP_VOLUME_SET_IN) // Code 0xBE - MAKE_CASE(SCSIOP_VOLUME_SET_OUT) // Code 0xBF - MAKE_CASE(SCSIOP_INIT_ELEMENT_RANGE) // Code 0xE7 + MAKE_CASE(SCSIOP_GET_LBA_STATUS) // Code 0x9E, aka SCSIOP_GET_PHYSICAL_ELEMENT_STATUS, SCSIOP_READ_CAPACITY16, + // SCSIOP_REMOVE_ELEMENT_AND_TRUNCATE, SCSIOP_SERVICE_ACTION_IN16 + MAKE_CASE(SCSIOP_SERVICE_ACTION_OUT16) // Code 0x9F + MAKE_CASE(SCSIOP_REPORT_LUNS) // Code 0xA0 + MAKE_CASE(SCSIOP_BLANK) // Code 0xA1, aka SCSIOP_ATA_PASSTHROUGH12 + MAKE_CASE(SCSIOP_SEND_EVENT) // Code 0xA2 + MAKE_CASE(SCSIOP_MAINTENANCE_IN) // Code 0xA3, aka SCSIOP_SEND_KEY + MAKE_CASE(SCSIOP_MAINTENANCE_OUT) // Code 0xA4, aka SCSIOP_REPORT_KEY + MAKE_CASE(SCSIOP_MOVE_MEDIUM) // Code 0xA5 + MAKE_CASE(SCSIOP_LOAD_UNLOAD_SLOT) // Code 0xA6 + MAKE_CASE(SCSIOP_SET_READ_AHEAD) // Code 0xA7 + MAKE_CASE(SCSIOP_READ12) // Code 0xA8 + MAKE_CASE(SCSIOP_SERVICE_ACTION_OUT12) // Code 0xA9 + MAKE_CASE(SCSIOP_WRITE12) // Code 0xAA + MAKE_CASE(SCSIOP_SEND_MESSAGE) // Code 0xAB + MAKE_CASE(SCSIOP_GET_PERFORMANCE) // Code 0xAC + MAKE_CASE(SCSIOP_READ_DVD_STRUCTURE) // Code 0xAD + MAKE_CASE(SCSIOP_WRITE_VERIFY12) // Code 0xAE + MAKE_CASE(SCSIOP_VERIFY12) // Code 0xAF + MAKE_CASE(SCSIOP_SEARCH_DATA_HIGH12) // Code 0xB0 + MAKE_CASE(SCSIOP_SEARCH_DATA_EQUAL12) // Code 0xB1 + MAKE_CASE(SCSIOP_SEARCH_DATA_LOW12) // Code 0xB2 + MAKE_CASE(SCSIOP_SET_LIMITS12) // Code 0xB3 + MAKE_CASE(SCSIOP_READ_ELEMENT_STATUS_ATTACHED) // Code 0xB4 + MAKE_CASE(SCSIOP_REQUEST_VOL_ELEMENT) // Code 0xB5, aka SCSIOP_SECURITY_PROTOCOL_OUT + MAKE_CASE(SCSIOP_SEND_VOLUME_TAG) // Code 0xB6 + MAKE_CASE(SCSIOP_READ_DEFECT_DATA) // Code 0xB7 + MAKE_CASE(SCSIOP_READ_ELEMENT_STATUS) // Code 0xB8 + MAKE_CASE(SCSIOP_READ_CD_MSF) // Code 0xB9 + MAKE_CASE(SCSIOP_REDUNDANCY_GROUP_IN) // Code 0xBA + MAKE_CASE(SCSIOP_REDUNDANCY_GROUP_OUT) // Code 0xBB + MAKE_CASE(SCSIOP_SPARE_IN) // Code 0xBC + MAKE_CASE(SCSIOP_SPARE_OUT) // Code 0xBD, aka SCSIOP_MECHANISM_STATUS + MAKE_CASE(SCSIOP_VOLUME_SET_IN) // Code 0xBE + MAKE_CASE(SCSIOP_VOLUME_SET_OUT) // Code 0xBF + MAKE_CASE(SCSIOP_INIT_ELEMENT_RANGE) // Code 0xE7 } return scsiOpStr; } diff --git a/vioscsi/vioscsi.c b/vioscsi/vioscsi.c old mode 100755 new mode 100644 index 14f0d41d3..c5b51a12a --- a/vioscsi/vioscsi.c +++ b/vioscsi/vioscsi.c @@ -38,259 +38,179 @@ #include "vioscsi.tmh" #endif - #define MS_SM_HBA_API #include #include #include -#define VioScsiWmi_MofResourceName L"MofResource" +#define VioScsiWmi_MofResourceName L"MofResource" #include "resources.h" #include "..\build\vendor.ver" -#define VIOSCSI_SETUP_GUID_INDEX 0 -#define VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX 1 -#define VIOSCSI_MS_PORT_INFORM_GUID_INDEX 2 +#define VIOSCSI_SETUP_GUID_INDEX 0 +#define VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX 1 +#define VIOSCSI_MS_PORT_INFORM_GUID_INDEX 2 BOOLEAN IsCrashDumpMode; sp_DRIVER_INITIALIZE DriverEntry; -HW_INITIALIZE VioScsiHwInitialize; -HW_BUILDIO VioScsiBuildIo; -HW_STARTIO VioScsiStartIo; -HW_FIND_ADAPTER VioScsiFindAdapter; -HW_RESET_BUS VioScsiResetBus; -HW_ADAPTER_CONTROL VioScsiAdapterControl; -HW_UNIT_CONTROL VioScsiUnitControl; -HW_INTERRUPT VioScsiInterrupt; -HW_DPC_ROUTINE VioScsiCompleteDpcRoutine; -HW_PASSIVE_INITIALIZE_ROUTINE VioScsiPassiveInitializeRoutine; +HW_INITIALIZE VioScsiHwInitialize; +HW_BUILDIO VioScsiBuildIo; +HW_STARTIO VioScsiStartIo; +HW_FIND_ADAPTER VioScsiFindAdapter; +HW_RESET_BUS VioScsiResetBus; +HW_ADAPTER_CONTROL VioScsiAdapterControl; +HW_UNIT_CONTROL VioScsiUnitControl; +HW_INTERRUPT VioScsiInterrupt; +HW_DPC_ROUTINE VioScsiCompleteDpcRoutine; +HW_PASSIVE_INITIALIZE_ROUTINE VioScsiPassiveInitializeRoutine; HW_MESSAGE_SIGNALED_INTERRUPT_ROUTINE VioScsiMSInterrupt; - #ifdef EVENT_TRACING PVOID TraceContext = NULL; -VOID WppCleanupRoutine(PVOID arg1) { +VOID WppCleanupRoutine(PVOID arg1) +{ RhelDbgPrint(TRACE_LEVEL_INFORMATION, " WppCleanupRoutine\n"); WPP_CLEANUP(NULL, TraceContext); } #endif BOOLEAN -VioScsiHwInitialize( - IN PVOID DeviceExtension - ); +VioScsiHwInitialize(IN PVOID DeviceExtension); BOOLEAN -VioScsiHwReinitialize( - IN PVOID DeviceExtension - ); +VioScsiHwReinitialize(IN PVOID DeviceExtension); BOOLEAN -VioScsiBuildIo( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ); +VioScsiBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb); BOOLEAN -VioScsiStartIo( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ); +VioScsiStartIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb); ULONG -VioScsiFindAdapter( - IN PVOID DeviceExtension, - IN PVOID HwContext, - IN PVOID BusInformation, - IN PCHAR ArgumentString, - IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, - IN PBOOLEAN Again - ); +VioScsiFindAdapter(IN PVOID DeviceExtension, + IN PVOID HwContext, + IN PVOID BusInformation, + IN PCHAR ArgumentString, + IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, + IN PBOOLEAN Again); BOOLEAN -VioScsiResetBus( - IN PVOID DeviceExtension, - IN ULONG PathId - ); +VioScsiResetBus(IN PVOID DeviceExtension, IN ULONG PathId); SCSI_ADAPTER_CONTROL_STATUS -VioScsiAdapterControl( - IN PVOID DeviceExtension, - IN SCSI_ADAPTER_CONTROL_TYPE ControlType, - IN PVOID Parameters - ); +VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE ControlType, IN PVOID Parameters); SCSI_UNIT_CONTROL_STATUS -VioScsiUnitControl( - IN PVOID DeviceExtension, - IN SCSI_UNIT_CONTROL_TYPE ControlType, - IN PVOID Parameters - ); +VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlType, IN PVOID Parameters); UCHAR -VioScsiProcessPnP( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb -); +VioScsiProcessPnP(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); BOOLEAN FORCEINLINE -PreProcessRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ); +PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); -VOID -FORCEINLINE -PostProcessRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ); +VOID FORCEINLINE PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); -VOID -FORCEINLINE -DispatchQueue( - IN PVOID DeviceExtension, - IN ULONG MessageId - ); +VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId); BOOLEAN -VioScsiInterrupt( - IN PVOID DeviceExtension - ); - -VOID -TransportReset( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEvent evt - ); - -VOID -ParamChange( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEvent evt - ); +VioScsiInterrupt(IN PVOID DeviceExtension); + +VOID TransportReset(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt); + +VOID ParamChange(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt); BOOLEAN -VioScsiMSInterrupt( - IN PVOID DeviceExtension, - IN ULONG MessageID - ); - -VOID -VioScsiWmiInitialize( - IN PVOID DeviceExtension - ); - -VOID -VioScsiWmiSrb( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ); - -VOID -VioScsiIoControl( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ); +VioScsiMSInterrupt(IN PVOID DeviceExtension, IN ULONG MessageID); + +VOID VioScsiWmiInitialize(IN PVOID DeviceExtension); + +VOID VioScsiWmiSrb(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb); + +VOID VioScsiIoControl(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb); BOOLEAN -VioScsiQueryWmiDataBlock( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - IN ULONG GuidIndex, - IN ULONG InstanceIndex, - IN ULONG InstanceCount, - IN OUT PULONG InstanceLengthArray, - IN ULONG OutBufferSize, - OUT PUCHAR Buffer - ); +VioScsiQueryWmiDataBlock(IN PVOID Context, + IN PSCSIWMI_REQUEST_CONTEXT RequestContext, + IN ULONG GuidIndex, + IN ULONG InstanceIndex, + IN ULONG InstanceCount, + IN OUT PULONG InstanceLengthArray, + IN ULONG OutBufferSize, + OUT PUCHAR Buffer); UCHAR -VioScsiExecuteWmiMethod( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - IN ULONG GuidIndex, - IN ULONG InstanceIndex, - IN ULONG MethodId, - IN ULONG InBufferSize, - IN ULONG OutBufferSize, - IN OUT PUCHAR Buffer - ); +VioScsiExecuteWmiMethod(IN PVOID Context, + IN PSCSIWMI_REQUEST_CONTEXT RequestContext, + IN ULONG GuidIndex, + IN ULONG InstanceIndex, + IN ULONG MethodId, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN OUT PUCHAR Buffer); UCHAR -VioScsiQueryWmiRegInfo( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - OUT PWCHAR *MofResourceName - ); - -VOID -VioScsiReadExtendedData( - IN PVOID Context, - OUT PUCHAR Buffer - ); - -VOID -VioScsiSaveInquiryData( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ); - -VOID -VioScsiPatchInquiryData( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ); +VioScsiQueryWmiRegInfo(IN PVOID Context, IN PSCSIWMI_REQUEST_CONTEXT RequestContext, OUT PWCHAR *MofResourceName); + +VOID VioScsiReadExtendedData(IN PVOID Context, OUT PUCHAR Buffer); + +VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb); + +VOID VioScsiPatchInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb); GUID VioScsiWmiExtendedInfoGuid = VioScsiWmi_ExtendedInfo_Guid; GUID VioScsiWmiAdapterInformationQueryGuid = MS_SM_AdapterInformationQueryGuid; GUID VioScsiWmiPortInformationMethodsGuid = MS_SM_PortInformationMethodsGuid; +// clang-format off SCSIWMIGUIDREGINFO VioScsiGuidList[] = { { &VioScsiWmiExtendedInfoGuid, 1, 0 }, { &VioScsiWmiAdapterInformationQueryGuid, 1, 0 }, { &VioScsiWmiPortInformationMethodsGuid, 1, 0 }, }; +// clang-format on #define VioScsiGuidCount (sizeof(VioScsiGuidList) / sizeof(SCSIWMIGUIDREGINFO)) -void CopyUnicodeString(void* _pDest, const void* _pSrc, size_t _maxlength) +void CopyUnicodeString(void *_pDest, const void *_pSrc, size_t _maxlength) { - PUSHORT _pDestTemp = _pDest; - USHORT _length = _maxlength - sizeof(USHORT); - *_pDestTemp++ = _length; - _length = (USHORT)min(wcslen(_pSrc)*sizeof(WCHAR), _length); - memcpy(_pDestTemp, _pSrc, _length); + PUSHORT _pDestTemp = _pDest; + USHORT _length = _maxlength - sizeof(USHORT); + *_pDestTemp++ = _length; + _length = (USHORT)min(wcslen(_pSrc) * sizeof(WCHAR), _length); + memcpy(_pDestTemp, _pSrc, _length); } -void CopyAnsiToUnicodeString(void* _pDest, const void* _pSrc, size_t _maxlength) +void CopyAnsiToUnicodeString(void *_pDest, const void *_pSrc, size_t _maxlength) { PUSHORT _pDestTemp = _pDest; - PWCHAR dst; - PCHAR src = (PCHAR)_pSrc; - USHORT _length = _maxlength - sizeof(USHORT); + PWCHAR dst; + PCHAR src = (PCHAR)_pSrc; + USHORT _length = _maxlength - sizeof(USHORT); *_pDestTemp++ = _length; dst = (PWCHAR)_pDestTemp; - _length = (USHORT)min(strlen((const char*)_pSrc) * sizeof(WCHAR), _length); + _length = (USHORT)min(strlen((const char *)_pSrc) * sizeof(WCHAR), _length); _length /= sizeof(WCHAR); - while (_length) { + while (_length) + { *dst++ = *src++; --_length; }; } -USHORT CopyBufferToAnsiString(void* _pDest, const void* _pSrc, const char delimiter, size_t _maxlength) +USHORT CopyBufferToAnsiString(void *_pDest, const void *_pSrc, const char delimiter, size_t _maxlength) { - PCHAR dst = (PCHAR)_pDest; - PCHAR src = (PCHAR)_pSrc; - USHORT _length = _maxlength; + PCHAR dst = (PCHAR)_pDest; + PCHAR src = (PCHAR)_pSrc; + USHORT _length = _maxlength; - while (_length && (*src != delimiter)) { + while (_length && (*src != delimiter)) + { *dst++ = *src++; --_length; }; @@ -298,58 +218,45 @@ USHORT CopyBufferToAnsiString(void* _pDest, const void* _pSrc, const char delimi return _length; } -BOOLEAN VioScsiReadRegistryParameter( - IN PVOID DeviceExtension, - IN PUCHAR ValueName, - IN LONG offset -) +BOOLEAN VioScsiReadRegistryParameter(IN PVOID DeviceExtension, IN PUCHAR ValueName, IN LONG offset) { BOOLEAN Ret = FALSE; ULONG Len = sizeof(ULONG); - UCHAR* pBuf = NULL; + UCHAR *pBuf = NULL; PADAPTER_EXTENSION adaptExt; - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; pBuf = StorPortAllocateRegistryBuffer(DeviceExtension, &Len); - if (pBuf == NULL) { + if (pBuf == NULL) + { RhelDbgPrint(TRACE_LEVEL_FATAL, "StorPortAllocateRegistryBuffer failed to allocate buffer\n"); return FALSE; } memset(pBuf, 0, sizeof(ULONG)); - Ret = StorPortRegistryRead(DeviceExtension, - ValueName, - 1, - MINIPORT_REG_DWORD, - pBuf, - &Len); + Ret = StorPortRegistryRead(DeviceExtension, ValueName, 1, MINIPORT_REG_DWORD, pBuf, &Len); - if ((Ret == FALSE) || (Len == 0)) { + if ((Ret == FALSE) || (Len == 0)) + { RhelDbgPrint(TRACE_LEVEL_FATAL, "StorPortRegistryRead returned 0x%x, Len = %d\n", Ret, Len); StorPortFreeRegistryBuffer(DeviceExtension, pBuf); return FALSE; } - StorPortCopyMemory((PVOID)((UINT_PTR)adaptExt + offset), - (PVOID)pBuf, - sizeof(ULONG)); + StorPortCopyMemory((PVOID)((UINT_PTR)adaptExt + offset), (PVOID)pBuf, sizeof(ULONG)); - StorPortFreeRegistryBuffer(DeviceExtension, pBuf ); + StorPortFreeRegistryBuffer(DeviceExtension, pBuf); return TRUE; } ULONG -DriverEntry( - IN PVOID DriverObject, - IN PVOID RegistryPath - ) +DriverEntry(IN PVOID DriverObject, IN PVOID RegistryPath) { HW_INITIALIZATION_DATA hwInitData; - ULONG initResult; + ULONG initResult; #ifdef EVENT_TRACING STORAGE_TRACE_INIT_INFO initInfo; @@ -359,7 +266,8 @@ DriverEntry( IsCrashDumpMode = FALSE; RhelDbgPrint(TRACE_LEVEL_FATAL, " Vioscsi driver started...built on %s %s\n", __DATE__, __TIME__); - if (RegistryPath == NULL) { + if (RegistryPath == NULL) + { IsCrashDumpMode = TRUE; RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Crash dump mode\n"); } @@ -368,39 +276,36 @@ DriverEntry( hwInitData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA); - hwInitData.HwFindAdapter = VioScsiFindAdapter; - hwInitData.HwInitialize = VioScsiHwInitialize; - hwInitData.HwStartIo = VioScsiStartIo; - hwInitData.HwInterrupt = VioScsiInterrupt; - hwInitData.HwResetBus = VioScsiResetBus; - hwInitData.HwAdapterControl = VioScsiAdapterControl; - hwInitData.HwUnitControl = VioScsiUnitControl; - hwInitData.HwBuildIo = VioScsiBuildIo; + hwInitData.HwFindAdapter = VioScsiFindAdapter; + hwInitData.HwInitialize = VioScsiHwInitialize; + hwInitData.HwStartIo = VioScsiStartIo; + hwInitData.HwInterrupt = VioScsiInterrupt; + hwInitData.HwResetBus = VioScsiResetBus; + hwInitData.HwAdapterControl = VioScsiAdapterControl; + hwInitData.HwUnitControl = VioScsiUnitControl; + hwInitData.HwBuildIo = VioScsiBuildIo; - hwInitData.NeedPhysicalAddresses = TRUE; - hwInitData.TaggedQueuing = TRUE; - hwInitData.AutoRequestSense = TRUE; - hwInitData.MultipleRequestPerLu = TRUE; + hwInitData.NeedPhysicalAddresses = TRUE; + hwInitData.TaggedQueuing = TRUE; + hwInitData.AutoRequestSense = TRUE; + hwInitData.MultipleRequestPerLu = TRUE; - hwInitData.DeviceExtensionSize = sizeof(ADAPTER_EXTENSION); - hwInitData.SrbExtensionSize = sizeof(SRB_EXTENSION); + hwInitData.DeviceExtensionSize = sizeof(ADAPTER_EXTENSION); + hwInitData.SrbExtensionSize = sizeof(SRB_EXTENSION); - hwInitData.AdapterInterfaceType = PCIBus; + hwInitData.AdapterInterfaceType = PCIBus; /* Virtio doesn't specify the number of BARs used by the device; it may * be one, it may be more. PCI_TYPE0_ADDRESSES, the theoretical maximum * on PCI, is a safe upper bound. */ - hwInitData.NumberOfAccessRanges = PCI_TYPE0_ADDRESSES; - hwInitData.MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS; + hwInitData.NumberOfAccessRanges = PCI_TYPE0_ADDRESSES; + hwInitData.MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS; hwInitData.SrbTypeFlags = SRB_TYPE_FLAG_STORAGE_REQUEST_BLOCK; - hwInitData.AddressTypeFlags = ADDRESS_TYPE_FLAG_BTL8; + hwInitData.AddressTypeFlags = ADDRESS_TYPE_FLAG_BTL8; - initResult = StorPortInitialize(DriverObject, - RegistryPath, - &hwInitData, - NULL); + initResult = StorPortInitialize(DriverObject, RegistryPath, &hwInitData, NULL); #ifdef EVENT_TRACING TraceContext = NULL; @@ -414,66 +319,64 @@ DriverEntry( WPP_INIT_TRACING(DriverObject, RegistryPath, &initInfo); - if (initInfo.TraceContext != NULL) { + if (initInfo.TraceContext != NULL) + { TraceContext = initInfo.TraceContext; } #endif - RhelDbgPrint(TRACE_LEVEL_VERBOSE, - " Initialize returned 0x%x\n", initResult); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " Initialize returned 0x%x\n", initResult); return initResult; - } ULONG -VioScsiFindAdapter( - IN PVOID DeviceExtension, - IN PVOID HwContext, - IN PVOID BusInformation, - IN PCHAR ArgumentString, - IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, - IN PBOOLEAN Again - ) +VioScsiFindAdapter(IN PVOID DeviceExtension, + IN PVOID HwContext, + IN PVOID BusInformation, + IN PCHAR ArgumentString, + IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, + IN PBOOLEAN Again) { PADAPTER_EXTENSION adaptExt; - PVOID uncachedExtensionVa; - USHORT queueLength = 0; - ULONG Size; - ULONG HeapSize; - ULONG extensionSize; - ULONG index; - ULONG num_cpus; - ULONG max_cpus; - ULONG max_queues; - - UNREFERENCED_PARAMETER( HwContext ); - UNREFERENCED_PARAMETER( BusInformation ); - UNREFERENCED_PARAMETER( ArgumentString ); - UNREFERENCED_PARAMETER( Again ); - -ENTER_FN(); + PVOID uncachedExtensionVa; + USHORT queueLength = 0; + ULONG Size; + ULONG HeapSize; + ULONG extensionSize; + ULONG index; + ULONG num_cpus; + ULONG max_cpus; + ULONG max_queues; + + UNREFERENCED_PARAMETER(HwContext); + UNREFERENCED_PARAMETER(BusInformation); + UNREFERENCED_PARAMETER(ArgumentString); + UNREFERENCED_PARAMETER(Again); + + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; RtlZeroMemory(adaptExt, sizeof(ADAPTER_EXTENSION)); - adaptExt->dump_mode = IsCrashDumpMode; - adaptExt->hba_id = HBA_ID; - ConfigInfo->Master = TRUE; - ConfigInfo->ScatterGather = TRUE; - ConfigInfo->DmaWidth = Width32Bits; - ConfigInfo->Dma32BitAddresses = TRUE; - ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_FULL64BIT_SUPPORTED; - ConfigInfo->WmiDataProvider = TRUE; - ConfigInfo->AlignmentMask = 0x3; - ConfigInfo->MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS; - ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex; - ConfigInfo->HwMSInterruptRoutine = VioScsiMSInterrupt; - ConfigInfo->InterruptSynchronizationMode=InterruptSynchronizePerMessage; + adaptExt->dump_mode = IsCrashDumpMode; + adaptExt->hba_id = HBA_ID; + ConfigInfo->Master = TRUE; + ConfigInfo->ScatterGather = TRUE; + ConfigInfo->DmaWidth = Width32Bits; + ConfigInfo->Dma32BitAddresses = TRUE; + ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_FULL64BIT_SUPPORTED; + ConfigInfo->WmiDataProvider = TRUE; + ConfigInfo->AlignmentMask = 0x3; + ConfigInfo->MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS; + ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex; + ConfigInfo->HwMSInterruptRoutine = VioScsiMSInterrupt; + ConfigInfo->InterruptSynchronizationMode = InterruptSynchronizePerMessage; VioScsiWmiInitialize(DeviceExtension); - if (!InitHW(DeviceExtension, ConfigInfo)) { + if (!InitHW(DeviceExtension, ConfigInfo)) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot initialize HardWare\n"); return SP_RETURN_NOT_FOUND; } @@ -484,38 +387,41 @@ ENTER_FN(); * values advertised by the underlying device. */ adaptExt->scsi_config.num_queues = 1; - adaptExt->scsi_config.seg_max = SCSI_MINIMUM_PHYSICAL_BREAKS; - adaptExt->indirect = FALSE; - adaptExt->max_physical_breaks = SCSI_MINIMUM_PHYSICAL_BREAKS; + adaptExt->scsi_config.seg_max = SCSI_MINIMUM_PHYSICAL_BREAKS; + adaptExt->indirect = FALSE; + adaptExt->max_physical_breaks = SCSI_MINIMUM_PHYSICAL_BREAKS; GetScsiConfig(DeviceExtension); SetGuestFeatures(DeviceExtension); - ConfigInfo->NumberOfBuses = 1; - ConfigInfo->MaximumNumberOfTargets = min((UCHAR)adaptExt->scsi_config.max_target, 255/*SCSI_MAXIMUM_TARGETS_PER_BUS*/); + ConfigInfo->NumberOfBuses = 1; + ConfigInfo->MaximumNumberOfTargets = min((UCHAR)adaptExt->scsi_config.max_target, + 255 /*SCSI_MAXIMUM_TARGETS_PER_BUS*/); ConfigInfo->MaximumNumberOfLogicalUnits = min((UCHAR)adaptExt->scsi_config.max_lun, SCSI_MAXIMUM_LUNS_PER_TARGET); - ConfigInfo->MaximumTransferLength = SP_UNINITIALIZED_VALUE; // Unlimited - ConfigInfo->NumberOfPhysicalBreaks = SP_UNINITIALIZED_VALUE; // Unlimited + ConfigInfo->MaximumTransferLength = SP_UNINITIALIZED_VALUE; // Unlimited + ConfigInfo->NumberOfPhysicalBreaks = SP_UNINITIALIZED_VALUE; // Unlimited - if (!adaptExt->dump_mode) { + if (!adaptExt->dump_mode) + { adaptExt->max_physical_breaks = adaptExt->indirect ? MAX_PHYS_SEGMENTS : PHYS_SEGMENTS; /* Allow user to override max_physical_breaks via reg key * [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\vioscsi\Parameters\Device] * "PhysicalBreaks"={dword value here} */ - VioScsiReadRegistryParameter(DeviceExtension, REGISTRY_MAX_PH_BREAKS, FIELD_OFFSET(ADAPTER_EXTENSION, max_physical_breaks)); - adaptExt->max_physical_breaks = min( - max(SCSI_MINIMUM_PHYSICAL_BREAKS, adaptExt->max_physical_breaks), - MAX_PHYS_SEGMENTS); - - if (adaptExt->scsi_config.max_sectors > 0 && - adaptExt->scsi_config.max_sectors != 0xFFFF && - adaptExt->max_physical_breaks * PAGE_SIZE > adaptExt->scsi_config.max_sectors * SECTOR_SIZE) { - adaptExt->max_physical_breaks = adaptExt->scsi_config.max_sectors * SECTOR_SIZE / PAGE_SIZE; + VioScsiReadRegistryParameter(DeviceExtension, + REGISTRY_MAX_PH_BREAKS, + FIELD_OFFSET(ADAPTER_EXTENSION, max_physical_breaks)); + adaptExt->max_physical_breaks = min(max(SCSI_MINIMUM_PHYSICAL_BREAKS, adaptExt->max_physical_breaks), + MAX_PHYS_SEGMENTS); + + if (adaptExt->scsi_config.max_sectors > 0 && adaptExt->scsi_config.max_sectors != 0xFFFF && + adaptExt->max_physical_breaks * PAGE_SIZE > adaptExt->scsi_config.max_sectors * SECTOR_SIZE) + { + adaptExt->max_physical_breaks = adaptExt->scsi_config.max_sectors * SECTOR_SIZE / PAGE_SIZE; } } ConfigInfo->NumberOfPhysicalBreaks = adaptExt->max_physical_breaks + 1; - ConfigInfo->MaximumTransferLength = adaptExt->max_physical_breaks * PAGE_SIZE; + ConfigInfo->MaximumTransferLength = adaptExt->max_physical_breaks * PAGE_SIZE; RhelDbgPrint(TRACE_LEVEL_INFORMATION, " NumberOfPhysicalBreaks %d\n", ConfigInfo->NumberOfPhysicalBreaks); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MaximumTransferLength %d\n", ConfigInfo->MaximumTransferLength); @@ -537,7 +443,9 @@ ENTER_FN(); } adaptExt->action_on_reset = VioscsiResetCompleteRequests; - VioScsiReadRegistryParameter(DeviceExtension, REGISTRY_ACTION_ON_RESET, FIELD_OFFSET(ADAPTER_EXTENSION, action_on_reset)); + VioScsiReadRegistryParameter(DeviceExtension, + REGISTRY_ACTION_ON_RESET, + FIELD_OFFSET(ADAPTER_EXTENSION, action_on_reset)); adaptExt->resp_time = 0; VioScsiReadRegistryParameter(DeviceExtension, REGISTRY_RESP_TIME_LIMIT, FIELD_OFFSET(ADAPTER_EXTENSION, resp_time)); @@ -549,17 +457,20 @@ ENTER_FN(); * VioScsiFindAdapter again with more CPUs enabled. Unfortunately StorPortGetUncachedExtension * only allocates when called for the first time so we need to always use this upper bound. */ - if (adaptExt->dump_mode) { + if (adaptExt->dump_mode) + { max_queues = adaptExt->num_queues; - } else { + } + else + { max_queues = min(max_cpus, adaptExt->scsi_config.num_queues); - if (adaptExt->num_queues > max_queues) { + if (adaptExt->num_queues > max_queues) + { RhelDbgPrint(TRACE_LEVEL_WARNING, " Multiqueue can only use at most one queue per cpu."); adaptExt->num_queues = max_queues; } } - /* This function is our only chance to allocate memory for the driver; allocations are not * possible later on. Even worse, the only allocation mechanism guaranteed to work in all * cases is StorPortGetUncachedExtension, which gives us one block of physically contiguous @@ -575,12 +486,12 @@ ENTER_FN(); adaptExt->pageOffset = 0; adaptExt->poolOffset = 0; Size = 0; - for (index = VIRTIO_SCSI_CONTROL_QUEUE; index < max_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; ++index) { + for (index = VIRTIO_SCSI_CONTROL_QUEUE; index < max_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; ++index) + { virtio_query_queue_allocation(&adaptExt->vdev, index, &queueLength, &Size, &HeapSize); - if (Size == 0) { - LogError(DeviceExtension, - SP_INTERNAL_ADAPTER_ERROR, - __LINE__); + if (Size == 0) + { + LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); RhelDbgPrint(TRACE_LEVEL_FATAL, " Virtual queue %d config failed.\n", index); return SP_RETURN_ERROR; @@ -588,37 +499,44 @@ ENTER_FN(); adaptExt->pageAllocationSize += ROUND_TO_PAGES(Size); adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES(HeapSize); } - if (!adaptExt->dump_mode) { + if (!adaptExt->dump_mode) + { adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES(sizeof(SRB_EXTENSION)); adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES(sizeof(VirtIOSCSIEventNode) * 8); adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES(sizeof(STOR_DPC) * max_queues); } if (max_queues + VIRTIO_SCSI_REQUEST_QUEUE_0 > MAX_QUEUES_PER_DEVICE_DEFAULT) { - adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES( - ((ULONGLONG)max_queues + VIRTIO_SCSI_REQUEST_QUEUE_0) * virtio_get_queue_descriptor_size()); + adaptExt->poolAllocationSize += ROUND_TO_CACHE_LINES(((ULONGLONG)max_queues + VIRTIO_SCSI_REQUEST_QUEUE_0) * + virtio_get_queue_descriptor_size()); } - if(adaptExt->indirect) { + if (adaptExt->indirect) + { adaptExt->queue_depth = queueLength; - } else { + } + else + { adaptExt->queue_depth = queueLength / ConfigInfo->NumberOfPhysicalBreaks - 1; } ConfigInfo->MaxIOsPerLun = adaptExt->queue_depth * adaptExt->num_queues; ConfigInfo->InitialLunQueueDepth = ConfigInfo->MaxIOsPerLun; ConfigInfo->MaxNumberOfIO = ConfigInfo->MaxIOsPerLun; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " breaks_number = %x queue_depth = %x\n", - ConfigInfo->NumberOfPhysicalBreaks, - adaptExt->queue_depth); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " breaks_number = %x queue_depth = %x\n", + ConfigInfo->NumberOfPhysicalBreaks, + adaptExt->queue_depth); extensionSize = PAGE_SIZE + adaptExt->pageAllocationSize + adaptExt->poolAllocationSize; uncachedExtensionVa = StorPortGetUncachedExtension(DeviceExtension, ConfigInfo, extensionSize); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " StorPortGetUncachedExtension uncachedExtensionVa = %p allocation size = %d\n", uncachedExtensionVa, extensionSize); - if (!uncachedExtensionVa) { - LogError(DeviceExtension, - SP_INTERNAL_ADAPTER_ERROR, - __LINE__); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " StorPortGetUncachedExtension uncachedExtensionVa = %p allocation size = %d\n", + uncachedExtensionVa, + extensionSize); + if (!uncachedExtensionVa) + { + LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); RhelDbgPrint(TRACE_LEVEL_FATAL, " Can't get uncached extension allocation size = %d\n", extensionSize); return SP_RETURN_ERROR; @@ -638,44 +556,48 @@ ENTER_FN(); * |<===================================== extensionSize =========================================>| */ adaptExt->pageAllocationVa = (PVOID)(((ULONG_PTR)(uncachedExtensionVa) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)); - if (adaptExt->poolAllocationSize > 0) { + if (adaptExt->poolAllocationSize > 0) + { adaptExt->poolAllocationVa = (PVOID)((ULONG_PTR)adaptExt->pageAllocationVa + adaptExt->pageAllocationSize); } - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Page-aligned area at %p, size = %d\n", adaptExt->pageAllocationVa, adaptExt->pageAllocationSize); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Pool area at %p, size = %d\n", adaptExt->poolAllocationVa, adaptExt->poolAllocationSize); - - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p\n",adaptExt->pmsg_affinity); - if (!adaptExt->dump_mode && (adaptExt->num_queues > 1) && (adaptExt->pmsg_affinity == NULL)) { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " Page-aligned area at %p, size = %d\n", + adaptExt->pageAllocationVa, + adaptExt->pageAllocationSize); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " Pool area at %p, size = %d\n", + adaptExt->poolAllocationVa, + adaptExt->poolAllocationSize); + + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p\n", adaptExt->pmsg_affinity); + if (!adaptExt->dump_mode && (adaptExt->num_queues > 1) && (adaptExt->pmsg_affinity == NULL)) + { adaptExt->num_affinity = adaptExt->num_queues + 3; - ULONG Status = - StorPortAllocatePool(DeviceExtension, - sizeof(GROUP_AFFINITY) * (ULONGLONG)adaptExt->num_affinity, - VIOSCSI_POOL_TAG, - (PVOID*)&adaptExt->pmsg_affinity); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p Status = %lu\n",adaptExt->pmsg_affinity, Status); + ULONG Status = StorPortAllocatePool(DeviceExtension, + sizeof(GROUP_AFFINITY) * (ULONGLONG)adaptExt->num_affinity, + VIOSCSI_POOL_TAG, + (PVOID *)&adaptExt->pmsg_affinity); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p Status = %lu\n", adaptExt->pmsg_affinity, Status); } adaptExt->fw_ver = '0'; -EXIT_FN(); + EXIT_FN(); return SP_RETURN_FOUND; } BOOLEAN -VioScsiPassiveInitializeRoutine( - IN PVOID DeviceExtension -) +VioScsiPassiveInitializeRoutine(IN PVOID DeviceExtension) { ULONG index; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; -ENTER_FN(); + ENTER_FN(); - for (index = 0; index < adaptExt->num_queues; ++index) { - StorPortInitializeDpc(DeviceExtension, - &adaptExt->dpc[index], - VioScsiCompleteDpcRoutine); + for (index = 0; index < adaptExt->num_queues; ++index) + { + StorPortInitializeDpc(DeviceExtension, &adaptExt->dpc[index], VioScsiCompleteDpcRoutine); } adaptExt->dpc_ok = TRUE; -EXIT_FN(); + EXIT_FN(); return TRUE; } @@ -683,11 +605,9 @@ static BOOLEAN InitializeVirtualQueues(PADAPTER_EXTENSION adaptExt, ULONG numQue { NTSTATUS status; - status = virtio_find_queues( - &adaptExt->vdev, - numQueues, - adaptExt->vq); - if (!NT_SUCCESS(status)) { + status = virtio_find_queues(&adaptExt->vdev, numQueues, adaptExt->vq); + if (!NT_SUCCESS(status)) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " FAILED with status 0x%x\n", status); return FALSE; } @@ -696,15 +616,13 @@ static BOOLEAN InitializeVirtualQueues(PADAPTER_EXTENSION adaptExt, ULONG numQue } PVOID -VioScsiPoolAlloc( - IN PVOID DeviceExtension, - IN SIZE_T size - ) +VioScsiPoolAlloc(IN PVOID DeviceExtension, IN SIZE_T size) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; PVOID ptr = (PVOID)((ULONG_PTR)adaptExt->poolAllocationVa + adaptExt->poolOffset); - if ((adaptExt->poolOffset + size) <= adaptExt->poolAllocationSize) { + if ((adaptExt->poolOffset + size) <= adaptExt->poolAllocationSize) + { size = ROUND_TO_CACHE_LINES(size); adaptExt->poolOffset += (ULONG)size; RtlZeroMemory(ptr, size); @@ -715,51 +633,57 @@ VioScsiPoolAlloc( } BOOLEAN -VioScsiHwInitialize( - IN PVOID DeviceExtension - ) +VioScsiHwInitialize(IN PVOID DeviceExtension) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - ULONG i; - ULONG index; + ULONG i; + ULONG index; - PERF_CONFIGURATION_DATA perfData = { 0 }; - ULONG status = STOR_STATUS_SUCCESS; - MESSAGE_INTERRUPT_INFORMATION msi_info = { 0 }; - PREQUEST_LIST element; -ENTER_FN(); + PERF_CONFIGURATION_DATA perfData = {0}; + ULONG status = STOR_STATUS_SUCCESS; + MESSAGE_INTERRUPT_INFORMATION msi_info = {0}; + PREQUEST_LIST element; + ENTER_FN(); adaptExt->msix_vectors = 0; adaptExt->pageOffset = 0; adaptExt->poolOffset = 0; - while(StorPortGetMSIInfo(DeviceExtension, adaptExt->msix_vectors, &msi_info) == STOR_STATUS_SUCCESS) { + while (StorPortGetMSIInfo(DeviceExtension, adaptExt->msix_vectors, &msi_info) == STOR_STATUS_SUCCESS) + { RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MessageId = %x\n", msi_info.MessageId); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MessageData = %x\n", msi_info.MessageData); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " InterruptVector = %x\n", msi_info.InterruptVector); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " InterruptLevel = %x\n", msi_info.InterruptLevel); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " InterruptMode = %s\n", msi_info.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " InterruptMode = %s\n", + msi_info.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MessageAddress = %I64x\n\n", msi_info.MessageAddress.QuadPart); ++adaptExt->msix_vectors; } RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Queues %d msix_vectors %d\n", adaptExt->num_queues, adaptExt->msix_vectors); - if (adaptExt->num_queues > 1 && - ((adaptExt->num_queues + 3) > adaptExt->msix_vectors)) { + if (adaptExt->num_queues > 1 && ((adaptExt->num_queues + 3) > adaptExt->msix_vectors)) + { adaptExt->num_queues = (USHORT)adaptExt->msix_vectors; } - if (!adaptExt->dump_mode && adaptExt->msix_vectors > 0) { - if (adaptExt->msix_vectors >= adaptExt->num_queues + 3) { + if (!adaptExt->dump_mode && adaptExt->msix_vectors > 0) + { + if (adaptExt->msix_vectors >= adaptExt->num_queues + 3) + { /* initialize queues with a MSI vector per queue */ RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Using a unique MSI vector per queue\n"); adaptExt->msix_one_vector = FALSE; - } else { + } + else + { /* if we don't have enough vectors, use one for all queues */ RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Using one MSI vector for all queues\n"); adaptExt->msix_one_vector = TRUE; } - if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) { + if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) + { return FALSE; } } @@ -767,112 +691,137 @@ ENTER_FN(); { /* initialize queues with no MSI interrupts */ adaptExt->msix_enabled = FALSE; - if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) { + if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) + { return FALSE; } } - for (index = 0; index < adaptExt->num_queues; ++index) { - element = &adaptExt->processing_srbs[index]; - InitializeListHead(&element->srb_list); - element->srb_cnt = 0; + for (index = 0; index < adaptExt->num_queues; ++index) + { + element = &adaptExt->processing_srbs[index]; + InitializeListHead(&element->srb_list); + element->srb_cnt = 0; } - if (!adaptExt->dump_mode) { + if (!adaptExt->dump_mode) + { /* we don't get another chance to call StorPortEnablePassiveInitialization and initialize * DPCs if the adapter is being restarted, so leave our datastructures alone on restart */ - if (adaptExt->dpc == NULL) { + if (adaptExt->dpc == NULL) + { adaptExt->tmf_cmd.SrbExtension = (PSRB_EXTENSION)VioScsiPoolAlloc(DeviceExtension, sizeof(SRB_EXTENSION)); adaptExt->events = (PVirtIOSCSIEventNode)VioScsiPoolAlloc(DeviceExtension, sizeof(VirtIOSCSIEventNode) * 8); adaptExt->dpc = (PSTOR_DPC)VioScsiPoolAlloc(DeviceExtension, sizeof(STOR_DPC) * adaptExt->num_queues); } } - if (!adaptExt->dump_mode && CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_HOTPLUG)) { + if (!adaptExt->dump_mode && CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_HOTPLUG)) + { PVirtIOSCSIEventNode events = adaptExt->events; - for (i = 0; i < 8; i++) { - if (!KickEvent(DeviceExtension, (PVOID)(&events[i]))) { + for (i = 0; i < 8; i++) + { + if (!KickEvent(DeviceExtension, (PVOID)(&events[i]))) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot add event %d\n", i); - } + } } } if (!adaptExt->dump_mode) { - if ((adaptExt->num_queues > 1) && (adaptExt->perfFlags == 0)) { + if ((adaptExt->num_queues > 1) && (adaptExt->perfFlags == 0)) + { perfData.Version = STOR_PERF_VERSION; perfData.Size = sizeof(PERF_CONFIGURATION_DATA); status = StorPortInitializePerfOpts(DeviceExtension, TRUE, &perfData); - RhelDbgPrint(TRACE_LEVEL_FATAL, " Current PerfOpts Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, FirstRedirectionMessageNumber = %d,LastRedirectionMessageNumber = %d\n", - perfData.Version, - perfData.Flags, - perfData.ConcurrentChannels, - perfData.FirstRedirectionMessageNumber, - perfData.LastRedirectionMessageNumber); - if ( (status == STOR_STATUS_SUCCESS) && - (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION)) ) { - adaptExt->perfFlags = STOR_PERF_DPC_REDIRECTION; - if (CHECKFLAG(perfData.Flags, STOR_PERF_INTERRUPT_MESSAGE_RANGES)) { + RhelDbgPrint(TRACE_LEVEL_FATAL, + " Current PerfOpts Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, " + "FirstRedirectionMessageNumber = %d,LastRedirectionMessageNumber = %d\n", + perfData.Version, + perfData.Flags, + perfData.ConcurrentChannels, + perfData.FirstRedirectionMessageNumber, + perfData.LastRedirectionMessageNumber); + if ((status == STOR_STATUS_SUCCESS) && (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION))) + { + adaptExt->perfFlags = STOR_PERF_DPC_REDIRECTION; + if (CHECKFLAG(perfData.Flags, STOR_PERF_INTERRUPT_MESSAGE_RANGES)) + { adaptExt->perfFlags |= STOR_PERF_INTERRUPT_MESSAGE_RANGES; perfData.FirstRedirectionMessageNumber = 3; - perfData.LastRedirectionMessageNumber = perfData.FirstRedirectionMessageNumber + adaptExt->num_queues - 1; + perfData.LastRedirectionMessageNumber = perfData.FirstRedirectionMessageNumber + + adaptExt->num_queues - 1; ASSERT(perfData.LastRedirectionMessageNumber < adaptExt->num_affinity); - if ((adaptExt->pmsg_affinity != NULL) && CHECKFLAG(perfData.Flags, STOR_PERF_ADV_CONFIG_LOCALITY)) { - RtlZeroMemory((PCHAR)adaptExt->pmsg_affinity, sizeof (GROUP_AFFINITY) * ((ULONGLONG)adaptExt->num_queues + 3)); + if ((adaptExt->pmsg_affinity != NULL) && CHECKFLAG(perfData.Flags, STOR_PERF_ADV_CONFIG_LOCALITY)) + { + RtlZeroMemory((PCHAR)adaptExt->pmsg_affinity, + sizeof(GROUP_AFFINITY) * ((ULONGLONG)adaptExt->num_queues + 3)); adaptExt->perfFlags |= STOR_PERF_ADV_CONFIG_LOCALITY; perfData.MessageTargets = adaptExt->pmsg_affinity; - if (CHECKFLAG(perfData.Flags, STOR_PERF_CONCURRENT_CHANNELS)) { + if (CHECKFLAG(perfData.Flags, STOR_PERF_CONCURRENT_CHANNELS)) + { adaptExt->perfFlags |= STOR_PERF_CONCURRENT_CHANNELS; perfData.ConcurrentChannels = adaptExt->num_queues; } } } - if (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION_CURRENT_CPU)) { -// adaptExt->perfFlags |= STOR_PERF_DPC_REDIRECTION_CURRENT_CPU; + if (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION_CURRENT_CPU)) + { + // adaptExt->perfFlags |= STOR_PERF_DPC_REDIRECTION_CURRENT_CPU; } - if (CHECKFLAG(perfData.Flags, STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO)) { -// adaptExt->perfFlags |= STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO; + if (CHECKFLAG(perfData.Flags, STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO)) + { + // adaptExt->perfFlags |= STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO; } perfData.Flags = adaptExt->perfFlags; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, "Applied PerfOpts Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, FirstRedirectionMessageNumber = %d,LastRedirectionMessageNumber = %d\n", - perfData.Version, - perfData.Flags, - perfData.ConcurrentChannels, - perfData.FirstRedirectionMessageNumber, - perfData.LastRedirectionMessageNumber); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + "Applied PerfOpts Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, " + "FirstRedirectionMessageNumber = %d,LastRedirectionMessageNumber = %d\n", + perfData.Version, + perfData.Flags, + perfData.ConcurrentChannels, + perfData.FirstRedirectionMessageNumber, + perfData.LastRedirectionMessageNumber); status = StorPortInitializePerfOpts(DeviceExtension, FALSE, &perfData); - if (status != STOR_STATUS_SUCCESS) { + if (status != STOR_STATUS_SUCCESS) + { adaptExt->perfFlags = 0; - RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortInitializePerfOpts set failed with status = 0x%x\n", status); + RhelDbgPrint(TRACE_LEVEL_ERROR, + " StorPortInitializePerfOpts set failed with status = 0x%x\n", + status); } } - else { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " StorPortInitializePerfOpts get failed with status = 0x%x\n", status); + else + { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " StorPortInitializePerfOpts get failed with status = 0x%x\n", + status); } } - if (!adaptExt->dpc_ok && !StorPortEnablePassiveInitialization(DeviceExtension, VioScsiPassiveInitializeRoutine)) { + if (!adaptExt->dpc_ok && !StorPortEnablePassiveInitialization(DeviceExtension, VioScsiPassiveInitializeRoutine)) + { RhelDbgPrint(TRACE_LEVEL_FATAL, " StorPortEnablePassiveInitialization FAILED\n"); return FALSE; } } virtio_device_ready(&adaptExt->vdev); -EXIT_FN(); + EXIT_FN(); return TRUE; } BOOLEAN -VioScsiHwReinitialize( - IN PVOID DeviceExtension - ) +VioScsiHwReinitialize(IN PVOID DeviceExtension) { /* The adapter is being restarted and we need to bring it back up without * running any passive-level code. Note that VioScsiFindAdapter is *not* * called on restart. */ - if (!InitVirtIODevice(DeviceExtension)) { + if (!InitVirtIODevice(DeviceExtension)) + { return FALSE; } SetGuestFeatures(DeviceExtension); @@ -880,12 +829,9 @@ VioScsiHwReinitialize( } BOOLEAN -VioScsiStartIo( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ) +VioScsiStartIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { -ENTER_FN_SRB(); + ENTER_FN_SRB(); if (PreProcessRequest(DeviceExtension, (PSRB_TYPE)Srb)) { CompleteRequest(DeviceExtension, (PSRB_TYPE)Srb); @@ -894,15 +840,11 @@ ENTER_FN_SRB(); { SendSRB(DeviceExtension, (PSRB_TYPE)Srb); } -EXIT_FN_SRB(); + EXIT_FN_SRB(); return TRUE; } -VOID -HandleResponse( - IN PVOID DeviceExtension, - IN PVirtIOSCSICmd cmd -) +VOID HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd) { PSRB_TYPE Srb = (PSRB_TYPE)(cmd->srb); PSRB_EXTENSION srbExt = SRB_EXTENSION(Srb); @@ -912,59 +854,58 @@ HandleResponse( UCHAR srbStatus = SRB_STATUS_SUCCESS; ULONG srbDataTransferLen = SRB_DATA_TRANSFER_LENGTH(Srb); -ENTER_FN(); + ENTER_FN(); LOG_SRB_INFO(); - switch (resp->response) { - case VIRTIO_SCSI_S_OK: - SRB_SET_SCSI_STATUS(Srb, resp->status); - srbStatus = (resp->status == SCSISTAT_GOOD) ? SRB_STATUS_SUCCESS : SRB_STATUS_ERROR; - break; - case VIRTIO_SCSI_S_UNDERRUN: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_UNDERRUN\n"); - srbStatus = SRB_STATUS_DATA_OVERRUN; - break; - case VIRTIO_SCSI_S_ABORTED: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_ABORTED\n"); - srbStatus = SRB_STATUS_ABORTED; - break; - case VIRTIO_SCSI_S_BAD_TARGET: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BAD_TARGET\n"); - srbStatus = SRB_STATUS_INVALID_TARGET_ID; - break; - case VIRTIO_SCSI_S_RESET: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_RESET\n"); - srbStatus = SRB_STATUS_BUS_RESET; - break; - case VIRTIO_SCSI_S_BUSY: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BUSY\n"); - srbStatus = SRB_STATUS_BUSY; - break; - case VIRTIO_SCSI_S_TRANSPORT_FAILURE: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TRANSPORT_FAILURE\n"); - srbStatus = SRB_STATUS_ERROR; - break; - case VIRTIO_SCSI_S_TARGET_FAILURE: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TARGET_FAILURE\n"); - srbStatus = SRB_STATUS_ERROR; - break; - case VIRTIO_SCSI_S_NEXUS_FAILURE: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_NEXUS_FAILURE\n"); - srbStatus = SRB_STATUS_ERROR; - break; - case VIRTIO_SCSI_S_FAILURE: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_FAILURE\n"); - srbStatus = SRB_STATUS_ERROR; - break; - default: - srbStatus = SRB_STATUS_ERROR; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unknown response %d\n", resp->response); - break; - } - if (srbStatus == SRB_STATUS_SUCCESS && - resp->resid && - srbDataTransferLen > resp->resid) + switch (resp->response) + { + case VIRTIO_SCSI_S_OK: + SRB_SET_SCSI_STATUS(Srb, resp->status); + srbStatus = (resp->status == SCSISTAT_GOOD) ? SRB_STATUS_SUCCESS : SRB_STATUS_ERROR; + break; + case VIRTIO_SCSI_S_UNDERRUN: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_UNDERRUN\n"); + srbStatus = SRB_STATUS_DATA_OVERRUN; + break; + case VIRTIO_SCSI_S_ABORTED: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_ABORTED\n"); + srbStatus = SRB_STATUS_ABORTED; + break; + case VIRTIO_SCSI_S_BAD_TARGET: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BAD_TARGET\n"); + srbStatus = SRB_STATUS_INVALID_TARGET_ID; + break; + case VIRTIO_SCSI_S_RESET: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_RESET\n"); + srbStatus = SRB_STATUS_BUS_RESET; + break; + case VIRTIO_SCSI_S_BUSY: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BUSY\n"); + srbStatus = SRB_STATUS_BUSY; + break; + case VIRTIO_SCSI_S_TRANSPORT_FAILURE: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TRANSPORT_FAILURE\n"); + srbStatus = SRB_STATUS_ERROR; + break; + case VIRTIO_SCSI_S_TARGET_FAILURE: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TARGET_FAILURE\n"); + srbStatus = SRB_STATUS_ERROR; + break; + case VIRTIO_SCSI_S_NEXUS_FAILURE: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_NEXUS_FAILURE\n"); + srbStatus = SRB_STATUS_ERROR; + break; + case VIRTIO_SCSI_S_FAILURE: + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_FAILURE\n"); + srbStatus = SRB_STATUS_ERROR; + break; + default: + srbStatus = SRB_STATUS_ERROR; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unknown response %d\n", resp->response); + break; + } + if (srbStatus == SRB_STATUS_SUCCESS && resp->resid && srbDataTransferLen > resp->resid) { SRB_SET_DATA_TRANSFER_LENGTH(Srb, srbDataTransferLen - resp->resid); srbStatus = SRB_STATUS_DATA_OVERRUN; @@ -972,10 +913,11 @@ ENTER_FN(); else if (srbStatus != SRB_STATUS_SUCCESS) { SRB_GET_SENSE_INFO(Srb, senseInfoBuffer, senseInfoBufferLength); - if (senseInfoBufferLength >= FIELD_OFFSET(SENSE_DATA, CommandSpecificInformation)) { - RtlCopyMemory(senseInfoBuffer, resp->sense, - min(resp->sense_len, senseInfoBufferLength)); - if (srbStatus == SRB_STATUS_ERROR) { + if (senseInfoBufferLength >= FIELD_OFFSET(SENSE_DATA, CommandSpecificInformation)) + { + RtlCopyMemory(senseInfoBuffer, resp->sense, min(resp->sense_len, senseInfoBufferLength)); + if (srbStatus == SRB_STATUS_ERROR) + { srbStatus |= SRB_STATUS_AUTOSENSE_VALID; } } @@ -989,21 +931,19 @@ ENTER_FN(); SRB_SET_SRB_STATUS(Srb, srbStatus); CompleteRequest(DeviceExtension, Srb); -EXIT_FN(); + EXIT_FN(); } BOOLEAN -VioScsiInterrupt( - IN PVOID DeviceExtension - ) +VioScsiInterrupt(IN PVOID DeviceExtension) { - PVirtIOSCSICmd cmd = NULL; + PVirtIOSCSICmd cmd = NULL; PVirtIOSCSIEventNode evtNode = NULL; - unsigned int len = 0; - PADAPTER_EXTENSION adaptExt = NULL; - BOOLEAN isInterruptServiced = FALSE; - PSRB_TYPE Srb = NULL; - ULONG intReason = 0; + unsigned int len = 0; + PADAPTER_EXTENSION adaptExt = NULL; + BOOLEAN isInterruptServiced = FALSE; + PSRB_TYPE Srb = NULL; + ULONG intReason = 0; adaptExt = (PADAPTER_EXTENSION)DeviceExtension; @@ -1012,57 +952,64 @@ VioScsiInterrupt( return FALSE; } - //NOTE : SDV banned function - //RhelDbgPrint(TRACE_LEVEL_VERBOSE, " IRQL (%d)\n", KeGetCurrentIrql()); + // NOTE : SDV banned function + // RhelDbgPrint(TRACE_LEVEL_VERBOSE, " IRQL (%d)\n", KeGetCurrentIrql()); intReason = virtio_read_isr_status(&adaptExt->vdev); - if (intReason == 1 || adaptExt->dump_mode) { + if (intReason == 1 || adaptExt->dump_mode) + { isInterruptServiced = TRUE; - if (adaptExt->tmf_infly) { - while((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], &len)) != NULL) { - VirtIOSCSICtrlTMFResp *resp; - Srb = (PSRB_TYPE)cmd->srb; - ASSERT(Srb == (PSRB_TYPE)&adaptExt->tmf_cmd.Srb); - resp = &cmd->resp.tmf; - switch(resp->response) { - case VIRTIO_SCSI_S_OK: - case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: - break; - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " unknown response %d\n", resp->response); - ASSERT(0); - break; - } - StorPortResume(DeviceExtension); - } - adaptExt->tmf_infly = FALSE; + if (adaptExt->tmf_infly) + { + while ((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], &len)) != NULL) + { + VirtIOSCSICtrlTMFResp *resp; + Srb = (PSRB_TYPE)cmd->srb; + ASSERT(Srb == (PSRB_TYPE)&adaptExt->tmf_cmd.Srb); + resp = &cmd->resp.tmf; + switch (resp->response) + { + case VIRTIO_SCSI_S_OK: + case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: + break; + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " unknown response %d\n", resp->response); + ASSERT(0); + break; + } + StorPortResume(DeviceExtension); + } + adaptExt->tmf_infly = FALSE; } - while((evtNode = (PVirtIOSCSIEventNode)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], &len)) != NULL) { - PVirtIOSCSIEvent evt = &evtNode->event; - switch (evt->event) { - case VIRTIO_SCSI_T_NO_EVENT: - break; - case VIRTIO_SCSI_T_TRANSPORT_RESET: - TransportReset(DeviceExtension, evt); - break; - case VIRTIO_SCSI_T_PARAM_CHANGE: - ParamChange(DeviceExtension, evt); - break; - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); - break; - } - SynchronizedKickEventRoutine(DeviceExtension, evtNode); + while ((evtNode = (PVirtIOSCSIEventNode)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], &len)) != + NULL) + { + PVirtIOSCSIEvent evt = &evtNode->event; + switch (evt->event) + { + case VIRTIO_SCSI_T_NO_EVENT: + break; + case VIRTIO_SCSI_T_TRANSPORT_RESET: + TransportReset(DeviceExtension, evt); + break; + case VIRTIO_SCSI_T_PARAM_CHANGE: + ParamChange(DeviceExtension, evt); + break; + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); + break; + } + SynchronizedKickEventRoutine(DeviceExtension, evtNode); } if (!adaptExt->dump_mode && adaptExt->dpc_ok) { StorPortIssueDpc(DeviceExtension, - &adaptExt->dpc[0], - ULongToPtr(QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)), - ULongToPtr(QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0))); + &adaptExt->dpc[0], + ULongToPtr(QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)), + ULongToPtr(QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0))); } else { @@ -1074,23 +1021,18 @@ VioScsiInterrupt( return isInterruptServiced; } -static BOOLEAN -VioScsiMSInterruptWorker( - IN PVOID DeviceExtension, - IN ULONG MessageID - ) +static BOOLEAN VioScsiMSInterruptWorker(IN PVOID DeviceExtension, IN ULONG MessageID) { - PVirtIOSCSICmd cmd; + PVirtIOSCSICmd cmd; PVirtIOSCSIEventNode evtNode; - unsigned int len; - PADAPTER_EXTENSION adaptExt; - PSRB_TYPE Srb = NULL; - ULONG intReason = 0; + unsigned int len; + PADAPTER_EXTENSION adaptExt; + PSRB_TYPE Srb = NULL; + ULONG intReason = 0; adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - RhelDbgPrint(TRACE_LEVEL_VERBOSE, - " MessageID 0x%x\n", MessageID); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " MessageID 0x%x\n", MessageID); if (MessageID >= QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)) { @@ -1099,50 +1041,55 @@ VioScsiMSInterruptWorker( } if (MessageID == 0) { - return TRUE; + return TRUE; } if (MessageID == QUEUE_TO_MESSAGE(VIRTIO_SCSI_CONTROL_QUEUE)) { if (adaptExt->tmf_infly) { - while((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], &len)) != NULL) - { - VirtIOSCSICtrlTMFResp *resp; - Srb = (PSRB_TYPE)(cmd->srb); - ASSERT(Srb == (PSRB_TYPE)&adaptExt->tmf_cmd.Srb); - resp = &cmd->resp.tmf; - switch(resp->response) { - case VIRTIO_SCSI_S_OK: - case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: - break; - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " Unknown response %d\n", resp->response); - ASSERT(0); - break; - } - StorPortResume(DeviceExtension); - } - adaptExt->tmf_infly = FALSE; + while ((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], &len)) != NULL) + { + VirtIOSCSICtrlTMFResp *resp; + Srb = (PSRB_TYPE)(cmd->srb); + ASSERT(Srb == (PSRB_TYPE)&adaptExt->tmf_cmd.Srb); + resp = &cmd->resp.tmf; + switch (resp->response) + { + case VIRTIO_SCSI_S_OK: + case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: + break; + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " Unknown response %d\n", resp->response); + ASSERT(0); + break; + } + StorPortResume(DeviceExtension); + } + adaptExt->tmf_infly = FALSE; } return TRUE; } - if (MessageID == QUEUE_TO_MESSAGE(VIRTIO_SCSI_EVENTS_QUEUE)) { - while((evtNode = (PVirtIOSCSIEventNode)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], &len)) != NULL) { - PVirtIOSCSIEvent evt = &evtNode->event; - switch (evt->event) { - case VIRTIO_SCSI_T_NO_EVENT: - break; - case VIRTIO_SCSI_T_TRANSPORT_RESET: - TransportReset(DeviceExtension, evt); - break; - case VIRTIO_SCSI_T_PARAM_CHANGE: - ParamChange(DeviceExtension, evt); - break; - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); - break; - } - SynchronizedKickEventRoutine(DeviceExtension, evtNode); + if (MessageID == QUEUE_TO_MESSAGE(VIRTIO_SCSI_EVENTS_QUEUE)) + { + while ((evtNode = (PVirtIOSCSIEventNode)virtqueue_get_buf(adaptExt->vq[VIRTIO_SCSI_EVENTS_QUEUE], &len)) != + NULL) + { + PVirtIOSCSIEvent evt = &evtNode->event; + switch (evt->event) + { + case VIRTIO_SCSI_T_NO_EVENT: + break; + case VIRTIO_SCSI_T_TRANSPORT_RESET: + TransportReset(DeviceExtension, evt); + break; + case VIRTIO_SCSI_T_PARAM_CHANGE: + ParamChange(DeviceExtension, evt); + break; + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); + break; + } + SynchronizedKickEventRoutine(DeviceExtension, evtNode); } return TRUE; } @@ -1150,10 +1097,7 @@ VioScsiMSInterruptWorker( } BOOLEAN -VioScsiMSInterrupt( - IN PVOID DeviceExtension, - IN ULONG MessageID - ) +VioScsiMSInterrupt(IN PVOID DeviceExtension, IN ULONG MessageID) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; BOOLEAN isInterruptServiced = FALSE; @@ -1164,14 +1108,17 @@ VioScsiMSInterrupt( return FALSE; } - if (!adaptExt->msix_one_vector) { + if (!adaptExt->msix_one_vector) + { /* Each queue has its own vector, this is the fast and common case */ return VioScsiMSInterruptWorker(DeviceExtension, MessageID); } /* Fall back to checking all queues */ - for (i = 0; i < adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; i++) { - if (virtqueue_has_buf(adaptExt->vq[i])) { + for (i = 0; i < adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0; i++) + { + if (virtqueue_has_buf(adaptExt->vq[i])) + { isInterruptServiced |= VioScsiMSInterruptWorker(DeviceExtension, i + 1); } } @@ -1179,121 +1126,112 @@ VioScsiMSInterrupt( } BOOLEAN -VioScsiResetBus( - IN PVOID DeviceExtension, - IN ULONG PathId - ) +VioScsiResetBus(IN PVOID DeviceExtension, IN ULONG PathId) { - UNREFERENCED_PARAMETER( PathId ); + UNREFERENCED_PARAMETER(PathId); return DeviceReset(DeviceExtension); } SCSI_ADAPTER_CONTROL_STATUS -VioScsiAdapterControl( - IN PVOID DeviceExtension, - IN SCSI_ADAPTER_CONTROL_TYPE ControlType, - IN PVOID Parameters - ) +VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE ControlType, IN PVOID Parameters) { PSCSI_SUPPORTED_CONTROL_TYPE_LIST ControlTypeList; - ULONG AdjustedMaxControlType; - ULONG Index; - PADAPTER_EXTENSION adaptExt; - SCSI_ADAPTER_CONTROL_STATUS status = ScsiAdapterControlUnsuccessful; - BOOLEAN SupportedControlTypes[17] = { 0 }; + ULONG AdjustedMaxControlType; + ULONG Index; + PADAPTER_EXTENSION adaptExt; + SCSI_ADAPTER_CONTROL_STATUS status = ScsiAdapterControlUnsuccessful; + BOOLEAN SupportedControlTypes[17] = {0}; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - SupportedControlTypes[0] = 1; //ScsiQuerySupportedControlTypes - SupportedControlTypes[1] = 1; //ScsiStopAdapter - SupportedControlTypes[2] = 1; //ScsiRestartAdapter - SupportedControlTypes[16] = 1; //ScsiAdapterSurpriseRemoval - - switch (ControlType) { - - case ScsiQuerySupportedControlTypes: { - RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiQuerySupportedControlTypes\n"); - ControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters; - AdjustedMaxControlType = - (ControlTypeList->MaxControlType < 5) ? - ControlTypeList->MaxControlType : - 5; - for (Index = 0; Index < AdjustedMaxControlType; Index++) { - ControlTypeList->SupportedTypeList[Index] = - SupportedControlTypes[Index]; - } - status = ScsiAdapterControlSuccess; - break; - } - case ScsiStopAdapter: { - RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiStopAdapter\n"); - ShutDown(DeviceExtension); - if (adaptExt->pmsg_affinity != NULL) { - StorPortFreePool(DeviceExtension, - (PVOID)adaptExt->pmsg_affinity); - adaptExt->pmsg_affinity = NULL; - } - adaptExt->perfFlags = 0; - status = ScsiAdapterControlSuccess; - break; - } - case ScsiRestartAdapter: { - RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiRestartAdapter\n"); - ShutDown(DeviceExtension); - if (!VioScsiHwReinitialize(DeviceExtension)) - { - RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot reinitialize HW\n"); - break; - } - status = ScsiAdapterControlSuccess; - break; - } - case ScsiAdapterSurpriseRemoval: { - RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiAdapterSurpriseRemoval\n"); - adaptExt->bRemoved = TRUE; - status = ScsiAdapterControlSuccess; - break; - } - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported ControlType %d\n", ControlType); - break; + SupportedControlTypes[0] = 1; // ScsiQuerySupportedControlTypes + SupportedControlTypes[1] = 1; // ScsiStopAdapter + SupportedControlTypes[2] = 1; // ScsiRestartAdapter + SupportedControlTypes[16] = 1; // ScsiAdapterSurpriseRemoval + + switch (ControlType) + { + + case ScsiQuerySupportedControlTypes: + { + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiQuerySupportedControlTypes\n"); + ControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters; + AdjustedMaxControlType = (ControlTypeList->MaxControlType < 5) ? ControlTypeList->MaxControlType : 5; + for (Index = 0; Index < AdjustedMaxControlType; Index++) + { + ControlTypeList->SupportedTypeList[Index] = SupportedControlTypes[Index]; + } + status = ScsiAdapterControlSuccess; + break; + } + case ScsiStopAdapter: + { + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiStopAdapter\n"); + ShutDown(DeviceExtension); + if (adaptExt->pmsg_affinity != NULL) + { + StorPortFreePool(DeviceExtension, (PVOID)adaptExt->pmsg_affinity); + adaptExt->pmsg_affinity = NULL; + } + adaptExt->perfFlags = 0; + status = ScsiAdapterControlSuccess; + break; + } + case ScsiRestartAdapter: + { + RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiRestartAdapter\n"); + ShutDown(DeviceExtension); + if (!VioScsiHwReinitialize(DeviceExtension)) + { + RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot reinitialize HW\n"); + break; + } + status = ScsiAdapterControlSuccess; + break; + } + case ScsiAdapterSurpriseRemoval: + { + RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiAdapterSurpriseRemoval\n"); + adaptExt->bRemoved = TRUE; + status = ScsiAdapterControlSuccess; + break; + } + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported ControlType %d\n", ControlType); + break; } -EXIT_FN(); + EXIT_FN(); return status; } SCSI_UNIT_CONTROL_STATUS -VioScsiUnitControl( - IN PVOID DeviceExtension, - IN SCSI_UNIT_CONTROL_TYPE ControlType, - IN PVOID Parameters - ) +VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlType, IN PVOID Parameters) { PSCSI_SUPPORTED_CONTROL_TYPE_LIST ControlTypeList; - ULONG AdjustedMaxControlType; - ULONG index; - PADAPTER_EXTENSION adaptExt; - SCSI_UNIT_CONTROL_STATUS Status = ScsiUnitControlUnsuccessful; - BOOLEAN SupportedControlTypes[11] = { 0 }; + ULONG AdjustedMaxControlType; + ULONG index; + PADAPTER_EXTENSION adaptExt; + SCSI_UNIT_CONTROL_STATUS Status = ScsiUnitControlUnsuccessful; + BOOLEAN SupportedControlTypes[11] = {0}; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - SupportedControlTypes[0] = 1; //ScsiQuerySupportedControlTypes - SupportedControlTypes[2] = 1; //ScsiUnitStart - SupportedControlTypes[9] = 1; //ScsiUnitRemove - SupportedControlTypes[10] = 1; //ScsiUnitSurpriseRemoval + SupportedControlTypes[0] = 1; // ScsiQuerySupportedControlTypes + SupportedControlTypes[2] = 1; // ScsiUnitStart + SupportedControlTypes[9] = 1; // ScsiUnitRemove + SupportedControlTypes[10] = 1; // ScsiUnitSurpriseRemoval RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unit Control Type %d\n", ControlType); - switch (ControlType) { + switch (ControlType) + { case ScsiQuerySupportedControlTypes: ControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters; - AdjustedMaxControlType = (ControlTypeList->MaxControlType < 11) ? - ControlTypeList->MaxControlType : 11; - for (index = 0; index < AdjustedMaxControlType; index++) { - ControlTypeList->SupportedTypeList[index] = - SupportedControlTypes[index]; + AdjustedMaxControlType = (ControlTypeList->MaxControlType < 11) ? ControlTypeList->MaxControlType : 11; + for (index = 0; index < AdjustedMaxControlType; index++) + { + ControlTypeList->SupportedTypeList[index] = SupportedControlTypes[index]; } Status = ScsiUnitControlSuccess; break; @@ -1302,32 +1240,34 @@ ENTER_FN(); break; case ScsiUnitRemove: case ScsiUnitSurpriseRemoval: - ULONG vq_req_idx; - PREQUEST_LIST element; - STOR_LOCK_HANDLE LockHandle = { 0 }; - PVOID LockContext = NULL; //sanity check for LockMode = InterruptLock or StartIoLock - PSTOR_ADDR_BTL8 stor_addr = (PSTOR_ADDR_BTL8)Parameters; + ULONG vq_req_idx; + PREQUEST_LIST element; + STOR_LOCK_HANDLE LockHandle = {0}; + PVOID LockContext = NULL; // sanity check for LockMode = InterruptLock or StartIoLock + PSTOR_ADDR_BTL8 stor_addr = (PSTOR_ADDR_BTL8)Parameters; - for (vq_req_idx = 0; vq_req_idx < adaptExt->num_queues; vq_req_idx++) { + for (vq_req_idx = 0; vq_req_idx < adaptExt->num_queues; vq_req_idx++) + { element = &adaptExt->processing_srbs[vq_req_idx]; LockContext = &adaptExt->dpc[vq_req_idx]; StorPortAcquireSpinLock(DeviceExtension, DpcLock, LockContext, &LockHandle); if (!IsListEmpty(&element->srb_list)) { PLIST_ENTRY entry = element->srb_list.Flink; - while (entry != &element->srb_list) { + while (entry != &element->srb_list) + { PSRB_EXTENSION currSrbExt = CONTAINING_RECORD(entry, SRB_EXTENSION, list_entry); - PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; - if (SRB_PATH_ID(currSrb) == stor_addr->Path && - SRB_TARGET_ID(currSrb) == stor_addr->Target && - SRB_LUN(currSrb) == stor_addr->Lun) { + PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; + if (SRB_PATH_ID(currSrb) == stor_addr->Path && SRB_TARGET_ID(currSrb) == stor_addr->Target && + SRB_LUN(currSrb) == stor_addr->Lun) + { SRB_SET_SRB_STATUS(currSrb, SRB_STATUS_NO_DEVICE); CompleteRequest(DeviceExtension, (PSRB_TYPE)currSrb); RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " Complete pending I/Os on Path %d Target %d Lun %d \n", - SRB_PATH_ID(currSrb), - SRB_TARGET_ID(currSrb), - SRB_LUN(currSrb)); + " Complete pending I/Os on Path %d Target %d Lun %d \n", + SRB_PATH_ID(currSrb), + SRB_TARGET_ID(currSrb), + SRB_LUN(currSrb)); element->srb_cnt--; } } @@ -1341,43 +1281,37 @@ ENTER_FN(); break; } -EXIT_FN(); + EXIT_FN(); return Status; } BOOLEAN -VioScsiBuildIo( - IN PVOID DeviceExtension, - IN PSCSI_REQUEST_BLOCK Srb - ) +VioScsiBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { - PCDB cdb; - ULONG i; - ULONG fragLen; - ULONG sgElement; - ULONG sgMaxElements; - PADAPTER_EXTENSION adaptExt; - PSRB_EXTENSION srbExt; + PCDB cdb; + ULONG i; + ULONG fragLen; + ULONG sgElement; + ULONG sgMaxElements; + PADAPTER_EXTENSION adaptExt; + PSRB_EXTENSION srbExt; PSTOR_SCATTER_GATHER_LIST sgList; - VirtIOSCSICmd *cmd; - UCHAR TargetId; - UCHAR Lun; + VirtIOSCSICmd *cmd; + UCHAR TargetId; + UCHAR Lun; -ENTER_FN_SRB(); - cdb = SRB_CDB(Srb); - srbExt = SRB_EXTENSION(Srb); + ENTER_FN_SRB(); + cdb = SRB_CDB(Srb); + srbExt = SRB_EXTENSION(Srb); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; TargetId = SRB_TARGET_ID(Srb); - Lun = SRB_LUN(Srb); + Lun = SRB_LUN(Srb); - if( (SRB_PATH_ID(Srb) > (UCHAR)adaptExt->num_queues) || - (TargetId >= adaptExt->scsi_config.max_target) || - (Lun >= adaptExt->scsi_config.max_lun) || - adaptExt->bRemoved) { + if ((SRB_PATH_ID(Srb) > (UCHAR)adaptExt->num_queues) || (TargetId >= adaptExt->scsi_config.max_target) || + (Lun >= adaptExt->scsi_config.max_lun) || adaptExt->bRemoved) + { SRB_SET_SRB_STATUS(Srb, SRB_STATUS_NO_DEVICE); - StorPortNotification(RequestComplete, - DeviceExtension, - Srb); + StorPortNotification(RequestComplete, DeviceExtension, Srb); return FALSE; } @@ -1398,13 +1332,14 @@ ENTER_FN_SRB(); cmd->req.cmd.task_attr = VIRTIO_SCSI_S_SIMPLE; cmd->req.cmd.prio = 0; cmd->req.cmd.crn = 0; - if (cdb != NULL) { + if (cdb != NULL) + { RtlCopyMemory(cmd->req.cmd.cdb, cdb, min(VIRTIO_SCSI_CDB_SIZE, SRB_CDB_LENGTH(Srb))); } sgElement = 0; srbExt->psgl[sgElement].physAddr = StorPortGetPhysicalAddress(DeviceExtension, NULL, &cmd->req.cmd, &fragLen); - srbExt->psgl[sgElement].length = sizeof(cmd->req.cmd); + srbExt->psgl[sgElement].length = sizeof(cmd->req.cmd); sgElement++; sgList = StorPortGetScatterGatherList(DeviceExtension, Srb); @@ -1412,8 +1347,10 @@ ENTER_FN_SRB(); { sgMaxElements = min((adaptExt->max_physical_breaks + 1), sgList->NumberOfElements); - if((SRB_FLAGS(Srb) & SRB_FLAGS_DATA_OUT) == SRB_FLAGS_DATA_OUT) { - for (i = 0; i < sgMaxElements; i++, sgElement++) { + if ((SRB_FLAGS(Srb) & SRB_FLAGS_DATA_OUT) == SRB_FLAGS_DATA_OUT) + { + for (i = 0; i < sgMaxElements; i++, sgElement++) + { srbExt->psgl[sgElement].physAddr = sgList->List[i].PhysicalAddress; srbExt->psgl[sgElement].length = sgList->List[i].Length; srbExt->Xfer += sgList->List[i].Length; @@ -1429,8 +1366,10 @@ ENTER_FN_SRB(); { sgMaxElements = min((adaptExt->max_physical_breaks + 1), sgList->NumberOfElements); - if((SRB_FLAGS(Srb) & SRB_FLAGS_DATA_OUT) != SRB_FLAGS_DATA_OUT) { - for (i = 0; i < sgMaxElements; i++, sgElement++) { + if ((SRB_FLAGS(Srb) & SRB_FLAGS_DATA_OUT) != SRB_FLAGS_DATA_OUT) + { + for (i = 0; i < sgMaxElements; i++, sgElement++) + { srbExt->psgl[sgElement].physAddr = sgList->List[i].PhysicalAddress; srbExt->psgl[sgElement].length = sgList->List[i].Length; srbExt->Xfer += sgList->List[i].Length; @@ -1441,72 +1380,67 @@ ENTER_FN_SRB(); if (adaptExt->resp_time) { - LARGE_INTEGER counter = { 0 }; + LARGE_INTEGER counter = {0}; ULONG status = STOR_STATUS_SUCCESS; status = StorPortQueryPerformanceCounter(DeviceExtension, NULL, &counter); - if ( status == STOR_STATUS_SUCCESS) + if (status == STOR_STATUS_SUCCESS) { srbExt->time = counter.QuadPart; } else { - RhelDbgPrint(TRACE_LEVEL_ERROR, "SRB 0x%p StorPortQueryPerformanceCounter failed with status 0x%lx\n", Srb, status); + RhelDbgPrint(TRACE_LEVEL_ERROR, + "SRB 0x%p StorPortQueryPerformanceCounter failed with status 0x%lx\n", + Srb, + status); } } -EXIT_FN_SRB(); + EXIT_FN_SRB(); return TRUE; } - -VOID -FORCEINLINE -DispatchQueue( - IN PVOID DeviceExtension, - IN ULONG MessageId -) +VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId) { - PADAPTER_EXTENSION adaptExt; -ENTER_FN(); + PADAPTER_EXTENSION adaptExt; + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - if (!adaptExt->dump_mode && adaptExt->dpc_ok) { + if (!adaptExt->dump_mode && adaptExt->dpc_ok) + { NT_ASSERT(MessageId >= QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)); StorPortIssueDpc(DeviceExtension, - &adaptExt->dpc[MessageId - QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)], - ULongToPtr(MessageId), - ULongToPtr(MessageId)); -EXIT_FN(); + &adaptExt->dpc[MessageId - QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)], + ULongToPtr(MessageId), + ULongToPtr(MessageId)); + EXIT_FN(); return; } ProcessBuffer(DeviceExtension, MessageId, InterruptLock); -EXIT_FN(); + EXIT_FN(); } -VOID -ProcessBuffer( - IN PVOID DeviceExtension, - IN ULONG MessageId, - IN STOR_SPINLOCK LockMode -) +VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOCK LockMode) { - PVirtIOSCSICmd cmd; - unsigned int len; - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - ULONG QueueNumber = MESSAGE_TO_QUEUE(MessageId); - STOR_LOCK_HANDLE LockHandle = { 0 }; - struct virtqueue *vq; - PSRB_TYPE Srb = NULL; - PSRB_EXTENSION srbExt = NULL; - PREQUEST_LIST element; - ULONG vq_req_idx; - PVOID LockContext = NULL; //sanity check for LockMode = InterruptLock or StartIoLock - -ENTER_FN(); - - if (QueueNumber >= (adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) { - RhelDbgPrint(TRACE_LEVEL_VERBOSE, " Modulo assignment required for QueueNumber as it exceeds the number of virtqueues available.\n"); + PVirtIOSCSICmd cmd; + unsigned int len; + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; + ULONG QueueNumber = MESSAGE_TO_QUEUE(MessageId); + STOR_LOCK_HANDLE LockHandle = {0}; + struct virtqueue *vq; + PSRB_TYPE Srb = NULL; + PSRB_EXTENSION srbExt = NULL; + PREQUEST_LIST element; + ULONG vq_req_idx; + PVOID LockContext = NULL; // sanity check for LockMode = InterruptLock or StartIoLock + + ENTER_FN(); + + if (QueueNumber >= (adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) + { + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " Modulo assignment required for QueueNumber as it exceeds the number of virtqueues available.\n"); QueueNumber %= adaptExt->num_queues; } vq_req_idx = QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0; @@ -1514,26 +1448,30 @@ ENTER_FN(); vq = adaptExt->vq[QueueNumber]; - if (LockMode == DpcLock) { + if (LockMode == DpcLock) + { LockContext = &adaptExt->dpc[vq_req_idx]; } - StorPortAcquireSpinLock(DeviceExtension, LockMode, LockContext, &LockHandle); + StorPortAcquireSpinLock(DeviceExtension, LockMode, LockContext, &LockHandle); - do { + do + { virtqueue_disable_cb(vq); - while ((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(vq, &len)) != NULL) { + while ((cmd = (PVirtIOSCSICmd)virtqueue_get_buf(vq, &len)) != NULL) + { PLIST_ENTRY le = NULL; BOOLEAN bFound = FALSE; Srb = (PSRB_TYPE)(cmd->srb); - if (!Srb) { + if (!Srb) + { continue; } srbExt = SRB_EXTENSION(Srb); for (le = element->srb_list.Flink; le != &element->srb_list && !bFound; le = le->Flink) { PSRB_EXTENSION currSrbExt = CONTAINING_RECORD(le, SRB_EXTENSION, list_entry); - PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; + PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; if (currSrbExt == srbExt && (PSRB_TYPE)currSrb == Srb) { @@ -1543,7 +1481,8 @@ ENTER_FN(); break; } } - if (bFound) { + if (bFound) + { HandleResponse(DeviceExtension, cmd); } } @@ -1551,36 +1490,27 @@ ENTER_FN(); StorPortReleaseSpinLock(DeviceExtension, &LockHandle); -EXIT_FN(); + EXIT_FN(); } -VOID -VioScsiCompleteDpcRoutine( - IN PSTOR_DPC Dpc, - IN PVOID Context, - IN PVOID SystemArgument1, - IN PVOID SystemArgument2 - ) +VOID VioScsiCompleteDpcRoutine(IN PSTOR_DPC Dpc, IN PVOID Context, IN PVOID SystemArgument1, IN PVOID SystemArgument2) { ULONG MessageId; -ENTER_FN(); + ENTER_FN(); MessageId = PtrToUlong(SystemArgument1); ProcessBuffer(Context, MessageId, DpcLock); -EXIT_FN(); + EXIT_FN(); } -VOID -CompletePendingRequestsOnReset( - IN PVOID DeviceExtension - ) +VOID CompletePendingRequestsOnReset(IN PVOID DeviceExtension) { - PADAPTER_EXTENSION adaptExt; - ULONG QueueNumber; - ULONG vq_req_idx; - PREQUEST_LIST element; - STOR_LOCK_HANDLE LockHandle = { 0 }; - PVOID LockContext = NULL; //sanity check for LockMode = InterruptLock or StartIoLock + PADAPTER_EXTENSION adaptExt; + ULONG QueueNumber; + ULONG vq_req_idx; + PREQUEST_LIST element; + STOR_LOCK_HANDLE LockHandle = {0}; + PVOID LockContext = NULL; // sanity check for LockMode = InterruptLock or StartIoLock adaptExt = (PADAPTER_EXTENSION)DeviceExtension; @@ -1590,62 +1520,68 @@ CompletePendingRequestsOnReset( StorPortPause(DeviceExtension, 10); DeviceReset(DeviceExtension); - for (vq_req_idx = 0; vq_req_idx < adaptExt->num_queues; vq_req_idx++) { + for (vq_req_idx = 0; vq_req_idx < adaptExt->num_queues; vq_req_idx++) + { element = &adaptExt->processing_srbs[vq_req_idx]; RhelDbgPrint(TRACE_LEVEL_FATAL, " queue %d cnt %d\n", vq_req_idx, element->srb_cnt); LockContext = &adaptExt->dpc[vq_req_idx]; StorPortAcquireSpinLock(DeviceExtension, DpcLock, LockContext, &LockHandle); - while (!IsListEmpty(&element->srb_list)) { + while (!IsListEmpty(&element->srb_list)) + { PLIST_ENTRY entry = RemoveHeadList(&element->srb_list); - if (entry) { + if (entry) + { PSRB_EXTENSION currSrbExt = CONTAINING_RECORD(entry, SRB_EXTENSION, list_entry); - PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; - if (currSrb) { + PSCSI_REQUEST_BLOCK currSrb = currSrbExt->Srb; + if (currSrb) + { SRB_SET_SRB_STATUS(currSrb, SRB_STATUS_BUS_RESET); CompleteRequest(DeviceExtension, (PSRB_TYPE)currSrb); element->srb_cnt--; } } } - if (element->srb_cnt) { + if (element->srb_cnt) + { element->srb_cnt = 0; } StorPortReleaseSpinLock(DeviceExtension, &LockHandle); } StorPortResume(DeviceExtension); } - else { + else + { RhelDbgPrint(TRACE_LEVEL_FATAL, " Reset is already in progress, doing nothing.\n"); } adaptExt->reset_in_progress = FALSE; } UCHAR -VioScsiProcessPnP( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +VioScsiProcessPnP(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { - PADAPTER_EXTENSION adaptExt; + PADAPTER_EXTENSION adaptExt; PSCSI_PNP_REQUEST_BLOCK pnpBlock; - ULONG SrbPnPFlags; - ULONG PnPAction; - UCHAR SrbStatus; + ULONG SrbPnPFlags; + ULONG PnPAction; + UCHAR SrbStatus; -ENTER_FN(); - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - pnpBlock = (PSCSI_PNP_REQUEST_BLOCK)Srb; + ENTER_FN(); + adaptExt = (PADAPTER_EXTENSION)DeviceExtension; + pnpBlock = (PSCSI_PNP_REQUEST_BLOCK)Srb; SrbStatus = SRB_STATUS_SUCCESS; SRB_GET_PNP_INFO(Srb, SrbPnPFlags, PnPAction); - switch (PnPAction) { + switch (PnPAction) + { case StorQueryCapabilities: RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " StorQueryCapabilities on %d::%d::%d\n", - SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb)); + " StorQueryCapabilities on %d::%d::%d\n", + SRB_PATH_ID(Srb), + SRB_TARGET_ID(Srb), + SRB_LUN(Srb)); if (((SrbPnPFlags & SRB_PNP_FLAGS_ADAPTER_REQUEST) == 0) || - (SRB_DATA_TRANSFER_LENGTH(Srb) >= sizeof(STOR_DEVICE_CAPABILITIES))) { - PSTOR_DEVICE_CAPABILITIES devCap = - (PSTOR_DEVICE_CAPABILITIES)SRB_DATA_BUFFER(Srb); + (SRB_DATA_TRANSFER_LENGTH(Srb) >= sizeof(STOR_DEVICE_CAPABILITIES))) + { + PSTOR_DEVICE_CAPABILITIES devCap = (PSTOR_DEVICE_CAPABILITIES)SRB_DATA_BUFFER(Srb); RtlZeroMemory(devCap, sizeof(*devCap)); devCap->Removable = 1; devCap->SurpriseRemovalOK = 1; @@ -1654,34 +1590,35 @@ ENTER_FN(); case StorRemoveDevice: case StorSurpriseRemoval: RhelDbgPrint(TRACE_LEVEL_FATAL, - " Adapter Removal happens on %d::%d::%d\n", - SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb)); + " Adapter Removal happens on %d::%d::%d\n", + SRB_PATH_ID(Srb), + SRB_TARGET_ID(Srb), + SRB_LUN(Srb)); adaptExt->bRemoved = TRUE; break; default: RhelDbgPrint(TRACE_LEVEL_FATAL, - " Unsupported PnPAction SrbPnPFlags = %d, PnPAction = %d\n", - SrbPnPFlags, PnPAction); + " Unsupported PnPAction SrbPnPFlags = %d, PnPAction = %d\n", + SrbPnPFlags, + PnPAction); SrbStatus = SRB_STATUS_INVALID_REQUEST; break; } -EXIT_FN(); + EXIT_FN(); return SrbStatus; } BOOLEAN FORCEINLINE -PreProcessRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { PADAPTER_EXTENSION adaptExt; -ENTER_FN_SRB(); + ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - switch (SRB_FUNCTION(Srb)) { + switch (SRB_FUNCTION(Srb)) + { case SRB_FUNCTION_PNP: SRB_SET_SRB_STATUS(Srb, VioScsiProcessPnP(DeviceExtension, Srb)); return TRUE; @@ -1693,8 +1630,14 @@ ENTER_FN_SRB(); case SRB_FUNCTION_RESET_BUS: case SRB_FUNCTION_RESET_DEVICE: case SRB_FUNCTION_RESET_LOGICAL_UNIT: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> SRB_FUNCTION_RESET_LOGICAL_UNIT Target (%d::%d::%d), SRB 0x%p\n", SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); - switch (adaptExt->action_on_reset) { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " <--> SRB_FUNCTION_RESET_LOGICAL_UNIT Target (%d::%d::%d), SRB 0x%p\n", + SRB_PATH_ID(Srb), + SRB_TARGET_ID(Srb), + SRB_LUN(Srb), + Srb); + switch (adaptExt->action_on_reset) + { case VioscsiResetCompleteRequests: RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Completing all pending SRBs\n"); CompletePendingRequestsOnReset(DeviceExtension); @@ -1716,26 +1659,25 @@ ENTER_FN_SRB(); VioScsiIoControl(DeviceExtension, Srb); return TRUE; } -EXIT_FN_SRB(); + EXIT_FN_SRB(); return FALSE; } -VOID -PostProcessRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +VOID PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { - PCDB cdb = NULL; - PADAPTER_EXTENSION adaptExt = NULL; - PSRB_EXTENSION srbExt = NULL; -ENTER_FN_SRB(); - if (SRB_FUNCTION(Srb) != SRB_FUNCTION_EXECUTE_SCSI) { + PCDB cdb = NULL; + PADAPTER_EXTENSION adaptExt = NULL; + PSRB_EXTENSION srbExt = NULL; + ENTER_FN_SRB(); + if (SRB_FUNCTION(Srb) != SRB_FUNCTION_EXECUTE_SCSI) + { return; } - cdb = SRB_CDB(Srb); + cdb = SRB_CDB(Srb); if (!cdb) + { return; + } adaptExt = (PADAPTER_EXTENSION)DeviceExtension; @@ -1743,35 +1685,34 @@ ENTER_FN_SRB(); { case SCSIOP_READ_CAPACITY: case SCSIOP_READ_CAPACITY16: - break; + break; case SCSIOP_INQUIRY: - VioScsiSaveInquiryData(DeviceExtension, Srb); - VioScsiPatchInquiryData(DeviceExtension, Srb); - if (!StorPortSetDeviceQueueDepth( DeviceExtension, SRB_PATH_ID(Srb), - SRB_TARGET_ID(Srb), SRB_LUN(Srb), - adaptExt->queue_depth)) { - RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortSetDeviceQueueDepth(%p, %x) failed.\n", - DeviceExtension, - adaptExt->queue_depth); - } - break; + VioScsiSaveInquiryData(DeviceExtension, Srb); + VioScsiPatchInquiryData(DeviceExtension, Srb); + if (!StorPortSetDeviceQueueDepth(DeviceExtension, + SRB_PATH_ID(Srb), + SRB_TARGET_ID(Srb), + SRB_LUN(Srb), + adaptExt->queue_depth)) + { + RhelDbgPrint(TRACE_LEVEL_ERROR, + " StorPortSetDeviceQueueDepth(%p, %x) failed.\n", + DeviceExtension, + adaptExt->queue_depth); + } + break; default: - break; - + break; } -EXIT_FN_SRB(); + EXIT_FN_SRB(); } -VOID -CompleteRequest( - IN PVOID DeviceExtension, - IN PSRB_TYPE Srb - ) +VOID CompleteRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { - PADAPTER_EXTENSION adaptExt = NULL; - PSRB_EXTENSION srbExt = NULL; + PADAPTER_EXTENSION adaptExt = NULL; + PSRB_EXTENSION srbExt = NULL; - ENTER_FN_SRB(); + ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; PostProcessRequest(DeviceExtension, Srb); @@ -1780,115 +1721,114 @@ CompleteRequest( srbExt = SRB_EXTENSION(Srb); if (srbExt->time != 0) { - LARGE_INTEGER counter = { 0 }; - LARGE_INTEGER freq = { 0 }; + LARGE_INTEGER counter = {0}; + LARGE_INTEGER freq = {0}; ULONG status = StorPortQueryPerformanceCounter(DeviceExtension, &freq, &counter); if (status == STOR_STATUS_SUCCESS) { ULONGLONG time_msec = ((counter.QuadPart - srbExt->time) * 1000) / freq.QuadPart; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, "time_msec %I64d Start %llu End %llu Freq %llu\n", - time_msec, srbExt->time, counter.QuadPart, freq.QuadPart); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + "time_msec %I64d Start %llu End %llu Freq %llu\n", + time_msec, + srbExt->time, + counter.QuadPart, + freq.QuadPart); if (time_msec >= adaptExt->resp_time) { PCDB cdb = SRB_CDB(Srb); - if (cdb) { // Check for SDV compliance + if (cdb) + { // Check for SDV compliance UCHAR OpCode = cdb->CDB6GENERIC.OperationCode; - RhelDbgPrint(TRACE_LEVEL_WARNING, "Response Time SRB 0x%p : time %I64d (%lu) : length %d : OpCode 0x%x (%s)\n", - Srb, time_msec, SRB_GET_TIMEOUTVALUE(Srb) * 1000, SRB_DATA_TRANSFER_LENGTH(Srb), - OpCode, DbgGetScsiOpStr(OpCode)); + RhelDbgPrint(TRACE_LEVEL_WARNING, + "Response Time SRB 0x%p : time %I64d (%lu) : length %d : OpCode 0x%x (%s)\n", + Srb, + time_msec, + SRB_GET_TIMEOUTVALUE(Srb) * 1000, + SRB_DATA_TRANSFER_LENGTH(Srb), + OpCode, + DbgGetScsiOpStr(OpCode)); DbgPrint("Response Time SRB 0x%p : time %I64d (%lu) : length %d : OpCode 0x%x (%s)\n", - Srb, time_msec, SRB_GET_TIMEOUTVALUE(Srb) * 1000, SRB_DATA_TRANSFER_LENGTH(Srb), - OpCode, DbgGetScsiOpStr(OpCode)); + Srb, + time_msec, + SRB_GET_TIMEOUTVALUE(Srb) * 1000, + SRB_DATA_TRANSFER_LENGTH(Srb), + OpCode, + DbgGetScsiOpStr(OpCode)); } } } else { - RhelDbgPrint(TRACE_LEVEL_ERROR, "SRB 0x%p StorPortQueryPerformanceCounter failed with status 0x%lx\n", Srb, status); + RhelDbgPrint(TRACE_LEVEL_ERROR, + "SRB 0x%p StorPortQueryPerformanceCounter failed with status 0x%lx\n", + Srb, + status); } } } - StorPortNotification(RequestComplete, - DeviceExtension, - Srb); -EXIT_FN_SRB(); + StorPortNotification(RequestComplete, DeviceExtension, Srb); + EXIT_FN_SRB(); } -VOID -LogError( - IN PVOID DeviceExtension, - IN ULONG ErrorCode, - IN ULONG UniqueId - ) +VOID LogError(IN PVOID DeviceExtension, IN ULONG ErrorCode, IN ULONG UniqueId) { STOR_LOG_EVENT_DETAILS logEvent; ULONG sz = 0; - RtlZeroMemory( &logEvent, sizeof(logEvent) ); - logEvent.InterfaceRevision = STOR_CURRENT_LOG_INTERFACE_REVISION; - logEvent.Size = sizeof(logEvent); - logEvent.EventAssociation = StorEventAdapterAssociation; + RtlZeroMemory(&logEvent, sizeof(logEvent)); + logEvent.InterfaceRevision = STOR_CURRENT_LOG_INTERFACE_REVISION; + logEvent.Size = sizeof(logEvent); + logEvent.EventAssociation = StorEventAdapterAssociation; logEvent.StorportSpecificErrorCode = TRUE; - logEvent.ErrorCode = ErrorCode; - logEvent.DumpDataSize = sizeof(UniqueId); - logEvent.DumpData = &UniqueId; - StorPortLogSystemEvent( DeviceExtension, &logEvent, &sz ); + logEvent.ErrorCode = ErrorCode; + logEvent.DumpDataSize = sizeof(UniqueId); + logEvent.DumpData = &UniqueId; + StorPortLogSystemEvent(DeviceExtension, &logEvent, &sz); } -VOID -TransportReset( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEvent evt - ) +VOID TransportReset(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) { UCHAR TargetId = evt->lun[1]; UCHAR Lun = (evt->lun[2] << 8) | evt->lun[3]; -ENTER_FN(); + ENTER_FN(); switch (evt->reason) { case VIRTIO_SCSI_EVT_RESET_RESCAN: - StorPortNotification( BusChangeDetected, DeviceExtension, 0); - break; + StorPortNotification(BusChangeDetected, DeviceExtension, 0); + break; case VIRTIO_SCSI_EVT_RESET_REMOVED: - StorPortNotification( BusChangeDetected, DeviceExtension, 0); - break; + StorPortNotification(BusChangeDetected, DeviceExtension, 0); + break; default: - RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <--> Unsupport virtio scsi event reason 0x%x\n", evt->reason); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <--> Unsupport virtio scsi event reason 0x%x\n", evt->reason); } -EXIT_FN(); + EXIT_FN(); } -VOID -ParamChange( - IN PVOID DeviceExtension, - IN PVirtIOSCSIEvent evt - ) +VOID ParamChange(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) { UCHAR TargetId = evt->lun[1]; UCHAR Lun = (evt->lun[2] << 8) | evt->lun[3]; UCHAR AdditionalSenseCode = (UCHAR)(evt->reason & 255); UCHAR AdditionalSenseCodeQualifier = (UCHAR)(evt->reason >> 8); -ENTER_FN(); + ENTER_FN(); if (AdditionalSenseCode == SCSI_ADSENSE_PARAMETERS_CHANGED && - (AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_PARAMETERS_CHANGED || - AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_MODE_PARAMETERS_CHANGED || - AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_CAPACITY_DATA_HAS_CHANGED)) + (AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_PARAMETERS_CHANGED || + AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_MODE_PARAMETERS_CHANGED || + AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_CAPACITY_DATA_HAS_CHANGED)) { - StorPortNotification( BusChangeDetected, DeviceExtension, 0); + StorPortNotification(BusChangeDetected, DeviceExtension, 0); } -EXIT_FN(); + EXIT_FN(); } -VOID -VioScsiWmiInitialize( - IN PVOID DeviceExtension - ) +VOID VioScsiWmiInitialize(IN PVOID DeviceExtension) { - PADAPTER_EXTENSION adaptExt; + PADAPTER_EXTENSION adaptExt; PSCSI_WMILIB_CONTEXT WmiLibContext; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; WmiLibContext = (PSCSI_WMILIB_CONTEXT)(&(adaptExt->WmiLibContext)); @@ -1901,31 +1841,29 @@ ENTER_FN(); WmiLibContext->SetWmiDataBlock = NULL; WmiLibContext->ExecuteWmiMethod = VioScsiExecuteWmiMethod; WmiLibContext->WmiFunctionControl = NULL; -EXIT_FN(); + EXIT_FN(); } -VOID -VioScsiWmiSrb( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ) +VOID VioScsiWmiSrb(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { UCHAR status; SCSIWMI_REQUEST_CONTEXT requestContext = {0}; ULONG retSize; - PADAPTER_EXTENSION adaptExt; + PADAPTER_EXTENSION adaptExt; PSRB_WMI_DATA pSrbWmi = SRB_WMI_DATA(Srb); -ENTER_FN_SRB(); + ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; ASSERT(SRB_FUNCTION(Srb) == SRB_FUNCTION_WMI); - ASSERT(SRB_LENGTH(Srb) == sizeof(SCSI_WMI_REQUEST_BLOCK)); + ASSERT(SRB_LENGTH(Srb) == sizeof(SCSI_WMI_REQUEST_BLOCK)); ASSERT(SRB_DATA_TRANSFER_LENGTH(Srb) >= sizeof(ULONG)); ASSERT(SRB_DATA_BUFFER(Srb)); if (!pSrbWmi) + { return; + } if (!(pSrbWmi->WMIFlags & SRB_WMI_FLAGS_ADAPTER_REQUEST)) { SRB_SET_DATA_TRANSFER_LENGTH(Srb, 0); @@ -1934,45 +1872,49 @@ ENTER_FN_SRB(); else { requestContext.UserContext = Srb; - (VOID)ScsiPortWmiDispatchFunction(&adaptExt->WmiLibContext, - pSrbWmi->WMISubFunction, - DeviceExtension, - &requestContext, - pSrbWmi->DataPath, - SRB_DATA_TRANSFER_LENGTH(Srb), - SRB_DATA_BUFFER(Srb)); + (VOID) ScsiPortWmiDispatchFunction(&adaptExt->WmiLibContext, + pSrbWmi->WMISubFunction, + DeviceExtension, + &requestContext, + pSrbWmi->DataPath, + SRB_DATA_TRANSFER_LENGTH(Srb), + SRB_DATA_BUFFER(Srb)); - retSize = ScsiPortWmiGetReturnSize(&requestContext); - status = ScsiPortWmiGetReturnStatus(&requestContext); + retSize = ScsiPortWmiGetReturnSize(&requestContext); + status = ScsiPortWmiGetReturnStatus(&requestContext); SRB_SET_DATA_TRANSFER_LENGTH(Srb, retSize); SRB_SET_SRB_STATUS(Srb, status); } -EXIT_FN_SRB(); + EXIT_FN_SRB(); } -VOID -VioScsiIoControl( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ) +VOID VioScsiIoControl(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { PSRB_IO_CONTROL srbControl; - PVOID srbDataBuffer = SRB_DATA_BUFFER(Srb); - PADAPTER_EXTENSION adaptExt; + PVOID srbDataBuffer = SRB_DATA_BUFFER(Srb); + PADAPTER_EXTENSION adaptExt; -ENTER_FN_SRB(); + ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; srbControl = (PSRB_IO_CONTROL)srbDataBuffer; - switch (srbControl->ControlCode) { + switch (srbControl->ControlCode) + { case IOCTL_SCSI_MINIPORT_NOT_QUORUM_CAPABLE: SRB_SET_SRB_STATUS(Srb, SRB_STATUS_ERROR); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> Signature = %02x %02x %02x %02x %02x %02x %02x %02x\n", - srbControl->Signature[0], srbControl->Signature[1], srbControl->Signature[2], srbControl->Signature[3], - srbControl->Signature[4], srbControl->Signature[5], srbControl->Signature[6], srbControl->Signature[7]); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " <--> Signature = %02x %02x %02x %02x %02x %02x %02x %02x\n", + srbControl->Signature[0], + srbControl->Signature[1], + srbControl->Signature[2], + srbControl->Signature[3], + srbControl->Signature[4], + srbControl->Signature[5], + srbControl->Signature[6], + srbControl->Signature[7]); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> IOCTL_SCSI_MINIPORT_NOT_QUORUM_CAPABLE\n"); break; case IOCTL_SCSI_MINIPORT_FIRMWARE: @@ -1984,67 +1926,79 @@ ENTER_FN_SRB(); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> Unsupport control code 0x%x\n", srbControl->ControlCode); break; } -EXIT_FN_SRB(); + EXIT_FN_SRB(); } UCHAR -ParseIdentificationDescr( - IN PVOID DeviceExtension, - IN PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr, - IN UCHAR PageLength -) +ParseIdentificationDescr(IN PVOID DeviceExtension, + IN PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr, + IN UCHAR PageLength) { - PADAPTER_EXTENSION adaptExt; + PADAPTER_EXTENSION adaptExt; UCHAR CodeSet = 0; UCHAR IdentifierType = 0; adaptExt = (PADAPTER_EXTENSION)DeviceExtension; ENTER_FN(); - if (IdentificationDescr) { - CodeSet = IdentificationDescr->CodeSet;//(UCHAR)(((PCHAR)IdentificationDescr)[0]); - IdentifierType = IdentificationDescr->IdentifierType;//(UCHAR)(((PCHAR)IdentificationDescr)[1]); - switch (IdentifierType) { - case VioscsiVpdIdentifierTypeVendorSpecific: { - if (CodeSet == VioscsiVpdCodeSetAscii) { - if (IdentificationDescr->IdentifierLength > 0 && adaptExt->ser_num == NULL) { - int ln = min(64, IdentificationDescr->IdentifierLength); - ULONG Status = - StorPortAllocatePool(DeviceExtension, - ln + 1, - VIOSCSI_POOL_TAG, - (PVOID*)&adaptExt->ser_num); - if (NT_SUCCESS(Status)) { - StorPortMoveMemory(adaptExt->ser_num, IdentificationDescr->Identifier, ln); - adaptExt->ser_num[ln] = '\0'; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); + if (IdentificationDescr) + { + CodeSet = IdentificationDescr->CodeSet; //(UCHAR)(((PCHAR)IdentificationDescr)[0]); + IdentifierType = IdentificationDescr->IdentifierType; //(UCHAR)(((PCHAR)IdentificationDescr)[1]); + switch (IdentifierType) + { + case VioscsiVpdIdentifierTypeVendorSpecific: + { + if (CodeSet == VioscsiVpdCodeSetAscii) + { + if (IdentificationDescr->IdentifierLength > 0 && adaptExt->ser_num == NULL) + { + int ln = min(64, IdentificationDescr->IdentifierLength); + ULONG Status = StorPortAllocatePool(DeviceExtension, + ln + 1, + VIOSCSI_POOL_TAG, + (PVOID *)&adaptExt->ser_num); + if (NT_SUCCESS(Status)) + { + StorPortMoveMemory(adaptExt->ser_num, IdentificationDescr->Identifier, ln); + adaptExt->ser_num[ln] = '\0'; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); + } + } } } - } - } - break; - case VioscsiVpdIdentifierTypeFCPHName: { - if ((CodeSet == VioscsiVpdCodeSetBinary) && (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) { - REVERSE_BYTES_QUAD(&adaptExt->wwn, IdentificationDescr->Identifier); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " wwn %llu\n", (ULONGLONG)adaptExt->wwn); - } - } - break; - case VioscsiVpdIdentifierTypeFCTargetPortPHName: { - if ((CodeSet == VioscsiVpdCodeSetSASBinary) && (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) { - REVERSE_BYTES_QUAD(&adaptExt->port_wwn, IdentificationDescr->Identifier); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port wwn %llu\n", (ULONGLONG)adaptExt->port_wwn); - } - } - break; - case VioscsiVpdIdentifierTypeFCTargetPortRelativeTargetPort: { - if ((CodeSet == VioscsiVpdCodeSetSASBinary) && (IdentificationDescr->IdentifierLength == sizeof(ULONG))) { - REVERSE_BYTES(&adaptExt->port_idx, IdentificationDescr->Identifier); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port index %lu\n", (ULONG)adaptExt->port_idx); - } - } - break; - default: - RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported IdentifierType = %x!\n", IdentifierType); - break; + break; + case VioscsiVpdIdentifierTypeFCPHName: + { + if ((CodeSet == VioscsiVpdCodeSetBinary) && + (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) + { + REVERSE_BYTES_QUAD(&adaptExt->wwn, IdentificationDescr->Identifier); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " wwn %llu\n", (ULONGLONG)adaptExt->wwn); + } + } + break; + case VioscsiVpdIdentifierTypeFCTargetPortPHName: + { + if ((CodeSet == VioscsiVpdCodeSetSASBinary) && + (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) + { + REVERSE_BYTES_QUAD(&adaptExt->port_wwn, IdentificationDescr->Identifier); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port wwn %llu\n", (ULONGLONG)adaptExt->port_wwn); + } + } + break; + case VioscsiVpdIdentifierTypeFCTargetPortRelativeTargetPort: + { + if ((CodeSet == VioscsiVpdCodeSetSASBinary) && + (IdentificationDescr->IdentifierLength == sizeof(ULONG))) + { + REVERSE_BYTES(&adaptExt->port_idx, IdentificationDescr->Identifier); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port index %lu\n", (ULONG)adaptExt->port_idx); + } + } + break; + default: + RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported IdentifierType = %x!\n", IdentifierType); + break; } return IdentificationDescr->IdentifierLength; } @@ -2052,171 +2006,196 @@ ParseIdentificationDescr( return 0; } -VOID -VioScsiSaveInquiryData( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb - ) +VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { - PVOID dataBuffer; - PADAPTER_EXTENSION adaptExt; + PVOID dataBuffer; + PADAPTER_EXTENSION adaptExt; PCDB cdb; ULONG dataLen; UCHAR SrbStatus = SRB_STATUS_SUCCESS; -ENTER_FN_SRB(); + ENTER_FN_SRB(); if (!Srb) + { return; + } - cdb = SRB_CDB(Srb); + cdb = SRB_CDB(Srb); if (!cdb) + { return; + } SRB_GET_SCSI_STATUS(Srb, SrbStatus); if (SrbStatus == SRB_STATUS_ERROR) + { return; + } adaptExt = (PADAPTER_EXTENSION)DeviceExtension; dataBuffer = SRB_DATA_BUFFER(Srb); dataLen = SRB_DATA_TRANSFER_LENGTH(Srb); - if (cdb->CDB6INQUIRY3.EnableVitalProductData == 1) { - switch (cdb->CDB6INQUIRY3.PageCode) { - case VPD_SERIAL_NUMBER: { - PVPD_SERIAL_NUMBER_PAGE SerialPage; - SerialPage = (PVPD_SERIAL_NUMBER_PAGE)dataBuffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VPD_SERIAL_NUMBER PageLength = %d\n", SerialPage->PageLength); - if (SerialPage->PageLength > 0 && adaptExt->ser_num == NULL) { - int ln = min(64, SerialPage->PageLength); - ULONG Status = - StorPortAllocatePool(DeviceExtension, - ln + 1, - VIOSCSI_POOL_TAG, - (PVOID*)&adaptExt->ser_num); - if (NT_SUCCESS(Status)) { - StorPortMoveMemory(adaptExt->ser_num, SerialPage->SerialNumber, ln); - adaptExt->ser_num[ln] = '\0'; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); + if (cdb->CDB6INQUIRY3.EnableVitalProductData == 1) + { + switch (cdb->CDB6INQUIRY3.PageCode) + { + case VPD_SERIAL_NUMBER: + { + PVPD_SERIAL_NUMBER_PAGE SerialPage; + SerialPage = (PVPD_SERIAL_NUMBER_PAGE)dataBuffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " VPD_SERIAL_NUMBER PageLength = %d\n", + SerialPage->PageLength); + if (SerialPage->PageLength > 0 && adaptExt->ser_num == NULL) + { + int ln = min(64, SerialPage->PageLength); + ULONG Status = StorPortAllocatePool(DeviceExtension, + ln + 1, + VIOSCSI_POOL_TAG, + (PVOID *)&adaptExt->ser_num); + if (NT_SUCCESS(Status)) + { + StorPortMoveMemory(adaptExt->ser_num, SerialPage->SerialNumber, ln); + adaptExt->ser_num[ln] = '\0'; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); + } } } - } - break; - case VPD_DEVICE_IDENTIFIERS: { - PVPD_IDENTIFICATION_PAGE IdentificationPage; - PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr; - UCHAR PageLength = 0; - IdentificationPage = (PVPD_IDENTIFICATION_PAGE)dataBuffer; - PageLength = IdentificationPage->PageLength; - if (PageLength >= sizeof(VPD_IDENTIFICATION_DESCRIPTOR)) { - UCHAR IdentifierLength = 0; - IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)IdentificationPage->Descriptors; - do { - UCHAR offset = 0; - IdentifierLength = ParseIdentificationDescr(DeviceExtension, IdentificationDescr, PageLength); - offset = sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + IdentifierLength; - PageLength -= min(PageLength, offset); - IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)((ULONG_PTR)IdentificationDescr + offset); - } while (PageLength); + break; + case VPD_DEVICE_IDENTIFIERS: + { + PVPD_IDENTIFICATION_PAGE IdentificationPage; + PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr; + UCHAR PageLength = 0; + IdentificationPage = (PVPD_IDENTIFICATION_PAGE)dataBuffer; + PageLength = IdentificationPage->PageLength; + if (PageLength >= sizeof(VPD_IDENTIFICATION_DESCRIPTOR)) + { + UCHAR IdentifierLength = 0; + IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)IdentificationPage->Descriptors; + do + { + UCHAR offset = 0; + IdentifierLength = ParseIdentificationDescr(DeviceExtension, + IdentificationDescr, + PageLength); + offset = sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + IdentifierLength; + PageLength -= min(PageLength, offset); + IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)((ULONG_PTR)IdentificationDescr + + offset); + } while (PageLength); + } } - } - break; + break; } } - else if (cdb->CDB6INQUIRY3.PageCode == VPD_SUPPORTED_PAGES) { + else if (cdb->CDB6INQUIRY3.PageCode == VPD_SUPPORTED_PAGES) + { PINQUIRYDATA InquiryData = (PINQUIRYDATA)dataBuffer; - if (InquiryData && dataLen) { + if (InquiryData && dataLen) + { CopyBufferToAnsiString(adaptExt->ven_id, InquiryData->VendorId, ' ', sizeof(InquiryData->VendorId)); CopyBufferToAnsiString(adaptExt->prod_id, InquiryData->ProductId, ' ', sizeof(InquiryData->ProductId)); - CopyBufferToAnsiString(adaptExt->rev_id, InquiryData->ProductRevisionLevel, ' ',sizeof(InquiryData->ProductRevisionLevel)); + CopyBufferToAnsiString(adaptExt->rev_id, + InquiryData->ProductRevisionLevel, + ' ', + sizeof(InquiryData->ProductRevisionLevel)); } } -EXIT_FN_SRB(); + EXIT_FN_SRB(); } -VOID -VioScsiPatchInquiryData( - IN PVOID DeviceExtension, - IN OUT PSRB_TYPE Srb -) +VOID VioScsiPatchInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { - PVOID dataBuffer; - PADAPTER_EXTENSION adaptExt; + PVOID dataBuffer; + PADAPTER_EXTENSION adaptExt; PCDB cdb; ULONG dataLen; UCHAR SrbStatus = SRB_STATUS_SUCCESS; ENTER_FN_SRB(); if (!Srb) + { return; + } cdb = SRB_CDB(Srb); if (!cdb) + { return; + } SRB_GET_SCSI_STATUS(Srb, SrbStatus); if (SrbStatus == SRB_STATUS_ERROR) + { return; + } adaptExt = (PADAPTER_EXTENSION)DeviceExtension; dataBuffer = SRB_DATA_BUFFER(Srb); dataLen = SRB_DATA_TRANSFER_LENGTH(Srb); - if (cdb->CDB6INQUIRY3.EnableVitalProductData == 1) { - switch (cdb->CDB6INQUIRY3.PageCode) { - case VPD_DEVICE_IDENTIFIERS: { - PVPD_IDENTIFICATION_PAGE IdentificationPage; - PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr; - UCHAR PageLength = 0; - IdentificationPage = (PVPD_IDENTIFICATION_PAGE)dataBuffer; - PageLength = IdentificationPage->PageLength; - if (dataLen >= (sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + sizeof(VPD_IDENTIFICATION_PAGE) + 8) && - PageLength <= sizeof(VPD_IDENTIFICATION_PAGE)) { - UCHAR IdentifierLength = 0; - IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)IdentificationPage->Descriptors; - if (IdentificationDescr->IdentifierLength == 0) + if (cdb->CDB6INQUIRY3.EnableVitalProductData == 1) + { + switch (cdb->CDB6INQUIRY3.PageCode) + { + case VPD_DEVICE_IDENTIFIERS: + { + PVPD_IDENTIFICATION_PAGE IdentificationPage; + PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr; + UCHAR PageLength = 0; + IdentificationPage = (PVPD_IDENTIFICATION_PAGE)dataBuffer; + PageLength = IdentificationPage->PageLength; + if (dataLen >= (sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + sizeof(VPD_IDENTIFICATION_PAGE) + 8) && + PageLength <= sizeof(VPD_IDENTIFICATION_PAGE)) { - IdentificationDescr->CodeSet = VpdCodeSetBinary; - IdentificationDescr->IdentifierType = VpdIdentifierTypeEUI64; - IdentificationDescr->IdentifierLength = 8; - IdentificationDescr->Identifier[0] = (adaptExt->system_io_bus_number >> 12) & 0xF; - IdentificationDescr->Identifier[1] = (adaptExt->system_io_bus_number >> 8) & 0xF; - IdentificationDescr->Identifier[2] = (adaptExt->system_io_bus_number >> 4) & 0xF; - IdentificationDescr->Identifier[3] = adaptExt->system_io_bus_number & 0xF; - IdentificationDescr->Identifier[4] = (adaptExt->slot_number >> 12) & 0xF; - IdentificationDescr->Identifier[5] = (adaptExt->slot_number >> 8) & 0xF; - IdentificationDescr->Identifier[6] = (adaptExt->slot_number >> 4) & 0xF; - IdentificationDescr->Identifier[7] = adaptExt->slot_number & 0xF; - IdentificationPage->PageLength = sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + IdentificationDescr->IdentifierLength; - SRB_SET_DATA_TRANSFER_LENGTH(Srb, (sizeof(VPD_IDENTIFICATION_PAGE) + - IdentificationPage->PageLength)); + UCHAR IdentifierLength = 0; + IdentificationDescr = (PVPD_IDENTIFICATION_DESCRIPTOR)IdentificationPage->Descriptors; + if (IdentificationDescr->IdentifierLength == 0) + { + IdentificationDescr->CodeSet = VpdCodeSetBinary; + IdentificationDescr->IdentifierType = VpdIdentifierTypeEUI64; + IdentificationDescr->IdentifierLength = 8; + IdentificationDescr->Identifier[0] = (adaptExt->system_io_bus_number >> 12) & 0xF; + IdentificationDescr->Identifier[1] = (adaptExt->system_io_bus_number >> 8) & 0xF; + IdentificationDescr->Identifier[2] = (adaptExt->system_io_bus_number >> 4) & 0xF; + IdentificationDescr->Identifier[3] = adaptExt->system_io_bus_number & 0xF; + IdentificationDescr->Identifier[4] = (adaptExt->slot_number >> 12) & 0xF; + IdentificationDescr->Identifier[5] = (adaptExt->slot_number >> 8) & 0xF; + IdentificationDescr->Identifier[6] = (adaptExt->slot_number >> 4) & 0xF; + IdentificationDescr->Identifier[7] = adaptExt->slot_number & 0xF; + IdentificationPage->PageLength = sizeof(VPD_IDENTIFICATION_DESCRIPTOR) + + IdentificationDescr->IdentifierLength; + SRB_SET_DATA_TRANSFER_LENGTH(Srb, + (sizeof(VPD_IDENTIFICATION_PAGE) + + IdentificationPage->PageLength)); + } } } - } - break; + break; } } EXIT_FN_SRB(); } BOOLEAN -VioScsiQueryWmiDataBlock( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - IN ULONG GuidIndex, - IN ULONG InstanceIndex, - IN ULONG InstanceCount, - IN OUT PULONG InstanceLengthArray, - IN ULONG OutBufferSize, - OUT PUCHAR Buffer - ) +VioScsiQueryWmiDataBlock(IN PVOID Context, + IN PSCSIWMI_REQUEST_CONTEXT RequestContext, + IN ULONG GuidIndex, + IN ULONG InstanceIndex, + IN ULONG InstanceCount, + IN OUT PULONG InstanceLengthArray, + IN ULONG OutBufferSize, + OUT PUCHAR Buffer) { ULONG size = 0; UCHAR status = SRB_STATUS_SUCCESS; - PADAPTER_EXTENSION adaptExt; + PADAPTER_EXTENSION adaptExt; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)Context; UNREFERENCED_PARAMETER(InstanceIndex); @@ -2224,331 +2203,341 @@ ENTER_FN(); switch (GuidIndex) { case VIOSCSI_SETUP_GUID_INDEX: - { - size = VioScsiExtendedInfo_SIZE; - if (OutBufferSize < size) { - status = SRB_STATUS_DATA_OVERRUN; - break; - } + size = VioScsiExtendedInfo_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } - VioScsiReadExtendedData(Context, - Buffer); - *InstanceLengthArray = size; - status = SRB_STATUS_SUCCESS; - } - break; + VioScsiReadExtendedData(Context, Buffer); + *InstanceLengthArray = size; + status = SRB_STATUS_SUCCESS; + } + break; case VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX: - { - PMS_SM_AdapterInformationQuery pOutBfr = (PMS_SM_AdapterInformationQuery)Buffer; - RhelDbgPrint(TRACE_LEVEL_FATAL, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX\n"); - size = sizeof(MS_SM_AdapterInformationQuery); - if (OutBufferSize < size) { - status = SRB_STATUS_DATA_OVERRUN; - break; - } + PMS_SM_AdapterInformationQuery pOutBfr = (PMS_SM_AdapterInformationQuery)Buffer; + RhelDbgPrint(TRACE_LEVEL_FATAL, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX\n"); + size = sizeof(MS_SM_AdapterInformationQuery); + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } - RtlZeroMemory(pOutBfr, size); - pOutBfr->UniqueAdapterId = adaptExt->hba_id; - pOutBfr->HBAStatus = HBA_STATUS_OK; - pOutBfr->NumberOfPorts = 1; - pOutBfr->VendorSpecificID = VENDORID | (PRODUCTID << 16); - CopyUnicodeString(pOutBfr->Manufacturer, MANUFACTURER, sizeof(pOutBfr->Manufacturer)); - if (adaptExt->ser_num) - { - CopyAnsiToUnicodeString(pOutBfr->SerialNumber, adaptExt->ser_num, sizeof(pOutBfr->SerialNumber)); - } - else - { - CopyUnicodeString(pOutBfr->SerialNumber, SERIALNUMBER, sizeof(pOutBfr->SerialNumber)); + RtlZeroMemory(pOutBfr, size); + pOutBfr->UniqueAdapterId = adaptExt->hba_id; + pOutBfr->HBAStatus = HBA_STATUS_OK; + pOutBfr->NumberOfPorts = 1; + pOutBfr->VendorSpecificID = VENDORID | (PRODUCTID << 16); + CopyUnicodeString(pOutBfr->Manufacturer, MANUFACTURER, sizeof(pOutBfr->Manufacturer)); + if (adaptExt->ser_num) + { + CopyAnsiToUnicodeString(pOutBfr->SerialNumber, adaptExt->ser_num, sizeof(pOutBfr->SerialNumber)); + } + else + { + CopyUnicodeString(pOutBfr->SerialNumber, SERIALNUMBER, sizeof(pOutBfr->SerialNumber)); + } + CopyUnicodeString(pOutBfr->Model, MODEL, sizeof(pOutBfr->Model)); + CopyUnicodeString(pOutBfr->ModelDescription, MODELDESCRIPTION, sizeof(pOutBfr->ModelDescription)); + CopyUnicodeString(pOutBfr->HardwareVersion, HARDWAREVERSION, sizeof(pOutBfr->ModelDescription)); + CopyUnicodeString(pOutBfr->DriverVersion, DRIVERVERSION, sizeof(pOutBfr->DriverVersion)); + CopyUnicodeString(pOutBfr->OptionROMVersion, OPTIONROMVERSION, sizeof(pOutBfr->OptionROMVersion)); + CopyAnsiToUnicodeString(pOutBfr->FirmwareVersion, adaptExt->rev_id, sizeof(pOutBfr->FirmwareVersion)); + CopyUnicodeString(pOutBfr->DriverName, DRIVERNAME, sizeof(pOutBfr->DriverName)); + CopyUnicodeString(pOutBfr->HBASymbolicName, HBASYMBOLICNAME, sizeof(pOutBfr->HBASymbolicName)); + CopyUnicodeString(pOutBfr->RedundantFirmwareVersion, + REDUNDANTFIRMWAREVERSION, + sizeof(pOutBfr->RedundantFirmwareVersion)); + CopyUnicodeString(pOutBfr->RedundantOptionROMVersion, + REDUNDANTOPTIONROMVERSION, + sizeof(pOutBfr->RedundantOptionROMVersion)); + CopyUnicodeString(pOutBfr->MfgDomain, MFRDOMAIN, sizeof(pOutBfr->MfgDomain)); + + *InstanceLengthArray = size; + status = SRB_STATUS_SUCCESS; } - CopyUnicodeString(pOutBfr->Model, MODEL, sizeof(pOutBfr->Model)); - CopyUnicodeString(pOutBfr->ModelDescription, MODELDESCRIPTION, sizeof(pOutBfr->ModelDescription)); - CopyUnicodeString(pOutBfr->HardwareVersion, HARDWAREVERSION, sizeof(pOutBfr->ModelDescription)); - CopyUnicodeString(pOutBfr->DriverVersion, DRIVERVERSION, sizeof(pOutBfr->DriverVersion)); - CopyUnicodeString(pOutBfr->OptionROMVersion, OPTIONROMVERSION, sizeof(pOutBfr->OptionROMVersion)); - CopyAnsiToUnicodeString(pOutBfr->FirmwareVersion, adaptExt->rev_id, sizeof(pOutBfr->FirmwareVersion)); - CopyUnicodeString(pOutBfr->DriverName, DRIVERNAME, sizeof(pOutBfr->DriverName)); - CopyUnicodeString(pOutBfr->HBASymbolicName, HBASYMBOLICNAME, sizeof(pOutBfr->HBASymbolicName)); - CopyUnicodeString(pOutBfr->RedundantFirmwareVersion, REDUNDANTFIRMWAREVERSION, sizeof(pOutBfr->RedundantFirmwareVersion)); - CopyUnicodeString(pOutBfr->RedundantOptionROMVersion, REDUNDANTOPTIONROMVERSION, sizeof(pOutBfr->RedundantOptionROMVersion)); - CopyUnicodeString(pOutBfr->MfgDomain, MFRDOMAIN, sizeof(pOutBfr->MfgDomain)); - - *InstanceLengthArray = size; - status = SRB_STATUS_SUCCESS; - } - break; + break; case VIOSCSI_MS_PORT_INFORM_GUID_INDEX: - { - size = sizeof(ULONG); - if (OutBufferSize < size) { - status = SRB_STATUS_DATA_OVERRUN; - RhelDbgPrint(TRACE_LEVEL_WARNING, " --> VIOSCSI_MS_PORT_INFORM_GUID_INDEX out buffer too small %d %d\n", OutBufferSize, size); - break; + size = sizeof(ULONG); + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + RhelDbgPrint(TRACE_LEVEL_WARNING, + " --> VIOSCSI_MS_PORT_INFORM_GUID_INDEX out buffer too small %d %d\n", + OutBufferSize, + size); + break; + } + *InstanceLengthArray = size; + status = SRB_STATUS_SUCCESS; } - *InstanceLengthArray = size; - status = SRB_STATUS_SUCCESS; - } - break; + break; default: - { - status = SRB_STATUS_ERROR; - } + { + status = SRB_STATUS_ERROR; + } } - ScsiPortWmiPostProcess(RequestContext, - status, - size); + ScsiPortWmiPostProcess(RequestContext, status, size); -EXIT_FN(); + EXIT_FN(); return TRUE; } UCHAR -VioScsiExecuteWmiMethod( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - IN ULONG GuidIndex, - IN ULONG InstanceIndex, - IN ULONG MethodId, - IN ULONG InBufferSize, - IN ULONG OutBufferSize, - IN OUT PUCHAR Buffer - ) +VioScsiExecuteWmiMethod(IN PVOID Context, + IN PSCSIWMI_REQUEST_CONTEXT RequestContext, + IN ULONG GuidIndex, + IN ULONG InstanceIndex, + IN ULONG MethodId, + IN ULONG InBufferSize, + IN ULONG OutBufferSize, + IN OUT PUCHAR Buffer) { - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)Context; - ULONG size = 0; - UCHAR status = SRB_STATUS_SUCCESS; + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)Context; + ULONG size = 0; + UCHAR status = SRB_STATUS_SUCCESS; UNREFERENCED_PARAMETER(InstanceIndex); ENTER_FN(); switch (GuidIndex) { case VIOSCSI_SETUP_GUID_INDEX: - { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_SETUP_GUID_INDEX ERROR\n"); - } - break; + { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_SETUP_GUID_INDEX ERROR\n"); + } + break; case VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX: - { - PMS_SM_AdapterInformationQuery pOutBfr = (PMS_SM_AdapterInformationQuery)Buffer; - pOutBfr; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX ERROR\n"); - } - break; + { + PMS_SM_AdapterInformationQuery pOutBfr = (PMS_SM_AdapterInformationQuery)Buffer; + pOutBfr; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX ERROR\n"); + } + break; case VIOSCSI_MS_PORT_INFORM_GUID_INDEX: - { - switch (MethodId) { - case SM_GetPortType: - { - PSM_GetPortType_IN pInBfr = (PSM_GetPortType_IN)Buffer; - PSM_GetPortType_OUT pOutBfr = (PSM_GetPortType_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortType\n"); - size = SM_GetPortType_OUT_SIZE; - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; - break; - } - if (InBufferSize < SM_GetPortType_IN_SIZE) - { - status = SRB_STATUS_ERROR; - break; - } - pOutBfr->HBAStatus = HBA_STATUS_OK; - pOutBfr->PortType = HBA_PORTTYPE_SASDEVICE; - } - break; - case SM_GetAdapterPortAttributes: - { - PSM_GetAdapterPortAttributes_IN pInBfr = (PSM_GetAdapterPortAttributes_IN)Buffer; - PSM_GetAdapterPortAttributes_OUT pOutBfr = (PSM_GetAdapterPortAttributes_OUT)Buffer; - PMS_SMHBA_FC_Port pPortSpecificAttributes = NULL; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetAdapterPortAttributes\n"); - size = FIELD_OFFSET(SM_GetAdapterPortAttributes_OUT, PortAttributes) + FIELD_OFFSET(MS_SMHBA_PORTATTRIBUTES, PortSpecificAttributes) + sizeof(MS_SMHBA_FC_Port); - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; - break; - } - if (InBufferSize < SM_GetAdapterPortAttributes_IN_SIZE) - { - status = SRB_STATUS_ERROR; - break; - } - pOutBfr->HBAStatus = HBA_STATUS_OK; - CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, MODEL, sizeof(pOutBfr->PortAttributes.OSDeviceName)); - pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; - pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; - pOutBfr->PortAttributes.PortSpecificAttributesSize = sizeof(MS_SMHBA_FC_Port); - pPortSpecificAttributes = (PMS_SMHBA_FC_Port) pOutBfr->PortAttributes.PortSpecificAttributes; - RtlZeroMemory(pPortSpecificAttributes, sizeof(MS_SMHBA_FC_Port)); - RtlMoveMemory(pPortSpecificAttributes->NodeWWN, &adaptExt->wwn, sizeof(pPortSpecificAttributes->NodeWWN)); - RtlMoveMemory(pPortSpecificAttributes->PortWWN, &adaptExt->port_wwn, sizeof(pPortSpecificAttributes->PortWWN)); - pPortSpecificAttributes->FcId = 0; - pPortSpecificAttributes->PortSupportedClassofService = 0; -//FIXME report PortSupportedFc4Types PortActiveFc4Types FabricName; - pPortSpecificAttributes->NumberofDiscoveredPorts = 1; - pPortSpecificAttributes->NumberofPhys = 1; - CopyUnicodeString(pPortSpecificAttributes->PortSymbolicName, PORTSYMBOLICNAME, sizeof(pPortSpecificAttributes->PortSymbolicName)); - } - break; - case SM_GetDiscoveredPortAttributes: + switch (MethodId) { - PSM_GetDiscoveredPortAttributes_IN pInBfr = (PSM_GetDiscoveredPortAttributes_IN)Buffer; - PSM_GetDiscoveredPortAttributes_OUT pOutBfr = (PSM_GetDiscoveredPortAttributes_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetDiscoveredPortAttributes\n"); - size = SM_GetDiscoveredPortAttributes_OUT_SIZE; - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; - break; - } - if (InBufferSize < SM_GetDiscoveredPortAttributes_IN_SIZE) - { - status = SRB_STATUS_ERROR; - break; - } - pOutBfr->HBAStatus = HBA_STATUS_OK; - CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, MODEL, sizeof(pOutBfr->PortAttributes.OSDeviceName)); - pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; - pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; - } - break; - case SM_GetPortAttributesByWWN: - { - PSM_GetPortAttributesByWWN_IN pInBfr = (PSM_GetPortAttributesByWWN_IN)Buffer; - PSM_GetPortAttributesByWWN_OUT pOutBfr = (PSM_GetPortAttributesByWWN_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortAttributesByWWN\n"); - size = SM_GetPortAttributesByWWN_OUT_SIZE; - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; + case SM_GetPortType: + { + PSM_GetPortType_IN pInBfr = (PSM_GetPortType_IN)Buffer; + PSM_GetPortType_OUT pOutBfr = (PSM_GetPortType_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortType\n"); + size = SM_GetPortType_OUT_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetPortType_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + pOutBfr->HBAStatus = HBA_STATUS_OK; + pOutBfr->PortType = HBA_PORTTYPE_SASDEVICE; + } break; - } - if (InBufferSize < SM_GetPortAttributesByWWN_IN_SIZE) - { - status = SRB_STATUS_ERROR; + case SM_GetAdapterPortAttributes: + { + PSM_GetAdapterPortAttributes_IN pInBfr = (PSM_GetAdapterPortAttributes_IN)Buffer; + PSM_GetAdapterPortAttributes_OUT pOutBfr = (PSM_GetAdapterPortAttributes_OUT)Buffer; + PMS_SMHBA_FC_Port pPortSpecificAttributes = NULL; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetAdapterPortAttributes\n"); + size = FIELD_OFFSET(SM_GetAdapterPortAttributes_OUT, PortAttributes) + + FIELD_OFFSET(MS_SMHBA_PORTATTRIBUTES, PortSpecificAttributes) + + sizeof(MS_SMHBA_FC_Port); + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetAdapterPortAttributes_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + pOutBfr->HBAStatus = HBA_STATUS_OK; + CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, + MODEL, + sizeof(pOutBfr->PortAttributes.OSDeviceName)); + pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; + pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; + pOutBfr->PortAttributes.PortSpecificAttributesSize = sizeof(MS_SMHBA_FC_Port); + pPortSpecificAttributes = (PMS_SMHBA_FC_Port)pOutBfr->PortAttributes.PortSpecificAttributes; + RtlZeroMemory(pPortSpecificAttributes, sizeof(MS_SMHBA_FC_Port)); + RtlMoveMemory(pPortSpecificAttributes->NodeWWN, + &adaptExt->wwn, + sizeof(pPortSpecificAttributes->NodeWWN)); + RtlMoveMemory(pPortSpecificAttributes->PortWWN, + &adaptExt->port_wwn, + sizeof(pPortSpecificAttributes->PortWWN)); + pPortSpecificAttributes->FcId = 0; + pPortSpecificAttributes->PortSupportedClassofService = 0; + // FIXME report PortSupportedFc4Types PortActiveFc4Types FabricName; + pPortSpecificAttributes->NumberofDiscoveredPorts = 1; + pPortSpecificAttributes->NumberofPhys = 1; + CopyUnicodeString(pPortSpecificAttributes->PortSymbolicName, + PORTSYMBOLICNAME, + sizeof(pPortSpecificAttributes->PortSymbolicName)); + } break; - } - pOutBfr->HBAStatus = HBA_STATUS_OK; - CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, MODEL, sizeof(pOutBfr->PortAttributes.OSDeviceName)); - pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; - pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortAttributesByWWN Not Implemented Yet\n"); - } - break; - case SM_GetProtocolStatistics: - { - PSM_GetProtocolStatistics_IN pInBfr = (PSM_GetProtocolStatistics_IN)Buffer; - PSM_GetProtocolStatistics_OUT pOutBfr = (PSM_GetProtocolStatistics_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetProtocolStatistics\n"); - size = SM_GetProtocolStatistics_OUT_SIZE; - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; + case SM_GetDiscoveredPortAttributes: + { + PSM_GetDiscoveredPortAttributes_IN pInBfr = (PSM_GetDiscoveredPortAttributes_IN)Buffer; + PSM_GetDiscoveredPortAttributes_OUT pOutBfr = (PSM_GetDiscoveredPortAttributes_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetDiscoveredPortAttributes\n"); + size = SM_GetDiscoveredPortAttributes_OUT_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetDiscoveredPortAttributes_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + pOutBfr->HBAStatus = HBA_STATUS_OK; + CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, + MODEL, + sizeof(pOutBfr->PortAttributes.OSDeviceName)); + pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; + pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; + } break; - } - if (InBufferSize < SM_GetProtocolStatistics_IN_SIZE) - { - status = SRB_STATUS_ERROR; + case SM_GetPortAttributesByWWN: + { + PSM_GetPortAttributesByWWN_IN pInBfr = (PSM_GetPortAttributesByWWN_IN)Buffer; + PSM_GetPortAttributesByWWN_OUT pOutBfr = (PSM_GetPortAttributesByWWN_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortAttributesByWWN\n"); + size = SM_GetPortAttributesByWWN_OUT_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetPortAttributesByWWN_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + pOutBfr->HBAStatus = HBA_STATUS_OK; + CopyUnicodeString(pOutBfr->PortAttributes.OSDeviceName, + MODEL, + sizeof(pOutBfr->PortAttributes.OSDeviceName)); + pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; + pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " --> SM_GetPortAttributesByWWN Not Implemented Yet\n"); + } break; - } - } - break; - case SM_GetPhyStatistics: - { - PSM_GetPhyStatistics_IN pInBfr = (PSM_GetPhyStatistics_IN)Buffer; - PSM_GetPhyStatistics_OUT pOutBfr = (PSM_GetPhyStatistics_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPhyStatistics\n"); - size = FIELD_OFFSET(SM_GetPhyStatistics_OUT, PhyCounter) + sizeof(LONGLONG); - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; + case SM_GetProtocolStatistics: + { + PSM_GetProtocolStatistics_IN pInBfr = (PSM_GetProtocolStatistics_IN)Buffer; + PSM_GetProtocolStatistics_OUT pOutBfr = (PSM_GetProtocolStatistics_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetProtocolStatistics\n"); + size = SM_GetProtocolStatistics_OUT_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetProtocolStatistics_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + } break; - } - if (InBufferSize < SM_GetPhyStatistics_IN_SIZE) - { - status = SRB_STATUS_ERROR; + case SM_GetPhyStatistics: + { + PSM_GetPhyStatistics_IN pInBfr = (PSM_GetPhyStatistics_IN)Buffer; + PSM_GetPhyStatistics_OUT pOutBfr = (PSM_GetPhyStatistics_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPhyStatistics\n"); + size = FIELD_OFFSET(SM_GetPhyStatistics_OUT, PhyCounter) + sizeof(LONGLONG); + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetPhyStatistics_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + } break; - } - } - break; - case SM_GetFCPhyAttributes: - { - PSM_GetFCPhyAttributes_IN pInBfr = (PSM_GetFCPhyAttributes_IN)Buffer; - PSM_GetFCPhyAttributes_OUT pOutBfr = (PSM_GetFCPhyAttributes_OUT)Buffer; - - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetFCPhyAttributes\n"); - size = SM_GetFCPhyAttributes_OUT_SIZE; - - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; + case SM_GetFCPhyAttributes: + { + PSM_GetFCPhyAttributes_IN pInBfr = (PSM_GetFCPhyAttributes_IN)Buffer; + PSM_GetFCPhyAttributes_OUT pOutBfr = (PSM_GetFCPhyAttributes_OUT)Buffer; + + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetFCPhyAttributes\n"); + size = SM_GetFCPhyAttributes_OUT_SIZE; + + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + + if (InBufferSize < SM_GetFCPhyAttributes_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + } break; - } - - if (InBufferSize < SM_GetFCPhyAttributes_IN_SIZE) - { - status = SRB_STATUS_ERROR; + case SM_GetSASPhyAttributes: + { + PSM_GetSASPhyAttributes_IN pInBfr = (PSM_GetSASPhyAttributes_IN)Buffer; + PSM_GetSASPhyAttributes_OUT pOutBfr = (PSM_GetSASPhyAttributes_OUT)Buffer; + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetSASPhyAttributes\n"); + size = SM_GetSASPhyAttributes_OUT_SIZE; + if (OutBufferSize < size) + { + status = SRB_STATUS_DATA_OVERRUN; + break; + } + if (InBufferSize < SM_GetSASPhyAttributes_IN_SIZE) + { + status = SRB_STATUS_ERROR; + break; + } + } break; - } - } - break; - case SM_GetSASPhyAttributes: - { - PSM_GetSASPhyAttributes_IN pInBfr = (PSM_GetSASPhyAttributes_IN)Buffer; - PSM_GetSASPhyAttributes_OUT pOutBfr = (PSM_GetSASPhyAttributes_OUT)Buffer; - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetSASPhyAttributes\n"); - size = SM_GetSASPhyAttributes_OUT_SIZE; - if (OutBufferSize < size) - { - status = SRB_STATUS_DATA_OVERRUN; + case SM_RefreshInformation: + { + } break; - } - if (InBufferSize < SM_GetSASPhyAttributes_IN_SIZE) - { - status = SRB_STATUS_ERROR; + default: + status = SRB_STATUS_INVALID_REQUEST; + RhelDbgPrint(TRACE_LEVEL_ERROR, " --> ERROR Unknown MethodId = %lu\n", MethodId); break; - } - } - break; - case SM_RefreshInformation: - { } - break; - default: - status = SRB_STATUS_INVALID_REQUEST; - RhelDbgPrint(TRACE_LEVEL_ERROR, " --> ERROR Unknown MethodId = %lu\n", MethodId); - break; } - } - break; + break; default: status = SRB_STATUS_INVALID_REQUEST; RhelDbgPrint(TRACE_LEVEL_ERROR, " --> VioScsiExecuteWmiMethod Unsupported GuidIndex = %lu\n", GuidIndex); - break; + break; } - ScsiPortWmiPostProcess(RequestContext, - status, - size); + ScsiPortWmiPostProcess(RequestContext, status, size); EXIT_FN(); return SRB_STATUS_SUCCESS; - } UCHAR -VioScsiQueryWmiRegInfo( - IN PVOID Context, - IN PSCSIWMI_REQUEST_CONTEXT RequestContext, - OUT PWCHAR *MofResourceName - ) +VioScsiQueryWmiRegInfo(IN PVOID Context, IN PSCSIWMI_REQUEST_CONTEXT RequestContext, OUT PWCHAR *MofResourceName) { -ENTER_FN(); + ENTER_FN(); UNREFERENCED_PARAMETER(Context); UNREFERENCED_PARAMETER(RequestContext); @@ -2556,17 +2545,13 @@ ENTER_FN(); return SRB_STATUS_SUCCESS; } -VOID -VioScsiReadExtendedData( -IN PVOID Context, -OUT PUCHAR Buffer -) +VOID VioScsiReadExtendedData(IN PVOID Context, OUT PUCHAR Buffer) { UCHAR numberOfBytes = sizeof(VioScsiExtendedInfo) - 1; - PADAPTER_EXTENSION adaptExt; - PVioScsiExtendedInfo extInfo; + PADAPTER_EXTENSION adaptExt; + PVioScsiExtendedInfo extInfo; -ENTER_FN(); + ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)Context; extInfo = (PVioScsiExtendedInfo)Buffer; @@ -2584,5 +2569,5 @@ ENTER_FN(); extInfo->CompletionDuringStartIo = CHECKFLAG(adaptExt->perfFlags, STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO); extInfo->PhysicalBreaks = adaptExt->max_physical_breaks; extInfo->ResponseTime = adaptExt->resp_time; -EXIT_FN(); + EXIT_FN(); } diff --git a/vioscsi/vioscsi.h b/vioscsi/vioscsi.h old mode 100755 new mode 100644 index ea995fd5e..50ce94d13 --- a/vioscsi/vioscsi.h +++ b/vioscsi/vioscsi.h @@ -46,128 +46,131 @@ typedef struct VirtIOBufferDescriptor VIO_SG, *PVIO_SG; #define VIRTIO_SCSI_SENSE_SIZE 96 #ifndef NTDDI_WINTHRESHOLD -#define NTDDI_WINTHRESHOLD 0x0A000000 /* ABRACADABRA_THRESHOLD */ +#define NTDDI_WINTHRESHOLD 0x0A000000 /* ABRACADABRA_THRESHOLD */ #endif -#define PHYS_SEGMENTS 32 -#define MAX_PHYS_SEGMENTS 512 -#define VIOSCSI_POOL_TAG 'SoiV' -#define VIRTIO_MAX_SG (1+1+MAX_PHYS_SEGMENTS+1) //cmd + resp + (MAX_PHYS_SEGMENTS + extra_page) +#define PHYS_SEGMENTS 32 +#define MAX_PHYS_SEGMENTS 512 +#define VIOSCSI_POOL_TAG 'SoiV' +#define VIRTIO_MAX_SG (1 + 1 + MAX_PHYS_SEGMENTS + 1) // cmd + resp + (MAX_PHYS_SEGMENTS + extra_page) -#define SECTOR_SIZE 512 -#define IO_PORT_LENGTH 0x40 -#define MAX_CPU 256 - -#define REGISTRY_MAX_PH_BREAKS "PhysicalBreaks" -#define REGISTRY_ACTION_ON_RESET "VioscsiActionOnReset" -#define REGISTRY_RESP_TIME_LIMIT "TraceResponseTime" +#define SECTOR_SIZE 512 +#define IO_PORT_LENGTH 0x40 +#define MAX_CPU 256 +#define REGISTRY_MAX_PH_BREAKS "PhysicalBreaks" +#define REGISTRY_ACTION_ON_RESET "VioscsiActionOnReset" +#define REGISTRY_RESP_TIME_LIMIT "TraceResponseTime" /* Feature Bits */ -#define VIRTIO_SCSI_F_INOUT 0 -#define VIRTIO_SCSI_F_HOTPLUG 1 -#define VIRTIO_SCSI_F_CHANGE 2 +#define VIRTIO_SCSI_F_INOUT 0 +#define VIRTIO_SCSI_F_HOTPLUG 1 +#define VIRTIO_SCSI_F_CHANGE 2 /* Response codes */ -#define VIRTIO_SCSI_S_OK 0 -#define VIRTIO_SCSI_S_UNDERRUN 1 -#define VIRTIO_SCSI_S_ABORTED 2 -#define VIRTIO_SCSI_S_BAD_TARGET 3 -#define VIRTIO_SCSI_S_RESET 4 -#define VIRTIO_SCSI_S_BUSY 5 -#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6 -#define VIRTIO_SCSI_S_TARGET_FAILURE 7 -#define VIRTIO_SCSI_S_NEXUS_FAILURE 8 -#define VIRTIO_SCSI_S_FAILURE 9 -#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10 -#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11 -#define VIRTIO_SCSI_S_INCORRECT_LUN 12 +#define VIRTIO_SCSI_S_OK 0 +#define VIRTIO_SCSI_S_UNDERRUN 1 +#define VIRTIO_SCSI_S_ABORTED 2 +#define VIRTIO_SCSI_S_BAD_TARGET 3 +#define VIRTIO_SCSI_S_RESET 4 +#define VIRTIO_SCSI_S_BUSY 5 +#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6 +#define VIRTIO_SCSI_S_TARGET_FAILURE 7 +#define VIRTIO_SCSI_S_NEXUS_FAILURE 8 +#define VIRTIO_SCSI_S_FAILURE 9 +#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10 +#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11 +#define VIRTIO_SCSI_S_INCORRECT_LUN 12 /* Controlq type codes. */ -#define VIRTIO_SCSI_T_TMF 0 -#define VIRTIO_SCSI_T_AN_QUERY 1 -#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2 +#define VIRTIO_SCSI_T_TMF 0 +#define VIRTIO_SCSI_T_AN_QUERY 1 +#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2 /* Valid TMF subtypes. */ -#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0 -#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1 -#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2 -#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3 -#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4 -#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5 -#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6 -#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7 +#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0 +#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1 +#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2 +#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3 +#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4 +#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5 +#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6 +#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7 /* Events. */ -#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000 -#define VIRTIO_SCSI_T_NO_EVENT 0 -#define VIRTIO_SCSI_T_TRANSPORT_RESET 1 -#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2 -#define VIRTIO_SCSI_T_PARAM_CHANGE 3 +#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000 +#define VIRTIO_SCSI_T_NO_EVENT 0 +#define VIRTIO_SCSI_T_TRANSPORT_RESET 1 +#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2 +#define VIRTIO_SCSI_T_PARAM_CHANGE 3 /* Reasons of transport reset event */ -#define VIRTIO_SCSI_EVT_RESET_HARD 0 -#define VIRTIO_SCSI_EVT_RESET_RESCAN 1 -#define VIRTIO_SCSI_EVT_RESET_REMOVED 2 +#define VIRTIO_SCSI_EVT_RESET_HARD 0 +#define VIRTIO_SCSI_EVT_RESET_RESCAN 1 +#define VIRTIO_SCSI_EVT_RESET_REMOVED 2 -#define VIRTIO_SCSI_S_SIMPLE 0 -#define VIRTIO_SCSI_S_ORDERED 1 -#define VIRTIO_SCSI_S_HEAD 2 -#define VIRTIO_SCSI_S_ACA 3 +#define VIRTIO_SCSI_S_SIMPLE 0 +#define VIRTIO_SCSI_S_ORDERED 1 +#define VIRTIO_SCSI_S_HEAD 2 +#define VIRTIO_SCSI_S_ACA 3 -#define VIRTIO_SCSI_CONTROL_QUEUE 0 -#define VIRTIO_SCSI_EVENTS_QUEUE 1 -#define VIRTIO_SCSI_REQUEST_QUEUE_0 2 -#define VIRTIO_SCSI_QUEUE_LAST VIRTIO_SCSI_REQUEST_QUEUE_0 + MAX_CPU +#define VIRTIO_SCSI_CONTROL_QUEUE 0 +#define VIRTIO_SCSI_EVENTS_QUEUE 1 +#define VIRTIO_SCSI_REQUEST_QUEUE_0 2 +#define VIRTIO_SCSI_QUEUE_LAST VIRTIO_SCSI_REQUEST_QUEUE_0 + MAX_CPU /* MSI messages and virtqueue indices are offset by 1, MSI 0 is not used */ -#define QUEUE_TO_MESSAGE(QueueId) ((QueueId) + 1) -#define MESSAGE_TO_QUEUE(MessageId) ((MessageId) - 1) +#define QUEUE_TO_MESSAGE(QueueId) ((QueueId) + 1) +#define MESSAGE_TO_QUEUE(MessageId) ((MessageId)-1) /* SCSI command request, followed by data-out */ #pragma pack(1) -typedef struct { - u8 lun[8]; /* Logical Unit Number */ - u64 tag; /* Command identifier */ - u8 task_attr; /* Task attribute */ +typedef struct +{ + u8 lun[8]; /* Logical Unit Number */ + u64 tag; /* Command identifier */ + u8 task_attr; /* Task attribute */ u8 prio; u8 crn; u8 cdb[VIRTIO_SCSI_CDB_SIZE]; -} VirtIOSCSICmdReq, * PVirtIOSCSICmdReq; +} VirtIOSCSICmdReq, *PVirtIOSCSICmdReq; #pragma pack() - /* Response, followed by sense data and data-in */ #pragma pack(1) -typedef struct { +typedef struct +{ u32 sense_len; /* Sense data length */ u32 resid; /* Residual bytes in data buffer */ u16 status_qualifier; /* Status qualifier */ u8 status; /* Command completion status */ u8 response; /* Response values */ u8 sense[VIRTIO_SCSI_SENSE_SIZE]; -} VirtIOSCSICmdResp, * PVirtIOSCSICmdResp; +} VirtIOSCSICmdResp, *PVirtIOSCSICmdResp; #pragma pack() /* Task Management Request */ #pragma pack(1) -typedef struct { +typedef struct +{ u32 type; u32 subtype; u8 lun[8]; u64 tag; -} VirtIOSCSICtrlTMFReq, * PVirtIOSCSICtrlTMFReq; +} VirtIOSCSICtrlTMFReq, *PVirtIOSCSICtrlTMFReq; #pragma pack() #pragma pack(1) -typedef struct { +typedef struct +{ u8 response; -} VirtIOSCSICtrlTMFResp, * PVirtIOSCSICtrlTMFResp; +} VirtIOSCSICtrlTMFResp, *PVirtIOSCSICtrlTMFResp; #pragma pack() /* Asynchronous notification query/subscription */ #pragma pack(1) -typedef struct { +typedef struct +{ u32 type; u8 lun[8]; u32 event_requested; @@ -175,22 +178,25 @@ typedef struct { #pragma pack() #pragma pack(1) -typedef struct { +typedef struct +{ u32 event_actual; u8 response; -} VirtIOSCSICtrlANResp, * PVirtIOSCSICtrlANResp; +} VirtIOSCSICtrlANResp, *PVirtIOSCSICtrlANResp; #pragma pack() #pragma pack(1) -typedef struct { +typedef struct +{ u32 event; u8 lun[8]; u32 reason; -} VirtIOSCSIEvent, * PVirtIOSCSIEvent; +} VirtIOSCSIEvent, *PVirtIOSCSIEvent; #pragma pack() #pragma pack(1) -typedef struct { +typedef struct +{ u32 num_queues; u32 seg_max; u32 max_sectors; @@ -201,183 +207,196 @@ typedef struct { u16 max_channel; u16 max_target; u32 max_lun; -} VirtIOSCSIConfig, * PVirtIOSCSIConfig; +} VirtIOSCSIConfig, *PVirtIOSCSIConfig; #pragma pack() #pragma pack(1) -typedef struct { +typedef struct +{ PVOID srb; PVOID comp; union { - VirtIOSCSICmdReq cmd; - VirtIOSCSICtrlTMFReq tmf; - VirtIOSCSICtrlANReq an; + VirtIOSCSICmdReq cmd; + VirtIOSCSICtrlTMFReq tmf; + VirtIOSCSICtrlANReq an; } req; union { - VirtIOSCSICmdResp cmd; + VirtIOSCSICmdResp cmd; VirtIOSCSICtrlTMFResp tmf; - VirtIOSCSICtrlANResp an; - VirtIOSCSIEvent event; + VirtIOSCSICtrlANResp an; + VirtIOSCSIEvent event; } resp; -} VirtIOSCSICmd, * PVirtIOSCSICmd; +} VirtIOSCSICmd, *PVirtIOSCSICmd; #pragma pack() #pragma pack(1) -typedef struct { - PVOID adapter; +typedef struct +{ + PVOID adapter; VirtIOSCSIEvent event; - VIO_SG sg; -} VirtIOSCSIEventNode, * PVirtIOSCSIEventNode; + VIO_SG sg; +} VirtIOSCSIEventNode, *PVirtIOSCSIEventNode; #pragma pack() typedef struct _VRING_DESC_ALIAS { - union - { + union { ULONGLONG data[2]; UCHAR chars[SIZE_OF_SINGLE_INDIRECT_DESC]; - }u; -}VRING_DESC_ALIAS, *PVRING_DESC_ALIAS; + } u; +} VRING_DESC_ALIAS, *PVRING_DESC_ALIAS; #pragma pack(1) -typedef struct _SRB_EXTENSION { - LIST_ENTRY list_entry; - PSCSI_REQUEST_BLOCK Srb; - ULONG out; - ULONG in; - ULONG Xfer; - VirtIOSCSICmd cmd; +typedef struct _SRB_EXTENSION +{ + LIST_ENTRY list_entry; + PSCSI_REQUEST_BLOCK Srb; + ULONG out; + ULONG in; + ULONG Xfer; + VirtIOSCSICmd cmd; PVIO_SG POINTER_ALIGN psgl; PVRING_DESC_ALIAS POINTER_ALIGN pdesc; - VIO_SG vio_sg[VIRTIO_MAX_SG]; - VRING_DESC_ALIAS desc_alias[VIRTIO_MAX_SG]; - ULONGLONG time; -}SRB_EXTENSION, * PSRB_EXTENSION; + VIO_SG vio_sg[VIRTIO_MAX_SG]; + VRING_DESC_ALIAS desc_alias[VIRTIO_MAX_SG]; + ULONGLONG time; +} SRB_EXTENSION, *PSRB_EXTENSION; #pragma pack() #pragma pack(1) -typedef struct { - SCSI_REQUEST_BLOCK Srb; - PSRB_EXTENSION SrbExtension; -}TMF_COMMAND, * PTMF_COMMAND; +typedef struct +{ + SCSI_REQUEST_BLOCK Srb; + PSRB_EXTENSION SrbExtension; +} TMF_COMMAND, *PTMF_COMMAND; #pragma pack() -typedef struct _REQUEST_LIST { - LIST_ENTRY srb_list; - ULONG srb_cnt; +typedef struct _REQUEST_LIST +{ + LIST_ENTRY srb_list; + ULONG srb_cnt; } REQUEST_LIST, *PREQUEST_LIST; -typedef struct virtio_bar { - PHYSICAL_ADDRESS BasePA; - ULONG uLength; - PVOID pBase; - BOOLEAN bPortSpace; +typedef struct virtio_bar +{ + PHYSICAL_ADDRESS BasePA; + ULONG uLength; + PVOID pBase; + BOOLEAN bPortSpace; } VIRTIO_BAR, *PVIRTIO_BAR; -typedef enum ACTION_ON_RESET { +typedef enum ACTION_ON_RESET +{ VioscsiResetCompleteRequests, VioscsiResetDoNothing, VioscsiResetBugCheck = 0xDEADDEAD, } ACTION_ON_RESET; -typedef struct _ADAPTER_EXTENSION { - VirtIODevice vdev; +typedef struct _ADAPTER_EXTENSION +{ + VirtIODevice vdev; - PVOID pageAllocationVa; - ULONG pageAllocationSize; - ULONG pageOffset; + PVOID pageAllocationVa; + ULONG pageAllocationSize; + ULONG pageOffset; - PVOID poolAllocationVa; - ULONG poolAllocationSize; - ULONG poolOffset; + PVOID poolAllocationVa; + ULONG poolAllocationSize; + ULONG poolOffset; - struct virtqueue * vq[VIRTIO_SCSI_QUEUE_LAST]; - ULONG_PTR device_base; - VirtIOSCSIConfig scsi_config; + struct virtqueue *vq[VIRTIO_SCSI_QUEUE_LAST]; + ULONG_PTR device_base; + VirtIOSCSIConfig scsi_config; union { PCI_COMMON_HEADER pci_config; - UCHAR pci_config_buf[sizeof(PCI_COMMON_CONFIG)]; + UCHAR pci_config_buf[sizeof(PCI_COMMON_CONFIG)]; }; - VIRTIO_BAR pci_bars[PCI_TYPE0_ADDRESSES]; - ULONG system_io_bus_number; - ULONG slot_number; - - ULONG queue_depth; - BOOLEAN dump_mode; - - ULONGLONG features; - - ULONG msix_vectors; - BOOLEAN msix_enabled; - BOOLEAN msix_one_vector; - BOOLEAN indirect; - - TMF_COMMAND tmf_cmd; - BOOLEAN tmf_infly; - - PVirtIOSCSIEventNode events; - - ULONG num_queues; - REQUEST_LIST processing_srbs[MAX_CPU]; - ULONG perfFlags; - PGROUP_AFFINITY pmsg_affinity; - ULONG num_affinity; - BOOLEAN dpc_ok; - PSTOR_DPC dpc; - ULONG max_physical_breaks; - SCSI_WMILIB_CONTEXT WmiLibContext; - ULONGLONG hba_id; - PUCHAR ser_num; - ULONGLONG wwn; - ULONGLONG port_wwn; - ULONG port_idx; - UCHAR ven_id[8 + 1]; - UCHAR prod_id[16 + 1]; - UCHAR rev_id[4 + 1]; - BOOLEAN reset_in_progress; - ACTION_ON_RESET action_on_reset; - ULONGLONG fw_ver; - ULONG resp_time; - BOOLEAN bRemoved; -} ADAPTER_EXTENSION, * PADAPTER_EXTENSION; + VIRTIO_BAR pci_bars[PCI_TYPE0_ADDRESSES]; + ULONG system_io_bus_number; + ULONG slot_number; + + ULONG queue_depth; + BOOLEAN dump_mode; + + ULONGLONG features; + + ULONG msix_vectors; + BOOLEAN msix_enabled; + BOOLEAN msix_one_vector; + BOOLEAN indirect; + + TMF_COMMAND tmf_cmd; + BOOLEAN tmf_infly; + + PVirtIOSCSIEventNode events; + + ULONG num_queues; + REQUEST_LIST processing_srbs[MAX_CPU]; + ULONG perfFlags; + PGROUP_AFFINITY pmsg_affinity; + ULONG num_affinity; + BOOLEAN dpc_ok; + PSTOR_DPC dpc; + ULONG max_physical_breaks; + SCSI_WMILIB_CONTEXT WmiLibContext; + ULONGLONG hba_id; + PUCHAR ser_num; + ULONGLONG wwn; + ULONGLONG port_wwn; + ULONG port_idx; + UCHAR ven_id[8 + 1]; + UCHAR prod_id[16 + 1]; + UCHAR rev_id[4 + 1]; + BOOLEAN reset_in_progress; + ACTION_ON_RESET action_on_reset; + ULONGLONG fw_ver; + ULONG resp_time; + BOOLEAN bRemoved; +} ADAPTER_EXTENSION, *PADAPTER_EXTENSION; #ifndef PCIX_TABLE_POINTER -typedef struct { - union { - struct { - ULONG BaseIndexRegister :3; - ULONG Reserved :29; +typedef struct +{ + union { + struct + { + ULONG BaseIndexRegister : 3; + ULONG Reserved : 29; + }; + ULONG TableOffset; }; - ULONG TableOffset; - }; } PCIX_TABLE_POINTER, *PPCIX_TABLE_POINTER; #endif #ifndef PCI_MSIX_CAPABILITY -typedef struct { - PCI_CAPABILITIES_HEADER Header; - struct { - USHORT TableSize :11; - USHORT Reserved :3; - USHORT FunctionMask :1; - USHORT MSIXEnable :1; - } MessageControl; - PCIX_TABLE_POINTER MessageTable; - PCIX_TABLE_POINTER PBATable; +typedef struct +{ + PCI_CAPABILITIES_HEADER Header; + struct + { + USHORT TableSize : 11; + USHORT Reserved : 3; + USHORT FunctionMask : 1; + USHORT MSIXEnable : 1; + } MessageControl; + PCIX_TABLE_POINTER MessageTable; + PCIX_TABLE_POINTER PBATable; } PCI_MSIX_CAPABILITY, *PPCI_MSIX_CAPABILITY; #endif -#define SPC3_SCSI_SENSEQ_PARAMETERS_CHANGED 0x0 -#define SPC3_SCSI_SENSEQ_MODE_PARAMETERS_CHANGED 0x01 -#define SPC3_SCSI_SENSEQ_CAPACITY_DATA_HAS_CHANGED 0x09 +#define SPC3_SCSI_SENSEQ_PARAMETERS_CHANGED 0x0 +#define SPC3_SCSI_SENSEQ_MODE_PARAMETERS_CHANGED 0x01 +#define SPC3_SCSI_SENSEQ_CAPACITY_DATA_HAS_CHANGED 0x09 -typedef enum VIOSCSI_VPD_CODE_SET { +typedef enum VIOSCSI_VPD_CODE_SET +{ VioscsiVpdCodeSetBinary = 1, VioscsiVpdCodeSetAscii = 2, VioscsiVpdCodeSetSASBinary = 0x61, } VIOSCSI_VPD_CODE_SET, *PVIOSCSI_VPD_CODE_SET; -typedef enum VIOSCSI_VPD_IDENTIFIER_TYPE { +typedef enum VIOSCSI_VPD_IDENTIFIER_TYPE +{ VioscsiVpdIdentifierTypeVendorSpecific = 0, VioscsiVpdIdentifierTypeVendorId = 1, VioscsiVpdIdentifierTypeEUI64 = 2, diff --git a/vioscsi/vioscsidt.h b/vioscsi/vioscsidt.h old mode 100755 new mode 100644 index 7faa94a23..b1e59c89e --- a/vioscsi/vioscsidt.h +++ b/vioscsi/vioscsidt.h @@ -3,73 +3,77 @@ // VioScsiExtendedInfoGuid - VioScsiExtendedInfo // VirtIO SCSI Extended Information -#define VioScsiWmi_ExtendedInfo_Guid \ - { 0x5cdac4f6,0x3d46,0x44e2, { 0x8d,0xee,0x01,0x60,0x6e,0x11,0xe2,0x65 } } - -#if ! (defined(MIDL_PASS)) -DEFINE_GUID(VioScsiExtendedInfoGuid_GUID, \ - 0x5cdac4f6,0x3d46,0x44e2,0x8d,0xee,0x01,0x60,0x6e,0x11,0xe2,0x65); +#define VioScsiWmi_ExtendedInfo_Guid \ + { \ + 0x5cdac4f6, 0x3d46, 0x44e2, \ + { \ + 0x8d, 0xee, 0x01, 0x60, 0x6e, 0x11, 0xe2, 0x65 \ + } \ + } + +#if !(defined(MIDL_PASS)) +DEFINE_GUID(VioScsiExtendedInfoGuid_GUID, 0x5cdac4f6, 0x3d46, 0x44e2, 0x8d, 0xee, 0x01, 0x60, 0x6e, 0x11, 0xe2, 0x65); #endif - typedef struct _VioScsiExtendedInfo { - // + // ULONG QueueDepth; - #define VioScsiExtendedInfo_QueueDepth_SIZE sizeof(ULONG) - #define VioScsiExtendedInfo_QueueDepth_ID 1 +#define VioScsiExtendedInfo_QueueDepth_SIZE sizeof(ULONG) +#define VioScsiExtendedInfo_QueueDepth_ID 1 - // + // UCHAR QueuesCount; - #define VioScsiExtendedInfo_QueuesCount_SIZE sizeof(UCHAR) - #define VioScsiExtendedInfo_QueuesCount_ID 2 +#define VioScsiExtendedInfo_QueuesCount_SIZE sizeof(UCHAR) +#define VioScsiExtendedInfo_QueuesCount_ID 2 - // + // BOOLEAN Indirect; - #define VioScsiExtendedInfo_Indirect_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_Indirect_ID 3 +#define VioScsiExtendedInfo_Indirect_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_Indirect_ID 3 - // + // BOOLEAN EventIndex; - #define VioScsiExtendedInfo_EventIndex_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_EventIndex_ID 4 +#define VioScsiExtendedInfo_EventIndex_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_EventIndex_ID 4 - // + // BOOLEAN DpcRedirection; - #define VioScsiExtendedInfo_DpcRedirection_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_DpcRedirection_ID 5 +#define VioScsiExtendedInfo_DpcRedirection_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_DpcRedirection_ID 5 - // + // BOOLEAN ConcurrentChannels; - #define VioScsiExtendedInfo_ConcurrentChannels_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_ConcurrentChannels_ID 6 +#define VioScsiExtendedInfo_ConcurrentChannels_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_ConcurrentChannels_ID 6 - // + // BOOLEAN InterruptMsgRanges; - #define VioScsiExtendedInfo_InterruptMsgRanges_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_InterruptMsgRanges_ID 7 +#define VioScsiExtendedInfo_InterruptMsgRanges_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_InterruptMsgRanges_ID 7 - // + // BOOLEAN CompletionDuringStartIo; - #define VioScsiExtendedInfo_CompletionDuringStartIo_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_CompletionDuringStartIo_ID 8 +#define VioScsiExtendedInfo_CompletionDuringStartIo_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_CompletionDuringStartIo_ID 8 - // + // BOOLEAN RingPacked; - #define VioScsiExtendedInfo_RingPacked_SIZE sizeof(BOOLEAN) - #define VioScsiExtendedInfo_RingPacked_ID 9 +#define VioScsiExtendedInfo_RingPacked_SIZE sizeof(BOOLEAN) +#define VioScsiExtendedInfo_RingPacked_ID 9 - // + // ULONG PhysicalBreaks; - #define VioScsiExtendedInfo_PhysicalBreaks_SIZE sizeof(ULONG) - #define VioScsiExtendedInfo_PhysicalBreaks_ID 10 +#define VioScsiExtendedInfo_PhysicalBreaks_SIZE sizeof(ULONG) +#define VioScsiExtendedInfo_PhysicalBreaks_ID 10 // ULONG ResponseTime; - #define VioScsiExtendedInfo_ResponseTime_SIZE sizeof(ULONG) - #define VioScsiExtendedInfo_ResponseTime_ID 11 +#define VioScsiExtendedInfo_ResponseTime_SIZE sizeof(ULONG) +#define VioScsiExtendedInfo_ResponseTime_ID 11 } VioScsiExtendedInfo, *PVioScsiExtendedInfo; -#define VioScsiExtendedInfo_SIZE (FIELD_OFFSET(VioScsiExtendedInfo, ResponseTime) + VioScsiExtendedInfo_ResponseTime_SIZE) +#define VioScsiExtendedInfo_SIZE \ + (FIELD_OFFSET(VioScsiExtendedInfo, ResponseTime) + VioScsiExtendedInfo_ResponseTime_SIZE) #endif diff --git a/vioscsi/virtio_pci.c b/vioscsi/virtio_pci.c old mode 100755 new mode 100644 index 3ca5dbda8..0095a6b32 --- a/vioscsi/virtio_pci.c +++ b/vioscsi/virtio_pci.c @@ -33,8 +33,8 @@ */ #include "osdep.h" #include "virtio_pci.h" -//#include "utils.h" -//#include "vioscsi.h" +// #include "utils.h" +// #include "vioscsi.h" #include "helper.h" #include "trace.h" @@ -50,54 +50,72 @@ static u32 ReadVirtIODeviceRegister(ULONG_PTR ulRegister) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { return StorPortReadRegisterUlong(NULL, (PULONG)(ulRegister)); - } else { + } + else + { return StorPortReadPortUlong(NULL, (PULONG)(ulRegister)); } } static void WriteVirtIODeviceRegister(ULONG_PTR ulRegister, u32 ulValue) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { StorPortWriteRegisterUlong(NULL, (PULONG)(ulRegister), (ULONG)(ulValue)); - } else { + } + else + { StorPortWritePortUlong(NULL, (PULONG)(ulRegister), (ULONG)(ulValue)); } } static u8 ReadVirtIODeviceByte(ULONG_PTR ulRegister) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { return StorPortReadRegisterUchar(NULL, (PUCHAR)(ulRegister)); - } else { + } + else + { return StorPortReadPortUchar(NULL, (PUCHAR)(ulRegister)); } } static void WriteVirtIODeviceByte(ULONG_PTR ulRegister, u8 bValue) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { StorPortWriteRegisterUchar(NULL, (PUCHAR)(ulRegister), (UCHAR)(bValue)); - } else { + } + else + { StorPortWritePortUchar(NULL, (PUCHAR)(ulRegister), (UCHAR)(bValue)); } } static u16 ReadVirtIODeviceWord(ULONG_PTR ulRegister) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { return StorPortReadRegisterUshort(NULL, (PUSHORT)(ulRegister)); - } else { + } + else + { return StorPortReadPortUshort(NULL, (PUSHORT)(ulRegister)); } } static void WriteVirtIODeviceWord(ULONG_PTR ulRegister, u16 wValue) { - if (ulRegister & ~PORT_MASK) { + if (ulRegister & ~PORT_MASK) + { StorPortWriteRegisterUshort(NULL, (PUSHORT)(ulRegister), (USHORT)(wValue)); - } else { + } + else + { StorPortWritePortUshort(NULL, (PUSHORT)(ulRegister), (USHORT)(wValue)); } } @@ -107,12 +125,15 @@ static void *mem_alloc_contiguous_pages(void *context, size_t size) PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)context; PVOID ptr = (PVOID)((ULONG_PTR)adaptExt->pageAllocationVa + adaptExt->pageOffset); - if ((adaptExt->pageOffset + size) <= adaptExt->pageAllocationSize) { + if ((adaptExt->pageOffset + size) <= adaptExt->pageAllocationSize) + { size = ROUND_TO_PAGES(size); adaptExt->pageOffset += size; RtlZeroMemory(ptr, size); return ptr; - } else { + } + else + { RhelDbgPrint(TRACE_LEVEL_FATAL, " Ran out of memory in alloc_pages_exact(%Id)\n", size); return NULL; } @@ -171,7 +192,8 @@ static int pci_read_config_dword(void *context, int where, u32 *dwVal) static size_t pci_get_resource_len(void *context, int bar) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)context; - if (bar < PCI_TYPE0_ADDRESSES) { + if (bar < PCI_TYPE0_ADDRESSES) + { return adaptExt->pci_bars[bar].uLength; } return 0; @@ -180,18 +202,20 @@ static size_t pci_get_resource_len(void *context, int bar) static void *pci_map_address_range(void *context, int bar, size_t offset, size_t maxlen) { PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)context; - if (bar < PCI_TYPE0_ADDRESSES) { + if (bar < PCI_TYPE0_ADDRESSES) + { PVIRTIO_BAR pBar = &adaptExt->pci_bars[bar]; - if (pBar->pBase == NULL) { - pBar->pBase = StorPortGetDeviceBase( - adaptExt, - PCIBus, - adaptExt->system_io_bus_number, - pBar->BasePA, - pBar->uLength, - !!pBar->bPortSpace); + if (pBar->pBase == NULL) + { + pBar->pBase = StorPortGetDeviceBase(adaptExt, + PCIBus, + adaptExt->system_io_bus_number, + pBar->BasePA, + pBar->uLength, + !!pBar->bPortSpace); } - if (pBar->pBase != NULL && offset < pBar->uLength) { + if (pBar->pBase != NULL && offset < pBar->uLength) + { return (PUCHAR)pBar->pBase + offset; } } @@ -203,18 +227,27 @@ static u16 vdev_get_msix_vector(void *context, int queue) PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)context; u16 vector; - if (queue >= 0) { + if (queue >= 0) + { /* queue interrupt */ - if (adaptExt->msix_enabled) { - if (adaptExt->msix_one_vector) { + if (adaptExt->msix_enabled) + { + if (adaptExt->msix_one_vector) + { vector = 0; - } else { + } + else + { vector = QUEUE_TO_MESSAGE(queue); } - } else { + } + else + { vector = VIRTIO_MSI_NO_VECTOR; } - } else { + } + else + { /* on-device-config-change interrupt */ vector = VIRTIO_MSI_NO_VECTOR; } @@ -230,6 +263,7 @@ static void vdev_sleep(void *context, unsigned int msecs) StorPortStallExecution(1000 * msecs); } +// clang-format off VirtIOSystemOps VioScsiSystemOps = { .vdev_read_byte = ReadVirtIODeviceByte, .vdev_read_word = ReadVirtIODeviceWord, @@ -250,3 +284,4 @@ VirtIOSystemOps VioScsiSystemOps = { .vdev_get_msix_vector = vdev_get_msix_vector, .vdev_sleep = vdev_sleep, }; +// clang-format on \ No newline at end of file