diff options
| author | Alexander Gordeev <agordeev@redhat.com> | 2014-02-13 12:48:02 -0500 |
|---|---|---|
| committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-02-13 12:48:02 -0500 |
| commit | 3ce4e860e578f843db36a1f7357ba00aeaa7610f (patch) | |
| tree | 5ab6d5d5db55c65646e4cce6ce0c17e1d87fc203 | |
| parent | 13f9653dab9a5d350a560c435a0f3d90ff7905ef (diff) | |
PCI/MSI: Add pci_enable_msi_exact() and pci_enable_msix_exact()
The new functions are special cases for pci_enable_msi_range() and
pci_enable_msix_range() when a particular number of MSI or MSI-X
is needed.
By contrast with pci_enable_msi_range() and pci_enable_msix_range()
functions, pci_enable_msi_exact() and pci_enable_msix_exact()
return zero in case of success, which indicates MSI or MSI-X
interrupts have been successfully allocated.
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
| -rw-r--r-- | Documentation/PCI/MSI-HOWTO.txt | 86 | ||||
| -rw-r--r-- | include/linux/pci.h | 20 |
2 files changed, 104 insertions, 2 deletions
diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt index 96ee5eb9d4d4..10a93696e55a 100644 --- a/Documentation/PCI/MSI-HOWTO.txt +++ b/Documentation/PCI/MSI-HOWTO.txt | |||
| @@ -159,6 +159,11 @@ static int foo_driver_enable_msi(struct pci_dev *pdev, int nvec) | |||
| 159 | return pci_enable_msi_range(pdev, nvec, nvec); | 159 | return pci_enable_msi_range(pdev, nvec, nvec); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | Note, unlike pci_enable_msi_exact() function, which could be also used to | ||
| 163 | enable a particular number of MSI-X interrupts, pci_enable_msi_range() | ||
| 164 | returns either a negative errno or 'nvec' (not negative errno or 0 - as | ||
| 165 | pci_enable_msi_exact() does). | ||
| 166 | |||
| 162 | 4.2.1.3 Single MSI mode | 167 | 4.2.1.3 Single MSI mode |
| 163 | 168 | ||
| 164 | The most notorious example of the request type described above is | 169 | The most notorious example of the request type described above is |
| @@ -175,7 +180,22 @@ enable the single MSI mode, pci_enable_msi_range() returns either a | |||
| 175 | negative errno or 1 (not negative errno or 0 - as pci_enable_msi() | 180 | negative errno or 1 (not negative errno or 0 - as pci_enable_msi() |
| 176 | does). | 181 | does). |
| 177 | 182 | ||
| 178 | 4.2.3 pci_disable_msi | 183 | 4.2.3 pci_enable_msi_exact |
| 184 | |||
| 185 | int pci_enable_msi_exact(struct pci_dev *dev, int nvec) | ||
| 186 | |||
| 187 | This variation on pci_enable_msi_range() call allows a device driver to | ||
| 188 | request exactly 'nvec' MSIs. | ||
| 189 | |||
| 190 | If this function returns a negative number, it indicates an error and | ||
| 191 | the driver should not attempt to request any more MSI interrupts for | ||
| 192 | this device. | ||
| 193 | |||
| 194 | By contrast with pci_enable_msi_range() function, pci_enable_msi_exact() | ||
| 195 | returns zero in case of success, which indicates MSI interrupts have been | ||
| 196 | successfully allocated. | ||
| 197 | |||
| 198 | 4.2.4 pci_disable_msi | ||
| 179 | 199 | ||
| 180 | void pci_disable_msi(struct pci_dev *dev) | 200 | void pci_disable_msi(struct pci_dev *dev) |
| 181 | 201 | ||
| @@ -303,6 +323,11 @@ static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) | |||
| 303 | nvec, nvec); | 323 | nvec, nvec); |
| 304 | } | 324 | } |
| 305 | 325 | ||
| 326 | Note, unlike pci_enable_msix_exact() function, which could be also used to | ||
| 327 | enable a particular number of MSI-X interrupts, pci_enable_msix_range() | ||
| 328 | returns either a negative errno or 'nvec' (not negative errno or 0 - as | ||
| 329 | pci_enable_msix_exact() does). | ||
| 330 | |||
| 306 | 4.3.1.3 Specific requirements to the number of MSI-X interrupts | 331 | 4.3.1.3 Specific requirements to the number of MSI-X interrupts |
| 307 | 332 | ||
| 308 | As noted above, there could be devices that can not operate with just any | 333 | As noted above, there could be devices that can not operate with just any |
| @@ -349,7 +374,64 @@ Note how pci_enable_msix_range() return value is analized for a fallback - | |||
| 349 | any error code other than -ENOSPC indicates a fatal error and should not | 374 | any error code other than -ENOSPC indicates a fatal error and should not |
| 350 | be retried. | 375 | be retried. |
| 351 | 376 | ||
| 352 | 4.3.2 pci_disable_msix | 377 | 4.3.2 pci_enable_msix_exact |
| 378 | |||
| 379 | int pci_enable_msix_exact(struct pci_dev *dev, | ||
| 380 | struct msix_entry *entries, int nvec) | ||
| 381 | |||
| 382 | This variation on pci_enable_msix_range() call allows a device driver to | ||
| 383 | request exactly 'nvec' MSI-Xs. | ||
| 384 | |||
| 385 | If this function returns a negative number, it indicates an error and | ||
| 386 | the driver should not attempt to allocate any more MSI-X interrupts for | ||
| 387 | this device. | ||
| 388 | |||
| 389 | By contrast with pci_enable_msix_range() function, pci_enable_msix_exact() | ||
| 390 | returns zero in case of success, which indicates MSI-X interrupts have been | ||
| 391 | successfully allocated. | ||
| 392 | |||
| 393 | Another version of a routine that enables MSI-X mode for a device with | ||
| 394 | specific requirements described in chapter 4.3.1.3 might look like this: | ||
| 395 | |||
| 396 | /* | ||
| 397 | * Assume 'minvec' and 'maxvec' are non-zero | ||
| 398 | */ | ||
| 399 | static int foo_driver_enable_msix(struct foo_adapter *adapter, | ||
| 400 | int minvec, int maxvec) | ||
| 401 | { | ||
| 402 | int rc; | ||
| 403 | |||
| 404 | minvec = roundup_pow_of_two(minvec); | ||
| 405 | maxvec = rounddown_pow_of_two(maxvec); | ||
| 406 | |||
| 407 | if (minvec > maxvec) | ||
| 408 | return -ERANGE; | ||
| 409 | |||
| 410 | retry: | ||
| 411 | rc = pci_enable_msix_exact(adapter->pdev, | ||
| 412 | adapter->msix_entries, maxvec); | ||
| 413 | |||
| 414 | /* | ||
| 415 | * -ENOSPC is the only error code allowed to be analyzed | ||
| 416 | */ | ||
| 417 | if (rc == -ENOSPC) { | ||
| 418 | if (maxvec == 1) | ||
| 419 | return -ENOSPC; | ||
| 420 | |||
| 421 | maxvec /= 2; | ||
| 422 | |||
| 423 | if (minvec > maxvec) | ||
| 424 | return -ENOSPC; | ||
| 425 | |||
| 426 | goto retry; | ||
| 427 | } else if (rc < 0) { | ||
| 428 | return rc; | ||
| 429 | } | ||
| 430 | |||
| 431 | return maxvec; | ||
| 432 | } | ||
| 433 | |||
| 434 | 4.3.3 pci_disable_msix | ||
| 353 | 435 | ||
| 354 | void pci_disable_msix(struct pci_dev *dev) | 436 | void pci_disable_msix(struct pci_dev *dev) |
| 355 | 437 | ||
diff --git a/include/linux/pci.h b/include/linux/pci.h index fb57c892b214..33aa2caf0f0c 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h | |||
| @@ -1169,8 +1169,23 @@ void msi_remove_pci_irq_vectors(struct pci_dev *dev); | |||
| 1169 | void pci_restore_msi_state(struct pci_dev *dev); | 1169 | void pci_restore_msi_state(struct pci_dev *dev); |
| 1170 | int pci_msi_enabled(void); | 1170 | int pci_msi_enabled(void); |
| 1171 | int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec); | 1171 | int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec); |
| 1172 | static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec) | ||
| 1173 | { | ||
| 1174 | int rc = pci_enable_msi_range(dev, nvec, nvec); | ||
| 1175 | if (rc < 0) | ||
| 1176 | return rc; | ||
| 1177 | return 0; | ||
| 1178 | } | ||
| 1172 | int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, | 1179 | int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, |
| 1173 | int minvec, int maxvec); | 1180 | int minvec, int maxvec); |
| 1181 | static inline int pci_enable_msix_exact(struct pci_dev *dev, | ||
| 1182 | struct msix_entry *entries, int nvec) | ||
| 1183 | { | ||
| 1184 | int rc = pci_enable_msix_range(dev, entries, nvec, nvec); | ||
| 1185 | if (rc < 0) | ||
| 1186 | return rc; | ||
| 1187 | return 0; | ||
| 1188 | } | ||
| 1174 | #else | 1189 | #else |
| 1175 | static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } | 1190 | static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; } |
| 1176 | static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec) | 1191 | static inline int pci_enable_msi_block(struct pci_dev *dev, int nvec) |
| @@ -1189,9 +1204,14 @@ static inline int pci_msi_enabled(void) { return 0; } | |||
| 1189 | static inline int pci_enable_msi_range(struct pci_dev *dev, int minvec, | 1204 | static inline int pci_enable_msi_range(struct pci_dev *dev, int minvec, |
| 1190 | int maxvec) | 1205 | int maxvec) |
| 1191 | { return -ENOSYS; } | 1206 | { return -ENOSYS; } |
| 1207 | static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec) | ||
| 1208 | { return -ENOSYS; } | ||
| 1192 | static inline int pci_enable_msix_range(struct pci_dev *dev, | 1209 | static inline int pci_enable_msix_range(struct pci_dev *dev, |
| 1193 | struct msix_entry *entries, int minvec, int maxvec) | 1210 | struct msix_entry *entries, int minvec, int maxvec) |
| 1194 | { return -ENOSYS; } | 1211 | { return -ENOSYS; } |
| 1212 | static inline int pci_enable_msix_exact(struct pci_dev *dev, | ||
| 1213 | struct msix_entry *entries, int nvec) | ||
| 1214 | { return -ENOSYS; } | ||
| 1195 | #endif | 1215 | #endif |
| 1196 | 1216 | ||
| 1197 | #ifdef CONFIG_PCIEPORTBUS | 1217 | #ifdef CONFIG_PCIEPORTBUS |
