6aa7dcbd76ba3f40f5454c786549d5e020de6900
[openwrt/staging/svanheule.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 @@ -597,6 +597,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 @@ -863,22 +868,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 @@ -932,22 +926,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 @@ -1452,6 +1443,34 @@ 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 + int virq;
125 +
126 + advk_writel(pcie, PCIE_MSG_PM_PME_MASK, PCIE_ISR0_REG);
127 +
128 + /*
129 + * PCIE_MSG_LOG_REG contains the last inbound message, so store
130 + * the requester ID only when PME was not asserted yet.
131 + * Also do not trigger PME interrupt when PME is still asserted.
132 + */
133 + if (!(le32_to_cpu(pcie->bridge.pcie_conf.rootsta) & PCI_EXP_RTSTA_PME)) {
134 + pcie->bridge.pcie_conf.rootsta = cpu_to_le32(requester | PCI_EXP_RTSTA_PME);
135 +
136 + /*
137 + * Trigger PME interrupt only if PMEIE bit in Root Control is set.
138 + * Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ, so use PCIe interrupt 0.
139 + */
140 + if (!(le16_to_cpu(pcie->bridge.pcie_conf.rootctl) & PCI_EXP_RTCTL_PMEIE))
141 + return;
142 +
143 + virq = irq_find_mapping(pcie->irq_domain, 0);
144 + if (generic_handle_irq(virq) == -EINVAL)
145 + dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
146 + }
147 +}
148 +
149 static void advk_pcie_handle_msi(struct advk_pcie *pcie)
150 {
151 u32 msi_val, msi_mask, msi_status, msi_idx;
152 @@ -1491,18 +1510,9 @@ static void advk_pcie_handle_int(struct
153 isr1_mask = advk_readl(pcie, PCIE_ISR1_MASK_REG);
154 isr1_status = isr1_val & ((~isr1_mask) & PCIE_ISR1_ALL_MASK);
155
156 - /* Process PME interrupt */
157 - if (isr0_status & PCIE_MSG_PM_PME_MASK) {
158 - /*
159 - * Do not clear PME interrupt bit in ISR0, it is cleared by IRQ
160 - * receiver by writing to the PCI_EXP_RTSTA register of emulated
161 - * root bridge. Aardvark HW returns zero for PCI_EXP_FLAGS_IRQ,
162 - * so use PCIe interrupt 0.
163 - */
164 - virq = irq_find_mapping(pcie->irq_domain, 0);
165 - if (generic_handle_irq(virq) == -EINVAL)
166 - dev_err_ratelimited(&pcie->pdev->dev, "unhandled PME IRQ\n");
167 - }
168 + /* Process PME interrupt as the first one to do not miss PME requester id */
169 + if (isr0_status & PCIE_MSG_PM_PME_MASK)
170 + advk_pcie_handle_pme(pcie);
171
172 /* Process ERR interrupt */
173 if (isr0_status & PCIE_ISR0_ERR_MASK) {