]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
UBUNTU: SAUCE: cxlflash: Use IDR to manage adapter contexts
authorUma Krishnan <ukrishn@linux.vnet.ibm.com>
Thu, 26 Oct 2017 19:35:21 +0000 (14:35 -0500)
committerSeth Forshee <seth.forshee@canonical.com>
Tue, 27 Mar 2018 19:10:07 +0000 (14:10 -0500)
BugLink: http://bugs.launchpad.net/bugs/1752672
A range of PASIDs are used as identifiers for the adapter contexts. These
contexts may be destroyed and created randomly. Use an IDR to keep track
of contexts that are in use and assign a unique identifier to new ones.

Signed-off-by: Uma Krishnan <ukrishn@linux.vnet.ibm.com>
Acked-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
drivers/scsi/cxlflash/ocxl_hw.c
drivers/scsi/cxlflash/ocxl_hw.h

index d75b8737f05fec4a34767fd6d5dbd6fc1792df49..64722104483bf6cc2b11f9f6212d02f4b4a49cd4 100644 (file)
@@ -12,6 +12,8 @@
  * 2 of the License, or (at your option) any later version.
  */
 
+#include <linux/idr.h>
+
 #include <misc/ocxl.h>
 
 #include "backend.h"
@@ -60,14 +62,25 @@ static void *ocxlflash_dev_context_init(struct pci_dev *pdev, void *afu_cookie)
        if (unlikely(!ctx)) {
                dev_err(dev, "%s: Context allocation failed\n", __func__);
                rc = -ENOMEM;
-               goto err;
+               goto err1;
+       }
+
+       idr_preload(GFP_KERNEL);
+       rc = idr_alloc(&afu->idr, ctx, 0, afu->max_pasid, GFP_NOWAIT);
+       idr_preload_end();
+       if (unlikely(rc < 0)) {
+               dev_err(dev, "%s: idr_alloc failed rc=%d\n", __func__, rc);
+               goto err2;
        }
 
+       ctx->pe = rc;
        ctx->master = false;
        ctx->hw_afu = afu;
 out:
        return ctx;
-err:
+err2:
+       kfree(ctx);
+err1:
        ctx = ERR_PTR(rc);
        goto out;
 }
@@ -86,6 +99,7 @@ static int ocxlflash_release_context(void *ctx_cookie)
        if (!ctx)
                goto out;
 
+       idr_remove(&ctx->hw_afu->idr, ctx->pe);
        kfree(ctx);
 out:
        return rc;
@@ -103,6 +117,7 @@ static void ocxlflash_destroy_afu(void *afu_cookie)
                return;
 
        ocxlflash_release_context(afu->ocxl_ctx);
+       idr_destroy(&afu->idr);
        kfree(afu);
 }
 
@@ -237,6 +252,7 @@ static void *ocxlflash_create_afu(struct pci_dev *pdev)
                goto err1;
        }
 
+       idr_init(&afu->idr);
        afu->ocxl_ctx = ctx;
 out:
        return afu;
index de43c049780edf286a0feaa4aa52eaeaa140d7aa..0381682b1f7a73eaa0d1feaa64c14af9e83cb175 100644 (file)
@@ -26,10 +26,12 @@ struct ocxl_hw_afu {
        int afu_actag_base;             /* AFU acTag base */
        int afu_actag_enabled;          /* AFU acTag number enabled */
 
+       struct idr idr;                 /* IDR to manage contexts */
        int max_pasid;                  /* Maximum number of contexts */
 };
 
 struct ocxlflash_context {
        struct ocxl_hw_afu *hw_afu;     /* HW AFU back pointer */
        bool master;                    /* Whether this is a master context */
+       int pe;                         /* Process element */
 };