diff mbox series

[v1,09/29] cxl/region: Use iterator to find the root port in cxl_find_root_decoder()

Message ID 20250107141015.3367194-10-rrichter@amd.com
State New
Headers show
Series cxl: Add address translation support and enable AMD Zen5 platforms | expand

Commit Message

Robert Richter Jan. 7, 2025, 2:09 p.m. UTC
The function cxl_find_root_decoder() uses find_cxl_root() to find the
root port. For the implementation of support of address translation an
iterator is needed that traverses all ports from the endpoint to the
root port.

Use the iterator in find_cxl_root() and unfold it into
cxl_find_root_decoder().

Signed-off-by: Robert Richter <rrichter@amd.com>
---
 drivers/cxl/core/region.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Gregory Price Jan. 7, 2025, 5:23 p.m. UTC | #1
On Tue, Jan 07, 2025 at 03:09:55PM +0100, Robert Richter wrote:
> The function cxl_find_root_decoder() uses find_cxl_root() to find the
> root port. For the implementation of support of address translation an
> iterator is needed that traverses all ports from the endpoint to the
> root port.
> 
> Use the iterator in find_cxl_root() and unfold it into
> cxl_find_root_decoder().
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>
> ---
>  drivers/cxl/core/region.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 

I wonder if we can expose this mapping in the sysfs hierarchy, because
I've always been frustrated about how confusing what decoders/endpoints
relate to each other.

(I say this not looking forward in the series to see if you did exactly
this, just spitballing)

Reviewed-by: Gregory Price <gourry@gourry.net>

> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 5132c689b1f2..5750ed2796a8 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3206,13 +3206,18 @@ static struct cxl_root_decoder *
>  cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
>  {
>  	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> -	struct cxl_port *port = cxled_to_port(cxled);
> -	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
> +	struct cxl_port *iter = cxled_to_port(cxled);
>  	struct range *hpa = &cxled->cxld.hpa_range;
>  	struct cxl_decoder *cxld = &cxled->cxld;
>  	struct device *cxlrd_dev;
>  
> -	cxlrd_dev = device_find_child(&cxl_root->port.dev, hpa,
> +	while (iter && !is_cxl_root(iter))
> +		iter = to_cxl_port(iter->dev.parent);
> +
> +	if (!iter)
> +		return NULL;
> +
> +	cxlrd_dev = device_find_child(&iter->dev, hpa,
>  				      match_root_decoder_by_range);
>  	if (!cxlrd_dev) {
>  		dev_err(cxlmd->dev.parent,
> -- 
> 2.39.5
>
Jonathan Cameron Jan. 13, 2025, 6:11 p.m. UTC | #2
On Tue, 7 Jan 2025 15:09:55 +0100
Robert Richter <rrichter@amd.com> wrote:

> The function cxl_find_root_decoder() uses find_cxl_root() to find the
> root port. For the implementation of support of address translation an
> iterator is needed that traverses all ports from the endpoint to the
> root port.
> 
> Use the iterator in find_cxl_root() and unfold it into
> cxl_find_root_decoder().
> 
> Signed-off-by: Robert Richter <rrichter@amd.com>

It is functionally the same. So I'll assume it makes sense later :)

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/cxl/core/region.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 5132c689b1f2..5750ed2796a8 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3206,13 +3206,18 @@ static struct cxl_root_decoder *
>  cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
>  {
>  	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
> -	struct cxl_port *port = cxled_to_port(cxled);
> -	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
> +	struct cxl_port *iter = cxled_to_port(cxled);
>  	struct range *hpa = &cxled->cxld.hpa_range;
>  	struct cxl_decoder *cxld = &cxled->cxld;
>  	struct device *cxlrd_dev;
>  
> -	cxlrd_dev = device_find_child(&cxl_root->port.dev, hpa,
> +	while (iter && !is_cxl_root(iter))
> +		iter = to_cxl_port(iter->dev.parent);
> +
> +	if (!iter)
> +		return NULL;
> +
> +	cxlrd_dev = device_find_child(&iter->dev, hpa,
>  				      match_root_decoder_by_range);
>  	if (!cxlrd_dev) {
>  		dev_err(cxlmd->dev.parent,
diff mbox series

Patch

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 5132c689b1f2..5750ed2796a8 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3206,13 +3206,18 @@  static struct cxl_root_decoder *
 cxl_find_root_decoder(struct cxl_endpoint_decoder *cxled)
 {
 	struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
-	struct cxl_port *port = cxled_to_port(cxled);
-	struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
+	struct cxl_port *iter = cxled_to_port(cxled);
 	struct range *hpa = &cxled->cxld.hpa_range;
 	struct cxl_decoder *cxld = &cxled->cxld;
 	struct device *cxlrd_dev;
 
-	cxlrd_dev = device_find_child(&cxl_root->port.dev, hpa,
+	while (iter && !is_cxl_root(iter))
+		iter = to_cxl_port(iter->dev.parent);
+
+	if (!iter)
+		return NULL;
+
+	cxlrd_dev = device_find_child(&iter->dev, hpa,
 				      match_root_decoder_by_range);
 	if (!cxlrd_dev) {
 		dev_err(cxlmd->dev.parent,