952eb9d4059b5b1529564cb6fbf640378a1d607b
[openwrt/staging/chunkeey.git] / target / linux / generic / pending-5.15 / 850-0003-PCI-aardvark-Fix-support-for-MSI-interrupts.patch
1 From bb03b126ea6c9e57177b537dd022246fa5dbef16 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Fri, 12 Feb 2021 16:24:07 +0100
4 Subject: [PATCH] PCI: aardvark: Fix support for MSI interrupts
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Aardvark hardware supports Multi-MSI and MSI_FLAG_MULTI_PCI_MSI is already
10 set for the MSI chip. But when allocating MSI interrupt numbers for
11 Multi-MSI, the numbers need to be properly aligned, otherwise endpoint
12 devices send MSI interrupt with incorrect numbers.
13
14 Fix this issue by using function bitmap_find_free_region() instead of
15 bitmap_find_next_zero_area().
16
17 To ensure that aligned MSI interrupt numbers are used by endpoint devices,
18 we cannot use Linux virtual irq numbers (as they are random and not
19 properly aligned). Instead we need to use the aligned hwirq numbers.
20
21 This change fixes receiving MSI interrupts on Armada 3720 boards and
22 allows using NVMe disks which use Multi-MSI feature with 3 interrupts.
23
24 Without this NVMe disks freeze booting as linux nvme-core.c is waiting
25 60s for an interrupt.
26
27 Signed-off-by: Pali Rohár <pali@kernel.org>
28 Signed-off-by: Marek Behún <kabel@kernel.org>
29 ---
30 drivers/pci/controller/pci-aardvark.c | 16 ++++++----------
31 1 file changed, 6 insertions(+), 10 deletions(-)
32
33 --- a/drivers/pci/controller/pci-aardvark.c
34 +++ b/drivers/pci/controller/pci-aardvark.c
35 @@ -1182,7 +1182,7 @@ static void advk_msi_irq_compose_msi_msg
36
37 msg->address_lo = lower_32_bits(msi_msg);
38 msg->address_hi = upper_32_bits(msi_msg);
39 - msg->data = data->irq;
40 + msg->data = data->hwirq;
41 }
42
43 static int advk_msi_set_affinity(struct irq_data *irq_data,
44 @@ -1199,15 +1199,11 @@ static int advk_msi_irq_domain_alloc(str
45 int hwirq, i;
46
47 mutex_lock(&pcie->msi_used_lock);
48 - hwirq = bitmap_find_next_zero_area(pcie->msi_used, MSI_IRQ_NUM,
49 - 0, nr_irqs, 0);
50 - if (hwirq >= MSI_IRQ_NUM) {
51 - mutex_unlock(&pcie->msi_used_lock);
52 - return -ENOSPC;
53 - }
54 -
55 - bitmap_set(pcie->msi_used, hwirq, nr_irqs);
56 + hwirq = bitmap_find_free_region(pcie->msi_used, MSI_IRQ_NUM,
57 + order_base_2(nr_irqs));
58 mutex_unlock(&pcie->msi_used_lock);
59 + if (hwirq < 0)
60 + return -ENOSPC;
61
62 for (i = 0; i < nr_irqs; i++)
63 irq_domain_set_info(domain, virq + i, hwirq + i,
64 @@ -1225,7 +1221,7 @@ static void advk_msi_irq_domain_free(str
65 struct advk_pcie *pcie = domain->host_data;
66
67 mutex_lock(&pcie->msi_used_lock);
68 - bitmap_clear(pcie->msi_used, d->hwirq, nr_irqs);
69 + bitmap_release_region(pcie->msi_used, d->hwirq, order_base_2(nr_irqs));
70 mutex_unlock(&pcie->msi_used_lock);
71 }
72