Skip to content

Commit f337043

Browse files
Davidlohr Buesodjbw
authored andcommitted
cxl/test: Add Secure Erase opcode support
Add support to emulate the CXL the "Secure Erase" operation. Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net> Link: https://lore.kernel.org/r/20230612181038.14421-8-dave@stgolabs.net Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 180ffd3 commit f337043

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • tools/testing/cxl/test

tools/testing/cxl/test/mem.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,30 @@ static int mock_sanitize(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
557557
return 0; /* assume less than 2 secs, no bg */
558558
}
559559

560+
static int mock_secure_erase(struct cxl_dev_state *cxlds,
561+
struct cxl_mbox_cmd *cmd)
562+
{
563+
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
564+
565+
if (cmd->size_in != 0)
566+
return -EINVAL;
567+
568+
if (cmd->size_out != 0)
569+
return -EINVAL;
570+
571+
if (mdata->security_state & CXL_PMEM_SEC_STATE_USER_PASS_SET) {
572+
cmd->return_code = CXL_MBOX_CMD_RC_SECURITY;
573+
return -ENXIO;
574+
}
575+
576+
if (mdata->security_state & CXL_PMEM_SEC_STATE_LOCKED) {
577+
cmd->return_code = CXL_MBOX_CMD_RC_SECURITY;
578+
return -ENXIO;
579+
}
580+
581+
return 0;
582+
}
583+
560584
static int mock_get_security_state(struct cxl_dev_state *cxlds,
561585
struct cxl_mbox_cmd *cmd)
562586
{
@@ -1178,6 +1202,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
11781202
case CXL_MBOX_OP_SANITIZE:
11791203
rc = mock_sanitize(cxlds, cmd);
11801204
break;
1205+
case CXL_MBOX_OP_SECURE_ERASE:
1206+
rc = mock_secure_erase(cxlds, cmd);
1207+
break;
11811208
case CXL_MBOX_OP_GET_SECURITY_STATE:
11821209
rc = mock_get_security_state(cxlds, cmd);
11831210
break;

0 commit comments

Comments
 (0)