ptsc.c revision 1.2.2.2 1 1.2.2.2 thorpej /* $NetBSD: ptsc.c,v 1.2.2.2 2002/01/10 19:36:36 thorpej Exp $ */
2 1.2.2.2 thorpej
3 1.2.2.2 thorpej /*
4 1.2.2.2 thorpej * Copyright (c) 1995 Scott Stevens
5 1.2.2.2 thorpej * Copyright (c) 1995 Daniel Widenfalk
6 1.2.2.2 thorpej * Copyright (c) 1994 Christian E. Hopps
7 1.2.2.2 thorpej * Copyright (c) 1982, 1990 The Regents of the University of California.
8 1.2.2.2 thorpej * All rights reserved.
9 1.2.2.2 thorpej *
10 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.2.2.2 thorpej * are met:
13 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 thorpej * must display the following acknowledgement:
20 1.2.2.2 thorpej * This product includes software developed by the University of
21 1.2.2.2 thorpej * California, Berkeley and its contributors.
22 1.2.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
23 1.2.2.2 thorpej * may be used to endorse or promote products derived from this software
24 1.2.2.2 thorpej * without specific prior written permission.
25 1.2.2.2 thorpej *
26 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.2.2.2 thorpej * SUCH DAMAGE.
37 1.2.2.2 thorpej *
38 1.2.2.2 thorpej * @(#)ptsc.c
39 1.2.2.2 thorpej */
40 1.2.2.2 thorpej
41 1.2.2.2 thorpej /*
42 1.2.2.2 thorpej * Power-tec SCSI-2 driver uses SFAS216 generic driver
43 1.2.2.2 thorpej *
44 1.2.2.2 thorpej * Thanks to Alsystems for loaning a development card and providing
45 1.2.2.2 thorpej * programming information.
46 1.2.2.2 thorpej */
47 1.2.2.2 thorpej
48 1.2.2.2 thorpej #include <sys/param.h>
49 1.2.2.2 thorpej #include <sys/systm.h>
50 1.2.2.2 thorpej #include <sys/kernel.h>
51 1.2.2.2 thorpej #include <sys/device.h>
52 1.2.2.2 thorpej #include <dev/scsipi/scsi_all.h>
53 1.2.2.2 thorpej #include <dev/scsipi/scsipi_all.h>
54 1.2.2.2 thorpej #include <dev/scsipi/scsiconf.h>
55 1.2.2.2 thorpej #include <uvm/uvm_extern.h>
56 1.2.2.2 thorpej #include <machine/pmap.h>
57 1.2.2.2 thorpej #include <machine/io.h>
58 1.2.2.2 thorpej #include <machine/intr.h>
59 1.2.2.2 thorpej #include <machine/bootconfig.h>
60 1.2.2.2 thorpej #include <acorn32/podulebus/podulebus.h>
61 1.2.2.2 thorpej #include <acorn32/podulebus/sfasreg.h>
62 1.2.2.2 thorpej #include <acorn32/podulebus/sfasvar.h>
63 1.2.2.2 thorpej #include <acorn32/podulebus/ptscreg.h>
64 1.2.2.2 thorpej #include <acorn32/podulebus/ptscvar.h>
65 1.2.2.2 thorpej #include <dev/podulebus/podules.h>
66 1.2.2.2 thorpej #include <dev/podulebus/powerromreg.h>
67 1.2.2.2 thorpej
68 1.2.2.2 thorpej void ptscattach __P((struct device *, struct device *, void *));
69 1.2.2.2 thorpej int ptscmatch __P((struct device *, struct cfdata *, void *));
70 1.2.2.2 thorpej void ptsc_scsi_request __P((struct scsipi_channel *,
71 1.2.2.2 thorpej scsipi_adapter_req_t, void *));
72 1.2.2.2 thorpej
73 1.2.2.2 thorpej struct cfattach ptsc_ca = {
74 1.2.2.2 thorpej sizeof(struct ptsc_softc), ptscmatch, ptscattach
75 1.2.2.2 thorpej };
76 1.2.2.2 thorpej
77 1.2.2.2 thorpej int ptsc_intr __P((void *arg));
78 1.2.2.2 thorpej int ptsc_setup_dma __P((struct sfas_softc *sc, void *ptr, int len,
79 1.2.2.2 thorpej int mode));
80 1.2.2.2 thorpej int ptsc_build_dma_chain __P((struct sfas_softc *sc,
81 1.2.2.2 thorpej struct sfas_dma_chain *chain, void *p, int l));
82 1.2.2.2 thorpej int ptsc_need_bump __P((struct sfas_softc *sc, void *ptr, int len));
83 1.2.2.2 thorpej void ptsc_led __P((struct sfas_softc *sc, int mode));
84 1.2.2.2 thorpej
85 1.2.2.2 thorpej /*
86 1.2.2.2 thorpej * if we are a Power-tec SCSI-2 card
87 1.2.2.2 thorpej */
88 1.2.2.2 thorpej int
89 1.2.2.2 thorpej ptscmatch(pdp, cf, auxp)
90 1.2.2.2 thorpej struct device *pdp;
91 1.2.2.2 thorpej struct cfdata *cf;
92 1.2.2.2 thorpej void *auxp;
93 1.2.2.2 thorpej {
94 1.2.2.2 thorpej struct podule_attach_args *pa = (struct podule_attach_args *)auxp;
95 1.2.2.2 thorpej
96 1.2.2.2 thorpej /* Look for the card */
97 1.2.2.2 thorpej
98 1.2.2.2 thorpej /*
99 1.2.2.2 thorpej * All Power-tec cards effectively have PowerROMS. Note,
100 1.2.2.2 thorpej * though, that here, if we fail to initialise the loader, we
101 1.2.2.2 thorpej * assume this _is_ the right kind of card.
102 1.2.2.2 thorpej */
103 1.2.2.2 thorpej if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
104 1.2.2.2 thorpej (podulebus_initloader(pa) != 0 ||
105 1.2.2.2 thorpej podloader_callloader(pa, 0, 0) == PRID_POWERTEC))
106 1.2.2.2 thorpej return 1;
107 1.2.2.2 thorpej
108 1.2.2.2 thorpej return 0;
109 1.2.2.2 thorpej }
110 1.2.2.2 thorpej
111 1.2.2.2 thorpej void
112 1.2.2.2 thorpej ptscattach(pdp, dp, auxp)
113 1.2.2.2 thorpej struct device *pdp;
114 1.2.2.2 thorpej struct device *dp;
115 1.2.2.2 thorpej void *auxp;
116 1.2.2.2 thorpej {
117 1.2.2.2 thorpej struct ptsc_softc *sc = (struct ptsc_softc *)dp;
118 1.2.2.2 thorpej struct podule_attach_args *pa;
119 1.2.2.2 thorpej ptsc_regmap_p rp = &sc->sc_regmap;
120 1.2.2.2 thorpej vu_char *fas;
121 1.2.2.2 thorpej
122 1.2.2.2 thorpej pa = (struct podule_attach_args *)auxp;
123 1.2.2.2 thorpej
124 1.2.2.2 thorpej if (pa->pa_podule_number == -1)
125 1.2.2.2 thorpej panic("Podule has disappeared !");
126 1.2.2.2 thorpej
127 1.2.2.2 thorpej sc->sc_specific.sc_podule_number = pa->pa_podule_number;
128 1.2.2.2 thorpej sc->sc_specific.sc_podule = pa->pa_podule;
129 1.2.2.2 thorpej sc->sc_specific.sc_iobase =
130 1.2.2.2 thorpej (vu_char *)sc->sc_specific.sc_podule->fast_base;
131 1.2.2.2 thorpej
132 1.2.2.2 thorpej rp->chipreset = &sc->sc_specific.sc_iobase[PTSC_CONTROL_CHIPRESET];
133 1.2.2.2 thorpej rp->inten = &sc->sc_specific.sc_iobase[PTSC_CONTROL_INTEN];
134 1.2.2.2 thorpej rp->status = &sc->sc_specific.sc_iobase[PTSC_STATUS];
135 1.2.2.2 thorpej rp->term = &sc->sc_specific.sc_iobase[PTSC_CONTROL_TERM];
136 1.2.2.2 thorpej rp->led = &sc->sc_specific.sc_iobase[PTSC_CONTROL_LED];
137 1.2.2.2 thorpej fas = &sc->sc_specific.sc_iobase[PTSC_FASOFFSET_BASE];
138 1.2.2.2 thorpej
139 1.2.2.2 thorpej rp->FAS216.sfas_tc_low = &fas[PTSC_FASOFFSET_TCL];
140 1.2.2.2 thorpej rp->FAS216.sfas_tc_mid = &fas[PTSC_FASOFFSET_TCM];
141 1.2.2.2 thorpej rp->FAS216.sfas_fifo = &fas[PTSC_FASOFFSET_FIFO];
142 1.2.2.2 thorpej rp->FAS216.sfas_command = &fas[PTSC_FASOFFSET_COMMAND];
143 1.2.2.2 thorpej rp->FAS216.sfas_dest_id = &fas[PTSC_FASOFFSET_DESTID];
144 1.2.2.2 thorpej rp->FAS216.sfas_timeout = &fas[PTSC_FASOFFSET_TIMEOUT];
145 1.2.2.2 thorpej rp->FAS216.sfas_syncper = &fas[PTSC_FASOFFSET_PERIOD];
146 1.2.2.2 thorpej rp->FAS216.sfas_syncoff = &fas[PTSC_FASOFFSET_OFFSET];
147 1.2.2.2 thorpej rp->FAS216.sfas_config1 = &fas[PTSC_FASOFFSET_CONFIG1];
148 1.2.2.2 thorpej rp->FAS216.sfas_clkconv = &fas[PTSC_FASOFFSET_CLOCKCONV];
149 1.2.2.2 thorpej rp->FAS216.sfas_test = &fas[PTSC_FASOFFSET_TEST];
150 1.2.2.2 thorpej rp->FAS216.sfas_config2 = &fas[PTSC_FASOFFSET_CONFIG2];
151 1.2.2.2 thorpej rp->FAS216.sfas_config3 = &fas[PTSC_FASOFFSET_CONFIG3];
152 1.2.2.2 thorpej rp->FAS216.sfas_tc_high = &fas[PTSC_FASOFFSET_TCH];
153 1.2.2.2 thorpej rp->FAS216.sfas_fifo_bot = &fas[PTSC_FASOFFSET_FIFOBOTTOM];
154 1.2.2.2 thorpej
155 1.2.2.2 thorpej sc->sc_softc.sc_fas = (sfas_regmap_p)rp;
156 1.2.2.2 thorpej sc->sc_softc.sc_spec = &sc->sc_specific;
157 1.2.2.2 thorpej
158 1.2.2.2 thorpej sc->sc_softc.sc_led = ptsc_led;
159 1.2.2.2 thorpej
160 1.2.2.2 thorpej sc->sc_softc.sc_setup_dma = ptsc_setup_dma;
161 1.2.2.2 thorpej sc->sc_softc.sc_build_dma_chain = ptsc_build_dma_chain;
162 1.2.2.2 thorpej sc->sc_softc.sc_need_bump = ptsc_need_bump;
163 1.2.2.2 thorpej
164 1.2.2.2 thorpej sc->sc_softc.sc_clock_freq = 40; /* Power-Tec runs at 8MHz */
165 1.2.2.2 thorpej sc->sc_softc.sc_timeout = 250; /* Set default timeout to 250ms */
166 1.2.2.2 thorpej sc->sc_softc.sc_config_flags = SFAS_NO_DMA /*| SFAS_NF_DEBUG*/;
167 1.2.2.2 thorpej sc->sc_softc.sc_host_id = 7; /* Should check the jumpers */
168 1.2.2.2 thorpej
169 1.2.2.2 thorpej sc->sc_softc.sc_bump_sz = NBPG;
170 1.2.2.2 thorpej sc->sc_softc.sc_bump_pa = 0x0;
171 1.2.2.2 thorpej
172 1.2.2.2 thorpej sfasinitialize((struct sfas_softc *)sc);
173 1.2.2.2 thorpej
174 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_dev = &sc->sc_softc.sc_dev;
175 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_nchannels = 1;
176 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_openings = 7;
177 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_max_periph = 1;
178 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_ioctl = NULL;
179 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_minphys = sfas_minphys;
180 1.2.2.2 thorpej sc->sc_softc.sc_adapter.adapt_request = ptsc_scsi_request;
181 1.2.2.2 thorpej
182 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_adapter = &sc->sc_softc.sc_adapter;
183 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_bustype = &scsi_bustype;
184 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_channel = 0;
185 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_ntargets = 8;
186 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_nluns = 8;
187 1.2.2.2 thorpej sc->sc_softc.sc_channel.chan_id = sc->sc_softc.sc_host_id;
188 1.2.2.2 thorpej
189 1.2.2.2 thorpej /* Provide an override for the host id */
190 1.2.2.2 thorpej (void)get_bootconf_option(boot_args, "ptsc.hostid",
191 1.2.2.2 thorpej BOOTOPT_TYPE_INT, &sc->sc_softc.sc_channel.chan_id);
192 1.2.2.2 thorpej
193 1.2.2.2 thorpej printf(": host=%d", sc->sc_softc.sc_channel.chan_id);
194 1.2.2.2 thorpej
195 1.2.2.2 thorpej /* initialise the card */
196 1.2.2.2 thorpej /* *rp->term = 0;*/
197 1.2.2.2 thorpej *rp->inten = (PTSC_POLL?0:1);
198 1.2.2.2 thorpej *rp->led = 0;
199 1.2.2.2 thorpej
200 1.2.2.2 thorpej #if PTSC_POLL == 0
201 1.2.2.2 thorpej evcnt_attach_dynamic(&sc->sc_softc.sc_intrcnt, EVCNT_TYPE_INTR, NULL,
202 1.2.2.2 thorpej dp->dv_xname, "intr");
203 1.2.2.2 thorpej sc->sc_softc.sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO,
204 1.2.2.2 thorpej ptsc_intr, &sc->sc_softc, &sc->sc_softc.sc_intrcnt);
205 1.2.2.2 thorpej if (sc->sc_softc.sc_ih == NULL)
206 1.2.2.2 thorpej panic("%s: Cannot install IRQ handler\n", dp->dv_xname);
207 1.2.2.2 thorpej #else
208 1.2.2.2 thorpej printf(" polling");
209 1.2.2.2 thorpej #endif
210 1.2.2.2 thorpej
211 1.2.2.2 thorpej printf("\n");
212 1.2.2.2 thorpej
213 1.2.2.2 thorpej /* attach all scsi units on us */
214 1.2.2.2 thorpej config_found(dp, &sc->sc_softc.sc_channel, scsiprint);
215 1.2.2.2 thorpej }
216 1.2.2.2 thorpej
217 1.2.2.2 thorpej
218 1.2.2.2 thorpej int
219 1.2.2.2 thorpej ptsc_intr(arg)
220 1.2.2.2 thorpej void *arg;
221 1.2.2.2 thorpej {
222 1.2.2.2 thorpej struct sfas_softc *dev = arg;
223 1.2.2.2 thorpej ptsc_regmap_p rp;
224 1.2.2.2 thorpej int quickints;
225 1.2.2.2 thorpej
226 1.2.2.2 thorpej rp = (ptsc_regmap_p)dev->sc_fas;
227 1.2.2.2 thorpej
228 1.2.2.2 thorpej if (*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) {
229 1.2.2.2 thorpej quickints = 16;
230 1.2.2.2 thorpej do {
231 1.2.2.2 thorpej dev->sc_status = *rp->FAS216.sfas_status;
232 1.2.2.2 thorpej dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
233 1.2.2.2 thorpej
234 1.2.2.2 thorpej if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
235 1.2.2.2 thorpej dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
236 1.2.2.2 thorpej dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
237 1.2.2.2 thorpej }
238 1.2.2.2 thorpej
239 1.2.2.2 thorpej sfasintr(dev);
240 1.2.2.2 thorpej
241 1.2.2.2 thorpej } while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING)
242 1.2.2.2 thorpej && --quickints);
243 1.2.2.2 thorpej }
244 1.2.2.2 thorpej
245 1.2.2.2 thorpej return(0); /* Pass interrupt on down the chain */
246 1.2.2.2 thorpej }
247 1.2.2.2 thorpej
248 1.2.2.2 thorpej /* Load transfer address into dma register */
249 1.2.2.2 thorpej void
250 1.2.2.2 thorpej ptsc_set_dma_adr(sc, ptr)
251 1.2.2.2 thorpej struct sfas_softc *sc;
252 1.2.2.2 thorpej void *ptr;
253 1.2.2.2 thorpej {
254 1.2.2.2 thorpej #if 0
255 1.2.2.2 thorpej ptsc_regmap_p rp;
256 1.2.2.2 thorpej unsigned int *p;
257 1.2.2.2 thorpej unsigned int d;
258 1.2.2.2 thorpej #endif
259 1.2.2.2 thorpej #if 0
260 1.2.2.2 thorpej printf("ptsc_set_dma_adr(sc = 0x%08x, ptr = 0x%08x)\n", (u_int)sc, (u_int)ptr);
261 1.2.2.2 thorpej #endif
262 1.2.2.2 thorpej return;
263 1.2.2.2 thorpej #if 0
264 1.2.2.2 thorpej rp = (ptsc_regmap_p)sc->sc_fas;
265 1.2.2.2 thorpej
266 1.2.2.2 thorpej d = (unsigned int)ptr;
267 1.2.2.2 thorpej p = (unsigned int *)((d & 0xFFFFFF) + (int)rp->dmabase);
268 1.2.2.2 thorpej
269 1.2.2.2 thorpej *rp->clear=0;
270 1.2.2.2 thorpej *p = d;
271 1.2.2.2 thorpej #endif
272 1.2.2.2 thorpej }
273 1.2.2.2 thorpej
274 1.2.2.2 thorpej /* Set DMA transfer counter */
275 1.2.2.2 thorpej void
276 1.2.2.2 thorpej ptsc_set_dma_tc(sc, len)
277 1.2.2.2 thorpej struct sfas_softc *sc;
278 1.2.2.2 thorpej unsigned int len;
279 1.2.2.2 thorpej {
280 1.2.2.2 thorpej printf("ptsc_set_dma_tc(sc, len = 0x%08x)", len);
281 1.2.2.2 thorpej
282 1.2.2.2 thorpej *sc->sc_fas->sfas_tc_low = len; len >>= 8;
283 1.2.2.2 thorpej *sc->sc_fas->sfas_tc_mid = len; len >>= 8;
284 1.2.2.2 thorpej *sc->sc_fas->sfas_tc_high = len;
285 1.2.2.2 thorpej }
286 1.2.2.2 thorpej
287 1.2.2.2 thorpej /* Set DMA mode */
288 1.2.2.2 thorpej void
289 1.2.2.2 thorpej ptsc_set_dma_mode(sc, mode)
290 1.2.2.2 thorpej struct sfas_softc *sc;
291 1.2.2.2 thorpej int mode;
292 1.2.2.2 thorpej {
293 1.2.2.2 thorpej #if 0
294 1.2.2.2 thorpej struct csc_specific *spec;
295 1.2.2.2 thorpej
296 1.2.2.2 thorpej spec = sc->sc_spec;
297 1.2.2.2 thorpej
298 1.2.2.2 thorpej spec->portbits = (spec->portbits & ~FLSC_PB_DMA_BITS) | mode;
299 1.2.2.2 thorpej *((flsc_regmap_p)sc->sc_fas)->hardbits = spec->portbits;
300 1.2.2.2 thorpej #endif
301 1.2.2.2 thorpej }
302 1.2.2.2 thorpej
303 1.2.2.2 thorpej /* Initialize DMA for transfer */
304 1.2.2.2 thorpej int
305 1.2.2.2 thorpej ptsc_setup_dma(sc, ptr, len, mode)
306 1.2.2.2 thorpej struct sfas_softc *sc;
307 1.2.2.2 thorpej void *ptr;
308 1.2.2.2 thorpej int len;
309 1.2.2.2 thorpej int mode;
310 1.2.2.2 thorpej {
311 1.2.2.2 thorpej int retval;
312 1.2.2.2 thorpej
313 1.2.2.2 thorpej retval = 0;
314 1.2.2.2 thorpej
315 1.2.2.2 thorpej #if 0
316 1.2.2.2 thorpej printf("ptsc_setup_dma(sc, ptr = 0x%08x, len = 0x%08x, mode = 0x%08x)\n", (u_int)ptr, len, mode);
317 1.2.2.2 thorpej #endif
318 1.2.2.2 thorpej return(0);
319 1.2.2.2 thorpej
320 1.2.2.2 thorpej #if 0
321 1.2.2.2 thorpej switch(mode) {
322 1.2.2.2 thorpej case SFAS_DMA_READ:
323 1.2.2.2 thorpej case SFAS_DMA_WRITE:
324 1.2.2.2 thorpej flsc_set_dma_adr(sc, ptr);
325 1.2.2.2 thorpej if (mode == SFAS_DMA_READ)
326 1.2.2.2 thorpej flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_READ);
327 1.2.2.2 thorpej else
328 1.2.2.2 thorpej flsc_set_dma_mode(sc,FLSC_PB_ENABLE_DMA | FLSC_PB_DMA_WRITE);
329 1.2.2.2 thorpej
330 1.2.2.2 thorpej flsc_set_dma_tc(sc, len);
331 1.2.2.2 thorpej break;
332 1.2.2.2 thorpej
333 1.2.2.2 thorpej case SFAS_DMA_CLEAR:
334 1.2.2.2 thorpej default:
335 1.2.2.2 thorpej flsc_set_dma_mode(sc, FLSC_PB_DISABLE_DMA);
336 1.2.2.2 thorpej flsc_set_dma_adr(sc, 0);
337 1.2.2.2 thorpej
338 1.2.2.2 thorpej retval = (*sc->sc_fas->sfas_tc_high << 16) |
339 1.2.2.2 thorpej (*sc->sc_fas->sfas_tc_mid << 8) |
340 1.2.2.2 thorpej *sc->sc_fas->sfas_tc_low;
341 1.2.2.2 thorpej
342 1.2.2.2 thorpej flsc_set_dma_tc(sc, 0);
343 1.2.2.2 thorpej break;
344 1.2.2.2 thorpej }
345 1.2.2.2 thorpej
346 1.2.2.2 thorpej return(retval);
347 1.2.2.2 thorpej #endif
348 1.2.2.2 thorpej }
349 1.2.2.2 thorpej
350 1.2.2.2 thorpej /* Check if address and len is ok for DMA transfer */
351 1.2.2.2 thorpej int
352 1.2.2.2 thorpej ptsc_need_bump(sc, ptr, len)
353 1.2.2.2 thorpej struct sfas_softc *sc;
354 1.2.2.2 thorpej void *ptr;
355 1.2.2.2 thorpej int len;
356 1.2.2.2 thorpej {
357 1.2.2.2 thorpej int p;
358 1.2.2.2 thorpej
359 1.2.2.2 thorpej p = (int)ptr & 0x03;
360 1.2.2.2 thorpej
361 1.2.2.2 thorpej if (p) {
362 1.2.2.2 thorpej p = 4-p;
363 1.2.2.2 thorpej
364 1.2.2.2 thorpej if (len < 256)
365 1.2.2.2 thorpej p = len;
366 1.2.2.2 thorpej }
367 1.2.2.2 thorpej
368 1.2.2.2 thorpej return(p);
369 1.2.2.2 thorpej }
370 1.2.2.2 thorpej
371 1.2.2.2 thorpej /* Interrupt driven routines */
372 1.2.2.2 thorpej int
373 1.2.2.2 thorpej ptsc_build_dma_chain(sc, chain, p, l)
374 1.2.2.2 thorpej struct sfas_softc *sc;
375 1.2.2.2 thorpej struct sfas_dma_chain *chain;
376 1.2.2.2 thorpej void *p;
377 1.2.2.2 thorpej int l;
378 1.2.2.2 thorpej {
379 1.2.2.2 thorpej #if 0
380 1.2.2.2 thorpej vm_offset_t pa, lastpa;
381 1.2.2.2 thorpej char *ptr;
382 1.2.2.2 thorpej int len, prelen, postlen, max_t, n;
383 1.2.2.2 thorpej #endif
384 1.2.2.2 thorpej #if 0
385 1.2.2.2 thorpej printf("ptsc_build_dma_chain()\n");
386 1.2.2.2 thorpej #endif
387 1.2.2.2 thorpej return(0);
388 1.2.2.2 thorpej
389 1.2.2.2 thorpej #if 0
390 1.2.2.2 thorpej if (l == 0)
391 1.2.2.2 thorpej return(0);
392 1.2.2.2 thorpej
393 1.2.2.2 thorpej #define set_link(n, p, l, f)\
394 1.2.2.2 thorpej do { chain[n].ptr = (p); chain[n].len = (l); chain[n++].flg = (f); } while(0)
395 1.2.2.2 thorpej
396 1.2.2.2 thorpej n = 0;
397 1.2.2.2 thorpej
398 1.2.2.2 thorpej if (l < 512)
399 1.2.2.2 thorpej set_link(n, (vm_offset_t)p, l, SFAS_CHAIN_BUMP);
400 1.2.2.2 thorpej else if (p >= (void *)0xFF000000) {
401 1.2.2.2 thorpej while(l != 0) {
402 1.2.2.2 thorpej len = ((l > sc->sc_bump_sz) ? sc->sc_bump_sz : l);
403 1.2.2.2 thorpej
404 1.2.2.2 thorpej set_link(n, (vm_offset_t)p, len, SFAS_CHAIN_BUMP);
405 1.2.2.2 thorpej
406 1.2.2.2 thorpej p += len;
407 1.2.2.2 thorpej l -= len;
408 1.2.2.2 thorpej }
409 1.2.2.2 thorpej } else {
410 1.2.2.2 thorpej ptr = p;
411 1.2.2.2 thorpej len = l;
412 1.2.2.2 thorpej
413 1.2.2.2 thorpej pa = kvtop(ptr);
414 1.2.2.2 thorpej prelen = ((int)ptr & 0x03);
415 1.2.2.2 thorpej
416 1.2.2.2 thorpej if (prelen) {
417 1.2.2.2 thorpej prelen = 4-prelen;
418 1.2.2.2 thorpej set_link(n, (vm_offset_t)ptr, prelen, SFAS_CHAIN_BUMP);
419 1.2.2.2 thorpej ptr += prelen;
420 1.2.2.2 thorpej len -= prelen;
421 1.2.2.2 thorpej }
422 1.2.2.2 thorpej
423 1.2.2.2 thorpej lastpa = 0;
424 1.2.2.2 thorpej while(len > 3) {
425 1.2.2.2 thorpej pa = kvtop(ptr);
426 1.2.2.2 thorpej max_t = NBPG - (pa & PGOFSET);
427 1.2.2.2 thorpej if (max_t > len)
428 1.2.2.2 thorpej max_t = len;
429 1.2.2.2 thorpej
430 1.2.2.2 thorpej max_t &= ~3;
431 1.2.2.2 thorpej
432 1.2.2.2 thorpej if (lastpa == pa)
433 1.2.2.2 thorpej sc->sc_chain[n-1].len += max_t;
434 1.2.2.2 thorpej else
435 1.2.2.2 thorpej set_link(n, pa, max_t, SFAS_CHAIN_DMA);
436 1.2.2.2 thorpej
437 1.2.2.2 thorpej lastpa = pa+max_t;
438 1.2.2.2 thorpej
439 1.2.2.2 thorpej ptr += max_t;
440 1.2.2.2 thorpej len -= max_t;
441 1.2.2.2 thorpej }
442 1.2.2.2 thorpej
443 1.2.2.2 thorpej if (len)
444 1.2.2.2 thorpej set_link(n, (vm_offset_t)ptr, len, SFAS_CHAIN_BUMP);
445 1.2.2.2 thorpej }
446 1.2.2.2 thorpej
447 1.2.2.2 thorpej return(n);
448 1.2.2.2 thorpej #endif
449 1.2.2.2 thorpej }
450 1.2.2.2 thorpej
451 1.2.2.2 thorpej /* Turn on/off led */
452 1.2.2.2 thorpej void
453 1.2.2.2 thorpej ptsc_led(sc, mode)
454 1.2.2.2 thorpej struct sfas_softc *sc;
455 1.2.2.2 thorpej int mode;
456 1.2.2.2 thorpej {
457 1.2.2.2 thorpej ptsc_regmap_p rp;
458 1.2.2.2 thorpej
459 1.2.2.2 thorpej rp = (ptsc_regmap_p)sc->sc_fas;
460 1.2.2.2 thorpej
461 1.2.2.2 thorpej if (mode) {
462 1.2.2.2 thorpej sc->sc_led_status++;
463 1.2.2.2 thorpej } else {
464 1.2.2.2 thorpej if (sc->sc_led_status)
465 1.2.2.2 thorpej sc->sc_led_status--;
466 1.2.2.2 thorpej }
467 1.2.2.2 thorpej *rp->led = (sc->sc_led_status?1:0);
468 1.2.2.2 thorpej }
469 1.2.2.2 thorpej
470 1.2.2.2 thorpej void
471 1.2.2.2 thorpej ptsc_scsi_request(chan, req, arg)
472 1.2.2.2 thorpej struct scsipi_channel *chan;
473 1.2.2.2 thorpej scsipi_adapter_req_t req;
474 1.2.2.2 thorpej void *arg;
475 1.2.2.2 thorpej {
476 1.2.2.2 thorpej struct scsipi_xfer *xs;
477 1.2.2.2 thorpej
478 1.2.2.2 thorpej switch (req) {
479 1.2.2.2 thorpej case ADAPTER_REQ_RUN_XFER:
480 1.2.2.2 thorpej xs = arg;
481 1.2.2.2 thorpej /* ensure command is polling for the moment */
482 1.2.2.2 thorpej #if PTSC_POLL > 0
483 1.2.2.2 thorpej xs->xs_control |= XS_CTL_POLL;
484 1.2.2.2 thorpej #endif
485 1.2.2.2 thorpej #if 0
486 1.2.2.2 thorpej printf("Opcode %d\n", (int)(xs->cmd->opcode));
487 1.2.2.2 thorpej #endif
488 1.2.2.2 thorpej default:
489 1.2.2.2 thorpej }
490 1.2.2.2 thorpej sfas_scsi_request(chan, req, arg);
491 1.2.2.2 thorpej }
492