Skip to contentSkip to conversation

dmaengine: Add Synopsys eDMA IP core driver

RFC In review Gustavo Pimentel 2 participants 15 messages Apr 23, 2019 – May 7, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC v6 1/6 dmaengine: Add Synopsys eDMA IP core driver

Add Synopsys PCIe Endpoint eDMA IP core driver to kernel.

This IP is generally distributed with Synopsys PCIe Endpoint IP (depends of the use and licensing agreement).

This core driver, initializes and configures the eDMA IP using vma-helpers functions and dma-engine subsystem.

This driver can be compile as built-in or external module in kernel.

To enable this driver just select DW_EDMA option in kernel configuration, however it requires and selects automatically DMA_ENGINE and DMA_VIRTUAL_CHANNELS option too.

In order to transfer data from point A to B as fast as possible this IP requires a dedicated memory space containing linked list of elements.

All elements of this linked list are continuous and each one describes a data transfer (source and destination addresses, length and a control variable).

For the sake of simplicity, lets assume a memory space for channel write 0 which allows about 42 elements.

+---------+
| Desc #0 |-+
+---------+ |
            V
       +----------+
       | Chunk #0 |-+
       |  CB = 1  | |  +----------+  +-----+  +-----------+  +-----+
       +----------+ +->| Burst #0 |->| ... |->| Burst #41 |->| llp |
            |          +----------+  +-----+  +-----------+  +-----+
            V
       +----------+
       | Chunk #1 |-+
       |  CB = 0  | |  +-----------+  +-----+  +-----------+  +-----+
       +----------+ +->| Burst #42 |->| ... |->| Burst #83 |->| llp |
            |          +-----------+  +-----+  +-----------+  +-----+
            V
       +----------+
       | Chunk #2 |-+
       |  CB = 1  | |  +-----------+  +-----+  +------------+  +-----+
       +----------+ +->| Burst #84 |->| ... |->| Burst #125 |->| llp |
            |          +-----------+  +-----+  +------------+  +-----+
            V
       +----------+
       | Chunk #3 |-+
       |  CB = 0  | |  +------------+  +-----+  +------------+  +-----+
       +----------+ +->| Burst #126 |->| ... |->| Burst #129 |->| llp |
                       +------------+  +-----+  +------------+  +-----+

Legend:
- Linked list, also know as Chunk
- Linked list element*, also know as Burst *CB*, also know as Change Bit,
it's a control bit (and typically is toggled) that allows to easily identify and differentiate between the current linked list and the previous or the next one.
- LLP, is a special element that indicates the end of the linked list
element stream also informs that the next CB should be toggle

On every last Burst of the Chunk (Burst #41, Burst #83, Burst #125 or even Burst #129) is set some flags on their control variable (RIE and LIE bits) that will trigger the send of "done" interruption.

On the interruptions callback, is decided whether to recycle the linked list memory space by writing a new set of Bursts elements (if still exists Chunks to transfer) or is considered completed (if there is no Chunks available to transfer).

On scatter-gather transfer mode, the client will submit a scatter-gather list of n (on this case 130) elements, that will be divide in multiple Chunks, each Chunk will have (on this case 42) a limited number of Bursts and after transferring all Bursts, an interrupt will be triggered, which will allow to recycle the all linked list dedicated memory again with the new information relative to the next Chunk and respective Burst associated and repeat the whole cycle again.

On cyclic transfer mode, the client will submit a buffer pointer, length of it and number of repetitions, in this case each burst will correspond directly to each repetition.

Each Burst can describes a data transfer from point A(source) to point B(destination) with a length that can be from 1 byte up to 4 GB. Since dedicated the memory space where the linked list will reside is limited, the whole n burst elements will be organized in several Chunks, that will be used later to recycle the dedicated memory space to initiate a new sequence of data transfers.

The whole transfer is considered has completed when it was transferred all bursts.

Currently this IP has a set well-known register map, which includes support for legacy and unroll modes. Legacy mode is version of this register map that has multiplexer register that allows to switch registers between all write and read channels and the unroll modes repeats all write and read channels registers with an offset between them. This register map is called v0.

The IP team is creating a new register map more suitable to the latest PCIe features, that very likely will change the map register, which this version will be called v1. As soon as this new version is released by the IP team the support for this version in be included on this driver.

This patch has a direct dependency of the patch ("[RFC 2/7] dmaengine:
Add Synopsys eDMA IP version 0 support").

According to the logic, patches 1, 2 and 3 should be squashed into 1 unique patch, but for the sake of simplicity of review, it was divided in this 3 patches files.

Cc Vinod Koul <[email protected]>
Cc Dan Williams <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Joao Pinto <[email protected]>

---
Changes:
RFC v1->RFC v2:
- Replace comments // (C99 style) by /**/
- Fix the headers of the .c and .h files according to the most recent convention
- Fix errors and checks pointed out by checkpatch with --strict option
- Replace patch small description tag from dma by dmaengine
- Change some dev_info() into dev_dbg()
- Remove unnecessary zero initialization after kzalloc
- Remove direction validation on config() API, since the direction parameter is deprecated
- Refactor code to replace atomic_t by u32 variable type
- Replace start_transfer() name by dw_edma_start_transfer()
- Add spinlock to dw_edma_device_prep_slave_sg()
- Add spinlock to dw_edma_free_chunk()
- Simplify switch case into if on dw_edma_device_pause(), dw_edma_device_resume() and dw_edma_device_terminate_all()
RFC v2->RFC v3:
- Add driver parameter to disable msix feature
- Fix printk variable of phys_addr_t type
- Fix printk variable of __iomem type
- Fix printk variable of size_t type
- Add comments or improve existing ones
- Add possibility to work with multiple IRQs feature
- Fix source and destination addresses
- Add define to magic numbers
- Add DMA cyclic transfer feature
- Rebase to v5.0-rc1
RFC v3->RFC v4:
- Remove unnecessary dev_info() calls
- Add multiple IRQ automatic adaption feature
- Reorder variables declaration in reverse tree order on several functions
- Add return check of dw_edma_alloc_burst() in dw_edma_alloc_chunk()
- Add return check of dw_edma_alloc_chunk() in dw_edma_alloc_desc()
- Remove pm_runtime_get_sync() call in probe()
- Fix dma_cyclic() buffer address
- Replace devm_*_irq() by *_irq() and recode accordingly
- Fix license header
- Replace kvzalloc() by kzalloc() and kvfree() by kfree()
- Move ops->device_config callback from config() to probe()
- Remove restriction to perform operation only in IDLE state on dw_edma_device_config(), dw_edma_device_prep_slave_sg(), dw_edma_device_prep_dma_cyclic()
- Recode and simplify slave_sg() and dma_cyclic()
- Recode and simplify interrupts and channel setup
- Recode dw_edma_device_tx_status()
- Move get_cached_msi_msg() to here
- Code rewrite to use direct dw-edma-v0-core functions instead of callbacks
RFC v4->RFC v5:
- Patch resended, forgot to replace of '___' by '---' and to remove duplicate signed-off
RFC v5->RFC v6:
- Add author on file header
- Remove debug prints
- Code rewrite following Andy's suggestations

 drivers/dma/Kconfig                |   2 +
 drivers/dma/Makefile               |   1 +
 drivers/dma/dw-edma/Kconfig        |   9 +
 drivers/dma/dw-edma/Makefile       |   4 +
 drivers/dma/dw-edma/dw-edma-core.c | 919 +++++++++++++++++++++++++++++++++++++
 drivers/dma/dw-edma/dw-edma-core.h | 165 +++++++
 include/linux/dma/edma.h           |  47 ++
 7 files changed, 1147 insertions(+)
 create mode 100644 drivers/dma/dw-edma/Kconfig
 create mode 100644 drivers/dma/dw-edma/Makefile
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.h
 create mode 100644 include/linux/dma/edma.h
drivers/dma/Kconfig +2 -0
index 0b1dfb5..58b78d2 100644
@@ -665,6 +665,8 @@ source "drivers/dma/qcom/Kconfig"
 
 source "drivers/dma/dw/Kconfig"
 
+source "drivers/dma/dw-edma/Kconfig"
+
 source "drivers/dma/hsu/Kconfig"
 
 source "drivers/dma/sh/Kconfig"
drivers/dma/Makefile +1 -0
index 6126e1c..5bddf6f 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_DMA_SUN4I) += sun4i-dma.o
 obj-$(CONFIG_DMA_SUN6I) += sun6i-dma.o
 obj-$(CONFIG_DW_AXI_DMAC) += dw-axi-dmac/
 obj-$(CONFIG_DW_DMAC_CORE) += dw/
+obj-$(CONFIG_DW_EDMA) += dw-edma/
 obj-$(CONFIG_EP93XX_DMA) += ep93xx_dma.o
 obj-$(CONFIG_FSL_DMA) += fsldma.o
 obj-$(CONFIG_FSL_EDMA) += fsl-edma.o fsl-edma-common.o
drivers/dma/dw-edma/Kconfig new file +9 -0
new file mode 100644
index 0000000..3016bed
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DW_EDMA
+	tristate "Synopsys DesignWare eDMA controller driver"
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Support the Synopsys DesignWare eDMA controller, normally
+	  implemented on endpoints SoCs.
drivers/dma/dw-edma/Makefile new file +4 -0
new file mode 100644
index 0000000..3224010
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_DW_EDMA)		+= dw-edma.o
+dw-edma-objs			:= dw-edma-core.o
drivers/dma/dw-edma/dw-edma-core.c new file +919 -0

919 lines not on this page · raw message

drivers/dma/dw-edma/dw-edma-core.h new file +165 -0

165 lines not on this page · raw message

include/linux/dma/edma.h new file +47 -0

47 lines not on this page · raw message

maintainer
#1 lore raw
Quoted 1 line · Gustavo Pimentel

Add Synopsys PCIe Endpoint eDMA IP core driver to kernel.

Still an RFC ?

drivers/dma/dw-edma/dw-edma-core.c line 69

