@@ -335,11 +335,41 @@ static int msi_verify_entries(struct pci_dev *dev)
335
335
return !entry ? 0 : - EIO ;
336
336
}
337
337
338
- static int __msi_capability_init (struct pci_dev * dev , int nvec , struct irq_affinity_desc * masks )
338
+ /**
339
+ * msi_capability_init - configure device's MSI capability structure
340
+ * @dev: pointer to the pci_dev data structure of MSI device function
341
+ * @nvec: number of interrupts to allocate
342
+ * @affd: description of automatic IRQ affinity assignments (may be %NULL)
343
+ *
344
+ * Setup the MSI capability structure of the device with the requested
345
+ * number of interrupts. A return value of zero indicates the successful
346
+ * setup of an entry with the new MSI IRQ. A negative return value indicates
347
+ * an error, and a positive return value indicates the number of interrupts
348
+ * which could have been allocated.
349
+ */
350
+ static int msi_capability_init (struct pci_dev * dev , int nvec ,
351
+ struct irq_affinity * affd )
339
352
{
340
- int ret = msi_setup_msi_desc ( dev , nvec , masks ) ;
353
+ struct irq_affinity_desc * masks = NULL ;
341
354
struct msi_desc * entry , desc ;
355
+ int ret ;
342
356
357
+ /* Reject multi-MSI early on irq domain enabled architectures */
358
+ if (nvec > 1 && !pci_msi_domain_supports (dev , MSI_FLAG_MULTI_PCI_MSI , ALLOW_LEGACY ))
359
+ return 1 ;
360
+
361
+ /*
362
+ * Disable MSI during setup in the hardware, but mark it enabled
363
+ * so that setup code can evaluate it.
364
+ */
365
+ pci_msi_set_enable (dev , 0 );
366
+ dev -> msi_enabled = 1 ;
367
+
368
+ if (affd )
369
+ masks = irq_create_affinity_masks (nvec , affd );
370
+
371
+ msi_lock_descs (& dev -> dev );
372
+ ret = msi_setup_msi_desc (dev , nvec , masks );
343
373
if (ret )
344
374
goto fail ;
345
375
@@ -368,48 +398,19 @@ static int __msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affin
368
398
369
399
pcibios_free_irq (dev );
370
400
dev -> irq = entry -> irq ;
371
- return 0 ;
401
+ goto unlock ;
402
+
372
403
err :
373
404
pci_msi_unmask (& desc , msi_multi_mask (& desc ));
374
405
pci_free_msi_irqs (dev );
375
406
fail :
376
407
dev -> msi_enabled = 0 ;
408
+ unlock :
409
+ msi_unlock_descs (& dev -> dev );
410
+ kfree (masks );
377
411
return ret ;
378
412
}
379
413
380
- /**
381
- * msi_capability_init - configure device's MSI capability structure
382
- * @dev: pointer to the pci_dev data structure of MSI device function
383
- * @nvec: number of interrupts to allocate
384
- * @affd: description of automatic IRQ affinity assignments (may be %NULL)
385
- *
386
- * Setup the MSI capability structure of the device with the requested
387
- * number of interrupts. A return value of zero indicates the successful
388
- * setup of an entry with the new MSI IRQ. A negative return value indicates
389
- * an error, and a positive return value indicates the number of interrupts
390
- * which could have been allocated.
391
- */
392
- static int msi_capability_init (struct pci_dev * dev , int nvec ,
393
- struct irq_affinity * affd )
394
- {
395
- /* Reject multi-MSI early on irq domain enabled architectures */
396
- if (nvec > 1 && !pci_msi_domain_supports (dev , MSI_FLAG_MULTI_PCI_MSI , ALLOW_LEGACY ))
397
- return 1 ;
398
-
399
- /*
400
- * Disable MSI during setup in the hardware, but mark it enabled
401
- * so that setup code can evaluate it.
402
- */
403
- pci_msi_set_enable (dev , 0 );
404
- dev -> msi_enabled = 1 ;
405
-
406
- struct irq_affinity_desc * masks __free (kfree ) =
407
- affd ? irq_create_affinity_masks (nvec , affd ) : NULL ;
408
-
409
- guard (msi_descs_lock )(& dev -> dev );
410
- return __msi_capability_init (dev , nvec , masks );
411
- }
412
-
413
414
int __pci_enable_msi_range (struct pci_dev * dev , int minvec , int maxvec ,
414
415
struct irq_affinity * affd )
415
416
{
@@ -662,41 +663,40 @@ static void msix_mask_all(void __iomem *base, int tsize)
662
663
writel (ctrl , base + PCI_MSIX_ENTRY_VECTOR_CTRL );
663
664
}
664
665
665
- static int __msix_setup_interrupts (struct pci_dev * dev , struct msix_entry * entries ,
666
- int nvec , struct irq_affinity_desc * masks )
666
+ static int msix_setup_interrupts (struct pci_dev * dev , struct msix_entry * entries ,
667
+ int nvec , struct irq_affinity * affd )
667
668
{
668
- int ret = msix_setup_msi_descs (dev , entries , nvec , masks );
669
+ struct irq_affinity_desc * masks = NULL ;
670
+ int ret ;
671
+
672
+ if (affd )
673
+ masks = irq_create_affinity_masks (nvec , affd );
669
674
675
+ msi_lock_descs (& dev -> dev );
676
+ ret = msix_setup_msi_descs (dev , entries , nvec , masks );
670
677
if (ret )
671
- goto fail ;
678
+ goto out_free ;
672
679
673
680
ret = pci_msi_setup_msi_irqs (dev , nvec , PCI_CAP_ID_MSIX );
674
681
if (ret )
675
- goto fail ;
682
+ goto out_free ;
676
683
677
684
/* Check if all MSI entries honor device restrictions */
678
685
ret = msi_verify_entries (dev );
679
686
if (ret )
680
- goto fail ;
687
+ goto out_free ;
681
688
682
689
msix_update_entries (dev , entries );
683
- return 0 ;
690
+ goto out_unlock ;
684
691
685
- fail :
692
+ out_free :
686
693
pci_free_msi_irqs (dev );
694
+ out_unlock :
695
+ msi_unlock_descs (& dev -> dev );
696
+ kfree (masks );
687
697
return ret ;
688
698
}
689
699
690
- static int msix_setup_interrupts (struct pci_dev * dev , struct msix_entry * entries ,
691
- int nvec , struct irq_affinity * affd )
692
- {
693
- struct irq_affinity_desc * masks __free (kfree ) =
694
- affd ? irq_create_affinity_masks (nvec , affd ) : NULL ;
695
-
696
- guard (msi_descs_lock )(& dev -> dev );
697
- return __msix_setup_interrupts (dev , entries , nvec , masks );
698
- }
699
-
700
700
/**
701
701
* msix_capability_init - configure device's MSI-X capability
702
702
* @dev: pointer to the pci_dev data structure of MSI-X device function
@@ -870,13 +870,13 @@ void __pci_restore_msix_state(struct pci_dev *dev)
870
870
871
871
write_msg = arch_restore_msi_irqs (dev );
872
872
873
- scoped_guard (msi_descs_lock , & dev -> dev ) {
874
- msi_for_each_desc (entry , & dev -> dev , MSI_DESC_ALL ) {
875
- if (write_msg )
876
- __pci_write_msi_msg (entry , & entry -> msg );
877
- pci_msix_write_vector_ctrl (entry , entry -> pci .msix_ctrl );
878
- }
873
+ msi_lock_descs (& dev -> dev );
874
+ msi_for_each_desc (entry , & dev -> dev , MSI_DESC_ALL ) {
875
+ if (write_msg )
876
+ __pci_write_msi_msg (entry , & entry -> msg );
877
+ pci_msix_write_vector_ctrl (entry , entry -> pci .msix_ctrl );
879
878
}
879
+ msi_unlock_descs (& dev -> dev );
880
880
881
881
pci_msix_clear_and_set_ctrl (dev , PCI_MSIX_FLAGS_MASKALL , 0 );
882
882
}
@@ -915,53 +915,6 @@ void pci_free_msi_irqs(struct pci_dev *dev)
915
915
}
916
916
}
917
917
918
- #ifdef CONFIG_PCIE_TPH
919
- /**
920
- * pci_msix_write_tph_tag - Update the TPH tag for a given MSI-X vector
921
- * @pdev: The PCIe device to update
922
- * @index: The MSI-X index to update
923
- * @tag: The tag to write
924
- *
925
- * Returns: 0 on success, error code on failure
926
- */
927
- int pci_msix_write_tph_tag (struct pci_dev * pdev , unsigned int index , u16 tag )
928
- {
929
- struct msi_desc * msi_desc ;
930
- struct irq_desc * irq_desc ;
931
- unsigned int virq ;
932
-
933
- if (!pdev -> msix_enabled )
934
- return - ENXIO ;
935
-
936
- guard (msi_descs_lock )(& pdev -> dev );
937
- virq = msi_get_virq (& pdev -> dev , index );
938
- if (!virq )
939
- return - ENXIO ;
940
- /*
941
- * This is a horrible hack, but short of implementing a PCI
942
- * specific interrupt chip callback and a huge pile of
943
- * infrastructure, this is the minor nuissance. It provides the
944
- * protection against concurrent operations on this entry and keeps
945
- * the control word cache in sync.
946
- */
947
- irq_desc = irq_to_desc (virq );
948
- if (!irq_desc )
949
- return - ENXIO ;
950
-
951
- guard (raw_spinlock_irq )(& irq_desc -> lock );
952
- msi_desc = irq_data_get_msi_desc (& irq_desc -> irq_data );
953
- if (!msi_desc || msi_desc -> pci .msi_attrib .is_virtual )
954
- return - ENXIO ;
955
-
956
- msi_desc -> pci .msix_ctrl &= ~PCI_MSIX_ENTRY_CTRL_ST ;
957
- msi_desc -> pci .msix_ctrl |= FIELD_PREP (PCI_MSIX_ENTRY_CTRL_ST , tag );
958
- pci_msix_write_vector_ctrl (msi_desc , msi_desc -> pci .msix_ctrl );
959
- /* Flush the write */
960
- readl (pci_msix_desc_addr (msi_desc ));
961
- return 0 ;
962
- }
963
- #endif
964
-
965
918
/* Misc. infrastructure */
966
919
967
920
struct pci_dev * msi_desc_to_pci_dev (struct msi_desc * desc )
0 commit comments