2ef9afea5b7d993214da3f3fb2eb68f53441cd89
[openwrt/staging/jogo.git] /
1 From 68727b545332327b4c2f9c0f8d006be8970e7832 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Fri, 19 Feb 2021 14:22:22 +0100
4 Subject: [PATCH] PCI: aardvark: Fix support for PME requester on emulated
5 bridge
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Enable aardvark PME interrupt unconditionally by unmasking it and read PME
11 requester ID to emulated bridge config space immediately after receiving
12 interrupt.
13
14 PME requester ID is stored in the PCIE_MSG_LOG_REG register, which contains
15 the last inbound message. So when new inbound message is received by HW
16 (including non-PM), the content in PCIE_MSG_LOG_REG register is replaced by
17 a new value.
18
19 PCIe specification mandates that subsequent PMEs are kept pending until the
20 PME Status Register bit is cleared by software by writing a 1b.
21
22 Support for masking/unmasking PME interrupt on emulated bridge via
23 PCI_EXP_RTCTL_PMEIE bit is now implemented only in emulated bridge config
24 space, to ensure that we do not miss any aardvark PME interrupt.
25
26 Reading of PCI_EXP_RTCAP and PCI_EXP_RTSTA registers is simplified as final
27 value is now always stored into emulated bridge config space by the
28 interrupt handler, so there is no need to implement support for these
29 registers in read_pcie callback.
30
31 Clearing of W1C bit PCI_EXP_RTSTA_PME is now also simplified as it is done
32 by pci-bridge-emul.c code for emulated bridge config space. So there is no
33 need to implement support for clearing this bit in write_pcie callback.
34
35 Signed-off-by: Pali Rohár <pali@kernel.org>
36 Signed-off-by: Marek Behún <kabel@kernel.org>
37 ---
38 drivers/pci/controller/pci-aardvark.c | 94 +++++++++++++++------------
39 1 file changed, 52 insertions(+), 42 deletions(-)
40
41 --- a/drivers/pci/controller/pci-aardvark.c
42 +++ b/drivers/pci/controller/pci-aardvark.c
43 @@ -590,6 +590,11 @@ static void advk_pcie_setup_hw(struct ad
44 reg &= ~PCIE_ISR0_MSI_INT_PENDING;
45 advk_writel(pcie, reg, PCIE_ISR0_MASK_REG);
46
47 + /* Unmask PME interrupt for processing of PME requester */
48 + reg = advk_readl(pcie, PCIE_ISR0_MASK_REG);
49 + reg &= ~PCIE_MSG_PM_PME_MASK;
50 + advk_writel(pcie, reg, PCIE_ISR0_MASK_REG);
51 +
52 /* Enable summary interrupt for GIC SPI source */
53 reg = PCIE_IRQ_ALL_MASK & (~PCIE_IRQ_ENABLE_INTS_MASK);
54 advk_writel(pcie, reg, HOST_CTRL_INT_MASK_REG);
55 @@ -856,22 +861,11 @@ advk_pci_bridge_emul_pcie_conf_read(stru
56 *value = PCI_EXP_SLTSTA_PDS << 16;
57 return PCI_BRIDGE_EMUL_HANDLED;
58
59 - case PCI_EXP_RTCTL: {
60 - u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG);
61 - *value = (val & PCIE_MSG_PM_PME_MASK) ? 0 : PCI_EXP_RTCTL_PMEIE;
62 - *value |= le16_to_cpu(bridge->pcie_conf.rootctl) & PCI_EXP_RTCTL_CRSSVE;
63 - *value |= PCI_EXP_RTCAP_CRSVIS << 16;
64 - return PCI_BRIDGE_EMUL_HANDLED;
65 - }
66 -
67 - case PCI_EXP_RTSTA: {
68 - u32 isr0 = advk_readl(pcie, PCIE_ISR0_REG);
69 - u32 msglog = advk_readl(pcie, PCIE_MSG_LOG_REG);
70 - *value = msglog >> 16;
71 - if (isr0 & PCIE_MSG_PM_PME_MASK)
72 - *value |= PCI_EXP_RTSTA_PME;
73 - return PCI_BRIDGE_EMUL_HANDLED;
74 - }
75 + /*
76 + * PCI_EXP_RTCTL and PCI_EXP_RTSTA are also supported, but do not need
77 + * to be handled here, because their values are stored in emulated
78 + * config space buffer, and we read them from there when needed.
79 + */
80
81 case PCI_EXP_LNKCAP: {
82 u32 val = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg);
83 @@ -925,22 +919,19 @@ advk_pci_bridge_emul_pcie_conf_write(str
84 advk_pcie_wait_for_retrain(pcie);
85 break;
86
87 - case PCI_EXP_RTCTL:
88 - /* Only mask/unmask PME interrupt */
89 - if (mask & PCI_EXP_RTCTL_PMEIE) {
90 - u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG);
91 - if (new & PCI_EXP_RTCTL_PMEIE)
92 - val &= ~PCIE_MSG_PM_PME_MASK;
93 - else
94 - val |= PCIE_MSG_PM_PME_MASK;
95 - advk_writel(pcie, val, PCIE_ISR0_MASK_REG);
96 - }
97 + case PCI_EXP_RTCTL: {
98 + u16 rootctl = le16_to_cpu(bridge->pcie_conf.rootctl);
99 + /* Only emulation of PMEIE and CRSSVE bits is provided */
100 + rootctl &= PCI_EXP_RTCTL_PMEIE | PCI_EXP_RTCTL_CRSSVE;
101 + bridge->pcie_conf.rootctl = cpu_to_le16(rootctl);
102 break;
103 + }
104
105 - case PCI_EXP_RTSTA:
106 - if (new & PCI_EXP_RTSTA_PME)
107 - advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG);
108 - break;
109 + /*
110 + * PCI_EXP_RTSTA is also supported, but does not need to be handled
111 + * here, because its value is stored in emulated config space buffer,
112 + * and we write it there when needed.
113 + */
114
115 case PCI_EXP_DEVCTL:
116 case PCI_EXP_DEVCTL2:
117 @@ -1445,6 +1436,32 @@ static void advk_pcie_remove_irq_domain(
118 irq_domain_remove(pcie->irq_domain);
119 }
120
121 +static void advk_pcie_handle_pme(struct advk_pcie *pcie)
122 +{
123 + u32 requester = advk_readl(pcie, PCIE_MSG_LOG_REG) >> 16;
124 +
125 + advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG);
126 +
127 + /*
128 + * PCIE_MSG_LOG_REG contains the last inbound message, so store
129 + * the requester ID only when PME was not asserted yet.
130 + * Also do not trigger PME interrupt when PME is still asserted.
131 + */
132 + if (!(le32_to_cpu(pcie->bridge.pcie_conf.rootsta) & PCI_EXP_RTSTA_PME)) {
133 + pcie->bridge.pcie_conf.rootsta = cpu_to_le32(requester | PCI_EXP_RTSTA_PME);
134 +
135 + /*
136 + * Trigger PME interrupt only if PMEIE bit in Root Control is set.
137 + * Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ, so use PCIe interrupt 0.
138 + */
139 + if (!(le16_to_cpu(pcie->bridge.pcie_conf.rootctl) & PCI_EXP_RTCTL_PMEIE))
140 + return;
141 +
142 + if (generic_handle_domain_irq(pcie->irq_domain, 0) == -EINVAL)
143 + dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
144 + }
145 +}
146 +
147 static void advk_pcie_handle_msi(struct advk_pcie *pcie)
148 {
149 u32 msi_val, msi_mask, msi_status, msi_idx;
150 @@ -1480,17 +1497,9 @@ static void advk_pcie_handle_int(struct
151 isr1_mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
152 isr1_status = isr1_val & ((~isr1_mask) & PCIE_ISR1_ALL_MASK);
153
154 - /* Process PME interrupt */
155 - if (isr0_status & PCIE_MSG_PM_PME_MASK) {
156 - /*
157 - * Do not clear PME interrupt bit in ISR0, it is cleared by IRQ
158 - * receiver by writing to the PCI_EXP_RTSTA register of emulated
159 - * root bridge. Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ,
160 - * so use PCIe interrupt 0.
161 - */
162 - if (generic_handle_domain_irq(pcie->irq_domain, 0) == -EINVAL)
163 - dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
164 - }
165 + /* Process PME interrupt as the first one to do not miss PME requester id */
166 + if (isr0_status & PCIE_MSG_PM_PME_MASK)
167 + advk_pcie_handle_pme(pcie);
168
169 /* Process ERR interrupt */
170 if (isr0_status & PCIE_ISR0_ERR_MASK) {