xref: /freebsd/sys/dev/isp/isp_target.h (revision f856af0466c076beef4ea9b15d088e1119a945b8)
1 /* $FreeBSD$ */
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  */
44 typedef 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 */
92 typedef 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 
110 typedef 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 
122 typedef 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 /*
159  * ISP24XX Immediate Notify
160  */
161 typedef struct {
162 	isphdr_t	in_header;
163 	uint32_t	in_reserved;
164 	uint16_t	in_nphdl;
165 	uint16_t	in_reserved1;
166 	uint16_t	in_flags;
167 	uint16_t	in_srr_rxid;
168 	uint16_t	in_status;
169 	uint8_t		in_status_subcode;
170 	uint8_t		in_reserved2;
171 	uint32_t	in_rxid;
172 	uint16_t	in_srr_reloff_lo;
173 	uint16_t	in_srr_reloff_hi;
174 	uint16_t	in_srr_iu;
175 	uint16_t	in_srr_oxid;
176 	uint8_t		in_reserved3[18];
177 	uint8_t		in_reserved4;
178 	uint8_t		in_vpindex;
179 	uint32_t	in_reserved5;
180 	uint16_t	in_portid_lo;
181 	uint8_t		in_portid_hi;
182 	uint8_t		in_reserved6;
183 	uint16_t	in_reserved7;
184 	uint16_t	in_oxid;
185 } in_fcentry_24xx_t;
186 
187 #define	IN24XX_FLAG_PUREX_IOCB		0x1
188 #define	IN24XX_FLAG_GLOBAL_LOGOUT	0x2
189 
190 #define	IN24XX_LIP_RESET	0x0E
191 #define	IN24XX_LINK_RESET	0x0F
192 #define	IN24XX_PORT_LOGOUT	0x29
193 #define	IN24XX_PORT_CHANGED	0x2A
194 #define	IN24XX_LINK_FAILED	0x2E
195 #define	IN24XX_SRR_RCVD		0x45
196 #define	IN24XX_ELS_RCVD		0x46	/*
197 					 * login-affectin ELS received- check
198 					 * subcode for specific opcode
199 					 */
200 /*
201  * Notify Acknowledge Entry structure
202  */
203 #define NA_RSVDLEN	22
204 typedef struct {
205 	isphdr_t	na_header;
206 	uint32_t	na_reserved;
207 	uint8_t		na_lun;		/* lun */
208 	uint8_t		na_iid;		/* initiator */
209 	uint8_t		na_reserved2;
210 	uint8_t		na_tgt;		/* target */
211 	uint32_t	na_flags;
212 	uint8_t		na_status;
213 	uint8_t		na_event;
214 	uint16_t	na_seqid;	/* sequence id */
215 	uint16_t	na_reserved3[NA_RSVDLEN];
216 } na_entry_t;
217 
218 /*
219  * Value for the na_event field
220  */
221 #define NA_RST_CLRD	0x80	/* Clear an async event notification */
222 #define	NA_OK		0x01	/* Notify Acknowledge Succeeded */
223 #define	NA_INVALID	0x06	/* Invalid Notify Acknowledge */
224 
225 #define	NA2_RSVDLEN	21
226 typedef struct {
227 	isphdr_t	na_header;
228 	uint32_t	na_reserved;
229 	uint8_t		na_reserved1;
230 	uint8_t		na_iid;		/* initiator loop id */
231 	uint16_t	na_response;
232 	uint16_t	na_flags;
233 	uint16_t	na_reserved2;
234 	uint16_t	na_status;
235 	uint16_t	na_task_flags;
236 	uint16_t	na_seqid;	/* sequence id */
237 	uint16_t	na_reserved3[NA2_RSVDLEN];
238 } na_fcentry_t;
239 
240 typedef struct {
241 	isphdr_t	na_header;
242 	uint32_t	na_reserved;
243 	uint16_t	na_iid;		/* initiator loop id */
244 	uint16_t	na_response;	/* response code */
245 	uint16_t	na_flags;
246 	uint16_t	na_reserved2;
247 	uint16_t	na_status;
248 	uint16_t	na_task_flags;
249 	uint16_t	na_seqid;	/* sequence id */
250 	uint16_t	na_reserved3[NA2_RSVDLEN];
251 } na_fcentry_e_t;
252 
253 #define	NAFC_RCOUNT	0x80	/* increment resource count */
254 #define NAFC_RST_CLRD	0x20	/* Clear LIP Reset */
255 #define	NAFC_TVALID	0x10	/* task mangement response code is valid */
256 
257 /*
258  * ISP24XX Notify Acknowledge
259  */
260 
261 typedef struct {
262 	isphdr_t	na_header;
263 	uint32_t	na_handle;
264 	uint16_t	na_nphdl;
265 	uint16_t	na_reserved1;
266 	uint16_t	na_flags;
267 	uint16_t	na_srr_rxid;
268 	uint16_t	na_status;
269 	uint8_t		na_status_subcode;
270 	uint8_t		na_reserved2;
271 	uint32_t	na_rxid;
272 	uint16_t	na_srr_reloff_lo;
273 	uint16_t	na_srr_reloff_hi;
274 	uint16_t	na_srr_iu;
275 	uint16_t	na_srr_flags;
276 	uint8_t		na_reserved3[18];
277 	uint8_t		na_reserved4;
278 	uint8_t		na_vpindex;
279 	uint8_t		na_srr_reject_vunique;
280 	uint8_t		na_srr_reject_explanation;
281 	uint8_t		na_srr_reject_code;
282 	uint8_t		na_reserved5;
283 	uint8_t		na_reserved6[6];
284 	uint16_t	na_oxid;
285 } na_fcentry_24xx_t;
286 
287 /*
288  * Accept Target I/O Entry structure
289  */
290 #define ATIO_CDBLEN	26
291 
292 typedef struct {
293 	isphdr_t	at_header;
294 	uint16_t	at_reserved;
295 	uint16_t	at_handle;
296 	uint8_t		at_lun;		/* lun */
297 	uint8_t		at_iid;		/* initiator */
298 	uint8_t		at_cdblen; 	/* cdb length */
299 	uint8_t		at_tgt;		/* target */
300 	uint32_t	at_flags;
301 	uint8_t		at_status;	/* firmware status */
302 	uint8_t		at_scsi_status;	/* scsi status */
303 	uint8_t		at_tag_val;	/* tag value */
304 	uint8_t		at_tag_type;	/* tag type */
305 	uint8_t		at_cdb[ATIO_CDBLEN];	/* received CDB */
306 	uint8_t		at_sense[QLTM_SENSELEN];/* suggested sense data */
307 } at_entry_t;
308 
309 /*
310  * at_flags values
311  */
312 #define AT_NODISC	0x00008000	/* disconnect disabled */
313 #define AT_TQAE		0x00000002	/* Tagged Queue Action enabled */
314 
315 /*
316  * at_status values
317  */
318 #define AT_PATH_INVALID	0x07	/* ATIO sent to firmware for disabled lun */
319 #define	AT_RESET	0x0E	/* SCSI Bus Reset Occurred */
320 #define AT_PHASE_ERROR	0x14	/* Bus phase sequence error */
321 #define AT_NOCAP	0x16	/* Requested capability not available */
322 #define AT_BDR_MSG	0x17	/* Bus Device Reset msg received */
323 #define AT_CDB		0x3D	/* CDB received */
324 /*
325  * Macros to create and fetch and test concatenated handle and tag value macros
326  */
327 
328 #define	AT_MAKE_TAGID(tid, inst, aep)					\
329 	tid = aep->at_handle;						\
330 	if (aep->at_flags & AT_TQAE) {					\
331 		tid |= (aep->at_tag_val << 16);				\
332 		tid |= (1 << 24);					\
333 	}								\
334 	tid |= (GET_BUS_VAL(aep->at_iid) << 25);			\
335 	tid |= (inst << 26)
336 
337 #define	CT_MAKE_TAGID(tid, bus, inst, ct)				\
338 	tid = ct->ct_fwhandle;						\
339 	if (ct->ct_flags & CT_TQAE) {					\
340 		tid |= (ct->ct_tag_val << 16);				\
341 		tid |= (1 << 24);					\
342 	}								\
343 	tid |= ((bus & 0x1) << 25);					\
344 	tid |= (inst << 26)
345 
346 #define	AT_HAS_TAG(val)		((val) & (1 << 24))
347 #define	AT_GET_TAG(val)		(((val) >> 16) & 0xff)
348 #define	AT_GET_INST(val)	(((val) >> 26) & 0x3f)
349 #define	AT_GET_BUS(val)		(((val) >> 25) & 0x1)
350 #define	AT_GET_HANDLE(val)	((val) & 0xffff)
351 
352 #define	IN_MAKE_TAGID(tid, inst, inp)					\
353 	tid = inp->in_seqid;						\
354 	tid |= (inp->in_tag_val << 16);					\
355 	tid |= (1 << 24);						\
356 	tid |= (GET_BUS_VAL(inp->in_iid) << 25);			\
357 	tid |= (inst << 26)
358 
359 #define	TAG_INSERT_INST(tid, inst)					\
360 	tid &= ~(0x3ffffff);						\
361 	tid |= (inst << 26)
362 
363 #define	TAG_INSERT_BUS(tid, bus)					\
364 	tid &= ~(1 << 25);						\
365 	tid |= (bus << 25)
366 
367 /*
368  * Accept Target I/O Entry structure, Type 2
369  */
370 #define ATIO2_CDBLEN	16
371 
372 typedef struct {
373 	isphdr_t	at_header;
374 	uint32_t	at_reserved;
375 	uint8_t		at_lun;		/* lun or reserved */
376 	uint8_t		at_iid;		/* initiator */
377 	uint16_t	at_rxid; 	/* response ID */
378 	uint16_t	at_flags;
379 	uint16_t	at_status;	/* firmware status */
380 	uint8_t		at_crn;		/* command reference number */
381 	uint8_t		at_taskcodes;
382 	uint8_t		at_taskflags;
383 	uint8_t		at_execodes;
384 	uint8_t		at_cdb[ATIO2_CDBLEN];	/* received CDB */
385 	uint32_t	at_datalen;		/* allocated data len */
386 	uint16_t	at_scclun;		/* SCC Lun or reserved */
387 	uint16_t	at_wwpn[4];		/* WWPN of initiator */
388 	uint16_t	at_reserved2[6];
389 	uint16_t	at_oxid;
390 } at2_entry_t;
391 
392 typedef struct {
393 	isphdr_t	at_header;
394 	uint32_t	at_reserved;
395 	uint16_t	at_iid;		/* initiator */
396 	uint16_t	at_rxid; 	/* response ID */
397 	uint16_t	at_flags;
398 	uint16_t	at_status;	/* firmware status */
399 	uint8_t		at_crn;		/* command reference number */
400 	uint8_t		at_taskcodes;
401 	uint8_t		at_taskflags;
402 	uint8_t		at_execodes;
403 	uint8_t		at_cdb[ATIO2_CDBLEN];	/* received CDB */
404 	uint32_t	at_datalen;		/* allocated data len */
405 	uint16_t	at_scclun;		/* SCC Lun or reserved */
406 	uint16_t	at_wwpn[4];		/* WWPN of initiator */
407 	uint16_t	at_reserved2[6];
408 	uint16_t	at_oxid;
409 } at2e_entry_t;
410 
411 #define	ATIO2_WWPN_OFFSET	0x2A
412 #define	ATIO2_OXID_OFFSET	0x3E
413 
414 #define	ATIO2_TC_ATTR_MASK	0x7
415 #define	ATIO2_TC_ATTR_SIMPLEQ	0
416 #define	ATIO2_TC_ATTR_HEADOFQ	1
417 #define	ATIO2_TC_ATTR_ORDERED	2
418 #define	ATIO2_TC_ATTR_ACAQ	4
419 #define	ATIO2_TC_ATTR_UNTAGGED	5
420 
421 #define	ATIO2_EX_WRITE		0x1
422 #define	ATIO2_EX_READ		0x2
423 /*
424  * Macros to create and fetch and test concatenated handle and tag value macros
425  */
426 #define	AT2_MAKE_TAGID(tid, inst, aep)					\
427 	tid = aep->at_rxid;						\
428 	tid |= (inst << 16)
429 
430 #define	CT2_MAKE_TAGID(tid, inst, ct)					\
431 	tid = ct->ct_rxid;						\
432 	tid |= (inst << 16)
433 
434 #define	AT2_HAS_TAG(val)	1
435 #define	AT2_GET_TAG(val)	((val) & 0xffff)
436 #define	AT2_GET_INST(val)	((val) >> 16)
437 #define	AT2_GET_HANDLE		AT2_GET_TAG
438 
439 #define	FC_HAS_TAG	AT2_HAS_TAG
440 #define	FC_GET_TAG	AT2_GET_TAG
441 #define	FC_GET_INST	AT2_GET_INST
442 #define	FC_GET_HANDLE	AT2_GET_HANDLE
443 
444 #define	IN_FC_MAKE_TAGID(tid, inst, seqid)				\
445 	tid = seqid;							\
446 	tid |= (inst << 16)
447 
448 #define	FC_TAG_INSERT_INST(tid, inst)					\
449 	tid &= ~0xffff;							\
450 	tid |= (inst << 16)
451 
452 /*
453  * 24XX ATIO Definition
454  *
455  * This is *quite* different from other entry types.
456  * First of all, it has its own queue it comes in on.
457  *
458  * Secondly, it doesn't have a normal header.
459  *
460  * Thirdly, it's just a passthru of the FCP CMND IU
461  * which is recorded in big endian mode.
462  */
463 typedef struct {
464 	uint8_t		at_type;
465 	uint8_t		at_count;
466 	/*
467 	 * Task attribute in high four bits,
468 	 * the rest is the FCP CMND IU Length.
469 	 * NB: the command can extend past the
470 	 * length for a single queue entry.
471 	 */
472 	uint16_t	at_ta_len;
473 	uint32_t	at_rxid;
474 	fc_hdr_t	at_hdr;
475 	fcp_cmnd_iu_t	at_cmnd;
476 } at7_entry_t;
477 
478 
479 /*
480  * Continue Target I/O Entry structure
481  * Request from driver. The response from the
482  * ISP firmware is the same except that the last 18
483  * bytes are overwritten by suggested sense data if
484  * the 'autosense valid' bit is set in the status byte.
485  */
486 typedef struct {
487 	isphdr_t	ct_header;
488 	uint16_t	ct_syshandle;
489 	uint16_t	ct_fwhandle;	/* required by f/w */
490 	uint8_t		ct_lun;	/* lun */
491 	uint8_t		ct_iid;	/* initiator id */
492 	uint8_t		ct_reserved2;
493 	uint8_t		ct_tgt;	/* our target id */
494 	uint32_t	ct_flags;
495 	uint8_t 	ct_status;	/* isp status */
496 	uint8_t 	ct_scsi_status;	/* scsi status */
497 	uint8_t 	ct_tag_val;	/* tag value */
498 	uint8_t 	ct_tag_type;	/* tag type */
499 	uint32_t	ct_xfrlen;	/* transfer length */
500 	uint32_t	ct_resid;	/* residual length */
501 	uint16_t	ct_timeout;
502 	uint16_t	ct_seg_count;
503 	ispds_t		ct_dataseg[ISP_RQDSEG];
504 } ct_entry_t;
505 
506 /*
507  * For some of the dual port SCSI adapters, port (bus #) is reported
508  * in the MSbit of ct_iid. Bit fields are a bit too awkward here.
509  *
510  * Note that this does not apply to FC adapters at all which can and
511  * do report IIDs between 0x81 && 0xfe (or 0x7ff) which represent devices
512  * that have logged in across a SCSI fabric.
513  */
514 #define	GET_IID_VAL(x)		(x & 0x3f)
515 #define	GET_BUS_VAL(x)		((x >> 7) & 0x1)
516 #define	SET_IID_VAL(y, x)	y = ((y & ~0x3f) | (x & 0x3f))
517 #define	SET_BUS_VAL(y, x)	y = ((y & 0x3f) | ((x & 0x1) << 7))
518 
519 /*
520  * ct_flags values
521  */
522 #define CT_TQAE		0x00000002	/* bit  1, Tagged Queue Action enable */
523 #define CT_DATA_IN	0x00000040	/* bits 6&7, Data direction */
524 #define CT_DATA_OUT	0x00000080	/* bits 6&7, Data direction */
525 #define CT_NO_DATA	0x000000C0	/* bits 6&7, Data direction */
526 #define	CT_CCINCR	0x00000100	/* bit 8, autoincrement atio count */
527 #define CT_DATAMASK	0x000000C0	/* bits 6&7, Data direction */
528 #define	CT_INISYNCWIDE	0x00004000	/* bit 14, Do Sync/Wide Negotiation */
529 #define CT_NODISC	0x00008000	/* bit 15, Disconnects disabled */
530 #define CT_DSDP		0x01000000	/* bit 24, Disable Save Data Pointers */
531 #define CT_SENDRDP	0x04000000	/* bit 26, Send Restore Pointers msg */
532 #define CT_SENDSTATUS	0x80000000	/* bit 31, Send SCSI status byte */
533 
534 /*
535  * ct_status values
536  * - set by the firmware when it returns the CTIO
537  */
538 #define CT_OK		0x01	/* completed without error */
539 #define CT_ABORTED	0x02	/* aborted by host */
540 #define CT_ERR		0x04	/* see sense data for error */
541 #define CT_INVAL	0x06	/* request for disabled lun */
542 #define CT_NOPATH	0x07	/* invalid ITL nexus */
543 #define	CT_INVRXID	0x08	/* (FC only) Invalid RX_ID */
544 #define	CT_DATA_OVER	0x09	/* (FC only) Data Overrun */
545 #define CT_RSELTMO	0x0A	/* reselection timeout after 2 tries */
546 #define CT_TIMEOUT	0x0B	/* timed out */
547 #define CT_RESET	0x0E	/* SCSI Bus Reset occurred */
548 #define	CT_PARITY	0x0F	/* Uncorrectable Parity Error */
549 #define	CT_BUS_ERROR	0x10	/* (FC Only) DMA PCI Error */
550 #define	CT_PANIC	0x13	/* Unrecoverable Error */
551 #define CT_PHASE_ERROR	0x14	/* Bus phase sequence error */
552 #define	CT_DATA_UNDER	0x15	/* (FC only) Data Underrun */
553 #define CT_BDR_MSG	0x17	/* Bus Device Reset msg received */
554 #define CT_TERMINATED	0x19	/* due to Terminate Transfer mbox cmd */
555 #define	CT_PORTUNAVAIL	0x28	/* port not available */
556 #define	CT_LOGOUT	0x29	/* port logout */
557 #define	CT_PORTCHANGED	0x2A	/* port changed */
558 #define	CT_IDE		0x33	/* Initiator Detected Error */
559 #define CT_NOACK	0x35	/* Outstanding Immed. Notify. entry */
560 #define	CT_SRR		0x45	/* SRR Received */
561 #define	CT_LUN_RESET	0x48	/* Lun Reset Received */
562 
563 /*
564  * When the firmware returns a CTIO entry, it may overwrite the last
565  * part of the structure with sense data. This starts at offset 0x2E
566  * into the entry, which is in the middle of ct_dataseg[1]. Rather
567  * than define a new struct for this, I'm just using the sense data
568  * offset.
569  */
570 #define CTIO_SENSE_OFFSET	0x2E
571 
572 /*
573  * Entry length in u_longs. All entries are the same size so
574  * any one will do as the numerator.
575  */
576 #define UINT32_ENTRY_SIZE	(sizeof(at_entry_t)/sizeof(uint32_t))
577 
578 /*
579  * QLA2100 CTIO (type 2) entry
580  */
581 #define	MAXRESPLEN	26
582 typedef struct {
583 	isphdr_t	ct_header;
584 	uint32_t	ct_syshandle;
585 	uint8_t		ct_lun;		/* lun */
586 	uint8_t		ct_iid;		/* initiator id */
587 	uint16_t	ct_rxid;	/* response ID */
588 	uint16_t	ct_flags;
589 	uint16_t 	ct_status;	/* isp status */
590 	uint16_t	ct_timeout;
591 	uint16_t	ct_seg_count;
592 	uint32_t	ct_reloff;	/* relative offset */
593 	int32_t		ct_resid;	/* residual length */
594 	union {
595 		/*
596 		 * The three different modes that the target driver
597 		 * can set the CTIO{2,3,4} up as.
598 		 *
599 		 * The first is for sending FCP_DATA_IUs as well as
600 		 * (optionally) sending a terminal SCSI status FCP_RSP_IU.
601 		 *
602 		 * The second is for sending SCSI sense data in an FCP_RSP_IU.
603 		 * Note that no FCP_DATA_IUs will be sent.
604 		 *
605 		 * The third is for sending FCP_RSP_IUs as built specifically
606 		 * in system memory as located by the isp_dataseg.
607 		 */
608 		struct {
609 			uint32_t _reserved;
610 			uint16_t _reserved2;
611 			uint16_t ct_scsi_status;
612 			uint32_t ct_xfrlen;
613 			union {
614 				ispds_t ct_dataseg[ISP_RQDSEG_T2];
615 				ispds64_t ct_dataseg64[ISP_RQDSEG_T3];
616 				ispdslist_t ct_dslist;
617 			} u;
618 		} m0;
619 		struct {
620 			uint16_t _reserved;
621 			uint16_t _reserved2;
622 			uint16_t ct_senselen;
623 			uint16_t ct_scsi_status;
624 			uint16_t ct_resplen;
625 			uint8_t  ct_resp[MAXRESPLEN];
626 		} m1;
627 		struct {
628 			uint32_t _reserved;
629 			uint16_t _reserved2;
630 			uint16_t _reserved3;
631 			uint32_t ct_datalen;
632 			ispds_t ct_fcp_rsp_iudata;
633 		} m2;
634 	} rsp;
635 } ct2_entry_t;
636 
637 typedef struct {
638 	isphdr_t	ct_header;
639 	uint32_t	ct_syshandle;
640 	uint16_t	ct_iid;		/* initiator id */
641 	uint16_t	ct_rxid;	/* response ID */
642 	uint16_t	ct_flags;
643 	uint16_t 	ct_status;	/* isp status */
644 	uint16_t	ct_timeout;
645 	uint16_t	ct_seg_count;
646 	uint32_t	ct_reloff;	/* relative offset */
647 	int32_t		ct_resid;	/* residual length */
648 	union {
649 		struct {
650 			uint32_t _reserved;
651 			uint16_t _reserved2;
652 			uint16_t ct_scsi_status;
653 			uint32_t ct_xfrlen;
654 			union {
655 				ispds_t ct_dataseg[ISP_RQDSEG_T2];
656 				ispds64_t ct_dataseg64[ISP_RQDSEG_T3];
657 				ispdslist_t ct_dslist;
658 			} u;
659 		} m0;
660 		struct {
661 			uint16_t _reserved;
662 			uint16_t _reserved2;
663 			uint16_t ct_senselen;
664 			uint16_t ct_scsi_status;
665 			uint16_t ct_resplen;
666 			uint8_t  ct_resp[MAXRESPLEN];
667 		} m1;
668 		struct {
669 			uint32_t _reserved;
670 			uint16_t _reserved2;
671 			uint16_t _reserved3;
672 			uint32_t ct_datalen;
673 			ispds_t ct_fcp_rsp_iudata;
674 		} m2;
675 	} rsp;
676 } ct2e_entry_t;
677 
678 /*
679  * ct_flags values for CTIO2
680  */
681 #define	CT2_FLAG_MODE0	0x0000
682 #define	CT2_FLAG_MODE1	0x0001
683 #define	CT2_FLAG_MODE2	0x0002
684 #define		CT2_FLAG_MMASK	0x0003
685 #define CT2_DATA_IN	0x0040
686 #define CT2_DATA_OUT	0x0080
687 #define CT2_NO_DATA	0x00C0
688 #define 	CT2_DATAMASK	0x00C0
689 #define	CT2_CCINCR	0x0100
690 #define	CT2_FASTPOST	0x0200
691 #define	CT2_CONFIRM	0x2000
692 #define	CT2_TERMINATE	0x4000
693 #define CT2_SENDSTATUS	0x8000
694 
695 /*
696  * ct_status values are (mostly) the same as that for ct_entry.
697  */
698 
699 /*
700  * ct_scsi_status values- the low 8 bits are the normal SCSI status
701  * we know and love. The upper 8 bits are validity markers for FCP_RSP_IU
702  * fields.
703  */
704 #define	CT2_RSPLEN_VALID	0x0100
705 #define	CT2_SNSLEN_VALID	0x0200
706 #define	CT2_DATA_OVER		0x0400
707 #define	CT2_DATA_UNDER		0x0800
708 
709 /*
710  * ISP24XX CTIO
711  */
712 #define	MAXRESPLEN_24XX	24
713 typedef struct {
714 	isphdr_t	ct_header;
715 	uint32_t	ct_syshandle;
716 	uint16_t	ct_nphdl;	/* status on returned CTIOs */
717 	uint16_t	ct_timeout;
718 	uint16_t	ct_seg_count;
719 	uint8_t		ct_vpindex;
720 	uint8_t		ct_xflags;
721 	uint16_t	ct_iid_lo;	/* low 16 bits of portid */
722 	uint8_t		ct_iid_hi;	/* hi 8 bits of portid */
723 	uint8_t		ct_reserved;
724 	uint32_t	ct_rxid;
725 	uint16_t	ct_senselen;	/* mode 0 only */
726 	uint16_t	ct_flags;
727 	int32_t		ct_resid;	/* residual length */
728 	uint16_t	ct_oxid;
729 	uint16_t	ct_scsi_status;	/* modes 0 && 1 only */
730 	union {
731 		struct {
732 			uint32_t	reloff;
733 			uint32_t	reserved0;
734 			uint32_t	ct_xfrlen;
735 			uint32_t	reserved1;
736 			ispds64_t	ds;
737 		} m0;
738 		struct {
739 			uint16_t ct_resplen;
740 			uint16_t reserved;
741 			uint8_t  ct_resp[MAXRESPLEN_24XX];
742 		} m1;
743 		struct {
744 			uint32_t reserved0;
745 			uint32_t ct_datalen;
746 			uint32_t reserved1;
747 			ispds64_t ct_fcp_rsp_iudata;
748 		} m2;
749 	} rsp;
750 } ct7_entry_t;
751 
752 /*
753  * ct_flags values for CTIO7
754  */
755 #define CT7_DATA_IN	0x0002
756 #define CT7_DATA_OUT	0x0001
757 #define CT7_NO_DATA	0x0000
758 #define 	CT7_DATAMASK	0x003
759 #define	CT7_DSD_ENABLE	0x0004
760 #define	CT7_CONF_STSFD	0x0010
761 #define	CT7_EXPLCT_CONF	0x0020
762 #define	CT7_FLAG_MODE0	0x0000
763 #define	CT7_FLAG_MODE1	0x0040
764 #define	CT7_FLAG_MODE7	0x0080
765 #define		CT7_FLAG_MMASK	0x00C0
766 #define	CT7_FASTPOST	0x0100
767 #define	CT7_ATTR_MASK	0x1e00	/* task attributes from atio7 */
768 #define	CT7_CONFIRM	0x2000
769 #define	CT7_TERMINATE	0x4000
770 #define CT7_SENDSTATUS	0x8000
771 
772 /*
773  * Type 7 CTIO status codes
774  */
775 #define CT7_OK		0x01	/* completed without error */
776 #define CT7_ABORTED	0x02	/* aborted by host */
777 #define CT7_ERR		0x04	/* see sense data for error */
778 #define CT7_INVAL	0x06	/* request for disabled lun */
779 #define	CT7_INVRXID	0x08	/* (FC only) Invalid RX_ID */
780 #define	CT7_DATA_OVER	0x09	/* (FC only) Data Overrun */
781 #define CT7_TIMEOUT	0x0B	/* timed out */
782 #define CT7_RESET	0x0E	/* LIP Rset Received */
783 #define	CT7_BUS_ERROR	0x10	/* DMA PCI Error */
784 #define	CT7_REASSY_ERR	0x11	/* DMA reassembly error */
785 #define	CT7_DATA_UNDER	0x15	/* (FC only) Data Underrun */
786 #define	CT7_PORTUNAVAIL	0x28	/* port not available */
787 #define	CT7_LOGOUT	0x29	/* port logout */
788 #define	CT7_PORTCHANGED	0x2A	/* port changed */
789 #define	CT7_SRR		0x45	/* SRR Received */
790 
791 /*
792  * Other 24XX related target IOCBs
793  */
794 
795 /*
796  * ABTS Received
797  */
798 typedef struct {
799 	isphdr_t	abts_header;
800 	uint8_t		abts_reserved0[6];
801 	uint16_t	abts_nphdl;
802 	uint16_t	abts_reserved1;
803 	uint16_t	abts_sof;
804 	uint32_t	abts_rxid_abts;
805 	uint16_t	abts_did_lo;
806 	uint8_t		abts_did_hi;
807 	uint8_t		abts_r_ctl;
808 	uint16_t	abts_sid_lo;
809 	uint8_t		abts_sid_hi;
810 	uint8_t		abts_cs_ctl;
811 	uint16_t	abts_fs_ctl;
812 	uint8_t		abts_f_ctl;
813 	uint8_t		abts_type;
814 	uint16_t	abts_seq_cnt;
815 	uint8_t		abts_df_ctl;
816 	uint8_t		abts_seq_id;
817 	uint16_t	abts_rx_id;
818 	uint16_t	abts_ox_id;
819 	uint32_t	abts_param;
820 	uint8_t		abts_reserved2[16];
821 	uint32_t	abts_rxid_task;
822 } abts_t;
823 
824 typedef struct {
825 	isphdr_t	abts_rsp_header;
826 	uint32_t	abts_rsp_handle;
827 	uint16_t	abts_rsp_status;
828 	uint16_t	abts_rsp_nphdl;
829 	uint16_t	abts_rsp_ctl_flags;
830 	uint16_t	abts_rsp_sof;
831 	uint32_t	abts_rsp_rxid_abts;
832 	uint16_t	abts_rsp_did_lo;
833 	uint8_t		abts_rsp_did_hi;
834 	uint8_t		abts_rsp_r_ctl;
835 	uint16_t	abts_rsp_sid_lo;
836 	uint8_t		abts_rsp_sid_hi;
837 	uint8_t		abts_rsp_cs_ctl;
838 	uint16_t	abts_rsp_f_ctl_lo;
839 	uint8_t		abts_rsp_f_ctl_hi;
840 	uint8_t		abts_rsp_type;
841 	uint16_t	abts_rsp_seq_cnt;
842 	uint8_t		abts_rsp_df_ctl;
843 	uint8_t		abts_rsp_seq_id;
844 	uint16_t	abts_rsp_rx_id;
845 	uint16_t	abts_rsp_ox_id;
846 	uint32_t	abts_rsp_param;
847 	union {
848 		struct {
849 			uint16_t reserved;
850 			uint8_t	last_seq_id;
851 			uint8_t seq_id_valid;
852 			uint16_t aborted_rx_id;
853 			uint16_t aborted_ox_id;
854 			uint16_t high_seq_cnt;
855 			uint16_t low_seq_cnt;
856 			uint8_t reserved2[4];
857 		} ba_acc;
858 		struct {
859 			uint8_t vendor_unique;
860 			uint8_t	explanation;
861 			uint8_t reason;
862 			uint8_t reserved;
863 			uint8_t reserved2[12];
864 		} ba_rjt;
865 		struct {
866 			uint8_t reserved[8];
867 			uint32_t subcode1;
868 			uint32_t subcode2;
869 		} rsp;
870 		uint8_t reserved[16];
871 	} abts_rsp_payload;
872 	uint32_t	abts_rsp_rxid_task;
873 } abts_rsp_t;
874 
875 /* terminate this ABTS exchange */
876 #define	ISP24XX_ABTS_RSP_TERMINATE	0x01
877 
878 #define	ISP24XX_ABTS_RSP_COMPLETE	0x00
879 #define	ISP24XX_ABTS_RSP_RESET		0x04
880 #define	ISP24XX_ABTS_RSP_ABORTED	0x05
881 #define	ISP24XX_ABTS_RSP_TIMEOUT	0x06
882 #define	ISP24XX_ABTS_RSP_INVXID		0x08
883 #define	ISP24XX_ABTS_RSP_LOGOUT		0x29
884 #define	ISP24XX_ABTS_RSP_SUBCODE	0x31
885 
886 /*
887  * Debug macros
888  */
889 
890 #define	ISP_TDQE(isp, msg, idx, arg)	\
891     if (isp->isp_dblev & ISP_LOGTDEBUG2) isp_print_qentry(isp, msg, idx, arg)
892 
893 #ifndef	ISP_TOOLS
894 /*
895  * The functions below are for the publicly available
896  * target mode functions that are internal to the Qlogic driver.
897  */
898 
899 /*
900  * This function handles new response queue entry appropriate for target mode.
901  */
902 int isp_target_notify(ispsoftc_t *, void *, uint32_t *);
903 
904 /*
905  * This function externalizes the ability to acknowledge an Immediate Notify
906  * request.
907  */
908 void isp_notify_ack(ispsoftc_t *, void *);
909 
910 /*
911  * Enable/Disable/Modify a logical unit.
912  * (softc, cmd, bus, tgt, lun, cmd_cnt, inotify_cnt, opaque)
913  */
914 #define	DFLT_CMND_CNT	0xfe	/* unmonitored */
915 #define	DFLT_INOT_CNT	0xfe	/* unmonitored */
916 int isp_lun_cmd(ispsoftc_t *, int, int, int, int, int, int, uint32_t);
917 
918 /*
919  * General request queue 'put' routine for target mode entries.
920  */
921 int isp_target_put_entry(ispsoftc_t *isp, void *);
922 
923 /*
924  * General routine to put back an ATIO entry-
925  * used for replenishing f/w resource counts.
926  * The argument is a pointer to a source ATIO
927  * or ATIO2.
928  */
929 int isp_target_put_atio(ispsoftc_t *, void *);
930 
931 /*
932  * General routine to send a final CTIO for a command- used mostly for
933  * local responses.
934  */
935 int isp_endcmd(ispsoftc_t *, void *, uint32_t, uint32_t);
936 #define	ECMD_SVALID	0x100
937 
938 /*
939  * Handle an asynchronous event
940  *
941  * Return nonzero if the interrupt that generated this event has been dismissed.
942  */
943 int isp_target_async(ispsoftc_t *, int, int);
944 #endif
945 #endif	/* _ISP_TARGET_H */
946