Skip to content

Commit 4fe0d15

Browse files
Christoph Hellwigbjorn-helgaas
authored andcommitted
PCI: Use positive flags in pci_alloc_irq_vectors()
Instead of passing negative flags like PCI_IRQ_NOMSI to prevent use of certain interrupt types, pass positive flags like PCI_IRQ_LEGACY, PCI_IRQ_MSI, etc., to specify the acceptable interrupt types. This is based on a number of pending driver conversions that just happend to be a whole more obvious to read this way, and given that we have no users in the tree yet it can still easily be done. I've also added a PCI_IRQ_ALL_TYPES catchall to keep the case of accepting all interrupt types very simple. [bhelgaas: changelog, fix PCI_IRQ_AFFINITY doc typo, remove mention of PCI_IRQ_NOLEGACY] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Alexander Gordeev <[email protected]>
1 parent 8b078c6 commit 4fe0d15

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

Documentation/PCI/MSI-HOWTO.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,11 @@ has a requirements for a minimum number of vectors the driver can pass a
9494
min_vecs argument set to this limit, and the PCI core will return -ENOSPC
9595
if it can't meet the minimum number of vectors.
9696

97-
The flags argument should normally be set to 0, but can be used to pass the
98-
PCI_IRQ_NOMSI and PCI_IRQ_NOMSIX flag in case a device claims to support
99-
MSI or MSI-X, but the support is broken, or to pass PCI_IRQ_NOLEGACY in
100-
case the device does not support legacy interrupt lines.
101-
102-
By default this function will spread the interrupts around the available
103-
CPUs, but this feature can be disabled by passing the PCI_IRQ_NOAFFINITY
104-
flag.
97+
The flags argument is used to specify which type of interrupt can be used
98+
by the device and the driver (PCI_IRQ_LEGACY, PCI_IRQ_MSI, PCI_IRQ_MSIX).
99+
A convenient short-hand (PCI_IRQ_ALL_TYPES) is also available to ask for
100+
any possible kind of interrupt. If the PCI_IRQ_AFFINITY flag is set,
101+
pci_alloc_irq_vectors() will spread the interrupts around the available CPUs.
105102

106103
To get the Linux IRQ numbers passed to request_irq() and free_irq() and the
107104
vectors, use the following function:
@@ -131,7 +128,7 @@ larger than the number supported by the device it will automatically be
131128
capped to the supported limit, so there is no need to query the number of
132129
vectors supported beforehand:
133130

134-
nvec = pci_alloc_irq_vectors(pdev, 1, nvec, 0);
131+
nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_ALL_TYPES)
135132
if (nvec < 0)
136133
goto out_err;
137134

@@ -140,23 +137,22 @@ interrupts it can request a particular number of interrupts by passing that
140137
number to pci_alloc_irq_vectors() function as both 'min_vecs' and
141138
'max_vecs' parameters:
142139

143-
ret = pci_alloc_irq_vectors(pdev, nvec, nvec, 0);
140+
ret = pci_alloc_irq_vectors(pdev, nvec, nvec, PCI_IRQ_ALL_TYPES);
144141
if (ret < 0)
145142
goto out_err;
146143

147144
The most notorious example of the request type described above is enabling
148145
the single MSI mode for a device. It could be done by passing two 1s as
149146
'min_vecs' and 'max_vecs':
150147

151-
ret = pci_alloc_irq_vectors(pdev, 1, 1, 0);
148+
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
152149
if (ret < 0)
153150
goto out_err;
154151

155152
Some devices might not support using legacy line interrupts, in which case
156-
the PCI_IRQ_NOLEGACY flag can be used to fail the request if the platform
157-
can't provide MSI or MSI-X interrupts:
153+
the driver can specify that only MSI or MSI-X is acceptable:
158154

159-
nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_NOLEGACY);
155+
nvec = pci_alloc_irq_vectors(pdev, 1, nvec, PCI_IRQ_MSI | PCI_IRQ_MSIX);
160156
if (nvec < 0)
161157
goto out_err;
162158

