csc.c revision 1.11 1 /* $NetBSD: csc.c,v 1.11 2003/05/03 18:10:41 wiz Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Scott Stevens.
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, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Cumana SCSI-2 driver uses the SFAS216 generic driver
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/device.h>
47
48 #include <uvm/uvm_extern.h>
49
50 #include <dev/scsipi/scsi_all.h>
51 #include <dev/scsipi/scsipi_all.h>
52 #include <dev/scsipi/scsiconf.h>
53 #include <machine/io.h>
54 #include <machine/intr.h>
55 #include <machine/bootconfig.h>
56 #include <acorn32/podulebus/podulebus.h>
57 #include <acorn32/podulebus/sfasreg.h>
58 #include <acorn32/podulebus/sfasvar.h>
59 #include <acorn32/podulebus/cscreg.h>
60 #include <acorn32/podulebus/cscvar.h>
61 #include <dev/podulebus/podules.h>
62 #include <dev/podulebus/powerromreg.h>
63
64 int cscmatch(struct device *, struct cfdata *, void *);
65 void cscattach(struct device *, struct device *, void *);
66
67 CFATTACH_DECL(csc, sizeof(struct csc_softc),
68 cscmatch, cscattach, NULL, NULL);
69
70 int csc_intr(void *);
71 int csc_setup_dma(void *, void *, int, int);
72 int csc_build_dma_chain(void *, void *, void *, int);
73 int csc_need_bump(void *, void *, int);
74 void csc_led(void *, int);
75
76 void csc_set_dma_adr(struct sfas_softc *, void *);
77 void csc_set_dma_tc(struct sfas_softc *, unsigned int);
78 void csc_set_dma_mode(struct sfas_softc *, int);
79
80 /*
81 * if we are a Cumana SCSI-2 card
82 */
83 int
84 cscmatch(pdp, cf, auxp)
85 struct device *pdp;
86 struct cfdata *cf;
87 void *auxp;
88 {
89 struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
90
91 /* Look for the card */
92 if (pa->pa_product == PODULE_CUMANA_SCSI2)
93 return 1;
94
95 /* PowerROM */
96 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
97 podulebus_initloader(pa) == 0 &&
98 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI2)
99 return 1;
100
101 return 0;
102 }
103
104 void
105 cscattach(pdp, dp, auxp)
106 struct device *pdp;
107 struct device *dp;
108 void *auxp;
109 {
110 struct csc_softc *sc = (struct csc_softc *)dp;
111 struct podule_attach_args *pa;
112 csc_regmap_p rp = &sc->sc_regmap;
113 vu_char *fas;
114 int loop;
115
116 pa = (struct podule_attach_args *)auxp;
117
118 if (pa->pa_podule_number == -1)
119 panic("Podule has disappeared !");
120
121 sc->sc_specific.sc_podule_number = pa->pa_podule_number;
122 sc->sc_specific.sc_podule = pa->pa_podule;
123 sc->sc_specific.sc_iobase =
124 (vu_char *)sc->sc_specific.sc_podule->mod_base;
125
126 rp->status0 = &sc->sc_specific.sc_iobase[CSC_STATUS0];
127 rp->alatch = &sc->sc_specific.sc_iobase[CSC_ALATCH];
128 rp->dack = (vu_short *)&sc->sc_specific.sc_iobase[CSC_DACK];
129 fas = &sc->sc_specific.sc_iobase[CSC_FAS_OFFSET_BASE];
130
131 rp->FAS216.sfas_tc_low = &fas[CSC_FAS_OFFSET_TCL];
132 rp->FAS216.sfas_tc_mid = &fas[CSC_FAS_OFFSET_TCM];
133 rp->FAS216.sfas_fifo = &fas[CSC_FAS_OFFSET_FIFO];
134 rp->FAS216.sfas_command = &fas[CSC_FAS_OFFSET_COMMAND];
135 rp->FAS216.sfas_dest_id = &fas[CSC_FAS_OFFSET_DESTID];
136 rp->FAS216.sfas_timeout = &fas[CSC_FAS_OFFSET_TIMEOUT];
137 rp->FAS216.sfas_syncper = &fas[CSC_FAS_OFFSET_PERIOD];
138 rp->FAS216.sfas_syncoff = &fas[CSC_FAS_OFFSET_OFFSET];
139 rp->FAS216.sfas_config1 = &fas[CSC_FAS_OFFSET_CONFIG1];
140 rp->FAS216.sfas_clkconv = &fas[CSC_FAS_OFFSET_CLKCONV];
141 rp->FAS216.sfas_test = &fas[CSC_FAS_OFFSET_TEST];
142 rp->FAS216.sfas_config2 = &fas[CSC_FAS_OFFSET_CONFIG2];
143 rp->FAS216.sfas_config3 = &fas[CSC_FAS_OFFSET_CONFIG3];
144 rp->FAS216.sfas_tc_high = &fas[CSC_FAS_OFFSET_TCH];
145 rp->FAS216.sfas_fifo_bot = &fas[CSC_FAS_OFFSET_FIFOBOT];
146
147 sc->sc_softc.sc_fas = (sfas_regmap_p)rp;
148 sc->sc_softc.sc_spec = &sc->sc_specific;
149
150 sc->sc_softc.sc_led = csc_led;
151
152 sc->sc_softc.sc_setup_dma = csc_setup_dma;
153 sc->sc_softc.sc_build_dma_chain = csc_build_dma_chain;
154 sc->sc_softc.sc_need_bump = csc_need_bump;
155
156 sc->sc_softc.sc_clock_freq = 8; /* Cumana runs at 8MHz */
157 sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
158 sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/;
159 sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */
160
161 sc->sc_softc.sc_bump_sz = PAGE_SIZE;
162 sc->sc_softc.sc_bump_pa = 0x0;
163
164 sfasinitialize((struct sfas_softc *)sc);
165
166 sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev;
167 sc->sc_softc.sc_adapter.adapt_nchannels = 1;
168 sc->sc_softc.sc_adapter.adapt_openings = 7;
169 sc->sc_softc.sc_adapter.adapt_max_periph = 1;
170 sc->sc_softc.sc_adapter.adapt_ioctl = NULL;
171 sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys;
172 sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request;
173
174 sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter;
175 sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype;
176 sc->sc_softc.sc_channel.chan_channel = 0;
177 sc->sc_softc.sc_channel.chan_ntargets = 8;
178 sc->sc_softc.sc_channel.chan_nluns = 8;
179 sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id;
180
181 /* Provide an override for the host id */
182 (void)get_bootconf_option(boot_args, "csc.hostid",
183 BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id);
184
185 printf(": host=%d", sc->sc_softc.sc_channel.chan_id);
186
187 /* initialise the alatch */
188 sc->sc_specific.sc_alatch_defs = (CSC_POLL?0:CSC_ALATCH_DEFS_INTEN);
189 for (loop = 0; loop < 8; loop ++) {
190 if(loop != 3)
191 *rp->alatch = (loop << 1) |
192 ((sc->sc_specific.sc_alatch_defs & (1 << loop))?1:0);
193 }
194
195 #if CSC_POLL == 0
196 evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL,
197 dp->dv_xname, "intr");
198 sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
199 csc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt);
200 if (sc->sc_softc.sc_ih == NULL)
201 panic("%s: Cannot install IRQ handler", dp->dv_xname);
202 #else
203 printf(" polling");
204 sc->sc_softc.sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY;
205 #endif
206 printf("\n");
207
208 /* attach all scsi units on us */
209 config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
210 }
211
212
213 int
214 csc_intr(arg)
215 void *arg;
216 {
217 struct sfas_softc *dev = arg;
218 csc_regmap_p rp;
219 int quickints;
220
221 rp = (csc_regmap_p)dev->sc_fas;
222
223 if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
224 quickints = 16;
225 do {
226 dev->sc_status = *rp->FAS216.sfas_status;
227 dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
228
229 if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
230 dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
231 dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
232 }
233 sfasintr(dev);
234
235 } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
236 && --quickints);
237 }
238
239 return(0); /* Pass interrupt on down the chain */
240 }
241
242 /* Load transfer address into DMA register */
243 void
244 csc_set_dma_adr(sc, ptr)
245 struct sfas_softc *sc;
246 void *ptr;
247 {
248 return;
249 }
250
251 /* Set DMA transfer counter */
252 void
253 csc_set_dma_tc(sc, len)
254 struct sfas_softc *sc;
255 unsigned int len;
256 {
257 *sc->sc_fas->sfas_tc_low = len; len >>= 8;
258 *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
259 *sc->sc_fas->sfas_tc_high = len;
260 }
261
262 /* Set DMA mode */
263 void
264 csc_set_dma_mode(sc, mode)
265 struct sfas_softc *sc;
266 int mode;
267 {
268 }
269
270 /* Initialize DMA for transfer */
271 int
272 csc_setup_dma(sc, ptr, len, mode)
273 void *sc;
274 void *ptr;
275 int len;
276 int mode;
277 {
278
279 return (0);
280 }
281
282 /* Check if address and len is ok for DMA transfer */
283 int
284 csc_need_bump(sc, ptr, len)
285 void *sc;
286 void *ptr;
287 int len;
288 {
289 int p;
290
291 p = (int)ptr & 0x03;
292
293 if (p) {
294 p = 4-p;
295
296 if (len < 256)
297 p = len;
298 }
299
300 return(p);
301 }
302
303 /* Interrupt driven routines */
304 int
305 csc_build_dma_chain(sc, chain, p, l)
306 void *sc;
307 void *chain;
308 void *p;
309 int l;
310 {
311 return(0);
312 }
313
314 /* Turn on/off led */
315 void
316 csc_led(v, mode)
317 void *v;
318 int mode;
319 {
320 struct sfas_softc *sc = v;
321 csc_regmap_p rp;
322
323 rp = (csc_regmap_p)sc->sc_fas;
324
325 if (mode) {
326 sc->sc_led_status++;
327 } else {
328 if (sc->sc_led_status)
329 sc->sc_led_status--;
330 }
331 }
332