Skip to contentSkip to conversation

dmaengine: APM X-Gene SoC DMA engine driver support

PATCH Superseded Rameshwar Prasad Sahu 2 participants 9 messages Feb 3, 2015 – Feb 11, 2015

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover dmaengine: APM X-Gene SoC DMA engine driver support

This patch set implements the APM X-Gene SoC DMA driver support to offload the DMA operations such as memory copy(memcpy), scatter gathering.

v5 changes:
1. Minor changes in coding style.
2. Added DMA_CTRL_ACK flag initialization
v4 changes:
1. Fixed dma-ranges property on DTS.

---

Rameshwar Prasad Sahu (3):
dmaengine: Add support for APM X-Gene SoC DMA engine driver
arm64: dts: Add APM X-Gene DMA device and DMA clock DTS nodes
Documentation: dma: Add APM X-Gene SoC DMA engine driver documentation

 .../devicetree/bindings/dma/apm-xgene-dma.txt      |   49 +
 arch/arm64/boot/dts/apm/apm-storm.dtsi             |   26 +
 drivers/dma/Kconfig                                |    8 +
 drivers/dma/Makefile                               |    1 +
 drivers/dma/xgene-dma.c                            | 1597 ++++++++++++++++++++
 5 files changed, 1681 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/apm-xgene-dma.txt
 create mode 100755 drivers/dma/xgene-dma.c

--
1.8.2.1

#1 lore raw

PATCH v5 1/3 dmaengine: Add support for APM X-Gene SoC DMA engine driver

This patch implements the APM X-Gene SoC DMA engine driver. The APM X-Gene SoC DMA engine consists of 4 DMA channels for performing DMA operations. These DMA operations include memory copy and scatter gathering offload.

---
 drivers/dma/Kconfig     |    8 +
 drivers/dma/Makefile    |    1 +
 drivers/dma/xgene-dma.c | 1597 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1606 insertions(+)
 create mode 100755 drivers/dma/xgene-dma.c
drivers/dma/Kconfig +8 -0
index f2b2c4e..251ce60 100644
@@ -416,6 +416,14 @@ config NBPFAXI_DMA
 	help
 	  Support for "Type-AXI" NBPF DMA IPs from Renesas
 
+config XGENE_DMA
+	tristate "APM X-Gene DMA support"
+	depends on ARCH_XGENE
+	select DMA_ENGINE
+	select ASYNC_TX_ENABLE_CHANNEL_SWITCH
+	help
+	  Enable support for the APM X-Gene SoC DMA engine.
+
 config DMA_ENGINE
 	bool
 
drivers/dma/Makefile +1 -0
index 2022b54..0567e69 100644
@@ -50,3 +50,4 @@ obj-y += xilinx/
 obj-$(CONFIG_INTEL_MIC_X100_DMA) += mic_x100_dma.o
 obj-$(CONFIG_NBPFAXI_DMA) += nbpfaxi.o
 obj-$(CONFIG_DMA_SUN6I) += sun6i-dma.o
+obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
drivers/dma/xgene-dma.c new file +1597 -0

1,597 lines not on this page · raw message

--
1.8.2.1

#2 lore raw

Re: [PATCH v5 1/3] dmaengine: Add support for APM X-Gene SoC DMA engine driver

Quoted 3 lines · Rameshwar Prasad Sahu

+/* Applied Micro X-Gene SoC DMA engine Driver
+ *
+ * Copyright (c) 2014, Applied Micro Circuits Corporation

not 2015?

Quoted 34 lines

+ * Authors: Rameshwar Prasad Sahu <[email protected]>
+ * Loc Ho <[email protected]>
+ *

drivers/dma/xgene-dma.c new file +30 -0
+/* DMA ring csr registers and bit definations */
+#define RING_CONFIG		0x04
+#define RING_ENABLE		BIT(31)
+#define RING_ID			0x08
+#define RING_ID_SETUP(v)	((v) | BIT(31))
+#define RING_ID_BUF		0x0C
+#define RING_ID_BUF_SETUP(v)	(((v) << 9) | BIT(21))
+#define RING_THRESLD0_SET1	0x30
+#define RING_THRESLD0_SET1_VAL	0X64
+#define RING_THRESLD1_SET1	0x34
+#define RING_THRESLD1_SET1_VAL	0xC8
+#define RING_HYSTERESIS		0x68
+#define RING_HYSTERESIS_VAL	0xFFFFFFFF
+#define RING_STATE		0x6C
+#define RING_STATE_WR_BASE	0x70
+#define RING_NE_INT_MODE	0x017C
+#define RING_NE_INT_MODE_SET(m, v)	\
+	((m) = ((m) & ~BIT(31 - (v))) | BIT(31 - (v)))
+#define RING_NE_INT_MODE_RESET(m, v)	\
+	((m) &= (~BIT(31 - (v))))
+#define RING_CLKEN		0xC208
+#define RING_SRST		0xC200
+#define RING_MEM_RAM_SHUTDOWN	0xD070
+#define RING_BLK_MEM_RDY	0xD074
+#define RING_BLK_MEM_RDY_VAL	0xFFFFFFFF
+#define RING_ID_GET(owner, num)	(((owner) << 6) | (num))
+#define RING_DST_RING_ID(v)	((1 << 10) | (v))
+#define RING_CMD_OFFSET(v)	(((v) << 6) + 0x2C)
+#define RING_COHERENT_SET(m)	(((u32 *)(m))[2] |= BIT(4))
+#define RING_ADDRL_SET(m, v)	(((u32 *)(m))[2] |= (((v) >> 8) << 5))

