From abab2155edb1e0088db657871a7b258559fc58a4 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Fri, 5 Jun 2020 02:21:46 +0000 Subject: [PATCH] Limit AHCI to only one MSI if more is not needed. My AMD Ryzen system has 4 AHCI controllers, each supporting 16 MSI vectors. Since two of the controllers have only one SATA port, limit to single MSI saves system 30 interrupt vectors for free. It may be possible to also limit number of MSI vectors to 4 and 8 for the other two controllers, but according to the AHCI specification after that controllers may revert to only one vector, that would be a bigger loss to risk. MFC after: 2 weeks --- sys/dev/ahci/ahci_pci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/dev/ahci/ahci_pci.c b/sys/dev/ahci/ahci_pci.c index c6937965bee..6f87efb6bb9 100644 --- a/sys/dev/ahci/ahci_pci.c +++ b/sys/dev/ahci/ahci_pci.c @@ -470,6 +470,7 @@ ahci_pci_attach(device_t dev) uint8_t revid = pci_get_revid(dev); int msi_count, msix_count; uint8_t table_bar = 0, pba_bar = 0; + uint32_t caps, pi; msi_count = pci_msi_count(dev); msix_count = pci_msix_count(dev); @@ -604,9 +605,12 @@ ahci_pci_attach(device_t dev) /* Setup MSI register parameters */ /* Process hints. */ + caps = ATA_INL(ctlr->r_mem, AHCI_CAP); + pi = ATA_INL(ctlr->r_mem, AHCI_PI); if (ctlr->quirks & AHCI_Q_NOMSI) ctlr->msi = 0; - else if (ctlr->quirks & AHCI_Q_1MSI) + else if ((ctlr->quirks & AHCI_Q_1MSI) || + ((caps & (AHCI_CAP_NPMASK | AHCI_CAP_CCCS)) == 0 && pi == 1)) ctlr->msi = 1; else ctlr->msi = 2;