]> git.karo-electronics.de Git - linux-beck.git/commitdiff
PCI: Fail MSI/MSI-X initialization if device is not in PCI_D0
authorYijing Wang <wangyijing@huawei.com>
Thu, 10 Oct 2013 12:58:11 +0000 (20:58 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 29 Oct 2013 19:30:52 +0000 (13:30 -0600)
Currently, pci_enable_msi() and pci_enable_msix() return success even if
the device power state is not D0.  However, we don't write the MSI message
to the device registers, and the registers will never be updated later.

This patch makes pci_enable_msi() and pci_enable_msix() return an error
instead.

[bhelgaas: changelog]
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Acked-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/msi.c

index d5f90d6383bc38660dcaba3786adcbf1e78a936b..604265c408534eff2d65436660591fbac3e9b5f7 100644 (file)
@@ -831,7 +831,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
        int status, maxvec;
        u16 msgctl;
 
-       if (!dev->msi_cap)
+       if (!dev->msi_cap || dev->current_state != PCI_D0)
                return -EINVAL;
 
        pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
@@ -862,7 +862,7 @@ int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
        int ret, nvec;
        u16 msgctl;
 
-       if (!dev->msi_cap)
+       if (!dev->msi_cap || dev->current_state != PCI_D0)
                return -EINVAL;
 
        pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
@@ -955,7 +955,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
        int status, nr_entries;
        int i, j;
 
-       if (!entries || !dev->msix_cap)
+       if (!entries || !dev->msix_cap || dev->current_state != PCI_D0)
                return -EINVAL;
 
        status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);