anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame SOURCES/0136-libcxl-add-interfaces-for-SET_PARTITION_INFO-mailbox.patch

e0018b
From b424b4bfd555654fc41996e964bdd0495f585793 Mon Sep 17 00:00:00 2001
e0018b
From: Alison Schofield <alison.schofield@intel.com>
e0018b
Date: Tue, 22 Feb 2022 11:56:07 -0800
e0018b
Subject: [PATCH 136/217] libcxl: add interfaces for SET_PARTITION_INFO mailbox
e0018b
 command
e0018b
e0018b
The CXL PMEM provisioning model depends upon the CXL mailbox command
e0018b
SET_PARTITION_INFO to change a device's partitioning between volatile
e0018b
and persistent capacity.
e0018b
e0018b
Add interfaces to libcxl to allocate and send a SET_PARTITION_INFO
e0018b
mailbox command as defined in the CXL 2.0 specification.
e0018b
e0018b
Link: https://lore.kernel.org/r/978c1cf78f3dd22f6070e51a241bc63cac9297de.1645558189.git.alison.schofield@intel.com
e0018b
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 Documentation/cxl/lib/libcxl.txt | 11 +++++++++++
e0018b
 cxl/lib/libcxl.c                 | 28 ++++++++++++++++++++++++++++
e0018b
 cxl/lib/libcxl.sym               |  2 ++
e0018b
 cxl/lib/private.h                |  8 ++++++++
e0018b
 cxl/libcxl.h                     | 10 ++++++++++
e0018b
 5 files changed, 59 insertions(+)
e0018b
e0018b
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
e0018b
index a6986ab..7b223cb 100644
e0018b
--- a/Documentation/cxl/lib/libcxl.txt
e0018b
+++ b/Documentation/cxl/lib/libcxl.txt
e0018b
@@ -132,6 +132,8 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
e0018b
 int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
e0018b
 			   size_t offset);
e0018b
 struct cxl_cmd *cxl_cmd_new_get_partition(struct cxl_memdev *memdev);
e0018b
+struct cxl_cmd *cxl_cmd_new_set_partition(struct cxl_memdev *memdev,
e0018b
+					  unsigned long long volatile_size);
e0018b
 
e0018b
 ----
e0018b
 
e0018b
@@ -148,6 +150,8 @@ this sub-class of interfaces, there are:
e0018b
    a CXL standard opcode. See the potential command ids in
e0018b
    /usr/include/linux/cxl_mem.h.
e0018b
 
e0018b
+ * 'cxl_cmd_<name>_set_<field>' interfaces that set specific fields in a cxl_cmd
e0018b
+
e0018b
  * 'cxl_cmd_submit' which submits the command via ioctl()
e0018b
 
e0018b
  * 'cxl_cmd_<name>_get_<field>' interfaces that get specific fields out of the
e0018b
@@ -167,6 +171,13 @@ cxl_memdev{read,write,zero}_label() are helpers for marshaling multiple
e0018b
 label access commands over an arbitrary extent of the device's label
e0018b
 area.
e0018b
 
e0018b
+cxl_cmd_partition_set_mode() supports selecting NEXTBOOT or IMMEDIATE
e0018b
+mode. When CXL_SETPART_IMMEDIATE mode is set, it is the caller’s
e0018b
+responsibility to avoid immediate changes to partitioning when the
e0018b
+device is in use. When CXL_SETPART_NEXTBOOT mode is set, the change
e0018b
+in partitioning shall become the “next” configuration, to become
e0018b
+active on the next device reset.
e0018b
+
e0018b
 BUSES
e0018b
 -----
e0018b
 The CXL Memory space is CPU and Device coherent. The address ranges that
e0018b
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
e0018b
index c05c13c..daa2bbc 100644
e0018b
--- a/cxl/lib/libcxl.c
e0018b
+++ b/cxl/lib/libcxl.c
e0018b
@@ -2478,6 +2478,34 @@ cxl_cmd_partition_get_next_persistent_size(struct cxl_cmd *cmd)
e0018b
 	return cxl_capacity_to_bytes(c->next_persistent);
e0018b
 }
e0018b
 
