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