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