ispvar.h revision 1.4 1 /* $NetBSD: ispvar.h,v 1.4 1997/04/05 02:48:36 mjacob Exp $ */
2
3 /*
4 * Soft Definitions for for Qlogic ISP SCSI adapters.
5 *
6 * Copyright (c) 1997 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 #ifndef _ISPVAR_H
36 #define _ISPVAR_H
37
38 #include <dev/ic/ispmbox.h>
39
40 /*
41 * Vector for MD code to provide specific services.
42 */
43 struct ispsoftc;
44 struct ispmdvec {
45 u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int));
46 void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
47 vm_offset_t (*dv_mbxdma)
48 __P((struct ispsoftc *, vm_offset_t, u_int32_t));
49 int (*dv_dmaset) __P((struct ispsoftc *,
50 struct scsi_xfer *, ispreq_t *, u_int8_t *, u_int8_t));
51 void (*dv_dmaclr)
52 __P((struct ispsoftc *, struct scsi_xfer *, u_int32_t));
53 void (*dv_reset0) __P((struct ispsoftc *));
54 void (*dv_reset1) __P((struct ispsoftc *));
55 const u_int16_t *dv_ispfw; /* ptr to f/w */
56 u_int16_t dv_fwlen; /* length of f/w */
57 u_int16_t dv_codeorg; /* code ORG for f/w */
58 /*
59 * Initial values for conf1 register
60 */
61 u_int16_t dv_conf1;
62 u_int16_t dv_clock; /* clock frequency */
63 };
64
65 #define MAX_TARGETS 16
66 #define MAX_LUNS 8
67
68 #define RQUEST_QUEUE_LEN 256
69 #define RESULT_QUEUE_LEN (RQUEST_QUEUE_LEN >> 3)
70 #define QENTRY_LEN 64
71
72 /*
73 * Soft Structure per host adapter
74 */
75 struct ispsoftc {
76 struct device isp_dev;
77 struct ispmdvec * isp_mdvec;
78 #define isp_name isp_dev.dv_xname
79 struct scsi_link isp_link;
80 u_int8_t isp_max_target;
81 u_int8_t isp_state;
82 /*
83 * Host Adapter Parameters, nominally stored in NVRAM
84 */
85 u_int16_t isp_adapter_enabled : 1,
86 isp_req_ack_active_neg : 1,
87 isp_data_line_active_neg: 1,
88 isp_cmd_dma_burst_enable: 1,
89 isp_data_dma_burst_enabl: 1,
90 isp_fifo_threshold : 2,
91 : 1,
92 isp_initiator_id : 4,
93 isp_async_data_setup : 4;
94 u_int16_t isp_selection_timeout;
95 u_int16_t isp_max_queue_depth;
96 u_int8_t isp_tag_aging;
97 u_int8_t isp_bus_reset_delay;
98 u_int8_t isp_retry_count;
99 u_int8_t isp_retry_delay;
100 struct {
101 u_int8_t dev_flags; /* Device Flags - see below */
102 u_int8_t exc_throttle;
103 u_int8_t sync_period;
104 u_int8_t sync_offset : 4,
105 dev_enable : 1;
106 } isp_devparam[MAX_TARGETS];
107 /*
108 * Result and Request Queues.
109 */
110 volatile u_int8_t isp_reqidx; /* index of next request */
111 volatile u_int8_t isp_residx; /* index of next result */
112 volatile u_int8_t isp_sendmarker;
113 volatile u_int8_t isp_seqno;
114 /*
115 * Sheer laziness, but it gets us around the problem
116 * where we don't have a clean way of remembering
117 * which scsi_xfer is bound to which ISP queue entry.
118 *
119 * There are other more clever ways to do this, but,
120 * jeez, so I blow a couple of KB per host adapter...
121 * and it *is* faster.
122 */
123 volatile struct scsi_xfer *isp_xflist[RQUEST_QUEUE_LEN];
124 /*
125 * request/result queue
126 */
127 volatile u_int8_t isp_rquest[RQUEST_QUEUE_LEN][QENTRY_LEN];
128 volatile u_int8_t isp_result[RESULT_QUEUE_LEN][QENTRY_LEN];
129 };
130
131 /*
132 * ISP States
133 */
134 #define ISP_NILSTATE 0
135 #define ISP_RESETSTATE 1
136 #define ISP_INITSTATE 2
137 #define ISP_RUNSTATE 3
138
139
140 /*
141 * Device Flags
142 */
143 #define DPARM_DISC 0x80
144 #define DPARM_PARITY 0x40
145 #define DPARM_WIDE 0x20
146 #define DPARM_SYNC 0x10
147 #define DPARM_TQING 0x08
148 #define DPARM_ARQ 0x04
149 #define DPARM_QFRZ 0x02
150 #define DPARM_RENEG 0x01
151
152 #define DPARM_DEFAULT (0xff & ~DPARM_QFRZ)
153
154
155 /*
156 * Macros to read, write ISP registers through MD code
157 */
158
159 #define ISP_READ(isp, reg) \
160 (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
161
162 #define ISP_WRITE(isp, reg, val) \
163 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
164
165 #define ISP_MBOXDMASETUP(isp, kva, len) \
166 (*(isp)->isp_mdvec->dv_mbxdma)((isp), (vm_offset_t) (kva), (len))
167
168 #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \
169 (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
170
171 #define ISP_DMAFREE(isp, xs, seqno) \
172 if ((isp)->isp_mdvec->dv_dmaclr) \
173 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
174
175 #define ISP_RESET0(isp) \
176 if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
177 #define ISP_RESET1(isp) \
178 if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
179
180
181 #define ISP_SETBITS(isp, reg, val) \
182 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
183
184 #define ISP_CLRBITS(isp, reg, val) \
185 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
186
187 /*
188 * Function Prototypes
189 */
190 /*
191 * Reset Hardware.
192 *
193 * Only looks at sc_dev.dv_xname, sc_iot and sc_ioh fields.
194 */
195 void isp_reset __P((struct ispsoftc *));
196
197 /*
198 * Initialize Hardware to known state
199 */
200 void isp_init __P((struct ispsoftc *));
201
202 /*
203 * Complete attachment of Hardware
204 */
205 void isp_attach __P((struct ispsoftc *));
206
207 /*
208 * Free any associated resources prior to decommissioning.
209 */
210 void isp_uninit __P((struct ispsoftc *));
211
212 /*
213 * Interrupt Service Routine
214 */
215 int isp_intr __P((void *));
216
217
218
219
220 #endif /* _ISPVAR_H */
221