]> www.infradead.org Git - users/willy/xarray.git/commitdiff
cxlflash: Convert context idr to an IDA
authorMatthew Wilcox <willy@infradead.org>
Sun, 10 Feb 2019 17:12:38 +0000 (12:12 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:47 +0000 (23:39 -0400)
This driver does not look up the pointers it stores, so it can use the
IDA instead of the IDR or XArray, consuming less memory.  Also actually
store the max instead of one greater than the max in the variable
called pasid_max.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/scsi/cxlflash/ocxl_hw.c
drivers/scsi/cxlflash/ocxl_hw.h

index 7018cd8025694b6c7a7cac540ac959ea69e5a983..ffe4fdf798740bfb9e91e7191293cdd6e6c0cd12 100644 (file)
@@ -493,11 +493,10 @@ static void *ocxlflash_dev_context_init(struct pci_dev *pdev, void *afu_cookie)
                goto err1;
        }
 
-       idr_preload(GFP_KERNEL);
-       rc = idr_alloc(&afu->idr, ctx, 0, afu->max_pasid, GFP_NOWAIT);
-       idr_preload_end();
+       rc = ida_alloc_max(&afu->ctx_ids, afu->max_pasid, GFP_KERNEL);
        if (unlikely(rc < 0)) {
-               dev_err(dev, "%s: idr_alloc failed rc=%d\n", __func__, rc);
+               dev_err(dev, "%s: Context ID alloc failed rc=%d\n", __func__,
+                               rc);
                goto err2;
        }
 
@@ -548,7 +547,7 @@ static int ocxlflash_release_context(void *ctx_cookie)
        }
        mutex_unlock(&ctx->state_mutex);
 
-       idr_remove(&ctx->hw_afu->idr, ctx->pe);
+       ida_free(&ctx->hw_afu->ctx_ids, ctx->pe);
        ocxlflash_release_mapping(ctx);
        kfree(ctx);
 out:
@@ -708,7 +707,6 @@ static void ocxlflash_destroy_afu(void *afu_cookie)
                return;
 
        ocxlflash_release_context(afu->ocxl_ctx);
-       idr_destroy(&afu->idr);
 
        /* Disable the AFU */
        pos = afu->acfg.dvsec_afu_control_pos;
@@ -882,7 +880,7 @@ static int ocxlflash_config_afu(struct pci_dev *pdev, struct ocxl_hw_afu *afu)
        dev_dbg(dev, "%s: acTag base=%d enabled=%d\n", __func__, base, count);
        afu->afu_actag_base = base;
        afu->afu_actag_enabled = count;
-       afu->max_pasid = 1 << acfg->pasid_supported_log;
+       afu->max_pasid = (1 << acfg->pasid_supported_log) - 1;
 
        ocxl_config_set_afu_pasid(pdev, pos, 0, acfg->pasid_supported_log);
 
@@ -920,7 +918,7 @@ static void *ocxlflash_create_afu(struct pci_dev *pdev)
 
        afu->pdev = pdev;
        afu->dev = dev;
-       idr_init(&afu->idr);
+       ida_init(&afu->ctx_ids);
 
        rc = ocxlflash_config_fn(pdev, afu);
        if (unlikely(rc)) {
@@ -952,7 +950,6 @@ err3:
 err2:
        ocxlflash_unconfig_fn(pdev, afu);
 err1:
-       idr_destroy(&afu->idr);
        kfree(afu);
        afu = NULL;
        goto out;
index fc6ad4f985defbdd611d7ae18c4055b81556365d..a72f8cf28516fb2d9ffb95a2fedc87e173d7f586 100644 (file)
@@ -37,7 +37,7 @@ struct ocxl_hw_afu {
        void __iomem *gmmio_virt;       /* Global MMIO map */
 
        void *link_token;               /* Link token for the SPA */
-       struct idr idr;                 /* IDR to manage contexts */
+       struct ida ctx_ids;             /* Context ID allocations */
        int max_pasid;                  /* Maximum number of contexts */
        bool is_present;                /* Function has AFUs defined */
 };