Skip to content

Commit a93bd0a

Browse files
Vidya Sagargregkh
authored andcommitted
PCI: tegra194: Handle errors in BPMP response
commit f8c9ad4 upstream. The return value from tegra_bpmp_transfer() indicates the success or failure of the IPC transaction with BPMP. If the transaction succeeded, we also need to check the actual command's result code. If we don't have error handling for tegra_bpmp_transfer(), we will set the pcie->ep_state to EP_STATE_ENABLED even when the tegra_bpmp_transfer() command fails. Thus, the pcie->ep_state will get out of sync with reality, and any further PERST# assert + deassert will be a no-op and will not trigger the hardware initialization sequence. This is because pex_ep_event_pex_rst_deassert() checks the current pcie->ep_state, and does nothing if the current state is already EP_STATE_ENABLED. Thus, it is important to have error handling for tegra_bpmp_transfer(), such that the pcie->ep_state can not get out of sync with reality, so that we will try to initialize the hardware not only during the first PERST# assert + deassert, but also during any succeeding PERST# assert + deassert. One example where this fix is needed is when using a rock5b as host. During the initial PERST# assert + deassert (triggered by the bootloader on the rock5b) pex_ep_event_pex_rst_deassert() will get called, but for some unknown reason, the tegra_bpmp_transfer() call to initialize the PHY fails. Once Linux has been loaded on the rock5b, the PCIe driver will once again assert + deassert PERST#. However, without tegra_bpmp_transfer() error handling, this second PERST# assert + deassert will not trigger the hardware initialization sequence. With tegra_bpmp_transfer() error handling, the second PERST# assert + deassert will once again trigger the hardware to be initialized and this time the tegra_bpmp_transfer() succeeds. Fixes: c57247f ("PCI: tegra: Add support for PCIe endpoint mode in Tegra194") Signed-off-by: Vidya Sagar <vidyas@nvidia.com> [cassel: improve commit log] Signed-off-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Manivannan Sadhasivam <mani@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Acked-by: Thierry Reding <treding@nvidia.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20250922140822.519796-8-cassel@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 695c062 commit a93bd0a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

drivers/pci/controller/dwc/pcie-tegra194.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie,
12051205
struct mrq_uphy_response resp;
12061206
struct tegra_bpmp_message msg;
12071207
struct mrq_uphy_request req;
1208+
int err;
12081209

12091210
/*
12101211
* Controller-5 doesn't need to have its state set by BPMP-FW in
@@ -1227,7 +1228,13 @@ static int tegra_pcie_bpmp_set_ctrl_state(struct tegra_pcie_dw *pcie,
12271228
msg.rx.data = &resp;
12281229
msg.rx.size = sizeof(resp);
12291230

1230-
return tegra_bpmp_transfer(pcie->bpmp, &msg);
1231+
err = tegra_bpmp_transfer(pcie->bpmp, &msg);
1232+
if (err)
1233+
return err;
1234+
if (msg.rx.ret)
1235+
return -EINVAL;
1236+
1237+
return 0;
12311238
}
12321239

12331240
static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
@@ -1236,6 +1243,7 @@ static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
12361243
struct mrq_uphy_response resp;
12371244
struct tegra_bpmp_message msg;
12381245
struct mrq_uphy_request req;
1246+
int err;
12391247

12401248
memset(&req, 0, sizeof(req));
12411249
memset(&resp, 0, sizeof(resp));
@@ -1255,7 +1263,13 @@ static int tegra_pcie_bpmp_set_pll_state(struct tegra_pcie_dw *pcie,
12551263
msg.rx.data = &resp;
12561264
msg.rx.size = sizeof(resp);
12571265

1258-
return tegra_bpmp_transfer(pcie->bpmp, &msg);
1266+
err = tegra_bpmp_transfer(pcie->bpmp, &msg);
1267+
if (err)
1268+
return err;
1269+
if (msg.rx.ret)
1270+
return -EINVAL;
1271+
1272+
return 0;
12591273
}
12601274

12611275
static void tegra_pcie_downstream_dev_to_D0(struct tegra_pcie_dw *pcie)

0 commit comments

Comments
 (0)