ispvar.h revision 1.10 1 /* $NetBSD: ispvar.h,v 1.10 1998/07/18 21:06:20 mjacob Exp $ */
2 /* $Id: ispvar.h,v 1.10 1998/07/18 21:06:20 mjacob Exp $ */
3 /*
4 * Soft Definitions for for Qlogic ISP SCSI adapters.
5 *
6 *---------------------------------------
7 * Copyright (c) 1997, 1998 by Matthew Jacob
8 * NASA/Ames Research Center
9 * All rights reserved.
10 *---------------------------------------
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice immediately at the beginning of the file, without modification,
16 * this list of conditions, and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
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
37 #ifndef _ISPVAR_H
38 #define _ISPVAR_H
39
40 #ifdef __NetBSD__
41 #include <dev/ic/ispmbox.h>
42 #endif
43 #ifdef __FreeBSD__
44 #include <dev/isp/ispmbox.h>
45 #endif
46 #ifdef __linux__
47 #include <ispmbox.h>
48 #endif
49
50 #define ISP_CORE_VERSION_MAJOR 1
51 #define ISP_CORE_VERSION_MINOR 1
52
53 /*
54 * Vector for MD code to provide specific services.
55 */
56 struct ispsoftc;
57 struct ispmdvec {
58 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int));
59 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
60 int (*dv_mbxdma) __P((struct ispsoftc *));
61 int (*dv_dmaset) __P((struct ispsoftc *,
62 ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
63 void (*dv_dmaclr)
64 __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
65 void (*dv_reset0) __P((struct ispsoftc *));
66 void (*dv_reset1) __P((struct ispsoftc *));
67 void (*dv_dregs) __P((struct ispsoftc *));
68 const u_int16_t *dv_ispfw; /* ptr to f/w */
69 u_int16_t dv_fwlen; /* length of f/w */
70 u_int16_t dv_codeorg; /* code ORG for f/w */
71 u_int16_t dv_fwrev; /* f/w revision */
72 /*
73 * Initial values for conf1 register
74 */
75 u_int16_t dv_conf1;
76 u_int16_t dv_clock; /* clock frequency */
77 };
78
79 #define MAX_TARGETS 16
80 #define MAX_LUNS 8
81 #define MAX_FC_TARG 126
82
83 #define RQUEST_QUEUE_LEN MAXISPREQUEST
84 #define RESULT_QUEUE_LEN (MAXISPREQUEST/4)
85
86 #define QENTRY_LEN 64
87
88 #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN))
89 #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN)
90
91 /*
92 * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
93 */
94
95 typedef struct {
96 u_int isp_adapter_enabled : 1,
97 isp_req_ack_active_neg : 1,
98 isp_data_line_active_neg: 1,
99 isp_cmd_dma_burst_enable: 1,
100 isp_data_dma_burst_enabl: 1,
101 isp_fifo_threshold : 2,
102 isp_diffmode : 1,
103 isp_initiator_id : 4,
104 isp_async_data_setup : 4;
105 u_int16_t isp_selection_timeout;
106 u_int16_t isp_max_queue_depth;
107 u_int16_t isp_clock;
108 u_int8_t isp_tag_aging;
109 u_int8_t isp_bus_reset_delay;
110 u_int8_t isp_retry_count;
111 u_int8_t isp_retry_delay;
112 struct {
113 u_int dev_flags : 8, /* Device Flags - see below */
114 exc_throttle : 8,
115 sync_period : 8,
116 sync_offset : 4,
117 dev_enable : 1;
118 } isp_devparam[MAX_TARGETS];
119 } sdparam; /* scsi device parameters */
120
121 /*
122 * Device Flags
123 */
124 #define DPARM_DISC 0x80
125 #define DPARM_PARITY 0x40
126 #define DPARM_WIDE 0x20
127 #define DPARM_SYNC 0x10
128 #define DPARM_TQING 0x08
129 #define DPARM_ARQ 0x04
130 #define DPARM_QFRZ 0x02
131 #define DPARM_RENEG 0x01
132 #define DPARM_DEFAULT (0xff & ~DPARM_QFRZ)
133
134 #define ISP_20M_SYNCPARMS 0x080c
135 #define ISP_10M_SYNCPARMS 0x0c19
136 #define ISP_08M_SYNCPARMS 0x0c25
137 #define ISP_05M_SYNCPARMS 0x0c32
138 #define ISP_04M_SYNCPARMS 0x0c41
139
140 /*
141 * Fibre Channel Specifics
142 */
143 typedef struct {
144 #if 0
145 /*
146 * Not gathered yet.
147 */
148 u_int64_t isp_wwn; /* WWN of adapter */
149 #endif
150 u_int8_t isp_loopid; /* FCAL of this adapter inst */
151 u_int8_t isp_retry_count;
152 u_int8_t isp_retry_delay;
153 u_int8_t isp_fwstate; /* ISP F/W state */
154
155 /*
156 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
157 */
158 volatile caddr_t isp_scratch;
159 u_int32_t isp_scdma;
160 } fcparam;
161
162 #define ISP2100_SCRLEN 0x100
163
164 #define FW_CONFIG_WAIT 0x0000
165 #define FW_WAIT_AL_PA 0x0001
166 #define FW_WAIT_LOGIN 0x0002
167 #define FW_READY 0x0003
168 #define FW_LOSS_OF_SYNC 0x0004
169 #define FW_ERROR 0x0005
170 #define FW_REINIT 0x0006
171 #define FW_NON_PART 0x0007
172
173 static __inline char *fw_statename __P((u_int8_t x));
174 static __inline char *
175 fw_statename(x)
176 u_int8_t x;
177 {
178 switch(x) {
179 case FW_CONFIG_WAIT: return "Config Wait";
180 case FW_WAIT_AL_PA: return "Waiting for AL/PA";
181 case FW_WAIT_LOGIN: return "Wait Login";
182 case FW_READY: return "Ready";
183 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
184 case FW_ERROR: return "Error";
185 case FW_REINIT: return "Re-Init";
186 case FW_NON_PART: return "Nonparticipating";
187 default: return "eh?";
188 }
189 }
190
191 /*
192 * Soft Structure per host adapter
193 */
194 struct ispsoftc {
195 /*
196 * Platform (OS) specific data
197 */
198 struct isposinfo isp_osinfo;
199
200 /*
201 * Pointer to bus specific data
202 */
203 struct ispmdvec * isp_mdvec;
204
205 /*
206 * State, debugging, etc..
207 */
208
209 u_int32_t isp_state : 3,
210 isp_dogactive : 1,
211 isp_dblev : 4,
212 isp_confopts : 8,
213 isp_fwrev : 16;
214
215 /*
216 * Host Adapter Type and Parameters.
217 * Some parameters nominally stored in NVRAM on card.
218 */
219 void * isp_param;
220 u_int8_t isp_type;
221 int16_t isp_nactive;
222
223 /*
224 * Result and Request Queues.
225 */
226 volatile u_int8_t isp_reqidx; /* index of next request */
227 volatile u_int8_t isp_residx; /* index of next result */
228 volatile u_int8_t isp_sendmarker;
229 volatile u_int8_t isp_seqno;
230
231 /*
232 * Sheer laziness, but it gets us around the problem
233 * where we don't have a clean way of remembering
234 * which transaction is bound to which ISP queue entry.
235 *
236 * There are other more clever ways to do this, but,
237 * jeez, so I blow a couple of KB per host adapter...
238 * and it *is* faster.
239 */
240 volatile ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN];
241
242 /*
243 * request/result queues
244 */
245 volatile caddr_t isp_rquest;
246 volatile caddr_t isp_result;
247 u_int32_t isp_rquest_dma;
248 u_int32_t isp_result_dma;
249 };
250
251 /*
252 * ISP States
253 */
254 #define ISP_NILSTATE 0
255 #define ISP_RESETSTATE 1
256 #define ISP_INITSTATE 2
257 #define ISP_RUNSTATE 3
258
259 /*
260 * ISP Configuration Options
261 */
262 #define ISP_CFG_NORELOAD 0x80 /* don't download f/w */
263
264 /*
265 * Adapter Types
266 */
267 #define ISP_HA_SCSI 0xf
268 #define ISP_HA_SCSI_UNKNOWN 0x0
269 #define ISP_HA_SCSI_1020 0x1
270 #define ISP_HA_SCSI_1020A 0x2
271 #define ISP_HA_SCSI_1040A 0x3
272 #define ISP_HA_SCSI_1040B 0x4
273 #define ISP_HA_FC 0xf0
274 #define ISP_HA_FC_2100 0x10
275
276 /*
277 * Macros to read, write ISP registers through MD code
278 */
279
280 #define ISP_READ(isp, reg) \
281 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
282
283 #define ISP_WRITE(isp, reg, val) \
284 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
285
286 #define ISP_MBOXDMASETUP(isp) \
287 (*(isp)->isp_mdvec->dv_mbxdma)((isp))
288
289 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \
290 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
291
292 #define ISP_DMAFREE(isp, xs, seqno) \
293 if ((isp)->isp_mdvec->dv_dmaclr) \
294 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
295
296 #define ISP_RESET0(isp) \
297 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
298 #define ISP_RESET1(isp) \
299 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
300 #define ISP_DUMPREGS(isp) \
301 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
302
303 #define ISP_SETBITS(isp, reg, val) \
304 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
305
306 #define ISP_CLRBITS(isp, reg, val) \
307 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
308
309 /*
310 * Function Prototypes
311 */
312
313 /*
314 * Reset Hardware. Totally. Assumes that you'll follow this with
315 * a call to isp_init.
316 */
317 void isp_reset __P((struct ispsoftc *));
318
319 /*
320 * Initialize Hardware to known state
321 */
322 void isp_init __P((struct ispsoftc *));
323
324 /*
325 * Free any associated resources prior to decommissioning.
326 */
327 void isp_uninit __P((struct ispsoftc *));
328
329 /*
330 * Reset the ISP and call completion for any orphaned commands.
331 */
332 void isp_restart __P((struct ispsoftc *));
333
334 /*
335 * Interrupt Service Routine
336 */
337 int isp_intr __P((void *));
338
339 /*
340 * Watchdog Routine
341 */
342 void isp_watch __P((void *));
343
344 /*
345 * Command Entry Point
346 */
347 extern int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
348
349 /*
350 * Platform Dependent to Internal Control Point
351 *
352 * For: Aborting a running command - arg is an ISP_SCSI_XFER_T *
353 * Resetting a Device - arg is target to reset
354 * Resetting a BUS - arg is ignored
355 *
356 * Second argument is an index into xflist array.
357 * Assumes all locks must be held already.
358 */
359 typedef enum {
360 ISPCTL_RESET_BUS,
361 ISPCTL_RESET_DEV,
362 ISPCTL_ABORT_CMD
363 } ispctl_t;
364 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
365
366 /*
367 * lost command routine (XXXX IN TRANSITION XXXX)
368 */
369 extern void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
370
371 #endif /* _ISPVAR_H */
372