asc.c revision 1.3 1 /* $NetBSD: asc.c,v 1.3 2001/11/27 00:53:12 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2001 Richard Earnshaw
5 * All rights reserved.
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the company nor the name of the author may be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 *
29 * Copyright (c) 1996 Mark Brinicombe
30 * Copyright (c) 1982, 1990 The Regents of the University of California.
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * from:ahsc.c
62 */
63
64 /*
65 * Driver for the Acorn SCSI card using the SBIC (WD33C93A) generic driver
66 *
67 * Thanks to Acorn for supplying programming information on this card.
68 */
69
70 /* #define ASC_DMAMAP_DEBUG */
71 /* #define DEBUG */
72
73 #include "opt_ddb.h"
74
75 #include <sys/types.h>
76 #include <sys/param.h>
77 #include <sys/systm.h>
78 #include <sys/kernel.h>
79 #include <sys/device.h>
80 #include <sys/buf.h>
81
82 #include <uvm/uvm_extern.h>
83
84 #include <machine/bus.h>
85 #include <machine/intr.h>
86 #include <machine/bootconfig.h> /* asc_poll */
87
88 #include <dev/scsipi/scsi_all.h>
89 #include <dev/scsipi/scsipi_all.h>
90 #include <dev/scsipi/scsiconf.h>
91
92 #include <arm/arm32/katelib.h>
93
94 #include <dev/podulebus/podules.h>
95 #include <dev/podulebus/powerromreg.h>
96
97 #include <acorn32/podulebus/podulebus.h>
98 #include <acorn32/podulebus/sbicreg.h>
99 #include <acorn32/podulebus/sbicvar.h>
100 #include <acorn32/podulebus/ascreg.h>
101 #include <acorn32/podulebus/ascvar.h>
102
103 void ascattach (struct device *, struct device *, void *);
104 int ascmatch (struct device *, struct cfdata *, void *);
105
106 void asc_enintr (struct sbic_softc *);
107
108 int asc_dmaok (void *, bus_dma_tag_t, struct sbic_acb *);
109 int asc_dmasetup (void *, bus_dma_tag_t, struct sbic_acb *, int);
110 int asc_dmanext (void *, bus_dma_tag_t, struct sbic_acb *, int);
111 void asc_dmastop (void *, bus_dma_tag_t, struct sbic_acb *);
112 void asc_dmafinish (void *, bus_dma_tag_t, struct sbic_acb *);
113
114 void asc_scsi_request (struct scsipi_channel *,
115 scsipi_adapter_req_t, void *);
116 int asc_intr (void *);
117 void asc_minphys (struct buf *);
118
119 #ifdef DEBUG
120 int asc_dmadebug = 0;
121 #endif
122
123 struct cfattach asc_ca = {
124 sizeof(struct asc_softc), ascmatch, ascattach
125 };
126
127 extern struct cfdriver asc_cd;
128
129 u_long scsi_nosync;
130 int shift_nosync;
131
132 #if ASC_POLL > 0
133 int asc_poll = 0;
134
135 #endif
136
137 int
138 ascmatch(struct device *pdp, struct cfdata *cf, void *auxp)
139 {
140 struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
141
142 /* Look for the card */
143
144 /* Standard ROM, skipping the MCS card that used the same ID. */
145 if (matchpodule(pa, MANUFACTURER_ACORN, PODULE_ACORN_SCSI, -1) &&
146 strncmp(pa->pa_podule->description, "MCS", 3) != 0)
147 return 1;
148
149 /* PowerROM */
150 if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
151 podulebus_initloader(pa) == 0 &&
152 podloader_callloader(pa, 0, 0) == PRID_ACORN_SCSI1)
153 return 1;
154
155 return 0;
156 }
157
158 void
159 ascattach(struct device *pdp, struct device *dp, void *auxp)
160 {
161 /* volatile struct sdmac *rp;*/
162 struct asc_softc *sc;
163 struct sbic_softc *sbic;
164 struct podule_attach_args *pa;
165
166 sc = (struct asc_softc *)dp;
167 pa = (struct podule_attach_args *)auxp;
168
169 if (pa->pa_podule_number == -1)
170 panic("Podule has disappeared !");
171
172 sc->sc_podule_number = pa->pa_podule_number;
173 sc->sc_podule = pa->pa_podule;
174 podules[sc->sc_podule_number].attached = 1;
175
176 sbic = &sc->sc_softc;
177
178 sbic->sc_enintr = asc_enintr;
179 sbic->sc_dmaok = asc_dmaok;
180 sbic->sc_dmasetup = asc_dmasetup;
181 sbic->sc_dmanext = asc_dmanext;
182 sbic->sc_dmastop = asc_dmastop;
183 sbic->sc_dmafinish = asc_dmafinish;
184
185 /* Map sbic */
186 sbic->sc_sbicp.sc_sbiciot = pa->pa_iot;
187 if (bus_space_map (sbic->sc_sbicp.sc_sbiciot,
188 sc->sc_podule->mod_base + ASC_SBIC, ASC_SBIC_SPACE, 0,
189 &sbic->sc_sbicp.sc_sbicioh))
190 panic("%s: Cannot map SBIC\n", dp->dv_xname);
191
192 sbic->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143;
193
194 sbic->sc_adapter.adapt_dev = &sbic->sc_dev;
195 sbic->sc_adapter.adapt_nchannels = 1;
196 sbic->sc_adapter.adapt_openings = 7;
197 sbic->sc_adapter.adapt_max_periph = 1;
198 sbic->sc_adapter.adapt_ioctl = NULL;
199 sbic->sc_adapter.adapt_minphys = asc_minphys;
200 sbic->sc_adapter.adapt_request = asc_scsi_request;
201
202 sbic->sc_channel.chan_adapter = &sbic->sc_adapter;
203 sbic->sc_channel.chan_bustype = &scsi_bustype;
204 sbic->sc_channel.chan_channel = 0;
205 sbic->sc_channel.chan_ntargets = 8;
206 sbic->sc_channel.chan_nluns = 8;
207 sbic->sc_channel.chan_id = 7;
208
209 /* Provide an override for the host id */
210 (void)get_bootconf_option(boot_args, "asc.hostid",
211 BOOTOPT_TYPE_INT, &sbic->sc_channel.chan_id);
212
213 printf(": hostid=%d", sbic->sc_channel.chan_id);
214
215 #if ASC_POLL > 0
216 if (boot_args)
217 get_bootconf_option(boot_args, "ascpoll", BOOTOPT_TYPE_BOOLEAN,
218 &asc_poll);
219
220 if (asc_poll)
221 printf(" polling");
222 #endif
223 printf("\n");
224
225 sc->sc_pagereg = sc->sc_podule->fast_base + ASC_PAGEREG;
226 sc->sc_intstat = sc->sc_podule->fast_base + ASC_INTSTATUS;
227
228 /* Reset the card */
229
230 WriteByte(sc->sc_pagereg, 0x80);
231 DELAY(500000);
232 WriteByte(sc->sc_pagereg, 0x00);
233 DELAY(250000);
234
235 sbicinit(sbic);
236
237 /* If we are polling only, we don't need a interrupt handler. */
238
239 #ifdef ASC_POLL
240 if (!asc_poll)
241 #endif
242 {
243 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
244 dp->dv_xname, "intr");
245 sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
246 asc_intr, sc, &sc->sc_intrcnt);
247 if (sc->sc_ih == NULL)
248 panic("%s: Cannot claim podule IRQ\n", dp->dv_xname);
249 }
250
251 /*
252 * attach all scsi units on us
253 */
254 config_found(dp, &sbic->sc_channel, scsiprint);
255 }
256
257
258 void
259 asc_enintr(struct sbic_softc *sbicsc)
260 {
261 struct asc_softc *sc = (struct asc_softc *)sbicsc;
262
263 sbicsc->sc_flags |= SBICF_INTR;
264 WriteByte(sc->sc_pagereg, 0x40);
265 }
266
267 int
268 asc_dmaok (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
269 {
270 return 0;
271 }
272
273 int
274 asc_dmasetup (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb, int dir)
275 {
276 printf("asc_dmasetup()");
277 #ifdef DDB
278 Debugger();
279 #else
280 panic("Hit a brick wall\n");
281 #endif
282 return 0;
283 }
284
285 int
286 asc_dmanext (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb, int dir)
287 {
288 printf("asc_dmanext()");
289 #ifdef DDB
290 Debugger();
291 #else
292 panic("Hit a brick wall\n");
293 #endif
294 return 0;
295 }
296
297 void
298 asc_dmastop (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
299 {
300 printf("asc_dmastop\n");
301 }
302
303 void
304 asc_dmafinish (void *dma_h, bus_dma_tag_t dma_t, struct sbic_acb *acb)
305 {
306 printf("asc_dmafinish\n");
307 }
308
309 int
310 asc_dmaintr(dev)
311 struct sbic_softc *dev;
312 {
313 panic("asc_dmaintr");
314 return 0;
315 }
316
317 void
318 asc_dump(void)
319 {
320 int i;
321
322 for (i = 0; i < asc_cd.cd_ndevs; ++i)
323 if (asc_cd.cd_devs[i])
324 sbic_dump(asc_cd.cd_devs[i]);
325 }
326
327 void
328 asc_scsi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
329 void *arg)
330 {
331 struct scsipi_xfer *xs;
332
333 switch (req) {
334 case ADAPTER_REQ_RUN_XFER:
335 xs = arg;
336
337 #if ASC_POLL > 0
338 /* ensure command is polling for the moment */
339
340 if (asc_poll)
341 xs->xs_control |= XS_CTL_POLL;
342 #endif
343
344 /* printf("id=%d lun=%dcmdlen=%d datalen=%d opcode=%02x flags=%08x status=%02x blk=%02x %02x\n",
345 xs->xs_periph->periph_target, xs->xs_periph->periph_lun, xs->cmdlen, xs->datalen, xs->cmd->opcode,
346 xs->xs_control, xs->status, xs->cmd->bytes[0], xs->cmd->bytes[1]);*/
347
348 default:
349 }
350 sbic_scsi_request(chan, req, arg);
351 }
352
353
354 int
355 asc_intr(void *arg)
356 {
357 struct asc_softc *sc = arg;
358 int intr;
359
360 /* printf("ascintr:");*/
361 intr = ReadByte(sc->sc_intstat);
362 /* printf("%02x\n", intr);*/
363
364 if (intr & IS_SBIC_IRQ)
365 sbicintr((struct sbic_softc *)sc);
366
367 return 0; /* Pass interrupt on down the chain */
368 }
369
370 /*
371 * limit the transfer as required.
372 */
373 void
374 asc_minphys(struct buf *bp)
375 {
376 #if 0
377 /*
378 * We must limit the DMA xfer size
379 */
380 if (bp->b_bcount > MAX_DMA_LEN) {
381 printf("asc: Reducing dma length\n");
382 bp->b_bcount = MAX_DMA_LEN;
383 }
384 #endif
385 minphys(bp);
386 }
387
388