Skip to contentSkip to conversation

serial: fsl_lpuart: add eDMA support

PATCH Superseded Yuan Yao 3 participants 8 messages Jan 9, 2014 – Jan 13, 2014

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Yuan Yao

author
#0 lore raw

cover serial: fsl_lpuart: add eDMA support

Changed in v2:
- Add eDMA support for lpuart receive.
- Use dma_map_single in a right way.
- Use dma_mapping_error test dma_map_single.
- Change some names of variable.
- Fix some bugs.

Added in v1:
- Add device tree bindings for lupart eDMA support.
- Add eDMA support for lpuart send.

author
#1 lore raw

PATCH 1/2 ARM: dts: vf610: lpuart: Add eDMA support

---
 arch/arm/boot/dts/vf610.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/boot/dts/vf610.dtsi +12 -0
index 365e0fa..ed6b053 100644
@@ -118,6 +118,9 @@
 				interrupts = <0 61 0x00>;
 				clocks = <&clks VF610_CLK_UART0>;
 				clock-names = "ipg";
+				dma-names = "lpuart-tx","lpuart-rx";
+				dmas = <&edma0 0 VF610_EDMA_MUXID0_UART0_TX>,
+					<&edma0 0 VF610_EDMA_MUXID0_UART0_RX>;
 				status = "disabled";
 			};
 
@@ -127,6 +130,9 @@
 				interrupts = <0 62 0x04>;
 				clocks = <&clks VF610_CLK_UART1>;
 				clock-names = "ipg";
+				dma-names = "lpuart-tx","lpuart-rx";
+				dmas = <&edma0 0 VF610_EDMA_MUXID0_UART1_TX>,
+					<&edma0 0 VF610_EDMA_MUXID0_UART1_RX>;
 				status = "disabled";
 			};
 
@@ -136,6 +142,9 @@
 				interrupts = <0 63 0x04>;
 				clocks = <&clks VF610_CLK_UART2>;
 				clock-names = "ipg";
+				dma-names = "lpuart-tx","lpuart-rx";
+				dmas = <&edma0 0 VF610_EDMA_MUXID0_UART2_TX>,
+					<&edma0 0 VF610_EDMA_MUXID0_UART2_RX>;
 				status = "disabled";
 			};
 
@@ -145,6 +154,9 @@
 				interrupts = <0 64 0x04>;
 				clocks = <&clks VF610_CLK_UART3>;
 				clock-names = "ipg";
+				dma-names = "lpuart-tx","lpuart-rx";
+				dmas = <&edma0 0 VF610_EDMA_MUXID0_UART3_TX>,
+					<&edma0 0 VF610_EDMA_MUXID0_UART3_RX>;
 				status = "disabled";
 			};
 
Signature · 1 line
1.8.4
author
#2 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

In reply to Yuan Yao
---
 .../devicetree/bindings/serial/fsl-lpuart.txt      |  17 +-
 drivers/tty/serial/fsl_lpuart.c                    | 434 +++++++++++++++++----
 2 files changed, 365 insertions(+), 86 deletions(-)
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +13 -4
index 6fd1dd1..311598d 100644
@@ -4,11 +4,20 @@ Required properties:
 - compatible : Should be "fsl,<soc>-lpuart"
 - reg : Address and length of the register set for the device
 - interrupts : Should contain uart interrupt
+- clocks : clocks: from common clock binding: handle to uart clock
+- clock-names : from common clock binding: Shall be "jpg"
+- dma-names: Should contain "lpuart-tx" for transmit and "lpuart-rx" for receive channels
+- dmas: Should contain dma specifiers for transmit and receive channels
 
 Example:
 
 uart0: serial at 40027000 {
-	       compatible = "fsl,vf610-lpuart";
-	       reg = <0x40027000 0x1000>;
-	       interrupts = <0 61 0x00>;
-       };
+		compatible = "fsl,vf610-lpuart";
+		reg = <0x40027000 0x1000>;
+		interrupts = <0 61 0x00>;
+		clocks = <&clks VF610_CLK_UART0>;
+		clock-names = "ipg";
+		dma-names = "lpuart-tx","lpuart-rx";
+		dmas = <&edma0 0 VF610_EDMA_MUXID0_UART0_TX>,
+			<&edma0 0 VF610_EDMA_MUXID0_UART0_RX>;
+	};
drivers/tty/serial/fsl_lpuart.c +354 -82

552 lines not on this page · raw message

Signature · 1 line
1.8.4
#3 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

Quoted 5 lines · Yuan Yao
---
 .../devicetree/bindings/serial/fsl-lpuart.txt      |  17 +-
 drivers/tty/serial/fsl_lpuart.c                    | 434 +++++++++++++++++----
 2 files changed, 365 insertions(+), 86 deletions(-)

Both patches are lacking a changeset description. Please describe why this patch is needed and what the changes to the interfaces are.

Documentation/devicetree/bindings/serial/fsl-lpuart.txt Required properties: · line 8

