1 From 854c1f0e9574e9b25a55b439608c71e013b34a56 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Mon, 25 Sep 2017 12:12:20 +0800
4 Subject: [PATCH] dma: support layerscape
6 This is a integrated patch for layerscape dma support.
8 Signed-off-by: jiaheng.fan <jiaheng.fan@nxp.com>
9 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
11 drivers/dma/Kconfig | 31 +
12 drivers/dma/Makefile | 3 +
13 drivers/dma/caam_dma.c | 563 +++++++++++++++
14 drivers/dma/dpaa2-qdma/Kconfig | 8 +
15 drivers/dma/dpaa2-qdma/Makefile | 8 +
16 drivers/dma/dpaa2-qdma/dpaa2-qdma.c | 986 +++++++++++++++++++++++++
17 drivers/dma/dpaa2-qdma/dpaa2-qdma.h | 262 +++++++
18 drivers/dma/dpaa2-qdma/dpdmai.c | 454 ++++++++++++
19 drivers/dma/dpaa2-qdma/fsl_dpdmai.h | 521 ++++++++++++++
20 drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h | 222 ++++++
21 drivers/dma/fsl-qdma.c | 1201 +++++++++++++++++++++++++++++++
22 11 files changed, 4259 insertions(+)
23 create mode 100644 drivers/dma/caam_dma.c
24 create mode 100644 drivers/dma/dpaa2-qdma/Kconfig
25 create mode 100644 drivers/dma/dpaa2-qdma/Makefile
26 create mode 100644 drivers/dma/dpaa2-qdma/dpaa2-qdma.c
27 create mode 100644 drivers/dma/dpaa2-qdma/dpaa2-qdma.h
28 create mode 100644 drivers/dma/dpaa2-qdma/dpdmai.c
29 create mode 100644 drivers/dma/dpaa2-qdma/fsl_dpdmai.h
30 create mode 100644 drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h
31 create mode 100644 drivers/dma/fsl-qdma.c
33 diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
34 index 141aefbe..8caaf091 100644
35 --- a/drivers/dma/Kconfig
36 +++ b/drivers/dma/Kconfig
37 @@ -192,6 +192,20 @@ config FSL_EDMA
38 multiplexing capability for DMA request sources(slot).
39 This module can be found on Freescale Vybrid and LS-1 SoCs.
42 + tristate "Freescale qDMA engine support"
44 + select DMA_VIRTUAL_CHANNELS
45 + select DMA_ENGINE_RAID
46 + select ASYNC_TX_ENABLE_CHANNEL_SWITCH
48 + Support the Freescale qDMA engine with command queue and legacy mode.
49 + Channel virtualization is supported through enqueuing of DMA jobs to,
50 + or dequeuing DMA jobs from, different work queues.
51 + This module can be found on Freescale LS SoCs.
53 +source drivers/dma/dpaa2-qdma/Kconfig
56 tristate "Freescale RAID engine Support"
57 depends on FSL_SOC && !ASYNC_TX_ENABLE_CHANNEL_SWITCH
58 @@ -564,6 +578,23 @@ config ZX_DMA
60 Support the DMA engine for ZTE ZX296702 platform devices.
62 +config CRYPTO_DEV_FSL_CAAM_DMA
63 + tristate "CAAM DMA engine support"
64 + depends on CRYPTO_DEV_FSL_CAAM_JR
68 + select ASYNC_TX_ENABLE_CHANNEL_SWITCH
70 + Selecting this will offload the DMA operations for users of
71 + the scatter gather memcopy API to the CAAM via job rings. The
72 + CAAM is a hardware module that provides hardware acceleration to
73 + cryptographic operations. It has a built-in DMA controller that can
74 + be programmed to read/write cryptographic data. This module defines
75 + a DMA driver that uses the DMA capabilities of the CAAM.
77 + To compile this as a module, choose M here: the module
78 + will be called caam_dma.
81 source "drivers/dma/bestcomm/Kconfig"
82 diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
83 index e4dc9cac..a694da0e 100644
84 --- a/drivers/dma/Makefile
85 +++ b/drivers/dma/Makefile
86 @@ -29,6 +29,8 @@ obj-$(CONFIG_DW_DMAC_CORE) += dw/
87 obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o
88 obj-$(CONFIG_FSL_DMA) += fsldma.o
89 obj-$(CONFIG_FSL_EDMA) += fsl-edma.o
90 +obj-$(CONFIG_FSL_QDMA) += fsl-qdma.o
91 +obj-$(CONFIG_FSL_DPAA2_QDMA) += dpaa2-qdma/
92 obj-$(CONFIG_FSL_RAID) += fsl_raid.o
93 obj-$(CONFIG_HSU_DMA) += hsu/
94 obj-$(CONFIG_IMG_MDC_DMA) += img-mdc-dma.o
95 @@ -67,6 +69,7 @@ obj-$(CONFIG_TI_DMA_CROSSBAR) += ti-dma-crossbar.o
96 obj-$(CONFIG_TI_EDMA) += edma.o
97 obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
98 obj-$(CONFIG_ZX_DMA) += zx296702_dma.o
99 +obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_DMA) += caam_dma.o
103 diff --git a/drivers/dma/caam_dma.c b/drivers/dma/caam_dma.c
105 index 00000000..e430b320
107 +++ b/drivers/dma/caam_dma.c
110 + * caam support for SG DMA
112 + * Copyright 2016 Freescale Semiconductor, Inc
113 + * Copyright 2017 NXP
116 +#include <linux/module.h>
117 +#include <linux/platform_device.h>
118 +#include <linux/dma-mapping.h>
119 +#include <linux/interrupt.h>
120 +#include <linux/slab.h>
121 +#include <linux/debugfs.h>
123 +#include <linux/dmaengine.h>
124 +#include "dmaengine.h"
126 +#include "../crypto/caam/regs.h"
127 +#include "../crypto/caam/jr.h"
128 +#include "../crypto/caam/error.h"
129 +#include "../crypto/caam/intern.h"
130 +#include "../crypto/caam/desc_constr.h"
131 +#include "../crypto/caam/sg_sw_sec4.h"
133 +#define DESC_DMA_MEMCPY_LEN ((CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN) / \
136 +/* This is max chunk size of a DMA transfer. If a buffer is larger than this
137 + * value it is internally broken into chunks of max CAAM_DMA_CHUNK_SIZE bytes
138 + * and for each chunk a DMA transfer request is issued.
139 + * This value is the largest number on 16 bits that is a multiple of 256 bytes
140 + * (the largest configurable CAAM DMA burst size).
142 +#define CAAM_DMA_CHUNK_SIZE 65280
144 +struct caam_dma_sh_desc {
145 + u32 desc[DESC_DMA_MEMCPY_LEN] ____cacheline_aligned;
146 + dma_addr_t desc_dma;
149 +/* caam dma extended descriptor */
150 +struct caam_dma_edesc {
151 + struct dma_async_tx_descriptor async_tx;
152 + struct list_head node;
153 + struct caam_dma_ctx *ctx;
154 + dma_addr_t src_dma;
155 + dma_addr_t dst_dma;
156 + unsigned int src_len;
157 + unsigned int dst_len;
158 + struct sec4_sg_entry *sec4_sg;
159 + u32 jd[] ____cacheline_aligned;
163 + * caam_dma_ctx - per jr/channel context
164 + * @chan: dma channel used by async_tx API
165 + * @node: list_head used to attach to the global dma_ctx_list
166 + * @jrdev: Job Ring device
167 + * @submit_q: queue of pending (submitted, but not enqueued) jobs
168 + * @done_not_acked: jobs that have been completed by jr, but maybe not acked
169 + * @edesc_lock: protects extended descriptor
171 +struct caam_dma_ctx {
172 + struct dma_chan chan;
173 + struct list_head node;
174 + struct device *jrdev;
175 + struct list_head submit_q;
176 + struct list_head done_not_acked;
177 + spinlock_t edesc_lock;
180 +static struct dma_device *dma_dev;
181 +static struct caam_dma_sh_desc *dma_sh_desc;
182 +static LIST_HEAD(dma_ctx_list);
184 +static dma_cookie_t caam_dma_tx_submit(struct dma_async_tx_descriptor *tx)
186 + struct caam_dma_edesc *edesc = NULL;
187 + struct caam_dma_ctx *ctx = NULL;
188 + dma_cookie_t cookie;
190 + edesc = container_of(tx, struct caam_dma_edesc, async_tx);
191 + ctx = container_of(tx->chan, struct caam_dma_ctx, chan);
193 + spin_lock_bh(&ctx->edesc_lock);
195 + cookie = dma_cookie_assign(tx);
196 + list_add_tail(&edesc->node, &ctx->submit_q);
198 + spin_unlock_bh(&ctx->edesc_lock);
203 +static unsigned int caam_dma_sg_dma_len(struct scatterlist *sg,
204 + unsigned int nents)
208 + for (len = 0; sg && nents; sg = sg_next(sg), nents--)
209 + len += sg_dma_len(sg);
214 +static struct caam_dma_edesc *
215 +caam_dma_sg_edesc_alloc(struct dma_chan *chan,
216 + struct scatterlist *dst_sg, unsigned int dst_nents,
217 + struct scatterlist *src_sg, unsigned int src_nents,
218 + unsigned long flags)
220 + struct caam_dma_ctx *ctx = container_of(chan, struct caam_dma_ctx,
222 + struct device *jrdev = ctx->jrdev;
223 + struct caam_dma_edesc *edesc;
224 + struct sec4_sg_entry *sec4_sg;
225 + dma_addr_t sec4_sg_dma_src;
226 + unsigned int sec4_sg_bytes;
228 + if (!dst_sg || !src_sg || !dst_nents || !src_nents)
231 + sec4_sg_bytes = (src_nents + dst_nents) * sizeof(*sec4_sg);
233 + edesc = kzalloc(sizeof(*edesc) + DESC_JOB_IO_LEN + sec4_sg_bytes,
234 + GFP_DMA | GFP_NOWAIT);
236 + return ERR_PTR(-ENOMEM);
238 + edesc->src_len = caam_dma_sg_dma_len(src_sg, src_nents);
239 + edesc->dst_len = caam_dma_sg_dma_len(dst_sg, dst_nents);
240 + if (edesc->src_len != edesc->dst_len) {
241 + dev_err(jrdev, "%s: src(%u) and dst(%u) len mismatch.\n",
242 + __func__, edesc->src_len, edesc->dst_len);
244 + return ERR_PTR(-EINVAL);
247 + dma_async_tx_descriptor_init(&edesc->async_tx, chan);
248 + edesc->async_tx.tx_submit = caam_dma_tx_submit;
249 + edesc->async_tx.flags = flags;
250 + edesc->async_tx.cookie = -EBUSY;
252 + /* Prepare SEC SGs */
253 + edesc->sec4_sg = (void *)edesc + offsetof(struct caam_dma_edesc, jd) +
256 + sec4_sg = edesc->sec4_sg;
257 + sg_to_sec4_sg_last(src_sg, src_nents, sec4_sg, 0);
259 + sec4_sg += src_nents;
260 + sg_to_sec4_sg_last(dst_sg, dst_nents, sec4_sg, 0);
262 + sec4_sg_dma_src = dma_map_single(jrdev, edesc->sec4_sg, sec4_sg_bytes,
264 + if (dma_mapping_error(jrdev, sec4_sg_dma_src)) {
265 + dev_err(jrdev, "error mapping segments to device\n");
267 + return ERR_PTR(-ENOMEM);
270 + edesc->src_dma = sec4_sg_dma_src;
271 + edesc->dst_dma = sec4_sg_dma_src + src_nents * sizeof(*sec4_sg);
277 +static void caam_jr_chan_free_edesc(struct caam_dma_edesc *edesc)
279 + struct caam_dma_ctx *ctx = edesc->ctx;
280 + struct caam_dma_edesc *_edesc = NULL;
282 + spin_lock_bh(&ctx->edesc_lock);
284 + list_add_tail(&edesc->node, &ctx->done_not_acked);
285 + list_for_each_entry_safe(edesc, _edesc, &ctx->done_not_acked, node) {
286 + if (async_tx_test_ack(&edesc->async_tx)) {
287 + list_del(&edesc->node);
292 + spin_unlock_bh(&ctx->edesc_lock);
295 +static void caam_dma_done(struct device *dev, u32 *hwdesc, u32 err,
298 + struct caam_dma_edesc *edesc = context;
299 + struct caam_dma_ctx *ctx = edesc->ctx;
300 + dma_async_tx_callback callback;
301 + void *callback_param;
304 + caam_jr_strstatus(ctx->jrdev, err);
306 + dma_run_dependencies(&edesc->async_tx);
308 + spin_lock_bh(&ctx->edesc_lock);
309 + dma_cookie_complete(&edesc->async_tx);
310 + spin_unlock_bh(&ctx->edesc_lock);
312 + callback = edesc->async_tx.callback;
313 + callback_param = edesc->async_tx.callback_param;
315 + dma_descriptor_unmap(&edesc->async_tx);
317 + caam_jr_chan_free_edesc(edesc);
320 + callback(callback_param);
323 +static void caam_dma_sg_init_job_desc(struct caam_dma_edesc *edesc)
325 + u32 *jd = edesc->jd;
326 + u32 *sh_desc = dma_sh_desc->desc;
327 + dma_addr_t desc_dma = dma_sh_desc->desc_dma;
329 + /* init the job descriptor */
330 + init_job_desc_shared(jd, desc_dma, desc_len(sh_desc), HDR_REVERSE);
332 + /* set SEQIN PTR */
333 + append_seq_in_ptr(jd, edesc->src_dma, edesc->src_len, LDST_SGF);
335 + /* set SEQOUT PTR */
336 + append_seq_out_ptr(jd, edesc->dst_dma, edesc->dst_len, LDST_SGF);
339 + print_hex_dump(KERN_ERR, "caam dma desc@" __stringify(__LINE__) ": ",
340 + DUMP_PREFIX_ADDRESS, 16, 4, jd, desc_bytes(jd), 1);
344 +/* This function can be called from an interrupt context */
345 +static struct dma_async_tx_descriptor *
346 +caam_dma_prep_sg(struct dma_chan *chan, struct scatterlist *dst_sg,
347 + unsigned int dst_nents, struct scatterlist *src_sg,
348 + unsigned int src_nents, unsigned long flags)
350 + struct caam_dma_edesc *edesc;
352 + /* allocate extended descriptor */
353 + edesc = caam_dma_sg_edesc_alloc(chan, dst_sg, dst_nents, src_sg,
355 + if (IS_ERR_OR_NULL(edesc))
356 + return ERR_CAST(edesc);
358 + /* Initialize job descriptor */
359 + caam_dma_sg_init_job_desc(edesc);
361 + return &edesc->async_tx;
364 +static void caam_dma_memcpy_init_job_desc(struct caam_dma_edesc *edesc)
366 + u32 *jd = edesc->jd;
367 + u32 *sh_desc = dma_sh_desc->desc;
368 + dma_addr_t desc_dma = dma_sh_desc->desc_dma;
370 + /* init the job descriptor */
371 + init_job_desc_shared(jd, desc_dma, desc_len(sh_desc), HDR_REVERSE);
373 + /* set SEQIN PTR */
374 + append_seq_in_ptr(jd, edesc->src_dma, edesc->src_len, 0);
376 + /* set SEQOUT PTR */
377 + append_seq_out_ptr(jd, edesc->dst_dma, edesc->dst_len, 0);
380 + print_hex_dump(KERN_ERR, "caam dma desc@" __stringify(__LINE__) ": ",
381 + DUMP_PREFIX_ADDRESS, 16, 4, jd, desc_bytes(jd), 1);
385 +static struct dma_async_tx_descriptor *
386 +caam_dma_prep_memcpy(struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
387 + size_t len, unsigned long flags)
389 + struct caam_dma_edesc *edesc;
390 + struct caam_dma_ctx *ctx = container_of(chan, struct caam_dma_ctx,
393 + edesc = kzalloc(sizeof(*edesc) + DESC_JOB_IO_LEN, GFP_DMA | GFP_NOWAIT);
395 + return ERR_PTR(-ENOMEM);
397 + dma_async_tx_descriptor_init(&edesc->async_tx, chan);
398 + edesc->async_tx.tx_submit = caam_dma_tx_submit;
399 + edesc->async_tx.flags = flags;
400 + edesc->async_tx.cookie = -EBUSY;
402 + edesc->src_dma = src;
403 + edesc->src_len = len;
404 + edesc->dst_dma = dst;
405 + edesc->dst_len = len;
408 + caam_dma_memcpy_init_job_desc(edesc);
410 + return &edesc->async_tx;
413 +/* This function can be called in an interrupt context */
414 +static void caam_dma_issue_pending(struct dma_chan *chan)
416 + struct caam_dma_ctx *ctx = container_of(chan, struct caam_dma_ctx,
418 + struct caam_dma_edesc *edesc, *_edesc;
420 + spin_lock_bh(&ctx->edesc_lock);
421 + list_for_each_entry_safe(edesc, _edesc, &ctx->submit_q, node) {
422 + if (caam_jr_enqueue(ctx->jrdev, edesc->jd,
423 + caam_dma_done, edesc) < 0)
425 + list_del(&edesc->node);
427 + spin_unlock_bh(&ctx->edesc_lock);
430 +static void caam_dma_free_chan_resources(struct dma_chan *chan)
432 + struct caam_dma_ctx *ctx = container_of(chan, struct caam_dma_ctx,
434 + struct caam_dma_edesc *edesc, *_edesc;
436 + spin_lock_bh(&ctx->edesc_lock);
437 + list_for_each_entry_safe(edesc, _edesc, &ctx->submit_q, node) {
438 + list_del(&edesc->node);
441 + list_for_each_entry_safe(edesc, _edesc, &ctx->done_not_acked, node) {
442 + list_del(&edesc->node);
445 + spin_unlock_bh(&ctx->edesc_lock);
448 +static int caam_dma_jr_chan_bind(void)
450 + struct device *jrdev;
451 + struct caam_dma_ctx *ctx;
455 + for (i = 0; i < caam_jr_driver_probed(); i++) {
456 + jrdev = caam_jridx_alloc(i);
457 + if (IS_ERR(jrdev)) {
458 + pr_err("job ring device %d allocation failed\n", i);
462 + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
464 + caam_jr_free(jrdev);
468 + ctx->chan.device = dma_dev;
469 + ctx->chan.private = ctx;
471 + ctx->jrdev = jrdev;
473 + INIT_LIST_HEAD(&ctx->submit_q);
474 + INIT_LIST_HEAD(&ctx->done_not_acked);
475 + INIT_LIST_HEAD(&ctx->node);
476 + spin_lock_init(&ctx->edesc_lock);
478 + dma_cookie_init(&ctx->chan);
480 + /* add the context of this channel to the context list */
481 + list_add_tail(&ctx->node, &dma_ctx_list);
483 + /* add this channel to the device chan list */
484 + list_add_tail(&ctx->chan.device_node, &dma_dev->channels);
492 +static inline void caam_jr_dma_free(struct dma_chan *chan)
494 + struct caam_dma_ctx *ctx = container_of(chan, struct caam_dma_ctx,
497 + list_del(&ctx->node);
498 + list_del(&chan->device_node);
499 + caam_jr_free(ctx->jrdev);
503 +static void set_caam_dma_desc(u32 *desc)
507 + /* dma shared descriptor */
508 + init_sh_desc(desc, HDR_SHARE_NEVER | (1 << HDR_START_IDX_SHIFT));
510 + /* REG1 = CAAM_DMA_CHUNK_SIZE */
511 + append_math_add_imm_u32(desc, REG1, ZERO, IMM, CAAM_DMA_CHUNK_SIZE);
513 + /* REG0 = SEQINLEN - CAAM_DMA_CHUNK_SIZE */
514 + append_math_sub_imm_u32(desc, REG0, SEQINLEN, IMM, CAAM_DMA_CHUNK_SIZE);
519 + jmp_cmd = append_jump(desc, JUMP_TEST_INVALL | JUMP_COND_MATH_N |
522 + /* REG1 = SEQINLEN */
523 + append_math_sub(desc, REG1, SEQINLEN, ZERO, CAAM_CMD_SZ);
526 + set_jump_tgt_here(desc, jmp_cmd);
528 + /* VARSEQINLEN = REG1 */
529 + append_math_add(desc, VARSEQINLEN, REG1, ZERO, CAAM_CMD_SZ);
531 + /* VARSEQOUTLEN = REG1 */
532 + append_math_add(desc, VARSEQOUTLEN, REG1, ZERO, CAAM_CMD_SZ);
534 + /* do FIFO STORE */
535 + append_seq_fifo_store(desc, 0, FIFOST_TYPE_METADATA | LDST_VLF);
538 + append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
539 + FIFOLD_TYPE_IFIFO | LDST_VLF);
542 + * jmp 0xF8 (after shared desc header)
544 + append_jump(desc, JUMP_TEST_INVALL | JUMP_COND_MATH_N |
545 + JUMP_COND_MATH_Z | 0xF8);
548 + print_hex_dump(KERN_ERR, "caam dma shdesc@" __stringify(__LINE__) ": ",
549 + DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
553 +static int __init caam_dma_probe(struct platform_device *pdev)
555 + struct device *dev = &pdev->dev;
556 + struct device *ctrldev = dev->parent;
557 + struct dma_chan *chan, *_chan;
562 + if (!caam_jr_driver_probed()) {
563 + dev_info(dev, "Defer probing after JR driver probing\n");
564 + return -EPROBE_DEFER;
567 + dma_dev = kzalloc(sizeof(*dma_dev), GFP_KERNEL);
571 + dma_sh_desc = kzalloc(sizeof(*dma_sh_desc), GFP_KERNEL | GFP_DMA);
575 + sh_desc = dma_sh_desc->desc;
576 + set_caam_dma_desc(sh_desc);
577 + dma_sh_desc->desc_dma = dma_map_single(ctrldev, sh_desc,
578 + desc_bytes(sh_desc),
580 + if (dma_mapping_error(ctrldev, dma_sh_desc->desc_dma)) {
581 + dev_err(dev, "unable to map dma descriptor\n");
585 + INIT_LIST_HEAD(&dma_dev->channels);
587 + bonds = caam_dma_jr_chan_bind();
593 + dma_dev->dev = dev;
594 + dma_dev->residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
595 + dma_cap_set(DMA_SG, dma_dev->cap_mask);
596 + dma_cap_set(DMA_MEMCPY, dma_dev->cap_mask);
597 + dma_cap_set(DMA_PRIVATE, dma_dev->cap_mask);
598 + dma_dev->device_tx_status = dma_cookie_status;
599 + dma_dev->device_issue_pending = caam_dma_issue_pending;
600 + dma_dev->device_prep_dma_sg = caam_dma_prep_sg;
601 + dma_dev->device_prep_dma_memcpy = caam_dma_prep_memcpy;
602 + dma_dev->device_free_chan_resources = caam_dma_free_chan_resources;
604 + err = dma_async_device_register(dma_dev);
606 + dev_err(dev, "Failed to register CAAM DMA engine\n");
610 + dev_info(dev, "caam dma support with %d job rings\n", bonds);
615 + list_for_each_entry_safe(chan, _chan, &dma_dev->channels, device_node)
616 + caam_jr_dma_free(chan);
618 + dma_unmap_single(ctrldev, dma_sh_desc->desc_dma, desc_bytes(sh_desc),
621 + kfree(dma_sh_desc);
627 +static int caam_dma_remove(struct platform_device *pdev)
629 + struct device *dev = &pdev->dev;
630 + struct device *ctrldev = dev->parent;
631 + struct caam_dma_ctx *ctx, *_ctx;
633 + dma_async_device_unregister(dma_dev);
635 + list_for_each_entry_safe(ctx, _ctx, &dma_ctx_list, node) {
636 + list_del(&ctx->node);
637 + caam_jr_free(ctx->jrdev);
641 + dma_unmap_single(ctrldev, dma_sh_desc->desc_dma,
642 + desc_bytes(dma_sh_desc->desc), DMA_TO_DEVICE);
644 + kfree(dma_sh_desc);
647 + dev_info(dev, "caam dma support disabled\n");
651 +static const struct of_device_id caam_dma_match[] = {
652 + { .compatible = "fsl,sec-v5.4-dma", },
653 + { .compatible = "fsl,sec-v5.0-dma", },
654 + { .compatible = "fsl,sec-v4.0-dma", },
657 +MODULE_DEVICE_TABLE(of, caam_dma_match);
659 +static struct platform_driver caam_dma_driver = {
661 + .name = "caam-dma",
662 + .of_match_table = caam_dma_match,
664 + .probe = caam_dma_probe,
665 + .remove = caam_dma_remove,
667 +module_platform_driver(caam_dma_driver);
669 +MODULE_LICENSE("Dual BSD/GPL");
670 +MODULE_DESCRIPTION("NXP CAAM support for SG DMA");
671 +MODULE_AUTHOR("NXP Semiconductors");
672 diff --git a/drivers/dma/dpaa2-qdma/Kconfig b/drivers/dma/dpaa2-qdma/Kconfig
674 index 00000000..084e34bf
676 +++ b/drivers/dma/dpaa2-qdma/Kconfig
678 +menuconfig FSL_DPAA2_QDMA
679 + tristate "NXP DPAA2 QDMA"
680 + depends on FSL_MC_BUS && FSL_MC_DPIO
682 + select DMA_VIRTUAL_CHANNELS
684 + NXP Data Path Acceleration Architecture 2 QDMA driver,
685 + using the NXP MC bus driver.
686 diff --git a/drivers/dma/dpaa2-qdma/Makefile b/drivers/dma/dpaa2-qdma/Makefile
688 index 00000000..ba599ac6
690 +++ b/drivers/dma/dpaa2-qdma/Makefile
693 +# Makefile for the NXP DPAA2 CAAM controllers
695 +ccflags-y += -DVERSION=\"\"
697 +obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma.o
699 +fsl-dpaa2-qdma-objs := dpaa2-qdma.o dpdmai.o
700 diff --git a/drivers/dma/dpaa2-qdma/dpaa2-qdma.c b/drivers/dma/dpaa2-qdma/dpaa2-qdma.c
702 index 00000000..ad6b03f7
704 +++ b/drivers/dma/dpaa2-qdma/dpaa2-qdma.c
707 + * drivers/dma/dpaa2-qdma/dpaa2-qdma.c
709 + * Copyright 2015-2017 NXP Semiconductor, Inc.
710 + * Author: Changming Huang <jerry.huang@nxp.com>
712 + * Driver for the NXP QDMA engine with QMan mode.
713 + * Channel virtualization is supported through enqueuing of DMA jobs to,
714 + * or dequeuing DMA jobs from different work queues with QMan portal.
715 + * This module can be found on NXP LS2 SoCs.
717 + * This program is free software; you can redistribute it and/or modify it
718 + * under the terms of the GNU General Public License as published by the
719 + * Free Software Foundation; either version 2 of the License, or (at your
720 + * option) any later version.
723 +#include <linux/init.h>
724 +#include <linux/module.h>
725 +#include <linux/interrupt.h>
726 +#include <linux/clk.h>
727 +#include <linux/dma-mapping.h>
728 +#include <linux/dmapool.h>
729 +#include <linux/slab.h>
730 +#include <linux/spinlock.h>
731 +#include <linux/of.h>
732 +#include <linux/of_device.h>
733 +#include <linux/of_address.h>
734 +#include <linux/of_irq.h>
735 +#include <linux/of_dma.h>
736 +#include <linux/types.h>
737 +#include <linux/delay.h>
738 +#include <linux/iommu.h>
740 +#include "../virt-dma.h"
742 +#include "../../../drivers/staging/fsl-mc/include/mc.h"
743 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-io.h"
744 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
745 +#include "fsl_dpdmai_cmd.h"
746 +#include "fsl_dpdmai.h"
747 +#include "dpaa2-qdma.h"
749 +static bool smmu_disable = true;
751 +static struct dpaa2_qdma_chan *to_dpaa2_qdma_chan(struct dma_chan *chan)
753 + return container_of(chan, struct dpaa2_qdma_chan, vchan.chan);
756 +static struct dpaa2_qdma_comp *to_fsl_qdma_comp(struct virt_dma_desc *vd)
758 + return container_of(vd, struct dpaa2_qdma_comp, vdesc);
761 +static int dpaa2_qdma_alloc_chan_resources(struct dma_chan *chan)
766 +static void dpaa2_qdma_free_chan_resources(struct dma_chan *chan)
768 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
769 + unsigned long flags;
772 + spin_lock_irqsave(&dpaa2_chan->vchan.lock, flags);
773 + vchan_get_all_descriptors(&dpaa2_chan->vchan, &head);
774 + spin_unlock_irqrestore(&dpaa2_chan->vchan.lock, flags);
776 + vchan_dma_desc_free_list(&dpaa2_chan->vchan, &head);
780 + * Request a command descriptor for enqueue.
782 +static struct dpaa2_qdma_comp *
783 +dpaa2_qdma_request_desc(struct dpaa2_qdma_chan *dpaa2_chan)
785 + struct dpaa2_qdma_comp *comp_temp = NULL;
786 + unsigned long flags;
788 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
789 + if (list_empty(&dpaa2_chan->comp_free)) {
790 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
791 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
794 + comp_temp->fd_virt_addr = dma_pool_alloc(dpaa2_chan->fd_pool,
795 + GFP_NOWAIT, &comp_temp->fd_bus_addr);
796 + if (!comp_temp->fd_virt_addr)
799 + comp_temp->fl_virt_addr =
800 + (void *)((struct dpaa2_fd *)
801 + comp_temp->fd_virt_addr + 1);
802 + comp_temp->fl_bus_addr = comp_temp->fd_bus_addr +
803 + sizeof(struct dpaa2_fd);
804 + comp_temp->desc_virt_addr =
805 + (void *)((struct dpaa2_frame_list *)
806 + comp_temp->fl_virt_addr + 3);
807 + comp_temp->desc_bus_addr = comp_temp->fl_bus_addr +
808 + sizeof(struct dpaa2_frame_list) * 3;
810 + comp_temp->qchan = dpaa2_chan;
811 + comp_temp->sg_blk_num = 0;
812 + INIT_LIST_HEAD(&comp_temp->sg_src_head);
813 + INIT_LIST_HEAD(&comp_temp->sg_dst_head);
816 + comp_temp = list_first_entry(&dpaa2_chan->comp_free,
817 + struct dpaa2_qdma_comp, list);
818 + list_del(&comp_temp->list);
819 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
821 + comp_temp->qchan = dpaa2_chan;
826 +static void dpaa2_qdma_populate_fd(uint32_t format,
827 + struct dpaa2_qdma_comp *dpaa2_comp)
829 + struct dpaa2_fd *fd;
831 + fd = (struct dpaa2_fd *)dpaa2_comp->fd_virt_addr;
832 + memset(fd, 0, sizeof(struct dpaa2_fd));
835 + fd->simple.addr = dpaa2_comp->fl_bus_addr;
836 + /* Bypass memory translation, Frame list format, short length disable */
837 + /* we need to disable BMT if fsl-mc use iova addr */
839 + fd->simple.bpid = QMAN_FD_BMT_ENABLE;
840 + fd->simple.format_offset = QMAN_FD_FMT_ENABLE | QMAN_FD_SL_DISABLE;
842 + fd->simple.frc = format | QDMA_SER_CTX;
845 +/* first frame list for descriptor buffer */
846 +static void dpaa2_qdma_populate_first_framel(
847 + struct dpaa2_frame_list *f_list,
848 + struct dpaa2_qdma_comp *dpaa2_comp)
850 + struct dpaa2_qdma_sd_d *sdd;
852 + sdd = (struct dpaa2_qdma_sd_d *)dpaa2_comp->desc_virt_addr;
853 + memset(sdd, 0, 2 * (sizeof(*sdd)));
854 + /* source and destination descriptor */
855 + sdd->cmd = QDMA_SD_CMD_RDTTYPE_COHERENT; /* source descriptor CMD */
857 + sdd->cmd = QDMA_DD_CMD_WRTTYPE_COHERENT; /* dest descriptor CMD */
859 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
860 + /* first frame list to source descriptor */
861 + f_list->addr_lo = dpaa2_comp->desc_bus_addr;
862 + f_list->addr_hi = (dpaa2_comp->desc_bus_addr >> 32);
863 + f_list->data_len.data_len_sl0 = 0x20; /* source/destination desc len */
864 + f_list->fmt = QDMA_FL_FMT_SBF; /* single buffer frame */
866 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
867 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
868 + f_list->f = 0; /* not the last frame list */
871 +/* source and destination frame list */
872 +static void dpaa2_qdma_populate_frames(struct dpaa2_frame_list *f_list,
873 + dma_addr_t dst, dma_addr_t src, size_t len, uint8_t fmt)
875 + /* source frame list to source buffer */
876 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
877 + f_list->addr_lo = src;
878 + f_list->addr_hi = (src >> 32);
879 + f_list->data_len.data_len_sl0 = len;
880 + f_list->fmt = fmt; /* single buffer frame or scatter gather frame */
882 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
883 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
884 + f_list->f = 0; /* not the last frame list */
887 + /* destination frame list to destination buffer */
888 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
889 + f_list->addr_lo = dst;
890 + f_list->addr_hi = (dst >> 32);
891 + f_list->data_len.data_len_sl0 = len;
892 + f_list->fmt = fmt; /* single buffer frame or scatter gather frame */
894 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
895 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
896 + f_list->f = QDMA_FL_F; /* Final bit: 1, for last frame list */
899 +static struct dma_async_tx_descriptor *dpaa2_qdma_prep_memcpy(
900 + struct dma_chan *chan, dma_addr_t dst,
901 + dma_addr_t src, size_t len, unsigned long flags)
903 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
904 + struct dpaa2_qdma_comp *dpaa2_comp;
905 + struct dpaa2_frame_list *f_list;
908 + dpaa2_comp = dpaa2_qdma_request_desc(dpaa2_chan);
911 + format = QDMA_FD_LONG_FORMAT;
913 + format = QDMA_FD_SHORT_FORMAT;
915 + /* populate Frame descriptor */
916 + dpaa2_qdma_populate_fd(format, dpaa2_comp);
918 + f_list = (struct dpaa2_frame_list *)dpaa2_comp->fl_virt_addr;
921 + /* first frame list for descriptor buffer (logn format) */
922 + dpaa2_qdma_populate_first_framel(f_list, dpaa2_comp);
927 + dpaa2_qdma_populate_frames(f_list, dst, src, len, QDMA_FL_FMT_SBF);
929 + return vchan_tx_prep(&dpaa2_chan->vchan, &dpaa2_comp->vdesc, flags);
932 +static struct qdma_sg_blk *dpaa2_qdma_get_sg_blk(
933 + struct dpaa2_qdma_comp *dpaa2_comp,
934 + struct dpaa2_qdma_chan *dpaa2_chan)
936 + struct qdma_sg_blk *sg_blk = NULL;
937 + dma_addr_t phy_sgb;
938 + unsigned long flags;
940 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
941 + if (list_empty(&dpaa2_chan->sgb_free)) {
942 + sg_blk = (struct qdma_sg_blk *)dma_pool_alloc(
943 + dpaa2_chan->sg_blk_pool,
944 + GFP_NOWAIT, &phy_sgb);
946 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
949 + sg_blk->blk_virt_addr = (void *)(sg_blk + 1);
950 + sg_blk->blk_bus_addr = phy_sgb + sizeof(*sg_blk);
952 + sg_blk = list_first_entry(&dpaa2_chan->sgb_free,
953 + struct qdma_sg_blk, list);
954 + list_del(&sg_blk->list);
956 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
961 +static uint32_t dpaa2_qdma_populate_sg(struct device *dev,
962 + struct dpaa2_qdma_chan *dpaa2_chan,
963 + struct dpaa2_qdma_comp *dpaa2_comp,
964 + struct scatterlist *dst_sg, u32 dst_nents,
965 + struct scatterlist *src_sg, u32 src_nents)
967 + struct dpaa2_qdma_sg *src_sge;
968 + struct dpaa2_qdma_sg *dst_sge;
969 + struct qdma_sg_blk *sg_blk;
970 + struct qdma_sg_blk *sg_blk_dst;
976 + uint32_t total_len = 0;
979 + num = min(dst_nents, src_nents);
980 + blocks = num / (NUM_SG_PER_BLK - 1);
981 + if (num % (NUM_SG_PER_BLK - 1))
983 + if (dpaa2_comp->sg_blk_num < blocks) {
984 + len = blocks - dpaa2_comp->sg_blk_num;
985 + for (i = 0; i < len; i++) {
986 + /* source sg blocks */
987 + sg_blk = dpaa2_qdma_get_sg_blk(dpaa2_comp, dpaa2_chan);
990 + list_add_tail(&sg_blk->list, &dpaa2_comp->sg_src_head);
991 + /* destination sg blocks */
992 + sg_blk = dpaa2_qdma_get_sg_blk(dpaa2_comp, dpaa2_chan);
995 + list_add_tail(&sg_blk->list, &dpaa2_comp->sg_dst_head);
998 + len = dpaa2_comp->sg_blk_num - blocks;
999 + for (i = 0; i < len; i++) {
1000 + spin_lock(&dpaa2_chan->queue_lock);
1001 + /* handle source sg blocks */
1002 + sg_blk = list_first_entry(&dpaa2_comp->sg_src_head,
1003 + struct qdma_sg_blk, list);
1004 + list_del(&sg_blk->list);
1005 + list_add_tail(&sg_blk->list, &dpaa2_chan->sgb_free);
1006 + /* handle destination sg blocks */
1007 + sg_blk = list_first_entry(&dpaa2_comp->sg_dst_head,
1008 + struct qdma_sg_blk, list);
1009 + list_del(&sg_blk->list);
1010 + list_add_tail(&sg_blk->list, &dpaa2_chan->sgb_free);
1011 + spin_unlock(&dpaa2_chan->queue_lock);
1014 + dpaa2_comp->sg_blk_num = blocks;
1016 + /* get the first source sg phy address */
1017 + sg_blk = list_first_entry(&dpaa2_comp->sg_src_head,
1018 + struct qdma_sg_blk, list);
1019 + dpaa2_comp->sge_src_bus_addr = sg_blk->blk_bus_addr;
1020 + /* get the first destinaiton sg phy address */
1021 + sg_blk_dst = list_first_entry(&dpaa2_comp->sg_dst_head,
1022 + struct qdma_sg_blk, list);
1023 + dpaa2_comp->sge_dst_bus_addr = sg_blk_dst->blk_bus_addr;
1025 + for (i = 0; i < blocks; i++) {
1026 + src_sge = (struct dpaa2_qdma_sg *)sg_blk->blk_virt_addr;
1027 + dst_sge = (struct dpaa2_qdma_sg *)sg_blk_dst->blk_virt_addr;
1029 + for (j = 0; j < (NUM_SG_PER_BLK - 1); j++) {
1030 + len = min(sg_dma_len(dst_sg), sg_dma_len(src_sg));
1034 + src = sg_dma_address(src_sg);
1035 + dst = sg_dma_address(dst_sg);
1038 + src_sge->addr_lo = src;
1039 + src_sge->addr_hi = (src >> 32);
1040 + src_sge->data_len.data_len_sl0 = len;
1041 + src_sge->ctrl.sl = QDMA_SG_SL_LONG;
1042 + src_sge->ctrl.fmt = QDMA_SG_FMT_SDB;
1043 + /* destination SG */
1044 + dst_sge->addr_lo = dst;
1045 + dst_sge->addr_hi = (dst >> 32);
1046 + dst_sge->data_len.data_len_sl0 = len;
1047 + dst_sge->ctrl.sl = QDMA_SG_SL_LONG;
1048 + dst_sge->ctrl.fmt = QDMA_SG_FMT_SDB;
1052 + src_sge->ctrl.f = QDMA_SG_F;
1053 + dst_sge->ctrl.f = QDMA_SG_F;
1056 + dst_sg = sg_next(dst_sg);
1057 + src_sg = sg_next(src_sg);
1060 + if (j == (NUM_SG_PER_BLK - 2)) {
1061 + /* for next blocks, extension */
1062 + sg_blk = list_next_entry(sg_blk, list);
1063 + sg_blk_dst = list_next_entry(sg_blk_dst, list);
1064 + src_sge->addr_lo = sg_blk->blk_bus_addr;
1065 + src_sge->addr_hi = sg_blk->blk_bus_addr >> 32;
1066 + src_sge->ctrl.sl = QDMA_SG_SL_LONG;
1067 + src_sge->ctrl.fmt = QDMA_SG_FMT_SGTE;
1068 + dst_sge->addr_lo = sg_blk_dst->blk_bus_addr;
1069 + dst_sge->addr_hi =
1070 + sg_blk_dst->blk_bus_addr >> 32;
1071 + dst_sge->ctrl.sl = QDMA_SG_SL_LONG;
1072 + dst_sge->ctrl.fmt = QDMA_SG_FMT_SGTE;
1081 +static struct dma_async_tx_descriptor *dpaa2_qdma_prep_sg(
1082 + struct dma_chan *chan,
1083 + struct scatterlist *dst_sg, u32 dst_nents,
1084 + struct scatterlist *src_sg, u32 src_nents,
1085 + unsigned long flags)
1087 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
1088 + struct dpaa2_qdma_comp *dpaa2_comp;
1089 + struct dpaa2_frame_list *f_list;
1090 + struct device *dev = dpaa2_chan->qdma->priv->dev;
1091 + uint32_t total_len = 0;
1093 + /* basic sanity checks */
1094 + if (dst_nents == 0 || src_nents == 0)
1097 + if (dst_sg == NULL || src_sg == NULL)
1100 + /* get the descriptors required */
1101 + dpaa2_comp = dpaa2_qdma_request_desc(dpaa2_chan);
1103 + /* populate Frame descriptor */
1104 + dpaa2_qdma_populate_fd(QDMA_FD_LONG_FORMAT, dpaa2_comp);
1106 + /* prepare Scatter gather entry for source and destination */
1107 + total_len = dpaa2_qdma_populate_sg(dev, dpaa2_chan,
1108 + dpaa2_comp, dst_sg, dst_nents, src_sg, src_nents);
1110 + f_list = (struct dpaa2_frame_list *)dpaa2_comp->fl_virt_addr;
1111 + /* first frame list for descriptor buffer */
1112 + dpaa2_qdma_populate_first_framel(f_list, dpaa2_comp);
1114 + /* prepare Scatter gather entry for source and destination */
1115 + /* populate source and destination frame list table */
1116 + dpaa2_qdma_populate_frames(f_list, dpaa2_comp->sge_dst_bus_addr,
1117 + dpaa2_comp->sge_src_bus_addr,
1118 + total_len, QDMA_FL_FMT_SGE);
1120 + return vchan_tx_prep(&dpaa2_chan->vchan, &dpaa2_comp->vdesc, flags);
1123 +static enum dma_status dpaa2_qdma_tx_status(struct dma_chan *chan,
1124 + dma_cookie_t cookie, struct dma_tx_state *txstate)
1126 + return dma_cookie_status(chan, cookie, txstate);
1129 +static void dpaa2_qdma_free_desc(struct virt_dma_desc *vdesc)
1133 +static void dpaa2_qdma_issue_pending(struct dma_chan *chan)
1135 + struct dpaa2_qdma_comp *dpaa2_comp;
1136 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
1137 + struct dpaa2_qdma_engine *dpaa2_qdma = dpaa2_chan->qdma;
1138 + struct dpaa2_qdma_priv *priv = dpaa2_qdma->priv;
1139 + struct virt_dma_desc *vdesc;
1140 + struct dpaa2_fd *fd;
1142 + unsigned long flags;
1144 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
1145 + spin_lock(&dpaa2_chan->vchan.lock);
1146 + if (vchan_issue_pending(&dpaa2_chan->vchan)) {
1147 + vdesc = vchan_next_desc(&dpaa2_chan->vchan);
1150 + dpaa2_comp = to_fsl_qdma_comp(vdesc);
1152 + fd = (struct dpaa2_fd *)dpaa2_comp->fd_virt_addr;
1154 + list_del(&vdesc->node);
1155 + list_add_tail(&dpaa2_comp->list, &dpaa2_chan->comp_used);
1157 + /* TOBO: priority hard-coded to zero */
1158 + err = dpaa2_io_service_enqueue_fq(NULL,
1159 + priv->tx_queue_attr[0].fqid, fd);
1161 + list_del(&dpaa2_comp->list);
1162 + list_add_tail(&dpaa2_comp->list,
1163 + &dpaa2_chan->comp_free);
1168 + spin_unlock(&dpaa2_chan->vchan.lock);
1169 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
1172 +static int __cold dpaa2_qdma_setup(struct fsl_mc_device *ls_dev)
1174 + struct device *dev = &ls_dev->dev;
1175 + struct dpaa2_qdma_priv *priv;
1176 + struct dpaa2_qdma_priv_per_prio *ppriv;
1177 + uint8_t prio_def = DPDMAI_PRIO_NUM;
1181 + priv = dev_get_drvdata(dev);
1184 + priv->dpqdma_id = ls_dev->obj_desc.id;
1186 + /*Get the handle for the DPDMAI this interface is associate with */
1187 + err = dpdmai_open(priv->mc_io, 0, priv->dpqdma_id, &ls_dev->mc_handle);
1189 + dev_err(dev, "dpdmai_open() failed\n");
1192 + dev_info(dev, "Opened dpdmai object successfully\n");
1194 + err = dpdmai_get_attributes(priv->mc_io, 0, ls_dev->mc_handle,
1195 + &priv->dpdmai_attr);
1197 + dev_err(dev, "dpdmai_get_attributes() failed\n");
1201 + if (priv->dpdmai_attr.version.major > DPDMAI_VER_MAJOR) {
1202 + dev_err(dev, "DPDMAI major version mismatch\n"
1203 + "Found %u.%u, supported version is %u.%u\n",
1204 + priv->dpdmai_attr.version.major,
1205 + priv->dpdmai_attr.version.minor,
1206 + DPDMAI_VER_MAJOR, DPDMAI_VER_MINOR);
1209 + if (priv->dpdmai_attr.version.minor > DPDMAI_VER_MINOR) {
1210 + dev_err(dev, "DPDMAI minor version mismatch\n"
1211 + "Found %u.%u, supported version is %u.%u\n",
1212 + priv->dpdmai_attr.version.major,
1213 + priv->dpdmai_attr.version.minor,
1214 + DPDMAI_VER_MAJOR, DPDMAI_VER_MINOR);
1217 + priv->num_pairs = min(priv->dpdmai_attr.num_of_priorities, prio_def);
1218 + ppriv = kcalloc(priv->num_pairs, sizeof(*ppriv), GFP_KERNEL);
1220 + dev_err(dev, "kzalloc for ppriv failed\n");
1223 + priv->ppriv = ppriv;
1225 + for (i = 0; i < priv->num_pairs; i++) {
1226 + err = dpdmai_get_rx_queue(priv->mc_io, 0, ls_dev->mc_handle,
1227 + i, &priv->rx_queue_attr[i]);
1229 + dev_err(dev, "dpdmai_get_rx_queue() failed\n");
1232 + ppriv->rsp_fqid = priv->rx_queue_attr[i].fqid;
1234 + err = dpdmai_get_tx_queue(priv->mc_io, 0, ls_dev->mc_handle,
1235 + i, &priv->tx_queue_attr[i]);
1237 + dev_err(dev, "dpdmai_get_tx_queue() failed\n");
1240 + ppriv->req_fqid = priv->tx_queue_attr[i].fqid;
1242 + ppriv->priv = priv;
1249 +static void dpaa2_qdma_fqdan_cb(struct dpaa2_io_notification_ctx *ctx)
1251 + struct dpaa2_qdma_priv_per_prio *ppriv = container_of(ctx,
1252 + struct dpaa2_qdma_priv_per_prio, nctx);
1253 + struct dpaa2_qdma_priv *priv = ppriv->priv;
1254 + struct dpaa2_qdma_comp *dpaa2_comp, *_comp_tmp;
1255 + struct dpaa2_qdma_chan *qchan;
1256 + const struct dpaa2_fd *fd;
1257 + const struct dpaa2_fd *fd_eq;
1258 + struct dpaa2_dq *dq;
1264 + uint32_t n_chans = priv->dpaa2_qdma->n_chans;
1267 + err = dpaa2_io_service_pull_fq(NULL, ppriv->rsp_fqid,
1271 + while (!is_last) {
1273 + dq = dpaa2_io_store_next(ppriv->store, &is_last);
1274 + } while (!is_last && !dq);
1276 + dev_err(priv->dev, "FQID returned no valid frames!\n");
1280 + /* obtain FD and process the error */
1281 + fd = dpaa2_dq_fd(dq);
1282 + status = fd->simple.ctrl & 0xff;
1284 + dev_err(priv->dev, "FD error occurred\n");
1286 + for (i = 0; i < n_chans; i++) {
1287 + qchan = &priv->dpaa2_qdma->chans[i];
1288 + spin_lock(&qchan->queue_lock);
1289 + if (list_empty(&qchan->comp_used)) {
1290 + spin_unlock(&qchan->queue_lock);
1293 + list_for_each_entry_safe(dpaa2_comp, _comp_tmp,
1294 + &qchan->comp_used, list) {
1295 + fd_eq = (struct dpaa2_fd *)
1296 + dpaa2_comp->fd_virt_addr;
1298 + if (fd_eq->simple.addr ==
1299 + fd->simple.addr) {
1301 + list_del(&dpaa2_comp->list);
1302 + list_add_tail(&dpaa2_comp->list,
1303 + &qchan->comp_free);
1305 + spin_lock(&qchan->vchan.lock);
1306 + vchan_cookie_complete(
1307 + &dpaa2_comp->vdesc);
1308 + spin_unlock(&qchan->vchan.lock);
1313 + spin_unlock(&qchan->queue_lock);
1319 + dpaa2_io_service_rearm(NULL, ctx);
1322 +static int __cold dpaa2_qdma_dpio_setup(struct dpaa2_qdma_priv *priv)
1325 + struct device *dev = priv->dev;
1326 + struct dpaa2_qdma_priv_per_prio *ppriv;
1328 + num = priv->num_pairs;
1329 + ppriv = priv->ppriv;
1330 + for (i = 0; i < num; i++) {
1331 + ppriv->nctx.is_cdan = 0;
1332 + ppriv->nctx.desired_cpu = 1;
1333 + ppriv->nctx.id = ppriv->rsp_fqid;
1334 + ppriv->nctx.cb = dpaa2_qdma_fqdan_cb;
1335 + err = dpaa2_io_service_register(NULL, &ppriv->nctx);
1337 + dev_err(dev, "Notification register failed\n");
1341 + ppriv->store = dpaa2_io_store_create(DPAA2_QDMA_STORE_SIZE,
1343 + if (!ppriv->store) {
1344 + dev_err(dev, "dpaa2_io_store_create() failed\n");
1353 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
1356 + while (ppriv >= priv->ppriv) {
1357 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
1358 + dpaa2_io_store_destroy(ppriv->store);
1364 +static void __cold dpaa2_dpmai_store_free(struct dpaa2_qdma_priv *priv)
1366 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
1369 + for (i = 0; i < priv->num_pairs; i++) {
1370 + dpaa2_io_store_destroy(ppriv->store);
1375 +static void __cold dpaa2_dpdmai_dpio_free(struct dpaa2_qdma_priv *priv)
1377 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
1380 + for (i = 0; i < priv->num_pairs; i++) {
1381 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
1386 +static int __cold dpaa2_dpdmai_bind(struct dpaa2_qdma_priv *priv)
1389 + struct dpdmai_rx_queue_cfg rx_queue_cfg;
1390 + struct device *dev = priv->dev;
1391 + struct dpaa2_qdma_priv_per_prio *ppriv;
1392 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
1395 + num = priv->num_pairs;
1396 + ppriv = priv->ppriv;
1397 + for (i = 0; i < num; i++) {
1398 + rx_queue_cfg.options = DPDMAI_QUEUE_OPT_USER_CTX |
1399 + DPDMAI_QUEUE_OPT_DEST;
1400 + rx_queue_cfg.user_ctx = ppriv->nctx.qman64;
1401 + rx_queue_cfg.dest_cfg.dest_type = DPDMAI_DEST_DPIO;
1402 + rx_queue_cfg.dest_cfg.dest_id = ppriv->nctx.dpio_id;
1403 + rx_queue_cfg.dest_cfg.priority = ppriv->prio;
1404 + err = dpdmai_set_rx_queue(priv->mc_io, 0, ls_dev->mc_handle,
1405 + rx_queue_cfg.dest_cfg.priority, &rx_queue_cfg);
1407 + dev_err(dev, "dpdmai_set_rx_queue() failed\n");
1417 +static int __cold dpaa2_dpdmai_dpio_unbind(struct dpaa2_qdma_priv *priv)
1420 + struct device *dev = priv->dev;
1421 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
1422 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
1425 + for (i = 0; i < priv->num_pairs; i++) {
1426 + ppriv->nctx.qman64 = 0;
1427 + ppriv->nctx.dpio_id = 0;
1431 + err = dpdmai_reset(priv->mc_io, 0, ls_dev->mc_handle);
1433 + dev_err(dev, "dpdmai_reset() failed\n");
1438 +static void __cold dpaa2_dpdmai_free_pool(struct dpaa2_qdma_chan *qchan,
1439 + struct list_head *head)
1441 + struct qdma_sg_blk *sgb_tmp, *_sgb_tmp;
1442 + /* free the QDMA SG pool block */
1443 + list_for_each_entry_safe(sgb_tmp, _sgb_tmp, head, list) {
1444 + sgb_tmp->blk_virt_addr = (void *)((struct qdma_sg_blk *)
1445 + sgb_tmp->blk_virt_addr - 1);
1446 + sgb_tmp->blk_bus_addr = sgb_tmp->blk_bus_addr
1447 + - sizeof(*sgb_tmp);
1448 + dma_pool_free(qchan->sg_blk_pool, sgb_tmp->blk_virt_addr,
1449 + sgb_tmp->blk_bus_addr);
1454 +static void __cold dpaa2_dpdmai_free_comp(struct dpaa2_qdma_chan *qchan,
1455 + struct list_head *head)
1457 + struct dpaa2_qdma_comp *comp_tmp, *_comp_tmp;
1458 + /* free the QDMA comp resource */
1459 + list_for_each_entry_safe(comp_tmp, _comp_tmp,
1461 + dma_pool_free(qchan->fd_pool,
1462 + comp_tmp->fd_virt_addr,
1463 + comp_tmp->fd_bus_addr);
1464 + /* free the SG source block on comp */
1465 + dpaa2_dpdmai_free_pool(qchan, &comp_tmp->sg_src_head);
1466 + /* free the SG destination block on comp */
1467 + dpaa2_dpdmai_free_pool(qchan, &comp_tmp->sg_dst_head);
1468 + list_del(&comp_tmp->list);
1474 +static void __cold dpaa2_dpdmai_free_channels(
1475 + struct dpaa2_qdma_engine *dpaa2_qdma)
1477 + struct dpaa2_qdma_chan *qchan;
1480 + num = dpaa2_qdma->n_chans;
1481 + for (i = 0; i < num; i++) {
1482 + qchan = &dpaa2_qdma->chans[i];
1483 + dpaa2_dpdmai_free_comp(qchan, &qchan->comp_used);
1484 + dpaa2_dpdmai_free_comp(qchan, &qchan->comp_free);
1485 + dpaa2_dpdmai_free_pool(qchan, &qchan->sgb_free);
1486 + dma_pool_destroy(qchan->fd_pool);
1487 + dma_pool_destroy(qchan->sg_blk_pool);
1491 +static int dpaa2_dpdmai_alloc_channels(struct dpaa2_qdma_engine *dpaa2_qdma)
1493 + struct dpaa2_qdma_chan *dpaa2_chan;
1494 + struct device *dev = &dpaa2_qdma->priv->dpdmai_dev->dev;
1497 + INIT_LIST_HEAD(&dpaa2_qdma->dma_dev.channels);
1498 + for (i = 0; i < dpaa2_qdma->n_chans; i++) {
1499 + dpaa2_chan = &dpaa2_qdma->chans[i];
1500 + dpaa2_chan->qdma = dpaa2_qdma;
1501 + dpaa2_chan->vchan.desc_free = dpaa2_qdma_free_desc;
1502 + vchan_init(&dpaa2_chan->vchan, &dpaa2_qdma->dma_dev);
1504 + dpaa2_chan->fd_pool = dma_pool_create("fd_pool",
1505 + dev, FD_POOL_SIZE, 32, 0);
1506 + if (!dpaa2_chan->fd_pool)
1508 + dpaa2_chan->sg_blk_pool = dma_pool_create("sg_blk_pool",
1509 + dev, SG_POOL_SIZE, 32, 0);
1510 + if (!dpaa2_chan->sg_blk_pool)
1513 + spin_lock_init(&dpaa2_chan->queue_lock);
1514 + INIT_LIST_HEAD(&dpaa2_chan->comp_used);
1515 + INIT_LIST_HEAD(&dpaa2_chan->comp_free);
1516 + INIT_LIST_HEAD(&dpaa2_chan->sgb_free);
1521 +static int dpaa2_qdma_probe(struct fsl_mc_device *dpdmai_dev)
1523 + struct dpaa2_qdma_priv *priv;
1524 + struct device *dev = &dpdmai_dev->dev;
1525 + struct dpaa2_qdma_engine *dpaa2_qdma;
1528 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1531 + dev_set_drvdata(dev, priv);
1532 + priv->dpdmai_dev = dpdmai_dev;
1534 + priv->iommu_domain = iommu_get_domain_for_dev(dev);
1535 + if (priv->iommu_domain)
1536 + smmu_disable = false;
1538 + /* obtain a MC portal */
1539 + err = fsl_mc_portal_allocate(dpdmai_dev, 0, &priv->mc_io);
1541 + dev_err(dev, "MC portal allocation failed\n");
1542 + goto err_mcportal;
1545 + /* DPDMAI initialization */
1546 + err = dpaa2_qdma_setup(dpdmai_dev);
1548 + dev_err(dev, "dpaa2_dpdmai_setup() failed\n");
1549 + goto err_dpdmai_setup;
1553 + err = dpaa2_qdma_dpio_setup(priv);
1555 + dev_err(dev, "dpaa2_dpdmai_dpio_setup() failed\n");
1556 + goto err_dpio_setup;
1559 + /* DPDMAI binding to DPIO */
1560 + err = dpaa2_dpdmai_bind(priv);
1562 + dev_err(dev, "dpaa2_dpdmai_bind() failed\n");
1566 + /* DPDMAI enable */
1567 + err = dpdmai_enable(priv->mc_io, 0, dpdmai_dev->mc_handle);
1569 + dev_err(dev, "dpdmai_enable() faile\n");
1573 + dpaa2_qdma = kzalloc(sizeof(*dpaa2_qdma), GFP_KERNEL);
1574 + if (!dpaa2_qdma) {
1579 + priv->dpaa2_qdma = dpaa2_qdma;
1580 + dpaa2_qdma->priv = priv;
1582 + dpaa2_qdma->n_chans = NUM_CH;
1584 + err = dpaa2_dpdmai_alloc_channels(dpaa2_qdma);
1586 + dev_err(dev, "QDMA alloc channels faile\n");
1590 + dma_cap_set(DMA_PRIVATE, dpaa2_qdma->dma_dev.cap_mask);
1591 + dma_cap_set(DMA_SLAVE, dpaa2_qdma->dma_dev.cap_mask);
1592 + dma_cap_set(DMA_MEMCPY, dpaa2_qdma->dma_dev.cap_mask);
1593 + dma_cap_set(DMA_SG, dpaa2_qdma->dma_dev.cap_mask);
1595 + dpaa2_qdma->dma_dev.dev = dev;
1596 + dpaa2_qdma->dma_dev.device_alloc_chan_resources
1597 + = dpaa2_qdma_alloc_chan_resources;
1598 + dpaa2_qdma->dma_dev.device_free_chan_resources
1599 + = dpaa2_qdma_free_chan_resources;
1600 + dpaa2_qdma->dma_dev.device_tx_status = dpaa2_qdma_tx_status;
1601 + dpaa2_qdma->dma_dev.device_prep_dma_memcpy = dpaa2_qdma_prep_memcpy;
1602 + dpaa2_qdma->dma_dev.device_prep_dma_sg = dpaa2_qdma_prep_sg;
1603 + dpaa2_qdma->dma_dev.device_issue_pending = dpaa2_qdma_issue_pending;
1605 + err = dma_async_device_register(&dpaa2_qdma->dma_dev);
1607 + dev_err(dev, "Can't register NXP QDMA engine.\n");
1614 + dpaa2_dpdmai_free_channels(dpaa2_qdma);
1615 + kfree(dpaa2_qdma);
1617 + dpdmai_disable(priv->mc_io, 0, dpdmai_dev->mc_handle);
1619 + dpaa2_dpdmai_dpio_unbind(priv);
1621 + dpaa2_dpmai_store_free(priv);
1622 + dpaa2_dpdmai_dpio_free(priv);
1624 + dpdmai_close(priv->mc_io, 0, dpdmai_dev->mc_handle);
1626 + fsl_mc_portal_free(priv->mc_io);
1628 + kfree(priv->ppriv);
1630 + dev_set_drvdata(dev, NULL);
1634 +static int dpaa2_qdma_remove(struct fsl_mc_device *ls_dev)
1636 + struct device *dev;
1637 + struct dpaa2_qdma_priv *priv;
1638 + struct dpaa2_qdma_engine *dpaa2_qdma;
1640 + dev = &ls_dev->dev;
1641 + priv = dev_get_drvdata(dev);
1642 + dpaa2_qdma = priv->dpaa2_qdma;
1644 + dpdmai_disable(priv->mc_io, 0, ls_dev->mc_handle);
1645 + dpaa2_dpdmai_dpio_unbind(priv);
1646 + dpaa2_dpmai_store_free(priv);
1647 + dpaa2_dpdmai_dpio_free(priv);
1648 + dpdmai_close(priv->mc_io, 0, ls_dev->mc_handle);
1649 + fsl_mc_portal_free(priv->mc_io);
1650 + dev_set_drvdata(dev, NULL);
1651 + dpaa2_dpdmai_free_channels(dpaa2_qdma);
1653 + dma_async_device_unregister(&dpaa2_qdma->dma_dev);
1655 + kfree(dpaa2_qdma);
1660 +static const struct fsl_mc_device_id dpaa2_qdma_id_table[] = {
1662 + .vendor = FSL_MC_VENDOR_FREESCALE,
1663 + .obj_type = "dpdmai",
1668 +static struct fsl_mc_driver dpaa2_qdma_driver = {
1670 + .name = "dpaa2-qdma",
1671 + .owner = THIS_MODULE,
1673 + .probe = dpaa2_qdma_probe,
1674 + .remove = dpaa2_qdma_remove,
1675 + .match_id_table = dpaa2_qdma_id_table
1678 +static int __init dpaa2_qdma_driver_init(void)
1680 + return fsl_mc_driver_register(&(dpaa2_qdma_driver));
1682 +late_initcall(dpaa2_qdma_driver_init);
1684 +static void __exit fsl_qdma_exit(void)
1686 + fsl_mc_driver_unregister(&(dpaa2_qdma_driver));
1688 +module_exit(fsl_qdma_exit);
1690 +MODULE_DESCRIPTION("NXP DPAA2 qDMA driver");
1691 +MODULE_LICENSE("Dual BSD/GPL");
1692 diff --git a/drivers/dma/dpaa2-qdma/dpaa2-qdma.h b/drivers/dma/dpaa2-qdma/dpaa2-qdma.h
1693 new file mode 100644
1694 index 00000000..71a00db8
1696 +++ b/drivers/dma/dpaa2-qdma/dpaa2-qdma.h
1698 +/* Copyright 2015 NXP Semiconductor Inc.
1700 + * Redistribution and use in source and binary forms, with or without
1701 + * modification, are permitted provided that the following conditions are met:
1702 + * * Redistributions of source code must retain the above copyright
1703 + * notice, this list of conditions and the following disclaimer.
1704 + * * Redistributions in binary form must reproduce the above copyright
1705 + * notice, this list of conditions and the following disclaimer in the
1706 + * documentation and/or other materials provided with the distribution.
1707 + * * Neither the name of NXP Semiconductor nor the
1708 + * names of its contributors may be used to endorse or promote products
1709 + * derived from this software without specific prior written permission.
1712 + * ALTERNATIVELY, this software may be distributed under the terms of the
1713 + * GNU General Public License ("GPL") as published by the Free Software
1714 + * Foundation, either version 2 of that License or (at your option) any
1717 + * THIS SOFTWARE IS PROVIDED BY NXP Semiconductor ``AS IS'' AND ANY
1718 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1719 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1720 + * DISCLAIMED. IN NO EVENT SHALL NXP Semiconductor BE LIABLE FOR ANY
1721 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1722 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1723 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1724 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1725 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1726 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1729 +#ifndef __DPAA2_QDMA_H
1730 +#define __DPAA2_QDMA_H
1732 +#define LONG_FORMAT 1
1734 +#define DPAA2_QDMA_STORE_SIZE 16
1736 +#define NUM_SG_PER_BLK 16
1738 +#define QDMA_DMR_OFFSET 0x0
1739 +#define QDMA_DQ_EN (0 << 30)
1740 +#define QDMA_DQ_DIS (1 << 30)
1742 +#define QDMA_DSR_M_OFFSET 0x10004
1744 +struct dpaa2_qdma_sd_d {
1748 + uint32_t ssd:12; /* souce stride distance */
1749 + uint32_t sss:12; /* souce stride size */
1753 + uint32_t dsd:12; /* Destination stride distance */
1754 + uint32_t dss:12; /* Destination stride size */
1758 + uint32_t rbpcmd; /* Route-by-port command */
1760 +} __attribute__((__packed__));
1761 +/* Source descriptor command read transaction type for RBP=0:
1762 + coherent copy of cacheable memory */
1763 +#define QDMA_SD_CMD_RDTTYPE_COHERENT (0xb << 28)
1764 +/* Destination descriptor command write transaction type for RBP=0:
1765 + coherent copy of cacheable memory */
1766 +#define QDMA_DD_CMD_WRTTYPE_COHERENT (0x6 << 28)
1768 +#define QDMA_SG_FMT_SDB 0x0 /* single data buffer */
1769 +#define QDMA_SG_FMT_FDS 0x1 /* frame data section */
1770 +#define QDMA_SG_FMT_SGTE 0x2 /* SGT extension */
1771 +#define QDMA_SG_SL_SHORT 0x1 /* short length */
1772 +#define QDMA_SG_SL_LONG 0x0 /* short length */
1773 +#define QDMA_SG_F 0x1 /* last sg entry */
1774 +struct dpaa2_qdma_sg {
1775 + uint32_t addr_lo; /* address 0:31 */
1776 + uint32_t addr_hi:17; /* address 32:48 */
1779 + uint32_t data_len_sl0; /* SL=0, the long format */
1781 + uint32_t len:17; /* SL=1, the short format */
1782 + uint32_t reserve:3;
1785 + uint32_t size:10; /* buff size */
1787 + } data_len; /* AVAIL_LENGTH */
1792 + uint32_t offset:12;
1797 +} __attribute__((__packed__));
1799 +#define QMAN_FD_FMT_ENABLE (1 << 12) /* frame list table enable */
1800 +#define QMAN_FD_BMT_ENABLE (1 << 15) /* bypass memory translation */
1801 +#define QMAN_FD_BMT_DISABLE (0 << 15) /* bypass memory translation */
1802 +#define QMAN_FD_SL_DISABLE (0 << 14) /* short lengthe disabled */
1803 +#define QMAN_FD_SL_ENABLE (1 << 14) /* short lengthe enabled */
1805 +#define QDMA_SB_FRAME (0 << 28) /* single frame */
1806 +#define QDMA_SG_FRAME (2 << 28) /* scatter gather frames */
1807 +#define QDMA_FINAL_BIT_DISABLE (0 << 31) /* final bit disable */
1808 +#define QDMA_FINAL_BIT_ENABLE (1 << 31) /* final bit enable */
1810 +#define QDMA_FD_SHORT_FORMAT (1 << 11) /* short format */
1811 +#define QDMA_FD_LONG_FORMAT (0 << 11) /* long format */
1812 +#define QDMA_SER_DISABLE (0 << 8) /* no notification */
1813 +#define QDMA_SER_CTX (1 << 8) /* notification by FQD_CTX[fqid] */
1814 +#define QDMA_SER_DEST (2 << 8) /* notification by destination desc */
1815 +#define QDMA_SER_BOTH (3 << 8) /* soruce and dest notification */
1816 +#define QDMA_FD_SPF_ENALBE (1 << 30) /* source prefetch enable */
1818 +#define QMAN_FD_VA_ENABLE (1 << 14) /* Address used is virtual address */
1819 +#define QMAN_FD_VA_DISABLE (0 << 14)/* Address used is a real address */
1820 +#define QMAN_FD_CBMT_ENABLE (1 << 15) /* Flow Context: 49bit physical address */
1821 +#define QMAN_FD_CBMT_DISABLE (0 << 15) /* Flow Context: 64bit virtual address */
1822 +#define QMAN_FD_SC_DISABLE (0 << 27) /* stashing control */
1824 +#define QDMA_FL_FMT_SBF 0x0 /* Single buffer frame */
1825 +#define QDMA_FL_FMT_SGE 0x2 /* Scatter gather frame */
1826 +#define QDMA_FL_BMT_ENABLE 0x1 /* enable bypass memory translation */
1827 +#define QDMA_FL_BMT_DISABLE 0x0 /* enable bypass memory translation */
1828 +#define QDMA_FL_SL_LONG 0x0 /* long length */
1829 +#define QDMA_FL_SL_SHORT 0x1 /* short length */
1830 +#define QDMA_FL_F 0x1 /* last frame list bit */
1831 +/*Description of Frame list table structure*/
1832 +struct dpaa2_frame_list {
1833 + uint32_t addr_lo; /* lower 32 bits of address */
1834 + uint32_t addr_hi:17; /* upper 17 bits of address */
1835 + uint32_t resrvd:15;
1837 + uint32_t data_len_sl0; /* If SL=0, then data length is 32 */
1839 + uint32_t data_len:18; /* IF SL=1; length is 18bit */
1840 + uint32_t resrvd:2;
1841 + uint32_t mem:12; /* Valid only when SL=1 */
1845 + uint32_t bpid:14; /* Frame buffer pool ID */
1846 + uint32_t ivp:1; /* Invalid Pool ID. */
1847 + uint32_t bmt:1; /* Bypass Memory Translation */
1848 + uint32_t offset:12; /* Frame offset */
1849 + uint32_t fmt:2; /* Frame Format */
1850 + uint32_t sl:1; /* Short Length */
1851 + uint32_t f:1; /* Final bit */
1853 + uint32_t frc; /* Frame Context */
1855 + uint32_t err:8; /* Frame errors */
1856 + uint32_t resrvd0:8;
1857 + uint32_t asal:4; /* accelerator-specific annotation length */
1858 + uint32_t resrvd1:1;
1861 + uint32_t pta:1; /* pass-through annotation */
1862 + uint32_t resrvd2:8;
1864 + uint32_t flc_lo; /* lower 32 bits fo flow context */
1865 + uint32_t flc_hi; /* higher 32 bits fo flow context */
1866 +} __attribute__((__packed__));
1868 +struct dpaa2_qdma_chan {
1869 + struct virt_dma_chan vchan;
1870 + struct virt_dma_desc vdesc;
1871 + enum dma_status status;
1872 + struct dpaa2_qdma_engine *qdma;
1874 + struct mutex dpaa2_queue_mutex;
1875 + spinlock_t queue_lock;
1876 + struct dma_pool *fd_pool;
1877 + struct dma_pool *sg_blk_pool;
1879 + struct list_head comp_used;
1880 + struct list_head comp_free;
1882 + struct list_head sgb_free;
1885 +struct qdma_sg_blk {
1886 + dma_addr_t blk_bus_addr;
1887 + void *blk_virt_addr;
1888 + struct list_head list;
1891 +struct dpaa2_qdma_comp {
1892 + dma_addr_t fd_bus_addr;
1893 + dma_addr_t fl_bus_addr;
1894 + dma_addr_t desc_bus_addr;
1895 + dma_addr_t sge_src_bus_addr;
1896 + dma_addr_t sge_dst_bus_addr;
1897 + void *fd_virt_addr;
1898 + void *fl_virt_addr;
1899 + void *desc_virt_addr;
1900 + void *sg_src_virt_addr;
1901 + void *sg_dst_virt_addr;
1902 + struct qdma_sg_blk *sg_blk;
1903 + uint32_t sg_blk_num;
1904 + struct list_head sg_src_head;
1905 + struct list_head sg_dst_head;
1906 + struct dpaa2_qdma_chan *qchan;
1907 + struct virt_dma_desc vdesc;
1908 + struct list_head list;
1911 +struct dpaa2_qdma_engine {
1912 + struct dma_device dma_dev;
1914 + struct dpaa2_qdma_chan chans[NUM_CH];
1916 + struct dpaa2_qdma_priv *priv;
1920 + * dpaa2_qdma_priv - driver private data
1922 +struct dpaa2_qdma_priv {
1925 + struct iommu_domain *iommu_domain;
1926 + struct dpdmai_attr dpdmai_attr;
1927 + struct device *dev;
1928 + struct fsl_mc_io *mc_io;
1929 + struct fsl_mc_device *dpdmai_dev;
1931 + struct dpdmai_rx_queue_attr rx_queue_attr[DPDMAI_PRIO_NUM];
1932 + struct dpdmai_tx_queue_attr tx_queue_attr[DPDMAI_PRIO_NUM];
1934 + uint8_t num_pairs;
1936 + struct dpaa2_qdma_engine *dpaa2_qdma;
1937 + struct dpaa2_qdma_priv_per_prio *ppriv;
1940 +struct dpaa2_qdma_priv_per_prio {
1945 + struct dpaa2_io_store *store;
1946 + struct dpaa2_io_notification_ctx nctx;
1948 + struct dpaa2_qdma_priv *priv;
1951 +/* FD pool size: one FD + 3 Frame list + 2 source/destination descriptor */
1952 +#define FD_POOL_SIZE (sizeof(struct dpaa2_fd) + \
1953 + sizeof(struct dpaa2_frame_list) * 3 + \
1954 + sizeof(struct dpaa2_qdma_sd_d) * 2)
1956 +/* qdma_sg_blk + 16 SGs */
1957 +#define SG_POOL_SIZE (sizeof(struct qdma_sg_blk) +\
1958 + sizeof(struct dpaa2_qdma_sg) * NUM_SG_PER_BLK)
1959 +#endif /* __DPAA2_QDMA_H */
1960 diff --git a/drivers/dma/dpaa2-qdma/dpdmai.c b/drivers/dma/dpaa2-qdma/dpdmai.c
1961 new file mode 100644
1962 index 00000000..ad13fc1e
1964 +++ b/drivers/dma/dpaa2-qdma/dpdmai.c
1966 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
1968 + * Redistribution and use in source and binary forms, with or without
1969 + * modification, are permitted provided that the following conditions are met:
1970 + * * Redistributions of source code must retain the above copyright
1971 + * notice, this list of conditions and the following disclaimer.
1972 + * * Redistributions in binary form must reproduce the above copyright
1973 + * notice, this list of conditions and the following disclaimer in the
1974 + * documentation and/or other materials provided with the distribution.
1975 + * * Neither the name of the above-listed copyright holders nor the
1976 + * names of any contributors may be used to endorse or promote products
1977 + * derived from this software without specific prior written permission.
1980 + * ALTERNATIVELY, this software may be distributed under the terms of the
1981 + * GNU General Public License ("GPL") as published by the Free Software
1982 + * Foundation, either version 2 of that License or (at your option) any
1985 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1986 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1987 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1988 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1989 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1990 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1991 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1992 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1993 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1994 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1995 + * POSSIBILITY OF SUCH DAMAGE.
1997 +#include <linux/types.h>
1998 +#include <linux/io.h>
1999 +#include "fsl_dpdmai.h"
2000 +#include "fsl_dpdmai_cmd.h"
2001 +#include "../../../drivers/staging/fsl-mc/include/mc-sys.h"
2002 +#include "../../../drivers/staging/fsl-mc/include/mc-cmd.h"
2004 +int dpdmai_open(struct fsl_mc_io *mc_io,
2005 + uint32_t cmd_flags,
2009 + struct mc_command cmd = { 0 };
2012 + /* prepare command */
2013 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
2016 + DPDMAI_CMD_OPEN(cmd, dpdmai_id);
2018 + /* send command to mc*/
2019 + err = mc_send_command(mc_io, &cmd);
2023 + /* retrieve response parameters */
2024 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
2029 +int dpdmai_close(struct fsl_mc_io *mc_io,
2030 + uint32_t cmd_flags,
2033 + struct mc_command cmd = { 0 };
2035 + /* prepare command */
2036 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
2037 + cmd_flags, token);
2039 + /* send command to mc*/
2040 + return mc_send_command(mc_io, &cmd);
2043 +int dpdmai_create(struct fsl_mc_io *mc_io,
2044 + uint32_t cmd_flags,
2045 + const struct dpdmai_cfg *cfg,
2048 + struct mc_command cmd = { 0 };
2051 + /* prepare command */
2052 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
2055 + DPDMAI_CMD_CREATE(cmd, cfg);
2057 + /* send command to mc*/
2058 + err = mc_send_command(mc_io, &cmd);
2062 + /* retrieve response parameters */
2063 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
2068 +int dpdmai_destroy(struct fsl_mc_io *mc_io,
2069 + uint32_t cmd_flags,
2072 + struct mc_command cmd = { 0 };
2074 + /* prepare command */
2075 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
2079 + /* send command to mc*/
2080 + return mc_send_command(mc_io, &cmd);
2083 +int dpdmai_enable(struct fsl_mc_io *mc_io,
2084 + uint32_t cmd_flags,
2087 + struct mc_command cmd = { 0 };
2089 + /* prepare command */
2090 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
2094 + /* send command to mc*/
2095 + return mc_send_command(mc_io, &cmd);
2098 +int dpdmai_disable(struct fsl_mc_io *mc_io,
2099 + uint32_t cmd_flags,
2102 + struct mc_command cmd = { 0 };
2104 + /* prepare command */
2105 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
2109 + /* send command to mc*/
2110 + return mc_send_command(mc_io, &cmd);
2113 +int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
2114 + uint32_t cmd_flags,
2118 + struct mc_command cmd = { 0 };
2120 + /* prepare command */
2121 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
2125 + /* send command to mc*/
2126 + err = mc_send_command(mc_io, &cmd);
2130 + /* retrieve response parameters */
2131 + DPDMAI_RSP_IS_ENABLED(cmd, *en);
2136 +int dpdmai_reset(struct fsl_mc_io *mc_io,
2137 + uint32_t cmd_flags,
2140 + struct mc_command cmd = { 0 };
2142 + /* prepare command */
2143 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
2147 + /* send command to mc*/
2148 + return mc_send_command(mc_io, &cmd);
2151 +int dpdmai_get_irq(struct fsl_mc_io *mc_io,
2152 + uint32_t cmd_flags,
2154 + uint8_t irq_index,
2156 + struct dpdmai_irq_cfg *irq_cfg)
2158 + struct mc_command cmd = { 0 };
2161 + /* prepare command */
2162 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ,
2165 + DPDMAI_CMD_GET_IRQ(cmd, irq_index);
2167 + /* send command to mc*/
2168 + err = mc_send_command(mc_io, &cmd);
2172 + /* retrieve response parameters */
2173 + DPDMAI_RSP_GET_IRQ(cmd, *type, irq_cfg);
2178 +int dpdmai_set_irq(struct fsl_mc_io *mc_io,
2179 + uint32_t cmd_flags,
2181 + uint8_t irq_index,
2182 + struct dpdmai_irq_cfg *irq_cfg)
2184 + struct mc_command cmd = { 0 };
2186 + /* prepare command */
2187 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ,
2190 + DPDMAI_CMD_SET_IRQ(cmd, irq_index, irq_cfg);
2192 + /* send command to mc*/
2193 + return mc_send_command(mc_io, &cmd);
2196 +int dpdmai_get_irq_enable(struct fsl_mc_io *mc_io,
2197 + uint32_t cmd_flags,
2199 + uint8_t irq_index,
2202 + struct mc_command cmd = { 0 };
2205 + /* prepare command */
2206 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_ENABLE,
2209 + DPDMAI_CMD_GET_IRQ_ENABLE(cmd, irq_index);
2211 + /* send command to mc*/
2212 + err = mc_send_command(mc_io, &cmd);
2216 + /* retrieve response parameters */
2217 + DPDMAI_RSP_GET_IRQ_ENABLE(cmd, *en);
2222 +int dpdmai_set_irq_enable(struct fsl_mc_io *mc_io,
2223 + uint32_t cmd_flags,
2225 + uint8_t irq_index,
2228 + struct mc_command cmd = { 0 };
2230 + /* prepare command */
2231 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ_ENABLE,
2234 + DPDMAI_CMD_SET_IRQ_ENABLE(cmd, irq_index, en);
2236 + /* send command to mc*/
2237 + return mc_send_command(mc_io, &cmd);
2240 +int dpdmai_get_irq_mask(struct fsl_mc_io *mc_io,
2241 + uint32_t cmd_flags,
2243 + uint8_t irq_index,
2246 + struct mc_command cmd = { 0 };
2249 + /* prepare command */
2250 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_MASK,
2253 + DPDMAI_CMD_GET_IRQ_MASK(cmd, irq_index);
2255 + /* send command to mc*/
2256 + err = mc_send_command(mc_io, &cmd);
2260 + /* retrieve response parameters */
2261 + DPDMAI_RSP_GET_IRQ_MASK(cmd, *mask);
2266 +int dpdmai_set_irq_mask(struct fsl_mc_io *mc_io,
2267 + uint32_t cmd_flags,
2269 + uint8_t irq_index,
2272 + struct mc_command cmd = { 0 };
2274 + /* prepare command */
2275 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ_MASK,
2278 + DPDMAI_CMD_SET_IRQ_MASK(cmd, irq_index, mask);
2280 + /* send command to mc*/
2281 + return mc_send_command(mc_io, &cmd);
2284 +int dpdmai_get_irq_status(struct fsl_mc_io *mc_io,
2285 + uint32_t cmd_flags,
2287 + uint8_t irq_index,
2290 + struct mc_command cmd = { 0 };
2293 + /* prepare command */
2294 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_STATUS,
2297 + DPDMAI_CMD_GET_IRQ_STATUS(cmd, irq_index, *status);
2299 + /* send command to mc*/
2300 + err = mc_send_command(mc_io, &cmd);
2304 + /* retrieve response parameters */
2305 + DPDMAI_RSP_GET_IRQ_STATUS(cmd, *status);
2310 +int dpdmai_clear_irq_status(struct fsl_mc_io *mc_io,
2311 + uint32_t cmd_flags,
2313 + uint8_t irq_index,
2316 + struct mc_command cmd = { 0 };
2318 + /* prepare command */
2319 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLEAR_IRQ_STATUS,
2322 + DPDMAI_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status);
2324 + /* send command to mc*/
2325 + return mc_send_command(mc_io, &cmd);
2328 +int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
2329 + uint32_t cmd_flags,
2331 + struct dpdmai_attr *attr)
2333 + struct mc_command cmd = { 0 };
2336 + /* prepare command */
2337 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
2341 + /* send command to mc*/
2342 + err = mc_send_command(mc_io, &cmd);
2346 + /* retrieve response parameters */
2347 + DPDMAI_RSP_GET_ATTR(cmd, attr);
2352 +int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
2353 + uint32_t cmd_flags,
2356 + const struct dpdmai_rx_queue_cfg *cfg)
2358 + struct mc_command cmd = { 0 };
2360 + /* prepare command */
2361 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
2364 + DPDMAI_CMD_SET_RX_QUEUE(cmd, priority, cfg);
2366 + /* send command to mc*/
2367 + return mc_send_command(mc_io, &cmd);
2370 +int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
2371 + uint32_t cmd_flags,
2373 + uint8_t priority, struct dpdmai_rx_queue_attr *attr)
2375 + struct mc_command cmd = { 0 };
2378 + /* prepare command */
2379 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
2382 + DPDMAI_CMD_GET_RX_QUEUE(cmd, priority);
2384 + /* send command to mc*/
2385 + err = mc_send_command(mc_io, &cmd);
2389 + /* retrieve response parameters */
2390 + DPDMAI_RSP_GET_RX_QUEUE(cmd, attr);
2395 +int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
2396 + uint32_t cmd_flags,
2399 + struct dpdmai_tx_queue_attr *attr)
2401 + struct mc_command cmd = { 0 };
2404 + /* prepare command */
2405 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
2408 + DPDMAI_CMD_GET_TX_QUEUE(cmd, priority);
2410 + /* send command to mc*/
2411 + err = mc_send_command(mc_io, &cmd);
2415 + /* retrieve response parameters */
2416 + DPDMAI_RSP_GET_TX_QUEUE(cmd, attr);
2420 diff --git a/drivers/dma/dpaa2-qdma/fsl_dpdmai.h b/drivers/dma/dpaa2-qdma/fsl_dpdmai.h
2421 new file mode 100644
2422 index 00000000..e931ce16
2424 +++ b/drivers/dma/dpaa2-qdma/fsl_dpdmai.h
2426 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
2428 + * Redistribution and use in source and binary forms, with or without
2429 + * modification, are permitted provided that the following conditions are met:
2430 + * * Redistributions of source code must retain the above copyright
2431 + * notice, this list of conditions and the following disclaimer.
2432 + * * Redistributions in binary form must reproduce the above copyright
2433 + * notice, this list of conditions and the following disclaimer in the
2434 + * documentation and/or other materials provided with the distribution.
2435 + * * Neither the name of the above-listed copyright holders nor the
2436 + * names of any contributors may be used to endorse or promote products
2437 + * derived from this software without specific prior written permission.
2440 + * ALTERNATIVELY, this software may be distributed under the terms of the
2441 + * GNU General Public License ("GPL") as published by the Free Software
2442 + * Foundation, either version 2 of that License or (at your option) any
2445 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2446 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2447 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2448 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2449 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2450 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2451 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2452 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2453 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2454 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2455 + * POSSIBILITY OF SUCH DAMAGE.
2457 +#ifndef __FSL_DPDMAI_H
2458 +#define __FSL_DPDMAI_H
2462 +/* Data Path DMA Interface API
2463 + * Contains initialization APIs and runtime control APIs for DPDMAI
2466 +/* General DPDMAI macros */
2469 + * Maximum number of Tx/Rx priorities per DPDMAI object
2471 +#define DPDMAI_PRIO_NUM 2
2474 + * All queues considered; see dpdmai_set_rx_queue()
2476 +#define DPDMAI_ALL_QUEUES (uint8_t)(-1)
2479 + * dpdmai_open() - Open a control session for the specified object
2480 + * @mc_io: Pointer to MC portal's I/O object
2481 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2482 + * @dpdmai_id: DPDMAI unique ID
2483 + * @token: Returned token; use in subsequent API calls
2485 + * This function can be used to open a control session for an
2486 + * already created object; an object may have been declared in
2487 + * the DPL or by calling the dpdmai_create() function.
2488 + * This function returns a unique authentication token,
2489 + * associated with the specific object ID and the specific MC
2490 + * portal; this token must be used in all subsequent commands for
2491 + * this specific object.
2493 + * Return: '0' on Success; Error code otherwise.
2495 +int dpdmai_open(struct fsl_mc_io *mc_io,
2496 + uint32_t cmd_flags,
2501 + * dpdmai_close() - Close the control session of the object
2502 + * @mc_io: Pointer to MC portal's I/O object
2503 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2504 + * @token: Token of DPDMAI object
2506 + * After this function is called, no further operations are
2507 + * allowed on the object without opening a new control session.
2509 + * Return: '0' on Success; Error code otherwise.
2511 +int dpdmai_close(struct fsl_mc_io *mc_io,
2512 + uint32_t cmd_flags,
2516 + * struct dpdmai_cfg - Structure representing DPDMAI configuration
2517 + * @priorities: Priorities for the DMA hardware processing; valid priorities are
2518 + * configured with values 1-8; the entry following last valid entry
2519 + * should be configured with 0
2521 +struct dpdmai_cfg {
2522 + uint8_t priorities[DPDMAI_PRIO_NUM];
2526 + * dpdmai_create() - Create the DPDMAI object
2527 + * @mc_io: Pointer to MC portal's I/O object
2528 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2529 + * @cfg: Configuration structure
2530 + * @token: Returned token; use in subsequent API calls
2532 + * Create the DPDMAI object, allocate required resources and
2533 + * perform required initialization.
2535 + * The object can be created either by declaring it in the
2536 + * DPL file, or by calling this function.
2538 + * This function returns a unique authentication token,
2539 + * associated with the specific object ID and the specific MC
2540 + * portal; this token must be used in all subsequent calls to
2541 + * this specific object. For objects that are created using the
2542 + * DPL file, call dpdmai_open() function to get an authentication
2545 + * Return: '0' on Success; Error code otherwise.
2547 +int dpdmai_create(struct fsl_mc_io *mc_io,
2548 + uint32_t cmd_flags,
2549 + const struct dpdmai_cfg *cfg,
2553 + * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
2554 + * @mc_io: Pointer to MC portal's I/O object
2555 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2556 + * @token: Token of DPDMAI object
2558 + * Return: '0' on Success; error code otherwise.
2560 +int dpdmai_destroy(struct fsl_mc_io *mc_io,
2561 + uint32_t cmd_flags,
2565 + * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
2566 + * @mc_io: Pointer to MC portal's I/O object
2567 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2568 + * @token: Token of DPDMAI object
2570 + * Return: '0' on Success; Error code otherwise.
2572 +int dpdmai_enable(struct fsl_mc_io *mc_io,
2573 + uint32_t cmd_flags,
2577 + * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
2578 + * @mc_io: Pointer to MC portal's I/O object
2579 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2580 + * @token: Token of DPDMAI object
2582 + * Return: '0' on Success; Error code otherwise.
2584 +int dpdmai_disable(struct fsl_mc_io *mc_io,
2585 + uint32_t cmd_flags,
2589 + * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
2590 + * @mc_io: Pointer to MC portal's I/O object
2591 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2592 + * @token: Token of DPDMAI object
2593 + * @en: Returns '1' if object is enabled; '0' otherwise
2595 + * Return: '0' on Success; Error code otherwise.
2597 +int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
2598 + uint32_t cmd_flags,
2603 + * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
2604 + * @mc_io: Pointer to MC portal's I/O object
2605 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2606 + * @token: Token of DPDMAI object
2608 + * Return: '0' on Success; Error code otherwise.
2610 +int dpdmai_reset(struct fsl_mc_io *mc_io,
2611 + uint32_t cmd_flags,
2615 + * struct dpdmai_irq_cfg - IRQ configuration
2616 + * @addr: Address that must be written to signal a message-based interrupt
2617 + * @val: Value to write into irq_addr address
2618 + * @irq_num: A user defined number associated with this IRQ
2620 +struct dpdmai_irq_cfg {
2627 + * dpdmai_set_irq() - Set IRQ information for the DPDMAI to trigger an interrupt.
2628 + * @mc_io: Pointer to MC portal's I/O object
2629 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2630 + * @token: Token of DPDMAI object
2631 + * @irq_index: Identifies the interrupt index to configure
2632 + * @irq_cfg: IRQ configuration
2634 + * Return: '0' on Success; Error code otherwise.
2636 +int dpdmai_set_irq(struct fsl_mc_io *mc_io,
2637 + uint32_t cmd_flags,
2639 + uint8_t irq_index,
2640 + struct dpdmai_irq_cfg *irq_cfg);
2643 + * dpdmai_get_irq() - Get IRQ information from the DPDMAI
2645 + * @mc_io: Pointer to MC portal's I/O object
2646 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2647 + * @token: Token of DPDMAI object
2648 + * @irq_index: The interrupt index to configure
2649 + * @type: Interrupt type: 0 represents message interrupt
2650 + * type (both irq_addr and irq_val are valid)
2651 + * @irq_cfg: IRQ attributes
2653 + * Return: '0' on Success; Error code otherwise.
2655 +int dpdmai_get_irq(struct fsl_mc_io *mc_io,
2656 + uint32_t cmd_flags,
2658 + uint8_t irq_index,
2660 + struct dpdmai_irq_cfg *irq_cfg);
2663 + * dpdmai_set_irq_enable() - Set overall interrupt state.
2664 + * @mc_io: Pointer to MC portal's I/O object
2665 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2666 + * @token: Token of DPDMAI object
2667 + * @irq_index: The interrupt index to configure
2668 + * @en: Interrupt state - enable = 1, disable = 0
2670 + * Allows GPP software to control when interrupts are generated.
2671 + * Each interrupt can have up to 32 causes. The enable/disable control's the
2672 + * overall interrupt state. if the interrupt is disabled no causes will cause
2675 + * Return: '0' on Success; Error code otherwise.
2677 +int dpdmai_set_irq_enable(struct fsl_mc_io *mc_io,
2678 + uint32_t cmd_flags,
2680 + uint8_t irq_index,
2684 + * dpdmai_get_irq_enable() - Get overall interrupt state
2685 + * @mc_io: Pointer to MC portal's I/O object
2686 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2687 + * @token: Token of DPDMAI object
2688 + * @irq_index: The interrupt index to configure
2689 + * @en: Returned Interrupt state - enable = 1, disable = 0
2691 + * Return: '0' on Success; Error code otherwise.
2693 +int dpdmai_get_irq_enable(struct fsl_mc_io *mc_io,
2694 + uint32_t cmd_flags,
2696 + uint8_t irq_index,
2700 + * dpdmai_set_irq_mask() - Set interrupt mask.
2701 + * @mc_io: Pointer to MC portal's I/O object
2702 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2703 + * @token: Token of DPDMAI object
2704 + * @irq_index: The interrupt index to configure
2705 + * @mask: event mask to trigger interrupt;
2707 + * 0 = ignore event
2708 + * 1 = consider event for asserting IRQ
2710 + * Every interrupt can have up to 32 causes and the interrupt model supports
2711 + * masking/unmasking each cause independently
2713 + * Return: '0' on Success; Error code otherwise.
2715 +int dpdmai_set_irq_mask(struct fsl_mc_io *mc_io,
2716 + uint32_t cmd_flags,
2718 + uint8_t irq_index,
2722 + * dpdmai_get_irq_mask() - Get interrupt mask.
2723 + * @mc_io: Pointer to MC portal's I/O object
2724 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2725 + * @token: Token of DPDMAI object
2726 + * @irq_index: The interrupt index to configure
2727 + * @mask: Returned event mask to trigger interrupt
2729 + * Every interrupt can have up to 32 causes and the interrupt model supports
2730 + * masking/unmasking each cause independently
2732 + * Return: '0' on Success; Error code otherwise.
2734 +int dpdmai_get_irq_mask(struct fsl_mc_io *mc_io,
2735 + uint32_t cmd_flags,
2737 + uint8_t irq_index,
2741 + * dpdmai_get_irq_status() - Get the current status of any pending interrupts
2742 + * @mc_io: Pointer to MC portal's I/O object
2743 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2744 + * @token: Token of DPDMAI object
2745 + * @irq_index: The interrupt index to configure
2746 + * @status: Returned interrupts status - one bit per cause:
2747 + * 0 = no interrupt pending
2748 + * 1 = interrupt pending
2750 + * Return: '0' on Success; Error code otherwise.
2752 +int dpdmai_get_irq_status(struct fsl_mc_io *mc_io,
2753 + uint32_t cmd_flags,
2755 + uint8_t irq_index,
2756 + uint32_t *status);
2759 + * dpdmai_clear_irq_status() - Clear a pending interrupt's status
2760 + * @mc_io: Pointer to MC portal's I/O object
2761 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2762 + * @token: Token of DPDMAI object
2763 + * @irq_index: The interrupt index to configure
2764 + * @status: bits to clear (W1C) - one bit per cause:
2765 + * 0 = don't change
2766 + * 1 = clear status bit
2768 + * Return: '0' on Success; Error code otherwise.
2770 +int dpdmai_clear_irq_status(struct fsl_mc_io *mc_io,
2771 + uint32_t cmd_flags,
2773 + uint8_t irq_index,
2777 + * struct dpdmai_attr - Structure representing DPDMAI attributes
2778 + * @id: DPDMAI object ID
2779 + * @version: DPDMAI version
2780 + * @num_of_priorities: number of priorities
2782 +struct dpdmai_attr {
2785 + * struct version - DPDMAI version
2786 + * @major: DPDMAI major version
2787 + * @minor: DPDMAI minor version
2793 + uint8_t num_of_priorities;
2797 + * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
2798 + * @mc_io: Pointer to MC portal's I/O object
2799 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2800 + * @token: Token of DPDMAI object
2801 + * @attr: Returned object's attributes
2803 + * Return: '0' on Success; Error code otherwise.
2805 +int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
2806 + uint32_t cmd_flags,
2808 + struct dpdmai_attr *attr);
2811 + * enum dpdmai_dest - DPDMAI destination types
2812 + * @DPDMAI_DEST_NONE: Unassigned destination; The queue is set in parked mode
2813 + * and does not generate FQDAN notifications; user is expected to dequeue
2814 + * from the queue based on polling or other user-defined method
2815 + * @DPDMAI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
2816 + * notifications to the specified DPIO; user is expected to dequeue
2817 + * from the queue only after notification is received
2818 + * @DPDMAI_DEST_DPCON: The queue is set in schedule mode and does not generate
2819 + * FQDAN notifications, but is connected to the specified DPCON object;
2820 + * user is expected to dequeue from the DPCON channel
2823 + DPDMAI_DEST_NONE = 0,
2824 + DPDMAI_DEST_DPIO = 1,
2825 + DPDMAI_DEST_DPCON = 2
2829 + * struct dpdmai_dest_cfg - Structure representing DPDMAI destination parameters
2830 + * @dest_type: Destination type
2831 + * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
2832 + * @priority: Priority selection within the DPIO or DPCON channel; valid values
2833 + * are 0-1 or 0-7, depending on the number of priorities in that
2834 + * channel; not relevant for 'DPDMAI_DEST_NONE' option
2836 +struct dpdmai_dest_cfg {
2837 + enum dpdmai_dest dest_type;
2842 +/* DPDMAI queue modification options */
2845 + * Select to modify the user's context associated with the queue
2847 +#define DPDMAI_QUEUE_OPT_USER_CTX 0x00000001
2850 + * Select to modify the queue's destination
2852 +#define DPDMAI_QUEUE_OPT_DEST 0x00000002
2855 + * struct dpdmai_rx_queue_cfg - DPDMAI RX queue configuration
2856 + * @options: Flags representing the suggested modifications to the queue;
2857 + * Use any combination of 'DPDMAI_QUEUE_OPT_<X>' flags
2858 + * @user_ctx: User context value provided in the frame descriptor of each
2860 + * valid only if 'DPDMAI_QUEUE_OPT_USER_CTX' is contained in 'options'
2861 + * @dest_cfg: Queue destination parameters;
2862 + * valid only if 'DPDMAI_QUEUE_OPT_DEST' is contained in 'options'
2864 +struct dpdmai_rx_queue_cfg {
2866 + uint64_t user_ctx;
2867 + struct dpdmai_dest_cfg dest_cfg;
2872 + * dpdmai_set_rx_queue() - Set Rx queue configuration
2873 + * @mc_io: Pointer to MC portal's I/O object
2874 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2875 + * @token: Token of DPDMAI object
2876 + * @priority: Select the queue relative to number of
2877 + * priorities configured at DPDMAI creation; use
2878 + * DPDMAI_ALL_QUEUES to configure all Rx queues
2880 + * @cfg: Rx queue configuration
2882 + * Return: '0' on Success; Error code otherwise.
2884 +int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
2885 + uint32_t cmd_flags,
2888 + const struct dpdmai_rx_queue_cfg *cfg);
2891 + * struct dpdmai_rx_queue_attr - Structure representing attributes of Rx queues
2892 + * @user_ctx: User context value provided in the frame descriptor of each
2894 + * @dest_cfg: Queue destination configuration
2895 + * @fqid: Virtual FQID value to be used for dequeue operations
2897 +struct dpdmai_rx_queue_attr {
2898 + uint64_t user_ctx;
2899 + struct dpdmai_dest_cfg dest_cfg;
2904 + * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
2905 + * @mc_io: Pointer to MC portal's I/O object
2906 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2907 + * @token: Token of DPDMAI object
2908 + * @priority: Select the queue relative to number of
2909 + * priorities configured at DPDMAI creation
2910 + * @attr: Returned Rx queue attributes
2912 + * Return: '0' on Success; Error code otherwise.
2914 +int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
2915 + uint32_t cmd_flags,
2918 + struct dpdmai_rx_queue_attr *attr);
2921 + * struct dpdmai_tx_queue_attr - Structure representing attributes of Tx queues
2922 + * @fqid: Virtual FQID to be used for sending frames to DMA hardware
2925 +struct dpdmai_tx_queue_attr {
2930 + * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
2931 + * @mc_io: Pointer to MC portal's I/O object
2932 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2933 + * @token: Token of DPDMAI object
2934 + * @priority: Select the queue relative to number of
2935 + * priorities configured at DPDMAI creation
2936 + * @attr: Returned Tx queue attributes
2938 + * Return: '0' on Success; Error code otherwise.
2940 +int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
2941 + uint32_t cmd_flags,
2944 + struct dpdmai_tx_queue_attr *attr);
2946 +#endif /* __FSL_DPDMAI_H */
2947 diff --git a/drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h b/drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h
2948 new file mode 100644
2949 index 00000000..7d403c01
2951 +++ b/drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h
2953 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
2955 + * Redistribution and use in source and binary forms, with or without
2956 + * modification, are permitted provided that the following conditions are met:
2957 + * * Redistributions of source code must retain the above copyright
2958 + * notice, this list of conditions and the following disclaimer.
2959 + * * Redistributions in binary form must reproduce the above copyright
2960 + * notice, this list of conditions and the following disclaimer in the
2961 + * documentation and/or other materials provided with the distribution.
2962 + * * Neither the name of the above-listed copyright holders nor the
2963 + * names of any contributors may be used to endorse or promote products
2964 + * derived from this software without specific prior written permission.
2967 + * ALTERNATIVELY, this software may be distributed under the terms of the
2968 + * GNU General Public License ("GPL") as published by the Free Software
2969 + * Foundation, either version 2 of that License or (at your option) any
2972 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2973 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2974 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2975 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2976 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2977 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2978 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2979 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2980 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2981 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2982 + * POSSIBILITY OF SUCH DAMAGE.
2984 +#ifndef _FSL_DPDMAI_CMD_H
2985 +#define _FSL_DPDMAI_CMD_H
2987 +/* DPDMAI Version */
2988 +#define DPDMAI_VER_MAJOR 2
2989 +#define DPDMAI_VER_MINOR 2
2991 +#define DPDMAI_CMD_BASE_VERSION 0
2992 +#define DPDMAI_CMD_ID_OFFSET 4
2995 +#define DPDMAI_CMDID_CLOSE ((0x800 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2996 +#define DPDMAI_CMDID_OPEN ((0x80E << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2997 +#define DPDMAI_CMDID_CREATE ((0x90E << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2998 +#define DPDMAI_CMDID_DESTROY ((0x900 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3000 +#define DPDMAI_CMDID_ENABLE ((0x002 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3001 +#define DPDMAI_CMDID_DISABLE ((0x003 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3002 +#define DPDMAI_CMDID_GET_ATTR ((0x004 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3003 +#define DPDMAI_CMDID_RESET ((0x005 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3004 +#define DPDMAI_CMDID_IS_ENABLED ((0x006 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3006 +#define DPDMAI_CMDID_SET_IRQ ((0x010 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3007 +#define DPDMAI_CMDID_GET_IRQ ((0x011 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3008 +#define DPDMAI_CMDID_SET_IRQ_ENABLE ((0x012 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3009 +#define DPDMAI_CMDID_GET_IRQ_ENABLE ((0x013 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3010 +#define DPDMAI_CMDID_SET_IRQ_MASK ((0x014 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3011 +#define DPDMAI_CMDID_GET_IRQ_MASK ((0x015 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3012 +#define DPDMAI_CMDID_GET_IRQ_STATUS ((0x016 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3013 +#define DPDMAI_CMDID_CLEAR_IRQ_STATUS ((0x017 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3015 +#define DPDMAI_CMDID_SET_RX_QUEUE ((0x1A0 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3016 +#define DPDMAI_CMDID_GET_RX_QUEUE ((0x1A1 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3017 +#define DPDMAI_CMDID_GET_TX_QUEUE ((0x1A2 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
3020 +#define MC_CMD_HDR_TOKEN_O 32 /* Token field offset */
3021 +#define MC_CMD_HDR_TOKEN_S 16 /* Token field size */
3024 +#define MAKE_UMASK64(_width) \
3025 + ((uint64_t)((_width) < 64 ? ((uint64_t)1 << (_width)) - 1 : \
3028 +static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val)
3030 + return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset);
3033 +static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width)
3035 + return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width));
3038 +#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
3039 + ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
3041 +#define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \
3042 + (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width)))
3044 +#define MC_CMD_HDR_READ_TOKEN(_hdr) \
3045 + ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
3047 +/* cmd, param, offset, width, type, arg_name */
3048 +#define DPDMAI_CMD_OPEN(cmd, dpdmai_id) \
3049 + MC_CMD_OP(cmd, 0, 0, 32, int, dpdmai_id)
3051 +/* cmd, param, offset, width, type, arg_name */
3052 +#define DPDMAI_CMD_CREATE(cmd, cfg) \
3054 + MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->priorities[0]);\
3055 + MC_CMD_OP(cmd, 0, 16, 8, uint8_t, cfg->priorities[1]);\
3058 +/* cmd, param, offset, width, type, arg_name */
3059 +#define DPDMAI_RSP_IS_ENABLED(cmd, en) \
3060 + MC_RSP_OP(cmd, 0, 0, 1, int, en)
3062 +/* cmd, param, offset, width, type, arg_name */
3063 +#define DPDMAI_CMD_SET_IRQ(cmd, irq_index, irq_cfg) \
3065 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, irq_index);\
3066 + MC_CMD_OP(cmd, 0, 32, 32, uint32_t, irq_cfg->val);\
3067 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
3068 + MC_CMD_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
3071 +/* cmd, param, offset, width, type, arg_name */
3072 +#define DPDMAI_CMD_GET_IRQ(cmd, irq_index) \
3073 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
3075 +/* cmd, param, offset, width, type, arg_name */
3076 +#define DPDMAI_RSP_GET_IRQ(cmd, type, irq_cfg) \
3078 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, irq_cfg->val); \
3079 + MC_RSP_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
3080 + MC_RSP_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
3081 + MC_RSP_OP(cmd, 2, 32, 32, int, type); \
3084 +/* cmd, param, offset, width, type, arg_name */
3085 +#define DPDMAI_CMD_SET_IRQ_ENABLE(cmd, irq_index, enable_state) \
3087 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, enable_state); \
3088 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
3091 +/* cmd, param, offset, width, type, arg_name */
3092 +#define DPDMAI_CMD_GET_IRQ_ENABLE(cmd, irq_index) \
3093 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
3095 +/* cmd, param, offset, width, type, arg_name */
3096 +#define DPDMAI_RSP_GET_IRQ_ENABLE(cmd, enable_state) \
3097 + MC_RSP_OP(cmd, 0, 0, 8, uint8_t, enable_state)
3099 +/* cmd, param, offset, width, type, arg_name */
3100 +#define DPDMAI_CMD_SET_IRQ_MASK(cmd, irq_index, mask) \
3102 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, mask); \
3103 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
3106 +/* cmd, param, offset, width, type, arg_name */
3107 +#define DPDMAI_CMD_GET_IRQ_MASK(cmd, irq_index) \
3108 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
3110 +/* cmd, param, offset, width, type, arg_name */
3111 +#define DPDMAI_RSP_GET_IRQ_MASK(cmd, mask) \
3112 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, mask)
3114 +/* cmd, param, offset, width, type, arg_name */
3115 +#define DPDMAI_CMD_GET_IRQ_STATUS(cmd, irq_index, status) \
3117 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status);\
3118 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
3121 +/* cmd, param, offset, width, type, arg_name */
3122 +#define DPDMAI_RSP_GET_IRQ_STATUS(cmd, status) \
3123 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, status)
3125 +/* cmd, param, offset, width, type, arg_name */
3126 +#define DPDMAI_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status) \
3128 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status); \
3129 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
3132 +/* cmd, param, offset, width, type, arg_name */
3133 +#define DPDMAI_RSP_GET_ATTR(cmd, attr) \
3135 + MC_RSP_OP(cmd, 0, 0, 32, int, attr->id); \
3136 + MC_RSP_OP(cmd, 0, 32, 8, uint8_t, attr->num_of_priorities); \
3137 + MC_RSP_OP(cmd, 1, 0, 16, uint16_t, attr->version.major);\
3138 + MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
3141 +/* cmd, param, offset, width, type, arg_name */
3142 +#define DPDMAI_CMD_SET_RX_QUEUE(cmd, priority, cfg) \
3144 + MC_CMD_OP(cmd, 0, 0, 32, int, cfg->dest_cfg.dest_id); \
3145 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, cfg->dest_cfg.priority); \
3146 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority); \
3147 + MC_CMD_OP(cmd, 0, 48, 4, enum dpdmai_dest, cfg->dest_cfg.dest_type); \
3148 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, cfg->user_ctx); \
3149 + MC_CMD_OP(cmd, 2, 0, 32, uint32_t, cfg->options);\
3152 +/* cmd, param, offset, width, type, arg_name */
3153 +#define DPDMAI_CMD_GET_RX_QUEUE(cmd, priority) \
3154 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority)
3156 +/* cmd, param, offset, width, type, arg_name */
3157 +#define DPDMAI_RSP_GET_RX_QUEUE(cmd, attr) \
3159 + MC_RSP_OP(cmd, 0, 0, 32, int, attr->dest_cfg.dest_id);\
3160 + MC_RSP_OP(cmd, 0, 32, 8, uint8_t, attr->dest_cfg.priority);\
3161 + MC_RSP_OP(cmd, 0, 48, 4, enum dpdmai_dest, attr->dest_cfg.dest_type);\
3162 + MC_RSP_OP(cmd, 1, 0, 64, uint64_t, attr->user_ctx);\
3163 + MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->fqid);\
3166 +/* cmd, param, offset, width, type, arg_name */
3167 +#define DPDMAI_CMD_GET_TX_QUEUE(cmd, priority) \
3168 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority)
3170 +/* cmd, param, offset, width, type, arg_name */
3171 +#define DPDMAI_RSP_GET_TX_QUEUE(cmd, attr) \
3172 + MC_RSP_OP(cmd, 1, 0, 32, uint32_t, attr->fqid)
3174 +#endif /* _FSL_DPDMAI_CMD_H */
3175 diff --git a/drivers/dma/fsl-qdma.c b/drivers/dma/fsl-qdma.c
3176 new file mode 100644
3177 index 00000000..6c4c2813
3179 +++ b/drivers/dma/fsl-qdma.c
3182 + * drivers/dma/fsl-qdma.c
3184 + * Copyright 2014-2015 Freescale Semiconductor, Inc.
3186 + * Driver for the Freescale qDMA engine with software command queue mode.
3187 + * Channel virtualization is supported through enqueuing of DMA jobs to,
3188 + * or dequeuing DMA jobs from, different work queues.
3189 + * This module can be found on Freescale LS SoCs.
3191 + * This program is free software; you can redistribute it and/or modify it
3192 + * under the terms of the GNU General Public License as published by the
3193 + * Free Software Foundation; either version 2 of the License, or (at your
3194 + * option) any later version.
3197 +#include <asm/cacheflush.h>
3198 +#include <linux/clk.h>
3199 +#include <linux/delay.h>
3200 +#include <linux/dma-mapping.h>
3201 +#include <linux/dmapool.h>
3202 +#include <linux/init.h>
3203 +#include <linux/interrupt.h>
3204 +#include <linux/module.h>
3205 +#include <linux/of.h>
3206 +#include <linux/of_address.h>
3207 +#include <linux/of_device.h>
3208 +#include <linux/of_dma.h>
3209 +#include <linux/of_irq.h>
3210 +#include <linux/slab.h>
3211 +#include <linux/spinlock.h>
3213 +#include "virt-dma.h"
3215 +#define FSL_QDMA_DMR 0x0
3216 +#define FSL_QDMA_DSR 0x4
3217 +#define FSL_QDMA_DEIER 0xe00
3218 +#define FSL_QDMA_DEDR 0xe04
3219 +#define FSL_QDMA_DECFDW0R 0xe10
3220 +#define FSL_QDMA_DECFDW1R 0xe14
3221 +#define FSL_QDMA_DECFDW2R 0xe18
3222 +#define FSL_QDMA_DECFDW3R 0xe1c
3223 +#define FSL_QDMA_DECFQIDR 0xe30
3224 +#define FSL_QDMA_DECBR 0xe34
3226 +#define FSL_QDMA_BCQMR(x) (0xc0 + 0x100 * (x))
3227 +#define FSL_QDMA_BCQSR(x) (0xc4 + 0x100 * (x))
3228 +#define FSL_QDMA_BCQEDPA_SADDR(x) (0xc8 + 0x100 * (x))
3229 +#define FSL_QDMA_BCQDPA_SADDR(x) (0xcc + 0x100 * (x))
3230 +#define FSL_QDMA_BCQEEPA_SADDR(x) (0xd0 + 0x100 * (x))
3231 +#define FSL_QDMA_BCQEPA_SADDR(x) (0xd4 + 0x100 * (x))
3232 +#define FSL_QDMA_BCQIER(x) (0xe0 + 0x100 * (x))
3233 +#define FSL_QDMA_BCQIDR(x) (0xe4 + 0x100 * (x))
3235 +#define FSL_QDMA_SQDPAR 0x80c
3236 +#define FSL_QDMA_SQEPAR 0x814
3237 +#define FSL_QDMA_BSQMR 0x800
3238 +#define FSL_QDMA_BSQSR 0x804
3239 +#define FSL_QDMA_BSQICR 0x828
3240 +#define FSL_QDMA_CQMR 0xa00
3241 +#define FSL_QDMA_CQDSCR1 0xa08
3242 +#define FSL_QDMA_CQDSCR2 0xa0c
3243 +#define FSL_QDMA_CQIER 0xa10
3244 +#define FSL_QDMA_CQEDR 0xa14
3245 +#define FSL_QDMA_SQCCMR 0xa20
3247 +#define FSL_QDMA_SQICR_ICEN
3249 +#define FSL_QDMA_CQIDR_CQT 0xff000000
3250 +#define FSL_QDMA_CQIDR_SQPE 0x800000
3251 +#define FSL_QDMA_CQIDR_SQT 0x8000
3253 +#define FSL_QDMA_BCQIER_CQTIE 0x8000
3254 +#define FSL_QDMA_BCQIER_CQPEIE 0x800000
3255 +#define FSL_QDMA_BSQICR_ICEN 0x80000000
3256 +#define FSL_QDMA_BSQICR_ICST(x) ((x) << 16)
3257 +#define FSL_QDMA_CQIER_MEIE 0x80000000
3258 +#define FSL_QDMA_CQIER_TEIE 0x1
3259 +#define FSL_QDMA_SQCCMR_ENTER_WM 0x200000
3261 +#define FSL_QDMA_QUEUE_MAX 8
3263 +#define FSL_QDMA_BCQMR_EN 0x80000000
3264 +#define FSL_QDMA_BCQMR_EI 0x40000000
3265 +#define FSL_QDMA_BCQMR_CD_THLD(x) ((x) << 20)
3266 +#define FSL_QDMA_BCQMR_CQ_SIZE(x) ((x) << 16)
3268 +#define FSL_QDMA_BCQSR_QF 0x10000
3269 +#define FSL_QDMA_BCQSR_XOFF 0x1
3271 +#define FSL_QDMA_BSQMR_EN 0x80000000
3272 +#define FSL_QDMA_BSQMR_DI 0x40000000
3273 +#define FSL_QDMA_BSQMR_CQ_SIZE(x) ((x) << 16)
3275 +#define FSL_QDMA_BSQSR_QE 0x20000
3277 +#define FSL_QDMA_DMR_DQD 0x40000000
3278 +#define FSL_QDMA_DSR_DB 0x80000000
3280 +#define FSL_QDMA_BASE_BUFFER_SIZE 96
3281 +#define FSL_QDMA_EXPECT_SG_ENTRY_NUM 16
3282 +#define FSL_QDMA_CIRCULAR_DESC_SIZE_MIN 64
3283 +#define FSL_QDMA_CIRCULAR_DESC_SIZE_MAX 16384
3284 +#define FSL_QDMA_QUEUE_NUM_MAX 8
3286 +#define FSL_QDMA_CMD_RWTTYPE 0x4
3287 +#define FSL_QDMA_CMD_LWC 0x2
3289 +#define FSL_QDMA_CMD_RWTTYPE_OFFSET 28
3290 +#define FSL_QDMA_CMD_NS_OFFSET 27
3291 +#define FSL_QDMA_CMD_DQOS_OFFSET 24
3292 +#define FSL_QDMA_CMD_WTHROTL_OFFSET 20
3293 +#define FSL_QDMA_CMD_DSEN_OFFSET 19
3294 +#define FSL_QDMA_CMD_LWC_OFFSET 16
3296 +#define FSL_QDMA_E_SG_TABLE 1
3297 +#define FSL_QDMA_E_DATA_BUFFER 0
3298 +#define FSL_QDMA_F_LAST_ENTRY 1
3300 +u64 pre_addr, pre_queue;
3302 +struct fsl_qdma_ccdf {
3312 + u32 addr_lo; /* low 32-bits of 40-bit address */
3313 + u32 addr_hi:8; /* high 8-bits of 40-bit address */
3317 + u32 dd:2; /* dynamic debug */
3321 + /* More efficient address accessor */
3322 + u64 __notaddress:24;
3327 +struct fsl_qdma_csgf {
3335 + u32 addr_lo; /* low 32-bits of 40-bit address */
3336 + u32 addr_hi:8; /* high 8-bits of 40-bit address */
3341 + /* More efficient address accessor */
3342 + u64 __notaddress:24;
3347 +struct fsl_qdma_sdf {
3349 + u32 ssd:12; /* souce stride distance */
3350 + u32 sss:12; /* souce stride size */
3356 +struct fsl_qdma_ddf {
3358 + u32 dsd:12; /* Destination stride distance */
3359 + u32 dss:12; /* Destination stride size */
3365 +struct fsl_qdma_chan {
3366 + struct virt_dma_chan vchan;
3367 + struct virt_dma_desc vdesc;
3368 + enum dma_status status;
3370 + struct fsl_qdma_engine *qdma;
3371 + struct fsl_qdma_queue *queue;
3372 + struct list_head qcomp;
3375 +struct fsl_qdma_queue {
3376 + struct fsl_qdma_ccdf *virt_head;
3377 + struct fsl_qdma_ccdf *virt_tail;
3378 + struct list_head comp_used;
3379 + struct list_head comp_free;
3380 + struct dma_pool *comp_pool;
3381 + struct dma_pool *sg_pool;
3382 + spinlock_t queue_lock;
3383 + dma_addr_t bus_addr;
3386 + struct fsl_qdma_ccdf *cq;
3389 +struct fsl_qdma_sg {
3390 + dma_addr_t bus_addr;
3394 +struct fsl_qdma_comp {
3395 + dma_addr_t bus_addr;
3397 + struct fsl_qdma_chan *qchan;
3398 + struct fsl_qdma_sg *sg_block;
3399 + struct virt_dma_desc vdesc;
3400 + struct list_head list;
3405 +struct fsl_qdma_engine {
3406 + struct dma_device dma_dev;
3407 + void __iomem *ctrl_base;
3408 + void __iomem *status_base;
3409 + void __iomem *block_base;
3412 + struct mutex fsl_qdma_mutex;
3416 + struct fsl_qdma_queue *queue;
3417 + struct fsl_qdma_queue *status;
3418 + struct fsl_qdma_chan chans[];
3422 +static u32 qdma_readl(struct fsl_qdma_engine *qdma, void __iomem *addr)
3424 + if (qdma->big_endian)
3425 + return ioread32be(addr);
3427 + return ioread32(addr);
3430 +static void qdma_writel(struct fsl_qdma_engine *qdma, u32 val,
3431 + void __iomem *addr)
3433 + if (qdma->big_endian)
3434 + iowrite32be(val, addr);
3436 + iowrite32(val, addr);
3439 +static struct fsl_qdma_chan *to_fsl_qdma_chan(struct dma_chan *chan)
3441 + return container_of(chan, struct fsl_qdma_chan, vchan.chan);
3444 +static struct fsl_qdma_comp *to_fsl_qdma_comp(struct virt_dma_desc *vd)
3446 + return container_of(vd, struct fsl_qdma_comp, vdesc);
3449 +static int fsl_qdma_alloc_chan_resources(struct dma_chan *chan)
3452 + * In QDMA mode, We don't need to do anything.
3457 +static void fsl_qdma_free_chan_resources(struct dma_chan *chan)
3459 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
3460 + unsigned long flags;
3463 + spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
3464 + vchan_get_all_descriptors(&fsl_chan->vchan, &head);
3465 + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags);
3467 + vchan_dma_desc_free_list(&fsl_chan->vchan, &head);
3470 +static void fsl_qdma_comp_fill_memcpy(struct fsl_qdma_comp *fsl_comp,
3471 + dma_addr_t dst, dma_addr_t src, u32 len)
3473 + struct fsl_qdma_ccdf *ccdf;
3474 + struct fsl_qdma_csgf *csgf_desc, *csgf_src, *csgf_dest;
3475 + struct fsl_qdma_sdf *sdf;
3476 + struct fsl_qdma_ddf *ddf;
3478 + ccdf = (struct fsl_qdma_ccdf *)fsl_comp->virt_addr;
3479 + csgf_desc = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 1;
3480 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 2;
3481 + csgf_dest = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 3;
3482 + sdf = (struct fsl_qdma_sdf *)fsl_comp->virt_addr + 4;
3483 + ddf = (struct fsl_qdma_ddf *)fsl_comp->virt_addr + 5;
3485 + memset(fsl_comp->virt_addr, 0, FSL_QDMA_BASE_BUFFER_SIZE);
3486 + /* Head Command Descriptor(Frame Descriptor) */
3487 + ccdf->addr = fsl_comp->bus_addr + 16;
3488 + ccdf->format = 1; /* Compound S/G format */
3489 + /* Status notification is enqueued to status queue. */
3491 + /* Compound Command Descriptor(Frame List Table) */
3492 + csgf_desc->addr = fsl_comp->bus_addr + 64;
3493 + /* It must be 32 as Compound S/G Descriptor */
3494 + csgf_desc->length = 32;
3495 + csgf_src->addr = src;
3496 + csgf_src->length = len;
3497 + csgf_dest->addr = dst;
3498 + csgf_dest->length = len;
3499 + /* This entry is the last entry. */
3500 + csgf_dest->f = FSL_QDMA_F_LAST_ENTRY;
3501 + /* Descriptor Buffer */
3502 + sdf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
3503 + ddf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
3504 + ddf->cmd |= FSL_QDMA_CMD_LWC << FSL_QDMA_CMD_LWC_OFFSET;
3507 +static void fsl_qdma_comp_fill_sg(
3508 + struct fsl_qdma_comp *fsl_comp,
3509 + struct scatterlist *dst_sg, unsigned int dst_nents,
3510 + struct scatterlist *src_sg, unsigned int src_nents)
3512 + struct fsl_qdma_ccdf *ccdf;
3513 + struct fsl_qdma_csgf *csgf_desc, *csgf_src, *csgf_dest, *csgf_sg;
3514 + struct fsl_qdma_sdf *sdf;
3515 + struct fsl_qdma_ddf *ddf;
3516 + struct fsl_qdma_sg *sg_block, *temp;
3517 + struct scatterlist *sg;
3518 + u64 total_src_len = 0;
3519 + u64 total_dst_len = 0;
3522 + ccdf = (struct fsl_qdma_ccdf *)fsl_comp->virt_addr;
3523 + csgf_desc = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 1;
3524 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 2;
3525 + csgf_dest = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 3;
3526 + sdf = (struct fsl_qdma_sdf *)fsl_comp->virt_addr + 4;
3527 + ddf = (struct fsl_qdma_ddf *)fsl_comp->virt_addr + 5;
3529 + memset(fsl_comp->virt_addr, 0, FSL_QDMA_BASE_BUFFER_SIZE);
3530 + /* Head Command Descriptor(Frame Descriptor) */
3531 + ccdf->addr = fsl_comp->bus_addr + 16;
3532 + ccdf->format = 1; /* Compound S/G format */
3533 + /* Status notification is enqueued to status queue. */
3536 + /* Compound Command Descriptor(Frame List Table) */
3537 + csgf_desc->addr = fsl_comp->bus_addr + 64;
3538 + /* It must be 32 as Compound S/G Descriptor */
3539 + csgf_desc->length = 32;
3541 + sg_block = fsl_comp->sg_block;
3542 + csgf_src->addr = sg_block->bus_addr;
3543 + /* This entry link to the s/g entry. */
3544 + csgf_src->e = FSL_QDMA_E_SG_TABLE;
3546 + temp = sg_block + fsl_comp->sg_block_src;
3547 + csgf_dest->addr = temp->bus_addr;
3548 + /* This entry is the last entry. */
3549 + csgf_dest->f = FSL_QDMA_F_LAST_ENTRY;
3550 + /* This entry link to the s/g entry. */
3551 + csgf_dest->e = FSL_QDMA_E_SG_TABLE;
3553 + for_each_sg(src_sg, sg, src_nents, i) {
3554 + temp = sg_block + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
3555 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
3556 + i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
3557 + csgf_sg->addr = sg_dma_address(sg);
3558 + csgf_sg->length = sg_dma_len(sg);
3559 + total_src_len += sg_dma_len(sg);
3561 + if (i == src_nents - 1)
3562 + csgf_sg->f = FSL_QDMA_F_LAST_ENTRY;
3563 + if (i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) ==
3564 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 2) {
3565 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
3566 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1;
3568 + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3569 + csgf_sg->addr = temp->bus_addr;
3570 + csgf_sg->e = FSL_QDMA_E_SG_TABLE;
3574 + sg_block += fsl_comp->sg_block_src;
3575 + for_each_sg(dst_sg, sg, dst_nents, i) {
3576 + temp = sg_block + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
3577 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
3578 + i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
3579 + csgf_sg->addr = sg_dma_address(sg);
3580 + csgf_sg->length = sg_dma_len(sg);
3581 + total_dst_len += sg_dma_len(sg);
3583 + if (i == dst_nents - 1)
3584 + csgf_sg->f = FSL_QDMA_F_LAST_ENTRY;
3585 + if (i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) ==
3586 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 2) {
3587 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
3588 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1;
3590 + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3591 + csgf_sg->addr = temp->bus_addr;
3592 + csgf_sg->e = FSL_QDMA_E_SG_TABLE;
3596 + if (total_src_len != total_dst_len)
3597 + dev_err(&fsl_comp->qchan->vchan.chan.dev->device,
3598 + "The data length for src and dst isn't match.\n");
3600 + csgf_src->length = total_src_len;
3601 + csgf_dest->length = total_dst_len;
3603 + /* Descriptor Buffer */
3604 + sdf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
3605 + ddf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
3609 + * Prei-request full command descriptor for enqueue.
3611 +static int fsl_qdma_pre_request_enqueue_desc(struct fsl_qdma_queue *queue)
3613 + struct fsl_qdma_comp *comp_temp;
3616 + for (i = 0; i < queue->n_cq; i++) {
3617 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
3620 + comp_temp->virt_addr = dma_pool_alloc(queue->comp_pool,
3622 + &comp_temp->bus_addr);
3623 + if (!comp_temp->virt_addr)
3625 + list_add_tail(&comp_temp->list, &queue->comp_free);
3631 + * Request a command descriptor for enqueue.
3633 +static struct fsl_qdma_comp *fsl_qdma_request_enqueue_desc(
3634 + struct fsl_qdma_chan *fsl_chan,
3635 + unsigned int dst_nents,
3636 + unsigned int src_nents)
3638 + struct fsl_qdma_comp *comp_temp;
3639 + struct fsl_qdma_sg *sg_block;
3640 + struct fsl_qdma_queue *queue = fsl_chan->queue;
3641 + unsigned long flags;
3642 + unsigned int dst_sg_entry_block, src_sg_entry_block, sg_entry_total, i;
3644 + spin_lock_irqsave(&queue->queue_lock, flags);
3645 + if (list_empty(&queue->comp_free)) {
3646 + spin_unlock_irqrestore(&queue->queue_lock, flags);
3647 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
3650 + comp_temp->virt_addr = dma_pool_alloc(queue->comp_pool,
3652 + &comp_temp->bus_addr);
3653 + if (!comp_temp->virt_addr)
3656 + comp_temp = list_first_entry(&queue->comp_free,
3657 + struct fsl_qdma_comp,
3659 + list_del(&comp_temp->list);
3660 + spin_unlock_irqrestore(&queue->queue_lock, flags);
3663 + if (dst_nents != 0)
3664 + dst_sg_entry_block = dst_nents /
3665 + (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3667 + dst_sg_entry_block = 0;
3669 + if (src_nents != 0)
3670 + src_sg_entry_block = src_nents /
3671 + (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3673 + src_sg_entry_block = 0;
3675 + sg_entry_total = dst_sg_entry_block + src_sg_entry_block;
3676 + if (sg_entry_total) {
3677 + sg_block = kzalloc(sizeof(*sg_block) *
3682 + comp_temp->sg_block = sg_block;
3683 + for (i = 0; i < sg_entry_total; i++) {
3684 + sg_block->virt_addr = dma_pool_alloc(queue->sg_pool,
3686 + &sg_block->bus_addr);
3687 + memset(sg_block->virt_addr, 0,
3688 + FSL_QDMA_EXPECT_SG_ENTRY_NUM * 16);
3693 + comp_temp->sg_block_src = src_sg_entry_block;
3694 + comp_temp->sg_block_dst = dst_sg_entry_block;
3695 + comp_temp->qchan = fsl_chan;
3700 +static struct fsl_qdma_queue *fsl_qdma_alloc_queue_resources(
3701 + struct platform_device *pdev,
3702 + unsigned int queue_num)
3704 + struct device_node *np = pdev->dev.of_node;
3705 + struct fsl_qdma_queue *queue_head, *queue_temp;
3707 + unsigned int queue_size[FSL_QDMA_QUEUE_MAX];
3709 + if (queue_num > FSL_QDMA_QUEUE_MAX)
3710 + queue_num = FSL_QDMA_QUEUE_MAX;
3711 + len = sizeof(*queue_head) * queue_num;
3712 + queue_head = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
3716 + ret = of_property_read_u32_array(np, "queue-sizes", queue_size,
3719 + dev_err(&pdev->dev, "Can't get queue-sizes.\n");
3723 + for (i = 0; i < queue_num; i++) {
3724 + if (queue_size[i] > FSL_QDMA_CIRCULAR_DESC_SIZE_MAX
3725 + || queue_size[i] < FSL_QDMA_CIRCULAR_DESC_SIZE_MIN) {
3726 + dev_err(&pdev->dev, "Get wrong queue-sizes.\n");
3729 + queue_temp = queue_head + i;
3730 + queue_temp->cq = dma_alloc_coherent(&pdev->dev,
3731 + sizeof(struct fsl_qdma_ccdf) *
3733 + &queue_temp->bus_addr,
3735 + if (!queue_temp->cq)
3737 + queue_temp->n_cq = queue_size[i];
3738 + queue_temp->id = i;
3739 + queue_temp->virt_head = queue_temp->cq;
3740 + queue_temp->virt_tail = queue_temp->cq;
3742 + * The dma pool for queue command buffer
3744 + queue_temp->comp_pool = dma_pool_create("comp_pool",
3746 + FSL_QDMA_BASE_BUFFER_SIZE,
3748 + if (!queue_temp->comp_pool) {
3749 + dma_free_coherent(&pdev->dev,
3750 + sizeof(struct fsl_qdma_ccdf) *
3753 + queue_temp->bus_addr);
3757 + * The dma pool for queue command buffer
3759 + queue_temp->sg_pool = dma_pool_create("sg_pool",
3761 + FSL_QDMA_EXPECT_SG_ENTRY_NUM * 16,
3763 + if (!queue_temp->sg_pool) {
3764 + dma_free_coherent(&pdev->dev,
3765 + sizeof(struct fsl_qdma_ccdf) *
3768 + queue_temp->bus_addr);
3769 + dma_pool_destroy(queue_temp->comp_pool);
3773 + * List for queue command buffer
3775 + INIT_LIST_HEAD(&queue_temp->comp_used);
3776 + INIT_LIST_HEAD(&queue_temp->comp_free);
3777 + spin_lock_init(&queue_temp->queue_lock);
3780 + return queue_head;
3783 +static struct fsl_qdma_queue *fsl_qdma_prep_status_queue(
3784 + struct platform_device *pdev)
3786 + struct device_node *np = pdev->dev.of_node;
3787 + struct fsl_qdma_queue *status_head;
3788 + unsigned int status_size;
3791 + ret = of_property_read_u32(np, "status-sizes", &status_size);
3793 + dev_err(&pdev->dev, "Can't get status-sizes.\n");
3796 + if (status_size > FSL_QDMA_CIRCULAR_DESC_SIZE_MAX
3797 + || status_size < FSL_QDMA_CIRCULAR_DESC_SIZE_MIN) {
3798 + dev_err(&pdev->dev, "Get wrong status_size.\n");
3801 + status_head = devm_kzalloc(&pdev->dev, sizeof(*status_head),
3807 + * Buffer for queue command
3809 + status_head->cq = dma_alloc_coherent(&pdev->dev,
3810 + sizeof(struct fsl_qdma_ccdf) *
3812 + &status_head->bus_addr,
3814 + if (!status_head->cq)
3816 + status_head->n_cq = status_size;
3817 + status_head->virt_head = status_head->cq;
3818 + status_head->virt_tail = status_head->cq;
3819 + status_head->comp_pool = NULL;
3821 + return status_head;
3824 +static int fsl_qdma_halt(struct fsl_qdma_engine *fsl_qdma)
3826 + void __iomem *ctrl = fsl_qdma->ctrl_base;
3827 + void __iomem *block = fsl_qdma->block_base;
3831 + /* Disable the command queue and wait for idle state. */
3832 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
3833 + reg |= FSL_QDMA_DMR_DQD;
3834 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
3835 + for (i = 0; i < FSL_QDMA_QUEUE_NUM_MAX; i++)
3836 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BCQMR(i));
3839 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DSR);
3840 + if (!(reg & FSL_QDMA_DSR_DB))
3847 + /* Disable status queue. */
3848 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BSQMR);
3851 + * Clear the command queue interrupt detect register for all queues.
3853 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
3858 +static int fsl_qdma_queue_transfer_complete(struct fsl_qdma_engine *fsl_qdma)
3860 + struct fsl_qdma_queue *fsl_queue = fsl_qdma->queue;
3861 + struct fsl_qdma_queue *fsl_status = fsl_qdma->status;
3862 + struct fsl_qdma_queue *temp_queue;
3863 + struct fsl_qdma_comp *fsl_comp;
3864 + struct fsl_qdma_ccdf *status_addr;
3865 + struct fsl_qdma_csgf *csgf_src;
3866 + void __iomem *block = fsl_qdma->block_base;
3868 + bool duplicate, duplicate_handle;
3872 + duplicate_handle = 0;
3873 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQSR);
3874 + if (reg & FSL_QDMA_BSQSR_QE)
3876 + status_addr = fsl_status->virt_head;
3877 + if (status_addr->queue == pre_queue &&
3878 + status_addr->addr == pre_addr)
3881 + i = status_addr->queue;
3882 + pre_queue = status_addr->queue;
3883 + pre_addr = status_addr->addr;
3884 + temp_queue = fsl_queue + i;
3885 + spin_lock(&temp_queue->queue_lock);
3886 + if (list_empty(&temp_queue->comp_used)) {
3888 + duplicate_handle = 1;
3890 + spin_unlock(&temp_queue->queue_lock);
3894 + fsl_comp = list_first_entry(&temp_queue->comp_used,
3895 + struct fsl_qdma_comp,
3897 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr
3899 + if (fsl_comp->bus_addr + 16 !=
3900 + (dma_addr_t)status_addr->addr) {
3902 + duplicate_handle = 1;
3904 + spin_unlock(&temp_queue->queue_lock);
3910 + if (duplicate_handle) {
3911 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQMR);
3912 + reg |= FSL_QDMA_BSQMR_DI;
3913 + status_addr->addr = 0x0;
3914 + fsl_status->virt_head++;
3915 + if (fsl_status->virt_head == fsl_status->cq
3916 + + fsl_status->n_cq)
3917 + fsl_status->virt_head = fsl_status->cq;
3918 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
3919 + spin_unlock(&temp_queue->queue_lock);
3922 + list_del(&fsl_comp->list);
3924 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQMR);
3925 + reg |= FSL_QDMA_BSQMR_DI;
3926 + status_addr->addr = 0x0;
3927 + fsl_status->virt_head++;
3928 + if (fsl_status->virt_head == fsl_status->cq + fsl_status->n_cq)
3929 + fsl_status->virt_head = fsl_status->cq;
3930 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
3931 + spin_unlock(&temp_queue->queue_lock);
3933 + spin_lock(&fsl_comp->qchan->vchan.lock);
3934 + vchan_cookie_complete(&fsl_comp->vdesc);
3935 + fsl_comp->qchan->status = DMA_COMPLETE;
3936 + spin_unlock(&fsl_comp->qchan->vchan.lock);
3941 +static irqreturn_t fsl_qdma_error_handler(int irq, void *dev_id)
3943 + struct fsl_qdma_engine *fsl_qdma = dev_id;
3944 + unsigned int intr;
3945 + void __iomem *status = fsl_qdma->status_base;
3947 + intr = qdma_readl(fsl_qdma, status + FSL_QDMA_DEDR);
3950 + dev_err(fsl_qdma->dma_dev.dev, "DMA transaction error!\n");
3952 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEDR);
3953 + return IRQ_HANDLED;
3956 +static irqreturn_t fsl_qdma_queue_handler(int irq, void *dev_id)
3958 + struct fsl_qdma_engine *fsl_qdma = dev_id;
3959 + unsigned int intr, reg;
3960 + void __iomem *block = fsl_qdma->block_base;
3961 + void __iomem *ctrl = fsl_qdma->ctrl_base;
3963 + intr = qdma_readl(fsl_qdma, block + FSL_QDMA_BCQIDR(0));
3965 + if ((intr & FSL_QDMA_CQIDR_SQT) != 0)
3966 + intr = fsl_qdma_queue_transfer_complete(fsl_qdma);
3969 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
3970 + reg |= FSL_QDMA_DMR_DQD;
3971 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
3972 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BCQIER(0));
3973 + dev_err(fsl_qdma->dma_dev.dev, "QDMA: status err!\n");
3976 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
3978 + return IRQ_HANDLED;
3982 +fsl_qdma_irq_init(struct platform_device *pdev,
3983 + struct fsl_qdma_engine *fsl_qdma)
3987 + fsl_qdma->error_irq = platform_get_irq_byname(pdev,
3989 + if (fsl_qdma->error_irq < 0) {
3990 + dev_err(&pdev->dev, "Can't get qdma controller irq.\n");
3991 + return fsl_qdma->error_irq;
3994 + fsl_qdma->queue_irq = platform_get_irq_byname(pdev, "qdma-queue");
3995 + if (fsl_qdma->queue_irq < 0) {
3996 + dev_err(&pdev->dev, "Can't get qdma queue irq.\n");
3997 + return fsl_qdma->queue_irq;
4000 + ret = devm_request_irq(&pdev->dev, fsl_qdma->error_irq,
4001 + fsl_qdma_error_handler, 0, "qDMA error", fsl_qdma);
4003 + dev_err(&pdev->dev, "Can't register qDMA controller IRQ.\n");
4006 + ret = devm_request_irq(&pdev->dev, fsl_qdma->queue_irq,
4007 + fsl_qdma_queue_handler, 0, "qDMA queue", fsl_qdma);
4009 + dev_err(&pdev->dev, "Can't register qDMA queue IRQ.\n");
4016 +static int fsl_qdma_reg_init(struct fsl_qdma_engine *fsl_qdma)
4018 + struct fsl_qdma_queue *fsl_queue = fsl_qdma->queue;
4019 + struct fsl_qdma_queue *temp;
4020 + void __iomem *ctrl = fsl_qdma->ctrl_base;
4021 + void __iomem *status = fsl_qdma->status_base;
4022 + void __iomem *block = fsl_qdma->block_base;
4026 + /* Try to halt the qDMA engine first. */
4027 + ret = fsl_qdma_halt(fsl_qdma);
4029 + dev_err(fsl_qdma->dma_dev.dev, "DMA halt failed!");
4034 + * Clear the command queue interrupt detect register for all queues.
4036 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
4038 + for (i = 0; i < fsl_qdma->n_queues; i++) {
4039 + temp = fsl_queue + i;
4041 + * Initialize Command Queue registers to point to the first
4042 + * command descriptor in memory.
4043 + * Dequeue Pointer Address Registers
4044 + * Enqueue Pointer Address Registers
4046 + qdma_writel(fsl_qdma, temp->bus_addr,
4047 + block + FSL_QDMA_BCQDPA_SADDR(i));
4048 + qdma_writel(fsl_qdma, temp->bus_addr,
4049 + block + FSL_QDMA_BCQEPA_SADDR(i));
4051 + /* Initialize the queue mode. */
4052 + reg = FSL_QDMA_BCQMR_EN;
4053 + reg |= FSL_QDMA_BCQMR_CD_THLD(ilog2(temp->n_cq)-4);
4054 + reg |= FSL_QDMA_BCQMR_CQ_SIZE(ilog2(temp->n_cq)-6);
4055 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BCQMR(i));
4059 + * Workaround for erratum: ERR010812.
4060 + * We must enable XOFF to avoid the enqueue rejection occurs.
4061 + * Setting SQCCMR ENTER_WM to 0x20.
4063 + qdma_writel(fsl_qdma, FSL_QDMA_SQCCMR_ENTER_WM,
4064 + block + FSL_QDMA_SQCCMR);
4066 + * Initialize status queue registers to point to the first
4067 + * command descriptor in memory.
4068 + * Dequeue Pointer Address Registers
4069 + * Enqueue Pointer Address Registers
4071 + qdma_writel(fsl_qdma, fsl_qdma->status->bus_addr,
4072 + block + FSL_QDMA_SQEPAR);
4073 + qdma_writel(fsl_qdma, fsl_qdma->status->bus_addr,
4074 + block + FSL_QDMA_SQDPAR);
4075 + /* Initialize status queue interrupt. */
4076 + qdma_writel(fsl_qdma, FSL_QDMA_BCQIER_CQTIE,
4077 + block + FSL_QDMA_BCQIER(0));
4078 + qdma_writel(fsl_qdma, FSL_QDMA_BSQICR_ICEN | FSL_QDMA_BSQICR_ICST(5)
4080 + block + FSL_QDMA_BSQICR);
4081 + qdma_writel(fsl_qdma, FSL_QDMA_CQIER_MEIE | FSL_QDMA_CQIER_TEIE,
4082 + block + FSL_QDMA_CQIER);
4083 + /* Initialize controller interrupt register. */
4084 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEDR);
4085 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEIER);
4087 + /* Initialize the status queue mode. */
4088 + reg = FSL_QDMA_BSQMR_EN;
4089 + reg |= FSL_QDMA_BSQMR_CQ_SIZE(ilog2(fsl_qdma->status->n_cq)-6);
4090 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
4092 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
4093 + reg &= ~FSL_QDMA_DMR_DQD;
4094 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
4099 +static struct dma_async_tx_descriptor *fsl_qdma_prep_dma_sg(
4100 + struct dma_chan *chan,
4101 + struct scatterlist *dst_sg, unsigned int dst_nents,
4102 + struct scatterlist *src_sg, unsigned int src_nents,
4103 + unsigned long flags)
4105 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
4106 + struct fsl_qdma_comp *fsl_comp;
4108 + fsl_comp = fsl_qdma_request_enqueue_desc(fsl_chan,
4111 + fsl_qdma_comp_fill_sg(fsl_comp, dst_sg, dst_nents, src_sg, src_nents);
4113 + return vchan_tx_prep(&fsl_chan->vchan, &fsl_comp->vdesc, flags);
4116 +static struct dma_async_tx_descriptor *
4117 +fsl_qdma_prep_memcpy(struct dma_chan *chan, dma_addr_t dst,
4118 + dma_addr_t src, size_t len, unsigned long flags)
4120 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
4121 + struct fsl_qdma_comp *fsl_comp;
4123 + fsl_comp = fsl_qdma_request_enqueue_desc(fsl_chan, 0, 0);
4124 + fsl_qdma_comp_fill_memcpy(fsl_comp, dst, src, len);
4126 + return vchan_tx_prep(&fsl_chan->vchan, &fsl_comp->vdesc, flags);
4129 +static void fsl_qdma_enqueue_desc(struct fsl_qdma_chan *fsl_chan)
4131 + void __iomem *block = fsl_chan->qdma->block_base;
4132 + struct fsl_qdma_queue *fsl_queue = fsl_chan->queue;
4133 + struct fsl_qdma_comp *fsl_comp;
4134 + struct virt_dma_desc *vdesc;
4137 + reg = qdma_readl(fsl_chan->qdma, block + FSL_QDMA_BCQSR(fsl_queue->id));
4138 + if (reg & (FSL_QDMA_BCQSR_QF | FSL_QDMA_BCQSR_XOFF))
4140 + vdesc = vchan_next_desc(&fsl_chan->vchan);
4143 + list_del(&vdesc->node);
4144 + fsl_comp = to_fsl_qdma_comp(vdesc);
4146 + memcpy(fsl_queue->virt_head++, fsl_comp->virt_addr, 16);
4147 + if (fsl_queue->virt_head == fsl_queue->cq + fsl_queue->n_cq)
4148 + fsl_queue->virt_head = fsl_queue->cq;
4150 + list_add_tail(&fsl_comp->list, &fsl_queue->comp_used);
4152 + reg = qdma_readl(fsl_chan->qdma, block + FSL_QDMA_BCQMR(fsl_queue->id));
4153 + reg |= FSL_QDMA_BCQMR_EI;
4154 + qdma_writel(fsl_chan->qdma, reg, block + FSL_QDMA_BCQMR(fsl_queue->id));
4155 + fsl_chan->status = DMA_IN_PROGRESS;
4158 +static enum dma_status fsl_qdma_tx_status(struct dma_chan *chan,
4159 + dma_cookie_t cookie, struct dma_tx_state *txstate)
4161 + return dma_cookie_status(chan, cookie, txstate);
4164 +static void fsl_qdma_free_desc(struct virt_dma_desc *vdesc)
4166 + struct fsl_qdma_comp *fsl_comp;
4167 + struct fsl_qdma_queue *fsl_queue;
4168 + struct fsl_qdma_sg *sg_block;
4169 + unsigned long flags;
4172 + fsl_comp = to_fsl_qdma_comp(vdesc);
4173 + fsl_queue = fsl_comp->qchan->queue;
4175 + if (fsl_comp->sg_block) {
4176 + for (i = 0; i < fsl_comp->sg_block_src +
4177 + fsl_comp->sg_block_dst; i++) {
4178 + sg_block = fsl_comp->sg_block + i;
4179 + dma_pool_free(fsl_queue->sg_pool,
4180 + sg_block->virt_addr,
4181 + sg_block->bus_addr);
4183 + kfree(fsl_comp->sg_block);
4186 + spin_lock_irqsave(&fsl_queue->queue_lock, flags);
4187 + list_add_tail(&fsl_comp->list, &fsl_queue->comp_free);
4188 + spin_unlock_irqrestore(&fsl_queue->queue_lock, flags);
4191 +static void fsl_qdma_issue_pending(struct dma_chan *chan)
4193 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
4194 + struct fsl_qdma_queue *fsl_queue = fsl_chan->queue;
4195 + unsigned long flags;
4197 + spin_lock_irqsave(&fsl_queue->queue_lock, flags);
4198 + spin_lock(&fsl_chan->vchan.lock);
4199 + if (vchan_issue_pending(&fsl_chan->vchan))
4200 + fsl_qdma_enqueue_desc(fsl_chan);
4201 + spin_unlock(&fsl_chan->vchan.lock);
4202 + spin_unlock_irqrestore(&fsl_queue->queue_lock, flags);
4205 +static int fsl_qdma_probe(struct platform_device *pdev)
4207 + struct device_node *np = pdev->dev.of_node;
4208 + struct fsl_qdma_engine *fsl_qdma;
4209 + struct fsl_qdma_chan *fsl_chan;
4210 + struct resource *res;
4211 + unsigned int len, chans, queues;
4214 + ret = of_property_read_u32(np, "channels", &chans);
4216 + dev_err(&pdev->dev, "Can't get channels.\n");
4220 + len = sizeof(*fsl_qdma) + sizeof(*fsl_chan) * chans;
4221 + fsl_qdma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
4225 + ret = of_property_read_u32(np, "queues", &queues);
4227 + dev_err(&pdev->dev, "Can't get queues.\n");
4231 + fsl_qdma->queue = fsl_qdma_alloc_queue_resources(pdev, queues);
4232 + if (!fsl_qdma->queue)
4235 + fsl_qdma->status = fsl_qdma_prep_status_queue(pdev);
4236 + if (!fsl_qdma->status)
4239 + fsl_qdma->n_chans = chans;
4240 + fsl_qdma->n_queues = queues;
4241 + mutex_init(&fsl_qdma->fsl_qdma_mutex);
4243 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
4244 + fsl_qdma->ctrl_base = devm_ioremap_resource(&pdev->dev, res);
4245 + if (IS_ERR(fsl_qdma->ctrl_base))
4246 + return PTR_ERR(fsl_qdma->ctrl_base);
4248 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
4249 + fsl_qdma->status_base = devm_ioremap_resource(&pdev->dev, res);
4250 + if (IS_ERR(fsl_qdma->status_base))
4251 + return PTR_ERR(fsl_qdma->status_base);
4253 + res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
4254 + fsl_qdma->block_base = devm_ioremap_resource(&pdev->dev, res);
4255 + if (IS_ERR(fsl_qdma->block_base))
4256 + return PTR_ERR(fsl_qdma->block_base);
4258 + ret = fsl_qdma_irq_init(pdev, fsl_qdma);
4262 + fsl_qdma->big_endian = of_property_read_bool(np, "big-endian");
4263 + INIT_LIST_HEAD(&fsl_qdma->dma_dev.channels);
4264 + for (i = 0; i < fsl_qdma->n_chans; i++) {
4265 + struct fsl_qdma_chan *fsl_chan = &fsl_qdma->chans[i];
4267 + fsl_chan->qdma = fsl_qdma;
4268 + fsl_chan->queue = fsl_qdma->queue + i % fsl_qdma->n_queues;
4269 + fsl_chan->vchan.desc_free = fsl_qdma_free_desc;
4270 + INIT_LIST_HEAD(&fsl_chan->qcomp);
4271 + vchan_init(&fsl_chan->vchan, &fsl_qdma->dma_dev);
4273 + for (i = 0; i < fsl_qdma->n_queues; i++)
4274 + fsl_qdma_pre_request_enqueue_desc(fsl_qdma->queue + i);
4276 + dma_cap_set(DMA_MEMCPY, fsl_qdma->dma_dev.cap_mask);
4277 + dma_cap_set(DMA_SG, fsl_qdma->dma_dev.cap_mask);
4279 + fsl_qdma->dma_dev.dev = &pdev->dev;
4280 + fsl_qdma->dma_dev.device_alloc_chan_resources
4281 + = fsl_qdma_alloc_chan_resources;
4282 + fsl_qdma->dma_dev.device_free_chan_resources
4283 + = fsl_qdma_free_chan_resources;
4284 + fsl_qdma->dma_dev.device_tx_status = fsl_qdma_tx_status;
4285 + fsl_qdma->dma_dev.device_prep_dma_memcpy = fsl_qdma_prep_memcpy;
4286 + fsl_qdma->dma_dev.device_prep_dma_sg = fsl_qdma_prep_dma_sg;
4287 + fsl_qdma->dma_dev.device_issue_pending = fsl_qdma_issue_pending;
4289 + dma_set_mask(&pdev->dev, DMA_BIT_MASK(40));
4291 + platform_set_drvdata(pdev, fsl_qdma);
4293 + ret = dma_async_device_register(&fsl_qdma->dma_dev);
4295 + dev_err(&pdev->dev, "Can't register Freescale qDMA engine.\n");
4299 + ret = fsl_qdma_reg_init(fsl_qdma);
4301 + dev_err(&pdev->dev, "Can't Initialize the qDMA engine.\n");
4309 +static int fsl_qdma_remove(struct platform_device *pdev)
4311 + struct device_node *np = pdev->dev.of_node;
4312 + struct fsl_qdma_engine *fsl_qdma = platform_get_drvdata(pdev);
4313 + struct fsl_qdma_queue *queue_temp;
4314 + struct fsl_qdma_queue *status = fsl_qdma->status;
4315 + struct fsl_qdma_comp *comp_temp, *_comp_temp;
4318 + of_dma_controller_free(np);
4319 + dma_async_device_unregister(&fsl_qdma->dma_dev);
4321 + /* Free descriptor areas */
4322 + for (i = 0; i < fsl_qdma->n_queues; i++) {
4323 + queue_temp = fsl_qdma->queue + i;
4324 + list_for_each_entry_safe(comp_temp, _comp_temp,
4325 + &queue_temp->comp_used, list) {
4326 + dma_pool_free(queue_temp->comp_pool,
4327 + comp_temp->virt_addr,
4328 + comp_temp->bus_addr);
4329 + list_del(&comp_temp->list);
4332 + list_for_each_entry_safe(comp_temp, _comp_temp,
4333 + &queue_temp->comp_free, list) {
4334 + dma_pool_free(queue_temp->comp_pool,
4335 + comp_temp->virt_addr,
4336 + comp_temp->bus_addr);
4337 + list_del(&comp_temp->list);
4340 + dma_free_coherent(&pdev->dev, sizeof(struct fsl_qdma_ccdf) *
4341 + queue_temp->n_cq, queue_temp->cq,
4342 + queue_temp->bus_addr);
4343 + dma_pool_destroy(queue_temp->comp_pool);
4346 + dma_free_coherent(&pdev->dev, sizeof(struct fsl_qdma_ccdf) *
4347 + status->n_cq, status->cq, status->bus_addr);
4351 +static const struct of_device_id fsl_qdma_dt_ids[] = {
4352 + { .compatible = "fsl,ls1021a-qdma", },
4353 + { /* sentinel */ }
4355 +MODULE_DEVICE_TABLE(of, fsl_qdma_dt_ids);
4357 +static struct platform_driver fsl_qdma_driver = {
4359 + .name = "fsl-qdma",
4360 + .owner = THIS_MODULE,
4361 + .of_match_table = fsl_qdma_dt_ids,
4363 + .probe = fsl_qdma_probe,
4364 + .remove = fsl_qdma_remove,
4367 +static int __init fsl_qdma_init(void)
4369 + return platform_driver_register(&fsl_qdma_driver);
4371 +subsys_initcall(fsl_qdma_init);
4373 +static void __exit fsl_qdma_exit(void)
4375 + platform_driver_unregister(&fsl_qdma_driver);
4377 +module_exit(fsl_qdma_exit);
4379 +MODULE_ALIAS("platform:fsl-qdma");
4380 +MODULE_DESCRIPTION("Freescale qDMA engine driver");
4381 +MODULE_LICENSE("GPL v2");