[nvmewin] looking for help with IOCTL tool

Luse, Paul E paul.e.luse at intel.com
Mon Oct 1 16:18:01 PDT 2012


Hi-

To be clear, this is not a SCSI pass through request; this is an NVMe pass through command that we’ve encapsulated into an IOCTL that we send to the miniport.  The guideline we wrote doesn’t specify how the app identifies the miniport and we don’t have sample code there and I suppose we probably should.  Here’s some hacky example code that shows how your app can send a bunch of “identify IOCTLs” which you will have to define on your own (an IOCTL that just says “yes I’m a miniport that you are looking for”).  This routine will keep a list of those adapters in an array of handles with the array index being the scsiport number where the miniport is at that you are interested in.  So, in your driver quickly define an IOCTL and a handler that looks at a signature or whatever and responses success and this should work for you.  There are more elegant ways of doing it but this should get you going

Thx
Paul

int
FindNlAdapters(
    HANDLE          nlAdapters[],
    int             maxHandles
    )
{
    int           scsiPort;
    TCHAR           buffer[64];
    LPTSTR          pszTxt = "\\\\.\\Scsi";
    LPCTSTR         pszFormat = "%s%d:";
    size_t          cchDest = 64;
       DWORD           dw;
       NVME_PRIVATE_IOCTL myIoctl;
       int nlAdapterCount = 0;

       printf("FindNlAdapters: Searching ScsiPorts\n");
    // Initialize nlAdapters array with 0s.
    memset(nlAdapters, 0, maxHandles * sizeof(HANDLE));

    for (scsiPort = 0; scsiPort < maxHandles; scsiPort++) {
        wsprintf(buffer,pszFormat, pszTxt, scsiPort);
             HANDLE hand = CreateFile(buffer,
                    GENERIC_READ | GENERIC_WRITE,
                    FILE_SHARE_READ | FILE_SHARE_WRITE,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);
             if (hand == INVALID_HANDLE_VALUE) {
                    dw = GetLastError();
                    printf("didnt find %s            err %d \n", buffer, dw);
             }
             else {
                    printf("found %s \n", buffer);
        myIoctl.SrbIoCtrl.HeaderLength   = sizeof(SRB_IO_CONTROL);
        memcpy(myIoctl.SrbIoCtrl.Signature, NVME_SIG_STR, sizeof(NVME_SIG_STR));
        myIoctl.SrbIoCtrl.Timeout        = 20;
        myIoctl.SrbIoCtrl.ControlCode    = (ULONG)NL_IOCTL_IDENTIFY;
        myIoctl.SrbIoCtrl.ReturnCode     = 0;
        myIoctl.SrbIoCtrl.Length         = sizeof(NVME_PRIVATE_IOCTL) -
            sizeof(SRB_IO_CONTROL);
             BOOL b = DeviceIoControl(hand,
                    IOCTL_SCSI_MINIPORT,
                    &myIoctl,
                    sizeof(myIoctl),
                    &myIoctl,
                    sizeof(myIoctl),
                    &dw,
                    NULL);
             if (FALSE == b) {
                    printf("FindNlAdapters: NL_IOCTL_IDENTIFY: No NL miniport at this location %d\n" , scsiPort);
                    CloseHandle(hand);
             }
             else {
                    printf("FindNlAdapters: NL_IOCTL_IDENTIFY: NL miniport at this location %d !!!\n" , scsiPort);
                    nlAdapters[scsiPort] = hand;
                    nlAdapterCount++;
             }
             }
     }
     printf("FindNlAdapters: NL_IOCTL_IDENTIFY Success: nlAdapterCount: %d \n", nlAdapterCount);
     return nlAdapterCount;
}


From: nvmewin-bounces at lists.openfabrics.org [mailto:nvmewin-bounces at lists.openfabrics.org] On Behalf Of Yong Chen
Sent: Monday, October 01, 2012 3:28 PM
To: nvmewin at lists.openfabrics.org
Subject: [nvmewin] looking for help with IOCTL tool

Hi, everyone,

My team is starting to work on Windows driver based on nvmewin reference driver. Thanks for sharing such excellent work.

I have a question around IOCTL: which file path should I open in order to send the call to?

The PT_IOCTL.doc in the library suggests to open file handle on \\.\ScsiN<file:///\\.\ScsiN>: before sending DeviceIoControl() down. Unfortunately, our  Windows driver never receives anything. The SPTI tool sample in WDK says ScsiN: only works when the device is unclaimed by a SCSI driver. In the case, proper PathId, TargetId, and Lun must be set in the SCSI pass thru structure, but  NVME_PASS_THROUGH_IOCTL doesn’t have these fields.

According to MSDN<http://msdn.microsoft.com/en-us/library/windows/hardware/ff556013(v=vs.85).aspx>, IOCTL send to storage class drivers are mapped to SRBs with function set to SRB_FUNCTION_EXECUTE_SCSI. If I open \\.\PhysicalDriveN<file:///\\.\PhysicalDriveN>, then I do receive SRBs with such Execute SCSI function code.  But the current driver code expects SRB_FUNCTION_IO_CONTROL.

How do you guys do it?

Many thanks in advance,

________________________________
Yong Chen
Storage Architect
华为技术有限公司 Huawei Technologies Co., Ltd
[Company_logo]Office:  408-330-5482
Mobile:  425-922-0658
Email: yong.sc.chen at huawei.com<mailto:yong.sc.chen at huawei.com>
2330 Central Expressway
Santa Clara, CA 95050
http://www.huawei.com
本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁
止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中
的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from HUAWEI, which
is intended only for the person or entity whose address is listed above. Any use of the
information contained herein in any way (including, but not limited to, total or partial
disclosure, reproduction, or dissemination) by persons other than the intended
recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by
phone or email immediately and delete it!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/nvmewin/attachments/20121001/43ecb417/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 6737 bytes
Desc: image001.jpg
URL: <http://lists.openfabrics.org/pipermail/nvmewin/attachments/20121001/43ecb417/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 1742 bytes
Desc: image003.jpg
URL: <http://lists.openfabrics.org/pipermail/nvmewin/attachments/20121001/43ecb417/attachment-0001.jpg>


More information about the nvmewin mailing list