Skip to content

Commit

Permalink
ntb_transport: Check the number of spads the hardware supports
Browse files Browse the repository at this point in the history
I'm working on hardware that currently has a limited number of
scratchpad registers and ntb_ndev fails with no clue as to why. I
feel it is better to fail early and provide a reasonable error message
then to fail later on.

The same is done to ntb_perf, but it doesn't currently require enough
spads to actually fail. I've also removed the unused SPAD_MSG and
SPAD_ACK enums so that MAX_SPAD accurately reflects the number of
spads used.

Signed-off-by: Logan Gunthorpe <[email protected]>
Acked-by: Dave Jiang <[email protected]>
Signed-off-by: Jon Mason <[email protected]>
  • Loading branch information
lsgunth authored and jonmason committed Aug 5, 2016
1 parent 8b71d28 commit 19645a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions drivers/ntb/ntb_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,13 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
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,
"doorbell is unsafe, proceed anyway...\n");
Expand All @@ -1075,8 +1082,6 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)

nt->ndev = ndev;

mw_count = ntb_mw_count(ndev);

nt->mw_count = mw_count;

nt->mw_vec = kzalloc_node(mw_count * sizeof(*nt->mw_vec),
Expand Down
8 changes: 6 additions & 2 deletions drivers/ntb/test/ntb_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ enum {
VERSION = 0,
MW_SZ_HIGH,
MW_SZ_LOW,
SPAD_MSG,
SPAD_ACK,
MAX_SPAD
};

Expand Down Expand Up @@ -696,6 +694,12 @@ static int perf_probe(struct ntb_client *client, struct ntb_dev *ntb)
int node;
int rc = 0;

if (ntb_spad_count(ntb) < MAX_SPAD) {
dev_err(&ntb->dev, "Not enough scratch pad registers for %s",
DRIVER_NAME);
return -EIO;
}

node = dev_to_node(&pdev->dev);

perf = kzalloc_node(sizeof(*perf), GFP_KERNEL, node);
Expand Down

0 comments on commit 19645a0

Please sign in to comment.