Skip to contentSkip to conversation

acpi nfit: make emulation of translate SPA on nfit_test

PATCH Superseded Yasunori Goto 3 participants 9 messages Aug 18, 2017 – Sep 21, 2017

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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 v1 [1]:
- Separate patch set of kenel from ndctl patch set.
- Change interface via ND_CMD_CALL.

[1] 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

#1 lore raw

PATCH 1/3 acpi nfit: move definitions which nfit_test will use

To use nfit_test.ko can use the definition of NFIT_CMD_TRANSLATE_SPA, the defintion is moved from nfit/core.c to ndctl.h.

Probably, other NFIT_CMD_XXX defintions will be used by nfit_test.ko in future. move them to ndctl.h at this time.

---
 drivers/acpi/nfit/core.c   | 11 -----------
 include/uapi/linux/ndctl.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/acpi/nfit/core.c +0 -11
index 19182d0..00e49c2 100644
@@ -1621,17 +1621,6 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
 			acpi_desc);
 }
 
-/*
- * These constants are private because there are no kernel consumers of
- * these commands.
- */
-enum nfit_aux_cmds {
-        NFIT_CMD_TRANSLATE_SPA = 5,
-        NFIT_CMD_ARS_INJECT_SET = 7,
-        NFIT_CMD_ARS_INJECT_CLEAR = 8,
-        NFIT_CMD_ARS_INJECT_GET = 9,
-};
-
 static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
 {
 	struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
include/uapi/linux/ndctl.h +11 -0
index 6d3c542..a359d19 100644
@@ -204,6 +204,17 @@ enum {
 	ND_CMD_CALL = 10,
 };
 
+/*
+ * Though These constants are mainly used by acpi nfit driver,
+ * they are defined here for nfit_test.ko to be able to use them.
+ */
+enum nfit_aux_cmds {
+        NFIT_CMD_TRANSLATE_SPA = 5,
+        NFIT_CMD_ARS_INJECT_SET = 7,
+        NFIT_CMD_ARS_INJECT_CLEAR = 8,
+        NFIT_CMD_ARS_INJECT_GET = 9,
+};
+
 enum {
 	ND_ARS_VOLATILE = 1,
 	ND_ARS_PERSISTENT = 2,

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw

Re: [PATCH 1/3] acpi nfit: move definitions which nfit_test will use

Quoted 41 lines · Yasunori Goto

To use nfit_test.ko can use the definition of NFIT_CMD_TRANSLATE_SPA, the defintion is moved from nfit/core.c to ndctl.h.

Probably, other NFIT_CMD_XXX defintions will be used by nfit_test.ko in future. move them to ndctl.h at this time.

---
 drivers/acpi/nfit/core.c   | 11 -----------
 include/uapi/linux/ndctl.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)
drivers/acpi/nfit/core.c +0 -11
index 19182d0..00e49c2 100644
@@ -1621,17 +1621,6 @@ static int acpi_nfit_register_dimms(struct acpi_nfit_desc *acpi_desc)
                        acpi_desc);
 }
 
