1 /*- 2 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters. 3 * 4 * Copyright (c) 1997-2006 by Matthew Jacob 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 /* 29 * Bug fixes gratefully acknowledged from: 30 * Oded Kedem <oded@kashya.com> 31 */ 32 /* 33 * Include header file appropriate for platform we're building on. 34 */ 35 36 #ifdef __NetBSD__ 37 #include <dev/ic/isp_netbsd.h> 38 #endif 39 #ifdef __FreeBSD__ 40 #include <sys/cdefs.h> 41 __FBSDID("$FreeBSD$"); 42 #include <dev/isp/isp_freebsd.h> 43 #endif 44 #ifdef __OpenBSD__ 45 #include <dev/ic/isp_openbsd.h> 46 #endif 47 #ifdef __linux__ 48 #include "isp_linux.h" 49 #endif 50 51 #ifdef ISP_TARGET_MODE 52 static const char atiocope[] = 53 "ATIO returned for lun %d because it was in the middle of Bus Device Reset " 54 "on bus %d"; 55 static const char atior[] = 56 "ATIO returned on for lun %d on from loopid %d because a Bus Reset " 57 "occurred on bus %d"; 58 59 static void isp_got_msg(ispsoftc_t *, in_entry_t *); 60 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *); 61 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *); 62 static void isp_handle_atio(ispsoftc_t *, at_entry_t *); 63 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *); 64 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *); 65 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *); 66 static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *); 67 68 /* 69 * The Qlogic driver gets an interrupt to look at response queue entries. 70 * Some of these are status completions for initiatior mode commands, but 71 * if target mode is enabled, we get a whole wad of response queue entries 72 * to be handled here. 73 * 74 * Basically the split into 3 main groups: Lun Enable/Modification responses, 75 * SCSI Command processing, and Immediate Notification events. 76 * 77 * You start by writing a request queue entry to enable target mode (and 78 * establish some resource limitations which you can modify later). 79 * The f/w responds with a LUN ENABLE or LUN MODIFY response with 80 * the status of this action. If the enable was successful, you can expect... 81 * 82 * Response queue entries with SCSI commands encapsulate show up in an ATIO 83 * (Accept Target IO) type- sometimes with enough info to stop the command at 84 * this level. Ultimately the driver has to feed back to the f/w's request 85 * queue a sequence of CTIOs (continue target I/O) that describe data to 86 * be moved and/or status to be sent) and finally finishing with sending 87 * to the f/w's response queue an ATIO which then completes the handshake 88 * with the f/w for that command. There's a lot of variations on this theme, 89 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel 90 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic 91 * gist of it. 92 * 93 * The third group that can show up in the response queue are Immediate 94 * Notification events. These include things like notifications of SCSI bus 95 * resets, or Bus Device Reset messages or other messages received. This 96 * a classic oddbins area. It can get a little weird because you then turn 97 * around and acknowledge the Immediate Notify by writing an entry onto the 98 * request queue and then the f/w turns around and gives you an acknowledgement 99 * to *your* acknowledgement on the response queue (the idea being to let 100 * the f/w tell you when the event is *really* over I guess). 101 * 102 */ 103 104 105 /* 106 * A new response queue entry has arrived. The interrupt service code 107 * has already swizzled it into the platform dependent from canonical form. 108 * 109 * Because of the way this driver is designed, unfortunately most of the 110 * actual synchronization work has to be done in the platform specific 111 * code- we have no synchroniation primitives in the common code. 112 */ 113 114 int 115 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp) 116 { 117 uint16_t status; 118 uint32_t seqid; 119 union { 120 at_entry_t *atiop; 121 at2_entry_t *at2iop; 122 at2e_entry_t *at2eiop; 123 at7_entry_t *at7iop; 124 ct_entry_t *ctiop; 125 ct2_entry_t *ct2iop; 126 ct2e_entry_t *ct2eiop; 127 ct7_entry_t *ct7iop; 128 lun_entry_t *lunenp; 129 in_entry_t *inotp; 130 in_fcentry_t *inot_fcp; 131 in_fcentry_e_t *inote_fcp; 132 in_fcentry_24xx_t *inot_24xx; 133 na_entry_t *nackp; 134 na_fcentry_t *nack_fcp; 135 na_fcentry_e_t *nacke_fcp; 136 na_fcentry_24xx_t *nack_24xx; 137 isphdr_t *hp; 138 abts_t *abts; 139 abts_rsp_t *abts_rsp; 140 els_t *els; 141 void * *vp; 142 #define atiop unp.atiop 143 #define at2iop unp.at2iop 144 #define at2eiop unp.at2eiop 145 #define at7iop unp.at7iop 146 #define ctiop unp.ctiop 147 #define ct2iop unp.ct2iop 148 #define ct2eiop unp.ct2eiop 149 #define ct7iop unp.ct7iop 150 #define lunenp unp.lunenp 151 #define inotp unp.inotp 152 #define inot_fcp unp.inot_fcp 153 #define inote_fcp unp.inote_fcp 154 #define inot_24xx unp.inot_24xx 155 #define nackp unp.nackp 156 #define nack_fcp unp.nack_fcp 157 #define nacke_fcp unp.nacke_fcp 158 #define nack_24xx unp.nack_24xx 159 #define abts unp.abts 160 #define abts_rsp unp.abts_rsp 161 #define els unp.els 162 #define hdrp unp.hp 163 } unp; 164 uint8_t local[QENTRY_LEN]; 165 int bus, type, level, rval = 1; 166 167 type = isp_get_response_type(isp, (isphdr_t *)vptr); 168 unp.vp = vptr; 169 170 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr); 171 172 switch(type) { 173 case RQSTYPE_ATIO: 174 if (IS_24XX(isp)) { 175 int len; 176 177 isp_get_atio7(isp, at7iop, (at7_entry_t *) local); 178 at7iop = (at7_entry_t *) local; 179 /* 180 * Check for and do something with commands whose IULEN 181 * extends past a singel queue entry. 182 */ 183 len = at7iop->at_ta_len & 0xfffff; 184 if (len > (QENTRY_LEN - 8)) { 185 len -= (QENTRY_LEN - 8); 186 isp_prt(isp, ISP_LOGINFO, 187 "long IU length (%d) ignored", len); 188 while (len > 0) { 189 *optrp = ISP_NXT_QENTRY(*optrp, 190 RESULT_QUEUE_LEN(isp)); 191 len -= QENTRY_LEN; 192 } 193 } 194 /* 195 * Check for a task management function 196 */ 197 if (at7iop->at_cmnd.fcp_cmnd_task_management) { 198 isp_got_tmf_24xx(isp, at7iop); 199 break; 200 } 201 /* 202 * Just go straight to outer layer for this one. 203 */ 204 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local); 205 } else { 206 isp_get_atio(isp, atiop, (at_entry_t *) local); 207 isp_handle_atio(isp, (at_entry_t *) local); 208 } 209 break; 210 211 case RQSTYPE_CTIO: 212 isp_get_ctio(isp, ctiop, (ct_entry_t *) local); 213 isp_handle_ctio(isp, (ct_entry_t *) local); 214 break; 215 216 case RQSTYPE_ATIO2: 217 if (FCPARAM(isp)->isp_2klogin) { 218 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local); 219 } else { 220 isp_get_atio2(isp, at2iop, (at2_entry_t *) local); 221 } 222 isp_handle_atio2(isp, (at2_entry_t *) local); 223 break; 224 225 case RQSTYPE_CTIO3: 226 case RQSTYPE_CTIO2: 227 if (FCPARAM(isp)->isp_2klogin) { 228 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local); 229 } else { 230 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local); 231 } 232 isp_handle_ctio2(isp, (ct2_entry_t *) local); 233 break; 234 235 case RQSTYPE_CTIO7: 236 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local); 237 isp_handle_ctio7(isp, (ct7_entry_t *) local); 238 break; 239 240 case RQSTYPE_ENABLE_LUN: 241 case RQSTYPE_MODIFY_LUN: 242 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local); 243 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local); 244 break; 245 246 case RQSTYPE_NOTIFY: 247 /* 248 * Either the ISP received a SCSI message it can't 249 * handle, or it's returning an Immed. Notify entry 250 * we sent. We can send Immed. Notify entries to 251 * increment the firmware's resource count for them 252 * (we set this initially in the Enable Lun entry). 253 */ 254 bus = 0; 255 if (IS_24XX(isp)) { 256 isp_get_notify_24xx(isp, inot_24xx, 257 (in_fcentry_24xx_t *)local); 258 inot_24xx = (in_fcentry_24xx_t *) local; 259 status = inot_24xx->in_status; 260 seqid = inot_24xx->in_rxid; 261 isp_prt(isp, ISP_LOGTDEBUG0, 262 "Immediate Notify status=0x%x seqid=0x%x", 263 status, seqid); 264 switch (status) { 265 case IN24XX_LIP_RESET: 266 case IN24XX_LINK_RESET: 267 case IN24XX_PORT_LOGOUT: 268 case IN24XX_PORT_CHANGED: 269 case IN24XX_LINK_FAILED: 270 case IN24XX_SRR_RCVD: 271 case IN24XX_ELS_RCVD: 272 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, 273 &local); 274 break; 275 default: 276 isp_prt(isp, ISP_LOGINFO, 277 "isp_target_notify: unknown status (0x%x)", 278 status); 279 isp_notify_ack(isp, local); 280 break; 281 } 282 break; 283 } else if (IS_FC(isp)) { 284 if (FCPARAM(isp)->isp_2klogin) { 285 isp_get_notify_fc_e(isp, inote_fcp, 286 (in_fcentry_e_t *)local); 287 } else { 288 isp_get_notify_fc(isp, inot_fcp, 289 (in_fcentry_t *)local); 290 } 291 inot_fcp = (in_fcentry_t *) local; 292 status = inot_fcp->in_status; 293 seqid = inot_fcp->in_seqid; 294 } else { 295 isp_get_notify(isp, inotp, (in_entry_t *)local); 296 inotp = (in_entry_t *) local; 297 status = inotp->in_status & 0xff; 298 seqid = inotp->in_seqid; 299 if (IS_DUALBUS(isp)) { 300 bus = GET_BUS_VAL(inotp->in_iid); 301 SET_BUS_VAL(inotp->in_iid, 0); 302 } 303 } 304 305 isp_prt(isp, ISP_LOGTDEBUG0, 306 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x", 307 bus, status, seqid); 308 309 switch (status) { 310 case IN_MSG_RECEIVED: 311 case IN_IDE_RECEIVED: 312 if (IS_FC(isp)) { 313 isp_got_msg_fc(isp, (in_fcentry_t *)local); 314 } else { 315 isp_got_msg(isp, (in_entry_t *)local); 316 } 317 break; 318 case IN_RSRC_UNAVAIL: 319 isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs"); 320 isp_notify_ack(isp, local); 321 break; 322 case IN_RESET: 323 { 324 /* 325 * We form the notify structure here because we need 326 * to mark it as needing a NOTIFY ACK on return. 327 */ 328 tmd_notify_t notify; 329 330 MEMZERO(¬ify, sizeof (tmd_notify_t)); 331 notify.nt_hba = isp; 332 notify.nt_iid = INI_ANY; 333 /* nt_tgt set in outer layers */ 334 notify.nt_lun = LUN_ANY; 335 notify.nt_tagval = TAG_ANY; 336 notify.nt_ncode = NT_BUS_RESET; 337 notify.nt_need_ack = 1; 338 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 339 break; 340 } 341 case IN_PORT_LOGOUT: 342 case IN_ABORT_TASK: 343 case IN_PORT_CHANGED: 344 case IN_GLOBAL_LOGO: 345 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local); 346 break; 347 default: 348 isp_prt(isp, ISP_LOGINFO, 349 "isp_target_notify: unknown status (0x%x)", 350 status); 351 isp_notify_ack(isp, local); 352 break; 353 } 354 break; 355 356 case RQSTYPE_NOTIFY_ACK: 357 /* 358 * The ISP is acknowledging our acknowledgement of an 359 * Immediate Notify entry for some asynchronous event. 360 */ 361 if (IS_24XX(isp)) { 362 isp_get_notify_ack_24xx(isp, nack_24xx, 363 (na_fcentry_24xx_t *) local); 364 nack_24xx = (na_fcentry_24xx_t *) local; 365 if (nack_24xx->na_status != NA_OK) { 366 level = ISP_LOGINFO; 367 } else { 368 level = ISP_LOGTDEBUG1; 369 } 370 isp_prt(isp, level, 371 "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x", 372 nack_24xx->na_status, nack_24xx->na_status_subcode, 373 nack_24xx->na_rxid); 374 } else if (IS_FC(isp)) { 375 if (FCPARAM(isp)->isp_2klogin) { 376 isp_get_notify_ack_fc_e(isp, nacke_fcp, 377 (na_fcentry_e_t *)local); 378 } else { 379 isp_get_notify_ack_fc(isp, nack_fcp, 380 (na_fcentry_t *)local); 381 } 382 nack_fcp = (na_fcentry_t *)local; 383 if (nack_fcp->na_status != NA_OK) { 384 level = ISP_LOGINFO; 385 } else { 386 level = ISP_LOGTDEBUG1; 387 } 388 isp_prt(isp, level, 389 "Notify Ack Status=0x%x seqid 0x%x", 390 nack_fcp->na_status, nack_fcp->na_seqid); 391 } else { 392 isp_get_notify_ack(isp, nackp, (na_entry_t *)local); 393 nackp = (na_entry_t *)local; 394 if (nackp->na_status != NA_OK) { 395 level = ISP_LOGINFO; 396 } else { 397 level = ISP_LOGTDEBUG1; 398 } 399 isp_prt(isp, level, 400 "Notify Ack event 0x%x status=0x%x seqid 0x%x", 401 nackp->na_event, nackp->na_status, nackp->na_seqid); 402 } 403 break; 404 405 case RQSTYPE_ABTS_RCVD: 406 isp_get_abts(isp, abts, (abts_t *)local); 407 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local); 408 break; 409 case RQSTYPE_ABTS_RSP: 410 isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local); 411 abts_rsp = (abts_rsp_t *) local; 412 if (abts_rsp->abts_rsp_status) { 413 level = ISP_LOGINFO; 414 } else { 415 level = ISP_LOGTDEBUG0; 416 } 417 isp_prt(isp, level, 418 "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)", 419 abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status, 420 abts_rsp->abts_rsp_payload.rsp.subcode1, 421 abts_rsp->abts_rsp_payload.rsp.subcode2); 422 break; 423 default: 424 isp_prt(isp, ISP_LOGERR, 425 "Unknown entry type 0x%x in isp_target_notify", type); 426 rval = 0; 427 break; 428 } 429 #undef atiop 430 #undef at2iop 431 #undef at2eiop 432 #undef at7iop 433 #undef ctiop 434 #undef ct2iop 435 #undef ct2eiop 436 #undef ct7iop 437 #undef lunenp 438 #undef inotp 439 #undef inot_fcp 440 #undef inote_fcp 441 #undef inot_24xx 442 #undef nackp 443 #undef nack_fcp 444 #undef nacke_fcp 445 #undef hack_24xx 446 #undef abts 447 #undef abts_rsp 448 #undef els 449 #undef hdrp 450 return (rval); 451 } 452 453 454 /* 455 * Toggle (on/off) target mode for bus/target/lun 456 * 457 * The caller has checked for overlap and legality. 458 * 459 * Note that not all of bus, target or lun can be paid attention to. 460 * Note also that this action will not be complete until the f/w writes 461 * response entry. The caller is responsible for synchronizing this. 462 */ 463 int 464 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun, 465 int cmd_cnt, int inot_cnt, uint32_t opaque) 466 { 467 lun_entry_t el; 468 uint32_t nxti, optr; 469 void *outp; 470 471 472 MEMZERO(&el, sizeof (el)); 473 if (IS_DUALBUS(isp)) { 474 el.le_rsvd = (bus & 0x1) << 7; 475 } 476 el.le_cmd_count = cmd_cnt; 477 el.le_in_count = inot_cnt; 478 if (cmd == RQSTYPE_ENABLE_LUN) { 479 if (IS_SCSI(isp)) { 480 el.le_flags = LUN_TQAE|LUN_DISAD; 481 el.le_cdb6len = 12; 482 el.le_cdb7len = 12; 483 } 484 } else if (cmd == -RQSTYPE_ENABLE_LUN) { 485 cmd = RQSTYPE_ENABLE_LUN; 486 el.le_cmd_count = 0; 487 el.le_in_count = 0; 488 } else if (cmd == -RQSTYPE_MODIFY_LUN) { 489 cmd = RQSTYPE_MODIFY_LUN; 490 el.le_ops = LUN_CCDECR | LUN_INDECR; 491 } else { 492 el.le_ops = LUN_CCINCR | LUN_ININCR; 493 } 494 el.le_header.rqs_entry_type = cmd; 495 el.le_header.rqs_entry_count = 1; 496 el.le_reserved = opaque; 497 if (IS_SCSI(isp)) { 498 el.le_tgt = tgt; 499 el.le_lun = lun; 500 } else if (FCPARAM(isp)->isp_sccfw == 0) { 501 el.le_lun = lun; 502 } 503 504 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 505 isp_prt(isp, ISP_LOGERR, 506 "Request Queue Overflow in isp_lun_cmd"); 507 return (-1); 508 } 509 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el); 510 isp_put_enable_lun(isp, &el, outp); 511 ISP_ADD_REQUEST(isp, nxti); 512 return (0); 513 } 514 515 516 int 517 isp_target_put_entry(ispsoftc_t *isp, void *ap) 518 { 519 void *outp; 520 uint32_t nxti, optr; 521 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type; 522 523 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 524 isp_prt(isp, ISP_LOGWARN, 525 "Request Queue Overflow in isp_target_put_entry"); 526 return (-1); 527 } 528 switch (etype) { 529 case RQSTYPE_ATIO: 530 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp); 531 break; 532 case RQSTYPE_ATIO2: 533 if (FCPARAM(isp)->isp_2klogin) { 534 isp_put_atio2e(isp, (at2e_entry_t *) ap, 535 (at2e_entry_t *) outp); 536 } else { 537 isp_put_atio2(isp, (at2_entry_t *) ap, 538 (at2_entry_t *) outp); 539 } 540 break; 541 case RQSTYPE_CTIO: 542 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp); 543 break; 544 case RQSTYPE_CTIO2: 545 if (FCPARAM(isp)->isp_2klogin) { 546 isp_put_ctio2e(isp, (ct2e_entry_t *) ap, 547 (ct2e_entry_t *) outp); 548 } else { 549 isp_put_ctio2(isp, (ct2_entry_t *) ap, 550 (ct2_entry_t *) outp); 551 } 552 break; 553 case RQSTYPE_CTIO7: 554 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp); 555 break; 556 default: 557 isp_prt(isp, ISP_LOGERR, 558 "Unknown type 0x%x in isp_put_entry", etype); 559 return (-1); 560 } 561 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap); 562 ISP_ADD_REQUEST(isp, nxti); 563 return (0); 564 } 565 566 int 567 isp_target_put_atio(ispsoftc_t *isp, void *arg) 568 { 569 union { 570 at_entry_t _atio; 571 at2_entry_t _atio2; 572 at2e_entry_t _atio2e; 573 } atun; 574 575 MEMZERO(&atun, sizeof atun); 576 if (IS_FC(isp)) { 577 at2_entry_t *aep = arg; 578 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2; 579 atun._atio2.at_header.rqs_entry_count = 1; 580 if (FCPARAM(isp)->isp_sccfw) { 581 atun._atio2.at_scclun = aep->at_scclun; 582 } else { 583 atun._atio2.at_lun = (uint8_t) aep->at_lun; 584 } 585 if (FCPARAM(isp)->isp_2klogin) { 586 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid; 587 } else { 588 atun._atio2.at_iid = aep->at_iid; 589 } 590 atun._atio2.at_rxid = aep->at_rxid; 591 atun._atio2.at_status = CT_OK; 592 } else { 593 at_entry_t *aep = arg; 594 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO; 595 atun._atio.at_header.rqs_entry_count = 1; 596 atun._atio.at_handle = aep->at_handle; 597 atun._atio.at_iid = aep->at_iid; 598 atun._atio.at_tgt = aep->at_tgt; 599 atun._atio.at_lun = aep->at_lun; 600 atun._atio.at_tag_type = aep->at_tag_type; 601 atun._atio.at_tag_val = aep->at_tag_val; 602 atun._atio.at_status = (aep->at_flags & AT_TQAE); 603 atun._atio.at_status |= CT_OK; 604 } 605 return (isp_target_put_entry(isp, &atun)); 606 } 607 608 /* 609 * Command completion- both for handling cases of no resources or 610 * no blackhole driver, or other cases where we have to, inline, 611 * finish the command sanely, or for normal command completion. 612 * 613 * The 'completion' code value has the scsi status byte in the low 8 bits. 614 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have 615 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC 616 * values. 617 * 618 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't 619 * NB: inline SCSI sense reporting. As such, we lose this information. XXX. 620 * 621 * For both parallel && fibre channel, we use the feature that does 622 * an automatic resource autoreplenish so we don't have then later do 623 * put of an atio to replenish the f/w's resource count. 624 */ 625 626 int 627 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint32_t hdl) 628 { 629 int sts; 630 union { 631 ct_entry_t _ctio; 632 ct2_entry_t _ctio2; 633 ct2e_entry_t _ctio2e; 634 ct7_entry_t _ctio7; 635 } un; 636 637 MEMZERO(&un, sizeof un); 638 sts = code & 0xff; 639 640 if (IS_24XX(isp)) { 641 at7_entry_t *aep = arg; 642 ct7_entry_t *cto = &un._ctio7; 643 644 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 645 cto->ct_header.rqs_entry_count = 1; 646 /* XXXX */ cto->ct_nphdl = aep->at_hdr.seq_id; 647 cto->ct_rxid = aep->at_rxid; 648 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | 649 aep->at_hdr.s_id[2]; 650 cto->ct_iid_hi = aep->at_hdr.s_id[0]; 651 cto->ct_oxid = aep->at_hdr.ox_id; 652 cto->ct_scsi_status = sts; 653 cto->ct_flags = CT7_FLAG_MODE1 | CT7_NO_DATA | CT7_SENDSTATUS; 654 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) { 655 cto->rsp.m1.ct_resplen = 16; 656 cto->rsp.m1.ct_resp[0] = 0xf0; 657 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 658 cto->rsp.m1.ct_resp[7] = 8; 659 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 660 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 661 } 662 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) { 663 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl; 664 cto->ct_scsi_status |= CT2_DATA_UNDER; 665 } 666 cto->ct_syshandle = hdl; 667 } else if (IS_FC(isp)) { 668 at2_entry_t *aep = arg; 669 ct2_entry_t *cto = &un._ctio2; 670 671 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 672 cto->ct_header.rqs_entry_count = 1; 673 if (FCPARAM(isp)->isp_sccfw == 0) { 674 cto->ct_lun = aep->at_lun; 675 } 676 if (FCPARAM(isp)->isp_2klogin) { 677 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid; 678 } else { 679 cto->ct_iid = aep->at_iid; 680 } 681 cto->ct_rxid = aep->at_rxid; 682 cto->rsp.m1.ct_scsi_status = sts; 683 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1; 684 if (hdl == 0) { 685 cto->ct_flags |= CT2_CCINCR; 686 } 687 if (aep->at_datalen) { 688 cto->ct_resid = aep->at_datalen; 689 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER; 690 } 691 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) { 692 cto->rsp.m1.ct_resp[0] = 0xf0; 693 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 694 cto->rsp.m1.ct_resp[7] = 8; 695 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 696 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 697 cto->rsp.m1.ct_senselen = 16; 698 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID; 699 } 700 cto->ct_syshandle = hdl; 701 } else { 702 at_entry_t *aep = arg; 703 ct_entry_t *cto = &un._ctio; 704 705 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO; 706 cto->ct_header.rqs_entry_count = 1; 707 cto->ct_fwhandle = aep->at_handle; 708 cto->ct_iid = aep->at_iid; 709 cto->ct_tgt = aep->at_tgt; 710 cto->ct_lun = aep->at_lun; 711 cto->ct_tag_type = aep->at_tag_type; 712 cto->ct_tag_val = aep->at_tag_val; 713 if (aep->at_flags & AT_TQAE) { 714 cto->ct_flags |= CT_TQAE; 715 } 716 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA; 717 if (hdl == 0) { 718 cto->ct_flags |= CT_CCINCR; 719 } 720 cto->ct_scsi_status = sts; 721 cto->ct_syshandle = hdl; 722 } 723 return (isp_target_put_entry(isp, &un)); 724 } 725 726 /* 727 * These are either broadcast events or specifically CTIO fast completion 728 */ 729 int 730 isp_target_async(ispsoftc_t *isp, int bus, int event) 731 { 732 tmd_notify_t notify; 733 734 MEMZERO(¬ify, sizeof (tmd_notify_t)); 735 notify.nt_hba = isp; 736 notify.nt_iid = INI_ANY; 737 /* nt_tgt set in outer layers */ 738 notify.nt_lun = LUN_ANY; 739 notify.nt_tagval = TAG_ANY; 740 741 if (IS_SCSI(isp)) { 742 TAG_INSERT_BUS(notify.nt_tagval, bus); 743 } 744 745 switch (event) { 746 case ASYNC_LOOP_UP: 747 case ASYNC_PTPMODE: 748 notify.nt_ncode = NT_LINK_UP; 749 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 750 break; 751 case ASYNC_LOOP_DOWN: 752 notify.nt_ncode = NT_LINK_DOWN; 753 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 754 break; 755 case ASYNC_LIP_ERROR: 756 case ASYNC_LIP_F8: 757 case ASYNC_LIP_OCCURRED: 758 case ASYNC_LOOP_RESET: 759 notify.nt_ncode = NT_LIP_RESET; 760 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 761 break; 762 case ASYNC_BUS_RESET: 763 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */ 764 notify.nt_ncode = NT_BUS_RESET; 765 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 766 break; 767 case ASYNC_DEVICE_RESET: 768 notify.nt_ncode = NT_TARGET_RESET; 769 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 770 break; 771 case ASYNC_CTIO_DONE: 772 { 773 uint8_t storage[QENTRY_LEN]; 774 memset(storage, 0, QENTRY_LEN); 775 if (IS_24XX(isp)) { 776 ct7_entry_t *ct = (ct7_entry_t *) storage; 777 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 778 ct->ct_nphdl = CT7_OK; 779 ct->ct_syshandle = bus; 780 ct->ct_flags = CT7_SENDSTATUS|CT7_FASTPOST; 781 } else if (IS_FC(isp)) { 782 /* This should also suffice for 2K login code */ 783 ct2_entry_t *ct = (ct2_entry_t *) storage; 784 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 785 ct->ct_status = CT_OK; 786 ct->ct_syshandle = bus; 787 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST; 788 } else { 789 ct_entry_t *ct = (ct_entry_t *) storage; 790 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO; 791 ct->ct_status = CT_OK; 792 ct->ct_fwhandle = bus; 793 ct->ct_flags = CT_SENDSTATUS; 794 } 795 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage); 796 break; 797 } 798 default: 799 isp_prt(isp, ISP_LOGERR, 800 "isp_target_async: unknown event 0x%x", event); 801 if (isp->isp_state == ISP_RUNSTATE) { 802 isp_notify_ack(isp, NULL); 803 } 804 break; 805 } 806 return (0); 807 } 808 809 810 /* 811 * Process a received message. 812 * The ISP firmware can handle most messages, there are only 813 * a few that we need to deal with: 814 * - abort: clean up the current command 815 * - abort tag and clear queue 816 */ 817 818 static void 819 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp) 820 { 821 tmd_notify_t nt; 822 uint8_t status = inp->in_status & ~QLTM_SVALID; 823 824 MEMZERO(&nt, sizeof (nt)); 825 nt.nt_hba = isp; 826 nt.nt_iid = GET_IID_VAL(inp->in_iid); 827 nt.nt_tgt = inp->in_tgt; 828 nt.nt_lun = inp->in_lun; 829 IN_MAKE_TAGID(nt.nt_tagval, 0, inp); 830 nt.nt_lreserved = inp; 831 832 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) { 833 switch (inp->in_msg[0]) { 834 case MSG_ABORT: 835 nt.nt_ncode = NT_ABORT_TASK_SET; 836 break; 837 case MSG_BUS_DEV_RESET: 838 nt.nt_ncode = NT_TARGET_RESET; 839 break; 840 case MSG_ABORT_TAG: 841 nt.nt_ncode = NT_ABORT_TASK; 842 break; 843 case MSG_CLEAR_QUEUE: 844 nt.nt_ncode = NT_CLEAR_TASK_SET; 845 break; 846 case MSG_REL_RECOVERY: 847 nt.nt_ncode = NT_CLEAR_ACA; 848 break; 849 case MSG_TERM_IO_PROC: 850 nt.nt_ncode = NT_ABORT_TASK; 851 break; 852 case MSG_LUN_RESET: 853 nt.nt_ncode = NT_LUN_RESET; 854 break; 855 default: 856 isp_prt(isp, ISP_LOGERR, 857 "unhandled message 0x%x", inp->in_msg[0]); 858 isp_notify_ack(isp, inp); 859 return; 860 } 861 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 862 } else { 863 isp_prt(isp, ISP_LOGERR, 864 "unknown immediate notify status 0x%x", inp->in_status); 865 isp_notify_ack(isp, inp); 866 } 867 } 868 869 /* 870 * Synthesize a message from the task management flags in a FCP_CMND_IU. 871 */ 872 static void 873 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp) 874 { 875 tmd_notify_t nt; 876 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x"; 877 static const char f2[] = 878 "unknown %s 0x%x lun %d N-Port handle 0x%x task flags 0x%x seq 0x%x\n"; 879 uint16_t seqid, loopid; 880 881 MEMZERO(&nt, sizeof (tmd_notify_t)); 882 nt.nt_hba = isp; 883 if (FCPARAM(isp)->isp_2klogin) { 884 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid; 885 loopid = ((in_fcentry_e_t *)inp)->in_iid; 886 seqid = ((in_fcentry_e_t *)inp)->in_seqid; 887 } else { 888 nt.nt_iid = inp->in_iid; 889 loopid = inp->in_iid; 890 seqid = inp->in_seqid; 891 } 892 /* nt_tgt set in outer layers */ 893 if (FCPARAM(isp)->isp_sccfw) { 894 nt.nt_lun = inp->in_scclun; 895 } else { 896 nt.nt_lun = inp->in_lun; 897 } 898 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, seqid); 899 nt.nt_need_ack = 1; 900 nt.nt_lreserved = inp; 901 902 if (inp->in_status != IN_MSG_RECEIVED) { 903 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status", 904 inp->in_status, nt.nt_lun, loopid, inp->in_task_flags, 905 inp->in_seqid); 906 isp_notify_ack(isp, inp); 907 return; 908 } 909 910 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) { 911 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", 912 loopid, nt.nt_lun, inp->in_seqid); 913 nt.nt_ncode = NT_ABORT_TASK_SET; 914 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) { 915 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", 916 loopid, nt.nt_lun, inp->in_seqid); 917 nt.nt_ncode = NT_CLEAR_TASK_SET; 918 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) { 919 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", 920 loopid, nt.nt_lun, inp->in_seqid); 921 nt.nt_ncode = NT_LUN_RESET; 922 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) { 923 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", 924 loopid, nt.nt_lun, inp->in_seqid); 925 nt.nt_ncode = NT_TARGET_RESET; 926 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) { 927 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", 928 loopid, nt.nt_lun, inp->in_seqid); 929 nt.nt_ncode = NT_CLEAR_ACA; 930 } else { 931 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status, 932 nt.nt_lun, loopid, inp->in_task_flags, inp->in_seqid); 933 isp_notify_ack(isp, inp); 934 return; 935 } 936 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 937 } 938 939 static void 940 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep) 941 { 942 tmd_notify_t nt; 943 static const char f1[] = "%s from PortID 0x%06x lun %d seq 0x%x"; 944 static const char f2[] = 945 "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%x\n"; 946 uint32_t sid; 947 948 MEMZERO(&nt, sizeof (tmd_notify_t)); 949 nt.nt_hba = isp; 950 nt.nt_iid = INI_ANY; 951 nt.nt_lun = 952 (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | 953 (aep->at_cmnd.fcp_cmnd_lun[1]); 954 nt.nt_tagval = aep->at_rxid; 955 nt.nt_lreserved = aep; 956 sid = 957 (aep->at_hdr.s_id[0] << 16) | 958 (aep->at_hdr.s_id[1] << 8) | 959 (aep->at_hdr.s_id[2]); 960 961 if (aep->at_cmnd.fcp_cmnd_task_management & 962 FCP_CMND_TMF_ABORT_TASK_SET) { 963 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", 964 sid, nt.nt_lun, nt.nt_tagval); 965 nt.nt_ncode = NT_ABORT_TASK_SET; 966 } else if (aep->at_cmnd.fcp_cmnd_task_management & 967 FCP_CMND_TMF_CLEAR_TASK_SET) { 968 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", 969 sid, nt.nt_lun, nt.nt_tagval); 970 nt.nt_ncode = NT_CLEAR_TASK_SET; 971 } else if (aep->at_cmnd.fcp_cmnd_task_management & 972 FCP_CMND_TMF_LUN_RESET) { 973 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", 974 sid, nt.nt_lun, nt.nt_tagval); 975 nt.nt_ncode = NT_LUN_RESET; 976 } else if (aep->at_cmnd.fcp_cmnd_task_management & 977 FCP_CMND_TMF_TGT_RESET) { 978 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", 979 sid, nt.nt_lun, nt.nt_tagval); 980 nt.nt_ncode = NT_TARGET_RESET; 981 nt.nt_lun = LUN_ANY; 982 } else if (aep->at_cmnd.fcp_cmnd_task_management & 983 FCP_CMND_TMF_CLEAR_ACA) { 984 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", 985 sid, nt.nt_lun, nt.nt_tagval); 986 nt.nt_ncode = NT_CLEAR_ACA; 987 } else { 988 isp_prt(isp, ISP_LOGWARN, f2, 989 aep->at_cmnd.fcp_cmnd_task_management, 990 nt.nt_lun, sid, nt.nt_tagval); 991 isp_endcmd(isp, aep, 0, 0); 992 return; 993 } 994 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 995 } 996 997 void 998 isp_notify_ack(ispsoftc_t *isp, void *arg) 999 { 1000 char storage[QENTRY_LEN]; 1001 uint32_t nxti, optr; 1002 void *outp; 1003 1004 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 1005 isp_prt(isp, ISP_LOGWARN, 1006 "Request Queue Overflow For isp_notify_ack"); 1007 return; 1008 } 1009 1010 MEMZERO(storage, QENTRY_LEN); 1011 1012 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) { 1013 at7_entry_t *aep = arg; 1014 isp_endcmd(isp, aep, 0, 0); 1015 return; 1016 } else if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ABTS_RSP)) { 1017 abts_rsp_t *abts_rsp = (abts_rsp_t *) storage; 1018 /* 1019 * The caller will have set response values as appropriate 1020 * in the ABTS structure just before calling us. 1021 */ 1022 MEMCPY(abts_rsp, arg, QENTRY_LEN); 1023 isp_put_abts_rsp(isp, abts_rsp, (abts_rsp_t *)outp); 1024 } else if (IS_24XX(isp)) { 1025 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage; 1026 if (arg) { 1027 in_fcentry_24xx_t *in = arg; 1028 na->na_nphdl = in->in_nphdl; 1029 na->na_status = in->in_status; 1030 na->na_status_subcode = in->in_status_subcode; 1031 na->na_rxid = in->in_rxid; 1032 na->na_oxid = in->in_oxid; 1033 if (in->in_status == IN24XX_SRR_RCVD) { 1034 na->na_srr_rxid = in->in_srr_rxid; 1035 na->na_srr_reloff_hi = in->in_srr_reloff_hi; 1036 na->na_srr_reloff_lo = in->in_srr_reloff_lo; 1037 na->na_srr_iu = in->in_srr_iu; 1038 na->na_srr_flags = 1; 1039 na->na_srr_reject_vunique = 0; 1040 na->na_srr_reject_explanation = 1; 1041 na->na_srr_reject_code = 1; 1042 } 1043 } 1044 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1045 na->na_header.rqs_entry_count = 1; 1046 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp); 1047 } else if (IS_FC(isp)) { 1048 na_fcentry_t *na = (na_fcentry_t *) storage; 1049 int iid = 0; 1050 1051 if (arg) { 1052 in_fcentry_t *inp = arg; 1053 MEMCPY(storage, arg, sizeof (isphdr_t)); 1054 if (FCPARAM(isp)->isp_2klogin) { 1055 ((na_fcentry_e_t *)na)->na_iid = 1056 ((in_fcentry_e_t *)inp)->in_iid; 1057 iid = ((na_fcentry_e_t *)na)->na_iid; 1058 } else { 1059 na->na_iid = inp->in_iid; 1060 iid = na->na_iid; 1061 } 1062 na->na_task_flags = 1063 inp->in_task_flags & TASK_FLAGS_RESERVED_MASK; 1064 na->na_seqid = inp->in_seqid; 1065 na->na_flags = NAFC_RCOUNT; 1066 na->na_status = inp->in_status; 1067 if (inp->in_status == IN_RESET) { 1068 na->na_flags |= NAFC_RST_CLRD; 1069 } 1070 if (inp->in_status == IN_MSG_RECEIVED) { 1071 na->na_flags |= NAFC_TVALID; 1072 na->na_response = 0; /* XXX SUCCEEDED XXX */ 1073 } 1074 } else { 1075 na->na_flags = NAFC_RST_CLRD; 1076 } 1077 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1078 na->na_header.rqs_entry_count = 1; 1079 if (FCPARAM(isp)->isp_2klogin) { 1080 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, 1081 (na_fcentry_e_t *)outp); 1082 } else { 1083 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp); 1084 } 1085 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x " 1086 "flags %x tflags %x response %x", iid, na->na_seqid, 1087 na->na_flags, na->na_task_flags, na->na_response); 1088 } else { 1089 na_entry_t *na = (na_entry_t *) storage; 1090 if (arg) { 1091 in_entry_t *inp = arg; 1092 MEMCPY(storage, arg, sizeof (isphdr_t)); 1093 na->na_iid = inp->in_iid; 1094 na->na_lun = inp->in_lun; 1095 na->na_tgt = inp->in_tgt; 1096 na->na_seqid = inp->in_seqid; 1097 if (inp->in_status == IN_RESET) { 1098 na->na_event = NA_RST_CLRD; 1099 } 1100 } else { 1101 na->na_event = NA_RST_CLRD; 1102 } 1103 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1104 na->na_header.rqs_entry_count = 1; 1105 isp_put_notify_ack(isp, na, (na_entry_t *)outp); 1106 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt " 1107 "%u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt, 1108 na->na_seqid, na->na_event); 1109 } 1110 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage); 1111 ISP_ADD_REQUEST(isp, nxti); 1112 } 1113 1114 static void 1115 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep) 1116 { 1117 int lun; 1118 lun = aep->at_lun; 1119 /* 1120 * The firmware status (except for the QLTM_SVALID bit) indicates 1121 * why this ATIO was sent to us. 1122 * 1123 * If QLTM_SVALID is set, the firware has recommended Sense Data. 1124 * 1125 * If the DISCONNECTS DISABLED bit is set in the flags field, 1126 * we're still connected on the SCSI bus - i.e. the initiator 1127 * did not set DiscPriv in the identify message. We don't care 1128 * about this so it's ignored. 1129 */ 1130 1131 switch(aep->at_status & ~QLTM_SVALID) { 1132 case AT_PATH_INVALID: 1133 /* 1134 * ATIO rejected by the firmware due to disabled lun. 1135 */ 1136 isp_prt(isp, ISP_LOGERR, 1137 "rejected ATIO for disabled lun %d", lun); 1138 break; 1139 case AT_NOCAP: 1140 /* 1141 * Requested Capability not available 1142 * We sent an ATIO that overflowed the firmware's 1143 * command resource count. 1144 */ 1145 isp_prt(isp, ISP_LOGERR, 1146 "rejected ATIO for lun %d because of command count" 1147 " overflow", lun); 1148 break; 1149 1150 case AT_BDR_MSG: 1151 /* 1152 * If we send an ATIO to the firmware to increment 1153 * its command resource count, and the firmware is 1154 * recovering from a Bus Device Reset, it returns 1155 * the ATIO with this status. We set the command 1156 * resource count in the Enable Lun entry and do 1157 * not increment it. Therefore we should never get 1158 * this status here. 1159 */ 1160 isp_prt(isp, ISP_LOGERR, atiocope, lun, 1161 GET_BUS_VAL(aep->at_iid)); 1162 break; 1163 1164 case AT_CDB: /* Got a CDB */ 1165 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */ 1166 /* 1167 * Punt to platform specific layer. 1168 */ 1169 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1170 break; 1171 1172 case AT_RESET: 1173 /* 1174 * A bus reset came along and blew away this command. Why 1175 * they do this in addition the async event code stuff, 1176 * I dunno. 1177 * 1178 * Ignore it because the async event will clear things 1179 * up for us. 1180 */ 1181 isp_prt(isp, ISP_LOGWARN, atior, lun, 1182 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid)); 1183 break; 1184 1185 1186 default: 1187 isp_prt(isp, ISP_LOGERR, 1188 "Unknown ATIO status 0x%x from loopid %d for lun %d", 1189 aep->at_status, aep->at_iid, lun); 1190 (void) isp_target_put_atio(isp, aep); 1191 break; 1192 } 1193 } 1194 1195 static void 1196 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep) 1197 { 1198 int lun, iid; 1199 1200 if (FCPARAM(isp)->isp_sccfw) { 1201 lun = aep->at_scclun; 1202 } else { 1203 lun = aep->at_lun; 1204 } 1205 1206 if (FCPARAM(isp)->isp_2klogin) { 1207 iid = ((at2e_entry_t *)aep)->at_iid; 1208 } else { 1209 iid = aep->at_iid; 1210 } 1211 1212 /* 1213 * The firmware status (except for the QLTM_SVALID bit) indicates 1214 * why this ATIO was sent to us. 1215 * 1216 * If QLTM_SVALID is set, the firware has recommended Sense Data. 1217 * 1218 * If the DISCONNECTS DISABLED bit is set in the flags field, 1219 * we're still connected on the SCSI bus - i.e. the initiator 1220 * did not set DiscPriv in the identify message. We don't care 1221 * about this so it's ignored. 1222 */ 1223 1224 switch(aep->at_status & ~QLTM_SVALID) { 1225 case AT_PATH_INVALID: 1226 /* 1227 * ATIO rejected by the firmware due to disabled lun. 1228 */ 1229 isp_prt(isp, ISP_LOGERR, 1230 "rejected ATIO2 for disabled lun %d", lun); 1231 break; 1232 case AT_NOCAP: 1233 /* 1234 * Requested Capability not available 1235 * We sent an ATIO that overflowed the firmware's 1236 * command resource count. 1237 */ 1238 isp_prt(isp, ISP_LOGERR, 1239 "rejected ATIO2 for lun %d- command count overflow", lun); 1240 break; 1241 1242 case AT_BDR_MSG: 1243 /* 1244 * If we send an ATIO to the firmware to increment 1245 * its command resource count, and the firmware is 1246 * recovering from a Bus Device Reset, it returns 1247 * the ATIO with this status. We set the command 1248 * resource count in the Enable Lun entry and no 1249 * not increment it. Therefore we should never get 1250 * this status here. 1251 */ 1252 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0); 1253 break; 1254 1255 case AT_CDB: /* Got a CDB */ 1256 /* 1257 * Punt to platform specific layer. 1258 */ 1259 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1260 break; 1261 1262 case AT_RESET: 1263 /* 1264 * A bus reset came along an blew away this command. Why 1265 * they do this in addition the async event code stuff, 1266 * I dunno. 1267 * 1268 * Ignore it because the async event will clear things 1269 * up for us. 1270 */ 1271 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0); 1272 break; 1273 1274 1275 default: 1276 isp_prt(isp, ISP_LOGERR, 1277 "Unknown ATIO2 status 0x%x from loopid %d for lun %d", 1278 aep->at_status, iid, lun); 1279 (void) isp_target_put_atio(isp, aep); 1280 break; 1281 } 1282 } 1283 1284 static void 1285 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct) 1286 { 1287 void *xs; 1288 int pl = ISP_LOGTDEBUG2; 1289 char *fmsg = NULL; 1290 1291 if (ct->ct_syshandle) { 1292 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1293 if (xs == NULL) { 1294 pl = ISP_LOGALL; 1295 } 1296 } else { 1297 xs = NULL; 1298 } 1299 1300 switch(ct->ct_status & ~QLTM_SVALID) { 1301 case CT_OK: 1302 /* 1303 * There are generally 3 possibilities as to why we'd get 1304 * this condition: 1305 * We disconnected after receiving a CDB. 1306 * We sent or received data. 1307 * We sent status & command complete. 1308 */ 1309 1310 if (ct->ct_flags & CT_SENDSTATUS) { 1311 break; 1312 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) { 1313 /* 1314 * Nothing to do in this case. 1315 */ 1316 isp_prt(isp, pl, "CTIO- iid %d disconnected OK", 1317 ct->ct_iid); 1318 return; 1319 } 1320 break; 1321 1322 case CT_BDR_MSG: 1323 /* 1324 * Bus Device Reset message received or the SCSI Bus has 1325 * been Reset; the firmware has gone to Bus Free. 1326 * 1327 * The firmware generates an async mailbox interupt to 1328 * notify us of this and returns outstanding CTIOs with this 1329 * status. These CTIOs are handled in that same way as 1330 * CT_ABORTED ones, so just fall through here. 1331 */ 1332 fmsg = "Bus Device Reset"; 1333 /*FALLTHROUGH*/ 1334 case CT_RESET: 1335 if (fmsg == NULL) 1336 fmsg = "Bus Reset"; 1337 /*FALLTHROUGH*/ 1338 case CT_ABORTED: 1339 /* 1340 * When an Abort message is received the firmware goes to 1341 * Bus Free and returns all outstanding CTIOs with the status 1342 * set, then sends us an Immediate Notify entry. 1343 */ 1344 if (fmsg == NULL) 1345 fmsg = "ABORT TAG message sent by Initiator"; 1346 1347 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg); 1348 break; 1349 1350 case CT_INVAL: 1351 /* 1352 * CTIO rejected by the firmware due to disabled lun. 1353 * "Cannot Happen". 1354 */ 1355 isp_prt(isp, ISP_LOGERR, 1356 "Firmware rejected CTIO for disabled lun %d", 1357 ct->ct_lun); 1358 break; 1359 1360 case CT_NOPATH: 1361 /* 1362 * CTIO rejected by the firmware due "no path for the 1363 * nondisconnecting nexus specified". This means that 1364 * we tried to access the bus while a non-disconnecting 1365 * command is in process. 1366 */ 1367 isp_prt(isp, ISP_LOGERR, 1368 "Firmware rejected CTIO for bad nexus %d/%d/%d", 1369 ct->ct_iid, ct->ct_tgt, ct->ct_lun); 1370 break; 1371 1372 case CT_RSELTMO: 1373 fmsg = "Reselection"; 1374 /*FALLTHROUGH*/ 1375 case CT_TIMEOUT: 1376 if (fmsg == NULL) 1377 fmsg = "Command"; 1378 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1379 break; 1380 1381 case CT_PANIC: 1382 if (fmsg == NULL) 1383 fmsg = "Unrecoverable Error"; 1384 /*FALLTHROUGH*/ 1385 case CT_ERR: 1386 if (fmsg == NULL) 1387 fmsg = "Completed with Error"; 1388 /*FALLTHROUGH*/ 1389 case CT_PHASE_ERROR: 1390 if (fmsg == NULL) 1391 fmsg = "Phase Sequence Error"; 1392 /*FALLTHROUGH*/ 1393 case CT_TERMINATED: 1394 if (fmsg == NULL) 1395 fmsg = "terminated by TERMINATE TRANSFER"; 1396 /*FALLTHROUGH*/ 1397 case CT_NOACK: 1398 if (fmsg == NULL) 1399 fmsg = "unacknowledged Immediate Notify pending"; 1400 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg); 1401 break; 1402 default: 1403 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x", 1404 ct->ct_status & ~QLTM_SVALID); 1405 break; 1406 } 1407 1408 if (xs == NULL) { 1409 /* 1410 * There may be more than one CTIO for a data transfer, 1411 * or this may be a status CTIO we're not monitoring. 1412 * 1413 * The assumption is that they'll all be returned in the 1414 * order we got them. 1415 */ 1416 if (ct->ct_syshandle == 0) { 1417 if ((ct->ct_flags & CT_SENDSTATUS) == 0) { 1418 isp_prt(isp, pl, 1419 "intermediate CTIO completed ok"); 1420 } else { 1421 isp_prt(isp, pl, 1422 "unmonitored CTIO completed ok"); 1423 } 1424 } else { 1425 isp_prt(isp, pl, 1426 "NO xs for CTIO (handle 0x%x) status 0x%x", 1427 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1428 } 1429 } else { 1430 /* 1431 * Final CTIO completed. Release DMA resources and 1432 * notify platform dependent layers. 1433 */ 1434 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) { 1435 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1436 } 1437 isp_prt(isp, pl, "final CTIO complete"); 1438 /* 1439 * The platform layer will destroy the handle if appropriate. 1440 */ 1441 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1442 } 1443 } 1444 1445 static void 1446 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct) 1447 { 1448 void *xs; 1449 int pl = ISP_LOGTDEBUG2; 1450 char *fmsg = NULL; 1451 1452 if (ct->ct_syshandle) { 1453 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1454 if (xs == NULL) { 1455 pl = ISP_LOGALL; 1456 } 1457 } else { 1458 xs = NULL; 1459 } 1460 1461 switch(ct->ct_status & ~QLTM_SVALID) { 1462 case CT_BUS_ERROR: 1463 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 1464 /* FALL Through */ 1465 case CT_DATA_OVER: 1466 case CT_DATA_UNDER: 1467 case CT_OK: 1468 /* 1469 * There are generally 2 possibilities as to why we'd get 1470 * this condition: 1471 * We sent or received data. 1472 * We sent status & command complete. 1473 */ 1474 1475 break; 1476 1477 case CT_BDR_MSG: 1478 /* 1479 * Target Reset function received. 1480 * 1481 * The firmware generates an async mailbox interupt to 1482 * notify us of this and returns outstanding CTIOs with this 1483 * status. These CTIOs are handled in that same way as 1484 * CT_ABORTED ones, so just fall through here. 1485 */ 1486 fmsg = "TARGET RESET"; 1487 /*FALLTHROUGH*/ 1488 case CT_RESET: 1489 if (fmsg == NULL) 1490 fmsg = "LIP Reset"; 1491 /*FALLTHROUGH*/ 1492 case CT_ABORTED: 1493 /* 1494 * When an Abort message is received the firmware goes to 1495 * Bus Free and returns all outstanding CTIOs with the status 1496 * set, then sends us an Immediate Notify entry. 1497 */ 1498 if (fmsg == NULL) { 1499 fmsg = "ABORT"; 1500 } 1501 1502 isp_prt(isp, ISP_LOGTDEBUG0, 1503 "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 1504 break; 1505 1506 case CT_INVAL: 1507 /* 1508 * CTIO rejected by the firmware - invalid data direction. 1509 */ 1510 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction"); 1511 break; 1512 1513 case CT_RSELTMO: 1514 fmsg = "failure to reconnect to initiator"; 1515 /*FALLTHROUGH*/ 1516 case CT_TIMEOUT: 1517 if (fmsg == NULL) 1518 fmsg = "command"; 1519 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1520 break; 1521 1522 case CT_ERR: 1523 fmsg = "Completed with Error"; 1524 /*FALLTHROUGH*/ 1525 case CT_LOGOUT: 1526 if (fmsg == NULL) 1527 fmsg = "Port Logout"; 1528 /*FALLTHROUGH*/ 1529 case CT_PORTUNAVAIL: 1530 if (fmsg == NULL) 1531 fmsg = "Port not available"; 1532 /*FALLTHROUGH*/ 1533 case CT_PORTCHANGED: 1534 if (fmsg == NULL) 1535 fmsg = "Port Changed"; 1536 /*FALLTHROUGH*/ 1537 case CT_NOACK: 1538 if (fmsg == NULL) 1539 fmsg = "unacknowledged Immediate Notify pending"; 1540 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 1541 break; 1542 1543 case CT_INVRXID: 1544 /* 1545 * CTIO rejected by the firmware because an invalid RX_ID. 1546 * Just print a message. 1547 */ 1548 isp_prt(isp, ISP_LOGWARN, 1549 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 1550 break; 1551 1552 default: 1553 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x", 1554 ct->ct_status & ~QLTM_SVALID); 1555 break; 1556 } 1557 1558 if (xs == NULL) { 1559 /* 1560 * There may be more than one CTIO for a data transfer, 1561 * or this may be a status CTIO we're not monitoring. 1562 * 1563 * The assumption is that they'll all be returned in the 1564 * order we got them. 1565 */ 1566 if (ct->ct_syshandle == 0) { 1567 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) { 1568 isp_prt(isp, pl, 1569 "intermediate CTIO completed ok"); 1570 } else { 1571 isp_prt(isp, pl, 1572 "unmonitored CTIO completed ok"); 1573 } 1574 } else { 1575 isp_prt(isp, pl, 1576 "NO xs for CTIO (handle 0x%x) status 0x%x", 1577 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1578 } 1579 } else { 1580 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 1581 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1582 } 1583 if (ct->ct_flags & CT2_SENDSTATUS) { 1584 /* 1585 * Sent status and command complete. 1586 * 1587 * We're now really done with this command, so we 1588 * punt to the platform dependent layers because 1589 * only there can we do the appropriate command 1590 * complete thread synchronization. 1591 */ 1592 isp_prt(isp, pl, "status CTIO complete"); 1593 } else { 1594 /* 1595 * Final CTIO completed. Release DMA resources and 1596 * notify platform dependent layers. 1597 */ 1598 isp_prt(isp, pl, "data CTIO complete"); 1599 } 1600 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1601 /* 1602 * The platform layer will destroy the handle if appropriate. 1603 */ 1604 } 1605 } 1606 1607 static void 1608 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct) 1609 { 1610 void *xs; 1611 int pl = ISP_LOGTDEBUG2; 1612 char *fmsg = NULL; 1613 1614 if (ct->ct_syshandle) { 1615 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1616 if (xs == NULL) { 1617 pl = ISP_LOGALL; 1618 } 1619 } else { 1620 xs = NULL; 1621 } 1622 1623 switch(ct->ct_nphdl) { 1624 case CT7_BUS_ERROR: 1625 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 1626 /* FALL Through */ 1627 case CT7_DATA_OVER: 1628 case CT7_DATA_UNDER: 1629 case CT7_OK: 1630 /* 1631 * There are generally 2 possibilities as to why we'd get 1632 * this condition: 1633 * We sent or received data. 1634 * We sent status & command complete. 1635 */ 1636 1637 break; 1638 1639 case CT7_RESET: 1640 if (fmsg == NULL) { 1641 fmsg = "LIP Reset"; 1642 } 1643 /*FALLTHROUGH*/ 1644 case CT7_ABORTED: 1645 /* 1646 * When an Abort message is received the firmware goes to 1647 * Bus Free and returns all outstanding CTIOs with the status 1648 * set, then sends us an Immediate Notify entry. 1649 */ 1650 if (fmsg == NULL) { 1651 fmsg = "ABORT"; 1652 } 1653 isp_prt(isp, ISP_LOGTDEBUG0, 1654 "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 1655 break; 1656 1657 case CT7_TIMEOUT: 1658 if (fmsg == NULL) { 1659 fmsg = "command"; 1660 } 1661 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1662 break; 1663 1664 case CT7_ERR: 1665 fmsg = "Completed with Error"; 1666 /*FALLTHROUGH*/ 1667 case CT7_LOGOUT: 1668 if (fmsg == NULL) { 1669 fmsg = "Port Logout"; 1670 } 1671 /*FALLTHROUGH*/ 1672 case CT7_PORTUNAVAIL: 1673 if (fmsg == NULL) { 1674 fmsg = "Port not available"; 1675 } 1676 /*FALLTHROUGH*/ 1677 case CT7_PORTCHANGED: 1678 if (fmsg == NULL) { 1679 fmsg = "Port Changed"; 1680 } 1681 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 1682 break; 1683 1684 case CT7_INVRXID: 1685 /* 1686 * CTIO rejected by the firmware because an invalid RX_ID. 1687 * Just print a message. 1688 */ 1689 isp_prt(isp, ISP_LOGWARN, 1690 "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 1691 break; 1692 1693 case CT7_REASSY_ERR: 1694 isp_prt(isp, ISP_LOGWARN, "reassembly error"); 1695 break; 1696 1697 case CT7_SRR: 1698 isp_prt(isp, ISP_LOGWARN, "SRR received"); 1699 break; 1700 1701 default: 1702 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", 1703 ct->ct_nphdl); 1704 break; 1705 } 1706 1707 if (xs == NULL) { 1708 /* 1709 * There may be more than one CTIO for a data transfer, 1710 * or this may be a status CTIO we're not monitoring. 1711 * 1712 * The assumption is that they'll all be returned in the 1713 * order we got them. 1714 */ 1715 if (ct->ct_syshandle == 0) { 1716 if (ct->ct_flags & CT7_TERMINATE) { 1717 isp_prt(isp, ISP_LOGINFO, 1718 "termination of 0x%x complete", 1719 ct->ct_rxid); 1720 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) { 1721 isp_prt(isp, pl, 1722 "intermediate CTIO completed ok"); 1723 } else { 1724 isp_prt(isp, pl, 1725 "unmonitored CTIO completed ok"); 1726 } 1727 } else { 1728 isp_prt(isp, pl, 1729 "NO xs for CTIO (handle 0x%x) status 0x%x", 1730 ct->ct_syshandle, ct->ct_nphdl); 1731 } 1732 } else { 1733 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 1734 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1735 } 1736 if (ct->ct_flags & CT2_SENDSTATUS) { 1737 /* 1738 * Sent status and command complete. 1739 * 1740 * We're now really done with this command, so we 1741 * punt to the platform dependent layers because 1742 * only there can we do the appropriate command 1743 * complete thread synchronization. 1744 */ 1745 isp_prt(isp, pl, "status CTIO complete"); 1746 } else { 1747 /* 1748 * Final CTIO completed. Release DMA resources and 1749 * notify platform dependent layers. 1750 */ 1751 isp_prt(isp, pl, "data CTIO complete"); 1752 } 1753 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1754 /* 1755 * The platform layer will destroy the handle if appropriate. 1756 */ 1757 } 1758 } 1759 #endif 1760