1 /* $NecBSD: bsfunc.h,v 1.1 1997/07/18 09:19:03 kmatsuda Exp $ */
3 /* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsfunc.h,v 1.5 2004/09/18 18:47:20 dillon Exp $ */
5 * [NetBSD for NEC PC98 series]
6 * Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
33 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA. All rights reserved.
36 /**************************************************
38 **************************************************/
40 void bstimeout (void *);
43 void bs_setup_ctrl (struct targ_info *, u_int, u_int);
44 struct targ_info *bs_init_target_info (struct bs_softc *, int);
47 int bs_send_msg (struct targ_info *, u_int, struct msgbase *, int);
48 struct bsccb *bs_request_sense (struct targ_info *);
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 *);
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 *);
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);
66 void bs_printf (struct targ_info *, char *, char *);
67 void bs_panic (struct bs_softc *, u_char *);
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 *);
75 /**************************************************
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 *);
90 return (ti->ti_flags & BSDISC);
98 return (ti->ti_flags & BSSAT);
103 struct targ_info *ti;
106 return (ti->ti_flags & BSSMIT);
110 bs_check_link(ti, cb)
111 struct targ_info *ti;
114 struct bsccb *nextcb;
116 return ((ti->ti_flags & BSLINK) &&
117 (nextcb = TAILQ_NEXT(cb, ccb_chain)) &&
118 (nextcb->bsccb_flags & BSLINK));
121 static BS_INLINE u_int8_t
123 struct targ_info *ti;
126 return ((bs_check_disc(ti) ? 0xc0 : 0x80) | ti->ti_lun);
129 static BS_INLINE void
130 bs_targ_flags(ti, cb)
131 struct targ_info *ti;
134 u_int cmf = (u_int) bshw_cmd[cb->cmd[0]];
136 cb->bsccb_flags |= ((cmf & (BSSAT | BSSMIT | BSLINK)) | BSDISC);
137 cb->bsccb_flags &= ti->ti_mflags;
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);
145 /**************************************************
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 *);
153 static BS_INLINE void
155 struct bs_softc *bsc;
158 TAILQ_INIT(&bsc->sc_sttab);
159 TAILQ_INIT(&bsc->sc_titab);
162 static BS_INLINE void
163 bs_hostque_head(bsc, ti)
164 struct bs_softc *bsc;
165 struct targ_info *ti;
168 if (ti->ti_flags & BSQUEUED) {
169 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
171 ti->ti_flags |= BSQUEUED;
173 TAILQ_INSERT_HEAD(&bsc->sc_sttab, ti, ti_wchain);
176 static BS_INLINE void
177 bs_hostque_tail(bsc, ti)
178 struct bs_softc *bsc;
179 struct targ_info *ti;
182 if (ti->ti_flags & BSQUEUED) {
183 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
185 ti->ti_flags |= BSQUEUED;
187 TAILQ_INSERT_TAIL(&bsc->sc_sttab, ti, ti_wchain);
190 static BS_INLINE void
191 bs_hostque_delete(bsc, ti)
192 struct bs_softc *bsc;
193 struct targ_info *ti;
196 if (ti->ti_flags & BSQUEUED)
198 ti->ti_flags &= ~BSQUEUED;
199 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
203 /*************************************************************
205 ************************************************************/
206 static BS_INLINE void bs_start_timeout (struct bs_softc *);
207 static BS_INLINE void bs_terminate_timeout (struct bs_softc *);
209 static BS_INLINE void
210 bs_start_timeout(bsc)
211 struct bs_softc *bsc;
214 if ((bsc->sc_flags & BSSTARTTIMEOUT) == 0)
216 bsc->sc_flags |= BSSTARTTIMEOUT;
217 callout_reset(&bsc->timeout_ch, BS_TIMEOUT_INTERVAL,
222 static BS_INLINE void
223 bs_terminate_timeout(bsc)
224 struct bs_softc *bsc;
227 if (bsc->sc_flags & BSSTARTTIMEOUT)
229 callout_stop(&bsc->timeout_ch);
230 bsc->sc_flags &= ~BSSTARTTIMEOUT;