diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index 3abe4adba..be5570754 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -9,7 +9,7 @@ jobs: matrix: path: - check: '.' - exclude: './.*/.*trace.h|./NetKVM|./viocrypt|./viofs|./viosock|./VirtIO' + exclude: './.*/.*trace.h|./.*/wpp_.*_path.*.h|./NetKVM|./viocrypt|./viofs|./viosock|./VirtIO' - check: 'VirtIO' exclude: '' diff --git a/vioscsi/buildAll.bat b/vioscsi/buildAll.bat index 01f137890..0fa6e1554 100644 --- a/vioscsi/buildAll.bat +++ b/vioscsi/buildAll.bat @@ -1,4 +1,13 @@ @echo off + +rem Uncomment the following to enable ETW or debug for the hot path too. Defaults to cold path ETW only. +rem set RUN_WPP_ALL_PATHS=Yes + +rem Uncomment the following to compile without ETW or debug support. +rem set FORCE_RUN_UNCHECKED=Yes +rem Uncomment the following to enable debug instead of ETW. +rem set FORCE_RUN_DEBUG=Yes + if "%VIRTIO_WIN_NO_ARM%"=="" call ..\build\build.bat vioscsi.sln "Win10 Win11" ARM64 if errorlevel 1 goto :eof call ..\build\build.bat vioscsi.sln "Win10 Win11" %* diff --git a/vioscsi/helper.c b/vioscsi/helper.c index 440c5682f..75c04f9ac 100644 --- a/vioscsi/helper.c +++ b/vioscsi/helper.c @@ -32,7 +32,7 @@ #include "trace.h" #include "helper.h" -#if defined(EVENT_TRACING) +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) #include "helper.tmh" #endif @@ -45,6 +45,10 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_SRB_HP(); +#endif + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; PSRB_EXTENSION srbExt = NULL; PVOID va = NULL; @@ -59,8 +63,6 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) PREQUEST_LIST element; ULONG vq_req_idx; - ENTER_FN_SRB(); - if (!Srb) { return; @@ -73,7 +75,9 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) return; } - LOG_SRB_INFO(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + LOG_SRB_INFO_HP(); +#endif if (adaptExt->num_queues > 1) { @@ -90,11 +94,13 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortGetStartIoPerfParams failed srb 0x%p status 0x%x MessageNumber %d.\n", Srb, status, param.MessageNumber); +#endif } } @@ -102,7 +108,9 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) if (!srbExt) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " No SRB Extenstion for SRB 0x%p \n", Srb); +#endif return; } @@ -111,7 +119,9 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) if (adaptExt->reset_in_progress) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Reset is in progress, completing SRB 0x%p with SRB_STATUS_BUS_RESET.\n", Srb); +#endif SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUS_RESET); CompleteRequest(DeviceExtension, Srb); return; @@ -141,6 +151,7 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY); SRB_SET_SCSI_STATUS(Srb, ScsiStatus); StorPortBusy(DeviceExtension, 10); +#if !defined(RUN_UNCHECKED) 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", @@ -150,6 +161,7 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue); +#endif CompleteRequest(DeviceExtension, Srb); } StorPortReleaseSpinLock(DeviceExtension, &LockHandle); @@ -158,19 +170,24 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) virtqueue_notify(adaptExt->vq[QueueNumber]); } - EXIT_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_FN_SRB_HP(); +#endif } BOOLEAN SynchronizedTMFRoutine(IN PVOID DeviceExtension, IN PVOID Context) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + 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(); SET_VA_PA(); if (virtqueue_add_buf(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE], srbExt->psgl, @@ -181,26 +198,38 @@ SynchronizedTMFRoutine(IN PVOID DeviceExtension, IN PVOID Context) pa) >= 0) { virtqueue_kick(adaptExt->vq[VIRTIO_SCSI_CONTROL_QUEUE]); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY); StorPortBusy(DeviceExtension, adaptExt->queue_depth); +#if !defined(RUN_UNCHECKED) EXIT_ERR(); +#endif return FALSE; } BOOLEAN SendTMF(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { +#if !defined(RUN_UNCHECKED) ENTER_FN(); +#endif return StorPortSynchronizeAccess(DeviceExtension, SynchronizedTMFRoutine, (PVOID)Srb); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } BOOLEAN DeviceReset(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; PSCSI_REQUEST_BLOCK Srb = &adaptExt->tmf_cmd.Srb; PSRB_EXTENSION srbExt = adaptExt->tmf_cmd.SrbExtension; @@ -211,6 +240,9 @@ DeviceReset(IN PVOID DeviceExtension) ENTER_FN(); if (adaptExt->dump_mode) { +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return TRUE; } ASSERT(adaptExt->tmf_infly == FALSE); @@ -239,17 +271,27 @@ DeviceReset(IN PVOID DeviceExtension) if (!SendTMF(DeviceExtension, Srb)) { StorPortResume(DeviceExtension); +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return FALSE; } adaptExt->tmf_infly = TRUE; +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return TRUE; } VOID ShutDown(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + ULONG index; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - 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) @@ -258,13 +300,18 @@ VOID ShutDown(IN PVOID DeviceExtension) } virtio_device_shutdown(&adaptExt->vdev); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } VOID GetScsiConfig(IN PVOID DeviceExtension) { - PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; +#if !defined(RUN_UNCHECKED) ENTER_FN(); +#endif + + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; adaptExt->features = virtio_get_features(&adaptExt->vdev); adaptExt->indirect = CHECKBIT(adaptExt->features, VIRTIO_RING_F_INDIRECT_DESC); @@ -273,70 +320,66 @@ VOID GetScsiConfig(IN PVOID DeviceExtension) 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)); - 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)); - 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)); - 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)); - 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)); - 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)); - 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)); - 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)); - 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)); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_lun %lu\n", adaptExt->scsi_config.max_lun); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " seg_max : %lu \n", adaptExt->scsi_config.seg_max); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_sectors : %lu \n", adaptExt->scsi_config.max_sectors); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " num_queues : %lu \n", adaptExt->scsi_config.num_queues); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " cmd_per_lun : %lu \n", adaptExt->scsi_config.cmd_per_lun); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " event_info_size : %lu \n", adaptExt->scsi_config.event_info_size); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " sense_size : %lu \n", adaptExt->scsi_config.sense_size); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " cdb_size : %lu \n", adaptExt->scsi_config.cdb_size); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_channel : %u \n", adaptExt->scsi_config.max_channel); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_target : %u \n", adaptExt->scsi_config.max_target); + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " max_lun : %lu \n", adaptExt->scsi_config.max_lun); EXIT_FN(); +#endif } VOID SetGuestFeatures(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + ULONGLONG guestFeatures = 0; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - ENTER_FN(); if (CHECKBIT(adaptExt->features, VIRTIO_F_VERSION_1)) { @@ -370,12 +413,50 @@ VOID SetGuestFeatures(IN PVOID DeviceExtension) { guestFeatures |= (1ULL << VIRTIO_SCSI_F_HOTPLUG); } + +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_F_VERSION_1 flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_F_VERSION_1)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_F_RING_PACKED flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_F_RING_PACKED)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_F_ANY_LAYOUT flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_F_ANY_LAYOUT)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_F_ACCESS_PLATFORM flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_F_ACCESS_PLATFORM)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_RING_F_EVENT_IDX flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_RING_F_EVENT_IDX)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_RING_F_INDIRECT_DESC flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_RING_F_INDIRECT_DESC)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_SCSI_F_CHANGE flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_SCSI_F_CHANGE)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_GUEST_FEATURES, + " VIRTIO_SCSI_F_HOTPLUG flag is : %s \n", + (guestFeatures & (1ULL << VIRTIO_SCSI_F_HOTPLUG)) ? "ON" : "OFF"); +#endif + if (!NT_SUCCESS(virtio_set_features(&adaptExt->vdev, guestFeatures))) { - RhelDbgPrint(TRACE_LEVEL_FATAL, " virtio_set_features failed\n"); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_WARNING, " virtio_set_features() FAILED...!!!\n"); +#endif + } + else + { +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_GUEST_FEATURES, " virtio_set_features() executed successfully.\n"); +#endif } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } BOOLEAN @@ -388,7 +469,9 @@ InitVirtIODevice(IN PVOID DeviceExtension) if (!NT_SUCCESS(status)) { LogError(adaptExt, SP_INTERNAL_ADAPTER_ERROR, __LINE__); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Failed to initialize virtio device, error %x\n", status); +#endif return FALSE; } return TRUE; @@ -397,11 +480,14 @@ InitVirtIODevice(IN PVOID DeviceExtension) BOOLEAN InitHW(IN PVOID DeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PACCESS_RANGE accessRange; PADAPTER_EXTENSION adaptExt; ULONG pci_cfg_len, i; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; adaptExt->system_io_bus_number = ConfigInfo->SystemIoBusNumber; adaptExt->slot_number = ConfigInfo->SlotNumber; @@ -414,66 +500,414 @@ InitHW(IN PVOID DeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo) (PVOID)&adaptExt->pci_config_buf, sizeof(adaptExt->pci_config_buf)); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_VERBOSE, " StorPortGetBusData returns: %lu \n", pci_cfg_len); +#endif + if (pci_cfg_len != sizeof(adaptExt->pci_config_buf)) { LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " CANNOT READ PCI CONFIGURATION SPACE %d\n", pci_cfg_len); + EXIT_FN(); +#endif return FALSE; } + PPCI_COMMON_HEADER pPciComHeader; + UCHAR CapOffset; + PPCI_CAPABILITIES_HEADER pCapOffset; + PPCI_MSIX_CAPABILITY pMsixCapOffset; + PVIRTIO_PCI_COMMON_CFG_CAP pVirtioCommonCfgCap; + PVIRTIO_PCI_NOTIFY_CAP pVirtioNotifyCap; + PVIRTIO_PCI_ISR_CAP pVirtioIsrCap; + PVIRTIO_PCI_DEVICE_CAP pVirtioDeviceCap; + PPCI_RHEL_QEMU_CAPABILITY pQemuCapOffset; + ULONG max_cpus, idx; + + pPciComHeader = &adaptExt->pci_config; + if ((pPciComHeader->Status & PCI_STATUS_CAPABILITIES_LIST) == 0) { - UCHAR CapOffset; - PPCI_MSIX_CAPABILITY pMsixCapOffset; - PPCI_COMMON_HEADER pPciComHeader; - pPciComHeader = &adaptExt->pci_config; - if ((pPciComHeader->Status & PCI_STATUS_CAPABILITIES_LIST) == 0) - { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " NO CAPABILITIES_LIST\n"); - } - else +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " NO CAPABILITIES_LIST\n"); +#endif + } + else + { + if ((pPciComHeader->HeaderType & (~PCI_MULTIFUNCTION)) == PCI_DEVICE_TYPE) { - if ((pPciComHeader->HeaderType & (~PCI_MULTIFUNCTION)) == PCI_DEVICE_TYPE) + CapOffset = pPciComHeader->u.type0.CapabilitiesPtr; + while (CapOffset != 0) { - CapOffset = pPciComHeader->u.type0.CapabilitiesPtr; - while (CapOffset != 0) + pCapOffset = (PPCI_CAPABILITIES_HEADER)&adaptExt->pci_config_buf[CapOffset]; + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_MSIX) { pMsixCapOffset = (PPCI_MSIX_CAPABILITY)&adaptExt->pci_config_buf[CapOffset]; - if (pMsixCapOffset->Header.CapabilityID == PCI_CAPABILITY_ID_MSIX) + adaptExt->msix_enabled = (pMsixCapOffset->MessageControl.MSIXEnable == 1); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_MSIX, Next Capability Offset : 0x%x", + CapOffset); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : MessageControl.TableSize : %lu \n", + pMsixCapOffset->MessageControl.TableSize); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : Number of Table Entries (Vectors) : %lu \n", + pMsixCapOffset->MessageControl.TableSize + 1); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : MessageControl.FunctionMask : 0x%x \n", + pMsixCapOffset->MessageControl.FunctionMask); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : MessageControl.MSIXEnable : %lu \n", + pMsixCapOffset->MessageControl.MSIXEnable); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : Table Offset : %lu \n", + pMsixCapOffset->MessageTable.TableOffset); + RhelDbgPrint(TRACE_MSIX, + " > MSI-X : Pending Bit Array (PBA) Offset : 0x%x \n", + pMsixCapOffset->PBATable.TableOffset); + RhelDbgPrint(TRACE_MSIX, + " >> MSI-X is : %s [msix_enabled]\n", + (adaptExt->msix_enabled) ? "ENABLED" : "DISABLED"); +#endif + } + else if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_VENDOR_SPECIFIC) + { +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_VENDOR_SPECIFIC, Next Capability Offset : 0x%x \n", + CapOffset); + u8 virtioCapType = adaptExt->pci_config_buf[CapOffset + offsetof(struct virtio_pci_cap, cfg_type)]; + switch (virtioCapType) { - 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); + case VIRTIO_PCI_CAP_COMMON_CFG: + { + RhelDbgPrint(TRACE_PCI_CAP, + " > VIRTIO Capability FOUND : VIRTIO_PCI_CAP_COMMON_CFG \n"); + pVirtioCommonCfgCap = (PVIRTIO_PCI_COMMON_CFG_CAP)&adaptExt->pci_config_buf[CapOffset]; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - BAR : %lu (0x%x) \n", + pVirtioCommonCfgCap->cap.bar, + pVirtioCommonCfgCap->cap.bar); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Offset : %lu (0x%x) \n", + pVirtioCommonCfgCap->cap.offset, + pVirtioCommonCfgCap->cap.offset); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Length : %lu (0x%x) \n", + pVirtioCommonCfgCap->cap.length, + pVirtioCommonCfgCap->cap.length); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Device Feature : %lu (0x%x) " + "\n", + pVirtioCommonCfgCap->device_feature, + pVirtioCommonCfgCap->device_feature); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Number of Queues : %lu (0x%x) " + "\n", + pVirtioCommonCfgCap->num_queues, + pVirtioCommonCfgCap->num_queues); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Config Gen : %lu (0x%x) \n", + pVirtioCommonCfgCap->config_generation, + pVirtioCommonCfgCap->config_generation); + max_cpus = KeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Showing first %lu of %lu " + "Virtqueues: \n", + min(pVirtioCommonCfgCap->num_queues, + (max_cpus + VIRTIO_SCSI_REQUEST_QUEUE_0)), + pVirtioCommonCfgCap->num_queues); + for (idx = 0; idx < min(pVirtioCommonCfgCap->num_queues, + (max_cpus + VIRTIO_SCSI_REQUEST_QUEUE_0)); + ++idx) + { + pVirtioCommonCfgCap->queue_select = (u16)idx; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_COMMON_CFG Capability - Virtqueue : %lu | Size : " + "%lu Bytes (%lu KiB) \n", + pVirtioCommonCfgCap->queue_select, + pVirtioCommonCfgCap->queue_size, + (pVirtioCommonCfgCap->queue_size / 1024)); + } + } + break; + case VIRTIO_PCI_CAP_NOTIFY_CFG: + { + RhelDbgPrint(TRACE_PCI_CAP, + " > VIRTIO Capability FOUND : VIRTIO_PCI_CAP_NOTIFY_CFG \n"); + pVirtioNotifyCap = (PVIRTIO_PCI_NOTIFY_CAP)&adaptExt->pci_config_buf[CapOffset]; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_NOTIFY_CFG Capability - BAR : %lu (0x%x) \n", + pVirtioNotifyCap->cap.bar, + pVirtioNotifyCap->cap.bar); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_NOTIFY_CFG Capability - Offset : %lu (0x%x) \n", + pVirtioNotifyCap->cap.offset, + pVirtioNotifyCap->cap.offset); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_NOTIFY_CFG Capability - Length : %lu (0x%x) \n", + pVirtioNotifyCap->cap.length, + pVirtioNotifyCap->cap.length); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_NOTIFY_CFG Capability - Notify Off Multiplier : %lu " + "(0x%x) \n", + pVirtioNotifyCap->notify_off_multiplier, + pVirtioNotifyCap->notify_off_multiplier); + } + break; + case VIRTIO_PCI_CAP_ISR_CFG: + { + RhelDbgPrint(TRACE_PCI_CAP, " > VIRTIO Capability FOUND : VIRTIO_PCI_CAP_ISR_CFG \n"); + pVirtioIsrCap = (PVIRTIO_PCI_ISR_CAP)&adaptExt->pci_config_buf[CapOffset]; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_ISR_CFG Capability - BAR : %lu (0x%x) \n", + pVirtioIsrCap->cap.bar, + pVirtioIsrCap->cap.bar); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_ISR_CFG Capability - Offset : %lu (0x%x) \n", + pVirtioIsrCap->cap.offset, + pVirtioIsrCap->cap.offset); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_ISR_CFG Capability - Length : %lu (0x%x) \n", + pVirtioIsrCap->cap.length, + pVirtioIsrCap->cap.length); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_ISR_CFG Capability - Interrupt Service Routine (ISR) " + ": %lu (0x%x) \n", + pVirtioIsrCap->isr, + pVirtioIsrCap->isr); + } + break; + case VIRTIO_PCI_CAP_DEVICE_CFG: + { + RhelDbgPrint(TRACE_PCI_CAP, + " > VIRTIO Capability FOUND : VIRTIO_PCI_CAP_DEVICE_CFG \n"); + pVirtioDeviceCap = (PVIRTIO_PCI_DEVICE_CAP)&adaptExt->pci_config_buf[CapOffset]; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_DEVICE_CFG Capability - BAR : %lu (0x%x) \n", + pVirtioDeviceCap->cap.bar, + pVirtioDeviceCap->cap.bar); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_DEVICE_CFG Capability - Offset : %lu (0x%x) \n", + pVirtioDeviceCap->cap.offset, + pVirtioDeviceCap->cap.offset); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_DEVICE_CFG Capability - Length : %lu (0x%x) \n", + pVirtioDeviceCap->cap.length, + pVirtioDeviceCap->cap.length); + } + break; + case VIRTIO_PCI_CAP_PCI_CFG: + { + RhelDbgPrint(TRACE_PCI_CAP, " > VIRTIO Capability FOUND : VIRTIO_PCI_CAP_PCI_CFG \n"); + PVIRTIO_PCI_CFG_CAP pVirtioCfgCap; + pVirtioCfgCap = (PVIRTIO_PCI_CFG_CAP)&adaptExt->pci_config_buf[CapOffset]; + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_PCI_CFG Capability - BAR : %lu (0x%x) \n", + pVirtioCfgCap->cap.bar, + pVirtioCfgCap->cap.bar); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_PCI_CFG Capability - Offset : %lu (0x%x) \n", + pVirtioCfgCap->cap.offset, + pVirtioCfgCap->cap.offset); + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_PCI_CFG Capability - Length : %lu (0x%x) \n", + pVirtioCfgCap->cap.length, + pVirtioCfgCap->cap.length); + for (idx = 0; idx <= 3; ++idx) + { + RhelDbgPrint(TRACE_PCI_CAP, + " >> VIRTIO_PCI_CAP_PCI_CFG Capability - BAR Access [%lu]: %lu (0x%x) " + "\n", + idx, + pVirtioCfgCap->pci_cfg_data[idx], + pVirtioCfgCap->pci_cfg_data[idx]); + } + } + break; + case REDHAT_CAP_RESOURCE_RESERVE: + { + // This will likely never get hit because we need to set REDHAT_CAP_RESOURCE_RESERVE=6 + // (normally =1) so as not to clobber VIRTIO_PCI_CAP_COMMON_CFG=1 + pQemuCapOffset = (PPCI_RHEL_QEMU_CAPABILITY)&adaptExt->pci_config_buf[CapOffset]; + if (pQemuCapOffset->Reservation.type == REDHAT_CAP_RESOURCE_RESERVE) + { + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Capability Type : 0x%x (%s) \n", + pQemuCapOffset->Reservation.type, + ((pQemuCapOffset->Reservation.type == REDHAT_CAP_RESOURCE_RESERVE) ? "REDHAT_CAP_RESOURCE_RESERVE" + : "UNKNOWN")); + if (pQemuCapOffset->Reservation.len < REDHAT_CAP_RESOURCE_RESERVE_SIZE) + { + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : INVALID Capability Length : %lu | " + "!!! WARNING !!! \n", + pQemuCapOffset->Reservation.len); + } + else if (pQemuCapOffset->Reservation.type == REDHAT_CAP_RESOURCE_RESERVE) + { + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Capability Length : %lu \n", + pQemuCapOffset->Reservation.len); + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Minimum Bus Number : 0x%x \n", + pQemuCapOffset->Reservation.bus_res); + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : IO Space : 0x%I64x \n", + pQemuCapOffset->Reservation.io); + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Non-Prefetch Memory : 0x%x \n", + pQemuCapOffset->Reservation.mem); + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Prefetch Memory (32-bit MMIO) : " + "0x%x \n", + pQemuCapOffset->Reservation.prefetchable_32); + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : Prefetch Memory (64-bit MMIO) : " + "0x%I64x \n", + pQemuCapOffset->Reservation.prefetchable_64); + } + else + { + RhelDbgPrint(TRACE_PCI_CAP, + " QEMU Resource Reservation : UNKNOWN Capability Type | " + "!!! WARNING !!! \n"); + } + } + } + default: + { + RhelDbgPrint(TRACE_PCI_CAP, + " > UNKNOWN VENDOR SPECIFIC Capability FOUND : %lu (0x%x) \n", + virtioCapType, + virtioCapType); + } + break; } - else +#endif + } + else + { +#if !defined(RUN_UNCHECKED) + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_POWER_MANAGEMENT) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_POWER_MANAGEMENT, Next Capability Offset = " + "0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_AGP) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_AGP, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_VPD) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_VPD, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_SLOT_ID) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_SLOT_ID, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_MSI) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_MSI, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_CPCI_HOTSWAP) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_CPCI_HOTSWAP, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_PCIX) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_PCIX, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_HYPERTRANSPORT) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_HYPERTRANSPORT, Next Capability Offset = 0x%x " + "\n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_VENDOR_SPECIFIC) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_VENDOR_SPECIFIC, Next Capability Offset = 0x%x " + "\n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_DEBUG_PORT) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_DEBUG_PORT, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_CPCI_RES_CTRL) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_CPCI_RES_CTRL, Next Capability Offset = 0x%x " + "\n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_SHPC) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_SHPC, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_P2P_SSID) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_P2P_SSID, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_AGP_TARGET) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_AGP_TARGET, Next Capability Offset = 0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_SECURE) + { + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_SECURE capability, Next Capability Offset = " + "0x%x \n", + CapOffset); + } + if (pCapOffset->CapabilityID == PCI_CAPABILITY_ID_PCI_EXPRESS) { - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - " CapabilityID = %x, Next CapOffset = %x\n", - pMsixCapOffset->Header.CapabilityID, + RhelDbgPrint(TRACE_PCI_CAP, + " CapabilityID = PCI_CAPABILITY_ID_PCI_EXPRESS, Next Capability Offset = 0x%x \n", CapOffset); } - CapOffset = pMsixCapOffset->Header.Next; +#endif } - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " msix_enabled = %d\n", adaptExt->msix_enabled); - } - else - { - RhelDbgPrint(TRACE_LEVEL_FATAL, " NOT A PCI_DEVICE_TYPE\n"); + CapOffset = pCapOffset->Next; } } + else + { +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, " NOT A PCI_DEVICE_TYPE\n"); +#endif + // FIXME + // Should we not return on this error..? + // #if !defined(RUN_UNCHECKED) + // EXIT_FN(); + // #endif + // return FALSE; + } } /* initialize the pci_bars array */ @@ -485,67 +919,103 @@ InitHW(IN PVOID DeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo) 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 !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, + " Cannot get index for PCI Base Address Register (BAR) : %I64d \n", + accessRange->RangeStart.QuadPart); + EXIT_FN(); +#endif return FALSE; } adaptExt->pci_bars[iBar].BasePA = accessRange->RangeStart; adaptExt->pci_bars[iBar].uLength = accessRange->RangeLength; - adaptExt->pci_bars[iBar].bPortSpace = !accessRange->RangeInMemory; + adaptExt->pci_bars[iBar].bMemorySpace = accessRange->RangeInMemory; +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PCI Base Address Register (BAR) : 0x%010I64x | Length : %+5lu (0x%04x) | MemorySpace : %s | " + "IoSpace : %s \n", + adaptExt->pci_bars[iBar].BasePA.QuadPart, + adaptExt->pci_bars[iBar].uLength, + adaptExt->pci_bars[iBar].uLength, + (adaptExt->pci_bars[iBar].bMemorySpace) ? "YES" : "NO", + (!adaptExt->pci_bars[iBar].bMemorySpace) ? "YES" : "NO"); +#endif } } /* initialize the virtual device */ if (!InitVirtIODevice(DeviceExtension)) { +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return FALSE; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } BOOLEAN SynchronizedKickEventRoutine(IN PVOID DeviceExtension, IN PVOID Context) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + 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]); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } +#if !defined(RUN_UNCHECKED) EXIT_ERR(); +#endif return FALSE; } BOOLEAN KickEvent(IN PVOID DeviceExtension, IN PVirtIOSCSIEventNode EventNode) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt; ULONG fragLen; - 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); - return SynchronizedKickEventRoutine(DeviceExtension, (PVOID)EventNode); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif + return SynchronizedKickEventRoutine(DeviceExtension, (PVOID)EventNode); } VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN_SRB(); +#endif + PADAPTER_EXTENSION adaptExt; PSRB_EXTENSION srbExt = NULL; ULONG dataLen = 0; PSRB_IO_CONTROL srbControl = NULL; PFIRMWARE_REQUEST_BLOCK firmwareRequest = NULL; - ENTER_FN(); + adaptExt = (PADAPTER_EXTENSION)DeviceExtension; srbExt = SRB_EXTENSION(Srb); srbControl = (PSRB_IO_CONTROL)SRB_DATA_BUFFER(Srb); @@ -554,25 +1024,28 @@ VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " FirmwareRequest Bad Block Length %ul\n", dataLen); + EXIT_FN_SRB(); +#endif 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); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " FIRMWARE_FUNCTION_GET_INFO \n"); +#endif 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; @@ -602,10 +1075,12 @@ VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Wrong Version %ul or Size %ul\n", firmwareInfo->Version, firmwareInfo->Size); +#endif srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); } @@ -615,7 +1090,9 @@ VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { PSTORAGE_FIRMWARE_DOWNLOAD_V2 firmwareDwnld; firmwareDwnld = (PSTORAGE_FIRMWARE_DOWNLOAD_V2)((PUCHAR)srbControl + firmwareRequest->DataBufferOffset); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " FIRMWARE_FUNCTION_DOWNLOAD \n"); +#endif if ((firmwareDwnld->Version >= STORAGE_FIRMWARE_DOWNLOAD_STRUCTURE_VERSION_V2) || (firmwareDwnld->Size >= sizeof(STORAGE_FIRMWARE_DOWNLOAD_V2))) { @@ -627,10 +1104,12 @@ VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Wrong Version %ul or Size %ul\n", firmwareDwnld->Version, firmwareDwnld->Size); +#endif srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); } @@ -650,20 +1129,28 @@ VOID FirmwareRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Wrong Version %ul or Size %ul\n", firmwareActivate->Version, firmwareActivate->Size); +#endif srbControl->ReturnCode = FIRMWARE_STATUS_INVALID_PARAMETER; SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BAD_SRB_BLOCK_LENGTH); } +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " FIRMWARE_FUNCTION_ACTIVATE \n"); +#endif } break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unsupported Function %ul\n", firmwareRequest->Function); +#endif SRB_SET_SRB_STATUS(Srb, SRB_STATUS_INVALID_REQUEST); break; } - EXIT_FN(); +#if !defined(RUN_UNCHECKED) + EXIT_FN_SRB(); +#endif } diff --git a/vioscsi/helper.h b/vioscsi/helper.h index 13f2d2e62..f644780c6 100644 --- a/vioscsi/helper.h +++ b/vioscsi/helper.h @@ -35,6 +35,7 @@ #include #include #include +#include #include "osdep.h" #include "virtio_pci.h" @@ -132,9 +133,7 @@ VOID VioScsiCompleteDpcRoutine(IN PSTOR_DPC Dpc, IN PVOID Context, IN PVOID Syst VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOCK LockMode); -VOID -// FORCEINLINE -HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd); +VOID FORCEINLINE HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd, IN PVOID InlineFuncName); PVOID VioScsiPoolAlloc(IN PVOID DeviceExtension, IN SIZE_T size); diff --git a/vioscsi/trace.h b/vioscsi/trace.h old mode 100755 new mode 100644 index aa9fdce53..c19425230 --- a/vioscsi/trace.h +++ b/vioscsi/trace.h @@ -1,70 +1,85 @@ /* -* This file contains debug print support routines and globals. -* -* Copyright (c) 2012-2018 Red Hat, Inc. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met : -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and / or other materials provided with the distribution. -* 3. Neither the names of the copyright holders nor the names of their contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -*/ + * This file contains debug print support routines and globals. + * + * Copyright (c) 2012-2018 Red Hat, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met : + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and / or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of their contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ #ifndef ___TRACING_H___ #define ___TRACING_H___ /* RUN_UNCHECKED - NO DEBUG OR TRACING - * This option disables all debug messages and ETW for maximum performance.*/ + * This option disables all debug messages and ETW for maximum performance. + * NOT the default configuration. + * Configured in the vioscsi.vcxproj project file, which looks for the + * FORCE_RUN_UNCHECKED environment variable, from which the RUN_UNCHECKED + * macro is configured. */ +#if !defined(RUN_UNCHECKED) #define RUN_UNCHECKED 1 -#undef RUN_UNCHECKED // <== switch me here with comment +#undef RUN_UNCHECKED // <== switch me here with comment (force always defined - use with CAUTION) +#endif -/* RUN_MIN_CHECKED - MINIMUM DEBUG OR FULL TRACING +/* RUN_COLD_PATH_ONLY - COLD PATH DEBUG OR TRACING * This option includes select conditionally compiled debug messages. - * However, if ETW is enabled instead of DEBUG, all traces will be included - * regardless of any compile-time conditional statements because the WPP will - * scan for all events and will ignore compile-time conditional statements. */ -#define RUN_MIN_CHECKED 1 -#undef RUN_MIN_CHECKED // <== switch me here with comment + * This is the default option. + * Configured in the vioscsi.vcxproj project file, which looks for the + * RUN_WPP_ALL_PATHS environment variable, from which the WPP configuration + * and the RUN_COLD_PATH_ONLY macro are configured. */ +#if !defined(RUN_COLD_PATH_ONLY) +#define RUN_COLD_PATH_ONLY 1 +#undef RUN_COLD_PATH_ONLY // <== switch me here with comment (force always defined - use with CAUTION) +#endif /* EVENT_TRACING - CHOOSE BETWEEN DEBUG OR TRACING - * if EVENT_TRACING is undefined, DEBUG (DBG) will be enabled below... */ + * if EVENT_TRACING is undefined, DEBUG (DBG) will be enabled below... + * This is the default option. + * Configured in the vioscsi.vcxproj project file, which looks for the + * FORCE_RUN_DEBUG environment variable, from which the EVENT_TRACING + * macro is configured. */ +#if !defined(EVENT_TRACING) #define EVENT_TRACING 1 -//#undef EVENT_TRACING // <== switch me here with comment +#undef EVENT_TRACING // <== switch me here with comment (force always defined - use with CAUTION) +#endif #include #include #include #include "kdebugprint.h" -#define UCHAR_MAX 0xFF +#define UCHAR_MAX 0xFF #define DbgGetScsiOp(Srb) (SRB_CDB(Srb) ? SRB_CDB(Srb)->CDB6GENERIC.OperationCode : UCHAR_MAX) char *DbgGetScsiOpStr(IN UCHAR opCode); -void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath); +void InitializeDebugPrints(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath); #if !defined(EVENT_TRACING) -#define DBG 1 +#define DBG 1 /* EVENT_TRACING - CHOOSE BETWEEN DEBUG TO STDIO OR SERIAL PORT * if PRINT_DEBUG is undefined, output to the serial port (COM_DEBUG) will be enabled below... */ #define PRINT_DEBUG 1 -//#undef PRINT_DEBUG // <== switch me here with comment +// #undef PRINT_DEBUG // <== switch me here with comment #if !defined(PRINT_DEBUG) #define COM_DEBUG 1 #endif @@ -102,145 +117,185 @@ extern int nVioscsiDebugLevel; #define TRACE_ALL 31 #endif -#define RhelDbgPrint(Level, MSG, ...) \ - if ((!bDebugPrint) || Level > nVioscsiDebugLevel) {} \ - else VirtioDebugPrintProc (MSG, __VA_ARGS__) -#define VioScsiDbgBreak()\ - if (KD_DEBUGGER_ENABLED && !KD_DEBUGGER_NOT_PRESENT) DbgBreakPoint(); - -#define ENTER_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n",__FUNCTION__) -#define EXIT_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n",__FUNCTION__) -#define ENTER_INL_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n",__FUNCTION__) -#define EXIT_INL_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n",__FUNCTION__) -#define EXIT_ERR() RhelDbgPrint(TRACE_LEVEL_ERROR, " <--> %s (%d).\n", __FUNCTION__, __LINE__) -#define ENTER_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n",__FUNCTION__, Srb) -#define EXIT_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n",__FUNCTION__, Srb) -#define ENTER_INL_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n",__FUNCTION__, Srb) -#define EXIT_INL_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n",__FUNCTION__, Srb) -#define LOG_SRB_INFO() RhelDbgPrint(TRACE_LEVEL_INFORMATION, "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n",__FUNCTION__, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb) -#define LOG_SRB_INFO_FROM_INLFN() RhelDbgPrint(TRACE_LEVEL_INFORMATION, "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n",__FUNCTION__, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb) +#define RhelDbgPrint(Level, MSG, ...) \ + if ((!bDebugPrint) || Level > nVioscsiDebugLevel) \ + { \ + } \ + else \ + VirtioDebugPrintProc(MSG, __VA_ARGS__) +#define VioScsiDbgBreak() \ + if (KD_DEBUGGER_ENABLED && !KD_DEBUGGER_NOT_PRESENT) \ + DbgBreakPoint(); +#if !defined(RUN_COLD_PATH_ONLY) +// Put all hot path entries from here. We will skip them when RUN_COLD_PATH_ONLY is defined. +#define RhelDbgPrintHotPath(Level, MSG, ...) \ + if ((!bDebugPrint) || Level > nVioscsiDebugLevel) \ + { \ + } \ + else \ + VirtioDebugPrintProc(MSG, __VA_ARGS__) +#define ENTER_FN_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n", __FUNCTION__) +#define EXIT_FN_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n", __FUNCTION__) +#define ENTER_INL_FN_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n", __FUNCTION__) +#define EXIT_INL_FN_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n", __FUNCTION__) +#define EXIT_ERR_HP() RhelDbgPrint(TRACE_LEVEL_ERROR, " <--> %s (%d).\n", __FUNCTION__, __LINE__) +#define ENTER_FN_SRB_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define EXIT_FN_SRB_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define ENTER_INL_FN_SRB_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define EXIT_INL_FN_SRB_HP() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define LOG_SRB_INFO_HP() \ + RhelDbgPrint(TRACE_LEVEL_INFORMATION, \ + "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n", \ + __FUNCTION__, \ + DbgGetScsiOpStr(DbgGetScsiOp(Srb)), \ + DbgGetScsiOp(Srb), \ + SRB_PATH_ID(Srb), \ + SRB_TARGET_ID(Srb), \ + SRB_LUN(Srb), \ + Srb) +#define LOG_SRB_INFO_FROM_INLFN_HP() \ + RhelDbgPrint(TRACE_LEVEL_INFORMATION, \ + "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n", \ + __FUNCTION__, \ + DbgGetScsiOpStr(DbgGetScsiOp(Srb)), \ + DbgGetScsiOp(Srb), \ + SRB_PATH_ID(Srb), \ + SRB_TARGET_ID(Srb), \ + SRB_LUN(Srb), \ + Srb) #else -#if defined(RUN_UNCHECKED) && !defined(RUN_MIN_CHECKED) +#define RhelDbgPrintHotPath(Level, MSG, ...) \ + if ((!bDebugPrint) || Level > nVioscsiDebugLevel) \ + { \ + } \ + else \ + VirtioDebugPrintProc(MSG, __VA_ARGS__) +#define ENTER_FN_HP() +#define EXIT_FN_HP() +#define ENTER_INL_FN_HP() +#define EXIT_INL_FN_HP() +#define EXIT_ERR_HP() +#define ENTER_FN_SRB_HP() +#define EXIT_FN_SRB_HP() +#define LOG_SRB_INFO_HP() +#define ENTER_INL_FN_SRB_HP() +#define EXIT_INL_FN_SRB_HP() +#define LOG_SRB_INFO_FROM_INLFN_HP() +#endif + +#define ENTER_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n", __FUNCTION__) +#define EXIT_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n", __FUNCTION__) +#define ENTER_INL_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s.\n", __FUNCTION__) +#define EXIT_INL_FN() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s.\n", __FUNCTION__) +#define EXIT_ERR() RhelDbgPrint(TRACE_LEVEL_ERROR, " <--> %s (%d).\n", __FUNCTION__, __LINE__) +#define ENTER_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define EXIT_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define ENTER_INL_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " --> %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define EXIT_INL_FN_SRB() RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <-- %s Srb = 0x%p.\n", __FUNCTION__, Srb) +#define LOG_SRB_INFO() \ + RhelDbgPrint(TRACE_LEVEL_INFORMATION, \ + "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n", \ + __FUNCTION__, \ + DbgGetScsiOpStr(DbgGetScsiOp(Srb)), \ + DbgGetScsiOp(Srb), \ + SRB_PATH_ID(Srb), \ + SRB_TARGET_ID(Srb), \ + SRB_LUN(Srb), \ + Srb) +#define LOG_SRB_INFO_FROM_INLFN() \ + RhelDbgPrint(TRACE_LEVEL_INFORMATION, \ + "%s <--> Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p\n", \ + __FUNCTION__, \ + DbgGetScsiOpStr(DbgGetScsiOp(Srb)), \ + DbgGetScsiOp(Srb), \ + SRB_PATH_ID(Srb), \ + SRB_TARGET_ID(Srb), \ + SRB_LUN(Srb), \ + Srb) + +#else // DBG above, EVENT_TRACING below. +#if defined(RUN_UNCHECKED) +/* When the FORCE_RUN_UNCHECKED environment variable is set, + * the vioscsi.vcxproj project file will DISABLE the WPP, so + * we disable ETW here too. We define RUN_COLD_PATH_ONLY to + * dereference hot path entries, as these are subject to the + * compile-time conditional !defined(RUN_COLD_PATH_ONLY). + */ #undef EVENT_TRACING +#if !defined(RUN_COLD_PATH_ONLY) +#define RUN_COLD_PATH_ONLY +#endif #else -#pragma warning(disable: 28170) -#pragma warning(disable: 28251) +/* Enable EVENT_TRACING */ + +#pragma warning(disable : 28170) +#pragma warning(disable : 28251) #include // {194051B2-14C7-4987-A0E9-154377C58882} -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(VioScsiTraceGuid,(194051B2,14C7,4987,A0E9,154377C58882), \ - WPP_DEFINE_BIT(TRACE_LEVEL_NONE) /* bit 0 = 0x00000001 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_FATAL) /* bit 1 = 0x00000002 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_ERROR) /* bit 2 = 0x00000004 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_WARNING) /* bit 3 = 0x00000008 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_INFORMATION) /* bit 4 = 0x00000010 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_VERBOSE) /* bit 5 = 0x00000020 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED6) /* bit 6 = 0x00000040 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED7) /* bit 7 = 0x00000080 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED8) /* bit 8 = 0x00000100 */ \ - WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED9) /* bit 9 = 0x00000200 */ \ - WPP_DEFINE_BIT(TRACE_VQ) /* bit 10 = 0x00000400 */ \ - WPP_DEFINE_BIT(TRACE_LOCKS) /* bit 11 = 0x00000800 */ \ - WPP_DEFINE_BIT(TRACE_DPC) /* bit 12 = 0x00001000 */ \ - WPP_DEFINE_BIT(TRACE_MSIX) /* bit 13 = 0x00002000 */ \ - WPP_DEFINE_BIT(TRACE_ENTER_EXIT) /* bit 14 = 0x00004000 */ \ - WPP_DEFINE_BIT(TRACE_NOTIFY) /* bit 15 = 0x00008000 */ \ - WPP_DEFINE_BIT(TRACE_GUEST_FEATURES) /* bit 16 = 0x00008000 */ \ - WPP_DEFINE_BIT(TRACE_PCI_CAP) /* bit 17 = 0x00010000 */ \ - WPP_DEFINE_BIT(TRACE_MAPPING) /* bit 18 = 0x00020000 */ \ - WPP_DEFINE_BIT(TRACE_MSIX_CPU_AFFINITY) /* bit 19 = 0x00040000 */ \ - WPP_DEFINE_BIT(TRACE_REGISTRY) /* bit 20 = 0x00080000 */ \ - WPP_DEFINE_BIT(TRACE_ALL) /* bit LAST PLACEHLDR */ \ - ) - -// begin_wpp config -// USEPREFIX (RhelDbgPrint, "%!STDPREFIX! ####\t\t[%!FUNC!] DEBUG:"); -// FUNC RhelDbgPrint(LEVEL, MSG, ...); -// end_wpp -#define WPP_Flags_LEVEL_LOGGER(Flags, level) WPP_LEVEL_LOGGER(Flags) -#define WPP_Flags_LEVEL_ENABLED(Flags, level) \ - (WPP_LEVEL_ENABLED(Flags) && \ - WPP_CONTROL(WPP_BIT_ ## Flags).Level >= level) - -// begin_wpp config -// USEPREFIX (ENTER_FN, "%!STDPREFIX! ===>\t\t[%!FUNC!] X---X Working X---X"); -// FUNC ENTER_FN{ENTRYLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_ENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_ENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) +#define WPP_CONTROL_GUIDS \ + WPP_DEFINE_CONTROL_GUID(VioScsiTraceGuid, \ + (194051B2, 14C7, 4987, A0E9, 154377C58882), \ + WPP_DEFINE_BIT(TRACE_LEVEL_NONE) /* bit 0 = 0x00000001 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_FATAL) /* bit 1 = 0x00000002 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_ERROR) /* bit 2 = 0x00000004 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_WARNING) /* bit 3 = 0x00000008 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_INFORMATION) /* bit 4 = 0x00000010 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_VERBOSE) /* bit 5 = 0x00000020 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED6) /* bit 6 = 0x00000040 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED7) /* bit 7 = 0x00000080 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED8) /* bit 8 = 0x00000100 */ \ + WPP_DEFINE_BIT(TRACE_LEVEL_RESERVED9) /* bit 9 = 0x00000200 */ \ + WPP_DEFINE_BIT(TRACE_VQ) /* bit 10 = 0x00000400 */ \ + WPP_DEFINE_BIT(TRACE_LOCKS) /* bit 11 = 0x00000800 */ \ + WPP_DEFINE_BIT(TRACE_DPC) /* bit 12 = 0x00001000 */ \ + WPP_DEFINE_BIT(TRACE_MSIX) /* bit 13 = 0x00002000 */ \ + WPP_DEFINE_BIT(TRACE_ENTER_EXIT) /* bit 14 = 0x00004000 */ \ + WPP_DEFINE_BIT(TRACE_NOTIFY) /* bit 15 = 0x00008000 */ \ + WPP_DEFINE_BIT(TRACE_GUEST_FEATURES) /* bit 16 = 0x00008000 */ \ + WPP_DEFINE_BIT(TRACE_PCI_CAP) /* bit 17 = 0x00010000 */ \ + WPP_DEFINE_BIT(TRACE_MAPPING) /* bit 18 = 0x00020000 */ \ + WPP_DEFINE_BIT(TRACE_MSIX_CPU_AFFINITY) /* bit 19 = 0x00040000 */ \ + WPP_DEFINE_BIT(TRACE_REGISTRY) /* bit 20 = 0x00080000 */ \ + WPP_DEFINE_BIT(TRACE_ALL) /* bit LAST PLACEHLDR */ \ + ) -// begin_wpp config -// USEPREFIX (EXIT_FN, "%!STDPREFIX! <===\t\t[%!FUNC!] Processing complete."); -// FUNC EXIT_FN{EXITLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_EXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_EXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (ENTER_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] X---X Working X---X", InlineFuncName); -// FUNC ENTER_INL_FN{INLENTRYLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_INLENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_INLENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (EXIT_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] Processing complete.", InlineFuncName); -// FUNC EXIT_INL_FN{INLEXITLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_INLEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_INLEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (EXIT_ERR, "%!STDPREFIX! >>>>\t\t[%!FUNC!] ERROR line %d", __LINE__); -// FUNC EXIT_ERR{ERRORLEVEL=TRACE_LEVEL_ERROR}(...); -// end_wpp -#define WPP_ERRORLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_ERRORLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (ENTER_FN_SRB(PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!] SRB 0x%p", Srb); -// FUNC ENTER_FN_SRB{SRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_SRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_SRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (EXIT_FN_SRB(PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!] SRB 0x%p", Srb); -// FUNC EXIT_FN_SRB{SRBEXITLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_SRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_SRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (LOG_SRB_INFO(PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); -// FUNC LOG_SRB_INFO{SRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); -// end_wpp -#define WPP_SRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_SRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (ENTER_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] SRB 0x%p", InlineFuncName, Srb); -// FUNC ENTER_INL_FN_SRB{INLSRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_INLSRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_INLSRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (EXIT_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] SRB 0x%p", InlineFuncName, Srb); -// FUNC EXIT_INL_FN_SRB{INLSRBEXITLEVEL=TRACE_ENTER_EXIT}(...); -// end_wpp -#define WPP_INLSRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_INLSRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) - -// begin_wpp config -// USEPREFIX (LOG_SRB_INFO_FROM_INLFN(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!]:[%s] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", InlineFuncName, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); -// FUNC LOG_SRB_INFO_FROM_INLFN{INLSRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); -// end_wpp -#define WPP_INLSRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) -#define WPP_INLSRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) +#if !defined(RUN_COLD_PATH_ONLY) +/* This is NOT the default. + * When RUN_COLD_PATH_ONLY is NOT defined or when the RUN_WPP_ALL_PATHS + * environment variable is set, we load the wpp_all_paths.h header file. + * This header file contains both hot and cold path entries. + * The vioscsi.vcxproj project file will configure WPP to use this file. + */ +#include "wpp_all_paths.h" +#else +/* This is the default. + * When RUN_COLD_PATH_ONLY is defined or when the RUN_WPP_ALL_PATHS + * environment variable is NOT set, we load the wpp_cold_path.h header file. + * This header file contains cold paths entries only. + * The vioscsi.vcxproj project file will configure WPP to use this file. + */ +#include "wpp_cold_path.h" +/* To avoid compilation errors, we need dummy macros here for + * when the hot path is not included. Here VirtioDebugPrintProc is set to + * NoDebugPrintFunc in the utils.c file, so nothing will be printed. + */ +#define RhelDbgPrintHotPath(Level, MSG, ...) VirtioDebugPrintProc(MSG, __VA_ARGS__) +#define ENTER_FN_HP() +#define EXIT_FN_HP() +#define ENTER_INL_FN_HP() +#define EXIT_INL_FN_HP() +#define EXIT_ERR_HP() +#define ENTER_FN_SRB_HP() +#define EXIT_FN_SRB_HP() +#define LOG_SRB_INFO_HP() +#define ENTER_INL_FN_SRB_HP() +#define EXIT_INL_FN_SRB_HP() +#define LOG_SRB_INFO_FROM_INLFN_HP() +#endif +/* Common to hot and cold path entries from here. */ // // Configure WPP macros for optimum performance @@ -248,7 +303,7 @@ extern int nVioscsiDebugLevel; // as we call it in DriverEntry() anyway. // #define WPP_CHECK_INIT - + #endif #endif diff --git a/vioscsi/vioscsi.c b/vioscsi/vioscsi.c index c5b51a12a..80a3e9110 100644 --- a/vioscsi/vioscsi.c +++ b/vioscsi/vioscsi.c @@ -34,7 +34,7 @@ #include "vioscsidt.h" #include "trace.h" -#if defined(EVENT_TRACING) +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) #include "vioscsi.tmh" #endif @@ -68,7 +68,7 @@ HW_DPC_ROUTINE VioScsiCompleteDpcRoutine; HW_PASSIVE_INITIALIZE_ROUTINE VioScsiPassiveInitializeRoutine; HW_MESSAGE_SIGNALED_INTERRUPT_ROUTINE VioScsiMSInterrupt; -#ifdef EVENT_TRACING +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) PVOID TraceContext = NULL; VOID WppCleanupRoutine(PVOID arg1) { @@ -111,11 +111,11 @@ 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, IN PVOID InlineFuncName); -VOID FORCEINLINE PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb); +VOID FORCEINLINE PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb, IN PVOID InlineFuncName); -VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId); +VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId, IN PVOID InlineFuncName); BOOLEAN VioScsiInterrupt(IN PVOID DeviceExtension); @@ -229,7 +229,9 @@ BOOLEAN VioScsiReadRegistryParameter(IN PVOID DeviceExtension, IN PUCHAR ValueNa pBuf = StorPortAllocateRegistryBuffer(DeviceExtension, &Len); if (pBuf == NULL) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, "StorPortAllocateRegistryBuffer failed to allocate buffer\n"); +#endif return FALSE; } @@ -239,7 +241,9 @@ BOOLEAN VioScsiReadRegistryParameter(IN PVOID DeviceExtension, IN PUCHAR ValueNa if ((Ret == FALSE) || (Len == 0)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, "StorPortRegistryRead returned 0x%x, Len = %d\n", Ret, Len); +#endif StorPortFreeRegistryBuffer(DeviceExtension, pBuf); return FALSE; } @@ -258,18 +262,22 @@ DriverEntry(IN PVOID DriverObject, IN PVOID RegistryPath) HW_INITIALIZATION_DATA hwInitData; ULONG initResult; -#ifdef EVENT_TRACING +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) STORAGE_TRACE_INIT_INFO initInfo; #endif InitializeDebugPrints((PDRIVER_OBJECT)DriverObject, (PUNICODE_STRING)RegistryPath); IsCrashDumpMode = FALSE; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Vioscsi driver started...built on %s %s\n", __DATE__, __TIME__); +#endif if (RegistryPath == NULL) { IsCrashDumpMode = TRUE; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Crash dump mode\n"); +#endif } RtlZeroMemory(&hwInitData, sizeof(HW_INITIALIZATION_DATA)); @@ -307,7 +315,7 @@ DriverEntry(IN PVOID DriverObject, IN PVOID RegistryPath) initResult = StorPortInitialize(DriverObject, RegistryPath, &hwInitData, NULL); -#ifdef EVENT_TRACING +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) TraceContext = NULL; memset(&initInfo, 0, sizeof(STORAGE_TRACE_INIT_INFO)); @@ -325,7 +333,9 @@ DriverEntry(IN PVOID DriverObject, IN PVOID RegistryPath) } #endif +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " Initialize returned 0x%x\n", initResult); +#endif return initResult; } @@ -338,6 +348,10 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN PBOOLEAN Again) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt; PVOID uncachedExtensionVa; USHORT queueLength = 0; @@ -354,8 +368,6 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, UNREFERENCED_PARAMETER(ArgumentString); UNREFERENCED_PARAMETER(Again); - ENTER_FN(); - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; RtlZeroMemory(adaptExt, sizeof(ADAPTER_EXTENSION)); @@ -377,7 +389,9 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, if (!InitHW(DeviceExtension, ConfigInfo)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot initialize HardWare\n"); +#endif return SP_RETURN_NOT_FOUND; } @@ -423,8 +437,10 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, ConfigInfo->NumberOfPhysicalBreaks = adaptExt->max_physical_breaks + 1; ConfigInfo->MaximumTransferLength = adaptExt->max_physical_breaks * PAGE_SIZE; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " NumberOfPhysicalBreaks %d\n", ConfigInfo->NumberOfPhysicalBreaks); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " MaximumTransferLength %d\n", ConfigInfo->MaximumTransferLength); +#endif num_cpus = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS); max_cpus = KeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS); @@ -450,7 +466,9 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, adaptExt->resp_time = 0; VioScsiReadRegistryParameter(DeviceExtension, REGISTRY_RESP_TIME_LIMIT, FIELD_OFFSET(ADAPTER_EXTENSION, resp_time)); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Queues %d CPUs %d\n", adaptExt->num_queues, num_cpus); +#endif /* Figure out the maximum number of queues we will ever need to set up. Note that this may * be higher than adaptExt->num_queues, because the driver may be reinitialized by calling @@ -466,7 +484,9 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, max_queues = min(max_cpus, adaptExt->scsi_config.num_queues); if (adaptExt->num_queues > max_queues) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_WARNING, " Multiqueue can only use at most one queue per cpu."); +#endif adaptExt->num_queues = max_queues; } } @@ -493,7 +513,9 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, { LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Virtual queue %d config failed.\n", index); +#endif return SP_RETURN_ERROR; } adaptExt->pageAllocationSize += ROUND_TO_PAGES(Size); @@ -523,22 +545,28 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, ConfigInfo->InitialLunQueueDepth = ConfigInfo->MaxIOsPerLun; ConfigInfo->MaxNumberOfIO = ConfigInfo->MaxIOsPerLun; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " breaks_number = %x queue_depth = %x\n", ConfigInfo->NumberOfPhysicalBreaks, adaptExt->queue_depth); +#endif extensionSize = PAGE_SIZE + adaptExt->pageAllocationSize + adaptExt->poolAllocationSize; uncachedExtensionVa = StorPortGetUncachedExtension(DeviceExtension, ConfigInfo, extensionSize); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " StorPortGetUncachedExtension uncachedExtensionVa = %p allocation size = %d\n", uncachedExtensionVa, extensionSize); +#endif if (!uncachedExtensionVa) { LogError(DeviceExtension, SP_INTERNAL_ADAPTER_ERROR, __LINE__); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Can't get uncached extension allocation size = %d\n", extensionSize); +#endif return SP_RETURN_ERROR; } @@ -560,6 +588,7 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, { adaptExt->poolAllocationVa = (PVOID)((ULONG_PTR)adaptExt->pageAllocationVa + adaptExt->pageAllocationSize); } +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Page-aligned area at %p, size = %d\n", adaptExt->pageAllocationVa, @@ -570,6 +599,7 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, adaptExt->poolAllocationSize); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p\n", adaptExt->pmsg_affinity); +#endif if (!adaptExt->dump_mode && (adaptExt->num_queues > 1) && (adaptExt->pmsg_affinity == NULL)) { adaptExt->num_affinity = adaptExt->num_queues + 3; @@ -577,27 +607,36 @@ VioScsiFindAdapter(IN PVOID DeviceExtension, sizeof(GROUP_AFFINITY) * (ULONGLONG)adaptExt->num_affinity, VIOSCSI_POOL_TAG, (PVOID *)&adaptExt->pmsg_affinity); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " pmsg_affinity = %p Status = %lu\n", adaptExt->pmsg_affinity, Status); +#endif } adaptExt->fw_ver = '0'; +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return SP_RETURN_FOUND; } BOOLEAN -VioScsiPassiveInitializeRoutine(IN PVOID DeviceExtension) +VioScsiPassiveDpcInitializeRoutine(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + ULONG index; PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - ENTER_FN(); for (index = 0; index < adaptExt->num_queues; ++index) { StorPortInitializeDpc(DeviceExtension, &adaptExt->dpc[index], VioScsiCompleteDpcRoutine); } adaptExt->dpc_ok = TRUE; +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } @@ -608,7 +647,9 @@ static BOOLEAN InitializeVirtualQueues(PADAPTER_EXTENSION adaptExt, ULONG numQue status = virtio_find_queues(&adaptExt->vdev, numQueues, adaptExt->vq); if (!NT_SUCCESS(status)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " FAILED with status 0x%x\n", status); +#endif return FALSE; } @@ -628,13 +669,19 @@ VioScsiPoolAlloc(IN PVOID DeviceExtension, IN SIZE_T size) RtlZeroMemory(ptr, size); return ptr; } +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Out of memory %Id \n", size); +#endif return NULL; } BOOLEAN VioScsiHwInitialize(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension; ULONG i; ULONG index; @@ -643,65 +690,235 @@ VioScsiHwInitialize(IN PVOID DeviceExtension) 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; + if ((!adaptExt->dump_mode) && (adaptExt->num_queues > 1) && (adaptExt->perfFlags == 0)) + { + perfData.Version = STOR_PERF_VERSION; + perfData.Size = sizeof(PERF_CONFIGURATION_DATA); + + status = StorPortInitializePerfOpts(DeviceExtension, TRUE, &perfData); + + if (status == STOR_STATUS_SUCCESS) + { +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, + " PERF: GET PerfOpts : Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, " + "FirstRedirectionMessageNumber = %d, LastRedirectionMessageNumber = %d, DeviceNode = %d\n", + perfData.Version, + perfData.Flags, + perfData.ConcurrentChannels, + perfData.FirstRedirectionMessageNumber, + perfData.LastRedirectionMessageNumber, + perfData.DeviceNode); +#endif + } + else + { + // FIXME... + // should we not return here with ERROR, or continue with WARNING +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_WARNING, + " PERF: StorPortInitializePerfOpts GET failed with status = 0x%x\n", + status); + // EXIT_FN(); +#endif + // return FALSE; + } + + if ((status == STOR_STATUS_SUCCESS) && (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION))) + { + adaptExt->perfFlags = STOR_PERF_DPC_REDIRECTION; + 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_INTERRUPT_MESSAGE_RANGES)) + { + adaptExt->perfFlags |= STOR_PERF_INTERRUPT_MESSAGE_RANGES; + perfData.FirstRedirectionMessageNumber = VIRTIO_SCSI_REQUEST_QUEUE_0 + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET; + perfData.LastRedirectionMessageNumber = perfData.FirstRedirectionMessageNumber + + perfData.ConcurrentChannels - 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_affinity)); + adaptExt->perfFlags |= STOR_PERF_ADV_CONFIG_LOCALITY; + perfData.MessageTargets = adaptExt->pmsg_affinity; + } + 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; + } + perfData.Flags = adaptExt->perfFlags; +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " PERF: SET PerfOpts : Version = 0x%x, Flags = 0x%x, ConcurrentChannels = %d, " + "FirstRedirectionMessageNumber = %d, LastRedirectionMessageNumber = %d, DeviceNode = %d\n", + perfData.Version, + perfData.Flags, + perfData.ConcurrentChannels, + perfData.FirstRedirectionMessageNumber, + perfData.LastRedirectionMessageNumber, + perfData.DeviceNode); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_DPC_REDIRECTION flag is : %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_CONCURRENT_CHANNELS flag is: %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_CONCURRENT_CHANNELS)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_INTERRUPT_MESSAGE_RANGES flag is : %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_INTERRUPT_MESSAGE_RANGES)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_ADV_CONFIG_LOCALITY flag is: %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_ADV_CONFIG_LOCALITY)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO flag is: %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_DPC_REDIRECTION_CURRENT_CPU flag is : %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_DPC_REDIRECTION_CURRENT_CPU)) ? "ON" : "OFF"); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " PERF: STOR_PERF_NO_SGL flag is : %s \n", + (CHECKFLAG(perfData.Flags, STOR_PERF_NO_SGL)) ? "ON" : "OFF"); +#endif + + status = StorPortInitializePerfOpts(DeviceExtension, FALSE, &perfData); + + if (status != STOR_STATUS_SUCCESS) + { + adaptExt->perfFlags = 0; +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_ERROR, + " PERF: StorPortInitializePerfOpts SET failed with status = 0x%x\n", + status); +#endif + } + for (index = 0; index < adaptExt->num_affinity; ++index) + { + GROUP_AFFINITY vector_affinity = adaptExt->pmsg_affinity[index]; +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_MSIX_CPU_AFFINITY, + " PERF: MSI-X Vector %lu CPU Affinity : KAFFINITY Mask = %I64d, CPU Group = %lu \n", + index, + vector_affinity.Mask, + vector_affinity.Group); +#endif + } + } + } + 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, " MessageAddress = %I64x\n\n", msi_info.MessageAddress.QuadPart); +#if !defined(RUN_UNCHECKED) + if (adaptExt->num_queues > 1) + { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " MSI-X Vector [MessageId] = %lu, MessageAddress = 0x%I64x, MessageData = %lu, " + "InterruptVector = %lu, InterruptLevel = %lu, InterruptMode = %s, CPU Affinity : Mask = " + "%I64d, Group = %lu \n", + msi_info.MessageId, + msi_info.MessageAddress.QuadPart, + msi_info.MessageData, + msi_info.InterruptVector, + msi_info.InterruptLevel, + msi_info.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched", + adaptExt->pmsg_affinity[msi_info.MessageId].Mask, + adaptExt->pmsg_affinity[msi_info.MessageId].Group); + } + else + { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " MSI-X Vector [MessageId] = %lu, MessageAddress = 0x%I64x, MessageData = %lu, " + "InterruptVector = %lu, InterruptLevel = %lu, InterruptMode = %s \n", + msi_info.MessageId, + msi_info.MessageAddress.QuadPart, + msi_info.MessageData, + msi_info.InterruptVector, + msi_info.InterruptLevel, + msi_info.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); + } +#endif ++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 + VIRTIO_SCSI_REQUEST_QUEUE_0 + + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET) > 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->msix_vectors >= + adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0 + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET) { /* 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 { /* 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)) - { - return FALSE; - } } else { /* initialize queues with no MSI interrupts */ adaptExt->msix_enabled = FALSE; - if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) - { - return FALSE; - } } + if (!InitializeVirtualQueues(adaptExt, adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) + { +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, " !!! - Failed to initialize the Virtual Queues - !!!\n"); + EXIT_FN(); +#endif + return FALSE; + } + +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, + " VirtIO Request Queues : %d, MSI-X Enabled : %s, MSI-X Use ONE Vector : %s, MSI-X Vectors " + "[msix_vectors] : %d \n", + adaptExt->num_queues, + (adaptExt->msix_enabled) ? "YES" : "NO", + (adaptExt->msix_one_vector) ? "YES" : "NO", + adaptExt->msix_vectors); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " MSI-X Vector %lu | StorPort exclusive control \n", + (VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET - 1)); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " MSI-X Vector %lu | VIRTIO Control Queue \n", + (VIRTIO_SCSI_CONTROL_QUEUE + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET)); + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " MSI-X Vector %lu | VIRTIO Events Queue \n", + (VIRTIO_SCSI_EVENTS_QUEUE + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET)); +#endif for (index = 0; index < adaptExt->num_queues; ++index) { element = &adaptExt->processing_srbs[index]; InitializeListHead(&element->srb_list); element->srb_cnt = 0; +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " MSI-X Vector %lu | VIRTIO Request Queue %lu (index %lu) \n", + (index + VIRTIO_SCSI_REQUEST_QUEUE_0 + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET), + (index + 1), + index); +#endif } if (!adaptExt->dump_mode) @@ -715,101 +932,37 @@ VioScsiHwInitialize(IN PVOID DeviceExtension) 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)) - { - PVirtIOSCSIEventNode events = adaptExt->events; - 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 (CHECKBIT(adaptExt->features, VIRTIO_SCSI_F_HOTPLUG)) { - 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))) + PVirtIOSCSIEventNode events = adaptExt->events; + for (i = 0; i < 8; i++) { - adaptExt->perfFlags = STOR_PERF_DPC_REDIRECTION; - if (CHECKFLAG(perfData.Flags, STOR_PERF_INTERRUPT_MESSAGE_RANGES)) + if (!KickEvent(DeviceExtension, (PVOID)(&events[i]))) { - adaptExt->perfFlags |= STOR_PERF_INTERRUPT_MESSAGE_RANGES; - perfData.FirstRedirectionMessageNumber = 3; - 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)); - adaptExt->perfFlags |= STOR_PERF_ADV_CONFIG_LOCALITY; - perfData.MessageTargets = adaptExt->pmsg_affinity; - 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_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); - status = StorPortInitializePerfOpts(DeviceExtension, FALSE, &perfData); - if (status != STOR_STATUS_SUCCESS) - { - adaptExt->perfFlags = 0; - RhelDbgPrint(TRACE_LEVEL_ERROR, - " StorPortInitializePerfOpts set failed with status = 0x%x\n", - status); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot add event %d\n", i); +#endif } } - 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, VioScsiPassiveDpcInitializeRoutine)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " StorPortEnablePassiveInitialization FAILED\n"); + EXIT_FN(); +#endif return FALSE; } } virtio_device_ready(&adaptExt->vdev); + +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } @@ -831,8 +984,10 @@ VioScsiHwReinitialize(IN PVOID DeviceExtension) BOOLEAN VioScsiStartIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { - ENTER_FN_SRB(); - if (PreProcessRequest(DeviceExtension, (PSRB_TYPE)Srb)) +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_SRB_HP(); +#endif + if (PreProcessRequest(DeviceExtension, (PSRB_TYPE)Srb, "PreProcessRequest")) { CompleteRequest(DeviceExtension, (PSRB_TYPE)Srb); } @@ -840,13 +995,20 @@ VioScsiStartIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) { SendSRB(DeviceExtension, (PSRB_TYPE)Srb); } - EXIT_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_FN_SRB_HP(); +#endif return TRUE; } -VOID HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd) +VOID FORCEINLINE HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd, IN PVOID InlineFuncName) { PSRB_TYPE Srb = (PSRB_TYPE)(cmd->srb); + +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_INL_FN_SRB_HP(); +#endif + PSRB_EXTENSION srbExt = SRB_EXTENSION(Srb); VirtIOSCSICmdResp *resp = &cmd->resp.cmd; UCHAR senseInfoBufferLength = 0; @@ -854,55 +1016,87 @@ VOID HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd) UCHAR srbStatus = SRB_STATUS_SUCCESS; ULONG srbDataTransferLen = SRB_DATA_TRANSFER_LENGTH(Srb); - ENTER_FN(); - - LOG_SRB_INFO(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + LOG_SRB_INFO_FROM_INLFN_HP(); +#endif 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; +#if !defined(RUN_UNCHECKED) + if (srbStatus == SRB_STATUS_SUCCESS) + { +#if !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_OK : SRB_STATUS_SUCCESS\n"); +#endif + } + else + { + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_OK : SRB_STATUS_ERROR\n"); + } +#endif break; case VIRTIO_SCSI_S_UNDERRUN: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_UNDERRUN\n"); +#endif srbStatus = SRB_STATUS_DATA_OVERRUN; break; case VIRTIO_SCSI_S_ABORTED: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_ABORTED\n"); +#endif srbStatus = SRB_STATUS_ABORTED; break; case VIRTIO_SCSI_S_BAD_TARGET: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BAD_TARGET\n"); +#endif srbStatus = SRB_STATUS_INVALID_TARGET_ID; break; case VIRTIO_SCSI_S_RESET: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_RESET\n"); +#endif srbStatus = SRB_STATUS_BUS_RESET; break; case VIRTIO_SCSI_S_BUSY: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_BUSY\n"); +#endif srbStatus = SRB_STATUS_BUSY; break; case VIRTIO_SCSI_S_TRANSPORT_FAILURE: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TRANSPORT_FAILURE\n"); +#endif srbStatus = SRB_STATUS_ERROR; break; case VIRTIO_SCSI_S_TARGET_FAILURE: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_TARGET_FAILURE\n"); +#endif srbStatus = SRB_STATUS_ERROR; break; case VIRTIO_SCSI_S_NEXUS_FAILURE: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_NEXUS_FAILURE\n"); +#endif srbStatus = SRB_STATUS_ERROR; break; case VIRTIO_SCSI_S_FAILURE: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VIRTIO_SCSI_S_FAILURE\n"); +#endif srbStatus = SRB_STATUS_ERROR; break; default: srbStatus = SRB_STATUS_ERROR; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unknown response %d\n", resp->response); +#endif break; } if (srbStatus == SRB_STATUS_SUCCESS && resp->resid && srbDataTransferLen > resp->resid) @@ -928,10 +1122,13 @@ VOID HandleResponse(IN PVOID DeviceExtension, IN PVirtIOSCSICmd cmd) SRB_SET_DATA_TRANSFER_LENGTH(Srb, srbExt->Xfer); srbStatus = SRB_STATUS_DATA_OVERRUN; } + SRB_SET_SRB_STATUS(Srb, srbStatus); CompleteRequest(DeviceExtension, Srb); - EXIT_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_INL_FN_HP(); +#endif } BOOLEAN @@ -975,7 +1172,9 @@ VioScsiInterrupt(IN PVOID DeviceExtension) case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " unknown response %d\n", resp->response); +#endif ASSERT(0); break; } @@ -998,7 +1197,9 @@ VioScsiInterrupt(IN PVOID DeviceExtension) ParamChange(DeviceExtension, evt); break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); +#endif break; } SynchronizedKickEventRoutine(DeviceExtension, evtNode); @@ -1017,7 +1218,9 @@ VioScsiInterrupt(IN PVOID DeviceExtension) } } +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " isInterruptServiced = %d\n", isInterruptServiced); +#endif return isInterruptServiced; } @@ -1032,11 +1235,13 @@ static BOOLEAN VioScsiMSInterruptWorker(IN PVOID DeviceExtension, IN ULONG Messa adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - RhelDbgPrint(TRACE_LEVEL_VERBOSE, " MessageID 0x%x\n", MessageID); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_VERBOSE, " MessageID 0x%x\n", MessageID); +#endif if (MessageID >= QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)) { - DispatchQueue(DeviceExtension, MessageID); + DispatchQueue(DeviceExtension, MessageID, "DispatchQueue"); return TRUE; } if (MessageID == 0) @@ -1059,7 +1264,9 @@ static BOOLEAN VioScsiMSInterruptWorker(IN PVOID DeviceExtension, IN ULONG Messa case VIRTIO_SCSI_S_FUNCTION_SUCCEEDED: break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unknown response %d\n", resp->response); +#endif ASSERT(0); break; } @@ -1086,7 +1293,9 @@ static BOOLEAN VioScsiMSInterruptWorker(IN PVOID DeviceExtension, IN ULONG Messa ParamChange(DeviceExtension, evt); break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupport virtio scsi event %x\n", evt->event); +#endif break; } SynchronizedKickEventRoutine(DeviceExtension, evtNode); @@ -1136,6 +1345,10 @@ VioScsiResetBus(IN PVOID DeviceExtension, IN ULONG PathId) SCSI_ADAPTER_CONTROL_STATUS VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE ControlType, IN PVOID Parameters) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PSCSI_SUPPORTED_CONTROL_TYPE_LIST ControlTypeList; ULONG AdjustedMaxControlType; ULONG Index; @@ -1143,7 +1356,6 @@ VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE Con SCSI_ADAPTER_CONTROL_STATUS status = ScsiAdapterControlUnsuccessful; BOOLEAN SupportedControlTypes[17] = {0}; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; SupportedControlTypes[0] = 1; // ScsiQuerySupportedControlTypes SupportedControlTypes[1] = 1; // ScsiStopAdapter @@ -1152,10 +1364,11 @@ VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE Con switch (ControlType) { - case ScsiQuerySupportedControlTypes: { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiQuerySupportedControlTypes\n"); +#endif ControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters; AdjustedMaxControlType = (ControlTypeList->MaxControlType < 5) ? ControlTypeList->MaxControlType : 5; for (Index = 0; Index < AdjustedMaxControlType; Index++) @@ -1167,7 +1380,9 @@ VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE Con } case ScsiStopAdapter: { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " ScsiStopAdapter\n"); +#endif ShutDown(DeviceExtension); if (adaptExt->pmsg_affinity != NULL) { @@ -1180,11 +1395,15 @@ VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE Con } case ScsiRestartAdapter: { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiRestartAdapter\n"); +#endif ShutDown(DeviceExtension); if (!VioScsiHwReinitialize(DeviceExtension)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Cannot reinitialize HW\n"); +#endif break; } status = ScsiAdapterControlSuccess; @@ -1192,23 +1411,33 @@ VioScsiAdapterControl(IN PVOID DeviceExtension, IN SCSI_ADAPTER_CONTROL_TYPE Con } case ScsiAdapterSurpriseRemoval: { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " ScsiAdapterSurpriseRemoval\n"); +#endif adaptExt->bRemoved = TRUE; status = ScsiAdapterControlSuccess; break; } default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported ControlType %d\n", ControlType); +#endif break; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return status; } SCSI_UNIT_CONTROL_STATUS VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlType, IN PVOID Parameters) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PSCSI_SUPPORTED_CONTROL_TYPE_LIST ControlTypeList; ULONG AdjustedMaxControlType; ULONG index; @@ -1216,14 +1445,15 @@ VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlTy SCSI_UNIT_CONTROL_STATUS Status = ScsiUnitControlUnsuccessful; BOOLEAN SupportedControlTypes[11] = {0}; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; SupportedControlTypes[0] = 1; // ScsiQuerySupportedControlTypes SupportedControlTypes[2] = 1; // ScsiUnitStart SupportedControlTypes[9] = 1; // ScsiUnitRemove SupportedControlTypes[10] = 1; // ScsiUnitSurpriseRemoval +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Unit Control Type %d\n", ControlType); +#endif switch (ControlType) { case ScsiQuerySupportedControlTypes: @@ -1263,11 +1493,13 @@ VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlTy { SRB_SET_SRB_STATUS(currSrb, SRB_STATUS_NO_DEVICE); CompleteRequest(DeviceExtension, (PSRB_TYPE)currSrb); +#if !defined(RUN_UNCHECKED) 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)); +#endif element->srb_cnt--; } } @@ -1277,11 +1509,15 @@ VioScsiUnitControl(IN PVOID DeviceExtension, IN SCSI_UNIT_CONTROL_TYPE ControlTy Status = ScsiUnitControlSuccess; break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported Unit ControlType %d\n", ControlType); +#endif break; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return Status; } @@ -1300,7 +1536,10 @@ VioScsiBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) UCHAR TargetId; UCHAR Lun; - ENTER_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_SRB_HP(); +#endif + cdb = SRB_CDB(Srb); srbExt = SRB_EXTENSION(Srb); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; @@ -1315,7 +1554,9 @@ VioScsiBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) return FALSE; } - LOG_SRB_INFO(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + LOG_SRB_INFO_HP(); +#endif RtlZeroMemory(srbExt, sizeof(*srbExt)); srbExt->Srb = Srb; @@ -1389,22 +1630,28 @@ VioScsiBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, "SRB 0x%p StorPortQueryPerformanceCounter failed with status 0x%lx\n", Srb, status); +#endif } } - EXIT_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_FN_SRB_HP(); +#endif return TRUE; } -VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId) +VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId, IN PVOID InlineFuncName) { - PADAPTER_EXTENSION adaptExt; - ENTER_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_INL_FN_HP(); +#endif + PADAPTER_EXTENSION adaptExt; adaptExt = (PADAPTER_EXTENSION)DeviceExtension; if (!adaptExt->dump_mode && adaptExt->dpc_ok) @@ -1414,11 +1661,15 @@ VOID FORCEINLINE DispatchQueue(IN PVOID DeviceExtension, IN ULONG MessageId) &adaptExt->dpc[MessageId - QUEUE_TO_MESSAGE(VIRTIO_SCSI_REQUEST_QUEUE_0)], ULongToPtr(MessageId), ULongToPtr(MessageId)); - EXIT_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_INL_FN_HP(); +#endif return; } ProcessBuffer(DeviceExtension, MessageId, InterruptLock); - EXIT_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_INL_FN_HP(); +#endif } VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOCK LockMode) @@ -1435,12 +1686,16 @@ VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOC ULONG vq_req_idx; PVOID LockContext = NULL; // sanity check for LockMode = InterruptLock or StartIoLock - ENTER_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_HP(); +#endif if (QueueNumber >= (adaptExt->num_queues + VIRTIO_SCSI_REQUEST_QUEUE_0)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " Modulo assignment required for QueueNumber as it exceeds the number of virtqueues available.\n"); +#endif QueueNumber %= adaptExt->num_queues; } vq_req_idx = QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0; @@ -1483,24 +1738,29 @@ VOID ProcessBuffer(IN PVOID DeviceExtension, IN ULONG MessageId, IN STOR_SPINLOC } if (bFound) { - HandleResponse(DeviceExtension, cmd); + HandleResponse(DeviceExtension, cmd, "HandleResponse"); } } } while (!virtqueue_enable_cb(vq)); StorPortReleaseSpinLock(DeviceExtension, &LockHandle); - EXIT_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_FN_HP(); +#endif } VOID VioScsiCompleteDpcRoutine(IN PSTOR_DPC Dpc, IN PVOID Context, IN PVOID SystemArgument1, IN PVOID SystemArgument2) { ULONG MessageId; - - ENTER_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_HP(); +#endif MessageId = PtrToUlong(SystemArgument1); ProcessBuffer(Context, MessageId, DpcLock); - EXIT_FN(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_FN_HP(); +#endif } VOID CompletePendingRequestsOnReset(IN PVOID DeviceExtension) @@ -1523,7 +1783,9 @@ VOID CompletePendingRequestsOnReset(IN PVOID DeviceExtension) for (vq_req_idx = 0; vq_req_idx < adaptExt->num_queues; vq_req_idx++) { element = &adaptExt->processing_srbs[vq_req_idx]; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " queue %d cnt %d\n", vq_req_idx, element->srb_cnt); +#endif LockContext = &adaptExt->dpc[vq_req_idx]; StorPortAcquireSpinLock(DeviceExtension, DpcLock, LockContext, &LockHandle); while (!IsListEmpty(&element->srb_list)) @@ -1551,7 +1813,9 @@ VOID CompletePendingRequestsOnReset(IN PVOID DeviceExtension) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Reset is already in progress, doing nothing.\n"); +#endif } adaptExt->reset_in_progress = FALSE; } @@ -1559,13 +1823,16 @@ VOID CompletePendingRequestsOnReset(IN PVOID DeviceExtension) UCHAR VioScsiProcessPnP(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt; PSCSI_PNP_REQUEST_BLOCK pnpBlock; ULONG SrbPnPFlags; ULONG PnPAction; UCHAR SrbStatus; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; pnpBlock = (PSCSI_PNP_REQUEST_BLOCK)Srb; SrbStatus = SRB_STATUS_SUCCESS; @@ -1573,11 +1840,13 @@ VioScsiProcessPnP(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) switch (PnPAction) { case StorQueryCapabilities: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " StorQueryCapabilities on %d::%d::%d\n", SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb)); +#endif if (((SrbPnPFlags & SRB_PNP_FLAGS_ADAPTER_REQUEST) == 0) || (SRB_DATA_TRANSFER_LENGTH(Srb) >= sizeof(STOR_DEVICE_CAPABILITIES))) { @@ -1589,32 +1858,41 @@ VioScsiProcessPnP(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) break; case StorRemoveDevice: case StorSurpriseRemoval: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Adapter Removal happens on %d::%d::%d\n", SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb)); +#endif adaptExt->bRemoved = TRUE; break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Unsupported PnPAction SrbPnPFlags = %d, PnPAction = %d\n", SrbPnPFlags, PnPAction); +#endif SrbStatus = SRB_STATUS_INVALID_REQUEST; break; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return SrbStatus; } BOOLEAN FORCEINLINE -PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) +PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb, IN PVOID InlineFuncName) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_INL_FN_SRB_HP(); +#endif + PADAPTER_EXTENSION adaptExt; - ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; switch (SRB_FUNCTION(Srb)) @@ -1630,26 +1908,40 @@ PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) case SRB_FUNCTION_RESET_BUS: case SRB_FUNCTION_RESET_DEVICE: case SRB_FUNCTION_RESET_LOGICAL_UNIT: +#if !defined(RUN_UNCHECKED) 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); +#endif switch (adaptExt->action_on_reset) { case VioscsiResetCompleteRequests: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Completing all pending SRBs\n"); +#endif + // CompletePendingRequestsOnReset(DeviceExtension, DpcLock); CompletePendingRequestsOnReset(DeviceExtension); SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); +#if !defined(RUN_UNCHECKED) + EXIT_INL_FN_SRB(); +#endif return TRUE; case VioscsiResetDoNothing: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Doing nothing with all pending SRBs\n"); SRB_SET_SRB_STATUS(Srb, SRB_STATUS_SUCCESS); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Doing nothing with all pending SRBs\n"); + EXIT_INL_FN_SRB(); +#endif return TRUE; case VioscsiResetBugCheck: - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Let's bugcheck due to this reset event\n"); KeBugCheckEx(0xDEADDEAD, (ULONG_PTR)Srb, SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb)); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " Let's bugcheck due to this reset event\n"); + EXIT_INL_FN_SRB(); +#endif return TRUE; } case SRB_FUNCTION_WMI: @@ -1659,23 +1951,38 @@ PreProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) VioScsiIoControl(DeviceExtension, Srb); return TRUE; } - EXIT_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_INL_FN_SRB_HP(); +#endif return FALSE; } -VOID PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) +VOID FORCEINLINE PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb, IN PVOID InlineFuncName) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_INL_FN_SRB_HP(); +#endif + PCDB cdb = NULL; PADAPTER_EXTENSION adaptExt = NULL; PSRB_EXTENSION srbExt = NULL; - ENTER_FN_SRB(); + if (SRB_FUNCTION(Srb) != SRB_FUNCTION_EXECUTE_SCSI) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_VERBOSE, " Post-Processor detected this is NOT a SRB_FUNCTION_EXECUTE_SCSI.\n"); + EXIT_INL_FN_SRB_HP(); +#endif return; } cdb = SRB_CDB(Srb); if (!cdb) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_VERBOSE, + " Post-Processor detected this is NOT a Command Descriptor Block (CDB).\n"); + EXIT_INL_FN_SRB_HP(); +#endif return; } @@ -1687,6 +1994,10 @@ VOID PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) case SCSIOP_READ_CAPACITY16: break; case SCSIOP_INQUIRY: +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_VERBOSE, + " Post-Processor detected SCSIOP_INQUIRY. Saving and Patching Inquiry Data...\n"); +#endif VioScsiSaveInquiryData(DeviceExtension, Srb); VioScsiPatchInquiryData(DeviceExtension, Srb); if (!StorPortSetDeviceQueueDepth(DeviceExtension, @@ -1695,27 +2006,40 @@ VOID PostProcessRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) SRB_LUN(Srb), adaptExt->queue_depth)) { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " StorPortSetDeviceQueueDepth(%p, %x) failed.\n", DeviceExtension, adaptExt->queue_depth); +#endif } break; default: +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_VERBOSE, + " Post-Processor did NOT detect any CDB6GENERIC Operation Codes in the Command " + "Descriptor Block (CDB).\n"); +#endif break; } - EXIT_FN_SRB(); +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + EXIT_INL_FN_SRB_HP(); +#endif } VOID CompleteRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + ENTER_FN_SRB_HP(); +#endif + PADAPTER_EXTENSION adaptExt = NULL; PSRB_EXTENSION srbExt = NULL; - ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - PostProcessRequest(DeviceExtension, Srb); + PostProcessRequest(DeviceExtension, Srb, "PostProcessRequest"); +#if !defined(RUN_UNCHECKED) if (adaptExt->resp_time) { srbExt = SRB_EXTENSION(Srb); @@ -1767,8 +2091,13 @@ VOID CompleteRequest(IN PVOID DeviceExtension, IN PSRB_TYPE Srb) } } } +#endif StorPortNotification(RequestComplete, DeviceExtension, Srb); - EXIT_FN_SRB(); + +#if !defined(RUN_UNCHECKED) || !defined(RUN_COLD_PATH_ONLY) + RhelDbgPrintHotPath(TRACE_LEVEL_VERBOSE, " StorPort was notified the request is complete.\n"); + EXIT_FN_SRB_HP(); +#endif } VOID LogError(IN PVOID DeviceExtension, IN ULONG ErrorCode, IN ULONG UniqueId) @@ -1788,9 +2117,12 @@ VOID LogError(IN PVOID DeviceExtension, IN ULONG ErrorCode, IN ULONG UniqueId) VOID TransportReset(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + UCHAR TargetId = evt->lun[1]; UCHAR Lun = (evt->lun[2] << 8) | evt->lun[3]; - ENTER_FN(); switch (evt->reason) { @@ -1801,18 +2133,26 @@ VOID TransportReset(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) StorPortNotification(BusChangeDetected, DeviceExtension, 0); break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_VERBOSE, " <--> Unsupport virtio scsi event reason 0x%x\n", evt->reason); +#endif + break; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } VOID ParamChange(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + 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(); if (AdditionalSenseCode == SCSI_ADSENSE_PARAMETERS_CHANGED && (AdditionalSenseCodeQualifier == SPC3_SCSI_SENSEQ_PARAMETERS_CHANGED || @@ -1821,14 +2161,19 @@ VOID ParamChange(IN PVOID DeviceExtension, IN PVirtIOSCSIEvent evt) { StorPortNotification(BusChangeDetected, DeviceExtension, 0); } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } VOID VioScsiWmiInitialize(IN PVOID DeviceExtension) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt; PSCSI_WMILIB_CONTEXT WmiLibContext; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; WmiLibContext = (PSCSI_WMILIB_CONTEXT)(&(adaptExt->WmiLibContext)); @@ -1841,18 +2186,24 @@ VOID VioScsiWmiInitialize(IN PVOID DeviceExtension) WmiLibContext->SetWmiDataBlock = NULL; WmiLibContext->ExecuteWmiMethod = VioScsiExecuteWmiMethod; WmiLibContext->WmiFunctionControl = NULL; + +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } VOID VioScsiWmiSrb(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN_SRB(); +#endif + UCHAR status; SCSIWMI_REQUEST_CONTEXT requestContext = {0}; ULONG retSize; PADAPTER_EXTENSION adaptExt; PSRB_WMI_DATA pSrbWmi = SRB_WMI_DATA(Srb); - ENTER_FN_SRB(); adaptExt = (PADAPTER_EXTENSION)DeviceExtension; ASSERT(SRB_FUNCTION(Srb) == SRB_FUNCTION_WMI); @@ -1862,6 +2213,9 @@ VOID VioScsiWmiSrb(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) if (!pSrbWmi) { +#if !defined(RUN_UNCHECKED) + EXIT_FN_SRB(); +#endif return; } if (!(pSrbWmi->WMIFlags & SRB_WMI_FLAGS_ADAPTER_REQUEST)) @@ -1886,18 +2240,21 @@ VOID VioScsiWmiSrb(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) SRB_SET_DATA_TRANSFER_LENGTH(Srb, retSize); SRB_SET_SRB_STATUS(Srb, status); } - +#if !defined(RUN_UNCHECKED) EXIT_FN_SRB(); +#endif } VOID VioScsiIoControl(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN_SRB(); +#endif + PSRB_IO_CONTROL srbControl; PVOID srbDataBuffer = SRB_DATA_BUFFER(Srb); PADAPTER_EXTENSION adaptExt; - ENTER_FN_SRB(); - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; srbControl = (PSRB_IO_CONTROL)srbDataBuffer; @@ -1905,6 +2262,7 @@ VOID VioScsiIoControl(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { case IOCTL_SCSI_MINIPORT_NOT_QUORUM_CAPABLE: SRB_SET_SRB_STATUS(Srb, SRB_STATUS_ERROR); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> Signature = %02x %02x %02x %02x %02x %02x %02x %02x\n", srbControl->Signature[0], @@ -1916,17 +2274,24 @@ VOID VioScsiIoControl(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) srbControl->Signature[6], srbControl->Signature[7]); RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> IOCTL_SCSI_MINIPORT_NOT_QUORUM_CAPABLE\n"); +#endif break; case IOCTL_SCSI_MINIPORT_FIRMWARE: FirmwareRequest(DeviceExtension, Srb); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> IOCTL_SCSI_MINIPORT_FIRMWARE\n"); +#endif break; default: SRB_SET_SRB_STATUS(Srb, SRB_STATUS_INVALID_REQUEST); - RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> Unsupport control code 0x%x\n", srbControl->ControlCode); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_INFORMATION, " <--> Unsupported control code 0x%x\n", srbControl->ControlCode); +#endif break; } +#if !defined(RUN_UNCHECKED) EXIT_FN_SRB(); +#endif } UCHAR @@ -1934,11 +2299,14 @@ ParseIdentificationDescr(IN PVOID DeviceExtension, IN PVPD_IDENTIFICATION_DESCRIPTOR IdentificationDescr, IN UCHAR PageLength) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + PADAPTER_EXTENSION adaptExt; UCHAR CodeSet = 0; UCHAR IdentifierType = 0; adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - ENTER_FN(); if (IdentificationDescr) { CodeSet = IdentificationDescr->CodeSet; //(UCHAR)(((PCHAR)IdentificationDescr)[0]); @@ -1960,7 +2328,9 @@ ParseIdentificationDescr(IN PVOID DeviceExtension, { StorPortMoveMemory(adaptExt->ser_num, IdentificationDescr->Identifier, ln); adaptExt->ser_num[ln] = '\0'; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); +#endif } } } @@ -1972,7 +2342,9 @@ ParseIdentificationDescr(IN PVOID DeviceExtension, (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) { REVERSE_BYTES_QUAD(&adaptExt->wwn, IdentificationDescr->Identifier); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " wwn %llu\n", (ULONGLONG)adaptExt->wwn); +#endif } } break; @@ -1982,7 +2354,9 @@ ParseIdentificationDescr(IN PVOID DeviceExtension, (IdentificationDescr->IdentifierLength == sizeof(ULONGLONG))) { REVERSE_BYTES_QUAD(&adaptExt->port_wwn, IdentificationDescr->Identifier); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port wwn %llu\n", (ULONGLONG)adaptExt->port_wwn); +#endif } } break; @@ -1992,31 +2366,46 @@ ParseIdentificationDescr(IN PVOID DeviceExtension, (IdentificationDescr->IdentifierLength == sizeof(ULONG))) { REVERSE_BYTES(&adaptExt->port_idx, IdentificationDescr->Identifier); +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " port index %lu\n", (ULONG)adaptExt->port_idx); +#endif } } break; default: +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " Unsupported IdentifierType = %x!\n", IdentifierType); +#endif break; } +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return IdentificationDescr->IdentifierLength; } +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return 0; } VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN_SRB(); +#endif + PVOID dataBuffer; PADAPTER_EXTENSION adaptExt; PCDB cdb; ULONG dataLen; UCHAR SrbStatus = SRB_STATUS_SUCCESS; - ENTER_FN_SRB(); if (!Srb) { +#if !defined(RUN_UNCHECKED) + EXIT_FN_SRB(); +#endif return; } @@ -2024,12 +2413,18 @@ VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) if (!cdb) { +#if !defined(RUN_UNCHECKED) + EXIT_FN_SRB(); +#endif return; } SRB_GET_SCSI_STATUS(Srb, SrbStatus); if (SrbStatus == SRB_STATUS_ERROR) { +#if !defined(RUN_UNCHECKED) + EXIT_FN_SRB(); +#endif return; } @@ -2045,9 +2440,11 @@ VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { PVPD_SERIAL_NUMBER_PAGE SerialPage; SerialPage = (PVPD_SERIAL_NUMBER_PAGE)dataBuffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " VPD_SERIAL_NUMBER PageLength = %d\n", SerialPage->PageLength); +#endif if (SerialPage->PageLength > 0 && adaptExt->ser_num == NULL) { int ln = min(64, SerialPage->PageLength); @@ -2059,7 +2456,9 @@ VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { StorPortMoveMemory(adaptExt->ser_num, SerialPage->SerialNumber, ln); adaptExt->ser_num[ln] = '\0'; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " serial number %s\n", adaptExt->ser_num); +#endif } } } @@ -2104,17 +2503,22 @@ VOID VioScsiSaveInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) sizeof(InquiryData->ProductRevisionLevel)); } } +#if !defined(RUN_UNCHECKED) EXIT_FN_SRB(); +#endif } VOID VioScsiPatchInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) { +#if !defined(RUN_UNCHECKED) + ENTER_FN_SRB(); +#endif + PVOID dataBuffer; PADAPTER_EXTENSION adaptExt; PCDB cdb; ULONG dataLen; UCHAR SrbStatus = SRB_STATUS_SUCCESS; - ENTER_FN_SRB(); if (!Srb) { @@ -2178,7 +2582,9 @@ VOID VioScsiPatchInquiryData(IN PVOID DeviceExtension, IN OUT PSRB_TYPE Srb) break; } } +#if !defined(RUN_UNCHECKED) EXIT_FN_SRB(); +#endif } BOOLEAN @@ -2191,11 +2597,14 @@ VioScsiQueryWmiDataBlock(IN PVOID Context, IN ULONG OutBufferSize, OUT PUCHAR Buffer) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + ULONG size = 0; UCHAR status = SRB_STATUS_SUCCESS; PADAPTER_EXTENSION adaptExt; - ENTER_FN(); adaptExt = (PADAPTER_EXTENSION)Context; UNREFERENCED_PARAMETER(InstanceIndex); @@ -2219,7 +2628,9 @@ VioScsiQueryWmiDataBlock(IN PVOID Context, 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"); +#if !defined(RUN_UNCHECKED) + RhelDbgPrint(TRACE_LEVEL_WARNING, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX\n"); +#endif size = sizeof(MS_SM_AdapterInformationQuery); if (OutBufferSize < size) { @@ -2267,10 +2678,12 @@ VioScsiQueryWmiDataBlock(IN PVOID Context, if (OutBufferSize < size) { status = SRB_STATUS_DATA_OVERRUN; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_WARNING, " --> VIOSCSI_MS_PORT_INFORM_GUID_INDEX out buffer too small %d %d\n", OutBufferSize, size); +#endif break; } *InstanceLengthArray = size; @@ -2285,7 +2698,9 @@ VioScsiQueryWmiDataBlock(IN PVOID Context, ScsiPortWmiPostProcess(RequestContext, status, size); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return TRUE; } @@ -2299,24 +2714,31 @@ VioScsiExecuteWmiMethod(IN PVOID Context, IN ULONG OutBufferSize, IN OUT PUCHAR Buffer) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + 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: { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_SETUP_GUID_INDEX ERROR\n"); +#endif } break; case VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX: { PMS_SM_AdapterInformationQuery pOutBfr = (PMS_SM_AdapterInformationQuery)Buffer; pOutBfr; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> VIOSCSI_MS_ADAPTER_INFORM_GUID_INDEX ERROR\n"); +#endif } break; case VIOSCSI_MS_PORT_INFORM_GUID_INDEX: @@ -2327,7 +2749,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, { PSM_GetPortType_IN pInBfr = (PSM_GetPortType_IN)Buffer; PSM_GetPortType_OUT pOutBfr = (PSM_GetPortType_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortType\n"); +#endif size = SM_GetPortType_OUT_SIZE; if (OutBufferSize < size) { @@ -2348,7 +2772,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, PSM_GetAdapterPortAttributes_IN pInBfr = (PSM_GetAdapterPortAttributes_IN)Buffer; PSM_GetAdapterPortAttributes_OUT pOutBfr = (PSM_GetAdapterPortAttributes_OUT)Buffer; PMS_SMHBA_FC_Port pPortSpecificAttributes = NULL; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetAdapterPortAttributes\n"); +#endif size = FIELD_OFFSET(SM_GetAdapterPortAttributes_OUT, PortAttributes) + FIELD_OFFSET(MS_SMHBA_PORTATTRIBUTES, PortSpecificAttributes) + sizeof(MS_SMHBA_FC_Port); @@ -2391,7 +2817,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, { PSM_GetDiscoveredPortAttributes_IN pInBfr = (PSM_GetDiscoveredPortAttributes_IN)Buffer; PSM_GetDiscoveredPortAttributes_OUT pOutBfr = (PSM_GetDiscoveredPortAttributes_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetDiscoveredPortAttributes\n"); +#endif size = SM_GetDiscoveredPortAttributes_OUT_SIZE; if (OutBufferSize < size) { @@ -2415,7 +2843,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, { PSM_GetPortAttributesByWWN_IN pInBfr = (PSM_GetPortAttributesByWWN_IN)Buffer; PSM_GetPortAttributesByWWN_OUT pOutBfr = (PSM_GetPortAttributesByWWN_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortAttributesByWWN\n"); +#endif size = SM_GetPortAttributesByWWN_OUT_SIZE; if (OutBufferSize < size) { @@ -2433,15 +2863,19 @@ VioScsiExecuteWmiMethod(IN PVOID Context, sizeof(pOutBfr->PortAttributes.OSDeviceName)); pOutBfr->PortAttributes.PortState = HBA_PORTSTATE_ONLINE; pOutBfr->PortAttributes.PortType = HBA_PORTTYPE_SASDEVICE; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPortAttributesByWWN Not Implemented Yet\n"); +#endif } break; case SM_GetProtocolStatistics: { PSM_GetProtocolStatistics_IN pInBfr = (PSM_GetProtocolStatistics_IN)Buffer; PSM_GetProtocolStatistics_OUT pOutBfr = (PSM_GetProtocolStatistics_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetProtocolStatistics\n"); +#endif size = SM_GetProtocolStatistics_OUT_SIZE; if (OutBufferSize < size) { @@ -2459,7 +2893,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, { PSM_GetPhyStatistics_IN pInBfr = (PSM_GetPhyStatistics_IN)Buffer; PSM_GetPhyStatistics_OUT pOutBfr = (PSM_GetPhyStatistics_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetPhyStatistics\n"); +#endif size = FIELD_OFFSET(SM_GetPhyStatistics_OUT, PhyCounter) + sizeof(LONGLONG); if (OutBufferSize < size) { @@ -2478,7 +2914,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, PSM_GetFCPhyAttributes_IN pInBfr = (PSM_GetFCPhyAttributes_IN)Buffer; PSM_GetFCPhyAttributes_OUT pOutBfr = (PSM_GetFCPhyAttributes_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetFCPhyAttributes\n"); +#endif size = SM_GetFCPhyAttributes_OUT_SIZE; if (OutBufferSize < size) @@ -2498,7 +2936,9 @@ VioScsiExecuteWmiMethod(IN PVOID Context, { PSM_GetSASPhyAttributes_IN pInBfr = (PSM_GetSASPhyAttributes_IN)Buffer; PSM_GetSASPhyAttributes_OUT pOutBfr = (PSM_GetSASPhyAttributes_OUT)Buffer; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_INFORMATION, " --> SM_GetSASPhyAttributes\n"); +#endif size = SM_GetSASPhyAttributes_OUT_SIZE; if (OutBufferSize < size) { @@ -2518,41 +2958,56 @@ VioScsiExecuteWmiMethod(IN PVOID Context, break; default: status = SRB_STATUS_INVALID_REQUEST; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " --> ERROR Unknown MethodId = %lu\n", MethodId); +#endif break; } } break; default: status = SRB_STATUS_INVALID_REQUEST; +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_ERROR, " --> VioScsiExecuteWmiMethod Unsupported GuidIndex = %lu\n", GuidIndex); +#endif break; } ScsiPortWmiPostProcess(RequestContext, status, size); +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif return SRB_STATUS_SUCCESS; } UCHAR VioScsiQueryWmiRegInfo(IN PVOID Context, IN PSCSIWMI_REQUEST_CONTEXT RequestContext, OUT PWCHAR *MofResourceName) { +#if !defined(RUN_UNCHECKED) ENTER_FN(); +#endif + UNREFERENCED_PARAMETER(Context); UNREFERENCED_PARAMETER(RequestContext); *MofResourceName = VioScsiWmi_MofResourceName; + +#if !defined(RUN_UNCHECKED) + EXIT_FN(); +#endif return SRB_STATUS_SUCCESS; } VOID VioScsiReadExtendedData(IN PVOID Context, OUT PUCHAR Buffer) { +#if !defined(RUN_UNCHECKED) + ENTER_FN(); +#endif + UCHAR numberOfBytes = sizeof(VioScsiExtendedInfo) - 1; PADAPTER_EXTENSION adaptExt; PVioScsiExtendedInfo extInfo; - ENTER_FN(); - adaptExt = (PADAPTER_EXTENSION)Context; extInfo = (PVioScsiExtendedInfo)Buffer; @@ -2569,5 +3024,8 @@ VOID VioScsiReadExtendedData(IN PVOID Context, OUT PUCHAR Buffer) extInfo->CompletionDuringStartIo = CHECKFLAG(adaptExt->perfFlags, STOR_PERF_OPTIMIZE_FOR_COMPLETION_DURING_STARTIO); extInfo->PhysicalBreaks = adaptExt->max_physical_breaks; extInfo->ResponseTime = adaptExt->resp_time; + +#if !defined(RUN_UNCHECKED) EXIT_FN(); +#endif } diff --git a/vioscsi/vioscsi.h b/vioscsi/vioscsi.h index 50ce94d13..35dc77def 100644 --- a/vioscsi/vioscsi.h +++ b/vioscsi/vioscsi.h @@ -120,8 +120,9 @@ typedef struct VirtIOBufferDescriptor VIO_SG, *PVIO_SG; #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 VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET 1 +#define QUEUE_TO_MESSAGE(QueueId) ((QueueId) + VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET) +#define MESSAGE_TO_QUEUE(MessageId) ((MessageId)-VIRTIO_SCSI_MSI_CONTROL_Q_OFFSET) /* SCSI command request, followed by data-out */ #pragma pack(1) @@ -282,7 +283,7 @@ typedef struct virtio_bar PHYSICAL_ADDRESS BasePA; ULONG uLength; PVOID pBase; - BOOLEAN bPortSpace; + BOOLEAN bMemorySpace; } VIRTIO_BAR, *PVIRTIO_BAR; typedef enum ACTION_ON_RESET @@ -384,6 +385,63 @@ typedef struct } PCI_MSIX_CAPABILITY, *PPCI_MSIX_CAPABILITY; #endif +struct virtio_pci_cfg_cap +{ + struct virtio_pci_cap cap; + u8 pci_cfg_data[4]; /* Data for BAR access. */ +}; + +struct virtio_pci_isr_cap +{ + struct virtio_pci_cap cap; + u8 isr; +}; + +struct virtio_pci_device_cap +{ + struct virtio_pci_cap cap; + // Be careful not to touch anything hot here... +}; + +struct virtio_pci_common_cfg_cap +{ + struct virtio_pci_cap cap; + struct virtio_pci_common_cfg; +}; + +typedef struct virtio_pci_notify_cap VIRTIO_PCI_NOTIFY_CAP; +typedef VIRTIO_PCI_NOTIFY_CAP *PVIRTIO_PCI_NOTIFY_CAP; +typedef struct virtio_pci_cfg_cap VIRTIO_PCI_CFG_CAP; +typedef VIRTIO_PCI_CFG_CAP *PVIRTIO_PCI_CFG_CAP; +typedef struct virtio_pci_isr_cap VIRTIO_PCI_ISR_CAP; +typedef VIRTIO_PCI_ISR_CAP *PVIRTIO_PCI_ISR_CAP; +typedef struct virtio_pci_device_cap VIRTIO_PCI_DEVICE_CAP; +typedef VIRTIO_PCI_DEVICE_CAP *PVIRTIO_PCI_DEVICE_CAP; +typedef struct virtio_pci_common_cfg_cap VIRTIO_PCI_COMMON_CFG_CAP; +typedef VIRTIO_PCI_COMMON_CFG_CAP *PVIRTIO_PCI_COMMON_CFG_CAP; + +#define PCI_CAP_REDHAT_TYPE_OFFSET 3 +// #define REDHAT_CAP_RESOURCE_RESERVE 1 // <-- This clashes with VIRTIO_PCI_CAP_COMMON_CFG=1 per virtio_pci.h +#define REDHAT_CAP_RESOURCE_RESERVE 6 +#define REDHAT_CAP_RESOURCE_RESERVE_SIZE 32 + +#ifndef PCI_RHEL_QEMU_CAPABILITY +typedef struct +{ + PCI_CAPABILITIES_HEADER Header; + struct + { + u8 len; + u8 type; + u32 bus_res; + u64 io; + u32 mem; + u32 prefetchable_32; + u64 prefetchable_64; + } Reservation; +} PCI_RHEL_QEMU_CAPABILITY, *PPCI_RHEL_QEMU_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 diff --git a/vioscsi/vioscsi.vcxproj b/vioscsi/vioscsi.vcxproj index 05534f04d..b3b2d9ee8 100644 --- a/vioscsi/vioscsi.vcxproj +++ b/vioscsi/vioscsi.vcxproj @@ -33,6 +33,9 @@ 11.0 Win10 Release Win32 + true + WPPColdPathOnly + true Off @@ -127,6 +130,22 @@ $(IntDir);%(AdditionalIncludeDirectories) + + + %(PreprocessorDefinitions);RUN_UNCHECKED=1 + %(PreprocessorDefinitions);RUN_COLD_PATH_ONLY=1 + %(PreprocessorDefinitions);EVENT_TRACING=1 + %(PreprocessorDefinitions);NTDDI_VERSION=NTDDI_WINTHRESHOLD + + + + + %(PreprocessorDefinitions);RUN_UNCHECKED=1 + %(PreprocessorDefinitions);RUN_COLD_PATH_ONLY=1 + %(PreprocessorDefinitions);EVENT_TRACING=1 + %(PreprocessorDefinitions);NTDDI_VERSION=NTDDI_WIN10_CO + + @@ -165,28 +184,34 @@ $(ProjectDir)Install\$(TargetOS)\$(TargetArch)\$(TargetName).DVL.XML;$(ProjectDir)Install\$(TargetOS)\$(TargetArch)\$(TargetName).DVL-win10.XML - true - true + true + true {km-StorDefault.tpl}*.tmh {km-StorDefault.tpl}*.tmh - trace.h - trace.h + wpp_cold_path.h + wpp_all_paths.h + wpp_cold_path.h + wpp_all_paths.h - true - true + true + true {km-StorDefault.tpl}*.tmh {km-StorDefault.tpl}*.tmh - trace.h - trace.h + wpp_cold_path.h + wpp_all_paths.h + wpp_cold_path.h + wpp_all_paths.h - true - true + true + true {km-StorDefault.tpl}*.tmh {km-StorDefault.tpl}*.tmh - trace.h - trace.h + wpp_cold_path.h + wpp_all_paths.h + wpp_cold_path.h + wpp_all_paths.h diff --git a/vioscsi/virtio_pci.c b/vioscsi/virtio_pci.c index 25be1fa1d..f7336b8b1 100644 --- a/vioscsi/virtio_pci.c +++ b/vioscsi/virtio_pci.c @@ -38,7 +38,7 @@ #include "helper.h" #include "trace.h" -#if defined(EVENT_TRACING) +#if defined(EVENT_TRACING) && !defined(RUN_UNCHECKED) #include "virtio_pci.tmh" #endif @@ -134,7 +134,9 @@ static void *mem_alloc_contiguous_pages(void *context, size_t size) } else { +#if !defined(RUN_UNCHECKED) RhelDbgPrint(TRACE_LEVEL_FATAL, " Ran out of memory in alloc_pages_exact(%Id)\n", size); +#endif return NULL; } } @@ -212,7 +214,7 @@ static void *pci_map_address_range(void *context, int bar, size_t offset, size_t adaptExt->system_io_bus_number, pBar->BasePA, pBar->uLength, - !!pBar->bPortSpace); + !pBar->bMemorySpace); } if (pBar->pBase != NULL && offset < pBar->uLength) { diff --git a/vioscsi/wpp_all_paths.h b/vioscsi/wpp_all_paths.h new file mode 100644 index 000000000..d65cc304d --- /dev/null +++ b/vioscsi/wpp_all_paths.h @@ -0,0 +1,208 @@ +/* +* This file contains debug print support routines and globals. +* +* Copyright (c) 2012-2024 Red Hat, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met : +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and / or other materials provided with the distribution. +* 3. Neither the names of the copyright holders nor the names of their contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +*/ + +#ifndef ___WPPALLPATHS_H___ +#define ___WPPALLPATHS_H___ + +/* Custom RhelDbgPrint Entries */ + +// begin_wpp config +// USEPREFIX (RhelDbgPrint, "%!STDPREFIX! ####\t\t[%!FUNC!] DEBUG:"); +// FUNC RhelDbgPrint(LEVEL, MSG, ...); +// end_wpp + +// begin_wpp config +// USEPREFIX (RhelDbgPrintHotPath, "%!STDPREFIX! ####\t\t[%!FUNC!] DEBUG:"); +// FUNC RhelDbgPrintHotPath(LEVEL, MSG, ...); +// end_wpp + +#define WPP_Flags_LEVEL_LOGGER(Flags, level) WPP_LEVEL_LOGGER(Flags) +#define WPP_Flags_LEVEL_ENABLED(Flags, level) \ + (WPP_LEVEL_ENABLED(Flags) && \ + WPP_CONTROL(WPP_BIT_ ## Flags).Level >= level) + +/* Cold Path Entries */ + +// begin_wpp config +// USEPREFIX (ENTER_FN, "%!STDPREFIX! ===>\t\t[%!FUNC!] X---X Working X---X"); +// FUNC ENTER_FN{ENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_ENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN, "%!STDPREFIX! <===\t\t[%!FUNC!] Processing complete."); +// FUNC EXIT_FN{EXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_EXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_EXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] X---X Working X---X", InlineFuncName); +// FUNC ENTER_INL_FN{INLENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] Processing complete.", InlineFuncName); +// FUNC EXIT_INL_FN{INLEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_ERR, "%!STDPREFIX! >>>>\t\t[%!FUNC!] ERROR line %d", __LINE__); +// FUNC EXIT_ERR{ERRORLEVEL=TRACE_LEVEL_ERROR}(...); +// end_wpp +#define WPP_ERRORLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ERRORLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_FN_SRB(PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC ENTER_FN_SRB{SRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN_SRB(PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC EXIT_FN_SRB{SRBEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO(PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO{SRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_SRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC ENTER_INL_FN_SRB{INLSRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC EXIT_INL_FN_SRB{INLSRBEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO_FROM_INLFN(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!]:[%s] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", InlineFuncName, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO_FROM_INLFN{INLSRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_INLSRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +/* Hot Path Entries */ + +// begin_wpp config +// USEPREFIX (ENTER_FN_HP, "%!STDPREFIX! ===>\t\t[%!FUNC!] X---X Working X---X"); +// FUNC ENTER_FN_HP{ENTRYLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_ENTRYLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ENTRYLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN_HP, "%!STDPREFIX! <===\t\t[%!FUNC!] Processing complete."); +// FUNC EXIT_FN_HP{EXITLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_EXITLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_EXITLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN_HP(PVOID InlineFuncName), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] X---X Working X---X", InlineFuncName); +// FUNC ENTER_INL_FN_HP{INLENTRYLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLENTRYLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLENTRYLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN_HP(PVOID InlineFuncName), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] Processing complete.", InlineFuncName); +// FUNC EXIT_INL_FN_HP{INLEXITLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLEXITLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLEXITLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_ERR_HP, "%!STDPREFIX! >>>>\t\t[%!FUNC!] ERROR line %d", __LINE__); +// FUNC EXIT_ERR_HP{ERRORLEVELHP=TRACE_LEVEL_ERROR}(...); +// end_wpp +#define WPP_ERRORLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ERRORLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_FN_SRB_HP(PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC ENTER_FN_SRB_HP{SRBENTRYLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBENTRYLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBENTRYLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN_SRB_HP(PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC EXIT_FN_SRB_HP{SRBEXITLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBEXITLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBEXITLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO_HP(PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO_HP{SRBINFOLEVELHP=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_SRBINFOLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBINFOLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN_SRB_HP(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC ENTER_INL_FN_SRB_HP{INLSRBENTRYLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBENTRYLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBENTRYLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN_SRB_HP(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC EXIT_INL_FN_SRB_HP{INLSRBEXITLEVELHP=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBEXITLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBEXITLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO_FROM_INLFN_HP(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!]:[%s] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", InlineFuncName, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO_FROM_INLFN_HP{INLSRBINFOLEVELHP=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_INLSRBINFOLEVELHP_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBINFOLEVELHP_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +#endif //__WPPALLPATHS_H___ diff --git a/vioscsi/wpp_cold_path.h b/vioscsi/wpp_cold_path.h new file mode 100644 index 000000000..4c365d2d0 --- /dev/null +++ b/vioscsi/wpp_cold_path.h @@ -0,0 +1,123 @@ +/* +* This file contains debug print support routines and globals. +* +* Copyright (c) 2012-2024 Red Hat, Inc. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met : +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and / or other materials provided with the distribution. +* 3. Neither the names of the copyright holders nor the names of their contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +*/ + +#ifndef ___WPPCOLDPATH_H___ +#define ___WPPCOLDPATH_H___ + +/* Custom RhelDbgPrint Entries */ + +// begin_wpp config +// USEPREFIX (RhelDbgPrint, "%!STDPREFIX! ####\t\t[%!FUNC!] DEBUG:"); +// FUNC RhelDbgPrint(LEVEL, MSG, ...); +// end_wpp +#define WPP_Flags_LEVEL_LOGGER(Flags, level) WPP_LEVEL_LOGGER(Flags) +#define WPP_Flags_LEVEL_ENABLED(Flags, level) \ + (WPP_LEVEL_ENABLED(Flags) && \ + WPP_CONTROL(WPP_BIT_ ## Flags).Level >= level) + +/* Cold Path Entries */ + +// begin_wpp config +// USEPREFIX (ENTER_FN, "%!STDPREFIX! ===>\t\t[%!FUNC!] X---X Working X---X"); +// FUNC ENTER_FN{ENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_ENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN, "%!STDPREFIX! <===\t\t[%!FUNC!] Processing complete."); +// FUNC EXIT_FN{EXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_EXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_EXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] X---X Working X---X", InlineFuncName); +// FUNC ENTER_INL_FN{INLENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN(PVOID InlineFuncName), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] Processing complete.", InlineFuncName); +// FUNC EXIT_INL_FN{INLEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_ERR, "%!STDPREFIX! >>>>\t\t[%!FUNC!] ERROR line %d", __LINE__); +// FUNC EXIT_ERR{ERRORLEVEL=TRACE_LEVEL_ERROR}(...); +// end_wpp +#define WPP_ERRORLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_ERRORLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_FN_SRB(PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC ENTER_FN_SRB{SRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_FN_SRB(PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!] SRB 0x%p", Srb); +// FUNC EXIT_FN_SRB{SRBEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_SRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO(PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO{SRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_SRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_SRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (ENTER_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ===>\t\t[%!FUNC!]>>>[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC ENTER_INL_FN_SRB{INLSRBENTRYLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBENTRYLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBENTRYLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (EXIT_INL_FN_SRB(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! <===\t\t[%!FUNC!]<<<[%s] SRB 0x%p", InlineFuncName, Srb); +// FUNC EXIT_INL_FN_SRB{INLSRBEXITLEVEL=TRACE_ENTER_EXIT}(...); +// end_wpp +#define WPP_INLSRBEXITLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBEXITLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +// begin_wpp config +// USEPREFIX (LOG_SRB_INFO_FROM_INLFN(PVOID InlineFuncName, PVOID Srb), "%!STDPREFIX! ####\t\t[%!FUNC!]:[%s] Operation %s (0x%X), Target (%d::%d::%d), SRB 0x%p", InlineFuncName, DbgGetScsiOpStr(DbgGetScsiOp(Srb)), DbgGetScsiOp(Srb), SRB_PATH_ID(Srb), SRB_TARGET_ID(Srb), SRB_LUN(Srb), Srb); +// FUNC LOG_SRB_INFO_FROM_INLFN{INLSRBINFOLEVEL=TRACE_LEVEL_INFORMATION}(...); +// end_wpp +#define WPP_INLSRBINFOLEVEL_ENABLED(LEVEL) WPP_LEVEL_ENABLED(LEVEL) +#define WPP_INLSRBINFOLEVEL_LOGGER(LEVEL) WPP_LEVEL_LOGGER(LEVEL) + +#endif //__WPPCOLDPATH_H___