Virtual StorPort Driver

Based upon the lead article in the latest “The NT Insider” I tride to build a Virtual StorPort Driver to run on a 2008 Server checked build. However, I wasn’t successful, in that, after my DriverEntry is called nothing more happens.

In my .inf file I set is up as a SCSIAdapter.
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}

In my DriverEntry (among other things) I do:

// The VIRTUAL_HW_INITIALIZATION_DATA structure contains information particular
// to each virtual miniport driver.
VIRTUAL_HW_INITIALIZATION_DATA DBDiskHwInitializationData;
int i;

for ( i = 0; i < sizeof( VIRTUAL_HW_INITIALIZATION_DATA); i++)
{
((PUCHAR)&DBDiskHwInitializationData)[i] = 0;
}

DBDiskHwInitializationData.HwInitializationDataSize =
sizeof(VIRTUAL_HW_INITIALIZATION_DATA);
DBDiskHwInitializationData.AdapterInterfaceType = Internal;
DBDiskHwInitializationData.HwInitialize = DBDiskHwInitialize;
DBDiskHwInitializationData.HwStartIo = DBDiskHwStartIo;
DBDiskHwInitializationData.HwInterrupt = NULL; // not used by virtual driver
DBDiskHwInitializationData.HwFindAdapter = DBDiskHwFindAdapter;

Well, as the Nt Insider says, this is just the first part in a series.
We were just going over the basics and have not really given all the
information to make one work yet. Anyway, here is what we did in our
Virtual StorPort Driver…

–Mark Cariddi
OSR, Open Systems Resources, Inc

//
// Set up information for StorPortInitialize.
//
RtlZeroMemory(&OsrHwInitData,
sizeof(VIRTUAL_HW_INITIALIZATION_DATA));
OsrHwInitData.HwInitializationDataSize =
sizeof(VIRTUAL_HW_INITIALIZATION_DATA);

//
// Set up our entry points (callbacks).
//
OsrHwInitData.HwInitialize = OsrHwInitialize; //
Required.
OsrHwInitData.HwStartIo = OsrHwStartIo; //
Required.
OsrHwInitData.HwFindAdapter = OsrHwFindAdapter; //
Required.
OsrHwInitData.HwResetBus = OsrHwResetBus; //
Required.
OsrHwInitData.HwAdapterControl = OsrHwAdapterControl; //
Required.
OsrHwInitData.HwFreeAdapterResources = OsrHwFreeAdapterResources;
OsrHwInitData.HwProcessServiceRequest = OsrHwProcessServiceRequest;
OsrHwInitData.HwCompleteServiceIrp =
OsrHwCompleteServiceRequest;

OsrHwInitData.AdapterInterfaceType = Internal;

OsrHwInitData.MultipleRequestPerLu = TRUE;
OsrHwInitData.PortVersionFlags = 0;

OsrHwInitData.DeviceExtensionSize =
sizeof(HW_DEVICE_EXTENSION);
OsrHwInitData.SpecificLuExtensionSize = sizeof(HW_LU_EXTENSION);
OsrHwInitData.SrbExtensionSize = sizeof(HW_SRB_EXTENSION) +
OsrUserGetSrbExtensionSize();

status = StorPortInitialize(DriverObject,
RegistryPath,

(PHW_INITIALIZATION_DATA)&OsrHwInitData,
NULL);

if (STATUS_SUCCESS!=status) { // Port driver
said not OK?
OsrTracePrint(TRACE_LEVEL_ERROR,OSRVMINIPT_DEBUG_FUNCTRACE,
(“DriverEntry failure in call to
StorPortInitialize. status:0x%x\n”,status));
ExFreePool(OsrRegistryPath.Buffer);
ASSERT(FALSE);
return status;
}

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Thursday, October 01, 2009 12:32 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Virtual StorPort Driver

Based upon the lead article in the latest “The NT Insider” I tride to
build a Virtual StorPort Driver to run on a 2008 Server checked build.
However, I wasn’t successful, in that, after my DriverEntry is called
nothing more happens.

In my .inf file I set is up as a SCSIAdapter.
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}

