ntb_transport: Limit memory windows based on available, scratchpads
PATCH v5 1/1 ntb_transport: Limit memory windows based on available, scratchpads
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.
--- drivers/ntb/ntb_transport.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/ntb/ntb_transport.c +15 -12
@@ -66,6 +66,7 @@#define NTB_TRANSPORT_VER "4"#define NTB_TRANSPORT_NAME "ntb_transport"#define NTB_TRANSPORT_DESC "Software Queue-Pair Transport over NTB" +#define NTB_TRANSPORT_MIN_SPADS (MW0_SZ_HIGH + 2)MODULE_DESCRIPTION (NTB_TRANSPORT_DESC );MODULE_VERSION (NTB_TRANSPORT_VER );
@@ -242,9 +243,6 @@ enum {NUM_MWS ,MW0_SZ_HIGH , MW0_SZ_LOW, -MW1_SZ_HIGH , -MW1_SZ_LOW , - MAX_SPAD, };#define dev_client_dev (__dev) \
@@ -811,7 +809,7 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt) {struct ntb_transport_qp *qp;u64 qp_bitmap_alloc; -int i; +unsigned int i, count; qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free;
@@ -831,7 +829,8 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)* goes down, blast them now to give them a sane value the next * time they are accessed */ -for (i =0 ; i <MAX_SPAD ; i++) + count =ntb_spad_count (nt->ndev); +for (i =0 ; i < count; i++)ntb_spad_write (nt->ndev, i,0 ); }
@@ -1064,17 +1063,12 @@ 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; mw_count =ntb_mw_count (ndev); -if (ntb_spad_count (ndev) < (NUM_MWS +1 + mw_count *2 )) { -dev_err (&ndev->dev,"Not enough scratch pad registers for %s" , -NTB_TRANSPORT_NAME ); -return -EIO ; - }if (ntb_db_is_unsafe (ndev)) dev_dbg(&ndev->dev,
@@ -1090,8 +1084,17 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)return -ENOMEM ; nt->ndev = ndev; + spad_count =ntb_spad_count (ndev); + +/* Limit the MW's based on the availability of scratchpads */ + +if (spad_count <NTB_TRANSPORT_MIN_SPADS ) { + nt->mw_count =0 ; + goto err; + } - nt->mw_count = mw_count; + max_mw_count_for_spads = (spad_count -MW0_SZ_HIGH ) /2 ; + nt->mw_count =min (mw_count, max_mw_count_for_spads); nt->mw_vec =kzalloc_node (mw_count *sizeof (*nt->mw_vec),GFP_KERNEL , node);
Signature · 1 line
2.7.4
From: Shyam Sundar S K
Quoted 9 lines
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 <[email protected]>Reviewed-by Agrawal, Nitesh-kumar <[email protected]>Signed-off-by S-k, Shyam-sundar <[email protected]>
Quoted 87 lines
--- drivers/ntb/ntb_transport.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)drivers/ntb/ntb_transport.c +5
-11@@ -66,6 +66,7 @@#define NTB_TRANSPORT_VER "4"#define NTB_TRANSPORT_NAME "ntb_transport"#define NTB_TRANSPORT_DESC "Software Queue-Pair Transport over NTB" +#define NTB_TRANSPORT_MIN_SPADS (MW0_SZ_HIGH + 2)MODULE_DESCRIPTION (NTB_TRANSPORT_DESC );MODULE_VERSION (NTB_TRANSPORT_VER );@@ -242,9 +243,6 @@ enum {NUM_MWS ,MW0_SZ_HIGH , MW0_SZ_LOW, -MW1_SZ_HIGH , -MW1_SZ_LOW , - MAX_SPAD, };#define dev_client_dev (__dev) \@@ -811,7 +809,7 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt) {struct ntb_transport_qp *qp;u64 qp_bitmap_alloc; -int i; +unsigned int i, count; qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free;@@ -831,7 +829,8 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)* goes down, blast them now to give them a sane value the next * time they are accessed */ -for (i =0 ; i <MAX_SPAD ; i++) + count =ntb_spad_count (nt->ndev); +for (i =0 ; i < count; i++)ntb_spad_write (nt->ndev, i,0 ); }@@ -1064,17 +1063,12 @@ 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; mw_count =ntb_mw_count (ndev); -if (ntb_spad_count (ndev) < (NUM_MWS +1 + mw_count *2 )) { -dev_err (&ndev->dev,"Not enough scratch pad registers for %s" , -NTB_TRANSPORT_NAME ); -return -EIO ; - }if (ntb_db_is_unsafe (ndev))drivers/ntb/ntb_transport.c +10
-1dev_dbg(&ndev->dev,@@ -1090,8 +1084,17 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)return -ENOMEM ; nt->ndev = ndev; + spad_count =ntb_spad_count (ndev); + +/* Limit the MW's based on the availability of scratchpads */ + +if (spad_count <NTB_TRANSPORT_MIN_SPADS ) { + nt->mw_count =0 ; + goto err; + } - nt->mw_count = mw_count; + max_mw_count_for_spads = (spad_count -MW0_SZ_HIGH ) /2 ; + nt->mw_count =min (mw_count, max_mw_count_for_spads); nt->mw_vec = kzalloc_node(mw_count * sizeof(*nt->mw_vec),
GFP_KERNEL, node);
--
2.7.4
Quoted 7 lines · Allen Hubbe
From: Shyam Sundar S K
Quoted 6 lines
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.
Quoted 5 lines
Quoted 3 lines
Reviewed-by Shah, Nehal-bakulchandra <[email protected]>Reviewed-by Agrawal, Nitesh-kumar <[email protected]>Signed-off-by S-k, Shyam-sundar <[email protected]>Acked-by Allen Hubbe <[email protected]>
Applied to my ntb branch
Thanks,
Jon
Quoted 89 lines
Quoted 88 lines
--- drivers/ntb/ntb_transport.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)drivers/ntb/ntb_transport.c +5
-11@@ -66,6 +66,7 @@#define NTB_TRANSPORT_VER "4"#define NTB_TRANSPORT_NAME "ntb_transport"#define NTB_TRANSPORT_DESC "Software Queue-Pair Transport over NTB" +#define NTB_TRANSPORT_MIN_SPADS (MW0_SZ_HIGH + 2)MODULE_DESCRIPTION (NTB_TRANSPORT_DESC );MODULE_VERSION (NTB_TRANSPORT_VER );@@ -242,9 +243,6 @@ enum {NUM_MWS ,MW0_SZ_HIGH , MW0_SZ_LOW, -MW1_SZ_HIGH , -MW1_SZ_LOW , - MAX_SPAD, };#define dev_client_dev (__dev) \@@ -811,7 +809,7 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt) {struct ntb_transport_qp *qp;u64 qp_bitmap_alloc; -int i; +unsigned int i, count; qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free;@@ -831,7 +829,8 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)* goes down, blast them now to give them a sane value the next * time they are accessed */ -for (i =0 ; i <MAX_SPAD ; i++) + count =ntb_spad_count (nt->ndev); +for (i =0 ; i < count; i++)ntb_spad_write (nt->ndev, i,0 ); }@@ -1064,17 +1063,12 @@ 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; mw_count =ntb_mw_count (ndev); -if (ntb_spad_count (ndev) < (NUM_MWS +1 + mw_count *2 )) { -dev_err (&ndev->dev,"Not enough scratch pad registers for %s" , -NTB_TRANSPORT_NAME ); -return -EIO ; - }if (ntb_db_is_unsafe (ndev))drivers/ntb/ntb_transport.c +10
-1dev_dbg(&ndev->dev,@@ -1090,8 +1084,17 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)return -ENOMEM ; nt->ndev = ndev; + spad_count =ntb_spad_count (ndev); + +/* Limit the MW's based on the availability of scratchpads */ + +if (spad_count <NTB_TRANSPORT_MIN_SPADS ) { + nt->mw_count =0 ; + goto err; + } - nt->mw_count = mw_count; + max_mw_count_for_spads = (spad_count -MW0_SZ_HIGH ) /2 ; + nt->mw_count =min (mw_count, max_mw_count_for_spads); nt->mw_vec = kzalloc_node(mw_count * sizeof(*nt->mw_vec),
GFP_KERNEL, node);
--
2.7.4