[PATCH v7 7/9] nvmet: pci-epf: Use dmaengine_prep_config_single_safe() API
[email protected] Thu, 21 May 2026 11:32:53 -0400
| Newsgroups | dev.linux.lists.mhi,dev.linux.lists.imx,org.infradead.lists.linux-arm-kernel,org.infradead.lists.linux-nvme,org.kernel.vger.dmaengine,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <[email protected]> |
From: Frank Li <[email protected]> Use the new dmaengine_prep_config_single_safe() API to combine the configuration and descriptor preparation into a single call. Since dmaengine_prep_config_single_safe() performs the configuration and preparation atomically and the mutex can be removed. Tested-by: Niklas Cassel <[email protected]> Acked-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Frank Li <[email protected]> --- change in v7 - remove dma_(rx|tx)_lock totally (sashika AI) change in v6 - remove local unused variable lock (sashika AI) --- drivers/nvme/target/pci-epf.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/drivers/nvme/target/pci-epf.c b/drivers/nvme/target/pci-epf.c index 2afe8f4d0e461..b1ba2d0bea6d9 100644 --- a/drivers/nvme/target/pci-epf.c +++ b/drivers/nvme/target/pci-epf.c @@ -210,9 +210,7 @@ struct nvmet_pci_epf { bool dma_enabled; struct dma_chan *dma_tx_chan; - struct mutex dma_tx_lock; struct dma_chan *dma_rx_chan; - struct mutex dma_rx_lock; struct mutex mmio_lock; @@ -295,9 +293,6 @@ static void nvmet_pci_epf_init_dma(struct nvmet_pci_epf *nvme_epf) struct dma_chan *chan; dma_cap_mask_t mask; - mutex_init(&nvme_epf->dma_rx_lock); - mutex_init(&nvme_epf->dma_tx_lock); - dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); @@ -336,8 +331,6 @@ static void nvmet_pci_epf_init_dma(struct nvmet_pci_epf *nvme_epf) nvme_epf->dma_rx_chan = NULL; out_dma_no_rx: - mutex_destroy(&nvme_epf->dma_rx_lock); - mutex_destroy(&nvme_epf->dma_tx_lock); nvme_epf->dma_enabled = false; dev_info(&epf->dev, "DMA not supported, falling back to MMIO\n"); @@ -352,8 +345,6 @@ static void nvmet_pci_epf_deinit_dma(struct nvmet_pci_epf *nvme_epf) nvme_epf->dma_tx_chan = NULL; dma_release_channel(nvme_epf->dma_rx_chan); nvme_epf->dma_rx_chan = NULL; - mutex_destroy(&nvme_epf->dma_rx_lock); - mutex_destroy(&nvme_epf->dma_tx_lock); nvme_epf->dma_enabled = false; } @@ -368,18 +359,15 @@ static int nvmet_pci_epf_dma_transfer(struct nvmet_pci_epf *nvme_epf, struct dma_chan *chan; dma_cookie_t cookie; dma_addr_t dma_addr; - struct mutex *lock; int ret; switch (dir) { case DMA_FROM_DEVICE: - lock = &nvme_epf->dma_rx_lock; chan = nvme_epf->dma_rx_chan; sconf.direction = DMA_DEV_TO_MEM; sconf.src_addr = seg->pci_addr; break; case DMA_TO_DEVICE: - lock = &nvme_epf->dma_tx_lock; chan = nvme_epf->dma_tx_chan; sconf.direction = DMA_MEM_TO_DEV; sconf.dst_addr = seg->pci_addr; @@ -388,22 +376,15 @@ static int nvmet_pci_epf_dma_transfer(struct nvmet_pci_epf *nvme_epf, return -EINVAL; } - mutex_lock(lock); - dma_dev = dmaengine_get_dma_device(chan); dma_addr = dma_map_single(dma_dev, seg->buf, seg->length, dir); ret = dma_mapping_error(dma_dev, dma_addr); if (ret) - goto unlock; - - ret = dmaengine_slave_config(chan, &sconf); - if (ret) { - dev_err(dev, "Failed to configure DMA channel\n"); - goto unmap; - } + return ret; - desc = dmaengine_prep_slave_single(chan, dma_addr, seg->length, - sconf.direction, DMA_CTRL_ACK); + desc = dmaengine_prep_config_single_safe(chan, dma_addr, seg->length, + sconf.direction, + DMA_CTRL_ACK, &sconf); if (!desc) { dev_err(dev, "Failed to prepare DMA\n"); ret = -EIO; @@ -426,9 +407,6 @@ static int nvmet_pci_epf_dma_transfer(struct nvmet_pci_epf *nvme_epf, unmap: dma_unmap_single(dma_dev, dma_addr, seg->length, dir); -unlock: - mutex_unlock(lock); - return ret; } -- 2.43.0