Commit 61e1c590 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Thomas Gleixner

PCI/MSI: Propagate IRQ affinity description through the MSI code

No API change yet, just pass it down all the way from
pci_alloc_irq_vectors() to the core MSI code.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarJens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Link: http://lkml.kernel.org/r/1478654107-7384-5-git-send-email-hch@lst.deSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 67c93c21
...@@ -551,15 +551,14 @@ static int populate_msi_sysfs(struct pci_dev *pdev) ...@@ -551,15 +551,14 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
} }
static struct msi_desc * static struct msi_desc *
msi_setup_entry(struct pci_dev *dev, int nvec, bool affinity) msi_setup_entry(struct pci_dev *dev, int nvec, const struct irq_affinity *affd)
{ {
static const struct irq_affinity default_affd;
struct cpumask *masks = NULL; struct cpumask *masks = NULL;
struct msi_desc *entry; struct msi_desc *entry;
u16 control; u16 control;
if (affinity) { if (affd) {
masks = irq_create_affinity_masks(nvec, &default_affd); masks = irq_create_affinity_masks(nvec, affd);
if (!masks) if (!masks)
pr_err("Unable to allocate affinity masks, ignoring\n"); pr_err("Unable to allocate affinity masks, ignoring\n");
} }
...@@ -619,7 +618,8 @@ static int msi_verify_entries(struct pci_dev *dev) ...@@ -619,7 +618,8 @@ static int msi_verify_entries(struct pci_dev *dev)
* an error, and a positive return value indicates the number of interrupts * an error, and a positive return value indicates the number of interrupts
* which could have been allocated. * which could have been allocated.
*/ */
static int msi_capability_init(struct pci_dev *dev, int nvec, bool affinity) static int msi_capability_init(struct pci_dev *dev, int nvec,
const struct irq_affinity *affd)
{ {
struct msi_desc *entry; struct msi_desc *entry;
int ret; int ret;
...@@ -627,7 +627,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec, bool affinity) ...@@ -627,7 +627,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec, bool affinity)
pci_msi_set_enable(dev, 0); /* Disable MSI during set up */ pci_msi_set_enable(dev, 0); /* Disable MSI during set up */
entry = msi_setup_entry(dev, nvec, affinity); entry = msi_setup_entry(dev, nvec, affd);
if (!entry) if (!entry)
return -ENOMEM; return -ENOMEM;
...@@ -691,15 +691,14 @@ static void __iomem *msix_map_region(struct pci_dev *dev, unsigned nr_entries) ...@@ -691,15 +691,14 @@ static void __iomem *msix_map_region(struct pci_dev *dev, unsigned nr_entries)
static int msix_setup_entries(struct pci_dev *dev, void __iomem *base, static int msix_setup_entries(struct pci_dev *dev, void __iomem *base,
struct msix_entry *entries, int nvec, struct msix_entry *entries, int nvec,
bool affinity) const struct irq_affinity *affd)
{ {
static const struct irq_affinity default_affd;
struct cpumask *curmsk, *masks = NULL; struct cpumask *curmsk, *masks = NULL;
struct msi_desc *entry; struct msi_desc *entry;
int ret, i; int ret, i;
if (affinity) { if (affd) {
masks = irq_create_affinity_masks(nvec, &default_affd); masks = irq_create_affinity_masks(nvec, affd);
if (!masks) if (!masks)
pr_err("Unable to allocate affinity masks, ignoring\n"); pr_err("Unable to allocate affinity masks, ignoring\n");
} }
...@@ -755,14 +754,14 @@ static void msix_program_entries(struct pci_dev *dev, ...@@ -755,14 +754,14 @@ static void msix_program_entries(struct pci_dev *dev,
* @dev: pointer to the pci_dev data structure of MSI-X device function * @dev: pointer to the pci_dev data structure of MSI-X device function
* @entries: pointer to an array of struct msix_entry entries * @entries: pointer to an array of struct msix_entry entries
* @nvec: number of @entries * @nvec: number of @entries
* @affinity: flag to indicate cpu irq affinity mask should be set * @affd: Optional pointer to enable automatic affinity assignement
* *
* Setup the MSI-X capability structure of device function with a * Setup the MSI-X capability structure of device function with a
* single MSI-X irq. A return of zero indicates the successful setup of * 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. * 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, static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
int nvec, bool affinity) int nvec, const struct irq_affinity *affd)
{ {
int ret; int ret;
u16 control; u16 control;
...@@ -777,7 +776,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, ...@@ -777,7 +776,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
if (!base) if (!base)
return -ENOMEM; return -ENOMEM;
ret = msix_setup_entries(dev, base, entries, nvec, affinity); ret = msix_setup_entries(dev, base, entries, nvec, affd);
if (ret) if (ret)
return ret; return ret;
...@@ -958,7 +957,7 @@ int pci_msix_vec_count(struct pci_dev *dev) ...@@ -958,7 +957,7 @@ int pci_msix_vec_count(struct pci_dev *dev)
EXPORT_SYMBOL(pci_msix_vec_count); EXPORT_SYMBOL(pci_msix_vec_count);
static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries,
int nvec, bool affinity) int nvec, const struct irq_affinity *affd)
{ {
int nr_entries; int nr_entries;
int i, j; int i, j;
...@@ -990,7 +989,7 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, ...@@ -990,7 +989,7 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries,
dev_info(&dev->dev, "can't enable MSI-X (MSI IRQ already assigned)\n"); dev_info(&dev->dev, "can't enable MSI-X (MSI IRQ already assigned)\n");
return -EINVAL; return -EINVAL;
} }
return msix_capability_init(dev, entries, nvec, affinity); return msix_capability_init(dev, entries, nvec, affd);
} }
/** /**
...@@ -1010,7 +1009,7 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, ...@@ -1010,7 +1009,7 @@ static int __pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries,
**/ **/
int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec) int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
{ {
return __pci_enable_msix(dev, entries, nvec, false); return __pci_enable_msix(dev, entries, nvec, NULL);
} }
EXPORT_SYMBOL(pci_enable_msix); EXPORT_SYMBOL(pci_enable_msix);
...@@ -1061,10 +1060,8 @@ int pci_msi_enabled(void) ...@@ -1061,10 +1060,8 @@ int pci_msi_enabled(void)
EXPORT_SYMBOL(pci_msi_enabled); EXPORT_SYMBOL(pci_msi_enabled);
static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
unsigned int flags) const struct irq_affinity *affd)
{ {
static const struct irq_affinity default_affd;
bool affinity = flags & PCI_IRQ_AFFINITY;
int nvec; int nvec;
int rc; int rc;
...@@ -1093,13 +1090,13 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, ...@@ -1093,13 +1090,13 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
nvec = maxvec; nvec = maxvec;
for (;;) { for (;;) {
if (affinity) { if (affd) {
nvec = irq_calc_affinity_vectors(nvec, &default_affd); nvec = irq_calc_affinity_vectors(nvec, affd);
if (nvec < minvec) if (nvec < minvec)
return -ENOSPC; return -ENOSPC;
} }
rc = msi_capability_init(dev, nvec, affinity); rc = msi_capability_init(dev, nvec, affd);
if (rc == 0) if (rc == 0)
return nvec; return nvec;
...@@ -1126,29 +1123,27 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, ...@@ -1126,29 +1123,27 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
**/ **/
int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec)
{ {
return __pci_enable_msi_range(dev, minvec, maxvec, 0); return __pci_enable_msi_range(dev, minvec, maxvec, NULL);
} }
EXPORT_SYMBOL(pci_enable_msi_range); EXPORT_SYMBOL(pci_enable_msi_range);
static int __pci_enable_msix_range(struct pci_dev *dev, static int __pci_enable_msix_range(struct pci_dev *dev,
struct msix_entry *entries, int minvec, int maxvec, struct msix_entry *entries, int minvec,
unsigned int flags) int maxvec, const struct irq_affinity *affd)
{ {
static const struct irq_affinity default_affd;
bool affinity = flags & PCI_IRQ_AFFINITY;
int rc, nvec = maxvec; int rc, nvec = maxvec;
if (maxvec < minvec) if (maxvec < minvec)
return -ERANGE; return -ERANGE;
for (;;) { for (;;) {
if (affinity) { if (affd) {
nvec = irq_calc_affinity_vectors(nvec, &default_affd); nvec = irq_calc_affinity_vectors(nvec, affd);
if (nvec < minvec) if (nvec < minvec)
return -ENOSPC; return -ENOSPC;
} }
rc = __pci_enable_msix(dev, entries, nvec, affinity); rc = __pci_enable_msix(dev, entries, nvec, affd);
if (rc == 0) if (rc == 0)
return nvec; return nvec;
...@@ -1179,7 +1174,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev, ...@@ -1179,7 +1174,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
int minvec, int maxvec) int minvec, int maxvec)
{ {
return __pci_enable_msix_range(dev, entries, minvec, maxvec, 0); return __pci_enable_msix_range(dev, entries, minvec, maxvec, NULL);
} }
EXPORT_SYMBOL(pci_enable_msix_range); EXPORT_SYMBOL(pci_enable_msix_range);
...@@ -1203,17 +1198,22 @@ EXPORT_SYMBOL(pci_enable_msix_range); ...@@ -1203,17 +1198,22 @@ EXPORT_SYMBOL(pci_enable_msix_range);
int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs, int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
unsigned int max_vecs, unsigned int flags) unsigned int max_vecs, unsigned int flags)
{ {
static const struct irq_affinity msi_default_affd;
const struct irq_affinity *affd = NULL;
int vecs = -ENOSPC; int vecs = -ENOSPC;
if (flags & PCI_IRQ_AFFINITY)
affd = &msi_default_affd;
if (flags & PCI_IRQ_MSIX) { if (flags & PCI_IRQ_MSIX) {
vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs, vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
flags); affd);
if (vecs > 0) if (vecs > 0)
return vecs; return vecs;
} }
if (flags & PCI_IRQ_MSI) { if (flags & PCI_IRQ_MSI) {
vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, flags); vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd);
if (vecs > 0) if (vecs > 0)
return vecs; return vecs;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment