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