In my DriverEntry (among other things) I do:

// The VIRTUAL_HW_INITIALIZATION_DATA structure contains information
particular
// to each virtual miniport driver.
VIRTUAL_HW_INITIALIZATION_DATA DBDiskHwInitializationData;
int i;

for ( i = 0; i < sizeof(
VIRTUAL_HW_INITIALIZATION_DATA); i++)
{
((PUCHAR)&DBDiskHwInitializationData)[i] = 0;
}

DBDiskHwInitializationData.HwInitializationDataSize =
sizeof(VIRTUAL_HW_INITIALIZATION_DATA);
DBDiskHwInitializationData.AdapterInterfaceType =
Internal;
DBDiskHwInitializationData.HwInitialize =
DBDiskHwInitialize;
DBDiskHwInitializationData.HwStartIo = DBDiskHwStartIo;
DBDiskHwInitializationData.HwInterrupt = NULL; // not
used by virtual driver
DBDiskHwInitializationData.HwFindAdapter =
DBDiskHwFindAdapter;


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

And did you create an instance of the device on a some bus, like the root
bus? Or have a virtual bus of some type?

You can create new root enumerated device instances with the command (check
the devcon syntax to be sure):

devcon install theDevice.inf theDevicePnPId

The value of theDevicePnPId should match the value in theDevice.inf.

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-382802-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, October 01, 2009 9:32 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Virtual StorPort Driver

Based upon the lead article in the latest “The NT Insider” I tride to
build a Virtual StorPort Driver to run on a 2008 Server checked build.
However, I wasn’t successful, in that, after my DriverEntry is called
nothing more happens.

In my .inf file I set is up as a SCSIAdapter.
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}

In my DriverEntry (among other things) I do:

// The VIRTUAL_HW_INITIALIZATION_DATA structure contains information
particular
// to each virtual miniport driver.
VIRTUAL_HW_INITIALIZATION_DATA DBDiskHwInitializationData;
int i;

for ( i = 0; i < sizeof( VIRTUAL_HW_INITIALIZATION_DATA);
i++)
{
((PUCHAR)&DBDiskHwInitializationData)[i] = 0;
}

DBDiskHwInitializationData.HwInitializationDataSize =
sizeof(VIRTUAL_HW_INITIALIZATION_DATA);
DBDiskHwInitializationData.AdapterInterfaceType = Internal;
DBDiskHwInitializationData.HwInitialize =
DBDiskHwInitialize;
DBDiskHwInitializationData.HwStartIo = DBDiskHwStartIo;
DBDiskHwInitializationData.HwInterrupt = NULL; // not used
by virtual driver
DBDiskHwInitializationData.HwFindAdapter =
DBDiskHwFindAdapter;


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Thanks Mark,

I meant to add this to my post:

I do this in my DriverEntry:
status = StorPortInitialize(
DriverObject,
RegistryPath,
(PHW_INITIALIZATION_DATA) &DBDiskHwInitializationData,
NULL // HwContext
);
if (!NT_SUCCESS(status)) {
status = StorPortInitialize(
DriverObject,
RegistryPath,
(PHW_INITIALIZATION_DATA) &DBDiskHwInitializationData,
NULL
);
if (!NT_SUCCESS(status)) {
KdPrint((“DBDiskSys: error in StorPortInitialize (%#x).\n”, status));

return status;
}

But I never see DBDiskHwFindAdapter being called.
I’ll muck about a bit, and eagerly await the follow up articles.

Thanks again,
Davey

Hi Jan,
Nope, I didn’t create an instance of the device on a bus. I thought everything was virtual and the purpose of the HwFindAdapter routine was to fill in all the h/w related info normally provided by the PNP manager. I’ll look into your solution.
Thanks

As Jan said you have to set up the INF file correctly. We will talk
about this in follow on articles…

–Mark Cariddi
OSR, Open Systems Resources, INc…

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Thursday, October 01, 2009 1:03 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Virtual StorPort Driver

Hi Jan,
Nope, I didn’t create an instance of the device on a bus. I thought
everything was virtual and the purpose of the HwFindAdapter routine was
to fill in all the h/w related info normally provided by the PNP
manager. I’ll look into your solution.
Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>Nope, I didn’t create an instance of the device on a bus. I thought everything was virtual and the >purpose of the HwFindAdapter routine was to fill in all the h/w related info normally provided by >the >PNP manager. I’ll look into your solution.
A virtual mini port driver means that a lower edge interface of your driver will be not a standard mini-port interface, which is controlled by StorPort driver, but your own interface. This interface could be any which is supported by WDM. The common interface is PCI, which means that your Device Object would be created by PCI bus driver. And to support creating PCI FDO you need to provide such specific PCI information in your .inf file, like Device&Vendor ID, and include WDM routines which provide communication with PCI bus. But the upper interface of a Virtual mini-port driver will communicate with a Port driver. In generally, you need to have both a specific miniport support for upper edge interface and WDM support for low edge interface.

Igor Sharovar

Hi Igor,

I don’t have any hardware, so how does the PCI bus driver know to create an object for me? Is it just by virtue of declaring in the .inf file that my ‘device’ is PCI emumerated that this will happen?
Right now when I load my driver it gets unloaded immediately because there is no device created. I’ve tried creating a dummy control device, which keeps the driver loaded, but that’s it.

Thanks

You have to create a INF file that indicates you are root enumerated.
Then your drive will be loaded.

Mark Cariddi
OSR, Open Systems Resources, Inc…

[Version]
Signature=“$WINDOWS NT$”
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}
Provider=%OSR%
DriverVer=01/30/2007,6.0.6000.16386
CatalogFile = OSRVMINIPT.cat

[DestinationDirs]
DefaultDestDir = 12

[Manufacturer]
%OSR%=OSRVM, NTx86, NTamd64

[OSRVM.NTx86]
%OSRVMDeviceDesc%=OSRVM_Device, %rootstr%

[OSRVM.NTamd64]
%OSRVMDeviceDesc%=OSRVM_Device, %rootstr%

[OSRVM_Device]
CopyFiles=@OsrVStor.sys

[OSRVM_Device.Services]
AddService = OSRVStor, %SPSVCINST_ASSOCSERVICE%, OSRVM_Service_Inst

[SourceDisksNames.x86]
1 = %DiskId1%,\i386

[SourceDisksNames.amd64]
1 = %DiskId1%,\amd64

[SourceDisksFiles]
OsrVStor.sys = 1

[OSRVM_Service_Inst]
DisplayName = %OSRVMDeviceDesc%
ServiceType = %SERVICE_KERNEL_DRIVER%
StartType = %SERVICE_BOOT_START%
ErrorControl = %SERVICE_ERROR_NORMAL%
ServiceBinary = %12%\OsrVStor.sys
LoadOrderGroup = SCSI Miniport
AddReg = pnpsafe_isa_addreg

[pnpsafe_isa_addreg]
HKR, “Parameters”, “BreakOnEntry”, %REG_DWORD%,
0x00000000

[Strings]
OSR = “OSR, Open Systems Resoruces, Inc.”
SCSIClassName = “SCSI and RAID controllers”
OSRVMDeviceDesc = “OSR StorPort Virtual Adapter”
DiskId1 = “OSR Virtual Miniport Device Installation Disk #1
rootstr = “root\OsrVm”

;*******************************************
;Handy macro substitutions (non-localizable)
SPSVCINST_ASSOCSERVICE = 0x00000002
SERVICE_KERNEL_DRIVER = 1
SERVICE_BOOT_START = 0
SERVICE_ERROR_NORMAL = 1

REG_DWORD = 0x00010001
REG_BINARY = 0x00000001
REG_SZ = 0x00000000

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Friday, October 02, 2009 12:15 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Virtual StorPort Driver

Hi Igor,

I don’t have any hardware, so how does the PCI bus driver know to create
an object for me? Is it just by virtue of declaring in the .inf file
that my ‘device’ is PCI emumerated that this will happen?
Right now when I load my driver it gets unloaded immediately because
there is no device created. I’ve tried creating a dummy control device,
which keeps the driver loaded, but that’s it.

Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

xxxxx@gmail.com wrote:

I don’t have any hardware, so how does the PCI bus driver know to create an object for me? Is it just by virtue of declaring in the .inf file that my ‘device’ is PCI emumerated that this will happen?
Right now when I load my driver it gets unloaded immediately because there is no device created. I’ve tried creating a dummy control device, which keeps the driver loaded, but that’s it.

Um, if you don’t really have a PCI-based device, then why would you
declare in your INF that you are PCI-enumerated? Yuu can’t use the
services of the PCI bus driver unless you are a PCI device.

If you declare yourself as root-enumerated, then you will be enumerated
at every boot.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

A very nice article on Vminiports:

http://www.osronline.com/article.cfm?id=538

  • Charan

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Cariddi
Sent: Friday, October 02, 2009 9:31 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Virtual StorPort Driver

You have to create a INF file that indicates you are root enumerated.
Then your drive will be loaded.

Mark Cariddi
OSR, Open Systems Resources, Inc…

[Version]
Signature=“$WINDOWS NT$”
Class=SCSIAdapter
ClassGUID={4D36E97B-E325-11CE-BFC1-08002BE10318}
Provider=%OSR%
DriverVer=01/30/2007,6.0.6000.16386
CatalogFile = OSRVMINIPT.cat

[DestinationDirs]
DefaultDestDir = 12

[Manufacturer]
%OSR%=OSRVM, NTx86, NTamd64

[OSRVM.NTx86]
%OSRVMDeviceDesc%=OSRVM_Device, %rootstr%

[OSRVM.NTamd64]
%OSRVMDeviceDesc%=OSRVM_Device, %rootstr%

[OSRVM_Device]
CopyFiles=@OsrVStor.sys

[OSRVM_Device.Services]
AddService = OSRVStor, %SPSVCINST_ASSOCSERVICE%, OSRVM_Service_Inst

[SourceDisksNames.x86]
1 = %DiskId1%,\i386

[SourceDisksNames.amd64]
1 = %DiskId1%,\amd64

[SourceDisksFiles]
OsrVStor.sys = 1

[OSRVM_Service_Inst]
DisplayName = %OSRVMDeviceDesc%
ServiceType = %SERVICE_KERNEL_DRIVER%
StartType = %SERVICE_BOOT_START%
ErrorControl = %SERVICE_ERROR_NORMAL%
ServiceBinary = %12%\OsrVStor.sys
LoadOrderGroup = SCSI Miniport
AddReg = pnpsafe_isa_addreg

[pnpsafe_isa_addreg]
HKR, “Parameters”, “BreakOnEntry”, %REG_DWORD%,
0x00000000

[Strings]
OSR = “OSR, Open Systems Resoruces, Inc.”
SCSIClassName = “SCSI and RAID controllers”
OSRVMDeviceDesc = “OSR StorPort Virtual Adapter”
DiskId1 = “OSR Virtual Miniport Device Installation Disk #1
rootstr = “root\OsrVm”

;*******************************************
;Handy macro substitutions (non-localizable)
SPSVCINST_ASSOCSERVICE = 0x00000002
SERVICE_KERNEL_DRIVER = 1
SERVICE_BOOT_START = 0
SERVICE_ERROR_NORMAL = 1

REG_DWORD = 0x00010001
REG_BINARY = 0x00000001
REG_SZ = 0x00000000

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Friday, October 02, 2009 12:15 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Virtual StorPort Driver

Hi Igor,

I don’t have any hardware, so how does the PCI bus driver know to create
an object for me? Is it just by virtue of declaring in the .inf file
that my ‘device’ is PCI emumerated that this will happen?
Right now when I load my driver it gets unloaded immediately because
there is no device created. I’ve tried creating a dummy control device,
which keeps the driver loaded, but that’s it.

Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> I don’t have any hardware

Then you need to create a virtual devnode for your “storage adapter” during your driver’s installation.

Use “devcon install” for this - as described in the thread above.

Then your virtual adapter enumerates your virtual LUNs.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com