-/*
- * These constants are private because there are no kernel consumers of
- * these commands.
- */
-enum nfit_aux_cmds {
-        NFIT_CMD_TRANSLATE_SPA = 5,
-        NFIT_CMD_ARS_INJECT_SET = 7,
-        NFIT_CMD_ARS_INJECT_CLEAR = 8,
-        NFIT_CMD_ARS_INJECT_GET = 9,
-};
-
 static void acpi_nfit_init_dsms(struct acpi_nfit_desc *acpi_desc)
 {
        struct nvdimm_bus_descriptor *nd_desc = &acpi_desc->nd_desc;
include/uapi/linux/ndctl.h +0 -0
index 6d3c542..a359d19 100644
@@ -204,6 +204,17 @@ enum {
        ND_CMD_CALL = 10,
 };

include/uapi/linux/ndctl.h enum { · line 215

Quoted 10 lines
include/uapi/linux/ndctl.h +9 -0
 
+/*
+ * Though These constants are mainly used by acpi nfit driver,
+ * they are defined here for nfit_test.ko to be able to use them.
+ */
+enum nfit_aux_cmds {
+        NFIT_CMD_TRANSLATE_SPA = 5,
+        NFIT_CMD_ARS_INJECT_SET = 7,
+        NFIT_CMD_ARS_INJECT_CLEAR = 8,
+        NFIT_CMD_ARS_INJECT_GET = 9,

Like I mentioned in the ndctl patches let's instead move these to a libndctl-nfit.h header. There's no need for the kernel to export these command numbers since it only passes them through to the acpi device.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

PATCH 2/3 Enable to show what feature is supported via ND_CMD_CALL for nfit_test

In reply to Yasunori Goto

Though 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
index 00e49c2..8535f21 100644
@@ -1630,6 +1630,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_sub_cmd_force_en;
 	adev = to_acpi_dev(acpi_desc);
 	if (!adev)
 		return;
drivers/acpi/nfit/nfit.h +1 -0
index 54292db..5ef95d6 100644
@@ -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_sub_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

#4 lore raw

PATCH 3/3 acpi nfit: nfit_test supports translate SPA

In reply to Yasunori Goto

nfit_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.

---
 drivers/nvdimm/region_devs.c     |  1 +
 tools/testing/nvdimm/test/nfit.c | 98 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +1 -0
index 5954cfb..3c8cc7f 100644
@@ -162,6 +162,7 @@ bool is_nd_pmem(struct device *dev)
 {
 	return dev ? dev->type == &nd_pmem_device_type : false;
 }
+EXPORT_SYMBOL_GPL(is_nd_pmem);
 
 bool is_nd_blk(struct device *dev)
 {
tools/testing/nvdimm/test/nfit.c +97 -1

126 lines not on this page · raw message

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#5 lore raw

Re: [PATCH 3/3] acpi nfit: nfit_test supports translate SPA

Quoted 21 lines · Yasunori Goto

nfit_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.

---
 drivers/nvdimm/region_devs.c     |  1 +
 tools/testing/nvdimm/test/nfit.c | 98 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +0 -0
index 5954cfb..3c8cc7f 100644

drivers/nvdimm/region_devs.c bool is_nd_pmem(struct device *dev) · line 165

Quoted 4 lines
drivers/nvdimm/region_devs.c +1 -0
@@ -162,6 +162,7 @@ bool is_nd_pmem(struct device *dev)
 {
        return dev ? dev->type == &nd_pmem_device_type : false;
 }
+EXPORT_SYMBOL_GPL(is_nd_pmem);

Only a quick comment here because I need to run, but I'd like to find a way to support this without exporting this internal detail. We should be able to do this by just looking through the data that nfit_test registered with the acpi driver at init time. I'll try to think of a more concrete recommendation, but I do want the end solution to keep is_nd_pmem private to the libnvdimm core if at all possible.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#6 lore raw

Re: [PATCH 3/3] acpi nfit: nfit_test supports translate SPA

Quoted 27 lines · Yasunori Goto
Quoted 21 lines

nfit_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.

---
 drivers/nvdimm/region_devs.c     |  1 +
 tools/testing/nvdimm/test/nfit.c | 98 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)
drivers/nvdimm/region_devs.c +0 -0
index 5954cfb..3c8cc7f 100644

drivers/nvdimm/region_devs.c bool is_nd_pmem(struct device *dev) · line 165

Quoted 4 lines
drivers/nvdimm/region_devs.c +1 -0
@@ -162,6 +162,7 @@ bool is_nd_pmem(struct device *dev)
 {
        return dev ? dev->type == &nd_pmem_device_type : false;
 }
+EXPORT_SYMBOL_GPL(is_nd_pmem);
Quoted 8 lines

Only a quick comment here because I need to run, but I'd like to find a way to support this without exporting this internal detail. We should be able to do this by just looking through the data that nfit_test registered with the acpi driver at init time. I'll try to think of a more concrete recommendation, but I do want the end solution to keep is_nd_pmem private to the libnvdimm core if at all possible.

Ok, I'll reconsider it.

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] acpi nfit: nfit_test supports translate SPA

In reply to Yasunori Goto
Quoted 8 lines · Yasunori Goto

nfit_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.

Quoted 7 lines

---
 drivers/nvdimm/region_devs.c     |  1 +
 tools/testing/nvdimm/test/nfit.c | 98
+++++++++++++++++++++++++++++++++++++++-

 2 files changed, 98 insertions(+), 1 deletion(-)

A few >80 character lines in this, but other than that, looks good to me. You can run patches through scripts/checkpatch.pl in the kernel tree to catch problems like this.

Quoted 52 lines
drivers/nvdimm/region_devs.c +1 -0
index 5954cfb..3c8cc7f 100644
@@ -162,6 +162,7 @@ bool is_nd_pmem(struct device *dev)
  {
  	return dev ? dev->type == &nd_pmem_device_type : false;
  }
+EXPORT_SYMBOL_GPL(is_nd_pmem);


 bool is_nd_blk(struct device *dev)
 {

tools/testing/nvdimm/test/nfit.c +0 -0
index 4c2fa98..426d1fa 100644
@@ -342,6 +342,78 @@ static int nfit_test_cmd_clear_error(struct
 nd_cmd_clear_error *clear_err,
  	return 0;
  }

tools/testing/nvdimm/test/nfit.c +6 -0
+struct region_search_spa{
+	u64 addr;
+	struct nd_region *region;
+};
+
+static int nfit_test_search_region_spa(struct device *dev, void

*data)

tools/testing/nvdimm/test/nfit.c +12 -0
+{
+	struct region_search_spa *ctx = data;
+	struct nd_region *nd_region;
+	resource_size_t ndr_end;
+
+	if (!is_nd_pmem(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)

{

tools/testing/nvdimm/test/nfit.c +8 -0
+		ctx->region = nd_region;
+		return 1;
+	}
+
+	return 0;
+}
+
+static int nfit_test_search_spa(struct nvdimm_bus *bus, struct
Quoted 1 line

nd_cmd_trans_spa *spa)

Over 80 char, you can split the line after 'bus' here.

Quoted 43 lines
tools/testing/nvdimm/test/nfit.c +12 -0
+{
+	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);

80 ch

tools/testing/nvdimm/test/nfit.c +12 -0
+
+	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];

tools/testing/nvdimm/test/nfit.c +10 -0
+	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_trans_spa *spa,

80 ch

tools/testing/nvdimm/test/nfit.c static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err, · line 405

Quoted 1 line
tools/testing/nvdimm/test/nfit.c +1 -0
+				unsigned int buf_len)

By convention, the second line starts after just two tab stops in this file.

Quoted 40 lines
tools/testing/nvdimm/test/nfit.c +11 -0
+{
+
+	if (buf_len < spa->trans_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 = {

tools/testing/nvdimm/test/nfit.c +14 -0
@@ -449,6 +521,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,

80 ch

tools/testing/nvdimm/test/nfit.c +1 -0
+							buf,
Quoted 1 line

buf_len);

and a couple extra tab stops here.

Quoted 39 lines
tools/testing/nvdimm/test/nfit.c +5 -0
+				return rc;
+			default:
+				return -ENOTTY;
+			}
+		}


  if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask)) return -ENOTTY;

