1 /* $FreeBSD$ */ 2 /*- 3 * Qlogic Target Mode Structure and Flag Definitions 4 * 5 * Copyright (c) 1997, 1998 6 * Patrick Stirling 7 * pms@psconsult.com 8 * All rights reserved. 9 * 10 * Additonal Copyright (c) 1997-2006 by Matthew Jacob 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice immediately at the beginning of the file, without modification, 18 * this list of conditions, and the following disclaimer. 19 * 2. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 */ 35 #ifndef _ISP_TARGET_H 36 #define _ISP_TARGET_H 37 38 #define QLTM_SENSELEN 18 /* non-FC cards only */ 39 #define QLTM_SVALID 0x80 40 41 /* 42 * Structure for Enable Lun and Modify Lun queue entries 43 */ 44 typedef struct { 45 isphdr_t le_header; 46 uint32_t le_reserved; 47 uint8_t le_lun; 48 uint8_t le_rsvd; 49 uint8_t le_ops; /* Modify LUN only */ 50 uint8_t le_tgt; /* Not for FC */ 51 uint32_t le_flags; /* Not for FC */ 52 uint8_t le_status; 53 uint8_t le_reserved2; 54 uint8_t le_cmd_count; 55 uint8_t le_in_count; 56 uint8_t le_cdb6len; /* Not for FC */ 57 uint8_t le_cdb7len; /* Not for FC */ 58 uint16_t le_timeout; 59 uint16_t le_reserved3[20]; 60 } lun_entry_t; 61 62 /* 63 * le_flags values 64 */ 65 #define LUN_TQAE 0x00000002 /* bit1 Tagged Queue Action Enable */ 66 #define LUN_DSSM 0x01000000 /* bit24 Disable Sending SDP Message */ 67 #define LUN_DISAD 0x02000000 /* bit25 Disable autodisconnect */ 68 #define LUN_DM 0x40000000 /* bit30 Disconnects Mandatory */ 69 70 /* 71 * le_ops values 72 */ 73 #define LUN_CCINCR 0x01 /* increment command count */ 74 #define LUN_CCDECR 0x02 /* decrement command count */ 75 #define LUN_ININCR 0x40 /* increment immed. notify count */ 76 #define LUN_INDECR 0x80 /* decrement immed. notify count */ 77 78 /* 79 * le_status values 80 */ 81 #define LUN_OK 0x01 /* we be rockin' */ 82 #define LUN_ERR 0x04 /* request completed with error */ 83 #define LUN_INVAL 0x06 /* invalid request */ 84 #define LUN_NOCAP 0x16 /* can't provide requested capability */ 85 #define LUN_ENABLED 0x3E /* LUN already enabled */ 86 87 /* 88 * Immediate Notify Entry structure 89 */ 90 #define IN_MSGLEN 8 /* 8 bytes */ 91 #define IN_RSVDLEN 8 /* 8 words */ 92 typedef struct { 93 isphdr_t in_header; 94 uint32_t in_reserved; 95 uint8_t in_lun; /* lun */ 96 uint8_t in_iid; /* initiator */ 97 uint8_t in_reserved2; 98 uint8_t in_tgt; /* target */ 99 uint32_t in_flags; 100 uint8_t in_status; 101 uint8_t in_rsvd2; 102 uint8_t in_tag_val; /* tag value */ 103 uint8_t in_tag_type; /* tag type */ 104 uint16_t in_seqid; /* sequence id */ 105 uint8_t in_msg[IN_MSGLEN]; /* SCSI message bytes */ 106 uint16_t in_reserved3[IN_RSVDLEN]; 107 uint8_t in_sense[QLTM_SENSELEN];/* suggested sense data */ 108 } in_entry_t; 109 110 typedef struct { 111 isphdr_t in_header; 112 uint32_t in_reserved; 113 uint8_t in_lun; /* lun */ 114 uint8_t in_iid; /* initiator */ 115 uint16_t in_scclun; 116 uint32_t in_reserved2; 117 uint16_t in_status; 118 uint16_t in_task_flags; 119 uint16_t in_seqid; /* sequence id */ 120 } in_fcentry_t; 121 122 typedef struct { 123 isphdr_t in_header; 124 uint32_t in_reserved; 125 uint16_t in_iid; /* initiator */ 126 uint16_t in_scclun; 127 uint32_t in_reserved2; 128 uint16_t in_status; 129 uint16_t in_task_flags; 130 uint16_t in_seqid; /* sequence id */ 131 } in_fcentry_e_t; 132 133 /* 134 * Values for the in_status field 135 */ 136 #define IN_REJECT 0x0D /* Message Reject message received */ 137 #define IN_RESET 0x0E /* Bus Reset occurred */ 138 #define IN_NO_RCAP 0x16 /* requested capability not available */ 139 #define IN_IDE_RECEIVED 0x33 /* Initiator Detected Error msg received */ 140 #define IN_RSRC_UNAVAIL 0x34 /* resource unavailable */ 141 #define IN_MSG_RECEIVED 0x36 /* SCSI message received */ 142 #define IN_ABORT_TASK 0x20 /* task named in RX_ID is being aborted (FC) */ 143 #define IN_PORT_LOGOUT 0x29 /* port has logged out (FC) */ 144 #define IN_PORT_CHANGED 0x2A /* port changed */ 145 #define IN_GLOBAL_LOGO 0x2E /* all ports logged out */ 146 #define IN_NO_NEXUS 0x3B /* Nexus not established */ 147 148 /* 149 * Values for the in_task_flags field- should only get one at a time! 150 */ 151 #define TASK_FLAGS_RESERVED_MASK (0xe700) 152 #define TASK_FLAGS_CLEAR_ACA (1<<14) 153 #define TASK_FLAGS_TARGET_RESET (1<<13) 154 #define TASK_FLAGS_LUN_RESET (1<<12) 155 #define TASK_FLAGS_CLEAR_TASK_SET (1<<10) 156 #define TASK_FLAGS_ABORT_TASK_SET (1<<9) 157 158 /* 159 * ISP24XX Immediate Notify 160 */ 161 typedef struct { 162 isphdr_t in_header; 163 uint32_t in_reserved; 164 uint16_t in_nphdl; 165 uint16_t in_reserved1; 166 uint16_t in_flags; 167 uint16_t in_srr_rxid; 168 uint16_t in_status; 169 uint8_t in_status_subcode; 170 uint8_t in_reserved2; 171 uint32_t in_rxid; 172 uint16_t in_srr_reloff_lo; 173 uint16_t in_srr_reloff_hi; 174 uint16_t in_srr_iu; 175 uint16_t in_srr_oxid; 176 uint8_t in_reserved3[18]; 177 uint8_t in_reserved4; 178 uint8_t in_vpindex; 179 uint32_t in_reserved5; 180 uint16_t in_portid_lo; 181 uint8_t in_portid_hi; 182 uint8_t in_reserved6; 183 uint16_t in_reserved7; 184 uint16_t in_oxid; 185 } in_fcentry_24xx_t; 186 187 #define IN24XX_FLAG_PUREX_IOCB 0x1 188 #define IN24XX_FLAG_GLOBAL_LOGOUT 0x2 189 190 #define IN24XX_LIP_RESET 0x0E 191 #define IN24XX_LINK_RESET 0x0F 192 #define IN24XX_PORT_LOGOUT 0x29 193 #define IN24XX_PORT_CHANGED 0x2A 194 #define IN24XX_LINK_FAILED 0x2E 195 #define IN24XX_SRR_RCVD 0x45 196 #define IN24XX_ELS_RCVD 0x46 /* 197 * login-affectin ELS received- check 198 * subcode for specific opcode 199 */ 200 /* 201 * Notify Acknowledge Entry structure 202 */ 203 #define NA_RSVDLEN 22 204 typedef struct { 205 isphdr_t na_header; 206 uint32_t na_reserved; 207 uint8_t na_lun; /* lun */ 208 uint8_t na_iid; /* initiator */ 209 uint8_t na_reserved2; 210 uint8_t na_tgt; /* target */ 211 uint32_t na_flags; 212 uint8_t na_status; 213 uint8_t na_event; 214 uint16_t na_seqid; /* sequence id */ 215 uint16_t na_reserved3[NA_RSVDLEN]; 216 } na_entry_t; 217 218 /* 219 * Value for the na_event field 220 */ 221 #define NA_RST_CLRD 0x80 /* Clear an async event notification */ 222 #define NA_OK 0x01 /* Notify Acknowledge Succeeded */ 223 #define NA_INVALID 0x06 /* Invalid Notify Acknowledge */ 224 225 #define NA2_RSVDLEN 21 226 typedef struct { 227 isphdr_t na_header; 228 uint32_t na_reserved; 229 uint8_t na_reserved1; 230 uint8_t na_iid; /* initiator loop id */ 231 uint16_t na_response; 232 uint16_t na_flags; 233 uint16_t na_reserved2; 234 uint16_t na_status; 235 uint16_t na_task_flags; 236 uint16_t na_seqid; /* sequence id */ 237 uint16_t na_reserved3[NA2_RSVDLEN]; 238 } na_fcentry_t; 239 240 typedef struct { 241 isphdr_t na_header; 242 uint32_t na_reserved; 243 uint16_t na_iid; /* initiator loop id */ 244 uint16_t na_response; /* response code */ 245 uint16_t na_flags; 246 uint16_t na_reserved2; 247 uint16_t na_status; 248 uint16_t na_task_flags; 249 uint16_t na_seqid; /* sequence id */ 250 uint16_t na_reserved3[NA2_RSVDLEN]; 251 } na_fcentry_e_t; 252 253 #define NAFC_RCOUNT 0x80 /* increment resource count */ 254 #define NAFC_RST_CLRD 0x20 /* Clear LIP Reset */ 255 #define NAFC_TVALID 0x10 /* task mangement response code is valid */ 256 257 /* 258 * ISP24XX Notify Acknowledge 259 */ 260 261 typedef struct { 262 isphdr_t na_header; 263 uint32_t na_handle; 264 uint16_t na_nphdl; 265 uint16_t na_reserved1; 266 uint16_t na_flags; 267 uint16_t na_srr_rxid; 268 uint16_t na_status; 269 uint8_t na_status_subcode; 270 uint8_t na_reserved2; 271 uint32_t na_rxid; 272 uint16_t na_srr_reloff_lo; 273 uint16_t na_srr_reloff_hi; 274 uint16_t na_srr_iu; 275 uint16_t na_srr_flags; 276 uint8_t na_reserved3[18]; 277 uint8_t na_reserved4; 278 uint8_t na_vpindex; 279 uint8_t na_srr_reject_vunique; 280 uint8_t na_srr_reject_explanation; 281 uint8_t na_srr_reject_code; 282 uint8_t na_reserved5; 283 uint8_t na_reserved6[6]; 284 uint16_t na_oxid; 285 } na_fcentry_24xx_t; 286 287 /* 288 * Accept Target I/O Entry structure 289 */ 290 #define ATIO_CDBLEN 26 291 292 typedef struct { 293 isphdr_t at_header; 294 uint16_t at_reserved; 295 uint16_t at_handle; 296 uint8_t at_lun; /* lun */ 297 uint8_t at_iid; /* initiator */ 298 uint8_t at_cdblen; /* cdb length */ 299 uint8_t at_tgt; /* target */ 300 uint32_t at_flags; 301 uint8_t at_status; /* firmware status */ 302 uint8_t at_scsi_status; /* scsi status */ 303 uint8_t at_tag_val; /* tag value */ 304 uint8_t at_tag_type; /* tag type */ 305 uint8_t at_cdb[ATIO_CDBLEN]; /* received CDB */ 306 uint8_t at_sense[QLTM_SENSELEN];/* suggested sense data */ 307 } at_entry_t; 308 309 /* 310 * at_flags values 311 */ 312 #define AT_NODISC 0x00008000 /* disconnect disabled */ 313 #define AT_TQAE 0x00000002 /* Tagged Queue Action enabled */ 314 315 /* 316 * at_status values 317 */ 318 #define AT_PATH_INVALID 0x07 /* ATIO sent to firmware for disabled lun */ 319 #define AT_RESET 0x0E /* SCSI Bus Reset Occurred */ 320 #define AT_PHASE_ERROR 0x14 /* Bus phase sequence error */ 321 #define AT_NOCAP 0x16 /* Requested capability not available */ 322 #define AT_BDR_MSG 0x17 /* Bus Device Reset msg received */ 323 #define AT_CDB 0x3D /* CDB received */ 324 /* 325 * Macros to create and fetch and test concatenated handle and tag value macros 326 */ 327 328 #define AT_MAKE_TAGID(tid, bus, inst, aep) \ 329 tid = aep->at_handle; \ 330 if (aep->at_flags & AT_TQAE) { \ 331 tid |= (aep->at_tag_val << 16); \ 332 tid |= (1 << 24); \ 333 } \ 334 tid |= (bus << 25); \ 335 tid |= (inst << 26) 336 337 #define CT_MAKE_TAGID(tid, bus, inst, ct) \ 338 tid = ct->ct_fwhandle; \ 339 if (ct->ct_flags & CT_TQAE) { \ 340 tid |= (ct->ct_tag_val << 16); \ 341 tid |= (1 << 24); \ 342 } \ 343 tid |= ((bus & 0x1) << 25); \ 344 tid |= (inst << 26) 345 346 #define AT_HAS_TAG(val) ((val) & (1 << 24)) 347 #define AT_GET_TAG(val) (((val) >> 16) & 0xff) 348 #define AT_GET_INST(val) (((val) >> 26) & 0x3f) 349 #define AT_GET_BUS(val) (((val) >> 25) & 0x1) 350 #define AT_GET_HANDLE(val) ((val) & 0xffff) 351 352 #define IN_MAKE_TAGID(tid, bus, inst, inp) \ 353 tid = inp->in_seqid; \ 354 tid |= (inp->in_tag_val << 16); \ 355 tid |= (1 << 24); \ 356 tid |= (bus << 25); \ 357 tid |= (inst << 26) 358 359 #define TAG_INSERT_INST(tid, inst) \ 360 tid &= ~(0x3ffffff); \ 361 tid |= (inst << 26) 362 363 #define TAG_INSERT_BUS(tid, bus) \ 364 tid &= ~(1 << 25); \ 365 tid |= (bus << 25) 366 367 /* 368 * Accept Target I/O Entry structure, Type 2 369 */ 370 #define ATIO2_CDBLEN 16 371 372 typedef struct { 373 isphdr_t at_header; 374 uint32_t at_reserved; 375 uint8_t at_lun; /* lun or reserved */ 376 uint8_t at_iid; /* initiator */ 377 uint16_t at_rxid; /* response ID */ 378 uint16_t at_flags; 379 uint16_t at_status; /* firmware status */ 380 uint8_t at_crn; /* command reference number */ 381 uint8_t at_taskcodes; 382 uint8_t at_taskflags; 383 uint8_t at_execodes; 384 uint8_t at_cdb[ATIO2_CDBLEN]; /* received CDB */ 385 uint32_t at_datalen; /* allocated data len */ 386 uint16_t at_scclun; /* SCC Lun or reserved */ 387 uint16_t at_wwpn[4]; /* WWPN of initiator */ 388 uint16_t at_reserved2[6]; 389 uint16_t at_oxid; 390 } at2_entry_t; 391 392 typedef struct { 393 isphdr_t at_header; 394 uint32_t at_reserved; 395 uint16_t at_iid; /* initiator */ 396 uint16_t at_rxid; /* response ID */ 397 uint16_t at_flags; 398 uint16_t at_status; /* firmware status */ 399 uint8_t at_crn; /* command reference number */ 400 uint8_t at_taskcodes; 401 uint8_t at_taskflags; 402 uint8_t at_execodes; 403 uint8_t at_cdb[ATIO2_CDBLEN]; /* received CDB */ 404 uint32_t at_datalen; /* allocated data len */ 405 uint16_t at_scclun; /* SCC Lun or reserved */ 406 uint16_t at_wwpn[4]; /* WWPN of initiator */ 407 uint16_t at_reserved2[6]; 408 uint16_t at_oxid; 409 } at2e_entry_t; 410 411 #define ATIO2_WWPN_OFFSET 0x2A 412 #define ATIO2_OXID_OFFSET 0x3E 413 414 #define ATIO2_TC_ATTR_MASK 0x7 415 #define ATIO2_TC_ATTR_SIMPLEQ 0 416 #define ATIO2_TC_ATTR_HEADOFQ 1 417 #define ATIO2_TC_ATTR_ORDERED 2 418 #define ATIO2_TC_ATTR_ACAQ 4 419 #define ATIO2_TC_ATTR_UNTAGGED 5 420 421 #define ATIO2_EX_WRITE 0x1 422 #define ATIO2_EX_READ 0x2 423 /* 424 * Macros to create and fetch and test concatenated handle and tag value macros 425 */ 426 #define AT2_MAKE_TAGID(tid, bus, inst, aep) \ 427 tid = aep->at_rxid; \ 428 tid |= (((uint64_t)inst) << 32); \ 429 tid |= (((uint64_t)bus) << 48) 430 431 #define CT2_MAKE_TAGID(tid, bus, inst, ct) \ 432 tid = ct->ct_rxid; \ 433 tid |= (((uint64_t)inst) << 32); \ 434 tid |= (((uint64_t)(bus & 0xff)) << 48) 435 436 #define AT2_HAS_TAG(val) 1 437 #define AT2_GET_TAG(val) ((val) & 0xffffffff) 438 #define AT2_GET_INST(val) ((val) >> 32) 439 #define AT2_GET_HANDLE AT2_GET_TAG 440 #define AT2_GET_BUS(val) (((val) >> 48) & 0xff) 441 442 #define FC_HAS_TAG AT2_HAS_TAG 443 #define FC_GET_TAG AT2_GET_TAG 444 #define FC_GET_INST AT2_GET_INST 445 #define FC_GET_HANDLE AT2_GET_HANDLE 446 447 #define IN_FC_MAKE_TAGID(tid, bus, inst, seqid) \ 448 tid = seqid; \ 449 tid |= (((uint64_t)inst) << 32); \ 450 tid |= (((uint64_t)(bus & 0xff)) << 48) 451 452 #define FC_TAG_INSERT_INST(tid, inst) \ 453 tid &= ~0xffff00000000ull; \ 454 tid |= (((uint64_t)inst) << 32) 455 456 /* 457 * 24XX ATIO Definition 458 * 459 * This is *quite* different from other entry types. 460 * First of all, it has its own queue it comes in on. 461 * 462 * Secondly, it doesn't have a normal header. 463 * 464 * Thirdly, it's just a passthru of the FCP CMND IU 465 * which is recorded in big endian mode. 466 */ 467 typedef struct { 468 uint8_t at_type; 469 uint8_t at_count; 470 /* 471 * Task attribute in high four bits, 472 * the rest is the FCP CMND IU Length. 473 * NB: the command can extend past the 474 * length for a single queue entry. 475 */ 476 uint16_t at_ta_len; 477 uint32_t at_rxid; 478 fc_hdr_t at_hdr; 479 fcp_cmnd_iu_t at_cmnd; 480 } at7_entry_t; 481 482 483 /* 484 * Continue Target I/O Entry structure 485 * Request from driver. The response from the 486 * ISP firmware is the same except that the last 18 487 * bytes are overwritten by suggested sense data if 488 * the 'autosense valid' bit is set in the status byte. 489 */ 490 typedef struct { 491 isphdr_t ct_header; 492 uint16_t ct_syshandle; 493 uint16_t ct_fwhandle; /* required by f/w */ 494 uint8_t ct_lun; /* lun */ 495 uint8_t ct_iid; /* initiator id */ 496 uint8_t ct_reserved2; 497 uint8_t ct_tgt; /* our target id */ 498 uint32_t ct_flags; 499 uint8_t ct_status; /* isp status */ 500 uint8_t ct_scsi_status; /* scsi status */ 501 uint8_t ct_tag_val; /* tag value */ 502 uint8_t ct_tag_type; /* tag type */ 503 uint32_t ct_xfrlen; /* transfer length */ 504 uint32_t ct_resid; /* residual length */ 505 uint16_t ct_timeout; 506 uint16_t ct_seg_count; 507 ispds_t ct_dataseg[ISP_RQDSEG]; 508 } ct_entry_t; 509 510 /* 511 * For some of the dual port SCSI adapters, port (bus #) is reported 512 * in the MSbit of ct_iid. Bit fields are a bit too awkward here. 513 * 514 * Note that this does not apply to FC adapters at all which can and 515 * do report IIDs between 0x81 && 0xfe (or 0x7ff) which represent devices 516 * that have logged in across a SCSI fabric. 517 */ 518 #define GET_IID_VAL(x) (x & 0x3f) 519 #define GET_BUS_VAL(x) ((x >> 7) & 0x1) 520 #define SET_IID_VAL(y, x) y = ((y & ~0x3f) | (x & 0x3f)) 521 #define SET_BUS_VAL(y, x) y = ((y & 0x3f) | ((x & 0x1) << 7)) 522 523 /* 524 * ct_flags values 525 */ 526 #define CT_TQAE 0x00000002 /* bit 1, Tagged Queue Action enable */ 527 #define CT_DATA_IN 0x00000040 /* bits 6&7, Data direction */ 528 #define CT_DATA_OUT 0x00000080 /* bits 6&7, Data direction */ 529 #define CT_NO_DATA 0x000000C0 /* bits 6&7, Data direction */ 530 #define CT_CCINCR 0x00000100 /* bit 8, autoincrement atio count */ 531 #define CT_DATAMASK 0x000000C0 /* bits 6&7, Data direction */ 532 #define CT_INISYNCWIDE 0x00004000 /* bit 14, Do Sync/Wide Negotiation */ 533 #define CT_NODISC 0x00008000 /* bit 15, Disconnects disabled */ 534 #define CT_DSDP 0x01000000 /* bit 24, Disable Save Data Pointers */ 535 #define CT_SENDRDP 0x04000000 /* bit 26, Send Restore Pointers msg */ 536 #define CT_SENDSTATUS 0x80000000 /* bit 31, Send SCSI status byte */ 537 538 /* 539 * ct_status values 540 * - set by the firmware when it returns the CTIO 541 */ 542 #define CT_OK 0x01 /* completed without error */ 543 #define CT_ABORTED 0x02 /* aborted by host */ 544 #define CT_ERR 0x04 /* see sense data for error */ 545 #define CT_INVAL 0x06 /* request for disabled lun */ 546 #define CT_NOPATH 0x07 /* invalid ITL nexus */ 547 #define CT_INVRXID 0x08 /* (FC only) Invalid RX_ID */ 548 #define CT_DATA_OVER 0x09 /* (FC only) Data Overrun */ 549 #define CT_RSELTMO 0x0A /* reselection timeout after 2 tries */ 550 #define CT_TIMEOUT 0x0B /* timed out */ 551 #define CT_RESET 0x0E /* SCSI Bus Reset occurred */ 552 #define CT_PARITY 0x0F /* Uncorrectable Parity Error */ 553 #define CT_BUS_ERROR 0x10 /* (FC Only) DMA PCI Error */ 554 #define CT_PANIC 0x13 /* Unrecoverable Error */ 555 #define CT_PHASE_ERROR 0x14 /* Bus phase sequence error */ 556 #define CT_DATA_UNDER 0x15 /* (FC only) Data Underrun */ 557 #define CT_BDR_MSG 0x17 /* Bus Device Reset msg received */ 558 #define CT_TERMINATED 0x19 /* due to Terminate Transfer mbox cmd */ 559 #define CT_PORTUNAVAIL 0x28 /* port not available */ 560 #define CT_LOGOUT 0x29 /* port logout */ 561 #define CT_PORTCHANGED 0x2A /* port changed */ 562 #define CT_IDE 0x33 /* Initiator Detected Error */ 563 #define CT_NOACK 0x35 /* Outstanding Immed. Notify. entry */ 564 #define CT_SRR 0x45 /* SRR Received */ 565 #define CT_LUN_RESET 0x48 /* Lun Reset Received */ 566 567 /* 568 * When the firmware returns a CTIO entry, it may overwrite the last 569 * part of the structure with sense data. This starts at offset 0x2E 570 * into the entry, which is in the middle of ct_dataseg[1]. Rather 571 * than define a new struct for this, I'm just using the sense data 572 * offset. 573 */ 574 #define CTIO_SENSE_OFFSET 0x2E 575 576 /* 577 * Entry length in u_longs. All entries are the same size so 578 * any one will do as the numerator. 579 */ 580 #define UINT32_ENTRY_SIZE (sizeof(at_entry_t)/sizeof(uint32_t)) 581 582 /* 583 * QLA2100 CTIO (type 2) entry 584 */ 585 #define MAXRESPLEN 26 586 typedef struct { 587 isphdr_t ct_header; 588 uint32_t ct_syshandle; 589 uint8_t ct_lun; /* lun */ 590 uint8_t ct_iid; /* initiator id */ 591 uint16_t ct_rxid; /* response ID */ 592 uint16_t ct_flags; 593 uint16_t ct_status; /* isp status */ 594 uint16_t ct_timeout; 595 uint16_t ct_seg_count; 596 uint32_t ct_reloff; /* relative offset */ 597 int32_t ct_resid; /* residual length */ 598 union { 599 /* 600 * The three different modes that the target driver 601 * can set the CTIO{2,3,4} up as. 602 * 603 * The first is for sending FCP_DATA_IUs as well as 604 * (optionally) sending a terminal SCSI status FCP_RSP_IU. 605 * 606 * The second is for sending SCSI sense data in an FCP_RSP_IU. 607 * Note that no FCP_DATA_IUs will be sent. 608 * 609 * The third is for sending FCP_RSP_IUs as built specifically 610 * in system memory as located by the isp_dataseg. 611 */ 612 struct { 613 uint32_t _reserved; 614 uint16_t _reserved2; 615 uint16_t ct_scsi_status; 616 uint32_t ct_xfrlen; 617 union { 618 ispds_t ct_dataseg[ISP_RQDSEG_T2]; 619 ispds64_t ct_dataseg64[ISP_RQDSEG_T3]; 620 ispdslist_t ct_dslist; 621 } u; 622 } m0; 623 struct { 624 uint16_t _reserved; 625 uint16_t _reserved2; 626 uint16_t ct_senselen; 627 uint16_t ct_scsi_status; 628 uint16_t ct_resplen; 629 uint8_t ct_resp[MAXRESPLEN]; 630 } m1; 631 struct { 632 uint32_t _reserved; 633 uint16_t _reserved2; 634 uint16_t _reserved3; 635 uint32_t ct_datalen; 636 ispds_t ct_fcp_rsp_iudata; 637 } m2; 638 } rsp; 639 } ct2_entry_t; 640 641 typedef struct { 642 isphdr_t ct_header; 643 uint32_t ct_syshandle; 644 uint16_t ct_iid; /* initiator id */ 645 uint16_t ct_rxid; /* response ID */ 646 uint16_t ct_flags; 647 uint16_t ct_status; /* isp status */ 648 uint16_t ct_timeout; 649 uint16_t ct_seg_count; 650 uint32_t ct_reloff; /* relative offset */ 651 int32_t ct_resid; /* residual length */ 652 union { 653 struct { 654 uint32_t _reserved; 655 uint16_t _reserved2; 656 uint16_t ct_scsi_status; 657 uint32_t ct_xfrlen; 658 union { 659 ispds_t ct_dataseg[ISP_RQDSEG_T2]; 660 ispds64_t ct_dataseg64[ISP_RQDSEG_T3]; 661 ispdslist_t ct_dslist; 662 } u; 663 } m0; 664 struct { 665 uint16_t _reserved; 666 uint16_t _reserved2; 667 uint16_t ct_senselen; 668 uint16_t ct_scsi_status; 669 uint16_t ct_resplen; 670 uint8_t ct_resp[MAXRESPLEN]; 671 } m1; 672 struct { 673 uint32_t _reserved; 674 uint16_t _reserved2; 675 uint16_t _reserved3; 676 uint32_t ct_datalen; 677 ispds_t ct_fcp_rsp_iudata; 678 } m2; 679 } rsp; 680 } ct2e_entry_t; 681 682 /* 683 * ct_flags values for CTIO2 684 */ 685 #define CT2_FLAG_MODE0 0x0000 686 #define CT2_FLAG_MODE1 0x0001 687 #define CT2_FLAG_MODE2 0x0002 688 #define CT2_FLAG_MMASK 0x0003 689 #define CT2_DATA_IN 0x0040 690 #define CT2_DATA_OUT 0x0080 691 #define CT2_NO_DATA 0x00C0 692 #define CT2_DATAMASK 0x00C0 693 #define CT2_CCINCR 0x0100 694 #define CT2_FASTPOST 0x0200 695 #define CT2_CONFIRM 0x2000 696 #define CT2_TERMINATE 0x4000 697 #define CT2_SENDSTATUS 0x8000 698 699 /* 700 * ct_status values are (mostly) the same as that for ct_entry. 701 */ 702 703 /* 704 * ct_scsi_status values- the low 8 bits are the normal SCSI status 705 * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU 706 * fields. 707 */ 708 #define CT2_RSPLEN_VALID 0x0100 709 #define CT2_SNSLEN_VALID 0x0200 710 #define CT2_DATA_OVER 0x0400 711 #define CT2_DATA_UNDER 0x0800 712 713 /* 714 * ISP24XX CTIO 715 */ 716 #define MAXRESPLEN_24XX 24 717 typedef struct { 718 isphdr_t ct_header; 719 uint32_t ct_syshandle; 720 uint16_t ct_nphdl; /* status on returned CTIOs */ 721 uint16_t ct_timeout; 722 uint16_t ct_seg_count; 723 uint8_t ct_vpindex; 724 uint8_t ct_xflags; 725 uint16_t ct_iid_lo; /* low 16 bits of portid */ 726 uint8_t ct_iid_hi; /* hi 8 bits of portid */ 727 uint8_t ct_reserved; 728 uint32_t ct_rxid; 729 uint16_t ct_senselen; /* mode 0 only */ 730 uint16_t ct_flags; 731 int32_t ct_resid; /* residual length */ 732 uint16_t ct_oxid; 733 uint16_t ct_scsi_status; /* modes 0 && 1 only */ 734 union { 735 struct { 736 uint32_t reloff; 737 uint32_t reserved0; 738 uint32_t ct_xfrlen; 739 uint32_t reserved1; 740 ispds64_t ds; 741 } m0; 742 struct { 743 uint16_t ct_resplen; 744 uint16_t reserved; 745 uint8_t ct_resp[MAXRESPLEN_24XX]; 746 } m1; 747 struct { 748 uint32_t reserved0; 749 uint32_t ct_datalen; 750 uint32_t reserved1; 751 ispds64_t ct_fcp_rsp_iudata; 752 } m2; 753 } rsp; 754 } ct7_entry_t; 755 756 /* 757 * ct_flags values for CTIO7 758 */ 759 #define CT7_DATA_IN 0x0002 760 #define CT7_DATA_OUT 0x0001 761 #define CT7_NO_DATA 0x0000 762 #define CT7_DATAMASK 0x003 763 #define CT7_DSD_ENABLE 0x0004 764 #define CT7_CONF_STSFD 0x0010 765 #define CT7_EXPLCT_CONF 0x0020 766 #define CT7_FLAG_MODE0 0x0000 767 #define CT7_FLAG_MODE1 0x0040 768 #define CT7_FLAG_MODE7 0x0080 769 #define CT7_FLAG_MMASK 0x00C0 770 #define CT7_FASTPOST 0x0100 771 #define CT7_ATTR_MASK 0x1e00 /* task attributes from atio7 */ 772 #define CT7_CONFIRM 0x2000 773 #define CT7_TERMINATE 0x4000 774 #define CT7_SENDSTATUS 0x8000 775 776 /* 777 * Type 7 CTIO status codes 778 */ 779 #define CT7_OK 0x01 /* completed without error */ 780 #define CT7_ABORTED 0x02 /* aborted by host */ 781 #define CT7_ERR 0x04 /* see sense data for error */ 782 #define CT7_INVAL 0x06 /* request for disabled lun */ 783 #define CT7_INVRXID 0x08 /* (FC only) Invalid RX_ID */ 784 #define CT7_DATA_OVER 0x09 /* (FC only) Data Overrun */ 785 #define CT7_TIMEOUT 0x0B /* timed out */ 786 #define CT7_RESET 0x0E /* LIP Rset Received */ 787 #define CT7_BUS_ERROR 0x10 /* DMA PCI Error */ 788 #define CT7_REASSY_ERR 0x11 /* DMA reassembly error */ 789 #define CT7_DATA_UNDER 0x15 /* (FC only) Data Underrun */ 790 #define CT7_PORTUNAVAIL 0x28 /* port not available */ 791 #define CT7_LOGOUT 0x29 /* port logout */ 792 #define CT7_PORTCHANGED 0x2A /* port changed */ 793 #define CT7_SRR 0x45 /* SRR Received */ 794 795 /* 796 * Other 24XX related target IOCBs 797 */ 798 799 /* 800 * ABTS Received 801 */ 802 typedef struct { 803 isphdr_t abts_header; 804 uint8_t abts_reserved0[6]; 805 uint16_t abts_nphdl; 806 uint16_t abts_reserved1; 807 uint16_t abts_sof; 808 uint32_t abts_rxid_abts; 809 uint16_t abts_did_lo; 810 uint8_t abts_did_hi; 811 uint8_t abts_r_ctl; 812 uint16_t abts_sid_lo; 813 uint8_t abts_sid_hi; 814 uint8_t abts_cs_ctl; 815 uint16_t abts_fs_ctl; 816 uint8_t abts_f_ctl; 817 uint8_t abts_type; 818 uint16_t abts_seq_cnt; 819 uint8_t abts_df_ctl; 820 uint8_t abts_seq_id; 821 uint16_t abts_rx_id; 822 uint16_t abts_ox_id; 823 uint32_t abts_param; 824 uint8_t abts_reserved2[16]; 825 uint32_t abts_rxid_task; 826 } abts_t; 827 828 typedef struct { 829 isphdr_t abts_rsp_header; 830 uint32_t abts_rsp_handle; 831 uint16_t abts_rsp_status; 832 uint16_t abts_rsp_nphdl; 833 uint16_t abts_rsp_ctl_flags; 834 uint16_t abts_rsp_sof; 835 uint32_t abts_rsp_rxid_abts; 836 uint16_t abts_rsp_did_lo; 837 uint8_t abts_rsp_did_hi; 838 uint8_t abts_rsp_r_ctl; 839 uint16_t abts_rsp_sid_lo; 840 uint8_t abts_rsp_sid_hi; 841 uint8_t abts_rsp_cs_ctl; 842 uint16_t abts_rsp_f_ctl_lo; 843 uint8_t abts_rsp_f_ctl_hi; 844 uint8_t abts_rsp_type; 845 uint16_t abts_rsp_seq_cnt; 846 uint8_t abts_rsp_df_ctl; 847 uint8_t abts_rsp_seq_id; 848 uint16_t abts_rsp_rx_id; 849 uint16_t abts_rsp_ox_id; 850 uint32_t abts_rsp_param; 851 union { 852 struct { 853 uint16_t reserved; 854 uint8_t last_seq_id; 855 uint8_t seq_id_valid; 856 uint16_t aborted_rx_id; 857 uint16_t aborted_ox_id; 858 uint16_t high_seq_cnt; 859 uint16_t low_seq_cnt; 860 uint8_t reserved2[4]; 861 } ba_acc; 862 struct { 863 uint8_t vendor_unique; 864 uint8_t explanation; 865 uint8_t reason; 866 uint8_t reserved; 867 uint8_t reserved2[12]; 868 } ba_rjt; 869 struct { 870 uint8_t reserved[8]; 871 uint32_t subcode1; 872 uint32_t subcode2; 873 } rsp; 874 uint8_t reserved[16]; 875 } abts_rsp_payload; 876 uint32_t abts_rsp_rxid_task; 877 } abts_rsp_t; 878 879 /* terminate this ABTS exchange */ 880 #define ISP24XX_ABTS_RSP_TERMINATE 0x01 881 882 #define ISP24XX_ABTS_RSP_COMPLETE 0x00 883 #define ISP24XX_ABTS_RSP_RESET 0x04 884 #define ISP24XX_ABTS_RSP_ABORTED 0x05 885 #define ISP24XX_ABTS_RSP_TIMEOUT 0x06 886 #define ISP24XX_ABTS_RSP_INVXID 0x08 887 #define ISP24XX_ABTS_RSP_LOGOUT 0x29 888 #define ISP24XX_ABTS_RSP_SUBCODE 0x31 889 890 /* 891 * Debug macros 892 */ 893 894 #define ISP_TDQE(isp, msg, idx, arg) \ 895 if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg) 896 897 #ifndef ISP_TOOLS 898 /* 899 * The functions below are for the publicly available 900 * target mode functions that are internal to the Qlogic driver. 901 */ 902 903 /* 904 * This function handles new response queue entry appropriate for target mode. 905 */ 906 int isp_target_notify(ispsoftc_t *, void *, uint32_t *); 907 908 /* 909 * This function externalizes the ability to acknowledge an Immediate Notify 910 * request. 911 */ 912 void isp_notify_ack(ispsoftc_t *, void *); 913 914 /* 915 * Enable/Disable/Modify a logical unit. 916 * (softc, cmd, bus, tgt, lun, cmd_cnt, inotify_cnt, opaque) 917 */ 918 #define DFLT_CMND_CNT 0xfe /* unmonitored */ 919 #define DFLT_INOT_CNT 0xfe /* unmonitored */ 920 int isp_lun_cmd(ispsoftc_t *, int, int, int, int, int, int, uint32_t); 921 922 /* 923 * General request queue 'put' routine for target mode entries. 924 */ 925 int isp_target_put_entry(ispsoftc_t *isp, void *); 926 927 /* 928 * General routine to put back an ATIO entry- 929 * used for replenishing f/w resource counts. 930 * The argument is a pointer to a source ATIO 931 * or ATIO2. 932 */ 933 int isp_target_put_atio(ispsoftc_t *, void *); 934 935 /* 936 * General routine to send a final CTIO for a command- used mostly for 937 * local responses. 938 */ 939 int isp_endcmd(ispsoftc_t *, void *, uint32_t, uint32_t); 940 #define ECMD_SVALID 0x100 941 942 /* 943 * Handle an asynchronous event 944 * 945 * Return nonzero if the interrupt that generated this event has been dismissed. 946 */ 947 int isp_target_async(ispsoftc_t *, int, int); 948 #endif 949 #endif /* _ISP_TARGET_H */ 950