@@ -40,6 +40,13 @@ int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
4040 struct msi_desc * entry ;
4141 int ret ;
4242
43+ /*
44+ * If an architecture wants to support multiple MSI, it needs to
45+ * override arch_setup_msi_irqs()
46+ */
47+ if (type == PCI_CAP_ID_MSI && nvec > 1 )
48+ return 1 ;
49+
4350 list_for_each_entry (entry , & dev -> msi_list , list ) {
4451 ret = arch_setup_msi_irq (dev , entry );
4552 if (ret < 0 )
@@ -58,8 +65,12 @@ void arch_teardown_msi_irqs(struct pci_dev *dev)
5865 struct msi_desc * entry ;
5966
6067 list_for_each_entry (entry , & dev -> msi_list , list ) {
61- if (entry -> irq != 0 )
62- arch_teardown_msi_irq (entry -> irq );
68+ int i , nvec ;
69+ if (entry -> irq == 0 )
70+ continue ;
71+ nvec = 1 << entry -> msi_attrib .multiple ;
72+ for (i = 0 ; i < nvec ; i ++ )
73+ arch_teardown_msi_irq (entry -> irq + i );
6374 }
6475}
6576#endif
@@ -163,7 +174,8 @@ static void msi_set_mask_bit(unsigned irq, u32 flag)
163174 msix_mask_irq (desc , flag );
164175 readl (desc -> mask_base ); /* Flush write to device */
165176 } else {
166- msi_mask_irq (desc , 1 , flag );
177+ unsigned offset = irq - desc -> dev -> irq ;
178+ msi_mask_irq (desc , 1 << offset , flag << offset );
167179 }
168180}
169181
@@ -229,6 +241,12 @@ void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
229241 } else {
230242 struct pci_dev * dev = entry -> dev ;
231243 int pos = entry -> msi_attrib .pos ;
244+ u16 msgctl ;
245+
246+ pci_read_config_word (dev , msi_control_reg (pos ), & msgctl );
247+ msgctl &= ~PCI_MSI_FLAGS_QSIZE ;
248+ msgctl |= entry -> msi_attrib .multiple << 4 ;
249+ pci_write_config_word (dev , msi_control_reg (pos ), msgctl );
232250
233251 pci_write_config_dword (dev , msi_lower_address_reg (pos ),
234252 msg -> address_lo );
@@ -291,7 +309,7 @@ static void __pci_restore_msi_state(struct pci_dev *dev)
291309 pci_read_config_word (dev , pos + PCI_MSI_FLAGS , & control );
292310 msi_mask_irq (entry , msi_capable_mask (control ), entry -> masked );
293311 control &= ~PCI_MSI_FLAGS_QSIZE ;
294- control |= PCI_MSI_FLAGS_ENABLE ;
312+ control |= ( entry -> msi_attrib . multiple << 4 ) | PCI_MSI_FLAGS_ENABLE ;
295313 pci_write_config_word (dev , pos + PCI_MSI_FLAGS , control );
296314}
297315
@@ -332,13 +350,15 @@ EXPORT_SYMBOL_GPL(pci_restore_msi_state);
332350/**
333351 * msi_capability_init - configure device's MSI capability structure
334352 * @dev: pointer to the pci_dev data structure of MSI device function
353+ * @nvec: number of interrupts to allocate
335354 *
336- * Setup the MSI capability structure of device function with a single
337- * MSI irq, regardless of device function is capable of handling
338- * multiple messages. A return of zero indicates the successful setup
339- * of an entry zero with the new MSI irq or non-zero for otherwise.
340- **/
341- static int msi_capability_init (struct pci_dev * dev )
355+ * Setup the MSI capability structure of the device with the requested
356+ * number of interrupts. A return value of zero indicates the successful
357+ * setup of an entry with the new MSI irq. A negative return value indicates
358+ * an error, and a positive return value indicates the number of interrupts
359+ * which could have been allocated.
360+ */
361+ static int msi_capability_init (struct pci_dev * dev , int nvec )
342362{
343363 struct msi_desc * entry ;
344364 int pos , ret ;
@@ -371,7 +391,7 @@ static int msi_capability_init(struct pci_dev *dev)
371391 list_add_tail (& entry -> list , & dev -> msi_list );
372392
373393 /* Configure MSI capability structure */
374- ret = arch_setup_msi_irqs (dev , 1 , PCI_CAP_ID_MSI );
394+ ret = arch_setup_msi_irqs (dev , nvec , PCI_CAP_ID_MSI );
375395 if (ret ) {
376396 msi_free_irqs (dev );
377397 return ret ;
@@ -524,35 +544,48 @@ static int pci_msi_check_device(struct pci_dev* dev, int nvec, int type)
524544}
525545
526546/**
527- * pci_enable_msi - configure device's MSI capability structure
528- * @dev: pointer to the pci_dev data structure of MSI device function
547+ * pci_enable_msi_block - configure device's MSI capability structure
548+ * @dev: device to configure
549+ * @nvec: number of interrupts to configure
529550 *
530- * Setup the MSI capability structure of device function with
531- * a single MSI irq upon its software driver call to request for
532- * MSI mode enabled on its hardware device function. A return of zero
533- * indicates the successful setup of an entry zero with the new MSI
534- * irq or non-zero for otherwise.
535- **/
536- int pci_enable_msi (struct pci_dev * dev )
551+ * Allocate IRQs for a device with the MSI capability.
552+ * This function returns a negative errno if an error occurs. If it
553+ * is unable to allocate the number of interrupts requested, it returns
554+ * the number of interrupts it might be able to allocate. If it successfully
555+ * allocates at least the number of interrupts requested, it returns 0 and
556+ * updates the @dev's irq member to the lowest new interrupt number; the
557+ * other interrupt numbers allocated to this device are consecutive.
558+ */
559+ int pci_enable_msi_block (struct pci_dev * dev , unsigned int nvec )
537560{
538- int status ;
561+ int status , pos , maxvec ;
562+ u16 msgctl ;
563+
564+ pos = pci_find_capability (dev , PCI_CAP_ID_MSI );
565+ if (!pos )
566+ return - EINVAL ;
567+ pci_read_config_word (dev , pos + PCI_MSI_FLAGS , & msgctl );
568+ maxvec = 1 << ((msgctl & PCI_MSI_FLAGS_QMASK ) >> 1 );
569+ if (nvec > maxvec )
570+ return maxvec ;
539571
540- status = pci_msi_check_device (dev , 1 , PCI_CAP_ID_MSI );
572+ status = pci_msi_check_device (dev , nvec , PCI_CAP_ID_MSI );
541573 if (status )
542574 return status ;
543575
544576 WARN_ON (!!dev -> msi_enabled );
545577
546- /* Check whether driver already requested for MSI-X irqs */
578+ /* Check whether driver already requested MSI-X irqs */
547579 if (dev -> msix_enabled ) {
548580 dev_info (& dev -> dev , "can't enable MSI "
549581 "(MSI-X already enabled)\n" );
550582 return - EINVAL ;
551583 }
552- status = msi_capability_init (dev );
584+
585+ status = msi_capability_init (dev , nvec );
553586 return status ;
554587}
555- EXPORT_SYMBOL (pci_enable_msi );
588+ EXPORT_SYMBOL (pci_enable_msi_block );
556589
557590void pci_msi_shutdown (struct pci_dev * dev )
558591{
@@ -599,8 +632,12 @@ static int msi_free_irqs(struct pci_dev* dev)
599632 struct msi_desc * entry , * tmp ;
600633
601634 list_for_each_entry (entry , & dev -> msi_list , list ) {
602- if (entry -> irq )
603- BUG_ON (irq_has_action (entry -> irq ));
635+ int i , nvec ;
636+ if (!entry -> irq )
637+ continue ;
638+ nvec = 1 << entry -> msi_attrib .multiple ;
639+ for (i = 0 ; i < nvec ; i ++ )
640+ BUG_ON (irq_has_action (entry -> irq + i ));
604641 }
605642
606643 arch_teardown_msi_irqs (dev );
0 commit comments