Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Ensure MSI-X is disabled if allocation of MSI-X ...



details:   https://anonhg.NetBSD.org/src/rev/b396b2e5d126
branches:  trunk
changeset: 976300:b396b2e5d126
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Thu Sep 17 17:33:50 2020 +0000

description:
Ensure MSI-X is disabled if allocation of MSI-X interrupts fail.

The virtio device config space moves out from under us when MSI-X
remains enabled, and/or INTx interrupts are masked if we don't ensure
this.

This un-breaks virtio devices that run out of MSI-X interrupts.
Particularly a problem on uniproc x86, where there are only 8 or 9
vectors available, allowing for only about 4 virtio devices to use
MSI-X.

diffstat:

 sys/dev/pci/virtio_pci.c |  14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diffs (46 lines):

diff -r 973f72a71e84 -r b396b2e5d126 sys/dev/pci/virtio_pci.c
--- a/sys/dev/pci/virtio_pci.c  Thu Sep 17 17:09:59 2020 +0000
+++ b/sys/dev/pci/virtio_pci.c  Thu Sep 17 17:33:50 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.12 2020/09/17 17:04:31 jakllsch Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.13 2020/09/17 17:33:50 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2010 Minoura Makoto.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.12 2020/09/17 17:04:31 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.13 2020/09/17 17:33:50 jakllsch Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -662,10 +662,13 @@
        struct virtio_pci_softc * const psc = (struct virtio_pci_softc *)sc;
        device_t self = sc->sc_dev;
        pci_chipset_tag_t pc = psc->sc_pa.pa_pc;
+       pcitag_t tag = psc->sc_pa.pa_tag;
        int error;
        int nmsix;
+       int off;
        int counts[PCI_INTR_TYPE_SIZE];
        pci_intr_type_t max_type;
+       pcireg_t ctl;
 
        nmsix = pci_msix_count(psc->sc_pa.pa_pc, psc->sc_pa.pa_tag);
        aprint_debug_dev(self, "pci_msix_count=%d\n", nmsix);
@@ -730,6 +733,13 @@
 
                psc->sc_ihs_num = 1;
                psc->sc_config_offset = VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI;
+
+               error = pci_get_capability(pc, tag, PCI_CAP_MSIX, &off, NULL);
+               if (error != 0) {
+                       ctl = pci_conf_read(pc, tag, off + PCI_MSIX_CTL);
+                       ctl &= ~PCI_MSIX_CTL_ENABLE;
+                       pci_conf_write(pc, tag, off + PCI_MSIX_CTL, ctl);
+               }
        }
 
        return 0;



Home | Main Index | Thread Index | Old Index