isp_target.h revision 73115
1/* $FreeBSD: head/sys/dev/isp/isp_target.h 73115 2001-02-27 00:14:39Z 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
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	_ISPTARGET_H
37#define	_ISPTARGET_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	0x00000001	/* 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_int32_t	at_reserved;
216	u_int8_t	at_lun;		/* lun */
217	u_int8_t	at_iid;		/* initiator */
218	u_int8_t	at_cdblen; 	/* cdb length */
219	u_int8_t	at_tgt;		/* target */
220	u_int32_t	at_flags;
221	u_int8_t	at_status;	/* firmware status */
222	u_int8_t	at_scsi_status;	/* scsi status */
223	u_int8_t	at_tag_val;	/* tag value */
224	u_int8_t	at_tag_type;	/* tag type */
225	u_int8_t	at_cdb[ATIO_CDBLEN];	/* received CDB */
226	u_int8_t	at_sense[QLTM_SENSELEN];/* suggested sense data */
227} at_entry_t;
228
229/*
230 * at_flags values
231 */
232#define AT_NODISC	0x00008000	/* disconnect disabled */
233#define AT_TQAE		0x00000001	/* Tagged Queue Action enabled */
234
235/*
236 * at_status values
237 */
238#define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
239#define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
240#define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
241#define AT_NOCAP	0x16	/* Requested capability not available */
242#define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
243#define AT_CDB		0x3D	/* CDB received */
244
245/*
246 * Accept Target I/O Entry structure, Type 2
247 */
248#define ATIO2_CDBLEN	16
249
250typedef struct {
251	isphdr_t	at_header;
252	u_int32_t	at_reserved;
253	u_int8_t	at_lun;		/* lun or reserved */
254	u_int8_t	at_iid;		/* initiator */
255	u_int16_t	at_rxid; 	/* response ID */
256	u_int16_t	at_flags;
257	u_int16_t	at_status;	/* firmware status */
258	u_int8_t	at_reserved1;
259	u_int8_t	at_taskcodes;
260	u_int8_t	at_taskflags;
261	u_int8_t	at_execodes;
262	u_int8_t	at_cdb[ATIO2_CDBLEN];	/* received CDB */
263	u_int32_t	at_datalen;		/* allocated data len */
264	u_int16_t	at_scclun;	/* SCC Lun or reserved */
265	u_int16_t	at_reserved2[10];
266	u_int16_t	at_oxid;
267} at2_entry_t;
268
269#define	ATIO2_WWPN_OFFSET	0x2A
270#define	ATIO2_OXID_OFFSET	0x3E
271
272#define	ATIO2_TC_ATTR_MASK	0x7
273#define	ATIO2_TC_ATTR_SIMPLEQ	0
274#define	ATIO2_TC_ATTR_HEADOFQ	1
275#define	ATIO2_TC_ATTR_ORDERED	2
276#define	ATIO2_TC_ATTR_ACAQ	4
277#define	ATIO2_TC_ATTR_UNTAGGED	5
278
279/*
280 * Continue Target I/O Entry structure
281 * Request from driver. The response from the
282 * ISP firmware is the same except that the last 18
283 * bytes are overwritten by suggested sense data if
284 * the 'autosense valid' bit is set in the status byte.
285 */
286typedef struct {
287	isphdr_t	ct_header;
288	u_int32_t	ct_reserved;
289	u_int8_t	ct_lun;	/* lun */
290	u_int8_t	ct_iid;	/* initiator id */
291	u_int8_t	ct_reserved2;
292	u_int8_t	ct_tgt;	/* our target id */
293	u_int32_t	ct_flags;
294	u_int8_t 	ct_status;	/* isp status */
295	u_int8_t 	ct_scsi_status;	/* scsi status */
296	u_int8_t 	ct_tag_val;	/* tag value */
297	u_int8_t 	ct_tag_type;	/* tag type */
298	u_int32_t	ct_xfrlen;	/* transfer length */
299	u_int32_t	ct_resid;	/* residual length */
300	u_int16_t	ct_timeout;
301	u_int16_t	ct_seg_count;
302	ispds_t		ct_dataseg[ISP_RQDSEG];
303} ct_entry_t;
304
305/*
306 * For some of the dual port SCSI adapters, port (bus #) is reported
307 * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
308 *
309 * Note that this does not apply to FC adapters at all which can and
310 * do report IIDs between 129 && 255 (these represent devices that have
311 * logged in across a SCSI fabric).
312 */
313#define	GET_IID_VAL(x)		(x & 0x3f)
314#define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
315#define	SET_IID_VAL(y, x)	(y | (x & 0x3f))
316#define	SET_BUS_VAL(y, x)	(y | ((x & 0x1) << 7))
317
318/*
319 * ct_flags values
320 */
321#define CT_TQAE		0x00000001	/* bit  1, Tagged Queue Action enable */
322#define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
323#define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
324#define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
325#define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
326#define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
327#define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
328#define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
329#define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
330#define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
331#define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
332
333/*
334 * ct_status values
335 * - set by the firmware when it returns the CTIO
336 */
337#define CT_OK		0x01	/* completed without error */
338#define CT_ABORTED	0x02	/* aborted by host */
339#define CT_ERR		0x04	/* see sense data for error */
340#define CT_INVAL	0x06	/* request for disabled lun */
341#define CT_NOPATH	0x07	/* invalid ITL nexus */
342#define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
343#define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
344#define CT_TIMEOUT	0x0B	/* timed out */
345#define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
346#define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
347#define	CT_PANIC	0x13	/* Unrecoverable Error */
348#define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
349#define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
350#define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
351#define	CT_PORTNOTAVAIL	0x28	/* port not available */
352#define	CT_LOGOUT	0x29	/* port logout */
353#define	CT_PORTCHANGED	0x2A	/* port changed */
354#define	CT_IDE		0x33	/* Initiator Detected Error */
355#define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
356
357/*
358 * When the firmware returns a CTIO entry, it may overwrite the last
359 * part of the structure with sense data. This starts at offset 0x2E
360 * into the entry, which is in the middle of ct_dataseg[1]. Rather
361 * than define a new struct for this, I'm just using the sense data
362 * offset.
363 */
364#define CTIO_SENSE_OFFSET	0x2E
365
366/*
367 * Entry length in u_longs. All entries are the same size so
368 * any one will do as the numerator.
369 */
370#define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(u_int32_t))
371
372/*
373 * QLA2100 CTIO (type 2) entry
374 */
375#define	MAXRESPLEN	26
376typedef struct {
377	isphdr_t	ct_header;
378	u_int32_t	ct_reserved;
379	u_int8_t	ct_lun;	/* lun */
380	u_int8_t	ct_iid;	/* initiator id */
381	u_int16_t	ct_rxid; /* response ID */
382	u_int16_t	ct_flags;
383	u_int16_t 	ct_status;	/* isp status */
384	u_int16_t	ct_timeout;
385	u_int16_t	ct_seg_count;
386	u_int32_t	ct_reloff;	/* relative offset */
387	int32_t		ct_resid;	/* residual length */
388	union {
389		/*
390		 * The three different modes that the target driver
391		 * can set the CTIO2 up as.
392		 *
393		 * The first is for sending FCP_DATA_IUs as well as
394		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
395		 *
396		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
397		 * Note that no FCP_DATA_IUs will be sent.
398		 *
399		 * The third is for sending FCP_RSP_IUs as built specifically
400		 * in system memory as located by the isp_dataseg.
401		 */
402		struct {
403			u_int32_t _reserved;
404			u_int16_t _reserved2;
405			u_int16_t ct_scsi_status;
406			u_int32_t ct_xfrlen;
407			ispds_t ct_dataseg[ISP_RQDSEG_T2];
408		} m0;
409		struct {
410			u_int16_t _reserved;
411			u_int16_t _reserved2;
412			u_int16_t ct_senselen;
413			u_int16_t ct_scsi_status;
414			u_int16_t ct_resplen;
415			u_int8_t  ct_resp[MAXRESPLEN];
416		} m1;
417		struct {
418			u_int32_t _reserved;
419			u_int16_t _reserved2;
420			u_int16_t _reserved3;
421			u_int32_t ct_datalen;
422			ispds_t ct_fcp_rsp_iudata;
423		} m2;
424		/*
425		 * CTIO2 returned from F/W...
426		 */
427		struct {
428			u_int32_t _reserved[4];
429			u_int16_t ct_scsi_status;
430			u_int8_t  ct_sense[QLTM_SENSELEN];
431		} fw;
432	} rsp;
433} ct2_entry_t;
434
435/*
436 * ct_flags values for CTIO2
437 */
438#define	CT2_FLAG_MMASK	0x0003
439#define	CT2_FLAG_MODE0	0x0000
440#define	CT2_FLAG_MODE1	0x0001
441#define	CT2_FLAG_MODE2	0x0002
442#define CT2_DATA_IN	CT_DATA_IN
443#define CT2_DATA_OUT	CT_DATA_OUT
444#define CT2_NO_DATA	CT_NO_DATA
445#define CT2_DATAMASK	CT_DATAMASK
446#define	CT2_CCINCR	0x0100
447#define	CT2_FASTPOST	0x0200
448#define CT2_SENDSTATUS	0x8000
449
450/*
451 * ct_status values are (mostly) the same as that for ct_entry.
452 */
453
454/*
455 * ct_scsi_status values- the low 8 bits are the normal SCSI status
456 * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
457 * fields.
458 */
459#define	CT2_RSPLEN_VALID	0x0100
460#define	CT2_SNSLEN_VALID	0x0200
461#define	CT2_DATA_OVER		0x0400
462#define	CT2_DATA_UNDER		0x0800
463
464/*
465 * Macros for packing/unpacking the above structures
466 */
467
468#ifdef	__sparc__
469#define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
470	if (isp->isp_bus == ISP_SBUS) {	\
471		source -> taga =  dest -> tagb;	\
472		source -> tagb =  dest -> taga;	\
473	} else { \
474		source -> taga =  dest -> taga;	\
475		source -> tagb =  dest -> taga;	\
476	}
477#else
478#define	ISP_SBUS_SWOZZLE(isp, src, dest, taga, tagb)	\
479		source -> taga =  dest -> taga;	\
480		source -> tagb =  dest -> taga;
481#endif
482
483#define	MCIDF(d, s)	if ((void *) d != (void *)s) MEMCPY(d, s, QENTRY_LEN)
484
485/* This is really only for SBus cards on a sparc */
486#ifdef	__sparc__
487#define	ISP_SWIZ_ATIO(isp, dest, vsrc)					\
488{									\
489	at_entry_t *source = (at_entry_t *) vsrc;			\
490	at_entry_t local, *vdst;					\
491	if ((void *)dest == (void *)vsrc) {				\
492		MEMCPY(vsrc, &local, sizeof (at_entry_t));		\
493		vdst = &local;						\
494	} else {							\
495		vdst = dest;						\
496	}								\
497	vdst->at_header = source->at_header;				\
498	vdst->at_reserved2 = source->at_reserved2;			\
499	ISP_SBUS_SWOZZLE(isp, source, vdst, at_lun, at_iid);		\
500	ISP_SBUS_SWOZZLE(isp, source, vdst, at_cdblen, at_tgt);		\
501	vdst->at_flags = source->at_flags;				\
502	ISP_SBUS_SWOZZLE(isp, source, vdst, at_status, at_scsi_status);	\
503	ISP_SBUS_SWOZZLE(isp, source, vdst, at_tag_val, at_tag_type);	\
504	MEMCPY(vdst->at_cdb, source->at_cdb, ATIO_CDBLEN);		\
505	MEMCPY(vdst->at_sense, source->at_sense, QLTM_SENSELEN);	\
506}
507
508#define	ISP_SWIZ_CTIO(isp, dest, vsrc)					\
509{									\
510	ct_entry_t *source = (ct_entry_t *) vsrc;			\
511	ct_entry_t *local, *vdst;					\
512	if ((void *)dest == (void *)vsrc) {				\
513		MEMCPY(vsrc, &local, sizeof (ct_entry_t));		\
514		vdst = &local;						\
515	} else {							\
516		vdst = dest;						\
517	}								\
518	vdst->ct_header = source->ct_header;				\
519	vdst->ct_reserved = source->ct_reserved;			\
520	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_lun, ct_iid);		\
521	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_rsvd, ct_tgt);		\
522	vdst->ct_flags = source->ct_flags;				\
523	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_status, ct_scsi_status);	\
524	ISP_SBUS_SWOZZLE(isp, source, vdst, ct_tag_val, ct_tag_type);	\
525	vdst->ct_xfrlen = source->ct_xfrlen;				\
526	vdst->ct_resid = source->ct_resid;				\
527	vdst->ct_timeout = source->ct_timeout;				\
528	vdst->ct_seg_count = source->ct_seg_count;			\
529	MEMCPY(vdst->ct_cdb, source->ct_cdb, ATIO_CDBLEN);		\
530	MEMCPY(vdst->ct_sense, source->ct_sense, QLTM_SENSELEN);	\
531	vdst->ct_dataseg = source->ct_dataseg;				\
532}
533#define	ISP_SWIZ_ENABLE_LUN(isp, dest, vsrc)				\
534{									\
535	lun_entry_t *source = (lun_entry_t *)vsrc;			\
536	lun_entry_t *local, *vdst;					\
537	if ((void *)dest == (void *)vsrc) {				\
538		MEMCPY(vsrc, &local, sizeof (lun_entry_t));		\
539		vdst = &local;						\
540	} else {							\
541		vdst = dest;						\
542	}								\
543	vdst->le_header = source->le_header;				\
544	vdst->le_reserved2 = source->le_reserved2;			\
545	ISP_SBUS_SWOZZLE(isp, source, vdst, le_lun, le_rsvd);		\
546	ISP_SBUS_SWOZZLE(isp, source, vdst, le_ops, le_tgt);		\
547	vdst->le_flags = source->le_flags;				\
548	ISP_SBUS_SWOZZLE(isp, source, vdst, le_status, le_rsvd2);	\
549	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cmd_count, le_in_count);	\
550	ISP_SBUS_SWOZZLE(isp, source, vdst, le_cdb6len, le_cdb7len);	\
551	vdst->le_timeout = source->le_timeout;				\
552	vdst->le_reserved = source->le_reserved;			\
553}
554#define	ISP_SWIZ_NOTIFY(isp, dest, vsrc)				\
555{									\
556	in_entry_type *source = (in_entry_t *)vsrc;			\
557	in_entry_t *local, *vdst;					\
558	if ((void *)dest == (void *)vsrc) {				\
559		MEMCPY(vsrc, &local, sizeof (in_entry_t));		\
560		vdst = &local;						\
561	} else {							\
562		vdst = dest;						\
563	}								\
564	vdst->in_header = source->in_header;				\
565	vdst->in_reserved2 = source->in_reserved2;			\
566	ISP_SBUS_SWOZZLE(isp, source, vdst, in_lun, in_iid);		\
567	ISP_SBUS_SWOZZLE(isp, source, vdst, in_rsvd, in_tgt);		\
568	vdst->in_flags = source->in_flags;				\
569	ISP_SBUS_SWOZZLE(isp, source, vdst, in_status, in_rsvd2);	\
570	ISP_SBUS_SWOZZLE(isp, source, vdst, in_tag_val, in_tag_type);	\
571	vdst->in_seqid = source->in_seqid;				\
572	MEMCPY(vdst->in_msg, source->in_msg, IN_MSGLEN);		\
573	MEMCPY(vdst->in_reserved, source->in_reserved, IN_RESERVED);	\
574	MEMCPY(vdst->in_sense, source->in_sense, QLTM_SENSELEN);	\
575}
576#define	ISP_SWIZ_NOT_ACK(isp, dest)					\
577{									\
578	na_entry_t *source = (na_entry_t *)vsrc;			\
579	na_entry_t *local, *vdst;					\
580	if ((void *)dest == (void *)vsrc) {				\
581		MEMCPY(vsrc, &local, sizeof (na_entry_t));		\
582		vdst = &local;						\
583	} else {							\
584		vdst = dest;						\
585	}								\
586	vdst->na_header = source->na_header;				\
587	vdst->na_reserved2 = source->na_reserved2;			\
588	ISP_SBUS_SWOZZLE(isp, source, vdst, na_lun, na_iid);		\
589	ISP_SBUS_SWOZZLE(isp, source, vdst, na_rsvd, na_tgt);		\
590	vdst->na_flags = source->na_flags;				\
591	ISP_SBUS_SWOZZLE(isp, source, vdst, na_status, na_event);	\
592	vdst->na_seqid = source->na_seqid;				\
593	MEMCPY(vdst->na_reserved, source->na_reserved, NA_RSVDLEN);	\
594}
595#define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
596#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
597#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
598#else
599#define	ISP_SWIZ_ATIO(isp, d, s)	MCIDF(d, s)
600#define	ISP_SWIZ_CTIO(isp, d, s)	MCIDF(d, s)
601#define	ISP_SWIZ_ENABLE_LUN(isp, d, s)	MCIDF(d, s)
602#define	ISP_SWIZ_NOTIFY(isp, d, s)	MCIDF(d, s)
603#define	ISP_SWIZ_NOT_ACK(isp, d, s)	MCIDF(d, s)
604#define	ISP_SWIZ_NOT_ACK_FC(isp, d, s)	MCIDF(d, s)
605#define	ISP_SWIZ_ATIO2(isp, d, s)	MCIDF(d, s)
606#define	ISP_SWIZ_CTIO2(isp, d, s)	MCIDF(d, s)
607#endif
608
609/*
610 * Debug macros
611 */
612
613#define	ISP_TDQE(isp, msg, idx, arg)	\
614    if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
615
616/*
617 * The functions below are target mode functions that
618 * are generally internal to the Qlogic driver.
619 */
620
621/*
622 * This function handles new response queue entry appropriate for target mode.
623 */
624int isp_target_notify __P((struct ispsoftc *, void *, u_int16_t *));
625
626/*
627 * Enable/Disable/Modify a logical unit.
628 */
629#define	DFLT_CMD_CNT	32	/* XX */
630#define	DFLT_INOTIFY	(4)
631int isp_lun_cmd __P((struct ispsoftc *, int, int, int, int, u_int32_t));
632
633/*
634 * General request queue 'put' routine for target mode entries.
635 */
636int isp_target_put_entry __P((struct ispsoftc *isp, void *));
637
638/*
639 * General routine to put back an ATIO entry-
640 * used for replenishing f/w resource counts.
641 */
642int
643isp_target_put_atio __P((struct ispsoftc *, int, int, int, int, int));
644
645/*
646 * General routine to send a final CTIO for a command- used mostly for
647 * local responses.
648 */
649int
650isp_endcmd __P((struct ispsoftc *, void *, u_int32_t, u_int32_t));
651#define	ECMD_SVALID	0x100
652
653/*
654 * Handle an asynchronous event
655 */
656
657void isp_target_async __P((struct ispsoftc *, int, int));
658
659#endif	/* _ISPTARGET_H */
660