Blame SOURCES/0035-libcxl-add-support-for-command-query-and-submission.patch

2eb93d
From 96afebd1b32ff839129f3bc0ba323ab5f04674ea Mon Sep 17 00:00:00 2001
2eb93d
From: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
Date: Thu, 7 Oct 2021 02:21:27 -0600
2eb93d
Subject: [PATCH 035/217] libcxl: add support for command query and submission
2eb93d
2eb93d
Add a set of APIs around 'cxl_cmd' for querying the kernel for supported
2eb93d
commands, allocating and validating command structures against the
2eb93d
supported set, and submitting the commands.
2eb93d
2eb93d
'Query Commands' and 'Send Command' are implemented as IOCTLs in the
2eb93d
kernel. 'Query Commands' returns information about each supported
2eb93d
command, such as flags governing its use, or input and output payload
2eb93d
sizes. This information is used to validate command support, as well as
2eb93d
set up input and output buffers for command submission.
2eb93d
2eb93d
Cc: Ben Widawsky <ben.widawsky@intel.com>
2eb93d
Cc: Dan Williams <dan.j.williams@intel.com>
2eb93d
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 cxl/lib/libcxl.c   | 390 +++++++++++++++++++++++++++++++++++++++++++++
2eb93d
 cxl/lib/libcxl.sym |   9 ++
2eb93d
 cxl/lib/private.h  |  33 ++++
2eb93d
 cxl/libcxl.h       |  11 ++
2eb93d
 4 files changed, 443 insertions(+)
2eb93d
2eb93d
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
2eb93d
index c15e987..727d599 100644
2eb93d
--- a/cxl/lib/libcxl.c
2eb93d
+++ b/cxl/lib/libcxl.c
2eb93d
@@ -9,14 +9,17 @@
2eb93d
 #include <unistd.h>
2eb93d
 #include <sys/stat.h>
2eb93d
 #include <sys/types.h>
2eb93d
+#include <sys/ioctl.h>
2eb93d
 #include <sys/sysmacros.h>
2eb93d
 #include <uuid/uuid.h>
2eb93d
 #include <ccan/list/list.h>
2eb93d
 #include <ccan/array_size/array_size.h>
2eb93d
 
2eb93d
 #include <util/log.h>
2eb93d
+#include <util/size.h>
2eb93d
 #include <util/sysfs.h>
2eb93d
 #include <util/bitmap.h>
2eb93d
+#include <cxl/cxl_mem.h>
2eb93d
 #include <cxl/libcxl.h>
2eb93d
 #include "private.h"
2eb93d
 
2eb93d
@@ -343,3 +346,390 @@ CXL_EXPORT const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev
2eb93d
 {
2eb93d
 	return memdev->firmware_version;
2eb93d
 }