tools/testing/nvdimm/test/nfit.c +1 -0
@@ -1430,7 +1522,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-

Quoted 1 line

dimm_cmd_force_en);

tools/testing/nvdimm/test/nfit.c +1 -0
+	set_bit(NFIT_CMD_TRANSLATE_SPA, &acpi_desc-
Quoted 1 line

bus_sub_cmd_force_en);

 }

 static void nfit_test1_setup(struct nfit_test *t)

tools/testing/nvdimm/test/nfit.c +0 -0
@@ -1616,10 +1710,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

tools/testing/nvdimm/test/nfit.c +2 -1
-				| 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,

tools/testing/nvdimm/test/nfit.c +1 -0
+			.bus_dsm_mask = 1UL <<

NFIT_CMD_TRANSLATE_SPA,
  },
  .dev = &adev->dev,
  };

Quoted 4 lines

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer Reviewed-by on the v1 series
#8 lore raw
In reply to Yasunori Goto
Quoted 11 lines · Yasunori Goto

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 v1 [1]:
 - Separate patch set of kenel from ndctl patch set.
 - Change interface via ND_CMD_CALL.

Other than the few checkpatch type issues, the series looks good to me.

Quoted 13 lines

[1] https://www.mail-archive.com/[email protected]/msg05287.ht
ml

----

Thanks,
---
Yasunori Goto

Quoted 4 lines

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm