dma: add channels support
v6 cover dma: add channels support
Hi All,
This series is the next try to add DMA channels support for DMA controllers which last version was posted by Álvaro Fernández Rojas [1]. i've kept version numbering.
Comparing to the original post I've added few changes:
- added possibility to pass DMA driver/channel's specific data per each transfer using additional parameter "metadata" in dma_send/dma_receive() API. For example, port number for network packets to be directed to the specific port on multi port ethernet controllers.
- added new dma_prepare_rcv_buf() API which allows to implement zero-copy DEV_TO_MEM transfer using DMA streaming channels which is usual case for Networking.
- added dma-uclass test
- removed unused function dma_get_by_index_platdata()
- updated comments
Hence, originally DMA channels support was introduced to add support for "bmips: add bcm6348-enet support" - that series can be easily updated following DMA channels API changes (if still actual).
Patches 5-6 - Here I'm providing DMA and networking drivers for the new TI AM65x SoC [2] as an illustration of DMA channels API usage only. Unfortunately, those drivers are still under development so NOT-FOR-MERGE (!will not build!)
- we'd like code/bindings to be accepted in LKML first.
Full sources can be found at [3].
[1] https://patchwork.ozlabs.org/cover/881642/
[2] http://www.ti.com/lit/ug/spruid7b/spruid7b.pdf
[3] git at git.ti.com:~gragst/ti-u-boot/gragsts-ti-u-boot.git
branch: master-am6-dma-wip
===
A DMA is a feature of computer systems that allows certain hardware subsystems to access main system memory, independent of the CPU. DMA channels are typically generated externally to the HW module consuming them, by an entity this API calls a DMA provider. This API provides a standard means for drivers to enable and disable DMAs, and to copy, send and receive data using DMA.
DMA channel API:
dma_get_by_index()
dma_get_by_name()
dma_request()
dma_free()
dma_enable()
dma_disable()
dma_prepare_rcv_buf()
dma_receive()
dma_send()
A driver that implements UCLASS_DMA is a DMA provider. A provider will often implement multiple separate DMAs channels, since the hardware it manages often has this capability. dma_uclass.h describes the interface which DMA providers must implement.
DMA consumers/clients are the HW modules driven by the DMA channels.
DMA consumer DMA_MEM_TO_DEV (transmit) usage example (based on networking). Note. In u-boot dma_send() is sync operation always - it'll start transfer and will poll for it to complete:
- get/request dma channel
struct dma dma_tx; ret = dma_get_by_name(common->dev, "tx0", &dma_tx); if (ret) ...
- enable dma channel
ret = dma_enable(&dma_tx); if (ret) ...
- dma transmit DMA_MEM_TO_DEV.
struct ti_drv_packet_data packet_data; packet_data.opt1 = val1; packet_data.opt2 = val2; ret = dma_send(&dma_tx, packet, length, &packet_data); if (ret) ..
DMA consumer DMA_DEV_TO_MEM (receive) usage example (based on networking). Note. dma_receive() is sync operation always - it'll start transfer (if required) and will poll for it to complete (or for any previously configured dev2mem transfer to complete):
- get/request dma channel
struct dma dma_rx; ret = dma_get_by_name(common->dev, "rx0", &dma_rx); if (ret) ...
- enable dma channel
ret = dma_enable(&dma_rx); if (ret) ...
- dma receive DMA_DEV_TO_MEM.
struct ti_drv_packet_data packet_data; len = dma_receive(&dma_rx, (void **)packet, &packet_data); if (ret < 0) ...
DMA consumer DMA_DEV_TO_MEM (receive) zero-copy usage example (based on networking). Networking subsystem allows to configure and use few receive buffers (dev2mem), as Networking RX DMA channels usually implemented as streaming interface
- get/request dma channel
struct dma dma_rx;
ret = dma_get_by_name(common->dev, "rx0", &dma_rx);
if (ret) ...
for (i = 0; i < RX_DESC_NUM; i++) {
ret = dma_prepare_rcv_buf(&dma_rx,
net_rx_packets[i],
RX_BUF_SIZE);
if (ret) ...
}- enable dma channel
ret = dma_enable(&dma_rx); if (ret) ...
- dma receive DMA_DEV_TO_MEM.
struct ti_drv_packet_data packet_data; void *packet; len = dma_receive(&dma_rx, &packet, &packet_data); if (ret < 0) .. /* packet - points on buffer prepared by dma_prepare_rcv_buf(). process packet*/ - return buffer back to DAM channel ret = dma_prepare_rcv_buf(&dma_rx, net_rx_packets[rx_next], RX_BUF_SIZE);
Grygorii Strashko (2):
test: dma: add dma-uclass test
net: ethernet: ti: introduce am654 gigabit eth switch subsystem driver
Vignesh R (1):
dma: ti: add driver to K3 UDMA
Álvaro Fernández Rojas (2):
dma: move dma_ops to dma-uclass.h
dma: add channels support
arch/sandbox/dts/test.dts | 8 + configs/sandbox_defconfig | 3 + drivers/dma/Kconfig | 16 + drivers/dma/Makefile | 3 + drivers/dma/dma-uclass.c | 183 +++- drivers/dma/sandbox-dma-test.c | 284 +++++++ drivers/dma/ti-edma3.c | 2 +- drivers/dma/ti/Kconfig | 14 + drivers/dma/ti/Makefile | 3 + drivers/dma/ti/k3-udma-hwdef.h | 184 ++++ drivers/dma/ti/k3-udma.c | 1661 +++++++++++++++++++++++++++++++++++++ drivers/net/Kconfig | 8 + drivers/net/Makefile | 1 + drivers/net/am65-cpsw-nuss.c | 962 +++++++++++++++++++++ include/dma-uclass.h | 128 +++ include/dma.h | 282 ++++++- include/dt-bindings/dma/k3-udma.h | 26 + include/linux/soc/ti/ti-udma.h | 24 + test/dm/Makefile | 1 + test/dm/dma.c | 121 +++ 20 files changed, 3884 insertions(+), 30 deletions(-) create mode 100644 drivers/dma/sandbox-dma-test.c create mode 100644 drivers/dma/ti/Kconfig create mode 100644 drivers/dma/ti/Makefile create mode 100644 drivers/dma/ti/k3-udma-hwdef.h create mode 100644 drivers/dma/ti/k3-udma.c create mode 100644 drivers/net/am65-cpsw-nuss.c create mode 100644 include/dma-uclass.h create mode 100644 include/dt-bindings/dma/k3-udma.h create mode 100644 include/linux/soc/ti/ti-udma.h create mode 100644 test/dm/dma.c
Signature · 1 line
2.10.5
PATCH v6 1/5 dma: move dma_ops to dma-uclass.h
From: Álvaro Fernández Rojas <[email protected]>
Move dma_ops to a separate header file, following other uclass implementations. While doing so, this patch also improves dma_ops documentation.
--- drivers/dma/dma-uclass.c | 2 +- drivers/dma/ti-edma3.c | 2 +- include/dma-uclass.h | 39 +++++++++++++++++++++++++++++++++++++++ include/dma.h | 22 ---------------------- 4 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 include/dma-uclass.h
drivers/dma/dma-uclass.c +1 -1
@@ -9,10 +9,10 @@*/ #include <common.h> -#include <dma.h> #include <dm.h> #include <dm/uclass-internal.h> #include <dm/device-internal.h> +#include <dma-uclass.h> #include <errno.h> int dma_get_device (u32 transfer_type,struct udevice **devp)
drivers/dma/ti-edma3.c +1 -1
@@ -11,7 +11,7 @@#include <asm/io.h> #include <common.h> #include <dm.h> -#include <dma.h> +#include <dma-uclass.h> #include <asm/omap_common.h> #include <asm/ti-common/ti-edma3.h>
include/dma-uclass.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2018 Álvaro Fernández Rojas <[email protected]> +* Copyright (C) 2018 Texas Instruments Incorporated <www.ti.com> +* Written by Mugunthan V N <[email protected]> +* +*/ + +#ifndef _DMA_UCLASS_H +#define _DMA_UCLASS_H + +/* See dma.h for background documentation. */ + +#include <dma.h> + +/* +* struct dma_ops - Driver model DMA operations +* +* The uclass interface is implemented by all DMA devices which use +* driver model. +*/ +struct dma_ops { +/** +* transfer() - Issue a DMA transfer. The implementation must +* wait until the transfer is done. +* +* @dev: The DMA device +* @direction: direction of data transfer (should be one from +* enum dma_direction) +* @dst: The destination pointer. +* @src: The source pointer. +* @len: Length of the data to be copied (number of bytes). +* @return zero on success, or -ve error code. +*/ +int (*transfer)(struct udevice *dev,int direction,void *dst, +void *src,size_t len); +}; + +#endif /* _DMA_UCLASS_H */
include/dma.h +0 -22
@@ -27,28 +27,6 @@ enum dma_direction {#define DMA_SUPPORTS_DEV_TO_DEV BIT(3)/* -* struct dma_ops - Driver model DMA operations -* -* The uclass interface is implemented by all DMA devices which use -* driver model. -*/ -struct dma_ops { -/* -* Get the current timer count -* -* @dev: The DMA device -* @direction: direction of data transfer should be one from -enum dma_direction -* @dst: Destination pointer -* @src: Source pointer -* @len: Length of the data to be copied. -* @return: 0 if OK, -ve on error -*/ -int (*transfer)(struct udevice *dev,int direction,void *dst, -void *src,size_t len); -}; - -/* * struct dma_dev_priv - information about a device used by the uclass * * @supported: mode of transfers that DMA can support, should be
Signature · 1 line
2.10.5
PATCH v6 1/5 dma: move dma_ops to dma-uclass.h
Quoted 8 lines · Grygorii Strashko
From: Álvaro Fernández Rojas <[email protected]>
Move
dma_opsto a separate header file, following other uclass implementations. While doing so, this patch also improvesdma_opsdocumentation.Reviewed-by Simon Glass <[email protected]>Signed-off-by Álvaro Fernández Rojas <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181102/7f82f2b8/attachment.sig>
PATCH v6 2/5 dma: add channels support
In reply to Grygorii StrashkoFrom: Álvaro Fernández Rojas <[email protected]>
This adds channels support for dma controllers that have multiple channels which can transfer data to/from different devices (enet, usb...).
DMA channel API:
dma_get_by_index()
dma_get_by_name()
dma_request()
dma_free()
dma_enable()
dma_disable()
dma_prepare_rcv_buf()
dma_receive()
dma_send()
[grygorii.strashko at ti.com: drop unused dma_get_by_index_platdata(),
add metadata to send/receive ops, add dma_prepare_rcv_buf(), minor clean up]
--- drivers/dma/Kconfig | 7 ++ drivers/dma/dma-uclass.c | 181 ++++++++++++++++++++++++++++++++- include/dma-uclass.h | 89 ++++++++++++++++ include/dma.h | 260 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 531 insertions(+), 6 deletions(-)
drivers/dma/Kconfig +7 -0
@@ -12,6 +12,13 @@ config DMA buses that is used to transfer data to and from memory. The uclass interface is defined in include/dma.h. +config DMA_CHANNELS + bool "Enable DMA channels support" + depends on DMA + help + Enable channels support for DMA. Some DMA controllers have multiple + channels which can either transfer data to/from different devices. + config TI_EDMA3 bool "TI EDMA3 driver" help
drivers/dma/dma-uclass.c +177 -4
196 lines not on this page · raw message
include/dma-uclass.h +89 -0
101 lines not on this page · raw message
include/dma.h +258 -2
276 lines not on this page · raw message
Signature · 1 line
2.10.5
PATCH v6 2/5 dma: add channels support
Quoted 16 lines · Grygorii Strashko
From: Álvaro Fernández Rojas <[email protected]>
This adds channels support for dma controllers that have multiple channels which can transfer data to/from different devices (enet, usb...).
DMA channel API:
dma_get_by_index()
dma_get_by_name()
dma_request()
dma_free()
dma_enable()
dma_disable()
dma_prepare_rcv_buf()
dma_receive()
dma_send()
Quoted 5 lines
Signed-off-by Álvaro Fernández Rojas <[email protected]>[grygorii.strashko at ti.com: drop unused
dma_get_by_index_platdata(),
add metadata to send/receive ops, adddma_prepare_rcv_buf(), minor clean up]Signed-off-by Grygorii Strashko <[email protected]>
But, please check this patch again, in at least one place you're dropping an old TI copyright date and making it just be 2018.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181102/a8816320/attachment.sig>
PATCH v6 3/5 sandbox: dma: add dma-uclass test
In reply to Grygorii StrashkoAdd a sandbox DMA driver implementation (provider) and corresponding DM test.
--- arch/sandbox/dts/test.dts | 8 ++ configs/sandbox_defconfig | 3 + drivers/dma/Kconfig | 7 + drivers/dma/Makefile | 1 + drivers/dma/sandbox-dma-test.c | 284 +++++++++++++++++++++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/dma.c | 121 ++++++++++++++++++ 7 files changed, 425 insertions(+) create mode 100644 drivers/dma/sandbox-dma-test.c create mode 100644 test/dm/dma.c
arch/sandbox/dts/test.dts +8 -0
@@ -708,6 +708,14 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + dma: dma { + compatible = "sandbox,dma"; + #dma-cells = <1>; + + dmas = <&dma 0>, <&dma 1>, <&dma 2>; + dma-names = "m2m", "tx0", "rx0"; + }; }; #include "sandbox_pmic.dtsi"
configs/sandbox_defconfig +3 -0
@@ -217,3 +217,6 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_UT_ENV=y CONFIG_UT_OVERLAY=y +CONFIG_DMA=y +CONFIG_DMA_CHANNELS=y +CONFIG_SANDBOX_DMA=y
drivers/dma/Kconfig +7 -0
@@ -19,6 +19,13 @@ config DMA_CHANNELS Enable channels support for DMA. Some DMA controllers have multiple channels which can either transfer data to/from different devices. +config SANDBOX_DMA + bool "Enable the sandbox DMA test driver" + depends on DMA && DMA_CHANNELS && SANDBOX + help + Enable support for a test DMA uclass implementation. It stimulates + DMA transfer by simple copying data between channels. + config TI_EDMA3 bool "TI EDMA3 driver" help
drivers/dma/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_DMA) += dma-uclass.o obj-$(CONFIG_FSLDMAFEC) += MCD_tasksInit.o MCD_dmaApi.o MCD_tasks.o obj-$(CONFIG_APBH_DMA) += apbh_dma.o obj-$(CONFIG_FSL_DMA) += fsl_dma.o +obj-$(CONFIG_SANDBOX_DMA) += sandbox-dma-test.o obj-$(CONFIG_TI_KSNAV) += keystone_nav.o keystone_nav_cfg.o obj-$(CONFIG_TI_EDMA3) += ti-edma3.o obj-$(CONFIG_DMA_LPC32XX) += lpc32xx_dma.o
drivers/dma/sandbox-dma-test.c new file +284 -0
284 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -53,4 +53,5 @@ obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_TEE) += tee.o +obj-$(CONFIG_DMA) += dma.o endif
test/dm/dma.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.10.5
PATCH v6 3/5 sandbox: dma: add dma-uclass test
Quoted 4 lines · Grygorii Strashko
Add a sandbox DMA driver implementation (provider) and corresponding DM test.
Signed-off-by Grygorii Strashko <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181102/b24baf55/attachment.sig>
PATCH v6 4/5 dma: ti: add driver to K3 UDMA
In reply to Grygorii StrashkoFrom: Vignesh R <[email protected]>
Add support for K3 AM65x UDMA with only support pktmode MEM_TO_MEM transfers and DEV_TO_MEM/MEM_TO_DEV through DMA channels.
--- drivers/dma/Kconfig | 2 + drivers/dma/Makefile | 2 + drivers/dma/ti/Kconfig | 14 + drivers/dma/ti/Makefile | 3 + drivers/dma/ti/k3-udma-hwdef.h | 184 ++++ drivers/dma/ti/k3-udma.c | 1661 +++++++++++++++++++++++++++++++++++++ include/dt-bindings/dma/k3-udma.h | 26 + include/linux/soc/ti/ti-udma.h | 24 + 8 files changed, 1916 insertions(+) create mode 100644 drivers/dma/ti/Kconfig create mode 100644 drivers/dma/ti/Makefile create mode 100644 drivers/dma/ti/k3-udma-hwdef.h create mode 100644 drivers/dma/ti/k3-udma.c create mode 100644 include/dt-bindings/dma/k3-udma.h create mode 100644 include/linux/soc/ti/ti-udma.h
drivers/dma/Kconfig +2 -0
@@ -48,4 +48,6 @@ config APBH_DMA_BURST8 endif +source "drivers/dma/ti/Kconfig" + endmenu # menu "DMA Support"
drivers/dma/Makefile +2 -0
@@ -12,3 +12,5 @@ obj-$(CONFIG_SANDBOX_DMA) += sandbox-dma-test.o obj-$(CONFIG_TI_KSNAV) += keystone_nav.o keystone_nav_cfg.o obj-$(CONFIG_TI_EDMA3) += ti-edma3.o obj-$(CONFIG_DMA_LPC32XX) += lpc32xx_dma.o + +obj-y += ti/
drivers/dma/ti/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0+ + +if ARCH_K3 + +config TI_K3_NAVSS_UDMA + bool "Texas Instruments UDMA" + depends on ARCH_K3 + select DMA + select TI_K3_NAVSS_RINGACC + select TI_K3_NAVSS_PSILCFG + default n + help + Support for UDMA used in K3 devices. +endif
drivers/dma/ti/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_TI_K3_NAVSS_UDMA) += k3-udma.o
drivers/dma/ti/k3-udma-hwdef.h new file +184 -0
184 lines not on this page · raw message
drivers/dma/ti/k3-udma.c new file +1661 -0
1,661 lines not on this page · raw message
include/dt-bindings/dma/k3-udma.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __DT_TI_UDMA_H +#define __DT_TI_UDMA_H + +#define UDMA_TR_MODE 0 +#define UDMA_PKT_MODE 1 + +#define UDMA_DIR_TX 0 +#define UDMA_DIR_RX 1 + +#define PSIL_STATIC_TR_NONE 0 +#define PSIL_STATIC_TR_XY 1 +#define PSIL_STATIC_TR_MCAN 2 + +#define UDMA_PDMA_TR_XY (id) \ + ti,psil-config##id { \ + linux,udma-mode = <UDMA_TR_MODE>; \ + statictr-type = <PSIL_STATIC_TR_XY>; \ + } + +#define UDMA_PDMA_PKT_XY (id) \ + ti,psil-config##id { \ + linux,udma-mode = <UDMA_PKT_MODE>; \ + statictr-type = <PSIL_STATIC_TR_XY>; \ + } + +#endif /* __DT_TI_UDMA_H */
include/linux/soc/ti/ti-udma.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com +* Author: Peter Ujfalusi <[email protected]> +*/ + +#ifndef __TI_UDMA_H +#define __TI_UDMA_H + +/** +* struct ti_udma_drv_packet_data - TI UDMA transfer specific data +* +* @pkt_type: Packet Type - specific for each DMA client HW +* @dest_tag: Destination tag The source pointer. +* +* TI UDMA transfer specific data passed as part of DMA transfer to +* the DMA client HW in UDMA descriptors. +*/ +struct ti_udma_drv_packet_data { +u32 pkt_type; +u32 dest_tag; +}; + +#endif /* __TI_UDMA_H */
Signature · 1 line
2.10.5
PATCH v6 5/5 net: ethernet: ti: introduce am654 gigabit eth switch subsystem driver
In reply to Grygorii StrashkoAdd new driver for the TI AM65x SoC Gigabit Ethernet Switch subsystem (CPSW NUSS). It has two ports (internal and one external) and provides Ethernet packet communication for the device.
CPSW NUSS features: the Reduced Gigabit Media Independent Interface (RGMII), Reduced Media Independent Interface (RMII), and the Management Data Input/Output (MDIO) interface for physical layer device (PHY) management. The TI AM65x SoC has integrated two-port Gigabit Ethernet Switch subsystem into device MCU domain named MCU_CPSW0. One Ethernet port (port 1) with selectable RGMII and RMII interfaces and an internal Communications Port Programming Interface (CPPI) port (Host port 0).
Host Port 0 CPPI Packet Streaming Interface interface supports 8 TX channels and 8 RX channels operating by TI am654 NAVSS Unified DMA Peripheral Root Complex (UDMA-P) controller.
--- drivers/net/Kconfig | 8 + drivers/net/Makefile | 1 + drivers/net/am65-cpsw-nuss.c | 962 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 971 insertions(+) create mode 100644 drivers/net/am65-cpsw-nuss.c
drivers/net/Kconfig +8 -0
@@ -327,6 +327,14 @@ config DRIVER_TI_EMAC help Support for davinci emac +config TI_AM65_CPSW_NUSS + bool "TI K3 AM65x MCU CPSW Nuss Ethernet controller driver" + depends on ARCH_K3 + select PHYLIB + help + This driver supports TI K3 MCU CPSW Nuss Ethernet controller + in Texas Instruments K3 AM65x SoCs. + config XILINX_AXIEMAC depends on DM_ETH && (MICROBLAZE || ARCH_ZYNQ || ARCH_ZYNQMP) select PHYLIB
drivers/net/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o obj-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o obj-$(CONFIG_FMAN_ENET) += fsl_mdio.o +obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o obj-$(CONFIG_ULI526X) += uli526x.o obj-$(CONFIG_VSC7385_ENET) += vsc7385.o obj-$(CONFIG_XILINX_AXIEMAC) += xilinx_axi_emac.o
drivers/net/am65-cpsw-nuss.c new file +962 -0
962 lines not on this page · raw message
Signature · 1 line
2.10.5