# \[PATCH 1/2\] irqchip/armada-370-xp: Fix return value of armada\_370\_xp\_msi\_alloc()

- Subsystems: ARM/Marvell Kirkwood and Armada 370, 375, 38x, 39x, XP, 3700, 7K/8K, CN9130 SOC support, IRQCHIP DRIVERS, THE REST
- Maintainers: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth, Thomas Gleixner, Linus Torvalds
- Status: LANDED (ce20eff57361 · 2021-11-25 16:49)
- Landed in mainline as ce20eff57361 on 2021-11-25.
- List: linux-arm-kernel
- 4 messages, 2 authors
- Page: https://ratatoskr.run/linux-arm-kernel/2021/11/1586500/t

## \[PATCH 1/2\] irqchip/armada-370-xp: Fix return value of armada\_370\_xp\_msi\_alloc()

- From: Pali Rohár \<pali@kernel.org\>
- Date: 2021-11-25 13:03:24 
- Message: https://ratatoskr.run/linux-arm-kernel/2021/11/1586500.md

```text
IRQ domain alloc function should return zero on success. Non-zero value
indicates failure.

Signed-off-by: Pali Rohár <pali@kernel.org>
Fixes: fcc392d501bd ("irqchip/armada-370-xp: Use the generic MSI infrastructure")
Cc: <redacted>
---
 drivers/irqchip/irq-armada-370-xp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 80906bfec845..41ad745cf343 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -250,7 +250,7 @@ static int armada_370_xp_msi_alloc(struct irq_domain *domain, unsigned int virq,
 				    NULL, NULL);
 	}
 
-	return hwirq;
+	return 0;
 }
 
 static void armada_370_xp_msi_free(struct irq_domain *domain,
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```

## \[PATCH 2/2\] irqchip/armada-370-xp: Fix support for Multi-MSI interrupts

- From: Pali Rohár \<pali@kernel.org\>
- Date: 2021-11-25 13:03:28 
- Message: https://ratatoskr.run/linux-arm-kernel/2021/11/1586501.md

```text
irq-armada-370-xp driver already sets MSI_FLAG_MULTI_PCI_MSI flag into
msi_domain_info structure. But allocated interrupt numbers for Multi-MSI
needs to be properly aligned otherwise devices send MSI interrupt with
wrong number.

Fix this issue by using function bitmap_find_free_region() instead of
bitmap_find_next_zero_area() to allocate aligned interrupt numbers.

Signed-off-by: Pali Rohár <pali@kernel.org>
Fixes: a71b9412c90c ("irqchip/armada-370-xp: Allow allocation of multiple MSIs")
Cc: <redacted>
---
 drivers/irqchip/irq-armada-370-xp.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 41ad745cf343..5b8d571c041d 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -232,16 +232,12 @@ static int armada_370_xp_msi_alloc(struct irq_domain *domain, unsigned int virq,
 	int hwirq, i;
 
 	mutex_lock(&msi_used_lock);
+	hwirq = bitmap_find_free_region(msi_used, PCI_MSI_DOORBELL_NR,
+					order_base_2(nr_irqs));
+	mutex_unlock(&msi_used_lock);
 
-	hwirq = bitmap_find_next_zero_area(msi_used, PCI_MSI_DOORBELL_NR,
-					   0, nr_irqs, 0);
-	if (hwirq >= PCI_MSI_DOORBELL_NR) {
-		mutex_unlock(&msi_used_lock);
+	if (hwirq < 0)
 		return -ENOSPC;
-	}
-
-	bitmap_set(msi_used, hwirq, nr_irqs);
-	mutex_unlock(&msi_used_lock);
 
 	for (i = 0; i < nr_irqs; i++) {
 		irq_domain_set_info(domain, virq + i, hwirq + i,
@@ -259,7 +255,7 @@ static void armada_370_xp_msi_free(struct irq_domain *domain,
 	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
 
 	mutex_lock(&msi_used_lock);
-	bitmap_clear(msi_used, d->hwirq, nr_irqs);
+	bitmap_release_region(msi_used, d->hwirq, order_base_2(nr_irqs));
 	mutex_unlock(&msi_used_lock);
 }
 
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```

## Re: \[PATCH 2/2\] irqchip/armada-370-xp: Fix support for Multi-MSI interrupts

- From: Marc Zyngier \<maz@kernel.org\>
- Date: 2021-11-25 14:05:41 
- Message: https://ratatoskr.run/linux-arm-kernel/2021/11/1586552.md

```text
On Thu, 25 Nov 2021 13:00:57 +0000,
Pali Rohár [ref] wrote:
> 
> irq-armada-370-xp driver already sets MSI_FLAG_MULTI_PCI_MSI flag into
> msi_domain_info structure. But allocated interrupt numbers for Multi-MSI
> needs to be properly aligned otherwise devices send MSI interrupt with
> wrong number.
> 
> Fix this issue by using function bitmap_find_free_region() instead of
> bitmap_find_next_zero_area() to allocate aligned interrupt numbers.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Fixes: a71b9412c90c ("irqchip/armada-370-xp: Allow allocation of multiple MSIs")
> Cc: <redacted>
> ---
>  drivers/irqchip/irq-armada-370-xp.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
> index 41ad745cf343..5b8d571c041d 100644
> --- a/drivers/irqchip/irq-armada-370-xp.c
> +++ b/drivers/irqchip/irq-armada-370-xp.c
> @@ -232,16 +232,12 @@ static int armada_370_xp_msi_alloc(struct irq_domain *domain, unsigned int virq,
>  	int hwirq, i;
>  
>  	mutex_lock(&msi_used_lock);
> +	hwirq = bitmap_find_free_region(msi_used, PCI_MSI_DOORBELL_NR,
> +					order_base_2(nr_irqs));
> +	mutex_unlock(&msi_used_lock);
>  
> -	hwirq = bitmap_find_next_zero_area(msi_used, PCI_MSI_DOORBELL_NR,
> -					   0, nr_irqs, 0);
> -	if (hwirq >= PCI_MSI_DOORBELL_NR) {
> -		mutex_unlock(&msi_used_lock);
> +	if (hwirq < 0)
>  		return -ENOSPC;
> -	}
> -
> -	bitmap_set(msi_used, hwirq, nr_irqs);
> -	mutex_unlock(&msi_used_lock);
>  
>  	for (i = 0; i < nr_irqs; i++) {
>  		irq_domain_set_info(domain, virq + i, hwirq + i,
> @@ -259,7 +255,7 @@ static void armada_370_xp_msi_free(struct irq_domain *domain,
>  	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
>  
>  	mutex_lock(&msi_used_lock);
> -	bitmap_clear(msi_used, d->hwirq, nr_irqs);
> +	bitmap_release_region(msi_used, d->hwirq, order_base_2(nr_irqs));
>  	mutex_unlock(&msi_used_lock);
>  }
>  
> -- 
> 2.20.1
> 
> 

Acked-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```

## Re: \[PATCH 1/2\] irqchip/armada-370-xp: Fix return value of armada\_370\_xp\_msi\_alloc()

- From: Marc Zyngier \<maz@kernel.org\>
- Date: 2021-11-25 14:08:26 
- Message: https://ratatoskr.run/linux-arm-kernel/2021/11/1586554.md

```text
On Thu, 25 Nov 2021 13:00:56 +0000,
Pali Rohár [ref] wrote:
> 
> IRQ domain alloc function should return zero on success. Non-zero value
> indicates failure.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Fixes: fcc392d501bd ("irqchip/armada-370-xp: Use the generic MSI infrastructure")
> Cc: <redacted>
> ---
>  drivers/irqchip/irq-armada-370-xp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
> index 80906bfec845..41ad745cf343 100644
> --- a/drivers/irqchip/irq-armada-370-xp.c
> +++ b/drivers/irqchip/irq-armada-370-xp.c
> @@ -250,7 +250,7 @@ static int armada_370_xp_msi_alloc(struct irq_domain *domain, unsigned int virq,
>  				    NULL, NULL);
>  	}
>  
> -	return hwirq;
> +	return 0;
>  }
>  
>  static void armada_370_xp_msi_free(struct irq_domain *domain,
> -- 
> 2.20.1
> 
> 

Looks good too. As this lives in the irqchip tree, I'll queue these
two patches directly unless someone shouts...

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
```
