Skip to content

Commit

Permalink
Initial draft of MEDIA_SANITIZE protocol with NVM Express Support (#107)
Browse files Browse the repository at this point in the history
Implementation of MEDIA_SANITIZE_PROTOCOL for NIST purge/clear actions with mapping to NVM Express native commands.
  • Loading branch information
rayrobles authored and kenlautner committed May 9, 2023
1 parent f43d29c commit 4eb232c
Show file tree
Hide file tree
Showing 11 changed files with 2,138 additions and 30 deletions.
23 changes: 22 additions & 1 deletion MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
NVM Express specification.
Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
Expand Down Expand Up @@ -181,6 +182,26 @@ EnumerateNvmeDevNamespace (
Device->BlockIo2.FlushBlocksEx = NvmeBlockIoFlushBlocksEx;
InitializeListHead (&Device->AsyncQueue);

//
// Create Media Sanitize Protocol instance
//
Device->MediaSanitize.Revision = MEDIA_SANITIZE_PROTOCOL_REVISION;
Device->MediaSanitize.Media = &Device->Media;
Device->MediaSanitize.MediaClear = NvmExpressMediaClear;
Device->MediaSanitize.MediaPurge = NvmExpressMediaPurge;
Device->MediaSanitize.MediaFormat = NvmExpressMediaFormat;

ASSERT (
sizeof (Device->MediaSanitize.SanitizeCapabilities) ==
sizeof (Device->Controller->ControllerData->Sanicap)
);

CopyMem (
&(Device->MediaSanitize.SanitizeCapabilities),
&(Device->Controller->ControllerData->Sanicap),
sizeof (Device->MediaSanitize.SanitizeCapabilities)
);

//
// Create StorageSecurityProtocol Instance
//
Expand Down
40 changes: 38 additions & 2 deletions MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
NVM Express specification.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
Expand All @@ -29,6 +30,7 @@
#include <Protocol/DriverSupportedEfiVersion.h>
#include <Protocol/StorageSecurityCommand.h>
#include <Protocol/ResetNotification.h>
#include <Protocol/MediaSanitize.h>

#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
Expand All @@ -51,6 +53,7 @@ typedef struct _NVME_DEVICE_PRIVATE_DATA NVME_DEVICE_PRIVATE_DATA;
#include "NvmExpressBlockIo.h"
#include "NvmExpressDiskInfo.h"
#include "NvmExpressHci.h"
#include "NvmExpressMediaSanitize.h"

extern EFI_DRIVER_BINDING_PROTOCOL gNvmExpressDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gNvmExpressComponentName;
Expand Down Expand Up @@ -84,6 +87,30 @@ extern EFI_GUID gNVMeEnableCompleteEventGroupGuid;

#define NVME_MAX_QUEUES 3 // Number of queues supported by the driver

//
// FormatNVM Admin Command LBA Format (LBAF) Mask
//
#define NVME_LBA_FORMATNVM_LBAF_MASK 0xF

//
// NVMe Completion Queue Entry Bits, Fields, Masks
//
#define NVME_CQE_STATUS_FIELD_MASK 0xFFFF0000
#define NVME_CQE_STATUS_FIELD_OFFSET 16
#define NVME_CQE_STATUS_FIELD_SCT_MASK 0x0E00
#define NVME_CQE_STATUS_FIELD_SCT_OFFSET 0x9
#define NVME_CQE_STATUS_FIELD_SC_MASK 0x1FE
#define NVME_CQE_STATUS_FIELD_SC_OFFSET 0x01
#define NVME_CQE_SCT_GENERIC_CMD_STATUS 0x0
#define NVME_CQE_SCT_CMD_SPECIFIC_STATUS 0x1
#define NVME_CQE_SCT_MEDIA_DATA_INTEGRITY_ERRORS_STATUS 0x2
#define NVME_CQE_SCT_PATH_RELATED_STATUS 0x3
#define NVME_CQE_SC_SUCCESSFUL_COMPLETION 0x00
#define NVME_CQE_SC_INVALID_CMD_OPCODE 0x01
#define NVME_CQE_SC_INVALID_FIELD_IN_CMD 0x02

#define NVME_ALL_NAMESPACES 0xFFFFFFFF

// MU_CHANGE [BEGIN] - Support alternative hardware queue sizes in NVME driver

//
Expand Down Expand Up @@ -224,6 +251,8 @@ struct _NVME_DEVICE_PRIVATE_DATA {
EFI_DISK_INFO_PROTOCOL DiskInfo;
EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;

MEDIA_SANITIZE_PROTOCOL MediaSanitize;

LIST_ENTRY AsyncQueue;

EFI_LBA NumBlocks;
Expand Down Expand Up @@ -265,6 +294,13 @@ struct _NVME_DEVICE_PRIVATE_DATA {
NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
)

#define NVME_DEVICE_PRIVATE_DATA_FROM_MEDIA_SANITIZE(a) \
CR (a, \
NVME_DEVICE_PRIVATE_DATA, \
MediaSanitize, \
NVME_DEVICE_PRIVATE_DATA_SIGNATURE \
)

//
// Nvme block I/O 2 request.
//
Expand Down
5 changes: 4 additions & 1 deletion MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# NVM Express specification.
#
# Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.<BR>
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
Expand Down Expand Up @@ -40,6 +40,8 @@
NvmExpressHci.c
NvmExpressHci.h
NvmExpressPassthru.c
NvmExpressMediaSanitize.c
NvmExpressMediaSanitize.h

## MSChange [BEGIN]
[Guids]
Expand Down Expand Up @@ -74,6 +76,7 @@
gEfiDiskInfoProtocolGuid ## BY_START
gEfiStorageSecurityCommandProtocolGuid ## BY_START
gEfiDriverSupportedEfiVersionProtocolGuid ## PRODUCES
gMediaSanitizeProtocolGuid ## PRODUCES
gEfiResetNotificationProtocolGuid ## CONSUMES

[Pcd]
Expand Down
Loading

0 comments on commit 4eb232c

Please sign in to comment.