Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: JMicron JMS583 USB-NVMe bridge support #315

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linux/DtaDevLinuxSata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void DtaDevLinuxSata::identify(OPAL_DiskInfo& disk_info)

if (!(memcmp(nullz.data(), buffer, 512))) {
disk_info.devType = DEVICE_TYPE_OTHER;
identify_SAS(&disk_info);
return;
}
IDENTIFY_RESPONSE * id = (IDENTIFY_RESPONSE *) buffer;
Expand Down
185 changes: 93 additions & 92 deletions windows/DtaDiskNVMe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,39 @@ using namespace std;
#define StorageAdapterProtocolSpecificProperty (STORAGE_PROPERTY_ID) 49

#define NVME_MAX_LOG_SIZE 4096 // value from random internet search
#if 0
typedef enum _STORAGE_PROTOCOL_TYPE {
ProtocolTypeUnknown = 0x00,
ProtocolTypeScsi,
ProtocolTypeAta,
ProtocolTypeNvme,
ProtocolTypeSd,
ProtocolTypeProprietary = 0x7E,
ProtocolTypeMaxReserved = 0x7F
ProtocolTypeUnknown = 0x00,
ProtocolTypeScsi,
ProtocolTypeAta,
ProtocolTypeNvme,
ProtocolTypeSd,
ProtocolTypeProprietary = 0x7E,
ProtocolTypeMaxReserved = 0x7F
} STORAGE_PROTOCOL_TYPE, *PSTORAGE_PROTOCOL_TYPE;
typedef struct _STORAGE_PROTOCOL_SPECIFIC_DATA {
STORAGE_PROTOCOL_TYPE ProtocolType;
DWORD DataType;
DWORD ProtocolDataRequestValue;
DWORD ProtocolDataRequestSubValue;
DWORD ProtocolDataOffset;
DWORD ProtocolDataLength;
DWORD FixedProtocolReturnData;
DWORD Reserved[3];
STORAGE_PROTOCOL_TYPE ProtocolType;
DWORD DataType;
DWORD ProtocolDataRequestValue;
DWORD ProtocolDataRequestSubValue;
DWORD ProtocolDataOffset;
DWORD ProtocolDataLength;
DWORD FixedProtocolReturnData;
DWORD Reserved[3];
} STORAGE_PROTOCOL_SPECIFIC_DATA, *PSTORAGE_PROTOCOL_SPECIFIC_DATA;

typedef enum _STORAGE_PROTOCOL_NVME_DATA_TYPE {
NVMeDataTypeUnknown = 0,
NVMeDataTypeIdentify,
NVMeDataTypeLogPage,
NVMeDataTypeFeature
NVMeDataTypeUnknown = 0,
NVMeDataTypeIdentify,
NVMeDataTypeLogPage,
NVMeDataTypeFeature
} STORAGE_PROTOCOL_NVME_DATA_TYPE, *PSTORAGE_PROTOCOL_NVME_DATA_TYPE;
typedef struct _STORAGE_PROTOCOL_DATA_DESCRIPTOR {
DWORD Version;
DWORD Size;
STORAGE_PROTOCOL_SPECIFIC_DATA ProtocolSpecificData;
DWORD Version;
DWORD Size;
STORAGE_PROTOCOL_SPECIFIC_DATA ProtocolSpecificData;
} STORAGE_PROTOCOL_DATA_DESCRIPTOR, *PSTORAGE_PROTOCOL_DATA_DESCRIPTOR;

#endif
// End of missing stuff


Expand All @@ -90,94 +91,94 @@ void DtaDiskNVMe::init(const char * devref)
0,
NULL);
if (INVALID_HANDLE_VALUE == hDev)
return;
return;
else
isOpen = TRUE;
}

uint8_t DtaDiskNVMe::sendCmd(ATACOMMAND cmd, uint8_t protocol, uint16_t comID,
void * buffer, uint16_t bufferlen)
{
UNREFERENCED_PARAMETER(cmd);
UNREFERENCED_PARAMETER(protocol);
UNREFERENCED_PARAMETER(comID);
UNREFERENCED_PARAMETER(buffer);
UNREFERENCED_PARAMETER(bufferlen);
LOG(D1) << "Entering DtaDiskNVMe::sendCmd";
LOG(D1) << "DtaDiskNVMe::sendCmd Not yet implemented ";
return DTAERROR_COMMAND_ERROR;
UNREFERENCED_PARAMETER(cmd);
UNREFERENCED_PARAMETER(protocol);
UNREFERENCED_PARAMETER(comID);
UNREFERENCED_PARAMETER(buffer);
UNREFERENCED_PARAMETER(bufferlen);
LOG(D1) << "Entering DtaDiskNVMe::sendCmd";
LOG(D1) << "DtaDiskNVMe::sendCmd Not yet implemented ";
return DTAERROR_COMMAND_ERROR;
}

/** adds the IDENTIFY information to the disk_info structure */

void DtaDiskNVMe::identify(OPAL_DiskInfo& disk_info)
{
LOG(D1) << "Entering DtaDiskNVMe::identify()";
PVOID buffer = NULL;
UINT8 *results = NULL;
ULONG bufferLength = 0;
DWORD dwReturned = 0;
BOOL iorc = 0;

PSTORAGE_PROPERTY_QUERY query = NULL;
PSTORAGE_PROTOCOL_SPECIFIC_DATA protocolData = NULL;
PSTORAGE_PROTOCOL_DATA_DESCRIPTOR protocolDataDescr = NULL;
// This buffer allocation is needed because the STORAGE_PROPERTY_QUERY has additional data
// that the nvme driver doesn't use ???????????????????
/* ****************************************************************************************
!!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!!
This buffer definition causes the STORAGE_PROTOCOL_SPECIFIC_DATA to OVERLAY the
STORAGE_PROPERTY_QUERY.AdditionalParameters field
* **************************************************************************************** */
bufferLength = FIELD_OFFSET(STORAGE_PROPERTY_QUERY, AdditionalParameters)
+ sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA) + NVME_MAX_LOG_SIZE;
buffer = malloc(bufferLength);
/* */
if (buffer == NULL) {
LOG(E) << "DeviceNVMeQueryProtocolDataTest: allocate buffer failed, exit.\n";
return;
}

