Blame SOURCES/0033-cxl-add-a-local-copy-of-the-cxl_mem-UAPI-header.patch

26ccd9
From 894fb9b2b59364f7f5683ea68c8bd765223a4ca8 Mon Sep 17 00:00:00 2001
26ccd9
From: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
Date: Thu, 7 Oct 2021 02:21:25 -0600
26ccd9
Subject: [PATCH 033/217] cxl: add a local copy of the cxl_mem UAPI header
26ccd9
26ccd9
While CXL functionality is under development, it is useful to have a
26ccd9
local copy of the UAPI header for cxl_mem definitions. This allows
26ccd9
building cxl and libcxl on systems where the appropriate kernel headers
26ccd9
are not installed in the usual locations.
26ccd9
26ccd9
Cc: Ben Widawsky <ben.widawsky@intel.com>
26ccd9
Cc: Dan Williams <dan.j.williams@intel.com>
26ccd9
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 Makefile.am         |   3 +-
26ccd9
 Makefile.am.in      |   1 +
26ccd9
 cxl/cxl_mem.h       | 189 ++++++++++++++++++++++++++++++++++++++++++++
26ccd9
 cxl/lib/Makefile.am |   2 +-
26ccd9
 4 files changed, 193 insertions(+), 2 deletions(-)
26ccd9
 create mode 100644 cxl/cxl_mem.h
26ccd9
26ccd9
diff --git a/Makefile.am b/Makefile.am
26ccd9
index 428fd40..4904ee7 100644
26ccd9
--- a/Makefile.am
26ccd9
+++ b/Makefile.am
26ccd9
@@ -89,4 +89,5 @@ libutil_a_SOURCES = \
26ccd9
 
26ccd9
 nobase_include_HEADERS = \
26ccd9
 	daxctl/libdaxctl.h \
26ccd9
-	cxl/libcxl.h
26ccd9
+	cxl/libcxl.h \
26ccd9
+	cxl/cxl_mem.h
26ccd9
diff --git a/Makefile.am.in b/Makefile.am.in
26ccd9
index aaeee53..a748128 100644
26ccd9
--- a/Makefile.am.in
26ccd9
+++ b/Makefile.am.in
26ccd9
@@ -11,6 +11,7 @@ AM_CPPFLAGS = \
26ccd9
 	-DNDCTL_MAN_PATH=\""$(mandir)"\" \
26ccd9
 	-I${top_srcdir}/ndctl/lib \
26ccd9
 	-I${top_srcdir}/ndctl \
26ccd9
+	-I${top_srcdir}/cxl \
26ccd9
 	-I${top_srcdir}/ \
26ccd9
 	$(KMOD_CFLAGS) \
26ccd9
 	$(UDEV_CFLAGS) \
