1 From 659603c5f6cbc3d39922d4374df25ae4627d0e88 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 | 14 +
12 drivers/dma/Makefile | 2 +
13 drivers/dma/dpaa2-qdma/Kconfig | 8 +
14 drivers/dma/dpaa2-qdma/Makefile | 8 +
15 drivers/dma/dpaa2-qdma/dpaa2-qdma.c | 986 +++++++++++++++++++++++++
16 drivers/dma/dpaa2-qdma/dpaa2-qdma.h | 262 +++++++
17 drivers/dma/dpaa2-qdma/dpdmai.c | 454 ++++++++++++
18 drivers/dma/dpaa2-qdma/fsl_dpdmai.h | 521 ++++++++++++++
19 drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h | 222 ++++++
20 drivers/dma/fsl-qdma.c | 1201 +++++++++++++++++++++++++++++++
21 10 files changed, 3678 insertions(+)
22 create mode 100644 drivers/dma/dpaa2-qdma/Kconfig
23 create mode 100644 drivers/dma/dpaa2-qdma/Makefile
24 create mode 100644 drivers/dma/dpaa2-qdma/dpaa2-qdma.c
25 create mode 100644 drivers/dma/dpaa2-qdma/dpaa2-qdma.h
26 create mode 100644 drivers/dma/dpaa2-qdma/dpdmai.c
27 create mode 100644 drivers/dma/dpaa2-qdma/fsl_dpdmai.h
28 create mode 100644 drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h
29 create mode 100644 drivers/dma/fsl-qdma.c
31 --- a/drivers/dma/Kconfig
32 +++ b/drivers/dma/Kconfig
33 @@ -192,6 +192,20 @@ config FSL_EDMA
34 multiplexing capability for DMA request sources(slot).
35 This module can be found on Freescale Vybrid and LS-1 SoCs.
38 + tristate "Freescale qDMA engine support"
40 + select DMA_VIRTUAL_CHANNELS
41 + select DMA_ENGINE_RAID
42 + select ASYNC_TX_ENABLE_CHANNEL_SWITCH
44 + Support the Freescale qDMA engine with command queue and legacy mode.
45 + Channel virtualization is supported through enqueuing of DMA jobs to,
46 + or dequeuing DMA jobs from, different work queues.
47 + This module can be found on Freescale LS SoCs.
49 +source drivers/dma/dpaa2-qdma/Kconfig
52 tristate "Freescale RAID engine Support"
53 depends on FSL_SOC && !ASYNC_TX_ENABLE_CHANNEL_SWITCH
54 --- a/drivers/dma/Makefile
55 +++ b/drivers/dma/Makefile
56 @@ -29,6 +29,8 @@ obj-$(CONFIG_DW_DMAC_CORE) += dw/
57 obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o
58 obj-$(CONFIG_FSL_DMA) += fsldma.o
59 obj-$(CONFIG_FSL_EDMA) += fsl-edma.o
60 +obj-$(CONFIG_FSL_QDMA) += fsl-qdma.o
61 +obj-$(CONFIG_FSL_DPAA2_QDMA) += dpaa2-qdma/
62 obj-$(CONFIG_FSL_RAID) += fsl_raid.o
63 obj-$(CONFIG_HSU_DMA) += hsu/
64 obj-$(CONFIG_IMG_MDC_DMA) += img-mdc-dma.o
66 +++ b/drivers/dma/dpaa2-qdma/Kconfig
68 +menuconfig FSL_DPAA2_QDMA
69 + tristate "NXP DPAA2 QDMA"
70 + depends on FSL_MC_BUS && FSL_MC_DPIO
72 + select DMA_VIRTUAL_CHANNELS
74 + NXP Data Path Acceleration Architecture 2 QDMA driver,
75 + using the NXP MC bus driver.
77 +++ b/drivers/dma/dpaa2-qdma/Makefile
80 +# Makefile for the NXP DPAA2 CAAM controllers
82 +ccflags-y += -DVERSION=\"\"
84 +obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma.o
86 +fsl-dpaa2-qdma-objs := dpaa2-qdma.o dpdmai.o
88 +++ b/drivers/dma/dpaa2-qdma/dpaa2-qdma.c
91 + * drivers/dma/dpaa2-qdma/dpaa2-qdma.c
93 + * Copyright 2015-2017 NXP Semiconductor, Inc.
94 + * Author: Changming Huang <jerry.huang@nxp.com>
96 + * Driver for the NXP QDMA engine with QMan mode.
97 + * Channel virtualization is supported through enqueuing of DMA jobs to,
98 + * or dequeuing DMA jobs from different work queues with QMan portal.
99 + * This module can be found on NXP LS2 SoCs.
101 + * This program is free software; you can redistribute it and/or modify it
102 + * under the terms of the GNU General Public License as published by the
103 + * Free Software Foundation; either version 2 of the License, or (at your
104 + * option) any later version.
107 +#include <linux/init.h>
108 +#include <linux/module.h>
109 +#include <linux/interrupt.h>
110 +#include <linux/clk.h>
111 +#include <linux/dma-mapping.h>
112 +#include <linux/dmapool.h>
113 +#include <linux/slab.h>
114 +#include <linux/spinlock.h>
115 +#include <linux/of.h>
116 +#include <linux/of_device.h>
117 +#include <linux/of_address.h>
118 +#include <linux/of_irq.h>
119 +#include <linux/of_dma.h>
120 +#include <linux/types.h>
121 +#include <linux/delay.h>
122 +#include <linux/iommu.h>
124 +#include "../virt-dma.h"
126 +#include "../../../drivers/staging/fsl-mc/include/mc.h"
127 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-io.h"
128 +#include "../../../drivers/staging/fsl-mc/include/dpaa2-fd.h"
129 +#include "fsl_dpdmai_cmd.h"
130 +#include "fsl_dpdmai.h"
131 +#include "dpaa2-qdma.h"
133 +static bool smmu_disable = true;
135 +static struct dpaa2_qdma_chan *to_dpaa2_qdma_chan(struct dma_chan *chan)
137 + return container_of(chan, struct dpaa2_qdma_chan, vchan.chan);
140 +static struct dpaa2_qdma_comp *to_fsl_qdma_comp(struct virt_dma_desc *vd)
142 + return container_of(vd, struct dpaa2_qdma_comp, vdesc);
145 +static int dpaa2_qdma_alloc_chan_resources(struct dma_chan *chan)
150 +static void dpaa2_qdma_free_chan_resources(struct dma_chan *chan)
152 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
153 + unsigned long flags;
156 + spin_lock_irqsave(&dpaa2_chan->vchan.lock, flags);
157 + vchan_get_all_descriptors(&dpaa2_chan->vchan, &head);
158 + spin_unlock_irqrestore(&dpaa2_chan->vchan.lock, flags);
160 + vchan_dma_desc_free_list(&dpaa2_chan->vchan, &head);
164 + * Request a command descriptor for enqueue.
166 +static struct dpaa2_qdma_comp *
167 +dpaa2_qdma_request_desc(struct dpaa2_qdma_chan *dpaa2_chan)
169 + struct dpaa2_qdma_comp *comp_temp = NULL;
170 + unsigned long flags;
172 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
173 + if (list_empty(&dpaa2_chan->comp_free)) {
174 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
175 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
178 + comp_temp->fd_virt_addr = dma_pool_alloc(dpaa2_chan->fd_pool,
179 + GFP_NOWAIT, &comp_temp->fd_bus_addr);
180 + if (!comp_temp->fd_virt_addr)
183 + comp_temp->fl_virt_addr =
184 + (void *)((struct dpaa2_fd *)
185 + comp_temp->fd_virt_addr + 1);
186 + comp_temp->fl_bus_addr = comp_temp->fd_bus_addr +
187 + sizeof(struct dpaa2_fd);
188 + comp_temp->desc_virt_addr =
189 + (void *)((struct dpaa2_frame_list *)
190 + comp_temp->fl_virt_addr + 3);
191 + comp_temp->desc_bus_addr = comp_temp->fl_bus_addr +
192 + sizeof(struct dpaa2_frame_list) * 3;
194 + comp_temp->qchan = dpaa2_chan;
195 + comp_temp->sg_blk_num = 0;
196 + INIT_LIST_HEAD(&comp_temp->sg_src_head);
197 + INIT_LIST_HEAD(&comp_temp->sg_dst_head);
200 + comp_temp = list_first_entry(&dpaa2_chan->comp_free,
201 + struct dpaa2_qdma_comp, list);
202 + list_del(&comp_temp->list);
203 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
205 + comp_temp->qchan = dpaa2_chan;
210 +static void dpaa2_qdma_populate_fd(uint32_t format,
211 + struct dpaa2_qdma_comp *dpaa2_comp)
213 + struct dpaa2_fd *fd;
215 + fd = (struct dpaa2_fd *)dpaa2_comp->fd_virt_addr;
216 + memset(fd, 0, sizeof(struct dpaa2_fd));
219 + fd->simple.addr = dpaa2_comp->fl_bus_addr;
220 + /* Bypass memory translation, Frame list format, short length disable */
221 + /* we need to disable BMT if fsl-mc use iova addr */
223 + fd->simple.bpid = QMAN_FD_BMT_ENABLE;
224 + fd->simple.format_offset = QMAN_FD_FMT_ENABLE | QMAN_FD_SL_DISABLE;
226 + fd->simple.frc = format | QDMA_SER_CTX;
229 +/* first frame list for descriptor buffer */
230 +static void dpaa2_qdma_populate_first_framel(
231 + struct dpaa2_frame_list *f_list,
232 + struct dpaa2_qdma_comp *dpaa2_comp)
234 + struct dpaa2_qdma_sd_d *sdd;
236 + sdd = (struct dpaa2_qdma_sd_d *)dpaa2_comp->desc_virt_addr;
237 + memset(sdd, 0, 2 * (sizeof(*sdd)));
238 + /* source and destination descriptor */
239 + sdd->cmd = QDMA_SD_CMD_RDTTYPE_COHERENT; /* source descriptor CMD */
241 + sdd->cmd = QDMA_DD_CMD_WRTTYPE_COHERENT; /* dest descriptor CMD */
243 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
244 + /* first frame list to source descriptor */
245 + f_list->addr_lo = dpaa2_comp->desc_bus_addr;
246 + f_list->addr_hi = (dpaa2_comp->desc_bus_addr >> 32);
247 + f_list->data_len.data_len_sl0 = 0x20; /* source/destination desc len */
248 + f_list->fmt = QDMA_FL_FMT_SBF; /* single buffer frame */
250 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
251 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
252 + f_list->f = 0; /* not the last frame list */
255 +/* source and destination frame list */
256 +static void dpaa2_qdma_populate_frames(struct dpaa2_frame_list *f_list,
257 + dma_addr_t dst, dma_addr_t src, size_t len, uint8_t fmt)
259 + /* source frame list to source buffer */
260 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
261 + f_list->addr_lo = src;
262 + f_list->addr_hi = (src >> 32);
263 + f_list->data_len.data_len_sl0 = len;
264 + f_list->fmt = fmt; /* single buffer frame or scatter gather frame */
266 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
267 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
268 + f_list->f = 0; /* not the last frame list */
271 + /* destination frame list to destination buffer */
272 + memset(f_list, 0, sizeof(struct dpaa2_frame_list));
273 + f_list->addr_lo = dst;
274 + f_list->addr_hi = (dst >> 32);
275 + f_list->data_len.data_len_sl0 = len;
276 + f_list->fmt = fmt; /* single buffer frame or scatter gather frame */
278 + f_list->bmt = QDMA_FL_BMT_ENABLE; /* bypass memory translation */
279 + f_list->sl = QDMA_FL_SL_LONG; /* long length */
280 + f_list->f = QDMA_FL_F; /* Final bit: 1, for last frame list */
283 +static struct dma_async_tx_descriptor *dpaa2_qdma_prep_memcpy(
284 + struct dma_chan *chan, dma_addr_t dst,
285 + dma_addr_t src, size_t len, unsigned long flags)
287 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
288 + struct dpaa2_qdma_comp *dpaa2_comp;
289 + struct dpaa2_frame_list *f_list;
292 + dpaa2_comp = dpaa2_qdma_request_desc(dpaa2_chan);
295 + format = QDMA_FD_LONG_FORMAT;
297 + format = QDMA_FD_SHORT_FORMAT;
299 + /* populate Frame descriptor */
300 + dpaa2_qdma_populate_fd(format, dpaa2_comp);
302 + f_list = (struct dpaa2_frame_list *)dpaa2_comp->fl_virt_addr;
305 + /* first frame list for descriptor buffer (logn format) */
306 + dpaa2_qdma_populate_first_framel(f_list, dpaa2_comp);
311 + dpaa2_qdma_populate_frames(f_list, dst, src, len, QDMA_FL_FMT_SBF);
313 + return vchan_tx_prep(&dpaa2_chan->vchan, &dpaa2_comp->vdesc, flags);
316 +static struct qdma_sg_blk *dpaa2_qdma_get_sg_blk(
317 + struct dpaa2_qdma_comp *dpaa2_comp,
318 + struct dpaa2_qdma_chan *dpaa2_chan)
320 + struct qdma_sg_blk *sg_blk = NULL;
321 + dma_addr_t phy_sgb;
322 + unsigned long flags;
324 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
325 + if (list_empty(&dpaa2_chan->sgb_free)) {
326 + sg_blk = (struct qdma_sg_blk *)dma_pool_alloc(
327 + dpaa2_chan->sg_blk_pool,
328 + GFP_NOWAIT, &phy_sgb);
330 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
333 + sg_blk->blk_virt_addr = (void *)(sg_blk + 1);
334 + sg_blk->blk_bus_addr = phy_sgb + sizeof(*sg_blk);
336 + sg_blk = list_first_entry(&dpaa2_chan->sgb_free,
337 + struct qdma_sg_blk, list);
338 + list_del(&sg_blk->list);
340 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
345 +static uint32_t dpaa2_qdma_populate_sg(struct device *dev,
346 + struct dpaa2_qdma_chan *dpaa2_chan,
347 + struct dpaa2_qdma_comp *dpaa2_comp,
348 + struct scatterlist *dst_sg, u32 dst_nents,
349 + struct scatterlist *src_sg, u32 src_nents)
351 + struct dpaa2_qdma_sg *src_sge;
352 + struct dpaa2_qdma_sg *dst_sge;
353 + struct qdma_sg_blk *sg_blk;
354 + struct qdma_sg_blk *sg_blk_dst;
360 + uint32_t total_len = 0;
363 + num = min(dst_nents, src_nents);
364 + blocks = num / (NUM_SG_PER_BLK - 1);
365 + if (num % (NUM_SG_PER_BLK - 1))
367 + if (dpaa2_comp->sg_blk_num < blocks) {
368 + len = blocks - dpaa2_comp->sg_blk_num;
369 + for (i = 0; i < len; i++) {
370 + /* source sg blocks */
371 + sg_blk = dpaa2_qdma_get_sg_blk(dpaa2_comp, dpaa2_chan);
374 + list_add_tail(&sg_blk->list, &dpaa2_comp->sg_src_head);
375 + /* destination sg blocks */
376 + sg_blk = dpaa2_qdma_get_sg_blk(dpaa2_comp, dpaa2_chan);
379 + list_add_tail(&sg_blk->list, &dpaa2_comp->sg_dst_head);
382 + len = dpaa2_comp->sg_blk_num - blocks;
383 + for (i = 0; i < len; i++) {
384 + spin_lock(&dpaa2_chan->queue_lock);
385 + /* handle source sg blocks */
386 + sg_blk = list_first_entry(&dpaa2_comp->sg_src_head,
387 + struct qdma_sg_blk, list);
388 + list_del(&sg_blk->list);
389 + list_add_tail(&sg_blk->list, &dpaa2_chan->sgb_free);
390 + /* handle destination sg blocks */
391 + sg_blk = list_first_entry(&dpaa2_comp->sg_dst_head,
392 + struct qdma_sg_blk, list);
393 + list_del(&sg_blk->list);
394 + list_add_tail(&sg_blk->list, &dpaa2_chan->sgb_free);
395 + spin_unlock(&dpaa2_chan->queue_lock);
398 + dpaa2_comp->sg_blk_num = blocks;
400 + /* get the first source sg phy address */
401 + sg_blk = list_first_entry(&dpaa2_comp->sg_src_head,
402 + struct qdma_sg_blk, list);
403 + dpaa2_comp->sge_src_bus_addr = sg_blk->blk_bus_addr;
404 + /* get the first destinaiton sg phy address */
405 + sg_blk_dst = list_first_entry(&dpaa2_comp->sg_dst_head,
406 + struct qdma_sg_blk, list);
407 + dpaa2_comp->sge_dst_bus_addr = sg_blk_dst->blk_bus_addr;
409 + for (i = 0; i < blocks; i++) {
410 + src_sge = (struct dpaa2_qdma_sg *)sg_blk->blk_virt_addr;
411 + dst_sge = (struct dpaa2_qdma_sg *)sg_blk_dst->blk_virt_addr;
413 + for (j = 0; j < (NUM_SG_PER_BLK - 1); j++) {
414 + len = min(sg_dma_len(dst_sg), sg_dma_len(src_sg));
418 + src = sg_dma_address(src_sg);
419 + dst = sg_dma_address(dst_sg);
422 + src_sge->addr_lo = src;
423 + src_sge->addr_hi = (src >> 32);
424 + src_sge->data_len.data_len_sl0 = len;
425 + src_sge->ctrl.sl = QDMA_SG_SL_LONG;
426 + src_sge->ctrl.fmt = QDMA_SG_FMT_SDB;
427 + /* destination SG */
428 + dst_sge->addr_lo = dst;
429 + dst_sge->addr_hi = (dst >> 32);
430 + dst_sge->data_len.data_len_sl0 = len;
431 + dst_sge->ctrl.sl = QDMA_SG_SL_LONG;
432 + dst_sge->ctrl.fmt = QDMA_SG_FMT_SDB;
436 + src_sge->ctrl.f = QDMA_SG_F;
437 + dst_sge->ctrl.f = QDMA_SG_F;
440 + dst_sg = sg_next(dst_sg);
441 + src_sg = sg_next(src_sg);
444 + if (j == (NUM_SG_PER_BLK - 2)) {
445 + /* for next blocks, extension */
446 + sg_blk = list_next_entry(sg_blk, list);
447 + sg_blk_dst = list_next_entry(sg_blk_dst, list);
448 + src_sge->addr_lo = sg_blk->blk_bus_addr;
449 + src_sge->addr_hi = sg_blk->blk_bus_addr >> 32;
450 + src_sge->ctrl.sl = QDMA_SG_SL_LONG;
451 + src_sge->ctrl.fmt = QDMA_SG_FMT_SGTE;
452 + dst_sge->addr_lo = sg_blk_dst->blk_bus_addr;
454 + sg_blk_dst->blk_bus_addr >> 32;
455 + dst_sge->ctrl.sl = QDMA_SG_SL_LONG;
456 + dst_sge->ctrl.fmt = QDMA_SG_FMT_SGTE;
465 +static struct dma_async_tx_descriptor *dpaa2_qdma_prep_sg(
466 + struct dma_chan *chan,
467 + struct scatterlist *dst_sg, u32 dst_nents,
468 + struct scatterlist *src_sg, u32 src_nents,
469 + unsigned long flags)
471 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
472 + struct dpaa2_qdma_comp *dpaa2_comp;
473 + struct dpaa2_frame_list *f_list;
474 + struct device *dev = dpaa2_chan->qdma->priv->dev;
475 + uint32_t total_len = 0;
477 + /* basic sanity checks */
478 + if (dst_nents == 0 || src_nents == 0)
481 + if (dst_sg == NULL || src_sg == NULL)
484 + /* get the descriptors required */
485 + dpaa2_comp = dpaa2_qdma_request_desc(dpaa2_chan);
487 + /* populate Frame descriptor */
488 + dpaa2_qdma_populate_fd(QDMA_FD_LONG_FORMAT, dpaa2_comp);
490 + /* prepare Scatter gather entry for source and destination */
491 + total_len = dpaa2_qdma_populate_sg(dev, dpaa2_chan,
492 + dpaa2_comp, dst_sg, dst_nents, src_sg, src_nents);
494 + f_list = (struct dpaa2_frame_list *)dpaa2_comp->fl_virt_addr;
495 + /* first frame list for descriptor buffer */
496 + dpaa2_qdma_populate_first_framel(f_list, dpaa2_comp);
498 + /* prepare Scatter gather entry for source and destination */
499 + /* populate source and destination frame list table */
500 + dpaa2_qdma_populate_frames(f_list, dpaa2_comp->sge_dst_bus_addr,
501 + dpaa2_comp->sge_src_bus_addr,
502 + total_len, QDMA_FL_FMT_SGE);
504 + return vchan_tx_prep(&dpaa2_chan->vchan, &dpaa2_comp->vdesc, flags);
507 +static enum dma_status dpaa2_qdma_tx_status(struct dma_chan *chan,
508 + dma_cookie_t cookie, struct dma_tx_state *txstate)
510 + return dma_cookie_status(chan, cookie, txstate);
513 +static void dpaa2_qdma_free_desc(struct virt_dma_desc *vdesc)
517 +static void dpaa2_qdma_issue_pending(struct dma_chan *chan)
519 + struct dpaa2_qdma_comp *dpaa2_comp;
520 + struct dpaa2_qdma_chan *dpaa2_chan = to_dpaa2_qdma_chan(chan);
521 + struct dpaa2_qdma_engine *dpaa2_qdma = dpaa2_chan->qdma;
522 + struct dpaa2_qdma_priv *priv = dpaa2_qdma->priv;
523 + struct virt_dma_desc *vdesc;
524 + struct dpaa2_fd *fd;
526 + unsigned long flags;
528 + spin_lock_irqsave(&dpaa2_chan->queue_lock, flags);
529 + spin_lock(&dpaa2_chan->vchan.lock);
530 + if (vchan_issue_pending(&dpaa2_chan->vchan)) {
531 + vdesc = vchan_next_desc(&dpaa2_chan->vchan);
534 + dpaa2_comp = to_fsl_qdma_comp(vdesc);
536 + fd = (struct dpaa2_fd *)dpaa2_comp->fd_virt_addr;
538 + list_del(&vdesc->node);
539 + list_add_tail(&dpaa2_comp->list, &dpaa2_chan->comp_used);
541 + /* TOBO: priority hard-coded to zero */
542 + err = dpaa2_io_service_enqueue_fq(NULL,
543 + priv->tx_queue_attr[0].fqid, fd);
545 + list_del(&dpaa2_comp->list);
546 + list_add_tail(&dpaa2_comp->list,
547 + &dpaa2_chan->comp_free);
552 + spin_unlock(&dpaa2_chan->vchan.lock);
553 + spin_unlock_irqrestore(&dpaa2_chan->queue_lock, flags);
556 +static int __cold dpaa2_qdma_setup(struct fsl_mc_device *ls_dev)
558 + struct device *dev = &ls_dev->dev;
559 + struct dpaa2_qdma_priv *priv;
560 + struct dpaa2_qdma_priv_per_prio *ppriv;
561 + uint8_t prio_def = DPDMAI_PRIO_NUM;
565 + priv = dev_get_drvdata(dev);
568 + priv->dpqdma_id = ls_dev->obj_desc.id;
570 + /*Get the handle for the DPDMAI this interface is associate with */
571 + err = dpdmai_open(priv->mc_io, 0, priv->dpqdma_id, &ls_dev->mc_handle);
573 + dev_err(dev, "dpdmai_open() failed\n");
576 + dev_info(dev, "Opened dpdmai object successfully\n");
578 + err = dpdmai_get_attributes(priv->mc_io, 0, ls_dev->mc_handle,
579 + &priv->dpdmai_attr);
581 + dev_err(dev, "dpdmai_get_attributes() failed\n");
585 + if (priv->dpdmai_attr.version.major > DPDMAI_VER_MAJOR) {
586 + dev_err(dev, "DPDMAI major version mismatch\n"
587 + "Found %u.%u, supported version is %u.%u\n",
588 + priv->dpdmai_attr.version.major,
589 + priv->dpdmai_attr.version.minor,
590 + DPDMAI_VER_MAJOR, DPDMAI_VER_MINOR);
593 + if (priv->dpdmai_attr.version.minor > DPDMAI_VER_MINOR) {
594 + dev_err(dev, "DPDMAI minor version mismatch\n"
595 + "Found %u.%u, supported version is %u.%u\n",
596 + priv->dpdmai_attr.version.major,
597 + priv->dpdmai_attr.version.minor,
598 + DPDMAI_VER_MAJOR, DPDMAI_VER_MINOR);
601 + priv->num_pairs = min(priv->dpdmai_attr.num_of_priorities, prio_def);
602 + ppriv = kcalloc(priv->num_pairs, sizeof(*ppriv), GFP_KERNEL);
604 + dev_err(dev, "kzalloc for ppriv failed\n");
607 + priv->ppriv = ppriv;
609 + for (i = 0; i < priv->num_pairs; i++) {
610 + err = dpdmai_get_rx_queue(priv->mc_io, 0, ls_dev->mc_handle,
611 + i, &priv->rx_queue_attr[i]);
613 + dev_err(dev, "dpdmai_get_rx_queue() failed\n");
616 + ppriv->rsp_fqid = priv->rx_queue_attr[i].fqid;
618 + err = dpdmai_get_tx_queue(priv->mc_io, 0, ls_dev->mc_handle,
619 + i, &priv->tx_queue_attr[i]);
621 + dev_err(dev, "dpdmai_get_tx_queue() failed\n");
624 + ppriv->req_fqid = priv->tx_queue_attr[i].fqid;
626 + ppriv->priv = priv;
633 +static void dpaa2_qdma_fqdan_cb(struct dpaa2_io_notification_ctx *ctx)
635 + struct dpaa2_qdma_priv_per_prio *ppriv = container_of(ctx,
636 + struct dpaa2_qdma_priv_per_prio, nctx);
637 + struct dpaa2_qdma_priv *priv = ppriv->priv;
638 + struct dpaa2_qdma_comp *dpaa2_comp, *_comp_tmp;
639 + struct dpaa2_qdma_chan *qchan;
640 + const struct dpaa2_fd *fd;
641 + const struct dpaa2_fd *fd_eq;
642 + struct dpaa2_dq *dq;
648 + uint32_t n_chans = priv->dpaa2_qdma->n_chans;
651 + err = dpaa2_io_service_pull_fq(NULL, ppriv->rsp_fqid,
657 + dq = dpaa2_io_store_next(ppriv->store, &is_last);
658 + } while (!is_last && !dq);
660 + dev_err(priv->dev, "FQID returned no valid frames!\n");
664 + /* obtain FD and process the error */
665 + fd = dpaa2_dq_fd(dq);
666 + status = fd->simple.ctrl & 0xff;
668 + dev_err(priv->dev, "FD error occurred\n");
670 + for (i = 0; i < n_chans; i++) {
671 + qchan = &priv->dpaa2_qdma->chans[i];
672 + spin_lock(&qchan->queue_lock);
673 + if (list_empty(&qchan->comp_used)) {
674 + spin_unlock(&qchan->queue_lock);
677 + list_for_each_entry_safe(dpaa2_comp, _comp_tmp,
678 + &qchan->comp_used, list) {
679 + fd_eq = (struct dpaa2_fd *)
680 + dpaa2_comp->fd_virt_addr;
682 + if (fd_eq->simple.addr ==
685 + list_del(&dpaa2_comp->list);
686 + list_add_tail(&dpaa2_comp->list,
687 + &qchan->comp_free);
689 + spin_lock(&qchan->vchan.lock);
690 + vchan_cookie_complete(
691 + &dpaa2_comp->vdesc);
692 + spin_unlock(&qchan->vchan.lock);
697 + spin_unlock(&qchan->queue_lock);
703 + dpaa2_io_service_rearm(NULL, ctx);
706 +static int __cold dpaa2_qdma_dpio_setup(struct dpaa2_qdma_priv *priv)
709 + struct device *dev = priv->dev;
710 + struct dpaa2_qdma_priv_per_prio *ppriv;
712 + num = priv->num_pairs;
713 + ppriv = priv->ppriv;
714 + for (i = 0; i < num; i++) {
715 + ppriv->nctx.is_cdan = 0;
716 + ppriv->nctx.desired_cpu = 1;
717 + ppriv->nctx.id = ppriv->rsp_fqid;
718 + ppriv->nctx.cb = dpaa2_qdma_fqdan_cb;
719 + err = dpaa2_io_service_register(NULL, &ppriv->nctx);
721 + dev_err(dev, "Notification register failed\n");
725 + ppriv->store = dpaa2_io_store_create(DPAA2_QDMA_STORE_SIZE,
727 + if (!ppriv->store) {
728 + dev_err(dev, "dpaa2_io_store_create() failed\n");
737 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
740 + while (ppriv >= priv->ppriv) {
741 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
742 + dpaa2_io_store_destroy(ppriv->store);
748 +static void __cold dpaa2_dpmai_store_free(struct dpaa2_qdma_priv *priv)
750 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
753 + for (i = 0; i < priv->num_pairs; i++) {
754 + dpaa2_io_store_destroy(ppriv->store);
759 +static void __cold dpaa2_dpdmai_dpio_free(struct dpaa2_qdma_priv *priv)
761 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
764 + for (i = 0; i < priv->num_pairs; i++) {
765 + dpaa2_io_service_deregister(NULL, &ppriv->nctx);
770 +static int __cold dpaa2_dpdmai_bind(struct dpaa2_qdma_priv *priv)
773 + struct dpdmai_rx_queue_cfg rx_queue_cfg;
774 + struct device *dev = priv->dev;
775 + struct dpaa2_qdma_priv_per_prio *ppriv;
776 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
779 + num = priv->num_pairs;
780 + ppriv = priv->ppriv;
781 + for (i = 0; i < num; i++) {
782 + rx_queue_cfg.options = DPDMAI_QUEUE_OPT_USER_CTX |
783 + DPDMAI_QUEUE_OPT_DEST;
784 + rx_queue_cfg.user_ctx = ppriv->nctx.qman64;
785 + rx_queue_cfg.dest_cfg.dest_type = DPDMAI_DEST_DPIO;
786 + rx_queue_cfg.dest_cfg.dest_id = ppriv->nctx.dpio_id;
787 + rx_queue_cfg.dest_cfg.priority = ppriv->prio;
788 + err = dpdmai_set_rx_queue(priv->mc_io, 0, ls_dev->mc_handle,
789 + rx_queue_cfg.dest_cfg.priority, &rx_queue_cfg);
791 + dev_err(dev, "dpdmai_set_rx_queue() failed\n");
801 +static int __cold dpaa2_dpdmai_dpio_unbind(struct dpaa2_qdma_priv *priv)
804 + struct device *dev = priv->dev;
805 + struct fsl_mc_device *ls_dev = to_fsl_mc_device(dev);
806 + struct dpaa2_qdma_priv_per_prio *ppriv = priv->ppriv;
809 + for (i = 0; i < priv->num_pairs; i++) {
810 + ppriv->nctx.qman64 = 0;
811 + ppriv->nctx.dpio_id = 0;
815 + err = dpdmai_reset(priv->mc_io, 0, ls_dev->mc_handle);
817 + dev_err(dev, "dpdmai_reset() failed\n");
822 +static void __cold dpaa2_dpdmai_free_pool(struct dpaa2_qdma_chan *qchan,
823 + struct list_head *head)
825 + struct qdma_sg_blk *sgb_tmp, *_sgb_tmp;
826 + /* free the QDMA SG pool block */
827 + list_for_each_entry_safe(sgb_tmp, _sgb_tmp, head, list) {
828 + sgb_tmp->blk_virt_addr = (void *)((struct qdma_sg_blk *)
829 + sgb_tmp->blk_virt_addr - 1);
830 + sgb_tmp->blk_bus_addr = sgb_tmp->blk_bus_addr
831 + - sizeof(*sgb_tmp);
832 + dma_pool_free(qchan->sg_blk_pool, sgb_tmp->blk_virt_addr,
833 + sgb_tmp->blk_bus_addr);
838 +static void __cold dpaa2_dpdmai_free_comp(struct dpaa2_qdma_chan *qchan,
839 + struct list_head *head)
841 + struct dpaa2_qdma_comp *comp_tmp, *_comp_tmp;
842 + /* free the QDMA comp resource */
843 + list_for_each_entry_safe(comp_tmp, _comp_tmp,
845 + dma_pool_free(qchan->fd_pool,
846 + comp_tmp->fd_virt_addr,
847 + comp_tmp->fd_bus_addr);
848 + /* free the SG source block on comp */
849 + dpaa2_dpdmai_free_pool(qchan, &comp_tmp->sg_src_head);
850 + /* free the SG destination block on comp */
851 + dpaa2_dpdmai_free_pool(qchan, &comp_tmp->sg_dst_head);
852 + list_del(&comp_tmp->list);
858 +static void __cold dpaa2_dpdmai_free_channels(
859 + struct dpaa2_qdma_engine *dpaa2_qdma)
861 + struct dpaa2_qdma_chan *qchan;
864 + num = dpaa2_qdma->n_chans;
865 + for (i = 0; i < num; i++) {
866 + qchan = &dpaa2_qdma->chans[i];
867 + dpaa2_dpdmai_free_comp(qchan, &qchan->comp_used);
868 + dpaa2_dpdmai_free_comp(qchan, &qchan->comp_free);
869 + dpaa2_dpdmai_free_pool(qchan, &qchan->sgb_free);
870 + dma_pool_destroy(qchan->fd_pool);
871 + dma_pool_destroy(qchan->sg_blk_pool);
875 +static int dpaa2_dpdmai_alloc_channels(struct dpaa2_qdma_engine *dpaa2_qdma)
877 + struct dpaa2_qdma_chan *dpaa2_chan;
878 + struct device *dev = &dpaa2_qdma->priv->dpdmai_dev->dev;
881 + INIT_LIST_HEAD(&dpaa2_qdma->dma_dev.channels);
882 + for (i = 0; i < dpaa2_qdma->n_chans; i++) {
883 + dpaa2_chan = &dpaa2_qdma->chans[i];
884 + dpaa2_chan->qdma = dpaa2_qdma;
885 + dpaa2_chan->vchan.desc_free = dpaa2_qdma_free_desc;
886 + vchan_init(&dpaa2_chan->vchan, &dpaa2_qdma->dma_dev);
888 + dpaa2_chan->fd_pool = dma_pool_create("fd_pool",
889 + dev, FD_POOL_SIZE, 32, 0);
890 + if (!dpaa2_chan->fd_pool)
892 + dpaa2_chan->sg_blk_pool = dma_pool_create("sg_blk_pool",
893 + dev, SG_POOL_SIZE, 32, 0);
894 + if (!dpaa2_chan->sg_blk_pool)
897 + spin_lock_init(&dpaa2_chan->queue_lock);
898 + INIT_LIST_HEAD(&dpaa2_chan->comp_used);
899 + INIT_LIST_HEAD(&dpaa2_chan->comp_free);
900 + INIT_LIST_HEAD(&dpaa2_chan->sgb_free);
905 +static int dpaa2_qdma_probe(struct fsl_mc_device *dpdmai_dev)
907 + struct dpaa2_qdma_priv *priv;
908 + struct device *dev = &dpdmai_dev->dev;
909 + struct dpaa2_qdma_engine *dpaa2_qdma;
912 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
915 + dev_set_drvdata(dev, priv);
916 + priv->dpdmai_dev = dpdmai_dev;
918 + priv->iommu_domain = iommu_get_domain_for_dev(dev);
919 + if (priv->iommu_domain)
920 + smmu_disable = false;
922 + /* obtain a MC portal */
923 + err = fsl_mc_portal_allocate(dpdmai_dev, 0, &priv->mc_io);
925 + dev_err(dev, "MC portal allocation failed\n");
929 + /* DPDMAI initialization */
930 + err = dpaa2_qdma_setup(dpdmai_dev);
932 + dev_err(dev, "dpaa2_dpdmai_setup() failed\n");
933 + goto err_dpdmai_setup;
937 + err = dpaa2_qdma_dpio_setup(priv);
939 + dev_err(dev, "dpaa2_dpdmai_dpio_setup() failed\n");
940 + goto err_dpio_setup;
943 + /* DPDMAI binding to DPIO */
944 + err = dpaa2_dpdmai_bind(priv);
946 + dev_err(dev, "dpaa2_dpdmai_bind() failed\n");
950 + /* DPDMAI enable */
951 + err = dpdmai_enable(priv->mc_io, 0, dpdmai_dev->mc_handle);
953 + dev_err(dev, "dpdmai_enable() faile\n");
957 + dpaa2_qdma = kzalloc(sizeof(*dpaa2_qdma), GFP_KERNEL);
963 + priv->dpaa2_qdma = dpaa2_qdma;
964 + dpaa2_qdma->priv = priv;
966 + dpaa2_qdma->n_chans = NUM_CH;
968 + err = dpaa2_dpdmai_alloc_channels(dpaa2_qdma);
970 + dev_err(dev, "QDMA alloc channels faile\n");
974 + dma_cap_set(DMA_PRIVATE, dpaa2_qdma->dma_dev.cap_mask);
975 + dma_cap_set(DMA_SLAVE, dpaa2_qdma->dma_dev.cap_mask);
976 + dma_cap_set(DMA_MEMCPY, dpaa2_qdma->dma_dev.cap_mask);
977 + dma_cap_set(DMA_SG, dpaa2_qdma->dma_dev.cap_mask);
979 + dpaa2_qdma->dma_dev.dev = dev;
980 + dpaa2_qdma->dma_dev.device_alloc_chan_resources
981 + = dpaa2_qdma_alloc_chan_resources;
982 + dpaa2_qdma->dma_dev.device_free_chan_resources
983 + = dpaa2_qdma_free_chan_resources;
984 + dpaa2_qdma->dma_dev.device_tx_status = dpaa2_qdma_tx_status;
985 + dpaa2_qdma->dma_dev.device_prep_dma_memcpy = dpaa2_qdma_prep_memcpy;
986 + dpaa2_qdma->dma_dev.device_prep_dma_sg = dpaa2_qdma_prep_sg;
987 + dpaa2_qdma->dma_dev.device_issue_pending = dpaa2_qdma_issue_pending;
989 + err = dma_async_device_register(&dpaa2_qdma->dma_dev);
991 + dev_err(dev, "Can't register NXP QDMA engine.\n");
998 + dpaa2_dpdmai_free_channels(dpaa2_qdma);
1001 + dpdmai_disable(priv->mc_io, 0, dpdmai_dev->mc_handle);
1003 + dpaa2_dpdmai_dpio_unbind(priv);
1005 + dpaa2_dpmai_store_free(priv);
1006 + dpaa2_dpdmai_dpio_free(priv);
1008 + dpdmai_close(priv->mc_io, 0, dpdmai_dev->mc_handle);
1010 + fsl_mc_portal_free(priv->mc_io);
1012 + kfree(priv->ppriv);
1014 + dev_set_drvdata(dev, NULL);
1018 +static int dpaa2_qdma_remove(struct fsl_mc_device *ls_dev)
1020 + struct device *dev;
1021 + struct dpaa2_qdma_priv *priv;
1022 + struct dpaa2_qdma_engine *dpaa2_qdma;
1024 + dev = &ls_dev->dev;
1025 + priv = dev_get_drvdata(dev);
1026 + dpaa2_qdma = priv->dpaa2_qdma;
1028 + dpdmai_disable(priv->mc_io, 0, ls_dev->mc_handle);
1029 + dpaa2_dpdmai_dpio_unbind(priv);
1030 + dpaa2_dpmai_store_free(priv);
1031 + dpaa2_dpdmai_dpio_free(priv);
1032 + dpdmai_close(priv->mc_io, 0, ls_dev->mc_handle);
1033 + fsl_mc_portal_free(priv->mc_io);
1034 + dev_set_drvdata(dev, NULL);
1035 + dpaa2_dpdmai_free_channels(dpaa2_qdma);
1037 + dma_async_device_unregister(&dpaa2_qdma->dma_dev);
1039 + kfree(dpaa2_qdma);
1044 +static const struct fsl_mc_device_id dpaa2_qdma_id_table[] = {
1046 + .vendor = FSL_MC_VENDOR_FREESCALE,
1047 + .obj_type = "dpdmai",
1052 +static struct fsl_mc_driver dpaa2_qdma_driver = {
1054 + .name = "dpaa2-qdma",
1055 + .owner = THIS_MODULE,
1057 + .probe = dpaa2_qdma_probe,
1058 + .remove = dpaa2_qdma_remove,
1059 + .match_id_table = dpaa2_qdma_id_table
1062 +static int __init dpaa2_qdma_driver_init(void)
1064 + return fsl_mc_driver_register(&(dpaa2_qdma_driver));
1066 +late_initcall(dpaa2_qdma_driver_init);
1068 +static void __exit fsl_qdma_exit(void)
1070 + fsl_mc_driver_unregister(&(dpaa2_qdma_driver));
1072 +module_exit(fsl_qdma_exit);
1074 +MODULE_DESCRIPTION("NXP DPAA2 qDMA driver");
1075 +MODULE_LICENSE("Dual BSD/GPL");
1077 +++ b/drivers/dma/dpaa2-qdma/dpaa2-qdma.h
1079 +/* Copyright 2015 NXP Semiconductor Inc.
1081 + * Redistribution and use in source and binary forms, with or without
1082 + * modification, are permitted provided that the following conditions are met:
1083 + * * Redistributions of source code must retain the above copyright
1084 + * notice, this list of conditions and the following disclaimer.
1085 + * * Redistributions in binary form must reproduce the above copyright
1086 + * notice, this list of conditions and the following disclaimer in the
1087 + * documentation and/or other materials provided with the distribution.
1088 + * * Neither the name of NXP Semiconductor nor the
1089 + * names of its contributors may be used to endorse or promote products
1090 + * derived from this software without specific prior written permission.
1093 + * ALTERNATIVELY, this software may be distributed under the terms of the
1094 + * GNU General Public License ("GPL") as published by the Free Software
1095 + * Foundation, either version 2 of that License or (at your option) any
1098 + * THIS SOFTWARE IS PROVIDED BY NXP Semiconductor ``AS IS'' AND ANY
1099 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1100 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1101 + * DISCLAIMED. IN NO EVENT SHALL NXP Semiconductor BE LIABLE FOR ANY
1102 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1103 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1104 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1105 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1106 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1107 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1110 +#ifndef __DPAA2_QDMA_H
1111 +#define __DPAA2_QDMA_H
1113 +#define LONG_FORMAT 1
1115 +#define DPAA2_QDMA_STORE_SIZE 16
1117 +#define NUM_SG_PER_BLK 16
1119 +#define QDMA_DMR_OFFSET 0x0
1120 +#define QDMA_DQ_EN (0 << 30)
1121 +#define QDMA_DQ_DIS (1 << 30)
1123 +#define QDMA_DSR_M_OFFSET 0x10004
1125 +struct dpaa2_qdma_sd_d {
1129 + uint32_t ssd:12; /* souce stride distance */
1130 + uint32_t sss:12; /* souce stride size */
1134 + uint32_t dsd:12; /* Destination stride distance */
1135 + uint32_t dss:12; /* Destination stride size */
1139 + uint32_t rbpcmd; /* Route-by-port command */
1141 +} __attribute__((__packed__));
1142 +/* Source descriptor command read transaction type for RBP=0:
1143 + coherent copy of cacheable memory */
1144 +#define QDMA_SD_CMD_RDTTYPE_COHERENT (0xb << 28)
1145 +/* Destination descriptor command write transaction type for RBP=0:
1146 + coherent copy of cacheable memory */
1147 +#define QDMA_DD_CMD_WRTTYPE_COHERENT (0x6 << 28)
1149 +#define QDMA_SG_FMT_SDB 0x0 /* single data buffer */
1150 +#define QDMA_SG_FMT_FDS 0x1 /* frame data section */
1151 +#define QDMA_SG_FMT_SGTE 0x2 /* SGT extension */
1152 +#define QDMA_SG_SL_SHORT 0x1 /* short length */
1153 +#define QDMA_SG_SL_LONG 0x0 /* short length */
1154 +#define QDMA_SG_F 0x1 /* last sg entry */
1155 +struct dpaa2_qdma_sg {
1156 + uint32_t addr_lo; /* address 0:31 */
1157 + uint32_t addr_hi:17; /* address 32:48 */
1160 + uint32_t data_len_sl0; /* SL=0, the long format */
1162 + uint32_t len:17; /* SL=1, the short format */
1163 + uint32_t reserve:3;
1166 + uint32_t size:10; /* buff size */
1168 + } data_len; /* AVAIL_LENGTH */
1173 + uint32_t offset:12;
1178 +} __attribute__((__packed__));
1180 +#define QMAN_FD_FMT_ENABLE (1 << 12) /* frame list table enable */
1181 +#define QMAN_FD_BMT_ENABLE (1 << 15) /* bypass memory translation */
1182 +#define QMAN_FD_BMT_DISABLE (0 << 15) /* bypass memory translation */
1183 +#define QMAN_FD_SL_DISABLE (0 << 14) /* short lengthe disabled */
1184 +#define QMAN_FD_SL_ENABLE (1 << 14) /* short lengthe enabled */
1186 +#define QDMA_SB_FRAME (0 << 28) /* single frame */
1187 +#define QDMA_SG_FRAME (2 << 28) /* scatter gather frames */
1188 +#define QDMA_FINAL_BIT_DISABLE (0 << 31) /* final bit disable */
1189 +#define QDMA_FINAL_BIT_ENABLE (1 << 31) /* final bit enable */
1191 +#define QDMA_FD_SHORT_FORMAT (1 << 11) /* short format */
1192 +#define QDMA_FD_LONG_FORMAT (0 << 11) /* long format */
1193 +#define QDMA_SER_DISABLE (0 << 8) /* no notification */
1194 +#define QDMA_SER_CTX (1 << 8) /* notification by FQD_CTX[fqid] */
1195 +#define QDMA_SER_DEST (2 << 8) /* notification by destination desc */
1196 +#define QDMA_SER_BOTH (3 << 8) /* soruce and dest notification */
1197 +#define QDMA_FD_SPF_ENALBE (1 << 30) /* source prefetch enable */
1199 +#define QMAN_FD_VA_ENABLE (1 << 14) /* Address used is virtual address */
1200 +#define QMAN_FD_VA_DISABLE (0 << 14)/* Address used is a real address */
1201 +#define QMAN_FD_CBMT_ENABLE (1 << 15) /* Flow Context: 49bit physical address */
1202 +#define QMAN_FD_CBMT_DISABLE (0 << 15) /* Flow Context: 64bit virtual address */
1203 +#define QMAN_FD_SC_DISABLE (0 << 27) /* stashing control */
1205 +#define QDMA_FL_FMT_SBF 0x0 /* Single buffer frame */
1206 +#define QDMA_FL_FMT_SGE 0x2 /* Scatter gather frame */
1207 +#define QDMA_FL_BMT_ENABLE 0x1 /* enable bypass memory translation */
1208 +#define QDMA_FL_BMT_DISABLE 0x0 /* enable bypass memory translation */
1209 +#define QDMA_FL_SL_LONG 0x0 /* long length */
1210 +#define QDMA_FL_SL_SHORT 0x1 /* short length */
1211 +#define QDMA_FL_F 0x1 /* last frame list bit */
1212 +/*Description of Frame list table structure*/
1213 +struct dpaa2_frame_list {
1214 + uint32_t addr_lo; /* lower 32 bits of address */
1215 + uint32_t addr_hi:17; /* upper 17 bits of address */
1216 + uint32_t resrvd:15;
1218 + uint32_t data_len_sl0; /* If SL=0, then data length is 32 */
1220 + uint32_t data_len:18; /* IF SL=1; length is 18bit */
1221 + uint32_t resrvd:2;
1222 + uint32_t mem:12; /* Valid only when SL=1 */
1226 + uint32_t bpid:14; /* Frame buffer pool ID */
1227 + uint32_t ivp:1; /* Invalid Pool ID. */
1228 + uint32_t bmt:1; /* Bypass Memory Translation */
1229 + uint32_t offset:12; /* Frame offset */
1230 + uint32_t fmt:2; /* Frame Format */
1231 + uint32_t sl:1; /* Short Length */
1232 + uint32_t f:1; /* Final bit */
1234 + uint32_t frc; /* Frame Context */
1236 + uint32_t err:8; /* Frame errors */
1237 + uint32_t resrvd0:8;
1238 + uint32_t asal:4; /* accelerator-specific annotation length */
1239 + uint32_t resrvd1:1;
1242 + uint32_t pta:1; /* pass-through annotation */
1243 + uint32_t resrvd2:8;
1245 + uint32_t flc_lo; /* lower 32 bits fo flow context */
1246 + uint32_t flc_hi; /* higher 32 bits fo flow context */
1247 +} __attribute__((__packed__));
1249 +struct dpaa2_qdma_chan {
1250 + struct virt_dma_chan vchan;
1251 + struct virt_dma_desc vdesc;
1252 + enum dma_status status;
1253 + struct dpaa2_qdma_engine *qdma;
1255 + struct mutex dpaa2_queue_mutex;
1256 + spinlock_t queue_lock;
1257 + struct dma_pool *fd_pool;
1258 + struct dma_pool *sg_blk_pool;
1260 + struct list_head comp_used;
1261 + struct list_head comp_free;
1263 + struct list_head sgb_free;
1266 +struct qdma_sg_blk {
1267 + dma_addr_t blk_bus_addr;
1268 + void *blk_virt_addr;
1269 + struct list_head list;
1272 +struct dpaa2_qdma_comp {
1273 + dma_addr_t fd_bus_addr;
1274 + dma_addr_t fl_bus_addr;
1275 + dma_addr_t desc_bus_addr;
1276 + dma_addr_t sge_src_bus_addr;
1277 + dma_addr_t sge_dst_bus_addr;
1278 + void *fd_virt_addr;
1279 + void *fl_virt_addr;
1280 + void *desc_virt_addr;
1281 + void *sg_src_virt_addr;
1282 + void *sg_dst_virt_addr;
1283 + struct qdma_sg_blk *sg_blk;
1284 + uint32_t sg_blk_num;
1285 + struct list_head sg_src_head;
1286 + struct list_head sg_dst_head;
1287 + struct dpaa2_qdma_chan *qchan;
1288 + struct virt_dma_desc vdesc;
1289 + struct list_head list;
1292 +struct dpaa2_qdma_engine {
1293 + struct dma_device dma_dev;
1295 + struct dpaa2_qdma_chan chans[NUM_CH];
1297 + struct dpaa2_qdma_priv *priv;
1301 + * dpaa2_qdma_priv - driver private data
1303 +struct dpaa2_qdma_priv {
1306 + struct iommu_domain *iommu_domain;
1307 + struct dpdmai_attr dpdmai_attr;
1308 + struct device *dev;
1309 + struct fsl_mc_io *mc_io;
1310 + struct fsl_mc_device *dpdmai_dev;
1312 + struct dpdmai_rx_queue_attr rx_queue_attr[DPDMAI_PRIO_NUM];
1313 + struct dpdmai_tx_queue_attr tx_queue_attr[DPDMAI_PRIO_NUM];
1315 + uint8_t num_pairs;
1317 + struct dpaa2_qdma_engine *dpaa2_qdma;
1318 + struct dpaa2_qdma_priv_per_prio *ppriv;
1321 +struct dpaa2_qdma_priv_per_prio {
1326 + struct dpaa2_io_store *store;
1327 + struct dpaa2_io_notification_ctx nctx;
1329 + struct dpaa2_qdma_priv *priv;
1332 +/* FD pool size: one FD + 3 Frame list + 2 source/destination descriptor */
1333 +#define FD_POOL_SIZE (sizeof(struct dpaa2_fd) + \
1334 + sizeof(struct dpaa2_frame_list) * 3 + \
1335 + sizeof(struct dpaa2_qdma_sd_d) * 2)
1337 +/* qdma_sg_blk + 16 SGs */
1338 +#define SG_POOL_SIZE (sizeof(struct qdma_sg_blk) +\
1339 + sizeof(struct dpaa2_qdma_sg) * NUM_SG_PER_BLK)
1340 +#endif /* __DPAA2_QDMA_H */
1342 +++ b/drivers/dma/dpaa2-qdma/dpdmai.c
1344 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
1346 + * Redistribution and use in source and binary forms, with or without
1347 + * modification, are permitted provided that the following conditions are met:
1348 + * * Redistributions of source code must retain the above copyright
1349 + * notice, this list of conditions and the following disclaimer.
1350 + * * Redistributions in binary form must reproduce the above copyright
1351 + * notice, this list of conditions and the following disclaimer in the
1352 + * documentation and/or other materials provided with the distribution.
1353 + * * Neither the name of the above-listed copyright holders nor the
1354 + * names of any contributors may be used to endorse or promote products
1355 + * derived from this software without specific prior written permission.
1358 + * ALTERNATIVELY, this software may be distributed under the terms of the
1359 + * GNU General Public License ("GPL") as published by the Free Software
1360 + * Foundation, either version 2 of that License or (at your option) any
1363 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1364 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1365 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1366 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1367 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1368 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1369 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1370 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1371 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1372 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1373 + * POSSIBILITY OF SUCH DAMAGE.
1375 +#include <linux/types.h>
1376 +#include <linux/io.h>
1377 +#include "fsl_dpdmai.h"
1378 +#include "fsl_dpdmai_cmd.h"
1379 +#include "../../../drivers/staging/fsl-mc/include/mc-sys.h"
1380 +#include "../../../drivers/staging/fsl-mc/include/mc-cmd.h"
1382 +int dpdmai_open(struct fsl_mc_io *mc_io,
1383 + uint32_t cmd_flags,
1387 + struct mc_command cmd = { 0 };
1390 + /* prepare command */
1391 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
1394 + DPDMAI_CMD_OPEN(cmd, dpdmai_id);
1396 + /* send command to mc*/
1397 + err = mc_send_command(mc_io, &cmd);
1401 + /* retrieve response parameters */
1402 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
1407 +int dpdmai_close(struct fsl_mc_io *mc_io,
1408 + uint32_t cmd_flags,
1411 + struct mc_command cmd = { 0 };
1413 + /* prepare command */
1414 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
1415 + cmd_flags, token);
1417 + /* send command to mc*/
1418 + return mc_send_command(mc_io, &cmd);
1421 +int dpdmai_create(struct fsl_mc_io *mc_io,
1422 + uint32_t cmd_flags,
1423 + const struct dpdmai_cfg *cfg,
1426 + struct mc_command cmd = { 0 };
1429 + /* prepare command */
1430 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
1433 + DPDMAI_CMD_CREATE(cmd, cfg);
1435 + /* send command to mc*/
1436 + err = mc_send_command(mc_io, &cmd);
1440 + /* retrieve response parameters */
1441 + *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
1446 +int dpdmai_destroy(struct fsl_mc_io *mc_io,
1447 + uint32_t cmd_flags,
1450 + struct mc_command cmd = { 0 };
1452 + /* prepare command */
1453 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
1457 + /* send command to mc*/
1458 + return mc_send_command(mc_io, &cmd);
1461 +int dpdmai_enable(struct fsl_mc_io *mc_io,
1462 + uint32_t cmd_flags,
1465 + struct mc_command cmd = { 0 };
1467 + /* prepare command */
1468 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
1472 + /* send command to mc*/
1473 + return mc_send_command(mc_io, &cmd);
1476 +int dpdmai_disable(struct fsl_mc_io *mc_io,
1477 + uint32_t cmd_flags,
1480 + struct mc_command cmd = { 0 };
1482 + /* prepare command */
1483 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
1487 + /* send command to mc*/
1488 + return mc_send_command(mc_io, &cmd);
1491 +int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
1492 + uint32_t cmd_flags,
1496 + struct mc_command cmd = { 0 };
1498 + /* prepare command */
1499 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
1503 + /* send command to mc*/
1504 + err = mc_send_command(mc_io, &cmd);
1508 + /* retrieve response parameters */
1509 + DPDMAI_RSP_IS_ENABLED(cmd, *en);
1514 +int dpdmai_reset(struct fsl_mc_io *mc_io,
1515 + uint32_t cmd_flags,
1518 + struct mc_command cmd = { 0 };
1520 + /* prepare command */
1521 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
1525 + /* send command to mc*/
1526 + return mc_send_command(mc_io, &cmd);
1529 +int dpdmai_get_irq(struct fsl_mc_io *mc_io,
1530 + uint32_t cmd_flags,
1532 + uint8_t irq_index,
1534 + struct dpdmai_irq_cfg *irq_cfg)
1536 + struct mc_command cmd = { 0 };
1539 + /* prepare command */
1540 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ,
1543 + DPDMAI_CMD_GET_IRQ(cmd, irq_index);
1545 + /* send command to mc*/
1546 + err = mc_send_command(mc_io, &cmd);
1550 + /* retrieve response parameters */
1551 + DPDMAI_RSP_GET_IRQ(cmd, *type, irq_cfg);
1556 +int dpdmai_set_irq(struct fsl_mc_io *mc_io,
1557 + uint32_t cmd_flags,
1559 + uint8_t irq_index,
1560 + struct dpdmai_irq_cfg *irq_cfg)
1562 + struct mc_command cmd = { 0 };
1564 + /* prepare command */
1565 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ,
1568 + DPDMAI_CMD_SET_IRQ(cmd, irq_index, irq_cfg);
1570 + /* send command to mc*/
1571 + return mc_send_command(mc_io, &cmd);
1574 +int dpdmai_get_irq_enable(struct fsl_mc_io *mc_io,
1575 + uint32_t cmd_flags,
1577 + uint8_t irq_index,
1580 + struct mc_command cmd = { 0 };
1583 + /* prepare command */
1584 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_ENABLE,
1587 + DPDMAI_CMD_GET_IRQ_ENABLE(cmd, irq_index);
1589 + /* send command to mc*/
1590 + err = mc_send_command(mc_io, &cmd);
1594 + /* retrieve response parameters */
1595 + DPDMAI_RSP_GET_IRQ_ENABLE(cmd, *en);
1600 +int dpdmai_set_irq_enable(struct fsl_mc_io *mc_io,
1601 + uint32_t cmd_flags,
1603 + uint8_t irq_index,
1606 + struct mc_command cmd = { 0 };
1608 + /* prepare command */
1609 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ_ENABLE,
1612 + DPDMAI_CMD_SET_IRQ_ENABLE(cmd, irq_index, en);
1614 + /* send command to mc*/
1615 + return mc_send_command(mc_io, &cmd);
1618 +int dpdmai_get_irq_mask(struct fsl_mc_io *mc_io,
1619 + uint32_t cmd_flags,
1621 + uint8_t irq_index,
1624 + struct mc_command cmd = { 0 };
1627 + /* prepare command */
1628 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_MASK,
1631 + DPDMAI_CMD_GET_IRQ_MASK(cmd, irq_index);
1633 + /* send command to mc*/
1634 + err = mc_send_command(mc_io, &cmd);
1638 + /* retrieve response parameters */
1639 + DPDMAI_RSP_GET_IRQ_MASK(cmd, *mask);
1644 +int dpdmai_set_irq_mask(struct fsl_mc_io *mc_io,
1645 + uint32_t cmd_flags,
1647 + uint8_t irq_index,
1650 + struct mc_command cmd = { 0 };
1652 + /* prepare command */
1653 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_IRQ_MASK,
1656 + DPDMAI_CMD_SET_IRQ_MASK(cmd, irq_index, mask);
1658 + /* send command to mc*/
1659 + return mc_send_command(mc_io, &cmd);
1662 +int dpdmai_get_irq_status(struct fsl_mc_io *mc_io,
1663 + uint32_t cmd_flags,
1665 + uint8_t irq_index,
1668 + struct mc_command cmd = { 0 };
1671 + /* prepare command */
1672 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_IRQ_STATUS,
1675 + DPDMAI_CMD_GET_IRQ_STATUS(cmd, irq_index, *status);
1677 + /* send command to mc*/
1678 + err = mc_send_command(mc_io, &cmd);
1682 + /* retrieve response parameters */
1683 + DPDMAI_RSP_GET_IRQ_STATUS(cmd, *status);
1688 +int dpdmai_clear_irq_status(struct fsl_mc_io *mc_io,
1689 + uint32_t cmd_flags,
1691 + uint8_t irq_index,
1694 + struct mc_command cmd = { 0 };
1696 + /* prepare command */
1697 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLEAR_IRQ_STATUS,
1700 + DPDMAI_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status);
1702 + /* send command to mc*/
1703 + return mc_send_command(mc_io, &cmd);
1706 +int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
1707 + uint32_t cmd_flags,
1709 + struct dpdmai_attr *attr)
1711 + struct mc_command cmd = { 0 };
1714 + /* prepare command */
1715 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
1719 + /* send command to mc*/
1720 + err = mc_send_command(mc_io, &cmd);
1724 + /* retrieve response parameters */
1725 + DPDMAI_RSP_GET_ATTR(cmd, attr);
1730 +int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
1731 + uint32_t cmd_flags,
1734 + const struct dpdmai_rx_queue_cfg *cfg)
1736 + struct mc_command cmd = { 0 };
1738 + /* prepare command */
1739 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
1742 + DPDMAI_CMD_SET_RX_QUEUE(cmd, priority, cfg);
1744 + /* send command to mc*/
1745 + return mc_send_command(mc_io, &cmd);
1748 +int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
1749 + uint32_t cmd_flags,
1751 + uint8_t priority, struct dpdmai_rx_queue_attr *attr)
1753 + struct mc_command cmd = { 0 };
1756 + /* prepare command */
1757 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
1760 + DPDMAI_CMD_GET_RX_QUEUE(cmd, priority);
1762 + /* send command to mc*/
1763 + err = mc_send_command(mc_io, &cmd);
1767 + /* retrieve response parameters */
1768 + DPDMAI_RSP_GET_RX_QUEUE(cmd, attr);
1773 +int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
1774 + uint32_t cmd_flags,
1777 + struct dpdmai_tx_queue_attr *attr)
1779 + struct mc_command cmd = { 0 };
1782 + /* prepare command */
1783 + cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
1786 + DPDMAI_CMD_GET_TX_QUEUE(cmd, priority);
1788 + /* send command to mc*/
1789 + err = mc_send_command(mc_io, &cmd);
1793 + /* retrieve response parameters */
1794 + DPDMAI_RSP_GET_TX_QUEUE(cmd, attr);
1799 +++ b/drivers/dma/dpaa2-qdma/fsl_dpdmai.h
1801 +/* Copyright 2013-2015 Freescale Semiconductor Inc.
1803 + * Redistribution and use in source and binary forms, with or without
1804 + * modification, are permitted provided that the following conditions are met:
1805 + * * Redistributions of source code must retain the above copyright
1806 + * notice, this list of conditions and the following disclaimer.
1807 + * * Redistributions in binary form must reproduce the above copyright
1808 + * notice, this list of conditions and the following disclaimer in the
1809 + * documentation and/or other materials provided with the distribution.
1810 + * * Neither the name of the above-listed copyright holders nor the
1811 + * names of any contributors may be used to endorse or promote products
1812 + * derived from this software without specific prior written permission.
1815 + * ALTERNATIVELY, this software may be distributed under the terms of the
1816 + * GNU General Public License ("GPL") as published by the Free Software
1817 + * Foundation, either version 2 of that License or (at your option) any
1820 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1821 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1822 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1823 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
1824 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1825 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1826 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1827 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1828 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1829 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1830 + * POSSIBILITY OF SUCH DAMAGE.
1832 +#ifndef __FSL_DPDMAI_H
1833 +#define __FSL_DPDMAI_H
1837 +/* Data Path DMA Interface API
1838 + * Contains initialization APIs and runtime control APIs for DPDMAI
1841 +/* General DPDMAI macros */
1844 + * Maximum number of Tx/Rx priorities per DPDMAI object
1846 +#define DPDMAI_PRIO_NUM 2
1849 + * All queues considered; see dpdmai_set_rx_queue()
1851 +#define DPDMAI_ALL_QUEUES (uint8_t)(-1)
1854 + * dpdmai_open() - Open a control session for the specified object
1855 + * @mc_io: Pointer to MC portal's I/O object
1856 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1857 + * @dpdmai_id: DPDMAI unique ID
1858 + * @token: Returned token; use in subsequent API calls
1860 + * This function can be used to open a control session for an
1861 + * already created object; an object may have been declared in
1862 + * the DPL or by calling the dpdmai_create() function.
1863 + * This function returns a unique authentication token,
1864 + * associated with the specific object ID and the specific MC
1865 + * portal; this token must be used in all subsequent commands for
1866 + * this specific object.
1868 + * Return: '0' on Success; Error code otherwise.
1870 +int dpdmai_open(struct fsl_mc_io *mc_io,
1871 + uint32_t cmd_flags,
1876 + * dpdmai_close() - Close the control session of the object
1877 + * @mc_io: Pointer to MC portal's I/O object
1878 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1879 + * @token: Token of DPDMAI object
1881 + * After this function is called, no further operations are
1882 + * allowed on the object without opening a new control session.
1884 + * Return: '0' on Success; Error code otherwise.
1886 +int dpdmai_close(struct fsl_mc_io *mc_io,
1887 + uint32_t cmd_flags,
1891 + * struct dpdmai_cfg - Structure representing DPDMAI configuration
1892 + * @priorities: Priorities for the DMA hardware processing; valid priorities are
1893 + * configured with values 1-8; the entry following last valid entry
1894 + * should be configured with 0
1896 +struct dpdmai_cfg {
1897 + uint8_t priorities[DPDMAI_PRIO_NUM];
1901 + * dpdmai_create() - Create the DPDMAI object
1902 + * @mc_io: Pointer to MC portal's I/O object
1903 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1904 + * @cfg: Configuration structure
1905 + * @token: Returned token; use in subsequent API calls
1907 + * Create the DPDMAI object, allocate required resources and
1908 + * perform required initialization.
1910 + * The object can be created either by declaring it in the
1911 + * DPL file, or by calling this function.
1913 + * This function returns a unique authentication token,
1914 + * associated with the specific object ID and the specific MC
1915 + * portal; this token must be used in all subsequent calls to
1916 + * this specific object. For objects that are created using the
1917 + * DPL file, call dpdmai_open() function to get an authentication
1920 + * Return: '0' on Success; Error code otherwise.
1922 +int dpdmai_create(struct fsl_mc_io *mc_io,
1923 + uint32_t cmd_flags,
1924 + const struct dpdmai_cfg *cfg,
1928 + * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
1929 + * @mc_io: Pointer to MC portal's I/O object
1930 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1931 + * @token: Token of DPDMAI object
1933 + * Return: '0' on Success; error code otherwise.
1935 +int dpdmai_destroy(struct fsl_mc_io *mc_io,
1936 + uint32_t cmd_flags,
1940 + * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
1941 + * @mc_io: Pointer to MC portal's I/O object
1942 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1943 + * @token: Token of DPDMAI object
1945 + * Return: '0' on Success; Error code otherwise.
1947 +int dpdmai_enable(struct fsl_mc_io *mc_io,
1948 + uint32_t cmd_flags,
1952 + * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
1953 + * @mc_io: Pointer to MC portal's I/O object
1954 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1955 + * @token: Token of DPDMAI object
1957 + * Return: '0' on Success; Error code otherwise.
1959 +int dpdmai_disable(struct fsl_mc_io *mc_io,
1960 + uint32_t cmd_flags,
1964 + * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
1965 + * @mc_io: Pointer to MC portal's I/O object
1966 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1967 + * @token: Token of DPDMAI object
1968 + * @en: Returns '1' if object is enabled; '0' otherwise
1970 + * Return: '0' on Success; Error code otherwise.
1972 +int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
1973 + uint32_t cmd_flags,
1978 + * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
1979 + * @mc_io: Pointer to MC portal's I/O object
1980 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1981 + * @token: Token of DPDMAI object
1983 + * Return: '0' on Success; Error code otherwise.
1985 +int dpdmai_reset(struct fsl_mc_io *mc_io,
1986 + uint32_t cmd_flags,
1990 + * struct dpdmai_irq_cfg - IRQ configuration
1991 + * @addr: Address that must be written to signal a message-based interrupt
1992 + * @val: Value to write into irq_addr address
1993 + * @irq_num: A user defined number associated with this IRQ
1995 +struct dpdmai_irq_cfg {
2002 + * dpdmai_set_irq() - Set IRQ information for the DPDMAI to trigger an interrupt.
2003 + * @mc_io: Pointer to MC portal's I/O object
2004 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2005 + * @token: Token of DPDMAI object
2006 + * @irq_index: Identifies the interrupt index to configure
2007 + * @irq_cfg: IRQ configuration
2009 + * Return: '0' on Success; Error code otherwise.
2011 +int dpdmai_set_irq(struct fsl_mc_io *mc_io,
2012 + uint32_t cmd_flags,
2014 + uint8_t irq_index,
2015 + struct dpdmai_irq_cfg *irq_cfg);
2018 + * dpdmai_get_irq() - Get IRQ information from the DPDMAI
2020 + * @mc_io: Pointer to MC portal's I/O object
2021 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2022 + * @token: Token of DPDMAI object
2023 + * @irq_index: The interrupt index to configure
2024 + * @type: Interrupt type: 0 represents message interrupt
2025 + * type (both irq_addr and irq_val are valid)
2026 + * @irq_cfg: IRQ attributes
2028 + * Return: '0' on Success; Error code otherwise.
2030 +int dpdmai_get_irq(struct fsl_mc_io *mc_io,
2031 + uint32_t cmd_flags,
2033 + uint8_t irq_index,
2035 + struct dpdmai_irq_cfg *irq_cfg);
2038 + * dpdmai_set_irq_enable() - Set overall interrupt state.
2039 + * @mc_io: Pointer to MC portal's I/O object
2040 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2041 + * @token: Token of DPDMAI object
2042 + * @irq_index: The interrupt index to configure
2043 + * @en: Interrupt state - enable = 1, disable = 0
2045 + * Allows GPP software to control when interrupts are generated.
2046 + * Each interrupt can have up to 32 causes. The enable/disable control's the
2047 + * overall interrupt state. if the interrupt is disabled no causes will cause
2050 + * Return: '0' on Success; Error code otherwise.
2052 +int dpdmai_set_irq_enable(struct fsl_mc_io *mc_io,
2053 + uint32_t cmd_flags,
2055 + uint8_t irq_index,
2059 + * dpdmai_get_irq_enable() - Get overall interrupt state
2060 + * @mc_io: Pointer to MC portal's I/O object
2061 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2062 + * @token: Token of DPDMAI object
2063 + * @irq_index: The interrupt index to configure
2064 + * @en: Returned Interrupt state - enable = 1, disable = 0
2066 + * Return: '0' on Success; Error code otherwise.
2068 +int dpdmai_get_irq_enable(struct fsl_mc_io *mc_io,
2069 + uint32_t cmd_flags,
2071 + uint8_t irq_index,
2075 + * dpdmai_set_irq_mask() - Set interrupt mask.
2076 + * @mc_io: Pointer to MC portal's I/O object
2077 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2078 + * @token: Token of DPDMAI object
2079 + * @irq_index: The interrupt index to configure
2080 + * @mask: event mask to trigger interrupt;
2082 + * 0 = ignore event
2083 + * 1 = consider event for asserting IRQ
2085 + * Every interrupt can have up to 32 causes and the interrupt model supports
2086 + * masking/unmasking each cause independently
2088 + * Return: '0' on Success; Error code otherwise.
2090 +int dpdmai_set_irq_mask(struct fsl_mc_io *mc_io,
2091 + uint32_t cmd_flags,
2093 + uint8_t irq_index,
2097 + * dpdmai_get_irq_mask() - Get interrupt mask.
2098 + * @mc_io: Pointer to MC portal's I/O object
2099 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2100 + * @token: Token of DPDMAI object
2101 + * @irq_index: The interrupt index to configure
2102 + * @mask: Returned event mask to trigger interrupt
2104 + * Every interrupt can have up to 32 causes and the interrupt model supports
2105 + * masking/unmasking each cause independently
2107 + * Return: '0' on Success; Error code otherwise.
2109 +int dpdmai_get_irq_mask(struct fsl_mc_io *mc_io,
2110 + uint32_t cmd_flags,
2112 + uint8_t irq_index,
2116 + * dpdmai_get_irq_status() - Get the current status of any pending interrupts
2117 + * @mc_io: Pointer to MC portal's I/O object
2118 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2119 + * @token: Token of DPDMAI object
2120 + * @irq_index: The interrupt index to configure
2121 + * @status: Returned interrupts status - one bit per cause:
2122 + * 0 = no interrupt pending
2123 + * 1 = interrupt pending
2125 + * Return: '0' on Success; Error code otherwise.
2127 +int dpdmai_get_irq_status(struct fsl_mc_io *mc_io,
2128 + uint32_t cmd_flags,
2130 + uint8_t irq_index,
2131 + uint32_t *status);
2134 + * dpdmai_clear_irq_status() - Clear a pending interrupt's status
2135 + * @mc_io: Pointer to MC portal's I/O object
2136 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2137 + * @token: Token of DPDMAI object
2138 + * @irq_index: The interrupt index to configure
2139 + * @status: bits to clear (W1C) - one bit per cause:
2140 + * 0 = don't change
2141 + * 1 = clear status bit
2143 + * Return: '0' on Success; Error code otherwise.
2145 +int dpdmai_clear_irq_status(struct fsl_mc_io *mc_io,
2146 + uint32_t cmd_flags,
2148 + uint8_t irq_index,
2152 + * struct dpdmai_attr - Structure representing DPDMAI attributes
2153 + * @id: DPDMAI object ID
2154 + * @version: DPDMAI version
2155 + * @num_of_priorities: number of priorities
2157 +struct dpdmai_attr {
2160 + * struct version - DPDMAI version
2161 + * @major: DPDMAI major version
2162 + * @minor: DPDMAI minor version
2168 + uint8_t num_of_priorities;
2172 + * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
2173 + * @mc_io: Pointer to MC portal's I/O object
2174 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2175 + * @token: Token of DPDMAI object
2176 + * @attr: Returned object's attributes
2178 + * Return: '0' on Success; Error code otherwise.
2180 +int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
2181 + uint32_t cmd_flags,
2183 + struct dpdmai_attr *attr);
2186 + * enum dpdmai_dest - DPDMAI destination types
2187 + * @DPDMAI_DEST_NONE: Unassigned destination; The queue is set in parked mode
2188 + * and does not generate FQDAN notifications; user is expected to dequeue
2189 + * from the queue based on polling or other user-defined method
2190 + * @DPDMAI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
2191 + * notifications to the specified DPIO; user is expected to dequeue
2192 + * from the queue only after notification is received
2193 + * @DPDMAI_DEST_DPCON: The queue is set in schedule mode and does not generate
2194 + * FQDAN notifications, but is connected to the specified DPCON object;
2195 + * user is expected to dequeue from the DPCON channel
2198 + DPDMAI_DEST_NONE = 0,
2199 + DPDMAI_DEST_DPIO = 1,
2200 + DPDMAI_DEST_DPCON = 2
2204 + * struct dpdmai_dest_cfg - Structure representing DPDMAI destination parameters
2205 + * @dest_type: Destination type
2206 + * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
2207 + * @priority: Priority selection within the DPIO or DPCON channel; valid values
2208 + * are 0-1 or 0-7, depending on the number of priorities in that
2209 + * channel; not relevant for 'DPDMAI_DEST_NONE' option
2211 +struct dpdmai_dest_cfg {
2212 + enum dpdmai_dest dest_type;
2217 +/* DPDMAI queue modification options */
2220 + * Select to modify the user's context associated with the queue
2222 +#define DPDMAI_QUEUE_OPT_USER_CTX 0x00000001
2225 + * Select to modify the queue's destination
2227 +#define DPDMAI_QUEUE_OPT_DEST 0x00000002
2230 + * struct dpdmai_rx_queue_cfg - DPDMAI RX queue configuration
2231 + * @options: Flags representing the suggested modifications to the queue;
2232 + * Use any combination of 'DPDMAI_QUEUE_OPT_<X>' flags
2233 + * @user_ctx: User context value provided in the frame descriptor of each
2235 + * valid only if 'DPDMAI_QUEUE_OPT_USER_CTX' is contained in 'options'
2236 + * @dest_cfg: Queue destination parameters;
2237 + * valid only if 'DPDMAI_QUEUE_OPT_DEST' is contained in 'options'
2239 +struct dpdmai_rx_queue_cfg {
2241 + uint64_t user_ctx;
2242 + struct dpdmai_dest_cfg dest_cfg;
2247 + * dpdmai_set_rx_queue() - Set Rx queue configuration
2248 + * @mc_io: Pointer to MC portal's I/O object
2249 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2250 + * @token: Token of DPDMAI object
2251 + * @priority: Select the queue relative to number of
2252 + * priorities configured at DPDMAI creation; use
2253 + * DPDMAI_ALL_QUEUES to configure all Rx queues
2255 + * @cfg: Rx queue configuration
2257 + * Return: '0' on Success; Error code otherwise.
2259 +int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
2260 + uint32_t cmd_flags,
2263 + const struct dpdmai_rx_queue_cfg *cfg);
2266 + * struct dpdmai_rx_queue_attr - Structure representing attributes of Rx queues
2267 + * @user_ctx: User context value provided in the frame descriptor of each
2269 + * @dest_cfg: Queue destination configuration
2270 + * @fqid: Virtual FQID value to be used for dequeue operations
2272 +struct dpdmai_rx_queue_attr {
2273 + uint64_t user_ctx;
2274 + struct dpdmai_dest_cfg dest_cfg;
2279 + * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
2280 + * @mc_io: Pointer to MC portal's I/O object
2281 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2282 + * @token: Token of DPDMAI object
2283 + * @priority: Select the queue relative to number of
2284 + * priorities configured at DPDMAI creation
2285 + * @attr: Returned Rx queue attributes
2287 + * Return: '0' on Success; Error code otherwise.
2289 +int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
2290 + uint32_t cmd_flags,
2293 + struct dpdmai_rx_queue_attr *attr);
2296 + * struct dpdmai_tx_queue_attr - Structure representing attributes of Tx queues
2297 + * @fqid: Virtual FQID to be used for sending frames to DMA hardware
2300 +struct dpdmai_tx_queue_attr {
2305 + * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
2306 + * @mc_io: Pointer to MC portal's I/O object
2307 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2308 + * @token: Token of DPDMAI object
2309 + * @priority: Select the queue relative to number of
2310 + * priorities configured at DPDMAI creation
2311 + * @attr: Returned Tx queue attributes
2313 + * Return: '0' on Success; Error code otherwise.
2315 +int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
2316 + uint32_t cmd_flags,
2319 + struct dpdmai_tx_queue_attr *attr);
2321 +#endif /* __FSL_DPDMAI_H */
2323 +++ b/drivers/dma/dpaa2-qdma/fsl_dpdmai_cmd.h
2325 +/* Copyright 2013-2016 Freescale Semiconductor Inc.
2327 + * Redistribution and use in source and binary forms, with or without
2328 + * modification, are permitted provided that the following conditions are met:
2329 + * * Redistributions of source code must retain the above copyright
2330 + * notice, this list of conditions and the following disclaimer.
2331 + * * Redistributions in binary form must reproduce the above copyright
2332 + * notice, this list of conditions and the following disclaimer in the
2333 + * documentation and/or other materials provided with the distribution.
2334 + * * Neither the name of the above-listed copyright holders nor the
2335 + * names of any contributors may be used to endorse or promote products
2336 + * derived from this software without specific prior written permission.
2339 + * ALTERNATIVELY, this software may be distributed under the terms of the
2340 + * GNU General Public License ("GPL") as published by the Free Software
2341 + * Foundation, either version 2 of that License or (at your option) any
2344 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2345 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2346 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2347 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
2348 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2349 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2350 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2351 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2352 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2353 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2354 + * POSSIBILITY OF SUCH DAMAGE.
2356 +#ifndef _FSL_DPDMAI_CMD_H
2357 +#define _FSL_DPDMAI_CMD_H
2359 +/* DPDMAI Version */
2360 +#define DPDMAI_VER_MAJOR 2
2361 +#define DPDMAI_VER_MINOR 2
2363 +#define DPDMAI_CMD_BASE_VERSION 0
2364 +#define DPDMAI_CMD_ID_OFFSET 4
2367 +#define DPDMAI_CMDID_CLOSE ((0x800 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2368 +#define DPDMAI_CMDID_OPEN ((0x80E << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2369 +#define DPDMAI_CMDID_CREATE ((0x90E << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2370 +#define DPDMAI_CMDID_DESTROY ((0x900 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2372 +#define DPDMAI_CMDID_ENABLE ((0x002 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2373 +#define DPDMAI_CMDID_DISABLE ((0x003 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2374 +#define DPDMAI_CMDID_GET_ATTR ((0x004 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2375 +#define DPDMAI_CMDID_RESET ((0x005 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2376 +#define DPDMAI_CMDID_IS_ENABLED ((0x006 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2378 +#define DPDMAI_CMDID_SET_IRQ ((0x010 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2379 +#define DPDMAI_CMDID_GET_IRQ ((0x011 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2380 +#define DPDMAI_CMDID_SET_IRQ_ENABLE ((0x012 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2381 +#define DPDMAI_CMDID_GET_IRQ_ENABLE ((0x013 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2382 +#define DPDMAI_CMDID_SET_IRQ_MASK ((0x014 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2383 +#define DPDMAI_CMDID_GET_IRQ_MASK ((0x015 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2384 +#define DPDMAI_CMDID_GET_IRQ_STATUS ((0x016 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2385 +#define DPDMAI_CMDID_CLEAR_IRQ_STATUS ((0x017 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2387 +#define DPDMAI_CMDID_SET_RX_QUEUE ((0x1A0 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2388 +#define DPDMAI_CMDID_GET_RX_QUEUE ((0x1A1 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2389 +#define DPDMAI_CMDID_GET_TX_QUEUE ((0x1A2 << DPDMAI_CMD_ID_OFFSET) | DPDMAI_CMD_BASE_VERSION)
2392 +#define MC_CMD_HDR_TOKEN_O 32 /* Token field offset */
2393 +#define MC_CMD_HDR_TOKEN_S 16 /* Token field size */
2396 +#define MAKE_UMASK64(_width) \
2397 + ((uint64_t)((_width) < 64 ? ((uint64_t)1 << (_width)) - 1 : \
2400 +static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val)
2402 + return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset);
2405 +static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width)
2407 + return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width));
2410 +#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
2411 + ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
2413 +#define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \
2414 + (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width)))
2416 +#define MC_CMD_HDR_READ_TOKEN(_hdr) \
2417 + ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
2419 +/* cmd, param, offset, width, type, arg_name */
2420 +#define DPDMAI_CMD_OPEN(cmd, dpdmai_id) \
2421 + MC_CMD_OP(cmd, 0, 0, 32, int, dpdmai_id)
2423 +/* cmd, param, offset, width, type, arg_name */
2424 +#define DPDMAI_CMD_CREATE(cmd, cfg) \
2426 + MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->priorities[0]);\
2427 + MC_CMD_OP(cmd, 0, 16, 8, uint8_t, cfg->priorities[1]);\
2430 +/* cmd, param, offset, width, type, arg_name */
2431 +#define DPDMAI_RSP_IS_ENABLED(cmd, en) \
2432 + MC_RSP_OP(cmd, 0, 0, 1, int, en)
2434 +/* cmd, param, offset, width, type, arg_name */
2435 +#define DPDMAI_CMD_SET_IRQ(cmd, irq_index, irq_cfg) \
2437 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, irq_index);\
2438 + MC_CMD_OP(cmd, 0, 32, 32, uint32_t, irq_cfg->val);\
2439 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
2440 + MC_CMD_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
2443 +/* cmd, param, offset, width, type, arg_name */
2444 +#define DPDMAI_CMD_GET_IRQ(cmd, irq_index) \
2445 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
2447 +/* cmd, param, offset, width, type, arg_name */
2448 +#define DPDMAI_RSP_GET_IRQ(cmd, type, irq_cfg) \
2450 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, irq_cfg->val); \
2451 + MC_RSP_OP(cmd, 1, 0, 64, uint64_t, irq_cfg->addr);\
2452 + MC_RSP_OP(cmd, 2, 0, 32, int, irq_cfg->irq_num); \
2453 + MC_RSP_OP(cmd, 2, 32, 32, int, type); \
2456 +/* cmd, param, offset, width, type, arg_name */
2457 +#define DPDMAI_CMD_SET_IRQ_ENABLE(cmd, irq_index, enable_state) \
2459 + MC_CMD_OP(cmd, 0, 0, 8, uint8_t, enable_state); \
2460 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
2463 +/* cmd, param, offset, width, type, arg_name */
2464 +#define DPDMAI_CMD_GET_IRQ_ENABLE(cmd, irq_index) \
2465 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
2467 +/* cmd, param, offset, width, type, arg_name */
2468 +#define DPDMAI_RSP_GET_IRQ_ENABLE(cmd, enable_state) \
2469 + MC_RSP_OP(cmd, 0, 0, 8, uint8_t, enable_state)
2471 +/* cmd, param, offset, width, type, arg_name */
2472 +#define DPDMAI_CMD_SET_IRQ_MASK(cmd, irq_index, mask) \
2474 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, mask); \
2475 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
2478 +/* cmd, param, offset, width, type, arg_name */
2479 +#define DPDMAI_CMD_GET_IRQ_MASK(cmd, irq_index) \
2480 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index)
2482 +/* cmd, param, offset, width, type, arg_name */
2483 +#define DPDMAI_RSP_GET_IRQ_MASK(cmd, mask) \
2484 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, mask)
2486 +/* cmd, param, offset, width, type, arg_name */
2487 +#define DPDMAI_CMD_GET_IRQ_STATUS(cmd, irq_index, status) \
2489 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status);\
2490 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index);\
2493 +/* cmd, param, offset, width, type, arg_name */
2494 +#define DPDMAI_RSP_GET_IRQ_STATUS(cmd, status) \
2495 + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, status)
2497 +/* cmd, param, offset, width, type, arg_name */
2498 +#define DPDMAI_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status) \
2500 + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, status); \
2501 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, irq_index); \
2504 +/* cmd, param, offset, width, type, arg_name */
2505 +#define DPDMAI_RSP_GET_ATTR(cmd, attr) \
2507 + MC_RSP_OP(cmd, 0, 0, 32, int, attr->id); \
2508 + MC_RSP_OP(cmd, 0, 32, 8, uint8_t, attr->num_of_priorities); \
2509 + MC_RSP_OP(cmd, 1, 0, 16, uint16_t, attr->version.major);\
2510 + MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
2513 +/* cmd, param, offset, width, type, arg_name */
2514 +#define DPDMAI_CMD_SET_RX_QUEUE(cmd, priority, cfg) \
2516 + MC_CMD_OP(cmd, 0, 0, 32, int, cfg->dest_cfg.dest_id); \
2517 + MC_CMD_OP(cmd, 0, 32, 8, uint8_t, cfg->dest_cfg.priority); \
2518 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority); \
2519 + MC_CMD_OP(cmd, 0, 48, 4, enum dpdmai_dest, cfg->dest_cfg.dest_type); \
2520 + MC_CMD_OP(cmd, 1, 0, 64, uint64_t, cfg->user_ctx); \
2521 + MC_CMD_OP(cmd, 2, 0, 32, uint32_t, cfg->options);\
2524 +/* cmd, param, offset, width, type, arg_name */
2525 +#define DPDMAI_CMD_GET_RX_QUEUE(cmd, priority) \
2526 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority)
2528 +/* cmd, param, offset, width, type, arg_name */
2529 +#define DPDMAI_RSP_GET_RX_QUEUE(cmd, attr) \
2531 + MC_RSP_OP(cmd, 0, 0, 32, int, attr->dest_cfg.dest_id);\
2532 + MC_RSP_OP(cmd, 0, 32, 8, uint8_t, attr->dest_cfg.priority);\
2533 + MC_RSP_OP(cmd, 0, 48, 4, enum dpdmai_dest, attr->dest_cfg.dest_type);\
2534 + MC_RSP_OP(cmd, 1, 0, 64, uint64_t, attr->user_ctx);\
2535 + MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->fqid);\
2538 +/* cmd, param, offset, width, type, arg_name */
2539 +#define DPDMAI_CMD_GET_TX_QUEUE(cmd, priority) \
2540 + MC_CMD_OP(cmd, 0, 40, 8, uint8_t, priority)
2542 +/* cmd, param, offset, width, type, arg_name */
2543 +#define DPDMAI_RSP_GET_TX_QUEUE(cmd, attr) \
2544 + MC_RSP_OP(cmd, 1, 0, 32, uint32_t, attr->fqid)
2546 +#endif /* _FSL_DPDMAI_CMD_H */
2548 +++ b/drivers/dma/fsl-qdma.c
2551 + * drivers/dma/fsl-qdma.c
2553 + * Copyright 2014-2015 Freescale Semiconductor, Inc.
2555 + * Driver for the Freescale qDMA engine with software command queue mode.
2556 + * Channel virtualization is supported through enqueuing of DMA jobs to,
2557 + * or dequeuing DMA jobs from, different work queues.
2558 + * This module can be found on Freescale LS SoCs.
2560 + * This program is free software; you can redistribute it and/or modify it
2561 + * under the terms of the GNU General Public License as published by the
2562 + * Free Software Foundation; either version 2 of the License, or (at your
2563 + * option) any later version.
2566 +#include <asm/cacheflush.h>
2567 +#include <linux/clk.h>
2568 +#include <linux/delay.h>
2569 +#include <linux/dma-mapping.h>
2570 +#include <linux/dmapool.h>
2571 +#include <linux/init.h>
2572 +#include <linux/interrupt.h>
2573 +#include <linux/module.h>
2574 +#include <linux/of.h>
2575 +#include <linux/of_address.h>
2576 +#include <linux/of_device.h>
2577 +#include <linux/of_dma.h>
2578 +#include <linux/of_irq.h>
2579 +#include <linux/slab.h>
2580 +#include <linux/spinlock.h>
2582 +#include "virt-dma.h"
2584 +#define FSL_QDMA_DMR 0x0
2585 +#define FSL_QDMA_DSR 0x4
2586 +#define FSL_QDMA_DEIER 0xe00
2587 +#define FSL_QDMA_DEDR 0xe04
2588 +#define FSL_QDMA_DECFDW0R 0xe10
2589 +#define FSL_QDMA_DECFDW1R 0xe14
2590 +#define FSL_QDMA_DECFDW2R 0xe18
2591 +#define FSL_QDMA_DECFDW3R 0xe1c
2592 +#define FSL_QDMA_DECFQIDR 0xe30
2593 +#define FSL_QDMA_DECBR 0xe34
2595 +#define FSL_QDMA_BCQMR(x) (0xc0 + 0x100 * (x))
2596 +#define FSL_QDMA_BCQSR(x) (0xc4 + 0x100 * (x))
2597 +#define FSL_QDMA_BCQEDPA_SADDR(x) (0xc8 + 0x100 * (x))
2598 +#define FSL_QDMA_BCQDPA_SADDR(x) (0xcc + 0x100 * (x))
2599 +#define FSL_QDMA_BCQEEPA_SADDR(x) (0xd0 + 0x100 * (x))
2600 +#define FSL_QDMA_BCQEPA_SADDR(x) (0xd4 + 0x100 * (x))
2601 +#define FSL_QDMA_BCQIER(x) (0xe0 + 0x100 * (x))
2602 +#define FSL_QDMA_BCQIDR(x) (0xe4 + 0x100 * (x))
2604 +#define FSL_QDMA_SQDPAR 0x80c
2605 +#define FSL_QDMA_SQEPAR 0x814
2606 +#define FSL_QDMA_BSQMR 0x800
2607 +#define FSL_QDMA_BSQSR 0x804
2608 +#define FSL_QDMA_BSQICR 0x828
2609 +#define FSL_QDMA_CQMR 0xa00
2610 +#define FSL_QDMA_CQDSCR1 0xa08
2611 +#define FSL_QDMA_CQDSCR2 0xa0c
2612 +#define FSL_QDMA_CQIER 0xa10
2613 +#define FSL_QDMA_CQEDR 0xa14
2614 +#define FSL_QDMA_SQCCMR 0xa20
2616 +#define FSL_QDMA_SQICR_ICEN
2618 +#define FSL_QDMA_CQIDR_CQT 0xff000000
2619 +#define FSL_QDMA_CQIDR_SQPE 0x800000
2620 +#define FSL_QDMA_CQIDR_SQT 0x8000
2622 +#define FSL_QDMA_BCQIER_CQTIE 0x8000
2623 +#define FSL_QDMA_BCQIER_CQPEIE 0x800000
2624 +#define FSL_QDMA_BSQICR_ICEN 0x80000000
2625 +#define FSL_QDMA_BSQICR_ICST(x) ((x) << 16)
2626 +#define FSL_QDMA_CQIER_MEIE 0x80000000
2627 +#define FSL_QDMA_CQIER_TEIE 0x1
2628 +#define FSL_QDMA_SQCCMR_ENTER_WM 0x200000
2630 +#define FSL_QDMA_QUEUE_MAX 8
2632 +#define FSL_QDMA_BCQMR_EN 0x80000000
2633 +#define FSL_QDMA_BCQMR_EI 0x40000000
2634 +#define FSL_QDMA_BCQMR_CD_THLD(x) ((x) << 20)
2635 +#define FSL_QDMA_BCQMR_CQ_SIZE(x) ((x) << 16)
2637 +#define FSL_QDMA_BCQSR_QF 0x10000
2638 +#define FSL_QDMA_BCQSR_XOFF 0x1
2640 +#define FSL_QDMA_BSQMR_EN 0x80000000
2641 +#define FSL_QDMA_BSQMR_DI 0x40000000
2642 +#define FSL_QDMA_BSQMR_CQ_SIZE(x) ((x) << 16)
2644 +#define FSL_QDMA_BSQSR_QE 0x20000
2646 +#define FSL_QDMA_DMR_DQD 0x40000000
2647 +#define FSL_QDMA_DSR_DB 0x80000000
2649 +#define FSL_QDMA_BASE_BUFFER_SIZE 96
2650 +#define FSL_QDMA_EXPECT_SG_ENTRY_NUM 16
2651 +#define FSL_QDMA_CIRCULAR_DESC_SIZE_MIN 64
2652 +#define FSL_QDMA_CIRCULAR_DESC_SIZE_MAX 16384
2653 +#define FSL_QDMA_QUEUE_NUM_MAX 8
2655 +#define FSL_QDMA_CMD_RWTTYPE 0x4
2656 +#define FSL_QDMA_CMD_LWC 0x2
2658 +#define FSL_QDMA_CMD_RWTTYPE_OFFSET 28
2659 +#define FSL_QDMA_CMD_NS_OFFSET 27
2660 +#define FSL_QDMA_CMD_DQOS_OFFSET 24
2661 +#define FSL_QDMA_CMD_WTHROTL_OFFSET 20
2662 +#define FSL_QDMA_CMD_DSEN_OFFSET 19
2663 +#define FSL_QDMA_CMD_LWC_OFFSET 16
2665 +#define FSL_QDMA_E_SG_TABLE 1
2666 +#define FSL_QDMA_E_DATA_BUFFER 0
2667 +#define FSL_QDMA_F_LAST_ENTRY 1
2669 +u64 pre_addr, pre_queue;
2671 +struct fsl_qdma_ccdf {
2681 + u32 addr_lo; /* low 32-bits of 40-bit address */
2682 + u32 addr_hi:8; /* high 8-bits of 40-bit address */
2686 + u32 dd:2; /* dynamic debug */
2690 + /* More efficient address accessor */
2691 + u64 __notaddress:24;
2696 +struct fsl_qdma_csgf {
2704 + u32 addr_lo; /* low 32-bits of 40-bit address */
2705 + u32 addr_hi:8; /* high 8-bits of 40-bit address */
2710 + /* More efficient address accessor */
2711 + u64 __notaddress:24;
2716 +struct fsl_qdma_sdf {
2718 + u32 ssd:12; /* souce stride distance */
2719 + u32 sss:12; /* souce stride size */
2725 +struct fsl_qdma_ddf {
2727 + u32 dsd:12; /* Destination stride distance */
2728 + u32 dss:12; /* Destination stride size */
2734 +struct fsl_qdma_chan {
2735 + struct virt_dma_chan vchan;
2736 + struct virt_dma_desc vdesc;
2737 + enum dma_status status;
2739 + struct fsl_qdma_engine *qdma;
2740 + struct fsl_qdma_queue *queue;
2741 + struct list_head qcomp;
2744 +struct fsl_qdma_queue {
2745 + struct fsl_qdma_ccdf *virt_head;
2746 + struct fsl_qdma_ccdf *virt_tail;
2747 + struct list_head comp_used;
2748 + struct list_head comp_free;
2749 + struct dma_pool *comp_pool;
2750 + struct dma_pool *sg_pool;
2751 + spinlock_t queue_lock;
2752 + dma_addr_t bus_addr;
2755 + struct fsl_qdma_ccdf *cq;
2758 +struct fsl_qdma_sg {
2759 + dma_addr_t bus_addr;
2763 +struct fsl_qdma_comp {
2764 + dma_addr_t bus_addr;
2766 + struct fsl_qdma_chan *qchan;
2767 + struct fsl_qdma_sg *sg_block;
2768 + struct virt_dma_desc vdesc;
2769 + struct list_head list;
2774 +struct fsl_qdma_engine {
2775 + struct dma_device dma_dev;
2776 + void __iomem *ctrl_base;
2777 + void __iomem *status_base;
2778 + void __iomem *block_base;
2781 + struct mutex fsl_qdma_mutex;
2785 + struct fsl_qdma_queue *queue;
2786 + struct fsl_qdma_queue *status;
2787 + struct fsl_qdma_chan chans[];
2791 +static u32 qdma_readl(struct fsl_qdma_engine *qdma, void __iomem *addr)
2793 + if (qdma->big_endian)
2794 + return ioread32be(addr);
2796 + return ioread32(addr);
2799 +static void qdma_writel(struct fsl_qdma_engine *qdma, u32 val,
2800 + void __iomem *addr)
2802 + if (qdma->big_endian)
2803 + iowrite32be(val, addr);
2805 + iowrite32(val, addr);
2808 +static struct fsl_qdma_chan *to_fsl_qdma_chan(struct dma_chan *chan)
2810 + return container_of(chan, struct fsl_qdma_chan, vchan.chan);
2813 +static struct fsl_qdma_comp *to_fsl_qdma_comp(struct virt_dma_desc *vd)
2815 + return container_of(vd, struct fsl_qdma_comp, vdesc);
2818 +static int fsl_qdma_alloc_chan_resources(struct dma_chan *chan)
2821 + * In QDMA mode, We don't need to do anything.
2826 +static void fsl_qdma_free_chan_resources(struct dma_chan *chan)
2828 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
2829 + unsigned long flags;
2832 + spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
2833 + vchan_get_all_descriptors(&fsl_chan->vchan, &head);
2834 + spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags);
2836 + vchan_dma_desc_free_list(&fsl_chan->vchan, &head);
2839 +static void fsl_qdma_comp_fill_memcpy(struct fsl_qdma_comp *fsl_comp,
2840 + dma_addr_t dst, dma_addr_t src, u32 len)
2842 + struct fsl_qdma_ccdf *ccdf;
2843 + struct fsl_qdma_csgf *csgf_desc, *csgf_src, *csgf_dest;
2844 + struct fsl_qdma_sdf *sdf;
2845 + struct fsl_qdma_ddf *ddf;
2847 + ccdf = (struct fsl_qdma_ccdf *)fsl_comp->virt_addr;
2848 + csgf_desc = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 1;
2849 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 2;
2850 + csgf_dest = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 3;
2851 + sdf = (struct fsl_qdma_sdf *)fsl_comp->virt_addr + 4;
2852 + ddf = (struct fsl_qdma_ddf *)fsl_comp->virt_addr + 5;
2854 + memset(fsl_comp->virt_addr, 0, FSL_QDMA_BASE_BUFFER_SIZE);
2855 + /* Head Command Descriptor(Frame Descriptor) */
2856 + ccdf->addr = fsl_comp->bus_addr + 16;
2857 + ccdf->format = 1; /* Compound S/G format */
2858 + /* Status notification is enqueued to status queue. */
2860 + /* Compound Command Descriptor(Frame List Table) */
2861 + csgf_desc->addr = fsl_comp->bus_addr + 64;
2862 + /* It must be 32 as Compound S/G Descriptor */
2863 + csgf_desc->length = 32;
2864 + csgf_src->addr = src;
2865 + csgf_src->length = len;
2866 + csgf_dest->addr = dst;
2867 + csgf_dest->length = len;
2868 + /* This entry is the last entry. */
2869 + csgf_dest->f = FSL_QDMA_F_LAST_ENTRY;
2870 + /* Descriptor Buffer */
2871 + sdf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
2872 + ddf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
2873 + ddf->cmd |= FSL_QDMA_CMD_LWC << FSL_QDMA_CMD_LWC_OFFSET;
2876 +static void fsl_qdma_comp_fill_sg(
2877 + struct fsl_qdma_comp *fsl_comp,
2878 + struct scatterlist *dst_sg, unsigned int dst_nents,
2879 + struct scatterlist *src_sg, unsigned int src_nents)
2881 + struct fsl_qdma_ccdf *ccdf;
2882 + struct fsl_qdma_csgf *csgf_desc, *csgf_src, *csgf_dest, *csgf_sg;
2883 + struct fsl_qdma_sdf *sdf;
2884 + struct fsl_qdma_ddf *ddf;
2885 + struct fsl_qdma_sg *sg_block, *temp;
2886 + struct scatterlist *sg;
2887 + u64 total_src_len = 0;
2888 + u64 total_dst_len = 0;
2891 + ccdf = (struct fsl_qdma_ccdf *)fsl_comp->virt_addr;
2892 + csgf_desc = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 1;
2893 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 2;
2894 + csgf_dest = (struct fsl_qdma_csgf *)fsl_comp->virt_addr + 3;
2895 + sdf = (struct fsl_qdma_sdf *)fsl_comp->virt_addr + 4;
2896 + ddf = (struct fsl_qdma_ddf *)fsl_comp->virt_addr + 5;
2898 + memset(fsl_comp->virt_addr, 0, FSL_QDMA_BASE_BUFFER_SIZE);
2899 + /* Head Command Descriptor(Frame Descriptor) */
2900 + ccdf->addr = fsl_comp->bus_addr + 16;
2901 + ccdf->format = 1; /* Compound S/G format */
2902 + /* Status notification is enqueued to status queue. */
2905 + /* Compound Command Descriptor(Frame List Table) */
2906 + csgf_desc->addr = fsl_comp->bus_addr + 64;
2907 + /* It must be 32 as Compound S/G Descriptor */
2908 + csgf_desc->length = 32;
2910 + sg_block = fsl_comp->sg_block;
2911 + csgf_src->addr = sg_block->bus_addr;
2912 + /* This entry link to the s/g entry. */
2913 + csgf_src->e = FSL_QDMA_E_SG_TABLE;
2915 + temp = sg_block + fsl_comp->sg_block_src;
2916 + csgf_dest->addr = temp->bus_addr;
2917 + /* This entry is the last entry. */
2918 + csgf_dest->f = FSL_QDMA_F_LAST_ENTRY;
2919 + /* This entry link to the s/g entry. */
2920 + csgf_dest->e = FSL_QDMA_E_SG_TABLE;
2922 + for_each_sg(src_sg, sg, src_nents, i) {
2923 + temp = sg_block + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
2924 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
2925 + i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
2926 + csgf_sg->addr = sg_dma_address(sg);
2927 + csgf_sg->length = sg_dma_len(sg);
2928 + total_src_len += sg_dma_len(sg);
2930 + if (i == src_nents - 1)
2931 + csgf_sg->f = FSL_QDMA_F_LAST_ENTRY;
2932 + if (i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) ==
2933 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 2) {
2934 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
2935 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1;
2937 + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
2938 + csgf_sg->addr = temp->bus_addr;
2939 + csgf_sg->e = FSL_QDMA_E_SG_TABLE;
2943 + sg_block += fsl_comp->sg_block_src;
2944 + for_each_sg(dst_sg, sg, dst_nents, i) {
2945 + temp = sg_block + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
2946 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
2947 + i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1);
2948 + csgf_sg->addr = sg_dma_address(sg);
2949 + csgf_sg->length = sg_dma_len(sg);
2950 + total_dst_len += sg_dma_len(sg);
2952 + if (i == dst_nents - 1)
2953 + csgf_sg->f = FSL_QDMA_F_LAST_ENTRY;
2954 + if (i % (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) ==
2955 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 2) {
2956 + csgf_sg = (struct fsl_qdma_csgf *)temp->virt_addr +
2957 + FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1;
2959 + i / (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
2960 + csgf_sg->addr = temp->bus_addr;
2961 + csgf_sg->e = FSL_QDMA_E_SG_TABLE;
2965 + if (total_src_len != total_dst_len)
2966 + dev_err(&fsl_comp->qchan->vchan.chan.dev->device,
2967 + "The data length for src and dst isn't match.\n");
2969 + csgf_src->length = total_src_len;
2970 + csgf_dest->length = total_dst_len;
2972 + /* Descriptor Buffer */
2973 + sdf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
2974 + ddf->cmd = FSL_QDMA_CMD_RWTTYPE << FSL_QDMA_CMD_RWTTYPE_OFFSET;
2978 + * Prei-request full command descriptor for enqueue.
2980 +static int fsl_qdma_pre_request_enqueue_desc(struct fsl_qdma_queue *queue)
2982 + struct fsl_qdma_comp *comp_temp;
2985 + for (i = 0; i < queue->n_cq; i++) {
2986 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
2989 + comp_temp->virt_addr = dma_pool_alloc(queue->comp_pool,
2991 + &comp_temp->bus_addr);
2992 + if (!comp_temp->virt_addr)
2994 + list_add_tail(&comp_temp->list, &queue->comp_free);
3000 + * Request a command descriptor for enqueue.
3002 +static struct fsl_qdma_comp *fsl_qdma_request_enqueue_desc(
3003 + struct fsl_qdma_chan *fsl_chan,
3004 + unsigned int dst_nents,
3005 + unsigned int src_nents)
3007 + struct fsl_qdma_comp *comp_temp;
3008 + struct fsl_qdma_sg *sg_block;
3009 + struct fsl_qdma_queue *queue = fsl_chan->queue;
3010 + unsigned long flags;
3011 + unsigned int dst_sg_entry_block, src_sg_entry_block, sg_entry_total, i;
3013 + spin_lock_irqsave(&queue->queue_lock, flags);
3014 + if (list_empty(&queue->comp_free)) {
3015 + spin_unlock_irqrestore(&queue->queue_lock, flags);
3016 + comp_temp = kzalloc(sizeof(*comp_temp), GFP_KERNEL);
3019 + comp_temp->virt_addr = dma_pool_alloc(queue->comp_pool,
3021 + &comp_temp->bus_addr);
3022 + if (!comp_temp->virt_addr)
3025 + comp_temp = list_first_entry(&queue->comp_free,
3026 + struct fsl_qdma_comp,
3028 + list_del(&comp_temp->list);
3029 + spin_unlock_irqrestore(&queue->queue_lock, flags);
3032 + if (dst_nents != 0)
3033 + dst_sg_entry_block = dst_nents /
3034 + (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3036 + dst_sg_entry_block = 0;
3038 + if (src_nents != 0)
3039 + src_sg_entry_block = src_nents /
3040 + (FSL_QDMA_EXPECT_SG_ENTRY_NUM - 1) + 1;
3042 + src_sg_entry_block = 0;
3044 + sg_entry_total = dst_sg_entry_block + src_sg_entry_block;
3045 + if (sg_entry_total) {
3046 + sg_block = kzalloc(sizeof(*sg_block) *
3051 + comp_temp->sg_block = sg_block;
3052 + for (i = 0; i < sg_entry_total; i++) {
3053 + sg_block->virt_addr = dma_pool_alloc(queue->sg_pool,
3055 + &sg_block->bus_addr);
3056 + memset(sg_block->virt_addr, 0,
3057 + FSL_QDMA_EXPECT_SG_ENTRY_NUM * 16);
3062 + comp_temp->sg_block_src = src_sg_entry_block;
3063 + comp_temp->sg_block_dst = dst_sg_entry_block;
3064 + comp_temp->qchan = fsl_chan;
3069 +static struct fsl_qdma_queue *fsl_qdma_alloc_queue_resources(
3070 + struct platform_device *pdev,
3071 + unsigned int queue_num)
3073 + struct device_node *np = pdev->dev.of_node;
3074 + struct fsl_qdma_queue *queue_head, *queue_temp;
3076 + unsigned int queue_size[FSL_QDMA_QUEUE_MAX];
3078 + if (queue_num > FSL_QDMA_QUEUE_MAX)
3079 + queue_num = FSL_QDMA_QUEUE_MAX;
3080 + len = sizeof(*queue_head) * queue_num;
3081 + queue_head = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
3085 + ret = of_property_read_u32_array(np, "queue-sizes", queue_size,
3088 + dev_err(&pdev->dev, "Can't get queue-sizes.\n");
3092 + for (i = 0; i < queue_num; i++) {
3093 + if (queue_size[i] > FSL_QDMA_CIRCULAR_DESC_SIZE_MAX
3094 + || queue_size[i] < FSL_QDMA_CIRCULAR_DESC_SIZE_MIN) {
3095 + dev_err(&pdev->dev, "Get wrong queue-sizes.\n");
3098 + queue_temp = queue_head + i;
3099 + queue_temp->cq = dma_alloc_coherent(&pdev->dev,
3100 + sizeof(struct fsl_qdma_ccdf) *
3102 + &queue_temp->bus_addr,
3104 + if (!queue_temp->cq)
3106 + queue_temp->n_cq = queue_size[i];
3107 + queue_temp->id = i;
3108 + queue_temp->virt_head = queue_temp->cq;
3109 + queue_temp->virt_tail = queue_temp->cq;
3111 + * The dma pool for queue command buffer
3113 + queue_temp->comp_pool = dma_pool_create("comp_pool",
3115 + FSL_QDMA_BASE_BUFFER_SIZE,
3117 + if (!queue_temp->comp_pool) {
3118 + dma_free_coherent(&pdev->dev,
3119 + sizeof(struct fsl_qdma_ccdf) *
3122 + queue_temp->bus_addr);
3126 + * The dma pool for queue command buffer
3128 + queue_temp->sg_pool = dma_pool_create("sg_pool",
3130 + FSL_QDMA_EXPECT_SG_ENTRY_NUM * 16,
3132 + if (!queue_temp->sg_pool) {
3133 + dma_free_coherent(&pdev->dev,
3134 + sizeof(struct fsl_qdma_ccdf) *
3137 + queue_temp->bus_addr);
3138 + dma_pool_destroy(queue_temp->comp_pool);
3142 + * List for queue command buffer
3144 + INIT_LIST_HEAD(&queue_temp->comp_used);
3145 + INIT_LIST_HEAD(&queue_temp->comp_free);
3146 + spin_lock_init(&queue_temp->queue_lock);
3149 + return queue_head;
3152 +static struct fsl_qdma_queue *fsl_qdma_prep_status_queue(
3153 + struct platform_device *pdev)
3155 + struct device_node *np = pdev->dev.of_node;
3156 + struct fsl_qdma_queue *status_head;
3157 + unsigned int status_size;
3160 + ret = of_property_read_u32(np, "status-sizes", &status_size);
3162 + dev_err(&pdev->dev, "Can't get status-sizes.\n");
3165 + if (status_size > FSL_QDMA_CIRCULAR_DESC_SIZE_MAX
3166 + || status_size < FSL_QDMA_CIRCULAR_DESC_SIZE_MIN) {
3167 + dev_err(&pdev->dev, "Get wrong status_size.\n");
3170 + status_head = devm_kzalloc(&pdev->dev, sizeof(*status_head),
3176 + * Buffer for queue command
3178 + status_head->cq = dma_alloc_coherent(&pdev->dev,
3179 + sizeof(struct fsl_qdma_ccdf) *
3181 + &status_head->bus_addr,
3183 + if (!status_head->cq)
3185 + status_head->n_cq = status_size;
3186 + status_head->virt_head = status_head->cq;
3187 + status_head->virt_tail = status_head->cq;
3188 + status_head->comp_pool = NULL;
3190 + return status_head;
3193 +static int fsl_qdma_halt(struct fsl_qdma_engine *fsl_qdma)
3195 + void __iomem *ctrl = fsl_qdma->ctrl_base;
3196 + void __iomem *block = fsl_qdma->block_base;
3200 + /* Disable the command queue and wait for idle state. */
3201 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
3202 + reg |= FSL_QDMA_DMR_DQD;
3203 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
3204 + for (i = 0; i < FSL_QDMA_QUEUE_NUM_MAX; i++)
3205 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BCQMR(i));
3208 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DSR);
3209 + if (!(reg & FSL_QDMA_DSR_DB))
3216 + /* Disable status queue. */
3217 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BSQMR);
3220 + * Clear the command queue interrupt detect register for all queues.
3222 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
3227 +static int fsl_qdma_queue_transfer_complete(struct fsl_qdma_engine *fsl_qdma)
3229 + struct fsl_qdma_queue *fsl_queue = fsl_qdma->queue;
3230 + struct fsl_qdma_queue *fsl_status = fsl_qdma->status;
3231 + struct fsl_qdma_queue *temp_queue;
3232 + struct fsl_qdma_comp *fsl_comp;
3233 + struct fsl_qdma_ccdf *status_addr;
3234 + struct fsl_qdma_csgf *csgf_src;
3235 + void __iomem *block = fsl_qdma->block_base;
3237 + bool duplicate, duplicate_handle;
3241 + duplicate_handle = 0;
3242 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQSR);
3243 + if (reg & FSL_QDMA_BSQSR_QE)
3245 + status_addr = fsl_status->virt_head;
3246 + if (status_addr->queue == pre_queue &&
3247 + status_addr->addr == pre_addr)
3250 + i = status_addr->queue;
3251 + pre_queue = status_addr->queue;
3252 + pre_addr = status_addr->addr;
3253 + temp_queue = fsl_queue + i;
3254 + spin_lock(&temp_queue->queue_lock);
3255 + if (list_empty(&temp_queue->comp_used)) {
3257 + duplicate_handle = 1;
3259 + spin_unlock(&temp_queue->queue_lock);
3263 + fsl_comp = list_first_entry(&temp_queue->comp_used,
3264 + struct fsl_qdma_comp,
3266 + csgf_src = (struct fsl_qdma_csgf *)fsl_comp->virt_addr
3268 + if (fsl_comp->bus_addr + 16 !=
3269 + (dma_addr_t)status_addr->addr) {
3271 + duplicate_handle = 1;
3273 + spin_unlock(&temp_queue->queue_lock);
3279 + if (duplicate_handle) {
3280 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQMR);
3281 + reg |= FSL_QDMA_BSQMR_DI;
3282 + status_addr->addr = 0x0;
3283 + fsl_status->virt_head++;
3284 + if (fsl_status->virt_head == fsl_status->cq
3285 + + fsl_status->n_cq)
3286 + fsl_status->virt_head = fsl_status->cq;
3287 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
3288 + spin_unlock(&temp_queue->queue_lock);
3291 + list_del(&fsl_comp->list);
3293 + reg = qdma_readl(fsl_qdma, block + FSL_QDMA_BSQMR);
3294 + reg |= FSL_QDMA_BSQMR_DI;
3295 + status_addr->addr = 0x0;
3296 + fsl_status->virt_head++;
3297 + if (fsl_status->virt_head == fsl_status->cq + fsl_status->n_cq)
3298 + fsl_status->virt_head = fsl_status->cq;
3299 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
3300 + spin_unlock(&temp_queue->queue_lock);
3302 + spin_lock(&fsl_comp->qchan->vchan.lock);
3303 + vchan_cookie_complete(&fsl_comp->vdesc);
3304 + fsl_comp->qchan->status = DMA_COMPLETE;
3305 + spin_unlock(&fsl_comp->qchan->vchan.lock);
3310 +static irqreturn_t fsl_qdma_error_handler(int irq, void *dev_id)
3312 + struct fsl_qdma_engine *fsl_qdma = dev_id;
3313 + unsigned int intr;
3314 + void __iomem *status = fsl_qdma->status_base;
3316 + intr = qdma_readl(fsl_qdma, status + FSL_QDMA_DEDR);
3319 + dev_err(fsl_qdma->dma_dev.dev, "DMA transaction error!\n");
3321 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEDR);
3322 + return IRQ_HANDLED;
3325 +static irqreturn_t fsl_qdma_queue_handler(int irq, void *dev_id)
3327 + struct fsl_qdma_engine *fsl_qdma = dev_id;
3328 + unsigned int intr, reg;
3329 + void __iomem *block = fsl_qdma->block_base;
3330 + void __iomem *ctrl = fsl_qdma->ctrl_base;
3332 + intr = qdma_readl(fsl_qdma, block + FSL_QDMA_BCQIDR(0));
3334 + if ((intr & FSL_QDMA_CQIDR_SQT) != 0)
3335 + intr = fsl_qdma_queue_transfer_complete(fsl_qdma);
3338 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
3339 + reg |= FSL_QDMA_DMR_DQD;
3340 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
3341 + qdma_writel(fsl_qdma, 0, block + FSL_QDMA_BCQIER(0));
3342 + dev_err(fsl_qdma->dma_dev.dev, "QDMA: status err!\n");
3345 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
3347 + return IRQ_HANDLED;
3351 +fsl_qdma_irq_init(struct platform_device *pdev,
3352 + struct fsl_qdma_engine *fsl_qdma)
3356 + fsl_qdma->error_irq = platform_get_irq_byname(pdev,
3358 + if (fsl_qdma->error_irq < 0) {
3359 + dev_err(&pdev->dev, "Can't get qdma controller irq.\n");
3360 + return fsl_qdma->error_irq;
3363 + fsl_qdma->queue_irq = platform_get_irq_byname(pdev, "qdma-queue");
3364 + if (fsl_qdma->queue_irq < 0) {
3365 + dev_err(&pdev->dev, "Can't get qdma queue irq.\n");
3366 + return fsl_qdma->queue_irq;
3369 + ret = devm_request_irq(&pdev->dev, fsl_qdma->error_irq,
3370 + fsl_qdma_error_handler, 0, "qDMA error", fsl_qdma);
3372 + dev_err(&pdev->dev, "Can't register qDMA controller IRQ.\n");
3375 + ret = devm_request_irq(&pdev->dev, fsl_qdma->queue_irq,
3376 + fsl_qdma_queue_handler, 0, "qDMA queue", fsl_qdma);
3378 + dev_err(&pdev->dev, "Can't register qDMA queue IRQ.\n");
3385 +static int fsl_qdma_reg_init(struct fsl_qdma_engine *fsl_qdma)
3387 + struct fsl_qdma_queue *fsl_queue = fsl_qdma->queue;
3388 + struct fsl_qdma_queue *temp;
3389 + void __iomem *ctrl = fsl_qdma->ctrl_base;
3390 + void __iomem *status = fsl_qdma->status_base;
3391 + void __iomem *block = fsl_qdma->block_base;
3395 + /* Try to halt the qDMA engine first. */
3396 + ret = fsl_qdma_halt(fsl_qdma);
3398 + dev_err(fsl_qdma->dma_dev.dev, "DMA halt failed!");
3403 + * Clear the command queue interrupt detect register for all queues.
3405 + qdma_writel(fsl_qdma, 0xffffffff, block + FSL_QDMA_BCQIDR(0));
3407 + for (i = 0; i < fsl_qdma->n_queues; i++) {
3408 + temp = fsl_queue + i;
3410 + * Initialize Command Queue registers to point to the first
3411 + * command descriptor in memory.
3412 + * Dequeue Pointer Address Registers
3413 + * Enqueue Pointer Address Registers
3415 + qdma_writel(fsl_qdma, temp->bus_addr,
3416 + block + FSL_QDMA_BCQDPA_SADDR(i));
3417 + qdma_writel(fsl_qdma, temp->bus_addr,
3418 + block + FSL_QDMA_BCQEPA_SADDR(i));
3420 + /* Initialize the queue mode. */
3421 + reg = FSL_QDMA_BCQMR_EN;
3422 + reg |= FSL_QDMA_BCQMR_CD_THLD(ilog2(temp->n_cq)-4);
3423 + reg |= FSL_QDMA_BCQMR_CQ_SIZE(ilog2(temp->n_cq)-6);
3424 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BCQMR(i));
3428 + * Workaround for erratum: ERR010812.
3429 + * We must enable XOFF to avoid the enqueue rejection occurs.
3430 + * Setting SQCCMR ENTER_WM to 0x20.
3432 + qdma_writel(fsl_qdma, FSL_QDMA_SQCCMR_ENTER_WM,
3433 + block + FSL_QDMA_SQCCMR);
3435 + * Initialize status queue registers to point to the first
3436 + * command descriptor in memory.
3437 + * Dequeue Pointer Address Registers
3438 + * Enqueue Pointer Address Registers
3440 + qdma_writel(fsl_qdma, fsl_qdma->status->bus_addr,
3441 + block + FSL_QDMA_SQEPAR);
3442 + qdma_writel(fsl_qdma, fsl_qdma->status->bus_addr,
3443 + block + FSL_QDMA_SQDPAR);
3444 + /* Initialize status queue interrupt. */
3445 + qdma_writel(fsl_qdma, FSL_QDMA_BCQIER_CQTIE,
3446 + block + FSL_QDMA_BCQIER(0));
3447 + qdma_writel(fsl_qdma, FSL_QDMA_BSQICR_ICEN | FSL_QDMA_BSQICR_ICST(5)
3449 + block + FSL_QDMA_BSQICR);
3450 + qdma_writel(fsl_qdma, FSL_QDMA_CQIER_MEIE | FSL_QDMA_CQIER_TEIE,
3451 + block + FSL_QDMA_CQIER);
3452 + /* Initialize controller interrupt register. */
3453 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEDR);
3454 + qdma_writel(fsl_qdma, 0xffffffff, status + FSL_QDMA_DEIER);
3456 + /* Initialize the status queue mode. */
3457 + reg = FSL_QDMA_BSQMR_EN;
3458 + reg |= FSL_QDMA_BSQMR_CQ_SIZE(ilog2(fsl_qdma->status->n_cq)-6);
3459 + qdma_writel(fsl_qdma, reg, block + FSL_QDMA_BSQMR);
3461 + reg = qdma_readl(fsl_qdma, ctrl + FSL_QDMA_DMR);
3462 + reg &= ~FSL_QDMA_DMR_DQD;
3463 + qdma_writel(fsl_qdma, reg, ctrl + FSL_QDMA_DMR);
3468 +static struct dma_async_tx_descriptor *fsl_qdma_prep_dma_sg(
3469 + struct dma_chan *chan,
3470 + struct scatterlist *dst_sg, unsigned int dst_nents,
3471 + struct scatterlist *src_sg, unsigned int src_nents,
3472 + unsigned long flags)
3474 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
3475 + struct fsl_qdma_comp *fsl_comp;
3477 + fsl_comp = fsl_qdma_request_enqueue_desc(fsl_chan,
3480 + fsl_qdma_comp_fill_sg(fsl_comp, dst_sg, dst_nents, src_sg, src_nents);
3482 + return vchan_tx_prep(&fsl_chan->vchan, &fsl_comp->vdesc, flags);
3485 +static struct dma_async_tx_descriptor *
3486 +fsl_qdma_prep_memcpy(struct dma_chan *chan, dma_addr_t dst,
3487 + dma_addr_t src, size_t len, unsigned long flags)
3489 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
3490 + struct fsl_qdma_comp *fsl_comp;
3492 + fsl_comp = fsl_qdma_request_enqueue_desc(fsl_chan, 0, 0);
3493 + fsl_qdma_comp_fill_memcpy(fsl_comp, dst, src, len);
3495 + return vchan_tx_prep(&fsl_chan->vchan, &fsl_comp->vdesc, flags);
3498 +static void fsl_qdma_enqueue_desc(struct fsl_qdma_chan *fsl_chan)
3500 + void __iomem *block = fsl_chan->qdma->block_base;
3501 + struct fsl_qdma_queue *fsl_queue = fsl_chan->queue;
3502 + struct fsl_qdma_comp *fsl_comp;
3503 + struct virt_dma_desc *vdesc;
3506 + reg = qdma_readl(fsl_chan->qdma, block + FSL_QDMA_BCQSR(fsl_queue->id));
3507 + if (reg & (FSL_QDMA_BCQSR_QF | FSL_QDMA_BCQSR_XOFF))
3509 + vdesc = vchan_next_desc(&fsl_chan->vchan);
3512 + list_del(&vdesc->node);
3513 + fsl_comp = to_fsl_qdma_comp(vdesc);
3515 + memcpy(fsl_queue->virt_head++, fsl_comp->virt_addr, 16);
3516 + if (fsl_queue->virt_head == fsl_queue->cq + fsl_queue->n_cq)
3517 + fsl_queue->virt_head = fsl_queue->cq;
3519 + list_add_tail(&fsl_comp->list, &fsl_queue->comp_used);
3521 + reg = qdma_readl(fsl_chan->qdma, block + FSL_QDMA_BCQMR(fsl_queue->id));
3522 + reg |= FSL_QDMA_BCQMR_EI;
3523 + qdma_writel(fsl_chan->qdma, reg, block + FSL_QDMA_BCQMR(fsl_queue->id));
3524 + fsl_chan->status = DMA_IN_PROGRESS;
3527 +static enum dma_status fsl_qdma_tx_status(struct dma_chan *chan,
3528 + dma_cookie_t cookie, struct dma_tx_state *txstate)
3530 + return dma_cookie_status(chan, cookie, txstate);
3533 +static void fsl_qdma_free_desc(struct virt_dma_desc *vdesc)
3535 + struct fsl_qdma_comp *fsl_comp;
3536 + struct fsl_qdma_queue *fsl_queue;
3537 + struct fsl_qdma_sg *sg_block;
3538 + unsigned long flags;
3541 + fsl_comp = to_fsl_qdma_comp(vdesc);
3542 + fsl_queue = fsl_comp->qchan->queue;
3544 + if (fsl_comp->sg_block) {
3545 + for (i = 0; i < fsl_comp->sg_block_src +
3546 + fsl_comp->sg_block_dst; i++) {
3547 + sg_block = fsl_comp->sg_block + i;
3548 + dma_pool_free(fsl_queue->sg_pool,
3549 + sg_block->virt_addr,
3550 + sg_block->bus_addr);
3552 + kfree(fsl_comp->sg_block);
3555 + spin_lock_irqsave(&fsl_queue->queue_lock, flags);
3556 + list_add_tail(&fsl_comp->list, &fsl_queue->comp_free);
3557 + spin_unlock_irqrestore(&fsl_queue->queue_lock, flags);
3560 +static void fsl_qdma_issue_pending(struct dma_chan *chan)
3562 + struct fsl_qdma_chan *fsl_chan = to_fsl_qdma_chan(chan);
3563 + struct fsl_qdma_queue *fsl_queue = fsl_chan->queue;
3564 + unsigned long flags;
3566 + spin_lock_irqsave(&fsl_queue->queue_lock, flags);
3567 + spin_lock(&fsl_chan->vchan.lock);
3568 + if (vchan_issue_pending(&fsl_chan->vchan))
3569 + fsl_qdma_enqueue_desc(fsl_chan);
3570 + spin_unlock(&fsl_chan->vchan.lock);
3571 + spin_unlock_irqrestore(&fsl_queue->queue_lock, flags);
3574 +static int fsl_qdma_probe(struct platform_device *pdev)
3576 + struct device_node *np = pdev->dev.of_node;
3577 + struct fsl_qdma_engine *fsl_qdma;
3578 + struct fsl_qdma_chan *fsl_chan;
3579 + struct resource *res;
3580 + unsigned int len, chans, queues;
3583 + ret = of_property_read_u32(np, "channels", &chans);
3585 + dev_err(&pdev->dev, "Can't get channels.\n");
3589 + len = sizeof(*fsl_qdma) + sizeof(*fsl_chan) * chans;
3590 + fsl_qdma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
3594 + ret = of_property_read_u32(np, "queues", &queues);
3596 + dev_err(&pdev->dev, "Can't get queues.\n");
3600 + fsl_qdma->queue = fsl_qdma_alloc_queue_resources(pdev, queues);
3601 + if (!fsl_qdma->queue)
3604 + fsl_qdma->status = fsl_qdma_prep_status_queue(pdev);
3605 + if (!fsl_qdma->status)
3608 + fsl_qdma->n_chans = chans;
3609 + fsl_qdma->n_queues = queues;
3610 + mutex_init(&fsl_qdma->fsl_qdma_mutex);
3612 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3613 + fsl_qdma->ctrl_base = devm_ioremap_resource(&pdev->dev, res);
3614 + if (IS_ERR(fsl_qdma->ctrl_base))
3615 + return PTR_ERR(fsl_qdma->ctrl_base);
3617 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
3618 + fsl_qdma->status_base = devm_ioremap_resource(&pdev->dev, res);
3619 + if (IS_ERR(fsl_qdma->status_base))
3620 + return PTR_ERR(fsl_qdma->status_base);
3622 + res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
3623 + fsl_qdma->block_base = devm_ioremap_resource(&pdev->dev, res);
3624 + if (IS_ERR(fsl_qdma->block_base))
3625 + return PTR_ERR(fsl_qdma->block_base);
3627 + ret = fsl_qdma_irq_init(pdev, fsl_qdma);
3631 + fsl_qdma->big_endian = of_property_read_bool(np, "big-endian");
3632 + INIT_LIST_HEAD(&fsl_qdma->dma_dev.channels);
3633 + for (i = 0; i < fsl_qdma->n_chans; i++) {
3634 + struct fsl_qdma_chan *fsl_chan = &fsl_qdma->chans[i];
3636 + fsl_chan->qdma = fsl_qdma;
3637 + fsl_chan->queue = fsl_qdma->queue + i % fsl_qdma->n_queues;
3638 + fsl_chan->vchan.desc_free = fsl_qdma_free_desc;
3639 + INIT_LIST_HEAD(&fsl_chan->qcomp);
3640 + vchan_init(&fsl_chan->vchan, &fsl_qdma->dma_dev);
3642 + for (i = 0; i < fsl_qdma->n_queues; i++)
3643 + fsl_qdma_pre_request_enqueue_desc(fsl_qdma->queue + i);
3645 + dma_cap_set(DMA_MEMCPY, fsl_qdma->dma_dev.cap_mask);
3646 + dma_cap_set(DMA_SG, fsl_qdma->dma_dev.cap_mask);
3648 + fsl_qdma->dma_dev.dev = &pdev->dev;
3649 + fsl_qdma->dma_dev.device_alloc_chan_resources
3650 + = fsl_qdma_alloc_chan_resources;
3651 + fsl_qdma->dma_dev.device_free_chan_resources
3652 + = fsl_qdma_free_chan_resources;
3653 + fsl_qdma->dma_dev.device_tx_status = fsl_qdma_tx_status;
3654 + fsl_qdma->dma_dev.device_prep_dma_memcpy = fsl_qdma_prep_memcpy;
3655 + fsl_qdma->dma_dev.device_prep_dma_sg = fsl_qdma_prep_dma_sg;
3656 + fsl_qdma->dma_dev.device_issue_pending = fsl_qdma_issue_pending;
3658 + dma_set_mask(&pdev->dev, DMA_BIT_MASK(40));
3660 + platform_set_drvdata(pdev, fsl_qdma);
3662 + ret = dma_async_device_register(&fsl_qdma->dma_dev);
3664 + dev_err(&pdev->dev, "Can't register Freescale qDMA engine.\n");
3668 + ret = fsl_qdma_reg_init(fsl_qdma);
3670 + dev_err(&pdev->dev, "Can't Initialize the qDMA engine.\n");
3678 +static int fsl_qdma_remove(struct platform_device *pdev)
3680 + struct device_node *np = pdev->dev.of_node;
3681 + struct fsl_qdma_engine *fsl_qdma = platform_get_drvdata(pdev);
3682 + struct fsl_qdma_queue *queue_temp;
3683 + struct fsl_qdma_queue *status = fsl_qdma->status;
3684 + struct fsl_qdma_comp *comp_temp, *_comp_temp;
3687 + of_dma_controller_free(np);
3688 + dma_async_device_unregister(&fsl_qdma->dma_dev);
3690 + /* Free descriptor areas */
3691 + for (i = 0; i < fsl_qdma->n_queues; i++) {
3692 + queue_temp = fsl_qdma->queue + i;
3693 + list_for_each_entry_safe(comp_temp, _comp_temp,
3694 + &queue_temp->comp_used, list) {
3695 + dma_pool_free(queue_temp->comp_pool,
3696 + comp_temp->virt_addr,
3697 + comp_temp->bus_addr);
3698 + list_del(&comp_temp->list);
3701 + list_for_each_entry_safe(comp_temp, _comp_temp,
3702 + &queue_temp->comp_free, list) {
3703 + dma_pool_free(queue_temp->comp_pool,
3704 + comp_temp->virt_addr,
3705 + comp_temp->bus_addr);
3706 + list_del(&comp_temp->list);
3709 + dma_free_coherent(&pdev->dev, sizeof(struct fsl_qdma_ccdf) *
3710 + queue_temp->n_cq, queue_temp->cq,
3711 + queue_temp->bus_addr);
3712 + dma_pool_destroy(queue_temp->comp_pool);
3715 + dma_free_coherent(&pdev->dev, sizeof(struct fsl_qdma_ccdf) *
3716 + status->n_cq, status->cq, status->bus_addr);
3720 +static const struct of_device_id fsl_qdma_dt_ids[] = {
3721 + { .compatible = "fsl,ls1021a-qdma", },
3722 + { /* sentinel */ }
3724 +MODULE_DEVICE_TABLE(of, fsl_qdma_dt_ids);
3726 +static struct platform_driver fsl_qdma_driver = {
3728 + .name = "fsl-qdma",
3729 + .owner = THIS_MODULE,
3730 + .of_match_table = fsl_qdma_dt_ids,
3732 + .probe = fsl_qdma_probe,
3733 + .remove = fsl_qdma_remove,
3736 +static int __init fsl_qdma_init(void)
3738 + return platform_driver_register(&fsl_qdma_driver);
3740 +subsys_initcall(fsl_qdma_init);
3742 +static void __exit fsl_qdma_exit(void)
3744 + platform_driver_unregister(&fsl_qdma_driver);
3746 +module_exit(fsl_qdma_exit);
3748 +MODULE_ALIAS("platform:fsl-qdma");
3749 +MODULE_DESCRIPTION("Freescale qDMA engine driver");
3750 +MODULE_LICENSE("GPL v2");