Skip to content

Commit

Permalink
libnvme: add EMVS support to sanitize command
Browse files Browse the repository at this point in the history
Add Enter Media Verification State (EMVS) support to sanitize
command.
TP4152 - Post-Sanitize Media Verification 2024.04.01 Ratified.

Signed-off-by: Francis Pravin <francis.p@samsung.com>
Reviewed-by: Steven Seungcheol Lee <sc108.lee@samsung.com>
  • Loading branch information
francispravin5 authored and igaw committed Oct 10, 2024
1 parent d678aa0 commit 8cdd746
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/nvme/api-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ struct nvme_get_property_args {
* @owpass: Overwrite pass count
* @oipbp: Set to overwrite invert pattern between passes
* @nodas: Set to not deallocate blocks after sanitizing
* @emvs: Set to enter media verification state
*/
struct nvme_sanitize_nvm_args {
__u32 *result;
Expand All @@ -523,6 +524,7 @@ struct nvme_sanitize_nvm_args {
__u8 owpass;
bool oipbp;
bool nodas;
bool emvs;
};

/**
Expand Down
29 changes: 19 additions & 10 deletions src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,12 +1641,25 @@ int nvme_get_property(struct nvme_get_property_args *args)

int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args)
{
__u32 cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) |
NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) |
NVME_SET(args->owpass, SANITIZE_CDW10_OWPASS) |
NVME_SET(!!args->oipbp, SANITIZE_CDW10_OIPBP) |
NVME_SET(!!args->nodas, SANITIZE_CDW10_NODAS);
__u32 cdw11 = args->ovrpat;
const size_t size_v1 = sizeof_args(struct nvme_sanitize_nvm_args, nodas, __u64);
const size_t size_v2 = sizeof_args(struct nvme_sanitize_nvm_args, emvs, __u64);
__u32 cdw10, cdw11;

if (args->args_size < size_v1 || args->args_size > size_v2) {
errno = EINVAL;
return -1;
}

cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) |
NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) |
NVME_SET(args->owpass, SANITIZE_CDW10_OWPASS) |
NVME_SET(!!args->oipbp, SANITIZE_CDW10_OIPBP) |
NVME_SET(!!args->nodas, SANITIZE_CDW10_NODAS);

if (args->args_size == size_v2)
cdw10 |= NVME_SET(!!args->emvs, SANITIZE_CDW10_EMVS);

cdw11 = args->ovrpat;

struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_sanitize_nvm,
Expand All @@ -1655,10 +1668,6 @@ int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args)
.timeout_ms = args->timeout,
};

if (args->args_size < sizeof(*args)) {
errno = EINVAL;
return -1;
}
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
}

Expand Down
2 changes: 2 additions & 0 deletions src/nvme/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,13 @@ enum nvme_cmd_dword_fields {
NVME_SANITIZE_CDW10_OWPASS_SHIFT = 4,
NVME_SANITIZE_CDW10_OIPBP_SHIFT = 8,
NVME_SANITIZE_CDW10_NODAS_SHIFT = 9,
NVME_SANITIZE_CDW10_EMVS_SHIFT = 10,
NVME_SANITIZE_CDW10_SANACT_MASK = 0x7,
NVME_SANITIZE_CDW10_AUSE_MASK = 0x1,
NVME_SANITIZE_CDW10_OWPASS_MASK = 0xf,
NVME_SANITIZE_CDW10_OIPBP_MASK = 0x1,
NVME_SANITIZE_CDW10_NODAS_MASK = 0x1,
NVME_SANITIZE_CDW10_EMVS_MASK = 0x1,
NVME_SECURITY_NSSF_SHIFT = 0,
NVME_SECURITY_SPSP0_SHIFT = 8,
NVME_SECURITY_SPSP1_SHIFT = 16,
Expand Down
2 changes: 2 additions & 0 deletions src/nvme/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -8257,12 +8257,14 @@ enum nvme_directive_send_identify_endir {
* @NVME_SANITIZE_SANACT_START_BLOCK_ERASE: Start a Block Erase sanitize operation.
* @NVME_SANITIZE_SANACT_START_OVERWRITE: Start an Overwrite sanitize operation.
* @NVME_SANITIZE_SANACT_START_CRYPTO_ERASE: Start a Crypto Erase sanitize operation.
* @NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF: Exit Media Verification State
*/
enum nvme_sanitize_sanact {
NVME_SANITIZE_SANACT_EXIT_FAILURE = 1,
NVME_SANITIZE_SANACT_START_BLOCK_ERASE = 2,
NVME_SANITIZE_SANACT_START_OVERWRITE = 3,
NVME_SANITIZE_SANACT_START_CRYPTO_ERASE = 4,
NVME_SANITIZE_SANACT_EXIT_MEDIA_VERIF = 5,
};

/**
Expand Down

0 comments on commit 8cdd746

Please sign in to comment.