Skip to contentSkip to conversation

PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0

PATCH In review Yijing Wang 2 participants 3 messages Oct 10, 2013 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0

Currently, if device power state != PCI_D0, we still initialize device MSI/MSIX, but we won't write the MSI message to device MSI/MSIX registers. It's weird, we don't configure MSI/MSIX registers properly, but pci_enable_msi() or pci_enable_msix() return success, and even these registers will never be updated later. So I think it should return error if device power state != PCI_D0.

---

v1->v2: keep __write_msi_msg() function device power state statement,
because Ben Hutchings point out this function may be called
during device in D3 state to set irq affinity. We should not touch that.

---
 drivers/pci/msi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/pci/msi.c +3 -3
index d5f90d6..604265c 100644
@@ -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);
Signature · 1 line
1.7.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yijing Wang

Currently, if device power state != PCI_D0, we still initialize device MSI/MSIX, but we won't write the MSI message to device MSI/MSIX registers. It's weird, we don't configure MSI/MSIX registers properly, but pci_enable_msi() or pci_enable_msix() return success, and even these registers will never be updated later. So I think it should return error if device power state != PCI_D0.

Quoted 8 lines

---

v1->v2: keep __write_msi_msg() function device power state statement,
because Ben Hutchings point out this function may be called
during device in D3 state to set irq affinity. We should not touch that.

S-o-b needs to be above the first '---' but perhaps Bjorn can fix that up before applying.

Quoted 35 lines
---
 drivers/pci/msi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/pci/msi.c +3 -3
index d5f90d6..604265c 100644
@@ -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);
Signature · 2 lines
Ben Hutchings
A free society is one where it is safe to be unpopular. - Adlai Stevenson
#2 lore raw
Quoted 15 lines · Ben Hutchings
Quoted 14 lines · Yijing Wang

Currently, if device power state != PCI_D0, we still initialize device MSI/MSIX, but we won't write the MSI message to device MSI/MSIX registers. It's weird, we don't configure MSI/MSIX registers properly, but pci_enable_msi() or pci_enable_msix() return success, and even these registers will never be updated later. So I think it should return error if device power state != PCI_D0.

---

v1->v2: keep __write_msi_msg() function device power state statement,
because Ben Hutchings point out this function may be called
during device in D3 state to set irq affinity. We should not touch that.

Quoted 6 lines
Quoted 1 line

S-o-b needs to be above the first '---' but perhaps Bjorn can fix that up before applying.

Thanks very much, I will update it, so Bjorn can apply it easily.

Quoted 37 lines
Quoted 36 lines
---
 drivers/pci/msi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/pci/msi.c +3 -3
index d5f90d6..604265c 100644
@@ -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);
Signature · 2 lines
Thanks!
Yijing