isp_target.h revision 57217
11590Srgrimes/* $FreeBSD: head/sys/dev/isp/isp_target.h 57217 2000-02-15 00:54:26Z mjacob $ */ 21590Srgrimes/* 31590Srgrimes * Qlogic Target Mode Structure and Flag Definitions 41590Srgrimes * 51590Srgrimes * Copyright (c) 1997, 1998 61590Srgrimes * Patrick Stirling 71590Srgrimes * pms@psconsult.com 81590Srgrimes * All rights reserved. 91590Srgrimes * 101590Srgrimes * Additional Copyright (c) 1999 111590Srgrimes * Matthew Jacob 121590Srgrimes * mjacob@feral.com 131590Srgrimes * All rights reserved. 141590Srgrimes * 151590Srgrimes * 161590Srgrimes * Redistribution and use in source and binary forms, with or without 171590Srgrimes * modification, are permitted provided that the following conditions 181590Srgrimes * are met: 191590Srgrimes * 1. Redistributions of source code must retain the above copyright 201590Srgrimes * notice immediately at the beginning of the file, without modification, 211590Srgrimes * this list of conditions, and the following disclaimer. 221590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 231590Srgrimes * notice, this list of conditions and the following disclaimer in the 241590Srgrimes * documentation and/or other materials provided with the distribution. 251590Srgrimes * 3. The name of the author may not be used to endorse or promote products 261590Srgrimes * derived from this software without specific prior written permission. 271590Srgrimes * 281590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 291590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3087675Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3187675Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 3287675Smarkm * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3387675Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 341590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3528695Scharnier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361590Srgrimes * SUCH DAMAGE. 371590Srgrimes * 3887675Smarkm */ 391590Srgrimes#ifndef _ISPTARGET_H 401590Srgrimes#define _ISPTARGET_H 4187675Smarkm 4228695Scharnier/* 431590Srgrimes * Defines for all entry types 441590Srgrimes */ 451590Srgrimes#define QLTM_SVALID 0x80 461590Srgrimes#define QLTM_SENSELEN 18 471590Srgrimes 481590Srgrimes/* 491590Srgrimes * Structure for Enable Lun and Modify Lun queue entries 501590Srgrimes */ 511590Srgrimestypedef struct { 521590Srgrimes isphdr_t le_header; 5328695Scharnier u_int32_t le_reserved; 5428695Scharnier u_int8_t le_lun; 5573255Simp u_int8_t le_rsvd; 5625777Sache u_int8_t le_ops; /* Modify LUN only */ 571590Srgrimes u_int8_t le_tgt; /* Not for FC */ 581590Srgrimes u_int32_t le_flags; /* Not for FC */ 591590Srgrimes u_int8_t le_status; 601590Srgrimes u_int8_t le_reserved2; 611590Srgrimes u_int8_t le_cmd_count; 6229434Sache u_int8_t le_in_count; 631590Srgrimes u_int8_t le_cdb6len; /* Not for FC */ 64202200Sed u_int8_t le_cdb7len; /* Not for FC */ 65233269Sglebius u_int16_t le_timeout; 66233269Sglebius u_int16_t le_reserved3[20]; 671590Srgrimes} lun_entry_t; 6883242Sdd 6983242Sdd/* 7073255Simp * le_flags values 7173255Simp */ 721590Srgrimes#define LUN_TQAE 0x00000001 /* bit1 Tagged Queue Action Enable */ 73227200Sed#define LUN_DSSM 0x01000000 /* bit24 Disable Sending SDP Message */ 7473255Simp#define LUN_DM 0x40000000 /* bit30 Disconnects Mandatory */ 7573255Simp 7673255Simp/* 7773255Simp * le_ops values 78227200Sed */ 79227200Sed#define LUN_CCINCR 0x01 /* increment command count */ 80227200Sed#define LUN_CCDECR 0x02 /* decrement command count */ 811590Srgrimes#define LUN_ININCR 0x40 /* increment immed. notify count */ 82155875Scognet#define LUN_INDECR 0x80 /* decrement immed. notify count */ 83200156Sed 84155875Scognet/* 85155875Scognet * le_status values 86155875Scognet */ 87155875Scognet#define LUN_OK 0x01 /* we be rockin' */ 88200156Sed#define LUN_ERR 0x04 /* request completed with error */ 89155875Scognet#define LUN_INVAL 0x06 /* invalid request */ 90155875Scognet#define LUN_NOCAP 0x16 /* can't provide requested capability */ 91155875Scognet#define LUN_ENABLED 0x3E /* LUN already enabled */ 92155875Scognet 93155875Scognet/* 94155875Scognet * Immediate Notify Entry structure 951590Srgrimes */ 9673255Simp#define IN_MSGLEN 8 /* 8 bytes */ 971590Srgrimes#define IN_RSVDLEN 8 /* 8 words */ 981590Srgrimestypedef struct { 99200156Sed isphdr_t in_header; 10073255Simp u_int32_t in_reserved; 10183082Sru u_int8_t in_lun; /* lun */ 10273255Simp u_int8_t in_iid; /* initiator */ 10373255Simp u_int8_t in_reserved2; 10483242Sdd u_int8_t in_tgt; /* target */ 10583242Sdd u_int32_t in_flags; 10673255Simp u_int8_t in_status; 1071590Srgrimes u_int8_t in_rsvd2; 10825777Sache u_int8_t in_tag_val; /* tag value */ 10925777Sache u_int8_t in_tag_type; /* tag type */ 11073255Simp u_int16_t in_seqid; /* sequence id */ 1111590Srgrimes u_int8_t in_msg[IN_MSGLEN]; /* SCSI message bytes */ 1121590Srgrimes u_int16_t in_reserved3[IN_RSVDLEN]; 1131590Srgrimes u_int8_t in_sense[QLTM_SENSELEN];/* suggested sense data */ 1141590Srgrimes} in_entry_t; 1151590Srgrimes 1161590Srgrimestypedef struct { 11773255Simp isphdr_t in_header; 11873255Simp u_int32_t in_reserved; 11973255Simp u_int8_t in_lun; /* lun */ 12073255Simp u_int8_t in_iid; /* initiator */ 12173255Simp u_int16_t in_scclun; 12273255Simp u_int32_t in_reserved2; 12373255Simp u_int16_t in_status; 1241590Srgrimes u_int16_t in_task_flags; 1251590Srgrimes u_int16_t in_seqid; /* sequence id */ 12628695Scharnier} in_fcentry_t; 1271590Srgrimes 1281590Srgrimes/* 1291590Srgrimes * Values for the in_status field 1301590Srgrimes */ 13128695Scharnier#define IN_RESET 0x0E /* Bus Reset occurred */ 1321590Srgrimes#define IN_NO_RCAP 0x16 /* requested capability not available */ 13373255Simp#define IN_IDE_RECEIVED 0x33 /* Initiator Detected Error msg received */ 13473255Simp#define IN_RSRC_UNAVAIL 0x34 /* resource unavailable */ 13573320Simp#define IN_MSG_RECEIVED 0x36 /* SCSI message received */ 13673255Simp#define IN_ABORT_TASK 0x20 /* task named in RX_ID is being aborted (FC) */ 13773320Simp#define IN_PORT_LOGOUT 0x29 /* port has logged out (FC) */ 13873320Simp#define IN_PORT_CHANGED 0x2A /* port changed */ 13973255Simp#define IN_GLOBAL_LOGO 0x2E /* all ports logged out */ 14073255Simp 1411590Srgrimes/* 1421590Srgrimes * Values for the in_task_flags field- should only get one at a time! 1431590Srgrimes */ 1441590Srgrimes#define TASK_FLAGS_ABORT_TASK (1<<9) 1451590Srgrimes#define TASK_FLAGS_CLEAR_TASK_SET (1<<10) 146200156Sed#define TASK_FLAGS_TARGET_RESET (1<<13) 147200156Sed#define TASK_FLAGS_CLEAR_ACA (1<<14) 1481590Srgrimes#define TASK_FLAGS_TERMINATE_TASK (1<<15) 149200156Sed 150155875Scognet#ifndef MSG_ABORT_TAG 15173255Simp#define MSG_ABORT_TAG 0x06 15283082Sru#endif 153200156Sed#ifndef MSG_CLEAR_QUEUE 15473255Simp#define MSG_CLEAR_QUEUE 0x0e 15573255Simp#endif 15673255Simp#ifndef MSG_BUS_DEV_RESET 15787675Smarkm#define MSG_BUS_DEV_RESET 0x0b 15873255Simp#endif 15973255Simp#ifndef MSG_REL_RECOVERY 16073255Simp#define MSG_REL_RECOVERY 0x10 16183082Sru#endif 16283082Sru#ifndef MSG_TERM_IO_PROC 163200156Sed#define MSG_TERM_IO_PROC 0x11 16483082Sru#endif 16583082Sru 16683082Sru 16783082Sru/* 16883082Sru * Notify Acknowledge Entry structure 16973255Simp */ 17073255Simp#define NA_RSVDLEN 22 17173255Simptypedef struct { 17273255Simp isphdr_t na_header; 173200156Sed u_int32_t na_reserved; 17428695Scharnier u_int8_t na_lun; /* lun */ 1751590Srgrimes u_int8_t na_iid; /* initiator */ 1761590Srgrimes u_int8_t na_reserved2; 1771590Srgrimes u_int8_t na_tgt; /* target */ 1781590Srgrimes u_int32_t na_flags; 17928695Scharnier u_int8_t na_status; 180201224Sed u_int8_t na_event; 18128695Scharnier u_int16_t na_seqid; /* sequence id */ 18273320Simp u_int16_t na_reserved3[NA_RSVDLEN]; 18328695Scharnier} na_entry_t; 18428695Scharnier 18528695Scharnier/* 1861590Srgrimes * Value for the na_event field 18773255Simp */ 1881590Srgrimes#define NA_RST_CLRD 0x80 /* Clear an async event notification */ 18973255Simp 190233269Sglebius#define NA2_RSVDLEN 21 1911590Srgrimestypedef struct { 1921590Srgrimes isphdr_t na_header; 1931590Srgrimes u_int32_t na_reserved; 19429434Sache u_int8_t na_lun; /* lun */ 1951590Srgrimes u_int8_t na_iid; /* initiator */ 1961590Srgrimes u_int16_t na_scclun; 197233269Sglebius u_int16_t na_flags; 198233269Sglebius u_int16_t na_reserved2; 19987675Smarkm u_int16_t na_status; 20069231Skris u_int16_t na_task_flags; 20176367Skris u_int16_t na_seqid; /* sequence id */ 2021590Srgrimes u_int16_t na_reserved3[NA2_RSVDLEN]; 20369231Skris} na_fcentry_t; 20469231Skris#define NAFC_RCOUNT 0x80 /* increment resource count */ 20569231Skris#define NAFC_RST_CLRD 0x20 /* Clear LIP Reset */ 2061590Srgrimes/* 2071590Srgrimes * Accept Target I/O Entry structure 2081590Srgrimes */ 20969231Skris#define ATIO_CDBLEN 26 21069231Skris 21166557Sn_hibmatypedef struct { 21266557Sn_hibma isphdr_t at_header; 2131590Srgrimes u_int32_t at_reserved; 2141590Srgrimes u_int8_t at_lun; /* lun */ 2151590Srgrimes u_int8_t at_iid; /* initiator */ 2161590Srgrimes u_int8_t at_cdblen; /* cdb length */ 2171590Srgrimes u_int8_t at_tgt; /* target */ 2181590Srgrimes u_int32_t at_flags; 2191590Srgrimes u_int8_t at_status; /* firmware status */ 2201590Srgrimes u_int8_t at_scsi_status; /* scsi status */ 2211590Srgrimes u_int8_t at_tag_val; /* tag value */ 2221590Srgrimes u_int8_t at_tag_type; /* tag type */ 2231590Srgrimes u_int8_t at_cdb[ATIO_CDBLEN]; /* received CDB */ 2241590Srgrimes u_int8_t at_sense[QLTM_SENSELEN];/* suggested sense data */ 2251590Srgrimes} at_entry_t; 226233269Sglebius 227233269Sglebius/* 228233269Sglebius * at_flags values 2291590Srgrimes */ 230233269Sglebius#define AT_NODISC 0x00008000 /* disconnect disabled */ 231233269Sglebius#define AT_TQAE 0x00000001 /* Tagged Queue Action enabled */ 232233269Sglebius 23363909Sasmodai/* 234233269Sglebius * at_status values 2351590Srgrimes */ 236233269Sglebius#define AT_PATH_INVALID 0x07 /* ATIO sent to firmware for disabled lun */ 2371590Srgrimes#define AT_RESET 0x0E /* SCSI Bus Reset Occurred */ 23876367Skris#define AT_PHASE_ERROR 0x14 /* Bus phase sequence error */ 23976367Skris#define AT_NOCAP 0x16 /* Requested capability not available */ 24076367Skris#define AT_BDR_MSG 0x17 /* Bus Device Reset msg received */ 241233269Sglebius#define AT_CDB 0x3D /* CDB received */ 24276367Skris 243241848Seadler/* 244241848Seadler * Accept Target I/O Entry structure, Type 2 24576367Skris */ 246223940Sobrien#define ATIO2_CDBLEN 16 247233269Sglebius 248233269Sglebiustypedef struct { 249233269Sglebius isphdr_t at_header; 250233269Sglebius u_int32_t at_reserved; 25150776Sdbaker u_int8_t at_lun; /* lun or reserved */ 252175346Sdas u_int8_t at_iid; /* initiator */ 253233269Sglebius u_int16_t at_rxid; /* response ID */ 2541590Srgrimes u_int16_t at_flags; 255233269Sglebius u_int16_t at_status; /* firmware status */ 256233269Sglebius u_int8_t at_reserved1; 257233269Sglebius u_int8_t at_taskcodes; 258175346Sdas u_int8_t at_taskflags; 259175346Sdas u_int8_t at_execodes; 260175346Sdas u_int8_t at_cdb[ATIO2_CDBLEN]; /* received CDB */ 261233269Sglebius u_int32_t at_datalen; /* allocated data len */ 262233269Sglebius u_int16_t at_scclun; /* SCC Lun or reserved */ 2631590Srgrimes u_int16_t at_reserved2; 264175346Sdas u_int16_t at_scsi_status; 265233269Sglebius u_int8_t at_sense[QLTM_SENSELEN]; 266233269Sglebius} at2_entry_t; 267233269Sglebius 268233269Sglebius#define ATIO2_TC_ATTR_MASK 0x7 269233269Sglebius#define ATIO2_TC_ATTR_SIMPLEQ 0 270233269Sglebius#define ATIO2_TC_ATTR_HEADOFQ 1 27129434Sache#define ATIO2_TC_ATTR_ORDERED 2 272233269Sglebius#define ATIO2_TC_ATTR_ACAQ 4 273233269Sglebius#define ATIO2_TC_ATTR_UNTAGGED 5 27429434Sache 27529434Sache/* 27624729Sache * Continue Target I/O Entry structure 277233269Sglebius * Request from driver. The response from the 27829434Sache * ISP firmware is the same except that the last 18 2791590Srgrimes * bytes are overwritten by suggested sense data if 280175346Sdas * the 'autosense valid' bit is set in the status byte. 281233269Sglebius */ 2821590Srgrimestypedef struct { 2831590Srgrimes isphdr_t ct_header; 28428695Scharnier u_int32_t ct_reserved; 28569231Skris u_int8_t ct_lun; /* lun */ 2861590Srgrimes u_int8_t ct_iid; /* initiator id */ 28728695Scharnier u_int8_t ct_reserved2; 28869231Skris u_int8_t ct_tgt; /* our target id */ 28987675Smarkm u_int32_t ct_flags; 29069231Skris u_int8_t ct_status; /* isp status */ 2911590Srgrimes u_int8_t ct_scsi_status; /* scsi status */ 2921590Srgrimes u_int8_t ct_tag_val; /* tag value */ 293 u_int8_t ct_tag_type; /* tag type */ 294 u_int32_t ct_xfrlen; /* transfer length */ 295 u_int32_t ct_resid; /* residual length */ 296 u_int16_t ct_timeout; 297 u_int16_t ct_seg_count; 298 ispds_t ct_dataseg[ISP_RQDSEG]; 299} ct_entry_t; 300 301/* 302 * For some of the dual port SCSI adapters, port (bus #) is reported 303 * in the MSbit of ct_iid. Bit fields are a bit too awkward here. 304 * 305 * Note that this does not apply to FC adapters at all which can and 306 * do report IIDs between 129 && 255 (these represent devices that have 307 * logged in across a SCSI fabric). 308 */ 309#define GET_IID_VAL(x) (x & 0x3f) 310#define GET_BUS_VAL(x) ((x >> 7) & 0x1) 311#define SET_IID_VAL(y, x) (y | (x & 0x3f)) 312#define SET_BUS_VAL(y, x) (y | ((x & 0x1) << 7)) 313 314/* 315 * ct_flags values 316 */ 317#define CT_TQAE 0x00000001 /* bit 1, Tagged Queue Action enable */ 318#define CT_DATA_IN 0x00000040 /* bits 6&7, Data direction */ 319#define CT_DATA_OUT 0x00000080 /* bits 6&7, Data direction */ 320#define CT_NO_DATA 0x000000C0 /* bits 6&7, Data direction */ 321#define CT_CCINCR 0x00000100 /* bit 8, autoincrement atio count */ 322#define CT_DATAMASK 0x000000C0 /* bits 6&7, Data direction */ 323#define CT_NODISC 0x00008000 /* bit 15, Disconnects disabled */ 324#define CT_DSDP 0x01000000 /* bit 24, Disable Save Data Pointers */ 325#define CT_SENDRDP 0x04000000 /* bit 26, Send Restore Pointers msg */ 326#define CT_SENDSTATUS 0x80000000 /* bit 31, Send SCSI status byte */ 327 328/* 329 * ct_status values 330 * - set by the firmware when it returns the CTIO 331 */ 332#define CT_OK 0x01 /* completed without error */ 333#define CT_ABORTED 0x02 /* aborted by host */ 334#define CT_ERR 0x04 /* see sense data for error */ 335#define CT_INVAL 0x06 /* request for disabled lun */ 336#define CT_NOPATH 0x07 /* invalid ITL nexus */ 337#define CT_INVRXID 0x08 /* (FC only) Invalid RX_ID */ 338#define CT_RSELTMO 0x0A /* reselection timeout after 2 tries */ 339#define CT_TIMEOUT 0x0B /* timed out */ 340#define CT_RESET 0x0E /* SCSI Bus Reset occurred */ 341#define CT_PHASE_ERROR 0x14 /* Bus phase sequence error */ 342#define CT_BDR_MSG 0x17 /* Bus Device Reset msg received */ 343#define CT_TERMINATED 0x19 /* due to Terminate Transfer mbox cmd */ 344#define CT_PORTNOTAVAIL 0x28 /* port not available */ 345#define CT_LOGOUT 0x29 /* port logout */ 346#define CT_PORTCHANGED 0x2A /* port changed */ 347#define CT_NOACK 0x35 /* Outstanding Immed. Notify. entry */ 348 349/* 350 * When the firmware returns a CTIO entry, it may overwrite the last 351 * part of the structure with sense data. This starts at offset 0x2E 352 * into the entry, which is in the middle of ct_dataseg[1]. Rather 353 * than define a new struct for this, I'm just using the sense data 354 * offset. 355 */ 356#define CTIO_SENSE_OFFSET 0x2E 357 358/* 359 * Entry length in u_longs. All entries are the same size so 360 * any one will do as the numerator. 361 */ 362#define UINT32_ENTRY_SIZE (sizeof(at_entry_t)/sizeof(u_int32_t)) 363 364/* 365 * QLA2100 CTIO (type 2) entry 366 */ 367#define MAXRESPLEN 26 368typedef struct { 369 isphdr_t ct_header; 370 u_int32_t ct_reserved; 371 u_int8_t ct_lun; /* lun */ 372 u_int8_t ct_iid; /* initiator id */ 373 u_int16_t ct_rxid; /* response ID */ 374 u_int16_t ct_flags; 375 u_int16_t ct_status; /* isp status */ 376 u_int16_t ct_timeout; 377 u_int16_t ct_seg_count; 378 u_int32_t ct_reloff; /* relative offset */ 379 int32_t ct_resid; /* residual length */ 380 union { 381 /* 382 * The three different modes that the target driver 383 * can set the CTIO2 up as. 384 * 385 * The first is for sending FCP_DATA_IUs as well as 386 * (optionally) sending a terminal SCSI status FCP_RSP_IU. 387 * 388 * The second is for sending SCSI sense data in an FCP_RSP_IU. 389 * Note that no FCP_DATA_IUs will be sent. 390 * 391 * The third is for sending FCP_RSP_IUs as built specifically 392 * in system memory as located by the isp_dataseg. 393 */ 394 struct { 395 u_int32_t _reserved; 396 u_int16_t _reserved2; 397 u_int16_t ct_scsi_status; 398 u_int32_t ct_xfrlen; 399 ispds_t ct_dataseg[ISP_RQDSEG_T2]; 400 } m0; 401 struct { 402 u_int16_t _reserved; 403 u_int16_t _reserved2; 404 u_int16_t ct_senselen; 405 u_int16_t ct_scsi_status; 406 u_int16_t ct_resplen; 407 u_int8_t ct_resp[MAXRESPLEN]; 408 } m1; 409 struct { 410 u_int32_t _reserved; 411 u_int16_t _reserved2; 412 u_int16_t _reserved3; 413 u_int32_t ct_datalen; 414 ispds_t ct_fcp_rsp_iudata; 415 } m2; 416 /* 417 * CTIO2 returned from F/W... 418 */ 419 struct { 420 u_int32_t _reserved[4]; 421 u_int16_t ct_scsi_status; 422 u_int8_t ct_sense[QLTM_SENSELEN]; 423 } fw; 424 } rsp; 425} ct2_entry_t; 426 427/* 428 * ct_flags values for CTIO2 429 */ 430#define CT2_FLAG_MMASK 0x0003 431#define CT2_FLAG_MODE0 0x0000 432#define CT2_FLAG_MODE1 0x0001 433#define CT2_FLAG_MODE2 0x0002 434#define CT2_DATA_IN CT_DATA_IN 435#define CT2_DATA_OUT CT_DATA_OUT 436#define CT2_NO_DATA CT_NO_DATA 437#define CT2_DATAMASK CT_DATAMASK 438#define CT2_CCINCR 0x0100 439#define CT2_FASTPOST 0x0200 440#define CT2_SENDSTATUS 0x8000 441 442/* 443 * ct_status values are (mostly) the same as that for ct_entry. 444 */ 445 446/* 447 * ct_scsi_status values- the low 8 bits are the normal SCSI status 448 * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU 449 * fields. 450 */ 451#define CT2_RSPLEN_VALID 0x0100 452#define CT2_SNSLEN_VALID 0x0200 453#define CT2_DATA_OVER 0x0400 454#define CT2_DATA_UNDER 0x0800 455 456/* 457 * Macros for packing/unpacking the above structures 458 */ 459 460#ifdef __sparc__ 461#define ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb) \ 462 if (isp->isp_bus == ISP_SBUS) { \ 463 source -> taga = dest -> tagb; \ 464 source -> tagb = dest -> taga; \ 465 } else { \ 466 source -> taga = dest -> taga; \ 467 source -> tagb = dest -> taga; \ 468 } 469#else 470#define ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb) \ 471 source -> taga = dest -> taga; \ 472 source -> tagb = dest -> taga; 473#endif 474 475#define MCIDF(d, s) if ((void *) d != (void *)s) MEMCPY(d, s, QENTRY_LEN) 476 477/* This is really only for SBus cards on a sparc */ 478#ifdef __sparc__ 479#define ISP_SWIZ_ATIO(isp, dest, vsrc) \ 480{ \ 481 at_entry_t *source = (at_entry_t *) vsrc; \ 482 at_entry_t local, *vdst; \ 483 if ((void *)dest == (void *)vsrc) { \ 484 MEMCPY(vsrc, &local, sizeof (at_entry_t)); \ 485 vdst = &local; \ 486 } else { \ 487 vdst = dest; \ 488 } \ 489 vdst->at_header = source->at_header; \ 490 vdst->at_reserved2 = source->at_reserved2; \ 491 ISP_SBUS_SWOZZLE(isp, source, vdst, at_lun, at_iid); \ 492 ISP_SBUS_SWOZZLE(isp, source, vdst, at_cdblen, at_tgt); \ 493 vdst->at_flags = source->at_flags; \ 494 ISP_SBUS_SWOZZLE(isp, source, vdst, at_status, at_scsi_status); \ 495 ISP_SBUS_SWOZZLE(isp, source, vdst, at_tag_val, at_tag_type); \ 496 MEMCPY(vdst->at_cdb, source->at_cdb, ATIO_CDBLEN); \ 497 MEMCPY(vdst->at_sense, source->at_sense, QLTM_SENSELEN); \ 498} 499 500#define ISP_SWIZ_CTIO(isp, dest, vsrc) \ 501{ \ 502 ct_entry_t *source = (ct_entry-t *) vsrc; \ 503 ct_entry_t *local, *vdst; \ 504 if ((void *)dest == (void *)vsrc) { \ 505 MEMCPY(vsrc, &local, sizeof (ct_entry_t)); \ 506 vdst = &local; \ 507 } else { \ 508 vdst = dest; \ 509 } \ 510 vdst->ct_header = source->ct_header; \ 511 vdst->ct_reserved = source->ct_reserved; \ 512 ISP_SBUS_SWOZZLE(isp, source, vdst, ct_lun, ct_iid); \ 513 ISP_SBUS_SWOZZLE(isp, source, vdst, ct_rsvd, ct_tgt); \ 514 vdst->ct_flags = source->ct_flags; \ 515 ISP_SBUS_SWOZZLE(isp, source, vdst, ct_status, ct_scsi_status); \ 516 ISP_SBUS_SWOZZLE(isp, source, vdst, ct_tag_val, ct_tag_type); \ 517 vdst->ct_xfrlen = source->ct_xfrlen; \ 518 vdst->ct_resid = source->ct_resid; \ 519 vdst->ct_timeout = source->ct_timeout; \ 520 vdst->ct_seg_count = source->ct_seg_count; \ 521 MEMCPY(vdst->ct_cdb, source->ct_cdb, ATIO_CDBLEN); \ 522 MEMCPY(vdst->ct_sense, source->ct_sense, QLTM_SENSELEN); \ 523 vdst->ct_dataseg = source->ct_dataseg; \ 524} 525#define ISP_SWIZ_ENABLE_LUN(isp, dest, vsrc) \ 526{ \ 527 lun_entry_t *source = (lun_entry_t *)vsrc; \ 528 lun_entry_t *local, *vdst; \ 529 if ((void *)dest == (void *)vsrc) { \ 530 MEMCPY(vsrc, &local, sizeof (lun_entry_t)); \ 531 vdst = &local; \ 532 } else { \ 533 vdst = dest; \ 534 } \ 535 vdst->le_header = source->le_header; \ 536 vdst->le_reserved2 = source->le_reserved2; \ 537 ISP_SBUS_SWOZZLE(isp, source, vdst, le_lun, le_rsvd); \ 538 ISP_SBUS_SWOZZLE(isp, source, vdst, le_ops, le_tgt); \ 539 vdst->le_flags = source->le_flags; \ 540 ISP_SBUS_SWOZZLE(isp, source, vdst, le_status, le_rsvd2); \ 541 ISP_SBUS_SWOZZLE(isp, source, vdst, le_cmd_count, le_in_count); \ 542 ISP_SBUS_SWOZZLE(isp, source, vdst, le_cdb6len, le_cdb7len); \ 543 vdst->le_timeout = source->le_timeout; \ 544 vdst->le_reserved = source->le_reserved; \ 545} 546#define ISP_SWIZ_NOTIFY(isp, dest, vsrc) \ 547{ \ 548 in_entry_type *source = (in_entry_t *)vsrc; \ 549 in_entry_t *local, *vdst; \ 550 if ((void *)dest == (void *)vsrc) { \ 551 MEMCPY(vsrc, &local, sizeof (in_entry_t)); \ 552 vdst = &local; \ 553 } else { \ 554 vdst = dest; \ 555 } \ 556 vdst->in_header = source->in_header; \ 557 vdst->in_reserved2 = source->in_reserved2; \ 558 ISP_SBUS_SWOZZLE(isp, source, vdst, in_lun, in_iid); \ 559 ISP_SBUS_SWOZZLE(isp, source, vdst, in_rsvd, in_tgt); \ 560 vdst->in_flags = source->in_flags; \ 561 ISP_SBUS_SWOZZLE(isp, source, vdst, in_status, in_rsvd2); \ 562 ISP_SBUS_SWOZZLE(isp, source, vdst, in_tag_val, in_tag_type); \ 563 vdst->in_seqid = source->in_seqid; \ 564 MEMCPY(vdst->in_msg, source->in_msg, IN_MSGLEN); \ 565 MEMCPY(vdst->in_reserved, source->in_reserved, IN_RESERVED); \ 566 MEMCPY(vdst->in_sense, source->in_sense, QLTM_SENSELEN); \ 567} 568#define ISP_SWIZ_NOT_ACK(isp, dest) \ 569{ \ 570 na_entry_t *source = (na_entry_t *)vsrc; \ 571 na_entry_t *local, *vdst; \ 572 if ((void *)dest == (void *)vsrc) { \ 573 MEMCPY(vsrc, &local, sizeof (na_entry_t)); \ 574 vdst = &local; \ 575 } else { \ 576 vdst = dest; \ 577 } \ 578 vdst->na_header = source->na_header; \ 579 vdst->na_reserved2 = source->na_reserved2; \ 580 ISP_SBUS_SWOZZLE(isp, source, vdst, na_lun, na_iid); \ 581 ISP_SBUS_SWOZZLE(isp, source, vdst, na_rsvd, na_tgt); \ 582 vdst->na_flags = source->na_flags; \ 583 ISP_SBUS_SWOZZLE(isp, source, vdst, na_status, na_event); \ 584 vdst->na_seqid = source->na_seqid; \ 585 MEMCPY(vdst->na_reserved, source->na_reserved, NA_RSVDLEN); \ 586} 587#define ISP_SWIZ_NOT_ACK_FC(isp, d, s) MCIDF(d, s) 588#define ISP_SWIZ_ATIO2(isp, d, s) MCIDF(d, s) 589#define ISP_SWIZ_CTIO2(isp, d, s) MCIDF(d, s) 590#else 591#define ISP_SWIZ_ATIO(isp, d, s) MCIDF(d, s) 592#define ISP_SWIZ_CTIO(isp, d, s) MCIDF(d, s) 593#define ISP_SWIZ_ENABLE_LUN(isp, d, s) MCIDF(d, s) 594#define ISP_SWIZ_NOTIFY(isp, d, s) MCIDF(d, s) 595#define ISP_SWIZ_NOT_ACK(isp, d, s) MCIDF(d, s) 596#define ISP_SWIZ_NOT_ACK_FC(isp, d, s) MCIDF(d, s) 597#define ISP_SWIZ_ATIO2(isp, d, s) MCIDF(d, s) 598#define ISP_SWIZ_CTIO2(isp, d, s) MCIDF(d, s) 599#endif 600 601/* 602 * Debug macros 603 */ 604 605extern int isp_tdebug; 606#define ISP_TDQE(isp, msg, idx, arg) \ 607 if (isp_tdebug > 3) isp_print_qentry(isp, msg, idx, arg) 608 609#define ITDEBUG(level, msg) if (isp_tdebug >= level) PRINTF msg 610 611/* 612 * The functions below are target mode functions that 613 * are generally internal to the Qlogic driver. 614 */ 615 616/* 617 * This function handles new response queue entry appropriate for target mode. 618 */ 619int isp_target_notify __P((struct ispsoftc *, void *, u_int16_t *)); 620 621/* 622 * Enable/Disable/Modify a logical unit. 623 */ 624#define DFLT_CMD_CNT (RESULT_QUEUE_LEN >> 1) 625#define DFLT_INOTIFY (4) 626int isp_lun_cmd __P((struct ispsoftc *isp, int, int, int, int, u_int32_t)); 627 628/* 629 * General request queue 'put' routine for target mode entries. 630 */ 631int isp_target_put_entry __P((struct ispsoftc *isp, void *)); 632 633/* 634 * General routine to put back an ATIO entry- 635 * used for replenishing f/w resource counts. 636 */ 637int 638isp_target_put_atio __P((struct ispsoftc *isp, int, int, int, int, int)); 639 640/* 641 * General routine to send a final CTIO for a command- used mostly for 642 * local responses. 643 */ 644int 645isp_endcmd __P((struct ispsoftc *isp, void *, u_int32_t, u_int32_t)); 646#define ECMD_SVALID 0x100 647 648/* 649 * Handle an asynchronous event 650 */ 651 652void isp_target_async __P((struct ispsoftc *, int, int)); 653 654#endif /* _ISPTARGET_H */ 655