[PATCH v2 2/3] NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
Koichiro Den <[email protected]> Fri, 6 Mar 2026 12:14:42 +0900
| Newsgroups | dev.linux.lists.ntb,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci |
|---|---|
| Message-ID | <[email protected]> |
ntb_transport currently uses ndev->pdev->dev for coherent allocations and frees. Switch the coherent buffer allocation/free paths to use ntb_get_dma_dev(), so ntb_transport can work with NTB implementations where the NTB PCI function is not the right device to use for DMA mappings. Suggested-by: Frank Li <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Signed-off-by: Koichiro Den <[email protected]> --- drivers/ntb/ntb_transport.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index 78e02fe6caba..a67cc26e47b9 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -759,13 +759,13 @@ static void ntb_transport_msi_desc_changed(void *data) static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw) { struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; - struct pci_dev *pdev = nt->ndev->pdev; + struct device *dma_dev = ntb_get_dma_dev(nt->ndev); if (!mw->virt_addr) return; ntb_mw_clear_trans(nt->ndev, PIDX, num_mw); - dma_free_coherent(&pdev->dev, mw->alloc_size, + dma_free_coherent(dma_dev, mw->alloc_size, mw->alloc_addr, mw->dma_addr); mw->xlat_size = 0; mw->buff_size = 0; @@ -835,7 +835,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, resource_size_t size) { struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; - struct pci_dev *pdev = nt->ndev->pdev; + struct device *dma_dev = ntb_get_dma_dev(nt->ndev); size_t xlat_size, buff_size; resource_size_t xlat_align; resource_size_t xlat_align_size; @@ -864,12 +864,12 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, mw->buff_size = buff_size; mw->alloc_size = buff_size; - rc = ntb_alloc_mw_buffer(mw, &pdev->dev, xlat_align); + rc = ntb_alloc_mw_buffer(mw, dma_dev, xlat_align); if (rc) { mw->alloc_size *= 2; - rc = ntb_alloc_mw_buffer(mw, &pdev->dev, xlat_align); + rc = ntb_alloc_mw_buffer(mw, dma_dev, xlat_align); if (rc) { - dev_err(&pdev->dev, + dev_err(dma_dev, "Unable to alloc aligned MW buff\n"); mw->xlat_size = 0; mw->buff_size = 0; @@ -882,7 +882,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, rc = ntb_mw_set_trans(nt->ndev, PIDX, num_mw, mw->dma_addr, mw->xlat_size); if (rc) { - dev_err(&pdev->dev, "Unable to set mw%d translation", num_mw); + dev_err(dma_dev, "Unable to set mw%d translation", num_mw); ntb_free_mw(nt, num_mw); return -EIO; } -- 2.51.0