ref: 3d6deb3f690c2f5e68325c8c528216b386606f63
parent: 82f44b3ffca7c854a3e1bb10aa42da7d5bffae7b
author: mia soweli <inbox@tachibana-labs.org>
date: Sun Jun 16 10:22:58 EDT 2024
9/port: make sure MSI-X is off before enabling and disabling MSI
--- a/sys/src/9/port/pci.c
+++ b/sys/src/9/port/pci.c
@@ -1019,7 +1019,22 @@
return pcienumcaps(p, matchhtcap, cap);
}
+enum {
+ MSIXCtrl = 0x02,
+};
+
static int
+pcimsixdisable(Pcidev *p)
+{
+ int off;
+
+ if((off = pcicap(p, PciCapMSIX)) < 0)
+ return -1;
+ pcicfgw16(p, off + MSIXCtrl, 0);
+ return 0;
+}
+
+static int
pcigetmsi(Pcidev *p)
{
if(p->msi != 0)
@@ -1041,6 +1056,7 @@
if((off = pcigetmsi(p)) < 0)
return -1;
+ pcimsixdisable(p); /* make sure MSI-X is off */
ok64 = (pcicfgr16(p, off + MSICtrl) & (1<<7)) != 0;
pcicfgw32(p, off + MSIAddr, addr);
if(ok64) pcicfgw32(p, off + MSIAddr+4, addr >> 32);
@@ -1054,6 +1070,7 @@
{
int off;
+ pcimsixdisable(p); /* also disable MSI-X */
if((off = pcigetmsi(p)) < 0)
return -1;
pcicfgw16(p, off + MSICtrl, 0);
@@ -1060,22 +1077,7 @@
return 0;
}
-enum {
- MSIXCtrl = 0x02,
-};
-
static int
-pcimsixdisable(Pcidev *p)
-{
- int off;
-
- if((off = pcicap(p, PciCapMSIX)) < 0)
- return -1;
- pcicfgw16(p, off + MSIXCtrl, 0);
- return 0;
-}
-
-static int
pcigetpmrb(Pcidev *p)
{
if(p->pmrb != 0)
@@ -1215,7 +1217,6 @@
{
if(p == nil)
return;
- pcimsixdisable(p);
pcimsidisable(p);
pciclrbme(p);
}
--
⑨