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