diff options
| author | Matthew Wilcox <willy@linux.intel.com> | 2009-03-17 08:54:05 -0400 |
|---|---|---|
| committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-03-20 13:48:11 -0400 |
| commit | c41ade2ee1dc146d2de2ee470a87cd6b878a08f4 (patch) | |
| tree | 28de511376f31c5b6cc84348e46408a879f7a9f4 /Documentation/PCI | |
| parent | 0994375e9614f78657031e04e30019b9cdb62795 (diff) | |
Rewrite MSI-HOWTO
I didn't find the previous version very useful, so I rewrote it.
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Reviewed-by: Randy Dunlap <randy.dunlap@oracle.com>
Reviewed-by: Grant Grundler <grundler@parisc-linunx.org>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'Documentation/PCI')
| -rw-r--r-- | Documentation/PCI/MSI-HOWTO.txt | 758 |
1 files changed, 277 insertions, 481 deletions
diff --git a/Documentation/PCI/MSI-HOWTO.txt b/Documentation/PCI/MSI-HOWTO.txt index 256defd7e174..1c02431f1d1a 100644 --- a/Documentation/PCI/MSI-HOWTO.txt +++ b/Documentation/PCI/MSI-HOWTO.txt | |||
| @@ -4,506 +4,302 @@ | |||
| 4 | Revised Feb 12, 2004 by Martine Silbermann | 4 | Revised Feb 12, 2004 by Martine Silbermann |
| 5 | email: Martine.Silbermann@hp.com | 5 | email: Martine.Silbermann@hp.com |
| 6 | Revised Jun 25, 2004 by Tom L Nguyen | 6 | Revised Jun 25, 2004 by Tom L Nguyen |
| 7 | Revised Jul 9, 2008 by Matthew Wilcox <willy@linux.intel.com> | ||
| 8 | Copyright 2003, 2008 Intel Corporation | ||
| 7 | 9 | ||
| 8 | 1. About this guide | 10 | 1. About this guide |
| 9 | 11 | ||
| 10 | This guide describes the basics of Message Signaled Interrupts (MSI), | 12 | This guide describes the basics of Message Signaled Interrupts (MSIs), |
| 11 | the advantages of using MSI over traditional interrupt mechanisms, | 13 | the advantages of using MSI over traditional interrupt mechanisms, how |
| 12 | and how to enable your driver to use MSI or MSI-X. Also included is | 14 | to change your driver to use MSI or MSI-X and some basic diagnostics to |
| 13 | a Frequently Asked Questions (FAQ) section. | 15 | try if a device doesn't support MSIs. |
| 14 | 16 | ||
| 15 | 1.1 Terminology | 17 | |
| 16 | 18 | 2. What are MSIs? | |
| 17 | PCI devices can be single-function or multi-function. In either case, | 19 | |
| 18 | when this text talks about enabling or disabling MSI on a "device | 20 | A Message Signaled Interrupt is a write from the device to a special |
| 19 | function," it is referring to one specific PCI device and function and | 21 | address which causes an interrupt to be received by the CPU. |
| 20 | not to all functions on a PCI device (unless the PCI device has only | 22 | |
| 21 | one function). | 23 | The MSI capability was first specified in PCI 2.2 and was later enhanced |
| 22 | 24 | in PCI 3.0 to allow each interrupt to be masked individually. The MSI-X | |
| 23 | 2. Copyright 2003 Intel Corporation | 25 | capability was also introduced with PCI 3.0. It supports more interrupts |
| 24 | 26 | per device than MSI and allows interrupts to be independently configured. | |
| 25 | 3. What is MSI/MSI-X? | 27 | |
| 26 | 28 | Devices may support both MSI and MSI-X, but only one can be enabled at | |
| 27 | Message Signaled Interrupt (MSI), as described in the PCI Local Bus | 29 | a time. |
| 28 | Specification Revision 2.3 or later, is an optional feature, and a | 30 | |
| 29 | required feature for PCI Express devices. MSI enables a device function | 31 | |
| 30 | to request service by sending an Inbound Memory Write on its PCI bus to | 32 | 3. Why use MSIs? |
| 31 | the FSB as a Message Signal Interrupt transaction. Because MSI is | 33 | |
| 32 | generated in the form of a Memory Write, all transaction conditions, | 34 | There are three reasons why using MSIs can give an advantage over |
| 33 | such as a Retry, Master-Abort, Target-Abort or normal completion, are | 35 | traditional pin-based interrupts. |
| 34 | supported. | 36 | |
| 35 | 37 | Pin-based PCI interrupts are often shared amongst several devices. | |
| 36 | A PCI device that supports MSI must also support pin IRQ assertion | 38 | To support this, the kernel must call each interrupt handler associated |
| 37 | interrupt mechanism to provide backward compatibility for systems that | 39 | with an interrupt, which leads to reduced performance for the system as |
| 38 | do not support MSI. In systems which support MSI, the bus driver is | 40 | a whole. MSIs are never shared, so this problem cannot arise. |
| 39 | responsible for initializing the message address and message data of | 41 | |
| 40 | the device function's MSI/MSI-X capability structure during device | 42 | When a device writes data to memory, then raises a pin-based interrupt, |
| 41 | initial configuration. | 43 | it is possible that the interrupt may arrive before all the data has |
| 42 | 44 | arrived in memory (this becomes more likely with devices behind PCI-PCI | |
| 43 | An MSI capable device function indicates MSI support by implementing | 45 | bridges). In order to ensure that all the data has arrived in memory, |
| 44 | the MSI/MSI-X capability structure in its PCI capability list. The | 46 | the interrupt handler must read a register on the device which raised |
| 45 | device function may implement both the MSI capability structure and | 47 | the interrupt. PCI transaction ordering rules require that all the data |
| 46 | the MSI-X capability structure; however, the bus driver should not | 48 | arrives in memory before the value can be returned from the register. |
| 47 | enable both. | 49 | Using MSIs avoids this problem as the interrupt-generating write cannot |
| 48 | 50 | pass the data writes, so by the time the interrupt is raised, the driver | |
| 49 | The MSI capability structure contains Message Control register, | 51 | knows that all the data has arrived in memory. |
| 50 | Message Address register and Message Data register. These registers | 52 | |
| 51 | provide the bus driver control over MSI. The Message Control register | 53 | PCI devices can only support a single pin-based interrupt per function. |
| 52 | indicates the MSI capability supported by the device. The Message | 54 | Often drivers have to query the device to find out what event has |
| 53 | Address register specifies the target address and the Message Data | 55 | occurred, slowing down interrupt handling for the common case. With |
| 54 | register specifies the characteristics of the message. To request | 56 | MSIs, a device can support more interrupts, allowing each interrupt |
| 55 | service, the device function writes the content of the Message Data | 57 | to be specialised to a different purpose. One possible design gives |
| 56 | register to the target address. The device and its software driver | 58 | infrequent conditions (such as errors) their own interrupt which allows |
| 57 | are prohibited from writing to these registers. | 59 | the driver to handle the normal interrupt handling path more efficiently. |
| 58 | 60 | Other possible designs include giving one interrupt to each packet queue | |
| 59 | The MSI-X capability structure is an optional extension to MSI. It | 61 | in a network card or each port in a storage controller. |
| 60 | uses an independent and separate capability structure. There are | 62 | |
| 61 | some key advantages to implementing the MSI-X capability structure | 63 | |
| 62 | over the MSI capability structure as described below. | 64 | 4. How to use MSIs |
| 63 | 65 | ||
| 64 | - Support a larger maximum number of vectors per function. | 66 | PCI devices are initialised to use pin-based interrupts. The device |
| 65 | 67 | driver has to set up the device to use MSI or MSI-X. Not all machines | |
| 66 | - Provide the ability for system software to configure | 68 | support MSIs correctly, and for those machines, the APIs described below |
| 67 | each vector with an independent message address and message | 69 | will simply fail and the device will continue to use pin-based interrupts. |
| 68 | data, specified by a table that resides in Memory Space. | 70 | |
| 69 | 71 | 4.1 Include kernel support for MSIs | |
| 70 | - MSI and MSI-X both support per-vector masking. Per-vector | 72 | |
| 71 | masking is an optional extension of MSI but a required | 73 | To support MSI or MSI-X, the kernel must be built with the CONFIG_PCI_MSI |
| 72 | feature for MSI-X. Per-vector masking provides the kernel the | 74 | option enabled. This option is only available on some architectures, |
| 73 | ability to mask/unmask a single MSI while running its | 75 | and it may depend on some other options also being set. For example, |
| 74 | interrupt service routine. If per-vector masking is | 76 | on x86, you must also enable X86_UP_APIC or SMP in order to see the |
| 75 | not supported, then the device driver should provide the | 77 | CONFIG_PCI_MSI option. |
| 76 | hardware/software synchronization to ensure that the device | 78 | |
| 77 | generates MSI when the driver wants it to do so. | 79 | 4.2 Using MSI |
| 78 | 80 | ||
| 79 | 4. Why use MSI? | 81 | Most of the hard work is done for the driver in the PCI layer. It simply |
| 80 | 82 | has to request that the PCI layer set up the MSI capability for this | |
| 81 | As a benefit to the simplification of board design, MSI allows board | 83 | device. |
| 82 | designers to remove out-of-band interrupt routing. MSI is another | 84 | |
| 83 | step towards a legacy-free environment. | 85 | 4.2.1 pci_enable_msi |
| 84 | |||
| 85 | Due to increasing pressure on chipset and processor packages to | ||
| 86 | reduce pin count, the need for interrupt pins is expected to | ||
| 87 | diminish over time. Devices, due to pin constraints, may implement | ||
| 88 | messages to increase performance. | ||
| 89 | |||
| 90 | PCI Express endpoints uses INTx emulation (in-band messages) instead | ||
| 91 | of IRQ pin assertion. Using INTx emulation requires interrupt | ||
| 92 | sharing among devices connected to the same node (PCI bridge) while | ||
| 93 | MSI is unique (non-shared) and does not require BIOS configuration | ||
| 94 | support. As a result, the PCI Express technology requires MSI | ||
| 95 | support for better interrupt performance. | ||
| 96 | |||
| 97 | Using MSI enables the device functions to support two or more | ||
| 98 | vectors, which can be configured to target different CPUs to | ||
| 99 | increase scalability. | ||
| 100 | |||
| 101 | 5. Configuring a driver to use MSI/MSI-X | ||
| 102 | |||
| 103 | By default, the kernel will not enable MSI/MSI-X on all devices that | ||
| 104 | support this capability. The CONFIG_PCI_MSI kernel option | ||
| 105 | must be selected to enable MSI/MSI-X support. | ||
| 106 | |||
| 107 | 5.1 Including MSI/MSI-X support into the kernel | ||
| 108 | |||
| 109 | To allow MSI/MSI-X capable device drivers to selectively enable | ||
| 110 | MSI/MSI-X (using pci_enable_msi()/pci_enable_msix() as described | ||
| 111 | below), the VECTOR based scheme needs to be enabled by setting | ||
| 112 | CONFIG_PCI_MSI during kernel config. | ||
| 113 | |||
| 114 | Since the target of the inbound message is the local APIC, providing | ||
| 115 | CONFIG_X86_LOCAL_APIC must be enabled as well as CONFIG_PCI_MSI. | ||
| 116 | |||
| 117 | 5.2 Configuring for MSI support | ||
| 118 | |||
| 119 | Due to the non-contiguous fashion in vector assignment of the | ||
| 120 | existing Linux kernel, this version does not support multiple | ||
| 121 | messages regardless of a device function is capable of supporting | ||
| 122 | more than one vector. To enable MSI on a device function's MSI | ||
| 123 | capability structure requires a device driver to call the function | ||
| 124 | pci_enable_msi() explicitly. | ||
| 125 | |||
| 126 | 5.2.1 API pci_enable_msi | ||
| 127 | 86 | ||
| 128 | int pci_enable_msi(struct pci_dev *dev) | 87 | int pci_enable_msi(struct pci_dev *dev) |
| 129 | 88 | ||
| 130 | With this new API, a device driver that wants to have MSI | 89 | A successful call will allocate ONE interrupt to the device, regardless |
| 131 | enabled on its device function must call this API to enable MSI. | 90 | of how many MSIs the device supports. The device will be switched from |
