Message ID | 20250320180450.539-6-shiju.jose@huawei.com (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | cxl: support CXL memory RAS features | expand |
shiju.jose@ wrote: > From: Shiju Jose <shiju.jose@huawei.com> > > Add support for PERFORM_MAINTENANCE mailbox command. > > CXL spec 3.2 section 8.2.10.7.1 describes the Perform Maintenance command. > This command requests the device to execute the maintenance operation > specified by the maintenance operation class and the maintenance operation > subclass. > > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > Reviewed-by: Dave Jiang <dave.jiang@intel.com> > Signed-off-by: Shiju Jose <shiju.jose@huawei.com> > --- > drivers/cxl/core/mbox.c | 34 ++++++++++++++++++++++++++++++++++ > drivers/cxl/cxlmem.h | 17 +++++++++++++++++ > 2 files changed, 51 insertions(+) > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > index d72764056ce6..19d46a284650 100644 > --- a/drivers/cxl/core/mbox.c > +++ b/drivers/cxl/core/mbox.c > @@ -824,6 +824,40 @@ static const uuid_t log_uuid[] = { > [VENDOR_DEBUG_UUID] = DEFINE_CXL_VENDOR_DEBUG_UUID, > }; > > +int cxl_do_maintenance(struct cxl_mailbox *cxl_mbox, > + u8 class, u8 subclass, > + void *data_in, size_t data_in_size) > +{ > + struct cxl_memdev_maintenance_pi { > + struct cxl_mbox_do_maintenance_hdr hdr; Please call this "perform_maintenance" because "do_" is usually a Linux-ism for a core helper. Also fold this patch into the caller that needs it. > + u8 data[]; > + } __packed; > + struct cxl_mbox_cmd mbox_cmd; > + size_t hdr_size; > + > + struct cxl_memdev_maintenance_pi *pi __free(kfree) = > + kmalloc(cxl_mbox->payload_size, GFP_KERNEL); s/kmalloc/kvzalloc/ if (!pi) return -ENOMEM; > + pi->hdr.op_class = class; > + pi->hdr.op_subclass = subclass; > + hdr_size = sizeof(pi->hdr); > + /* > + * Check minimum mbox payload size is available for > + * the maintenance data transfer. > + */ > + if (hdr_size + data_in_size > cxl_mbox->payload_size) > + return -ENOMEM; -EINVAL > + > + memcpy(pi->data, data_in, data_in_size); > + mbox_cmd = (struct cxl_mbox_cmd) { > + .opcode = CXL_MBOX_OP_DO_MAINTENANCE, > + .size_in = hdr_size + data_in_size, > + .payload_in = pi, > + }; > + > + return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd); > +} > +EXPORT_SYMBOL_NS_GPL(cxl_do_maintenance, "CXL"); Why? There is nothing in this function that needs the rest of mbox.c beyond cxl_internal_send_cmd which is already exported. Just define this in the only object that needs it.
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index d72764056ce6..19d46a284650 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -824,6 +824,40 @@ static const uuid_t log_uuid[] = { [VENDOR_DEBUG_UUID] = DEFINE_CXL_VENDOR_DEBUG_UUID, }; +int cxl_do_maintenance(struct cxl_mailbox *cxl_mbox, + u8 class, u8 subclass, + void *data_in, size_t data_in_size) +{ + struct cxl_memdev_maintenance_pi { + struct cxl_mbox_do_maintenance_hdr hdr; + u8 data[]; + } __packed; + struct cxl_mbox_cmd mbox_cmd; + size_t hdr_size; + + struct cxl_memdev_maintenance_pi *pi __free(kfree) = + kmalloc(cxl_mbox->payload_size, GFP_KERNEL); + pi->hdr.op_class = class; + pi->hdr.op_subclass = subclass; + hdr_size = sizeof(pi->hdr); + /* + * Check minimum mbox payload size is available for + * the maintenance data transfer. + */ + if (hdr_size + data_in_size > cxl_mbox->payload_size) + return -ENOMEM; + + memcpy(pi->data, data_in, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_DO_MAINTENANCE, + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + + return cxl_internal_send_cmd(cxl_mbox, &mbox_cmd); +} +EXPORT_SYMBOL_NS_GPL(cxl_do_maintenance, "CXL"); + /** * cxl_enumerate_cmds() - Enumerate commands for a device. * @mds: The driver data for the operation diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 11fa98cc4d9c..7ab257e0c85e 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -527,6 +527,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, CXL_MBOX_OP_GET_FEATURE = 0x0501, CXL_MBOX_OP_SET_FEATURE = 0x0502, + CXL_MBOX_OP_DO_MAINTENANCE = 0x0600, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, @@ -827,6 +828,19 @@ enum { CXL_PMEM_SEC_PASS_USER, }; +/* + * Perform Maintenance CXL 3.2 Spec 8.2.10.7.1 + */ + +/* + * Perform Maintenance input payload + * CXL rev 3.2 section 8.2.10.7.1 Table 8-117 + */ +struct cxl_mbox_do_maintenance_hdr { + u8 op_class; + u8 op_subclass; +} __packed; + int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd); int cxl_dev_state_identify(struct cxl_memdev_state *mds); @@ -898,4 +912,7 @@ struct cxl_hdm { struct seq_file; struct dentry *cxl_debugfs_create_dir(const char *dir); void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); +int cxl_do_maintenance(struct cxl_mailbox *cxl_mbox, + u8 class, u8 subclass, + void *data_in, size_t data_in_size); #endif /* __CXL_MEM_H__ */