isp_target.h revision 75195
155372Smjacob/* $FreeBSD: head/sys/dev/isp/isp_target.h 75195 2001-04-04 21:46:48Z mjacob $ */
255372Smjacob/*
355372Smjacob * Qlogic Target Mode Structure and Flag Definitions
455372Smjacob *
555372Smjacob * Copyright (c) 1997, 1998
655372Smjacob * Patrick Stirling
755372Smjacob * pms@psconsult.com
855372Smjacob * All rights reserved.
955372Smjacob *
1073319Smjacob * Additional Copyright (c) 1999, 2000, 2001
1155372Smjacob * Matthew Jacob
1255372Smjacob * mjacob@feral.com
1355372Smjacob * All rights reserved.
1455372Smjacob *
1555372Smjacob *
1655372Smjacob * Redistribution and use in source and binary forms, with or without
1755372Smjacob * modification, are permitted provided that the following conditions
1855372Smjacob * are met:
1955372Smjacob * 1. Redistributions of source code must retain the above copyright
2055372Smjacob *    notice immediately at the beginning of the file, without modification,
2155372Smjacob *    this list of conditions, and the following disclaimer.
2266189Smjacob * 2. The name of the author may not be used to endorse or promote products
2355372Smjacob *    derived from this software without specific prior written permission.
2455372Smjacob *
2555372Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2655372Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2755372Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2855372Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2955372Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3055372Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3155372Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3255372Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3355372Smjacob * SUCH DAMAGE.
3455372Smjacob *
3555372Smjacob */
3674231Smjacob#ifndef	_ISP_TARGET_H
3774231Smjacob#define	_ISP_TARGET_H
3855372Smjacob
3955372Smjacob/*
4055372Smjacob * Defines for all entry types
4155372Smjacob */
4255372Smjacob#define QLTM_SVALID	0x80
4355372Smjacob#define	QLTM_SENSELEN	18
4455372Smjacob
4555372Smjacob/*
4655372Smjacob * Structure for Enable Lun and Modify Lun queue entries
4755372Smjacob */
4855372Smjacobtypedef struct {
4955372Smjacob	isphdr_t	le_header;
5055372Smjacob	u_int32_t	le_reserved;
5155372Smjacob	u_int8_t	le_lun;
5255372Smjacob	u_int8_t	le_rsvd;
5355372Smjacob	u_int8_t	le_ops;		/* Modify LUN only */
5455372Smjacob	u_int8_t	le_tgt;		/* Not for FC */
5555372Smjacob	u_int32_t	le_flags;	/* Not for FC */
5655372Smjacob	u_int8_t	le_status;
5755372Smjacob	u_int8_t	le_reserved2;
5855372Smjacob	u_int8_t	le_cmd_count;
5955372Smjacob	u_int8_t	le_in_count;
6055372Smjacob	u_int8_t	le_cdb6len;	/* Not for FC */
6155372Smjacob	u_int8_t	le_cdb7len;	/* Not for FC */
6255372Smjacob	u_int16_t	le_timeout;
6355372Smjacob	u_int16_t	le_reserved3[20];
6455372Smjacob} lun_entry_t;
6555372Smjacob
6655372Smjacob/*
6755372Smjacob * le_flags values
6855372Smjacob */
6975195Smjacob#define LUN_TQAE	0x00000002	/* bit1  Tagged Queue Action Enable */
7055372Smjacob#define LUN_DSSM	0x01000000	/* bit24 Disable Sending SDP Message */
7161771Smjacob#define	LUN_DISAD	0x02000000	/* bit25 Disable autodisconnect */
7255372Smjacob#define LUN_DM		0x40000000	/* bit30 Disconnects Mandatory */
7355372Smjacob
7455372Smjacob/*
7555372Smjacob * le_ops values
7655372Smjacob */
7755372Smjacob#define LUN_CCINCR	0x01	/* increment command count */
7855372Smjacob#define LUN_CCDECR	0x02	/* decrement command count */
7955372Smjacob#define LUN_ININCR	0x40	/* increment immed. notify count */
8055372Smjacob#define LUN_INDECR	0x80	/* decrement immed. notify count */
8155372Smjacob
8255372Smjacob/*
8355372Smjacob * le_status values
8455372Smjacob */
8555372Smjacob#define	LUN_OK		0x01	/* we be rockin' */
8655372Smjacob#define LUN_ERR		0x04	/* request completed with error */
8755372Smjacob#define LUN_INVAL	0x06	/* invalid request */
8855372Smjacob#define LUN_NOCAP	0x16	/* can't provide requested capability */
8955372Smjacob#define LUN_ENABLED	0x3E	/* LUN already enabled */
9055372Smjacob
9155372Smjacob/*
9255372Smjacob * Immediate Notify Entry structure
9355372Smjacob */
9455372Smjacob#define IN_MSGLEN	8	/* 8 bytes */
9555372Smjacob#define IN_RSVDLEN	8	/* 8 words */
9655372Smjacobtypedef struct {
9755372Smjacob	isphdr_t	in_header;
9855372Smjacob	u_int32_t	in_reserved;
9955372Smjacob	u_int8_t	in_lun;		/* lun */
10055372Smjacob	u_int8_t	in_iid;		/* initiator */
10155372Smjacob	u_int8_t	in_reserved2;
10255372Smjacob	u_int8_t	in_tgt;		/* target */
10355372Smjacob	u_int32_t	in_flags;
10455372Smjacob	u_int8_t	in_status;
10555372Smjacob	u_int8_t	in_rsvd2;
10655372Smjacob	u_int8_t	in_tag_val;	/* tag value */
10755372Smjacob	u_int8_t	in_tag_type;	/* tag type */
10855372Smjacob	u_int16_t	in_seqid;	/* sequence id */
10955372Smjacob	u_int8_t	in_msg[IN_MSGLEN];	/* SCSI message bytes */
11055372Smjacob	u_int16_t	in_reserved3[IN_RSVDLEN];
11155372Smjacob	u_int8_t	in_sense[QLTM_SENSELEN];/* suggested sense data */
11255372Smjacob} in_entry_t;
11355372Smjacob
11455372Smjacobtypedef struct {
11555372Smjacob	isphdr_t	in_header;
11655372Smjacob	u_int32_t	in_reserved;
11755372Smjacob	u_int8_t	in_lun;		/* lun */
11855372Smjacob	u_int8_t	in_iid;		/* initiator */
11955372Smjacob	u_int16_t	in_scclun;
12055372Smjacob	u_int32_t	in_reserved2;
12155372Smjacob	u_int16_t	in_status;
12255372Smjacob	u_int16_t	in_task_flags;
12355372Smjacob	u_int16_t	in_seqid;	/* sequence id */
12455372Smjacob} in_fcentry_t;
12555372Smjacob
12655372Smjacob/*
12755372Smjacob * Values for the in_status field
12855372Smjacob */
12963390Smjacob#define	IN_REJECT	0x0D	/* Message Reject message received */
13055372Smjacob#define IN_RESET	0x0E	/* Bus Reset occurred */
13155372Smjacob#define IN_NO_RCAP	0x16	/* requested capability not available */
13255372Smjacob#define IN_IDE_RECEIVED	0x33	/* Initiator Detected Error msg received */
13355372Smjacob#define IN_RSRC_UNAVAIL	0x34	/* resource unavailable */
13455372Smjacob#define IN_MSG_RECEIVED	0x36	/* SCSI message received */
13555372Smjacob#define	IN_ABORT_TASK	0x20	/* task named in RX_ID is being aborted (FC) */
13655372Smjacob#define	IN_PORT_LOGOUT	0x29	/* port has logged out (FC) */
13755372Smjacob#define	IN_PORT_CHANGED	0x2A	/* port changed */
13855372Smjacob#define	IN_GLOBAL_LOGO	0x2E	/* all ports logged out */
13963390Smjacob#define	IN_NO_NEXUS	0x3B	/* Nexus not established */
14055372Smjacob
14155372Smjacob/*
14255372Smjacob * Values for the in_task_flags field- should only get one at a time!
14355372Smjacob */
14455372Smjacob#define	TASK_FLAGS_ABORT_TASK		(1<<9)
14555372Smjacob#define	TASK_FLAGS_CLEAR_TASK_SET	(1<<10)
14655372Smjacob#define	TASK_FLAGS_TARGET_RESET		(1<<13)
14755372Smjacob#define	TASK_FLAGS_CLEAR_ACA		(1<<14)
14855372Smjacob#define	TASK_FLAGS_TERMINATE_TASK	(1<<15)
14955372Smjacob
15055372Smjacob#ifndef	MSG_ABORT_TAG
15155372Smjacob#define	MSG_ABORT_TAG		0x06
15255372Smjacob#endif
15355372Smjacob#ifndef	MSG_CLEAR_QUEUE
15455372Smjacob#define	MSG_CLEAR_QUEUE		0x0e
15555372Smjacob#endif
15655372Smjacob#ifndef	MSG_BUS_DEV_RESET
15755372Smjacob#define	MSG_BUS_DEV_RESET	0x0b
15855372Smjacob#endif
15955372Smjacob#ifndef	MSG_REL_RECOVERY
16055372Smjacob#define	MSG_REL_RECOVERY	0x10
16155372Smjacob#endif
16255372Smjacob#ifndef	MSG_TERM_IO_PROC
16355372Smjacob#define	MSG_TERM_IO_PROC	0x11
16455372Smjacob#endif
16555372Smjacob
16655372Smjacob
16755372Smjacob/*
16855372Smjacob * Notify Acknowledge Entry structure
16955372Smjacob */
17055372Smjacob#define NA_RSVDLEN	22
17155372Smjacobtypedef struct {
17255372Smjacob	isphdr_t	na_header;
17355372Smjacob	u_int32_t	na_reserved;
17455372Smjacob	u_int8_t	na_lun;		/* lun */
17555372Smjacob	u_int8_t	na_iid;		/* initiator */
17655372Smjacob	u_int8_t	na_reserved2;
17755372Smjacob	u_int8_t	na_tgt;		/* target */
17855372Smjacob	u_int32_t	na_flags;
17955372Smjacob	u_int8_t	na_status;
18055372Smjacob	u_int8_t	na_event;
18155372Smjacob	u_int16_t	na_seqid;	/* sequence id */
18255372Smjacob	u_int16_t	na_reserved3[NA_RSVDLEN];
18355372Smjacob} na_entry_t;
18455372Smjacob
18555372Smjacob/*
18655372Smjacob * Value for the na_event field
18755372Smjacob */
18855372Smjacob#define NA_RST_CLRD	0x80	/* Clear an async event notification */
18959453Smjacob#define	NA_OK		0x01	/* Notify Acknowledge Succeeded */
19059453Smjacob#define	NA_INVALID	0x06	/* Invalid Notify Acknowledge */
19155372Smjacob
19255372Smjacob#define	NA2_RSVDLEN	21
19355372Smjacobtypedef struct {
19455372Smjacob	isphdr_t	na_header;
19555372Smjacob	u_int32_t	na_reserved;
19655372Smjacob	u_int8_t	na_lun;		/* lun */
19755372Smjacob	u_int8_t	na_iid;		/* initiator */
19855372Smjacob	u_int16_t	na_scclun;
19955372Smjacob	u_int16_t	na_flags;
20055372Smjacob	u_int16_t	na_reserved2;
20155372Smjacob	u_int16_t	na_status;
20255372Smjacob	u_int16_t	na_task_flags;
20355372Smjacob	u_int16_t	na_seqid;	/* sequence id */
20455372Smjacob	u_int16_t	na_reserved3[NA2_RSVDLEN];
20555372Smjacob} na_fcentry_t;
20655372Smjacob#define	NAFC_RCOUNT	0x80	/* increment resource count */
20755372Smjacob#define NAFC_RST_CLRD	0x20	/* Clear LIP Reset */
20855372Smjacob/*
20955372Smjacob * Accept Target I/O Entry structure
21055372Smjacob */
21155372Smjacob#define ATIO_CDBLEN	26
21255372Smjacob
21355372Smjacobtypedef struct {
21455372Smjacob	isphdr_t	at_header;
21573319Smjacob	u_int16_t	at_reserved;
21673319Smjacob	u_int16_t	at_handle;
21755372Smjacob	u_int8_t	at_lun;		/* lun */
21855372Smjacob	u_int8_t	at_iid;		/* initiator */
21955372Smjacob	u_int8_t	at_cdblen; 	/* cdb length */
22055372Smjacob	u_int8_t	at_tgt;		/* target */
22155372Smjacob	u_int32_t	at_flags;
22255372Smjacob	u_int8_t	at_status;	/* firmware status */
22355372Smjacob	u_int8_t	at_scsi_status;	/* scsi status */
22455372Smjacob	u_int8_t	at_tag_val;	/* tag value */
22555372Smjacob	u_int8_t	at_tag_type;	/* tag type */
22655372Smjacob	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
22755372Smjacob	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
22855372Smjacob} at_entry_t;
22955372Smjacob
23055372Smjacob/*
23155372Smjacob * at_flags values
23255372Smjacob */
23355372Smjacob#define AT_NODISC	0x00008000	/* disconnect disabled */
23475195Smjacob#define AT_TQAE		0x00000002	/* Tagged Queue Action enabled */
23555372Smjacob
23655372Smjacob/*
23755372Smjacob * at_status values
23855372Smjacob */
23955372Smjacob#define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
24055372Smjacob#define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
24155372Smjacob#define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
24255372Smjacob#define AT_NOCAP	0x16	/* Requested capability not available */
24355372Smjacob#define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
24455372Smjacob#define AT_CDB		0x3D	/* CDB received */
24555372Smjacob
24655372Smjacob/*
24775195Smjacob * Macros to create and fetch and test concatenated handle and tag value macros
24875195Smjacob */
24975195Smjacob
25075195Smjacob#define	AT_MAKE_TAGID(tid, aep)						\
25175195Smjacob	tid = ((aep)->at_handle << 16);					\
25275195Smjacob	if ((aep)->at_flags & AT_TQAE)					\
25375195Smjacob		(tid) |= ((aep)->at_tag_val + 1)
25475195Smjacob
25575195Smjacob#define	CT_MAKE_TAGID(tid, ct)						\
25675195Smjacob	tid = ((ct)->ct_fwhandle << 16);				\
25775195Smjacob	if ((ct)->ct_flags & CT_TQAE)					\
25875195Smjacob		(tid) |= ((ct)->ct_tag_val + 1)
25975195Smjacob
26075195Smjacob#define	AT_HAS_TAG(val)		((val) & 0xffff)
26175195Smjacob#define	AT_GET_TAG(val)		AT_HAS_TAG(val) - 1
26275195Smjacob#define	AT_GET_HANDLE(val)	((val) >> 16)
26375195Smjacob
26475195Smjacob/*
26555372Smjacob * Accept Target I/O Entry structure, Type 2
26655372Smjacob */
26755372Smjacob#define ATIO2_CDBLEN	16
26855372Smjacob
26955372Smjacobtypedef struct {
27055372Smjacob	isphdr_t	at_header;
27155372Smjacob	u_int32_t	at_reserved;
27255372Smjacob	u_int8_t	at_lun;		/* lun or reserved */
27355372Smjacob	u_int8_t	at_iid;		/* initiator */
27455372Smjacob	u_int16_t	at_rxid; 	/* response ID */
27555372Smjacob	u_int16_t	at_flags;
27655372Smjacob	u_int16_t	at_status;	/* firmware status */
27755372Smjacob	u_int8_t	at_reserved1;
27855372Smjacob	u_int8_t	at_taskcodes;
27955372Smjacob	u_int8_t	at_taskflags;
28055372Smjacob	u_int8_t	at_execodes;
28155372Smjacob	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
28255372Smjacob	u_int32_t	at_datalen;		/* allocated data len */
28355372Smjacob	u_int16_t	at_scclun;	/* SCC Lun or reserved */
28473115Smjacob	u_int16_t	at_reserved2[10];
28573115Smjacob	u_int16_t	at_oxid;
28655372Smjacob} at2_entry_t;
28755372Smjacob
28870457Smjacob#define	ATIO2_WWPN_OFFSET	0x2A
28970457Smjacob#define	ATIO2_OXID_OFFSET	0x3E
29070457Smjacob
29155372Smjacob#define	ATIO2_TC_ATTR_MASK	0x7
29255372Smjacob#define	ATIO2_TC_ATTR_SIMPLEQ	0
29355372Smjacob#define	ATIO2_TC_ATTR_HEADOFQ	1
29455372Smjacob#define	ATIO2_TC_ATTR_ORDERED	2
29555372Smjacob#define	ATIO2_TC_ATTR_ACAQ	4
29655372Smjacob#define	ATIO2_TC_ATTR_UNTAGGED	5
29755372Smjacob
29855372Smjacob/*
29955372Smjacob * Continue Target I/O Entry structure
30055372Smjacob * Request from driver. The response from the
30155372Smjacob * ISP firmware is the same except that the last 18
30255372Smjacob * bytes are overwritten by suggested sense data if
30355372Smjacob * the 'autosense valid' bit is set in the status byte.
30455372Smjacob */
30555372Smjacobtypedef struct {
30655372Smjacob	isphdr_t	ct_header;
30773319Smjacob	u_int16_t	ct_reserved;
30873319Smjacob#define	ct_syshandle	ct_reserved	/* we use this */
30973319Smjacob	u_int16_t	ct_fwhandle;	/* required by f/w */
31055372Smjacob	u_int8_t	ct_lun;	/* lun */
31155372Smjacob	u_int8_t	ct_iid;	/* initiator id */
31255372Smjacob	u_int8_t	ct_reserved2;
31355372Smjacob	u_int8_t	ct_tgt;	/* our target id */
31455372Smjacob	u_int32_t	ct_flags;
31555372Smjacob	u_int8_t 	ct_status;	/* isp status */
31655372Smjacob	u_int8_t 	ct_scsi_status;	/* scsi status */
31755372Smjacob	u_int8_t 	ct_tag_val;	/* tag value */
31855372Smjacob	u_int8_t 	ct_tag_type;	/* tag type */
31955372Smjacob	u_int32_t	ct_xfrlen;	/* transfer length */
32055372Smjacob	u_int32_t	ct_resid;	/* residual length */
32155372Smjacob	u_int16_t	ct_timeout;
32255372Smjacob	u_int16_t	ct_seg_count;
32355372Smjacob	ispds_t		ct_dataseg[ISP_RQDSEG];
32455372Smjacob} ct_entry_t;
32555372Smjacob
32655372Smjacob/*
32756005Smjacob * For some of the dual port SCSI adapters, port (bus #) is reported
32856005Smjacob * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
32956005Smjacob *
33056005Smjacob * Note that this does not apply to FC adapters at all which can and
33156005Smjacob * do report IIDs between 129 && 255 (these represent devices that have
33256005Smjacob * logged in across a SCSI fabric).
33356005Smjacob */
33456005Smjacob#define	GET_IID_VAL(x)		(x & 0x3f)
33556005Smjacob#define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
33656005Smjacob#define	SET_IID_VAL(y, x)	(y | (x & 0x3f))
33756005Smjacob#define	SET_BUS_VAL(y, x)	(y | ((x & 0x1) << 7))
33856005Smjacob
33956005Smjacob/*
34055372Smjacob * ct_flags values
34155372Smjacob */
34275195Smjacob#define CT_TQAE		0x00000002	/* bit  1, Tagged Queue Action enable */
34355372Smjacob#define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
34455372Smjacob#define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
34555372Smjacob#define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
34655372Smjacob#define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
34755372Smjacob#define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
34863390Smjacob#define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
34955372Smjacob#define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
35055372Smjacob#define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
35155372Smjacob#define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
35255372Smjacob#define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
35355372Smjacob
35455372Smjacob/*
35555372Smjacob * ct_status values
35655372Smjacob * - set by the firmware when it returns the CTIO
35755372Smjacob */
35855372Smjacob#define CT_OK		0x01	/* completed without error */
35955372Smjacob#define CT_ABORTED	0x02	/* aborted by host */
36055372Smjacob#define CT_ERR		0x04	/* see sense data for error */
36155372Smjacob#define CT_INVAL	0x06	/* request for disabled lun */
36255372Smjacob#define CT_NOPATH	0x07	/* invalid ITL nexus */
36355372Smjacob#define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
36455372Smjacob#define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
36555372Smjacob#define CT_TIMEOUT	0x0B	/* timed out */
36655372Smjacob#define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
36763390Smjacob#define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
36863390Smjacob#define	CT_PANIC	0x13	/* Unrecoverable Error */
36955372Smjacob#define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
37055372Smjacob#define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
37155372Smjacob#define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
37255372Smjacob#define	CT_PORTNOTAVAIL	0x28	/* port not available */
37355372Smjacob#define	CT_LOGOUT	0x29	/* port logout */
37455372Smjacob#define	CT_PORTCHANGED	0x2A	/* port changed */
37563390Smjacob#define	CT_IDE		0x33	/* Initiator Detected Error */
37655372Smjacob#define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
37755372Smjacob
37855372Smjacob/*
37955372Smjacob * When the firmware returns a CTIO entry, it may overwrite the last
38055372Smjacob * part of the structure with sense data. This starts at offset 0x2E
38155372Smjacob * into the entry, which is in the middle of ct_dataseg[1]. Rather
38255372Smjacob * than define a new struct for this, I'm just using the sense data
38355372Smjacob * offset.
38455372Smjacob */
38555372Smjacob#define CTIO_SENSE_OFFSET	0x2E
38655372Smjacob
38755372Smjacob/*
38855372Smjacob * Entry length in u_longs. All entries are the same size so
38955372Smjacob * any one will do as the numerator.
39055372Smjacob */
39155372Smjacob#define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
39255372Smjacob
39355372Smjacob/*
39455372Smjacob * QLA2100 CTIO (type 2) entry
39555372Smjacob */
39655372Smjacob#define	MAXRESPLEN	26
39755372Smjacobtypedef struct {
39855372Smjacob	isphdr_t	ct_header;
39973319Smjacob	u_int16_t	ct_reserved;
40073319Smjacob	u_int16_t	ct_fwhandle;	/* just to match CTIO */
40155372Smjacob	u_int8_t	ct_lun;	/* lun */
40255372Smjacob	u_int8_t	ct_iid;	/* initiator id */
40355372Smjacob	u_int16_t	ct_rxid; /* response ID */
40455372Smjacob	u_int16_t	ct_flags;
40555372Smjacob	u_int16_t 	ct_status;	/* isp status */
40655372Smjacob	u_int16_t	ct_timeout;
40755372Smjacob	u_int16_t	ct_seg_count;
40855372Smjacob	u_int32_t	ct_reloff;	/* relative offset */
40956005Smjacob	int32_t		ct_resid;	/* residual length */
41055372Smjacob	union {
41155372Smjacob		/*
41255372Smjacob		 * The three different modes that the target driver
41355372Smjacob		 * can set the CTIO2 up as.
41455372Smjacob		 *
41555372Smjacob		 * The first is for sending FCP_DATA_IUs as well as
41655372Smjacob		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
41755372Smjacob		 *
41855372Smjacob		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
41955372Smjacob		 * Note that no FCP_DATA_IUs will be sent.
42055372Smjacob		 *
42155372Smjacob		 * The third is for sending FCP_RSP_IUs as built specifically
42255372Smjacob		 * in system memory as located by the isp_dataseg.
42355372Smjacob		 */
42455372Smjacob		struct {
42555372Smjacob			u_int32_t _reserved;
42655372Smjacob			u_int16_t _reserved2;
42755372Smjacob			u_int16_t ct_scsi_status;
42855372Smjacob			u_int32_t ct_xfrlen;
42955372Smjacob			ispds_t ct_dataseg[ISP_RQDSEG_T2];
43055372Smjacob		} m0;
43155372Smjacob		struct {
43255372Smjacob			u_int16_t _reserved;
43355372Smjacob			u_int16_t _reserved2;
43455372Smjacob			u_int16_t ct_senselen;
43555372Smjacob			u_int16_t ct_scsi_status;
43655372Smjacob			u_int16_t ct_resplen;
43755372Smjacob			u_int8_t  ct_resp[MAXRESPLEN];
43855372Smjacob		} m1;
43955372Smjacob		struct {
44055372Smjacob			u_int32_t _reserved;
44155372Smjacob			u_int16_t _reserved2;
44255372Smjacob			u_int16_t _reserved3;
44355372Smjacob			u_int32_t ct_datalen;
44455372Smjacob			ispds_t ct_fcp_rsp_iudata;
44555372Smjacob		} m2;
44655372Smjacob		/*
44755372Smjacob		 * CTIO2 returned from F/W...
44855372Smjacob		 */
44955372Smjacob		struct {
45055372Smjacob			u_int32_t _reserved[4];
45155372Smjacob			u_int16_t ct_scsi_status;
45255372Smjacob			u_int8_t  ct_sense[QLTM_SENSELEN];
45355372Smjacob		} fw;
45455372Smjacob	} rsp;
45555372Smjacob} ct2_entry_t;
45655372Smjacob
45755372Smjacob/*
45855372Smjacob * ct_flags values for CTIO2
45955372Smjacob */
46055372Smjacob#define	CT2_FLAG_MMASK	0x0003
46155372Smjacob#define	CT2_FLAG_MODE0	0x0000
46255372Smjacob#define	CT2_FLAG_MODE1	0x0001
46355372Smjacob#define	CT2_FLAG_MODE2	0x0002
46455372Smjacob#define CT2_DATA_IN	CT_DATA_IN
46555372Smjacob#define CT2_DATA_OUT	CT_DATA_OUT
46655372Smjacob#define CT2_NO_DATA	CT_NO_DATA
46755372Smjacob#define CT2_DATAMASK	CT_DATAMASK
46855372Smjacob#define	CT2_CCINCR	0x0100
46955372Smjacob#define	CT2_FASTPOST	0x0200
47055372Smjacob#define CT2_SENDSTATUS	0x8000
47155372Smjacob
47255372Smjacob/*
47355372Smjacob * ct_status values are (mostly) the same as that for ct_entry.
47455372Smjacob */
47555372Smjacob
47655372Smjacob/*
47755372Smjacob * ct_scsi_status values- the low 8 bits are the normal SCSI status
47855372Smjacob * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
47955372Smjacob * fields.
48055372Smjacob */
48155372Smjacob#define	CT2_RSPLEN_VALID	0x0100
48255372Smjacob#define	CT2_SNSLEN_VALID	0x0200
48355372Smjacob#define	CT2_DATA_OVER		0x0400
48455372Smjacob#define	CT2_DATA_UNDER		0x0800
48555372Smjacob
48655372Smjacob/*
48755372Smjacob * Macros for packing/unpacking the above structures
48855372Smjacob */
48955372Smjacob
49055372Smjacob#ifdef	__sparc__
49174231Smjacob#define	ISP_SBUS_SWOZZLE(isp, src, dst, taga, tagb)	\
49274231Smjacob	if (isp->isp_bustype == ISP_BT_SBUS) {	\
49374231Smjacob		u_int8_t tmp = src -> taga;	\
49474231Smjacob		dst -> taga =  dst -> tagb;	\
49574231Smjacob		src -> tagb =  tmp;		\
49655372Smjacob	} else { \
49774231Smjacob		dst -> taga =  src -> taga;	\
49874231Smjacob		dst -> tagb =  src -> taga;	\
49955372Smjacob	}
50055372Smjacob#else
50174231Smjacob#define	ISP_SBUS_SWOZZLE(isp, src, dst, taga, tagb)	\
50274231Smjacob		dst -> taga =  src -> taga;	\
50374231Smjacob		dst -> tagb =  src -> taga
50455372Smjacob#endif
50555372Smjacob
50656005Smjacob#define	MCIDF(d, s)	if ((void *) d != (void *)s) MEMCPY(d, s, QENTRY_LEN)
50756005Smjacob
50855372Smjacob/* This is really only for SBus cards on a sparc */
50955372Smjacob#ifdef	__sparc__
51074231Smjacob#define	ISP_SWIZ_ATIO(isp, vdst, vsrc)					\
51155372Smjacob{									\
51274231Smjacob	at_entry_t *src = (at_entry_t *) vsrc;				\
51374231Smjacob	at_entry_t *dst = (at_entry_t *) vdst;				\
51474231Smjacob	dst->at_header = src->at_header;				\
51574231Smjacob	dst->at_reserved = src->at_reserved;				\
51674231Smjacob	dst->at_handle = src->at_handle;				\
51774231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_lun, at_iid);		\
51874231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_cdblen, at_tgt);		\
51974231Smjacob	dst->at_flags = src->at_flags;					\
52074231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_status, at_scsi_status);	\
52174231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_tag_val, at_tag_type);	\
52274231Smjacob	MEMCPY(dst->at_cdb, src->at_cdb, ATIO_CDBLEN);			\
52374231Smjacob	MEMCPY(dst->at_sense, src->at_sense, QLTM_SENSELEN);		\
52455372Smjacob}
52574231Smjacob#define	ISP_SWIZ_ATIO2(isp, vdst, vsrc)					\
52655372Smjacob{									\
52774231Smjacob	at2_entry_t *src = (at2_entry_t *) vsrc;			\
52874231Smjacob	at2_entry_t *dst = (at2_entry_t *) vdst;			\
52974231Smjacob	dst->at_reserved = src->at_reserved;				\
53074231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_lun, at_iid);		\
53174231Smjacob	dst->at_rxid = src->at_rxid;					\
53274231Smjacob	dst->at_flags = src->at_flags;					\
53374231Smjacob	dst->at_status = src->at_status;				\
53474231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_reserved1, at_taskcodes);	\
53574231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, at_taskflags, at_execodes);	\
53674231Smjacob	MEMCPY(dst->at_cdb, src->at_cdb, ATIO2_CDBLEN);			\
53774231Smjacob	dst->at_datalen = src->at_datalen;				\
53874231Smjacob	dst->at_scclun = src->at_scclun;				\
53974231Smjacob	MEMCPY(dst->at_reserved2, src->at_reserved2, sizeof dst->at_reserved2);\
54074231Smjacob	dst->at_oxid = src->at_oxid;					\
54155372Smjacob}
54274231Smjacob#define	ISP_SWIZ_CTIO(isp, vdst, vsrc)					\
54355372Smjacob{									\
54474231Smjacob	ct_entry_t *src = (ct_entry_t *) vsrc;				\
54574231Smjacob	ct_entry_t *dst = (ct_entry_t *) vdst;				\
54674231Smjacob	dst->ct_header = src->ct_header;				\
54774231Smjacob	dst->ct_syshandle = src->ct_syshandle;				\
54874231Smjacob	dst->ct_fwhandle = src->ct_fwhandle;				\
54974231Smjacob	dst->ct_fwhandle = src->ct_fwhandle;				\
55074231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, ct_lun, ct_iid);		\
55174231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, ct_reserved2, ct_tgt);		\
55274231Smjacob	dst->ct_flags = src->ct_flags;					\
55374231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, ct_status, ct_scsi_status);	\
55474231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, ct_tag_val, ct_tag_type);	\
55574231Smjacob	dst->ct_xfrlen = src->ct_xfrlen;				\
55674231Smjacob	dst->ct_resid = src->ct_resid;					\
55774231Smjacob	dst->ct_timeout = src->ct_timeout;				\
55874231Smjacob	dst->ct_seg_count = src->ct_seg_count;				\
55974231Smjacob	MEMCPY(dst->ct_dataseg, src->ct_dataseg, sizeof (dst->ct_dataseg)); \
56055372Smjacob}
56174231Smjacob#define	ISP_SWIZ_CTIO2(isp, vdst, vsrc)					\
56255372Smjacob{									\
56374231Smjacob	ct2_entry_t *src = (ct2_entry_t *) vsrc;			\
56474231Smjacob	ct2_entry_t *dst = (ct2_entry_t *) vdst;			\
56574231Smjacob	dst->ct_header = src->ct_header;				\
56674231Smjacob	dst->ct_syshandle = src->ct_syshandle;				\
56774231Smjacob	dst->ct_fwhandle = src->ct_fwhandle;				\
56874231Smjacob	dst->ct_fwhandle = src->ct_fwhandle;				\
56974231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, ct_lun, ct_iid);		\
57074231Smjacob	dst->ct_rxid = src->ct_rxid;					\
57174231Smjacob	dst->ct_flags = src->ct_flags;					\
57274231Smjacob	dst->ct_status = src->ct_status;				\
57374231Smjacob	dst->ct_timeout = src->ct_timeout;				\
57474231Smjacob	dst->ct_seg_count = src->ct_seg_count;				\
57574231Smjacob	dst->ct_reloff = src->ct_reloff;				\
57674231Smjacob	dst->ct_resid = src->ct_resid;					\
57774231Smjacob	dst->rsp = src->rsp;						\
57855372Smjacob}
57974231Smjacob#define	ISP_SWIZ_ENABLE_LUN(isp, vdst, vsrc)				\
58055372Smjacob{									\
58174231Smjacob	lun_entry_t *src = (lun_entry_t *)vsrc;				\
58274231Smjacob	lun_entry_t *dst = (lun_entry_t *)vdst;				\
58374231Smjacob	dst->le_header = src->le_header;				\
58474231Smjacob	dst->le_reserved2 = src->le_reserved2;				\
58574231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, le_lun, le_rsvd);		\
58674231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, le_ops, le_tgt);		\
58774231Smjacob	dst->le_flags = src->le_flags;					\
58874231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, le_status, le_reserved2);	\
58974231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, le_cmd_count, le_in_count);	\
59074231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, le_cdb6len, le_cdb7len);	\
59174231Smjacob	dst->le_timeout = src->le_timeout;				\
59274231Smjacob	dst->le_reserved = src->le_reserved;				\
59355372Smjacob}
59474231Smjacob#define	ISP_SWIZ_NOTIFY(isp, vdst, vsrc)				\
59574231Smjacob{									\
59674231Smjacob	in_entry_type *src = (in_entry_t *)vsrc;			\
59774231Smjacob	in_entry_type *dst = (in_entry_t *)vdst;			\
59874231Smjacob	dst->in_header = src->in_header;				\
59974231Smjacob	dst->in_reserved2 = src->in_reserved2;				\
60074231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, in_lun, in_iid);		\
60174231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, in_reserved2, in_tgt);		\
60274231Smjacob	dst->in_flags = src->in_flags;					\
60374231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, in_status, in_rsvd2);		\
60474231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, in_tag_val, in_tag_type);	\
60574231Smjacob	dst->in_seqid = src->in_seqid;					\
60674231Smjacob	MEMCPY(dst->in_msg, src->in_msg, IN_MSGLEN);			\
60774231Smjacob	MEMCPY(dst->in_reserved, src->in_reserved, IN_RESERVED);	\
60874231Smjacob	MEMCPY(dst->in_sense, src->in_sense, QLTM_SENSELEN);		\
60974231Smjacob}
61074231Smjacob#define	ISP_SWIZ_NOTIFY_FC(isp, vdst, vsrc)				\
61174231Smjacob{									\
61274231Smjacob	in_fcentry_type *src = (in_fcentry_t *)vsrc;			\
61374231Smjacob	in_fcentry_type *dst = (in_fcentry_t *)vdst;			\
61474231Smjacob	dst->in_header = src->in_header;				\
61574231Smjacob	dst->in_reserved2 = src->in_reserved2;				\
61674231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, in_lun, in_iid);		\
61774231Smjacob	dst->in_scclun = src->in_scclun;				\
61874231Smjacob	dst->in_reserved2 = src->in_reserved2;				\
61974231Smjacob	dst->in_status = src->in_status;				\
62074231Smjacob	dst->in_task_flags = src->in_task_flags;			\
62174231Smjacob	dst->in_seqid = src->in_seqid;					\
62274231Smjacob}
62374231Smjacob#define	ISP_SWIZ_NOT_ACK(isp, vdst, vsrc)				\
62474231Smjacob{									\
62574231Smjacob	na_entry_t *src = (na_entry_t *)vsrc;				\
62674231Smjacob	na_entry_t *dst = (na_entry_t *)vdst;				\
62774231Smjacob	dst->na_header = src->na_header;				\
62874231Smjacob	dst->na_reserved = src->na_reserved;				\
62974231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, na_lun, na_iid);		\
63074231Smjacob	dst->na_reserved2 = src->na_reserved2;				\
63174231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, na_reserved, na_tgt);		\
63274231Smjacob	dst->na_flags = src->na_flags;					\
63374231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, na_status, na_event);		\
63474231Smjacob	dst->na_seqid = src->na_seqid;					\
63574231Smjacob	MEMCPY(dst->na_reserved3, src->na_reserved3, NA_RSVDLEN);	\
63674231Smjacob}
63774231Smjacob#define	ISP_SWIZ_NOT_ACK_FC(isp, vdst, vsrc)				\
63874231Smjacob{									\
63974231Smjacob	na_fcentry_t *src = (na_fcentry_t *)vsrc;			\
64074231Smjacob	na_fcentry_t *dst = (na_fcentry_t *)vdst;			\
64174231Smjacob	dst->na_header = src->na_header;				\
64274231Smjacob	dst->na_reserved = src->na_reserved;				\
64374231Smjacob	ISP_SBUS_SWOZZLE(isp, src, dst, na_lun, na_iid);		\
64474231Smjacob	dst->na_scclun = src->na_scclun;				\
64574231Smjacob	dst->na_flags = src->na_flags;					\
64674231Smjacob	dst->na_reserved2 = src->na_reserved2;				\
64774231Smjacob	dst->na_status = src->na_status;				\
64874231Smjacob	dst->na_task_flags = src->na_task_flags;			\
64974231Smjacob	dst->na_seqid = src->na_seqid;					\
65074231Smjacob	MEMCPY(dst->na_reserved3, src->na_reserved3, NA2_RSVDLEN);	\
65174231Smjacob}
65255372Smjacob#else
65356005Smjacob#define	ISP_SWIZ_ATIO(isp, d, s)	MCIDF(d, s)
65474231Smjacob#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
65556005Smjacob#define	ISP_SWIZ_CTIO(isp, d, s)	MCIDF(d, s)
65674231Smjacob#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
65756005Smjacob#define	ISP_SWIZ_ENABLE_LUN(isp, d, s)	MCIDF(d, s)
65874231Smjacob#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
65974231Smjacob#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
66056005Smjacob#define	ISP_SWIZ_NOTIFY(isp, d, s)	MCIDF(d, s)
66174231Smjacob#define	ISP_SWIZ_NOTIFY_FC(isp, d, s)	MCIDF(d, s)
66256005Smjacob#define	ISP_SWIZ_NOT_ACK(isp, d, s)	MCIDF(d, s)
66356005Smjacob#define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
66455372Smjacob#endif
66555372Smjacob
66655372Smjacob/*
66755372Smjacob * Debug macros
66855372Smjacob */
66955372Smjacob
67055372Smjacob#define	ISP_TDQE(isp, msg, idx, arg)	\
67164089Smjacob    if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
67255372Smjacob
67355372Smjacob/*
67456005Smjacob * The functions below are target mode functions that
67556005Smjacob * are generally internal to the Qlogic driver.
67655372Smjacob */
67755372Smjacob
67855372Smjacob/*
67955372Smjacob * This function handles new response queue entry appropriate for target mode.
68055372Smjacob */
68175195Smjacobint isp_target_notify(struct ispsoftc *, void *, u_int16_t *);
68255372Smjacob
68355372Smjacob/*
68455372Smjacob * Enable/Disable/Modify a logical unit.
68555372Smjacob */
68664089Smjacob#define	DFLT_CMD_CNT	32	/* XX */
68755372Smjacob#define	DFLT_INOTIFY	(4)
68875195Smjacobint isp_lun_cmd(struct ispsoftc *, int, int, int, int, u_int32_t);
68955372Smjacob
69055372Smjacob/*
69155372Smjacob * General request queue 'put' routine for target mode entries.
69255372Smjacob */
69375195Smjacobint isp_target_put_entry(struct ispsoftc *isp, void *);
69455372Smjacob
69555372Smjacob/*
69655372Smjacob * General routine to put back an ATIO entry-
69755372Smjacob * used for replenishing f/w resource counts.
69875195Smjacob * The argument is a pointer to a source ATIO
69975195Smjacob * or ATIO2.
70055372Smjacob */
70175195Smjacobint isp_target_put_atio(struct ispsoftc *, void *);
70255372Smjacob
70355372Smjacob/*
70455372Smjacob * General routine to send a final CTIO for a command- used mostly for
70555372Smjacob * local responses.
70655372Smjacob */
70775195Smjacobint isp_endcmd(struct ispsoftc *, void *, u_int32_t, u_int16_t);
70856005Smjacob#define	ECMD_SVALID	0x100
70955372Smjacob
71055372Smjacob/*
71155372Smjacob * Handle an asynchronous event
71255372Smjacob */
71355372Smjacob
71475195Smjacobvoid isp_target_async(struct ispsoftc *, int, int);
71555372Smjacob
71674231Smjacob#endif	/* _ISP_TARGET_H */
717