HwScsiFindAdapter in Virtual SCSI Miniport

Hello,

A few days ago I commented my problem with SRB commands in my miniport. I don’t exactly know the cause yet, that is why I would like to ask some more questions.

According what I read on http://www.osronline.com/DDKx/storage/k302_9vsi.htm, for a Plug and Play miniport driver, the port driver calls HwScsiFindAdapter when the Plug and Play Manager has detected an adapter for that miniport, right?

Well, by debugging and using LOGs I found that HwScsiFindAdapter is also never called as the same as HwStartIo. Perhaps HwStartIo won’t be able to be called without before calling HwScsiFindAdapter. I don’t know. But in that case, why does Plug and Play Manager never call HwScsiFindAdapter ?

After installing the miniport through the PNP Manager, the miniport seems to be installed correctly and Windows doesn’t report any error.

HwInitialize and HwResetBus are also never called.

This is the initialization of the structure HW_INITIALIZATION_DATA:

RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
HwInitializationData.HwInitialize = CDDAInitialize;
HwInitializationData.HwResetBus = CDDAResetBus;
HwInitializationData.HwStartIo = CDDAStartIo;
HwInitializationData.HwFindAdapter = CDDAFindAdapter;
HwInitializationData.HwAdapterControl = CDDAAdapterControl;
HwInitializationData.AdapterInterfaceType = PCIBus;
HwInitializationData.DeviceExtensionSize = sizeof( DEVICE_EXTENSION );
HwInitializationData.MapBuffers = TRUE;
HwInitializationData.ReceiveEvent = TRUE;
HwInitializationData.AutoRequestSense = TRUE;
HwInitializationData.VendorIdLength = 8;
HwInitializationData.VendorId = “Valhalla”;
HwInitializationData.DeviceIdLength = 8;
HwInitializationData.DeviceId = “CDDASCSI”;

status = ScsiPortInitialize( DriverObject, RegistryPath, &HwInitializationData, &HwContext );

if (!NT_SUCCESS(status))
{
return status;
DbgPrint(“It was impossible to initialize SCSI port”);
CDDALogS(“SCSI Miniport Initilizated WRONG”);
}

CDDALogS(“SCSI Miniport Initilizated OK”);

In the member AdapterInterfaceType I have tried with both, PCIBus and Internal, but the sames happens. ScsiPortInitialize always returns SUCCESS, however, HwScsiXXXX funcitons are never called.

Do I need to add something special different code in the PNP dispatcher for SCSI minports? In such dispatcher I’m checking for the following Minor Functions:

IRP_MN_START_DEVICE
IRP_MN_QUERY_STOP_DEVICE
IRP_MN_CANCEL_STOP_DEVICE
IRP_MN_STOP_DEVICE
IRP_MN_QUERY_REMOVE_DEVICE
IRP_MN_CANCEL_REMOVE_DEVICE
IRP_MN_SURPRISE_REMOVAL
IRP_MN_REMOVE_DEVICE

and only IRP_MN_START_DEVICE is called (successfully). The other ones are not called.

Does anyone have some idea?

Thanks in advance.

Christian D’Orazio

That is more like what I expected. Your previous posts seemed to indicate that your HwScsiFindAdapter interface was being called but not HwStartIo, and that did not make much sense if you had not screwed up the rather simple processing in HwScsiFindAdapter. Your virtual scsi adapter has to have memory or port hardware resources or scsiport ignores it. If you claim you are a PCI device, how are you arranging to have PCI memory or port resources? Same question for ‘Internal’, how are you managing to have memory or port registers for your device?

Back when all systems had an ISA bus you could just claim an unused ISA port in your inf file and that would be sufficient to convince scsiport to accept your HBA. Most new systems do not have an ISA bus and consequently that door has been closed.

What worked for me was to hack up the toaster bus driver from the WDF samples and have it enumerate the HBA. That gets me a PDO that I can explicitly control from a service application. In order to add resources to that PDO I had to put an upper filter driver above the HBA FDO to create fictional hardware memory registers for the PDO by modifying IRP_MN_START_DEVICE before it arrived at scsiport. (The bus driver cannot do this, PNP will reject its attempts to assign fictional resources to the PDO.)

