Skip to contentSkip to conversation

spi: qup: Add DMA capabilities

PATCH In review Andy Gross 4 participants 6 messages Jun 26, 2014 – Jul 2, 2014

Subsystems (3)
lore
Share & tools
lore

Andy Gross

author
#0 lore raw

PATCH 1/1 spi: qup: Add DMA capabilities

This patch adds DMA capabilities to the spi-qup driver. If DMA channels are present, the QUP will use DMA instead of block mode for transfers to/from SPI peripherals for transactions larger than the length of a block.

---
 .../devicetree/bindings/spi/qcom,spi-qup.txt       |   10 +
 drivers/spi/spi-qup.c                              |  361 ++++++++++++++++++--
 2 files changed, 350 insertions(+), 21 deletions(-)
Documentation/devicetree/bindings/spi/qcom,spi-qup.txt +10 -0
index b82a268..4d8977a 100644
@@ -23,6 +23,12 @@ Optional properties:
 - spi-max-frequency: Specifies maximum SPI clock frequency,
                      Units - Hz. Definition as per
                      Documentation/devicetree/bindings/spi/spi-bus.txt
+- dmas :             Two DMA channel specifiers following the convention outlined
+                     in bindings/dma/dma.txt
+- dma-names:         Names for the dma channels, if present. There must be at
+                     least one channel named "tx" for transmit and named "rx" for
+                     receive.
+
 
 SPI slave nodes must be children of the SPI master node and can contain
 properties described in Documentation/devicetree/bindings/spi/spi-bus.txt
@@ -41,6 +47,10 @@ Example:
 		clocks = <&gcc GCC_BLSP2_QUP2_SPI_APPS_CLK>, <&gcc GCC_BLSP2_AHB_CLK>;
 		clock-names = "core", "iface";
 
+		dmas = <&blsp2_bam 2>,
+			<&blsp2_bam 3>;
+		dma-names = "rx", "tx";
+
 		pinctrl-names = "default";
 		pinctrl-0 = <&spi8_default>;
 
drivers/spi/spi-qup.c +340 -21

455 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
maintainer
#1 lore raw

drivers/spi/spi-qup.c static void spi_qup_fifo_write(struct spi_qup *controller, · line 306

Quoted 3 lines · Andy Gross
drivers/spi/spi-qup.c +3 -0
+	if (xfer->rx_buf) {
+		rx_dma = dma_map_single(controller->dev, xfer->rx_buf,
+			xfer->len, DMA_FROM_DEVICE);

It would be better to use the core DMA mapping code rather than open
coding. This code won't work for vmalloc()ed addresses, or physically
non-contiguous addresses unless there's an IOMMU fixing things up.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140627/0c812691/attachment.sig>

author
#2 lore raw
Quoted 9 lines · Mark Brown

drivers/spi/spi-qup.c static void spi_qup_fifo_write(struct spi_qup *controller, · line 306

Quoted 3 lines · Andy Gross
drivers/spi/spi-qup.c +3 -0
+	if (xfer->rx_buf) {
+		rx_dma = dma_map_single(controller->dev, xfer->rx_buf,
+			xfer->len, DMA_FROM_DEVICE);

It would be better to use the core DMA mapping code rather than open coding. This code won't work for vmalloc()ed addresses, or physically non-contiguous addresses unless there's an IOMMU fixing things up.

Ah, ok. So I just need a to setup the scatter gather page list and then do a dma_map_sg. I'll resend once I have this in place.

Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#3 lore raw
Quoted 11 lines · Andy Gross
Quoted 9 lines · Mark Brown

drivers/spi/spi-qup.c static void spi_qup_fifo_write(struct spi_qup *controller, · line 306

Quoted 3 lines · Andy Gross
drivers/spi/spi-qup.c +3 -0
+	if (xfer->rx_buf) {
+		rx_dma = dma_map_single(controller->dev, xfer->rx_buf,
+			xfer->len, DMA_FROM_DEVICE);

It would be better to use the core DMA mapping code rather than open coding. This code won't work for vmalloc()ed addresses, or physically non-contiguous addresses unless there's an IOMMU fixing things up.

Quoted 2 lines

Ah, ok. So I just need a to setup the scatter gather page list and then do a dma_map_sg. I'll resend once I have this in place.

Note that DMA from vmalloc'd memory is non-coherent on some platforms, even if you use the DMA API.

The only thing that the DMA API guarantees is that the kernel mapping will be made coherent for DMA purposes. No other mapping has this guarantee.

Consider a VIVT cache (like the older ARMs). For this cache, you need to find every alias of a physical page and flush it. The DMA API doesn't have that information - it can only deal with the kernel's lowmem mapping.

We have introduced a couple of helpers recently to solve the problem of vmalloc() (since a number of filesystems now do this trick) but the vmalloc() user has to deal with the problem:

flush_kernel_vmap_range()
invalidate_kernel_vmap_range()

See the bottom of Documentation/cachetlb.txt for details.

The long and the short of it is that it's better if vmalloc()'d memory is avoided where possible. It's also loads better if subsystems pass physical references to memory for IO purposes where possible like our block layer does (iow, struct page + offset, length) rather than using randomly mapped virtual addresses, where the driver may not know where the memory has come from.

Signature · 2 lines
FTTC broadband for 0.8mile line: now at 9.7Mbps down 460kbps up... slowly
improving, and getting towards what was expected from it.
author
#4 lore raw

On Fri, Jun 27, 2014 at 05:24:11PM +0100, Russell King - ARM Linux wrote:

<snip>

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

It would be better to use the core DMA mapping code rather than open coding. This code won't work for vmalloc()ed addresses, or physically non-contiguous addresses unless there's an IOMMU fixing things up.

Ah, ok. So I just need a to setup the scatter gather page list and then do a dma_map_sg. I'll resend once I have this in place.

Note that DMA from vmalloc'd memory is non-coherent on some platforms, even if you use the DMA API.

Thankfully, that isn't the case on this platform. As as the QUP controller is only on Qualcomm chipsets, we don't have to worry about it being used on other platforms.

Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw
In reply to Andy Gross

Hi Andy,

Just few comments.

Quoted 10 lines · Andy Gross

This patch adds DMA capabilities to the spi-qup driver. If DMA channels are present, the QUP will use DMA instead of block mode for transfers to/from SPI peripherals for transactions larger than the length of a block.

---
 .../devicetree/bindings/spi/qcom,spi-qup.txt       |   10 +
 drivers/spi/spi-qup.c                              |  361 ++++++++++++++++++--
 2 files changed, 350 insertions(+), 21 deletions(-)

<snip>

Quoted 25 lines
drivers/spi/spi-qup.c +4 -0
index fc1de86..9b01db5 100644
@@ -22,6 +22,8 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/spi/spi.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
 
 #define QUP_CONFIG			0x0000
 #define QUP_STATE			0x0004
@@ -116,6 +118,8 @@
 
 #define SPI_NUM_CHIPSELECTS		4
 
+#define SPI_MAX_XFER			(SZ_64K - 64)
+
 /* high speed mode is when bus rate is greater then 26MHz */
 #define SPI_HS_MIN_RATE			26000000
 #define SPI_MAX_RATE			50000000
@@ -142,6 +146,17 @@ struct spi_qup {
 	int			w_size;	/* bytes per SPI word */
 	int			tx_bytes;

drivers/spi/spi-qup.c struct spi_qup { · line 157

Quoted 10 lines
drivers/spi/spi-qup.c +9 -0
 	int			rx_bytes;
+
+	int			use_dma;
+
+	struct dma_chan		*rx_chan;
+	struct dma_slave_config	rx_conf;
+	struct dma_chan		*tx_chan;
+	struct dma_slave_config tx_conf;
+	dma_addr_t		rx_dma;
+	dma_addr_t		tx_dma;

DMA addresses seems unused.

drivers/spi/spi-qup.c struct spi_qup { · line 158

Quoted 1 line
drivers/spi/spi-qup.c +1 -0
+	void			*dummy;

This is not so dummy, probably 'spare'.

Quoted 2 lines
drivers/spi/spi-qup.c +1 -0
+	atomic_t		dma_outstanding;
 };

<snip>

Quoted 5 lines
drivers/spi/spi-qup.c +0 -0
@@ -632,6 +896,56 @@ static int spi_qup_probe(struct platform_device *pdev)
 	writel_relaxed(SPI_ERROR_CLK_UNDER_RUN | SPI_ERROR_CLK_OVER_RUN,
 		       base + SPI_ERROR_FLAGS_EN);

drivers/spi/spi-qup.c static int spi_qup_probe(struct platform_device *pdev) · line 907

Quoted 10 lines
drivers/spi/spi-qup.c +9 -0
 
+	/* allocate dma resources, if available */
+	controller->rx_chan = dma_request_slave_channel(&pdev->dev, "rx");
+	if (controller->rx_chan) {
+		controller->tx_chan =
+			dma_request_slave_channel(&pdev->dev, "tx");
+
+		if (!controller->tx_chan) {
+			dev_err(&pdev->dev, "Failed to allocate dma tx chan");
+			dma_release_channel(controller->rx_chan);

There is no point to go further with DMA configuration if there are no channels, right?

drivers/spi/spi-qup.c static int spi_qup_probe(struct platform_device *pdev) · line 918

Quoted 11 lines
drivers/spi/spi-qup.c +11 -0
+		}
+
+		/* set DMA parameters */
+		controller->rx_conf.device_fc = 1;
+		controller->rx_conf.src_addr = res->start + QUP_INPUT_FIFO;
+		controller->rx_conf.src_maxburst = controller->in_blk_sz;
+
+		controller->tx_conf.device_fc = 1;
+		controller->tx_conf.dst_addr = res->start + QUP_OUTPUT_FIFO;
+		controller->tx_conf.dst_maxburst = controller->out_blk_sz;
+

Please, could you share blsp2_bam device node configuration? I would like to test these changes.

Regards,
Ivan