drivers/dma/xgene-dma.c

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+#define RING_ADDRH_SET(m, v)	(((u32 *)(m))[3] |= ((v) >> 35))
+#define RING_ACCEPTLERR_SET(m)	(((u32 *)(m))[3] |= BIT(19))
+#define RING_SIZE_SET(m, v)	(((u32 *)(m))[3] |= ((v) << 23))
+#define RING_RECOMBBUF_SET(m)	(((u32 *)(m))[3] |= BIT(27))
+#define RING_RECOMTIMEOUTL_SET(m)	\
+	(((u32 *)(m))[3] |= (0x7 << 28))
+#define RING_RECOMTIMEOUTH_SET(m)	\
+	(((u32 *)(m))[4] |= 0x3)
+#define RING_SELTHRSH_SET(m)	(((u32 *)(m))[4] |= BIT(3))
+#define RING_TYPE_SET(m, v)	(((u32 *)(m))[4] |= ((v) << 19))a

these defines and the ones which follow need to be namespace aptly

Quoted 1 line

+static void xgene_dma_cpu_to_le64(u64 *desc, int count)

why is this endian specific?

drivers/dma/xgene-dma.c line 431

Quoted 13 lines
drivers/dma/xgene-dma.c new file +13 -0
+
+static irqreturn_t xgene_dma_ring_isr(int irq, void *id)
+{
+	struct xgene_dma_chan *chan = (struct xgene_dma_chan *)id;
+
+	BUG_ON(!chan);
+
+	/* Disable DMA channel IRQ */
+	disable_irq_nosync(chan->rx_irq);
+
+	/* Schedule tasklet */
+	tasklet_schedule(&chan->rx_tasklet);
+

Ideally you should submit next txn here, but...

Quoted 5 lines
drivers/dma/xgene-dma.c new file +5 -0
+
+static int xgene_dma_alloc_chan_resources(struct dma_chan *channel)
+{
+	struct xgene_dma_chan *chan = to_xgene_dma_chan(channel);
+	int i;

drivers/dma/xgene-dma.c line 806

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+
+	/* Check if we have already allcated resources */
+	if (chan->slots)
+		return DMA_SLOT_PER_CHANNEL;
+
+	spin_lock_bh(&chan->lock);
+
+	chan->slots = devm_kzalloc(chan->pdma->dev,
+				   sizeof(struct xgene_dma_slot) *
+				   DMA_SLOT_PER_CHANNEL, GFP_ATOMIC);

GFP_NOWAIT pls

drivers/dma/xgene-dma.c line 863

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+
+static enum dma_status xgene_dma_tx_status(struct dma_chan *channel,
+					   dma_cookie_t cookie,
+					   struct dma_tx_state *txstate)
+{
+	return dma_cookie_status(channel, cookie, txstate);

why no residue calculation

drivers/dma/xgene-dma.c line 869

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+}
+
+static void xgene_dma_issue_pending(struct dma_chan *channel)
+{
+	/* Nothing to do */
+}

What do you mean by nothing to do here
See Documentation/dmaengine/client.txt Section 4 & 5

Quoted 14 lines
drivers/dma/xgene-dma.c new file +14 -0
+static dma_cookie_t xgene_dma_tx_memcpy_submit(
+	struct dma_async_tx_descriptor *tx)
+{
+	struct xgene_dma_chan *chan = to_xgene_dma_chan(tx->chan);
+	struct xgene_dma_slot *slot = to_xgene_dma_slot(tx);
+	dma_addr_t dst = slot->dst;
+	dma_addr_t src = slot->src;
+	size_t len = slot->len;
+	size_t copy;
+	dma_cookie_t cookie;
+
+	spin_lock_bh(&chan->lock);
+
+	chan->tx_cmd = 0;

drivers/dma/xgene-dma.c line 1040

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+	slot->desc_cnt = 0;
+
+	/* Run until we are out of length */
+	do {
+		/* Create the largest transaction possible */
+		copy = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+
+		/* Prepare DMA descriptor */
+		xgene_dma_prep_cpy_desc(chan, slot, dst, src, copy);
+

This is wrong. The descriptor is supposed to be already prepared and now it has to be submitted to queue

Quoted 30 lines
drivers/dma/xgene-dma.c new file +30 -0
+static struct dma_async_tx_descriptor *xgene_dma_prep_memcpy(
+	struct dma_chan *channel, dma_addr_t dst, dma_addr_t src,
+	size_t len, unsigned long flags)
+{
+	struct xgene_dma_chan *chan = to_xgene_dma_chan(channel);
+	struct xgene_dma_slot *slot;
+
+	/* Sanity check */
+	BUG_ON(len > DMA_MAX_MEMCPY_BYTE_CNT);
+
+	spin_lock_bh(&chan->lock);
+
+	slot = xgene_dma_get_channel_slot(chan);
+	if (!slot) {
+		spin_unlock_bh(&chan->lock);
+		return NULL;
+	}
+
+	dev_dbg(chan->pdma->dev,
+		"MEMCPY channel %d slot %d len 0x%zX dst 0x%llX src 0x%llX\n",
+		chan->index, slot->index, len, dst, src);
+
+	/* Setup slot variables */
+	slot->flags = FLAG_SLOT_IN_USE;
+	slot->txd.flags = flags;
+	slot->txd.tx_submit = xgene_dma_tx_memcpy_submit;
+
+	/*
+	 * Due to the race in tx_submit call from the client,
+	 * need to serialize the submission of H/W DMA descriptors.

drivers/dma/xgene-dma.c line 1099

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+	 * So make shadow copy to prepare DMA descriptor during
+	 * tx_submit call.
+	 */
+	slot->dst = dst;
+	slot->src = src;
+	slot->len = len;
+
+	spin_unlock_bh(&chan->lock);
+
+	return &slot->txd;

Nope, you are supposed to allocate and populate a descriptor here

Quoted 29 lines
drivers/dma/xgene-dma.c new file +29 -0
+}
+
+static dma_cookie_t xgene_dma_tx_sgcpy_submit(
+	struct dma_async_tx_descriptor *tx)
+{
+	struct xgene_dma_chan *chan = to_xgene_dma_chan(tx->chan);
+	struct xgene_dma_slot *slot = to_xgene_dma_slot(tx);
+	struct scatterlist *dst_sg, *src_sg;
+	size_t dst_avail, src_avail;
+	dma_addr_t dst, src;
+	size_t len;
+	dma_cookie_t cookie;
+	size_t nbytes  = slot->len;
+
+	spin_lock_bh(&chan->lock);
+
+	dst_sg = slot->srcdst_list + slot->src_nents;
+	src_sg = slot->srcdst_list;
+
+	chan->tx_cmd = 0;
+	slot->desc_cnt = 0;
+
+	/* Get prepared for the loop */
+	dst_avail = sg_dma_len(dst_sg);
+	src_avail = sg_dma_len(src_sg);
+
+	/* Run until we are out of length */
+	do {
+		/* Create the largest transaction possible */

drivers/dma/xgene-dma.c line 1138

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+		len = min_t(size_t, src_avail, dst_avail);
+		len = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+		if (len == 0)
+			goto fetch;
+
+		dst = sg_dma_address(dst_sg) + sg_dma_len(dst_sg) - dst_avail;
+		src = sg_dma_address(src_sg) + sg_dma_len(src_sg) - src_avail;
+
+		/* Prepare DMA descriptor */
+		xgene_dma_prep_cpy_desc(chan, slot, dst, src, len);

again this wrong, also you should ideally have single submit. Why does it have to be transfer type dependent.

Quoted 13 lines
drivers/dma/xgene-dma.c new file +13 -0
+
+static void xgene_dma_set_caps(struct xgene_dma_chan *chan,
+			       struct dma_device *dma_dev)
+{
+	/* Initialize DMA device capability mask */
+	dma_cap_zero(dma_dev->cap_mask);
+
+	/* Set DMA device capability */
+	dma_cap_set(DMA_MEMCPY, dma_dev->cap_mask);
+	dma_cap_set(DMA_SG, dma_dev->cap_mask);
+
+	/* Set base and prep routines */
+	dma_dev->dev = chan->pdma->dev;

drivers/dma/xgene-dma.c line 1286

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+	dma_dev->device_alloc_chan_resources = xgene_dma_alloc_chan_resources;
+	dma_dev->device_free_chan_resources = xgene_dma_free_chan_resources;
+	dma_dev->device_issue_pending = xgene_dma_issue_pending;
+	dma_dev->device_tx_status = xgene_dma_tx_status;
+
+	if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
+		dma_dev->device_prep_dma_memcpy = xgene_dma_prep_memcpy;
+
+	if (dma_has_cap(DMA_SG, dma_dev->cap_mask))
+		dma_dev->device_prep_dma_sg = xgene_dma_prep_sg;

these two if conditions dont make any sense

Quoted 4 lines
drivers/dma/xgene-dma.c new file +4 -0
+static int xgene_dma_runtime_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct xgene_dma *pdma = platform_get_drvdata(pdev);

drivers/dma/xgene-dma.c line 1447

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+	int ret;
+
+	ret = clk_prepare_enable(pdma->dma_clk);
+	if (ret) {
+		dev_err(dev, "Failed to enable clk %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}

This should be under runtime pm flag. people can run kernels with these disabled

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+
+static int xgene_dma_remove(struct platform_device *pdev)
+{
+	struct xgene_dma *pdma = platform_get_drvdata(pdev);
+	struct xgene_dma_chan *chan;
+	int i;

drivers/dma/xgene-dma.c line 1555

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+
+	for (i = 0; i < DMA_MAX_CHANNEL; i++) {
+		chan = &pdma->channels[i];
+
+		/* Delete DMA ring descriptors */
+		xgene_dma_delete_chan_rings(chan);
+
+		/* Kill the DMA channel tasklet */
+		tasklet_kill(&chan->rx_tasklet);
+

But your irq is still active and can be triggered!

drivers/dma/xgene-dma.c line 1565

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+		/* Unregister DMA device */
+		dma_async_device_unregister(&pdma->dma_dev[i]);
+	}
+
+	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		xgene_dma_runtime_suspend(&pdev->dev);
+
+	return 0;
+}

Okay we need some good work here. First cleanup the usage of dmaengine APIs. Second I would like to see cookie management and descriptor management cleaned by using helpers available

Signature · 1 line
~Vinod
#3 lore raw

Re: [PATCH v5 1/3] dmaengine: Add support for APM X-Gene SoC DMA engine driver

Hi Vinod,

Thanks for reviewing this patch.

Please see inline......

Thanks,
with regards,
Ram

Quoted 42 lines · Vinod Koul
Quoted 3 lines · Rameshwar Prasad Sahu

+/* Applied Micro X-Gene SoC DMA engine Driver
+ *
+ * Copyright (c) 2014, Applied Micro Circuits Corporation

not 2015?

Quoted 37 lines

+ * Authors: Rameshwar Prasad Sahu <[email protected]>
+ * Loc Ho <[email protected]>
+ *

drivers/dma/xgene-dma.c new file +33 -0
+/* DMA ring csr registers and bit definations */
+#define RING_CONFIG          0x04
+#define RING_ENABLE          BIT(31)
+#define RING_ID                      0x08
+#define RING_ID_SETUP(v)     ((v) | BIT(31))
+#define RING_ID_BUF          0x0C
+#define RING_ID_BUF_SETUP(v) (((v) << 9) | BIT(21))
+#define RING_THRESLD0_SET1   0x30
+#define RING_THRESLD0_SET1_VAL       0X64
+#define RING_THRESLD1_SET1   0x34
+#define RING_THRESLD1_SET1_VAL       0xC8
+#define RING_HYSTERESIS              0x68
+#define RING_HYSTERESIS_VAL  0xFFFFFFFF
+#define RING_STATE           0x6C
+#define RING_STATE_WR_BASE   0x70
+#define RING_NE_INT_MODE     0x017C
+#define RING_NE_INT_MODE_SET(m, v)   \
+     ((m) = ((m) & ~BIT(31 - (v))) | BIT(31 - (v)))
+#define RING_NE_INT_MODE_RESET(m, v) \
+     ((m) &= (~BIT(31 - (v))))
+#define RING_CLKEN           0xC208
+#define RING_SRST            0xC200
+#define RING_MEM_RAM_SHUTDOWN        0xD070
+#define RING_BLK_MEM_RDY     0xD074
+#define RING_BLK_MEM_RDY_VAL 0xFFFFFFFF
+#define RING_ID_GET(owner, num)      (((owner) << 6) | (num))
+#define RING_DST_RING_ID(v)  ((1 << 10) | (v))
+#define RING_CMD_OFFSET(v)   (((v) << 6) + 0x2C)
+#define RING_COHERENT_SET(m) (((u32 *)(m))[2] |= BIT(4))
+#define RING_ADDRL_SET(m, v) (((u32 *)(m))[2] |= (((v) >> 8) << 5))
+#define RING_ADDRH_SET(m, v) (((u32 *)(m))[3] |= ((v) >> 35))
+#define RING_ACCEPTLERR_SET(m)       (((u32 *)(m))[3] |= BIT(19))
+#define RING_SIZE_SET(m, v)  (((u32 *)(m))[3] |= ((v) << 23))
Quoted 9 lines

drivers/dma/xgene-dma.c

Quoted 7 lines
drivers/dma/xgene-dma.c new file +7 -0
+#define RING_RECOMBBUF_SET(m)        (((u32 *)(m))[3] |= BIT(27))
+#define RING_RECOMTIMEOUTL_SET(m)    \
+     (((u32 *)(m))[3] |= (0x7 << 28))
+#define RING_RECOMTIMEOUTH_SET(m)    \
+     (((u32 *)(m))[4] |= 0x3)
+#define RING_SELTHRSH_SET(m) (((u32 *)(m))[4] |= BIT(3))
+#define RING_TYPE_SET(m, v)  (((u32 *)(m))[4] |= ((v) << 19))a

these defines and the ones which follow need to be namespace aptly

Okay..

Quoted 2 lines
Quoted 1 line

+static void xgene_dma_cpu_to_le64(u64 *desc, int count)

why is this endian specific?

Our cpu supports both little endian and big endian,
Our DMA hw engine is little endian, so DMA engine descriptor needs to be in little endian format .

Quoted 15 lines
Quoted 4 lines
drivers/dma/xgene-dma.c new file +3 -0
+
+static irqreturn_t xgene_dma_ring_isr(int irq, void *id)
+{

drivers/dma/xgene-dma.c line 431

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+     struct xgene_dma_chan *chan = (struct xgene_dma_chan *)id;
+
+     BUG_ON(!chan);
+
+     /* Disable DMA channel IRQ */
+     disable_irq_nosync(chan->rx_irq);
+
+     /* Schedule tasklet */
+     tasklet_schedule(&chan->rx_tasklet);
+

Ideally you should submit next txn here, but...

Already we have pushed prepared descriptor to engine, so here this is just rx path to get completion interrupt.

Quoted 17 lines
Quoted 6 lines
drivers/dma/xgene-dma.c new file +5 -0
+
+static int xgene_dma_alloc_chan_resources(struct dma_chan *channel)
+{
+     struct xgene_dma_chan *chan = to_xgene_dma_chan(channel);
+     int i;

drivers/dma/xgene-dma.c line 806

Quoted 10 lines
drivers/dma/xgene-dma.c new file +10 -0
+
+     /* Check if we have already allcated resources */
+     if (chan->slots)
+             return DMA_SLOT_PER_CHANNEL;
+
+     spin_lock_bh(&chan->lock);
+
+     chan->slots = devm_kzalloc(chan->pdma->dev,
+                                sizeof(struct xgene_dma_slot) *
+                                DMA_SLOT_PER_CHANNEL, GFP_ATOMIC);

GFP_NOWAIT pls

Okay GFP_KERNEL should also be ok ?

Quoted 8 lines

drivers/dma/xgene-dma.c line 863

Quoted 7 lines
drivers/dma/xgene-dma.c new file +6 -0
+
+static enum dma_status xgene_dma_tx_status(struct dma_chan *channel,
+                                        dma_cookie_t cookie,
+                                        struct dma_tx_state *txstate)
+{
+     return dma_cookie_status(channel, cookie, txstate);

why no residue calculation

We don't have way to pause, resume or stop DMA operation in DMA engine hw once we have submitted descriptor to engine. While prep routine we have prepared descriptor for whole requested length, so no need to calculate residue.

Quoted 9 lines

drivers/dma/xgene-dma.c line 869

Quoted 7 lines
drivers/dma/xgene-dma.c new file +6 -0
+}
+
+static void xgene_dma_issue_pending(struct dma_chan *channel)
+{
+     /* Nothing to do */
+}

What do you mean by nothing to do here
See Documentation/dmaengine/client.txt Section 4 & 5

This docs is only applicable on slave DMA operations, we don't support slave DMA, it's only master.
Our hw engine is designed in the way that there is no scope of flushing pending transaction explicitly by sw.
We have circular ring descriptor dedicated to engine. In submit callback we are queuing descriptor and informing to engine, so after this it's internal to hw to execute descriptor one by one.

Quoted 20 lines
Quoted 20 lines
drivers/dma/xgene-dma.c new file +18 -0
+static dma_cookie_t xgene_dma_tx_memcpy_submit(
+     struct dma_async_tx_descriptor *tx)
+{
+     struct xgene_dma_chan *chan = to_xgene_dma_chan(tx->chan);
+     struct xgene_dma_slot *slot = to_xgene_dma_slot(tx);
+     dma_addr_t dst = slot->dst;
+     dma_addr_t src = slot->src;
+     size_t len = slot->len;
+     size_t copy;
+     dma_cookie_t cookie;
+
+     spin_lock_bh(&chan->lock);
+
+     chan->tx_cmd = 0;
+     slot->desc_cnt = 0;
+
+     /* Run until we are out of length */
+     do {
Quoted 8 lines

drivers/dma/xgene-dma.c line 1040

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+             /* Create the largest transaction possible */
+             copy = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+
+             /* Prepare DMA descriptor */
+             xgene_dma_prep_cpy_desc(chan, slot, dst, src, copy);
+

This is wrong. The descriptor is supposed to be already prepared and now it has to be submitted to queue

Due to the race in tx_submit call from the client, need to serialize the submission of H/W DMA descriptors.
So we are making shadow copy in prepare DMA routine and preparing
actual descriptor during tx_submit call.

Quoted 35 lines
Quoted 35 lines
drivers/dma/xgene-dma.c new file +33 -0
+static struct dma_async_tx_descriptor *xgene_dma_prep_memcpy(
+     struct dma_chan *channel, dma_addr_t dst, dma_addr_t src,
+     size_t len, unsigned long flags)
+{
+     struct xgene_dma_chan *chan = to_xgene_dma_chan(channel);
+     struct xgene_dma_slot *slot;
+
+     /* Sanity check */
+     BUG_ON(len > DMA_MAX_MEMCPY_BYTE_CNT);
+
+     spin_lock_bh(&chan->lock);
+
+     slot = xgene_dma_get_channel_slot(chan);
+     if (!slot) {
+             spin_unlock_bh(&chan->lock);
+             return NULL;
+     }
+
+     dev_dbg(chan->pdma->dev,
+             "MEMCPY channel %d slot %d len 0x%zX dst 0x%llX src 0x%llX\n",
+             chan->index, slot->index, len, dst, src);
+
+     /* Setup slot variables */
+     slot->flags = FLAG_SLOT_IN_USE;
+     slot->txd.flags = flags;
+     slot->txd.tx_submit = xgene_dma_tx_memcpy_submit;
+
+     /*
+      * Due to the race in tx_submit call from the client,
+      * need to serialize the submission of H/W DMA descriptors.
+      * So make shadow copy to prepare DMA descriptor during
+      * tx_submit call.
+      */
Quoted 8 lines

drivers/dma/xgene-dma.c line 1099

Quoted 7 lines
drivers/dma/xgene-dma.c new file +7 -0
+     slot->dst = dst;
+     slot->src = src;
+     slot->len = len;
+
+     spin_unlock_bh(&chan->lock);
+
+     return &slot->txd;

Nope, you are supposed to allocate and populate a descriptor here

We have already allocated chan resources during alloc_chan_resource callback. Can you please elaborate more what do you want.

Quoted 33 lines
Quoted 33 lines
drivers/dma/xgene-dma.c new file +33 -0
+}
+
+static dma_cookie_t xgene_dma_tx_sgcpy_submit(
+     struct dma_async_tx_descriptor *tx)
+{
+     struct xgene_dma_chan *chan = to_xgene_dma_chan(tx->chan);
+     struct xgene_dma_slot *slot = to_xgene_dma_slot(tx);
+     struct scatterlist *dst_sg, *src_sg;
+     size_t dst_avail, src_avail;
+     dma_addr_t dst, src;
+     size_t len;
+     dma_cookie_t cookie;
+     size_t nbytes  = slot->len;
+
+     spin_lock_bh(&chan->lock);
+
+     dst_sg = slot->srcdst_list + slot->src_nents;
+     src_sg = slot->srcdst_list;
+
+     chan->tx_cmd = 0;
+     slot->desc_cnt = 0;
+
+     /* Get prepared for the loop */
+     dst_avail = sg_dma_len(dst_sg);
+     src_avail = sg_dma_len(src_sg);
+
+     /* Run until we are out of length */
+     do {
+             /* Create the largest transaction possible */
+             len = min_t(size_t, src_avail, dst_avail);
+             len = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+             if (len == 0)
+                     goto fetch;
Quoted 8 lines

drivers/dma/xgene-dma.c line 1138

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+
+             dst = sg_dma_address(dst_sg) + sg_dma_len(dst_sg) - dst_avail;
+             src = sg_dma_address(src_sg) + sg_dma_len(src_sg) - src_avail;
+
+             /* Prepare DMA descriptor */
+             xgene_dma_prep_cpy_desc(chan, slot, dst, src, len);

again this wrong, also you should ideally have single submit. Why does it have to be transfer type dependent.

Please refer my above shadowcopy comments.

Quoted 17 lines
Quoted 17 lines
drivers/dma/xgene-dma.c new file +16 -0
+
+static void xgene_dma_set_caps(struct xgene_dma_chan *chan,
+                            struct dma_device *dma_dev)
+{
+     /* Initialize DMA device capability mask */
+     dma_cap_zero(dma_dev->cap_mask);
+
+     /* Set DMA device capability */
+     dma_cap_set(DMA_MEMCPY, dma_dev->cap_mask);
+     dma_cap_set(DMA_SG, dma_dev->cap_mask);
+
+     /* Set base and prep routines */
+     dma_dev->dev = chan->pdma->dev;
+     dma_dev->device_alloc_chan_resources = xgene_dma_alloc_chan_resources;
+     dma_dev->device_free_chan_resources = xgene_dma_free_chan_resources;
+     dma_dev->device_issue_pending = xgene_dma_issue_pending;
Quoted 8 lines

drivers/dma/xgene-dma.c line 1286

Quoted 7 lines
drivers/dma/xgene-dma.c new file +7 -0
+     dma_dev->device_tx_status = xgene_dma_tx_status;
+
+     if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
+             dma_dev->device_prep_dma_memcpy = xgene_dma_prep_memcpy;
+
+     if (dma_has_cap(DMA_SG, dma_dev->cap_mask))
+             dma_dev->device_prep_dma_sg = xgene_dma_prep_sg;

these two if conditions dont make any sense

Okay..

Quoted 8 lines
Quoted 8 lines
drivers/dma/xgene-dma.c new file +8 -0
+static int xgene_dma_runtime_resume(struct device *dev)
+{
+     struct platform_device *pdev = to_platform_device(dev);
+     struct xgene_dma *pdma = platform_get_drvdata(pdev);
+     int ret;
+
+     ret = clk_prepare_enable(pdma->dma_clk);
+     if (ret) {
Quoted 8 lines

drivers/dma/xgene-dma.c line 1447

Quoted 6 lines
drivers/dma/xgene-dma.c new file +6 -0
+             dev_err(dev, "Failed to enable clk %d\n", ret);
+             return ret;
+     }
+
+     return 0;
+}

This should be under runtime pm flag. people can run kernels with these disabled

Okay..

Quoted 10 lines
Quoted 10 lines
drivers/dma/xgene-dma.c new file +9 -0
+
+static int xgene_dma_remove(struct platform_device *pdev)
+{
+     struct xgene_dma *pdma = platform_get_drvdata(pdev);
+     struct xgene_dma_chan *chan;
+     int i;
+
+     for (i = 0; i < DMA_MAX_CHANNEL; i++) {
+             chan = &pdma->channels[i];
Quoted 8 lines

drivers/dma/xgene-dma.c line 1555

Quoted 7 lines
drivers/dma/xgene-dma.c new file +7 -0
+
+             /* Delete DMA ring descriptors */
+             xgene_dma_delete_chan_rings(chan);
+
+             /* Kill the DMA channel tasklet */
+             tasklet_kill(&chan->rx_tasklet);
+

But your irq is still active and can be triggered!

Okay I will change accordingly

Quoted 14 lines

drivers/dma/xgene-dma.c line 1565

Quoted 11 lines
drivers/dma/xgene-dma.c new file +10 -0
+             /* Unregister DMA device */
+             dma_async_device_unregister(&pdma->dma_dev[i]);
+     }
+
+     pm_runtime_disable(&pdev->dev);
+     if (!pm_runtime_status_suspended(&pdev->dev))
+             xgene_dma_runtime_suspend(&pdev->dev);
+
+     return 0;
+}

Okay we need some good work here. First cleanup the usage of dmaengine APIs. Second I would like to see cookie management and descriptor management cleaned by using helpers available

Yes sure, I will your follow your comments for further cleanup.

Quoted 8 lines

--
~Vinod

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH v5 1/3] dmaengine: Add support for APM X-Gene SoC DMA engine driver

Quoted 5 lines · Rameshwar Sahu

Hi Vinod,

Thanks for reviewing this patch.

Please see inline......

Please STOP top posting

Quoted 9 lines
Quoted 9 lines

drivers/dma/xgene-dma.c line 869

Quoted 7 lines
drivers/dma/xgene-dma.c new file +6 -0
+}
+
+static void xgene_dma_issue_pending(struct dma_chan *channel)
+{
+     /* Nothing to do */
+}

What do you mean by nothing to do here
See Documentation/dmaengine/client.txt Section 4 & 5

Quoted 7 lines

This docs is only applicable on slave DMA operations, we don't support slave DMA, it's only master.
Our hw engine is designed in the way that there is no scope of flushing pending transaction explicitly by sw.
We have circular ring descriptor dedicated to engine. In submit callback we are queuing descriptor and informing to engine, so after this it's internal to hw to execute descriptor one by one.

But the API expectations on this are _same_

No the API expects you to maintain a SW queue, then push to your ring buffer when you get issue_pending. Issue pending is the start of data transfer, you client will expect accordingly.

Quoted 11 lines
Quoted 10 lines

drivers/dma/xgene-dma.c line 1040

Quoted 8 lines
drivers/dma/xgene-dma.c new file +8 -0
+     /* Run until we are out of length */
+     do {
+             /* Create the largest transaction possible */
+             copy = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+
+             /* Prepare DMA descriptor */
+             xgene_dma_prep_cpy_desc(chan, slot, dst, src, copy);
+

This is wrong. The descriptor is supposed to be already prepared and now it has to be submitted to queue

Quoted 4 lines

Due to the race in tx_submit call from the client, need to serialize the submission of H/W DMA descriptors.
So we are making shadow copy in prepare DMA routine and preparing
actual descriptor during tx_submit call.

Thats an abuse of API and I dont see a reason why this race should happen in the first place.

So you get a prep call, you prepare a desc in SW. Then submit pushes it to a queue. Finally in issue pending you push them to HW. Simple..?

Signature · 1 line
~Vinod
#5 lore raw

Re: [PATCH v5 1/3] dmaengine: Add support for APM X-Gene SoC DMA engine driver

Hi Vinod,

Quoted 24 lines · Vinod Koul
Quoted 5 lines · Rameshwar Sahu

Hi Vinod,

Thanks for reviewing this patch.

Please see inline......

Please STOP top posting

Quoted 9 lines
Quoted 9 lines

drivers/dma/xgene-dma.c line 869

Quoted 7 lines
drivers/dma/xgene-dma.c new file +6 -0
+}
+
+static void xgene_dma_issue_pending(struct dma_chan *channel)
+{
+     /* Nothing to do */
+}

What do you mean by nothing to do here
See Documentation/dmaengine/client.txt Section 4 & 5

Quoted 7 lines

This docs is only applicable on slave DMA operations, we don't support slave DMA, it's only master.
Our hw engine is designed in the way that there is no scope of flushing pending transaction explicitly by sw.
We have circular ring descriptor dedicated to engine. In submit callback we are queuing descriptor and informing to engine, so after this it's internal to hw to execute descriptor one by one.

Quoted 5 lines

But the API expectations on this are _same_

No the API expects you to maintain a SW queue, then push to your ring buffer when you get issue_pending. Issue pending is the start of data transfer, you client will expect accordingly.

Okay, I will maintain a sw queue, and will push sw descriptor to hw in this callback.

Quoted 16 lines
Quoted 12 lines
Quoted 11 lines

drivers/dma/xgene-dma.c line 1040

Quoted 9 lines
drivers/dma/xgene-dma.c new file +8 -0
+     /* Run until we are out of length */
+     do {
+             /* Create the largest transaction possible */
+             copy = min_t(size_t, len, DMA_MAX_64BDSC_BYTE_CNT);
+
+             /* Prepare DMA descriptor */
+             xgene_dma_prep_cpy_desc(chan, slot, dst, src, copy);
+

This is wrong. The descriptor is supposed to be already prepared and now it has to be submitted to queue

Quoted 4 lines

Due to the race in tx_submit call from the client, need to serialize the submission of H/W DMA descriptors.
So we are making shadow copy in prepare DMA routine and preparing
actual descriptor during tx_submit call.

Quoted 5 lines

Thats an abuse of API and I dont see a reason why this race should happen in the first place.

So you get a prep call, you prepare a desc in SW. Then submit pushes it to a queue. Finally in issue pending you push them to HW. Simple..?

I agree, I will do it and post another version soon.

Quoted 7 lines

--
~Vinod
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

PATCH v5 2/3 arm64: dts: Add APM X-Gene DMA device and DMA clock DTS nodes

In reply to Rameshwar Prasad Sahu

This patch adds the device tree node for APM X-Gene SoC DMA controller and DMA clock.

---
 arch/arm64/boot/dts/apm/apm-storm.dtsi | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
arch/arm64/boot/dts/apm/apm-storm.dtsi +26 -0
index f1ad9c2..5bf39f3 100644
@@ -102,6 +102,7 @@
 		#address-cells = <2>;
 		#size-cells = <2>;
 		ranges;
+		dma-ranges = <0x0 0x0 0x0 0x0 0x400 0x0>;
 
 		clocks {
 			#address-cells = <2>;
@@ -352,6 +353,15 @@
 				reg-names = "csr-reg";
 				clock-output-names = "pcie4clk";
 			};
+
+			dmaclk: dmaclk at 1f27c000 {
+				compatible = "apm,xgene-device-clock";
+				#clock-cells = <1>;
+				clocks = <&socplldiv2 0>;
+				reg = <0x0 0x1f27c000 0x0 0x1000>;
+				reg-names = "csr-reg";
+				clock-output-names = "dmaclk";
+			};
 		};
 
 		pcie0: pcie at 1f2b0000 {
@@ -656,5 +666,21 @@
 			interrupts = <0x0 0x41 0x4>;
 			clocks = <&rngpkaclk 0>;
 		};
+
+		dma: dma at 1f270000 {
+			compatible = "apm,xgene-dma";
+			device_type = "dma";
+			reg = <0x0 0x1f270000 0x0 0x10000>,
+			      <0x0 0x1f200000 0x0 0x10000>,
+			      <0x0 0x1b008000 0x0 0x2000>;
+			reg-names = "dma_csr", "ring_csr", "ring_cmd_csr";
+			interrupts = <0x0 0x82 0x4>,
+				     <0x0 0xb8 0x4>,
+				     <0x0 0xb9 0x4>,
+				     <0x0 0xba 0x4>,
+				     <0x0 0xbb 0x4>;
+			dma-coherent;
+			clocks = <&dmaclk 0>;
+		};
 	};
 };

--
1.8.2.1

#7 lore raw

PATCH v5 3/3 Documentation: dma: Add APM X-Gene SoC DMA engine driver documentation

In reply to Rameshwar Prasad Sahu

This patch adds device tree binding for APM X-Gene SoC DMA engine driver.

---
 .../devicetree/bindings/dma/apm-xgene-dma.txt      | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/apm-xgene-dma.txt
Documentation/devicetree/bindings/dma/apm-xgene-dma.txt new file +49 -0
new file mode 100644
index 0000000..cfbdcdb
@@ -0,0 +1,49 @@
+Applied Micro X-Gene SoC DMA nodes
+
+DMA nodes are defined to describe on-chip DMA interfaces in
+APM X-Gene SoC.
+
+Required properties for DMA interfaces:
+- compatible: Should be "apm,xgene-dma".
+- device_type: set to "dma".
+- reg: Address and length of the register set for the device.
+  It contains the information of registers in the same order
+  as described by reg-names.
+- reg-names: Should contain the register set names.
+  - "dma_csr": DMA control and status register address space.
+  - "ring_csr": Descriptor ring control and status register
+                address space.
+  - "ring_cmd_csr": Descriptor ring command register address space.
+- interrupts: DMA has 5 interrupts sources. 1st interrupt is
+  DMA error reporting interrupt. 2nd, 3rd, 4th and 5th interrupts
+  are completion interrupts for each DMA channels.
+- clocks: Reference to the clock entry.
+
+Optional properties:
+- dma-coherent : Present if dma operations are coherent
+
+Example:
+	dmaclk: dmaclk at 1f27c000 {
+		compatible = "apm,xgene-device-clock";
+		#clock-cells = <1>;
+		clocks = <&socplldiv2 0>;
+		reg = <0x0 0x1f27c000 0x0 0x1000>;
+		reg-names = "csr-reg";
+		clock-output-names = "dmaclk";
+	};
+
+	dma: dma at 1f270000 {
+		compatible = "apm,xgene-dma";
+		device_type = "dma";
+		reg = <0x0 0x1f270000 0x0 0x10000>,
+		      <0x0 0x1f200000 0x0 0x10000>,
+		      <0x0 0x1b008000 0x0 0x2000>;
+		reg-names = "dma_csr", "ring_csr", "ring_cmd_csr";
+		interrupts = <0x0 0xb8 0x4>,
+			     <0x0 0xb9 0x4>,
+			     <0x0 0xba 0x4>,
+			     <0x0 0xbb 0x4>,
+			     <0x0 0x82 0x4>;
+		dma-coherent;
+		clocks = <&dmaclk 0>;
+	};

--
1.8.2.1

#8 lore raw
In reply to Rameshwar Prasad Sahu

Hi Vinod,

Can you please review this patch set.

Thanks,
with regards,
Ram

Quoted 31 lines · Rameshwar Prasad Sahu

This patch set implements the APM X-Gene SoC DMA driver support to offload the DMA operations such as memory copy(memcpy), scatter gathering.

v5 changes:
1. Minor changes in coding style.
2. Added DMA_CTRL_ACK flag initialization
v4 changes:
1. Fixed dma-ranges property on DTS.

---

Rameshwar Prasad Sahu (3):
dmaengine: Add support for APM X-Gene SoC DMA engine driver
arm64: dts: Add APM X-Gene DMA device and DMA clock DTS nodes
Documentation: dma: Add APM X-Gene SoC DMA engine driver documentation

 .../devicetree/bindings/dma/apm-xgene-dma.txt      |   49 +
 arch/arm64/boot/dts/apm/apm-storm.dtsi             |   26 +
 drivers/dma/Kconfig                                |    8 +
 drivers/dma/Makefile                               |    1 +
 drivers/dma/xgene-dma.c                            | 1597 ++++++++++++++++++++
 5 files changed, 1681 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/apm-xgene-dma.txt
 create mode 100755 drivers/dma/xgene-dma.c

--
1.8.2.1