Skip to contentSkip to conversation

Initial CXL support

PATCH Superseded Vishal Verma 3 participants 31 messages Nov 11, 2021 – Jan 31, 2022

Subsystems (4)
lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

v5 cover Initial CXL support

Changes since v4[1]:

- Collect review tags
- Handle the case where label_size > payload_max. With cxl_test labels being 128K, it was easy to hit this case, so add in the handling to loop over the label space in payload_max sized chunks to read/write the full label area.
- Make label APIs consistent for what size==0 means (Dan)
- Introduce an nvdimm bridge object, and an API to check whether one is active, replacing the stub 'cxl_memdev_is_active() API) (Dan)
- Import Linux's FIELD_GET() and use it for health_info accessors (Dan)
- Move all symbols to the v1 group in libcxl.sym since this is the first release (Dan)
- Replace the implicit cmd struct casting via (void *) with explicit casts to the respective structs (Dan).
- Various man page fixups (Dan)
- Switch json_object_new_uint64 to json_object_new_int, as the former is a relatively new API, and unavailable in some distributions of json-c
- Remove error prints for cmd failure in util_cxl_memdev_health_to_json(). The cmd can fail for a number of reasons, we can just skip printing the json in that case.

[1]: https://lore.kernel.org/linux-cxl/[email protected]/T/#m9bb81856e45b7e4bff861ccb19af9ba0952e8d47

---

These patches add a new utility and library to support CXL devices. This comprehends the kernel's sysfs layout for CXL devices, and implements a command submission harness for CXL mailbox commands via ioctl()s defined by the cxl_mem driver.

These patches include:
- libcxl representation of cxl_mem devices
- A command submission harness through libcxl
- A 'cxl-list' command which displays information about a device
- cxl-{read,write,zero}-labels commands for Label Storage Area manipulation

An ndctl branch with these patches is also available at [2]

[2]: https://github.com/pmem/ndctl/tree/cxl-2.0v5

Ira Weiny (1):
ndctl: Add CXL packages to the RPM spec

Vishal Verma (15):
ndctl: add .clang-format
cxl: add a cxl utility and libcxl library
cxl: add a local copy of the cxl_mem UAPI header
util: add the struct_size() helper from the kernel
libcxl: add support for command query and submission
libcxl: add support for the 'Identify Device' command
libcxl: add GET_HEALTH_INFO mailbox command and accessors
libcxl: add support for the 'GET_LSA' command
libcxl: add label_size to cxl_memdev, and an API to retrieve it
libcxl: add representation for an nvdimm bridge object
libcxl: add interfaces for label operations
cxl: add commands to read, write, and zero labels Documentation/cxl: add library API documentation
cxl-cli: add bash completion
cxl: add health information to cxl-list

 Documentation/cxl/cxl-list.txt           |   68 ++
 Documentation/cxl/cxl-read-labels.txt    |   33 +
 Documentation/cxl/cxl-write-labels.txt   |   32 +
 Documentation/cxl/cxl-zero-labels.txt    |   29 +
 Documentation/cxl/cxl.txt                |   34 +
 Documentation/cxl/human-option.txt       |    8 +
 Documentation/cxl/labels-description.txt |    8 +
 Documentation/cxl/labels-options.txt     |   17 +
 Documentation/cxl/lib/cxl_new.txt        |   43 +
 Documentation/cxl/lib/libcxl.txt         |   56 +
 Documentation/cxl/memdev-option.txt      |    4 +
 Documentation/cxl/verbose-option.txt     |    5 +
 configure.ac                             |    4 +
 Makefile.am                              |   14 +-
 Makefile.am.in                           |    5 +
 cxl/lib/private.h                        |  149 +++
 cxl/lib/libcxl.c                         | 1357 ++++++++++++++++++++++
 cxl/builtin.h                            |   13 +
 cxl/cxl_mem.h                            |  189 +++
 cxl/libcxl.h                             |  117 ++
 util/bitmap.h                            |   85 ++
 util/filter.h                            |    2 +
 util/json.h                              |    4 +
 util/main.h                              |    3 +
 util/size.h                              |   62 +
 util/util.h                              |    6 +
 cxl/cxl.c                                |   99 ++
 cxl/list.c                               |  118 ++
 cxl/memdev.c                             |  324 ++++++
 util/filter.c                            |   20 +
 util/json.c                              |  205 ++++
 .clang-format                            |  162 +++
 .gitignore                               |    7 +-
 Documentation/cxl/Makefile.am            |   61 +
 Documentation/cxl/lib/Makefile.am        |   58 +
 contrib/ndctl                            |  109 ++
 cxl/Makefile.am                          |   22 +
 cxl/lib/Makefile.am                      |   32 +
 cxl/lib/libcxl.pc.in                     |   11 +
 cxl/lib/libcxl.sym                       |   75 ++
 ndctl.spec.in                            |   49 +
 41 files changed, 3695 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl-read-labels.txt
 create mode 100644 Documentation/cxl/cxl-write-labels.txt
 create mode 100644 Documentation/cxl/cxl-zero-labels.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/labels-description.txt
 create mode 100644 Documentation/cxl/labels-options.txt
 create mode 100644 Documentation/cxl/lib/cxl_new.txt
 create mode 100644 Documentation/cxl/lib/libcxl.txt
 create mode 100644 Documentation/cxl/memdev-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/cxl_mem.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 cxl/memdev.c
 create mode 100644 .clang-format
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 Documentation/cxl/lib/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym

base-commit: 4e646fa490ba4b782afa188dd8818b94c419924e

Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v5 1/16 ndctl: add .clang-format

Copy the Linux kernel's .clang-format and modify it for ndctl. Only the 'ForEachMacros' section has been modified from the original kernel copy.

---
 .clang-format | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 161 insertions(+)
 create mode 100644 .clang-format
.clang-format new file +161 -0
new file mode 100644
index 0000000..4e00fff
@@ -0,0 +1,161 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# clang-format configuration file. Intended for clang-format >= 4.
+# Copied from Linux's .clang-format
+#
+# For more information, see:
+#
+#   https://clang.llvm.org/docs/ClangFormat.html
+#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+#
+---
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+#AlignEscapedNewlines: Left # Unknown to clang-format-4.0
+AlignOperands: true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: false
+  AfterControlStatement: false
+  AfterEnum: false
+  AfterFunction: true
+  AfterNamespace: true
+  AfterObjCDeclaration: false
+  AfterStruct: false
+  AfterUnion: false
+  #AfterExternBlock: false # Unknown to clang-format-5.0
+  BeforeCatch: false
+  BeforeElse: false
+  IndentBraces: false
+  #SplitEmptyFunction: true # Unknown to clang-format-4.0
+  #SplitEmptyRecord: true # Unknown to clang-format-4.0
+  #SplitEmptyNamespace: true # Unknown to clang-format-4.0
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+#BreakBeforeInheritanceComma: false # Unknown to clang-format-4.0
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+#BreakConstructorInitializers: BeforeComma # Unknown to clang-format-4.0
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+#CompactNamespaces: false # Unknown to clang-format-4.0
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+#FixNamespaceComments: false # Unknown to clang-format-4.0
+
+# Taken from:
+# while read -r sym; do
+# 	printf "  - '%s'\n" "$sym";
+# done < \
+# 	<(cscope -dL6 "foreach|for_each" \
+# 	| awk '{ print $4 $5 }' | grep -E 'foreach|for_each' \
+# 	| sed -e 's/#define//' \
+# 		-e 's/*//' \
+# 		-e 's/://' \
+# 		-e 's/\(.*for_each.*\)(.*/\1/' \
+# 		-e 's/\(.*foreach.*\)(.*/\1/' \
+# 	| sort -u)
+ForEachMacros:
+  - 'daxctl_dev_foreach'
+  - 'daxctl_mapping_foreach'
+  - 'daxctl_region_foreach'
+  - 'kmod_list_foreach'
+  - 'kmod_list_foreach_reverse'
+  - 'list_for_each'
+  - 'list_for_each_off'
+  - 'list_for_each_rev'
+  - 'list_for_each_safe'
+  - 'list_for_each_safe_off'
+  - 'ndctl_btt_foreach'
+  - 'ndctl_btt_foreach_safe'
+  - 'ndctl_bus_foreach'
+  - 'ndctl_dax_foreach'
+  - 'ndctl_dax_foreach_safe'
+  - 'ndctl_dimm_foreach'
+  - 'ndctl_dimm_foreach_in_interleave_set'
+  - 'ndctl_dimm_foreach_in_region'
+  - 'ndctl_interleave_set_foreach'
+  - 'ndctl_mapping_foreach'
+  - 'ndctl_namespace_badblock_foreach'
+  - 'ndctl_namespace_bb_foreach'
+  - 'ndctl_namespace_foreach'
+  - 'ndctl_namespace_foreach_safe'
+  - 'ndctl_pfn_foreach'
+  - 'ndctl_pfn_foreach_safe'
+  - 'ndctl_region_badblock_foreach'
+  - 'ndctl_region_foreach'
+  - 'udev_list_entry_foreach'
+
+#IncludeBlocks: Preserve # Unknown to clang-format-5.0
+IncludeCategories:
+  - Regex: '.*'
+    Priority: 1
+IncludeIsMainRegex: '(Test)?$'
+IndentCaseLabels: false
+#IndentPPDirectives: None # Unknown to clang-format-5.0
+IndentWidth: 8
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+#ObjCBinPackProtocolList: Auto # Unknown to clang-format-5.0
+ObjCBlockIndentWidth: 8
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+
+# Taken from git's rules
+#PenaltyBreakAssignment: 10 # Unknown to clang-format-4.0
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+
+PointerAlignment: Right
+ReflowComments: false
+SortIncludes: false
+#SortUsingDeclarations: false # Unknown to clang-format-4.0
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+#SpaceBeforeCtorInitializerColon: true # Unknown to clang-format-5.0
+#SpaceBeforeInheritanceColon: true # Unknown to clang-format-5.0
+SpaceBeforeParens: ControlStatements
+#SpaceBeforeRangeBasedForLoopColon: true # Unknown to clang-format-5.0
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp03
+TabWidth: 8
+UseTab: Always
+...
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH v5 2/16 cxl: add a cxl utility and libcxl library

In reply to Vishal Verma

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

---
 Documentation/cxl/cxl-list.txt       |  64 +++++
 Documentation/cxl/cxl.txt            |  34 +++
 Documentation/cxl/human-option.txt   |   8 +
 Documentation/cxl/verbose-option.txt |   5 +
 configure.ac                         |   3 +
 Makefile.am                          |   8 +-
 Makefile.am.in                       |   4 +
 cxl/lib/private.h                    |  29 +++
 cxl/lib/libcxl.c                     | 345 +++++++++++++++++++++++++++
 cxl/builtin.h                        |   8 +
 cxl/libcxl.h                         |  55 +++++
 util/filter.h                        |   2 +
 util/json.h                          |   3 +
 util/main.h                          |   3 +
 cxl/cxl.c                            |  96 ++++++++
 cxl/list.c                           | 113 +++++++++
 util/filter.c                        |  20 ++
 util/json.c                          |  26 ++
 .clang-format                        |   1 +
 .gitignore                           |   4 +-
 Documentation/cxl/Makefile.am        |  58 +++++
 cxl/Makefile.am                      |  21 ++
 cxl/lib/Makefile.am                  |  32 +++
 cxl/lib/libcxl.pc.in                 |  11 +
 cxl/lib/libcxl.sym                   |  25 ++
 25 files changed, 974 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym
Documentation/cxl/cxl-list.txt new file +64 -0
new file mode 100644
index 0000000..bd377b3
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-list(1)
+===========
+
+NAME
+----
+cxl-list - List CXL capable memory devices, and their attributes in json.
+
+SYNOPSIS
+--------
+[verse]
+'cxl list' [<options>]
+
+Walk the CXL capable device hierarchy in the system and list all device
+instances along with some of their major attributes.
+
+Options can be specified to limit the output to specific memdevs.
+By default, 'cxl list' with no options is equivalent to:
+[verse]
+cxl list --memdevs
+
+EXAMPLE
+-------
+----
+# cxl list --memdevs
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+OPTIONS
+-------
+-d::
+--memdev=::
+	Specify a cxl memory device name to filter the listing. For example:
+----
+# cxl list --memdev=mem0
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+-D::
+--memdevs::
+	Include all CXL memory devices in the listing
+
+-i::
+--idle::
+	Include idle (not enabled / zero-sized) devices in the listing
+
+include::human-option.txt[]
+
+include::verbose-option.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl-list[1]
Documentation/cxl/cxl.txt new file +34 -0
new file mode 100644
index 0000000..41a51c7
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl(1)
+======
+
+NAME
+----
+cxl - Provides enumeration and provisioning commands for CXL platforms
+
+SYNOPSIS
+--------
+[verse]
+'cxl' [--version] [--help] COMMAND [ARGS]
+
+OPTIONS
+-------
+-v::
+--version::
+  Display the version of the 'cxl' utility.
+
+-h::
+--help::
+  Run the 'cxl help' command.
+
+DESCRIPTION
+-----------
+The cxl utility provides enumeration and provisioning commands for
+the CXL devices managed by the Linux kernel.
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl[1]
Documentation/cxl/human-option.txt new file +8 -0
new file mode 100644
index 0000000..2f4de7a
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-u::
+--human::
+	By default the command will output machine-friendly raw-integer
+	data. Instead, with this flag, numbers representing storage size
+	will be formatted as human readable strings with units, other
+	fields are converted to hexadecimal strings.
Documentation/cxl/verbose-option.txt new file +5 -0
new file mode 100644
index 0000000..cb62c8e
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-v::
+--verbose::
+	Emit more debug messages
configure.ac +3 -0
index dc39dbe..dadae0a 100644
@@ -222,12 +222,15 @@ AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
         daxctl/lib/Makefile
+        cxl/lib/Makefile
         ndctl/lib/Makefile
         ndctl/Makefile
         daxctl/Makefile
+        cxl/Makefile
         test/Makefile
         Documentation/ndctl/Makefile
         Documentation/daxctl/Makefile
+        Documentation/cxl/Makefile
 ])
 
 AC_OUTPUT
Makefile.am +5 -3
index 60a1998..428fd40 100644
@@ -1,9 +1,9 @@
 include Makefile.am.in
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl
+SUBDIRS = . cxl/lib daxctl/lib ndctl/lib cxl ndctl daxctl
 if ENABLE_DOCS
-SUBDIRS += Documentation/ndctl Documentation/daxctl
+SUBDIRS += Documentation/ndctl Documentation/daxctl Documentation/cxl
 endif
 SUBDIRS += test
 
@@ -87,4 +87,6 @@ libutil_a_SOURCES = \
 	util/filter.h \
 	util/bitmap.h
 
-nobase_include_HEADERS = daxctl/libdaxctl.h
+nobase_include_HEADERS = \
+	daxctl/libdaxctl.h \
+	cxl/libcxl.h
Makefile.am.in +4 -0
index bdceda9..aaeee53 100644
@@ -42,3 +42,7 @@ LIBNDCTL_AGE=19
 LIBDAXCTL_CURRENT=6
 LIBDAXCTL_REVISION=0
 LIBDAXCTL_AGE=5
+
+LIBCXL_CURRENT=1
+LIBCXL_REVISION=0
+LIBCXL_AGE=0
cxl/lib/private.h new file +29 -0
new file mode 100644
index 0000000..fc88fa1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/* Copyright (C) 2020-2021, Intel Corporation. All rights reserved. */
+#ifndef _LIBCXL_PRIVATE_H_
+#define _LIBCXL_PRIVATE_H_
+
+#include <libkmod.h>
+
+#define CXL_EXPORT __attribute__ ((visibility("default")))
+
+struct cxl_memdev {
+	int id, major, minor;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+	char *firmware_version;
+	struct cxl_ctx *ctx;
+	struct list_node list;
+	unsigned long long pmem_size;
+	unsigned long long ram_size;
+	int payload_max;
+	struct kmod_module *module;
+};
+
+static inline int check_kmod(struct kmod_ctx *kmod_ctx)
+{
+	return kmod_ctx ? 0 : -ENXIO;
+}
+
+#endif /* _LIBCXL_PRIVATE_H_ */
cxl/lib/libcxl.c new file +345 -0

345 lines not on this page · raw message

cxl/builtin.h new file +8 -0
new file mode 100644
index 0000000..3797f98
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */
+#ifndef _CXL_BUILTIN_H_
+#define _CXL_BUILTIN_H_
+
+struct cxl_ctx;
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx);
+#endif /* _CXL_BUILTIN_H_ */
cxl/libcxl.h new file +55 -0

55 lines not on this page · raw message

util/filter.h +2 -0
index 1e1a41c..9a80d65 100644
@@ -29,6 +29,8 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
 		const char *ident);
 struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 		const char *ident);
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+		const char *ident);
 
 enum ndctl_namespace_mode util_nsmode(const char *mode);
 const char *util_nsmode_name(enum ndctl_namespace_mode mode);
util/json.h +3 -0
index 0f09e36..91918c8 100644
@@ -55,4 +55,7 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm);
 struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags);
 struct json_object *util_region_capabilities_to_json(struct ndctl_region *region);
+struct cxl_memdev;
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags);
 #endif /* __NDCTL_JSON_H__ */
util/main.h +3 -0
index c89a843..80b55c4 100644
@@ -10,16 +10,19 @@
 enum program {
 	PROG_NDCTL,
 	PROG_DAXCTL,
+	PROG_CXL,
 };
 
 struct ndctl_ctx;
 struct daxctl_ctx;
+struct cxl_ctx;
 
 struct cmd_struct {
 	const char *cmd;
 	union {
 		int (*n_fn)(int, const char **, struct ndctl_ctx *ctx);
 		int (*d_fn)(int, const char **, struct daxctl_ctx *ctx);
+		int (*c_fn)(int, const char **, struct cxl_ctx *ctx);
 	};
 };
 
cxl/cxl.c new file +96 -0

96 lines not on this page · raw message

cxl/list.c new file +113 -0

113 lines not on this page · raw message

