]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
scsi: cxlflash: Read host function configuration
authorUma Krishnan <ukrishn@linux.vnet.ibm.com>
Mon, 26 Mar 2018 16:31:09 +0000 (11:31 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 18 Apr 2018 23:32:47 +0000 (19:32 -0400)
Per the OCXL specification, the underlying host can have multiple AFUs per
function with each function supporting its own configuration. The host
function configuration is read on the initialization path to evaluate the
number of functions present and identify the features and configuration of the
functions present. This data is cached for use in later configuration
steps. Note that for the OCXL hardware supported by the cxlflash driver, only
one AFU per function is expected.

Signed-off-by: Uma Krishnan <ukrishn@linux.vnet.ibm.com>
Acked-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Reviewed-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/cxlflash/ocxl_hw.c
drivers/scsi/cxlflash/ocxl_hw.h

index e3a0a9b42e8f0c9dbf46cec831f364e20de8b0d7..85c0f84f2a68bf43b496e96117ce519c66dc5e00 100644 (file)
@@ -31,6 +31,38 @@ static void ocxlflash_destroy_afu(void *afu_cookie)
        kfree(afu);
 }
 
+/**
+ * ocxlflash_config_fn() - configure the host function
+ * @pdev:      PCI device associated with the host.
+ * @afu:       AFU associated with the host.
+ *
+ * Return: 0 on success, -errno on failure
+ */
+static int ocxlflash_config_fn(struct pci_dev *pdev, struct ocxl_hw_afu *afu)
+{
+       struct ocxl_fn_config *fcfg = &afu->fcfg;
+       struct device *dev = &pdev->dev;
+       int rc = 0;
+
+       /* Read DVSEC config of the function */
+       rc = ocxl_config_read_function(pdev, fcfg);
+       if (unlikely(rc)) {
+               dev_err(dev, "%s: ocxl_config_read_function failed rc=%d\n",
+                       __func__, rc);
+               goto out;
+       }
+
+       /* Check if function has AFUs defined, only 1 per function supported */
+       if (fcfg->max_afu_index >= 0) {
+               afu->is_present = true;
+               if (fcfg->max_afu_index != 0)
+                       dev_warn(dev, "%s: Unexpected AFU index value %d\n",
+                                __func__, fcfg->max_afu_index);
+       }
+out:
+       return rc;
+}
+
 /**
  * ocxlflash_create_afu() - create the AFU for OCXL
  * @pdev:      PCI device associated with the host.
@@ -41,6 +73,7 @@ static void *ocxlflash_create_afu(struct pci_dev *pdev)
 {
        struct device *dev = &pdev->dev;
        struct ocxl_hw_afu *afu;
+       int rc;
 
        afu = kzalloc(sizeof(*afu), GFP_KERNEL);
        if (unlikely(!afu)) {
@@ -50,8 +83,19 @@ static void *ocxlflash_create_afu(struct pci_dev *pdev)
 
        afu->pdev = pdev;
        afu->dev = dev;
+
+       rc = ocxlflash_config_fn(pdev, afu);
+       if (unlikely(rc)) {
+               dev_err(dev, "%s: Function configuration failed rc=%d\n",
+                       __func__, rc);
+               goto err1;
+       }
 out:
        return afu;
+err1:
+       kfree(afu);
+       afu = NULL;
+       goto out;
 }
 
 /* Backend ops to ocxlflash services */
index c7e5c4dba49ca4a8f6eede1c83fcdb5fca84400b..356a6a36be5c613aa81e2ea553afdeca14b5b143 100644 (file)
@@ -16,4 +16,8 @@
 struct ocxl_hw_afu {
        struct pci_dev *pdev;           /* PCI device */
        struct device *dev;             /* Generic device */
+
+       struct ocxl_fn_config fcfg;     /* DVSEC config of the function */
+
+       bool is_present;                /* Function has AFUs defined */
 };