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