Skip to content

Commit f6b8ab3

Browse files
committed
cxl/memdev: Make mailbox functionality optional
In support of the Linux CXL core scaling for a wider set of CXL devices, allow for the creation of memdevs with some memory device capabilities disabled. Specifically, allow for CXL devices outside of those claiming to be compliant with the generic CXL memory device class code, like vendor specific Type-2/3 devices that host CXL.mem. This implies, allow for the creation of memdevs that only support component-registers, not necessarily memory-device-registers (like mailbox registers). A memdev derived from a CXL endpoint that does not support generic class code expectations is tagged "CXL_DEVTYPE_DEVMEM", while a memdev derived from a class-code compliant endpoint is tagged "CXL_DEVTYPE_CLASSMEM". The primary assumption of a CXL_DEVTYPE_DEVMEM memdev is that it optionally may not host a mailbox. Disable the command passthrough ioctl for memdevs that are not CXL_DEVTYPE_CLASSMEM, and return empty strings from memdev attributes associated with data retrieved via the class-device-standard IDENTIFY command. Note that empty strings were chosen over attribute visibility to maintain compatibility with shipping versions of cxl-cli that expect those attributes to always be present. Once cxl-cli has dropped that requirement this workaround can be deprecated. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/168679260782.3436160.7587293613945445365.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 59f8d15 commit f6b8ab3

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

drivers/cxl/core/mbox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)
12721272
mutex_init(&mds->mbox_mutex);
12731273
mutex_init(&mds->event.log_lock);
12741274
mds->cxlds.dev = dev;
1275+
mds->cxlds.type = CXL_DEVTYPE_CLASSMEM;
12751276

12761277
return mds;
12771278
}

drivers/cxl/core/memdev.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static ssize_t firmware_version_show(struct device *dev,
4141
struct cxl_dev_state *cxlds = cxlmd->cxlds;
4242
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
4343

44+
if (!mds)
45+
return sysfs_emit(buf, "\n");
4446
return sysfs_emit(buf, "%.16s\n", mds->firmware_version);
4547
}
4648
static DEVICE_ATTR_RO(firmware_version);
@@ -52,6 +54,8 @@ static ssize_t payload_max_show(struct device *dev,
5254
struct cxl_dev_state *cxlds = cxlmd->cxlds;
5355
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
5456

57+
if (!mds)
58+
return sysfs_emit(buf, "\n");
5559
return sysfs_emit(buf, "%zu\n", mds->payload_size);
5660
}
5761
static DEVICE_ATTR_RO(payload_max);
@@ -63,6 +67,8 @@ static ssize_t label_storage_size_show(struct device *dev,
6367
struct cxl_dev_state *cxlds = cxlmd->cxlds;
6468
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds);
6569

70+
if (!mds)
71+
return sysfs_emit(buf, "\n");
6672
return sysfs_emit(buf, "%zu\n", mds->lsa_size);
6773
}
6874
static DEVICE_ATTR_RO(label_storage_size);
@@ -517,10 +523,12 @@ static long cxl_memdev_ioctl(struct file *file, unsigned int cmd,
517523
unsigned long arg)
518524
{
519525
struct cxl_memdev *cxlmd = file->private_data;
526+
struct cxl_dev_state *cxlds;
520527
int rc = -ENXIO;
521528

522529
down_read(&cxl_memdev_rwsem);
523-
if (cxlmd->cxlds)
530+
cxlds = cxlmd->cxlds;
531+
if (cxlds && cxlds->type == CXL_DEVTYPE_CLASSMEM)
524532
rc = __cxl_memdev_ioctl(cxlmd, cmd, arg);
525533
up_read(&cxl_memdev_rwsem);
526534

drivers/cxl/cxlmem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ struct cxl_poison_state {
254254
struct mutex lock; /* Protect reads of poison list */
255255
};
256256

257+
/*
258+
* enum cxl_devtype - delineate type-2 from a generic type-3 device
259+
* @CXL_DEVTYPE_DEVMEM - Vendor specific CXL Type-2 device implementing HDM-D or
260+
* HDM-DB, no requirement that this device implements a
261+
* mailbox, or other memory-device-standard manageability
262+
* flows.
263+
* @CXL_DEVTYPE_CLASSMEM - Common class definition of a CXL Type-3 device with
264+
* HDM-H and class-mandatory memory device registers
265+
*/
266+
enum cxl_devtype {
267+
CXL_DEVTYPE_DEVMEM,
268+
CXL_DEVTYPE_CLASSMEM,
269+
};
270+
257271
/**
258272
* struct cxl_dev_state - The driver device state
259273
*
@@ -272,6 +286,7 @@ struct cxl_poison_state {
272286
* @ram_res: Active Volatile memory capacity configuration
273287
* @component_reg_phys: register base of component registers
274288
* @serial: PCIe Device Serial Number
289+
* @type: Generic Memory Class device or Vendor Specific Memory device
275290
*/
276291
struct cxl_dev_state {
277292
struct device *dev;
@@ -285,6 +300,7 @@ struct cxl_dev_state {
285300
struct resource ram_res;
286301
resource_size_t component_reg_phys;
287302
u64 serial;
303+
enum cxl_devtype type;
288304
};
289305

290306
/**
@@ -343,6 +359,8 @@ struct cxl_memdev_state {
343359
static inline struct cxl_memdev_state *
344360
to_cxl_memdev_state(struct cxl_dev_state *cxlds)
345361
{
362+
if (cxlds->type != CXL_DEVTYPE_CLASSMEM)
363+
return NULL;
346364
return container_of(cxlds, struct cxl_memdev_state, cxlds);
347365
}
348366

0 commit comments

Comments
 (0)