Skip to content

Commit 5908f3e

Browse files
davejiangjgunthorpe
authored andcommitted
cxl: Add support to handle user feature commands for get feature
Add helper function to parse the user data from fwctl RPC ioctl and send the parsed input parameters to cxl_get_feature() call. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Li Ming <[email protected]> Signed-off-by: Dave Jiang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4d1c09c commit 5908f3e

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

drivers/cxl/core/features.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,47 @@ static void *cxlctl_get_supported_features(struct cxl_features_state *cxlfs,
427427
return no_free_ptr(rpc_out);
428428
}
429429

430+
static void *cxlctl_get_feature(struct cxl_features_state *cxlfs,
431+
const struct fwctl_rpc_cxl *rpc_in,
432+
size_t *out_len)
433+
{
434+
struct cxl_mailbox *cxl_mbox = &cxlfs->cxlds->cxl_mbox;
435+
const struct cxl_mbox_get_feat_in *feat_in;
436+
u16 offset, count, return_code;
437+
size_t out_size = *out_len;
438+
439+
if (rpc_in->op_size != sizeof(*feat_in))
440+
return ERR_PTR(-EINVAL);
441+
442+
feat_in = &rpc_in->get_feat_in;
443+
offset = le16_to_cpu(feat_in->offset);
444+
count = le16_to_cpu(feat_in->count);
445+
446+
if (!count)
447+
return ERR_PTR(-EINVAL);
448+
449+
struct fwctl_rpc_cxl_out *rpc_out __free(kvfree) =
450+
kvzalloc(out_size, GFP_KERNEL);
451+
if (!rpc_out)
452+
return ERR_PTR(-ENOMEM);
453+
454+
out_size = cxl_get_feature(cxl_mbox, &feat_in->uuid,
455+
feat_in->selection, rpc_out->payload,
456+
count, offset, &return_code);
457+
*out_len = sizeof(struct fwctl_rpc_cxl_out);
458+
if (!out_size) {
459+
rpc_out->size = 0;
460+
rpc_out->retval = return_code;
461+
return no_free_ptr(rpc_out);
462+
}
463+
464+
rpc_out->size = out_size;
465+
rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS;
466+
*out_len += out_size;
467+
468+
return no_free_ptr(rpc_out);
469+
}
470+
430471
static bool cxlctl_validate_hw_command(struct cxl_features_state *cxlfs,
431472
const struct fwctl_rpc_cxl *rpc_in,
432473
enum fwctl_rpc_scope scope,
@@ -436,6 +477,7 @@ static bool cxlctl_validate_hw_command(struct cxl_features_state *cxlfs,
436477

437478
switch (opcode) {
438479
case CXL_MBOX_OP_GET_SUPPORTED_FEATURES:
480+
case CXL_MBOX_OP_GET_FEATURE:
439481
if (cxl_mbox->feat_cap < CXL_FEATURES_RO)
440482
return false;
441483
if (scope >= FWCTL_RPC_CONFIGURATION)
@@ -453,6 +495,8 @@ static void *cxlctl_handle_commands(struct cxl_features_state *cxlfs,
453495
switch (opcode) {
454496
case CXL_MBOX_OP_GET_SUPPORTED_FEATURES:
455497
return cxlctl_get_supported_features(cxlfs, rpc_in, out_len);
498+
case CXL_MBOX_OP_GET_FEATURE:
499+
return cxlctl_get_feature(cxlfs, rpc_in, out_len);
456500
default:
457501
return ERR_PTR(-EOPNOTSUPP);
458502
}

include/uapi/fwctl/cxl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @op_size: Size of input payload.
1919
* @reserved1: Reserved. Must be 0s.
2020
* @get_sup_feats_in: Get Supported Features input
21+
* @get_feat_in: Get Feature input
2122
*/
2223
struct fwctl_rpc_cxl {
2324
__struct_group(fwctl_rpc_cxl_hdr, hdr, /* no attrs */,
@@ -26,21 +27,28 @@ struct fwctl_rpc_cxl {
2627
__u32 op_size;
2728
__u32 reserved1;
2829
);
29-
struct cxl_mbox_get_sup_feats_in get_sup_feats_in;
30+
union {
31+
struct cxl_mbox_get_sup_feats_in get_sup_feats_in;
32+
struct cxl_mbox_get_feat_in get_feat_in;
33+
};
3034
};
3135

3236
/**
3337
* struct fwctl_rpc_cxl_out - ioctl(FWCTL_RPC) output for CXL
3438
* @size: Size of the output payload
3539
* @retval: Return value from device
3640
* @get_sup_feats_out: Get Supported Features output
41+
* @payload: raw byte stream of payload
3742
*/
3843
struct fwctl_rpc_cxl_out {
3944
__struct_group(fwctl_rpc_cxl_out_hdr, hdr, /* no attrs */,
4045
__u32 size;
4146
__u32 retval;
4247
);
43-
struct cxl_mbox_get_sup_feats_out get_sup_feats_out;
48+
union {
49+
struct cxl_mbox_get_sup_feats_out get_sup_feats_out;
50+
__DECLARE_FLEX_ARRAY(__u8, payload);
51+
};
4452
};
4553

4654
#endif

0 commit comments

Comments
 (0)