[U-Boot] [PATCH v8 00/31] dma: add channels support

Álvaro Fernández Rojas
2018-11-26T18:00:08Z

In order to add bcm6348-enet support, dma-uclass must be extended to support
dma channels and reworked to operate like the other dm uclass (clk, reset...).

===

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);

===

v8: Adopt changes introduced by Grygorii Strashko:
- Sync with latest u-boot.
- Introduce bcm6368-enet driver support.
v7: From Grygorii Strashko:
- copyright fixed as suggested by Tom Rini
- added "Reviewed-by" tags
v6: From Grygorii Strashko:
- 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
v5: Fix issues reported by Grygorii Strashko and other fixes:
- Fix build of ti-edma3.
- Remove unused bcm6348-iudma defines.
- Increment bcm6348-iudma rx descriptors.
- Fix bcm6348-iudma flow control issues.
- bcm6348-iudma error checking now depends on hw.
- Remove unneeded bcm6348-iudma interrupts.
- Receive as much packets as possible from bcm6348-eth and cache them in
net_rx_packets. This is needed in order to fix flow control issues.
v4: Fix issues reported by Grygorii Strashko and other fixes:
- Remove usage of net_rx_packets as buffer from bcm6348-iudma.
- Allocate dynamic rx buffer on bcm6348-iudma.
- Copy received dma buffer to net_rx_packets in order to avoid possible
dma overwrites.
- Check dma errors and discard invalid packets.
- Reset dma rx channel when sending a new packet to prevent flow control
issues.
- Fix packet casting on bcm6348_eth_recv/send.
v3: Introduce changes reported by Simon Glass:
- Improve dma-uclass.h documentation.
- Switch to live tree API.
v2: Introduce changes reported by Vignesh:
- Respect current dma implementation.
- Let dma_memcpy find a compatible dma device.
Other changes:
- Fix bcm6348-iudma rx burst config.

Grygorii Strashko (1):
test: dma: add dma-uclass test

Álvaro Fernández Rojas (30):
dma: move dma_ops to dma-uclass.h
dma: add channels support
dma: add bcm6348-iudma support
bmips: bcm6338: add bcm6348-iudma support
bmips: bcm6348: add bcm6348-iudma support
bmips: bcm6358: add bcm6348-iudma support
bmips: bcm6368: add bcm6348-iudma support
bmips: bcm6328: add bcm6348-iudma support
bmips: bcm6362: add bcm6348-iudma support
bmips: bcm63268: add bcm6348-iudma support
bmips: bcm6318: add bcm6348-iudma support
net: add support for bcm6348-enet
bmips: bcm6338: add support for bcm6348-enet
bmips: enable f at st1704 enet support
bmips: bcm6348: add support for bcm6348-enet
bmips: enable ct-5361 enet support
bmips: bcm6358: add support for bcm6348-enet
bmips: enable hg556a enet support
bmips: enable nb4-ser enet support
net: add support for bcm6368-enet
bmips: bcm6368: add support for bcm6368-enet
bmips: enable wap-5813n enet support
bmips: bcm6328: add support for bcm6368-enet
bmips: enable ar-5387un enet support
bmips: bcm6362: add support for bcm6368-enet
bmips: enable dgnd3700v2 enet support
bmips: bcm63268: add support for bcm6368-enet
bmips: enable vr-3032u enet support
bmips: bcm6318: add support for bcm6368-enet
bmips: enable ar-5315u enet support

