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 el.le_timeout = 30; 504 505 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 506 isp_prt(isp, ISP_LOGERR, 507 "Request Queue Overflow in isp_lun_cmd"); 508 return (-1); 509 } 510 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el); 511 isp_put_enable_lun(isp, &el, outp); 512 ISP_ADD_REQUEST(isp, nxti); 513 return (0); 514 } 515 516 517 int 518 isp_target_put_entry(ispsoftc_t *isp, void *ap) 519 { 520 void *outp; 521 uint32_t nxti, optr; 522 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type; 523 524 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 525 isp_prt(isp, ISP_LOGWARN, 526 "Request Queue Overflow in isp_target_put_entry"); 527 return (-1); 528 } 529 switch (etype) { 530 case RQSTYPE_ATIO: 531 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp); 532 break; 533 case RQSTYPE_ATIO2: 534 if (FCPARAM(isp)->isp_2klogin) { 535 isp_put_atio2e(isp, (at2e_entry_t *) ap, 536 (at2e_entry_t *) outp); 537 } else { 538 isp_put_atio2(isp, (at2_entry_t *) ap, 539 (at2_entry_t *) outp); 540 } 541 break; 542 case RQSTYPE_CTIO: 543 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp); 544 break; 545 case RQSTYPE_CTIO2: 546 if (FCPARAM(isp)->isp_2klogin) { 547 isp_put_ctio2e(isp, (ct2e_entry_t *) ap, 548 (ct2e_entry_t *) outp); 549 } else { 550 isp_put_ctio2(isp, (ct2_entry_t *) ap, 551 (ct2_entry_t *) outp); 552 } 553 break; 554 case RQSTYPE_CTIO7: 555 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp); 556 break; 557 default: 558 isp_prt(isp, ISP_LOGERR, 559 "Unknown type 0x%x in isp_put_entry", etype); 560 return (-1); 561 } 562 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap); 563 ISP_ADD_REQUEST(isp, nxti); 564 return (0); 565 } 566 567 int 568 isp_target_put_atio(ispsoftc_t *isp, void *arg) 569 { 570 union { 571 at_entry_t _atio; 572 at2_entry_t _atio2; 573 at2e_entry_t _atio2e; 574 } atun; 575 576 MEMZERO(&atun, sizeof atun); 577 if (IS_FC(isp)) { 578 at2_entry_t *aep = arg; 579 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2; 580 atun._atio2.at_header.rqs_entry_count = 1; 581 if (FCPARAM(isp)->isp_sccfw) { 582 atun._atio2.at_scclun = aep->at_scclun; 583 } else { 584 atun._atio2.at_lun = (uint8_t) aep->at_lun; 585 } 586 if (FCPARAM(isp)->isp_2klogin) { 587 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid; 588 } else { 589 atun._atio2.at_iid = aep->at_iid; 590 } 591 atun._atio2.at_rxid = aep->at_rxid; 592 atun._atio2.at_status = CT_OK; 593 } else { 594 at_entry_t *aep = arg; 595 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO; 596 atun._atio.at_header.rqs_entry_count = 1; 597 atun._atio.at_handle = aep->at_handle; 598 atun._atio.at_iid = aep->at_iid; 599 atun._atio.at_tgt = aep->at_tgt; 600 atun._atio.at_lun = aep->at_lun; 601 atun._atio.at_tag_type = aep->at_tag_type; 602 atun._atio.at_tag_val = aep->at_tag_val; 603 atun._atio.at_status = (aep->at_flags & AT_TQAE); 604 atun._atio.at_status |= CT_OK; 605 } 606 return (isp_target_put_entry(isp, &atun)); 607 } 608 609 /* 610 * Command completion- both for handling cases of no resources or 611 * no blackhole driver, or other cases where we have to, inline, 612 * finish the command sanely, or for normal command completion. 613 * 614 * The 'completion' code value has the scsi status byte in the low 8 bits. 615 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have 616 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC 617 * values. 618 * 619 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't 620 * NB: inline SCSI sense reporting. As such, we lose this information. XXX. 621 * 622 * For both parallel && fibre channel, we use the feature that does 623 * an automatic resource autoreplenish so we don't have then later do 624 * put of an atio to replenish the f/w's resource count. 625 */ 626 627 int 628 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint32_t hdl) 629 { 630 int sts; 631 union { 632 ct_entry_t _ctio; 633 ct2_entry_t _ctio2; 634 ct2e_entry_t _ctio2e; 635 ct7_entry_t _ctio7; 636 } un; 637 638 MEMZERO(&un, sizeof un); 639 sts = code & 0xff; 640 641 if (IS_24XX(isp)) { 642 at7_entry_t *aep = arg; 643 ct7_entry_t *cto = &un._ctio7; 644 645 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 646 cto->ct_header.rqs_entry_count = 1; 647 /* XXXX */ cto->ct_nphdl = aep->at_hdr.seq_id; 648 cto->ct_rxid = aep->at_rxid; 649 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | 650 aep->at_hdr.s_id[2]; 651 cto->ct_iid_hi = aep->at_hdr.s_id[0]; 652 cto->ct_oxid = aep->at_hdr.ox_id; 653 cto->ct_scsi_status = sts; 654 cto->ct_flags = CT7_FLAG_MODE1 | CT7_NO_DATA | CT7_SENDSTATUS; 655 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) { 656 cto->rsp.m1.ct_resplen = 16; 657 cto->rsp.m1.ct_resp[0] = 0xf0; 658 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 659 cto->rsp.m1.ct_resp[7] = 8; 660 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 661 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 662 } 663 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) { 664 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl; 665 cto->ct_scsi_status |= CT2_DATA_UNDER; 666 } 667 cto->ct_syshandle = hdl; 668 } else if (IS_FC(isp)) { 669 at2_entry_t *aep = arg; 670 ct2_entry_t *cto = &un._ctio2; 671 672 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 673 cto->ct_header.rqs_entry_count = 1; 674 if (FCPARAM(isp)->isp_sccfw == 0) { 675 cto->ct_lun = aep->at_lun; 676 } 677 if (FCPARAM(isp)->isp_2klogin) { 678 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid; 679 } else { 680 cto->ct_iid = aep->at_iid; 681 } 682 cto->ct_rxid = aep->at_rxid; 683 cto->rsp.m1.ct_scsi_status = sts; 684 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1; 685 if (hdl == 0) { 686 cto->ct_flags |= CT2_CCINCR; 687 } 688 if (aep->at_datalen) { 689 cto->ct_resid = aep->at_datalen; 690 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER; 691 } 692 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) { 693 cto->rsp.m1.ct_resp[0] = 0xf0; 694 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 695 cto->rsp.m1.ct_resp[7] = 8; 696 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 697 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 698 cto->rsp.m1.ct_senselen = 16; 699 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID; 700 } 701 cto->ct_syshandle = hdl; 702 } else { 703 at_entry_t *aep = arg; 704 ct_entry_t *cto = &un._ctio; 705 706 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO; 707 cto->ct_header.rqs_entry_count = 1; 708 cto->ct_fwhandle = aep->at_handle; 709 cto->ct_iid = aep->at_iid; 710 cto->ct_tgt = aep->at_tgt; 711 cto->ct_lun = aep->at_lun; 712 cto->ct_tag_type = aep->at_tag_type; 713 cto->ct_tag_val = aep->at_tag_val; 714 if (aep->at_flags & AT_TQAE) { 715 cto->ct_flags |= CT_TQAE; 716 } 717 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA; 718 if (hdl == 0) { 719 cto->ct_flags |= CT_CCINCR; 720 } 721 cto->ct_scsi_status = sts; 722 cto->ct_syshandle = hdl; 723 } 724 return (isp_target_put_entry(isp, &un)); 725 } 726 727 /* 728 * These are either broadcast events or specifically CTIO fast completion 729 */ 730 int 731 isp_target_async(ispsoftc_t *isp, int bus, int event) 732 { 733 tmd_notify_t notify; 734 735 MEMZERO(¬ify, sizeof (tmd_notify_t)); 736 notify.nt_hba = isp; 737 notify.nt_iid = INI_ANY; 738 /* nt_tgt set in outer layers */ 739 notify.nt_lun = LUN_ANY; 740 notify.nt_tagval = TAG_ANY; 741 742 if (IS_SCSI(isp)) { 743 TAG_INSERT_BUS(notify.nt_tagval, bus); 744 } 745 746 switch (event) { 747 case ASYNC_LOOP_UP: 748 case ASYNC_PTPMODE: 749 notify.nt_ncode = NT_LINK_UP; 750 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 751 break; 752 case ASYNC_LOOP_DOWN: 753 notify.nt_ncode = NT_LINK_DOWN; 754 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 755 break; 756 case ASYNC_LIP_ERROR: 757 case ASYNC_LIP_F8: 758 case ASYNC_LIP_OCCURRED: 759 case ASYNC_LOOP_RESET: 760 notify.nt_ncode = NT_LIP_RESET; 761 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 762 break; 763 case ASYNC_BUS_RESET: 764 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */ 765 notify.nt_ncode = NT_BUS_RESET; 766 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 767 break; 768 case ASYNC_DEVICE_RESET: 769 notify.nt_ncode = NT_TARGET_RESET; 770 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 771 break; 772 case ASYNC_CTIO_DONE: 773 { 774 uint8_t storage[QENTRY_LEN]; 775 memset(storage, 0, QENTRY_LEN); 776 if (IS_24XX(isp)) { 777 ct7_entry_t *ct = (ct7_entry_t *) storage; 778 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 779 ct->ct_nphdl = CT7_OK; 780 ct->ct_syshandle = bus; 781 ct->ct_flags = CT7_SENDSTATUS|CT7_FASTPOST; 782 } else if (IS_FC(isp)) { 783 /* This should also suffice for 2K login code */ 784 ct2_entry_t *ct = (ct2_entry_t *) storage; 785 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 786 ct->ct_status = CT_OK; 787 ct->ct_syshandle = bus; 788 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST; 789 } else { 790 ct_entry_t *ct = (ct_entry_t *) storage; 791 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO; 792 ct->ct_status = CT_OK; 793 ct->ct_fwhandle = bus; 794 ct->ct_flags = CT_SENDSTATUS; 795 } 796 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage); 797 break; 798 } 799 default: 800 isp_prt(isp, ISP_LOGERR, 801 "isp_target_async: unknown event 0x%x", event); 802 if (isp->isp_state == ISP_RUNSTATE) { 803 isp_notify_ack(isp, NULL); 804 } 805 break; 806 } 807 return (0); 808 } 809 810 811 /* 812 * Process a received message. 813 * The ISP firmware can handle most messages, there are only 814 * a few that we need to deal with: 815 * - abort: clean up the current command 816 * - abort tag and clear queue 817 */ 818 819 static void 820 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp) 821 { 822 tmd_notify_t nt; 823 uint8_t status = inp->in_status & ~QLTM_SVALID; 824 825 MEMZERO(&nt, sizeof (nt)); 826 nt.nt_hba = isp; 827 nt.nt_iid = GET_IID_VAL(inp->in_iid); 828 nt.nt_tgt = inp->in_tgt; 829 nt.nt_lun = inp->in_lun; 830 IN_MAKE_TAGID(nt.nt_tagval, 0, inp); 831 nt.nt_lreserved = inp; 832 833 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) { 834 switch (inp->in_msg[0]) { 835 case MSG_ABORT: 836 nt.nt_ncode = NT_ABORT_TASK_SET; 837 break; 838 case MSG_BUS_DEV_RESET: 839 nt.nt_ncode = NT_TARGET_RESET; 840 break; 841 case MSG_ABORT_TAG: 842 nt.nt_ncode = NT_ABORT_TASK; 843 break; 844 case MSG_CLEAR_QUEUE: 845 nt.nt_ncode = NT_CLEAR_TASK_SET; 846 break; 847 case MSG_REL_RECOVERY: 848 nt.nt_ncode = NT_CLEAR_ACA; 849 break; 850 case MSG_TERM_IO_PROC: 851 nt.nt_ncode = NT_ABORT_TASK; 852 break; 853 case MSG_LUN_RESET: 854 nt.nt_ncode = NT_LUN_RESET; 855 break; 856 default: 857 isp_prt(isp, ISP_LOGERR, 858 "unhandled message 0x%x", inp->in_msg[0]); 859 isp_notify_ack(isp, inp); 860 return; 861 } 862 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 863 } else { 864 isp_prt(isp, ISP_LOGERR, 865 "unknown immediate notify status 0x%x", inp->in_status); 866 isp_notify_ack(isp, inp); 867 } 868 } 869 870 /* 871 * Synthesize a message from the task management flags in a FCP_CMND_IU. 872 */ 873 static void 874 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp) 875 { 876 tmd_notify_t nt; 877 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x"; 878 static const char f2[] = 879 "unknown %s 0x%x lun %d N-Port handle 0x%x task flags 0x%x seq 0x%x\n"; 880 uint16_t seqid, loopid; 881 882 MEMZERO(&nt, sizeof (tmd_notify_t)); 883 nt.nt_hba = isp; 884 if (FCPARAM(isp)->isp_2klogin) { 885 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid; 886 loopid = ((in_fcentry_e_t *)inp)->in_iid; 887 seqid = ((in_fcentry_e_t *)inp)->in_seqid; 888 } else { 889 nt.nt_iid = inp->in_iid; 890 loopid = inp->in_iid; 891 seqid = inp->in_seqid; 892 } 893 /* nt_tgt set in outer layers */ 894 if (FCPARAM(isp)->isp_sccfw) { 895 nt.nt_lun = inp->in_scclun; 896 } else { 897 nt.nt_lun = inp->in_lun; 898 } 899 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, seqid); 900 nt.nt_need_ack = 1; 901 nt.nt_lreserved = inp; 902 903 if (inp->in_status != IN_MSG_RECEIVED) { 904 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status", 905 inp->in_status, nt.nt_lun, loopid, inp->in_task_flags, 906 inp->in_seqid); 907 isp_notify_ack(isp, inp); 908 return; 909 } 910 911 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) { 912 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", 913 loopid, nt.nt_lun, inp->in_seqid); 914 nt.nt_ncode = NT_ABORT_TASK_SET; 915 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) { 916 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", 917 loopid, nt.nt_lun, inp->in_seqid); 918 nt.nt_ncode = NT_CLEAR_TASK_SET; 919 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) { 920 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", 921 loopid, nt.nt_lun, inp->in_seqid); 922 nt.nt_ncode = NT_LUN_RESET; 923 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) { 924 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", 925 loopid, nt.nt_lun, inp->in_seqid); 926 nt.nt_ncode = NT_TARGET_RESET; 927 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) { 928 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", 929 loopid, nt.nt_lun, inp->in_seqid); 930 nt.nt_ncode = NT_CLEAR_ACA; 931 } else { 932 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status, 933 nt.nt_lun, loopid, inp->in_task_flags, inp->in_seqid); 934 isp_notify_ack(isp, inp); 935 return; 936 } 937 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 938 } 939 940 static void 941 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep) 942 { 943 tmd_notify_t nt; 944 static const char f1[] = "%s from PortID 0x%06x lun %d seq 0x%x"; 945 static const char f2[] = 946 "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%x\n"; 947 uint32_t sid; 948 949 MEMZERO(&nt, sizeof (tmd_notify_t)); 950 nt.nt_hba = isp; 951 nt.nt_iid = INI_ANY; 952 nt.nt_lun = 953 (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | 954 (aep->at_cmnd.fcp_cmnd_lun[1]); 955 nt.nt_tagval = aep->at_rxid; 956 nt.nt_lreserved = aep; 957 sid = 958 (aep->at_hdr.s_id[0] << 16) | 959 (aep->at_hdr.s_id[1] << 8) | 960 (aep->at_hdr.s_id[2]); 961 962 if (aep->at_cmnd.fcp_cmnd_task_management & 963 FCP_CMND_TMF_ABORT_TASK_SET) { 964 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", 965 sid, nt.nt_lun, nt.nt_tagval); 966 nt.nt_ncode = NT_ABORT_TASK_SET; 967 } else if (aep->at_cmnd.fcp_cmnd_task_management & 968 FCP_CMND_TMF_CLEAR_TASK_SET) { 969 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", 970 sid, nt.nt_lun, nt.nt_tagval); 971 nt.nt_ncode = NT_CLEAR_TASK_SET; 972 } else if (aep->at_cmnd.fcp_cmnd_task_management & 973 FCP_CMND_TMF_LUN_RESET) { 974 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", 975 sid, nt.nt_lun, nt.nt_tagval); 976 nt.nt_ncode = NT_LUN_RESET; 977 } else if (aep->at_cmnd.fcp_cmnd_task_management & 978 FCP_CMND_TMF_TGT_RESET) { 979 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", 980 sid, nt.nt_lun, nt.nt_tagval); 981 nt.nt_ncode = NT_TARGET_RESET; 982 nt.nt_lun = LUN_ANY; 983 } else if (aep->at_cmnd.fcp_cmnd_task_management & 984 FCP_CMND_TMF_CLEAR_ACA) { 985 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", 986 sid, nt.nt_lun, nt.nt_tagval); 987 nt.nt_ncode = NT_CLEAR_ACA; 988 } else { 989 isp_prt(isp, ISP_LOGWARN, f2, 990 aep->at_cmnd.fcp_cmnd_task_management, 991 nt.nt_lun, sid, nt.nt_tagval); 992 isp_endcmd(isp, aep, 0, 0); 993 return; 994 } 995 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt); 996 } 997 998 void 999 isp_notify_ack(ispsoftc_t *isp, void *arg) 1000 { 1001 char storage[QENTRY_LEN]; 1002 uint32_t nxti, optr; 1003 void *outp; 1004 1005 if (isp_getrqentry(isp, &nxti, &optr, &outp)) { 1006 isp_prt(isp, ISP_LOGWARN, 1007 "Request Queue Overflow For isp_notify_ack"); 1008 return; 1009 } 1010 1011 MEMZERO(storage, QENTRY_LEN); 1012 1013 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) { 1014 at7_entry_t *aep = arg; 1015 isp_endcmd(isp, aep, 0, 0); 1016 return; 1017 } else if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ABTS_RSP)) { 1018 abts_rsp_t *abts_rsp = (abts_rsp_t *) storage; 1019 /* 1020 * The caller will have set response values as appropriate 1021 * in the ABTS structure just before calling us. 1022 */ 1023 MEMCPY(abts_rsp, arg, QENTRY_LEN); 1024 isp_put_abts_rsp(isp, abts_rsp, (abts_rsp_t *)outp); 1025 } else if (IS_24XX(isp)) { 1026 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage; 1027 if (arg) { 1028 in_fcentry_24xx_t *in = arg; 1029 na->na_nphdl = in->in_nphdl; 1030 na->na_status = in->in_status; 1031 na->na_status_subcode = in->in_status_subcode; 1032 na->na_rxid = in->in_rxid; 1033 na->na_oxid = in->in_oxid; 1034 if (in->in_status == IN24XX_SRR_RCVD) { 1035 na->na_srr_rxid = in->in_srr_rxid; 1036 na->na_srr_reloff_hi = in->in_srr_reloff_hi; 1037 na->na_srr_reloff_lo = in->in_srr_reloff_lo; 1038 na->na_srr_iu = in->in_srr_iu; 1039 na->na_srr_flags = 1; 1040 na->na_srr_reject_vunique = 0; 1041 na->na_srr_reject_explanation = 1; 1042 na->na_srr_reject_code = 1; 1043 } 1044 } 1045 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1046 na->na_header.rqs_entry_count = 1; 1047 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp); 1048 } else if (IS_FC(isp)) { 1049 na_fcentry_t *na = (na_fcentry_t *) storage; 1050 int iid = 0; 1051 1052 if (arg) { 1053 in_fcentry_t *inp = arg; 1054 MEMCPY(storage, arg, sizeof (isphdr_t)); 1055 if (FCPARAM(isp)->isp_2klogin) { 1056 ((na_fcentry_e_t *)na)->na_iid = 1057 ((in_fcentry_e_t *)inp)->in_iid; 1058 iid = ((na_fcentry_e_t *)na)->na_iid; 1059 } else { 1060 na->na_iid = inp->in_iid; 1061 iid = na->na_iid; 1062 } 1063 na->na_task_flags = 1064 inp->in_task_flags & TASK_FLAGS_RESERVED_MASK; 1065 na->na_seqid = inp->in_seqid; 1066 na->na_flags = NAFC_RCOUNT; 1067 na->na_status = inp->in_status; 1068 if (inp->in_status == IN_RESET) { 1069 na->na_flags |= NAFC_RST_CLRD; 1070 } 1071 if (inp->in_status == IN_MSG_RECEIVED) { 1072 na->na_flags |= NAFC_TVALID; 1073 na->na_response = 0; /* XXX SUCCEEDED XXX */ 1074 } 1075 } else { 1076 na->na_flags = NAFC_RST_CLRD; 1077 } 1078 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1079 na->na_header.rqs_entry_count = 1; 1080 if (FCPARAM(isp)->isp_2klogin) { 1081 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, 1082 (na_fcentry_e_t *)outp); 1083 } else { 1084 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp); 1085 } 1086 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x " 1087 "flags %x tflags %x response %x", iid, na->na_seqid, 1088 na->na_flags, na->na_task_flags, na->na_response); 1089 } else { 1090 na_entry_t *na = (na_entry_t *) storage; 1091 if (arg) { 1092 in_entry_t *inp = arg; 1093 MEMCPY(storage, arg, sizeof (isphdr_t)); 1094 na->na_iid = inp->in_iid; 1095 na->na_lun = inp->in_lun; 1096 na->na_tgt = inp->in_tgt; 1097 na->na_seqid = inp->in_seqid; 1098 if (inp->in_status == IN_RESET) { 1099 na->na_event = NA_RST_CLRD; 1100 } 1101 } else { 1102 na->na_event = NA_RST_CLRD; 1103 } 1104 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1105 na->na_header.rqs_entry_count = 1; 1106 isp_put_notify_ack(isp, na, (na_entry_t *)outp); 1107 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt " 1108 "%u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt, 1109 na->na_seqid, na->na_event); 1110 } 1111 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage); 1112 ISP_ADD_REQUEST(isp, nxti); 1113 } 1114 1115 static void 1116 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep) 1117 { 1118 int lun; 1119 lun = aep->at_lun; 1120 /* 1121 * The firmware status (except for the QLTM_SVALID bit) indicates 1122 * why this ATIO was sent to us. 1123 * 1124 * If QLTM_SVALID is set, the firware has recommended Sense Data. 1125 * 1126 * If the DISCONNECTS DISABLED bit is set in the flags field, 1127 * we're still connected on the SCSI bus - i.e. the initiator 1128 * did not set DiscPriv in the identify message. We don't care 1129 * about this so it's ignored. 1130 */ 1131 1132 switch(aep->at_status & ~QLTM_SVALID) { 1133 case AT_PATH_INVALID: 1134 /* 1135 * ATIO rejected by the firmware due to disabled lun. 1136 */ 1137 isp_prt(isp, ISP_LOGERR, 1138 "rejected ATIO for disabled lun %d", lun); 1139 break; 1140 case AT_NOCAP: 1141 /* 1142 * Requested Capability not available 1143 * We sent an ATIO that overflowed the firmware's 1144 * command resource count. 1145 */ 1146 isp_prt(isp, ISP_LOGERR, 1147 "rejected ATIO for lun %d because of command count" 1148 " overflow", lun); 1149 break; 1150 1151 case AT_BDR_MSG: 1152 /* 1153 * If we send an ATIO to the firmware to increment 1154 * its command resource count, and the firmware is 1155 * recovering from a Bus Device Reset, it returns 1156 * the ATIO with this status. We set the command 1157 * resource count in the Enable Lun entry and do 1158 * not increment it. Therefore we should never get 1159 * this status here. 1160 */ 1161 isp_prt(isp, ISP_LOGERR, atiocope, lun, 1162 GET_BUS_VAL(aep->at_iid)); 1163 break; 1164 1165 case AT_CDB: /* Got a CDB */ 1166 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */ 1167 /* 1168 * Punt to platform specific layer. 1169 */ 1170 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1171 break; 1172 1173 case AT_RESET: 1174 /* 1175 * A bus reset came along and blew away this command. Why 1176 * they do this in addition the async event code stuff, 1177 * I dunno. 1178 * 1179 * Ignore it because the async event will clear things 1180 * up for us. 1181 */ 1182 isp_prt(isp, ISP_LOGWARN, atior, lun, 1183 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid)); 1184 break; 1185 1186 1187 default: 1188 isp_prt(isp, ISP_LOGERR, 1189 "Unknown ATIO status 0x%x from loopid %d for lun %d", 1190 aep->at_status, aep->at_iid, lun); 1191 (void) isp_target_put_atio(isp, aep); 1192 break; 1193 } 1194 } 1195 1196 static void 1197 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep) 1198 { 1199 int lun, iid; 1200 1201 if (FCPARAM(isp)->isp_sccfw) { 1202 lun = aep->at_scclun; 1203 } else { 1204 lun = aep->at_lun; 1205 } 1206 1207 if (FCPARAM(isp)->isp_2klogin) { 1208 iid = ((at2e_entry_t *)aep)->at_iid; 1209 } else { 1210 iid = aep->at_iid; 1211 } 1212 1213 /* 1214 * The firmware status (except for the QLTM_SVALID bit) indicates 1215 * why this ATIO was sent to us. 1216 * 1217 * If QLTM_SVALID is set, the firware has recommended Sense Data. 1218 * 1219 * If the DISCONNECTS DISABLED bit is set in the flags field, 1220 * we're still connected on the SCSI bus - i.e. the initiator 1221 * did not set DiscPriv in the identify message. We don't care 1222 * about this so it's ignored. 1223 */ 1224 1225 switch(aep->at_status & ~QLTM_SVALID) { 1226 case AT_PATH_INVALID: 1227 /* 1228 * ATIO rejected by the firmware due to disabled lun. 1229 */ 1230 isp_prt(isp, ISP_LOGERR, 1231 "rejected ATIO2 for disabled lun %d", lun); 1232 break; 1233 case AT_NOCAP: 1234 /* 1235 * Requested Capability not available 1236 * We sent an ATIO that overflowed the firmware's 1237 * command resource count. 1238 */ 1239 isp_prt(isp, ISP_LOGERR, 1240 "rejected ATIO2 for lun %d- command count overflow", lun); 1241 break; 1242 1243 case AT_BDR_MSG: 1244 /* 1245 * If we send an ATIO to the firmware to increment 1246 * its command resource count, and the firmware is 1247 * recovering from a Bus Device Reset, it returns 1248 * the ATIO with this status. We set the command 1249 * resource count in the Enable Lun entry and no 1250 * not increment it. Therefore we should never get 1251 * this status here. 1252 */ 1253 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0); 1254 break; 1255 1256 case AT_CDB: /* Got a CDB */ 1257 /* 1258 * Punt to platform specific layer. 1259 */ 1260 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1261 break; 1262 1263 case AT_RESET: 1264 /* 1265 * A bus reset came along an blew away this command. Why 1266 * they do this in addition the async event code stuff, 1267 * I dunno. 1268 * 1269 * Ignore it because the async event will clear things 1270 * up for us. 1271 */ 1272 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0); 1273 break; 1274 1275 1276 default: 1277 isp_prt(isp, ISP_LOGERR, 1278 "Unknown ATIO2 status 0x%x from loopid %d for lun %d", 1279 aep->at_status, iid, lun); 1280 (void) isp_target_put_atio(isp, aep); 1281 break; 1282 } 1283 } 1284 1285 static void 1286 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct) 1287 { 1288 void *xs; 1289 int pl = ISP_LOGTDEBUG2; 1290 char *fmsg = NULL; 1291 1292 if (ct->ct_syshandle) { 1293 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1294 if (xs == NULL) { 1295 pl = ISP_LOGALL; 1296 } 1297 } else { 1298 xs = NULL; 1299 } 1300 1301 switch(ct->ct_status & ~QLTM_SVALID) { 1302 case CT_OK: 1303 /* 1304 * There are generally 3 possibilities as to why we'd get 1305 * this condition: 1306 * We disconnected after receiving a CDB. 1307 * We sent or received data. 1308 * We sent status & command complete. 1309 */ 1310 1311 if (ct->ct_flags & CT_SENDSTATUS) { 1312 break; 1313 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) { 1314 /* 1315 * Nothing to do in this case. 1316 */ 1317 isp_prt(isp, pl, "CTIO- iid %d disconnected OK", 1318 ct->ct_iid); 1319 return; 1320 } 1321 break; 1322 1323 case CT_BDR_MSG: 1324 /* 1325 * Bus Device Reset message received or the SCSI Bus has 1326 * been Reset; the firmware has gone to Bus Free. 1327 * 1328 * The firmware generates an async mailbox interupt to 1329 * notify us of this and returns outstanding CTIOs with this 1330 * status. These CTIOs are handled in that same way as 1331 * CT_ABORTED ones, so just fall through here. 1332 */ 1333 fmsg = "Bus Device Reset"; 1334 /*FALLTHROUGH*/ 1335 case CT_RESET: 1336 if (fmsg == NULL) 1337 fmsg = "Bus Reset"; 1338 /*FALLTHROUGH*/ 1339 case CT_ABORTED: 1340 /* 1341 * When an Abort message is received the firmware goes to 1342 * Bus Free and returns all outstanding CTIOs with the status 1343 * set, then sends us an Immediate Notify entry. 1344 */ 1345 if (fmsg == NULL) 1346 fmsg = "ABORT TAG message sent by Initiator"; 1347 1348 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg); 1349 break; 1350 1351 case CT_INVAL: 1352 /* 1353 * CTIO rejected by the firmware due to disabled lun. 1354 * "Cannot Happen". 1355 */ 1356 isp_prt(isp, ISP_LOGERR, 1357 "Firmware rejected CTIO for disabled lun %d", 1358 ct->ct_lun); 1359 break; 1360 1361 case CT_NOPATH: 1362 /* 1363 * CTIO rejected by the firmware due "no path for the 1364 * nondisconnecting nexus specified". This means that 1365 * we tried to access the bus while a non-disconnecting 1366 * command is in process. 1367 */ 1368 isp_prt(isp, ISP_LOGERR, 1369 "Firmware rejected CTIO for bad nexus %d/%d/%d", 1370 ct->ct_iid, ct->ct_tgt, ct->ct_lun); 1371 break; 1372 1373 case CT_RSELTMO: 1374 fmsg = "Reselection"; 1375 /*FALLTHROUGH*/ 1376 case CT_TIMEOUT: 1377 if (fmsg == NULL) 1378 fmsg = "Command"; 1379 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1380 break; 1381 1382 case CT_PANIC: 1383 if (fmsg == NULL) 1384 fmsg = "Unrecoverable Error"; 1385 /*FALLTHROUGH*/ 1386 case CT_ERR: 1387 if (fmsg == NULL) 1388 fmsg = "Completed with Error"; 1389 /*FALLTHROUGH*/ 1390 case CT_PHASE_ERROR: 1391 if (fmsg == NULL) 1392 fmsg = "Phase Sequence Error"; 1393 /*FALLTHROUGH*/ 1394 case CT_TERMINATED: 1395 if (fmsg == NULL) 1396 fmsg = "terminated by TERMINATE TRANSFER"; 1397 /*FALLTHROUGH*/ 1398 case CT_NOACK: 1399 if (fmsg == NULL) 1400 fmsg = "unacknowledged Immediate Notify pending"; 1401 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg); 1402 break; 1403 default: 1404 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x", 1405 ct->ct_status & ~QLTM_SVALID); 1406 break; 1407 } 1408 1409 if (xs == NULL) { 1410 /* 1411 * There may be more than one CTIO for a data transfer, 1412 * or this may be a status CTIO we're not monitoring. 1413 * 1414 * The assumption is that they'll all be returned in the 1415 * order we got them. 1416 */ 1417 if (ct->ct_syshandle == 0) { 1418 if ((ct->ct_flags & CT_SENDSTATUS) == 0) { 1419 isp_prt(isp, pl, 1420 "intermediate CTIO completed ok"); 1421 } else { 1422 isp_prt(isp, pl, 1423 "unmonitored CTIO completed ok"); 1424 } 1425 } else { 1426 isp_prt(isp, pl, 1427 "NO xs for CTIO (handle 0x%x) status 0x%x", 1428 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1429 } 1430 } else { 1431 /* 1432 * Final CTIO completed. Release DMA resources and 1433 * notify platform dependent layers. 1434 */ 1435 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) { 1436 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1437 } 1438 isp_prt(isp, pl, "final CTIO complete"); 1439 /* 1440 * The platform layer will destroy the handle if appropriate. 1441 */ 1442 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1443 } 1444 } 1445 1446 static void 1447 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct) 1448 { 1449 void *xs; 1450 int pl = ISP_LOGTDEBUG2; 1451 char *fmsg = NULL; 1452 1453 if (ct->ct_syshandle) { 1454 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1455 if (xs == NULL) { 1456 pl = ISP_LOGALL; 1457 } 1458 } else { 1459 xs = NULL; 1460 } 1461 1462 switch(ct->ct_status & ~QLTM_SVALID) { 1463 case CT_BUS_ERROR: 1464 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 1465 /* FALL Through */ 1466 case CT_DATA_OVER: 1467 case CT_DATA_UNDER: 1468 case CT_OK: 1469 /* 1470 * There are generally 2 possibilities as to why we'd get 1471 * this condition: 1472 * We sent or received data. 1473 * We sent status & command complete. 1474 */ 1475 1476 break; 1477 1478 case CT_BDR_MSG: 1479 /* 1480 * Target Reset function received. 1481 * 1482 * The firmware generates an async mailbox interupt to 1483 * notify us of this and returns outstanding CTIOs with this 1484 * status. These CTIOs are handled in that same way as 1485 * CT_ABORTED ones, so just fall through here. 1486 */ 1487 fmsg = "TARGET RESET"; 1488 /*FALLTHROUGH*/ 1489 case CT_RESET: 1490 if (fmsg == NULL) 1491 fmsg = "LIP Reset"; 1492 /*FALLTHROUGH*/ 1493 case CT_ABORTED: 1494 /* 1495 * When an Abort message is received the firmware goes to 1496 * Bus Free and returns all outstanding CTIOs with the status 1497 * set, then sends us an Immediate Notify entry. 1498 */ 1499 if (fmsg == NULL) { 1500 fmsg = "ABORT"; 1501 } 1502 1503 isp_prt(isp, ISP_LOGTDEBUG0, 1504 "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 1505 break; 1506 1507 case CT_INVAL: 1508 /* 1509 * CTIO rejected by the firmware - invalid data direction. 1510 */ 1511 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction"); 1512 break; 1513 1514 case CT_RSELTMO: 1515 fmsg = "failure to reconnect to initiator"; 1516 /*FALLTHROUGH*/ 1517 case CT_TIMEOUT: 1518 if (fmsg == NULL) 1519 fmsg = "command"; 1520 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1521 break; 1522 1523 case CT_ERR: 1524 fmsg = "Completed with Error"; 1525 /*FALLTHROUGH*/ 1526 case CT_LOGOUT: 1527 if (fmsg == NULL) 1528 fmsg = "Port Logout"; 1529 /*FALLTHROUGH*/ 1530 case CT_PORTUNAVAIL: 1531 if (fmsg == NULL) 1532 fmsg = "Port not available"; 1533 /*FALLTHROUGH*/ 1534 case CT_PORTCHANGED: 1535 if (fmsg == NULL) 1536 fmsg = "Port Changed"; 1537 /*FALLTHROUGH*/ 1538 case CT_NOACK: 1539 if (fmsg == NULL) 1540 fmsg = "unacknowledged Immediate Notify pending"; 1541 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 1542 break; 1543 1544 case CT_INVRXID: 1545 /* 1546 * CTIO rejected by the firmware because an invalid RX_ID. 1547 * Just print a message. 1548 */ 1549 isp_prt(isp, ISP_LOGWARN, 1550 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 1551 break; 1552 1553 default: 1554 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x", 1555 ct->ct_status & ~QLTM_SVALID); 1556 break; 1557 } 1558 1559 if (xs == NULL) { 1560 /* 1561 * There may be more than one CTIO for a data transfer, 1562 * or this may be a status CTIO we're not monitoring. 1563 * 1564 * The assumption is that they'll all be returned in the 1565 * order we got them. 1566 */ 1567 if (ct->ct_syshandle == 0) { 1568 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) { 1569 isp_prt(isp, pl, 1570 "intermediate CTIO completed ok"); 1571 } else { 1572 isp_prt(isp, pl, 1573 "unmonitored CTIO completed ok"); 1574 } 1575 } else { 1576 isp_prt(isp, pl, 1577 "NO xs for CTIO (handle 0x%x) status 0x%x", 1578 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1579 } 1580 } else { 1581 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 1582 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1583 } 1584 if (ct->ct_flags & CT2_SENDSTATUS) { 1585 /* 1586 * Sent status and command complete. 1587 * 1588 * We're now really done with this command, so we 1589 * punt to the platform dependent layers because 1590 * only there can we do the appropriate command 1591 * complete thread synchronization. 1592 */ 1593 isp_prt(isp, pl, "status CTIO complete"); 1594 } else { 1595 /* 1596 * Final CTIO completed. Release DMA resources and 1597 * notify platform dependent layers. 1598 */ 1599 isp_prt(isp, pl, "data CTIO complete"); 1600 } 1601 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1602 /* 1603 * The platform layer will destroy the handle if appropriate. 1604 */ 1605 } 1606 } 1607 1608 static void 1609 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct) 1610 { 1611 void *xs; 1612 int pl = ISP_LOGTDEBUG2; 1613 char *fmsg = NULL; 1614 1615 if (ct->ct_syshandle) { 1616 xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 1617 if (xs == NULL) { 1618 pl = ISP_LOGALL; 1619 } 1620 } else { 1621 xs = NULL; 1622 } 1623 1624 switch(ct->ct_nphdl) { 1625 case CT7_BUS_ERROR: 1626 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 1627 /* FALL Through */ 1628 case CT7_DATA_OVER: 1629 case CT7_DATA_UNDER: 1630 case CT7_OK: 1631 /* 1632 * There are generally 2 possibilities as to why we'd get 1633 * this condition: 1634 * We sent or received data. 1635 * We sent status & command complete. 1636 */ 1637 1638 break; 1639 1640 case CT7_RESET: 1641 if (fmsg == NULL) { 1642 fmsg = "LIP Reset"; 1643 } 1644 /*FALLTHROUGH*/ 1645 case CT7_ABORTED: 1646 /* 1647 * When an Abort message is received the firmware goes to 1648 * Bus Free and returns all outstanding CTIOs with the status 1649 * set, then sends us an Immediate Notify entry. 1650 */ 1651 if (fmsg == NULL) { 1652 fmsg = "ABORT"; 1653 } 1654 isp_prt(isp, ISP_LOGTDEBUG0, 1655 "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 1656 break; 1657 1658 case CT7_TIMEOUT: 1659 if (fmsg == NULL) { 1660 fmsg = "command"; 1661 } 1662 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg); 1663 break; 1664 1665 case CT7_ERR: 1666 fmsg = "Completed with Error"; 1667 /*FALLTHROUGH*/ 1668 case CT7_LOGOUT: 1669 if (fmsg == NULL) { 1670 fmsg = "Port Logout"; 1671 } 1672 /*FALLTHROUGH*/ 1673 case CT7_PORTUNAVAIL: 1674 if (fmsg == NULL) { 1675 fmsg = "Port not available"; 1676 } 1677 /*FALLTHROUGH*/ 1678 case CT7_PORTCHANGED: 1679 if (fmsg == NULL) { 1680 fmsg = "Port Changed"; 1681 } 1682 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 1683 break; 1684 1685 case CT7_INVRXID: 1686 /* 1687 * CTIO rejected by the firmware because an invalid RX_ID. 1688 * Just print a message. 1689 */ 1690 isp_prt(isp, ISP_LOGWARN, 1691 "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 1692 break; 1693 1694 case CT7_REASSY_ERR: 1695 isp_prt(isp, ISP_LOGWARN, "reassembly error"); 1696 break; 1697 1698 case CT7_SRR: 1699 isp_prt(isp, ISP_LOGWARN, "SRR received"); 1700 break; 1701 1702 default: 1703 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", 1704 ct->ct_nphdl); 1705 break; 1706 } 1707 1708 if (xs == NULL) { 1709 /* 1710 * There may be more than one CTIO for a data transfer, 1711 * or this may be a status CTIO we're not monitoring. 1712 * 1713 * The assumption is that they'll all be returned in the 1714 * order we got them. 1715 */ 1716 if (ct->ct_syshandle == 0) { 1717 if (ct->ct_flags & CT7_TERMINATE) { 1718 isp_prt(isp, ISP_LOGINFO, 1719 "termination of 0x%x complete", 1720 ct->ct_rxid); 1721 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) { 1722 isp_prt(isp, pl, 1723 "intermediate CTIO completed ok"); 1724 } else { 1725 isp_prt(isp, pl, 1726 "unmonitored CTIO completed ok"); 1727 } 1728 } else { 1729 isp_prt(isp, pl, 1730 "NO xs for CTIO (handle 0x%x) status 0x%x", 1731 ct->ct_syshandle, ct->ct_nphdl); 1732 } 1733 } else { 1734 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 1735 ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1736 } 1737 if (ct->ct_flags & CT2_SENDSTATUS) { 1738 /* 1739 * Sent status and command complete. 1740 * 1741 * We're now really done with this command, so we 1742 * punt to the platform dependent layers because 1743 * only there can we do the appropriate command 1744 * complete thread synchronization. 1745 */ 1746 isp_prt(isp, pl, "status CTIO complete"); 1747 } else { 1748 /* 1749 * Final CTIO completed. Release DMA resources and 1750 * notify platform dependent layers. 1751 */ 1752 isp_prt(isp, pl, "data CTIO complete"); 1753 } 1754 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1755 /* 1756 * The platform layer will destroy the handle if appropriate. 1757 */ 1758 } 1759 } 1760 #endif 1761