From: Vishal Verma <vishal.l.verma@intel.com>
To: <linux-cxl@vger.kernel.org>
Cc: <nvdimm@lists.linux.dev>, Dan Williams <dan.j.williams@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>
Subject: [ndctl PATCH v3 03/11] cxl/memdev: refactor decoder mode string parsing
Date: Mon, 15 Aug 2022 13:22:06 -0600 [thread overview]
Message-ID: <20220815192214.545800-4-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20220815192214.545800-1-vishal.l.verma@intel.com>
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().
Cc: 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.37.1
next prev parent reply other threads:[~2022-08-15 19:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 19:22 [ndctl PATCH v3 00/11] cxl: add region management Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 01/11] libcxl: add a depth attribute to cxl_port Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 02/11] cxl/port: Consolidate the debug option in cxl-port man pages Vishal Verma
2022-08-15 19:22 ` Vishal Verma [this message]
2022-08-15 22:57 ` [ndctl PATCH v3 03/11] cxl/memdev: refactor decoder mode string parsing Dan Williams
2022-08-15 19:22 ` [ndctl PATCH v3 04/11] libcxl: Introduce libcxl region and mapping objects Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 05/11] cxl-cli: add region listing support Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 06/11] libcxl: add low level APIs for region creation Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 07/11] cxl: add a 'create-region' command Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 08/11] cxl: add commands to {enable,disable,destroy}-region Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 09/11] cxl/list: make memdevs and regions the default listing Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 10/11] test: add a cxl-create-region test Vishal Verma
2022-08-15 19:22 ` [ndctl PATCH v3 11/11] cxl/decoder: add a max_available_extent attribute Vishal Verma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220815192214.545800-4-vishal.l.verma@intel.com \
--to=vishal.l.verma@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).