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