1 /* $NecBSD: bsfunc.h,v 1.1 1997/07/18 09:19:03 kmatsuda Exp $ */
4 * [NetBSD for NEC PC98 series]
5 * Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
32 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA. All rights reserved.
35 /**************************************************
37 **************************************************/
39 void bstimeout __P((void *));
42 void bs_setup_ctrl __P((struct targ_info *, u_int, u_int));
43 struct targ_info *bs_init_target_info __P((struct bs_softc *, int));
46 int bs_send_msg __P((struct targ_info *, u_int, struct msgbase *, int));
47 struct bsccb *bs_request_sense __P((struct targ_info *));
50 int bs_start_syncmsg __P((struct targ_info *, struct bsccb *, int));
51 int bs_send_syncmsg __P((struct targ_info *));
52 int bs_analyze_syncmsg __P((struct targ_info *, struct bsccb *));
55 void bs_scsibus_start __P((struct bs_softc *));
56 void bs_reset_nexus __P((struct bs_softc *));
57 struct bsccb *bs_force_abort __P((struct targ_info *));
58 void bs_reset_device __P((struct targ_info *));
61 struct bsccb *bs_make_internal_ccb __P((struct targ_info *, u_int, u_int8_t *, u_int, u_int8_t *, u_int, u_int, int));
62 struct bsccb *bs_make_msg_ccb __P((struct targ_info *, u_int, struct bsccb *, struct msgbase *, u_int));
65 void bs_printf __P((struct targ_info *, char *, char *));
66 void bs_panic __P((struct bs_softc *, u_char *));
69 u_int bsr __P((u_int));
70 u_int bsw __P((u_int, int));
71 void bs_debug_print_all __P((struct bs_softc *));
72 void bs_debug_print __P((struct bs_softc *, struct targ_info *));
74 /**************************************************
76 *************************************************/
77 static BS_INLINE int bs_check_sat __P((struct targ_info *));
78 static BS_INLINE int bs_check_smit __P((struct targ_info *));
79 static BS_INLINE int bs_check_disc __P((struct targ_info *));
80 static BS_INLINE int bs_check_link __P((struct targ_info *, struct bsccb *));
81 static BS_INLINE u_int8_t bs_identify_msg __P((struct targ_info *));
82 static BS_INLINE void bs_targ_flags __P((struct targ_info *, struct bsccb *));
89 return (ti->ti_flags & BSDISC);
97 return (ti->ti_flags & BSSAT);
102 struct targ_info *ti;
105 return (ti->ti_flags & BSSMIT);
109 bs_check_link(ti, cb)
110 struct targ_info *ti;
113 struct bsccb *nextcb;
115 return ((ti->ti_flags & BSLINK) &&
116 (nextcb = cb->ccb_chain.tqe_next) &&
117 (nextcb->bsccb_flags & BSLINK));
120 static BS_INLINE u_int8_t
122 struct targ_info *ti;
125 return ((bs_check_disc(ti) ? 0xc0 : 0x80) | ti->ti_lun);
128 static BS_INLINE void
129 bs_targ_flags(ti, cb)
130 struct targ_info *ti;
133 u_int cmf = (u_int) bshw_cmd[cb->cmd[0]];
135 cb->bsccb_flags |= ((cmf & (BSSAT | BSSMIT | BSLINK)) | BSDISC);
136 cb->bsccb_flags &= ti->ti_mflags;
138 if (cb->datalen < DEV_BSIZE)
139 cb->bsccb_flags &= ~BSSMIT;
140 if (cb->bsccb_flags & BSFORCEIOPOLL)
141 cb->bsccb_flags &= ~(BSLINK | BSSMIT | BSSAT | BSDISC);
144 /**************************************************
146 **************************************************/
147 static BS_INLINE void bs_hostque_init __P((struct bs_softc *));
148 static BS_INLINE void bs_hostque_head __P((struct bs_softc *, struct targ_info *));
149 static BS_INLINE void bs_hostque_tail __P((struct bs_softc *, struct targ_info *));
150 static BS_INLINE void bs_hostque_delete __P((struct bs_softc *, struct targ_info *));
152 static BS_INLINE void
154 struct bs_softc *bsc;
157 TAILQ_INIT(&bsc->sc_sttab);
158 TAILQ_INIT(&bsc->sc_titab);
161 static BS_INLINE void
162 bs_hostque_head(bsc, ti)
163 struct bs_softc *bsc;
164 struct targ_info *ti;
167 if (ti->ti_flags & BSQUEUED) {
168 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
170 ti->ti_flags |= BSQUEUED;
172 TAILQ_INSERT_HEAD(&bsc->sc_sttab, ti, ti_wchain);
175 static BS_INLINE void
176 bs_hostque_tail(bsc, ti)
177 struct bs_softc *bsc;
178 struct targ_info *ti;
181 if (ti->ti_flags & BSQUEUED) {
182 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
184 ti->ti_flags |= BSQUEUED;
186 TAILQ_INSERT_TAIL(&bsc->sc_sttab, ti, ti_wchain);
189 static BS_INLINE void
190 bs_hostque_delete(bsc, ti)
191 struct bs_softc *bsc;
192 struct targ_info *ti;
195 if (ti->ti_flags & BSQUEUED)
197 ti->ti_flags &= ~BSQUEUED;
198 TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
202 /*************************************************************
204 ************************************************************/
205 static BS_INLINE void bs_start_timeout __P((struct bs_softc *));
206 static BS_INLINE void bs_terminate_timeout __P((struct bs_softc *));
208 static BS_INLINE void
209 bs_start_timeout(bsc)
210 struct bs_softc *bsc;
213 if ((bsc->sc_flags & BSSTARTTIMEOUT) == 0)
215 bsc->sc_flags |= BSSTARTTIMEOUT;
219 timeout(bstimeout, bsc, BS_TIMEOUT_INTERVAL);
223 static BS_INLINE void
224 bs_terminate_timeout(bsc)
225 struct bs_softc *bsc;
228 if (bsc->sc_flags & BSSTARTTIMEOUT)
231 untimeout(bstimeout, bsc,
234 untimeout(bstimeout, bsc);
236 bsc->sc_flags &= ~BSSTARTTIMEOUT;