* [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev
@ 2026-09-18 20:41 Frank.Li
2026-09-18 20:53 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Frank.Li @ 2026-09-18 20:41 UTC (permalink / raw)
To: Jon Mason, Dave Jiang, Allen Hubbe, Frank Li,
open list:NTB DRIVER CORE, open list
Cc: imx, vkoul
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev
2026-09-18 20:41 [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev Frank.Li
@ 2026-09-18 20:53 ` sashiko-bot
2026-09-18 21:06 ` Frank Li
0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-09-18 20:53 UTC (permalink / raw)
To: Frank.Li; +Cc: imx, Frank.Li, ntb
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] ntb: missed replacing chan->device->dev in perf_dma_filter()
- [Low] ntb: commit message incorrectly mentions IIO instead of NTB
--
commit 00ad86ab4ff3c677b79412d332638c7a5186dbbe
Author: Frank Li <Frank.Li@nxp.com>
ntb: use dmaengine_get_dma_device() instead of chan->device->dev
This commit replaces direct chan->device->dev access with the proper
dmaengine_get_dma_device() accessor in NTB DMA consumers. It prepares
for making the DMA engine provider data structures private.
> Replace direct dma_chan::device::dev access with the proper
> dmaengine_get_dma_device() accessor in IIO DMA consumers.
[Severity: Low]
This isn't a bug, but the commit message incorrectly mentions IIO DMA
consumers instead of NTB DMA consumers.
> 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
[ ... ]
> @@ -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;
[Severity: Medium]
Does this patch miss a replacement in perf_dma_filter()?
Right above this hunk, perf_dma_filter() still accesses chan->device->dev
directly:
drivers/ntb/test/ntb_perf.c:perf_dma_filter() {
...
return node == NUMA_NO_NODE || node == dev_to_node(chan->device->dev);
}
Since the goal is to prepare for making DMA engine structures private by
abstracting chan->device->dev behind dmaengine_get_dma_device(chan), will
leaving this direct access cause a build failure once the structure is made
private?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260918204152.2364336-1-Frank.Li@oss.nxp.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev
2026-09-18 20:53 ` sashiko-bot
@ 2026-09-18 21:06 ` Frank Li
0 siblings, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-09-18 21:06 UTC (permalink / raw)
To: sashiko-reviews; +Cc: imx, Frank.Li, ntb
On Fri, Sep 18, 2026 at 08:53:23PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] ntb: missed replacing chan->device->dev in perf_dma_filter()
> - [Low] ntb: commit message incorrectly mentions IIO instead of NTB
> --
>
> commit 00ad86ab4ff3c677b79412d332638c7a5186dbbe
> Author: Frank Li <Frank.Li@nxp.com>
>
> ntb: use dmaengine_get_dma_device() instead of chan->device->dev
>
> This commit replaces direct chan->device->dev access with the proper
> dmaengine_get_dma_device() accessor in NTB DMA consumers. It prepares
> for making the DMA engine provider data structures private.
>
> > Replace direct dma_chan::device::dev access with the proper
> > dmaengine_get_dma_device() accessor in IIO DMA consumers.
>
> [Severity: Low]
> This isn't a bug, but the commit message incorrectly mentions IIO DMA
> consumers instead of NTB DMA consumers.
>
> > 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
> [ ... ]
> > @@ -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;
>
> [Severity: Medium]
> Does this patch miss a replacement in perf_dma_filter()?
>
> Right above this hunk, perf_dma_filter() still accesses chan->device->dev
> directly:
>
> drivers/ntb/test/ntb_perf.c:perf_dma_filter() {
> ...
> return node == NUMA_NO_NODE || node == dev_to_node(chan->device->dev);
> }
Can't simple replace it here. Following patch will handle it by add
new DMA Engine API.
which require dma provider device to get dma channel. if return per channel
device, will fail to get dma chan.
Frank
>
> Since the goal is to prepare for making DMA engine structures private by
> abstracting chan->device->dev behind dmaengine_get_dma_device(chan), will
> leaving this direct access cause a build failure once the structure is made
> private?
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260918204152.2364336-1-Frank.Li@oss.nxp.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-18 21:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18 20:41 [PATCH 1/1] ntb: use dmaengine_get_dma_device() instead of chan->device->dev Frank.Li
2026-09-18 20:53 ` sashiko-bot
2026-09-18 21:06 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox