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