csc.c revision 1.5 1 /* $NetBSD: csc.c,v 1.5 2002/09/27 15:35:30 provos 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 #include <dev/scsipi/scsi_all.h>
48 #include <dev/scsipi/scsipi_all.h>
49 #include <dev/scsipi/scsiconf.h>
50 #include <uvm/uvm_extern.h>
51 #include <machine/pmap.h>
52 #include <machine/io.h>
53 #include <machine/intr.h>
54 #include <machine/bootconfig.h>
55 #include <acorn32/podulebus/podulebus.h>
56 #include <acorn32/podulebus/sfasreg.h>
57 #include <acorn32/podulebus/sfasvar.h>
58 #include <acorn32/podulebus/cscreg.h>
59 #include <acorn32/podulebus/cscvar.h>
60 #include <dev/podulebus/podules.h>
61 #include <dev/podulebus/powerromreg.h>
62
63 void cscattach __P((struct device *, struct device *, void *));
64 int cscmatch __P((struct device *, struct cfdata *, void *));
65
66 struct cfattach csc_ca = {
67 sizeof(struct csc_softc), cscmatch, cscattach
68 };
69
70 int csc_intr __P((void *arg));
71 int csc_setup_dma __P((struct sfas_softc *sc, void *ptr, int len,
72 int mode));
73 int csc_build_dma_chain __P((struct sfas_softc *sc,
74 struct sfas_dma_chain *chain, void *p, int l));
75 int csc_need_bump __P((struct sfas_softc *sc, void *ptr, int len));
76 void csc_led __P((struct sfas_softc *sc, int mode));
77
78 /*
79 * if we are a Cumana SCSI-2 card
80 */
81 int
82 cscmatch(pdp, cf, auxp)
83 struct device *pdp;
84 struct cfdata *cf;
85 void *auxp;
86 {
87 struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
88
89 /* Look for the card */
90 if (pa->pa_product == PODULE_CUMANA_SCSI2)
91 return 1;
92
93 /* PowerROM */
94 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
95 podulebus_initloader(pa) == 0 &&
96 podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI2)
97 return 1;
98
99 return 0;
100 }
101
102 void
103 cscattach(pdp, dp, auxp)
104 struct device *pdp;
105 struct device *dp;
106 void *auxp;
107 {
108 struct csc_softc *sc = (struct csc_softc *)dp;
109 struct podule_attach_args *pa;
110 csc_regmap_p rp = &sc->sc_regmap;
111 vu_char *fas;
112 int loop;
113
114 pa = (struct podule_attach_args *)auxp;
115
116 if (pa->pa_podule_number == -1)
117 panic("Podule has disappeared !");
118
119 sc->sc_specific.sc_podule_number = pa->pa_podule_number;
120 sc->sc_specific.sc_podule = pa->pa_podule;
121 sc->sc_specific.sc_iobase =
122 (vu_char *)sc->sc_specific.sc_podule->mod_base;
123
124 rp->status0 = &sc->sc_specific.sc_iobase[CSC_STATUS0];
125 rp->alatch = &sc->sc_specific.sc_iobase[CSC_ALATCH];
126 rp->dack = (vu_short *)&sc->sc_specific.sc_iobase[CSC_DACK];
127 fas = &sc->sc_specific.sc_iobase[CSC_FAS_OFFSET_BASE];
128
129 rp->FAS216.sfas_tc_low = &fas[CSC_FAS_OFFSET_TCL];
130 rp->FAS216.sfas_tc_mid = &fas[CSC_FAS_OFFSET_TCM];
131 rp->FAS216.sfas_fifo = &fas[CSC_FAS_OFFSET_FIFO];
132 rp->FAS216.sfas_command = &fas[CSC_FAS_OFFSET_COMMAND];
133 rp->FAS216.sfas_dest_id = &fas[CSC_FAS_OFFSET_DESTID];
134 rp->FAS216.sfas_timeout = &fas[CSC_FAS_OFFSET_TIMEOUT];
135 rp->FAS216.sfas_syncper = &fas[CSC_FAS_OFFSET_PERIOD];
136 rp->FAS216.sfas_syncoff = &fas[CSC_FAS_OFFSET_OFFSET];
137 rp->FAS216.sfas_config1 = &fas[CSC_FAS_OFFSET_CONFIG1];
138 rp->FAS216.sfas_clkconv = &fas[CSC_FAS_OFFSET_CLKCONV];
139 rp->FAS216.sfas_test = &fas[CSC_FAS_OFFSET_TEST];
140 rp->FAS216.sfas_config2 = &fas[CSC_FAS_OFFSET_CONFIG2];
141 rp->FAS216.sfas_config3 = &fas[CSC_FAS_OFFSET_CONFIG3];
142 rp->FAS216.sfas_tc_high = &fas[CSC_FAS_OFFSET_TCH];
143 rp->FAS216.sfas_fifo_bot = &fas[CSC_FAS_OFFSET_FIFOBOT];
144
145 sc->sc_softc.sc_fas = (sfas_regmap_p)rp;
146 sc->sc_softc.sc_spec = &sc->sc_specific;
147
148 sc->sc_softc.sc_led = csc_led;
149
150 sc->sc_softc.sc_setup_dma = csc_setup_dma;
151 sc->sc_softc.sc_build_dma_chain = csc_build_dma_chain;
152 sc->sc_softc.sc_need_bump = csc_need_bump;
153
154 sc->sc_softc.sc_clock_freq = 8; /* Cumana runs at 8MHz */
155 sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
156 sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/;
157 sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */
158
159 sc->sc_softc.sc_bump_sz = NBPG;
160 sc->sc_softc.sc_bump_pa = 0x0;
161
162 sfasinitialize((struct sfas_softc *)sc);
163
164 sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev;
165 sc->sc_softc.sc_adapter.adapt_nchannels = 1;
166 sc->sc_softc.sc_adapter.adapt_openings = 7;
167 sc->sc_softc.sc_adapter.adapt_max_periph = 1;
168 sc->sc_softc.sc_adapter.adapt_ioctl = NULL;
169 sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys;
170 sc->sc_softc.sc_adapter.adapt_request = sfas_scsi_request;
171
172 sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter;
173 sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype;
174 sc->sc_softc.sc_channel.chan_channel = 0;
175 sc->sc_softc.sc_channel.chan_ntargets = 8;
176 sc->sc_softc.sc_channel.chan_nluns = 8;
177 sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id;
178
179 /* Provide an override for the host id */
180 (void)get_bootconf_option(boot_args, "csc.hostid",
181 BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id);
182
183 printf(": host=%d", sc->sc_softc.sc_channel.chan_id);
184
185 /* initialise the alatch */
186 sc->sc_specific.sc_alatch_defs = (CSC_POLL?0:CSC_ALATCH_DEFS_INTEN);
187 for (loop = 0; loop < 8; loop ++) {
188 if(loop != 3)
189 *rp->alatch = (loop << 1) |
190 ((sc->sc_specific.sc_alatch_defs & (1 << loop))?1:0);
191 }
192
193 #if CSC_POLL == 0
194 evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL,
195 dp->dv_xname, "intr");
196 sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
197 csc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt);
198 if (sc->sc_softc.sc_ih == NULL)
199 panic("%s: Cannot install IRQ handler", dp->dv_xname);
200 #else
201 printf(" polling");
202 sc->sc_softc.sc_adapter.adapt_flags |= SCSIPI_ADAPT_POLL_ONLY;
203 #endif
204 printf("\n");
205
206 /* attach all scsi units on us */
207 config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
208 }
209
210
211 int
212 csc_intr(arg)
213 void *arg;
214 {
215 struct sfas_softc *dev = arg;
216 csc_regmap_p rp;
217 int quickints;
218
219 rp = (csc_regmap_p)dev->sc_fas;
220
221 if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
222 quickints = 16;
223 do {
224 dev->sc_status = *rp->FAS216.sfas_status;
225 dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
226
227 if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
228 dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
229 dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
230 }
231 sfasintr(dev);
232
233 } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
234 && --quickints);
235 }
236
237 return(0); /* Pass interrupt on down the chain */
238 }
239
240 /* Load transfer address into dma register */
241 void
242 csc_set_dma_adr(sc, ptr)
243 struct sfas_softc *sc;
244 void *ptr;
245 {
246 return;
247 }
248
249 /* Set DMA transfer counter */
250 void
251 csc_set_dma_tc(sc, len)
252 struct sfas_softc *sc;
253 unsigned int len;
254 {
255 *sc->sc_fas->sfas_tc_low = len; len >>= 8;
256 *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
257 *sc->sc_fas->sfas_tc_high = len;
258 }
259
260 /* Set DMA mode */
261 void
262 csc_set_dma_mode(sc, mode)
263 struct sfas_softc *sc;
264 int mode;
265 {
266 }
267
268 /* Initialize DMA for transfer */
269 int
270 csc_setup_dma(sc, ptr, len, mode)
271 struct sfas_softc *sc;
272 void *ptr;
273 int len;
274 int mode;
275 {
276 return(0);
277 }
278
279 /* Check if address and len is ok for DMA transfer */
280 int
281 csc_need_bump(sc, ptr, len)
282 struct sfas_softc *sc;
283 void *ptr;
284 int len;
285 {
286 int p;
287
288 p = (int)ptr & 0x03;
289
290 if (p) {
291 p = 4-p;
292
293 if (len < 256)
294 p = len;
295 }
296
297 return(p);
298 }
299
300 /* Interrupt driven routines */
301 int
302 csc_build_dma_chain(sc, chain, p, l)
303 struct sfas_softc *sc;
304 struct sfas_dma_chain *chain;
305 void *p;
306 int l;
307 {
308 return(0);
309 }
310
311 /* Turn on/off led */
312 void
313 csc_led(sc, mode)
314 struct sfas_softc *sc;
315 int mode;
316 {
317 csc_regmap_p rp;
318
319 rp = (csc_regmap_p)sc->sc_fas;
320
321 if (mode) {
322 sc->sc_led_status++;
323 } else {
324 if (sc->sc_led_status)
325 sc->sc_led_status--;
326 }
327 }
328