util/filter.c +20 -0
index 8b4aad3..d81dade 100644
@@ -12,6 +12,7 @@
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident)
 {
@@ -339,6 +340,25 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 	return NULL;
 }
 
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+					  const char *ident)
+{
+	int memdev_id;
+
+	if (!ident || strcmp(ident, "all") == 0)
+		return memdev;
+
+	if (strcmp(ident, cxl_memdev_get_devname(memdev)) == 0)
+		return memdev;
+
+	if ((sscanf(ident, "%d", &memdev_id) == 1
+			|| sscanf(ident, "mem%d", &memdev_id) == 1)
+			&& cxl_memdev_get_id(memdev) == memdev_id)
+		return memdev;
+
+	return NULL;
+}
+
 enum ndctl_namespace_mode util_nsmode(const char *mode)
 {
 	if (!mode)
util/json.c +26 -0
index a8d2412..3be3a92 100644
@@ -9,6 +9,7 @@
 #include <json-c/printbuf.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 #include <ccan/array_size/array_size.h>
 #include <ccan/short_types/short_types.h>
 #include <ndctl.h>
@@ -1440,3 +1441,28 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
 	json_object_put(jerr);
 	return NULL;
 }
+
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags)
+{
+	const char *devname = cxl_memdev_get_devname(memdev);
+	struct json_object *jdev, *jobj;
+
+	jdev = json_object_new_object();
+	if (!devname || !jdev)
+		return NULL;
+
+	jobj = json_object_new_string(devname);
+	if (jobj)
+		json_object_object_add(jdev, "memdev", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_pmem_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "pmem_size", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_ram_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "ram_size", jobj);
+
+	return jdev;
+}
.clang-format +1 -0
index 4e00fff..d2e77d0 100644
@@ -77,6 +77,7 @@ ExperimentalAutoDetectBinPacking: false
 # 		-e 's/\(.*foreach.*\)(.*/\1/' \
 # 	| sort -u)
 ForEachMacros:
+  - 'cxl_memdev_foreach'
   - 'daxctl_dev_foreach'
   - 'daxctl_mapping_foreach'
   - 'daxctl_region_foreach'
.gitignore +3 -1
index 53512b2..6a97b92 100644
@@ -16,9 +16,11 @@ Makefile.in
 *.1
 Documentation/daxctl/asciidoc.conf
 Documentation/ndctl/asciidoc.conf
-Documentation/ndctl/attrs.adoc
+Documentation/cxl/asciidoc.conf
 Documentation/daxctl/asciidoctor-extensions.rb
 Documentation/ndctl/asciidoctor-extensions.rb
+Documentation/cxl/asciidoctor-extensions.rb
+Documentation/ndctl/attrs.adoc
 .dirstamp
 daxctl/config.h
 daxctl/daxctl
Documentation/cxl/Makefile.am new file +58 -0

58 lines not on this page · raw message

cxl/Makefile.am new file +21 -0
new file mode 100644
index 0000000..98606b9
@@ -0,0 +1,21 @@
+include $(top_srcdir)/Makefile.am.in
+
+bin_PROGRAMS = cxl
+
+DISTCLEANFILES = config.h
+BUILT_SOURCES = config.h
+config.h: $(srcdir)/Makefile.am
+	$(AM_V_GEN) echo "/* Autogenerated by cxl/Makefile.am */" >$@
+
+cxl_SOURCES =\
+		cxl.c \
+		list.c \
+		../util/json.c \
+		builtin.h
+
+cxl_LDADD =\
+	lib/libcxl.la \
+	../libutil.a \
+	$(UUID_LIBS) \
+	$(KMOD_LIBS) \
+	$(JSON_LIBS)
cxl/lib/Makefile.am new file +32 -0
new file mode 100644
index 0000000..277f0cd
@@ -0,0 +1,32 @@
+include $(top_srcdir)/Makefile.am.in
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libcxl.h
+lib_LTLIBRARIES = libcxl.la
+
+libcxl_la_SOURCES =\
+	../libcxl.h \
+	private.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	../../util/log.c \
+	../../util/log.h \
+	libcxl.c
+
+libcxl_la_LIBADD =\
+	$(UUID_LIBS) \
+	$(KMOD_LIBS)
+
+EXTRA_DIST += libcxl.sym
+
+libcxl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBCXL_CURRENT):$(LIBCXL_REVISION):$(LIBCXL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/cxl/lib/libcxl.sym
+libcxl_la_DEPENDENCIES = libcxl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcxl.pc
+EXTRA_DIST += libcxl.pc.in
+CLEANFILES += libcxl.pc
cxl/lib/libcxl.pc.in new file +11 -0
new file mode 100644
index 0000000..949fcdc
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libcxl
+Description: Manage CXL devices
+Version: @VERSION@
+Libs: -L${libdir} -lcxl
+Libs.private:
+Cflags: -I${includedir}
cxl/lib/libcxl.sym new file +25 -0
new file mode 100644
index 0000000..2616e5c
@@ -0,0 +1,25 @@
+LIBCXL_1 {
+global:
+	cxl_get_userdata;
+	cxl_set_userdata;
+	cxl_get_private_data;
+	cxl_set_private_data;
+	cxl_ref;
+	cxl_get_log_priority;
+	cxl_set_log_fn;
+	cxl_unref;
+	cxl_set_log_priority;
+	cxl_new;
+	cxl_memdev_get_first;
+	cxl_memdev_get_next;
+	cxl_memdev_get_id;
+	cxl_memdev_get_devname;
+	cxl_memdev_get_major;
+	cxl_memdev_get_minor;
+	cxl_memdev_get_ctx;
+	cxl_memdev_get_pmem_size;
+	cxl_memdev_get_ram_size;
+	cxl_memdev_get_firmware_verison;
+local:
+        *;
+};
Signature · 1 line
2.31.1
author maintainer
#3 lore raw

PATCH v6 2/16 cxl: add a cxl utility and libcxl library

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

---

Changes in v6:
- Use -m/-M as the short options for listing memdevs (Dan)

 Documentation/cxl/cxl-list.txt       |  64 +++++
 Documentation/cxl/cxl.txt            |  34 +++
 Documentation/cxl/human-option.txt   |   8 +
 Documentation/cxl/verbose-option.txt |   5 +
 configure.ac                         |   3 +
 Makefile.am                          |   8 +-
 Makefile.am.in                       |   4 +
 cxl/lib/private.h                    |  29 +++
 cxl/lib/libcxl.c                     | 345 +++++++++++++++++++++++++++
 cxl/builtin.h                        |   8 +
 cxl/libcxl.h                         |  55 +++++
 util/filter.h                        |   2 +
 util/json.h                          |   3 +
 util/main.h                          |   3 +
 cxl/cxl.c                            |  96 ++++++++
 cxl/list.c                           | 113 +++++++++
 util/filter.c                        |  20 ++
 util/json.c                          |  26 ++
 .clang-format                        |   1 +
 .gitignore                           |   4 +-
 Documentation/cxl/Makefile.am        |  58 +++++
 cxl/Makefile.am                      |  21 ++
 cxl/lib/Makefile.am                  |  32 +++
 cxl/lib/libcxl.pc.in                 |  11 +
 cxl/lib/libcxl.sym                   |  25 ++
 25 files changed, 974 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym
Documentation/cxl/cxl-list.txt new file +64 -0
new file mode 100644
index 0000000..e761cfa
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-list(1)
+===========
+
+NAME
+----
+cxl-list - List CXL capable memory devices, and their attributes in json.
+
+SYNOPSIS
+--------
+[verse]
+'cxl list' [<options>]
+
+Walk the CXL capable device hierarchy in the system and list all device
+instances along with some of their major attributes.
+
+Options can be specified to limit the output to specific memdevs.
+By default, 'cxl list' with no options is equivalent to:
+[verse]
+cxl list --memdevs
+
+EXAMPLE
+-------
+----
+# cxl list --memdevs
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+OPTIONS
+-------
+-m::
+--memdev=::
+	Specify a cxl memory device name to filter the listing. For example:
+----
+# cxl list --memdev=mem0
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+-M::
+--memdevs::
+	Include all CXL memory devices in the listing
+
+-i::
+--idle::
+	Include idle (not enabled / zero-sized) devices in the listing
+
+include::human-option.txt[]
+
+include::verbose-option.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl-list[1]
Documentation/cxl/cxl.txt new file +34 -0
new file mode 100644
index 0000000..41a51c7
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl(1)
+======
+
+NAME
+----
+cxl - Provides enumeration and provisioning commands for CXL platforms
+
+SYNOPSIS
+--------
+[verse]
+'cxl' [--version] [--help] COMMAND [ARGS]
+
+OPTIONS
+-------
+-v::
+--version::
+  Display the version of the 'cxl' utility.
+
+-h::
+--help::
+  Run the 'cxl help' command.
+
+DESCRIPTION
+-----------
+The cxl utility provides enumeration and provisioning commands for
+the CXL devices managed by the Linux kernel.
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl[1]
Documentation/cxl/human-option.txt new file +8 -0
new file mode 100644
index 0000000..2f4de7a
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-u::
+--human::
+	By default the command will output machine-friendly raw-integer
+	data. Instead, with this flag, numbers representing storage size
+	will be formatted as human readable strings with units, other
+	fields are converted to hexadecimal strings.
Documentation/cxl/verbose-option.txt new file +5 -0
new file mode 100644
index 0000000..cb62c8e
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-v::
+--verbose::
+	Emit more debug messages
configure.ac +3 -0
index dc39dbe..dadae0a 100644
@@ -222,12 +222,15 @@ AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
         daxctl/lib/Makefile
+        cxl/lib/Makefile
         ndctl/lib/Makefile
         ndctl/Makefile
         daxctl/Makefile
+        cxl/Makefile
         test/Makefile
         Documentation/ndctl/Makefile
         Documentation/daxctl/Makefile
+        Documentation/cxl/Makefile
 ])
 
 AC_OUTPUT
Makefile.am +5 -3
index 60a1998..428fd40 100644
@@ -1,9 +1,9 @@
 include Makefile.am.in
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl
+SUBDIRS = . cxl/lib daxctl/lib ndctl/lib cxl ndctl daxctl
 if ENABLE_DOCS
-SUBDIRS += Documentation/ndctl Documentation/daxctl
+SUBDIRS += Documentation/ndctl Documentation/daxctl Documentation/cxl
 endif
 SUBDIRS += test
 
@@ -87,4 +87,6 @@ libutil_a_SOURCES = \
 	util/filter.h \
 	util/bitmap.h
 
-nobase_include_HEADERS = daxctl/libdaxctl.h
+nobase_include_HEADERS = \
+	daxctl/libdaxctl.h \
+	cxl/libcxl.h
Makefile.am.in +4 -0
index bdceda9..aaeee53 100644
@@ -42,3 +42,7 @@ LIBNDCTL_AGE=19
 LIBDAXCTL_CURRENT=6
 LIBDAXCTL_REVISION=0
 LIBDAXCTL_AGE=5
+
+LIBCXL_CURRENT=1
+LIBCXL_REVISION=0
+LIBCXL_AGE=0
cxl/lib/private.h new file +29 -0
new file mode 100644
index 0000000..fc88fa1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/* Copyright (C) 2020-2021, Intel Corporation. All rights reserved. */
+#ifndef _LIBCXL_PRIVATE_H_
+#define _LIBCXL_PRIVATE_H_
+
+#include <libkmod.h>
+
+#define CXL_EXPORT __attribute__ ((visibility("default")))
+
+struct cxl_memdev {
+	int id, major, minor;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+	char *firmware_version;
+	struct cxl_ctx *ctx;
+	struct list_node list;
+	unsigned long long pmem_size;
+	unsigned long long ram_size;
+	int payload_max;
+	struct kmod_module *module;
+};
+
+static inline int check_kmod(struct kmod_ctx *kmod_ctx)
+{
+	return kmod_ctx ? 0 : -ENXIO;
+}
+
+#endif /* _LIBCXL_PRIVATE_H_ */
cxl/lib/libcxl.c new file +345 -0

345 lines not on this page · raw message

cxl/builtin.h new file +8 -0
new file mode 100644
index 0000000..3797f98
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */
+#ifndef _CXL_BUILTIN_H_
+#define _CXL_BUILTIN_H_
+
+struct cxl_ctx;
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx);
+#endif /* _CXL_BUILTIN_H_ */
cxl/libcxl.h new file +55 -0

55 lines not on this page · raw message

util/filter.h +2 -0
index 1e1a41c..9a80d65 100644
@@ -29,6 +29,8 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
 		const char *ident);
 struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 		const char *ident);
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+		const char *ident);
 
 enum ndctl_namespace_mode util_nsmode(const char *mode);
 const char *util_nsmode_name(enum ndctl_namespace_mode mode);
util/json.h +3 -0
index 0f09e36..91918c8 100644
@@ -55,4 +55,7 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm);
 struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags);
 struct json_object *util_region_capabilities_to_json(struct ndctl_region *region);
+struct cxl_memdev;
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags);
 #endif /* __NDCTL_JSON_H__ */
util/main.h +3 -0
index c89a843..80b55c4 100644
@@ -10,16 +10,19 @@
 enum program {
 	PROG_NDCTL,
 	PROG_DAXCTL,
+	PROG_CXL,
 };
 
 struct ndctl_ctx;
 struct daxctl_ctx;
+struct cxl_ctx;
 
 struct cmd_struct {
 	const char *cmd;
 	union {
 		int (*n_fn)(int, const char **, struct ndctl_ctx *ctx);
 		int (*d_fn)(int, const char **, struct daxctl_ctx *ctx);
+		int (*c_fn)(int, const char **, struct cxl_ctx *ctx);
 	};
 };
 
cxl/cxl.c new file +96 -0

96 lines not on this page · raw message

cxl/list.c new file +113 -0

113 lines not on this page · raw message

util/filter.c +20 -0
index 8b4aad3..d81dade 100644
@@ -12,6 +12,7 @@
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident)
 {
@@ -339,6 +340,25 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 	return NULL;
 }
 
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+					  const char *ident)
+{
+	int memdev_id;
+
+	if (!ident || strcmp(ident, "all") == 0)
+		return memdev;
+
+	if (strcmp(ident, cxl_memdev_get_devname(memdev)) == 0)
+		return memdev;
+
+	if ((sscanf(ident, "%d", &memdev_id) == 1
+			|| sscanf(ident, "mem%d", &memdev_id) == 1)
+			&& cxl_memdev_get_id(memdev) == memdev_id)
+		return memdev;
+
+	return NULL;
+}
+
 enum ndctl_namespace_mode util_nsmode(const char *mode)
 {
 	if (!mode)
util/json.c +26 -0
index a8d2412..3be3a92 100644
@@ -9,6 +9,7 @@
 #include <json-c/printbuf.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 #include <ccan/array_size/array_size.h>
 #include <ccan/short_types/short_types.h>
 #include <ndctl.h>
@@ -1440,3 +1441,28 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
 	json_object_put(jerr);
 	return NULL;
 }
+
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags)
+{
+	const char *devname = cxl_memdev_get_devname(memdev);
+	struct json_object *jdev, *jobj;
+
+	jdev = json_object_new_object();
+	if (!devname || !jdev)
+		return NULL;
+
+	jobj = json_object_new_string(devname);
+	if (jobj)
+		json_object_object_add(jdev, "memdev", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_pmem_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "pmem_size", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_ram_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "ram_size", jobj);
+
+	return jdev;
+}
.clang-format +1 -0
index 4e00fff..d2e77d0 100644
@@ -77,6 +77,7 @@ ExperimentalAutoDetectBinPacking: false
 # 		-e 's/\(.*foreach.*\)(.*/\1/' \
 # 	| sort -u)
 ForEachMacros:
+  - 'cxl_memdev_foreach'
   - 'daxctl_dev_foreach'
   - 'daxctl_mapping_foreach'
   - 'daxctl_region_foreach'
.gitignore +3 -1
index 53512b2..6a97b92 100644
@@ -16,9 +16,11 @@ Makefile.in
 *.1
 Documentation/daxctl/asciidoc.conf
 Documentation/ndctl/asciidoc.conf
-Documentation/ndctl/attrs.adoc
+Documentation/cxl/asciidoc.conf
 Documentation/daxctl/asciidoctor-extensions.rb
 Documentation/ndctl/asciidoctor-extensions.rb
+Documentation/cxl/asciidoctor-extensions.rb
+Documentation/ndctl/attrs.adoc
 .dirstamp
 daxctl/config.h
 daxctl/daxctl
Documentation/cxl/Makefile.am new file +58 -0

58 lines not on this page · raw message

