cxl/region: Add a mode attribute for regions
authorDan Williams <dan.j.williams@intel.com>
Fri, 10 Feb 2023 09:05:39 +0000 (01:05 -0800)
committerDan Williams <dan.j.williams@intel.com>
Sat, 11 Feb 2023 01:31:58 +0000 (17:31 -0800)
In preparation for a new region type, "ram" regions, add a mode
attribute to clarify the mode of the decoders that can be added to a
region. Share the internals of mode_show() (for decoders) with the
region case.

Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Fan Ni <fan.ni@samsung.com>
Link: https://lore.kernel.org/r/167601993930.1924368.4305018565539515665.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Documentation/ABI/testing/sysfs-bus-cxl
drivers/cxl/core/port.c
drivers/cxl/core/region.c
drivers/cxl/cxl.h

index 5be032313e292bde8c87a2d29c902bbc27564e1b..058b0c45001fadd18bab14c64c26bea76e63b37f 100644 (file)
@@ -358,6 +358,17 @@ Description:
                results in the same address being allocated.
 
 
+What:          /sys/bus/cxl/devices/regionZ/mode
+Date:          January, 2023
+KernelVersion: v6.3
+Contact:       linux-cxl@vger.kernel.org
+Description:
+               (RO) The mode of a region is established at region creation time
+               and dictates the mode of the endpoint decoder that comprise the
+               region. For more details on the possible modes see
+               /sys/bus/cxl/devices/decoderX.Y/mode
+
+
 What:          /sys/bus/cxl/devices/regionZ/resource
 Date:          May, 2022
 KernelVersion: v6.0
index 317bcf4dbd9d22c3608c57cae419a1736728523d..1e541956f60550a6ce89ff541b5050952df8e2c3 100644 (file)
@@ -180,17 +180,7 @@ static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
 {
        struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev);
 
-       switch (cxled->mode) {
-       case CXL_DECODER_RAM:
-               return sysfs_emit(buf, "ram\n");
-       case CXL_DECODER_PMEM:
-               return sysfs_emit(buf, "pmem\n");
-       case CXL_DECODER_NONE:
-               return sysfs_emit(buf, "none\n");
-       case CXL_DECODER_MIXED:
-       default:
-               return sysfs_emit(buf, "mixed\n");
-       }
+       return sysfs_emit(buf, "%s\n", cxl_decoder_mode_name(cxled->mode));
 }
 
 static ssize_t mode_store(struct device *dev, struct device_attribute *attr,
index 60828d01972acf313c84b234162a25258c87662b..17d2d0c127255a564fd6b79fd5ac83ca9fa3f114 100644 (file)
@@ -458,6 +458,15 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(resource);
 
+static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       struct cxl_region *cxlr = to_cxl_region(dev);
+
+       return sysfs_emit(buf, "%s\n", cxl_decoder_mode_name(cxlr->mode));
+}
+static DEVICE_ATTR_RO(mode);
+
 static int alloc_hpa(struct cxl_region *cxlr, resource_size_t size)
 {
        struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent);
@@ -585,6 +594,7 @@ static struct attribute *cxl_region_attrs[] = {
        &dev_attr_interleave_granularity.attr,
        &dev_attr_resource.attr,
        &dev_attr_size.attr,
+       &dev_attr_mode.attr,
        NULL,
 };
 
index aa3af3bb73b20ae98ea10b0ad0457e7ba4449a66..ca76879af1de9c7deaca572f5ad880fba4c31f16 100644 (file)
@@ -320,6 +320,20 @@ enum cxl_decoder_mode {
        CXL_DECODER_DEAD,
 };
 
+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_MIXED] = "mixed",
+       };
+
+       if (mode >= CXL_DECODER_NONE && mode <= CXL_DECODER_MIXED)
+               return names[mode];
+       return "mixed";
+}
+
 /**
  * struct cxl_endpoint_decoder - Endpoint  / SPA to DPA decoder
  * @cxld: base cxl_decoder_object