Skip to contentSkip to conversation

ndctl: Add support and test for CXL Features support

PATCH In review Dave Jiang 4 participants 8 messages May 23, 2025 – May 29, 2025

Subsystems (3)
lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

v9 cover ndctl: Add support and test for CXL Features support

v9:
- Move script body to main(). (Marc)
- Remove uuid dep for test module. (Marc)
- Remove removal of error trap. (Marc)

v8:
- Stash fwctl discovery functions behind ifdef (Alison)
- Deal with old compilers and __counted_by(). (Alison)

v7:
- Move enumeration of fwctl behind meson option 'fwctl'. (Dan)

v6:
- Rename cxl-features.control.c back to fwctl.c. (Dan)
- Move features behind a meson option. (Dan)
- See individual commits for specific changes from v5.

v5:
- Add documentation for exported symbols. (Alison)
- Create 'struct cxl_fwctl' as object under cxl_memdev. (Dan)
- Make command prep common code. (Alison)
- Rename fwctl.c to cxl-features-control.c. (Alison)
- See individual commits for specific changes from v4.

v4:
- Adjust to kernel changes of input/output structs
- Fixup skip/pass/fail logic
- Added new kernel headers detection and dependency in meson.build

v3:
- Update test to use opcode instead of command id.

v2:
- Drop features device enumeration
- Add discovery of char device under memdev

The series provides support of libcxl enumerating FWCTL character device under the cxl_memdev device. It discovers the char device major and minor numbers for the CXL features device in order to allow issuing of ioctls to the device.

A unit test is added to locate cxl_memdev exported by the cxl_test kernel module and issue all the supported ioctls to the associated FWCTL char device to verify that all the ioctl paths are working as expected.

Kernel series: https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Dave Jiang (4):
cxl: Add cxl_bus_get_by_provider()
cxl: Enumerate major/minor of FWCTL char device
ndctl: Add features.h from kernel UAPI
cxl/test: Add test for cxl features device

 Documentation/cxl/lib/libcxl.txt |  26 ++
 config.h.meson                   |   3 +
 cxl/fwctl/cxl.h                  |  56 ++++
 cxl/fwctl/features.h             | 187 +++++++++++++
 cxl/fwctl/fwctl.h                | 141 ++++++++++
 cxl/lib/libcxl.c                 |  94 +++++++
 cxl/lib/libcxl.sym               |   8 +
 cxl/lib/private.h                |   6 +
 cxl/libcxl.h                     |   7 +
 meson.build                      |   1 +
 meson_options.txt                |   2 +
 test/cxl-features.sh             |  37 +++
 test/fwctl.c                     | 439 +++++++++++++++++++++++++++++++
 test/meson.build                 |  18 ++
 14 files changed, 1025 insertions(+)
 create mode 100644 cxl/fwctl/cxl.h
 create mode 100644 cxl/fwctl/features.h
 create mode 100644 cxl/fwctl/fwctl.h
 create mode 100755 test/cxl-features.sh
 create mode 100644 test/fwctl.c

base-commit: 1850ddcbcbf9eebd343c6e87a2c55f3f5e3930c4

Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v9 1/4 cxl: Add cxl_bus_get_by_provider()

Add helper function cxl_bus_get_by_provider() in order to support unit test that will utilize the API call.

---
 Documentation/cxl/lib/libcxl.txt |  2 ++
 cxl/lib/libcxl.c                 | 11 +++++++++++
 cxl/lib/libcxl.sym               |  5 +++++
 cxl/libcxl.h                     |  2 ++
 4 files changed, 20 insertions(+)
Documentation/cxl/lib/libcxl.txt +2 -0
index 40598a08b9f4..25ff406c2920 100644
@@ -215,6 +215,8 @@ the associated bus object.
 const char *cxl_bus_get_provider(struct cxl_bus *bus);
 const char *cxl_bus_get_devname(struct cxl_bus *bus);
 int cxl_bus_get_id(struct cxl_bus *bus);