Now of course one has to ask: do you understand that your virtual scsiport is virtually worthless as a commercial product? You can get it to function, but it will have horrible performance. We have discussed virtual scsiport here repeatedly and all of the reasons why it is not a good real world solution have been described in detail.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-297403-
xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com.ar
Sent: Wednesday, August 15, 2007 3:21 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] HwScsiFindAdapter in Virtual SCSI Miniport

Hello,

A few days ago I commented my problem with SRB commands in my miniport.
I don’t exactly know the cause yet, that is why I would like to ask
some more questions.

According what I read on
http://www.osronline.com/DDKx/storage/k302_9vsi.htm, for a Plug and
Play miniport driver, the port driver calls HwScsiFindAdapter when the
Plug and Play Manager has detected an adapter for that miniport, right?

Well, by debugging and using LOGs I found that HwScsiFindAdapter is
also never called as the same as HwStartIo. Perhaps HwStartIo won’t be
able to be called without before calling HwScsiFindAdapter. I don’t
know. But in that case, why does Plug and Play Manager never call
HwScsiFindAdapter ?

After installing the miniport through the PNP Manager, the miniport
seems to be installed correctly and Windows doesn’t report any error.

HwInitialize and HwResetBus are also never called.

This is the initialization of the structure HW_INITIALIZATION_DATA:

RtlZeroMemory(&HwInitializationData,
sizeof(HW_INITIALIZATION_DATA));
HwInitializationData.HwInitializationDataSize =
sizeof(HW_INITIALIZATION_DATA);
HwInitializationData.HwInitialize =
CDDAInitialize;
HwInitializationData.HwResetBus =
CDDAResetBus;
HwInitializationData.HwStartIo =
CDDAStartIo;
HwInitializationData.HwFindAdapter =
CDDAFindAdapter;
HwInitializationData.HwAdapterControl =
CDDAAdapterControl;
HwInitializationData.AdapterInterfaceType = PCIBus;
HwInitializationData.DeviceExtensionSize = sizeof(
DEVICE_EXTENSION );
HwInitializationData.MapBuffers =
TRUE;
HwInitializationData.ReceiveEvent = TRUE;
HwInitializationData.AutoRequestSense = TRUE;
HwInitializationData.VendorIdLength = 8;
HwInitializationData.VendorId =
“Valhalla”;
HwInitializationData.DeviceIdLength = 8;
HwInitializationData.DeviceId =
“CDDASCSI”;

status = ScsiPortInitialize( DriverObject, RegistryPath,
&HwInitializationData, &HwContext );

if (!NT_SUCCESS(status))
{
return status;
DbgPrint(“It was impossible to initialize SCSI port”);
CDDALogS(“SCSI Miniport Initilizated WRONG”);
}

CDDALogS(“SCSI Miniport Initilizated OK”);

In the member AdapterInterfaceType I have tried with both, PCIBus and
Internal, but the sames happens. ScsiPortInitialize always returns
SUCCESS, however, HwScsiXXXX funcitons are never called.

Do I need to add something special different code in the PNP dispatcher
for SCSI minports? In such dispatcher I’m checking for the following
Minor Functions:

IRP_MN_START_DEVICE
IRP_MN_QUERY_STOP_DEVICE
IRP_MN_CANCEL_STOP_DEVICE
IRP_MN_STOP_DEVICE
IRP_MN_QUERY_REMOVE_DEVICE
IRP_MN_CANCEL_REMOVE_DEVICE
IRP_MN_SURPRISE_REMOVAL
IRP_MN_REMOVE_DEVICE

and only IRP_MN_START_DEVICE is called (successfully). The other ones
are not called.

Does anyone have some idea?

Thanks in advance.

Christian D’Orazio


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

Hello Mark,

Thanks for your answer. What I exactly need to develop is something like MagicDisk. So, I’m trying to choose the best solution by asking in this forum. Most people recommended to develop and SCSI minport in order to mount a virtual CDDA from BIN files. Anyway, it won’t be a commercial product, but I don’t understand why you ask

do you understand that your virtual scsiport is virtually worthless as a commercial product?

Do commercial products use another techniques in order to do that? Please let me know in order to know if I’m trying to do this in a wrong way…