//
// Initialize query data structure to get Identify Data.
//
ZeroMemory(buffer, bufferLength);

query = (PSTORAGE_PROPERTY_QUERY)buffer;
/* ****************************************************************************************
!!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!!
This buffer definition causes the STORAGE_PROTOCOL_SPECIFIC_DATA to OVERLAY the
STORAGE_PROPERTY_QUERY.AdditionalParameters field
* **************************************************************************************** */
protocolDataDescr = (PSTORAGE_PROTOCOL_DATA_DESCRIPTOR)buffer;
protocolData = (PSTORAGE_PROTOCOL_SPECIFIC_DATA)query->AdditionalParameters;
/* */
query->PropertyId = StorageAdapterProtocolSpecificProperty;
query->QueryType = PropertyStandardQuery;

protocolData->ProtocolType = ProtocolTypeNvme;
protocolData->DataType = NVMeDataTypeIdentify;
// protocolData->ProtocolDataRequestValue = NVME_IDENTIFY_CNS_CONTROLLER;
protocolData->ProtocolDataRequestSubValue = 0;
protocolData->ProtocolDataOffset = sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA);
protocolData->ProtocolDataLength = NVME_MAX_LOG_SIZE;

iorc = DeviceIoControl(hDev, IOCTL_STORAGE_QUERY_PROPERTY,
buffer, bufferLength, buffer, bufferLength, &dwReturned, NULL);
PVOID buffer = NULL;
UINT8 *results = NULL;
ULONG bufferLength = 0;
DWORD dwReturned = 0;
BOOL iorc = 0;

PSTORAGE_PROPERTY_QUERY query = NULL;
PSTORAGE_PROTOCOL_SPECIFIC_DATA protocolData = NULL;
PSTORAGE_PROTOCOL_DATA_DESCRIPTOR protocolDataDescr = NULL;
// This buffer allocation is needed because the STORAGE_PROPERTY_QUERY has additional data
// that the nvme driver doesn't use ???????????????????
/* ****************************************************************************************
!!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!!
This buffer definition causes the STORAGE_PROTOCOL_SPECIFIC_DATA to OVERLAY the
STORAGE_PROPERTY_QUERY.AdditionalParameters field
* **************************************************************************************** */
bufferLength = FIELD_OFFSET(STORAGE_PROPERTY_QUERY, AdditionalParameters)
+ sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA) + NVME_MAX_LOG_SIZE;
buffer = malloc(bufferLength);
/* */
if (buffer == NULL) {
LOG(E) << "DeviceNVMeQueryProtocolDataTest: allocate buffer failed, exit.\n";
return;
}

//
// Initialize query data structure to get Identify Data.
//
ZeroMemory(buffer, bufferLength);

query = (PSTORAGE_PROPERTY_QUERY)buffer;
/* ****************************************************************************************
!!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!! !!DANGER WILL ROBINSON!!
This buffer definition causes the STORAGE_PROTOCOL_SPECIFIC_DATA to OVERLAY the
STORAGE_PROPERTY_QUERY.AdditionalParameters field
* **************************************************************************************** */
protocolDataDescr = (PSTORAGE_PROTOCOL_DATA_DESCRIPTOR)buffer;
protocolData = (PSTORAGE_PROTOCOL_SPECIFIC_DATA)query->AdditionalParameters;
/* */
query->PropertyId = StorageAdapterProtocolSpecificProperty;
query->QueryType = PropertyStandardQuery;

protocolData->ProtocolType = ProtocolTypeNvme;
protocolData->DataType = NVMeDataTypeIdentify;
// protocolData->ProtocolDataRequestValue = NVME_IDENTIFY_CNS_CONTROLLER;
protocolData->ProtocolDataRequestSubValue = 0;
protocolData->ProtocolDataOffset = sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA);
protocolData->ProtocolDataLength = NVME_MAX_LOG_SIZE;

iorc = DeviceIoControl(hDev, IOCTL_STORAGE_QUERY_PROPERTY,
buffer, bufferLength, buffer, bufferLength, &dwReturned, NULL);

//
//
//
disk_info.devType = DEVICE_TYPE_NVME;
results = (UINT8 *)buffer + FIELD_OFFSET(STORAGE_PROPERTY_QUERY, AdditionalParameters)
+ sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA);
results += 4;
memcpy(disk_info.serialNum, results, sizeof(disk_info.serialNum));
results += sizeof(disk_info.serialNum);
memcpy(disk_info.modelNum, results, sizeof(disk_info.modelNum));
results += sizeof(disk_info.modelNum);
memcpy(disk_info.firmwareRev, results, sizeof(disk_info.firmwareRev));
results = (UINT8 *)buffer + FIELD_OFFSET(STORAGE_PROPERTY_QUERY, AdditionalParameters)
+ sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA);
results += 4;
memcpy(disk_info.serialNum, results, sizeof(disk_info.serialNum));
results += sizeof(disk_info.serialNum);
memcpy(disk_info.modelNum, results, sizeof(disk_info.modelNum));
results += sizeof(disk_info.modelNum);
memcpy(disk_info.firmwareRev, results, sizeof(disk_info.firmwareRev));

return;
}
Expand Down
Loading