1b36970f2SChengwen Feng.. SPDX-License-Identifier: BSD-3-Clause 2b36970f2SChengwen Feng Copyright 2021 HiSilicon Limited 3b36970f2SChengwen Feng 4*41dd9a6bSDavid YoungDirect Memory Access (DMA) Device Library 5*41dd9a6bSDavid Young========================================= 6b36970f2SChengwen Feng 7b36970f2SChengwen FengThe DMA library provides a DMA device framework for management and provisioning 8b36970f2SChengwen Fengof hardware and software DMA poll mode drivers, defining generic API which 9b36970f2SChengwen Fengsupport a number of different DMA operations. 10b36970f2SChengwen Feng 11b36970f2SChengwen Feng 12b36970f2SChengwen FengDesign Principles 13b36970f2SChengwen Feng----------------- 14b36970f2SChengwen Feng 15b36970f2SChengwen FengThe DMA framework provides a generic DMA device framework which supports both 16b36970f2SChengwen Fengphysical (hardware) and virtual (software) DMA devices, as well as a generic DMA 17b36970f2SChengwen FengAPI which allows DMA devices to be managed and configured, and supports DMA 18b36970f2SChengwen Fengoperations to be provisioned on DMA poll mode driver. 19b36970f2SChengwen Feng 20b36970f2SChengwen Feng.. _figure_dmadev: 21b36970f2SChengwen Feng 22b36970f2SChengwen Feng.. figure:: img/dmadev.* 23b36970f2SChengwen Feng 24b36970f2SChengwen FengThe above figure shows the model on which the DMA framework is built on: 25b36970f2SChengwen Feng 26b36970f2SChengwen Feng * The DMA controller could have multiple hardware DMA channels (aka. hardware 27b36970f2SChengwen Feng DMA queues), each hardware DMA channel should be represented by a dmadev. 28b36970f2SChengwen Feng * The dmadev could create multiple virtual DMA channels, each virtual DMA 29b36970f2SChengwen Feng channel represents a different transfer context. 30b36970f2SChengwen Feng * The DMA operation request must be submitted to the virtual DMA channel. 31b36970f2SChengwen Feng 32b36970f2SChengwen Feng 33b36970f2SChengwen FengDevice Management 34b36970f2SChengwen Feng----------------- 35b36970f2SChengwen Feng 36b36970f2SChengwen FengDevice Creation 37b36970f2SChengwen Feng~~~~~~~~~~~~~~~ 38b36970f2SChengwen Feng 39b36970f2SChengwen FengPhysical DMA controllers are discovered during the PCI probe/enumeration of the 40b36970f2SChengwen FengEAL function which is executed at DPDK initialization, this is based on their 41b36970f2SChengwen FengPCI BDF (bus/bridge, device, function). Specific physical DMA controllers, like 42b36970f2SChengwen Fengother physical devices in DPDK can be listed using the EAL command line options. 43b36970f2SChengwen Feng 44b36970f2SChengwen FengThe dmadevs are dynamically allocated by using the function 45b36970f2SChengwen Feng``rte_dma_pmd_allocate`` based on the number of hardware DMA channels. 46b36970f2SChengwen Feng 47b36970f2SChengwen Feng 48b36970f2SChengwen FengDevice Identification 49b36970f2SChengwen Feng~~~~~~~~~~~~~~~~~~~~~ 50b36970f2SChengwen Feng 51b36970f2SChengwen FengEach DMA device, whether physical or virtual is uniquely designated by two 52b36970f2SChengwen Fengidentifiers: 53b36970f2SChengwen Feng 54b36970f2SChengwen Feng- A unique device index used to designate the DMA device in all functions 55b36970f2SChengwen Feng exported by the DMA API. 56b36970f2SChengwen Feng 57b36970f2SChengwen Feng- A device name used to designate the DMA device in console messages, for 58b36970f2SChengwen Feng administration or debugging purposes. 59e0180db1SChengwen Feng 60e0180db1SChengwen Feng 61e0180db1SChengwen FengDevice Features and Capabilities 62e0180db1SChengwen Feng-------------------------------- 63e0180db1SChengwen Feng 64e0180db1SChengwen FengDMA devices may support different feature sets. The ``rte_dma_info_get`` API 65e0180db1SChengwen Fengcan be used to get the device info and supported features. 66e0180db1SChengwen Feng 67e0180db1SChengwen FengSilent mode is a special device capability which does not require the 68e0180db1SChengwen Fengapplication to invoke dequeue APIs. 6991e581e5SChengwen Feng 703d36a0a1SKevin Laatz.. _dmadev_enqueue_dequeue: 713d36a0a1SKevin Laatz 7291e581e5SChengwen Feng 7391e581e5SChengwen FengEnqueue / Dequeue APIs 7491e581e5SChengwen Feng~~~~~~~~~~~~~~~~~~~~~~ 7591e581e5SChengwen Feng 7691e581e5SChengwen FengEnqueue APIs such as ``rte_dma_copy`` and ``rte_dma_fill`` can be used to 7791e581e5SChengwen Fengenqueue operations to hardware. If an enqueue is successful, a ``ring_idx`` is 7891e581e5SChengwen Fengreturned. This ``ring_idx`` can be used by applications to track per operation 7991e581e5SChengwen Fengmetadata in an application-defined circular ring. 8091e581e5SChengwen Feng 8191e581e5SChengwen FengThe ``rte_dma_submit`` API is used to issue doorbell to hardware. 8291e581e5SChengwen FengAlternatively the ``RTE_DMA_OP_FLAG_SUBMIT`` flag can be passed to the enqueue 8391e581e5SChengwen FengAPIs to also issue the doorbell to hardware. 8491e581e5SChengwen Feng 853d36a0a1SKevin LaatzThe following code demonstrates how to enqueue a burst of copies to the 863d36a0a1SKevin Laatzdevice and start the hardware processing of them: 873d36a0a1SKevin Laatz 883d36a0a1SKevin Laatz.. code-block:: C 893d36a0a1SKevin Laatz 903d36a0a1SKevin Laatz struct rte_mbuf *srcs[DMA_BURST_SZ], *dsts[DMA_BURST_SZ]; 913d36a0a1SKevin Laatz unsigned int i; 923d36a0a1SKevin Laatz 933d36a0a1SKevin Laatz for (i = 0; i < RTE_DIM(srcs); i++) { 943d36a0a1SKevin Laatz if (rte_dma_copy(dev_id, vchan, rte_pktmbuf_iova(srcs[i]), 953d36a0a1SKevin Laatz rte_pktmbuf_iova(dsts[i]), COPY_LEN, 0) < 0) { 963d36a0a1SKevin Laatz PRINT_ERR("Error with rte_dma_copy for buffer %u\n", i); 973d36a0a1SKevin Laatz return -1; 983d36a0a1SKevin Laatz } 993d36a0a1SKevin Laatz } 1003d36a0a1SKevin Laatz rte_dma_submit(dev_id, vchan); 1013d36a0a1SKevin Laatz 10291e581e5SChengwen FengThere are two dequeue APIs ``rte_dma_completed`` and 10391e581e5SChengwen Feng``rte_dma_completed_status``, these are used to obtain the results of the 10491e581e5SChengwen Fengenqueue requests. ``rte_dma_completed`` will return the number of successfully 10591e581e5SChengwen Fengcompleted operations. ``rte_dma_completed_status`` will return the number of 10691e581e5SChengwen Fengcompleted operations along with the status of each operation (filled into the 10791e581e5SChengwen Feng``status`` array passed by user). These two APIs can also return the last 10891e581e5SChengwen Fengcompleted operation's ``ring_idx`` which could help user track operations within 10991e581e5SChengwen Fengtheir own application-defined rings. 110280c3ca0SKevin Laatz 111280c3ca0SKevin Laatz 112280c3ca0SKevin LaatzQuerying Device Statistics 113280c3ca0SKevin Laatz~~~~~~~~~~~~~~~~~~~~~~~~~~ 114280c3ca0SKevin Laatz 115280c3ca0SKevin LaatzThe statistics from a dmadev device can be got via the statistics functions, 116280c3ca0SKevin Laatzi.e. ``rte_dma_stats_get()``. The statistics returned for each device instance are: 117280c3ca0SKevin Laatz 118280c3ca0SKevin Laatz* ``submitted``: The number of operations submitted to the device. 119280c3ca0SKevin Laatz* ``completed``: The number of operations which have completed (successful and failed). 120280c3ca0SKevin Laatz* ``errors``: The number of operations that completed with error. 12139b5ab60SSean Morrissey 12239b5ab60SSean MorrisseyThe dmadev library has support for displaying DMA device information 12339b5ab60SSean Morrisseythrough the Telemetry interface. Telemetry commands that can be used 12439b5ab60SSean Morrisseyare shown below. 12539b5ab60SSean Morrissey 12639b5ab60SSean Morrissey#. Get the list of available DMA devices by ID:: 12739b5ab60SSean Morrissey 12839b5ab60SSean Morrissey --> /dmadev/list 12939b5ab60SSean Morrissey {"/dmadev/list": [0, 1]} 13039b5ab60SSean Morrissey 13139b5ab60SSean Morrissey#. Get general information from a DMA device by passing the device id as a parameter:: 13239b5ab60SSean Morrissey 13339b5ab60SSean Morrissey --> /dmadev/info,0 13439b5ab60SSean Morrissey {"/dmadev/info": {"name": "0000:00:01.0", "nb_vchans": 1, "numa_node": 0, "max_vchans": 1, "max_desc": 4096, 13539b5ab60SSean Morrissey "min_desc": 32, "max_sges": 0, "capabilities": {"mem2mem": 1, "mem2dev": 0, "dev2mem": 0, ...}}} 13639b5ab60SSean Morrissey 13739b5ab60SSean Morrissey#. Get the statistics for a particular DMA device and virtual DMA channel by passing the device id and vchan id as parameters 13839b5ab60SSean Morrissey (if a DMA device only has one virtual DMA channel you only need to pass the device id):: 13939b5ab60SSean Morrissey 14039b5ab60SSean Morrissey --> /dmadev/stats,0,0 14139b5ab60SSean Morrissey {"/dmadev/stats": {"submitted": 0, "completed": 0, "errors": 0}} 14239b5ab60SSean Morrissey 14339b5ab60SSean MorrisseyFor more information on how to use the Telemetry interface, see 14439b5ab60SSean Morrisseythe :doc:`../howto/telemetry`. 145