ispvar.h revision 1.11 1 /* $Id: ispvar.h,v 1.11 1998/09/08 07:27:04 mjacob Exp $ */
2 /*
3 * Soft Definitions for for Qlogic ISP SCSI adapters.
4 *
5 *---------------------------------------
6 * Copyright (c) 1997, 1998 by Matthew Jacob
7 * NASA/Ames Research Center
8 * All rights reserved.
9 *---------------------------------------
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. 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
36 #ifndef _ISPVAR_H
37 #define _ISPVAR_H
38
39 #ifdef __NetBSD__
40 #include <dev/ic/ispmbox.h>
41 #endif
42 #ifdef __FreeBSD__
43 #include <dev/isp/ispmbox.h>
44 #endif
45 #ifdef __linux__
46 #include <ispmbox.h>
47 #endif
48
49 #define ISP_CORE_VERSION_MAJOR 1
50 #define ISP_CORE_VERSION_MINOR 2
51
52 /*
53 * Vector for MD code to provide specific services.
54 */
55 struct ispsoftc;
56 struct ispmdvec {
57 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int));
58 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
59 int (*dv_mbxdma) __P((struct ispsoftc *));
60 int (*dv_dmaset) __P((struct ispsoftc *,
61 ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
62 void (*dv_dmaclr)
63 __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
64 void (*dv_reset0) __P((struct ispsoftc *));
65 void (*dv_reset1) __P((struct ispsoftc *));
66 void (*dv_dregs) __P((struct ispsoftc *));
67 const u_int16_t *dv_ispfw; /* ptr to f/w */
68 u_int16_t dv_fwlen; /* length of f/w */
69 u_int16_t dv_codeorg; /* code ORG for f/w */
70 u_int16_t dv_fwrev; /* f/w revision */
71 /*
72 * Initial values for conf1 register
73 */
74 u_int16_t dv_conf1;
75 u_int16_t dv_clock; /* clock frequency */
76 };
77
78 #define MAX_TARGETS 16
79 #define MAX_FC_TARG 126
80
81 /* queue length must be a power of two */
82 #define QENTRY_LEN 64
83 #define RQUEST_QUEUE_LEN MAXISPREQUEST
84 #define RESULT_QUEUE_LEN (MAXISPREQUEST/4)
85 #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN))
86 #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN)
87 #define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1))
88 #define ISP_QDEPTH(in, out, qlen) ((in - out) & ((qlen) - 1))
89
90 /*
91 * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
92 */
93
94 typedef struct {
95 u_int isp_req_ack_active_neg : 1,
96 isp_data_line_active_neg: 1,
97 isp_cmd_dma_burst_enable: 1,
98 isp_data_dma_burst_enabl: 1,
99 isp_fifo_threshold : 2,
100 isp_diffmode : 1,
101 isp_fast_mttr : 1,
102 isp_initiator_id : 4,
103 isp_async_data_setup : 4;
104 u_int16_t isp_selection_timeout;
105 u_int16_t isp_max_queue_depth;
106 u_int16_t isp_clock;
107 u_int8_t isp_tag_aging;
108 u_int8_t isp_bus_reset_delay;
109 u_int8_t isp_retry_count;
110 u_int8_t isp_retry_delay;
111 struct {
112 u_int dev_update : 1,
113 dev_enable : 1,
114 exc_throttle : 7,
115 sync_offset : 4,
116 sync_period : 8;
117 u_int16_t dev_flags; /* persistent device flags */
118 u_int16_t cur_dflags; /* current device flags */
119 } isp_devparam[MAX_TARGETS];
120 } sdparam; /* scsi device parameters */
121
122 /*
123 * Device Flags
124 */
125 #define DPARM_DISC 0x8000
126 #define DPARM_PARITY 0x4000
127 #define DPARM_WIDE 0x2000
128 #define DPARM_SYNC 0x1000
129 #define DPARM_TQING 0x0800
130 #define DPARM_ARQ 0x0400
131 #define DPARM_QFRZ 0x0200
132 #define DPARM_RENEG 0x0100
133 #define DPARM_NARROW 0x0080 /* Possibly only available with >= 7.55 fw */
134 #define DPARM_ASYNC 0x0040 /* Possibly only available with >= 7.55 fw */
135 #define DPARM_DEFAULT (0xFFFF & ~DPARM_QFRZ)
136 #define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
137
138
139 #define ISP_20M_SYNCPARMS 0x080c
140 #define ISP_10M_SYNCPARMS 0x0c19
141 #define ISP_08M_SYNCPARMS 0x0c25
142 #define ISP_05M_SYNCPARMS 0x0c32
143 #define ISP_04M_SYNCPARMS 0x0c41
144
145 /*
146 * Fibre Channel Specifics
147 */
148 typedef struct {
149 u_int64_t isp_wwn; /* WWN of adapter */
150 u_int8_t isp_loopid; /* hard loop id */
151 u_int8_t isp_alpa; /* ALPA */
152 u_int8_t isp_execthrottle;
153 u_int8_t isp_retry_delay;
154 u_int8_t isp_retry_count;
155 u_int8_t isp_fwstate; /* ISP F/W state */
156 u_int16_t isp_maxalloc;
157 u_int16_t isp_maxfrmlen;
158 u_int16_t isp_fwoptions;
159 /*
160 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
161 */
162 volatile caddr_t isp_scratch;
163 u_int32_t isp_scdma;
164 } fcparam;
165
166 #define ISP2100_SCRLEN 0x100
167
168 #define FW_CONFIG_WAIT 0x0000
169 #define FW_WAIT_AL_PA 0x0001
170 #define FW_WAIT_LOGIN 0x0002
171 #define FW_READY 0x0003
172 #define FW_LOSS_OF_SYNC 0x0004
173 #define FW_ERROR 0x0005
174 #define FW_REINIT 0x0006
175 #define FW_NON_PART 0x0007
176
177 static __inline char *fw_statename __P((u_int8_t x));
178 static __inline char *
179 fw_statename(x)
180 u_int8_t x;
181 {
182 switch(x) {
183 case FW_CONFIG_WAIT: return "Config Wait";
184 case FW_WAIT_AL_PA: return "Waiting for AL/PA";
185 case FW_WAIT_LOGIN: return "Wait Login";
186 case FW_READY: return "Ready";
187 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
188 case FW_ERROR: return "Error";
189 case FW_REINIT: return "Re-Init";
190 case FW_NON_PART: return "Nonparticipating";
191 default: return "eh?";
192 }
193 }
194
195 /*
196 * Soft Structure per host adapter
197 */
198 struct ispsoftc {
199 /*
200 * Platform (OS) specific data
201 */
202 struct isposinfo isp_osinfo;
203
204 /*
205 * Pointer to bus specific data
206 */
207 struct ispmdvec * isp_mdvec;
208
209 /*
210 * State, debugging, etc..
211 */
212
213 u_int : 8,
214 isp_confopts : 8,
215 : 2,
216 isp_dblev : 3,
217 isp_gotdparms : 1,
218 isp_dogactive : 1,
219 isp_bustype : 1, /* BUS Implementation */
220 isp_type : 8; /* HBA Type and Revision */
221
222 u_int16_t isp_fwrev; /* Running F/W revision */
223 u_int16_t isp_romfw_rev; /* 'ROM' F/W revision */
224 void * isp_param;
225
226 /*
227 * Volatile state
228 */
229
230 volatile u_int
231 : 19,
232 isp_state : 3,
233 isp_sendmarker : 1, /* send a marker entry */
234 isp_update : 1, /* update paramters */
235 isp_nactive : 9; /* how many commands active */
236
237 /*
238 * Result and Request Queue indices.
239 */
240 volatile u_int8_t isp_reqodx; /* index of last ISP pickup */
241 volatile u_int8_t isp_reqidx; /* index of next request */
242 volatile u_int8_t isp_residx; /* index of next result */
243 volatile u_int8_t isp_seqno; /* rolling sequence # */
244
245 /*
246 * Sheer laziness, but it gets us around the problem
247 * where we don't have a clean way of remembering
248 * which transaction is bound to which ISP queue entry.
249 *
250 * There are other more clever ways to do this, but,
251 * jeez, so I blow a couple of KB per host adapter...
252 * and it *is* faster.
253 */
254 volatile ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN];
255
256 /*
257 * request/result queues and dma handles for them.
258 */
259 volatile caddr_t isp_rquest;
260 volatile caddr_t isp_result;
261 u_int32_t isp_rquest_dma;
262 u_int32_t isp_result_dma;
263 };
264
265 /*
266 * ISP States
267 */
268 #define ISP_NILSTATE 0
269 #define ISP_RESETSTATE 1
270 #define ISP_INITSTATE 2
271 #define ISP_RUNSTATE 3
272
273 /*
274 * ISP Configuration Options
275 */
276 #define ISP_CFG_NORELOAD 0x80 /* don't download f/w */
277
278 #define ISP_FW_REV(maj, min) ((maj) << 10| (min))
279
280 /*
281 * Bus (implementation) types
282 */
283 #define ISP_BT_PCI 0 /* PCI Implementations */
284 #define ISP_BT_SBUS 1 /* SBus Implementations */
285
286 /*
287 * Chip Types
288 */
289 #define ISP_HA_SCSI 0xf
290 #define ISP_HA_SCSI_UNKNOWN 0x1
291 #define ISP_HA_SCSI_1020 0x2
292 #define ISP_HA_SCSI_1020A 0x3
293 #define ISP_HA_SCSI_1040 0x4
294 #define ISP_HA_SCSI_1040A 0x5
295 #define ISP_HA_SCSI_1040B 0x6
296 #define ISP_HA_FC 0xf0
297 #define ISP_HA_FC_2100 0x10
298
299 /*
300 * Macros to read, write ISP registers through MD code
301 */
302
303 #define ISP_READ(isp, reg) \
304 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
305
306 #define ISP_WRITE(isp, reg, val) \
307 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
308
309 #define ISP_MBOXDMASETUP(isp) \
310 (*(isp)->isp_mdvec->dv_mbxdma)((isp))
311
312 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \
313 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
314
315 #define ISP_DMAFREE(isp, xs, seqno) \
316 if ((isp)->isp_mdvec->dv_dmaclr) \
317 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
318
319 #define ISP_RESET0(isp) \
320 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
321 #define ISP_RESET1(isp) \
322 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
323 #define ISP_DUMPREGS(isp) \
324 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
325
326 #define ISP_SETBITS(isp, reg, val) \
327 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
328
329 #define ISP_CLRBITS(isp, reg, val) \
330 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
331
332 /*
333 * Function Prototypes
334 */
335
336 /*
337 * Reset Hardware. Totally. Assumes that you'll follow this with
338 * a call to isp_init.
339 */
340 void isp_reset __P((struct ispsoftc *));
341
342 /*
343 * Initialize Hardware to known state
344 */
345 void isp_init __P((struct ispsoftc *));
346
347 /*
348 * Free any associated resources prior to decommissioning.
349 */
350 void isp_uninit __P((struct ispsoftc *));
351
352 /*
353 * Reset the ISP and call completion for any orphaned commands.
354 */
355 void isp_restart __P((struct ispsoftc *));
356
357 /*
358 * Interrupt Service Routine
359 */
360 int isp_intr __P((void *));
361
362 /*
363 * Watchdog Routine
364 */
365 void isp_watch __P((void *));
366
367 /*
368 * Command Entry Point
369 */
370 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
371
372 /*
373 * Platform Dependent to Internal Control Point
374 *
375 * For: Aborting a running command - arg is an ISP_SCSI_XFER_T *
376 * Resetting a Device - arg is target to reset
377 * Resetting a BUS - arg is ignored
378 *
379 * Second argument is an index into xflist array.
380 * Assumes all locks must be held already.
381 */
382 typedef enum {
383 ISPCTL_RESET_BUS,
384 ISPCTL_RESET_DEV,
385 ISPCTL_ABORT_CMD
386 } ispctl_t;
387 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
388
389 /*
390 * lost command routine (XXXX IN TRANSITION XXXX)
391 */
392 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
393
394
395 #endif /* _ISPVAR_H */
396