diff mbox series

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

Message ID 20210407222625.320177-7-ben.widawsky@intel.com
State New, archived
Headers show
Series Enumerate HDM Decoder registers | expand

Commit Message

Ben Widawsky April 7, 2021, 10:26 p.m. UTC
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.

Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
---
 drivers/cxl/mem.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

Comments

Jonathan Cameron April 8, 2021, 5:33 p.m. UTC | #1
On Wed, 7 Apr 2021 15:26:24 -0700
Ben Widawsky <ben.widawsky@intel.com> 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@intel.com>
> ---
>  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;
>  }
>
Dan Williams April 15, 2021, 10:54 p.m. UTC | #2
On Wed, Apr 7, 2021 at 3:26 PM Ben Widawsky <ben.widawsky@intel.com> 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.

I don't understand the point of this or the organization choice.
cxl_setup_device_regs() *is* the core implementation so there
shouldn't be a "__" prefixed version wrapping it. I agree that some
users will not care that some of the device registers are not found,
but that won't be cxl_mem_setup_regs() making that call.
diff mbox series

Patch

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)
+{
+	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;
 }