From: Matthew Wilcox Date: Sun, 10 Feb 2019 17:12:38 +0000 (-0500) Subject: cxlflash: Convert context idr to an IDA X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f2332c07865c1d9ca7b617fa00cf8728ec320282;p=users%2Fwilly%2Fxarray.git cxlflash: Convert context idr to an IDA 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 --- diff --git a/drivers/scsi/cxlflash/ocxl_hw.c b/drivers/scsi/cxlflash/ocxl_hw.c index 7018cd802569..ffe4fdf79874 100644 --- a/drivers/scsi/cxlflash/ocxl_hw.c +++ b/drivers/scsi/cxlflash/ocxl_hw.c @@ -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; diff --git a/drivers/scsi/cxlflash/ocxl_hw.h b/drivers/scsi/cxlflash/ocxl_hw.h index fc6ad4f985de..a72f8cf28516 100644 --- a/drivers/scsi/cxlflash/ocxl_hw.h +++ b/drivers/scsi/cxlflash/ocxl_hw.h @@ -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 */ };