nextdma.c revision 1.35 1 1.35 lukem /* $NetBSD: nextdma.c,v 1.35 2003/07/15 02:59:32 lukem Exp $ */
2 1.1 dbj /*
3 1.1 dbj * Copyright (c) 1998 Darrin B. Jewell
4 1.1 dbj * All rights reserved.
5 1.1 dbj *
6 1.1 dbj * Redistribution and use in source and binary forms, with or without
7 1.1 dbj * modification, are permitted provided that the following conditions
8 1.1 dbj * are met:
9 1.1 dbj * 1. Redistributions of source code must retain the above copyright
10 1.1 dbj * notice, this list of conditions and the following disclaimer.
11 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 dbj * notice, this list of conditions and the following disclaimer in the
13 1.1 dbj * documentation and/or other materials provided with the distribution.
14 1.1 dbj * 3. All advertising materials mentioning features or use of this software
15 1.1 dbj * must display the following acknowledgement:
16 1.1 dbj * This product includes software developed by Darrin B. Jewell
17 1.1 dbj * 4. The name of the author may not be used to endorse or promote products
18 1.1 dbj * derived from this software without specific prior written permission
19 1.1 dbj *
20 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 dbj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 dbj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 dbj * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 dbj * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 dbj * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 dbj * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 dbj * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 dbj * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 dbj * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 dbj */
31 1.35 lukem
32 1.35 lukem #include <sys/cdefs.h>
33 1.35 lukem __KERNEL_RCSID(0, "$NetBSD: nextdma.c,v 1.35 2003/07/15 02:59:32 lukem Exp $");
34 1.1 dbj
35 1.1 dbj #include <sys/param.h>
36 1.1 dbj #include <sys/systm.h>
37 1.1 dbj #include <sys/mbuf.h>
38 1.1 dbj #include <sys/syslog.h>
39 1.1 dbj #include <sys/socket.h>
40 1.1 dbj #include <sys/device.h>
41 1.1 dbj #include <sys/malloc.h>
42 1.1 dbj #include <sys/ioctl.h>
43 1.1 dbj #include <sys/errno.h>
44 1.1 dbj
45 1.31 mycroft #define _M68K_BUS_DMA_PRIVATE
46 1.1 dbj #include <machine/autoconf.h>
47 1.1 dbj #include <machine/cpu.h>
48 1.1 dbj #include <machine/intr.h>
49 1.5 dbj
50 1.5 dbj #include <m68k/cacheops.h>
51 1.1 dbj
52 1.1 dbj #include <next68k/next68k/isr.h>
53 1.31 mycroft #include <next68k/next68k/nextrom.h>
54 1.1 dbj
55 1.31 mycroft #include <next68k/dev/intiovar.h>
56 1.1 dbj
57 1.1 dbj #include "nextdmareg.h"
58 1.1 dbj #include "nextdmavar.h"
59 1.1 dbj
60 1.31 mycroft #include "esp.h"
61 1.31 mycroft #include "xe.h"
62 1.31 mycroft
63 1.31 mycroft #if DEBUG
64 1.1 dbj #define ND_DEBUG
65 1.1 dbj #endif
66 1.1 dbj
67 1.31 mycroft extern int turbo;
68 1.31 mycroft
69 1.31 mycroft #define panic __asm __volatile("trap #15"); printf
70 1.30 christos
71 1.31 mycroft #define NEXTDMA_DEBUG nextdma_debug
72 1.31 mycroft /* (nsc->sc_chan->nd_intr == NEXT_I_SCSI_DMA) && nextdma_debug */
73 1.1 dbj #if defined(ND_DEBUG)
74 1.8 dbj int nextdma_debug = 0;
75 1.30 christos #define DPRINTF(x) if (NEXTDMA_DEBUG) printf x;
76 1.31 mycroft int ndtraceshow = 0;
77 1.31 mycroft char ndtrace[8192+100];
78 1.31 mycroft char *ndtracep = ndtrace;
79 1.31 mycroft #define NDTRACEIF(x) if (10 && /* (nsc->sc_chan->nd_intr == NEXT_I_SCSI_DMA) && */ ndtracep < (ndtrace + 8192)) do {x;} while (0)
80 1.1 dbj #else
81 1.1 dbj #define DPRINTF(x)
82 1.31 mycroft #define NDTRACEIF(x)
83 1.1 dbj #endif
84 1.31 mycroft #define PRINTF(x) printf x
85 1.1 dbj
86 1.26 dbj #if defined(ND_DEBUG)
87 1.26 dbj int nextdma_debug_enetr_idx = 0;
88 1.26 dbj unsigned int nextdma_debug_enetr_state[100] = { 0 };
89 1.26 dbj int nextdma_debug_scsi_idx = 0;
90 1.26 dbj unsigned int nextdma_debug_scsi_state[100] = { 0 };
91 1.26 dbj
92 1.31 mycroft void nextdma_debug_initstate(struct nextdma_softc *);
93 1.31 mycroft void nextdma_debug_savestate(struct nextdma_softc *, unsigned int);
94 1.26 dbj void nextdma_debug_scsi_dumpstate(void);
95 1.26 dbj void nextdma_debug_enetr_dumpstate(void);
96 1.31 mycroft #endif
97 1.31 mycroft
98 1.31 mycroft
99 1.31 mycroft int nextdma_match __P((struct device *, struct cfdata *, void *));
100 1.31 mycroft void nextdma_attach __P((struct device *, struct device *, void *));
101 1.31 mycroft
102 1.31 mycroft void nextdmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
103 1.31 mycroft bus_size_t, int));
104 1.31 mycroft int nextdma_continue __P((struct nextdma_softc *));
105 1.31 mycroft void nextdma_rotate __P((struct nextdma_softc *));
106 1.31 mycroft
107 1.31 mycroft void nextdma_setup_cont_regs __P((struct nextdma_softc *));
108 1.31 mycroft void nextdma_setup_curr_regs __P((struct nextdma_softc *));
109 1.31 mycroft
110 1.31 mycroft #if NESP > 0
111 1.31 mycroft static int nextdma_esp_intr __P((void *));
112 1.31 mycroft #endif
113 1.31 mycroft #if NXE > 0
114 1.31 mycroft static int nextdma_enet_intr __P((void *));
115 1.31 mycroft #endif
116 1.31 mycroft
117 1.31 mycroft #define nd_bsr4(reg) bus_space_read_4(nsc->sc_bst, nsc->sc_bsh, (reg))
118 1.31 mycroft #define nd_bsw4(reg,val) bus_space_write_4(nsc->sc_bst, nsc->sc_bsh, (reg), (val))
119 1.26 dbj
120 1.34 thorpej CFATTACH_DECL(nextdma, sizeof(struct nextdma_softc),
121 1.34 thorpej nextdma_match, nextdma_attach, NULL, NULL);
122 1.31 mycroft
123 1.31 mycroft static struct nextdma_channel nextdma_channel[] = {
124 1.31 mycroft #if NESP > 0
125 1.31 mycroft { "scsi", NEXT_P_SCSI_CSR, DD_SIZE, NEXT_I_SCSI_DMA, &nextdma_esp_intr },
126 1.31 mycroft #endif
127 1.31 mycroft #if NXE > 0
128 1.31 mycroft { "enetx", NEXT_P_ENETX_CSR, DD_SIZE, NEXT_I_ENETX_DMA, &nextdma_enet_intr },
129 1.31 mycroft { "enetr", NEXT_P_ENETR_CSR, DD_SIZE, NEXT_I_ENETR_DMA, &nextdma_enet_intr },
130 1.31 mycroft #endif
131 1.31 mycroft };
132 1.31 mycroft static int nnextdma_channels = (sizeof(nextdma_channel)/sizeof(nextdma_channel[0]));
133 1.31 mycroft
134 1.31 mycroft static int attached = 0;
135 1.26 dbj
136 1.31 mycroft struct nextdma_softc *
137 1.31 mycroft nextdma_findchannel(name)
138 1.31 mycroft char *name;
139 1.26 dbj {
140 1.31 mycroft struct device *dev = alldevs.tqh_first;
141 1.26 dbj
142 1.31 mycroft while (dev != NULL) {
143 1.31 mycroft if (!strncmp(dev->dv_xname, "nextdma", 7)) {
144 1.31 mycroft struct nextdma_softc *nsc = (struct nextdma_softc *)dev;
145 1.31 mycroft if (!strcmp (nsc->sc_chan->nd_name, name))
146 1.31 mycroft return (nsc);
147 1.26 dbj }
148 1.31 mycroft dev = dev->dv_list.tqe_next;
149 1.31 mycroft }
150 1.31 mycroft return (NULL);
151 1.26 dbj }
152 1.26 dbj
153 1.31 mycroft int
154 1.31 mycroft nextdma_match(parent, match, aux)
155 1.31 mycroft struct device *parent;
156 1.31 mycroft struct cfdata *match;
157 1.31 mycroft void *aux;
158 1.26 dbj {
159 1.31 mycroft struct intio_attach_args *ia = (struct intio_attach_args *)aux;
160 1.26 dbj
161 1.31 mycroft if (attached >= nnextdma_channels)
162 1.31 mycroft return (0);
163 1.26 dbj
164 1.31 mycroft ia->ia_addr = (void *)nextdma_channel[attached].nd_base;
165 1.1 dbj
166 1.31 mycroft return (1);
167 1.31 mycroft }
168 1.1 dbj
169 1.1 dbj void
170 1.31 mycroft nextdma_attach(parent, self, aux)
171 1.31 mycroft struct device *parent, *self;
172 1.31 mycroft void *aux;
173 1.1 dbj {
174 1.31 mycroft struct nextdma_softc *nsc = (struct nextdma_softc *)self;
175 1.31 mycroft struct intio_attach_args *ia = (struct intio_attach_args *)aux;
176 1.31 mycroft
177 1.31 mycroft if (attached >= nnextdma_channels)
178 1.31 mycroft return;
179 1.31 mycroft
180 1.31 mycroft nsc->sc_chan = &nextdma_channel[attached];
181 1.1 dbj
182 1.31 mycroft nsc->sc_dmat = ia->ia_dmat;
183 1.31 mycroft nsc->sc_bst = ia->ia_bst;
184 1.1 dbj
185 1.31 mycroft if (bus_space_map(nsc->sc_bst, nsc->sc_chan->nd_base,
186 1.31 mycroft nsc->sc_chan->nd_size, 0, &nsc->sc_bsh)) {
187 1.32 provos panic("%s: can't map DMA registers for channel %s",
188 1.31 mycroft nsc->sc_dev.dv_xname, nsc->sc_chan->nd_name);
189 1.1 dbj }
190 1.1 dbj
191 1.31 mycroft nextdma_init (nsc);
192 1.30 christos
193 1.31 mycroft isrlink_autovec(nsc->sc_chan->nd_intrfunc, nsc,
194 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), 10, NULL);
195 1.31 mycroft INTR_ENABLE(nsc->sc_chan->nd_intr);
196 1.1 dbj
197 1.31 mycroft printf (": channel %d (%s)\n", attached,
198 1.31 mycroft nsc->sc_chan->nd_name);
199 1.31 mycroft attached++;
200 1.31 mycroft
201 1.31 mycroft return;
202 1.1 dbj }
203 1.1 dbj
204 1.1 dbj void
205 1.31 mycroft nextdma_init(nsc)
206 1.31 mycroft struct nextdma_softc *nsc;
207 1.1 dbj {
208 1.22 tv #ifdef ND_DEBUG
209 1.30 christos if (NEXTDMA_DEBUG) {
210 1.22 tv char sbuf[256];
211 1.22 tv
212 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
213 1.22 tv sbuf, sizeof(sbuf));
214 1.22 tv printf("DMA init ipl (%ld) intr(0x%s)\n",
215 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), sbuf);
216 1.22 tv }
217 1.22 tv #endif
218 1.1 dbj
219 1.31 mycroft nsc->sc_stat.nd_map = NULL;
220 1.31 mycroft nsc->sc_stat.nd_idx = 0;
221 1.31 mycroft nsc->sc_stat.nd_map_cont = NULL;
222 1.31 mycroft nsc->sc_stat.nd_idx_cont = 0;
223 1.31 mycroft nsc->sc_stat.nd_exception = 0;
224 1.1 dbj
225 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_RESET | DMACSR_CLRCOMPLETE);
226 1.31 mycroft nd_bsw4 (DD_CSR, 0);
227 1.1 dbj
228 1.31 mycroft #if 01
229 1.31 mycroft nextdma_setup_curr_regs(nsc);
230 1.31 mycroft nextdma_setup_cont_regs(nsc);
231 1.31 mycroft #endif
232 1.1 dbj
233 1.20 dbj #if defined(DIAGNOSTIC)
234 1.1 dbj {
235 1.1 dbj u_long state;
236 1.31 mycroft state = nd_bsr4 (DD_CSR);
237 1.20 dbj
238 1.20 dbj #if 1
239 1.31 mycroft /* mourning (a 25Mhz 68040 mono slab) appears to set BUSEXC
240 1.31 mycroft * milo (a 25Mhz 68040 mono cube) didn't have this problem
241 1.31 mycroft * Darrin B. Jewell <jewell (at) mit.edu> Mon May 25 07:53:05 1998
242 1.31 mycroft */
243 1.31 mycroft state &= (DMACSR_COMPLETE | DMACSR_SUPDATE | DMACSR_ENABLE);
244 1.20 dbj #else
245 1.31 mycroft state &= (DMACSR_BUSEXC | DMACSR_COMPLETE |
246 1.31 mycroft DMACSR_SUPDATE | DMACSR_ENABLE);
247 1.20 dbj #endif
248 1.1 dbj if (state) {
249 1.31 mycroft nextdma_print(nsc);
250 1.20 dbj panic("DMA did not reset");
251 1.1 dbj }
252 1.1 dbj }
253 1.1 dbj #endif
254 1.1 dbj }
255 1.1 dbj
256 1.1 dbj void
257 1.31 mycroft nextdma_reset(nsc)
258 1.31 mycroft struct nextdma_softc *nsc;
259 1.1 dbj {
260 1.1 dbj int s;
261 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
262 1.31 mycroft
263 1.18 dbj s = spldma();
264 1.8 dbj
265 1.8 dbj DPRINTF(("DMA reset\n"));
266 1.8 dbj
267 1.8 dbj #if (defined(ND_DEBUG))
268 1.31 mycroft if (NEXTDMA_DEBUG > 1) nextdma_print(nsc);
269 1.8 dbj #endif
270 1.8 dbj
271 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
272 1.31 mycroft if ((stat->nd_map) || (stat->nd_map_cont)) {
273 1.31 mycroft if (stat->nd_map_cont) {
274 1.30 christos DPRINTF(("DMA: resetting with non null continue map\n"));
275 1.31 mycroft if (nsc->sc_conf.nd_completed_cb)
276 1.31 mycroft (*nsc->sc_conf.nd_completed_cb)
277 1.31 mycroft (stat->nd_map_cont, nsc->sc_conf.nd_cb_arg);
278 1.30 christos
279 1.31 mycroft stat->nd_map_cont = 0;
280 1.31 mycroft stat->nd_idx_cont = 0;
281 1.30 christos }
282 1.31 mycroft if (nsc->sc_conf.nd_shutdown_cb)
283 1.31 mycroft (*nsc->sc_conf.nd_shutdown_cb)(nsc->sc_conf.nd_cb_arg);
284 1.31 mycroft stat->nd_map = 0;
285 1.31 mycroft stat->nd_idx = 0;
286 1.26 dbj }
287 1.20 dbj
288 1.1 dbj splx(s);
289 1.1 dbj }
290 1.1 dbj
291 1.1 dbj /****************************************************************/
292 1.1 dbj
293 1.1 dbj
294 1.1 dbj /* Call the completed and continue callbacks to try to fill
295 1.1 dbj * in the dma continue buffers.
296 1.1 dbj */
297 1.1 dbj void
298 1.31 mycroft nextdma_rotate(nsc)
299 1.31 mycroft struct nextdma_softc *nsc;
300 1.1 dbj {
301 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
302 1.1 dbj
303 1.31 mycroft NDTRACEIF (*ndtracep++ = 'r');
304 1.31 mycroft DPRINTF(("DMA nextdma_rotate()\n"));
305 1.1 dbj
306 1.1 dbj /* Rotate the continue map into the current map */
307 1.31 mycroft stat->nd_map = stat->nd_map_cont;
308 1.31 mycroft stat->nd_idx = stat->nd_idx_cont;
309 1.1 dbj
310 1.31 mycroft if ((!stat->nd_map_cont) ||
311 1.31 mycroft ((++stat->nd_idx_cont >= stat->nd_map_cont->dm_nsegs))) {
312 1.31 mycroft if (nsc->sc_conf.nd_continue_cb) {
313 1.31 mycroft stat->nd_map_cont = (*nsc->sc_conf.nd_continue_cb)
314 1.31 mycroft (nsc->sc_conf.nd_cb_arg);
315 1.31 mycroft if (stat->nd_map_cont) {
316 1.31 mycroft stat->nd_map_cont->dm_xfer_len = 0;
317 1.26 dbj }
318 1.1 dbj } else {
319 1.31 mycroft stat->nd_map_cont = 0;
320 1.1 dbj }
321 1.31 mycroft stat->nd_idx_cont = 0;
322 1.1 dbj }
323 1.7 dbj
324 1.29 dbj #if defined(DIAGNOSTIC) && 0
325 1.31 mycroft if (stat->nd_map_cont) {
326 1.31 mycroft if (!DMA_BEGINALIGNED(stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_addr)) {
327 1.31 mycroft nextdma_print(nsc);
328 1.32 provos panic("DMA request unaligned at start");
329 1.7 dbj }
330 1.31 mycroft if (!DMA_ENDALIGNED(stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_addr +
331 1.31 mycroft stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len)) {
332 1.31 mycroft nextdma_print(nsc);
333 1.32 provos panic("DMA request unaligned at end");
334 1.7 dbj }
335 1.7 dbj }
336 1.7 dbj #endif
337 1.7 dbj
338 1.1 dbj }
339 1.1 dbj
340 1.1 dbj void
341 1.31 mycroft nextdma_setup_curr_regs(nsc)
342 1.31 mycroft struct nextdma_softc *nsc;
343 1.1 dbj {
344 1.20 dbj bus_addr_t dd_next;
345 1.20 dbj bus_addr_t dd_limit;
346 1.20 dbj bus_addr_t dd_saved_next;
347 1.20 dbj bus_addr_t dd_saved_limit;
348 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
349 1.20 dbj
350 1.31 mycroft NDTRACEIF (*ndtracep++ = 'C');
351 1.31 mycroft DPRINTF(("DMA nextdma_setup_curr_regs()\n"));
352 1.1 dbj
353 1.31 mycroft if (stat->nd_map) {
354 1.31 mycroft dd_next = stat->nd_map->dm_segs[stat->nd_idx].ds_addr;
355 1.31 mycroft dd_limit = (stat->nd_map->dm_segs[stat->nd_idx].ds_addr +
356 1.31 mycroft stat->nd_map->dm_segs[stat->nd_idx].ds_len);
357 1.15 dbj
358 1.31 mycroft if (!turbo && nsc->sc_chan->nd_intr == NEXT_I_ENETX_DMA) {
359 1.20 dbj dd_limit |= 0x80000000; /* Ethernet transmit needs secret magic */
360 1.29 dbj dd_limit += 15;
361 1.20 dbj }
362 1.20 dbj } else {
363 1.31 mycroft dd_next = turbo ? 0 : 0xdeadbeef;
364 1.31 mycroft dd_limit = turbo ? 0 : 0xdeadbeef;
365 1.20 dbj }
366 1.1 dbj
367 1.20 dbj dd_saved_next = dd_next;
368 1.20 dbj dd_saved_limit = dd_limit;
369 1.1 dbj
370 1.31 mycroft NDTRACEIF (if (stat->nd_map) {
371 1.31 mycroft sprintf (ndtracep, "%ld", stat->nd_map->dm_segs[stat->nd_idx].ds_len);
372 1.31 mycroft ndtracep += strlen (ndtracep);
373 1.31 mycroft });
374 1.30 christos
375 1.31 mycroft if (!turbo && (nsc->sc_chan->nd_intr == NEXT_I_ENETX_DMA)) {
376 1.31 mycroft nd_bsw4 (DD_NEXT_INITBUF, dd_next);
377 1.15 dbj } else {
378 1.31 mycroft nd_bsw4 (DD_NEXT, dd_next);
379 1.15 dbj }
380 1.31 mycroft nd_bsw4 (DD_LIMIT, dd_limit);
381 1.31 mycroft if (!turbo) nd_bsw4 (DD_SAVED_NEXT, dd_saved_next);
382 1.31 mycroft if (!turbo) nd_bsw4 (DD_SAVED_LIMIT, dd_saved_limit);
383 1.1 dbj
384 1.20 dbj #ifdef DIAGNOSTIC
385 1.31 mycroft if ((nd_bsr4 (DD_NEXT_INITBUF) != dd_next)
386 1.31 mycroft || (nd_bsr4 (DD_NEXT) != dd_next)
387 1.31 mycroft || (nd_bsr4 (DD_LIMIT) != dd_limit)
388 1.31 mycroft || (!turbo && (nd_bsr4 (DD_SAVED_NEXT) != dd_saved_next))
389 1.31 mycroft || (!turbo && (nd_bsr4 (DD_SAVED_LIMIT) != dd_saved_limit))
390 1.31 mycroft ) {
391 1.31 mycroft nextdma_print(nsc);
392 1.20 dbj panic("DMA failure writing to current regs");
393 1.20 dbj }
394 1.7 dbj #endif
395 1.1 dbj }
396 1.1 dbj
397 1.1 dbj void
398 1.31 mycroft nextdma_setup_cont_regs(nsc)
399 1.31 mycroft struct nextdma_softc *nsc;
400 1.1 dbj {
401 1.31 mycroft bus_addr_t dd_start;
402 1.31 mycroft bus_addr_t dd_stop;
403 1.31 mycroft bus_addr_t dd_saved_start;
404 1.31 mycroft bus_addr_t dd_saved_stop;
405 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
406 1.1 dbj
407 1.31 mycroft NDTRACEIF (*ndtracep++ = 'c');
408 1.31 mycroft DPRINTF(("DMA nextdma_setup_regs()\n"));
409 1.1 dbj
410 1.31 mycroft if (stat->nd_map_cont) {
411 1.31 mycroft dd_start = stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_addr;
412 1.31 mycroft dd_stop = (stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_addr +
413 1.31 mycroft stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len);
414 1.22 tv
415 1.31 mycroft if (!turbo && nsc->sc_chan->nd_intr == NEXT_I_ENETX_DMA) {
416 1.31 mycroft dd_stop |= 0x80000000; /* Ethernet transmit needs secret magic */
417 1.31 mycroft dd_stop += 15;
418 1.24 dbj }
419 1.1 dbj } else {
420 1.31 mycroft dd_start = turbo ? nd_bsr4 (DD_NEXT) : 0xdeadbee0;
421 1.31 mycroft dd_stop = turbo ? 0 : 0xdeadbee0;
422 1.1 dbj }
423 1.1 dbj
424 1.31 mycroft dd_saved_start = dd_start;
425 1.31 mycroft dd_saved_stop = dd_stop;
426 1.22 tv
427 1.31 mycroft NDTRACEIF (if (stat->nd_map_cont) {
428 1.31 mycroft sprintf (ndtracep, "%ld", stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len);
429 1.31 mycroft ndtracep += strlen (ndtracep);
430 1.31 mycroft });
431 1.31 mycroft
432 1.31 mycroft nd_bsw4 (DD_START, dd_start);
433 1.31 mycroft nd_bsw4 (DD_STOP, dd_stop);
434 1.31 mycroft if (!turbo) nd_bsw4 (DD_SAVED_START, dd_saved_start);
435 1.31 mycroft if (!turbo) nd_bsw4 (DD_SAVED_STOP, dd_saved_stop);
436 1.31 mycroft if (turbo && nsc->sc_chan->nd_intr == NEXT_I_ENETR_DMA)
437 1.31 mycroft nd_bsw4 (DD_STOP - 0x40, dd_start);
438 1.31 mycroft
439 1.31 mycroft #ifdef DIAGNOSTIC
440 1.31 mycroft if ((nd_bsr4 (DD_START) != dd_start)
441 1.31 mycroft || (dd_stop && (nd_bsr4 (DD_STOP) != dd_stop))
442 1.31 mycroft || (!turbo && (nd_bsr4 (DD_SAVED_START) != dd_saved_start))
443 1.31 mycroft || (!turbo && (nd_bsr4 (DD_SAVED_STOP) != dd_saved_stop))
444 1.31 mycroft ) {
445 1.31 mycroft nextdma_print(nsc);
446 1.31 mycroft panic("DMA failure writing to continue regs");
447 1.31 mycroft }
448 1.31 mycroft #endif
449 1.1 dbj }
450 1.1 dbj
451 1.1 dbj /****************************************************************/
452 1.1 dbj
453 1.31 mycroft #if NESP > 0
454 1.31 mycroft static int
455 1.31 mycroft nextdma_esp_intr(arg)
456 1.31 mycroft void *arg;
457 1.1 dbj {
458 1.31 mycroft /* @@@ This is bogus, we can't be certain of arg's type
459 1.18 dbj * unless the interrupt is for us. For now we successfully
460 1.18 dbj * cheat because DMA interrupts are the only things invoked
461 1.18 dbj * at this interrupt level.
462 1.1 dbj */
463 1.31 mycroft struct nextdma_softc *nsc = arg;
464 1.31 mycroft int esp_dma_int __P((void *)); /* XXX */
465 1.31 mycroft
466 1.31 mycroft if (!INTR_OCCURRED(nsc->sc_chan->nd_intr))
467 1.31 mycroft return 0;
468 1.31 mycroft /* Handle dma interrupts */
469 1.1 dbj
470 1.31 mycroft return esp_dma_int (nsc->sc_conf.nd_cb_arg);
471 1.1 dbj
472 1.31 mycroft }
473 1.30 christos #endif
474 1.30 christos
475 1.31 mycroft #if NXE > 0
476 1.31 mycroft static int
477 1.31 mycroft nextdma_enet_intr(arg)
478 1.31 mycroft void *arg;
479 1.31 mycroft {
480 1.31 mycroft /* @@@ This is bogus, we can't be certain of arg's type
481 1.31 mycroft * unless the interrupt is for us. For now we successfully
482 1.31 mycroft * cheat because DMA interrupts are the only things invoked
483 1.31 mycroft * at this interrupt level.
484 1.31 mycroft */
485 1.31 mycroft struct nextdma_softc *nsc = arg;
486 1.31 mycroft unsigned int state;
487 1.31 mycroft bus_addr_t onext;
488 1.31 mycroft bus_addr_t olimit;
489 1.31 mycroft bus_addr_t slimit;
490 1.31 mycroft int result;
491 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
492 1.31 mycroft
493 1.31 mycroft if (!INTR_OCCURRED(nsc->sc_chan->nd_intr))
494 1.31 mycroft return 0;
495 1.31 mycroft /* Handle dma interrupts */
496 1.31 mycroft
497 1.31 mycroft NDTRACEIF (*ndtracep++ = 'D');
498 1.22 tv #ifdef ND_DEBUG
499 1.30 christos if (NEXTDMA_DEBUG) {
500 1.22 tv char sbuf[256];
501 1.22 tv
502 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
503 1.22 tv sbuf, sizeof(sbuf));
504 1.22 tv printf("DMA interrupt ipl (%ld) intr(0x%s)\n",
505 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), sbuf);
506 1.22 tv }
507 1.22 tv #endif
508 1.1 dbj
509 1.7 dbj #ifdef DIAGNOSTIC
510 1.31 mycroft if (!stat->nd_map) {
511 1.31 mycroft nextdma_print(nsc);
512 1.32 provos panic("DMA missing current map in interrupt!");
513 1.7 dbj }
514 1.7 dbj #endif
515 1.7 dbj
516 1.31 mycroft state = nd_bsr4 (DD_CSR);
517 1.26 dbj
518 1.26 dbj #if defined(ND_DEBUG)
519 1.31 mycroft nextdma_debug_savestate(nsc, state);
520 1.26 dbj #endif
521 1.26 dbj
522 1.26 dbj #ifdef DIAGNOSTIC
523 1.31 mycroft if (/* (state & DMACSR_READ) || */ !(state & DMACSR_COMPLETE)) {
524 1.31 mycroft char sbuf[256];
525 1.31 mycroft nextdma_print(nsc);
526 1.31 mycroft bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
527 1.31 mycroft printf("DMA: state 0x%s\n",sbuf);
528 1.32 provos panic("DMA complete not set in interrupt");
529 1.31 mycroft }
530 1.26 dbj #endif
531 1.26 dbj
532 1.31 mycroft DPRINTF(("DMA: finishing xfer\n"));
533 1.23 dbj
534 1.31 mycroft onext = stat->nd_map->dm_segs[stat->nd_idx].ds_addr;
535 1.31 mycroft olimit = onext + stat->nd_map->dm_segs[stat->nd_idx].ds_len;
536 1.23 dbj
537 1.31 mycroft result = 0;
538 1.31 mycroft if (state & DMACSR_ENABLE) {
539 1.31 mycroft /* enable bit was set */
540 1.31 mycroft result |= 0x01;
541 1.31 mycroft }
542 1.31 mycroft if (state & DMACSR_SUPDATE) {
543 1.31 mycroft /* supdate bit was set */
544 1.31 mycroft result |= 0x02;
545 1.31 mycroft }
546 1.31 mycroft if (stat->nd_map_cont == NULL) {
547 1.31 mycroft KASSERT(stat->nd_idx+1 == stat->nd_map->dm_nsegs);
548 1.31 mycroft /* Expecting a shutdown, didn't SETSUPDATE last turn */
549 1.31 mycroft result |= 0x04;
550 1.31 mycroft }
551 1.31 mycroft if (state & DMACSR_BUSEXC) {
552 1.31 mycroft /* bus exception bit was set */
553 1.31 mycroft result |= 0x08;
554 1.31 mycroft }
555 1.31 mycroft switch (result) {
556 1.31 mycroft case 0x00: /* !BUSEXC && !expecting && !SUPDATE && !ENABLE */
557 1.31 mycroft case 0x08: /* BUSEXC && !expecting && !SUPDATE && !ENABLE */
558 1.31 mycroft if (turbo) {
559 1.31 mycroft volatile u_int *limit = (volatile u_int *)IIOV(0x2000050+0x4000);
560 1.31 mycroft slimit = *limit;
561 1.31 mycroft } else {
562 1.31 mycroft slimit = nd_bsr4 (DD_SAVED_LIMIT);
563 1.31 mycroft }
564 1.31 mycroft break;
565 1.31 mycroft case 0x01: /* !BUSEXC && !expecting && !SUPDATE && ENABLE */
566 1.31 mycroft case 0x09: /* BUSEXC && !expecting && !SUPDATE && ENABLE */
567 1.31 mycroft if (turbo) {
568 1.31 mycroft volatile u_int *limit = (volatile u_int *)IIOV(0x2000050+0x4000);
569 1.31 mycroft slimit = *limit;
570 1.31 mycroft } else {
571 1.31 mycroft slimit = nd_bsr4 (DD_SAVED_LIMIT);
572 1.31 mycroft }
573 1.31 mycroft break;
574 1.31 mycroft case 0x02: /* !BUSEXC && !expecting && SUPDATE && !ENABLE */
575 1.31 mycroft case 0x0a: /* BUSEXC && !expecting && SUPDATE && !ENABLE */
576 1.31 mycroft slimit = nd_bsr4 (DD_NEXT);
577 1.31 mycroft break;
578 1.31 mycroft case 0x04: /* !BUSEXC && expecting && !SUPDATE && !ENABLE */
579 1.31 mycroft case 0x0c: /* BUSEXC && expecting && !SUPDATE && !ENABLE */
580 1.31 mycroft slimit = nd_bsr4 (DD_LIMIT);
581 1.31 mycroft break;
582 1.31 mycroft default:
583 1.31 mycroft #ifdef DIAGNOSTIC
584 1.31 mycroft {
585 1.31 mycroft char sbuf[256];
586 1.31 mycroft printf("DMA: please send this output to port-next68k-maintainer (at) netbsd.org:\n");
587 1.31 mycroft bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
588 1.31 mycroft printf("DMA: state 0x%s\n",sbuf);
589 1.31 mycroft nextdma_print(nsc);
590 1.32 provos panic("DMA: condition 0x%02x not yet documented to occur",result);
591 1.31 mycroft }
592 1.31 mycroft #endif
593 1.31 mycroft slimit = olimit;
594 1.31 mycroft break;
595 1.31 mycroft }
596 1.22 tv
597 1.31 mycroft if (!turbo && nsc->sc_chan->nd_intr == NEXT_I_ENETX_DMA) {
598 1.31 mycroft slimit &= ~0x80000000;
599 1.31 mycroft slimit -= 15;
600 1.31 mycroft }
601 1.22 tv
602 1.23 dbj #ifdef DIAGNOSTIC
603 1.31 mycroft if ((state & DMACSR_READ))
604 1.31 mycroft DPRINTF (("limits: 0x%08lx <= 0x%08lx <= 0x%08lx %s\n", onext, slimit, olimit,
605 1.31 mycroft (state & DMACSR_READ) ? "read" : "write"));
606 1.31 mycroft if ((slimit < onext) || (slimit > olimit)) {
607 1.31 mycroft char sbuf[256];
608 1.31 mycroft bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
609 1.31 mycroft printf("DMA: state 0x%s\n",sbuf);
610 1.31 mycroft nextdma_print(nsc);
611 1.32 provos panic("DMA: Unexpected limit register (0x%08lx) in finish_xfer",slimit);
612 1.31 mycroft }
613 1.1 dbj #endif
614 1.1 dbj
615 1.26 dbj #ifdef DIAGNOSTIC
616 1.31 mycroft if ((state & DMACSR_ENABLE) && ((stat->nd_idx+1) != stat->nd_map->dm_nsegs)) {
617 1.31 mycroft if (slimit != olimit) {
618 1.31 mycroft char sbuf[256];
619 1.31 mycroft bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
620 1.31 mycroft printf("DMA: state 0x%s\n",sbuf);
621 1.31 mycroft nextdma_print(nsc);
622 1.32 provos panic("DMA: short limit register (0x%08lx) w/o finishing map.",slimit);
623 1.31 mycroft }
624 1.31 mycroft }
625 1.26 dbj #endif
626 1.26 dbj
627 1.23 dbj #if (defined(ND_DEBUG))
628 1.31 mycroft if (NEXTDMA_DEBUG > 2) nextdma_print(nsc);
629 1.23 dbj #endif
630 1.7 dbj
631 1.31 mycroft stat->nd_map->dm_xfer_len += slimit-onext;
632 1.31 mycroft
633 1.31 mycroft /* If we've reached the end of the current map, then inform
634 1.31 mycroft * that we've completed that map.
635 1.31 mycroft */
636 1.31 mycroft if ((stat->nd_idx+1) == stat->nd_map->dm_nsegs) {
637 1.31 mycroft if (nsc->sc_conf.nd_completed_cb)
638 1.31 mycroft (*nsc->sc_conf.nd_completed_cb)
639 1.31 mycroft (stat->nd_map, nsc->sc_conf.nd_cb_arg);
640 1.31 mycroft } else {
641 1.31 mycroft KASSERT(stat->nd_map == stat->nd_map_cont);
642 1.31 mycroft KASSERT(stat->nd_idx+1 == stat->nd_idx_cont);
643 1.31 mycroft }
644 1.31 mycroft stat->nd_map = 0;
645 1.31 mycroft stat->nd_idx = 0;
646 1.12 dbj
647 1.31 mycroft #if (defined(ND_DEBUG))
648 1.31 mycroft if (NEXTDMA_DEBUG) {
649 1.31 mycroft char sbuf[256];
650 1.31 mycroft bitmask_snprintf(state, DMACSR_BITS, sbuf, sizeof(sbuf));
651 1.31 mycroft printf("CLNDMAP: dd->dd_csr = 0x%s\n", sbuf);
652 1.31 mycroft }
653 1.31 mycroft #endif
654 1.31 mycroft if (state & DMACSR_ENABLE) {
655 1.31 mycroft u_long dmadir; /* DMACSR_SETREAD or DMACSR_SETWRITE */
656 1.23 dbj
657 1.31 mycroft nextdma_rotate(nsc);
658 1.31 mycroft nextdma_setup_cont_regs(nsc);
659 1.31 mycroft
660 1.31 mycroft if (state & DMACSR_READ) {
661 1.31 mycroft dmadir = DMACSR_SETREAD;
662 1.31 mycroft } else {
663 1.31 mycroft dmadir = DMACSR_SETWRITE;
664 1.30 christos }
665 1.22 tv
666 1.31 mycroft if (stat->nd_map_cont == NULL) {
667 1.31 mycroft KASSERT(stat->nd_idx+1 == stat->nd_map->dm_nsegs);
668 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | dmadir);
669 1.31 mycroft NDTRACEIF (*ndtracep++ = 'g');
670 1.23 dbj } else {
671 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | dmadir | DMACSR_SETSUPDATE);
672 1.31 mycroft NDTRACEIF (*ndtracep++ = 'G');
673 1.31 mycroft }
674 1.31 mycroft } else {
675 1.31 mycroft DPRINTF(("DMA: a shutdown occurred\n"));
676 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_CLRCOMPLETE | DMACSR_RESET);
677 1.31 mycroft
678 1.31 mycroft /* Cleanup more incomplete transfers */
679 1.31 mycroft /* cleanup continue map */
680 1.31 mycroft if (stat->nd_map_cont) {
681 1.31 mycroft DPRINTF(("DMA: shutting down with non null continue map\n"));
682 1.31 mycroft if (nsc->sc_conf.nd_completed_cb)
683 1.31 mycroft (*nsc->sc_conf.nd_completed_cb)
684 1.31 mycroft (stat->nd_map_cont, nsc->sc_conf.nd_cb_arg);
685 1.23 dbj
686 1.31 mycroft stat->nd_map_cont = 0;
687 1.31 mycroft stat->nd_idx_cont = 0;
688 1.1 dbj }
689 1.31 mycroft if (nsc->sc_conf.nd_shutdown_cb)
690 1.31 mycroft (*nsc->sc_conf.nd_shutdown_cb)(nsc->sc_conf.nd_cb_arg);
691 1.1 dbj }
692 1.30 christos
693 1.22 tv #ifdef ND_DEBUG
694 1.30 christos if (NEXTDMA_DEBUG) {
695 1.22 tv char sbuf[256];
696 1.22 tv
697 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
698 1.22 tv sbuf, sizeof(sbuf));
699 1.22 tv printf("DMA exiting interrupt ipl (%ld) intr(0x%s)\n",
700 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), sbuf);
701 1.22 tv }
702 1.22 tv #endif
703 1.31 mycroft
704 1.31 mycroft return(1);
705 1.1 dbj }
706 1.31 mycroft #endif
707 1.1 dbj
708 1.1 dbj /*
709 1.1 dbj * Check to see if dma has finished for a channel */
710 1.1 dbj int
711 1.31 mycroft nextdma_finished(nsc)
712 1.31 mycroft struct nextdma_softc *nsc;
713 1.1 dbj {
714 1.1 dbj int r;
715 1.1 dbj int s;
716 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
717 1.31 mycroft
718 1.31 mycroft s = spldma();
719 1.31 mycroft r = (stat->nd_map == NULL) && (stat->nd_map_cont == NULL);
720 1.1 dbj splx(s);
721 1.31 mycroft
722 1.1 dbj return(r);
723 1.1 dbj }
724 1.1 dbj
725 1.1 dbj void
726 1.31 mycroft nextdma_start(nsc, dmadir)
727 1.31 mycroft struct nextdma_softc *nsc;
728 1.31 mycroft u_long dmadir; /* DMACSR_SETREAD or DMACSR_SETWRITE */
729 1.1 dbj {
730 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
731 1.1 dbj
732 1.31 mycroft NDTRACEIF (*ndtracep++ = 'n');
733 1.1 dbj #ifdef DIAGNOSTIC
734 1.31 mycroft if (!nextdma_finished(nsc)) {
735 1.22 tv char sbuf[256];
736 1.22 tv
737 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
738 1.22 tv sbuf, sizeof(sbuf));
739 1.32 provos panic("DMA trying to start before previous finished on intr(0x%s)", sbuf);
740 1.1 dbj }
741 1.1 dbj #endif
742 1.1 dbj
743 1.22 tv #ifdef ND_DEBUG
744 1.30 christos if (NEXTDMA_DEBUG) {
745 1.22 tv char sbuf[256];
746 1.22 tv
747 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
748 1.22 tv sbuf, sizeof(sbuf));
749 1.22 tv printf("DMA start (%ld) intr(0x%s)\n",
750 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), sbuf);
751 1.22 tv }
752 1.22 tv #endif
753 1.1 dbj
754 1.1 dbj #ifdef DIAGNOSTIC
755 1.31 mycroft if (stat->nd_map) {
756 1.31 mycroft nextdma_print(nsc);
757 1.32 provos panic("DMA: nextdma_start() with non null map");
758 1.1 dbj }
759 1.31 mycroft if (stat->nd_map_cont) {
760 1.31 mycroft nextdma_print(nsc);
761 1.32 provos panic("DMA: nextdma_start() with non null continue map");
762 1.1 dbj }
763 1.1 dbj #endif
764 1.1 dbj
765 1.9 dbj #ifdef DIAGNOSTIC
766 1.19 dbj if ((dmadir != DMACSR_SETREAD) && (dmadir != DMACSR_SETWRITE)) {
767 1.32 provos panic("DMA: nextdma_start(), dmadir arg must be DMACSR_SETREAD or DMACSR_SETWRITE");
768 1.9 dbj }
769 1.9 dbj #endif
770 1.9 dbj
771 1.26 dbj #if defined(ND_DEBUG)
772 1.31 mycroft nextdma_debug_initstate(nsc);
773 1.26 dbj #endif
774 1.26 dbj
775 1.7 dbj /* preload both the current and the continue maps */
776 1.31 mycroft nextdma_rotate(nsc);
777 1.1 dbj
778 1.1 dbj #ifdef DIAGNOSTIC
779 1.31 mycroft if (!stat->nd_map_cont) {
780 1.1 dbj panic("No map available in nextdma_start()");
781 1.1 dbj }
782 1.1 dbj #endif
783 1.1 dbj
784 1.31 mycroft nextdma_rotate(nsc);
785 1.7 dbj
786 1.22 tv #ifdef ND_DEBUG
787 1.30 christos if (NEXTDMA_DEBUG) {
788 1.22 tv char sbuf[256];
789 1.22 tv
790 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
791 1.22 tv sbuf, sizeof(sbuf));
792 1.22 tv printf("DMA initiating DMA %s of %d segments on intr(0x%s)\n",
793 1.31 mycroft (dmadir == DMACSR_SETREAD ? "read" : "write"), stat->nd_map->dm_nsegs, sbuf);
794 1.22 tv }
795 1.22 tv #endif
796 1.1 dbj
797 1.31 mycroft nd_bsw4 (DD_CSR, (turbo ? DMACSR_INITBUFTURBO : DMACSR_INITBUF) |
798 1.31 mycroft DMACSR_RESET | dmadir);
799 1.31 mycroft nd_bsw4 (DD_CSR, 0);
800 1.1 dbj
801 1.31 mycroft nextdma_setup_curr_regs(nsc);
802 1.31 mycroft nextdma_setup_cont_regs(nsc);
803 1.1 dbj
804 1.4 dbj #if (defined(ND_DEBUG))
805 1.31 mycroft if (NEXTDMA_DEBUG > 2) nextdma_print(nsc);
806 1.4 dbj #endif
807 1.1 dbj
808 1.31 mycroft if (stat->nd_map_cont == NULL) {
809 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_SETENABLE | dmadir);
810 1.20 dbj } else {
811 1.31 mycroft nd_bsw4 (DD_CSR, DMACSR_SETSUPDATE | DMACSR_SETENABLE | dmadir);
812 1.1 dbj }
813 1.1 dbj }
814 1.31 mycroft
815 1.31 mycroft /* This routine is used for debugging */
816 1.31 mycroft void
817 1.31 mycroft nextdma_print(nsc)
818 1.31 mycroft struct nextdma_softc *nsc;
819 1.31 mycroft {
820 1.31 mycroft u_long dd_csr;
821 1.31 mycroft u_long dd_next;
822 1.31 mycroft u_long dd_next_initbuf;
823 1.31 mycroft u_long dd_limit;
824 1.31 mycroft u_long dd_start;
825 1.31 mycroft u_long dd_stop;
826 1.31 mycroft u_long dd_saved_next;
827 1.31 mycroft u_long dd_saved_limit;
828 1.31 mycroft u_long dd_saved_start;
829 1.31 mycroft u_long dd_saved_stop;
830 1.31 mycroft char sbuf[256];
831 1.31 mycroft struct nextdma_status *stat = &nsc->sc_stat;
832 1.31 mycroft
833 1.31 mycroft /* Read all of the registers before we print anything out,
834 1.31 mycroft * in case something changes
835 1.31 mycroft */
836 1.31 mycroft dd_csr = nd_bsr4 (DD_CSR);
837 1.31 mycroft dd_next = nd_bsr4 (DD_NEXT);
838 1.31 mycroft dd_next_initbuf = nd_bsr4 (DD_NEXT_INITBUF);
839 1.31 mycroft dd_limit = nd_bsr4 (DD_LIMIT);
840 1.31 mycroft dd_start = nd_bsr4 (DD_START);
841 1.31 mycroft dd_stop = nd_bsr4 (DD_STOP);
842 1.31 mycroft dd_saved_next = nd_bsr4 (DD_SAVED_NEXT);
843 1.31 mycroft dd_saved_limit = nd_bsr4 (DD_SAVED_LIMIT);
844 1.31 mycroft dd_saved_start = nd_bsr4 (DD_SAVED_START);
845 1.31 mycroft dd_saved_stop = nd_bsr4 (DD_SAVED_STOP);
846 1.31 mycroft
847 1.31 mycroft bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRSTAT)),
848 1.31 mycroft NEXT_INTR_BITS, sbuf, sizeof(sbuf));
849 1.31 mycroft printf("NDMAP: *intrstat = 0x%s\n", sbuf);
850 1.31 mycroft
851 1.31 mycroft bitmask_snprintf((*(volatile u_long *)IIOV(NEXT_P_INTRMASK)),
852 1.31 mycroft NEXT_INTR_BITS, sbuf, sizeof(sbuf));
853 1.31 mycroft printf("NDMAP: *intrmask = 0x%s\n", sbuf);
854 1.31 mycroft
855 1.31 mycroft /* NDMAP is Next DMA Print (really!) */
856 1.31 mycroft
857 1.31 mycroft if (stat->nd_map) {
858 1.31 mycroft int i;
859 1.31 mycroft
860 1.31 mycroft printf("NDMAP: nd_map->dm_mapsize = %ld\n",
861 1.31 mycroft stat->nd_map->dm_mapsize);
862 1.31 mycroft printf("NDMAP: nd_map->dm_nsegs = %d\n",
863 1.31 mycroft stat->nd_map->dm_nsegs);
864 1.31 mycroft printf("NDMAP: nd_map->dm_xfer_len = %ld\n",
865 1.31 mycroft stat->nd_map->dm_xfer_len);
866 1.31 mycroft printf("NDMAP: nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
867 1.31 mycroft stat->nd_idx, stat->nd_map->dm_segs[stat->nd_idx].ds_addr);
868 1.31 mycroft printf("NDMAP: nd_map->dm_segs[%d].ds_len = %ld\n",
869 1.31 mycroft stat->nd_idx, stat->nd_map->dm_segs[stat->nd_idx].ds_len);
870 1.31 mycroft
871 1.31 mycroft printf("NDMAP: Entire map;\n");
872 1.31 mycroft for(i=0;i<stat->nd_map->dm_nsegs;i++) {
873 1.31 mycroft printf("NDMAP: nd_map->dm_segs[%d].ds_addr = 0x%08lx\n",
874 1.31 mycroft i,stat->nd_map->dm_segs[i].ds_addr);
875 1.31 mycroft printf("NDMAP: nd_map->dm_segs[%d].ds_len = %ld\n",
876 1.31 mycroft i,stat->nd_map->dm_segs[i].ds_len);
877 1.31 mycroft }
878 1.31 mycroft } else {
879 1.31 mycroft printf("NDMAP: nd_map = NULL\n");
880 1.31 mycroft }
881 1.31 mycroft if (stat->nd_map_cont) {
882 1.31 mycroft printf("NDMAP: nd_map_cont->dm_mapsize = %ld\n",
883 1.31 mycroft stat->nd_map_cont->dm_mapsize);
884 1.31 mycroft printf("NDMAP: nd_map_cont->dm_nsegs = %d\n",
885 1.31 mycroft stat->nd_map_cont->dm_nsegs);
886 1.31 mycroft printf("NDMAP: nd_map_cont->dm_xfer_len = %ld\n",
887 1.31 mycroft stat->nd_map_cont->dm_xfer_len);
888 1.31 mycroft printf("NDMAP: nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
889 1.31 mycroft stat->nd_idx_cont,stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_addr);
890 1.31 mycroft printf("NDMAP: nd_map_cont->dm_segs[%d].ds_len = %ld\n",
891 1.31 mycroft stat->nd_idx_cont,stat->nd_map_cont->dm_segs[stat->nd_idx_cont].ds_len);
892 1.31 mycroft if (stat->nd_map_cont != stat->nd_map) {
893 1.31 mycroft int i;
894 1.31 mycroft printf("NDMAP: Entire map;\n");
895 1.31 mycroft for(i=0;i<stat->nd_map_cont->dm_nsegs;i++) {
896 1.31 mycroft printf("NDMAP: nd_map_cont->dm_segs[%d].ds_addr = 0x%08lx\n",
897 1.31 mycroft i,stat->nd_map_cont->dm_segs[i].ds_addr);
898 1.31 mycroft printf("NDMAP: nd_map_cont->dm_segs[%d].ds_len = %ld\n",
899 1.31 mycroft i,stat->nd_map_cont->dm_segs[i].ds_len);
900 1.31 mycroft }
901 1.31 mycroft }
902 1.31 mycroft } else {
903 1.31 mycroft printf("NDMAP: nd_map_cont = NULL\n");
904 1.31 mycroft }
905 1.31 mycroft
906 1.31 mycroft bitmask_snprintf(dd_csr, DMACSR_BITS, sbuf, sizeof(sbuf));
907 1.31 mycroft printf("NDMAP: dd->dd_csr = 0x%s\n", sbuf);
908 1.31 mycroft
909 1.31 mycroft printf("NDMAP: dd->dd_saved_next = 0x%08lx\n", dd_saved_next);
910 1.31 mycroft printf("NDMAP: dd->dd_saved_limit = 0x%08lx\n", dd_saved_limit);
911 1.31 mycroft printf("NDMAP: dd->dd_saved_start = 0x%08lx\n", dd_saved_start);
912 1.31 mycroft printf("NDMAP: dd->dd_saved_stop = 0x%08lx\n", dd_saved_stop);
913 1.31 mycroft printf("NDMAP: dd->dd_next = 0x%08lx\n", dd_next);
914 1.31 mycroft printf("NDMAP: dd->dd_next_initbuf = 0x%08lx\n", dd_next_initbuf);
915 1.31 mycroft printf("NDMAP: dd->dd_limit = 0x%08lx\n", dd_limit);
916 1.31 mycroft printf("NDMAP: dd->dd_start = 0x%08lx\n", dd_start);
917 1.31 mycroft printf("NDMAP: dd->dd_stop = 0x%08lx\n", dd_stop);
918 1.31 mycroft
919 1.31 mycroft bitmask_snprintf(NEXT_I_BIT(nsc->sc_chan->nd_intr), NEXT_INTR_BITS,
920 1.31 mycroft sbuf, sizeof(sbuf));
921 1.31 mycroft printf("NDMAP: interrupt ipl (%ld) intr(0x%s)\n",
922 1.31 mycroft NEXT_I_IPL(nsc->sc_chan->nd_intr), sbuf);
923 1.31 mycroft }
924 1.31 mycroft
925 1.31 mycroft #if defined(ND_DEBUG)
926 1.31 mycroft void
927 1.31 mycroft nextdma_debug_initstate(struct nextdma_softc *nsc)
928 1.31 mycroft {
929 1.31 mycroft switch(nsc->sc_chan->nd_intr) {
930 1.31 mycroft case NEXT_I_ENETR_DMA:
931 1.31 mycroft memset(nextdma_debug_enetr_state,0,sizeof(nextdma_debug_enetr_state));
932 1.31 mycroft break;
933 1.31 mycroft case NEXT_I_SCSI_DMA:
934 1.31 mycroft memset(nextdma_debug_scsi_state,0,sizeof(nextdma_debug_scsi_state));
935 1.31 mycroft break;
936 1.31 mycroft }
937 1.31 mycroft }
938 1.31 mycroft
939 1.31 mycroft void
940 1.31 mycroft nextdma_debug_savestate(struct nextdma_softc *nsc, unsigned int state)
941 1.31 mycroft {
942 1.31 mycroft switch(nsc->sc_chan->nd_intr) {
943 1.31 mycroft case NEXT_I_ENETR_DMA:
944 1.31 mycroft nextdma_debug_enetr_state[nextdma_debug_enetr_idx++] = state;
945 1.31 mycroft nextdma_debug_enetr_idx %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
946 1.31 mycroft break;
947 1.31 mycroft case NEXT_I_SCSI_DMA:
948 1.31 mycroft nextdma_debug_scsi_state[nextdma_debug_scsi_idx++] = state;
949 1.31 mycroft nextdma_debug_scsi_idx %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
950 1.31 mycroft break;
951 1.31 mycroft }
952 1.31 mycroft }
953 1.31 mycroft
954 1.31 mycroft void
955 1.31 mycroft nextdma_debug_enetr_dumpstate(void)
956 1.31 mycroft {
957 1.31 mycroft int i;
958 1.31 mycroft int s;
959 1.31 mycroft s = spldma();
960 1.31 mycroft i = nextdma_debug_enetr_idx;
961 1.31 mycroft do {
962 1.31 mycroft char sbuf[256];
963 1.31 mycroft if (nextdma_debug_enetr_state[i]) {
964 1.31 mycroft bitmask_snprintf(nextdma_debug_enetr_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
965 1.31 mycroft printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
966 1.31 mycroft }
967 1.31 mycroft i++;
968 1.31 mycroft i %= (sizeof(nextdma_debug_enetr_state)/sizeof(unsigned int));
969 1.31 mycroft } while (i != nextdma_debug_enetr_idx);
970 1.31 mycroft splx(s);
971 1.31 mycroft }
972 1.31 mycroft
973 1.31 mycroft void
974 1.31 mycroft nextdma_debug_scsi_dumpstate(void)
975 1.31 mycroft {
976 1.31 mycroft int i;
977 1.31 mycroft int s;
978 1.31 mycroft s = spldma();
979 1.31 mycroft i = nextdma_debug_scsi_idx;
980 1.31 mycroft do {
981 1.31 mycroft char sbuf[256];
982 1.31 mycroft if (nextdma_debug_scsi_state[i]) {
983 1.31 mycroft bitmask_snprintf(nextdma_debug_scsi_state[i], DMACSR_BITS, sbuf, sizeof(sbuf));
984 1.31 mycroft printf("DMA: 0x%02x state 0x%s\n",i,sbuf);
985 1.31 mycroft }
986 1.31 mycroft i++;
987 1.31 mycroft i %= (sizeof(nextdma_debug_scsi_state)/sizeof(unsigned int));
988 1.31 mycroft } while (i != nextdma_debug_scsi_idx);
989 1.31 mycroft splx(s);
990 1.31 mycroft }
991 1.31 mycroft #endif
992 1.31 mycroft
993