diff options
-rw-r--r-- | Documentation/PCI/MSI-HOWTO.txt | 119 | ||||
-rw-r--r-- | drivers/ata/ahci.c | 4 | ||||
-rw-r--r-- | drivers/pci/host/pci-mvebu.c | 11 | ||||
-rw-r--r-- | drivers/pci/msi.c | 10 | ||||
-rw-r--r-- | drivers/pci/pci.c | 10 | ||||
-rw-r--r-- | include/linux/pci.h | 20 |
6 files changed, 152 insertions, 22 deletions
diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt index a8d01005f480..10a93696e55a 100644 --- a/Documentation/PCI/MSI-HOWTO.txt +++ b/Documentation/PCI/MSI-HOWTO.txt | |||
@@ -82,7 +82,19 @@ Most of the hard work is done for the driver in the PCI layer. It simply | |||
82 | has to request that the PCI layer set up the MSI capability for this | 82 | has to request that the PCI layer set up the MSI capability for this |
83 | device. | 83 | device. |
84 | 84 | ||
85 | 4.2.1 pci_enable_msi_range | 85 | 4.2.1 pci_enable_msi |
86 | |||
87 | int pci_enable_msi(struct pci_dev *dev) | ||
88 | |||
89 | A successful call allocates ONE interrupt to the device, regardless | ||
90 | of how many MSIs the device supports. The device is switched from | ||
91 | pin-based interrupt mode to MSI mode. The dev->irq number is changed | ||
92 | to a new number which represents the message signaled interrupt; | ||
93 | consequently, this function should be called before the driver calls | ||
94 | request_irq(), because an MSI is delivered via a vector that is | ||
95 | different from the vector of a pin-based interrupt. | ||
96 | |||
97 | 4.2.2 pci_enable_msi_range | ||
86 | 98 | ||
87 | int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) | 99 | int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec) |
88 | 100 | ||
@@ -147,6 +159,11 @@ static int foo_driver_enable_msi(struct pci_dev *pdev, int nvec) | |||
147 | return pci_enable_msi_range(pdev, nvec, nvec); | 159 | return pci_enable_msi_range(pdev, nvec, nvec); |
148 | } | 160 | } |
149 | 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 | |||
150 | 4.2.1.3 Single MSI mode | 167 | 4.2.1.3 Single MSI mode |
151 | 168 | ||
152 | The most notorious example of the request type described above is | 169 | The most notorious example of the request type described above is |
@@ -158,7 +175,27 @@ static int foo_driver_enable_single_msi(struct pci_dev *pdev) | |||
158 | return pci_enable_msi_range(pdev, 1, 1); | 175 | return pci_enable_msi_range(pdev, 1, 1); |
159 | } | 176 | } |
160 | 177 | ||
161 | 4.2.2 pci_disable_msi | 178 | Note, unlike pci_enable_msi() function, which could be also used to |
179 | enable the single MSI mode, pci_enable_msi_range() returns either a | ||
180 | negative errno or 1 (not negative errno or 0 - as pci_enable_msi() | ||
181 | does). | ||
182 | |||
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 | ||
162 | 199 | ||
163 | void pci_disable_msi(struct pci_dev *dev) | 200 | void pci_disable_msi(struct pci_dev *dev) |
164 | 201 | ||
@@ -172,7 +209,7 @@ on any interrupt for which it previously called request_irq(). | |||
172 | Failure to do so results in a BUG_ON(), leaving the device with | 209 | Failure to do so results in a BUG_ON(), leaving the device with |
173 | MSI enabled and thus leaking its vector. | 210 | MSI enabled and thus leaking its vector. |
174 | 211 | ||
175 | 4.2.3 pci_msi_vec_count | 212 | 4.2.4 pci_msi_vec_count |
176 | 213 | ||
177 | int pci_msi_vec_count(struct pci_dev *dev) | 214 | int pci_msi_vec_count(struct pci_dev *dev) |
178 | 215 | ||
@@ -257,8 +294,8 @@ possible, likely up to the limit returned by pci_msix_vec_count() function: | |||
257 | 294 | ||
258 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) | 295 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) |
259 | { | 296 | { |
260 | return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, | 297 | return pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
261 | 1, nvec); | 298 | 1, nvec); |
262 | } | 299 | } |
263 | 300 | ||
264 | Note the value of 'minvec' parameter is 1. As 'minvec' is inclusive, | 301 | Note the value of 'minvec' parameter is 1. As 'minvec' is inclusive, |
@@ -269,8 +306,8 @@ In this case the function could look like this: | |||
269 | 306 | ||
270 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) | 307 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) |
271 | { | 308 | { |
272 | return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, | 309 | return pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
273 | FOO_DRIVER_MINIMUM_NVEC, nvec); | 310 | FOO_DRIVER_MINIMUM_NVEC, nvec); |
274 | } | 311 | } |
275 | 312 | ||
276 | 4.3.1.2 Exact number of MSI-X interrupts | 313 | 4.3.1.2 Exact number of MSI-X interrupts |
@@ -282,10 +319,15 @@ parameters: | |||
282 | 319 | ||
283 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) | 320 | static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec) |
284 | { | 321 | { |
285 | return pci_enable_msi_range(adapter->pdev, adapter->msix_entries, | 322 | return pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
286 | nvec, nvec); | 323 | nvec, nvec); |
287 | } | 324 | } |
288 | 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 | |||
289 | 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 |
290 | 332 | ||
291 | 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 |
@@ -332,7 +374,64 @@ Note how pci_enable_msix_range() return value is analized for a fallback - | |||
332 | 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 |
333 | be retried. | 375 | be retried. |
334 | 376 | ||
335 | 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 | ||
336 | 435 | ||
337 | void pci_disable_msix(struct pci_dev *dev) | 436 | void pci_disable_msix(struct pci_dev *dev) |
338 | 437 | ||
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 7df81576a489..c81d809c111b 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c | |||
@@ -1184,8 +1184,10 @@ static int ahci_init_interrupts(struct pci_dev *pdev, unsigned int n_ports, | |||
1184 | 1184 | ||
1185 | nvec = rc; | 1185 | nvec = rc; |
1186 | rc = pci_enable_msi_block(pdev, nvec); | 1186 | rc = pci_enable_msi_block(pdev, nvec); |
1187 | if (rc) | 1187 | if (rc < 0) |
1188 | goto intx; | 1188 | goto intx; |
1189 | else if (rc > 0) | ||
1190 | goto single_msi; | ||
1189 | 1191 | ||
1190 | return nvec; | 1192 | return nvec; |
1191 | 1193 | ||
diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index 13478ecd4113..0e79665afd44 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c | |||
@@ -60,14 +60,6 @@ | |||
60 | #define PCIE_DEBUG_CTRL 0x1a60 | 60 | #define PCIE_DEBUG_CTRL 0x1a60 |
61 | #define PCIE_DEBUG_SOFT_RESET BIT(20) | 61 | #define PCIE_DEBUG_SOFT_RESET BIT(20) |
62 | 62 | ||
63 | /* | ||
64 | * This product ID is registered by Marvell, and used when the Marvell | ||
65 | * SoC is not the root complex, but an endpoint on the PCIe bus. It is | ||
66 | * therefore safe to re-use this PCI ID for our emulated PCI-to-PCI | ||
67 | * bridge. | ||
68 | */ | ||
69 | #define MARVELL_EMULATED_PCI_PCI_BRIDGE_ID 0x7846 | ||
70 | |||
71 | /* PCI configuration space of a PCI-to-PCI bridge */ | 63 | /* PCI configuration space of a PCI-to-PCI bridge */ |
72 | struct mvebu_sw_pci_bridge { | 64 | struct mvebu_sw_pci_bridge { |
73 | u16 vendor; | 65 | u16 vendor; |
@@ -388,7 +380,8 @@ static void mvebu_sw_pci_bridge_init(struct mvebu_pcie_port *port) | |||
388 | 380 | ||
389 | bridge->class = PCI_CLASS_BRIDGE_PCI; | 381 | bridge->class = PCI_CLASS_BRIDGE_PCI; |
390 | bridge->vendor = PCI_VENDOR_ID_MARVELL; | 382 | bridge->vendor = PCI_VENDOR_ID_MARVELL; |
391 | bridge->device = MARVELL_EMULATED_PCI_PCI_BRIDGE_ID; | 383 | bridge->device = mvebu_readl(port, PCIE_DEV_ID_OFF) >> 16; |
384 | bridge->revision = mvebu_readl(port, PCIE_DEV_REV_OFF) & 0xff; | ||
392 | bridge->header_type = PCI_HEADER_TYPE_BRIDGE; | 385 | bridge->header_type = PCI_HEADER_TYPE_BRIDGE; |
393 | bridge->cache_line_size = 0x10; | 386 | bridge->cache_line_size = 0x10; |
394 | 387 | ||
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 7a0fec6ce571..955ab7990c5b 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c | |||
@@ -545,9 +545,15 @@ static int populate_msi_sysfs(struct pci_dev *pdev) | |||
545 | return -ENOMEM; | 545 | return -ENOMEM; |
546 | list_for_each_entry(entry, &pdev->msi_list, list) { | 546 | list_for_each_entry(entry, &pdev->msi_list, list) { |
547 | char *name = kmalloc(20, GFP_KERNEL); | 547 | char *name = kmalloc(20, GFP_KERNEL); |
548 | if (!name) | ||
549 | goto error_attrs; | ||
550 | |||
548 | msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); | 551 | msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); |
549 | if (!msi_dev_attr) | 552 | if (!msi_dev_attr) { |
553 | kfree(name); | ||
550 | goto error_attrs; | 554 | goto error_attrs; |
555 | } | ||
556 | |||
551 | sprintf(name, "%d", entry->irq); | 557 | sprintf(name, "%d", entry->irq); |
552 | sysfs_attr_init(&msi_dev_attr->attr); | 558 | sysfs_attr_init(&msi_dev_attr->attr); |
553 | msi_dev_attr->attr.name = name; | 559 | msi_dev_attr->attr.name = name; |
@@ -589,6 +595,7 @@ error_attrs: | |||
589 | ++count; | 595 | ++count; |
590 | msi_attr = msi_attrs[count]; | 596 | msi_attr = msi_attrs[count]; |
591 | } | 597 | } |
598 | kfree(msi_attrs); | ||
592 | return ret; | 599 | return ret; |
593 | } | 600 | } |
594 | 601 | ||
@@ -959,7 +966,6 @@ EXPORT_SYMBOL(pci_disable_msi); | |||
959 | /** | 966 | /** |
960 | * pci_msix_vec_count - return the number of device's MSI-X table entries | 967 | * pci_msix_vec_count - return the number of device's MSI-X table entries |
961 | * @dev: pointer to the pci_dev data structure of MSI-X device function | 968 | * @dev: pointer to the pci_dev data structure of MSI-X device function |
962 | |||
963 | * This function returns the number of device's MSI-X table entries and | 969 | * This function returns the number of device's MSI-X table entries and |
964 | * therefore the number of MSI-X vectors device is capable of sending. | 970 | * therefore the number of MSI-X vectors device is capable of sending. |
965 | * It returns a negative errno if the device is not capable of sending MSI-X | 971 | * It returns a negative errno if the device is not capable of sending MSI-X |
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 1febe90831b4..6b05f6134b68 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -1181,6 +1181,8 @@ EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state); | |||
1181 | static int do_pci_enable_device(struct pci_dev *dev, int bars) | 1181 | static int do_pci_enable_device(struct pci_dev *dev, int bars) |
1182 | { | 1182 | { |
1183 | int err; | 1183 | int err; |
1184 | u16 cmd; | ||
1185 | u8 pin; | ||
1184 | 1186 | ||
1185 | err = pci_set_power_state(dev, PCI_D0); | 1187 | err = pci_set_power_state(dev, PCI_D0); |
1186 | if (err < 0 && err != -EIO) | 1188 | if (err < 0 && err != -EIO) |
@@ -1190,6 +1192,14 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) | |||
1190 | return err; | 1192 | return err; |
1191 | pci_fixup_device(pci_fixup_enable, dev); | 1193 | pci_fixup_device(pci_fixup_enable, dev); |
1192 | 1194 | ||
1195 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); | ||
1196 | if (pin) { | ||
1197 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | ||
1198 | if (cmd & PCI_COMMAND_INTX_DISABLE) | ||
1199 | pci_write_config_word(dev, PCI_COMMAND, | ||
1200 | cmd & ~PCI_COMMAND_INTX_DISABLE); | ||
1201 | } | ||
1202 | |||
1193 | return 0; | 1203 | return 0; |
1194 | } | 1204 | } |
1195 | 1205 | ||
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 |