Skip to content

Commit 09eac2c

Browse files
stellarhopperdjbw
authored andcommitted
tools/testing/cxl: add mock output for the GET_HEALTH_INFO command
Add mocked health information for cxl_test memdevs. This allows cxl-cli's 'list' command to display the canned health_info fields. Cc: Dan Williams <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Vishal Verma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent a91bd78 commit 09eac2c

File tree

1 file changed

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

1 file changed

+49
-0
lines changed

tools/testing/cxl/test/mem.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,24 @@ static struct cxl_cel_entry mock_cel[] = {
2828
.opcode = cpu_to_le16(CXL_MBOX_OP_SET_LSA),
2929
.effect = cpu_to_le16(EFFECT(1) | EFFECT(2)),
3030
},
31+
{
32+
.opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO),
33+
.effect = cpu_to_le16(0),
34+
},
3135
};
3236

37+
/* See CXL 2.0 Table 181 Get Health Info Output Payload */
38+
struct cxl_mbox_health_info {
39+
u8 health_status;
40+
u8 media_status;
41+
u8 ext_status;
42+
u8 life_used;
43+
__le16 temperature;
44+
__le32 dirty_shutdowns;
45+
__le32 volatile_errors;
46+
__le32 pmem_errors;
47+
} __packed;
48+
3349
static struct {
3450
struct cxl_mbox_get_supported_logs gsl;
3551
struct cxl_gsl_entry entry;
@@ -156,6 +172,36 @@ static int mock_set_lsa(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
156172
return 0;
157173
}
158174

175+
static int mock_health_info(struct cxl_dev_state *cxlds,
176+
struct cxl_mbox_cmd *cmd)
177+
{
178+
struct cxl_mbox_health_info health_info = {
179+
/* set flags for maint needed, perf degraded, hw replacement */
180+
.health_status = 0x7,
181+
/* set media status to "All Data Lost" */
182+
.media_status = 0x3,
183+
/*
184+
* set ext_status flags for:
185+
* ext_life_used: normal,
186+
* ext_temperature: critical,
187+
* ext_corrected_volatile: warning,
188+
* ext_corrected_persistent: normal,
189+
*/
190+
.ext_status = 0x18,
191+
.life_used = 15,
192+
.temperature = cpu_to_le16(25),
193+
.dirty_shutdowns = cpu_to_le32(10),
194+
.volatile_errors = cpu_to_le32(20),
195+
.pmem_errors = cpu_to_le32(30),
196+
};
197+
198+
if (cmd->size_out < sizeof(health_info))
199+
return -EINVAL;
200+
201+
memcpy(cmd->payload_out, &health_info, sizeof(health_info));
202+
return 0;
203+
}
204+
159205
static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd)
160206
{
161207
struct device *dev = cxlds->dev;
@@ -177,6 +223,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *
177223
case CXL_MBOX_OP_SET_LSA:
178224
rc = mock_set_lsa(cxlds, cmd);
179225
break;
226+
case CXL_MBOX_OP_GET_HEALTH_INFO:
227+
rc = mock_health_info(cxlds, cmd);
228+
break;
180229
default:
181230
break;
182231
}

0 commit comments

Comments
 (0)