timeout/untimeout ==> callout_*
[dragonfly.git] / sys / dev / disk / i386 / bs / bsfunc.h
1 /*      $NecBSD: bsfunc.h,v 1.1 1997/07/18 09:19:03 kmatsuda Exp $      */
2 /*      $NetBSD$        */
3 /*      $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsfunc.h,v 1.5 2004/09/18 18:47:20 dillon Exp $ */
4 /*
5  * [NetBSD for NEC PC98 series]
6  *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
7  *  All rights reserved.
8  * 
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. The name of the author may not be used to endorse or promote products
18  *     derived from this software without specific prior written permission.
19  * 
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Copyright (c) 1994, 1995, 1996 Naofumi HONDA.  All rights reserved.
34  */
35
36 /**************************************************
37  * FUNC
38  **************************************************/
39 /* timeout */
40 void bstimeout (void *);
41
42 /* ctrl setup */
43 void bs_setup_ctrl (struct targ_info *, u_int, u_int);
44 struct targ_info *bs_init_target_info (struct bs_softc *, int);
45
46 /* msg op */
47 int bs_send_msg (struct targ_info *, u_int, struct msgbase *, int);
48 struct bsccb *bs_request_sense (struct targ_info *);
49
50 /* sync msg op */
51 int bs_start_syncmsg (struct targ_info *, struct bsccb *, int);
52 int bs_send_syncmsg (struct targ_info *);
53 int bs_analyze_syncmsg (struct targ_info *, struct bsccb *);
54
55 /* reset device */
56 void bs_scsibus_start (struct bs_softc *);
57 void bs_reset_nexus (struct bs_softc *);
58 struct bsccb *bs_force_abort (struct targ_info *);
59 void bs_reset_device (struct targ_info *);
60
61 /* ccb */
62 struct bsccb *bs_make_internal_ccb (struct targ_info *, u_int, u_int8_t *, u_int, u_int8_t *, u_int, u_int, int);
63 struct bsccb *bs_make_msg_ccb (struct targ_info *, u_int, struct bsccb *, struct msgbase *, u_int);
64
65 /* misc funcs */
66 void bs_printf (struct targ_info *, char *, char *);
67 void bs_panic (struct bs_softc *, u_char *);
68
69 /* misc debug */
70 u_int bsr (u_int);
71 u_int bsw (u_int, int);
72 void bs_debug_print_all (struct bs_softc *);
73 void bs_debug_print (struct bs_softc *, struct targ_info *);
74
75 /**************************************************
76  * TARG FLAGS
77  *************************************************/
78 static BS_INLINE int bs_check_sat (struct targ_info *);
79 static BS_INLINE int bs_check_smit (struct targ_info *);
80 static BS_INLINE int bs_check_disc (struct targ_info *);
81 static BS_INLINE int bs_check_link (struct targ_info *, struct bsccb *);
82 static BS_INLINE u_int8_t bs_identify_msg (struct targ_info *);
83 static BS_INLINE void bs_targ_flags (struct targ_info *, struct bsccb *);
84
85 static BS_INLINE int
86 bs_check_disc(ti)
87         struct targ_info *ti;
88 {
89
90         return (ti->ti_flags & BSDISC);
91 }
92
93 static BS_INLINE int
94 bs_check_sat(ti)
95         struct targ_info *ti;
96 {
97
98         return (ti->ti_flags & BSSAT);
99 }
100
101 static BS_INLINE int
102 bs_check_smit(ti)
103         struct targ_info *ti;
104 {
105
106         return (ti->ti_flags & BSSMIT);
107 }
108
109 static BS_INLINE int
110 bs_check_link(ti, cb)
111         struct targ_info *ti;
112         struct bsccb *cb;
113 {
114         struct bsccb *nextcb;
115
116         return ((ti->ti_flags & BSLINK) &&
117                 (nextcb = TAILQ_NEXT(cb, ccb_chain)) &&
118                 (nextcb->bsccb_flags & BSLINK));
119 }
120
121 static BS_INLINE u_int8_t
122 bs_identify_msg(ti)
123         struct targ_info *ti;
124 {
125
126         return ((bs_check_disc(ti) ? 0xc0 : 0x80) | ti->ti_lun);
127 }
128
129 static BS_INLINE void
130 bs_targ_flags(ti, cb)
131         struct targ_info *ti;
132         struct bsccb *cb;
133 {
134         u_int cmf = (u_int) bshw_cmd[cb->cmd[0]];
135
136         cb->bsccb_flags |= ((cmf & (BSSAT | BSSMIT | BSLINK)) | BSDISC);
137         cb->bsccb_flags &= ti->ti_mflags;
138
139         if (cb->datalen < DEV_BSIZE)
140                 cb->bsccb_flags &= ~BSSMIT;
141         if (cb->bsccb_flags & BSFORCEIOPOLL)
142                 cb->bsccb_flags &= ~(BSLINK | BSSMIT | BSSAT | BSDISC);
143 }
144
145 /**************************************************
146  * QUEUE OP
147  **************************************************/
148 static BS_INLINE void bs_hostque_init (struct bs_softc *);
149 static BS_INLINE void bs_hostque_head (struct bs_softc *, struct targ_info *);
150 static BS_INLINE void bs_hostque_tail (struct bs_softc *, struct targ_info *);
151 static BS_INLINE void bs_hostque_delete (struct bs_softc *, struct targ_info *);
152
153 static BS_INLINE void
154 bs_hostque_init(bsc)
155         struct bs_softc *bsc;
156 {
157
158         TAILQ_INIT(&bsc->sc_sttab);
159         TAILQ_INIT(&bsc->sc_titab);
160 }
161
162 static BS_INLINE void
163 bs_hostque_head(bsc, ti)
164         struct bs_softc *bsc;
165         struct targ_info *ti;
166 {
167
168         if (ti->ti_flags & BSQUEUED) {
169                 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
170         } else {
171                 ti->ti_flags |= BSQUEUED;
172         }
173         TAILQ_INSERT_HEAD(&bsc->sc_sttab, ti, ti_wchain);
174 }
175
176 static BS_INLINE void
177 bs_hostque_tail(bsc, ti)
178         struct bs_softc *bsc;
179         struct targ_info *ti;
180 {
181
182         if (ti->ti_flags & BSQUEUED) {
183                 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
184         } else {
185                 ti->ti_flags |= BSQUEUED;
186         }
187         TAILQ_INSERT_TAIL(&bsc->sc_sttab, ti, ti_wchain);
188 }
189
190 static BS_INLINE void
191 bs_hostque_delete(bsc, ti)
192         struct bs_softc *bsc;
193         struct targ_info *ti;
194 {
195
196         if (ti->ti_flags & BSQUEUED)
197         {
198                 ti->ti_flags &= ~BSQUEUED;
199                 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
200         }
201 }
202
203 /*************************************************************
204  * TIMEOUT
205  ************************************************************/
206 static BS_INLINE void bs_start_timeout (struct bs_softc *);
207 static BS_INLINE void bs_terminate_timeout (struct bs_softc *);
208
209 static BS_INLINE void
210 bs_start_timeout(bsc)
211         struct bs_softc *bsc;
212 {
213
214         if ((bsc->sc_flags & BSSTARTTIMEOUT) == 0)
215         {
216                 bsc->sc_flags |= BSSTARTTIMEOUT;
217                 callout_reset(&bsc->timeout_ch, BS_TIMEOUT_INTERVAL,
218                                 bstimeout, bsc);
219         }
220 }
221
222 static BS_INLINE void
223 bs_terminate_timeout(bsc)
224         struct bs_softc *bsc;
225 {
226
227         if (bsc->sc_flags & BSSTARTTIMEOUT)
228         {
229                 callout_stop(&bsc->timeout_ch);
230                 bsc->sc_flags &= ~BSSTARTTIMEOUT;
231         }
232 }