1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2009-2020 Alexander Motin <mav@FreeBSD.org> 5 * Copyright (c) 1997-2009 by Matthew Jacob 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 */ 31 /* 32 * Machine and OS Independent Target Mode Code for the Qlogic FC adapters. 33 */ 34 /* 35 * Bug fixes gratefully acknowledged from: 36 * Oded Kedem <oded@kashya.com> 37 */ 38 /* 39 * Include header file appropriate for platform we're building on. 40 */ 41 42 #ifdef __NetBSD__ 43 #include <dev/ic/isp_netbsd.h> 44 #endif 45 #ifdef __FreeBSD__ 46 #include <sys/cdefs.h> 47 #include <dev/isp/isp_freebsd.h> 48 #endif 49 #ifdef __OpenBSD__ 50 #include <dev/ic/isp_openbsd.h> 51 #endif 52 #ifdef __linux__ 53 #include "isp_linux.h" 54 #endif 55 56 #ifdef ISP_TARGET_MODE 57 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *); 58 static void isp_handle_abts(ispsoftc_t *, abts_t *); 59 static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *); 60 static void isp_handle_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *); 61 62 /* 63 * The Qlogic driver gets an interrupt to look at response queue entries. 64 * Some of these are status completions for initiatior mode commands, but 65 * if target mode is enabled, we get a whole wad of response queue entries 66 * to be handled here. 67 * 68 * Basically the split into 3 main groups: Lun Enable/Modification responses, 69 * SCSI Command processing, and Immediate Notification events. 70 * 71 * You start by writing a request queue entry to enable target mode (and 72 * establish some resource limitations which you can modify later). 73 * The f/w responds with a LUN ENABLE or LUN MODIFY response with 74 * the status of this action. If the enable was successful, you can expect... 75 * 76 * Response queue entries with SCSI commands encapsulate show up in an ATIO 77 * (Accept Target IO) type- sometimes with enough info to stop the command at 78 * this level. Ultimately the driver has to feed back to the f/w's request 79 * queue a sequence of CTIOs (continue target I/O) that describe data to 80 * be moved and/or status to be sent) and finally finishing with sending 81 * to the f/w's response queue an ATIO which then completes the handshake 82 * with the f/w for that command. There's a lot of variations on this theme, 83 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel 84 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic 85 * gist of it. 86 * 87 * The third group that can show up in the response queue are Immediate 88 * Notification events. These include things like notifications of SCSI bus 89 * resets, or Bus Device Reset messages or other messages received. This 90 * a classic oddbins area. It can get a little weird because you then turn 91 * around and acknowledge the Immediate Notify by writing an entry onto the 92 * request queue and then the f/w turns around and gives you an acknowledgement 93 * to *your* acknowledgement on the response queue (the idea being to let 94 * the f/w tell you when the event is *really* over I guess). 95 * 96 */ 97 98 99 /* 100 * A new response queue entry has arrived. The interrupt service code 101 * has already swizzled it into the platform dependent from canonical form. 102 * 103 * Because of the way this driver is designed, unfortunately most of the 104 * actual synchronization work has to be done in the platform specific 105 * code- we have no synchroniation primitives in the common code. 106 */ 107 108 int 109 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp, uint16_t ql) 110 { 111 union { 112 at7_entry_t *at7iop; 113 ct7_entry_t *ct7iop; 114 in_fcentry_24xx_t *inot_24xx; 115 na_fcentry_24xx_t *nack_24xx; 116 isphdr_t *hp; 117 abts_t *abts; 118 abts_rsp_t *abts_rsp; 119 void * *vp; 120 #define at7iop unp.at7iop 121 #define ct7iop unp.ct7iop 122 #define inot_24xx unp.inot_24xx 123 #define nack_24xx unp.nack_24xx 124 #define abts unp.abts 125 #define abts_rsp unp.abts_rsp 126 #define hdrp unp.hp 127 } unp; 128 uint8_t local[QENTRY_LEN]; 129 int type, len, level, rval = 1; 130 131 type = isp_get_response_type(isp, (isphdr_t *)vptr); 132 unp.vp = vptr; 133 134 if (isp->isp_dblev & ISP_LOGTDEBUG2) 135 isp_print_qentry(isp, __func__, *optrp, vptr); 136 137 switch (type) { 138 case RQSTYPE_ATIO: 139 isp_get_atio7(isp, at7iop, (at7_entry_t *) local); 140 at7iop = (at7_entry_t *) local; 141 /* 142 * Check for and do something with commands whose 143 * IULEN extends past a single queue entry. 144 */ 145 len = at7iop->at_ta_len & 0x0fff; 146 if (len > (QENTRY_LEN - 8)) { 147 len -= (QENTRY_LEN - 8); 148 isp_prt(isp, ISP_LOGINFO, "long IU length (%d) ignored", len); 149 while (len > 0) { 150 *optrp = ISP_NXT_QENTRY(*optrp, ql); 151 len -= QENTRY_LEN; 152 } 153 } 154 /* 155 * Check for a task management function 156 */ 157 if (at7iop->at_cmnd.fcp_cmnd_task_management) { 158 isp_got_tmf_24xx(isp, at7iop); 159 break; 160 } 161 /* 162 * Just go straight to outer layer for this one. 163 */ 164 isp_async(isp, ISPASYNC_TARGET_ACTION, local); 165 break; 166 167 case RQSTYPE_CTIO7: 168 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local); 169 isp_handle_ctio7(isp, (ct7_entry_t *) local); 170 break; 171 172 case RQSTYPE_NOTIFY: 173 isp_get_notify_24xx(isp, inot_24xx, (in_fcentry_24xx_t *)local); 174 isp_handle_notify_24xx(isp, (in_fcentry_24xx_t *)local); 175 break; 176 177 case RQSTYPE_NOTIFY_ACK: 178 /* 179 * The ISP is acknowledging our acknowledgement of an 180 * Immediate Notify entry for some asynchronous event. 181 */ 182 isp_get_notify_ack_24xx(isp, nack_24xx, (na_fcentry_24xx_t *) local); 183 nack_24xx = (na_fcentry_24xx_t *) local; 184 if (nack_24xx->na_status != NA_OK) 185 level = ISP_LOGINFO; 186 else 187 level = ISP_LOGTDEBUG1; 188 isp_prt(isp, level, "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x", nack_24xx->na_status, nack_24xx->na_status_subcode, nack_24xx->na_rxid); 189 break; 190 191 case RQSTYPE_ABTS_RCVD: 192 isp_get_abts(isp, abts, (abts_t *)local); 193 isp_handle_abts(isp, (abts_t *)local); 194 break; 195 case RQSTYPE_ABTS_RSP: 196 isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local); 197 abts_rsp = (abts_rsp_t *) local; 198 if (abts_rsp->abts_rsp_status) 199 level = ISP_LOGINFO; 200 else 201 level = ISP_LOGTDEBUG0; 202 isp_prt(isp, level, "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)", abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status, 203 abts_rsp->abts_rsp_payload.rsp.subcode1, abts_rsp->abts_rsp_payload.rsp.subcode2); 204 break; 205 default: 206 isp_prt(isp, ISP_LOGERR, "%s: unknown entry type 0x%x", __func__, type); 207 rval = 0; 208 break; 209 } 210 #undef at7iop 211 #undef ct7iop 212 #undef inot_24xx 213 #undef hack_24xx 214 #undef abts 215 #undef abts_rsp 216 #undef hdrp 217 return (rval); 218 } 219 220 /* 221 * Command completion- both for handling cases of no resources or 222 * no blackhole driver, or other cases where we have to, inline, 223 * finish the command sanely, or for normal command completion. 224 * 225 * The 'completion' code value has the scsi status byte in the low 8 bits. 226 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have 227 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC 228 * values. 229 * 230 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't 231 * NB: inline SCSI sense reporting. As such, we lose this information. XXX. 232 * 233 * For both parallel && fibre channel, we use the feature that does 234 * an automatic resource autoreplenish so we don't have then later do 235 * put of an atio to replenish the f/w's resource count. 236 */ 237 238 int 239 isp_endcmd(ispsoftc_t *isp, ...) 240 { 241 uint32_t code, hdl; 242 uint8_t sts; 243 at7_entry_t *aep; 244 ct7_entry_t _ctio7, *cto = &_ctio7; 245 va_list ap; 246 int vpidx, nphdl; 247 248 va_start(ap, isp); 249 aep = va_arg(ap, at7_entry_t *); 250 nphdl = va_arg(ap, int); 251 /* 252 * Note that vpidx may equal 0xff (unknown) here 253 */ 254 vpidx = va_arg(ap, int); 255 code = va_arg(ap, uint32_t); 256 hdl = va_arg(ap, uint32_t); 257 va_end(ap); 258 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] chan %d code %x", __func__, aep->at_rxid, vpidx, code); 259 260 sts = code & 0xff; 261 ISP_MEMZERO(cto, sizeof(*cto)); 262 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 263 cto->ct_header.rqs_entry_count = 1; 264 cto->ct_nphdl = nphdl; 265 cto->ct_rxid = aep->at_rxid; 266 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2]; 267 cto->ct_iid_hi = aep->at_hdr.s_id[0]; 268 cto->ct_oxid = aep->at_hdr.ox_id; 269 cto->ct_scsi_status = sts; 270 cto->ct_vpidx = vpidx; 271 cto->ct_flags = CT7_NOACK; 272 if (code & ECMD_TERMINATE) { 273 cto->ct_flags |= CT7_TERMINATE; 274 } else if (code & ECMD_SVALID) { 275 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS; 276 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8); 277 cto->ct_senselen = min(16, MAXRESPLEN_24XX); 278 ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp)); 279 cto->rsp.m1.ct_resp[0] = 0xf0; 280 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 281 cto->rsp.m1.ct_resp[7] = 8; 282 cto->rsp.m1.ct_resp[12] = (code >> 16) & 0xff; 283 cto->rsp.m1.ct_resp[13] = (code >> 24) & 0xff; 284 } else if (code & ECMD_RVALID) { 285 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS; 286 cto->ct_scsi_status |= (FCP_RSPLEN_VALID << 8); 287 cto->rsp.m1.ct_resplen = 4; 288 ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp)); 289 cto->rsp.m1.ct_resp[0] = (code >> 12) & 0xf; 290 cto->rsp.m1.ct_resp[1] = (code >> 16) & 0xff; 291 cto->rsp.m1.ct_resp[2] = (code >> 24) & 0xff; 292 cto->rsp.m1.ct_resp[3] = 0; 293 } else { 294 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS; 295 } 296 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl != 0) { 297 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl; 298 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8); 299 } 300 cto->ct_syshandle = hdl; 301 return (isp_send_entry(isp, cto)); 302 } 303 304 /* 305 * These are either broadcast events or specifically CTIO fast completion 306 */ 307 308 void 309 isp_target_async(ispsoftc_t *isp, int bus, int event) 310 { 311 isp_notify_t notify; 312 313 ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 314 notify.nt_hba = isp; 315 notify.nt_wwn = INI_ANY; 316 notify.nt_nphdl = NIL_HANDLE; 317 notify.nt_sid = PORT_ANY; 318 notify.nt_did = PORT_ANY; 319 notify.nt_tgt = TGT_ANY; 320 notify.nt_channel = bus; 321 notify.nt_lun = LUN_ANY; 322 notify.nt_tagval = TAG_ANY; 323 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 324 325 switch (event) { 326 case ASYNC_LOOP_UP: 327 case ASYNC_PTPMODE: 328 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP UP", __func__); 329 notify.nt_ncode = NT_LINK_UP; 330 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 331 break; 332 case ASYNC_LOOP_DOWN: 333 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP DOWN", __func__); 334 notify.nt_ncode = NT_LINK_DOWN; 335 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 336 break; 337 case ASYNC_LIP_ERROR: 338 case ASYNC_LIP_NOS_OLS_RECV: 339 case ASYNC_LIP_OCCURRED: 340 case ASYNC_LOOP_RESET: 341 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LIP RESET", __func__); 342 notify.nt_ncode = NT_LIP_RESET; 343 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 344 break; 345 default: 346 isp_prt(isp, ISP_LOGERR, "%s: unknown event 0x%x", __func__, event); 347 break; 348 } 349 } 350 351 static void 352 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep) 353 { 354 isp_notify_t notify; 355 static const char f1[] = "%s from PortID 0x%06x lun %jx seq 0x%08x"; 356 static const char f2[] = "unknown Task Flag 0x%x lun %jx PortID 0x%x tag 0x%08x"; 357 fcportdb_t *lp; 358 uint16_t chan; 359 uint32_t sid, did; 360 361 ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 362 notify.nt_hba = isp; 363 notify.nt_wwn = INI_ANY; 364 notify.nt_lun = CAM_EXTLUN_BYTE_SWIZZLE(be64dec(aep->at_cmnd.fcp_cmnd_lun)); 365 notify.nt_tagval = aep->at_rxid; 366 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 367 notify.nt_lreserved = aep; 368 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2]; 369 did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2]; 370 if (ISP_CAP_MULTI_ID(isp) && isp->isp_nchan > 1) { 371 /* Channel has to be derived from D_ID */ 372 isp_find_chan_by_did(isp, did, &chan); 373 if (chan == ISP_NOCHAN) { 374 isp_prt(isp, ISP_LOGWARN, 375 "%s: D_ID 0x%x not found on any channel", 376 __func__, did); 377 isp_endcmd(isp, aep, NIL_HANDLE, ISP_NOCHAN, 378 ECMD_TERMINATE, 0); 379 return; 380 } 381 } else { 382 chan = 0; 383 } 384 if (isp_find_pdb_by_portid(isp, chan, sid, &lp)) 385 notify.nt_nphdl = lp->handle; 386 else 387 notify.nt_nphdl = NIL_HANDLE; 388 notify.nt_sid = sid; 389 notify.nt_did = did; 390 notify.nt_channel = chan; 391 if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_QUERY_TASK_SET) { 392 isp_prt(isp, ISP_LOGINFO, f1, "QUERY TASK SET", sid, notify.nt_lun, aep->at_rxid); 393 notify.nt_ncode = NT_QUERY_TASK_SET; 394 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_ABORT_TASK_SET) { 395 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", sid, notify.nt_lun, aep->at_rxid); 396 notify.nt_ncode = NT_ABORT_TASK_SET; 397 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_TASK_SET) { 398 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", sid, notify.nt_lun, aep->at_rxid); 399 notify.nt_ncode = NT_CLEAR_TASK_SET; 400 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_QUERY_ASYNC_EVENT) { 401 isp_prt(isp, ISP_LOGINFO, f1, "QUERY ASYNC EVENT", sid, notify.nt_lun, aep->at_rxid); 402 notify.nt_ncode = NT_QUERY_ASYNC_EVENT; 403 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_LUN_RESET) { 404 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", sid, notify.nt_lun, aep->at_rxid); 405 notify.nt_ncode = NT_LUN_RESET; 406 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_TGT_RESET) { 407 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", sid, notify.nt_lun, aep->at_rxid); 408 notify.nt_ncode = NT_TARGET_RESET; 409 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_ACA) { 410 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", sid, notify.nt_lun, aep->at_rxid); 411 notify.nt_ncode = NT_CLEAR_ACA; 412 } else { 413 isp_prt(isp, ISP_LOGWARN, f2, aep->at_cmnd.fcp_cmnd_task_management, notify.nt_lun, sid, aep->at_rxid); 414 notify.nt_ncode = NT_UNKNOWN; 415 isp_endcmd(isp, aep, notify.nt_nphdl, chan, ECMD_RVALID | (0x4 << 12), 0); 416 return; 417 } 418 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 419 } 420 421 int 422 isp_notify_ack(ispsoftc_t *isp, void *arg) 423 { 424 na_fcentry_24xx_t _na, *na = &_na; 425 426 /* 427 * This is in case a Task Management Function ends up here. 428 */ 429 if (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO) 430 return (isp_endcmd(isp, arg, NIL_HANDLE, 0, 0, 0)); 431 432 in_fcentry_24xx_t *in = arg; 433 434 ISP_MEMZERO(na, sizeof(*na)); 435 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 436 na->na_header.rqs_entry_count = 1; 437 na->na_nphdl = in->in_nphdl; 438 na->na_flags = in->in_flags; 439 na->na_status = in->in_status; 440 na->na_status_subcode = in->in_status_subcode; 441 na->na_fwhandle = in->in_fwhandle; 442 na->na_rxid = in->in_rxid; 443 na->na_oxid = in->in_oxid; 444 na->na_vpidx = in->in_vpidx; 445 if (in->in_status == IN24XX_SRR_RCVD) { 446 na->na_srr_rxid = in->in_srr_rxid; 447 na->na_srr_reloff_hi = in->in_srr_reloff_hi; 448 na->na_srr_reloff_lo = in->in_srr_reloff_lo; 449 na->na_srr_iu = in->in_srr_iu; 450 /* 451 * Whether we're accepting the SRR or rejecting 452 * it is determined by looking at the in_reserved 453 * field in the original notify structure. 454 */ 455 if (in->in_reserved) { 456 na->na_srr_flags = 1; 457 na->na_srr_reject_vunique = 0; 458 /* Unable to perform this command at this time. */ 459 na->na_srr_reject_code = 9; 460 /* Unable to supply the requested data. */ 461 na->na_srr_reject_explanation = 0x2a; 462 } 463 } 464 return (isp_send_entry(isp, na)); 465 } 466 467 int 468 isp_acknak_abts(ispsoftc_t *isp, void *arg, int errno) 469 { 470 char storage[QENTRY_LEN]; 471 uint16_t tmpw; 472 uint8_t tmpb; 473 abts_t *abts = arg; 474 abts_rsp_t *rsp = (abts_rsp_t *) storage; 475 476 if (abts->abts_header.rqs_entry_type != RQSTYPE_ABTS_RCVD) { 477 isp_prt(isp, ISP_LOGERR, "%s: called for non-ABTS entry (0x%x)", __func__, abts->abts_header.rqs_entry_type); 478 return (0); 479 } 480 481 ISP_MEMCPY(rsp, abts, QENTRY_LEN); 482 rsp->abts_rsp_header.rqs_entry_type = RQSTYPE_ABTS_RSP; 483 484 isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS of 0x%x being %s'd", 485 rsp->abts_rsp_rxid_abts, rsp->abts_rsp_rxid_task, 486 (errno == 0) ? "BA_ACC" : "BA_RJT"); 487 rsp->abts_rsp_r_ctl = (errno == 0) ? BA_ACC : BA_RJT; 488 489 /* 490 * Swap destination and source for response. 491 */ 492 tmpw = rsp->abts_rsp_did_lo; 493 tmpb = rsp->abts_rsp_did_hi; 494 rsp->abts_rsp_did_lo = rsp->abts_rsp_sid_lo; 495 rsp->abts_rsp_did_hi = rsp->abts_rsp_sid_hi; 496 rsp->abts_rsp_sid_lo = tmpw; 497 rsp->abts_rsp_sid_hi = tmpb; 498 499 rsp->abts_rsp_f_ctl_hi ^= 0x80; /* invert Exchange Context */ 500 rsp->abts_rsp_f_ctl_hi &= ~0x7f; /* clear Sequence Initiator and other bits */ 501 rsp->abts_rsp_f_ctl_hi |= 0x10; /* abort the whole exchange */ 502 rsp->abts_rsp_f_ctl_hi |= 0x8; /* last data frame of sequence */ 503 rsp->abts_rsp_f_ctl_hi |= 0x1; /* transfer Sequence Initiative */ 504 rsp->abts_rsp_f_ctl_lo = 0; 505 506 if (errno == 0) { 507 uint16_t rx_id, ox_id; 508 509 rx_id = rsp->abts_rsp_rx_id; 510 ox_id = rsp->abts_rsp_ox_id; 511 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_acc, sizeof (rsp->abts_rsp_payload.ba_acc)); 512 rsp->abts_rsp_payload.ba_acc.aborted_rx_id = rx_id; 513 rsp->abts_rsp_payload.ba_acc.aborted_ox_id = ox_id; 514 rsp->abts_rsp_payload.ba_acc.high_seq_cnt = 0xffff; 515 } else { 516 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_rjt, sizeof (rsp->abts_rsp_payload.ba_rjt)); 517 switch (errno) { 518 case ENOMEM: 519 rsp->abts_rsp_payload.ba_rjt.reason = 5; /* Logical busy */ 520 break; 521 default: 522 rsp->abts_rsp_payload.ba_rjt.reason = 9; /* Unable to perform command request */ 523 break; 524 } 525 } 526 return (isp_send_entry(isp, rsp)); 527 } 528 529 static void 530 isp_handle_abts(ispsoftc_t *isp, abts_t *abts) 531 { 532 isp_notify_t notify, *nt = ¬ify; 533 fcportdb_t *lp; 534 uint16_t chan; 535 uint32_t sid, did; 536 537 did = (abts->abts_did_hi << 16) | abts->abts_did_lo; 538 sid = (abts->abts_sid_hi << 16) | abts->abts_sid_lo; 539 ISP_MEMZERO(nt, sizeof (isp_notify_t)); 540 541 nt->nt_hba = isp; 542 nt->nt_did = did; 543 nt->nt_nphdl = abts->abts_nphdl; 544 nt->nt_sid = sid; 545 if (ISP_CAP_MULTI_ID(isp) && isp->isp_nchan > 1) { 546 /* Channel has to be derived from D_ID */ 547 isp_find_chan_by_did(isp, did, &chan); 548 if (chan == ISP_NOCHAN) { 549 isp_prt(isp, ISP_LOGWARN, 550 "%s: D_ID 0x%x not found on any channel", 551 __func__, did); 552 isp_acknak_abts(isp, abts, ENXIO); 553 return; 554 } 555 } else 556 chan = 0; 557 nt->nt_tgt = FCPARAM(isp, chan)->isp_wwpn; 558 if (isp_find_pdb_by_handle(isp, chan, abts->abts_nphdl, &lp)) 559 nt->nt_wwn = lp->port_wwn; 560 else 561 nt->nt_wwn = INI_ANY; 562 nt->nt_lun = LUN_ANY; 563 nt->nt_need_ack = 1; 564 nt->nt_tagval = abts->abts_rxid_task; 565 nt->nt_tagval |= (((uint64_t) abts->abts_rxid_abts) << 32); 566 isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS from N-Port handle 0x%x" 567 " Port 0x%06x for task 0x%x (rx_id 0x%04x ox_id 0x%04x)", 568 abts->abts_rxid_abts, abts->abts_nphdl, sid, abts->abts_rxid_task, 569 abts->abts_rx_id, abts->abts_ox_id); 570 nt->nt_channel = chan; 571 nt->nt_ncode = NT_ABORT_TASK; 572 nt->nt_lreserved = abts; 573 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 574 } 575 576 static void 577 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct) 578 { 579 void *xs; 580 int pl = ISP_LOGTDEBUG2; 581 char *fmsg = NULL; 582 583 if (ct->ct_syshandle) { 584 xs = isp_find_xs(isp, ct->ct_syshandle); 585 if (xs == NULL) { 586 pl = ISP_LOGALL; 587 } 588 } else { 589 xs = NULL; 590 } 591 592 switch (ct->ct_nphdl) { 593 case CT7_BUS_ERROR: 594 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 595 /* FALL Through */ 596 case CT7_DATA_OVER: 597 case CT7_DATA_UNDER: 598 case CT7_OK: 599 /* 600 * There are generally 2 possibilities as to why we'd get 601 * this condition: 602 * We sent or received data. 603 * We sent status & command complete. 604 */ 605 606 break; 607 608 case CT7_RESET: 609 if (fmsg == NULL) { 610 fmsg = "LIP Reset"; 611 } 612 /*FALLTHROUGH*/ 613 case CT7_ABORTED: 614 /* 615 * When an Abort message is received the firmware goes to 616 * Bus Free and returns all outstanding CTIOs with the status 617 * set, then sends us an Immediate Notify entry. 618 */ 619 if (fmsg == NULL) { 620 fmsg = "ABORT"; 621 } 622 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 623 break; 624 625 case CT7_TIMEOUT: 626 if (fmsg == NULL) { 627 fmsg = "command"; 628 } 629 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg); 630 break; 631 632 case CT7_ERR: 633 fmsg = "Completed with Error"; 634 /*FALLTHROUGH*/ 635 case CT7_LOGOUT: 636 if (fmsg == NULL) { 637 fmsg = "Port Logout"; 638 } 639 /*FALLTHROUGH*/ 640 case CT7_PORTUNAVAIL: 641 if (fmsg == NULL) { 642 fmsg = "Port not available"; 643 } 644 /*FALLTHROUGH*/ 645 case CT7_PORTCHANGED: 646 if (fmsg == NULL) { 647 fmsg = "Port Changed"; 648 } 649 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 650 break; 651 652 case CT7_INVRXID: 653 /* 654 * CTIO rejected by the firmware because an invalid RX_ID. 655 * Just print a message. 656 */ 657 isp_prt(isp, ISP_LOGWARN, "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 658 break; 659 660 case CT7_REASSY_ERR: 661 isp_prt(isp, ISP_LOGWARN, "reassembly error"); 662 break; 663 664 case CT7_SRR: 665 isp_prt(isp, ISP_LOGTDEBUG0, "SRR received"); 666 break; 667 668 default: 669 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", ct->ct_nphdl); 670 break; 671 } 672 673 if (xs == NULL) { 674 /* 675 * There may be more than one CTIO for a data transfer, 676 * or this may be a status CTIO we're not monitoring. 677 * 678 * The assumption is that they'll all be returned in the 679 * order we got them. 680 */ 681 if (ct->ct_syshandle == 0) { 682 if (ct->ct_flags & CT7_TERMINATE) { 683 isp_prt(isp, ISP_LOGINFO, "termination of [RX_ID 0x%x] complete", ct->ct_rxid); 684 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) { 685 isp_prt(isp, pl, "intermediate CTIO completed ok"); 686 } else { 687 isp_prt(isp, pl, "unmonitored CTIO completed ok"); 688 } 689 } else { 690 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_nphdl); 691 } 692 } else { 693 ISP_DMAFREE(isp, xs); 694 if (ct->ct_flags & CT7_SENDSTATUS) { 695 /* 696 * Sent status and command complete. 697 * 698 * We're now really done with this command, so we 699 * punt to the platform dependent layers because 700 * only there can we do the appropriate command 701 * complete thread synchronization. 702 */ 703 isp_prt(isp, pl, "status CTIO complete"); 704 } else { 705 /* 706 * Final CTIO completed. Release DMA resources and 707 * notify platform dependent layers. 708 */ 709 isp_prt(isp, pl, "data CTIO complete"); 710 } 711 isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 712 /* 713 * The platform layer will destroy the handle if appropriate. 714 */ 715 } 716 } 717 718 static void 719 isp_handle_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot) 720 { 721 uint8_t chan; 722 uint16_t nphdl, prli_options = 0; 723 uint32_t portid; 724 fcportdb_t *lp; 725 char *msg = NULL; 726 uint8_t *ptr = (uint8_t *)inot; 727 uint64_t wwpn = INI_NONE, wwnn = INI_NONE; 728 isp_notify_t notify; 729 char buf[16]; 730 731 nphdl = inot->in_nphdl; 732 if (nphdl != NIL_HANDLE) { 733 portid = inot->in_portid_hi << 16 | inot->in_portid_lo; 734 } else { 735 portid = PORT_ANY; 736 } 737 738 chan = ISP_GET_VPIDX(isp, inot->in_vpidx); 739 if (chan >= isp->isp_nchan && 740 inot->in_status != IN24XX_LIP_RESET && 741 inot->in_status != IN24XX_LINK_RESET && 742 inot->in_status != IN24XX_LINK_FAILED) { 743 isp_prt(isp, ISP_LOGWARN, "%s: Received INOT with status %x on VP %x", 744 __func__, inot->in_status, chan); 745 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot); 746 return; 747 } 748 749 switch (inot->in_status) { 750 case IN24XX_ELS_RCVD: 751 { 752 /* 753 * Note that we're just getting notification that an ELS was 754 * received (possibly with some associated information sent 755 * upstream). This is *not* the same as being given the ELS 756 * frame to accept or reject. 757 */ 758 switch (inot->in_status_subcode) { 759 case LOGO: 760 msg = "LOGO"; 761 wwpn = be64dec(&ptr[IN24XX_PLOGI_WWPN_OFF]); 762 isp_del_wwn_entry(isp, chan, wwpn, nphdl, portid); 763 break; 764 case PRLO: 765 msg = "PRLO"; 766 break; 767 case PLOGI: 768 msg = "PLOGI"; 769 wwnn = be64dec(&ptr[IN24XX_PLOGI_WWNN_OFF]); 770 wwpn = be64dec(&ptr[IN24XX_PLOGI_WWPN_OFF]); 771 isp_add_wwn_entry(isp, chan, wwpn, wwnn, 772 nphdl, portid, prli_options); 773 break; 774 case PRLI: 775 msg = "PRLI"; 776 prli_options = inot->in_prli_options; 777 if (inot->in_flags & IN24XX_FLAG_PN_NN_VALID) 778 wwnn = be64dec(&ptr[IN24XX_PRLI_WWNN_OFF]); 779 wwpn = be64dec(&ptr[IN24XX_PRLI_WWPN_OFF]); 780 isp_add_wwn_entry(isp, chan, wwpn, wwnn, 781 nphdl, portid, prli_options); 782 break; 783 case TPRLO: 784 msg = "TPRLO"; 785 break; 786 case PDISC: 787 msg = "PDISC"; 788 break; 789 case ADISC: 790 msg = "ADISC"; 791 break; 792 default: 793 ISP_SNPRINTF(buf, sizeof (buf), "ELS 0x%x", 794 inot->in_status_subcode); 795 msg = buf; 796 break; 797 } 798 if (inot->in_flags & IN24XX_FLAG_PUREX_IOCB) { 799 isp_prt(isp, ISP_LOGERR, "%s Chan %d ELS N-port handle %x" 800 " PortID 0x%06x marked as needing a PUREX response", 801 msg, chan, nphdl, portid); 802 break; 803 } 804 isp_prt(isp, ISP_LOGTDEBUG0, "%s Chan %d ELS N-port handle %x" 805 " PortID 0x%06x RX_ID 0x%x OX_ID 0x%x", msg, chan, nphdl, 806 portid, inot->in_rxid, inot->in_oxid); 807 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot); 808 break; 809 } 810 811 case IN24XX_PORT_LOGOUT: 812 msg = "PORT LOGOUT"; 813 if (isp_find_pdb_by_handle(isp, chan, nphdl, &lp)) 814 isp_del_wwn_entry(isp, chan, lp->port_wwn, nphdl, lp->portid); 815 /* FALLTHROUGH */ 816 case IN24XX_PORT_CHANGED: 817 if (msg == NULL) 818 msg = "PORT CHANGED"; 819 /* FALLTHROUGH */ 820 case IN24XX_LIP_RESET: 821 if (msg == NULL) 822 msg = "LIP RESET"; 823 isp_prt(isp, ISP_LOGINFO, "Chan %d %s (sub-status 0x%x) for " 824 "N-port handle 0x%x", 825 chan, msg, inot->in_status_subcode, nphdl); 826 827 /* 828 * All subcodes here are irrelevant. What is relevant 829 * is that we need to terminate all active commands from 830 * this initiator (known by N-port handle). 831 */ 832 /* XXX IMPLEMENT XXX */ 833 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot); 834 break; 835 836 case IN24XX_SRR_RCVD: 837 #ifdef ISP_TARGET_MODE 838 ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 839 notify.nt_hba = isp; 840 notify.nt_wwn = INI_ANY; 841 notify.nt_tgt = FCPARAM(isp, chan)->isp_wwpn; 842 notify.nt_nphdl = nphdl; 843 notify.nt_sid = portid; 844 notify.nt_did = PORT_ANY; 845 notify.nt_lun = LUN_ANY; 846 notify.nt_tagval = inot->in_rxid; 847 notify.nt_tagval |= ((uint64_t)inot->in_srr_rxid << 32); 848 notify.nt_need_ack = 1; 849 notify.nt_channel = chan; 850 notify.nt_lreserved = inot; 851 notify.nt_ncode = NT_SRR; 852 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 853 break; 854 #else 855 if (msg == NULL) 856 msg = "SRR RCVD"; 857 /* FALLTHROUGH */ 858 #endif 859 case IN24XX_LINK_RESET: 860 if (msg == NULL) 861 msg = "LINK RESET"; 862 case IN24XX_LINK_FAILED: 863 if (msg == NULL) 864 msg = "LINK FAILED"; 865 default: 866 isp_prt(isp, ISP_LOGWARN, "Chan %d %s", chan, msg); 867 isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot); 868 break; 869 } 870 } 871 #endif 872