From: Frank Li <Frank.li@nxp.com>
To: Koichiro Den <den@valinux.co.jp>
Cc: dave.jiang@intel.com, ntb@lists.linux.dev,
linux-pci@vger.kernel.org, dmaengine@vger.kernel.org,
linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, mani@kernel.org,
kwilczynski@kernel.org, kishon@kernel.org, bhelgaas@google.com,
corbet@lwn.net, geert+renesas@glider.be, magnus.damm@gmail.com,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
vkoul@kernel.org, joro@8bytes.org, will@kernel.org,
robin.murphy@arm.com, jdmason@kudzu.us, allenbh@gmail.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, Basavaraj.Natikar@amd.com,
Shyam-sundar.S-k@amd.com, kurt.schwemmer@microsemi.com,
logang@deltatee.com, jingoohan1@gmail.com, lpieralisi@kernel.org,
utkarsh02t@gmail.com, jbrunet@baylibre.com, dlemoal@kernel.org,
arnd@arndb.de, elfring@users.sourceforge.net
Subject: Re: [RFC PATCH v3 13/35] NTB: ntb_transport: Introduce get_dma_dev() helper
Date: Fri, 19 Dec 2025 09:31:11 -0500 [thread overview]
Message-ID: <aUVhr33M86WCAIqZ@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20251217151609.3162665-14-den@valinux.co.jp>
On Thu, Dec 18, 2025 at 12:15:47AM +0900, Koichiro Den wrote:
> When ntb_transport is used on top of an endpoint function (EPF) NTB
> implementation, DMA mappings should be associated with the underlying
> PCIe controller device rather than the virtual NTB PCI function. This
> matters for IOMMU configuration and DMA mask validation.
>
> Add a small helper, get_dma_dev(), that returns the appropriate struct
> device for DMA mapping, i.e. &pdev->dev for a regular NTB host bridge
> and the EPC parent device for EPF-based NTB endpoints. Use it in the
> places where we set up DMA mappings or log DMA-related errors.
>
> Signed-off-by: Koichiro Den <den@valinux.co.jp>
> ---
> drivers/ntb/ntb_transport.c | 35 ++++++++++++++++++++++++++++-------
> 1 file changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index bac842177b55..78d0469edbcc 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -63,6 +63,7 @@
> #include <linux/mutex.h>
> #include "linux/ntb.h"
> #include "linux/ntb_transport.h"
> +#include <linux/pci-epc.h>
>
> #define NTB_TRANSPORT_VERSION 4
> #define NTB_TRANSPORT_VER "4"
> @@ -259,6 +260,26 @@ struct ntb_payload_header {
> unsigned int flags;
> };
>
> +/*
> + * Return the device that should be used for DMA mapping.
> + *
> + * On RC, this is simply &pdev->dev.
> + * On EPF-backed NTB endpoints, use the EPC parent device so that
> + * DMA capabilities and IOMMU configuration are taken from the
> + * controller rather than the virtual NTB PCI function.
> + */
> +static struct device *get_dma_dev(struct ntb_dev *ndev)
> +{
> + struct device *dev = &ndev->pdev->dev;
> + struct pci_epc *epc;
> +
> + epc = (struct pci_epc *)ntb_get_private_data(ndev);
> + if (epc)
> + dev = epc->dev.parent;
> +
> + return dev;
> +}
> +
I think add callback .get_dma_dev() directly. So vntb epf driver to provide
a implement. The file is common for all ntb transfer, should not include
ntb lower driver's specific implmentatin.
Frank
> enum {
> VERSION = 0,
> QP_LINKS,
> @@ -771,13 +792,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 *dev = 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(dev, mw->alloc_size,
> mw->alloc_addr, mw->dma_addr);
> mw->xlat_size = 0;
> mw->buff_size = 0;
> @@ -847,7 +868,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 *dev = get_dma_dev(nt->ndev);
> size_t xlat_size, buff_size;
> resource_size_t xlat_align;
> resource_size_t xlat_align_size;
> @@ -877,12 +898,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, 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, dev, xlat_align);
> if (rc) {
> - dev_err(&pdev->dev,
> + dev_err(dev,
> "Unable to alloc aligned MW buff\n");
> mw->xlat_size = 0;
> mw->buff_size = 0;
> @@ -895,7 +916,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, offset);
> if (rc) {
> - dev_err(&pdev->dev, "Unable to set mw%d translation", num_mw);
> + dev_err(dev, "Unable to set mw%d translation", num_mw);
> ntb_free_mw(nt, num_mw);
> return -EIO;
> }
> --
> 2.51.0
>
next prev parent reply other threads:[~2025-12-19 14:31 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 15:15 [RFC PATCH v3 00/35] NTB transport backed by endpoint DW eDMA Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 01/35] PCI: endpoint: pci-epf-vntb: Use array_index_nospec() on mws_size[] access Koichiro Den
2025-12-19 3:08 ` Frank Li
2025-12-17 15:15 ` [RFC PATCH v3 02/35] NTB: epf: Add mwN_offset support and config region versioning Koichiro Den
2025-12-19 3:19 ` Frank Li
2025-12-19 7:23 ` Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 03/35] PCI: dwc: ep: Support BAR subrange inbound mapping via address match iATU Koichiro Den
2025-12-19 14:19 ` Frank Li
2025-12-20 15:36 ` Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 04/35] NTB: Add offset parameter to MW translation APIs Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 05/35] PCI: endpoint: pci-epf-vntb: Propagate MW offset from configfs when present Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 06/35] NTB: ntb_transport: Support partial memory windows with offsets Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 07/35] PCI: endpoint: pci-epf-vntb: Hint subrange mapping preference to EPC driver Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 08/35] NTB: core: Add .get_private_data() to ntb_dev_ops Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 09/35] NTB: epf: vntb: Implement .get_private_data() callback Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 10/35] dmaengine: dw-edma: Fix MSI data values for multi-vector IMWr interrupts Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 11/35] NTB: ntb_transport: Move TX memory window setup into setup_qp_mw() Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 12/35] NTB: ntb_transport: Dynamically determine qp count Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 13/35] NTB: ntb_transport: Introduce get_dma_dev() helper Koichiro Den
2025-12-19 14:31 ` Frank Li [this message]
2025-12-20 15:29 ` Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 14/35] NTB: epf: Reserve a subset of MSI vectors for non-NTB users Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 15/35] NTB: ntb_transport: Move internal types to ntb_transport_internal.h Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 16/35] NTB: ntb_transport: Introduce ntb_transport_backend_ops Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 17/35] dmaengine: dw-edma: Add helper func to retrieve register base and size Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 18/35] dmaengine: dw-edma: Add per-channel interrupt routing mode Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 19/35] dmaengine: dw-edma: Poll completion when local IRQ handling is disabled Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 20/35] dmaengine: dw-edma: Add notify-only channels support Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 21/35] dmaengine: dw-edma: Add a helper to retrieve LL (Linked List) region Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 22/35] dmaengine: dw-edma: Serialize RMW on shared interrupt registers Koichiro Den
2025-12-19 14:39 ` Frank Li
2025-12-20 15:21 ` Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 23/35] NTB: ntb_transport: Split core into ntb_transport_core.c Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 24/35] NTB: ntb_transport: Add additional hooks for DW eDMA backend Koichiro Den
2025-12-17 15:15 ` [RFC PATCH v3 25/35] NTB: hw: Introduce DesignWare eDMA helper Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 26/35] NTB: ntb_transport: Introduce DW eDMA backed transport mode Koichiro Den
2025-12-19 15:00 ` Frank Li
2025-12-20 15:28 ` Koichiro Den
2026-01-06 18:46 ` Dave Jiang
2026-01-07 15:05 ` Koichiro Den
2026-01-06 18:51 ` Dave Jiang
2026-01-07 14:54 ` Koichiro Den
2026-01-07 19:02 ` Dave Jiang
2026-01-08 1:25 ` Koichiro Den
2026-01-08 17:55 ` Dave Jiang
2026-01-10 13:43 ` Koichiro Den
2026-01-12 15:43 ` Dave Jiang
2026-01-13 2:44 ` Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 27/35] NTB: epf: Provide db_vector_count/db_vector_mask callbacks Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 28/35] ntb_netdev: Multi-queue support Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 29/35] NTB: epf: Add per-SoC quirk to cap MRRS for DWC eDMA (128B for R-Car) Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 30/35] iommu: ipmmu-vmsa: Add PCIe ch0 to devices_allowlist Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 31/35] iommu: ipmmu-vmsa: Add support for reserved regions Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 32/35] arm64: dts: renesas: Add Spider RC/EP DTs for NTB with remote DW PCIe eDMA Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 33/35] NTB: epf: Add an additional memory window (MW2) barno mapping on Renesas R-Car Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 34/35] Documentation: PCI: endpoint: pci-epf-vntb: Update and add mwN_offset usage Koichiro Den
2025-12-17 15:16 ` [RFC PATCH v3 35/35] Documentation: driver-api: ntb: Document remote eDMA transport backend Koichiro Den
2026-01-06 21:09 ` Dave Jiang
2026-01-07 15:13 ` Koichiro Den
2025-12-19 15:12 ` [RFC PATCH v3 00/35] NTB transport backed by endpoint DW eDMA Frank Li
2025-12-20 15:44 ` Koichiro Den
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=aUVhr33M86WCAIqZ@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=Basavaraj.Natikar@amd.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=allenbh@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=dave.jiang@intel.com \
--cc=davem@davemloft.net \
--cc=den@valinux.co.jp \
--cc=dlemoal@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=edumazet@google.com \
--cc=elfring@users.sourceforge.net \
--cc=geert+renesas@glider.be \
--cc=jbrunet@baylibre.com \
--cc=jdmason@kudzu.us \
--cc=jingoohan1@gmail.com \
--cc=joro@8bytes.org \
--cc=kishon@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=kurt.schwemmer@microsemi.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=lpieralisi@kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mani@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ntb@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=utkarsh02t@gmail.com \
--cc=vkoul@kernel.org \
--cc=will@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