Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66f0d0c4 authored by Yijing Wang's avatar Yijing Wang Committed by Bjorn Helgaas
Browse files

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: default avatarYijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 7171511e
Loading
Loading
Loading
Loading
+16 −23
Original line number Original line Diff line number Diff line
@@ -149,15 +149,14 @@ static void msi_set_enable(struct pci_dev *dev, int enable)
	pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
	pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
}
}


static void msix_set_enable(struct pci_dev *dev, int enable)
static void msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set)
{
{
	u16 control;
	u16 ctrl;


	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
	control &= ~PCI_MSIX_FLAGS_ENABLE;
	ctrl &= ~clear;
	if (enable)
	ctrl |= set;
		control |= PCI_MSIX_FLAGS_ENABLE;
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl);
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
}
}


static inline __attribute_const__ u32 msi_mask(unsigned x)
static inline __attribute_const__ u32 msi_mask(unsigned x)
@@ -469,26 +468,23 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
static void __pci_restore_msix_state(struct pci_dev *dev)
static void __pci_restore_msix_state(struct pci_dev *dev)
{
{
	struct msi_desc *entry;
	struct msi_desc *entry;
	u16 control;


	if (!dev->msix_enabled)
	if (!dev->msix_enabled)
		return;
		return;
	BUG_ON(list_empty(&dev->msi_list));
	BUG_ON(list_empty(&dev->msi_list));
	entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
	entry = list_first_entry(&dev->msi_list, struct msi_desc, list);
	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);


	/* route the table */
	/* route the table */
	pci_intx_for_msi(dev, 0);
	pci_intx_for_msi(dev, 0);
	control |= PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL;
	msix_clear_and_set_ctrl(dev, 0,
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
				PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL);


	arch_restore_msi_irqs(dev);
	arch_restore_msi_irqs(dev);
	list_for_each_entry(entry, &dev->msi_list, list) {
	list_for_each_entry(entry, &dev->msi_list, list) {
		msix_mask_irq(entry, entry->masked);
		msix_mask_irq(entry, entry->masked);
	}
	}


	control &= ~PCI_MSIX_FLAGS_MASKALL;
	msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
}
}


void pci_restore_msi_state(struct pci_dev *dev)
void pci_restore_msi_state(struct pci_dev *dev)
@@ -743,12 +739,10 @@ static int msix_capability_init(struct pci_dev *dev,
	u16 control;
	u16 control;
	void __iomem *base;
	void __iomem *base;


	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);

	/* Ensure MSI-X is disabled while it is set up */
	/* Ensure MSI-X is disabled while it is set up */
	control &= ~PCI_MSIX_FLAGS_ENABLE;
	msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);


	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
	/* Request & Map MSI-X table region */
	/* Request & Map MSI-X table region */
	base = msix_map_region(dev, msix_table_size(control));
	base = msix_map_region(dev, msix_table_size(control));
	if (!base)
	if (!base)
@@ -767,8 +761,8 @@ static int msix_capability_init(struct pci_dev *dev,
	 * MSI-X registers.  We need to mask all the vectors to prevent
	 * MSI-X registers.  We need to mask all the vectors to prevent
	 * interrupts coming in before they're fully set up.
	 * interrupts coming in before they're fully set up.
	 */
	 */
	control |= PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE;
	msix_clear_and_set_ctrl(dev, 0,
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);
				PCI_MSIX_FLAGS_MASKALL | PCI_MSIX_FLAGS_ENABLE);


	msix_program_entries(dev, entries);
	msix_program_entries(dev, entries);


@@ -780,8 +774,7 @@ static int msix_capability_init(struct pci_dev *dev,
	pci_intx_for_msi(dev, 0);
	pci_intx_for_msi(dev, 0);
	dev->msix_enabled = 1;
	dev->msix_enabled = 1;


	control &= ~PCI_MSIX_FLAGS_MASKALL;
	msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
	pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, control);


	return 0;
	return 0;


@@ -1001,7 +994,7 @@ void pci_msix_shutdown(struct pci_dev *dev)
		arch_msix_mask_irq(entry, 1);
		arch_msix_mask_irq(entry, 1);
	}
	}


	msix_set_enable(dev, 0);
	msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
	pci_intx_for_msi(dev, 1);
	pci_intx_for_msi(dev, 1);
	dev->msix_enabled = 0;
	dev->msix_enabled = 0;
}
}
@@ -1065,7 +1058,7 @@ void pci_msi_init_pci_dev(struct pci_dev *dev)


	dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
	dev->msix_cap = pci_find_capability(dev, PCI_CAP_ID_MSIX);
	if (dev->msix_cap)
	if (dev->msix_cap)
		msix_set_enable(dev, 0);
		msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0);
}
}


/**
/**