scsi: Launch a thread when scanning for drives in the scsi drivers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c
index c98989c..d2ba023 100644
--- a/src/hw/esp-scsi.c
+++ b/src/hw/esp-scsi.c
@@ -20,6 +20,7 @@
 #include "pcidevice.h" // foreachpci
 #include "pci_ids.h" // PCI_DEVICE_ID
 #include "pci_regs.h" // PCI_VENDOR_ID
+#include "stacks.h" // run_thread
 #include "std/disk.h" // DISK_RET_SUCCESS
 #include "string.h" // memset
 #include "util.h" // usleep
@@ -188,8 +189,9 @@
 }
 
 static void
-init_esp_scsi(struct pci_device *pci)
+init_esp_scsi(void *data)
 {
+    struct pci_device *pci = data;
     u32 iobase = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0);
     if (!iobase)
         return;
@@ -203,8 +205,6 @@
     int i;
     for (i = 0; i <= 7; i++)
         esp_scsi_scan_target(pci, iobase, i);
-
-    return;
 }
 
 void
@@ -221,6 +221,6 @@
         if (pci->vendor != PCI_VENDOR_ID_AMD
             || pci->device != PCI_DEVICE_ID_AMD_SCSI)
             continue;
-        init_esp_scsi(pci);
+        run_thread(init_esp_scsi, pci);
     }
 }
diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c
index fd695fa..b63430d 100644
--- a/src/hw/lsi-scsi.c
+++ b/src/hw/lsi-scsi.c
@@ -20,6 +20,7 @@
 #include "pcidevice.h" // foreachpci
 #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK
 #include "pci_regs.h" // PCI_VENDOR_ID
+#include "stacks.h" // run_thread
 #include "std/disk.h" // DISK_RET_SUCCESS
 #include "string.h" // memset
 #include "util.h" // usleep
@@ -168,8 +169,9 @@
 }
 
 static void
-init_lsi_scsi(struct pci_device *pci)
+init_lsi_scsi(void *data)
 {
+    struct pci_device *pci = data;
     u32 iobase = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0);
     if (!iobase)
         return;
@@ -183,8 +185,6 @@
     int i;
     for (i = 0; i < 7; i++)
         lsi_scsi_scan_target(pci, iobase, i);
-
-    return;
 }
 
 void
@@ -201,6 +201,6 @@
         if (pci->vendor != PCI_VENDOR_ID_LSI_LOGIC
             || pci->device != PCI_DEVICE_ID_LSI_53C895A)
             continue;
-        init_lsi_scsi(pci);
+        run_thread(init_lsi_scsi, pci);
     }
 }
diff --git a/src/hw/megasas.c b/src/hw/megasas.c
index 7514164..efd0f6e 100644
--- a/src/hw/megasas.c
+++ b/src/hw/megasas.c
@@ -357,8 +357,9 @@
 }
 
 static void
-init_megasas(struct pci_device *pci)
+init_megasas(void *data)
 {
+    struct pci_device *pci = data;
     u32 bar = PCI_BASE_ADDRESS_2;
     if (!(pci_config_readl(pci->bdf, bar) & PCI_BASE_ADDRESS_IO_MASK))
         bar = PCI_BASE_ADDRESS_0;
@@ -372,8 +373,6 @@
     // reset
     if (megasas_transition_to_ready(pci, iobase) == 0)
         megasas_scan_target(pci, iobase);
-
-    return;
 }
 
 void
@@ -401,6 +400,6 @@
             pci->device == PCI_DEVICE_ID_DELL_PERC5 ||
             pci->device == PCI_DEVICE_ID_LSI_SAS2208 ||
             pci->device == PCI_DEVICE_ID_LSI_SAS3108)
-            init_megasas(pci);
+            run_thread(init_megasas, pci);
     }
 }
diff --git a/src/hw/mpt-scsi.c b/src/hw/mpt-scsi.c
index 7d1aa3d..a37e44c 100644
--- a/src/hw/mpt-scsi.c
+++ b/src/hw/mpt-scsi.c
@@ -15,6 +15,7 @@
 #include "pcidevice.h" // foreachpci
 #include "pci_ids.h" // PCI_DEVICE_ID
 #include "pci_regs.h" // PCI_VENDOR_ID
+#include "stacks.h" // run_thread
 #include "std/disk.h" // DISK_RET_SUCCESS
 #include "string.h" // memset
 #include "util.h" // usleep
@@ -241,8 +242,9 @@
 }
 
 static void
-init_mpt_scsi(struct pci_device *pci, const char *dev_name)
+init_mpt_scsi(void *data)
 {
+    struct pci_device *pci = data;
     u16 *msg_in_p;
     u32 iobase = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0);
     if (!iobase)
@@ -250,7 +252,8 @@
     struct MptIOCInitReply MptIOCInitReply;
     pci_enable_busmaster(pci);
 
-    dprintf(1, "found %s at %pP, io @ %x\n", dev_name, pci, iobase);
+    dprintf(1, "found mpt-scsi(%04x) at %pP, io @ %x\n"
+            , pci->device, pci, iobase);
 
     // reset
     mpt_out_doorbell(MPT_DOORBELL_MSG_RESET, 0, iobase);
@@ -295,16 +298,10 @@
 
     struct pci_device *pci;
     foreachpci(pci) {
-        if (pci->vendor == PCI_VENDOR_ID_LSI_LOGIC) {
-            if (pci->device == PCI_DEVICE_ID_LSI_53C1030) {
-                init_mpt_scsi(pci, "lsi53c1030");
-            }
-            if (pci->device == PCI_DEVICE_ID_LSI_SAS1068) {
-                init_mpt_scsi(pci, "sas1068");
-            }
-            if (pci->device == PCI_DEVICE_ID_LSI_SAS1068E) {
-                init_mpt_scsi(pci, "sas1068e");
-            }
-        }
+        if (pci->vendor == PCI_VENDOR_ID_LSI_LOGIC
+            && (pci->device == PCI_DEVICE_ID_LSI_53C1030
+                || pci->device == PCI_DEVICE_ID_LSI_SAS1068
+                || pci->device == PCI_DEVICE_ID_LSI_SAS1068E))
+            run_thread(init_mpt_scsi, pci);
     }
 }
diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c
index a9d118b..05cbd91 100644
--- a/src/hw/pvscsi.c
+++ b/src/hw/pvscsi.c
@@ -17,6 +17,7 @@
 #include "pci_ids.h" // PCI_DEVICE_ID_VMWARE_PVSCSI
 #include "pci_regs.h" // PCI_VENDOR_ID
 #include "pvscsi.h" // pvscsi_setup
+#include "stacks.h" // run_thread
 #include "std/disk.h" // DISK_RET_SUCCESS
 #include "string.h" // memset
 #include "util.h" // usleep
@@ -294,8 +295,9 @@
 }
 
 static void
-init_pvscsi(struct pci_device *pci)
+init_pvscsi(void *data)
 {
+    struct pci_device *pci = data;
     void *iobase = pci_enable_membar(pci, PCI_BASE_ADDRESS_0);
     if (!iobase)
         return;
@@ -310,8 +312,6 @@
     int i;
     for (i = 0; i < 7; i++)
         pvscsi_scan_target(pci, iobase, ring_dsc, i);
-
-    return;
 }
 
 void
@@ -328,6 +328,6 @@
         if (pci->vendor != PCI_VENDOR_ID_VMWARE
             || pci->device != PCI_DEVICE_ID_VMWARE_PVSCSI)
             continue;
-        init_pvscsi(pci);
+        run_thread(init_pvscsi, pci);
     }
 }