Quoted 10 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +2 -0
index 6fd1dd1..311598d 100644
@@ -4,11 +4,20 @@ Required properties:
 - compatible : Should be "fsl,<soc>-lpuart"
 - reg : Address and length of the register set for the device
 - interrupts : Should contain uart interrupt
+- clocks : clocks: from common clock binding: handle to uart clock
+- clock-names : from common clock binding: Shall be "jpg"
	typo: "ipg", not "jpg"

Documentation/devicetree/bindings/serial/fsl-lpuart.txt Required properties: · line 10

Quoted 2 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +2 -0
+- dma-names: Should contain "lpuart-tx" for transmit and "lpuart-rx" for receive channels
+- dmas: Should contain dma specifiers for transmit and receive channels

I note that this is an incompatible change: Prior to this patch, the dma properties were not allowed, now they are listed as "required". We try hard to avoid incompatible changes to the binding in general. Please make sure that you either

a) list the dma properties as "optional" and verify that the driver still works fine when they are absent, or

b) document in the changeset text your motivation for doing an incompatible change, why you could not do it in a compatible way, and what the possible impact is for existing users.

Quoted 6 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +0 -3
 Example:
 
 uart0: serial at 40027000 {
-	       compatible = "fsl,vf610-lpuart";
-	       reg = <0x40027000 0x1000>;
-	       interrupts = <0 61 0x00>;

Documentation/devicetree/bindings/serial/fsl-lpuart.txt Required properties: · line 23

Quoted 10 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +9 -1
-       };
+		compatible = "fsl,vf610-lpuart";
+		reg = <0x40027000 0x1000>;
+		interrupts = <0 61 0x00>;
+		clocks = <&clks VF610_CLK_UART0>;
+		clock-names = "ipg";
+		dma-names = "lpuart-tx","lpuart-rx";
+		dmas = <&edma0 0 VF610_EDMA_MUXID0_UART0_TX>,
+			<&edma0 0 VF610_EDMA_MUXID0_UART0_RX>;
+	};

I checked again and found that VF610_EDMA_MUXID0_UART0_TX and RX are not defined as macros anywhere, and I think they should not be. The common convention is to just ust number literals here. There is no point defining the macros in a common header file because they will change with every new SoC.

Documentation/devicetree/bindings/serial/fsl-lpuart.txt static struct of_device_id lpuart_dt_ids[] = { · line 167

Quoted 11 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +4 -0
@@ -131,6 +158,10 @@ static struct of_device_id lpuart_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, lpuart_dt_ids);
 
