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