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