All of lore.kernel.org
 help / color / mirror / Atom feed
From: Santosh Sivaraj <santosh@fossix.org>
To: Linux NVDIMM <linux-nvdimm@lists.01.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
	Vaibhav Jain <vaibhav@linux.ibm.com>,
	Shivaprasad G Bhat <sbhat@linux.ibm.com>,
	Harish Sriram <harish@linux.ibm.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: Santosh Sivaraj <santosh@fossix.org>
Subject: [RFC v5 6/7] ndtest: Add nvdimm control functions
Date: Mon, 14 Dec 2020 16:08:58 +0530	[thread overview]
Message-ID: <20201214103859.2409175-7-santosh@fossix.org> (raw)
In-Reply-To: <20201214103859.2409175-1-santosh@fossix.org>

Add functions to support ND_CMD_GET_CONFIG_SIZE, ND_CMD_SET_CONFIG_DATA and
ND_CMD_GET_CONFIG_DATA.

Signed-off-by: Santosh Sivaraj <santosh@fossix.org>
---
 tools/testing/nvdimm/test/ndtest.c | 51 ++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 821296b59bdc..dc1e3636616a 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -254,6 +254,45 @@ static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
 	return container_of(pdev, struct ndtest_priv, pdev);
 }
 
+static int ndtest_config_get(struct ndtest_dimm *p, unsigned int buf_len,
+			     struct nd_cmd_get_config_data_hdr *hdr)
+{
+	unsigned int len;
+
+	if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+		return -EINVAL;
+
+	hdr->status = 0;
+	len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+	memcpy(hdr->out_buf, p->label_area + hdr->in_offset, len);
+
+	return buf_len - len;
+}
+
+static int ndtest_config_set(struct ndtest_dimm *p, unsigned int buf_len,
+			     struct nd_cmd_set_config_hdr *hdr)
+{
+	unsigned int len;
+
+	if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
+		return -EINVAL;
+
+	len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
+	memcpy(p->label_area + hdr->in_offset, hdr->in_buf, len);
+
+	return buf_len - len;
+}
+
+static int ndtest_get_config_size(struct ndtest_dimm *dimm, unsigned int buf_len,
+				  struct nd_cmd_get_config_size *size)
+{
+	size->status = 0;
+	size->max_xfer = 8;
+	size->config_size = dimm->config_size;
+
+	return 0;
+}
+
 static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
 		      struct nvdimm *nvdimm, unsigned int cmd, void *buf,
 		      unsigned int buf_len, int *cmd_rc)
@@ -275,12 +314,24 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
 
 	switch (cmd) {
 	case ND_CMD_GET_CONFIG_SIZE:
+		*cmd_rc = ndtest_get_config_size(dimm, buf_len, buf);
+		break;
 	case ND_CMD_GET_CONFIG_DATA:
+		*cmd_rc = ndtest_config_get(dimm, buf_len, buf);
+		break;
 	case ND_CMD_SET_CONFIG_DATA:
+		*cmd_rc = ndtest_config_set(dimm, buf_len, buf);
+		break;
 	default:
 		return -EINVAL;
 	}
 
+	/* Failures for a DIMM can be injected using fail_cmd and
+	 * fail_cmd_code, see the device attributes below
+	 */
+	if ((1 << cmd) & dimm->fail_cmd)
+		return dimm->fail_cmd_code ? dimm->fail_cmd_code : -EIO;
+
 	return 0;
 }
 
-- 
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  parent reply	other threads:[~2020-12-14 10:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 10:38 [RFC v5 0/7] PMEM device emulation without nfit depenency Santosh Sivaraj
2020-12-14 10:38 ` [RFC v5 1/7] testing/nvdimm: Add test module for non-nfit platforms Santosh Sivaraj
2020-12-16  5:05   ` Dan Williams
2020-12-17  7:16     ` Santosh Sivaraj
2021-01-28  5:41   ` Dan Williams
2020-12-14 10:38 ` [RFC v5 2/7] ndtest: Add compatability string to treat it as PAPR family Santosh Sivaraj
2020-12-14 10:38 ` [RFC v5 3/7] ndtest: Add dimms to the two buses Santosh Sivaraj
2020-12-14 10:38 ` [RFC v5 4/7] ndtest: Add dimm attributes Santosh Sivaraj
2020-12-14 10:38 ` [RFC v5 5/7] ndtest: Add regions and mappings to the test buses Santosh Sivaraj
2020-12-14 10:38 ` Santosh Sivaraj [this message]
2020-12-14 10:38 ` [RFC v5 7/7] ndtest: Add papr health related flags Santosh Sivaraj
2020-12-14 10:41 ` [ndctl RFC v5 1/5] libndctl: test enablement for non-nfit devices Santosh Sivaraj
2020-12-14 10:41   ` [ndctl RFC v5 2/5] test: Don't skip tests if nfit modules are missing Santosh Sivaraj
2020-12-14 10:41   ` [ndctl RFC v5 3/5] papr: Add support to parse save_fail flag for dimm Santosh Sivaraj
2020-12-14 10:41   ` [ndctl RFC v5 4/5] test/libndctl: skip SMART tests on non-nfit devices Santosh Sivaraj
2020-12-14 10:41   ` [ndctl RFC v5 5/5] Use page size as alignment value Santosh Sivaraj
2020-12-15 23:21 ` [RFC v5 0/7] PMEM device emulation without nfit depenency Dan Williams
2020-12-17  7:23   ` Santosh Sivaraj
2021-01-28  8:12 ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201214103859.2409175-7-santosh@fossix.org \
    --to=santosh@fossix.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=harish@linux.ibm.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=sbhat@linux.ibm.com \
    --cc=vaibhav@linux.ibm.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.