[RFC PATCH v3 07/35] PCI: endpoint: pci-epf-vntb: Hint subrange mapping preference to EPC driver

Koichiro Den posted 35 patches 1 month, 3 weeks ago
[RFC PATCH v3 07/35] PCI: endpoint: pci-epf-vntb: Hint subrange mapping preference to EPC driver
Posted by Koichiro Den 1 month, 3 weeks ago
Now that pci_epc_set_bar supports subrange mapping, give a hint about
that when calling pci_epc_set_bar(). For example, DW EPC chooses Address
Match Mode IB iATU mapping when 'use_submap' is set to true.

Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 30 ++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index 337995e2f3ce..23bbcfd20c3b 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -731,6 +731,12 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
 				PCI_BASE_ADDRESS_MEM_TYPE_64 :
 				PCI_BASE_ADDRESS_MEM_TYPE_32;
 
+		/* express preference for subrange mapping */
+		ntb->epf->bar[barno].use_submap = true;
+		ntb->epf->bar[barno].num_submap = 0;
+		if (WARN_ON(ntb->epf->bar[barno].submap))
+			dev_warn(dev, "BAR%u submap is not NULL\n", barno);
+
 		ret = pci_epc_set_bar(ntb->epf->epc,
 				      ntb->epf->func_no,
 				      ntb->epf->vfunc_no,
@@ -1391,6 +1397,7 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,
 	enum pci_barno barno;
 	int ret;
 	struct device *dev;
+	unsigned int sb;
 
 	dev = &ntb->ntb.dev;
 	barno = ntb->epf_ntb_bar[BAR_MW1 + idx];
@@ -1399,7 +1406,28 @@ static int vntb_epf_mw_set_trans(struct ntb_dev *ndev, int pidx, int idx,
 	epf_bar->barno = barno;
 	epf_bar->size = size;
 
-	ret = pci_epc_set_bar(ntb->epf->epc, 0, 0, epf_bar);
+	/* express preference for subrange mapping */
+	epf_bar->use_submap = true;
+	for (sb = 0; sb < epf_bar->num_submap; sb++) {
+		if (epf_bar->submap[sb].offset == offset) {
+			dev_warn(dev, "offset 0x%llx is already mapped\n",
+				 offset);
+			return -EBUSY;
+		}
+	}
+	epf_bar->num_submap++;
+	epf_bar->submap = devm_krealloc_array(
+				&ntb->epf->dev, epf_bar->submap,
+				epf_bar->num_submap, sizeof(*epf_bar->submap),
+				GFP_KERNEL);
+	if (!epf_bar->submap)
+		return -ENOMEM;
+	epf_bar->submap[sb].phys_addr = addr;
+	epf_bar->submap[sb].size = size;
+	epf_bar->submap[sb].offset = offset;
+
+	ret = pci_epc_set_bar(ntb->epf->epc, ntb->epf->func_no,
+			      ntb->epf->vfunc_no, epf_bar);
 	if (ret) {
 		dev_err(dev, "failure set mw trans\n");
 		return ret;
-- 
2.51.0