Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
* [PATCH 1/2] ntb_transport: Limit memory windows based on available, scratchpads
@ 2016-12-01 19:11 Shyam Sundar S K
  2016-12-02  2:22 ` Allen Hubbe
  0 siblings, 1 reply; 6+ messages in thread
From: Shyam Sundar S K @ 2016-12-01 19:11 UTC (permalink / raw)
  To: Jon Mason, Allen Hubbe, Dave Jiang
  Cc: Yu, Xiangliang, Shah, Nehal-bakulchandra, Agrawal, Nitesh-kumar,
	Sen, Pankaj, Su, Richard (Bin), Subramaniyan, Ramkumar, linux-ntb

When the underlying NTB H/W driver advertises more memory windows
than the number of scratchpads available to setup MW's, it is likely
that we may end up filling the remaining memory windows with garbage.
So to avoid that, lets limit the memory windows that transport driver
can setup based on the available scratchpads.

Reviewed-by: Shah, Nehal-bakulchandra <Nehal-bakulchandra.Shah@amd.com>
Reviewed-by: Agrawal, Nitesh-kumar <Nitesh-kumar.Agrawal@amd.com>
Signed-off-by: S-k, Shyam-sundar <Shyam-sundar.S-k@amd.com>
---
 drivers/ntb/ntb_transport.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 4eb8adb..50d6b06 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1064,7 +1064,7 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 {
 	struct ntb_transport_ctx *nt;
 	struct ntb_transport_mw *mw;
-	unsigned int mw_count, qp_count;
+	unsigned int mw_count, qp_count, spad_count, max_mw_count_for_spads;
 	u64 qp_bitmap;
 	int node;
 	int rc, i;
@@ -1090,8 +1090,16 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
 		return -ENOMEM;

 	nt->ndev = ndev;
+	spad_count = ntb_spad_count(ndev);

-	nt->mw_count = mw_count;
+    /* Limit the MW's based on the availability of scratchpads */
+	if (spad_count > NUM_MWS + 2) {
+		max_mw_count_for_spads = (spad_count - (NUM_MWS + 1)) >> 1;
+		nt->mw_count = min(mw_count, max_mw_count_for_spads);
+	} else {
+		nt->mw_count = 0;
+		goto err;
+	}

 	nt->mw_vec = kzalloc_node(mw_count * sizeof(*nt->mw_vec),
 				  GFP_KERNEL, node);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-02 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-01 19:11 [PATCH 1/2] ntb_transport: Limit memory windows based on available, scratchpads Shyam Sundar S K
2016-12-02  2:22 ` Allen Hubbe
2016-12-02 12:32   ` Shyam Sundar S K
2016-12-02 14:30     ` Allen Hubbe
2016-12-02 16:31       ` Shyam Sundar S K
2016-12-02 16:57         ` Allen Hubbe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox