ndctl/0191-cxl-memdev-refactor-decoder-mode-string-parsing.patch
Jeff Moyer 2c91dc1bcd Backport changes up to v74, excluding the config file changes
This includes support for the CXL commands, and adds the following
packages: cxl-cli, cxl-devel, cxl-libs.

Resolves: rhbz#2132167
2022-10-13 16:55:42 -04:00

75 lines
2.3 KiB
Diff

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