54 IN UINT32 NamespaceId,
74 Status = EFI_NOT_STARTED;
76 Device = NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO (This);
83 NewNamespaceData =
NULL;
91 CommandPacket.NvmeCmd = &Command;
92 CommandPacket.NvmeCompletion = &Completion;
93 CommandPacket.CommandTimeout = NVME_GENERIC_TIMEOUT;
94 CommandPacket.QueueType = NVME_ADMIN_QUEUE;
95 Command.Cdw0.Opcode = NVME_ADMIN_FORMAT_NVM_CMD;
96 Command.Nsid = NamespaceId;
101 FormatNvmCdw10.Ses = Ses;
108 LbaFormat = (Flbas == 0 ? Device->NamespaceData.Flbas : Flbas);
109 FormatNvmCdw10.Lbaf = LbaFormat & NVME_LBA_FORMATNVM_LBAF_MASK;
118 Status = Device->Controller->Passthru.PassThru (
119 &(Device->Controller->Passthru),
125 if (EFI_ERROR (Status)) {
126 StatusField = (UINT16)((CommandPacket.NvmeCompletion->DW3 & NVME_CQE_STATUS_FIELD_MASK) >>
127 NVME_CQE_STATUS_FIELD_OFFSET);
129 Sc = (StatusField & NVME_CQE_STATUS_FIELD_SC_MASK) >> NVME_CQE_STATUS_FIELD_SC_OFFSET;
130 Sct = (StatusField & NVME_CQE_STATUS_FIELD_SCT_MASK) >> NVME_CQE_STATUS_FIELD_SCT_OFFSET;
132 DEBUG ((DEBUG_ERROR,
"%a: NVMe FormatNVM admin command failed SCT = 0x%x, SC = 0x%x\n", __func__, Sct, Sc));
141 if (NewNamespaceData ==
NULL) {
142 Status = EFI_OUT_OF_RESOURCES;
147 (VOID *)NewNamespaceData
150 if (!EFI_ERROR (Status)) {
154 NewFlbas = NewNamespaceData->Flbas;
155 LbaFmtIdx = NewFlbas & NVME_LBA_FORMATNVM_LBAF_MASK;
156 Lbads = NewNamespaceData->LbaFormat[LbaFmtIdx].Lbads;
157 Device->Media.
BlockSize = (UINT32)1 << Lbads;
158 Device->Media.
LastBlock = NewNamespaceData->Nsze - 1;
198 IN UINT32 NamespaceId,
199 IN UINT32 SanitizeAction,
200 IN UINT32 NoDeallocAfterSanitize,
201 IN UINT32 OverwritePattern
215 Device = NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO (This);
227 CommandPacket.NvmeCmd = &Command;
228 CommandPacket.NvmeCompletion = &Completion;
229 CommandPacket.CommandTimeout = NVME_GENERIC_TIMEOUT;
230 CommandPacket.QueueType = NVME_ADMIN_QUEUE;
231 Command.Cdw0.Opcode = NVME_ADMIN_SANITIZE_CMD;
232 Command.Nsid = NamespaceId;
234 SanitizeCdw10Cdw11.Nodas = NoDeallocAfterSanitize;
235 SanitizeCdw10Cdw11.Sanact = SanitizeAction;
236 SanitizeCdw10Cdw11.Ovrpat = OverwritePattern;
242 Status = Device->Controller->Passthru.PassThru (
243 &(Device->Controller->Passthru),
249 if (EFI_ERROR (Status)) {
250 StatusField = (UINT16)((CommandPacket.NvmeCompletion->DW3 & NVME_CQE_STATUS_FIELD_MASK) >>
251 NVME_CQE_STATUS_FIELD_OFFSET);
253 Sc = (StatusField & NVME_CQE_STATUS_FIELD_SC_MASK) >> NVME_CQE_STATUS_FIELD_SC_OFFSET;
254 Sct = (StatusField & NVME_CQE_STATUS_FIELD_SCT_MASK) >> NVME_CQE_STATUS_FIELD_SCT_OFFSET;
256 DEBUG ((DEBUG_ERROR,
"%a: NVMe Sanitize admin command failed SCT = 0x%x, SC = 0x%x\n", __func__, Sct, Sc));
264 if ((Sct == NVME_CQE_SCT_GENERIC_CMD_STATUS) &&
265 (Sc == NVME_CQE_SC_INVALID_CMD_OPCODE))
267 switch (SanitizeCdw10Cdw11.Sanact) {
268 case SANITIZE_ACTION_BLOCK_ERASE:
269 FnvmSes = SES_USER_DATA_ERASE;
271 case SANITIZE_ACTION_CRYPTO_ERASE:
272 FnvmSes = SES_CRYPTO_ERASE;
274 case SANITIZE_ACTION_OVERWRITE:
275 case SANITIZE_ACTION_EXIT_FAILURE_MODE:
280 FnvmSes = SES_NO_SECURE_ERASE;
284 if ((FnvmSes == SES_USER_DATA_ERASE) || (FnvmSes == SES_CRYPTO_ERASE)) {
285 Status = NvmExpressFormatNvm (
326NvmExpressMediaClear (
330 IN VOID *SectorOwBuffer
336 UINT32 TotalPassCount;
343 return EFI_INVALID_PARAMETER;
346 Device = NVME_DEVICE_PRIVATE_DATA_FROM_MEDIA_SANITIZE (This);
347 Media = &Device->Media;
351 return EFI_MEDIA_CHANGED;
359 if (SectorOwBuffer ==
NULL) {
360 return EFI_INVALID_PARAMETER;
366 for (TotalPassCount = 0; TotalPassCount < PassCount; TotalPassCount++) {
367 for (SectorOffset = 0; SectorOffset < Media->
LastBlock; SectorOffset++ ) {
368 Status = Device->BlockIo.WriteBlocks (
413NvmExpressMediaPurge (
416 IN UINT32 PurgeAction,
417 IN UINT32 OverwritePattern
423 UINT32 SanitizeAction;
432 return EFI_INVALID_PARAMETER;
435 Device = NVME_DEVICE_PRIVATE_DATA_FROM_MEDIA_SANITIZE (This);
436 NamespaceId = Device->NamespaceId;
437 Media = &Device->Media;
438 SaniCap = Device->Controller->ControllerData->Sanicap;
442 return EFI_MEDIA_CHANGED;
450 if (((PurgeAction & PURGE_ACTION_OVERWRITE) == PURGE_ACTION_OVERWRITE) && (SaniCap.Ows)) {
451 SanitizeAction = SANITIZE_ACTION_OVERWRITE;
452 }
else if (((PurgeAction & PURGE_ACTION_BLOCK_ERASE) == PURGE_ACTION_BLOCK_ERASE) && (SaniCap.Bes)) {
453 SanitizeAction = SANITIZE_ACTION_BLOCK_ERASE;
454 }
else if (((PurgeAction & PURGE_ACTION_CRYPTO_ERASE) == PURGE_ACTION_CRYPTO_ERASE) && (SaniCap.Ces)) {
455 SanitizeAction = SANITIZE_ACTION_CRYPTO_ERASE;
457 SanitizeAction = SANITIZE_ACTION_NO_ACTION;
460 if ((PurgeAction & PURGE_ACTION_NO_DEALLOCATE) == PURGE_ACTION_NO_DEALLOCATE) {
461 NoDeallocate = NVME_NO_DEALLOCATE_AFTER_SANITZE;
467 Status = NvmExpressSanitize (
503NvmExpressMediaFormat (
507 IN UINT32 SecureEraseAction
513 UINT32 SecureEraseSettings;
515 BOOLEAN LbaSizeIsSupported;
522 return EFI_INVALID_PARAMETER;
525 Device = NVME_DEVICE_PRIVATE_DATA_FROM_MEDIA_SANITIZE (This);
526 NamespaceId = Device->NamespaceId;
527 Media = &Device->Media;
532 return EFI_MEDIA_CHANGED;
538 switch (SecureEraseAction) {
539 case FORMAT_SES_USER_DATA_ERASE:
540 SecureEraseSettings = SES_USER_DATA_ERASE;
542 case FORMAT_SES_CRYPTOGRAPHIC_ERASE:
543 SecureEraseSettings = SES_CRYPTO_ERASE;
550 SecureEraseSettings = SES_NO_SECURE_ERASE;
562 LbaSizeIsSupported =
FALSE;
563 for (FlbaIndex = 0; FlbaIndex < Device->NamespaceData.Nlbaf; FlbaIndex++) {
564 if (Device->NamespaceData.LbaFormat[FlbaIndex].Lbads == LbaSize) {
565 LbaSizeIsSupported =
TRUE;
570 if (LbaSizeIsSupported) {
571 Status = NvmExpressFormatNvm (
578 Status = EFI_INVALID_PARAMETER;
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define DEBUG(Expression)
EFI_STATUS NvmeIdentifyNamespace(IN NVME_CONTROLLER_PRIVATE_DATA *Private, IN UINT32 NamespaceId, IN VOID *Buffer)