ndctl: Add support and test for CXL Features support
Dave Jiang
maintainerv8 cover ndctl: Add support and test for CXL Features support
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 | 31 +++ test/fwctl.c | 439 +++++++++++++++++++++++++++++++ test/meson.build | 19 ++ 14 files changed, 1020 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
Dave Jiang
maintainerPATCH v8 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
@@ -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
@@ -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
@@ -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
@@ -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
Dave Jiang
maintainerPATCH v8 2/4 cxl: Enumerate major/minor of FWCTL char device
In reply to Dave JiangAdd 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.
---
v8:
- Put helper functions behind ifdef when fwctl is disabled
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Dave Jiang
maintainerPATCH v8 3/4 ndctl: Add features.h from kernel UAPI
In reply to Dave JiangPull in the kernel UAPI header files from CXL Features support and FWCTL. This is needed to support building the CXL Features unit test.
---
v8:
- Add define for __counted_by() to deal with older compilers. (Alison)
--- 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
@@ -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
Dave Jiang
maintainerPATCH v8 4/4 cxl/test: Add test for cxl features device
In reply to Dave JiangAdd 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.
---
v8:
- Fix typo in test script
--- cxl/fwctl/cxl.h | 2 +- test/cxl-features.sh | 31 +++ test/fwctl.c | 439 +++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 19 ++ 4 files changed, 490 insertions(+), 1 deletion(-) create mode 100755 test/cxl-features.sh create mode 100644 test/fwctl.c
cxl/fwctl/cxl.h +1 -1
@@ -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 +31 -0
@@ -0,0 +1,31 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Intel Corporation. All rights reserved. + +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" +# disable trap +trap - $(compgen -A signal) +"$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
test/fwctl.c new file +439 -0
439 lines not on this page · raw message
test/meson.build +19 -0
@@ -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,18 @@ if get_option('keyutils').enabled() ] endif +uuid_dep = dependency('uuid', required: false) +if get_option('fwctl').enabled() and uuid_dep.found() + 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
Re: [NDCTL PATCH v8 4/4] cxl/test: Add test for cxl features device
[Sorry for commenting for the first time on v8]
Could you move all the cxl-features.sh code to a main() function and then call main "$@" at the end?
It's a pretty standard practice and has many benefits listed here:
https://github.com/thesofproject/sof-test/issues/740
More inline
test/cxl-features.sh line 5
Quoted 11 lines · Dave Jiang
test/cxl-features.sh new file +5
-0@@ -0,0 +1,31 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2025 Intel Corporation. All rights reserved. + +rc=77
Once this is a function:
local rc=77
test/cxl-features.sh line 18
Quoted 13 lines
test/cxl-features.sh new file +13
-0+# 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" +# disable trap +trap - $(compgen -A signal)
ALL of them? Is that really necessary? Or just ERR maybe? A comment maybe?
traps are usually the reserved domain of test/common.
If this just for ERR, then you shouldn't need to change traps at all:
rc=0
"$FEATURES" || rc=$?
|| and friends turn off "set -e" and "trap ERR" temporarily (otherwise they would be incompatible with each other)
test/cxl-features.sh line 29
Quoted 11 lines
test/cxl-features.sh new file +11
-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
In a distant future this should live in test/common...
Quoted 2 lines
test/cxl-features.sh new file +2
-0+ +_cxl_cleanup