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