mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-06-11 15:46:40 +02:00
NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
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 <Frank.Li@nxp.com> Signed-off-by: Koichiro Den <den@valinux.co.jp> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Link: https://patch.msgid.link/20260306031443.1911860-3-den@valinux.co.jp
This commit is contained in:
committed by
Bjorn Helgaas
parent
362a4549f2
commit
852b94ff92
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user