xref: /freebsd/sys/dev/isp/isp_target.h (revision 0615a5479815484e754c9ba26aab7f42f2b3bf15)
10615a547SMatt Jacob /* $FreeBSD$ */
20615a547SMatt Jacob /*
30615a547SMatt Jacob  * Qlogic Target Mode Structure and Flag Definitions
40615a547SMatt Jacob  *
50615a547SMatt Jacob  * Copyright (c) 1997, 1998
60615a547SMatt Jacob  * Patrick Stirling
70615a547SMatt Jacob  * pms@psconsult.com
80615a547SMatt Jacob  * All rights reserved.
90615a547SMatt Jacob  *
100615a547SMatt Jacob  * Additional Copyright (c) 1999
110615a547SMatt Jacob  * Matthew Jacob
120615a547SMatt Jacob  * mjacob@feral.com
130615a547SMatt Jacob  * All rights reserved.
140615a547SMatt Jacob  *
150615a547SMatt Jacob  *
160615a547SMatt Jacob  * Redistribution and use in source and binary forms, with or without
170615a547SMatt Jacob  * modification, are permitted provided that the following conditions
180615a547SMatt Jacob  * are met:
190615a547SMatt Jacob  * 1. Redistributions of source code must retain the above copyright
200615a547SMatt Jacob  *    notice immediately at the beginning of the file, without modification,
210615a547SMatt Jacob  *    this list of conditions, and the following disclaimer.
220615a547SMatt Jacob  * 2. Redistributions in binary form must reproduce the above copyright
230615a547SMatt Jacob  *    notice, this list of conditions and the following disclaimer in the
240615a547SMatt Jacob  *    documentation and/or other materials provided with the distribution.
250615a547SMatt Jacob  * 3. The name of the author may not be used to endorse or promote products
260615a547SMatt Jacob  *    derived from this software without specific prior written permission.
270615a547SMatt Jacob  *
280615a547SMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
290615a547SMatt Jacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
300615a547SMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
310615a547SMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
320615a547SMatt Jacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
330615a547SMatt Jacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
340615a547SMatt Jacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
350615a547SMatt Jacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
360615a547SMatt Jacob  * SUCH DAMAGE.
370615a547SMatt Jacob  *
380615a547SMatt Jacob  */
390615a547SMatt Jacob #ifndef	_ISPTARGET_H
400615a547SMatt Jacob #define	_ISPTARGET_H
410615a547SMatt Jacob 
420615a547SMatt Jacob /*
430615a547SMatt Jacob  * Defines for all entry types
440615a547SMatt Jacob  */
450615a547SMatt Jacob #define QLTM_SVALID	0x80
460615a547SMatt Jacob #define	QLTM_SENSELEN	18
470615a547SMatt Jacob 
480615a547SMatt Jacob /*
490615a547SMatt Jacob  * Structure for Enable Lun and Modify Lun queue entries
500615a547SMatt Jacob  */
510615a547SMatt Jacob typedef struct {
520615a547SMatt Jacob 	isphdr_t	le_header;
530615a547SMatt Jacob 	u_int32_t	le_reserved;
540615a547SMatt Jacob 	u_int8_t	le_lun;
550615a547SMatt Jacob 	u_int8_t	le_rsvd;
560615a547SMatt Jacob 	u_int8_t	le_ops;		/* Modify LUN only */
570615a547SMatt Jacob 	u_int8_t	le_tgt;		/* Not for FC */
580615a547SMatt Jacob 	u_int32_t	le_flags;	/* Not for FC */
590615a547SMatt Jacob 	u_int8_t	le_status;
600615a547SMatt Jacob 	u_int8_t	le_reserved2;
610615a547SMatt Jacob 	u_int8_t	le_cmd_count;
620615a547SMatt Jacob 	u_int8_t	le_in_count;
630615a547SMatt Jacob 	u_int8_t	le_cdb6len;	/* Not for FC */
640615a547SMatt Jacob 	u_int8_t	le_cdb7len;	/* Not for FC */
650615a547SMatt Jacob 	u_int16_t	le_timeout;
660615a547SMatt Jacob 	u_int16_t	le_reserved3[20];
670615a547SMatt Jacob } lun_entry_t;
680615a547SMatt Jacob 
690615a547SMatt Jacob /*
700615a547SMatt Jacob  * le_flags values
710615a547SMatt Jacob  */
720615a547SMatt Jacob #define LUN_TQAE	0x00000001	/* bit1  Tagged Queue Action Enable */
730615a547SMatt Jacob #define LUN_DSSM	0x01000000	/* bit24 Disable Sending SDP Message */
740615a547SMatt Jacob #define LUN_DM		0x40000000	/* bit30 Disconnects Mandatory */
750615a547SMatt Jacob 
760615a547SMatt Jacob /*
770615a547SMatt Jacob  * le_ops values
780615a547SMatt Jacob  */
790615a547SMatt Jacob #define LUN_CCINCR	0x01	/* increment command count */
800615a547SMatt Jacob #define LUN_CCDECR	0x02	/* decrement command count */
810615a547SMatt Jacob #define LUN_ININCR	0x40	/* increment immed. notify count */
820615a547SMatt Jacob #define LUN_INDECR	0x80	/* decrement immed. notify count */
830615a547SMatt Jacob 
840615a547SMatt Jacob /*
850615a547SMatt Jacob  * le_status values
860615a547SMatt Jacob  */
870615a547SMatt Jacob #define	LUN_OK		0x01	/* we be rockin' */
880615a547SMatt Jacob #define LUN_ERR		0x04	/* request completed with error */
890615a547SMatt Jacob #define LUN_INVAL	0x06	/* invalid request */
900615a547SMatt Jacob #define LUN_NOCAP	0x16	/* can't provide requested capability */
910615a547SMatt Jacob #define LUN_ENABLED	0x3E	/* LUN already enabled */
920615a547SMatt Jacob 
930615a547SMatt Jacob /*
940615a547SMatt Jacob  * Immediate Notify Entry structure
950615a547SMatt Jacob  */
960615a547SMatt Jacob #define IN_MSGLEN	8	/* 8 bytes */
970615a547SMatt Jacob #define IN_RSVDLEN	8	/* 8 words */
980615a547SMatt Jacob typedef struct {
990615a547SMatt Jacob 	isphdr_t	in_header;
1000615a547SMatt Jacob 	u_int32_t	in_reserved;
1010615a547SMatt Jacob 	u_int8_t	in_lun;		/* lun */
1020615a547SMatt Jacob 	u_int8_t	in_iid;		/* initiator */
1030615a547SMatt Jacob 	u_int8_t	in_reserved2;
1040615a547SMatt Jacob 	u_int8_t	in_tgt;		/* target */
1050615a547SMatt Jacob 	u_int32_t	in_flags;
1060615a547SMatt Jacob 	u_int8_t	in_status;
1070615a547SMatt Jacob 	u_int8_t	in_rsvd2;
1080615a547SMatt Jacob 	u_int8_t	in_tag_val;	/* tag value */
1090615a547SMatt Jacob 	u_int8_t	in_tag_type;	/* tag type */
1100615a547SMatt Jacob 	u_int16_t	in_seqid;	/* sequence id */
1110615a547SMatt Jacob 	u_int8_t	in_msg[IN_MSGLEN];	/* SCSI message bytes */
1120615a547SMatt Jacob 	u_int16_t	in_reserved3[IN_RSVDLEN];
1130615a547SMatt Jacob 	u_int8_t	in_sense[QLTM_SENSELEN];/* suggested sense data */
1140615a547SMatt Jacob } in_entry_t;
1150615a547SMatt Jacob 
1160615a547SMatt Jacob typedef struct {
1170615a547SMatt Jacob 	isphdr_t	in_header;
1180615a547SMatt Jacob 	u_int32_t	in_reserved;
1190615a547SMatt Jacob 	u_int8_t	in_lun;		/* lun */
1200615a547SMatt Jacob 	u_int8_t	in_iid;		/* initiator */
1210615a547SMatt Jacob 	u_int16_t	in_scclun;
1220615a547SMatt Jacob 	u_int32_t	in_reserved2;
1230615a547SMatt Jacob 	u_int16_t	in_status;
1240615a547SMatt Jacob 	u_int16_t	in_task_flags;
1250615a547SMatt Jacob 	u_int16_t	in_seqid;	/* sequence id */
1260615a547SMatt Jacob } in_fcentry_t;
1270615a547SMatt Jacob 
1280615a547SMatt Jacob /*
1290615a547SMatt Jacob  * Values for the in_status field
1300615a547SMatt Jacob  */
1310615a547SMatt Jacob #define IN_RESET	0x0E	/* Bus Reset occurred */
1320615a547SMatt Jacob #define IN_NO_RCAP	0x16	/* requested capability not available */
1330615a547SMatt Jacob #define IN_IDE_RECEIVED	0x33	/* Initiator Detected Error msg received */
1340615a547SMatt Jacob #define IN_RSRC_UNAVAIL	0x34	/* resource unavailable */
1350615a547SMatt Jacob #define IN_MSG_RECEIVED	0x36	/* SCSI message received */
1360615a547SMatt Jacob #define	IN_ABORT_TASK	0x20	/* task named in RX_ID is being aborted (FC) */
1370615a547SMatt Jacob #define	IN_PORT_LOGOUT	0x29	/* port has logged out (FC) */
1380615a547SMatt Jacob #define	IN_PORT_CHANGED	0x2A	/* port changed */
1390615a547SMatt Jacob #define	IN_GLOBAL_LOGO	0x2E	/* all ports logged out */
1400615a547SMatt Jacob 
1410615a547SMatt Jacob /*
1420615a547SMatt Jacob  * Values for the in_task_flags field- should only get one at a time!
1430615a547SMatt Jacob  */
1440615a547SMatt Jacob #define	TASK_FLAGS_ABORT_TASK		(1<<9)
1450615a547SMatt Jacob #define	TASK_FLAGS_CLEAR_TASK_SET	(1<<10)
1460615a547SMatt Jacob #define	TASK_FLAGS_TARGET_RESET		(1<<13)
1470615a547SMatt Jacob #define	TASK_FLAGS_CLEAR_ACA		(1<<14)
1480615a547SMatt Jacob #define	TASK_FLAGS_TERMINATE_TASK	(1<<15)
1490615a547SMatt Jacob 
1500615a547SMatt Jacob #ifndef	MSG_ABORT_TAG
1510615a547SMatt Jacob #define	MSG_ABORT_TAG		0x06
1520615a547SMatt Jacob #endif
1530615a547SMatt Jacob #ifndef	MSG_CLEAR_QUEUE
1540615a547SMatt Jacob #define	MSG_CLEAR_QUEUE		0x0e
1550615a547SMatt Jacob #endif
1560615a547SMatt Jacob #ifndef	MSG_BUS_DEV_RESET
1570615a547SMatt Jacob #define	MSG_BUS_DEV_RESET	0x0b
1580615a547SMatt Jacob #endif
1590615a547SMatt Jacob #ifndef	MSG_REL_RECOVERY
1600615a547SMatt Jacob #define	MSG_REL_RECOVERY	0x10
1610615a547SMatt Jacob #endif
1620615a547SMatt Jacob #ifndef	MSG_TERM_IO_PROC
1630615a547SMatt Jacob #define	MSG_TERM_IO_PROC	0x11
1640615a547SMatt Jacob #endif
1650615a547SMatt Jacob 
1660615a547SMatt Jacob 
1670615a547SMatt Jacob /*
1680615a547SMatt Jacob  * Notify Acknowledge Entry structure
1690615a547SMatt Jacob  */
1700615a547SMatt Jacob #define NA_RSVDLEN	22
1710615a547SMatt Jacob typedef struct {
1720615a547SMatt Jacob 	isphdr_t	na_header;
1730615a547SMatt Jacob 	u_int32_t	na_reserved;
1740615a547SMatt Jacob 	u_int8_t	na_lun;		/* lun */
1750615a547SMatt Jacob 	u_int8_t	na_iid;		/* initiator */
1760615a547SMatt Jacob 	u_int8_t	na_reserved2;
1770615a547SMatt Jacob 	u_int8_t	na_tgt;		/* target */
1780615a547SMatt Jacob 	u_int32_t	na_flags;
1790615a547SMatt Jacob 	u_int8_t	na_status;
1800615a547SMatt Jacob 	u_int8_t	na_event;
1810615a547SMatt Jacob 	u_int16_t	na_seqid;	/* sequence id */
1820615a547SMatt Jacob 	u_int16_t	na_reserved3[NA_RSVDLEN];
1830615a547SMatt Jacob } na_entry_t;
1840615a547SMatt Jacob 
1850615a547SMatt Jacob /*
1860615a547SMatt Jacob  * Value for the na_event field
1870615a547SMatt Jacob  */
1880615a547SMatt Jacob #define NA_RST_CLRD	0x80	/* Clear an async event notification */
1890615a547SMatt Jacob 
1900615a547SMatt Jacob #define	NA2_RSVDLEN	21
1910615a547SMatt Jacob typedef struct {
1920615a547SMatt Jacob 	isphdr_t	na_header;
1930615a547SMatt Jacob 	u_int32_t	na_reserved;
1940615a547SMatt Jacob 	u_int8_t	na_lun;		/* lun */
1950615a547SMatt Jacob 	u_int8_t	na_iid;		/* initiator */
1960615a547SMatt Jacob 	u_int16_t	na_scclun;
1970615a547SMatt Jacob 	u_int16_t	na_flags;
1980615a547SMatt Jacob 	u_int16_t	na_reserved2;
1990615a547SMatt Jacob 	u_int16_t	na_status;
2000615a547SMatt Jacob 	u_int16_t	na_task_flags;
2010615a547SMatt Jacob 	u_int16_t	na_seqid;	/* sequence id */
2020615a547SMatt Jacob 	u_int16_t	na_reserved3[NA2_RSVDLEN];
2030615a547SMatt Jacob } na_fcentry_t;
2040615a547SMatt Jacob #define	NAFC_RCOUNT	0x80	/* increment resource count */
2050615a547SMatt Jacob #define NAFC_RST_CLRD	0x20	/* Clear LIP Reset */
2060615a547SMatt Jacob /*
2070615a547SMatt Jacob  * Accept Target I/O Entry structure
2080615a547SMatt Jacob  */
2090615a547SMatt Jacob #define ATIO_CDBLEN	26
2100615a547SMatt Jacob 
2110615a547SMatt Jacob typedef struct {
2120615a547SMatt Jacob 	isphdr_t	at_header;
2130615a547SMatt Jacob 	u_int32_t	at_reserved;
2140615a547SMatt Jacob 	u_int8_t	at_lun;		/* lun */
2150615a547SMatt Jacob 	u_int8_t	at_iid;		/* initiator */
2160615a547SMatt Jacob 	u_int8_t	at_cdblen; 	/* cdb length */
2170615a547SMatt Jacob 	u_int8_t	at_tgt;		/* target */
2180615a547SMatt Jacob 	u_int32_t	at_flags;
2190615a547SMatt Jacob 	u_int8_t	at_status;	/* firmware status */
2200615a547SMatt Jacob 	u_int8_t	at_scsi_status;	/* scsi status */
2210615a547SMatt Jacob 	u_int8_t	at_tag_val;	/* tag value */
2220615a547SMatt Jacob 	u_int8_t	at_tag_type;	/* tag type */
2230615a547SMatt Jacob 	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
2240615a547SMatt Jacob 	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
2250615a547SMatt Jacob } at_entry_t;
2260615a547SMatt Jacob 
2270615a547SMatt Jacob /*
2280615a547SMatt Jacob  * at_flags values
2290615a547SMatt Jacob  */
2300615a547SMatt Jacob #define AT_NODISC	0x00008000	/* disconnect disabled */
2310615a547SMatt Jacob #define AT_TQAE		0x00000001	/* Tagged Queue Action enabled */
2320615a547SMatt Jacob 
2330615a547SMatt Jacob /*
2340615a547SMatt Jacob  * at_status values
2350615a547SMatt Jacob  */
2360615a547SMatt Jacob #define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
2370615a547SMatt Jacob #define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
2380615a547SMatt Jacob #define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
2390615a547SMatt Jacob #define AT_NOCAP	0x16	/* Requested capability not available */
2400615a547SMatt Jacob #define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
2410615a547SMatt Jacob #define AT_CDB		0x3D	/* CDB received */
2420615a547SMatt Jacob 
2430615a547SMatt Jacob /*
2440615a547SMatt Jacob  * Accept Target I/O Entry structure, Type 2
2450615a547SMatt Jacob  */
2460615a547SMatt Jacob #define ATIO2_CDBLEN	16
2470615a547SMatt Jacob 
2480615a547SMatt Jacob typedef struct {
2490615a547SMatt Jacob 	isphdr_t	at_header;
2500615a547SMatt Jacob 	u_int32_t	at_reserved;
2510615a547SMatt Jacob 	u_int8_t	at_lun;		/* lun or reserved */
2520615a547SMatt Jacob 	u_int8_t	at_iid;		/* initiator */
2530615a547SMatt Jacob 	u_int16_t	at_rxid; 	/* response ID */
2540615a547SMatt Jacob 	u_int16_t	at_flags;
2550615a547SMatt Jacob 	u_int16_t	at_status;	/* firmware status */
2560615a547SMatt Jacob 	u_int8_t	at_reserved1;
2570615a547SMatt Jacob 	u_int8_t	at_taskcodes;
2580615a547SMatt Jacob 	u_int8_t	at_taskflags;
2590615a547SMatt Jacob 	u_int8_t	at_execodes;
2600615a547SMatt Jacob 	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
2610615a547SMatt Jacob 	u_int32_t	at_datalen;		/* allocated data len */
2620615a547SMatt Jacob 	u_int16_t	at_scclun;	/* SCC Lun or reserved */
2630615a547SMatt Jacob 	u_int16_t	at_reserved2;
2640615a547SMatt Jacob 	u_int16_t	at_scsi_status;
2650615a547SMatt Jacob 	u_int8_t	at_sense[QLTM_SENSELEN];
2660615a547SMatt Jacob } at2_entry_t;
2670615a547SMatt Jacob 
2680615a547SMatt Jacob #define	ATIO2_TC_ATTR_MASK	0x7
2690615a547SMatt Jacob #define	ATIO2_TC_ATTR_SIMPLEQ	0
2700615a547SMatt Jacob #define	ATIO2_TC_ATTR_HEADOFQ	1
2710615a547SMatt Jacob #define	ATIO2_TC_ATTR_ORDERED	2
2720615a547SMatt Jacob #define	ATIO2_TC_ATTR_ACAQ	4
2730615a547SMatt Jacob #define	ATIO2_TC_ATTR_UNTAGGED	5
2740615a547SMatt Jacob 
2750615a547SMatt Jacob /*
2760615a547SMatt Jacob  * Continue Target I/O Entry structure
2770615a547SMatt Jacob  * Request from driver. The response from the
2780615a547SMatt Jacob  * ISP firmware is the same except that the last 18
2790615a547SMatt Jacob  * bytes are overwritten by suggested sense data if
2800615a547SMatt Jacob  * the 'autosense valid' bit is set in the status byte.
2810615a547SMatt Jacob  */
2820615a547SMatt Jacob typedef struct {
2830615a547SMatt Jacob 	isphdr_t	ct_header;
2840615a547SMatt Jacob 	u_int32_t	ct_reserved;
2850615a547SMatt Jacob 	u_int8_t	ct_lun;	/* lun */
2860615a547SMatt Jacob 	u_int8_t	ct_iid;	/* initiator id */
2870615a547SMatt Jacob 	u_int8_t	ct_reserved2;
2880615a547SMatt Jacob 	u_int8_t	ct_tgt;	/* our target id */
2890615a547SMatt Jacob 	u_int32_t	ct_flags;
2900615a547SMatt Jacob 	u_int8_t 	ct_status;	/* isp status */
2910615a547SMatt Jacob 	u_int8_t 	ct_scsi_status;	/* scsi status */
2920615a547SMatt Jacob 	u_int8_t 	ct_tag_val;	/* tag value */
2930615a547SMatt Jacob 	u_int8_t 	ct_tag_type;	/* tag type */
2940615a547SMatt Jacob 	u_int32_t	ct_xfrlen;	/* transfer length */
2950615a547SMatt Jacob 	u_int32_t	ct_resid;	/* residual length */
2960615a547SMatt Jacob 	u_int16_t	ct_timeout;
2970615a547SMatt Jacob 	u_int16_t	ct_seg_count;
2980615a547SMatt Jacob 	ispds_t		ct_dataseg[ISP_RQDSEG];
2990615a547SMatt Jacob } ct_entry_t;
3000615a547SMatt Jacob 
3010615a547SMatt Jacob /*
3020615a547SMatt Jacob  * ct_flags values
3030615a547SMatt Jacob  */
3040615a547SMatt Jacob #define CT_TQAE		0x00000001	/* bit  1, Tagged Queue Action enable */
3050615a547SMatt Jacob #define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
3060615a547SMatt Jacob #define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
3070615a547SMatt Jacob #define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
3080615a547SMatt Jacob #define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
3090615a547SMatt Jacob #define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
3100615a547SMatt Jacob #define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
3110615a547SMatt Jacob #define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
3120615a547SMatt Jacob #define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
3130615a547SMatt Jacob #define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
3140615a547SMatt Jacob 
3150615a547SMatt Jacob /*
3160615a547SMatt Jacob  * ct_status values
3170615a547SMatt Jacob  * - set by the firmware when it returns the CTIO
3180615a547SMatt Jacob  */
3190615a547SMatt Jacob #define CT_OK		0x01	/* completed without error */
3200615a547SMatt Jacob #define CT_ABORTED	0x02	/* aborted by host */
3210615a547SMatt Jacob #define CT_ERR		0x04	/* see sense data for error */
3220615a547SMatt Jacob #define CT_INVAL	0x06	/* request for disabled lun */
3230615a547SMatt Jacob #define CT_NOPATH	0x07	/* invalid ITL nexus */
3240615a547SMatt Jacob #define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
3250615a547SMatt Jacob #define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
3260615a547SMatt Jacob #define CT_TIMEOUT	0x0B	/* timed out */
3270615a547SMatt Jacob #define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
3280615a547SMatt Jacob #define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
3290615a547SMatt Jacob #define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
3300615a547SMatt Jacob #define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
3310615a547SMatt Jacob #define	CT_PORTNOTAVAIL	0x28	/* port not available */
3320615a547SMatt Jacob #define	CT_LOGOUT	0x29	/* port logout */
3330615a547SMatt Jacob #define	CT_PORTCHANGED	0x2A	/* port changed */
3340615a547SMatt Jacob #define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
3350615a547SMatt Jacob 
3360615a547SMatt Jacob /*
3370615a547SMatt Jacob  * When the firmware returns a CTIO entry, it may overwrite the last
3380615a547SMatt Jacob  * part of the structure with sense data. This starts at offset 0x2E
3390615a547SMatt Jacob  * into the entry, which is in the middle of ct_dataseg[1]. Rather
3400615a547SMatt Jacob  * than define a new struct for this, I'm just using the sense data
3410615a547SMatt Jacob  * offset.
3420615a547SMatt Jacob  */
3430615a547SMatt Jacob #define CTIO_SENSE_OFFSET	0x2E
3440615a547SMatt Jacob 
3450615a547SMatt Jacob /*
3460615a547SMatt Jacob  * Entry length in u_longs. All entries are the same size so
3470615a547SMatt Jacob  * any one will do as the numerator.
3480615a547SMatt Jacob  */
3490615a547SMatt Jacob #define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
3500615a547SMatt Jacob 
3510615a547SMatt Jacob /*
3520615a547SMatt Jacob  * QLA2100 CTIO (type 2) entry
3530615a547SMatt Jacob  */
3540615a547SMatt Jacob #define	MAXRESPLEN	26
3550615a547SMatt Jacob typedef struct {
3560615a547SMatt Jacob 	isphdr_t	ct_header;
3570615a547SMatt Jacob 	u_int32_t	ct_reserved;
3580615a547SMatt Jacob 	u_int8_t	ct_lun;	/* lun */
3590615a547SMatt Jacob 	u_int8_t	ct_iid;	/* initiator id */
3600615a547SMatt Jacob 	u_int16_t	ct_rxid; /* response ID */
3610615a547SMatt Jacob 	u_int16_t	ct_flags;
3620615a547SMatt Jacob 	u_int16_t 	ct_status;	/* isp status */
3630615a547SMatt Jacob 	u_int16_t	ct_timeout;
3640615a547SMatt Jacob 	u_int16_t	ct_seg_count;
3650615a547SMatt Jacob 	u_int32_t	ct_reloff;	/* relative offset */
3660615a547SMatt Jacob 	u_int32_t	ct_resid;	/* residual length */
3670615a547SMatt Jacob 	union {
3680615a547SMatt Jacob 		/*
3690615a547SMatt Jacob 		 * The three different modes that the target driver
3700615a547SMatt Jacob 		 * can set the CTIO2 up as.
3710615a547SMatt Jacob 		 *
3720615a547SMatt Jacob 		 * The first is for sending FCP_DATA_IUs as well as
3730615a547SMatt Jacob 		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
3740615a547SMatt Jacob 		 *
3750615a547SMatt Jacob 		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
3760615a547SMatt Jacob 		 * Note that no FCP_DATA_IUs will be sent.
3770615a547SMatt Jacob 		 *
3780615a547SMatt Jacob 		 * The third is for sending FCP_RSP_IUs as built specifically
3790615a547SMatt Jacob 		 * in system memory as located by the isp_dataseg.
3800615a547SMatt Jacob 		 */
3810615a547SMatt Jacob 		struct {
3820615a547SMatt Jacob 			u_int32_t _reserved;
3830615a547SMatt Jacob 			u_int16_t _reserved2;
3840615a547SMatt Jacob 			u_int16_t ct_scsi_status;
3850615a547SMatt Jacob 			u_int32_t ct_xfrlen;
3860615a547SMatt Jacob 			ispds_t ct_dataseg[ISP_RQDSEG_T2];
3870615a547SMatt Jacob 		} m0;
3880615a547SMatt Jacob 		struct {
3890615a547SMatt Jacob 			u_int16_t _reserved;
3900615a547SMatt Jacob 			u_int16_t _reserved2;
3910615a547SMatt Jacob 			u_int16_t ct_senselen;
3920615a547SMatt Jacob 			u_int16_t ct_scsi_status;
3930615a547SMatt Jacob 			u_int16_t ct_resplen;
3940615a547SMatt Jacob 			u_int8_t  ct_resp[MAXRESPLEN];
3950615a547SMatt Jacob 		} m1;
3960615a547SMatt Jacob 		struct {
3970615a547SMatt Jacob 			u_int32_t _reserved;
3980615a547SMatt Jacob 			u_int16_t _reserved2;
3990615a547SMatt Jacob 			u_int16_t _reserved3;
4000615a547SMatt Jacob 			u_int32_t ct_datalen;
4010615a547SMatt Jacob 			ispds_t ct_fcp_rsp_iudata;
4020615a547SMatt Jacob 		} m2;
4030615a547SMatt Jacob 		/*
4040615a547SMatt Jacob 		 * CTIO2 returned from F/W...
4050615a547SMatt Jacob 		 */
4060615a547SMatt Jacob 		struct {
4070615a547SMatt Jacob 			u_int32_t _reserved[4];
4080615a547SMatt Jacob 			u_int16_t ct_scsi_status;
4090615a547SMatt Jacob 			u_int8_t  ct_sense[QLTM_SENSELEN];
4100615a547SMatt Jacob 		} fw;
4110615a547SMatt Jacob 	} rsp;
4120615a547SMatt Jacob } ct2_entry_t;
4130615a547SMatt Jacob 
4140615a547SMatt Jacob /*
4150615a547SMatt Jacob  * ct_flags values for CTIO2
4160615a547SMatt Jacob  */
4170615a547SMatt Jacob #define	CT2_FLAG_MMASK	0x0003
4180615a547SMatt Jacob #define	CT2_FLAG_MODE0	0x0000
4190615a547SMatt Jacob #define	CT2_FLAG_MODE1	0x0001
4200615a547SMatt Jacob #define	CT2_FLAG_MODE2	0x0002
4210615a547SMatt Jacob #define CT2_DATA_IN	CT_DATA_IN
4220615a547SMatt Jacob #define CT2_DATA_OUT	CT_DATA_OUT
4230615a547SMatt Jacob #define CT2_NO_DATA	CT_NO_DATA
4240615a547SMatt Jacob #define CT2_DATAMASK	CT_DATAMASK
4250615a547SMatt Jacob #define	CT2_CCINCR	0x0100
4260615a547SMatt Jacob #define	CT2_FASTPOST	0x0200
4270615a547SMatt Jacob #define CT2_SENDSTATUS	0x8000
4280615a547SMatt Jacob 
4290615a547SMatt Jacob /*
4300615a547SMatt Jacob  * ct_status values are (mostly) the same as that for ct_entry.
4310615a547SMatt Jacob  */
4320615a547SMatt Jacob 
4330615a547SMatt Jacob /*
4340615a547SMatt Jacob  * ct_scsi_status values- the low 8 bits are the normal SCSI status
4350615a547SMatt Jacob  * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
4360615a547SMatt Jacob  * fields.
4370615a547SMatt Jacob  */
4380615a547SMatt Jacob #define	CT2_RSPLEN_VALID	0x0100
4390615a547SMatt Jacob #define	CT2_SNSLEN_VALID	0x0200
4400615a547SMatt Jacob #define	CT2_DATA_OVER		0x0400
4410615a547SMatt Jacob #define	CT2_DATA_UNDER		0x0800
4420615a547SMatt Jacob 
4430615a547SMatt Jacob /*
4440615a547SMatt Jacob  * Macros for packing/unpacking the above structures
4450615a547SMatt Jacob  */
4460615a547SMatt Jacob 
4470615a547SMatt Jacob #ifdef	__sparc__
4480615a547SMatt Jacob #define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
4490615a547SMatt Jacob 	if (isp->isp_bus == ISP_SBUS) {	\
4500615a547SMatt Jacob 		source -> taga =  dest -> tagb;	\
4510615a547SMatt Jacob 		source -> tagb =  dest -> taga;	\
4520615a547SMatt Jacob 	} else { \
4530615a547SMatt Jacob 		source -> taga =  dest -> taga;	\
4540615a547SMatt Jacob 		source -> tagb =  dest -> taga;	\
4550615a547SMatt Jacob 	}
4560615a547SMatt Jacob #else
4570615a547SMatt Jacob #define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
4580615a547SMatt Jacob 		source -> taga =  dest -> taga;	\
4590615a547SMatt Jacob 		source -> tagb =  dest -> taga;
4600615a547SMatt Jacob #endif
4610615a547SMatt Jacob 
4620615a547SMatt Jacob /* This is really only for SBus cards on a sparc */
4630615a547SMatt Jacob #ifdef	__sparc__
4640615a547SMatt Jacob #define	ISP_SWIZ_ATIO(isp, dest, vsrc)					\
4650615a547SMatt Jacob {									\
4660615a547SMatt Jacob 	at_entry_t *source = (at_entry_t *) vsrc;			\
4670615a547SMatt Jacob 	dest->at_header = source->at_header;				\
4680615a547SMatt Jacob 	dest->at_reserved2 = source->at_reserved2;			\
4690615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, at_lun, at_iid);		\
4700615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, at_cdblen, at_tgt);		\
4710615a547SMatt Jacob 	dest->at_flags = source->at_flags;				\
4720615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, at_status, at_scsi_status);	\
4730615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, at_tag_val, at_tag_type);	\
4740615a547SMatt Jacob 	MEMCPY(dest->at_cdb, source->at_cdb, ATIO_CDBLEN);		\
4750615a547SMatt Jacob 	MEMCPY(dest->at_sense, source->at_sense, QLTM_SENSELEN);	\
4760615a547SMatt Jacob }
4770615a547SMatt Jacob 
4780615a547SMatt Jacob #define	ISP_SWIZ_CTIO(isp, dest, vsrc)					\
4790615a547SMatt Jacob {									\
4800615a547SMatt Jacob 	ct_entry_t *source = (ct_entry-t *) vsrc;			\
4810615a547SMatt Jacob 	dest->ct_header = source->ct_header;				\
4820615a547SMatt Jacob 	dest->ct_reserved = source->ct_reserved;			\
4830615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, ct_lun, ct_iid);		\
4840615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, ct_rsvd, ct_tgt);		\
4850615a547SMatt Jacob 	dest->ct_flags = source->ct_flags;				\
4860615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, ct_status, ct_scsi_status);	\
4870615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, ct_tag_val, ct_tag_type);	\
4880615a547SMatt Jacob 	dest->ct_xfrlen = source->ct_xfrlen;				\
4890615a547SMatt Jacob 	dest->ct_resid = source->ct_resid;				\
4900615a547SMatt Jacob 	dest->ct_timeout = source->ct_timeout;				\
4910615a547SMatt Jacob 	dest->ct_seg_count = source->ct_seg_count;			\
4920615a547SMatt Jacob 	MEMCPY(dest->ct_cdb, source->ct_cdb, ATIO_CDBLEN);		\
4930615a547SMatt Jacob 	MEMCPY(dest->ct_sense, source->ct_sense, QLTM_SENSELEN);	\
4940615a547SMatt Jacob 	dest->ct_dataseg = source->ct_dataseg;				\
4950615a547SMatt Jacob }
4960615a547SMatt Jacob #define	ISP_SWIZ_ENABLE_LUN(isp, dest, vsrc)				\
4970615a547SMatt Jacob {									\
4980615a547SMatt Jacob 	lun_entry_t *source = (lun_entry_t *)vsrc;			\
4990615a547SMatt Jacob 	dest->le_header = source->le_header;				\
5000615a547SMatt Jacob 	dest->le_reserved2 = source->le_reserved2;			\
5010615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, le_lun, le_rsvd);		\
5020615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, le_ops, le_tgt);		\
5030615a547SMatt Jacob 	dest->le_flags = source->le_flags;				\
5040615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, le_status, le_rsvd2);	\
5050615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, le_cmd_count, le_in_count);	\
5060615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, le_cdb6len, le_cdb7len);	\
5070615a547SMatt Jacob 	dest->le_timeout = source->le_timeout;				\
5080615a547SMatt Jacob 	dest->le_reserved = source->le_reserved;			\
5090615a547SMatt Jacob }
5100615a547SMatt Jacob #define	ISP_SWIZ_NOTIFY(isp, dest, vsrc)				\
5110615a547SMatt Jacob {									\
5120615a547SMatt Jacob 	in_entry_type *source = (in_entry_t *)vsrc;			\
5130615a547SMatt Jacob 	dest->in_header = source->in_header;				\
5140615a547SMatt Jacob 	dest->in_reserved2 = source->in_reserved2;			\
5150615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, in_lun, in_iid);		\
5160615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, in_rsvd, in_tgt);		\
5170615a547SMatt Jacob 	dest->in_flags = source->in_flags;				\
5180615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, in_status, in_rsvd2);	\
5190615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, in_tag_val, in_tag_type);	\
5200615a547SMatt Jacob 	dest->in_seqid = source->in_seqid;				\
5210615a547SMatt Jacob 	MEMCPY(dest->in_msg, source->in_msg, IN_MSGLEN);		\
5220615a547SMatt Jacob 	MEMCPY(dest->in_reserved, source->in_reserved, IN_RESERVED);	\
5230615a547SMatt Jacob 	MEMCPY(dest->in_sense, source->in_sense, QLTM_SENSELEN);	\
5240615a547SMatt Jacob }
5250615a547SMatt Jacob #define	ISP_SWIZ_NOT_ACK(isp, dest)					\
5260615a547SMatt Jacob {									\
5270615a547SMatt Jacob 	na_entry_t *source = (na_entry_t *)vsrc;			\
5280615a547SMatt Jacob 	dest->na_header = source->na_header;				\
5290615a547SMatt Jacob 	dest->na_reserved2 = source->na_reserved2;			\
5300615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, na_lun, na_iid);		\
5310615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, na_rsvd, na_tgt);		\
5320615a547SMatt Jacob 	dest->na_flags = source->na_flags;				\
5330615a547SMatt Jacob 	ISP_SBUS_SWOZZLE(isp, source, dest, na_status, na_event);	\
5340615a547SMatt Jacob 	dest->na_seqid = source->na_seqid;				\
5350615a547SMatt Jacob 	MEMCPY(dest->na_reserved, source->na_reserved, NA_RSVDLEN);	\
5360615a547SMatt Jacob }
5370615a547SMatt Jacob #define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5380615a547SMatt Jacob #else
5390615a547SMatt Jacob #define	ISP_SWIZ_ATIO(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5400615a547SMatt Jacob #define	ISP_SWIZ_CTIO(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5410615a547SMatt Jacob #define	ISP_SWIZ_ENABLE_LUN(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5420615a547SMatt Jacob #define	ISP_SWIZ_NOTIFY(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5430615a547SMatt Jacob #define	ISP_SWIZ_NOT_ACK(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5440615a547SMatt Jacob #define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5450615a547SMatt Jacob #endif
5460615a547SMatt Jacob #define	ISP_SWIZ_ATIO2(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5470615a547SMatt Jacob #define	ISP_SWIZ_CTIO2(isp, d, s)	MEMCPY((void *)d, (void *)s, QENTRY_LEN)
5480615a547SMatt Jacob 
5490615a547SMatt Jacob /*
5500615a547SMatt Jacob  * Debug macros
5510615a547SMatt Jacob  */
5520615a547SMatt Jacob 
5530615a547SMatt Jacob extern int isp_tdebug;
5540615a547SMatt Jacob #define	ISP_TDQE(isp, msg, idx, arg)	\
5550615a547SMatt Jacob 	if (isp_tdebug > 3) isp_print_qentry(isp, msg, idx, arg)
5560615a547SMatt Jacob 
5570615a547SMatt Jacob #define	ITDEBUG(level, msg)	if (level > isp_tdebug) PRINTF msg
5580615a547SMatt Jacob 
5590615a547SMatt Jacob /*
5600615a547SMatt Jacob  * Common (for all platfoms) software SCSI msg/event structures.
5610615a547SMatt Jacob  */
5620615a547SMatt Jacob 
5630615a547SMatt Jacob typedef struct {
5640615a547SMatt Jacob 	u_int8_t	nt_iid;			/* inititator id */
5650615a547SMatt Jacob 	u_int8_t	nt_tgt;			/* target id */
5660615a547SMatt Jacob 	u_int16_t	nt_lun;			/* logical unit */
5670615a547SMatt Jacob 	u_int8_t	nt_bus;			/* bus */
5680615a547SMatt Jacob 	u_int8_t	nt_tagtype;		/* tag type */
5690615a547SMatt Jacob 	u_int16_t	nt_tagval;		/* tag value */
5700615a547SMatt Jacob 	u_int8_t	nt_msg[IN_MSGLEN];	/* message content */
5710615a547SMatt Jacob } tmd_msg_t;
5720615a547SMatt Jacob 
5730615a547SMatt Jacob typedef struct {
5740615a547SMatt Jacob 	u_int16_t	ev_bus;			/* bus */
5750615a547SMatt Jacob 	u_int16_t	ev_event;		/* type of async event */
5760615a547SMatt Jacob } tmd_event_t;
5770615a547SMatt Jacob 
5780615a547SMatt Jacob /*
5790615a547SMatt Jacob  * Target Mode functions
5800615a547SMatt Jacob  */
5810615a547SMatt Jacob 
5820615a547SMatt Jacob /*
5830615a547SMatt Jacob  * This function handles new response queue entry appropriate for target mode.
5840615a547SMatt Jacob  */
5850615a547SMatt Jacob int isp_target_notify __P((struct ispsoftc *, void *, u_int16_t *));
5860615a547SMatt Jacob 
5870615a547SMatt Jacob /*
5880615a547SMatt Jacob  * Enable/Disable/Modify a logical unit.
5890615a547SMatt Jacob  */
5900615a547SMatt Jacob #define	DFLT_CMD_CNT	(RESULT_QUEUE_LEN >> 1)
5910615a547SMatt Jacob #define	DFLT_INOTIFY	(4)
5920615a547SMatt Jacob int isp_lun_cmd __P((struct ispsoftc *isp, int, int, int, int, u_int32_t));
5930615a547SMatt Jacob 
5940615a547SMatt Jacob /*
5950615a547SMatt Jacob  * General request queue 'put' routine for target mode entries.
5960615a547SMatt Jacob  */
5970615a547SMatt Jacob int isp_target_put_entry __P((struct ispsoftc *isp, void *));
5980615a547SMatt Jacob 
5990615a547SMatt Jacob /*
6000615a547SMatt Jacob  * General routine to put back an ATIO entry-
6010615a547SMatt Jacob  * used for replenishing f/w resource counts.
6020615a547SMatt Jacob  */
6030615a547SMatt Jacob int
6040615a547SMatt Jacob isp_target_put_atio __P((struct ispsoftc *isp, int, int, int, int, int));
6050615a547SMatt Jacob 
6060615a547SMatt Jacob /*
6070615a547SMatt Jacob  * General routine to send a final CTIO for a command- used mostly for
6080615a547SMatt Jacob  * local responses.
6090615a547SMatt Jacob  */
6100615a547SMatt Jacob int
6110615a547SMatt Jacob isp_endcmd __P((struct ispsoftc *isp, void *, u_int32_t, u_int32_t));
6120615a547SMatt Jacob 
6130615a547SMatt Jacob /*
6140615a547SMatt Jacob  * Handle an asynchronous event
6150615a547SMatt Jacob  */
6160615a547SMatt Jacob 
6170615a547SMatt Jacob void isp_target_async __P((struct ispsoftc *, int, int));
6180615a547SMatt Jacob 
6190615a547SMatt Jacob #endif	/* _ISPTARGET_H */
620