arch/mips/dts/brcm,bcm6318.dtsi | 38 ++
arch/mips/dts/brcm,bcm63268.dtsi | 38 ++
arch/mips/dts/brcm,bcm6328.dtsi | 30 ++
arch/mips/dts/brcm,bcm6338.dtsi | 29 ++
arch/mips/dts/brcm,bcm6348.dtsi | 42 +++
arch/mips/dts/brcm,bcm6358.dtsi | 46 +++
arch/mips/dts/brcm,bcm6362.dtsi | 32 ++
arch/mips/dts/brcm,bcm6368.dtsi | 32 ++
arch/mips/dts/comtrend,ar-5315u.dts | 32 ++
arch/mips/dts/comtrend,ar-5387un.dts | 32 ++
arch/mips/dts/comtrend,ct-5361.dts | 12 +
arch/mips/dts/comtrend,vr-3032u.dts | 32 ++
arch/mips/dts/comtrend,wap-5813n.dts | 14 +
arch/mips/dts/huawei,hg556a.dts | 12 +
arch/mips/dts/netgear,dgnd3700v2.dts | 14 +
arch/mips/dts/sagem,f at st1704.dts | 12 +
arch/mips/dts/sfr,nb4-ser.dts | 24 ++
arch/sandbox/dts/test.dts | 8 +
configs/comtrend_ar5315u_ram_defconfig | 7 +-
configs/comtrend_ar5387un_ram_defconfig | 7 +-
configs/comtrend_ct5361_ram_defconfig | 8 +-
configs/comtrend_vr3032u_ram_defconfig | 7 +-
configs/comtrend_wap5813n_ram_defconfig | 8 +-
configs/huawei_hg556a_ram_defconfig | 8 +-
configs/netgear_dgnd3700v2_ram_defconfig | 8 +-
configs/sagem_f@st1704_ram_defconfig | 8 +-
configs/sandbox_defconfig | 3 +
configs/sfr_nb4-ser_ram_defconfig | 8 +-
drivers/dma/Kconfig | 23 ++
drivers/dma/Makefile | 2 +
drivers/dma/bcm6348-iudma.c | 533 ++++++++++++++++++++++++++
drivers/dma/dma-uclass.c | 183 ++++++++-
drivers/dma/sandbox-dma-test.c | 282 ++++++++++++++
drivers/dma/ti-edma3.c | 2 +-
drivers/net/Kconfig | 18 +
drivers/net/Makefile | 2 +
drivers/net/bcm6348-eth.c | 576 ++++++++++++++++++++++++++++
drivers/net/bcm6368-eth.c | 604 ++++++++++++++++++++++++++++++
include/configs/bmips_common.h | 5 +-
include/dma-uclass.h | 128 +++++++
include/dma.h | 282 ++++++++++++--
include/dt-bindings/clock/bcm6318-clock.h | 11 +
include/dt-bindings/dma/bcm6318-dma.h | 15 +
include/dt-bindings/dma/bcm63268-dma.h | 15 +
include/dt-bindings/dma/bcm6328-dma.h | 15 +
include/dt-bindings/dma/bcm6338-dma.h | 15 +
include/dt-bindings/dma/bcm6348-dma.h | 17 +
include/dt-bindings/dma/bcm6358-dma.h | 17 +
include/dt-bindings/dma/bcm6362-dma.h | 15 +
include/dt-bindings/dma/bcm6368-dma.h | 15 +
test/dm/Makefile | 1 +
test/dm/dma.c | 123 ++++++
52 files changed, 3410 insertions(+), 40 deletions(-)
create mode 100644 drivers/dma/bcm6348-iudma.c
create mode 100644 drivers/dma/sandbox-dma-test.c
create mode 100644 drivers/net/bcm6348-eth.c
create mode 100644 drivers/net/bcm6368-eth.c
create mode 100644 include/dma-uclass.h
create mode 100644 include/dt-bindings/dma/bcm6318-dma.h
create mode 100644 include/dt-bindings/dma/bcm63268-dma.h
create mode 100644 include/dt-bindings/dma/bcm6328-dma.h
create mode 100644 include/dt-bindings/dma/bcm6338-dma.h
create mode 100644 include/dt-bindings/dma/bcm6348-dma.h
create mode 100644 include/dt-bindings/dma/bcm6358-dma.h
create mode 100644 include/dt-bindings/dma/bcm6362-dma.h
create mode 100644 include/dt-bindings/dma/bcm6368-dma.h
create mode 100644 test/dm/dma.c

--
2.11.0