Skip to content

Commit 140eb52

Browse files
dmeyergiojonmason
authored andcommitted
NTB: ntb_hw_switchtec: Fix peer BAR bug in switchtec_ntb_init_shared_mw
This resolves a bug which may incorrectly configure the peer host's LUT for shared memory window access. The code was using the local host's first BAR number, rather than the peer hosts's first BAR number, to determine what peer NT control register to program. The bug will cause the Switchtec NTB link to work only if both peers have the same first NTB BAR configured. In all other configurations, the link will not come up, failing silently. When both hosts have the same first BAR, the configuration works only because the first BAR numbers happent to be the same. When the hosts do not have the same first BAR, then the LUT translation will not be configured in the correct peer LUT and will not give the peer the shared memory window access required for the link to operate. Signed-off-by: Doug Meyer <dmeyer@gigaio.com> Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Fixes: 678784a44ae8 ("NTB: switchtec_ntb: Initialize hardware for memory windows") Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent d8a5b80 commit 140eb52

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎drivers/ntb/hw/mscc/ntb_hw_switchtec.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,8 @@ static void switchtec_ntb_init_shared(struct switchtec_ntb *sndev)
964964
static int switchtec_ntb_init_shared_mw(struct switchtec_ntb *sndev)
965965
{
966966
struct ntb_ctrl_regs __iomem *ctl = sndev->mmio_peer_ctrl;
967-
int bar = sndev->direct_mw_to_bar[0];
967+
int self_bar = sndev->direct_mw_to_bar[0];
968+
int peer_bar = sndev->peer_direct_mw_to_bar[0];
968969
u32 ctl_val;
969970
int rc;
970971

@@ -985,12 +986,12 @@ static int switchtec_ntb_init_shared_mw(struct switchtec_ntb *sndev)
985986
if (rc)
986987
goto unalloc_and_exit;
987988

988-
ctl_val = ioread32(&ctl->bar_entry[bar].ctl);
989+
ctl_val = ioread32(&ctl->bar_entry[peer_bar].ctl);
989990
ctl_val &= 0xFF;
990991
ctl_val |= NTB_CTRL_BAR_LUT_WIN_EN;
991992
ctl_val |= ilog2(LUT_SIZE) << 8;
992993
ctl_val |= (sndev->nr_lut_mw - 1) << 14;
993-
iowrite32(ctl_val, &ctl->bar_entry[bar].ctl);
994+
iowrite32(ctl_val, &ctl->bar_entry[peer_bar].ctl);
994995

995996
iowrite64((NTB_CTRL_LUT_EN | (sndev->self_partition << 1) |
996997
sndev->self_shared_dma),
@@ -1009,7 +1010,7 @@ static int switchtec_ntb_init_shared_mw(struct switchtec_ntb *sndev)
10091010
goto unalloc_and_exit;
10101011
}
10111012

1012-
sndev->peer_shared = pci_iomap(sndev->stdev->pdev, bar, LUT_SIZE);
1013+
sndev->peer_shared = pci_iomap(sndev->stdev->pdev, self_bar, LUT_SIZE);
10131014
if (!sndev->peer_shared) {
10141015
rc = -ENOMEM;
10151016
goto unalloc_and_exit;

0 commit comments

Comments
 (0)