csc.c revision 1.2 1 /* $NetBSD: csc.c,v 1.2 2001/11/27 00:53:12 thorpej 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 void csc_scsi_request __P((struct scsipi_channel *,
66 scsipi_adapter_req_t, void *));
67
68 struct cfattach csc_ca = {
69 sizeof(struct csc_softc), cscmatch, cscattach
70 };
71
72 int csc_intr __P((void *arg));
73 int csc_setup_dma __P((struct sfas_softc *sc, void *ptr, int len,
74 int mode));
75 int csc_build_dma_chain __P((struct sfas_softc *sc,
76 struct sfas_dma_chain *chain, void *p, int l));
77 int csc_need_bump __P((struct sfas_softc *sc, void *ptr, int len));
78 void csc_led __P((struct sfas_softc *sc, int mode));
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 (matchpodule(pa, MANUFACTURER_CUMANA, PODULE_CUMANA_SCSI2, -1))
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 = NBPG;
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 = csc_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\n", dp->dv_xname);
202 #else
203 printf(" polling");
204 #endif
205 printf("\n");
206
207 /* attach all scsi units on us */
208 config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
209 }
210
211
212 int
213 csc_intr(arg)
214 void *arg;
215 {
216 struct sfas_softc *dev = arg;
217 csc_regmap_p rp;
218 int quickints;
219
220 rp = (csc_regmap_p)dev->sc_fas;
221
222 if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
223 quickints = 16;
224 do {
225 dev->sc_status = *rp->FAS216.sfas_status;
226 dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
227
228 if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
229 dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
230 dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
231 }
232 sfasintr(dev);
233
234 } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
235 && --quickints);
236 }
237
238 return(0); /* Pass interrupt on down the chain */
239 }
240
241 /* Load transfer address into dma register */
242 void
243 csc_set_dma_adr(sc, ptr)
244 struct sfas_softc *sc;
245 void *ptr;
246 {
247 return;
248 }
249
250 /* Set DMA transfer counter */
251 void
252 csc_set_dma_tc(sc, len)
253 struct sfas_softc *sc;
254 unsigned int len;
255 {
256 *sc->sc_fas->sfas_tc_low = len; len >>= 8;
257 *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
258 *sc->sc_fas->sfas_tc_high = len;
259 }
260
261 /* Set DMA mode */
262 void
263 csc_set_dma_mode(sc, mode)
264 struct sfas_softc *sc;
265 int mode;
266 {
267 }
268
269 /* Initialize DMA for transfer */
270 int
271 csc_setup_dma(sc, ptr, len, mode)
272 struct sfas_softc *sc;
273 void *ptr;
274 int len;
275 int mode;
276 {
277 return(0);
278 }
279
280 /* Check if address and len is ok for DMA transfer */
281 int
282 csc_need_bump(sc, ptr, len)
283 struct sfas_softc *sc;
284 void *ptr;
285 int len;
286 {
287 int p;
288
289 p = (int)ptr & 0x03;
290
291 if (p) {
292 p = 4-p;
293
294 if (len < 256)
295 p = len;
296 }
297
298 return(p);
299 }
300
301 /* Interrupt driven routines */
302 int
303 csc_build_dma_chain(sc, chain, p, l)
304 struct sfas_softc *sc;
305 struct sfas_dma_chain *chain;
306 void *p;
307 int l;
308 {
309 return(0);
310 }
311
312 /* Turn on/off led */
313 void
314 csc_led(sc, mode)
315 struct sfas_softc *sc;
316 int mode;
317 {
318 csc_regmap_p rp;
319
320 rp = (csc_regmap_p)sc->sc_fas;
321
322 if (mode) {
323 sc->sc_led_status++;
324 } else {
325 if (sc->sc_led_status)
326 sc->sc_led_status--;
327 }
328 }
329
330 void
331 csc_scsi_request(chan, req, arg)
332 struct scsipi_channel *chan;
333 scsipi_adapter_req_t req;
334 void *arg;
335 {
336 struct scsipi_xfer *xs;
337
338 switch (req) {
339 case ADAPTER_REQ_RUN_XFER:
340 xs = arg;
341 /* ensure command is polling for the moment */
342 #if CSC_POLL > 0
343 xs->xs_control |= XS_CTL_POLL;
344 #endif
345 default:
346 }
347 sfas_scsi_request(chan, req, arg);
348 }
349