isp_target.h revision 70457
155372Smjacob/* $FreeBSD: head/sys/dev/isp/isp_target.h 70457 2000-12-28 23:27:54Z 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 *
1066189Smjacob * Additional Copyright (c) 1999< 2000
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 */
3655372Smjacob#ifndef	_ISPTARGET_H
3755372Smjacob#define	_ISPTARGET_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 */
6955372Smjacob#define LUN_TQAE	0x00000001	/* 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;
21555372Smjacob	u_int32_t	at_reserved;
21655372Smjacob	u_int8_t	at_lun;		/* lun */
21755372Smjacob	u_int8_t	at_iid;		/* initiator */
21855372Smjacob	u_int8_t	at_cdblen; 	/* cdb length */
21955372Smjacob	u_int8_t	at_tgt;		/* target */
22055372Smjacob	u_int32_t	at_flags;
22155372Smjacob	u_int8_t	at_status;	/* firmware status */
22255372Smjacob	u_int8_t	at_scsi_status;	/* scsi status */
22355372Smjacob	u_int8_t	at_tag_val;	/* tag value */
22455372Smjacob	u_int8_t	at_tag_type;	/* tag type */
22555372Smjacob	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
22655372Smjacob	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
22755372Smjacob} at_entry_t;
22855372Smjacob
22955372Smjacob/*
23055372Smjacob * at_flags values
23155372Smjacob */
23255372Smjacob#define AT_NODISC	0x00008000	/* disconnect disabled */
23355372Smjacob#define AT_TQAE		0x00000001	/* Tagged Queue Action enabled */
23455372Smjacob
23555372Smjacob/*
23655372Smjacob * at_status values
23755372Smjacob */
23855372Smjacob#define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
23955372Smjacob#define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
24055372Smjacob#define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
24155372Smjacob#define AT_NOCAP	0x16	/* Requested capability not available */
24255372Smjacob#define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
24355372Smjacob#define AT_CDB		0x3D	/* CDB received */
24455372Smjacob
24555372Smjacob/*
24655372Smjacob * Accept Target I/O Entry structure, Type 2
24755372Smjacob */
24855372Smjacob#define ATIO2_CDBLEN	16
24955372Smjacob
25055372Smjacobtypedef struct {
25155372Smjacob	isphdr_t	at_header;
25255372Smjacob	u_int32_t	at_reserved;
25355372Smjacob	u_int8_t	at_lun;		/* lun or reserved */
25455372Smjacob	u_int8_t	at_iid;		/* initiator */
25555372Smjacob	u_int16_t	at_rxid; 	/* response ID */
25655372Smjacob	u_int16_t	at_flags;
25755372Smjacob	u_int16_t	at_status;	/* firmware status */
25855372Smjacob	u_int8_t	at_reserved1;
25955372Smjacob	u_int8_t	at_taskcodes;
26055372Smjacob	u_int8_t	at_taskflags;
26155372Smjacob	u_int8_t	at_execodes;
26255372Smjacob	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
26355372Smjacob	u_int32_t	at_datalen;		/* allocated data len */
26455372Smjacob	u_int16_t	at_scclun;	/* SCC Lun or reserved */
26555372Smjacob	u_int16_t	at_reserved2;
26655372Smjacob	u_int16_t	at_scsi_status;
26755372Smjacob	u_int8_t	at_sense[QLTM_SENSELEN];
26855372Smjacob} at2_entry_t;
26955372Smjacob
27070457Smjacob#define	ATIO2_WWPN_OFFSET	0x2A
27170457Smjacob#define	ATIO2_OXID_OFFSET	0x3E
27270457Smjacob
27355372Smjacob#define	ATIO2_TC_ATTR_MASK	0x7
27455372Smjacob#define	ATIO2_TC_ATTR_SIMPLEQ	0
27555372Smjacob#define	ATIO2_TC_ATTR_HEADOFQ	1
27655372Smjacob#define	ATIO2_TC_ATTR_ORDERED	2
27755372Smjacob#define	ATIO2_TC_ATTR_ACAQ	4
27855372Smjacob#define	ATIO2_TC_ATTR_UNTAGGED	5
27955372Smjacob
28055372Smjacob/*
28155372Smjacob * Continue Target I/O Entry structure
28255372Smjacob * Request from driver. The response from the
28355372Smjacob * ISP firmware is the same except that the last 18
28455372Smjacob * bytes are overwritten by suggested sense data if
28555372Smjacob * the 'autosense valid' bit is set in the status byte.
28655372Smjacob */
28755372Smjacobtypedef struct {
28855372Smjacob	isphdr_t	ct_header;
28955372Smjacob	u_int32_t	ct_reserved;
29055372Smjacob	u_int8_t	ct_lun;	/* lun */
29155372Smjacob	u_int8_t	ct_iid;	/* initiator id */
29255372Smjacob	u_int8_t	ct_reserved2;
29355372Smjacob	u_int8_t	ct_tgt;	/* our target id */
29455372Smjacob	u_int32_t	ct_flags;
29555372Smjacob	u_int8_t 	ct_status;	/* isp status */
29655372Smjacob	u_int8_t 	ct_scsi_status;	/* scsi status */
29755372Smjacob	u_int8_t 	ct_tag_val;	/* tag value */
29855372Smjacob	u_int8_t 	ct_tag_type;	/* tag type */
29955372Smjacob	u_int32_t	ct_xfrlen;	/* transfer length */
30055372Smjacob	u_int32_t	ct_resid;	/* residual length */
30155372Smjacob	u_int16_t	ct_timeout;
30255372Smjacob	u_int16_t	ct_seg_count;
30355372Smjacob	ispds_t		ct_dataseg[ISP_RQDSEG];
30455372Smjacob} ct_entry_t;
30555372Smjacob
30655372Smjacob/*
30756005Smjacob * For some of the dual port SCSI adapters, port (bus #) is reported
30856005Smjacob * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
30956005Smjacob *
31056005Smjacob * Note that this does not apply to FC adapters at all which can and
31156005Smjacob * do report IIDs between 129 && 255 (these represent devices that have
31256005Smjacob * logged in across a SCSI fabric).
31356005Smjacob */
31456005Smjacob#define	GET_IID_VAL(x)		(x & 0x3f)
31556005Smjacob#define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
31656005Smjacob#define	SET_IID_VAL(y, x)	(y | (x & 0x3f))
31756005Smjacob#define	SET_BUS_VAL(y, x)	(y | ((x & 0x1) << 7))
31856005Smjacob
31956005Smjacob/*
32055372Smjacob * ct_flags values
32155372Smjacob */
32255372Smjacob#define CT_TQAE		0x00000001	/* bit  1, Tagged Queue Action enable */
32355372Smjacob#define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
32455372Smjacob#define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
32555372Smjacob#define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
32655372Smjacob#define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
32755372Smjacob#define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
32863390Smjacob#define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
32955372Smjacob#define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
33055372Smjacob#define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
33155372Smjacob#define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
33255372Smjacob#define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
33355372Smjacob
33455372Smjacob/*
33555372Smjacob * ct_status values
33655372Smjacob * - set by the firmware when it returns the CTIO
33755372Smjacob */
33855372Smjacob#define CT_OK		0x01	/* completed without error */
33955372Smjacob#define CT_ABORTED	0x02	/* aborted by host */
34055372Smjacob#define CT_ERR		0x04	/* see sense data for error */
34155372Smjacob#define CT_INVAL	0x06	/* request for disabled lun */
34255372Smjacob#define CT_NOPATH	0x07	/* invalid ITL nexus */
34355372Smjacob#define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
34455372Smjacob#define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
34555372Smjacob#define CT_TIMEOUT	0x0B	/* timed out */
34655372Smjacob#define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
34763390Smjacob#define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
34863390Smjacob#define	CT_PANIC	0x13	/* Unrecoverable Error */
34955372Smjacob#define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
35055372Smjacob#define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
35155372Smjacob#define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
35255372Smjacob#define	CT_PORTNOTAVAIL	0x28	/* port not available */
35355372Smjacob#define	CT_LOGOUT	0x29	/* port logout */
35455372Smjacob#define	CT_PORTCHANGED	0x2A	/* port changed */
35563390Smjacob#define	CT_IDE		0x33	/* Initiator Detected Error */
35655372Smjacob#define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
35755372Smjacob
35855372Smjacob/*
35955372Smjacob * When the firmware returns a CTIO entry, it may overwrite the last
36055372Smjacob * part of the structure with sense data. This starts at offset 0x2E
36155372Smjacob * into the entry, which is in the middle of ct_dataseg[1]. Rather
36255372Smjacob * than define a new struct for this, I'm just using the sense data
36355372Smjacob * offset.
36455372Smjacob */
36555372Smjacob#define CTIO_SENSE_OFFSET	0x2E
36655372Smjacob
36755372Smjacob/*
36855372Smjacob * Entry length in u_longs. All entries are the same size so
36955372Smjacob * any one will do as the numerator.
37055372Smjacob */
37155372Smjacob#define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
37255372Smjacob
37355372Smjacob/*
37455372Smjacob * QLA2100 CTIO (type 2) entry
37555372Smjacob */
37655372Smjacob#define	MAXRESPLEN	26
37755372Smjacobtypedef struct {
37855372Smjacob	isphdr_t	ct_header;
37955372Smjacob	u_int32_t	ct_reserved;
38055372Smjacob	u_int8_t	ct_lun;	/* lun */
38155372Smjacob	u_int8_t	ct_iid;	/* initiator id */
38255372Smjacob	u_int16_t	ct_rxid; /* response ID */
38355372Smjacob	u_int16_t	ct_flags;
38455372Smjacob	u_int16_t 	ct_status;	/* isp status */
38555372Smjacob	u_int16_t	ct_timeout;
38655372Smjacob	u_int16_t	ct_seg_count;
38755372Smjacob	u_int32_t	ct_reloff;	/* relative offset */
38856005Smjacob	int32_t		ct_resid;	/* residual length */
38955372Smjacob	union {
39055372Smjacob		/*
39155372Smjacob		 * The three different modes that the target driver
39255372Smjacob		 * can set the CTIO2 up as.
39355372Smjacob		 *
39455372Smjacob		 * The first is for sending FCP_DATA_IUs as well as
39555372Smjacob		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
39655372Smjacob		 *
39755372Smjacob		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
39855372Smjacob		 * Note that no FCP_DATA_IUs will be sent.
39955372Smjacob		 *
40055372Smjacob		 * The third is for sending FCP_RSP_IUs as built specifically
40155372Smjacob		 * in system memory as located by the isp_dataseg.
40255372Smjacob		 */
40355372Smjacob		struct {
40455372Smjacob			u_int32_t _reserved;
40555372Smjacob			u_int16_t _reserved2;
40655372Smjacob			u_int16_t ct_scsi_status;
40755372Smjacob			u_int32_t ct_xfrlen;
40855372Smjacob			ispds_t ct_dataseg[ISP_RQDSEG_T2];
40955372Smjacob		} m0;
41055372Smjacob		struct {
41155372Smjacob			u_int16_t _reserved;
41255372Smjacob			u_int16_t _reserved2;
41355372Smjacob			u_int16_t ct_senselen;
41455372Smjacob			u_int16_t ct_scsi_status;
41555372Smjacob			u_int16_t ct_resplen;
41655372Smjacob			u_int8_t  ct_resp[MAXRESPLEN];
41755372Smjacob		} m1;
41855372Smjacob		struct {
41955372Smjacob			u_int32_t _reserved;
42055372Smjacob			u_int16_t _reserved2;
42155372Smjacob			u_int16_t _reserved3;
42255372Smjacob			u_int32_t ct_datalen;
42355372Smjacob			ispds_t ct_fcp_rsp_iudata;
42455372Smjacob		} m2;
42555372Smjacob		/*
42655372Smjacob		 * CTIO2 returned from F/W...
42755372Smjacob		 */
42855372Smjacob		struct {
42955372Smjacob			u_int32_t _reserved[4];
43055372Smjacob			u_int16_t ct_scsi_status;
43155372Smjacob			u_int8_t  ct_sense[QLTM_SENSELEN];
43255372Smjacob		} fw;
43355372Smjacob	} rsp;
43455372Smjacob} ct2_entry_t;
43555372Smjacob
43655372Smjacob/*
43755372Smjacob * ct_flags values for CTIO2
43855372Smjacob */
43955372Smjacob#define	CT2_FLAG_MMASK	0x0003
44055372Smjacob#define	CT2_FLAG_MODE0	0x0000
44155372Smjacob#define	CT2_FLAG_MODE1	0x0001
44255372Smjacob#define	CT2_FLAG_MODE2	0x0002
44355372Smjacob#define CT2_DATA_IN	CT_DATA_IN
44455372Smjacob#define CT2_DATA_OUT	CT_DATA_OUT
44555372Smjacob#define CT2_NO_DATA	CT_NO_DATA
44655372Smjacob#define CT2_DATAMASK	CT_DATAMASK
44755372Smjacob#define	CT2_CCINCR	0x0100
44855372Smjacob#define	CT2_FASTPOST	0x0200
44955372Smjacob#define CT2_SENDSTATUS	0x8000
45055372Smjacob
45155372Smjacob/*
45255372Smjacob * ct_status values are (mostly) the same as that for ct_entry.
45355372Smjacob */
45455372Smjacob
45555372Smjacob/*
45655372Smjacob * ct_scsi_status values- the low 8 bits are the normal SCSI status
45755372Smjacob * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
45855372Smjacob * fields.
45955372Smjacob */
46055372Smjacob#define	CT2_RSPLEN_VALID	0x0100
46155372Smjacob#define	CT2_SNSLEN_VALID	0x0200
46255372Smjacob#define	CT2_DATA_OVER		0x0400
46355372Smjacob#define	CT2_DATA_UNDER		0x0800
46455372Smjacob
46555372Smjacob/*
46655372Smjacob * Macros for packing/unpacking the above structures
46755372Smjacob */
46855372Smjacob
46955372Smjacob#ifdef	__sparc__
47055372Smjacob#define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
47155372Smjacob	if (isp->isp_bus == ISP_SBUS) {	\
47255372Smjacob		source -> taga =  dest -> tagb;	\
47355372Smjacob		source -> tagb =  dest -> taga;	\
47455372Smjacob	} else { \
47555372Smjacob		source -> taga =  dest -> taga;	\
47655372Smjacob		source -> tagb =  dest -> taga;	\
47755372Smjacob	}
47855372Smjacob#else
47955372Smjacob#define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
48055372Smjacob		source -> taga =  dest -> taga;	\
48155372Smjacob		source -> tagb =  dest -> taga;
48255372Smjacob#endif
48355372Smjacob
48456005Smjacob#define	MCIDF(d, s)	if ((void *) d != (void *)s) MEMCPY(d, s, QENTRY_LEN)
48556005Smjacob
48655372Smjacob/* This is really only for SBus cards on a sparc */
48755372Smjacob#ifdef	__sparc__
48855372Smjacob#define	ISP_SWIZ_ATIO(isp, dest, vsrc)					\
48955372Smjacob{									\
49055372Smjacob	at_entry_t *source = (at_entry_t *) vsrc;			\
49156005Smjacob	at_entry_t local, *vdst;					\
49256005Smjacob	if ((void *)dest == (void *)vsrc) {				\
49356005Smjacob		MEMCPY(vsrc, &local, sizeof (at_entry_t));		\
49456005Smjacob		vdst = &local;						\
49556005Smjacob	} else {							\
49656005Smjacob		vdst = dest;						\
49756005Smjacob	}								\
49856005Smjacob	vdst->at_header = source->at_header;				\
49956005Smjacob	vdst->at_reserved2 = source->at_reserved2;			\
50056005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, at_lun, at_iid);		\
50156005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, at_cdblen, at_tgt);		\
50256005Smjacob	vdst->at_flags = source->at_flags;				\
50356005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, at_status, at_scsi_status);	\
50456005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, at_tag_val, at_tag_type);	\
50556005Smjacob	MEMCPY(vdst->at_cdb, source->at_cdb, ATIO_CDBLEN);		\
50656005Smjacob	MEMCPY(vdst->at_sense, source->at_sense, QLTM_SENSELEN);	\
50755372Smjacob}
50855372Smjacob
50955372Smjacob#define	ISP_SWIZ_CTIO(isp, dest, vsrc)					\
51055372Smjacob{									\
51164089Smjacob	ct_entry_t *source = (ct_entry_t *) vsrc;			\
51256005Smjacob	ct_entry_t *local, *vdst;					\
51356005Smjacob	if ((void *)dest == (void *)vsrc) {				\
51456005Smjacob		MEMCPY(vsrc, &local, sizeof (ct_entry_t));		\
51556005Smjacob		vdst = &local;						\
51656005Smjacob	} else {							\
51756005Smjacob		vdst = dest;						\
51856005Smjacob	}								\
51956005Smjacob	vdst->ct_header = source->ct_header;				\
52056005Smjacob	vdst->ct_reserved = source->ct_reserved;			\
52156005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_lun, ct_iid);		\
52256005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_rsvd, ct_tgt);		\
52356005Smjacob	vdst->ct_flags = source->ct_flags;				\
52456005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_status, ct_scsi_status);	\
52556005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_tag_val, ct_tag_type);	\
52656005Smjacob	vdst->ct_xfrlen = source->ct_xfrlen;				\
52756005Smjacob	vdst->ct_resid = source->ct_resid;				\
52856005Smjacob	vdst->ct_timeout = source->ct_timeout;				\
52956005Smjacob	vdst->ct_seg_count = source->ct_seg_count;			\
53056005Smjacob	MEMCPY(vdst->ct_cdb, source->ct_cdb, ATIO_CDBLEN);		\
53156005Smjacob	MEMCPY(vdst->ct_sense, source->ct_sense, QLTM_SENSELEN);	\
53256005Smjacob	vdst->ct_dataseg = source->ct_dataseg;				\
53355372Smjacob}
53455372Smjacob#define	ISP_SWIZ_ENABLE_LUN(isp, dest, vsrc)				\
53555372Smjacob{									\
53655372Smjacob	lun_entry_t *source = (lun_entry_t *)vsrc;			\
53756005Smjacob	lun_entry_t *local, *vdst;					\
53856005Smjacob	if ((void *)dest == (void *)vsrc) {				\
53956005Smjacob		MEMCPY(vsrc, &local, sizeof (lun_entry_t));		\
54056005Smjacob		vdst = &local;						\
54156005Smjacob	} else {							\
54256005Smjacob		vdst = dest;						\
54356005Smjacob	}								\
54456005Smjacob	vdst->le_header = source->le_header;				\
54556005Smjacob	vdst->le_reserved2 = source->le_reserved2;			\
54656005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, le_lun, le_rsvd);		\
54756005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, le_ops, le_tgt);		\
54856005Smjacob	vdst->le_flags = source->le_flags;				\
54956005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, le_status, le_rsvd2);	\
55056005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cmd_count, le_in_count);	\
55156005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cdb6len, le_cdb7len);	\
55256005Smjacob	vdst->le_timeout = source->le_timeout;				\
55356005Smjacob	vdst->le_reserved = source->le_reserved;			\
55455372Smjacob}
55555372Smjacob#define	ISP_SWIZ_NOTIFY(isp, dest, vsrc)				\
55655372Smjacob{									\
55755372Smjacob	in_entry_type *source = (in_entry_t *)vsrc;			\
55856005Smjacob	in_entry_t *local, *vdst;					\
55956005Smjacob	if ((void *)dest == (void *)vsrc) {				\
56056005Smjacob		MEMCPY(vsrc, &local, sizeof (in_entry_t));		\
56156005Smjacob		vdst = &local;						\
56256005Smjacob	} else {							\
56356005Smjacob		vdst = dest;						\
56456005Smjacob	}								\
56556005Smjacob	vdst->in_header = source->in_header;				\
56656005Smjacob	vdst->in_reserved2 = source->in_reserved2;			\
56756005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, in_lun, in_iid);		\
56856005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, in_rsvd, in_tgt);		\
56956005Smjacob	vdst->in_flags = source->in_flags;				\
57056005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, in_status, in_rsvd2);	\
57156005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, in_tag_val, in_tag_type);	\
57256005Smjacob	vdst->in_seqid = source->in_seqid;				\
57356005Smjacob	MEMCPY(vdst->in_msg, source->in_msg, IN_MSGLEN);		\
57456005Smjacob	MEMCPY(vdst->in_reserved, source->in_reserved, IN_RESERVED);	\
57556005Smjacob	MEMCPY(vdst->in_sense, source->in_sense, QLTM_SENSELEN);	\
57655372Smjacob}
57755372Smjacob#define	ISP_SWIZ_NOT_ACK(isp, dest)					\
57855372Smjacob{									\
57955372Smjacob	na_entry_t *source = (na_entry_t *)vsrc;			\
58056005Smjacob	na_entry_t *local, *vdst;					\
58156005Smjacob	if ((void *)dest == (void *)vsrc) {				\
58256005Smjacob		MEMCPY(vsrc, &local, sizeof (na_entry_t));		\
58356005Smjacob		vdst = &local;						\
58456005Smjacob	} else {							\
58556005Smjacob		vdst = dest;						\
58656005Smjacob	}								\
58756005Smjacob	vdst->na_header = source->na_header;				\
58856005Smjacob	vdst->na_reserved2 = source->na_reserved2;			\
58956005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, na_lun, na_iid);		\
59056005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, na_rsvd, na_tgt);		\
59156005Smjacob	vdst->na_flags = source->na_flags;				\
59256005Smjacob	ISP_SBUS_SWOZZLE(isp, source, vdst, na_status, na_event);	\
59356005Smjacob	vdst->na_seqid = source->na_seqid;				\
59456005Smjacob	MEMCPY(vdst->na_reserved, source->na_reserved, NA_RSVDLEN);	\
59555372Smjacob}
59656005Smjacob#define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
59756005Smjacob#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
59856005Smjacob#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
59955372Smjacob#else
60056005Smjacob#define	ISP_SWIZ_ATIO(isp, d, s)	MCIDF(d, s)
60156005Smjacob#define	ISP_SWIZ_CTIO(isp, d, s)	MCIDF(d, s)
60256005Smjacob#define	ISP_SWIZ_ENABLE_LUN(isp, d, s)	MCIDF(d, s)
60356005Smjacob#define	ISP_SWIZ_NOTIFY(isp, d, s)	MCIDF(d, s)
60456005Smjacob#define	ISP_SWIZ_NOT_ACK(isp, d, s)	MCIDF(d, s)
60556005Smjacob#define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
60656005Smjacob#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
60756005Smjacob#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
60855372Smjacob#endif
60955372Smjacob
61055372Smjacob/*
61155372Smjacob * Debug macros
61255372Smjacob */
61355372Smjacob
61455372Smjacob#define	ISP_TDQE(isp, msg, idx, arg)	\
61564089Smjacob    if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
61655372Smjacob
61755372Smjacob/*
61856005Smjacob * The functions below are target mode functions that
61956005Smjacob * are generally internal to the Qlogic driver.
62055372Smjacob */
62155372Smjacob
62255372Smjacob/*
62355372Smjacob * This function handles new response queue entry appropriate for target mode.
62455372Smjacob */
62555372Smjacobint isp_target_notify __P((struct ispsoftc *, void *, u_int16_t *));
62655372Smjacob
62755372Smjacob/*
62855372Smjacob * Enable/Disable/Modify a logical unit.
62955372Smjacob */
63064089Smjacob#define	DFLT_CMD_CNT	32	/* XX */
63155372Smjacob#define	DFLT_INOTIFY	(4)
63259453Smjacobint isp_lun_cmd __P((struct ispsoftc *, int, int, int, int, u_int32_t));
63355372Smjacob
63455372Smjacob/*
63555372Smjacob * General request queue 'put' routine for target mode entries.
63655372Smjacob */
63755372Smjacobint isp_target_put_entry __P((struct ispsoftc *isp, void *));
63855372Smjacob
63955372Smjacob/*
64055372Smjacob * General routine to put back an ATIO entry-
64155372Smjacob * used for replenishing f/w resource counts.
64255372Smjacob */
64355372Smjacobint
64459453Smjacobisp_target_put_atio __P((struct ispsoftc *, int, int, int, int, int));
64555372Smjacob
64655372Smjacob/*
64755372Smjacob * General routine to send a final CTIO for a command- used mostly for
64855372Smjacob * local responses.
64955372Smjacob */
65055372Smjacobint
65159453Smjacobisp_endcmd __P((struct ispsoftc *, void *, u_int32_t, u_int32_t));
65256005Smjacob#define	ECMD_SVALID	0x100
65355372Smjacob
65455372Smjacob/*
65555372Smjacob * Handle an asynchronous event
65655372Smjacob */
65755372Smjacob
65855372Smjacobvoid isp_target_async __P((struct ispsoftc *, int, int));
65955372Smjacob
66055372Smjacob#endif	/* _ISPTARGET_H */
661