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