Skip to content

Commit 6ec4b6d

Browse files
AlisonSchofielddjbw
authored andcommitted
tools/testing/cxl: Mock the Clear Poison mailbox command
Mock the clear of poison by deleting the device:address entry from the mock_poison_list[]. Behave like a real CXL device and do not fail if the address is not in the poison list, but offer a dev_dbg() message. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/ecf19743c6572e60971bbd078f67d520cf5bca5d.1681874357.git.alison.schofield@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 371c161 commit 6ec4b6d

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

  • tools/testing/cxl/test

tools/testing/cxl/test/mem.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ static struct cxl_cel_entry mock_cel[] = {
5252
.opcode = cpu_to_le16(CXL_MBOX_OP_INJECT_POISON),
5353
.effect = cpu_to_le16(0),
5454
},
55+
{
56+
.opcode = cpu_to_le16(CXL_MBOX_OP_CLEAR_POISON),
57+
.effect = cpu_to_le16(0),
58+
},
5559
};
5660

5761
/* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -997,6 +1001,35 @@ static int mock_inject_poison(struct cxl_dev_state *cxlds,
9971001
return 0;
9981002
}
9991003

1004+
static bool mock_poison_del(struct cxl_dev_state *cxlds, u64 dpa)
1005+
{
1006+
for (int i = 0; i < MOCK_INJECT_TEST_MAX; i++) {
1007+
if (mock_poison_list[i].cxlds == cxlds &&
1008+
mock_poison_list[i].dpa == dpa) {
1009+
mock_poison_list[i].cxlds = NULL;
1010+
return true;
1011+
}
1012+
}
1013+
return false;
1014+
}
1015+
1016+
static int mock_clear_poison(struct cxl_dev_state *cxlds,
1017+
struct cxl_mbox_cmd *cmd)
1018+
{
1019+
struct cxl_mbox_clear_poison *pi = cmd->payload_in;
1020+
u64 dpa = le64_to_cpu(pi->address);
1021+
1022+
/*
1023+
* A real CXL device will write pi->write_data to the address
1024+
* being cleared. In this mock, just delete this address from
1025+
* the mock poison list.
1026+
*/
1027+
if (!mock_poison_del(cxlds, dpa))
1028+
dev_dbg(cxlds->dev, "DPA: 0x%llx not in poison list\n", dpa);
1029+
1030+
return 0;
1031+
}
1032+
10001033
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
10011034
{
10021035
struct device *dev = cxlds->dev;
@@ -1057,6 +1090,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
10571090
case CXL_MBOX_OP_INJECT_POISON:
10581091
rc = mock_inject_poison(cxlds, cmd);
10591092
break;
1093+
case CXL_MBOX_OP_CLEAR_POISON:
1094+
rc = mock_clear_poison(cxlds, cmd);
1095+
break;
10601096
default:
10611097
break;
10621098
}

0 commit comments

Comments
 (0)