@@ -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,
@@ -1445,6 +1449,88 @@ static int mock_get_feature(struct cxl_mockmem_data *mdata,
return -EOPNOTSUPP;
}
+struct scrub_feat_data {
+ u8 cycle;
+#define SCRUB_DATA_F_ENABLE BIT(0)
+ u8 flags;
+};
+#define SCRUB_DATA_CYCLE_OFFSET 0
+#define SCRUB_DATA_FLAGS_OFFSET 1
+
+struct set_feat_input {
+ uuid_t uuid;
+ __le32 flags;
+ __le16 offset;
+ u8 version;
+ u8 rsvd[9];
+ u8 data[];
+} __packed;
+
+enum set_feature_flags {
+ SET_FEATURE_F_FULL_XFER = 0,
+ SET_FEATURE_F_INIT_XFER,
+ SET_FEATURE_F_CONT_XFER,
+ SET_FEATURE_F_FIN_XFER,
+ SET_FEATURE_F_ABORT_XFER,
+};
+
+#define SET_FEATURE_F_ACTION_MASK GENMASK(2, 0)
+
+static int mock_set_patrol_scrub(struct cxl_mockmem_data *mdata,
+ struct cxl_mbox_cmd *cmd)
+{
+ struct set_feat_input *input = cmd->payload_in;
+ struct scrub_feat_data *data;
+ u32 action;
+
+ action = FIELD_GET(SET_FEATURE_F_ACTION_MASK,
+ le32_to_cpu(input->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 != SET_FEATURE_F_FULL_XFER) {
+ cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+ return -EINVAL;
+ }
+
+ /* Offset should be reserved when doing full transfer */
+ if (input->offset) {
+ cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+ return -EINVAL;
+ }
+
+ data = (struct scrub_feat_data *)input->data;
+ /* Does not support changing cycle, should be reserved */
+ if (data->cycle) {
+ cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+ return -EINVAL;
+ }
+
+ /* Check reserved fields */
+ if (data->flags & ~SCRUB_DATA_F_ENABLE) {
+ cmd->return_code = CXL_MBOX_CMD_RC_INPUT;
+ return -EINVAL;
+ }
+ mdata->patrol_feat.flags = data->flags & SCRUB_DATA_F_ENABLE;
+
+ return 0;
+}
+
+static int mock_set_feature(struct cxl_mockmem_data *mdata,
+ struct cxl_mbox_cmd *cmd)
+{
+ struct set_feat_input *input = cmd->payload_in;
+
+ if (uuid_equal(&input->uuid, &DEV_PATROL_SCRUB_FEAT_UUID))
+ return mock_set_patrol_scrub(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)
{
@@ -1580,6 +1666,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;
}
Add 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. Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- tools/testing/cxl/test/mem.c | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)