genirq/msi, PCI/MSI: Spring cleaning - Part 1
Subsystems (22)
v2 cover genirq/msi, PCI/MSI: Spring cleaning - Part 1
The [PCI] MSI code has gained quite some warts over time. A recent discussion unearthed a shortcoming: the lack of support for expanding PCI/MSI-X vectors after initialization of MSI-X.
PCI/MSI-X has no requirement to setup all vectors when MSI-X is enabled in the device. The non-used vectors have just to be masked in the vector table. For PCI/MSI this is not possible because the number of vectors cannot be changed after initialization.
The PCI/MSI code, but also the core MSI irq domain code are built around the assumption that all required vectors are installed at initialization time and freed when the device is shut down by the driver.
Supporting dynamic expansion at least for MSI-X is important for VFIO so that the host side interrupts for passthrough devices can be installed on demand.
This is the first part of a large (total 101 patches) series which refactors the [PCI]MSI infrastructure to make runtime expansion of MSI-X vectors possible. The last part (10 patches) provide this functionality.
The first part is mostly a cleanup which consolidates code, moves the PCI MSI code into a separate directory and splits it up into several parts.
No functional change intended except for patch 2/N which changes the behaviour of pci_get_vector()/affinity() to get rid of the assumption that the provided index is the "index" into the descriptor list instead of using it as the actual MSI[X] index as seen by the hardware. This would break users of sparse allocated MSI-X entries, but non of them use these functions.
This series is based on 5.16-rc2 and also available via git:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v2-part-1
For the curious who can't wait for the next part to arrive the full series is available via:
git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git msi-v2-part-3
V1 of this series can be found here:
https://lore.kernel.org/r/[email protected]
Changes versus V1:
- Add missing includes and use correct variable name in legacy code - Cedric
- Moved the MSI lock from struct device to struct pci_dev - New patch
This is really PCI/MSI specific and there is no point to have it in every struct device. Neither does it make sense to hide it in msi_device_data as the V1 series part 2 did.
- Picked up Reviewed/Tested/Acked-by tags as appropriate
Thanks,
tglx
--- arch/powerpc/platforms/4xx/msi.c | 281 ------------ b/Documentation/driver-api/pci/pci.rst | 2 b/arch/mips/pci/msi-octeon.c | 32 - b/arch/powerpc/platforms/4xx/Makefile | 1 b/arch/powerpc/platforms/cell/axon_msi.c | 2 b/arch/powerpc/platforms/powernv/pci-ioda.c | 4 b/arch/powerpc/platforms/pseries/msi.c | 6 b/arch/powerpc/sysdev/Kconfig | 6 b/arch/s390/pci/pci_irq.c | 4 b/arch/sparc/kernel/pci_msi.c | 4 b/arch/x86/hyperv/irqdomain.c | 55 -- b/arch/x86/include/asm/x86_init.h | 6 b/arch/x86/include/asm/xen/hypervisor.h | 8 b/arch/x86/kernel/apic/msi.c | 8 b/arch/x86/kernel/x86_init.c | 12 b/arch/x86/pci/xen.c | 19 b/drivers/base/core.c | 1 b/drivers/irqchip/irq-gic-v2m.c | 1 b/drivers/irqchip/irq-gic-v3-its-pci-msi.c | 1 b/drivers/irqchip/irq-gic-v3-mbi.c | 1 b/drivers/net/wireless/ath/ath11k/pci.c | 2 b/drivers/pci/Makefile | 3 b/drivers/pci/msi/Makefile | 7 b/drivers/pci/msi/irqdomain.c | 267 +++++++++++ b/drivers/pci/msi/legacy.c | 79 +++ b/drivers/pci/msi/msi.c | 647 ++++------------------------ b/drivers/pci/msi/msi.h | 39 + b/drivers/pci/msi/pcidev_msi.c | 43 + b/drivers/pci/pci-sysfs.c | 7 b/drivers/pci/probe.c | 4 b/drivers/pci/xen-pcifront.c | 2 b/include/linux/device.h | 2 b/include/linux/msi.h | 136 ++--- b/include/linux/pci.h | 2 b/kernel/irq/msi.c | 41 + 35 files changed, 702 insertions(+), 1033 deletions(-)
PATCH v2 1/23 powerpc/4xx: Remove MSI support which never worked
This code is broken since day one. ppc4xx_setup_msi_irqs() has the following gems:
1) The handling of the result of msi_bitmap_alloc_hwirqs() is completely broken:
When the result is greater than or equal 0 (bitmap allocation successful) then the loop terminates and the function returns 0 (success) despite not having installed an interrupt.
When the result is less than 0 (bitmap allocation fails), it prints an error message and continues to "work" with that error code which would eventually end up in the MSI message data.
2) On every invocation the file global pp4xx_msi::msi_virqs bitmap is allocated thereby leaking the previous one.
IOW, this has never worked and for more than 10 years nobody cared. Remove the gunk.
--- arch/powerpc/platforms/4xx/Makefile | 1 arch/powerpc/platforms/4xx/msi.c | 281 ------------------------------------ arch/powerpc/sysdev/Kconfig | 6 3 files changed, 288 deletions(-)
arch/powerpc/platforms/4xx/Makefile +0 -1
@@ -3,6 +3,5 @@ obj-y += uic.o machine_check.o obj-$(CONFIG_4xx_SOC) += soc.o obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PPC4xx_HSTA_MSI) += hsta_msi.o -obj-$(CONFIG_PPC4xx_MSI) += msi.o obj-$(CONFIG_PPC4xx_CPM) += cpm.o obj-$(CONFIG_PPC4xx_GPIO) += gpio.o
arch/powerpc/platforms/4xx/msi.c deleted +0 -281
281 lines not on this page · raw message
arch/powerpc/sysdev/Kconfig +0 -6
@@ -12,17 +12,11 @@ config PPC4xx_HSTA_MSI depends on PCI_MSI depends on PCI && 4xx -config PPC4xx_MSI - bool - depends on PCI_MSI - depends on PCI && 4xx - config PPC_MSI_BITMAP bool depends on PCI_MSI default y if MPIC default y if FSL_PCI - default y if PPC4xx_MSI default y if PPC_POWERNV source "arch/powerpc/sysdev/xics/Kconfig"
PATCH v2 2/23 PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
In reply to Thomas Gleixnerpci_irq_vector() and pci_irq_get_affinity() use the list position to find the MSI-X descriptor at a given index. That's correct for the normal case where the entry number is the same as the list position.
But it's wrong for cases where MSI-X was allocated with an entries array describing sparse entry numbers into the hardware message descriptor table. That's inconsistent at best.
Make it always check the entry number because that's what the zero base index really means. This change won't break existing users which use a sparse entries array for allocation because these users retrieve the Linux interrupt number from the entries array after allocation and none of them uses pci_irq_vector() or pci_irq_get_affinity().
---
V2: Fix typo in subject - Jason
--- drivers/pci/msi.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/pci/msi.c +18 -8
@@ -1187,19 +1187,24 @@ EXPORT_SYMBOL(pci_free_irq_vectors);/** * pci_irq_vector - return Linux IRQ number of a device vector -* @dev: PCI device to operate on -* @nr: device-relative interrupt vector index (0-based). +* @dev: PCI device to operate on +* @nr: Interrupt vector index (0-based) +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: The Linux interrupt number or -EINVAl if @nr is out of range. */ int pci_irq_vector (struct pci_dev *dev,unsigned int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return entry->irq; - i++; }WARN_ON_ONCE (1 );return -EINVAL ;
@@ -1223,17 +1228,22 @@ EXPORT_SYMBOL(pci_irq_vector);* pci_irq_get_affinity - return the affinity of a particular MSI vector * @dev: PCI device to operate on * @nr: device-relative interrupt vector index (0-based). +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: A cpumask pointer or NULL if @nr is out of range */ const struct cpumask *pci_irq_get_affinity (struct pci_dev *dev,int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return &entry->affinity->mask; - i++; }WARN_ON_ONCE (1 );return NULL ;
PATCH v2 3/23 genirq/msi: Guard sysfs code
In reply to Thomas GleixnerNo point in building unused code when CONFIG_SYSFS=n.
--- include/linux/msi.h | 10 ++++++++++ kernel/irq/msi.c | 2 ++ 2 files changed, 12 insertions(+)
include/linux/msi.h +10 -0
@@ -239,9 +239,19 @@ void __pci_write_msi_msg(struct msi_descvoid pci_msi_mask_irq (struct irq_data *data);void pci_msi_unmask_irq (struct irq_data *data); +#ifdef CONFIG_SYSFS const struct attribute_group **msi_populate_sysfs (struct device *dev);void msi_destroy_sysfs (struct device *dev,const struct attribute_group **msi_irq_groups); +#else +static inline const struct attribute_group **msi_populate_sysfs (struct device *dev) +{ +return NULL ; +} +static inline void msi_destroy_sysfs (struct device *dev,const struct attribute_group **msi_irq_groups) +{ +} +#endif /* * The arch hooks to setup up msi irqs. Default functions are implemented
kernel/irq/msi.c +2 -0
@@ -72,6 +72,7 @@ void get_cached_msi_msg(unsigned int irq }EXPORT_SYMBOL_GPL (get_cached_msi_msg); +#ifdef CONFIG_SYSFS static ssize_t msi_mode_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -204,6 +205,7 @@ void msi_destroy_sysfs(struct device *de kfree(msi_irq_groups); } } +#endif #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN static inline void irq_chip_write_msi_msg(struct irq_data *data,
PATCH v2 5/23 genirq/msi: Fixup includes
In reply to Thomas GleixnerRemove the kobject.h include from msi.h as it's not required and add a sysfs.h include to the core code instead.
--- include/linux/msi.h | 2 +- kernel/irq/msi.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/msi.h +1 -1
@@ -2,7 +2,7 @@#ifndef LINUX_MSI_H #define LINUX_MSI_H -#include <linux/kobject.h> +#include <linux/cpumask.h> #include <linux/list.h> #include <asm/msi.h>
kernel/irq/msi.c +1 -0
@@ -14,6 +14,7 @@#include <linux/irqdomain.h> #include <linux/msi.h> #include <linux/slab.h> +#include <linux/sysfs.h> #include <linux/pci.h> #include "internals.h"
PATCH v2 4/23 genirq/msi: Remove unused domain callbacks
In reply to Thomas GleixnerNo users and there is no need to grow them.
--- include/linux/msi.h | 11 ++++------- kernel/irq/msi.c | 5 ----- 2 files changed, 4 insertions(+), 12 deletions(-)
include/linux/msi.h +4 -7
@@ -304,7 +304,6 @@ struct msi_domain_info;* @msi_free: Domain specific function to free a MSI interrupts * @msi_check: Callback for verification of the domain/info/dev data * @msi_prepare: Prepare the allocation of the interrupts in the domain -* @msi_finish: Optional callback to finalize the allocation * @set_desc: Set the msi descriptor for an interrupt * @handle_error: Optional error handler if the allocation fails * @domain_alloc_irqs: Optional function to override the default allocation
@@ -312,12 +311,11 @@ struct msi_domain_info;* @domain_free_irqs: Optional function to override the default free * function. * -* @get_hwirq, @msi_init and @msi_free are callbacks used by -* msi_create_irq_domain() and related interfaces +* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying +* irqdomain. * -* @msi_check, @msi_prepare, @msi_finish, @set_desc and @handle_error -* are callbacks used by msi_domain_alloc_irqs() and related -* interfaces which are based on msi_desc. +* @msi_check, @msi_prepare, @handle_error and @set_desc are callbacks used by +* msi_domain_alloc/free_irqs(). * * @domain_alloc_irqs, @domain_free_irqs can be used to override the * default allocation/free functions (__msi_domain_alloc/free_irqs). This
@@ -351,7 +349,6 @@ struct msi_domain_ops {int (*msi_prepare)(struct irq_domain *domain,struct device *dev,int nvec,msi_alloc_info_t *arg); -void (*msi_finish)(msi_alloc_info_t *arg,int retval);void (*set_desc)(msi_alloc_info_t *arg,struct msi_desc *desc); int (*handle_error)(struct irq_domain *domain,
kernel/irq/msi.c +0 -5
@@ -562,8 +562,6 @@ int __msi_domain_alloc_irqs(struct irq_d ret = -ENOSPC ;if (ops->handle_error) ret = ops->handle_error (domain, desc, ret); -if (ops->msi_finish) - ops->msi_finish (&arg, ret);return ret; }
@@ -573,9 +571,6 @@ int __msi_domain_alloc_irqs(struct irq_d } } -if (ops->msi_finish) - ops->msi_finish (&arg,0 ); - can_reserve =msi_check_reservation_mode (domain, info, dev);/*
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 6/23 PCI/MSI: Make pci_msi_domain_write_msg() static
In reply to Thomas GleixnerThere is no point to have this function public as it is set by the PCI core anyway when a PCI/MSI irqdomain is created.
--- drivers/irqchip/irq-gic-v2m.c | 1 - drivers/irqchip/irq-gic-v3-its-pci-msi.c | 1 - drivers/irqchip/irq-gic-v3-mbi.c | 1 - drivers/pci/msi.c | 2 +- include/linux/msi.h | 1 - 5 files changed, 1 insertion(+), 5 deletions(-)
drivers/irqchip/irq-gic-v2m.c +0 -1
@@ -88,7 +88,6 @@ static struct irq_chip gicv2m_msi_irq_ch .irq_mask = gicv2m_mask_msi_irq, .irq_unmask = gicv2m_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info gicv2m_msi_domain_info = {
drivers/irqchip/irq-gic-v3-its-pci-msi.c +0 -1
@@ -28,7 +28,6 @@ static struct irq_chip its_msi_irq_chip .irq_unmask = its_unmask_msi_irq, .irq_mask = its_mask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static int its_pci_msi_vec_count (struct pci_dev *pdev,void *data)
drivers/irqchip/irq-gic-v3-mbi.c +0 -1
@@ -171,7 +171,6 @@ static struct irq_chip mbi_msi_irq_chip .irq_unmask = mbi_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, .irq_compose_msi_msg = mbi_compose_msi_msg, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info mbi_msi_domain_info = {
drivers/pci/msi.c +1 -1
@@ -1281,7 +1281,7 @@ EXPORT_SYMBOL_GPL(msi_desc_to_pci_sysdat* @irq_data: Pointer to interrupt data of the MSI interrupt * @msg: Pointer to the message */ -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) +static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) {struct msi_desc *desc =irq_data_get_msi_desc (irq_data);
include/linux/msi.h +0 -1
@@ -455,7 +455,6 @@ void *platform_msi_get_host_data(struct#endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */ #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg);struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 7/23 PCI/MSI: Remove msi_desc_to_pci_sysdata()
In reply to Thomas GleixnerLast user is gone long ago.
--- drivers/pci/msi.c | 8 -------- include/linux/msi.h | 5 ----- 2 files changed, 13 deletions(-)
drivers/pci/msi.c +0 -8
@@ -1267,14 +1267,6 @@ struct pci_dev *msi_desc_to_pci_dev(stru }EXPORT_SYMBOL (msi_desc_to_pci_dev); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (desc); - -return dev->bus->sysdata; -} -EXPORT_SYMBOL_GPL (msi_desc_to_pci_sysdata); -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN /** * pci_msi_domain_write_msg - Helper to write MSI message to PCI config space
include/linux/msi.h +0 -5
@@ -218,13 +218,8 @@ static inline void msi_desc_set_iommu_cofor_each_msi_entry ((desc), &(pdev)->dev) struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc);void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg);#else /* CONFIG_PCI_MSI */ -static inline void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -return NULL ; -}static inline void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg) { }
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 8/23 PCI/sysfs: Use pci_irq_vector()
In reply to Thomas Gleixnerinstead of fiddling with msi descriptors.
--- drivers/pci/pci-sysfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/pci/pci-sysfs.c +2 -5
@@ -62,11 +62,8 @@ static ssize_t irq_show(struct device *d* For MSI, show the first MSI IRQ; for all other cases including * MSI-X, show the legacy INTx IRQ. */ -if (pdev->msi_enabled) { -struct msi_desc *desc =first_pci_msi_entry (pdev); - -return sysfs_emit (buf,"%u\n" , desc->irq); - } +if (pdev->msi_enabled) +return sysfs_emit (buf,"%u\n" ,pci_irq_vector (pdev,0 ));#endif return sysfs_emit (buf,"%u\n" , pdev->irq);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 9/23 MIPS: Octeon: Use arch_setup_msi_irq()
In reply to Thomas GleixnerThe core code provides the same loop code except for the MSI-X reject. Move that to arch_setup_msi_irq() and remove the duplicated code.
No functional change.
--- arch/mips/pci/msi-octeon.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
arch/mips/pci/msi-octeon.c +3 -29
@@ -68,6 +68,9 @@ int arch_setup_msi_irq(struct pci_dev *du64 search_mask;int index; +if (desc->pci.msi_attrib.is_msix) +return -EINVAL ; +/* * Read the MSI config to figure out how many IRQs this device * wants. Most devices only want 1, which will give
@@ -182,35 +185,6 @@ int arch_setup_msi_irq(struct pci_dev *dreturn 0 ; } -int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct msi_desc *entry; -int ret; - -/* -* MSI-X is not supported. -*/ -if (type ==PCI_CAP_ID_MSIX ) -return -EINVAL ; - -/* -* If an architecture wants to support multiple MSI, it needs to -* override arch_setup_msi_irqs() -*/ -if (type ==PCI_CAP_ID_MSI && nvec >1 ) -return 1 ; - -for_each_pci_msi_entry (entry, dev) { - ret =arch_setup_msi_irq (dev, entry); -if (ret <0 ) -return ret; -if (ret >0 ) -return -ENOSPC ; - } - -return 0 ; -} -/** * Called when a device no longer needs its MSI interrupts. All * MSI interrupts for the device are freed.
PATCH v2 12/23 PCI/MSI: Make arch_restore_msi_irqs() less horrible.
In reply to Thomas GleixnerMake arch_restore_msi_irqs() return a boolean which indicates whether the core code should restore the MSI message or not. Get rid of the indirection in x86.
--- arch/s390/pci/pci_irq.c | 4 +- arch/x86/include/asm/x86_init.h | 6 --- arch/x86/include/asm/xen/hypervisor.h | 8 +++++ arch/x86/kernel/apic/msi.c | 6 +++ arch/x86/kernel/x86_init.c | 12 ------- arch/x86/pci/xen.c | 13 ++++---- drivers/pci/msi.c | 54 +++++++++++----------------------- include/linux/msi.h | 7 +--- 8 files changed, 45 insertions(+), 65 deletions(-)
arch/s390/pci/pci_irq.c +2 -2
@@ -387,13 +387,13 @@ void arch_teardown_msi_irqs(struct pci_dairq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, zdev->msi_nr_irqs); } -void arch_restore_msi_irqs (struct pci_dev *pdev) +bool arch_restore_msi_irqs (struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev);if (!zdev->irqs_registered)zpci_set_irq (zdev); -default_restore_msi_irqs (pdev); +return true; }static struct airq_struct zpci_airq = {
arch/x86/include/asm/x86_init.h +0 -6
@@ -289,12 +289,6 @@ struct x86_platform_ops {struct x86_hyper_runtime hyper; }; -struct pci_dev ; - -struct x86_msi_ops { -void (*restore_msi_irqs)(struct pci_dev *dev); -}; -struct x86_apic_ops {unsigned int (*io_apic_read) (unsigned int apic,unsigned int reg);void (*restore)(void );
arch/x86/include/asm/xen/hypervisor.h +8 -0
@@ -57,6 +57,14 @@ static inline bool __init xen_x2apic_par }#endif +struct pci_dev ; + +#ifdef CONFIG_XEN_DOM0 +bool xen_initdom_restore_msi (struct pci_dev *dev); +#else +static inline bool xen_initdom_restore_msi (struct pci_dev *dev) {return true; } +#endif +#ifdef CONFIG_HOTPLUG_CPU void xen_arch_register_cpu (int num);void xen_arch_unregister_cpu (int num);
arch/x86/kernel/apic/msi.c +6 -0
@@ -19,6 +19,7 @@#include <asm/hw_irq.h> #include <asm/apic.h> #include <asm/irq_remapping.h> +#include <asm/xen/hypervisor.h> struct irq_domain *x86_pci_msi_default_domain__ro_after_init ;
@@ -345,3 +346,8 @@ void dmar_free_hwirq(int irq) irq_domain_free_irqs(irq, 1); }#endif + +bool arch_restore_msi_irqs (struct pci_dev *dev) +{ +return xen_initdom_restore_msi (dev); +}
arch/x86/kernel/x86_init.c +0 -12
@@ -145,18 +145,6 @@ struct x86_platform_ops x86_platform __rEXPORT_SYMBOL_GPL (x86_platform); -#if defined(CONFIG_PCI_MSI ) -struct x86_msi_ops x86_msi__ro_after_init = { - .restore_msi_irqs = default_restore_msi_irqs, -}; - -/* MSI arch specific hooks */ -void arch_restore_msi_irqs (struct pci_dev *dev) -{ - x86_msi.restore_msi_irqs (dev); -} -#endif -struct x86_apic_ops x86_apic_ops__ro_after_init = { .io_apic_read = native_io_apic_read, .restore = native_restore_boot_irq_mode,
arch/x86/pci/xen.c +7 -6
@@ -351,10 +351,13 @@ static int xen_initdom_setup_msi_irqs(streturn ret; } -static void xen_initdom_restore_msi_irqs (struct pci_dev *dev) +bool xen_initdom_restore_msi (struct pci_dev *dev) {int ret =0 ; +if (!xen_initial_domain ()) +return true; +if (pci_seg_supported) {struct physdev_pci_device restore_ext;
@@ -375,10 +378,10 @@ static void xen_initdom_restore_msi_irqs ret =HYPERVISOR_physdev_op (PHYSDEVOP_restore_msi, &restore); WARN(ret && ret != -ENOSYS, "restore_msi -> %d\n", ret); } +return false; }#else /* CONFIG_XEN_PV_DOM0 */ #define xen_initdom_setup_msi_irqs NULL -#define xen_initdom_restore_msi_irqs NULL#endif /* !CONFIG_XEN_PV_DOM0 */ static void xen_teardown_msi_irqs (struct pci_dev *dev)
@@ -466,12 +469,10 @@ static __init struct irq_domain *xen_crestatic __init void xen_setup_pci_msi (void ) {if (xen_pv_domain ()) { -if (xen_initial_domain ()) { +if (xen_initial_domain ()) xen_msi_ops.setup_msi_irqs = xen_initdom_setup_msi_irqs; - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs; - }else { +else xen_msi_ops.setup_msi_irqs = xen_setup_msi_irqs; - } xen_msi_ops.teardown_msi_irqs = xen_pv_teardown_msi_irqs; pci_msi_ignore_mask =1 ; }else if (xen_hvm_domain ()) {
drivers/pci/msi.c +19 -35
94 lines not on this page · raw message
include/linux/msi.h +3 -4
@@ -273,11 +273,10 @@ static inline void arch_teardown_msi_irq#endif /* -* The restore hooks are still available as they are useful even -* for fully irq domain based setups. Courtesy to XEN/X86. +* The restore hook is still available even for fully irq domain based +* setups. Courtesy to XEN/X86. */ -void arch_restore_msi_irqs (struct pci_dev *dev); -void default_restore_msi_irqs (struct pci_dev *dev); +bool arch_restore_msi_irqs (struct pci_dev *dev);#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 14/23 PCI/MSI: Make msix_update_entries() smarter
In reply to Thomas GleixnerNo need to walk the descriptors and check for each one whether the entries pointer function argument is NULL. Do it once.
--- drivers/pci/msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi.c +2 -2
@@ -642,8 +642,8 @@ static void msix_update_entries(struct p {struct msi_desc *entry; -for_each_pci_msi_entry (entry, dev) { -if (entries) { +if (entries) { +for_each_pci_msi_entry (entry, dev) { entries->vector = entry->irq; entries++; }
PATCH v2 13/23 PCI/MSI: Cleanup include zoo
In reply to Thomas GleixnerGet rid of the pile of unneeded includes which accumulated over time.
---
V2: Address build fail on powerpc - Cedric
--- drivers/pci/msi.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/pci/msi.c +4 -12
@@ -7,22 +7,14 @@* Copyright (C) 2016 Christoph Hellwig. */ +#include <linux/acpi_iort.h> #include <linux/err.h> -#include <linux/mm.h> -#include <linux/irq.h> -#include <linux/interrupt.h> #include <linux/export.h> -#include <linux/ioport.h> -#include <linux/pci.h> -#include <linux/proc_fs.h> -#include <linux/msi.h> -#include <linux/smp.h> -#include <linux/errno.h> -#include <linux/io.h> -#include <linux/acpi_iort.h> -#include <linux/slab.h> +#include <linux/irq.h> #include <linux/irqdomain.h> +#include <linux/msi.h> #include <linux/of_irq.h> +#include <linux/pci.h> #include "pci.h"
PATCH v2 10/23 genirq/msi, treewide: Use a named struct for PCI/MSI attributes
In reply to Thomas GleixnerThe unnamed struct sucks and is in the way of further cleanups. Stick the PCI related MSI data into a real data structure and cleanup all users.
No functional change.
--- arch/powerpc/platforms/cell/axon_msi.c | 2 arch/powerpc/platforms/powernv/pci-ioda.c | 4 - arch/powerpc/platforms/pseries/msi.c | 6 - arch/sparc/kernel/pci_msi.c | 4 - arch/x86/kernel/apic/msi.c | 2 arch/x86/pci/xen.c | 6 - drivers/net/wireless/ath/ath11k/pci.c | 2 drivers/pci/msi.c | 116 +++++++++++++++--------------- drivers/pci/xen-pcifront.c | 2 include/linux/msi.h | 84 ++++++++++----------- kernel/irq/msi.c | 4 - 11 files changed, 115 insertions(+), 117 deletions(-)
arch/powerpc/platforms/cell/axon_msi.c +1 -1
@@ -212,7 +212,7 @@ static int setup_msi_msg_address(struct entry =first_pci_msi_entry (dev);for (; dn; dn =of_get_next_parent (dn)) { -if (entry->msi_attrib.is_64) { +if (entry->pci.msi_attrib.is_64) { prop =of_get_property (dn,"msi-address-64" , &len);if (prop)break ;
arch/powerpc/platforms/powernv/pci-ioda.c +2 -2
@@ -2154,10 +2154,10 @@ static void pnv_msi_compose_msg(struct iint rc; rc =__pnv_pci_ioda_msi_setup (phb, pdev, d->hwirq, - entry->msi_attrib.is_64, msg); + entry->pci.msi_attrib.is_64, msg);if (rc)dev_err (&pdev->dev,"Failed to setup %s-bit MSI #%ld : %d\n" , - entry->msi_attrib.is_64 ?"64" :"32" , d->hwirq, rc); + entry->pci.msi_attrib.is_64 ?"64" :"32" , d->hwirq, rc); }/*
arch/powerpc/platforms/pseries/msi.c +3 -3
@@ -332,7 +332,7 @@ static int check_msix_entries(struct pci expected =0 ;for_each_pci_msi_entry (entry, pdev) { -if (entry->msi_attrib.entry_nr != expected) { +if (entry->pci.msi_attrib.entry_nr != expected) {pr_debug ("rtas_msi: bad MSI-X entries.\n" );return -EINVAL ; }
@@ -449,7 +449,7 @@ static int pseries_msi_ops_prepare(struc {struct pci_dev *pdev =to_pci_dev (dev);struct msi_desc *desc =first_pci_msi_entry (pdev); -int type = desc->msi_attrib.is_msix ?PCI_CAP_ID_MSIX :PCI_CAP_ID_MSI ; +int type = desc->pci.msi_attrib.is_msix ?PCI_CAP_ID_MSIX :PCI_CAP_ID_MSI ;return rtas_prepare_msi_irqs (pdev, nvec, type, arg); }
@@ -580,7 +580,7 @@ static int pseries_irq_domain_alloc(struint hwirq;int i, ret; - hwirq =rtas_query_irq_number (pci_get_pdn (pdev), desc->msi_attrib.entry_nr); + hwirq =rtas_query_irq_number (pci_get_pdn (pdev), desc->pci.msi_attrib.entry_nr);if (hwirq <0 ) {dev_err (&pdev->dev,"Failed to query HW IRQ: %d\n" , hwirq);return hwirq;
arch/sparc/kernel/pci_msi.c +2 -2
@@ -146,13 +146,13 @@ static int sparc64_setup_msi_irq(unsigne msiqid =pick_msiq (pbm); err = ops->msi_setup (pbm, msiqid, msi, - (entry->msi_attrib.is_64 ?1 :0 )); + (entry->pci.msi_attrib.is_64 ?1 :0 ));if (err) goto out_msi_free; pbm->msi_irq_table[msi - pbm->msi_first] = *irq_p; -if (entry->msi_attrib.is_64) { +if (entry->pci.msi_attrib.is_64) { msg.address_hi = pbm->msi64_start >>32 ; msg.address_lo = pbm->msi64_start &0xffffffff ; }else {
arch/x86/kernel/apic/msi.c +1 -1
@@ -163,7 +163,7 @@ int pci_msi_prepare(struct irq_domain *dstruct msi_desc *desc =first_pci_msi_entry (pdev);init_irq_alloc_info (arg,NULL ); -if (desc->msi_attrib.is_msix) { +if (desc->pci.msi_attrib.is_msix) { arg->type =X86_IRQ_ALLOC_TYPE_PCI_MSIX ; }else { arg->type =X86_IRQ_ALLOC_TYPE_PCI_MSI ;
arch/x86/pci/xen.c +3 -3
@@ -306,7 +306,7 @@ static int xen_initdom_setup_msi_irqs(streturn -EINVAL ; map_irq.table_base =pci_resource_start (dev, bir); - map_irq.entry_nr = msidesc->msi_attrib.entry_nr; + map_irq.entry_nr = msidesc->pci.msi_attrib.entry_nr; } ret = -EINVAL ;
@@ -398,7 +398,7 @@ static void xen_pv_teardown_msi_irqs(str {struct msi_desc *msidesc =first_pci_msi_entry (dev); -if (msidesc->msi_attrib.is_msix) +if (msidesc->pci.msi_attrib.is_msix)xen_pci_frontend_disable_msix (dev);else xen_pci_frontend_disable_msi (dev);
@@ -414,7 +414,7 @@ static int xen_msi_domain_alloc_irqs(strif (WARN_ON_ONCE (!dev_is_pci (dev)))return -EINVAL ; -if (first_msi_entry (dev)->msi_attrib.is_msix) +if (first_msi_entry (dev)->pci.msi_attrib.is_msix) type =PCI_CAP_ID_MSIX ;else type =PCI_CAP_ID_MSI ;
drivers/net/wireless/ath/ath11k/pci.c +1 -1
@@ -911,7 +911,7 @@ static int ath11k_pci_alloc_msi(struct a } ab_pci->msi_ep_base_data = msi_desc->msg.data; -if (msi_desc->msi_attrib.is_64) +if (msi_desc->pci.msi_attrib.is_64)set_bit (ATH11K_PCI_FLAG_IS_MSI_64 , &ab_pci->flags);ath11k_dbg (ab,ATH11K_DBG_PCI ,"msi base data is %d\n" , ab_pci->msi_ep_base_data);
drivers/pci/msi.c +58 -58
278 lines not on this page · raw message
drivers/pci/xen-pcifront.c +1 -1
@@ -263,7 +263,7 @@ static int pci_frontend_enable_msix(stru i =0 ;for_each_pci_msi_entry (entry, dev) { - op.msix_entries[i].entry = entry->msi_attrib.entry_nr; + op.msix_entries[i].entry = entry->pci.msi_attrib.entry_nr;/* Vector is useless at this point. */ op.msix_entries[i].vector =-1 ; i++;
include/linux/msi.h +41 -43
102 lines not on this page · raw message
kernel/irq/msi.c +2 -2
@@ -91,7 +91,7 @@ static ssize_t msi_mode_show(struct devireturn -ENODEV ;if (dev_is_pci (dev)) - is_msix = entry->msi_attrib.is_msix; + is_msix = entry->pci.msi_attrib.is_msix;return sysfs_emit (buf,"%s\n" , is_msix ?"msix" :"msi" ); }
@@ -535,7 +535,7 @@ static bool msi_check_reservation_mode(s* masking and MSI does so when the can_mask attribute is set. */ desc =first_msi_entry (dev); -return desc->msi_attrib.is_msix || desc->msi_attrib.can_mask; +return desc->pci.msi_attrib.is_msix || desc->pci.msi_attrib.can_mask; } int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
PATCH v2 16/23 PCI/MSI: Split out CONFIG_PCI_MSI independent part
In reply to Thomas GleixnerThese functions are required even when CONFIG_PCI_MSI is not set. Move them to their own file.
--- drivers/pci/msi/Makefile | 3 ++- drivers/pci/msi/msi.c | 39 --------------------------------------- drivers/pci/msi/pcidev_msi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 40 deletions(-)
drivers/pci/msi/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.o
drivers/pci/msi/msi.c +0 -39
@@ -18,8 +18,6 @@#include "../pci.h" -#ifdef CONFIG_PCI_MSI -static int pci_msi_enable =1 ;int pci_msi_ignore_mask;
@@ -1493,40 +1491,3 @@ bool pci_dev_has_special_msi_domain(stru }#endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ -#endif /* CONFIG_PCI_MSI */ - -void pci_msi_init (struct pci_dev *dev) -{ -u16 ctrl; - -/* -* Disable the MSI hardware to avoid screaming interrupts -* during boot. This is the power on reset default so -* usually this should be a noop. -*/ - dev->msi_cap =pci_find_capability (dev,PCI_CAP_ID_MSI ); -if (!dev->msi_cap) -return ; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &ctrl); -if (ctrl &PCI_MSI_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , - ctrl & ~PCI_MSI_FLAGS_ENABLE ); - -if (!(ctrl &PCI_MSI_FLAGS_64BIT )) - dev->no_64bit_msi =1 ; -} - -void pci_msix_init (struct pci_dev *dev) -{ -u16 ctrl; - - dev->msix_cap =pci_find_capability (dev,PCI_CAP_ID_MSIX ); -if (!dev->msix_cap) -return ; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); -if (ctrl &PCI_MSIX_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , - ctrl & ~PCI_MSIX_FLAGS_ENABLE ); -}
drivers/pci/msi/pcidev_msi.c new file +43 -0
43 lines not on this page · raw message
PATCH v2 11/23 x86/hyperv: Refactor hv_msi_domain_free_irqs()
In reply to Thomas GleixnerNo point in looking up things over and over. Just look up the associated irq data and work from there.
No functional change.
--- arch/x86/hyperv/irqdomain.c | 55 +++++++++++++------------------------------- 1 file changed, 17 insertions(+), 38 deletions(-)
arch/x86/hyperv/irqdomain.c +17 -38
@@ -253,64 +253,43 @@ static int hv_unmap_msi_interrupt(structreturn hv_unmap_interrupt (hv_build_pci_dev_id (dev).as_uint64, old_entry); } -static void hv_teardown_msi_irq_common (struct pci_dev *dev,struct msi_desc *msidesc,int irq) +static void hv_teardown_msi_irq (struct pci_dev *dev,struct irq_data *irqd) { -u64 status;struct hv_interrupt_entry old_entry; -struct irq_desc *desc; -struct irq_data *data;struct msi_msg msg; +u64 status; - desc =irq_to_desc (irq); -if (!desc) { -pr_debug ("%s: no irq desc\n" , __func__); -return ; - } - - data = &desc->irq_data; -if (!data) { -pr_debug ("%s: no irq data\n" , __func__); -return ; - } - -if (!data->chip_data) { +if (!irqd->chip_data) {pr_debug ("%s: no chip data\n!" , __func__);return ; } - old_entry = *(struct hv_interrupt_entry *)data->chip_data; + old_entry = *(struct hv_interrupt_entry *)irqd->chip_data;entry_to_msi_msg (&old_entry, &msg); -kfree (data->chip_data); - data->chip_data =NULL ; +kfree (irqd->chip_data); + irqd->chip_data =NULL ; status =hv_unmap_msi_interrupt (dev, &old_entry); -if (status !=HV_STATUS_SUCCESS ) { +if (status !=HV_STATUS_SUCCESS )pr_err ("%s: hypercall failed, status %lld\n" , __func__, status); -return ; - } } -static void hv_msi_domain_free_irqs (struct irq_domain *domain,struct device *dev) +static void hv_msi_free_irq (struct irq_domain *domain, +struct msi_domain_info *info,unsigned int virq) { -int i; -struct msi_desc *entry; -struct pci_dev *pdev; +struct irq_data *irqd =irq_get_irq_data (virq); +struct msi_desc *desc; -if (WARN_ON_ONCE (!dev_is_pci (dev))) +if (!irqd)return ; - pdev =to_pci_dev (dev); + desc =irq_data_get_msi_desc (irqd); +if (!desc || !desc->irq ||WARN_ON_ONCE (!dev_is_pci (desc->dev))) +return ; -for_each_pci_msi_entry (entry, pdev) { -if (entry->irq) { -for (i =0 ; i < entry->nvec_used; i++) { -hv_teardown_msi_irq_common (pdev, entry, entry->irq + i); -irq_domain_free_irqs (entry->irq + i,1 ); - } - } - } +hv_teardown_msi_irq (to_pci_dev (desc->dev), irqd); }/*
@@ -329,7 +308,7 @@ static struct irq_chip hv_pci_msi_contro };static struct msi_domain_ops pci_msi_domain_ops = { - .domain_free_irqs = hv_msi_domain_free_irqs, + .msi_free = hv_msi_free_irq, .msi_prepare = pci_msi_prepare, };
PATCH v2 15/23 PCI/MSI: Move code into a separate directory
In reply to Thomas Gleixnermsi.c is getting larger and really could do with a splitup. Move it into it's own directory to prepare for that.
--- Documentation/driver-api/pci/pci.rst | 2 drivers/pci/Makefile | 3 drivers/pci/msi.c | 1532 ----------------------------------- drivers/pci/msi/Makefile | 4 drivers/pci/msi/msi.c | 1532 +++++++++++++++++++++++++++++++++++ 5 files changed, 1539 insertions(+), 1534 deletions(-)
Documentation/driver-api/pci/pci.rst +1 -1
@@ -13,7 +13,7 @@ PCI Support Library .. kernel-doc:: drivers/pci/search.c :export: -.. kernel-doc:: drivers/pci/msi.c +.. kernel-doc:: drivers/pci/msi/msi.c :export: .. kernel-doc:: drivers/pci/bus.c
drivers/pci/Makefile +2 -1
@@ -5,8 +5,9 @@ obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \ remove.o pci.o pci-driver.o search.o \ pci-sysfs.o rom.o setup-res.o irq.o vpd.o \ - setup-bus.o vc.o mmap.o setup-irq.o msi.o + setup-bus.o vc.o mmap.o setup-irq.o +obj-$(CONFIG_PCI) += msi/ obj-$(CONFIG_PCI) += pcie/ ifdef CONFIG_PCI
drivers/pci/msi.c deleted +0 -1532
1,532 lines not on this page · raw message
drivers/pci/msi/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the PCI/MSI +obj-$(CONFIG_PCI) += msi.o
drivers/pci/msi/msi.c new file +1532 -0
1,446 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH v2 17/23 PCI/MSI: Split out !IRQDOMAIN code
In reply to Thomas GleixnerSplit out the non irqdomain code into its own file.
---
V2: Add proper includes and fix variable name - Cedric
--- drivers/pci/msi/Makefile | 5 ++-- drivers/pci/msi/legacy.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/msi/msi.c | 46 ----------------------------------------- 3 files changed, 55 insertions(+), 48 deletions(-)
drivers/pci/msi/Makefile +3 -2
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += pcidev_msi.o -obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o
drivers/pci/msi/legacy.c new file +52 -0
52 lines not on this page · raw message
drivers/pci/msi/msi.c +0 -46
52 lines not on this page · raw message
PATCH v2 19/23 PCI/MSI: Sanitize MSIX table map handling
In reply to Thomas GleixnerUnmapping the MSIX base mapping in the loops which allocate/free MSI desciptors is daft and in the way of allowing runtime expansion of MSI-X descriptors.
Store the mapping in struct pci_dev and free it after freeing the MSI-X descriptors.
--- drivers/pci/msi/msi.c | 18 ++++++++---------- include/linux/pci.h | 1 + 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/pci/msi/msi.c +8 -10
@@ -241,14 +241,14 @@ static void free_msi_irqs(struct pci_devpci_msi_teardown_msi_irqs (dev);list_for_each_entry_safe (entry, tmp, msi_list, list) { -if (entry->pci.msi_attrib.is_msix) { -if (list_is_last (&entry->list, msi_list)) -iounmap (entry->pci.mask_base); - } -list_del (&entry->list);free_msi_entry (entry); } + +if (dev->msix_base) { +iounmap (dev->msix_base); + dev->msix_base =NULL ; + } }static void pci_intx_for_msi (struct pci_dev *dev,int enable)
@@ -501,10 +501,6 @@ static int msix_setup_entries(struct pcifor (i =0 , curmsk = masks; i < nvec; i++) { entry =alloc_msi_entry (&dev->dev,1 , curmsk);if (!entry) { -if (!i) -iounmap (base); -else -free_msi_irqs (dev);/* No enough memory. Don't try again */ ret = -ENOMEM ; goto out;
@@ -602,12 +598,14 @@ static int msix_capability_init(struct p goto out_disable; } + dev->msix_base = base; +/* Ensure that all table entries are masked. */ msix_mask_all (base, tsize); ret =msix_setup_entries (dev, base, entries, nvec, affd);if (ret) - goto out_disable; + goto out_free; ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret)
include/linux/pci.h +1 -0
@@ -473,6 +473,7 @@ struct pci_dev {u8 ptm_granularity;#endif #ifdef CONFIG_PCI_MSI +void __iomem *msix_base;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 21/23 PCI/MSI: Make pci_msi_domain_check_cap() static
In reply to Thomas GleixnerNo users outside of that file.
--- drivers/pci/msi/irqdomain.c | 5 +++-- include/linux/msi.h | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/pci/msi/irqdomain.c +3 -2
@@ -79,8 +79,9 @@ static inline bool pci_msi_desc_is_multi* 1 if Multi MSI is requested, but the domain does not support it * -ENOTSUPP otherwise */ -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev) +static int pci_msi_domain_check_cap (struct irq_domain *domain, +struct msi_domain_info *info, +struct device *dev) {struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev));
include/linux/msi.h +0 -2
@@ -439,8 +439,6 @@ void *platform_msi_get_host_data(structstruct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent); -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev);u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev);struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev);bool pci_dev_has_special_msi_domain (struct pci_dev *pdev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 22/23 genirq/msi: Handle PCI/MSI allocation fail in core code
In reply to Thomas GleixnerGet rid of yet another irqdomain callback and let the core code return the already available information of how many descriptors could be allocated.
--- drivers/pci/msi/irqdomain.c | 13 ------------- include/linux/msi.h | 5 +---- kernel/irq/msi.c | 29 +++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 21 deletions(-)
drivers/pci/msi/irqdomain.c +0 -13
@@ -95,16 +95,6 @@ static int pci_msi_domain_check_cap(strureturn 0 ; } -static int pci_msi_domain_handle_error (struct irq_domain *domain, -struct msi_desc *desc,int error) -{ -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) -return 1 ; - -return error; -} -static void pci_msi_domain_set_desc (msi_alloc_info_t *arg,struct msi_desc *desc) {
@@ -115,7 +105,6 @@ static void pci_msi_domain_set_desc(msi_static struct msi_domain_ops pci_msi_domain_ops_default = { .set_desc = pci_msi_domain_set_desc, .msi_check = pci_msi_domain_check_cap, - .handle_error = pci_msi_domain_handle_error, };static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info)
@@ -129,8 +118,6 @@ static void pci_msi_domain_update_dom_op ops->set_desc = pci_msi_domain_set_desc;if (ops->msi_check ==NULL ) ops->msi_check = pci_msi_domain_check_cap; -if (ops->handle_error ==NULL ) - ops->handle_error = pci_msi_domain_handle_error; } }
include/linux/msi.h +1 -4
@@ -286,7 +286,6 @@ struct msi_domain_info;* @msi_check: Callback for verification of the domain/info/dev data * @msi_prepare: Prepare the allocation of the interrupts in the domain * @set_desc: Set the msi descriptor for an interrupt -* @handle_error: Optional error handler if the allocation fails * @domain_alloc_irqs: Optional function to override the default allocation * function. * @domain_free_irqs: Optional function to override the default free
@@ -295,7 +294,7 @@ struct msi_domain_info;* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * -* @msi_check, @msi_prepare, @handle_error and @set_desc are callbacks used by +* @msi_check, @msi_prepare and @set_desc are callbacks used by * msi_domain_alloc/free_irqs(). * * @domain_alloc_irqs, @domain_free_irqs can be used to override the
@@ -332,8 +331,6 @@ struct msi_domain_ops { msi_alloc_info_t *arg);void (*set_desc)(msi_alloc_info_t *arg,struct msi_desc *desc); -int (*handle_error)(struct irq_domain *domain, -struct msi_desc *desc,int error);int (*domain_alloc_irqs)(struct irq_domain *domain,struct device *dev,int nvec); void (*domain_free_irqs)(struct irq_domain *domain,
kernel/irq/msi.c +25 -4
@@ -538,6 +538,27 @@ static bool msi_check_reservation_mode(sreturn desc->pci.msi_attrib.is_msix || desc->pci.msi_attrib.can_mask; } +static int msi_handle_pci_fail (struct irq_domain *domain,struct msi_desc *desc, +int allocated) +{ +switch (domain->bus_token) { +case DOMAIN_BUS_PCI_MSI : +case DOMAIN_BUS_VMD_MSI : +if (IS_ENABLED (CONFIG_PCI_MSI )) +break ; + fallthrough; +default : +return -ENOSPC ; + } + +/* Let a failed PCI multi MSI allocation retry */ +if (desc->nvec_used >1 ) +return 1 ; + +/* If there was a successful allocation let the caller know */ +return allocated ? allocated : -ENOSPC ; +} +int __msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev,int nvec) {
@@ -546,6 +567,7 @@ int __msi_domain_alloc_irqs(struct irq_dstruct irq_data *irq_data;struct msi_desc *desc;msi_alloc_info_t arg = { }; +int allocated =0 ;int i, ret, virq;bool can_reserve;
@@ -560,16 +582,15 @@ int __msi_domain_alloc_irqs(struct irq_ddev_to_node (dev), &arg, false, desc->affinity);if (virq <0 ) { - ret = -ENOSPC ; -if (ops->handle_error) - ret = ops->handle_error (domain, desc, ret); -return ret; + ret =msi_handle_pci_fail (domain, desc, allocated); + goto cleanup; }for (i =0 ; i < desc->nvec_used; i++) {irq_set_msi_desc_off (virq, i, desc);irq_debugfs_copy_devname (virq + i, dev); } + allocated++; } can_reserve =msi_check_reservation_mode (domain, info, dev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 23/23 PCI/MSI: Move descriptor counting on allocation fail to the legacy code
In reply to Thomas GleixnerThe irqdomain code already returns the information. Move the loop to the legacy code.
--- drivers/pci/msi/legacy.c | 20 +++++++++++++++++++- drivers/pci/msi/msi.c | 19 +------------------ 2 files changed, 20 insertions(+), 19 deletions(-)
drivers/pci/msi/legacy.c +19 -1
@@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struc } } +static int pci_msi_setup_check_result (struct pci_dev *dev,int type,int ret) +{ +struct msi_desc *entry; +int avail =0 ; + +if (type !=PCI_CAP_ID_MSIX || ret >=0 ) +return ret; + +/* Scan the MSI descriptors for successfully allocated ones. */ +for_each_pci_msi_entry (entry, dev) { +if (entry->irq !=0 ) + avail++; + } +return avail ? avail : ret; +} +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) { -return arch_setup_msi_irqs (dev, nvec, type); +int ret =arch_setup_msi_irqs (dev, nvec, type); + +return pci_msi_setup_check_result (dev, type, ret); }void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev)
drivers/pci/msi/msi.c +1 -18
@@ -609,7 +609,7 @@ static int msix_capability_init(struct p ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret) - goto out_avail; + goto out_free;/* Check if all MSI entries honor device restrictions */ ret =msi_verify_entries (dev);
@@ -634,23 +634,6 @@ static int msix_capability_init(struct ppcibios_free_irq (dev);return 0 ; -out_avail: -if (ret <0 ) { -/* -* If we had some success, report the number of IRQs -* we succeeded in setting up. -*/ -struct msi_desc *entry; -int avail =0 ; - -for_each_pci_msi_entry (entry, dev) { -if (entry->irq !=0 ) - avail++; - } -if (avail !=0 ) - ret = avail; - } - out_free:free_msi_irqs (dev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
PATCH v2 18/23 PCI/MSI: Split out irqdomain code
In reply to Thomas GleixnerMove the irqdomain specific code into it's own file.
--- drivers/pci/msi/Makefile | 1 drivers/pci/msi/irqdomain.c | 279 ++++++++++++++++++++++++++++++++++++++ drivers/pci/msi/legacy.c | 13 + drivers/pci/msi/msi.c | 319 +------------------------------------------- drivers/pci/msi/msi.h | 39 +++++ include/linux/msi.h | 11 - 6 files changed, 340 insertions(+), 322 deletions(-)
drivers/pci/msi/Makefile +1 -0
@@ -3,4 +3,5 @@ # Makefile for the PCI/MSI obj-$(CONFIG_PCI) += pcidev_msi.o obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_IRQ_DOMAIN) += irqdomain.o obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o
drivers/pci/msi/irqdomain.c new file +279 -0
279 lines not on this page · raw message
drivers/pci/msi/legacy.c +11 -2
@@ -4,8 +4,7 @@* * Legacy architecture specific setup and teardown mechanism. */ -#include <linux/msi.h> -#include <linux/pci.h> +#include "msi.h" /* Arch hooks */ int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc)
@@ -50,3 +49,13 @@ void __weak arch_teardown_msi_irqs(struc } } } + +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +return arch_setup_msi_irqs (dev, nvec, type); +} + +void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +arch_teardown_msi_irqs (dev); +}
drivers/pci/msi/msi.c +10 -309
350 lines not on this page · raw message
drivers/pci/msi/msi.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/pci.h> +#include <linux/msi.h> + +#define msix_table_size (flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) + +extern int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_teardown_msi_irqs (struct pci_dev *dev); + +#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS +extern int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev); +#else +static inline int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +WARN_ON_ONCE (1 ); +return -ENODEV ; +} + +static inline void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +WARN_ON_ONCE (1 ); +} +#endif + +/* +* PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to +* mask all MSI interrupts by clearing the MSI enable bit does not work +* reliably as devices without an INTx disable bit will then generate a +* level IRQ which will never be cleared. +*/ +static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) +{ +/* Don't shift by >= width of type */ +if (desc->pci.msi_attrib.multi_cap >=5 ) +return 0xffffffff ; +return (1 << (1 << desc->pci.msi_attrib.multi_cap)) -1 ; +}
include/linux/msi.h +0 -11
@@ -259,17 +259,6 @@ int arch_setup_msi_irq(struct pci_dev *dvoid arch_teardown_msi_irq (unsigned int irq);int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type);void arch_teardown_msi_irqs (struct pci_dev *dev); -#else -static inline int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -WARN_ON_ONCE (1 ); -return -ENODEV ; -} - -static inline void arch_teardown_msi_irqs (struct pci_dev *dev) -{ -WARN_ON_ONCE (1 ); -}#endif /*
PATCH v2 20/23 PCI/MSI: Move msi_lock to struct pci_dev
In reply to Thomas GleixnerIt's only required for PCI/MSI. So no point in having it in every struct device.
---
V2: New patch
--- drivers/base/core.c | 1 - drivers/pci/msi/msi.c | 2 +- drivers/pci/probe.c | 4 +++- include/linux/device.h | 2 -- include/linux/pci.h | 1 + 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/base/core.c +0 -1
@@ -2875,7 +2875,6 @@ void device_initialize(struct device *dedevice_pm_init (dev);set_dev_node (dev,NUMA_NO_NODE );#ifdef CONFIG_GENERIC_MSI_IRQ -raw_spin_lock_init (&dev->msi_lock);INIT_LIST_HEAD (&dev->msi_list);#endif INIT_LIST_HEAD (&dev->links.consumers);
drivers/pci/msi/msi.c +1 -1
@@ -18,7 +18,7 @@ int pci_msi_ignore_mask; static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) { -raw_spinlock_t *lock = &desc->dev->msi_lock; +raw_spinlock_t *lock = &to_pci_dev (desc->dev)->msi_lock;unsigned long flags;if (!desc->pci.msi_attrib.can_mask)
drivers/pci/probe.c +3 -1
@@ -2311,7 +2311,9 @@ struct pci_dev *pci_alloc_dev(struct pciINIT_LIST_HEAD (&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus =pci_bus_get (bus); - +#ifdef CONFIG_PCI_MSI +raw_spin_lock_init (&dev->msi_lock); +#endif return dev; }EXPORT_SYMBOL (pci_alloc_dev);
include/linux/device.h +0 -2
@@ -407,7 +407,6 @@ struct dev_links_info {* @em_pd: device's energy model performance domain * @pins: For device pin management. * See Documentation/driver-api/pin-control.rst for details. -* @msi_lock: Lock to protect MSI mask cache and mask register * @msi_list: Hosts MSI descriptors * @msi_domain: The generic MSI domain this device is using. * @numa_node: NUMA node this device is close to.
@@ -508,7 +507,6 @@ struct device {struct dev_pin_info *pins;#endif #ifdef CONFIG_GENERIC_MSI_IRQ -raw_spinlock_t msi_lock;struct list_head msi_list;#endif #ifdef CONFIG_DMA_OPS
include/linux/pci.h +1 -0
@@ -474,6 +474,7 @@ struct pci_dev {#endif #ifdef CONFIG_PCI_MSI void __iomem *msix_base; +raw_spinlock_t msi_lock;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
Re: [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked
In reply to Thomas GleixnerHello Thomas,
Quoted 14 lines · Thomas Gleixner
This code is broken since day one.
ppc4xx_setup_msi_irqs()has the following gems:1) The handling of the result of
msi_bitmap_alloc_hwirqs()is completely broken:When the result is greater than or equal 0 (bitmap allocation successful) then the loop terminates and the function returns 0 (success) despite not having installed an interrupt.
When the result is less than 0 (bitmap allocation fails), it prints an error message and continues to "work" with that error code which would eventually end up in the MSI message data.
Quoted 7 lines
2) On every invocation the file global
pp4xx_msi::msi_virqsbitmap is allocated thereby leaking the previous one.IOW, this has never worked and for more than 10 years nobody cared. Remove the gunk.
Fixes 3fb7933850fa ("powerpc/4xx: Adding PCIe MSI support")
Shouldn't we remove all of it ? including the updates in the device trees and the Kconfig changes under :
arch/powerpc/platforms/44x/Kconfig: select PPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: select PPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: select PPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: select PPC4xx_MSIarch/powerpc/platforms/40x/Kconfig: select PPC4xx_MSI
Thanks,
C.
Quoted 327 lines
Fixes 247540b03bfc ("powerpc/44x: Fix PCI MSI support for Maui APM821xx SoC and Bluestone board")Signed-off-by Thomas Gleixner <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Cc Michael Ellerman <[email protected]>Cc Paul Mackerras <[email protected]>Cc Benjamin Herrenschmidt <[email protected]>--- arch/powerpc/platforms/4xx/Makefile | 1 arch/powerpc/platforms/4xx/msi.c | 281 ------------------------------------ arch/powerpc/sysdev/Kconfig | 6 3 files changed, 288 deletions(-)arch/powerpc/platforms/4xx/Makefile +0
-1@@ -3,6 +3,5 @@ obj-y += uic.o machine_check.o obj-$(CONFIG_4xx_SOC) += soc.o obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PPC4xx_HSTA_MSI) += hsta_msi.o -obj-$(CONFIG_PPC4xx_MSI) += msi.o obj-$(CONFIG_PPC4xx_CPM) += cpm.o obj-$(CONFIG_PPC4xx_GPIO) += gpio.oarch/powerpc/platforms/4xx/msi.c deleted +0
-281@@ -1,281 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Adding PCI-E MSI support for PPC4XX SoCs. -* -* Copyright (c) 2010, Applied Micro Circuits Corporation -* Authors: Tirumala R Marri <[email protected]> -* Feng Kan <[email protected]> -*/ - -#include <linux/irq.h> -#include <linux/pci.h> -#include <linux/msi.h> -#include <linux/of_platform.h> -#include <linux/interrupt.h> -#include <linux/export.h> -#include <linux/kernel.h> -#include <asm/prom.h> -#include <asm/hw_irq.h> -#include <asm/ppc-pci.h> -#include <asm/dcr.h> -#include <asm/dcr-regs.h> -#include <asm/msi_bitmap.h> - -#define PEIH_TERMADH 0x00 -#define PEIH_TERMADL 0x08 -#define PEIH_MSIED 0x10 -#define PEIH_MSIMK 0x18 -#define PEIH_MSIASS 0x20 -#define PEIH_FLUSH0 0x30 -#define PEIH_FLUSH1 0x38 -#define PEIH_CNTRST 0x48 - -static int msi_irqs; - -struct ppc4xx_msi { -u32 msi_addr_lo; -u32 msi_addr_hi; -void __iomem *msi_regs; -int *msi_virqs; -struct msi_bitmap bitmap; -struct device_node *msi_dev; -}; - -static struct ppc4xx_msi ppc4xx_msi; - -static int ppc4xx_msi_init_allocator (struct platform_device *dev, -struct ppc4xx_msi *msi_data) -{ -int err; - - err =msi_bitmap_alloc (&msi_data->bitmap, msi_irqs, - dev->dev.of_node); -if (err) -return err; - - err =msi_bitmap_reserve_dt_hwirqs (&msi_data->bitmap); -if (err <0 ) { -msi_bitmap_free (&msi_data->bitmap); -return err; - } - -return 0 ; -} - -static int ppc4xx_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -int int_no = -ENOMEM ; -unsigned int virq; -struct msi_msg msg; -struct msi_desc *entry; -struct ppc4xx_msi *msi_data = &ppc4xx_msi; - -dev_dbg (&dev->dev,"PCIE-MSI:%s called. vec %x type %d\n" , - __func__, nvec, type); -if (type ==PCI_CAP_ID_MSIX ) -pr_debug ("ppc4xx msi: MSI-X untested, trying anyway.\n" ); - - msi_data->msi_virqs =kmalloc_array (msi_irqs,sizeof (int ),GFP_KERNEL ); -if (!msi_data->msi_virqs) -return -ENOMEM ; - -for_each_pci_msi_entry (entry, dev) { - int_no =msi_bitmap_alloc_hwirqs (&msi_data->bitmap,1 ); -if (int_no >=0 ) -break ; -if (int_no <0 ) { -pr_debug ("%s: fail allocating msi interrupt\n" , - __func__); - } - virq =irq_of_parse_and_map (msi_data->msi_dev, int_no); -if (!virq) { -dev_err (&dev->dev,"%s: fail mapping irq\n" , __func__); -msi_bitmap_free_hwirqs (&msi_data->bitmap, int_no,1 ); -return -ENOSPC ; - } -dev_dbg (&dev->dev,"%s: virq = %d\n" , __func__, virq); - -/* Setup msi address space */ - msg.address_hi = msi_data->msi_addr_hi; - msg.address_lo = msi_data->msi_addr_lo; - -irq_set_msi_desc (virq, entry); - msg.data = int_no; -pci_write_msi_msg (virq, &msg); - } -return 0 ; -} - -void ppc4xx_teardown_msi_irqs (struct pci_dev *dev) -{ -struct msi_desc *entry; -struct ppc4xx_msi *msi_data = &ppc4xx_msi; -irq_hw_number_t hwirq; - -dev_dbg (&dev->dev,"PCIE-MSI: tearing down msi irqs\n" ); - -for_each_pci_msi_entry (entry, dev) { -if (!entry->irq) -continue ; - hwirq =virq_to_hw (entry->irq); -irq_set_msi_desc (entry->irq,NULL ); -irq_dispose_mapping (entry->irq); -msi_bitmap_free_hwirqs (&msi_data->bitmap, hwirq,1 ); - } -} - -static int ppc4xx_setup_pcieh_hw (struct platform_device *dev, -struct resource res,struct ppc4xx_msi *msi) -{ -const u32 *msi_data; -const u32 *msi_mask; -const u32 *sdr_addr; -dma_addr_t msi_phys; -void *msi_virt; -int err; - - sdr_addr =of_get_property (dev->dev.of_node,"sdr-base" ,NULL ); -if (!sdr_addr) -return -EINVAL ; - - msi_data =of_get_property (dev->dev.of_node,"msi-data" ,NULL ); -if (!msi_data) -return -EINVAL ; - - msi_mask =of_get_property (dev->dev.of_node,"msi-mask" ,NULL ); -if (!msi_mask) -return -EINVAL ; - - msi->msi_dev =of_find_node_by_name (NULL ,"ppc4xx-msi" ); -if (!msi->msi_dev) -return -ENODEV ; - - msi->msi_regs =of_iomap (msi->msi_dev,0 ); -if (!msi->msi_regs) { -dev_err (&dev->dev,"of_iomap failed\n" ); - err = -ENOMEM ; - goto node_put; - } -dev_dbg (&dev->dev,"PCIE-MSI: msi register mapped 0x%x 0x%x\n" , - (u32) (msi->msi_regs +PEIH_TERMADH ), (u32) (msi->msi_regs)); - - msi_virt =dma_alloc_coherent (&dev->dev,64 , &msi_phys,GFP_KERNEL ); -if (!msi_virt) { - err = -ENOMEM ; - goto iounmap; - } - msi->msi_addr_hi =upper_32_bits (msi_phys); - msi->msi_addr_lo =lower_32_bits (msi_phys &0xffffffff ); -dev_dbg (&dev->dev,"PCIE-MSI: msi address high 0x%x, low 0x%x\n" , - msi->msi_addr_hi, msi->msi_addr_lo); - -mtdcri (SDR0 , *sdr_addr,upper_32_bits (res.start));/*HIGH addr */ -mtdcri (SDR0 , *sdr_addr +1 ,lower_32_bits (res.start));/* Low addr */ - -/* Progam the Interrupt handler Termination addr registers */ -out_be32 (msi->msi_regs +PEIH_TERMADH , msi->msi_addr_hi); -out_be32 (msi->msi_regs +PEIH_TERMADL , msi->msi_addr_lo); - -/* Program MSI Expected data and Mask bits */ -out_be32 (msi->msi_regs +PEIH_MSIED , *msi_data); -out_be32 (msi->msi_regs +PEIH_MSIMK , *msi_mask); - -dma_free_coherent (&dev->dev,64 , msi_virt, msi_phys); - -return 0 ; - -iounmap: -iounmap (msi->msi_regs); -node_put: -of_node_put (msi->msi_dev); -return err; -} - -static int ppc4xx_of_msi_remove (struct platform_device *dev) -{ -struct ppc4xx_msi *msi = dev->dev.platform_data; -int i; -int virq; - -for (i =0 ; i < msi_irqs; i++) { - virq = msi->msi_virqs[i]; -if (virq) -irq_dispose_mapping (virq); - } - -if (msi->bitmap.bitmap) -msi_bitmap_free (&msi->bitmap); -iounmap (msi->msi_regs); -of_node_put (msi->msi_dev); - -return 0 ; -} - -static int ppc4xx_msi_probe (struct platform_device *dev) -{ -struct ppc4xx_msi *msi; -struct resource res; -int err =0 ; -struct pci_controller *phb; - -dev_dbg (&dev->dev,"PCIE-MSI: Setting up MSI support...\n" ); - - msi =devm_kzalloc (&dev->dev,sizeof (*msi),GFP_KERNEL ); -if (!msi) -return -ENOMEM ; - dev->dev.platform_data = msi; - -/* Get MSI ranges */ - err =of_address_to_resource (dev->dev.of_node,0 , &res); -if (err) { -dev_err (&dev->dev,"%pOF resource error!\n" , dev->dev.of_node); -return err; - } - - msi_irqs =of_irq_count (dev->dev.of_node); -if (!msi_irqs) -return -ENODEV ; - - err =ppc4xx_setup_pcieh_hw (dev, res, msi); -if (err) -return err; - - err =ppc4xx_msi_init_allocator (dev, msi); -if (err) { -dev_err (&dev->dev,"Error allocating MSI bitmap\n" ); - goto error_out; - } - ppc4xx_msi = *msi; - -list_for_each_entry (phb, &hose_list, list_node) { - phb->controller_ops.setup_msi_irqs = ppc4xx_setup_msi_irqs; - phb->controller_ops.teardown_msi_irqs = ppc4xx_teardown_msi_irqs; - } -return 0 ; - -error_out: -ppc4xx_of_msi_remove (dev); -return err; -} -static const struct of_device_id ppc4xx_msi_ids[] = { - { - .compatible ="amcc,ppc4xx-msi" , - }, - {} -}; -static struct platform_driver ppc4xx_msi_driver = { - .probe = ppc4xx_msi_probe, - .remove = ppc4xx_of_msi_remove, - .driver = { - .name ="ppc4xx-msi" , - .of_match_table = ppc4xx_msi_ids, - }, - -}; - -static __init int ppc4xx_msi_init (void ) -{ -return platform_driver_register (&ppc4xx_msi_driver); -} - -subsys_initcall (ppc4xx_msi_init);arch/powerpc/sysdev/Kconfig +0
-6@@ -12,17 +12,11 @@ config PPC4xx_HSTA_MSI depends on PCI_MSI depends on PCI && 4xx -config PPC4xx_MSI - bool - depends on PCI_MSI - depends on PCI && 4xx - config PPC_MSI_BITMAP bool depends on PCI_MSI default y if MPIC default y if FSL_PCI - default y if PPC4xx_MSI default y if PPC_POWERNV source "arch/powerpc/sysdev/xics/Kconfig"
Re: [patch V2 03/23] genirq/msi: Guard sysfs code
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
No point in building unused code when
CONFIG_SYSFS=n.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 05/23] genirq/msi: Fixup includes
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
Remove the
kobject.hinclude frommsi.has it's not required and add asysfs.hinclude to the core code instead.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 08/23] PCI/sysfs: Use pci_irq_vector()
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
instead of fiddling with msi descriptors.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 10/23] genirq/msi, treewide: Use a named struct for PCI/MSI attributes
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
The unnamed struct sucks and is in the way of further cleanups. Stick the PCI related MSI data into a real data structure and cleanup all users.
No functional change.
Quoted 9 lines
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Acked-by Kalle Valo <[email protected]>Cc Greg Kroah-Hartman <[email protected]>
Re: [patch V2 14/23] PCI/MSI: Make msix_update_entries() smarter
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
No need to walk the descriptors and check for each one whether the entries pointer function argument is NULL. Do it once.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 16/23] PCI/MSI: Split out CONFIG_PCI_MSI independent part
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
These functions are required even when
CONFIG_PCI_MSIis not set. Move them to their own file.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 17/23] PCI/MSI: Split out !IRQDOMAIN code
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Split out the non irqdomain code into its own file.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 18/23] PCI/MSI: Split out irqdomain code
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Move the irqdomain specific code into it's own file.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 20/23] PCI/MSI: Move msi_lock to struct pci_dev
In reply to Thomas GleixnerQuoted 4 lines · Thomas Gleixner
It's only required for PCI/MSI. So no point in having it in every struct device.
Signed-off-by Thomas Gleixner <[email protected]>
Yes!!!
Re: [patch V2 21/23] PCI/MSI: Make pci_msi_domain_check_cap() static
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
No users outside of that file.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 22/23] genirq/msi: Handle PCI/MSI allocation fail in core code
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
Get rid of yet another irqdomain callback and let the core code return the already available information of how many descriptors could be allocated.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Re: [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
The irqdomain code already returns the information. Move the loop to the legacy code.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Michael Ellerman
reviewerRe: [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked
In reply to Cédric Le GoaterQuoted 25 lines · Cédric Le Goater
Hello Thomas,
Quoted 14 lines · Thomas Gleixner
This code is broken since day one.
ppc4xx_setup_msi_irqs()has the following gems:1) The handling of the result of
msi_bitmap_alloc_hwirqs()is completely broken:When the result is greater than or equal 0 (bitmap allocation successful) then the loop terminates and the function returns 0 (success) despite not having installed an interrupt.
When the result is less than 0 (bitmap allocation fails), it prints an error message and continues to "work" with that error code which would eventually end up in the MSI message data.
Quoted 7 lines
2) On every invocation the file global
pp4xx_msi::msi_virqsbitmap is allocated thereby leaking the previous one.IOW, this has never worked and for more than 10 years nobody cared. Remove the gunk.
Fixes 3fb7933850fa ("powerpc/4xx: Adding PCIe MSI support")
Quoted 8 lines
Shouldn't we remove all of it ? including the updates in the device trees and the
Kconfigchanges under :
arch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/40x/Kconfig: selectPPC4xx_MSI
This patch should drop those selects I guess. Can you send an incremental diff for Thomas to squash in?
Removing all the tendrils in various device tree files will probably require some archaeology, and it should be perfectly safe to leave those in the tree with the driver gone. So I think we can do that as a subsequent patch, rather than in this series.
cheers
Re: [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked
Quoted 29 lines · Michael Ellerman
Quoted 28 lines · Cédric Le Goater
Hello Thomas,
Quoted 14 lines · Thomas Gleixner
This code is broken since day one.
ppc4xx_setup_msi_irqs()has the following gems:1) The handling of the result of
msi_bitmap_alloc_hwirqs()is completely broken:When the result is greater than or equal 0 (bitmap allocation successful) then the loop terminates and the function returns 0 (success) despite not having installed an interrupt.
When the result is less than 0 (bitmap allocation fails), it prints an error message and continues to "work" with that error code which would eventually end up in the MSI message data.
Quoted 7 lines
2) On every invocation the file global
pp4xx_msi::msi_virqsbitmap is allocated thereby leaking the previous one.IOW, this has never worked and for more than 10 years nobody cared. Remove the gunk.
Fixes 3fb7933850fa ("powerpc/4xx: Adding PCIe MSI support")Shouldn't we remove all of it ? including the updates in the device trees and the
Kconfigchanges under :
Quoted 8 lines
Quoted 5 lines
arch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/44x/Kconfig: selectPPC4xx_MSIarch/powerpc/platforms/40x/Kconfig: selectPPC4xx_MSIThis patch should drop those selects I guess. Can you send an incremental diff for Thomas to squash in?
Sure.
Quoted 4 lines
Removing all the tendrils in various device tree files will probably require some archaeology, and it should be perfectly safe to leave those in the tree with the driver gone. So I think we can do that as a subsequent patch, rather than in this series.
Here are the changes. Compiled tested with ppc40x and ppc44x defconfigs.
Thanks,
C.
arch/powerpc/boot/dts/bluestone.dts +0 -25
@@ -366,30 +366,5 @@ PCIE0: pcie@d00000000 { 0x0 0x0 0x0 0x3 &UIC3 0xe 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC3 0xf 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0xC 0x10000000 0x100 - 0xC 0x10000000 0x100>; - sdr-base = <0x36C>; - msi-data = <0x00004440>; - msi-mask = <0x0000ffe0>; - interrupts =<0 1 2 3 4 5 6 7>; - interrupt-parent = <&MSI>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - msi-available-ranges = <0x0 0x100>; - interrupt-map = < - 0 &UIC3 0x18 1 - 1 &UIC3 0x19 1 - 2 &UIC3 0x1A 1 - 3 &UIC3 0x1B 1 - 4 &UIC3 0x1C 1 - 5 &UIC3 0x1D 1 - 6 &UIC3 0x1E 1 - 7 &UIC3 0x1F 1 - >; - }; }; };
arch/powerpc/boot/dts/canyonlands.dts +0 -18
@@ -544,23 +544,5 @@ PCIE1: pcie@d20000000 { 0x0 0x0 0x0 0x3 &UIC3 0x12 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC3 0x13 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0xC 0x10000000 0x100>; - sdr-base = <0x36C>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts = <0 1 2 3>; - interrupt-parent = <&UIC3>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC3 0x18 1 - 1 &UIC3 0x19 1 - 2 &UIC3 0x1A 1 - 3 &UIC3 0x1B 1>; - }; }; };
arch/powerpc/boot/dts/katmai.dts +0 -18
@@ -442,24 +442,6 @@ PCIE2: pcie@d40000000 { 0x0 0x0 0x0 0x4 &UIC3 0xb 0x4 /* swizzled int D */>; }; - MSI: ppc4xx-msi@400300000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0x4 0x00300000 0x100>; - sdr-base = <0x3B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts =<0 1 2 3>; - interrupt-parent = <&UIC0>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC0 0xC 1 - 1 &UIC0 0x0D 1 - 2 &UIC0 0x0E 1 - 3 &UIC0 0x0F 1>; - }; - I2O: i2o@400100000 { compatible = "ibm,i2o-440spe"; reg = <0x00000004 0x00100000 0x100>;
arch/powerpc/boot/dts/kilauea.dts +0 -28
@@ -403,33 +403,5 @@ PCIE1: pcie@c0000000 { 0x0 0x0 0x0 0x3 &UIC2 0xd 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC2 0xe 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = <0xEF620000 0x100>; - sdr-base = <0x4B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <12>; - interrupts = <0 1 2 3 4 5 6 7 8 9 0xA 0xB 0xC 0xD>; - interrupt-parent = <&UIC2>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC2 0x10 1 - 1 &UIC2 0x11 1 - 2 &UIC2 0x12 1 - 2 &UIC2 0x13 1 - 2 &UIC2 0x14 1 - 2 &UIC2 0x15 1 - 2 &UIC2 0x16 1 - 2 &UIC2 0x17 1 - 2 &UIC2 0x18 1 - 2 &UIC2 0x19 1 - 2 &UIC2 0x1A 1 - 2 &UIC2 0x1B 1 - 2 &UIC2 0x1C 1 - 3 &UIC2 0x1D 1>; - }; }; };
arch/powerpc/boot/dts/redwood.dts +0 -19
@@ -358,25 +358,6 @@ PCIE2: pcie@d40000000 { 0x0 0x0 0x0 0x4 &UIC3 0xb 0x4 /* swizzled int D */>; }; - MSI: ppc4xx-msi@400300000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0x4 0x00300000 0x100 - 0x4 0x00300000 0x100>; - sdr-base = <0x3B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts =<0 1 2 3>; - interrupt-parent = <&UIC0>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC0 0xC 1 - 1 &UIC0 0x0D 1 - 2 &UIC0 0x0E 1 - 3 &UIC0 0x0F 1>; - }; - };
arch/powerpc/platforms/40x/Kconfig +0 -1
@@ -23,7 +23,6 @@ config KILAUEA select PPC4xx_PCI_EXPRESS select FORCE_PCI select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC405EX evaluation board.
arch/powerpc/platforms/44x/Kconfig +0 -4
@@ -23,7 +23,6 @@ config BLUESTONE select APM821xx select FORCE_PCI select PCI_MSI - select PPC4xx_MSI select PPC4xx_PCI_EXPRESS select IBM_EMAC_RGMII if IBM_EMAC help
@@ -73,7 +72,6 @@ config KATMAI select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC440SPe evaluation board.
@@ -115,7 +113,6 @@ config CANYONLANDS select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI select IBM_EMAC_RGMII if IBM_EMAC select IBM_EMAC_ZMII if IBM_EMAC help
@@ -141,7 +138,6 @@ config REDWOOD select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC460SX Redwood board.
Signature · 8 lines
2.31.1 -- ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked
Cedric,
Quoted 5 lines · Cédric Le Goater
Quoted 3 lines · Michael Ellerman
This patch should drop those selects I guess. Can you send an incremental diff for Thomas to squash in?
Quoted 8 lines
Sure.
Quoted 4 lines
Removing all the tendrils in various device tree files will probably require some archaeology, and it should be perfectly safe to leave those in the tree with the driver gone. So I think we can do that as a subsequent patch, rather than in this series.
Here are the changes. Compiled tested with ppc40x and ppc44x defconfigs.
< Lots of patch skipped />
arch/powerpc/platforms/44x/Kconfig config REDWOOD · line 142
Quoted 7 lines
arch/powerpc/platforms/44x/Kconfig +0
-1@@ -141,7 +138,6 @@ config REDWOOD select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC460SX Redwood board.
While that is incremental it certainly is worth a patch on it's own. Could you add a proper changelog and an SOB please?
Thanks,
tglx
Re: [patch V2 02/23] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
In reply to Thomas GleixnerQuoted 14 lines · Thomas Gleixner
pci_irq_vector()andpci_irq_get_affinity()use the list position to find the MSI-X descriptor at a given index. That's correct for the normal case where the entry number is the same as the list position.But it's wrong for cases where MSI-X was allocated with an entries array describing sparse entry numbers into the hardware message descriptor table. That's inconsistent at best.
Make it always check the entry number because that's what the zero base index really means. This change won't break existing users which use a sparse entries array for allocation because these users retrieve the Linux interrupt number from the entries array after allocation and none of them uses
pci_irq_vector()orpci_irq_get_affinity().
Quoted 4 lines
Fixes aff171641d18 ("PCI: Provide sensible IRQ vector alloc/free routines")Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 65 lines
---
V2: Fix typo in subject - Jason--- drivers/pci/msi.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)drivers/pci/msi.c +18
-8@@ -1187,19 +1187,24 @@ EXPORT_SYMBOL(pci_free_irq_vectors);/** * pci_irq_vector - return Linux IRQ number of a device vector -* @dev: PCI device to operate on -* @nr: device-relative interrupt vector index (0-based). +* @dev: PCI device to operate on +* @nr: Interrupt vector index (0-based) +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: The Linux interrupt number or -EINVAl if @nr is out of range. */ int pci_irq_vector (struct pci_dev *dev,unsigned int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return entry->irq; - i++; }WARN_ON_ONCE (1 );return -EINVAL ;@@ -1223,17 +1228,22 @@ EXPORT_SYMBOL(pci_irq_vector);* pci_irq_get_affinity - return the affinity of a particular MSI vector * @dev: PCI device to operate on * @nr: device-relative interrupt vector index (0-based). +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: A cpumask pointer or NULL if @nr is out of range */ const struct cpumask *pci_irq_get_affinity (struct pci_dev *dev,int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return &entry->affinity->mask; - i++; }WARN_ON_ONCE (1 );return NULL ;
Re: [patch V2 06/23] PCI/MSI: Make pci_msi_domain_write_msg() static
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
There is no point to have this function public as it is set by the PCI core anyway when a PCI/MSI irqdomain is created.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 60 lines
--- drivers/irqchip/irq-gic-v2m.c | 1 - drivers/irqchip/irq-gic-v3-its-pci-msi.c | 1 - drivers/irqchip/irq-gic-v3-mbi.c | 1 - drivers/pci/msi.c | 2 +- include/linux/msi.h | 1 - 5 files changed, 1 insertion(+), 5 deletions(-)drivers/irqchip/irq-gic-v2m.c +0
-1@@ -88,7 +88,6 @@ static struct irq_chip gicv2m_msi_irq_ch .irq_mask = gicv2m_mask_msi_irq, .irq_unmask = gicv2m_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info gicv2m_msi_domain_info = {drivers/irqchip/irq-gic-v3-its-pci-msi.c +0
-1@@ -28,7 +28,6 @@ static struct irq_chip its_msi_irq_chip .irq_unmask = its_unmask_msi_irq, .irq_mask = its_mask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static int its_pci_msi_vec_count (struct pci_dev *pdev,void *data)drivers/irqchip/irq-gic-v3-mbi.c +0
-1@@ -171,7 +171,6 @@ static struct irq_chip mbi_msi_irq_chip .irq_unmask = mbi_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, .irq_compose_msi_msg = mbi_compose_msi_msg, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info mbi_msi_domain_info = {drivers/pci/msi.c +1
-1@@ -1281,7 +1281,7 @@ EXPORT_SYMBOL_GPL(msi_desc_to_pci_sysdat* @irq_data: Pointer to interrupt data of the MSI interrupt * @msg: Pointer to the message */ -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) +static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) {struct msi_desc *desc =irq_data_get_msi_desc (irq_data);include/linux/msi.h +0
-1@@ -455,7 +455,6 @@ void *platform_msi_get_host_data(struct#endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */ #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg);struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent);
Re: [patch V2 07/23] PCI/MSI: Remove msi_desc_to_pci_sysdata()
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Last user is gone long ago.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 39 lines
--- drivers/pci/msi.c | 8 -------- include/linux/msi.h | 5 ----- 2 files changed, 13 deletions(-)drivers/pci/msi.c +0
-8@@ -1267,14 +1267,6 @@ struct pci_dev *msi_desc_to_pci_dev(stru }EXPORT_SYMBOL (msi_desc_to_pci_dev); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (desc); - -return dev->bus->sysdata; -} -EXPORT_SYMBOL_GPL (msi_desc_to_pci_sysdata); -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN /** * pci_msi_domain_write_msg - Helper to write MSI message to PCI config space include/linux/msi.h +0
-5@@ -218,13 +218,8 @@ static inline void msi_desc_set_iommu_cofor_each_msi_entry ((desc), &(pdev)->dev) struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc);void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg);#else /* CONFIG_PCI_MSI */ -static inline void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -return NULL ; -}static inline void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg) { }
Re: [patch V2 08/23] PCI/sysfs: Use pci_irq_vector()
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
instead of fiddling with msi descriptors.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
s/msi/MSI/ above if you have a chance. Nice cleanup, thanks!
Quoted 21 lines
--- drivers/pci/pci-sysfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/pci/pci-sysfs.c +2
-5@@ -62,11 +62,8 @@ static ssize_t irq_show(struct device *d* For MSI, show the first MSI IRQ; for all other cases including * MSI-X, show the legacy INTx IRQ. */ -if (pdev->msi_enabled) { -struct msi_desc *desc =first_pci_msi_entry (pdev); - -return sysfs_emit (buf,"%u\n" , desc->irq); - } +if (pdev->msi_enabled) +return sysfs_emit (buf,"%u\n" ,pci_irq_vector (pdev,0 ));#endif return sysfs_emit (buf,"%u\n" , pdev->irq);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 12/23] PCI/MSI: Make arch_restore_msi_irqs() less horrible.
In reply to Thomas GleixnerQuoted 11 lines · Thomas Gleixner
Make
arch_restore_msi_irqs()return a boolean which indicates whether the core code should restore the MSI message or not. Get rid of the indirection in x86.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Heiko Carstens <[email protected]>
Quoted 265 lines
--- arch/s390/pci/pci_irq.c | 4 +- arch/x86/include/asm/x86_init.h | 6 --- arch/x86/include/asm/xen/hypervisor.h | 8 +++++ arch/x86/kernel/apic/msi.c | 6 +++ arch/x86/kernel/x86_init.c | 12 ------- arch/x86/pci/xen.c | 13 ++++---- drivers/pci/msi.c | 54 +++++++++++----------------------- include/linux/msi.h | 7 +--- 8 files changed, 45 insertions(+), 65 deletions(-)arch/s390/pci/pci_irq.c +2
-2@@ -387,13 +387,13 @@ void arch_teardown_msi_irqs(struct pci_dairq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, zdev->msi_nr_irqs); } -void arch_restore_msi_irqs (struct pci_dev *pdev) +bool arch_restore_msi_irqs (struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev);if (!zdev->irqs_registered)zpci_set_irq (zdev); -default_restore_msi_irqs (pdev); +return true; }static struct airq_struct zpci_airq = {arch/x86/include/asm/x86_init.h +0
-6@@ -289,12 +289,6 @@ struct x86_platform_ops {struct x86_hyper_runtime hyper; }; -struct pci_dev ; - -struct x86_msi_ops { -void (*restore_msi_irqs)(struct pci_dev *dev); -}; -struct x86_apic_ops {unsigned int (*io_apic_read) (unsigned int apic,unsigned int reg);void (*restore)(void );arch/x86/include/asm/xen/hypervisor.h +8
-0@@ -57,6 +57,14 @@ static inline bool __init xen_x2apic_par }#endif +struct pci_dev ; + +#ifdef CONFIG_XEN_DOM0 +bool xen_initdom_restore_msi (struct pci_dev *dev); +#else +static inline bool xen_initdom_restore_msi (struct pci_dev *dev) {return true; } +#endif +#ifdef CONFIG_HOTPLUG_CPU void xen_arch_register_cpu (int num);void xen_arch_unregister_cpu (int num);arch/x86/kernel/apic/msi.c +6
-0@@ -19,6 +19,7 @@#include <asm/hw_irq.h> #include <asm/apic.h> #include <asm/irq_remapping.h> +#include <asm/xen/hypervisor.h> struct irq_domain *x86_pci_msi_default_domain__ro_after_init ;@@ -345,3 +346,8 @@ void dmar_free_hwirq(int irq) irq_domain_free_irqs(irq, 1); }#endif + +bool arch_restore_msi_irqs (struct pci_dev *dev) +{ +return xen_initdom_restore_msi (dev); +}arch/x86/kernel/x86_init.c +0
-12@@ -145,18 +145,6 @@ struct x86_platform_ops x86_platform __rEXPORT_SYMBOL_GPL (x86_platform); -#if defined(CONFIG_PCI_MSI ) -struct x86_msi_ops x86_msi__ro_after_init = { - .restore_msi_irqs = default_restore_msi_irqs, -}; - -/* MSI arch specific hooks */ -void arch_restore_msi_irqs (struct pci_dev *dev) -{ - x86_msi.restore_msi_irqs (dev); -} -#endif -struct x86_apic_ops x86_apic_ops__ro_after_init = { .io_apic_read = native_io_apic_read, .restore = native_restore_boot_irq_mode,arch/x86/pci/xen.c +7
-6@@ -351,10 +351,13 @@ static int xen_initdom_setup_msi_irqs(streturn ret; } -static void xen_initdom_restore_msi_irqs (struct pci_dev *dev) +bool xen_initdom_restore_msi (struct pci_dev *dev) {int ret =0 ; +if (!xen_initial_domain ()) +return true; +if (pci_seg_supported) {struct physdev_pci_device restore_ext;@@ -375,10 +378,10 @@ static void xen_initdom_restore_msi_irqs ret =HYPERVISOR_physdev_op (PHYSDEVOP_restore_msi, &restore); WARN(ret && ret != -ENOSYS, "restore_msi -> %d\n", ret); } +return false; }#else /* CONFIG_XEN_PV_DOM0 */ #define xen_initdom_setup_msi_irqs NULL -#define xen_initdom_restore_msi_irqs NULL#endif /* !CONFIG_XEN_PV_DOM0 */ static void xen_teardown_msi_irqs (struct pci_dev *dev)@@ -466,12 +469,10 @@ static __init struct irq_domain *xen_crestatic __init void xen_setup_pci_msi (void ) {if (xen_pv_domain ()) { -if (xen_initial_domain ()) { +if (xen_initial_domain ()) xen_msi_ops.setup_msi_irqs = xen_initdom_setup_msi_irqs; - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs; - }else { +else xen_msi_ops.setup_msi_irqs = xen_setup_msi_irqs; - } xen_msi_ops.teardown_msi_irqs = xen_pv_teardown_msi_irqs; pci_msi_ignore_mask =1 ; }else if (xen_hvm_domain ()) {drivers/pci/msi.c +19
-35@@ -106,29 +106,6 @@ void __weak arch_teardown_msi_irqs(struc }#endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */ -static void default_restore_msi_irq (struct pci_dev *dev,int irq) -{ -struct msi_desc *entry; - - entry =NULL ; -if (dev->msix_enabled) { -for_each_pci_msi_entry (entry, dev) { -if (irq == entry->irq) -break ; - } - }else if (dev->msi_enabled) { - entry =irq_get_msi_desc (irq); - } - -if (entry) -__pci_write_msi_msg (entry, &entry->msg); -} - -void __weak arch_restore_msi_irqs (struct pci_dev *dev) -{ -return default_restore_msi_irqs (dev); -} -/* * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to * mask all MSI interrupts by clearing the MSI enable bit does not work @@ -242,14 +219,6 @@ void pci_msi_unmask_irq(struct irq_data }EXPORT_SYMBOL_GPL (pci_msi_unmask_irq); -void default_restore_msi_irqs (struct pci_dev *dev) -{ -struct msi_desc *entry; - -for_each_pci_msi_entry (entry, dev) -default_restore_msi_irq (dev, entry->irq); -} -void __pci_read_msi_msg (struct msi_desc *entry,struct msi_msg *msg) {struct pci_dev *dev =msi_desc_to_pci_dev (entry);@@ -403,10 +372,19 @@ static void pci_msi_set_enable(struct pcpci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , control); } +/* +* Architecture override returns true when the PCI MSI message should be +* written by the generic restore function. +*/ +bool __weak arch_restore_msi_irqs (struct pci_dev *dev) +{ +return true; +} +static void __pci_restore_msi_state (struct pci_dev *dev) { -u16 control;struct msi_desc *entry; +u16 control;if (!dev->msi_enabled)return ;@@ -415,7 +393,8 @@ static void __pci_restore_msi_state(strupci_intx_for_msi (dev,0 );pci_msi_set_enable (dev,0 ); -arch_restore_msi_irqs (dev); +if (arch_restore_msi_irqs (dev)) +__pci_write_msi_msg (entry, &entry->msg);pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &control);pci_msi_update_mask (entry,0 ,0 );@@ -437,6 +416,7 @@ static void pci_msix_clear_and_set_ctrl(static void __pci_restore_msix_state (struct pci_dev *dev) {struct msi_desc *entry; +bool write_msg;if (!dev->msix_enabled)return ;@@ -447,9 +427,13 @@ static void __pci_restore_msix_state(strpci_msix_clear_and_set_ctrl (dev,0 ,PCI_MSIX_FLAGS_ENABLE |PCI_MSIX_FLAGS_MASKALL ); -arch_restore_msi_irqs (dev); -for_each_pci_msi_entry (entry, dev) + write_msg =arch_restore_msi_irqs (dev); + +for_each_pci_msi_entry (entry, dev) { +if (write_msg) +__pci_write_msi_msg (entry, &entry->msg);pci_msix_write_vector_ctrl (entry, entry->pci.msix_ctrl); + }pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_MASKALL ,0 ); }include/linux/msi.h +3
-4@@ -273,11 +273,10 @@ static inline void arch_teardown_msi_irq#endif /* -* The restore hooks are still available as they are useful even -* for fully irq domain based setups. Courtesy to XEN/X86. +* The restore hook is still available even for fully irq domain based +* setups. Courtesy to XEN/X86. */ -void arch_restore_msi_irqs (struct pci_dev *dev); -void default_restore_msi_irqs (struct pci_dev *dev); +bool arch_restore_msi_irqs (struct pci_dev *dev);#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 13/23] PCI/MSI: Cleanup include zoo
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Get rid of the pile of unneeded includes which accumulated over time.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Nice, thanks!
Quoted 36 lines
---
V2: Address build fail on powerpc - Cedric--- drivers/pci/msi.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)drivers/pci/msi.c +4
-12@@ -7,22 +7,14 @@* Copyright (C) 2016 Christoph Hellwig. */ +#include <linux/acpi_iort.h> #include <linux/err.h> -#include <linux/mm.h> -#include <linux/irq.h> -#include <linux/interrupt.h> #include <linux/export.h> -#include <linux/ioport.h> -#include <linux/pci.h> -#include <linux/proc_fs.h> -#include <linux/msi.h> -#include <linux/smp.h> -#include <linux/errno.h> -#include <linux/io.h> -#include <linux/acpi_iort.h> -#include <linux/slab.h> +#include <linux/irq.h> #include <linux/irqdomain.h> +#include <linux/msi.h> #include <linux/of_irq.h> +#include <linux/pci.h> #include "pci.h"
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 14/23] PCI/MSI: Make msix_update_entries() smarter
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
No need to walk the descriptors and check for each one whether the entries pointer function argument is NULL. Do it once.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 18 lines
--- drivers/pci/msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/msi.c +2
-2@@ -642,8 +642,8 @@ static void msix_update_entries(struct p {struct msi_desc *entry; -for_each_pci_msi_entry (entry, dev) { -if (entries) { +if (entries) { +for_each_pci_msi_entry (entry, dev) { entries->vector = entry->irq; entries++; }
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 15/23] PCI/MSI: Move code into a separate directory
In reply to Thomas GleixnerQuoted 2 lines · Thomas Gleixner
msi.cis getting larger and really could do with a splitup. Move it into it's own directory to prepare for that.
s/it's/its/
Quoted 3 lines
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 3,110 lines
--- Documentation/driver-api/pci/pci.rst | 2 drivers/pci/Makefile | 3 drivers/pci/msi.c | 1532 ----------------------------------- drivers/pci/msi/Makefile | 4 drivers/pci/msi/msi.c | 1532 +++++++++++++++++++++++++++++++++++ 5 files changed, 1539 insertions(+), 1534 deletions(-)Documentation/driver-api/pci/pci.rst +1
-1@@ -13,7 +13,7 @@ PCI Support Library .. kernel-doc:: drivers/pci/search.c :export: -.. kernel-doc:: drivers/pci/msi.c +.. kernel-doc:: drivers/pci/msi/msi.c :export: .. kernel-doc:: drivers/pci/bus.cdrivers/pci/Makefile +2
-1@@ -5,8 +5,9 @@ obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \ remove.o pci.o pci-driver.o search.o \ pci-sysfs.o rom.o setup-res.o irq.o vpd.o \ - setup-bus.o vc.o mmap.o setup-irq.o msi.o + setup-bus.o vc.o mmap.o setup-irq.o +obj-$(CONFIG_PCI) += msi/ obj-$(CONFIG_PCI) += pcie/ ifdef CONFIG_PCIdrivers/pci/msi.c deleted +0
-1532@@ -1,1532 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* PCI Message Signaled Interrupt (MSI) -* -* Copyright (C) 2003-2004 Intel -* Copyright (C) Tom Long Nguyen ([email protected]) -* Copyright (C) 2016 Christoph Hellwig. -*/ - -#include <linux/acpi_iort.h> -#include <linux/err.h> -#include <linux/export.h> -#include <linux/irq.h> -#include <linux/irqdomain.h> -#include <linux/msi.h> -#include <linux/of_irq.h> -#include <linux/pci.h> - -#include "pci.h" - -#ifdef CONFIG_PCI_MSI - -static int pci_msi_enable =1 ; -int pci_msi_ignore_mask; - -#define msix_table_size (flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) - -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -static int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct irq_domain *domain; - - domain =dev_get_msi_domain (&dev->dev); -if (domain &&irq_domain_is_hierarchy (domain)) -return msi_domain_alloc_irqs (domain, &dev->dev, nvec); - -return arch_setup_msi_irqs (dev, nvec, type); -} - -static void pci_msi_teardown_msi_irqs (struct pci_dev *dev) -{ -struct irq_domain *domain; - - domain =dev_get_msi_domain (&dev->dev); -if (domain &&irq_domain_is_hierarchy (domain)) -msi_domain_free_irqs (domain, &dev->dev); -else -arch_teardown_msi_irqs (dev); -} -#else -#define pci_msi_setup_msi_irqs arch_setup_msi_irqs -#define pci_msi_teardown_msi_irqs arch_teardown_msi_irqs -#endif - -#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS -/* Arch hooks */ -int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc) -{ -return -EINVAL ; -} - -void __weak arch_teardown_msi_irq (unsigned int irq) -{ -} - -int __weak arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct msi_desc *entry; -int ret; - -/* -* If an architecture wants to support multiple MSI, it needs to -* override arch_setup_msi_irqs() -*/ -if (type ==PCI_CAP_ID_MSI && nvec >1 ) -return 1 ; - -for_each_pci_msi_entry (entry, dev) { - ret =arch_setup_msi_irq (dev, entry); -if (ret <0 ) -return ret; -if (ret >0 ) -return -ENOSPC ; - } - -return 0 ; -} - -void __weak arch_teardown_msi_irqs (struct pci_dev *dev) -{ -int i; -struct msi_desc *entry; - -for_each_pci_msi_entry (entry, dev) -if (entry->irq) -for (i =0 ; i < entry->nvec_used; i++) -arch_teardown_msi_irq (entry->irq + i); -} -#endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */ - -/* -* PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to -* mask all MSI interrupts by clearing the MSI enable bit does not work -* reliably as devices without an INTx disable bit will then generate a -* level IRQ which will never be cleared. -*/ -static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) -{ -/* Don't shift by >= width of type */ -if (desc->pci.msi_attrib.multi_cap >=5 ) -return 0xffffffff ; -return (1 << (1 << desc->pci.msi_attrib.multi_cap)) -1 ; -} - -static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) -{ -raw_spinlock_t *lock = &desc->dev->msi_lock; -unsigned long flags; - -if (!desc->pci.msi_attrib.can_mask) -return ; - -raw_spin_lock_irqsave (lock, flags); - desc->pci.msi_mask &= ~clear; - desc->pci.msi_mask |= set; -pci_write_config_dword (msi_desc_to_pci_dev (desc), desc->pci.mask_pos, - desc->pci.msi_mask); -raw_spin_unlock_irqrestore (lock, flags); -} - -static inline void pci_msi_mask (struct msi_desc *desc,u32 mask) -{ -pci_msi_update_mask (desc,0 , mask); -} - -static inline void pci_msi_unmask (struct msi_desc *desc,u32 mask) -{ -pci_msi_update_mask (desc, mask,0 ); -} - -static inline void __iomem *pci_msix_desc_addr (struct msi_desc *desc) -{ -return desc->pci.mask_base + desc->pci.msi_attrib.entry_nr *PCI_MSIX_ENTRY_SIZE ; -} - -/* -* This internal function does not flush PCI writes to the device. All -* users must ensure that they read from the device before either assuming -* that the device state is up to date, or returning out of this file. -* It does not affect the msi_desc::msix_ctrl cache either. Use with care! -*/ -static void pci_msix_write_vector_ctrl (struct msi_desc *desc,u32 ctrl) -{ -void __iomem *desc_addr =pci_msix_desc_addr (desc); - -if (desc->pci.msi_attrib.can_mask) -writel (ctrl, desc_addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); -} - -static inline void pci_msix_mask (struct msi_desc *desc) -{ - desc->pci.msix_ctrl |=PCI_MSIX_ENTRY_CTRL_MASKBIT ; -pci_msix_write_vector_ctrl (desc, desc->pci.msix_ctrl); -/* Flush write to device */ -readl (desc->pci.mask_base); -} - -static inline void pci_msix_unmask (struct msi_desc *desc) -{ - desc->pci.msix_ctrl &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT ; -pci_msix_write_vector_ctrl (desc, desc->pci.msix_ctrl); -} - -static void __pci_msi_mask_desc (struct msi_desc *desc,u32 mask) -{ -if (desc->pci.msi_attrib.is_msix) -pci_msix_mask (desc); -else -pci_msi_mask (desc, mask); -} - -static void __pci_msi_unmask_desc (struct msi_desc *desc,u32 mask) -{ -if (desc->pci.msi_attrib.is_msix) -pci_msix_unmask (desc); -else -pci_msi_unmask (desc, mask); -} - -/** -* pci_msi_mask_irq - Generic IRQ chip callback to mask PCI/MSI interrupts -* @data: pointer to irqdata associated to that interrupt -*/ -void pci_msi_mask_irq (struct irq_data *data) -{ -struct msi_desc *desc =irq_data_get_msi_desc (data); - -__pci_msi_mask_desc (desc,BIT (data->irq - desc->irq)); -} -EXPORT_SYMBOL_GPL (pci_msi_mask_irq); - -/** -* pci_msi_unmask_irq - Generic IRQ chip callback to unmask PCI/MSI interrupts -* @data: pointer to irqdata associated to that interrupt -*/ -void pci_msi_unmask_irq (struct irq_data *data) -{ -struct msi_desc *desc =irq_data_get_msi_desc (data); - -__pci_msi_unmask_desc (desc,BIT (data->irq - desc->irq)); -} -EXPORT_SYMBOL_GPL (pci_msi_unmask_irq); - -void __pci_read_msi_msg (struct msi_desc *entry,struct msi_msg *msg) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (entry); - -BUG_ON (dev->current_state !=PCI_D0 ); - -if (entry->pci.msi_attrib.is_msix) { -void __iomem *base =pci_msix_desc_addr (entry); - -if (WARN_ON_ONCE (entry->pci.msi_attrib.is_virtual)) -return ; - - msg->address_lo =readl (base +PCI_MSIX_ENTRY_LOWER_ADDR ); - msg->address_hi =readl (base +PCI_MSIX_ENTRY_UPPER_ADDR ); - msg->data =readl (base +PCI_MSIX_ENTRY_DATA ); - }else { -int pos = dev->msi_cap; -u16 data; - -pci_read_config_dword (dev, pos +PCI_MSI_ADDRESS_LO , - &msg->address_lo); -if (entry->pci.msi_attrib.is_64) { -pci_read_config_dword (dev, pos +PCI_MSI_ADDRESS_HI , - &msg->address_hi); -pci_read_config_word (dev, pos +PCI_MSI_DATA_64 , &data); - }else { - msg->address_hi =0 ; -pci_read_config_word (dev, pos +PCI_MSI_DATA_32 , &data); - } - msg->data = data; - } -} - -void __pci_write_msi_msg (struct msi_desc *entry,struct msi_msg *msg) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (entry); - -if (dev->current_state !=PCI_D0 ||pci_dev_is_disconnected (dev)) { -/* Don't touch the hardware now */ - }else if (entry->pci.msi_attrib.is_msix) { -void __iomem *base =pci_msix_desc_addr (entry); -u32 ctrl = entry->pci.msix_ctrl; -bool unmasked = !(ctrl &PCI_MSIX_ENTRY_CTRL_MASKBIT ); - -if (entry->pci.msi_attrib.is_virtual) - goto skip; - -/* -* The specification mandates that the entry is masked -* when the message is modified: -* -* "If software changes the Address or Data value of an -* entry while the entry is unmasked, the result is -* undefined." -*/ -if (unmasked) -pci_msix_write_vector_ctrl (entry, ctrl |PCI_MSIX_ENTRY_CTRL_MASKBIT ); - -writel (msg->address_lo, base +PCI_MSIX_ENTRY_LOWER_ADDR ); -writel (msg->address_hi, base +PCI_MSIX_ENTRY_UPPER_ADDR ); -writel (msg->data, base +PCI_MSIX_ENTRY_DATA ); - -if (unmasked) -pci_msix_write_vector_ctrl (entry, ctrl); - -/* Ensure that the writes are visible in the device */ -readl (base +PCI_MSIX_ENTRY_DATA ); - }else { -int pos = dev->msi_cap; -u16 msgctl; - -pci_read_config_word (dev, pos +PCI_MSI_FLAGS , &msgctl); - msgctl &= ~PCI_MSI_FLAGS_QSIZE ; - msgctl |= entry->pci.msi_attrib.multiple <<4 ; -pci_write_config_word (dev, pos +PCI_MSI_FLAGS , msgctl); - -pci_write_config_dword (dev, pos +PCI_MSI_ADDRESS_LO , - msg->address_lo); -if (entry->pci.msi_attrib.is_64) { -pci_write_config_dword (dev, pos +PCI_MSI_ADDRESS_HI , - msg->address_hi); -pci_write_config_word (dev, pos +PCI_MSI_DATA_64 , - msg->data); - }else { -pci_write_config_word (dev, pos +PCI_MSI_DATA_32 , - msg->data); - } -/* Ensure that the writes are visible in the device */ -pci_read_config_word (dev, pos +PCI_MSI_FLAGS , &msgctl); - } - -skip: - entry->msg = *msg; - -if (entry->write_msi_msg) - entry->write_msi_msg (entry, entry->write_msi_msg_data); - -} - -void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg) -{ -struct msi_desc *entry =irq_get_msi_desc (irq); - -__pci_write_msi_msg (entry, msg); -} -EXPORT_SYMBOL_GPL (pci_write_msi_msg); - -static void free_msi_irqs (struct pci_dev *dev) -{ -struct list_head *msi_list =dev_to_msi_list (&dev->dev); -struct msi_desc *entry, *tmp; -int i; - -for_each_pci_msi_entry (entry, dev) -if (entry->irq) -for (i =0 ; i < entry->nvec_used; i++) -BUG_ON (irq_has_action (entry->irq + i)); - -if (dev->msi_irq_groups) { -msi_destroy_sysfs (&dev->dev, dev->msi_irq_groups); - dev->msi_irq_groups =NULL ; - } - -pci_msi_teardown_msi_irqs (dev); - -list_for_each_entry_safe (entry, tmp, msi_list, list) { -if (entry->pci.msi_attrib.is_msix) { -if (list_is_last (&entry->list, msi_list)) -iounmap (entry->pci.mask_base); - } - -list_del (&entry->list); -free_msi_entry (entry); - } -} - -static void pci_intx_for_msi (struct pci_dev *dev,int enable) -{ -if (!(dev->dev_flags &PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG )) -pci_intx (dev, enable); -} - -static void pci_msi_set_enable (struct pci_dev *dev,int enable) -{ -u16 control; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &control); - control &= ~PCI_MSI_FLAGS_ENABLE ; -if (enable) - control |=PCI_MSI_FLAGS_ENABLE ; -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , control); -} - -/* -* Architecture override returns true when the PCI MSI message should be -* written by the generic restore function. -*/ -bool __weak arch_restore_msi_irqs (struct pci_dev *dev) -{ -return true; -} - -static void __pci_restore_msi_state (struct pci_dev *dev) -{ -struct msi_desc *entry; -u16 control; - -if (!dev->msi_enabled) -return ; - - entry =irq_get_msi_desc (dev->irq); - -pci_intx_for_msi (dev,0 ); -pci_msi_set_enable (dev,0 ); -if (arch_restore_msi_irqs (dev)) -__pci_write_msi_msg (entry, &entry->msg); - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &control); -pci_msi_update_mask (entry,0 ,0 ); - control &= ~PCI_MSI_FLAGS_QSIZE ; - control |= (entry->pci.msi_attrib.multiple <<4 ) |PCI_MSI_FLAGS_ENABLE ; -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , control); -} - -static void pci_msix_clear_and_set_ctrl (struct pci_dev *dev,u16 clear,u16 set) -{ -u16 ctrl; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); - ctrl &= ~clear; - ctrl |= set; -pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , ctrl); -} - -static void __pci_restore_msix_state (struct pci_dev *dev) -{ -struct msi_desc *entry; -bool write_msg; - -if (!dev->msix_enabled) -return ; -BUG_ON (list_empty (dev_to_msi_list (&dev->dev))); - -/* route the table */ -pci_intx_for_msi (dev,0 ); -pci_msix_clear_and_set_ctrl (dev,0 , -PCI_MSIX_FLAGS_ENABLE |PCI_MSIX_FLAGS_MASKALL ); - - write_msg =arch_restore_msi_irqs (dev); - -for_each_pci_msi_entry (entry, dev) { -if (write_msg) -__pci_write_msi_msg (entry, &entry->msg); -pci_msix_write_vector_ctrl (entry, entry->pci.msix_ctrl); - } - -pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_MASKALL ,0 ); -} - -void pci_restore_msi_state (struct pci_dev *dev) -{ -__pci_restore_msi_state (dev); -__pci_restore_msix_state (dev); -} -EXPORT_SYMBOL_GPL (pci_restore_msi_state); - -static struct msi_desc * -msi_setup_entry (struct pci_dev *dev,int nvec,struct irq_affinity *affd) -{ -struct irq_affinity_desc *masks =NULL ; -struct msi_desc *entry; -u16 control; - -if (affd) - masks =irq_create_affinity_masks (nvec, affd); - -/* MSI Entry Initialization */ - entry =alloc_msi_entry (&dev->dev, nvec, masks); -if (!entry) - goto out; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &control); -/* Lies, damned lies, and MSIs */ -if (dev->dev_flags &PCI_DEV_FLAGS_HAS_MSI_MASKING ) - control |=PCI_MSI_FLAGS_MASKBIT ; - - entry->pci.msi_attrib.is_msix =0 ; - entry->pci.msi_attrib.is_64 = !!(control &PCI_MSI_FLAGS_64BIT ); - entry->pci.msi_attrib.is_virtual =0 ; - entry->pci.msi_attrib.entry_nr =0 ; - entry->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && - !!(control &PCI_MSI_FLAGS_MASKBIT ); - entry->pci.msi_attrib.default_irq = dev->irq;/* Save IOAPIC IRQ */ - entry->pci.msi_attrib.multi_cap = (control &PCI_MSI_FLAGS_QMASK ) >>1 ; - entry->pci.msi_attrib.multiple =ilog2 (__roundup_pow_of_two (nvec)); - -if (control &PCI_MSI_FLAGS_64BIT ) - entry->pci.mask_pos = dev->msi_cap +PCI_MSI_MASK_64 ; -else - entry->pci.mask_pos = dev->msi_cap +PCI_MSI_MASK_32 ; - -/* Save the initial mask status */ -if (entry->pci.msi_attrib.can_mask) -pci_read_config_dword (dev, entry->pci.mask_pos, &entry->pci.msi_mask); - -out: -kfree (masks); -return entry; -} - -static int msi_verify_entries (struct pci_dev *dev) -{ -struct msi_desc *entry; - -if (!dev->no_64bit_msi) -return 0 ; - -for_each_pci_msi_entry (entry, dev) { -if (entry->msg.address_hi) { -pci_err (dev,"arch assigned 64-bit MSI address %#x%08x but device only supports 32 bits\n" , - entry->msg.address_hi, entry->msg.address_lo); -return -EIO ; - } - } -return 0 ; -} - -/** -* msi_capability_init - configure device's MSI capability structure -* @dev: pointer to the pci_dev data structure of MSI device function -* @nvec: number of interrupts to allocate -* @affd: description of automatic IRQ affinity assignments (may be %NULL) -* -* Setup the MSI capability structure of the device with the requested -* number of interrupts. A return value of zero indicates the successful -* setup of an entry with the new MSI IRQ. A negative return value indicates -* an error, and a positive return value indicates the number of interrupts -* which could have been allocated. -*/ -static int msi_capability_init (struct pci_dev *dev,int nvec, -struct irq_affinity *affd) -{ -const struct attribute_group **groups; -struct msi_desc *entry; -int ret; - -pci_msi_set_enable (dev,0 );/* Disable MSI during set up */ - - entry =msi_setup_entry (dev, nvec, affd); -if (!entry) -return -ENOMEM ; - -/* All MSIs are unmasked by default; mask them all */ -pci_msi_mask (entry,msi_multi_mask (entry)); - -list_add_tail (&entry->list,dev_to_msi_list (&dev->dev)); - -/* Configure MSI capability structure */ - ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSI ); -if (ret) - goto err; - - ret =msi_verify_entries (dev); -if (ret) - goto err; - - groups =msi_populate_sysfs (&dev->dev); -if (IS_ERR (groups)) { - ret =PTR_ERR (groups); - goto err; - } - - dev->msi_irq_groups = groups; - -/* Set MSI enabled bits */ -pci_intx_for_msi (dev,0 ); -pci_msi_set_enable (dev,1 ); - dev->msi_enabled =1 ; - -pcibios_free_irq (dev); - dev->irq = entry->irq; -return 0 ; - -err: -pci_msi_unmask (entry,msi_multi_mask (entry)); -free_msi_irqs (dev); -return ret; -} - -static void __iomem *msix_map_region (struct pci_dev *dev, -unsigned int nr_entries) -{ -resource_size_t phys_addr; -u32 table_offset; -unsigned long flags; -u8 bir; - -pci_read_config_dword (dev, dev->msix_cap +PCI_MSIX_TABLE , - &table_offset); - bir = (u8)(table_offset &PCI_MSIX_TABLE_BIR ); - flags =pci_resource_flags (dev, bir); -if (!flags || (flags &IORESOURCE_UNSET )) -return NULL ; - - table_offset &=PCI_MSIX_TABLE_OFFSET ; - phys_addr =pci_resource_start (dev, bir) + table_offset; - -return ioremap (phys_addr, nr_entries *PCI_MSIX_ENTRY_SIZE ); -} - -static int msix_setup_entries (struct pci_dev *dev,void __iomem *base, -struct msix_entry *entries,int nvec, -struct irq_affinity *affd) -{ -struct irq_affinity_desc *curmsk, *masks =NULL ; -struct msi_desc *entry; -void __iomem *addr; -int ret, i; -int vec_count =pci_msix_vec_count (dev); - -if (affd) - masks =irq_create_affinity_masks (nvec, affd); - -for (i =0 , curmsk = masks; i < nvec; i++) { - entry =alloc_msi_entry (&dev->dev,1 , curmsk); -if (!entry) { -if (!i) -iounmap (base); -else -free_msi_irqs (dev); -/* No enough memory. Don't try again */ - ret = -ENOMEM ; - goto out; - } - - entry->pci.msi_attrib.is_msix =1 ; - entry->pci.msi_attrib.is_64 =1 ; - -if (entries) - entry->pci.msi_attrib.entry_nr = entries[i].entry; -else - entry->pci.msi_attrib.entry_nr = i; - - entry->pci.msi_attrib.is_virtual = - entry->pci.msi_attrib.entry_nr >= vec_count; - - entry->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && - !entry->pci.msi_attrib.is_virtual; - - entry->pci.msi_attrib.default_irq = dev->irq; - entry->pci.mask_base = base; - -if (entry->pci.msi_attrib.can_mask) { - addr =pci_msix_desc_addr (entry); - entry->pci.msix_ctrl =readl (addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); - } - -list_add_tail (&entry->list,dev_to_msi_list (&dev->dev)); -if (masks) - curmsk++; - } - ret =0 ; -out: -kfree (masks); -return ret; -} - -static void msix_update_entries (struct pci_dev *dev,struct msix_entry *entries) -{ -struct msi_desc *entry; - -if (entries) { -for_each_pci_msi_entry (entry, dev) { - entries->vector = entry->irq; - entries++; - } - } -} - -static void msix_mask_all (void __iomem *base,int tsize) -{ -u32 ctrl =PCI_MSIX_ENTRY_CTRL_MASKBIT ; -int i; - -if (pci_msi_ignore_mask) -return ; - -for (i =0 ; i < tsize; i++, base +=PCI_MSIX_ENTRY_SIZE ) -writel (ctrl, base +PCI_MSIX_ENTRY_VECTOR_CTRL ); -} - -/** -* msix_capability_init - configure device's MSI-X capability -* @dev: pointer to the pci_dev data structure of MSI-X device function -* @entries: pointer to an array of struct msix_entry entries -* @nvec: number of @entries -* @affd: Optional pointer to enable automatic affinity assignment -* -* Setup the MSI-X capability structure of device function with a -* single MSI-X IRQ. A return of zero indicates the successful setup of -* requested MSI-X entries with allocated IRQs or non-zero for otherwise. -**/ -static int msix_capability_init (struct pci_dev *dev,struct msix_entry *entries, -int nvec,struct irq_affinity *affd) -{ -const struct attribute_group **groups; -void __iomem *base; -int ret, tsize; -u16 control; - -/* -* Some devices require MSI-X to be enabled before the MSI-X -* registers can be accessed. Mask all the vectors to prevent -* interrupts coming in before they're fully set up. -*/ -pci_msix_clear_and_set_ctrl (dev,0 ,PCI_MSIX_FLAGS_MASKALL | -PCI_MSIX_FLAGS_ENABLE ); - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &control); -/* Request & Map MSI-X table region */ - tsize =msix_table_size (control); - base =msix_map_region (dev, tsize); -if (!base) { - ret = -ENOMEM ; - goto out_disable; - } - -/* Ensure that all table entries are masked. */ -msix_mask_all (base, tsize); - - ret =msix_setup_entries (dev, base, entries, nvec, affd); -if (ret) - goto out_disable; - - ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX ); -if (ret) - goto out_avail; - -/* Check if all MSI entries honor device restrictions */ - ret =msi_verify_entries (dev); -if (ret) - goto out_free; - -msix_update_entries (dev, entries); - - groups =msi_populate_sysfs (&dev->dev); -if (IS_ERR (groups)) { - ret =PTR_ERR (groups); - goto out_free; - } - - dev->msi_irq_groups = groups; - -/* Set MSI-X enabled bits and unmask the function */ -pci_intx_for_msi (dev,0 ); - dev->msix_enabled =1 ; -pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_MASKALL ,0 ); - -pcibios_free_irq (dev); -return 0 ; - -out_avail: -if (ret <0 ) { -/* -* If we had some success, report the number of IRQs -* we succeeded in setting up. -*/ -struct msi_desc *entry; -int avail =0 ; - -for_each_pci_msi_entry (entry, dev) { -if (entry->irq !=0 ) - avail++; - } -if (avail !=0 ) - ret = avail; - } - -out_free: -free_msi_irqs (dev); - -out_disable: -pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_ENABLE ,0 ); - -return ret; -} - -/** -* pci_msi_supported - check whether MSI may be enabled on a device -* @dev: pointer to the pci_dev data structure of MSI device function -* @nvec: how many MSIs have been requested? -* -* Look at global flags, the device itself, and its parent buses -* to determine if MSI/-X are supported for the device. If MSI/-X is -* supported return 1, else return 0. -**/ -static int pci_msi_supported (struct pci_dev *dev,int nvec) -{ -struct pci_bus *bus; - -/* MSI must be globally enabled and supported by the device */ -if (!pci_msi_enable) -return 0 ; - -if (!dev || dev->no_msi) -return 0 ; - -/* -* You can't ask to have 0 or less MSIs configured. -* a) it's stupid .. -* b) the list manipulation code assumes nvec >= 1. -*/ -if (nvec <1 ) -return 0 ; - -/* -* Any bridge which does NOT route MSI transactions from its -* secondary bus to its primary bus must set NO_MSI flag on -* the secondary pci_bus. -* -* The NO_MSI flag can either be set directly by: -* - arch-specific PCI host bus controller drivers (deprecated) -* - quirks for specific PCI bridges -* -* or indirectly by platform-specific PCI host bridge drivers by -* advertising the 'msi_domain' property, which results in -* the NO_MSI flag when no MSI domain is found for this bridge -* at probe time. -*/ -for (bus = dev->bus; bus; bus = bus->parent) -if (bus->bus_flags &PCI_BUS_FLAGS_NO_MSI ) -return 0 ; - -return 1 ; -} - -/** -* pci_msi_vec_count - Return the number of MSI vectors a device can send -* @dev: device to report about -* -* This function returns the number of MSI vectors a device requested via -* Multiple Message Capable register. It returns a negative errno if the -* device is not capable sending MSI interrupts. Otherwise, the call succeeds -* and returns a power of two, up to a maximum of 2^5 (32), according to the -* MSI specification. -**/ -int pci_msi_vec_count (struct pci_dev *dev) -{ -int ret; -u16 msgctl; - -if (!dev->msi_cap) -return -EINVAL ; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &msgctl); - ret =1 << ((msgctl &PCI_MSI_FLAGS_QMASK ) >>1 ); - -return ret; -} -EXPORT_SYMBOL (pci_msi_vec_count); - -static void pci_msi_shutdown (struct pci_dev *dev) -{ -struct msi_desc *desc; - -if (!pci_msi_enable || !dev || !dev->msi_enabled) -return ; - -BUG_ON (list_empty (dev_to_msi_list (&dev->dev))); - desc =first_pci_msi_entry (dev); - -pci_msi_set_enable (dev,0 ); -pci_intx_for_msi (dev,1 ); - dev->msi_enabled =0 ; - -/* Return the device with MSI unmasked as initial states */ -pci_msi_unmask (desc,msi_multi_mask (desc)); - -/* Restore dev->irq to its default pin-assertion IRQ */ - dev->irq = desc->pci.msi_attrib.default_irq; -pcibios_alloc_irq (dev); -} - -void pci_disable_msi (struct pci_dev *dev) -{ -if (!pci_msi_enable || !dev || !dev->msi_enabled) -return ; - -pci_msi_shutdown (dev); -free_msi_irqs (dev); -} -EXPORT_SYMBOL (pci_disable_msi); - -/** -* pci_msix_vec_count - return the number of device's MSI-X table entries -* @dev: pointer to the pci_dev data structure of MSI-X device function -* This function returns the number of device's MSI-X table entries and -* therefore the number of MSI-X vectors device is capable of sending. -* It returns a negative errno if the device is not capable of sending MSI-X -* interrupts. -**/ -int pci_msix_vec_count (struct pci_dev *dev) -{ -u16 control; - -if (!dev->msix_cap) -return -EINVAL ; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &control); -return msix_table_size (control); -} -EXPORT_SYMBOL (pci_msix_vec_count); - -static int __pci_enable_msix (struct pci_dev *dev,struct msix_entry *entries, -int nvec,struct irq_affinity *affd,int flags) -{ -int nr_entries; -int i, j; - -if (!pci_msi_supported (dev, nvec) || dev->current_state !=PCI_D0 ) -return -EINVAL ; - - nr_entries =pci_msix_vec_count (dev); -if (nr_entries <0 ) -return nr_entries; -if (nvec > nr_entries && !(flags &PCI_IRQ_VIRTUAL )) -return nr_entries; - -if (entries) { -/* Check for any invalid entries */ -for (i =0 ; i < nvec; i++) { -if (entries[i].entry >= nr_entries) -return -EINVAL ;/* invalid entry */ -for (j = i +1 ; j < nvec; j++) { -if (entries[i].entry == entries[j].entry) -return -EINVAL ;/* duplicate entry */ - } - } - } - -/* Check whether driver already requested for MSI IRQ */ -if (dev->msi_enabled) { -pci_info (dev,"can't enable MSI-X (MSI IRQ already assigned)\n" ); -return -EINVAL ; - } -return msix_capability_init (dev, entries, nvec, affd); -} - -static void pci_msix_shutdown (struct pci_dev *dev) -{ -struct msi_desc *entry; - -if (!pci_msi_enable || !dev || !dev->msix_enabled) -return ; - -if (pci_dev_is_disconnected (dev)) { - dev->msix_enabled =0 ; -return ; - } - -/* Return the device with MSI-X masked as initial states */ -for_each_pci_msi_entry (entry, dev) -pci_msix_mask (entry); - -pci_msix_clear_and_set_ctrl (dev,PCI_MSIX_FLAGS_ENABLE ,0 ); -pci_intx_for_msi (dev,1 ); - dev->msix_enabled =0 ; -pcibios_alloc_irq (dev); -} - -void pci_disable_msix (struct pci_dev *dev) -{ -if (!pci_msi_enable || !dev || !dev->msix_enabled) -return ; - -pci_msix_shutdown (dev); -free_msi_irqs (dev); -} -EXPORT_SYMBOL (pci_disable_msix); - -void pci_no_msi (void ) -{ - pci_msi_enable =0 ; -} - -/** -* pci_msi_enabled - is MSI enabled? -* -* Returns true if MSI has not been disabled by the command-line option -* pci=nomsi. -**/ -int pci_msi_enabled (void ) -{ -return pci_msi_enable; -} -EXPORT_SYMBOL (pci_msi_enabled); - -static int __pci_enable_msi_range (struct pci_dev *dev,int minvec,int maxvec, -struct irq_affinity *affd) -{ -int nvec; -int rc; - -if (!pci_msi_supported (dev, minvec) || dev->current_state !=PCI_D0 ) -return -EINVAL ; - -/* Check whether driver already requested MSI-X IRQs */ -if (dev->msix_enabled) { -pci_info (dev,"can't enable MSI (MSI-X already enabled)\n" ); -return -EINVAL ; - } - -if (maxvec < minvec) -return -ERANGE ; - -if (WARN_ON_ONCE (dev->msi_enabled)) -return -EINVAL ; - - nvec =pci_msi_vec_count (dev); -if (nvec <0 ) -return nvec; -if (nvec < minvec) -return -ENOSPC ; - -if (nvec > maxvec) - nvec = maxvec; - -for (;;) { -if (affd) { - nvec =irq_calc_affinity_vectors (minvec, nvec, affd); -if (nvec < minvec) -return -ENOSPC ; - } - - rc =msi_capability_init (dev, nvec, affd); -if (rc ==0 ) -return nvec; - -if (rc <0 ) -return rc; -if (rc < minvec) -return -ENOSPC ; - - nvec = rc; - } -} - -/* deprecated, don't use */ -int pci_enable_msi (struct pci_dev *dev) -{ -int rc =__pci_enable_msi_range (dev,1 ,1 ,NULL ); -if (rc <0 ) -return rc; -return 0 ; -} -EXPORT_SYMBOL (pci_enable_msi); - -static int __pci_enable_msix_range (struct pci_dev *dev, -struct msix_entry *entries,int minvec, -int maxvec,struct irq_affinity *affd, -int flags) -{ -int rc, nvec = maxvec; - -if (maxvec < minvec) -return -ERANGE ; - -if (WARN_ON_ONCE (dev->msix_enabled)) -return -EINVAL ; - -for (;;) { -if (affd) { - nvec =irq_calc_affinity_vectors (minvec, nvec, affd); -if (nvec < minvec) -return -ENOSPC ; - } - - rc =__pci_enable_msix (dev, entries, nvec, affd, flags); -if (rc ==0 ) -return nvec; - -if (rc <0 ) -return rc; -if (rc < minvec) -return -ENOSPC ; - - nvec = rc; - } -} - -/** -* pci_enable_msix_range - configure device's MSI-X capability structure -* @dev: pointer to the pci_dev data structure of MSI-X device function -* @entries: pointer to an array of MSI-X entries -* @minvec: minimum number of MSI-X IRQs requested -* @maxvec: maximum number of MSI-X IRQs requested -* -* Setup the MSI-X capability structure of device function with a maximum -* possible number of interrupts in the range between @minvec and @maxvec -* upon its software driver call to request for MSI-X mode enabled on its -* hardware device function. It returns a negative errno if an error occurs. -* If it succeeds, it returns the actual number of interrupts allocated and -* indicates the successful configuration of MSI-X capability structure -* with new allocated MSI-X interrupts. -**/ -int pci_enable_msix_range (struct pci_dev *dev,struct msix_entry *entries, -int minvec,int maxvec) -{ -return __pci_enable_msix_range (dev, entries, minvec, maxvec,NULL ,0 ); -} -EXPORT_SYMBOL (pci_enable_msix_range); - -/** -* pci_alloc_irq_vectors_affinity - allocate multiple IRQs for a device -* @dev: PCI device to operate on -* @min_vecs: minimum number of vectors required (must be >= 1) -* @max_vecs: maximum (desired) number of vectors -* @flags: flags or quirks for the allocation -* @affd: optional description of the affinity requirements -* -* Allocate up to @max_vecs interrupt vectors for @dev, using MSI-X or MSI -* vectors if available, and fall back to a single legacy vector -* if neither is available. Return the number of vectors allocated, -* (which might be smaller than @max_vecs) if successful, or a negative -* error code on error. If less than @min_vecs interrupt vectors are -* available for @dev the function will fail with -ENOSPC. -* -* To get the Linux IRQ number used for a vector that can be passed to -* request_irq() use the pci_irq_vector() helper. -*/ -int pci_alloc_irq_vectors_affinity (struct pci_dev *dev,unsigned int min_vecs, -unsigned int max_vecs,unsigned int flags, -struct irq_affinity *affd) -{ -struct irq_affinity msi_default_affd = {0 }; -int nvecs = -ENOSPC ; - -if (flags &PCI_IRQ_AFFINITY ) { -if (!affd) - affd = &msi_default_affd; - }else { -if (WARN_ON (affd)) - affd =NULL ; - } - -if (flags &PCI_IRQ_MSIX ) { - nvecs =__pci_enable_msix_range (dev,NULL , min_vecs, max_vecs, - affd, flags); -if (nvecs >0 ) -return nvecs; - } - -if (flags &PCI_IRQ_MSI ) { - nvecs =__pci_enable_msi_range (dev, min_vecs, max_vecs, affd); -if (nvecs >0 ) -return nvecs; - } - -/* use legacy IRQ if allowed */ -if (flags &PCI_IRQ_LEGACY ) { -if (min_vecs ==1 && dev->irq) { -/* -* Invoke the affinity spreading logic to ensure that -* the device driver can adjust queue configuration -* for the single interrupt case. -*/ -if (affd) -irq_create_affinity_masks (1 , affd); -pci_intx (dev,1 ); -return 1 ; - } - } - -return nvecs; -} -EXPORT_SYMBOL (pci_alloc_irq_vectors_affinity); - -/** -* pci_free_irq_vectors - free previously allocated IRQs for a device -* @dev: PCI device to operate on -* -* Undoes the allocations and enabling in pci_alloc_irq_vectors(). -*/ -void pci_free_irq_vectors (struct pci_dev *dev) -{ -pci_disable_msix (dev); -pci_disable_msi (dev); -} -EXPORT_SYMBOL (pci_free_irq_vectors); - -/** -* pci_irq_vector - return Linux IRQ number of a device vector -* @dev: PCI device to operate on -* @nr: Interrupt vector index (0-based) -* -* @nr has the following meanings depending on the interrupt mode: -* MSI-X: The index in the MSI-X vector table -* MSI: The index of the enabled MSI vectors -* INTx: Must be 0 -* -* Return: The Linux interrupt number or -EINVAl if @nr is out of range. -*/ -int pci_irq_vector (struct pci_dev *dev,unsigned int nr) -{ -if (dev->msix_enabled) { -struct msi_desc *entry; - -for_each_pci_msi_entry (entry, dev) { -if (entry->pci.msi_attrib.entry_nr == nr) -return entry->irq; - } -WARN_ON_ONCE (1 ); -return -EINVAL ; - } - -if (dev->msi_enabled) { -struct msi_desc *entry =first_pci_msi_entry (dev); - -if (WARN_ON_ONCE (nr >= entry->nvec_used)) -return -EINVAL ; - }else { -if (WARN_ON_ONCE (nr >0 )) -return -EINVAL ; - } - -return dev->irq + nr; -} -EXPORT_SYMBOL (pci_irq_vector); - -/** -* pci_irq_get_affinity - return the affinity of a particular MSI vector -* @dev: PCI device to operate on -* @nr: device-relative interrupt vector index (0-based). -* -* @nr has the following meanings depending on the interrupt mode: -* MSI-X: The index in the MSI-X vector table -* MSI: The index of the enabled MSI vectors -* INTx: Must be 0 -* -* Return: A cpumask pointer or NULL if @nr is out of range -*/ -const struct cpumask *pci_irq_get_affinity (struct pci_dev *dev,int nr) -{ -if (dev->msix_enabled) { -struct msi_desc *entry; - -for_each_pci_msi_entry (entry, dev) { -if (entry->pci.msi_attrib.entry_nr == nr) -return &entry->affinity->mask; - } -WARN_ON_ONCE (1 ); -return NULL ; - }else if (dev->msi_enabled) { -struct msi_desc *entry =first_pci_msi_entry (dev); - -if (WARN_ON_ONCE (!entry || !entry->affinity || - nr >= entry->nvec_used)) -return NULL ; - -return &entry->affinity[nr].mask; - }else { -return cpu_possible_mask; - } -} -EXPORT_SYMBOL (pci_irq_get_affinity); - -struct pci_dev *msi_desc_to_pci_dev (struct msi_desc *desc) -{ -return to_pci_dev (desc->dev); -} -EXPORT_SYMBOL (msi_desc_to_pci_dev); - -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -/** -* pci_msi_domain_write_msg - Helper to write MSI message to PCI config space -* @irq_data: Pointer to interrupt data of the MSI interrupt -* @msg: Pointer to the message -*/ -static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) -{ -struct msi_desc *desc =irq_data_get_msi_desc (irq_data); - -/* -* For MSI-X desc->irq is always equal to irq_data->irq. For -* MSI only the first interrupt of MULTI MSI passes the test. -*/ -if (desc->irq == irq_data->irq) -__pci_write_msi_msg (desc, msg); -} - -/** -* pci_msi_domain_calc_hwirq - Generate a unique ID for an MSI source -* @desc: Pointer to the MSI descriptor -* -* The ID number is only used within the irqdomain. -*/ -static irq_hw_number_t pci_msi_domain_calc_hwirq (struct msi_desc *desc) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (desc); - -return (irq_hw_number_t )desc->pci.msi_attrib.entry_nr | -pci_dev_id (dev) <<11 | - (pci_domain_nr (dev->bus) &0xFFFFFFFF ) <<27 ; -} - -static inline bool pci_msi_desc_is_multi_msi (struct msi_desc *desc) -{ -return !desc->pci.msi_attrib.is_msix && desc->nvec_used >1 ; -} - -/** -* pci_msi_domain_check_cap - Verify that @domain supports the capabilities -* for @dev -* @domain: The interrupt domain to check -* @info: The domain info for verification -* @dev: The device to check -* -* Returns: -* 0 if the functionality is supported -* 1 if Multi MSI is requested, but the domain does not support it -* -ENOTSUPP otherwise -*/ -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev) -{ -struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev)); - -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && - !(info->flags &MSI_FLAG_MULTI_PCI_MSI )) -return 1 ; -else if (desc->pci.msi_attrib.is_msix && !(info->flags &MSI_FLAG_PCI_MSIX )) -return -ENOTSUPP ; - -return 0 ; -} - -static int pci_msi_domain_handle_error (struct irq_domain *domain, -struct msi_desc *desc,int error) -{ -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) -return 1 ; - -return error; -} - -static void pci_msi_domain_set_desc (msi_alloc_info_t *arg, -struct msi_desc *desc) -{ - arg->desc = desc; - arg->hwirq =pci_msi_domain_calc_hwirq (desc); -} - -static struct msi_domain_ops pci_msi_domain_ops_default = { - .set_desc = pci_msi_domain_set_desc, - .msi_check = pci_msi_domain_check_cap, - .handle_error = pci_msi_domain_handle_error, -}; - -static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info) -{ -struct msi_domain_ops *ops = info->ops; - -if (ops ==NULL ) { - info->ops = &pci_msi_domain_ops_default; - }else { -if (ops->set_desc ==NULL ) - ops->set_desc = pci_msi_domain_set_desc; -if (ops->msi_check ==NULL ) - ops->msi_check = pci_msi_domain_check_cap; -if (ops->handle_error ==NULL ) - ops->handle_error = pci_msi_domain_handle_error; - } -} - -static void pci_msi_domain_update_chip_ops (struct msi_domain_info *info) -{ -struct irq_chip *chip = info->chip; - -BUG_ON (!chip); -if (!chip->irq_write_msi_msg) - chip->irq_write_msi_msg = pci_msi_domain_write_msg; -if (!chip->irq_mask) - chip->irq_mask = pci_msi_mask_irq; -if (!chip->irq_unmask) - chip->irq_unmask = pci_msi_unmask_irq; -} - -/** -* pci_msi_create_irq_domain - Create a MSI interrupt domain -* @fwnode: Optional fwnode of the interrupt controller -* @info: MSI domain info -* @parent: Parent irq domain -* -* Updates the domain and chip ops and creates a MSI interrupt domain. -* -* Returns: -* A domain pointer or NULL in case of failure. -*/ -struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode, -struct msi_domain_info *info, -struct irq_domain *parent) -{ -struct irq_domain *domain; - -if (WARN_ON (info->flags &MSI_FLAG_LEVEL_CAPABLE )) - info->flags &= ~MSI_FLAG_LEVEL_CAPABLE ; - -if (info->flags &MSI_FLAG_USE_DEF_DOM_OPS ) -pci_msi_domain_update_dom_ops (info); -if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS ) -pci_msi_domain_update_chip_ops (info); - - info->flags |=MSI_FLAG_ACTIVATE_EARLY ; -if (IS_ENABLED (CONFIG_GENERIC_IRQ_RESERVATION_MODE )) - info->flags |=MSI_FLAG_MUST_REACTIVATE ; - -/* PCI-MSI is oneshot-safe */ - info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; - - domain =msi_create_irq_domain (fwnode, info, parent); -if (!domain) -return NULL ; - -irq_domain_update_bus_token (domain,DOMAIN_BUS_PCI_MSI ); -return domain; -} -EXPORT_SYMBOL_GPL (pci_msi_create_irq_domain); - -/* -* Users of the generic MSI infrastructure expect a device to have a single ID, -* so with DMA aliases we have to pick the least-worst compromise. Devices with -* DMA phantom functions tend to still emit MSIs from the real function number, -* so we ignore those and only consider topological aliases where either the -* alias device or RID appears on a different bus number. We also make the -* reasonable assumption that bridges are walked in an upstream direction (so -* the last one seen wins), and the much braver assumption that the most likely -* case is that of PCI->PCIe so we should always use the alias RID. This echoes -* the logic from intel_irq_remapping's set_msi_sid(), which presumably works -* well enough in practice; in the face of the horrible PCIe<->PCI-X conditions -* for taking ownership all we can really do is close our eyes and hope... -*/ -static int get_msi_id_cb (struct pci_dev *pdev,u16 alias,void *data) -{ -u32 *pa = data; -u8 bus =PCI_BUS_NUM (*pa); - -if (pdev->bus->number != bus ||PCI_BUS_NUM (alias) != bus) - *pa = alias; - -return 0 ; -} - -/** -* pci_msi_domain_get_msi_rid - Get the MSI requester id (RID) -* @domain: The interrupt domain -* @pdev: The PCI device. -* -* The RID for a device is formed from the alias, with a firmware -* supplied mapping applied -* -* Returns: The RID. -*/ -u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev) -{ -struct device_node *of_node; -u32 rid =pci_dev_id (pdev); - -pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); - - of_node =irq_domain_get_of_node (domain); - rid = of_node ?of_msi_map_id (&pdev->dev, of_node, rid) : -iort_msi_map_id (&pdev->dev, rid); - -return rid; -} - -/** -* pci_msi_get_device_domain - Get the MSI domain for a given PCI device -* @pdev: The PCI device -* -* Use the firmware data to find a device-specific MSI domain -* (i.e. not one that is set as a default). -* -* Returns: The corresponding MSI domain or NULL if none has been found. -*/ -struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev) -{ -struct irq_domain *dom; -u32 rid =pci_dev_id (pdev); - -pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); - dom =of_msi_map_get_device_domain (&pdev->dev, rid,DOMAIN_BUS_PCI_MSI ); -if (!dom) - dom =iort_get_device_domain (&pdev->dev, rid, -DOMAIN_BUS_PCI_MSI ); -return dom; -} - -/** -* pci_dev_has_special_msi_domain - Check whether the device is handled by -* a non-standard PCI-MSI domain -* @pdev: The PCI device to check. -* -* Returns: True if the device irqdomain or the bus irqdomain is -* non-standard PCI/MSI. -*/ -bool pci_dev_has_special_msi_domain (struct pci_dev *pdev) -{ -struct irq_domain *dom =dev_get_msi_domain (&pdev->dev); - -if (!dom) - dom =dev_get_msi_domain (&pdev->bus->dev); - -if (!dom) -return true; - -return dom->bus_token !=DOMAIN_BUS_PCI_MSI ; -} - -#endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ -#endif /* CONFIG_PCI_MSI */ - -void pci_msi_init (struct pci_dev *dev) -{ -u16 ctrl; - -/* -* Disable the MSI hardware to avoid screaming interrupts -* during boot. This is the power on reset default so -* usually this should be a noop. -*/ - dev->msi_cap =pci_find_capability (dev,PCI_CAP_ID_MSI ); -if (!dev->msi_cap) -return ; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &ctrl); -if (ctrl &PCI_MSI_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , - ctrl & ~PCI_MSI_FLAGS_ENABLE ); - -if (!(ctrl &PCI_MSI_FLAGS_64BIT )) - dev->no_64bit_msi =1 ; -} - -void pci_msix_init (struct pci_dev *dev) -{ -u16 ctrl; - - dev->msix_cap =pci_find_capability (dev,PCI_CAP_ID_MSIX ); -if (!dev->msix_cap) -return ; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); -if (ctrl &PCI_MSIX_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , - ctrl & ~PCI_MSIX_FLAGS_ENABLE ); -}drivers/pci/msi/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the PCI/MSI +obj-$(CONFIG_PCI) += msi.odrivers/pci/msi/msi.c new file +1532
-0@@ -0,0 +1,1532 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* PCI Message Signaled Interrupt (MSI) +* +* Copyright (C) 2003-2004 Intel +* Copyright (C) Tom Long Nguyen ([email protected]) +* Copyright (C) 2016 Christoph Hellwig. +*/ + +#include <linux/acpi_iort.h> +#include <linux/err.h> +#include <linux/export.h> +#include <linux/irq.h> +#include <linux/irqdomain.h> +#include <linux/msi.h> +#include <linux/of_irq.h> +#include <linux/pci.h> + +#include "../pci.h" + +#ifdef CONFIG_PCI_MSI + +static int pci_msi_enable = 1; +int pci_msi_ignore_mask; + +#define msix_table_size(flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) + +#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN +static int pci_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +{ + struct irq_domain *domain; + + domain = dev_get_msi_domain(&dev->dev); + if (domain && irq_domain_is_hierarchy(domain)) + return msi_domain_alloc_irqs(domain, &dev->dev, nvec); + + return arch_setup_msi_irqs(dev, nvec, type); +} + +static void pci_msi_teardown_msi_irqs(struct pci_dev *dev) +{ + struct irq_domain *domain; + + domain = dev_get_msi_domain(&dev->dev); + if (domain && irq_domain_is_hierarchy(domain)) + msi_domain_free_irqs(domain, &dev->dev); + else + arch_teardown_msi_irqs(dev); +} +#else +#define pci_msi_setup_msi_irqs arch_setup_msi_irqs +#define pci_msi_teardown_msi_irqs arch_teardown_msi_irqs +#endif + +#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS +/* Arch hooks */ +int __weak arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) +{ + return -EINVAL; +} + +void __weak arch_teardown_msi_irq(unsigned int irq) +{ +} + +int __weak arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +{ + struct msi_desc *entry; + int ret; + + /* + * If an architecture wants to support multiple MSI, it needs to + * override arch_setup_msi_irqs() + */ + if (type == PCI_CAP_ID_MSI && nvec > 1) + return 1; + + for_each_pci_msi_entry(entry, dev) { + ret = arch_setup_msi_irq(dev, entry); + if (ret < 0) + return ret; + if (ret > 0) + return -ENOSPC; + } + + return 0; +} + +void __weak arch_teardown_msi_irqs(struct pci_dev *dev) +{ + int i; + struct msi_desc *entry; + + for_each_pci_msi_entry(entry, dev) + if (entry->irq) + for (i = 0; i < entry->nvec_used; i++) + arch_teardown_msi_irq(entry->irq + i); +} +#endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */ + +/* + * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to + * mask all MSI interrupts by clearing the MSI enable bit does not work + * reliably as devices without an INTx disable bit will then generate a + * level IRQ which will never be cleared. + */ +static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) +{ + /* Don't shift by >= width of type */ + if (desc->pci.msi_attrib.multi_cap >= 5) + return 0xffffffff; + return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1; +} + +static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) +{ + raw_spinlock_t *lock = &desc->dev->msi_lock; + unsigned long flags; + + if (!desc->pci.msi_attrib.can_mask) + return; + + raw_spin_lock_irqsave(lock, flags); + desc->pci.msi_mask &= ~clear; + desc->pci.msi_mask |= set; + pci_write_config_dword(msi_desc_to_pci_dev(desc), desc->pci.mask_pos, + desc->pci.msi_mask); + raw_spin_unlock_irqrestore(lock, flags); +} + +static inline void pci_msi_mask(struct msi_desc *desc, u32 mask) +{ + pci_msi_update_mask(desc, 0, mask); +} + +static inline void pci_msi_unmask(struct msi_desc *desc, u32 mask) +{ + pci_msi_update_mask(desc, mask, 0); +} + +static inline void __iomem *pci_msix_desc_addr(struct msi_desc *desc) +{ + return desc->pci.mask_base + desc->pci.msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE; +} + +/* + * This internal function does not flush PCI writes to the device. All + * users must ensure that they read from the device before either assuming + * that the device state is up to date, or returning out of this file. + * It does not affect the msi_desc::msix_ctrl cache either. Use with care! + */ +static void pci_msix_write_vector_ctrl(struct msi_desc *desc, u32 ctrl) +{ + void __iomem *desc_addr = pci_msix_desc_addr(desc); + + if (desc->pci.msi_attrib.can_mask) + writel(ctrl, desc_addr + PCI_MSIX_ENTRY_VECTOR_CTRL); +} + +static inline void pci_msix_mask(struct msi_desc *desc) +{ + desc->pci.msix_ctrl |= PCI_MSIX_ENTRY_CTRL_MASKBIT; + pci_msix_write_vector_ctrl(desc, desc->pci.msix_ctrl); + /* Flush write to device */ + readl(desc->pci.mask_base); +} + +static inline void pci_msix_unmask(struct msi_desc *desc) +{ + desc->pci.msix_ctrl &= ~PCI_MSIX_ENTRY_CTRL_MASKBIT; + pci_msix_write_vector_ctrl(desc, desc->pci.msix_ctrl); +} + +static void __pci_msi_mask_desc(struct msi_desc *desc, u32 mask) +{ + if (desc->pci.msi_attrib.is_msix) + pci_msix_mask(desc); + else + pci_msi_mask(desc, mask); +} + +static void __pci_msi_unmask_desc(struct msi_desc *desc, u32 mask) +{ + if (desc->pci.msi_attrib.is_msix) + pci_msix_unmask(desc); + else + pci_msi_unmask(desc, mask); +} + +/** + * pci_msi_mask_irq - Generic IRQ chip callback to mask PCI/MSI interrupts + * @data: pointer to irqdata associated to that interrupt + */ +void pci_msi_mask_irq(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + __pci_msi_mask_desc(desc, BIT(data->irq - desc->irq)); +} +EXPORT_SYMBOL_GPL(pci_msi_mask_irq); + +/** + * pci_msi_unmask_irq - Generic IRQ chip callback to unmask PCI/MSI interrupts + * @data: pointer to irqdata associated to that interrupt + */ +void pci_msi_unmask_irq(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + __pci_msi_unmask_desc(desc, BIT(data->irq - desc->irq)); +} +EXPORT_SYMBOL_GPL(pci_msi_unmask_irq); + +void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg) +{ + struct pci_dev *dev = msi_desc_to_pci_dev(entry); + + BUG_ON(dev->current_state != PCI_D0); + + if (entry->pci.msi_attrib.is_msix) { + void __iomem *base = pci_msix_desc_addr(entry); + + if (WARN_ON_ONCE(entry->pci.msi_attrib.is_virtual)) + return; + + msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR); + msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR); + msg->data = readl(base + PCI_MSIX_ENTRY_DATA); + } else { + int pos = dev->msi_cap; + u16 data; + + pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, + &msg->address_lo); + if (entry->pci.msi_attrib.is_64) { + pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, + &msg->address_hi); + pci_read_config_word(dev, pos + PCI_MSI_DATA_64, &data); + } else { + msg->address_hi = 0; + pci_read_config_word(dev, pos + PCI_MSI_DATA_32, &data); + } + msg->data = data; + } +} + +void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) +{ + struct pci_dev *dev = msi_desc_to_pci_dev(entry); + + if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev)) { + /* Don't touch the hardware now */ + } else if (entry->pci.msi_attrib.is_msix) { + void __iomem *base = pci_msix_desc_addr(entry); + u32 ctrl = entry->pci.msix_ctrl; + bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); + + if (entry->pci.msi_attrib.is_virtual) + goto skip; + + /* + * The specification mandates that the entry is masked + * when the message is modified: + * + * "If software changes the Address or Data value of an + * entry while the entry is unmasked, the result is + * undefined." + */ + if (unmasked) + pci_msix_write_vector_ctrl(entry, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT); + + writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR); + writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); + writel(msg->data, base + PCI_MSIX_ENTRY_DATA); + + if (unmasked) + pci_msix_write_vector_ctrl(entry, ctrl); + + /* Ensure that the writes are visible in the device */ + readl(base + PCI_MSIX_ENTRY_DATA); + } else { + int pos = dev->msi_cap; + u16 msgctl; + + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + msgctl &= ~PCI_MSI_FLAGS_QSIZE; + msgctl |= entry->pci.msi_attrib.multiple << 4; + pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl); + + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, + msg->address_lo); + if (entry->pci.msi_attrib.is_64) { + pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, + msg->address_hi); + pci_write_config_word(dev, pos + PCI_MSI_DATA_64, + msg->data); + } else { + pci_write_config_word(dev, pos + PCI_MSI_DATA_32, + msg->data); + } + /* Ensure that the writes are visible in the device */ + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl); + } + +skip: + entry->msg = *msg; + + if (entry->write_msi_msg) + entry->write_msi_msg(entry, entry->write_msi_msg_data); + +} + +void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) +{ + struct msi_desc *entry = irq_get_msi_desc(irq); + + __pci_write_msi_msg(entry, msg); +} +EXPORT_SYMBOL_GPL(pci_write_msi_msg); + +static void free_msi_irqs(struct pci_dev *dev) +{ + struct list_head *msi_list = dev_to_msi_list(&dev->dev); + struct msi_desc *entry, *tmp; + int i; + + for_each_pci_msi_entry(entry, dev) + if (entry->irq) + for (i = 0; i < entry->nvec_used; i++) + BUG_ON(irq_has_action(entry->irq + i)); + + if (dev->msi_irq_groups) { + msi_destroy_sysfs(&dev->dev, dev->msi_irq_groups); + dev->msi_irq_groups = NULL; + } + + pci_msi_teardown_msi_irqs(dev); + + list_for_each_entry_safe(entry, tmp, msi_list, list) { + if (entry->pci.msi_attrib.is_msix) { + if (list_is_last(&entry->list, msi_list)) + iounmap(entry->pci.mask_base); + } + + list_del(&entry->list); + free_msi_entry(entry); + } +} + +static void pci_intx_for_msi(struct pci_dev *dev, int enable) +{ + if (!(dev->dev_flags & PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG)) + pci_intx(dev, enable); +} + +static void pci_msi_set_enable(struct pci_dev *dev, int enable) +{ + u16 control; + + pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); + control &= ~PCI_MSI_FLAGS_ENABLE; + if (enable) + control |= PCI_MSI_FLAGS_ENABLE; + pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); +} + +/* + * Architecture override returns true when the PCI MSI message should be + * written by the generic restore function. + */ +bool __weak arch_restore_msi_irqs(struct pci_dev *dev) +{ + return true; +} + +static void __pci_restore_msi_state(struct pci_dev *dev) +{ + struct msi_desc *entry; + u16 control; + + if (!dev->msi_enabled) + return; + + entry = irq_get_msi_desc(dev->irq); + + pci_intx_for_msi(dev, 0); + pci_msi_set_enable(dev, 0); + if (arch_restore_msi_irqs(dev)) + __pci_write_msi_msg(entry, &entry->msg); + + pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); + pci_msi_update_mask(entry, 0, 0); + control &= ~PCI_MSI_FLAGS_QSIZE; + control |= (entry->pci.msi_attrib.multiple << 4) | PCI_MSI_FLAGS_ENABLE; + pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); +} + +static void pci_msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set) +{ + u16 ctrl; + + pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl); + ctrl &= ~clear; + ctrl |= set; + pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl); +} + +static void __pci_restore_msix_state(struct pci_dev *dev) +{ + struct msi_desc *entry; + bool write_msg; + + if (!dev->msix_enabled) + return; + BUG_ON(list_empty(dev_to_msi_list(&dev->dev))); + + /* route the table */ + pci_intx_for_msi(dev, 0); + pci_msix_clear_and_set_ctrl(dev, 0, + PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL); + + write_msg = arch_restore_msi_irqs(dev); + + for_each_pci_msi_entry(entry, dev) { + if (write_msg) + __pci_write_msi_msg(entry, &entry->msg); + pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl); + } + + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0); +} + +void pci_restore_msi_state(struct pci_dev *dev) +{ + __pci_restore_msi_state(dev); + __pci_restore_msix_state(dev); +} +EXPORT_SYMBOL_GPL(pci_restore_msi_state); + +static struct msi_desc * +msi_setup_entry(struct pci_dev *dev, int nvec, struct irq_affinity *affd) +{ + struct irq_affinity_desc *masks = NULL; + struct msi_desc *entry; + u16 control; + + if (affd) + masks = irq_create_affinity_masks(nvec, affd); + + /* MSI Entry Initialization */ + entry = alloc_msi_entry(&dev->dev, nvec, masks); + if (!entry) + goto out; + + pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); + /* Lies, damned lies, and MSIs */ + if (dev->dev_flags & PCI_DEV_FLAGS_HAS_MSI_MASKING) + control |= PCI_MSI_FLAGS_MASKBIT; + + entry->pci.msi_attrib.is_msix = 0; + entry->pci.msi_attrib.is_64 = !!(control & PCI_MSI_FLAGS_64BIT); + entry->pci.msi_attrib.is_virtual = 0; + entry->pci.msi_attrib.entry_nr = 0; + entry->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && + !!(control & PCI_MSI_FLAGS_MASKBIT); + entry->pci.msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ + entry->pci.msi_attrib.multi_cap = (control & PCI_MSI_FLAGS_QMASK) >> 1; + entry->pci.msi_attrib.multiple = ilog2(__roundup_pow_of_two(nvec)); + + if (control & PCI_MSI_FLAGS_64BIT) + entry->pci.mask_pos = dev->msi_cap + PCI_MSI_MASK_64; + else + entry->pci.mask_pos = dev->msi_cap + PCI_MSI_MASK_32; + + /* Save the initial mask status */ + if (entry->pci.msi_attrib.can_mask) + pci_read_config_dword(dev, entry->pci.mask_pos, &entry->pci.msi_mask); + +out: + kfree(masks); + return entry; +} + +static int msi_verify_entries(struct pci_dev *dev) +{ + struct msi_desc *entry; + + if (!dev->no_64bit_msi) + return 0; + + for_each_pci_msi_entry(entry, dev) { + if (entry->msg.address_hi) { + pci_err(dev, "arch assigned 64-bit MSI address %#x%08x but device only supports 32 bits\n", + entry->msg.address_hi, entry->msg.address_lo); + return -EIO; + } + } + return 0; +} + +/** + * msi_capability_init - configure device's MSI capability structure + * @dev: pointer to the pci_dev data structure of MSI device function + * @nvec: number of interrupts to allocate + * @affd: description of automatic IRQ affinity assignments (may be %NULL) + * + * Setup the MSI capability structure of the device with the requested + * number of interrupts. A return value of zero indicates the successful + * setup of an entry with the new MSI IRQ. A negative return value indicates + * an error, and a positive return value indicates the number of interrupts + * which could have been allocated. + */ +static int msi_capability_init(struct pci_dev *dev, int nvec, + struct irq_affinity *affd) +{ + const struct attribute_group **groups; + struct msi_desc *entry; + int ret; + + pci_msi_set_enable(dev, 0); /* Disable MSI during set up */ + + entry = msi_setup_entry(dev, nvec, affd); + if (!entry) + return -ENOMEM; + + /* All MSIs are unmasked by default; mask them all */ + pci_msi_mask(entry, msi_multi_mask(entry)); + + list_add_tail(&entry->list, dev_to_msi_list(&dev->dev)); + + /* Configure MSI capability structure */ + ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSI); + if (ret) + goto err; + + ret = msi_verify_entries(dev); + if (ret) + goto err; + + groups = msi_populate_sysfs(&dev->dev); + if (IS_ERR(groups)) { + ret = PTR_ERR(groups); + goto err; + } + + dev->msi_irq_groups = groups; + + /* Set MSI enabled bits */ + pci_intx_for_msi(dev, 0); + pci_msi_set_enable(dev, 1); + dev->msi_enabled = 1; + + pcibios_free_irq(dev); + dev->irq = entry->irq; + return 0; + +err: + pci_msi_unmask(entry, msi_multi_mask(entry)); + free_msi_irqs(dev); + return ret; +} + +static void __iomem *msix_map_region(struct pci_dev *dev, + unsigned int nr_entries) +{ + resource_size_t phys_addr; + u32 table_offset; + unsigned long flags; + u8 bir; + + pci_read_config_dword(dev, dev->msix_cap + PCI_MSIX_TABLE, + &table_offset); + bir = (u8)(table_offset & PCI_MSIX_TABLE_BIR); + flags = pci_resource_flags(dev, bir); + if (!flags || (flags & IORESOURCE_UNSET)) + return NULL; + + table_offset &= PCI_MSIX_TABLE_OFFSET; + phys_addr = pci_resource_start(dev, bir) + table_offset; + + return ioremap(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); +} + +static int msix_setup_entries(struct pci_dev *dev, void __iomem *base, + struct msix_entry *entries, int nvec, + struct irq_affinity *affd) +{ + struct irq_affinity_desc *curmsk, *masks = NULL; + struct msi_desc *entry; + void __iomem *addr; + int ret, i; + int vec_count = pci_msix_vec_count(dev); + + if (affd) + masks = irq_create_affinity_masks(nvec, affd); + + for (i = 0, curmsk = masks; i < nvec; i++) { + entry = alloc_msi_entry(&dev->dev, 1, curmsk); + if (!entry) { + if (!i) + iounmap(base); + else + free_msi_irqs(dev); + /* No enough memory. Don't try again */ + ret = -ENOMEM; + goto out; + } + + entry->pci.msi_attrib.is_msix = 1; + entry->pci.msi_attrib.is_64 = 1; + + if (entries) + entry->pci.msi_attrib.entry_nr = entries[i].entry; + else + entry->pci.msi_attrib.entry_nr = i; + + entry->pci.msi_attrib.is_virtual = + entry->pci.msi_attrib.entry_nr >= vec_count; + + entry->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && + !entry->pci.msi_attrib.is_virtual; + + entry->pci.msi_attrib.default_irq = dev->irq; + entry->pci.mask_base = base; + + if (entry->pci.msi_attrib.can_mask) { + addr = pci_msix_desc_addr(entry); + entry->pci.msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL); + } + + list_add_tail(&entry->list, dev_to_msi_list(&dev->dev)); + if (masks) + curmsk++; + } + ret = 0; +out: + kfree(masks); + return ret; +} + +static void msix_update_entries(struct pci_dev *dev, struct msix_entry *entries) +{ + struct msi_desc *entry; + + if (entries) { + for_each_pci_msi_entry(entry, dev) { + entries->vector = entry->irq; + entries++; + } + } +} + +static void msix_mask_all(void __iomem *base, int tsize) +{ + u32 ctrl = PCI_MSIX_ENTRY_CTRL_MASKBIT; + int i; + + if (pci_msi_ignore_mask) + return; + + for (i = 0; i < tsize; i++, base += PCI_MSIX_ENTRY_SIZE) + writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL); +} + +/** + * msix_capability_init - configure device's MSI-X capability + * @dev: pointer to the pci_dev data structure of MSI-X device function + * @entries: pointer to an array of struct msix_entry entries + * @nvec: number of @entries + * @affd: Optional pointer to enable automatic affinity assignment + * + * Setup the MSI-X capability structure of device function with a + * single MSI-X IRQ. A return of zero indicates the successful setup of + * requested MSI-X entries with allocated IRQs or non-zero for otherwise. + **/ +static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, + int nvec, struct irq_affinity *affd) +{ + const struct attribute_group **groups; + void __iomem *base; + int ret, tsize; + u16 control; + + /* + * Some devices require MSI-X to be enabled before the MSI-X + * registers can be accessed. Mask all the vectors to prevent + * interrupts coming in before they're fully set up. + */ + pci_msix_clear_and_set_ctrl(dev, 0, PCI_MSIX_FLAGS_MASKALL | + PCI_MSIX_FLAGS_ENABLE); + + pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); + /* Request & Map MSI-X table region */ + tsize = msix_table_size(control); + base = msix_map_region(dev, tsize); + if (!base) { + ret = -ENOMEM; + goto out_disable; + } + + /* Ensure that all table entries are masked. */ + msix_mask_all(base, tsize); + + ret = msix_setup_entries(dev, base, entries, nvec, affd); + if (ret) + goto out_disable; + + ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX); + if (ret) + goto out_avail; + + /* Check if all MSI entries honor device restrictions */ + ret = msi_verify_entries(dev); + if (ret) + goto out_free; + + msix_update_entries(dev, entries); + + groups = msi_populate_sysfs(&dev->dev); + if (IS_ERR(groups)) { + ret = PTR_ERR(groups); + goto out_free; + } + + dev->msi_irq_groups = groups; + + /* Set MSI-X enabled bits and unmask the function */ + pci_intx_for_msi(dev, 0); + dev->msix_enabled = 1; + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0); + + pcibios_free_irq(dev); + return 0; + +out_avail: + if (ret < 0) { + /* + * If we had some success, report the number of IRQs + * we succeeded in setting up. + */ + struct msi_desc *entry; + int avail = 0; + + for_each_pci_msi_entry(entry, dev) { + if (entry->irq != 0) + avail++; + } + if (avail != 0) + ret = avail; + } + +out_free: + free_msi_irqs(dev); + +out_disable: + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); + + return ret; +} + +/** + * pci_msi_supported - check whether MSI may be enabled on a device + * @dev: pointer to the pci_dev data structure of MSI device function + * @nvec: how many MSIs have been requested? + * + * Look at global flags, the device itself, and its parent buses + * to determine if MSI/-X are supported for the device. If MSI/-X is + * supported return 1, else return 0. + **/ +static int pci_msi_supported(struct pci_dev *dev, int nvec) +{ + struct pci_bus *bus; + + /* MSI must be globally enabled and supported by the device */ + if (!pci_msi_enable) + return 0; + + if (!dev || dev->no_msi) + return 0; + + /* + * You can't ask to have 0 or less MSIs configured. + * a) it's stupid .. + * b) the list manipulation code assumes nvec >= 1. + */ + if (nvec < 1) + return 0; + + /* + * Any bridge which does NOT route MSI transactions from its + * secondary bus to its primary bus must set NO_MSI flag on + * the secondary pci_bus. + * + * The NO_MSI flag can either be set directly by: + * - arch-specific PCI host bus controller drivers (deprecated) + * - quirks for specific PCI bridges + * + * or indirectly by platform-specific PCI host bridge drivers by + * advertising the 'msi_domain' property, which results in + * the NO_MSI flag when no MSI domain is found for this bridge + * at probe time. + */ + for (bus = dev->bus; bus; bus = bus->parent) + if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI) + return 0; + + return 1; +} + +/** + * pci_msi_vec_count - Return the number of MSI vectors a device can send + * @dev: device to report about + * + * This function returns the number of MSI vectors a device requested via + * Multiple Message Capable register. It returns a negative errno if the + * device is not capable sending MSI interrupts. Otherwise, the call succeeds + * and returns a power of two, up to a maximum of 2^5 (32), according to the + * MSI specification. + **/ +int pci_msi_vec_count(struct pci_dev *dev) +{ + int ret; + u16 msgctl; + + if (!dev->msi_cap) + return -EINVAL; + + pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl); + ret = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK) >> 1); + + return ret; +} +EXPORT_SYMBOL(pci_msi_vec_count); + +static void pci_msi_shutdown(struct pci_dev *dev) +{ + struct msi_desc *desc; + + if (!pci_msi_enable || !dev || !dev->msi_enabled) + return; + + BUG_ON(list_empty(dev_to_msi_list(&dev->dev))); + desc = first_pci_msi_entry(dev); + + pci_msi_set_enable(dev, 0); + pci_intx_for_msi(dev, 1); + dev->msi_enabled = 0; + + /* Return the device with MSI unmasked as initial states */ + pci_msi_unmask(desc, msi_multi_mask(desc)); + + /* Restore dev->irq to its default pin-assertion IRQ */ + dev->irq = desc->pci.msi_attrib.default_irq; + pcibios_alloc_irq(dev); +} + +void pci_disable_msi(struct pci_dev *dev) +{ + if (!pci_msi_enable || !dev || !dev->msi_enabled) + return; + + pci_msi_shutdown(dev); + free_msi_irqs(dev); +} +EXPORT_SYMBOL(pci_disable_msi); + +/** + * pci_msix_vec_count - return the number of device's MSI-X table entries + * @dev: pointer to the pci_dev data structure of MSI-X device function + * This function returns the number of device's MSI-X table entries and + * therefore the number of MSI-X vectors device is capable of sending. + * It returns a negative errno if the device is not capable of sending MSI-X + * interrupts. + **/ +int pci_msix_vec_count(struct pci_dev *dev) +{ + u16 control; + + if (!dev->msix_cap) + return -EINVAL; + + pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); + return msix_table_size(control); +} +EXPORT_SYMBOL(pci_msix_vec_count); + +static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, + int nvec, struct irq_affinity *affd, int flags) +{ + int nr_entries; + int i, j; + + if (!pci_msi_supported(dev, nvec) || dev->current_state != PCI_D0) + return -EINVAL; + + nr_entries = pci_msix_vec_count(dev); + if (nr_entries < 0) + return nr_entries; + if (nvec > nr_entries && !(flags & PCI_IRQ_VIRTUAL)) + return nr_entries; + + if (entries) { + /* Check for any invalid entries */ + for (i = 0; i < nvec; i++) { + if (entries[i].entry >= nr_entries) + return -EINVAL; /* invalid entry */ + for (j = i + 1; j < nvec; j++) { + if (entries[i].entry == entries[j].entry) + return -EINVAL; /* duplicate entry */ + } + } + } + + /* Check whether driver already requested for MSI IRQ */ + if (dev->msi_enabled) { + pci_info(dev, "can't enable MSI-X (MSI IRQ already assigned)\n"); + return -EINVAL; + } + return msix_capability_init(dev, entries, nvec, affd); +} + +static void pci_msix_shutdown(struct pci_dev *dev) +{ + struct msi_desc *entry; + + if (!pci_msi_enable || !dev || !dev->msix_enabled) + return; + + if (pci_dev_is_disconnected(dev)) { + dev->msix_enabled = 0; + return; + } + + /* Return the device with MSI-X masked as initial states */ + for_each_pci_msi_entry(entry, dev) + pci_msix_mask(entry); + + pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_ENABLE, 0); + pci_intx_for_msi(dev, 1); + dev->msix_enabled = 0; + pcibios_alloc_irq(dev); +} + +void pci_disable_msix(struct pci_dev *dev) +{ + if (!pci_msi_enable || !dev || !dev->msix_enabled) + return; + + pci_msix_shutdown(dev); + free_msi_irqs(dev); +} +EXPORT_SYMBOL(pci_disable_msix); + +void pci_no_msi(void) +{ + pci_msi_enable = 0; +} + +/** + * pci_msi_enabled - is MSI enabled? + * + * Returns true if MSI has not been disabled by the command-line option + * pci=nomsi. + **/ +int pci_msi_enabled(void) +{ + return pci_msi_enable; +} +EXPORT_SYMBOL(pci_msi_enabled); + +static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, + struct irq_affinity *affd) +{ + int nvec; + int rc; + + if (!pci_msi_supported(dev, minvec) || dev->current_state != PCI_D0) + return -EINVAL; + + /* Check whether driver already requested MSI-X IRQs */ + if (dev->msix_enabled) { + pci_info(dev, "can't enable MSI (MSI-X already enabled)\n"); + return -EINVAL; + } + + if (maxvec < minvec) + return -ERANGE; + + if (WARN_ON_ONCE(dev->msi_enabled)) + return -EINVAL; + + nvec = pci_msi_vec_count(dev); + if (nvec < 0) + return nvec; + if (nvec < minvec) + return -ENOSPC; + + if (nvec > maxvec) + nvec = maxvec; + + for (;;) { + if (affd) { + nvec = irq_calc_affinity_vectors(minvec, nvec, affd); + if (nvec < minvec) + return -ENOSPC; + } + + rc = msi_capability_init(dev, nvec, affd); + if (rc == 0) + return nvec; + + if (rc < 0) + return rc; + if (rc < minvec) + return -ENOSPC; + + nvec = rc; + } +} + +/* deprecated, don't use */ +int pci_enable_msi(struct pci_dev *dev) +{ + int rc = __pci_enable_msi_range(dev, 1, 1, NULL); + if (rc < 0) + return rc; + return 0; +} +EXPORT_SYMBOL(pci_enable_msi); + +static int __pci_enable_msix_range(struct pci_dev *dev, + struct msix_entry *entries, int minvec, + int maxvec, struct irq_affinity *affd, + int flags) +{ + int rc, nvec = maxvec; + + if (maxvec < minvec) + return -ERANGE; + + if (WARN_ON_ONCE(dev->msix_enabled)) + return -EINVAL; + + for (;;) { + if (affd) { + nvec = irq_calc_affinity_vectors(minvec, nvec, affd); + if (nvec < minvec) + return -ENOSPC; + } + + rc = __pci_enable_msix(dev, entries, nvec, affd, flags); + if (rc == 0) + return nvec; + + if (rc < 0) + return rc; + if (rc < minvec) + return -ENOSPC; + + nvec = rc; + } +} + +/** + * pci_enable_msix_range - configure device's MSI-X capability structure + * @dev: pointer to the pci_dev data structure of MSI-X device function + * @entries: pointer to an array of MSI-X entries + * @minvec: minimum number of MSI-X IRQs requested + * @maxvec: maximum number of MSI-X IRQs requested + * + * Setup the MSI-X capability structure of device function with a maximum + * possible number of interrupts in the range between @minvec and @maxvec + * upon its software driver call to request for MSI-X mode enabled on its + * hardware device function. It returns a negative errno if an error occurs. + * If it succeeds, it returns the actual number of interrupts allocated and + * indicates the successful configuration of MSI-X capability structure + * with new allocated MSI-X interrupts. + **/ +int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, + int minvec, int maxvec) +{ + return __pci_enable_msix_range(dev, entries, minvec, maxvec, NULL, 0); +} +EXPORT_SYMBOL(pci_enable_msix_range); + +/** + * pci_alloc_irq_vectors_affinity - allocate multiple IRQs for a device + * @dev: PCI device to operate on + * @min_vecs: minimum number of vectors required (must be >= 1) + * @max_vecs: maximum (desired) number of vectors + * @flags: flags or quirks for the allocation + * @affd: optional description of the affinity requirements + * + * Allocate up to @max_vecs interrupt vectors for @dev, using MSI-X or MSI + * vectors if available, and fall back to a single legacy vector + * if neither is available. Return the number of vectors allocated, + * (which might be smaller than @max_vecs) if successful, or a negative + * error code on error. If less than @min_vecs interrupt vectors are + * available for @dev the function will fail with -ENOSPC. + * + * To get the Linux IRQ number used for a vector that can be passed to + * request_irq() use the pci_irq_vector() helper. + */ +int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs, + unsigned int max_vecs, unsigned int flags, + struct irq_affinity *affd) +{ + struct irq_affinity msi_default_affd = {0}; + int nvecs = -ENOSPC; + + if (flags & PCI_IRQ_AFFINITY) { + if (!affd) + affd = &msi_default_affd; + } else { + if (WARN_ON(affd)) + affd = NULL; + } + + if (flags & PCI_IRQ_MSIX) { + nvecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, + affd, flags); + if (nvecs > 0) + return nvecs; + } + + if (flags & PCI_IRQ_MSI) { + nvecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd); + if (nvecs > 0) + return nvecs; + } + + /* use legacy IRQ if allowed */ + if (flags & PCI_IRQ_LEGACY) { + if (min_vecs == 1 && dev->irq) { + /* + * Invoke the affinity spreading logic to ensure that + * the device driver can adjust queue configuration + * for the single interrupt case. + */ + if (affd) + irq_create_affinity_masks(1, affd); + pci_intx(dev, 1); + return 1; + } + } + + return nvecs; +} +EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity); + +/** + * pci_free_irq_vectors - free previously allocated IRQs for a device + * @dev: PCI device to operate on + * + * Undoes the allocations and enabling in pci_alloc_irq_vectors(). + */ +void pci_free_irq_vectors(struct pci_dev *dev) +{ + pci_disable_msix(dev); + pci_disable_msi(dev); +} +EXPORT_SYMBOL(pci_free_irq_vectors); + +/** + * pci_irq_vector - return Linux IRQ number of a device vector + * @dev: PCI device to operate on + * @nr: Interrupt vector index (0-based) + * + * @nr has the following meanings depending on the interrupt mode: + * MSI-X: The index in the MSI-X vector table + * MSI: The index of the enabled MSI vectors + * INTx: Must be 0 + * + * Return: The Linux interrupt number or -EINVAl if @nr is out of range. + */ +int pci_irq_vector(struct pci_dev *dev, unsigned int nr) +{ + if (dev->msix_enabled) { + struct msi_desc *entry; + + for_each_pci_msi_entry(entry, dev) { + if (entry->pci.msi_attrib.entry_nr == nr) + return entry->irq; + } + WARN_ON_ONCE(1); + return -EINVAL; + } + + if (dev->msi_enabled) { + struct msi_desc *entry = first_pci_msi_entry(dev); + + if (WARN_ON_ONCE(nr >= entry->nvec_used)) + return -EINVAL; + } else { + if (WARN_ON_ONCE(nr > 0)) + return -EINVAL; + } + + return dev->irq + nr; +} +EXPORT_SYMBOL(pci_irq_vector); + +/** + * pci_irq_get_affinity - return the affinity of a particular MSI vector + * @dev: PCI device to operate on + * @nr: device-relative interrupt vector index (0-based). + * + * @nr has the following meanings depending on the interrupt mode: + * MSI-X: The index in the MSI-X vector table + * MSI: The index of the enabled MSI vectors + * INTx: Must be 0 + * + * Return: A cpumask pointer or NULL if @nr is out of range + */ +const struct cpumask *pci_irq_get_affinity(struct pci_dev *dev, int nr) +{ + if (dev->msix_enabled) { + struct msi_desc *entry; + + for_each_pci_msi_entry(entry, dev) { + if (entry->pci.msi_attrib.entry_nr == nr) + return &entry->affinity->mask; + } + WARN_ON_ONCE(1); + return NULL; + } else if (dev->msi_enabled) { + struct msi_desc *entry = first_pci_msi_entry(dev); + + if (WARN_ON_ONCE(!entry || !entry->affinity || + nr >= entry->nvec_used)) + return NULL; + + return &entry->affinity[nr].mask; + } else { + return cpu_possible_mask; + } +} +EXPORT_SYMBOL(pci_irq_get_affinity); + +struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc) +{ + return to_pci_dev(desc->dev); +} +EXPORT_SYMBOL(msi_desc_to_pci_dev); + +#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN +/** + * pci_msi_domain_write_msg - Helper to write MSI message to PCI config space + * @irq_data: Pointer to interrupt data of the MSI interrupt + * @msg: Pointer to the message + */ +static void pci_msi_domain_write_msg(struct irq_data *irq_data, struct msi_msg *msg) +{ + struct msi_desc *desc = irq_data_get_msi_desc(irq_data); + + /* + * For MSI-X desc->irq is always equal to irq_data->irq. For + * MSI only the first interrupt of MULTI MSI passes the test. + */ + if (desc->irq == irq_data->irq) + __pci_write_msi_msg(desc, msg); +} + +/** + * pci_msi_domain_calc_hwirq - Generate a unique ID for an MSI source + * @desc: Pointer to the MSI descriptor + * + * The ID number is only used within the irqdomain. + */ +static irq_hw_number_t pci_msi_domain_calc_hwirq(struct msi_desc *desc) +{ + struct pci_dev *dev = msi_desc_to_pci_dev(desc); + + return (irq_hw_number_t)desc->pci.msi_attrib.entry_nr | + pci_dev_id(dev) << 11 | + (pci_domain_nr(dev->bus) & 0xFFFFFFFF) << 27; +} + +static inline bool pci_msi_desc_is_multi_msi(struct msi_desc *desc) +{ + return !desc->pci.msi_attrib.is_msix && desc->nvec_used > 1; +} + +/** + * pci_msi_domain_check_cap - Verify that @domain supports the capabilities + * for @dev + * @domain: The interrupt domain to check + * @info: The domain info for verification + * @dev: The device to check + * + * Returns: + * 0 if the functionality is supported + * 1 if Multi MSI is requested, but the domain does not support it + * -ENOTSUPP otherwise + */ +int pci_msi_domain_check_cap(struct irq_domain *domain, + struct msi_domain_info *info, struct device *dev) +{ + struct msi_desc *desc = first_pci_msi_entry(to_pci_dev(dev)); + + /* Special handling to support __pci_enable_msi_range() */ + if (pci_msi_desc_is_multi_msi(desc) && + !(info->flags & MSI_FLAG_MULTI_PCI_MSI)) + return 1; + else if (desc->pci.msi_attrib.is_msix && !(info->flags & MSI_FLAG_PCI_MSIX)) + return -ENOTSUPP; + + return 0; +} + +static int pci_msi_domain_handle_error(struct irq_domain *domain, + struct msi_desc *desc, int error) +{ + /* Special handling to support __pci_enable_msi_range() */ + if (pci_msi_desc_is_multi_msi(desc) && error == -ENOSPC) + return 1; + + return error; +} + +static void pci_msi_domain_set_desc(msi_alloc_info_t *arg, + struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq = pci_msi_domain_calc_hwirq(desc); +} + +static struct msi_domain_ops pci_msi_domain_ops_default = { + .set_desc = pci_msi_domain_set_desc, + .msi_check = pci_msi_domain_check_cap, + .handle_error = pci_msi_domain_handle_error, +}; + +static void pci_msi_domain_update_dom_ops(struct msi_domain_info *info) +{ + struct msi_domain_ops *ops = info->ops; + + if (ops == NULL) { + info->ops = &pci_msi_domain_ops_default; + } else { + if (ops->set_desc == NULL) + ops->set_desc = pci_msi_domain_set_desc; + if (ops->msi_check == NULL) + ops->msi_check = pci_msi_domain_check_cap; + if (ops->handle_error == NULL) + ops->handle_error = pci_msi_domain_handle_error; + } +} + +static void pci_msi_domain_update_chip_ops(struct msi_domain_info *info) +{ + struct irq_chip *chip = info->chip; + + BUG_ON(!chip); + if (!chip->irq_write_msi_msg) + chip->irq_write_msi_msg = pci_msi_domain_write_msg; + if (!chip->irq_mask) + chip->irq_mask = pci_msi_mask_irq; + if (!chip->irq_unmask) + chip->irq_unmask = pci_msi_unmask_irq; +} + +/** + * pci_msi_create_irq_domain - Create a MSI interrupt domain + * @fwnode: Optional fwnode of the interrupt controller + * @info: MSI domain info + * @parent: Parent irq domain + * + * Updates the domain and chip ops and creates a MSI interrupt domain. + * + * Returns: + * A domain pointer or NULL in case of failure. + */ +struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode, + struct msi_domain_info *info, + struct irq_domain *parent) +{ + struct irq_domain *domain; + + if (WARN_ON(info->flags & MSI_FLAG_LEVEL_CAPABLE)) + info->flags &= ~MSI_FLAG_LEVEL_CAPABLE; + + if (info->flags & MSI_FLAG_USE_DEF_DOM_OPS) + pci_msi_domain_update_dom_ops(info); + if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS) + pci_msi_domain_update_chip_ops(info); + + info->flags |= MSI_FLAG_ACTIVATE_EARLY; + if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE)) + info->flags |= MSI_FLAG_MUST_REACTIVATE; + + /* PCI-MSI is oneshot-safe */ + info->chip->flags |= IRQCHIP_ONESHOT_SAFE; + + domain = msi_create_irq_domain(fwnode, info, parent); + if (!domain) + return NULL; + + irq_domain_update_bus_token(domain, DOMAIN_BUS_PCI_MSI); + return domain; +} +EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain); + +/* + * Users of the generic MSI infrastructure expect a device to have a single ID, + * so with DMA aliases we have to pick the least-worst compromise. Devices with + * DMA phantom functions tend to still emit MSIs from the real function number, + * so we ignore those and only consider topological aliases where either the + * alias device or RID appears on a different bus number. We also make the + * reasonable assumption that bridges are walked in an upstream direction (so + * the last one seen wins), and the much braver assumption that the most likely + * case is that of PCI->PCIe so we should always use the alias RID. This echoes + * the logic from intel_irq_remapping's set_msi_sid(), which presumably works + * well enough in practice; in the face of the horrible PCIe<->PCI-X conditions + * for taking ownership all we can really do is close our eyes and hope... + */ +static int get_msi_id_cb(struct pci_dev *pdev, u16 alias, void *data) +{ + u32 *pa = data; + u8 bus = PCI_BUS_NUM(*pa); + + if (pdev->bus->number != bus || PCI_BUS_NUM(alias) != bus) + *pa = alias; + + return 0; +} + +/** + * pci_msi_domain_get_msi_rid - Get the MSI requester id (RID) + * @domain: The interrupt domain + * @pdev: The PCI device. + * + * The RID for a device is formed from the alias, with a firmware + * supplied mapping applied + * + * Returns: The RID. + */ +u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev) +{ + struct device_node *of_node; + u32 rid = pci_dev_id(pdev); + + pci_for_each_dma_alias(pdev, get_msi_id_cb, &rid); + + of_node = irq_domain_get_of_node(domain); + rid = of_node ? of_msi_map_id(&pdev->dev, of_node, rid) :Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: [patch V2 16/23] PCI/MSI: Split out CONFIG_PCI_MSI independent part
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
These functions are required even when
CONFIG_PCI_MSIis not set. Move them to their own file.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 114 lines
--- drivers/pci/msi/Makefile | 3 ++- drivers/pci/msi/msi.c | 39 --------------------------------------- drivers/pci/msi/pcidev_msi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 40 deletions(-)drivers/pci/msi/Makefile +2
-1@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.odrivers/pci/msi/msi.c +0
-39@@ -18,8 +18,6 @@#include "../pci.h" -#ifdef CONFIG_PCI_MSI -static int pci_msi_enable =1 ;int pci_msi_ignore_mask;@@ -1493,40 +1491,3 @@ bool pci_dev_has_special_msi_domain(stru }#endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ -#endif /* CONFIG_PCI_MSI */ - -void pci_msi_init (struct pci_dev *dev) -{ -u16 ctrl; - -/* -* Disable the MSI hardware to avoid screaming interrupts -* during boot. This is the power on reset default so -* usually this should be a noop. -*/ - dev->msi_cap =pci_find_capability (dev,PCI_CAP_ID_MSI ); -if (!dev->msi_cap) -return ; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &ctrl); -if (ctrl &PCI_MSI_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , - ctrl & ~PCI_MSI_FLAGS_ENABLE ); - -if (!(ctrl &PCI_MSI_FLAGS_64BIT )) - dev->no_64bit_msi =1 ; -} - -void pci_msix_init (struct pci_dev *dev) -{ -u16 ctrl; - - dev->msix_cap =pci_find_capability (dev,PCI_CAP_ID_MSIX ); -if (!dev->msix_cap) -return ; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); -if (ctrl &PCI_MSIX_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , - ctrl & ~PCI_MSIX_FLAGS_ENABLE ); -}drivers/pci/msi/pcidev_msi.c new file +43
-0@@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* MSI[X} related functions which are available unconditionally. +*/ +#include "../pci.h" + +/* +* Disable the MSI[X] hardware to avoid screaming interrupts during boot. +* This is the power on reset default so usually this should be a noop. +*/ + +void pci_msi_init (struct pci_dev *dev) +{ +u16 ctrl; + + dev->msi_cap =pci_find_capability (dev,PCI_CAP_ID_MSI ); +if (!dev->msi_cap) +return ; + +pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &ctrl); +if (ctrl &PCI_MSI_FLAGS_ENABLE ) { +pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , + ctrl & ~PCI_MSI_FLAGS_ENABLE ); + } + +if (!(ctrl &PCI_MSI_FLAGS_64BIT )) + dev->no_64bit_msi =1 ; +} + +void pci_msix_init (struct pci_dev *dev) +{ +u16 ctrl; + + dev->msix_cap =pci_find_capability (dev,PCI_CAP_ID_MSIX ); +if (!dev->msix_cap) +return ; + +pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); +if (ctrl &PCI_MSIX_FLAGS_ENABLE ) { +pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , + ctrl & ~PCI_MSIX_FLAGS_ENABLE ); + } +}
Re: [patch V2 17/23] PCI/MSI: Split out !IRQDOMAIN code
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
Split out the non irqdomain code into its own file.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 130 lines
---
V2: Add proper includes and fix variable name - Cedric--- drivers/pci/msi/Makefile | 5 ++-- drivers/pci/msi/legacy.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/msi/msi.c | 46 ----------------------------------------- 3 files changed, 55 insertions(+), 48 deletions(-)drivers/pci/msi/Makefile +3
-2@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += pcidev_msi.o -obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.odrivers/pci/msi/legacy.c new file +52
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* PCI Message Signaled Interrupt (MSI). +* +* Legacy architecture specific setup and teardown mechanism. +*/ +#include <linux/msi.h> +#include <linux/pci.h> + +/* Arch hooks */ +int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc) +{ +return -EINVAL ; +} + +void __weak arch_teardown_msi_irq (unsigned int irq) +{ +} + +int __weak arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +struct msi_desc *desc; +int ret; + +/* +* If an architecture wants to support multiple MSI, it needs to +* override arch_setup_msi_irqs() +*/ +if (type ==PCI_CAP_ID_MSI && nvec >1 ) +return 1 ; + +for_each_pci_msi_entry (desc, dev) { + ret =arch_setup_msi_irq (dev, desc); +if (ret) +return ret <0 ? ret : -ENOSPC ; + } + +return 0 ; +} + +void __weak arch_teardown_msi_irqs (struct pci_dev *dev) +{ +struct msi_desc *desc; +int i; + +for_each_pci_msi_entry (desc, dev) { +if (desc->irq) { +for (i =0 ; i < desc->nvec_used; i++) +arch_teardown_msi_irq (desc->irq + i); + } + } +}drivers/pci/msi/msi.c +0
-46@@ -50,52 +50,6 @@ static void pci_msi_teardown_msi_irqs(st#define pci_msi_teardown_msi_irqs arch_teardown_msi_irqs#endif -#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS -/* Arch hooks */ -int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc) -{ -return -EINVAL ; -} - -void __weak arch_teardown_msi_irq (unsigned int irq) -{ -} - -int __weak arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct msi_desc *entry; -int ret; - -/* -* If an architecture wants to support multiple MSI, it needs to -* override arch_setup_msi_irqs() -*/ -if (type ==PCI_CAP_ID_MSI && nvec >1 ) -return 1 ; - -for_each_pci_msi_entry (entry, dev) { - ret =arch_setup_msi_irq (dev, entry); -if (ret <0 ) -return ret; -if (ret >0 ) -return -ENOSPC ; - } - -return 0 ; -} - -void __weak arch_teardown_msi_irqs (struct pci_dev *dev) -{ -int i; -struct msi_desc *entry; - -for_each_pci_msi_entry (entry, dev) -if (entry->irq) -for (i =0 ; i < entry->nvec_used; i++) -arch_teardown_msi_irq (entry->irq + i); -} -#endif /* CONFIG_PCI_MSI_ARCH_FALLBACKS */ -/* * PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to * mask all MSI interrupts by clearing the MSI enable bit does not work
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 18/23] PCI/MSI: Split out irqdomain code
In reply to Thomas GleixnerQuoted 1 line · Thomas Gleixner
Move the irqdomain specific code into it's own file.
s/it's/its/
Quoted 3 lines
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 743 lines
--- drivers/pci/msi/Makefile | 1 drivers/pci/msi/irqdomain.c | 279 ++++++++++++++++++++++++++++++++++++++ drivers/pci/msi/legacy.c | 13 + drivers/pci/msi/msi.c | 319 +------------------------------------------- drivers/pci/msi/msi.h | 39 +++++ include/linux/msi.h | 11 - 6 files changed, 340 insertions(+), 322 deletions(-)drivers/pci/msi/Makefile +1
-0@@ -3,4 +3,5 @@ # Makefile for the PCI/MSI obj-$(CONFIG_PCI) += pcidev_msi.o obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_IRQ_DOMAIN) += irqdomain.o obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.odrivers/pci/msi/irqdomain.c new file +279
-0@@ -0,0 +1,279 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* PCI Message Signaled Interrupt (MSI) - irqdomain support +*/ +#include <linux/acpi_iort.h> +#include <linux/irqdomain.h> +#include <linux/of_irq.h> + +#include "msi.h" + +int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +struct irq_domain *domain; + + domain =dev_get_msi_domain (&dev->dev); +if (domain &&irq_domain_is_hierarchy (domain)) +return msi_domain_alloc_irqs (domain, &dev->dev, nvec); + +return pci_msi_legacy_setup_msi_irqs (dev, nvec, type); +} + +void pci_msi_teardown_msi_irqs (struct pci_dev *dev) +{ +struct irq_domain *domain; + + domain =dev_get_msi_domain (&dev->dev); +if (domain &&irq_domain_is_hierarchy (domain)) +msi_domain_free_irqs (domain, &dev->dev); +else +pci_msi_legacy_teardown_msi_irqs (dev); +} + +/** +* pci_msi_domain_write_msg - Helper to write MSI message to PCI config space +* @irq_data: Pointer to interrupt data of the MSI interrupt +* @msg: Pointer to the message +*/ +static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) +{ +struct msi_desc *desc =irq_data_get_msi_desc (irq_data); + +/* +* For MSI-X desc->irq is always equal to irq_data->irq. For +* MSI only the first interrupt of MULTI MSI passes the test. +*/ +if (desc->irq == irq_data->irq) +__pci_write_msi_msg (desc, msg); +} + +/** +* pci_msi_domain_calc_hwirq - Generate a unique ID for an MSI source +* @desc: Pointer to the MSI descriptor +* +* The ID number is only used within the irqdomain. +*/ +static irq_hw_number_t pci_msi_domain_calc_hwirq (struct msi_desc *desc) +{ +struct pci_dev *dev =msi_desc_to_pci_dev (desc); + +return (irq_hw_number_t )desc->pci.msi_attrib.entry_nr | +pci_dev_id (dev) <<11 | + (pci_domain_nr (dev->bus) &0xFFFFFFFF ) <<27 ; +} + +static inline bool pci_msi_desc_is_multi_msi (struct msi_desc *desc) +{ +return !desc->pci.msi_attrib.is_msix && desc->nvec_used >1 ; +} + +/** +* pci_msi_domain_check_cap - Verify that @domain supports the capabilities +* for @dev +* @domain: The interrupt domain to check +* @info: The domain info for verification +* @dev: The device to check +* +* Returns: +* 0 if the functionality is supported +* 1 if Multi MSI is requested, but the domain does not support it +* -ENOTSUPP otherwise +*/ +int pci_msi_domain_check_cap (struct irq_domain *domain, +struct msi_domain_info *info,struct device *dev) +{ +struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev)); + +/* Special handling to support __pci_enable_msi_range() */ +if (pci_msi_desc_is_multi_msi (desc) && + !(info->flags &MSI_FLAG_MULTI_PCI_MSI )) +return 1 ; +else if (desc->pci.msi_attrib.is_msix && !(info->flags &MSI_FLAG_PCI_MSIX )) +return -ENOTSUPP ; + +return 0 ; +} + +static int pci_msi_domain_handle_error (struct irq_domain *domain, +struct msi_desc *desc,int error) +{ +/* Special handling to support __pci_enable_msi_range() */ +if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) +return 1 ; + +return error; +} + +static void pci_msi_domain_set_desc (msi_alloc_info_t *arg, +struct msi_desc *desc) +{ + arg->desc = desc; + arg->hwirq =pci_msi_domain_calc_hwirq (desc); +} + +static struct msi_domain_ops pci_msi_domain_ops_default = { + .set_desc = pci_msi_domain_set_desc, + .msi_check = pci_msi_domain_check_cap, + .handle_error = pci_msi_domain_handle_error, +}; + +static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info) +{ +struct msi_domain_ops *ops = info->ops; + +if (ops ==NULL ) { + info->ops = &pci_msi_domain_ops_default; + }else { +if (ops->set_desc ==NULL ) + ops->set_desc = pci_msi_domain_set_desc; +if (ops->msi_check ==NULL ) + ops->msi_check = pci_msi_domain_check_cap; +if (ops->handle_error ==NULL ) + ops->handle_error = pci_msi_domain_handle_error; + } +} + +static void pci_msi_domain_update_chip_ops (struct msi_domain_info *info) +{ +struct irq_chip *chip = info->chip; + +BUG_ON (!chip); +if (!chip->irq_write_msi_msg) + chip->irq_write_msi_msg = pci_msi_domain_write_msg; +if (!chip->irq_mask) + chip->irq_mask = pci_msi_mask_irq; +if (!chip->irq_unmask) + chip->irq_unmask = pci_msi_unmask_irq; +} + +/** +* pci_msi_create_irq_domain - Create a MSI interrupt domain +* @fwnode: Optional fwnode of the interrupt controller +* @info: MSI domain info +* @parent: Parent irq domain +* +* Updates the domain and chip ops and creates a MSI interrupt domain. +* +* Returns: +* A domain pointer or NULL in case of failure. +*/ +struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode, +struct msi_domain_info *info, +struct irq_domain *parent) +{ +struct irq_domain *domain; + +if (WARN_ON (info->flags &MSI_FLAG_LEVEL_CAPABLE )) + info->flags &= ~MSI_FLAG_LEVEL_CAPABLE ; + +if (info->flags &MSI_FLAG_USE_DEF_DOM_OPS ) +pci_msi_domain_update_dom_ops (info); +if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS ) +pci_msi_domain_update_chip_ops (info); + + info->flags |=MSI_FLAG_ACTIVATE_EARLY ; +if (IS_ENABLED (CONFIG_GENERIC_IRQ_RESERVATION_MODE )) + info->flags |=MSI_FLAG_MUST_REACTIVATE ; + +/* PCI-MSI is oneshot-safe */ + info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; + + domain =msi_create_irq_domain (fwnode, info, parent); +if (!domain) +return NULL ; + +irq_domain_update_bus_token (domain,DOMAIN_BUS_PCI_MSI ); +return domain; +} +EXPORT_SYMBOL_GPL (pci_msi_create_irq_domain); + +/* +* Users of the generic MSI infrastructure expect a device to have a single ID, +* so with DMA aliases we have to pick the least-worst compromise. Devices with +* DMA phantom functions tend to still emit MSIs from the real function number, +* so we ignore those and only consider topological aliases where either the +* alias device or RID appears on a different bus number. We also make the +* reasonable assumption that bridges are walked in an upstream direction (so +* the last one seen wins), and the much braver assumption that the most likely +* case is that of PCI->PCIe so we should always use the alias RID. This echoes +* the logic from intel_irq_remapping's set_msi_sid(), which presumably works +* well enough in practice; in the face of the horrible PCIe<->PCI-X conditions +* for taking ownership all we can really do is close our eyes and hope... +*/ +static int get_msi_id_cb (struct pci_dev *pdev,u16 alias,void *data) +{ +u32 *pa = data; +u8 bus =PCI_BUS_NUM (*pa); + +if (pdev->bus->number != bus ||PCI_BUS_NUM (alias) != bus) + *pa = alias; + +return 0 ; +} + +/** +* pci_msi_domain_get_msi_rid - Get the MSI requester id (RID) +* @domain: The interrupt domain +* @pdev: The PCI device. +* +* The RID for a device is formed from the alias, with a firmware +* supplied mapping applied +* +* Returns: The RID. +*/ +u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev) +{ +struct device_node *of_node; +u32 rid =pci_dev_id (pdev); + +pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); + + of_node =irq_domain_get_of_node (domain); + rid = of_node ?of_msi_map_id (&pdev->dev, of_node, rid) : +iort_msi_map_id (&pdev->dev, rid); + +return rid; +} + +/** +* pci_msi_get_device_domain - Get the MSI domain for a given PCI device +* @pdev: The PCI device +* +* Use the firmware data to find a device-specific MSI domain +* (i.e. not one that is set as a default). +* +* Returns: The corresponding MSI domain or NULL if none has been found. +*/ +struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev) +{ +struct irq_domain *dom; +u32 rid =pci_dev_id (pdev); + +pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); + dom =of_msi_map_get_device_domain (&pdev->dev, rid,DOMAIN_BUS_PCI_MSI ); +if (!dom) + dom =iort_get_device_domain (&pdev->dev, rid, +DOMAIN_BUS_PCI_MSI ); +return dom; +} + +/** +* pci_dev_has_special_msi_domain - Check whether the device is handled by +* a non-standard PCI-MSI domain +* @pdev: The PCI device to check. +* +* Returns: True if the device irqdomain or the bus irqdomain is +* non-standard PCI/MSI. +*/ +bool pci_dev_has_special_msi_domain (struct pci_dev *pdev) +{ +struct irq_domain *dom =dev_get_msi_domain (&pdev->dev); + +if (!dom) + dom =dev_get_msi_domain (&pdev->bus->dev); + +if (!dom) +return true; + +return dom->bus_token !=DOMAIN_BUS_PCI_MSI ; +}drivers/pci/msi/legacy.c +11
-2@@ -4,8 +4,7 @@* * Legacy architecture specific setup and teardown mechanism. */ -#include <linux/msi.h> -#include <linux/pci.h> +#include "msi.h" /* Arch hooks */ int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc)@@ -50,3 +49,13 @@ void __weak arch_teardown_msi_irqs(struc } } } + +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +return arch_setup_msi_irqs (dev, nvec, type); +} + +void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +arch_teardown_msi_irqs (dev); +}drivers/pci/msi/msi.c +10
-309@@ -6,64 +6,16 @@* Copyright (C) Tom Long Nguyen ([email protected]) * Copyright (C) 2016 Christoph Hellwig. */ - -#include <linux/acpi_iort.h> #include <linux/err.h> #include <linux/export.h> #include <linux/irq.h> -#include <linux/irqdomain.h> -#include <linux/msi.h> -#include <linux/of_irq.h> -#include <linux/pci.h> #include "../pci.h" +#include "msi.h" static int pci_msi_enable =1 ;int pci_msi_ignore_mask; -#define msix_table_size (flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) - -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -static int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct irq_domain *domain; - - domain =dev_get_msi_domain (&dev->dev); -if (domain &&irq_domain_is_hierarchy (domain)) -return msi_domain_alloc_irqs (domain, &dev->dev, nvec); - -return arch_setup_msi_irqs (dev, nvec, type); -} - -static void pci_msi_teardown_msi_irqs (struct pci_dev *dev) -{ -struct irq_domain *domain; - - domain =dev_get_msi_domain (&dev->dev); -if (domain &&irq_domain_is_hierarchy (domain)) -msi_domain_free_irqs (domain, &dev->dev); -else -arch_teardown_msi_irqs (dev); -} -#else -#define pci_msi_setup_msi_irqs arch_setup_msi_irqs -#define pci_msi_teardown_msi_irqs arch_teardown_msi_irqs -#endif - -/* -* PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to -* mask all MSI interrupts by clearing the MSI enable bit does not work -* reliably as devices without an INTx disable bit will then generate a -* level IRQ which will never be cleared. -*/ -static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) -{ -/* Don't shift by >= width of type */ -if (desc->pci.msi_attrib.multi_cap >=5 ) -return 0xffffffff ; -return (1 << (1 << desc->pci.msi_attrib.multi_cap)) -1 ; -} - static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) {raw_spinlock_t *lock = &desc->dev->msi_lock;@@ -903,23 +855,6 @@ void pci_disable_msix(struct pci_dev *de }EXPORT_SYMBOL (pci_disable_msix); -void pci_no_msi (void ) -{ - pci_msi_enable =0 ; -} - -/** -* pci_msi_enabled - is MSI enabled? -* -* Returns true if MSI has not been disabled by the command-line option -* pci=nomsi. -**/ -int pci_msi_enabled (void ) -{ -return pci_msi_enable; -} -EXPORT_SYMBOL (pci_msi_enabled); -static int __pci_enable_msi_range (struct pci_dev *dev,int minvec,int maxvec,struct irq_affinity *affd) {@@ -1195,253 +1130,19 @@ struct pci_dev *msi_desc_to_pci_dev(stru }EXPORT_SYMBOL (msi_desc_to_pci_dev); -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -/** -* pci_msi_domain_write_msg - Helper to write MSI message to PCI config space -* @irq_data: Pointer to interrupt data of the MSI interrupt -* @msg: Pointer to the message -*/ -static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) -{ -struct msi_desc *desc =irq_data_get_msi_desc (irq_data); - -/* -* For MSI-X desc->irq is always equal to irq_data->irq. For -* MSI only the first interrupt of MULTI MSI passes the test. -*/ -if (desc->irq == irq_data->irq) -__pci_write_msi_msg (desc, msg); -} - -/** -* pci_msi_domain_calc_hwirq - Generate a unique ID for an MSI source -* @desc: Pointer to the MSI descriptor -* -* The ID number is only used within the irqdomain. -*/ -static irq_hw_number_t pci_msi_domain_calc_hwirq (struct msi_desc *desc) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (desc); - -return (irq_hw_number_t )desc->pci.msi_attrib.entry_nr | -pci_dev_id (dev) <<11 | - (pci_domain_nr (dev->bus) &0xFFFFFFFF ) <<27 ; -} - -static inline bool pci_msi_desc_is_multi_msi (struct msi_desc *desc) -{ -return !desc->pci.msi_attrib.is_msix && desc->nvec_used >1 ; -} - -/** -* pci_msi_domain_check_cap - Verify that @domain supports the capabilities -* for @dev -* @domain: The interrupt domain to check -* @info: The domain info for verification -* @dev: The device to check -* -* Returns: -* 0 if the functionality is supported -* 1 if Multi MSI is requested, but the domain does not support it -* -ENOTSUPP otherwise -*/ -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev) -{ -struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev)); - -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && - !(info->flags &MSI_FLAG_MULTI_PCI_MSI )) -return 1 ; -else if (desc->pci.msi_attrib.is_msix && !(info->flags &MSI_FLAG_PCI_MSIX )) -return -ENOTSUPP ; - -return 0 ; -} - -static int pci_msi_domain_handle_error (struct irq_domain *domain, -struct msi_desc *desc,int error) -{ -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) -return 1 ; - -return error; -} - -static void pci_msi_domain_set_desc (msi_alloc_info_t *arg, -struct msi_desc *desc) -{ - arg->desc = desc; - arg->hwirq =pci_msi_domain_calc_hwirq (desc); -} - -static struct msi_domain_ops pci_msi_domain_ops_default = { - .set_desc = pci_msi_domain_set_desc, - .msi_check = pci_msi_domain_check_cap, - .handle_error = pci_msi_domain_handle_error, -}; - -static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info) -{ -struct msi_domain_ops *ops = info->ops; - -if (ops ==NULL ) { - info->ops = &pci_msi_domain_ops_default; - }else { -if (ops->set_desc ==NULL ) - ops->set_desc = pci_msi_domain_set_desc; -if (ops->msi_check ==NULL ) - ops->msi_check = pci_msi_domain_check_cap; -if (ops->handle_error ==NULL ) - ops->handle_error = pci_msi_domain_handle_error; - } -} - -static void pci_msi_domain_update_chip_ops (struct msi_domain_info *info) -{ -struct irq_chip *chip = info->chip; - -BUG_ON (!chip); -if (!chip->irq_write_msi_msg) - chip->irq_write_msi_msg = pci_msi_domain_write_msg; -if (!chip->irq_mask) - chip->irq_mask = pci_msi_mask_irq; -if (!chip->irq_unmask) - chip->irq_unmask = pci_msi_unmask_irq; -} - -/** -* pci_msi_create_irq_domain - Create a MSI interrupt domain -* @fwnode: Optional fwnode of the interrupt controller -* @info: MSI domain info -* @parent: Parent irq domain -* -* Updates the domain and chip ops and creates a MSI interrupt domain. -* -* Returns: -* A domain pointer or NULL in case of failure. -*/ -struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode, -struct msi_domain_info *info, -struct irq_domain *parent) -{ -struct irq_domain *domain; - -if (WARN_ON (info->flags &MSI_FLAG_LEVEL_CAPABLE )) - info->flags &= ~MSI_FLAG_LEVEL_CAPABLE ; - -if (info->flags &MSI_FLAG_USE_DEF_DOM_OPS ) -pci_msi_domain_update_dom_ops (info); -if (info->flags &MSI_FLAG_USE_DEF_CHIP_OPS ) -pci_msi_domain_update_chip_ops (info); - - info->flags |=MSI_FLAG_ACTIVATE_EARLY ; -if (IS_ENABLED (CONFIG_GENERIC_IRQ_RESERVATION_MODE )) - info->flags |=MSI_FLAG_MUST_REACTIVATE ; - -/* PCI-MSI is oneshot-safe */ - info->chip->flags |=IRQCHIP_ONESHOT_SAFE ; - - domain =msi_create_irq_domain (fwnode, info, parent); -if (!domain) -return NULL ; - -irq_domain_update_bus_token (domain,DOMAIN_BUS_PCI_MSI ); -return domain; -} -EXPORT_SYMBOL_GPL (pci_msi_create_irq_domain); - -/* -* Users of the generic MSI infrastructure expect a device to have a single ID, -* so with DMA aliases we have to pick the least-worst compromise. Devices with -* DMA phantom functions tend to still emit MSIs from the real function number, -* so we ignore those and only consider topological aliases where either the -* alias device or RID appears on a different bus number. We also make the -* reasonable assumption that bridges are walked in an upstream direction (so -* the last one seen wins), and the much braver assumption that the most likely -* case is that of PCI->PCIe so we should always use the alias RID. This echoes -* the logic from intel_irq_remapping's set_msi_sid(), which presumably works -* well enough in practice; in the face of the horrible PCIe<->PCI-X conditions -* for taking ownership all we can really do is close our eyes and hope... -*/ -static int get_msi_id_cb (struct pci_dev *pdev,u16 alias,void *data) -{ -u32 *pa = data; -u8 bus =PCI_BUS_NUM (*pa); - -if (pdev->bus->number != bus ||PCI_BUS_NUM (alias) != bus) - *pa = alias; - -return 0 ; -} - -/** -* pci_msi_domain_get_msi_rid - Get the MSI requester id (RID) -* @domain: The interrupt domain -* @pdev: The PCI device. -* -* The RID for a device is formed from the alias, with a firmware -* supplied mapping applied -* -* Returns: The RID. -*/ -u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev) -{ -struct device_node *of_node; -u32 rid =pci_dev_id (pdev); - -pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); - - of_node =irq_domain_get_of_node (domain); - rid = of_node ?of_msi_map_id (&pdev->dev, of_node, rid) : -iort_msi_map_id (&pdev->dev, rid); - -return rid; -} - -/** -* pci_msi_get_device_domain - Get the MSI domain for a given PCI device -* @pdev: The PCI device -* -* Use the firmware data to find a device-specific MSI domain -* (i.e. not one that is set as a default). -* -* Returns: The corresponding MSI domain or NULL if none has been found. -*/ -struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev) +void pci_no_msi (void ) { -struct irq_domain *dom; -u32 rid =pci_dev_id (pdev); - -pci_for_each_dma_alias (pdev, get_msi_id_cb, &rid); - dom =of_msi_map_get_device_domain (&pdev->dev, rid,DOMAIN_BUS_PCI_MSI ); -if (!dom) - dom =iort_get_device_domain (&pdev->dev, rid, -DOMAIN_BUS_PCI_MSI ); -return dom; + pci_msi_enable =0 ; }/** -* pci_dev_has_special_msi_domain - Check whether the device is handled by -* a non-standard PCI-MSI domain -* @pdev: The PCI device to check. +* pci_msi_enabled - is MSI enabled? * -* Returns: True if the device irqdomain or the bus irqdomain is -* non-standard PCI/MSI. -*/ -bool pci_dev_has_special_msi_domain (struct pci_dev *pdev) +* Returns true if MSI has not been disabled by the command-line option +* pci=nomsi. +**/ +int pci_msi_enabled (void ) { -struct irq_domain *dom =dev_get_msi_domain (&pdev->dev); - -if (!dom) - dom =dev_get_msi_domain (&pdev->bus->dev); - -if (!dom) -return true; - -return dom->bus_token !=DOMAIN_BUS_PCI_MSI ; +return pci_msi_enable; } - -#endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ +EXPORT_SYMBOL (pci_msi_enabled);drivers/pci/msi/msi.h new file +39
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/pci.h> +#include <linux/msi.h> + +#define msix_table_size (flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) + +extern int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_teardown_msi_irqs (struct pci_dev *dev); + +#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS +extern int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev); +#else +static inline int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +WARN_ON_ONCE (1 ); +return -ENODEV ; +} + +static inline void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +WARN_ON_ONCE (1 ); +} +#endif + +/* +* PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to +* mask all MSI interrupts by clearing the MSI enable bit does not work +* reliably as devices without an INTx disable bit will then generate a +* level IRQ which will never be cleared. +*/ +static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) +{ +/* Don't shift by >= width of type */ +if (desc->pci.msi_attrib.multi_cap >=5 ) +return 0xffffffff ; +return (1 << (1 << desc->pci.msi_attrib.multi_cap)) -1 ; +}include/linux/msi.h +0
-11@@ -259,17 +259,6 @@ int arch_setup_msi_irq(struct pci_dev *dvoid arch_teardown_msi_irq (unsigned int irq);int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type);void arch_teardown_msi_irqs (struct pci_dev *dev); -#else -static inline int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -WARN_ON_ONCE (1 ); -return -ENODEV ; -} - -static inline void arch_teardown_msi_irqs (struct pci_dev *dev) -{ -WARN_ON_ONCE (1 ); -}#endif /*
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 19/23] PCI/MSI: Sanitize MSIX table map handling
In reply to Thomas GleixnerQuoted 3 lines · Thomas Gleixner
Unmapping the MSIX base mapping in the loops which allocate/free MSI desciptors is daft and in the way of allowing runtime expansion of MSI-X descriptors.
s/MSIX/MSI-X/ (subject and first use in commit log) s/desciptors/descriptors/
Quoted 6 lines
Store the mapping in struct
pci_devand free it after freeing the MSI-X descriptors.Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 65 lines
--- drivers/pci/msi/msi.c | 18 ++++++++---------- include/linux/pci.h | 1 + 2 files changed, 9 insertions(+), 10 deletions(-)drivers/pci/msi/msi.c +8
-10@@ -241,14 +241,14 @@ static void free_msi_irqs(struct pci_devpci_msi_teardown_msi_irqs (dev);list_for_each_entry_safe (entry, tmp, msi_list, list) { -if (entry->pci.msi_attrib.is_msix) { -if (list_is_last (&entry->list, msi_list)) -iounmap (entry->pci.mask_base); - } -list_del (&entry->list);free_msi_entry (entry); } + +if (dev->msix_base) { +iounmap (dev->msix_base); + dev->msix_base =NULL ; + } }static void pci_intx_for_msi (struct pci_dev *dev,int enable)@@ -501,10 +501,6 @@ static int msix_setup_entries(struct pcifor (i =0 , curmsk = masks; i < nvec; i++) { entry =alloc_msi_entry (&dev->dev,1 , curmsk);if (!entry) { -if (!i) -iounmap (base); -else -free_msi_irqs (dev);/* No enough memory. Don't try again */ ret = -ENOMEM ; goto out;@@ -602,12 +598,14 @@ static int msix_capability_init(struct p goto out_disable; } + dev->msix_base = base; +/* Ensure that all table entries are masked. */ msix_mask_all (base, tsize); ret =msix_setup_entries (dev, base, entries, nvec, affd);if (ret) - goto out_disable; + goto out_free; ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret)include/linux/pci.h +1
-0@@ -473,6 +473,7 @@ struct pci_dev {u8 ptm_granularity;#endif #ifdef CONFIG_PCI_MSI +void __iomem *msix_base;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 20/23] PCI/MSI: Move msi_lock to struct pci_dev
In reply to Thomas GleixnerQuoted 4 lines · Thomas Gleixner
It's only required for PCI/MSI. So no point in having it in every struct device.
Signed-off-by Thomas Gleixner <[email protected]>
Quoted 73 lines
---
V2: New patch--- drivers/base/core.c | 1 - drivers/pci/msi/msi.c | 2 +- drivers/pci/probe.c | 4 +++- include/linux/device.h | 2 -- include/linux/pci.h | 1 + 5 files changed, 5 insertions(+), 5 deletions(-)drivers/base/core.c +0
-1@@ -2875,7 +2875,6 @@ void device_initialize(struct device *dedevice_pm_init (dev);set_dev_node (dev,NUMA_NO_NODE );#ifdef CONFIG_GENERIC_MSI_IRQ -raw_spin_lock_init (&dev->msi_lock);INIT_LIST_HEAD (&dev->msi_list);#endif INIT_LIST_HEAD (&dev->links.consumers);drivers/pci/msi/msi.c +1
-1@@ -18,7 +18,7 @@ int pci_msi_ignore_mask; static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) { -raw_spinlock_t *lock = &desc->dev->msi_lock; +raw_spinlock_t *lock = &to_pci_dev (desc->dev)->msi_lock;unsigned long flags;if (!desc->pci.msi_attrib.can_mask)drivers/pci/probe.c +3
-1@@ -2311,7 +2311,9 @@ struct pci_dev *pci_alloc_dev(struct pciINIT_LIST_HEAD (&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus =pci_bus_get (bus); - +#ifdef CONFIG_PCI_MSI +raw_spin_lock_init (&dev->msi_lock); +#endif return dev; }EXPORT_SYMBOL (pci_alloc_dev);include/linux/device.h +0
-2@@ -407,7 +407,6 @@ struct dev_links_info {* @em_pd: device's energy model performance domain * @pins: For device pin management. * See Documentation/driver-api/pin-control.rst for details. -* @msi_lock: Lock to protect MSI mask cache and mask register * @msi_list: Hosts MSI descriptors * @msi_domain: The generic MSI domain this device is using. * @numa_node: NUMA node this device is close to. @@ -508,7 +507,6 @@ struct device {struct dev_pin_info *pins;#endif #ifdef CONFIG_GENERIC_MSI_IRQ -raw_spinlock_t msi_lock;struct list_head msi_list;#endif #ifdef CONFIG_DMA_OPS include/linux/pci.h +1
-0@@ -474,6 +474,7 @@ struct pci_dev {#endif #ifdef CONFIG_PCI_MSI void __iomem *msix_base; +raw_spinlock_t msi_lock;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 21/23] PCI/MSI: Make pci_msi_domain_check_cap() static
In reply to Thomas GleixnerQuoted 5 lines · Thomas Gleixner
No users outside of that file.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 31 lines
--- drivers/pci/msi/irqdomain.c | 5 +++-- include/linux/msi.h | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-)drivers/pci/msi/irqdomain.c +3
-2@@ -79,8 +79,9 @@ static inline bool pci_msi_desc_is_multi* 1 if Multi MSI is requested, but the domain does not support it * -ENOTSUPP otherwise */ -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev) +static int pci_msi_domain_check_cap (struct irq_domain *domain, +struct msi_domain_info *info, +struct device *dev) {struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev));include/linux/msi.h +0
-2@@ -439,8 +439,6 @@ void *platform_msi_get_host_data(structstruct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent); -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev);u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev);struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev);bool pci_dev_has_special_msi_domain (struct pci_dev *pdev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 22/23] genirq/msi: Handle PCI/MSI allocation fail in core code
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
Get rid of yet another irqdomain callback and let the core code return the already available information of how many descriptors could be allocated.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 129 lines
--- drivers/pci/msi/irqdomain.c | 13 ------------- include/linux/msi.h | 5 +---- kernel/irq/msi.c | 29 +++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 21 deletions(-)drivers/pci/msi/irqdomain.c +0
-13@@ -95,16 +95,6 @@ static int pci_msi_domain_check_cap(strureturn 0 ; } -static int pci_msi_domain_handle_error (struct irq_domain *domain, -struct msi_desc *desc,int error) -{ -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) -return 1 ; - -return error; -} -static void pci_msi_domain_set_desc (msi_alloc_info_t *arg,struct msi_desc *desc) {@@ -115,7 +105,6 @@ static void pci_msi_domain_set_desc(msi_static struct msi_domain_ops pci_msi_domain_ops_default = { .set_desc = pci_msi_domain_set_desc, .msi_check = pci_msi_domain_check_cap, - .handle_error = pci_msi_domain_handle_error, };static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info)@@ -129,8 +118,6 @@ static void pci_msi_domain_update_dom_op ops->set_desc = pci_msi_domain_set_desc;if (ops->msi_check ==NULL ) ops->msi_check = pci_msi_domain_check_cap; -if (ops->handle_error ==NULL ) - ops->handle_error = pci_msi_domain_handle_error; } }include/linux/msi.h +1
-4@@ -286,7 +286,6 @@ struct msi_domain_info;* @msi_check: Callback for verification of the domain/info/dev data * @msi_prepare: Prepare the allocation of the interrupts in the domain * @set_desc: Set the msi descriptor for an interrupt -* @handle_error: Optional error handler if the allocation fails * @domain_alloc_irqs: Optional function to override the default allocation * function. * @domain_free_irqs: Optional function to override the default free @@ -295,7 +294,7 @@ struct msi_domain_info;* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * -* @msi_check, @msi_prepare, @handle_error and @set_desc are callbacks used by +* @msi_check, @msi_prepare and @set_desc are callbacks used by * msi_domain_alloc/free_irqs(). * * @domain_alloc_irqs, @domain_free_irqs can be used to override the @@ -332,8 +331,6 @@ struct msi_domain_ops { msi_alloc_info_t *arg);void (*set_desc)(msi_alloc_info_t *arg,struct msi_desc *desc); -int (*handle_error)(struct irq_domain *domain, -struct msi_desc *desc,int error);int (*domain_alloc_irqs)(struct irq_domain *domain,struct device *dev,int nvec); void (*domain_free_irqs)(struct irq_domain *domain,kernel/irq/msi.c +25
-4@@ -538,6 +538,27 @@ static bool msi_check_reservation_mode(sreturn desc->pci.msi_attrib.is_msix || desc->pci.msi_attrib.can_mask; } +static int msi_handle_pci_fail (struct irq_domain *domain,struct msi_desc *desc, +int allocated) +{ +switch (domain->bus_token) { +case DOMAIN_BUS_PCI_MSI : +case DOMAIN_BUS_VMD_MSI : +if (IS_ENABLED (CONFIG_PCI_MSI )) +break ; + fallthrough; +default : +return -ENOSPC ; + } + +/* Let a failed PCI multi MSI allocation retry */ +if (desc->nvec_used >1 ) +return 1 ; + +/* If there was a successful allocation let the caller know */ +return allocated ? allocated : -ENOSPC ; +} +int __msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev,int nvec) {@@ -546,6 +567,7 @@ int __msi_domain_alloc_irqs(struct irq_dstruct irq_data *irq_data;struct msi_desc *desc;msi_alloc_info_t arg = { }; +int allocated =0 ;int i, ret, virq;bool can_reserve;@@ -560,16 +582,15 @@ int __msi_domain_alloc_irqs(struct irq_ddev_to_node (dev), &arg, false, desc->affinity);if (virq <0 ) { - ret = -ENOSPC ; -if (ops->handle_error) - ret = ops->handle_error (domain, desc, ret); -return ret; + ret =msi_handle_pci_fail (domain, desc, allocated); + goto cleanup; }for (i =0 ; i < desc->nvec_used; i++) {irq_set_msi_desc_off (virq, i, desc);irq_debugfs_copy_devname (virq + i, dev); } + allocated++; } can_reserve =msi_check_reservation_mode (domain, info, dev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 23/23] PCI/MSI: Move descriptor counting on allocation fail to the legacy code
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
The irqdomain code already returns the information. Move the loop to the legacy code.
Signed-off-by Thomas Gleixner <[email protected]>Tested-by Juergen Gross <[email protected]>Reviewed-by Jason Gunthorpe <[email protected]>
Quoted 72 lines
--- drivers/pci/msi/legacy.c | 20 +++++++++++++++++++- drivers/pci/msi/msi.c | 19 +------------------ 2 files changed, 20 insertions(+), 19 deletions(-)drivers/pci/msi/legacy.c +19
-1@@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struc } } +static int pci_msi_setup_check_result (struct pci_dev *dev,int type,int ret) +{ +struct msi_desc *entry; +int avail =0 ; + +if (type !=PCI_CAP_ID_MSIX || ret >=0 ) +return ret; + +/* Scan the MSI descriptors for successfully allocated ones. */ +for_each_pci_msi_entry (entry, dev) { +if (entry->irq !=0 ) + avail++; + } +return avail ? avail : ret; +} +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) { -return arch_setup_msi_irqs (dev, nvec, type); +int ret =arch_setup_msi_irqs (dev, nvec, type); + +return pci_msi_setup_check_result (dev, type, ret); }void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev)drivers/pci/msi/msi.c +1
-18@@ -609,7 +609,7 @@ static int msix_capability_init(struct p ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret) - goto out_avail; + goto out_free;/* Check if all MSI entries honor device restrictions */ ret =msi_verify_entries (dev);@@ -634,23 +634,6 @@ static int msix_capability_init(struct ppcibios_free_irq (dev);return 0 ; -out_avail: -if (ret <0 ) { -/* -* If we had some success, report the number of IRQs -* we succeeded in setting up. -*/ -struct msi_desc *entry; -int avail =0 ; - -for_each_pci_msi_entry (entry, dev) { -if (entry->irq !=0 ) - avail++; - } -if (avail !=0 ) - ret = avail; - } - out_free:free_msi_irqs (dev);
Signature · 3 lines
ath11k mailing list [email protected] http://lists.infradead.org/mailman/listinfo/ath11k
Re: [patch V2 01/23] powerpc/4xx: Remove MSI support which never worked
In reply to Thomas GleixnerQuoted 18 lines · Thomas Gleixner
Cedric,
Quoted 5 lines · Cédric Le Goater
Quoted 3 lines · Michael Ellerman
This patch should drop those selects I guess. Can you send an incremental diff for Thomas to squash in?
Quoted 8 lines
Sure.
Quoted 4 lines
Removing all the tendrils in various device tree files will probably require some archaeology, and it should be perfectly safe to leave those in the tree with the driver gone. So I think we can do that as a subsequent patch, rather than in this series.
Here are the changes. Compiled tested with ppc40x and ppc44x defconfigs.
< Lots of patch skipped />
Quoted 10 lines
arch/powerpc/platforms/44x/Kconfig config REDWOOD · line 142
Quoted 7 lines
arch/powerpc/platforms/44x/Kconfig +0
-1@@ -141,7 +138,6 @@ config REDWOOD select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC460SX Redwood board.While that is incremental it certainly is worth a patch on it's own. Could you add a proper changelog and an SOB please?
Here you are.
https://github.com/legoater/linux/commit/75d2764b11fe8f6d8bf50d60a3feb599ce27b16d
Thanks,
C.
Re: [patch V2 20/23] PCI/MSI: Move msi_lock to struct pci_dev
In reply to Thomas GleixnerQuoted 6 lines · Thomas Gleixner
It's only required for PCI/MSI. So no point in having it in every struct device.
Signed-off-by Thomas Gleixner <[email protected]>---
V2: New patch
Quoted 7 lines
--- drivers/base/core.c | 1 - drivers/pci/msi/msi.c | 2 +- drivers/pci/probe.c | 4 +++- include/linux/device.h | 2 -- include/linux/pci.h | 1 + 5 files changed, 5 insertions(+), 5 deletions(-)
Quoted 13 lines
drivers/base/core.c +0
-1@@ -2875,7 +2875,6 @@ void device_initialize(struct device *dedevice_pm_init (dev);set_dev_node (dev,NUMA_NO_NODE );#ifdef CONFIG_GENERIC_MSI_IRQ -raw_spin_lock_init (&dev->msi_lock);INIT_LIST_HEAD (&dev->msi_list);#endif INIT_LIST_HEAD (&dev->links.consumers);
drivers/pci/msi/msi.c int pci_msi_ignore_mask; · line 24
Quoted 8 lines
drivers/pci/msi/msi.c +1
-1@@ -18,7 +18,7 @@ int pci_msi_ignore_mask; static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) { -raw_spinlock_t *lock = &desc->dev->msi_lock; +raw_spinlock_t *lock = &to_pci_dev (desc->dev)->msi_lock;unsigned long flags;if (!desc->pci.msi_attrib.can_mask)
It looks like most of the time this is called by an irq_chip, except for a few special cases list pci_msi_shutdown()
Is this something that should ideally go away someday and use some lock in the irq_chip - not unlike what we've thought is needed for IMS?
Jason
Re: [patch V2 20/23] PCI/MSI: Move msi_lock to struct pci_dev
Quoted 9 lines · Jason Gunthorpe
Quoted 1 line · Thomas Gleixner
if (!desc->pci.msi_attrib.can_mask)
It looks like most of the time this is called by an
irq_chip, except for a few special cases listpci_msi_shutdown()Is this something that should ideally go away someday and use some lock in the
irq_chip- not unlike what we've thought is needed for IMS?
Some day we'll have that yes.
[tip: irq/msi] PCI/MSI: Move descriptor counting on allocation fail to the legacy code
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 60bf9b33c82c0e040a98272d7ff4f5a52e7469d6 Gitweb: https://git.kernel.org/tip/60bf9b33c82c0e040a98272d7ff4f5a52e7469d6 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:28:00 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:23 +01:00
PCI/MSI: Move descriptor counting on allocation fail to the legacy code
The irqdomain code already returns the information. Move the loop to the legacy code.
--- drivers/pci/msi/legacy.c | 20 +++++++++++++++++++- drivers/pci/msi/msi.c | 19 +------------------ 2 files changed, 20 insertions(+), 19 deletions(-)
drivers/pci/msi/legacy.c +19 -1
@@ -50,9 +50,27 @@ void __weak arch_teardown_msi_irqs(struct pci_dev *dev) } } +static int pci_msi_setup_check_result (struct pci_dev *dev,int type,int ret) +{ +struct msi_desc *entry; +int avail =0 ; + +if (type !=PCI_CAP_ID_MSIX || ret >=0 ) +return ret; + +/* Scan the MSI descriptors for successfully allocated ones. */ +for_each_pci_msi_entry (entry, dev) { +if (entry->irq !=0 ) + avail++; + } +return avail ? avail : ret; +} +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) { -return arch_setup_msi_irqs (dev, nvec, type); +int ret =arch_setup_msi_irqs (dev, nvec, type); + +return pci_msi_setup_check_result (dev, type, ret); }void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev)
drivers/pci/msi/msi.c +1 -18
@@ -609,7 +609,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret) - goto out_avail; + goto out_free;/* Check if all MSI entries honor device restrictions */ ret =msi_verify_entries (dev);
@@ -634,23 +634,6 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,pcibios_free_irq (dev);return 0 ; -out_avail: -if (ret <0 ) { -/* -* If we had some success, report the number of IRQs -* we succeeded in setting up. -*/ -struct msi_desc *entry; -int avail =0 ; - -for_each_pci_msi_entry (entry, dev) { -if (entry->irq !=0 ) - avail++; - } -if (avail !=0 ) - ret = avail; - } - out_free:free_msi_irqs (dev);
[tip: irq/msi] genirq/msi: Handle PCI/MSI allocation fail in core code
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 890337624e1fa2da079fc1c036a62d178c985280 Gitweb: https://git.kernel.org/tip/890337624e1fa2da079fc1c036a62d178c985280 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:59 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
genirq/msi: Handle PCI/MSI allocation fail in core code
Get rid of yet another irqdomain callback and let the core code return the already available information of how many descriptors could be allocated.
--- drivers/pci/msi/irqdomain.c | 13 ------------- include/linux/msi.h | 5 +---- kernel/irq/msi.c | 29 +++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 21 deletions(-)
drivers/pci/msi/irqdomain.c +0 -13
@@ -95,16 +95,6 @@ static int pci_msi_domain_check_cap(struct irq_domain *domain,return 0 ; } -static int pci_msi_domain_handle_error (struct irq_domain *domain, -struct msi_desc *desc,int error) -{ -/* Special handling to support __pci_enable_msi_range() */ -if (pci_msi_desc_is_multi_msi (desc) && error == -ENOSPC ) -return 1 ; - -return error; -} -static void pci_msi_domain_set_desc (msi_alloc_info_t *arg,struct msi_desc *desc) {
@@ -115,7 +105,6 @@ static void pci_msi_domain_set_desc(msi_alloc_info_t *arg,static struct msi_domain_ops pci_msi_domain_ops_default = { .set_desc = pci_msi_domain_set_desc, .msi_check = pci_msi_domain_check_cap, - .handle_error = pci_msi_domain_handle_error, };static void pci_msi_domain_update_dom_ops (struct msi_domain_info *info)
@@ -129,8 +118,6 @@ static void pci_msi_domain_update_dom_ops(struct msi_domain_info *info) ops->set_desc = pci_msi_domain_set_desc;if (ops->msi_check ==NULL ) ops->msi_check = pci_msi_domain_check_cap; -if (ops->handle_error ==NULL ) - ops->handle_error = pci_msi_domain_handle_error; } }
include/linux/msi.h +1 -4
@@ -286,7 +286,6 @@ struct msi_domain_info;* @msi_check: Callback for verification of the domain/info/dev data * @msi_prepare: Prepare the allocation of the interrupts in the domain * @set_desc: Set the msi descriptor for an interrupt -* @handle_error: Optional error handler if the allocation fails * @domain_alloc_irqs: Optional function to override the default allocation * function. * @domain_free_irqs: Optional function to override the default free
@@ -295,7 +294,7 @@ struct msi_domain_info;* @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying * irqdomain. * -* @msi_check, @msi_prepare, @handle_error and @set_desc are callbacks used by +* @msi_check, @msi_prepare and @set_desc are callbacks used by * msi_domain_alloc/free_irqs(). * * @domain_alloc_irqs, @domain_free_irqs can be used to override the
@@ -332,8 +331,6 @@ struct msi_domain_ops { msi_alloc_info_t *arg);void (*set_desc)(msi_alloc_info_t *arg,struct msi_desc *desc); -int (*handle_error)(struct irq_domain *domain, -struct msi_desc *desc,int error);int (*domain_alloc_irqs)(struct irq_domain *domain,struct device *dev,int nvec); void (*domain_free_irqs)(struct irq_domain *domain,
kernel/irq/msi.c +25 -4
@@ -538,6 +538,27 @@ static bool msi_check_reservation_mode(struct irq_domain *domain,return desc->pci.msi_attrib.is_msix || desc->pci.msi_attrib.can_mask; } +static int msi_handle_pci_fail (struct irq_domain *domain,struct msi_desc *desc, +int allocated) +{ +switch (domain->bus_token) { +case DOMAIN_BUS_PCI_MSI : +case DOMAIN_BUS_VMD_MSI : +if (IS_ENABLED (CONFIG_PCI_MSI )) +break ; + fallthrough; +default : +return -ENOSPC ; + } + +/* Let a failed PCI multi MSI allocation retry */ +if (desc->nvec_used >1 ) +return 1 ; + +/* If there was a successful allocation let the caller know */ +return allocated ? allocated : -ENOSPC ; +} +int __msi_domain_alloc_irqs (struct irq_domain *domain,struct device *dev,int nvec) {
@@ -546,6 +567,7 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,struct irq_data *irq_data;struct msi_desc *desc;msi_alloc_info_t arg = { }; +int allocated =0 ;int i, ret, virq;bool can_reserve;
@@ -560,16 +582,15 @@ int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,dev_to_node (dev), &arg, false, desc->affinity);if (virq <0 ) { - ret = -ENOSPC ; -if (ops->handle_error) - ret = ops->handle_error (domain, desc, ret); -return ret; + ret =msi_handle_pci_fail (domain, desc, allocated); + goto cleanup; }for (i =0 ; i < desc->nvec_used; i++) {irq_set_msi_desc_off (virq, i, desc);irq_debugfs_copy_devname (virq + i, dev); } + allocated++; } can_reserve =msi_check_reservation_mode (domain, info, dev);
[tip: irq/msi] PCI/MSI: Make pci_msi_domain_check_cap() static
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 57ce3a3c99b21e9c4f951ef01e0a3603c987c259 Gitweb: https://git.kernel.org/tip/57ce3a3c99b21e9c4f951ef01e0a3603c987c259 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:57 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Make pci_msi_domain_check_cap() static
No users outside of that file.
--- drivers/pci/msi/irqdomain.c | 5 +++-- include/linux/msi.h | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/pci/msi/irqdomain.c +3 -2
@@ -79,8 +79,9 @@ static inline bool pci_msi_desc_is_multi_msi(struct msi_desc *desc)* 1 if Multi MSI is requested, but the domain does not support it * -ENOTSUPP otherwise */ -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev) +static int pci_msi_domain_check_cap (struct irq_domain *domain, +struct msi_domain_info *info, +struct device *dev) {struct msi_desc *desc =first_pci_msi_entry (to_pci_dev (dev));
include/linux/msi.h +0 -2
@@ -439,8 +439,6 @@ void *platform_msi_get_host_data(struct irq_domain *domain);struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent); -int pci_msi_domain_check_cap (struct irq_domain *domain, -struct msi_domain_info *info,struct device *dev);u32 pci_msi_domain_get_msi_rid (struct irq_domain *domain,struct pci_dev *pdev);struct irq_domain *pci_msi_get_device_domain (struct pci_dev *pdev);bool pci_dev_has_special_msi_domain (struct pci_dev *pdev);
[tip: irq/msi] PCI/MSI: Move msi_lock to struct pci_dev
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: cd119b09a87d8beb50356d8c5c6aa42d89c44eb7 Gitweb: https://git.kernel.org/tip/cd119b09a87d8beb50356d8c5c6aa42d89c44eb7 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:56 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Move msi_lock to struct pci_dev
It's only required for PCI/MSI. So no point in having it in every struct device.
--- drivers/base/core.c | 1 - drivers/pci/msi/msi.c | 2 +- drivers/pci/probe.c | 4 +++- include/linux/device.h | 2 -- include/linux/pci.h | 1 + 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/base/core.c +0 -1
@@ -2875,7 +2875,6 @@ void device_initialize(struct device *dev)device_pm_init (dev);set_dev_node (dev,NUMA_NO_NODE );#ifdef CONFIG_GENERIC_MSI_IRQ -raw_spin_lock_init (&dev->msi_lock);INIT_LIST_HEAD (&dev->msi_list);#endif INIT_LIST_HEAD (&dev->links.consumers);
drivers/pci/msi/msi.c +1 -1
@@ -18,7 +18,7 @@ int pci_msi_ignore_mask; static noinline void pci_msi_update_mask(struct msi_desc *desc, u32 clear, u32 set) { -raw_spinlock_t *lock = &desc->dev->msi_lock; +raw_spinlock_t *lock = &to_pci_dev (desc->dev)->msi_lock;unsigned long flags;if (!desc->pci.msi_attrib.can_mask)
drivers/pci/probe.c +3 -1
@@ -2311,7 +2311,9 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus =pci_bus_get (bus); - +#ifdef CONFIG_PCI_MSI +raw_spin_lock_init (&dev->msi_lock); +#endif return dev; }EXPORT_SYMBOL (pci_alloc_dev);
include/linux/device.h +0 -2
@@ -407,7 +407,6 @@ struct dev_links_info {* @em_pd: device's energy model performance domain * @pins: For device pin management. * See Documentation/driver-api/pin-control.rst for details. -* @msi_lock: Lock to protect MSI mask cache and mask register * @msi_list: Hosts MSI descriptors * @msi_domain: The generic MSI domain this device is using. * @numa_node: NUMA node this device is close to.
@@ -508,7 +507,6 @@ struct device {struct dev_pin_info *pins;#endif #ifdef CONFIG_GENERIC_MSI_IRQ -raw_spinlock_t msi_lock;struct list_head msi_list;#endif #ifdef CONFIG_DMA_OPS
include/linux/pci.h +1 -0
@@ -474,6 +474,7 @@ struct pci_dev {#endif #ifdef CONFIG_PCI_MSI void __iomem *msix_base; +raw_spinlock_t msi_lock;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
[tip: irq/msi] PCI/MSI: Sanitize MSI-X table map handling
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 85aa607e79f8343f1ea028b29bdf8b6bc99c729a Gitweb: https://git.kernel.org/tip/85aa607e79f8343f1ea028b29bdf8b6bc99c729a Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:54 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Sanitize MSI-X table map handling
Unmapping the MSI-X base mapping in the loops which allocate/free MSI descriptors is daft and in the way of allowing runtime expansion of MSI-X descriptors.
Store the mapping in struct pci_dev and free it after freeing the MSI-X descriptors.
--- drivers/pci/msi/msi.c | 18 ++++++++---------- include/linux/pci.h | 1 + 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/pci/msi/msi.c +8 -10
@@ -241,14 +241,14 @@ static void free_msi_irqs(struct pci_dev *dev)pci_msi_teardown_msi_irqs (dev);list_for_each_entry_safe (entry, tmp, msi_list, list) { -if (entry->pci.msi_attrib.is_msix) { -if (list_is_last (&entry->list, msi_list)) -iounmap (entry->pci.mask_base); - } -list_del (&entry->list);free_msi_entry (entry); } + +if (dev->msix_base) { +iounmap (dev->msix_base); + dev->msix_base =NULL ; + } }static void pci_intx_for_msi (struct pci_dev *dev,int enable)
@@ -501,10 +501,6 @@ static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,for (i =0 , curmsk = masks; i < nvec; i++) { entry =alloc_msi_entry (&dev->dev,1 , curmsk);if (!entry) { -if (!i) -iounmap (base); -else -free_msi_irqs (dev);/* No enough memory. Don't try again */ ret = -ENOMEM ; goto out;
@@ -602,12 +598,14 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, goto out_disable; } + dev->msix_base = base; +/* Ensure that all table entries are masked. */ msix_mask_all (base, tsize); ret =msix_setup_entries (dev, base, entries, nvec, affd);if (ret) - goto out_disable; + goto out_free; ret =pci_msi_setup_msi_irqs (dev, nvec,PCI_CAP_ID_MSIX );if (ret)
include/linux/pci.h +1 -0
@@ -473,6 +473,7 @@ struct pci_dev {u8 ptm_granularity;#endif #ifdef CONFIG_PCI_MSI +void __iomem *msix_base;const struct attribute_group **msi_irq_groups;#endif struct pci_vpd vpd;
[tip: irq/msi] PCI/MSI: Split out irqdomain code
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: aa423ac4221abdfb8588751e7838ca5f42f56db3 Gitweb: https://git.kernel.org/tip/aa423ac4221abdfb8588751e7838ca5f42f56db3 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:52 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Split out irqdomain code
Move the irqdomain specific code into its own file.
--- drivers/pci/msi/Makefile | 1 +- drivers/pci/msi/irqdomain.c | 279 +++++++++++++++++++++++++++++++- drivers/pci/msi/legacy.c | 13 +- drivers/pci/msi/msi.c | 319 +---------------------------------- drivers/pci/msi/msi.h | 39 ++++- include/linux/msi.h | 11 +- 6 files changed, 340 insertions(+), 322 deletions(-) create mode 100644 drivers/pci/msi/irqdomain.c create mode 100644 drivers/pci/msi/msi.h
drivers/pci/msi/Makefile +1 -0
@@ -3,4 +3,5 @@ # Makefile for the PCI/MSI obj-$(CONFIG_PCI) += pcidev_msi.o obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_IRQ_DOMAIN) += irqdomain.o obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o
drivers/pci/msi/irqdomain.c new file +279 -0
279 lines not on this page · raw message
drivers/pci/msi/legacy.c +11 -2
@@ -4,8 +4,7 @@* * Legacy architecture specific setup and teardown mechanism. */ -#include <linux/msi.h> -#include <linux/pci.h> +#include "msi.h" /* Arch hooks */ int __weak arch_setup_msi_irq (struct pci_dev *dev,struct msi_desc *desc)
@@ -50,3 +49,13 @@ void __weak arch_teardown_msi_irqs(struct pci_dev *dev) } } } + +int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +return arch_setup_msi_irqs (dev, nvec, type); +} + +void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +arch_teardown_msi_irqs (dev); +}
drivers/pci/msi/msi.c +10 -309
350 lines not on this page · raw message
drivers/pci/msi/msi.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include <linux/pci.h> +#include <linux/msi.h> + +#define msix_table_size (flags) ((flags & PCI_MSIX_FLAGS_QSIZE) + 1) + +extern int pci_msi_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_teardown_msi_irqs (struct pci_dev *dev); + +#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS +extern int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type); +extern void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev); +#else +static inline int pci_msi_legacy_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) +{ +WARN_ON_ONCE (1 ); +return -ENODEV ; +} + +static inline void pci_msi_legacy_teardown_msi_irqs (struct pci_dev *dev) +{ +WARN_ON_ONCE (1 ); +} +#endif + +/* +* PCI 2.3 does not specify mask bits for each MSI interrupt. Attempting to +* mask all MSI interrupts by clearing the MSI enable bit does not work +* reliably as devices without an INTx disable bit will then generate a +* level IRQ which will never be cleared. +*/ +static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) +{ +/* Don't shift by >= width of type */ +if (desc->pci.msi_attrib.multi_cap >=5 ) +return 0xffffffff ; +return (1 << (1 << desc->pci.msi_attrib.multi_cap)) -1 ; +}
include/linux/msi.h +0 -11
@@ -259,17 +259,6 @@ int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);void arch_teardown_msi_irq (unsigned int irq);int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type);void arch_teardown_msi_irqs (struct pci_dev *dev); -#else -static inline int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -WARN_ON_ONCE (1 ); -return -ENODEV ; -} - -static inline void arch_teardown_msi_irqs (struct pci_dev *dev) -{ -WARN_ON_ONCE (1 ); -}#endif /*
[tip: irq/msi] PCI/MSI: Split out !IRQDOMAIN code
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: a01e09ef123789aa2e23e6b0238ed420791dd4ea Gitweb: https://git.kernel.org/tip/a01e09ef123789aa2e23e6b0238ed420791dd4ea Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:51 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Split out !IRQDOMAIN code
Split out the non irqdomain code into its own file.
--- drivers/pci/msi/Makefile | 5 ++-- drivers/pci/msi/legacy.c | 52 +++++++++++++++++++++++++++++++++++++++- drivers/pci/msi/msi.c | 46 +----------------------------------- 3 files changed, 55 insertions(+), 48 deletions(-) create mode 100644 drivers/pci/msi/legacy.c
drivers/pci/msi/Makefile +3 -2
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += pcidev_msi.o -obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.o +obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o
drivers/pci/msi/legacy.c new file +52 -0
52 lines not on this page · raw message
drivers/pci/msi/msi.c +0 -46
52 lines not on this page · raw message
[tip: irq/msi] PCI/MSI: Split out CONFIG_PCI_MSI independent part
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 54324c2f3d728f451d9053fcc7859b26fc9cecb4 Gitweb: https://git.kernel.org/tip/54324c2f3d728f451d9053fcc7859b26fc9cecb4 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:49 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Split out CONFIG_PCI_MSI independent part
These functions are required even when CONFIG_PCI_MSI is not set. Move them to their own file.
--- drivers/pci/msi/Makefile | 3 +- drivers/pci/msi/msi.c | 39 +-------------------------------- drivers/pci/msi/pcidev_msi.c | 43 +++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 drivers/pci/msi/pcidev_msi.c
drivers/pci/msi/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 # # Makefile for the PCI/MSI -obj-$(CONFIG_PCI) += msi.o +obj-$(CONFIG_PCI) += pcidev_msi.o +obj-$(CONFIG_PCI_MSI) += msi.o
drivers/pci/msi/msi.c +0 -39
@@ -18,8 +18,6 @@#include "../pci.h" -#ifdef CONFIG_PCI_MSI -static int pci_msi_enable =1 ;int pci_msi_ignore_mask;
@@ -1493,40 +1491,3 @@ bool pci_dev_has_special_msi_domain(struct pci_dev *pdev) }#endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */ -#endif /* CONFIG_PCI_MSI */ - -void pci_msi_init (struct pci_dev *dev) -{ -u16 ctrl; - -/* -* Disable the MSI hardware to avoid screaming interrupts -* during boot. This is the power on reset default so -* usually this should be a noop. -*/ - dev->msi_cap =pci_find_capability (dev,PCI_CAP_ID_MSI ); -if (!dev->msi_cap) -return ; - -pci_read_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , &ctrl); -if (ctrl &PCI_MSI_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msi_cap +PCI_MSI_FLAGS , - ctrl & ~PCI_MSI_FLAGS_ENABLE ); - -if (!(ctrl &PCI_MSI_FLAGS_64BIT )) - dev->no_64bit_msi =1 ; -} - -void pci_msix_init (struct pci_dev *dev) -{ -u16 ctrl; - - dev->msix_cap =pci_find_capability (dev,PCI_CAP_ID_MSIX ); -if (!dev->msix_cap) -return ; - -pci_read_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , &ctrl); -if (ctrl &PCI_MSIX_FLAGS_ENABLE ) -pci_write_config_word (dev, dev->msix_cap +PCI_MSIX_FLAGS , - ctrl & ~PCI_MSIX_FLAGS_ENABLE ); -}
drivers/pci/msi/pcidev_msi.c new file +43 -0
43 lines not on this page · raw message
[tip: irq/msi] PCI/MSI: Move code into a separate directory
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 288c81ce4be7c15544605594966faaeb8803b5da Gitweb: https://git.kernel.org/tip/288c81ce4be7c15544605594966faaeb8803b5da Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:47 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:22 +01:00
PCI/MSI: Move code into a separate directory
msi.c is getting larger and really could do with a splitup. Move it into its own directory to prepare for that.
--- Documentation/driver-api/pci/pci.rst | 2 +- drivers/pci/Makefile | 3 +- drivers/pci/msi.c | 1532 +------------------------- drivers/pci/msi/Makefile | 4 +- drivers/pci/msi/msi.c | 1532 +++++++++++++++++++++++++- 5 files changed, 1539 insertions(+), 1534 deletions(-) delete mode 100644 drivers/pci/msi.c create mode 100644 drivers/pci/msi/Makefile create mode 100644 drivers/pci/msi/msi.c
Documentation/driver-api/pci/pci.rst +1 -1
@@ -13,7 +13,7 @@ PCI Support Library .. kernel-doc:: drivers/pci/search.c :export: -.. kernel-doc:: drivers/pci/msi.c +.. kernel-doc:: drivers/pci/msi/msi.c :export: .. kernel-doc:: drivers/pci/bus.c
drivers/pci/Makefile +2 -1
@@ -5,8 +5,9 @@ obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \ remove.o pci.o pci-driver.o search.o \ pci-sysfs.o rom.o setup-res.o irq.o vpd.o \ - setup-bus.o vc.o mmap.o setup-irq.o msi.o + setup-bus.o vc.o mmap.o setup-irq.o +obj-$(CONFIG_PCI) += msi/ obj-$(CONFIG_PCI) += pcie/ ifdef CONFIG_PCI
drivers/pci/msi.c deleted +0 -1532
1,532 lines not on this page · raw message
drivers/pci/msi/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the PCI/MSI +obj-$(CONFIG_PCI) += msi.o
drivers/pci/msi/msi.c new file +1532 -0
1,446 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
[tip: irq/msi] PCI/MSI: Cleanup include zoo
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 29a03ada4a007067d5427a6a1b7ba1dc7566ea2e Gitweb: https://git.kernel.org/tip/29a03ada4a007067d5427a6a1b7ba1dc7566ea2e Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:44 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
PCI/MSI: Cleanup include zoo
Get rid of the pile of unneeded includes which accumulated over time.
--- drivers/pci/msi.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/pci/msi.c +4 -12
@@ -7,22 +7,14 @@* Copyright (C) 2016 Christoph Hellwig. */ +#include <linux/acpi_iort.h> #include <linux/err.h> -#include <linux/mm.h> -#include <linux/irq.h> -#include <linux/interrupt.h> #include <linux/export.h> -#include <linux/ioport.h> -#include <linux/pci.h> -#include <linux/proc_fs.h> -#include <linux/msi.h> -#include <linux/smp.h> -#include <linux/errno.h> -#include <linux/io.h> -#include <linux/acpi_iort.h> -#include <linux/slab.h> +#include <linux/irq.h> #include <linux/irqdomain.h> +#include <linux/msi.h> #include <linux/of_irq.h> +#include <linux/pci.h> #include "pci.h"
[tip: irq/msi] PCI/MSI: Make msix_update_entries() smarter
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 7112158d97a1539b217c360d379724ac3ee99fa3 Gitweb: https://git.kernel.org/tip/7112158d97a1539b217c360d379724ac3ee99fa3 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:46 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
PCI/MSI: Make msix_update_entries() smarter
No need to walk the descriptors and check for each one whether the entries pointer function argument is NULL. Do it once.
--- drivers/pci/msi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/msi.c +2 -2
@@ -642,8 +642,8 @@ static void msix_update_entries(struct pci_dev *dev, struct msix_entry *entries) {struct msi_desc *entry; -for_each_pci_msi_entry (entry, dev) { -if (entries) { +if (entries) { +for_each_pci_msi_entry (entry, dev) { entries->vector = entry->irq; entries++; }
[tip: irq/msi] PCI/MSI: Make arch_restore_msi_irqs() less horrible.
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: ae72f3156729541581f526b85883ca53a20df2fa Gitweb: https://git.kernel.org/tip/ae72f3156729541581f526b85883ca53a20df2fa Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:42 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
PCI/MSI: Make arch_restore_msi_irqs() less horrible.
Make arch_restore_msi_irqs() return a boolean which indicates whether the core code should restore the MSI message or not. Get rid of the indirection in x86.
--- arch/s390/pci/pci_irq.c | 4 +- arch/x86/include/asm/x86_init.h | 6 +--- arch/x86/include/asm/xen/hypervisor.h | 8 ++++- arch/x86/kernel/apic/msi.c | 6 +++- arch/x86/kernel/x86_init.c | 12 +------ arch/x86/pci/xen.c | 13 +++--- drivers/pci/msi.c | 54 +++++++++----------------- include/linux/msi.h | 7 +-- 8 files changed, 45 insertions(+), 65 deletions(-)
arch/s390/pci/pci_irq.c +2 -2
@@ -387,13 +387,13 @@ void arch_teardown_msi_irqs(struct pci_dev *pdev)airq_iv_free (zpci_ibv[0 ], zdev->msi_first_bit, zdev->msi_nr_irqs); } -void arch_restore_msi_irqs (struct pci_dev *pdev) +bool arch_restore_msi_irqs (struct pci_dev *pdev) {struct zpci_dev *zdev =to_zpci (pdev);if (!zdev->irqs_registered)zpci_set_irq (zdev); -default_restore_msi_irqs (pdev); +return true; }static struct airq_struct zpci_airq = {
arch/x86/include/asm/x86_init.h +0 -6
@@ -289,12 +289,6 @@ struct x86_platform_ops {struct x86_hyper_runtime hyper; }; -struct pci_dev ; - -struct x86_msi_ops { -void (*restore_msi_irqs)(struct pci_dev *dev); -}; -struct x86_apic_ops {unsigned int (*io_apic_read) (unsigned int apic,unsigned int reg);void (*restore)(void );
arch/x86/include/asm/xen/hypervisor.h +8 -0
@@ -57,6 +57,14 @@ static inline bool __init xen_x2apic_para_available(void) }#endif +struct pci_dev ; + +#ifdef CONFIG_XEN_DOM0 +bool xen_initdom_restore_msi (struct pci_dev *dev); +#else +static inline bool xen_initdom_restore_msi (struct pci_dev *dev) {return true; } +#endif +#ifdef CONFIG_HOTPLUG_CPU void xen_arch_register_cpu (int num);void xen_arch_unregister_cpu (int num);
arch/x86/kernel/apic/msi.c +6 -0
@@ -19,6 +19,7 @@#include <asm/hw_irq.h> #include <asm/apic.h> #include <asm/irq_remapping.h> +#include <asm/xen/hypervisor.h> struct irq_domain *x86_pci_msi_default_domain__ro_after_init ;
@@ -345,3 +346,8 @@ void dmar_free_hwirq(int irq) irq_domain_free_irqs(irq, 1); }#endif + +bool arch_restore_msi_irqs (struct pci_dev *dev) +{ +return xen_initdom_restore_msi (dev); +}
arch/x86/kernel/x86_init.c +0 -12
@@ -145,18 +145,6 @@ struct x86_platform_ops x86_platform __ro_after_init = {EXPORT_SYMBOL_GPL (x86_platform); -#if defined(CONFIG_PCI_MSI ) -struct x86_msi_ops x86_msi__ro_after_init = { - .restore_msi_irqs = default_restore_msi_irqs, -}; - -/* MSI arch specific hooks */ -void arch_restore_msi_irqs (struct pci_dev *dev) -{ - x86_msi.restore_msi_irqs (dev); -} -#endif -struct x86_apic_ops x86_apic_ops__ro_after_init = { .io_apic_read = native_io_apic_read, .restore = native_restore_boot_irq_mode,
arch/x86/pci/xen.c +7 -6
@@ -351,10 +351,13 @@ out:return ret; } -static void xen_initdom_restore_msi_irqs (struct pci_dev *dev) +bool xen_initdom_restore_msi (struct pci_dev *dev) {int ret =0 ; +if (!xen_initial_domain ()) +return true; +if (pci_seg_supported) {struct physdev_pci_device restore_ext;
@@ -375,10 +378,10 @@ static void xen_initdom_restore_msi_irqs(struct pci_dev *dev) ret =HYPERVISOR_physdev_op (PHYSDEVOP_restore_msi, &restore); WARN(ret && ret != -ENOSYS, "restore_msi -> %d\n", ret); } +return false; }#else /* CONFIG_XEN_PV_DOM0 */ #define xen_initdom_setup_msi_irqs NULL -#define xen_initdom_restore_msi_irqs NULL#endif /* !CONFIG_XEN_PV_DOM0 */ static void xen_teardown_msi_irqs (struct pci_dev *dev)
@@ -466,12 +469,10 @@ static __init struct irq_domain *xen_create_pci_msi_domain(void)static __init void xen_setup_pci_msi (void ) {if (xen_pv_domain ()) { -if (xen_initial_domain ()) { +if (xen_initial_domain ()) xen_msi_ops.setup_msi_irqs = xen_initdom_setup_msi_irqs; - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs; - }else { +else xen_msi_ops.setup_msi_irqs = xen_setup_msi_irqs; - } xen_msi_ops.teardown_msi_irqs = xen_pv_teardown_msi_irqs; pci_msi_ignore_mask =1 ; }else if (xen_hvm_domain ()) {
drivers/pci/msi.c +19 -35
94 lines not on this page · raw message
include/linux/msi.h +3 -4
@@ -273,11 +273,10 @@ static inline void arch_teardown_msi_irqs(struct pci_dev *dev)#endif /* -* The restore hooks are still available as they are useful even -* for fully irq domain based setups. Courtesy to XEN/X86. +* The restore hook is still available even for fully irq domain based +* setups. Courtesy to XEN/X86. */ -void arch_restore_msi_irqs (struct pci_dev *dev); -void default_restore_msi_irqs (struct pci_dev *dev); +bool arch_restore_msi_irqs (struct pci_dev *dev);#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
[tip: irq/msi] genirq/msi, treewide: Use a named struct for PCI/MSI attributes
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: e58f2259b91c02974c20db7b28d39d810a21249b Gitweb: https://git.kernel.org/tip/e58f2259b91c02974c20db7b28d39d810a21249b Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:39 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
genirq/msi, treewide: Use a named struct for PCI/MSI attributes
The unnamed struct sucks and is in the way of further cleanups. Stick the PCI related MSI data into a real data structure and cleanup all users.
No functional change.
--- arch/powerpc/platforms/cell/axon_msi.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 4 +- arch/powerpc/platforms/pseries/msi.c | 6 +- arch/sparc/kernel/pci_msi.c | 4 +- arch/x86/kernel/apic/msi.c | 2 +- arch/x86/pci/xen.c | 6 +- drivers/net/wireless/ath/ath11k/pci.c | 2 +- drivers/pci/msi.c | 116 ++++++++++----------- drivers/pci/xen-pcifront.c | 2 +- include/linux/msi.h | 84 +++++++-------- kernel/irq/msi.c | 4 +- 11 files changed, 115 insertions(+), 117 deletions(-)
arch/powerpc/platforms/cell/axon_msi.c +1 -1
@@ -212,7 +212,7 @@ static int setup_msi_msg_address(struct pci_dev *dev, struct msi_msg *msg) entry =first_pci_msi_entry (dev);for (; dn; dn =of_get_next_parent (dn)) { -if (entry->msi_attrib.is_64) { +if (entry->pci.msi_attrib.is_64) { prop =of_get_property (dn,"msi-address-64" , &len);if (prop)break ;
arch/powerpc/platforms/powernv/pci-ioda.c +2 -2
@@ -2154,10 +2154,10 @@ static void pnv_msi_compose_msg(struct irq_data *d, struct msi_msg *msg)int rc; rc =__pnv_pci_ioda_msi_setup (phb, pdev, d->hwirq, - entry->msi_attrib.is_64, msg); + entry->pci.msi_attrib.is_64, msg);if (rc)dev_err (&pdev->dev,"Failed to setup %s-bit MSI #%ld : %d\n" , - entry->msi_attrib.is_64 ?"64" :"32" , d->hwirq, rc); + entry->pci.msi_attrib.is_64 ?"64" :"32" , d->hwirq, rc); }/*
arch/powerpc/platforms/pseries/msi.c +3 -3
@@ -332,7 +332,7 @@ static int check_msix_entries(struct pci_dev *pdev) expected =0 ;for_each_pci_msi_entry (entry, pdev) { -if (entry->msi_attrib.entry_nr != expected) { +if (entry->pci.msi_attrib.entry_nr != expected) {pr_debug ("rtas_msi: bad MSI-X entries.\n" );return -EINVAL ; }
@@ -449,7 +449,7 @@ static int pseries_msi_ops_prepare(struct irq_domain *domain, struct device *dev {struct pci_dev *pdev =to_pci_dev (dev);struct msi_desc *desc =first_pci_msi_entry (pdev); -int type = desc->msi_attrib.is_msix ?PCI_CAP_ID_MSIX :PCI_CAP_ID_MSI ; +int type = desc->pci.msi_attrib.is_msix ?PCI_CAP_ID_MSIX :PCI_CAP_ID_MSI ;return rtas_prepare_msi_irqs (pdev, nvec, type, arg); }
@@ -580,7 +580,7 @@ static int pseries_irq_domain_alloc(struct irq_domain *domain, unsigned int virqint hwirq;int i, ret; - hwirq =rtas_query_irq_number (pci_get_pdn (pdev), desc->msi_attrib.entry_nr); + hwirq =rtas_query_irq_number (pci_get_pdn (pdev), desc->pci.msi_attrib.entry_nr);if (hwirq <0 ) {dev_err (&pdev->dev,"Failed to query HW IRQ: %d\n" , hwirq);return hwirq;
arch/sparc/kernel/pci_msi.c +2 -2
@@ -146,13 +146,13 @@ static int sparc64_setup_msi_irq(unsigned int *irq_p, msiqid =pick_msiq (pbm); err = ops->msi_setup (pbm, msiqid, msi, - (entry->msi_attrib.is_64 ?1 :0 )); + (entry->pci.msi_attrib.is_64 ?1 :0 ));if (err) goto out_msi_free; pbm->msi_irq_table[msi - pbm->msi_first] = *irq_p; -if (entry->msi_attrib.is_64) { +if (entry->pci.msi_attrib.is_64) { msg.address_hi = pbm->msi64_start >>32 ; msg.address_lo = pbm->msi64_start &0xffffffff ; }else {
arch/x86/kernel/apic/msi.c +1 -1
@@ -163,7 +163,7 @@ int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,struct msi_desc *desc =first_pci_msi_entry (pdev);init_irq_alloc_info (arg,NULL ); -if (desc->msi_attrib.is_msix) { +if (desc->pci.msi_attrib.is_msix) { arg->type =X86_IRQ_ALLOC_TYPE_PCI_MSIX ; }else { arg->type =X86_IRQ_ALLOC_TYPE_PCI_MSI ;
arch/x86/pci/xen.c +3 -3
@@ -306,7 +306,7 @@ static int xen_initdom_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)return -EINVAL ; map_irq.table_base =pci_resource_start (dev, bir); - map_irq.entry_nr = msidesc->msi_attrib.entry_nr; + map_irq.entry_nr = msidesc->pci.msi_attrib.entry_nr; } ret = -EINVAL ;
@@ -398,7 +398,7 @@ static void xen_pv_teardown_msi_irqs(struct pci_dev *dev) {struct msi_desc *msidesc =first_pci_msi_entry (dev); -if (msidesc->msi_attrib.is_msix) +if (msidesc->pci.msi_attrib.is_msix)xen_pci_frontend_disable_msix (dev);else xen_pci_frontend_disable_msi (dev);
@@ -414,7 +414,7 @@ static int xen_msi_domain_alloc_irqs(struct irq_domain *domain,if (WARN_ON_ONCE (!dev_is_pci (dev)))return -EINVAL ; -if (first_msi_entry (dev)->msi_attrib.is_msix) +if (first_msi_entry (dev)->pci.msi_attrib.is_msix) type =PCI_CAP_ID_MSIX ;else type =PCI_CAP_ID_MSI ;
drivers/net/wireless/ath/ath11k/pci.c +1 -1
@@ -911,7 +911,7 @@ static int ath11k_pci_alloc_msi(struct ath11k_pci *ab_pci) } ab_pci->msi_ep_base_data = msi_desc->msg.data; -if (msi_desc->msi_attrib.is_64) +if (msi_desc->pci.msi_attrib.is_64)set_bit (ATH11K_PCI_FLAG_IS_MSI_64 , &ab_pci->flags);ath11k_dbg (ab,ATH11K_DBG_PCI ,"msi base data is %d\n" , ab_pci->msi_ep_base_data);
drivers/pci/msi.c +58 -58
278 lines not on this page · raw message
drivers/pci/xen-pcifront.c +1 -1
@@ -263,7 +263,7 @@ static int pci_frontend_enable_msix(struct pci_dev *dev, i =0 ;for_each_pci_msi_entry (entry, dev) { - op.msix_entries[i].entry = entry->msi_attrib.entry_nr; + op.msix_entries[i].entry = entry->pci.msi_attrib.entry_nr;/* Vector is useless at this point. */ op.msix_entries[i].vector =-1 ; i++;
include/linux/msi.h +41 -43
102 lines not on this page · raw message
kernel/irq/msi.c +2 -2
@@ -91,7 +91,7 @@ static ssize_t msi_mode_show(struct device *dev, struct device_attribute *attr,return -ENODEV ;if (dev_is_pci (dev)) - is_msix = entry->msi_attrib.is_msix; + is_msix = entry->pci.msi_attrib.is_msix;return sysfs_emit (buf,"%s\n" , is_msix ?"msix" :"msi" ); }
@@ -535,7 +535,7 @@ static bool msi_check_reservation_mode(struct irq_domain *domain,* masking and MSI does so when the can_mask attribute is set. */ desc =first_msi_entry (dev); -return desc->msi_attrib.is_msix || desc->msi_attrib.can_mask; +return desc->pci.msi_attrib.is_msix || desc->pci.msi_attrib.can_mask; } int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
[tip: irq/msi] x86/hyperv: Refactor hv_msi_domain_free_irqs()
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 1982afd6c0582c523970f5426cc1f11ef8ead7bd Gitweb: https://git.kernel.org/tip/1982afd6c0582c523970f5426cc1f11ef8ead7bd Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:41 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
x86/hyperv: Refactor hv_msi_domain_free_irqs()
No point in looking up things over and over. Just look up the associated irq data and work from there.
No functional change.
--- arch/x86/hyperv/irqdomain.c | 55 +++++++++++------------------------- 1 file changed, 17 insertions(+), 38 deletions(-)
arch/x86/hyperv/irqdomain.c +17 -38
@@ -253,64 +253,43 @@ static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entryreturn hv_unmap_interrupt (hv_build_pci_dev_id (dev).as_uint64, old_entry); } -static void hv_teardown_msi_irq_common (struct pci_dev *dev,struct msi_desc *msidesc,int irq) +static void hv_teardown_msi_irq (struct pci_dev *dev,struct irq_data *irqd) { -u64 status;struct hv_interrupt_entry old_entry; -struct irq_desc *desc; -struct irq_data *data;struct msi_msg msg; +u64 status; - desc =irq_to_desc (irq); -if (!desc) { -pr_debug ("%s: no irq desc\n" , __func__); -return ; - } - - data = &desc->irq_data; -if (!data) { -pr_debug ("%s: no irq data\n" , __func__); -return ; - } - -if (!data->chip_data) { +if (!irqd->chip_data) {pr_debug ("%s: no chip data\n!" , __func__);return ; } - old_entry = *(struct hv_interrupt_entry *)data->chip_data; + old_entry = *(struct hv_interrupt_entry *)irqd->chip_data;entry_to_msi_msg (&old_entry, &msg); -kfree (data->chip_data); - data->chip_data =NULL ; +kfree (irqd->chip_data); + irqd->chip_data =NULL ; status =hv_unmap_msi_interrupt (dev, &old_entry); -if (status !=HV_STATUS_SUCCESS ) { +if (status !=HV_STATUS_SUCCESS )pr_err ("%s: hypercall failed, status %lld\n" , __func__, status); -return ; - } } -static void hv_msi_domain_free_irqs (struct irq_domain *domain,struct device *dev) +static void hv_msi_free_irq (struct irq_domain *domain, +struct msi_domain_info *info,unsigned int virq) { -int i; -struct msi_desc *entry; -struct pci_dev *pdev; +struct irq_data *irqd =irq_get_irq_data (virq); +struct msi_desc *desc; -if (WARN_ON_ONCE (!dev_is_pci (dev))) +if (!irqd)return ; - pdev =to_pci_dev (dev); + desc =irq_data_get_msi_desc (irqd); +if (!desc || !desc->irq ||WARN_ON_ONCE (!dev_is_pci (desc->dev))) +return ; -for_each_pci_msi_entry (entry, pdev) { -if (entry->irq) { -for (i =0 ; i < entry->nvec_used; i++) { -hv_teardown_msi_irq_common (pdev, entry, entry->irq + i); -irq_domain_free_irqs (entry->irq + i,1 ); - } - } - } +hv_teardown_msi_irq (to_pci_dev (desc->dev), irqd); }/*
@@ -329,7 +308,7 @@ static struct irq_chip hv_pci_msi_controller = { };static struct msi_domain_ops pci_msi_domain_ops = { - .domain_free_irqs = hv_msi_domain_free_irqs, + .msi_free = hv_msi_free_irq, .msi_prepare = pci_msi_prepare, };
[tip: irq/msi] PCI/MSI: Remove msi_desc_to_pci_sysdata()
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: ade044a3d0f0389e4f916337c505550acc3fd011 Gitweb: https://git.kernel.org/tip/ade044a3d0f0389e4f916337c505550acc3fd011 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:34 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
PCI/MSI: Remove msi_desc_to_pci_sysdata()
Last user is gone long ago.
--- drivers/pci/msi.c | 8 -------- include/linux/msi.h | 5 ----- 2 files changed, 13 deletions(-)
drivers/pci/msi.c +0 -8
@@ -1267,14 +1267,6 @@ struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc) }EXPORT_SYMBOL (msi_desc_to_pci_dev); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -struct pci_dev *dev =msi_desc_to_pci_dev (desc); - -return dev->bus->sysdata; -} -EXPORT_SYMBOL_GPL (msi_desc_to_pci_sysdata); -#ifdef CONFIG_PCI_MSI_IRQ_DOMAIN /** * pci_msi_domain_write_msg - Helper to write MSI message to PCI config space
include/linux/msi.h +0 -5
@@ -218,13 +218,8 @@ static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc,for_each_msi_entry ((desc), &(pdev)->dev) struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc); -void *msi_desc_to_pci_sysdata (struct msi_desc *desc);void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg);#else /* CONFIG_PCI_MSI */ -static inline void *msi_desc_to_pci_sysdata (struct msi_desc *desc) -{ -return NULL ; -}static inline void pci_write_msi_msg (unsigned int irq,struct msi_msg *msg) { }
[tip: irq/msi] PCI/sysfs: Use pci_irq_vector()
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 793c5006769d77b8148236bc124b75e391110531 Gitweb: https://git.kernel.org/tip/793c5006769d77b8148236bc124b75e391110531 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:36 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
PCI/sysfs: Use pci_irq_vector()
instead of fiddling with MSI descriptors.
--- drivers/pci/pci-sysfs.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/pci/pci-sysfs.c +2 -5
@@ -62,11 +62,8 @@ static ssize_t irq_show(struct device *dev,* For MSI, show the first MSI IRQ; for all other cases including * MSI-X, show the legacy INTx IRQ. */ -if (pdev->msi_enabled) { -struct msi_desc *desc =first_pci_msi_entry (pdev); - -return sysfs_emit (buf,"%u\n" , desc->irq); - } +if (pdev->msi_enabled) +return sysfs_emit (buf,"%u\n" ,pci_irq_vector (pdev,0 ));#endif return sysfs_emit (buf,"%u\n" , pdev->irq);
[tip: irq/msi] PCI/MSI: Make pci_msi_domain_write_msg() static
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 9e8688c5f2990dadcf83728cd00a7e8497fc6aa9 Gitweb: https://git.kernel.org/tip/9e8688c5f2990dadcf83728cd00a7e8497fc6aa9 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:33 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
PCI/MSI: Make pci_msi_domain_write_msg() static
There is no point to have this function public as it is set by the PCI core anyway when a PCI/MSI irqdomain is created.
--- drivers/irqchip/irq-gic-v2m.c | 1 - drivers/irqchip/irq-gic-v3-its-pci-msi.c | 1 - drivers/irqchip/irq-gic-v3-mbi.c | 1 - drivers/pci/msi.c | 2 +- include/linux/msi.h | 1 - 5 files changed, 1 insertion(+), 5 deletions(-)
drivers/irqchip/irq-gic-v2m.c +0 -1
@@ -88,7 +88,6 @@ static struct irq_chip gicv2m_msi_irq_chip = { .irq_mask = gicv2m_mask_msi_irq, .irq_unmask = gicv2m_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info gicv2m_msi_domain_info = {
drivers/irqchip/irq-gic-v3-its-pci-msi.c +0 -1
@@ -28,7 +28,6 @@ static struct irq_chip its_msi_irq_chip = { .irq_unmask = its_unmask_msi_irq, .irq_mask = its_mask_msi_irq, .irq_eoi = irq_chip_eoi_parent, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static int its_pci_msi_vec_count (struct pci_dev *pdev,void *data)
drivers/irqchip/irq-gic-v3-mbi.c +0 -1
@@ -171,7 +171,6 @@ static struct irq_chip mbi_msi_irq_chip = { .irq_unmask = mbi_unmask_msi_irq, .irq_eoi = irq_chip_eoi_parent, .irq_compose_msi_msg = mbi_compose_msi_msg, - .irq_write_msi_msg = pci_msi_domain_write_msg, };static struct msi_domain_info mbi_msi_domain_info = {
drivers/pci/msi.c +1 -1
@@ -1281,7 +1281,7 @@ EXPORT_SYMBOL_GPL(msi_desc_to_pci_sysdata);* @irq_data: Pointer to interrupt data of the MSI interrupt * @msg: Pointer to the message */ -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) +static void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg) {struct msi_desc *desc =irq_data_get_msi_desc (irq_data);
include/linux/msi.h +0 -1
@@ -455,7 +455,6 @@ void *platform_msi_get_host_data(struct irq_domain *domain);#endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */ #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN -void pci_msi_domain_write_msg (struct irq_data *irq_data,struct msi_msg *msg);struct irq_domain *pci_msi_create_irq_domain (struct fwnode_handle *fwnode,struct msi_domain_info *info,struct irq_domain *parent);
[tip: irq/msi] genirq/msi: Fixup includes
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 3ba1f050c91d5ce3672dbf3a55dc2451c0b342e2 Gitweb: https://git.kernel.org/tip/3ba1f050c91d5ce3672dbf3a55dc2451c0b342e2 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:31 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
genirq/msi: Fixup includes
Remove the kobject.h include from msi.h as it's not required and add a sysfs.h include to the core code instead.
--- include/linux/msi.h | 2 +- kernel/irq/msi.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/msi.h +1 -1
@@ -2,7 +2,7 @@#ifndef LINUX_MSI_H #define LINUX_MSI_H -#include <linux/kobject.h> +#include <linux/cpumask.h> #include <linux/list.h> #include <asm/msi.h>
kernel/irq/msi.c +1 -0
@@ -14,6 +14,7 @@#include <linux/irqdomain.h> #include <linux/msi.h> #include <linux/slab.h> +#include <linux/sysfs.h> #include <linux/pci.h> #include "internals.h"
[tip: irq/msi] MIPS: Octeon: Use arch_setup_msi_irq()
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: bec61847cdc7ff22d6d85e6e6436d4b7416c1f9b Gitweb: https://git.kernel.org/tip/bec61847cdc7ff22d6d85e6e6436d4b7416c1f9b Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:38 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:21 +01:00
MIPS: Octeon: Use arch_setup_msi_irq()
The core code provides the same loop code except for the MSI-X reject. Move that to arch_setup_msi_irq() and remove the duplicated code.
No functional change.
--- arch/mips/pci/msi-octeon.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
arch/mips/pci/msi-octeon.c +3 -29
@@ -68,6 +68,9 @@ int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)u64 search_mask;int index; +if (desc->pci.msi_attrib.is_msix) +return -EINVAL ; +/* * Read the MSI config to figure out how many IRQs this device * wants. Most devices only want 1, which will give
@@ -182,35 +185,6 @@ msi_irq_allocated:return 0 ; } -int arch_setup_msi_irqs (struct pci_dev *dev,int nvec,int type) -{ -struct msi_desc *entry; -int ret; - -/* -* MSI-X is not supported. -*/ -if (type ==PCI_CAP_ID_MSIX ) -return -EINVAL ; - -/* -* If an architecture wants to support multiple MSI, it needs to -* override arch_setup_msi_irqs() -*/ -if (type ==PCI_CAP_ID_MSI && nvec >1 ) -return 1 ; - -for_each_pci_msi_entry (entry, dev) { - ret =arch_setup_msi_irq (dev, entry); -if (ret <0 ) -return ret; -if (ret >0 ) -return -ENOSPC ; - } - -return 0 ; -} -/** * Called when a device no longer needs its MSI interrupts. All * MSI interrupts for the device are freed.
[tip: irq/msi] genirq/msi: Guard sysfs code
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 1197528aaea79ed4909aba695d18fdecc5387a36 Gitweb: https://git.kernel.org/tip/1197528aaea79ed4909aba695d18fdecc5387a36 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:28 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
genirq/msi: Guard sysfs code
No point in building unused code when CONFIG_SYSFS=n.
--- include/linux/msi.h | 10 ++++++++++ kernel/irq/msi.c | 2 ++ 2 files changed, 12 insertions(+)
include/linux/msi.h +10 -0
@@ -239,9 +239,19 @@ void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);void pci_msi_mask_irq (struct irq_data *data);void pci_msi_unmask_irq (struct irq_data *data); +#ifdef CONFIG_SYSFS const struct attribute_group **msi_populate_sysfs (struct device *dev);void msi_destroy_sysfs (struct device *dev,const struct attribute_group **msi_irq_groups); +#else +static inline const struct attribute_group **msi_populate_sysfs (struct device *dev) +{ +return NULL ; +} +static inline void msi_destroy_sysfs (struct device *dev,const struct attribute_group **msi_irq_groups) +{ +} +#endif /* * The arch hooks to setup up msi irqs. Default functions are implemented
kernel/irq/msi.c +2 -0
@@ -72,6 +72,7 @@ void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg) }EXPORT_SYMBOL_GPL (get_cached_msi_msg); +#ifdef CONFIG_SYSFS static ssize_t msi_mode_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -204,6 +205,7 @@ void msi_destroy_sysfs(struct device *dev, const struct attribute_group **msi_ir kfree(msi_irq_groups); } } +#endif #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN static inline void irq_chip_write_msi_msg(struct irq_data *data,
[tip: irq/msi] PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 29bbc35e29d9b6347780dcacde2deb4b39344167 Gitweb: https://git.kernel.org/tip/29bbc35e29d9b6347780dcacde2deb4b39344167 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:26 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
PCI/MSI: Fix pci_irq_vector()/pci_irq_get_affinity()
pci_irq_vector() and pci_irq_get_affinity() use the list position to find the MSI-X descriptor at a given index. That's correct for the normal case where the entry number is the same as the list position.
But it's wrong for cases where MSI-X was allocated with an entries array describing sparse entry numbers into the hardware message descriptor table. That's inconsistent at best.
Make it always check the entry number because that's what the zero base index really means. This change won't break existing users which use a sparse entries array for allocation because these users retrieve the Linux interrupt number from the entries array after allocation and none of them uses pci_irq_vector() or pci_irq_get_affinity().
--- drivers/pci/msi.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/pci/msi.c +18 -8
@@ -1187,19 +1187,24 @@ EXPORT_SYMBOL(pci_free_irq_vectors);/** * pci_irq_vector - return Linux IRQ number of a device vector -* @dev: PCI device to operate on -* @nr: device-relative interrupt vector index (0-based). +* @dev: PCI device to operate on +* @nr: Interrupt vector index (0-based) +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: The Linux interrupt number or -EINVAl if @nr is out of range. */ int pci_irq_vector (struct pci_dev *dev,unsigned int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return entry->irq; - i++; }WARN_ON_ONCE (1 );return -EINVAL ;
@@ -1223,17 +1228,22 @@ EXPORT_SYMBOL(pci_irq_vector);* pci_irq_get_affinity - return the affinity of a particular MSI vector * @dev: PCI device to operate on * @nr: device-relative interrupt vector index (0-based). +* +* @nr has the following meanings depending on the interrupt mode: +* MSI-X: The index in the MSI-X vector table +* MSI: The index of the enabled MSI vectors +* INTx: Must be 0 +* +* Return: A cpumask pointer or NULL if @nr is out of range */ const struct cpumask *pci_irq_get_affinity (struct pci_dev *dev,int nr) {if (dev->msix_enabled) {struct msi_desc *entry; -int i =0 ;for_each_pci_msi_entry (entry, dev) { -if (i == nr) +if (entry->msi_attrib.entry_nr == nr)return &entry->affinity->mask; - i++; }WARN_ON_ONCE (1 );return NULL ;
[tip: irq/msi] powerpc/4xx: Complete removal of MSI support
In reply to Cédric Le GoaterThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: eca213152a36b381724251afaa5ce04ac551e3f7 Gitweb: https://git.kernel.org/tip/eca213152a36b381724251afaa5ce04ac551e3f7 Author: Cédric Le Goater <[email protected]> AuthorDate: Tue, 07 Dec 2021 16:32:50 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
powerpc/4xx: Complete removal of MSI support
Finish the work by removing all references to the PPC4xx_MSI config and the associated device nodes in the DTs.
--- arch/powerpc/boot/dts/bluestone.dts | 25 +----------------------- arch/powerpc/boot/dts/canyonlands.dts | 18 +----------------- arch/powerpc/boot/dts/katmai.dts | 18 +----------------- arch/powerpc/boot/dts/kilauea.dts | 28 +-------------------------- arch/powerpc/boot/dts/redwood.dts | 19 +------------------ arch/powerpc/platforms/40x/Kconfig | 1 +- arch/powerpc/platforms/44x/Kconfig | 4 +---- 7 files changed, 113 deletions(-)
arch/powerpc/boot/dts/bluestone.dts +0 -25
@@ -366,30 +366,5 @@ 0x0 0x0 0x0 0x3 &UIC3 0xe 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC3 0xf 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0xC 0x10000000 0x100 - 0xC 0x10000000 0x100>; - sdr-base = <0x36C>; - msi-data = <0x00004440>; - msi-mask = <0x0000ffe0>; - interrupts =<0 1 2 3 4 5 6 7>; - interrupt-parent = <&MSI>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - msi-available-ranges = <0x0 0x100>; - interrupt-map = < - 0 &UIC3 0x18 1 - 1 &UIC3 0x19 1 - 2 &UIC3 0x1A 1 - 3 &UIC3 0x1B 1 - 4 &UIC3 0x1C 1 - 5 &UIC3 0x1D 1 - 6 &UIC3 0x1E 1 - 7 &UIC3 0x1F 1 - >; - }; }; };
arch/powerpc/boot/dts/canyonlands.dts +0 -18
@@ -544,23 +544,5 @@ 0x0 0x0 0x0 0x3 &UIC3 0x12 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC3 0x13 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0xC 0x10000000 0x100>; - sdr-base = <0x36C>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts = <0 1 2 3>; - interrupt-parent = <&UIC3>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC3 0x18 1 - 1 &UIC3 0x19 1 - 2 &UIC3 0x1A 1 - 3 &UIC3 0x1B 1>; - }; }; };
arch/powerpc/boot/dts/katmai.dts +0 -18
@@ -442,24 +442,6 @@ 0x0 0x0 0x0 0x4 &UIC3 0xb 0x4 /* swizzled int D */>; }; - MSI: ppc4xx-msi@400300000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0x4 0x00300000 0x100>; - sdr-base = <0x3B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts =<0 1 2 3>; - interrupt-parent = <&UIC0>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC0 0xC 1 - 1 &UIC0 0x0D 1 - 2 &UIC0 0x0E 1 - 3 &UIC0 0x0F 1>; - }; - I2O: i2o@400100000 { compatible = "ibm,i2o-440spe"; reg = <0x00000004 0x00100000 0x100>;
arch/powerpc/boot/dts/kilauea.dts +0 -28
@@ -403,33 +403,5 @@ 0x0 0x0 0x0 0x3 &UIC2 0xd 0x4 /* swizzled int C */ 0x0 0x0 0x0 0x4 &UIC2 0xe 0x4 /* swizzled int D */>; }; - - MSI: ppc4xx-msi@C10000000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = <0xEF620000 0x100>; - sdr-base = <0x4B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <12>; - interrupts = <0 1 2 3 4 5 6 7 8 9 0xA 0xB 0xC 0xD>; - interrupt-parent = <&UIC2>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC2 0x10 1 - 1 &UIC2 0x11 1 - 2 &UIC2 0x12 1 - 2 &UIC2 0x13 1 - 2 &UIC2 0x14 1 - 2 &UIC2 0x15 1 - 2 &UIC2 0x16 1 - 2 &UIC2 0x17 1 - 2 &UIC2 0x18 1 - 2 &UIC2 0x19 1 - 2 &UIC2 0x1A 1 - 2 &UIC2 0x1B 1 - 2 &UIC2 0x1C 1 - 3 &UIC2 0x1D 1>; - }; }; };
arch/powerpc/boot/dts/redwood.dts +0 -19
@@ -358,25 +358,6 @@ 0x0 0x0 0x0 0x4 &UIC3 0xb 0x4 /* swizzled int D */>; }; - MSI: ppc4xx-msi@400300000 { - compatible = "amcc,ppc4xx-msi", "ppc4xx-msi"; - reg = < 0x4 0x00300000 0x100 - 0x4 0x00300000 0x100>; - sdr-base = <0x3B0>; - msi-data = <0x00000000>; - msi-mask = <0x44440000>; - interrupt-count = <3>; - interrupts =<0 1 2 3>; - interrupt-parent = <&UIC0>; - #interrupt-cells = <1>; - #address-cells = <0>; - #size-cells = <0>; - interrupt-map = <0 &UIC0 0xC 1 - 1 &UIC0 0x0D 1 - 2 &UIC0 0x0E 1 - 3 &UIC0 0x0F 1>; - }; - };
arch/powerpc/platforms/40x/Kconfig +0 -1
@@ -23,7 +23,6 @@ config KILAUEA select PPC4xx_PCI_EXPRESS select FORCE_PCI select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC405EX evaluation board.
arch/powerpc/platforms/44x/Kconfig +0 -4
@@ -23,7 +23,6 @@ config BLUESTONE select APM821xx select FORCE_PCI select PCI_MSI - select PPC4xx_MSI select PPC4xx_PCI_EXPRESS select IBM_EMAC_RGMII if IBM_EMAC help
@@ -73,7 +72,6 @@ config KATMAI select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC440SPe evaluation board.
@@ -115,7 +113,6 @@ config CANYONLANDS select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI select IBM_EMAC_RGMII if IBM_EMAC select IBM_EMAC_ZMII if IBM_EMAC help
@@ -141,7 +138,6 @@ config REDWOOD select FORCE_PCI select PPC4xx_PCI_EXPRESS select PCI_MSI - select PPC4xx_MSI help This option enables support for the AMCC PPC460SX Redwood board.
[tip: irq/msi] powerpc/4xx: Remove MSI support which never worked
In reply to Thomas GleixnerThe following commit has been merged into the irq/msi branch of tip:
The following commit has been merged into the irq/msi branch of tip:
Commit-ID: 4f1d038b5ea1b45d8265a5407712f975b600bb94 Gitweb: https://git.kernel.org/tip/4f1d038b5ea1b45d8265a5407712f975b600bb94 Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 06 Dec 2021 23:27:25 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 09 Dec 2021 11:52:20 +01:00
powerpc/4xx: Remove MSI support which never worked
This code is broken since day one. ppc4xx_setup_msi_irqs() has the following gems:
1) The handling of the result of msi_bitmap_alloc_hwirqs() is completely broken:
When the result is greater than or equal 0 (bitmap allocation successful) then the loop terminates and the function returns 0 (success) despite not having installed an interrupt.
When the result is less than 0 (bitmap allocation fails), it prints an error message and continues to "work" with that error code which would eventually end up in the MSI message data.
2) On every invocation the file global pp4xx_msi::msi_virqs bitmap is allocated thereby leaking the previous one.
IOW, this has never worked and for more than 10 years nobody cared. Remove the gunk.
--- arch/powerpc/platforms/4xx/Makefile | 1 +- arch/powerpc/platforms/4xx/msi.c | 281 +--------------------------- arch/powerpc/sysdev/Kconfig | 6 +- 3 files changed, 288 deletions(-) delete mode 100644 arch/powerpc/platforms/4xx/msi.c
arch/powerpc/platforms/4xx/Makefile +0 -1
@@ -3,6 +3,5 @@ obj-y += uic.o machine_check.o obj-$(CONFIG_4xx_SOC) += soc.o obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PPC4xx_HSTA_MSI) += hsta_msi.o -obj-$(CONFIG_PPC4xx_MSI) += msi.o obj-$(CONFIG_PPC4xx_CPM) += cpm.o obj-$(CONFIG_PPC4xx_GPIO) += gpio.o
arch/powerpc/platforms/4xx/msi.c deleted +0 -281
281 lines not on this page · raw message
arch/powerpc/sysdev/Kconfig +0 -6
@@ -12,17 +12,11 @@ config PPC4xx_HSTA_MSI depends on PCI_MSI depends on PCI && 4xx -config PPC4xx_MSI - bool - depends on PCI_MSI - depends on PCI && 4xx - config PPC_MSI_BITMAP bool depends on PCI_MSI default y if MPIC default y if FSL_PCI - default y if PPC4xx_MSI default y if PPC_POWERNV source "arch/powerpc/sysdev/xics/Kconfig"