Subject: Re: [PATCH v18 12/20] sfc: get endpoint decoder

From: Jonathan Cameron <[email-masked]>
Date: Thu, 18 Sep 2025 15:53:44 +0100

On Thu, 18 Sep 2025 10:17:38 +0100
[email-masked] wrote:

> From: Alejandro Lucero <[email-masked]>
> 
> Use cxl api for getting DPA (Device Physical Address) to use through an
> endpoint decoder.
> 
> Signed-off-by: Alejandro Lucero <[email-masked]>
> Reviewed-by: Martin Habets <[email-masked]>
> Acked-by: Edward Cree <[email-masked]>
> Reviewed-by: Jonathan Cameron <[email-masked]>
> ---
>  drivers/net/ethernet/sfc/efx_cxl.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c
> index d29594e71027..4461b7a4dc2c 100644
> --- a/drivers/net/ethernet/sfc/efx_cxl.c
> +++ b/drivers/net/ethernet/sfc/efx_cxl.c
> @@ -99,16 +99,23 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
>  
>  	if (IS_ERR(cxl->cxlrd)) {
>  		pci_err(pci_dev, "cxl_get_hpa_freespace failed\n");
> -		cxl_release_endpoint(cxl->cxlmd, cxl->endpoint);
> -		return PTR_ERR(cxl->cxlrd);
> +		rc = PTR_ERR(cxl->cxlrd);
> +		goto err_release;

Push back into patch 10.  I was wondering why you didn't do this there, thn
found it here.

>  	}
>  
>  	if (max_size < EFX_CTPIO_BUFFER_SIZE) {
>  		pci_err(pci_dev, "%s: not enough free HPA space %pap < %u\n",
>  			__func__, &max_size, EFX_CTPIO_BUFFER_SIZE);
> -		cxl_put_root_decoder(cxl->cxlrd);
> -		cxl_release_endpoint(cxl->cxlmd, cxl->endpoint);
> -		return -ENOSPC;
> +		rc = -ENOSPC;
> +		goto err_decoder;
> +	}
> +
> +	cxl->cxled = cxl_request_dpa(cxl->cxlmd, CXL_PARTMODE_RAM,
> +				     EFX_CTPIO_BUFFER_SIZE);
> +	if (IS_ERR(cxl->cxled)) {
> +		pci_err(pci_dev, "CXL accel request DPA failed");
> +		rc = PTR_ERR(cxl->cxled);
> +		goto err_decoder;
>  	}
>  
>  	probe_data->cxl = cxl;
> @@ -116,12 +123,21 @@ int efx_cxl_init(struct efx_probe_data *probe_data)
>  	cxl_release_endpoint(cxl->cxlmd, cxl->endpoint);
>  
>  	return 0;
> +
> +err_decoder:
> +	cxl_put_root_decoder(cxl->cxlrd);
> +err_release:
> +	cxl_release_endpoint(cxl->cxlmd, cxl->endpoint);
> +
> +	return rc;
>  }
>  
>  void efx_cxl_exit(struct efx_probe_data *probe_data)
>  {
> -	if (probe_data->cxl)
> +	if (probe_data->cxl) {
> +		cxl_dpa_free(probe_data->cxl->cxled);
>  		cxl_put_root_decoder(probe_data->cxl->cxlrd);
> +	}
>  }
>  
>  MODULE_IMPORT_NS("CXL");