8a80d67af34dee75a8f0fa78fc70af66432f1071
[openwrt/staging/xback.git] /
1 From 7f353accca6e4a3222991c65b1a6801503973bd3 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Fri, 2 Jul 2021 16:44:10 +0200
4 Subject: [PATCH] PCI: aardvark: Add support for masking MSI interrupts
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 We should not unmask MSIs at setup, but only when kernel asks for them
10 to be unmasked.
11
12 At setup, mask all MSIs, and implement IRQ chip callbacks for masking
13 and unmasking particular MSIs.
14
15 Signed-off-by: Pali Rohár <pali@kernel.org>
16 Signed-off-by: Marek Behún <kabel@kernel.org>
17 ---
18 drivers/pci/controller/pci-aardvark.c | 54 ++++++++++++++++++++++++---
19 1 file changed, 49 insertions(+), 5 deletions(-)
20
21 --- a/drivers/pci/controller/pci-aardvark.c
22 +++ b/drivers/pci/controller/pci-aardvark.c
23 @@ -274,6 +274,7 @@ struct advk_pcie {
24 raw_spinlock_t irq_lock;
25 struct irq_domain *msi_domain;
26 struct irq_domain *msi_inner_domain;
27 + raw_spinlock_t msi_irq_lock;
28 DECLARE_BITMAP(msi_used, MSI_IRQ_NUM);
29 struct mutex msi_used_lock;
30 u16 msi_msg;
31 @@ -570,12 +571,10 @@ static void advk_pcie_setup_hw(struct ad
32 advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG);
33 advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG);
34
35 - /* Disable All ISR0/1 Sources */
36 + /* Disable All ISR0/1 and MSI Sources */
37 advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_MASK_REG);
38 advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_MASK_REG);
39 -
40 - /* Unmask all MSIs */
41 - advk_writel(pcie, ~(u32)PCIE_MSI_ALL_MASK, PCIE_MSI_MASK_REG);
42 + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_MASK_REG);
43
44 /* Unmask summary MSI interrupt */
45 reg = advk_readl(pcie, PCIE_ISR0_MASK_REG);
46 @@ -1191,10 +1190,52 @@ static int advk_msi_set_affinity(struct
47 return -EINVAL;
48 }
49
50 +static void advk_msi_irq_mask(struct irq_data *d)
51 +{
52 + struct advk_pcie *pcie = d->domain->host_data;
53 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
54 + unsigned long flags;
55 + u32 mask;
56 +
57 + raw_spin_lock_irqsave(&pcie->msi_irq_lock, flags);
58 + mask = advk_readl(pcie, PCIE_MSI_MASK_REG);
59 + mask |= BIT(hwirq);
60 + advk_writel(pcie, mask, PCIE_MSI_MASK_REG);
61 + raw_spin_unlock_irqrestore(&pcie->msi_irq_lock, flags);
62 +}
63 +
64 +static void advk_msi_irq_unmask(struct irq_data *d)
65 +{
66 + struct advk_pcie *pcie = d->domain->host_data;
67 + irq_hw_number_t hwirq = irqd_to_hwirq(d);
68 + unsigned long flags;
69 + u32 mask;
70 +
71 + raw_spin_lock_irqsave(&pcie->msi_irq_lock, flags);
72 + mask = advk_readl(pcie, PCIE_MSI_MASK_REG);
73 + mask &= ~BIT(hwirq);
74 + advk_writel(pcie, mask, PCIE_MSI_MASK_REG);
75 + raw_spin_unlock_irqrestore(&pcie->msi_irq_lock, flags);
76 +}
77 +
78 +static void advk_msi_top_irq_mask(struct irq_data *d)
79 +{
80 + pci_msi_mask_irq(d);
81 + irq_chip_mask_parent(d);
82 +}
83 +
84 +static void advk_msi_top_irq_unmask(struct irq_data *d)
85 +{
86 + pci_msi_unmask_irq(d);
87 + irq_chip_unmask_parent(d);
88 +}
89 +
90 static struct irq_chip advk_msi_bottom_irq_chip = {
91 .name = "MSI",
92 .irq_compose_msi_msg = advk_msi_irq_compose_msi_msg,
93 .irq_set_affinity = advk_msi_set_affinity,
94 + .irq_mask = advk_msi_irq_mask,
95 + .irq_unmask = advk_msi_irq_unmask,
96 };
97
98 static int advk_msi_irq_domain_alloc(struct irq_domain *domain,
99 @@ -1284,7 +1325,9 @@ static const struct irq_domain_ops advk_
100 };
101
102 static struct irq_chip advk_msi_irq_chip = {
103 - .name = "advk-MSI",
104 + .name = "advk-MSI",
105 + .irq_mask = advk_msi_top_irq_mask,
106 + .irq_unmask = advk_msi_top_irq_unmask,
107 };
108
109 static struct msi_domain_info advk_msi_domain_info = {
110 @@ -1298,6 +1341,7 @@ static int advk_pcie_init_msi_irq_domain
111 struct device *dev = &pcie->pdev->dev;
112 phys_addr_t msi_msg_phys;
113
114 + raw_spin_lock_init(&pcie->msi_irq_lock);
115 mutex_init(&pcie->msi_used_lock);
116
117 msi_msg_phys = virt_to_phys(&pcie->msi_msg);