Skip to content

Commit 1d55abc

Browse files
hreineckemartinkpetersen
authored andcommitted
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: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Acked-by: Sreekanth Reddy <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 1afca6b commit 1d55abc

File tree

2 files changed

+48
-59
lines changed

2 files changed

+48
-59
lines changed

drivers/scsi/mpt3sas/mpt3sas_base.c

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER *ioc)
11481148
/* TMs are on msix_index == 0 */
11491149
if (reply_q->msix_index == 0)
11501150
continue;
1151-
synchronize_irq(reply_q->vector);
1151+
synchronize_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index));
11521152
}
11531153
}
11541154

@@ -1837,11 +1837,8 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc)
18371837

18381838
list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
18391839
list_del(&reply_q->list);
1840-
if (smp_affinity_enable) {
1841-
irq_set_affinity_hint(reply_q->vector, NULL);
1842-
free_cpumask_var(reply_q->affinity_hint);
1843-
}
1844-
free_irq(reply_q->vector, reply_q);
1840+
free_irq(pci_irq_vector(ioc->pdev, reply_q->msix_index),
1841+
reply_q);
18451842
kfree(reply_q);
18461843
}
18471844
}
@@ -1850,13 +1847,13 @@ _base_free_irq(struct MPT3SAS_ADAPTER *ioc)
18501847
* _base_request_irq - request irq
18511848
* @ioc: per adapter object
18521849
* @index: msix index into vector table
1853-
* @vector: irq vector
18541850
*
18551851
* Inserting respective reply_queue into the list.
18561852
*/
18571853
static int
1858-
_base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
1854+
_base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index)
18591855
{
1856+
struct pci_dev *pdev = ioc->pdev;
18601857
struct adapter_reply_queue *reply_q;
18611858
int r;
18621859

@@ -1868,14 +1865,6 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
18681865
}
18691866
reply_q->ioc = ioc;
18701867
reply_q->msix_index = index;
1871-
reply_q->vector = vector;
1872-
1873-
if (smp_affinity_enable) {
1874-
if (!zalloc_cpumask_var(&reply_q->affinity_hint, GFP_KERNEL)) {
1875-
kfree(reply_q);
1876-
return -ENOMEM;
1877-
}
1878-
}
18791868

18801869
atomic_set(&reply_q->busy, 0);
18811870
if (ioc->msix_enable)
@@ -1884,12 +1873,11 @@ _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector)
18841873
else
18851874
snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
18861875
ioc->driver_name, ioc->id);
1887-
r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1888-
reply_q);
1876+
r = request_irq(pci_irq_vector(pdev, index), _base_interrupt,
1877+
IRQF_SHARED, reply_q->name, reply_q);
18891878
if (r) {
18901879
pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n",
1891-
reply_q->name, vector);
1892-
free_cpumask_var(reply_q->affinity_hint);
1880+
reply_q->name, pci_irq_vector(pdev, index));
18931881
kfree(reply_q);
18941882
return -EBUSY;
18951883
}
@@ -1925,6 +1913,21 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
19251913
if (!nr_msix)
19261914
return;
19271915

1916+
if (smp_affinity_enable) {
1917+
list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
1918+
const cpumask_t *mask = pci_irq_get_affinity(ioc->pdev,
1919+
reply_q->msix_index);
1920+
if (!mask) {
1921+
pr_warn(MPT3SAS_FMT "no affinity for msi %x\n",
1922+
ioc->name, reply_q->msix_index);
1923+
continue;
1924+
}
1925+
1926+
for_each_cpu(cpu, mask)
1927+
ioc->cpu_msix_table[cpu] = reply_q->msix_index;
1928+
}
1929+
return;
1930+
}
19281931
cpu = cpumask_first(cpu_online_mask);
19291932

19301933
list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
@@ -1938,18 +1941,9 @@ _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc)
19381941
group++;
19391942

19401943
for (i = 0 ; i < group ; i++) {
1941-
ioc->cpu_msix_table[cpu] = index;
1942-
if (smp_affinity_enable)
1943-
cpumask_or(reply_q->affinity_hint,
1944-
reply_q->affinity_hint, get_cpu_mask(cpu));
1944+
ioc->cpu_msix_table[cpu] = reply_q->msix_index;
19451945
cpu = cpumask_next(cpu, cpu_online_mask);
19461946
}
1947-
if (smp_affinity_enable)
1948-
if (irq_set_affinity_hint(reply_q->vector,
1949-
reply_q->affinity_hint))
1950-
dinitprintk(ioc, pr_info(MPT3SAS_FMT
1951-
"Err setting affinity hint to irq vector %d\n",
1952-
ioc->name, reply_q->vector));
19531947
index++;
19541948
}
19551949
}
@@ -1976,10 +1970,10 @@ _base_disable_msix(struct MPT3SAS_ADAPTER *ioc)
19761970
static int
19771971
_base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
19781972
{
1979-
struct msix_entry *entries, *a;
19801973
int r;
19811974
int i, local_max_msix_vectors;
19821975
u8 try_msix = 0;
1976+
unsigned int irq_flags = PCI_IRQ_MSIX;
19831977

19841978
if (msix_disable == -1 || msix_disable == 0)
19851979
try_msix = 1;
@@ -1991,7 +1985,7 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
19911985
goto try_ioapic;
19921986

19931987
ioc->reply_queue_count = min_t(int, ioc->cpu_count,
1994-
ioc->msix_vector_count);
1988+
ioc->msix_vector_count);
19951989

