mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Frank.Li@oss.nxp.com, Jon Mason <jdmason@kudzu.us>,
	Allen Hubbe <allenbh@gmail.com>, Frank Li <Frank.Li@nxp.com>,
	"open list:NTB DRIVER CORE" <ntb@lists.linux.dev>,
	open list <linux-kernel@vger.kernel.org>
Cc: imx@lists.linux.dev, vkoul@kernel.org
Subject: Re: [PATCH v2 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev
Date: Mon, 21 Sep 2026 16:09:04 -0700	[thread overview]
Message-ID: <cb8b0e2a-dadb-45dc-a1dc-80b9944fb06b@intel.com> (raw)
In-Reply-To: <20260921203910.1350228-1-Frank.Li@oss.nxp.com>



On 9/21/26 1:39 PM, Frank.Li@oss.nxp.com wrote:
> From: Frank Li <Frank.Li@nxp.com>
> 
> Replace direct dma_chan::device::dev access with the proper
> dmaengine_get_dma_device() accessor in NTB 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>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
> change in v2
> - fix commit message wrong mention IIO (copy-parste error). (report by
> sashkio)
> ---
>  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 f9caa1a653c5b..890697cfc6b96 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);


      reply	other threads:[~2026-09-21 23:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 20:39 Frank.Li
2026-09-21 23:09 ` Dave Jiang [this message]

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=cb8b0e2a-dadb-45dc-a1dc-80b9944fb06b@intel.com \
    --to=dave.jiang@intel.com \
    --cc=Frank.Li@nxp.com \
    --cc=Frank.Li@oss.nxp.com \
    --cc=allenbh@gmail.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

all inboxes | Powered by JetHome®