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