[RFC PATCH v4 24/38] NTB: ntb_transport: Run ntb_set_mw() before link-up negotiation

Koichiro Den <[email protected]>
Newsgroups dev.linux.lists.ntb,dev.linux.lists.iommu,org.kernel.vger.dmaengine,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kernel.vger.linux-pci,org.kernel.vger.linux-renesas-soc,org.kernel.vger.netdev
Message-ID <[email protected]>
Some backends may need to program BAR subrange mappings, and due to
pci_epc_set_bar() submap API constraint, the entire BAR layout needs to
be provided when calling the function. Since one MW that is to be
programmed by ntb_set_mw() can be the last piece that allows us to call
pci_epc_set_bar() for the BAR, calling it only after link-up can race
with post-link-up setup on the host.

Invoke ntb_set_mw() before the link-up handshake so the MW translation
is established early and the post-link-up setup can run without relying
on late MW programming. Since ntb_set_mw() can re-setup the MW when it
turns out that the size differs, it's safe to do so.

Signed-off-by: Koichiro Den <[email protected]>
---
 drivers/ntb/ntb_transport_core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/ntb/ntb_transport_core.c b/drivers/ntb/ntb_transport_core.c
index 2129fa7a22d8..185d73f8ea93 100644
--- a/drivers/ntb/ntb_transport_core.c
+++ b/drivers/ntb/ntb_transport_core.c
@@ -977,6 +977,10 @@ static void ntb_transport_link_work(struct work_struct *work)
 
 		spad = MW0_SZ_LOW + (i * 2);
 		ntb_peer_spad_write(ndev, PIDX, spad, lower_32_bits(size));
+
+		rc = ntb_set_mw(nt, i, size);
+		if (rc)
+			goto out;
 	}
 
 	ntb_peer_spad_write(ndev, PIDX, NUM_MWS, nt->mw_count);
@@ -1032,6 +1036,7 @@ static void ntb_transport_link_work(struct work_struct *work)
 
 		dev_dbg(&pdev->dev, "Remote MW%d size = %#llx\n", i, val64);
 
+		/* If it turns out that the size differs, reconfigure it */
 		rc = ntb_set_mw(nt, i, val64);
 		if (rc)
 			goto out1;
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.