cxl/Makefile.am new file +21 -0
new file mode 100644
index 0000000..98606b9
@@ -0,0 +1,21 @@
+include $(top_srcdir)/Makefile.am.in
+
+bin_PROGRAMS = cxl
+
+DISTCLEANFILES = config.h
+BUILT_SOURCES = config.h
+config.h: $(srcdir)/Makefile.am
+	$(AM_V_GEN) echo "/* Autogenerated by cxl/Makefile.am */" >$@
+
+cxl_SOURCES =\
+		cxl.c \
+		list.c \
+		../util/json.c \
+		builtin.h
+
+cxl_LDADD =\
+	lib/libcxl.la \
+	../libutil.a \
+	$(UUID_LIBS) \
+	$(KMOD_LIBS) \
+	$(JSON_LIBS)
cxl/lib/Makefile.am new file +32 -0
new file mode 100644
index 0000000..277f0cd
@@ -0,0 +1,32 @@
+include $(top_srcdir)/Makefile.am.in
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libcxl.h
+lib_LTLIBRARIES = libcxl.la
+
+libcxl_la_SOURCES =\
+	../libcxl.h \
+	private.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	../../util/log.c \
+	../../util/log.h \
+	libcxl.c
+
+libcxl_la_LIBADD =\
+	$(UUID_LIBS) \
+	$(KMOD_LIBS)
+
+EXTRA_DIST += libcxl.sym
+
+libcxl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBCXL_CURRENT):$(LIBCXL_REVISION):$(LIBCXL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/cxl/lib/libcxl.sym
+libcxl_la_DEPENDENCIES = libcxl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcxl.pc
+EXTRA_DIST += libcxl.pc.in
+CLEANFILES += libcxl.pc
cxl/lib/libcxl.pc.in new file +11 -0
new file mode 100644
index 0000000..949fcdc
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libcxl
+Description: Manage CXL devices
+Version: @VERSION@
+Libs: -L${libdir} -lcxl
+Libs.private:
+Cflags: -I${includedir}
cxl/lib/libcxl.sym new file +25 -0
new file mode 100644
index 0000000..2616e5c
@@ -0,0 +1,25 @@
+LIBCXL_1 {
+global:
+	cxl_get_userdata;
+	cxl_set_userdata;
+	cxl_get_private_data;
+	cxl_set_private_data;
+	cxl_ref;
+	cxl_get_log_priority;
+	cxl_set_log_fn;
+	cxl_unref;
+	cxl_set_log_priority;
+	cxl_new;
+	cxl_memdev_get_first;
+	cxl_memdev_get_next;
+	cxl_memdev_get_id;
+	cxl_memdev_get_devname;
+	cxl_memdev_get_major;
+	cxl_memdev_get_minor;
+	cxl_memdev_get_ctx;
+	cxl_memdev_get_pmem_size;
+	cxl_memdev_get_ram_size;
+	cxl_memdev_get_firmware_verison;
+local:
+        *;
+};
Signature · 1 line
2.31.1
#4 lore raw

Re: [ndctl PATCH v5 02/16] cxl: add a cxl utility and libcxl library

In reply to Vishal Verma
Quoted 17 lines · Vishal Verma

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

[..]

Quoted 20 lines
cxl/list.c new file +20 -0
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+       const struct option options[] = {
+               OPT_STRING('d', "memdev", &param.memdev, "memory device name",
+                          "filter by CXL memory device name"),
+               OPT_BOOLEAN('D', "memdevs", &list.memdevs,
+                           "include CXL memory device info"),
+               OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
+               OPT_BOOLEAN('u', "human", &list.human,
+                               "use human friendly number formats "),
+               OPT_END(),
+       };
+       const char * const u[] = {
+               "cxl list [<options>]",
+               NULL
+       };
+       struct json_object *jdevs = NULL;
+       unsigned long list_flags;
+       struct cxl_memdev *memdev;
+       int i;

cxl/list.c line 79

Quoted 10 lines
cxl/list.c new file +10 -0
+
+       argc = parse_options(argc, argv, options, u, 0);
+       for (i = 0; i < argc; i++)
+               error("unknown parameter \"%s\"\n", argv[i]);
+
+       if (argc)
+               usage_with_options(u, options);
+
+       if (num_list_flags() == 0)
+               list.memdevs = true;

It strikes me that we may regret this default. In the interest of giving us flexibility to pick a new default later (i.e. to not grow any maintenance dependencies on this default), let's fail for now if no list options are specified. I expect "cxl list" to enumerate the active and most relevant end user devices by default. For ndctl its namespaces, but for cxl-cli I expect it should be regions by default to show all the CXL address ranges. Likely it should be "--regions --namespaces" by default since regions are the primary user relevant devices for volatile memory and namespaces are the end user relevant devices for persistent memory, but the "--regions" vs "--regions --namespaces" decision can be made later.

author maintainer
#5 lore raw

PATCH v6 1/1 cxl: add a cxl utility and libcxl library

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

---

Changes in v6:
- Remove the cxl-list default of listing memdevs as we may want to list regions by default, once that support is available. For now just error out if memdevs are not explicitly asked for. (Dan)

 Documentation/cxl/cxl-list.txt       |  64 +++++
 Documentation/cxl/cxl.txt            |  34 +++
 Documentation/cxl/human-option.txt   |   8 +
 Documentation/cxl/verbose-option.txt |   5 +
 configure.ac                         |   3 +
 Makefile.am                          |   8 +-
 Makefile.am.in                       |   4 +
 cxl/lib/private.h                    |  29 +++
 cxl/lib/libcxl.c                     | 345 +++++++++++++++++++++++++++
 cxl/builtin.h                        |   8 +
 cxl/libcxl.h                         |  55 +++++
 util/filter.h                        |   2 +
 util/json.h                          |   3 +
 util/main.h                          |   3 +
 cxl/cxl.c                            |  96 ++++++++
 cxl/list.c                           | 121 ++++++++++
 util/filter.c                        |  20 ++
 util/json.c                          |  26 ++
 .clang-format                        |   1 +
 .gitignore                           |   4 +-
 Documentation/cxl/Makefile.am        |  58 +++++
 cxl/Makefile.am                      |  21 ++
 cxl/lib/Makefile.am                  |  32 +++
 cxl/lib/libcxl.pc.in                 |  11 +
 cxl/lib/libcxl.sym                   |  25 ++
 25 files changed, 982 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym
Documentation/cxl/cxl-list.txt new file +64 -0
new file mode 100644
index 0000000..e761cfa
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-list(1)
+===========
+
+NAME
+----
+cxl-list - List CXL capable memory devices, and their attributes in json.
+
+SYNOPSIS
+--------
+[verse]
+'cxl list' [<options>]
+
+Walk the CXL capable device hierarchy in the system and list all device
+instances along with some of their major attributes.
+
+Options can be specified to limit the output to specific memdevs.
+By default, 'cxl list' with no options is equivalent to:
+[verse]
+cxl list --memdevs
+
+EXAMPLE
+-------
+----
+# cxl list --memdevs
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+OPTIONS
+-------
+-m::
+--memdev=::
+	Specify a cxl memory device name to filter the listing. For example:
+----
+# cxl list --memdev=mem0
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+-M::
+--memdevs::
+	Include all CXL memory devices in the listing
+
+-i::
+--idle::
+	Include idle (not enabled / zero-sized) devices in the listing
+
+include::human-option.txt[]
+
+include::verbose-option.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl-list[1]
Documentation/cxl/cxl.txt new file +34 -0
new file mode 100644
index 0000000..41a51c7
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl(1)
+======
+
+NAME
+----
+cxl - Provides enumeration and provisioning commands for CXL platforms
+
+SYNOPSIS
+--------
+[verse]
+'cxl' [--version] [--help] COMMAND [ARGS]
+
+OPTIONS
+-------
+-v::
+--version::
+  Display the version of the 'cxl' utility.
+
+-h::
+--help::
+  Run the 'cxl help' command.
+
+DESCRIPTION
+-----------
+The cxl utility provides enumeration and provisioning commands for
+the CXL devices managed by the Linux kernel.
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl[1]
Documentation/cxl/human-option.txt new file +8 -0
new file mode 100644
index 0000000..2f4de7a
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-u::
+--human::
+	By default the command will output machine-friendly raw-integer
+	data. Instead, with this flag, numbers representing storage size
+	will be formatted as human readable strings with units, other
+	fields are converted to hexadecimal strings.
Documentation/cxl/verbose-option.txt new file +5 -0
new file mode 100644
index 0000000..cb62c8e
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-v::
+--verbose::
+	Emit more debug messages
configure.ac +3 -0
index dc39dbe..dadae0a 100644
@@ -222,12 +222,15 @@ AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
         daxctl/lib/Makefile
+        cxl/lib/Makefile
         ndctl/lib/Makefile
         ndctl/Makefile
         daxctl/Makefile
+        cxl/Makefile
         test/Makefile
         Documentation/ndctl/Makefile
         Documentation/daxctl/Makefile
+        Documentation/cxl/Makefile
 ])
 
 AC_OUTPUT
Makefile.am +5 -3
index 60a1998..428fd40 100644
@@ -1,9 +1,9 @@
 include Makefile.am.in
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl
+SUBDIRS = . cxl/lib daxctl/lib ndctl/lib cxl ndctl daxctl
 if ENABLE_DOCS
-SUBDIRS += Documentation/ndctl Documentation/daxctl
+SUBDIRS += Documentation/ndctl Documentation/daxctl Documentation/cxl
 endif
 SUBDIRS += test
 
@@ -87,4 +87,6 @@ libutil_a_SOURCES = \
 	util/filter.h \
 	util/bitmap.h
 
-nobase_include_HEADERS = daxctl/libdaxctl.h
+nobase_include_HEADERS = \
+	daxctl/libdaxctl.h \
+	cxl/libcxl.h
Makefile.am.in +4 -0
index bdceda9..aaeee53 100644
@@ -42,3 +42,7 @@ LIBNDCTL_AGE=19
 LIBDAXCTL_CURRENT=6
 LIBDAXCTL_REVISION=0
 LIBDAXCTL_AGE=5
+
+LIBCXL_CURRENT=1
+LIBCXL_REVISION=0
+LIBCXL_AGE=0
cxl/lib/private.h new file +29 -0
new file mode 100644
index 0000000..fc88fa1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/* Copyright (C) 2020-2021, Intel Corporation. All rights reserved. */
+#ifndef _LIBCXL_PRIVATE_H_
+#define _LIBCXL_PRIVATE_H_
+
+#include <libkmod.h>
+
+#define CXL_EXPORT __attribute__ ((visibility("default")))
+
+struct cxl_memdev {
+	int id, major, minor;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+	char *firmware_version;
+	struct cxl_ctx *ctx;
+	struct list_node list;
+	unsigned long long pmem_size;
+	unsigned long long ram_size;
+	int payload_max;
+	struct kmod_module *module;
+};
+
+static inline int check_kmod(struct kmod_ctx *kmod_ctx)
+{
+	return kmod_ctx ? 0 : -ENXIO;
+}
+
+#endif /* _LIBCXL_PRIVATE_H_ */
cxl/lib/libcxl.c new file +345 -0

345 lines not on this page · raw message

cxl/builtin.h new file +8 -0
new file mode 100644
index 0000000..3797f98
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */
+#ifndef _CXL_BUILTIN_H_
+#define _CXL_BUILTIN_H_
+
+struct cxl_ctx;
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx);
+#endif /* _CXL_BUILTIN_H_ */
cxl/libcxl.h new file +55 -0

55 lines not on this page · raw message

util/filter.h +2 -0
index 1e1a41c..9a80d65 100644
@@ -29,6 +29,8 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
 		const char *ident);
 struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 		const char *ident);
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+		const char *ident);
 
 enum ndctl_namespace_mode util_nsmode(const char *mode);
 const char *util_nsmode_name(enum ndctl_namespace_mode mode);
util/json.h +3 -0
index 0f09e36..91918c8 100644
@@ -55,4 +55,7 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm);
 struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags);
 struct json_object *util_region_capabilities_to_json(struct ndctl_region *region);
+struct cxl_memdev;
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags);
 #endif /* __NDCTL_JSON_H__ */
util/main.h +3 -0
index c89a843..80b55c4 100644
@@ -10,16 +10,19 @@
 enum program {
 	PROG_NDCTL,
 	PROG_DAXCTL,
+	PROG_CXL,
 };
 
 struct ndctl_ctx;
 struct daxctl_ctx;
+struct cxl_ctx;
 
 struct cmd_struct {
 	const char *cmd;
 	union {
 		int (*n_fn)(int, const char **, struct ndctl_ctx *ctx);
 		int (*d_fn)(int, const char **, struct daxctl_ctx *ctx);
+		int (*c_fn)(int, const char **, struct cxl_ctx *ctx);
 	};
 };
 
cxl/cxl.c new file +96 -0

96 lines not on this page · raw message

cxl/list.c new file +121 -0

121 lines not on this page · raw message

util/filter.c +20 -0
index 8b4aad3..d81dade 100644
@@ -12,6 +12,7 @@
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident)
 {
@@ -339,6 +340,25 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 	return NULL;
 }
 
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+					  const char *ident)
+{
+	int memdev_id;
+
+	if (!ident || strcmp(ident, "all") == 0)
+		return memdev;
+
+	if (strcmp(ident, cxl_memdev_get_devname(memdev)) == 0)
+		return memdev;
+
+	if ((sscanf(ident, "%d", &memdev_id) == 1
+			|| sscanf(ident, "mem%d", &memdev_id) == 1)
+			&& cxl_memdev_get_id(memdev) == memdev_id)
+		return memdev;
+
+	return NULL;
+}
+
 enum ndctl_namespace_mode util_nsmode(const char *mode)
 {
 	if (!mode)
util/json.c +26 -0
index a8d2412..3be3a92 100644
@@ -9,6 +9,7 @@
 #include <json-c/printbuf.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 #include <ccan/array_size/array_size.h>
 #include <ccan/short_types/short_types.h>
 #include <ndctl.h>
@@ -1440,3 +1441,28 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
 	json_object_put(jerr);
 	return NULL;
 }
+
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags)
+{
+	const char *devname = cxl_memdev_get_devname(memdev);
+	struct json_object *jdev, *jobj;
+
+	jdev = json_object_new_object();
+	if (!devname || !jdev)
+		return NULL;
+
+	jobj = json_object_new_string(devname);
+	if (jobj)
+		json_object_object_add(jdev, "memdev", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_pmem_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "pmem_size", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_ram_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "ram_size", jobj);
+
+	return jdev;
+}
.clang-format +1 -0
index 4e00fff..d2e77d0 100644
@@ -77,6 +77,7 @@ ExperimentalAutoDetectBinPacking: false
 # 		-e 's/\(.*foreach.*\)(.*/\1/' \
 # 	| sort -u)
 ForEachMacros:
+  - 'cxl_memdev_foreach'
   - 'daxctl_dev_foreach'
   - 'daxctl_mapping_foreach'
   - 'daxctl_region_foreach'
.gitignore +3 -1
index 53512b2..6a97b92 100644
@@ -16,9 +16,11 @@ Makefile.in
 *.1
 Documentation/daxctl/asciidoc.conf
 Documentation/ndctl/asciidoc.conf
-Documentation/ndctl/attrs.adoc
+Documentation/cxl/asciidoc.conf
 Documentation/daxctl/asciidoctor-extensions.rb
 Documentation/ndctl/asciidoctor-extensions.rb
+Documentation/cxl/asciidoctor-extensions.rb
+Documentation/ndctl/attrs.adoc
 .dirstamp
 daxctl/config.h
 daxctl/daxctl
Documentation/cxl/Makefile.am new file +58 -0

58 lines not on this page · raw message

