[PATCH 04/11] PCI: endpoint: pci-epf-vntb: Implement MW group translation callbacks

Koichiro Den <[email protected]> Tue, 4 Aug 2026 03:04:31 +0900
Newsgroups dev.linux.lists.ntb,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-pci
Message-ID <[email protected]>
All RC-to-EP MWs in a packed group share one inbound BAR. Setting each
MW separately would keep replacing that BAR and could expose a partial
group.

Add group callbacks that program the shared BAR once for the complete
backing range. The EPC API has no operation to disable only the inbound
translation without also clearing the host-assigned BAR address. Keep
clear as a no-op, matching the existing per-MW behavior.

Signed-off-by: Koichiro Den <[email protected]>
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index f22459e5a8c6..0c72b907c289 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -1622,6 +1622,31 @@ static int vntb_epf_mw_clear_trans(struct ntb_dev *ntb, int pidx, int idx)
 	return 0;
 }
 
+static int
+vntb_epf_mw_set_trans_group(struct ntb_dev *ndev, int pidx, int widx,
+			    dma_addr_t addr, resource_size_t size)
+{
+	struct epf_ntb *ntb = ntb_ndev(ndev);
+	struct pci_epf_bar *epf_bar;
+
+	if (pidx != NTB_DEF_PEER_IDX || !ntb->packed_mws || widx)
+		return -EINVAL;
+	if (!IS_ALIGNED(addr, SZ_4K) || size != ntb->mws_size[0])
+		return -EINVAL;
+
+	epf_bar = &ntb->epf->bar[ntb->mw_layout[0].barno];
+	epf_bar->phys_addr = addr;
+
+	return pci_epc_set_bar(ntb->epf->epc, ntb->epf->func_no,
+			       ntb->epf->vfunc_no, epf_bar);
+}
+
+static int vntb_epf_mw_clear_trans_group(struct ntb_dev *ndev, int pidx,
+					 int widx)
+{
+	return 0;
+}
+
 static int vntb_epf_peer_mw_get_addr(struct ntb_dev *ndev, int idx,
 				phys_addr_t *base, resource_size_t *size)
 {
@@ -1839,6 +1864,8 @@ static const struct ntb_dev_ops vntb_epf_ops = {
 	.db_vector_mask		= vntb_epf_db_vector_mask,
 	.db_set_mask		= vntb_epf_db_set_mask,
 	.mw_get_trans_group	= vntb_epf_mw_get_trans_group,
+	.mw_set_trans_group	= vntb_epf_mw_set_trans_group,
+	.mw_clear_trans_group	= vntb_epf_mw_clear_trans_group,
 	.mw_set_trans		= vntb_epf_mw_set_trans,
 	.mw_clear_trans		= vntb_epf_mw_clear_trans,
 	.peer_mw_get_addr	= vntb_epf_peer_mw_get_addr,
-- 
2.51.0