cxl: Add CXL feature commands support via fwctl
Subsystems (3)
Dave Jiang
maintainerv2 cover cxl: Add CXL feature commands support via fwctl
v2:
- Drop features device and driver. Move features enabling to cxl_memdev. (Dan)
- Drop sysfs attribute of number of features. (Dan)
- Drop moving of include/uapi/linux/cxl_mem.h. (Dan)
- Set get driver info ioctl to return reserved 32bit. Set behavior of issue ioctl successful as indicating Feature commands supported.
- Set 'Set Feature Size' to 0 for kernel exclusive Features.
- See individual patches for detailed changes from v1.
- Hide FWCTL bits behind CONFIG_CXL_FWCTL. (Dan)
v1:
- Create a CXL features driver to handle all feature command related bits including FWCTL support. (Dan)
- Tested against CXL CLI unit tests for FWCTL.
- See individual patches for detailed changes from RFC v2.
RFC v2:
- Dropped 1/13 and 2/13 from previous version. Merged upstream already.
- Combined changes from Shiju for "get supported features"
- Addressed comments from Jonathan and Jason
- See specific changes in individual patch revision history
- Added hardware command info to FWCTL
- Added filtering to set feature command
- Added documentation
This series add support for CXL feature commands using the FWCTL framework [1]. The code has been tested with CXL CLI unit tests for FWCTL.
Patches 1-7 are shared with EDAC series [1] and there will be an immutable branch once accepted post review.
CXL Features support is added behind the CXL mem driver. The 3 mailbox commands "Get Supported Features", "Get Feature", and "Set Feature" are implemented. The "Get" commands are under the FWCTL_RPC_CONFIGURATION policy, the "Set" command checks the policy depending on the set effects of the feature defined by the device via the Feature set effects field. All mailbox commands for CXL provides an effects table that describes the effects of a command when performed on the device. For CXL features, there is also an effects field that describes the effects a feature set operation has on the device per feature. The security policy is checked against this feature specific effects field.
The code is based off of v3 of FWCTL series [2] posted by Jason and rebased on top of v6.13-rc5.
[1]: https://lore.kernel.org/linux-cxl/[email protected]/T/#t
[2]: https://lore.kernel.org/linux-cxl/[email protected]/#r
---
Dave Jiang (14):
cxl: Refactor user ioctl command path from mds to mailbox
cxl: Enumerate feature commands
cxl: Add Get Supported Features command for kernel usage cxl/test: Add Get Supported Features mailbox command support
cxl: Setup exclusive CXL features that are reserved for the kernel
cxl: Add FWCTL support to the CXL memdev driver
cxl: Add support for FWCTL get driver information callback
cxl: Move cxl feature command structs to user header
cxl: Add support for fwctl RPC command to enable CXL feature commands
cxl: Add support to handle user feature commands for get feature
cxl: Add support to handle user feature commands for set feature cxl/test: Add Get Feature support to cxl_test
cxl/test: Add Set Feature support to cxl_test
fwctl/cxl: Add documentation to FWCTL CXL
Shiju Jose (2):
cxl/mbox: Add GET_FEATURE mailbox command
cxl/mbox: Add SET_FEATURE mailbox command
Documentation/userspace-api/fwctl/fwctl-cxl.rst | 135 +++++++++++ Documentation/userspace-api/fwctl/index.rst | 1 + drivers/cxl/Kconfig | 1 + drivers/cxl/Makefile | 2 +- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 6 +- drivers/cxl/core/features.c | 175 ++++++++++++++ drivers/cxl/core/mbox.c | 128 ++++++---- drivers/cxl/core/memdev.c | 22 +- drivers/cxl/cxl.h | 3 + drivers/cxl/cxlmem.h | 45 +--- drivers/cxl/features.c | 567 ++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/features.h | 15 ++ drivers/cxl/mem.c | 5 + include/cxl/features.h | 80 +++++++ include/cxl/mailbox.h | 44 +++- include/uapi/cxl/features.h | 128 ++++++++++ include/uapi/fwctl/cxl.h | 56 +++++ include/uapi/fwctl/fwctl.h | 1 + tools/testing/cxl/Kbuild | 3 +- tools/testing/cxl/test/mem.c | 174 ++++++++++++++ 21 files changed, 1494 insertions(+), 98 deletions(-)
Dave Jiang
maintainerPATCH v2 1/16 cxl: Refactor user ioctl command path from mds to mailbox
With 'struct cxl_mailbox' context introduced, the helper functions cxl_query_cmd() and cxl_send_cmd() can take a cxl_mailbox directly rather than a cxl_memdev parameter. Refactor to use cxl_mailbox directly.
--- drivers/cxl/core/core.h | 6 ++- drivers/cxl/core/mbox.c | 89 +++++++++++++++++++-------------------- drivers/cxl/core/memdev.c | 22 +++++++--- drivers/cxl/cxlmem.h | 40 ------------------ include/cxl/mailbox.h | 41 +++++++++++++++++- 5 files changed, 102 insertions(+), 96 deletions(-)
drivers/cxl/core/core.h +4 -2
@@ -4,6 +4,8 @@#ifndef __CXL_CORE_H__#define __CXL_CORE_H__ +#include <cxl/mailbox.h> +extern const struct device_type cxl_nvdimm_bridge_type;extern const struct device_type cxl_nvdimm_type;extern const struct device_type cxl_pmu_type;
@@ -65,9 +67,9 @@ static inline void cxl_region_exit(void)struct cxl_send_command ;struct cxl_mem_query_commands ; -int cxl_query_cmd (struct cxl_memdev *cxlmd, +int cxl_query_cmd (struct cxl_mailbox *cxl_mbox,struct cxl_mem_query_commands __user *q); -int cxl_send_cmd (struct cxl_memdev *cxlmd,struct cxl_send_command __user *s); +int cxl_send_cmd (struct cxl_mailbox *cxl_mailbox,struct cxl_send_command __user *s);void __iomem *devm_cxl_iomap_block (struct device *dev,resource_size_t addr,resource_size_t length);
drivers/cxl/core/mbox.c +43 -46
241 lines not on this page · raw message
drivers/cxl/core/memdev.c +15 -7
@@ -564,9 +564,11 @@ EXPORT_SYMBOL_NS_GPL(is_cxl_memdev, "CXL");void set_exclusive_cxl_commands (struct cxl_memdev_state *mds,unsigned long *cmds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +down_write (&cxl_memdev_rwsem); -bitmap_or (mds->exclusive_cmds, mds->exclusive_cmds, cmds, -CXL_MEM_COMMAND_ID_MAX ); +bitmap_or (cxl_mbox->exclusive_cmds, cxl_mbox->exclusive_cmds, + cmds,CXL_MEM_COMMAND_ID_MAX );up_write (&cxl_memdev_rwsem); }EXPORT_SYMBOL_NS_GPL (set_exclusive_cxl_commands,"CXL" );
@@ -579,9 +581,11 @@ EXPORT_SYMBOL_NS_GPL(set_exclusive_cxl_commands, "CXL");void clear_exclusive_cxl_commands (struct cxl_memdev_state *mds,unsigned long *cmds) { +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +down_write (&cxl_memdev_rwsem); -bitmap_andnot (mds->exclusive_cmds, mds->exclusive_cmds, cmds, -CXL_MEM_COMMAND_ID_MAX ); +bitmap_andnot (cxl_mbox->exclusive_cmds, cxl_mbox->exclusive_cmds, + cmds,CXL_MEM_COMMAND_ID_MAX );up_write (&cxl_memdev_rwsem); }EXPORT_SYMBOL_NS_GPL (clear_exclusive_cxl_commands,"CXL" );
@@ -656,11 +660,14 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,static long __cxl_memdev_ioctl (struct cxl_memdev *cxlmd,unsigned int cmd,unsigned long arg) { +struct cxl_memdev_state *mds =to_cxl_memdev_state (cxlmd->cxlds); +struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; +switch (cmd) {case CXL_MEM_QUERY_COMMANDS : -return cxl_query_cmd (cxlmd, (void __user *)arg); +return cxl_query_cmd (cxl_mbox, (void __user *)arg);case CXL_MEM_SEND_COMMAND : -return cxl_send_cmd (cxlmd, (void __user *)arg); +return cxl_send_cmd (cxl_mbox, (void __user *)arg);default :return -ENOTTY ; }
@@ -994,10 +1001,11 @@ static void cxl_remove_fw_upload(void *fwl)int devm_cxl_setup_fw_upload (struct device *host,struct cxl_memdev_state *mds) {struct cxl_dev_state *cxlds = &mds->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox;struct device *dev = &cxlds->cxlmd->dev;struct fw_upload *fwl; -if (!test_bit (CXL_MEM_COMMAND_ID_GET_FW_INFO , mds->enabled_cmds)) +if (!test_bit (CXL_MEM_COMMAND_ID_GET_FW_INFO , cxl_mbox->enabled_cmds))return 0 ; fwl = firmware_upload_register(THIS_MODULE, dev, dev_name(dev),
drivers/cxl/cxlmem.h +0 -40
@@ -106,42 +106,6 @@ static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port,return xa_load (&port->endpoints, (unsigned long )&cxlmd->dev); } -/** -* struct cxl_mbox_cmd - A command to be submitted to hardware. -* @opcode: (input) The command set and command submitted to hardware. -* @payload_in: (input) Pointer to the input payload. -* @payload_out: (output) Pointer to the output payload. Must be allocated by -* the caller. -* @size_in: (input) Number of bytes to load from @payload_in. -* @size_out: (input) Max number of bytes loaded into @payload_out. -* (output) Number of bytes generated by the device. For fixed size -* outputs commands this is always expected to be deterministic. For -* variable sized output commands, it tells the exact number of bytes -* written. -* @min_out: (input) internal command output payload size validation -* @poll_count: (input) Number of timeouts to attempt. -* @poll_interval_ms: (input) Time between mailbox background command polling -* interval timeouts. -* @return_code: (output) Error code returned from hardware. -* -* This is the primary mechanism used to send commands to the hardware. -* All the fields except @payload_* correspond exactly to the fields described in -* Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and -* @payload_out are written to, and read from the Command Payload Registers -* defined in CXL 2.0 8.2.8.4.8. -*/ -struct cxl_mbox_cmd { -u16 opcode; -void *payload_in; -void *payload_out; -size_t size_in; -size_t size_out; -size_t min_out; -int poll_count; -int poll_interval_ms; -u16 return_code; -}; -/* * Per CXL 3.0 Section 8.2.8.4.5.1 */
@@ -461,8 +425,6 @@ static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)* @lsa_size: Size of Label Storage Area * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) * @firmware_version: Firmware version for the memory device. -* @enabled_cmds: Hardware commands found enabled in CEL. -* @exclusive_cmds: Commands that are kernel-internal only * @total_bytes: sum of all possible capacities * @volatile_only_bytes: hard volatile capacity * @persistent_only_bytes: hard persistent capacity
@@ -485,8 +447,6 @@ struct cxl_memdev_state {struct cxl_dev_state cxlds;size_t lsa_size;char firmware_version[0x10 ]; -DECLARE_BITMAP (enabled_cmds,CXL_MEM_COMMAND_ID_MAX ); -DECLARE_BITMAP (exclusive_cmds,CXL_MEM_COMMAND_ID_MAX );u64 total_bytes;u64 volatile_only_bytes;u64 persistent_only_bytes;
include/cxl/mailbox.h +40 -1
58 lines not on this page · raw message
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 2/16 cxl: Enumerate feature commands
In reply to Dave JiangAdd feature commands enumeration code in order to detect and enumerate the 3 feature related commands "get supported features", "get feature", and "set feature". The enumeration will help determine whether the driver can issue any of the 3 commands to the device.
---
v2:
- Setup allocation of cxlfs and move enumeration of commands to the setup function.
- Introduce features_capability enum. (Dan)
- Name the setup function devm_cxl_add_features(). (Dan)
- Drop 'cxl_mem_command' support. (Dan)
- Move feature support to mem probe. (Dan)
- Remove comma at last entry of data structs. (Jonathan)
--- drivers/cxl/Makefile | 2 +- drivers/cxl/core/mbox.c | 30 ++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ drivers/cxl/cxlmem.h | 5 ++++ drivers/cxl/features.c | 55 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/features.h | 8 ++++++ drivers/cxl/mem.c | 5 ++++ include/cxl/features.h | 35 +++++++++++++++++++++++++ include/cxl/mailbox.h | 2 ++ tools/testing/cxl/Kbuild | 2 +- 10 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 drivers/cxl/features.c create mode 100644 drivers/cxl/features.h create mode 100644 include/cxl/features.h
drivers/cxl/Makefile +1 -1
@@ -17,5 +17,5 @@ obj-$(CONFIG_CXL_PCI) += cxl_pci.o cxl_port-y := port.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o security.o -cxl_mem-y := mem.o +cxl_mem-y := mem.o features.o cxl_pci-y := pci.o
drivers/cxl/core/mbox.c +30 -0
@@ -69,6 +69,29 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { CXL_CMD(GET_TIMESTAMP, 0, 0x8, 0), }; +static u16 cxl_feature_commands[] = { +CXL_MBOX_OP_GET_SUPPORTED_FEATURES , +CXL_MBOX_OP_GET_FEATURE , +CXL_MBOX_OP_SET_FEATURE +}; + +/** +* cxl_get_feature_command_id() - Get the index id for a feature command +* @opcode: The device opcode for the feature command +* +* Return the index id on success or -errno on failure +*/ +int cxl_get_feature_command_id (u16 opcode) +{ +for (int i =0 ; i <ARRAY_SIZE (cxl_feature_commands); i++) { +if (cxl_feature_commands[i] == opcode) +return i; + } + +return -ENOENT ; +} +EXPORT_SYMBOL_NS_GPL (cxl_get_feature_command_id,"CXL" ); +/* * Commands that RAW doesn't permit. The rationale for each: *
@@ -734,6 +757,13 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel)if (cmd) {set_bit (cmd->info.id, cxl_mbox->enabled_cmds); enabled++; + }else { +int fid =cxl_get_feature_command_id (opcode); + +if (fid >=0 ) { +set_bit (fid, cxl_mbox->feature_cmds); + enabled++; + } }if (cxl_is_poison_command (opcode)) {
drivers/cxl/cxl.h +2 -0
@@ -911,6 +911,8 @@ void cxl_coordinates_combine(struct access_coordinate *out,bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port); +int cxl_get_feature_command_id (u16 opcode); +/* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/.
drivers/cxl/cxlmem.h +5 -0
@@ -39,6 +39,7 @@* @dev: driver core device object * @cdev: char dev core object for ioctl operations * @cxlds: The device state backing this device +* @cxlfs: The features state for the device * @detach_work: active memdev lost a port in its ancestry * @cxl_nvb: coordinate removal of @cxl_nvd if present * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
@@ -50,6 +51,7 @@ struct cxl_memdev {struct device dev;struct cdev cdev;struct cxl_dev_state *cxlds; +struct cxl_features_state *cxlfs;struct work_struct detach_work;struct cxl_nvdimm_bridge *cxl_nvb;struct cxl_nvdimm *cxl_nvd;
@@ -490,6 +492,9 @@ enum cxl_opcode {CXL_MBOX_OP_GET_LOG_CAPS =0x0402 ,CXL_MBOX_OP_CLEAR_LOG =0x0403 ,CXL_MBOX_OP_GET_SUP_LOG_SUBLIST =0x0405 , +CXL_MBOX_OP_GET_SUPPORTED_FEATURES =0x0500 , +CXL_MBOX_OP_GET_FEATURE =0x0501 , +CXL_MBOX_OP_SET_FEATURE =0x0502 ,CXL_MBOX_OP_IDENTIFY =0x4000 ,CXL_MBOX_OP_GET_PARTITION_INFO =0x4100 , CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101,
drivers/cxl/features.c new file +55 -0
55 lines not on this page · raw message
drivers/cxl/features.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_LOCAL__ +#define __CXL_FEATURES_LOCAL__ + +int devm_cxl_add_features (struct cxl_memdev *cxlmd); + +#endif
drivers/cxl/mem.c +5 -0
@@ -7,6 +7,7 @@#include "cxlmem.h" #include "cxlpci.h" +#include "features.h" /** * DOC: cxl mem
@@ -180,6 +181,10 @@ static int cxl_mem_probe(struct device *dev)return rc; } + rc =devm_cxl_add_features (cxlmd); +if (rc) +dev_dbg (dev,"No CXL Features enumerated.\n" ); +/* * The kernel may be operating out of CXL memory on this device, * there is no spec defined way to determine whether this device
include/cxl/features.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2024-2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_H__ +#define __CXL_FEATURES_H__ + +struct cxl_mailbox ; + +/* Index IDs for CXL mailbox Feature commands */ +enum feature_cmds { +CXL_FEATURE_ID_GET_SUPPORTED_FEATURES =0 , +CXL_FEATURE_ID_GET_FEATURE , +CXL_FEATURE_ID_SET_FEATURE , +CXL_FEATURE_ID_MAX +}; + +/* Feature commands capability supported by a device */ +enum cxl_features_capability { +CXL_FEATURES_NONE =0 , +CXL_FEATURES_RO , +CXL_FEATURES_RW +}; + +/** +* struct cxl_features_state - The Features state for the device +* @cxlmd: Pointer to cxl mem device +* @cap: Feature commands capability +* @num_features: total Features supported by the device +*/ +struct cxl_features_state { +struct cxl_memdev *cxlmd; +enum cxl_features_capability cap; +int num_features; +}; + +#endif
include/cxl/mailbox.h +2 -0
@@ -3,6 +3,7 @@#ifndef __CXL_MBOX_H__#define __CXL_MBOX_H__#include <linux/rcuwait.h> +#include <cxl/features.h> #include <uapi/linux/cxl_mem.h> /**
@@ -56,6 +57,7 @@ struct cxl_mailbox {struct device *host;DECLARE_BITMAP (enabled_cmds,CXL_MEM_COMMAND_ID_MAX );DECLARE_BITMAP (exclusive_cmds,CXL_MEM_COMMAND_ID_MAX ); +DECLARE_BITMAP (feature_cmds,CXL_FEATURE_ID_MAX );size_t payload_size;struct mutex mbox_mutex;/* lock to protect mailbox context */ struct rcuwait mbox_wait;
tools/testing/cxl/Kbuild +1 -1
@@ -46,7 +46,7 @@ cxl_port-y += cxl_port_test.o obj-m += cxl_mem.o -cxl_mem-y := $(CXL_SRC)/mem.o +cxl_mem-y := $(CXL_SRC)/mem.o $(CXL_SRC)/features.o cxl_mem-y += config_check.o cxl_mem-y += cxl_mem_test.o
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 3/16 cxl: Add Get Supported Features command for kernel usage
In reply to Dave JiangCXL spec r3.2 8.2.9.6.1 Get Supported Features (Opcode 0500h) The command retrieve the list of supported device-specific features (identified by UUID) and general information about each Feature.
The driver will retrieve the feature entries in order to make checks and provide information for the Get Feature and Set Feature command. One of the main piece of information retrieved are the effects a Set Feature command would have for a particular feature.
---
v2:
- Move to memdev driver and drop features driver support. (Dan)
- Use features_capability to check what's supported. (Dan)
- Drop cxl_get_supported_feature_entry() as no usage (Dan, Jonathan)
- Drop Shiju sign off tags per requested. (Shiju)
- Rename EXTEND bit(9) to VALID. (Jonathan)
--- drivers/cxl/features.c | 159 +++++++++++++++++++++++++++++++++++++++-- include/cxl/features.h | 57 +++++++++++++++ 2 files changed, 210 insertions(+), 6 deletions(-)
drivers/cxl/features.c +153 -6
@@ -7,11 +7,144 @@#include "cxlmem.h" #include "features.h" -static void enumerate_feature_cmds (struct cxl_memdev *cxlmd) +static void cxl_free_feature_entries (void *entries) +{ +kvfree (entries); +} + +static int cxl_get_supported_features_count (struct cxl_mailbox *cxl_mbox) +{ +struct cxl_mbox_get_sup_feats_out mbox_out; +struct cxl_mbox_get_sup_feats_in mbox_in; +struct cxl_mbox_cmd mbox_cmd; +int rc; + +memset (&mbox_in,0 ,sizeof (mbox_in)); + mbox_in.count =cpu_to_le32 (sizeof (mbox_out)); +memset (&mbox_out,0 ,sizeof (mbox_out)); + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_SUPPORTED_FEATURES , + .size_in =sizeof (mbox_in), + .payload_in = &mbox_in, + .size_out =sizeof (mbox_out), + .payload_out = &mbox_out, + .min_out =sizeof (mbox_out), + }; + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +return le16_to_cpu (mbox_out.supported_feats); +} + +static int get_supported_features (struct cxl_memdev *cxlmd, +struct cxl_features_state *cxlfs) +{ +int remain_feats, max_size, max_feats, start, rc, hdr_size; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox; +int feat_size =sizeof (struct cxl_feat_entry ); +struct cxl_mbox_get_sup_feats_in mbox_in; +struct cxl_feat_entry *entry; +struct cxl_mbox_cmd mbox_cmd; +int count; + +if (cxlfs->cap <CXL_FEATURES_RO ) +return -EOPNOTSUPP ; + + count =cxl_get_supported_features_count (cxl_mbox); +if (count ==0 ) +return 0 ; +if (count <0 ) +return -ENXIO ; + + struct cxl_feat_entry *entries __free(kvfree) = +kvmalloc (count *sizeof (*entries),GFP_KERNEL ); +if (!entries) +return -ENOMEM ; + + struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) = +kvmalloc (cxl_mbox->payload_size,GFP_KERNEL ); +if (!mbox_out) +return -ENOMEM ; + + hdr_size =sizeof (*mbox_out); + max_size = cxl_mbox->payload_size - hdr_size; +/* max feat entries that can fit in mailbox max payload size */ + max_feats = max_size / feat_size; + entry = entries; + + start =0 ; + remain_feats = count; +do { +int retrieved, alloc_size, copy_feats; +int num_entries; + +if (remain_feats > max_feats) { + alloc_size =sizeof (*mbox_out) + max_feats * feat_size; + remain_feats = remain_feats - max_feats; + copy_feats = max_feats; + }else { + alloc_size =sizeof (*mbox_out) + remain_feats * feat_size; + copy_feats = remain_feats; + remain_feats =0 ; + } + +memset (&mbox_in,0 ,sizeof (mbox_in)); + mbox_in.count =cpu_to_le32 (alloc_size); + mbox_in.start_idx =cpu_to_le16 (start); +memset (mbox_out,0 , alloc_size); + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_SUPPORTED_FEATURES , + .size_in =sizeof (mbox_in), + .payload_in = &mbox_in, + .size_out = alloc_size, + .payload_out = mbox_out, + .min_out = hdr_size, + }; + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +if (mbox_cmd.size_out <= hdr_size) +return -ENXIO ; + +/* +* Make sure retrieved out buffer is multiple of feature +* entries. +*/ + retrieved = mbox_cmd.size_out - hdr_size; +if (retrieved % feat_size) +return -ENXIO ; + + num_entries =le16_to_cpu (mbox_out->num_entries); +/* +* If the reported output entries * defined entry size != +* retrieved output bytes, then the output package is incorrect. +*/ +if (num_entries * feat_size != retrieved) +return -ENXIO ; + +memcpy (entry, mbox_out->ents, retrieved); + entry++; +/* +* If the number of output entries is less than expected, add the +* remaining entries to the next batch. +*/ + remain_feats += copy_feats - num_entries; + start += num_entries; + }while (remain_feats); + + cxlfs->num_features = count; + cxlfs->entries =no_free_ptr (entries); +return devm_add_action_or_reset (&cxlmd->dev, cxl_free_feature_entries, + cxlfs->entries); +} + +static void enumerate_feature_cmds (struct cxl_memdev *cxlmd, +struct cxl_features_state *cxlfs) {struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; -struct cxl_features_state *cxlfs = cxlds->cxlmd->cxlfs;int fid; fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_SUPPORTED_FEATURES );
@@ -31,6 +164,15 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd) cxlfs->cap =CXL_FEATURES_RW ; } +static void cxl_cxlfs_free (struct cxl_features_state *cxlfs) +{ +struct device *dev = &cxlfs->cxlmd->dev; + +devm_kfree (dev, cxlfs); +} + +DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T)) +/** * devm_cxl_add_features() - Allocate and initialize features context * @cxlmd: CXL memory device
@@ -39,16 +181,21 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd)*/ int devm_cxl_add_features (struct cxl_memdev *cxlmd) { -struct cxl_features_state *cxlfs;struct device *dev = &cxlmd->dev; +int rc; - cxlfs =devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); + struct cxl_features_state *cxlfs __free(free_cxlfs) = +devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL );if (!cxlfs)return -ENOMEM ; - cxlmd->cxlfs = cxlfs; cxlfs->cxlmd = cxlmd; -enumerate_feature_cmds (cxlmd); +enumerate_feature_cmds (cxlmd, cxlfs); + rc =get_supported_features (cxlmd, cxlfs); +if (rc) +return rc; + + cxlmd->cxlfs =no_free_ptr (cxlfs);return 0 ; }
include/cxl/features.h +57 -0
74 lines not on this page · raw message
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 4/16 cxl/test: Add Get Supported Features mailbox command support
In reply to Dave JiangAdd cxl-test emulation of Get Supported Features mailbox command. Currently only adding a test feature with feature identifier of all f's for testing.
---
v1:
- Fix setting of num_entries endieness issue. (Jonathan)
--- tools/testing/cxl/test/mem.c | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
tools/testing/cxl/test/mem.c +68 -0
@@ -44,6 +44,10 @@ static struct cxl_cel_entry mock_cel[] = { .opcode = cpu_to_le16(CXL_MBOX_OP_GET_SUPPORTED_LOGS), .effect = CXL_CMD_EFFECT_NONE, }, + { + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_SUPPORTED_FEATURES), + .effect = CXL_CMD_EFFECT_NONE, + }, { .opcode = cpu_to_le16(CXL_MBOX_OP_IDENTIFY), .effect = CXL_CMD_EFFECT_NONE,
@@ -1337,6 +1341,67 @@ static int mock_activate_fw(struct cxl_mockmem_data *mdata,return -EINVAL ; } +#define CXL_VENDOR_FEATURE_TEST \ + UUID_INIT(0xffffffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff) + +static void fill_feature_vendor_test (struct cxl_feat_entry *feat) +{ + feat->uuid =CXL_VENDOR_FEATURE_TEST ; + feat->id =0 ; + feat->get_feat_size =cpu_to_le16 (0x4 ); + feat->set_feat_size =cpu_to_le16 (0x4 ); + feat->flags =cpu_to_le32 (CXL_FEATURE_F_CHANGEABLE | +CXL_FEATURE_F_DEFAULT_SEL | +CXL_FEATURE_F_SAVED_SEL ); + feat->get_feat_ver =1 ; + feat->set_feat_ver =1 ; + feat->effects =cpu_to_le16 (CXL_CMD_CONFIG_CHANGE_COLD_RESET | +CXL_CMD_EFFECTS_VALID ); +} + +static int mock_get_supported_features (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct cxl_mbox_get_sup_feats_in *in = cmd->payload_in; +struct cxl_mbox_get_sup_feats_out *out = cmd->payload_out; +struct cxl_feat_entry *feat; +u16 start_idx, count; + +if (cmd->size_out <sizeof (*out)) { + cmd->return_code =CXL_MBOX_CMD_RC_PAYLOADLEN ; +return -EINVAL ; + } + +/* +* Current emulation only supports 1 feature +*/ + start_idx =le16_to_cpu (in->start_idx); +if (start_idx !=0 ) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + } + + count =le16_to_cpu (in->count); +if (count <sizeof (*out)) { + cmd->return_code =CXL_MBOX_CMD_RC_PAYLOADLEN ; +return -EINVAL ; + } + + out->supported_feats =cpu_to_le16 (1 ); + cmd->return_code =0 ; +if (count <sizeof (*out) +sizeof (*feat)) { + out->num_entries =0 ; +return 0 ; + } + + out->num_entries =cpu_to_le16 (1 ); + feat = out->ents; +fill_feature_vendor_test (feat); + +return 0 ; +} +static int cxl_mock_mbox_send (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd) {
@@ -1422,6 +1487,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,case CXL_MBOX_OP_ACTIVATE_FW : rc =mock_activate_fw (mdata, cmd);break ; +case CXL_MBOX_OP_GET_SUPPORTED_FEATURES : + rc =mock_get_supported_features (mdata, cmd); +break ;default :break ; }
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 5/16 cxl/mbox: Add GET_FEATURE mailbox command
In reply to Dave JiangFrom: Shiju Jose <[email protected]>
Add support for GET_FEATURE mailbox command.
CXL spec r3.2 section 8.2.9.6 describes optional device specific features. The settings of a feature can be retrieved using Get Feature command. CXL spec r3.2 section 8.2.9.6.2 describes Get Feature command.
---
v2:
- Set input as 'struct cxl_mailbox' for cxl_get_feature() (Dan)
- Set feat_uuid as 'uuid_t *' (Dan)
- Use uuid_copy() to assign uuid
--- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/features.c | 59 +++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 29 ++++++++++++++++++ tools/testing/cxl/Kbuild | 1 + 4 files changed, 90 insertions(+) create mode 100644 drivers/cxl/core/features.c
drivers/cxl/core/Makefile +1 -0
@@ -14,5 +14,6 @@ cxl_core-y += pci.o cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-y += cdat.o +cxl_core-y += features.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o
drivers/cxl/core/features.c new file +59 -0
59 lines not on this page · raw message
include/cxl/features.h +29 -0
@@ -89,4 +89,33 @@ struct cxl_mbox_get_sup_feats_out { struct cxl_feat_entry ents[] __counted_by_le(num_entries); } __packed; +/* +* Get Feature CXL spec r3.2 Spec 8.2.9.6.2 +*/ + +/* +* Get Feature input payload +* CXL spec r3.2 section 8.2.9.6.2 Table 8-99 +*/ +struct cxl_mbox_get_feat_in { +uuid_t uuid; +__le16 offset; +__le16 count; +u8 selection; +} __packed; + +/* Selection field for 'struct cxl_mbox_get_feat_in' */ +enum cxl_get_feat_selection { +CXL_GET_FEAT_SEL_CURRENT_VALUE , +CXL_GET_FEAT_SEL_DEFAULT_VALUE , +CXL_GET_FEAT_SEL_SAVED_VALUE , +CXL_GET_FEAT_SEL_MAX +}; + +struct cxl_mailbox ; +size_t cxl_get_feature (struct cxl_mailbox *cxl_mbox,const uuid_t *feat_uuid, +enum cxl_get_feat_selection selection, +void *feat_out,size_t feat_out_size,u16 offset, +u16 *return_code); +#endif
tools/testing/cxl/Kbuild +1 -0
@@ -61,6 +61,7 @@ cxl_core-y += $(CXL_CORE_SRC)/pci.o cxl_core-y += $(CXL_CORE_SRC)/hdm.o cxl_core-y += $(CXL_CORE_SRC)/pmu.o cxl_core-y += $(CXL_CORE_SRC)/cdat.o +cxl_core-y += $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o cxl_core-y += config_check.o
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 6/16 cxl/mbox: Add SET_FEATURE mailbox command
In reply to Dave JiangFrom: Shiju Jose <[email protected]>
Add support for SET_FEATURE mailbox command.
CXL spec r3.2 section 8.2.9.6 describes optional device specific features. CXL devices supports features with changeable attributes.
The settings of a feature can be optionally modified using Set Feature command.
CXL spec r3.2 section 8.2.9.6.3 describes Set Feature command.
---
v2:
- Set input as 'struct cxl_mailbox' for cxl_get_feature() (Dan)
- Set feat_uuid as 'uuid_t *' (Dan)
- Use uuid_copy() to assign uuid
- Fix tab alignment. (Jonathan)
- Update kmalloc() to kzalloc(). (Dan)
--- drivers/cxl/core/features.c | 81 +++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 33 +++++++++++++++ 2 files changed, 114 insertions(+)
drivers/cxl/core/features.c +81 -0
@@ -57,3 +57,84 @@ size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,return data_rcvd_size; }EXPORT_SYMBOL_NS_GPL (cxl_get_feature,"CXL" ); + +/* +* FEAT_DATA_MIN_PAYLOAD_SIZE - min extra number of bytes should be +* available in the mailbox for storing the actual feature data so that +* the feature data transfer would work as expected. +*/ +#define FEAT_DATA_MIN_PAYLOAD_SIZE 10 +int cxl_set_feature (struct cxl_mailbox *cxl_mbox, +const uuid_t *feat_uuid,u8 feat_version, +void *feat_data,size_t feat_data_size, +u32 feat_flag,u16 offset,u16 *return_code) +{ +struct cxl_memdev_set_feat_pi { +struct cxl_mbox_set_feat_hdr hdr; +u8 feat_data[]; + } __packed; +size_t data_in_size, data_sent_size =0 ; +struct cxl_mbox_cmd mbox_cmd; +size_t hdr_size; +int rc =0 ; + +if (return_code) + *return_code =CXL_MBOX_CMD_RC_INPUT ; + + struct cxl_memdev_set_feat_pi *pi __free(kfree) = +kzalloc (cxl_mbox->payload_size,GFP_KERNEL ); +uuid_copy (&pi->hdr.uuid, feat_uuid); + pi->hdr.version = feat_version; + feat_flag &= ~CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK ; + feat_flag |=CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET ; + hdr_size =sizeof (pi->hdr); +/* +* Check minimum mbox payload size is available for +* the feature data transfer. +*/ +if (hdr_size +FEAT_DATA_MIN_PAYLOAD_SIZE > cxl_mbox->payload_size) +return -ENOMEM ; + +if ((hdr_size + feat_data_size) <= cxl_mbox->payload_size) { + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER ); + data_in_size = feat_data_size; + }else { + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER ); + data_in_size = cxl_mbox->payload_size - hdr_size; + } + +do { + pi->hdr.offset =cpu_to_le16 (offset + data_sent_size); +memcpy (pi->feat_data, feat_data + data_sent_size, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_SET_FEATURE , + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +if (rc <0 ) { +if (return_code) + *return_code = mbox_cmd.return_code; +return rc; + } + + data_sent_size += data_in_size; +if (data_sent_size >= feat_data_size) { +if (return_code) + *return_code =CXL_MBOX_CMD_RC_SUCCESS ; +return 0 ; + } + +if ((feat_data_size - data_sent_size) <= (cxl_mbox->payload_size - hdr_size)) { + data_in_size = feat_data_size - data_sent_size; + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER ); + }else { + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER ); + } + }while (true); +} +EXPORT_SYMBOL_NS_GPL (cxl_set_feature,"CXL" );
include/cxl/features.h +33 -0
@@ -112,10 +112,43 @@ enum cxl_get_feat_selection {CXL_GET_FEAT_SEL_MAX }; +/* +* Set Feature CXL spec r3.2 8.2.9.6.3 +*/ + +/* +* Set Feature input payload +* CXL spec r3.2 section 8.2.9.6.3 Table 8-101 +*/ +struct cxl_mbox_set_feat_hdr { +uuid_t uuid; +__le32 flags; +__le16 offset; +u8 version; +u8 rsvd[9 ]; +} __packed; + +/* Set Feature flags field */ +enum cxl_set_feat_flag_data_transfer { +CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER =0 , +CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER , +CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER , +CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER , +CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER , +CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX +}; + +#define CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK GENMASK(2, 0) + +#define CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET BIT(3) +struct cxl_mailbox ;size_t cxl_get_feature (struct cxl_mailbox *cxl_mbox,const uuid_t *feat_uuid,enum cxl_get_feat_selection selection,void *feat_out,size_t feat_out_size,u16 offset,u16 *return_code); +int cxl_set_feature (struct cxl_mailbox *cxl_mbox,const uuid_t *feat_uuid, +u8 feat_version,void *feat_data,size_t feat_data_size, +u32 feat_flag,u16 offset,u16 *return_code);#endif
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 7/16 cxl: Setup exclusive CXL features that are reserved for the kernel
In reply to Dave JiangCertain features will be exclusively used by components such as in kernel RAS driver. Setup an exclusion list that can be later filtered out before exposing to user space.
--- drivers/cxl/core/features.c | 29 +++++++++++++++++++++++++++++ drivers/cxl/features.c | 4 ++++ drivers/cxl/features.h | 3 +++ include/cxl/features.h | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)
drivers/cxl/core/features.c +29 -0
@@ -8,6 +8,35 @@#include "cxlmem.h" #include "features.h" +/* All the features below are exclusive to the kernel */ +static const uuid_t cxl_exclusive_feats[] = { +CXL_FEAT_PATROL_SCRUB_UUID , +CXL_FEAT_ECS_UUID , +CXL_FEAT_SPPR_UUID , +CXL_FEAT_HPPR_UUID , +CXL_FEAT_CACHELINE_SPARING_UUID , +CXL_FEAT_ROW_SPARING_UUID , +CXL_FEAT_BANK_SPARING_UUID , +CXL_FEAT_RANK_SPARING_UUID , +}; + +/** +* is_cxl_feature_exclusive() - Check if a CXL feature is exclusive to kernel +* @entry: cxl feature entry +* +* Return true if feature is exclusive to kernel, otherwise false +*/ +bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry) +{ +for (int i =0 ; i <ARRAY_SIZE (cxl_exclusive_feats); i++) { +if (uuid_equal (&entry->uuid, &cxl_exclusive_feats[i])) +return true; + } + +return false; +} +EXPORT_SYMBOL_NS_GPL (is_cxl_feature_exclusive,"CXL" ); + size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, enum cxl_get_feat_selection selection, void *feat_out, size_t feat_out_size, u16 offset,
drivers/cxl/features.c +4 -0
@@ -46,6 +46,7 @@ static int get_supported_features(struct cxl_memdev *cxlmd,struct cxl_mbox_get_sup_feats_in mbox_in;struct cxl_feat_entry *entry;struct cxl_mbox_cmd mbox_cmd; +int user_feats =0 ;int count;if (cxlfs->cap <CXL_FEATURES_RO )
@@ -125,6 +126,8 @@ static int get_supported_features(struct cxl_memdev *cxlmd,return -ENXIO ;memcpy (entry, mbox_out->ents, retrieved); +if (!is_cxl_feature_exclusive (entry)) + user_feats++; entry++;/* * If the number of output entries is less than expected, add the
@@ -135,6 +138,7 @@ static int get_supported_features(struct cxl_memdev *cxlmd, }while (remain_feats); cxlfs->num_features = count; + cxlfs->num_user_features = user_feats; cxlfs->entries =no_free_ptr (entries);return devm_add_action_or_reset (&cxlmd->dev, cxl_free_feature_entries, cxlfs->entries);
drivers/cxl/features.h +3 -0
@@ -3,6 +3,9 @@#ifndef __CXL_FEATURES_LOCAL__#define __CXL_FEATURES_LOCAL__ +struct cxl_feat_entry ; +int devm_cxl_add_features (struct cxl_memdev *cxlmd); +bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);#endif
include/cxl/features.h +35 -0
@@ -5,6 +5,39 @@#include <linux/uuid.h> +/* Feature UUIDs used by the kernel */ +#define CXL_FEAT_PATROL_SCRUB_UUID \ + UUID_INIT(0x96dad7d6, 0xfde8, 0x482b, 0xa7, 0x33, 0x75, 0x77, 0x4e, \ + 0x06, 0xdb, 0x8a) + +#define CXL_FEAT_ECS_UUID \ + UUID_INIT(0xe5b13f22, 0x2328, 0x4a14, 0xb8, 0xba, 0xb9, 0x69, 0x1e, \ + 0x89, 0x33, 0x86) + +#define CXL_FEAT_SPPR_UUID \ + UUID_INIT(0x892ba475, 0xfad8, 0x474e, 0x9d, 0x3e, 0x69, 0x2c, 0x91, \ + 0x75, 0x68, 0xbb) + +#define CXL_FEAT_HPPR_UUID \ + UUID_INIT(0x80ea4521, 0x786f, 0x4127, 0xaf, 0xb1, 0xec, 0x74, 0x59, \ + 0xfb, 0x0e, 0x24) + +#define CXL_FEAT_CACHELINE_SPARING_UUID \ + UUID_INIT(0x96C33386, 0x91dd, 0x44c7, 0x9e, 0xcb, 0xfd, 0xaf, 0x65, \ + 0x03, 0xba, 0xc4) + +#define CXL_FEAT_ROW_SPARING_UUID \ + UUID_INIT(0x450ebf67, 0xb135, 0x4f97, 0xa4, 0x98, 0xc2, 0xd5, 0x7f, \ + 0x27, 0x9b, 0xed) + +#define CXL_FEAT_BANK_SPARING_UUID \ + UUID_INIT(0x78b79636, 0x90ac, 0x4b64, 0xa4, 0xef, 0xfa, 0xac, 0x5d, \ + 0x18, 0xa8, 0x63) + +#define CXL_FEAT_RANK_SPARING_UUID \ + UUID_INIT(0x34dbaff5, 0x0552, 0x4281, 0x8f, 0x76, 0xda, 0x0b, 0x5e, \ + 0x7a, 0x76, 0xa7) +struct cxl_mailbox ;/* Index IDs for CXL mailbox Feature commands */
@@ -27,12 +60,14 @@ enum cxl_features_capability {* @cxlmd: Pointer to cxl mem device * @cap: Feature commands capability * @num_features: total Features supported by the device +* @num_user_features: total Features not kernel exclusive * @entries: Feature detail entries fetched from the device */ struct cxl_features_state {struct cxl_memdev *cxlmd;enum cxl_features_capability cap;int num_features; +int num_user_features;struct cxl_feat_entry *entries; };
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 8/16 cxl: Add FWCTL support to the CXL memdev driver
In reply to Dave JiangAdd fwctl support code to allow sending of CXL feature commands from userspace through as ioctls via FWCTL. Provide initial setup bits.
---
v2:
- Associate FWCTL with the 'cxl_memdev' through the memdev driver. (Dan)
- I'm leaving Jonathan's tag off to get this looked at again.
- Hide FWCTL code behind CONFIG_CXL_FWCTL (Dan)
--- drivers/cxl/Kconfig | 15 +++++++ drivers/cxl/Makefile | 1 + drivers/cxl/features.c | 35 ++++++++++++--- drivers/cxl/features.h | 2 + drivers/cxl/fwctl.c | 88 ++++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 3 ++ include/uapi/fwctl/fwctl.h | 1 + tools/testing/cxl/Kbuild | 1 + 8 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 drivers/cxl/fwctl.c
drivers/cxl/Kconfig +15 -0
@@ -102,6 +102,21 @@ config CXL_MEM If unsure say 'm'. +config CXL_FWCTL + bool "CXL: Firmware Control support" + depends on CXL_MEM + select FWCTL + help + Enable support for firmware control of CXL devices. This allows + a FWCTL char device to be created in order to issue ioctls from + user space to exercise the CXL Features commands supported by + a CXL mailbox. There are some Features defined in the CXL spec + such as memory sparing. However a lof of those features are + exclusive to the kernel. Most likely the Features maniulated + by CXL_FWCTL will be vendor defined Features. + + If unsure say 'n'. + config CXL_PORT default CXL_BUS tristate
drivers/cxl/Makefile +1 -0
@@ -18,4 +18,5 @@ cxl_port-y := port.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o security.o cxl_mem-y := mem.o features.o +cxl_mem-$(CONFIG_CXL_FWCTL) += fwctl.o cxl_pci-y := pci.o
drivers/cxl/features.c +29 -6
@@ -1,8 +1,11 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */ +#include <linux/pci.h> #include <linux/device.h> +#include <linux/module.h> #include <cxl/mailbox.h> #include <cxl/features.h> +#include "cxl.h" #include "cxlmem.h" #include "features.h"
@@ -168,11 +171,31 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, cxlfs->cap =CXL_FEATURES_RW ; } +/* The __weak symbol gets replaced by FWCTL allocation function in fwctl.c */ +struct cxl_features_state *__weak devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{ +struct device *dev = &cxlmd->dev; +struct cxl_features_state *cxlfs = +devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); + +if (!cxlfs) +return ERR_PTR (-ENOMEM ); + + cxlfs->cxlmd = cxlmd; + +return cxlfs; +} + +/* The __weak symbol gets replaced by FWCTL free function in fwctl.c */ +void __weak devm_cxlfs_free (struct cxl_memdev *cxlmd) +{ +devm_kfree (&cxlmd->dev, cxlmd->cxlfs); + cxlmd->cxlfs =NULL ; +} +static void cxl_cxlfs_free (struct cxl_features_state *cxlfs) { -struct device *dev = &cxlfs->cxlmd->dev; - -devm_kfree (dev, cxlfs); +devm_cxlfs_free (cxlfs->cxlmd); } DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))
@@ -185,15 +208,13 @@ DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))*/ int devm_cxl_add_features (struct cxl_memdev *cxlmd) { -struct device *dev = &cxlmd->dev;int rc; struct cxl_features_state *cxlfs __free(free_cxlfs) = -devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); +devm_cxlfs_allocate (cxlmd);if (!cxlfs)return -ENOMEM ; - cxlfs->cxlmd = cxlmd;enumerate_feature_cmds (cxlmd, cxlfs); rc =get_supported_features (cxlmd, cxlfs);if (rc)
@@ -204,3 +225,5 @@ int devm_cxl_add_features(struct cxl_memdev *cxlmd)return 0 ; }EXPORT_SYMBOL_NS_GPL (devm_cxl_add_features,"CXL" ); + +MODULE_IMPORT_NS ("CXL" );
drivers/cxl/features.h +2 -0
@@ -5,6 +5,8 @@struct cxl_feat_entry ; +struct cxl_features_state *devm_cxlfs_allocate (struct cxl_memdev *cxlmd); +void devm_cxlfs_free (struct cxl_memdev *cxlmd);int devm_cxl_add_features (struct cxl_memdev *cxlmd);bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);
drivers/cxl/fwctl.c new file +88 -0
88 lines not on this page · raw message
include/cxl/features.h +3 -0
@@ -4,6 +4,7 @@#define __CXL_FEATURES_H__#include <linux/uuid.h> +#include <linux/fwctl.h> /* Feature UUIDs used by the kernel */ #define CXL_FEAT_PATROL_SCRUB_UUID \
@@ -57,6 +58,7 @@ enum cxl_features_capability {/** * struct cxl_features_state - The Features state for the device +* @fwctl: FWCTL device * @cxlmd: Pointer to cxl mem device * @cap: Feature commands capability * @num_features: total Features supported by the device
@@ -64,6 +66,7 @@ enum cxl_features_capability {* @entries: Feature detail entries fetched from the device */ struct cxl_features_state { +struct fwctl_device fwctl;struct cxl_memdev *cxlmd;enum cxl_features_capability cap;int num_features;
include/uapi/fwctl/fwctl.h +1 -0
@@ -43,6 +43,7 @@ enum {enum fwctl_device_type {FWCTL_DEVICE_TYPE_ERROR =0 ,FWCTL_DEVICE_TYPE_MLX5 =1 , +FWCTL_DEVICE_TYPE_CXL =2 , };/**
tools/testing/cxl/Kbuild +1 -0
@@ -47,6 +47,7 @@ cxl_port-y += cxl_port_test.o obj-m += cxl_mem.o cxl_mem-y := $(CXL_SRC)/mem.o $(CXL_SRC)/features.o +cxl_mem-$(CONFIG_CXL_FWCTL) += $(CXL_SRC)/fwctl.o cxl_mem-y += config_check.o cxl_mem-y += cxl_mem_test.o
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 9/16 cxl: Add support for FWCTL get driver information callback
In reply to Dave JiangAdd definition for fwctl_ops->info() to return driver information. The function will return a data structure with a reserved u32. This is setup for future usages.
---
v2:
- Set command_info to reserved. (Dan)
--- drivers/cxl/fwctl.c | 18 ++++++++++++++++-- include/cxl/mailbox.h | 1 + include/uapi/fwctl/cxl.h | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 include/uapi/fwctl/cxl.h
drivers/cxl/fwctl.c +16 -2
@@ -6,6 +6,8 @@#include "cxlmem.h" #include "features.h" +#define to_cxl_features_state (fwctl) container_of(fwctl, struct cxl_features_state, fwctl) +static int cxlctl_open_uctx (struct fwctl_uctx *uctx) {return 0 ;
@@ -17,8 +19,20 @@ static void cxlctl_close_uctx(struct fwctl_uctx *uctx)static void *cxlctl_info (struct fwctl_uctx *uctx,size_t *length) { -/* Place holder */ -return ERR_PTR (-EOPNOTSUPP ); +struct fwctl_device *fwctl = uctx->fwctl; +struct cxl_features_state *cxlfs =to_cxl_features_state (fwctl); +struct fwctl_info_cxl *info; + +if (!cxlfs->num_user_features) +return ERR_PTR (-EOPNOTSUPP ); + + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) +return ERR_PTR (-ENOMEM ); + + *length =sizeof (*info); + +return info; } static void *cxlctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope,
include/cxl/mailbox.h +1 -0
@@ -4,6 +4,7 @@#define __CXL_MBOX_H__#include <linux/rcuwait.h> #include <cxl/features.h> +#include <uapi/fwctl/cxl.h> #include <uapi/linux/cxl_mem.h> /**
include/uapi/fwctl/cxl.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2024, 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> + +/** +* struct fwctl_info_cxl - ioctl(FWCTL_INFO) out_device_data +* @reserved: Place older for future usages +*/ +struct fwctl_info_cxl { +__u32 reserved; +}; +#endif
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 10/16 cxl: Move cxl feature command structs to user header
In reply to Dave JiangIn preparation for cxl fwctl enabling, move data structures related to cxl feature commands to a user header file.
Reviewed-by; Jonathan Cameron <[email protected]>
--- include/cxl/features.h | 107 +------------------------------ include/uapi/cxl/features.h | 122 ++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 106 deletions(-) create mode 100644 include/uapi/cxl/features.h
include/cxl/features.h +1 -106
@@ -5,6 +5,7 @@#include <linux/uuid.h> #include <linux/fwctl.h> +#include <uapi/cxl/features.h> /* Feature UUIDs used by the kernel */ #define CXL_FEAT_PATROL_SCRUB_UUID \
@@ -74,112 +75,6 @@ struct cxl_features_state {struct cxl_feat_entry *entries; }; -/* Get Supported Features (0x500h) CXL r3.2 8.2.9.6.1 */ -struct cxl_mbox_get_sup_feats_in { -__le32 count; -__le16 start_idx; -u8 reserved[2 ]; -} __packed; - -/* CXL spec r3.2 Table 8-87 command effects */ -#define CXL_CMD_CONFIG_CHANGE_COLD_RESET BIT(0) -#define CXL_CMD_CONFIG_CHANGE_IMMEDIATE BIT(1) -#define CXL_CMD_DATA_CHANGE_IMMEDIATE BIT(2) -#define CXL_CMD_POLICY_CHANGE_IMMEDIATE BIT(3) -#define CXL_CMD_LOG_CHANGE_IMMEDIATE BIT(4) -#define CXL_CMD_SECURITY_STATE_CHANGE BIT(5) -#define CXL_CMD_BACKGROUND BIT(6) -#define CXL_CMD_BGCMD_ABORT_SUPPORTED BIT(7) -#define CXL_CMD_EFFECTS_VALID BIT(9) -#define CXL_CMD_CONFIG_CHANGE_CONV_RESET BIT(10) -#define CXL_CMD_CONFIG_CHANGE_CXL_RESET BIT(11) - -/* -* CXL spec r3.2 Table 8-109 -* Get Supported Features Supported Feature Entry -*/ -struct cxl_feat_entry { -uuid_t uuid; -__le16 id; -__le16 get_feat_size; -__le16 set_feat_size; -__le32 flags; -u8 get_feat_ver; -u8 set_feat_ver; -__le16 effects; -u8 reserved[18 ]; -} __packed; - -/* @flags field for 'struct cxl_feat_entry' */ -#define CXL_FEATURE_F_CHANGEABLE BIT(0) -#define CXL_FEATURE_F_PERSIST_FW_UPDATE BIT(4) -#define CXL_FEATURE_F_DEFAULT_SEL BIT(5) -#define CXL_FEATURE_F_SAVED_SEL BIT(6) - -/* -* CXL spec r3.2 Table 8-108 -* Get supported Features Output Payload -*/ -struct cxl_mbox_get_sup_feats_out { -__le16 num_entries; -__le16 supported_feats; -u8 reserved[4 ]; - struct cxl_feat_entry ents[] __counted_by_le(num_entries); -} __packed; - -/* -* Get Feature CXL spec r3.2 Spec 8.2.9.6.2 -*/ - -/* -* Get Feature input payload -* CXL spec r3.2 section 8.2.9.6.2 Table 8-99 -*/ -struct cxl_mbox_get_feat_in { -uuid_t uuid; -__le16 offset; -__le16 count; -u8 selection; -} __packed; - -/* Selection field for 'struct cxl_mbox_get_feat_in' */ -enum cxl_get_feat_selection { -CXL_GET_FEAT_SEL_CURRENT_VALUE , -CXL_GET_FEAT_SEL_DEFAULT_VALUE , -CXL_GET_FEAT_SEL_SAVED_VALUE , -CXL_GET_FEAT_SEL_MAX -}; - -/* -* Set Feature CXL spec r3.2 8.2.9.6.3 -*/ - -/* -* Set Feature input payload -* CXL spec r3.2 section 8.2.9.6.3 Table 8-101 -*/ -struct cxl_mbox_set_feat_hdr { -uuid_t uuid; -__le32 flags; -__le16 offset; -u8 version; -u8 rsvd[9 ]; -} __packed; - -/* Set Feature flags field */ -enum cxl_set_feat_flag_data_transfer { -CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER =0 , -CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER , -CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER , -CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER , -CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER , -CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX -}; - -#define CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK GENMASK(2, 0) - -#define CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET BIT(3) -struct cxl_mailbox ; size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, enum cxl_get_feat_selection selection,
include/uapi/cxl/features.h new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 11/16 cxl: Add support for fwctl RPC command to enable CXL feature commands
In reply to Dave Jiangfwctl provides a fwctl_ops->fw_rpc() callback in order to issue ioctls to a device. The cxl fwctl driver will start by supporting the CXL feature commands: Get Supported Features, Get Feature, and Set Feature.
The fw_rpc() callback provides 'enum fwctl_rpc_scope' parameter where it indicates the security scope of the call. The Get Supported Features and Get Feature calls can be executed with the scope of FWCTL_RPC_CONFIGRATION. The Set Feature call is gated by the effects of the feature reported by Get Supported Features call for the specific feature.
Only "get supported features" is supported in this patch. Additional commands will be added in follow on patches. "Get supported features" will filter the features that are exclusive to the kernel and only report out features that are not kernel only.
---
v2:
- Return -EINVAL for get_support_feature_info() instead of -ENOENT. (Dan)
- Set set_feat_size to 0 for kernel exclusive features.
- Just don't bother checking the valid (9) bit. (Dan)
- Reject if the reserved bits are set. (Dan)
--- drivers/cxl/core/mbox.c | 9 ++ drivers/cxl/cxl.h | 1 + drivers/cxl/fwctl.c | 204 +++++++++++++++++++++++++++++++++++- include/cxl/features.h | 9 +- include/uapi/cxl/features.h | 1 + include/uapi/fwctl/cxl.h | 37 +++++++ 6 files changed, 250 insertions(+), 11 deletions(-)
drivers/cxl/core/mbox.c +9 -0
@@ -92,6 +92,15 @@ int cxl_get_feature_command_id(u16 opcode) }EXPORT_SYMBOL_NS_GPL (cxl_get_feature_command_id,"CXL" ); +u16 cxl_get_feature_command_opcode (int feature_id) +{ +if (feature_id >=ARRAY_SIZE (cxl_feature_commands)) +return 0xffff ; + +return cxl_feature_commands[feature_id]; +} +EXPORT_SYMBOL_NS_GPL (cxl_get_feature_command_opcode,"CXL" ); +/* * Commands that RAW doesn't permit. The rationale for each: *
drivers/cxl/cxl.h +1 -0
@@ -912,6 +912,7 @@ void cxl_coordinates_combine(struct access_coordinate *out,bool cxl_endpoint_decoder_reset_detected (struct cxl_port *port);int cxl_get_feature_command_id (u16 opcode); +u16 cxl_get_feature_command_opcode (int feature_id);/* * Unit test builds overrides this to __weak, find the 'strong' version
drivers/cxl/fwctl.c +201 -3
212 lines not on this page · raw message
include/cxl/features.h +1 -8
@@ -42,14 +42,6 @@struct cxl_mailbox ; -/* Index IDs for CXL mailbox Feature commands */ -enum feature_cmds { -CXL_FEATURE_ID_GET_SUPPORTED_FEATURES =0 , -CXL_FEATURE_ID_GET_FEATURE , -CXL_FEATURE_ID_SET_FEATURE , -CXL_FEATURE_ID_MAX -}; -/* Feature commands capability supported by a device */ enum cxl_features_capability {CXL_FEATURES_NONE =0 ,
@@ -83,5 +75,6 @@ size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,int cxl_set_feature (struct cxl_mailbox *cxl_mbox,const uuid_t *feat_uuid,u8 feat_version,void *feat_data,size_t feat_data_size,u32 feat_flag,u16 offset,u16 *return_code); +bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);#endif
include/uapi/cxl/features.h +1 -0
@@ -33,6 +33,7 @@ struct cxl_mbox_get_sup_feats_in {#define CXL_CMD_EFFECTS_VALID BIT(9)#define CXL_CMD_CONFIG_CHANGE_CONV_RESET BIT(10)#define CXL_CMD_CONFIG_CHANGE_CXL_RESET BIT(11) +#define CXL_CMD_EFFECTS_RESERVED GENMASK(15, 12)/* * CXL spec r3.2 Table 8-109
include/uapi/fwctl/cxl.h +37 -0
@@ -16,4 +16,41 @@struct fwctl_info_cxl {__u32 reserved; }; + +/** +* struct fwctl_rpc_cxl - ioctl(FWCTL_RPC) input for CXL +* @command_id: the defined command id by 'enum feature_cmds' +* @flags: Flags for the command (input). +* @op_size: Size of input payload. +* @reserved1: Reserved. Must be 0s. +* @in_payload: User address of the hardware op input structure +*/ +struct fwctl_rpc_cxl { +__u32 command_id; +__u32 flags; +__u32 op_size; +__u32 reserved1; +__aligned_u64 in_payload; +}; + +/* command_id for CXL mailbox Feature commands */ +enum feature_cmds { +CXL_FEATURE_ID_GET_SUPPORTED_FEATURES =0 , +CXL_FEATURE_ID_GET_FEATURE , +CXL_FEATURE_ID_SET_FEATURE , +CXL_FEATURE_ID_MAX +}; + +/** +* struct fwctl_rpc_cxl_out - ioctl(FWCTL_RPC) output for CXL +* @size: Size of the output payload +* @retval: Return value from device +* @payload: Return data from device +*/ +struct fwctl_rpc_cxl_out { +__u32 size; +__u32 retval; + __u8 payload[] __counted_by(size); +}; +#endif
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 12/16 cxl: Add support to handle user feature commands for get feature
In reply to Dave JiangAdd helper function to parse the user data from fwctl RPC ioctl and send the parsed input parameters to cxl_get_feature() call.
---
v2:
- Use rpc_out->payload inline. (Jonathan)
- Adjust to new cxl_get_feature() input params.
--- drivers/cxl/fwctl.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/cxl/fwctl.c +46 -0
@@ -134,6 +134,51 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,return no_free_ptr (rpc_out); } +static void *cxlctl_get_feature (struct cxl_features_state *cxlfs, +const struct fwctl_rpc_cxl *rpc_in, +size_t *out_len) +{ +struct cxl_dev_state *cxlds = cxlfs->cxlmd->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; +struct cxl_mbox_get_feat_in feat_in; +u16 offset, count, return_code; +size_t out_size = *out_len; + +if (rpc_in->op_size !=sizeof (feat_in)) +return ERR_PTR (-EINVAL ); + +if (copy_from_user (&feat_in,u64_to_user_ptr (rpc_in->in_payload), + rpc_in->op_size)) +return ERR_PTR (-EFAULT ); + + offset =le16_to_cpu (feat_in.offset); + count =le16_to_cpu (feat_in.count); + +if (!count) +return ERR_PTR (-EINVAL ); + + struct fwctl_rpc_cxl_out *rpc_out __free(kvfree) = +kvzalloc (out_size,GFP_KERNEL ); +if (!rpc_out) +return ERR_PTR (-ENOMEM ); + + out_size =cxl_get_feature (cxl_mbox, &feat_in.uuid, + feat_in.selection, rpc_out->payload, + count, offset, &return_code); + *out_len =sizeof (struct fwctl_rpc_cxl_out ); +if (!out_size) { + rpc_out->size =0 ; + rpc_out->retval = return_code; +return no_free_ptr (rpc_out); + } + + rpc_out->size = out_size; + rpc_out->retval =CXL_MBOX_CMD_RC_SUCCESS ; + *out_len += out_size; + +return no_free_ptr (rpc_out); +} +static bool cxlctl_validate_set_features (struct cxl_features_state *cxlfs,const struct fwctl_rpc_cxl *rpc_in,enum fwctl_rpc_scope scope)
@@ -216,6 +261,7 @@ static void *cxlctl_handle_commands(struct cxl_features_state *cxlfs,case CXL_MBOX_OP_GET_SUPPORTED_FEATURES :return cxlctl_get_supported_features (cxlfs, rpc_in, out_len);case CXL_MBOX_OP_GET_FEATURE : +return cxlctl_get_feature (cxlfs, rpc_in, out_len);case CXL_MBOX_OP_SET_FEATURE :default :return ERR_PTR (-EOPNOTSUPP );
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 13/16 cxl: Add support to handle user feature commands for set feature
In reply to Dave JiangAdd helper function to parse the user data from fwctl RPC ioctl and send the parsed input parameters to cxl_set_feature() call.
---
v2:
- Adjust to new cxl_set_feature() input params.
- Add check for exclusive feature during Set Feature call
--- drivers/cxl/core/features.c | 18 ++++++++----- drivers/cxl/features.h | 1 + drivers/cxl/fwctl.c | 53 +++++++++++++++++++++++++++++++++++++ include/uapi/cxl/features.h | 5 ++++ 4 files changed, 71 insertions(+), 6 deletions(-)
drivers/cxl/core/features.c +12 -6
@@ -20,6 +20,17 @@ static const uuid_t cxl_exclusive_feats[] = { CXL_FEAT_RANK_SPARING_UUID, }; +bool is_cxl_feature_exclusive_by_uuid (uuid_t *uuid) +{ +for (int i =0 ; i <ARRAY_SIZE (cxl_exclusive_feats); i++) { +if (uuid_equal (uuid, &cxl_exclusive_feats[i])) +return true; + } + +return false; +} +EXPORT_SYMBOL_NS_GPL (is_cxl_feature_exclusive_by_uuid,"CXL" ); +/** * is_cxl_feature_exclusive() - Check if a CXL feature is exclusive to kernel * @entry: cxl feature entry
@@ -28,12 +39,7 @@ static const uuid_t cxl_exclusive_feats[] = {*/ bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry) { -for (int i =0 ; i <ARRAY_SIZE (cxl_exclusive_feats); i++) { -if (uuid_equal (&entry->uuid, &cxl_exclusive_feats[i])) -return true; - } - -return false; +return is_cxl_feature_exclusive_by_uuid (&entry->uuid); }EXPORT_SYMBOL_NS_GPL (is_cxl_feature_exclusive,"CXL" );
drivers/cxl/features.h +1 -0
@@ -8,6 +8,7 @@ struct cxl_feat_entry;struct cxl_features_state *devm_cxlfs_allocate (struct cxl_memdev *cxlmd);void devm_cxlfs_free (struct cxl_memdev *cxlmd);int devm_cxl_add_features (struct cxl_memdev *cxlmd); +bool is_cxl_feature_exclusive_by_uuid (uuid_t *uuid);bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);#endif
drivers/cxl/fwctl.c +53 -0
65 lines not on this page · raw message
include/uapi/cxl/features.h +5 -0
@@ -107,6 +107,11 @@ struct cxl_mbox_set_feat_hdr {__u8 rsvd[9 ]; } __attribute__ ((__packed__)); +struct cxl_mbox_set_feat_in { +struct cxl_mbox_set_feat_hdr hdr; +__u8 data[]; +} __attribute__ ((__packed__ )); +/* Set Feature flags field */ enum cxl_set_feat_flag_data_transfer {CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER =0 ,
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 14/16 cxl/test: Add Get Feature support to cxl_test
In reply to Dave JiangAdd emulation of Get Feature command to cxl_test. The feature for device patrol scrub is returned by the emulation code. This is the only feature currently supported by cxl_test. It returns the information for the device patrol scrub feature.
--- tools/testing/cxl/test/mem.c | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
tools/testing/cxl/test/mem.c +56 -0
@@ -48,6 +48,10 @@ static struct cxl_cel_entry mock_cel[] = { .opcode = cpu_to_le16(CXL_MBOX_OP_GET_SUPPORTED_FEATURES), .effect = CXL_CMD_EFFECT_NONE, }, + { + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_FEATURE), + .effect = CXL_CMD_EFFECT_NONE, + }, { .opcode = cpu_to_le16(CXL_MBOX_OP_IDENTIFY), .effect = CXL_CMD_EFFECT_NONE,
@@ -149,6 +153,10 @@ struct mock_event_store {u32 ev_status; }; +struct vendor_test_feat { +__le32 data; +} __packed; +struct cxl_mockmem_data {void *lsa;void *fw;
@@ -165,6 +173,7 @@ struct cxl_mockmem_data {u8 event_buf[SZ_4K ];u64 timestamp;unsigned long sanitize_timeout; +struct vendor_test_feat test_feat; };static struct mock_event_log *event_find_log (struct device *dev,int log_type)
@@ -1360,6 +1369,44 @@ static void fill_feature_vendor_test(struct cxl_feat_entry *feat) CXL_CMD_EFFECTS_VALID); } +static int mock_get_test_feature (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct vendor_test_feat *output = cmd->payload_out; +struct cxl_mbox_get_feat_in *input = cmd->payload_in; +u16 offset =le16_to_cpu (input->offset); +u16 count =le16_to_cpu (input->count); +u8 *ptr; + +if (offset >sizeof (*output)) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + } + +if (offset + count >sizeof (*output)) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + } + + ptr = (u8 *)&mdata->test_feat + offset; +memcpy ((u8 *)output + offset, ptr, count); + +return 0 ; +} + +static int mock_get_feature (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct cxl_mbox_get_feat_in *input = cmd->payload_in; + +if (uuid_equal (&input->uuid, &CXL_VENDOR_FEATURE_TEST )) +return mock_get_test_feature (mdata, cmd); + + cmd->return_code =CXL_MBOX_CMD_RC_UNSUPPORTED ; + +return -EOPNOTSUPP ; +} +static int mock_get_supported_features (struct cxl_mockmem_data *mdata,struct cxl_mbox_cmd *cmd) {
@@ -1490,6 +1537,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,case CXL_MBOX_OP_GET_SUPPORTED_FEATURES : rc =mock_get_supported_features (mdata, cmd);break ; +case CXL_MBOX_OP_GET_FEATURE : + rc =mock_get_feature (mdata, cmd); +break ;default :break ; }
@@ -1537,6 +1587,11 @@ static int cxl_mock_mailbox_create(struct cxl_dev_state *cxlds)return 0 ; } +static void cxl_mock_test_feat_init (struct cxl_mockmem_data *mdata) +{ + mdata->test_feat.data =cpu_to_le32 (0xdeadbeef ); +} +static int cxl_mock_mem_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -1624,6 +1679,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)return rc;cxl_mem_get_event_records (mds,CXLDEV_EVENT_STATUS_ALL ); +cxl_mock_test_feat_init (mdata);return 0 ; }
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 15/16 cxl/test: Add Set Feature support to cxl_test
In reply to Dave JiangAdd emulation to support Set Feature mailbox command to cxl_test. The only feature supported is the device patrol scrub feature. The set feature allows activation of patrol scrub for the cxl_test emulated device. The command does not support partial data transfer even though the spec allows it. This restriction is to reduce complexity of the emulation given the patrol scrub feature is very minimal.
--- tools/testing/cxl/test/mem.c | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/cxl/test/mem.c +50 -0
@@ -52,6 +52,10 @@ static struct cxl_cel_entry mock_cel[] = { .opcode = cpu_to_le16(CXL_MBOX_OP_GET_FEATURE), .effect = CXL_CMD_EFFECT_NONE, }, + { + .opcode = cpu_to_le16(CXL_MBOX_OP_SET_FEATURE), + .effect = cpu_to_le16(EFFECT(CONF_CHANGE_IMMEDIATE)), + }, { .opcode = cpu_to_le16(CXL_MBOX_OP_IDENTIFY), .effect = CXL_CMD_EFFECT_NONE,
@@ -1407,6 +1411,49 @@ static int mock_get_feature(struct cxl_mockmem_data *mdata,return -EOPNOTSUPP ; } +static int mock_set_test_feature (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct cxl_mbox_set_feat_in *input = cmd->payload_in; +struct vendor_test_feat *test = (struct vendor_test_feat *)input->data; +u32 action; + + action =FIELD_GET (CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK , +le32_to_cpu (input->hdr.flags)); +/* +* While it is spec compliant to support other set actions, it is not +* necessary to add the complication in the emulation currently. Reject +* anything besides full xfer. +*/ +if (action !=CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER ) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + } + +/* Offset should be reserved when doing full transfer */ +if (input->hdr.offset) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + } + +memcpy (&mdata->test_feat.data, &test->data,sizeof (u32)); + +return 0 ; +} + +static int mock_set_feature (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct cxl_mbox_set_feat_in *input = cmd->payload_in; + +if (uuid_equal (&input->hdr.uuid, &CXL_VENDOR_FEATURE_TEST )) +return mock_set_test_feature (mdata, cmd); + + cmd->return_code =CXL_MBOX_CMD_RC_UNSUPPORTED ; + +return -EOPNOTSUPP ; +} +static int mock_get_supported_features (struct cxl_mockmem_data *mdata,struct cxl_mbox_cmd *cmd) {
@@ -1540,6 +1587,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,case CXL_MBOX_OP_GET_FEATURE : rc =mock_get_feature (mdata, cmd);break ; +case CXL_MBOX_OP_SET_FEATURE : + rc =mock_set_feature (mdata, cmd); +break ;default :break ; }
Signature · 1 line
2.48.1
Dave Jiang
maintainerPATCH v2 16/16 fwctl/cxl: Add documentation to FWCTL CXL
In reply to Dave JiangAdd policy and operational documentation for FWCTL CXL.
---
v2:
- Various corrections. (Dan)
- Add sample code for ioctl. (Dan)
- Update to reflect changes from driver code review.
--- .../userspace-api/fwctl/fwctl-cxl.rst | 135 ++++++++++++++++++ Documentation/userspace-api/fwctl/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 137 insertions(+) create mode 100644 Documentation/userspace-api/fwctl/fwctl-cxl.rst
Documentation/userspace-api/fwctl/fwctl-cxl.rst new file +135 -0
@@ -0,0 +1,135 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================ +fwctl cxl driver +================ + +:Author: Dave Jiang + +Overview +======== + +The CXL spec defines a set of commands that can be issued to the mailbox of a +CXL device or switch. It also left room for vendor specific commands to be +issued to the mailbox as well. fwctl provides a path to issue a set of allowed +mailbox commands from user space to the device moderated by the kernel driver. + +The following 3 commands will be used to support CXL Features: +CXL spec r3.1 8.2.9.6.1 Get Supported Features (Opcode 0500h) +CXL spec r3.1 8.2.9.6.2 Get Feature (Opcode 0501h) +CXL spec r3.1 8.2.9.6.3 Set Feature (Opcode 0502h) + +The "Get Supported Features" return data may be filtered by the kernel driver to +drop any features that are forbidden by the kernel or being exclusively used by +the kernel. The "Get Supported Features" command and the "Get Features" falls +under the fwctl policy of FWCTL_RPC_CONFIGURATION. + +For "Set Feature" command, the access policy currently is broken down into two +categories depending on the Set Feature effects reported by the device. If the +Set Feature will cause immediate change to the device, the fwctl access policy +must be FWCTL_RPC_DEBUG_WRITE_FULL. The effects for this level are +"immediate config change", "immediate data change", "immediate policy change", +or "immediate log change" for the set effects mask. If the effects are "config +change with cold reset" or "config change with conventional reset", then the +fwctl access policy must be FWCTL_RPC_DEBUG_WRITE or higher. + +fwctl cxl User API +================== + +.. kernel-doc:: include/uapi/fwctl/cxl.h +.. kernel-doc:: include/uapi/cxl/features.h + +1. Driver info query +-------------------- + +First step for the app is to issue the ioctl(FWCTL_CMD_INFO). Successful +invocation of the ioctl implies the Features capability is operational and +returns an all zeros 32bit payload. A ``struct fwctl_info`` needs to be filled +out with the ``fwctl_info.out_device_type`` set to ``FWCTL_DEVICE_TYPE_CXL``. +The return data should be ``struct fwctl_info_cxl`` that contains a reserved +32bit field that should be all zeros. + +2. Send hardware commands +------------------------- + +Next step is to send the 'Get Supported Features' command to the driver from +user space via ioctl(FWCTL_RPC). A ``struct fwctl_rpc_cxl`` is pointed to +by ``fwctl_rpc.in``. ``struct fwctl_rpc_cxl.in_payload`` points to +the hardware input structure that is defined by the CXL spec. ``fwctl_rpc.out`` +points to the buffer that contains a ``struct fwctl_rpc_cxl_out`` that includes +the hardware output data inlined as ``fwctl_rpc_cxl_out.payload``. This command +is called twice. First time to retrieve the number of features supported. +A second time to retrieve the specific feature details as the output data. + +After getting the specific feature details, a Get/Set Feature command can be +appropriately programmed and sent. For a "Set Feature" command, the retrieved +feature info contains an effects field that details the resulting +"Set Feature" command will trigger. That will inform the user whether +the system is configured to allowed the "Set Feature" command or not. + +Code example of a Get Feature +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: c + + static int cxl_fwctl_rpc_get_test_feature(int fd, struct test_feature *feat_ctx, + const uint32_t expected_data) + { + struct cxl_mbox_get_feat_in feat_in __attribute__((aligned(16))) = {0}; + struct fwctl_rpc_cxl in __attribute__((aligned(16))) = {0}; + struct fwctl_rpc_cxl_out *out; + struct fwctl_rpc rpc = {0}; + size_t out_size; + uint32_t val; + void *data; + int rc; + + uuid_copy(feat_in.uuid, feat_ctx->uuid); + feat_in.count = feat_ctx->get_size; + + out_size = sizeof(*out) + feat_in.count; + out = aligned_alloc(16, out_size); + if (!out) + return -ENOMEM; + + memset(out, 0, out_size); + data = out->payload; + + in.command_id = CXL_FEATURE_ID_GET_FEATURE; + in.op_size = sizeof(feat_in); + in.in_payload = (uint64_t)(uint64_t *)&feat_in; + + rpc.size = sizeof(rpc); + rpc.scope = FWCTL_RPC_CONFIGURATION; + rpc.in_len = sizeof(in); + rpc.out_len = out_size; + rpc.in = (uint64_t)(uint64_t *)∈ + rpc.out = (uint64_t)(uint64_t *)out; + + rc = send_command(fd, &rpc, out); + if (rc) + goto out; + + val = le32toh(*(__le32 *)data); + if (memcmp(&val, &expected_data, sizeof(val)) != 0) { + rc = -ENXIO; + goto out; + } + + out: + free(out); + return rc; + } + +It is recommended to take a look at CXL CLI test directory +<https://github.com/pmem/ndctl/tree/main/test/fwctl.c> for a detailed user code +example on how to exercise this path. + + +fwctl cxl Kernel API +==================== + +.. kernel-doc:: drivers/cxl/core/features.c +.. kernel-doc:: drivers/cxl/features.c + :export: +.. kernel-doc:: include/cxl/features.h
Documentation/userspace-api/fwctl/index.rst +1 -0
@@ -10,3 +10,4 @@ to securely construct and execute RPCs inside device firmware. :maxdepth: 1 fwctl + fwctl-cxl
MAINTAINERS +1 -0
@@ -5773,6 +5773,7 @@ M: Dan Williams <[email protected]> L: [email protected] S: Maintained F: Documentation/driver-api/cxl +F: Documentation/userspace-api/fwctl/fwctl-cxl.rst F: drivers/cxl/ F: include/cxl/ F: include/uapi/linux/cxl_mem.h
Signature · 1 line
2.48.1
Dave Jiang
maintainerRe: [PATCH v2 08/16] cxl: Add FWCTL support to the CXL memdev driver
In reply to Dave JiangQuoted 29 lines · Dave Jiang
Add fwctl support code to allow sending of CXL feature commands from userspace through as ioctls via FWCTL. Provide initial setup bits.
Signed-off-by Dave Jiang <[email protected]>---
v2:
- Associate FWCTL with the 'cxl_memdev' through the memdev driver. (Dan)
- I'm leaving Jonathan's tag off to get this looked at again.
- Hide FWCTL code behindCONFIG_CXL_FWCTL(Dan)--- drivers/cxl/Kconfig | 15 +++++++ drivers/cxl/Makefile | 1 + drivers/cxl/features.c | 35 ++++++++++++--- drivers/cxl/features.h | 2 + drivers/cxl/fwctl.c | 88 ++++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 3 ++ include/uapi/fwctl/fwctl.h | 1 + tools/testing/cxl/Kbuild | 1 + 8 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 drivers/cxl/fwctl.cdrivers/cxl/Kconfig +0
-0@@ -102,6 +102,21 @@ config CXL_MEM If unsure say 'm'.
drivers/cxl/Kconfig config CXL_MEM · line 114
Quoted 10 lines
drivers/cxl/Kconfig +10
-0+config CXL_FWCTL + bool "CXL: Firmware Control support" + depends on CXL_MEM + select FWCTL + help + Enable support for firmware control of CXL devices. This allows + a FWCTL char device to be created in order to issue ioctls from + user space to exercise the CXL Features commands supported by + a CXL mailbox. There are some Features defined in the CXL spec + such as memory sparing. However a lof of those features are
s/lof/lot/
drivers/cxl/Kconfig config CXL_MEM · line 115
Quoted 1 line
drivers/cxl/Kconfig +1
-0+ exclusive to the kernel. Most likely the Features maniulated
s/maniulated/manipulated/
wonder why checkpatch did not catch these but caught others
Quoted 22 lines
drivers/cxl/Kconfig +4
-0+ by CXL_FWCTL will be vendor defined Features. + + If unsure say 'n'. + config CXL_PORT default CXL_BUS tristatedrivers/cxl/Makefile +1
-0@@ -18,4 +18,5 @@ cxl_port-y := port.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o security.o cxl_mem-y := mem.o features.o +cxl_mem-$(CONFIG_CXL_FWCTL) += fwctl.o cxl_pci-y := pci.odrivers/cxl/features.c +0
-0
drivers/cxl/features.c line 8
Quoted 8 lines
drivers/cxl/features.c +3
-0@@ -1,8 +1,11 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */ +#include <linux/pci.h> #include <linux/device.h> +#include <linux/module.h> #include <cxl/mailbox.h> #include <cxl/features.h> +
stray blank line, will remove
DJ
Quoted 220 lines
drivers/cxl/features.c +26
-6#include "cxl.h" #include "cxlmem.h" #include "features.h" @@ -168,11 +171,31 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, cxlfs->cap =CXL_FEATURES_RW ; } +/* The __weak symbol gets replaced by FWCTL allocation function in fwctl.c */ +struct cxl_features_state *__weak devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{ +struct device *dev = &cxlmd->dev; +struct cxl_features_state *cxlfs = +devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); + +if (!cxlfs) +return ERR_PTR (-ENOMEM ); + + cxlfs->cxlmd = cxlmd; + +return cxlfs; +} + +/* The __weak symbol gets replaced by FWCTL free function in fwctl.c */ +void __weak devm_cxlfs_free (struct cxl_memdev *cxlmd) +{ +devm_kfree (&cxlmd->dev, cxlmd->cxlfs); + cxlmd->cxlfs =NULL ; +} +static void cxl_cxlfs_free (struct cxl_features_state *cxlfs) { -struct device *dev = &cxlfs->cxlmd->dev; - -devm_kfree (dev, cxlfs); +devm_cxlfs_free (cxlfs->cxlmd); } DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))@@ -185,15 +208,13 @@ DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))*/ int devm_cxl_add_features (struct cxl_memdev *cxlmd) { -struct device *dev = &cxlmd->dev;int rc; struct cxl_features_state *cxlfs __free(free_cxlfs) = -devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); +devm_cxlfs_allocate (cxlmd);if (!cxlfs)return -ENOMEM ; - cxlfs->cxlmd = cxlmd;enumerate_feature_cmds (cxlmd, cxlfs); rc =get_supported_features (cxlmd, cxlfs);if (rc)@@ -204,3 +225,5 @@ int devm_cxl_add_features(struct cxl_memdev *cxlmd)return 0 ; }EXPORT_SYMBOL_NS_GPL (devm_cxl_add_features,"CXL" ); + +MODULE_IMPORT_NS ("CXL" );drivers/cxl/features.h +2
-0@@ -5,6 +5,8 @@struct cxl_feat_entry ; +struct cxl_features_state *devm_cxlfs_allocate (struct cxl_memdev *cxlmd); +void devm_cxlfs_free (struct cxl_memdev *cxlmd);int devm_cxl_add_features (struct cxl_memdev *cxlmd);bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);drivers/cxl/fwctl.c new file +88
-0@@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2025 Intel Corporation. All rights reserved. */ +#include <linux/fwctl.h> +#include <linux/device.h> +#include <cxl/features.h> +#include "cxlmem.h" +#include "features.h" + +static int cxlctl_open_uctx (struct fwctl_uctx *uctx) +{ +return 0 ; +} + +static void cxlctl_close_uctx (struct fwctl_uctx *uctx) +{ +} + +static void *cxlctl_info (struct fwctl_uctx *uctx,size_t *length) +{ +/* Place holder */ +return ERR_PTR (-EOPNOTSUPP ); +} + +static void *cxlctl_fw_rpc (struct fwctl_uctx *uctx,enum fwctl_rpc_scope scope, +void *rpc_in,size_t in_len,size_t *out_len) +{ +/* Place holder */ +return ERR_PTR (-EOPNOTSUPP ); +} + +static const struct fwctl_ops cxlctl_ops = { + .device_type =FWCTL_DEVICE_TYPE_CXL , + .uctx_size =sizeof (struct fwctl_uctx ), + .open_uctx = cxlctl_open_uctx, + .close_uctx = cxlctl_close_uctx, + .info = cxlctl_info, + .fw_rpc = cxlctl_fw_rpc, +}; + +static void remove_cxlfs (void *_cxlfs) +{ +struct cxl_features_state *cxlfs = _cxlfs; +struct cxl_memdev *cxlmd = cxlfs->cxlmd; +struct fwctl_device *fwctl = &cxlfs->fwctl; + + cxlmd->cxlfs =NULL ; +fwctl_unregister (fwctl); +fwctl_put (fwctl); +} + +DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) fwctl_put(&_T->fwctl)) + +static struct cxl_features_state * +__devm_cxl_cfs_allocate (struct cxl_memdev *cxlmd,const struct fwctl_ops *ops) +{ +struct device *dev = &cxlmd->dev; +int rc; + + struct cxl_features_state *cxlfs __free(free_cxlfs) = + fwctl_alloc_device(dev, ops, struct cxl_features_state, fwctl); +if (!cxlfs) +return ERR_PTR (-ENOMEM ); + + cxlfs->cxlmd = cxlmd; + rc =fwctl_register (&cxlfs->fwctl); +if (rc) +return ERR_PTR (rc); + + rc =devm_add_action_or_reset (dev, remove_cxlfs, cxlfs); +if (rc) +return ERR_PTR (rc); + +return no_free_ptr (cxlfs); +} + +struct cxl_features_state *devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{ +return __devm_cxl_cfs_allocate (cxlmd, &cxlctl_ops); +} +EXPORT_SYMBOL_NS_GPL (devm_cxlfs_allocate,"CXL" ); + +void devm_cxlfs_free (struct cxl_memdev *cxlmd) +{ +devm_release_action (&cxlmd->dev, remove_cxlfs, cxlmd); +} +EXPORT_SYMBOL_NS_GPL (devm_cxlfs_free,"CXL" ); + +MODULE_IMPORT_NS ("FWCTL" );include/cxl/features.h +3
-0@@ -4,6 +4,7 @@#define __CXL_FEATURES_H__#include <linux/uuid.h> +#include <linux/fwctl.h> /* Feature UUIDs used by the kernel */ #define CXL_FEAT_PATROL_SCRUB_UUID \@@ -57,6 +58,7 @@ enum cxl_features_capability {/** * struct cxl_features_state - The Features state for the device +* @fwctl: FWCTL device * @cxlmd: Pointer to cxl mem device * @cap: Feature commands capability * @num_features: total Features supported by the device @@ -64,6 +66,7 @@ enum cxl_features_capability {* @entries: Feature detail entries fetched from the device */ struct cxl_features_state { +struct fwctl_device fwctl;struct cxl_memdev *cxlmd;enum cxl_features_capability cap;int num_features;include/uapi/fwctl/fwctl.h +1
-0@@ -43,6 +43,7 @@ enum {enum fwctl_device_type {FWCTL_DEVICE_TYPE_ERROR =0 ,FWCTL_DEVICE_TYPE_MLX5 =1 , +FWCTL_DEVICE_TYPE_CXL =2 , };/** tools/testing/cxl/Kbuild +1
-0@@ -47,6 +47,7 @@ cxl_port-y += cxl_port_test.o obj-m += cxl_mem.o cxl_mem-y := $(CXL_SRC)/mem.o $(CXL_SRC)/features.o +cxl_mem-$(CONFIG_CXL_FWCTL) += $(CXL_SRC)/fwctl.o cxl_mem-y += config_check.o cxl_mem-y += cxl_mem_test.o
Re: [PATCH v2 02/16] cxl: Enumerate feature commands
In reply to Dave JiangQuoted 6 lines · On Fri, 31 Jan 2025 17:41:55 -0700 Dave Jiang <[email protected]> wrote:
Add feature commands enumeration code in order to detect and enumerate the 3 feature related commands "get supported features", "get feature", and "set feature". The enumeration will help determine whether the driver can issue any of the 3 commands to the device.
Signed-off-by Dave Jiang <[email protected]>
Quoted 9 lines
---
v2:
- Setup allocation of cxlfs and move enumeration of commands to the setup function.
- Introducefeatures_capabilityenum. (Dan)
- Name the setup functiondevm_cxl_add_features(). (Dan)
- Drop 'cxl_mem_command' support. (Dan)
- Move feature support to mem probe. (Dan)
- Remove comma at last entry of data structs. (Jonathan)
Got carried away on this one. Only drop them for termination
entries. So MAX or NULL or similar.
drivers/cxl/core/mbox.c static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { · line 75
Quoted 12 lines
drivers/cxl/core/mbox.c +4
-0@@ -69,6 +69,29 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { CXL_CMD(GET_TIMESTAMP, 0, 0x8, 0), }; +static u16 cxl_feature_commands[] = { +CXL_MBOX_OP_GET_SUPPORTED_FEATURES , +CXL_MBOX_OP_GET_FEATURE , +CXL_MBOX_OP_SET_FEATURE
This one does want a trailing comma. Might be more feature commands in future.
Quoted 12 lines
drivers/cxl/core/mbox.c +1
-0+};drivers/cxl/features.c new file +4
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */ +#include <linux/device.h> +#include <cxl/mailbox.h>
drivers/cxl/features.c line 14
Quoted 10 lines
drivers/cxl/features.c new file +10
-0+#include <cxl/features.h> +#include "cxl.h" +#include "cxlmem.h" +#include "features.h" + +static void enumerate_feature_cmds (struct cxl_memdev *cxlmd) +{ +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; +struct cxl_features_state *cxlfs = cxlds->cxlmd->cxlfs;
Going in circles?
cxlmd->cxlfs;
Quoted 25 lines
drivers/cxl/features.c new file +25
-0+int fid; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_SUPPORTED_FEATURES ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_FEATURE ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + cxlfs->cap =CXL_FEATURES_RO ; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_SET_FEATURE ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + cxlfs->cap =CXL_FEATURES_RW ; +} + +/** +* devm_cxl_add_features() - Allocate and initialize features context +* @cxlmd: CXL memory device +* +* Return 0 on success or -errno on failure. +*/
drivers/cxl/features.c line 49
Quoted 10 lines
drivers/cxl/features.c new file +10
-0+int devm_cxl_add_features (struct cxl_memdev *cxlmd) +{ +struct cxl_features_state *cxlfs; +struct device *dev = &cxlmd->dev; + + cxlfs =devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); +if (!cxlfs) +return -ENOMEM ; + + cxlmd->cxlfs = cxlfs;
So I was curious about this one and why we leave the pointer hanging in the remove path + whether the two way pointer nest is needed.
That gets dealt with in patch 8.
I'd be tempted to drag the bones of dev_cxlfs_allocate() to this patch so that you can do that cleanup now and avoid some of the churn of the later patches.
As for the two way pointer nest. I'm not sure it is needed. Seems like most if not all places we use cxlmd->cxlfs have just gotten it in the caller from cxlfs->cxlmd. e.g. cxl_cxlfs_free() in patch 8. For here we could just pass it into enumerate_feature_cmds.
Maybe Shiju's set needs it. I haven't checked.
Quoted 23 lines
drivers/cxl/features.c new file +6
-0+ cxlfs->cxlmd = cxlmd; +enumerate_feature_cmds (cxlmd); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (devm_cxl_add_features,"CXL" );include/cxl/features.h new file +10
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2024-2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_H__ +#define __CXL_FEATURES_H__ + +struct cxl_mailbox ; + +/* Index IDs for CXL mailbox Feature commands */ +enum feature_cmds { + CXL_FEATURE_ID_GET_SUPPORTED_FEATURES = 0,
include/cxl/features.h line 20
Quoted 10 lines
include/cxl/features.h new file +10
-0+CXL_FEATURE_ID_GET_FEATURE , +CXL_FEATURE_ID_SET_FEATURE , +CXL_FEATURE_ID_MAX +}; + +/* Feature commands capability supported by a device */ +enum cxl_features_capability { +CXL_FEATURES_NONE =0 , +CXL_FEATURES_RO , + CXL_FEATURES_RW
Trivial but this one should have a trailing comma. Maybe we'll have a write only one! Anyhow, it's not a terminating entry so we shouldn't assume nothing comes after it.
Quoted 15 lines
include/cxl/features.h new file +15
-0+}; + +/** +* struct cxl_features_state - The Features state for the device +* @cxlmd: Pointer to cxl mem device +* @cap: Feature commands capability +* @num_features: total Features supported by the device +*/ +struct cxl_features_state { +struct cxl_memdev *cxlmd; +enum cxl_features_capability cap; +int num_features; +}; + +#endif
Re: [PATCH v2 03/16] cxl: Add Get Supported Features command for kernel usage
In reply to Dave JiangQuoted 11 lines · On Fri, 31 Jan 2025 17:41:56 -0700 Dave Jiang <[email protected]> wrote:
CXL spec r3.2 8.2.9.6.1 Get Supported Features (Opcode 0500h) The command retrieve the list of supported device-specific features (identified by UUID) and general information about each Feature.
The driver will retrieve the feature entries in order to make checks and provide information for the Get Feature and Set Feature command. One of the main piece of information retrieved are the effects a Set Feature command would have for a particular feature.
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Quoted 7 lines
---
v2:
- Move to memdev driver and drop features driver support. (Dan)
- Usefeatures_capabilityto check what's supported. (Dan)
- Dropcxl_get_supported_feature_entry()as no usage (Dan, Jonathan)
- Drop Shiju sign off tags per requested. (Shiju)
- Rename EXTEND bit(9) to VALID. (Jonathan)
I've read this code too many times :(
Anyhow some feedback on stuff I think belongs in patch 2 and use of struct_size() to make the sizing calcs more obvious that I'd missed until now.
Quoted 7 lines
drivers/cxl/features.c +7
-0+static int get_supported_features (struct cxl_memdev *cxlmd, +struct cxl_features_state *cxlfs) +{ +int remain_feats, max_size, max_feats, start, rc, hdr_size; +struct cxl_mailbox *cxl_mbox = &cxlmd->cxlds->cxl_mbox; +int feat_size =sizeof (struct cxl_feat_entry ); +struct cxl_mbox_get_sup_feats_in mbox_in;
drivers/cxl/features.c line 56
Quoted 10 lines
drivers/cxl/features.c +10
-0+struct cxl_feat_entry *entry; +struct cxl_mbox_cmd mbox_cmd; +int count; + +if (cxlfs->cap <CXL_FEATURES_RO ) +return -EOPNOTSUPP ; + + count =cxl_get_supported_features_count (cxl_mbox); +if (count ==0 ) +return 0 ;
Not sure this should return 0. That will leave the cxlfs in place. + your outermost call in the mem driver prints a message saying nothing found only if an error is returned.
Quoted 4 lines
drivers/cxl/features.c +4
-0+if (count <0 ) +return -ENXIO ; + + struct cxl_feat_entry *entries __free(kvfree) =
drivers/cxl/features.c line 70
Quoted 10 lines
drivers/cxl/features.c +10
-0+kvmalloc (count *sizeof (*entries),GFP_KERNEL ); +if (!entries) +return -ENOMEM ; + + struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) = +kvmalloc (cxl_mbox->payload_size,GFP_KERNEL ); +if (!mbox_out) +return -ENOMEM ; + + hdr_size =sizeof (*mbox_out);
May seem an odd request but can we make this struct_size(mbox_out, ents, 0)
as it seems odd to say how big is this thing we just allocated and get a smaller size (though correct given the trailing [] array)
drivers/cxl/features.c line 83
Quoted 13 lines
drivers/cxl/features.c +13
-0+ max_size = cxl_mbox->payload_size - hdr_size; +/* max feat entries that can fit in mailbox max payload size */ + max_feats = max_size / feat_size; + entry = entries; + + start =0 ; + remain_feats = count; + do { + int retrieved, alloc_size, copy_feats; + int num_entries; + + if (remain_feats > max_feats) { + alloc_size = sizeof(*mbox_out) + max_feats * feat_size;
alloc_size = struct_size(mbox_out, ents, max_feats);
drivers/cxl/features.c line 87
Quoted 4 lines
drivers/cxl/features.c +4
-0+ remain_feats = remain_feats - max_feats; + copy_feats = max_feats; + }else { + alloc_size =sizeof (*mbox_out) + remain_feats * feat_size;
alloc_size = struct_size(mbox_out, ents, remain_feats);
Quoted 47 lines
drivers/cxl/features.c +47
-0+ copy_feats = remain_feats; + remain_feats =0 ; + } + +memset (&mbox_in,0 ,sizeof (mbox_in)); + mbox_in.count =cpu_to_le32 (alloc_size); + mbox_in.start_idx =cpu_to_le16 (start); +memset (mbox_out,0 , alloc_size); + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_GET_SUPPORTED_FEATURES , + .size_in =sizeof (mbox_in), + .payload_in = &mbox_in, + .size_out = alloc_size, + .payload_out = mbox_out, + .min_out = hdr_size, + }; + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +if (rc <0 ) +return rc; + +if (mbox_cmd.size_out <= hdr_size) +return -ENXIO ; + +/* +* Make sure retrieved out buffer is multiple of feature +* entries. +*/ + retrieved = mbox_cmd.size_out - hdr_size; +if (retrieved % feat_size) +return -ENXIO ; + + num_entries =le16_to_cpu (mbox_out->num_entries); +/* +* If the reported output entries * defined entry size != +* retrieved output bytes, then the output package is incorrect. +*/ +if (num_entries * feat_size != retrieved) +return -ENXIO ; + +memcpy (entry, mbox_out->ents, retrieved); + entry++; +/* +* If the number of output entries is less than expected, add the +* remaining entries to the next batch. +*/ + remain_feats += copy_feats - num_entries; + start += num_entries;
drivers/cxl/features.c line 144
Quoted 10 lines
drivers/cxl/features.c +10
-0+ }while (remain_feats); + + cxlfs->num_features = count; + cxlfs->entries =no_free_ptr (entries); +return devm_add_action_or_reset (&cxlmd->dev, cxl_free_feature_entries, + cxlfs->entries); +} + +static void enumerate_feature_cmds (struct cxl_memdev *cxlmd, +struct cxl_features_state *cxlfs)
Good. Suggested this in previous.
drivers/cxl/features.c line 14
Quoted 4 lines
{
drivers/cxl/features.c +0
-1struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; -struct cxl_features_state *cxlfs = cxlds->cxlmd->cxlfs;
And you drop the circular line. Push this into patch 2.
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd) · line 171
Quoted 12 lines
drivers/cxl/features.c +5
-0int fid; fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_SUPPORTED_FEATURES );@@ -31,6 +164,15 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd) cxlfs->cap =CXL_FEATURES_RW ; } +static void cxl_cxlfs_free (struct cxl_features_state *cxlfs) +{ +struct device *dev = &cxlfs->cxlmd->dev; + +devm_kfree (dev, cxlfs);
As below. Let's bring cleanup here if we have to unset cxlmd->cxlfs later.
Quoted 8 lines
drivers/cxl/features.c +4
-0+} + +DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T)) +/** * devm_cxl_add_features() - Allocate and initialize features context * @cxlmd: CXL memory device
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd) · line 188
Quoted 10 lines
drivers/cxl/features.c +3
-2@@ -39,16 +181,21 @@ static void enumerate_feature_cmds(struct cxl_memdev *cxlmd)*/ int devm_cxl_add_features (struct cxl_memdev *cxlmd) { -struct cxl_features_state *cxlfs;struct device *dev = &cxlmd->dev; +int rc; - cxlfs =devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); + struct cxl_features_state *cxlfs __free(free_cxlfs) = +devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL );
This line changes 3 times in the series. Can we drag the last one here (as per comment on patch 2) by introducing the new allocate function at this point.
Quoted 15 lines
drivers/cxl/features.c +6
-2if (!cxlfs)return -ENOMEM ; - cxlmd->cxlfs = cxlfs; cxlfs->cxlmd = cxlmd; -enumerate_feature_cmds (cxlmd); +enumerate_feature_cmds (cxlmd, cxlfs); + rc =get_supported_features (cxlmd, cxlfs); +if (rc) +return rc; + + cxlmd->cxlfs =no_free_ptr (cxlfs);return 0 ; }
Re: [PATCH v2 04/16] cxl/test: Add Get Supported Features mailbox command support
In reply to Dave JiangQuoted 30 lines · On Fri, 31 Jan 2025 17:41:57 -0700 Dave Jiang <[email protected]> wrote:
Add cxl-test emulation of Get Supported Features mailbox command. Currently only adding a test feature with feature identifier of all f's for testing.
Reviewed-by Jonathan Cameron <[email protected]>Acked-by Dan Williams <[email protected]>Signed-off-by Dave Jiang <[email protected]>tools/testing/cxl/test/mem.c +21
-0+static int mock_get_supported_features (struct cxl_mockmem_data *mdata, +struct cxl_mbox_cmd *cmd) +{ +struct cxl_mbox_get_sup_feats_in *in = cmd->payload_in; +struct cxl_mbox_get_sup_feats_out *out = cmd->payload_out; +struct cxl_feat_entry *feat; +u16 start_idx, count; + +if (cmd->size_out <sizeof (*out)) { + cmd->return_code =CXL_MBOX_CMD_RC_PAYLOADLEN ; +return -EINVAL ; + } + +/* +* Current emulation only supports 1 feature +*/ + start_idx =le16_to_cpu (in->start_idx); +if (start_idx !=0 ) { + cmd->return_code =CXL_MBOX_CMD_RC_INPUT ; +return -EINVAL ; + }
tools/testing/cxl/test/mem.c static int mock_activate_fw(struct cxl_mockmem_data *mdata, · line 1393
Quoted 10 lines
tools/testing/cxl/test/mem.c +10
-0+ + count =le16_to_cpu (in->count); +if (count <sizeof (*out)) { + cmd->return_code =CXL_MBOX_CMD_RC_PAYLOADLEN ; +return -EINVAL ; + } + + out->supported_feats =cpu_to_le16 (1 ); + cmd->return_code =0 ; +if (count <sizeof (*out) +sizeof (*feat)) {
struct_size() probably makes sense here as well.
Quoted 24 lines
tools/testing/cxl/test/mem.c +14
-0+ out->num_entries =0 ; +return 0 ; + } + + out->num_entries =cpu_to_le16 (1 ); + feat = out->ents; +fill_feature_vendor_test (feat); + +return 0 ; +} +static int cxl_mock_mbox_send (struct cxl_mailbox *cxl_mbox,struct cxl_mbox_cmd *cmd) {@@ -1422,6 +1487,9 @@ static int cxl_mock_mbox_send(struct cxl_mailbox *cxl_mbox,case CXL_MBOX_OP_ACTIVATE_FW : rc =mock_activate_fw (mdata, cmd);break ; +case CXL_MBOX_OP_GET_SUPPORTED_FEATURES : + rc =mock_get_supported_features (mdata, cmd); +break ;default :break ; }
Re: [PATCH v2 06/16] cxl/mbox: Add SET_FEATURE mailbox command
In reply to Dave JiangQuoted 10 lines · On Fri, 31 Jan 2025 17:41:59 -0700 Dave Jiang <[email protected]> wrote:
From: Shiju Jose <[email protected]>
Add support for
SET_FEATUREmailbox command.CXL spec r3.2 section 8.2.9.6 describes optional device specific features. CXL devices supports features with changeable attributes.
The settings of a feature can be optionally modified using Set Feature command.
CXL spec r3.2 section 8.2.9.6.3 describes Set Feature command.
Quoted 3 lines
Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Shiju Jose <[email protected]>Signed-off-by Dave Jiang <[email protected]>
Just one tiny thing on a reread.
J
Quoted 49 lines
---
v2:
- Set input as 'structcxl_mailbox' forcxl_get_feature()(Dan)
- Setfeat_uuidas 'uuid_t*' (Dan)
- Useuuid_copy()to assign uuid
- Fix tab alignment. (Jonathan)
- Updatekmalloc()tokzalloc(). (Dan)--- drivers/cxl/core/features.c | 81 +++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 33 +++++++++++++++ 2 files changed, 114 insertions(+)drivers/cxl/core/features.c +29
-0@@ -57,3 +57,84 @@ size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,return data_rcvd_size; }EXPORT_SYMBOL_NS_GPL (cxl_get_feature,"CXL" ); + +/* +* FEAT_DATA_MIN_PAYLOAD_SIZE - min extra number of bytes should be +* available in the mailbox for storing the actual feature data so that +* the feature data transfer would work as expected. +*/ +#define FEAT_DATA_MIN_PAYLOAD_SIZE 10 +int cxl_set_feature (struct cxl_mailbox *cxl_mbox, +const uuid_t *feat_uuid,u8 feat_version, +void *feat_data,size_t feat_data_size, +u32 feat_flag,u16 offset,u16 *return_code) +{ +struct cxl_memdev_set_feat_pi { +struct cxl_mbox_set_feat_hdr hdr; +u8 feat_data[]; + } __packed; +size_t data_in_size, data_sent_size =0 ; +struct cxl_mbox_cmd mbox_cmd; +size_t hdr_size; +int rc =0 ; + +if (return_code) + *return_code =CXL_MBOX_CMD_RC_INPUT ; + + struct cxl_memdev_set_feat_pi *pi __free(kfree) = +kzalloc (cxl_mbox->payload_size,GFP_KERNEL ); +uuid_copy (&pi->hdr.uuid, feat_uuid); + pi->hdr.version = feat_version; + feat_flag &= ~CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK ;
drivers/cxl/core/features.c size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 98
Quoted 10 lines
drivers/cxl/core/features.c +10
-0+ feat_flag |=CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET ; + hdr_size =sizeof (pi->hdr); +/* +* Check minimum mbox payload size is available for +* the feature data transfer. +*/ +if (hdr_size +FEAT_DATA_MIN_PAYLOAD_SIZE > cxl_mbox->payload_size) +return -ENOMEM ; + +if ((hdr_size + feat_data_size) <= cxl_mbox->payload_size) {
Trivial: Inconsistent brackets wrt to previous check. I'd drop them inner set here as not adding anything.
Quoted 42 lines
drivers/cxl/core/features.c +42
-0+ pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER ); + data_in_size = feat_data_size; + }else { + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER ); + data_in_size = cxl_mbox->payload_size - hdr_size; + } + +do { + pi->hdr.offset =cpu_to_le16 (offset + data_sent_size); +memcpy (pi->feat_data, feat_data + data_sent_size, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd ) { + .opcode =CXL_MBOX_OP_SET_FEATURE , + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + rc =cxl_internal_send_cmd (cxl_mbox, &mbox_cmd); +if (rc <0 ) { +if (return_code) + *return_code = mbox_cmd.return_code; +return rc; + } + + data_sent_size += data_in_size; +if (data_sent_size >= feat_data_size) { +if (return_code) + *return_code =CXL_MBOX_CMD_RC_SUCCESS ; +return 0 ; + } + +if ((feat_data_size - data_sent_size) <= (cxl_mbox->payload_size - hdr_size)) { + data_in_size = feat_data_size - data_sent_size; + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER ); + }else { + pi->hdr.flags =cpu_to_le32 (feat_flag | +CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER ); + } + }while (true); +} +EXPORT_SYMBOL_NS_GPL (cxl_set_feature,"CXL" );
Re: [PATCH v2 08/16] cxl: Add FWCTL support to the CXL memdev driver
In reply to Dave JiangQuoted 8 lines · On Fri, 31 Jan 2025 17:42:01 -0700 Dave Jiang <[email protected]> wrote:
Add fwctl support code to allow sending of CXL feature commands from userspace through as ioctls via FWCTL. Provide initial setup bits.
Signed-off-by Dave Jiang <[email protected]>---
v2:
- Associate FWCTL with the 'cxl_memdev' through the memdev driver. (Dan)
- I'm leaving Jonathan's tag off to get this looked at again.
Wise move ;) Comments inline. Mind you I'm rereading the lot as been off a few days and this is all gone from my head!
Quoted 5 lines
drivers/cxl/features.c +0
-0
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, · line 182
Quoted 10 lines
drivers/cxl/features.c +9
-0+/* The __weak symbol gets replaced by FWCTL allocation function in fwctl.c */ +struct cxl_features_state *__weak devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{ +struct device *dev = &cxlmd->dev; +struct cxl_features_state *cxlfs = +devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); + +if (!cxlfs) +return ERR_PTR (-ENOMEM );
This is returning an error pointer, but the DEFINE FREE assumes NULL I think for the failed to allocate case. Or just return NULL and don't modify that.
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, · line 193
Quoted 11 lines
drivers/cxl/features.c +11
-0+ + cxlfs->cxlmd = cxlmd; + +return cxlfs; +} + +/* The __weak symbol gets replaced by FWCTL free function in fwctl.c */ +void __weak devm_cxlfs_free (struct cxl_memdev *cxlmd) +{ +devm_kfree (&cxlmd->dev, cxlmd->cxlfs); + cxlmd->cxlfs =NULL ;
This missing clear of hanging pointer I mentioned back in earlier patch.
drivers/cxl/features.c DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))
Quoted 12 lines
drivers/cxl/features.c +3
-3+} +static void cxl_cxlfs_free (struct cxl_features_state *cxlfs) { -struct device *dev = &cxlfs->cxlmd->dev; - -devm_kfree (dev, cxlfs); +devm_cxlfs_free (cxlfs->cxlmd); } DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))@@ -185,15 +208,13 @@ DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T))
As above, needs to be if (!IS_ERR_OR_NULL(_T)) I think.
drivers/cxl/features.c DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) cxl_cxlfs_free(_T)) · line 214
Quoted 9 lines
drivers/cxl/features.c +1
-2*/ int devm_cxl_add_features (struct cxl_memdev *cxlmd) { -struct device *dev = &cxlmd->dev;int rc; struct cxl_features_state *cxlfs __free(free_cxlfs) = -devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); +devm_cxlfs_allocate (cxlmd);
As per early comments. I'd drag this much earlier in the series though make only add the __weak markings and comments in this patch. That will reduce churn.
Quoted 20 lines
drivers/cxl/features.c +2
-1if (!cxlfs)return -ENOMEM ; - cxlfs->cxlmd = cxlmd;enumerate_feature_cmds (cxlmd, cxlfs); rc =get_supported_features (cxlmd, cxlfs);if (rc)@@ -204,3 +225,5 @@ int devm_cxl_add_features(struct cxl_memdev *cxlmd)return 0 ; }EXPORT_SYMBOL_NS_GPL (devm_cxl_add_features,"CXL" ); + +MODULE_IMPORT_NS ("CXL" );drivers/cxl/fwctl.c new file +0
-0
drivers/cxl/fwctl.c line 46
Quoted 8 lines
drivers/cxl/fwctl.c new file +7
-0@@ -0,0 +1,88 @@ +static void remove_cxlfs (void *_cxlfs) +{ +struct cxl_features_state *cxlfs = _cxlfs; +struct cxl_memdev *cxlmd = cxlfs->cxlmd; +struct fwctl_device *fwctl = &cxlfs->fwctl; + + cxlmd->cxlfs =NULL ;
This is a little nasty. Originally set in enumerate commands, so not obvious it should be unwound down in here. Perhaps a comment is enough.
Quoted 6 lines
drivers/cxl/fwctl.c new file +6
-0+fwctl_unregister (fwctl); +fwctl_put (fwctl); +} + +DEFINE_FREE(free_cxlfs, struct cxl_features_state *, if (_T) fwctl_put(&_T->fwctl)) +
drivers/cxl/fwctl.c line 62
Quoted 10 lines
drivers/cxl/fwctl.c new file +10
-0+static struct cxl_features_state * +__devm_cxl_cfs_allocate (struct cxl_memdev *cxlmd,const struct fwctl_ops *ops) +{ +struct device *dev = &cxlmd->dev; +int rc; + + struct cxl_features_state *cxlfs __free(free_cxlfs) = + fwctl_alloc_device(dev, ops, struct cxl_features_state, fwctl); +if (!cxlfs) +return ERR_PTR (-ENOMEM );
As above, the caller of this is used with __free that is assuming NULL for failed.
drivers/cxl/fwctl.c line 74
Quoted 12 lines
drivers/cxl/fwctl.c new file +12
-0+ + cxlfs->cxlmd = cxlmd; + rc =fwctl_register (&cxlfs->fwctl); +if (rc) +return ERR_PTR (rc); + + rc =devm_add_action_or_reset (dev, remove_cxlfs, cxlfs); +if (rc) +return ERR_PTR (rc); + +return no_free_ptr (cxlfs); +}
This use of weak functions is a bit too clever for me to be entirely happy but it seems right so fair enough.
Quoted 14 lines
drivers/cxl/fwctl.c new file +14
-0+ +struct cxl_features_state *devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{ +return __devm_cxl_cfs_allocate (cxlmd, &cxlctl_ops); +} +EXPORT_SYMBOL_NS_GPL (devm_cxlfs_allocate,"CXL" ); + +void devm_cxlfs_free (struct cxl_memdev *cxlmd) +{ +devm_release_action (&cxlmd->dev, remove_cxlfs, cxlmd); +} +EXPORT_SYMBOL_NS_GPL (devm_cxlfs_free,"CXL" ); + +MODULE_IMPORT_NS ("FWCTL" );
Re: [PATCH v2 09/16] cxl: Add support for FWCTL get driver information callback
In reply to Dave JiangQuoted 17 lines · On Fri, 31 Jan 2025 17:42:02 -0700 Dave Jiang <[email protected]> wrote:
Add definition for
fwctl_ops->info()to return driver information. The function will return a data structure with a reserved u32. This is setup for future usages.Reviewed-by Jonathan Cameron <[email protected]>Signed-off-by Dave Jiang <[email protected]>include/uapi/fwctl/cxl.h new file +4
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2024, Intel Corporation +*
include/uapi/fwctl/cxl.h line 14
Quoted 10 lines
include/uapi/fwctl/cxl.h new file +10
-0+* 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> + +/** +* struct fwctl_info_cxl - ioctl(FWCTL_INFO) out_device_data +* @reserved: Place older for future usages
holder. Freudian slip?
:)
Quoted 5 lines
include/uapi/fwctl/cxl.h new file +5
-0+*/ +struct fwctl_info_cxl { +__u32 reserved; +}; +#endif
Re: [PATCH v2 11/16] cxl: Add support for fwctl RPC command to enable CXL feature commands
In reply to Dave JiangQuoted 16 lines · On Fri, 31 Jan 2025 17:42:04 -0700 Dave Jiang <[email protected]> wrote:
fwctl provides a
fwctl_ops->fw_rpc()callback in order to issue ioctls to a device. The cxl fwctl driver will start by supporting the CXL feature commands: Get Supported Features, Get Feature, and Set Feature.The
fw_rpc()callback provides 'enumfwctl_rpc_scope' parameter where it indicates the security scope of the call. The Get Supported Features and Get Feature calls can be executed with the scope ofFWCTL_RPC_CONFIGRATION. The Set Feature call is gated by the effects of the feature reported by Get Supported Features call for the specific feature.Only "get supported features" is supported in this patch. Additional commands will be added in follow on patches. "Get supported features" will filter the features that are exclusive to the kernel and only report out features that are not kernel only.
Quoted 7 lines
Signed-off-by Dave Jiang <[email protected]>---
v2:
- Return-EINVALforget_support_feature_info()instead of-ENOENT. (Dan)
- Setset_feat_sizeto 0 for kernel exclusive features.
- Just don't bother checking the valid (9) bit. (Dan)
- Reject if the reserved bits are set. (Dan)
A few minor things inline. Main ones are things that should be in earlier patches to reduce noise in this one.
Jonathan
Quoted 33 lines
drivers/cxl/fwctl.c +25
-0@@ -35,11 +35,209 @@ static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length)return info; } + +static void *cxlctl_get_supported_features (struct cxl_features_state *cxlfs, +const struct fwctl_rpc_cxl *rpc_in, +size_t *out_len) +{ +struct cxl_mbox_get_sup_feats_out *feat_out; +struct cxl_mbox_get_sup_feats_in feat_in; +struct cxl_feat_entry *pos; +int requested, copied; +size_t out_size; +u32 count; +u16 start; + +if (rpc_in->op_size !=sizeof (feat_in)) +return ERR_PTR (-EINVAL ); + +if (copy_from_user (&feat_in,u64_to_user_ptr (rpc_in->in_payload), + rpc_in->op_size)) +return ERR_PTR (-EFAULT ); + + count =le32_to_cpu (feat_in.count); + start =le16_to_cpu (feat_in.start_idx); + requested = count /sizeof (*pos); + +/*
drivers/cxl/fwctl.c static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length) · line 72
Quoted 10 lines
drivers/cxl/fwctl.c +10
-0+* Make sure that the total requested number of entries is not greater +* than the total number of supported features allowed for userspace. +*/ +if (start >= cxlfs->num_user_features) +return ERR_PTR (-EINVAL ); + + requested =min_t (int, requested, cxlfs->num_user_features - start); + + out_size =sizeof (struct fwctl_rpc_cxl_out ) +sizeof (*feat_out) + + requested *sizeof (*pos);
Pity we don't have a pointer to rpc_out until next line, otherwise could do
out_size = struct_size(rpc_out, payload, struct_size(feat_out, ents, requested));
Maybe still worth
out_size = sizeof(struct fwctl_rpc_cxl_out) + struct_size(feat_out, ents, requested);
Whilst pos is the right type, it isn't anything in particular in some code paths so this just seems odd.
drivers/cxl/fwctl.c static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length) · line 101
Quoted 7 lines
drivers/cxl/fwctl.c +7
-0+ + struct fwctl_rpc_cxl_out *rpc_out __free(kvfree) = +kvzalloc (out_size,GFP_KERNEL ); +if (!rpc_out) +return ERR_PTR (-ENOMEM ); + + rpc_out->size =sizeof (*feat_out) + requested *sizeof (*pos);
struct_size for this one.
Quoted 4 lines
drivers/cxl/fwctl.c +4
-0+ feat_out = (struct cxl_mbox_get_sup_feats_out *)rpc_out->payload; +if (requested ==0 ) { + feat_out->num_entries =cpu_to_le16 (requested); + feat_out->supported_feats =
drivers/cxl/fwctl.c static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length) · line 115
Quoted 10 lines
drivers/cxl/fwctl.c +10
-0+cpu_to_le16 (cxlfs->num_user_features); + rpc_out->retval =CXL_MBOX_CMD_RC_SUCCESS ; + *out_len = out_size; +return no_free_ptr (rpc_out); + } + + pos = &feat_out->ents[0 ]; + + copied =0 ; +for (int i =0 ; i < cxlfs->num_features; i++, pos++) {
for (int i = 0, copied = 0, pos = &feat_out->ents[0], i < cxlfs->num_features; i++, pos++)
perhaps, or maybe keep copied outside given it's not adjusted in the loops control.
drivers/cxl/fwctl.c static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length) · line 124
Quoted 9 lines
drivers/cxl/fwctl.c +9
-0+memcpy (pos, &cxlfs->entries[i],sizeof (*pos)); +/* +* If the feature is exclusive, set the set_feat_size to 0 to +* indicate that the feature is not changeable. +*/ +if (is_cxl_feature_exclusive (pos)) + pos->set_feat_size =0 ; + + copied++;
Could move copied alongside pos++ in the loop definition and this check to the start of the loop.
I don't mind on these changes. That loop will get very fiddly.
Quoted 7 lines
drivers/cxl/fwctl.c +7
-0+if (copied == requested) +break ; + } + + feat_out->num_entries =cpu_to_le16 (requested); + feat_out->supported_feats =cpu_to_le16 (cxlfs->num_features); + rpc_out->retval =CXL_MBOX_CMD_RC_SUCCESS ;
drivers/cxl/fwctl.c static void *cxlctl_info(struct fwctl_uctx *uctx, size_t *length)
Quoted 10 lines
drivers/cxl/fwctl.c +6
-1+ *out_len = out_size; + +return no_free_ptr (rpc_out); +} +static void *cxlctl_fw_rpc (struct fwctl_uctx *uctx,enum fwctl_rpc_scope scope, -void *rpc_in,size_t in_len,size_t *out_len) +void *in,size_t in_len,size_t *out_len)
Push renames back to where the stub was introduced. Reduces noise as I doubt anyone minds them!
Quoted 39 lines
drivers/cxl/fwctl.c +13
-2{ -/* Place holder */ -return ERR_PTR (-EOPNOTSUPP ); +struct fwctl_device *fwctl = uctx->fwctl; +struct cxl_features_state *cxlfs =to_cxl_features_state (fwctl); +const struct fwctl_rpc_cxl *rpc_in = in; +u16 opcode; + + opcode =cxl_get_feature_command_opcode (rpc_in->command_id); +if (opcode ==0xffff ) +return ERR_PTR (-EINVAL ); + +if (!cxlctl_validate_hw_command (cxlfs, rpc_in, scope, opcode)) +return ERR_PTR (-EINVAL ); + +return cxlctl_handle_commands (cxlfs, rpc_in, out_len, opcode); }static const struct fwctl_ops cxlctl_ops = {include/cxl/features.h +0
-8@@ -42,14 +42,6 @@struct cxl_mailbox ; -/* Index IDs for CXL mailbox Feature commands */ -enum feature_cmds { -CXL_FEATURE_ID_GET_SUPPORTED_FEATURES =0 , -CXL_FEATURE_ID_GET_FEATURE , -CXL_FEATURE_ID_SET_FEATURE , -CXL_FEATURE_ID_MAX -}; -/* Feature commands capability supported by a device */ enum cxl_features_capability {CXL_FEATURES_NONE =0 ,
include/cxl/features.h size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 78
Quoted 4 lines
include/cxl/features.h +1
-0@@ -83,5 +75,6 @@ size_t cxl_get_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,int cxl_set_feature (struct cxl_mailbox *cxl_mbox,const uuid_t *feat_uuid,u8 feat_version,void *feat_data,size_t feat_data_size,u32 feat_flag,u16 offset,u16 *return_code); +bool is_cxl_feature_exclusive (struct cxl_feat_entry *entry);
Why not put it here directly in patch 7?
Isn't it defined in two places after this patch?
Quoted 2 lines
include/cxl/features.h +0
-0#endif
Re: [PATCH v2 16/16] fwctl/cxl: Add documentation to FWCTL CXL
In reply to Dave JiangOne minor comment. With a sentence added on that (assuming I didn't miss it somewhere)
Quoted 21 lines
Documentation/userspace-api/fwctl/fwctl-cxl.rst new file +15
-0@@ -0,0 +1,135 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================ +fwctl cxl driver +================ + +:Author: Dave Jiang + +Overview +======== + +The CXL spec defines a set of commands that can be issued to the mailbox of a +CXL device or switch. It also left room for vendor specific commands to be +issued to the mailbox as well. fwctl provides a path to issue a set of allowed +mailbox commands from user space to the device moderated by the kernel driver.
Documentation/userspace-api/fwctl/fwctl-cxl.rst line 25
Quoted 10 lines
Documentation/userspace-api/fwctl/fwctl-cxl.rst new file +10
-0+ +The following 3 commands will be used to support CXL Features: +CXL spec r3.1 8.2.9.6.1 Get Supported Features (Opcode 0500h) +CXL spec r3.1 8.2.9.6.2 Get Feature (Opcode 0501h) +CXL spec r3.1 8.2.9.6.3 Set Feature (Opcode 0502h) + +The "Get Supported Features" return data may be filtered by the kernel driver to +drop any features that are forbidden by the kernel or being exclusively used by +the kernel. The "Get Supported Features" command and the "Get Features" falls +under the fwctl policy of FWCTL_RPC_CONFIGURATION.
Document what 'filtered' means given change to zero sized set?
Quoted 9 lines
Documentation/userspace-api/fwctl/fwctl-cxl.rst new file +9
-0+ +For "Set Feature" command, the access policy currently is broken down into two +categories depending on the Set Feature effects reported by the device. If the +Set Feature will cause immediate change to the device, the fwctl access policy +must be FWCTL_RPC_DEBUG_WRITE_FULL. The effects for this level are +"immediate config change", "immediate data change", "immediate policy change", +or "immediate log change" for the set effects mask. If the effects are "config +change with cold reset" or "config change with conventional reset", then the +fwctl access policy must be FWCTL_RPC_DEBUG_WRITE or higher.
Jason Gunthorpe
maintainerRe: [PATCH v2 08/16] cxl: Add FWCTL support to the CXL memdev driver
In reply to Jonathan CameronQuoted 6 lines · Jonathan Cameron
Quoted 6 lines
drivers/cxl/features.c +0
-0
Quoted 6 lines
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, · line 176
Quoted 3 lines
drivers/cxl/features.c +3
-0+/* The __weak symbol gets replaced by FWCTL allocation function in fwctl.c */ +struct cxl_features_state *__weak devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{This use of weak functions is a bit too clever for me to be entirely happy but it seems right so fair enough.
weak functions have become frowned upon lately and I can't clearly see why you'd want this? Can you do it without it please?
Jason
Dave Jiang
maintainerRe: [PATCH v2 08/16] cxl: Add FWCTL support to the CXL memdev driver
Quoted 15 lines · Jason Gunthorpe
Quoted 6 lines · Jonathan Cameron
Quoted 6 lines
drivers/cxl/features.c +0
-0Quoted 6 lines
drivers/cxl/features.c static void enumerate_feature_cmds(struct cxl_memdev *cxlmd, · line 176
Quoted 3 lines
drivers/cxl/features.c +3
-0+/* The __weak symbol gets replaced by FWCTL allocation function in fwctl.c */ +struct cxl_features_state *__weak devm_cxlfs_allocate (struct cxl_memdev *cxlmd) +{This use of weak functions is a bit too clever for me to be entirely happy but it seems right so fair enough.
Quoted 2 lines
weak functions have become frowned upon lately and I can't clearly see why you'd want this? Can you do it without it please?
The intent is to allow the allocation function to be replaced with the FWCTL version when CONFIG_CXL_FWCTL is set. I'll think about how to do this differently. I was really trying to avoid doing #ifdef in the C file.
Quoted 2 lines
Jason
Jason Gunthorpe
maintainerRe: [PATCH v2 08/16] cxl: Add FWCTL support to the CXL memdev driver
Quoted 4 lines · Dave Jiang
The intent is to allow the allocation function to be replaced with the FWCTL version when
CONFIG_CXL_FWCTLis set. I'll think about how to do this differently. I was really trying to avoid doing #ifdef in the C file.
Use an #ifdef (maybe wrapped in an inline function or something), it is much, much better
Jason
Dave Jiang
maintainerRe: [PATCH v2 02/16] cxl: Enumerate feature commands
In reply to Jonathan CameronQuoted 29 lines · Jonathan Cameron
Quoted 6 lines · On Fri, 31 Jan 2025 17:41:55 -0700 Dave Jiang <[email protected]> wrote:
Add feature commands enumeration code in order to detect and enumerate the 3 feature related commands "get supported features", "get feature", and "set feature". The enumeration will help determine whether the driver can issue any of the 3 commands to the device.
Signed-off-by Dave Jiang <[email protected]>Quoted 9 lines
---
v2:
- Setup allocation of cxlfs and move enumeration of commands to the setup function.
- Introducefeatures_capabilityenum. (Dan)
- Name the setup functiondevm_cxl_add_features(). (Dan)
- Drop 'cxl_mem_command' support. (Dan)
- Move feature support to mem probe. (Dan)
- Remove comma at last entry of data structs. (Jonathan)Got carried away on this one. Only drop them for termination
entries. So MAX or NULL or similar.Quoted 8 lines
drivers/cxl/core/mbox.c +0
-0@@ -69,6 +69,29 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { CXL_CMD(GET_TIMESTAMP, 0, 0x8, 0), };
Quoted 6 lines
drivers/cxl/core/mbox.c static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { · line 75
Quoted 4 lines
drivers/cxl/core/mbox.c +4
-0+static u16 cxl_feature_commands[] = { +CXL_MBOX_OP_GET_SUPPORTED_FEATURES , +CXL_MBOX_OP_GET_FEATURE , +CXL_MBOX_OP_SET_FEATURE This one does want a trailing comma. Might be more feature commands in future.
ok
Quoted 24 lines
Quoted 13 lines
drivers/cxl/core/mbox.c +1
-0+};drivers/cxl/features.c new file +4
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */ +#include <linux/device.h> +#include <cxl/mailbox.h> drivers/cxl/features.c line 14
Quoted 10 lines
drivers/cxl/features.c new file +10
-0+#include <cxl/features.h> +#include "cxl.h" +#include "cxlmem.h" +#include "features.h" + +static void enumerate_feature_cmds (struct cxl_memdev *cxlmd) +{ +struct cxl_dev_state *cxlds = cxlmd->cxlds; +struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; +struct cxl_features_state *cxlfs = cxlds->cxlmd->cxlfs;Going in circles?
Quoted 1 line
cxlmd->cxlfs;
yeah oops. should be cleaned up with the other changes going on in this patch
Quoted 42 lines
Quoted 27 lines
drivers/cxl/features.c new file +25
-0+int fid; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_SUPPORTED_FEATURES ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_GET_FEATURE ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + cxlfs->cap =CXL_FEATURES_RO ; + + fid =cxl_get_feature_command_id (CXL_MBOX_OP_SET_FEATURE ); +if (!test_bit (fid, cxl_mbox->feature_cmds)) +return ; + + cxlfs->cap =CXL_FEATURES_RW ; +} + +/** +* devm_cxl_add_features() - Allocate and initialize features context +* @cxlmd: CXL memory device +* +* Return 0 on success or -errno on failure. +*/ drivers/cxl/features.c line 49
Quoted 10 lines
drivers/cxl/features.c new file +10
-0+int devm_cxl_add_features (struct cxl_memdev *cxlmd) +{ +struct cxl_features_state *cxlfs; +struct device *dev = &cxlmd->dev; + + cxlfs =devm_kzalloc (dev,sizeof (*cxlfs),GFP_KERNEL ); +if (!cxlfs) +return -ENOMEM ; + + cxlmd->cxlfs = cxlfs;So I was curious about this one and why we leave the pointer hanging in the remove path + whether the two way pointer nest is needed.
Quoted 5 lines
That gets dealt with in patch 8.
I'd be tempted to drag the bones of
dev_cxlfs_allocate()to this patch so that you can do that cleanup now and avoid some of the churn of the later patches.
ok I'll do that.
Quoted 8 lines
As for the two way pointer nest. I'm not sure it is needed. Seems like most if not all places we use
cxlmd->cxlfshave just gotten it in the caller fromcxlfs->cxlmd. e.g.cxl_cxlfs_free()in patch 8. For here we could just pass it intoenumerate_feature_cmds.Maybe Shiju's set needs it. I haven't checked.
I think he does with calling of cxl_get_supported_feature_entry(). Need a way to go from cxlmd to cxlfs.
Quoted 33 lines
Quoted 33 lines
drivers/cxl/features.c new file +6
-0+ cxlfs->cxlmd = cxlmd; +enumerate_feature_cmds (cxlmd); + +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (devm_cxl_add_features,"CXL" );include/cxl/features.h new file +16
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2024-2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_H__ +#define __CXL_FEATURES_H__ + +struct cxl_mailbox ; + +/* Index IDs for CXL mailbox Feature commands */ +enum feature_cmds { +CXL_FEATURE_ID_GET_SUPPORTED_FEATURES =0 , +CXL_FEATURE_ID_GET_FEATURE , +CXL_FEATURE_ID_SET_FEATURE , +CXL_FEATURE_ID_MAX +}; + +/* Feature commands capability supported by a device */
Quoted 8 lines
include/cxl/features.h line 20
Quoted 4 lines
include/cxl/features.h new file +4
-0+enum cxl_features_capability { +CXL_FEATURES_NONE =0 , +CXL_FEATURES_RO , +CXL_FEATURES_RW Trivial but this one should have a trailing comma. Maybe we'll have a write only one! Anyhow, it's not a terminating entry so we shouldn't assume nothing comes after it.
ok
Quoted 17 lines
Quoted 16 lines
include/cxl/features.h new file +15
-0+}; + +/** +* struct cxl_features_state - The Features state for the device +* @cxlmd: Pointer to cxl mem device +* @cap: Feature commands capability +* @num_features: total Features supported by the device +*/ +struct cxl_features_state { +struct cxl_memdev *cxlmd; +enum cxl_features_capability cap; +int num_features; +}; + +#endif