Skip to content

Commit 4385539

Browse files
committed
PCI/MSI: Enable and mask MSI-X early
The ordering of MSI-X enable in hardware is dysfunctional: 1) MSI-X is disabled in the control register 2) Various setup functions 3) pci_msi_setup_msi_irqs() is invoked which ends up accessing the MSI-X table entries 4) MSI-X is enabled and masked in the control register with the comment that enabling is required for some hardware to access the MSI-X table Step #4 obviously contradicts #3. The history of this is an issue with the NIU hardware. When #4 was introduced the table access actually happened in msix_program_entries() which was invoked after enabling and masking MSI-X. This was changed in commit d71d643 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") which removed the table write from msix_program_entries(). Interestingly enough nobody noticed and either NIU still works or it did not get any testing with a kernel 3.19 or later. Nevertheless this is inconsistent and there is no reason why MSI-X can't be enabled and masked in the control register early on, i.e. move step #4 above to step #1. This preserves the NIU workaround and has no side effects on other hardware. Fixes: d71d643 ("PCI/MSI: Kill redundant call of irq_set_msi_desc() for MSI-X interrupts") Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Marc Zyngier <[email protected]> Reviewed-by: Ashok Raj <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 36a21d5 commit 4385539

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/pci/msi.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -772,18 +772,25 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
772772
u16 control;
773773
void __iomem *base;
774774

775-
/* Ensure MSI-X is disabled while it is set up */
776-
pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
775+
/*
776+
* Some devices require MSI-X to be enabled before the MSI-X
777+
* registers can be accessed. Mask all the vectors to prevent
778+
* interrupts coming in before they're fully set up.
779+
*/
780+
pci_msix_clear_and_set_ctrl(dev, 0, PCI_MSIX_FLAGS_MASKALL |
781+
PCI_MSIX_FLAGS_ENABLE);
777782

778783
pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
779784
/* Request & Map MSI-X table region */
780785
base = msix_map_region(dev, msix_table_size(control));
781-
if (!base)
782-
return -ENOMEM;
786+
if (!base) {
787+
ret = -ENOMEM;
788+
goto out_disable;
789+
}
783790

784791
ret = msix_setup_entries(dev, base, entries, nvec, affd);
785792
if (ret)
786-
return ret;
793+
goto out_disable;
787794

788795
ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX);
789796
if (ret)
@@ -794,14 +801,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
794801
if (ret)
795802
goto out_free;
796803

797-
/*
798-
* Some devices require MSI-X to be enabled before we can touch the
799-
* MSI-X registers. We need to mask all the vectors to prevent
800-
* interrupts coming in before they're fully set up.
801-
*/
802-
pci_msix_clear_and_set_ctrl(dev, 0,
803-
PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE);
804-
805804
msix_program_entries(dev, entries);
806805

807806
ret = populate_msi_sysfs(dev);
@@ -836,6 +835,9 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
836835
out_free:
837836
free_msi_irqs(dev);
838837

838+
out_disable:
839+
pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
840+
839841
return ret;
840842
}
841843

0 commit comments

Comments
 (0)