ispvar.h revision 1.26 1 /* $NetBSD: ispvar.h,v 1.26 1999/12/04 03:06:05 mjacob Exp $ */
2 /*
3 * Copyright (C) 1999 National Aeronautics & Space Administration
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * Soft Definitions for for Qlogic ISP SCSI adapters.
31 * Matthew Jacob <mjacob (at) nas.nasa.gov>
32 */
33 #ifndef _ISPVAR_H
34 #define _ISPVAR_H
35
36 #if defined(__NetBSD__) || defined(__OpenBSD__)
37 #include <dev/ic/ispmbox.h>
38 #ifdef ISP_TARGET_MODE
39 #include <dev/ic/isp_target.h>
40 #endif
41 #endif
42 #ifdef __FreeBSD__
43 #include <dev/isp/ispmbox.h>
44 #ifdef ISP_TARGET_MODE
45 #include <dev/isp/isp_target.h>
46 #endif
47 #endif
48 #ifdef __linux__
49 #include "ispmbox.h"
50 #ifdef ISP_TARGET_MODE
51 #include "isp_target.h"
52 #endif
53 #endif
54
55 #define ISP_CORE_VERSION_MAJOR 1
56 #define ISP_CORE_VERSION_MINOR 11
57
58 /*
59 * Vector for bus specific code to provide specific services.
60 */
61 struct ispsoftc;
62 struct ispmdvec {
63 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int));
64 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
65 int (*dv_mbxdma) __P((struct ispsoftc *));
66 int (*dv_dmaset) __P((struct ispsoftc *,
67 ISP_SCSI_XFER_T *, ispreq_t *, u_int16_t *, u_int16_t));
68 void (*dv_dmaclr)
69 __P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
70 void (*dv_reset0) __P((struct ispsoftc *));
71 void (*dv_reset1) __P((struct ispsoftc *));
72 void (*dv_dregs) __P((struct ispsoftc *));
73 const u_int16_t *dv_ispfw; /* ptr to f/w */
74 u_int16_t dv_fwlen; /* length of f/w */
75 u_int16_t dv_codeorg; /* code ORG for f/w */
76 u_int32_t dv_fwrev; /* f/w revision */
77 /*
78 * Initial values for conf1 register
79 */
80 u_int16_t dv_conf1;
81 u_int16_t dv_clock; /* clock frequency */
82 };
83
84 #define MAX_TARGETS 16
85 #ifdef ISP2100_FABRIC
86 #define MAX_FC_TARG 256
87 #else
88 #define MAX_FC_TARG 126
89 #endif
90
91 #define ISP_MAX_TARGETS(isp) (IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
92 #ifdef ISP2100_SCCLUN
93 #define _ISP_FC_LUN(isp) 65536
94 #else
95 #define _ISP_FC_LUN(isp) 16
96 #endif
97 #define _ISP_SCSI_LUN(isp) \
98 ((ISP_FW_REVX(isp->isp_fwrev) >= ISP_FW_REV(7, 55, 0))? 32 : 8)
99 #define ISP_MAX_LUNS(isp) \
100 (IS_FC(isp)? _ISP_FC_LUN(isp) : _ISP_SCSI_LUN(isp))
101
102
103 /*
104 * Macros to read, write ISP registers through bus specific code.
105 */
106
107 #define ISP_READ(isp, reg) \
108 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
109
110 #define ISP_WRITE(isp, reg, val) \
111 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
112
113 #define ISP_MBOXDMASETUP(isp) \
114 (*(isp)->isp_mdvec->dv_mbxdma)((isp))
115
116 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \
117 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
118
119 #define ISP_DMAFREE(isp, xs, hndl) \
120 if ((isp)->isp_mdvec->dv_dmaclr) \
121 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
122
123 #define ISP_RESET0(isp) \
124 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
125 #define ISP_RESET1(isp) \
126 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
127 #define ISP_DUMPREGS(isp) \
128 if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
129
130 #define ISP_SETBITS(isp, reg, val) \
131 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
132
133 #define ISP_CLRBITS(isp, reg, val) \
134 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
135
136 /* this is the size of a queue entry (request and response) */
137 #define QENTRY_LEN 64
138 /* both request and result queue length must be a power of two */
139 #define RQUEST_QUEUE_LEN MAXISPREQUEST
140 /* I've seen wierdnesses with the result queue < 64 */
141 #if MAXISPREQUEST > 64
142 #define RESULT_QUEUE_LEN (MAXISPREQUEST/2)
143 #else
144 #define RESULT_QUEUE_LEN MAXISPREQUEST
145 #endif
146 #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN))
147 #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN)
148 #define ISP_NXT_QENTRY(idx, qlen) (((idx) + 1) & ((qlen)-1))
149 #define ISP_QAVAIL(in, out, qlen) \
150 ((in == out)? (qlen - 1) : ((in > out)? \
151 ((qlen - 1) - (in - out)) : (out - in - 1)))
152
153 #define ISP_ADD_REQUEST(isp, iptr) \
154 ISP_WRITE(isp, INMAILBOX4, iptr), isp->isp_reqidx = iptr
155
156 /*
157 * SCSI Specific Host Adapter Parameters- per bus, per target
158 */
159
160 typedef struct {
161 u_int isp_gotdparms : 1,
162 isp_req_ack_active_neg : 1,
163 isp_data_line_active_neg: 1,
164 isp_cmd_dma_burst_enable: 1,
165 isp_data_dma_burst_enabl: 1,
166 isp_fifo_threshold : 3,
167 isp_ultramode : 1,
168 isp_diffmode : 1,
169 isp_lvdmode : 1,
170 : 1,
171 isp_initiator_id : 4,
172 isp_async_data_setup : 4;
173 u_int16_t isp_selection_timeout;
174 u_int16_t isp_max_queue_depth;
175 u_int8_t isp_tag_aging;
176 u_int8_t isp_bus_reset_delay;
177 u_int8_t isp_retry_count;
178 u_int8_t isp_retry_delay;
179 struct {
180 u_int dev_enable : 1, /* ignored */
181 : 1,
182 dev_update : 1,
183 dev_refresh : 1,
184 exc_throttle : 8,
185 cur_offset : 4,
186 sync_offset : 4;
187 u_int8_t cur_period; /* current sync period */
188 u_int8_t sync_period; /* goal sync period */
189 u_int16_t dev_flags; /* goal device flags */
190 u_int16_t cur_dflags; /* current device flags */
191 } isp_devparam[MAX_TARGETS];
192 } sdparam;
193
194 /*
195 * Device Flags
196 */
197 #define DPARM_DISC 0x8000
198 #define DPARM_PARITY 0x4000
199 #define DPARM_WIDE 0x2000
200 #define DPARM_SYNC 0x1000
201 #define DPARM_TQING 0x0800
202 #define DPARM_ARQ 0x0400
203 #define DPARM_QFRZ 0x0200
204 #define DPARM_RENEG 0x0100
205 #define DPARM_NARROW 0x0080 /* Possibly only available with >= 7.55 fw */
206 #define DPARM_ASYNC 0x0040 /* Possibly only available with >= 7.55 fw */
207 #define DPARM_DEFAULT (0xFF00 & ~DPARM_QFRZ)
208 #define DPARM_SAFE_DFLT (DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
209
210
211 /* technically, not really correct, as they need to be rated based upon clock */
212 #define ISP_40M_SYNCPARMS 0x080a
213 #define ISP_20M_SYNCPARMS 0x080c
214 #define ISP_10M_SYNCPARMS 0x0c19
215 #define ISP_08M_SYNCPARMS 0x0c25
216 #define ISP_05M_SYNCPARMS 0x0c32
217 #define ISP_04M_SYNCPARMS 0x0c41
218
219 /*
220 * Fibre Channel Specifics
221 */
222 #define FL_PORT_ID 0x7e /* FL_Port Special ID */
223 #define FC_PORT_ID 0x7f /* Fabric Controller Special ID */
224 #define FC_SNS_ID 0x80 /* SNS Server Special ID */
225
226 typedef struct {
227 u_int32_t isp_fwoptions : 16,
228 : 7,
229 loop_seen_once : 1,
230 isp_loopstate : 3, /* Current Loop State */
231 isp_fwstate : 3, /* ISP F/W state */
232 isp_gotdparms : 1,
233 isp_onfabric : 1;
234 u_int8_t isp_loopid; /* hard loop id */
235 u_int8_t isp_alpa; /* ALPA */
236 volatile u_int16_t isp_lipseq; /* LIP sequence # */
237 u_int32_t isp_portid;
238 u_int8_t isp_execthrottle;
239 u_int8_t isp_retry_delay;
240 u_int8_t isp_retry_count;
241 u_int8_t isp_reserved;
242 u_int16_t isp_maxalloc;
243 u_int16_t isp_maxfrmlen;
244 u_int64_t isp_nodewwn;
245 u_int64_t isp_portwwn;
246 /*
247 * Port Data Base. This is indexed by 'target', which is invariate.
248 * However, elements within can move around due to loop changes,
249 * so the actual loop ID passed to the F/W is in this structure.
250 * The first time the loop is seen up, loopid will match the index
251 * (except for fabric nodes which are above mapped above FC_SNS_ID
252 * and are completely virtual), but subsequent LIPs can cause things
253 * to move around.
254 */
255 struct lportdb {
256 u_int
257 loopid : 8,
258 : 4,
259 fabdev : 1,
260 roles : 2,
261 valid : 1;
262 u_int32_t portid;
263 u_int64_t node_wwn;
264 u_int64_t port_wwn;
265 } portdb[MAX_FC_TARG], tport[FL_PORT_ID];
266
267 /*
268 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
269 */
270 caddr_t isp_scratch;
271 u_int32_t isp_scdma;
272 } fcparam;
273
274 #define FW_CONFIG_WAIT 0
275 #define FW_WAIT_AL_PA 1
276 #define FW_WAIT_LOGIN 2
277 #define FW_READY 3
278 #define FW_LOSS_OF_SYNC 4
279 #define FW_ERROR 5
280 #define FW_REINIT 6
281 #define FW_NON_PART 7
282
283 #define LOOP_NIL 0
284 #define LOOP_LIP_RCVD 1
285 #define LOOP_PDB_RCVD 2
286 #define LOOP_READY 7
287
288 /*
289 * Soft Structure per host adapter
290 */
291 struct ispsoftc {
292 /*
293 * Platform (OS) specific data
294 */
295 struct isposinfo isp_osinfo;
296
297 /*
298 * Pointer to bus specific functions and data
299 */
300 struct ispmdvec * isp_mdvec;
301
302 /*
303 * (Mostly) nonvolatile state. Board specific parameters
304 * may contain some volatile state (e.g., current loop state).
305 */
306
307 void * isp_param; /* type specific */
308 u_int16_t isp_fwrev[3]; /* Loaded F/W revision */
309 u_int16_t isp_romfw_rev[3]; /* PROM F/W revision */
310 u_int16_t isp_maxcmds; /* max possible I/O cmds */
311 u_int8_t isp_type; /* HBA Chip Type */
312 u_int8_t isp_revision; /* HBA Chip H/W Revision */
313
314 u_int32_t : 4,
315 isp_touched : 1, /* board ever seen? */
316 isp_fast_mttr : 1, /* fast sram */
317 isp_bustype : 1, /* SBus or PCI */
318 isp_dogactive : 1, /* watchdog running */
319 isp_dblev : 8, /* debug level */
320 isp_clock : 8, /* input clock */
321 isp_confopts : 8; /* config options */
322
323 /*
324 * Volatile state
325 */
326
327 volatile u_int32_t : 9,
328 isp_state : 3,
329 isp_sendmarker : 2, /* send a marker entry */
330 isp_update : 2, /* update parameters */
331 isp_nactive : 16; /* how many commands active */
332
333 volatile u_int16_t isp_reqodx; /* index of last ISP pickup */
334 volatile u_int16_t isp_reqidx; /* index of next request */
335 volatile u_int16_t isp_residx; /* index of next result */
336 volatile u_int16_t isp_lasthdls; /* last handle seed */
337
338 /*
339 * Active commands are stored here, indexed by handle functions.
340 */
341 ISP_SCSI_XFER_T **isp_xflist;
342
343 /*
344 * request/result queue pointers and dma handles for them.
345 */
346 caddr_t isp_rquest;
347 caddr_t isp_result;
348 u_int32_t isp_rquest_dma;
349 u_int32_t isp_result_dma;
350 };
351
352 #define SDPARAM(isp) ((sdparam *) (isp)->isp_param)
353 #define FCPARAM(isp) ((fcparam *) (isp)->isp_param)
354
355 /*
356 * ISP States
357 */
358 #define ISP_NILSTATE 0
359 #define ISP_RESETSTATE 1
360 #define ISP_INITSTATE 2
361 #define ISP_RUNSTATE 3
362
363 /*
364 * ISP Configuration Options
365 */
366 #define ISP_CFG_NORELOAD 0x80 /* don't download f/w */
367 #define ISP_CFG_NONVRAM 0x40 /* ignore NVRAM */
368 #define ISP_CFG_FULL_DUPLEX 0x01 /* Full Duplex (Fibre Channel only) */
369 #define ISP_CFG_OWNWWN 0x02 /* override NVRAM wwn */
370
371 #define ISP_FW_REV(maj, min, mic) ((maj << 24) | (min << 16) | mic)
372 #define ISP_FW_REVX(xp) ((xp[0]<<24) | (xp[1] << 16) | xp[2])
373
374 /*
375 * Bus (implementation) types
376 */
377 #define ISP_BT_PCI 0 /* PCI Implementations */
378 #define ISP_BT_SBUS 1 /* SBus Implementations */
379
380 /*
381 * Chip Types
382 */
383 #define ISP_HA_SCSI 0xf
384 #define ISP_HA_SCSI_UNKNOWN 0x1
385 #define ISP_HA_SCSI_1020 0x2
386 #define ISP_HA_SCSI_1020A 0x3
387 #define ISP_HA_SCSI_1040 0x4
388 #define ISP_HA_SCSI_1040A 0x5
389 #define ISP_HA_SCSI_1040B 0x6
390 #define ISP_HA_SCSI_1040C 0x7
391 #define ISP_HA_SCSI_1080 0xd
392 #define ISP_HA_SCSI_12X0 0xe
393 #define ISP_HA_FC 0xf0
394 #define ISP_HA_FC_2100 0x10
395 #define ISP_HA_FC_2200 0x20
396
397 #define IS_SCSI(isp) (isp->isp_type & ISP_HA_SCSI)
398 #define IS_1080(isp) (isp->isp_type == ISP_HA_SCSI_1080)
399 #define IS_12X0(isp) (isp->isp_type == ISP_HA_SCSI_12X0)
400 #define IS_FC(isp) (isp->isp_type & ISP_HA_FC)
401
402 /*
403 * Function Prototypes
404 */
405
406 /*
407 * Reset Hardware. Totally. Assumes that you'll follow this with
408 * a call to isp_init.
409 */
410 void isp_reset __P((struct ispsoftc *));
411
412 /*
413 * Initialize Hardware to known state
414 */
415 void isp_init __P((struct ispsoftc *));
416
417 /*
418 * Reset the ISP and call completion for any orphaned commands.
419 */
420 void isp_restart __P((struct ispsoftc *));
421
422 /*
423 * Interrupt Service Routine
424 */
425 int isp_intr __P((void *));
426
427 /*
428 * Command Entry Point
429 */
430 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
431
432 /*
433 * Platform Dependent to External to Internal Control Function
434 *
435 * Assumes all locks are held and that no reentrancy issues need be dealt with.
436 *
437 */
438 typedef enum {
439 ISPCTL_RESET_BUS, /* Reset Bus */
440 ISPCTL_RESET_DEV, /* Reset Device */
441 ISPCTL_ABORT_CMD, /* Abort Command */
442 ISPCTL_UPDATE_PARAMS, /* Update Operating Parameters */
443 #ifdef ISP_TARGET_MODE
444 ISPCTL_ENABLE_LUN, /* enable a LUN */
445 ISPCTL_MODIFY_LUN, /* enable a LUN */
446 #endif
447 ISPCTL_FCLINK_TEST /* Test FC Link Status */
448 } ispctl_t;
449 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
450
451
452 /*
453 * Platform Dependent to Internal to External Control Function
454 * (each platform must provide such a function)
455 *
456 * Assumes all locks are held and that no reentrancy issues need be dealt with.
457 *
458 */
459
460 typedef enum {
461 ISPASYNC_NEW_TGT_PARAMS,
462 ISPASYNC_BUS_RESET, /* Bus Was Reset */
463 ISPASYNC_LOOP_DOWN, /* FC Loop Down */
464 ISPASYNC_LOOP_UP, /* FC Loop Up */
465 ISPASYNC_PDB_CHANGED, /* FC Port Data Base Changed */
466 ISPASYNC_CHANGE_NOTIFY, /* FC SNS Change Notification */
467 ISPASYNC_FABRIC_DEV, /* FC New Fabric Device */
468 ISPASYNC_TARGET_CMD, /* New target command */
469 ISPASYNC_TARGET_EVENT /* New target event */
470 } ispasync_t;
471 int isp_async __P((struct ispsoftc *, ispasync_t, void *));
472
473 /*
474 * lost command routine (XXXX IN TRANSITION XXXX)
475 */
476 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
477
478 #endif /* _ISPVAR_H */
479