Quoted 7 lines
drivers/dma/dw-edma/dw-edma-core.c new file +7 -0
+static struct dw_edma_chunk *dw_edma_alloc_chunk(struct dw_edma_desc *desc)
+{
+	struct dw_edma_chan *chan = desc->chan;
+	struct dw_edma *dw = chan->chip->dw;
+	struct dw_edma_chunk *chunk;
+
+	chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);

Looking at the code this should be called from one of the device_prep_xxx calls so this should not sleep, so GFP_NOWAIT please

(pls audit rest of the mem allocations in the code)

drivers/dma/dw-edma/dw-edma-core.c line 75

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-core.c new file +6 -0
+	if (unlikely(!chunk))
+		return NULL;
+
+	INIT_LIST_HEAD(&chunk->list);
+	chunk->chan = chan;
+	chunk->cb = !(desc->chunks_alloc % 2);

? why %2?

Quoted 7 lines
drivers/dma/dw-edma/dw-edma-core.c new file +7 -0
+static enum dma_status
+dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
+			 struct dma_tx_state *txstate)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;

drivers/dma/dw-edma/dw-edma-core.c line 294

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+	unsigned long flags;
+	enum dma_status ret;
+	u32 residue = 0;
+
+	ret = dma_cookie_status(dchan, cookie, txstate);
+	if (ret == DMA_COMPLETE)
+		return ret;
+
+	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
+		ret = DMA_PAUSED;

Don't you want to set residue on paused channel, how else will user know the position of pause?

