isp_target.c revision 1.7 1 1.7 mjacob /* $NetBSD: isp_target.c,v 1.7 2000/08/01 23:55:11 mjacob Exp $ */
2 1.1 mjacob /*
3 1.1 mjacob * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
4 1.1 mjacob *
5 1.1 mjacob * Copyright (c) 1999 by Matthew Jacob
6 1.1 mjacob * All rights reserved.
7 1.1 mjacob * mjacob (at) feral.com
8 1.1 mjacob *
9 1.1 mjacob * Redistribution and use in source and binary forms, with or without
10 1.1 mjacob * modification, are permitted provided that the following conditions
11 1.1 mjacob * are met:
12 1.1 mjacob * 1. Redistributions of source code must retain the above copyright
13 1.1 mjacob * notice immediately at the beginning of the file, without modification,
14 1.1 mjacob * this list of conditions, and the following disclaimer.
15 1.1 mjacob * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mjacob * notice, this list of conditions and the following disclaimer in the
17 1.1 mjacob * documentation and/or other materials provided with the distribution.
18 1.1 mjacob * 3. The name of the author may not be used to endorse or promote products
19 1.1 mjacob * derived from this software without specific prior written permission.
20 1.1 mjacob *
21 1.1 mjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 1.1 mjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 mjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 mjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
25 1.1 mjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 mjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 mjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 mjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 mjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 mjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 mjacob * SUCH DAMAGE.
32 1.1 mjacob */
33 1.1 mjacob
34 1.1 mjacob /*
35 1.1 mjacob * Include header file appropriate for platform we're building on.
36 1.1 mjacob */
37 1.1 mjacob
38 1.1 mjacob #ifdef __NetBSD__
39 1.1 mjacob #include <dev/ic/isp_netbsd.h>
40 1.1 mjacob #endif
41 1.1 mjacob #ifdef __FreeBSD__
42 1.1 mjacob #include <dev/isp/isp_freebsd.h>
43 1.1 mjacob #endif
44 1.1 mjacob #ifdef __OpenBSD__
45 1.1 mjacob #include <dev/ic/isp_openbsd.h>
46 1.1 mjacob #endif
47 1.1 mjacob #ifdef __linux__
48 1.1 mjacob #include "isp_linux.h"
49 1.1 mjacob #endif
50 1.1 mjacob
51 1.1 mjacob #ifdef ISP_TARGET_MODE
52 1.7 mjacob static char *atiocope =
53 1.7 mjacob "ATIO returned for lun %d because it was in the middle of Bus Device Reset";
54 1.7 mjacob static char *atior =
55 1.7 mjacob "ATIO returned for lun %d from initiator %d because a Bus Reset occurred";
56 1.1 mjacob
57 1.1 mjacob static void isp_got_msg __P((struct ispsoftc *, int, in_entry_t *));
58 1.1 mjacob static void isp_got_msg_fc __P((struct ispsoftc *, int, in_fcentry_t *));
59 1.1 mjacob static void isp_notify_ack __P((struct ispsoftc *, void *));
60 1.1 mjacob static void isp_handle_atio(struct ispsoftc *, at_entry_t *);
61 1.1 mjacob static void isp_handle_atio2(struct ispsoftc *, at2_entry_t *);
62 1.1 mjacob static void isp_handle_ctio(struct ispsoftc *, ct_entry_t *);
63 1.1 mjacob static void isp_handle_ctio2(struct ispsoftc *, ct2_entry_t *);
64 1.1 mjacob
65 1.1 mjacob /*
66 1.1 mjacob * The Qlogic driver gets an interrupt to look at response queue entries.
67 1.1 mjacob * Some of these are status completions for initiatior mode commands, but
68 1.1 mjacob * if target mode is enabled, we get a whole wad of response queue entries
69 1.1 mjacob * to be handled here.
70 1.1 mjacob *
71 1.1 mjacob * Basically the split into 3 main groups: Lun Enable/Modification responses,
72 1.1 mjacob * SCSI Command processing, and Immediate Notification events.
73 1.1 mjacob *
74 1.1 mjacob * You start by writing a request queue entry to enable target mode (and
75 1.1 mjacob * establish some resource limitations which you can modify later).
76 1.1 mjacob * The f/w responds with a LUN ENABLE or LUN MODIFY response with
77 1.1 mjacob * the status of this action. If the enable was successful, you can expect...
78 1.1 mjacob *
79 1.1 mjacob * Response queue entries with SCSI commands encapsulate show up in an ATIO
80 1.1 mjacob * (Accept Target IO) type- sometimes with enough info to stop the command at
81 1.1 mjacob * this level. Ultimately the driver has to feed back to the f/w's request
82 1.1 mjacob * queue a sequence of CTIOs (continue target I/O) that describe data to
83 1.1 mjacob * be moved and/or status to be sent) and finally finishing with sending
84 1.1 mjacob * to the f/w's response queue an ATIO which then completes the handshake
85 1.1 mjacob * with the f/w for that command. There's a lot of variations on this theme,
86 1.1 mjacob * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
87 1.1 mjacob * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
88 1.1 mjacob * gist of it.
89 1.1 mjacob *
90 1.1 mjacob * The third group that can show up in the response queue are Immediate
91 1.1 mjacob * Notification events. These include things like notifications of SCSI bus
92 1.1 mjacob * resets, or Bus Device Reset messages or other messages received. This
93 1.1 mjacob * a classic oddbins area. It can get a little wierd because you then turn
94 1.1 mjacob * around and acknowledge the Immediate Notify by writing an entry onto the
95 1.1 mjacob * request queue and then the f/w turns around and gives you an acknowledgement
96 1.1 mjacob * to *your* acknowledgement on the response queue (the idea being to let
97 1.1 mjacob * the f/w tell you when the event is *really* over I guess).
98 1.1 mjacob *
99 1.1 mjacob */
100 1.1 mjacob
101 1.1 mjacob
102 1.1 mjacob /*
103 1.1 mjacob * A new response queue entry has arrived. The interrupt service code
104 1.1 mjacob * has already swizzled it into the platform dependent from canonical form.
105 1.1 mjacob *
106 1.1 mjacob * Because of the way this driver is designed, unfortunately most of the
107 1.1 mjacob * actual synchronization work has to be done in the platform specific
108 1.1 mjacob * code- we have no synchroniation primitives in the common code.
109 1.1 mjacob */
110 1.1 mjacob
111 1.1 mjacob int
112 1.1 mjacob isp_target_notify(isp, vptr, optrp)
113 1.1 mjacob struct ispsoftc *isp;
114 1.1 mjacob void *vptr;
115 1.1 mjacob u_int16_t *optrp;
116 1.1 mjacob {
117 1.1 mjacob u_int16_t status, seqid;
118 1.1 mjacob union {
119 1.1 mjacob at_entry_t *atiop;
120 1.1 mjacob at2_entry_t *at2iop;
121 1.1 mjacob ct_entry_t *ctiop;
122 1.1 mjacob ct2_entry_t *ct2iop;
123 1.1 mjacob lun_entry_t *lunenp;
124 1.1 mjacob in_entry_t *inotp;
125 1.1 mjacob in_fcentry_t *inot_fcp;
126 1.1 mjacob na_entry_t *nackp;
127 1.1 mjacob na_fcentry_t *nack_fcp;
128 1.1 mjacob isphdr_t *hp;
129 1.1 mjacob void * *vp;
130 1.1 mjacob #define atiop unp.atiop
131 1.1 mjacob #define at2iop unp.at2iop
132 1.1 mjacob #define ctiop unp.ctiop
133 1.1 mjacob #define ct2iop unp.ct2iop
134 1.1 mjacob #define lunenp unp.lunenp
135 1.1 mjacob #define inotp unp.inotp
136 1.1 mjacob #define inot_fcp unp.inot_fcp
137 1.1 mjacob #define nackp unp.nackp
138 1.1 mjacob #define nack_fcp unp.nack_fcp
139 1.1 mjacob #define hdrp unp.hp
140 1.1 mjacob } unp;
141 1.1 mjacob int bus, rval = 0;
142 1.1 mjacob
143 1.1 mjacob unp.vp = vptr;
144 1.1 mjacob
145 1.1 mjacob ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
146 1.1 mjacob
147 1.1 mjacob switch(hdrp->rqs_entry_type) {
148 1.1 mjacob case RQSTYPE_ATIO:
149 1.1 mjacob isp_handle_atio(isp, atiop);
150 1.1 mjacob break;
151 1.1 mjacob case RQSTYPE_CTIO:
152 1.1 mjacob isp_handle_ctio(isp, ctiop);
153 1.1 mjacob break;
154 1.1 mjacob case RQSTYPE_ATIO2:
155 1.1 mjacob isp_handle_atio2(isp, at2iop);
156 1.1 mjacob break;
157 1.1 mjacob case RQSTYPE_CTIO2:
158 1.1 mjacob isp_handle_ctio2(isp, ct2iop);
159 1.1 mjacob break;
160 1.1 mjacob case RQSTYPE_ENABLE_LUN:
161 1.1 mjacob case RQSTYPE_MODIFY_LUN:
162 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, vptr);
163 1.1 mjacob break;
164 1.1 mjacob
165 1.1 mjacob case RQSTYPE_NOTIFY:
166 1.1 mjacob /*
167 1.1 mjacob * Either the ISP received a SCSI message it can't
168 1.1 mjacob * handle, or it's returning an Immed. Notify entry
169 1.1 mjacob * we sent. We can send Immed. Notify entries to
170 1.1 mjacob * increment the firmware's resource count for them
171 1.1 mjacob * (we set this initially in the Enable Lun entry).
172 1.1 mjacob */
173 1.3 mjacob bus = 0;
174 1.1 mjacob if (IS_FC(isp)) {
175 1.1 mjacob status = inot_fcp->in_status;
176 1.1 mjacob seqid = inot_fcp->in_seqid;
177 1.1 mjacob } else {
178 1.1 mjacob status = inotp->in_status & 0xff;
179 1.1 mjacob seqid = inotp->in_seqid;
180 1.3 mjacob if (IS_DUALBUS(isp)) {
181 1.3 mjacob bus = (inotp->in_iid & 0x80) >> 7;
182 1.3 mjacob inotp->in_iid &= ~0x80;
183 1.3 mjacob }
184 1.1 mjacob }
185 1.7 mjacob isp_prt(isp, ISP_LOGTDEBUG1,
186 1.7 mjacob "Immediate Notify, status=0x%x seqid=0x%x", status, seqid);
187 1.1 mjacob switch (status) {
188 1.1 mjacob case IN_RESET:
189 1.1 mjacob (void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
190 1.1 mjacob break;
191 1.1 mjacob case IN_MSG_RECEIVED:
192 1.1 mjacob case IN_IDE_RECEIVED:
193 1.1 mjacob if (IS_FC(isp)) {
194 1.1 mjacob isp_got_msg_fc(isp, bus, vptr);
195 1.1 mjacob } else {
196 1.1 mjacob isp_got_msg(isp, bus, vptr);
197 1.1 mjacob }
198 1.1 mjacob break;
199 1.1 mjacob case IN_RSRC_UNAVAIL:
200 1.7 mjacob isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
201 1.1 mjacob break;
202 1.1 mjacob case IN_ABORT_TASK:
203 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
204 1.7 mjacob "Abort Task for Initiator %d RX_ID 0x%x",
205 1.7 mjacob inot_fcp->in_iid, seqid);
206 1.1 mjacob break;
207 1.1 mjacob case IN_PORT_LOGOUT:
208 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
209 1.7 mjacob "Port Logout for Initiator %d RX_ID 0x%x",
210 1.7 mjacob inot_fcp->in_iid, seqid);
211 1.1 mjacob break;
212 1.1 mjacob case IN_PORT_CHANGED:
213 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
214 1.7 mjacob "Port Changed for Initiator %d RX_ID 0x%x",
215 1.7 mjacob inot_fcp->in_iid, seqid);
216 1.1 mjacob break;
217 1.1 mjacob case IN_GLOBAL_LOGO:
218 1.7 mjacob isp_prt(isp, ISP_LOGWARN, "All ports logged out");
219 1.1 mjacob break;
220 1.1 mjacob default:
221 1.7 mjacob isp_prt(isp, ISP_LOGERR,
222 1.7 mjacob "bad status (0x%x) in isp_target_notify", status);
223 1.1 mjacob break;
224 1.1 mjacob }
225 1.1 mjacob isp_notify_ack(isp, vptr);
226 1.1 mjacob break;
227 1.1 mjacob
228 1.1 mjacob case RQSTYPE_NOTIFY_ACK:
229 1.1 mjacob /*
230 1.1 mjacob * The ISP is acknowledging our acknowledgement of an
231 1.1 mjacob * Immediate Notify entry for some asynchronous event.
232 1.1 mjacob */
233 1.1 mjacob if (IS_FC(isp)) {
234 1.7 mjacob isp_prt(isp, ISP_LOGTDEBUG1,
235 1.7 mjacob "Notify Ack status=0x%x seqid 0x%x",
236 1.7 mjacob nack_fcp->na_status, nack_fcp->na_seqid);
237 1.1 mjacob } else {
238 1.7 mjacob isp_prt(isp, ISP_LOGTDEBUG1,
239 1.7 mjacob "Notify Ack event 0x%x status=0x%x seqid 0x%x",
240 1.7 mjacob nackp->na_event, nackp->na_status, nackp->na_seqid);
241 1.1 mjacob }
242 1.1 mjacob break;
243 1.1 mjacob default:
244 1.7 mjacob isp_prt(isp, ISP_LOGERR,
245 1.7 mjacob "Unknown entry type 0x%x in isp_target_notify",
246 1.7 mjacob hdrp->rqs_entry_type);
247 1.1 mjacob rval = -1;
248 1.1 mjacob break;
249 1.1 mjacob }
250 1.1 mjacob #undef atiop
251 1.1 mjacob #undef at2iop
252 1.1 mjacob #undef ctiop
253 1.1 mjacob #undef ct2iop
254 1.1 mjacob #undef lunenp
255 1.1 mjacob #undef inotp
256 1.1 mjacob #undef inot_fcp
257 1.1 mjacob #undef nackp
258 1.1 mjacob #undef nack_fcp
259 1.1 mjacob #undef hdrp
260 1.1 mjacob return (rval);
261 1.1 mjacob }
262 1.1 mjacob
263 1.1 mjacob
264 1.1 mjacob /*
265 1.1 mjacob * Toggle (on/off) target mode for bus/target/lun
266 1.1 mjacob *
267 1.1 mjacob * The caller has checked for overlap and legality.
268 1.1 mjacob *
269 1.1 mjacob * Note that not all of bus, target or lun can be paid attention to.
270 1.1 mjacob * Note also that this action will not be complete until the f/w writes
271 1.1 mjacob * response entry. The caller is responsible for synchronizing this.
272 1.1 mjacob */
273 1.1 mjacob int
274 1.1 mjacob isp_lun_cmd(isp, cmd, bus, tgt, lun, opaque)
275 1.1 mjacob struct ispsoftc *isp;
276 1.1 mjacob int cmd;
277 1.1 mjacob int bus;
278 1.1 mjacob int tgt;
279 1.1 mjacob int lun;
280 1.1 mjacob u_int32_t opaque;
281 1.1 mjacob {
282 1.1 mjacob lun_entry_t el;
283 1.1 mjacob u_int16_t iptr, optr;
284 1.1 mjacob void *outp;
285 1.1 mjacob
286 1.1 mjacob
287 1.1 mjacob MEMZERO(&el, sizeof (el));
288 1.3 mjacob if (IS_DUALBUS(isp)) {
289 1.3 mjacob el.le_rsvd = (bus & 0x1) << 7;
290 1.3 mjacob }
291 1.1 mjacob el.le_cmd_count = DFLT_CMD_CNT;
292 1.1 mjacob el.le_in_count = DFLT_INOTIFY;
293 1.1 mjacob if (cmd == RQSTYPE_ENABLE_LUN) {
294 1.1 mjacob if (IS_SCSI(isp)) {
295 1.5 mjacob el.le_flags = LUN_TQAE|LUN_DISAD;
296 1.1 mjacob el.le_cdb6len = 12;
297 1.1 mjacob el.le_cdb7len = 12;
298 1.1 mjacob }
299 1.1 mjacob } else if (cmd == -RQSTYPE_ENABLE_LUN) {
300 1.1 mjacob cmd = RQSTYPE_ENABLE_LUN;
301 1.1 mjacob el.le_cmd_count = 0;
302 1.1 mjacob el.le_in_count = 0;
303 1.1 mjacob } else if (cmd == -RQSTYPE_MODIFY_LUN) {
304 1.1 mjacob cmd = RQSTYPE_MODIFY_LUN;
305 1.1 mjacob el.le_ops = LUN_CCDECR | LUN_INDECR;
306 1.1 mjacob } else {
307 1.1 mjacob el.le_ops = LUN_CCINCR | LUN_ININCR;
308 1.1 mjacob }
309 1.1 mjacob el.le_header.rqs_entry_type = cmd;
310 1.1 mjacob el.le_header.rqs_entry_count = 1;
311 1.1 mjacob el.le_reserved = opaque;
312 1.1 mjacob if (IS_SCSI(isp)) {
313 1.1 mjacob el.le_tgt = tgt;
314 1.1 mjacob el.le_lun = lun;
315 1.5 mjacob } else if (isp->isp_maxluns <= 16) {
316 1.1 mjacob el.le_lun = lun;
317 1.1 mjacob }
318 1.1 mjacob
319 1.1 mjacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
320 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
321 1.7 mjacob "Request Queue Overflow in isp_lun_cmd");
322 1.1 mjacob return (-1);
323 1.1 mjacob }
324 1.1 mjacob ISP_SWIZ_ENABLE_LUN(isp, outp, &el);
325 1.1 mjacob ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
326 1.1 mjacob ISP_ADD_REQUEST(isp, iptr);
327 1.1 mjacob return (0);
328 1.1 mjacob }
329 1.1 mjacob
330 1.1 mjacob
331 1.1 mjacob int
332 1.1 mjacob isp_target_put_entry(isp, ap)
333 1.1 mjacob struct ispsoftc *isp;
334 1.1 mjacob void *ap;
335 1.1 mjacob {
336 1.1 mjacob void *outp;
337 1.1 mjacob u_int16_t iptr, optr;
338 1.1 mjacob u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
339 1.1 mjacob
340 1.1 mjacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
341 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
342 1.7 mjacob "Request Queue Overflow in isp_target_put_entry");
343 1.1 mjacob return (-1);
344 1.1 mjacob }
345 1.1 mjacob switch (etype) {
346 1.1 mjacob case RQSTYPE_ATIO:
347 1.1 mjacob ISP_SWIZ_ATIO(isp, outp, ap);
348 1.1 mjacob break;
349 1.1 mjacob case RQSTYPE_ATIO2:
350 1.1 mjacob ISP_SWIZ_ATIO2(isp, outp, ap);
351 1.1 mjacob break;
352 1.1 mjacob case RQSTYPE_CTIO:
353 1.1 mjacob ISP_SWIZ_CTIO(isp, outp, ap);
354 1.1 mjacob break;
355 1.1 mjacob case RQSTYPE_CTIO2:
356 1.1 mjacob ISP_SWIZ_CTIO2(isp, outp, ap);
357 1.1 mjacob break;
358 1.1 mjacob default:
359 1.7 mjacob isp_prt(isp, ISP_LOGERR,
360 1.7 mjacob "Unknown type 0x%x in isp_put_entry", etype);
361 1.1 mjacob return (-1);
362 1.1 mjacob }
363 1.1 mjacob
364 1.1 mjacob ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);;
365 1.1 mjacob
366 1.1 mjacob ISP_ADD_REQUEST(isp, iptr);
367 1.1 mjacob return (0);
368 1.1 mjacob }
369 1.1 mjacob
370 1.1 mjacob int
371 1.1 mjacob isp_target_put_atio(isp, iid, tgt, lun, ttype, tval)
372 1.1 mjacob struct ispsoftc *isp;
373 1.1 mjacob int iid;
374 1.1 mjacob int tgt;
375 1.1 mjacob int lun;
376 1.1 mjacob int ttype;
377 1.1 mjacob int tval;
378 1.1 mjacob {
379 1.1 mjacob union {
380 1.1 mjacob at_entry_t _atio;
381 1.1 mjacob at2_entry_t _atio2;
382 1.1 mjacob } atun;
383 1.1 mjacob
384 1.1 mjacob MEMZERO(&atun, sizeof atun);
385 1.1 mjacob if (IS_FC(isp)) {
386 1.1 mjacob atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
387 1.1 mjacob atun._atio2.at_header.rqs_entry_count = 1;
388 1.5 mjacob if (isp->isp_maxluns > 16) {
389 1.5 mjacob atun._atio2.at_scclun = (u_int16_t) lun;
390 1.5 mjacob } else {
391 1.5 mjacob atun._atio2.at_lun = (u_int8_t) lun;
392 1.5 mjacob }
393 1.1 mjacob atun._atio2.at_status = CT_OK;
394 1.1 mjacob } else {
395 1.1 mjacob atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
396 1.1 mjacob atun._atio.at_header.rqs_entry_count = 1;
397 1.1 mjacob atun._atio.at_iid = iid;
398 1.1 mjacob atun._atio.at_tgt = tgt;
399 1.1 mjacob atun._atio.at_lun = lun;
400 1.1 mjacob atun._atio.at_tag_type = ttype;
401 1.1 mjacob atun._atio.at_tag_val = tval;
402 1.1 mjacob atun._atio.at_status = CT_OK;
403 1.1 mjacob }
404 1.1 mjacob return (isp_target_put_entry(isp, &atun));
405 1.1 mjacob }
406 1.1 mjacob
407 1.1 mjacob /*
408 1.1 mjacob * Command completion- both for handling cases of no resources or
409 1.1 mjacob * no blackhole driver, or other cases where we have to, inline,
410 1.1 mjacob * finish the command sanely, or for normal command completion.
411 1.1 mjacob *
412 1.1 mjacob * The 'completion' code value has the scsi status byte in the low 8 bits.
413 1.1 mjacob * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
414 1.1 mjacob * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
415 1.1 mjacob * values.
416 1.1 mjacob *
417 1.1 mjacob * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
418 1.1 mjacob * NB: inline SCSI sense reporting.
419 1.1 mjacob *
420 1.1 mjacob * For both parallel && fibre channel, we use the feature that does
421 1.1 mjacob * an automatic resource autoreplenish so we don't have then later do
422 1.1 mjacob * put of an atio to replenish the f/w's resource count.
423 1.1 mjacob */
424 1.1 mjacob
425 1.1 mjacob int
426 1.1 mjacob isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int32_t hdl)
427 1.1 mjacob {
428 1.1 mjacob int sts;
429 1.1 mjacob union {
430 1.1 mjacob ct_entry_t _ctio;
431 1.1 mjacob ct2_entry_t _ctio2;
432 1.1 mjacob } un;
433 1.1 mjacob
434 1.1 mjacob MEMZERO(&un, sizeof un);
435 1.1 mjacob sts = code & 0xff;
436 1.1 mjacob
437 1.1 mjacob if (IS_FC(isp)) {
438 1.1 mjacob at2_entry_t *aep = arg;
439 1.1 mjacob ct2_entry_t *cto = &un._ctio2;
440 1.1 mjacob
441 1.1 mjacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
442 1.1 mjacob cto->ct_header.rqs_entry_count = 1;
443 1.1 mjacob cto->ct_iid = aep->at_iid;
444 1.5 mjacob if (isp->isp_maxluns <= 16) {
445 1.5 mjacob cto->ct_lun = aep->at_lun;
446 1.5 mjacob }
447 1.1 mjacob cto->ct_rxid = aep->at_rxid;
448 1.2 mjacob cto->rsp.m1.ct_scsi_status = sts & 0xff;
449 1.1 mjacob cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
450 1.1 mjacob if (hdl == 0) {
451 1.1 mjacob cto->ct_flags |= CT2_CCINCR;
452 1.1 mjacob }
453 1.1 mjacob if (aep->at_datalen) {
454 1.1 mjacob cto->ct_resid = aep->at_datalen;
455 1.1 mjacob cto->ct_flags |= CT2_DATA_UNDER;
456 1.1 mjacob }
457 1.2 mjacob if ((sts & 0xff) == SCSI_CHECK && (sts & ECMD_SVALID)) {
458 1.1 mjacob cto->rsp.m1.ct_resp[0] = 0xf0;
459 1.1 mjacob cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
460 1.1 mjacob cto->rsp.m1.ct_resp[7] = 8;
461 1.1 mjacob cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
462 1.1 mjacob cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
463 1.1 mjacob cto->rsp.m1.ct_senselen = 16;
464 1.1 mjacob cto->ct_flags |= CT2_SNSLEN_VALID;
465 1.1 mjacob }
466 1.1 mjacob cto->ct_reserved = hdl;
467 1.1 mjacob } else {
468 1.1 mjacob at_entry_t *aep = arg;
469 1.1 mjacob ct_entry_t *cto = &un._ctio;
470 1.1 mjacob
471 1.1 mjacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
472 1.1 mjacob cto->ct_header.rqs_entry_count = 1;
473 1.1 mjacob cto->ct_iid = aep->at_iid;
474 1.1 mjacob cto->ct_tgt = aep->at_tgt;
475 1.1 mjacob cto->ct_lun = aep->at_lun;
476 1.1 mjacob cto->ct_tag_type = aep->at_tag_type;
477 1.1 mjacob cto->ct_tag_val = aep->at_tag_val;
478 1.1 mjacob cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
479 1.1 mjacob if (hdl == 0) {
480 1.1 mjacob cto->ct_flags |= CT_CCINCR;
481 1.1 mjacob }
482 1.1 mjacob cto->ct_scsi_status = sts;
483 1.1 mjacob cto->ct_reserved = hdl;
484 1.1 mjacob }
485 1.1 mjacob return (isp_target_put_entry(isp, &un));
486 1.1 mjacob }
487 1.1 mjacob
488 1.1 mjacob void
489 1.1 mjacob isp_target_async(isp, bus, event)
490 1.1 mjacob struct ispsoftc *isp;
491 1.1 mjacob int bus;
492 1.1 mjacob int event;
493 1.1 mjacob {
494 1.1 mjacob tmd_event_t evt;
495 1.1 mjacob tmd_msg_t msg;
496 1.1 mjacob
497 1.1 mjacob switch (event) {
498 1.1 mjacob /*
499 1.1 mjacob * These three we handle here to propagate an effective bus reset
500 1.1 mjacob * upstream, but these do not require any immediate notify actions
501 1.1 mjacob * so we return when done.
502 1.1 mjacob */
503 1.1 mjacob case ASYNC_LIP_OCCURRED:
504 1.1 mjacob case ASYNC_LOOP_UP:
505 1.1 mjacob case ASYNC_LOOP_DOWN:
506 1.1 mjacob evt.ev_bus = bus;
507 1.1 mjacob evt.ev_event = event;
508 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
509 1.1 mjacob return;
510 1.1 mjacob
511 1.1 mjacob case ASYNC_LOOP_RESET:
512 1.1 mjacob case ASYNC_BUS_RESET:
513 1.1 mjacob case ASYNC_TIMEOUT_RESET:
514 1.1 mjacob if (IS_FC(isp)) {
515 1.1 mjacob return; /* we'll be getting an inotify instead */
516 1.1 mjacob }
517 1.1 mjacob evt.ev_bus = bus;
518 1.1 mjacob evt.ev_event = event;
519 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
520 1.1 mjacob break;
521 1.1 mjacob case ASYNC_DEVICE_RESET:
522 1.1 mjacob /*
523 1.1 mjacob * Bus Device Reset resets a specific target, so
524 1.1 mjacob * we pass this as a synthesized message.
525 1.1 mjacob */
526 1.1 mjacob MEMZERO(&msg, sizeof msg);
527 1.1 mjacob if (IS_FC(isp)) {
528 1.1 mjacob msg.nt_iid =
529 1.1 mjacob ((fcparam *)isp->isp_param)->isp_loopid;
530 1.1 mjacob } else {
531 1.1 mjacob msg.nt_iid =
532 1.1 mjacob ((sdparam *)isp->isp_param)->isp_initiator_id;
533 1.1 mjacob }
534 1.1 mjacob msg.nt_bus = bus;
535 1.1 mjacob msg.nt_msg[0] = MSG_BUS_DEV_RESET;
536 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
537 1.1 mjacob break;
538 1.1 mjacob default:
539 1.7 mjacob isp_prt(isp, ISP_LOGERR,
540 1.7 mjacob "isp_target_async: unknown event 0x%x", event);
541 1.1 mjacob break;
542 1.1 mjacob }
543 1.6 mjacob if (isp->isp_state == ISP_RUNSTATE)
544 1.6 mjacob isp_notify_ack(isp, NULL);
545 1.1 mjacob }
546 1.1 mjacob
547 1.1 mjacob
548 1.1 mjacob /*
549 1.1 mjacob * Process a received message.
550 1.1 mjacob * The ISP firmware can handle most messages, there are only
551 1.1 mjacob * a few that we need to deal with:
552 1.1 mjacob * - abort: clean up the current command
553 1.1 mjacob * - abort tag and clear queue
554 1.1 mjacob */
555 1.1 mjacob
556 1.1 mjacob static void
557 1.1 mjacob isp_got_msg(isp, bus, inp)
558 1.1 mjacob struct ispsoftc *isp;
559 1.1 mjacob int bus;
560 1.1 mjacob in_entry_t *inp;
561 1.1 mjacob {
562 1.1 mjacob u_int8_t status = inp->in_status & ~QLTM_SVALID;
563 1.1 mjacob
564 1.1 mjacob if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
565 1.1 mjacob tmd_msg_t msg;
566 1.1 mjacob
567 1.1 mjacob MEMZERO(&msg, sizeof (msg));
568 1.1 mjacob msg.nt_bus = bus;
569 1.1 mjacob msg.nt_iid = inp->in_iid;
570 1.1 mjacob msg.nt_tgt = inp->in_tgt;
571 1.1 mjacob msg.nt_lun = inp->in_lun;
572 1.1 mjacob msg.nt_tagtype = inp->in_tag_type;
573 1.1 mjacob msg.nt_tagval = inp->in_tag_val;
574 1.1 mjacob MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN);
575 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
576 1.1 mjacob } else {
577 1.7 mjacob isp_prt(isp, ISP_LOGERR,
578 1.7 mjacob "unknown immediate notify status 0x%x", inp->in_status);
579 1.1 mjacob }
580 1.1 mjacob }
581 1.1 mjacob
582 1.1 mjacob /*
583 1.1 mjacob * Synthesize a message from the task management flags in a FCP_CMND_IU.
584 1.1 mjacob */
585 1.1 mjacob static void
586 1.1 mjacob isp_got_msg_fc(isp, bus, inp)
587 1.1 mjacob struct ispsoftc *isp;
588 1.1 mjacob int bus;
589 1.1 mjacob in_fcentry_t *inp;
590 1.1 mjacob {
591 1.7 mjacob static char *f1 = "%s from iid %d lun %d seq 0x%x";
592 1.1 mjacob static char *f2 =
593 1.7 mjacob "unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n";
594 1.1 mjacob
595 1.1 mjacob if (inp->in_status != IN_MSG_RECEIVED) {
596 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
597 1.1 mjacob inp->in_status, inp->in_lun, inp->in_iid,
598 1.1 mjacob inp->in_task_flags, inp->in_seqid);
599 1.1 mjacob } else {
600 1.1 mjacob tmd_msg_t msg;
601 1.1 mjacob
602 1.1 mjacob MEMZERO(&msg, sizeof (msg));
603 1.1 mjacob msg.nt_bus = bus;
604 1.1 mjacob msg.nt_iid = inp->in_iid;
605 1.5 mjacob if (isp->isp_maxluns > 16) {
606 1.5 mjacob msg.nt_lun = inp->in_scclun;
607 1.5 mjacob } else {
608 1.5 mjacob msg.nt_lun = inp->in_lun;
609 1.5 mjacob }
610 1.1 mjacob msg.nt_tagval = inp->in_seqid;
611 1.1 mjacob
612 1.1 mjacob if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK) {
613 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK",
614 1.1 mjacob inp->in_iid, inp->in_lun, inp->in_seqid);
615 1.1 mjacob msg.nt_msg[0] = MSG_ABORT_TAG;
616 1.1 mjacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
617 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
618 1.1 mjacob inp->in_iid, inp->in_lun, inp->in_seqid);
619 1.1 mjacob msg.nt_msg[0] = MSG_CLEAR_QUEUE;
620 1.1 mjacob } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
621 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
622 1.1 mjacob inp->in_iid, inp->in_lun, inp->in_seqid);
623 1.1 mjacob msg.nt_msg[0] = MSG_BUS_DEV_RESET;
624 1.1 mjacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
625 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
626 1.1 mjacob inp->in_iid, inp->in_lun, inp->in_seqid);
627 1.1 mjacob /* ???? */
628 1.1 mjacob msg.nt_msg[0] = MSG_REL_RECOVERY;
629 1.1 mjacob } else if (inp->in_task_flags & TASK_FLAGS_TERMINATE_TASK) {
630 1.7 mjacob isp_prt(isp, ISP_LOGINFO, f1, "TERMINATE TASK",
631 1.1 mjacob inp->in_iid, inp->in_lun, inp->in_seqid);
632 1.1 mjacob msg.nt_msg[0] = MSG_TERM_IO_PROC;
633 1.1 mjacob } else {
634 1.7 mjacob isp_prt(isp, ISP_LOGWARN, f2, "task flag",
635 1.1 mjacob inp->in_status, inp->in_lun, inp->in_iid,
636 1.1 mjacob inp->in_task_flags, inp->in_seqid);
637 1.1 mjacob }
638 1.1 mjacob if (msg.nt_msg[0]) {
639 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
640 1.1 mjacob }
641 1.1 mjacob }
642 1.1 mjacob }
643 1.1 mjacob
644 1.1 mjacob static void
645 1.1 mjacob isp_notify_ack(isp, arg)
646 1.1 mjacob struct ispsoftc *isp;
647 1.1 mjacob void *arg;
648 1.1 mjacob {
649 1.1 mjacob char storage[QENTRY_LEN];
650 1.1 mjacob u_int16_t iptr, optr;
651 1.1 mjacob void *outp;
652 1.1 mjacob
653 1.1 mjacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
654 1.7 mjacob isp_prt(isp, ISP_LOGWARN,
655 1.7 mjacob "Request Queue Overflow For isp_notify_ack");
656 1.1 mjacob return;
657 1.1 mjacob }
658 1.1 mjacob
659 1.2 mjacob MEMZERO(storage, QENTRY_LEN);
660 1.1 mjacob
661 1.1 mjacob if (IS_FC(isp)) {
662 1.1 mjacob na_fcentry_t *na = (na_fcentry_t *) storage;
663 1.1 mjacob if (arg) {
664 1.1 mjacob in_fcentry_t *inp = arg;
665 1.2 mjacob MEMCPY(storage, arg, sizeof (isphdr_t));
666 1.1 mjacob na->na_iid = inp->in_iid;
667 1.5 mjacob if (isp->isp_maxluns > 16) {
668 1.5 mjacob na->na_lun = inp->in_scclun;
669 1.5 mjacob } else {
670 1.5 mjacob na->na_lun = inp->in_lun;
671 1.5 mjacob }
672 1.1 mjacob na->na_task_flags = inp->in_task_flags;
673 1.1 mjacob na->na_seqid = inp->in_seqid;
674 1.1 mjacob na->na_flags = NAFC_RCOUNT;
675 1.1 mjacob if (inp->in_status == IN_RESET) {
676 1.1 mjacob na->na_flags |= NAFC_RST_CLRD;
677 1.1 mjacob }
678 1.1 mjacob } else {
679 1.1 mjacob na->na_flags = NAFC_RST_CLRD;
680 1.1 mjacob }
681 1.4 he na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
682 1.4 he na->na_header.rqs_entry_count = 1;
683 1.1 mjacob ISP_SWIZ_NOT_ACK_FC(isp, outp, na);
684 1.1 mjacob } else {
685 1.1 mjacob na_entry_t *na = (na_entry_t *) storage;
686 1.1 mjacob if (arg) {
687 1.1 mjacob in_entry_t *inp = arg;
688 1.2 mjacob MEMCPY(storage, arg, sizeof (isphdr_t));
689 1.1 mjacob na->na_iid = inp->in_iid;
690 1.1 mjacob na->na_lun = inp->in_lun;
691 1.1 mjacob na->na_tgt = inp->in_tgt;
692 1.1 mjacob na->na_seqid = inp->in_seqid;
693 1.1 mjacob if (inp->in_status == IN_RESET) {
694 1.4 he na->na_event = NA_RST_CLRD;
695 1.1 mjacob }
696 1.1 mjacob } else {
697 1.4 he na->na_event = NA_RST_CLRD;
698 1.1 mjacob }
699 1.4 he na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
700 1.4 he na->na_header.rqs_entry_count = 1;
701 1.1 mjacob ISP_SWIZ_NOT_ACK(isp, outp, na);
702 1.1 mjacob }
703 1.1 mjacob ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
704 1.1 mjacob ISP_ADD_REQUEST(isp, iptr);
705 1.1 mjacob }
706 1.1 mjacob
707 1.1 mjacob static void
708 1.1 mjacob isp_handle_atio(isp, aep)
709 1.1 mjacob struct ispsoftc *isp;
710 1.1 mjacob at_entry_t *aep;
711 1.1 mjacob {
712 1.1 mjacob int lun;
713 1.1 mjacob lun = aep->at_lun;
714 1.1 mjacob /*
715 1.1 mjacob * The firmware status (except for the QLTM_SVALID bit) indicates
716 1.1 mjacob * why this ATIO was sent to us.
717 1.1 mjacob *
718 1.1 mjacob * If QLTM_SVALID is set, the firware has recommended Sense Data.
719 1.1 mjacob *
720 1.1 mjacob * If the DISCONNECTS DISABLED bit is set in the flags field,
721 1.1 mjacob * we're still connected on the SCSI bus - i.e. the initiator
722 1.1 mjacob * did not set DiscPriv in the identify message. We don't care
723 1.1 mjacob * about this so it's ignored.
724 1.1 mjacob */
725 1.1 mjacob
726 1.1 mjacob switch(aep->at_status & ~QLTM_SVALID) {
727 1.1 mjacob case AT_PATH_INVALID:
728 1.1 mjacob /*
729 1.1 mjacob * ATIO rejected by the firmware due to disabled lun.
730 1.1 mjacob */
731 1.7 mjacob isp_prt(isp, ISP_LOGERR,
732 1.7 mjacob "rejected ATIO for disabled lun %d", lun);
733 1.1 mjacob break;
734 1.1 mjacob case AT_NOCAP:
735 1.1 mjacob /*
736 1.1 mjacob * Requested Capability not available
737 1.1 mjacob * We sent an ATIO that overflowed the firmware's
738 1.1 mjacob * command resource count.
739 1.1 mjacob */
740 1.7 mjacob isp_prt(isp, ISP_LOGERR,
741 1.7 mjacob "rejected ATIO for lun %d because of command count"
742 1.7 mjacob " overflow", lun);
743 1.1 mjacob break;
744 1.1 mjacob
745 1.1 mjacob case AT_BDR_MSG:
746 1.1 mjacob /*
747 1.1 mjacob * If we send an ATIO to the firmware to increment
748 1.1 mjacob * its command resource count, and the firmware is
749 1.1 mjacob * recovering from a Bus Device Reset, it returns
750 1.1 mjacob * the ATIO with this status. We set the command
751 1.1 mjacob * resource count in the Enable Lun entry and no
752 1.1 mjacob * not increment it. Therefore we should never get
753 1.1 mjacob * this status here.
754 1.1 mjacob */
755 1.7 mjacob isp_prt(isp, ISP_LOGERR, atiocope, lun);
756 1.1 mjacob break;
757 1.1 mjacob
758 1.1 mjacob case AT_CDB: /* Got a CDB */
759 1.1 mjacob case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
760 1.1 mjacob /*
761 1.1 mjacob * Punt to platform specific layer.
762 1.1 mjacob */
763 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
764 1.1 mjacob break;
765 1.1 mjacob
766 1.1 mjacob case AT_RESET:
767 1.1 mjacob /*
768 1.1 mjacob * A bus reset came along an blew away this command. Why
769 1.1 mjacob * they do this in addition the async event code stuff,
770 1.1 mjacob * I dunno.
771 1.1 mjacob *
772 1.1 mjacob * Ignore it because the async event will clear things
773 1.1 mjacob * up for us.
774 1.1 mjacob */
775 1.7 mjacob isp_prt(isp, ISP_LOGWARN, atior, lun, aep->at_iid);
776 1.1 mjacob break;
777 1.1 mjacob
778 1.1 mjacob
779 1.1 mjacob default:
780 1.7 mjacob isp_prt(isp, ISP_LOGERR,
781 1.7 mjacob "Unknown ATIO status 0x%x from initiator %d for lun %d",
782 1.7 mjacob aep->at_status, aep->at_iid, lun);
783 1.1 mjacob (void) isp_target_put_atio(isp, aep->at_iid, aep->at_tgt,
784 1.1 mjacob lun, aep->at_tag_type, aep->at_tag_val);
785 1.1 mjacob break;
786 1.1 mjacob }
787 1.1 mjacob }
788 1.1 mjacob
789 1.1 mjacob static void
790 1.1 mjacob isp_handle_atio2(isp, aep)
791 1.1 mjacob struct ispsoftc *isp;
792 1.1 mjacob at2_entry_t *aep;
793 1.1 mjacob {
794 1.1 mjacob int lun;
795 1.5 mjacob
796 1.5 mjacob if (isp->isp_maxluns > 16) {
797 1.5 mjacob lun = aep->at_scclun;
798 1.5 mjacob } else {
799 1.5 mjacob lun = aep->at_lun;
800 1.5 mjacob }
801 1.5 mjacob
802 1.1 mjacob /*
803 1.1 mjacob * The firmware status (except for the QLTM_SVALID bit) indicates
804 1.1 mjacob * why this ATIO was sent to us.
805 1.1 mjacob *
806 1.1 mjacob * If QLTM_SVALID is set, the firware has recommended Sense Data.
807 1.1 mjacob *
808 1.1 mjacob * If the DISCONNECTS DISABLED bit is set in the flags field,
809 1.1 mjacob * we're still connected on the SCSI bus - i.e. the initiator
810 1.1 mjacob * did not set DiscPriv in the identify message. We don't care
811 1.1 mjacob * about this so it's ignored.
812 1.1 mjacob */
813 1.1 mjacob
814 1.1 mjacob switch(aep->at_status & ~QLTM_SVALID) {
815 1.1 mjacob case AT_PATH_INVALID:
816 1.1 mjacob /*
817 1.1 mjacob * ATIO rejected by the firmware due to disabled lun.
818 1.1 mjacob */
819 1.7 mjacob isp_prt(isp, ISP_LOGERR,
820 1.7 mjacob "rejected ATIO2 for disabled lun %d", lun);
821 1.1 mjacob break;
822 1.1 mjacob case AT_NOCAP:
823 1.1 mjacob /*
824 1.1 mjacob * Requested Capability not available
825 1.1 mjacob * We sent an ATIO that overflowed the firmware's
826 1.1 mjacob * command resource count.
827 1.1 mjacob */
828 1.7 mjacob isp_prt(isp, ISP_LOGERR,
829 1.7 mjacob "rejected ATIO2 for lun %d- command count overflow", lun);
830 1.1 mjacob break;
831 1.1 mjacob
832 1.1 mjacob case AT_BDR_MSG:
833 1.1 mjacob /*
834 1.1 mjacob * If we send an ATIO to the firmware to increment
835 1.1 mjacob * its command resource count, and the firmware is
836 1.1 mjacob * recovering from a Bus Device Reset, it returns
837 1.1 mjacob * the ATIO with this status. We set the command
838 1.1 mjacob * resource count in the Enable Lun entry and no
839 1.1 mjacob * not increment it. Therefore we should never get
840 1.1 mjacob * this status here.
841 1.1 mjacob */
842 1.7 mjacob isp_prt(isp, ISP_LOGERR, atiocope, lun);
843 1.1 mjacob break;
844 1.1 mjacob
845 1.1 mjacob case AT_CDB: /* Got a CDB */
846 1.1 mjacob /*
847 1.1 mjacob * Punt to platform specific layer.
848 1.1 mjacob */
849 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
850 1.1 mjacob break;
851 1.1 mjacob
852 1.1 mjacob case AT_RESET:
853 1.1 mjacob /*
854 1.1 mjacob * A bus reset came along an blew away this command. Why
855 1.1 mjacob * they do this in addition the async event code stuff,
856 1.1 mjacob * I dunno.
857 1.1 mjacob *
858 1.1 mjacob * Ignore it because the async event will clear things
859 1.1 mjacob * up for us.
860 1.1 mjacob */
861 1.7 mjacob isp_prt(isp, ISP_LOGERR, atior, lun, aep->at_iid);
862 1.1 mjacob break;
863 1.1 mjacob
864 1.1 mjacob
865 1.1 mjacob default:
866 1.7 mjacob isp_prt(isp, ISP_LOGERR,
867 1.7 mjacob "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
868 1.7 mjacob aep->at_status, aep->at_iid, lun);
869 1.1 mjacob (void) isp_target_put_atio(isp, aep->at_iid, 0, lun, 0, 0);
870 1.1 mjacob break;
871 1.1 mjacob }
872 1.1 mjacob }
873 1.1 mjacob
874 1.1 mjacob static void
875 1.1 mjacob isp_handle_ctio(isp, ct)
876 1.1 mjacob struct ispsoftc *isp;
877 1.1 mjacob ct_entry_t *ct;
878 1.1 mjacob {
879 1.7 mjacob XS_T *xs;
880 1.7 mjacob int pl = ISP_LOGTDEBUG2;
881 1.1 mjacob char *fmsg = NULL;
882 1.1 mjacob
883 1.1 mjacob if (ct->ct_reserved) {
884 1.1 mjacob xs = isp_find_xs(isp, ct->ct_reserved);
885 1.1 mjacob if (xs == NULL)
886 1.7 mjacob pl = ISP_LOGALL;
887 1.1 mjacob } else {
888 1.7 mjacob pl = ISP_LOGTDEBUG1;
889 1.1 mjacob xs = NULL;
890 1.1 mjacob }
891 1.1 mjacob
892 1.1 mjacob switch(ct->ct_status & ~QLTM_SVALID) {
893 1.1 mjacob case CT_OK:
894 1.1 mjacob /*
895 1.1 mjacob * There are generally 3 possibilities as to why we'd get
896 1.1 mjacob * this condition:
897 1.1 mjacob * We disconnected after receiving a CDB.
898 1.1 mjacob * We sent or received data.
899 1.1 mjacob * We sent status & command complete.
900 1.1 mjacob */
901 1.1 mjacob
902 1.4 he if (ct->ct_flags & CT_SENDSTATUS) {
903 1.4 he break;
904 1.4 he } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
905 1.1 mjacob /*
906 1.1 mjacob * Nothing to do in this case.
907 1.1 mjacob */
908 1.7 mjacob isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
909 1.7 mjacob ct->ct_iid);
910 1.1 mjacob return;
911 1.1 mjacob }
912 1.1 mjacob break;
913 1.1 mjacob
914 1.1 mjacob case CT_BDR_MSG:
915 1.1 mjacob /*
916 1.1 mjacob * Bus Device Reset message received or the SCSI Bus has
917 1.1 mjacob * been Reset; the firmware has gone to Bus Free.
918 1.1 mjacob *
919 1.1 mjacob * The firmware generates an async mailbox interupt to
920 1.1 mjacob * notify us of this and returns outstanding CTIOs with this
921 1.1 mjacob * status. These CTIOs are handled in that same way as
922 1.1 mjacob * CT_ABORTED ones, so just fall through here.
923 1.1 mjacob */
924 1.1 mjacob fmsg = "Bus Device Reset";
925 1.1 mjacob /*FALLTHROUGH*/
926 1.1 mjacob case CT_RESET:
927 1.1 mjacob if (fmsg == NULL)
928 1.1 mjacob fmsg = "Bus Reset";
929 1.1 mjacob /*FALLTHROUGH*/
930 1.1 mjacob case CT_ABORTED:
931 1.1 mjacob /*
932 1.1 mjacob * When an Abort message is received the firmware goes to
933 1.1 mjacob * Bus Free and returns all outstanding CTIOs with the status
934 1.1 mjacob * set, then sends us an Immediate Notify entry.
935 1.1 mjacob */
936 1.1 mjacob if (fmsg == NULL)
937 1.1 mjacob fmsg = "ABORT TASK sent by Initiator";
938 1.1 mjacob
939 1.7 mjacob isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
940 1.1 mjacob break;
941 1.1 mjacob
942 1.1 mjacob case CT_INVAL:
943 1.1 mjacob /*
944 1.1 mjacob * CTIO rejected by the firmware due to disabled lun.
945 1.1 mjacob * "Cannot Happen".
946 1.1 mjacob */
947 1.7 mjacob isp_prt(isp, ISP_LOGERR,
948 1.7 mjacob "Firmware rejected CTIO for disabled lun %d",
949 1.7 mjacob ct->ct_lun);
950 1.1 mjacob break;
951 1.1 mjacob
952 1.1 mjacob case CT_NOPATH:
953 1.1 mjacob /*
954 1.1 mjacob * CTIO rejected by the firmware due "no path for the
955 1.1 mjacob * nondisconnecting nexus specified". This means that
956 1.1 mjacob * we tried to access the bus while a non-disconnecting
957 1.1 mjacob * command is in process.
958 1.1 mjacob */
959 1.7 mjacob isp_prt(isp, ISP_LOGERR,
960 1.7 mjacob "Firmware rejected CTIO for bad nexus %d/%d/%d",
961 1.7 mjacob ct->ct_iid, ct->ct_tgt, ct->ct_lun);
962 1.1 mjacob break;
963 1.1 mjacob
964 1.1 mjacob case CT_RSELTMO:
965 1.1 mjacob fmsg = "Reselection";
966 1.1 mjacob /*FALLTHROUGH*/
967 1.1 mjacob case CT_TIMEOUT:
968 1.1 mjacob if (fmsg == NULL)
969 1.1 mjacob fmsg = "Command";
970 1.7 mjacob isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
971 1.1 mjacob break;
972 1.1 mjacob
973 1.1 mjacob case CT_ERR:
974 1.1 mjacob fmsg = "Completed with Error";
975 1.1 mjacob /*FALLTHROUGH*/
976 1.1 mjacob case CT_PHASE_ERROR:
977 1.1 mjacob if (fmsg == NULL)
978 1.1 mjacob fmsg = "Phase Sequence Error";
979 1.1 mjacob /*FALLTHROUGH*/
980 1.1 mjacob case CT_TERMINATED:
981 1.1 mjacob if (fmsg == NULL)
982 1.1 mjacob fmsg = "terminated by TERMINATE TRANSFER";
983 1.1 mjacob /*FALLTHROUGH*/
984 1.1 mjacob case CT_NOACK:
985 1.1 mjacob if (fmsg == NULL)
986 1.1 mjacob fmsg = "unacknowledged Immediate Notify pending";
987 1.1 mjacob
988 1.7 mjacob isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
989 1.1 mjacob #if 0
990 1.1 mjacob if (status & SENSEVALID) {
991 1.1 mjacob bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
992 1.1 mjacob (caddr_t) &cdp->cd_sensedata,
993 1.1 mjacob sizeof(scsi_sense_t));
994 1.1 mjacob cdp->cd_flags |= CDF_SENSEVALID;
995 1.1 mjacob }
996 1.1 mjacob #endif
997 1.1 mjacob break;
998 1.1 mjacob default:
999 1.7 mjacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1000 1.1 mjacob ct->ct_status & ~QLTM_SVALID);
1001 1.1 mjacob break;
1002 1.1 mjacob }
1003 1.1 mjacob
1004 1.1 mjacob if (xs == NULL) {
1005 1.1 mjacob /*
1006 1.1 mjacob * There may be more than one CTIO for a data transfer,
1007 1.1 mjacob * or this may be a status CTIO we're not monitoring.
1008 1.1 mjacob *
1009 1.1 mjacob * The assumption is that they'll all be returned in the
1010 1.1 mjacob * order we got them.
1011 1.1 mjacob */
1012 1.1 mjacob if (ct->ct_reserved == 0) {
1013 1.1 mjacob if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1014 1.7 mjacob isp_prt(isp, pl,
1015 1.7 mjacob "intermediate CTIO completed ok");
1016 1.1 mjacob } else {
1017 1.7 mjacob isp_prt(isp, pl,
1018 1.7 mjacob "unmonitored CTIO completed ok");
1019 1.1 mjacob }
1020 1.1 mjacob } else {
1021 1.7 mjacob isp_prt(isp, pl,
1022 1.7 mjacob "NO xs for CTIO (handle 0x%x) status 0x%x",
1023 1.7 mjacob ct->ct_reserved, ct->ct_status & ~QLTM_SVALID);
1024 1.1 mjacob }
1025 1.1 mjacob } else {
1026 1.1 mjacob if (ct->ct_flags & CT_SENDSTATUS) {
1027 1.1 mjacob /*
1028 1.1 mjacob * Sent status and command complete.
1029 1.1 mjacob *
1030 1.1 mjacob * We're now really done with this command, so we
1031 1.1 mjacob * punt to the platform dependent layers because
1032 1.1 mjacob * only there can we do the appropriate command
1033 1.1 mjacob * complete thread synchronization.
1034 1.1 mjacob */
1035 1.7 mjacob isp_prt(isp, pl, "status CTIO complete");
1036 1.1 mjacob } else {
1037 1.1 mjacob /*
1038 1.1 mjacob * Final CTIO completed. Release DMA resources and
1039 1.1 mjacob * notify platform dependent layers.
1040 1.1 mjacob */
1041 1.7 mjacob isp_prt(isp, pl, "data CTIO complete");
1042 1.1 mjacob ISP_DMAFREE(isp, xs, ct->ct_reserved);
1043 1.1 mjacob }
1044 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1045 1.1 mjacob /*
1046 1.1 mjacob * The platform layer will destroy the handle if appropriate.
1047 1.1 mjacob */
1048 1.1 mjacob }
1049 1.1 mjacob }
1050 1.1 mjacob
1051 1.1 mjacob static void
1052 1.1 mjacob isp_handle_ctio2(isp, ct)
1053 1.1 mjacob struct ispsoftc *isp;
1054 1.1 mjacob ct2_entry_t *ct;
1055 1.1 mjacob {
1056 1.7 mjacob XS_T *xs;
1057 1.7 mjacob int pl = ISP_LOGTDEBUG2;
1058 1.1 mjacob char *fmsg = NULL;
1059 1.1 mjacob
1060 1.1 mjacob if (ct->ct_reserved) {
1061 1.1 mjacob xs = isp_find_xs(isp, ct->ct_reserved);
1062 1.1 mjacob if (xs == NULL)
1063 1.7 mjacob pl = ISP_LOGALL;
1064 1.1 mjacob } else {
1065 1.7 mjacob pl = ISP_LOGTDEBUG1;
1066 1.1 mjacob xs = NULL;
1067 1.1 mjacob }
1068 1.1 mjacob
1069 1.1 mjacob switch(ct->ct_status & ~QLTM_SVALID) {
1070 1.1 mjacob case CT_OK:
1071 1.1 mjacob /*
1072 1.1 mjacob * There are generally 2 possibilities as to why we'd get
1073 1.1 mjacob * this condition:
1074 1.1 mjacob * We sent or received data.
1075 1.1 mjacob * We sent status & command complete.
1076 1.1 mjacob */
1077 1.1 mjacob
1078 1.1 mjacob break;
1079 1.1 mjacob
1080 1.1 mjacob case CT_BDR_MSG:
1081 1.1 mjacob /*
1082 1.1 mjacob * Bus Device Reset message received or the SCSI Bus has
1083 1.1 mjacob * been Reset; the firmware has gone to Bus Free.
1084 1.1 mjacob *
1085 1.1 mjacob * The firmware generates an async mailbox interupt to
1086 1.1 mjacob * notify us of this and returns outstanding CTIOs with this
1087 1.1 mjacob * status. These CTIOs are handled in that same way as
1088 1.1 mjacob * CT_ABORTED ones, so just fall through here.
1089 1.1 mjacob */
1090 1.1 mjacob fmsg = "Bus Device Reset";
1091 1.1 mjacob /*FALLTHROUGH*/
1092 1.1 mjacob case CT_RESET:
1093 1.1 mjacob if (fmsg == NULL)
1094 1.1 mjacob fmsg = "Bus Reset";
1095 1.1 mjacob /*FALLTHROUGH*/
1096 1.1 mjacob case CT_ABORTED:
1097 1.1 mjacob /*
1098 1.1 mjacob * When an Abort message is received the firmware goes to
1099 1.1 mjacob * Bus Free and returns all outstanding CTIOs with the status
1100 1.1 mjacob * set, then sends us an Immediate Notify entry.
1101 1.1 mjacob */
1102 1.1 mjacob if (fmsg == NULL)
1103 1.1 mjacob fmsg = "ABORT TASK sent by Initiator";
1104 1.1 mjacob
1105 1.7 mjacob isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s", fmsg);
1106 1.1 mjacob break;
1107 1.1 mjacob
1108 1.1 mjacob case CT_INVAL:
1109 1.1 mjacob /*
1110 1.2 mjacob * CTIO rejected by the firmware - invalid data direction.
1111 1.1 mjacob */
1112 1.7 mjacob isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data directiond");
1113 1.1 mjacob break;
1114 1.1 mjacob
1115 1.1 mjacob case CT_NOPATH:
1116 1.1 mjacob /*
1117 1.1 mjacob * CTIO rejected by the firmware due "no path for the
1118 1.1 mjacob * nondisconnecting nexus specified". This means that
1119 1.1 mjacob * we tried to access the bus while a non-disconnecting
1120 1.1 mjacob * command is in process.
1121 1.1 mjacob */
1122 1.7 mjacob isp_prt(isp, ISP_LOGERR,
1123 1.7 mjacob "Firmware rejected CTIO2 for bad nexus %d->%d",
1124 1.7 mjacob ct->ct_iid, ct->ct_lun);
1125 1.1 mjacob break;
1126 1.1 mjacob
1127 1.1 mjacob case CT_RSELTMO:
1128 1.1 mjacob fmsg = "Reselection";
1129 1.1 mjacob /*FALLTHROUGH*/
1130 1.1 mjacob case CT_TIMEOUT:
1131 1.1 mjacob if (fmsg == NULL)
1132 1.1 mjacob fmsg = "Command";
1133 1.7 mjacob isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1134 1.1 mjacob break;
1135 1.1 mjacob
1136 1.1 mjacob case CT_ERR:
1137 1.1 mjacob fmsg = "Completed with Error";
1138 1.1 mjacob /*FALLTHROUGH*/
1139 1.1 mjacob case CT_PHASE_ERROR: /* Bus phase sequence error */
1140 1.1 mjacob if (fmsg == NULL)
1141 1.1 mjacob fmsg = "Phase Sequence Error";
1142 1.1 mjacob /*FALLTHROUGH*/
1143 1.1 mjacob case CT_TERMINATED:
1144 1.1 mjacob if (fmsg == NULL)
1145 1.1 mjacob fmsg = "terminated by TERMINATE TRANSFER";
1146 1.1 mjacob /*FALLTHROUGH*/
1147 1.1 mjacob case CT_LOGOUT:
1148 1.1 mjacob if (fmsg == NULL)
1149 1.1 mjacob fmsg = "Port Logout";
1150 1.1 mjacob /*FALLTHROUGH*/
1151 1.1 mjacob case CT_PORTNOTAVAIL:
1152 1.1 mjacob if (fmsg == NULL)
1153 1.1 mjacob fmsg = "Port not available";
1154 1.1 mjacob case CT_NOACK:
1155 1.1 mjacob if (fmsg == NULL)
1156 1.1 mjacob fmsg = "unacknowledged Immediate Notify pending";
1157 1.1 mjacob
1158 1.7 mjacob isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1159 1.1 mjacob #if 0
1160 1.1 mjacob if (status & SENSEVALID) {
1161 1.1 mjacob bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
1162 1.1 mjacob (caddr_t) &cdp->cd_sensedata,
1163 1.1 mjacob sizeof(scsi_sense_t));
1164 1.1 mjacob cdp->cd_flags |= CDF_SENSEVALID;
1165 1.1 mjacob }
1166 1.1 mjacob #endif
1167 1.1 mjacob break;
1168 1.1 mjacob
1169 1.1 mjacob case CT_INVRXID:
1170 1.1 mjacob /*
1171 1.1 mjacob * CTIO rejected by the firmware because an invalid RX_ID.
1172 1.1 mjacob * Just print a message.
1173 1.1 mjacob */
1174 1.7 mjacob isp_prt(isp, ISP_LOGERR,
1175 1.7 mjacob "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1176 1.1 mjacob break;
1177 1.1 mjacob
1178 1.1 mjacob default:
1179 1.7 mjacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1180 1.7 mjacob ct->ct_status & ~QLTM_SVALID);
1181 1.1 mjacob break;
1182 1.1 mjacob }
1183 1.1 mjacob
1184 1.1 mjacob if (xs == NULL) {
1185 1.1 mjacob /*
1186 1.1 mjacob * There may be more than one CTIO for a data transfer,
1187 1.1 mjacob * or this may be a status CTIO we're not monitoring.
1188 1.1 mjacob *
1189 1.1 mjacob * The assumption is that they'll all be returned in the
1190 1.1 mjacob * order we got them.
1191 1.1 mjacob */
1192 1.1 mjacob if (ct->ct_reserved == 0) {
1193 1.1 mjacob if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1194 1.7 mjacob isp_prt(isp, pl,
1195 1.7 mjacob "intermediate CTIO completed ok");
1196 1.1 mjacob } else {
1197 1.7 mjacob isp_prt(isp, pl,
1198 1.7 mjacob "unmonitored CTIO completed ok");
1199 1.1 mjacob }
1200 1.1 mjacob } else {
1201 1.7 mjacob isp_prt(isp, pl,
1202 1.7 mjacob "NO xs for CTIO (handle 0x%x) status 0x%x",
1203 1.7 mjacob ct->ct_reserved, ct->ct_status & ~QLTM_SVALID);
1204 1.1 mjacob }
1205 1.1 mjacob } else {
1206 1.1 mjacob if (ct->ct_flags & CT_SENDSTATUS) {
1207 1.1 mjacob /*
1208 1.1 mjacob * Sent status and command complete.
1209 1.1 mjacob *
1210 1.1 mjacob * We're now really done with this command, so we
1211 1.1 mjacob * punt to the platform dependent layers because
1212 1.1 mjacob * only there can we do the appropriate command
1213 1.1 mjacob * complete thread synchronization.
1214 1.1 mjacob */
1215 1.7 mjacob isp_prt(isp, pl, "status CTIO complete");
1216 1.1 mjacob } else {
1217 1.1 mjacob /*
1218 1.1 mjacob * Final CTIO completed. Release DMA resources and
1219 1.1 mjacob * notify platform dependent layers.
1220 1.1 mjacob */
1221 1.7 mjacob isp_prt(isp, pl, "data CTIO complete");
1222 1.1 mjacob ISP_DMAFREE(isp, xs, ct->ct_reserved);
1223 1.1 mjacob }
1224 1.1 mjacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1225 1.1 mjacob /*
1226 1.1 mjacob * The platform layer will destroy the handle if appropriate.
1227 1.1 mjacob */
1228 1.1 mjacob }
1229 1.1 mjacob }
1230 1.1 mjacob #endif
1231