anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

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

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