bztzsc.c revision 1.1 1 1.1 is /* $NetBSD: bztzsc.c,v 1.1 1996/12/16 16:17:29 is Exp $ */
2 1.1 is
3 1.1 is /*
4 1.1 is * Copyright (c) 1996 Ignatios Souvatzis
5 1.1 is * Copyright (c) 1982, 1990 The Regents of the University of California.
6 1.1 is * All rights reserved.
7 1.1 is *
8 1.1 is * Redistribution and use in source and binary forms, with or without
9 1.1 is * modification, are permitted provided that the following conditions
10 1.1 is * are met:
11 1.1 is * 1. Redistributions of source code must retain the above copyright
12 1.1 is * notice, this list of conditions and the following disclaimer.
13 1.1 is * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 is * notice, this list of conditions and the following disclaimer in the
15 1.1 is * documentation and/or other materials provided with the distribution.
16 1.1 is * 3. All advertising materials mentioning features or use of this software
17 1.1 is * must display the following acknowledgement:
18 1.1 is * This product contains software written by Ignatios Souvatzis for
19 1.1 is * the NetBSD project.
20 1.1 is * 4. Neither the name of the University nor the names of its contributors
21 1.1 is * may be used to endorse or promote products derived from this software
22 1.1 is * without specific prior written permission.
23 1.1 is *
24 1.1 is * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 is * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 is * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 is * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 is * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 is * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 is * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 is * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 is * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 is * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 is * SUCH DAMAGE.
35 1.1 is *
36 1.1 is */
37 1.1 is
38 1.1 is #include <sys/param.h>
39 1.1 is #include <sys/systm.h>
40 1.1 is #include <sys/kernel.h>
41 1.1 is #include <sys/device.h>
42 1.1 is #include <scsi/scsi_all.h>
43 1.1 is #include <scsi/scsiconf.h>
44 1.1 is #include <vm/vm.h>
45 1.1 is #include <vm/vm_kern.h>
46 1.1 is #include <vm/vm_page.h>
47 1.1 is #include <machine/pmap.h>
48 1.1 is #include <amiga/amiga/custom.h>
49 1.1 is #include <amiga/amiga/cc.h>
50 1.1 is #include <amiga/amiga/device.h>
51 1.1 is #include <amiga/amiga/isr.h>
52 1.1 is #include <amiga/dev/sfasreg.h>
53 1.1 is #include <amiga/dev/sfasvar.h>
54 1.1 is #include <amiga/dev/zbusvar.h>
55 1.1 is #include <amiga/dev/bztzscreg.h>
56 1.1 is #include <amiga/dev/bztzscvar.h>
57 1.1 is
58 1.1 is void bztzscattach __P((struct device *, struct device *, void *));
59 1.1 is int bztzscmatch __P((struct device *, void *, void *));
60 1.1 is
61 1.1 is struct scsi_adapter bztzsc_scsiswitch = {
62 1.1 is sfas_scsicmd,
63 1.1 is sfas_minphys,
64 1.1 is 0, /* no lun support */
65 1.1 is 0, /* no lun support */
66 1.1 is };
67 1.1 is
68 1.1 is struct scsi_device bztzsc_scsidev = {
69 1.1 is NULL, /* use default error handler */
70 1.1 is NULL, /* do not have a start functio */
71 1.1 is NULL, /* have no async handler */
72 1.1 is NULL, /* Use default done routine */
73 1.1 is };
74 1.1 is
75 1.1 is struct cfattach bztzsc_ca = {
76 1.1 is sizeof(struct bztzsc_softc), bztzscmatch, bztzscattach
77 1.1 is };
78 1.1 is
79 1.1 is struct cfdriver bztzsc_cd = {
80 1.1 is NULL, "bztzsc", DV_DULL, NULL, 0
81 1.1 is };
82 1.1 is
83 1.1 is int bztzsc_intr __P((void *));
84 1.1 is void bztzsc_set_dma_tc __P((struct sfas_softc *sc, unsigned int len));
85 1.1 is int bztzsc_setup_dma __P((struct sfas_softc *sc, vm_offset_t ptr, int len,
86 1.1 is int mode));
87 1.1 is int bztzsc_build_dma_chain __P((struct sfas_softc *sc,
88 1.1 is struct sfas_dma_chain *chain, void *p, int l));
89 1.1 is int bztzsc_need_bump __P((struct sfas_softc *sc, vm_offset_t ptr, int len));
90 1.1 is void bztzsc_led __P((struct sfas_softc *sc, int mode));
91 1.1 is
92 1.1 is /*
93 1.1 is * If we are an Phase 5 Devices Blizzard-2060 SCSI option:
94 1.1 is */
95 1.1 is int
96 1.1 is bztzscmatch(pdp, match, auxp)
97 1.1 is struct device *pdp;
98 1.1 is void *match, *auxp;
99 1.1 is {
100 1.1 is struct zbus_args *zap;
101 1.1 is volatile u_int8_t *ta;
102 1.1 is
103 1.1 is zap = auxp;
104 1.1 is
105 1.1 is if (zap->manid != 0x2140) /* Phase V ? */
106 1.1 is return(0);
107 1.1 is
108 1.1 is
109 1.1 is if (zap->prodid != 24) /* is it B2060? */
110 1.1 is return 0;
111 1.1 is
112 1.1 is ta = (vu_char *)(((char *)zap->va) + 0x1ff00 + 0x20);
113 1.1 is
114 1.1 is if (badbaddr((caddr_t)ta))
115 1.1 is return(0);
116 1.1 is
117 1.1 is *ta = 0;
118 1.1 is *ta = 1;
119 1.1 is DELAY(5);
120 1.1 is if (*ta != 1)
121 1.1 is return(0);
122 1.1 is
123 1.1 is return(1);
124 1.1 is }
125 1.1 is
126 1.1 is u_int32_t bztzsc_flags = 0;
127 1.1 is
128 1.1 is void
129 1.1 is bztzscattach(pdp, dp, auxp)
130 1.1 is struct device *pdp;
131 1.1 is struct device *dp;
132 1.1 is void *auxp;
133 1.1 is {
134 1.1 is struct bztzsc_softc *sc;
135 1.1 is struct zbus_args *zap;
136 1.1 is bztzsc_regmap_p rp;
137 1.1 is vu_char *fas;
138 1.1 is
139 1.1 is zap = auxp;
140 1.1 is
141 1.1 is fas = &((vu_char *)zap->va)[0x1ff00];
142 1.1 is
143 1.1 is sc = (struct bztzsc_softc *)dp;
144 1.1 is rp = &sc->sc_regmap;
145 1.1 is
146 1.1 is rp->FAS216.sfas_tc_low = &fas[0x00];
147 1.1 is rp->FAS216.sfas_tc_mid = &fas[0x04];
148 1.1 is rp->FAS216.sfas_fifo = &fas[0x08];
149 1.1 is rp->FAS216.sfas_command = &fas[0x0C];
150 1.1 is rp->FAS216.sfas_dest_id = &fas[0x10];
151 1.1 is rp->FAS216.sfas_timeout = &fas[0x14];
152 1.1 is rp->FAS216.sfas_syncper = &fas[0x18];
153 1.1 is rp->FAS216.sfas_syncoff = &fas[0x1C];
154 1.1 is rp->FAS216.sfas_config1 = &fas[0x20];
155 1.1 is rp->FAS216.sfas_clkconv = &fas[0x24];
156 1.1 is rp->FAS216.sfas_test = &fas[0x28];
157 1.1 is rp->FAS216.sfas_config2 = &fas[0x2C];
158 1.1 is rp->FAS216.sfas_config3 = &fas[0x30];
159 1.1 is rp->FAS216.sfas_tc_high = &fas[0x38];
160 1.1 is rp->FAS216.sfas_fifo_bot = &fas[0x3C];
161 1.1 is
162 1.1 is rp->hardbits = &fas[0xe0];
163 1.1 is rp->addrport = &fas[0xf0];
164 1.1 is
165 1.1 is sc->sc_softc.sc_fas = (sfas_regmap_p)rp;
166 1.1 is
167 1.1 is sc->sc_softc.sc_led = bztzsc_led;
168 1.1 is
169 1.1 is sc->sc_softc.sc_setup_dma = bztzsc_setup_dma;
170 1.1 is sc->sc_softc.sc_build_dma_chain = bztzsc_build_dma_chain;
171 1.1 is sc->sc_softc.sc_need_bump = bztzsc_need_bump;
172 1.1 is
173 1.1 is sc->sc_softc.sc_clock_freq = 40; /* Phase5 SCSI all run at 40MHz */
174 1.1 is sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
175 1.1 is
176 1.1 is sc->sc_softc.sc_config_flags = bztzsc_flags; /* for the moment */
177 1.1 is
178 1.1 is sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */
179 1.1 is
180 1.1 is sc->sc_softc.sc_bump_sz = NBPG; /* XXX should be the VM pagesize */
181 1.1 is sc->sc_softc.sc_bump_pa = 0x0;
182 1.1 is
183 1.1 is sfasinitialize((struct sfas_softc *)sc);
184 1.1 is
185 1.1 is sc->sc_softc.sc_link.adapter_softc = sc;
186 1.1 is sc->sc_softc.sc_link.adapter_target = sc->sc_softc.sc_host_id;
187 1.1 is sc->sc_softc.sc_link.adapter = &bztzsc_scsiswitch;
188 1.1 is sc->sc_softc.sc_link.device = &bztzsc_scsidev;
189 1.1 is sc->sc_softc.sc_link.openings = 1;
190 1.1 is
191 1.1 is sc->sc_softc.sc_isr.isr_intr = bztzsc_intr;
192 1.1 is sc->sc_softc.sc_isr.isr_arg = &sc->sc_softc;
193 1.1 is sc->sc_softc.sc_isr.isr_ipl = 2;
194 1.1 is add_isr(&sc->sc_softc.sc_isr);
195 1.1 is
196 1.1 is /* We don't want interrupt until we're initialized! */
197 1.1 is
198 1.1 is printf("\n");
199 1.1 is
200 1.1 is /* attach all scsi units on us */
201 1.1 is config_found(dp, &sc->sc_softc.sc_link, scsiprint);
202 1.1 is }
203 1.1 is
204 1.1 is int
205 1.1 is bztzsc_intr(arg)
206 1.1 is void *arg;
207 1.1 is {
208 1.1 is struct sfas_softc *dev = arg;
209 1.1 is bztzsc_regmap_p rp;
210 1.1 is int quickints;
211 1.1 is
212 1.1 is rp = (bztzsc_regmap_p)dev->sc_fas;
213 1.1 is
214 1.1 is if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
215 1.1 is quickints = 16;
216 1.1 is do {
217 1.1 is dev->sc_status = *rp->FAS216.sfas_status;
218 1.1 is dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
219 1.1 is
220 1.1 is if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
221 1.1 is dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
222 1.1 is dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
223 1.1 is }
224 1.1 is sfasintr(dev);
225 1.1 is
226 1.1 is } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
227 1.1 is && --quickints);
228 1.1 is
229 1.1 is return(1);
230 1.1 is }
231 1.1 is return(0);
232 1.1 is }
233 1.1 is
234 1.1 is /* Set DMA transfer counter */
235 1.1 is void
236 1.1 is bztzsc_set_dma_tc(sc, len)
237 1.1 is struct sfas_softc *sc;
238 1.1 is unsigned int len;
239 1.1 is {
240 1.1 is *sc->sc_fas->sfas_tc_low = len; len >>= 8;
241 1.1 is *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
242 1.1 is *sc->sc_fas->sfas_tc_high = len;
243 1.1 is }
244 1.1 is
245 1.1 is /* Initialize DMA for transfer */
246 1.1 is int
247 1.1 is bztzsc_setup_dma(sc, ptr, len, mode)
248 1.1 is struct sfas_softc *sc;
249 1.1 is vm_offset_t ptr;
250 1.1 is int len;
251 1.1 is int mode;
252 1.1 is {
253 1.1 is int retval;
254 1.1 is u_int32_t d;
255 1.1 is bztzsc_regmap_p rp;
256 1.1 is
257 1.1 is retval = 0;
258 1.1 is
259 1.1 is switch(mode) {
260 1.1 is
261 1.1 is case SFAS_DMA_READ:
262 1.1 is case SFAS_DMA_WRITE:
263 1.1 is
264 1.1 is rp = (bztzsc_regmap_p)sc->sc_fas;
265 1.1 is
266 1.1 is d = (u_int32_t)ptr;
267 1.1 is d >>= 1;
268 1.1 is
269 1.1 is if (mode == SFAS_DMA_WRITE)
270 1.1 is d |= (1L << 31);
271 1.1 is
272 1.1 is rp->addrport[12] = (u_int8_t)d;
273 1.1 is __asm __volatile("nop");
274 1.1 is
275 1.1 is d >>= 8;
276 1.1 is rp->addrport[8] = (u_int8_t)d;
277 1.1 is __asm __volatile("nop");
278 1.1 is
279 1.1 is d >>= 8;
280 1.1 is rp->addrport[4] = (u_int8_t)d;
281 1.1 is __asm __volatile("nop");
282 1.1 is
283 1.1 is d >>= 8;
284 1.1 is rp->addrport[0] = (u_int8_t)d;
285 1.1 is __asm __volatile("nop");
286 1.1 is
287 1.1 is bztzsc_set_dma_tc(sc, len);
288 1.1 is break;
289 1.1 is
290 1.1 is case SFAS_DMA_CLEAR:
291 1.1 is default:
292 1.1 is retval = (*sc->sc_fas->sfas_tc_high << 16) |
293 1.1 is (*sc->sc_fas->sfas_tc_mid << 8) |
294 1.1 is *sc->sc_fas->sfas_tc_low;
295 1.1 is
296 1.1 is bztzsc_set_dma_tc(sc, 0);
297 1.1 is break;
298 1.1 is }
299 1.1 is
300 1.1 is return(retval);
301 1.1 is }
302 1.1 is
303 1.1 is /* Check if address and len is ok for DMA transfer */
304 1.1 is int
305 1.1 is bztzsc_need_bump(sc, ptr, len)
306 1.1 is struct sfas_softc *sc;
307 1.1 is vm_offset_t ptr;
308 1.1 is int len;
309 1.1 is {
310 1.1 is int p;
311 1.1 is
312 1.1 is p = (int)ptr & 0x03;
313 1.1 is
314 1.1 is if (p) {
315 1.1 is p = 4-p;
316 1.1 is
317 1.1 is if (len < 256)
318 1.1 is p = len;
319 1.1 is }
320 1.1 is return(p);
321 1.1 is }
322 1.1 is
323 1.1 is /* Interrupt driven routines */
324 1.1 is /* XXX some of this is voodoo might be remnants intended for the Fastlane. */
325 1.1 is int
326 1.1 is bztzsc_build_dma_chain(sc, chain, p, l)
327 1.1 is struct sfas_softc *sc;
328 1.1 is struct sfas_dma_chain *chain;
329 1.1 is void *p;
330 1.1 is int l;
331 1.1 is {
332 1.1 is vm_offset_t pa, lastpa;
333 1.1 is char *ptr;
334 1.1 is int len, prelen, max_t, n;
335 1.1 is
336 1.1 is if (l == 0)
337 1.1 is return(0);
338 1.1 is
339 1.1 is #define set_link(n, p, l, f)\
340 1.1 is do { chain[n].ptr = (p); chain[n].len = (l); chain[n++].flg = (f); } while(0)
341 1.1 is
342 1.1 is n = 0;
343 1.1 is
344 1.1 is if (l < 512)
345 1.1 is set_link(n, (vm_offset_t)p, l, SFAS_CHAIN_BUMP);
346 1.1 is else if ((p >= (void *)0xFF000000)
347 1.1 is #if defined(M68040) || defined(M68060)
348 1.1 is && ((mmutype == MMU_68040) && (p >= (void *)0xFFFC0000))
349 1.1 is #endif
350 1.1 is ) {
351 1.1 is while(l != 0) {
352 1.1 is len = ((l > sc->sc_bump_sz) ? sc->sc_bump_sz : l);
353 1.1 is
354 1.1 is set_link(n, (vm_offset_t)p, len, SFAS_CHAIN_BUMP);
355 1.1 is
356 1.1 is p += len;
357 1.1 is l -= len;
358 1.1 is }
359 1.1 is } else {
360 1.1 is ptr = p;
361 1.1 is len = l;
362 1.1 is
363 1.1 is pa = kvtop(ptr);
364 1.1 is prelen = ((int)ptr & 0x03);
365 1.1 is
366 1.1 is if (prelen) {
367 1.1 is prelen = 4-prelen;
368 1.1 is set_link(n, (vm_offset_t)ptr, prelen, SFAS_CHAIN_BUMP);
369 1.1 is ptr += prelen;
370 1.1 is len -= prelen;
371 1.1 is }
372 1.1 is
373 1.1 is lastpa = 0;
374 1.1 is while(len > 3) {
375 1.1 is pa = kvtop(ptr);
376 1.1 is max_t = NBPG - (pa & PGOFSET);
377 1.1 is if (max_t > len)
378 1.1 is max_t = len;
379 1.1 is
380 1.1 is max_t &= ~3;
381 1.1 is
382 1.1 is if (lastpa == pa)
383 1.1 is sc->sc_chain[n-1].len += max_t;
384 1.1 is else
385 1.1 is set_link(n, pa, max_t, SFAS_CHAIN_DMA);
386 1.1 is
387 1.1 is lastpa = pa+max_t;
388 1.1 is
389 1.1 is ptr += max_t;
390 1.1 is len -= max_t;
391 1.1 is }
392 1.1 is
393 1.1 is if (len)
394 1.1 is set_link(n, (vm_offset_t)ptr, len, SFAS_CHAIN_BUMP);
395 1.1 is }
396 1.1 is
397 1.1 is return(n);
398 1.1 is }
399 1.1 is
400 1.1 is /* real one for 2060 */
401 1.1 is void
402 1.1 is bztzsc_led(sc, mode)
403 1.1 is struct sfas_softc *sc;
404 1.1 is int mode;
405 1.1 is {
406 1.1 is bztzsc_regmap_p rp;
407 1.1 is
408 1.1 is rp = (bztzsc_regmap_p)sc->sc_fas;
409 1.1 is
410 1.1 is if (mode)
411 1.1 is *rp->hardbits = 0x00; /* Led on, Int on */
412 1.1 is else
413 1.1 is *rp->hardbits = 0x02; /* Led off, Int on */
414 1.1 is }
415