@@ -316,23 +316,24 @@ Description:
What: /sys/bus/cxl/devices/decoderX.Y/mode
-Date: May, 2022
-KernelVersion: v6.0
+Date: May, 2022, October 2024
+KernelVersion: v6.0, v6.12 (dcY)
Contact: linux-cxl@vger.kernel.org
Description:
(RW) When a CXL decoder is of devtype "cxl_decoder_endpoint" it
translates from a host physical address range, to a device local
address range. Device-local address ranges are further split
- into a 'ram' (volatile memory) range and 'pmem' (persistent
- memory) range. The 'mode' attribute emits one of 'ram', 'pmem',
- 'mixed', or 'none'. The 'mixed' indication is for error cases
- when a decoder straddles the volatile/persistent partition
- boundary, and 'none' indicates the decoder is not actively
- decoding, or no DPA allocation policy has been set.
+ into a 'ram' (volatile memory) range, 'pmem' (persistent
+ memory) range, or Dynamic Capacity (DC) range. The 'mode'
+ attribute emits one of 'ram', 'pmem', 'dcY', 'mixed', or
+ 'none'. The 'mixed' indication is for error cases when a
+ decoder straddles partition boundaries, and 'none' indicates
+ the decoder is not actively decoding, or no DPA allocation
+ policy has been set.
'mode' can be written, when the decoder is in the 'disabled'
- state, with either 'ram' or 'pmem' to set the boundaries for the
- next allocation.
+ state, with 'ram', 'pmem', or 'dcY' to set the boundaries for
+ the next allocation.
What: /sys/bus/cxl/devices/decoderX.Y/dpa_resource
@@ -551,6 +551,7 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
switch (mode) {
case CXL_DECODER_RAM:
case CXL_DECODER_PMEM:
+ case CXL_DECODER_DC0 ... CXL_DECODER_DC7:
break;
default:
dev_dbg(dev, "unsupported mode: %d\n", mode);
@@ -578,6 +579,15 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
goto out;
}
+ if (mode >= CXL_DECODER_DC0 && mode <= CXL_DECODER_DC7) {
+ rc = dc_mode_to_region_index(mode);
+ if (!resource_size(&cxlds->dc_res[rc])) {
+ dev_dbg(dev, "no available dynamic capacity\n");
+ rc = -ENXIO;
+ goto out;
+ }
+ }
+
cxled->mode = mode;
rc = 0;
out:
@@ -205,11 +205,11 @@ static ssize_t mode_store(struct device *dev, struct device_attribute *attr,
enum cxl_decoder_mode mode;
ssize_t rc;
- if (sysfs_streq(buf, "pmem"))
- mode = CXL_DECODER_PMEM;
- else if (sysfs_streq(buf, "ram"))
- mode = CXL_DECODER_RAM;
- else
+ for (mode = CXL_DECODER_RAM; mode < CXL_DECODER_MIXED; mode++)
+ if (sysfs_streq(buf, cxl_decoder_mode_names[mode]))
+ break;
+
+ if (mode >= CXL_DECODER_MIXED)
return -EINVAL;
rc = cxl_dpa_set_mode(cxled, mode);
@@ -365,6 +365,9 @@ struct cxl_decoder {
/*
* CXL_DECODER_DEAD prevents endpoints from being reattached to regions
* while cxld_unregister() is running
+ *
+ * NOTE: CXL_DECODER_RAM must be second and CXL_DECODER_MIXED must be last.
+ * See mode_store()
*/
enum cxl_decoder_mode {
CXL_DECODER_NONE,
@@ -382,25 +385,25 @@ enum cxl_decoder_mode {
CXL_DECODER_DEAD,
};
+static const char * const cxl_decoder_mode_names[] = {
+ [CXL_DECODER_NONE] = "none",
+ [CXL_DECODER_RAM] = "ram",
+ [CXL_DECODER_PMEM] = "pmem",
+ [CXL_DECODER_DC0] = "dc0",
+ [CXL_DECODER_DC1] = "dc1",
+ [CXL_DECODER_DC2] = "dc2",
+ [CXL_DECODER_DC3] = "dc3",
+ [CXL_DECODER_DC4] = "dc4",
+ [CXL_DECODER_DC5] = "dc5",
+ [CXL_DECODER_DC6] = "dc6",
+ [CXL_DECODER_DC7] = "dc7",
+ [CXL_DECODER_MIXED] = "mixed",
+};
+
static inline const char *cxl_decoder_mode_name(enum cxl_decoder_mode mode)
{
- static const char * const names[] = {
- [CXL_DECODER_NONE] = "none",
- [CXL_DECODER_RAM] = "ram",
- [CXL_DECODER_PMEM] = "pmem",
- [CXL_DECODER_DC0] = "dc0",
- [CXL_DECODER_DC1] = "dc1",
- [CXL_DECODER_DC2] = "dc2",
- [CXL_DECODER_DC3] = "dc3",
- [CXL_DECODER_DC4] = "dc4",
- [CXL_DECODER_DC5] = "dc5",
- [CXL_DECODER_DC6] = "dc6",
- [CXL_DECODER_DC7] = "dc7",
- [CXL_DECODER_MIXED] = "mixed",
- };
-
if (mode >= CXL_DECODER_NONE && mode <= CXL_DECODER_MIXED)
- return names[mode];
+ return cxl_decoder_mode_names[mode];
return "mixed";
}