692d4ee55579ef2b2227ac65e726dd8fe4dd8ff9
[openwrt/staging/aparcar.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 diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
42 index e2b66b0e8fb3..85a632537b70 100644
43 --- a/drivers/pci/controller/pci-aardvark.c
44 +++ b/drivers/pci/controller/pci-aardvark.c
45 @@ -597,6 +597,11 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
46 reg &= ~PCIE_ISR0_MSI_INT_PENDING;
47 advk_writel(pcie, reg, PCIE_ISR0_MASK_REG);
48
49 + /* Unmask PME interrupt for processing of PME requester */
50 + reg = advk_readl(pcie, PCIE_ISR0_MASK_REG);
51 + reg &= ~PCIE_MSG_PM_PME_MASK;
52 + advk_writel(pcie, reg, PCIE_ISR0_MASK_REG);
53 +
54 /* Enable summary interrupt for GIC SPI source */
55 reg = PCIE_IRQ_ALL_MASK & (~PCIE_IRQ_ENABLE_INTS_MASK);
56 advk_writel(pcie, reg, HOST_CTRL_INT_MASK_REG);
57 @@ -863,22 +868,11 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge,
58 *value = PCI_EXP_SLTSTA_PDS << 16;
59 return PCI_BRIDGE_EMUL_HANDLED;
60
61 - case PCI_EXP_RTCTL: {
62 - u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG);
63 - *value = (val & PCIE_MSG_PM_PME_MASK) ? 0 : PCI_EXP_RTCTL_PMEIE;
64 - *value |= le16_to_cpu(bridge->pcie_conf.rootctl) & PCI_EXP_RTCTL_CRSSVE;
65 - *value |= PCI_EXP_RTCAP_CRSVIS << 16;
66 - return PCI_BRIDGE_EMUL_HANDLED;
67 - }
68 -
69 - case PCI_EXP_RTSTA: {
70 - u32 isr0 = advk_readl(pcie, PCIE_ISR0_REG);
71 - u32 msglog = advk_readl(pcie, PCIE_MSG_LOG_REG);
72 - *value = msglog >> 16;
73 - if (isr0 & PCIE_MSG_PM_PME_MASK)
74 - *value |= PCI_EXP_RTSTA_PME;
75 - return PCI_BRIDGE_EMUL_HANDLED;
76 - }
77 + /*
78 + * PCI_EXP_RTCTL and PCI_EXP_RTSTA are also supported, but do not need
79 + * to be handled here, because their values are stored in emulated
80 + * config space buffer, and we read them from there when needed.
81 + */
82
83 case PCI_EXP_LNKCAP: {
84 u32 val = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg);
85 @@ -933,22 +927,19 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge,
86 advk_pcie_wait_for_retrain(pcie);
87 break;
88
89 - case PCI_EXP_RTCTL:
90 - /* Only mask/unmask PME interrupt */
91 - if (mask & PCI_EXP_RTCTL_PMEIE) {
92 - u32 val = advk_readl(pcie, PCIE_ISR0_MASK_REG);
93 - if (new & PCI_EXP_RTCTL_PMEIE)
94 - val &= ~PCIE_MSG_PM_PME_MASK;
95 - else
96 - val |= PCIE_MSG_PM_PME_MASK;
97 - advk_writel(pcie, val, PCIE_ISR0_MASK_REG);
98 - }
99 + case PCI_EXP_RTCTL: {
100 + u16 rootctl = le16_to_cpu(bridge->pcie_conf.rootctl);
101 + /* Only emulation of PMEIE and CRSSVE bits is provided */
102 + rootctl &= PCI_EXP_RTCTL_PMEIE | PCI_EXP_RTCTL_CRSSVE;
103 + bridge->pcie_conf.rootctl = cpu_to_le16(rootctl);
104 break;
105 + }
106
107 - case PCI_EXP_RTSTA:
108 - if (new & PCI_EXP_RTSTA_PME)
109 - advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG);
110 - break;
111 + /*
112 + * PCI_EXP_RTSTA is also supported, but does not need to be handled
113 + * here, because its value is stored in emulated config space buffer,
114 + * and we write it there when needed.
115 + */
116
117 case PCI_EXP_DEVCTL:
118 case PCI_EXP_DEVCTL2:
119 @@ -1450,6 +1441,34 @@ static void advk_pcie_remove_irq_domain(struct advk_pcie *pcie)
120 irq_domain_remove(pcie->irq_domain);
121 }
122
123 +static void advk_pcie_handle_pme(struct advk_pcie *pcie)
124 +{
125 + u32 requester = advk_readl(pcie, PCIE_MSG_LOG_REG) >> 16;
126 + int virq;
127 +
128 + advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG);
129 +
130 + /*
131 + * PCIE_MSG_LOG_REG contains the last inbound message, so store
132 + * the requester ID only when PME was not asserted yet.
133 + * Also do not trigger PME interrupt when PME is still asserted.
134 + */
135 + if (!(le32_to_cpu(pcie->bridge.pcie_conf.rootsta) & PCI_EXP_RTSTA_PME)) {
136 + pcie->bridge.pcie_conf.rootsta = cpu_to_le32(requester | PCI_EXP_RTSTA_PME);
137 +
138 + /*
139 + * Trigger PME interrupt only if PMEIE bit in Root Control is set.
140 + * Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ, so use PCIe interrupt 0.
141 + */
142 + if (!(le16_to_cpu(pcie->bridge.pcie_conf.rootctl) & PCI_EXP_RTCTL_PMEIE))
143 + return;
144 +
145 + virq = irq_find_mapping(pcie->irq_domain, 0);
146 + if (generic_handle_irq(virq) == -EINVAL)
147 + dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
148 + }
149 +}
150 +
151 static void advk_pcie_handle_msi(struct advk_pcie *pcie)
152 {
153 u32 msi_val, msi_mask, msi_status, msi_idx;
154 @@ -1489,18 +1508,9 @@ static void advk_pcie_handle_int(struct advk_pcie *pcie)
155 isr1_mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
156 isr1_status = isr1_val & ((~isr1_mask) & PCIE_ISR1_ALL_MASK);
157
158 - /* Process PME interrupt */
159 - if (isr0_status & PCIE_MSG_PM_PME_MASK) {
160 - /*
161 - * Do not clear PME interrupt bit in ISR0, it is cleared by IRQ
162 - * receiver by writing to the PCI_EXP_RTSTA register of emulated
163 - * root bridge. Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ,
164 - * so use PCIe interrupt 0.
165 - */
166 - virq = irq_find_mapping(pcie->irq_domain, 0);
167 - if (generic_handle_irq(virq) == -EINVAL)
168 - dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
169 - }
170 + /* Process PME interrupt as the first one to do not miss PME requester id */
171 + if (isr0_status & PCIE_MSG_PM_PME_MASK)
172 + advk_pcie_handle_pme(pcie);
173
174 /* Process ERR interrupt */
175 if (isr0_status & PCIE_ISR0_ERR_MASK) {
176 --
177 2.34.1
178