Blame SOURCES/0132-libcxl-add-GET_PARTITION_INFO-mailbox-command-and-ac.patch

26ccd9
From 4f588b964dccf72030b1c432ed5dd8e2856f9d38 Mon Sep 17 00:00:00 2001
26ccd9
From: Alison Schofield <alison.schofield@intel.com>
26ccd9
Date: Tue, 22 Feb 2022 11:56:03 -0800
26ccd9
Subject: [PATCH 132/217] libcxl: add GET_PARTITION_INFO mailbox command and
26ccd9
 accessors
26ccd9
26ccd9
The CXL PMEM provisioning model depends upon the values reported
26ccd9
in the CXL GET_PARTITION_INFO mailbox command when changing the
26ccd9
partitioning between volatile and persistent capacity.
26ccd9
26ccd9
Add libcxl APIs to create a new GET_PARTITION_INFO mailbox command,
26ccd9
the command output data structure (privately), and accessor APIs to
26ccd9
return the fields in the partition info output.
26ccd9
26ccd9
Per the CXL 2.0 specification, devices report partition capacities
26ccd9
as multiples of 256MB. Define and use a capacity multiplier to
26ccd9
convert the raw data into bytes for user consumption. Use byte
26ccd9
format as the norm for all capacity values produced or consumed
26ccd9
using CXL Mailbox commands.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/6cd7fffe1a95c9a1bc2239cb342067df564401a5.1645558189.git.alison.schofield@intel.com
26ccd9
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 Documentation/cxl/lib/libcxl.txt |  1 +
26ccd9
 cxl/lib/libcxl.c                 | 66 ++++++++++++++++++++++++++++++++
26ccd9
 cxl/lib/libcxl.sym               |  5 +++
26ccd9
 cxl/lib/private.h                | 10 +++++
26ccd9
 cxl/libcxl.h                     |  5 +++
26ccd9
 util/size.h                      |  1 +
26ccd9
 6 files changed, 88 insertions(+)
26ccd9
26ccd9
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
26ccd9
index 4392b47..a6986ab 100644
26ccd9
--- a/Documentation/cxl/lib/libcxl.txt
26ccd9
+++ b/Documentation/cxl/lib/libcxl.txt
26ccd9
@@ -131,6 +131,7 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
26ccd9
 			  size_t offset);
26ccd9
 int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
26ccd9
 			   size_t offset);
26ccd9
+struct cxl_cmd *cxl_cmd_new_get_partition(struct cxl_memdev *memdev);
26ccd9
 
26ccd9
 ----
26ccd9
 
26ccd9
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
26ccd9
index e0b443f..4557a71 100644
26ccd9
--- a/cxl/lib/libcxl.c
26ccd9
+++ b/cxl/lib/libcxl.c
26ccd9
@@ -1985,6 +1985,11 @@ static int cxl_cmd_validate_status(struct cxl_cmd *cmd, u32 id)
26ccd9
 	return 0;
26ccd9
 }
26ccd9
 
26ccd9
+static uint64_t cxl_capacity_to_bytes(leint64_t size)
26ccd9
+{
26ccd9
+	return le64_to_cpu(size) * CXL_CAPACITY_MULTIPLIER;
26ccd9
+}
26ccd9
+
26ccd9
 /* Helpers for health_info fields (no endian conversion) */
26ccd9
 #define cmd_get_field_u8(cmd, n, N, field)				\
26ccd9
 do {									\
26ccd9
@@ -2371,6 +2376,67 @@ CXL_EXPORT ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd,
26ccd9
 	return length;
26ccd9
 }
26ccd9
 
26ccd9
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_get_partition(struct cxl_memdev *memdev)
26ccd9
+{
26ccd9
+	return cxl_cmd_new_generic(memdev,
26ccd9
+				   CXL_MEM_COMMAND_ID_GET_PARTITION_INFO);
26ccd9
+}
26ccd9
+
26ccd9
+static struct cxl_cmd_get_partition *
26ccd9
+cmd_to_get_partition(struct cxl_cmd *cmd)
26ccd9
+{
26ccd9
+	if (cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_GET_PARTITION_INFO))
26ccd9
+		return NULL;
26ccd9
+
26ccd9
+	if (!cmd)
26ccd9
+		return NULL;
26ccd9
+	return cmd->output_payload;
26ccd9
+}
26ccd9
+
26ccd9
+CXL_EXPORT unsigned long long
26ccd9
+cxl_cmd_partition_get_active_volatile_size(struct cxl_cmd *cmd)
26ccd9
+{
26ccd9
+	struct cxl_cmd_get_partition *c;
26ccd9
+
26ccd9
+	c = cmd_to_get_partition(cmd);
26ccd9
+	if (!c)
26ccd9
+		return ULLONG_MAX;
26ccd9
+	return cxl_capacity_to_bytes(c->active_volatile);
26ccd9
+}
26ccd9
+
26ccd9
+CXL_EXPORT unsigned long long
26ccd9
+cxl_cmd_partition_get_active_persistent_size(struct cxl_cmd *cmd)
26ccd9
+{
26ccd9
+	struct cxl_cmd_get_partition *c;
26ccd9
+
26ccd9
+	c = cmd_to_get_partition(cmd);
26ccd9
+	if (!c)
26ccd9
+		return ULLONG_MAX;
26ccd9
+	return cxl_capacity_to_bytes(c->active_persistent);
26ccd9
+}
26ccd9
+
26ccd9
+CXL_EXPORT unsigned long long
26ccd9
+cxl_cmd_partition_get_next_volatile_size(struct cxl_cmd *cmd)
26ccd9
+{
26ccd9
+	struct cxl_cmd_get_partition *c;
26ccd9
+
26ccd9
+	c = cmd_to_get_partition(cmd);
26ccd9
+	if (!c)
26ccd9
+		return ULLONG_MAX;
26ccd9
+	return cxl_capacity_to_bytes(c->next_volatile);
26ccd9
+}
26ccd9
+
26ccd9
+CXL_EXPORT unsigned long long
26ccd9
+cxl_cmd_partition_get_next_persistent_size(struct cxl_cmd *cmd)
26ccd9
+{
26ccd9
+	struct cxl_cmd_get_partition *c;
26ccd9
+
26ccd9
+	c = cmd_to_get_partition(cmd);
26ccd9
+	if (!c)
26ccd9
+		return ULLONG_MAX;
26ccd9
+	return cxl_capacity_to_bytes(c->next_persistent);
26ccd9
+}
26ccd9
+
26ccd9
 CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
