Re: [PATCH 6/7] cxl/mem: Create a helper to setup device regs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 7 Apr 2021 15:26:24 -0700
Ben Widawsky <ben.widawsky@xxxxxxxxx> wrote:

> Memory devices have a list of required register regions within the
> register block, but this isn't required of all CXL components or
> devices. To make things more tidy, and allow for easily setting up other
> block types in this loop, the helper is introduced.

Two things in here, the move and allowing it to be missing.
I would call that out explicitly in the patch description.

> 
> Signed-off-by: Ben Widawsky <ben.widawsky@xxxxxxxxx>
> ---
>  drivers/cxl/mem.c | 38 +++++++++++++++++++++++---------------
>  1 file changed, 23 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
> index 49f651694cb0..b7342aaf38c4 100644
> --- a/drivers/cxl/mem.c
> +++ b/drivers/cxl/mem.c
> @@ -974,6 +974,24 @@ static int cxl_mem_dvsec(struct pci_dev *pdev, int dvsec)
>  	return 0;
>  }
>  
> +static int __cxl_setup_device_regs(struct cxl_mem *cxlm, void __iomem *base)

Naming is a little unusual.   Normally __ would imply unlocked or something
like that, whereas here it's mostly implying more error checks.

I don't immediately have a good idea for a name however...

> +{
> +	struct cxl_regs *regs = &cxlm->regs;
> +	struct pci_dev *pdev = cxlm->pdev;
> +	struct device *dev = &pdev->dev;
> +
> +	cxl_setup_device_regs(dev, base, &regs->device_regs);
> +	if (!regs->status || !regs->mbox || !regs->memdev) {
> +		dev_err(dev, "registers not found: %s%s%s\n",
> +				!regs->status ? "status " : "",
> +				!regs->mbox ? "mbox " : "",
> +				!regs->memdev ? "memdev" : "");
> +		return -ENXIO;
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * cxl_mem_setup_regs() - Setup necessary MMIO.
>   * @cxlm: The CXL memory device to communicate with.
> @@ -986,12 +1004,11 @@ static int cxl_mem_dvsec(struct pci_dev *pdev, int dvsec)
>   */
>  static int cxl_mem_setup_regs(struct cxl_mem *cxlm)
>  {
> -	struct cxl_regs *regs = &cxlm->regs;
>  	struct pci_dev *pdev = cxlm->pdev;
>  	struct device *dev = &pdev->dev;
>  	u32 regloc_size, regblocks;
>  	void __iomem *base;
> -	int regloc, i;
> +	int regloc, i, rc;
>  
>  	regloc = cxl_mem_dvsec(pdev, PCI_DVSEC_ID_CXL_REGLOC_OFFSET);
>  	if (!regloc) {
> @@ -1021,23 +1038,14 @@ static int cxl_mem_setup_regs(struct cxl_mem *cxlm)
>  			if (IS_ERR(base))
>  				return PTR_ERR(base);
>  
> -			cxl_setup_device_regs(dev, base, &regs->device_regs);
> -			if (!regs->status || !regs->mbox || !regs->memdev) {
> -				dev_err(dev, "registers not found: %s%s%s\n",
> -						!regs->status ? "status " : "",
> -						!regs->mbox ? "mbox " : "",
> -						!regs->memdev ? "memdev" : "");
> -				return -ENXIO;
> -			}
> +			rc = __cxl_setup_device_regs(cxlm, base);
> +			if (rc)
> +				return rc;
> +
>  			break;
>  		}
>  	}
>  
> -	if (i == regblocks) {
> -		dev_err(dev, "Missing register locator for device registers\n");
> -		return -ENXIO;
> -	}
> -
>  	return 0;
>  }
>  




[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux