repository: /home/vadimr/shares/kvm-guest-drivers-windows branch: master commit f7f53b25857f20732b2eb69f127bb2d9bf369e4e Author: Vadim Rozenfeld<vrozenfe@xxxxxxxxxx> Date: Mon Sep 21 22:05:51 2009 +0300 [PATCH] viostor driver. Code cleanup. Getting rid of the Registry stuff. Signed-off-by: Vadim Rozenfeld<vrozenfe@xxxxxxxxxx> diff --git a/viostor/virtio_stor.c b/viostor/virtio_stor.c index d528ca9..e4acaa0 100644 --- a/viostor/virtio_stor.c +++ b/viostor/virtio_stor.c @@ -19,13 +19,6 @@ ULONG RhelDbgLevel = TRACE_LEVEL_NONE; BOOLEAN IsCrashDumpMode; -UNICODE_STRING ViostorServicePathUnicode = - RTL_CONSTANT_STRING(VIOSTOR_SERVICE_NAME); - -UNICODE_STRING MaxTransferSizeUnicode = - RTL_CONSTANT_STRING(MAX_TRANSFER_SIZE); - - BOOLEAN VirtIoHwInitialize( IN PVOID DeviceExtension @@ -98,12 +91,6 @@ CompleteSRB( IN PSCSI_REQUEST_BLOCK Srb ); -BOOLEAN -GetMaxTransferSize( - IN PVOID DeviceExtension - ); - - ULONG DriverEntry( IN PVOID DriverObject, @@ -292,32 +279,16 @@ VirtIoFindAdapter( vq_sz = (sizeof(struct vring_virtqueue) + sizeof(PVOID) * pageNum); if(adaptExt->dump_mode) { - adaptExt->breaks_number = 8; - adaptExt->queue_depth = 4; + ConfigInfo->NumberOfPhysicalBreaks = 8; } else { - if(GetMaxTransferSize(DeviceExtension)) { - adaptExt->breaks_number = (adaptExt->transfer_size / 4); - if(pageNum<= (adaptExt->breaks_number * 4)) { - adaptExt->breaks_number = (pageNum / 4); - } - adaptExt->breaks_number = min(adaptExt->breaks_number, 64); - adaptExt->breaks_number = max(adaptExt->breaks_number, 1); - adaptExt->queue_depth = (pageNum / adaptExt->breaks_number) - 1; - adaptExt->queue_depth = max(adaptExt->queue_depth, 1); - } else { - adaptExt->breaks_number = (pageNum / 2); - adaptExt->breaks_number = min(adaptExt->breaks_number, 8); - adaptExt->breaks_number = max(adaptExt->breaks_number, 1); - adaptExt->queue_depth = 4; - } + ConfigInfo->NumberOfPhysicalBreaks = 16; } - ConfigInfo->NumberOfPhysicalBreaks = adaptExt->breaks_number; - ConfigInfo->MaximumTransferLength - = ConfigInfo->NumberOfPhysicalBreaks * PAGE_SIZE; + ConfigInfo->MaximumTransferLength = ConfigInfo->NumberOfPhysicalBreaks * PAGE_SIZE; + adaptExt->queue_depth = pageNum / ConfigInfo->NumberOfPhysicalBreaks - 1; RhelDbgPrint(TRACE_LEVEL_INFORMATION, ("breaks_number = %x queue_depth = %x\n", - adaptExt->breaks_number, + ConfigInfo->NumberOfPhysicalBreaks, adaptExt->queue_depth)); ptr = (ULONG_PTR)ScsiPortGetUncachedExtension(DeviceExtension, ConfigInfo, (PAGE_SIZE + vr_sz + vq_sz)); @@ -1000,67 +971,3 @@ CompleteSRB( Srb->Lun); #endif } - -BOOLEAN -GetMaxTransferSize( - IN PVOID DeviceExtension - ) -{ - - NTSTATUS status; - OBJECT_ATTRIBUTES oa; - HANDLE keyHandle; - RHEL_ULONG_VALUE_PARTIAL_INFO ulongValueInfo; - ULONG ulongValueLength; - PADAPTER_EXTENSION adaptExt; - - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - - InitializeObjectAttributes(&oa, -&ViostorServicePathUnicode, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - - status = ZwOpenKey(&keyHandle, - KEY_READ, -&oa); - - if (!NT_SUCCESS(status)) { - RhelDbgPrint(TRACE_LEVEL_ERROR, - ("ReadRegistryValues: Failed to open services key! 0x%x\n", - status)); - return FALSE; - } - - status = ZwQueryValueKey(keyHandle, -&MaxTransferSizeUnicode, - KeyValuePartialInformation, -&ulongValueInfo, - sizeof(ulongValueInfo), -&ulongValueLength); - - if (!NT_SUCCESS(status)) { - RhelDbgPrint(TRACE_LEVEL_ERROR, - ("ReadRegistryValues: Failed to query %wZ value! 0x%x\n", -&MaxTransferSizeUnicode, status)); - ZwClose(keyHandle); - return FALSE; - } - - ASSERT(ulongValueInfo.PartialInfo.Type == REG_SZ); - - switch(*ulongValueInfo.PartialInfo.Data) { - case '0' : adaptExt->transfer_size = 64; break; - case '1' : adaptExt->transfer_size = 128; break; - case '2' : adaptExt->transfer_size = 256; break; - default : adaptExt->transfer_size = 64; break; - } - - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - ("%wZ set to %d\n",&MaxTransferSizeUnicode, - adaptExt->transfer_size)); - - ZwClose(keyHandle); - return TRUE; -} diff --git a/viostor/virtio_stor.h b/viostor/virtio_stor.h index 999405b..1c0dbb6 100644 --- a/viostor/virtio_stor.h +++ b/viostor/virtio_stor.h @@ -50,10 +50,6 @@ typedef struct VirtIOBufferDescriptor VIO_SG, *PVIO_SG; #define VIRTIO_MAX_SG (3+MAX_PHYS_SEGMENTS) #define IO_PORT_LENGTH 0x40 -#define VIOSTOR_SERVICE_NAME L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Viostor\\Parameters\\MaxTransferSize" -#define MAX_TRANSFER_SIZE L"default" - - #pragma pack(1) typedef struct virtio_blk_config { /* The capacity (in 512-byte sectors). */ @@ -94,19 +90,12 @@ typedef struct virtio_blk_req { VIO_SG sg[VIRTIO_MAX_SG]; }blk_req, *pblk_req; -typedef struct _RHEL_ULONG_VALUE_PARTIAL_INFO { - KEY_VALUE_PARTIAL_INFORMATION PartialInfo; - UCHAR Buffer[8]; -}RHEL_ULONG_VALUE_PARTIAL_INFO, *PRHEL_ULONG_VALUE_PARTIAL_INFO; - typedef struct _ADAPTER_EXTENSION { ULONG_PTR device_base; virtio_pci_vq_info pci_vq_info; vring_virtqueue* virtqueue; INQUIRYDATA inquiry_data; blk_config info; - ULONG breaks_number; - ULONG transfer_size; ULONG queue_depth; BOOLEAN dump_mode; }ADAPTER_EXTENSION, *PADAPTER_EXTENSION; diff --git a/viostor/wlh.inf b/viostor/wlh.inf index 8c64191..aae425a 100644 --- a/viostor/wlh.inf +++ b/viostor/wlh.inf @@ -85,14 +85,6 @@ HKR,,TypesSupported,%REG_DWORD%,7 [pnpsafe_pci_addreg] HKR, "Parameters\PnpInterface", "5", %REG_DWORD%, 0x00000001 HKR, "Parameters", "BusType", %REG_DWORD%, 0x00000001 -;HKR, "Parameters", "MaxTransferSize", %REG_DWORD%, 0x0000040 - -HKR, "Parameters\MaxTransferSize", ParamDesc, 0, "Maximum Transfer Size" -HKR, "Parameters\MaxTransferSize", type, 0, "enum" -HKR, "Parameters\MaxTransferSize", default, 0, "0" -HKR, "Parameters\MaxTransferSize\enum", "0", 0, "64 KB" -HKR, "Parameters\MaxTransferSize\enum", "1", 0, "128 KB" -HKR, "Parameters\MaxTransferSize\enum", "2", 0, "256 KB" [Strings] ; diff --git a/viostor/wnet.inf b/viostor/wnet.inf index 8c64191..aae425a 100644 --- a/viostor/wnet.inf +++ b/viostor/wnet.inf @@ -85,14 +85,6 @@ HKR,,TypesSupported,%REG_DWORD%,7 [pnpsafe_pci_addreg] HKR, "Parameters\PnpInterface", "5", %REG_DWORD%, 0x00000001 HKR, "Parameters", "BusType", %REG_DWORD%, 0x00000001 -;HKR, "Parameters", "MaxTransferSize", %REG_DWORD%, 0x0000040 - -HKR, "Parameters\MaxTransferSize", ParamDesc, 0, "Maximum Transfer Size" -HKR, "Parameters\MaxTransferSize", type, 0, "enum" -HKR, "Parameters\MaxTransferSize", default, 0, "0" -HKR, "Parameters\MaxTransferSize\enum", "0", 0, "64 KB" -HKR, "Parameters\MaxTransferSize\enum", "1", 0, "128 KB" -HKR, "Parameters\MaxTransferSize\enum", "2", 0, "256 KB" [Strings] ;
diff --git a/viostor/virtio_stor.c b/viostor/virtio_stor.c index d528ca9..e4acaa0 100644 --- a/viostor/virtio_stor.c +++ b/viostor/virtio_stor.c @@ -19,13 +19,6 @@ ULONG RhelDbgLevel = TRACE_LEVEL_NONE; BOOLEAN IsCrashDumpMode; -UNICODE_STRING ViostorServicePathUnicode = - RTL_CONSTANT_STRING(VIOSTOR_SERVICE_NAME); - -UNICODE_STRING MaxTransferSizeUnicode = - RTL_CONSTANT_STRING(MAX_TRANSFER_SIZE); - - BOOLEAN VirtIoHwInitialize( IN PVOID DeviceExtension @@ -98,12 +91,6 @@ CompleteSRB( IN PSCSI_REQUEST_BLOCK Srb ); -BOOLEAN -GetMaxTransferSize( - IN PVOID DeviceExtension - ); - - ULONG DriverEntry( IN PVOID DriverObject, @@ -292,32 +279,16 @@ VirtIoFindAdapter( vq_sz = (sizeof(struct vring_virtqueue) + sizeof(PVOID) * pageNum); if(adaptExt->dump_mode) { - adaptExt->breaks_number = 8; - adaptExt->queue_depth = 4; + ConfigInfo->NumberOfPhysicalBreaks = 8; } else { - if(GetMaxTransferSize(DeviceExtension)) { - adaptExt->breaks_number = (adaptExt->transfer_size / 4); - if(pageNum <= (adaptExt->breaks_number * 4)) { - adaptExt->breaks_number = (pageNum / 4); - } - adaptExt->breaks_number = min(adaptExt->breaks_number, 64); - adaptExt->breaks_number = max(adaptExt->breaks_number, 1); - adaptExt->queue_depth = (pageNum / adaptExt->breaks_number) - 1; - adaptExt->queue_depth = max(adaptExt->queue_depth, 1); - } else { - adaptExt->breaks_number = (pageNum / 2); - adaptExt->breaks_number = min(adaptExt->breaks_number, 8); - adaptExt->breaks_number = max(adaptExt->breaks_number, 1); - adaptExt->queue_depth = 4; - } + ConfigInfo->NumberOfPhysicalBreaks = 16; } - ConfigInfo->NumberOfPhysicalBreaks = adaptExt->breaks_number; - ConfigInfo->MaximumTransferLength - = ConfigInfo->NumberOfPhysicalBreaks * PAGE_SIZE; + ConfigInfo->MaximumTransferLength = ConfigInfo->NumberOfPhysicalBreaks * PAGE_SIZE; + adaptExt->queue_depth = pageNum / ConfigInfo->NumberOfPhysicalBreaks - 1; RhelDbgPrint(TRACE_LEVEL_INFORMATION, ("breaks_number = %x queue_depth = %x\n", - adaptExt->breaks_number, + ConfigInfo->NumberOfPhysicalBreaks, adaptExt->queue_depth)); ptr = (ULONG_PTR)ScsiPortGetUncachedExtension(DeviceExtension, ConfigInfo, (PAGE_SIZE + vr_sz + vq_sz)); @@ -1000,67 +971,3 @@ CompleteSRB( Srb->Lun); #endif } - -BOOLEAN -GetMaxTransferSize( - IN PVOID DeviceExtension - ) -{ - - NTSTATUS status; - OBJECT_ATTRIBUTES oa; - HANDLE keyHandle; - RHEL_ULONG_VALUE_PARTIAL_INFO ulongValueInfo; - ULONG ulongValueLength; - PADAPTER_EXTENSION adaptExt; - - adaptExt = (PADAPTER_EXTENSION)DeviceExtension; - - InitializeObjectAttributes(&oa, - &ViostorServicePathUnicode, - OBJ_CASE_INSENSITIVE, - NULL, - NULL); - - status = ZwOpenKey(&keyHandle, - KEY_READ, - &oa); - - if (!NT_SUCCESS(status)) { - RhelDbgPrint(TRACE_LEVEL_ERROR, - ("ReadRegistryValues: Failed to open services key! 0x%x\n", - status)); - return FALSE; - } - - status = ZwQueryValueKey(keyHandle, - &MaxTransferSizeUnicode, - KeyValuePartialInformation, - &ulongValueInfo, - sizeof(ulongValueInfo), - &ulongValueLength); - - if (!NT_SUCCESS(status)) { - RhelDbgPrint(TRACE_LEVEL_ERROR, - ("ReadRegistryValues: Failed to query %wZ value! 0x%x\n", - &MaxTransferSizeUnicode, status)); - ZwClose(keyHandle); - return FALSE; - } - - ASSERT(ulongValueInfo.PartialInfo.Type == REG_SZ); - - switch(*ulongValueInfo.PartialInfo.Data) { - case '0' : adaptExt->transfer_size = 64; break; - case '1' : adaptExt->transfer_size = 128; break; - case '2' : adaptExt->transfer_size = 256; break; - default : adaptExt->transfer_size = 64; break; - } - - RhelDbgPrint(TRACE_LEVEL_INFORMATION, - ("%wZ set to %d\n", &MaxTransferSizeUnicode, - adaptExt->transfer_size)); - - ZwClose(keyHandle); - return TRUE; -} diff --git a/viostor/virtio_stor.h b/viostor/virtio_stor.h index 999405b..1c0dbb6 100644 --- a/viostor/virtio_stor.h +++ b/viostor/virtio_stor.h @@ -50,10 +50,6 @@ typedef struct VirtIOBufferDescriptor VIO_SG, *PVIO_SG; #define VIRTIO_MAX_SG (3+MAX_PHYS_SEGMENTS) #define IO_PORT_LENGTH 0x40 -#define VIOSTOR_SERVICE_NAME L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Viostor\\Parameters\\MaxTransferSize" -#define MAX_TRANSFER_SIZE L"default" - - #pragma pack(1) typedef struct virtio_blk_config { /* The capacity (in 512-byte sectors). */ @@ -94,19 +90,12 @@ typedef struct virtio_blk_req { VIO_SG sg[VIRTIO_MAX_SG]; }blk_req, *pblk_req; -typedef struct _RHEL_ULONG_VALUE_PARTIAL_INFO { - KEY_VALUE_PARTIAL_INFORMATION PartialInfo; - UCHAR Buffer[8]; -}RHEL_ULONG_VALUE_PARTIAL_INFO, *PRHEL_ULONG_VALUE_PARTIAL_INFO; - typedef struct _ADAPTER_EXTENSION { ULONG_PTR device_base; virtio_pci_vq_info pci_vq_info; vring_virtqueue* virtqueue; INQUIRYDATA inquiry_data; blk_config info; - ULONG breaks_number; - ULONG transfer_size; ULONG queue_depth; BOOLEAN dump_mode; }ADAPTER_EXTENSION, *PADAPTER_EXTENSION; diff --git a/viostor/wlh.inf b/viostor/wlh.inf index 8c64191..aae425a 100644 --- a/viostor/wlh.inf +++ b/viostor/wlh.inf @@ -85,14 +85,6 @@ HKR,,TypesSupported,%REG_DWORD%,7 [pnpsafe_pci_addreg] HKR, "Parameters\PnpInterface", "5", %REG_DWORD%, 0x00000001 HKR, "Parameters", "BusType", %REG_DWORD%, 0x00000001 -;HKR, "Parameters", "MaxTransferSize", %REG_DWORD%, 0x0000040 - -HKR, "Parameters\MaxTransferSize", ParamDesc, 0, "Maximum Transfer Size" -HKR, "Parameters\MaxTransferSize", type, 0, "enum" -HKR, "Parameters\MaxTransferSize", default, 0, "0" -HKR, "Parameters\MaxTransferSize\enum", "0", 0, "64 KB" -HKR, "Parameters\MaxTransferSize\enum", "1", 0, "128 KB" -HKR, "Parameters\MaxTransferSize\enum", "2", 0, "256 KB" [Strings] ; diff --git a/viostor/wnet.inf b/viostor/wnet.inf index 8c64191..aae425a 100644 --- a/viostor/wnet.inf +++ b/viostor/wnet.inf @@ -85,14 +85,6 @@ HKR,,TypesSupported,%REG_DWORD%,7 [pnpsafe_pci_addreg] HKR, "Parameters\PnpInterface", "5", %REG_DWORD%, 0x00000001 HKR, "Parameters", "BusType", %REG_DWORD%, 0x00000001 -;HKR, "Parameters", "MaxTransferSize", %REG_DWORD%, 0x0000040 - -HKR, "Parameters\MaxTransferSize", ParamDesc, 0, "Maximum Transfer Size" -HKR, "Parameters\MaxTransferSize", type, 0, "enum" -HKR, "Parameters\MaxTransferSize", default, 0, "0" -HKR, "Parameters\MaxTransferSize\enum", "0", 0, "64 KB" -HKR, "Parameters\MaxTransferSize\enum", "1", 0, "128 KB" -HKR, "Parameters\MaxTransferSize\enum", "2", 0, "256 KB" [Strings] ;