19961990
printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores"
19971991
": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count,
@@ -2002,56 +1996,51 @@ _base_enable_msix(struct MPT3SAS_ADAPTER *ioc)
20021996
else
20031997
local_max_msix_vectors = max_msix_vectors;
20041998

2005-
if (local_max_msix_vectors > 0) {
1999+
if (local_max_msix_vectors > 0)
20062000
ioc->reply_queue_count = min_t(int, local_max_msix_vectors,
20072001
ioc->reply_queue_count);
2008-
ioc->msix_vector_count = ioc->reply_queue_count;
2009-
} else if (local_max_msix_vectors == 0)
2002+
else if (local_max_msix_vectors == 0)
20102003
goto try_ioapic;
20112004

20122005
if (ioc->msix_vector_count < ioc->cpu_count)
20132006
smp_affinity_enable = 0;
20142007

2015-
entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
2016-
GFP_KERNEL);
2017-
if (!entries) {
2018-
dfailprintk(ioc, pr_info(MPT3SAS_FMT
2019-
"kcalloc failed @ at %s:%d/%s() !!!\n",
2020-
ioc->name, __FILE__, __LINE__, __func__));
2021-
goto try_ioapic;
2022-
}
2008+
if (smp_affinity_enable)
2009+
irq_flags |= PCI_IRQ_AFFINITY;
20232010

2024-
for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
2025-
a->entry = i;
2026-
2027-
r = pci_enable_msix_exact(ioc->pdev, entries, ioc->reply_queue_count);
2028-
if (r) {
2011+
r = pci_alloc_irq_vectors(ioc->pdev, 1, ioc->reply_queue_count,
2012+
irq_flags);
2013+
if (r < 0) {
20292014
dfailprintk(ioc, pr_info(MPT3SAS_FMT
2030-
"pci_enable_msix_exact failed (r=%d) !!!\n",
2015+
"pci_alloc_irq_vectors failed (r=%d) !!!\n",
20312016
ioc->name, r));
2032-
kfree(entries);
20332017
goto try_ioapic;
20342018
}
20352019

20362020
ioc->msix_enable = 1;
2037-
for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
2038-
r = _base_request_irq(ioc, i, a->vector);
2021+
ioc->reply_queue_count = r;
2022+
for (i = 0; i < ioc->reply_queue_count; i++) {
2023+
r = _base_request_irq(ioc, i);
20392024
if (r) {
20402025
_base_free_irq(ioc);
20412026
_base_disable_msix(ioc);
2042-
kfree(entries);
20432027
goto try_ioapic;
20442028
}
20452029
}
20462030

2047-
kfree(entries);
20482031
return 0;
20492032

20502033
/* failback to io_apic interrupt routing */
20512034
try_ioapic:
20522035

20532036
ioc->reply_queue_count = 1;
2054-
r = _base_request_irq(ioc, 0, ioc->pdev->irq);
2037+
r = pci_alloc_irq_vectors(ioc->pdev, 1, 1, PCI_IRQ_LEGACY);
2038+
if (r < 0) {
2039+
dfailprintk(ioc, pr_info(MPT3SAS_FMT
2040+
"pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n",
2041+
ioc->name, r));
2042+
} else
2043+
r = _base_request_irq(ioc, 0);
20552044

20562045
return r;
20572046
}
@@ -2222,7 +2211,8 @@ mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc)
22222211
list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
22232212
pr_info(MPT3SAS_FMT "%s: IRQ %d\n",
22242213
reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
2225-
"IO-APIC enabled"), reply_q->vector);
2214+
"IO-APIC enabled"),
2215+
pci_irq_vector(ioc->pdev, reply_q->msix_index));
22262216

22272217
pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
22282218
ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
@@ -5357,7 +5347,8 @@ mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc)
53575347
sizeof(resource_size_t *), GFP_KERNEL);
53585348
if (!ioc->reply_post_host_index) {
53595349
dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation "
5360-
"for cpu_msix_table failed!!!\n", ioc->name));
5350+
"for reply_post_host_index failed!!!\n",
5351+
ioc->name));
53615352
r = -ENOMEM;
53625353
goto out_free_resources;
53635354
}

drivers/scsi/mpt3sas/mpt3sas_base.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,10 @@ struct _event_ack_list {
731731
struct adapter_reply_queue {
732732
struct MPT3SAS_ADAPTER *ioc;
733733
u8 msix_index;
734-
unsigned int vector;
735734
u32 reply_post_host_index;
736735
Mpi2ReplyDescriptorsUnion_t *reply_post_free;
737736
char name[MPT_NAME_LENGTH];
738737
atomic_t busy;
739-
cpumask_var_t affinity_hint;
740738
struct list_head list;
741739
};
742740

0 commit comments

Comments
 (0)