isp_target.h revision 154704
155372Smjacob/* $FreeBSD: head/sys/dev/isp/isp_target.h 154704 2006-01-23 06:23:37Z mjacob $ */
2139749Simp/*-
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 *
10154704Smjacob * Additonal Copyright (c) 1997-2006 by Matthew Jacob
1155372Smjacob * All rights reserved.
1255372Smjacob *
1355372Smjacob * Redistribution and use in source and binary forms, with or without
1455372Smjacob * modification, are permitted provided that the following conditions
1555372Smjacob * are met:
1655372Smjacob * 1. Redistributions of source code must retain the above copyright
1755372Smjacob *    notice immediately at the beginning of the file, without modification,
1855372Smjacob *    this list of conditions, and the following disclaimer.
1966189Smjacob * 2. The name of the author may not be used to endorse or promote products
2055372Smjacob *    derived from this software without specific prior written permission.
2155372Smjacob *
2255372Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2355372Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2455372Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2555372Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2655372Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2755372Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28154704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29154704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3055372Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3155372Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3255372Smjacob * SUCH DAMAGE.
3355372Smjacob *
3455372Smjacob */
3574231Smjacob#ifndef	_ISP_TARGET_H
3674231Smjacob#define	_ISP_TARGET_H
3755372Smjacob
38120016Smjacob#define	QLTM_SENSELEN	18	/* non-FC cards only */
3955372Smjacob#define QLTM_SVALID	0x80
4055372Smjacob
4155372Smjacob/*
4255372Smjacob * Structure for Enable Lun and Modify Lun queue entries
4355372Smjacob */
4455372Smjacobtypedef struct {
4555372Smjacob	isphdr_t	le_header;
4655372Smjacob	u_int32_t	le_reserved;
4755372Smjacob	u_int8_t	le_lun;
4855372Smjacob	u_int8_t	le_rsvd;
4955372Smjacob	u_int8_t	le_ops;		/* Modify LUN only */
5055372Smjacob	u_int8_t	le_tgt;		/* Not for FC */
5155372Smjacob	u_int32_t	le_flags;	/* Not for FC */
5255372Smjacob	u_int8_t	le_status;
5355372Smjacob	u_int8_t	le_reserved2;
5455372Smjacob	u_int8_t	le_cmd_count;
5555372Smjacob	u_int8_t	le_in_count;
5655372Smjacob	u_int8_t	le_cdb6len;	/* Not for FC */
5755372Smjacob	u_int8_t	le_cdb7len;	/* Not for FC */
5855372Smjacob	u_int16_t	le_timeout;
5955372Smjacob	u_int16_t	le_reserved3[20];
6055372Smjacob} lun_entry_t;
6155372Smjacob
6255372Smjacob/*
6355372Smjacob * le_flags values
6455372Smjacob */
6575195Smjacob#define LUN_TQAE	0x00000002	/* bit1  Tagged Queue Action Enable */
6655372Smjacob#define LUN_DSSM	0x01000000	/* bit24 Disable Sending SDP Message */
6761771Smjacob#define	LUN_DISAD	0x02000000	/* bit25 Disable autodisconnect */
6855372Smjacob#define LUN_DM		0x40000000	/* bit30 Disconnects Mandatory */
6955372Smjacob
7055372Smjacob/*
7155372Smjacob * le_ops values
7255372Smjacob */
7355372Smjacob#define LUN_CCINCR	0x01	/* increment command count */
7455372Smjacob#define LUN_CCDECR	0x02	/* decrement command count */
7555372Smjacob#define LUN_ININCR	0x40	/* increment immed. notify count */
7655372Smjacob#define LUN_INDECR	0x80	/* decrement immed. notify count */
7755372Smjacob
7855372Smjacob/*
7955372Smjacob * le_status values
8055372Smjacob */
8155372Smjacob#define	LUN_OK		0x01	/* we be rockin' */
8255372Smjacob#define LUN_ERR		0x04	/* request completed with error */
8355372Smjacob#define LUN_INVAL	0x06	/* invalid request */
8455372Smjacob#define LUN_NOCAP	0x16	/* can't provide requested capability */
8555372Smjacob#define LUN_ENABLED	0x3E	/* LUN already enabled */
8655372Smjacob
8755372Smjacob/*
8855372Smjacob * Immediate Notify Entry structure
8955372Smjacob */
9055372Smjacob#define IN_MSGLEN	8	/* 8 bytes */
9155372Smjacob#define IN_RSVDLEN	8	/* 8 words */
9255372Smjacobtypedef struct {
9355372Smjacob	isphdr_t	in_header;
9455372Smjacob	u_int32_t	in_reserved;
9555372Smjacob	u_int8_t	in_lun;		/* lun */
9655372Smjacob	u_int8_t	in_iid;		/* initiator */
9755372Smjacob	u_int8_t	in_reserved2;
9855372Smjacob	u_int8_t	in_tgt;		/* target */
9955372Smjacob	u_int32_t	in_flags;
10055372Smjacob	u_int8_t	in_status;
10155372Smjacob	u_int8_t	in_rsvd2;
10255372Smjacob	u_int8_t	in_tag_val;	/* tag value */
10355372Smjacob	u_int8_t	in_tag_type;	/* tag type */
10455372Smjacob	u_int16_t	in_seqid;	/* sequence id */
10555372Smjacob	u_int8_t	in_msg[IN_MSGLEN];	/* SCSI message bytes */
10655372Smjacob	u_int16_t	in_reserved3[IN_RSVDLEN];
10755372Smjacob	u_int8_t	in_sense[QLTM_SENSELEN];/* suggested sense data */
10855372Smjacob} in_entry_t;
10955372Smjacob
11055372Smjacobtypedef struct {
11155372Smjacob	isphdr_t	in_header;
11255372Smjacob	u_int32_t	in_reserved;
11355372Smjacob	u_int8_t	in_lun;		/* lun */
11455372Smjacob	u_int8_t	in_iid;		/* initiator */
11555372Smjacob	u_int16_t	in_scclun;
11655372Smjacob	u_int32_t	in_reserved2;
11755372Smjacob	u_int16_t	in_status;
11855372Smjacob	u_int16_t	in_task_flags;
11955372Smjacob	u_int16_t	in_seqid;	/* sequence id */
12055372Smjacob} in_fcentry_t;
12155372Smjacob
122154704Smjacobtypedef struct {
123154704Smjacob	isphdr_t	in_header;
124154704Smjacob	u_int32_t	in_reserved;
125154704Smjacob	u_int16_t	in_iid;		/* initiator */
126154704Smjacob	u_int16_t	in_scclun;
127154704Smjacob	u_int32_t	in_reserved2;
128154704Smjacob	u_int16_t	in_status;
129154704Smjacob	u_int16_t	in_task_flags;
130154704Smjacob	u_int16_t	in_seqid;	/* sequence id */
131154704Smjacob} in_fcentry_e_t;
132154704Smjacob
13355372Smjacob/*
13455372Smjacob * Values for the in_status field
13555372Smjacob */
13663390Smjacob#define	IN_REJECT	0x0D	/* Message Reject message received */
13755372Smjacob#define IN_RESET	0x0E	/* Bus Reset occurred */
13855372Smjacob#define IN_NO_RCAP	0x16	/* requested capability not available */
13955372Smjacob#define IN_IDE_RECEIVED	0x33	/* Initiator Detected Error msg received */
14055372Smjacob#define IN_RSRC_UNAVAIL	0x34	/* resource unavailable */
14155372Smjacob#define IN_MSG_RECEIVED	0x36	/* SCSI message received */
14255372Smjacob#define	IN_ABORT_TASK	0x20	/* task named in RX_ID is being aborted (FC) */
14355372Smjacob#define	IN_PORT_LOGOUT	0x29	/* port has logged out (FC) */
14455372Smjacob#define	IN_PORT_CHANGED	0x2A	/* port changed */
14555372Smjacob#define	IN_GLOBAL_LOGO	0x2E	/* all ports logged out */
14663390Smjacob#define	IN_NO_NEXUS	0x3B	/* Nexus not established */
14755372Smjacob
14855372Smjacob/*
14955372Smjacob * Values for the in_task_flags field- should only get one at a time!
15055372Smjacob */
151120016Smjacob#define	TASK_FLAGS_CLEAR_ACA		(1<<14)
152120016Smjacob#define	TASK_FLAGS_TARGET_RESET		(1<<13)
153120016Smjacob#define	TASK_FLAGS_LUN_RESET		(1<<12)
15455372Smjacob#define	TASK_FLAGS_CLEAR_TASK_SET	(1<<10)
155120016Smjacob#define	TASK_FLAGS_ABORT_TASK_SET	(1<<9)
15655372Smjacob
157120016Smjacob#ifndef	MSG_ABORT
158120016Smjacob#define	MSG_ABORT		0x06
159120016Smjacob#endif
160120016Smjacob#ifndef	MSG_BUS_DEV_RESET
161120016Smjacob#define	MSG_BUS_DEV_RESET	0x0c
162120016Smjacob#endif
16355372Smjacob#ifndef	MSG_ABORT_TAG
164120016Smjacob#define	MSG_ABORT_TAG		0x0d
16555372Smjacob#endif
16655372Smjacob#ifndef	MSG_CLEAR_QUEUE
16755372Smjacob#define	MSG_CLEAR_QUEUE		0x0e
16855372Smjacob#endif
16955372Smjacob#ifndef	MSG_REL_RECOVERY
17055372Smjacob#define	MSG_REL_RECOVERY	0x10
17155372Smjacob#endif
17255372Smjacob#ifndef	MSG_TERM_IO_PROC
17355372Smjacob#define	MSG_TERM_IO_PROC	0x11
17455372Smjacob#endif
175120016Smjacob#ifndef	MSG_LUN_RESET
176120016Smjacob#define	MSG_LUN_RESET		0x17
177120016Smjacob#endif
17855372Smjacob
17955372Smjacob/*
18055372Smjacob * Notify Acknowledge Entry structure
18155372Smjacob */
18255372Smjacob#define NA_RSVDLEN	22
18355372Smjacobtypedef struct {
18455372Smjacob	isphdr_t	na_header;
18555372Smjacob	u_int32_t	na_reserved;
18655372Smjacob	u_int8_t	na_lun;		/* lun */
18755372Smjacob	u_int8_t	na_iid;		/* initiator */
18855372Smjacob	u_int8_t	na_reserved2;
18955372Smjacob	u_int8_t	na_tgt;		/* target */
19055372Smjacob	u_int32_t	na_flags;
19155372Smjacob	u_int8_t	na_status;
19255372Smjacob	u_int8_t	na_event;
19355372Smjacob	u_int16_t	na_seqid;	/* sequence id */
19455372Smjacob	u_int16_t	na_reserved3[NA_RSVDLEN];
19555372Smjacob} na_entry_t;
19655372Smjacob
19755372Smjacob/*
19855372Smjacob * Value for the na_event field
19955372Smjacob */
20055372Smjacob#define NA_RST_CLRD	0x80	/* Clear an async event notification */
20159453Smjacob#define	NA_OK		0x01	/* Notify Acknowledge Succeeded */
20259453Smjacob#define	NA_INVALID	0x06	/* Invalid Notify Acknowledge */
20355372Smjacob
20455372Smjacob#define	NA2_RSVDLEN	21
20555372Smjacobtypedef struct {
20655372Smjacob	isphdr_t	na_header;
20755372Smjacob	u_int32_t	na_reserved;
20855372Smjacob	u_int8_t	na_lun;		/* lun */
20955372Smjacob	u_int8_t	na_iid;		/* initiator */
21055372Smjacob	u_int16_t	na_scclun;
21155372Smjacob	u_int16_t	na_flags;
21255372Smjacob	u_int16_t	na_reserved2;
21355372Smjacob	u_int16_t	na_status;
21455372Smjacob	u_int16_t	na_task_flags;
21555372Smjacob	u_int16_t	na_seqid;	/* sequence id */
21655372Smjacob	u_int16_t	na_reserved3[NA2_RSVDLEN];
21755372Smjacob} na_fcentry_t;
218154704Smjacob
219154704Smjacobtypedef struct {
220154704Smjacob	isphdr_t	na_header;
221154704Smjacob	u_int32_t	na_reserved;
222154704Smjacob	u_int16_t	na_iid;		/* initiator */
223154704Smjacob	u_int16_t	na_scclun;
224154704Smjacob	u_int16_t	na_flags;
225154704Smjacob	u_int16_t	na_reserved2;
226154704Smjacob	u_int16_t	na_status;
227154704Smjacob	u_int16_t	na_task_flags;
228154704Smjacob	u_int16_t	na_seqid;	/* sequence id */
229154704Smjacob	u_int16_t	na_reserved3[NA2_RSVDLEN];
230154704Smjacob} na_fcentry_e_t;
231154704Smjacob
23255372Smjacob#define	NAFC_RCOUNT	0x80	/* increment resource count */
23355372Smjacob#define NAFC_RST_CLRD	0x20	/* Clear LIP Reset */
23455372Smjacob/*
23555372Smjacob * Accept Target I/O Entry structure
23655372Smjacob */
23755372Smjacob#define ATIO_CDBLEN	26
23855372Smjacob
23955372Smjacobtypedef struct {
24055372Smjacob	isphdr_t	at_header;
24173319Smjacob	u_int16_t	at_reserved;
24273319Smjacob	u_int16_t	at_handle;
24355372Smjacob	u_int8_t	at_lun;		/* lun */
24455372Smjacob	u_int8_t	at_iid;		/* initiator */
24555372Smjacob	u_int8_t	at_cdblen; 	/* cdb length */
24655372Smjacob	u_int8_t	at_tgt;		/* target */
24755372Smjacob	u_int32_t	at_flags;
24855372Smjacob	u_int8_t	at_status;	/* firmware status */
24955372Smjacob	u_int8_t	at_scsi_status;	/* scsi status */
25055372Smjacob	u_int8_t	at_tag_val;	/* tag value */
25155372Smjacob	u_int8_t	at_tag_type;	/* tag type */
25255372Smjacob	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
25355372Smjacob	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
25455372Smjacob} at_entry_t;
25555372Smjacob
25655372Smjacob/*
25755372Smjacob * at_flags values
25855372Smjacob */
25955372Smjacob#define AT_NODISC	0x00008000	/* disconnect disabled */
26075195Smjacob#define AT_TQAE		0x00000002	/* Tagged Queue Action enabled */
26155372Smjacob
26255372Smjacob/*
26355372Smjacob * at_status values
26455372Smjacob */
26555372Smjacob#define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
26655372Smjacob#define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
26755372Smjacob#define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
26855372Smjacob#define AT_NOCAP	0x16	/* Requested capability not available */
26955372Smjacob#define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
27055372Smjacob#define AT_CDB		0x3D	/* CDB received */
27155372Smjacob/*
27275195Smjacob * Macros to create and fetch and test concatenated handle and tag value macros
27375195Smjacob */
27475195Smjacob
275140652Smjacob#define	AT_MAKE_TAGID(tid, inst, aep)					\
276140652Smjacob	tid = aep->at_handle;						\
277140652Smjacob	if (aep->at_flags & AT_TQAE) {					\
278140652Smjacob		tid |= (aep->at_tag_val << 16);				\
279140652Smjacob		tid |= (1 << 24);					\
280140652Smjacob	}								\
281154704Smjacob	tid |= (GET_BUS_VAL(aep->at_iid) << 25);			\
282154704Smjacob	tid |= (inst << 26)
28375195Smjacob
284154704Smjacob#define	CT_MAKE_TAGID(tid, bus, inst, ct)				\
285140652Smjacob	tid = ct->ct_fwhandle;						\
286140652Smjacob	if (ct->ct_flags & CT_TQAE) {					\
287140652Smjacob		tid |= (ct->ct_tag_val << 16);				\
288140652Smjacob		tid |= (1 << 24);					\
289140652Smjacob	}								\
290154704Smjacob	tid |= ((bus & 0x1) << 25);					\
291154704Smjacob	tid |= (inst << 26)
29275195Smjacob
293140652Smjacob#define	AT_HAS_TAG(val)		((val) & (1 << 24))
294140652Smjacob#define	AT_GET_TAG(val)		(((val) >> 16) & 0xff)
295154704Smjacob#define	AT_GET_INST(val)	(((val) >> 26) & 0x3f)
296154704Smjacob#define	AT_GET_BUS(val)		(((val) >> 25) & 0x1)
297140652Smjacob#define	AT_GET_HANDLE(val)	((val) & 0xffff)
29875195Smjacob
299140652Smjacob#define	IN_MAKE_TAGID(tid, inst, inp)					\
300140652Smjacob	tid = inp->in_seqid;						\
301140652Smjacob	tid |= (inp->in_tag_val << 16);					\
302140652Smjacob	tid |= (1 << 24);						\
303154704Smjacob	tid |= (GET_BUS_VAL(inp->in_iid) << 25);			\
304154704Smjacob	tid |= (inst << 26)
305140652Smjacob
306140652Smjacob#define	TAG_INSERT_INST(tid, inst)					\
307154704Smjacob	tid &= ~(0x3ffffff);						\
308154704Smjacob	tid |= (inst << 26)
309140652Smjacob
310154704Smjacob#define	TAG_INSERT_BUS(tid, bus)					\
311154704Smjacob	tid &= ~(1 << 25);						\
312154704Smjacob	tid |= (bus << 25)
313154704Smjacob
31475195Smjacob/*
31555372Smjacob * Accept Target I/O Entry structure, Type 2
31655372Smjacob */
31755372Smjacob#define ATIO2_CDBLEN	16
31855372Smjacob
31955372Smjacobtypedef struct {
32055372Smjacob	isphdr_t	at_header;
32155372Smjacob	u_int32_t	at_reserved;
32255372Smjacob	u_int8_t	at_lun;		/* lun or reserved */
32355372Smjacob	u_int8_t	at_iid;		/* initiator */
32455372Smjacob	u_int16_t	at_rxid; 	/* response ID */
32555372Smjacob	u_int16_t	at_flags;
32655372Smjacob	u_int16_t	at_status;	/* firmware status */
327120016Smjacob	u_int8_t	at_crn;		/* command reference number */
32855372Smjacob	u_int8_t	at_taskcodes;
32955372Smjacob	u_int8_t	at_taskflags;
33055372Smjacob	u_int8_t	at_execodes;
33155372Smjacob	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
33255372Smjacob	u_int32_t	at_datalen;		/* allocated data len */
33390224Smjacob	u_int16_t	at_scclun;		/* SCC Lun or reserved */
33490224Smjacob	u_int16_t	at_wwpn[4];		/* WWPN of initiator */
33590224Smjacob	u_int16_t	at_reserved2[6];
33673115Smjacob	u_int16_t	at_oxid;
33755372Smjacob} at2_entry_t;
33855372Smjacob
339154704Smjacobtypedef struct {
340154704Smjacob	isphdr_t	at_header;
341154704Smjacob	u_int32_t	at_reserved;
342154704Smjacob	u_int16_t	at_iid;		/* initiator */
343154704Smjacob	u_int16_t	at_rxid; 	/* response ID */
344154704Smjacob	u_int16_t	at_flags;
345154704Smjacob	u_int16_t	at_status;	/* firmware status */
346154704Smjacob	u_int8_t	at_crn;		/* command reference number */
347154704Smjacob	u_int8_t	at_taskcodes;
348154704Smjacob	u_int8_t	at_taskflags;
349154704Smjacob	u_int8_t	at_execodes;
350154704Smjacob	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
351154704Smjacob	u_int32_t	at_datalen;		/* allocated data len */
352154704Smjacob	u_int16_t	at_scclun;		/* SCC Lun or reserved */
353154704Smjacob	u_int16_t	at_wwpn[4];		/* WWPN of initiator */
354154704Smjacob	u_int16_t	at_reserved2[6];
355154704Smjacob	u_int16_t	at_oxid;
356154704Smjacob} at2e_entry_t;
357154704Smjacob
35870457Smjacob#define	ATIO2_WWPN_OFFSET	0x2A
35970457Smjacob#define	ATIO2_OXID_OFFSET	0x3E
36070457Smjacob
36155372Smjacob#define	ATIO2_TC_ATTR_MASK	0x7
36255372Smjacob#define	ATIO2_TC_ATTR_SIMPLEQ	0
36355372Smjacob#define	ATIO2_TC_ATTR_HEADOFQ	1
36455372Smjacob#define	ATIO2_TC_ATTR_ORDERED	2
36555372Smjacob#define	ATIO2_TC_ATTR_ACAQ	4
36655372Smjacob#define	ATIO2_TC_ATTR_UNTAGGED	5
36755372Smjacob
368120016Smjacob#define	ATIO2_EX_WRITE		0x1
369120016Smjacob#define	ATIO2_EX_READ		0x2
370140652Smjacob/*
371140652Smjacob * Macros to create and fetch and test concatenated handle and tag value macros
372140652Smjacob */
373140652Smjacob#define	AT2_MAKE_TAGID(tid, inst, aep)					\
374140652Smjacob	tid = aep->at_rxid;						\
375140652Smjacob	tid |= (inst << 16)
376120016Smjacob
377140652Smjacob#define	CT2_MAKE_TAGID(tid, inst, ct)					\
378140652Smjacob	tid = ct->ct_rxid;						\
379140652Smjacob	tid |= (inst << 16)
380140652Smjacob
381140652Smjacob#define	AT2_HAS_TAG(val)	1
382140652Smjacob#define	AT2_GET_TAG(val)	((val) & 0xffff)
383140652Smjacob#define	AT2_GET_INST(val)	((val) >> 16)
384140652Smjacob#define	AT2_GET_HANDLE		AT2_GET_TAG
385140652Smjacob
386154704Smjacob#define	FC_HAS_TAG	AT2_HAS_TAG
387154704Smjacob#define	FC_GET_TAG	AT2_GET_TAG
388154704Smjacob#define	FC_GET_INST	AT2_GET_INST
389154704Smjacob#define	FC_GET_HANDLE	AT2_GET_HANDLE
390154704Smjacob
391140652Smjacob#define	IN_FC_MAKE_TAGID(tid, inst, inp)				\
392140652Smjacob	tid = inp->in_seqid;						\
393140652Smjacob	tid |= (inst << 16)
394140652Smjacob
395140652Smjacob#define	FC_TAG_INSERT_INST(tid, inst)					\
396140652Smjacob	tid &= ~0xffff;							\
397140652Smjacob	tid |= (inst << 16)
398140652Smjacob
399140652Smjacob
40055372Smjacob/*
40155372Smjacob * Continue Target I/O Entry structure
40255372Smjacob * Request from driver. The response from the
40355372Smjacob * ISP firmware is the same except that the last 18
40455372Smjacob * bytes are overwritten by suggested sense data if
40555372Smjacob * the 'autosense valid' bit is set in the status byte.
40655372Smjacob */
40755372Smjacobtypedef struct {
40855372Smjacob	isphdr_t	ct_header;
40973319Smjacob	u_int16_t	ct_reserved;
41073319Smjacob#define	ct_syshandle	ct_reserved	/* we use this */
41173319Smjacob	u_int16_t	ct_fwhandle;	/* required by f/w */
41255372Smjacob	u_int8_t	ct_lun;	/* lun */
41355372Smjacob	u_int8_t	ct_iid;	/* initiator id */
41455372Smjacob	u_int8_t	ct_reserved2;
41555372Smjacob	u_int8_t	ct_tgt;	/* our target id */
41655372Smjacob	u_int32_t	ct_flags;
41755372Smjacob	u_int8_t 	ct_status;	/* isp status */
41855372Smjacob	u_int8_t 	ct_scsi_status;	/* scsi status */
41955372Smjacob	u_int8_t 	ct_tag_val;	/* tag value */
42055372Smjacob	u_int8_t 	ct_tag_type;	/* tag type */
42155372Smjacob	u_int32_t	ct_xfrlen;	/* transfer length */
42255372Smjacob	u_int32_t	ct_resid;	/* residual length */
42355372Smjacob	u_int16_t	ct_timeout;
42455372Smjacob	u_int16_t	ct_seg_count;
42587635Smjacob	/*
42687635Smjacob	 * This is so we can share tag name space with
42787635Smjacob	 * CTIO{2,3,4} with the minimum of pain.
42887635Smjacob	 */
42987635Smjacob	union {
43087635Smjacob		ispds_t		ct_a[ISP_RQDSEG];
43187635Smjacob	} _u;
43287635Smjacob#define	ct_dataseg	_u.ct_a
43355372Smjacob} ct_entry_t;
43455372Smjacob
43555372Smjacob/*
43656005Smjacob * For some of the dual port SCSI adapters, port (bus #) is reported
43756005Smjacob * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
43856005Smjacob *
43956005Smjacob * Note that this does not apply to FC adapters at all which can and
440154704Smjacob * do report IIDs between 0x81 && 0xfe (or 0x7ff) which represent devices
441154704Smjacob * that have logged in across a SCSI fabric.
44256005Smjacob */
44356005Smjacob#define	GET_IID_VAL(x)		(x & 0x3f)
44456005Smjacob#define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
44583005Smjacob#define	SET_IID_VAL(y, x)	y = ((y & ~0x3f) | (x & 0x3f))
44683005Smjacob#define	SET_BUS_VAL(y, x)	y = ((y & 0x3f) | ((x & 0x1) << 7))
44756005Smjacob
44856005Smjacob/*
44955372Smjacob * ct_flags values
45055372Smjacob */
45175195Smjacob#define CT_TQAE		0x00000002	/* bit  1, Tagged Queue Action enable */
45255372Smjacob#define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
45355372Smjacob#define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
45455372Smjacob#define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
45555372Smjacob#define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
45655372Smjacob#define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
45763390Smjacob#define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
45855372Smjacob#define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
45955372Smjacob#define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
46055372Smjacob#define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
46155372Smjacob#define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
46255372Smjacob
46355372Smjacob/*
46455372Smjacob * ct_status values
46555372Smjacob * - set by the firmware when it returns the CTIO
46655372Smjacob */
46755372Smjacob#define CT_OK		0x01	/* completed without error */
46855372Smjacob#define CT_ABORTED	0x02	/* aborted by host */
46955372Smjacob#define CT_ERR		0x04	/* see sense data for error */
47055372Smjacob#define CT_INVAL	0x06	/* request for disabled lun */
47155372Smjacob#define CT_NOPATH	0x07	/* invalid ITL nexus */
47255372Smjacob#define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
47377365Smjacob#define	CT_DATA_OVER	0x09	/* (FC only) Data Overrun */
47455372Smjacob#define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
47555372Smjacob#define CT_TIMEOUT	0x0B	/* timed out */
47655372Smjacob#define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
47763390Smjacob#define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
47877365Smjacob#define	CT_BUS_ERROR	0x10	/* (FC Only) DMA PCI Error */
47963390Smjacob#define	CT_PANIC	0x13	/* Unrecoverable Error */
48055372Smjacob#define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
48155372Smjacob#define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
48277365Smjacob#define	CT_DATA_UNDER	0x15	/* (FC only) Data Underrun */
48355372Smjacob#define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
48455372Smjacob#define	CT_PORTNOTAVAIL	0x28	/* port not available */
48555372Smjacob#define	CT_LOGOUT	0x29	/* port logout */
48655372Smjacob#define	CT_PORTCHANGED	0x2A	/* port changed */
48763390Smjacob#define	CT_IDE		0x33	/* Initiator Detected Error */
48855372Smjacob#define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
489154704Smjacob#define	CT_SRR		0x45	/* SRR Received */
490154704Smjacob#define	CT_LUN_RESET	0x48	/* Lun Reset Received */
49155372Smjacob
49255372Smjacob/*
49355372Smjacob * When the firmware returns a CTIO entry, it may overwrite the last
49455372Smjacob * part of the structure with sense data. This starts at offset 0x2E
49555372Smjacob * into the entry, which is in the middle of ct_dataseg[1]. Rather
49655372Smjacob * than define a new struct for this, I'm just using the sense data
49755372Smjacob * offset.
49855372Smjacob */
49955372Smjacob#define CTIO_SENSE_OFFSET	0x2E
50055372Smjacob
50155372Smjacob/*
50255372Smjacob * Entry length in u_longs. All entries are the same size so
50355372Smjacob * any one will do as the numerator.
50455372Smjacob */
50555372Smjacob#define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
50655372Smjacob
50755372Smjacob/*
50855372Smjacob * QLA2100 CTIO (type 2) entry
50955372Smjacob */
51055372Smjacob#define	MAXRESPLEN	26
51155372Smjacobtypedef struct {
51255372Smjacob	isphdr_t	ct_header;
51373319Smjacob	u_int16_t	ct_reserved;
51473319Smjacob	u_int16_t	ct_fwhandle;	/* just to match CTIO */
51592893Smjacob	u_int8_t	ct_lun;		/* lun */
51692893Smjacob	u_int8_t	ct_iid;		/* initiator id */
51792893Smjacob	u_int16_t	ct_rxid;	/* response ID */
51855372Smjacob	u_int16_t	ct_flags;
51955372Smjacob	u_int16_t 	ct_status;	/* isp status */
52055372Smjacob	u_int16_t	ct_timeout;
52155372Smjacob	u_int16_t	ct_seg_count;
52255372Smjacob	u_int32_t	ct_reloff;	/* relative offset */
52356005Smjacob	int32_t		ct_resid;	/* residual length */
52455372Smjacob	union {
52555372Smjacob		/*
52655372Smjacob		 * The three different modes that the target driver
52787635Smjacob		 * can set the CTIO{2,3,4} up as.
52855372Smjacob		 *
52955372Smjacob		 * The first is for sending FCP_DATA_IUs as well as
53055372Smjacob		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
53155372Smjacob		 *
53255372Smjacob		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
53355372Smjacob		 * Note that no FCP_DATA_IUs will be sent.
53455372Smjacob		 *
53555372Smjacob		 * The third is for sending FCP_RSP_IUs as built specifically
53655372Smjacob		 * in system memory as located by the isp_dataseg.
53755372Smjacob		 */
53855372Smjacob		struct {
53955372Smjacob			u_int32_t _reserved;
54055372Smjacob			u_int16_t _reserved2;
54155372Smjacob			u_int16_t ct_scsi_status;
54255372Smjacob			u_int32_t ct_xfrlen;
54387635Smjacob			union {
54487635Smjacob				ispds_t ct_a[ISP_RQDSEG_T2];	/* CTIO2 */
54587635Smjacob				ispds64_t ct_b[ISP_RQDSEG_T3];	/* CTIO3 */
54687635Smjacob				ispdslist_t ct_c;		/* CTIO4 */
54787635Smjacob			} _u;
54887635Smjacob#define	ct_dataseg	_u.ct_a
54987635Smjacob#define	ct_dataseg64	_u.ct_b
55087635Smjacob#define	ct_dslist	_u.ct_c
55155372Smjacob		} m0;
55255372Smjacob		struct {
55355372Smjacob			u_int16_t _reserved;
55455372Smjacob			u_int16_t _reserved2;
55555372Smjacob			u_int16_t ct_senselen;
55655372Smjacob			u_int16_t ct_scsi_status;
55755372Smjacob			u_int16_t ct_resplen;
55855372Smjacob			u_int8_t  ct_resp[MAXRESPLEN];
55955372Smjacob		} m1;
56055372Smjacob		struct {
56155372Smjacob			u_int32_t _reserved;
56255372Smjacob			u_int16_t _reserved2;
56355372Smjacob			u_int16_t _reserved3;
56455372Smjacob			u_int32_t ct_datalen;
56555372Smjacob			ispds_t ct_fcp_rsp_iudata;
56655372Smjacob		} m2;
56755372Smjacob	} rsp;
56855372Smjacob} ct2_entry_t;
56955372Smjacob
570154704Smjacobtypedef struct {
571154704Smjacob	isphdr_t	ct_header;
572154704Smjacob	u_int16_t	ct_reserved;
573154704Smjacob	u_int16_t	ct_fwhandle;	/* just to match CTIO */
574154704Smjacob	u_int16_t	ct_iid;		/* initiator id */
575154704Smjacob	u_int16_t	ct_rxid;	/* response ID */
576154704Smjacob	u_int16_t	ct_flags;
577154704Smjacob	u_int16_t 	ct_status;	/* isp status */
578154704Smjacob	u_int16_t	ct_timeout;
579154704Smjacob	u_int16_t	ct_seg_count;
580154704Smjacob	u_int32_t	ct_reloff;	/* relative offset */
581154704Smjacob	int32_t		ct_resid;	/* residual length */
582154704Smjacob	union {
583154704Smjacob		struct {
584154704Smjacob			u_int32_t _reserved;
585154704Smjacob			u_int16_t _reserved2;
586154704Smjacob			u_int16_t ct_scsi_status;
587154704Smjacob			u_int32_t ct_xfrlen;
588154704Smjacob			union {
589154704Smjacob				ispds_t ct_a[ISP_RQDSEG_T2];	/* CTIO2 */
590154704Smjacob				ispds64_t ct_b[ISP_RQDSEG_T3];	/* CTIO3 */
591154704Smjacob				ispdslist_t ct_c;		/* CTIO4 */
592154704Smjacob			} _u;
593154704Smjacob		} m0;
594154704Smjacob		struct {
595154704Smjacob			u_int16_t _reserved;
596154704Smjacob			u_int16_t _reserved2;
597154704Smjacob			u_int16_t ct_senselen;
598154704Smjacob			u_int16_t ct_scsi_status;
599154704Smjacob			u_int16_t ct_resplen;
600154704Smjacob			u_int8_t  ct_resp[MAXRESPLEN];
601154704Smjacob		} m1;
602154704Smjacob		struct {
603154704Smjacob			u_int32_t _reserved;
604154704Smjacob			u_int16_t _reserved2;
605154704Smjacob			u_int16_t _reserved3;
606154704Smjacob			u_int32_t ct_datalen;
607154704Smjacob			ispds_t ct_fcp_rsp_iudata;
608154704Smjacob		} m2;
609154704Smjacob	} rsp;
610154704Smjacob} ct2e_entry_t;
611154704Smjacob
61255372Smjacob/*
61355372Smjacob * ct_flags values for CTIO2
61455372Smjacob */
61555372Smjacob#define	CT2_FLAG_MMASK	0x0003
61655372Smjacob#define	CT2_FLAG_MODE0	0x0000
61755372Smjacob#define	CT2_FLAG_MODE1	0x0001
61855372Smjacob#define	CT2_FLAG_MODE2	0x0002
61955372Smjacob#define CT2_DATA_IN	CT_DATA_IN
62055372Smjacob#define CT2_DATA_OUT	CT_DATA_OUT
62155372Smjacob#define CT2_NO_DATA	CT_NO_DATA
62255372Smjacob#define CT2_DATAMASK	CT_DATAMASK
62355372Smjacob#define	CT2_CCINCR	0x0100
62455372Smjacob#define	CT2_FASTPOST	0x0200
625120016Smjacob#define	CT2_TERMINATE	0x4000
62655372Smjacob#define CT2_SENDSTATUS	0x8000
62755372Smjacob
62855372Smjacob/*
62955372Smjacob * ct_status values are (mostly) the same as that for ct_entry.
63055372Smjacob */
63155372Smjacob
63255372Smjacob/*
63355372Smjacob * ct_scsi_status values- the low 8 bits are the normal SCSI status
63455372Smjacob * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
63555372Smjacob * fields.
63655372Smjacob */
63755372Smjacob#define	CT2_RSPLEN_VALID	0x0100
63855372Smjacob#define	CT2_SNSLEN_VALID	0x0200
63955372Smjacob#define	CT2_DATA_OVER		0x0400
64055372Smjacob#define	CT2_DATA_UNDER		0x0800
64155372Smjacob
64255372Smjacob/*
64355372Smjacob * Debug macros
64455372Smjacob */
64555372Smjacob
64655372Smjacob#define	ISP_TDQE(isp, msg, idx, arg)	\
64764089Smjacob    if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
64855372Smjacob
64955372Smjacob/*
65087635Smjacob * The functions below are for the publicly available
65187635Smjacob * target mode functions that are internal to the Qlogic driver.
65255372Smjacob */
65355372Smjacob
65455372Smjacob/*
65555372Smjacob * This function handles new response queue entry appropriate for target mode.
65655372Smjacob */
65775195Smjacobint isp_target_notify(struct ispsoftc *, void *, u_int16_t *);
65855372Smjacob
65955372Smjacob/*
660154704Smjacob * This function externalizes the ability to acknowledge an Immediate Notify
661154704Smjacob * request.
662154704Smjacob */
663154704Smjacobvoid isp_notify_ack(struct ispsoftc *, void *);
664154704Smjacob
665154704Smjacob/*
66655372Smjacob * Enable/Disable/Modify a logical unit.
66777365Smjacob * (softc, cmd, bus, tgt, lun, cmd_cnt, inotify_cnt, opaque)
66855372Smjacob */
66998283Smjacob#define	DFLT_CMND_CNT	0xfe	/* unmonitored */
67098283Smjacob#define	DFLT_INOT_CNT	16
67177365Smjacobint isp_lun_cmd(struct ispsoftc *, int, int, int, int, int, int, u_int32_t);
67255372Smjacob
67355372Smjacob/*
67455372Smjacob * General request queue 'put' routine for target mode entries.
67555372Smjacob */
67675195Smjacobint isp_target_put_entry(struct ispsoftc *isp, void *);
67755372Smjacob
67855372Smjacob/*
67955372Smjacob * General routine to put back an ATIO entry-
68055372Smjacob * used for replenishing f/w resource counts.
68175195Smjacob * The argument is a pointer to a source ATIO
68275195Smjacob * or ATIO2.
68355372Smjacob */
68475195Smjacobint isp_target_put_atio(struct ispsoftc *, void *);
68555372Smjacob
68655372Smjacob/*
68755372Smjacob * General routine to send a final CTIO for a command- used mostly for
68855372Smjacob * local responses.
68955372Smjacob */
69075195Smjacobint isp_endcmd(struct ispsoftc *, void *, u_int32_t, u_int16_t);
69156005Smjacob#define	ECMD_SVALID	0x100
69255372Smjacob
69355372Smjacob/*
69455372Smjacob * Handle an asynchronous event
69598283Smjacob *
69698283Smjacob * Return nonzero if the interrupt that generated this event has been dismissed.
69755372Smjacob */
698154704Smjacobint isp_target_async(struct ispsoftc *, int, int);
69955372Smjacob
70074231Smjacob#endif	/* _ISP_TARGET_H */
701