cxl/Makefile.am new file +21 -0
new file mode 100644
index 0000000..98606b9
@@ -0,0 +1,21 @@
+include $(top_srcdir)/Makefile.am.in
+
+bin_PROGRAMS = cxl
+
+DISTCLEANFILES = config.h
+BUILT_SOURCES = config.h
+config.h: $(srcdir)/Makefile.am
+	$(AM_V_GEN) echo "/* Autogenerated by cxl/Makefile.am */" >$@
+
+cxl_SOURCES =\
+		cxl.c \
+		list.c \
+		../util/json.c \
+		builtin.h
+
+cxl_LDADD =\
+	lib/libcxl.la \
+	../libutil.a \
+	$(UUID_LIBS) \
+	$(KMOD_LIBS) \
+	$(JSON_LIBS)
cxl/lib/Makefile.am new file +32 -0
new file mode 100644
index 0000000..277f0cd
@@ -0,0 +1,32 @@
+include $(top_srcdir)/Makefile.am.in
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libcxl.h
+lib_LTLIBRARIES = libcxl.la
+
+libcxl_la_SOURCES =\
+	../libcxl.h \
+	private.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	../../util/log.c \
+	../../util/log.h \
+	libcxl.c
+
+libcxl_la_LIBADD =\
+	$(UUID_LIBS) \
+	$(KMOD_LIBS)
+
+EXTRA_DIST += libcxl.sym
+
+libcxl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBCXL_CURRENT):$(LIBCXL_REVISION):$(LIBCXL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/cxl/lib/libcxl.sym
+libcxl_la_DEPENDENCIES = libcxl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcxl.pc
+EXTRA_DIST += libcxl.pc.in
+CLEANFILES += libcxl.pc
cxl/lib/libcxl.pc.in new file +11 -0
new file mode 100644
index 0000000..949fcdc
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libcxl
+Description: Manage CXL devices
+Version: @VERSION@
+Libs: -L${libdir} -lcxl
+Libs.private:
+Cflags: -I${includedir}
cxl/lib/libcxl.sym new file +25 -0
new file mode 100644
index 0000000..2616e5c
@@ -0,0 +1,25 @@
+LIBCXL_1 {
+global:
+	cxl_get_userdata;
+	cxl_set_userdata;
+	cxl_get_private_data;
+	cxl_set_private_data;
+	cxl_ref;
+	cxl_get_log_priority;
+	cxl_set_log_fn;
+	cxl_unref;
+	cxl_set_log_priority;
+	cxl_new;
+	cxl_memdev_get_first;
+	cxl_memdev_get_next;
+	cxl_memdev_get_id;
+	cxl_memdev_get_devname;
+	cxl_memdev_get_major;
+	cxl_memdev_get_minor;
+	cxl_memdev_get_ctx;
+	cxl_memdev_get_pmem_size;
+	cxl_memdev_get_ram_size;
+	cxl_memdev_get_firmware_verison;
+local:
+        *;
+};
Signature · 1 line
2.33.1
#6 lore raw

Re: [ndctl PATCH v6] cxl: add a cxl utility and libcxl library

Quoted 83 lines · Vishal Verma

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

---

Changes in v6:
- Remove the cxl-list default of listing memdevs as we may want to list regions by default, once that support is available. For now just error out if memdevs are not explicitly asked for. (Dan)

 Documentation/cxl/cxl-list.txt       |  64 +++++
 Documentation/cxl/cxl.txt            |  34 +++
 Documentation/cxl/human-option.txt   |   8 +
 Documentation/cxl/verbose-option.txt |   5 +
 configure.ac                         |   3 +
 Makefile.am                          |   8 +-
 Makefile.am.in                       |   4 +
 cxl/lib/private.h                    |  29 +++
 cxl/lib/libcxl.c                     | 345 +++++++++++++++++++++++++++
 cxl/builtin.h                        |   8 +
 cxl/libcxl.h                         |  55 +++++
 util/filter.h                        |   2 +
 util/json.h                          |   3 +
 util/main.h                          |   3 +
 cxl/cxl.c                            |  96 ++++++++
 cxl/list.c                           | 121 ++++++++++
 util/filter.c                        |  20 ++
 util/json.c                          |  26 ++
 .clang-format                        |   1 +
 .gitignore                           |   4 +-
 Documentation/cxl/Makefile.am        |  58 +++++
 cxl/Makefile.am                      |  21 ++
 cxl/lib/Makefile.am                  |  32 +++
 cxl/lib/libcxl.pc.in                 |  11 +
 cxl/lib/libcxl.sym                   |  25 ++
 25 files changed, 982 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym
Documentation/cxl/cxl-list.txt new file +11 -0
new file mode 100644
index 0000000..e761cfa
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-list(1)
+===========
+
+NAME
+----
+cxl-list - List CXL capable memory devices, and their attributes in json.
+
+SYNOPSIS
+--------

Documentation/cxl/cxl-list.txt line 21

Quoted 10 lines
Documentation/cxl/cxl-list.txt new file +10 -0
+[verse]
+'cxl list' [<options>]
+
+Walk the CXL capable device hierarchy in the system and list all device
+instances along with some of their major attributes.
+
+Options can be specified to limit the output to specific memdevs.
+By default, 'cxl list' with no options is equivalent to:
+[verse]
+cxl list --memdevs

With the default change these last 4 lines can be trimmed.

Quoted 19 lines
Documentation/cxl/cxl-list.txt new file +19 -0
+
+EXAMPLE
+-------
+----
+# cxl list --memdevs
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+OPTIONS
+-------
+-m::
+--memdev=::
+       Specify a cxl memory device name to filter the listing. For example:
+----
+# cxl list --memdev=mem0

Documentation/cxl/cxl-list.txt line 50

Quoted 10 lines
Documentation/cxl/cxl-list.txt new file +10 -0
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+-M::
+--memdevs::
+       Include all CXL memory devices in the listing

The -m is a filter so I think this can be: s/all//

Quoted 14 lines
Documentation/cxl/cxl-list.txt new file +14 -0
+
+-i::
+--idle::
+       Include idle (not enabled / zero-sized) devices in the listing
+
+include::human-option.txt[]
+
+include::verbose-option.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl-list[1]

[..]

Quoted 81 lines
cxl/list.c new file +75 -0
new file mode 100644
index 0000000..69201d9
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <util/json.h>
+#include <util/filter.h>
+#include <json-c/json.h>
+#include <cxl/libcxl.h>
+#include <util/parse-options.h>
+#include <ccan/array_size/array_size.h>
+
+static struct {
+       bool memdevs;
+       bool idle;
+       bool human;
+} list;
+
+static unsigned long listopts_to_flags(void)
+{
+       unsigned long flags = 0;
+
+       if (list.idle)
+               flags |= UTIL_JSON_IDLE;
+       if (list.human)
+               flags |= UTIL_JSON_HUMAN;
+       return flags;
+}
+
+static struct {
+       const char *memdev;
+} param;
+
+static int did_fail;
+
+#define fail(fmt, ...) \
+do { \
+       did_fail = 1; \
+       fprintf(stderr, "cxl-%s:%s:%d: " fmt, \
+                       VERSION, __func__, __LINE__, ##__VA_ARGS__); \
+} while (0)
+
+static int num_list_flags(void)
+{
+       return list.memdevs;
+}
+
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
+{
+       const struct option options[] = {
+               OPT_STRING('m', "memdev", &param.memdev, "memory device name",
+                          "filter by CXL memory device name"),
+               OPT_BOOLEAN('M', "memdevs", &list.memdevs,
+                           "include CXL memory device info"),
+               OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
+               OPT_BOOLEAN('u', "human", &list.human,
+                               "use human friendly number formats "),
+               OPT_END(),
+       };
+       const char * const u[] = {
+               "cxl list [<options>]",
+               NULL
+       };
+       struct json_object *jdevs = NULL;
+       unsigned long list_flags;
+       struct cxl_memdev *memdev;
+       int i;
+
+       argc = parse_options(argc, argv, options, u, 0);
+       for (i = 0; i < argc; i++)
+               error("unknown parameter \"%s\"\n", argv[i]);
+
+       if (argc)

cxl/list.c line 85

Quoted 10 lines
cxl/list.c new file +10 -0
+               usage_with_options(u, options);
+
+       if (num_list_flags() == 0) {
+               /*
+                * TODO: We likely want to list regions by default if nothing
+                * was explicitly asked for. But until we have region support,
+                * print this error asking for devices explicitly.
+                * Once region support is added, this TODO can be removed.
+                */
+               fprintf(stderr,

Should this be error() instead like the "unknown parameter" print above?

cxl/list.c line 86

Quoted 1 line
cxl/list.c new file +1 -0
+                       "please specify entities to list, e.g. using -m/-M\n");

Add a usage_with_options() call here to abort?

author maintainer
#7 lore raw

PATCH v7 1/1 cxl: add a cxl utility and libcxl library

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

---

Changes in v7:
- Update the man page w.r.t the new default behavior (Dan)
- Use error() and usage_with_options() to fail when no list entities are specified (Dan)

 Documentation/cxl/cxl-list.txt       |  59 +++++
 Documentation/cxl/cxl.txt            |  34 +++
 Documentation/cxl/human-option.txt   |   8 +
 Documentation/cxl/verbose-option.txt |   5 +
 configure.ac                         |   3 +
 Makefile.am                          |   8 +-
 Makefile.am.in                       |   4 +
 cxl/lib/private.h                    |  29 +++
 cxl/lib/libcxl.c                     | 345 +++++++++++++++++++++++++++
 cxl/builtin.h                        |   8 +
 cxl/libcxl.h                         |  55 +++++
 util/filter.h                        |   2 +
 util/json.h                          |   3 +
 util/main.h                          |   3 +
 cxl/cxl.c                            |  96 ++++++++
 cxl/list.c                           | 121 ++++++++++
 util/filter.c                        |  20 ++
 util/json.c                          |  26 ++
 .clang-format                        |   1 +
 .gitignore                           |   4 +-
 Documentation/cxl/Makefile.am        |  58 +++++
 cxl/Makefile.am                      |  21 ++
 cxl/lib/Makefile.am                  |  32 +++
 cxl/lib/libcxl.pc.in                 |  11 +
 cxl/lib/libcxl.sym                   |  25 ++
 25 files changed, 977 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/cxl/cxl-list.txt
 create mode 100644 Documentation/cxl/cxl.txt
 create mode 100644 Documentation/cxl/human-option.txt
 create mode 100644 Documentation/cxl/verbose-option.txt
 create mode 100644 cxl/lib/private.h
 create mode 100644 cxl/lib/libcxl.c
 create mode 100644 cxl/builtin.h
 create mode 100644 cxl/libcxl.h
 create mode 100644 cxl/cxl.c
 create mode 100644 cxl/list.c
 create mode 100644 Documentation/cxl/Makefile.am
 create mode 100644 cxl/Makefile.am
 create mode 100644 cxl/lib/Makefile.am
 create mode 100644 cxl/lib/libcxl.pc.in
 create mode 100644 cxl/lib/libcxl.sym
Documentation/cxl/cxl-list.txt new file +59 -0
new file mode 100644
index 0000000..370d5b8
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-list(1)
+===========
+
+NAME
+----
+cxl-list - List CXL capable memory devices, and their attributes in json.
+
+SYNOPSIS
+--------
+[verse]
+'cxl list' [<options>]
+
+Walk the CXL capable device hierarchy in the system and list all device
+instances along with some of their major attributes.
+
+EXAMPLE
+-------
+----
+# cxl list --memdevs
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+OPTIONS
+-------
+-m::
+--memdev=::
+	Specify a cxl memory device name to filter the listing. For example:
+----
+# cxl list --memdev=mem0
+{
+  "memdev":"mem0",
+  "pmem_size":268435456,
+  "ram_size":0,
+}
+----
+
+-M::
+--memdevs::
+	Include CXL memory devices in the listing
+
+-i::
+--idle::
+	Include idle (not enabled / zero-sized) devices in the listing
+
+include::human-option.txt[]
+
+include::verbose-option.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl-list[1]
Documentation/cxl/cxl.txt new file +34 -0
new file mode 100644
index 0000000..41a51c7
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl(1)
+======
+
+NAME
+----
+cxl - Provides enumeration and provisioning commands for CXL platforms
+
+SYNOPSIS
+--------
+[verse]
+'cxl' [--version] [--help] COMMAND [ARGS]
+
+OPTIONS
+-------
+-v::
+--version::
+  Display the version of the 'cxl' utility.
+
+-h::
+--help::
+  Run the 'cxl help' command.
+
+DESCRIPTION
+-----------
+The cxl utility provides enumeration and provisioning commands for
+the CXL devices managed by the Linux kernel.
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:ndctl[1]
Documentation/cxl/human-option.txt new file +8 -0
new file mode 100644
index 0000000..2f4de7a
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-u::
+--human::
+	By default the command will output machine-friendly raw-integer
+	data. Instead, with this flag, numbers representing storage size
+	will be formatted as human readable strings with units, other
+	fields are converted to hexadecimal strings.
Documentation/cxl/verbose-option.txt new file +5 -0
new file mode 100644
index 0000000..cb62c8e
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+
+-v::
+--verbose::
+	Emit more debug messages
configure.ac +3 -0
index dc39dbe..dadae0a 100644
@@ -222,12 +222,15 @@ AC_CONFIG_HEADERS(config.h)
 AC_CONFIG_FILES([
         Makefile
         daxctl/lib/Makefile
+        cxl/lib/Makefile
         ndctl/lib/Makefile
         ndctl/Makefile
         daxctl/Makefile
+        cxl/Makefile
         test/Makefile
         Documentation/ndctl/Makefile
         Documentation/daxctl/Makefile
+        Documentation/cxl/Makefile
 ])
 
 AC_OUTPUT
Makefile.am +5 -3
index 60a1998..428fd40 100644
@@ -1,9 +1,9 @@
 include Makefile.am.in
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl
+SUBDIRS = . cxl/lib daxctl/lib ndctl/lib cxl ndctl daxctl
 if ENABLE_DOCS
-SUBDIRS += Documentation/ndctl Documentation/daxctl
+SUBDIRS += Documentation/ndctl Documentation/daxctl Documentation/cxl
 endif
 SUBDIRS += test
 
@@ -87,4 +87,6 @@ libutil_a_SOURCES = \
 	util/filter.h \
 	util/bitmap.h
 
-nobase_include_HEADERS = daxctl/libdaxctl.h
+nobase_include_HEADERS = \
+	daxctl/libdaxctl.h \
+	cxl/libcxl.h
Makefile.am.in +4 -0
index bdceda9..aaeee53 100644
@@ -42,3 +42,7 @@ LIBNDCTL_AGE=19
 LIBDAXCTL_CURRENT=6
 LIBDAXCTL_REVISION=0
 LIBDAXCTL_AGE=5
+
+LIBCXL_CURRENT=1
+LIBCXL_REVISION=0
+LIBCXL_AGE=0
cxl/lib/private.h new file +29 -0
new file mode 100644
index 0000000..fc88fa1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+/* Copyright (C) 2020-2021, Intel Corporation. All rights reserved. */
+#ifndef _LIBCXL_PRIVATE_H_
+#define _LIBCXL_PRIVATE_H_
+
+#include <libkmod.h>
+
+#define CXL_EXPORT __attribute__ ((visibility("default")))
+
+struct cxl_memdev {
+	int id, major, minor;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+	char *firmware_version;
+	struct cxl_ctx *ctx;
+	struct list_node list;
+	unsigned long long pmem_size;
+	unsigned long long ram_size;
+	int payload_max;
+	struct kmod_module *module;
+};
+
+static inline int check_kmod(struct kmod_ctx *kmod_ctx)
+{
+	return kmod_ctx ? 0 : -ENXIO;
+}
+
+#endif /* _LIBCXL_PRIVATE_H_ */
cxl/lib/libcxl.c new file +345 -0

345 lines not on this page · raw message

cxl/builtin.h new file +8 -0
new file mode 100644
index 0000000..3797f98
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2020-2021 Intel Corporation. All rights reserved. */
+#ifndef _CXL_BUILTIN_H_
+#define _CXL_BUILTIN_H_
+
+struct cxl_ctx;
+int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx);
+#endif /* _CXL_BUILTIN_H_ */
cxl/libcxl.h new file +55 -0

55 lines not on this page · raw message

util/filter.h +2 -0
index 1e1a41c..9a80d65 100644
@@ -29,6 +29,8 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,
 		const char *ident);
 struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 		const char *ident);
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+		const char *ident);
 
 enum ndctl_namespace_mode util_nsmode(const char *mode);
 const char *util_nsmode_name(enum ndctl_namespace_mode mode);
util/json.h +3 -0
index 0f09e36..91918c8 100644
@@ -55,4 +55,7 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm);
 struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags);
 struct json_object *util_region_capabilities_to_json(struct ndctl_region *region);
+struct cxl_memdev;
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags);
 #endif /* __NDCTL_JSON_H__ */
util/main.h +3 -0
index c89a843..80b55c4 100644
@@ -10,16 +10,19 @@
 enum program {
 	PROG_NDCTL,
 	PROG_DAXCTL,
+	PROG_CXL,
 };
 
 struct ndctl_ctx;
 struct daxctl_ctx;
+struct cxl_ctx;
 
 struct cmd_struct {
 	const char *cmd;
 	union {
 		int (*n_fn)(int, const char **, struct ndctl_ctx *ctx);
 		int (*d_fn)(int, const char **, struct daxctl_ctx *ctx);
+		int (*c_fn)(int, const char **, struct cxl_ctx *ctx);
 	};
 };
 
cxl/cxl.c new file +96 -0

96 lines not on this page · raw message

cxl/list.c new file +121 -0

121 lines not on this page · raw message

util/filter.c +20 -0
index 8b4aad3..d81dade 100644
@@ -12,6 +12,7 @@
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 
 struct ndctl_bus *util_bus_filter(struct ndctl_bus *bus, const char *__ident)
 {
@@ -339,6 +340,25 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region,
 	return NULL;
 }
 
+struct cxl_memdev *util_cxl_memdev_filter(struct cxl_memdev *memdev,
+					  const char *ident)
+{
+	int memdev_id;
+
+	if (!ident || strcmp(ident, "all") == 0)
+		return memdev;
+
+	if (strcmp(ident, cxl_memdev_get_devname(memdev)) == 0)
+		return memdev;
+
+	if ((sscanf(ident, "%d", &memdev_id) == 1
+			|| sscanf(ident, "mem%d", &memdev_id) == 1)
+			&& cxl_memdev_get_id(memdev) == memdev_id)
+		return memdev;
+
+	return NULL;
+}
+
 enum ndctl_namespace_mode util_nsmode(const char *mode)
 {
 	if (!mode)
util/json.c +26 -0
index a8d2412..3be3a92 100644
@@ -9,6 +9,7 @@
 #include <json-c/printbuf.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
+#include <cxl/libcxl.h>
 #include <ccan/array_size/array_size.h>
 #include <ccan/short_types/short_types.h>
 #include <ndctl.h>
@@ -1440,3 +1441,28 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
 	json_object_put(jerr);
 	return NULL;
 }
+
+struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
+		unsigned long flags)
+{
+	const char *devname = cxl_memdev_get_devname(memdev);
+	struct json_object *jdev, *jobj;
+
+	jdev = json_object_new_object();
+	if (!devname || !jdev)
+		return NULL;
+
+	jobj = json_object_new_string(devname);
+	if (jobj)
+		json_object_object_add(jdev, "memdev", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_pmem_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "pmem_size", jobj);
+
+	jobj = util_json_object_size(cxl_memdev_get_ram_size(memdev), flags);
+	if (jobj)
+		json_object_object_add(jdev, "ram_size", jobj);
+
+	return jdev;
+}
.clang-format +1 -0
index 4e00fff..d2e77d0 100644
@@ -77,6 +77,7 @@ ExperimentalAutoDetectBinPacking: false
 # 		-e 's/\(.*foreach.*\)(.*/\1/' \
 # 	| sort -u)
 ForEachMacros:
+  - 'cxl_memdev_foreach'
   - 'daxctl_dev_foreach'
   - 'daxctl_mapping_foreach'
   - 'daxctl_region_foreach'
.gitignore +3 -1
index 53512b2..6a97b92 100644
@@ -16,9 +16,11 @@ Makefile.in
 *.1
 Documentation/daxctl/asciidoc.conf
 Documentation/ndctl/asciidoc.conf
-Documentation/ndctl/attrs.adoc
+Documentation/cxl/asciidoc.conf
 Documentation/daxctl/asciidoctor-extensions.rb
 Documentation/ndctl/asciidoctor-extensions.rb
+Documentation/cxl/asciidoctor-extensions.rb
+Documentation/ndctl/attrs.adoc
 .dirstamp
 daxctl/config.h
 daxctl/daxctl
Documentation/cxl/Makefile.am new file +58 -0

58 lines not on this page · raw message

cxl/Makefile.am new file +21 -0
new file mode 100644
index 0000000..98606b9
@@ -0,0 +1,21 @@
+include $(top_srcdir)/Makefile.am.in
+
+bin_PROGRAMS = cxl
+
+DISTCLEANFILES = config.h
+BUILT_SOURCES = config.h
+config.h: $(srcdir)/Makefile.am
+	$(AM_V_GEN) echo "/* Autogenerated by cxl/Makefile.am */" >$@
+
+cxl_SOURCES =\
+		cxl.c \
+		list.c \
+		../util/json.c \
+		builtin.h
+
+cxl_LDADD =\
+	lib/libcxl.la \
+	../libutil.a \
+	$(UUID_LIBS) \
+	$(KMOD_LIBS) \
+	$(JSON_LIBS)
cxl/lib/Makefile.am new file +32 -0
new file mode 100644
index 0000000..277f0cd
@@ -0,0 +1,32 @@
+include $(top_srcdir)/Makefile.am.in
+
+%.pc: %.pc.in Makefile
+	$(SED_PROCESS)
+
+pkginclude_HEADERS = ../libcxl.h
+lib_LTLIBRARIES = libcxl.la
+
+libcxl_la_SOURCES =\
+	../libcxl.h \
+	private.h \
+	../../util/sysfs.c \
+	../../util/sysfs.h \
+	../../util/log.c \
+	../../util/log.h \
+	libcxl.c
+
+libcxl_la_LIBADD =\
+	$(UUID_LIBS) \
+	$(KMOD_LIBS)
+
+EXTRA_DIST += libcxl.sym
+
+libcxl_la_LDFLAGS = $(AM_LDFLAGS) \
+	-version-info $(LIBCXL_CURRENT):$(LIBCXL_REVISION):$(LIBCXL_AGE) \
+	-Wl,--version-script=$(top_srcdir)/cxl/lib/libcxl.sym
+libcxl_la_DEPENDENCIES = libcxl.sym
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libcxl.pc
+EXTRA_DIST += libcxl.pc.in
+CLEANFILES += libcxl.pc
cxl/lib/libcxl.pc.in new file +11 -0
new file mode 100644
index 0000000..949fcdc
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libcxl
+Description: Manage CXL devices
+Version: @VERSION@
+Libs: -L${libdir} -lcxl
+Libs.private:
+Cflags: -I${includedir}
cxl/lib/libcxl.sym new file +25 -0
new file mode 100644
index 0000000..2616e5c
@@ -0,0 +1,25 @@
+LIBCXL_1 {
+global:
+	cxl_get_userdata;
+	cxl_set_userdata;
+	cxl_get_private_data;
+	cxl_set_private_data;
+	cxl_ref;
+	cxl_get_log_priority;
+	cxl_set_log_fn;
+	cxl_unref;
+	cxl_set_log_priority;
+	cxl_new;
+	cxl_memdev_get_first;
+	cxl_memdev_get_next;
+	cxl_memdev_get_id;
+	cxl_memdev_get_devname;
+	cxl_memdev_get_major;
+	cxl_memdev_get_minor;
+	cxl_memdev_get_ctx;
+	cxl_memdev_get_pmem_size;
+	cxl_memdev_get_ram_size;
+	cxl_memdev_get_firmware_verison;
+local:
+        *;
+};
Signature · 1 line
2.33.1
#8 lore raw

