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

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