kernel: Remove some unused variables in RAID and disk drivers.
[dragonfly.git] / sys / dev / disk / aic7xxx / aic_osm_lib.c
CommitLineData
750f3593
PA
1/*
2 * FreeBSD OSM Library for the aic7xxx aic79xx based Adaptec SCSI controllers
3 *
4 * Copyright (c) 1994-2002 Justin T. Gibbs.
5 * Copyright (c) 2001-2003 Adaptec Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU Public License ("GPL").
19 *
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
30 * SUCH DAMAGE.
31 *
32 * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic_osm_lib.c#5 $
33 *
dff3fb2d 34 * $FreeBSD: src/sys/dev/aic7xxx/aic_osm_lib.c,v 1.3 2004/08/17 00:14:31 gibbs Exp $
750f3593
PA
35 */
36
37static void aic_recovery_thread(void *arg);
38
39void
40aic_set_recoveryscb(struct aic_softc *aic, struct scb *scb)
41{
42
43 if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
44 struct scb *list_scb;
45
46 scb->flags |= SCB_RECOVERY_SCB;
47
dff3fb2d 48 AIC_SCB_DATA(aic)->recovery_scbs++;
750f3593
PA
49
50 /*
51 * Go through all of our pending SCBs and remove
52 * any scheduled timeouts for them. We will reschedule
53 * them after we've successfully fixed this problem.
54 */
55 LIST_FOREACH(list_scb, &aic->pending_scbs, pending_links) {
ef8ef949 56 callout_stop(&scb->io_timer);
750f3593
PA
57 }
58 }
59}
60
61void
62aic_platform_timeout(void *arg)
63{
64 struct scb *scb;
65
66 scb = (struct scb *)arg;
ef8ef949 67 aic_lock(scb->aic_softc);
750f3593 68 aic_timeout(scb);
ef8ef949 69 aic_unlock(scb->aic_softc);
750f3593
PA
70}
71
72int
73aic_spawn_recovery_thread(struct aic_softc *aic)
74{
75 int error;
76
77 error = aic_kthread_create(aic_recovery_thread, aic,
78 &aic->platform_data->recovery_thread,
79 /*flags*/0, /*altstack*/0, "aic_recovery%d",
80 aic->unit);
81 return (error);
82}
83
84/*
85 * Lock is not held on entry.
86 */
87void
88aic_terminate_recovery_thread(struct aic_softc *aic)
89{
90
750f3593 91 if (aic->platform_data->recovery_thread == NULL) {
750f3593
PA
92 return;
93 }
94 aic->flags |= AIC_SHUTDOWN_RECOVERY;
95 wakeup(aic);
96 /*
97 * Sleep on a slightly different location
98 * for this interlock just for added safety.
99 */
ef8ef949 100 aic_lock(aic);
ae8e83e6 101 tsleep_interlock(aic->platform_data, 0);
ef8ef949 102 aic_unlock(aic);
d9345d3a 103 tsleep(aic->platform_data, PINTERLOCKED, "thtrm", 0);
750f3593
PA
104}
105
106static void
107aic_recovery_thread(void *arg)
108{
109 struct aic_softc *aic;
110
cd8ab232
MD
111 get_mplock();
112
750f3593 113 aic = (struct aic_softc *)arg;
ef8ef949 114 aic_lock(aic);
cd8ab232 115
750f3593
PA
116 for (;;) {
117
118 if (LIST_EMPTY(&aic->timedout_scbs) != 0
ef8ef949 119 && (aic->flags & AIC_SHUTDOWN_RECOVERY) == 0) {
ae8e83e6 120 tsleep_interlock(aic, 0);
ef8ef949 121 aic_unlock(aic);
d9345d3a 122 tsleep(aic, PINTERLOCKED, "idle", 0);
ef8ef949 123 aic_lock(aic);
ef8ef949 124 }
750f3593
PA
125
126 if ((aic->flags & AIC_SHUTDOWN_RECOVERY) != 0)
127 break;
128
750f3593 129 aic_recover_commands(aic);
750f3593
PA
130 }
131 aic->platform_data->recovery_thread = NULL;
132 wakeup(aic->platform_data);
ef8ef949 133 aic_unlock(aic);
cd8ab232
MD
134
135 rel_mplock();
750f3593 136}