Hi,

Some comments below:

> -----Original Message-----
> From: edk2-devel [mailto:[email protected]] On Behalf Of
> Rafael Machado
> Sent: Wednesday, March 28, 2018 9:32 PM
> To: [email protected]
> Subject: [edk2] NVMe Smart Data Buffer Size
> 
> Hi everyone
> 
> I'am working on a development related to retrieving the SMART data
> information from a NVMe device.
> After some research I got to a code that works correctly, but I would like
> to have a 100% understanding of why it works.
> 
> To retrieve the SMART data I send the command
> (EFI_NVM_EXPRESS_COMMAND) as
> follows:
> 
> //************************************************************
> //Fill the EFI_NVM_EXPRESS_COMMAND struct
> Command->Cdw0.Opcode = NVME_ADMIN_GET_LOG_PAGE_CMD; //This is
> the command
> 0x02
> Command->Nsid =   NVME_ALL_VALID_NSID; //The NSID used in this case is
> the 0xFFFFFFFF to retrieve the global information
> Command->Cdw10 =  (4096 << 16) | 2; // page 2 is the Smart/Health log page
> Command->Cdw11 =  0x0;
> Command->Cdw12 =  0x0;
> Command->Cdw13 =  0x0;
> Command->Flags =  CDW10_VALID
>                                  | CDW11_VALID
>                                  | CDW12_VALID
>                                  | CDW13_VALID;
> 
> // Fill the EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET struct
> This->Nsid = NVME_ALL_VALID_NSID;  //This is the NSID used by
> the NVME_PROTOCOL, that is also 0xFFFFFFFF
> CommandPacket->NvmeCmd        = Command;
> CommandPacket->NvmeCompletion = Completion;
> CommandPacket->TransferBuffer = (VOID*) SmartData;
> CommandPacket->TransferLength = 4096;
> CommandPacket->CommandTimeout = 0;
> CommandPacket->QueueType      = NVME_ADMIN_QUEUE;
> CommandPacket->MetadataBuffer = NULL;
> CommandPacket->MetadataLength = 0;
> //************************************************************
> 
> The question I have, is about the size of the buffer to be used as the
> transfer buffer at the EFI_NVM_EXPRESS_COMMAND and at the
> EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET. At the Nvme spec we
> see that the
> SmartData information is 512 bytes long.
> 
> So the question is.
> Why, even having just 512 bytes to be retrieved by the GetLogCommand page
> 0x02, do I need to create a 4096 bytes buffer to retrieve the SMART data ?

I have a check on the NVMe v1.1 spec for the Get Log Page command:

For Command Dword 10:
27:16 Number of Dwords (NUMD):
This field specifies the number of Dwords to return. If host software
specifies a size larger than the log page requested, the results are
undefined. This is a 0's based value.

Per my understanding, since the field requires a 0's based Dword value,
for getting the SMART / Health Information (which is 512 bytes in length),
the Cdw10 should be:
Command->Cdw10 =  (127 << 16) | 2; // 128 Dword, 0's based

And for the PassThru command packet:
CommandPacket->TransferLength = 512;

Please help to verify if this works properly for you. Thanks in advance.

> 
> Command->Cdw10 =  (4096 << 16) | 2;
> CommandPacket->TransferBuffer = (VOID*) SmartData; (allocated previously)
> CommandPacket->TransferLength = 4096;
> 
> Just for reference. When I create a 512 bytes buffer I get a DeviceError
> status after the PassThru. With the sample code below:
> 
> Command->Cdw10 =  (512 << 16) | 2;
> CommandPacket->TransferBuffer = (VOID*) SmartData; (allocated previously)
> CommandPacket->TransferLength = 512;
> 
> 
> Another question I have is:
> We have two places that we need to set the Nsid.
> 
> EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET. Nsid
> EFI_NVM_EXPRESS_COMMAND.Nsid
> 
> Since I am not a NVme expert, my question is if both represent the same
> information.
> Should I use 0xFFFFFFFF in both?

Yes, you are right.

These two values:
NamespaceId param for EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.PassThru() and
Nsid field of EFI_NVM_EXPRESS_COMMAND

should be set to the same value.

Best Regards,
Hao Wu

> 
> Thanks and Regards
> Rafael R. Machado
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to