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