/*-1* FreeBSD OSM Library for the aic7xxx aic79xx based Adaptec SCSI controllers2*3* Copyright (c) 1994-2002 Justin T. Gibbs.4* Copyright (c) 2001-2003 Adaptec Inc.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions, and the following disclaimer,12* without modification.13* 2. The name of the author may not be used to endorse or promote products14* derived from this software without specific prior written permission.15*16* Alternatively, this software may be distributed under the terms of the17* GNU Public License ("GPL").18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR23* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic_osm_lib.c#5 $32*/3334#include <sys/cdefs.h>35static void aic_recovery_thread(void *arg);3637void38aic_set_recoveryscb(struct aic_softc *aic, struct scb *scb)39{4041if ((scb->flags & SCB_RECOVERY_SCB) == 0) {42struct scb *list_scb;4344scb->flags |= SCB_RECOVERY_SCB;4546AIC_SCB_DATA(aic)->recovery_scbs++;4748/*49* Go through all of our pending SCBs and remove50* any scheduled timeouts for them. We will reschedule51* them after we've successfully fixed this problem.52*/53LIST_FOREACH(list_scb, &aic->pending_scbs, pending_links) {54callout_stop(&scb->io_timer);55}56}57}5859void60aic_platform_timeout(void *arg)61{62struct scb *scb;6364scb = (struct scb *)arg;65aic_lock(scb->aic_softc);66aic_timeout(scb);67aic_unlock(scb->aic_softc);68}6970int71aic_spawn_recovery_thread(struct aic_softc *aic)72{73int error;7475error = aic_kthread_create(aic_recovery_thread, aic,76&aic->platform_data->recovery_thread,77/*flags*/0, /*altstack*/0, "aic_recovery%d",78aic->unit);79return (error);80}8182/*83* Lock is not held on entry.84*/85void86aic_terminate_recovery_thread(struct aic_softc *aic)87{8889if (aic->platform_data->recovery_thread == NULL) {90return;91}92aic->flags |= AIC_SHUTDOWN_RECOVERY;93wakeup(aic);94/*95* Sleep on a slightly different location96* for this interlock just for added safety.97*/98msleep(aic->platform_data, &aic->platform_data->mtx, PUSER, "thtrm", 0);99}100101static void102aic_recovery_thread(void *arg)103{104struct aic_softc *aic;105106aic = (struct aic_softc *)arg;107aic_lock(aic);108for (;;) {109110if (LIST_EMPTY(&aic->timedout_scbs) != 0111&& (aic->flags & AIC_SHUTDOWN_RECOVERY) == 0)112msleep(aic, &aic->platform_data->mtx, PUSER, "idle", 0);113114if ((aic->flags & AIC_SHUTDOWN_RECOVERY) != 0)115break;116117aic_recover_commands(aic);118}119aic->platform_data->recovery_thread = NULL;120wakeup(aic->platform_data);121aic_unlock(aic);122kproc_exit(0);123}124125void126aic_calc_geometry(struct ccb_calc_geometry *ccg, int extended)127{128cam_calc_geometry(ccg, extended);129}130131132