e0018b
+CXL_EXPORT int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd,
e0018b
+		enum cxl_setpartition_mode mode)
e0018b
+{
e0018b
+	struct cxl_cmd_set_partition *setpart = cmd->input_payload;
e0018b
+
e0018b
+	if (mode == CXL_SETPART_IMMEDIATE)
e0018b
+		setpart->flags = CXL_CMD_SET_PARTITION_FLAG_IMMEDIATE;
e0018b
+	else
e0018b
+		setpart->flags = !CXL_CMD_SET_PARTITION_FLAG_IMMEDIATE;
e0018b
+
e0018b
+	return 0;
e0018b
+}
e0018b
+
e0018b
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition(struct cxl_memdev *memdev,
e0018b
+		unsigned long long volatile_size)
e0018b
+{
e0018b
+	struct cxl_cmd_set_partition *setpart;
e0018b
+	struct cxl_cmd *cmd;
e0018b
+
e0018b
+	cmd = cxl_cmd_new_generic(memdev,
e0018b
+			CXL_MEM_COMMAND_ID_SET_PARTITION_INFO);
e0018b
+
e0018b
+	setpart = cmd->input_payload;
e0018b
+	setpart->volatile_size = cpu_to_le64(volatile_size)
e0018b
+					/ CXL_CAPACITY_MULTIPLIER;
e0018b
+	return cmd;
e0018b
+}
e0018b
+
e0018b
 CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
e0018b
 {
e0018b
 	struct cxl_memdev *memdev = cmd->memdev;
e0018b
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
e0018b
index 5ac6e9b..aab1112 100644
e0018b
--- a/cxl/lib/libcxl.sym
e0018b
+++ b/cxl/lib/libcxl.sym
e0018b
@@ -163,4 +163,6 @@ global:
e0018b
 	cxl_cmd_identify_get_total_size;
e0018b
 	cxl_cmd_identify_get_volatile_only_size;
e0018b
 	cxl_cmd_identify_get_persistent_only_size;
e0018b
+	cxl_cmd_new_set_partition;
e0018b
+	cxl_cmd_partition_set_mode;
e0018b
 } LIBCXL_1;
e0018b
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
e0018b
index 7f3a562..c6d88f7 100644
e0018b
--- a/cxl/lib/private.h
e0018b
+++ b/cxl/lib/private.h
e0018b
@@ -195,6 +195,14 @@ struct cxl_cmd_get_partition {
e0018b
 
e0018b
 #define CXL_CAPACITY_MULTIPLIER		SZ_256M
e0018b
 
e0018b
+struct cxl_cmd_set_partition {
e0018b
+	le64 volatile_size;
e0018b
+	u8 flags;
e0018b
+} __attribute__((packed));
e0018b
+
e0018b
+/* CXL 2.0 8.2.9.5.2 Set Partition Info */
e0018b
+#define CXL_CMD_SET_PARTITION_FLAG_IMMEDIATE				BIT(0)
e0018b
+
e0018b
 /* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */
e0018b
 #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK		BIT(0)
e0018b
 #define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK		BIT(1)
e0018b
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
e0018b
index 6e18e84..0063d31 100644
e0018b
--- a/cxl/libcxl.h
e0018b
+++ b/cxl/libcxl.h
e0018b
@@ -250,6 +250,16 @@ unsigned long long cxl_cmd_partition_get_active_volatile_size(struct cxl_cmd *cm
e0018b
 unsigned long long cxl_cmd_partition_get_active_persistent_size(struct cxl_cmd *cmd);
e0018b
 unsigned long long cxl_cmd_partition_get_next_volatile_size(struct cxl_cmd *cmd);
e0018b
 unsigned long long cxl_cmd_partition_get_next_persistent_size(struct cxl_cmd *cmd);
e0018b
+struct cxl_cmd *cxl_cmd_new_set_partition(struct cxl_memdev *memdev,
e0018b
+		unsigned long long volatile_size);
e0018b
+
e0018b
+enum cxl_setpartition_mode {
e0018b
+	CXL_SETPART_NEXTBOOT,
e0018b
+	CXL_SETPART_IMMEDIATE,
e0018b
+};
e0018b
+
e0018b
+int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd,
e0018b
+		enum cxl_setpartition_mode mode);
e0018b
 
e0018b
 #ifdef __cplusplus
e0018b
 } /* extern "C" */
e0018b
-- 
e0018b
2.27.0
e0018b