anitazha / rpms / ndctl

Forked from rpms/ndctl 2 years ago
Clone

Blame 0191-cxl-memdev-refactor-decoder-mode-string-parsing.patch

Jeff Moyer 2c91dc
From 14565442634cfab0aac8823129a175be572fb11e Mon Sep 17 00:00:00 2001
Jeff Moyer 2c91dc
From: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
Date: Mon, 15 Aug 2022 13:22:06 -0600
Jeff Moyer 2c91dc
Subject: [PATCH 191/217] cxl/memdev: refactor decoder mode string parsing
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
In preparation for create-region to use a similar decoder mode string
Jeff Moyer 2c91dc
to enum operation, break out the mode string parsing into its own inline
Jeff Moyer 2c91dc
helper in libcxl.h, and call it from memdev.c:__reserve_dpa().
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
Link: https://lore.kernel.org/r/20220815192214.545800-4-vishal.l.verma@intel.com
Jeff Moyer 2c91dc
Cc: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Jeff Moyer 2c91dc
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Jeff Moyer 2c91dc
---
Jeff Moyer 2c91dc
 cxl/libcxl.h | 13 +++++++++++++
Jeff Moyer 2c91dc
 cxl/memdev.c | 11 ++---------
Jeff Moyer 2c91dc
 2 files changed, 15 insertions(+), 9 deletions(-)
Jeff Moyer 2c91dc
Jeff Moyer 2c91dc
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
Jeff Moyer 2c91dc
index 33a216e..c1f8d14 100644
Jeff Moyer 2c91dc
--- a/cxl/libcxl.h
Jeff Moyer 2c91dc
+++ b/cxl/libcxl.h
Jeff Moyer 2c91dc
@@ -4,6 +4,7 @@
Jeff Moyer 2c91dc
 #define _LIBCXL_H_
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 #include <stdarg.h>
Jeff Moyer 2c91dc
+#include <string.h>
Jeff Moyer 2c91dc
 #include <unistd.h>
Jeff Moyer 2c91dc
 #include <stdbool.h>
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
@@ -154,6 +155,18 @@ static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)
Jeff Moyer 2c91dc
 	return names[mode];
Jeff Moyer 2c91dc
 }
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
+static inline enum cxl_decoder_mode
Jeff Moyer 2c91dc
+cxl_decoder_mode_from_ident(const char *ident)
Jeff Moyer 2c91dc
+{
Jeff Moyer 2c91dc
+	if (strcmp(ident, "ram") == 0)
Jeff Moyer 2c91dc
+		return CXL_DECODER_MODE_RAM;
Jeff Moyer 2c91dc
+	else if (strcmp(ident, "volatile") == 0)
Jeff Moyer 2c91dc
+		return CXL_DECODER_MODE_RAM;
Jeff Moyer 2c91dc
+	else if (strcmp(ident, "pmem") == 0)
Jeff Moyer 2c91dc
+		return CXL_DECODER_MODE_PMEM;
Jeff Moyer 2c91dc
+	return CXL_DECODER_MODE_NONE;
Jeff Moyer 2c91dc
+}
Jeff Moyer 2c91dc
+
Jeff Moyer 2c91dc
 enum cxl_decoder_mode cxl_decoder_get_mode(struct cxl_decoder *decoder);
Jeff Moyer 2c91dc
 int cxl_decoder_set_mode(struct cxl_decoder *decoder,
Jeff Moyer 2c91dc
 			 enum cxl_decoder_mode mode);
Jeff Moyer 2c91dc
diff --git a/cxl/memdev.c b/cxl/memdev.c
Jeff Moyer 2c91dc
index e42f554..0b3ad02 100644
Jeff Moyer 2c91dc
--- a/cxl/memdev.c
Jeff Moyer 2c91dc
+++ b/cxl/memdev.c
Jeff Moyer 2c91dc
@@ -154,15 +154,8 @@ static int __reserve_dpa(struct cxl_memdev *memdev,
Jeff Moyer 2c91dc
 	int rc;
Jeff Moyer 2c91dc
 
Jeff Moyer 2c91dc
 	if (param.type) {
Jeff Moyer 2c91dc
-		if (strcmp(param.type, "ram") == 0)
Jeff Moyer 2c91dc
-			mode = CXL_DECODER_MODE_RAM;
Jeff Moyer 2c91dc
-		else if (strcmp(param.type, "volatile") == 0)
Jeff Moyer 2c91dc
-			mode = CXL_DECODER_MODE_RAM;
Jeff Moyer 2c91dc
-		else if (strcmp(param.type, "ram") == 0)
Jeff Moyer 2c91dc
-			mode = CXL_DECODER_MODE_RAM;
Jeff Moyer 2c91dc
-		else if (strcmp(param.type, "pmem") == 0)
Jeff Moyer 2c91dc
-			mode = CXL_DECODER_MODE_PMEM;
Jeff Moyer 2c91dc
-		else {
Jeff Moyer 2c91dc
+		mode = cxl_decoder_mode_from_ident(param.type);
Jeff Moyer 2c91dc
+		if (mode == CXL_DECODER_MODE_NONE) {
Jeff Moyer 2c91dc
 			log_err(&ml, "%s: unsupported type: %s\n", devname,
Jeff Moyer 2c91dc
 				param.type);
Jeff Moyer 2c91dc
 			return -EINVAL;
Jeff Moyer 2c91dc
-- 
Jeff Moyer 2c91dc
2.27.0
Jeff Moyer 2c91dc