ivsc.c revision 1.33 1 1.33 agc /* $NetBSD: ivsc.c,v 1.33 2003/08/07 16:26:42 agc Exp $ */
2 1.5 cgd
3 1.1 chopps /*
4 1.1 chopps * Copyright (c) 1982, 1990 The Regents of the University of California.
5 1.1 chopps * All rights reserved.
6 1.1 chopps *
7 1.1 chopps * Redistribution and use in source and binary forms, with or without
8 1.1 chopps * modification, are permitted provided that the following conditions
9 1.1 chopps * are met:
10 1.1 chopps * 1. Redistributions of source code must retain the above copyright
11 1.1 chopps * notice, this list of conditions and the following disclaimer.
12 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chopps * notice, this list of conditions and the following disclaimer in the
14 1.1 chopps * documentation and/or other materials provided with the distribution.
15 1.33 agc * 3. Neither the name of the University nor the names of its contributors
16 1.33 agc * may be used to endorse or promote products derived from this software
17 1.33 agc * without specific prior written permission.
18 1.33 agc *
19 1.33 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.33 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.33 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.33 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.33 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.33 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.33 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.33 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.33 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.33 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.33 agc * SUCH DAMAGE.
30 1.33 agc *
31 1.33 agc * @(#)ivsdma.c
32 1.33 agc */
33 1.33 agc
34 1.33 agc /*
35 1.33 agc * Copyright (c) 1994 Michael L. Hitch
36 1.33 agc *
37 1.33 agc * Redistribution and use in source and binary forms, with or without
38 1.33 agc * modification, are permitted provided that the following conditions
39 1.33 agc * are met:
40 1.33 agc * 1. Redistributions of source code must retain the above copyright
41 1.33 agc * notice, this list of conditions and the following disclaimer.
42 1.33 agc * 2. Redistributions in binary form must reproduce the above copyright
43 1.33 agc * notice, this list of conditions and the following disclaimer in the
44 1.33 agc * documentation and/or other materials provided with the distribution.
45 1.1 chopps * 3. All advertising materials mentioning features or use of this software
46 1.1 chopps * must display the following acknowledgement:
47 1.1 chopps * This product includes software developed by the University of
48 1.1 chopps * California, Berkeley and its contributors.
49 1.1 chopps * 4. Neither the name of the University nor the names of its contributors
50 1.1 chopps * may be used to endorse or promote products derived from this software
51 1.1 chopps * without specific prior written permission.
52 1.1 chopps *
53 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 1.1 chopps * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 1.1 chopps * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 1.1 chopps * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 1.1 chopps * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 1.1 chopps * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 1.1 chopps * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1 chopps * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1 chopps * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1 chopps * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1 chopps * SUCH DAMAGE.
64 1.1 chopps *
65 1.1 chopps * @(#)ivsdma.c
66 1.1 chopps */
67 1.30 aymeric
68 1.30 aymeric #include <sys/cdefs.h>
69 1.33 agc __KERNEL_RCSID(0, "$NetBSD: ivsc.c,v 1.33 2003/08/07 16:26:42 agc Exp $");
70 1.30 aymeric
71 1.2 chopps #include <sys/param.h>
72 1.2 chopps #include <sys/systm.h>
73 1.2 chopps #include <sys/kernel.h>
74 1.2 chopps #include <sys/device.h>
75 1.22 bouyer #include <dev/scsipi/scsi_all.h>
76 1.22 bouyer #include <dev/scsipi/scsipi_all.h>
77 1.22 bouyer #include <dev/scsipi/scsiconf.h>
78 1.2 chopps #include <amiga/amiga/custom.h>
79 1.2 chopps #include <amiga/amiga/device.h>
80 1.9 chopps #include <amiga/amiga/isr.h>
81 1.2 chopps #include <amiga/dev/scireg.h>
82 1.2 chopps #include <amiga/dev/scivar.h>
83 1.7 chopps #include <amiga/dev/zbusvar.h>
84 1.2 chopps
85 1.29 aymeric void ivscattach(struct device *, struct device *, void *);
86 1.29 aymeric int ivscmatch(struct device *, struct cfdata *, void *);
87 1.2 chopps
88 1.29 aymeric int ivsc_intr(void *);
89 1.29 aymeric int ivsc_dma_xfer_in(struct sci_softc *dev, int len,
90 1.29 aymeric register u_char *buf, int phase);
91 1.29 aymeric int ivsc_dma_xfer_out(struct sci_softc *dev, int len,
92 1.29 aymeric register u_char *buf, int phase);
93 1.2 chopps
94 1.2 chopps
95 1.2 chopps #ifdef DEBUG
96 1.2 chopps extern int sci_debug;
97 1.19 christos #define QPRINTF(a) if (sci_debug > 1) printf a
98 1.15 veego #else
99 1.15 veego #define QPRINTF(a)
100 1.2 chopps #endif
101 1.2 chopps
102 1.2 chopps extern int sci_data_wait;
103 1.2 chopps
104 1.11 chopps int ivsdma_pseudo = 1; /* 0=off, 1=on */
105 1.11 chopps
106 1.32 thorpej CFATTACH_DECL(ivsc, sizeof(struct sci_softc),
107 1.32 thorpej ivscmatch, ivscattach, NULL, NULL);
108 1.1 chopps
109 1.1 chopps /*
110 1.2 chopps * if this is an IVS board
111 1.1 chopps */
112 1.2 chopps int
113 1.29 aymeric ivscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
114 1.2 chopps {
115 1.7 chopps struct zbus_args *zap;
116 1.1 chopps
117 1.2 chopps zap = auxp;
118 1.1 chopps
119 1.2 chopps /*
120 1.2 chopps * Check manufacturer and product id.
121 1.2 chopps */
122 1.2 chopps if (zap->manid != 2112 || /* If manufacturer is IVS */
123 1.12 chopps (zap->prodid != 48 && /* product = Trumpcard 500 */
124 1.12 chopps zap->prodid != 52 && /* product = Trumpcard */
125 1.2 chopps zap->prodid != 243)) /* product = Vector SCSI */
126 1.2 chopps return(0); /* didn't match */
127 1.2 chopps return(1);
128 1.2 chopps }
129 1.1 chopps
130 1.1 chopps void
131 1.29 aymeric ivscattach(struct device *pdp, struct device *dp, void *auxp)
132 1.2 chopps {
133 1.2 chopps volatile u_char *rp;
134 1.28 bouyer struct sci_softc *sc = (struct sci_softc *)dp;
135 1.7 chopps struct zbus_args *zap;
136 1.28 bouyer struct scsipi_adapter *adapt = &sc->sc_adapter;
137 1.28 bouyer struct scsipi_channel *chan = &sc->sc_channel;
138 1.3 chopps
139 1.19 christos printf("\n");
140 1.2 chopps
141 1.2 chopps zap = auxp;
142 1.29 aymeric
143 1.27 tron rp = (u_char *)zap->va + 0x40;
144 1.2 chopps sc->sci_data = rp;
145 1.2 chopps sc->sci_odata = rp;
146 1.2 chopps sc->sci_icmd = rp + 2;
147 1.2 chopps sc->sci_mode = rp + 4;
148 1.2 chopps sc->sci_tcmd = rp + 6;
149 1.2 chopps sc->sci_bus_csr = rp + 8;
150 1.2 chopps sc->sci_sel_enb = rp + 8;
151 1.2 chopps sc->sci_csr = rp + 10;
152 1.2 chopps sc->sci_dma_send = rp + 10;
153 1.2 chopps sc->sci_idata = rp + 12;
154 1.2 chopps sc->sci_trecv = rp + 12;
155 1.2 chopps sc->sci_iack = rp + 14;
156 1.2 chopps sc->sci_irecv = rp + 14;
157 1.2 chopps
158 1.11 chopps if (ivsdma_pseudo == 1) {
159 1.11 chopps sc->dma_xfer_in = ivsc_dma_xfer_in;
160 1.11 chopps sc->dma_xfer_out = ivsc_dma_xfer_out;
161 1.11 chopps }
162 1.2 chopps
163 1.9 chopps sc->sc_isr.isr_intr = ivsc_intr;
164 1.9 chopps sc->sc_isr.isr_arg = sc;
165 1.9 chopps sc->sc_isr.isr_ipl = 2;
166 1.9 chopps add_isr(&sc->sc_isr);
167 1.9 chopps
168 1.2 chopps scireset(sc);
169 1.2 chopps
170 1.28 bouyer /*
171 1.28 bouyer * Fill in the scsipi_adapter.
172 1.28 bouyer */
173 1.28 bouyer memset(adapt, 0, sizeof(*adapt));
174 1.28 bouyer adapt->adapt_dev = &sc->sc_dev;
175 1.28 bouyer adapt->adapt_nchannels = 1;
176 1.28 bouyer adapt->adapt_openings = 7;
177 1.28 bouyer adapt->adapt_max_periph = 1;
178 1.28 bouyer adapt->adapt_request = sci_scsipi_request;
179 1.28 bouyer adapt->adapt_minphys = sci_minphys;
180 1.25 thorpej
181 1.28 bouyer /*
182 1.28 bouyer * Fill in the scsipi_channel.
183 1.28 bouyer */
184 1.28 bouyer memset(chan, 0, sizeof(*chan));
185 1.28 bouyer chan->chan_adapter = adapt;
186 1.28 bouyer chan->chan_bustype = &scsi_bustype;
187 1.28 bouyer chan->chan_channel = 0;
188 1.29 aymeric chan->chan_ntargets = 8;
189 1.28 bouyer chan->chan_nluns = 8;
190 1.28 bouyer chan->chan_id = 7;
191 1.2 chopps
192 1.2 chopps /*
193 1.2 chopps * attach all scsi units on us
194 1.2 chopps */
195 1.28 bouyer config_found(dp, chan, scsiprint);
196 1.2 chopps }
197 1.2 chopps
198 1.2 chopps int
199 1.29 aymeric ivsc_dma_xfer_in(struct sci_softc *dev, int len, register u_char *buf,
200 1.29 aymeric int phase)
201 1.2 chopps {
202 1.11 chopps int wait = sci_data_wait;
203 1.11 chopps volatile register u_char *sci_dma = dev->sci_idata + 0x20;
204 1.11 chopps volatile register u_char *sci_csr = dev->sci_csr;
205 1.15 veego #ifdef DEBUG
206 1.15 veego u_char *obp = buf;
207 1.15 veego #endif
208 1.11 chopps
209 1.11 chopps QPRINTF(("ivsc_dma_in %d, csr=%02x\n", len, *dev->sci_bus_csr));
210 1.11 chopps
211 1.11 chopps *dev->sci_tcmd = phase;
212 1.11 chopps *dev->sci_mode |= SCI_MODE_DMA;
213 1.11 chopps *dev->sci_irecv = 0;
214 1.11 chopps
215 1.11 chopps while (len >= 128) {
216 1.11 chopps wait = sci_data_wait;
217 1.11 chopps while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
218 1.11 chopps (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
219 1.11 chopps if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
220 1.11 chopps || !(*dev->sci_bus_csr & SCI_BUS_BSY)
221 1.11 chopps || --wait < 0) {
222 1.11 chopps #ifdef DEBUG
223 1.11 chopps if (sci_debug)
224 1.19 christos printf("ivsc_dma_in2 fail: l%d i%x w%d\n",
225 1.15 veego len, *dev->sci_bus_csr, wait);
226 1.11 chopps #endif
227 1.11 chopps *dev->sci_mode &= ~SCI_MODE_DMA;
228 1.11 chopps return 0;
229 1.11 chopps }
230 1.11 chopps }
231 1.11 chopps
232 1.11 chopps #define R1 (*buf++ = *sci_dma)
233 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
234 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
235 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
236 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
237 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
238 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
239 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
240 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
241 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
242 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
243 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
244 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
245 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
246 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
247 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
248 1.11 chopps R1; R1; R1; R1; R1; R1; R1; R1;
249 1.11 chopps len -= 128;
250 1.11 chopps }
251 1.11 chopps
252 1.11 chopps while (len > 0) {
253 1.11 chopps wait = sci_data_wait;
254 1.11 chopps while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
255 1.11 chopps (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
256 1.11 chopps if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
257 1.11 chopps || !(*dev->sci_bus_csr & SCI_BUS_BSY)
258 1.11 chopps || --wait < 0) {
259 1.11 chopps #ifdef DEBUG
260 1.11 chopps if (sci_debug)
261 1.19 christos printf("ivsc_dma_in1 fail: l%d i%x w%d\n",
262 1.15 veego len, *dev->sci_bus_csr, wait);
263 1.11 chopps #endif
264 1.11 chopps *dev->sci_mode &= ~SCI_MODE_DMA;
265 1.11 chopps return 0;
266 1.11 chopps }
267 1.11 chopps }
268 1.11 chopps
269 1.11 chopps *buf++ = *sci_dma;
270 1.11 chopps len--;
271 1.11 chopps }
272 1.11 chopps
273 1.11 chopps QPRINTF(("ivsc_dma_in {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
274 1.11 chopps len, obp[0], obp[1], obp[2], obp[3], obp[4], obp[5],
275 1.11 chopps obp[6], obp[7], obp[8], obp[9]));
276 1.11 chopps
277 1.11 chopps *dev->sci_mode &= ~SCI_MODE_DMA;
278 1.11 chopps return 0;
279 1.2 chopps }
280 1.2 chopps
281 1.2 chopps int
282 1.29 aymeric ivsc_dma_xfer_out(struct sci_softc *dev, int len, register u_char *buf,
283 1.29 aymeric int phase)
284 1.1 chopps {
285 1.11 chopps int wait = sci_data_wait;
286 1.11 chopps volatile register u_char *sci_dma = dev->sci_data + 0x20;
287 1.11 chopps volatile register u_char *sci_csr = dev->sci_csr;
288 1.11 chopps
289 1.11 chopps QPRINTF(("ivsc_dma_out %d, csr=%02x\n", len, *dev->sci_bus_csr));
290 1.11 chopps
291 1.11 chopps QPRINTF(("ivsc_dma_out {%d} %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
292 1.11 chopps len, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
293 1.11 chopps buf[6], buf[7], buf[8], buf[9]));
294 1.11 chopps
295 1.11 chopps *dev->sci_tcmd = phase;
296 1.11 chopps *dev->sci_mode |= SCI_MODE_DMA;
297 1.11 chopps *dev->sci_icmd |= SCI_ICMD_DATA;
298 1.11 chopps *dev->sci_dma_send = 0;
299 1.11 chopps while (len > 0) {
300 1.11 chopps wait = sci_data_wait;
301 1.11 chopps while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) !=
302 1.11 chopps (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) {
303 1.11 chopps if (!(*sci_csr & SCI_CSR_PHASE_MATCH)
304 1.11 chopps || !(*dev->sci_bus_csr & SCI_BUS_BSY)
305 1.11 chopps || --wait < 0) {
306 1.11 chopps #ifdef DEBUG
307 1.11 chopps if (sci_debug)
308 1.19 christos printf("ivsc_dma_out fail: l%d i%x w%d\n",
309 1.15 veego len, *dev->sci_bus_csr, wait);
310 1.11 chopps #endif
311 1.11 chopps *dev->sci_mode &= ~SCI_MODE_DMA;
312 1.11 chopps return 0;
313 1.11 chopps }
314 1.11 chopps }
315 1.11 chopps
316 1.11 chopps *sci_dma = *buf++;
317 1.11 chopps len--;
318 1.11 chopps }
319 1.11 chopps
320 1.11 chopps wait = sci_data_wait;
321 1.11 chopps while ((*sci_csr & (SCI_CSR_DREQ|SCI_CSR_PHASE_MATCH)) ==
322 1.11 chopps SCI_CSR_PHASE_MATCH && --wait);
323 1.11 chopps
324 1.11 chopps
325 1.11 chopps *dev->sci_mode &= ~SCI_MODE_DMA;
326 1.11 chopps return 0;
327 1.1 chopps }
328 1.2 chopps
329 1.2 chopps int
330 1.29 aymeric ivsc_intr(void *arg)
331 1.2 chopps {
332 1.15 veego struct sci_softc *dev = arg;
333 1.2 chopps u_char stat;
334 1.2 chopps
335 1.9 chopps if ((*dev->sci_csr & SCI_CSR_INT) == 0)
336 1.9 chopps return(0);
337 1.9 chopps stat = *dev->sci_iack;
338 1.14 is /* XXXX is: something is missing here, at least a: */
339 1.14 is return(1);
340 1.2 chopps }
341