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

Manivannan Sadhasivam <[email protected]> Thu, 2 Apr 2026 22:07:48 +0530
Newsgroups dev.linux.lists.mhi
Message-ID <w2vvxje5kadmjoh4qxu77jarevqcue2d73lvje75yve7djnxu4@3v4lhwjep4rk>
On Thu, Apr 02, 2026 at 04:44:21PM +0200, Javier Achirica wrote:
> 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.

Can you please explain what do you mean by '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?
> 

This change is correct on its own. You just need to apply it to v7.0-rc1 and
send it as proper patch to [email protected]. TBH this version itself is fine.

But I'm more curious about the issue you are facing as we never saw it, though
it is fundamentally wrong to request non-power-of-2 MSIs.

- Mani

> 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);
> 

-- 
மணிவண்ணன் சதாசிவம்