Skip to content

Commit 14ccef1

Browse files
santoshsdjbw
authored andcommitted
ndtest: Add nvdimm control functions
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 6fde2d4 commit 14ccef1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tools/testing/nvdimm/test/ndtest.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,45 @@ static inline struct ndtest_priv *to_ndtest_priv(struct device *dev)
254254
return container_of(pdev, struct ndtest_priv, pdev);
255255
}
256256

257+
static int ndtest_config_get(struct ndtest_dimm *p, unsigned int buf_len,
258+
struct nd_cmd_get_config_data_hdr *hdr)
259+
{
260+
unsigned int len;
261+
262+
if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
263+
return -EINVAL;
264+
265+
hdr->status = 0;
266+
len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
267+
memcpy(hdr->out_buf, p->label_area + hdr->in_offset, len);
268+
269+
return buf_len - len;
270+
}
271+
272+
static int ndtest_config_set(struct ndtest_dimm *p, unsigned int buf_len,
273+
struct nd_cmd_set_config_hdr *hdr)
274+
{
275+
unsigned int len;
276+
277+
if ((hdr->in_offset + hdr->in_length) > LABEL_SIZE)
278+
return -EINVAL;
279+
280+
len = min(hdr->in_length, LABEL_SIZE - hdr->in_offset);
281+
memcpy(p->label_area + hdr->in_offset, hdr->in_buf, len);
282+
283+
return buf_len - len;
284+
}
285+
286+
static int ndtest_get_config_size(struct ndtest_dimm *dimm, unsigned int buf_len,
287+
struct nd_cmd_get_config_size *size)
288+
{
289+
size->status = 0;
290+
size->max_xfer = 8;
291+
size->config_size = dimm->config_size;
292+
293+
return 0;
294+
}
295+
257296
static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
258297
struct nvdimm *nvdimm, unsigned int cmd, void *buf,
259298
unsigned int buf_len, int *cmd_rc)
@@ -275,12 +314,24 @@ static int ndtest_ctl(struct nvdimm_bus_descriptor *nd_desc,
275314

276315
switch (cmd) {
277316
case ND_CMD_GET_CONFIG_SIZE:
317+
*cmd_rc = ndtest_get_config_size(dimm, buf_len, buf);
318+
break;
278319
case ND_CMD_GET_CONFIG_DATA:
320+
*cmd_rc = ndtest_config_get(dimm, buf_len, buf);
321+
break;
279322
case ND_CMD_SET_CONFIG_DATA:
323+
*cmd_rc = ndtest_config_set(dimm, buf_len, buf);
324+
break;
280325
default:
281326
return -EINVAL;
282327
}
283328

329+
/* Failures for a DIMM can be injected using fail_cmd and
330+
* fail_cmd_code, see the device attributes below
331+
*/
332+
if ((1 << cmd) & dimm->fail_cmd)
333+
return dimm->fail_cmd_code ? dimm->fail_cmd_code : -EIO;
334+
284335
return 0;
285336
}
286337

0 commit comments

Comments
 (0)