aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYijing Wang <wangyijing@huawei.com>2014-06-19 04:29:53 -0400
committerBjorn Helgaas <bhelgaas@google.com>2014-07-03 18:48:59 -0400
commit66f0d0c40c08c12d069a2ed513ea48426ecc8820 (patch)
tree39ce899621b16e7bc7bdcd1f13121ed9100e76f1
parent7171511eaec5bf23fb06078f59784a3a0626b38f (diff)
PCI/MSI: Add internal msix_clear_and_set_ctrl() function
Add msix_clear_and_set_ctrl() simplify code. No functional change. [bhelgaas: fix whitespace] Signed-off-by: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/msi.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 13f3d3037272..ba84f17d8062 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -149,15 +149,14 @@ static void msi_set_enable(struct pci_dev *dev, int enable)
149 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); 149 pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
150} 150}
151 151
152static void msix_set_enable(struct pci_dev *dev, int enable) 152static void msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set)
153{ 153{
154 u16 control; 154 u16 ctrl;
155 155
156 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); 156 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
157 control &= ~PCI_MSIX_FLAGS_ENABLE; 157 ctrl &= ~clear;
158 if (enable) 158 ctrl |= set;
159 control |= PCI_MSIX_FLAGS_ENABLE; 159 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl);
160 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
161} 160}
162 161
163static inline __attribute_const__ u32 msi_mask(unsigned x) 162static inline __attribute_const__ u32 msi_mask(unsigned x)
@@ -469,26 +468,23 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
469static void __pci_restore_msix_state(struct pci_dev *dev) 468static void __pci_restore_msix_state(struct pci_dev *dev)
470{ 469{
471 struct msi_desc *entry; 470 struct msi_desc *entry;
472 u16 control;
473 471
474 if (!dev->msix_enabled) 472 if (!dev->msix_enabled)
475 return; 473 return;
476 BUG_ON(list_empty(&dev->msi_list)); 474 BUG_ON(list_empty(&dev->msi_list));
477 entry = list_first_entry(&dev->msi_list, struct msi_desc, list); 475 entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
478 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
479 476
480 /* route the table */ 477 /* route the table */
481 pci_intx_for_msi(dev, 0); 478 pci_intx_for_msi(dev, 0);
482 control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL; 479 msix_clear_and_set_ctrl(dev, 0,
483 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control); 480 PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL);
484 481
485 arch_restore_msi_irqs(dev); 482 arch_restore_msi_irqs(dev);
486 list_for_each_entry(entry, &dev->msi_list, list) { 483 list_for_each_entry(entry, &dev->msi_list, list) {
487 msix_mask_irq(entry, entry->masked); 484 msix_mask_irq(entry, entry->masked);
488 } 485 }
489 486
490 control &= ~PCI_MSIX_FLAGS_MASKALL; 487 msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
491 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
492} 488}
493 489
494void pci_restore_msi_state(struct pci_dev *dev) 490void pci_restore_msi_state(struct pci_dev *dev)
@@ -743,12 +739,10 @@ static int msix_capability_init(struct pci_dev *dev,
743 u16 control; 739 u16 control;
744 void __iomem *base; 740 void __iomem *base;
745 741
746 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
747
748 /* Ensure MSI-X is disabled while it is set up */ 742 /* Ensure MSI-X is disabled while it is set up */
749 control &= ~PCI_MSIX_FLAGS_ENABLE; 743 msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
750 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
751 744
745 pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
752 /* Request & Map MSI-X table region */ 746 /* Request & Map MSI-X table region */
753 base = msix_map_region(dev, msix_table_size(control)); 747 base = msix_map_region(dev, msix_table_size(control));
754 if (!base) 748 if (!base)
@@ -767,8 +761,8 @@ static int msix_capability_init(struct pci_dev *dev,
767 * MSI-X registers. We need to mask all the vectors to prevent 761 * MSI-X registers. We need to mask all the vectors to prevent
768 * interrupts coming in before they're fully set up. 762 * interrupts coming in before they're fully set up.
769 */ 763 */
770 control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE; 764 msix_clear_and_set_ctrl(dev, 0,
771 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control); 765 PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE);
772 766
773 msix_program_entries(dev, entries); 767 msix_program_entries(dev, entries);
774 768
@@ -780,8 +774,7 @@ static int msix_capability_init(struct pci_dev *dev,
780 pci_intx_for_msi(dev, 0); 774 pci_intx_for_msi(dev, 0);
781 dev->msix_enabled = 1; 775 dev->msix_enabled = 1;
782 776
783 control &= ~PCI_MSIX_FLAGS_MASKALL; 777 msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
784 pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
785 778
786 return 0; 779 return 0;
787 780
@@ -1001,7 +994,7 @@ void pci_msix_shutdown(struct pci_dev *dev)
1001 arch_msix_mask_irq(entry, 1); 994 arch_msix_mask_irq(entry, 1);
1002 } 995 }
1003 996
1004 msix_set_enable(dev, 0); 997 msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
1005 pci_intx_for_msi(dev, 1); 998 pci_intx_for_msi(dev, 1);
1006 dev->msix_enabled = 0; 999 dev->msix_enabled = 0;
1007} 1000}
@@ -1065,7 +1058,7 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)
1065 1058
1066 dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX); 1059 dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1067 if (dev->msix_cap) 1060 if (dev->msix_cap)
1068 msix_set_enable(dev, 0); 1061 msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
1069} 1062}
1070 1063
1071/** 1064/**