Skip to content

Commit 7ff351c

Browse files
wesleywesleyjonmason
authored andcommitted
ntb_hw_switchtec: Fix bug with more than 32 partitions
Switchtec could support as mush as 48 partitions, but ffs & fls are for 32 bit argument, in case of partition index larger than 31, the current code could not parse the peer partition index correctly. Change to the 64 bit version __ffs64 & fls64 accordingly to fix this bug. Fixes: 3df54c8 ("ntb_hw_switchtec: Allow using Switchtec NTB in multi-partition setups") Signed-off-by: Wesley Sheng <[email protected]> Signed-off-by: Kelvin Cao <[email protected]> Signed-off-by: Jon Mason <[email protected]>
1 parent 32c3d37 commit 7ff351c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

drivers/ntb/hw/mscc/ntb_hw_switchtec.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,6 @@ static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
840840
u64 tpart_vec;
841841
int self;
842842
u64 part_map;
843-
int bit;
844843

845844
sndev->ntb.pdev = sndev->stdev->pdev;
846845
sndev->ntb.topo = NTB_TOPO_SWITCH;
@@ -861,29 +860,28 @@ static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
861860
part_map = ioread64(&sndev->mmio_ntb->ep_map);
862861
part_map &= ~(1 << sndev->self_partition);
863862

864-
if (!ffs(tpart_vec)) {
863+
if (!tpart_vec) {
865864
if (sndev->stdev->partition_count != 2) {
866865
dev_err(&sndev->stdev->dev,
867866
"ntb target partition not defined\n");
868867
return -ENODEV;
869868
}
870869

871-
bit = ffs(part_map);
872-
if (!bit) {
870+
if (!part_map) {
873871
dev_err(&sndev->stdev->dev,
874872
"peer partition is not NT partition\n");
875873
return -ENODEV;
876874
}
877875

878-
sndev->peer_partition = bit - 1;
876+
sndev->peer_partition = __ffs64(part_map);
879877
} else {
880-
if (ffs(tpart_vec) != fls(tpart_vec)) {
878+
if (__ffs64(tpart_vec) != (fls64(tpart_vec) - 1)) {
881879
dev_err(&sndev->stdev->dev,
882880
"ntb driver only supports 1 pair of 1-1 ntb mapping\n");
883881
return -ENODEV;
884882
}
885883

886-
sndev->peer_partition = ffs(tpart_vec) - 1;
884+
sndev->peer_partition = __ffs64(tpart_vec);
887885
if (!(part_map & (1ULL << sndev->peer_partition))) {
888886
dev_err(&sndev->stdev->dev,
889887
"ntb target partition is not NT partition\n");

0 commit comments

Comments
 (0)