Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Frank.Li@oss.nxp.com
To: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
	Allen Hubbe <allenbh@gmail.com>, Frank Li <Frank.Li@nxp.com>,
	ntb@lists.linux.dev (open list:NTB DRIVER CORE),
	linux-kernel@vger.kernel.org (open list)
Cc: imx@lists.linux.dev, vkoul@kernel.org
Subject: [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev
Date: Fri, 18 Sep 2026 16:41:48 -0400	[thread overview]
Message-ID: <20260918204152.2364336-1-Frank.Li@oss.nxp.com> (raw)

From: Frank Li <Frank.Li@nxp.com>

Replace direct dma_chan::device::dev access with the proper
dmaengine_get_dma_device() accessor in IIO DMA consumers.

chan->device->dev is not always the device used for DMA mapping.
Some DMA engines support per-channel IOMMU mappings, so different
channels may use different DMA devices.  dmaengine_get_dma_device()
returns the correct device for each channel.

This also prepares for making the DMA engine provider data structures
private. DMA consumers should not access DMA engine internals directly.

Assisted-by: LLM
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/ntb/ntb_transport.c | 29 +++++++++++++++++------------
 drivers/ntb/test/ntb_perf.c | 14 ++++++++------
 2 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 45144abfb7aad..895418c243642 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1519,6 +1519,7 @@ static int ntb_async_rx_submit(struct ntb_queue_entry *entry, void *offset)
 	struct ntb_transport_qp *qp = entry->qp;
 	struct dma_chan *chan = qp->rx_dma_chan;
 	struct dma_device *device;
+	struct device *dma_dev;
 	size_t pay_off, buff_off, len;
 	struct dmaengine_unmap_data *unmap;
 	dma_cookie_t cookie;
@@ -1526,27 +1527,28 @@ static int ntb_async_rx_submit(struct ntb_queue_entry *entry, void *offset)
 
 	len = entry->len;
 	device = chan->device;
+	dma_dev = dmaengine_get_dma_device(chan);
 	pay_off = (size_t)offset & ~PAGE_MASK;
 	buff_off = (size_t)buf & ~PAGE_MASK;
 
 	if (!is_dma_copy_aligned(device, pay_off, buff_off, len))
 		goto err;
 
-	unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOWAIT);
+	unmap = dmaengine_get_unmap_data(dma_dev, 2, GFP_NOWAIT);
 	if (!unmap)
 		goto err;
 
 	unmap->len = len;
