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