+static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long count);
+static int lpuart_dma_rx(struct lpuart_port *sport);
+static void lpuart_prepare_tx(struct lpuart_port *sport);
+
 static void lpuart_stop_tx(struct uart_port *port)
 {
 	unsigned char temp;

Coding style: Please try to avoid forward declarations for "static" functions. Instead, reorder the code in a way that they are not needed.

Arnd

author
#4 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

Hi, Arnd

Quoted 16 lines

Review static struct of_device_id lpuart_dt_ids[] = { · line 165

Quoted 9 lines · Arnd Bergmann
(quoted diff) +4 -0
@@ -131,6 +158,10 @@ static struct of_device_id lpuart_dt_ids[] = {
 };  MODULE_DEVICE_TABLE(of, lpuart_dt_ids);
 
+static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long
+count); static int lpuart_dma_rx(struct lpuart_port *sport); static
+void lpuart_prepare_tx(struct lpuart_port *sport);
+
 static void lpuart_stop_tx(struct uart_port *port)  {
 	unsigned char temp;

Coding style: Please try to avoid forward declarations for "static" functions.
Instead, reorder the code in a way that they are not needed.

Quoted 2 lines

Arnd

I need the functions like this:
Static A()

{
	if(condition) 
		B();
}
Static B()
{
	callback:C();
}
Static C()
{
	if(condition)
		A();
}

So, it's hard to avoid forward declarations for "static" functions. I'm very glad for a better way.

#5 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

Quoted 16 lines · Yao Yuan

I need the functions like this:
Static A()

{
        if(condition) 
                B();
}
Static B()
{
        callback:C();
}
Static C()
{
        if(condition)
                A();
}
Quoted 2 lines

So, it's hard to avoid forward declarations for "static" functions. I'm very glad for a better way.

Ok, that makes sense. It is an unusual pattern from the dmaengine API, most drivers can more easily do without forward declarations. I think you'd be able to avoid the lpuart_prepare_tx() forward declation, but that wouldn't actually improve readability in this case. Just add a comment above the declarations describing that they are needed for the callbacks and that no recursion is possible. The important problem to avoid really is having unbounded recursion between multple functions, because that could blow the kernel stack size limit.

A small improvement that you can try is to have forward declarations for the completion functions rather than the dma start functions, but it won't be a big difference in the end. Your choice.

Arnd

#6 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

In reply to Yuan Yao

Hi,

Quoted 9 lines · Yuan Yao
---
 .../devicetree/bindings/serial/fsl-lpuart.txt      |  17 +-
 drivers/tty/serial/fsl_lpuart.c                    | 434 +++++++++++++++++----
 2 files changed, 365 insertions(+), 86 deletions(-)
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +1 -0
index 6fd1dd1..311598d 100644
+static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long count)

[...]

Quoted 9 lines

{

Documentation/devicetree/bindings/serial/fsl-lpuart.txt +3 -5
-	struct lpuart_port *sport = dev_id;
-	unsigned int flg, ignored = 0;
-	struct tty_port *port = &sport->port.state->port;
-	unsigned long flags;
-	unsigned char rx, sr;
+	struct circ_buf *xmit = &sport->port.state->xmit;
+	dma_addr_t tx_bus_addr;
+

Documentation/devicetree/bindings/serial/fsl-lpuart.txt

Quoted 10 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +10 -0
+	dma_sync_single_for_device(sport->port.dev, sport->dma_tx_buf_bus,
+				UART_XMIT_SIZE, DMA_TO_DEVICE);
+	sport->dma_tx_bytes = count & ~(DMA_TX_MAXBURST_MASK);
+	tx_bus_addr = sport->dma_tx_buf_bus + xmit->tail;
+	sport->dma_tx_desc = dmaengine_prep_slave_single(sport->dma_tx_chan,
+					tx_bus_addr, sport->dma_tx_bytes,
+					DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
+
+	if (!sport->dma_tx_desc) {
+		dev_err(sport->port.dev, "Not able to get desc for Tx\n");

s/Not able/unable/
Also the capitalization of 'Tx' looks strange. IMO 'TX' or 'tx' would look better.

Quoted 19 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +7 -9
+		return -EIO;
+	}
 
-	spin_lock_irqsave(&sport->port.lock, flags);
+	sport->dma_tx_desc->callback = lpuart_dma_tx_complete;
+	sport->dma_tx_desc->callback_param = sport;
+	sport->dma_tx_in_progress = 1;
+	sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
+	dma_async_issue_pending(sport->dma_tx_chan);
 
-	while (!(readb(sport->port.membase + UARTSFIFO) & UARTSFIFO_RXEMPT)) {
-		flg = TTY_NORMAL;
-		sport->port.icount.rx++;
-		/*
-		 * to clear the FE, OR, NF, FE, PE flags,
-		 * read SR1 then read DR
-		 */
-		sr = readb(sport->port.membase + UARTSR1);

Documentation/devicetree/bindings/serial/fsl-lpuart.txt

Quoted 10 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +6 -3
-		rx = readb(sport->port.membase + UARTDR);
+	return 0;
+}
 
-		if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
-			continue;
+static int lpuart_dma_rx(struct lpuart_port *sport)
+{
+	dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus,
+			DMA_RX_BUFFER_SIZE, DMA_TO_DEVICE);

dma_alloc_coherent() (which you use to allocate the DMA rx buffer) and dma_symc_*() are orthogonal to each other!
You either allocate DMA coherent memory as DMA buffer or use ordinary memory with the DMA streaming API (dma_map_*(), dma_sync_*()). See Documentation/DMA-API-HOWTO.txt

Documentation/devicetree/bindings/serial/fsl-lpuart.txt

Quoted 7 lines
Documentation/devicetree/bindings/serial/fsl-lpuart.txt +6 -0
+	sport->dma_rx_desc = dmaengine_prep_slave_single(sport->dma_rx_chan,
+			sport->dma_rx_buf_bus, DMA_RX_BUFFER_SIZE,
+			DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
+
+	if (!sport->dma_rx_desc) {
+		dev_err(sport->port.dev, "Not able to get desc for Rx\n");

Strange capitalization of 'Rx'.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#7 lore raw

PATCH 2/2 serial: fsl_lpuart: add eDMA support

Quoted 10 lines · Lothar Wa?mann

drivers/tty/serial/fsl_lpuart.c static void lpuart_enable_ms(struct uart_port *port) · line 305

Quoted 5 lines
drivers/tty/serial/fsl_lpuart.c +4 -0
+static int lpuart_dma_rx(struct lpuart_port *sport)
+{
+     dma_sync_single_for_device(sport->port.dev, sport->dma_rx_buf_bus,
+                     DMA_RX_BUFFER_SIZE, DMA_TO_DEVICE);

dma_alloc_coherent() (which you use to allocate the DMA rx buffer) and dma_symc_*() are orthogonal to each other!
You either allocate DMA coherent memory as DMA buffer or use ordinary memory with the DMA streaming API (dma_map_*(), dma_sync_*()). See Documentation/DMA-API-HOWTO.txt

Well spotted, it took me a while to figure out what the driver actually does mixing these two. Apparently the tx path is using the streaming DMA API, while the rx path uses the consistent API.

I think the driver should really use the same API both ways, and it depends on the amount of data transferred with each DMA which API fits better. I'd say that if typical transfer is just a few dozen bytes at most, it should perform better if you use the consistent API with uncacheable memory buffers, because it won't have the overhead from the cache flushes. If you often transfer kilobytes at once, the streaming API would be faster because it avoids uncached memory accesses.

Arnd