Commit 65a54646 authored by Christoph Hellwig's avatar Christoph Hellwig

nvme-pci: simplify nvme_dbbuf_dma_alloc

Move the OACS check and the error checking into nvme_dbbuf_dma_alloc so
that an upcoming second caller doesn't have to duplicate this boilerplate
code.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
parent a6ee7f19
...@@ -239,10 +239,13 @@ static inline unsigned int nvme_dbbuf_size(struct nvme_dev *dev) ...@@ -239,10 +239,13 @@ static inline unsigned int nvme_dbbuf_size(struct nvme_dev *dev)
return dev->nr_allocated_queues * 8 * dev->db_stride; return dev->nr_allocated_queues * 8 * dev->db_stride;
} }
static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev) static void nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
{ {
unsigned int mem_size = nvme_dbbuf_size(dev); unsigned int mem_size = nvme_dbbuf_size(dev);
if (!(dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP))
return;
if (dev->dbbuf_dbs) { if (dev->dbbuf_dbs) {
/* /*
* Clear the dbbuf memory so the driver doesn't observe stale * Clear the dbbuf memory so the driver doesn't observe stale
...@@ -250,25 +253,27 @@ static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev) ...@@ -250,25 +253,27 @@ static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
*/ */
memset(dev->dbbuf_dbs, 0, mem_size); memset(dev->dbbuf_dbs, 0, mem_size);
memset(dev->dbbuf_eis, 0, mem_size); memset(dev->dbbuf_eis, 0, mem_size);
return 0; return;
} }
dev->dbbuf_dbs = dma_alloc_coherent(dev->dev, mem_size, dev->dbbuf_dbs = dma_alloc_coherent(dev->dev, mem_size,
&dev->dbbuf_dbs_dma_addr, &dev->dbbuf_dbs_dma_addr,
GFP_KERNEL); GFP_KERNEL);
if (!dev->dbbuf_dbs) if (!dev->dbbuf_dbs)
return -ENOMEM; goto fail;
dev->dbbuf_eis = dma_alloc_coherent(dev->dev, mem_size, dev->dbbuf_eis = dma_alloc_coherent(dev->dev, mem_size,
&dev->dbbuf_eis_dma_addr, &dev->dbbuf_eis_dma_addr,
GFP_KERNEL); GFP_KERNEL);
if (!dev->dbbuf_eis) { if (!dev->dbbuf_eis)
dma_free_coherent(dev->dev, mem_size, goto fail_free_dbbuf_dbs;
dev->dbbuf_dbs, dev->dbbuf_dbs_dma_addr); return;
dev->dbbuf_dbs = NULL;
return -ENOMEM;
}
return 0; fail_free_dbbuf_dbs:
dma_free_coherent(dev->dev, mem_size, dev->dbbuf_dbs,
dev->dbbuf_dbs_dma_addr);
dev->dbbuf_dbs = NULL;
fail:
dev_warn(dev->dev, "unable to allocate dma for dbbuf\n");
} }
static void nvme_dbbuf_dma_free(struct nvme_dev *dev) static void nvme_dbbuf_dma_free(struct nvme_dev *dev)
...@@ -2855,12 +2860,7 @@ static void nvme_reset_work(struct work_struct *work) ...@@ -2855,12 +2860,7 @@ static void nvme_reset_work(struct work_struct *work)
if (result) if (result)
goto out; goto out;
if (dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP) { nvme_dbbuf_dma_alloc(dev);
result = nvme_dbbuf_dma_alloc(dev);
if (result)
dev_warn(dev->dev,
"unable to allocate dma for dbbuf\n");
}
if (dev->ctrl.hmpre) { if (dev->ctrl.hmpre) {
result = nvme_setup_host_mem(dev); result = nvme_setup_host_mem(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment