[PATCH v3 6/6] tools/testing/cxl: Mock the Get Poison List mbox command

From: alison . schofield
Date: Thu Nov 10 2022 - 22:13:18 EST


From: Alison Schofield <alison.schofield@xxxxxxxxx>

Return fake poison error records when the get poison list mbox
command is issued. This supports testing the kernel tracing
and cxl list capabilities for media errors.

Signed-off-by: Alison Schofield <alison.schofield@xxxxxxxxx>
---
tools/testing/cxl/test/mem.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)

diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c
index f0704d090073..f729e055605d 100644
--- a/tools/testing/cxl/test/mem.c
+++ b/tools/testing/cxl/test/mem.c
@@ -38,6 +38,10 @@ static struct cxl_cel_entry mock_cel[] = {
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
.effect = cpu_to_le16(0),
},
+ {
+ .opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON),
+ .effect = cpu_to_le16(0),
+ },
};

/* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -207,6 +211,30 @@ static int mock_health_info(struct cxl_dev_state *cxlds,
return 0;
}

+static int mock_get_poison(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
+{
+ struct {
+ struct cxl_mbox_poison_payload_out poison_out;
+ struct cxl_poison_record record;
+ } mock_poison_list = {
+ .poison_out = {
+ .count = cpu_to_le16(1),
+ },
+ .record = {
+ /* .address encodes DPA and poison source bits */
+ .address = cpu_to_le64(CXL_POISON_SOURCE_INTERNAL),
+ .length = cpu_to_le32(1),
+ },
+ };
+
+ if (cmd->size_out < sizeof(mock_poison_list))
+ return -EINVAL;
+
+ memcpy(cmd->payload_out, &mock_poison_list, sizeof(mock_poison_list));
+ cmd->size_out = sizeof(mock_poison_list);
+ return 0;
+}
+
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
{
struct device *dev = cxlds->dev;
@@ -234,6 +262,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
case CXL_MBOX_OP_GET_HEALTH_INFO:
rc = mock_health_info(cxlds, cmd);
break;
+ case CXL_MBOX_OP_GET_POISON:
+ rc = mock_get_poison(cxlds, cmd);
+ break;
default:
break;
}
--
2.37.3