drivers/pci/msi.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
10691069
nvec = maxvec;
10701070

10711071
for (;;) {
1072-
if (!(flags & PCI_IRQ_NOAFFINITY)) {
1072+
if (flags & PCI_IRQ_AFFINITY) {
10731073
dev->irq_affinity = irq_create_affinity_mask(&nvec);
10741074
if (nvec < minvec)
10751075
return -ENOSPC;
@@ -1105,7 +1105,7 @@ static int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
11051105
**/
11061106
int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec)
11071107
{
1108-
return __pci_enable_msi_range(dev, minvec, maxvec, PCI_IRQ_NOAFFINITY);
1108+
return __pci_enable_msi_range(dev, minvec, maxvec, 0);
11091109
}
11101110
EXPORT_SYMBOL(pci_enable_msi_range);
11111111

@@ -1120,7 +1120,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
11201120
return -ERANGE;
11211121

11221122
for (;;) {
1123-
if (!(flags & PCI_IRQ_NOAFFINITY)) {
1123+
if (flags & PCI_IRQ_AFFINITY) {
11241124
dev->irq_affinity = irq_create_affinity_mask(&nvec);
11251125
if (nvec < minvec)
11261126
return -ENOSPC;
@@ -1160,8 +1160,7 @@ static int __pci_enable_msix_range(struct pci_dev *dev,
11601160
int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
11611161
int minvec, int maxvec)
11621162
{
1163-
return __pci_enable_msix_range(dev, entries, minvec, maxvec,
1164-
PCI_IRQ_NOAFFINITY);
1163+
return __pci_enable_msix_range(dev, entries, minvec, maxvec, 0);
11651164
}
11661165
EXPORT_SYMBOL(pci_enable_msix_range);
11671166

@@ -1187,21 +1186,21 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
11871186
{
11881187
int vecs = -ENOSPC;
11891188

1190-
if (!(flags & PCI_IRQ_NOMSIX)) {
1189+
if (flags & PCI_IRQ_MSIX) {
11911190
vecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
11921191
flags);
11931192
if (vecs > 0)
11941193
return vecs;
11951194
}
11961195

1197-
if (!(flags & PCI_IRQ_NOMSI)) {
1196+
if (flags & PCI_IRQ_MSI) {
11981197
vecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, flags);
11991198
if (vecs > 0)
12001199
return vecs;
12011200
}
12021201

12031202
/* use legacy irq if allowed */
1204-
if (!(flags & PCI_IRQ_NOLEGACY) && min_vecs == 1)
1203+
if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1)
12051204
return 1;
12061205
return vecs;
12071206
}

include/linux/pci.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,10 +1251,12 @@ resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
12511251
int pci_set_vga_state(struct pci_dev *pdev, bool decode,
12521252
unsigned int command_bits, u32 flags);
12531253

1254-
#define PCI_IRQ_NOLEGACY (1 << 0) /* don't use legacy interrupts */
1255-
#define PCI_IRQ_NOMSI (1 << 1) /* don't use MSI interrupts */
1256-
#define PCI_IRQ_NOMSIX (1 << 2) /* don't use MSI-X interrupts */
1257-
#define PCI_IRQ_NOAFFINITY (1 << 3) /* don't auto-assign affinity */
1254+
#define PCI_IRQ_LEGACY (1 << 0) /* allow legacy interrupts */
1255+
#define PCI_IRQ_MSI (1 << 1) /* allow MSI interrupts */
1256+
#define PCI_IRQ_MSIX (1 << 2) /* allow MSI-X interrupts */
1257+
#define PCI_IRQ_AFFINITY (1 << 3) /* auto-assign affinity */
1258+
#define PCI_IRQ_ALL_TYPES \
1259+
(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
12581260

12591261
/* kmem_cache style wrapper around pci_alloc_consistent() */
12601262

0 commit comments

Comments
 (0)