+struct cxl_bus *cxl_bus_get_by_provider(struct cxl_ctx *ctx,
+					const char *provider);
 ----
 
 The provider name of a bus is a persistent name that is independent of
cxl/lib/libcxl.c +11 -0
index 63aa4ef3acdc..bab7343e8a4a 100644
@@ -3358,6 +3358,17 @@ CXL_EXPORT struct cxl_ctx *cxl_bus_get_ctx(struct cxl_bus *bus)
 	return cxl_port_get_ctx(&bus->port);
 }
 
+CXL_EXPORT struct cxl_bus *cxl_bus_get_by_provider(struct cxl_ctx *ctx,
+						   const char *provider)
+{
+	struct cxl_bus *bus;
+
+	cxl_bus_foreach(ctx, bus)
+		if (strcmp(provider, cxl_bus_get_provider(bus)) == 0)
+			return bus;
+	return NULL;
+}
+
 CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
 {
 	if (!cmd)
cxl/lib/libcxl.sym +5 -0
index 763151fbef59..4c9760f377e6 100644
@@ -287,3 +287,8 @@ global:
 	cxl_memdev_trigger_poison_list;
 	cxl_region_trigger_poison_list;
 } LIBCXL_7;
+
+LIBCXL_9 {
+global:
+	cxl_bus_get_by_provider;
+} LIBECXL_8;
cxl/libcxl.h +2 -0
index 43c082acd836..7a32b9b65736 100644
@@ -122,6 +122,8 @@ int cxl_bus_get_id(struct cxl_bus *bus);
 struct cxl_port *cxl_bus_get_port(struct cxl_bus *bus);
 struct cxl_ctx *cxl_bus_get_ctx(struct cxl_bus *bus);
 int cxl_bus_disable_invalidate(struct cxl_bus *bus);
