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