Skip to content

Commit beddb5e

Browse files
Ahmed S. DarwishKAGA-KOKO
authored andcommitted
PCI/MSI: Move pci_alloc_irq_vectors_affinity() to api.c
To disentangle the maze in msi.c, all exported device-driver MSI APIs are now to be grouped in one file, api.c. Move pci_alloc_irq_vectors_affinity() and let its kernel-doc reference pci_alloc_irq_vectors() documentation added in parent commit. Signed-off-by: Ahmed S. Darwish <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5c0997d commit beddb5e

File tree

2 files changed

+59
-65
lines changed

2 files changed

+59
-65
lines changed

drivers/pci/msi/api.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,62 @@ int pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
123123
flags, NULL);
124124
}
125125
EXPORT_SYMBOL(pci_alloc_irq_vectors);
126+
127+
/**
128+
* pci_alloc_irq_vectors_affinity() - Allocate multiple device interrupt
129+
* vectors with affinity requirements
130+
* @dev: the PCI device to operate on
131+
* @min_vecs: minimum required number of vectors (must be >= 1)
132+
* @max_vecs: maximum desired number of vectors
133+
* @flags: allocation flags, as in pci_alloc_irq_vectors()
134+
* @affd: affinity requirements (can be %NULL).
135+
*
136+
* Same as pci_alloc_irq_vectors(), but with the extra @affd parameter.
137+
* Check that function docs, and &struct irq_affinity, for more details.
138+
*/
139+
int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
140+
unsigned int max_vecs, unsigned int flags,
141+
struct irq_affinity *affd)
142+
{
143+
struct irq_affinity msi_default_affd = {0};
144+
int nvecs = -ENOSPC;
145+
146+
if (flags & PCI_IRQ_AFFINITY) {
147+
if (!affd)
148+
affd = &msi_default_affd;
149+
} else {
150+
if (WARN_ON(affd))
151+
affd = NULL;
152+
}
153+
154+
if (flags & PCI_IRQ_MSIX) {
155+
nvecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
156+
affd, flags);
157+
if (nvecs > 0)
158+
return nvecs;
159+
}
160+
161+
if (flags & PCI_IRQ_MSI) {
162+
nvecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd);
163+
if (nvecs > 0)
164+
return nvecs;
165+
}
166+
167+
/* use legacy IRQ if allowed */
168+
if (flags & PCI_IRQ_LEGACY) {
169+
if (min_vecs == 1 && dev->irq) {
170+
/*
171+
* Invoke the affinity spreading logic to ensure that
172+
* the device driver can adjust queue configuration
173+
* for the single interrupt case.
174+
*/
175+
if (affd)
176+
irq_create_affinity_masks(1, affd);
177+
pci_intx(dev, 1);
178+
return 1;
179+
}
180+
}
181+
182+
return nvecs;
183+
}
184+
EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity);

drivers/pci/msi/msi.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -886,71 +886,6 @@ int __pci_enable_msix_range(struct pci_dev *dev,
886886
}
887887
}
888888

889-
/**
890-
* pci_alloc_irq_vectors_affinity - allocate multiple IRQs for a device
891-
* @dev: PCI device to operate on
892-
* @min_vecs: minimum number of vectors required (must be >= 1)
893-
* @max_vecs: maximum (desired) number of vectors
894-
* @flags: flags or quirks for the allocation
895-
* @affd: optional description of the affinity requirements
896-
*
897-
* Allocate up to @max_vecs interrupt vectors for @dev, using MSI-X or MSI
898-
* vectors if available, and fall back to a single legacy vector
899-
* if neither is available. Return the number of vectors allocated,
900-
* (which might be smaller than @max_vecs) if successful, or a negative
901-
* error code on error. If less than @min_vecs interrupt vectors are
902-
* available for @dev the function will fail with -ENOSPC.
903-
*
904-
* To get the Linux IRQ number used for a vector that can be passed to
905-
* request_irq() use the pci_irq_vector() helper.
906-
*/
907-
int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
908-
unsigned int max_vecs, unsigned int flags,
909-
struct irq_affinity *affd)
910-
{
911-
struct irq_affinity msi_default_affd = {0};
912-
int nvecs = -ENOSPC;
913-
914-
if (flags & PCI_IRQ_AFFINITY) {
915-
if (!affd)
916-
affd = &msi_default_affd;
917-
} else {
918-
if (WARN_ON(affd))
919-
affd = NULL;
920-
}
921-
922-
if (flags & PCI_IRQ_MSIX) {
923-
nvecs = __pci_enable_msix_range(dev, NULL, min_vecs, max_vecs,
924-
affd, flags);
925-
if (nvecs > 0)
926-
return nvecs;
927-
}
928-
929-
if (flags & PCI_IRQ_MSI) {
930-
nvecs = __pci_enable_msi_range(dev, min_vecs, max_vecs, affd);
931-
if (nvecs > 0)
932-
return nvecs;
933-
}
934-
935-
/* use legacy IRQ if allowed */
936-
if (flags & PCI_IRQ_LEGACY) {
937-
if (min_vecs == 1 && dev->irq) {
938-
/*
939-
* Invoke the affinity spreading logic to ensure that
940-
* the device driver can adjust queue configuration
941-
* for the single interrupt case.
942-
*/
943-
if (affd)
944-
irq_create_affinity_masks(1, affd);
945-
pci_intx(dev, 1);
946-
return 1;
947-
}
948-
}
949-
950-
return nvecs;
951-
}
952-
EXPORT_SYMBOL(pci_alloc_irq_vectors_affinity);
953-
954889
/**
955890
* pci_free_irq_vectors - free previously allocated IRQs for a device
956891
* @dev: PCI device to operate on

0 commit comments

Comments
 (0)