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