Message ID | 20211007204753.3321681-1-vishal.l.verma@intel.com |
---|---|
State | Superseded |
Headers | show |
Series | tools/testing/cxl: add mock output for the GET_HEALTH_INFO command | expand |
On Thu, Oct 7, 2021 at 1:48 PM Vishal Verma <vishal.l.verma@intel.com> wrote: > > 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 <dan.j.williams@intel.com> > Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> > --- > drivers/cxl/cxlmem.h | 12 ++++++++++++ > tools/testing/cxl/test/mem.c | 24 ++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > > diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h > index c4f450ad434d..c7957cce8e8b 100644 > --- a/drivers/cxl/cxlmem.h > +++ b/drivers/cxl/cxlmem.h > @@ -228,6 +228,18 @@ struct cxl_mbox_set_lsa { > u8 data[]; > } __packed; > > +/* See CXL 2.0 Table 181 Get Health Info Output Payload */ > +struct cxl_mbox_health_info { > + u8 health_status; > + u8 media_status; > + u8 ext_status; > + u8 life_used; > + __le16 temperature; > + __le32 dirty_shutdowns; > + __le32 volatile_errors; > + __le32 pmem_errors; > +} __packed; I think this one can be local to tools/testing/cxl/test/mem.c unless / until the driver has a reason to issue this command itself, but I think I want to keep the expectation that the kernel just notifies userspace about health changes, it never ingests / polls that data itself. Otherwise if this definition is going to be in the kernel code proper I think it would want some definitions for those status fields, but let's skip all that and move this into tools/testing/. > + > /** > * struct cxl_mem_command - Driver representation of a memory device command > * @info: Command information as it exists for the UAPI > diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c > index 12a8437a9ca0..bd707e83a3e9 100644 > --- a/tools/testing/cxl/test/mem.c > +++ b/tools/testing/cxl/test/mem.c > @@ -28,6 +28,10 @@ static struct cxl_cel_entry mock_cel[] = { > .opcode = cpu_to_le16(CXL_MBOX_OP_SET_LSA), > .effect = cpu_to_le16(EFFECT(1) | EFFECT(2)), > }, > + { > + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO), > + .effect = cpu_to_le16(0), > + }, > }; > > static struct { > @@ -156,6 +160,23 @@ static int mock_set_lsa(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) > return 0; > } > > +static int mock_health_info(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) > +{ > + struct cxl_mbox_health_info health_info = { > + .health_status = 0x7, > + .media_status = 0x3, > + .ext_status = 0x18, Might be nice to comment what these mean so someone at a glance can compare it to the cxl list output. Extra credit for adding #defines, but I don't think that's necessary. > + .life_used = 15, > + .temperature = cpu_to_le16(25), > + .dirty_shutdowns = cpu_to_le16(10), > + .volatile_errors = cpu_to_le16(20), > + .pmem_errors = cpu_to_le16(30), > + }; Perhaps a: if (cmd->size_out < sizeof(health_info)) return -EINVAL; ...to make the static analyzers and match the other mock routines. Otherwise, looks good. > + > + memcpy(cmd->payload_out, &health_info, sizeof(health_info)); > + return 0; > +} > + > static int cxl_mock_mbox_send(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) > { > struct device *dev = cxlm->dev; > @@ -177,6 +198,9 @@ static int cxl_mock_mbox_send(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) > case CXL_MBOX_OP_SET_LSA: > rc = mock_set_lsa(cxlm, cmd); > break; > + case CXL_MBOX_OP_GET_HEALTH_INFO: > + rc = mock_health_info(cxlm, cmd); > + break; > default: > break; > } > > base-commit: ed97afb53365cd03dde266c9644334a558fe5a16 > -- > 2.31.1 >
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index c4f450ad434d..c7957cce8e8b 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -228,6 +228,18 @@ struct cxl_mbox_set_lsa { u8 data[]; } __packed; +/* See CXL 2.0 Table 181 Get Health Info Output Payload */ +struct cxl_mbox_health_info { + u8 health_status; + u8 media_status; + u8 ext_status; + u8 life_used; + __le16 temperature; + __le32 dirty_shutdowns; + __le32 volatile_errors; + __le32 pmem_errors; +} __packed; + /** * struct cxl_mem_command - Driver representation of a memory device command * @info: Command information as it exists for the UAPI diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index 12a8437a9ca0..bd707e83a3e9 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -28,6 +28,10 @@ static struct cxl_cel_entry mock_cel[] = { .opcode = cpu_to_le16(CXL_MBOX_OP_SET_LSA), .effect = cpu_to_le16(EFFECT(1) | EFFECT(2)), }, + { + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO), + .effect = cpu_to_le16(0), + }, }; static struct { @@ -156,6 +160,23 @@ static int mock_set_lsa(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) return 0; } +static int mock_health_info(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) +{ + struct cxl_mbox_health_info health_info = { + .health_status = 0x7, + .media_status = 0x3, + .ext_status = 0x18, + .life_used = 15, + .temperature = cpu_to_le16(25), + .dirty_shutdowns = cpu_to_le16(10), + .volatile_errors = cpu_to_le16(20), + .pmem_errors = cpu_to_le16(30), + }; + + memcpy(cmd->payload_out, &health_info, sizeof(health_info)); + return 0; +} + static int cxl_mock_mbox_send(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) { struct device *dev = cxlm->dev; @@ -177,6 +198,9 @@ static int cxl_mock_mbox_send(struct cxl_mem *cxlm, struct cxl_mbox_cmd *cmd) case CXL_MBOX_OP_SET_LSA: rc = mock_set_lsa(cxlm, cmd); break; + case CXL_MBOX_OP_GET_HEALTH_INFO: + rc = mock_health_info(cxlm, cmd); + break; default: break; }
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 <dan.j.williams@intel.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> --- drivers/cxl/cxlmem.h | 12 ++++++++++++ tools/testing/cxl/test/mem.c | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) base-commit: ed97afb53365cd03dde266c9644334a558fe5a16