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