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