git: 10bbea2e25ef - stable/14 - mpi3mr: Move creation of watchdog to interupt config hook

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 19 Oct 2023 21:24:04 UTC
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=10bbea2e25ef95936619b6522bbdeea2317e76a5

commit 10bbea2e25ef95936619b6522bbdeea2317e76a5
Author:     Sumit Saxena <sumit@FreeBSD.org>
AuthorDate: 2023-10-19 21:15:50 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-10-19 21:21:12 +0000

    mpi3mr: Move creation of watchdog to interupt config hook
    
    Move creation of watchdog process from just before we configure the
    interrupt config hook to into the config hook itself. This prevents it
    from racing the config intr hook and doing an extra reset of the
    card. This extra reset is usually harmless, but sometimes it can prevent
    discovery of devices if done at just the wrong time. This can lead to no
    disks being registered in a box full of disks, for example. Starting it
    later eliminates this race, making discovery reliable.
    
    Reviewed by: imp
    
    (cherry picked from commit 7e02c7074c4c6df77b860e0dbcd032a2ea04b98b)
---
 sys/dev/mpi3mr/mpi3mr_pci.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sys/dev/mpi3mr/mpi3mr_pci.c b/sys/dev/mpi3mr/mpi3mr_pci.c
index d7278e5549e7..4935ac0d519c 100644
--- a/sys/dev/mpi3mr/mpi3mr_pci.c
+++ b/sys/dev/mpi3mr/mpi3mr_pci.c
@@ -307,6 +307,7 @@ static void
 mpi3mr_ich_startup(void *arg)
 {
 	struct mpi3mr_softc *sc;
+	int error;
 
 	sc = (struct mpi3mr_softc *)arg;
 	mpi3mr_dprint(sc, MPI3MR_XINFO, "%s entry\n", __func__);
@@ -314,8 +315,16 @@ mpi3mr_ich_startup(void *arg)
 	mtx_lock(&sc->mpi3mr_mtx);
 	
 	mpi3mr_startup(sc);
+
 	mtx_unlock(&sc->mpi3mr_mtx);
 
+	error = mpi3mr_kproc_create(mpi3mr_watchdog_thread, sc,
+	    &sc->watchdog_thread, 0, 0, "mpi3mr_watchdog%d",
+	    device_get_unit(sc->mpi3mr_dev));
+
+	if (error)
+		device_printf(sc->mpi3mr_dev, "Error %d starting OCR thread\n", error);
+
 	mpi3mr_dprint(sc, MPI3MR_XINFO, "disestablish config intrhook\n");
 	config_intrhook_disestablish(&sc->mpi3mr_ich);
 	sc->mpi3mr_ich.ich_arg = NULL;
@@ -443,14 +452,6 @@ mpi3mr_pci_attach(device_t dev)
 		goto load_failed;
 	}
 	
-	error = mpi3mr_kproc_create(mpi3mr_watchdog_thread, sc,
-	    &sc->watchdog_thread, 0, 0, "mpi3mr_watchdog%d",
-	    device_get_unit(sc->mpi3mr_dev));
-	if (error) {
-		device_printf(sc->mpi3mr_dev, "Error %d starting OCR thread\n", error);
-		goto load_failed;
-	}
-	
 	sc->mpi3mr_ich.ich_func = mpi3mr_ich_startup;
 	sc->mpi3mr_ich.ich_arg = sc;
 	if (config_intrhook_establish(&sc->mpi3mr_ich) != 0) {