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