gtidmac.c revision 1.5 1 1.5 kiyohara /* $NetBSD: gtidmac.c,v 1.5 2010/07/20 11:47:59 kiyohara Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2008 KIYOHARA Takashi
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara *
15 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 kiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 kiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1 kiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1 kiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 kiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1 kiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 kiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara */
27 1.1 kiyohara
28 1.1 kiyohara #include <sys/cdefs.h>
29 1.5 kiyohara __KERNEL_RCSID(0, "$NetBSD: gtidmac.c,v 1.5 2010/07/20 11:47:59 kiyohara Exp $");
30 1.1 kiyohara
31 1.1 kiyohara #include <sys/param.h>
32 1.1 kiyohara #include <sys/bus.h>
33 1.1 kiyohara #include <sys/device.h>
34 1.1 kiyohara #include <sys/errno.h>
35 1.1 kiyohara #include <sys/endian.h>
36 1.2 kiyohara #include <sys/kmem.h>
37 1.1 kiyohara
38 1.1 kiyohara #include <uvm/uvm_param.h> /* For PAGE_SIZE */
39 1.1 kiyohara
40 1.1 kiyohara #include <dev/dmover/dmovervar.h>
41 1.1 kiyohara
42 1.1 kiyohara #include <dev/marvell/gtidmacreg.h>
43 1.1 kiyohara #include <dev/marvell/gtidmacvar.h>
44 1.1 kiyohara #include <dev/marvell/marvellreg.h>
45 1.1 kiyohara #include <dev/marvell/marvellvar.h>
46 1.1 kiyohara
47 1.1 kiyohara #include <prop/proplib.h>
48 1.1 kiyohara
49 1.1 kiyohara #include "locators.h"
50 1.1 kiyohara
51 1.1 kiyohara #ifdef GTIDMAC_DEBUG
52 1.1 kiyohara #define DPRINTF(x) if (gtidmac_debug) printf x
53 1.1 kiyohara int gtidmac_debug = 0;
54 1.1 kiyohara #else
55 1.1 kiyohara #define DPRINTF(x)
56 1.1 kiyohara #endif
57 1.1 kiyohara
58 1.1 kiyohara #define GTIDMAC_NDESC 64
59 1.1 kiyohara #define GTIDMAC_MAXCHAN 8
60 1.1 kiyohara #define MVXORE_NDESC 128
61 1.1 kiyohara #define MVXORE_MAXCHAN 2
62 1.1 kiyohara
63 1.1 kiyohara #define GTIDMAC_NSEGS ((GTIDMAC_MAXXFER + PAGE_SIZE - 1) / PAGE_SIZE)
64 1.1 kiyohara #define MVXORE_NSEGS ((MVXORE_MAXXFER + PAGE_SIZE - 1) / PAGE_SIZE)
65 1.1 kiyohara
66 1.1 kiyohara
67 1.1 kiyohara struct gtidmac_softc;
68 1.1 kiyohara
69 1.1 kiyohara struct gtidmac_function {
70 1.1 kiyohara int (*chan_alloc)(void *, bus_dmamap_t **, bus_dmamap_t **, void *);
71 1.1 kiyohara void (*chan_free)(void *, int);
72 1.1 kiyohara int (*dma_setup)(void *, int, int, bus_dmamap_t *, bus_dmamap_t *,
73 1.1 kiyohara bus_size_t);
74 1.1 kiyohara void (*dma_start)(void *, int,
75 1.1 kiyohara void (*dma_done_cb)(void *, int, bus_dmamap_t *,
76 1.1 kiyohara bus_dmamap_t *, int));
77 1.1 kiyohara uint32_t (*dma_finish)(void *, int, int);
78 1.1 kiyohara };
79 1.1 kiyohara
80 1.1 kiyohara struct gtidmac_dma_desc {
81 1.1 kiyohara int dd_index;
82 1.1 kiyohara union {
83 1.1 kiyohara struct gtidmac_desc *idmac_vaddr;
84 1.1 kiyohara struct mvxore_desc *xore_vaddr;
85 1.1 kiyohara } dd_vaddr;
86 1.1 kiyohara #define dd_idmac_vaddr dd_vaddr.idmac_vaddr
87 1.1 kiyohara #define dd_xore_vaddr dd_vaddr.xore_vaddr
88 1.1 kiyohara paddr_t dd_paddr;
89 1.1 kiyohara SLIST_ENTRY(gtidmac_dma_desc) dd_next;
90 1.1 kiyohara };
91 1.1 kiyohara
92 1.1 kiyohara struct gtidmac_softc {
93 1.1 kiyohara device_t sc_dev;
94 1.1 kiyohara
95 1.1 kiyohara bus_space_tag_t sc_iot;
96 1.1 kiyohara bus_space_handle_t sc_ioh;
97 1.1 kiyohara
98 1.1 kiyohara bus_dma_tag_t sc_dmat;
99 1.1 kiyohara struct gtidmac_dma_desc *sc_dd_buffer;
100 1.1 kiyohara bus_dma_segment_t sc_pattern_segment;
101 1.1 kiyohara struct {
102 1.1 kiyohara u_char pbuf[16]; /* 16byte/pattern */
103 1.1 kiyohara } *sc_pbuf; /* x256 pattern */
104 1.1 kiyohara
105 1.1 kiyohara int sc_gtidmac_nchan;
106 1.1 kiyohara struct gtidmac_desc *sc_dbuf;
107 1.1 kiyohara bus_dmamap_t sc_dmap;
108 1.1 kiyohara SLIST_HEAD(, gtidmac_dma_desc) sc_dlist;
109 1.1 kiyohara struct {
110 1.1 kiyohara bus_dmamap_t chan_in; /* In dmamap */
111 1.1 kiyohara bus_dmamap_t chan_out; /* Out dmamap */
112 1.1 kiyohara uint64_t chan_totalcnt; /* total transfered byte */
113 1.1 kiyohara int chan_ddidx;
114 1.1 kiyohara void *chan_running; /* opaque object data */
115 1.1 kiyohara void (*chan_dma_done)(void *, int, bus_dmamap_t *,
116 1.1 kiyohara bus_dmamap_t *, int);
117 1.1 kiyohara } sc_cdesc[GTIDMAC_MAXCHAN];
118 1.1 kiyohara struct gtidmac_intr_arg {
119 1.1 kiyohara struct gtidmac_softc *ia_sc;
120 1.1 kiyohara uint32_t ia_cause;
121 1.1 kiyohara uint32_t ia_mask;
122 1.1 kiyohara uint32_t ia_eaddr;
123 1.1 kiyohara uint32_t ia_eselect;
124 1.1 kiyohara } sc_intrarg[GTIDMAC_NINTRRUPT];
125 1.1 kiyohara
126 1.1 kiyohara int sc_mvxore_nchan;
127 1.1 kiyohara struct mvxore_desc *sc_dbuf_xore;
128 1.1 kiyohara bus_dmamap_t sc_dmap_xore;
129 1.1 kiyohara SLIST_HEAD(, gtidmac_dma_desc) sc_dlist_xore;
130 1.1 kiyohara struct {
131 1.1 kiyohara bus_dmamap_t chan_in[MVXORE_NSRC]; /* In dmamap */
132 1.1 kiyohara bus_dmamap_t chan_out; /* Out dmamap */
133 1.1 kiyohara uint64_t chan_totalcnt; /* total transfered */
134 1.1 kiyohara int chan_ddidx;
135 1.1 kiyohara void *chan_running; /* opaque object data */
136 1.1 kiyohara void (*chan_dma_done)(void *, int, bus_dmamap_t *,
137 1.1 kiyohara bus_dmamap_t *, int);
138 1.1 kiyohara } sc_cdesc_xore[MVXORE_MAXCHAN];
139 1.1 kiyohara
140 1.1 kiyohara struct dmover_backend sc_dmb;
141 1.1 kiyohara struct dmover_backend sc_dmb_xore;
142 1.1 kiyohara int sc_dmb_busy;
143 1.1 kiyohara };
144 1.1 kiyohara struct gtidmac_softc *gtidmac_softc = NULL;
145 1.1 kiyohara
146 1.1 kiyohara static int gtidmac_match(device_t, struct cfdata *, void *);
147 1.1 kiyohara static void gtidmac_attach(device_t, device_t, void *);
148 1.1 kiyohara
149 1.1 kiyohara static int gtidmac_intr(void *);
150 1.1 kiyohara static int mvxore_intr(void *);
151 1.1 kiyohara
152 1.1 kiyohara static void gtidmac_process(struct dmover_backend *);
153 1.1 kiyohara static void gtidmac_dmover_run(struct dmover_backend *);
154 1.1 kiyohara static void gtidmac_dmover_done(void *, int, bus_dmamap_t *, bus_dmamap_t *,
155 1.1 kiyohara int);
156 1.1 kiyohara __inline int gtidmac_dmmap_load(struct gtidmac_softc *, bus_dmamap_t,
157 1.1 kiyohara dmover_buffer_type, dmover_buffer *, int);
158 1.1 kiyohara __inline void gtidmac_dmmap_unload(struct gtidmac_softc *, bus_dmamap_t, int);
159 1.1 kiyohara
160 1.1 kiyohara static uint32_t gtidmac_finish(void *, int, int);
161 1.1 kiyohara static uint32_t mvxore_finish(void *, int, int);
162 1.1 kiyohara
163 1.1 kiyohara static void gtidmac_wininit(struct gtidmac_softc *);
164 1.1 kiyohara static void mvxore_wininit(struct gtidmac_softc *);
165 1.1 kiyohara
166 1.1 kiyohara #ifdef GTIDMAC_DEBUG
167 1.1 kiyohara static void gtidmac_dump_idmacreg(struct gtidmac_softc *, int);
168 1.1 kiyohara static void gtidmac_dump_idmacdesc(struct gtidmac_softc *,
169 1.1 kiyohara struct gtidmac_dma_desc *, uint32_t, int);
170 1.1 kiyohara static void gtidmac_dump_xorereg(struct gtidmac_softc *, int);
171 1.1 kiyohara static void gtidmac_dump_xoredesc(struct gtidmac_softc *,
172 1.1 kiyohara struct gtidmac_dma_desc *, uint32_t, int);
173 1.1 kiyohara #endif
174 1.1 kiyohara
175 1.1 kiyohara
176 1.1 kiyohara static struct gtidmac_function gtidmac_functions = {
177 1.1 kiyohara .chan_alloc = gtidmac_chan_alloc,
178 1.1 kiyohara .chan_free = gtidmac_chan_free,
179 1.1 kiyohara .dma_setup = gtidmac_setup,
180 1.1 kiyohara .dma_start = gtidmac_start,
181 1.1 kiyohara .dma_finish = gtidmac_finish,
182 1.1 kiyohara };
183 1.1 kiyohara
184 1.1 kiyohara static struct gtidmac_function mvxore_functions = {
185 1.1 kiyohara .chan_alloc = mvxore_chan_alloc,
186 1.1 kiyohara .chan_free = mvxore_chan_free,
187 1.1 kiyohara .dma_setup = mvxore_setup,
188 1.1 kiyohara .dma_start = mvxore_start,
189 1.1 kiyohara .dma_finish = mvxore_finish,
190 1.1 kiyohara };
191 1.1 kiyohara
192 1.1 kiyohara static const struct dmover_algdesc gtidmac_algdescs[] = {
193 1.1 kiyohara {
194 1.1 kiyohara .dad_name = DMOVER_FUNC_ZERO,
195 1.1 kiyohara .dad_data = >idmac_functions,
196 1.1 kiyohara .dad_ninputs = 0
197 1.1 kiyohara },
198 1.1 kiyohara {
199 1.1 kiyohara .dad_name = DMOVER_FUNC_FILL8,
200 1.1 kiyohara .dad_data = >idmac_functions,
201 1.1 kiyohara .dad_ninputs = 0
202 1.1 kiyohara },
203 1.1 kiyohara {
204 1.1 kiyohara .dad_name = DMOVER_FUNC_COPY,
205 1.1 kiyohara .dad_data = >idmac_functions,
206 1.1 kiyohara .dad_ninputs = 1
207 1.1 kiyohara },
208 1.1 kiyohara };
209 1.1 kiyohara
210 1.1 kiyohara static const struct dmover_algdesc mvxore_algdescs[] = {
211 1.1 kiyohara #if 0
212 1.1 kiyohara /*
213 1.1 kiyohara * As for these operations, there are a lot of restrictions. It is
214 1.1 kiyohara * necessary to use IDMAC.
215 1.1 kiyohara */
216 1.1 kiyohara {
217 1.1 kiyohara .dad_name = DMOVER_FUNC_ZERO,
218 1.1 kiyohara .dad_data = &mvxore_functions,
219 1.1 kiyohara .dad_ninputs = 0
220 1.1 kiyohara },
221 1.1 kiyohara {
222 1.1 kiyohara .dad_name = DMOVER_FUNC_FILL8,
223 1.1 kiyohara .dad_data = &mvxore_functions,
224 1.1 kiyohara .dad_ninputs = 0
225 1.1 kiyohara },
226 1.1 kiyohara #endif
227 1.1 kiyohara {
228 1.1 kiyohara .dad_name = DMOVER_FUNC_COPY,
229 1.1 kiyohara .dad_data = &mvxore_functions,
230 1.1 kiyohara .dad_ninputs = 1
231 1.1 kiyohara },
232 1.1 kiyohara {
233 1.1 kiyohara .dad_name = DMOVER_FUNC_ISCSI_CRC32C,
234 1.1 kiyohara .dad_data = &mvxore_functions,
235 1.1 kiyohara .dad_ninputs = 1
236 1.1 kiyohara },
237 1.1 kiyohara {
238 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR2,
239 1.1 kiyohara .dad_data = &mvxore_functions,
240 1.1 kiyohara .dad_ninputs = 2
241 1.1 kiyohara },
242 1.1 kiyohara {
243 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR3,
244 1.1 kiyohara .dad_data = &mvxore_functions,
245 1.1 kiyohara .dad_ninputs = 3
246 1.1 kiyohara },
247 1.1 kiyohara {
248 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR4,
249 1.1 kiyohara .dad_data = &mvxore_functions,
250 1.1 kiyohara .dad_ninputs = 4
251 1.1 kiyohara },
252 1.1 kiyohara {
253 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR5,
254 1.1 kiyohara .dad_data = &mvxore_functions,
255 1.1 kiyohara .dad_ninputs = 5
256 1.1 kiyohara },
257 1.1 kiyohara {
258 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR6,
259 1.1 kiyohara .dad_data = &mvxore_functions,
260 1.1 kiyohara .dad_ninputs = 6
261 1.1 kiyohara },
262 1.1 kiyohara {
263 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR7,
264 1.1 kiyohara .dad_data = &mvxore_functions,
265 1.1 kiyohara .dad_ninputs = 7
266 1.1 kiyohara },
267 1.1 kiyohara {
268 1.1 kiyohara .dad_name = DMOVER_FUNC_XOR8,
269 1.1 kiyohara .dad_data = &mvxore_functions,
270 1.1 kiyohara .dad_ninputs = 8
271 1.1 kiyohara },
272 1.1 kiyohara };
273 1.1 kiyohara
274 1.1 kiyohara CFATTACH_DECL_NEW(gtidmac_gt, sizeof(struct gtidmac_softc),
275 1.1 kiyohara gtidmac_match, gtidmac_attach, NULL, NULL);
276 1.1 kiyohara CFATTACH_DECL_NEW(gtidmac_mbus, sizeof(struct gtidmac_softc),
277 1.1 kiyohara gtidmac_match, gtidmac_attach, NULL, NULL);
278 1.1 kiyohara
279 1.1 kiyohara
280 1.1 kiyohara /* ARGSUSED */
281 1.1 kiyohara static int
282 1.1 kiyohara gtidmac_match(device_t parent, struct cfdata *match, void *aux)
283 1.1 kiyohara {
284 1.1 kiyohara struct marvell_attach_args *mva = aux;
285 1.1 kiyohara
286 1.1 kiyohara if (strcmp(mva->mva_name, match->cf_name) != 0)
287 1.1 kiyohara return 0;
288 1.1 kiyohara
289 1.1 kiyohara if (mva->mva_model == MARVELL_ORION_1_88F6082)
290 1.1 kiyohara return 0;
291 1.1 kiyohara
292 1.4 kiyohara if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
293 1.4 kiyohara mva->mva_irq == MVA_IRQ_DEFAULT)
294 1.1 kiyohara return 0;
295 1.1 kiyohara
296 1.1 kiyohara mva->mva_size = GTIDMAC_SIZE;
297 1.1 kiyohara return 1;
298 1.1 kiyohara }
299 1.1 kiyohara
300 1.1 kiyohara /* ARGSUSED */
301 1.1 kiyohara static void
302 1.1 kiyohara gtidmac_attach(device_t parent, device_t self, void *aux)
303 1.1 kiyohara {
304 1.1 kiyohara struct gtidmac_softc *sc = device_private(self);
305 1.1 kiyohara struct marvell_attach_args *mva = aux;
306 1.1 kiyohara bus_dma_segment_t segs, segs_xore;
307 1.1 kiyohara struct gtidmac_dma_desc *dd;
308 1.1 kiyohara prop_dictionary_t dict = device_properties(self);
309 1.1 kiyohara uint32_t mask, dmb_speed, xore_irq;
310 1.1 kiyohara int idmac_nchan, xore_nchan, nsegs, nsegs_xore, i, j, k, n;
311 1.1 kiyohara
312 1.1 kiyohara xore_irq = 0;
313 1.1 kiyohara idmac_nchan = 8;
314 1.1 kiyohara xore_nchan = 0;
315 1.1 kiyohara switch (mva->mva_model) {
316 1.1 kiyohara case MARVELL_DISCOVERY:
317 1.1 kiyohara case MARVELL_DISCOVERY_II:
318 1.1 kiyohara case MARVELL_DISCOVERY_III:
319 1.1 kiyohara break;
320 1.1 kiyohara
321 1.1 kiyohara case MARVELL_ORION_1_88F1181:
322 1.1 kiyohara case MARVELL_ORION_1_88F5082:
323 1.1 kiyohara case MARVELL_ORION_1_88F5180N:
324 1.1 kiyohara case MARVELL_ORION_1_88F5181:
325 1.1 kiyohara case MARVELL_ORION_1_88W8660:
326 1.1 kiyohara case MARVELL_ORION_2_88F1281:
327 1.1 kiyohara case MARVELL_ORION_2_88F5281:
328 1.1 kiyohara idmac_nchan = 4;
329 1.1 kiyohara break;
330 1.1 kiyohara
331 1.5 kiyohara #if 0
332 1.5 kiyohara case MARVELL_DISCOVERY_LT:
333 1.5 kiyohara case MARVELL_DISCOVERY_V:
334 1.5 kiyohara case MARVELL_DISCOVERY_VI: ????
335 1.5 kiyohara #endif
336 1.1 kiyohara case MARVELL_ORION_1_88F5182:
337 1.1 kiyohara idmac_nchan = 4;
338 1.1 kiyohara xore_nchan = 2;
339 1.1 kiyohara break;
340 1.1 kiyohara }
341 1.1 kiyohara if (xore_nchan != 0)
342 1.1 kiyohara if (!prop_dictionary_get_uint32(dict, "xore-irq-begin",
343 1.1 kiyohara &xore_irq)) {
344 1.1 kiyohara aprint_error(": no xore-irq-begin property\n");
345 1.1 kiyohara return;
346 1.1 kiyohara }
347 1.1 kiyohara
348 1.1 kiyohara aprint_naive("\n");
349 1.1 kiyohara aprint_normal(": Marvell IDMA Controller%s\n",
350 1.1 kiyohara xore_nchan ? "/XOR Engine" : "");
351 1.1 kiyohara
352 1.1 kiyohara sc->sc_dev = self;
353 1.1 kiyohara sc->sc_iot = mva->mva_iot;
354 1.1 kiyohara
355 1.1 kiyohara /* Map I/O registers */
356 1.1 kiyohara if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
357 1.1 kiyohara mva->mva_size, &sc->sc_ioh)) {
358 1.1 kiyohara aprint_error_dev(self, "can't map registers\n");
359 1.1 kiyohara return;
360 1.1 kiyohara }
361 1.1 kiyohara
362 1.1 kiyohara /*
363 1.1 kiyohara * Initialise DMA descriptors and associated metadata
364 1.1 kiyohara */
365 1.1 kiyohara sc->sc_dmat = mva->mva_dmat;
366 1.1 kiyohara n = idmac_nchan * GTIDMAC_NDESC + xore_nchan * MVXORE_NDESC;
367 1.1 kiyohara sc->sc_dd_buffer =
368 1.2 kiyohara kmem_alloc(sizeof(struct gtidmac_dma_desc) * n, KM_SLEEP);
369 1.1 kiyohara if (sc->sc_dd_buffer == NULL) {
370 1.1 kiyohara aprint_error_dev(self, "can't allocate memory\n");
371 1.1 kiyohara goto fail1;
372 1.1 kiyohara }
373 1.1 kiyohara /* pattern buffer */
374 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
375 1.1 kiyohara &sc->sc_pattern_segment, 1, &nsegs, BUS_DMA_NOWAIT)) {
376 1.1 kiyohara aprint_error_dev(self,
377 1.1 kiyohara "bus_dmamem_alloc failed: pattern buffer\n");
378 1.1 kiyohara goto fail2;
379 1.1 kiyohara }
380 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &sc->sc_pattern_segment, 1, PAGE_SIZE,
381 1.1 kiyohara (void **)&sc->sc_pbuf, BUS_DMA_NOWAIT)) {
382 1.1 kiyohara aprint_error_dev(self,
383 1.1 kiyohara "bus_dmamem_map failed: pattern buffer\n");
384 1.1 kiyohara goto fail3;
385 1.1 kiyohara }
386 1.1 kiyohara for (i = 0; i < 0x100; i++)
387 1.1 kiyohara for (j = 0; j < sizeof(sc->sc_pbuf[i].pbuf); j++)
388 1.1 kiyohara sc->sc_pbuf[i].pbuf[j] = i;
389 1.1 kiyohara
390 1.1 kiyohara /* IDMAC DMA descriptor buffer */
391 1.1 kiyohara sc->sc_gtidmac_nchan = idmac_nchan;
392 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat,
393 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan,
394 1.1 kiyohara PAGE_SIZE, 0, &segs, 1, &nsegs, BUS_DMA_NOWAIT)) {
395 1.1 kiyohara aprint_error_dev(self,
396 1.1 kiyohara "bus_dmamem_alloc failed: descriptor buffer\n");
397 1.1 kiyohara goto fail4;
398 1.1 kiyohara }
399 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &segs, 1,
400 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan,
401 1.1 kiyohara (void **)&sc->sc_dbuf, BUS_DMA_NOWAIT)) {
402 1.1 kiyohara aprint_error_dev(self,
403 1.1 kiyohara "bus_dmamem_map failed: descriptor buffer\n");
404 1.1 kiyohara goto fail5;
405 1.1 kiyohara }
406 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
407 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, 1,
408 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, 0,
409 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_dmap)) {
410 1.1 kiyohara aprint_error_dev(self,
411 1.1 kiyohara "bus_dmamap_create failed: descriptor buffer\n");
412 1.1 kiyohara goto fail6;
413 1.1 kiyohara }
414 1.1 kiyohara if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmap, sc->sc_dbuf,
415 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, NULL,
416 1.1 kiyohara BUS_DMA_NOWAIT)) {
417 1.1 kiyohara aprint_error_dev(self,
418 1.1 kiyohara "bus_dmamap_load failed: descriptor buffer\n");
419 1.1 kiyohara goto fail7;
420 1.1 kiyohara }
421 1.1 kiyohara SLIST_INIT(&sc->sc_dlist);
422 1.1 kiyohara for (i = 0; i < GTIDMAC_NDESC * idmac_nchan; i++) {
423 1.1 kiyohara dd = &sc->sc_dd_buffer[i];
424 1.1 kiyohara dd->dd_index = i;
425 1.1 kiyohara dd->dd_idmac_vaddr = &sc->sc_dbuf[i];
426 1.1 kiyohara dd->dd_paddr = sc->sc_dmap->dm_segs[0].ds_addr +
427 1.1 kiyohara (sizeof(struct gtidmac_desc) * i);
428 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist, dd, dd_next);
429 1.1 kiyohara }
430 1.1 kiyohara
431 1.1 kiyohara /* Initialize IDMAC DMA channels */
432 1.1 kiyohara mask = 0;
433 1.1 kiyohara for (i = 0; i < idmac_nchan; i++) {
434 1.1 kiyohara if (i > 0 &&
435 1.1 kiyohara ((i * GTIDMAC_I_BITS) & 31 /*bit*/) == 0) {
436 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
437 1.1 kiyohara GTIDMAC_IMR(i - 1), mask);
438 1.1 kiyohara mask = 0;
439 1.1 kiyohara }
440 1.1 kiyohara
441 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, GTIDMAC_MAXXFER,
442 1.1 kiyohara GTIDMAC_NSEGS, GTIDMAC_MAXXFER, 0, BUS_DMA_NOWAIT,
443 1.1 kiyohara &sc->sc_cdesc[i].chan_in)) {
444 1.1 kiyohara aprint_error_dev(self,
445 1.1 kiyohara "bus_dmamap_create failed: chan%d in\n", i);
446 1.1 kiyohara goto fail8;
447 1.1 kiyohara }
448 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, GTIDMAC_MAXXFER,
449 1.1 kiyohara GTIDMAC_NSEGS, GTIDMAC_MAXXFER, 0, BUS_DMA_NOWAIT,
450 1.1 kiyohara &sc->sc_cdesc[i].chan_out)) {
451 1.1 kiyohara aprint_error_dev(self,
452 1.1 kiyohara "bus_dmamap_create failed: chan%d out\n", i);
453 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat,
454 1.1 kiyohara sc->sc_cdesc[i].chan_in);
455 1.1 kiyohara goto fail8;
456 1.1 kiyohara }
457 1.1 kiyohara sc->sc_cdesc[i].chan_totalcnt = 0;
458 1.1 kiyohara sc->sc_cdesc[i].chan_running = NULL;
459 1.1 kiyohara
460 1.1 kiyohara /* Ignore bits overflow. The mask is 32bit. */
461 1.1 kiyohara mask |= GTIDMAC_I(i,
462 1.1 kiyohara GTIDMAC_I_COMP |
463 1.1 kiyohara GTIDMAC_I_ADDRMISS |
464 1.1 kiyohara GTIDMAC_I_ACCPROT |
465 1.1 kiyohara GTIDMAC_I_WRPROT |
466 1.1 kiyohara GTIDMAC_I_OWN);
467 1.1 kiyohara }
468 1.1 kiyohara if (i > 0)
469 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_IMR(i - 1),
470 1.1 kiyohara mask);
471 1.1 kiyohara
472 1.1 kiyohara /* Setup interrupt */
473 1.1 kiyohara for (j = 0; j < GTIDMAC_NINTRRUPT; j++) {
474 1.1 kiyohara int c = j * idmac_nchan / __arraycount(sc->sc_intrarg);
475 1.1 kiyohara
476 1.1 kiyohara sc->sc_intrarg[j].ia_sc = sc;
477 1.1 kiyohara sc->sc_intrarg[j].ia_cause = GTIDMAC_ICR(c);
478 1.1 kiyohara sc->sc_intrarg[j].ia_eaddr = GTIDMAC_EAR(c);
479 1.1 kiyohara sc->sc_intrarg[j].ia_eselect = GTIDMAC_ESR(c);
480 1.1 kiyohara marvell_intr_establish(mva->mva_irq + j, IPL_BIO,
481 1.1 kiyohara gtidmac_intr, &sc->sc_intrarg[j]);
482 1.1 kiyohara }
483 1.1 kiyohara
484 1.1 kiyohara if (mva->mva_model != MARVELL_DISCOVERY)
485 1.1 kiyohara gtidmac_wininit(sc);
486 1.1 kiyohara
487 1.1 kiyohara /* Register us with dmover. */
488 1.1 kiyohara sc->sc_dmb.dmb_name = device_xname(self);
489 1.1 kiyohara if (!prop_dictionary_get_uint32(dict, "dmb_speed", &dmb_speed)) {
490 1.1 kiyohara aprint_error_dev(self, "no dmb_speed property\n");
491 1.1 kiyohara dmb_speed = 10; /* More than fast swdmover perhaps. */
492 1.1 kiyohara }
493 1.1 kiyohara sc->sc_dmb.dmb_speed = dmb_speed;
494 1.1 kiyohara sc->sc_dmb.dmb_cookie = sc;
495 1.1 kiyohara sc->sc_dmb.dmb_algdescs = gtidmac_algdescs;
496 1.1 kiyohara sc->sc_dmb.dmb_nalgdescs = __arraycount(gtidmac_algdescs);
497 1.1 kiyohara sc->sc_dmb.dmb_process = gtidmac_process;
498 1.1 kiyohara dmover_backend_register(&sc->sc_dmb);
499 1.1 kiyohara sc->sc_dmb_busy = 0;
500 1.1 kiyohara
501 1.1 kiyohara if (xore_nchan) {
502 1.1 kiyohara /* XORE DMA descriptor buffer */
503 1.1 kiyohara sc->sc_mvxore_nchan = xore_nchan;
504 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat,
505 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
506 1.1 kiyohara PAGE_SIZE, 0, &segs_xore, 1, &nsegs_xore, BUS_DMA_NOWAIT)) {
507 1.1 kiyohara aprint_error_dev(self, "bus_dmamem_alloc failed:"
508 1.1 kiyohara " xore descriptor buffer\n");
509 1.1 kiyohara goto fail8;
510 1.1 kiyohara }
511 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &segs_xore, 1,
512 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
513 1.1 kiyohara (void **)&sc->sc_dbuf_xore, BUS_DMA_NOWAIT)) {
514 1.1 kiyohara aprint_error_dev(self,
515 1.1 kiyohara "bus_dmamem_map failed: xore descriptor buffer\n");
516 1.1 kiyohara goto fail9;
517 1.1 kiyohara }
518 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
519 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan, 1,
520 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan, 0,
521 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_dmap_xore)) {
522 1.1 kiyohara aprint_error_dev(self, "bus_dmamap_create failed:"
523 1.1 kiyohara " xore descriptor buffer\n");
524 1.1 kiyohara goto fail10;
525 1.1 kiyohara }
526 1.1 kiyohara if (bus_dmamap_load(
527 1.1 kiyohara sc->sc_dmat, sc->sc_dmap_xore, sc->sc_dbuf_xore,
528 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
529 1.1 kiyohara NULL, BUS_DMA_NOWAIT)) {
530 1.1 kiyohara aprint_error_dev(self,
531 1.1 kiyohara "bus_dmamap_load failed: xore descriptor buffer\n");
532 1.1 kiyohara goto fail11;
533 1.1 kiyohara }
534 1.1 kiyohara SLIST_INIT(&sc->sc_dlist_xore);
535 1.1 kiyohara for (j = 0; j < MVXORE_NDESC * xore_nchan; j++) {
536 1.1 kiyohara dd = &sc->sc_dd_buffer[j + GTIDMAC_NDESC * idmac_nchan];
537 1.1 kiyohara dd->dd_index = j;
538 1.1 kiyohara dd->dd_xore_vaddr = &sc->sc_dbuf_xore[j];
539 1.1 kiyohara dd->dd_paddr = sc->sc_dmap_xore->dm_segs[0].ds_addr +
540 1.1 kiyohara (sizeof(struct mvxore_desc) * j);
541 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist_xore, dd, dd_next);
542 1.1 kiyohara }
543 1.1 kiyohara
544 1.1 kiyohara /* Initialize XORE DMA channels */
545 1.1 kiyohara mask = 0;
546 1.1 kiyohara for (j = 0; j < xore_nchan; j++) {
547 1.1 kiyohara for (k = 0; k < MVXORE_NSRC; k++) {
548 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
549 1.1 kiyohara MVXORE_MAXXFER, MVXORE_NSEGS,
550 1.1 kiyohara MVXORE_MAXXFER, 0, BUS_DMA_NOWAIT,
551 1.1 kiyohara &sc->sc_cdesc_xore[j].chan_in[k])) {
552 1.1 kiyohara aprint_error_dev(self,
553 1.1 kiyohara "bus_dmamap_create failed:"
554 1.1 kiyohara " xore chan%d in[%d]\n", j, k);
555 1.1 kiyohara goto fail12;
556 1.1 kiyohara }
557 1.1 kiyohara }
558 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, MVXORE_MAXXFER,
559 1.1 kiyohara MVXORE_NSEGS, MVXORE_MAXXFER, 0,
560 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_cdesc_xore[j].chan_out)) {
561 1.1 kiyohara aprint_error_dev(self,
562 1.1 kiyohara "bus_dmamap_create failed: chan%d out\n",
563 1.1 kiyohara j);
564 1.1 kiyohara goto fail13;
565 1.1 kiyohara }
566 1.1 kiyohara sc->sc_cdesc_xore[j].chan_totalcnt = 0;
567 1.1 kiyohara sc->sc_cdesc_xore[j].chan_running = NULL;
568 1.1 kiyohara
569 1.1 kiyohara mask |= MVXORE_I(j,
570 1.1 kiyohara MVXORE_I_EOC |
571 1.1 kiyohara MVXORE_I_ADDRDECODE |
572 1.1 kiyohara MVXORE_I_ACCPROT |
573 1.1 kiyohara MVXORE_I_WRPROT |
574 1.1 kiyohara MVXORE_I_OWN |
575 1.1 kiyohara MVXORE_I_INTPARITY |
576 1.1 kiyohara MVXORE_I_XBAR);
577 1.1 kiyohara }
578 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIMR, mask);
579 1.1 kiyohara
580 1.1 kiyohara marvell_intr_establish(xore_irq + 0, IPL_BIO, mvxore_intr, sc);
581 1.1 kiyohara marvell_intr_establish(xore_irq + 1, IPL_BIO, mvxore_intr, sc);
582 1.1 kiyohara
583 1.1 kiyohara mvxore_wininit(sc);
584 1.1 kiyohara
585 1.1 kiyohara /* Register us with dmover. */
586 1.1 kiyohara sc->sc_dmb_xore.dmb_name = device_xname(sc->sc_dev);
587 1.1 kiyohara sc->sc_dmb_xore.dmb_speed = dmb_speed;
588 1.1 kiyohara sc->sc_dmb_xore.dmb_cookie = sc;
589 1.1 kiyohara sc->sc_dmb_xore.dmb_algdescs = mvxore_algdescs;
590 1.1 kiyohara sc->sc_dmb_xore.dmb_nalgdescs =
591 1.1 kiyohara __arraycount(mvxore_algdescs);
592 1.1 kiyohara sc->sc_dmb_xore.dmb_process = gtidmac_process;
593 1.1 kiyohara dmover_backend_register(&sc->sc_dmb_xore);
594 1.1 kiyohara }
595 1.1 kiyohara
596 1.1 kiyohara gtidmac_softc = sc;
597 1.1 kiyohara
598 1.1 kiyohara return;
599 1.1 kiyohara
600 1.1 kiyohara for (; j-- > 0;) {
601 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc_xore[j].chan_out);
602 1.1 kiyohara
603 1.1 kiyohara fail13:
604 1.1 kiyohara k = MVXORE_NSRC;
605 1.1 kiyohara fail12:
606 1.1 kiyohara for (; k-- > 0;)
607 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat,
608 1.1 kiyohara sc->sc_cdesc_xore[j].chan_in[k]);
609 1.1 kiyohara }
610 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap_xore);
611 1.1 kiyohara fail11:
612 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmap_xore);
613 1.1 kiyohara fail10:
614 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_dbuf_xore,
615 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC);
616 1.1 kiyohara fail9:
617 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &segs_xore, 1);
618 1.1 kiyohara fail8:
619 1.1 kiyohara for (; i-- > 0;) {
620 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc[i].chan_in);
621 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc[i].chan_out);
622 1.1 kiyohara }
623 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
624 1.1 kiyohara fail7:
625 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmap);
626 1.1 kiyohara fail6:
627 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_dbuf,
628 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC);
629 1.1 kiyohara fail5:
630 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &segs, 1);
631 1.1 kiyohara fail4:
632 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_pbuf, PAGE_SIZE);
633 1.1 kiyohara fail3:
634 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &sc->sc_pattern_segment, 1);
635 1.1 kiyohara fail2:
636 1.2 kiyohara kmem_free(sc->sc_dd_buffer, sizeof(struct gtidmac_dma_desc) * n);
637 1.1 kiyohara fail1:
638 1.1 kiyohara bus_space_unmap(sc->sc_iot, sc->sc_ioh, mva->mva_size);
639 1.1 kiyohara return;
640 1.1 kiyohara }
641 1.1 kiyohara
642 1.1 kiyohara
643 1.1 kiyohara static int
644 1.1 kiyohara gtidmac_intr(void *arg)
645 1.1 kiyohara {
646 1.1 kiyohara struct gtidmac_intr_arg *ia = arg;
647 1.1 kiyohara struct gtidmac_softc *sc = ia->ia_sc;
648 1.1 kiyohara uint32_t cause;
649 1.1 kiyohara int handled = 0, chan, error;
650 1.1 kiyohara
651 1.1 kiyohara cause = bus_space_read_4(sc->sc_iot, sc->sc_ioh, ia->ia_cause);
652 1.1 kiyohara DPRINTF(("IDMAC intr: cause=0x%x\n", cause));
653 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ia->ia_cause, ~cause);
654 1.1 kiyohara
655 1.1 kiyohara chan = 0;
656 1.1 kiyohara while (cause) {
657 1.1 kiyohara error = 0;
658 1.1 kiyohara if (cause & GTIDMAC_I_ADDRMISS) {
659 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Address Miss");
660 1.1 kiyohara error = EINVAL;
661 1.1 kiyohara }
662 1.1 kiyohara if (cause & GTIDMAC_I_ACCPROT) {
663 1.1 kiyohara aprint_error_dev(sc->sc_dev,
664 1.1 kiyohara "Access Protect Violation");
665 1.1 kiyohara error = EACCES;
666 1.1 kiyohara }
667 1.1 kiyohara if (cause & GTIDMAC_I_WRPROT) {
668 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Write Protect");
669 1.1 kiyohara error = EACCES;
670 1.1 kiyohara }
671 1.1 kiyohara if (cause & GTIDMAC_I_OWN) {
672 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Ownership Violation");
673 1.1 kiyohara error = EINVAL;
674 1.1 kiyohara }
675 1.1 kiyohara
676 1.1 kiyohara #define GTIDMAC_I_ERROR \
677 1.1 kiyohara (GTIDMAC_I_ADDRMISS | \
678 1.1 kiyohara GTIDMAC_I_ACCPROT | \
679 1.1 kiyohara GTIDMAC_I_WRPROT | \
680 1.1 kiyohara GTIDMAC_I_OWN)
681 1.1 kiyohara if (cause & GTIDMAC_I_ERROR) {
682 1.1 kiyohara uint32_t sel;
683 1.1 kiyohara int select;
684 1.1 kiyohara
685 1.1 kiyohara sel = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
686 1.1 kiyohara ia->ia_eselect) & GTIDMAC_ESR_SEL;
687 1.1 kiyohara select = sel - chan * GTIDMAC_I_BITS;
688 1.1 kiyohara if (select >= 0 && select < GTIDMAC_I_BITS) {
689 1.1 kiyohara uint32_t ear;
690 1.1 kiyohara
691 1.1 kiyohara ear = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
692 1.1 kiyohara ia->ia_eaddr);
693 1.1 kiyohara aprint_error(": Error Address 0x%x\n", ear);
694 1.1 kiyohara } else
695 1.1 kiyohara aprint_error(": lost Error Address\n");
696 1.1 kiyohara }
697 1.1 kiyohara
698 1.1 kiyohara if (cause & (GTIDMAC_I_COMP | GTIDMAC_I_ERROR)) {
699 1.1 kiyohara sc->sc_cdesc[chan].chan_dma_done(
700 1.1 kiyohara sc->sc_cdesc[chan].chan_running, chan,
701 1.1 kiyohara &sc->sc_cdesc[chan].chan_in,
702 1.1 kiyohara &sc->sc_cdesc[chan].chan_out, error);
703 1.1 kiyohara handled++;
704 1.1 kiyohara }
705 1.1 kiyohara
706 1.1 kiyohara cause >>= GTIDMAC_I_BITS;
707 1.1 kiyohara }
708 1.1 kiyohara DPRINTF(("IDMAC intr: %shandled\n", handled ? "" : "not "));
709 1.1 kiyohara
710 1.1 kiyohara return handled;
711 1.1 kiyohara }
712 1.1 kiyohara
713 1.1 kiyohara static int
714 1.1 kiyohara mvxore_intr(void *arg)
715 1.1 kiyohara {
716 1.1 kiyohara struct gtidmac_softc *sc = arg;
717 1.1 kiyohara uint32_t cause;
718 1.1 kiyohara int handled = 0, chan, error;
719 1.1 kiyohara
720 1.1 kiyohara cause = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEICR);
721 1.1 kiyohara DPRINTF(("XORE intr: cause=0x%x\n", cause));
722 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEICR, ~cause);
723 1.1 kiyohara
724 1.1 kiyohara chan = 0;
725 1.1 kiyohara while (cause) {
726 1.1 kiyohara error = 0;
727 1.1 kiyohara if (cause & MVXORE_I_ADDRDECODE) {
728 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Failed address decoding");
729 1.1 kiyohara error = EINVAL;
730 1.1 kiyohara }
731 1.1 kiyohara if (cause & MVXORE_I_ACCPROT) {
732 1.1 kiyohara aprint_error_dev(sc->sc_dev,
733 1.1 kiyohara "Access Protect Violation");
734 1.1 kiyohara error = EACCES;
735 1.1 kiyohara }
736 1.1 kiyohara if (cause & MVXORE_I_WRPROT) {
737 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Write Protect");
738 1.1 kiyohara error = EACCES;
739 1.1 kiyohara }
740 1.1 kiyohara if (cause & MVXORE_I_OWN) {
741 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Ownership Violation");
742 1.1 kiyohara error = EINVAL;
743 1.1 kiyohara }
744 1.1 kiyohara if (cause & MVXORE_I_INTPARITY) {
745 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Parity Error");
746 1.1 kiyohara error = EIO;
747 1.1 kiyohara }
748 1.1 kiyohara if (cause & MVXORE_I_XBAR) {
749 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Crossbar Parity Error");
750 1.1 kiyohara error = EINVAL;
751 1.1 kiyohara }
752 1.1 kiyohara
753 1.1 kiyohara #define MVXORE_I_ERROR \
754 1.1 kiyohara (MVXORE_I_ADDRDECODE | \
755 1.1 kiyohara MVXORE_I_ACCPROT | \
756 1.1 kiyohara MVXORE_I_WRPROT | \
757 1.1 kiyohara MVXORE_I_OWN | \
758 1.1 kiyohara MVXORE_I_INTPARITY | \
759 1.1 kiyohara MVXORE_I_XBAR)
760 1.1 kiyohara if (cause & MVXORE_I_ERROR) {
761 1.1 kiyohara uint32_t type;
762 1.1 kiyohara int event;
763 1.1 kiyohara
764 1.1 kiyohara type = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
765 1.1 kiyohara MVXORE_XEECR) & MVXORE_XEECR_ERRORTYPE_MASK;
766 1.1 kiyohara event = type - chan * MVXORE_I_BITS;
767 1.1 kiyohara if (event >= 0 && event < MVXORE_I_BITS) {
768 1.1 kiyohara uint32_t xeear;
769 1.1 kiyohara
770 1.1 kiyohara xeear = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
771 1.1 kiyohara MVXORE_XEEAR);
772 1.1 kiyohara aprint_error(": Error Address 0x%x\n", xeear);
773 1.1 kiyohara } else
774 1.1 kiyohara aprint_error(": lost Error Address\n");
775 1.1 kiyohara }
776 1.1 kiyohara
777 1.1 kiyohara if (cause & (MVXORE_I_EOC | MVXORE_I_ERROR)) {
778 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_dma_done(
779 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running, chan,
780 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_in,
781 1.1 kiyohara &sc->sc_cdesc_xore[chan].chan_out, error);
782 1.1 kiyohara handled++;
783 1.1 kiyohara }
784 1.1 kiyohara
785 1.1 kiyohara cause >>= MVXORE_I_BITS;
786 1.1 kiyohara }
787 1.1 kiyohara DPRINTF(("XORE intr: %shandled\n", handled ? "" : "not "));
788 1.1 kiyohara
789 1.1 kiyohara return handled;
790 1.1 kiyohara }
791 1.1 kiyohara
792 1.1 kiyohara
793 1.1 kiyohara /*
794 1.1 kiyohara * dmover(9) backend function.
795 1.1 kiyohara */
796 1.1 kiyohara static void
797 1.1 kiyohara gtidmac_process(struct dmover_backend *dmb)
798 1.1 kiyohara {
799 1.1 kiyohara struct gtidmac_softc *sc = dmb->dmb_cookie;
800 1.1 kiyohara int s;
801 1.1 kiyohara
802 1.1 kiyohara /* If the backend is currently idle, go process the queue. */
803 1.1 kiyohara s = splbio();
804 1.1 kiyohara if (!sc->sc_dmb_busy)
805 1.1 kiyohara gtidmac_dmover_run(dmb);
806 1.1 kiyohara splx(s);
807 1.1 kiyohara }
808 1.1 kiyohara
809 1.1 kiyohara static void
810 1.1 kiyohara gtidmac_dmover_run(struct dmover_backend *dmb)
811 1.1 kiyohara {
812 1.1 kiyohara struct gtidmac_softc *sc = dmb->dmb_cookie;
813 1.1 kiyohara struct dmover_request *dreq;
814 1.1 kiyohara const struct dmover_algdesc *algdesc;
815 1.1 kiyohara struct gtidmac_function *df;
816 1.1 kiyohara bus_dmamap_t *dmamap_in, *dmamap_out;
817 1.1 kiyohara int chan, ninputs, error, i;
818 1.1 kiyohara
819 1.1 kiyohara sc->sc_dmb_busy = 1;
820 1.1 kiyohara
821 1.1 kiyohara for (;;) {
822 1.1 kiyohara dreq = TAILQ_FIRST(&dmb->dmb_pendreqs);
823 1.1 kiyohara if (dreq == NULL)
824 1.1 kiyohara break;
825 1.1 kiyohara algdesc = dreq->dreq_assignment->das_algdesc;
826 1.1 kiyohara df = algdesc->dad_data;
827 1.1 kiyohara chan = (*df->chan_alloc)(sc, &dmamap_in, &dmamap_out, dreq);
828 1.1 kiyohara if (chan == -1)
829 1.1 kiyohara return;
830 1.1 kiyohara
831 1.1 kiyohara dmover_backend_remque(dmb, dreq);
832 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_RUNNING;
833 1.1 kiyohara
834 1.1 kiyohara /* XXXUNLOCK */
835 1.1 kiyohara
836 1.1 kiyohara error = 0;
837 1.1 kiyohara
838 1.1 kiyohara /* Load in/out buffers of dmover to bus_dmamap. */
839 1.1 kiyohara ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
840 1.1 kiyohara if (ninputs == 0) {
841 1.1 kiyohara int pno = 0;
842 1.1 kiyohara
843 1.1 kiyohara if (algdesc->dad_name == DMOVER_FUNC_FILL8)
844 1.1 kiyohara pno = dreq->dreq_immediate[0];
845 1.1 kiyohara
846 1.1 kiyohara i = 0;
847 1.1 kiyohara error = bus_dmamap_load(sc->sc_dmat, *dmamap_in,
848 1.1 kiyohara &sc->sc_pbuf[pno], sizeof(sc->sc_pbuf[pno]), NULL,
849 1.1 kiyohara BUS_DMA_NOWAIT | BUS_DMA_STREAMING | BUS_DMA_WRITE);
850 1.1 kiyohara if (error == 0) {
851 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, *dmamap_in, 0,
852 1.1 kiyohara sizeof(uint32_t), BUS_DMASYNC_PREWRITE);
853 1.1 kiyohara
854 1.1 kiyohara /*
855 1.1 kiyohara * We will call gtidmac_dmmap_unload() when
856 1.1 kiyohara * becoming an error.
857 1.1 kiyohara */
858 1.1 kiyohara i = 1;
859 1.1 kiyohara }
860 1.1 kiyohara } else
861 1.1 kiyohara for (i = 0; i < ninputs; i++) {
862 1.1 kiyohara error = gtidmac_dmmap_load(sc,
863 1.1 kiyohara *(dmamap_in + i), dreq->dreq_inbuf_type,
864 1.1 kiyohara &dreq->dreq_inbuf[i], 0/*write*/);
865 1.1 kiyohara if (error != 0)
866 1.1 kiyohara break;
867 1.1 kiyohara }
868 1.1 kiyohara if (algdesc->dad_name != DMOVER_FUNC_ISCSI_CRC32C) {
869 1.1 kiyohara if (error == 0)
870 1.1 kiyohara error = gtidmac_dmmap_load(sc, *dmamap_out,
871 1.1 kiyohara dreq->dreq_outbuf_type, &dreq->dreq_outbuf,
872 1.1 kiyohara 1/*read*/);
873 1.1 kiyohara
874 1.1 kiyohara if (error == 0) {
875 1.1 kiyohara /*
876 1.1 kiyohara * The size of outbuf is always believed to be
877 1.1 kiyohara * DMA transfer size in dmover request.
878 1.1 kiyohara */
879 1.1 kiyohara error = (*df->dma_setup)(sc, chan, ninputs,
880 1.1 kiyohara dmamap_in, dmamap_out,
881 1.1 kiyohara (*dmamap_out)->dm_mapsize);
882 1.1 kiyohara if (error != 0)
883 1.1 kiyohara gtidmac_dmmap_unload(sc, *dmamap_out,
884 1.1 kiyohara 1);
885 1.1 kiyohara }
886 1.1 kiyohara } else
887 1.1 kiyohara if (error == 0)
888 1.1 kiyohara error = (*df->dma_setup)(sc, chan, ninputs,
889 1.1 kiyohara dmamap_in, dmamap_out,
890 1.1 kiyohara (*dmamap_in)->dm_mapsize);
891 1.1 kiyohara
892 1.1 kiyohara /* XXXLOCK */
893 1.1 kiyohara
894 1.1 kiyohara if (error != 0) {
895 1.1 kiyohara for (; i-- > 0;)
896 1.1 kiyohara gtidmac_dmmap_unload(sc, *(dmamap_in + i), 0);
897 1.1 kiyohara (*df->chan_free)(sc, chan);
898 1.1 kiyohara
899 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_ERROR;
900 1.1 kiyohara dreq->dreq_error = error;
901 1.1 kiyohara /* XXXUNLOCK */
902 1.1 kiyohara dmover_done(dreq);
903 1.1 kiyohara /* XXXLOCK */
904 1.1 kiyohara continue;
905 1.1 kiyohara }
906 1.1 kiyohara
907 1.1 kiyohara (*df->dma_start)(sc, chan, gtidmac_dmover_done);
908 1.1 kiyohara break;
909 1.1 kiyohara }
910 1.1 kiyohara
911 1.1 kiyohara /* All done */
912 1.1 kiyohara sc->sc_dmb_busy = 0;
913 1.1 kiyohara }
914 1.1 kiyohara
915 1.1 kiyohara static void
916 1.1 kiyohara gtidmac_dmover_done(void *object, int chan, bus_dmamap_t *dmamap_in,
917 1.1 kiyohara bus_dmamap_t *dmamap_out, int error)
918 1.1 kiyohara {
919 1.1 kiyohara struct gtidmac_softc *sc;
920 1.1 kiyohara struct dmover_request *dreq = object;
921 1.1 kiyohara struct dmover_backend *dmb;
922 1.1 kiyohara struct gtidmac_function *df;
923 1.1 kiyohara uint32_t result;
924 1.1 kiyohara int ninputs, i;
925 1.1 kiyohara
926 1.1 kiyohara KASSERT(dreq != NULL);
927 1.1 kiyohara
928 1.1 kiyohara dmb = dreq->dreq_assignment->das_backend;
929 1.1 kiyohara df = dreq->dreq_assignment->das_algdesc->dad_data;
930 1.1 kiyohara ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
931 1.1 kiyohara sc = dmb->dmb_cookie;
932 1.1 kiyohara
933 1.1 kiyohara result = (*df->dma_finish)(sc, chan, error);
934 1.1 kiyohara for (i = 0; i < ninputs; i++)
935 1.1 kiyohara gtidmac_dmmap_unload(sc, *(dmamap_in + i), 0);
936 1.1 kiyohara if (dreq->dreq_assignment->das_algdesc->dad_name ==
937 1.1 kiyohara DMOVER_FUNC_ISCSI_CRC32C)
938 1.1 kiyohara memcpy(dreq->dreq_immediate, &result, sizeof(result));
939 1.1 kiyohara else
940 1.1 kiyohara gtidmac_dmmap_unload(sc, *dmamap_out, 1);
941 1.1 kiyohara
942 1.1 kiyohara (*df->chan_free)(sc, chan);
943 1.1 kiyohara
944 1.1 kiyohara if (error) {
945 1.1 kiyohara dreq->dreq_error = error;
946 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_ERROR;
947 1.1 kiyohara }
948 1.1 kiyohara
949 1.1 kiyohara dmover_done(dreq);
950 1.1 kiyohara
951 1.1 kiyohara /*
952 1.1 kiyohara * See if we can start some more dmover(9) requests.
953 1.1 kiyohara *
954 1.1 kiyohara * Note: We're already at splbio() here.
955 1.1 kiyohara */
956 1.1 kiyohara if (!sc->sc_dmb_busy)
957 1.1 kiyohara gtidmac_dmover_run(dmb);
958 1.1 kiyohara }
959 1.1 kiyohara
960 1.1 kiyohara __inline int
961 1.1 kiyohara gtidmac_dmmap_load(struct gtidmac_softc *sc, bus_dmamap_t dmamap,
962 1.1 kiyohara dmover_buffer_type dmbuf_type, dmover_buffer *dmbuf,
963 1.1 kiyohara int read)
964 1.1 kiyohara {
965 1.1 kiyohara int error, flags;
966 1.1 kiyohara
967 1.1 kiyohara flags = BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
968 1.1 kiyohara read ? BUS_DMA_READ : BUS_DMA_WRITE;
969 1.1 kiyohara
970 1.1 kiyohara switch (dmbuf_type) {
971 1.1 kiyohara case DMOVER_BUF_LINEAR:
972 1.1 kiyohara error = bus_dmamap_load(sc->sc_dmat, dmamap,
973 1.1 kiyohara dmbuf->dmbuf_linear.l_addr, dmbuf->dmbuf_linear.l_len,
974 1.1 kiyohara NULL, flags);
975 1.1 kiyohara break;
976 1.1 kiyohara
977 1.1 kiyohara case DMOVER_BUF_UIO:
978 1.1 kiyohara if ((read && dmbuf->dmbuf_uio->uio_rw != UIO_READ) ||
979 1.1 kiyohara (!read && dmbuf->dmbuf_uio->uio_rw == UIO_READ))
980 1.1 kiyohara return (EINVAL);
981 1.1 kiyohara
982 1.1 kiyohara error = bus_dmamap_load_uio(sc->sc_dmat, dmamap,
983 1.1 kiyohara dmbuf->dmbuf_uio, flags);
984 1.1 kiyohara break;
985 1.1 kiyohara
986 1.1 kiyohara default:
987 1.1 kiyohara error = EINVAL;
988 1.1 kiyohara }
989 1.1 kiyohara
990 1.1 kiyohara if (error == 0)
991 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
992 1.1 kiyohara read ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
993 1.1 kiyohara
994 1.1 kiyohara return error;
995 1.1 kiyohara }
996 1.1 kiyohara
997 1.1 kiyohara __inline void
998 1.1 kiyohara gtidmac_dmmap_unload(struct gtidmac_softc *sc, bus_dmamap_t dmamap, int read)
999 1.1 kiyohara {
1000 1.1 kiyohara
1001 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
1002 1.1 kiyohara read ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1003 1.1 kiyohara
1004 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, dmamap);
1005 1.1 kiyohara }
1006 1.1 kiyohara
1007 1.1 kiyohara
1008 1.1 kiyohara void *
1009 1.1 kiyohara gtidmac_tag_get()
1010 1.1 kiyohara {
1011 1.1 kiyohara
1012 1.1 kiyohara return gtidmac_softc;
1013 1.1 kiyohara }
1014 1.1 kiyohara
1015 1.1 kiyohara /*
1016 1.1 kiyohara * IDMAC functions
1017 1.1 kiyohara */
1018 1.1 kiyohara int
1019 1.1 kiyohara gtidmac_chan_alloc(void *tag, bus_dmamap_t **dmamap_in,
1020 1.1 kiyohara bus_dmamap_t **dmamap_out, void *object)
1021 1.1 kiyohara {
1022 1.1 kiyohara struct gtidmac_softc *sc = tag;
1023 1.1 kiyohara int chan;
1024 1.1 kiyohara
1025 1.1 kiyohara /* maybe need lock */
1026 1.1 kiyohara
1027 1.1 kiyohara for (chan = 0; chan < sc->sc_gtidmac_nchan; chan++)
1028 1.1 kiyohara if (sc->sc_cdesc[chan].chan_running == NULL)
1029 1.1 kiyohara break;
1030 1.1 kiyohara if (chan >= sc->sc_gtidmac_nchan)
1031 1.1 kiyohara return -1;
1032 1.1 kiyohara
1033 1.1 kiyohara
1034 1.1 kiyohara sc->sc_cdesc[chan].chan_running = object;
1035 1.1 kiyohara
1036 1.1 kiyohara /* unlock */
1037 1.1 kiyohara
1038 1.1 kiyohara *dmamap_in = &sc->sc_cdesc[chan].chan_in;
1039 1.1 kiyohara *dmamap_out = &sc->sc_cdesc[chan].chan_out;
1040 1.1 kiyohara
1041 1.1 kiyohara return chan;
1042 1.1 kiyohara }
1043 1.1 kiyohara
1044 1.1 kiyohara void
1045 1.1 kiyohara gtidmac_chan_free(void *tag, int chan)
1046 1.1 kiyohara {
1047 1.1 kiyohara struct gtidmac_softc *sc = tag;
1048 1.1 kiyohara
1049 1.1 kiyohara /* maybe need lock */
1050 1.1 kiyohara
1051 1.1 kiyohara sc->sc_cdesc[chan].chan_running = NULL;
1052 1.1 kiyohara
1053 1.1 kiyohara /* unlock */
1054 1.1 kiyohara }
1055 1.1 kiyohara
1056 1.1 kiyohara /* ARGSUSED */
1057 1.1 kiyohara int
1058 1.1 kiyohara gtidmac_setup(void *tag, int chan, int ninputs, bus_dmamap_t *dmamap_in,
1059 1.1 kiyohara bus_dmamap_t *dmamap_out, bus_size_t size)
1060 1.1 kiyohara {
1061 1.1 kiyohara struct gtidmac_softc *sc = tag;
1062 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1063 1.1 kiyohara struct gtidmac_desc *desc;
1064 1.1 kiyohara uint32_t ccl, bcnt, ires, ores;
1065 1.1 kiyohara int n = 0, iidx, oidx;
1066 1.1 kiyohara
1067 1.1 kiyohara KASSERT(ninputs == 0 || ninputs == 1);
1068 1.1 kiyohara
1069 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan));
1070 1.1 kiyohara #ifdef DIAGNOSTIC
1071 1.1 kiyohara if (ccl & GTIDMAC_CCLR_CHANACT)
1072 1.1 kiyohara panic("gtidmac_setup: chan%d already active", chan);
1073 1.1 kiyohara #endif
1074 1.1 kiyohara
1075 1.1 kiyohara /* We always Chain-mode and max (16M - 1)byte/desc */
1076 1.1 kiyohara ccl = (GTIDMAC_CCLR_DESCMODE_16M |
1077 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1078 1.1 kiyohara GTIDMAC_CCLR_CDEN |
1079 1.1 kiyohara #endif
1080 1.1 kiyohara GTIDMAC_CCLR_TRANSFERMODE_B /* Transfer Mode: Block */ |
1081 1.1 kiyohara GTIDMAC_CCLR_INTMODE_NULL /* Intr Mode: Next Desc NULL */ |
1082 1.1 kiyohara GTIDMAC_CCLR_CHAINMODE_C /* Chain Mode: Chaind */);
1083 1.1 kiyohara if (size != (*dmamap_in)->dm_mapsize) {
1084 1.1 kiyohara ccl |= GTIDMAC_CCLR_SRCHOLD;
1085 1.1 kiyohara if ((*dmamap_in)->dm_mapsize == 8)
1086 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_8B;
1087 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 16)
1088 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_16B;
1089 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 32)
1090 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_32B;
1091 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 64)
1092 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_64B;
1093 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 128)
1094 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_128B;
1095 1.1 kiyohara else
1096 1.1 kiyohara panic("gtidmac_setup: chan%d source:"
1097 1.1 kiyohara " unsupport hold size", chan);
1098 1.1 kiyohara } else
1099 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_128B;
1100 1.1 kiyohara if (size != (*dmamap_out)->dm_mapsize) {
1101 1.1 kiyohara ccl |= GTIDMAC_CCLR_DESTHOLD;
1102 1.1 kiyohara if ((*dmamap_out)->dm_mapsize == 8)
1103 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_8B;
1104 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 16)
1105 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_16B;
1106 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 32)
1107 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_32B;
1108 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 64)
1109 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_64B;
1110 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 128)
1111 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_128B;
1112 1.1 kiyohara else
1113 1.1 kiyohara panic("gtidmac_setup: chan%d destination:"
1114 1.1 kiyohara " unsupport hold size", chan);
1115 1.1 kiyohara } else
1116 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_128B;
1117 1.1 kiyohara
1118 1.1 kiyohara fstdd = SLIST_FIRST(&sc->sc_dlist);
1119 1.1 kiyohara if (fstdd == NULL) {
1120 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no descriptor\n");
1121 1.1 kiyohara return ENOMEM;
1122 1.1 kiyohara }
1123 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist, dd_next);
1124 1.1 kiyohara sc->sc_cdesc[chan].chan_ddidx = fstdd->dd_index;
1125 1.1 kiyohara
1126 1.1 kiyohara dd = fstdd;
1127 1.1 kiyohara ires = ores = 0;
1128 1.1 kiyohara iidx = oidx = 0;
1129 1.1 kiyohara while (1 /*CONSTCOND*/) {
1130 1.1 kiyohara if (ccl & GTIDMAC_CCLR_SRCHOLD) {
1131 1.1 kiyohara if (ccl & GTIDMAC_CCLR_DESTHOLD)
1132 1.1 kiyohara bcnt = size; /* src/dst hold */
1133 1.1 kiyohara else
1134 1.1 kiyohara bcnt = (*dmamap_out)->dm_segs[oidx].ds_len;
1135 1.1 kiyohara } else if (ccl & GTIDMAC_CCLR_DESTHOLD)
1136 1.1 kiyohara bcnt = (*dmamap_in)->dm_segs[iidx].ds_len;
1137 1.1 kiyohara else
1138 1.1 kiyohara bcnt = min((*dmamap_in)->dm_segs[iidx].ds_len - ires,
1139 1.1 kiyohara (*dmamap_out)->dm_segs[oidx].ds_len - ores);
1140 1.1 kiyohara
1141 1.1 kiyohara desc = dd->dd_idmac_vaddr;
1142 1.1 kiyohara desc->bc.mode16m.bcnt =
1143 1.1 kiyohara bcnt | GTIDMAC_CIDMABCR_BCLEFT | GTIDMAC_CIDMABCR_OWN;
1144 1.1 kiyohara desc->srcaddr = (*dmamap_in)->dm_segs[iidx].ds_addr + ires;
1145 1.1 kiyohara desc->dstaddr = (*dmamap_out)->dm_segs[oidx].ds_addr + ores;
1146 1.1 kiyohara
1147 1.1 kiyohara n += bcnt;
1148 1.1 kiyohara if (n >= size)
1149 1.1 kiyohara break;
1150 1.1 kiyohara if (!(ccl & GTIDMAC_CCLR_SRCHOLD)) {
1151 1.1 kiyohara ires += bcnt;
1152 1.1 kiyohara if (ires >= (*dmamap_in)->dm_segs[iidx].ds_len) {
1153 1.1 kiyohara ires = 0;
1154 1.1 kiyohara iidx++;
1155 1.1 kiyohara KASSERT(iidx < (*dmamap_in)->dm_nsegs);
1156 1.1 kiyohara }
1157 1.1 kiyohara }
1158 1.1 kiyohara if (!(ccl & GTIDMAC_CCLR_DESTHOLD)) {
1159 1.1 kiyohara ores += bcnt;
1160 1.1 kiyohara if (ores >= (*dmamap_out)->dm_segs[oidx].ds_len) {
1161 1.1 kiyohara ores = 0;
1162 1.1 kiyohara oidx++;
1163 1.1 kiyohara KASSERT(oidx < (*dmamap_out)->dm_nsegs);
1164 1.1 kiyohara }
1165 1.1 kiyohara }
1166 1.1 kiyohara
1167 1.1 kiyohara nxtdd = SLIST_FIRST(&sc->sc_dlist);
1168 1.1 kiyohara if (nxtdd == NULL) {
1169 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no descriptor\n");
1170 1.1 kiyohara return ENOMEM;
1171 1.1 kiyohara }
1172 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist, dd_next);
1173 1.1 kiyohara
1174 1.1 kiyohara desc->nextdp = (uint32_t)nxtdd->dd_paddr;
1175 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1176 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1177 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1178 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1179 1.1 kiyohara #else
1180 1.1 kiyohara BUS_DMASYNC_PREWRITE);
1181 1.1 kiyohara #endif
1182 1.1 kiyohara
1183 1.1 kiyohara SLIST_INSERT_AFTER(dd, nxtdd, dd_next);
1184 1.1 kiyohara dd = nxtdd;
1185 1.1 kiyohara }
1186 1.1 kiyohara desc->nextdp = (uint32_t)NULL;
1187 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap, dd->dd_index * sizeof(*desc),
1188 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1189 1.1 kiyohara sizeof(*desc), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1190 1.1 kiyohara #else
1191 1.1 kiyohara sizeof(*desc), BUS_DMASYNC_PREWRITE);
1192 1.1 kiyohara #endif
1193 1.1 kiyohara
1194 1.1 kiyohara /* Set paddr of descriptor to Channel Next Descriptor Pointer */
1195 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CNDPR(chan),
1196 1.3 kiyohara fstdd->dd_paddr);
1197 1.1 kiyohara
1198 1.1 kiyohara #if BYTE_ORDER == LITTLE_ENDIAN
1199 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCHR(chan),
1200 1.1 kiyohara GTIDMAC_CCHR_DESCBYTESWAP | GTIDMAC_CCHR_ENDIAN_LE);
1201 1.3 kiyohara #else
1202 1.3 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCHR(chan),
1203 1.3 kiyohara GTIDMAC_CCHR_DESCBYTESWAP | GTIDMAC_CCHR_ENDIAN_BE);
1204 1.1 kiyohara #endif
1205 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan), ccl);
1206 1.1 kiyohara
1207 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1208 1.1 kiyohara gtidmac_dump_idmacdesc(sc, fstdd, ccl, 0/*pre*/);
1209 1.1 kiyohara #endif
1210 1.1 kiyohara
1211 1.1 kiyohara sc->sc_cdesc[chan].chan_totalcnt += size;
1212 1.1 kiyohara
1213 1.1 kiyohara return 0;
1214 1.1 kiyohara }
1215 1.1 kiyohara
1216 1.1 kiyohara void
1217 1.1 kiyohara gtidmac_start(void *tag, int chan,
1218 1.1 kiyohara void (*dma_done_cb)(void *, int, bus_dmamap_t *, bus_dmamap_t *,
1219 1.1 kiyohara int))
1220 1.1 kiyohara {
1221 1.1 kiyohara struct gtidmac_softc *sc = tag;
1222 1.1 kiyohara uint32_t ccl;
1223 1.1 kiyohara
1224 1.1 kiyohara DPRINTF(("%s:%d: starting\n", device_xname(sc->sc_dev), chan));
1225 1.1 kiyohara
1226 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1227 1.1 kiyohara gtidmac_dump_idmacreg(sc, chan);
1228 1.1 kiyohara #endif
1229 1.1 kiyohara
1230 1.1 kiyohara sc->sc_cdesc[chan].chan_dma_done = dma_done_cb;
1231 1.1 kiyohara
1232 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan));
1233 1.1 kiyohara /* Start and 'Fetch Next Descriptor' */
1234 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan),
1235 1.1 kiyohara ccl | GTIDMAC_CCLR_CHANEN | GTIDMAC_CCLR_FETCHND);
1236 1.1 kiyohara }
1237 1.1 kiyohara
1238 1.1 kiyohara static uint32_t
1239 1.1 kiyohara gtidmac_finish(void *tag, int chan, int error)
1240 1.1 kiyohara {
1241 1.1 kiyohara struct gtidmac_softc *sc = tag;
1242 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1243 1.1 kiyohara struct gtidmac_desc *desc;
1244 1.1 kiyohara
1245 1.1 kiyohara fstdd = &sc->sc_dd_buffer[sc->sc_cdesc[chan].chan_ddidx];
1246 1.1 kiyohara
1247 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1248 1.1 kiyohara if (error || gtidmac_debug > 1) {
1249 1.1 kiyohara uint32_t ccl;
1250 1.1 kiyohara
1251 1.1 kiyohara gtidmac_dump_idmacreg(sc, chan);
1252 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1253 1.1 kiyohara GTIDMAC_CCLR(chan));
1254 1.1 kiyohara gtidmac_dump_idmacdesc(sc, fstdd, ccl, 1/*post*/);
1255 1.1 kiyohara }
1256 1.1 kiyohara #endif
1257 1.1 kiyohara
1258 1.1 kiyohara dd = fstdd;
1259 1.1 kiyohara do {
1260 1.1 kiyohara desc = dd->dd_idmac_vaddr;
1261 1.1 kiyohara
1262 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1263 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1264 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1265 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1266 1.1 kiyohara #else
1267 1.1 kiyohara BUS_DMASYNC_POSTWRITE);
1268 1.1 kiyohara #endif
1269 1.1 kiyohara
1270 1.1 kiyohara nxtdd = SLIST_NEXT(dd, dd_next);
1271 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist, dd, dd_next);
1272 1.1 kiyohara dd = nxtdd;
1273 1.1 kiyohara } while (desc->nextdp);
1274 1.1 kiyohara
1275 1.1 kiyohara return 0;
1276 1.1 kiyohara }
1277 1.1 kiyohara
1278 1.1 kiyohara /*
1279 1.1 kiyohara * XORE functions
1280 1.1 kiyohara */
1281 1.1 kiyohara int
1282 1.1 kiyohara mvxore_chan_alloc(void *tag, bus_dmamap_t **dmamap_in,
1283 1.1 kiyohara bus_dmamap_t **dmamap_out, void *object)
1284 1.1 kiyohara {
1285 1.1 kiyohara struct gtidmac_softc *sc = tag;
1286 1.1 kiyohara int chan;
1287 1.1 kiyohara
1288 1.1 kiyohara /* maybe need lock */
1289 1.1 kiyohara
1290 1.1 kiyohara for (chan = 0; chan < sc->sc_mvxore_nchan; chan++)
1291 1.1 kiyohara if (sc->sc_cdesc_xore[chan].chan_running == NULL)
1292 1.1 kiyohara break;
1293 1.1 kiyohara if (chan >= sc->sc_mvxore_nchan)
1294 1.1 kiyohara return -1;
1295 1.1 kiyohara
1296 1.1 kiyohara
1297 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running = object;
1298 1.1 kiyohara
1299 1.1 kiyohara /* unlock */
1300 1.1 kiyohara
1301 1.1 kiyohara *dmamap_in = sc->sc_cdesc_xore[chan].chan_in;
1302 1.1 kiyohara *dmamap_out = &sc->sc_cdesc_xore[chan].chan_out;
1303 1.1 kiyohara
1304 1.1 kiyohara return chan;
1305 1.1 kiyohara }
1306 1.1 kiyohara
1307 1.1 kiyohara void
1308 1.1 kiyohara mvxore_chan_free(void *tag, int chan)
1309 1.1 kiyohara {
1310 1.1 kiyohara struct gtidmac_softc *sc = tag;
1311 1.1 kiyohara
1312 1.1 kiyohara /* maybe need lock */
1313 1.1 kiyohara
1314 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running = NULL;
1315 1.1 kiyohara
1316 1.1 kiyohara /* unlock */
1317 1.1 kiyohara }
1318 1.1 kiyohara
1319 1.1 kiyohara /* ARGSUSED */
1320 1.1 kiyohara int
1321 1.1 kiyohara mvxore_setup(void *tag, int chan, int ninputs, bus_dmamap_t *dmamap_in,
1322 1.1 kiyohara bus_dmamap_t *dmamap_out, bus_size_t size)
1323 1.1 kiyohara {
1324 1.1 kiyohara struct gtidmac_softc *sc = tag;
1325 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1326 1.1 kiyohara struct mvxore_desc *desc;
1327 1.1 kiyohara uint32_t xexc, bcnt, cmd, lastcmd;
1328 1.1 kiyohara int n = 0, i;
1329 1.1 kiyohara uint32_t ires[MVXORE_NSRC] = { 0, 0, 0, 0, 0, 0, 0, 0 }, ores = 0;
1330 1.1 kiyohara int iidx[MVXORE_NSRC] = { 0, 0, 0, 0, 0, 0, 0, 0 }, oidx = 0;
1331 1.1 kiyohara
1332 1.1 kiyohara #ifdef DIAGNOSTIC
1333 1.1 kiyohara uint32_t xexact;
1334 1.1 kiyohara
1335 1.1 kiyohara xexact = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1336 1.1 kiyohara if ((xexact & MVXORE_XEXACTR_XESTATUS_MASK) ==
1337 1.1 kiyohara MVXORE_XEXACTR_XESTATUS_ACT)
1338 1.1 kiyohara panic("mvxore_setup: chan%d already active."
1339 1.1 kiyohara " mvxore not support hot insertion", chan);
1340 1.1 kiyohara #endif
1341 1.1 kiyohara
1342 1.1 kiyohara xexc =
1343 1.1 kiyohara (MVXORE_XEXCR_REGACCPROTECT |
1344 1.1 kiyohara MVXORE_XEXCR_DBL_128B |
1345 1.1 kiyohara MVXORE_XEXCR_SBL_128B);
1346 1.1 kiyohara cmd = lastcmd = 0;
1347 1.1 kiyohara if (ninputs > 1) {
1348 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_XOR;
1349 1.1 kiyohara lastcmd = cmd = (1 << ninputs) - 1;
1350 1.1 kiyohara } else if (ninputs == 1) {
1351 1.1 kiyohara if ((*dmamap_out)->dm_nsegs == 0) {
1352 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_CRC32;
1353 1.1 kiyohara lastcmd = MVXORE_DESC_CMD_CRCLAST;
1354 1.1 kiyohara } else
1355 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_DMA;
1356 1.1 kiyohara } else if (ninputs == 0) {
1357 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 1) {
1358 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1359 1.1 kiyohara "XORE not supports %d DMA segments\n",
1360 1.1 kiyohara (*dmamap_out)->dm_nsegs);
1361 1.1 kiyohara return EINVAL;
1362 1.1 kiyohara }
1363 1.1 kiyohara
1364 1.1 kiyohara if ((*dmamap_in)->dm_mapsize == 0) {
1365 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_ECC;
1366 1.1 kiyohara
1367 1.1 kiyohara /* XXXXX: Maybe need to set Timer Mode registers? */
1368 1.1 kiyohara
1369 1.1 kiyohara #if 0
1370 1.1 kiyohara } else if ((*dmamap_in)->dm_mapsize == 8 ||
1371 1.1 kiyohara (*dmamap_in)->dm_mapsize == 16) { /* in case dmover */
1372 1.1 kiyohara uint64_t pattern;
1373 1.1 kiyohara
1374 1.1 kiyohara /* XXXX: Get pattern data */
1375 1.1 kiyohara
1376 1.1 kiyohara KASSERT((*dmamap_in)->dm_mapsize == 8 ||
1377 1.1 kiyohara (void *)((uint32_t)(*dmamap_in)->_dm_origbuf &
1378 1.1 kiyohara ~PAGE_MASK) == sc->sc_pbuf);
1379 1.1 kiyohara pattern = *(uint64_t *)(*dmamap_in)->_dm_origbuf;
1380 1.1 kiyohara
1381 1.1 kiyohara /* XXXXX: XORE has a IVR. We should get this first. */
1382 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIVRL,
1383 1.1 kiyohara pattern);
1384 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIVRH,
1385 1.1 kiyohara pattern >> 32);
1386 1.1 kiyohara
1387 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_MEMINIT;
1388 1.1 kiyohara #endif
1389 1.1 kiyohara } else {
1390 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1391 1.1 kiyohara "XORE not supports DMA mapsize %zd\n",
1392 1.1 kiyohara (*dmamap_in)->dm_mapsize);
1393 1.1 kiyohara return EINVAL;
1394 1.1 kiyohara }
1395 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXDPR(chan),
1396 1.1 kiyohara (*dmamap_out)->dm_segs[0].ds_addr);
1397 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXBSR(chan),
1398 1.1 kiyohara (*dmamap_out)->dm_mapsize);
1399 1.1 kiyohara
1400 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan),
1401 1.1 kiyohara xexc);
1402 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_totalcnt += size;
1403 1.1 kiyohara
1404 1.1 kiyohara return 0;
1405 1.1 kiyohara }
1406 1.1 kiyohara
1407 1.1 kiyohara /* Make descriptor for DMA/CRC32/XOR */
1408 1.1 kiyohara
1409 1.1 kiyohara fstdd = SLIST_FIRST(&sc->sc_dlist_xore);
1410 1.1 kiyohara if (fstdd == NULL) {
1411 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no xore descriptor\n");
1412 1.1 kiyohara return ENOMEM;
1413 1.1 kiyohara }
1414 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist_xore, dd_next);
1415 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_ddidx =
1416 1.1 kiyohara fstdd->dd_index + GTIDMAC_NDESC * sc->sc_gtidmac_nchan;
1417 1.1 kiyohara
1418 1.1 kiyohara dd = fstdd;
1419 1.1 kiyohara while (1 /*CONSTCOND*/) {
1420 1.1 kiyohara desc = dd->dd_xore_vaddr;
1421 1.1 kiyohara desc->stat = MVXORE_DESC_STAT_OWN;
1422 1.1 kiyohara desc->cmd = cmd;
1423 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 0) {
1424 1.1 kiyohara desc->dstaddr =
1425 1.1 kiyohara (*dmamap_out)->dm_segs[oidx].ds_addr + ores;
1426 1.1 kiyohara bcnt = (*dmamap_out)->dm_segs[oidx].ds_len - ores;
1427 1.1 kiyohara } else {
1428 1.1 kiyohara desc->dstaddr = 0;
1429 1.1 kiyohara bcnt = MVXORE_MAXXFER; /* XXXXX */
1430 1.1 kiyohara }
1431 1.1 kiyohara for (i = 0; i < ninputs; i++) {
1432 1.1 kiyohara desc->srcaddr[i] =
1433 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_addr + ires[i];
1434 1.1 kiyohara bcnt = min(bcnt,
1435 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_len - ires[i]);
1436 1.1 kiyohara }
1437 1.1 kiyohara desc->bcnt = bcnt;
1438 1.1 kiyohara
1439 1.1 kiyohara n += bcnt;
1440 1.1 kiyohara if (n >= size)
1441 1.1 kiyohara break;
1442 1.1 kiyohara ores += bcnt;
1443 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 0 &&
1444 1.1 kiyohara ores >= (*dmamap_out)->dm_segs[oidx].ds_len) {
1445 1.1 kiyohara ores = 0;
1446 1.1 kiyohara oidx++;
1447 1.1 kiyohara KASSERT(oidx < (*dmamap_out)->dm_nsegs);
1448 1.1 kiyohara }
1449 1.1 kiyohara for (i = 0; i < ninputs; i++) {
1450 1.1 kiyohara ires[i] += bcnt;
1451 1.1 kiyohara if (ires[i] >=
1452 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_len) {
1453 1.1 kiyohara ires[i] = 0;
1454 1.1 kiyohara iidx[i]++;
1455 1.1 kiyohara KASSERT(iidx[i] < (*dmamap_in[i]).dm_nsegs);
1456 1.1 kiyohara }
1457 1.1 kiyohara }
1458 1.1 kiyohara
1459 1.1 kiyohara nxtdd = SLIST_FIRST(&sc->sc_dlist_xore);
1460 1.1 kiyohara if (nxtdd == NULL) {
1461 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no xore descriptor\n");
1462 1.1 kiyohara return ENOMEM;
1463 1.1 kiyohara }
1464 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist_xore, dd_next);
1465 1.1 kiyohara
1466 1.1 kiyohara desc->nextda = (uint32_t)nxtdd->dd_paddr;
1467 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1468 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1469 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1470 1.1 kiyohara
1471 1.1 kiyohara SLIST_INSERT_AFTER(dd, nxtdd, dd_next);
1472 1.1 kiyohara dd = nxtdd;
1473 1.1 kiyohara }
1474 1.1 kiyohara desc->cmd = lastcmd;
1475 1.1 kiyohara desc->nextda = (uint32_t)NULL;
1476 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1477 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1478 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1479 1.1 kiyohara
1480 1.1 kiyohara /* Set paddr of descriptor to Channel Next Descriptor Pointer */
1481 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXNDPR(chan),
1482 1.1 kiyohara fstdd->dd_paddr);
1483 1.1 kiyohara
1484 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan), xexc);
1485 1.1 kiyohara
1486 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1487 1.3 kiyohara gtidmac_dump_xoredesc(sc, fstdd, xexc, 0/*pre*/);
1488 1.1 kiyohara #endif
1489 1.1 kiyohara
1490 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_totalcnt += size;
1491 1.1 kiyohara
1492 1.1 kiyohara return 0;
1493 1.1 kiyohara }
1494 1.1 kiyohara
1495 1.1 kiyohara void
1496 1.1 kiyohara mvxore_start(void *tag, int chan,
1497 1.1 kiyohara void (*dma_done_cb)(void *, int, bus_dmamap_t *, bus_dmamap_t *,
1498 1.1 kiyohara int))
1499 1.1 kiyohara {
1500 1.1 kiyohara struct gtidmac_softc *sc = tag;
1501 1.1 kiyohara uint32_t xexact;
1502 1.1 kiyohara
1503 1.1 kiyohara DPRINTF(("%s:%d: xore starting\n", device_xname(sc->sc_dev), chan));
1504 1.1 kiyohara
1505 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1506 1.1 kiyohara gtidmac_dump_xorereg(sc, chan);
1507 1.1 kiyohara #endif
1508 1.1 kiyohara
1509 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_dma_done = dma_done_cb;
1510 1.1 kiyohara
1511 1.1 kiyohara xexact = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1512 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan),
1513 1.1 kiyohara xexact | MVXORE_XEXACTR_XESTART);
1514 1.1 kiyohara }
1515 1.1 kiyohara
1516 1.1 kiyohara static uint32_t
1517 1.1 kiyohara mvxore_finish(void *tag, int chan, int error)
1518 1.1 kiyohara {
1519 1.1 kiyohara struct gtidmac_softc *sc = tag;
1520 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1521 1.1 kiyohara struct mvxore_desc *desc;
1522 1.1 kiyohara uint32_t xexc;
1523 1.1 kiyohara
1524 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1525 1.1 kiyohara if (error || gtidmac_debug > 1)
1526 1.1 kiyohara gtidmac_dump_xorereg(sc, chan);
1527 1.1 kiyohara #endif
1528 1.1 kiyohara
1529 1.1 kiyohara xexc = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan));
1530 1.1 kiyohara if ((xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_ECC ||
1531 1.1 kiyohara (xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_MEMINIT)
1532 1.1 kiyohara return 0;
1533 1.1 kiyohara
1534 1.1 kiyohara fstdd = &sc->sc_dd_buffer[sc->sc_cdesc_xore[chan].chan_ddidx];
1535 1.1 kiyohara
1536 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1537 1.1 kiyohara if (error || gtidmac_debug > 1)
1538 1.1 kiyohara gtidmac_dump_xoredesc(sc, fstdd, xexc, 1/*post*/);
1539 1.1 kiyohara #endif
1540 1.1 kiyohara
1541 1.1 kiyohara dd = fstdd;
1542 1.1 kiyohara do {
1543 1.1 kiyohara desc = dd->dd_xore_vaddr;
1544 1.1 kiyohara
1545 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1546 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1547 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1548 1.1 kiyohara
1549 1.1 kiyohara nxtdd = SLIST_NEXT(dd, dd_next);
1550 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist_xore, dd, dd_next);
1551 1.1 kiyohara dd = nxtdd;
1552 1.1 kiyohara } while (desc->nextda);
1553 1.1 kiyohara
1554 1.1 kiyohara if ((xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_CRC32)
1555 1.1 kiyohara return desc->result;
1556 1.1 kiyohara return 0;
1557 1.1 kiyohara }
1558 1.1 kiyohara
1559 1.1 kiyohara static void
1560 1.1 kiyohara gtidmac_wininit(struct gtidmac_softc *sc)
1561 1.1 kiyohara {
1562 1.1 kiyohara device_t pdev = device_parent(sc->sc_dev);
1563 1.1 kiyohara uint64_t base;
1564 1.1 kiyohara uint32_t size, cxap, en;
1565 1.1 kiyohara int window, target, attr, rv, i;
1566 1.1 kiyohara struct {
1567 1.1 kiyohara int tag;
1568 1.1 kiyohara int winacc;
1569 1.1 kiyohara } targets[] = {
1570 1.1 kiyohara { MARVELL_TAG_SDRAM_CS0, GTIDMAC_CXAPR_WINACC_FA },
1571 1.1 kiyohara { MARVELL_TAG_SDRAM_CS1, GTIDMAC_CXAPR_WINACC_FA },
1572 1.1 kiyohara { MARVELL_TAG_SDRAM_CS2, GTIDMAC_CXAPR_WINACC_FA },
1573 1.1 kiyohara { MARVELL_TAG_SDRAM_CS3, GTIDMAC_CXAPR_WINACC_FA },
1574 1.1 kiyohara
1575 1.1 kiyohara /* Also can set following targets. */
1576 1.1 kiyohara /* Devices = 0x1(ORION_TARGETID_DEVICE_*) */
1577 1.1 kiyohara /* PCI = 0x3(ORION_TARGETID_PCI0_*) */
1578 1.1 kiyohara /* PCI Express = 0x4(ORION_TARGETID_PEX?_*) */
1579 1.1 kiyohara /* Tunit SRAM(?) = 0x5(???) */
1580 1.1 kiyohara
1581 1.1 kiyohara { MARVELL_TAG_UNDEFINED, GTIDMAC_CXAPR_WINACC_NOAA }
1582 1.1 kiyohara };
1583 1.1 kiyohara
1584 1.1 kiyohara en = 0xff;
1585 1.1 kiyohara cxap = 0;
1586 1.1 kiyohara for (window = 0, i = 0;
1587 1.1 kiyohara targets[i].tag != MARVELL_TAG_UNDEFINED && window < GTIDMAC_NWINDOW;
1588 1.1 kiyohara i++) {
1589 1.1 kiyohara rv = marvell_winparams_by_tag(pdev, targets[i].tag,
1590 1.1 kiyohara &target, &attr, &base, &size);
1591 1.1 kiyohara if (rv != 0 || size == 0)
1592 1.1 kiyohara continue;
1593 1.1 kiyohara
1594 1.1 kiyohara if (base > 0xffffffffULL) {
1595 1.1 kiyohara if (window >= GTIDMAC_NREMAP) {
1596 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1597 1.1 kiyohara "can't remap window %d\n", window);
1598 1.1 kiyohara continue;
1599 1.1 kiyohara }
1600 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1601 1.1 kiyohara GTIDMAC_HARXR(window), (base >> 32) & 0xffffffff);
1602 1.1 kiyohara }
1603 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_BARX(window),
1604 1.1 kiyohara GTIDMAC_BARX_TARGET(target) |
1605 1.1 kiyohara GTIDMAC_BARX_ATTR(attr) |
1606 1.1 kiyohara GTIDMAC_BARX_BASE(base));
1607 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_SRX(window),
1608 1.1 kiyohara GTIDMAC_SRX_SIZE(size));
1609 1.1 kiyohara en &= ~GTIDMAC_BAER_EN(window);
1610 1.1 kiyohara cxap |= GTIDMAC_CXAPR_WINACC(window, targets[i].winacc);
1611 1.1 kiyohara window++;
1612 1.1 kiyohara }
1613 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_BAER, en);
1614 1.1 kiyohara
1615 1.1 kiyohara for (i = 0; i < GTIDMAC_NACCPROT; i++)
1616 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CXAPR(i),
1617 1.1 kiyohara cxap);
1618 1.1 kiyohara }
1619 1.1 kiyohara
1620 1.1 kiyohara static void
1621 1.1 kiyohara mvxore_wininit(struct gtidmac_softc *sc)
1622 1.1 kiyohara {
1623 1.1 kiyohara device_t pdev = device_parent(sc->sc_dev);
1624 1.1 kiyohara uint64_t base;
1625 1.1 kiyohara uint32_t target, attr, size, xexwc;
1626 1.1 kiyohara int window, rv, i;
1627 1.1 kiyohara struct {
1628 1.1 kiyohara int tag;
1629 1.1 kiyohara int winacc;
1630 1.1 kiyohara } targets[] = {
1631 1.1 kiyohara { MARVELL_TAG_SDRAM_CS0, MVXORE_XEXWCR_WINACC_FA },
1632 1.1 kiyohara { MARVELL_TAG_SDRAM_CS1, MVXORE_XEXWCR_WINACC_FA },
1633 1.1 kiyohara { MARVELL_TAG_SDRAM_CS2, MVXORE_XEXWCR_WINACC_FA },
1634 1.1 kiyohara { MARVELL_TAG_SDRAM_CS3, MVXORE_XEXWCR_WINACC_FA },
1635 1.1 kiyohara
1636 1.1 kiyohara { MARVELL_TAG_UNDEFINED, MVXORE_XEXWCR_WINACC_NOAA }
1637 1.1 kiyohara };
1638 1.1 kiyohara
1639 1.1 kiyohara xexwc = 0;
1640 1.1 kiyohara for (window = 0, i = 0;
1641 1.1 kiyohara targets[i].tag != MARVELL_TAG_UNDEFINED && window < MVXORE_NWINDOW;
1642 1.1 kiyohara i++) {
1643 1.1 kiyohara rv = marvell_winparams_by_tag(pdev, targets[i].tag,
1644 1.1 kiyohara &target, &attr, &base, &size);
1645 1.1 kiyohara if (rv != 0 || size == 0)
1646 1.1 kiyohara continue;
1647 1.1 kiyohara
1648 1.1 kiyohara if (base > 0xffffffffULL) {
1649 1.1 kiyohara if (window >= MVXORE_NREMAP) {
1650 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1651 1.1 kiyohara "can't remap window %d\n", window);
1652 1.1 kiyohara continue;
1653 1.1 kiyohara }
1654 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1655 1.1 kiyohara MVXORE_XEHARRX(window), (base >> 32) & 0xffffffff);
1656 1.1 kiyohara }
1657 1.1 kiyohara
1658 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEBARX(window),
1659 1.1 kiyohara MVXORE_XEBARX_TARGET(target) |
1660 1.1 kiyohara MVXORE_XEBARX_ATTR(attr) |
1661 1.1 kiyohara MVXORE_XEBARX_BASE(base));
1662 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1663 1.1 kiyohara MVXORE_XESMRX(window), MVXORE_XESMRX_SIZE(size));
1664 1.1 kiyohara xexwc |= (MVXORE_XEXWCR_WINEN(window) |
1665 1.1 kiyohara MVXORE_XEXWCR_WINACC(window, targets[i].winacc));
1666 1.1 kiyohara window++;
1667 1.1 kiyohara }
1668 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXWCR(0), xexwc);
1669 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXWCR(1), xexwc);
1670 1.1 kiyohara
1671 1.1 kiyohara /* XXXXX: reset... */
1672 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXAOCR(0), 0);
1673 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXAOCR(1), 0);
1674 1.1 kiyohara }
1675 1.1 kiyohara
1676 1.1 kiyohara
1677 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1678 1.1 kiyohara static void
1679 1.1 kiyohara gtidmac_dump_idmacreg(struct gtidmac_softc *sc, int chan)
1680 1.1 kiyohara {
1681 1.1 kiyohara uint32_t val;
1682 1.1 kiyohara char buf[256];
1683 1.1 kiyohara
1684 1.1 kiyohara printf("IDMAC Registers\n");
1685 1.1 kiyohara
1686 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CIDMABCR(chan));
1687 1.3 kiyohara snprintb(buf, sizeof(buf), "\177\020b\037Own\0b\036BCLeft\0", val);
1688 1.3 kiyohara printf(" Byte Count : %s\n", buf);
1689 1.1 kiyohara printf(" ByteCnt : 0x%06x\n",
1690 1.1 kiyohara val & GTIDMAC_CIDMABCR_BYTECNT_MASK);
1691 1.1 kiyohara printf(" Source Address : 0x%08x\n",
1692 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CIDMASAR(chan)));
1693 1.1 kiyohara printf(" Destination Address : 0x%08x\n",
1694 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CIDMADAR(chan)));
1695 1.1 kiyohara printf(" Next Descriptor Pointer : 0x%08x\n",
1696 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CNDPR(chan)));
1697 1.1 kiyohara printf(" Current Descriptor Pointer : 0x%08x\n",
1698 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCDPR(chan)));
1699 1.1 kiyohara
1700 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan));
1701 1.3 kiyohara snprintb(buf, sizeof(buf),
1702 1.1 kiyohara "\177\020b\024Abr\0b\021CDEn\0b\016ChanAct\0b\015FetchND\0"
1703 1.1 kiyohara "b\014ChanEn\0b\012IntMode\0b\005DestHold\0b\003SrcHold\0",
1704 1.3 kiyohara val);
1705 1.3 kiyohara printf(" Channel Control (Low) : %s\n", buf);
1706 1.1 kiyohara printf(" SrcBurstLimit : %s Bytes\n",
1707 1.1 kiyohara (val & GTIDMAC_CCLR_SBL_MASK) == GTIDMAC_CCLR_SBL_128B ? "128" :
1708 1.1 kiyohara (val & GTIDMAC_CCLR_SBL_MASK) == GTIDMAC_CCLR_SBL_64B ? "64" :
1709 1.1 kiyohara (val & GTIDMAC_CCLR_SBL_MASK) == GTIDMAC_CCLR_SBL_32B ? "32" :
1710 1.1 kiyohara (val & GTIDMAC_CCLR_SBL_MASK) == GTIDMAC_CCLR_SBL_16B ? "16" :
1711 1.1 kiyohara (val & GTIDMAC_CCLR_SBL_MASK) == GTIDMAC_CCLR_SBL_8B ? "8" :
1712 1.1 kiyohara "unknwon");
1713 1.1 kiyohara printf(" DstBurstLimit : %s Bytes\n",
1714 1.1 kiyohara (val & GTIDMAC_CCLR_DBL_MASK) == GTIDMAC_CCLR_DBL_128B ? "128" :
1715 1.1 kiyohara (val & GTIDMAC_CCLR_DBL_MASK) == GTIDMAC_CCLR_DBL_64B ? "64" :
1716 1.1 kiyohara (val & GTIDMAC_CCLR_DBL_MASK) == GTIDMAC_CCLR_DBL_32B ? "32" :
1717 1.1 kiyohara (val & GTIDMAC_CCLR_DBL_MASK) == GTIDMAC_CCLR_DBL_16B ? "16" :
1718 1.1 kiyohara (val & GTIDMAC_CCLR_DBL_MASK) == GTIDMAC_CCLR_DBL_8B ? "8" :
1719 1.1 kiyohara "unknwon");
1720 1.1 kiyohara printf(" ChainMode : %sChained\n",
1721 1.1 kiyohara val & GTIDMAC_CCLR_CHAINMODE_NC ? "Non-" : "");
1722 1.1 kiyohara printf(" TransferMode : %s\n",
1723 1.1 kiyohara val & GTIDMAC_CCLR_TRANSFERMODE_B ? "Block" : "Demand");
1724 1.1 kiyohara printf(" DescMode : %s\n",
1725 1.1 kiyohara val & GTIDMAC_CCLR_DESCMODE_16M ? "16M" : "64k");
1726 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCHR(chan));
1727 1.3 kiyohara snprintb(buf, sizeof(buf),
1728 1.3 kiyohara "\177\020b\001DescByteSwap\0b\000Endianness\0", val);
1729 1.3 kiyohara printf(" Channel Control (High) : %s\n", buf);
1730 1.1 kiyohara }
1731 1.1 kiyohara
1732 1.1 kiyohara static void
1733 1.1 kiyohara gtidmac_dump_idmacdesc(struct gtidmac_softc *sc, struct gtidmac_dma_desc *dd,
1734 1.1 kiyohara uint32_t mode, int post)
1735 1.1 kiyohara {
1736 1.1 kiyohara struct gtidmac_desc *desc;
1737 1.1 kiyohara int i;
1738 1.1 kiyohara char buf[256];
1739 1.1 kiyohara
1740 1.1 kiyohara printf("IDMAC Descriptor\n");
1741 1.1 kiyohara
1742 1.1 kiyohara i = 0;
1743 1.1 kiyohara while (1 /*CONSTCOND*/) {
1744 1.1 kiyohara if (post)
1745 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1746 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1747 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1748 1.1 kiyohara
1749 1.1 kiyohara desc = dd->dd_idmac_vaddr;
1750 1.1 kiyohara
1751 1.1 kiyohara printf("%d (0x%lx)\n", i, dd->dd_paddr);
1752 1.1 kiyohara if (mode & GTIDMAC_CCLR_DESCMODE_16M) {
1753 1.3 kiyohara snprintb(buf, sizeof(buf),
1754 1.1 kiyohara "\177\020b\037Own\0b\036BCLeft\0",
1755 1.3 kiyohara desc->bc.mode16m.bcnt);
1756 1.3 kiyohara printf(" Byte Count : %s\n", buf);
1757 1.1 kiyohara printf(" ByteCount : 0x%06x\n",
1758 1.1 kiyohara desc->bc.mode16m.bcnt &
1759 1.1 kiyohara GTIDMAC_CIDMABCR_BYTECNT_MASK);
1760 1.1 kiyohara } else {
1761 1.1 kiyohara printf(" Byte Count : 0x%04x\n",
1762 1.1 kiyohara desc->bc.mode64k.bcnt);
1763 1.1 kiyohara printf(" Remind Byte Count : 0x%04x\n",
1764 1.1 kiyohara desc->bc.mode64k.rbc);
1765 1.1 kiyohara }
1766 1.1 kiyohara printf(" Source Address : 0x%08x\n", desc->srcaddr);
1767 1.1 kiyohara printf(" Destination Address : 0x%08x\n", desc->dstaddr);
1768 1.1 kiyohara printf(" Next Descriptor Pointer : 0x%08x\n", desc->nextdp);
1769 1.1 kiyohara
1770 1.1 kiyohara if (desc->nextdp == (uint32_t)NULL)
1771 1.1 kiyohara break;
1772 1.1 kiyohara
1773 1.1 kiyohara if (!post)
1774 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1775 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1776 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1777 1.1 kiyohara
1778 1.1 kiyohara i++;
1779 1.1 kiyohara dd = SLIST_NEXT(dd, dd_next);
1780 1.1 kiyohara }
1781 1.1 kiyohara if (!post)
1782 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1783 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1784 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1785 1.1 kiyohara }
1786 1.1 kiyohara
1787 1.1 kiyohara static void
1788 1.1 kiyohara gtidmac_dump_xorereg(struct gtidmac_softc *sc, int chan)
1789 1.1 kiyohara {
1790 1.1 kiyohara uint32_t val, opmode;
1791 1.1 kiyohara char buf[64];
1792 1.1 kiyohara
1793 1.1 kiyohara printf("XORE Registers\n");
1794 1.1 kiyohara
1795 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan));
1796 1.3 kiyohara snprintb(buf, sizeof(buf),
1797 1.3 kiyohara "\177\020"
1798 1.1 kiyohara "b\017RegAccProtect\0b\016DesSwp\0b\015DwrReqSwp\0b\014DrdResSwp\0",
1799 1.3 kiyohara val);
1800 1.1 kiyohara printf(" Configuration : 0x%s\n", buf);
1801 1.1 kiyohara opmode = val & MVXORE_XEXCR_OM_MASK;
1802 1.1 kiyohara printf(" OperationMode : %s operation\n",
1803 1.1 kiyohara opmode == MVXORE_XEXCR_OM_XOR ? "XOR calculate" :
1804 1.1 kiyohara opmode == MVXORE_XEXCR_OM_CRC32 ? "CRC-32 calculate" :
1805 1.1 kiyohara opmode == MVXORE_XEXCR_OM_DMA ? "DMA" :
1806 1.1 kiyohara opmode == MVXORE_XEXCR_OM_ECC ? "ECC cleanup" :
1807 1.1 kiyohara opmode == MVXORE_XEXCR_OM_MEMINIT ? "Memory Initialization" :
1808 1.1 kiyohara "unknown");
1809 1.1 kiyohara printf(" SrcBurstLimit : %s Bytes\n",
1810 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_128B ? "128" :
1811 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_64B ? "64" :
1812 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_32B ? "32" :
1813 1.1 kiyohara "unknwon");
1814 1.1 kiyohara printf(" DstBurstLimit : %s Bytes\n",
1815 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_128B ? "128" :
1816 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_64B ? "64" :
1817 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_32B ? "32" :
1818 1.1 kiyohara "unknwon");
1819 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1820 1.1 kiyohara printf(" Activation : 0x%08x\n", val);
1821 1.1 kiyohara val &= MVXORE_XEXACTR_XESTATUS_MASK;
1822 1.1 kiyohara printf(" XEstatus : %s\n",
1823 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_NA ? "Channel not active" :
1824 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_ACT ? "Channel active" :
1825 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_P ? "Channel paused" : "???");
1826 1.1 kiyohara
1827 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_XOR ||
1828 1.1 kiyohara opmode == MVXORE_XEXCR_OM_CRC32 ||
1829 1.1 kiyohara opmode == MVXORE_XEXCR_OM_DMA) {
1830 1.1 kiyohara printf(" NextDescPtr : 0x%08x\n",
1831 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1832 1.1 kiyohara MVXORE_XEXNDPR(chan)));
1833 1.1 kiyohara printf(" CurrentDescPtr : 0x%08x\n",
1834 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1835 1.1 kiyohara MVXORE_XEXCDPR(chan)));
1836 1.1 kiyohara }
1837 1.1 kiyohara printf(" ByteCnt : 0x%08x\n",
1838 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXBCR(chan)));
1839 1.1 kiyohara
1840 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_ECC ||
1841 1.1 kiyohara opmode == MVXORE_XEXCR_OM_MEMINIT) {
1842 1.1 kiyohara printf(" DstPtr : 0x%08x\n",
1843 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1844 1.1 kiyohara MVXORE_XEXDPR(chan)));
1845 1.1 kiyohara printf(" BlockSize : 0x%08x\n",
1846 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1847 1.1 kiyohara MVXORE_XEXBSR(chan)));
1848 1.1 kiyohara
1849 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_ECC) {
1850 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1851 1.1 kiyohara MVXORE_XETMCR);
1852 1.1 kiyohara if (val & MVXORE_XETMCR_TIMEREN) {
1853 1.1 kiyohara val >>= MVXORE_XETMCR_SECTIONSIZECTRL_SHIFT;
1854 1.1 kiyohara val &= MVXORE_XETMCR_SECTIONSIZECTRL_MASK;
1855 1.1 kiyohara printf(" SectionSizeCtrl : 0x%08x\n", 2 ^ val);
1856 1.1 kiyohara printf(" TimerInitVal : 0x%08x\n",
1857 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1858 1.1 kiyohara MVXORE_XETMIVR));
1859 1.1 kiyohara printf(" TimerCrntVal : 0x%08x\n",
1860 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1861 1.1 kiyohara MVXORE_XETMCVR));
1862 1.1 kiyohara }
1863 1.1 kiyohara } else /* MVXORE_XEXCR_OM_MEMINIT */
1864 1.1 kiyohara printf(" InitVal : 0x%08x%08x\n",
1865 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1866 1.1 kiyohara MVXORE_XEIVRH),
1867 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1868 1.1 kiyohara MVXORE_XEIVRL));
1869 1.1 kiyohara }
1870 1.1 kiyohara }
1871 1.1 kiyohara
1872 1.1 kiyohara static void
1873 1.1 kiyohara gtidmac_dump_xoredesc(struct gtidmac_softc *sc, struct gtidmac_dma_desc *dd,
1874 1.1 kiyohara uint32_t mode, int post)
1875 1.1 kiyohara {
1876 1.3 kiyohara struct mvxore_desc *desc;
1877 1.1 kiyohara int i, j;
1878 1.1 kiyohara char buf[256];
1879 1.1 kiyohara
1880 1.1 kiyohara printf("XORE Descriptor\n");
1881 1.1 kiyohara
1882 1.1 kiyohara mode &= MVXORE_XEXCR_OM_MASK;
1883 1.1 kiyohara
1884 1.1 kiyohara i = 0;
1885 1.1 kiyohara while (1 /*CONSTCOND*/) {
1886 1.1 kiyohara if (post)
1887 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1888 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1889 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1890 1.1 kiyohara
1891 1.1 kiyohara desc = dd->dd_xore_vaddr;
1892 1.1 kiyohara
1893 1.1 kiyohara printf("%d (0x%lx)\n", i, dd->dd_paddr);
1894 1.1 kiyohara
1895 1.3 kiyohara snprintb(buf, sizeof(buf), "\177\020b\037Own\0b\036Success\0",
1896 1.3 kiyohara desc->stat);
1897 1.1 kiyohara printf(" Status : 0x%s\n", buf);
1898 1.1 kiyohara if (desc->cmd & MVXORE_DESC_CMD_CRCLAST && post)
1899 1.1 kiyohara printf(" CRC-32 Result : 0x%08x\n",
1900 1.1 kiyohara desc->result);
1901 1.3 kiyohara snprintb(buf, sizeof(buf),
1902 1.1 kiyohara "\177\020b\037EODIntEn\0b\036CRCLast\0"
1903 1.1 kiyohara "b\007Src7Cmd\0b\006Src6Cmd\0b\005Src5Cmd\0b\004Src4Cmd\0"
1904 1.1 kiyohara "b\003Src3Cmd\0b\002Src2Cmd\0b\001Src1Cmd\0b\000Src0Cmd\0",
1905 1.3 kiyohara desc->cmd);
1906 1.1 kiyohara printf(" Command : 0x%s\n", buf);
1907 1.1 kiyohara printf(" Next Descriptor Address : 0x%08x\n", desc->nextda);
1908 1.1 kiyohara printf(" Byte Count : 0x%06x\n", desc->bcnt);
1909 1.1 kiyohara printf(" Destination Address : 0x%08x\n", desc->dstaddr);
1910 1.1 kiyohara if (mode == MVXORE_XEXCR_OM_XOR) {
1911 1.1 kiyohara for (j = 0; j < MVXORE_NSRC; j++)
1912 1.1 kiyohara if (desc->cmd & MVXORE_DESC_CMD_SRCCMD(j))
1913 1.1 kiyohara printf(" Source Address#%d :"
1914 1.1 kiyohara " 0x%08x\n", j, desc->srcaddr[j]);
1915 1.1 kiyohara } else
1916 1.1 kiyohara printf(" Source Address : 0x%08x\n",
1917 1.1 kiyohara desc->srcaddr[0]);
1918 1.1 kiyohara
1919 1.1 kiyohara if (desc->nextda == (uint32_t)NULL)
1920 1.1 kiyohara break;
1921 1.1 kiyohara
1922 1.1 kiyohara if (!post)
1923 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1924 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1925 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1926 1.1 kiyohara
1927 1.1 kiyohara i++;
1928 1.1 kiyohara dd = SLIST_NEXT(dd, dd_next);
1929 1.1 kiyohara }
1930 1.1 kiyohara if (!post)
1931 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1932 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1933 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1934 1.1 kiyohara }
1935 1.1 kiyohara #endif
1936