Re: [ndctl PATCH v7] cxl: add a cxl utility and libcxl library

Quoted 17 lines · Vishal Verma

CXL - or Compute eXpress Link - is a new interconnect that extends PCIe to support a wide range of devices, including cache coherent memory expanders. As such, these devices can be new sources of 'persistent memory', and the 'ndctl' umbrella of tools and libraries needs to be able to interact with them.

Add a new utility and library for managing these CXL memory devices. This is an initial bring-up for interacting with CXL devices, and only includes adding the utility and library infrastructure, parsing device information from sysfs for CXL devices, and providing a 'cxl-list' command to display this information in JSON formatted output.

Quoted 6 lines

---

Changes in v7:
- Update the man page w.r.t the new default behavior (Dan)
- Use error() and usage_with_options() to fail when no list entities are specified (Dan)

Looks good.

author maintainer
#9 lore raw

PATCH v5 3/16 cxl: add a local copy of the cxl_mem UAPI header

In reply to Vishal Verma

While CXL functionality is under development, it is useful to have a local copy of the UAPI header for cxl_mem definitions. This allows building cxl and libcxl on systems where the appropriate kernel headers are not installed in the usual locations.

---
 Makefile.am         |   3 +-
 Makefile.am.in      |   1 +
 cxl/cxl_mem.h       | 189 ++++++++++++++++++++++++++++++++++++++++++++
 cxl/lib/Makefile.am |   2 +-
 4 files changed, 193 insertions(+), 2 deletions(-)
 create mode 100644 cxl/cxl_mem.h
Makefile.am +2 -1
index 428fd40..4904ee7 100644
@@ -89,4 +89,5 @@ libutil_a_SOURCES = \
 
 nobase_include_HEADERS = \
 	daxctl/libdaxctl.h \
-	cxl/libcxl.h
+	cxl/libcxl.h \
+	cxl/cxl_mem.h
Makefile.am.in +1 -0
index aaeee53..a748128 100644
@@ -11,6 +11,7 @@ AM_CPPFLAGS = \
 	-DNDCTL_MAN_PATH=\""$(mandir)"\" \
 	-I${top_srcdir}/ndctl/lib \
 	-I${top_srcdir}/ndctl \
+	-I${top_srcdir}/cxl \
 	-I${top_srcdir}/ \
 	$(KMOD_CFLAGS) \
 	$(UDEV_CFLAGS) \
cxl/cxl_mem.h new file +189 -0

189 lines not on this page · raw message

cxl/lib/Makefile.am +1 -1
index 277f0cd..72c9ccd 100644
@@ -3,7 +3,7 @@ include $(top_srcdir)/Makefile.am.in
 %.pc: %.pc.in Makefile
 	$(SED_PROCESS)
 
-pkginclude_HEADERS = ../libcxl.h
+pkginclude_HEADERS = ../libcxl.h ../cxl_mem.h
 lib_LTLIBRARIES = libcxl.la
 
 libcxl_la_SOURCES =\
Signature · 1 line
2.31.1
author maintainer
#10 lore raw

PATCH v5 4/16 util: add the struct_size() helper from the kernel

In reply to Vishal Verma

Add struct_size() from include/linux/overflow.h which calculates the size of a struct with a trailing variable length array.

---
 util/size.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 util/util.h |  6 ++++++
 2 files changed, 68 insertions(+)
util/size.h +62 -0
index 646edae..a0f3593 100644
@@ -4,6 +4,8 @@
 #ifndef _NDCTL_SIZE_H_
 #define _NDCTL_SIZE_H_
 #include <stdbool.h>
+#include <stdint.h>
+#include <util/util.h>
 
 #define SZ_1K     0x00000400
 #define SZ_4K     0x00001000
@@ -30,4 +32,64 @@ static inline bool is_power_of_2(unsigned long long v)
 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
 #define HPAGE_SIZE (2 << 20)
 
+/*
+ * Helpers for struct_size() copied from include/linux/overflow.h (GPL-2.0)
+ *
+ * For simplicity and code hygiene, the fallback code below insists on
+ * a, b and *d having the same type (similar to the min() and max()
+ * macros), whereas gcc's type-generic overflow checkers accept
+ * different types. Hence we don't just make check_add_overflow an
+ * alias for __builtin_add_overflow, but add type checks similar to
+ * below.
+ */
+#define check_add_overflow(a, b, d) (({	\
+	typeof(a) __a = (a);			\
+	typeof(b) __b = (b);			\
+	typeof(d) __d = (d);			\
+	(void) (&__a == &__b);			\
+	(void) (&__a == __d);			\
+	__builtin_add_overflow(__a, __b, __d);	\
+}))
+
+#define check_mul_overflow(a, b, d) (({	\
+	typeof(a) __a = (a);			\
+	typeof(b) __b = (b);			\
+	typeof(d) __d = (d);			\
+	(void) (&__a == &__b);			\
+	(void) (&__a == __d);			\
+	__builtin_mul_overflow(__a, __b, __d);	\
+}))
+
+/*
+ * Compute a*b+c, returning SIZE_MAX on overflow. Internal helper for
+ * struct_size() below.
+ */
+static inline size_t __ab_c_size(size_t a, size_t b, size_t c)
+{
+	size_t bytes;
+
+	if (check_mul_overflow(a, b, &bytes))
+		return SIZE_MAX;
+	if (check_add_overflow(bytes, c, &bytes))
+		return SIZE_MAX;
+
+	return bytes;
+}
+
+/**
+ * struct_size() - Calculate size of structure with trailing array.
+ * @p: Pointer to the structure.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array.
+ *
+ * Calculates size of memory needed for structure @p followed by an
+ * array of @count number of @member elements.
+ *
+ * Return: number of bytes needed or SIZE_MAX on overflow.
+ */
+#define struct_size(p, member, count)					\
+	__ab_c_size(count,						\
+		    sizeof(*(p)->member) + __must_be_array((p)->member),\
+		    sizeof(*(p)))
+
 #endif /* _NDCTL_SIZE_H_ */
util/util.h +6 -0
index ae0e4e1..b2b4ae6 100644
@@ -63,6 +63,12 @@
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
 
+/* Are two types/vars the same type (ignoring qualifiers)? */
+#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
+
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
+
 enum {
 	READ, WRITE,
 };
Signature · 1 line
2.31.1
#11 lore raw

Re: [ndctl PATCH v5 04/16] util: add the struct_size() helper from the kernel

Hey Vishal,

Quoted 2 lines · Vishal Verma

Add struct_size() from include/linux/overflow.h which calculates the size of a struct with a trailing variable length array.

[...]

Quoted 18 lines
util/size.h +18 -0
+/*
+ * Helpers for struct_size() copied from include/linux/overflow.h (GPL-2.0)
+ *
+ * For simplicity and code hygiene, the fallback code below insists on
+ * a, b and *d having the same type (similar to the min() and max()
+ * macros), whereas gcc's type-generic overflow checkers accept
+ * different types. Hence we don't just make check_add_overflow an
+ * alias for __builtin_add_overflow, but add type checks similar to
+ * below.
+ */
+#define check_add_overflow(a, b, d) (({	\
+	typeof(a) __a = (a);			\
+	typeof(b) __b = (b);			\
+	typeof(d) __d = (d);			\
+	(void) (&__a == &__b);			\
+	(void) (&__a == __d);			\
+	__builtin_add_overflow(__a, __b, __d);	\
+}))

util/size.h static inline bool is_power_of_2(unsigned long long v) · line 62

Quoted 10 lines
util/size.h +10 -0
+
+#define check_mul_overflow(a, b, d) (({	\
+	typeof(a) __a = (a);			\
+	typeof(b) __b = (b);			\
+	typeof(d) __d = (d);			\
+	(void) (&__a == &__b);			\
+	(void) (&__a == __d);			\
+	__builtin_mul_overflow(__a, __b, __d);	\
+}))
+

The introduction of this two macro helpers broke compilation against < gcc 5.1.0 (think CentOS/OL/RHEL 7 or anything resembling that) and clang 3.4. Particularly because of the lack of these overflow builtins __builtin_mul_overflow() / __buitin_add_overflow() giving errors like:

BUILDSTDERR: lib/.libs/libcxl.so: undefined reference to `__builtin_mul_overflow'
BUILDSTDERR: lib/.libs/libcxl.so: undefined reference to `__builtin_add_overflow'

Since you pulled this helper from the kernel, you might wanna pull the compat code too that was there in commit f0907827a8a9 ("compiler.h: enable builtin overflow checkers and add fallback code"), particularly something like below.

#if GCC_VERSION >= 50100
#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
#endif

#if __clang__ && \
    __has_builtin(__builtin_mul_overflow) && \
    __has_builtin(__builtin_add_overflow)

#define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
#endif

#if COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW

#define check_add_overflow(a, b, d) (({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	__builtin_add_overflow(__a, __b, __d);	\
}))
#define check_mul_overflow(a, b, d) (({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	__builtin_mul_overflow(__a, __b, __d);	\
}))

#else /* !COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW */

/* Checking for unsigned overflow is relatively easy without causing UB. */

#define __unsigned_add_overflow(a, b, d) ({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	*__d = __a + __b;			\
	*__d < __a;				\
})
#define __unsigned_sub_overflow(a, b, d) ({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	*__d = __a - __b;			\
	__a < __b;				\
})
/*
 * If one of a or b is a compile-time constant, this avoids a division.
 */
#define __unsigned_mul_overflow(a, b, d) ({		\
	typeof(a) __a = (a);				\
	typeof(b) __b = (b);				\
	typeof(d) __d = (d);				\
	(void) (&__a == &__b);				\
	(void) (&__a == __d);				\
	*__d = __a * __b;				\
	__builtin_constant_p(__b) ?			\
	  __b > 0 && __a > type_max(typeof(__a)) / __b : \
	  __a > 0 && __b > type_max(typeof(__b)) / __a;	 \
})

/*
* For signed types, detecting overflow is much harder, especially if
* we want to avoid UB. But the interface of these macros is such that
* we must provide a result in *d, and in fact we must produce the
* result promised by gcc's builtins, which is simply the possibly
* wrapped-around value. Fortunately, we can just formally do the
* operations in the widest relevant unsigned type (u64) and then
* truncate the result - gcc is smart enough to generate the same code
* with and without the (u64) casts.
*/

/*
* Adding two signed integers can overflow only if they have the same
* sign, and overflow has happened iff the result has the opposite
* sign.
*/

#define __signed_add_overflow(a, b, d) ({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	*__d = (u64)__a + (u64)__b;		\
	(((~(__a ^ __b)) & (*__d ^ __a))	\
		& type_min(typeof(__a))) != 0;	\
})

/*
* Subtraction is similar, except that overflow can now happen only
* when the signs are opposite. In this case, overflow has happened if
* the result has the opposite sign of a.
*/

#define __signed_sub_overflow(a, b, d) ({	\
	typeof(a) __a = (a);			\
	typeof(b) __b = (b);			\
	typeof(d) __d = (d);			\
	(void) (&__a == &__b);			\
	(void) (&__a == __d);			\
	*__d = (u64)__a - (u64)__b;		\
	((((__a ^ __b)) & (*__d ^ __a))		\
		& type_min(typeof(__a))) != 0;	\
})

/*
* Signed multiplication is rather hard. gcc always follows C99, so
* division is truncated towards 0. This means that we can write the
* overflow check like this:
*

 * (a > 0 && (b > MAX/a || b < MIN/a)) ||
 * (a < -1 && (b > MIN/a || b < MAX/a) ||

* (a == -1 && b == MIN)
*
* The redundant casts of -1 are to silence an annoying -Wtype-limits
* (included in -Wextra) warning: When the type is u8 or u16, the
* __b_c_e in check_mul_overflow obviously selects
* __unsigned_mul_overflow, but unfortunately gcc still parses this
* code and warns about the limited range of __b.
*/

#define __signed_mul_overflow(a, b, d) ({				\
	typeof(a) __a = (a);						\
	typeof(b) __b = (b);						\
	typeof(d) __d = (d);						\
	typeof(a) __tmax = type_max(typeof(a));				\
	typeof(a) __tmin = type_min(typeof(a));				\
	(void) (&__a == &__b);						\
	(void) (&__a == __d);						\
	*__d = (u64)__a * (u64)__b;					\
	(__b > 0   && (__a > __tmax/__b || __a < __tmin/__b)) ||	\
	(__b < (typeof(__b))-1  && (__a > __tmin/__b || __a < __tmax/__b)) || \
	(__b == (typeof(__b))-1 && __a == __tmin);			\
})
#define check_add_overflow(a, b, d)					\
	__builtin_choose_expr(is_signed_type(typeof(a)),		\
			__signed_add_overflow(a, b, d),			\
			__unsigned_add_overflow(a, b, d))
#define check_sub_overflow(a, b, d)					\
	__builtin_choose_expr(is_signed_type(typeof(a)),		\
			__signed_sub_overflow(a, b, d),			\
			__unsigned_sub_overflow(a, b, d))
#define check_mul_overflow(a, b, d)					\
	__builtin_choose_expr(is_signed_type(typeof(a)),		\
			__signed_mul_overflow(a, b, d),			\
			__unsigned_mul_overflow(a, b, d))

#endif

author maintainer
#12 lore raw

PATCH v5 5/16 libcxl: add support for command query and submission

In reply to Vishal Verma

Add a set of APIs around 'cxl_cmd' for querying the kernel for supported commands, allocating and validating command structures against the supported set, and submitting the commands.

'Query Commands' and 'Send Command' are implemented as IOCTLs in the kernel. 'Query Commands' returns information about each supported command, such as flags governing its use, or input and output payload sizes. This information is used to validate command support, as well as set up input and output buffers for command submission.

---
 cxl/lib/private.h  |  33 ++++
 cxl/lib/libcxl.c   | 390 +++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  11 ++
 cxl/lib/libcxl.sym |   9 ++
 4 files changed, 443 insertions(+)
cxl/lib/private.h +33 -0
index fc88fa1..87ca17e 100644
@@ -4,6 +4,9 @@
 #define _LIBCXL_PRIVATE_H_
 
 #include <libkmod.h>
+#include <cxl/cxl_mem.h>
+#include <ccan/endian/endian.h>
+#include <ccan/short_types/short_types.h>
 
 #define CXL_EXPORT __attribute__ ((visibility("default")))
 
@@ -21,6 +24,36 @@ struct cxl_memdev {
 	struct kmod_module *module;
 };
 
+enum cxl_cmd_query_status {
+	CXL_CMD_QUERY_NOT_RUN = 0,
+	CXL_CMD_QUERY_OK,
+	CXL_CMD_QUERY_UNSUPPORTED,
+};
+
+/**
+ * struct cxl_cmd - CXL memdev command
+ * @memdev: the memory device to which the command is being sent
+ * @query_cmd: structure for the Linux 'Query commands' ioctl
+ * @send_cmd: structure for the Linux 'Send command' ioctl
+ * @input_payload: buffer for input payload managed by libcxl
+ * @output_payload: buffer for output payload managed by libcxl
+ * @refcount: reference for passing command buffer around
+ * @query_status: status from query_commands
+ * @query_idx: index of 'this' command in the query_commands array
+ * @status: command return status from the device
+ */
+struct cxl_cmd {
+	struct cxl_memdev *memdev;
+	struct cxl_mem_query_commands *query_cmd;
+	struct cxl_send_command *send_cmd;
+	void *input_payload;
+	void *output_payload;
+	int refcount;
+	int query_status;
+	int query_idx;
+	int status;
+};
+
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
 {
 	return kmod_ctx ? 0 : -ENXIO;
cxl/lib/libcxl.c +390 -0

407 lines not on this page · raw message

cxl/libcxl.h +11 -0
index fd06790..6e87b80 100644
@@ -48,6 +48,17 @@ const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
              memdev != NULL; \
              memdev = cxl_memdev_get_next(memdev))
 
+struct cxl_cmd;
+const char *cxl_cmd_get_devname(struct cxl_cmd *cmd);
+struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
+int cxl_cmd_set_input_payload(struct cxl_cmd *cmd, void *in, int size);
+int cxl_cmd_set_output_payload(struct cxl_cmd *cmd, void *out, int size);
+void cxl_cmd_ref(struct cxl_cmd *cmd);
+void cxl_cmd_unref(struct cxl_cmd *cmd);
+int cxl_cmd_submit(struct cxl_cmd *cmd);
+int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd);
+int cxl_cmd_get_out_size(struct cxl_cmd *cmd);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
cxl/lib/libcxl.sym +9 -0
index 2616e5c..3900f90 100644
@@ -20,6 +20,15 @@ global:
 	cxl_memdev_get_pmem_size;
 	cxl_memdev_get_ram_size;
 	cxl_memdev_get_firmware_verison;
+	cxl_cmd_get_devname;
+	cxl_cmd_new_raw;
+	cxl_cmd_set_input_payload;
+	cxl_cmd_set_output_payload;
+	cxl_cmd_ref;
+	cxl_cmd_unref;
+	cxl_cmd_submit;
+	cxl_cmd_get_mbox_status;
+	cxl_cmd_get_out_size;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#13 lore raw

PATCH v5 6/16 libcxl: add support for the 'Identify Device' command

In reply to Vishal Verma

Add APIs to allocate and send an 'Identify Device' command, and accessors to retrieve some of the fields from the resulting data.

Only add a handful accessor functions; more can be added as the need arises. The fields added are fw_revision, partition_align, and lsa_size.

---
 cxl/lib/private.h  | 19 +++++++++++++++++
 cxl/lib/libcxl.c   | 52 ++++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  4 ++++
 cxl/lib/libcxl.sym |  4 ++++
 4 files changed, 79 insertions(+)
