2 * FreeBSD OSM Library for the aic7xxx aic79xx based Adaptec SCSI controllers
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2001-2003 Adaptec Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU Public License ("GPL").
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic_osm_lib.c#5 $
34 * $FreeBSD: src/sys/dev/aic7xxx/aic_osm_lib.c,v 1.2 2003/12/19 18:34:30 gibbs Exp $
35 * $DragonFly: src/sys/dev/disk/aic7xxx/aic_osm_lib.c,v 1.1 2007/07/06 00:01:16 pavalos Exp $
38 static void aic_recovery_thread(void *arg);
41 aic_set_recoveryscb(struct aic_softc *aic, struct scb *scb)
44 if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
47 scb->flags |= SCB_RECOVERY_SCB;
50 * Take all queued, but not sent SCBs out of the equation.
51 * Also ensure that no new CCBs are queued to us while we
52 * try to fix this problem.
54 if ((scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
55 xpt_freeze_simq(SCB_GET_SIM(aic, scb), /*count*/1);
56 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
60 * Go through all of our pending SCBs and remove
61 * any scheduled timeouts for them. We will reschedule
62 * them after we've successfully fixed this problem.
64 LIST_FOREACH(list_scb, &aic->pending_scbs, pending_links) {
67 ccb = list_scb->io_ctx;
68 callout_stop(&ccb->ccb_h.timeout_ch);
74 aic_platform_timeout(void *arg)
78 scb = (struct scb *)arg;
85 aic_spawn_recovery_thread(struct aic_softc *aic)
89 error = aic_kthread_create(aic_recovery_thread, aic,
90 &aic->platform_data->recovery_thread,
91 /*flags*/0, /*altstack*/0, "aic_recovery%d",
97 * Lock is not held on entry.
100 aic_terminate_recovery_thread(struct aic_softc *aic)
104 if (aic->platform_data->recovery_thread == NULL) {
108 aic->flags |= AIC_SHUTDOWN_RECOVERY;
111 * Sleep on a slightly different location
112 * for this interlock just for added safety.
114 tsleep(aic->platform_data, 0, "thtrm", 0);
119 aic_recovery_thread(void *arg)
121 struct aic_softc *aic;
123 #if __FreeBSD_version >= 500000
126 aic = (struct aic_softc *)arg;
130 if (LIST_EMPTY(&aic->timedout_scbs) != 0
131 && (aic->flags & AIC_SHUTDOWN_RECOVERY) == 0)
132 tsleep(aic, 0, "idle", 0);
134 if ((aic->flags & AIC_SHUTDOWN_RECOVERY) != 0)
138 aic_recover_commands(aic);
141 aic->platform_data->recovery_thread = NULL;
142 wakeup(aic->platform_data);
144 #if __FreeBSD_version >= 500000