-	unmap->addr[0] = dma_map_phys(device->dev, virt_to_phys(offset),
+	unmap->addr[0] = dma_map_phys(dma_dev, virt_to_phys(offset),
 				      len, DMA_TO_DEVICE, 0);
-	if (dma_mapping_error(device->dev, unmap->addr[0]))
+	if (dma_mapping_error(dma_dev, unmap->addr[0]))
 		goto err_get_unmap;
 
 	unmap->to_cnt = 1;
 
-	unmap->addr[1] = dma_map_phys(device->dev, virt_to_phys(buf),
+	unmap->addr[1] = dma_map_phys(dma_dev, virt_to_phys(buf),
 				      len, DMA_FROM_DEVICE, 0);
-	if (dma_mapping_error(device->dev, unmap->addr[1]))
+	if (dma_mapping_error(dma_dev, unmap->addr[1]))
 		goto err_get_unmap;
 
 	unmap->from_cnt = 1;
@@ -1856,6 +1858,7 @@ static int ntb_async_tx_submit(struct ntb_transport_qp *qp,
 {
 	struct dma_async_tx_descriptor *txd;
 	struct dma_chan *chan = qp->tx_dma_chan;
+	struct device *dma_dev = dmaengine_get_dma_device(chan);
 	struct dma_device *device;
 	size_t len = entry->len;
 	void *buf = entry->buf;
@@ -1872,14 +1875,14 @@ static int ntb_async_tx_submit(struct ntb_transport_qp *qp,
 	if (!is_dma_copy_aligned(device, buff_off, dest_off, len))
 		goto err;
 
-	unmap = dmaengine_get_unmap_data(device->dev, 1, GFP_NOWAIT);
+	unmap = dmaengine_get_unmap_data(dma_dev, 1, GFP_NOWAIT);
 	if (!unmap)
 		goto err;
 
 	unmap->len = len;
-	unmap->addr[0] = dma_map_phys(device->dev, virt_to_phys(buf),
+	unmap->addr[0] = dma_map_phys(dma_dev, virt_to_phys(buf),
 				      len, DMA_TO_DEVICE, 0);
-	if (dma_mapping_error(device->dev, unmap->addr[0]))
+	if (dma_mapping_error(dma_dev, unmap->addr[0]))
 		goto err_get_unmap;
 
 	unmap->to_cnt = 1;
@@ -2026,6 +2029,7 @@ ntb_transport_create_queue(void *data, struct device *client_dev,
 	struct ntb_transport_qp *qp;
 	u64 qp_bit;
 	unsigned int free_queue;
+	struct device *tx_dev;
 	dma_cap_mask_t dma_mask;
 	int node;
 	int i;
@@ -2089,11 +2093,12 @@ ntb_transport_create_queue(void *data, struct device *client_dev,
 
 	qp->tx_mw_dma_addr = 0;
 	if (qp->tx_dma_chan) {
+		tx_dev = dmaengine_get_dma_device(qp->tx_dma_chan);
 		qp->tx_mw_dma_addr =
-			dma_map_resource(qp->tx_dma_chan->device->dev,
+			dma_map_resource(tx_dev,
 					 qp->tx_mw_phys, qp->tx_mw_size,
 					 DMA_FROM_DEVICE, 0);
-		if (dma_mapping_error(qp->tx_dma_chan->device->dev,
+		if (dma_mapping_error(tx_dev,
 				      qp->tx_mw_dma_addr)) {
 			qp->tx_mw_dma_addr = 0;
 			goto err1;
@@ -2142,7 +2147,7 @@ ntb_transport_create_queue(void *data, struct device *client_dev,
 	while ((entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_free_q)))
 		kfree(entry);
 	if (qp->tx_mw_dma_addr)
-		dma_unmap_resource(qp->tx_dma_chan->device->dev,
+		dma_unmap_resource(tx_dev,
 				   qp->tx_mw_dma_addr, qp->tx_mw_size,
 				   DMA_FROM_DEVICE, 0);
 	if (qp->tx_dma_chan)
@@ -2192,7 +2197,7 @@ void ntb_transport_free_queue(struct ntb_transport_qp *qp)
 		dma_sync_wait(chan, qp->last_cookie);
 		dmaengine_terminate_all(chan);
 
-		dma_unmap_resource(chan->device->dev,
+		dma_unmap_resource(dmaengine_get_dma_device(chan),
 				   qp->tx_mw_dma_addr, qp->tx_mw_size,
 				   DMA_FROM_DEVICE, 0);
 
diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
index dfd175f79e8f0..b936f15079df2 100644
--- a/drivers/ntb/test/ntb_perf.c
+++ b/drivers/ntb/test/ntb_perf.c
@@ -799,7 +799,7 @@ static int perf_copy_chunk(struct perf_thread *pthr,
 		goto ret_check_tsync;
 	}
 
-	dma_dev = pthr->dma_chan->device->dev;
+	dma_dev = dmaengine_get_dma_device(pthr->dma_chan);
 
 	if (!is_dma_copy_aligned(pthr->dma_chan->device, offset_in_page(src),
 				 offset_in_page(dst), len))
@@ -869,6 +869,7 @@ static bool perf_dma_filter(struct dma_chan *chan, void *data)
 static int perf_init_test(struct perf_thread *pthr)
 {
 	struct perf_ctx *perf = pthr->perf;
+	struct device *dma_dev;
 	dma_cap_mask_t dma_mask;
 	struct perf_peer *peer = pthr->perf->test_peer;
 
@@ -890,19 +891,20 @@ static int perf_init_test(struct perf_thread *pthr)
 			pthr->tidx);
 		goto err_free;
 	}
+	dma_dev = dmaengine_get_dma_device(pthr->dma_chan);
 	peer->dma_dst_addr =
-		dma_map_resource(pthr->dma_chan->device->dev,
+		dma_map_resource(dma_dev,
 				 peer->out_phys_addr, peer->outbuf_size,
 				 DMA_FROM_DEVICE, 0);
-	if (dma_mapping_error(pthr->dma_chan->device->dev,
+	if (dma_mapping_error(dma_dev,
 			      peer->dma_dst_addr)) {
-		dev_err(pthr->dma_chan->device->dev, "%d: Failed to map DMA addr\n",
+		dev_err(dma_dev, "%d: Failed to map DMA addr\n",
 			pthr->tidx);
 		peer->dma_dst_addr = 0;
 		dma_release_channel(pthr->dma_chan);
 		goto err_free;
 	}
-	dev_dbg(pthr->dma_chan->device->dev, "%d: Map MMIO %pa to DMA addr %pad\n",
+	dev_dbg(dma_dev, "%d: Map MMIO %pa to DMA addr %pad\n",
 			pthr->tidx,
 			&peer->out_phys_addr,
 			&peer->dma_dst_addr);
@@ -1003,7 +1005,7 @@ static void perf_clear_test(struct perf_thread *pthr)
 	 */
 	(void)dmaengine_terminate_sync(pthr->dma_chan);
 	if (pthr->perf->test_peer->dma_dst_addr)
-		dma_unmap_resource(pthr->dma_chan->device->dev,
+		dma_unmap_resource(dmaengine_get_dma_device(pthr->dma_chan),
 				   pthr->perf->test_peer->dma_dst_addr,
 				   pthr->perf->test_peer->outbuf_size,
 				   DMA_FROM_DEVICE, 0);
-- 
2.43.0


             reply	other threads:[~2026-09-18 20:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 20:41 Frank.Li [this message]
2026-09-18 20:53 ` [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev sashiko-bot
2026-09-18 21:06   ` Frank Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260918204152.2364336-1-Frank.Li@oss.nxp.com \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@nxp.com \
    --cc=allenbh@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=imx@lists.linux.dev \
    --cc=jdmason@kudzu.us \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntb@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox