esp.c revision 1.35.8.3 1 1.35.8.3 nathanw /* $NetBSD: esp.c,v 1.35.8.3 2002/08/01 02:42:47 nathanw Exp $ */
2 1.35.8.2 nathanw
3 1.35.8.2 nathanw /*-
4 1.35.8.2 nathanw * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.35.8.2 nathanw * All rights reserved.
6 1.35.8.2 nathanw *
7 1.35.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.35.8.2 nathanw * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 1.35.8.2 nathanw * Simulation Facility, NASA Ames Research Center.
10 1.35.8.2 nathanw *
11 1.35.8.2 nathanw * Redistribution and use in source and binary forms, with or without
12 1.35.8.2 nathanw * modification, are permitted provided that the following conditions
13 1.35.8.2 nathanw * are met:
14 1.35.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
15 1.35.8.2 nathanw * notice, this list of conditions and the following disclaimer.
16 1.35.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
17 1.35.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
18 1.35.8.2 nathanw * documentation and/or other materials provided with the distribution.
19 1.35.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
20 1.35.8.2 nathanw * must display the following acknowledgement:
21 1.35.8.2 nathanw * This product includes software developed by the NetBSD
22 1.35.8.2 nathanw * Foundation, Inc. and its contributors.
23 1.35.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.35.8.2 nathanw * contributors may be used to endorse or promote products derived
25 1.35.8.2 nathanw * from this software without specific prior written permission.
26 1.35.8.2 nathanw *
27 1.35.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.35.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.35.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.35.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.35.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.35.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.35.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.35.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.35.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.35.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.35.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
38 1.35.8.2 nathanw */
39 1.35.8.2 nathanw
40 1.35.8.2 nathanw /*
41 1.35.8.2 nathanw * Copyright (c) 1994 Peter Galbavy
42 1.35.8.2 nathanw * All rights reserved.
43 1.35.8.2 nathanw *
44 1.35.8.2 nathanw * Redistribution and use in source and binary forms, with or without
45 1.35.8.2 nathanw * modification, are permitted provided that the following conditions
46 1.35.8.2 nathanw * are met:
47 1.35.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
48 1.35.8.2 nathanw * notice, this list of conditions and the following disclaimer.
49 1.35.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
50 1.35.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
51 1.35.8.2 nathanw * documentation and/or other materials provided with the distribution.
52 1.35.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
53 1.35.8.2 nathanw * must display the following acknowledgement:
54 1.35.8.2 nathanw * This product includes software developed by Peter Galbavy
55 1.35.8.2 nathanw * 4. The name of the author may not be used to endorse or promote products
56 1.35.8.2 nathanw * derived from this software without specific prior written permission.
57 1.35.8.2 nathanw *
58 1.35.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 1.35.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
60 1.35.8.2 nathanw * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61 1.35.8.2 nathanw * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
62 1.35.8.2 nathanw * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
63 1.35.8.2 nathanw * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
64 1.35.8.2 nathanw * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.35.8.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66 1.35.8.2 nathanw * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
67 1.35.8.2 nathanw * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 1.35.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
69 1.35.8.2 nathanw */
70 1.35.8.2 nathanw
71 1.35.8.2 nathanw /*
72 1.35.8.2 nathanw * Based on aic6360 by Jarle Greipsland
73 1.35.8.2 nathanw *
74 1.35.8.2 nathanw * Acknowledgements: Many of the algorithms used in this driver are
75 1.35.8.2 nathanw * inspired by the work of Julian Elischer (julian (at) tfs.com) and
76 1.35.8.2 nathanw * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu). Thanks a million!
77 1.35.8.2 nathanw */
78 1.35.8.2 nathanw
79 1.35.8.2 nathanw /*
80 1.35.8.2 nathanw * Grabbed from the sparc port at revision 1.73 for the NeXT.
81 1.35.8.2 nathanw * Darrin B. Jewell <dbj (at) netbsd.org> Sat Jul 4 15:41:32 1998
82 1.35.8.2 nathanw */
83 1.35.8.2 nathanw
84 1.35.8.2 nathanw #include <sys/types.h>
85 1.35.8.2 nathanw #include <sys/param.h>
86 1.35.8.2 nathanw #include <sys/systm.h>
87 1.35.8.2 nathanw #include <sys/kernel.h>
88 1.35.8.2 nathanw #include <sys/errno.h>
89 1.35.8.2 nathanw #include <sys/ioctl.h>
90 1.35.8.2 nathanw #include <sys/device.h>
91 1.35.8.2 nathanw #include <sys/buf.h>
92 1.35.8.2 nathanw #include <sys/proc.h>
93 1.35.8.2 nathanw #include <sys/user.h>
94 1.35.8.2 nathanw #include <sys/queue.h>
95 1.35.8.2 nathanw
96 1.35.8.2 nathanw #include <dev/scsipi/scsi_all.h>
97 1.35.8.2 nathanw #include <dev/scsipi/scsipi_all.h>
98 1.35.8.2 nathanw #include <dev/scsipi/scsiconf.h>
99 1.35.8.2 nathanw #include <dev/scsipi/scsi_message.h>
100 1.35.8.2 nathanw
101 1.35.8.2 nathanw #include <machine/bus.h>
102 1.35.8.2 nathanw #include <machine/autoconf.h>
103 1.35.8.2 nathanw #include <machine/cpu.h>
104 1.35.8.2 nathanw
105 1.35.8.2 nathanw #include <dev/ic/ncr53c9xreg.h>
106 1.35.8.2 nathanw #include <dev/ic/ncr53c9xvar.h>
107 1.35.8.2 nathanw
108 1.35.8.2 nathanw #include <next68k/next68k/isr.h>
109 1.35.8.2 nathanw
110 1.35.8.2 nathanw #include <next68k/dev/nextdmareg.h>
111 1.35.8.2 nathanw #include <next68k/dev/nextdmavar.h>
112 1.35.8.2 nathanw
113 1.35.8.2 nathanw #include "espreg.h"
114 1.35.8.2 nathanw #include "espvar.h"
115 1.35.8.2 nathanw
116 1.35.8.2 nathanw #ifdef DEBUG
117 1.35.8.2 nathanw #define ESP_DEBUG
118 1.35.8.2 nathanw #endif
119 1.35.8.2 nathanw
120 1.35.8.2 nathanw #ifdef ESP_DEBUG
121 1.35.8.2 nathanw int esp_debug = 0;
122 1.35.8.2 nathanw #define DPRINTF(x) if (esp_debug) printf x;
123 1.35.8.3 nathanw int esplogshow = 0;
124 1.35.8.3 nathanw char esplog[8192+100];
125 1.35.8.3 nathanw char *esplogp = esplog;
126 1.35.8.3 nathanw #define ESPLOGIF 10 && (esplogp < (esplog + 8192))
127 1.35.8.2 nathanw #else
128 1.35.8.2 nathanw #define DPRINTF(x)
129 1.35.8.2 nathanw #endif
130 1.35.8.3 nathanw #define PRINTF(x) printf x;
131 1.35.8.2 nathanw
132 1.35.8.2 nathanw
133 1.35.8.2 nathanw void espattach_intio __P((struct device *, struct device *, void *));
134 1.35.8.2 nathanw int espmatch_intio __P((struct device *, struct cfdata *, void *));
135 1.35.8.2 nathanw
136 1.35.8.2 nathanw /* DMA callbacks */
137 1.35.8.2 nathanw bus_dmamap_t esp_dmacb_continue __P((void *arg));
138 1.35.8.2 nathanw void esp_dmacb_completed __P((bus_dmamap_t map, void *arg));
139 1.35.8.2 nathanw void esp_dmacb_shutdown __P((void *arg));
140 1.35.8.2 nathanw
141 1.35.8.2 nathanw #ifdef ESP_DEBUG
142 1.35.8.2 nathanw char esp_dma_dump[5*1024] = "";
143 1.35.8.2 nathanw struct ncr53c9x_softc *esp_debug_sc = 0;
144 1.35.8.2 nathanw void esp_dma_store __P((struct ncr53c9x_softc *sc));
145 1.35.8.2 nathanw void esp_dma_print __P((struct ncr53c9x_softc *sc));
146 1.35.8.2 nathanw int esp_dma_nest = 0;
147 1.35.8.2 nathanw #endif
148 1.35.8.2 nathanw
149 1.35.8.2 nathanw
150 1.35.8.2 nathanw /* Linkup to the rest of the kernel */
151 1.35.8.2 nathanw struct cfattach esp_ca = {
152 1.35.8.2 nathanw sizeof(struct esp_softc), espmatch_intio, espattach_intio
153 1.35.8.2 nathanw };
154 1.35.8.2 nathanw
155 1.35.8.2 nathanw /*
156 1.35.8.2 nathanw * Functions and the switch for the MI code.
157 1.35.8.2 nathanw */
158 1.35.8.2 nathanw u_char esp_read_reg __P((struct ncr53c9x_softc *, int));
159 1.35.8.2 nathanw void esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
160 1.35.8.2 nathanw int esp_dma_isintr __P((struct ncr53c9x_softc *));
161 1.35.8.2 nathanw void esp_dma_reset __P((struct ncr53c9x_softc *));
162 1.35.8.2 nathanw int esp_dma_intr __P((struct ncr53c9x_softc *));
163 1.35.8.2 nathanw int esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
164 1.35.8.2 nathanw size_t *, int, size_t *));
165 1.35.8.2 nathanw void esp_dma_go __P((struct ncr53c9x_softc *));
166 1.35.8.2 nathanw void esp_dma_stop __P((struct ncr53c9x_softc *));
167 1.35.8.2 nathanw int esp_dma_isactive __P((struct ncr53c9x_softc *));
168 1.35.8.2 nathanw
169 1.35.8.2 nathanw struct ncr53c9x_glue esp_glue = {
170 1.35.8.2 nathanw esp_read_reg,
171 1.35.8.2 nathanw esp_write_reg,
172 1.35.8.2 nathanw esp_dma_isintr,
173 1.35.8.2 nathanw esp_dma_reset,
174 1.35.8.2 nathanw esp_dma_intr,
175 1.35.8.2 nathanw esp_dma_setup,
176 1.35.8.2 nathanw esp_dma_go,
177 1.35.8.2 nathanw esp_dma_stop,
178 1.35.8.2 nathanw esp_dma_isactive,
179 1.35.8.2 nathanw NULL, /* gl_clear_latched_intr */
180 1.35.8.2 nathanw };
181 1.35.8.2 nathanw
182 1.35.8.2 nathanw #ifdef ESP_DEBUG
183 1.35.8.2 nathanw #define XCHR(x) "0123456789abcdef"[(x) & 0xf]
184 1.35.8.2 nathanw static void
185 1.35.8.2 nathanw esp_hex_dump(unsigned char *pkt, size_t len)
186 1.35.8.2 nathanw {
187 1.35.8.2 nathanw size_t i, j;
188 1.35.8.2 nathanw
189 1.35.8.2 nathanw printf("00000000 ");
190 1.35.8.2 nathanw for(i=0; i<len; i++) {
191 1.35.8.2 nathanw printf("%c%c ", XCHR(pkt[i]>>4), XCHR(pkt[i]));
192 1.35.8.2 nathanw if ((i+1) % 16 == 8) {
193 1.35.8.2 nathanw printf(" ");
194 1.35.8.2 nathanw }
195 1.35.8.2 nathanw if ((i+1) % 16 == 0) {
196 1.35.8.2 nathanw printf(" %c", '|');
197 1.35.8.2 nathanw for(j=0; j<16; j++) {
198 1.35.8.2 nathanw printf("%c", pkt[i-15+j]>=32 && pkt[i-15+j]<127?pkt[i-15+j]:'.');
199 1.35.8.2 nathanw }
200 1.35.8.2 nathanw printf("%c\n%c%c%c%c%c%c%c%c ", '|',
201 1.35.8.2 nathanw XCHR((i+1)>>28),XCHR((i+1)>>24),XCHR((i+1)>>20),XCHR((i+1)>>16),
202 1.35.8.2 nathanw XCHR((i+1)>>12), XCHR((i+1)>>8), XCHR((i+1)>>4), XCHR(i+1));
203 1.35.8.2 nathanw }
204 1.35.8.2 nathanw }
205 1.35.8.2 nathanw printf("\n");
206 1.35.8.2 nathanw }
207 1.35.8.2 nathanw #endif
208 1.35.8.2 nathanw
209 1.35.8.2 nathanw int
210 1.35.8.2 nathanw espmatch_intio(parent, cf, aux)
211 1.35.8.2 nathanw struct device *parent;
212 1.35.8.2 nathanw struct cfdata *cf;
213 1.35.8.2 nathanw void *aux;
214 1.35.8.2 nathanw {
215 1.35.8.2 nathanw /* should probably probe here */
216 1.35.8.2 nathanw /* Should also probably set up data from config */
217 1.35.8.2 nathanw
218 1.35.8.2 nathanw return(1);
219 1.35.8.2 nathanw }
220 1.35.8.2 nathanw
221 1.35.8.2 nathanw void
222 1.35.8.2 nathanw espattach_intio(parent, self, aux)
223 1.35.8.2 nathanw struct device *parent, *self;
224 1.35.8.2 nathanw void *aux;
225 1.35.8.2 nathanw {
226 1.35.8.2 nathanw struct esp_softc *esc = (void *)self;
227 1.35.8.2 nathanw struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
228 1.35.8.2 nathanw
229 1.35.8.2 nathanw #ifdef ESP_DEBUG
230 1.35.8.2 nathanw esp_debug_sc = sc;
231 1.35.8.2 nathanw #endif
232 1.35.8.2 nathanw
233 1.35.8.2 nathanw esc->sc_bst = NEXT68K_INTIO_BUS_SPACE;
234 1.35.8.2 nathanw if (bus_space_map(esc->sc_bst, NEXT_P_SCSI,
235 1.35.8.2 nathanw ESP_DEVICE_SIZE, 0, &esc->sc_bsh)) {
236 1.35.8.2 nathanw panic("\n%s: can't map ncr53c90 registers",
237 1.35.8.2 nathanw sc->sc_dev.dv_xname);
238 1.35.8.2 nathanw }
239 1.35.8.2 nathanw
240 1.35.8.2 nathanw sc->sc_id = 7;
241 1.35.8.2 nathanw sc->sc_freq = 20; /* Mhz */
242 1.35.8.2 nathanw
243 1.35.8.2 nathanw /*
244 1.35.8.2 nathanw * Set up glue for MI code early; we use some of it here.
245 1.35.8.2 nathanw */
246 1.35.8.2 nathanw sc->sc_glue = &esp_glue;
247 1.35.8.2 nathanw
248 1.35.8.2 nathanw /*
249 1.35.8.2 nathanw * XXX More of this should be in ncr53c9x_attach(), but
250 1.35.8.2 nathanw * XXX should we really poke around the chip that much in
251 1.35.8.2 nathanw * XXX the MI code? Think about this more...
252 1.35.8.2 nathanw */
253 1.35.8.2 nathanw
254 1.35.8.2 nathanw /*
255 1.35.8.2 nathanw * It is necessary to try to load the 2nd config register here,
256 1.35.8.2 nathanw * to find out what rev the esp chip is, else the ncr53c9x_reset
257 1.35.8.2 nathanw * will not set up the defaults correctly.
258 1.35.8.2 nathanw */
259 1.35.8.2 nathanw sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
260 1.35.8.2 nathanw sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE;
261 1.35.8.2 nathanw sc->sc_cfg3 = NCRCFG3_CDB;
262 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
263 1.35.8.2 nathanw
264 1.35.8.2 nathanw if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) !=
265 1.35.8.2 nathanw (NCRCFG2_SCSI2 | NCRCFG2_RPE)) {
266 1.35.8.2 nathanw sc->sc_rev = NCR_VARIANT_ESP100;
267 1.35.8.2 nathanw } else {
268 1.35.8.2 nathanw sc->sc_cfg2 = NCRCFG2_SCSI2;
269 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
270 1.35.8.2 nathanw sc->sc_cfg3 = 0;
271 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
272 1.35.8.2 nathanw sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK);
273 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
274 1.35.8.2 nathanw if (NCR_READ_REG(sc, NCR_CFG3) !=
275 1.35.8.2 nathanw (NCRCFG3_CDB | NCRCFG3_FCLK)) {
276 1.35.8.2 nathanw sc->sc_rev = NCR_VARIANT_ESP100A;
277 1.35.8.2 nathanw } else {
278 1.35.8.2 nathanw /* NCRCFG2_FE enables > 64K transfers */
279 1.35.8.2 nathanw sc->sc_cfg2 |= NCRCFG2_FE;
280 1.35.8.2 nathanw sc->sc_cfg3 = 0;
281 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
282 1.35.8.2 nathanw sc->sc_rev = NCR_VARIANT_ESP200;
283 1.35.8.2 nathanw }
284 1.35.8.2 nathanw }
285 1.35.8.2 nathanw
286 1.35.8.2 nathanw /*
287 1.35.8.2 nathanw * XXX minsync and maxxfer _should_ be set up in MI code,
288 1.35.8.2 nathanw * XXX but it appears to have some dependency on what sort
289 1.35.8.2 nathanw * XXX of DMA we're hooked up to, etc.
290 1.35.8.2 nathanw */
291 1.35.8.2 nathanw
292 1.35.8.2 nathanw /*
293 1.35.8.2 nathanw * This is the value used to start sync negotiations
294 1.35.8.2 nathanw * Note that the NCR register "SYNCTP" is programmed
295 1.35.8.2 nathanw * in "clocks per byte", and has a minimum value of 4.
296 1.35.8.2 nathanw * The SCSI period used in negotiation is one-fourth
297 1.35.8.2 nathanw * of the time (in nanoseconds) needed to transfer one byte.
298 1.35.8.2 nathanw * Since the chip's clock is given in MHz, we have the following
299 1.35.8.2 nathanw * formula: 4 * period = (1000 / freq) * 4
300 1.35.8.2 nathanw */
301 1.35.8.2 nathanw sc->sc_minsync = 1000 / sc->sc_freq;
302 1.35.8.2 nathanw
303 1.35.8.2 nathanw /*
304 1.35.8.2 nathanw * Alas, we must now modify the value a bit, because it's
305 1.35.8.2 nathanw * only valid when can switch on FASTCLK and FASTSCSI bits
306 1.35.8.2 nathanw * in config register 3...
307 1.35.8.2 nathanw */
308 1.35.8.2 nathanw switch (sc->sc_rev) {
309 1.35.8.2 nathanw case NCR_VARIANT_ESP100:
310 1.35.8.2 nathanw sc->sc_maxxfer = 64 * 1024;
311 1.35.8.2 nathanw sc->sc_minsync = 0; /* No synch on old chip? */
312 1.35.8.2 nathanw break;
313 1.35.8.2 nathanw
314 1.35.8.2 nathanw case NCR_VARIANT_ESP100A:
315 1.35.8.2 nathanw sc->sc_maxxfer = 64 * 1024;
316 1.35.8.2 nathanw /* Min clocks/byte is 5 */
317 1.35.8.2 nathanw sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5);
318 1.35.8.2 nathanw break;
319 1.35.8.2 nathanw
320 1.35.8.2 nathanw case NCR_VARIANT_ESP200:
321 1.35.8.2 nathanw sc->sc_maxxfer = 16 * 1024 * 1024;
322 1.35.8.2 nathanw /* XXX - do actually set FAST* bits */
323 1.35.8.2 nathanw break;
324 1.35.8.2 nathanw }
325 1.35.8.2 nathanw
326 1.35.8.2 nathanw /* @@@ Some ESP_DCTL bits probably need setting */
327 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
328 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_RESET);
329 1.35.8.2 nathanw DELAY(10);
330 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
331 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB);
332 1.35.8.2 nathanw DELAY(10);
333 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
334 1.35.8.2 nathanw
335 1.35.8.2 nathanw /* Set up SCSI DMA */
336 1.35.8.2 nathanw {
337 1.35.8.2 nathanw esc->sc_scsi_dma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
338 1.35.8.2 nathanw
339 1.35.8.2 nathanw if (bus_space_map(esc->sc_scsi_dma.nd_bst, NEXT_P_SCSI_CSR,
340 1.35.8.2 nathanw DD_SIZE,0, &esc->sc_scsi_dma.nd_bsh)) {
341 1.35.8.2 nathanw panic("\n%s: can't map scsi DMA registers",
342 1.35.8.2 nathanw sc->sc_dev.dv_xname);
343 1.35.8.2 nathanw }
344 1.35.8.2 nathanw
345 1.35.8.2 nathanw esc->sc_scsi_dma.nd_intr = NEXT_I_SCSI_DMA;
346 1.35.8.2 nathanw esc->sc_scsi_dma.nd_shutdown_cb = &esp_dmacb_shutdown;
347 1.35.8.2 nathanw esc->sc_scsi_dma.nd_continue_cb = &esp_dmacb_continue;
348 1.35.8.2 nathanw esc->sc_scsi_dma.nd_completed_cb = &esp_dmacb_completed;
349 1.35.8.2 nathanw esc->sc_scsi_dma.nd_cb_arg = sc;
350 1.35.8.2 nathanw nextdma_config(&esc->sc_scsi_dma);
351 1.35.8.2 nathanw nextdma_init(&esc->sc_scsi_dma);
352 1.35.8.2 nathanw
353 1.35.8.2 nathanw #if 0
354 1.35.8.2 nathanw /* Turn on target selection using the `dma' method */
355 1.35.8.2 nathanw sc->sc_features |= NCR_F_DMASELECT;
356 1.35.8.2 nathanw #endif
357 1.35.8.2 nathanw
358 1.35.8.2 nathanw esc->sc_datain = -1;
359 1.35.8.2 nathanw esc->sc_dmaaddr = 0;
360 1.35.8.2 nathanw esc->sc_dmalen = 0;
361 1.35.8.2 nathanw esc->sc_dmasize = 0;
362 1.35.8.2 nathanw
363 1.35.8.2 nathanw esc->sc_loaded = 0;
364 1.35.8.2 nathanw
365 1.35.8.2 nathanw esc->sc_begin = 0;
366 1.35.8.2 nathanw esc->sc_begin_size = 0;
367 1.35.8.2 nathanw
368 1.35.8.2 nathanw {
369 1.35.8.2 nathanw int error;
370 1.35.8.2 nathanw if ((error = bus_dmamap_create(esc->sc_scsi_dma.nd_dmat,
371 1.35.8.2 nathanw sc->sc_maxxfer, sc->sc_maxxfer/NBPG+1, sc->sc_maxxfer,
372 1.35.8.2 nathanw 0, BUS_DMA_ALLOCNOW, &esc->sc_main_dmamap)) != 0) {
373 1.35.8.2 nathanw panic("%s: can't create main i/o DMA map, error = %d",
374 1.35.8.2 nathanw sc->sc_dev.dv_xname,error);
375 1.35.8.2 nathanw }
376 1.35.8.2 nathanw }
377 1.35.8.2 nathanw esc->sc_main = 0;
378 1.35.8.2 nathanw esc->sc_main_size = 0;
379 1.35.8.2 nathanw
380 1.35.8.2 nathanw {
381 1.35.8.2 nathanw int error;
382 1.35.8.2 nathanw if ((error = bus_dmamap_create(esc->sc_scsi_dma.nd_dmat,
383 1.35.8.2 nathanw ESP_DMA_TAILBUFSIZE,
384 1.35.8.2 nathanw 1, ESP_DMA_TAILBUFSIZE,
385 1.35.8.2 nathanw 0, BUS_DMA_ALLOCNOW, &esc->sc_tail_dmamap)) != 0) {
386 1.35.8.2 nathanw panic("%s: can't create tail i/o DMA map, error = %d",
387 1.35.8.2 nathanw sc->sc_dev.dv_xname,error);
388 1.35.8.2 nathanw }
389 1.35.8.2 nathanw }
390 1.35.8.2 nathanw esc->sc_tail = 0;
391 1.35.8.2 nathanw esc->sc_tail_size = 0;
392 1.35.8.2 nathanw
393 1.35.8.2 nathanw }
394 1.35.8.2 nathanw
395 1.35.8.2 nathanw /* Establish interrupt channel */
396 1.35.8.2 nathanw isrlink_autovec(ncr53c9x_intr, sc, NEXT_I_IPL(NEXT_I_SCSI), 0);
397 1.35.8.2 nathanw INTR_ENABLE(NEXT_I_SCSI);
398 1.35.8.2 nathanw
399 1.35.8.2 nathanw /* register interrupt stats */
400 1.35.8.2 nathanw evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
401 1.35.8.2 nathanw sc->sc_dev.dv_xname, "intr");
402 1.35.8.2 nathanw
403 1.35.8.2 nathanw /* Do the common parts of attachment. */
404 1.35.8.2 nathanw sc->sc_adapter.adapt_minphys = minphys;
405 1.35.8.2 nathanw sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
406 1.35.8.2 nathanw ncr53c9x_attach(sc);
407 1.35.8.2 nathanw }
408 1.35.8.2 nathanw
409 1.35.8.2 nathanw /*
410 1.35.8.2 nathanw * Glue functions.
411 1.35.8.2 nathanw */
412 1.35.8.2 nathanw
413 1.35.8.2 nathanw u_char
414 1.35.8.2 nathanw esp_read_reg(sc, reg)
415 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
416 1.35.8.2 nathanw int reg;
417 1.35.8.2 nathanw {
418 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
419 1.35.8.2 nathanw
420 1.35.8.2 nathanw return(bus_space_read_1(esc->sc_bst, esc->sc_bsh, reg));
421 1.35.8.2 nathanw }
422 1.35.8.2 nathanw
423 1.35.8.2 nathanw void
424 1.35.8.2 nathanw esp_write_reg(sc, reg, val)
425 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
426 1.35.8.2 nathanw int reg;
427 1.35.8.2 nathanw u_char val;
428 1.35.8.2 nathanw {
429 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
430 1.35.8.2 nathanw
431 1.35.8.2 nathanw bus_space_write_1(esc->sc_bst, esc->sc_bsh, reg, val);
432 1.35.8.2 nathanw }
433 1.35.8.2 nathanw
434 1.35.8.3 nathanw volatile u_int32_t save1;
435 1.35.8.3 nathanw
436 1.35.8.3 nathanw #define xADDR 0x0211a000
437 1.35.8.3 nathanw int doze __P((volatile int));
438 1.35.8.3 nathanw int
439 1.35.8.3 nathanw doze(c)
440 1.35.8.3 nathanw volatile int c;
441 1.35.8.3 nathanw {
442 1.35.8.3 nathanw /* static int tmp1; */
443 1.35.8.3 nathanw u_int32_t tmp1;
444 1.35.8.3 nathanw volatile u_int8_t tmp2;
445 1.35.8.3 nathanw volatile u_int8_t *reg = (volatile u_int8_t *)IIOV(xADDR);
446 1.35.8.3 nathanw if (c > 244) return (0);
447 1.35.8.3 nathanw if (c == 0) return (0);
448 1.35.8.3 nathanw /* ((*(volatile u_long *)IIOV(NEXT_P_INTRMASK))&=(~NEXT_I_BIT(x))) */
449 1.35.8.3 nathanw (*reg) = 0;
450 1.35.8.3 nathanw (*reg) = 0;
451 1.35.8.3 nathanw do {
452 1.35.8.3 nathanw save1 = (*reg);
453 1.35.8.3 nathanw tmp2 = *(reg + 3);
454 1.35.8.3 nathanw tmp1 = tmp2;
455 1.35.8.3 nathanw } while (tmp1 <= c);
456 1.35.8.3 nathanw return (0);
457 1.35.8.3 nathanw }
458 1.35.8.3 nathanw
459 1.35.8.2 nathanw int
460 1.35.8.2 nathanw esp_dma_isintr(sc)
461 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
462 1.35.8.2 nathanw {
463 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
464 1.35.8.3 nathanw if (INTR_OCCURRED(NEXT_I_SCSI)) {
465 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'i';
466 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB | (esc->sc_datain ? ESPDCTL_DMARD : 0));
467 1.35.8.3 nathanw return (1);
468 1.35.8.3 nathanw } else {
469 1.35.8.3 nathanw return (0);
470 1.35.8.3 nathanw }
471 1.35.8.3 nathanw }
472 1.35.8.3 nathanw
473 1.35.8.3 nathanw int
474 1.35.8.3 nathanw esp_dma_intr(sc)
475 1.35.8.3 nathanw struct ncr53c9x_softc *sc;
476 1.35.8.3 nathanw {
477 1.35.8.3 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
478 1.35.8.2 nathanw
479 1.35.8.2 nathanw int r = (INTR_OCCURRED(NEXT_I_SCSI));
480 1.35.8.3 nathanw int flushcount;
481 1.35.8.3 nathanw r = 1;
482 1.35.8.2 nathanw
483 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'I';
484 1.35.8.2 nathanw if (r) {
485 1.35.8.3 nathanw /* printf ("esp_dma_isintr start\n"); */
486 1.35.8.2 nathanw {
487 1.35.8.3 nathanw int s = spldma();
488 1.35.8.3 nathanw void *ndmap = esc->sc_scsi_dma._nd_map;
489 1.35.8.3 nathanw int ndidx = esc->sc_scsi_dma._nd_idx;
490 1.35.8.3 nathanw splx(s);
491 1.35.8.2 nathanw
492 1.35.8.2 nathanw flushcount = 0;
493 1.35.8.2 nathanw
494 1.35.8.2 nathanw #ifdef ESP_DEBUG
495 1.35.8.3 nathanw /* esp_dma_nest++; */
496 1.35.8.2 nathanw
497 1.35.8.2 nathanw if (esp_debug) {
498 1.35.8.2 nathanw char sbuf[256];
499 1.35.8.2 nathanw
500 1.35.8.2 nathanw bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRSTAT)),
501 1.35.8.2 nathanw NEXT_INTR_BITS, sbuf, sizeof(sbuf));
502 1.35.8.2 nathanw printf("esp_dma_isintr = 0x%s\n", sbuf);
503 1.35.8.2 nathanw }
504 1.35.8.2 nathanw #endif
505 1.35.8.2 nathanw
506 1.35.8.3 nathanw while (!nextdma_finished(&esc->sc_scsi_dma)) { /* esp_dma_isactive(sc)) { */
507 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'w';
508 1.35.8.3 nathanw if (ESPLOGIF) {
509 1.35.8.3 nathanw sprintf (esplogp, "f%dm%dl%dw", NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF,
510 1.35.8.3 nathanw NCR_READ_REG((sc), NCR_TCM), NCR_READ_REG((sc), NCR_TCL));
511 1.35.8.3 nathanw esplogp += strlen (esplogp);
512 1.35.8.2 nathanw }
513 1.35.8.3 nathanw if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)
514 1.35.8.3 nathanw flushcount=5;
515 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD |
516 1.35.8.3 nathanw (esc->sc_datain ? ESPDCTL_DMARD : 0));
517 1.35.8.3 nathanw
518 1.35.8.3 nathanw s = spldma();
519 1.35.8.3 nathanw while (ndmap == esc->sc_scsi_dma._nd_map && ndidx == esc->sc_scsi_dma._nd_idx &&
520 1.35.8.3 nathanw !(bus_space_read_4(esc->sc_scsi_dma.nd_bst, esc->sc_scsi_dma.nd_bsh, DD_CSR)
521 1.35.8.3 nathanw & 0x08000000) &&
522 1.35.8.3 nathanw ++flushcount < 5) {
523 1.35.8.3 nathanw splx(s);
524 1.35.8.3 nathanw if (flushcount < 10) if (ESPLOGIF) *esplogp++ = 'F';
525 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_FLUSH |
526 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD |
527 1.35.8.3 nathanw (esc->sc_datain ? ESPDCTL_DMARD : 0));
528 1.35.8.3 nathanw doze(0x32);
529 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
530 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD |
531 1.35.8.3 nathanw (esc->sc_datain ? ESPDCTL_DMARD : 0));
532 1.35.8.3 nathanw doze(0x32);
533 1.35.8.3 nathanw s = spldma();
534 1.35.8.3 nathanw }
535 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = '0' + flushcount;
536 1.35.8.3 nathanw if (flushcount > 4) {
537 1.35.8.3 nathanw int next;
538 1.35.8.3 nathanw int onext = 0;
539 1.35.8.3 nathanw splx(s);
540 1.35.8.3 nathanw DPRINTF (("DMA reset\n"));
541 1.35.8.3 nathanw while (((next = bus_space_read_4(esc->sc_scsi_dma.nd_bst, esc->sc_scsi_dma.nd_bsh, DD_NEXT)) !=
542 1.35.8.3 nathanw (bus_space_read_4(esc->sc_scsi_dma.nd_bst, esc->sc_scsi_dma.nd_bsh, DD_LIMIT) & 0x7FFFFFFF)) &&
543 1.35.8.3 nathanw onext != next) {
544 1.35.8.3 nathanw onext = next;
545 1.35.8.3 nathanw DELAY(50);
546 1.35.8.3 nathanw }
547 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'R';
548 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB);
549 1.35.8.3 nathanw if (ESPLOGIF) {
550 1.35.8.3 nathanw sprintf (esplogp, "ff:%d tcm:%d tcl:%d ",
551 1.35.8.3 nathanw NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF,
552 1.35.8.3 nathanw NCR_READ_REG((sc), NCR_TCM), NCR_READ_REG((sc), NCR_TCL));
553 1.35.8.3 nathanw esplogp += strlen (esplogp);
554 1.35.8.3 nathanw }
555 1.35.8.3 nathanw s = spldma();
556 1.35.8.3 nathanw nextdma_reset (&esc->sc_scsi_dma);
557 1.35.8.3 nathanw splx(s);
558 1.35.8.3 nathanw goto out;
559 1.35.8.2 nathanw }
560 1.35.8.3 nathanw splx(s);
561 1.35.8.2 nathanw
562 1.35.8.2 nathanw #ifdef DIAGNOSTIC
563 1.35.8.3 nathanw if (flushcount > 4) {
564 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = '+';
565 1.35.8.3 nathanw printf("%s: unexpected flushcount %d on %s\n",sc->sc_dev.dv_xname,
566 1.35.8.3 nathanw flushcount, esc->sc_datain ? "read" : "write");
567 1.35.8.3 nathanw }
568 1.35.8.2 nathanw #endif
569 1.35.8.2 nathanw
570 1.35.8.3 nathanw if (!nextdma_finished(&esc->sc_scsi_dma)) { /* esp_dma_isactive(sc)) { */
571 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = '1';
572 1.35.8.2 nathanw }
573 1.35.8.3 nathanw flushcount = 0;
574 1.35.8.3 nathanw s = spldma();
575 1.35.8.3 nathanw ndmap = esc->sc_scsi_dma._nd_map;
576 1.35.8.3 nathanw ndidx = esc->sc_scsi_dma._nd_idx;
577 1.35.8.3 nathanw splx(s);
578 1.35.8.3 nathanw
579 1.35.8.3 nathanw goto loop;
580 1.35.8.3 nathanw
581 1.35.8.3 nathanw loop:
582 1.35.8.2 nathanw }
583 1.35.8.3 nathanw goto out;
584 1.35.8.3 nathanw out:
585 1.35.8.2 nathanw
586 1.35.8.2 nathanw #ifdef ESP_DEBUG
587 1.35.8.3 nathanw /* esp_dma_nest--; */
588 1.35.8.2 nathanw #endif
589 1.35.8.2 nathanw
590 1.35.8.2 nathanw }
591 1.35.8.2 nathanw
592 1.35.8.3 nathanw doze (0x32);
593 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB | (esc->sc_datain ? ESPDCTL_DMARD : 0));
594 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'b';
595 1.35.8.2 nathanw
596 1.35.8.3 nathanw while (esc->sc_datain != -1) DELAY(50);
597 1.35.8.3 nathanw
598 1.35.8.3 nathanw if (esc->sc_dmaaddr) {
599 1.35.8.3 nathanw bus_size_t xfer_len = 0;
600 1.35.8.3 nathanw int resid;
601 1.35.8.3 nathanw
602 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB);
603 1.35.8.3 nathanw if (esc->sc_scsi_dma.dm_xfer_exception == 0) {
604 1.35.8.3 nathanw resid = NCR_READ_REG((sc), NCR_TCL) + (NCR_READ_REG((sc), NCR_TCM) << 8);
605 1.35.8.3 nathanw if (resid) {
606 1.35.8.3 nathanw resid += (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF);
607 1.35.8.3 nathanw if (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)
608 1.35.8.3 nathanw if ((NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF) != 16 || NCR_READ_REG((sc), NCR_TCL) != 240)
609 1.35.8.3 nathanw esplogshow++;
610 1.35.8.3 nathanw }
611 1.35.8.3 nathanw xfer_len = esc->sc_dmasize - resid;
612 1.35.8.3 nathanw } else {
613 1.35.8.3 nathanw /*static*/ void ncr53c9x_abort(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
614 1.35.8.3 nathanw #define ncr53c9x_sched_msgout(m) \
615 1.35.8.3 nathanw do { \
616 1.35.8.3 nathanw NCR_MISC(("ncr53c9x_sched_msgout %x %d", m, __LINE__)); \
617 1.35.8.3 nathanw NCRCMD(sc, NCRCMD_SETATN); \
618 1.35.8.3 nathanw sc->sc_flags |= NCR_ATN; \
619 1.35.8.3 nathanw sc->sc_msgpriq |= (m); \
620 1.35.8.3 nathanw } while (0)
621 1.35.8.3 nathanw int i;
622 1.35.8.3 nathanw xfer_len = esc->sc_scsi_dma.dm_xfer_len;
623 1.35.8.3 nathanw resid = 0;
624 1.35.8.3 nathanw printf ("X\n");
625 1.35.8.3 nathanw for (i = 0; i < 16; i++) {
626 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_FLUSH |
627 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB |
628 1.35.8.3 nathanw (esc->sc_datain ? ESPDCTL_DMARD : 0));
629 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
630 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB |
631 1.35.8.3 nathanw (esc->sc_datain ? ESPDCTL_DMARD : 0));
632 1.35.8.3 nathanw }
633 1.35.8.3 nathanw #if 0
634 1.35.8.3 nathanw printf ("ff:%02x tcm:%d tcl:%d esp_dstat:%02x stat:%02x step: %02x intr:%02x new stat:%02X\n",
635 1.35.8.3 nathanw NCR_READ_REG(sc, NCR_FFLAG),
636 1.35.8.3 nathanw NCR_READ_REG((sc), NCR_TCM), NCR_READ_REG((sc), NCR_TCL),
637 1.35.8.3 nathanw NCR_READ_REG(sc, ESP_DSTAT),
638 1.35.8.3 nathanw sc->sc_espstat, sc->sc_espstep,
639 1.35.8.3 nathanw sc->sc_espintr, NCR_READ_REG(sc, NCR_STAT));
640 1.35.8.3 nathanw printf ("sc->sc_state: %x sc->sc_phase: %x sc->sc_espstep:%x sc->sc_prevphase:%x sc->sc_flags:%x\n",
641 1.35.8.3 nathanw sc->sc_state, sc->sc_phase, sc->sc_espstep, sc->sc_prevphase, sc->sc_flags);
642 1.35.8.3 nathanw #endif
643 1.35.8.3 nathanw /* sc->sc_flags &= ~NCR_ICCS; */
644 1.35.8.3 nathanw sc->sc_nexus->flags |= ECB_ABORT;
645 1.35.8.3 nathanw if (sc->sc_phase == MESSAGE_IN_PHASE) {
646 1.35.8.3 nathanw /* ncr53c9x_sched_msgout(SEND_ABORT); */
647 1.35.8.3 nathanw ncr53c9x_abort(sc, sc->sc_nexus);
648 1.35.8.3 nathanw } else if (sc->sc_phase != STATUS_PHASE) {
649 1.35.8.3 nathanw printf ("ATTENTION!!! not message/status phase: %d\n", sc->sc_phase);
650 1.35.8.3 nathanw }
651 1.35.8.3 nathanw }
652 1.35.8.3 nathanw
653 1.35.8.3 nathanw if (ESPLOGIF) {
654 1.35.8.3 nathanw sprintf (esplogp, "f%dm%dl%ds%dx%dr%dS", NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF, NCR_READ_REG((sc), NCR_TCM),
655 1.35.8.3 nathanw NCR_READ_REG((sc), NCR_TCL), esc->sc_dmasize, (int)xfer_len, resid);
656 1.35.8.3 nathanw esplogp += strlen (esplogp);
657 1.35.8.3 nathanw }
658 1.35.8.3 nathanw
659 1.35.8.3 nathanw *(esc->sc_dmaaddr) += xfer_len;
660 1.35.8.3 nathanw *(esc->sc_dmalen) -= xfer_len;
661 1.35.8.3 nathanw esc->sc_dmaaddr = 0;
662 1.35.8.3 nathanw esc->sc_dmalen = 0;
663 1.35.8.3 nathanw esc->sc_dmasize = 0;
664 1.35.8.2 nathanw }
665 1.35.8.3 nathanw
666 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'B';
667 1.35.8.3 nathanw sc->sc_espstat = NCR_READ_REG(sc, NCR_STAT) | (sc->sc_espstat & NCRSTAT_INT);
668 1.35.8.3 nathanw
669 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
670 1.35.8.3 nathanw /* printf ("esp_dma_isintr DONE\n"); */
671 1.35.8.2 nathanw
672 1.35.8.2 nathanw }
673 1.35.8.2 nathanw
674 1.35.8.2 nathanw return (r);
675 1.35.8.2 nathanw }
676 1.35.8.2 nathanw
677 1.35.8.2 nathanw void
678 1.35.8.2 nathanw esp_dma_reset(sc)
679 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
680 1.35.8.2 nathanw {
681 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
682 1.35.8.2 nathanw
683 1.35.8.2 nathanw DPRINTF(("esp dma reset\n"));
684 1.35.8.2 nathanw
685 1.35.8.2 nathanw #ifdef ESP_DEBUG
686 1.35.8.2 nathanw if (esp_debug) {
687 1.35.8.2 nathanw char sbuf[256];
688 1.35.8.2 nathanw
689 1.35.8.2 nathanw bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRSTAT)),
690 1.35.8.2 nathanw NEXT_INTR_BITS, sbuf, sizeof(sbuf));
691 1.35.8.2 nathanw printf(" *intrstat = 0x%s\n", sbuf);
692 1.35.8.2 nathanw
693 1.35.8.2 nathanw bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRMASK)),
694 1.35.8.2 nathanw NEXT_INTR_BITS, sbuf, sizeof(sbuf));
695 1.35.8.2 nathanw printf(" *intrmask = 0x%s\n", sbuf);
696 1.35.8.2 nathanw }
697 1.35.8.2 nathanw #endif
698 1.35.8.2 nathanw
699 1.35.8.2 nathanw /* Clear the DMAMOD bit in the DCTL register: */
700 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
701 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB);
702 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
703 1.35.8.2 nathanw
704 1.35.8.2 nathanw nextdma_reset(&esc->sc_scsi_dma);
705 1.35.8.3 nathanw nextdma_init(&esc->sc_scsi_dma);
706 1.35.8.2 nathanw
707 1.35.8.2 nathanw esc->sc_datain = -1;
708 1.35.8.2 nathanw esc->sc_dmaaddr = 0;
709 1.35.8.2 nathanw esc->sc_dmalen = 0;
710 1.35.8.2 nathanw esc->sc_dmasize = 0;
711 1.35.8.2 nathanw
712 1.35.8.2 nathanw esc->sc_loaded = 0;
713 1.35.8.2 nathanw
714 1.35.8.2 nathanw esc->sc_begin = 0;
715 1.35.8.2 nathanw esc->sc_begin_size = 0;
716 1.35.8.2 nathanw
717 1.35.8.2 nathanw if (esc->sc_main_dmamap->dm_mapsize) {
718 1.35.8.2 nathanw bus_dmamap_unload(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap);
719 1.35.8.2 nathanw }
720 1.35.8.2 nathanw esc->sc_main = 0;
721 1.35.8.2 nathanw esc->sc_main_size = 0;
722 1.35.8.2 nathanw
723 1.35.8.2 nathanw if (esc->sc_tail_dmamap->dm_mapsize) {
724 1.35.8.2 nathanw bus_dmamap_unload(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap);
725 1.35.8.2 nathanw }
726 1.35.8.2 nathanw esc->sc_tail = 0;
727 1.35.8.2 nathanw esc->sc_tail_size = 0;
728 1.35.8.2 nathanw }
729 1.35.8.2 nathanw
730 1.35.8.2 nathanw /* it appears that:
731 1.35.8.2 nathanw * addr and len arguments to this need to be kept up to date
732 1.35.8.2 nathanw * with the status of the transfter.
733 1.35.8.2 nathanw * the dmasize of this is the actual length of the transfer
734 1.35.8.2 nathanw * request, which is guaranteed to be less than maxxfer.
735 1.35.8.2 nathanw * (len may be > maxxfer)
736 1.35.8.2 nathanw */
737 1.35.8.2 nathanw
738 1.35.8.2 nathanw int
739 1.35.8.2 nathanw esp_dma_setup(sc, addr, len, datain, dmasize)
740 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
741 1.35.8.2 nathanw caddr_t *addr;
742 1.35.8.2 nathanw size_t *len;
743 1.35.8.2 nathanw int datain;
744 1.35.8.2 nathanw size_t *dmasize;
745 1.35.8.2 nathanw {
746 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
747 1.35.8.2 nathanw
748 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'h';
749 1.35.8.2 nathanw #ifdef DIAGNOSTIC
750 1.35.8.2 nathanw #ifdef ESP_DEBUG
751 1.35.8.2 nathanw /* if this is a read DMA, pre-fill the buffer with 0xdeadbeef
752 1.35.8.2 nathanw * to identify bogus reads
753 1.35.8.2 nathanw */
754 1.35.8.2 nathanw if (datain) {
755 1.35.8.2 nathanw int *v = (int *)(*addr);
756 1.35.8.2 nathanw int i;
757 1.35.8.2 nathanw for(i=0;i<((*len)/4);i++) v[i] = 0xdeadbeef;
758 1.35.8.2 nathanw v = (int *)(&(esc->sc_tailbuf[0]));
759 1.35.8.3 nathanw for(i=0;i<((sizeof(esc->sc_tailbuf)/4));i++) v[i] = 0xdeafbeef;
760 1.35.8.2 nathanw } else {
761 1.35.8.2 nathanw int *v;
762 1.35.8.2 nathanw int i;
763 1.35.8.2 nathanw v = (int *)(&(esc->sc_tailbuf[0]));
764 1.35.8.2 nathanw for(i=0;i<((sizeof(esc->sc_tailbuf)/4));i++) v[i] = 0xfeeb1eed;
765 1.35.8.2 nathanw }
766 1.35.8.2 nathanw #endif
767 1.35.8.2 nathanw #endif
768 1.35.8.2 nathanw
769 1.35.8.2 nathanw DPRINTF(("esp_dma_setup(%p,0x%08x,0x%08x)\n",*addr,*len,*dmasize));
770 1.35.8.2 nathanw
771 1.35.8.2 nathanw #if 0
772 1.35.8.2 nathanw #ifdef DIAGNOSTIC /* @@@ this is ok sometimes. verify that we handle it ok
773 1.35.8.3 nathanw * and then remove this check
774 1.35.8.3 nathanw */
775 1.35.8.2 nathanw if (*len != *dmasize) {
776 1.35.8.2 nathanw panic("esp dmalen 0x%lx != size 0x%lx",*len,*dmasize);
777 1.35.8.2 nathanw }
778 1.35.8.2 nathanw #endif
779 1.35.8.2 nathanw #endif
780 1.35.8.2 nathanw
781 1.35.8.2 nathanw #ifdef DIAGNOSTIC
782 1.35.8.2 nathanw if ((esc->sc_datain != -1) ||
783 1.35.8.2 nathanw (esc->sc_main_dmamap->dm_mapsize != 0) ||
784 1.35.8.2 nathanw (esc->sc_tail_dmamap->dm_mapsize != 0) ||
785 1.35.8.2 nathanw (esc->sc_dmasize != 0)) {
786 1.35.8.2 nathanw panic("%s: map already loaded in esp_dma_setup\n"
787 1.35.8.2 nathanw "\tdatain = %d\n\tmain_mapsize=%ld\n\tail_mapsize=%ld\n\tdmasize = %d",
788 1.35.8.2 nathanw sc->sc_dev.dv_xname, esc->sc_datain,
789 1.35.8.2 nathanw esc->sc_main_dmamap->dm_mapsize,
790 1.35.8.2 nathanw esc->sc_tail_dmamap->dm_mapsize,
791 1.35.8.2 nathanw esc->sc_dmasize);
792 1.35.8.2 nathanw }
793 1.35.8.2 nathanw #endif
794 1.35.8.2 nathanw
795 1.35.8.2 nathanw /* we are sometimes asked to dma zero bytes, that's easy */
796 1.35.8.2 nathanw if (*dmasize <= 0) {
797 1.35.8.2 nathanw return(0);
798 1.35.8.2 nathanw }
799 1.35.8.2 nathanw
800 1.35.8.3 nathanw if (*dmasize > ESP_MAX_DMASIZE)
801 1.35.8.3 nathanw *dmasize = ESP_MAX_DMASIZE;
802 1.35.8.3 nathanw
803 1.35.8.2 nathanw /* Save these in case we have to abort DMA */
804 1.35.8.2 nathanw esc->sc_datain = datain;
805 1.35.8.2 nathanw esc->sc_dmaaddr = addr;
806 1.35.8.2 nathanw esc->sc_dmalen = len;
807 1.35.8.2 nathanw esc->sc_dmasize = *dmasize;
808 1.35.8.2 nathanw
809 1.35.8.2 nathanw esc->sc_loaded = 0;
810 1.35.8.2 nathanw
811 1.35.8.2 nathanw #define DMA_SCSI_ALIGNMENT 16
812 1.35.8.2 nathanw #define DMA_SCSI_ALIGN(type, addr) \
813 1.35.8.2 nathanw ((type)(((unsigned)(addr)+DMA_SCSI_ALIGNMENT-1) \
814 1.35.8.2 nathanw &~(DMA_SCSI_ALIGNMENT-1)))
815 1.35.8.2 nathanw #define DMA_SCSI_ALIGNED(addr) \
816 1.35.8.2 nathanw (((unsigned)(addr)&(DMA_SCSI_ALIGNMENT-1))==0)
817 1.35.8.2 nathanw
818 1.35.8.2 nathanw {
819 1.35.8.2 nathanw size_t slop_bgn_size; /* # bytes to be fifo'd at beginning */
820 1.35.8.2 nathanw size_t slop_end_size; /* # bytes to be transferred in tail buffer */
821 1.35.8.2 nathanw
822 1.35.8.2 nathanw {
823 1.35.8.2 nathanw u_long bgn = (u_long)(*esc->sc_dmaaddr);
824 1.35.8.2 nathanw u_long end = (u_long)(*esc->sc_dmaaddr+esc->sc_dmasize);
825 1.35.8.2 nathanw
826 1.35.8.2 nathanw slop_bgn_size = DMA_SCSI_ALIGNMENT-(bgn % DMA_SCSI_ALIGNMENT);
827 1.35.8.2 nathanw if (slop_bgn_size == DMA_SCSI_ALIGNMENT) slop_bgn_size = 0;
828 1.35.8.2 nathanw slop_end_size = (end % DMA_ENDALIGNMENT);
829 1.35.8.2 nathanw }
830 1.35.8.2 nathanw
831 1.35.8.2 nathanw /* Force a minimum slop end size. This ensures that write
832 1.35.8.2 nathanw * requests will overrun, as required to get completion interrupts.
833 1.35.8.2 nathanw * In addition, since the tail buffer is guaranteed to be mapped
834 1.35.8.2 nathanw * in a single dma segment, the overrun won't accidentally
835 1.35.8.2 nathanw * end up in its own segment.
836 1.35.8.2 nathanw */
837 1.35.8.2 nathanw if (!esc->sc_datain) {
838 1.35.8.2 nathanw #if 0
839 1.35.8.2 nathanw slop_end_size += ESP_DMA_MAXTAIL;
840 1.35.8.2 nathanw #else
841 1.35.8.2 nathanw slop_end_size += 0x10;
842 1.35.8.2 nathanw #endif
843 1.35.8.2 nathanw }
844 1.35.8.2 nathanw
845 1.35.8.2 nathanw /* Check to make sure we haven't counted extra slop
846 1.35.8.2 nathanw * as would happen for a very short dma buffer, also
847 1.35.8.2 nathanw * for short buffers, just stuff the entire thing in the tail
848 1.35.8.2 nathanw */
849 1.35.8.2 nathanw if ((slop_bgn_size+slop_end_size >= esc->sc_dmasize)
850 1.35.8.2 nathanw #if 0
851 1.35.8.2 nathanw || (esc->sc_dmasize <= ESP_DMA_MAXTAIL)
852 1.35.8.2 nathanw #endif
853 1.35.8.2 nathanw )
854 1.35.8.2 nathanw {
855 1.35.8.2 nathanw slop_bgn_size = 0;
856 1.35.8.2 nathanw slop_end_size = esc->sc_dmasize;
857 1.35.8.2 nathanw }
858 1.35.8.2 nathanw
859 1.35.8.2 nathanw /* initialize the fifo buffer */
860 1.35.8.2 nathanw if (slop_bgn_size) {
861 1.35.8.2 nathanw esc->sc_begin = *esc->sc_dmaaddr;
862 1.35.8.2 nathanw esc->sc_begin_size = slop_bgn_size;
863 1.35.8.2 nathanw } else {
864 1.35.8.2 nathanw esc->sc_begin = 0;
865 1.35.8.2 nathanw esc->sc_begin_size = 0;
866 1.35.8.2 nathanw }
867 1.35.8.2 nathanw
868 1.35.8.3 nathanw #if 01
869 1.35.8.2 nathanw /* Load the normal DMA map */
870 1.35.8.2 nathanw {
871 1.35.8.2 nathanw esc->sc_main = *esc->sc_dmaaddr+slop_bgn_size;
872 1.35.8.2 nathanw esc->sc_main_size = (esc->sc_dmasize)-(slop_end_size+slop_bgn_size);
873 1.35.8.2 nathanw
874 1.35.8.2 nathanw if (esc->sc_main_size) {
875 1.35.8.2 nathanw int error;
876 1.35.8.3 nathanw
877 1.35.8.3 nathanw if (!esc->sc_datain || DMA_ENDALIGNED(esc->sc_main_size + slop_end_size)) {
878 1.35.8.3 nathanw KASSERT(DMA_SCSI_ALIGNMENT == DMA_ENDALIGNMENT);
879 1.35.8.3 nathanw KASSERT(DMA_BEGINALIGNMENT == DMA_ENDALIGNMENT);
880 1.35.8.3 nathanw esc->sc_main_size += slop_end_size;
881 1.35.8.3 nathanw slop_end_size = 0;
882 1.35.8.3 nathanw if (!esc->sc_datain) {
883 1.35.8.3 nathanw esc->sc_main_size = DMA_ENDALIGN(caddr_t,esc->sc_main+esc->sc_main_size)-esc->sc_main;
884 1.35.8.3 nathanw }
885 1.35.8.3 nathanw }
886 1.35.8.3 nathanw
887 1.35.8.2 nathanw error = bus_dmamap_load(esc->sc_scsi_dma.nd_dmat,
888 1.35.8.2 nathanw esc->sc_main_dmamap,
889 1.35.8.2 nathanw esc->sc_main, esc->sc_main_size,
890 1.35.8.2 nathanw NULL, BUS_DMA_NOWAIT);
891 1.35.8.2 nathanw if (error) {
892 1.35.8.2 nathanw #ifdef ESP_DEBUG
893 1.35.8.2 nathanw printf("%s: esc->sc_main_dmamap->_dm_size = %ld\n",
894 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_main_dmamap->_dm_size);
895 1.35.8.2 nathanw printf("%s: esc->sc_main_dmamap->_dm_segcnt = %d\n",
896 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_main_dmamap->_dm_segcnt);
897 1.35.8.2 nathanw printf("%s: esc->sc_main_dmamap->_dm_maxsegsz = %ld\n",
898 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_main_dmamap->_dm_maxsegsz);
899 1.35.8.2 nathanw printf("%s: esc->sc_main_dmamap->_dm_boundary = %ld\n",
900 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_main_dmamap->_dm_boundary);
901 1.35.8.2 nathanw esp_dma_print(sc);
902 1.35.8.2 nathanw #endif
903 1.35.8.2 nathanw panic("%s: can't load main dma map. error = %d, addr=%p, size=0x%08x",
904 1.35.8.2 nathanw sc->sc_dev.dv_xname, error,esc->sc_main,esc->sc_main_size);
905 1.35.8.2 nathanw }
906 1.35.8.3 nathanw if (!esc->sc_datain) { /* patch the dma map for write overrun */
907 1.35.8.3 nathanw esc->sc_main_dmamap->dm_mapsize += ESP_DMA_OVERRUN;
908 1.35.8.3 nathanw esc->sc_main_dmamap->dm_segs[esc->sc_main_dmamap->dm_nsegs - 1].ds_len +=
909 1.35.8.3 nathanw ESP_DMA_OVERRUN;
910 1.35.8.3 nathanw }
911 1.35.8.2 nathanw #if 0
912 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap,
913 1.35.8.2 nathanw 0, esc->sc_main_dmamap->dm_mapsize,
914 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
915 1.35.8.2 nathanw esc->sc_main_dmamap->dm_xfer_len = 0;
916 1.35.8.2 nathanw #endif
917 1.35.8.2 nathanw } else {
918 1.35.8.2 nathanw esc->sc_main = 0;
919 1.35.8.2 nathanw }
920 1.35.8.2 nathanw }
921 1.35.8.2 nathanw
922 1.35.8.2 nathanw /* Load the tail DMA map */
923 1.35.8.2 nathanw if (slop_end_size) {
924 1.35.8.2 nathanw esc->sc_tail = DMA_ENDALIGN(caddr_t,esc->sc_tailbuf+slop_end_size)-slop_end_size;
925 1.35.8.2 nathanw /* If the beginning of the tail is not correctly aligned,
926 1.35.8.2 nathanw * we have no choice but to align the start, which might then unalign the end.
927 1.35.8.2 nathanw */
928 1.35.8.2 nathanw esc->sc_tail = DMA_SCSI_ALIGN(caddr_t,esc->sc_tail);
929 1.35.8.2 nathanw /* So therefore, we change the tail size to be end aligned again. */
930 1.35.8.2 nathanw esc->sc_tail_size = DMA_ENDALIGN(caddr_t,esc->sc_tail+slop_end_size)-esc->sc_tail;
931 1.35.8.2 nathanw
932 1.35.8.2 nathanw /* @@@ next dma overrun lossage */
933 1.35.8.2 nathanw if (!esc->sc_datain) {
934 1.35.8.2 nathanw esc->sc_tail_size += ESP_DMA_OVERRUN;
935 1.35.8.2 nathanw }
936 1.35.8.2 nathanw
937 1.35.8.2 nathanw {
938 1.35.8.2 nathanw int error;
939 1.35.8.2 nathanw error = bus_dmamap_load(esc->sc_scsi_dma.nd_dmat,
940 1.35.8.2 nathanw esc->sc_tail_dmamap,
941 1.35.8.2 nathanw esc->sc_tail, esc->sc_tail_size,
942 1.35.8.2 nathanw NULL, BUS_DMA_NOWAIT);
943 1.35.8.2 nathanw if (error) {
944 1.35.8.2 nathanw panic("%s: can't load tail dma map. error = %d, addr=%p, size=0x%08x",
945 1.35.8.2 nathanw sc->sc_dev.dv_xname, error,esc->sc_tail,esc->sc_tail_size);
946 1.35.8.2 nathanw }
947 1.35.8.2 nathanw #if 0
948 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap,
949 1.35.8.2 nathanw 0, esc->sc_tail_dmamap->dm_mapsize,
950 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
951 1.35.8.2 nathanw esc->sc_tail_dmamap->dm_xfer_len = 0;
952 1.35.8.2 nathanw #endif
953 1.35.8.2 nathanw }
954 1.35.8.2 nathanw }
955 1.35.8.3 nathanw #else
956 1.35.8.3 nathanw
957 1.35.8.3 nathanw esc->sc_begin = *esc->sc_dmaaddr;
958 1.35.8.3 nathanw slop_bgn_size = DMA_SCSI_ALIGNMENT-((ulong)esc->sc_begin % DMA_SCSI_ALIGNMENT);
959 1.35.8.3 nathanw if (slop_bgn_size == DMA_SCSI_ALIGNMENT) slop_bgn_size = 0;
960 1.35.8.3 nathanw slop_end_size = esc->sc_dmasize - slop_bgn_size;
961 1.35.8.3 nathanw
962 1.35.8.3 nathanw if (slop_bgn_size < esc->sc_dmasize) {
963 1.35.8.3 nathanw int error;
964 1.35.8.3 nathanw
965 1.35.8.3 nathanw esc->sc_tail = 0;
966 1.35.8.3 nathanw esc->sc_tail_size = 0;
967 1.35.8.3 nathanw
968 1.35.8.3 nathanw esc->sc_begin_size = slop_bgn_size;
969 1.35.8.3 nathanw esc->sc_main = *esc->sc_dmaaddr+slop_bgn_size;
970 1.35.8.3 nathanw esc->sc_main_size = DMA_ENDALIGN(caddr_t,esc->sc_main+esc->sc_dmasize-slop_bgn_size)-esc->sc_main;
971 1.35.8.3 nathanw
972 1.35.8.3 nathanw if (!esc->sc_datain) {
973 1.35.8.3 nathanw esc->sc_main_size += ESP_DMA_OVERRUN;
974 1.35.8.3 nathanw }
975 1.35.8.3 nathanw error = bus_dmamap_load(esc->sc_scsi_dma.nd_dmat,
976 1.35.8.3 nathanw esc->sc_main_dmamap,
977 1.35.8.3 nathanw esc->sc_main, esc->sc_main_size,
978 1.35.8.3 nathanw NULL, BUS_DMA_NOWAIT);
979 1.35.8.3 nathanw if (error) {
980 1.35.8.3 nathanw panic("%s: can't load main dma map. error = %d, addr=%p, size=0x%08x",
981 1.35.8.3 nathanw sc->sc_dev.dv_xname, error,esc->sc_main,esc->sc_main_size);
982 1.35.8.3 nathanw }
983 1.35.8.3 nathanw } else {
984 1.35.8.3 nathanw esc->sc_begin = 0;
985 1.35.8.3 nathanw esc->sc_begin_size = 0;
986 1.35.8.3 nathanw esc->sc_main = 0;
987 1.35.8.3 nathanw esc->sc_main_size = 0;
988 1.35.8.3 nathanw
989 1.35.8.3 nathanw #if 0
990 1.35.8.3 nathanw esc->sc_tail = DMA_ENDALIGN(caddr_t,esc->sc_tailbuf+slop_bgn_size)-slop_bgn_size;
991 1.35.8.3 nathanw /* If the beginning of the tail is not correctly aligned,
992 1.35.8.3 nathanw * we have no choice but to align the start, which might then unalign the end.
993 1.35.8.3 nathanw */
994 1.35.8.3 nathanw #endif
995 1.35.8.3 nathanw esc->sc_tail = DMA_SCSI_ALIGN(caddr_t,esc->sc_tailbuf);
996 1.35.8.3 nathanw /* So therefore, we change the tail size to be end aligned again. */
997 1.35.8.3 nathanw esc->sc_tail_size = DMA_ENDALIGN(caddr_t,esc->sc_tail+esc->sc_dmasize)-esc->sc_tail;
998 1.35.8.3 nathanw
999 1.35.8.3 nathanw /* @@@ next dma overrun lossage */
1000 1.35.8.3 nathanw if (!esc->sc_datain) {
1001 1.35.8.3 nathanw esc->sc_tail_size += ESP_DMA_OVERRUN;
1002 1.35.8.3 nathanw }
1003 1.35.8.3 nathanw
1004 1.35.8.3 nathanw {
1005 1.35.8.3 nathanw int error;
1006 1.35.8.3 nathanw error = bus_dmamap_load(esc->sc_scsi_dma.nd_dmat,
1007 1.35.8.3 nathanw esc->sc_tail_dmamap,
1008 1.35.8.3 nathanw esc->sc_tail, esc->sc_tail_size,
1009 1.35.8.3 nathanw NULL, BUS_DMA_NOWAIT);
1010 1.35.8.3 nathanw if (error) {
1011 1.35.8.3 nathanw panic("%s: can't load tail dma map. error = %d, addr=%p, size=0x%08x",
1012 1.35.8.3 nathanw sc->sc_dev.dv_xname, error,esc->sc_tail,esc->sc_tail_size);
1013 1.35.8.3 nathanw }
1014 1.35.8.3 nathanw }
1015 1.35.8.3 nathanw }
1016 1.35.8.3 nathanw #endif
1017 1.35.8.3 nathanw
1018 1.35.8.3 nathanw DPRINTF(("%s: setup: %8p %d %8p %d %8p %d %8p %d\n", sc->sc_dev.dv_xname,
1019 1.35.8.3 nathanw *esc->sc_dmaaddr, esc->sc_dmasize, esc->sc_begin,
1020 1.35.8.3 nathanw esc->sc_begin_size, esc->sc_main, esc->sc_main_size, esc->sc_tail,
1021 1.35.8.3 nathanw esc->sc_tail_size));
1022 1.35.8.2 nathanw }
1023 1.35.8.2 nathanw
1024 1.35.8.2 nathanw return (0);
1025 1.35.8.2 nathanw }
1026 1.35.8.2 nathanw
1027 1.35.8.2 nathanw #ifdef ESP_DEBUG
1028 1.35.8.2 nathanw /* For debugging */
1029 1.35.8.2 nathanw void
1030 1.35.8.2 nathanw esp_dma_store(sc)
1031 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
1032 1.35.8.2 nathanw {
1033 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1034 1.35.8.2 nathanw char *p = &esp_dma_dump[0];
1035 1.35.8.2 nathanw
1036 1.35.8.2 nathanw p += sprintf(p,"%s: sc_datain=%d\n",sc->sc_dev.dv_xname,esc->sc_datain);
1037 1.35.8.2 nathanw p += sprintf(p,"%s: sc_loaded=0x%08x\n",sc->sc_dev.dv_xname,esc->sc_loaded);
1038 1.35.8.2 nathanw
1039 1.35.8.2 nathanw if (esc->sc_dmaaddr) {
1040 1.35.8.2 nathanw p += sprintf(p,"%s: sc_dmaaddr=%p\n",sc->sc_dev.dv_xname,*esc->sc_dmaaddr);
1041 1.35.8.2 nathanw } else {
1042 1.35.8.2 nathanw p += sprintf(p,"%s: sc_dmaaddr=NULL\n",sc->sc_dev.dv_xname);
1043 1.35.8.2 nathanw }
1044 1.35.8.2 nathanw if (esc->sc_dmalen) {
1045 1.35.8.2 nathanw p += sprintf(p,"%s: sc_dmalen=0x%08x\n",sc->sc_dev.dv_xname,*esc->sc_dmalen);
1046 1.35.8.2 nathanw } else {
1047 1.35.8.2 nathanw p += sprintf(p,"%s: sc_dmalen=NULL\n",sc->sc_dev.dv_xname);
1048 1.35.8.2 nathanw }
1049 1.35.8.2 nathanw p += sprintf(p,"%s: sc_dmasize=0x%08x\n",sc->sc_dev.dv_xname,esc->sc_dmasize);
1050 1.35.8.2 nathanw
1051 1.35.8.2 nathanw p += sprintf(p,"%s: sc_begin = %p, sc_begin_size = 0x%08x\n",
1052 1.35.8.2 nathanw sc->sc_dev.dv_xname, esc->sc_begin, esc->sc_begin_size);
1053 1.35.8.2 nathanw p += sprintf(p,"%s: sc_main = %p, sc_main_size = 0x%08x\n",
1054 1.35.8.2 nathanw sc->sc_dev.dv_xname, esc->sc_main, esc->sc_main_size);
1055 1.35.8.3 nathanw /* if (esc->sc_main) */ {
1056 1.35.8.2 nathanw int i;
1057 1.35.8.2 nathanw bus_dmamap_t map = esc->sc_main_dmamap;
1058 1.35.8.2 nathanw p += sprintf(p,"%s: sc_main_dmamap. mapsize = 0x%08lx, nsegs = %d\n",
1059 1.35.8.2 nathanw sc->sc_dev.dv_xname, map->dm_mapsize, map->dm_nsegs);
1060 1.35.8.2 nathanw for(i=0;i<map->dm_nsegs;i++) {
1061 1.35.8.2 nathanw p += sprintf(p,"%s: map->dm_segs[%d].ds_addr = 0x%08lx, len = 0x%08lx\n",
1062 1.35.8.2 nathanw sc->sc_dev.dv_xname, i, map->dm_segs[i].ds_addr, map->dm_segs[i].ds_len);
1063 1.35.8.2 nathanw }
1064 1.35.8.2 nathanw }
1065 1.35.8.2 nathanw p += sprintf(p,"%s: sc_tail = %p, sc_tail_size = 0x%08x\n",
1066 1.35.8.2 nathanw sc->sc_dev.dv_xname, esc->sc_tail, esc->sc_tail_size);
1067 1.35.8.3 nathanw /* if (esc->sc_tail) */ {
1068 1.35.8.2 nathanw int i;
1069 1.35.8.2 nathanw bus_dmamap_t map = esc->sc_tail_dmamap;
1070 1.35.8.2 nathanw p += sprintf(p,"%s: sc_tail_dmamap. mapsize = 0x%08lx, nsegs = %d\n",
1071 1.35.8.2 nathanw sc->sc_dev.dv_xname, map->dm_mapsize, map->dm_nsegs);
1072 1.35.8.2 nathanw for(i=0;i<map->dm_nsegs;i++) {
1073 1.35.8.2 nathanw p += sprintf(p,"%s: map->dm_segs[%d].ds_addr = 0x%08lx, len = 0x%08lx\n",
1074 1.35.8.2 nathanw sc->sc_dev.dv_xname, i, map->dm_segs[i].ds_addr, map->dm_segs[i].ds_len);
1075 1.35.8.2 nathanw }
1076 1.35.8.2 nathanw }
1077 1.35.8.2 nathanw }
1078 1.35.8.2 nathanw
1079 1.35.8.2 nathanw void
1080 1.35.8.2 nathanw esp_dma_print(sc)
1081 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
1082 1.35.8.2 nathanw {
1083 1.35.8.2 nathanw esp_dma_store(sc);
1084 1.35.8.2 nathanw printf("%s",esp_dma_dump);
1085 1.35.8.2 nathanw }
1086 1.35.8.2 nathanw #endif
1087 1.35.8.2 nathanw
1088 1.35.8.2 nathanw void
1089 1.35.8.2 nathanw esp_dma_go(sc)
1090 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
1091 1.35.8.2 nathanw {
1092 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1093 1.35.8.3 nathanw /* int s = spldma(); */
1094 1.35.8.3 nathanw
1095 1.35.8.3 nathanw if (esplogp != esplog) {
1096 1.35.8.3 nathanw if (esplogshow) {
1097 1.35.8.3 nathanw *esplogp = '\0';
1098 1.35.8.3 nathanw printf ("esplog: %s\n", esplog);
1099 1.35.8.3 nathanw esplogshow = 0;
1100 1.35.8.3 nathanw } else {
1101 1.35.8.3 nathanw DPRINTF (("X"));
1102 1.35.8.3 nathanw }
1103 1.35.8.3 nathanw esplogp = esplog;
1104 1.35.8.3 nathanw }
1105 1.35.8.2 nathanw
1106 1.35.8.2 nathanw DPRINTF(("%s: esp_dma_go(datain = %d)\n",
1107 1.35.8.2 nathanw sc->sc_dev.dv_xname, esc->sc_datain));
1108 1.35.8.2 nathanw
1109 1.35.8.2 nathanw #ifdef ESP_DEBUG
1110 1.35.8.2 nathanw if (esp_debug) esp_dma_print(sc);
1111 1.35.8.2 nathanw else esp_dma_store(sc);
1112 1.35.8.2 nathanw #endif
1113 1.35.8.2 nathanw
1114 1.35.8.2 nathanw #ifdef ESP_DEBUG
1115 1.35.8.2 nathanw {
1116 1.35.8.2 nathanw int n = NCR_READ_REG(sc, NCR_FFLAG);
1117 1.35.8.2 nathanw DPRINTF(("%s: fifo size = %d, seq = 0x%x\n",
1118 1.35.8.2 nathanw sc->sc_dev.dv_xname,
1119 1.35.8.2 nathanw n & NCRFIFO_FF, (n & NCRFIFO_SS)>>5));
1120 1.35.8.2 nathanw }
1121 1.35.8.2 nathanw #endif
1122 1.35.8.2 nathanw
1123 1.35.8.2 nathanw /* zero length dma transfers are boring */
1124 1.35.8.2 nathanw if (esc->sc_dmasize == 0) {
1125 1.35.8.3 nathanw /* splx(s); */
1126 1.35.8.2 nathanw return;
1127 1.35.8.2 nathanw }
1128 1.35.8.2 nathanw
1129 1.35.8.2 nathanw #if defined(DIAGNOSTIC)
1130 1.35.8.2 nathanw if ((esc->sc_begin_size == 0) &&
1131 1.35.8.2 nathanw (esc->sc_main_dmamap->dm_mapsize == 0) &&
1132 1.35.8.2 nathanw (esc->sc_tail_dmamap->dm_mapsize == 0)) {
1133 1.35.8.2 nathanw esp_dma_print(sc);
1134 1.35.8.2 nathanw panic("%s: No DMA requested!",sc->sc_dev.dv_xname);
1135 1.35.8.2 nathanw }
1136 1.35.8.2 nathanw #endif
1137 1.35.8.2 nathanw
1138 1.35.8.2 nathanw /* Stuff the fifo with the begin buffer */
1139 1.35.8.2 nathanw if (esc->sc_datain) {
1140 1.35.8.2 nathanw int i;
1141 1.35.8.2 nathanw DPRINTF(("%s: FIFO read of %d bytes:",
1142 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_begin_size));
1143 1.35.8.2 nathanw for(i=0;i<esc->sc_begin_size;i++) {
1144 1.35.8.2 nathanw esc->sc_begin[i]=NCR_READ_REG(sc, NCR_FIFO);
1145 1.35.8.2 nathanw DPRINTF((" %02x",esc->sc_begin[i]&0xff));
1146 1.35.8.2 nathanw }
1147 1.35.8.2 nathanw DPRINTF(("\n"));
1148 1.35.8.2 nathanw } else {
1149 1.35.8.2 nathanw int i;
1150 1.35.8.2 nathanw DPRINTF(("%s: FIFO write of %d bytes:",
1151 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_begin_size));
1152 1.35.8.2 nathanw for(i=0;i<esc->sc_begin_size;i++) {
1153 1.35.8.2 nathanw NCR_WRITE_REG(sc, NCR_FIFO, esc->sc_begin[i]);
1154 1.35.8.2 nathanw DPRINTF((" %02x",esc->sc_begin[i]&0xff));
1155 1.35.8.2 nathanw }
1156 1.35.8.2 nathanw DPRINTF(("\n"));
1157 1.35.8.2 nathanw }
1158 1.35.8.2 nathanw
1159 1.35.8.2 nathanw if (esc->sc_main_dmamap->dm_mapsize) {
1160 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap,
1161 1.35.8.2 nathanw 0, esc->sc_main_dmamap->dm_mapsize,
1162 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1163 1.35.8.2 nathanw esc->sc_main_dmamap->dm_xfer_len = 0;
1164 1.35.8.2 nathanw }
1165 1.35.8.2 nathanw
1166 1.35.8.2 nathanw if (esc->sc_tail_dmamap->dm_mapsize) {
1167 1.35.8.3 nathanw /* if we are a dma write cycle, copy the end slop */
1168 1.35.8.3 nathanw if (!esc->sc_datain) {
1169 1.35.8.3 nathanw memcpy(esc->sc_tail, *esc->sc_dmaaddr+esc->sc_begin_size+esc->sc_main_size,
1170 1.35.8.3 nathanw esc->sc_dmasize-(esc->sc_begin_size+esc->sc_main_size));
1171 1.35.8.3 nathanw }
1172 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap,
1173 1.35.8.2 nathanw 0, esc->sc_tail_dmamap->dm_mapsize,
1174 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1175 1.35.8.2 nathanw esc->sc_tail_dmamap->dm_xfer_len = 0;
1176 1.35.8.2 nathanw }
1177 1.35.8.2 nathanw
1178 1.35.8.3 nathanw esc->sc_scsi_dma.dm_xfer_len = 0;
1179 1.35.8.3 nathanw esc->sc_scsi_dma.dm_xfer_exception = 0;
1180 1.35.8.2 nathanw nextdma_start(&esc->sc_scsi_dma,
1181 1.35.8.2 nathanw (esc->sc_datain ? DMACSR_SETREAD : DMACSR_SETWRITE));
1182 1.35.8.2 nathanw
1183 1.35.8.2 nathanw if (esc->sc_datain) {
1184 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1185 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD | ESPDCTL_DMARD);
1186 1.35.8.2 nathanw } else {
1187 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1188 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMAMOD);
1189 1.35.8.2 nathanw }
1190 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
1191 1.35.8.3 nathanw
1192 1.35.8.3 nathanw if (esc->sc_begin_size) if (ESPLOGIF) { *esplogp++ = '1'; *esplogp++ = 'A' + esc->sc_begin_size; }
1193 1.35.8.3 nathanw if (esc->sc_main_size) if (ESPLOGIF) { *esplogp++ = '2'; *esplogp++ = '0' + esc->sc_main_dmamap->dm_nsegs; }
1194 1.35.8.3 nathanw if (esc->sc_tail_size) if (ESPLOGIF) { *esplogp++ = '3'; *esplogp++ = 'A' + esc->sc_tail_size; }
1195 1.35.8.3 nathanw
1196 1.35.8.3 nathanw /* splx(s); */
1197 1.35.8.2 nathanw }
1198 1.35.8.2 nathanw
1199 1.35.8.2 nathanw void
1200 1.35.8.2 nathanw esp_dma_stop(sc)
1201 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
1202 1.35.8.2 nathanw {
1203 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1204 1.35.8.2 nathanw next_dma_print(&esc->sc_scsi_dma);
1205 1.35.8.2 nathanw esp_dma_print(sc);
1206 1.35.8.3 nathanw #if 1
1207 1.35.8.2 nathanw panic("%s: stop not yet implemented\n",sc->sc_dev.dv_xname);
1208 1.35.8.3 nathanw #endif
1209 1.35.8.2 nathanw }
1210 1.35.8.2 nathanw
1211 1.35.8.2 nathanw int
1212 1.35.8.2 nathanw esp_dma_isactive(sc)
1213 1.35.8.2 nathanw struct ncr53c9x_softc *sc;
1214 1.35.8.2 nathanw {
1215 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1216 1.35.8.3 nathanw int r = (esc->sc_dmaaddr != NULL); /* !nextdma_finished(&esc->sc_scsi_dma); */
1217 1.35.8.2 nathanw DPRINTF(("esp_dma_isactive = %d\n",r));
1218 1.35.8.2 nathanw return(r);
1219 1.35.8.2 nathanw }
1220 1.35.8.2 nathanw
1221 1.35.8.2 nathanw /****************************************************************/
1222 1.35.8.2 nathanw
1223 1.35.8.3 nathanw int esp_dma_int __P((void *));
1224 1.35.8.3 nathanw int esp_dma_int(arg)
1225 1.35.8.3 nathanw void *arg;
1226 1.35.8.3 nathanw {
1227 1.35.8.3 nathanw void next_dma_rotate __P((struct nextdma_config *));
1228 1.35.8.3 nathanw void next_dma_setup_curr_regs __P((struct nextdma_config *));
1229 1.35.8.3 nathanw void next_dma_setup_cont_regs __P((struct nextdma_config *));
1230 1.35.8.3 nathanw
1231 1.35.8.3 nathanw struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
1232 1.35.8.3 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1233 1.35.8.3 nathanw unsigned int state;
1234 1.35.8.3 nathanw unsigned int ds_len;
1235 1.35.8.3 nathanw struct nextdma_config *nd = &esc->sc_scsi_dma;
1236 1.35.8.3 nathanw
1237 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'E';
1238 1.35.8.3 nathanw
1239 1.35.8.3 nathanw state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
1240 1.35.8.3 nathanw
1241 1.35.8.3 nathanw #if 1
1242 1.35.8.3 nathanw if (state & DMACSR_COMPLETE) if (ESPLOGIF) *esplogp++ = 'c';
1243 1.35.8.3 nathanw if (state & DMACSR_ENABLE) if (ESPLOGIF) *esplogp++ = 'e';
1244 1.35.8.3 nathanw if (state & DMACSR_BUSEXC) if (ESPLOGIF) *esplogp++ = 'b';
1245 1.35.8.3 nathanw if (state & DMACSR_READ) if (ESPLOGIF) *esplogp++ = 'r';
1246 1.35.8.3 nathanw if (state & DMACSR_SUPDATE) if (ESPLOGIF) *esplogp++ = 's';
1247 1.35.8.3 nathanw
1248 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'E';
1249 1.35.8.3 nathanw
1250 1.35.8.3 nathanw if (0) if ((state & DMACSR_BUSEXC) && (state & DMACSR_ENABLE)) esplogshow++;
1251 1.35.8.3 nathanw if (0) if ((state & DMACSR_SUPDATE)) esplogshow++;
1252 1.35.8.3 nathanw #endif
1253 1.35.8.3 nathanw
1254 1.35.8.3 nathanw ds_len = nd->_nd_map->dm_segs[nd->_nd_idx].ds_len;
1255 1.35.8.3 nathanw
1256 1.35.8.3 nathanw if ((nd->_nd_idx+1) == nd->_nd_map->dm_nsegs) {
1257 1.35.8.3 nathanw if (nd->nd_completed_cb)
1258 1.35.8.3 nathanw (*nd->nd_completed_cb)(nd->_nd_map, nd->nd_cb_arg);
1259 1.35.8.3 nathanw }
1260 1.35.8.3 nathanw next_dma_rotate(nd);
1261 1.35.8.3 nathanw
1262 1.35.8.3 nathanw if ((state & DMACSR_COMPLETE) && (state & DMACSR_ENABLE)) {
1263 1.35.8.3 nathanw #if 0
1264 1.35.8.3 nathanw int l = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT) & 0x7FFFFFFF;
1265 1.35.8.3 nathanw int s = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP);
1266 1.35.8.3 nathanw #endif
1267 1.35.8.3 nathanw /* next_dma_setup_cont_regs(nd); */
1268 1.35.8.3 nathanw if (nd->_nd_map_cont) {
1269 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,
1270 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
1271 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP,
1272 1.35.8.3 nathanw (nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
1273 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len) | 0/* x80000000 */);
1274 1.35.8.3 nathanw }
1275 1.35.8.3 nathanw
1276 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
1277 1.35.8.3 nathanw DMACSR_CLRCOMPLETE | (state & DMACSR_READ ? DMACSR_SETREAD : DMACSR_SETWRITE) |
1278 1.35.8.3 nathanw (nd->_nd_map_cont ? DMACSR_SETSUPDATE : 0));
1279 1.35.8.3 nathanw
1280 1.35.8.3 nathanw if (nd->dm_xfer_exception == 0) {
1281 1.35.8.3 nathanw nd->dm_xfer_len += ds_len;
1282 1.35.8.3 nathanw }
1283 1.35.8.3 nathanw
1284 1.35.8.3 nathanw #if 0
1285 1.35.8.3 nathanw if (state & DMACSR_BUSEXC) {
1286 1.35.8.3 nathanw sprintf (esplogp, "CE/BUSEXC: %08lX %08X %08X\n",
1287 1.35.8.3 nathanw (nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr + nd->_nd_map->dm_segs[nd->_nd_idx].ds_len),
1288 1.35.8.3 nathanw l, s);
1289 1.35.8.3 nathanw esplogp += strlen (esplogp);
1290 1.35.8.3 nathanw }
1291 1.35.8.3 nathanw #endif
1292 1.35.8.3 nathanw } else {
1293 1.35.8.3 nathanw #if 0
1294 1.35.8.3 nathanw if (state & DMACSR_BUSEXC) {
1295 1.35.8.3 nathanw while (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT) !=
1296 1.35.8.3 nathanw (bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT) & 0x7FFFFFFF))
1297 1.35.8.3 nathanw printf ("Y"); /* DELAY(50); */
1298 1.35.8.3 nathanw state = bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_CSR);
1299 1.35.8.3 nathanw }
1300 1.35.8.3 nathanw #endif
1301 1.35.8.3 nathanw
1302 1.35.8.3 nathanw if (!(state & DMACSR_SUPDATE)) {
1303 1.35.8.3 nathanw next_dma_rotate(nd);
1304 1.35.8.3 nathanw } else {
1305 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE |
1306 1.35.8.3 nathanw DMACSR_INITBUF | DMACSR_RESET |
1307 1.35.8.3 nathanw (state & DMACSR_READ ? DMACSR_SETREAD : DMACSR_SETWRITE));
1308 1.35.8.3 nathanw
1309 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT, nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
1310 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT,
1311 1.35.8.3 nathanw (nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
1312 1.35.8.3 nathanw nd->_nd_map->dm_segs[nd->_nd_idx].ds_len) | 0/* x80000000 */);
1313 1.35.8.3 nathanw if (nd->_nd_map_cont) {
1314 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,
1315 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
1316 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP,
1317 1.35.8.3 nathanw (nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
1318 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len) | 0/* x80000000 */);
1319 1.35.8.3 nathanw }
1320 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_SETENABLE |
1321 1.35.8.3 nathanw DMACSR_CLRCOMPLETE | (state & DMACSR_READ ? DMACSR_SETREAD : DMACSR_SETWRITE) |
1322 1.35.8.3 nathanw (nd->_nd_map_cont ? DMACSR_SETSUPDATE : 0));
1323 1.35.8.3 nathanw #if 1
1324 1.35.8.3 nathanw sprintf (esplogp, "supdate ");
1325 1.35.8.3 nathanw esplogp += strlen (esplogp);
1326 1.35.8.3 nathanw sprintf (esplogp, "%08X %08X %08X %08X ",
1327 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT),
1328 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT) & 0x7FFFFFFF,
1329 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START),
1330 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP) & 0x7FFFFFFF);
1331 1.35.8.3 nathanw esplogp += strlen (esplogp);
1332 1.35.8.3 nathanw #endif
1333 1.35.8.3 nathanw nd->dm_xfer_exception++;
1334 1.35.8.3 nathanw return(1);
1335 1.35.8.3 nathanw /* NCR_WRITE_REG(sc, ESP_DCTL, ctl); */
1336 1.35.8.3 nathanw goto restart;
1337 1.35.8.3 nathanw }
1338 1.35.8.3 nathanw
1339 1.35.8.3 nathanw if (nd->_nd_map) {
1340 1.35.8.3 nathanw #if 1
1341 1.35.8.3 nathanw sprintf (esplogp, "%08X %08X %08X %08X ",
1342 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_NEXT),
1343 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT) & 0x7FFFFFFF,
1344 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_START),
1345 1.35.8.3 nathanw bus_space_read_4(nd->nd_bst, nd->nd_bsh, DD_STOP) & 0x7FFFFFFF);
1346 1.35.8.3 nathanw esplogp += strlen (esplogp);
1347 1.35.8.3 nathanw #endif
1348 1.35.8.3 nathanw
1349 1.35.8.3 nathanw #if 0
1350 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
1351 1.35.8.3 nathanw
1352 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, 0);
1353 1.35.8.3 nathanw #endif
1354 1.35.8.3 nathanw #if 1
1355 1.35.8.3 nathanw /* 6/2 */
1356 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE |
1357 1.35.8.3 nathanw DMACSR_INITBUF | DMACSR_RESET |
1358 1.35.8.3 nathanw (state & DMACSR_READ ? DMACSR_SETREAD : DMACSR_SETWRITE));
1359 1.35.8.3 nathanw
1360 1.35.8.3 nathanw /* next_dma_setup_curr_regs(nd); */
1361 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_NEXT, nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr);
1362 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_LIMIT,
1363 1.35.8.3 nathanw (nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
1364 1.35.8.3 nathanw nd->_nd_map->dm_segs[nd->_nd_idx].ds_len) | 0/* x80000000 */);
1365 1.35.8.3 nathanw /* next_dma_setup_cont_regs(nd); */
1366 1.35.8.3 nathanw if (nd->_nd_map_cont) {
1367 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_START,
1368 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr);
1369 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_STOP,
1370 1.35.8.3 nathanw (nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
1371 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len) | 0/* x80000000 */);
1372 1.35.8.3 nathanw }
1373 1.35.8.3 nathanw
1374 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR,
1375 1.35.8.3 nathanw DMACSR_SETENABLE | (nd->_nd_map_cont ? DMACSR_SETSUPDATE : 0) |
1376 1.35.8.3 nathanw (state & DMACSR_READ ? DMACSR_SETREAD : DMACSR_SETWRITE));
1377 1.35.8.3 nathanw /* esplogshow++; */
1378 1.35.8.3 nathanw nd->dm_xfer_exception++;
1379 1.35.8.3 nathanw return(1);
1380 1.35.8.3 nathanw #endif
1381 1.35.8.3 nathanw /* NCR_WRITE_REG(sc, ESP_DCTL, ctl); */
1382 1.35.8.3 nathanw goto restart;
1383 1.35.8.3 nathanw restart:
1384 1.35.8.3 nathanw #if 1
1385 1.35.8.3 nathanw sprintf (esplogp, "restart %08lX %08lX\n",
1386 1.35.8.3 nathanw nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr,
1387 1.35.8.3 nathanw nd->_nd_map->dm_segs[nd->_nd_idx].ds_addr +
1388 1.35.8.3 nathanw nd->_nd_map->dm_segs[nd->_nd_idx].ds_len);
1389 1.35.8.3 nathanw if (nd->_nd_map_cont) {
1390 1.35.8.3 nathanw sprintf (esplogp + strlen(esplogp) - 1, " %08lX %08lX\n",
1391 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr,
1392 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_addr +
1393 1.35.8.3 nathanw nd->_nd_map_cont->dm_segs[nd->_nd_idx_cont].ds_len);
1394 1.35.8.3 nathanw }
1395 1.35.8.3 nathanw esplogp += strlen (esplogp);
1396 1.35.8.3 nathanw #endif
1397 1.35.8.3 nathanw next_dma_print(nd);
1398 1.35.8.3 nathanw NCR_WRITE_REG(sc, ESP_DCTL, ESPDCTL_16MHZ | ESPDCTL_INTENB);
1399 1.35.8.3 nathanw printf ("ff:%02x tcm:%d tcl:%d esp_dstat:%02x state:%02x step: %02x intr:%02x state:%08X\n",
1400 1.35.8.3 nathanw NCR_READ_REG(sc, NCR_FFLAG),
1401 1.35.8.3 nathanw NCR_READ_REG((sc), NCR_TCM), NCR_READ_REG((sc), NCR_TCL),
1402 1.35.8.3 nathanw NCR_READ_REG(sc, ESP_DSTAT),
1403 1.35.8.3 nathanw NCR_READ_REG(sc, NCR_STAT), NCR_READ_REG(sc, NCR_STEP),
1404 1.35.8.3 nathanw NCR_READ_REG(sc, NCR_INTR), state);
1405 1.35.8.3 nathanw *esplogp = '\0';
1406 1.35.8.3 nathanw printf ("esplog: %s\n", esplog);
1407 1.35.8.3 nathanw panic("%s: busexc/supdate occured. Please email this output to chris (at) pin.lu.",
1408 1.35.8.3 nathanw sc->sc_dev.dv_xname);
1409 1.35.8.3 nathanw esplogshow++;
1410 1.35.8.3 nathanw } else {
1411 1.35.8.3 nathanw bus_space_write_4(nd->nd_bst, nd->nd_bsh, DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
1412 1.35.8.3 nathanw if (nd->nd_shutdown_cb) (*nd->nd_shutdown_cb)(nd->nd_cb_arg);
1413 1.35.8.3 nathanw }
1414 1.35.8.3 nathanw }
1415 1.35.8.3 nathanw return (1);
1416 1.35.8.3 nathanw }
1417 1.35.8.3 nathanw
1418 1.35.8.2 nathanw /* Internal dma callback routines */
1419 1.35.8.2 nathanw bus_dmamap_t
1420 1.35.8.2 nathanw esp_dmacb_continue(arg)
1421 1.35.8.2 nathanw void *arg;
1422 1.35.8.2 nathanw {
1423 1.35.8.2 nathanw struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
1424 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1425 1.35.8.2 nathanw
1426 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'x';
1427 1.35.8.2 nathanw DPRINTF(("%s: dma continue\n",sc->sc_dev.dv_xname));
1428 1.35.8.2 nathanw
1429 1.35.8.2 nathanw #ifdef DIAGNOSTIC
1430 1.35.8.2 nathanw if ((esc->sc_datain < 0) || (esc->sc_datain > 1)) {
1431 1.35.8.2 nathanw panic("%s: map not loaded in dma continue callback, datain = %d",
1432 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_datain);
1433 1.35.8.2 nathanw }
1434 1.35.8.2 nathanw #endif
1435 1.35.8.2 nathanw
1436 1.35.8.2 nathanw if ((!(esc->sc_loaded & ESP_LOADED_MAIN)) &&
1437 1.35.8.2 nathanw (esc->sc_main_dmamap->dm_mapsize)) {
1438 1.35.8.2 nathanw DPRINTF(("%s: Loading main map\n",sc->sc_dev.dv_xname));
1439 1.35.8.2 nathanw #if 0
1440 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap,
1441 1.35.8.2 nathanw 0, esc->sc_main_dmamap->dm_mapsize,
1442 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1443 1.35.8.2 nathanw esc->sc_main_dmamap->dm_xfer_len = 0;
1444 1.35.8.2 nathanw #endif
1445 1.35.8.2 nathanw esc->sc_loaded |= ESP_LOADED_MAIN;
1446 1.35.8.2 nathanw return(esc->sc_main_dmamap);
1447 1.35.8.2 nathanw }
1448 1.35.8.2 nathanw
1449 1.35.8.2 nathanw if ((!(esc->sc_loaded & ESP_LOADED_TAIL)) &&
1450 1.35.8.2 nathanw (esc->sc_tail_dmamap->dm_mapsize)) {
1451 1.35.8.2 nathanw DPRINTF(("%s: Loading tail map\n",sc->sc_dev.dv_xname));
1452 1.35.8.2 nathanw #if 0
1453 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap,
1454 1.35.8.2 nathanw 0, esc->sc_tail_dmamap->dm_mapsize,
1455 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
1456 1.35.8.2 nathanw esc->sc_tail_dmamap->dm_xfer_len = 0;
1457 1.35.8.2 nathanw #endif
1458 1.35.8.2 nathanw esc->sc_loaded |= ESP_LOADED_TAIL;
1459 1.35.8.2 nathanw return(esc->sc_tail_dmamap);
1460 1.35.8.2 nathanw }
1461 1.35.8.2 nathanw
1462 1.35.8.2 nathanw DPRINTF(("%s: not loading map\n",sc->sc_dev.dv_xname));
1463 1.35.8.2 nathanw return(0);
1464 1.35.8.2 nathanw }
1465 1.35.8.2 nathanw
1466 1.35.8.2 nathanw
1467 1.35.8.2 nathanw void
1468 1.35.8.2 nathanw esp_dmacb_completed(map, arg)
1469 1.35.8.2 nathanw bus_dmamap_t map;
1470 1.35.8.2 nathanw void *arg;
1471 1.35.8.2 nathanw {
1472 1.35.8.2 nathanw struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
1473 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1474 1.35.8.2 nathanw
1475 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'X';
1476 1.35.8.2 nathanw DPRINTF(("%s: dma completed\n",sc->sc_dev.dv_xname));
1477 1.35.8.2 nathanw
1478 1.35.8.2 nathanw #ifdef DIAGNOSTIC
1479 1.35.8.2 nathanw if ((esc->sc_datain < 0) || (esc->sc_datain > 1)) {
1480 1.35.8.2 nathanw panic("%s: invalid dma direction in completed callback, datain = %d",
1481 1.35.8.2 nathanw sc->sc_dev.dv_xname,esc->sc_datain);
1482 1.35.8.2 nathanw }
1483 1.35.8.2 nathanw #endif
1484 1.35.8.2 nathanw
1485 1.35.8.2 nathanw #if defined(DIAGNOSTIC) && 0
1486 1.35.8.2 nathanw {
1487 1.35.8.2 nathanw int i;
1488 1.35.8.2 nathanw for(i=0;i<map->dm_nsegs;i++) {
1489 1.35.8.2 nathanw if (map->dm_xfer_len != map->dm_mapsize) {
1490 1.35.8.2 nathanw printf("%s: map->dm_mapsize = %d\n", sc->sc_dev.dv_xname,map->dm_mapsize);
1491 1.35.8.2 nathanw printf("%s: map->dm_nsegs = %d\n", sc->sc_dev.dv_xname,map->dm_nsegs);
1492 1.35.8.2 nathanw printf("%s: map->dm_xfer_len = %d\n", sc->sc_dev.dv_xname,map->dm_xfer_len);
1493 1.35.8.2 nathanw for(i=0;i<map->dm_nsegs;i++) {
1494 1.35.8.2 nathanw printf("%s: map->dm_segs[%d].ds_addr = 0x%08lx\n",
1495 1.35.8.2 nathanw sc->sc_dev.dv_xname,i,map->dm_segs[i].ds_addr);
1496 1.35.8.2 nathanw printf("%s: map->dm_segs[%d].ds_len = %d\n",
1497 1.35.8.2 nathanw sc->sc_dev.dv_xname,i,map->dm_segs[i].ds_len);
1498 1.35.8.2 nathanw }
1499 1.35.8.2 nathanw panic("%s: incomplete dma transfer\n",sc->sc_dev.dv_xname);
1500 1.35.8.2 nathanw }
1501 1.35.8.2 nathanw }
1502 1.35.8.2 nathanw }
1503 1.35.8.2 nathanw #endif
1504 1.35.8.2 nathanw
1505 1.35.8.2 nathanw if (map == esc->sc_main_dmamap) {
1506 1.35.8.2 nathanw #ifdef DIAGNOSTIC
1507 1.35.8.2 nathanw if ((esc->sc_loaded & ESP_UNLOADED_MAIN) ||
1508 1.35.8.2 nathanw !(esc->sc_loaded & ESP_LOADED_MAIN)) {
1509 1.35.8.2 nathanw panic("%s: unexpected completed call for main map\n",sc->sc_dev.dv_xname);
1510 1.35.8.2 nathanw }
1511 1.35.8.2 nathanw #endif
1512 1.35.8.2 nathanw esc->sc_loaded |= ESP_UNLOADED_MAIN;
1513 1.35.8.2 nathanw } else if (map == esc->sc_tail_dmamap) {
1514 1.35.8.2 nathanw #ifdef DIAGNOSTIC
1515 1.35.8.2 nathanw if ((esc->sc_loaded & ESP_UNLOADED_TAIL) ||
1516 1.35.8.2 nathanw !(esc->sc_loaded & ESP_LOADED_TAIL)) {
1517 1.35.8.2 nathanw panic("%s: unexpected completed call for tail map\n",sc->sc_dev.dv_xname);
1518 1.35.8.2 nathanw }
1519 1.35.8.2 nathanw #endif
1520 1.35.8.2 nathanw esc->sc_loaded |= ESP_UNLOADED_TAIL;
1521 1.35.8.2 nathanw }
1522 1.35.8.2 nathanw #ifdef DIAGNOSTIC
1523 1.35.8.2 nathanw else {
1524 1.35.8.2 nathanw panic("%s: unexpected completed map", sc->sc_dev.dv_xname);
1525 1.35.8.2 nathanw }
1526 1.35.8.2 nathanw #endif
1527 1.35.8.2 nathanw
1528 1.35.8.2 nathanw #ifdef ESP_DEBUG
1529 1.35.8.2 nathanw if (esp_debug) {
1530 1.35.8.2 nathanw if (map == esc->sc_main_dmamap) {
1531 1.35.8.2 nathanw printf("%s: completed main map\n",sc->sc_dev.dv_xname);
1532 1.35.8.2 nathanw } else if (map == esc->sc_tail_dmamap) {
1533 1.35.8.2 nathanw printf("%s: completed tail map\n",sc->sc_dev.dv_xname);
1534 1.35.8.2 nathanw }
1535 1.35.8.2 nathanw }
1536 1.35.8.2 nathanw #endif
1537 1.35.8.2 nathanw
1538 1.35.8.2 nathanw #if 0
1539 1.35.8.2 nathanw if ((map == esc->sc_tail_dmamap) ||
1540 1.35.8.2 nathanw ((esc->sc_tail_size == 0) && (map == esc->sc_main_dmamap))) {
1541 1.35.8.2 nathanw
1542 1.35.8.2 nathanw /* Clear the DMAMOD bit in the DCTL register to give control
1543 1.35.8.2 nathanw * back to the scsi chip.
1544 1.35.8.2 nathanw */
1545 1.35.8.2 nathanw if (esc->sc_datain) {
1546 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1547 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMARD);
1548 1.35.8.2 nathanw } else {
1549 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1550 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB);
1551 1.35.8.2 nathanw }
1552 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
1553 1.35.8.2 nathanw }
1554 1.35.8.2 nathanw #endif
1555 1.35.8.2 nathanw
1556 1.35.8.2 nathanw
1557 1.35.8.2 nathanw #if 0
1558 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, map,
1559 1.35.8.2 nathanw 0, map->dm_mapsize,
1560 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
1561 1.35.8.2 nathanw #endif
1562 1.35.8.2 nathanw
1563 1.35.8.2 nathanw }
1564 1.35.8.2 nathanw
1565 1.35.8.2 nathanw void
1566 1.35.8.2 nathanw esp_dmacb_shutdown(arg)
1567 1.35.8.2 nathanw void *arg;
1568 1.35.8.2 nathanw {
1569 1.35.8.2 nathanw struct ncr53c9x_softc *sc = (struct ncr53c9x_softc *)arg;
1570 1.35.8.2 nathanw struct esp_softc *esc = (struct esp_softc *)sc;
1571 1.35.8.2 nathanw
1572 1.35.8.3 nathanw if (ESPLOGIF) *esplogp++ = 'S';
1573 1.35.8.2 nathanw DPRINTF(("%s: dma shutdown\n",sc->sc_dev.dv_xname));
1574 1.35.8.2 nathanw
1575 1.35.8.3 nathanw if (esc->sc_loaded == 0)
1576 1.35.8.3 nathanw return;
1577 1.35.8.3 nathanw
1578 1.35.8.2 nathanw #if 0
1579 1.35.8.2 nathanw {
1580 1.35.8.2 nathanw /* Clear the DMAMOD bit in the DCTL register to give control
1581 1.35.8.2 nathanw * back to the scsi chip.
1582 1.35.8.2 nathanw */
1583 1.35.8.2 nathanw if (esc->sc_datain) {
1584 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1585 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB | ESPDCTL_DMARD);
1586 1.35.8.2 nathanw } else {
1587 1.35.8.2 nathanw NCR_WRITE_REG(sc, ESP_DCTL,
1588 1.35.8.3 nathanw ESPDCTL_16MHZ | ESPDCTL_INTENB);
1589 1.35.8.2 nathanw }
1590 1.35.8.2 nathanw DPRINTF(("esp dctl is 0x%02x\n",NCR_READ_REG(sc,ESP_DCTL)));
1591 1.35.8.2 nathanw }
1592 1.35.8.2 nathanw #endif
1593 1.35.8.2 nathanw
1594 1.35.8.2 nathanw DPRINTF(("%s: esp_dma_nest == %d\n",sc->sc_dev.dv_xname,esp_dma_nest));
1595 1.35.8.2 nathanw
1596 1.35.8.2 nathanw /* Stuff the end slop into fifo */
1597 1.35.8.2 nathanw
1598 1.35.8.2 nathanw #ifdef ESP_DEBUG
1599 1.35.8.2 nathanw if (esp_debug) {
1600 1.35.8.2 nathanw
1601 1.35.8.2 nathanw int n = NCR_READ_REG(sc, NCR_FFLAG);
1602 1.35.8.2 nathanw DPRINTF(("%s: fifo size = %d, seq = 0x%x\n",
1603 1.35.8.2 nathanw sc->sc_dev.dv_xname,n & NCRFIFO_FF, (n & NCRFIFO_SS)>>5));
1604 1.35.8.2 nathanw }
1605 1.35.8.2 nathanw #endif
1606 1.35.8.2 nathanw
1607 1.35.8.2 nathanw if (esc->sc_main_dmamap->dm_mapsize) {
1608 1.35.8.3 nathanw if (!esc->sc_datain) { /* unpatch the dma map for write overrun */
1609 1.35.8.3 nathanw esc->sc_main_dmamap->dm_mapsize -= ESP_DMA_OVERRUN;
1610 1.35.8.3 nathanw esc->sc_main_dmamap->dm_segs[esc->sc_main_dmamap->dm_nsegs - 1].ds_len -=
1611 1.35.8.3 nathanw ESP_DMA_OVERRUN;
1612 1.35.8.3 nathanw }
1613 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap,
1614 1.35.8.2 nathanw 0, esc->sc_main_dmamap->dm_mapsize,
1615 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
1616 1.35.8.2 nathanw bus_dmamap_unload(esc->sc_scsi_dma.nd_dmat, esc->sc_main_dmamap);
1617 1.35.8.3 nathanw if (ESPLOGIF) {
1618 1.35.8.3 nathanw sprintf (esplogp, "m%ld", esc->sc_main_dmamap->dm_xfer_len);
1619 1.35.8.3 nathanw esplogp += strlen (esplogp);
1620 1.35.8.3 nathanw }
1621 1.35.8.2 nathanw }
1622 1.35.8.2 nathanw
1623 1.35.8.2 nathanw if (esc->sc_tail_dmamap->dm_mapsize) {
1624 1.35.8.2 nathanw bus_dmamap_sync(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap,
1625 1.35.8.2 nathanw 0, esc->sc_tail_dmamap->dm_mapsize,
1626 1.35.8.2 nathanw (esc->sc_datain ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
1627 1.35.8.2 nathanw bus_dmamap_unload(esc->sc_scsi_dma.nd_dmat, esc->sc_tail_dmamap);
1628 1.35.8.3 nathanw /* copy the tail dma buffer data for read transfers */
1629 1.35.8.3 nathanw if (esc->sc_datain) {
1630 1.35.8.3 nathanw memcpy(*esc->sc_dmaaddr+esc->sc_begin_size+esc->sc_main_size,
1631 1.35.8.3 nathanw esc->sc_tail, esc->sc_dmasize-(esc->sc_begin_size+esc->sc_main_size));
1632 1.35.8.3 nathanw }
1633 1.35.8.3 nathanw if (ESPLOGIF) {
1634 1.35.8.3 nathanw sprintf (esplogp, "t%ld", esc->sc_tail_dmamap->dm_xfer_len);
1635 1.35.8.3 nathanw esplogp += strlen (esplogp);
1636 1.35.8.3 nathanw }
1637 1.35.8.2 nathanw }
1638 1.35.8.2 nathanw
1639 1.35.8.2 nathanw #ifdef ESP_DEBUG
1640 1.35.8.2 nathanw if (esp_debug) {
1641 1.35.8.2 nathanw printf("%s: dma_shutdown: addr=%p,len=0x%08x,size=0x%08x\n",
1642 1.35.8.2 nathanw sc->sc_dev.dv_xname,
1643 1.35.8.2 nathanw *esc->sc_dmaaddr, *esc->sc_dmalen, esc->sc_dmasize);
1644 1.35.8.2 nathanw if (esp_debug > 10) {
1645 1.35.8.2 nathanw esp_hex_dump(*(esc->sc_dmaaddr),esc->sc_dmasize);
1646 1.35.8.2 nathanw printf("%s: tail=%p,tailbuf=%p,tail_size=0x%08x\n",
1647 1.35.8.2 nathanw sc->sc_dev.dv_xname,
1648 1.35.8.2 nathanw esc->sc_tail, &(esc->sc_tailbuf[0]), esc->sc_tail_size);
1649 1.35.8.2 nathanw esp_hex_dump(&(esc->sc_tailbuf[0]),sizeof(esc->sc_tailbuf));
1650 1.35.8.2 nathanw }
1651 1.35.8.2 nathanw }
1652 1.35.8.2 nathanw #endif
1653 1.35.8.2 nathanw
1654 1.35.8.2 nathanw esc->sc_main = 0;
1655 1.35.8.2 nathanw esc->sc_main_size = 0;
1656 1.35.8.2 nathanw esc->sc_tail = 0;
1657 1.35.8.2 nathanw esc->sc_tail_size = 0;
1658 1.35.8.2 nathanw
1659 1.35.8.2 nathanw esc->sc_datain = -1;
1660 1.35.8.3 nathanw /* esc->sc_dmaaddr = 0; */
1661 1.35.8.3 nathanw /* esc->sc_dmalen = 0; */
1662 1.35.8.3 nathanw /* esc->sc_dmasize = 0; */
1663 1.35.8.2 nathanw
1664 1.35.8.2 nathanw esc->sc_loaded = 0;
1665 1.35.8.2 nathanw
1666 1.35.8.2 nathanw esc->sc_begin = 0;
1667 1.35.8.2 nathanw esc->sc_begin_size = 0;
1668 1.35.8.2 nathanw
1669 1.35.8.2 nathanw #ifdef ESP_DEBUG
1670 1.35.8.2 nathanw if (esp_debug) {
1671 1.35.8.2 nathanw char sbuf[256];
1672 1.35.8.2 nathanw
1673 1.35.8.2 nathanw bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRSTAT)),
1674 1.35.8.2 nathanw NEXT_INTR_BITS, sbuf, sizeof(sbuf));
1675 1.35.8.2 nathanw printf(" *intrstat = 0x%s\n", sbuf);
1676 1.35.8.2 nathanw
1677 1.35.8.2 nathanw bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRMASK)),
1678 1.35.8.2 nathanw NEXT_INTR_BITS, sbuf, sizeof(sbuf));
1679 1.35.8.2 nathanw printf(" *intrmask = 0x%s\n", sbuf);
1680 1.35.8.2 nathanw }
1681 1.35.8.2 nathanw #endif
1682 1.35.8.2 nathanw }
1683