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 52ea49c6e4SMatt Jacob int isp_tdebug = 1; 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 */ 170ea49c6e4SMatt Jacob if (IS_FC(isp)) { 171ea49c6e4SMatt Jacob status = inot_fcp->in_status; 172ea49c6e4SMatt Jacob seqid = inot_fcp->in_seqid; 173ea49c6e4SMatt Jacob } else { 174ea49c6e4SMatt Jacob status = inotp->in_status & 0xff; 175ea49c6e4SMatt Jacob seqid = inotp->in_seqid; 176ea49c6e4SMatt Jacob } 177ea49c6e4SMatt Jacob bus = 0; /* XXX: Which Channel? */ 178ea49c6e4SMatt Jacob ITDEBUG(2, ("isp_target_notify: Immediate Notify, " 179ea49c6e4SMatt Jacob "status=0x%x seqid=0x%x\n", status, seqid)); 180ea49c6e4SMatt Jacob switch (status) { 181ea49c6e4SMatt Jacob case IN_RESET: 182ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_BUS_RESET, &bus); 183ea49c6e4SMatt Jacob break; 184ea49c6e4SMatt Jacob case IN_MSG_RECEIVED: 185ea49c6e4SMatt Jacob case IN_IDE_RECEIVED: 186ea49c6e4SMatt Jacob if (IS_FC(isp)) { 187ea49c6e4SMatt Jacob isp_got_msg_fc(isp, bus, vptr); 188ea49c6e4SMatt Jacob } else { 189ea49c6e4SMatt Jacob isp_got_msg(isp, bus, vptr); 190ea49c6e4SMatt Jacob } 191ea49c6e4SMatt Jacob break; 192ea49c6e4SMatt Jacob case IN_RSRC_UNAVAIL: 193ea49c6e4SMatt Jacob PRINTF("%s: Firmware out of ATIOs\n", isp->isp_name); 194ea49c6e4SMatt Jacob break; 195ea49c6e4SMatt Jacob case IN_ABORT_TASK: 196ea49c6e4SMatt Jacob PRINTF("%s: Abort Task for Initiator %d RX_ID 0x%x\n", 197ea49c6e4SMatt Jacob isp->isp_name, inot_fcp->in_iid, seqid); 198ea49c6e4SMatt Jacob break; 199ea49c6e4SMatt Jacob case IN_PORT_LOGOUT: 200ea49c6e4SMatt Jacob PRINTF("%s: Port Logout 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_CHANGED: 204ea49c6e4SMatt Jacob PRINTF("%s: Port Changed 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_GLOBAL_LOGO: 208ea49c6e4SMatt Jacob PRINTF("%s: All ports logged out\n", isp->isp_name); 209ea49c6e4SMatt Jacob break; 210ea49c6e4SMatt Jacob default: 211ea49c6e4SMatt Jacob PRINTF("%s: bad status (0x%x) in isp_target_notify\n", 212ea49c6e4SMatt Jacob isp->isp_name, status); 213ea49c6e4SMatt Jacob break; 214ea49c6e4SMatt Jacob } 215ea49c6e4SMatt Jacob isp_notify_ack(isp, vptr); 216ea49c6e4SMatt Jacob break; 217ea49c6e4SMatt Jacob 218ea49c6e4SMatt Jacob case RQSTYPE_NOTIFY_ACK: 219ea49c6e4SMatt Jacob /* 220ea49c6e4SMatt Jacob * The ISP is acknowledging our acknowledgement of an 221ea49c6e4SMatt Jacob * Immediate Notify entry for some asynchronous event. 222ea49c6e4SMatt Jacob */ 223ea49c6e4SMatt Jacob if (IS_FC(isp)) { 224ea49c6e4SMatt Jacob ITDEBUG(2, ("%s: Notify Ack status=0x%x seqid 0x%x\n", 225ea49c6e4SMatt Jacob isp->isp_name, nack_fcp->na_status, 226ea49c6e4SMatt Jacob nack_fcp->na_seqid)); 227ea49c6e4SMatt Jacob } else { 228ea49c6e4SMatt Jacob ITDEBUG(2, ("%s: Notify Ack event 0x%x status=0x%x " 229ea49c6e4SMatt Jacob "seqid 0x%x\n", isp->isp_name, nackp->na_event, 230ea49c6e4SMatt Jacob nackp->na_status, nackp->na_seqid)); 231ea49c6e4SMatt Jacob } 232ea49c6e4SMatt Jacob break; 233ea49c6e4SMatt Jacob default: 234ea49c6e4SMatt Jacob PRINTF("%s: Unknown entry type 0x%x in isp_target_notify", 235ea49c6e4SMatt Jacob isp->isp_name, hdrp->rqs_entry_type); 236ea49c6e4SMatt Jacob rval = -1; 237ea49c6e4SMatt Jacob break; 238ea49c6e4SMatt Jacob } 239ea49c6e4SMatt Jacob #undef atiop 240ea49c6e4SMatt Jacob #undef at2iop 241ea49c6e4SMatt Jacob #undef ctiop 242ea49c6e4SMatt Jacob #undef ct2iop 243ea49c6e4SMatt Jacob #undef lunenp 244ea49c6e4SMatt Jacob #undef inotp 245ea49c6e4SMatt Jacob #undef inot_fcp 246ea49c6e4SMatt Jacob #undef nackp 247ea49c6e4SMatt Jacob #undef nack_fcp 248ea49c6e4SMatt Jacob #undef hdrp 249ea49c6e4SMatt Jacob return (rval); 250ea49c6e4SMatt Jacob } 251ea49c6e4SMatt Jacob 252ea49c6e4SMatt Jacob 253ea49c6e4SMatt Jacob /* 254ea49c6e4SMatt Jacob * Toggle (on/off) target mode for bus/target/lun 255ea49c6e4SMatt Jacob * 256ea49c6e4SMatt Jacob * The caller has checked for overlap and legality. 257ea49c6e4SMatt Jacob * 258ea49c6e4SMatt Jacob * Note that not all of bus, target or lun can be paid attention to. 259ea49c6e4SMatt Jacob * Note also that this action will not be complete until the f/w writes 260ea49c6e4SMatt Jacob * response entry. The caller is responsible for synchronizing this. 261ea49c6e4SMatt Jacob */ 262ea49c6e4SMatt Jacob int 263ea49c6e4SMatt Jacob isp_lun_cmd(isp, cmd, bus, tgt, lun, opaque) 264ea49c6e4SMatt Jacob struct ispsoftc *isp; 265ea49c6e4SMatt Jacob int cmd; 266ea49c6e4SMatt Jacob int bus; 267ea49c6e4SMatt Jacob int tgt; 268ea49c6e4SMatt Jacob int lun; 269ea49c6e4SMatt Jacob u_int32_t opaque; 270ea49c6e4SMatt Jacob { 271ea49c6e4SMatt Jacob lun_entry_t el; 272ea49c6e4SMatt Jacob u_int16_t iptr, optr; 273ea49c6e4SMatt Jacob void *outp; 274ea49c6e4SMatt Jacob 275ea49c6e4SMatt Jacob bus = bus; /* XXX */ 276ea49c6e4SMatt Jacob 277ea49c6e4SMatt Jacob MEMZERO(&el, sizeof (el)); 278ea49c6e4SMatt Jacob el.le_cmd_count = DFLT_CMD_CNT; 279ea49c6e4SMatt Jacob el.le_in_count = DFLT_INOTIFY; 280ea49c6e4SMatt Jacob if (cmd == RQSTYPE_ENABLE_LUN) { 281ea49c6e4SMatt Jacob if (IS_SCSI(isp)) { 282ea49c6e4SMatt Jacob el.le_flags = LUN_TQAE; 283ea49c6e4SMatt Jacob el.le_cdb6len = 12; 284ea49c6e4SMatt Jacob el.le_cdb7len = 12; 285ea49c6e4SMatt Jacob } 286ea49c6e4SMatt Jacob } else if (cmd == -RQSTYPE_ENABLE_LUN) { 287ea49c6e4SMatt Jacob cmd = RQSTYPE_ENABLE_LUN; 288ea49c6e4SMatt Jacob el.le_cmd_count = 0; 289ea49c6e4SMatt Jacob el.le_in_count = 0; 290ea49c6e4SMatt Jacob } else if (cmd == -RQSTYPE_MODIFY_LUN) { 291ea49c6e4SMatt Jacob cmd = RQSTYPE_MODIFY_LUN; 292ea49c6e4SMatt Jacob el.le_ops = LUN_CCDECR | LUN_INDECR; 293ea49c6e4SMatt Jacob } else { 294ea49c6e4SMatt Jacob el.le_ops = LUN_CCINCR | LUN_ININCR; 295ea49c6e4SMatt Jacob } 296ea49c6e4SMatt Jacob el.le_header.rqs_entry_type = cmd; 297ea49c6e4SMatt Jacob el.le_header.rqs_entry_count = 1; 298ea49c6e4SMatt Jacob el.le_reserved = opaque; 299ea49c6e4SMatt Jacob if (IS_SCSI(isp)) { 300ea49c6e4SMatt Jacob el.le_tgt = tgt; 301ea49c6e4SMatt Jacob el.le_lun = lun; 302ea49c6e4SMatt Jacob #ifndef ISP2100_SCCLUN 303ea49c6e4SMatt Jacob } else { 304ea49c6e4SMatt Jacob el.le_lun = lun; 305ea49c6e4SMatt Jacob #endif 306ea49c6e4SMatt Jacob } 307ea49c6e4SMatt Jacob 308ea49c6e4SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) { 309ea49c6e4SMatt Jacob PRINTF("%s: Request Queue Overflow in isp_lun_cmd\n", 310ea49c6e4SMatt Jacob isp->isp_name); 311ea49c6e4SMatt Jacob return (-1); 312ea49c6e4SMatt Jacob } 313ea49c6e4SMatt Jacob ISP_SWIZ_ENABLE_LUN(isp, outp, &el); 314ea49c6e4SMatt Jacob ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el); 315ea49c6e4SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 316ea49c6e4SMatt Jacob return (0); 317ea49c6e4SMatt Jacob } 318ea49c6e4SMatt Jacob 319ea49c6e4SMatt Jacob 320ea49c6e4SMatt Jacob int 321ea49c6e4SMatt Jacob isp_target_put_entry(isp, ap) 322ea49c6e4SMatt Jacob struct ispsoftc *isp; 323ea49c6e4SMatt Jacob void *ap; 324ea49c6e4SMatt Jacob { 325ea49c6e4SMatt Jacob void *outp; 326ea49c6e4SMatt Jacob u_int16_t iptr, optr; 327ea49c6e4SMatt Jacob u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type; 328ea49c6e4SMatt Jacob int s = splcam(); 329ea49c6e4SMatt Jacob 330ea49c6e4SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) { 331ea49c6e4SMatt Jacob splx(s); 332ea49c6e4SMatt Jacob PRINTF("%s: Request Queue Overflow in isp_target_put_entry " 333ea49c6e4SMatt Jacob "for type 0x%x\n", isp->isp_name, etype); 334ea49c6e4SMatt Jacob return (-1); 335ea49c6e4SMatt Jacob } 336ea49c6e4SMatt Jacob switch (etype) { 337ea49c6e4SMatt Jacob case RQSTYPE_ATIO: 338ea49c6e4SMatt Jacob ISP_SWIZ_ATIO(isp, outp, ap); 339ea49c6e4SMatt Jacob break; 340ea49c6e4SMatt Jacob case RQSTYPE_ATIO2: 341ea49c6e4SMatt Jacob ISP_SWIZ_ATIO2(isp, outp, ap); 342ea49c6e4SMatt Jacob break; 343ea49c6e4SMatt Jacob case RQSTYPE_CTIO: 344ea49c6e4SMatt Jacob ISP_SWIZ_CTIO(isp, outp, ap); 345ea49c6e4SMatt Jacob break; 346ea49c6e4SMatt Jacob case RQSTYPE_CTIO2: 347ea49c6e4SMatt Jacob ISP_SWIZ_CTIO2(isp, outp, ap); 348ea49c6e4SMatt Jacob break; 349ea49c6e4SMatt Jacob default: 350ea49c6e4SMatt Jacob splx(s); 351ea49c6e4SMatt Jacob PRINTF("%s: Unknown type 0x%x in isp_put_entry\n", 352ea49c6e4SMatt Jacob isp->isp_name, etype); 353ea49c6e4SMatt Jacob return (-1); 354ea49c6e4SMatt Jacob } 355ea49c6e4SMatt Jacob 356ea49c6e4SMatt Jacob ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);; 357ea49c6e4SMatt Jacob 358ea49c6e4SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 359ea49c6e4SMatt Jacob splx(s); 360ea49c6e4SMatt Jacob return (0); 361ea49c6e4SMatt Jacob } 362ea49c6e4SMatt Jacob 363ea49c6e4SMatt Jacob int 364ea49c6e4SMatt Jacob isp_target_put_atio(isp, iid, tgt, lun, ttype, tval) 365ea49c6e4SMatt Jacob struct ispsoftc *isp; 366ea49c6e4SMatt Jacob int iid; 367ea49c6e4SMatt Jacob int tgt; 368ea49c6e4SMatt Jacob int lun; 369ea49c6e4SMatt Jacob int ttype; 370ea49c6e4SMatt Jacob int tval; 371ea49c6e4SMatt Jacob { 372ea49c6e4SMatt Jacob union { 373ea49c6e4SMatt Jacob at_entry_t _atio; 374ea49c6e4SMatt Jacob at2_entry_t _atio2; 375ea49c6e4SMatt Jacob } atun; 376ea49c6e4SMatt Jacob 377ea49c6e4SMatt Jacob MEMZERO(&atun, sizeof atun); 378ea49c6e4SMatt Jacob if (IS_FC(isp)) { 379ea49c6e4SMatt Jacob atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2; 380ea49c6e4SMatt Jacob atun._atio2.at_header.rqs_entry_count = 1; 381ea49c6e4SMatt Jacob #ifdef ISP2100_SCCLUN 382ea49c6e4SMatt Jacob atun._atio2.at_scclun = (uint16_t) lun; 383ea49c6e4SMatt Jacob #else 384ea49c6e4SMatt Jacob atun._atio2.at_lun = (uint8_t) lun; 385ea49c6e4SMatt Jacob #endif 386ea49c6e4SMatt Jacob atun._atio2.at_status = CT_OK; 387ea49c6e4SMatt Jacob } else { 388ea49c6e4SMatt Jacob atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO; 389ea49c6e4SMatt Jacob atun._atio.at_header.rqs_entry_count = 1; 390ea49c6e4SMatt Jacob atun._atio.at_iid = iid; 391ea49c6e4SMatt Jacob atun._atio.at_tgt = tgt; 392ea49c6e4SMatt Jacob atun._atio.at_lun = lun; 393ea49c6e4SMatt Jacob atun._atio.at_tag_type = ttype; 394ea49c6e4SMatt Jacob atun._atio.at_tag_val = tval; 395ea49c6e4SMatt Jacob atun._atio.at_status = CT_OK; 396ea49c6e4SMatt Jacob } 397ea49c6e4SMatt Jacob return (isp_target_put_entry(isp, &atun)); 398ea49c6e4SMatt Jacob } 399ea49c6e4SMatt Jacob 400ea49c6e4SMatt Jacob /* 401ea49c6e4SMatt Jacob * Command completion- both for handling cases of no resources or 402ea49c6e4SMatt Jacob * no blackhole driver, or other cases where we have to, inline, 403ea49c6e4SMatt Jacob * finish the command sanely, or for normal command completion. 404ea49c6e4SMatt Jacob * 405ea49c6e4SMatt Jacob * The 'completion' code value has the scsi status byte in the low 8 bits. 406ea49c6e4SMatt Jacob * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have 407ea49c6e4SMatt Jacob * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC 408ea49c6e4SMatt Jacob * values. 409ea49c6e4SMatt Jacob * 410ea49c6e4SMatt Jacob * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't 411ea49c6e4SMatt Jacob * NB: inline SCSI sense reporting. 412ea49c6e4SMatt Jacob * 413ea49c6e4SMatt Jacob * For both parallel && fibre channel, we use the feature that does 414ea49c6e4SMatt Jacob * an automatic resource autoreplenish so we don't have then later do 415ea49c6e4SMatt Jacob * put of an atio to replenish the f/w's resource count. 416ea49c6e4SMatt Jacob */ 417ea49c6e4SMatt Jacob 418ea49c6e4SMatt Jacob int 419ea49c6e4SMatt Jacob isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int32_t hdl) 420ea49c6e4SMatt Jacob { 421ea49c6e4SMatt Jacob int sts; 422ea49c6e4SMatt Jacob union { 423ea49c6e4SMatt Jacob ct_entry_t _ctio; 424ea49c6e4SMatt Jacob ct2_entry_t _ctio2; 425ea49c6e4SMatt Jacob } un; 426ea49c6e4SMatt Jacob 427ea49c6e4SMatt Jacob MEMZERO(&un, sizeof un); 428ea49c6e4SMatt Jacob sts = code & 0xff; 429ea49c6e4SMatt Jacob 430ea49c6e4SMatt Jacob if (IS_FC(isp)) { 431ea49c6e4SMatt Jacob at2_entry_t *aep = arg; 432ea49c6e4SMatt Jacob ct2_entry_t *cto = &un._ctio2; 433ea49c6e4SMatt Jacob 434ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 435ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_count = 1; 436ea49c6e4SMatt Jacob cto->ct_iid = aep->at_iid; 437ea49c6e4SMatt Jacob #ifndef ISP2100_SCCLUN 438ea49c6e4SMatt Jacob cto->ct_lun = aep->at_lun; 439ea49c6e4SMatt Jacob #endif 440ea49c6e4SMatt Jacob cto->ct_rxid = aep->at_rxid; 441ea49c6e4SMatt Jacob cto->rsp.m1.ct_scsi_status = sts; 442ea49c6e4SMatt Jacob cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1; 443ea49c6e4SMatt Jacob if (hdl == 0) { 444ea49c6e4SMatt Jacob cto->ct_flags |= CT2_CCINCR; 445ea49c6e4SMatt Jacob } 446ea49c6e4SMatt Jacob if (aep->at_datalen) { 447ea49c6e4SMatt Jacob cto->ct_resid = aep->at_datalen; 448ea49c6e4SMatt Jacob cto->ct_flags |= CT2_DATA_UNDER; 449ea49c6e4SMatt Jacob } 450ea49c6e4SMatt Jacob if (sts == SCSI_CHECK && (sts & 0x100)) { 451ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[0] = 0xf0; 452ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 453ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[7] = 8; 454ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 455ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 456ea49c6e4SMatt Jacob cto->rsp.m1.ct_senselen = 16; 457ea49c6e4SMatt Jacob cto->ct_flags |= CT2_SNSLEN_VALID; 458ea49c6e4SMatt Jacob } 459ea49c6e4SMatt Jacob cto->ct_reserved = hdl; 460ea49c6e4SMatt Jacob } else { 461ea49c6e4SMatt Jacob at_entry_t *aep = arg; 462ea49c6e4SMatt Jacob ct_entry_t *cto = &un._ctio; 463ea49c6e4SMatt Jacob 464ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO; 465ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_count = 1; 466ea49c6e4SMatt Jacob cto->ct_iid = aep->at_iid; 467ea49c6e4SMatt Jacob cto->ct_tgt = aep->at_tgt; 468ea49c6e4SMatt Jacob cto->ct_lun = aep->at_lun; 469ea49c6e4SMatt Jacob cto->ct_tag_type = aep->at_tag_type; 470ea49c6e4SMatt Jacob cto->ct_tag_val = aep->at_tag_val; 471ea49c6e4SMatt Jacob cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA; 472ea49c6e4SMatt Jacob if (hdl == 0) { 473ea49c6e4SMatt Jacob cto->ct_flags |= CT_CCINCR; 474ea49c6e4SMatt Jacob } 475ea49c6e4SMatt Jacob cto->ct_scsi_status = sts; 476ea49c6e4SMatt Jacob cto->ct_reserved = hdl; 477ea49c6e4SMatt Jacob } 478ea49c6e4SMatt Jacob return (isp_target_put_entry(isp, &un)); 479ea49c6e4SMatt Jacob } 480ea49c6e4SMatt Jacob 481ea49c6e4SMatt Jacob void 482ea49c6e4SMatt Jacob isp_target_async(isp, bus, event) 483ea49c6e4SMatt Jacob struct ispsoftc *isp; 484ea49c6e4SMatt Jacob int bus; 485ea49c6e4SMatt Jacob int event; 486ea49c6e4SMatt Jacob { 487ea49c6e4SMatt Jacob tmd_event_t evt; 488ea49c6e4SMatt Jacob tmd_msg_t msg; 489ea49c6e4SMatt Jacob 490ea49c6e4SMatt Jacob switch (event) { 491ea49c6e4SMatt Jacob /* 492ea49c6e4SMatt Jacob * These three we handle here to propagate an effective bus reset 493ea49c6e4SMatt Jacob * upstream, but these do not require any immediate notify actions 494ea49c6e4SMatt Jacob * so we return when done. 495ea49c6e4SMatt Jacob */ 496ea49c6e4SMatt Jacob case ASYNC_LIP_OCCURRED: 497ea49c6e4SMatt Jacob case ASYNC_LOOP_UP: 498ea49c6e4SMatt Jacob case ASYNC_LOOP_DOWN: 499ea49c6e4SMatt Jacob evt.ev_bus = bus; 500ea49c6e4SMatt Jacob evt.ev_event = event; 501ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt); 502ea49c6e4SMatt Jacob return; 503ea49c6e4SMatt Jacob 504ea49c6e4SMatt Jacob case ASYNC_LOOP_RESET: 505ea49c6e4SMatt Jacob case ASYNC_BUS_RESET: 506ea49c6e4SMatt Jacob case ASYNC_TIMEOUT_RESET: 507ea49c6e4SMatt Jacob if (IS_FC(isp)) { 508ea49c6e4SMatt Jacob return; /* we'll be getting an inotify instead */ 509ea49c6e4SMatt Jacob } 510ea49c6e4SMatt Jacob evt.ev_bus = bus; 511ea49c6e4SMatt Jacob evt.ev_event = event; 512ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt); 513ea49c6e4SMatt Jacob break; 514ea49c6e4SMatt Jacob case ASYNC_DEVICE_RESET: 515ea49c6e4SMatt Jacob /* 516ea49c6e4SMatt Jacob * Bus Device Reset resets a specific target, so 517ea49c6e4SMatt Jacob * we pass this as a synthesized message. 518ea49c6e4SMatt Jacob */ 519ea49c6e4SMatt Jacob MEMZERO(&msg, sizeof msg); 520ea49c6e4SMatt Jacob if (IS_FC(isp)) { 521ea49c6e4SMatt Jacob msg.nt_iid = 522ea49c6e4SMatt Jacob ((fcparam *)isp->isp_param)->isp_loopid; 523ea49c6e4SMatt Jacob } else { 524ea49c6e4SMatt Jacob msg.nt_iid = 525ea49c6e4SMatt Jacob ((sdparam *)isp->isp_param)->isp_initiator_id; 526ea49c6e4SMatt Jacob } 527ea49c6e4SMatt Jacob msg.nt_bus = bus; 528ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_BUS_DEV_RESET; 529ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg); 530ea49c6e4SMatt Jacob break; 531ea49c6e4SMatt Jacob default: 532ea49c6e4SMatt Jacob PRINTF("%s: isp_target_async: unknown event 0x%x\n", 533ea49c6e4SMatt Jacob isp->isp_name, event); 534ea49c6e4SMatt Jacob break; 535ea49c6e4SMatt Jacob } 536ea49c6e4SMatt Jacob isp_notify_ack(isp, NULL); 537ea49c6e4SMatt Jacob } 538ea49c6e4SMatt Jacob 539ea49c6e4SMatt Jacob 540ea49c6e4SMatt Jacob /* 541ea49c6e4SMatt Jacob * Process a received message. 542ea49c6e4SMatt Jacob * The ISP firmware can handle most messages, there are only 543ea49c6e4SMatt Jacob * a few that we need to deal with: 544ea49c6e4SMatt Jacob * - abort: clean up the current command 545ea49c6e4SMatt Jacob * - abort tag and clear queue 546ea49c6e4SMatt Jacob */ 547ea49c6e4SMatt Jacob 548ea49c6e4SMatt Jacob static void 549ea49c6e4SMatt Jacob isp_got_msg(isp, bus, inp) 550ea49c6e4SMatt Jacob struct ispsoftc *isp; 551ea49c6e4SMatt Jacob int bus; 552ea49c6e4SMatt Jacob in_entry_t *inp; 553ea49c6e4SMatt Jacob { 554ea49c6e4SMatt Jacob u_int8_t status = inp->in_status & ~QLTM_SVALID; 555ea49c6e4SMatt Jacob 556ea49c6e4SMatt Jacob if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) { 557ea49c6e4SMatt Jacob tmd_msg_t msg; 558ea49c6e4SMatt Jacob 559ea49c6e4SMatt Jacob MEMZERO(&msg, sizeof (msg)); 560ea49c6e4SMatt Jacob msg.nt_bus = bus; 561ea49c6e4SMatt Jacob msg.nt_iid = inp->in_iid; 562ea49c6e4SMatt Jacob msg.nt_tgt = inp->in_tgt; 563ea49c6e4SMatt Jacob msg.nt_lun = inp->in_lun; 564ea49c6e4SMatt Jacob msg.nt_tagtype = inp->in_tag_type; 565ea49c6e4SMatt Jacob msg.nt_tagval = inp->in_tag_val; 566ea49c6e4SMatt Jacob MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN); 567ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg); 568ea49c6e4SMatt Jacob } else { 569ea49c6e4SMatt Jacob PRINTF("%s: unknown immediate notify status 0x%x\n", 570ea49c6e4SMatt Jacob isp->isp_name, inp->in_status); 571ea49c6e4SMatt Jacob } 572ea49c6e4SMatt Jacob } 573ea49c6e4SMatt Jacob 574ea49c6e4SMatt Jacob /* 575ea49c6e4SMatt Jacob * Synthesize a message from the task management flags in a FCP_CMND_IU. 576ea49c6e4SMatt Jacob */ 577ea49c6e4SMatt Jacob static void 578ea49c6e4SMatt Jacob isp_got_msg_fc(isp, bus, inp) 579ea49c6e4SMatt Jacob struct ispsoftc *isp; 580ea49c6e4SMatt Jacob int bus; 581ea49c6e4SMatt Jacob in_fcentry_t *inp; 582ea49c6e4SMatt Jacob { 583ea49c6e4SMatt Jacob static char *f1 = "%s: %s from iid %d lun %d seq 0x%x\n"; 584ea49c6e4SMatt Jacob static char *f2 = 585ea49c6e4SMatt Jacob "%s: unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n"; 586ea49c6e4SMatt Jacob 587ea49c6e4SMatt Jacob if (inp->in_status != IN_MSG_RECEIVED) { 588ea49c6e4SMatt Jacob PRINTF(f2, isp->isp_name, "immediate notify status", 589ea49c6e4SMatt Jacob inp->in_status, inp->in_lun, inp->in_iid, 590ea49c6e4SMatt Jacob inp->in_task_flags, inp->in_seqid); 591ea49c6e4SMatt Jacob } else { 592ea49c6e4SMatt Jacob tmd_msg_t msg; 593ea49c6e4SMatt Jacob 594ea49c6e4SMatt Jacob MEMZERO(&msg, sizeof (msg)); 595ea49c6e4SMatt Jacob msg.nt_bus = bus; 596ea49c6e4SMatt Jacob msg.nt_iid = inp->in_iid; 597ea49c6e4SMatt Jacob #ifdef ISP2100_SCCLUN 598ea49c6e4SMatt Jacob msg.nt_lun = inp->in_scclun; 599ea49c6e4SMatt Jacob #else 600ea49c6e4SMatt Jacob msg.nt_lun = inp->in_lun; 601ea49c6e4SMatt Jacob #endif 602ea49c6e4SMatt Jacob msg.nt_tagval = inp->in_seqid; 603ea49c6e4SMatt Jacob 604ea49c6e4SMatt Jacob if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK) { 605ea49c6e4SMatt Jacob PRINTF(f1, isp->isp_name, "ABORT TASK", 606ea49c6e4SMatt Jacob inp->in_iid, inp->in_lun, inp->in_seqid); 607ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_ABORT_TAG; 608ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) { 609ea49c6e4SMatt Jacob PRINTF(f1, isp->isp_name, "CLEAR TASK SET", 610ea49c6e4SMatt Jacob inp->in_iid, inp->in_lun, inp->in_seqid); 611ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_CLEAR_QUEUE; 612ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) { 613ea49c6e4SMatt Jacob PRINTF(f1, isp->isp_name, "TARGET RESET", 614ea49c6e4SMatt Jacob inp->in_iid, inp->in_lun, inp->in_seqid); 615ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_BUS_DEV_RESET; 616ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) { 617ea49c6e4SMatt Jacob PRINTF(f1, isp->isp_name, "CLEAR ACA", 618ea49c6e4SMatt Jacob inp->in_iid, inp->in_lun, inp->in_seqid); 619ea49c6e4SMatt Jacob /* ???? */ 620ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_REL_RECOVERY; 621ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_TERMINATE_TASK) { 622ea49c6e4SMatt Jacob PRINTF(f1, isp->isp_name, "TERMINATE TASK", 623ea49c6e4SMatt Jacob inp->in_iid, inp->in_lun, inp->in_seqid); 624ea49c6e4SMatt Jacob msg.nt_msg[0] = MSG_TERM_IO_PROC; 625ea49c6e4SMatt Jacob } else { 626ea49c6e4SMatt Jacob PRINTF(f2, isp->isp_name, "task flag", 627ea49c6e4SMatt Jacob inp->in_status, inp->in_lun, inp->in_iid, 628ea49c6e4SMatt Jacob inp->in_task_flags, inp->in_seqid); 629ea49c6e4SMatt Jacob } 630ea49c6e4SMatt Jacob if (msg.nt_msg[0]) { 631ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg); 632ea49c6e4SMatt Jacob } 633ea49c6e4SMatt Jacob } 634ea49c6e4SMatt Jacob } 635ea49c6e4SMatt Jacob 636ea49c6e4SMatt Jacob static void 637ea49c6e4SMatt Jacob isp_notify_ack(isp, arg) 638ea49c6e4SMatt Jacob struct ispsoftc *isp; 639ea49c6e4SMatt Jacob void *arg; 640ea49c6e4SMatt Jacob { 641ea49c6e4SMatt Jacob char storage[QENTRY_LEN]; 642ea49c6e4SMatt Jacob u_int16_t iptr, optr; 643ea49c6e4SMatt Jacob void *outp; 644ea49c6e4SMatt Jacob 645ea49c6e4SMatt Jacob if (isp_getrqentry(isp, &iptr, &optr, &outp)) { 646ea49c6e4SMatt Jacob PRINTF("%s: Request Queue Overflow For isp_notify_ack\n", 647ea49c6e4SMatt Jacob isp->isp_name); 648ea49c6e4SMatt Jacob return; 649ea49c6e4SMatt Jacob } 650ea49c6e4SMatt Jacob 651ea49c6e4SMatt Jacob MEMCPY(storage, arg, sizeof (isphdr_t)); 652ea49c6e4SMatt Jacob MEMZERO(&storage[sizeof (isphdr_t)], QENTRY_LEN - sizeof (isphdr_t)); 653ea49c6e4SMatt Jacob 654ea49c6e4SMatt Jacob if (IS_FC(isp)) { 655ea49c6e4SMatt Jacob na_fcentry_t *na = (na_fcentry_t *) storage; 656ea49c6e4SMatt Jacob if (arg) { 657ea49c6e4SMatt Jacob in_fcentry_t *inp = arg; 658ea49c6e4SMatt Jacob na->na_iid = inp->in_iid; 659ea49c6e4SMatt Jacob #ifdef ISP2100_SCCLUN 660ea49c6e4SMatt Jacob na->na_lun = inp->in_scclun; 661ea49c6e4SMatt Jacob #else 662ea49c6e4SMatt Jacob na->na_lun = inp->in_lun; 663ea49c6e4SMatt Jacob #endif 664ea49c6e4SMatt Jacob na->na_task_flags = inp->in_task_flags; 665ea49c6e4SMatt Jacob na->na_seqid = inp->in_seqid; 666ea49c6e4SMatt Jacob na->na_flags = NAFC_RCOUNT; 667ea49c6e4SMatt Jacob if (inp->in_status == IN_RESET) { 668ea49c6e4SMatt Jacob na->na_flags |= NAFC_RST_CLRD; 669ea49c6e4SMatt Jacob } 670ea49c6e4SMatt Jacob } else { 671ea49c6e4SMatt Jacob na->na_flags = NAFC_RST_CLRD; 672ea49c6e4SMatt Jacob } 673ea49c6e4SMatt Jacob ISP_SWIZ_NOT_ACK_FC(isp, outp, na); 674ea49c6e4SMatt Jacob } else { 675ea49c6e4SMatt Jacob na_entry_t *na = (na_entry_t *) storage; 676ea49c6e4SMatt Jacob if (arg) { 677ea49c6e4SMatt Jacob in_entry_t *inp = arg; 678ea49c6e4SMatt Jacob na->na_iid = inp->in_iid; 679ea49c6e4SMatt Jacob na->na_lun = inp->in_lun; 680ea49c6e4SMatt Jacob na->na_tgt = inp->in_tgt; 681ea49c6e4SMatt Jacob na->na_seqid = inp->in_seqid; 682ea49c6e4SMatt Jacob if (inp->in_status == IN_RESET) { 683ea49c6e4SMatt Jacob na->na_flags = NA_RST_CLRD; 684ea49c6e4SMatt Jacob } 685ea49c6e4SMatt Jacob } else { 686ea49c6e4SMatt Jacob na->na_flags = NA_RST_CLRD; 687ea49c6e4SMatt Jacob } 688ea49c6e4SMatt Jacob ISP_SWIZ_NOT_ACK(isp, outp, na); 689ea49c6e4SMatt Jacob } 690ea49c6e4SMatt Jacob ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage); 691ea49c6e4SMatt Jacob ISP_ADD_REQUEST(isp, iptr); 692ea49c6e4SMatt Jacob } 693ea49c6e4SMatt Jacob 694ea49c6e4SMatt Jacob static void 695ea49c6e4SMatt Jacob isp_handle_atio(isp, aep) 696ea49c6e4SMatt Jacob struct ispsoftc *isp; 697ea49c6e4SMatt Jacob at_entry_t *aep; 698ea49c6e4SMatt Jacob { 699ea49c6e4SMatt Jacob int lun; 700ea49c6e4SMatt Jacob lun = aep->at_lun; 701ea49c6e4SMatt Jacob /* 702ea49c6e4SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) indicates 703ea49c6e4SMatt Jacob * why this ATIO was sent to us. 704ea49c6e4SMatt Jacob * 705ea49c6e4SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 706ea49c6e4SMatt Jacob * 707ea49c6e4SMatt Jacob * If the DISCONNECTS DISABLED bit is set in the flags field, 708ea49c6e4SMatt Jacob * we're still connected on the SCSI bus - i.e. the initiator 709ea49c6e4SMatt Jacob * did not set DiscPriv in the identify message. We don't care 710ea49c6e4SMatt Jacob * about this so it's ignored. 711ea49c6e4SMatt Jacob */ 712ea49c6e4SMatt Jacob 713ea49c6e4SMatt Jacob switch(aep->at_status & ~QLTM_SVALID) { 714ea49c6e4SMatt Jacob case AT_PATH_INVALID: 715ea49c6e4SMatt Jacob /* 716ea49c6e4SMatt Jacob * ATIO rejected by the firmware due to disabled lun. 717ea49c6e4SMatt Jacob */ 718ea49c6e4SMatt Jacob printf("%s: rejected ATIO for disabled lun %d\n", 719ea49c6e4SMatt Jacob isp->isp_name, lun); 720ea49c6e4SMatt Jacob break; 721ea49c6e4SMatt Jacob case AT_NOCAP: 722ea49c6e4SMatt Jacob /* 723ea49c6e4SMatt Jacob * Requested Capability not available 724ea49c6e4SMatt Jacob * We sent an ATIO that overflowed the firmware's 725ea49c6e4SMatt Jacob * command resource count. 726ea49c6e4SMatt Jacob */ 727ea49c6e4SMatt Jacob PRINTF("%s: rejected ATIO for lun %d because of command count" 728ea49c6e4SMatt Jacob " overflow\n", isp->isp_name, lun); 729ea49c6e4SMatt Jacob break; 730ea49c6e4SMatt Jacob 731ea49c6e4SMatt Jacob case AT_BDR_MSG: 732ea49c6e4SMatt Jacob /* 733ea49c6e4SMatt Jacob * If we send an ATIO to the firmware to increment 734ea49c6e4SMatt Jacob * its command resource count, and the firmware is 735ea49c6e4SMatt Jacob * recovering from a Bus Device Reset, it returns 736ea49c6e4SMatt Jacob * the ATIO with this status. We set the command 737ea49c6e4SMatt Jacob * resource count in the Enable Lun entry and no 738ea49c6e4SMatt Jacob * not increment it. Therefore we should never get 739ea49c6e4SMatt Jacob * this status here. 740ea49c6e4SMatt Jacob */ 741ea49c6e4SMatt Jacob printf("%s: ATIO returned for lun %d because it was in the " 742ea49c6e4SMatt Jacob " middle of coping with a Bus Device Reset\n", 743ea49c6e4SMatt Jacob isp->isp_name, lun); 744ea49c6e4SMatt Jacob break; 745ea49c6e4SMatt Jacob 746ea49c6e4SMatt Jacob case AT_CDB: /* Got a CDB */ 747ea49c6e4SMatt Jacob case AT_PHASE_ERROR: /* Bus Phase Sequence Error */ 748ea49c6e4SMatt Jacob /* 749ea49c6e4SMatt Jacob * Punt to platform specific layer. 750ea49c6e4SMatt Jacob */ 751ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 752ea49c6e4SMatt Jacob break; 753ea49c6e4SMatt Jacob 754ea49c6e4SMatt Jacob case AT_RESET: 755ea49c6e4SMatt Jacob /* 756ea49c6e4SMatt Jacob * A bus reset came along an blew away this command. Why 757ea49c6e4SMatt Jacob * they do this in addition the async event code stuff, 758ea49c6e4SMatt Jacob * I dunno. 759ea49c6e4SMatt Jacob * 760ea49c6e4SMatt Jacob * Ignore it because the async event will clear things 761ea49c6e4SMatt Jacob * up for us. 762ea49c6e4SMatt Jacob */ 763ea49c6e4SMatt Jacob PRINTF("%s: ATIO returned for lun %d from initiator %d because" 764ea49c6e4SMatt Jacob " a Bus Reset occurred\n", isp->isp_name, lun, 765ea49c6e4SMatt Jacob aep->at_iid); 766ea49c6e4SMatt Jacob break; 767ea49c6e4SMatt Jacob 768ea49c6e4SMatt Jacob 769ea49c6e4SMatt Jacob default: 770ea49c6e4SMatt Jacob PRINTF("%s: Unknown ATIO status 0x%x from initiator %d for lun" 771ea49c6e4SMatt Jacob " %d\n", isp->isp_name, aep->at_status, aep->at_iid, lun); 772ea49c6e4SMatt Jacob (void) isp_target_put_atio(isp, aep->at_iid, aep->at_tgt, 773ea49c6e4SMatt Jacob lun, aep->at_tag_type, aep->at_tag_val); 774ea49c6e4SMatt Jacob break; 775ea49c6e4SMatt Jacob } 776ea49c6e4SMatt Jacob } 777ea49c6e4SMatt Jacob 778ea49c6e4SMatt Jacob static void 779ea49c6e4SMatt Jacob isp_handle_atio2(isp, aep) 780ea49c6e4SMatt Jacob struct ispsoftc *isp; 781ea49c6e4SMatt Jacob at2_entry_t *aep; 782ea49c6e4SMatt Jacob { 783ea49c6e4SMatt Jacob int lun; 784ea49c6e4SMatt Jacob #ifdef ISP2100_SCCLUN 785ea49c6e4SMatt Jacob lun = aep->at_scclun; 786ea49c6e4SMatt Jacob #else 787ea49c6e4SMatt Jacob lun = aep->at_lun; 788ea49c6e4SMatt Jacob #endif 789ea49c6e4SMatt Jacob /* 790ea49c6e4SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) indicates 791ea49c6e4SMatt Jacob * why this ATIO was sent to us. 792ea49c6e4SMatt Jacob * 793ea49c6e4SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 794ea49c6e4SMatt Jacob * 795ea49c6e4SMatt Jacob * If the DISCONNECTS DISABLED bit is set in the flags field, 796ea49c6e4SMatt Jacob * we're still connected on the SCSI bus - i.e. the initiator 797ea49c6e4SMatt Jacob * did not set DiscPriv in the identify message. We don't care 798ea49c6e4SMatt Jacob * about this so it's ignored. 799ea49c6e4SMatt Jacob */ 800ea49c6e4SMatt Jacob 801ea49c6e4SMatt Jacob switch(aep->at_status & ~QLTM_SVALID) { 802ea49c6e4SMatt Jacob case AT_PATH_INVALID: 803ea49c6e4SMatt Jacob /* 804ea49c6e4SMatt Jacob * ATIO rejected by the firmware due to disabled lun. 805ea49c6e4SMatt Jacob */ 806ea49c6e4SMatt Jacob printf("%s: rejected ATIO2 for disabled lun %d\n", 807ea49c6e4SMatt Jacob isp->isp_name, lun); 808ea49c6e4SMatt Jacob break; 809ea49c6e4SMatt Jacob case AT_NOCAP: 810ea49c6e4SMatt Jacob /* 811ea49c6e4SMatt Jacob * Requested Capability not available 812ea49c6e4SMatt Jacob * We sent an ATIO that overflowed the firmware's 813ea49c6e4SMatt Jacob * command resource count. 814ea49c6e4SMatt Jacob */ 815ea49c6e4SMatt Jacob PRINTF("%s: rejected ATIO2 for lun %d because of command count" 816ea49c6e4SMatt Jacob " overflow\n", isp->isp_name, lun); 817ea49c6e4SMatt Jacob break; 818ea49c6e4SMatt Jacob 819ea49c6e4SMatt Jacob case AT_BDR_MSG: 820ea49c6e4SMatt Jacob /* 821ea49c6e4SMatt Jacob * If we send an ATIO to the firmware to increment 822ea49c6e4SMatt Jacob * its command resource count, and the firmware is 823ea49c6e4SMatt Jacob * recovering from a Bus Device Reset, it returns 824ea49c6e4SMatt Jacob * the ATIO with this status. We set the command 825ea49c6e4SMatt Jacob * resource count in the Enable Lun entry and no 826ea49c6e4SMatt Jacob * not increment it. Therefore we should never get 827ea49c6e4SMatt Jacob * this status here. 828ea49c6e4SMatt Jacob */ 829ea49c6e4SMatt Jacob printf("%s: ATIO2 returned for lun %d because it was in the " 830ea49c6e4SMatt Jacob " middle of coping with a Bus Device Reset\n", 831ea49c6e4SMatt Jacob isp->isp_name, lun); 832ea49c6e4SMatt Jacob break; 833ea49c6e4SMatt Jacob 834ea49c6e4SMatt Jacob case AT_CDB: /* Got a CDB */ 835ea49c6e4SMatt Jacob /* 836ea49c6e4SMatt Jacob * Punt to platform specific layer. 837ea49c6e4SMatt Jacob */ 838ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 839ea49c6e4SMatt Jacob break; 840ea49c6e4SMatt Jacob 841ea49c6e4SMatt Jacob case AT_RESET: 842ea49c6e4SMatt Jacob /* 843ea49c6e4SMatt Jacob * A bus reset came along an blew away this command. Why 844ea49c6e4SMatt Jacob * they do this in addition the async event code stuff, 845ea49c6e4SMatt Jacob * I dunno. 846ea49c6e4SMatt Jacob * 847ea49c6e4SMatt Jacob * Ignore it because the async event will clear things 848ea49c6e4SMatt Jacob * up for us. 849ea49c6e4SMatt Jacob */ 850ea49c6e4SMatt Jacob PRINTF("%s: ATIO2 returned for lun %d from initiator %d because" 851ea49c6e4SMatt Jacob " a Bus Reset occurred\n", isp->isp_name, lun, 852ea49c6e4SMatt Jacob aep->at_iid); 853ea49c6e4SMatt Jacob break; 854ea49c6e4SMatt Jacob 855ea49c6e4SMatt Jacob 856ea49c6e4SMatt Jacob default: 857ea49c6e4SMatt Jacob PRINTF("%s: Unknown ATIO2 status 0x%x from initiator %d for lun" 858ea49c6e4SMatt Jacob " %d\n", isp->isp_name, aep->at_status, aep->at_iid, lun); 859ea49c6e4SMatt Jacob (void) isp_target_put_atio(isp, aep->at_iid, 0, lun, 0, 0); 860ea49c6e4SMatt Jacob break; 861ea49c6e4SMatt Jacob } 862ea49c6e4SMatt Jacob } 863ea49c6e4SMatt Jacob 864ea49c6e4SMatt Jacob static void 865ea49c6e4SMatt Jacob isp_handle_ctio(isp, ct) 866ea49c6e4SMatt Jacob struct ispsoftc *isp; 867ea49c6e4SMatt Jacob ct_entry_t *ct; 868ea49c6e4SMatt Jacob { 869ea49c6e4SMatt Jacob ISP_SCSI_XFER_T *xs; 870ea49c6e4SMatt Jacob int pl = 0; 871ea49c6e4SMatt Jacob char *fmsg = NULL; 872ea49c6e4SMatt Jacob 873ea49c6e4SMatt Jacob if (ct->ct_reserved) { 874ea49c6e4SMatt Jacob xs = isp_find_xs(isp, ct->ct_reserved); 875ea49c6e4SMatt Jacob if (xs == NULL) 876ea49c6e4SMatt Jacob pl = 0; 877ea49c6e4SMatt Jacob } else { 878ea49c6e4SMatt Jacob pl = 2; 879ea49c6e4SMatt Jacob xs = NULL; 880ea49c6e4SMatt Jacob } 881ea49c6e4SMatt Jacob 882ea49c6e4SMatt Jacob switch(ct->ct_status & ~QLTM_SVALID) { 883ea49c6e4SMatt Jacob case CT_OK: 884ea49c6e4SMatt Jacob /* 885ea49c6e4SMatt Jacob * There are generally 3 possibilities as to why we'd get 886ea49c6e4SMatt Jacob * this condition: 887ea49c6e4SMatt Jacob * We disconnected after receiving a CDB. 888ea49c6e4SMatt Jacob * We sent or received data. 889ea49c6e4SMatt Jacob * We sent status & command complete. 890ea49c6e4SMatt Jacob */ 891ea49c6e4SMatt Jacob 892ea49c6e4SMatt Jacob if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) { 893ea49c6e4SMatt Jacob /* 894ea49c6e4SMatt Jacob * Nothing to do in this case. 895ea49c6e4SMatt Jacob */ 896ea49c6e4SMatt Jacob IDPRINTF(pl, ("%s: CTIO- initiator disconnected OK\n", 897ea49c6e4SMatt Jacob isp->isp_name)); 898ea49c6e4SMatt Jacob return; 899ea49c6e4SMatt Jacob } 900ea49c6e4SMatt Jacob break; 901ea49c6e4SMatt Jacob 902ea49c6e4SMatt Jacob case CT_BDR_MSG: 903ea49c6e4SMatt Jacob /* 904ea49c6e4SMatt Jacob * Bus Device Reset message received or the SCSI Bus has 905ea49c6e4SMatt Jacob * been Reset; the firmware has gone to Bus Free. 906ea49c6e4SMatt Jacob * 907ea49c6e4SMatt Jacob * The firmware generates an async mailbox interupt to 908ea49c6e4SMatt Jacob * notify us of this and returns outstanding CTIOs with this 909ea49c6e4SMatt Jacob * status. These CTIOs are handled in that same way as 910ea49c6e4SMatt Jacob * CT_ABORTED ones, so just fall through here. 911ea49c6e4SMatt Jacob */ 912ea49c6e4SMatt Jacob fmsg = "Bus Device Reset"; 913ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 914ea49c6e4SMatt Jacob case CT_RESET: 915ea49c6e4SMatt Jacob if (fmsg == NULL) 916ea49c6e4SMatt Jacob fmsg = "Bus Reset"; 917ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 918ea49c6e4SMatt Jacob case CT_ABORTED: 919ea49c6e4SMatt Jacob /* 920ea49c6e4SMatt Jacob * When an Abort message is received the firmware goes to 921ea49c6e4SMatt Jacob * Bus Free and returns all outstanding CTIOs with the status 922ea49c6e4SMatt Jacob * set, then sends us an Immediate Notify entry. 923ea49c6e4SMatt Jacob */ 924ea49c6e4SMatt Jacob if (fmsg == NULL) 925ea49c6e4SMatt Jacob fmsg = "ABORT TASK sent by Initiator"; 926ea49c6e4SMatt Jacob 927ea49c6e4SMatt Jacob PRINTF("%s: CTIO destroyed by %s\n", isp->isp_name, fmsg); 928ea49c6e4SMatt Jacob break; 929ea49c6e4SMatt Jacob 930ea49c6e4SMatt Jacob case CT_INVAL: 931ea49c6e4SMatt Jacob /* 932ea49c6e4SMatt Jacob * CTIO rejected by the firmware due to disabled lun. 933ea49c6e4SMatt Jacob * "Cannot Happen". 934ea49c6e4SMatt Jacob */ 935ea49c6e4SMatt Jacob PRINTF("%s: Firmware rejected CTIO for disabled lun %d\n", 936ea49c6e4SMatt Jacob isp->isp_name, ct->ct_lun); 937ea49c6e4SMatt Jacob break; 938ea49c6e4SMatt Jacob 939ea49c6e4SMatt Jacob case CT_NOPATH: 940ea49c6e4SMatt Jacob /* 941ea49c6e4SMatt Jacob * CTIO rejected by the firmware due "no path for the 942ea49c6e4SMatt Jacob * nondisconnecting nexus specified". This means that 943ea49c6e4SMatt Jacob * we tried to access the bus while a non-disconnecting 944ea49c6e4SMatt Jacob * command is in process. 945ea49c6e4SMatt Jacob */ 946ea49c6e4SMatt Jacob PRINTF("%s: Firmware rejected CTIO for bad nexus %d/%d/%d\n", 947ea49c6e4SMatt Jacob isp->isp_name, ct->ct_iid, ct->ct_tgt, ct->ct_lun); 948ea49c6e4SMatt Jacob break; 949ea49c6e4SMatt Jacob 950ea49c6e4SMatt Jacob case CT_RSELTMO: 951ea49c6e4SMatt Jacob fmsg = "Reselection"; 952ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 953ea49c6e4SMatt Jacob case CT_TIMEOUT: 954ea49c6e4SMatt Jacob if (fmsg == NULL) 955ea49c6e4SMatt Jacob fmsg = "Command"; 956ea49c6e4SMatt Jacob PRINTF("%s: Firmware timed out on %s\n", isp->isp_name, fmsg); 957ea49c6e4SMatt Jacob break; 958ea49c6e4SMatt Jacob 959ea49c6e4SMatt Jacob case CT_ERR: 960ea49c6e4SMatt Jacob fmsg = "Completed with Error"; 961ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 962ea49c6e4SMatt Jacob case CT_PHASE_ERROR: 963ea49c6e4SMatt Jacob if (fmsg == NULL) 964ea49c6e4SMatt Jacob fmsg = "Phase Sequence Error"; 965ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 966ea49c6e4SMatt Jacob case CT_TERMINATED: 967ea49c6e4SMatt Jacob if (fmsg == NULL) 968ea49c6e4SMatt Jacob fmsg = "terminated by TERMINATE TRANSFER"; 969ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 970ea49c6e4SMatt Jacob case CT_NOACK: 971ea49c6e4SMatt Jacob if (fmsg == NULL) 972ea49c6e4SMatt Jacob fmsg = "unacknowledged Immediate Notify pending"; 973ea49c6e4SMatt Jacob 974ea49c6e4SMatt Jacob PRINTF("%s: CTIO returned by f/w- %s\n", isp->isp_name, fmsg); 975ea49c6e4SMatt Jacob #if 0 976ea49c6e4SMatt Jacob if (status & SENSEVALID) { 977ea49c6e4SMatt Jacob bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET), 978ea49c6e4SMatt Jacob (caddr_t) &cdp->cd_sensedata, 979ea49c6e4SMatt Jacob sizeof(scsi_sense_t)); 980ea49c6e4SMatt Jacob cdp->cd_flags |= CDF_SENSEVALID; 981ea49c6e4SMatt Jacob } 982ea49c6e4SMatt Jacob #endif 983ea49c6e4SMatt Jacob break; 984ea49c6e4SMatt Jacob default: 985ea49c6e4SMatt Jacob PRINTF("%s: Unknown CTIO status 0x%x\n", isp->isp_name, 986ea49c6e4SMatt Jacob ct->ct_status & ~QLTM_SVALID); 987ea49c6e4SMatt Jacob break; 988ea49c6e4SMatt Jacob } 989ea49c6e4SMatt Jacob 990ea49c6e4SMatt Jacob if (xs == NULL) { 991ea49c6e4SMatt Jacob /* 992ea49c6e4SMatt Jacob * There may be more than one CTIO for a data transfer, 993ea49c6e4SMatt Jacob * or this may be a status CTIO we're not monitoring. 994ea49c6e4SMatt Jacob * 995ea49c6e4SMatt Jacob * The assumption is that they'll all be returned in the 996ea49c6e4SMatt Jacob * order we got them. 997ea49c6e4SMatt Jacob */ 998ea49c6e4SMatt Jacob if (ct->ct_reserved == 0) { 999ea49c6e4SMatt Jacob if ((ct->ct_flags & CT_SENDSTATUS) == 0) { 1000ea49c6e4SMatt Jacob IDPRINTF(pl, 1001ea49c6e4SMatt Jacob ("%s: intermediate CTIO completed ok\n", 1002ea49c6e4SMatt Jacob isp->isp_name)); 1003ea49c6e4SMatt Jacob } else { 1004ea49c6e4SMatt Jacob IDPRINTF(pl, 1005ea49c6e4SMatt Jacob ("%s: unmonitored CTIO completed ok\n", 1006ea49c6e4SMatt Jacob isp->isp_name)); 1007ea49c6e4SMatt Jacob } 1008ea49c6e4SMatt Jacob } else { 1009ea49c6e4SMatt Jacob IDPRINTF(pl, 1010ea49c6e4SMatt Jacob ("%s: NO xs for CTIO (handle 0x%x) status 0x%x\n", 1011ea49c6e4SMatt Jacob isp->isp_name, ct->ct_reserved, 1012ea49c6e4SMatt Jacob ct->ct_status & ~QLTM_SVALID)); 1013ea49c6e4SMatt Jacob } 1014ea49c6e4SMatt Jacob } else { 1015ea49c6e4SMatt Jacob if (ct->ct_flags & CT_SENDSTATUS) { 1016ea49c6e4SMatt Jacob /* 1017ea49c6e4SMatt Jacob * Sent status and command complete. 1018ea49c6e4SMatt Jacob * 1019ea49c6e4SMatt Jacob * We're now really done with this command, so we 1020ea49c6e4SMatt Jacob * punt to the platform dependent layers because 1021ea49c6e4SMatt Jacob * only there can we do the appropriate command 1022ea49c6e4SMatt Jacob * complete thread synchronization. 1023ea49c6e4SMatt Jacob */ 1024ea49c6e4SMatt Jacob IDPRINTF(pl, 1025ea49c6e4SMatt Jacob ("%s: status CTIO complete\n", isp->isp_name)); 1026ea49c6e4SMatt Jacob } else { 1027ea49c6e4SMatt Jacob /* 1028ea49c6e4SMatt Jacob * Final CTIO completed. Release DMA resources and 1029ea49c6e4SMatt Jacob * notify platform dependent layers. 1030ea49c6e4SMatt Jacob */ 1031ea49c6e4SMatt Jacob IDPRINTF(pl, 1032ea49c6e4SMatt Jacob ("%s: data CTIO complete\n", isp->isp_name)); 1033ea49c6e4SMatt Jacob ISP_DMAFREE(isp, xs, ct->ct_reserved); 1034ea49c6e4SMatt Jacob } 1035ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1036ea49c6e4SMatt Jacob /* 1037ea49c6e4SMatt Jacob * The platform layer will destroy the handle if appropriate. 1038ea49c6e4SMatt Jacob */ 1039ea49c6e4SMatt Jacob } 1040ea49c6e4SMatt Jacob } 1041ea49c6e4SMatt Jacob 1042ea49c6e4SMatt Jacob static void 1043ea49c6e4SMatt Jacob isp_handle_ctio2(isp, ct) 1044ea49c6e4SMatt Jacob struct ispsoftc *isp; 1045ea49c6e4SMatt Jacob ct2_entry_t *ct; 1046ea49c6e4SMatt Jacob { 1047ea49c6e4SMatt Jacob ISP_SCSI_XFER_T *xs; 1048ea49c6e4SMatt Jacob int pl = 3; 1049ea49c6e4SMatt Jacob char *fmsg = NULL; 1050ea49c6e4SMatt Jacob 1051ea49c6e4SMatt Jacob if (ct->ct_reserved) { 1052ea49c6e4SMatt Jacob xs = isp_find_xs(isp, ct->ct_reserved); 1053ea49c6e4SMatt Jacob if (xs == NULL) 1054ea49c6e4SMatt Jacob pl = 0; 1055ea49c6e4SMatt Jacob } else { 1056ea49c6e4SMatt Jacob pl = 2; 1057ea49c6e4SMatt Jacob xs = NULL; 1058ea49c6e4SMatt Jacob } 1059ea49c6e4SMatt Jacob 1060ea49c6e4SMatt Jacob switch(ct->ct_status & ~QLTM_SVALID) { 1061ea49c6e4SMatt Jacob case CT_OK: 1062ea49c6e4SMatt Jacob /* 1063ea49c6e4SMatt Jacob * There are generally 2 possibilities as to why we'd get 1064ea49c6e4SMatt Jacob * this condition: 1065ea49c6e4SMatt Jacob * We sent or received data. 1066ea49c6e4SMatt Jacob * We sent status & command complete. 1067ea49c6e4SMatt Jacob */ 1068ea49c6e4SMatt Jacob 1069ea49c6e4SMatt Jacob break; 1070ea49c6e4SMatt Jacob 1071ea49c6e4SMatt Jacob case CT_BDR_MSG: 1072ea49c6e4SMatt Jacob /* 1073ea49c6e4SMatt Jacob * Bus Device Reset message received or the SCSI Bus has 1074ea49c6e4SMatt Jacob * been Reset; the firmware has gone to Bus Free. 1075ea49c6e4SMatt Jacob * 1076ea49c6e4SMatt Jacob * The firmware generates an async mailbox interupt to 1077ea49c6e4SMatt Jacob * notify us of this and returns outstanding CTIOs with this 1078ea49c6e4SMatt Jacob * status. These CTIOs are handled in that same way as 1079ea49c6e4SMatt Jacob * CT_ABORTED ones, so just fall through here. 1080ea49c6e4SMatt Jacob */ 1081ea49c6e4SMatt Jacob fmsg = "Bus Device Reset"; 1082ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1083ea49c6e4SMatt Jacob case CT_RESET: 1084ea49c6e4SMatt Jacob if (fmsg == NULL) 1085ea49c6e4SMatt Jacob fmsg = "Bus Reset"; 1086ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1087ea49c6e4SMatt Jacob case CT_ABORTED: 1088ea49c6e4SMatt Jacob /* 1089ea49c6e4SMatt Jacob * When an Abort message is received the firmware goes to 1090ea49c6e4SMatt Jacob * Bus Free and returns all outstanding CTIOs with the status 1091ea49c6e4SMatt Jacob * set, then sends us an Immediate Notify entry. 1092ea49c6e4SMatt Jacob */ 1093ea49c6e4SMatt Jacob if (fmsg == NULL) 1094ea49c6e4SMatt Jacob fmsg = "ABORT TASK sent by Initiator"; 1095ea49c6e4SMatt Jacob 1096ea49c6e4SMatt Jacob PRINTF("%s: CTIO2 destroyed by %s\n", isp->isp_name, fmsg); 1097ea49c6e4SMatt Jacob break; 1098ea49c6e4SMatt Jacob 1099ea49c6e4SMatt Jacob case CT_INVAL: 1100ea49c6e4SMatt Jacob /* 1101ea49c6e4SMatt Jacob * CTIO rejected by the firmware due to disabled lun. 1102ea49c6e4SMatt Jacob * "Cannot Happen". 1103ea49c6e4SMatt Jacob */ 1104ea49c6e4SMatt Jacob PRINTF("%s: Firmware rejected CTIO2 for disabled lun %d\n", 1105ea49c6e4SMatt Jacob isp->isp_name, ct->ct_lun); 1106ea49c6e4SMatt Jacob break; 1107ea49c6e4SMatt Jacob 1108ea49c6e4SMatt Jacob case CT_NOPATH: 1109ea49c6e4SMatt Jacob /* 1110ea49c6e4SMatt Jacob * CTIO rejected by the firmware due "no path for the 1111ea49c6e4SMatt Jacob * nondisconnecting nexus specified". This means that 1112ea49c6e4SMatt Jacob * we tried to access the bus while a non-disconnecting 1113ea49c6e4SMatt Jacob * command is in process. 1114ea49c6e4SMatt Jacob */ 1115ea49c6e4SMatt Jacob PRINTF("%s: Firmware rejected CTIO2 for bad nexus %d->%d\n", 1116ea49c6e4SMatt Jacob isp->isp_name, ct->ct_iid, ct->ct_lun); 1117ea49c6e4SMatt Jacob break; 1118ea49c6e4SMatt Jacob 1119ea49c6e4SMatt Jacob case CT_RSELTMO: 1120ea49c6e4SMatt Jacob fmsg = "Reselection"; 1121ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1122ea49c6e4SMatt Jacob case CT_TIMEOUT: 1123ea49c6e4SMatt Jacob if (fmsg == NULL) 1124ea49c6e4SMatt Jacob fmsg = "Command"; 1125ea49c6e4SMatt Jacob PRINTF("%s: Firmware timed out on %s\n", isp->isp_name, fmsg); 1126ea49c6e4SMatt Jacob break; 1127ea49c6e4SMatt Jacob 1128ea49c6e4SMatt Jacob case CT_ERR: 1129ea49c6e4SMatt Jacob fmsg = "Completed with Error"; 1130ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1131ea49c6e4SMatt Jacob case CT_PHASE_ERROR: /* Bus phase sequence error */ 1132ea49c6e4SMatt Jacob if (fmsg == NULL) 1133ea49c6e4SMatt Jacob fmsg = "Phase Sequence Error"; 1134ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1135ea49c6e4SMatt Jacob case CT_TERMINATED: 1136ea49c6e4SMatt Jacob if (fmsg == NULL) 1137ea49c6e4SMatt Jacob fmsg = "terminated by TERMINATE TRANSFER"; 1138ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1139ea49c6e4SMatt Jacob case CT_LOGOUT: 1140ea49c6e4SMatt Jacob if (fmsg == NULL) 1141ea49c6e4SMatt Jacob fmsg = "Port Logout"; 1142ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1143ea49c6e4SMatt Jacob case CT_PORTNOTAVAIL: 1144ea49c6e4SMatt Jacob if (fmsg == NULL) 1145ea49c6e4SMatt Jacob fmsg = "Port not available"; 1146ea49c6e4SMatt Jacob case CT_NOACK: 1147ea49c6e4SMatt Jacob if (fmsg == NULL) 1148ea49c6e4SMatt Jacob fmsg = "unacknowledged Immediate Notify pending"; 1149ea49c6e4SMatt Jacob 1150ea49c6e4SMatt Jacob PRINTF("%s: CTIO returned by f/w- %s\n", isp->isp_name, fmsg); 1151ea49c6e4SMatt Jacob #if 0 1152ea49c6e4SMatt Jacob if (status & SENSEVALID) { 1153ea49c6e4SMatt Jacob bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET), 1154ea49c6e4SMatt Jacob (caddr_t) &cdp->cd_sensedata, 1155ea49c6e4SMatt Jacob sizeof(scsi_sense_t)); 1156ea49c6e4SMatt Jacob cdp->cd_flags |= CDF_SENSEVALID; 1157ea49c6e4SMatt Jacob } 1158ea49c6e4SMatt Jacob #endif 1159ea49c6e4SMatt Jacob break; 1160ea49c6e4SMatt Jacob 1161ea49c6e4SMatt Jacob case CT_INVRXID: 1162ea49c6e4SMatt Jacob /* 1163ea49c6e4SMatt Jacob * CTIO rejected by the firmware because an invalid RX_ID. 1164ea49c6e4SMatt Jacob * Just print a message. 1165ea49c6e4SMatt Jacob */ 1166ea49c6e4SMatt Jacob PRINTF("%s: CTIO2 completed with Invalid RX_ID 0x%x", 1167ea49c6e4SMatt Jacob isp->isp_name, ct->ct_rxid); 1168ea49c6e4SMatt Jacob break; 1169ea49c6e4SMatt Jacob 1170ea49c6e4SMatt Jacob default: 1171ea49c6e4SMatt Jacob IDPRINTF(pl, ("%s: Unknown CTIO status 0x%x\n", isp->isp_name, 1172ea49c6e4SMatt Jacob ct->ct_status & ~QLTM_SVALID)); 1173ea49c6e4SMatt Jacob break; 1174ea49c6e4SMatt Jacob } 1175ea49c6e4SMatt Jacob 1176ea49c6e4SMatt Jacob if (xs == NULL) { 1177ea49c6e4SMatt Jacob /* 1178ea49c6e4SMatt Jacob * There may be more than one CTIO for a data transfer, 1179ea49c6e4SMatt Jacob * or this may be a status CTIO we're not monitoring. 1180ea49c6e4SMatt Jacob * 1181ea49c6e4SMatt Jacob * The assumption is that they'll all be returned in the 1182ea49c6e4SMatt Jacob * order we got them. 1183ea49c6e4SMatt Jacob */ 1184ea49c6e4SMatt Jacob if (ct->ct_reserved == 0) { 1185ea49c6e4SMatt Jacob if ((ct->ct_flags & CT_SENDSTATUS) == 0) { 1186ea49c6e4SMatt Jacob IDPRINTF(pl, 1187ea49c6e4SMatt Jacob ("%s: intermediate CTIO completed ok\n", 1188ea49c6e4SMatt Jacob isp->isp_name)); 1189ea49c6e4SMatt Jacob } else { 1190ea49c6e4SMatt Jacob IDPRINTF(pl, 1191ea49c6e4SMatt Jacob ("%s: unmonitored CTIO completed ok\n", 1192ea49c6e4SMatt Jacob isp->isp_name)); 1193ea49c6e4SMatt Jacob } 1194ea49c6e4SMatt Jacob } else { 1195ea49c6e4SMatt Jacob IDPRINTF(pl, 1196ea49c6e4SMatt Jacob ("%s: NO xs for CTIO (handle 0x%x) status 0x%x\n", 1197ea49c6e4SMatt Jacob isp->isp_name, ct->ct_reserved, 1198ea49c6e4SMatt Jacob ct->ct_status & ~QLTM_SVALID)); 1199ea49c6e4SMatt Jacob } 1200ea49c6e4SMatt Jacob } else { 1201ea49c6e4SMatt Jacob if (ct->ct_flags & CT_SENDSTATUS) { 1202ea49c6e4SMatt Jacob /* 1203ea49c6e4SMatt Jacob * Sent status and command complete. 1204ea49c6e4SMatt Jacob * 1205ea49c6e4SMatt Jacob * We're now really done with this command, so we 1206ea49c6e4SMatt Jacob * punt to the platform dependent layers because 1207ea49c6e4SMatt Jacob * only there can we do the appropriate command 1208ea49c6e4SMatt Jacob * complete thread synchronization. 1209ea49c6e4SMatt Jacob */ 1210ea49c6e4SMatt Jacob IDPRINTF(pl, 1211ea49c6e4SMatt Jacob ("%s: status CTIO complete\n", isp->isp_name)); 1212ea49c6e4SMatt Jacob } else { 1213ea49c6e4SMatt Jacob /* 1214ea49c6e4SMatt Jacob * Final CTIO completed. Release DMA resources and 1215ea49c6e4SMatt Jacob * notify platform dependent layers. 1216ea49c6e4SMatt Jacob */ 1217ea49c6e4SMatt Jacob IDPRINTF(pl, 1218ea49c6e4SMatt Jacob ("%s: data CTIO complete\n", isp->isp_name)); 1219ea49c6e4SMatt Jacob ISP_DMAFREE(isp, xs, ct->ct_reserved); 1220ea49c6e4SMatt Jacob } 1221ea49c6e4SMatt Jacob (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1222ea49c6e4SMatt Jacob /* 1223ea49c6e4SMatt Jacob * The platform layer will destroy the handle if appropriate. 1224ea49c6e4SMatt Jacob */ 1225ea49c6e4SMatt Jacob } 1226ea49c6e4SMatt Jacob } 1227ea49c6e4SMatt Jacob #endif 1228