Skip to content

Commit a115b1b

Browse files
Marek VasutLorenzo Pieralisi
authored andcommitted
PCI: rcar: Add L1 link state fix into data abort hook
When the link is in L1, hardware should return it to L0 automatically whenever a transaction targets a component on the other end of the link (PCIe r5.0, sec 5.2). The R-Car PCIe controller doesn't handle this transition correctly. If the link is not in L0, an MMIO transaction targeting a downstream device fails, and the controller reports an ARM imprecise external abort. Work around this by hooking the abort handler so the driver can detect this situation and help the hardware complete the link state transition. When the R-Car controller receives a PM_ENTER_L1 DLLP from the downstream component, it sets PMEL1RX bit in PMSR register, but then the controller enters some sort of in-between state. A subsequent MMIO transaction will fail, resulting in the external abort. The abort handler detects this condition and completes the link state transition by setting the L1IATN bit in PMCTLR and waiting for the link state transition to complete. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marek Vasut <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Lorenzo Pieralisi <[email protected]> Cc: Wolfram Sang <[email protected]> Cc: Yoshihiro Shimoda <[email protected]> Cc: [email protected]
1 parent 1e29cd9 commit a115b1b

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

drivers/pci/controller/pcie-rcar-host.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
#include <linux/bitops.h>
1515
#include <linux/clk.h>
16+
#include <linux/clk-provider.h>
1617
#include <linux/delay.h>
1718
#include <linux/interrupt.h>
1819
#include <linux/irq.h>
1920
#include <linux/irqdomain.h>
2021
#include <linux/kernel.h>
2122
#include <linux/init.h>
23+
#include <linux/iopoll.h>
2224
#include <linux/msi.h>
2325
#include <linux/of_address.h>
2426
#include <linux/of_irq.h>
@@ -41,6 +43,21 @@ struct rcar_msi {
4143
int irq2;
4244
};
4345

46+
#ifdef CONFIG_ARM
47+
/*
48+
* Here we keep a static copy of the remapped PCIe controller address.
49+
* This is only used on aarch32 systems, all of which have one single
50+
* PCIe controller, to provide quick access to the PCIe controller in
51+
* the L1 link state fixup function, called from the ARM fault handler.
52+
*/
53+
static void __iomem *pcie_base;
54+
/*
55+
* Static copy of bus clock pointer, so we can check whether the clock
56+
* is enabled or not.
57+
*/
58+
static struct clk *pcie_bus_clk;
59+
#endif
60+
4461
/* Structure representing the PCIe interface */
4562
struct rcar_pcie_host {
4663
struct rcar_pcie pcie;
@@ -776,6 +793,12 @@ static int rcar_pcie_get_resources(struct rcar_pcie_host *host)
776793
}
777794
host->msi.irq2 = i;
778795

796+
#ifdef CONFIG_ARM
797+
/* Cache static copy for L1 link state fixup hook on aarch32 */
798+
pcie_base = pcie->base;
799+
pcie_bus_clk = host->bus_clk;
800+
#endif
801+
779802
return 0;
780803

781804
err_irq2:
@@ -1031,4 +1054,67 @@ static struct platform_driver rcar_pcie_driver = {
10311054
},
10321055
.probe = rcar_pcie_probe,
10331056
};
1057+
1058+
#ifdef CONFIG_ARM
1059+
static DEFINE_SPINLOCK(pmsr_lock);
1060+
static int rcar_pcie_aarch32_abort_handler(unsigned long addr,
1061+
unsigned int fsr, struct pt_regs *regs)
1062+
{
1063+
unsigned long flags;
1064+
u32 pmsr, val;
1065+
int ret = 0;
1066+
1067+
spin_lock_irqsave(&pmsr_lock, flags);
1068+
1069+
if (!pcie_base || !__clk_is_enabled(pcie_bus_clk)) {
1070+
ret = 1;
1071+
goto unlock_exit;
1072+
}
1073+
1074+
pmsr = readl(pcie_base + PMSR);
1075+
1076+
/*
1077+
* Test if the PCIe controller received PM_ENTER_L1 DLLP and
1078+
* the PCIe controller is not in L1 link state. If true, apply
1079+
* fix, which will put the controller into L1 link state, from
1080+
* which it can return to L0s/L0 on its own.
1081+
*/
1082+
if ((pmsr & PMEL1RX) && ((pmsr & PMSTATE) != PMSTATE_L1)) {
1083+
writel(L1IATN, pcie_base + PMCTLR);
1084+
ret = readl_poll_timeout_atomic(pcie_base + PMSR, val,
1085+
val & L1FAEG, 10, 1000);
1086+
WARN(ret, "Timeout waiting for L1 link state, ret=%d\n", ret);
1087+
writel(L1FAEG | PMEL1RX, pcie_base + PMSR);
1088+
}
1089+
1090+
unlock_exit:
1091+
spin_unlock_irqrestore(&pmsr_lock, flags);
1092+
return ret;
1093+
}
1094+
1095+
static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst = {
1096+
{ .compatible = "renesas,pcie-r8a7779" },
1097+
{ .compatible = "renesas,pcie-r8a7790" },
1098+
{ .compatible = "renesas,pcie-r8a7791" },
1099+
{ .compatible = "renesas,pcie-rcar-gen2" },
1100+
{},
1101+
};
1102+
1103+
static int __init rcar_pcie_init(void)
1104+
{
1105+
if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
1106+
#ifdef CONFIG_ARM_LPAE
1107+
hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
1108+
"asynchronous external abort");
1109+
#else
1110+
hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
1111+
"imprecise external abort");
1112+
#endif
1113+
}
1114+
1115+
return platform_driver_register(&rcar_pcie_driver);
1116+
}
1117+
device_initcall(rcar_pcie_init);
1118+
#else
10341119
builtin_platform_driver(rcar_pcie_driver);
1120+
#endif

drivers/pci/controller/pcie-rcar.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
#define LTSMDIS BIT(31)
8686
#define MACCTLR_INIT_VAL (LTSMDIS | MACCTLR_NFTS_MASK)
8787
#define PMSR 0x01105c
88+
#define L1FAEG BIT(31)
89+
#define PMEL1RX BIT(23)
90+
#define PMSTATE GENMASK(18, 16)
91+
#define PMSTATE_L1 (3 << 16)
92+
#define PMCTLR 0x011060
93+
#define L1IATN BIT(31)
94+
8895
#define MACS2R 0x011078
8996
#define MACCGSPSETR 0x011084
9097
#define SPCNGRSN BIT(31)

0 commit comments

Comments
 (0)