[nvmewin] DeviceIOControl Error

Alex Chang Alex.Chang at pmcs.com
Mon Jun 9 09:09:44 PDT 2014


Hi Sean,

You’re send Get Features Command for Arbitration, which doesn’t involve data transfer via separate buffer and ByteSizeTx should be zero. In other words, the sizes of input and output buffer should be the same as size of NVME_PASS_THROUGH_IOCTL.

Thanks,
Alex

From: nvmewin-bounces at lists.openfabrics.org [mailto:nvmewin-bounces at lists.openfabrics.org] On Behalf Of Sean Chen
Sent: Monday, June 09, 2014 5:57 AM
To: nvmewin at lists.openfabrics.org
Subject: [nvmewin] DeviceIOControl Error

Hi All

I study PT_IOCTL.doc to implement NVMe command for windows. But DeviceIControl return "The request could not be performed because of an I/O device error." The following is my code:


// ================ Get Device ================
char  driveName[256];
Select_choice = ComboBox->GetCurSel();
sprintf(driveName, "\\\\.\\scsi%d:<file:///\\\scsi%25d:>", Select_choice);

DeviceHandle = CreateFile(driveName,
 GENERIC_READ | GENERIC_WRITE,
 FILE_SHARE_READ | FILE_SHARE_WRITE,
 NULL,
 OPEN_EXISTING,
 FILE_ATTRIBUTE_NORMAL,
 NULL);
if (DeviceHandle == INVALID_HANDLE_VALUE) {
 MessageBox("Cannot open device.", "Device Error", MB_OK|MB_ICONERROR);
 return FALSE;
}

// ================ NVME Test ================
int  ByteSizeTX = 256;
BOOL status = 0;
DWORD count = 0;
DWORD InputBufLen = 0;
DWORD OutputBufLen = 0;
PNVME_PASS_THROUGH_IOCTL pInBuffer = NULL;
PNVME_PASS_THROUGH_IOCTL pOutBuffer = NULL;

// From Device to Host
// Allocate input buffer to accommodate size of NVME_PASS_THRUGH_IOCTL only
InputBufLen = sizeof(NVME_PASS_THROUGH_IOCTL);
pInBuffer = (PNVME_PASS_THROUGH_IOCTL) malloc(InputBufLen);
// Allocate output buffer to accommodate size of NVME_PASS_THRUGH_IOCTL and data
OutputBufLen = sizeof(NVME_PASS_THROUGH_IOCTL) + ByteSizeTX;
pOutBuffer = (PNVME_PASS_THROUGH_IOCTL) malloc(OutputBufLen);
// Confirm we have buffers allocated successfully
if (pInBuffer == NULL || pOutBuffer == NULL)
 return;
// Zero out the buffers
memset(pInBuffer, 0, InputBufLen);
memset(pOutBuffer, 0, OutputBufLen);
// Populate SRB_IO_CONTROL fields in input buffer
pInBuffer->SrbIoCtrl.ControlCode = NVME_PASS_THROUGH_SRB_IO_CODE;
pInBuffer->SrbIoCtrl.HeaderLength = sizeof(SRB_IO_CONTROL);
memcpy((UCHAR*)(&pInBuffer->SrbIoCtrl.Signature[0]), NVME_SIG_STR, NVME_SIG_STR_LEN);
pInBuffer->SrbIoCtrl.Timeout = 40;
pInBuffer->SrbIoCtrl.Length = InputBufLen - sizeof(SRB_IO_CONTROL);
pInBuffer->DataBufferLen = ByteSizeTX;
pInBuffer->ReturnBufferLen = OutputBufLen;
//pInBuffer->Direction = NVME_FROM_DEV_TO_HOST;
// Fill in pInBuffer->NVMeCmd here
pInBuffer->NVMeCmd[0]  = 0x0A; // OpCode
pInBuffer->NVMeCmd[1]  = 0x01; // Namespace ID
pInBuffer->NVMeCmd[10]  = 0x01;
// Fill pInBuffer->DataBuffer here when transferring data to device
status = DeviceIoControl(
                  DeviceHandle,          // Handle to \\.\scsi<file:///\\.\scsi> device via CreateFile
                  IOCTL_SCSI_MINIPORT,   // IO control function to a miniport driver
                  pInBuffer,             // Input buffer with data sent to driver
                  InputBufLen,           // Length of data sent to driver (in bytes)
                  pOutBuffer,            // Output buffer with data received from driver
                  OutputBufLen,          // Length of data received from driver
                  &count,                // Bytes placed in DataBuffer
                  NULL);                 // NULL = no overlap
free(pInBuffer);
free(pOutBuffer);

// ====================================================

May I have anything wrong?
Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/nvmewin/attachments/20140609/65a68681/attachment.html>


More information about the nvmewin mailing list