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

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