Commit f8d22bf5 authored by Alison Schofield's avatar Alison Schofield Committed by Dan Williams

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: default avatarAlison Schofield <alison.schofield@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
Reviewed-by: default avatarDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/14d661ce3e3a32b7d8e76b8ecc5eb88343b3d09c.1681838292.git.alison.schofield@intel.comSigned-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 28a3ae4f
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/bits.h> #include <linux/bits.h>
#include <asm/unaligned.h>
#include <cxlmem.h> #include <cxlmem.h>
#include "trace.h" #include "trace.h"
...@@ -40,6 +41,10 @@ static struct cxl_cel_entry mock_cel[] = { ...@@ -40,6 +41,10 @@ static struct cxl_cel_entry mock_cel[] = {
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO), .opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
.effect = cpu_to_le16(0), .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 */ /* 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) ...@@ -471,6 +476,8 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER), cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER),
}; };
put_unaligned_le24(CXL_POISON_LIST_MAX, id.poison_list_max_mer);
if (cmd->size_out < sizeof(id)) if (cmd->size_out < sizeof(id))
return -EINVAL; return -EINVAL;
...@@ -888,6 +895,34 @@ static int mock_health_info(struct cxl_dev_state *cxlds, ...@@ -888,6 +895,34 @@ static int mock_health_info(struct cxl_dev_state *cxlds,
return 0; return 0;
} }
static int mock_get_poison(struct cxl_dev_state *cxlds,
struct cxl_mbox_cmd *cmd)
{
struct cxl_mbox_poison_in *pi = cmd->payload_in;
/* Mock one poison record at pi.offset for 64 bytes */
struct {
struct cxl_mbox_poison_out po;
struct cxl_poison_record record;
} __packed mock_plist = {
.po = {
.count = cpu_to_le16(1),
},
.record = {
.length = cpu_to_le32(1),
.address = cpu_to_le64(le64_to_cpu(pi->offset) +
CXL_POISON_SOURCE_INJECTED),
},
};
if (cmd->size_out < sizeof(mock_plist))
return -EINVAL;
memcpy(cmd->payload_out, &mock_plist, sizeof(mock_plist));
cmd->size_out = sizeof(mock_plist);
return 0;
}
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
{ {
struct device *dev = cxlds->dev; struct device *dev = cxlds->dev;
...@@ -942,6 +977,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd * ...@@ -942,6 +977,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE: case CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE:
rc = mock_passphrase_secure_erase(cxlds, cmd); rc = mock_passphrase_secure_erase(cxlds, cmd);
break; break;
case CXL_MBOX_OP_GET_POISON:
rc = mock_get_poison(cxlds, cmd);
break;
default: default:
break; break;
} }
...@@ -1010,6 +1048,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev) ...@@ -1010,6 +1048,10 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
if (rc) if (rc)
return rc; return rc;
rc = cxl_poison_state_init(cxlds);
if (rc)
return rc;
rc = cxl_dev_state_identify(cxlds); rc = cxl_dev_state_identify(cxlds);
if (rc) if (rc)
return rc; return rc;
......
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