Re: [PATCH v3 10/25] cxl/port: Add endpoint decoder DC mode support to sysfs

2024-08-23 Thread Jonathan Cameron
On Fri, 16 Aug 2024 09:44:18 -0500
[email protected] wrote:

> From: Navneet Singh 
> 
> Endpoint decoder mode is used to represent the partition the decoder
> points to such as ram or pmem.
> 
> Expand the mode to allow a decoder to point to a specific DC partition
> (Region).
> 
> Signed-off-by: Navneet Singh 
> Co-developed-by: Ira Weiny 
> Signed-off-by: Ira Weiny 
> 
Reviewed-by: Jonathan Cameron 



Re: [PATCH v3 10/25] cxl/port: Add endpoint decoder DC mode support to sysfs

2024-08-16 Thread Dave Jiang



On 8/16/24 7:44 AM, [email protected] wrote:
> From: Navneet Singh 
> 
> Endpoint decoder mode is used to represent the partition the decoder
> points to such as ram or pmem.
> 
> Expand the mode to allow a decoder to point to a specific DC partition
> (Region).
> 
> Signed-off-by: Navneet Singh 
> Co-developed-by: Ira Weiny 
> Signed-off-by: Ira Weiny 

Reviewed-by: Dave Jiang 
> 
> ---
> Changes:
> [Fan: change mode range logic]
> [Fan: use !resource_size()]
> [djiang: use the static mode name string array in mode_store()]
> [Jonathan: remove rc check from mode to region index]
> [Jonathan: clarify decoder mode 'mixed']
> [djbw: drop cleanup patch and just follow the convention in 
> cxl_dpa_set_mode()]
> [fan: make dcd resource size check similar to other partitions]
> [djbw, jonathan, fan: remove mode range check from dc_mode_to_region_index]
> [iweiny: push sysfs versions to 6.12]
> ---
>  Documentation/ABI/testing/sysfs-bus-cxl | 21 ++--
>  drivers/cxl/core/hdm.c  | 10 ++
>  drivers/cxl/core/port.c | 10 +-
>  drivers/cxl/cxl.h   | 35 
> ++---
>  4 files changed, 45 insertions(+), 31 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-cxl 
> b/Documentation/ABI/testing/sysfs-bus-cxl
> index 3f5627a1210a..957717264709 100644
> --- a/Documentation/ABI/testing/sysfs-bus-cxl
> +++ b/Documentation/ABI/testing/sysfs-bus-cxl
> @@ -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: [email protected]
>  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
> diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c
> index b4a517c6d283..ceca0b3d3e5c 100644
> --- a/drivers/cxl/core/hdm.c
> +++ b/drivers/cxl/core/hdm.c
> @@ -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:
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index 8054cbaac9f6..222aa0aeeef7 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -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,