2eb93d
+
2eb93d
+CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	if (!cmd)
2eb93d
+		return;
2eb93d
+	if (--cmd->refcount == 0) {
2eb93d
+		free(cmd->query_cmd);
2eb93d
+		free(cmd->send_cmd);
2eb93d
+		free(cmd->input_payload);
2eb93d
+		free(cmd->output_payload);
2eb93d
+		free(cmd);
2eb93d
+	}
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT void cxl_cmd_ref(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	cmd->refcount++;
2eb93d
+}
2eb93d
+
2eb93d
+static int cxl_cmd_alloc_query(struct cxl_cmd *cmd, int num_cmds)
2eb93d
+{
2eb93d
+	size_t size;
2eb93d
+
2eb93d
+	if (!cmd)
2eb93d
+		return -EINVAL;
2eb93d
+
2eb93d
+	if (cmd->query_cmd != NULL)
2eb93d
+		free(cmd->query_cmd);
2eb93d
+
2eb93d
+	size = struct_size(cmd->query_cmd, commands, num_cmds);
2eb93d
+	if (size == SIZE_MAX)
2eb93d
+		return -EOVERFLOW;
2eb93d
+
2eb93d
+	cmd->query_cmd = calloc(1, size);
2eb93d
+	if (!cmd->query_cmd)
2eb93d
+		return -ENOMEM;
2eb93d
+
2eb93d
+	cmd->query_cmd->n_commands = num_cmds;
2eb93d
+
2eb93d
+	return 0;
2eb93d
+}
2eb93d
+
2eb93d
+static struct cxl_cmd *cxl_cmd_new(struct cxl_memdev *memdev)
2eb93d
+{
2eb93d
+	struct cxl_cmd *cmd;
2eb93d
+	size_t size;
2eb93d
+
2eb93d
+	size = sizeof(*cmd);
2eb93d
+	cmd = calloc(1, size);
2eb93d
+	if (!cmd)
2eb93d
+		return NULL;
2eb93d
+
2eb93d
+	cxl_cmd_ref(cmd);
2eb93d
+	cmd->memdev = memdev;
2eb93d
+
2eb93d
+	return cmd;
2eb93d
+}
2eb93d
+
2eb93d
+static int __do_cmd(struct cxl_cmd *cmd, int ioctl_cmd, int fd)
2eb93d
+{
2eb93d
+	void *cmd_buf;
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	switch (ioctl_cmd) {
2eb93d
+	case CXL_MEM_QUERY_COMMANDS:
2eb93d
+		cmd_buf = cmd->query_cmd;
2eb93d
+		break;
2eb93d
+	case CXL_MEM_SEND_COMMAND:
2eb93d
+		cmd_buf = cmd->send_cmd;
2eb93d
+		break;
2eb93d
+	default:
2eb93d
+		return -EINVAL;
2eb93d
+	}
2eb93d
+
2eb93d
+	rc = ioctl(fd, ioctl_cmd, cmd_buf);
2eb93d
+	if (rc < 0)
2eb93d
+		rc = -errno;
2eb93d
+
2eb93d
+	return rc;
2eb93d
+}
2eb93d
+
2eb93d
+static int do_cmd(struct cxl_cmd *cmd, int ioctl_cmd)
2eb93d
+{
2eb93d
+	char *path;
2eb93d
+	struct stat st;
2eb93d
+	unsigned int major, minor;
2eb93d
+	int rc = 0, fd;
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
2eb93d
+	const char *devname = cxl_memdev_get_devname(memdev);
2eb93d
+
2eb93d
+	major = cxl_memdev_get_major(memdev);
2eb93d
+	minor = cxl_memdev_get_minor(memdev);
2eb93d
+
2eb93d
+	if (asprintf(&path, "/dev/cxl/%s", devname) < 0)
2eb93d
+		return -ENOMEM;
2eb93d
+
2eb93d
+	fd = open(path, O_RDWR);
2eb93d
+	if (fd < 0) {
2eb93d
+		err(ctx, "failed to open %s: %s\n", path, strerror(errno));
2eb93d
+		rc = -errno;
2eb93d
+		goto out;
2eb93d
+	}
2eb93d
+
2eb93d
+	if (fstat(fd, &st) >= 0 && S_ISCHR(st.st_mode)
2eb93d
+			&& major(st.st_rdev) == major
2eb93d
+			&& minor(st.st_rdev) == minor) {
2eb93d
+		rc = __do_cmd(cmd, ioctl_cmd, fd);
2eb93d
+	} else {
2eb93d
+		err(ctx, "failed to validate %s as a CXL memdev node\n", path);
2eb93d
+		rc = -ENXIO;
2eb93d
+	}
2eb93d
+	close(fd);
2eb93d
+out:
2eb93d
+	free(path);
2eb93d
+	return rc;
2eb93d
+}
2eb93d
+
2eb93d
+static int alloc_do_query(struct cxl_cmd *cmd, int num_cmds)
2eb93d
+{
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(cmd->memdev);
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	rc = cxl_cmd_alloc_query(cmd, num_cmds);
2eb93d
+	if (rc)
2eb93d
+		return rc;
2eb93d
+
2eb93d
+	rc = do_cmd(cmd, CXL_MEM_QUERY_COMMANDS);
2eb93d
+	if (rc < 0)
2eb93d
+		err(ctx, "%s: query commands failed: %s\n",
2eb93d
+			cxl_memdev_get_devname(cmd->memdev),
2eb93d
+			strerror(-rc));
2eb93d
+	return rc;
2eb93d
+}
2eb93d
+
2eb93d
+static int cxl_cmd_do_query(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
2eb93d
+	const char *devname = cxl_memdev_get_devname(memdev);
2eb93d
+	int rc, n_commands;
2eb93d
+
2eb93d
+	switch (cmd->query_status) {
2eb93d
+	case CXL_CMD_QUERY_OK:
2eb93d
+		return 0;
2eb93d
+	case CXL_CMD_QUERY_UNSUPPORTED:
2eb93d
+		return -EOPNOTSUPP;
2eb93d
+	case CXL_CMD_QUERY_NOT_RUN:
2eb93d
+		break;
2eb93d
+	default:
2eb93d
+		err(ctx, "%s: Unknown query_status %d\n",
2eb93d
+			devname, cmd->query_status);
2eb93d
+		return -EINVAL;
2eb93d
+	}
2eb93d
+
2eb93d
+	rc = alloc_do_query(cmd, 0);
2eb93d
+	if (rc)
2eb93d
+		return rc;
2eb93d
+
2eb93d
+	n_commands = cmd->query_cmd->n_commands;
2eb93d
+	dbg(ctx, "%s: supports %d commands\n", devname, n_commands);
2eb93d
+
2eb93d
+	return alloc_do_query(cmd, n_commands);
2eb93d
+}
2eb93d
+
2eb93d
+static int cxl_cmd_validate(struct cxl_cmd *cmd, u32 cmd_id)
2eb93d
+{
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+	struct cxl_mem_query_commands *query = cmd->query_cmd;
2eb93d
+	const char *devname = cxl_memdev_get_devname(memdev);
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
2eb93d
+	u32 i;
2eb93d
+
2eb93d
+	for (i = 0; i < query->n_commands; i++) {
2eb93d
+		struct cxl_command_info *cinfo = &query->commands[i];
2eb93d
+		const char *cmd_name = cxl_command_names[cinfo->id].name;
2eb93d
+
2eb93d
+		if (cinfo->id != cmd_id)
2eb93d
+			continue;
2eb93d
+
2eb93d
+		dbg(ctx, "%s: %s: in: %d, out %d, flags: %#08x\n",
2eb93d
+			devname, cmd_name, cinfo->size_in,
2eb93d
+			cinfo->size_out, cinfo->flags);
2eb93d
+
2eb93d
+		cmd->query_idx = i;
2eb93d
+		cmd->query_status = CXL_CMD_QUERY_OK;
2eb93d
+		return 0;
2eb93d
+	}
2eb93d
+	cmd->query_status = CXL_CMD_QUERY_UNSUPPORTED;
2eb93d
+	return -EOPNOTSUPP;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_set_input_payload(struct cxl_cmd *cmd, void *buf,
2eb93d
+		int size)
2eb93d
+{
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+
2eb93d
+	if (size > memdev->payload_max || size < 0)
2eb93d
+		return -EINVAL;
2eb93d
+
2eb93d
+	if (!buf) {
2eb93d
+
2eb93d
+		/* If the user didn't supply a buffer, allocate it */
2eb93d
+		cmd->input_payload = calloc(1, size);
2eb93d
+		if (!cmd->input_payload)
2eb93d
+			return -ENOMEM;
2eb93d
+		cmd->send_cmd->in.payload = (u64)cmd->input_payload;
2eb93d
+	} else {
2eb93d
+		/*
2eb93d
+		 * Use user-buffer as is. If an automatic allocation was
2eb93d
+		 * previously made (based on a fixed size from query),
2eb93d
+		 * it will get freed during unref.
2eb93d
+		 */
2eb93d
+		cmd->send_cmd->in.payload = (u64)buf;
2eb93d
+	}
2eb93d
+	cmd->send_cmd->in.size = size;
2eb93d
+
2eb93d
+	return 0;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_set_output_payload(struct cxl_cmd *cmd, void *buf,
2eb93d
+		int size)
2eb93d
+{
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+
2eb93d
+	if (size > memdev->payload_max || size < 0)
2eb93d
+		return -EINVAL;
2eb93d
+
2eb93d
+	if (!buf) {
2eb93d
+
2eb93d
+		/* If the user didn't supply a buffer, allocate it */
2eb93d
+		cmd->output_payload = calloc(1, size);
2eb93d
+		if (!cmd->output_payload)
2eb93d
+			return -ENOMEM;
2eb93d
+		cmd->send_cmd->out.payload = (u64)cmd->output_payload;
2eb93d
+	} else {
2eb93d
+		/*
2eb93d
+		 * Use user-buffer as is. If an automatic allocation was
2eb93d
+		 * previously made (based on a fixed size from query),
2eb93d
+		 * it will get freed during unref.
2eb93d
+		 */
2eb93d
+		cmd->send_cmd->out.payload = (u64)buf;
2eb93d
+	}
2eb93d
+	cmd->send_cmd->out.size = size;
2eb93d
+
2eb93d
+	return 0;
2eb93d
+}
2eb93d
+
2eb93d
+static int cxl_cmd_alloc_send(struct cxl_cmd *cmd, u32 cmd_id)
2eb93d
+{
2eb93d
+	struct cxl_mem_query_commands *query = cmd->query_cmd;
2eb93d
+	struct cxl_command_info *cinfo = &query->commands[cmd->query_idx];
2eb93d
+	size_t size;
2eb93d
+
2eb93d
+	if (!query)
2eb93d
+		return -EINVAL;
2eb93d
+
2eb93d
+	size = sizeof(struct cxl_send_command);
2eb93d
+	cmd->send_cmd = calloc(1, size);
2eb93d
+	if (!cmd->send_cmd)
2eb93d
+		return -ENOMEM;
2eb93d
+
2eb93d
+	if (cinfo->id != cmd_id)
2eb93d
+		return -EINVAL;
2eb93d
+
2eb93d
+	cmd->send_cmd->id = cmd_id;
2eb93d
+
2eb93d
+	if (cinfo->size_in > 0) {
2eb93d
+		cmd->input_payload = calloc(1, cinfo->size_in);
2eb93d
+		if (!cmd->input_payload)
2eb93d
+			return -ENOMEM;
2eb93d
+		cmd->send_cmd->in.payload = (u64)cmd->input_payload;
2eb93d
+		cmd->send_cmd->in.size = cinfo->size_in;
2eb93d
+	}
2eb93d
+	if (cinfo->size_out > 0) {
2eb93d
+		cmd->output_payload = calloc(1, cinfo->size_out);
2eb93d
+		if (!cmd->output_payload)
2eb93d
+			return -ENOMEM;
2eb93d
+		cmd->send_cmd->out.payload = (u64)cmd->output_payload;
2eb93d
+		cmd->send_cmd->out.size = cinfo->size_out;
2eb93d
+	}
2eb93d
+
2eb93d
+	return 0;
2eb93d
+}
2eb93d
+
2eb93d
+static struct cxl_cmd *cxl_cmd_new_generic(struct cxl_memdev *memdev,
2eb93d
+		u32 cmd_id)
2eb93d
+{
2eb93d
+	const char *devname = cxl_memdev_get_devname(memdev);
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
2eb93d
+	struct cxl_cmd *cmd;
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	cmd = cxl_cmd_new(memdev);
2eb93d
+	if (!cmd)
2eb93d
+		return NULL;
2eb93d
+
2eb93d
+	rc = cxl_cmd_do_query(cmd);
2eb93d
+	if (rc) {
2eb93d
+		err(ctx, "%s: query returned: %s\n", devname, strerror(-rc));
2eb93d
+		goto fail;
2eb93d
+	}
2eb93d
+
2eb93d
+	rc = cxl_cmd_validate(cmd, cmd_id);
2eb93d
+	if (rc) {
2eb93d
+		errno = -rc;
2eb93d
+		goto fail;
2eb93d
+	}
2eb93d
+
2eb93d
+	rc = cxl_cmd_alloc_send(cmd, cmd_id);
2eb93d
+	if (rc) {
2eb93d
+		errno = -rc;
2eb93d
+		goto fail;
2eb93d
+	}
2eb93d
+
2eb93d
+	cmd->status = 1;
2eb93d
+	return cmd;
2eb93d
+
2eb93d
+fail:
2eb93d
+	cxl_cmd_unref(cmd);
2eb93d
+	return NULL;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT const char *cxl_cmd_get_devname(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	return cxl_memdev_get_devname(cmd->memdev);
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev,
2eb93d
+		int opcode)
2eb93d
+{
2eb93d
+	struct cxl_cmd *cmd;
2eb93d
+
2eb93d
+	/* opcode '0' is reserved */
2eb93d
+	if (opcode <= 0) {
2eb93d
+		errno = EINVAL;
2eb93d
+		return NULL;
2eb93d
+	}
2eb93d
+
2eb93d
+	cmd = cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_RAW);
2eb93d
+	if (!cmd)
2eb93d
+		return NULL;
2eb93d
+
2eb93d
+	cmd->send_cmd->raw.opcode = opcode;
2eb93d
+	return cmd;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	struct cxl_memdev *memdev = cmd->memdev;
2eb93d
+	const char *devname = cxl_memdev_get_devname(memdev);
2eb93d
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	switch (cmd->query_status) {
2eb93d
+	case CXL_CMD_QUERY_OK:
2eb93d
+		break;
2eb93d
+	case CXL_CMD_QUERY_UNSUPPORTED:
2eb93d
+		return -EOPNOTSUPP;
2eb93d
+	case CXL_CMD_QUERY_NOT_RUN:
2eb93d
+		return -EINVAL;
2eb93d
+	default:
2eb93d
+		err(ctx, "%s: Unknown query_status %d\n",
2eb93d
+			devname, cmd->query_status);
2eb93d
+		return -EINVAL;
2eb93d
+	}
2eb93d
+
2eb93d
+	dbg(ctx, "%s: submitting SEND cmd: in: %d, out: %d\n", devname,
2eb93d
+		cmd->send_cmd->in.size, cmd->send_cmd->out.size);
2eb93d
+	rc = do_cmd(cmd, CXL_MEM_SEND_COMMAND);
2eb93d
+	cmd->status = cmd->send_cmd->retval;
2eb93d
+	dbg(ctx, "%s: got SEND cmd: in: %d, out: %d, retval: %d, status: %d\n",
2eb93d
+		devname, cmd->send_cmd->in.size, cmd->send_cmd->out.size,
2eb93d
+		rc, cmd->status);
2eb93d
+
2eb93d
+	return rc;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	return cmd->status;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_get_out_size(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	return cmd->send_cmd->out.size;
2eb93d
+}
2eb93d
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
2eb93d
index 2616e5c..3900f90 100644
2eb93d
--- a/cxl/lib/libcxl.sym
2eb93d
+++ b/cxl/lib/libcxl.sym
2eb93d
@@ -20,6 +20,15 @@ global:
2eb93d
 	cxl_memdev_get_pmem_size;
2eb93d
 	cxl_memdev_get_ram_size;
2eb93d
 	cxl_memdev_get_firmware_verison;
2eb93d
+	cxl_cmd_get_devname;
2eb93d
+	cxl_cmd_new_raw;
2eb93d
+	cxl_cmd_set_input_payload;
2eb93d
+	cxl_cmd_set_output_payload;
2eb93d
+	cxl_cmd_ref;
2eb93d
+	cxl_cmd_unref;
2eb93d
+	cxl_cmd_submit;
2eb93d
+	cxl_cmd_get_mbox_status;
2eb93d
+	cxl_cmd_get_out_size;
2eb93d
 local:
2eb93d
         *;
2eb93d
 };
2eb93d
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
2eb93d
index fc88fa1..87ca17e 100644
2eb93d
--- a/cxl/lib/private.h
2eb93d
+++ b/cxl/lib/private.h
2eb93d
@@ -4,6 +4,9 @@
2eb93d
 #define _LIBCXL_PRIVATE_H_
2eb93d
 
2eb93d
 #include <libkmod.h>
2eb93d
+#include <cxl/cxl_mem.h>
2eb93d
+#include <ccan/endian/endian.h>
2eb93d
+#include <ccan/short_types/short_types.h>
2eb93d
 
2eb93d
 #define CXL_EXPORT __attribute__ ((visibility("default")))
2eb93d
 
2eb93d
@@ -21,6 +24,36 @@ struct cxl_memdev {
2eb93d
 	struct kmod_module *module;
2eb93d
 };
2eb93d
 
2eb93d
+enum cxl_cmd_query_status {
2eb93d
+	CXL_CMD_QUERY_NOT_RUN = 0,
2eb93d
+	CXL_CMD_QUERY_OK,
2eb93d
+	CXL_CMD_QUERY_UNSUPPORTED,
2eb93d
+};
2eb93d
+
2eb93d
+/**
2eb93d
+ * struct cxl_cmd - CXL memdev command
2eb93d
+ * @memdev: the memory device to which the command is being sent
2eb93d
+ * @query_cmd: structure for the Linux 'Query commands' ioctl
2eb93d
+ * @send_cmd: structure for the Linux 'Send command' ioctl
2eb93d
+ * @input_payload: buffer for input payload managed by libcxl
2eb93d
+ * @output_payload: buffer for output payload managed by libcxl
2eb93d
+ * @refcount: reference for passing command buffer around
2eb93d
+ * @query_status: status from query_commands
2eb93d
+ * @query_idx: index of 'this' command in the query_commands array
2eb93d
+ * @status: command return status from the device
2eb93d
+ */
2eb93d
+struct cxl_cmd {
2eb93d
+	struct cxl_memdev *memdev;
2eb93d
+	struct cxl_mem_query_commands *query_cmd;
2eb93d
+	struct cxl_send_command *send_cmd;
2eb93d
+	void *input_payload;
2eb93d
+	void *output_payload;
2eb93d
+	int refcount;
2eb93d
+	int query_status;
2eb93d
+	int query_idx;
2eb93d
+	int status;
2eb93d
+};
2eb93d
+
2eb93d
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
2eb93d
 {
2eb93d
 	return kmod_ctx ? 0 : -ENXIO;
2eb93d
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
2eb93d
index fd06790..6e87b80 100644
2eb93d
--- a/cxl/libcxl.h
2eb93d
+++ b/cxl/libcxl.h
2eb93d
@@ -48,6 +48,17 @@ const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
2eb93d
              memdev != NULL; \
2eb93d
              memdev = cxl_memdev_get_next(memdev))
2eb93d
 
2eb93d
+struct cxl_cmd;
2eb93d
+const char *cxl_cmd_get_devname(struct cxl_cmd *cmd);
2eb93d
+struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
2eb93d
+int cxl_cmd_set_input_payload(struct cxl_cmd *cmd, void *in, int size);
2eb93d
+int cxl_cmd_set_output_payload(struct cxl_cmd *cmd, void *out, int size);
2eb93d
+void cxl_cmd_ref(struct cxl_cmd *cmd);
2eb93d
+void cxl_cmd_unref(struct cxl_cmd *cmd);
2eb93d
+int cxl_cmd_submit(struct cxl_cmd *cmd);
2eb93d
+int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd);
2eb93d
+int cxl_cmd_get_out_size(struct cxl_cmd *cmd);
2eb93d
+
2eb93d
 #ifdef __cplusplus
2eb93d
 } /* extern "C" */
2eb93d
 #endif
2eb93d
-- 
2eb93d
2.27.0
2eb93d