Commit 1d55abc0 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Martin K. Petersen

scsi: mpt3sas: switch to pci_alloc_irq_vectors

Cleanup the MSI-X handling allowing us to use the PCI-layer provided
vector allocation.
Signed-off-by: default avatarHannes Reinecke <hare@suse.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarSreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 1afca6b5
...@@ -1148,7 +1148,7 @@ mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER *ioc) ...@@ -1148,7 +1148,7 @@ mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER *ioc)
/* TMs are on msix_index == 0 */ /* TMs are on msix_index == 0 */
if (reply_q->msix_index == 0) if (reply_q->msix_index == 0)
continue; continue;
synchronize_irq(reply_q->vector); synchronize_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index));
} }
} }
...@@ -1837,11 +1837,8 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc) ...@@ -1837,11 +1837,8 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc)
list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
list_del(&reply_q->list); list_del(&reply_q->list);
if (smp_affinity_enable) { free_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index),
irq_set_affinity_hint(reply_q->vector, NULL); reply_q);
free_cpumask_var(reply_q->affinity_hint);
}
free_irq(reply_q->vector, reply_q);
kfree(reply_q); kfree(reply_q);
} }
} }
...@@ -1850,13 +1847,13 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc) ...@@ -1850,13 +1847,13 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc)
* _base_request_irq - request irq * _base_request_irq - request irq
* @ioc: per adapter object * @ioc: per adapter object
* @index: msix index into vector table * @index: msix index into vector table
* @vector: irq vector
* *
* Inserting respective reply_queue into the list. * Inserting respective reply_queue into the list.
*/ */
static int static int
_base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector) _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index)
{ {
struct pci_dev *pdev = ioc->pdev;
struct adapter_reply_queue *reply_q; struct adapter_reply_queue *reply_q;
int r; int r;
...@@ -1868,14 +1865,6 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector) ...@@ -1868,14 +1865,6 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
} }
reply_q->ioc = ioc; reply_q->ioc = ioc;
reply_q->msix_index = index; reply_q->msix_index = index;
reply_q->vector = vector;
if (smp_affinity_enable) {
if (!zalloc_cpumask_var(&reply_q->affinity_hint, GFP_KERNEL)) {
kfree(reply_q);
return -ENOMEM;
}
}
atomic_set(&reply_q->busy, 0); atomic_set(&reply_q->busy, 0);
if (ioc->msix_enable) if (ioc->msix_enable)
...@@ -1884,12 +1873,11 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector) ...@@ -1884,12 +1873,11 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
else else
snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
ioc->driver_name, ioc->id); ioc->driver_name, ioc->id);
r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name, r = request_irq(pci_irq_vector(pdev, index), _base_interrupt,
reply_q); IRQF_SHARED, reply_q->name, reply_q);
if (r) { if (r) {
pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n", pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n",
reply_q->name, vector); reply_q->name, pci_irq_vector(pdev, index));
free_cpumask_var(reply_q->affinity_hint);
kfree(reply_q); kfree(reply_q);
return -EBUSY; return -EBUSY;
} }
...@@ -1925,6 +1913,21 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc) ...@@ -1925,6 +1913,21 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
if (!nr_msix) if (!nr_msix)
return; return;
if (smp_affinity_enable) {
list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
const cpumask_t *mask = pci_irq_get_affinity(ioc->pdev,
reply_q->msix_index);
if (!mask) {
pr_warn(MPT3SAS_FMT "no affinity for msi %x\n",
ioc->name, reply_q->msix_index);
continue;
}
for_each_cpu(cpu, mask)
ioc->cpu_msix_table[cpu] = reply_q->msix_index;
}
return;
}
cpu = cpumask_first(cpu_online_mask); cpu = cpumask_first(cpu_online_mask);
list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
...@@ -1938,18 +1941,9 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc) ...@@ -1938,18 +1941,9 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
group++; group++;
for (i = 0 ; i < group ; i++) { for (i = 0 ; i < group ; i++) {
ioc->cpu_msix_table[cpu] = index; ioc->cpu_msix_table[cpu] = reply_q->msix_index;
if (smp_affinity_enable)
cpumask_or(reply_q->affinity_hint,
reply_q->affinity_hint, get_cpu_mask(cpu));
cpu = cpumask_next(cpu, cpu_online_mask); cpu = cpumask_next(cpu, cpu_online_mask);
} }
if (smp_affinity_enable)
if (irq_set_affinity_hint(reply_q->vector,
reply_q->affinity_hint))
dinitprintk(ioc, pr_info(MPT3SAS_FMT
"Err setting affinity hint to irq vector %d\n",
ioc->name, reply_q->vector));
index++; index++;
} }
} }
...@@ -1976,10 +1970,10 @@ _base_disable_msix(struct MPT3SAS_ADAPTER *ioc) ...@@ -1976,10 +1970,10 @@ _base_disable_msix(struct MPT3SAS_ADAPTER *ioc)
static int static int
_base_enable_msix(struct MPT3SAS_ADAPTER *ioc) _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
{ {
struct msix_entry *entries, *a;
int r; int r;
int i, local_max_msix_vectors; int i, local_max_msix_vectors;
u8 try_msix = 0; u8 try_msix = 0;
unsigned int irq_flags = PCI_IRQ_MSIX;
if (msix_disable == -1 || msix_disable == 0) if (msix_disable == -1 || msix_disable == 0)
try_msix = 1; try_msix = 1;
...@@ -1991,7 +1985,7 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc) ...@@ -1991,7 +1985,7 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
goto try_ioapic; goto try_ioapic;
ioc->reply_queue_count = min_t(int, ioc->cpu_count, ioc->reply_queue_count = min_t(int, ioc->cpu_count,
ioc->msix_vector_count); ioc->msix_vector_count);
printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores" printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores"
": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count, ": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count,
...@@ -2002,56 +1996,51 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc) ...@@ -2002,56 +1996,51 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
else else
local_max_msix_vectors = max_msix_vectors; local_max_msix_vectors = max_msix_vectors;
if (local_max_msix_vectors > 0) { if (local_max_msix_vectors > 0)
ioc->reply_queue_count = min_t(int, local_max_msix_vectors, ioc->reply_queue_count = min_t(int, local_max_msix_vectors,
ioc->reply_queue_count); ioc->reply_queue_count);
ioc->msix_vector_count = ioc->reply_queue_count; else if (local_max_msix_vectors == 0)
} else if (local_max_msix_vectors == 0)
goto try_ioapic; goto try_ioapic;
if (ioc->msix_vector_count < ioc->cpu_count) if (ioc->msix_vector_count < ioc->cpu_count)
smp_affinity_enable = 0; smp_affinity_enable = 0;
entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry), if (smp_affinity_enable)
GFP_KERNEL); irq_flags |= PCI_IRQ_AFFINITY;
if (!entries) {
dfailprintk(ioc, pr_info(MPT3SAS_FMT
"kcalloc failed @ at %s:%d/%s() !!!\n",
ioc->name, __FILE__, __LINE__, __func__));
goto try_ioapic;
}
for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) r = pci_alloc_irq_vectors(ioc->pdev, 1, ioc->reply_queue_count,
a->entry = i; irq_flags);
if (r < 0) {
r = pci_enable_msix_exact(ioc->pdev, entries, ioc->reply_queue_count);
if (r) {
dfailprintk(ioc, pr_info(MPT3SAS_FMT dfailprintk(ioc, pr_info(MPT3SAS_FMT
"pci_enable_msix_exact failed (r=%d) !!!\n", "pci_alloc_irq_vectors failed (r=%d) !!!\n",
ioc->name, r)); ioc->name, r));
kfree(entries);
goto try_ioapic; goto try_ioapic;
} }
ioc->msix_enable = 1; ioc->msix_enable = 1;
for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) { ioc->reply_queue_count = r;
r = _base_request_irq(ioc, i, a->vector); for (i = 0; i < ioc->reply_queue_count; i++) {
r = _base_request_irq(ioc, i);
if (r) { if (r) {
_base_free_irq(ioc); _base_free_irq(ioc);
_base_disable_msix(ioc); _base_disable_msix(ioc);
kfree(entries);
goto try_ioapic; goto try_ioapic;
} }
} }
kfree(entries);
return 0; return 0;
/* failback to io_apic interrupt routing */ /* failback to io_apic interrupt routing */
try_ioapic: try_ioapic:
ioc->reply_queue_count = 1; ioc->reply_queue_count = 1;
r = _base_request_irq(ioc, 0, ioc->pdev->irq); r = pci_alloc_irq_vectors(ioc->pdev, 1, 1, PCI_IRQ_LEGACY);
if (r < 0) {
dfailprintk(ioc, pr_info(MPT3SAS_FMT
"pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n",
ioc->name, r));
} else
r = _base_request_irq(ioc, 0);
return r; return r;
} }
...@@ -2222,7 +2211,8 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) ...@@ -2222,7 +2211,8 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
list_for_each_entry(reply_q, &ioc->reply_queue_list, list) list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
pr_info(MPT3SAS_FMT "%s: IRQ %d\n", pr_info(MPT3SAS_FMT "%s: IRQ %d\n",
reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
"IO-APIC enabled"), reply_q->vector); "IO-APIC enabled"),
pci_irq_vector(ioc->pdev, reply_q->msix_index));
pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n", pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz); ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
...@@ -5357,7 +5347,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) ...@@ -5357,7 +5347,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
sizeof(resource_size_t *), GFP_KERNEL); sizeof(resource_size_t *), GFP_KERNEL);
if (!ioc->reply_post_host_index) { if (!ioc->reply_post_host_index) {
dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation " dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation "
"for cpu_msix_table failed!!!\n", ioc->name)); "for reply_post_host_index failed!!!\n",
ioc->name));
r = -ENOMEM; r = -ENOMEM;
goto out_free_resources; goto out_free_resources;
} }
......
...@@ -731,12 +731,10 @@ struct _event_ack_list { ...@@ -731,12 +731,10 @@ struct _event_ack_list {
struct adapter_reply_queue { struct adapter_reply_queue {
struct MPT3SAS_ADAPTER *ioc; struct MPT3SAS_ADAPTER *ioc;
u8 msix_index; u8 msix_index;
unsigned int vector;
u32 reply_post_host_index; u32 reply_post_host_index;
Mpi2ReplyDescriptorsUnion_t *reply_post_free; Mpi2ReplyDescriptorsUnion_t *reply_post_free;
char name[MPT_NAME_LENGTH]; char name[MPT_NAME_LENGTH];
atomic_t busy; atomic_t busy;
cpumask_var_t affinity_hint;
struct list_head list; struct list_head list;
}; };
......
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