bus: mhi: host: pci_generic: round up nr_irqs to a power of two

Javier Achirica <[email protected]> Thu, 2 Apr 2026 16:44:21 +0200
Newsgroups dev.linux.lists.mhi
Message-ID <CACixm21E8g-k73HpPMQm2AjEu=PDONe5t0XhAHu3kqUMkYkrLA@mail.gmail.com>
Hello,

I have an issue with a SDX55 modem in a TCL HH500V router, when trying
to make it work under kernel 6.12.x (OpenWrt).

It looks like when an MHI device uses standard MSI, the PCI core
requires the allocated number of vectors to be a strict power of two.

In this case, nr_irqs is 5, so the generated mask is wrong and it
won't properly work. It can be fixed by explicitly rounding up the
requested IRQ count using `roundup_pow_of_two()` before passing it to
`pci_alloc_irq_vectors()`.

This patch, in 6.12.x tree, will fix it, but I'm not sure of the
impact of it on newer kernels and if it's the right way of fixing it.
Any tips on how to properly fix this issue?

Thanks!
Javier

Signed-off-by: Javier Achirica <[email protected]>
---
diff --git a/drivers/bus/mhi/host/pci_generic.c
b/drivers/bus/mhi/host/pci_generic.c
--- a/drivers/bus/mhi/host/pci_generic.c        2026-02-19
16:29:56.000000000 +0100
+++ b/drivers/bus/mhi/host/pci_generic.c        2026-03-29
13:14:17.053879617 +0200
@@ -1014,7 +1014,7 @@
         */
        mhi_cntrl->nr_irqs = 1 + mhi_cntrl_config->num_events;

-       nr_vectors = pci_alloc_irq_vectors(pdev, 1,
mhi_cntrl->nr_irqs, PCI_IRQ_MSI);
+       nr_vectors = pci_alloc_irq_vectors(pdev, 1,
roundup_pow_of_two(mhi_cntrl->nr_irqs), PCI_IRQ_MSI);
        if (nr_vectors < 0) {
                dev_err(&pdev->dev, "Error allocating MSI vectors %d\n",
                        nr_vectors);