Quoted 60 lines
drivers/dma/dw-edma/dw-edma-core.c new file +60 -0
+static struct dma_async_tx_descriptor *
+dw_edma_device_transfer(struct dw_edma_transfer *xfer)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
+	enum dma_transfer_direction direction = xfer->direction;
+	phys_addr_t src_addr, dst_addr;
+	struct scatterlist *sg = NULL;
+	struct dw_edma_chunk *chunk;
+	struct dw_edma_burst *burst;
+	struct dw_edma_desc *desc;
+	u32 cnt;
+	int i;
+
+	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
+	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
+		return NULL;
+
+	if (xfer->cyclic) {
+		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
+			return NULL;
+	} else {
+		if (xfer->xfer.sg.len < 1)
+			return NULL;
+	}
+
+	if (!chan->configured)
+		return NULL;
+
+	desc = dw_edma_alloc_desc(chan);
+	if (unlikely(!desc))
+		goto err_alloc;
+
+	chunk = dw_edma_alloc_chunk(desc);
+	if (unlikely(!chunk))
+		goto err_alloc;
+
+	src_addr = chan->config.src_addr;
+	dst_addr = chan->config.dst_addr;
+
+	if (xfer->cyclic) {
+		cnt = xfer->xfer.cyclic.cnt;
+	} else {
+		cnt = xfer->xfer.sg.len;
+		sg = xfer->xfer.sg.sgl;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		if (!xfer->cyclic && !sg)
+			break;
+
+		if (chunk->bursts_alloc == chan->ll_max) {
+			chunk = dw_edma_alloc_chunk(desc);
+			if (unlikely(!chunk))
+				goto err_alloc;
+		}
+
+		burst = dw_edma_alloc_burst(chunk);
+		if (unlikely(!burst))
+			goto err_alloc;
+

drivers/dma/dw-edma/dw-edma-core.c line 383

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+		if (xfer->cyclic)
+			burst->sz = xfer->xfer.cyclic.len;
+		else
+			burst->sz = sg_dma_len(sg);
+
+		chunk->ll_region.sz += burst->sz;
+		desc->alloc_sz += burst->sz;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			burst->sar = src_addr;

We are device to mem, so src is peripheral.. okay

drivers/dma/dw-edma/dw-edma-core.c line 388

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+			if (xfer->cyclic) {
+				burst->dar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->dar = sg_dma_address(sg);
+				src_addr += sg_dma_len(sg);

and we increment the src, doesn't make sense to me!

drivers/dma/dw-edma/dw-edma-core.c line 396

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+			}
+		} else {
+			burst->dar = dst_addr;
+			if (xfer->cyclic) {
+				burst->sar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->sar = sg_dma_address(sg);
+				dst_addr += sg_dma_len(sg);

same here as well

Quoted 13 lines
drivers/dma/dw-edma/dw-edma-core.c new file +13 -0
+static void dw_edma_done_interrupt(struct dw_edma_chan *chan)
+{
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+
+	dw_edma_v0_core_clear_done_int(chan);
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	vd = vchan_next_desc(&chan->vc);
+	if (vd) {
+		switch (chan->request) {
+		case EDMA_REQ_NONE:

drivers/dma/dw-edma/dw-edma-core.c line 472

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+			desc = vd2dw_edma_desc(vd);
+			if (desc->chunks_alloc) {
+				chan->status = EDMA_ST_BUSY;
+				dw_edma_start_transfer(chan);
+			} else {
+				list_del(&vd->node);
+				vchan_cookie_complete(vd);
+				chan->status = EDMA_ST_IDLE;
+			}
+			break;

Empty line after each break please

drivers/dma/dw-edma/dw-edma-core.c line 477

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+		case EDMA_REQ_STOP:
+			list_del(&vd->node);
+			vchan_cookie_complete(vd);
+			chan->request = EDMA_REQ_NONE;
+			chan->status = EDMA_ST_IDLE;

Why do we need to track request as well as status?

drivers/dma/dw-edma/dw-edma-core.c line 574

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+static int dw_edma_alloc_chan_resources(struct dma_chan *dchan)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+
+	if (chan->status != EDMA_ST_IDLE)
+		return -EBUSY;
+
+	dma_cookie_init(dchan);

not using vchan_init() you need to do this and init the lists..?

drivers/dma/dw-edma/dw-edma-core.h line 144

Quoted 3 lines
drivers/dma/dw-edma/dw-edma-core.h new file +3 -0
+struct dw_edma_transfer {
+	struct dma_chan			*dchan;
+	union Xfer {

no camel case please

It would help to run checkpatch with --strict option to find any style issues and fix them as well

Signature · 1 line
~Vinod
#2 lore raw

Hi Vinod,

Quoted 4 lines · Vinod Koul
Quoted 1 line · Gustavo Pimentel

Add Synopsys PCIe Endpoint eDMA IP core driver to kernel.

Still an RFC ?

Yes, it was RFC til I get a formal validation from the HW team. Now that I got it, I can formally submit the very first patch version.

Quoted 12 lines

drivers/dma/dw-edma/dw-edma-core.c line 69

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +7 -0
+static struct dw_edma_chunk *dw_edma_alloc_chunk(struct dw_edma_desc *desc)
+{
+	struct dw_edma_chan *chan = desc->chan;
+	struct dw_edma *dw = chan->chip->dw;
+	struct dw_edma_chunk *chunk;
+
+	chunk = kzalloc(sizeof(*chunk), GFP_KERNEL);

Looking at the code this should be called from one of the device_prep_xxx calls so this should not sleep, so GFP_NOWAIT please

Quoted 1 line

(pls audit rest of the mem allocations in the code)

Ok. Fixed on dw_edma_alloc_burst(), dw_edma_alloc_chunk() and dw_edma_alloc_desc().
The other memory allocations are on probe() and dw_edma_channel_setup() that is called by probe(), that doesn't require to be GFP_NOWAIT.

Quoted 8 lines

drivers/dma/dw-edma/dw-edma-core.c line 75

Quoted 7 lines
drivers/dma/dw-edma/dw-edma-core.c new file +6 -0
+	if (unlikely(!chunk))
+		return NULL;
+
+	INIT_LIST_HEAD(&chunk->list);
+	chunk->chan = chan;
+	chunk->cb = !(desc->chunks_alloc % 2);

? why %2?

I think it's explained on the patch description. CB also is known as Change Bit that must be toggled in order to the HW assume a new linked list is available to be consumed.
Since desc->chunks_alloc variable is an incremental counter the remainder after division by 2 will be zero (if chunks_alloc is even) or one (if chunks_alloc is odd).

Quoted 13 lines
Quoted 13 lines
drivers/dma/dw-edma/dw-edma-core.c new file +12 -0
+static enum dma_status
+dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
+			 struct dma_tx_state *txstate)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+	enum dma_status ret;
+	u32 residue = 0;
+
+	ret = dma_cookie_status(dchan, cookie, txstate);
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-core.c line 294

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+	if (ret == DMA_COMPLETE)
+		return ret;
+
+	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
+		ret = DMA_PAUSED;

Don't you want to set residue on paused channel, how else will user know the position of pause?

I didn't catch you on this. I'm only setting the dma status here. After this function, the residue is calculated and set, isn't it?

Quoted 82 lines
Quoted 61 lines
drivers/dma/dw-edma/dw-edma-core.c new file +60 -0
+static struct dma_async_tx_descriptor *
+dw_edma_device_transfer(struct dw_edma_transfer *xfer)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
+	enum dma_transfer_direction direction = xfer->direction;
+	phys_addr_t src_addr, dst_addr;
+	struct scatterlist *sg = NULL;
+	struct dw_edma_chunk *chunk;
+	struct dw_edma_burst *burst;
+	struct dw_edma_desc *desc;
+	u32 cnt;
+	int i;
+
+	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
+	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
+		return NULL;
+
+	if (xfer->cyclic) {
+		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
+			return NULL;
+	} else {
+		if (xfer->xfer.sg.len < 1)
+			return NULL;
+	}
+
+	if (!chan->configured)
+		return NULL;
+
+	desc = dw_edma_alloc_desc(chan);
+	if (unlikely(!desc))
+		goto err_alloc;
+
+	chunk = dw_edma_alloc_chunk(desc);
+	if (unlikely(!chunk))
+		goto err_alloc;
+
+	src_addr = chan->config.src_addr;
+	dst_addr = chan->config.dst_addr;
+
+	if (xfer->cyclic) {
+		cnt = xfer->xfer.cyclic.cnt;
+	} else {
+		cnt = xfer->xfer.sg.len;
+		sg = xfer->xfer.sg.sgl;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		if (!xfer->cyclic && !sg)
+			break;
+
+		if (chunk->bursts_alloc == chan->ll_max) {
+			chunk = dw_edma_alloc_chunk(desc);
+			if (unlikely(!chunk))
+				goto err_alloc;
+		}
+
+		burst = dw_edma_alloc_burst(chunk);
+		if (unlikely(!burst))
+			goto err_alloc;
+

drivers/dma/dw-edma/dw-edma-core.c line 383

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+		if (xfer->cyclic)
+			burst->sz = xfer->xfer.cyclic.len;
+		else
+			burst->sz = sg_dma_len(sg);
+
+		chunk->ll_region.sz += burst->sz;
+		desc->alloc_sz += burst->sz;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			burst->sar = src_addr;

We are device to mem, so src is peripheral.. okay

drivers/dma/dw-edma/dw-edma-core.c line 388

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+			if (xfer->cyclic) {
+				burst->dar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->dar = sg_dma_address(sg);
+				src_addr += sg_dma_len(sg);

and we increment the src, doesn't make sense to me!

Quoted 10 lines

drivers/dma/dw-edma/dw-edma-core.c line 396

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+			}
+		} else {
+			burst->dar = dst_addr;
+			if (xfer->cyclic) {
+				burst->sar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->sar = sg_dma_address(sg);
+				dst_addr += sg_dma_len(sg);

same here as well

This is hard to explain in words...
Well, in my perspective I want to transfer a piece of memory from the peripheral into local RAM

Through the DMA client API I'll break this piece of memory in several small parts and add all into a list (scatter-gather), right? Each element of the scatter-gather has the sg_dma_address (in the DMA_DEV_TO_MEM case will be the destination address) and the corresponding size.
However, I still need the other address (in the DMA_DEV_TO_MEM case will be the source address) for that small part of memory.
Since I get that address from the config, I still need to increment the source address in the same proportion of the destination address, in other words, the increment will be the part size.
If there is some way to set and get the address for the source (in this case) into each scatter-gather element, that would be much nicer, is that possible?

Quoted 18 lines
Quoted 18 lines
drivers/dma/dw-edma/dw-edma-core.c new file +17 -0
+static void dw_edma_done_interrupt(struct dw_edma_chan *chan)
+{
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+
+	dw_edma_v0_core_clear_done_int(chan);
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	vd = vchan_next_desc(&chan->vc);
+	if (vd) {
+		switch (chan->request) {
+		case EDMA_REQ_NONE:
+			desc = vd2dw_edma_desc(vd);
+			if (desc->chunks_alloc) {
+				chan->status = EDMA_ST_BUSY;
+				dw_edma_start_transfer(chan);
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-core.c line 472

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-core.c new file +6 -0
+			} else {
+				list_del(&vd->node);
+				vchan_cookie_complete(vd);
+				chan->status = EDMA_ST_IDLE;
+			}
+			break;

Empty line after each break please

Ok. Done.

Quoted 8 lines

drivers/dma/dw-edma/dw-edma-core.c line 477

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+		case EDMA_REQ_STOP:
+			list_del(&vd->node);
+			vchan_cookie_complete(vd);
+			chan->request = EDMA_REQ_NONE;
+			chan->status = EDMA_ST_IDLE;

Why do we need to track request as well as status?

Since I don't actually have the PAUSE state feature available on HW, I'm emulating it through software. As far as HW is concerned, it thinks that it has transferred everything (no more bursts valid available), but in terms of software, we still have a lot of chunks (each one containing several bursts) to process.

Quoted 11 lines

drivers/dma/dw-edma/dw-edma-core.c line 574

Quoted 9 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+static int dw_edma_alloc_chan_resources(struct dma_chan *dchan)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+
+	if (chan->status != EDMA_ST_IDLE)
+		return -EBUSY;
+
+	dma_cookie_init(dchan);

not using vchan_init() you need to do this and init the lists..?

That's right, vchan_init() already does that.

Quoted 6 lines

drivers/dma/dw-edma/dw-edma-core.h line 144

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-core.h new file +3 -0
+struct dw_edma_transfer {
+	struct dma_chan			*dchan;
+	union Xfer {

no camel case please

Ok.

Quoted 3 lines

It would help to run checkpatch with --strict option to find any style issues and fix them as well

I usually run with that option, but for now, that option is giving some warnings about macro variable names that are pure noise.

Quoted 2 lines
Signature · 1 line
~Vinod

Regards,
Gustavo

maintainer
#3 lore raw
Quoted 8 lines · Gustavo Pimentel
Quoted 7 lines

drivers/dma/dw-edma/dw-edma-core.c line 75

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-core.c new file +6 -0
+	if (unlikely(!chunk))
+		return NULL;
+
+	INIT_LIST_HEAD(&chunk->list);
+	chunk->chan = chan;
+	chunk->cb = !(desc->chunks_alloc % 2);

? why %2?

Quoted 6 lines

I think it's explained on the patch description. CB also is known as Change Bit that must be toggled in order to the HW assume a new linked list is available to be consumed.
Since desc->chunks_alloc variable is an incremental counter the remainder after division by 2 will be zero (if chunks_alloc is even) or one (if chunks_alloc is odd).

Okay it would be great to add a comment here to explain as well

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/dma/dw-edma/dw-edma-core.c new file +12 -0
+static enum dma_status
+dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
+			 struct dma_tx_state *txstate)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+	enum dma_status ret;
+	u32 residue = 0;
+
+	ret = dma_cookie_status(dchan, cookie, txstate);
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-core.c line 294

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+	if (ret == DMA_COMPLETE)
+		return ret;
+
+	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
+		ret = DMA_PAUSED;

Don't you want to set residue on paused channel, how else will user know the position of pause?

Quoted 2 lines

I didn't catch you on this. I'm only setting the dma status here. After this function, the residue is calculated and set, isn't it?

Hmm I thought you returned for paused case, if not then it is okay

Quoted 92 lines
Quoted 81 lines
Quoted 60 lines
drivers/dma/dw-edma/dw-edma-core.c new file +60 -0
+static struct dma_async_tx_descriptor *
+dw_edma_device_transfer(struct dw_edma_transfer *xfer)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
+	enum dma_transfer_direction direction = xfer->direction;
+	phys_addr_t src_addr, dst_addr;
+	struct scatterlist *sg = NULL;
+	struct dw_edma_chunk *chunk;
+	struct dw_edma_burst *burst;
+	struct dw_edma_desc *desc;
+	u32 cnt;
+	int i;
+
+	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
+	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
+		return NULL;
+
+	if (xfer->cyclic) {
+		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
+			return NULL;
+	} else {
+		if (xfer->xfer.sg.len < 1)
+			return NULL;
+	}
+
+	if (!chan->configured)
+		return NULL;
+
+	desc = dw_edma_alloc_desc(chan);
+	if (unlikely(!desc))
+		goto err_alloc;
+
+	chunk = dw_edma_alloc_chunk(desc);
+	if (unlikely(!chunk))
+		goto err_alloc;
+
+	src_addr = chan->config.src_addr;
+	dst_addr = chan->config.dst_addr;
+
+	if (xfer->cyclic) {
+		cnt = xfer->xfer.cyclic.cnt;
+	} else {
+		cnt = xfer->xfer.sg.len;
+		sg = xfer->xfer.sg.sgl;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		if (!xfer->cyclic && !sg)
+			break;
+
+		if (chunk->bursts_alloc == chan->ll_max) {
+			chunk = dw_edma_alloc_chunk(desc);
+			if (unlikely(!chunk))
+				goto err_alloc;
+		}
+
+		burst = dw_edma_alloc_burst(chunk);
+		if (unlikely(!burst))
+			goto err_alloc;
+

drivers/dma/dw-edma/dw-edma-core.c line 383

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+		if (xfer->cyclic)
+			burst->sz = xfer->xfer.cyclic.len;
+		else
+			burst->sz = sg_dma_len(sg);
+
+		chunk->ll_region.sz += burst->sz;
+		desc->alloc_sz += burst->sz;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			burst->sar = src_addr;

We are device to mem, so src is peripheral.. okay

drivers/dma/dw-edma/dw-edma-core.c line 388

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+			if (xfer->cyclic) {
+				burst->dar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->dar = sg_dma_address(sg);
+				src_addr += sg_dma_len(sg);

and we increment the src, doesn't make sense to me!

Quoted 10 lines

drivers/dma/dw-edma/dw-edma-core.c line 396

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+			}
+		} else {
+			burst->dar = dst_addr;
+			if (xfer->cyclic) {
+				burst->sar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->sar = sg_dma_address(sg);
+				dst_addr += sg_dma_len(sg);

same here as well

Quoted 3 lines

This is hard to explain in words...
Well, in my perspective I want to transfer a piece of memory from the peripheral into local RAM

Right and most of the case RAM address (sg) needs to increment whereas peripheral is a constant one

Quoted 5 lines

Through the DMA client API I'll break this piece of memory in several small parts and add all into a list (scatter-gather), right? Each element of the scatter-gather has the sg_dma_address (in the DMA_DEV_TO_MEM case will be the destination address) and the corresponding size.

Correct

Quoted 5 lines

However, I still need the other address (in the DMA_DEV_TO_MEM case will be the source address) for that small part of memory.
Since I get that address from the config, I still need to increment the source address in the same proportion of the destination address, in other words, the increment will be the part size.

I don't think so. Typically the device address is a FIFO, which does not increment and you keep pushing data at same address. It is not a memory

Quoted 12 lines

If there is some way to set and get the address for the source (in this case) into each scatter-gather element, that would be much nicer, is that possible?

Quoted 7 lines

drivers/dma/dw-edma/dw-edma-core.c line 477

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+		case EDMA_REQ_STOP:
+			list_del(&vd->node);
+			vchan_cookie_complete(vd);
+			chan->request = EDMA_REQ_NONE;
+			chan->status = EDMA_ST_IDLE;

Why do we need to track request as well as status?

Quoted 5 lines

Since I don't actually have the PAUSE state feature available on HW, I'm emulating it through software. As far as HW is concerned, it thinks that it has transferred everything (no more bursts valid available), but in terms of software, we still have a lot of chunks (each one containing several bursts) to process.

Why do you need to emulate, if HW doesnt support so be it? The applications should handle a device which doesnt support pause and not a low level driver

Quoted 6 lines
Quoted 5 lines

drivers/dma/dw-edma/dw-edma-core.h line 144

Quoted 3 lines
drivers/dma/dw-edma/dw-edma-core.h new file +3 -0
+struct dw_edma_transfer {
+	struct dma_chan			*dchan;
+	union Xfer {

no camel case please

Quoted 8 lines

Ok.

Quoted 3 lines

It would help to run checkpatch with --strict option to find any style issues and fix them as well

I usually run with that option, but for now, that option is giving some warnings about macro variable names that are pure noise.

yeah that is a *guide* and to be used as guidance. If code looks worse off then it shouldn't be used. But many of the test are helpful. Some macros checks actually make sense, but again use your judgement :)

Signature · 1 line
~Vinod
#4 lore raw
Quoted 10 lines · Vinod Koul
Quoted 8 lines · Gustavo Pimentel
Quoted 7 lines

drivers/dma/dw-edma/dw-edma-core.c line 75

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-core.c new file +6 -0
+	if (unlikely(!chunk))
+		return NULL;
+
+	INIT_LIST_HEAD(&chunk->list);
+	chunk->chan = chan;
+	chunk->cb = !(desc->chunks_alloc % 2);

? why %2?

Quoted 8 lines
Quoted 6 lines

I think it's explained on the patch description. CB also is known as Change Bit that must be toggled in order to the HW assume a new linked list is available to be consumed.
Since desc->chunks_alloc variable is an incremental counter the remainder after division by 2 will be zero (if chunks_alloc is even) or one (if chunks_alloc is odd).

Okay it would be great to add a comment here to explain as well

Ok, I'll add it.

Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +7 -0
+static enum dma_status
+dw_edma_device_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
+			 struct dma_tx_state *txstate)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan);
+	struct dw_edma_desc *desc;
+	struct virt_dma_desc *vd;

drivers/dma/dw-edma/dw-edma-core.c line 294

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+	unsigned long flags;
+	enum dma_status ret;
+	u32 residue = 0;
+
+	ret = dma_cookie_status(dchan, cookie, txstate);
+	if (ret == DMA_COMPLETE)
+		return ret;
+
+	if (ret == DMA_IN_PROGRESS && chan->status == EDMA_ST_PAUSE)
+		ret = DMA_PAUSED;

Don't you want to set residue on paused channel, how else will user know the position of pause?

Quoted 4 lines
Quoted 2 lines

I didn't catch you on this. I'm only setting the dma status here. After this function, the residue is calculated and set, isn't it?

Hmm I thought you returned for paused case, if not then it is okay

No, I'm just setting the dma status in pause case, then I calculate the residue.

Quoted 108 lines
Quoted 93 lines
Quoted 82 lines
Quoted 61 lines
drivers/dma/dw-edma/dw-edma-core.c new file +60 -0
+static struct dma_async_tx_descriptor *
+dw_edma_device_transfer(struct dw_edma_transfer *xfer)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
+	enum dma_transfer_direction direction = xfer->direction;
+	phys_addr_t src_addr, dst_addr;
+	struct scatterlist *sg = NULL;
+	struct dw_edma_chunk *chunk;
+	struct dw_edma_burst *burst;
+	struct dw_edma_desc *desc;
+	u32 cnt;
+	int i;
+
+	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
+	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
+		return NULL;
+
+	if (xfer->cyclic) {
+		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
+			return NULL;
+	} else {
+		if (xfer->xfer.sg.len < 1)
+			return NULL;
+	}
+
+	if (!chan->configured)
+		return NULL;
+
+	desc = dw_edma_alloc_desc(chan);
+	if (unlikely(!desc))
+		goto err_alloc;
+
+	chunk = dw_edma_alloc_chunk(desc);
+	if (unlikely(!chunk))
+		goto err_alloc;
+
+	src_addr = chan->config.src_addr;
+	dst_addr = chan->config.dst_addr;
+
+	if (xfer->cyclic) {
+		cnt = xfer->xfer.cyclic.cnt;
+	} else {
+		cnt = xfer->xfer.sg.len;
+		sg = xfer->xfer.sg.sgl;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		if (!xfer->cyclic && !sg)
+			break;
+
+		if (chunk->bursts_alloc == chan->ll_max) {
+			chunk = dw_edma_alloc_chunk(desc);
+			if (unlikely(!chunk))
+				goto err_alloc;
+		}
+
+		burst = dw_edma_alloc_burst(chunk);
+		if (unlikely(!burst))
+			goto err_alloc;
+

drivers/dma/dw-edma/dw-edma-core.c line 383

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+		if (xfer->cyclic)
+			burst->sz = xfer->xfer.cyclic.len;
+		else
+			burst->sz = sg_dma_len(sg);
+
+		chunk->ll_region.sz += burst->sz;
+		desc->alloc_sz += burst->sz;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			burst->sar = src_addr;

We are device to mem, so src is peripheral.. okay

drivers/dma/dw-edma/dw-edma-core.c line 388

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+			if (xfer->cyclic) {
+				burst->dar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->dar = sg_dma_address(sg);
+				src_addr += sg_dma_len(sg);

and we increment the src, doesn't make sense to me!

Quoted 10 lines

drivers/dma/dw-edma/dw-edma-core.c line 396

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+			}
+		} else {
+			burst->dar = dst_addr;
+			if (xfer->cyclic) {
+				burst->sar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->sar = sg_dma_address(sg);
+				dst_addr += sg_dma_len(sg);

same here as well

Quoted 3 lines

This is hard to explain in words...
Well, in my perspective I want to transfer a piece of memory from the peripheral into local RAM

Right and most of the case RAM address (sg) needs to increment whereas peripheral is a constant one

Quoted 5 lines

Through the DMA client API I'll break this piece of memory in several small parts and add all into a list (scatter-gather), right? Each element of the scatter-gather has the sg_dma_address (in the DMA_DEV_TO_MEM case will be the destination address) and the corresponding size.

Correct

Quoted 8 lines
Quoted 5 lines

However, I still need the other address (in the DMA_DEV_TO_MEM case will be the source address) for that small part of memory.
Since I get that address from the config, I still need to increment the source address in the same proportion of the destination address, in other words, the increment will be the part size.

I don't think so. Typically the device address is a FIFO, which does not increment and you keep pushing data at same address. It is not a memory

In my use case, it's a memory, perhaps that is what is causing this confusing.
I'm copying "plain and flat" data from point A to B, with the particularity that the peripheral memory is always continuous and the CPU memory can be constituted by scatter-gather chunks of contiguous memory

Quoted 19 lines
Quoted 13 lines

If there is some way to set and get the address for the source (in this case) into each scatter-gather element, that would be much nicer, is that possible?

Quoted 7 lines

drivers/dma/dw-edma/dw-edma-core.c line 477

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+		case EDMA_REQ_STOP:
+			list_del(&vd->node);
+			vchan_cookie_complete(vd);
+			chan->request = EDMA_REQ_NONE;
+			chan->status = EDMA_ST_IDLE;

Why do we need to track request as well as status?

Quoted 5 lines

Since I don't actually have the PAUSE state feature available on HW, I'm emulating it through software. As far as HW is concerned, it thinks that it has transferred everything (no more bursts valid available), but in terms of software, we still have a lot of chunks (each one containing several bursts) to process.

Quoted 3 lines

Why do you need to emulate, if HW doesnt support so be it? The applications should handle a device which doesnt support pause and not a low level driver

In this case, since I've to refill the eDMA memory and retrigger the HW block each time the transfer is completed, it's easy to emulate a pause state, by holding or not refilling the eDMA memory.
I thought that this could be a nice and easy feature to have.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

drivers/dma/dw-edma/dw-edma-core.h line 144

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-core.h new file +3 -0
+struct dw_edma_transfer {
+	struct dma_chan			*dchan;
+	union Xfer {

no camel case please

Ok.

Quoted 3 lines

It would help to run checkpatch with --strict option to find any style issues and fix them as well

Quoted 6 lines
Quoted 2 lines

I usually run with that option, but for now, that option is giving some warnings about macro variable names that are pure noise.

yeah that is a *guide* and to be used as guidance. If code looks worse off then it shouldn't be used. But many of the test are helpful. Some macros checks actually make sense, but again use your judgement :)

Sure.

Quoted 3 lines
Signature · 2 lines
-- 
~Vinod

Regards,
Gustavo

maintainer
#5 lore raw
Quoted 116 lines · Gustavo Pimentel
Quoted 115 lines · Vinod Koul
Quoted 92 lines · Gustavo Pimentel
Quoted 81 lines
Quoted 60 lines
drivers/dma/dw-edma/dw-edma-core.c new file +60 -0
+static struct dma_async_tx_descriptor *
+dw_edma_device_transfer(struct dw_edma_transfer *xfer)
+{
+	struct dw_edma_chan *chan = dchan2dw_edma_chan(xfer->dchan);
+	enum dma_transfer_direction direction = xfer->direction;
+	phys_addr_t src_addr, dst_addr;
+	struct scatterlist *sg = NULL;
+	struct dw_edma_chunk *chunk;
+	struct dw_edma_burst *burst;
+	struct dw_edma_desc *desc;
+	u32 cnt;
+	int i;
+
+	if ((direction == DMA_MEM_TO_DEV && chan->dir == EDMA_DIR_WRITE) ||
+	    (direction == DMA_DEV_TO_MEM && chan->dir == EDMA_DIR_READ))
+		return NULL;
+
+	if (xfer->cyclic) {
+		if (!xfer->xfer.cyclic.len || !xfer->xfer.cyclic.cnt)
+			return NULL;
+	} else {
+		if (xfer->xfer.sg.len < 1)
+			return NULL;
+	}
+
+	if (!chan->configured)
+		return NULL;
+
+	desc = dw_edma_alloc_desc(chan);
+	if (unlikely(!desc))
+		goto err_alloc;
+
+	chunk = dw_edma_alloc_chunk(desc);
+	if (unlikely(!chunk))
+		goto err_alloc;
+
+	src_addr = chan->config.src_addr;
+	dst_addr = chan->config.dst_addr;
+
+	if (xfer->cyclic) {
+		cnt = xfer->xfer.cyclic.cnt;
+	} else {
+		cnt = xfer->xfer.sg.len;
+		sg = xfer->xfer.sg.sgl;
+	}
+
+	for (i = 0; i < cnt; i++) {
+		if (!xfer->cyclic && !sg)
+			break;
+
+		if (chunk->bursts_alloc == chan->ll_max) {
+			chunk = dw_edma_alloc_chunk(desc);
+			if (unlikely(!chunk))
+				goto err_alloc;
+		}
+
+		burst = dw_edma_alloc_burst(chunk);
+		if (unlikely(!burst))
+			goto err_alloc;
+

drivers/dma/dw-edma/dw-edma-core.c line 383

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-core.c new file +10 -0
+		if (xfer->cyclic)
+			burst->sz = xfer->xfer.cyclic.len;
+		else
+			burst->sz = sg_dma_len(sg);
+
+		chunk->ll_region.sz += burst->sz;
+		desc->alloc_sz += burst->sz;
+
+		if (direction == DMA_DEV_TO_MEM) {
+			burst->sar = src_addr;

We are device to mem, so src is peripheral.. okay

drivers/dma/dw-edma/dw-edma-core.c line 388

Quoted 5 lines
drivers/dma/dw-edma/dw-edma-core.c new file +5 -0
+			if (xfer->cyclic) {
+				burst->dar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->dar = sg_dma_address(sg);
+				src_addr += sg_dma_len(sg);

and we increment the src, doesn't make sense to me!

Quoted 10 lines

drivers/dma/dw-edma/dw-edma-core.c line 396

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-core.c new file +8 -0
+			}
+		} else {
+			burst->dar = dst_addr;
+			if (xfer->cyclic) {
+				burst->sar = xfer->xfer.cyclic.paddr;
+			} else {
+				burst->sar = sg_dma_address(sg);
+				dst_addr += sg_dma_len(sg);

same here as well

Quoted 3 lines

This is hard to explain in words...
Well, in my perspective I want to transfer a piece of memory from the peripheral into local RAM

Right and most of the case RAM address (sg) needs to increment whereas peripheral is a constant one

Quoted 5 lines

Through the DMA client API I'll break this piece of memory in several small parts and add all into a list (scatter-gather), right? Each element of the scatter-gather has the sg_dma_address (in the DMA_DEV_TO_MEM case will be the destination address) and the corresponding size.

Correct

Quoted 5 lines

However, I still need the other address (in the DMA_DEV_TO_MEM case will be the source address) for that small part of memory.
Since I get that address from the config, I still need to increment the source address in the same proportion of the destination address, in other words, the increment will be the part size.

Quoted 8 lines
Quoted 2 lines

I don't think so. Typically the device address is a FIFO, which does not increment and you keep pushing data at same address. It is not a memory

In my use case, it's a memory, perhaps that is what is causing this confusing.
I'm copying "plain and flat" data from point A to B, with the particularity that the peripheral memory is always continuous and the CPU memory can be constituted by scatter-gather chunks of contiguous memory

Then why should it be slave transfer, it should be treated as memcpy with src and dst sg lists..

Signature · 1 line
~Vinod
#6 lore raw

RFC v6 2/6 dmaengine: Add Synopsys eDMA IP version 0 support

Add support for the eDMA IP version 0 driver for both register maps (legacy and unroll).

The legacy register mapping was the initial implementation, which consisted in having all registers belonging to channels multiplexed, which could be change anytime (which could led a race-condition) by view port register (access to only one channel available each time).

This register mapping is not very effective and efficient in a multithread environment, which has led to the development of unroll registers mapping, which consists of having all channels registers accessible any time by spreading all channels registers by an offset between them.

This version supports a maximum of 16 independent channels (8 write + 8 read), which can run simultaneously.

Implements a scatter-gather transfer through a linked list, where the size of linked list depends on the allocated memory divided equally among all channels.

Each linked list descriptor can transfer from 1 byte to 4 Gbytes and is alignmented to DWORD.

Both SAR (Source Address Register) and DAR (Destination Address Register) are alignmented to byte.

Cc Vinod Koul <[email protected]>
Cc Dan Williams <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Niklas Cassel <[email protected]>
Cc Joao Pinto <[email protected]>

---
Changes:
RFC v1->RFC v2:
- Replace comments // (C99 style) by /**/
- Replace magic numbers by defines
- Replace boolean return from ternary operation by a double negation operation
- Replace QWORD_HI/QWORD_LO macros by upper_32_bits()/lower_32_bits()
- Fix the headers of the .c and .h files according to the most recent convention
- Fix errors and checks pointed out by checkpatch with --strict option
- Replace patch small description tag from dma by dmaengine
- Refactor code to replace atomic_t by u32 variable type
RFC v2->RFC v3:
- Code rewrite to use FIELD_PREP() and FIELD_GET()
- Add define to magic numbers
- Fix minor bugs
- Rebase to v5.0-rc1
RFC v3->RFC v4:
- Fix license header
- Fix MSI data mask for even and odd channels
- Code rewrite to use direct dw-edma-v0-core functions instead of callbacks
RFC v4->RFC v5:
- Patch resended, forgot to replace of '___' by '---' and to remove duplicate signed-off
RFC v5->RFC v6:
- Add author on file header

 drivers/dma/dw-edma/Makefile          |   3 +-
 drivers/dma/dw-edma/dw-edma-core.c    |   1 +
 drivers/dma/dw-edma/dw-edma-v0-core.c | 347 ++++++++++++++++++++++++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-core.h |  28 +++
 drivers/dma/dw-edma/dw-edma-v0-regs.h | 158 ++++++++++++++++
 5 files changed, 536 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-regs.h
drivers/dma/dw-edma/Makefile +2 -1
index 3224010..01c7c63 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_DW_EDMA)		+= dw-edma.o
-dw-edma-objs			:= dw-edma-core.o
+dw-edma-objs			:= dw-edma-core.o \
+					dw-edma-v0-core.o
drivers/dma/dw-edma/dw-edma-core.c +1 -0
index 54cd531..15fc642 100644
@@ -17,6 +17,7 @@
 #include <linux/pci.h>
 
 #include "dw-edma-core.h"
+#include "dw-edma-v0-core.h"
 #include "../dmaengine.h"
 #include "../virt-dma.h"
 
drivers/dma/dw-edma/dw-edma-v0-core.c new file +347 -0

347 lines not on this page · raw message

drivers/dma/dw-edma/dw-edma-v0-core.h new file +28 -0
new file mode 100644
index 0000000..f8a4d4c
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018-2019 Synopsys, Inc. and/or its affiliates.
+ * Synopsys DesignWare eDMA v0 core
+ *
+ * Author: Gustavo Pimentel <[email protected]>
+ */
+
+#ifndef _DW_EDMA_V0_CORE_H
+#define _DW_EDMA_V0_CORE_H
+
+#include <linux/dma/edma.h>
+
+/* eDMA management callbacks */
+void dw_edma_v0_core_off(struct dw_edma *chan);
+u16 dw_edma_v0_core_ch_count(struct dw_edma *chan, enum dw_edma_dir dir);
+enum dma_status dw_edma_v0_core_ch_status(struct dw_edma_chan *chan);
+void dw_edma_v0_core_clear_done_int(struct dw_edma_chan *chan);
+void dw_edma_v0_core_clear_abort_int(struct dw_edma_chan *chan);
+u32 dw_edma_v0_core_status_done_int(struct dw_edma *chan, enum dw_edma_dir dir);
+u32 dw_edma_v0_core_status_abort_int(struct dw_edma *chan, enum dw_edma_dir dir);
+void dw_edma_v0_core_start(struct dw_edma_chunk *chunk, bool first);
+int dw_edma_v0_core_device_config(struct dw_edma_chan *chan);
+/* eDMA debug fs callbacks */
+int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip);
+void dw_edma_v0_core_debugfs_off(void);
+
+#endif /* _DW_EDMA_V0_CORE_H */
drivers/dma/dw-edma/dw-edma-v0-regs.h new file +158 -0

158 lines not on this page · raw message

maintainer
#7 lore raw

Re: [RFC v6 2/6] dmaengine: Add Synopsys eDMA IP version 0 support

Quoted 45 lines · Gustavo Pimentel
drivers/dma/dw-edma/dw-edma-v0-regs.h new file +45 -0
+struct dw_edma_v0_regs {
+	/* eDMA global registers */
+	u32 ctrl_data_arb_prior;			/* 0x000 */
+	u32 padding_1;					/* 0x004 */
+	u32 ctrl;					/* 0x008 */
+	u32 wr_engine_en;				/* 0x00c */
+	u32 wr_doorbell;				/* 0x010 */
+	u32 padding_2;					/* 0x014 */
+	u32 wr_ch_arb_weight_low;			/* 0x018 */
+	u32 wr_ch_arb_weight_high;			/* 0x01c */
+	u32 padding_3[3];				/* [0x020..0x028] */
+	u32 rd_engine_en;				/* 0x02c */
+	u32 rd_doorbell;				/* 0x030 */
+	u32 padding_4;					/* 0x034 */
+	u32 rd_ch_arb_weight_low;			/* 0x038 */
+	u32 rd_ch_arb_weight_high;			/* 0x03c */
+	u32 padding_5[3];				/* [0x040..0x048] */
+	/* eDMA interrupts registers */
+	u32 wr_int_status;				/* 0x04c */
+	u32 padding_6;					/* 0x050 */
+	u32 wr_int_mask;				/* 0x054 */
+	u32 wr_int_clear;				/* 0x058 */
+	u32 wr_err_status;				/* 0x05c */
+	u32 wr_done_imwr_low;				/* 0x060 */
+	u32 wr_done_imwr_high;				/* 0x064 */
+	u32 wr_abort_imwr_low;				/* 0x068 */
+	u32 wr_abort_imwr_high;				/* 0x06c */
+	u32 wr_ch01_imwr_data;				/* 0x070 */
+	u32 wr_ch23_imwr_data;				/* 0x074 */
+	u32 wr_ch45_imwr_data;				/* 0x078 */
+	u32 wr_ch67_imwr_data;				/* 0x07c */
+	u32 padding_7[4];				/* [0x080..0x08c] */
+	u32 wr_linked_list_err_en;			/* 0x090 */
+	u32 padding_8[3];				/* [0x094..0x09c] */
+	u32 rd_int_status;				/* 0x0a0 */
+	u32 padding_9;					/* 0x0a4 */
+	u32 rd_int_mask;				/* 0x0a8 */
+	u32 rd_int_clear;				/* 0x0ac */
+	u32 padding_10;					/* 0x0b0 */
+	u32 rd_err_status_low;				/* 0x0b4 */
+	u32 rd_err_status_high;				/* 0x0b8 */
+	u32 padding_11[2];				/* [0x0bc..0x0c0] */
+	u32 rd_linked_list_err_en;			/* 0x0c4 */
+	u32 padding_12;					/* 0x0c8 */
+	u32 rd_done_imwr_low;				/* 0x0cc */

drivers/dma/dw-edma/dw-edma-v0-regs.h line 136

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-v0-regs.h new file +10 -0
+	u32 rd_done_imwr_high;				/* 0x0d0 */
+	u32 rd_abort_imwr_low;				/* 0x0d4 */
+	u32 rd_abort_imwr_high;				/* 0x0d8 */
+	u32 rd_ch01_imwr_data;				/* 0x0dc */
+	u32 rd_ch23_imwr_data;				/* 0x0e0 */
+	u32 rd_ch45_imwr_data;				/* 0x0e4 */
+	u32 rd_ch67_imwr_data;				/* 0x0e8 */
+	u32 padding_13[4];				/* [0x0ec..0x0f8] */
+	/* eDMA channel context grouping */
+	union Type {

Again no camecase please

Signature · 1 line
~Vinod
#8 lore raw

RFC v6 3/6 dmaengine: Add Synopsys eDMA IP version 0 debugfs support

Add Synopsys eDMA IP version 0 debugfs support to assist any debug in the future.

Creates a file system structure composed by folders and files that mimic the IP register map (this files are read only) to ease any debug.

To enable this feature is necessary to select DEBUG_FS option on kernel configuration.

Small output example:

(eDMA IP version 0, unroll, 1 write + 1 read channels)

% mount -t debugfs none /sys/kernel/debug/
% tree /sys/kernel/debug/dw-edma-core:0/
dw-edma/

├── version
├── mode
├── wr_ch_cnt
├── rd_ch_cnt
└── registers
    ├── ctrl_data_arb_prior
    ├── ctrl
    ├── write
    │   ├── engine_en
    │   ├── doorbell
    │   ├── ch_arb_weight_low
    │   ├── ch_arb_weight_high
    │   ├── int_status
    │   ├── int_mask
    │   ├── int_clear
    │   ├── err_status
    │   ├── done_imwr_low
    │   ├── done_imwr_high
    │   ├── abort_imwr_low
    │   ├── abort_imwr_high
    │   ├── ch01_imwr_data
    │   ├── ch23_imwr_data
    │   ├── ch45_imwr_data
    │   ├── ch67_imwr_data
    │   ├── linked_list_err_en
    │   ├── engine_chgroup
    │   ├── engine_hshake_cnt_low
    │   ├── engine_hshake_cnt_high
    │   ├── ch0_pwr_en
    │   ├── ch1_pwr_en
    │   ├── ch2_pwr_en
    │   ├── ch3_pwr_en
    │   ├── ch4_pwr_en
    │   ├── ch5_pwr_en
    │   ├── ch6_pwr_en
    │   ├── ch7_pwr_en
    │   └── channel:0
    │       ├── ch_control1
    │       ├── ch_control2
    │       ├── transfer_size
    │       ├── sar_low
    │       ├── sar_high
    │       ├── dar_high
    │       ├── llp_low
    │       └── llp_high
    └── read
        ├── engine_en
        ├── doorbell
        ├── ch_arb_weight_low
        ├── ch_arb_weight_high
        ├── int_status
        ├── int_mask
        ├── int_clear
        ├── err_status_low
        ├── err_status_high
        ├── done_imwr_low
        ├── done_imwr_high
        ├── abort_imwr_low
        ├── abort_imwr_high
        ├── ch01_imwr_data
        ├── ch23_imwr_data
        ├── ch45_imwr_data
        ├── ch67_imwr_data
        ├── linked_list_err_en
        ├── engine_chgroup
        ├── engine_hshake_cnt_low
        ├── engine_hshake_cnt_high
        ├── ch0_pwr_en
        ├── ch1_pwr_en
        ├── ch2_pwr_en
        ├── ch3_pwr_en
        ├── ch4_pwr_en
        ├── ch5_pwr_en
        ├── ch6_pwr_en
        ├── ch7_pwr_en
        └── channel:0
            ├── ch_control1
            ├── ch_control2
            ├── transfer_size
            ├── sar_low
            ├── sar_high
            ├── dar_high
            ├── llp_low
            └── llp_high
Cc Vinod Koul <[email protected]>
Cc Dan Williams <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Joao Pinto <[email protected]>

---
Changes:
RFC v1->RFC v2:
- Replace comments // (C99 style) by /**/
- Fix the headers of the .c and .h files according to the most recent convention
- Fix errors and checks pointed out by checkpatch with --strict option
- Replace patch small description tag from dma by dmaengine
RFC v2->RFC v3:
- Code rewrite to use FIELD_PREP() and FIELD_GET()
- Add define to magic numbers
- Rebase to v5.0-rc1
RFC v3->RFC v4:
- Replaced number of entries of a struct calculation by a helper macro
- Reorder variables declaration in reverse tree order on several functions
- Fix inline function declarations when CONFIG_DEBUG_FS is not defined
- Fix license header
- Add missing cast
RFC v4->RFC v5:
- Patch resended, forgot to replace of '___' by '---' and to remove duplicate signed-off
RFC v5->RFC v6:
- Add author on file header

 drivers/dma/dw-edma/Makefile             |   3 +-
 drivers/dma/dw-edma/dw-edma-v0-core.c    |   3 +-
 drivers/dma/dw-edma/dw-edma-v0-debugfs.c | 361 +++++++++++++++++++++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-debugfs.h |  28 +++
 4 files changed, 393 insertions(+), 2 deletions(-)
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.h
drivers/dma/dw-edma/Makefile +2 -1
index 01c7c63..0c53033 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_DW_EDMA)		+= dw-edma.o
+dw-edma-$(CONFIG_DEBUG_FS)	:= dw-edma-v0-debugfs.o
 dw-edma-objs			:= dw-edma-core.o \
-					dw-edma-v0-core.o
+					dw-edma-v0-core.o $(dw-edma-y)
drivers/dma/dw-edma/dw-edma-v0-core.c +2 -1
index aa5d3f7..2fde20c 100644
@@ -339,9 +339,10 @@ int dw_edma_v0_core_device_config(struct dw_edma_chan *chan)
 /* eDMA debugfs callbacks */
 int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip)
 {
-	return 0;
+	return dw_edma_v0_debugfs_on(chip);
 }
 
 void dw_edma_v0_core_debugfs_off(void)
 {
+	dw_edma_v0_debugfs_off();
 }
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +361 -0

361 lines not on this page · raw message

drivers/dma/dw-edma/dw-edma-v0-debugfs.h new file +28 -0
new file mode 100644
index 0000000..cf17820
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018-2019 Synopsys, Inc. and/or its affiliates.
+ * Synopsys DesignWare eDMA v0 core
+ *
+ * Author: Gustavo Pimentel <[email protected]>
+ */
+
+#ifndef _DW_EDMA_V0_DEBUG_FS_H
+#define _DW_EDMA_V0_DEBUG_FS_H
+
+#include <linux/dma/edma.h>
+
+#ifdef CONFIG_DEBUG_FS
+int dw_edma_v0_debugfs_on(struct dw_edma_chip *chip);
+void dw_edma_v0_debugfs_off(void);
+#else
+static inline int dw_edma_v0_debugfs_on(struct dw_edma_chip *chip)
+{
+	return 0;
+}
+
+static inline void dw_edma_v0_debugfs_off(void)
+{
+}
+#endif /* CONFIG_DEBUG_FS */
+
+#endif /* _DW_EDMA_V0_DEBUG_FS_H */
maintainer
#9 lore raw

Re: [RFC v6 3/6] dmaengine: Add Synopsys eDMA IP version 0 debugfs support

drivers/dma/dw-edma/dw-edma-v0-core.c int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) · line 342

Quoted 4 lines · Gustavo Pimentel

int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip) {

drivers/dma/dw-edma/dw-edma-v0-core.c +1 -1
-	return 0;
+	return dw_edma_v0_debugfs_on(chip);

who calls this?

Quoted 1 line

+#define RD_PERM 0444

lets not use a macro for these, 444 is more readable :)

Quoted 21 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +21 -0
+static int dw_edma_debugfs_u32_get(void *data, u64 *val)
+{
+	if (dw->mode == EDMA_MODE_LEGACY &&
+	    data >= (void *)&regs->type.legacy.ch) {
+		void *ptr = (void *)&regs->type.legacy.ch;
+		u32 viewport_sel = 0;
+		unsigned long flags;
+		u16 ch;
+
+		for (ch = 0; ch < dw->wr_ch_cnt; ch++)
+			if (lim[0][ch].start >= data && data < lim[0][ch].end) {
+				ptr += (data - lim[0][ch].start);
+				goto legacy_sel_wr;
+			}
+
+		for (ch = 0; ch < dw->rd_ch_cnt; ch++)
+			if (lim[1][ch].start >= data && data < lim[1][ch].end) {
+				ptr += (data - lim[1][ch].start);
+				goto legacy_sel_rd;
+			}
+

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 87

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +10 -0
+		return 0;
+legacy_sel_rd:
+		viewport_sel = BIT(31);
+legacy_sel_wr:
+		viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, ch);
+
+		raw_spin_lock_irqsave(&dw->lock, flags);
+
+		writel(viewport_sel, &regs->type.legacy.viewport_sel);
+		*val = readl((u32 *)ptr);

why do you need the cast?

Quoted 17 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +17 -0
+static int dw_edma_debugfs_regs(void)
+{
+	const struct debugfs_entries debugfs_regs[] = {
+		REGISTER(ctrl_data_arb_prior),
+		REGISTER(ctrl),
+	};
+	struct dentry *regs_dir;
+	int nr_entries, err;
+
+	regs_dir = debugfs_create_dir(REGISTERS_STR, base_dir);
+	if (!regs_dir)
+		return -EPERM;
+
+	nr_entries = ARRAY_SIZE(debugfs_regs);
+	err = dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir);
+	if (err)
+		return err;

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 316

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +10 -0
+
+	err = dw_edma_debugfs_regs_wr(regs_dir);
+	if (err)
+		return err;
+
+	err = dw_edma_debugfs_regs_rd(regs_dir);
+	if (err)
+		return err;
+
+	return 0;

single return err would suffice right?

Quoted 27 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +27 -0
+int dw_edma_v0_debugfs_on(struct dw_edma_chip *chip)
+{
+	struct dentry *entry;
+	int err;
+
+	dw = chip->dw;
+	if (!dw)
+		return -EPERM;
+
+	regs = (struct dw_edma_v0_regs *)dw->rg_region.vaddr;
+	if (!regs)
+		return -EPERM;
+
+	base_dir = debugfs_create_dir(dw->name, 0);
+	if (!base_dir)
+		return -EPERM;
+
+	entry = debugfs_create_u32("version", RD_PERM, base_dir, &dw->version);
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u32("mode", RD_PERM, base_dir, &dw->mode);
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u16("wr_ch_cnt", RD_PERM, base_dir,
+				   &dw->wr_ch_cnt);

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 355

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +10 -0
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u16("rd_ch_cnt", RD_PERM, base_dir,
+				   &dw->rd_ch_cnt);
+	if (!entry)
+		return -EPERM;
+
+	err = dw_edma_debugfs_regs();
+	return err;

return dw_edma_debugfs_regs() perhpaps..?

Signature · 1 line
~Vinod
#10 lore raw

RE: [RFC v6 3/6] dmaengine: Add Synopsys eDMA IP version 0 debugfs support

Hi Vinod,

Quoted 8 lines · Vinod Koul

drivers/dma/dw-edma/dw-edma-v0-core.c int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) · line 342

Quoted 4 lines · Gustavo Pimentel

int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip) {

drivers/dma/dw-edma/dw-edma-v0-core.c +1 -1
-	return 0;
+	return dw_edma_v0_debugfs_on(chip);

who calls this?

The main driver. This was done like this for 2 reasons:
1) To not break the patch #1 compilation
2) Since the code it's to extensive, I decided to break it in another patch.

Quoted 4 lines
Quoted 2 lines

+#define RD_PERM 0444

lets not use a macro for these, 444 is more readable :)

Ok.

Quoted 26 lines
Quoted 26 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +25 -0
+static int dw_edma_debugfs_u32_get(void *data, u64 *val)
+{
+	if (dw->mode == EDMA_MODE_LEGACY &&
+	    data >= (void *)&regs->type.legacy.ch) {
+		void *ptr = (void *)&regs->type.legacy.ch;
+		u32 viewport_sel = 0;
+		unsigned long flags;
+		u16 ch;
+
+		for (ch = 0; ch < dw->wr_ch_cnt; ch++)
+			if (lim[0][ch].start >= data && data < lim[0][ch].end) {
+				ptr += (data - lim[0][ch].start);
+				goto legacy_sel_wr;
+			}
+
+		for (ch = 0; ch < dw->rd_ch_cnt; ch++)
+			if (lim[1][ch].start >= data && data < lim[1][ch].end) {
+				ptr += (data - lim[1][ch].start);
+				goto legacy_sel_rd;
+			}
+
+		return 0;
+legacy_sel_rd:
+		viewport_sel = BIT(31);
+legacy_sel_wr:
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 87

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+		viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, ch);
+
+		raw_spin_lock_irqsave(&dw->lock, flags);
+
+		writel(viewport_sel, &regs->type.legacy.viewport_sel);
+		*val = readl((u32 *)ptr);

why do you need the cast?

I can't tell from my head, but I think checkpatch or some code analysis tool was complaining about not having that.

Quoted 22 lines
Quoted 22 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +21 -0
+static int dw_edma_debugfs_regs(void)
+{
+	const struct debugfs_entries debugfs_regs[] = {
+		REGISTER(ctrl_data_arb_prior),
+		REGISTER(ctrl),
+	};
+	struct dentry *regs_dir;
+	int nr_entries, err;
+
+	regs_dir = debugfs_create_dir(REGISTERS_STR, base_dir);
+	if (!regs_dir)
+		return -EPERM;
+
+	nr_entries = ARRAY_SIZE(debugfs_regs);
+	err = dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir);
+	if (err)
+		return err;
+
+	err = dw_edma_debugfs_regs_wr(regs_dir);
+	if (err)
+		return err;
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 316

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+
+	err = dw_edma_debugfs_regs_rd(regs_dir);
+	if (err)
+		return err;
+
+	return 0;

single return err would suffice right?

By looking now to this code, I decided to remove the err variable and perform the if immediately on the function, if the result is different from 0 it goes directly to a return -EPERM.

Quoted 32 lines
Quoted 32 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +31 -0
+int dw_edma_v0_debugfs_on(struct dw_edma_chip *chip)
+{
+	struct dentry *entry;
+	int err;
+
+	dw = chip->dw;
+	if (!dw)
+		return -EPERM;
+
+	regs = (struct dw_edma_v0_regs *)dw->rg_region.vaddr;
+	if (!regs)
+		return -EPERM;
+
+	base_dir = debugfs_create_dir(dw->name, 0);
+	if (!base_dir)
+		return -EPERM;
+
+	entry = debugfs_create_u32("version", RD_PERM, base_dir, &dw->version);
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u32("mode", RD_PERM, base_dir, &dw->mode);
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u16("wr_ch_cnt", RD_PERM, base_dir,
+				   &dw->wr_ch_cnt);
+	if (!entry)
+		return -EPERM;
+
+	entry = debugfs_create_u16("rd_ch_cnt", RD_PERM, base_dir,
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 355

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+				   &dw->rd_ch_cnt);
+	if (!entry)
+		return -EPERM;
+
+	err = dw_edma_debugfs_regs();
+	return err;

return dw_edma_debugfs_regs() perhpaps..?

Sure, small traces of old code.

Quoted 2 lines
Signature · 1 line
~Vinod

Regards,
Gustavo

maintainer
#11 lore raw

Re: [RFC v6 3/6] dmaengine: Add Synopsys eDMA IP version 0 debugfs support

Quoted 13 lines · Gustavo Pimentel

Hi Vinod,

Quoted 8 lines · Vinod Koul

drivers/dma/dw-edma/dw-edma-v0-core.c int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) · line 342

Quoted 4 lines · Gustavo Pimentel

int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip) {

drivers/dma/dw-edma/dw-edma-v0-core.c +1 -1
-	return 0;
+	return dw_edma_v0_debugfs_on(chip);

who calls this?

Quoted 4 lines

The main driver. This was done like this for 2 reasons:
1) To not break the patch #1 compilation
2) Since the code it's to extensive, I decided to break it in another patch.

Hmm I guess I missed that one. I was actually looking at usage and not questioning split :)

Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +25 -0
+static int dw_edma_debugfs_u32_get(void *data, u64 *val)
+{
+	if (dw->mode == EDMA_MODE_LEGACY &&
+	    data >= (void *)&regs->type.legacy.ch) {
+		void *ptr = (void *)&regs->type.legacy.ch;
+		u32 viewport_sel = 0;
+		unsigned long flags;
+		u16 ch;
+
+		for (ch = 0; ch < dw->wr_ch_cnt; ch++)
+			if (lim[0][ch].start >= data && data < lim[0][ch].end) {
+				ptr += (data - lim[0][ch].start);
+				goto legacy_sel_wr;
+			}
+
+		for (ch = 0; ch < dw->rd_ch_cnt; ch++)
+			if (lim[1][ch].start >= data && data < lim[1][ch].end) {
+				ptr += (data - lim[1][ch].start);
+				goto legacy_sel_rd;
+			}
+
+		return 0;
+legacy_sel_rd:
+		viewport_sel = BIT(31);
+legacy_sel_wr:
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 87

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+		viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, ch);
+
+		raw_spin_lock_irqsave(&dw->lock, flags);
+
+		writel(viewport_sel, &regs->type.legacy.viewport_sel);
+		*val = readl((u32 *)ptr);

why do you need the cast?

Quoted 2 lines

I can't tell from my head, but I think checkpatch or some code analysis tool was complaining about not having that.

ptr is void, so there is no need for casts to or away from void.

Quoted 30 lines
Quoted 21 lines
Quoted 21 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +21 -0
+static int dw_edma_debugfs_regs(void)
+{
+	const struct debugfs_entries debugfs_regs[] = {
+		REGISTER(ctrl_data_arb_prior),
+		REGISTER(ctrl),
+	};
+	struct dentry *regs_dir;
+	int nr_entries, err;
+
+	regs_dir = debugfs_create_dir(REGISTERS_STR, base_dir);
+	if (!regs_dir)
+		return -EPERM;
+
+	nr_entries = ARRAY_SIZE(debugfs_regs);
+	err = dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir);
+	if (err)
+		return err;
+
+	err = dw_edma_debugfs_regs_wr(regs_dir);
+	if (err)
+		return err;
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 316

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+
+	err = dw_edma_debugfs_regs_rd(regs_dir);
+	if (err)
+		return err;
+
+	return 0;

single return err would suffice right?

Quoted 3 lines

By looking now to this code, I decided to remove the err variable and perform the if immediately on the function, if the result is different from 0 it goes directly to a return -EPERM.

And one more things, we do not need to check errors on debugfs calls, and if it fails it fails...

Signature · 1 line
~Vinod
#12 lore raw

RE: [RFC v6 3/6] dmaengine: Add Synopsys eDMA IP version 0 debugfs support

Quoted 91 lines · Vinod Koul
Quoted 13 lines · Gustavo Pimentel

Hi Vinod,

Quoted 8 lines · Vinod Koul

drivers/dma/dw-edma/dw-edma-v0-core.c int dw_edma_v0_core_device_config(struct dw_edma_chan *chan) · line 342

Quoted 4 lines · Gustavo Pimentel

int dw_edma_v0_core_debugfs_on(struct dw_edma_chip *chip) {

drivers/dma/dw-edma/dw-edma-v0-core.c +1 -1
-	return 0;
+	return dw_edma_v0_debugfs_on(chip);

who calls this?

Quoted 4 lines

The main driver. This was done like this for 2 reasons:
1) To not break the patch #1 compilation
2) Since the code it's to extensive, I decided to break it in another patch.

Hmm I guess I missed that one. I was actually looking at usage and not questioning split :)

Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +25 -0
+static int dw_edma_debugfs_u32_get(void *data, u64 *val)
+{
+	if (dw->mode == EDMA_MODE_LEGACY &&
+	    data >= (void *)&regs->type.legacy.ch) {
+		void *ptr = (void *)&regs->type.legacy.ch;
+		u32 viewport_sel = 0;
+		unsigned long flags;
+		u16 ch;
+
+		for (ch = 0; ch < dw->wr_ch_cnt; ch++)
+			if (lim[0][ch].start >= data && data < lim[0][ch].end) {
+				ptr += (data - lim[0][ch].start);
+				goto legacy_sel_wr;
+			}
+
+		for (ch = 0; ch < dw->rd_ch_cnt; ch++)
+			if (lim[1][ch].start >= data && data < lim[1][ch].end) {
+				ptr += (data - lim[1][ch].start);
+				goto legacy_sel_rd;
+			}
+
+		return 0;
+legacy_sel_rd:
+		viewport_sel = BIT(31);
+legacy_sel_wr:
Quoted 8 lines

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 87

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +6 -0
+		viewport_sel |= FIELD_PREP(EDMA_V0_VIEWPORT_MASK, ch);
+
+		raw_spin_lock_irqsave(&dw->lock, flags);
+
+		writel(viewport_sel, &regs->type.legacy.viewport_sel);
+		*val = readl((u32 *)ptr);

why do you need the cast?

Quoted 2 lines

I can't tell from my head, but I think checkpatch or some code analysis tool was complaining about not having that.

ptr is void, so there is no need for casts to or away from void.

Quoted 30 lines
Quoted 29 lines
Quoted 17 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +17 -0
+static int dw_edma_debugfs_regs(void)
+{
+	const struct debugfs_entries debugfs_regs[] = {
+		REGISTER(ctrl_data_arb_prior),
+		REGISTER(ctrl),
+	};
+	struct dentry *regs_dir;
+	int nr_entries, err;
+
+	regs_dir = debugfs_create_dir(REGISTERS_STR, base_dir);
+	if (!regs_dir)
+		return -EPERM;
+
+	nr_entries = ARRAY_SIZE(debugfs_regs);
+	err = dw_edma_debugfs_create_x32(debugfs_regs, nr_entries, regs_dir);
+	if (err)
+		return err;

drivers/dma/dw-edma/dw-edma-v0-debugfs.c line 316

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-v0-debugfs.c new file +10 -0
+
+	err = dw_edma_debugfs_regs_wr(regs_dir);
+	if (err)
+		return err;
+
+	err = dw_edma_debugfs_regs_rd(regs_dir);
+	if (err)
+		return err;
+
+	return 0;

single return err would suffice right?

Quoted 6 lines
Quoted 3 lines

By looking now to this code, I decided to remove the err variable and perform the if immediately on the function, if the result is different from 0 it goes directly to a return -EPERM.

And one more things, we do not need to check errors on debugfs calls, and if it fails it fails...

Ok, makes sense. I'll remove all return validation relatively to debugfs calls.

Quoted 3 lines
Signature · 2 lines
-- 
~Vinod
#13 lore raw

v6 cover dmaengine: Add Synopsys eDMA IP driver (version 0)

Add Synopsys eDMA IP driver (version 0 and for EP side only) to Linux kernel. This IP is generally distributed with Synopsys PCIe EndPoint IP (depends of the use and licensing agreement), which supports:
- legacy and unroll modes
- 16 independent and concurrent channels (8 write + 8 read)
- supports linked list (scatter-gather) transfer
- each linked list descriptor can transfer from 1 byte to 4 Gbytes
- supports cyclic transfer
- PCIe EndPoint glue-logic

This patch series contains:
- eDMA core + eDMA core v0 driver (implements the interface with DMAengine controller APIs and interfaces with eDMA HW block)
- eDMA PCIe glue-logic reference driver (attaches to Synopsys EP and provides memory access to eDMA core driver)

Gustavo Pimentel (6):
dmaengine: Add Synopsys eDMA IP core driver
dmaengine: Add Synopsys eDMA IP version 0 support
dmaengine: Add Synopsys eDMA IP version 0 debugfs support
PCI: Add Synopsys endpoint EDDA Device ID
dmaengine: Add Synopsys eDMA IP PCIe glue-logic
MAINTAINERS: Add Synopsys eDMA IP driver maintainer

 MAINTAINERS                              |   7 +
 drivers/dma/Kconfig                      |   2 +
 drivers/dma/Makefile                     |   1 +
 drivers/dma/dw-edma/Kconfig              |  18 +
 drivers/dma/dw-edma/Makefile             |   7 +
 drivers/dma/dw-edma/dw-edma-core.c       | 920 +++++++++++++++++++++++++++++++
 drivers/dma/dw-edma/dw-edma-core.h       | 165 ++++++
 drivers/dma/dw-edma/dw-edma-pcie.c       | 229 ++++++++
 drivers/dma/dw-edma/dw-edma-v0-core.c    | 348 ++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-core.h    |  28 +
 drivers/dma/dw-edma/dw-edma-v0-debugfs.c | 361 ++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-debugfs.h |  28 +
 drivers/dma/dw-edma/dw-edma-v0-regs.h    | 158 ++++++
 drivers/misc/pci_endpoint_test.c         |   2 +-
 include/linux/dma/edma.h                 |  47 ++
 include/linux/pci_ids.h                  |   1 +
 16 files changed, 2321 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/dw-edma/Kconfig
 create mode 100644 drivers/dma/dw-edma/Makefile
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-pcie.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-regs.h
 create mode 100644 include/linux/dma/edma.h
Cc Vinod Koul <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Kishon Vijay Abraham I <[email protected]>
Cc Joao Pinto <[email protected]>
Signature · 1 line
2.7.4
#14 lore raw

RE: [RFC v6 0/6] dmaengine: Add Synopsys eDMA IP driver (version 0)

Hi all,

An gentle reminder...

Thanks.

Quoted 63 lines · Gustavo Pimentel

Add Synopsys eDMA IP driver (version 0 and for EP side only) to Linux kernel. This IP is generally distributed with Synopsys PCIe EndPoint IP (depends of the use and licensing agreement), which supports:
- legacy and unroll modes
- 16 independent and concurrent channels (8 write + 8 read)
- supports linked list (scatter-gather) transfer
- each linked list descriptor can transfer from 1 byte to 4 Gbytes
- supports cyclic transfer
- PCIe EndPoint glue-logic

This patch series contains:
- eDMA core + eDMA core v0 driver (implements the interface with DMAengine controller APIs and interfaces with eDMA HW block)
- eDMA PCIe glue-logic reference driver (attaches to Synopsys EP and provides memory access to eDMA core driver)

Gustavo Pimentel (6):
dmaengine: Add Synopsys eDMA IP core driver
dmaengine: Add Synopsys eDMA IP version 0 support
dmaengine: Add Synopsys eDMA IP version 0 debugfs support
PCI: Add Synopsys endpoint EDDA Device ID
dmaengine: Add Synopsys eDMA IP PCIe glue-logic
MAINTAINERS: Add Synopsys eDMA IP driver maintainer

 MAINTAINERS                              |   7 +
 drivers/dma/Kconfig                      |   2 +
 drivers/dma/Makefile                     |   1 +
 drivers/dma/dw-edma/Kconfig              |  18 +
 drivers/dma/dw-edma/Makefile             |   7 +
 drivers/dma/dw-edma/dw-edma-core.c       | 920 +++++++++++++++++++++++++++++++
 drivers/dma/dw-edma/dw-edma-core.h       | 165 ++++++
 drivers/dma/dw-edma/dw-edma-pcie.c       | 229 ++++++++
 drivers/dma/dw-edma/dw-edma-v0-core.c    | 348 ++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-core.h    |  28 +
 drivers/dma/dw-edma/dw-edma-v0-debugfs.c | 361 ++++++++++++
 drivers/dma/dw-edma/dw-edma-v0-debugfs.h |  28 +
 drivers/dma/dw-edma/dw-edma-v0-regs.h    | 158 ++++++
 drivers/misc/pci_endpoint_test.c         |   2 +-
 include/linux/dma/edma.h                 |  47 ++
 include/linux/pci_ids.h                  |   1 +
 16 files changed, 2321 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/dw-edma/Kconfig
 create mode 100644 drivers/dma/dw-edma/Makefile
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-core.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-pcie.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-core.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.c
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-debugfs.h
 create mode 100644 drivers/dma/dw-edma/dw-edma-v0-regs.h
 create mode 100644 include/linux/dma/edma.h
Cc Vinod Koul <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Kishon Vijay Abraham I <[email protected]>
Cc Joao Pinto <[email protected]>
Signature · 1 line
2.7.4