summaryrefslogtreecommitdiffstats
path: root/sys/i386/isa/bs/bsfunc.h
blob: 13c06868d04cb6259480945682c9e8f0d99a1fc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*	$NecBSD: bsfunc.h,v 1.1 1997/07/18 09:19:03 kmatsuda Exp $	*/
/*	$NetBSD$	*/
/*
 * [NetBSD for NEC PC98 series]
 *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
 *  All rights reserved.
 * 
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. The name of the author may not be used to endorse or promote products
 *     derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/*
 * Copyright (c) 1994, 1995, 1996 Naofumi HONDA.  All rights reserved.
 */

/**************************************************
 * FUNC
 **************************************************/
/* timeout */
void bstimeout __P((void *));

/* ctrl setup */
void bs_setup_ctrl __P((struct targ_info *, u_int, u_int));
struct targ_info *bs_init_target_info __P((struct bs_softc *, int));

/* msg op */
int bs_send_msg __P((struct targ_info *, u_int, struct msgbase *, int));
struct bsccb *bs_request_sense __P((struct targ_info *));

/* sync msg op */
int bs_start_syncmsg __P((struct targ_info *, struct bsccb *, int));
int bs_send_syncmsg __P((struct targ_info *));
int bs_analyze_syncmsg __P((struct targ_info *, struct bsccb *));

/* reset device */
void bs_scsibus_start __P((struct bs_softc *));
void bs_reset_nexus __P((struct bs_softc *));
struct bsccb *bs_force_abort __P((struct targ_info *));
void bs_reset_device __P((struct targ_info *));

/* ccb */
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));
struct bsccb *bs_make_msg_ccb __P((struct targ_info *, u_int, struct bsccb *, struct msgbase *, u_int));

/* misc funcs */
void bs_printf __P((struct targ_info *, char *, char *));
void bs_panic __P((struct bs_softc *, u_char *));

/* misc debug */
u_int bsr __P((u_int));
u_int bsw __P((u_int, int));
void bs_debug_print_all __P((struct bs_softc *));
void bs_debug_print __P((struct bs_softc *, struct targ_info *));

/**************************************************
 * TARG FLAGS
 *************************************************/
static BS_INLINE int bs_check_sat __P((struct targ_info *));
static BS_INLINE int bs_check_smit __P((struct targ_info *));
static BS_INLINE int bs_check_disc __P((struct targ_info *));
static BS_INLINE int bs_check_link __P((struct targ_info *, struct bsccb *));
static BS_INLINE u_int8_t bs_identify_msg __P((struct targ_info *));
static BS_INLINE void bs_targ_flags __P((struct targ_info *, struct bsccb *));

static BS_INLINE int
bs_check_disc(ti)
	struct targ_info *ti;
{

	return (ti->ti_flags & BSDISC);
}

static BS_INLINE int
bs_check_sat(ti)
	struct targ_info *ti;
{

	return (ti->ti_flags & BSSAT);
}

static BS_INLINE int
bs_check_smit(ti)
	struct targ_info *ti;
{

	return (ti->ti_flags & BSSMIT);
}

static BS_INLINE int
bs_check_link(ti, cb)
	struct targ_info *ti;
	struct bsccb *cb;
{
	struct bsccb *nextcb;

	return ((ti->ti_flags & BSLINK) &&
		(nextcb = cb->ccb_chain.tqe_next) &&
		(nextcb->bsccb_flags & BSLINK));
}

static BS_INLINE u_int8_t
bs_identify_msg(ti)
	struct targ_info *ti;
{

	return ((bs_check_disc(ti) ? 0xc0 : 0x80) | ti->ti_lun);
}

static BS_INLINE void
bs_targ_flags(ti, cb)
	struct targ_info *ti;
	struct bsccb *cb;
{
	u_int cmf = (u_int) bshw_cmd[cb->cmd[0]];

	cb->bsccb_flags |= ((cmf & (BSSAT | BSSMIT | BSLINK)) | BSDISC);
	cb->bsccb_flags &= ti->ti_mflags;

	if (cb->datalen < DEV_BSIZE)
		cb->bsccb_flags &= ~BSSMIT;
	if (cb->bsccb_flags & BSFORCEIOPOLL)
		cb->bsccb_flags &= ~(BSLINK | BSSMIT | BSSAT | BSDISC);
}

/**************************************************
 * QUEUE OP
 **************************************************/
static BS_INLINE void bs_hostque_init __P((struct bs_softc *));
static BS_INLINE void bs_hostque_head __P((struct bs_softc *, struct targ_info *));
static BS_INLINE void bs_hostque_tail __P((struct bs_softc *, struct targ_info *));
static BS_INLINE void bs_hostque_delete __P((struct bs_softc *, struct targ_info *));

static BS_INLINE void
bs_hostque_init(bsc)
	struct bs_softc *bsc;
{

	TAILQ_INIT(&bsc->sc_sttab);
	TAILQ_INIT(&bsc->sc_titab);
}

static BS_INLINE void
bs_hostque_head(bsc, ti)
	struct bs_softc *bsc;
	struct targ_info *ti;
{

	if (ti->ti_flags & BSQUEUED) {
		TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
	} else {
		ti->ti_flags |= BSQUEUED;
	}
	TAILQ_INSERT_HEAD(&bsc->sc_sttab, ti, ti_wchain);
}

static BS_INLINE void
bs_hostque_tail(bsc, ti)
	struct bs_softc *bsc;
	struct targ_info *ti;
{

	if (ti->ti_flags & BSQUEUED) {
		TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
	} else {
		ti->ti_flags |= BSQUEUED;
	}
	TAILQ_INSERT_TAIL(&bsc->sc_sttab, ti, ti_wchain);
}

static BS_INLINE void
bs_hostque_delete(bsc, ti)
	struct bs_softc *bsc;
	struct targ_info *ti;
{

	if (ti->ti_flags & BSQUEUED)
	{
		ti->ti_flags &= ~BSQUEUED;
		TAILQ_REMOVE(&bsc->sc_sttab, ti, ti_wchain);
	}
}

/*************************************************************
 * TIMEOUT
 ************************************************************/
static BS_INLINE void bs_start_timeout __P((struct bs_softc *));
static BS_INLINE void bs_terminate_timeout __P((struct bs_softc *));

static BS_INLINE void
bs_start_timeout(bsc)
	struct bs_softc *bsc;
{

	if ((bsc->sc_flags & BSSTARTTIMEOUT) == 0)
	{
		bsc->sc_flags |= BSSTARTTIMEOUT;
#ifdef __FreeBSD__
		bsc->timeout_ch =
#endif
		timeout(bstimeout, bsc, BS_TIMEOUT_INTERVAL);
	}
}

static BS_INLINE void
bs_terminate_timeout(bsc)
	struct bs_softc *bsc;
{

	if (bsc->sc_flags & BSSTARTTIMEOUT)
	{
#ifdef __FreeBSD__
		untimeout(bstimeout, bsc,
				  bsc->timeout_ch);
#else
		untimeout(bstimeout, bsc);
#endif
		bsc->sc_flags &= ~BSSTARTTIMEOUT;
	}
}
OpenPOWER on IntegriCloud