Thanks,

Christian D’Orazio

Once you get your miniport to work you will discover that you are at
DISPATCH_LEVEL whenever your miniport interfaces are invoked. This will
limit your ability to call most kernel interfaces, as they tend to want
to be called at less than DISPATCH_LEVEL. As I said, search this group
for all the gory details about why a virtual miniport has severe
limitations. The performance of a virtual CD device, once you work out
all the issues, may be acceptable. The other choice, until msft manages
to release their virtual storport support, is to write a full scsiport
driver. For example, the osr virtual cd driver appears to be one of
those.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com.ar
Sent: Wednesday, August 15, 2007 7:59 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HwScsiFindAdapter in Virtual SCSI Miniport

Hello Mark,

Thanks for your answer. What I exactly need to develop is something like
MagicDisk. So, I’m trying to choose the best solution by asking in this
forum. Most people recommended to develop and SCSI minport in order to
mount a virtual CDDA from BIN files. Anyway, it won’t be a commercial
product, but I don’t understand why you ask

do you understand that your virtual scsiport is virtually worthless as a
commercial product?

Do commercial products use another techniques in order to do that?
Please let me know in order to know if I’m trying to do this in a wrong
way…

Thanks,

Christian D’Orazio


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

Hello,

Thanks Mark. What do you mean when you say the following?

Your virtual scsi adapter has to have memory or port
hardware resources or scsiport ignores it. If you claim you are a PCI device,
how are you arranging to have PCI memory or port resources? Same question for
‘Internal’, how are you managing to have memory or port registers for your
device?

When you talk about a port hardware resources…Are you talking about a physical hardware?

What exactly do I have to do in order to have memory? What do you mean when you say “managing memory”? Do I need to initialize the miniport with something special parameter in HW_INITIALIZATION_DATA, AddDevice fucniton, or PNP Dispatcher in order to manage such memory and so that HwFindAdapter be called?

Thanks in advance,

Christian D’Orazio

Scsiport does not support virtual HBAs. You have to trick scsiport into
believing that your HBA is a real hardware device. To do that you have
to have an IRP_MN_START_DEVICE IRP show up at scsiport with memory or
iospace (port) resources. If you do not do this scsiport will behave as
you have described: everything works fine but you never get called at
HwFindAdapter.

I described two ways to do this.

  1. on a system with an ISA bus you can, in your inf file, allocate port
    or memory resources for your virtual device and claim that you are an
    HBA on the ISA bus. Most new systems do not have an ISA bus, so this
    simple approach is obsolete.

  2. you can write an upper filter driver for your HBA device that
    modifies IRP_MN_START_DEVICE to put some fake resources into the IRP and
    fool scsiport that way. I suggest inserting them on the dispatch side
    and removing them on the completion side. One memory resource is all you
    need. Your HBA can then be on the ‘internal’ bus, which is platform
    independent.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com.ar
Sent: Thursday, August 16, 2007 7:02 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HwScsiFindAdapter in Virtual SCSI Miniport

Hello,

Thanks Mark. What do you mean when you say the following?

Your virtual scsi adapter has to have memory or port
hardware resources or scsiport ignores it. If you claim you are a PCI
device,
how are you arranging to have PCI memory or port resources? Same
question for
‘Internal’, how are you managing to have memory or port registers for
your
device?

When you talk about a port hardware resources…Are you talking about a
physical hardware?

What exactly do I have to do in order to have memory? What do you mean
when you say “managing memory”? Do I need to initialize the miniport
with something special parameter in HW_INITIALIZATION_DATA, AddDevice
fucniton, or PNP Dispatcher in order to manage such memory and so that
HwFindAdapter be called?

Thanks in advance,

Christian D’Orazio


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

There are numerous hidden, hard to solve challenges in creating a solid virtual SCSI miniport such as loading, IRQL, performance issues, etc. There are no samples in the WDK to use as guidance and it is worth noting from the archives that many veteran engineers stopped short of overcoming all of the technical challenges. However, one option is to google for SCSI virtual miniport source code to find a skeleton to fit out with your code. We needed fast 64-bit virtual disks and the perisoft.net/miniport kit works well for that. Some kits are nice because they also alleviate the need to claim any hardware resources. Microsoft has indicated it may in the future support writing virtual miniports so developing a miniport style solution now should result in a straightforward port to that end.

