acpi nfit: make emulation of translate SPA on nfit_test
Subsystems (2)
v3 cover acpi nfit: make emulation of translate SPA on nfit_test
This patch set is to emulate translate SPA feature by nfit_test.ko.
Certainly the nfit acpi driver supports translate SPA interface via ND_CMD_CALL. But nfit_test does not support it yet.
To test translate SPA with nfit_test, this patch set is needed.
---
Change log since v2 [1]:
- Make private defintion just for nfit_test. (NFIT_CMD_TRANSLATE_SPA, struct nd_cmd_translate_spa, and others)
- Check region by kobj.name instead of using is_nd_pmem().
Change log since v1 [2]:
- Separate patch set of kenel from ndctl patch set.
- Change interface via ND_CMD_CALL.
[1] https://www.mail-archive.com/[email protected]/msg05582.html
[2] https://www.mail-archive.com/[email protected]/msg05287.html
----
Thanks,
---
Yasunori Goto
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 1/3 nfit_test Make private definitions to command emulation
Make private definitions to command emulation.
These definitions were originally defined at include/uapi/linux/ndctl.h, but they are only for nfit_test emulation now.
--- tools/testing/nvdimm/test/nfit_test.h | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
tools/testing/nvdimm/test/nfit_test.h +48 -0
@@ -32,6 +32,54 @@ struct nfit_test_resource {void *buf; }; +#define ND_TRANSLATE_SPA_STATUS_INVALID_SPA 2 + +/* bus passthru commands */ +enum nfit_test_passthru_cmd { +NFIT_CMD_TRANSLATE_SPA =5 , +NFIT_CMD_ARS_INJECT_SET =7 , +NFIT_CMD_ARS_INJECT_CLEAR =8 , +NFIT_CMD_ARS_INJECT_GET =9 , +}; + +struct nd_cmd_translate_spa { +__u64 spa; +__u32 status; +__u8 flags; +__u8 _reserved[3 ]; +__u64 translate_length; +__u32 num_nvdimms; +struct nd_nvdimm_device { +__u32 nfit_device_handle; +__u32 _reserved; +__u64 dpa; + } __attribute__((packed)) devices[0 ]; + +} __attribute__((packed)); + +struct nd_cmd_ars_err_inj { +__u64 err_inj_spa_range_base; +__u64 err_inj_spa_range_length; +__u8 err_inj_options; +__u32 status; +} __attribute__((packed)); + +struct nd_cmd_ars_err_inj_clr { +__u64 err_inj_clr_spa_range_base; +__u64 err_inj_clr_spa_range_length; +__u32 status; +} __attribute__((packed)); + +struct nd_cmd_ars_err_inj_stat { +__u32 status; +__u32 inj_err_rec_count; +struct nd_error_stat_query_record { +__u64 err_inj_stat_spa_range_base; +__u64 err_inj_stat_spa_range_length; + } __attribute__((packed)) record[0 ]; +} __attribute__((packed)); + +union acpi_object ;typedef void *acpi_handle ;
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 2/3 acpi nfit: Enable to show what feature is supported via ND_CMD_CALL for nfit_test
In reply to Yasunori GotoThough nfit_test need to show what feature is supported via ND_CMD_CALL on device/nfit/dsm_mask, currently there is no way to tell it. This patch makes to enable it.
--- drivers/acpi/nfit/core.c | 1 + drivers/acpi/nfit/nfit.h | 1 + 2 files changed, 2 insertions(+)
drivers/acpi/nfit/core.c +1 -0
@@ -1641,6 +1641,7 @@ static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)int i; nd_desc->cmd_mask = acpi_desc->bus_cmd_force_en; + nd_desc->bus_dsm_mask = acpi_desc->bus_passthru_cmd_force_en; adev =to_acpi_dev (acpi_desc);if (!adev)return ;
drivers/acpi/nfit/nfit.h +1 -0
@@ -167,6 +167,7 @@ struct acpi_nfit_desc { unsigned int init_complete:1;unsigned long dimm_cmd_force_en;unsigned long bus_cmd_force_en; +unsigned long bus_passthru_cmd_force_en;int (*blk_do_io)(struct nd_blk_region *ndbr,resource_size_t dpa,void *iobuf,u64 len,int rw); };
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH v3 3/3 acpi nfit: nfit_test supports translate SPA
In reply to Yasunori Gotonfit_test supports translate SPA
To test ndctl list which use interface of Translate SPA, nfit_test needs to emulates it.
This test module searches region which includes SPA and returns 1 dimm handle which is last one.
--- tools/testing/nvdimm/test/nfit.c | 104 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-)
tools/testing/nvdimm/test/nfit.c +103 -1
@@ -342,6 +342,84 @@ static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err,return 0 ; } +struct region_search_spa { +u64 addr; +struct nd_region *region; +}; + +static int is_region_device (struct device *dev) + +{ +return !strncmp (dev->kobj.name,"region" ,6 ); +} + +static int nfit_test_search_region_spa (struct device *dev,void *data) +{ +struct region_search_spa *ctx = data; +struct nd_region *nd_region; +resource_size_t ndr_end; + +if (!is_region_device (dev)) +return 0 ; + + nd_region =to_nd_region (dev); + ndr_end = nd_region->ndr_start + nd_region->ndr_size; + +if (ctx->addr >= nd_region->ndr_start && ctx->addr < ndr_end) { + ctx->region = nd_region; +return 1 ; + } + +return 0 ; +} + +static int nfit_test_search_spa (struct nvdimm_bus *bus,struct nd_cmd_translate_spa *spa) +{ +int ret; +struct nd_region *nd_region =NULL ; +struct nvdimm *nvdimm =NULL ; +struct nd_mapping *nd_mapping =NULL ; +struct region_search_spa ctx = { + .addr = spa->spa, + .region =NULL , + }; +u64 dpa; + + ret =device_for_each_child (&bus->dev, &ctx, nfit_test_search_region_spa); + +if (!ret) +return -ENODEV ; + + nd_region = ctx.region; + + dpa = ctx.addr - nd_region->ndr_start; + +/* +* last dimm is selected for test +*/ + nd_mapping = &nd_region->mapping[nd_region->ndr_mappings -1 ]; + nvdimm = nd_mapping->nvdimm; + + spa->devices[0 ].nfit_device_handle = handle[nvdimm->id]; + spa->num_nvdimms =1 ; + spa->devices[0 ].dpa = dpa; + +return 0 ; +} + +static int nfit_test_cmd_translate_spa (struct nvdimm_bus *bus,struct nd_cmd_translate_spa *spa, +unsigned int buf_len) +{ + +if (buf_len < spa->translate_length) +return -EINVAL ; + +if (nfit_test_search_spa (bus, spa) <0 || !spa->num_nvdimms) + spa->status =2 ; + +return 0 ; +} +static int nfit_test_cmd_smart (struct nd_cmd_smart *smart,unsigned int buf_len) {static const struct nd_smart_payload smart_data = {
@@ -449,6 +527,26 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, } }else {struct ars_state *ars_state = &t->ars_state; +struct nd_cmd_pkg *call_pkg = buf; + +if (!nd_desc) +return -ENOTTY ; + +if (cmd ==ND_CMD_CALL ) { + func = call_pkg->nd_command; + + buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out; + buf = (void *) call_pkg->nd_payload; + +switch (func) { +case NFIT_CMD_TRANSLATE_SPA : + rc =nfit_test_cmd_translate_spa (acpi_desc->nvdimm_bus, + buf, buf_len); +return rc; +default : +return -ENOTTY ; + } + }if (!nd_desc || !test_bit (cmd, &nd_desc->cmd_mask))return -ENOTTY ;
@@ -1430,7 +1528,9 @@ static void nfit_test0_setup(struct nfit_test *t)set_bit (ND_CMD_ARS_START , &acpi_desc->bus_cmd_force_en);set_bit (ND_CMD_ARS_STATUS , &acpi_desc->bus_cmd_force_en);set_bit (ND_CMD_CLEAR_ERROR , &acpi_desc->bus_cmd_force_en); +set_bit (ND_CMD_CALL , &acpi_desc->bus_cmd_force_en);set_bit (ND_CMD_SMART_THRESHOLD , &acpi_desc->dimm_cmd_force_en); +set_bit (NFIT_CMD_TRANSLATE_SPA , &acpi_desc->bus_passthru_cmd_force_en); }static void nfit_test1_setup (struct nfit_test *t)
@@ -1616,10 +1716,12 @@ static int nfit_ctl_test(struct device *dev) .cmd_mask = 1UL << ND_CMD_ARS_CAP |1UL <<ND_CMD_ARS_START |1UL <<ND_CMD_ARS_STATUS - | 1UL << ND_CMD_CLEAR_ERROR, + |1UL <<ND_CMD_CLEAR_ERROR + | 1UL << ND_CMD_CALL, .module = THIS_MODULE, .provider_name = "ACPI.NFIT", .ndctl = acpi_nfit_ctl, + .bus_dsm_mask = 1UL << NFIT_CMD_TRANSLATE_SPA, }, .dev = &adev->dev, };
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm