ispvar.h revision 1.5 1 1.5 thorpej /* $NetBSD: ispvar.h,v 1.5 1997/06/08 06:31:53 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Soft Definitions for for Qlogic ISP SCSI adapters.
5 1.1 cgd *
6 1.2 cgd * Copyright (c) 1997 by Matthew Jacob
7 1.2 cgd * NASA/Ames Research Center
8 1.1 cgd * All rights reserved.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice immediately at the beginning of the file, without modification,
15 1.1 cgd * this list of conditions, and the following disclaimer.
16 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 cgd * notice, this list of conditions and the following disclaimer in the
18 1.1 cgd * documentation and/or other materials provided with the distribution.
19 1.1 cgd * 3. The name of the author may not be used to endorse or promote products
20 1.1 cgd * derived from this software without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 1.1 cgd * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 cgd * SUCH DAMAGE.
33 1.1 cgd */
34 1.2 cgd
35 1.1 cgd #ifndef _ISPVAR_H
36 1.1 cgd #define _ISPVAR_H
37 1.1 cgd
38 1.1 cgd #include <dev/ic/ispmbox.h>
39 1.1 cgd
40 1.1 cgd /*
41 1.1 cgd * Vector for MD code to provide specific services.
42 1.1 cgd */
43 1.1 cgd struct ispsoftc;
44 1.1 cgd struct ispmdvec {
45 1.1 cgd u_int16_t (*dv_rd_reg) __P((struct ispsoftc *, int));
46 1.1 cgd void (*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
47 1.5 thorpej int (*dv_mbxdma) __P((struct ispsoftc *));
48 1.1 cgd int (*dv_dmaset) __P((struct ispsoftc *,
49 1.1 cgd struct scsi_xfer *, ispreq_t *, u_int8_t *, u_int8_t));
50 1.1 cgd void (*dv_dmaclr)
51 1.1 cgd __P((struct ispsoftc *, struct scsi_xfer *, u_int32_t));
52 1.1 cgd void (*dv_reset0) __P((struct ispsoftc *));
53 1.1 cgd void (*dv_reset1) __P((struct ispsoftc *));
54 1.3 mycroft const u_int16_t *dv_ispfw; /* ptr to f/w */
55 1.1 cgd u_int16_t dv_fwlen; /* length of f/w */
56 1.1 cgd u_int16_t dv_codeorg; /* code ORG for f/w */
57 1.1 cgd /*
58 1.1 cgd * Initial values for conf1 register
59 1.1 cgd */
60 1.1 cgd u_int16_t dv_conf1;
61 1.4 mjacob u_int16_t dv_clock; /* clock frequency */
62 1.1 cgd };
63 1.1 cgd
64 1.1 cgd #define MAX_TARGETS 16
65 1.1 cgd #define MAX_LUNS 8
66 1.1 cgd
67 1.1 cgd #define RQUEST_QUEUE_LEN 256
68 1.1 cgd #define RESULT_QUEUE_LEN (RQUEST_QUEUE_LEN >> 3)
69 1.1 cgd #define QENTRY_LEN 64
70 1.1 cgd
71 1.5 thorpej #define ISP_QUEUE_ENTRY(q, idx) ((q) + ((idx) * QENTRY_LEN))
72 1.5 thorpej #define ISP_QUEUE_SIZE(n) ((n) * QENTRY_LEN)
73 1.5 thorpej
74 1.1 cgd /*
75 1.1 cgd * Soft Structure per host adapter
76 1.1 cgd */
77 1.1 cgd struct ispsoftc {
78 1.1 cgd struct device isp_dev;
79 1.1 cgd struct ispmdvec * isp_mdvec;
80 1.1 cgd #define isp_name isp_dev.dv_xname
81 1.1 cgd struct scsi_link isp_link;
82 1.1 cgd u_int8_t isp_max_target;
83 1.1 cgd u_int8_t isp_state;
84 1.1 cgd /*
85 1.1 cgd * Host Adapter Parameters, nominally stored in NVRAM
86 1.1 cgd */
87 1.1 cgd u_int16_t isp_adapter_enabled : 1,
88 1.1 cgd isp_req_ack_active_neg : 1,
89 1.1 cgd isp_data_line_active_neg: 1,
90 1.1 cgd isp_cmd_dma_burst_enable: 1,
91 1.1 cgd isp_data_dma_burst_enabl: 1,
92 1.1 cgd isp_fifo_threshold : 2,
93 1.1 cgd : 1,
94 1.1 cgd isp_initiator_id : 4,
95 1.1 cgd isp_async_data_setup : 4;
96 1.1 cgd u_int16_t isp_selection_timeout;
97 1.1 cgd u_int16_t isp_max_queue_depth;
98 1.1 cgd u_int8_t isp_tag_aging;
99 1.1 cgd u_int8_t isp_bus_reset_delay;
100 1.1 cgd u_int8_t isp_retry_count;
101 1.1 cgd u_int8_t isp_retry_delay;
102 1.1 cgd struct {
103 1.1 cgd u_int8_t dev_flags; /* Device Flags - see below */
104 1.1 cgd u_int8_t exc_throttle;
105 1.1 cgd u_int8_t sync_period;
106 1.1 cgd u_int8_t sync_offset : 4,
107 1.1 cgd dev_enable : 1;
108 1.1 cgd } isp_devparam[MAX_TARGETS];
109 1.1 cgd /*
110 1.1 cgd * Result and Request Queues.
111 1.1 cgd */
112 1.1 cgd volatile u_int8_t isp_reqidx; /* index of next request */
113 1.1 cgd volatile u_int8_t isp_residx; /* index of next result */
114 1.1 cgd volatile u_int8_t isp_sendmarker;
115 1.1 cgd volatile u_int8_t isp_seqno;
116 1.1 cgd /*
117 1.1 cgd * Sheer laziness, but it gets us around the problem
118 1.1 cgd * where we don't have a clean way of remembering
119 1.1 cgd * which scsi_xfer is bound to which ISP queue entry.
120 1.1 cgd *
121 1.1 cgd * There are other more clever ways to do this, but,
122 1.1 cgd * jeez, so I blow a couple of KB per host adapter...
123 1.1 cgd * and it *is* faster.
124 1.1 cgd */
125 1.1 cgd volatile struct scsi_xfer *isp_xflist[RQUEST_QUEUE_LEN];
126 1.1 cgd /*
127 1.1 cgd * request/result queue
128 1.1 cgd */
129 1.5 thorpej volatile caddr_t isp_rquest;
130 1.5 thorpej volatile caddr_t isp_result;
131 1.5 thorpej u_int32_t isp_rquest_dma;
132 1.5 thorpej u_int32_t isp_result_dma;
133 1.1 cgd };
134 1.1 cgd
135 1.1 cgd /*
136 1.1 cgd * ISP States
137 1.1 cgd */
138 1.1 cgd #define ISP_NILSTATE 0
139 1.1 cgd #define ISP_RESETSTATE 1
140 1.1 cgd #define ISP_INITSTATE 2
141 1.1 cgd #define ISP_RUNSTATE 3
142 1.1 cgd
143 1.1 cgd
144 1.1 cgd /*
145 1.1 cgd * Device Flags
146 1.1 cgd */
147 1.1 cgd #define DPARM_DISC 0x80
148 1.1 cgd #define DPARM_PARITY 0x40
149 1.1 cgd #define DPARM_WIDE 0x20
150 1.1 cgd #define DPARM_SYNC 0x10
151 1.1 cgd #define DPARM_TQING 0x08
152 1.1 cgd #define DPARM_ARQ 0x04
153 1.1 cgd #define DPARM_QFRZ 0x02
154 1.1 cgd #define DPARM_RENEG 0x01
155 1.1 cgd
156 1.1 cgd #define DPARM_DEFAULT (0xff & ~DPARM_QFRZ)
157 1.1 cgd
158 1.1 cgd
159 1.1 cgd /*
160 1.1 cgd * Macros to read, write ISP registers through MD code
161 1.1 cgd */
162 1.1 cgd
163 1.1 cgd #define ISP_READ(isp, reg) \
164 1.1 cgd (*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
165 1.1 cgd
166 1.1 cgd #define ISP_WRITE(isp, reg, val) \
167 1.1 cgd (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
168 1.1 cgd
169 1.5 thorpej #define ISP_MBOXDMASETUP(isp) \
170 1.5 thorpej (*(isp)->isp_mdvec->dv_mbxdma)((isp))
171 1.1 cgd
172 1.1 cgd #define ISP_DMASETUP(isp, xs, req, iptrp, optr) \
173 1.1 cgd (*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
174 1.1 cgd
175 1.1 cgd #define ISP_DMAFREE(isp, xs, seqno) \
176 1.1 cgd if ((isp)->isp_mdvec->dv_dmaclr) \
177 1.1 cgd (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
178 1.1 cgd
179 1.1 cgd #define ISP_RESET0(isp) \
180 1.1 cgd if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
181 1.1 cgd #define ISP_RESET1(isp) \
182 1.1 cgd if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
183 1.1 cgd
184 1.1 cgd
185 1.1 cgd #define ISP_SETBITS(isp, reg, val) \
186 1.1 cgd (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
187 1.1 cgd
188 1.1 cgd #define ISP_CLRBITS(isp, reg, val) \
189 1.1 cgd (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
190 1.1 cgd
191 1.1 cgd /*
192 1.1 cgd * Function Prototypes
193 1.1 cgd */
194 1.1 cgd /*
195 1.1 cgd * Reset Hardware.
196 1.1 cgd *
197 1.1 cgd * Only looks at sc_dev.dv_xname, sc_iot and sc_ioh fields.
198 1.1 cgd */
199 1.1 cgd void isp_reset __P((struct ispsoftc *));
200 1.1 cgd
201 1.1 cgd /*
202 1.1 cgd * Initialize Hardware to known state
203 1.1 cgd */
204 1.1 cgd void isp_init __P((struct ispsoftc *));
205 1.1 cgd
206 1.1 cgd /*
207 1.1 cgd * Complete attachment of Hardware
208 1.1 cgd */
209 1.1 cgd void isp_attach __P((struct ispsoftc *));
210 1.1 cgd
211 1.1 cgd /*
212 1.1 cgd * Free any associated resources prior to decommissioning.
213 1.1 cgd */
214 1.1 cgd void isp_uninit __P((struct ispsoftc *));
215 1.1 cgd
216 1.1 cgd /*
217 1.1 cgd * Interrupt Service Routine
218 1.1 cgd */
219 1.1 cgd int isp_intr __P((void *));
220 1.1 cgd
221 1.1 cgd
222 1.1 cgd
223 1.1 cgd
224 1.1 cgd #endif /* _ISPVAR_H */
225