ntb: use dmaengine_get_dma_device() instead of chan->device->dev
Subsystems (2)
PATCH v2 1/1 ntb: use dmaengine_get_dma_device() instead of chan->device->dev
From: Frank Li <[email protected]>
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.
---
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(-)
drivers/ntb/ntb_transport.c +17 -12
@@ -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 );
drivers/ntb/test/ntb_perf.c +8 -6
@@ -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 );
Signature · 1 line
2.43.0
Quoted 10 lines · On 9/21/26 1:39 PM, [email protected] wrote:
From: Frank Li <[email protected]>
Replace direct
dma_chan::device::devaccess with the properdmaengine_get_dma_device()accessor in NTB DMA consumers.
chan->device->devis 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.
Quoted 5 lines
This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.
Assisted-by LLMSigned-off-by Frank Li <[email protected]>
Quoted 177 lines
---
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(-)drivers/ntb/ntb_transport.c +17
-12@@ -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 );drivers/ntb/test/ntb_perf.c +8
-6@@ -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 );