@@ -191,6 +191,53 @@ static void *cxlctl_get_feature(struct cxl_features_state *cfs,
return no_free_ptr(rpc_out);
}
+static void *cxlctl_set_feature(struct cxl_features_state *cfs,
+ const struct fwctl_rpc_cxl *rpc_in,
+ size_t *out_len)
+{
+ size_t out_size, data_size;
+ u16 offset, return_code;
+ u32 flags;
+ int rc;
+
+ if (rpc_in->op_size <= sizeof(struct cxl_mbox_set_feat_hdr))
+ return ERR_PTR(-EINVAL);
+
+ struct cxl_mbox_set_feat_in *feat_in __free(kvfree) =
+ kvzalloc(rpc_in->op_size, GFP_KERNEL);
+ if (!feat_in)
+ return ERR_PTR(-ENOMEM);
+
+ 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->hdr.offset);
+ flags = le32_to_cpu(feat_in->hdr.flags);
+ out_size = *out_len;
+
+ struct fwctl_rpc_cxl_out *rpc_out __free(kvfree) =
+ kvzalloc(out_size, GFP_KERNEL);
+ if (!rpc_out)
+ return ERR_PTR(-ENOMEM);
+
+ rpc_out->size = 0;
+
+ data_size = rpc_in->op_size - sizeof(feat_in->hdr);
+ rc = cxl_set_feature(cfs->features, feat_in->hdr.uuid,
+ feat_in->hdr.version, feat_in->data,
+ data_size, flags, offset, &return_code);
+ if (rc) {
+ rpc_out->retval = return_code;
+ return no_free_ptr(rpc_out);
+ }
+
+ rpc_out->retval = CXL_MBOX_CMD_RC_SUCCESS;
+ *out_len = sizeof(*rpc_out);
+
+ return no_free_ptr(rpc_out);
+}
+
static bool cxlctl_validate_set_features(struct cxl_features_state *cfs,
const struct fwctl_rpc_cxl *rpc_in,
enum fwctl_rpc_scope scope)
@@ -275,6 +322,7 @@ static void *cxlctl_handle_commands(struct cxl_features_state *cfs,
case CXL_MBOX_OP_GET_FEATURE:
return cxlctl_get_feature(cfs, rpc_in, out_len);
case CXL_MBOX_OP_SET_FEATURE:
+ return cxlctl_set_feature(cfs, rpc_in, out_len);
default:
return ERR_PTR(-EOPNOTSUPP);
}
@@ -127,4 +127,9 @@ 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__));
+
#endif
Add helper function to parse the user data from fwctl RPC ioctl and send the parsed input parameters to cxl_set_feature() call. Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- drivers/cxl/features.c | 48 +++++++++++++++++++++++++++++++++++++ include/uapi/cxl/features.h | 5 ++++ 2 files changed, 53 insertions(+)