gtidmac.c revision 1.2 1 1.2 kiyohara /* $NetBSD: gtidmac.c,v 1.2 2010/06/02 06:05:32 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.2 kiyohara __KERNEL_RCSID(0, "$NetBSD: gtidmac.c,v 1.2 2010/06/02 06:05:32 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.1 kiyohara if (mva->mva_offset == GTCF_OFFSET_DEFAULT ||
293 1.1 kiyohara mva->mva_irq == GTCF_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 #if 0
320 1.1 kiyohara case MARVELL_DISCOVERY_V: ????
321 1.1 kiyohara #endif
322 1.1 kiyohara break;
323 1.1 kiyohara
324 1.1 kiyohara #if 0
325 1.1 kiyohara case MARVELL_DISCOVERY_LT: ????
326 1.1 kiyohara case MARVELL_DISCOVERY_VI: ????
327 1.1 kiyohara #endif
328 1.1 kiyohara case MARVELL_ORION_1_88F1181:
329 1.1 kiyohara case MARVELL_ORION_1_88F5082:
330 1.1 kiyohara case MARVELL_ORION_1_88F5180N:
331 1.1 kiyohara case MARVELL_ORION_1_88F5181:
332 1.1 kiyohara case MARVELL_ORION_1_88W8660:
333 1.1 kiyohara case MARVELL_ORION_2_88F1281:
334 1.1 kiyohara case MARVELL_ORION_2_88F5281:
335 1.1 kiyohara idmac_nchan = 4;
336 1.1 kiyohara break;
337 1.1 kiyohara
338 1.1 kiyohara case MARVELL_ORION_1_88F5182:
339 1.1 kiyohara idmac_nchan = 4;
340 1.1 kiyohara xore_nchan = 2;
341 1.1 kiyohara break;
342 1.1 kiyohara }
343 1.1 kiyohara if (xore_nchan != 0)
344 1.1 kiyohara if (!prop_dictionary_get_uint32(dict, "xore-irq-begin",
345 1.1 kiyohara &xore_irq)) {
346 1.1 kiyohara aprint_error(": no xore-irq-begin property\n");
347 1.1 kiyohara return;
348 1.1 kiyohara }
349 1.1 kiyohara
350 1.1 kiyohara aprint_naive("\n");
351 1.1 kiyohara aprint_normal(": Marvell IDMA Controller%s\n",
352 1.1 kiyohara xore_nchan ? "/XOR Engine" : "");
353 1.1 kiyohara
354 1.1 kiyohara sc->sc_dev = self;
355 1.1 kiyohara sc->sc_iot = mva->mva_iot;
356 1.1 kiyohara
357 1.1 kiyohara /* Map I/O registers */
358 1.1 kiyohara if (bus_space_subregion(mva->mva_iot, mva->mva_ioh, mva->mva_offset,
359 1.1 kiyohara mva->mva_size, &sc->sc_ioh)) {
360 1.1 kiyohara aprint_error_dev(self, "can't map registers\n");
361 1.1 kiyohara return;
362 1.1 kiyohara }
363 1.1 kiyohara
364 1.1 kiyohara /*
365 1.1 kiyohara * Initialise DMA descriptors and associated metadata
366 1.1 kiyohara */
367 1.1 kiyohara sc->sc_dmat = mva->mva_dmat;
368 1.1 kiyohara n = idmac_nchan * GTIDMAC_NDESC + xore_nchan * MVXORE_NDESC;
369 1.1 kiyohara sc->sc_dd_buffer =
370 1.2 kiyohara kmem_alloc(sizeof(struct gtidmac_dma_desc) * n, KM_SLEEP);
371 1.1 kiyohara if (sc->sc_dd_buffer == NULL) {
372 1.1 kiyohara aprint_error_dev(self, "can't allocate memory\n");
373 1.1 kiyohara goto fail1;
374 1.1 kiyohara }
375 1.1 kiyohara /* pattern buffer */
376 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
377 1.1 kiyohara &sc->sc_pattern_segment, 1, &nsegs, BUS_DMA_NOWAIT)) {
378 1.1 kiyohara aprint_error_dev(self,
379 1.1 kiyohara "bus_dmamem_alloc failed: pattern buffer\n");
380 1.1 kiyohara goto fail2;
381 1.1 kiyohara }
382 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &sc->sc_pattern_segment, 1, PAGE_SIZE,
383 1.1 kiyohara (void **)&sc->sc_pbuf, BUS_DMA_NOWAIT)) {
384 1.1 kiyohara aprint_error_dev(self,
385 1.1 kiyohara "bus_dmamem_map failed: pattern buffer\n");
386 1.1 kiyohara goto fail3;
387 1.1 kiyohara }
388 1.1 kiyohara for (i = 0; i < 0x100; i++)
389 1.1 kiyohara for (j = 0; j < sizeof(sc->sc_pbuf[i].pbuf); j++)
390 1.1 kiyohara sc->sc_pbuf[i].pbuf[j] = i;
391 1.1 kiyohara
392 1.1 kiyohara /* IDMAC DMA descriptor buffer */
393 1.1 kiyohara sc->sc_gtidmac_nchan = idmac_nchan;
394 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat,
395 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan,
396 1.1 kiyohara PAGE_SIZE, 0, &segs, 1, &nsegs, BUS_DMA_NOWAIT)) {
397 1.1 kiyohara aprint_error_dev(self,
398 1.1 kiyohara "bus_dmamem_alloc failed: descriptor buffer\n");
399 1.1 kiyohara goto fail4;
400 1.1 kiyohara }
401 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &segs, 1,
402 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan,
403 1.1 kiyohara (void **)&sc->sc_dbuf, BUS_DMA_NOWAIT)) {
404 1.1 kiyohara aprint_error_dev(self,
405 1.1 kiyohara "bus_dmamem_map failed: descriptor buffer\n");
406 1.1 kiyohara goto fail5;
407 1.1 kiyohara }
408 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
409 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, 1,
410 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, 0,
411 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_dmap)) {
412 1.1 kiyohara aprint_error_dev(self,
413 1.1 kiyohara "bus_dmamap_create failed: descriptor buffer\n");
414 1.1 kiyohara goto fail6;
415 1.1 kiyohara }
416 1.1 kiyohara if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmap, sc->sc_dbuf,
417 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC * idmac_nchan, NULL,
418 1.1 kiyohara BUS_DMA_NOWAIT)) {
419 1.1 kiyohara aprint_error_dev(self,
420 1.1 kiyohara "bus_dmamap_load failed: descriptor buffer\n");
421 1.1 kiyohara goto fail7;
422 1.1 kiyohara }
423 1.1 kiyohara SLIST_INIT(&sc->sc_dlist);
424 1.1 kiyohara for (i = 0; i < GTIDMAC_NDESC * idmac_nchan; i++) {
425 1.1 kiyohara dd = &sc->sc_dd_buffer[i];
426 1.1 kiyohara dd->dd_index = i;
427 1.1 kiyohara dd->dd_idmac_vaddr = &sc->sc_dbuf[i];
428 1.1 kiyohara dd->dd_paddr = sc->sc_dmap->dm_segs[0].ds_addr +
429 1.1 kiyohara (sizeof(struct gtidmac_desc) * i);
430 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist, dd, dd_next);
431 1.1 kiyohara }
432 1.1 kiyohara
433 1.1 kiyohara /* Initialize IDMAC DMA channels */
434 1.1 kiyohara mask = 0;
435 1.1 kiyohara for (i = 0; i < idmac_nchan; i++) {
436 1.1 kiyohara if (i > 0 &&
437 1.1 kiyohara ((i * GTIDMAC_I_BITS) & 31 /*bit*/) == 0) {
438 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
439 1.1 kiyohara GTIDMAC_IMR(i - 1), mask);
440 1.1 kiyohara mask = 0;
441 1.1 kiyohara }
442 1.1 kiyohara
443 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, GTIDMAC_MAXXFER,
444 1.1 kiyohara GTIDMAC_NSEGS, GTIDMAC_MAXXFER, 0, BUS_DMA_NOWAIT,
445 1.1 kiyohara &sc->sc_cdesc[i].chan_in)) {
446 1.1 kiyohara aprint_error_dev(self,
447 1.1 kiyohara "bus_dmamap_create failed: chan%d in\n", i);
448 1.1 kiyohara goto fail8;
449 1.1 kiyohara }
450 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, GTIDMAC_MAXXFER,
451 1.1 kiyohara GTIDMAC_NSEGS, GTIDMAC_MAXXFER, 0, BUS_DMA_NOWAIT,
452 1.1 kiyohara &sc->sc_cdesc[i].chan_out)) {
453 1.1 kiyohara aprint_error_dev(self,
454 1.1 kiyohara "bus_dmamap_create failed: chan%d out\n", i);
455 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat,
456 1.1 kiyohara sc->sc_cdesc[i].chan_in);
457 1.1 kiyohara goto fail8;
458 1.1 kiyohara }
459 1.1 kiyohara sc->sc_cdesc[i].chan_totalcnt = 0;
460 1.1 kiyohara sc->sc_cdesc[i].chan_running = NULL;
461 1.1 kiyohara
462 1.1 kiyohara /* Ignore bits overflow. The mask is 32bit. */
463 1.1 kiyohara mask |= GTIDMAC_I(i,
464 1.1 kiyohara GTIDMAC_I_COMP |
465 1.1 kiyohara GTIDMAC_I_ADDRMISS |
466 1.1 kiyohara GTIDMAC_I_ACCPROT |
467 1.1 kiyohara GTIDMAC_I_WRPROT |
468 1.1 kiyohara GTIDMAC_I_OWN);
469 1.1 kiyohara }
470 1.1 kiyohara if (i > 0)
471 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_IMR(i - 1),
472 1.1 kiyohara mask);
473 1.1 kiyohara
474 1.1 kiyohara /* Setup interrupt */
475 1.1 kiyohara for (j = 0; j < GTIDMAC_NINTRRUPT; j++) {
476 1.1 kiyohara int c = j * idmac_nchan / __arraycount(sc->sc_intrarg);
477 1.1 kiyohara
478 1.1 kiyohara sc->sc_intrarg[j].ia_sc = sc;
479 1.1 kiyohara sc->sc_intrarg[j].ia_cause = GTIDMAC_ICR(c);
480 1.1 kiyohara sc->sc_intrarg[j].ia_eaddr = GTIDMAC_EAR(c);
481 1.1 kiyohara sc->sc_intrarg[j].ia_eselect = GTIDMAC_ESR(c);
482 1.1 kiyohara marvell_intr_establish(mva->mva_irq + j, IPL_BIO,
483 1.1 kiyohara gtidmac_intr, &sc->sc_intrarg[j]);
484 1.1 kiyohara }
485 1.1 kiyohara
486 1.1 kiyohara if (mva->mva_model != MARVELL_DISCOVERY)
487 1.1 kiyohara gtidmac_wininit(sc);
488 1.1 kiyohara
489 1.1 kiyohara /* Register us with dmover. */
490 1.1 kiyohara sc->sc_dmb.dmb_name = device_xname(self);
491 1.1 kiyohara if (!prop_dictionary_get_uint32(dict, "dmb_speed", &dmb_speed)) {
492 1.1 kiyohara aprint_error_dev(self, "no dmb_speed property\n");
493 1.1 kiyohara dmb_speed = 10; /* More than fast swdmover perhaps. */
494 1.1 kiyohara }
495 1.1 kiyohara sc->sc_dmb.dmb_speed = dmb_speed;
496 1.1 kiyohara sc->sc_dmb.dmb_cookie = sc;
497 1.1 kiyohara sc->sc_dmb.dmb_algdescs = gtidmac_algdescs;
498 1.1 kiyohara sc->sc_dmb.dmb_nalgdescs = __arraycount(gtidmac_algdescs);
499 1.1 kiyohara sc->sc_dmb.dmb_process = gtidmac_process;
500 1.1 kiyohara dmover_backend_register(&sc->sc_dmb);
501 1.1 kiyohara sc->sc_dmb_busy = 0;
502 1.1 kiyohara
503 1.1 kiyohara if (xore_nchan) {
504 1.1 kiyohara /* XORE DMA descriptor buffer */
505 1.1 kiyohara sc->sc_mvxore_nchan = xore_nchan;
506 1.1 kiyohara if (bus_dmamem_alloc(sc->sc_dmat,
507 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
508 1.1 kiyohara PAGE_SIZE, 0, &segs_xore, 1, &nsegs_xore, BUS_DMA_NOWAIT)) {
509 1.1 kiyohara aprint_error_dev(self, "bus_dmamem_alloc failed:"
510 1.1 kiyohara " xore descriptor buffer\n");
511 1.1 kiyohara goto fail8;
512 1.1 kiyohara }
513 1.1 kiyohara if (bus_dmamem_map(sc->sc_dmat, &segs_xore, 1,
514 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
515 1.1 kiyohara (void **)&sc->sc_dbuf_xore, BUS_DMA_NOWAIT)) {
516 1.1 kiyohara aprint_error_dev(self,
517 1.1 kiyohara "bus_dmamem_map failed: xore descriptor buffer\n");
518 1.1 kiyohara goto fail9;
519 1.1 kiyohara }
520 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
521 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan, 1,
522 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan, 0,
523 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_dmap_xore)) {
524 1.1 kiyohara aprint_error_dev(self, "bus_dmamap_create failed:"
525 1.1 kiyohara " xore descriptor buffer\n");
526 1.1 kiyohara goto fail10;
527 1.1 kiyohara }
528 1.1 kiyohara if (bus_dmamap_load(
529 1.1 kiyohara sc->sc_dmat, sc->sc_dmap_xore, sc->sc_dbuf_xore,
530 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC * xore_nchan,
531 1.1 kiyohara NULL, BUS_DMA_NOWAIT)) {
532 1.1 kiyohara aprint_error_dev(self,
533 1.1 kiyohara "bus_dmamap_load failed: xore descriptor buffer\n");
534 1.1 kiyohara goto fail11;
535 1.1 kiyohara }
536 1.1 kiyohara SLIST_INIT(&sc->sc_dlist_xore);
537 1.1 kiyohara for (j = 0; j < MVXORE_NDESC * xore_nchan; j++) {
538 1.1 kiyohara dd = &sc->sc_dd_buffer[j + GTIDMAC_NDESC * idmac_nchan];
539 1.1 kiyohara dd->dd_index = j;
540 1.1 kiyohara dd->dd_xore_vaddr = &sc->sc_dbuf_xore[j];
541 1.1 kiyohara dd->dd_paddr = sc->sc_dmap_xore->dm_segs[0].ds_addr +
542 1.1 kiyohara (sizeof(struct mvxore_desc) * j);
543 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist_xore, dd, dd_next);
544 1.1 kiyohara }
545 1.1 kiyohara
546 1.1 kiyohara /* Initialize XORE DMA channels */
547 1.1 kiyohara mask = 0;
548 1.1 kiyohara for (j = 0; j < xore_nchan; j++) {
549 1.1 kiyohara for (k = 0; k < MVXORE_NSRC; k++) {
550 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat,
551 1.1 kiyohara MVXORE_MAXXFER, MVXORE_NSEGS,
552 1.1 kiyohara MVXORE_MAXXFER, 0, BUS_DMA_NOWAIT,
553 1.1 kiyohara &sc->sc_cdesc_xore[j].chan_in[k])) {
554 1.1 kiyohara aprint_error_dev(self,
555 1.1 kiyohara "bus_dmamap_create failed:"
556 1.1 kiyohara " xore chan%d in[%d]\n", j, k);
557 1.1 kiyohara goto fail12;
558 1.1 kiyohara }
559 1.1 kiyohara }
560 1.1 kiyohara if (bus_dmamap_create(sc->sc_dmat, MVXORE_MAXXFER,
561 1.1 kiyohara MVXORE_NSEGS, MVXORE_MAXXFER, 0,
562 1.1 kiyohara BUS_DMA_NOWAIT, &sc->sc_cdesc_xore[j].chan_out)) {
563 1.1 kiyohara aprint_error_dev(self,
564 1.1 kiyohara "bus_dmamap_create failed: chan%d out\n",
565 1.1 kiyohara j);
566 1.1 kiyohara goto fail13;
567 1.1 kiyohara }
568 1.1 kiyohara sc->sc_cdesc_xore[j].chan_totalcnt = 0;
569 1.1 kiyohara sc->sc_cdesc_xore[j].chan_running = NULL;
570 1.1 kiyohara
571 1.1 kiyohara mask |= MVXORE_I(j,
572 1.1 kiyohara MVXORE_I_EOC |
573 1.1 kiyohara MVXORE_I_ADDRDECODE |
574 1.1 kiyohara MVXORE_I_ACCPROT |
575 1.1 kiyohara MVXORE_I_WRPROT |
576 1.1 kiyohara MVXORE_I_OWN |
577 1.1 kiyohara MVXORE_I_INTPARITY |
578 1.1 kiyohara MVXORE_I_XBAR);
579 1.1 kiyohara }
580 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIMR, mask);
581 1.1 kiyohara
582 1.1 kiyohara marvell_intr_establish(xore_irq + 0, IPL_BIO, mvxore_intr, sc);
583 1.1 kiyohara marvell_intr_establish(xore_irq + 1, IPL_BIO, mvxore_intr, sc);
584 1.1 kiyohara
585 1.1 kiyohara mvxore_wininit(sc);
586 1.1 kiyohara
587 1.1 kiyohara /* Register us with dmover. */
588 1.1 kiyohara sc->sc_dmb_xore.dmb_name = device_xname(sc->sc_dev);
589 1.1 kiyohara sc->sc_dmb_xore.dmb_speed = dmb_speed;
590 1.1 kiyohara sc->sc_dmb_xore.dmb_cookie = sc;
591 1.1 kiyohara sc->sc_dmb_xore.dmb_algdescs = mvxore_algdescs;
592 1.1 kiyohara sc->sc_dmb_xore.dmb_nalgdescs =
593 1.1 kiyohara __arraycount(mvxore_algdescs);
594 1.1 kiyohara sc->sc_dmb_xore.dmb_process = gtidmac_process;
595 1.1 kiyohara dmover_backend_register(&sc->sc_dmb_xore);
596 1.1 kiyohara }
597 1.1 kiyohara
598 1.1 kiyohara gtidmac_softc = sc;
599 1.1 kiyohara
600 1.1 kiyohara return;
601 1.1 kiyohara
602 1.1 kiyohara for (; j-- > 0;) {
603 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc_xore[j].chan_out);
604 1.1 kiyohara
605 1.1 kiyohara fail13:
606 1.1 kiyohara k = MVXORE_NSRC;
607 1.1 kiyohara fail12:
608 1.1 kiyohara for (; k-- > 0;)
609 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat,
610 1.1 kiyohara sc->sc_cdesc_xore[j].chan_in[k]);
611 1.1 kiyohara }
612 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap_xore);
613 1.1 kiyohara fail11:
614 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmap_xore);
615 1.1 kiyohara fail10:
616 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_dbuf_xore,
617 1.1 kiyohara sizeof(struct mvxore_desc) * MVXORE_NDESC);
618 1.1 kiyohara fail9:
619 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &segs_xore, 1);
620 1.1 kiyohara fail8:
621 1.1 kiyohara for (; i-- > 0;) {
622 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc[i].chan_in);
623 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdesc[i].chan_out);
624 1.1 kiyohara }
625 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
626 1.1 kiyohara fail7:
627 1.1 kiyohara bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmap);
628 1.1 kiyohara fail6:
629 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_dbuf,
630 1.1 kiyohara sizeof(struct gtidmac_desc) * GTIDMAC_NDESC);
631 1.1 kiyohara fail5:
632 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &segs, 1);
633 1.1 kiyohara fail4:
634 1.1 kiyohara bus_dmamem_unmap(sc->sc_dmat, sc->sc_pbuf, PAGE_SIZE);
635 1.1 kiyohara fail3:
636 1.1 kiyohara bus_dmamem_free(sc->sc_dmat, &sc->sc_pattern_segment, 1);
637 1.1 kiyohara fail2:
638 1.2 kiyohara kmem_free(sc->sc_dd_buffer, sizeof(struct gtidmac_dma_desc) * n);
639 1.1 kiyohara fail1:
640 1.1 kiyohara bus_space_unmap(sc->sc_iot, sc->sc_ioh, mva->mva_size);
641 1.1 kiyohara return;
642 1.1 kiyohara }
643 1.1 kiyohara
644 1.1 kiyohara
645 1.1 kiyohara static int
646 1.1 kiyohara gtidmac_intr(void *arg)
647 1.1 kiyohara {
648 1.1 kiyohara struct gtidmac_intr_arg *ia = arg;
649 1.1 kiyohara struct gtidmac_softc *sc = ia->ia_sc;
650 1.1 kiyohara uint32_t cause;
651 1.1 kiyohara int handled = 0, chan, error;
652 1.1 kiyohara
653 1.1 kiyohara cause = bus_space_read_4(sc->sc_iot, sc->sc_ioh, ia->ia_cause);
654 1.1 kiyohara DPRINTF(("IDMAC intr: cause=0x%x\n", cause));
655 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ia->ia_cause, ~cause);
656 1.1 kiyohara
657 1.1 kiyohara chan = 0;
658 1.1 kiyohara while (cause) {
659 1.1 kiyohara error = 0;
660 1.1 kiyohara if (cause & GTIDMAC_I_ADDRMISS) {
661 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Address Miss");
662 1.1 kiyohara error = EINVAL;
663 1.1 kiyohara }
664 1.1 kiyohara if (cause & GTIDMAC_I_ACCPROT) {
665 1.1 kiyohara aprint_error_dev(sc->sc_dev,
666 1.1 kiyohara "Access Protect Violation");
667 1.1 kiyohara error = EACCES;
668 1.1 kiyohara }
669 1.1 kiyohara if (cause & GTIDMAC_I_WRPROT) {
670 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Write Protect");
671 1.1 kiyohara error = EACCES;
672 1.1 kiyohara }
673 1.1 kiyohara if (cause & GTIDMAC_I_OWN) {
674 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Ownership Violation");
675 1.1 kiyohara error = EINVAL;
676 1.1 kiyohara }
677 1.1 kiyohara
678 1.1 kiyohara #define GTIDMAC_I_ERROR \
679 1.1 kiyohara (GTIDMAC_I_ADDRMISS | \
680 1.1 kiyohara GTIDMAC_I_ACCPROT | \
681 1.1 kiyohara GTIDMAC_I_WRPROT | \
682 1.1 kiyohara GTIDMAC_I_OWN)
683 1.1 kiyohara if (cause & GTIDMAC_I_ERROR) {
684 1.1 kiyohara uint32_t sel;
685 1.1 kiyohara int select;
686 1.1 kiyohara
687 1.1 kiyohara sel = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
688 1.1 kiyohara ia->ia_eselect) & GTIDMAC_ESR_SEL;
689 1.1 kiyohara select = sel - chan * GTIDMAC_I_BITS;
690 1.1 kiyohara if (select >= 0 && select < GTIDMAC_I_BITS) {
691 1.1 kiyohara uint32_t ear;
692 1.1 kiyohara
693 1.1 kiyohara ear = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
694 1.1 kiyohara ia->ia_eaddr);
695 1.1 kiyohara aprint_error(": Error Address 0x%x\n", ear);
696 1.1 kiyohara } else
697 1.1 kiyohara aprint_error(": lost Error Address\n");
698 1.1 kiyohara }
699 1.1 kiyohara
700 1.1 kiyohara if (cause & (GTIDMAC_I_COMP | GTIDMAC_I_ERROR)) {
701 1.1 kiyohara sc->sc_cdesc[chan].chan_dma_done(
702 1.1 kiyohara sc->sc_cdesc[chan].chan_running, chan,
703 1.1 kiyohara &sc->sc_cdesc[chan].chan_in,
704 1.1 kiyohara &sc->sc_cdesc[chan].chan_out, error);
705 1.1 kiyohara handled++;
706 1.1 kiyohara }
707 1.1 kiyohara
708 1.1 kiyohara cause >>= GTIDMAC_I_BITS;
709 1.1 kiyohara }
710 1.1 kiyohara DPRINTF(("IDMAC intr: %shandled\n", handled ? "" : "not "));
711 1.1 kiyohara
712 1.1 kiyohara return handled;
713 1.1 kiyohara }
714 1.1 kiyohara
715 1.1 kiyohara static int
716 1.1 kiyohara mvxore_intr(void *arg)
717 1.1 kiyohara {
718 1.1 kiyohara struct gtidmac_softc *sc = arg;
719 1.1 kiyohara uint32_t cause;
720 1.1 kiyohara int handled = 0, chan, error;
721 1.1 kiyohara
722 1.1 kiyohara cause = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEICR);
723 1.1 kiyohara DPRINTF(("XORE intr: cause=0x%x\n", cause));
724 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEICR, ~cause);
725 1.1 kiyohara
726 1.1 kiyohara chan = 0;
727 1.1 kiyohara while (cause) {
728 1.1 kiyohara error = 0;
729 1.1 kiyohara if (cause & MVXORE_I_ADDRDECODE) {
730 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Failed address decoding");
731 1.1 kiyohara error = EINVAL;
732 1.1 kiyohara }
733 1.1 kiyohara if (cause & MVXORE_I_ACCPROT) {
734 1.1 kiyohara aprint_error_dev(sc->sc_dev,
735 1.1 kiyohara "Access Protect Violation");
736 1.1 kiyohara error = EACCES;
737 1.1 kiyohara }
738 1.1 kiyohara if (cause & MVXORE_I_WRPROT) {
739 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Write Protect");
740 1.1 kiyohara error = EACCES;
741 1.1 kiyohara }
742 1.1 kiyohara if (cause & MVXORE_I_OWN) {
743 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Ownership Violation");
744 1.1 kiyohara error = EINVAL;
745 1.1 kiyohara }
746 1.1 kiyohara if (cause & MVXORE_I_INTPARITY) {
747 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Parity Error");
748 1.1 kiyohara error = EIO;
749 1.1 kiyohara }
750 1.1 kiyohara if (cause & MVXORE_I_XBAR) {
751 1.1 kiyohara aprint_error_dev(sc->sc_dev, "Crossbar Parity Error");
752 1.1 kiyohara error = EINVAL;
753 1.1 kiyohara }
754 1.1 kiyohara
755 1.1 kiyohara #define MVXORE_I_ERROR \
756 1.1 kiyohara (MVXORE_I_ADDRDECODE | \
757 1.1 kiyohara MVXORE_I_ACCPROT | \
758 1.1 kiyohara MVXORE_I_WRPROT | \
759 1.1 kiyohara MVXORE_I_OWN | \
760 1.1 kiyohara MVXORE_I_INTPARITY | \
761 1.1 kiyohara MVXORE_I_XBAR)
762 1.1 kiyohara if (cause & MVXORE_I_ERROR) {
763 1.1 kiyohara uint32_t type;
764 1.1 kiyohara int event;
765 1.1 kiyohara
766 1.1 kiyohara type = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
767 1.1 kiyohara MVXORE_XEECR) & MVXORE_XEECR_ERRORTYPE_MASK;
768 1.1 kiyohara event = type - chan * MVXORE_I_BITS;
769 1.1 kiyohara if (event >= 0 && event < MVXORE_I_BITS) {
770 1.1 kiyohara uint32_t xeear;
771 1.1 kiyohara
772 1.1 kiyohara xeear = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
773 1.1 kiyohara MVXORE_XEEAR);
774 1.1 kiyohara aprint_error(": Error Address 0x%x\n", xeear);
775 1.1 kiyohara } else
776 1.1 kiyohara aprint_error(": lost Error Address\n");
777 1.1 kiyohara }
778 1.1 kiyohara
779 1.1 kiyohara if (cause & (MVXORE_I_EOC | MVXORE_I_ERROR)) {
780 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_dma_done(
781 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running, chan,
782 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_in,
783 1.1 kiyohara &sc->sc_cdesc_xore[chan].chan_out, error);
784 1.1 kiyohara handled++;
785 1.1 kiyohara }
786 1.1 kiyohara
787 1.1 kiyohara cause >>= MVXORE_I_BITS;
788 1.1 kiyohara }
789 1.1 kiyohara DPRINTF(("XORE intr: %shandled\n", handled ? "" : "not "));
790 1.1 kiyohara
791 1.1 kiyohara return handled;
792 1.1 kiyohara }
793 1.1 kiyohara
794 1.1 kiyohara
795 1.1 kiyohara /*
796 1.1 kiyohara * dmover(9) backend function.
797 1.1 kiyohara */
798 1.1 kiyohara static void
799 1.1 kiyohara gtidmac_process(struct dmover_backend *dmb)
800 1.1 kiyohara {
801 1.1 kiyohara struct gtidmac_softc *sc = dmb->dmb_cookie;
802 1.1 kiyohara int s;
803 1.1 kiyohara
804 1.1 kiyohara /* If the backend is currently idle, go process the queue. */
805 1.1 kiyohara s = splbio();
806 1.1 kiyohara if (!sc->sc_dmb_busy)
807 1.1 kiyohara gtidmac_dmover_run(dmb);
808 1.1 kiyohara splx(s);
809 1.1 kiyohara }
810 1.1 kiyohara
811 1.1 kiyohara static void
812 1.1 kiyohara gtidmac_dmover_run(struct dmover_backend *dmb)
813 1.1 kiyohara {
814 1.1 kiyohara struct gtidmac_softc *sc = dmb->dmb_cookie;
815 1.1 kiyohara struct dmover_request *dreq;
816 1.1 kiyohara const struct dmover_algdesc *algdesc;
817 1.1 kiyohara struct gtidmac_function *df;
818 1.1 kiyohara bus_dmamap_t *dmamap_in, *dmamap_out;
819 1.1 kiyohara int chan, ninputs, error, i;
820 1.1 kiyohara
821 1.1 kiyohara sc->sc_dmb_busy = 1;
822 1.1 kiyohara
823 1.1 kiyohara for (;;) {
824 1.1 kiyohara dreq = TAILQ_FIRST(&dmb->dmb_pendreqs);
825 1.1 kiyohara if (dreq == NULL)
826 1.1 kiyohara break;
827 1.1 kiyohara algdesc = dreq->dreq_assignment->das_algdesc;
828 1.1 kiyohara df = algdesc->dad_data;
829 1.1 kiyohara chan = (*df->chan_alloc)(sc, &dmamap_in, &dmamap_out, dreq);
830 1.1 kiyohara if (chan == -1)
831 1.1 kiyohara return;
832 1.1 kiyohara
833 1.1 kiyohara dmover_backend_remque(dmb, dreq);
834 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_RUNNING;
835 1.1 kiyohara
836 1.1 kiyohara /* XXXUNLOCK */
837 1.1 kiyohara
838 1.1 kiyohara error = 0;
839 1.1 kiyohara
840 1.1 kiyohara /* Load in/out buffers of dmover to bus_dmamap. */
841 1.1 kiyohara ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
842 1.1 kiyohara if (ninputs == 0) {
843 1.1 kiyohara int pno = 0;
844 1.1 kiyohara
845 1.1 kiyohara if (algdesc->dad_name == DMOVER_FUNC_FILL8)
846 1.1 kiyohara pno = dreq->dreq_immediate[0];
847 1.1 kiyohara
848 1.1 kiyohara i = 0;
849 1.1 kiyohara error = bus_dmamap_load(sc->sc_dmat, *dmamap_in,
850 1.1 kiyohara &sc->sc_pbuf[pno], sizeof(sc->sc_pbuf[pno]), NULL,
851 1.1 kiyohara BUS_DMA_NOWAIT | BUS_DMA_STREAMING | BUS_DMA_WRITE);
852 1.1 kiyohara if (error == 0) {
853 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, *dmamap_in, 0,
854 1.1 kiyohara sizeof(uint32_t), BUS_DMASYNC_PREWRITE);
855 1.1 kiyohara
856 1.1 kiyohara /*
857 1.1 kiyohara * We will call gtidmac_dmmap_unload() when
858 1.1 kiyohara * becoming an error.
859 1.1 kiyohara */
860 1.1 kiyohara i = 1;
861 1.1 kiyohara }
862 1.1 kiyohara } else
863 1.1 kiyohara for (i = 0; i < ninputs; i++) {
864 1.1 kiyohara error = gtidmac_dmmap_load(sc,
865 1.1 kiyohara *(dmamap_in + i), dreq->dreq_inbuf_type,
866 1.1 kiyohara &dreq->dreq_inbuf[i], 0/*write*/);
867 1.1 kiyohara if (error != 0)
868 1.1 kiyohara break;
869 1.1 kiyohara }
870 1.1 kiyohara if (algdesc->dad_name != DMOVER_FUNC_ISCSI_CRC32C) {
871 1.1 kiyohara if (error == 0)
872 1.1 kiyohara error = gtidmac_dmmap_load(sc, *dmamap_out,
873 1.1 kiyohara dreq->dreq_outbuf_type, &dreq->dreq_outbuf,
874 1.1 kiyohara 1/*read*/);
875 1.1 kiyohara
876 1.1 kiyohara if (error == 0) {
877 1.1 kiyohara /*
878 1.1 kiyohara * The size of outbuf is always believed to be
879 1.1 kiyohara * DMA transfer size in dmover request.
880 1.1 kiyohara */
881 1.1 kiyohara error = (*df->dma_setup)(sc, chan, ninputs,
882 1.1 kiyohara dmamap_in, dmamap_out,
883 1.1 kiyohara (*dmamap_out)->dm_mapsize);
884 1.1 kiyohara if (error != 0)
885 1.1 kiyohara gtidmac_dmmap_unload(sc, *dmamap_out,
886 1.1 kiyohara 1);
887 1.1 kiyohara }
888 1.1 kiyohara } else
889 1.1 kiyohara if (error == 0)
890 1.1 kiyohara error = (*df->dma_setup)(sc, chan, ninputs,
891 1.1 kiyohara dmamap_in, dmamap_out,
892 1.1 kiyohara (*dmamap_in)->dm_mapsize);
893 1.1 kiyohara
894 1.1 kiyohara /* XXXLOCK */
895 1.1 kiyohara
896 1.1 kiyohara if (error != 0) {
897 1.1 kiyohara for (; i-- > 0;)
898 1.1 kiyohara gtidmac_dmmap_unload(sc, *(dmamap_in + i), 0);
899 1.1 kiyohara (*df->chan_free)(sc, chan);
900 1.1 kiyohara
901 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_ERROR;
902 1.1 kiyohara dreq->dreq_error = error;
903 1.1 kiyohara /* XXXUNLOCK */
904 1.1 kiyohara dmover_done(dreq);
905 1.1 kiyohara /* XXXLOCK */
906 1.1 kiyohara continue;
907 1.1 kiyohara }
908 1.1 kiyohara
909 1.1 kiyohara (*df->dma_start)(sc, chan, gtidmac_dmover_done);
910 1.1 kiyohara break;
911 1.1 kiyohara }
912 1.1 kiyohara
913 1.1 kiyohara /* All done */
914 1.1 kiyohara sc->sc_dmb_busy = 0;
915 1.1 kiyohara }
916 1.1 kiyohara
917 1.1 kiyohara static void
918 1.1 kiyohara gtidmac_dmover_done(void *object, int chan, bus_dmamap_t *dmamap_in,
919 1.1 kiyohara bus_dmamap_t *dmamap_out, int error)
920 1.1 kiyohara {
921 1.1 kiyohara struct gtidmac_softc *sc;
922 1.1 kiyohara struct dmover_request *dreq = object;
923 1.1 kiyohara struct dmover_backend *dmb;
924 1.1 kiyohara struct gtidmac_function *df;
925 1.1 kiyohara uint32_t result;
926 1.1 kiyohara int ninputs, i;
927 1.1 kiyohara
928 1.1 kiyohara KASSERT(dreq != NULL);
929 1.1 kiyohara
930 1.1 kiyohara dmb = dreq->dreq_assignment->das_backend;
931 1.1 kiyohara df = dreq->dreq_assignment->das_algdesc->dad_data;
932 1.1 kiyohara ninputs = dreq->dreq_assignment->das_algdesc->dad_ninputs;
933 1.1 kiyohara sc = dmb->dmb_cookie;
934 1.1 kiyohara
935 1.1 kiyohara result = (*df->dma_finish)(sc, chan, error);
936 1.1 kiyohara for (i = 0; i < ninputs; i++)
937 1.1 kiyohara gtidmac_dmmap_unload(sc, *(dmamap_in + i), 0);
938 1.1 kiyohara if (dreq->dreq_assignment->das_algdesc->dad_name ==
939 1.1 kiyohara DMOVER_FUNC_ISCSI_CRC32C)
940 1.1 kiyohara memcpy(dreq->dreq_immediate, &result, sizeof(result));
941 1.1 kiyohara else
942 1.1 kiyohara gtidmac_dmmap_unload(sc, *dmamap_out, 1);
943 1.1 kiyohara
944 1.1 kiyohara (*df->chan_free)(sc, chan);
945 1.1 kiyohara
946 1.1 kiyohara if (error) {
947 1.1 kiyohara dreq->dreq_error = error;
948 1.1 kiyohara dreq->dreq_flags |= DMOVER_REQ_ERROR;
949 1.1 kiyohara }
950 1.1 kiyohara
951 1.1 kiyohara dmover_done(dreq);
952 1.1 kiyohara
953 1.1 kiyohara /*
954 1.1 kiyohara * See if we can start some more dmover(9) requests.
955 1.1 kiyohara *
956 1.1 kiyohara * Note: We're already at splbio() here.
957 1.1 kiyohara */
958 1.1 kiyohara if (!sc->sc_dmb_busy)
959 1.1 kiyohara gtidmac_dmover_run(dmb);
960 1.1 kiyohara }
961 1.1 kiyohara
962 1.1 kiyohara __inline int
963 1.1 kiyohara gtidmac_dmmap_load(struct gtidmac_softc *sc, bus_dmamap_t dmamap,
964 1.1 kiyohara dmover_buffer_type dmbuf_type, dmover_buffer *dmbuf,
965 1.1 kiyohara int read)
966 1.1 kiyohara {
967 1.1 kiyohara int error, flags;
968 1.1 kiyohara
969 1.1 kiyohara flags = BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
970 1.1 kiyohara read ? BUS_DMA_READ : BUS_DMA_WRITE;
971 1.1 kiyohara
972 1.1 kiyohara switch (dmbuf_type) {
973 1.1 kiyohara case DMOVER_BUF_LINEAR:
974 1.1 kiyohara error = bus_dmamap_load(sc->sc_dmat, dmamap,
975 1.1 kiyohara dmbuf->dmbuf_linear.l_addr, dmbuf->dmbuf_linear.l_len,
976 1.1 kiyohara NULL, flags);
977 1.1 kiyohara break;
978 1.1 kiyohara
979 1.1 kiyohara case DMOVER_BUF_UIO:
980 1.1 kiyohara if ((read && dmbuf->dmbuf_uio->uio_rw != UIO_READ) ||
981 1.1 kiyohara (!read && dmbuf->dmbuf_uio->uio_rw == UIO_READ))
982 1.1 kiyohara return (EINVAL);
983 1.1 kiyohara
984 1.1 kiyohara error = bus_dmamap_load_uio(sc->sc_dmat, dmamap,
985 1.1 kiyohara dmbuf->dmbuf_uio, flags);
986 1.1 kiyohara break;
987 1.1 kiyohara
988 1.1 kiyohara default:
989 1.1 kiyohara error = EINVAL;
990 1.1 kiyohara }
991 1.1 kiyohara
992 1.1 kiyohara if (error == 0)
993 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
994 1.1 kiyohara read ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
995 1.1 kiyohara
996 1.1 kiyohara return error;
997 1.1 kiyohara }
998 1.1 kiyohara
999 1.1 kiyohara __inline void
1000 1.1 kiyohara gtidmac_dmmap_unload(struct gtidmac_softc *sc, bus_dmamap_t dmamap, int read)
1001 1.1 kiyohara {
1002 1.1 kiyohara
1003 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
1004 1.1 kiyohara read ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
1005 1.1 kiyohara
1006 1.1 kiyohara bus_dmamap_unload(sc->sc_dmat, dmamap);
1007 1.1 kiyohara }
1008 1.1 kiyohara
1009 1.1 kiyohara
1010 1.1 kiyohara void *
1011 1.1 kiyohara gtidmac_tag_get()
1012 1.1 kiyohara {
1013 1.1 kiyohara
1014 1.1 kiyohara return gtidmac_softc;
1015 1.1 kiyohara }
1016 1.1 kiyohara
1017 1.1 kiyohara /*
1018 1.1 kiyohara * IDMAC functions
1019 1.1 kiyohara */
1020 1.1 kiyohara int
1021 1.1 kiyohara gtidmac_chan_alloc(void *tag, bus_dmamap_t **dmamap_in,
1022 1.1 kiyohara bus_dmamap_t **dmamap_out, void *object)
1023 1.1 kiyohara {
1024 1.1 kiyohara struct gtidmac_softc *sc = tag;
1025 1.1 kiyohara int chan;
1026 1.1 kiyohara
1027 1.1 kiyohara /* maybe need lock */
1028 1.1 kiyohara
1029 1.1 kiyohara for (chan = 0; chan < sc->sc_gtidmac_nchan; chan++)
1030 1.1 kiyohara if (sc->sc_cdesc[chan].chan_running == NULL)
1031 1.1 kiyohara break;
1032 1.1 kiyohara if (chan >= sc->sc_gtidmac_nchan)
1033 1.1 kiyohara return -1;
1034 1.1 kiyohara
1035 1.1 kiyohara
1036 1.1 kiyohara sc->sc_cdesc[chan].chan_running = object;
1037 1.1 kiyohara
1038 1.1 kiyohara /* unlock */
1039 1.1 kiyohara
1040 1.1 kiyohara *dmamap_in = &sc->sc_cdesc[chan].chan_in;
1041 1.1 kiyohara *dmamap_out = &sc->sc_cdesc[chan].chan_out;
1042 1.1 kiyohara
1043 1.1 kiyohara return chan;
1044 1.1 kiyohara }
1045 1.1 kiyohara
1046 1.1 kiyohara void
1047 1.1 kiyohara gtidmac_chan_free(void *tag, int chan)
1048 1.1 kiyohara {
1049 1.1 kiyohara struct gtidmac_softc *sc = tag;
1050 1.1 kiyohara
1051 1.1 kiyohara /* maybe need lock */
1052 1.1 kiyohara
1053 1.1 kiyohara sc->sc_cdesc[chan].chan_running = NULL;
1054 1.1 kiyohara
1055 1.1 kiyohara /* unlock */
1056 1.1 kiyohara }
1057 1.1 kiyohara
1058 1.1 kiyohara /* ARGSUSED */
1059 1.1 kiyohara int
1060 1.1 kiyohara gtidmac_setup(void *tag, int chan, int ninputs, bus_dmamap_t *dmamap_in,
1061 1.1 kiyohara bus_dmamap_t *dmamap_out, bus_size_t size)
1062 1.1 kiyohara {
1063 1.1 kiyohara struct gtidmac_softc *sc = tag;
1064 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1065 1.1 kiyohara struct gtidmac_desc *desc;
1066 1.1 kiyohara uint32_t ccl, bcnt, ires, ores;
1067 1.1 kiyohara int n = 0, iidx, oidx;
1068 1.1 kiyohara
1069 1.1 kiyohara KASSERT(ninputs == 0 || ninputs == 1);
1070 1.1 kiyohara
1071 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan));
1072 1.1 kiyohara #ifdef DIAGNOSTIC
1073 1.1 kiyohara if (ccl & GTIDMAC_CCLR_CHANACT)
1074 1.1 kiyohara panic("gtidmac_setup: chan%d already active", chan);
1075 1.1 kiyohara #endif
1076 1.1 kiyohara
1077 1.1 kiyohara /* We always Chain-mode and max (16M - 1)byte/desc */
1078 1.1 kiyohara ccl = (GTIDMAC_CCLR_DESCMODE_16M |
1079 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1080 1.1 kiyohara GTIDMAC_CCLR_CDEN |
1081 1.1 kiyohara #endif
1082 1.1 kiyohara GTIDMAC_CCLR_TRANSFERMODE_B /* Transfer Mode: Block */ |
1083 1.1 kiyohara GTIDMAC_CCLR_INTMODE_NULL /* Intr Mode: Next Desc NULL */ |
1084 1.1 kiyohara GTIDMAC_CCLR_CHAINMODE_C /* Chain Mode: Chaind */);
1085 1.1 kiyohara if (size != (*dmamap_in)->dm_mapsize) {
1086 1.1 kiyohara ccl |= GTIDMAC_CCLR_SRCHOLD;
1087 1.1 kiyohara if ((*dmamap_in)->dm_mapsize == 8)
1088 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_8B;
1089 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 16)
1090 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_16B;
1091 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 32)
1092 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_32B;
1093 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 64)
1094 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_64B;
1095 1.1 kiyohara else if ((*dmamap_in)->dm_mapsize == 128)
1096 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_128B;
1097 1.1 kiyohara else
1098 1.1 kiyohara panic("gtidmac_setup: chan%d source:"
1099 1.1 kiyohara " unsupport hold size", chan);
1100 1.1 kiyohara } else
1101 1.1 kiyohara ccl |= GTIDMAC_CCLR_SBL_128B;
1102 1.1 kiyohara if (size != (*dmamap_out)->dm_mapsize) {
1103 1.1 kiyohara ccl |= GTIDMAC_CCLR_DESTHOLD;
1104 1.1 kiyohara if ((*dmamap_out)->dm_mapsize == 8)
1105 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_8B;
1106 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 16)
1107 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_16B;
1108 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 32)
1109 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_32B;
1110 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 64)
1111 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_64B;
1112 1.1 kiyohara else if ((*dmamap_out)->dm_mapsize == 128)
1113 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_128B;
1114 1.1 kiyohara else
1115 1.1 kiyohara panic("gtidmac_setup: chan%d destination:"
1116 1.1 kiyohara " unsupport hold size", chan);
1117 1.1 kiyohara } else
1118 1.1 kiyohara ccl |= GTIDMAC_CCLR_DBL_128B;
1119 1.1 kiyohara
1120 1.1 kiyohara fstdd = SLIST_FIRST(&sc->sc_dlist);
1121 1.1 kiyohara if (fstdd == NULL) {
1122 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no descriptor\n");
1123 1.1 kiyohara return ENOMEM;
1124 1.1 kiyohara }
1125 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist, dd_next);
1126 1.1 kiyohara sc->sc_cdesc[chan].chan_ddidx = fstdd->dd_index;
1127 1.1 kiyohara
1128 1.1 kiyohara dd = fstdd;
1129 1.1 kiyohara ires = ores = 0;
1130 1.1 kiyohara iidx = oidx = 0;
1131 1.1 kiyohara while (1 /*CONSTCOND*/) {
1132 1.1 kiyohara if (ccl & GTIDMAC_CCLR_SRCHOLD) {
1133 1.1 kiyohara if (ccl & GTIDMAC_CCLR_DESTHOLD)
1134 1.1 kiyohara bcnt = size; /* src/dst hold */
1135 1.1 kiyohara else
1136 1.1 kiyohara bcnt = (*dmamap_out)->dm_segs[oidx].ds_len;
1137 1.1 kiyohara } else if (ccl & GTIDMAC_CCLR_DESTHOLD)
1138 1.1 kiyohara bcnt = (*dmamap_in)->dm_segs[iidx].ds_len;
1139 1.1 kiyohara else
1140 1.1 kiyohara bcnt = min((*dmamap_in)->dm_segs[iidx].ds_len - ires,
1141 1.1 kiyohara (*dmamap_out)->dm_segs[oidx].ds_len - ores);
1142 1.1 kiyohara
1143 1.1 kiyohara desc = dd->dd_idmac_vaddr;
1144 1.1 kiyohara desc->bc.mode16m.bcnt =
1145 1.1 kiyohara bcnt | GTIDMAC_CIDMABCR_BCLEFT | GTIDMAC_CIDMABCR_OWN;
1146 1.1 kiyohara desc->srcaddr = (*dmamap_in)->dm_segs[iidx].ds_addr + ires;
1147 1.1 kiyohara desc->dstaddr = (*dmamap_out)->dm_segs[oidx].ds_addr + ores;
1148 1.1 kiyohara
1149 1.1 kiyohara n += bcnt;
1150 1.1 kiyohara if (n >= size)
1151 1.1 kiyohara break;
1152 1.1 kiyohara if (!(ccl & GTIDMAC_CCLR_SRCHOLD)) {
1153 1.1 kiyohara ires += bcnt;
1154 1.1 kiyohara if (ires >= (*dmamap_in)->dm_segs[iidx].ds_len) {
1155 1.1 kiyohara ires = 0;
1156 1.1 kiyohara iidx++;
1157 1.1 kiyohara KASSERT(iidx < (*dmamap_in)->dm_nsegs);
1158 1.1 kiyohara }
1159 1.1 kiyohara }
1160 1.1 kiyohara if (!(ccl & GTIDMAC_CCLR_DESTHOLD)) {
1161 1.1 kiyohara ores += bcnt;
1162 1.1 kiyohara if (ores >= (*dmamap_out)->dm_segs[oidx].ds_len) {
1163 1.1 kiyohara ores = 0;
1164 1.1 kiyohara oidx++;
1165 1.1 kiyohara KASSERT(oidx < (*dmamap_out)->dm_nsegs);
1166 1.1 kiyohara }
1167 1.1 kiyohara }
1168 1.1 kiyohara
1169 1.1 kiyohara nxtdd = SLIST_FIRST(&sc->sc_dlist);
1170 1.1 kiyohara if (nxtdd == NULL) {
1171 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no descriptor\n");
1172 1.1 kiyohara return ENOMEM;
1173 1.1 kiyohara }
1174 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist, dd_next);
1175 1.1 kiyohara
1176 1.1 kiyohara desc->nextdp = (uint32_t)nxtdd->dd_paddr;
1177 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1178 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1179 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1180 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1181 1.1 kiyohara #else
1182 1.1 kiyohara BUS_DMASYNC_PREWRITE);
1183 1.1 kiyohara #endif
1184 1.1 kiyohara
1185 1.1 kiyohara SLIST_INSERT_AFTER(dd, nxtdd, dd_next);
1186 1.1 kiyohara dd = nxtdd;
1187 1.1 kiyohara }
1188 1.1 kiyohara desc->nextdp = (uint32_t)NULL;
1189 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap, dd->dd_index * sizeof(*desc),
1190 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1191 1.1 kiyohara sizeof(*desc), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1192 1.1 kiyohara #else
1193 1.1 kiyohara sizeof(*desc), BUS_DMASYNC_PREWRITE);
1194 1.1 kiyohara #endif
1195 1.1 kiyohara
1196 1.1 kiyohara /* Set paddr of descriptor to Channel Next Descriptor Pointer */
1197 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CNDPR(chan),
1198 1.1 kiyohara fstdd->dd_paddr+1);
1199 1.1 kiyohara
1200 1.1 kiyohara #if BYTE_ORDER == LITTLE_ENDIAN
1201 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCHR(chan),
1202 1.1 kiyohara GTIDMAC_CCHR_DESCBYTESWAP | GTIDMAC_CCHR_ENDIAN_LE);
1203 1.1 kiyohara #endif
1204 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan), ccl);
1205 1.1 kiyohara
1206 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1207 1.1 kiyohara gtidmac_dump_idmacdesc(sc, fstdd, ccl, 0/*pre*/);
1208 1.1 kiyohara #endif
1209 1.1 kiyohara
1210 1.1 kiyohara sc->sc_cdesc[chan].chan_totalcnt += size;
1211 1.1 kiyohara
1212 1.1 kiyohara return 0;
1213 1.1 kiyohara }
1214 1.1 kiyohara
1215 1.1 kiyohara void
1216 1.1 kiyohara gtidmac_start(void *tag, int chan,
1217 1.1 kiyohara void (*dma_done_cb)(void *, int, bus_dmamap_t *, bus_dmamap_t *,
1218 1.1 kiyohara int))
1219 1.1 kiyohara {
1220 1.1 kiyohara struct gtidmac_softc *sc = tag;
1221 1.1 kiyohara uint32_t ccl;
1222 1.1 kiyohara
1223 1.1 kiyohara DPRINTF(("%s:%d: starting\n", device_xname(sc->sc_dev), chan));
1224 1.1 kiyohara
1225 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1226 1.1 kiyohara gtidmac_dump_idmacreg(sc, chan);
1227 1.1 kiyohara #endif
1228 1.1 kiyohara
1229 1.1 kiyohara sc->sc_cdesc[chan].chan_dma_done = dma_done_cb;
1230 1.1 kiyohara
1231 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan));
1232 1.1 kiyohara /* Start and 'Fetch Next Descriptor' */
1233 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CCLR(chan),
1234 1.1 kiyohara ccl | GTIDMAC_CCLR_CHANEN | GTIDMAC_CCLR_FETCHND);
1235 1.1 kiyohara }
1236 1.1 kiyohara
1237 1.1 kiyohara static uint32_t
1238 1.1 kiyohara gtidmac_finish(void *tag, int chan, int error)
1239 1.1 kiyohara {
1240 1.1 kiyohara struct gtidmac_softc *sc = tag;
1241 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1242 1.1 kiyohara struct gtidmac_desc *desc;
1243 1.1 kiyohara
1244 1.1 kiyohara fstdd = &sc->sc_dd_buffer[sc->sc_cdesc[chan].chan_ddidx];
1245 1.1 kiyohara
1246 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1247 1.1 kiyohara if (error || gtidmac_debug > 1) {
1248 1.1 kiyohara uint32_t ccl;
1249 1.1 kiyohara
1250 1.1 kiyohara gtidmac_dump_idmacreg(sc, chan);
1251 1.1 kiyohara ccl = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1252 1.1 kiyohara GTIDMAC_CCLR(chan));
1253 1.1 kiyohara gtidmac_dump_idmacdesc(sc, fstdd, ccl, 1/*post*/);
1254 1.1 kiyohara }
1255 1.1 kiyohara #endif
1256 1.1 kiyohara
1257 1.1 kiyohara dd = fstdd;
1258 1.1 kiyohara do {
1259 1.1 kiyohara desc = dd->dd_idmac_vaddr;
1260 1.1 kiyohara
1261 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap,
1262 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1263 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1264 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1265 1.1 kiyohara #else
1266 1.1 kiyohara BUS_DMASYNC_POSTWRITE);
1267 1.1 kiyohara #endif
1268 1.1 kiyohara
1269 1.1 kiyohara nxtdd = SLIST_NEXT(dd, dd_next);
1270 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist, dd, dd_next);
1271 1.1 kiyohara dd = nxtdd;
1272 1.1 kiyohara } while (desc->nextdp);
1273 1.1 kiyohara
1274 1.1 kiyohara return 0;
1275 1.1 kiyohara }
1276 1.1 kiyohara
1277 1.1 kiyohara /*
1278 1.1 kiyohara * XORE functions
1279 1.1 kiyohara */
1280 1.1 kiyohara int
1281 1.1 kiyohara mvxore_chan_alloc(void *tag, bus_dmamap_t **dmamap_in,
1282 1.1 kiyohara bus_dmamap_t **dmamap_out, void *object)
1283 1.1 kiyohara {
1284 1.1 kiyohara struct gtidmac_softc *sc = tag;
1285 1.1 kiyohara int chan;
1286 1.1 kiyohara
1287 1.1 kiyohara /* maybe need lock */
1288 1.1 kiyohara
1289 1.1 kiyohara for (chan = 0; chan < sc->sc_mvxore_nchan; chan++)
1290 1.1 kiyohara if (sc->sc_cdesc_xore[chan].chan_running == NULL)
1291 1.1 kiyohara break;
1292 1.1 kiyohara if (chan >= sc->sc_mvxore_nchan)
1293 1.1 kiyohara return -1;
1294 1.1 kiyohara
1295 1.1 kiyohara
1296 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running = object;
1297 1.1 kiyohara
1298 1.1 kiyohara /* unlock */
1299 1.1 kiyohara
1300 1.1 kiyohara *dmamap_in = sc->sc_cdesc_xore[chan].chan_in;
1301 1.1 kiyohara *dmamap_out = &sc->sc_cdesc_xore[chan].chan_out;
1302 1.1 kiyohara
1303 1.1 kiyohara return chan;
1304 1.1 kiyohara }
1305 1.1 kiyohara
1306 1.1 kiyohara void
1307 1.1 kiyohara mvxore_chan_free(void *tag, int chan)
1308 1.1 kiyohara {
1309 1.1 kiyohara struct gtidmac_softc *sc = tag;
1310 1.1 kiyohara
1311 1.1 kiyohara /* maybe need lock */
1312 1.1 kiyohara
1313 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_running = NULL;
1314 1.1 kiyohara
1315 1.1 kiyohara /* unlock */
1316 1.1 kiyohara }
1317 1.1 kiyohara
1318 1.1 kiyohara /* ARGSUSED */
1319 1.1 kiyohara int
1320 1.1 kiyohara mvxore_setup(void *tag, int chan, int ninputs, bus_dmamap_t *dmamap_in,
1321 1.1 kiyohara bus_dmamap_t *dmamap_out, bus_size_t size)
1322 1.1 kiyohara {
1323 1.1 kiyohara struct gtidmac_softc *sc = tag;
1324 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1325 1.1 kiyohara struct mvxore_desc *desc;
1326 1.1 kiyohara uint32_t xexc, bcnt, cmd, lastcmd;
1327 1.1 kiyohara int n = 0, i;
1328 1.1 kiyohara uint32_t ires[MVXORE_NSRC] = { 0, 0, 0, 0, 0, 0, 0, 0 }, ores = 0;
1329 1.1 kiyohara int iidx[MVXORE_NSRC] = { 0, 0, 0, 0, 0, 0, 0, 0 }, oidx = 0;
1330 1.1 kiyohara
1331 1.1 kiyohara #ifdef DIAGNOSTIC
1332 1.1 kiyohara uint32_t xexact;
1333 1.1 kiyohara
1334 1.1 kiyohara xexact = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1335 1.1 kiyohara if ((xexact & MVXORE_XEXACTR_XESTATUS_MASK) ==
1336 1.1 kiyohara MVXORE_XEXACTR_XESTATUS_ACT)
1337 1.1 kiyohara panic("mvxore_setup: chan%d already active."
1338 1.1 kiyohara " mvxore not support hot insertion", chan);
1339 1.1 kiyohara #endif
1340 1.1 kiyohara
1341 1.1 kiyohara xexc =
1342 1.1 kiyohara (MVXORE_XEXCR_REGACCPROTECT |
1343 1.1 kiyohara MVXORE_XEXCR_DBL_128B |
1344 1.1 kiyohara MVXORE_XEXCR_SBL_128B);
1345 1.1 kiyohara cmd = lastcmd = 0;
1346 1.1 kiyohara if (ninputs > 1) {
1347 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_XOR;
1348 1.1 kiyohara lastcmd = cmd = (1 << ninputs) - 1;
1349 1.1 kiyohara } else if (ninputs == 1) {
1350 1.1 kiyohara if ((*dmamap_out)->dm_nsegs == 0) {
1351 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_CRC32;
1352 1.1 kiyohara lastcmd = MVXORE_DESC_CMD_CRCLAST;
1353 1.1 kiyohara } else
1354 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_DMA;
1355 1.1 kiyohara } else if (ninputs == 0) {
1356 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 1) {
1357 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1358 1.1 kiyohara "XORE not supports %d DMA segments\n",
1359 1.1 kiyohara (*dmamap_out)->dm_nsegs);
1360 1.1 kiyohara return EINVAL;
1361 1.1 kiyohara }
1362 1.1 kiyohara
1363 1.1 kiyohara if ((*dmamap_in)->dm_mapsize == 0) {
1364 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_ECC;
1365 1.1 kiyohara
1366 1.1 kiyohara /* XXXXX: Maybe need to set Timer Mode registers? */
1367 1.1 kiyohara
1368 1.1 kiyohara #if 0
1369 1.1 kiyohara } else if ((*dmamap_in)->dm_mapsize == 8 ||
1370 1.1 kiyohara (*dmamap_in)->dm_mapsize == 16) { /* in case dmover */
1371 1.1 kiyohara uint64_t pattern;
1372 1.1 kiyohara
1373 1.1 kiyohara /* XXXX: Get pattern data */
1374 1.1 kiyohara
1375 1.1 kiyohara KASSERT((*dmamap_in)->dm_mapsize == 8 ||
1376 1.1 kiyohara (void *)((uint32_t)(*dmamap_in)->_dm_origbuf &
1377 1.1 kiyohara ~PAGE_MASK) == sc->sc_pbuf);
1378 1.1 kiyohara pattern = *(uint64_t *)(*dmamap_in)->_dm_origbuf;
1379 1.1 kiyohara
1380 1.1 kiyohara /* XXXXX: XORE has a IVR. We should get this first. */
1381 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIVRL,
1382 1.1 kiyohara pattern);
1383 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEIVRH,
1384 1.1 kiyohara pattern >> 32);
1385 1.1 kiyohara
1386 1.1 kiyohara xexc |= MVXORE_XEXCR_OM_MEMINIT;
1387 1.1 kiyohara #endif
1388 1.1 kiyohara } else {
1389 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1390 1.1 kiyohara "XORE not supports DMA mapsize %zd\n",
1391 1.1 kiyohara (*dmamap_in)->dm_mapsize);
1392 1.1 kiyohara return EINVAL;
1393 1.1 kiyohara }
1394 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXDPR(chan),
1395 1.1 kiyohara (*dmamap_out)->dm_segs[0].ds_addr);
1396 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXBSR(chan),
1397 1.1 kiyohara (*dmamap_out)->dm_mapsize);
1398 1.1 kiyohara
1399 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan),
1400 1.1 kiyohara xexc);
1401 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_totalcnt += size;
1402 1.1 kiyohara
1403 1.1 kiyohara return 0;
1404 1.1 kiyohara }
1405 1.1 kiyohara
1406 1.1 kiyohara /* Make descriptor for DMA/CRC32/XOR */
1407 1.1 kiyohara
1408 1.1 kiyohara fstdd = SLIST_FIRST(&sc->sc_dlist_xore);
1409 1.1 kiyohara if (fstdd == NULL) {
1410 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no xore descriptor\n");
1411 1.1 kiyohara return ENOMEM;
1412 1.1 kiyohara }
1413 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist_xore, dd_next);
1414 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_ddidx =
1415 1.1 kiyohara fstdd->dd_index + GTIDMAC_NDESC * sc->sc_gtidmac_nchan;
1416 1.1 kiyohara
1417 1.1 kiyohara dd = fstdd;
1418 1.1 kiyohara while (1 /*CONSTCOND*/) {
1419 1.1 kiyohara desc = dd->dd_xore_vaddr;
1420 1.1 kiyohara desc->stat = MVXORE_DESC_STAT_OWN;
1421 1.1 kiyohara desc->cmd = cmd;
1422 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 0) {
1423 1.1 kiyohara desc->dstaddr =
1424 1.1 kiyohara (*dmamap_out)->dm_segs[oidx].ds_addr + ores;
1425 1.1 kiyohara bcnt = (*dmamap_out)->dm_segs[oidx].ds_len - ores;
1426 1.1 kiyohara } else {
1427 1.1 kiyohara desc->dstaddr = 0;
1428 1.1 kiyohara bcnt = MVXORE_MAXXFER; /* XXXXX */
1429 1.1 kiyohara }
1430 1.1 kiyohara for (i = 0; i < ninputs; i++) {
1431 1.1 kiyohara desc->srcaddr[i] =
1432 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_addr + ires[i];
1433 1.1 kiyohara bcnt = min(bcnt,
1434 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_len - ires[i]);
1435 1.1 kiyohara }
1436 1.1 kiyohara desc->bcnt = bcnt;
1437 1.1 kiyohara
1438 1.1 kiyohara n += bcnt;
1439 1.1 kiyohara if (n >= size)
1440 1.1 kiyohara break;
1441 1.1 kiyohara ores += bcnt;
1442 1.1 kiyohara if ((*dmamap_out)->dm_nsegs != 0 &&
1443 1.1 kiyohara ores >= (*dmamap_out)->dm_segs[oidx].ds_len) {
1444 1.1 kiyohara ores = 0;
1445 1.1 kiyohara oidx++;
1446 1.1 kiyohara KASSERT(oidx < (*dmamap_out)->dm_nsegs);
1447 1.1 kiyohara }
1448 1.1 kiyohara for (i = 0; i < ninputs; i++) {
1449 1.1 kiyohara ires[i] += bcnt;
1450 1.1 kiyohara if (ires[i] >=
1451 1.1 kiyohara (*dmamap_in[i]).dm_segs[iidx[i]].ds_len) {
1452 1.1 kiyohara ires[i] = 0;
1453 1.1 kiyohara iidx[i]++;
1454 1.1 kiyohara KASSERT(iidx[i] < (*dmamap_in[i]).dm_nsegs);
1455 1.1 kiyohara }
1456 1.1 kiyohara }
1457 1.1 kiyohara
1458 1.1 kiyohara nxtdd = SLIST_FIRST(&sc->sc_dlist_xore);
1459 1.1 kiyohara if (nxtdd == NULL) {
1460 1.1 kiyohara aprint_error_dev(sc->sc_dev, "no xore descriptor\n");
1461 1.1 kiyohara return ENOMEM;
1462 1.1 kiyohara }
1463 1.1 kiyohara SLIST_REMOVE_HEAD(&sc->sc_dlist_xore, dd_next);
1464 1.1 kiyohara
1465 1.1 kiyohara desc->nextda = (uint32_t)nxtdd->dd_paddr;
1466 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1467 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1468 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1469 1.1 kiyohara
1470 1.1 kiyohara SLIST_INSERT_AFTER(dd, nxtdd, dd_next);
1471 1.1 kiyohara dd = nxtdd;
1472 1.1 kiyohara }
1473 1.1 kiyohara desc->cmd = lastcmd;
1474 1.1 kiyohara desc->nextda = (uint32_t)NULL;
1475 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1476 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1477 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1478 1.1 kiyohara
1479 1.1 kiyohara /* Set paddr of descriptor to Channel Next Descriptor Pointer */
1480 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXNDPR(chan),
1481 1.1 kiyohara fstdd->dd_paddr);
1482 1.1 kiyohara
1483 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan), xexc);
1484 1.1 kiyohara
1485 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1486 1.1 kiyohara mvidmac_dump_xoredesc(sc, fstdd, xexc, 0/*pre*/);
1487 1.1 kiyohara #endif
1488 1.1 kiyohara
1489 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_totalcnt += size;
1490 1.1 kiyohara
1491 1.1 kiyohara return 0;
1492 1.1 kiyohara }
1493 1.1 kiyohara
1494 1.1 kiyohara void
1495 1.1 kiyohara mvxore_start(void *tag, int chan,
1496 1.1 kiyohara void (*dma_done_cb)(void *, int, bus_dmamap_t *, bus_dmamap_t *,
1497 1.1 kiyohara int))
1498 1.1 kiyohara {
1499 1.1 kiyohara struct gtidmac_softc *sc = tag;
1500 1.1 kiyohara uint32_t xexact;
1501 1.1 kiyohara
1502 1.1 kiyohara DPRINTF(("%s:%d: xore starting\n", device_xname(sc->sc_dev), chan));
1503 1.1 kiyohara
1504 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1505 1.1 kiyohara gtidmac_dump_xorereg(sc, chan);
1506 1.1 kiyohara #endif
1507 1.1 kiyohara
1508 1.1 kiyohara sc->sc_cdesc_xore[chan].chan_dma_done = dma_done_cb;
1509 1.1 kiyohara
1510 1.1 kiyohara xexact = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1511 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan),
1512 1.1 kiyohara xexact | MVXORE_XEXACTR_XESTART);
1513 1.1 kiyohara }
1514 1.1 kiyohara
1515 1.1 kiyohara static uint32_t
1516 1.1 kiyohara mvxore_finish(void *tag, int chan, int error)
1517 1.1 kiyohara {
1518 1.1 kiyohara struct gtidmac_softc *sc = tag;
1519 1.1 kiyohara struct gtidmac_dma_desc *dd, *fstdd, *nxtdd;
1520 1.1 kiyohara struct mvxore_desc *desc;
1521 1.1 kiyohara uint32_t xexc;
1522 1.1 kiyohara
1523 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1524 1.1 kiyohara if (error || gtidmac_debug > 1)
1525 1.1 kiyohara gtidmac_dump_xorereg(sc, chan);
1526 1.1 kiyohara #endif
1527 1.1 kiyohara
1528 1.1 kiyohara xexc = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXCR(chan));
1529 1.1 kiyohara if ((xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_ECC ||
1530 1.1 kiyohara (xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_MEMINIT)
1531 1.1 kiyohara return 0;
1532 1.1 kiyohara
1533 1.1 kiyohara fstdd = &sc->sc_dd_buffer[sc->sc_cdesc_xore[chan].chan_ddidx];
1534 1.1 kiyohara
1535 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1536 1.1 kiyohara if (error || gtidmac_debug > 1)
1537 1.1 kiyohara gtidmac_dump_xoredesc(sc, fstdd, xexc, 1/*post*/);
1538 1.1 kiyohara #endif
1539 1.1 kiyohara
1540 1.1 kiyohara dd = fstdd;
1541 1.1 kiyohara do {
1542 1.1 kiyohara desc = dd->dd_xore_vaddr;
1543 1.1 kiyohara
1544 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1545 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1546 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1547 1.1 kiyohara
1548 1.1 kiyohara nxtdd = SLIST_NEXT(dd, dd_next);
1549 1.1 kiyohara SLIST_INSERT_HEAD(&sc->sc_dlist_xore, dd, dd_next);
1550 1.1 kiyohara dd = nxtdd;
1551 1.1 kiyohara } while (desc->nextda);
1552 1.1 kiyohara
1553 1.1 kiyohara if ((xexc & MVXORE_XEXCR_OM_MASK) == MVXORE_XEXCR_OM_CRC32)
1554 1.1 kiyohara return desc->result;
1555 1.1 kiyohara return 0;
1556 1.1 kiyohara }
1557 1.1 kiyohara
1558 1.1 kiyohara static void
1559 1.1 kiyohara gtidmac_wininit(struct gtidmac_softc *sc)
1560 1.1 kiyohara {
1561 1.1 kiyohara device_t pdev = device_parent(sc->sc_dev);
1562 1.1 kiyohara uint64_t base;
1563 1.1 kiyohara uint32_t size, cxap, en;
1564 1.1 kiyohara int window, target, attr, rv, i;
1565 1.1 kiyohara struct {
1566 1.1 kiyohara int tag;
1567 1.1 kiyohara int winacc;
1568 1.1 kiyohara } targets[] = {
1569 1.1 kiyohara { MARVELL_TAG_SDRAM_CS0, GTIDMAC_CXAPR_WINACC_FA },
1570 1.1 kiyohara { MARVELL_TAG_SDRAM_CS1, GTIDMAC_CXAPR_WINACC_FA },
1571 1.1 kiyohara { MARVELL_TAG_SDRAM_CS2, GTIDMAC_CXAPR_WINACC_FA },
1572 1.1 kiyohara { MARVELL_TAG_SDRAM_CS3, GTIDMAC_CXAPR_WINACC_FA },
1573 1.1 kiyohara
1574 1.1 kiyohara /* Also can set following targets. */
1575 1.1 kiyohara /* Devices = 0x1(ORION_TARGETID_DEVICE_*) */
1576 1.1 kiyohara /* PCI = 0x3(ORION_TARGETID_PCI0_*) */
1577 1.1 kiyohara /* PCI Express = 0x4(ORION_TARGETID_PEX?_*) */
1578 1.1 kiyohara /* Tunit SRAM(?) = 0x5(???) */
1579 1.1 kiyohara
1580 1.1 kiyohara { MARVELL_TAG_UNDEFINED, GTIDMAC_CXAPR_WINACC_NOAA }
1581 1.1 kiyohara };
1582 1.1 kiyohara
1583 1.1 kiyohara en = 0xff;
1584 1.1 kiyohara cxap = 0;
1585 1.1 kiyohara for (window = 0, i = 0;
1586 1.1 kiyohara targets[i].tag != MARVELL_TAG_UNDEFINED && window < GTIDMAC_NWINDOW;
1587 1.1 kiyohara i++) {
1588 1.1 kiyohara rv = marvell_winparams_by_tag(pdev, targets[i].tag,
1589 1.1 kiyohara &target, &attr, &base, &size);
1590 1.1 kiyohara if (rv != 0 || size == 0)
1591 1.1 kiyohara continue;
1592 1.1 kiyohara
1593 1.1 kiyohara if (base > 0xffffffffULL) {
1594 1.1 kiyohara if (window >= GTIDMAC_NREMAP) {
1595 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1596 1.1 kiyohara "can't remap window %d\n", window);
1597 1.1 kiyohara continue;
1598 1.1 kiyohara }
1599 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1600 1.1 kiyohara GTIDMAC_HARXR(window), (base >> 32) & 0xffffffff);
1601 1.1 kiyohara }
1602 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_BARX(window),
1603 1.1 kiyohara GTIDMAC_BARX_TARGET(target) |
1604 1.1 kiyohara GTIDMAC_BARX_ATTR(attr) |
1605 1.1 kiyohara GTIDMAC_BARX_BASE(base));
1606 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_SRX(window),
1607 1.1 kiyohara GTIDMAC_SRX_SIZE(size));
1608 1.1 kiyohara en &= ~GTIDMAC_BAER_EN(window);
1609 1.1 kiyohara cxap |= GTIDMAC_CXAPR_WINACC(window, targets[i].winacc);
1610 1.1 kiyohara window++;
1611 1.1 kiyohara }
1612 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_BAER, en);
1613 1.1 kiyohara
1614 1.1 kiyohara for (i = 0; i < GTIDMAC_NACCPROT; i++)
1615 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CXAPR(i),
1616 1.1 kiyohara cxap);
1617 1.1 kiyohara }
1618 1.1 kiyohara
1619 1.1 kiyohara static void
1620 1.1 kiyohara mvxore_wininit(struct gtidmac_softc *sc)
1621 1.1 kiyohara {
1622 1.1 kiyohara device_t pdev = device_parent(sc->sc_dev);
1623 1.1 kiyohara uint64_t base;
1624 1.1 kiyohara uint32_t target, attr, size, xexwc;
1625 1.1 kiyohara int window, rv, i;
1626 1.1 kiyohara struct {
1627 1.1 kiyohara int tag;
1628 1.1 kiyohara int winacc;
1629 1.1 kiyohara } targets[] = {
1630 1.1 kiyohara { MARVELL_TAG_SDRAM_CS0, MVXORE_XEXWCR_WINACC_FA },
1631 1.1 kiyohara { MARVELL_TAG_SDRAM_CS1, MVXORE_XEXWCR_WINACC_FA },
1632 1.1 kiyohara { MARVELL_TAG_SDRAM_CS2, MVXORE_XEXWCR_WINACC_FA },
1633 1.1 kiyohara { MARVELL_TAG_SDRAM_CS3, MVXORE_XEXWCR_WINACC_FA },
1634 1.1 kiyohara
1635 1.1 kiyohara { MARVELL_TAG_UNDEFINED, MVXORE_XEXWCR_WINACC_NOAA }
1636 1.1 kiyohara };
1637 1.1 kiyohara
1638 1.1 kiyohara xexwc = 0;
1639 1.1 kiyohara for (window = 0, i = 0;
1640 1.1 kiyohara targets[i].tag != MARVELL_TAG_UNDEFINED && window < MVXORE_NWINDOW;
1641 1.1 kiyohara i++) {
1642 1.1 kiyohara rv = marvell_winparams_by_tag(pdev, targets[i].tag,
1643 1.1 kiyohara &target, &attr, &base, &size);
1644 1.1 kiyohara if (rv != 0 || size == 0)
1645 1.1 kiyohara continue;
1646 1.1 kiyohara
1647 1.1 kiyohara if (base > 0xffffffffULL) {
1648 1.1 kiyohara if (window >= MVXORE_NREMAP) {
1649 1.1 kiyohara aprint_error_dev(sc->sc_dev,
1650 1.1 kiyohara "can't remap window %d\n", window);
1651 1.1 kiyohara continue;
1652 1.1 kiyohara }
1653 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1654 1.1 kiyohara MVXORE_XEHARRX(window), (base >> 32) & 0xffffffff);
1655 1.1 kiyohara }
1656 1.1 kiyohara
1657 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEBARX(window),
1658 1.1 kiyohara MVXORE_XEBARX_TARGET(target) |
1659 1.1 kiyohara MVXORE_XEBARX_ATTR(attr) |
1660 1.1 kiyohara MVXORE_XEBARX_BASE(base));
1661 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh,
1662 1.1 kiyohara MVXORE_XESMRX(window), MVXORE_XESMRX_SIZE(size));
1663 1.1 kiyohara xexwc |= (MVXORE_XEXWCR_WINEN(window) |
1664 1.1 kiyohara MVXORE_XEXWCR_WINACC(window, targets[i].winacc));
1665 1.1 kiyohara window++;
1666 1.1 kiyohara }
1667 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXWCR(0), xexwc);
1668 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXWCR(1), xexwc);
1669 1.1 kiyohara
1670 1.1 kiyohara /* XXXXX: reset... */
1671 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXAOCR(0), 0);
1672 1.1 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXAOCR(1), 0);
1673 1.1 kiyohara }
1674 1.1 kiyohara
1675 1.1 kiyohara
1676 1.1 kiyohara #ifdef GTIDMAC_DEBUG
1677 1.1 kiyohara static void
1678 1.1 kiyohara gtidmac_dump_idmacreg(struct gtidmac_softc *sc, int chan)
1679 1.1 kiyohara {
1680 1.1 kiyohara uint32_t val;
1681 1.1 kiyohara char buf[256];
1682 1.1 kiyohara
1683 1.1 kiyohara printf("IDMAC Registers\n");
1684 1.1 kiyohara
1685 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GTIDMAC_CIDMABCR(chan));
1686 1.1 kiyohara bitmask_snprintf(val, "\177\020b\037Own\0b\036BCLeft\0", buf,
1687 1.1 kiyohara sizeof(buf));
1688 1.1 kiyohara printf(" Byte Count : 0x%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.1 kiyohara bitmask_snprintf(val,
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.1 kiyohara buf, sizeof(buf));
1705 1.1 kiyohara printf(" Channel Control (Low) : 0x%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.1 kiyohara bitmask_snprintf(val, "\177\020b\001DescByteSwap\0b\000Endianness\0",
1728 1.1 kiyohara buf, sizeof(buf));
1729 1.1 kiyohara printf(" Channel Control (High) : 0x%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.1 kiyohara bitmask_snprintf(desc->bc.mode16m.bcnt,
1754 1.1 kiyohara "\177\020b\037Own\0b\036BCLeft\0",
1755 1.1 kiyohara buf, sizeof(buf));
1756 1.1 kiyohara printf(" Byte Count : 0x%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.1 kiyohara bitmask_snprintf(val, "\177\020"
1797 1.1 kiyohara "b\017RegAccProtect\0b\016DesSwp\0b\015DwrReqSwp\0b\014DrdResSwp\0",
1798 1.1 kiyohara buf, sizeof(buf));
1799 1.1 kiyohara printf(" Configuration : 0x%s\n", buf);
1800 1.1 kiyohara opmode = val & MVXORE_XEXCR_OM_MASK;
1801 1.1 kiyohara printf(" OperationMode : %s operation\n",
1802 1.1 kiyohara opmode == MVXORE_XEXCR_OM_XOR ? "XOR calculate" :
1803 1.1 kiyohara opmode == MVXORE_XEXCR_OM_CRC32 ? "CRC-32 calculate" :
1804 1.1 kiyohara opmode == MVXORE_XEXCR_OM_DMA ? "DMA" :
1805 1.1 kiyohara opmode == MVXORE_XEXCR_OM_ECC ? "ECC cleanup" :
1806 1.1 kiyohara opmode == MVXORE_XEXCR_OM_MEMINIT ? "Memory Initialization" :
1807 1.1 kiyohara "unknown");
1808 1.1 kiyohara printf(" SrcBurstLimit : %s Bytes\n",
1809 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_128B ? "128" :
1810 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_64B ? "64" :
1811 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_32B ? "32" :
1812 1.1 kiyohara "unknwon");
1813 1.1 kiyohara printf(" DstBurstLimit : %s Bytes\n",
1814 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_128B ? "128" :
1815 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_64B ? "64" :
1816 1.1 kiyohara (val & MVXORE_XEXCR_SBL_MASK) == MVXORE_XEXCR_SBL_32B ? "32" :
1817 1.1 kiyohara "unknwon");
1818 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXACTR(chan));
1819 1.1 kiyohara printf(" Activation : 0x%08x\n", val);
1820 1.1 kiyohara val &= MVXORE_XEXACTR_XESTATUS_MASK;
1821 1.1 kiyohara printf(" XEstatus : %s\n",
1822 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_NA ? "Channel not active" :
1823 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_ACT ? "Channel active" :
1824 1.1 kiyohara val == MVXORE_XEXACTR_XESTATUS_P ? "Channel paused" : "???");
1825 1.1 kiyohara
1826 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_XOR ||
1827 1.1 kiyohara opmode == MVXORE_XEXCR_OM_CRC32 ||
1828 1.1 kiyohara opmode == MVXORE_XEXCR_OM_DMA) {
1829 1.1 kiyohara printf(" NextDescPtr : 0x%08x\n",
1830 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1831 1.1 kiyohara MVXORE_XEXNDPR(chan)));
1832 1.1 kiyohara printf(" CurrentDescPtr : 0x%08x\n",
1833 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1834 1.1 kiyohara MVXORE_XEXCDPR(chan)));
1835 1.1 kiyohara }
1836 1.1 kiyohara printf(" ByteCnt : 0x%08x\n",
1837 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVXORE_XEXBCR(chan)));
1838 1.1 kiyohara
1839 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_ECC ||
1840 1.1 kiyohara opmode == MVXORE_XEXCR_OM_MEMINIT) {
1841 1.1 kiyohara printf(" DstPtr : 0x%08x\n",
1842 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1843 1.1 kiyohara MVXORE_XEXDPR(chan)));
1844 1.1 kiyohara printf(" BlockSize : 0x%08x\n",
1845 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1846 1.1 kiyohara MVXORE_XEXBSR(chan)));
1847 1.1 kiyohara
1848 1.1 kiyohara if (opmode == MVXORE_XEXCR_OM_ECC) {
1849 1.1 kiyohara val = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1850 1.1 kiyohara MVXORE_XETMCR);
1851 1.1 kiyohara if (val & MVXORE_XETMCR_TIMEREN) {
1852 1.1 kiyohara val >>= MVXORE_XETMCR_SECTIONSIZECTRL_SHIFT;
1853 1.1 kiyohara val &= MVXORE_XETMCR_SECTIONSIZECTRL_MASK;
1854 1.1 kiyohara printf(" SectionSizeCtrl : 0x%08x\n", 2 ^ val);
1855 1.1 kiyohara printf(" TimerInitVal : 0x%08x\n",
1856 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1857 1.1 kiyohara MVXORE_XETMIVR));
1858 1.1 kiyohara printf(" TimerCrntVal : 0x%08x\n",
1859 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1860 1.1 kiyohara MVXORE_XETMCVR));
1861 1.1 kiyohara }
1862 1.1 kiyohara } else /* MVXORE_XEXCR_OM_MEMINIT */
1863 1.1 kiyohara printf(" InitVal : 0x%08x%08x\n",
1864 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1865 1.1 kiyohara MVXORE_XEIVRH),
1866 1.1 kiyohara bus_space_read_4(sc->sc_iot, sc->sc_ioh,
1867 1.1 kiyohara MVXORE_XEIVRL));
1868 1.1 kiyohara }
1869 1.1 kiyohara }
1870 1.1 kiyohara
1871 1.1 kiyohara static void
1872 1.1 kiyohara gtidmac_dump_xoredesc(struct gtidmac_softc *sc, struct gtidmac_dma_desc *dd,
1873 1.1 kiyohara uint32_t mode, int post)
1874 1.1 kiyohara {
1875 1.1 kiyohara struct gtxore_desc *desc;
1876 1.1 kiyohara int i, j;
1877 1.1 kiyohara char buf[256];
1878 1.1 kiyohara
1879 1.1 kiyohara printf("XORE Descriptor\n");
1880 1.1 kiyohara
1881 1.1 kiyohara mode &= MVXORE_XEXCR_OM_MASK;
1882 1.1 kiyohara
1883 1.1 kiyohara i = 0;
1884 1.1 kiyohara while (1 /*CONSTCOND*/) {
1885 1.1 kiyohara if (post)
1886 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1887 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1888 1.1 kiyohara BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
1889 1.1 kiyohara
1890 1.1 kiyohara desc = dd->dd_xore_vaddr;
1891 1.1 kiyohara
1892 1.1 kiyohara printf("%d (0x%lx)\n", i, dd->dd_paddr);
1893 1.1 kiyohara
1894 1.1 kiyohara bitmask_snprintf(desc->stat, "\177\020b\037Own\0b\036Success\0",
1895 1.1 kiyohara buf, sizeof(buf));
1896 1.1 kiyohara printf(" Status : 0x%s\n", buf);
1897 1.1 kiyohara if (desc->cmd & MVXORE_DESC_CMD_CRCLAST && post)
1898 1.1 kiyohara printf(" CRC-32 Result : 0x%08x\n",
1899 1.1 kiyohara desc->result);
1900 1.1 kiyohara bitmask_snprintf(desc->cmd,
1901 1.1 kiyohara "\177\020b\037EODIntEn\0b\036CRCLast\0"
1902 1.1 kiyohara "b\007Src7Cmd\0b\006Src6Cmd\0b\005Src5Cmd\0b\004Src4Cmd\0"
1903 1.1 kiyohara "b\003Src3Cmd\0b\002Src2Cmd\0b\001Src1Cmd\0b\000Src0Cmd\0",
1904 1.1 kiyohara buf, sizeof(buf));
1905 1.1 kiyohara printf(" Command : 0x%s\n", buf);
1906 1.1 kiyohara printf(" Next Descriptor Address : 0x%08x\n", desc->nextda);
1907 1.1 kiyohara printf(" Byte Count : 0x%06x\n", desc->bcnt);
1908 1.1 kiyohara printf(" Destination Address : 0x%08x\n", desc->dstaddr);
1909 1.1 kiyohara if (mode == MVXORE_XEXCR_OM_XOR) {
1910 1.1 kiyohara for (j = 0; j < MVXORE_NSRC; j++)
1911 1.1 kiyohara if (desc->cmd & MVXORE_DESC_CMD_SRCCMD(j))
1912 1.1 kiyohara printf(" Source Address#%d :"
1913 1.1 kiyohara " 0x%08x\n", j, desc->srcaddr[j]);
1914 1.1 kiyohara } else
1915 1.1 kiyohara printf(" Source Address : 0x%08x\n",
1916 1.1 kiyohara desc->srcaddr[0]);
1917 1.1 kiyohara
1918 1.1 kiyohara if (desc->nextda == (uint32_t)NULL)
1919 1.1 kiyohara break;
1920 1.1 kiyohara
1921 1.1 kiyohara if (!post)
1922 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1923 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1924 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1925 1.1 kiyohara
1926 1.1 kiyohara i++;
1927 1.1 kiyohara dd = SLIST_NEXT(dd, dd_next);
1928 1.1 kiyohara }
1929 1.1 kiyohara if (!post)
1930 1.1 kiyohara bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap_xore,
1931 1.1 kiyohara dd->dd_index * sizeof(*desc), sizeof(*desc),
1932 1.1 kiyohara BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1933 1.1 kiyohara }
1934 1.1 kiyohara #endif
1935