Module Name: src Committed By: jakllsch Date: Thu Sep 17 17:33:51 UTC 2020
Modified Files: src/sys/dev/pci: virtio_pci.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pci/virtio_pci.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/virtio_pci.c diff -u src/sys/dev/pci/virtio_pci.c:1.12 src/sys/dev/pci/virtio_pci.c:1.13 --- src/sys/dev/pci/virtio_pci.c:1.12 Thu Sep 17 17:04:31 2020 +++ src/sys/dev/pci/virtio_pci.c Thu Sep 17 17:33:50 2020 @@ -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 @@ virtio_pci_setup_interrupts(struct virti 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 @@ retry: 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;