26ccd9
diff --git a/cxl/cxl_mem.h b/cxl/cxl_mem.h
26ccd9
new file mode 100644
26ccd9
index 0000000..d38cc9c
26ccd9
--- /dev/null
26ccd9
+++ b/cxl/cxl_mem.h
26ccd9
@@ -0,0 +1,189 @@
26ccd9
+/* SPDX-License-Identifier: LGPL-2.1 */
26ccd9
+/* Copyright (C) 2020-2021, Intel Corporation. All rights reserved. */
26ccd9
+/*
26ccd9
+ * CXL IOCTLs for Memory Devices
26ccd9
+ */
26ccd9
+
26ccd9
+#ifndef _UAPI_CXL_MEM_H_
26ccd9
+#define _UAPI_CXL_MEM_H_
26ccd9
+
26ccd9
+#include <linux/types.h>
26ccd9
+#include <sys/user.h>
26ccd9
+#include <unistd.h>
26ccd9
+
26ccd9
+#define __user
26ccd9
+
26ccd9
+/**
26ccd9
+ * DOC: UAPI
26ccd9
+ *
26ccd9
+ * Not all of all commands that the driver supports are always available for use
26ccd9
+ * by userspace. Userspace must check the results from the QUERY command in
26ccd9
+ * order to determine the live set of commands.
26ccd9
+ */
26ccd9
+
26ccd9
+#define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands)
26ccd9
+#define CXL_MEM_SEND_COMMAND _IOWR(0xCE, 2, struct cxl_send_command)
26ccd9
+
26ccd9
+#define CXL_CMDS                                                          \
26ccd9
+	___C(INVALID, "Invalid Command"),                                 \
26ccd9
+	___C(IDENTIFY, "Identify Command"),                               \
26ccd9
+	___C(RAW, "Raw device command"),                                  \
26ccd9
+	___C(GET_SUPPORTED_LOGS, "Get Supported Logs"),                   \
26ccd9
+	___C(GET_FW_INFO, "Get FW Info"),                                 \
26ccd9
+	___C(GET_PARTITION_INFO, "Get Partition Information"),            \
26ccd9
+	___C(GET_LSA, "Get Label Storage Area"),                          \
26ccd9
+	___C(GET_HEALTH_INFO, "Get Health Info"),                         \
26ccd9
+	___C(GET_LOG, "Get Log"),                                         \
26ccd9
+	___C(SET_PARTITION_INFO, "Set Partition Information"),            \
26ccd9
+	___C(SET_LSA, "Set Label Storage Area"),                          \
26ccd9
+	___C(GET_ALERT_CONFIG, "Get Alert Configuration"),                \
26ccd9
+	___C(SET_ALERT_CONFIG, "Set Alert Configuration"),                \
26ccd9
+	___C(GET_SHUTDOWN_STATE, "Get Shutdown State"),                   \
26ccd9
+	___C(SET_SHUTDOWN_STATE, "Set Shutdown State"),                   \
26ccd9
+	___C(GET_POISON, "Get Poison List"),                              \
26ccd9
+	___C(INJECT_POISON, "Inject Poison"),                             \
26ccd9
+	___C(CLEAR_POISON, "Clear Poison"),                               \
26ccd9
+	___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"),         \
26ccd9
+	___C(SCAN_MEDIA, "Scan Media"),                                   \
26ccd9
+	___C(GET_SCAN_MEDIA, "Get Scan Media Results"),                   \
26ccd9
+	___C(MAX, "invalid / last command")
26ccd9
+
26ccd9
+#define ___C(a, b) CXL_MEM_COMMAND_ID_##a
26ccd9
+enum { CXL_CMDS };
26ccd9
+
26ccd9
+#undef ___C
26ccd9
+#define ___C(a, b) { b }
26ccd9
+static const struct {
26ccd9
+	const char *name;
26ccd9
+} cxl_command_names[] = { CXL_CMDS };
26ccd9
+
26ccd9
+/*
26ccd9
+ * Here's how this actually breaks out:
26ccd9
+ * cxl_command_names[] = {
26ccd9
+ *	[CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
26ccd9
+ *	[CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" },
26ccd9
+ *	...
26ccd9
+ *	[CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
26ccd9
+ * };
26ccd9
+ */
26ccd9
+
26ccd9
+#undef ___C
26ccd9
+
26ccd9
+/**
26ccd9
+ * struct cxl_command_info - Command information returned from a query.
26ccd9
+ * @id: ID number for the command.
26ccd9
+ * @flags: Flags that specify command behavior.
26ccd9
+ * @size_in: Expected input size, or -1 if variable length.
26ccd9
+ * @size_out: Expected output size, or -1 if variable length.
26ccd9
+ *
26ccd9
+ * Represents a single command that is supported by both the driver and the
26ccd9
+ * hardware. This is returned as part of an array from the query ioctl. The
26ccd9
+ * following would be a command that takes a variable length input and returns 0
26ccd9
+ * bytes of output.
26ccd9
+ *
26ccd9
+ *  - @id = 10
26ccd9
+ *  - @flags = 0
26ccd9
+ *  - @size_in = -1
26ccd9
+ *  - @size_out = 0
26ccd9
+ *
26ccd9
+ * See struct cxl_mem_query_commands.
26ccd9
+ */
26ccd9
+struct cxl_command_info {
26ccd9
+	__u32 id;
26ccd9
+
26ccd9
+	__u32 flags;
26ccd9
+#define CXL_MEM_COMMAND_FLAG_MASK GENMASK(0, 0)
26ccd9
+
26ccd9
+	__s32 size_in;
26ccd9
+	__s32 size_out;
26ccd9
+};
26ccd9
+
26ccd9
+/**
26ccd9
+ * struct cxl_mem_query_commands - Query supported commands.
26ccd9
+ * @n_commands: In/out parameter. When @n_commands is > 0, the driver will
26ccd9
+ *		return min(num_support_commands, n_commands). When @n_commands
26ccd9
+ *		is 0, driver will return the number of total supported commands.
26ccd9
+ * @rsvd: Reserved for future use.
26ccd9
+ * @commands: Output array of supported commands. This array must be allocated
26ccd9
+ *            by userspace to be at least min(num_support_commands, @n_commands)
26ccd9
+ *
26ccd9
+ * Allow userspace to query the available commands supported by both the driver,
26ccd9
+ * and the hardware. Commands that aren't supported by either the driver, or the
26ccd9
+ * hardware are not returned in the query.
26ccd9
+ *
26ccd9
+ * Examples:
26ccd9
+ *
26ccd9
+ *  - { .n_commands = 0 } // Get number of supported commands
26ccd9
+ *  - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
26ccd9
+ *    supported commands
26ccd9
+ *
26ccd9
+ *  See struct cxl_command_info.
26ccd9
+ */
26ccd9
+struct cxl_mem_query_commands {
26ccd9
+	/*
26ccd9
+	 * Input: Number of commands to return (space allocated by user)
26ccd9
+	 * Output: Number of commands supported by the driver/hardware
26ccd9
+	 *
26ccd9
+	 * If n_commands is 0, kernel will only return number of commands and
26ccd9
+	 * not try to populate commands[], thus allowing userspace to know how
26ccd9
+	 * much space to allocate
26ccd9
+	 */
26ccd9
+	__u32 n_commands;
26ccd9
+	__u32 rsvd;
26ccd9
+
26ccd9
+	struct cxl_command_info __user commands[]; /* out: supported commands */
26ccd9
+};
26ccd9
+
26ccd9
+/**
26ccd9
+ * struct cxl_send_command - Send a command to a memory device.
26ccd9
+ * @id: The command to send to the memory device. This must be one of the
26ccd9
+ *	commands returned by the query command.
26ccd9
+ * @flags: Flags for the command (input).
26ccd9
+ * @raw: Special fields for raw commands
26ccd9
+ * @raw.opcode: Opcode passed to hardware when using the RAW command.
26ccd9
+ * @raw.rsvd: Must be zero.
26ccd9
+ * @rsvd: Must be zero.
26ccd9
+ * @retval: Return value from the memory device (output).
26ccd9
+ * @in: Parameters associated with input payload.
26ccd9
+ * @in.size: Size of the payload to provide to the device (input).
26ccd9
+ * @in.rsvd: Must be zero.
26ccd9
+ * @in.payload: Pointer to memory for payload input, payload is little endian.
26ccd9
+ * @out: Parameters associated with output payload.
26ccd9
+ * @out.size: Size of the payload received from the device (input/output). This
26ccd9
+ *	      field is filled in by userspace to let the driver know how much
26ccd9
+ *	      space was allocated for output. It is populated by the driver to
26ccd9
+ *	      let userspace know how large the output payload actually was.
26ccd9
+ * @out.rsvd: Must be zero.
26ccd9
+ * @out.payload: Pointer to memory for payload output, payload is little endian.
26ccd9
+ *
26ccd9
+ * Mechanism for userspace to send a command to the hardware for processing. The
26ccd9
+ * driver will do basic validation on the command sizes. In some cases even the
26ccd9
+ * payload may be introspected. Userspace is required to allocate large enough
26ccd9
+ * buffers for size_out which can be variable length in certain situations.
26ccd9
+ */
26ccd9
+struct cxl_send_command {
26ccd9
+	__u32 id;
26ccd9
+	__u32 flags;
26ccd9
+	union {
26ccd9
+		struct {
26ccd9
+			__u16 opcode;
26ccd9
+			__u16 rsvd;
26ccd9
+		} raw;
26ccd9
+		__u32 rsvd;
26ccd9
+	};
26ccd9
+	__u32 retval;
26ccd9
+
26ccd9
+	struct {
26ccd9
+		__s32 size;
26ccd9
+		__u32 rsvd;
26ccd9
+		__u64 payload;
26ccd9
+	} in;
26ccd9
+
26ccd9
+	struct {
26ccd9
+		__s32 size;
26ccd9
+		__u32 rsvd;
26ccd9
+		__u64 payload;
26ccd9
+	} out;
26ccd9
+};
26ccd9
+
26ccd9
+#endif
26ccd9
diff --git a/cxl/lib/Makefile.am b/cxl/lib/Makefile.am
26ccd9
index 277f0cd..72c9ccd 100644
26ccd9
--- a/cxl/lib/Makefile.am
26ccd9
+++ b/cxl/lib/Makefile.am
26ccd9
@@ -3,7 +3,7 @@ include $(top_srcdir)/Makefile.am.in
26ccd9
 %.pc: %.pc.in Makefile
26ccd9
 	$(SED_PROCESS)
26ccd9
 
26ccd9
-pkginclude_HEADERS = ../libcxl.h
26ccd9
+pkginclude_HEADERS = ../libcxl.h ../cxl_mem.h
26ccd9
 lib_LTLIBRARIES = libcxl.la
26ccd9
 
26ccd9
 libcxl_la_SOURCES =\
26ccd9
-- 
26ccd9
2.27.0
26ccd9