cxl/lib/private.h +19 -0
index 87ca17e..3273f21 100644
@@ -54,6 +54,25 @@ struct cxl_cmd {
 	int status;
 };
 
+#define CXL_CMD_IDENTIFY_FW_REV_LENGTH 0x10
+
+struct cxl_cmd_identify {
+	char fw_revision[CXL_CMD_IDENTIFY_FW_REV_LENGTH];
+	le64 total_capacity;
+	le64 volatile_capacity;
+	le64 persistent_capacity;
+	le64 partition_align;
+	le16 info_event_log_size;
+	le16 warning_event_log_size;
+	le16 failure_event_log_size;
+	le16 fatal_event_log_size;
+	le32 lsa_size;
+	u8 poison_list_max_mer[3];
+	le16 inject_poison_limit;
+	u8 poison_caps;
+	u8 qos_telemetry_caps;
+} __attribute__((packed));
+
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
 {
 	return kmod_ctx ? 0 : -ENXIO;
cxl/lib/libcxl.c +52 -0

65 lines not on this page · raw message

cxl/libcxl.h +4 -0
index 6e87b80..0f2d5e9 100644
@@ -58,6 +58,10 @@ void cxl_cmd_unref(struct cxl_cmd *cmd);
 int cxl_cmd_submit(struct cxl_cmd *cmd);
 int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd);
 int cxl_cmd_get_out_size(struct cxl_cmd *cmd);
+struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
+int cxl_cmd_identify_get_fw_rev(struct cxl_cmd *cmd, char *fw_rev, int fw_len);
+unsigned long long cxl_cmd_identify_get_partition_align(struct cxl_cmd *cmd);
+unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd);
 
 #ifdef __cplusplus
 } /* extern "C" */
cxl/lib/libcxl.sym +4 -0
index 3900f90..1dc45f4 100644
@@ -29,6 +29,10 @@ global:
 	cxl_cmd_submit;
 	cxl_cmd_get_mbox_status;
 	cxl_cmd_get_out_size;
+	cxl_cmd_new_identify;
+	cxl_cmd_identify_get_fw_rev;
+	cxl_cmd_identify_get_partition_align;
+	cxl_cmd_identify_get_label_size;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#14 lore raw

PATCH v5 7/16 libcxl: add GET_HEALTH_INFO mailbox command and accessors

In reply to Vishal Verma

Add libcxl APIs to create a new GET_HEALTH_INFO mailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the health info output.

Cc Ben Widawsky <[email protected]>
Cc Dan Williams <[email protected]>
---
 cxl/lib/private.h  |  47 ++++++++
 cxl/lib/libcxl.c   | 291 +++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  33 +++++
 util/bitmap.h      |  85 +++++++++++++
 cxl/lib/libcxl.sym |  29 +++++
 5 files changed, 485 insertions(+)
cxl/lib/private.h +47 -0
index 3273f21..885553a 100644
@@ -73,6 +73,53 @@ struct cxl_cmd_identify {
 	u8 qos_telemetry_caps;
 } __attribute__((packed));
 
+struct cxl_cmd_get_health_info {
+	u8 health_status;
+	u8 media_status;
+	u8 ext_status;
+	u8 life_used;
+	le16 temperature;
+	le32 dirty_shutdowns;
+	le32 volatile_errors;
+	le32 pmem_errors;
+} __attribute__((packed));
+
+/* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */
+#define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK		BIT(0)
+#define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK		BIT(1)
+#define CXL_CMD_HEALTH_INFO_STATUS_HW_REPLACEMENT_NEEDED_MASK		BIT(2)
+
+/* CXL 2.0 8.2.9.5.3 Byte 1 Media Status */
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_NORMAL				0x0
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_NOT_READY			0x1
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_PERSISTENCE_LOST		0x2
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_DATA_LOST			0x3
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_POWERLOSS_PERSISTENCE_LOSS	0x4
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_SHUTDOWN_PERSISTENCE_LOSS	0x5
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_PERSISTENCE_LOSS_IMMINENT	0x6
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_POWERLOSS_DATA_LOSS		0x7
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_SHUTDOWN_DATA_LOSS		0x8
+#define CXL_CMD_HEALTH_INFO_MEDIA_STATUS_DATA_LOSS_IMMINENT		0x9
+
+/* CXL 2.0 8.2.9.5.3 Byte 2 Additional Status */
+#define CXL_CMD_HEALTH_INFO_EXT_LIFE_USED_MASK				GENMASK(1, 0)
+#define CXL_CMD_HEALTH_INFO_EXT_LIFE_USED_NORMAL			(0)
+#define CXL_CMD_HEALTH_INFO_EXT_LIFE_USED_WARNING			(1)
+#define CXL_CMD_HEALTH_INFO_EXT_LIFE_USED_CRITICAL			(2)
+#define CXL_CMD_HEALTH_INFO_EXT_TEMPERATURE_MASK			GENMASK(3, 2)
+#define CXL_CMD_HEALTH_INFO_EXT_TEMPERATURE_NORMAL			(0)
+#define CXL_CMD_HEALTH_INFO_EXT_TEMPERATURE_WARNING			(1)
+#define CXL_CMD_HEALTH_INFO_EXT_TEMPERATURE_CRITICAL			(2)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_VOLATILE_MASK			BIT(4)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_VOLATILE_NORMAL		(0)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_VOLATILE_WARNING		(1)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_PERSISTENT_MASK		BIT(5)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_PERSISTENT_NORMAL		(0)
+#define CXL_CMD_HEALTH_INFO_EXT_CORRECTED_PERSISTENT_WARNING		(1)
+
+#define CXL_CMD_HEALTH_INFO_LIFE_USED_NOT_IMPL				0xff
+#define CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL			0xffff
+
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
 {
 	return kmod_ctx ? 0 : -ENXIO;
cxl/lib/libcxl.c +291 -0

297 lines not on this page · raw message

cxl/libcxl.h +33 -0
index 0f2d5e9..eae2db8 100644
@@ -62,6 +62,39 @@ struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
 int cxl_cmd_identify_get_fw_rev(struct cxl_cmd *cmd, char *fw_rev, int fw_len);
 unsigned long long cxl_cmd_identify_get_partition_align(struct cxl_cmd *cmd);
 unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd);
+struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev);
+int cxl_cmd_health_info_get_maintenance_needed(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_performance_degraded(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_hw_replacement_needed(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_not_ready(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_persistence_lost(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_data_lost(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_not_ready(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_persistence_lost(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_data_lost(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_powerloss_persistence_loss(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_shutdown_persistence_loss(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_persistence_loss_imminent(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_powerloss_data_loss(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_shutdown_data_loss(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_media_data_loss_imminent(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_life_used_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_life_used_warning(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_life_used_critical(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_temperature_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_temperature_warning(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_temperature_critical(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_corrected_volatile_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_corrected_volatile_warning(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_corrected_persistent_normal(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_ext_corrected_persistent_warning(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_dirty_shutdowns(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_volatile_errors(struct cxl_cmd *cmd);
+int cxl_cmd_health_info_get_pmem_errors(struct cxl_cmd *cmd);
 
 #ifdef __cplusplus
 } /* extern "C" */
util/bitmap.h +85 -0

100 lines not on this page · raw message

cxl/lib/libcxl.sym +29 -0
index 1dc45f4..c83bc28 100644
@@ -33,6 +33,35 @@ global:
 	cxl_cmd_identify_get_fw_rev;
 	cxl_cmd_identify_get_partition_align;
 	cxl_cmd_identify_get_label_size;
+	cxl_cmd_new_get_health_info;
+	cxl_cmd_health_info_get_maintenance_needed;
+	cxl_cmd_health_info_get_performance_degraded;
+	cxl_cmd_health_info_get_hw_replacement_needed;
+	cxl_cmd_health_info_get_media_normal;
+	cxl_cmd_health_info_get_media_not_ready;
+	cxl_cmd_health_info_get_media_persistence_lost;
+	cxl_cmd_health_info_get_media_data_lost;
+	cxl_cmd_health_info_get_media_powerloss_persistence_loss;
+	cxl_cmd_health_info_get_media_shutdown_persistence_loss;
+	cxl_cmd_health_info_get_media_persistence_loss_imminent;
+	cxl_cmd_health_info_get_media_powerloss_data_loss;
+	cxl_cmd_health_info_get_media_shutdown_data_loss;
+	cxl_cmd_health_info_get_media_data_loss_imminent;
+	cxl_cmd_health_info_get_ext_life_used_normal;
+	cxl_cmd_health_info_get_ext_life_used_warning;
+	cxl_cmd_health_info_get_ext_life_used_critical;
+	cxl_cmd_health_info_get_ext_temperature_normal;
+	cxl_cmd_health_info_get_ext_temperature_warning;
+	cxl_cmd_health_info_get_ext_temperature_critical;
+	cxl_cmd_health_info_get_ext_corrected_volatile_normal;
+	cxl_cmd_health_info_get_ext_corrected_volatile_warning;
+	cxl_cmd_health_info_get_ext_corrected_persistent_normal;
+	cxl_cmd_health_info_get_ext_corrected_persistent_warning;
+	cxl_cmd_health_info_get_life_used;
+	cxl_cmd_health_info_get_temperature;
+	cxl_cmd_health_info_get_dirty_shutdowns;
+	cxl_cmd_health_info_get_volatile_errors;
+	cxl_cmd_health_info_get_pmem_errors;
 local:
         *;
 };
Signature · 1 line
2.31.1
Reviewed-by on v5 7/16
#15 lore raw

Re: [ndctl PATCH v5 07/16] libcxl: add GET_HEALTH_INFO mailbox command and accessors

Quoted 8 lines · Vishal Verma

Add libcxl APIs to create a new GET_HEALTH_INFO mailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the health info output.

Cc Ben Widawsky <[email protected]>
Cc Dan Williams <[email protected]>

Looks good to me:

author maintainer
#16 lore raw

PATCH v5 8/16 libcxl: add support for the 'GET_LSA' command

In reply to Vishal Verma

Add a command allocator and accessor APIs for the 'GET_LSA' mailbox command.

---
 cxl/lib/private.h  |  5 +++++
 cxl/lib/libcxl.c   | 36 ++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  4 ++++
 cxl/lib/libcxl.sym |  2 ++
 4 files changed, 47 insertions(+)
cxl/lib/private.h +5 -0
index 885553a..bf3a897 100644
@@ -73,6 +73,11 @@ struct cxl_cmd_identify {
 	u8 qos_telemetry_caps;
 } __attribute__((packed));
 
+struct cxl_cmd_get_lsa_in {
+	le32 offset;
+	le32 length;
+} __attribute__((packed));
+
 struct cxl_cmd_get_health_info {
 	u8 health_status;
 	u8 media_status;
cxl/lib/libcxl.c +36 -0
index 065824d..76913a2 100644
@@ -1036,6 +1036,42 @@ CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev,
 	return cmd;
 }
 
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
+		unsigned int offset, unsigned int length)
+{
+	struct cxl_cmd_get_lsa_in *get_lsa;
+	struct cxl_cmd *cmd;
+
+	cmd = cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_GET_LSA);
+	if (!cmd)
+		return NULL;
+
+	get_lsa = (struct cxl_cmd_get_lsa_in *)cmd->send_cmd->in.payload;
+	get_lsa->offset = cpu_to_le32(offset);
+	get_lsa->length = cpu_to_le32(length);
+	return cmd;
+}
+
+CXL_EXPORT ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd,
+		void *buf, unsigned int length)
+{
+	struct cxl_cmd_get_lsa_in *get_lsa;
+	void *payload;
+	int rc;
+
+	rc = cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_GET_LSA);
+	if (rc)
+		return rc;
+
+	get_lsa = (struct cxl_cmd_get_lsa_in *)cmd->send_cmd->in.payload;
+	if (length > le32_to_cpu(get_lsa->length))
+		return -EINVAL;
+
+	payload = (void *)cmd->send_cmd->out.payload;
+	memcpy(buf, payload, length);
+	return length;
+}
+
 CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
 {
 	struct cxl_memdev *memdev = cmd->memdev;
cxl/libcxl.h +4 -0
index eae2db8..7408745 100644
@@ -95,6 +95,10 @@ int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd);
 int cxl_cmd_health_info_get_dirty_shutdowns(struct cxl_cmd *cmd);
 int cxl_cmd_health_info_get_volatile_errors(struct cxl_cmd *cmd);
 int cxl_cmd_health_info_get_pmem_errors(struct cxl_cmd *cmd);
+struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
+		unsigned int offset, unsigned int length);
+ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf,
+		unsigned int length);
 
 #ifdef __cplusplus
 } /* extern "C" */
cxl/lib/libcxl.sym +2 -0
index c83bc28..629322c 100644
@@ -62,6 +62,8 @@ global:
 	cxl_cmd_health_info_get_dirty_shutdowns;
 	cxl_cmd_health_info_get_volatile_errors;
 	cxl_cmd_health_info_get_pmem_errors;
+	cxl_cmd_new_read_label;
+	cxl_cmd_read_label_get_payload;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#17 lore raw

PATCH v5 9/16 libcxl: add label_size to cxl_memdev, and an API to retrieve it

In reply to Vishal Verma

Size of the Label Storage Area (LSA) is available as a sysfs attribute called 'label_storage_size'. Add that to libcxl's memdev so that it is available for label related commands.

---
 cxl/lib/private.h  |  1 +
 cxl/lib/libcxl.c   | 12 ++++++++++++
 cxl/libcxl.h       |  1 +
 cxl/lib/libcxl.sym |  1 +
 4 files changed, 15 insertions(+)
cxl/lib/private.h +1 -0
index bf3a897..c4ed741 100644
@@ -21,6 +21,7 @@ struct cxl_memdev {
 	unsigned long long pmem_size;
 	unsigned long long ram_size;
 	int payload_max;
+	size_t lsa_size;
 	struct kmod_module *module;
 };
 
cxl/lib/libcxl.c +12 -0
index 76913a2..def3a97 100644
@@ -247,6 +247,13 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
 	if (memdev->payload_max < 0)
 		goto err_read;
 
+	sprintf(path, "%s/label_storage_size", cxlmem_base);
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		goto err_read;
+	memdev->lsa_size = strtoull(buf, NULL, 0);
+	if (memdev->lsa_size == ULLONG_MAX)
+		goto err_read;
+
 	memdev->dev_path = strdup(cxlmem_base);
 	if (!memdev->dev_path)
 		goto err_read;
@@ -350,6 +357,11 @@ CXL_EXPORT const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev
 	return memdev->firmware_version;
 }
 
+CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev)
+{
+	return memdev->lsa_size;
+}
+
 CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
 {
 	if (!cmd)
cxl/libcxl.h +1 -0
index 7408745..d3b97a1 100644
@@ -42,6 +42,7 @@ struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
+size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
cxl/lib/libcxl.sym +1 -0
index 629322c..858e953 100644
@@ -64,6 +64,7 @@ global:
 	cxl_cmd_health_info_get_pmem_errors;
 	cxl_cmd_new_read_label;
 	cxl_cmd_read_label_get_payload;
+	cxl_memdev_get_label_size;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#18 lore raw

PATCH v5 10/16 libcxl: add representation for an nvdimm bridge object

In reply to Vishal Verma

Add an nvdimm bridge object representation internal to libcxl. A bridge object is ited to its parent memdev object, and this patch adds its first interface, which checks whether a bridge is 'active' - i.e. implying the label space on the memdev is owned by the kernel.

---
 cxl/lib/private.h  |  9 ++++++
 cxl/lib/libcxl.c   | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  1 +
 cxl/lib/libcxl.sym |  1 +
 4 files changed, 84 insertions(+)
cxl/lib/private.h +9 -0
index c4ed741..2f0b6ea 100644
@@ -10,6 +10,14 @@
 
 #define CXL_EXPORT __attribute__ ((visibility("default")))
 
+
+struct cxl_nvdimm_br {
+	int id;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+};
+
 struct cxl_memdev {
 	int id, major, minor;
 	void *dev_buf;
@@ -23,6 +31,7 @@ struct cxl_memdev {
 	int payload_max;
 	size_t lsa_size;
 	struct kmod_module *module;
+	struct cxl_nvdimm_br *bridge;
 };
 
 enum cxl_cmd_query_status {
cxl/lib/libcxl.c +73 -0

102 lines not on this page · raw message

cxl/libcxl.h +1 -0
index d3b97a1..535e349 100644
@@ -43,6 +43,7 @@ unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
+int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
cxl/lib/libcxl.sym +1 -0
index 858e953..f3b0c63 100644
@@ -65,6 +65,7 @@ global:
 	cxl_cmd_new_read_label;
 	cxl_cmd_read_label_get_payload;
 	cxl_memdev_get_label_size;
+	cxl_memdev_nvdimm_bridge_active;
 local:
         *;
 };
Signature · 1 line
2.31.1
Reviewed-by on v5 10/16
#19 lore raw

Re: [ndctl PATCH v5 10/16] libcxl: add representation for an nvdimm bridge object

Quoted 3 lines · Vishal Verma

Add an nvdimm bridge object representation internal to libcxl. A bridge object is ited to its parent memdev object, and this patch adds its

s/ited/tied/

Quoted 2 lines

first interface, which checks whether a bridge is 'active' - i.e. implying the label space on the memdev is owned by the kernel.

Just some minor fixups below and you can add:

Quoted 15 lines
---
 cxl/lib/private.h  |  9 ++++++
 cxl/lib/libcxl.c   | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  1 +
 cxl/lib/libcxl.sym |  1 +
 4 files changed, 84 insertions(+)
cxl/lib/private.h +0 -0
index c4ed741..2f0b6ea 100644

cxl/lib/private.h line 14

Quoted 5 lines
cxl/lib/private.h +2 -0
@@ -10,6 +10,14 @@
 
 #define CXL_EXPORT __attribute__ ((visibility("default")))
 
+
+struct cxl_nvdimm_br {

Might as well spell out "bridge".

Quoted 100 lines
cxl/lib/private.h +7 -0
+       int id;
+       void *dev_buf;
+       size_t buf_len;
+       char *dev_path;
+};
+
 struct cxl_memdev {
        int id, major, minor;
        void *dev_buf;
@@ -23,6 +31,7 @@ struct cxl_memdev {
        int payload_max;
        size_t lsa_size;
        struct kmod_module *module;
+       struct cxl_nvdimm_br *bridge;
 };
 
 enum cxl_cmd_query_status {
cxl/lib/libcxl.c +49 -0
index def3a97..7bc0696 100644
@@ -45,11 +45,19 @@ struct cxl_ctx {
        void *private_data;
 };
 
+static void free_bridge(struct cxl_nvdimm_br *bridge)
+{
+       free(bridge->dev_buf);
+       free(bridge->dev_path);
+       free(bridge);
+}
+
 static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)
 {
        if (head)
                list_del_from(head, &memdev->list);
        kmod_module_unref(memdev->module);
+       free_bridge(memdev->bridge);
        free(memdev->firmware_version);
        free(memdev->dev_buf);
        free(memdev->dev_path);
@@ -205,6 +213,40 @@ CXL_EXPORT void cxl_set_log_priority(struct cxl_ctx *ctx, int priority)
        ctx->ctx.log_priority = priority;
 }
 
+static void *add_cxl_bridge(void *parent, int id, const char *br_base)
+{
+       const char *devname = devpath_to_devname(br_base);
+       struct cxl_memdev *memdev = parent;
+       struct cxl_ctx *ctx = memdev->ctx;
+       struct cxl_nvdimm_br *bridge;
+
+       dbg(ctx, "%s: bridge_base: \'%s\'\n", devname, br_base);
+
+       bridge = calloc(1, sizeof(*bridge));
+       if (!bridge)
+               goto err_dev;
+       bridge->id = id;
+
+       bridge->dev_path = strdup(br_base);
+       if (!bridge->dev_path)
+               goto err_read;
+
+       bridge->dev_buf = calloc(1, strlen(br_base) + 50);
+       if (!bridge->dev_buf)
+               goto err_read;
+       bridge->buf_len = strlen(br_base) + 50;
+
+       memdev->bridge = bridge;
+       return bridge;
+
+ err_read:
+       free(bridge->dev_buf);
+       free(bridge->dev_path);
+       free(bridge);
+ err_dev:
+       return NULL;
+}
+
 static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
 {
        const char *devname = devpath_to_devname(cxlmem_base);
@@ -271,6 +313,8 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
                goto err_read;
        memdev->buf_len = strlen(cxlmem_base) + 50;
 
+       sysfs_device_parse(ctx, cxlmem_base, "pmem", memdev, add_cxl_bridge);
+
        cxl_memdev_foreach(ctx, memdev_dup)
                if (memdev_dup->id == memdev->id) {
                        free_memdev(memdev, NULL);
@@ -362,6 +406,35 @@ CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev)
        return memdev->lsa_size;
 }
 
+static int is_enabled(const char *drvpath)
+{
+       struct stat st;
+
+       if (lstat(drvpath, &st) < 0 || !S_ISLNK(st.st_mode))

cxl/lib/libcxl.c CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev) · line 423

Quoted 10 lines
cxl/lib/libcxl.c +10 -0
+               return 0;
+       else
+               return 1;
+}
+
+CXL_EXPORT int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev)
+{
+       struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
+       struct cxl_nvdimm_br *bridge = memdev->bridge;
+       char *path = memdev->dev_buf;

Should this be: bridge->dev_buf?

cxl/lib/libcxl.c CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev) · line 424

Quoted 1 line
cxl/lib/libcxl.c +1 -0
+       int len = memdev->buf_len;

...and this should bridge->buf_len?

Not strictly a bug, but might as well use the 'bridge' version of these attributes, right?

Quoted 43 lines
cxl/lib/libcxl.c +13 -0
+
+       if (!bridge)
+               return 0;
+
+       if (snprintf(path, len, "%s/driver", bridge->dev_path) >= len) {
+               err(ctx, "%s: nvdimm bridge buffer too small!\n",
+                               cxl_memdev_get_devname(memdev));
+               return 0;
+       }
+
+       return is_enabled(path);
+}
+
 CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
 {
        if (!cmd)
cxl/libcxl.h +1 -0
index d3b97a1..535e349 100644
@@ -43,6 +43,7 @@ unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
+int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
cxl/lib/libcxl.sym +1 -1
index 858e953..f3b0c63 100644
@@ -65,6 +65,7 @@ global:
        cxl_cmd_new_read_label;
        cxl_cmd_read_label_get_payload;
        cxl_memdev_get_label_size;
+       cxl_memdev_nvdimm_bridge_active;
 local:
         *;
 };
--

2.31.1

author maintainer
#20 lore raw

Re: [ndctl PATCH v5 10/16] libcxl: add representation for an nvdimm bridge object

Quoted 11 lines · Dan Williams
Quoted 3 lines · Vishal Verma

Add an nvdimm bridge object representation internal to libcxl. A bridge object is ited to its parent memdev object, and this patch adds its

s/ited/tied/

Quoted 2 lines

first interface, which checks whether a bridge is 'active' - i.e. implying the label space on the memdev is owned by the kernel.

Just some minor fixups below and you can add:

Thanks Dan - fixed all these up in v6

Quoted 189 lines
Quoted 15 lines
---
 cxl/lib/private.h  |  9 ++++++
 cxl/lib/libcxl.c   | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  1 +
 cxl/lib/libcxl.sym |  1 +
 4 files changed, 84 insertions(+)
cxl/lib/private.h +0 -0
index c4ed741..2f0b6ea 100644

cxl/lib/private.h line 14

Quoted 5 lines
cxl/lib/private.h +2 -0
@@ -10,6 +10,14 @@
 
 #define CXL_EXPORT __attribute__ ((visibility("default")))
 
+
+struct cxl_nvdimm_br {

Might as well spell out "bridge".

Quoted 100 lines
cxl/lib/private.h +7 -0
+       int id;
+       void *dev_buf;
+       size_t buf_len;
+       char *dev_path;
+};
+
 struct cxl_memdev {
        int id, major, minor;
        void *dev_buf;
@@ -23,6 +31,7 @@ struct cxl_memdev {
        int payload_max;
        size_t lsa_size;
        struct kmod_module *module;
+       struct cxl_nvdimm_br *bridge;
 };
 
 enum cxl_cmd_query_status {
cxl/lib/libcxl.c +49 -0
index def3a97..7bc0696 100644
@@ -45,11 +45,19 @@ struct cxl_ctx {
        void *private_data;
 };
 
+static void free_bridge(struct cxl_nvdimm_br *bridge)
+{
+       free(bridge->dev_buf);
+       free(bridge->dev_path);
+       free(bridge);
+}
+
 static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)
 {
        if (head)
                list_del_from(head, &memdev->list);
        kmod_module_unref(memdev->module);
+       free_bridge(memdev->bridge);
        free(memdev->firmware_version);
        free(memdev->dev_buf);
        free(memdev->dev_path);
@@ -205,6 +213,40 @@ CXL_EXPORT void cxl_set_log_priority(struct cxl_ctx *ctx, int priority)
        ctx->ctx.log_priority = priority;
 }
 
+static void *add_cxl_bridge(void *parent, int id, const char *br_base)
+{
+       const char *devname = devpath_to_devname(br_base);
+       struct cxl_memdev *memdev = parent;
+       struct cxl_ctx *ctx = memdev->ctx;
+       struct cxl_nvdimm_br *bridge;
+
+       dbg(ctx, "%s: bridge_base: \'%s\'\n", devname, br_base);
+
+       bridge = calloc(1, sizeof(*bridge));
+       if (!bridge)
+               goto err_dev;
+       bridge->id = id;
+
+       bridge->dev_path = strdup(br_base);
+       if (!bridge->dev_path)
+               goto err_read;
+
+       bridge->dev_buf = calloc(1, strlen(br_base) + 50);
+       if (!bridge->dev_buf)
+               goto err_read;
+       bridge->buf_len = strlen(br_base) + 50;
+
+       memdev->bridge = bridge;
+       return bridge;
+
+ err_read:
+       free(bridge->dev_buf);
+       free(bridge->dev_path);
+       free(bridge);
+ err_dev:
+       return NULL;
+}
+
 static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
 {
        const char *devname = devpath_to_devname(cxlmem_base);
@@ -271,6 +313,8 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
                goto err_read;
        memdev->buf_len = strlen(cxlmem_base) + 50;
 
+       sysfs_device_parse(ctx, cxlmem_base, "pmem", memdev, add_cxl_bridge);
+
        cxl_memdev_foreach(ctx, memdev_dup)
                if (memdev_dup->id == memdev->id) {
                        free_memdev(memdev, NULL);
@@ -362,6 +406,35 @@ CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev)
        return memdev->lsa_size;
 }
 
+static int is_enabled(const char *drvpath)
+{
+       struct stat st;
+
+       if (lstat(drvpath, &st) < 0 || !S_ISLNK(st.st_mode))

cxl/lib/libcxl.c CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev) · line 423

Quoted 10 lines
cxl/lib/libcxl.c +10 -0
+               return 0;
+       else
+               return 1;
+}
+
+CXL_EXPORT int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev)
+{
+       struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
+       struct cxl_nvdimm_br *bridge = memdev->bridge;
+       char *path = memdev->dev_buf;

Should this be: bridge->dev_buf?

cxl/lib/libcxl.c CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev) · line 424

Quoted 1 line
cxl/lib/libcxl.c +1 -0
+       int len = memdev->buf_len;

...and this should bridge->buf_len?

Not strictly a bug, but might as well use the 'bridge' version of these attributes, right?

Quoted 43 lines
cxl/lib/libcxl.c +13 -0
+
+       if (!bridge)
+               return 0;
+
+       if (snprintf(path, len, "%s/driver", bridge->dev_path) >= len) {
+               err(ctx, "%s: nvdimm bridge buffer too small!\n",
+                               cxl_memdev_get_devname(memdev));
+               return 0;
+       }
+
+       return is_enabled(path);
+}
+
 CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
 {
        if (!cmd)
cxl/libcxl.h +1 -0
index d3b97a1..535e349 100644
@@ -43,6 +43,7 @@ unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
+int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
cxl/lib/libcxl.sym +1 -1
index 858e953..f3b0c63 100644
@@ -65,6 +65,7 @@ global:
        cxl_cmd_new_read_label;
        cxl_cmd_read_label_get_payload;
        cxl_memdev_get_label_size;
+       cxl_memdev_nvdimm_bridge_active;
 local:
         *;
 };
--

2.31.1

author maintainer
#21 lore raw

PATCH v6 10/16 libcxl: add representation for an nvdimm bridge object

In reply to Vishal Verma

Add an nvdimm bridge object representation internal to libcxl. A bridge object is tied to its parent memdev object, and this patch adds its first interface, which checks whether a bridge is 'active' - i.e. implying the label space on the memdev is owned by the kernel.

---
 cxl/lib/private.h  |  8 +++++
 cxl/lib/libcxl.c   | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |  1 +
 cxl/lib/libcxl.sym |  1 +
 4 files changed, 83 insertions(+)
cxl/lib/private.h +8 -0
index c4ed741..525c41e 100644
@@ -10,6 +10,13 @@
 
 #define CXL_EXPORT __attribute__ ((visibility("default")))
 
+struct cxl_nvdimm_bridge {
+	int id;
+	void *dev_buf;
+	size_t buf_len;
+	char *dev_path;
+};
+
 struct cxl_memdev {
 	int id, major, minor;
 	void *dev_buf;
@@ -23,6 +30,7 @@ struct cxl_memdev {
 	int payload_max;
 	size_t lsa_size;
 	struct kmod_module *module;
+	struct cxl_nvdimm_bridge *bridge;
 };
 
 enum cxl_cmd_query_status {
cxl/lib/libcxl.c +73 -0

102 lines not on this page · raw message

cxl/libcxl.h +1 -0
index d3b97a1..535e349 100644
@@ -43,6 +43,7 @@ unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
+int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
cxl/lib/libcxl.sym +1 -0
index 858e953..f3b0c63 100644
@@ -65,6 +65,7 @@ global:
 	cxl_cmd_new_read_label;
 	cxl_cmd_read_label_get_payload;
 	cxl_memdev_get_label_size;
+	cxl_memdev_nvdimm_bridge_active;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#22 lore raw

PATCH v5 11/16 libcxl: add interfaces for label operations

In reply to Vishal Verma

Add libcxl interfaces to allow performinfg label (LSA) manipulations. Add a 'cxl_cmd_new_set_lsa' interface to create a 'Set LSA' mailbox command payload, and interfaces to read, write, and zero the LSA area on a memdev.

---
 cxl/lib/private.h  |   6 ++
 cxl/lib/libcxl.c   | 158 +++++++++++++++++++++++++++++++++++++++++++++
 cxl/libcxl.h       |   8 +++
 cxl/lib/libcxl.sym |   4 ++
 4 files changed, 176 insertions(+)
cxl/lib/private.h +6 -0
index 2f0b6ea..375ba22 100644
@@ -88,6 +88,12 @@ struct cxl_cmd_get_lsa_in {
 	le32 length;
 } __attribute__((packed));
 
+struct cxl_cmd_set_lsa {
+	le32 offset;
+	le32 rsvd;
+	unsigned char lsa_data[0];
+} __attribute__ ((packed));
+
 struct cxl_cmd_get_health_info {
 	u8 health_status;
 	u8 media_status;
cxl/lib/libcxl.c +158 -0

161 lines not on this page · raw message

cxl/libcxl.h +8 -0
index 535e349..89d35ba 100644
@@ -44,6 +44,12 @@ unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
 size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
 int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
+int cxl_memdev_zero_label(struct cxl_memdev *memdev, size_t length,
+		size_t offset);
+int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
+		size_t offset);
+int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
+		size_t offset);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
@@ -101,6 +107,8 @@ struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
 		unsigned int offset, unsigned int length);
 ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf,
 		unsigned int length);
+struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev,
+		void *buf, unsigned int offset, unsigned int length);
 
 #ifdef __cplusplus
 } /* extern "C" */
cxl/lib/libcxl.sym +4 -0
index f3b0c63..077d104 100644
@@ -66,6 +66,10 @@ global:
 	cxl_cmd_read_label_get_payload;
 	cxl_memdev_get_label_size;
 	cxl_memdev_nvdimm_bridge_active;
+	cxl_cmd_new_write_label;
+	cxl_memdev_zero_label;
+	cxl_memdev_write_label;
+	cxl_memdev_read_label;
 local:
         *;
 };
Signature · 1 line
2.31.1
author maintainer
#23 lore raw

PATCH v5 12/16 cxl: add commands to read, write, and zero labels

In reply to Vishal Verma

Add the following cxl-cli commands: read-labels, write-labels, zero-labels. They operate on a CXL memdev, or a set of memdevs, and allow interacting with the label storage area (LSA) on the device.

Add man pages for the above cxl-cli commands.

---
 Documentation/cxl/cxl-read-labels.txt    |  33 +++
 Documentation/cxl/cxl-write-labels.txt   |  32 +++
 Documentation/cxl/cxl-zero-labels.txt    |  29 ++
 Documentation/cxl/labels-description.txt |   8 +
 Documentation/cxl/labels-options.txt     |  17 ++
 Documentation/cxl/memdev-option.txt      |   4 +
 cxl/builtin.h                            |   5 +
 cxl/cxl.c                                |   3 +
 cxl/memdev.c                             | 324 +++++++++++++++++++++++
 Documentation/cxl/Makefile.am            |   5 +-
 cxl/Makefile.am                          |   1 +
 11 files changed, 460 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/cxl/cxl-read-labels.txt
 create mode 100644 Documentation/cxl/cxl-write-labels.txt
 create mode 100644 Documentation/cxl/cxl-zero-labels.txt
 create mode 100644 Documentation/cxl/labels-description.txt
 create mode 100644 Documentation/cxl/labels-options.txt
 create mode 100644 Documentation/cxl/memdev-option.txt
 create mode 100644 cxl/memdev.c
Documentation/cxl/cxl-read-labels.txt new file +33 -0
new file mode 100644
index 0000000..143f296
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-read-labels(1)
+==================
+
+NAME
+----
+cxl-read-labels - read out the label area on a CXL memdev
+
+SYNOPSIS
+--------
+[verse]
+'cxl read-labels' <mem0> [<mem1>..<memN>] [<options>]
+
+include::labels-description.txt[]
+This command dumps the raw binary data in a memdev's label area to stdout or a
+file.  In the multi-memdev case the data is concatenated.
+
+OPTIONS
+-------
+include::labels-options.txt[]
+
+-o::
+--output::
+	output file
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:cxl-write-labels[1],
+linkcxl:cxl-zero-labels[1],
+CXL-2.0 9.13.2
Documentation/cxl/cxl-write-labels.txt new file +32 -0
new file mode 100644
index 0000000..75f42a5
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-write-labels(1)
+===================
+
+NAME
+----
+cxl-write-labels - write data to the label area on a memdev
+
+SYNOPSIS
+--------
+[verse]
+'cxl write-labels <mem> [-i <filename>]'
+
+include::labels-description.txt[]
+Read data from the input filename, or stdin, and write it to the given
+<mem> device. Note that the device must not be active in any region, or
+actively registered with the nvdimm subsystem. If it is, the kernel will
+not allow write access to the device's label data area.
+
+OPTIONS
+-------
+include::labels-options.txt[]
+-i::
+--input::
+	input file
+
+SEE ALSO
+--------
+linkcxl:cxl-read-labels[1],
+linkcxl:cxl-zero-labels[1],
+CXL-2.0 9.13.2
Documentation/cxl/cxl-zero-labels.txt new file +29 -0
new file mode 100644
index 0000000..bf95b24
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+
+cxl-zero-labels(1)
+==================
+
+NAME
+----
+cxl-zero-labels - zero out the label area on a set of memdevs
+
+SYNOPSIS
+--------
+[verse]
+'cxl zero-labels' <mem0> [<mem1>..<memN>] [<options>]
+
+include::labels-description.txt[]
+This command resets the device to its default state by
+deleting all labels.
+
+OPTIONS
+-------
+include::labels-options.txt[]
+
+include::../copyright.txt[]
+
+SEE ALSO
+--------
+linkcxl:cxl-read-labels[1],
+linkcxl:cxl-write-labels[1],
+CXL-2.0 9.13.2
Documentation/cxl/labels-description.txt new file +8 -0
new file mode 100644
index 0000000..f60bd5d
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+DESCRIPTION
+-----------
+The region label area is a small persistent partition of capacity
+available on some CXL memory devices. The label area is used to
+and configure or determine the set of memory devices participating
+in different interleave sets.
Documentation/cxl/labels-options.txt new file +17 -0
new file mode 100644
index 0000000..06fbac3
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+
+<memory device(s)>::
+include::memdev-option.txt[]
+
+-s::
+--size=::
+	Limit the operation to the given number of bytes. A size of 0
+	indicates to operate over the entire label capacity.
+
+-O::
+--offset=::
+	Begin the operation at the given offset into the label area.
+
+-v::
+	Turn on verbose debug messages in the library (if libcxl was built with
+	logging and debug enabled).
Documentation/cxl/memdev-option.txt new file +4 -0
new file mode 100644
index 0000000..e778582
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+A 'memX' device name, or a memdev id number. Restrict the operation to
+the specified memdev(s). The keyword 'all' can be specified to indicate
+the lack of any restriction.
cxl/builtin.h +5 -0
index 3797f98..78eca6e 100644
@@ -5,4 +5,9 @@
 
 struct cxl_ctx;
 int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_write_labels(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx);
+int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx);
 #endif /* _CXL_BUILTIN_H_ */
cxl/cxl.c +3 -0
index a7725f8..4b1661d 100644
@@ -61,6 +61,9 @@ static struct cmd_struct commands[] = {
 	{ "version", .c_fn = cmd_version },
 	{ "list", .c_fn = cmd_list },
 	{ "help", .c_fn = cmd_help },
+	{ "zero-labels", .c_fn = cmd_zero_labels },
+	{ "read-labels", .c_fn = cmd_read_labels },
+	{ "write-labels", .c_fn = cmd_write_labels },
 };
 
 int main(int argc, const char **argv)
cxl/memdev.c new file +324 -0

324 lines not on this page · raw message

Documentation/cxl/Makefile.am +4 -1
index db98dd7..efabaa3 100644
@@ -19,7 +19,10 @@ endif
 
 man1_MANS = \
 	cxl.1 \
-	cxl-list.1
+	cxl-list.1 \
+	cxl-read-labels.1 \
+	cxl-write-labels.1 \
+	cxl-zero-labels.1
 
 EXTRA_DIST = $(man1_MANS)
 
cxl/Makefile.am +1 -0
index 98606b9..da9f91d 100644
@@ -10,6 +10,7 @@ config.h: $(srcdir)/Makefile.am
 cxl_SOURCES =\
 		cxl.c \
 		list.c \
+		memdev.c \
 		../util/json.c \
 		builtin.h
 
Signature · 1 line
2.31.1
author maintainer
#24 lore raw

PATCH v5 13/16 Documentation/cxl: add library API documentation

In reply to Vishal Verma

Add library API documentation for libcxl(3) using the existing asciidoc(tor) build system. Add a section 3 man page for 'libcxl' that provides an overview of the library and its usage, and a man page for the 'cxl_new()' API.

---
 Documentation/cxl/lib/cxl_new.txt | 43 +++++++++++++++++++++++
 Documentation/cxl/lib/libcxl.txt  | 56 +++++++++++++++++++++++++++++
 configure.ac                      |  1 +
 Makefile.am                       |  1 +
 .gitignore                        |  3 ++
 Documentation/cxl/lib/Makefile.am | 58 +++++++++++++++++++++++++++++++
 6 files changed, 162 insertions(+)
 create mode 100644 Documentation/cxl/lib/cxl_new.txt
 create mode 100644 Documentation/cxl/lib/libcxl.txt
 create mode 100644 Documentation/cxl/lib/Makefile.am
Documentation/cxl/lib/cxl_new.txt new file +43 -0
new file mode 100644
index 0000000..147d4e0
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: LGPL-2.0
+
+cxl_new(3)
+==========
+
+NAME
+----
+cxl_new - Create a new library context object that acts as a handle for all
+library operations
+
+SYNOPSIS
+--------
+[verse]
+----
+#include <cxl/libcxl.h>
+
+int cxl_new(struct cxl_ctx **ctx);
+----
+
+DESCRIPTION
+-----------
+Instantiates a new library context, and stores an opaque pointer in ctx. The
+context is freed by linklibcxl:cxl_unref[3], i.e. cxl_new(3) implies an
+internal linklibcxl:cxl_ref[3].
+
+
+RETURN VALUE
+------------
+Returns 0 on success, and a negative errno on failure.
+Possible error codes are:
+
+ * -ENOMEM
+ * -ENXIO
+
+EXAMPLE
+-------
+See example usage in test/libcxl.c
+
+include::../../copyright.txt[]
+
+SEE ALSO
+--------
+linklibcxl:cxl_ref[3], linklibcxl:cxl_unref[3]
Documentation/cxl/lib/libcxl.txt new file +56 -0

56 lines not on this page · raw message

configure.ac +1 -0
index dadae0a..00497ae 100644
@@ -231,6 +231,7 @@ AC_CONFIG_FILES([
         Documentation/ndctl/Makefile
         Documentation/daxctl/Makefile
         Documentation/cxl/Makefile
+        Documentation/cxl/lib/Makefile
 ])
 
 AC_OUTPUT
Makefile.am +1 -0
index 4904ee7..e2f6bef 100644
@@ -4,6 +4,7 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 SUBDIRS = . cxl/lib daxctl/lib ndctl/lib cxl ndctl daxctl
 if ENABLE_DOCS
 SUBDIRS += Documentation/ndctl Documentation/daxctl Documentation/cxl
+SUBDIRS += Documentation/cxl/lib
 endif
 SUBDIRS += test
 
.gitignore +3 -0
index 6a97b92..6468c7a 100644
@@ -14,12 +14,15 @@ Makefile.in
 /libtool
 /stamp-h1
 *.1
+*.3
 Documentation/daxctl/asciidoc.conf
 Documentation/ndctl/asciidoc.conf
 Documentation/cxl/asciidoc.conf
+Documentation/cxl/lib/asciidoc.conf
 Documentation/daxctl/asciidoctor-extensions.rb
 Documentation/ndctl/asciidoctor-extensions.rb
 Documentation/cxl/asciidoctor-extensions.rb
+Documentation/cxl/lib/asciidoctor-extensions.rb
 Documentation/ndctl/attrs.adoc
 .dirstamp
 daxctl/config.h
Documentation/cxl/lib/Makefile.am new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.31.1
author maintainer
#25 lore raw

PATCH v5 14/16 ndctl: Add CXL packages to the RPM spec

In reply to Vishal Verma

From: Ira Weiny <[email protected]>

Add CXL related packages - the cxl-cli utility, the libcxl library, and development headers to respective RPM packages in the main spec file.

---
 Makefile.am   |  4 ++++
 ndctl.spec.in | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
Makefile.am +4 -0
index e2f6bef..fa2010a 100644
@@ -23,17 +23,21 @@ CLEANFILES += $(noinst_SCRIPTS)
 
 do_rhel_subst = sed -e 's,VERSION,$(VERSION),g' \
             -e 's,DAX_DNAME,daxctl-devel,g' \
+            -e 's,CXL_DNAME,cxl-devel,g' \
             -e 's,DNAME,ndctl-devel,g' \
             -e '/^%defattr.*/d' \
 	    -e 's,DAX_LNAME,daxctl-libs,g' \
+	    -e 's,CXL_LNAME,cxl-libs,g' \
 	    -e 's,LNAME,ndctl-libs,g'
 
 do_sles_subst = sed -e 's,VERSION,$(VERSION),g' \
             -e 's,DAX_DNAME,libdaxctl-devel,g' \
+            -e 's,CXL_DNAME,libcxl-devel,g' \
             -e 's,DNAME,libndctl-devel,g' \
             -e 's,%license,%doc,g' \
             -e 's,\(^License:.*GPL\)v2,\1-2.0,g' \
             -e "s,DAX_LNAME,libdaxctl$$(($(LIBDAXCTL_CURRENT) - $(LIBDAXCTL_AGE))),g" \
+            -e "s,CXL_LNAME,libcxl$$(($(LIBCXL_CURRENT) - $(LIBCXL_AGE))),g" \
             -e "s,LNAME,libndctl$$(($(LIBNDCTL_CURRENT) - $(LIBNDCTL_AGE))),g"
 
 rhel/ndctl.spec: ndctl.spec.in Makefile.am version.m4
ndctl.spec.in +49 -0

91 lines not on this page · raw message

Signature · 1 line
2.31.1
author maintainer
#26 lore raw

PATCH v5 15/16 cxl-cli: add bash completion

In reply to Vishal Verma

Add bash completion for the cxl-cli commands implemented so far:
cxl-list
cxl-read-labels
cxl-write-labels
cxl-zero-labels

---
 contrib/ndctl | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
contrib/ndctl +109 -0
index 680fe6a..cae4b1b 100755
@@ -647,5 +647,114 @@ _daxctl()
 	__daxctl_main
 }
 
+### cxl-cli ###
+
+__cxl_get_devs()
+{
+	local opts=("--memdevs" "$*")
+	cxl list "${opts[@]}" | grep -E "^\s*\"memdev\":" | cut -d'"' -f4
+}
+
+__cxlcomp()
+{
+	local i=0
+
+	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
+	for cword in "${COMPREPLY[@]}"; do
+		if [[ "$cword" == @(--memdev|--offset|--size|--input|--output) ]]; then
+			COMPREPLY[$i]="${cword}="
+		else
+			COMPREPLY[$i]="${cword} "
+		fi
+		((i++))
+	done
+}
+
+__cxl_comp_options()
+{
+
+	local cur=$1
+	local opts
+
+	if [[ "$cur" == *=* ]]; then
+		local cur_subopt=${cur%%=*}
+		local cur_arg=${cur##*=}
+		case $cur_subopt in
+		--memdev)
+			opts="$(__cxl_get_devs -i)"
+			;;
+		*)
+			return
+			;;
+		esac
+		__cxlcomp "$opts" "$cur_arg"
+	fi
+}
+
+__cxl_comp_non_option_args()
+{
+	local subcmd=$1
+	local cur=$2
+	local opts
+
+	case $subcmd in
+	read-labels)
+		;&
+	write-labels)
+		;&
+	zero-labels)
+		opts="$(__cxl_get_devs -i) all"
+		;;
+	*)
+		return
+		;;
+	esac
+	__cxlcomp "$opts" "$cur"
+}
+
+__cxl_main()
+{
+	local cmd subcmd
+
+	cmd=${words[0]}
+	COMPREPLY=()
+
+	# Skip options backward and find the last cxl command
+	__nd_common_prev_skip_opts
+	subcmd=$prev_skip_opts
+	# List cxl subcommands or long options
+	if [ -z $subcmd ]; then
+		if [[ $cur == --* ]]; then
+			cmds="--version --help --list-cmds"
+		else
+			cmds=$($cmd --list-cmds)
+		fi
+		__cxlcomp "$cmds" "$cur"
+	else
+		# List long option names
+		if [[ $cur == --* ]];  then
+			opts=$($cmd $subcmd --list-opts)
+			__cxlcomp "$opts" "$cur"
+			__cxl_comp_options "$cur"
+		else
+			[ -z "$subcmd" ] && return
+			__cxl_comp_non_option_args "$subcmd" "$cur"
+		fi
+	fi
+}
+
+type cxl &>/dev/null &&
+_cxl()
+{
+	local cur words cword prev
+	if [ $preload_get_comp_words_by_ref = "true" ]; then
+		_get_comp_words_by_ref -n =: cur words cword prev
+	else
+		__nd_common_get_comp_words_by_ref -n =: cur words cword prev
+	fi
+	__cxl_main
+}
+
 complete -o nospace -F _ndctl ndctl
 complete -o nospace -F _daxctl daxctl
