anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

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

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