remove __P() from this directory
[dragonfly.git] / sys / dev / disk / i386 / bs / bsfunc.h
CommitLineData
984263bc
MD
1/* $NecBSD: bsfunc.h,v 1.1 1997/07/18 09:19:03 kmatsuda Exp $ */
2/* $NetBSD$ */
38e94a25 3/* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsfunc.h,v 1.2 2003/08/27 10:35:16 rob Exp $ */
984263bc
MD
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 */
38e94a25 40void bstimeout (void *);
984263bc
MD
41
42/* ctrl setup */
38e94a25
RG
43void bs_setup_ctrl (struct targ_info *, u_int, u_int);
44struct targ_info *bs_init_target_info (struct bs_softc *, int);
984263bc
MD
45
46/* msg op */
38e94a25
RG
47int bs_send_msg (struct targ_info *, u_int, struct msgbase *, int);
48struct bsccb *bs_request_sense (struct targ_info *);
984263bc
MD
49
50/* sync msg op */
38e94a25
RG
51int bs_start_syncmsg (struct targ_info *, struct bsccb *, int);
52int bs_send_syncmsg (struct targ_info *);
53int bs_analyze_syncmsg (struct targ_info *, struct bsccb *);
984263bc
MD
54
55/* reset device */
38e94a25
RG
56void bs_scsibus_start (struct bs_softc *);
57void bs_reset_nexus (struct bs_softc *);
58struct bsccb *bs_force_abort (struct targ_info *);
59void bs_reset_device (struct targ_info *);
984263bc
MD
60
61/* ccb */
38e94a25
RG
62struct bsccb *bs_make_internal_ccb (struct targ_info *, u_int, u_int8_t *, u_int, u_int8_t *, u_int, u_int, int);
63struct bsccb *bs_make_msg_ccb (struct targ_info *, u_int, struct bsccb *, struct msgbase *, u_int);
984263bc
MD
64
65/* misc funcs */
38e94a25
RG
66void bs_printf (struct targ_info *, char *, char *);
67void bs_panic (struct bs_softc *, u_char *);
984263bc
MD
68
69/* misc debug */
38e94a25
RG
70u_int bsr (u_int);
71u_int bsw (u_int, int);
72void bs_debug_print_all (struct bs_softc *);
73void bs_debug_print (struct bs_softc *, struct targ_info *);
984263bc
MD
74
75/**************************************************
76 * TARG FLAGS
77 *************************************************/
38e94a25
RG
78static BS_INLINE int bs_check_sat (struct targ_info *);
79static BS_INLINE int bs_check_smit (struct targ_info *);
80static BS_INLINE int bs_check_disc (struct targ_info *);
81static BS_INLINE int bs_check_link (struct targ_info *, struct bsccb *);
82static BS_INLINE u_int8_t bs_identify_msg (struct targ_info *);
83static BS_INLINE void bs_targ_flags (struct targ_info *, struct bsccb *);
984263bc
MD
84
85static BS_INLINE int
86bs_check_disc(ti)
87 struct targ_info *ti;
88{
89
90 return (ti->ti_flags & BSDISC);
91}
92
93static BS_INLINE int
94bs_check_sat(ti)
95 struct targ_info *ti;
96{
97
98 return (ti->ti_flags & BSSAT);
99}
100
101static BS_INLINE int
102bs_check_smit(ti)
103 struct targ_info *ti;
104{
105
106 return (ti->ti_flags & BSSMIT);
107}
108
109static BS_INLINE int
110bs_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 = cb->ccb_chain.tqe_next) &&
118 (nextcb->bsccb_flags & BSLINK));
119}
120
121static BS_INLINE u_int8_t
122bs_identify_msg(ti)
123 struct targ_info *ti;
124{
125
126 return ((bs_check_disc(ti) ? 0xc0 : 0x80) | ti->ti_lun);
127}
128
129static BS_INLINE void
130bs_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 **************************************************/
38e94a25
RG
148static BS_INLINE void bs_hostque_init (struct bs_softc *);
149static BS_INLINE void bs_hostque_head (struct bs_softc *, struct targ_info *);
150static BS_INLINE void bs_hostque_tail (struct bs_softc *, struct targ_info *);
151static BS_INLINE void bs_hostque_delete (struct bs_softc *, struct targ_info *);
984263bc
MD
152
153static BS_INLINE void
154bs_hostque_init(bsc)
155 struct bs_softc *bsc;
156{
157
158 TAILQ_INIT(&bsc->sc_sttab);
159 TAILQ_INIT(&bsc->sc_titab);
160}
161
162static BS_INLINE void
163bs_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
176static BS_INLINE void
177bs_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
190static BS_INLINE void
191bs_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 ************************************************************/
38e94a25
RG
206static BS_INLINE void bs_start_timeout (struct bs_softc *);
207static BS_INLINE void bs_terminate_timeout (struct bs_softc *);
984263bc
MD
208
209static BS_INLINE void
210bs_start_timeout(bsc)
211 struct bs_softc *bsc;
212{
213
214 if ((bsc->sc_flags & BSSTARTTIMEOUT) == 0)
215 {
216 bsc->sc_flags |= BSSTARTTIMEOUT;
217#ifdef __FreeBSD__
218 bsc->timeout_ch =
219#endif
220 timeout(bstimeout, bsc, BS_TIMEOUT_INTERVAL);
221 }
222}
223
224static BS_INLINE void
225bs_terminate_timeout(bsc)
226 struct bs_softc *bsc;
227{
228
229 if (bsc->sc_flags & BSSTARTTIMEOUT)
230 {
231#ifdef __FreeBSD__
232 untimeout(bstimeout, bsc,
233 bsc->timeout_ch);
234#else
235 untimeout(bstimeout, bsc);
236#endif
237 bsc->sc_flags &= ~BSSTARTTIMEOUT;
238 }
239}