Commit 1fa99be3 authored by Dave Jiang's avatar Dave Jiang Committed by Dan Williams

tools/testing/cxl: Add "Get Security State" opcode support

Add the emulation support for handling "Get Security State" opcode for a
CXL memory device for the cxl_test. The function will copy back device
security state bitmask to the output payload.

The security state data is added as platform_data for the mock mem device.
Reviewed-by: default avatarDavidlohr Bueso <dave@stgolabs.net>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/166983610177.2734609.4953959949148428755.stgit@djiang5-desk3.ch.intel.comSigned-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 32828115
...@@ -65,6 +65,11 @@ static struct { ...@@ -65,6 +65,11 @@ static struct {
}, },
}; };
struct cxl_mockmem_data {
void *lsa;
u32 security_state;
};
static int mock_gsl(struct cxl_mbox_cmd *cmd) static int mock_gsl(struct cxl_mbox_cmd *cmd)
{ {
if (cmd->size_out < sizeof(mock_gsl_payload)) if (cmd->size_out < sizeof(mock_gsl_payload))
...@@ -137,10 +142,27 @@ static int mock_partition_info(struct cxl_dev_state *cxlds, ...@@ -137,10 +142,27 @@ static int mock_partition_info(struct cxl_dev_state *cxlds,
return 0; return 0;
} }
static int mock_get_security_state(struct cxl_dev_state *cxlds,
struct cxl_mbox_cmd *cmd)
{
struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
if (cmd->size_in)
return -EINVAL;
if (cmd->size_out != sizeof(u32))
return -EINVAL;
memcpy(cmd->payload_out, &mdata->security_state, sizeof(u32));
return 0;
}
static int mock_get_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) static int mock_get_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
{ {
struct cxl_mbox_get_lsa *get_lsa = cmd->payload_in; struct cxl_mbox_get_lsa *get_lsa = cmd->payload_in;
void *lsa = dev_get_drvdata(cxlds->dev); struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
void *lsa = mdata->lsa;
u32 offset, length; u32 offset, length;
if (sizeof(*get_lsa) > cmd->size_in) if (sizeof(*get_lsa) > cmd->size_in)
...@@ -159,7 +181,8 @@ static int mock_get_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) ...@@ -159,7 +181,8 @@ static int mock_get_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
static int mock_set_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) static int mock_set_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
{ {
struct cxl_mbox_set_lsa *set_lsa = cmd->payload_in; struct cxl_mbox_set_lsa *set_lsa = cmd->payload_in;
void *lsa = dev_get_drvdata(cxlds->dev); struct cxl_mockmem_data *mdata = dev_get_drvdata(cxlds->dev);
void *lsa = mdata->lsa;
u32 offset, length; u32 offset, length;
if (sizeof(*set_lsa) > cmd->size_in) if (sizeof(*set_lsa) > cmd->size_in)
...@@ -230,6 +253,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd * ...@@ -230,6 +253,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
case CXL_MBOX_OP_GET_HEALTH_INFO: case CXL_MBOX_OP_GET_HEALTH_INFO:
rc = mock_health_info(cxlds, cmd); rc = mock_health_info(cxlds, cmd);
break; break;
case CXL_MBOX_OP_GET_SECURITY_STATE:
rc = mock_get_security_state(cxlds, cmd);
break;
default: default:
break; break;
} }
...@@ -250,16 +276,20 @@ static int cxl_mock_mem_probe(struct platform_device *pdev) ...@@ -250,16 +276,20 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct cxl_memdev *cxlmd; struct cxl_memdev *cxlmd;
struct cxl_dev_state *cxlds; struct cxl_dev_state *cxlds;
void *lsa; struct cxl_mockmem_data *mdata;
int rc; int rc;
lsa = vmalloc(LSA_SIZE); mdata = devm_kzalloc(dev, sizeof(*mdata), GFP_KERNEL);
if (!lsa) if (!mdata)
return -ENOMEM;
dev_set_drvdata(dev, mdata);
mdata->lsa = vmalloc(LSA_SIZE);
if (!mdata->lsa)
return -ENOMEM; return -ENOMEM;
rc = devm_add_action_or_reset(dev, label_area_release, lsa); rc = devm_add_action_or_reset(dev, label_area_release, mdata->lsa);
if (rc) if (rc)
return rc; return rc;
dev_set_drvdata(dev, lsa);
cxlds = cxl_dev_state_create(dev); cxlds = cxl_dev_state_create(dev);
if (IS_ERR(cxlds)) if (IS_ERR(cxlds))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment