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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* $OpenBSD: isp_inline.h,v 1.6 2001/02/12 23:45:33 mjacob Exp $ */
/*
* Qlogic Host Adapter Inline Functions
*
* Copyright (c) 1999, 2000 by Matthew Jacob
* Feral Software
* All rights reserved.
* mjacob@feral.com
*
* 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 immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
* 2. 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*
*/
#ifndef _ISP_INLINE_H
#define _ISP_INLINE_H
/*
* Handle Functions.
* For each outstanding command there will be a non-zero handle.
* There will be at most isp_maxcmds handles, and isp_lasthdls
* will be a seed for the last handled allocated.
*/
static INLINE int
isp_save_xs __P((struct ispsoftc *, XS_T *, u_int32_t *));
static INLINE XS_T *
isp_find_xs __P((struct ispsoftc *, u_int32_t));
static INLINE u_int32_t
isp_find_handle __P((struct ispsoftc *, XS_T *));
static INLINE int
isp_handle_index __P((u_int32_t));
static INLINE void
isp_destroy_handle __P((struct ispsoftc *, u_int32_t));
static INLINE void
isp_remove_handle __P((struct ispsoftc *, XS_T *));
static INLINE int
isp_save_xs(isp, xs, handlep)
struct ispsoftc *isp;
XS_T *xs;
u_int32_t *handlep;
{
int i, j;
for (j = isp->isp_lasthdls, i = 0; i < (int) isp->isp_maxcmds; i++) {
if (isp->isp_xflist[j] == NULL) {
break;
}
if (++j == isp->isp_maxcmds) {
j = 0;
}
}
if (i == isp->isp_maxcmds) {
return (-1);
}
isp->isp_xflist[j] = xs;
*handlep = j+1;
if (++j == isp->isp_maxcmds)
j = 0;
isp->isp_lasthdls = (u_int16_t)j;
return (0);
}
static INLINE XS_T *
isp_find_xs(isp, handle)
struct ispsoftc *isp;
u_int32_t handle;
{
if (handle < 1 || handle > (u_int32_t) isp->isp_maxcmds) {
return (NULL);
} else {
return (isp->isp_xflist[handle - 1]);
}
}
static INLINE u_int32_t
isp_find_handle(isp, xs)
struct ispsoftc *isp;
XS_T *xs;
{
int i;
if (xs != NULL) {
for (i = 0; i < isp->isp_maxcmds; i++) {
if (isp->isp_xflist[i] == xs) {
return ((u_int32_t) i+1);
}
}
}
return (0);
}
static INLINE int
isp_handle_index(handle)
u_int32_t handle;
{
return (handle-1);
}
static INLINE void
isp_destroy_handle(isp, handle)
struct ispsoftc *isp;
u_int32_t handle;
{
if (handle > 0 && handle <= (u_int32_t) isp->isp_maxcmds) {
isp->isp_xflist[isp_handle_index(handle)] = NULL;
}
}
static INLINE void
isp_remove_handle(isp, xs)
struct ispsoftc *isp;
XS_T *xs;
{
isp_destroy_handle(isp, isp_find_handle(isp, xs));
}
static INLINE int
isp_getrqentry __P((struct ispsoftc *, u_int16_t *, u_int16_t *, void **));
static INLINE int
isp_getrqentry(isp, iptrp, optrp, resultp)
struct ispsoftc *isp;
u_int16_t *iptrp;
u_int16_t *optrp;
void **resultp;
{
volatile u_int16_t iptr, optr;
optr = isp->isp_reqodx = ISP_READ(isp, OUTMAILBOX4);
iptr = isp->isp_reqidx;
*resultp = ISP_QUEUE_ENTRY(isp->isp_rquest, iptr);
iptr = ISP_NXT_QENTRY(iptr, RQUEST_QUEUE_LEN(isp));
if (iptr == optr) {
return (1);
}
if (optrp)
*optrp = optr;
if (iptrp)
*iptrp = iptr;
return (0);
}
static INLINE void
isp_print_qentry __P((struct ispsoftc *, char *, int, void *));
#define TBA (4 * (((QENTRY_LEN >> 2) * 3) + 1) + 1)
static INLINE void
isp_print_qentry(isp, msg, idx, arg)
struct ispsoftc *isp;
char *msg;
int idx;
void *arg;
{
char buf[TBA];
int amt, i, j;
u_int8_t *ptr = arg;
for (buf[0] = 0, amt = i = 0; i < 4; i++) {
buf[0] = 0;
for (j = 0; j < (QENTRY_LEN >> 2); j++) {
SNPRINTF(buf, TBA, "%s %02x", buf, ptr[amt++] & 0xff);
}
STRNCAT(buf, "\n", TBA);
}
isp_prt(isp, ISP_LOGALL, "%s index %d:%s", msg, idx, buf);
}
static INLINE void
isp_print_bytes __P((struct ispsoftc *, char *, int, void *));
static INLINE void
isp_print_bytes(isp, msg, amt, arg)
struct ispsoftc *isp;
char *msg;
int amt;
void *arg;
{
char buf[128];
u_int8_t *ptr = arg;
int off;
if (msg)
isp_prt(isp, ISP_LOGALL, "%s:", msg);
off = 0;
buf[0] = 0;
while (off < amt) {
int j, to;
to = off;
for (j = 0; j < 16; j++) {
SNPRINTF(buf, 128, "%s %02x", buf, ptr[off++] & 0xff);
if (off == amt)
break;
}
isp_prt(isp, ISP_LOGALL, "0x%08x:%s", to, buf);
buf[0] = 0;
}
}
/*
* Do the common path to try and ensure that link is up, we've scanned
* the fabric (if we're on a fabric), and that we've synchronized this
* all with our own database and done the appropriate logins.
*
* We repeatedly check for firmware state and loop state after each
* action because things may have changed while we were doing this.
* Any failure or change of state causes us to return a nonzero value.
*
* We honor HBA roles in that if we're not in Initiator mode, we don't
* attempt to sync up the database (that's for somebody else to do,
* if ever).
*
* We assume we enter here with any locks held.
*/
static INLINE int isp_fc_runstate __P((struct ispsoftc *, int));
static INLINE int
isp_fc_runstate(isp, tval)
struct ispsoftc *isp;
int tval;
{
fcparam *fcp;
int *tptr;
if (IS_SCSI(isp))
return (0);
tptr = tval? &tval : NULL;
if (isp_control(isp, ISPCTL_FCLINK_TEST, tptr) != 0) {
return (-1);
}
fcp = FCPARAM(isp);
if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate < LOOP_PDB_RCVD)
return (-1);
if (isp_control(isp, ISPCTL_SCAN_FABRIC, NULL) != 0) {
return (-1);
}
if (isp_control(isp, ISPCTL_SCAN_LOOP, NULL) != 0) {
return (-1);
}
if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
return (0);
}
if (isp_control(isp, ISPCTL_PDB_SYNC, NULL) != 0) {
return (-1);
}
if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate != LOOP_READY) {
return (-1);
}
return (0);
}
#endif /* _ISP_INLINE_H */
|