+complete -o nospace -F _cxl cxl
Signature · 1 line
2.31.1
author maintainer
#27 lore raw

PATCH v5 16/16 cxl: add health information to cxl-list

In reply to Vishal Verma

Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command to memory device listings.

---
 Documentation/cxl/cxl-list.txt |   4 +
 util/json.h                    |   1 +
 cxl/list.c                     |   5 +
 util/json.c                    | 179 +++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+)
Documentation/cxl/cxl-list.txt +4 -0
index bd377b3..dc86651 100644
@@ -53,6 +53,10 @@ OPTIONS
 --idle::
 	Include idle (not enabled / zero-sized) devices in the listing
 
+-H::
+--health::
+	Include health information in the memdev listing
+
 include::human-option.txt[]
 
 include::verbose-option.txt[]
util/json.h +1 -0
index 91918c8..ce575e6 100644
@@ -19,6 +19,7 @@ enum util_json_flags {
 	UTIL_JSON_CONFIGURED	= (1 << 7),
 	UTIL_JSON_FIRMWARE	= (1 << 8),
 	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
+	UTIL_JSON_HEALTH	= (1 << 10),
 };
 
 struct json_object;
cxl/list.c +5 -0
index 3dea73f..2fa155a 100644
@@ -16,6 +16,7 @@ static struct {
 	bool memdevs;
 	bool idle;
 	bool human;
+	bool health;
 } list;
 
 static unsigned long listopts_to_flags(void)
@@ -26,6 +27,8 @@ static unsigned long listopts_to_flags(void)
 		flags |= UTIL_JSON_IDLE;
 	if (list.human)
 		flags |= UTIL_JSON_HUMAN;
+	if (list.health)
+		flags |= UTIL_JSON_HEALTH;
 	return flags;
 }
 
@@ -57,6 +60,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
 		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
 		OPT_BOOLEAN('u', "human", &list.human,
 				"use human friendly number formats "),
+		OPT_BOOLEAN('H', "health", &list.health,
+				"include memory device health information "),
 		OPT_END(),
 	};
 	const char * const u[] = {
util/json.c +179 -0

190 lines not on this page · raw message

Signature · 1 line
2.31.1
Reviewed-by on v5 16/16
#28 lore raw

Re: [ndctl PATCH v5 16/16] cxl: add health information to cxl-list

Quoted 18 lines · Vishal Verma

Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command to memory device listings.

---
 Documentation/cxl/cxl-list.txt |   4 +
 util/json.h                    |   1 +
 cxl/list.c                     |   5 +
 util/json.c                    | 179 +++++++++++++++++++++++++++++++++
 4 files changed, 189 insertions(+)
Documentation/cxl/cxl-list.txt +0 -0
index bd377b3..dc86651 100644

Documentation/cxl/cxl-list.txt OPTIONS · line 58

Quoted 6 lines
Documentation/cxl/cxl-list.txt +3 -0
@@ -53,6 +53,10 @@ OPTIONS
 --idle::
        Include idle (not enabled / zero-sized) devices in the listing
 
+-H::
+--health::
+       Include health information in the memdev listing

Let's include a sample listing here in the man page, like the following, so that people can get an idea ahead of time about the key names and value types in the payload. Other than that you can add:

  {
    "memdev":"mem7",
    "pmem_size":268435456,
    "ram_size":268435456,
    "health":{
      "maintenance_needed":true,
      "performance_degraded":true,
      "hw_replacement_needed":true,
      "media_normal":false,
      "media_not_ready":false,
      "media_persistence_lost":false,
      "media_data_lost":true,
      "media_powerloss_persistence_loss":false,
      "media_shutdown_persistence_loss":false,
      "media_persistence_loss_imminent":false,
      "media_powerloss_data_loss":false,
      "media_shutdown_data_loss":false,
      "media_data_loss_imminent":false,
      "ext_life_used":"normal",
      "ext_temperature":"critical",
      "ext_corrected_volatile":"warning",
      "ext_corrected_persistent":"normal",
      "life_used_percent":15,
      "temperature":25,
      "dirty_shutdowns":10,
      "volatile_errors":20,
      "pmem_errors":30
    }
author maintainer
#29 lore raw

PATCH v6 16/16 cxl: add health information to cxl-list

In reply to Vishal Verma

Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command to memory device listings.

---
 Documentation/cxl/cxl-list.txt |  38 +++++++
 util/json.h                    |   1 +
 cxl/list.c                     |   5 +
 util/json.c                    | 179 +++++++++++++++++++++++++++++++++
 4 files changed, 223 insertions(+)
Documentation/cxl/cxl-list.txt +38 -0
index e761cfa..d305a37 100644
@@ -53,6 +53,44 @@ OPTIONS
 --idle::
 	Include idle (not enabled / zero-sized) devices in the listing
 
+-H::
+--health::
+	Include health information in the memdev listing. Example listing:
+----
+# cxl list -m mem0 -H
+[
+  {
+    "memdev":"mem0",
+    "pmem_size":268435456,
+    "ram_size":268435456,
+    "health":{
+      "maintenance_needed":true,
+      "performance_degraded":true,
+      "hw_replacement_needed":true,
+      "media_normal":false,
+      "media_not_ready":false,
+      "media_persistence_lost":false,
+      "media_data_lost":true,
+      "media_powerloss_persistence_loss":false,
+      "media_shutdown_persistence_loss":false,
+      "media_persistence_loss_imminent":false,
+      "media_powerloss_data_loss":false,
+      "media_shutdown_data_loss":false,
+      "media_data_loss_imminent":false,
+      "ext_life_used":"normal",
+      "ext_temperature":"critical",
+      "ext_corrected_volatile":"warning",
+      "ext_corrected_persistent":"normal",
+      "life_used_percent":15,
+      "temperature":25,
+      "dirty_shutdowns":10,
+      "volatile_errors":20,
+      "pmem_errors":30
+    }
+  }
+]
+----
+
 include::human-option.txt[]
 
 include::verbose-option.txt[]
util/json.h +1 -0
index 91918c8..ce575e6 100644
@@ -19,6 +19,7 @@ enum util_json_flags {
 	UTIL_JSON_CONFIGURED	= (1 << 7),
 	UTIL_JSON_FIRMWARE	= (1 << 8),
 	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
+	UTIL_JSON_HEALTH	= (1 << 10),
 };
 
 struct json_object;
cxl/list.c +5 -0
index 7c1d2eb..931606a 100644
@@ -16,6 +16,7 @@ static struct {
 	bool memdevs;
 	bool idle;
 	bool human;
+	bool health;
 } list;
 
 static unsigned long listopts_to_flags(void)
@@ -26,6 +27,8 @@ static unsigned long listopts_to_flags(void)
 		flags |= UTIL_JSON_IDLE;
 	if (list.human)
 		flags |= UTIL_JSON_HUMAN;
+	if (list.health)
+		flags |= UTIL_JSON_HEALTH;
 	return flags;
 }
 
@@ -57,6 +60,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
 		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
 		OPT_BOOLEAN('u', "human", &list.human,
 				"use human friendly number formats "),
+		OPT_BOOLEAN('H', "health", &list.health,
+				"include memory device health information "),
 		OPT_END(),
 	};
 	const char * const u[] = {
util/json.c +179 -0

190 lines not on this page · raw message

Signature · 1 line
2.31.1