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 ?

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?

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

Reply via email to