+struct cxl_bus *cxl_bus_get_by_provider(struct cxl_ctx *ctx,
+					const char *provider);
 
 #define cxl_bus_foreach(ctx, bus)                                              \
 	for (bus = cxl_bus_get_first(ctx); bus != NULL;                        \
Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH v9 2/4 cxl: Enumerate major/minor of FWCTL char device

In reply to Dave Jiang

Add major/minor discovery for the FWCTL character device that is associated with supprting CXL Features under 'struct cxl_fwctl'. A 'struct cxl_fwctl' may be installed under cxl_memdev if CXL Features are supported and FWCTL is enabled. Add libcxl API functions to retrieve the major and minor of the FWCTL character device.

---
 Documentation/cxl/lib/libcxl.txt | 24 +++++++++
 config.h.meson                   |  3 ++
 cxl/lib/libcxl.c                 | 83 ++++++++++++++++++++++++++++++++
 cxl/lib/libcxl.sym               |  3 ++
 cxl/lib/private.h                |  6 +++
 cxl/libcxl.h                     |  5 ++
 meson.build                      |  1 +
 meson_options.txt                |  2 +
 8 files changed, 127 insertions(+)
Documentation/cxl/lib/libcxl.txt +24 -0
index 25ff406c2920..2a512fd9d276 100644
@@ -42,6 +42,7 @@ struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
 struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
 const char *cxl_memdev_get_host(struct cxl_memdev *memdev)
 struct cxl_memdev *cxl_endpoint_get_memdev(struct cxl_endpoint *endpoint);
+struct cxl_fwctl *cxl_memdev_get_fwctl(struct cxl_memdev *memdev);
 
 #define cxl_memdev_foreach(ctx, memdev) \
         for (memdev = cxl_memdev_get_first(ctx); \
@@ -59,6 +60,11 @@ specific memdev.
 The host of a memdev is the PCIe Endpoint device that registered its CXL
 capabilities with the Linux CXL core.
 
+A memdev may host a 'struct cxl_fwctl' if CXL Features are supported,
+CONFIG_CXL_FEATURES is enabled, and Firmware Control (FWCTL) is also enabled.
+By default the 'fwctl' option is enabled for CXL CLI. The discovery can
+be disabled by meson build option.
+
 === MEMDEV: Attributes
 ----
 int cxl_memdev_get_id(struct cxl_memdev *memdev);
@@ -185,6 +191,24 @@ device is in use. When CXL_SETPART_NEXTBOOT mode is set, the change
 in partitioning shall become the “next” configuration, to become
 active on the next device reset.
 
+FWCTL
+-----
+The object representing a Firmware Control (FWCTL) device is 'struct cxl_fwctl'.
+Library interfaces related to these devices have the prefix 'cxl_fwctl_'.
+These interfaces are associated with interacting with the FWCTL aspect of the
+memdev. And currently specifically with the CXL FWCTL character device that is
+a child of the memdev.
+
+=== FWCTL: Attributes
+----
+int cxl_fwctl_get_major(struct cxl_memdev *memdev);
+int cxl_fwctl_get_minor(struct cxl_memdev *memdev);
+----
+
+The character device node for Feature (firmware) control can be found by
+default at /dev/fwctl/fwctl%d, or created with a major / minor returned
+from cxl_memdev_get_fwctl_{major,minor}().
+
 BUSES
 -----
 The CXL Memory space is CPU and Device coherent. The address ranges that
config.h.meson +3 -0
index 5441dff9fce7..f75db3e6360f 100644
@@ -155,3 +155,6 @@
 #mesondefine DAXCTL_MODPROBE_DATA
 #mesondefine DAXCTL_MODPROBE_INSTALL
 #mesondefine PREFIX
+
+/* cxl fwctl support */
+#mesondefine ENABLE_FWCTL
cxl/lib/libcxl.c +83 -0

107 lines not on this page · raw message

cxl/lib/libcxl.sym +3 -0
index 4c9760f377e6..3ad0cd06e25a 100644
@@ -291,4 +291,7 @@ global:
 LIBCXL_9 {
 global:
 	cxl_bus_get_by_provider;
+	cxl_memdev_get_fwctl;
+	cxl_fwctl_get_major;
+	cxl_fwctl_get_minor;
 } LIBECXL_8;
cxl/lib/private.h +6 -0
index b6cd910e9335..7d5a1bcc14ac 100644
@@ -34,6 +34,11 @@ enum cxl_fwl_loading {
 	CXL_FWL_LOADING_START,
 };
 
+struct cxl_fwctl {
+	int major;
+	int minor;
+};
+
 struct cxl_endpoint;
 struct cxl_memdev {
 	int id, major, minor;
@@ -56,6 +61,7 @@ struct cxl_memdev {
 	unsigned long long serial;
 	struct cxl_endpoint *endpoint;
 	struct cxl_fw_loader *fwl;
+	struct cxl_fwctl *fwctl;
 };
 
 struct cxl_dport {
cxl/libcxl.h +5 -0
index 7a32b9b65736..54d97d7bb501 100644
@@ -59,6 +59,7 @@ static inline enum cxl_fwl_status cxl_fwl_status_from_ident(char *status)
 }
 
 struct cxl_memdev;
+struct cxl_fwctl;
 struct cxl_memdev *cxl_memdev_get_first(struct cxl_ctx *ctx);
 struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
 int cxl_memdev_get_id(struct cxl_memdev *memdev);
@@ -69,6 +70,7 @@ const char *cxl_memdev_get_host(struct cxl_memdev *memdev);
 struct cxl_bus *cxl_memdev_get_bus(struct cxl_memdev *memdev);
 int cxl_memdev_get_major(struct cxl_memdev *memdev);
 int cxl_memdev_get_minor(struct cxl_memdev *memdev);
+struct cxl_fwctl *cxl_memdev_get_fwctl(struct cxl_memdev *memdev);
 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);
@@ -81,6 +83,9 @@ int cxl_memdev_update_fw(struct cxl_memdev *memdev, const char *fw_path);
 int cxl_memdev_cancel_fw_update(struct cxl_memdev *memdev);
 int cxl_memdev_wait_sanitize(struct cxl_memdev *memdev, int timeout_ms);
 
+int cxl_fwctl_get_major(struct cxl_fwctl *fwctl);
+int cxl_fwctl_get_minor(struct cxl_fwctl *fwctl);
+
 /* ABI spelling mistakes are forever */
 static inline const char *cxl_memdev_get_firmware_version(
 		struct cxl_memdev *memdev)
meson.build +1 -0
index 3171ef1024ea..7bc40c7df12a 100644
@@ -237,6 +237,7 @@ conf.set('ENABLE_DESTRUCTIVE', get_option('destructive').enabled())
 conf.set('ENABLE_LOGGING', get_option('logging').enabled())
 conf.set('ENABLE_DEBUG', get_option('dbg').enabled())
 conf.set('ENABLE_LIBTRACEFS', get_option('libtracefs').enabled())
+conf.set('ENABLE_FWCTL', get_option('fwctl').enabled())
 
 typeof_code = '''
   void func() {
meson_options.txt +2 -0
index 5c41b1abe1f1..acc19be4ff0a 100644
@@ -28,3 +28,5 @@ option('iniparserdir', type : 'string',
        description : 'Path containing the iniparser header files')
 option('modprobedatadir', type : 'string',
        description : '''${sysconfdir}/modprobe.d/''')
+option('fwctl', type : 'feature', value : 'enabled',
+  description : 'enable firmware control')
Signature · 1 line
2.49.0
#3 lore raw

Re: [NDCTL PATCH v9 2/4] cxl: Enumerate major/minor of FWCTL char device

Quoted 8 lines · On Fri, 23 May 2025 09:46:37 -0700 Dave Jiang <[email protected]> wrote:

Add major/minor discovery for the FWCTL character device that is associated with supprting CXL Features under 'struct cxl_fwctl'. A 'struct cxl_fwctl' may be installed under cxl_memdev if CXL Features are supported and FWCTL is enabled. Add libcxl API functions to retrieve the major and minor of the FWCTL character device.

Hi Dave,

I don't normally look at ndctl stuff (not enough time) but I had a few mins so trivial comments inline.

Jonathan

Quoted 23 lines
cxl/lib/libcxl.c +14 -0
index bab7343e8a4a..af28f976bdc8 100644
@@ -1253,6 +1254,67 @@ static int add_cxl_memdev_fwl(struct cxl_memdev *memdev,
 	return -ENOMEM;
 }
 
+#ifdef ENABLE_FWCTL
+static const char fwctl_prefix[] = "fwctl";
+static int get_feature_chardev(struct cxl_memdev *memdev, const char *base,
+			       char *chardev_path)
+{
+	char *path = memdev->dev_buf;
+	struct dirent *entry;
+	bool found = false;
+	int rc = 0;
+	DIR *dir;
+
+	sprintf(path, "%s/fwctl/", base);
+	dir = opendir(path);
+	if (!dir)

cxl/lib/libcxl.c static int add_cxl_memdev_fwl(struct cxl_memdev *memdev, · line 1280

Quoted 10 lines
cxl/lib/libcxl.c +10 -0
+		return -errno;
+
+	while ((entry = readdir(dir)) != NULL) {
+		if (strncmp(entry->d_name, fwctl_prefix, strlen(fwctl_prefix)) == 0) {
+			found = true;
+			break;
+		}
+	}
+
+	if (!entry || !found) {

If entry != NULL then found is true as no other way to get out of the loop above. Which raises obvious question of why we need found?

Quoted 16 lines
cxl/lib/libcxl.c +10 -0
+		rc = -ENOENT;
+		goto read_err;
+	}
+
+	sprintf(chardev_path, "/dev/fwctl/%s", entry->d_name);
+
+read_err:
+	closedir(dir);
+	return rc;
+}
 
meson_options.txt +0 -0
index 5c41b1abe1f1..acc19be4ff0a 100644

meson_options.txt option('iniparserdir', type : 'string', · line 32

Quoted 5 lines
meson_options.txt +2 -0
@@ -28,3 +28,5 @@ option('iniparserdir', type : 'string',
        description : 'Path containing the iniparser header files')
 option('modprobedatadir', type : 'string',
        description : '''${sysconfdir}/modprobe.d/''')
+option('fwctl', type : 'feature', value : 'enabled',
+  description : 'enable firmware control')

Just looking at what is in the diff, seems that indent isn't matching local style.

Jonathan

author maintainer
#4 lore raw

PATCH v9 3/4 ndctl: Add features.h from kernel UAPI

In reply to Dave Jiang

Pull in the kernel UAPI header files from CXL Features support and FWCTL. This is needed to support building the CXL Features unit test.

---
 cxl/fwctl/cxl.h      |  56 +++++++++++++
 cxl/fwctl/features.h | 187 +++++++++++++++++++++++++++++++++++++++++++
 cxl/fwctl/fwctl.h    | 141 ++++++++++++++++++++++++++++++++
 3 files changed, 384 insertions(+)
 create mode 100644 cxl/fwctl/cxl.h
 create mode 100644 cxl/fwctl/features.h
 create mode 100644 cxl/fwctl/fwctl.h
cxl/fwctl/cxl.h new file +56 -0
new file mode 100644
index 000000000000..43f522f0cdcd
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (c) 2024-2025 Intel Corporation
+ *
+ * These are definitions for the mailbox command interface of CXL subsystem.
+ */
+#ifndef _UAPI_FWCTL_CXL_H_
+#define _UAPI_FWCTL_CXL_H_
+
+#include <linux/types.h>
+#include <linux/stddef.h>
+#include <cxl/features.h>
+
+/**
+ * struct fwctl_rpc_cxl - ioctl(FWCTL_RPC) input for CXL
+ * @opcode: CXL mailbox command opcode
+ * @flags: Flags for the command (input).
+ * @op_size: Size of input payload.
+ * @reserved1: Reserved. Must be 0s.
+ * @get_sup_feats_in: Get Supported Features input
+ * @get_feat_in: Get Feature input
+ * @set_feat_in: Set Feature input
+ */
+struct fwctl_rpc_cxl {
+	__struct_group(fwctl_rpc_cxl_hdr, hdr, /* no attrs */,
+		__u32 opcode;
+		__u32 flags;
+		__u32 op_size;
+		__u32 reserved1;
+	);
+	union {
+		struct cxl_mbox_get_sup_feats_in get_sup_feats_in;
+		struct cxl_mbox_get_feat_in get_feat_in;
+		struct cxl_mbox_set_feat_in set_feat_in;
+	};
+};
+
+/**
+ * struct fwctl_rpc_cxl_out - ioctl(FWCTL_RPC) output for CXL
+ * @size: Size of the output payload
+ * @retval: Return value from device
+ * @get_sup_feats_out: Get Supported Features output
+ * @payload: raw byte stream of payload
+ */
+struct fwctl_rpc_cxl_out {
+	__struct_group(fwctl_rpc_cxl_out_hdr, hdr, /* no attrs */,
+		__u32 size;
+		__u32 retval;
+	);
+	union {
+		struct cxl_mbox_get_sup_feats_out get_sup_feats_out;
+		__DECLARE_FLEX_ARRAY(__u8, payload);
+	};
+};
+
+#endif
cxl/fwctl/features.h new file +187 -0

187 lines not on this page · raw message

cxl/fwctl/fwctl.h new file +141 -0

141 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH v9 4/4 cxl/test: Add test for cxl features device

In reply to Dave Jiang

Add a unit test to verify the features ioctl commands. Test support added for locating a features device, retrieve and verify the supported features commands, retrieve specific feature command data, retrieve test feature data, and write and verify test feature data.

---
v9:
- Move everything to main() in test script. (Marc)
- Remove "remove trap" code in test script. (Marc)
- Remove uuid dep for test module. (Marc)

---
 cxl/fwctl/cxl.h      |   2 +-
 test/cxl-features.sh |  37 ++++
 test/fwctl.c         | 439 +++++++++++++++++++++++++++++++++++++++++++
 test/meson.build     |  18 ++
 4 files changed, 495 insertions(+), 1 deletion(-)
 create mode 100755 test/cxl-features.sh
 create mode 100644 test/fwctl.c
cxl/fwctl/cxl.h +1 -1
index 43f522f0cdcd..c560b2a1181d 100644
@@ -9,7 +9,7 @@
 
 #include <linux/types.h>
 #include <linux/stddef.h>
-#include <cxl/features.h>
+#include "features.h"
 
 /**
  * struct fwctl_rpc_cxl - ioctl(FWCTL_RPC) input for CXL
test/cxl-features.sh new file +37 -0
new file mode 100755
index 000000000000..839417f69d4c
@@ -0,0 +1,37 @@
+#!/bin/bash -Ex
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 Intel Corporation. All rights reserved.
+
+main()
+{
+    local rc=77
+    # 237 is -ENODEV
+    ERR_NODEV=237
+
+    . $(dirname "$0")/common
+    FEATURES="$TEST_PATH"/fwctl
+
+    trap 'err $LINENO' ERR
+
+    modprobe cxl_test
+
+    test -x "$FEATURES" || do_skip "no CXL Features Control"
+
+    rc=0
+    "$FEATURES" || rc=$?
+
+    echo "error: $rc"
+    if [ "$rc" -eq "$ERR_NODEV" ]; then
+	do_skip "no CXL FWCTL char dev"
+    elif [ "$rc" -ne 0 ]; then
+	echo "fail: $LINENO" && exit 1
+    fi
+
+    trap 'err $LINENO' ERR
+
+    _cxl_cleanup
+}
+
+{
+    main "$@"; exit "$?"
+}
test/fwctl.c new file +439 -0

439 lines not on this page · raw message

test/meson.build +18 -0
index 2fd7df5211dd..e05703545109 100644
@@ -17,6 +17,13 @@ ndctl_deps = libndctl_deps + [
   versiondep,
 ]
 
+libcxl_deps = [
+  cxl_dep,
+  ndctl_dep,
+  uuid,
+  kmod,
+]
+
 libndctl = executable('libndctl', testcore + [ 'libndctl.c'],
   dependencies : libndctl_deps,
   include_directories : root_inc,
@@ -235,6 +242,17 @@ if get_option('keyutils').enabled()
   ]
 endif
 
+if get_option('fwctl').enabled()
+  fwctl = executable('fwctl', 'fwctl.c',
+    dependencies : libcxl_deps,
+    include_directories : root_inc,
+  )
+  cxl_features = find_program('cxl-features.sh')
+  tests += [
+    [ 'cxl-features.sh',        cxl_features,       'cxl'   ],
+  ]
+endif
+
 foreach t : tests
   test(t[0], t[1],
     is_parallel : false,
Signature · 1 line
2.49.0
#6 lore raw

Re: [NDCTL PATCH v9 4/4] cxl/test: Add test for cxl features device

Again, apologies for commenting so late (v9).

I reviewed only the shell script below and all these comments could be "future improvements" post merge. Or, before merge if there is a v10.

test/cxl-features.sh line 9

Quoted 12 lines · Dave Jiang
test/cxl-features.sh new file +9 -0
@@ -0,0 +1,37 @@
+#!/bin/bash -Ex
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 Intel Corporation. All rights reserved.
+
+main()
+{
+    local rc=77
+    # 237 is -ENODEV
+    ERR_NODEV=237

Nit: local ERR_NODEV=237

test/cxl-features.sh line 11

Quoted 2 lines
test/cxl-features.sh new file +2 -0
+
+    . $(dirname "$0")/common

Mmmm... interesting, moving this too goes beyond what I recommended but maybe it's better?

In theory, sourced files have no side-effect or barely. In practice though...

LGTM!

test/cxl-features.sh line 23

Quoted 12 lines
test/cxl-features.sh new file +12 -0
+    FEATURES="$TEST_PATH"/fwctl
+
+    trap 'err $LINENO' ERR
+
+    modprobe cxl_test
+
+    test -x "$FEATURES" || do_skip "no CXL Features Control"
+
+    rc=0
+    "$FEATURES" || rc=$?
+
+    echo "error: $rc"

echo "status: $rc"

test/cxl-features.sh line 30

Quoted 7 lines
test/cxl-features.sh new file +7 -0
+    if [ "$rc" -eq "$ERR_NODEV" ]; then
+	do_skip "no CXL FWCTL char dev"
+    elif [ "$rc" -ne 0 ]; then
+	echo "fail: $LINENO" && exit 1
+    fi
+
+    trap 'err $LINENO' ERR

I had a chat with David and he confirmed this duplicate is an oversight.

Quoted 7 lines
test/cxl-features.sh new file +7 -0
+
+    _cxl_cleanup
+}
+
+{
+    main "$@"; exit "$?"
+}
maintainer
#7 lore raw
In reply to Dave Jiang

On Fri, May 23, 2025 at 09:46:35AM -0700, Dave Jiang wrote:

This set to applied to ndctl/pending.
https://github.com/pmem/ndctl/tree/pending

Marc & DaveJ - take a look and see if the unit test reflects your last comments and concerns. I err'd on the side of like-ness...keeping it like the other cxl-*.sh unit tests with respect to what is kept as boiler-plate at the top of the test.

Quoted 79 lines

v9:
- Move script body to main(). (Marc)
- Remove uuid dep for test module. (Marc)
- Remove removal of error trap. (Marc)

v8:
- Stash fwctl discovery functions behind ifdef (Alison)
- Deal with old compilers and __counted_by(). (Alison)

v7:
- Move enumeration of fwctl behind meson option 'fwctl'. (Dan)

v6:
- Rename cxl-features.control.c back to fwctl.c. (Dan)
- Move features behind a meson option. (Dan)
- See individual commits for specific changes from v5.

v5:
- Add documentation for exported symbols. (Alison)
- Create 'struct cxl_fwctl' as object under cxl_memdev. (Dan)
- Make command prep common code. (Alison)
- Rename fwctl.c to cxl-features-control.c. (Alison)
- See individual commits for specific changes from v4.

v4:
- Adjust to kernel changes of input/output structs
- Fixup skip/pass/fail logic
- Added new kernel headers detection and dependency in meson.build

v3:
- Update test to use opcode instead of command id.

v2:
- Drop features device enumeration
- Add discovery of char device under memdev

The series provides support of libcxl enumerating FWCTL character device under the cxl_memdev device. It discovers the char device major and minor numbers for the CXL features device in order to allow issuing of ioctls to the device.

A unit test is added to locate cxl_memdev exported by the cxl_test kernel module and issue all the supported ioctls to the associated FWCTL char device to verify that all the ioctl paths are working as expected.

Kernel series: https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Dave Jiang (4):
cxl: Add cxl_bus_get_by_provider()
cxl: Enumerate major/minor of FWCTL char device
ndctl: Add features.h from kernel UAPI
cxl/test: Add test for cxl features device

 Documentation/cxl/lib/libcxl.txt |  26 ++
 config.h.meson                   |   3 +
 cxl/fwctl/cxl.h                  |  56 ++++
 cxl/fwctl/features.h             | 187 +++++++++++++
 cxl/fwctl/fwctl.h                | 141 ++++++++++
 cxl/lib/libcxl.c                 |  94 +++++++
 cxl/lib/libcxl.sym               |   8 +
 cxl/lib/private.h                |   6 +
 cxl/libcxl.h                     |   7 +
 meson.build                      |   1 +
 meson_options.txt                |   2 +
 test/cxl-features.sh             |  37 +++
 test/fwctl.c                     | 439 +++++++++++++++++++++++++++++++
 test/meson.build                 |  18 ++
 14 files changed, 1025 insertions(+)
 create mode 100644 cxl/fwctl/cxl.h
 create mode 100644 cxl/fwctl/features.h
 create mode 100644 cxl/fwctl/fwctl.h
 create mode 100755 test/cxl-features.sh
 create mode 100644 test/fwctl.c

base-commit: 1850ddcbcbf9eebd343c6e87a2c55f3f5e3930c4

Signature · 1 line
2.49.0