Skip to content

Commit b17faba

Browse files
Shyam Sundar S Kjonmason
authored andcommitted
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. Signed-off-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com> Acked-by: Allen Hubbe <Allen.Hubbe@dell.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent 872deb2 commit b17faba

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/ntb/ntb_transport.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define NTB_TRANSPORT_VER "4"
6767
#define NTB_TRANSPORT_NAME "ntb_transport"
6868
#define NTB_TRANSPORT_DESC "Software Queue-Pair Transport over NTB"
69+
#define NTB_TRANSPORT_MIN_SPADS (MW0_SZ_HIGH + 2)
6970

7071
MODULE_DESCRIPTION(NTB_TRANSPORT_DESC);
7172
MODULE_VERSION(NTB_TRANSPORT_VER);
@@ -242,9 +243,6 @@ enum {
242243
NUM_MWS,
243244
MW0_SZ_HIGH,
244245
MW0_SZ_LOW,
245-
MW1_SZ_HIGH,
246-
MW1_SZ_LOW,
247-
MAX_SPAD,
248246
};
249247

250248
#define dev_client_dev(__dev) \
@@ -811,7 +809,7 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)
811809
{
812810
struct ntb_transport_qp *qp;
813811
u64 qp_bitmap_alloc;
814-
int i;
812+
unsigned int i, count;
815813

816814
qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free;
817815

@@ -831,7 +829,8 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)
831829
* goes down, blast them now to give them a sane value the next
832830
* time they are accessed
833831
*/
834-
for (i = 0; i < MAX_SPAD; i++)
832+
count = ntb_spad_count(nt->ndev);
833+
for (i = 0; i < count; i++)
835834
ntb_spad_write(nt->ndev, i, 0);
836835
}
837836

@@ -1064,17 +1063,12 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
10641063
{
10651064
struct ntb_transport_ctx *nt;
10661065
struct ntb_transport_mw *mw;
1067-
unsigned int mw_count, qp_count;
1066+
unsigned int mw_count, qp_count, spad_count, max_mw_count_for_spads;
10681067
u64 qp_bitmap;
10691068
int node;
10701069
int rc, i;
10711070

10721071
mw_count = ntb_mw_count(ndev);
1073-
if (ntb_spad_count(ndev) < (NUM_MWS + 1 + mw_count * 2)) {
1074-
dev_err(&ndev->dev, "Not enough scratch pad registers for %s",
1075-
NTB_TRANSPORT_NAME);
1076-
return -EIO;
1077-
}
10781072

10791073
if (ntb_db_is_unsafe(ndev))
10801074
dev_dbg(&ndev->dev,
@@ -1090,8 +1084,18 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
10901084
return -ENOMEM;
10911085

10921086
nt->ndev = ndev;
1087+
spad_count = ntb_spad_count(ndev);
1088+
1089+
/* Limit the MW's based on the availability of scratchpads */
1090+
1091+
if (spad_count < NTB_TRANSPORT_MIN_SPADS) {
1092+
nt->mw_count = 0;
1093+
rc = -EINVAL;
1094+
goto err;
1095+
}
10931096

1094-
nt->mw_count = mw_count;
1097+
max_mw_count_for_spads = (spad_count - MW0_SZ_HIGH) / 2;
1098+
nt->mw_count = min(mw_count, max_mw_count_for_spads);
10951099

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

0 commit comments

Comments
 (0)