blob: a8b41788dfde0fbe06416b51ec20d87672038725 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001 The MSI Driver Guide HOWTO
2 Tom L Nguyen tom.l.nguyen@intel.com
3 10/03/2003
4 Revised Feb 12, 2004 by Martine Silbermann
5 email: Martine.Silbermann@hp.com
6 Revised Jun 25, 2004 by Tom L Nguyen
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04007 Revised Jul 9, 2008 by Matthew Wilcox <willy@linux.intel.com>
8 Copyright 2003, 2008 Intel Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
101. About this guide
11
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040012This guide describes the basics of Message Signaled Interrupts (MSIs),
13the advantages of using MSI over traditional interrupt mechanisms, how
14to change your driver to use MSI or MSI-X and some basic diagnostics to
15try if a device doesn't support MSIs.
Randy Dunlap2500e7a2005-11-07 01:01:03 -080016
Randy Dunlap2500e7a2005-11-07 01:01:03 -080017
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400182. What are MSIs?
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040020A Message Signaled Interrupt is a write from the device to a special
21address which causes an interrupt to be received by the CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040023The MSI capability was first specified in PCI 2.2 and was later enhanced
24in PCI 3.0 to allow each interrupt to be masked individually. The MSI-X
25capability was also introduced with PCI 3.0. It supports more interrupts
26per device than MSI and allows interrupts to be independently configured.
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040028Devices may support both MSI and MSI-X, but only one can be enabled at
29a time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400323. Why use MSIs?
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040034There are three reasons why using MSIs can give an advantage over
35traditional pin-based interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040037Pin-based PCI interrupts are often shared amongst several devices.
38To support this, the kernel must call each interrupt handler associated
39with an interrupt, which leads to reduced performance for the system as
40a whole. MSIs are never shared, so this problem cannot arise.
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040042When a device writes data to memory, then raises a pin-based interrupt,
43it is possible that the interrupt may arrive before all the data has
44arrived in memory (this becomes more likely with devices behind PCI-PCI
45bridges). In order to ensure that all the data has arrived in memory,
46the interrupt handler must read a register on the device which raised
47the interrupt. PCI transaction ordering rules require that all the data
Michael Witten891f6922011-07-14 17:53:54 +000048arrive in memory before the value may be returned from the register.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040049Using MSIs avoids this problem as the interrupt-generating write cannot
50pass the data writes, so by the time the interrupt is raised, the driver
51knows that all the data has arrived in memory.
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040053PCI devices can only support a single pin-based interrupt per function.
54Often drivers have to query the device to find out what event has
55occurred, slowing down interrupt handling for the common case. With
56MSIs, a device can support more interrupts, allowing each interrupt
57to be specialised to a different purpose. One possible design gives
58infrequent conditions (such as errors) their own interrupt which allows
59the driver to handle the normal interrupt handling path more efficiently.
60Other possible designs include giving one interrupt to each packet queue
61in a network card or each port in a storage controller.
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400644. How to use MSIs
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040066PCI devices are initialised to use pin-based interrupts. The device
67driver has to set up the device to use MSI or MSI-X. Not all machines
68support MSIs correctly, and for those machines, the APIs described below
69will simply fail and the device will continue to use pin-based interrupts.
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400714.1 Include kernel support for MSIs
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040073To support MSI or MSI-X, the kernel must be built with the CONFIG_PCI_MSI
74option enabled. This option is only available on some architectures,
75and it may depend on some other options also being set. For example,
76on x86, you must also enable X86_UP_APIC or SMP in order to see the
77CONFIG_PCI_MSI option.
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400794.2 Using MSI
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040081Most of the hard work is done for the driver in the PCI layer. It simply
82has to request that the PCI layer set up the MSI capability for this
83device.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400854.2.1 pci_enable_msi
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87int pci_enable_msi(struct pci_dev *dev)
88
Michael Witten4979de62011-07-14 19:52:56 +000089A successful call allocates ONE interrupt to the device, regardless
90of how many MSIs the device supports. The device is switched from
Matthew Wilcoxc41ade22009-03-17 08:54:05 -040091pin-based interrupt mode to MSI mode. The dev->irq number is changed
Michael Witten4979de62011-07-14 19:52:56 +000092to a new number which represents the message signaled interrupt;
93consequently, this function should be called before the driver calls
94request_irq(), because an MSI is delivered via a vector that is
95different from the vector of a pin-based interrupt.
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -0400974.2.2 pci_enable_msi_block
98
99int pci_enable_msi_block(struct pci_dev *dev, int count)
100
101This variation on the above call allows a device driver to request multiple
102MSIs. The MSI specification only allows interrupts to be allocated in
103powers of two, up to a maximum of 2^5 (32).
104
105If this function returns 0, it has succeeded in allocating at least as many
106interrupts as the driver requested (it may have allocated more in order
107to satisfy the power-of-two requirement). In this case, the function
108enables MSI on this device and updates dev->irq to be the lowest of
109the new interrupts assigned to it. The other interrupts assigned to
110the device are in the range dev->irq to dev->irq + count - 1.
111
112If this function returns a negative number, it indicates an error and
113the driver should not attempt to request any more MSI interrupts for
Michael Witten4979de62011-07-14 19:52:56 +0000114this device. If this function returns a positive number, it is
115less than 'count' and indicates the number of interrupts that could have
116been allocated. In neither case is the irq value updated or the device
117switched into MSI mode.
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -0400118
119The device driver must decide what action to take if
Michael Wittena2d4d502011-07-14 20:03:28 +0000120pci_enable_msi_block() returns a value less than the number requested.
Michael Witten1d15afc2011-07-14 20:05:01 +0000121For instance, the driver could still make use of fewer interrupts;
122in this case the driver should call pci_enable_msi_block()
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -0400123again. Note that it is not guaranteed to succeed, even when the
124'count' has been reduced to the value returned from a previous call to
125pci_enable_msi_block(). This is because there are multiple constraints
126on the number of vectors that can be allocated; pci_enable_msi_block()
Michael Witten4979de62011-07-14 19:52:56 +0000127returns as soon as it finds any constraint that doesn't allow the
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -0400128call to succeed.
129
Alexander Gordeev08261d82012-11-19 16:02:10 +01001304.2.3 pci_enable_msi_block_auto
131
Alexander Gordeev52179dc2013-12-16 09:34:58 +0100132int pci_enable_msi_block_auto(struct pci_dev *dev, int *count)
Alexander Gordeev08261d82012-11-19 16:02:10 +0100133
134This variation on pci_enable_msi() call allows a device driver to request
135the maximum possible number of MSIs. The MSI specification only allows
136interrupts to be allocated in powers of two, up to a maximum of 2^5 (32).
137
138If this function returns a positive number, it indicates that it has
139succeeded and the returned value is the number of allocated interrupts. In
140this case, the function enables MSI on this device and updates dev->irq to
141be the lowest of the new interrupts assigned to it. The other interrupts
142assigned to the device are in the range dev->irq to dev->irq + returned
143value - 1.
144
145If this function returns a negative number, it indicates an error and
146the driver should not attempt to request any more MSI interrupts for
147this device.
148
149If the device driver needs to know the number of interrupts the device
150supports it can pass the pointer count where that number is stored. The
151device driver must decide what action to take if pci_enable_msi_block_auto()
152succeeds, but returns a value less than the number of interrupts supported.
153If the device driver does not need to know the number of interrupts
154supported, it can set the pointer count to NULL.
155
1564.2.4 pci_disable_msi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158void pci_disable_msi(struct pci_dev *dev)
159
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -0400160This function should be used to undo the effect of pci_enable_msi() or
Alexander Gordeev08261d82012-11-19 16:02:10 +0100161pci_enable_msi_block() or pci_enable_msi_block_auto(). Calling it restores
162dev->irq to the pin-based interrupt number and frees the previously
163allocated message signaled interrupt(s). The interrupt may subsequently be
164assigned to another device, so drivers should not cache the value of
165dev->irq.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Michael Witten263d8d52011-07-14 21:28:00 +0000167Before calling this function, a device driver must always call free_irq()
168on any interrupt for which it previously called request_irq().
Michael Witten4979de62011-07-14 19:52:56 +0000169Failure to do so results in a BUG_ON(), leaving the device with
170MSI enabled and thus leaking its vector.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Alexander Gordeevd1ac1d22013-12-30 08:28:13 +01001724.2.5 pci_msi_vec_count
173
174int pci_msi_vec_count(struct pci_dev *dev)
175
176This function could be used to retrieve the number of MSI vectors the
177device requested (via the Multiple Message Capable register). The MSI
178specification only allows the returned value to be a power of two,
179up to a maximum of 2^5 (32).
180
181If this function returns a negative number, it indicates the device is
182not capable of sending MSIs.
183
184If this function returns a positive number, it indicates the maximum
185number of MSI interrupt vectors that could be allocated.
186
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04001874.3 Using MSI-X
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400189The MSI-X capability is much more flexible than the MSI capability.
190It supports up to 2048 interrupts, each of which can be controlled
191independently. To support this flexibility, drivers must use an array of
192`struct msix_entry':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194struct msix_entry {
195 u16 vector; /* kernel uses to write alloc vector */
196 u16 entry; /* driver uses to specify entry */
197};
198
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400199This allows for the device to use these interrupts in a sparse fashion;
Michael Wittene4439232011-07-14 21:30:18 +0000200for example, it could use interrupts 3 and 1027 and yet allocate only a
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400201two-element array. The driver is expected to fill in the 'entry' value
Michael Wittene4439232011-07-14 21:30:18 +0000202in each element of the array to indicate for which entries the kernel
203should assign interrupts; it is invalid to fill in two entries with the
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400204same number.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002064.3.1 pci_enable_msix
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400208int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
209
210Calling this function asks the PCI subsystem to allocate 'nvec' MSIs.
211The 'entries' argument is a pointer to an array of msix_entry structs
212which should be at least 'nvec' entries in size. On success, the
Michael Witten4979de62011-07-14 19:52:56 +0000213device is switched into MSI-X mode and the function returns 0.
214The 'vector' member in each entry is populated with the interrupt number;
215the driver should then call request_irq() for each 'vector' that it
Michael Witten6457d9b2011-07-14 21:54:18 +0000216decides to use. The device driver is responsible for keeping track of the
217interrupts assigned to the MSI-X vectors so it can free them again later.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400218
219If this function returns a negative number, it indicates an error and
220the driver should not attempt to allocate any more MSI-X interrupts for
221this device. If it returns a positive number, it indicates the maximum
Michael Ellermanfafad5b2009-03-20 15:22:12 +1100222number of interrupt vectors that could have been allocated. See example
223below.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400224
225This function, in contrast with pci_enable_msi(), does not adjust
226dev->irq. The device will not generate interrupts for this interrupt
Michael Witten6457d9b2011-07-14 21:54:18 +0000227number once MSI-X is enabled.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400228
229Device drivers should normally call this function once per device
230during the initialization phase.
231
Michael Witten5a84fc32011-07-14 21:55:05 +0000232It is ideal if drivers can cope with a variable number of MSI-X interrupts;
Michael Ellermanfafad5b2009-03-20 15:22:12 +1100233there are many reasons why the platform may not be able to provide the
Michael Wittened737c12011-07-18 16:15:00 +0000234exact number that a driver asks for.
Michael Ellermanfafad5b2009-03-20 15:22:12 +1100235
236A request loop to achieve that might look like:
237
238static int foo_driver_enable_msix(struct foo_adapter *adapter, int nvec)
239{
240 while (nvec >= FOO_DRIVER_MINIMUM_NVEC) {
241 rc = pci_enable_msix(adapter->pdev,
242 adapter->msix_entries, nvec);
243 if (rc > 0)
244 nvec = rc;
245 else
246 return rc;
247 }
248
249 return -ENOSPC;
250}
251
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002524.3.2 pci_disable_msix
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254void pci_disable_msix(struct pci_dev *dev)
255
Michael Wittene6ffceb2011-07-14 23:30:47 +0000256This function should be used to undo the effect of pci_enable_msix(). It frees
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400257the previously allocated message signaled interrupts. The interrupts may
258subsequently be assigned to another device, so drivers should not cache
259the value of the 'vector' elements over a call to pci_disable_msix().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Michael Witten263d8d52011-07-14 21:28:00 +0000261Before calling this function, a device driver must always call free_irq()
262on any interrupt for which it previously called request_irq().
Michael Witten4979de62011-07-14 19:52:56 +0000263Failure to do so results in a BUG_ON(), leaving the device with
264MSI-X enabled and thus leaking its vector.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002664.3.3 The MSI-X Table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400268The MSI-X capability specifies a BAR and offset within that BAR for the
269MSI-X Table. This address is mapped by the PCI subsystem, and should not
270be accessed directly by the device driver. If the driver wishes to
271mask or unmask an interrupt, it should call disable_irq() / enable_irq().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002734.4 Handling devices implementing both MSI and MSI-X capabilities
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400275If a device implements both MSI and MSI-X capabilities, it can
Michael Wittene14bd7e2011-07-15 03:12:13 +0000276run in either MSI mode or MSI-X mode, but not both simultaneously.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400277This is a requirement of the PCI spec, and it is enforced by the
278PCI layer. Calling pci_enable_msi() when MSI-X is already enabled or
Michael Witten4979de62011-07-14 19:52:56 +0000279pci_enable_msix() when MSI is already enabled results in an error.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400280If a device driver wishes to switch between MSI and MSI-X at runtime,
281it must first quiesce the device, then switch it back to pin-interrupt
282mode, before calling pci_enable_msi() or pci_enable_msix() and resuming
283operation. This is not expected to be a common operation but may be
284useful for debugging or testing during development.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002864.5 Considerations when using MSIs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04002884.5.1 Choosing between MSI-X and MSI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400290If your device supports both MSI-X and MSI capabilities, you should use
291the MSI-X facilities in preference to the MSI facilities. As mentioned
292above, MSI-X supports any number of interrupts between 1 and 2048.
293In constrast, MSI is restricted to a maximum of 32 interrupts (and
294must be a power of two). In addition, the MSI interrupt vectors must
Michael Witten952df552011-07-15 03:15:10 +0000295be allocated consecutively, so the system might not be able to allocate
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400296as many vectors for MSI as it could for MSI-X. On some platforms, MSI
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300297interrupts must all be targeted at the same set of CPUs whereas MSI-X
298interrupts can all be targeted at different CPUs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003004.5.2 Spinlocks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400302Most device drivers have a per-device spinlock which is taken in the
303interrupt handler. With pin-based interrupts or a single MSI, it is not
304necessary to disable interrupts (Linux guarantees the same interrupt will
305not be re-entered). If a device uses multiple interrupts, the driver
306must disable interrupts while the lock is held. If the device sends
307a different interrupt, the driver will deadlock trying to recursively
308acquire the spinlock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400310There are two solutions. The first is to take the lock with
311spin_lock_irqsave() or spin_lock_irq() (see
312Documentation/DocBook/kernel-locking). The second is to specify
313IRQF_DISABLED to request_irq() so that the kernel runs the entire
314interrupt routine with interrupts disabled.
Randy Dunlap2500e7a2005-11-07 01:01:03 -0800315
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400316If your MSI interrupt routine does not hold the lock for the whole time
317it is running, the first solution may be best. The second solution is
318normally preferred as it avoids making two transitions from interrupt
319disabled to enabled and back again.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003214.6 How to tell whether MSI/MSI-X is enabled on a device
Randy Dunlap2500e7a2005-11-07 01:01:03 -0800322
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400323Using 'lspci -v' (as root) may show some devices with "MSI", "Message
324Signalled Interrupts" or "MSI-X" capabilities. Each of these capabilities
Michael Witten4979de62011-07-14 19:52:56 +0000325has an 'Enable' flag which is followed with either "+" (enabled)
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400326or "-" (disabled).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003295. MSI quirks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400331Several PCI chipsets or devices are known not to support MSIs.
332The PCI stack provides three ways to disable MSIs:
Randy Dunlap2500e7a2005-11-07 01:01:03 -0800333
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003341. globally
3352. on all devices behind a specific bridge
3363. on a single device
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003385.1. Disabling MSIs globally
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400340Some host chipsets simply don't support MSIs properly. If we're
341lucky, the manufacturer knows this and has indicated it in the ACPI
Michael Witten4979de62011-07-14 19:52:56 +0000342FADT table. In this case, Linux automatically disables MSIs.
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400343Some boards don't include this information in the table and so we have
344to detect them ourselves. The complete list of these is found near the
345quirk_disable_all_msi() function in drivers/pci/quirks.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400347If you have a board which has problems with MSIs, you can pass pci=nomsi
348on the kernel command line to disable MSIs on all devices. It would be
349in your best interests to report the problem to linux-pci@vger.kernel.org
350including a full 'lspci -v' so we can add the quirks to the kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003525.2. Disabling MSIs below a bridge
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400354Some PCI bridges are not able to route MSIs between busses properly.
355In this case, MSIs must be disabled on all devices behind the bridge.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200356
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400357Some bridges allow you to enable MSIs by changing some bits in their
358PCI configuration space (especially the Hypertransport chipsets such
359as the nVidia nForce and Serverworks HT2000). As with host chipsets,
360Linux mostly knows about them and automatically enables MSIs if it can.
Michael Wittene6b85a12011-07-15 03:25:44 +0000361If you have a bridge unknown to Linux, you can enable
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400362MSIs in configuration space using whatever method you know works, then
363enable MSIs on that bridge by doing:
Brice Goglin0cc2b372006-10-05 10:24:42 +0200364
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400365 echo 1 > /sys/bus/pci/devices/$bridge/msi_bus
Brice Goglin0cc2b372006-10-05 10:24:42 +0200366
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400367where $bridge is the PCI address of the bridge you've enabled (eg
3680000:00:0e.0).
Brice Goglin0cc2b372006-10-05 10:24:42 +0200369
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400370To disable MSIs, echo 0 instead of 1. Changing this value should be
Michael Witten1b8386f2011-07-15 03:26:37 +0000371done with caution as it could break interrupt handling for all devices
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400372below this bridge.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200373
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400374Again, please notify linux-pci@vger.kernel.org of any bridges that need
375special handling.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200376
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003775.3. Disabling MSIs on a single device
Brice Goglin0cc2b372006-10-05 10:24:42 +0200378
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400379Some devices are known to have faulty MSI implementations. Usually this
Michael Wittenc2b65e12011-07-15 03:27:22 +0000380is handled in the individual device driver, but occasionally it's necessary
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400381to handle this with a quirk. Some drivers have an option to disable use
382of MSI. While this is a convenient workaround for the driver author,
383it is not good practise, and should not be emulated.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200384
Matthew Wilcoxc41ade22009-03-17 08:54:05 -04003855.4. Finding why MSIs are disabled on a device
Brice Goglin0cc2b372006-10-05 10:24:42 +0200386
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400387From the above three sections, you can see that there are many reasons
388why MSIs may not be enabled for a given device. Your first step should
389be to examine your dmesg carefully to determine whether MSIs are enabled
390for your machine. You should also check your .config to be sure you
391have enabled CONFIG_PCI_MSI.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200392
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400393Then, 'lspci -t' gives the list of bridges above a device. Reading
Michael Witten798c7942011-07-15 03:29:04 +0000394/sys/bus/pci/devices/*/msi_bus will tell you whether MSIs are enabled (1)
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400395or disabled (0). If 0 is found in any of the msi_bus files belonging
396to bridges between the PCI root and the device, MSIs are disabled.
Brice Goglin0cc2b372006-10-05 10:24:42 +0200397
Matthew Wilcoxc41ade22009-03-17 08:54:05 -0400398It is also worth checking the device driver to see whether it supports MSIs.
399For example, it may contain calls to pci_enable_msi(), pci_enable_msix() or
400pci_enable_msi_block().