Home | History | Annotate | Line # | Download | only in ic
isp_target.h revision 1.10
      1 /* $NetBSD: isp_target.h,v 1.10 2000/12/28 08:23:48 mjacob Exp $ */
      2 /*
      3  * This driver, which is contained in NetBSD in the files:
      4  *
      5  *	sys/dev/ic/isp.c
      6  *	sys/dev/ic/isp_inline.h
      7  *	sys/dev/ic/isp_netbsd.c
      8  *	sys/dev/ic/isp_netbsd.h
      9  *	sys/dev/ic/isp_target.c
     10  *	sys/dev/ic/isp_target.h
     11  *	sys/dev/ic/isp_tpublic.h
     12  *	sys/dev/ic/ispmbox.h
     13  *	sys/dev/ic/ispreg.h
     14  *	sys/dev/ic/ispvar.h
     15  *	sys/microcode/isp/asm_sbus.h
     16  *	sys/microcode/isp/asm_1040.h
     17  *	sys/microcode/isp/asm_1080.h
     18  *	sys/microcode/isp/asm_12160.h
     19  *	sys/microcode/isp/asm_2100.h
     20  *	sys/microcode/isp/asm_2200.h
     21  *	sys/pci/isp_pci.c
     22  *	sys/sbus/isp_sbus.c
     23  *
     24  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26  * Linux versions. This tends to be an interesting maintenance problem.
     27  *
     28  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29  */
     30 /*
     31  * Qlogic Target Mode Structure and Flag Definitions
     32  *
     33  * Copyright (c) 1997, 1998
     34  * Patrick Stirling
     35  * pms (at) psconsult.com
     36  * All rights reserved.
     37  *
     38  * Additional Copyright (c) 1999
     39  * Matthew Jacob
     40  * mjacob (at) feral.com
     41  * All rights reserved.
     42  *
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice immediately at the beginning of the file, without modification,
     49  *    this list of conditions, and the following disclaimer.
     50  * 2. Redistributions in binary form must reproduce the above copyright
     51  *    notice, this list of conditions and the following disclaimer in the
     52  *    documentation and/or other materials provided with the distribution.
     53  * 3. The name of the author may not be used to endorse or promote products
     54  *    derived from this software without specific prior written permission.
     55  *
     56  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     57  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     59  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     60  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     61  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  * SUCH DAMAGE.
     65  *
     66  */
     67 #ifndef	_ISPTARGET_H
     68 #define	_ISPTARGET_H
     69 
     70 /*
     71  * Defines for all entry types
     72  */
     73 #define QLTM_SVALID	0x80
     74 #define	QLTM_SENSELEN	18
     75 
     76 /*
     77  * Structure for Enable Lun and Modify Lun queue entries
     78  */
     79 typedef struct {
     80 	isphdr_t	le_header;
     81 	u_int32_t	le_reserved;
     82 	u_int8_t	le_lun;
     83 	u_int8_t	le_rsvd;
     84 	u_int8_t	le_ops;		/* Modify LUN only */
     85 	u_int8_t	le_tgt;		/* Not for FC */
     86 	u_int32_t	le_flags;	/* Not for FC */
     87 	u_int8_t	le_status;
     88 	u_int8_t	le_reserved2;
     89 	u_int8_t	le_cmd_count;
     90 	u_int8_t	le_in_count;
     91 	u_int8_t	le_cdb6len;	/* Not for FC */
     92 	u_int8_t	le_cdb7len;	/* Not for FC */
     93 	u_int16_t	le_timeout;
     94 	u_int16_t	le_reserved3[20];
     95 } lun_entry_t;
     96 
     97 /*
     98  * le_flags values
     99  */
    100 #define LUN_TQAE	0x00000001	/* bit1  Tagged Queue Action Enable */
    101 #define LUN_DSSM	0x01000000	/* bit24 Disable Sending SDP Message */
    102 #define	LUN_DISAD	0x02000000	/* bit25 Disable autodisconnect */
    103 #define LUN_DM		0x40000000	/* bit30 Disconnects Mandatory */
    104 
    105 /*
    106  * le_ops values
    107  */
    108 #define LUN_CCINCR	0x01	/* increment command count */
    109 #define LUN_CCDECR	0x02	/* decrement command count */
    110 #define LUN_ININCR	0x40	/* increment immed. notify count */
    111 #define LUN_INDECR	0x80	/* decrement immed. notify count */
    112 
    113 /*
    114  * le_status values
    115  */
    116 #define	LUN_OK		0x01	/* we be rockin' */
    117 #define LUN_ERR		0x04	/* request completed with error */
    118 #define LUN_INVAL	0x06	/* invalid request */
    119 #define LUN_NOCAP	0x16	/* can't provide requested capability */
    120 #define LUN_ENABLED	0x3E	/* LUN already enabled */
    121 
    122 /*
    123  * Immediate Notify Entry structure
    124  */
    125 #define IN_MSGLEN	8	/* 8 bytes */
    126 #define IN_RSVDLEN	8	/* 8 words */
    127 typedef struct {
    128 	isphdr_t	in_header;
    129 	u_int32_t	in_reserved;
    130 	u_int8_t	in_lun;		/* lun */
    131 	u_int8_t	in_iid;		/* initiator */
    132 	u_int8_t	in_reserved2;
    133 	u_int8_t	in_tgt;		/* target */
    134 	u_int32_t	in_flags;
    135 	u_int8_t	in_status;
    136 	u_int8_t	in_rsvd2;
    137 	u_int8_t	in_tag_val;	/* tag value */
    138 	u_int8_t	in_tag_type;	/* tag type */
    139 	u_int16_t	in_seqid;	/* sequence id */
    140 	u_int8_t	in_msg[IN_MSGLEN];	/* SCSI message bytes */
    141 	u_int16_t	in_reserved3[IN_RSVDLEN];
    142 	u_int8_t	in_sense[QLTM_SENSELEN];/* suggested sense data */
    143 } in_entry_t;
    144 
    145 typedef struct {
    146 	isphdr_t	in_header;
    147 	u_int32_t	in_reserved;
    148 	u_int8_t	in_lun;		/* lun */
    149 	u_int8_t	in_iid;		/* initiator */
    150 	u_int16_t	in_scclun;
    151 	u_int32_t	in_reserved2;
    152 	u_int16_t	in_status;
    153 	u_int16_t	in_task_flags;
    154 	u_int16_t	in_seqid;	/* sequence id */
    155 } in_fcentry_t;
    156 
    157 /*
    158  * Values for the in_status field
    159  */
    160 #define	IN_REJECT	0x0D	/* Message Reject message received */
    161 #define IN_RESET	0x0E	/* Bus Reset occurred */
    162 #define IN_NO_RCAP	0x16	/* requested capability not available */
    163 #define IN_IDE_RECEIVED	0x33	/* Initiator Detected Error msg received */
    164 #define IN_RSRC_UNAVAIL	0x34	/* resource unavailable */
    165 #define IN_MSG_RECEIVED	0x36	/* SCSI message received */
    166 #define	IN_ABORT_TASK	0x20	/* task named in RX_ID is being aborted (FC) */
    167 #define	IN_PORT_LOGOUT	0x29	/* port has logged out (FC) */
    168 #define	IN_PORT_CHANGED	0x2A	/* port changed */
    169 #define	IN_GLOBAL_LOGO	0x2E	/* all ports logged out */
    170 #define	IN_NO_NEXUS	0x3B	/* Nexus not established */
    171 
    172 /*
    173  * Values for the in_task_flags field- should only get one at a time!
    174  */
    175 #define	TASK_FLAGS_ABORT_TASK		(1<<9)
    176 #define	TASK_FLAGS_CLEAR_TASK_SET	(1<<10)
    177 #define	TASK_FLAGS_TARGET_RESET		(1<<13)
    178 #define	TASK_FLAGS_CLEAR_ACA		(1<<14)
    179 #define	TASK_FLAGS_TERMINATE_TASK	(1<<15)
    180 
    181 #ifndef	MSG_ABORT_TAG
    182 #define	MSG_ABORT_TAG		0x06
    183 #endif
    184 #ifndef	MSG_CLEAR_QUEUE
    185 #define	MSG_CLEAR_QUEUE		0x0e
    186 #endif
    187 #ifndef	MSG_BUS_DEV_RESET
    188 #define	MSG_BUS_DEV_RESET	0x0b
    189 #endif
    190 #ifndef	MSG_REL_RECOVERY
    191 #define	MSG_REL_RECOVERY	0x10
    192 #endif
    193 #ifndef	MSG_TERM_IO_PROC
    194 #define	MSG_TERM_IO_PROC	0x11
    195 #endif
    196 
    197 
    198 /*
    199  * Notify Acknowledge Entry structure
    200  */
    201 #define NA_RSVDLEN	22
    202 typedef struct {
    203 	isphdr_t	na_header;
    204 	u_int32_t	na_reserved;
    205 	u_int8_t	na_lun;		/* lun */
    206 	u_int8_t	na_iid;		/* initiator */
    207 	u_int8_t	na_reserved2;
    208 	u_int8_t	na_tgt;		/* target */
    209 	u_int32_t	na_flags;
    210 	u_int8_t	na_status;
    211 	u_int8_t	na_event;
    212 	u_int16_t	na_seqid;	/* sequence id */
    213 	u_int16_t	na_reserved3[NA_RSVDLEN];
    214 } na_entry_t;
    215 
    216 /*
    217  * Value for the na_event field
    218  */
    219 #define NA_RST_CLRD	0x80	/* Clear an async event notification */
    220 #define	NA_OK		0x01	/* Notify Acknowledge Succeeded */
    221 #define	NA_INVALID	0x06	/* Invalid Notify Acknowledge */
    222 
    223 #define	NA2_RSVDLEN	21
    224 typedef struct {
    225 	isphdr_t	na_header;
    226 	u_int32_t	na_reserved;
    227 	u_int8_t	na_lun;		/* lun */
    228 	u_int8_t	na_iid;		/* initiator */
    229 	u_int16_t	na_scclun;
    230 	u_int16_t	na_flags;
    231 	u_int16_t	na_reserved2;
    232 	u_int16_t	na_status;
    233 	u_int16_t	na_task_flags;
    234 	u_int16_t	na_seqid;	/* sequence id */
    235 	u_int16_t	na_reserved3[NA2_RSVDLEN];
    236 } na_fcentry_t;
    237 #define	NAFC_RCOUNT	0x80	/* increment resource count */
    238 #define NAFC_RST_CLRD	0x20	/* Clear LIP Reset */
    239 /*
    240  * Accept Target I/O Entry structure
    241  */
    242 #define ATIO_CDBLEN	26
    243 
    244 typedef struct {
    245 	isphdr_t	at_header;
    246 	u_int32_t	at_reserved;
    247 	u_int8_t	at_lun;		/* lun */
    248 	u_int8_t	at_iid;		/* initiator */
    249 	u_int8_t	at_cdblen; 	/* cdb length */
    250 	u_int8_t	at_tgt;		/* target */
    251 	u_int32_t	at_flags;
    252 	u_int8_t	at_status;	/* firmware status */
    253 	u_int8_t	at_scsi_status;	/* scsi status */
    254 	u_int8_t	at_tag_val;	/* tag value */
    255 	u_int8_t	at_tag_type;	/* tag type */
    256 	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
    257 	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
    258 } at_entry_t;
    259 
    260 /*
    261  * at_flags values
    262  */
    263 #define AT_NODISC	0x00008000	/* disconnect disabled */
    264 #define AT_TQAE		0x00000001	/* Tagged Queue Action enabled */
    265 
    266 /*
    267  * at_status values
    268  */
    269 #define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
    270 #define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
    271 #define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
    272 #define AT_NOCAP	0x16	/* Requested capability not available */
    273 #define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
    274 #define AT_CDB		0x3D	/* CDB received */
    275 
    276 /*
    277  * Accept Target I/O Entry structure, Type 2
    278  */
    279 #define ATIO2_CDBLEN	16
    280 
    281 typedef struct {
    282 	isphdr_t	at_header;
    283 	u_int32_t	at_reserved;
    284 	u_int8_t	at_lun;		/* lun or reserved */
    285 	u_int8_t	at_iid;		/* initiator */
    286 	u_int16_t	at_rxid; 	/* response ID */
    287 	u_int16_t	at_flags;
    288 	u_int16_t	at_status;	/* firmware status */
    289 	u_int8_t	at_reserved1;
    290 	u_int8_t	at_taskcodes;
    291 	u_int8_t	at_taskflags;
    292 	u_int8_t	at_execodes;
    293 	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
    294 	u_int32_t	at_datalen;		/* allocated data len */
    295 	u_int16_t	at_scclun;	/* SCC Lun or reserved */
    296 	u_int16_t	at_reserved2;
    297 	u_int16_t	at_scsi_status;
    298 	u_int8_t	at_sense[QLTM_SENSELEN];
    299 } at2_entry_t;
    300 
    301 #define	ATIO2_WWPN_OFFSET	0x2A
    302 #define	ATIO2_OXID_OFFSET	0x3E
    303 
    304 #define	ATIO2_TC_ATTR_MASK	0x7
    305 #define	ATIO2_TC_ATTR_SIMPLEQ	0
    306 #define	ATIO2_TC_ATTR_HEADOFQ	1
    307 #define	ATIO2_TC_ATTR_ORDERED	2
    308 #define	ATIO2_TC_ATTR_ACAQ	4
    309 #define	ATIO2_TC_ATTR_UNTAGGED	5
    310 
    311 /*
    312  * Continue Target I/O Entry structure
    313  * Request from driver. The response from the
    314  * ISP firmware is the same except that the last 18
    315  * bytes are overwritten by suggested sense data if
    316  * the 'autosense valid' bit is set in the status byte.
    317  */
    318 typedef struct {
    319 	isphdr_t	ct_header;
    320 	u_int32_t	ct_reserved;
    321 	u_int8_t	ct_lun;	/* lun */
    322 	u_int8_t	ct_iid;	/* initiator id */
    323 	u_int8_t	ct_reserved2;
    324 	u_int8_t	ct_tgt;	/* our target id */
    325 	u_int32_t	ct_flags;
    326 	u_int8_t 	ct_status;	/* isp status */
    327 	u_int8_t 	ct_scsi_status;	/* scsi status */
    328 	u_int8_t 	ct_tag_val;	/* tag value */
    329 	u_int8_t 	ct_tag_type;	/* tag type */
    330 	u_int32_t	ct_xfrlen;	/* transfer length */
    331 	u_int32_t	ct_resid;	/* residual length */
    332 	u_int16_t	ct_timeout;
    333 	u_int16_t	ct_seg_count;
    334 	ispds_t		ct_dataseg[ISP_RQDSEG];
    335 } ct_entry_t;
    336 
    337 /*
    338  * For some of the dual port SCSI adapters, port (bus #) is reported
    339  * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
    340  *
    341  * Note that this does not apply to FC adapters at all which can and
    342  * do report IIDs between 129 && 255 (these represent devices that have
    343  * logged in across a SCSI fabric).
    344  */
    345 #define	GET_IID_VAL(x)		(x & 0x3f)
    346 #define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
    347 #define	SET_IID_VAL(y, x)	(y | (x & 0x3f))
    348 #define	SET_BUS_VAL(y, x)	(y | ((x & 0x1) << 7))
    349 
    350 /*
    351  * ct_flags values
    352  */
    353 #define CT_TQAE		0x00000001	/* bit  1, Tagged Queue Action enable */
    354 #define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
    355 #define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
    356 #define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
    357 #define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
    358 #define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
    359 #define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
    360 #define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
    361 #define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
    362 #define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
    363 #define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
    364 
    365 /*
    366  * ct_status values
    367  * - set by the firmware when it returns the CTIO
    368  */
    369 #define CT_OK		0x01	/* completed without error */
    370 #define CT_ABORTED	0x02	/* aborted by host */
    371 #define CT_ERR		0x04	/* see sense data for error */
    372 #define CT_INVAL	0x06	/* request for disabled lun */
    373 #define CT_NOPATH	0x07	/* invalid ITL nexus */
    374 #define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
    375 #define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
    376 #define CT_TIMEOUT	0x0B	/* timed out */
    377 #define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
    378 #define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
    379 #define	CT_PANIC	0x13	/* Unrecoverable Error */
    380 #define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
    381 #define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
    382 #define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
    383 #define	CT_PORTNOTAVAIL	0x28	/* port not available */
    384 #define	CT_LOGOUT	0x29	/* port logout */
    385 #define	CT_PORTCHANGED	0x2A	/* port changed */
    386 #define	CT_IDE		0x33	/* Initiator Detected Error */
    387 #define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
    388 
    389 /*
    390  * When the firmware returns a CTIO entry, it may overwrite the last
    391  * part of the structure with sense data. This starts at offset 0x2E
    392  * into the entry, which is in the middle of ct_dataseg[1]. Rather
    393  * than define a new struct for this, I'm just using the sense data
    394  * offset.
    395  */
    396 #define CTIO_SENSE_OFFSET	0x2E
    397 
    398 /*
    399  * Entry length in u_longs. All entries are the same size so
    400  * any one will do as the numerator.
    401  */
    402 #define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
    403 
    404 /*
    405  * QLA2100 CTIO (type 2) entry
    406  */
    407 #define	MAXRESPLEN	26
    408 typedef struct {
    409 	isphdr_t	ct_header;
    410 	u_int32_t	ct_reserved;
    411 	u_int8_t	ct_lun;	/* lun */
    412 	u_int8_t	ct_iid;	/* initiator id */
    413 	u_int16_t	ct_rxid; /* response ID */
    414 	u_int16_t	ct_flags;
    415 	u_int16_t 	ct_status;	/* isp status */
    416 	u_int16_t	ct_timeout;
    417 	u_int16_t	ct_seg_count;
    418 	u_int32_t	ct_reloff;	/* relative offset */
    419 	int32_t		ct_resid;	/* residual length */
    420 	union {
    421 		/*
    422 		 * The three different modes that the target driver
    423 		 * can set the CTIO2 up as.
    424 		 *
    425 		 * The first is for sending FCP_DATA_IUs as well as
    426 		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
    427 		 *
    428 		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
    429 		 * Note that no FCP_DATA_IUs will be sent.
    430 		 *
    431 		 * The third is for sending FCP_RSP_IUs as built specifically
    432 		 * in system memory as located by the isp_dataseg.
    433 		 */
    434 		struct {
    435 			u_int32_t _reserved;
    436 			u_int16_t _reserved2;
    437 			u_int16_t ct_scsi_status;
    438 			u_int32_t ct_xfrlen;
    439 			ispds_t ct_dataseg[ISP_RQDSEG_T2];
    440 		} m0;
    441 		struct {
    442 			u_int16_t _reserved;
    443 			u_int16_t _reserved2;
    444 			u_int16_t ct_senselen;
    445 			u_int16_t ct_scsi_status;
    446 			u_int16_t ct_resplen;
    447 			u_int8_t  ct_resp[MAXRESPLEN];
    448 		} m1;
    449 		struct {
    450 			u_int32_t _reserved;
    451 			u_int16_t _reserved2;
    452 			u_int16_t _reserved3;
    453 			u_int32_t ct_datalen;
    454 			ispds_t ct_fcp_rsp_iudata;
    455 		} m2;
    456 		/*
    457 		 * CTIO2 returned from F/W...
    458 		 */
    459 		struct {
    460 			u_int32_t _reserved[4];
    461 			u_int16_t ct_scsi_status;
    462 			u_int8_t  ct_sense[QLTM_SENSELEN];
    463 		} fw;
    464 	} rsp;
    465 } ct2_entry_t;
    466 
    467 /*
    468  * ct_flags values for CTIO2
    469  */
    470 #define	CT2_FLAG_MMASK	0x0003
    471 #define	CT2_FLAG_MODE0	0x0000
    472 #define	CT2_FLAG_MODE1	0x0001
    473 #define	CT2_FLAG_MODE2	0x0002
    474 #define CT2_DATA_IN	CT_DATA_IN
    475 #define CT2_DATA_OUT	CT_DATA_OUT
    476 #define CT2_NO_DATA	CT_NO_DATA
    477 #define CT2_DATAMASK	CT_DATAMASK
    478 #define	CT2_CCINCR	0x0100
    479 #define	CT2_FASTPOST	0x0200
    480 #define CT2_SENDSTATUS	0x8000
    481 
    482 /*
    483  * ct_status values are (mostly) the same as that for ct_entry.
    484  */
    485 
    486 /*
    487  * ct_scsi_status values- the low 8 bits are the normal SCSI status
    488  * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
    489  * fields.
    490  */
    491 #define	CT2_RSPLEN_VALID	0x0100
    492 #define	CT2_SNSLEN_VALID	0x0200
    493 #define	CT2_DATA_OVER		0x0400
    494 #define	CT2_DATA_UNDER		0x0800
    495 
    496 /*
    497  * Macros for packing/unpacking the above structures
    498  */
    499 
    500 #ifdef	__sparc__
    501 #define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
    502 	if (isp->isp_bus == ISP_SBUS) {	\
    503 		source -> taga =  dest -> tagb;	\
    504 		source -> tagb =  dest -> taga;	\
    505 	} else { \
    506 		source -> taga =  dest -> taga;	\
    507 		source -> tagb =  dest -> taga;	\
    508 	}
    509 #else
    510 #define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
    511 		source -> taga =  dest -> taga;	\
    512 		source -> tagb =  dest -> taga;
    513 #endif
    514 
    515 #define	MCIDF(d, s)	if ((void *) d != (void *)s) MEMCPY(d, s, QENTRY_LEN)
    516 
    517 /* This is really only for SBus cards on a sparc */
    518 #ifdef	__sparc__
    519 #define	ISP_SWIZ_ATIO(isp, dest, vsrc)					\
    520 {									\
    521 	at_entry_t *source = (at_entry_t *) vsrc;			\
    522 	at_entry_t local, *vdst;					\
    523 	if ((void *)dest == (void *)vsrc) {				\
    524 		MEMCPY(vsrc, &local, sizeof (at_entry_t));		\
    525 		vdst = &local;						\
    526 	} else {							\
    527 		vdst = dest;						\
    528 	}								\
    529 	vdst->at_header = source->at_header;				\
    530 	vdst->at_reserved2 = source->at_reserved2;			\
    531 	ISP_SBUS_SWOZZLE(isp, source, vdst, at_lun, at_iid);		\
    532 	ISP_SBUS_SWOZZLE(isp, source, vdst, at_cdblen, at_tgt);		\
    533 	vdst->at_flags = source->at_flags;				\
    534 	ISP_SBUS_SWOZZLE(isp, source, vdst, at_status, at_scsi_status);	\
    535 	ISP_SBUS_SWOZZLE(isp, source, vdst, at_tag_val, at_tag_type);	\
    536 	MEMCPY(vdst->at_cdb, source->at_cdb, ATIO_CDBLEN);		\
    537 	MEMCPY(vdst->at_sense, source->at_sense, QLTM_SENSELEN);	\
    538 }
    539 
    540 #define	ISP_SWIZ_CTIO(isp, dest, vsrc)					\
    541 {									\
    542 	ct_entry_t *source = (ct_entry_t *) vsrc;			\
    543 	ct_entry_t *local, *vdst;					\
    544 	if ((void *)dest == (void *)vsrc) {				\
    545 		MEMCPY(vsrc, &local, sizeof (ct_entry_t));		\
    546 		vdst = &local;						\
    547 	} else {							\
    548 		vdst = dest;						\
    549 	}								\
    550 	vdst->ct_header = source->ct_header;				\
    551 	vdst->ct_reserved = source->ct_reserved;			\
    552 	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_lun, ct_iid);		\
    553 	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_rsvd, ct_tgt);		\
    554 	vdst->ct_flags = source->ct_flags;				\
    555 	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_status, ct_scsi_status);	\
    556 	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_tag_val, ct_tag_type);	\
    557 	vdst->ct_xfrlen = source->ct_xfrlen;				\
    558 	vdst->ct_resid = source->ct_resid;				\
    559 	vdst->ct_timeout = source->ct_timeout;				\
    560 	vdst->ct_seg_count = source->ct_seg_count;			\
    561 	MEMCPY(vdst->ct_cdb, source->ct_cdb, ATIO_CDBLEN);		\
    562 	MEMCPY(vdst->ct_sense, source->ct_sense, QLTM_SENSELEN);	\
    563 	vdst->ct_dataseg = source->ct_dataseg;				\
    564 }
    565 #define	ISP_SWIZ_ENABLE_LUN(isp, dest, vsrc)				\
    566 {									\
    567 	lun_entry_t *source = (lun_entry_t *)vsrc;			\
    568 	lun_entry_t *local, *vdst;					\
    569 	if ((void *)dest == (void *)vsrc) {				\
    570 		MEMCPY(vsrc, &local, sizeof (lun_entry_t));		\
    571 		vdst = &local;						\
    572 	} else {							\
    573 		vdst = dest;						\
    574 	}								\
    575 	vdst->le_header = source->le_header;				\
    576 	vdst->le_reserved2 = source->le_reserved2;			\
    577 	ISP_SBUS_SWOZZLE(isp, source, vdst, le_lun, le_rsvd);		\
    578 	ISP_SBUS_SWOZZLE(isp, source, vdst, le_ops, le_tgt);		\
    579 	vdst->le_flags = source->le_flags;				\
    580 	ISP_SBUS_SWOZZLE(isp, source, vdst, le_status, le_rsvd2);	\
    581 	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cmd_count, le_in_count);	\
    582 	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cdb6len, le_cdb7len);	\
    583 	vdst->le_timeout = source->le_timeout;				\
    584 	vdst->le_reserved = source->le_reserved;			\
    585 }
    586 #define	ISP_SWIZ_NOTIFY(isp, dest, vsrc)				\
    587 {									\
    588 	in_entry_type *source = (in_entry_t *)vsrc;			\
    589 	in_entry_t *local, *vdst;					\
    590 	if ((void *)dest == (void *)vsrc) {				\
    591 		MEMCPY(vsrc, &local, sizeof (in_entry_t));		\
    592 		vdst = &local;						\
    593 	} else {							\
    594 		vdst = dest;						\
    595 	}								\
    596 	vdst->in_header = source->in_header;				\
    597 	vdst->in_reserved2 = source->in_reserved2;			\
    598 	ISP_SBUS_SWOZZLE(isp, source, vdst, in_lun, in_iid);		\
    599 	ISP_SBUS_SWOZZLE(isp, source, vdst, in_rsvd, in_tgt);		\
    600 	vdst->in_flags = source->in_flags;				\
    601 	ISP_SBUS_SWOZZLE(isp, source, vdst, in_status, in_rsvd2);	\
    602 	ISP_SBUS_SWOZZLE(isp, source, vdst, in_tag_val, in_tag_type);	\
    603 	vdst->in_seqid = source->in_seqid;				\
    604 	MEMCPY(vdst->in_msg, source->in_msg, IN_MSGLEN);		\
    605 	MEMCPY(vdst->in_reserved, source->in_reserved, IN_RESERVED);	\
    606 	MEMCPY(vdst->in_sense, source->in_sense, QLTM_SENSELEN);	\
    607 }
    608 #define	ISP_SWIZ_NOT_ACK(isp, dest)					\
    609 {									\
    610 	na_entry_t *source = (na_entry_t *)vsrc;			\
    611 	na_entry_t *local, *vdst;					\
    612 	if ((void *)dest == (void *)vsrc) {				\
    613 		MEMCPY(vsrc, &local, sizeof (na_entry_t));		\
    614 		vdst = &local;						\
    615 	} else {							\
    616 		vdst = dest;						\
    617 	}								\
    618 	vdst->na_header = source->na_header;				\
    619 	vdst->na_reserved2 = source->na_reserved2;			\
    620 	ISP_SBUS_SWOZZLE(isp, source, vdst, na_lun, na_iid);		\
    621 	ISP_SBUS_SWOZZLE(isp, source, vdst, na_rsvd, na_tgt);		\
    622 	vdst->na_flags = source->na_flags;				\
    623 	ISP_SBUS_SWOZZLE(isp, source, vdst, na_status, na_event);	\
    624 	vdst->na_seqid = source->na_seqid;				\
    625 	MEMCPY(vdst->na_reserved, source->na_reserved, NA_RSVDLEN);	\
    626 }
    627 #define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
    628 #define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
    629 #define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
    630 #else
    631 #define	ISP_SWIZ_ATIO(isp, d, s)	MCIDF(d, s)
    632 #define	ISP_SWIZ_CTIO(isp, d, s)	MCIDF(d, s)
    633 #define	ISP_SWIZ_ENABLE_LUN(isp, d, s)	MCIDF(d, s)
    634 #define	ISP_SWIZ_NOTIFY(isp, d, s)	MCIDF(d, s)
    635 #define	ISP_SWIZ_NOT_ACK(isp, d, s)	MCIDF(d, s)
    636 #define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
    637 #define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
    638 #define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
    639 #endif
    640 
    641 /*
    642  * Debug macros
    643  */
    644 
    645 #define	ISP_TDQE(isp, msg, idx, arg)	\
    646     if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
    647 
    648 /*
    649  * The functions below are target mode functions that
    650  * are generally internal to the Qlogic driver.
    651  */
    652 
    653 /*
    654  * This function handles new response queue entry appropriate for target mode.
    655  */
    656 int isp_target_notify __P((struct ispsoftc *, void *, u_int16_t *));
    657 
    658 /*
    659  * Enable/Disable/Modify a logical unit.
    660  */
    661 #define	DFLT_CMD_CNT	32	/* XX */
    662 #define	DFLT_INOTIFY	(4)
    663 int isp_lun_cmd __P((struct ispsoftc *, int, int, int, int, u_int32_t));
    664 
    665 /*
    666  * General request queue 'put' routine for target mode entries.
    667  */
    668 int isp_target_put_entry __P((struct ispsoftc *isp, void *));
    669 
    670 /*
    671  * General routine to put back an ATIO entry-
    672  * used for replenishing f/w resource counts.
    673  */
    674 int
    675 isp_target_put_atio __P((struct ispsoftc *, int, int, int, int, int));
    676 
    677 /*
    678  * General routine to send a final CTIO for a command- used mostly for
    679  * local responses.
    680  */
    681 int
    682 isp_endcmd __P((struct ispsoftc *, void *, u_int32_t, u_int32_t));
    683 #define	ECMD_SVALID	0x100
    684 
    685 /*
    686  * Handle an asynchronous event
    687  */
    688 
    689 void isp_target_async __P((struct ispsoftc *, int, int));
    690 
    691 #endif	/* _ISPTARGET_H */
    692