Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cxl: Add support for fwctl RPC command to enable CXL feature commands

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 '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. The flag
field of the Feature details will be cleared of the "Changeable"
field and the "set feat size" will be set to 0 to indicate that
the feature is not changeable.

Link: https://patch.msgid.link/r/20250307205648.1021626-4-dave.jiang@intel.com
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Li Ming <ming.li@zohomail.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Dave Jiang and committed by
Jason Gunthorpe
4d1c09ce 9b8e73cd

+166 -2
+119 -2
drivers/cxl/core/features.c
··· 4 4 #include <linux/device.h> 5 5 #include <cxl/mailbox.h> 6 6 #include <cxl/features.h> 7 + #include <uapi/fwctl/cxl.h> 7 8 #include "cxl.h" 8 9 #include "core.h" 9 10 #include "cxlmem.h" ··· 350 349 { 351 350 } 352 351 352 + static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs, 353 + const struct fwctl_rpc_cxl *rpc_in, 354 + size_t *out_len) 355 + { 356 + const struct cxl_mbox_get_sup_feats_in *feat_in; 357 + struct cxl_mbox_get_sup_feats_out *feat_out; 358 + struct cxl_feat_entry *pos; 359 + size_t out_size; 360 + int requested; 361 + u32 count; 362 + u16 start; 363 + int i; 364 + 365 + if (rpc_in->op_size != sizeof(*feat_in)) 366 + return ERR_PTR(-EINVAL); 367 + 368 + feat_in = &rpc_in->get_sup_feats_in; 369 + count = le32_to_cpu(feat_in->count); 370 + start = le16_to_cpu(feat_in->start_idx); 371 + requested = count / sizeof(*pos); 372 + 373 + /* 374 + * Make sure that the total requested number of entries is not greater 375 + * than the total number of supported features allowed for userspace. 376 + */ 377 + if (start >= cxlfs->entries->num_features) 378 + return ERR_PTR(-EINVAL); 379 + 380 + requested = min_t(int, requested, cxlfs->entries->num_features - start); 381 + 382 + out_size = sizeof(struct fwctl_rpc_cxl_out) + 383 + struct_size(feat_out, ents, requested); 384 + 385 + struct fwctl_rpc_cxl_out *rpc_out __free(kvfree) = 386 + kvzalloc(out_size, GFP_KERNEL); 387 + if (!rpc_out) 388 + return ERR_PTR(-ENOMEM); 389 + 390 + rpc_out->size = struct_size(feat_out, ents, requested); 391 + feat_out = &rpc_out->get_sup_feats_out; 392 + if (requested == 0) { 393 + feat_out->num_entries = cpu_to_le16(requested); 394 + feat_out->supported_feats = 395 + cpu_to_le16(cxlfs->entries->num_features); 396 + rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS; 397 + *out_len = out_size; 398 + return no_free_ptr(rpc_out); 399 + } 400 + 401 + for (i = start, pos = &feat_out->ents[0]; 402 + i < cxlfs->entries->num_features; i++, pos++) { 403 + if (i - start == requested) 404 + break; 405 + 406 + memcpy(pos, &cxlfs->entries->ent[i], sizeof(*pos)); 407 + /* 408 + * If the feature is exclusive, set the set_feat_size to 0 to 409 + * indicate that the feature is not changeable. 410 + */ 411 + if (is_cxl_feature_exclusive(pos)) { 412 + u32 flags; 413 + 414 + pos->set_feat_size = 0; 415 + flags = le32_to_cpu(pos->flags); 416 + flags &= ~CXL_FEATURE_F_CHANGEABLE; 417 + pos->flags = cpu_to_le32(flags); 418 + } 419 + } 420 + 421 + feat_out->num_entries = cpu_to_le16(requested); 422 + feat_out->supported_feats = cpu_to_le16(cxlfs->entries->num_features); 423 + rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS; 424 + *out_len = out_size; 425 + 426 + return no_free_ptr(rpc_out); 427 + } 428 + 429 + static bool cxlctl_validate_hw_command(struct cxl_features_state *cxlfs, 430 + const struct fwctl_rpc_cxl *rpc_in, 431 + enum fwctl_rpc_scope scope, 432 + u16 opcode) 433 + { 434 + struct cxl_mailbox *cxl_mbox = &cxlfs->cxlds->cxl_mbox; 435 + 436 + switch (opcode) { 437 + case CXL_MBOX_OP_GET_SUPPORTED_FEATURES: 438 + if (cxl_mbox->feat_cap < CXL_FEATURES_RO) 439 + return false; 440 + if (scope >= FWCTL_RPC_CONFIGURATION) 441 + return true; 442 + return false; 443 + default: 444 + return false; 445 + } 446 + } 447 + 448 + static void *cxlctl_handle_commands(struct cxl_features_state *cxlfs, 449 + const struct fwctl_rpc_cxl *rpc_in, 450 + size_t *out_len, u16 opcode) 451 + { 452 + switch (opcode) { 453 + case CXL_MBOX_OP_GET_SUPPORTED_FEATURES: 454 + return cxlctl_get_supported_features(cxlfs, rpc_in, out_len); 455 + default: 456 + return ERR_PTR(-EOPNOTSUPP); 457 + } 458 + } 459 + 353 460 static void *cxlctl_fw_rpc(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope, 354 461 void *in, size_t in_len, size_t *out_len) 355 462 { 356 - /* Place holder */ 357 - return ERR_PTR(-EOPNOTSUPP); 463 + struct fwctl_device *fwctl_dev = uctx->fwctl; 464 + struct cxl_memdev *cxlmd = fwctl_to_memdev(fwctl_dev); 465 + struct cxl_features_state *cxlfs = to_cxlfs(cxlmd->cxlds); 466 + const struct fwctl_rpc_cxl *rpc_in = in; 467 + u16 opcode = rpc_in->opcode; 468 + 469 + if (!cxlctl_validate_hw_command(cxlfs, rpc_in, scope, opcode)) 470 + return ERR_PTR(-EINVAL); 471 + 472 + return cxlctl_handle_commands(cxlfs, rpc_in, out_len, opcode); 358 473 } 359 474 360 475 static const struct fwctl_ops cxlctl_ops = {
+1
include/uapi/cxl/features.h
··· 42 42 #define CXL_CMD_EFFECTS_VALID BIT(9) 43 43 #define CXL_CMD_CONFIG_CHANGE_CONV_RESET BIT(10) 44 44 #define CXL_CMD_CONFIG_CHANGE_CXL_RESET BIT(11) 45 + #define CXL_CMD_EFFECTS_RESERVED GENMASK(15, 12) 45 46 46 47 /* 47 48 * struct cxl_feat_entry - Supported Feature Entry
+46
include/uapi/fwctl/cxl.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 + /* 3 + * Copyright (c) 2024-2025 Intel Corporation 4 + * 5 + * These are definitions for the mailbox command interface of CXL subsystem. 6 + */ 7 + #ifndef _UAPI_FWCTL_CXL_H_ 8 + #define _UAPI_FWCTL_CXL_H_ 9 + 10 + #include <linux/types.h> 11 + #include <linux/stddef.h> 12 + #include <cxl/features.h> 13 + 14 + /** 15 + * struct fwctl_rpc_cxl - ioctl(FWCTL_RPC) input for CXL 16 + * @opcode: CXL mailbox command opcode 17 + * @flags: Flags for the command (input). 18 + * @op_size: Size of input payload. 19 + * @reserved1: Reserved. Must be 0s. 20 + * @get_sup_feats_in: Get Supported Features input 21 + */ 22 + struct fwctl_rpc_cxl { 23 + __struct_group(fwctl_rpc_cxl_hdr, hdr, /* no attrs */, 24 + __u32 opcode; 25 + __u32 flags; 26 + __u32 op_size; 27 + __u32 reserved1; 28 + ); 29 + struct cxl_mbox_get_sup_feats_in get_sup_feats_in; 30 + }; 31 + 32 + /** 33 + * struct fwctl_rpc_cxl_out - ioctl(FWCTL_RPC) output for CXL 34 + * @size: Size of the output payload 35 + * @retval: Return value from device 36 + * @get_sup_feats_out: Get Supported Features output 37 + */ 38 + struct fwctl_rpc_cxl_out { 39 + __struct_group(fwctl_rpc_cxl_out_hdr, hdr, /* no attrs */, 40 + __u32 size; 41 + __u32 retval; 42 + ); 43 + struct cxl_mbox_get_sup_feats_out get_sup_feats_out; 44 + }; 45 + 46 + #endif