Index: ciss.c =================================================================== RCS file: /home/ncvs/src/sys/dev/ciss/ciss.c,v retrieving revision 1.84 diff -u -r1.84 ciss.c --- ciss.c 20 Oct 2007 23:23:14 -0000 1.84 +++ ciss.c 30 Oct 2007 13:17:53 -0000 @@ -182,7 +182,7 @@ static int ciss_name_device(struct ciss_softc *sc, int bus, int target); /* periodic status monitoring */ -static void ciss_periodic(void *arg); +static void ciss_periodic_thread(void *arg); static void ciss_disable_adapter(struct ciss_softc *sc); static void ciss_notify_event(struct ciss_softc *sc); static void ciss_notify_complete(struct ciss_request *cr); @@ -417,7 +417,6 @@ ciss_initq_complete(sc); ciss_initq_notify(sc); mtx_init(&sc->ciss_mtx, "cissmtx", NULL, MTX_DEF); - callout_init_mtx(&sc->ciss_periodic, &sc->ciss_mtx, 0); /* * Initalize device sysctls. @@ -460,9 +459,18 @@ goto out; /* - * Start the heartbeat routine and event chain. + * Start the heartbeat monitoring thread. */ - ciss_periodic(sc); +#if __FreeBSD_version > 500005 + if (kproc_create((void(*)(void *))ciss_periodic_thread, sc, + &sc->ciss_periodic_thread, 0, 0, "ciss_periodic%d", + device_get_unit(sc->ciss_dev))) +#else + if (kproc_create((void(*)(void *))ciss_periodic_thread, sc, + &sc->ciss_periodic_thread, "ciss_periodic%d", + device_get_unit(sc->ciss_dev))) +#endif + panic("Could not create periodic thread\n"); /* * Create the control device. @@ -1667,9 +1675,6 @@ /* we're going away */ sc->ciss_flags |= CISS_FLAG_ABORTING; - /* terminate the periodic heartbeat routine */ - callout_stop(&sc->ciss_periodic); - /* cancel the Event Notify chain */ ciss_notify_abort(sc); @@ -1700,8 +1705,6 @@ if (sc->ciss_dev_t != NULL) destroy_dev(sc->ciss_dev_t); - /* Final cleanup of the callout. */ - callout_drain(&sc->ciss_periodic); mtx_destroy(&sc->ciss_mtx); /* free the controller data */ @@ -3063,10 +3066,10 @@ } /************************************************************************ - * Periodic status monitoring. + * Periodic status monitoring thread. */ static void -ciss_periodic(void *arg) +ciss_periodic_thread(void *arg) { struct ciss_softc *sc; struct ciss_request *cr = NULL; @@ -3077,56 +3080,55 @@ sc = (struct ciss_softc *)arg; - /* - * Check the adapter heartbeat. - */ - if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { - sc->ciss_heart_attack++; - debug(0, "adapter heart attack in progress 0x%x/%d", - sc->ciss_heartbeat, sc->ciss_heart_attack); - if (sc->ciss_heart_attack == 3) { - ciss_printf(sc, "ADAPTER HEARTBEAT FAILED\n"); - ciss_disable_adapter(sc); - return; + while ((sc->ciss_flags & CISS_FLAG_ABORTING) ==0) { + /* + * Check the adapter heartbeat. + */ + if (sc->ciss_cfg->heartbeat == sc->ciss_heartbeat) { + sc->ciss_heart_attack++; + debug(0, "adapter heart attack in progress 0x%x/%d", + sc->ciss_heartbeat, sc->ciss_heart_attack); + if (sc->ciss_heart_attack == 3) { + ciss_printf(sc, "ADAPTER HEARTBEAT FAILED\n"); + ciss_disable_adapter(sc); + break; + } + } else { + sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; + sc->ciss_heart_attack = 0; + debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); } - } else { - sc->ciss_heartbeat = sc->ciss_cfg->heartbeat; - sc->ciss_heart_attack = 0; - debug(3, "new heartbeat 0x%x", sc->ciss_heartbeat); - } - /* - * Send the NOP message and wait for a response. - */ - if ((error = ciss_get_request(sc, &cr)) == 0) { - cc = CISS_FIND_COMMAND(cr); - cc->cdb.cdb_length = 1; - cc->cdb.type = CISS_CDB_TYPE_MESSAGE; - cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; - cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; - cc->cdb.timeout = 0; - cc->cdb.cdb[0] = CISS_OPCODE_MESSAGE_NOP; + /* + * Send the NOP message and wait for a response. + */ + if ((error = ciss_get_request(sc, &cr)) == 0) { + cc = CISS_FIND_COMMAND(cr); + cc->cdb.cdb_length = 1; + cc->cdb.type = CISS_CDB_TYPE_MESSAGE; + cc->cdb.attribute = CISS_CDB_ATTRIBUTE_SIMPLE; + cc->cdb.direction = CISS_CDB_DIRECTION_WRITE; + cc->cdb.timeout = 0; + cc->cdb.cdb[0] = CISS_OPCODE_MESSAGE_NOP; - if ((error = ciss_synch_request(cr, 10 * 1000)) != 0) { - ciss_printf(sc, "SENDING NOP MESSAGE FAILED\n"); + if ((error = ciss_synch_request(cr, 10 * 1000)) != 0) { + ciss_printf(sc, "SENDING NOP MESSAGE FAILED\n"); + } + + ciss_release_request(cr); } - ciss_release_request(cr); - } + /* + * If the notify event request has died for some reason, or has + * not started yet, restart it. + */ + if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { + debug(0, "(re)starting Event Notify chain"); + ciss_notify_event(sc); + } - /* - * If the notify event request has died for some reason, or has - * not started yet, restart it. - */ - if (!(sc->ciss_flags & CISS_FLAG_NOTIFY_OK)) { - debug(0, "(re)starting Event Notify chain"); - ciss_notify_event(sc); + msleep(&sc->ciss_periodic_thread, &sc->ciss_mtx, PUSER, "thmon", CISS_HEARTBEAT_RATE * hz); } - - /* - * Reschedule. - */ - callout_reset(&sc->ciss_periodic, CISS_HEARTBEAT_RATE * hz, ciss_periodic, sc); } /************************************************************************ Index: cissvar.h =================================================================== RCS file: /home/ncvs/src/sys/dev/ciss/cissvar.h,v retrieving revision 1.11 diff -u -r1.11 cissvar.h --- cissvar.h 1 May 2007 05:13:15 -0000 1.11 +++ cissvar.h 30 Oct 2007 12:44:45 -0000 @@ -224,7 +224,7 @@ TAILQ_HEAD(,ciss_request) ciss_notify; /* requests which are defered for processing */ struct proc *ciss_notify_thread; - struct callout ciss_periodic; /* periodic event handling */ + struct proc *ciss_periodic_thread; /* periodic event handling */ struct ciss_request *ciss_periodic_notify; /* notify callback request */ struct mtx ciss_mtx;