Skip to content

Commit e77e9c1

Browse files
davejiangjgunthorpe
authored andcommitted
cxl/test: Add Get Feature support to cxl_test
Add emulation of Get Feature command to cxl_test. The feature for device patrol scrub is returned by the emulation code. This is the only feature currently supported by cxl_test. It returns the information for the device patrol scrub feature. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Li Ming <[email protected]> Signed-off-by: Dave Jiang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent eb5dfcb commit e77e9c1

File tree

1 file changed

+56
-0
lines changed
  • tools/testing/cxl/test

1 file changed

+56
-0
lines changed

tools/testing/cxl/test/mem.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ static struct cxl_cel_entry mock_cel[] = {
4848
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_SUPPORTED_FEATURES),
4949
.effect = CXL_CMD_EFFECT_NONE,
5050
},
51+
{
52+
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_FEATURE),
53+
.effect = CXL_CMD_EFFECT_NONE,
54+
},
5155
{
5256
.opcode = cpu_to_le16(CXL_MBOX_OP_IDENTIFY),
5357
.effect = CXL_CMD_EFFECT_NONE,
@@ -149,6 +153,10 @@ struct mock_event_store {
149153
u32 ev_status;
150154
};
151155

156+
struct vendor_test_feat {
157+
__le32 data;
158+
} __packed;
159+
152160
struct cxl_mockmem_data {
153161
void *lsa;
154162
void *fw;
@@ -165,6 +173,7 @@ struct cxl_mockmem_data {
165173
u8 event_buf[SZ_4K];
166174
u64 timestamp;
167175
unsigned long sanitize_timeout;
176+
struct vendor_test_feat test_feat;
168177
};
169178

170179
static struct mock_event_log *event_find_log(struct device *dev, int log_type)
@@ -1379,6 +1388,44 @@ static void fill_feature_vendor_test(struct cxl_feat_entry *feat)
13791388

13801389
#define MAX_CXL_TEST_FEATS 1
13811390

1391+
static int mock_get_test_feature(struct cxl_mockmem_data *mdata,
1392+
struct cxl_mbox_cmd *cmd)
1393+
{
1394+
struct vendor_test_feat *output = cmd->payload_out;
1395+
struct cxl_mbox_get_feat_in *input = cmd->payload_in;
1396+
u16 offset = le16_to_cpu(input->offset);
1397+
u16 count = le16_to_cpu(input->count);
1398+
u8 *ptr;
1399+
1400+
if (offset > sizeof(*output)) {
1401+
cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
1402+
return -EINVAL;
1403+
}
1404+
1405+
if (offset + count > sizeof(*output)) {
1406+
cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
1407+
return -EINVAL;
1408+
}
1409+
1410+
ptr = (u8 *)&mdata->test_feat + offset;
1411+
memcpy((u8 *)output + offset, ptr, count);
1412+
1413+
return 0;
1414+
}
1415+
1416+
static int mock_get_feature(struct cxl_mockmem_data *mdata,
1417+
struct cxl_mbox_cmd *cmd)
1418+
{
1419+
struct cxl_mbox_get_feat_in *input = cmd->payload_in;
1420+
1421+
if (uuid_equal(&input->uuid, &CXL_VENDOR_FEATURE_TEST))
1422+
return mock_get_test_feature(mdata, cmd);
1423+
1424+
cmd->return_code = CXL_MBOX_CMD_RC_UNSUPPORTED;
1425+
1426+
return -EOPNOTSUPP;
1427+
}
1428+
13821429
static int mock_get_supported_features(struct cxl_mockmem_data *mdata,
13831430
struct cxl_mbox_cmd *cmd)
13841431
{
@@ -1509,6 +1556,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,
15091556
case CXL_MBOX_OP_GET_SUPPORTED_FEATURES:
15101557
rc = mock_get_supported_features(mdata, cmd);
15111558
break;
1559+
case CXL_MBOX_OP_GET_FEATURE:
1560+
rc = mock_get_feature(mdata, cmd);
1561+
break;
15121562
default:
15131563
break;
15141564
}
@@ -1556,6 +1606,11 @@ static int cxl_mock_mailbox_create(struct cxl_dev_state *cxlds)
15561606
return 0;
15571607
}
15581608

1609+
static void cxl_mock_test_feat_init(struct cxl_mockmem_data *mdata)
1610+
{
1611+
mdata->test_feat.data = cpu_to_le32(0xdeadbeef);
1612+
}
1613+
15591614
static int cxl_mock_mem_probe(struct platform_device *pdev)
15601615
{
15611616
struct device *dev = &pdev->dev;
@@ -1651,6 +1706,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
16511706
dev_dbg(dev, "No CXL FWCTL setup\n");
16521707

16531708
cxl_mem_get_event_records(mds, CXLDEV_EVENT_STATUS_ALL);
1709+
cxl_mock_test_feat_init(mdata);
16541710

16551711
return 0;
16561712
}

0 commit comments

Comments
 (0)