26ccd9
 {
26ccd9
 	struct cxl_memdev *memdev = cmd->memdev;
26ccd9
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
26ccd9
index e56a2bf..509e62d 100644
26ccd9
--- a/cxl/lib/libcxl.sym
26ccd9
+++ b/cxl/lib/libcxl.sym
26ccd9
@@ -155,4 +155,9 @@ global:
26ccd9
 	cxl_dport_get_port;
26ccd9
 	cxl_port_get_dport_by_memdev;
26ccd9
 	cxl_dport_maps_memdev;
26ccd9
+	cxl_cmd_new_get_partition;
26ccd9
+	cxl_cmd_partition_get_active_volatile_size;
26ccd9
+	cxl_cmd_partition_get_active_persistent_size;
26ccd9
+	cxl_cmd_partition_get_next_volatile_size;
26ccd9
+	cxl_cmd_partition_get_next_persistent_size;
26ccd9
 } LIBCXL_1;
26ccd9
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
26ccd9
index f483c30..7f3a562 100644
26ccd9
--- a/cxl/lib/private.h
26ccd9
+++ b/cxl/lib/private.h
26ccd9
@@ -7,6 +7,7 @@
26ccd9
 #include <cxl/cxl_mem.h>
26ccd9
 #include <ccan/endian/endian.h>
26ccd9
 #include <ccan/short_types/short_types.h>
26ccd9
+#include <util/size.h>
26ccd9
 
26ccd9
 #define CXL_EXPORT __attribute__ ((visibility("default")))
26ccd9
 
26ccd9
@@ -185,6 +186,15 @@ struct cxl_cmd_get_health_info {
26ccd9
 	le32 pmem_errors;
26ccd9
 } __attribute__((packed));
26ccd9
 
26ccd9
+struct cxl_cmd_get_partition {
26ccd9
+	le64 active_volatile;
26ccd9
+	le64 active_persistent;
26ccd9
+	le64 next_volatile;
26ccd9
+	le64 next_persistent;
26ccd9
+} __attribute__((packed));
26ccd9
+
26ccd9
+#define CXL_CAPACITY_MULTIPLIER		SZ_256M
26ccd9
+
26ccd9
 /* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */
26ccd9
 #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK		BIT(0)
26ccd9
 #define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK		BIT(1)
26ccd9
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
26ccd9
index 3b2293b..2c0a8d1 100644
26ccd9
--- a/cxl/libcxl.h
26ccd9
+++ b/cxl/libcxl.h
26ccd9
@@ -242,6 +242,11 @@ ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf,
26ccd9
 		unsigned int length);
26ccd9
 struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev,
26ccd9
 		void *buf, unsigned int offset, unsigned int length);
26ccd9
+struct cxl_cmd *cxl_cmd_new_get_partition(struct cxl_memdev *memdev);
26ccd9
+unsigned long long cxl_cmd_partition_get_active_volatile_size(struct cxl_cmd *cmd);
26ccd9
+unsigned long long cxl_cmd_partition_get_active_persistent_size(struct cxl_cmd *cmd);
26ccd9
+unsigned long long cxl_cmd_partition_get_next_volatile_size(struct cxl_cmd *cmd);
26ccd9
+unsigned long long cxl_cmd_partition_get_next_persistent_size(struct cxl_cmd *cmd);
26ccd9
 
26ccd9
 #ifdef __cplusplus
26ccd9
 } /* extern "C" */
26ccd9
diff --git a/util/size.h b/util/size.h
26ccd9
index a0f3593..e72467f 100644
26ccd9
--- a/util/size.h
26ccd9
+++ b/util/size.h
26ccd9
@@ -15,6 +15,7 @@
26ccd9
 #define SZ_4M     0x00400000
26ccd9
 #define SZ_16M    0x01000000
26ccd9
 #define SZ_64M    0x04000000
26ccd9
+#define SZ_256M	  0x10000000
26ccd9
 #define SZ_1G     0x40000000
26ccd9
 #define SZ_1T 0x10000000000ULL
26ccd9
 
26ccd9
-- 
26ccd9
2.27.0
26ccd9