Skip to content

Commit f8d22bf

Browse files
AlisonSchofielddjbw
authored andcommitted
tools/testing/cxl: Mock support for Get Poison List
Make mock memdevs support the Get Poison List mailbox command. Return a fake poison error record when the get poison list command is issued. This supports testing the kernel tracing and cxl list capabilities for media errors. Signed-off-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/14d661ce3e3a32b7d8e76b8ecc5eb88343b3d09c.1681838292.git.alison.schofield@intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 28a3ae4 commit f8d22bf

File tree

1 file changed

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

1 file changed

+42
-0
lines changed

tools/testing/cxl/test/mem.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/delay.h>
88
#include <linux/sizes.h>
99
#include <linux/bits.h>
10+
#include <asm/unaligned.h>
1011
#include <cxlmem.h>
1112

1213
#include "trace.h"
@@ -40,6 +41,10 @@ static struct cxl_cel_entry mock_cel[] = {
4041
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
4142
.effect = cpu_to_le16(0),
4243
},
44+
{
45+
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON),
46+
.effect = cpu_to_le16(0),
47+
},
4348
};
4449

4550
/* See CXL 2.0 Table 181 Get Health Info Output Payload */
@@ -471,6 +476,8 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
471476
cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
472477
};
473478

479+
put_unaligned_le24(CXL_POISON_LIST_MAX, id.poison_list_max_mer);
480+
474481
if (cmd->size_out < sizeof(id))
475482
return -EINVAL;
476483

@@ -888,6 +895,34 @@ static int mock_health_info(struct cxl_dev_state *cxlds,
888895
return 0;
889896
}
890897

898+
static int mock_get_poison(struct cxl_dev_state *cxlds,
899+
struct cxl_mbox_cmd *cmd)
900+
{
901+
struct cxl_mbox_poison_in *pi = cmd->payload_in;
902+
903+
/* Mock one poison record at pi.offset for 64 bytes */
904+
struct {
905+
struct cxl_mbox_poison_out po;
906+
struct cxl_poison_record record;
907+
} __packed mock_plist = {
908+
.po = {
909+
.count = cpu_to_le16(1),
910+
},
911+
.record = {
912+
.length = cpu_to_le32(1),
913+
.address = cpu_to_le64(le64_to_cpu(pi->offset) +
914+
CXL_POISON_SOURCE_INJECTED),
915+
},
916+
};
917+
918+
if (cmd->size_out < sizeof(mock_plist))
919+
return -EINVAL;
920+
921+
memcpy(cmd->payload_out, &mock_plist, sizeof(mock_plist));
922+
cmd->size_out = sizeof(mock_plist);
923+
return 0;
924+
}
925+
891926
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
892927
{
893928
struct device *dev = cxlds->dev;
@@ -942,6 +977,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
942977
case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE:
943978
rc = mock_passphrase_secure_erase(cxlds, cmd);
944979
break;
980+
case CXL_MBOX_OP_GET_POISON:
981+
rc = mock_get_poison(cxlds, cmd);
982+
break;
945983
default:
946984
break;
947985
}
@@ -1010,6 +1048,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
10101048
if (rc)
10111049
return rc;
10121050

1051+
rc = cxl_poison_state_init(cxlds);
1052+
if (rc)
1053+
return rc;
1054+
10131055
rc = cxl_dev_state_identify(cxlds);
10141056
if (rc)
10151057
return rc;

0 commit comments

Comments
 (0)