Hello,

Eriksson, I really appreciate your help but, did you see how much expensive the Perisoft’s skeleton is? I prefer to develop it by myself.

The following is for Mark:

I’m developing a PNP Driver. Then, In order to do what you said in your last answer, Is it enough to add some memory resource in the PNP Dispatcher when the MinorFunction is equal to IRP_MN_START_DEVICE (or IRP_MN_QUERY_LEGACY_BUS_INFORMATION, IRP_MN_FILTER_RESOURCE_REQUIREMENTS)? I don’t know why, but something tells me that it is not possible…

So, if that is not possible, Do you mean to develop 2 different drivers?

And the last but not least, What does a memory resource exactly mean? For example, Is it enough to allocate memory a assign this to some field in the DEVICE_EXTENSION structure?

Thanks for your valuable information.

Christian D’Orazio

You need at a minimum two drivers: one miniport and one standard WDM or
WDF FDO upper filter driver. The filter driver manipulates
IRP_MN_START_DEVICE. The memory resources in IRP_MN_START_DEVICE are
described in the WDK documentation. In your case you just need anything
at all that is going to look like a memory resource - nobody is going to
actually access it, so it really doesn’t matter what the values are.

Have I mentioned that virtual scsiport miniports are not really
supported and have many issues beyond simply getting them to start?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com.ar
Sent: Friday, August 17, 2007 5:52 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HwScsiFindAdapter in Virtual SCSI Miniport

Hello,

Eriksson, I really appreciate your help but, did you see how much
expensive the Perisoft’s skeleton is? I prefer to develop it by myself.

The following is for Mark:

I’m developing a PNP Driver. Then, In order to do what you said in your
last answer, Is it enough to add some memory resource in the PNP
Dispatcher when the MinorFunction is equal to IRP_MN_START_DEVICE (or
IRP_MN_QUERY_LEGACY_BUS_INFORMATION,
IRP_MN_FILTER_RESOURCE_REQUIREMENTS)? I don’t know why, but something
tells me that it is not possible…

So, if that is not possible, Do you mean to develop 2 different drivers?

And the last but not least, What does a memory resource exactly mean?
For example, Is it enough to allocate memory a assign this to some field
in the DEVICE_EXTENSION structure?

Thanks for your valuable information.

Christian D’Orazio


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

Maybe you didn’t, but I have many many many many many many many many many
many many many many many many many many many …
uhhh … LOT’s of times … :slight_smile:


The personal opinion of
Gary G. Little

“Roddy, Mark” wrote in message news:xxxxx@ntdev…
You need at a minimum two drivers: one miniport and one standard WDM or
WDF FDO upper filter driver. The filter driver manipulates
IRP_MN_START_DEVICE. The memory resources in IRP_MN_START_DEVICE are
described in the WDK documentation. In your case you just need anything
at all that is going to look like a memory resource - nobody is going to
actually access it, so it really doesn’t matter what the values are.

Have I mentioned that virtual scsiport miniports are not really
supported and have many issues beyond simply getting them to start?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.com.ar
Sent: Friday, August 17, 2007 5:52 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] HwScsiFindAdapter in Virtual SCSI Miniport

Hello,

Eriksson, I really appreciate your help but, did you see how much
expensive the Perisoft’s skeleton is? I prefer to develop it by myself.

The following is for Mark:

I’m developing a PNP Driver. Then, In order to do what you said in your
last answer, Is it enough to add some memory resource in the PNP
Dispatcher when the MinorFunction is equal to IRP_MN_START_DEVICE (or
IRP_MN_QUERY_LEGACY_BUS_INFORMATION,
IRP_MN_FILTER_RESOURCE_REQUIREMENTS)? I don’t know why, but something
tells me that it is not possible…

So, if that is not possible, Do you mean to develop 2 different drivers?

And the last but not least, What does a memory resource exactly mean?
For example, Is it enough to allocate memory a assign this to some field
in the DEVICE_EXTENSION structure?

Thanks for your valuable information.

Christian D’Orazio


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