LCOV - code coverage report
Current view: top level - lib/dmadev - rte_dmadev.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 20 0.0 %
Date: 2025-11-01 17:50:34 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2021 HiSilicon Limited
       3                 :            :  * Copyright(c) 2021 Intel Corporation
       4                 :            :  * Copyright(c) 2021 Marvell International Ltd
       5                 :            :  * Copyright(c) 2021 SmartShare Systems
       6                 :            :  */
       7                 :            : 
       8                 :            : #ifndef RTE_DMADEV_H
       9                 :            : #define RTE_DMADEV_H
      10                 :            : 
      11                 :            : /**
      12                 :            :  * @file rte_dmadev.h
      13                 :            :  *
      14                 :            :  * DMA (Direct Memory Access) device API.
      15                 :            :  *
      16                 :            :  * The DMA framework is built on the following model:
      17                 :            :  *
      18                 :            :  *     ---------------   ---------------       ---------------
      19                 :            :  *     | virtual DMA |   | virtual DMA |       | virtual DMA |
      20                 :            :  *     | channel     |   | channel     |       | channel     |
      21                 :            :  *     ---------------   ---------------       ---------------
      22                 :            :  *            |                |                      |
      23                 :            :  *            ------------------                      |
      24                 :            :  *                     |                              |
      25                 :            :  *               ------------                    ------------
      26                 :            :  *               |  dmadev  |                    |  dmadev  |
      27                 :            :  *               ------------                    ------------
      28                 :            :  *                     |                              |
      29                 :            :  *            ------------------               ------------------
      30                 :            :  *            | HW DMA channel |               | HW DMA channel |
      31                 :            :  *            ------------------               ------------------
      32                 :            :  *                     |                              |
      33                 :            :  *                     --------------------------------
      34                 :            :  *                                     |
      35                 :            :  *                           ---------------------
      36                 :            :  *                           | HW DMA Controller |
      37                 :            :  *                           ---------------------
      38                 :            :  *
      39                 :            :  * The DMA controller could have multiple HW-DMA-channels (aka. HW-DMA-queues),
      40                 :            :  * each HW-DMA-channel should be represented by a dmadev.
      41                 :            :  *
      42                 :            :  * The dmadev could create multiple virtual DMA channels, each virtual DMA
      43                 :            :  * channel represents a different transfer context. The DMA operation request
      44                 :            :  * must be submitted to the virtual DMA channel. e.g. Application could create
      45                 :            :  * virtual DMA channel 0 for memory-to-memory transfer scenario, and create
      46                 :            :  * virtual DMA channel 1 for memory-to-device transfer scenario.
      47                 :            :  *
      48                 :            :  * This framework uses 'int16_t dev_id' as the device identifier of a dmadev,
      49                 :            :  * and 'uint16_t vchan' as the virtual DMA channel identifier in one dmadev.
      50                 :            :  *
      51                 :            :  * The functions exported by the dmadev API to setup a device designated by its
      52                 :            :  * device identifier must be invoked in the following order:
      53                 :            :  *     - rte_dma_configure()
      54                 :            :  *     - rte_dma_vchan_setup()
      55                 :            :  *     - rte_dma_start()
      56                 :            :  *
      57                 :            :  * Then, the application can invoke dataplane functions to process jobs.
      58                 :            :  *
      59                 :            :  * If the application wants to change the configuration (i.e. invoke
      60                 :            :  * rte_dma_configure() or rte_dma_vchan_setup()), it must invoke
      61                 :            :  * rte_dma_stop() first to stop the device and then do the reconfiguration
      62                 :            :  * before invoking rte_dma_start() again. The dataplane functions should not
      63                 :            :  * be invoked when the device is stopped.
      64                 :            :  *
      65                 :            :  * Finally, an application can close a dmadev by invoking the rte_dma_close()
      66                 :            :  * function.
      67                 :            :  *
      68                 :            :  * The dataplane APIs include two parts:
      69                 :            :  * The first part is the submission of operation requests:
      70                 :            :  *     - rte_dma_copy()
      71                 :            :  *     - rte_dma_copy_sg()
      72                 :            :  *     - rte_dma_fill()
      73                 :            :  *     - rte_dma_submit()
      74                 :            :  *
      75                 :            :  * These APIs could work with different virtual DMA channels which have
      76                 :            :  * different contexts.
      77                 :            :  *
      78                 :            :  * The first three APIs are used to submit the operation request to the virtual
      79                 :            :  * DMA channel, if the submission is successful, a positive
      80                 :            :  * ring_idx <= UINT16_MAX is returned, otherwise a negative number is returned.
      81                 :            :  *
      82                 :            :  * The last API is used to issue doorbell to hardware, and also there are flags
      83                 :            :  * (@see RTE_DMA_OP_FLAG_SUBMIT) parameter of the first three APIs could do the
      84                 :            :  * same work.
      85                 :            :  * @note When enqueuing a set of jobs to the device, having a separate submit
      86                 :            :  * outside a loop makes for clearer code than having a check for the last
      87                 :            :  * iteration inside the loop to set a special submit flag.  However, for cases
      88                 :            :  * where one item alone is to be submitted or there is a small set of jobs to
      89                 :            :  * be submitted sequentially, having a submit flag provides a lower-overhead
      90                 :            :  * way of doing the submission while still keeping the code clean.
      91                 :            :  *
      92                 :            :  * The second part is to obtain the result of requests:
      93                 :            :  *     - rte_dma_completed()
      94                 :            :  *         - return the number of operation requests completed successfully.
      95                 :            :  *     - rte_dma_completed_status()
      96                 :            :  *         - return the number of operation requests completed.
      97                 :            :  *
      98                 :            :  * @note If the dmadev works in silent mode (@see RTE_DMA_CAPA_SILENT),
      99                 :            :  * application does not invoke the above two completed APIs.
     100                 :            :  *
     101                 :            :  * About the ring_idx which enqueue APIs (e.g. rte_dma_copy(), rte_dma_fill())
     102                 :            :  * return, the rules are as follows:
     103                 :            :  *     - ring_idx for each virtual DMA channel are independent.
     104                 :            :  *     - For a virtual DMA channel, the ring_idx is monotonically incremented,
     105                 :            :  *       when it reach UINT16_MAX, it wraps back to zero.
     106                 :            :  *     - This ring_idx can be used by applications to track per-operation
     107                 :            :  *       metadata in an application-defined circular ring.
     108                 :            :  *     - The initial ring_idx of a virtual DMA channel is zero, after the
     109                 :            :  *       device is stopped, the ring_idx needs to be reset to zero.
     110                 :            :  *
     111                 :            :  * One example:
     112                 :            :  *     - step-1: start one dmadev
     113                 :            :  *     - step-2: enqueue a copy operation, the ring_idx return is 0
     114                 :            :  *     - step-3: enqueue a copy operation again, the ring_idx return is 1
     115                 :            :  *     - ...
     116                 :            :  *     - step-101: stop the dmadev
     117                 :            :  *     - step-102: start the dmadev
     118                 :            :  *     - step-103: enqueue a copy operation, the ring_idx return is 0
     119                 :            :  *     - ...
     120                 :            :  *     - step-x+0: enqueue a fill operation, the ring_idx return is 65535
     121                 :            :  *     - step-x+1: enqueue a copy operation, the ring_idx return is 0
     122                 :            :  *     - ...
     123                 :            :  *
     124                 :            :  * The DMA operation address used in enqueue APIs (i.e. rte_dma_copy(),
     125                 :            :  * rte_dma_copy_sg(), rte_dma_fill()) is defined as rte_iova_t type.
     126                 :            :  *
     127                 :            :  * The dmadev supports two types of address: memory address and device address.
     128                 :            :  *
     129                 :            :  * - memory address: the source and destination address of the memory-to-memory
     130                 :            :  * transfer type, or the source address of the memory-to-device transfer type,
     131                 :            :  * or the destination address of the device-to-memory transfer type.
     132                 :            :  * @note If the device support SVA (@see RTE_DMA_CAPA_SVA), the memory address
     133                 :            :  * can be any VA address, otherwise it must be an IOVA address.
     134                 :            :  *
     135                 :            :  * - device address: the source and destination address of the device-to-device
     136                 :            :  * transfer type, or the source address of the device-to-memory transfer type,
     137                 :            :  * or the destination address of the memory-to-device transfer type.
     138                 :            :  *
     139                 :            :  * About MT-safe, all the functions of the dmadev API implemented by a PMD are
     140                 :            :  * lock-free functions which assume to not be invoked in parallel on different
     141                 :            :  * logical cores to work on the same target dmadev object.
     142                 :            :  * @note Different virtual DMA channels on the same dmadev *DO NOT* support
     143                 :            :  * parallel invocation because these virtual DMA channels share the same
     144                 :            :  * HW-DMA-channel.
     145                 :            :  */
     146                 :            : 
     147                 :            : #include <stdint.h>
     148                 :            : 
     149                 :            : #include <rte_bitops.h>
     150                 :            : #include <rte_common.h>
     151                 :            : #include <rte_uuid.h>
     152                 :            : 
     153                 :            : #ifdef __cplusplus
     154                 :            : extern "C" {
     155                 :            : #endif
     156                 :            : 
     157                 :            : /** Maximum number of devices if rte_dma_dev_max() is not called. */
     158                 :            : #define RTE_DMADEV_DEFAULT_MAX 64
     159                 :            : 
     160                 :            : /**
     161                 :            :  * Configure the maximum number of dmadevs.
     162                 :            :  * @note This function can be invoked before the primary process rte_eal_init()
     163                 :            :  * to change the maximum number of dmadevs. If not invoked, the maximum number
     164                 :            :  * of dmadevs is @see RTE_DMADEV_DEFAULT_MAX
     165                 :            :  *
     166                 :            :  * @param dev_max
     167                 :            :  *   maximum number of dmadevs.
     168                 :            :  *
     169                 :            :  * @return
     170                 :            :  *   0 on success. Otherwise negative value is returned.
     171                 :            :  */
     172                 :            : int rte_dma_dev_max(size_t dev_max);
     173                 :            : 
     174                 :            : /**
     175                 :            :  * Get the device identifier for the named DMA device.
     176                 :            :  *
     177                 :            :  * @param name
     178                 :            :  *   DMA device name.
     179                 :            :  *
     180                 :            :  * @return
     181                 :            :  *   Returns DMA device identifier on success.
     182                 :            :  *   - <0: Failure to find named DMA device.
     183                 :            :  */
     184                 :            : int rte_dma_get_dev_id_by_name(const char *name);
     185                 :            : 
     186                 :            : /**
     187                 :            :  * Check whether the dev_id is valid.
     188                 :            :  *
     189                 :            :  * @param dev_id
     190                 :            :  *   DMA device index.
     191                 :            :  *
     192                 :            :  * @return
     193                 :            :  *   - If the device index is valid (true) or not (false).
     194                 :            :  */
     195                 :            : bool rte_dma_is_valid(int16_t dev_id);
     196                 :            : 
     197                 :            : /**
     198                 :            :  * Get the total number of DMA devices that have been successfully
     199                 :            :  * initialised.
     200                 :            :  *
     201                 :            :  * @return
     202                 :            :  *   The total number of usable DMA devices.
     203                 :            :  */
     204                 :            : uint16_t rte_dma_count_avail(void);
     205                 :            : 
     206                 :            : /**
     207                 :            :  * Iterates over valid dmadev instances.
     208                 :            :  *
     209                 :            :  * @param start_dev_id
     210                 :            :  *   The id of the next possible dmadev.
     211                 :            :  * @return
     212                 :            :  *   Next valid dmadev, UINT16_MAX if there is none.
     213                 :            :  */
     214                 :            : int16_t rte_dma_next_dev(int16_t start_dev_id);
     215                 :            : 
     216                 :            : /** Utility macro to iterate over all available dmadevs */
     217                 :            : #define RTE_DMA_FOREACH_DEV(p) \
     218                 :            :         for (p = rte_dma_next_dev(0); \
     219                 :            :              p != -1; \
     220                 :            :              p = rte_dma_next_dev(p + 1))
     221                 :            : 
     222                 :            : 
     223                 :            : /**@{@name DMA capability
     224                 :            :  * @see struct rte_dma_info::dev_capa
     225                 :            :  */
     226                 :            : /** Support memory-to-memory transfer */
     227                 :            : #define RTE_DMA_CAPA_MEM_TO_MEM         RTE_BIT64(0)
     228                 :            : /** Support memory-to-device transfer. */
     229                 :            : #define RTE_DMA_CAPA_MEM_TO_DEV         RTE_BIT64(1)
     230                 :            : /** Support device-to-memory transfer. */
     231                 :            : #define RTE_DMA_CAPA_DEV_TO_MEM         RTE_BIT64(2)
     232                 :            : /** Support device-to-device transfer. */
     233                 :            : #define RTE_DMA_CAPA_DEV_TO_DEV         RTE_BIT64(3)
     234                 :            : /** Support SVA which could use VA as DMA address.
     235                 :            :  * If device support SVA then application could pass any VA address like memory
     236                 :            :  * from rte_malloc(), rte_memzone(), malloc, stack memory.
     237                 :            :  * If device don't support SVA, then application should pass IOVA address which
     238                 :            :  * from rte_malloc(), rte_memzone().
     239                 :            :  */
     240                 :            : #define RTE_DMA_CAPA_SVA                RTE_BIT64(4)
     241                 :            : /** Support work in silent mode.
     242                 :            :  * In this mode, application don't required to invoke rte_dma_completed*()
     243                 :            :  * API.
     244                 :            :  * @see struct rte_dma_conf::silent_mode
     245                 :            :  */
     246                 :            : #define RTE_DMA_CAPA_SILENT             RTE_BIT64(5)
     247                 :            : /** Supports error handling
     248                 :            :  *
     249                 :            :  * With this bit set, invalid input addresses will be reported as operation failures
     250                 :            :  * to the user but other operations can continue.
     251                 :            :  * Without this bit set, invalid data is not handled by either HW or driver, so user
     252                 :            :  * must ensure that all memory addresses are valid and accessible by HW.
     253                 :            :  */
     254                 :            : #define RTE_DMA_CAPA_HANDLES_ERRORS     RTE_BIT64(6)
     255                 :            : /** Support auto free for source buffer once mem to dev transfer is completed.
     256                 :            :  *
     257                 :            :  * @note Even though the DMA driver has this capability, it may not support all
     258                 :            :  * mempool drivers. If the mempool is not supported by the DMA driver,
     259                 :            :  * rte_dma_vchan_setup() will fail.
     260                 :            :  */
     261                 :            : #define RTE_DMA_CAPA_M2D_AUTO_FREE      RTE_BIT64(7)
     262                 :            : /** Support strict priority scheduling.
     263                 :            :  *
     264                 :            :  * Application could assign fixed priority to the DMA device using 'priority'
     265                 :            :  * field in struct rte_dma_conf. Number of supported priority levels will be
     266                 :            :  * known from 'nb_priorities' field in struct rte_dma_info.
     267                 :            :  */
     268                 :            : #define RTE_DMA_CAPA_PRI_POLICY_SP      RTE_BIT64(8)
     269                 :            : /** Support inter-process DMA transfers.
     270                 :            :  *
     271                 :            :  * When this bit is set, the DMA device can perform memory transfers
     272                 :            :  * between different process memory spaces.
     273                 :            :  */
     274                 :            : #define RTE_DMA_CAPA_INTER_PROCESS_DOMAIN       RTE_BIT64(9)
     275                 :            : /** Support inter-OS domain DMA transfers.
     276                 :            :  *
     277                 :            :  * The DMA device can perform memory transfers
     278                 :            :  * across different operating system domains.
     279                 :            :  */
     280                 :            : #define RTE_DMA_CAPA_INTER_OS_DOMAIN            RTE_BIT64(10)
     281                 :            : 
     282                 :            : /** Support copy operation.
     283                 :            :  * This capability start with index of 32, so that it could leave gap between
     284                 :            :  * normal capability and ops capability.
     285                 :            :  */
     286                 :            : #define RTE_DMA_CAPA_OPS_COPY           RTE_BIT64(32)
     287                 :            : /** Support scatter-gather list copy operation. */
     288                 :            : #define RTE_DMA_CAPA_OPS_COPY_SG        RTE_BIT64(33)
     289                 :            : /** Support fill operation. */
     290                 :            : #define RTE_DMA_CAPA_OPS_FILL           RTE_BIT64(34)
     291                 :            : /** Support enqueue and dequeue operations. */
     292                 :            : #define RTE_DMA_CAPA_OPS_ENQ_DEQ        RTE_BIT64(35)
     293                 :            : /**@}*/
     294                 :            : 
     295                 :            : /** DMA device configuration flags.
     296                 :            :  * @see struct rte_dma_conf::flags
     297                 :            :  */
     298                 :            : /** Operate in silent mode
     299                 :            :  * @see RTE_DMA_CAPA_SILENT
     300                 :            :  */
     301                 :            : #define RTE_DMA_CFG_FLAG_SILENT RTE_BIT64(0)
     302                 :            : /** Enable enqueue and dequeue operations
     303                 :            :  * @see RTE_DMA_CAPA_OPS_ENQ_DEQ
     304                 :            :  */
     305                 :            : #define RTE_DMA_CFG_FLAG_ENQ_DEQ RTE_BIT64(1)
     306                 :            : 
     307                 :            : /**
     308                 :            :  * A structure used to retrieve the information of a DMA device.
     309                 :            :  *
     310                 :            :  * @see rte_dma_info_get
     311                 :            :  */
     312                 :            : struct rte_dma_info {
     313                 :            :         const char *dev_name; /**< Unique device name. */
     314                 :            :         /** Device capabilities (RTE_DMA_CAPA_*). */
     315                 :            :         uint64_t dev_capa;
     316                 :            :         /** Maximum number of virtual DMA channels supported. */
     317                 :            :         uint16_t max_vchans;
     318                 :            :         /** Maximum allowed number of virtual DMA channel descriptors. */
     319                 :            :         uint16_t max_desc;
     320                 :            :         /** Minimum allowed number of virtual DMA channel descriptors. */
     321                 :            :         uint16_t min_desc;
     322                 :            :         /** Maximum number of source or destination scatter-gather entry
     323                 :            :          * supported.
     324                 :            :          * If the device does not support COPY_SG capability, this value can be
     325                 :            :          * zero.
     326                 :            :          * If the device supports COPY_SG capability, then rte_dma_copy_sg()
     327                 :            :          * parameter nb_src/nb_dst should not exceed this value.
     328                 :            :          */
     329                 :            :         uint16_t max_sges;
     330                 :            :         /** NUMA node connection, -1 if unknown. */
     331                 :            :         int16_t numa_node;
     332                 :            :         /** Number of virtual DMA channel configured. */
     333                 :            :         uint16_t nb_vchans;
     334                 :            :         /** Number of priority levels (must be > 1) if priority scheduling is supported,
     335                 :            :          * 0 otherwise.
     336                 :            :          */
     337                 :            :         uint16_t nb_priorities;
     338                 :            : };
     339                 :            : 
     340                 :            : /**
     341                 :            :  * Retrieve information of a DMA device.
     342                 :            :  *
     343                 :            :  * @param dev_id
     344                 :            :  *   The identifier of the device.
     345                 :            :  * @param[out] dev_info
     346                 :            :  *   A pointer to a structure of type *rte_dma_info* to be filled with the
     347                 :            :  *   information of the device.
     348                 :            :  *
     349                 :            :  * @return
     350                 :            :  *   0 on success. Otherwise negative value is returned.
     351                 :            :  */
     352                 :            : int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info);
     353                 :            : 
     354                 :            : /**
     355                 :            :  * A structure used to configure a DMA device.
     356                 :            :  *
     357                 :            :  * @see rte_dma_configure
     358                 :            :  */
     359                 :            : struct rte_dma_conf {
     360                 :            :         /** The number of virtual DMA channels to set up for the DMA device.
     361                 :            :          * This value cannot be greater than the field 'max_vchans' of struct
     362                 :            :          * rte_dma_info which get from rte_dma_info_get().
     363                 :            :          */
     364                 :            :         uint16_t nb_vchans;
     365                 :            :         /* The priority of the DMA device.
     366                 :            :          * This value should be lower than the field 'nb_priorities' of struct
     367                 :            :          * rte_dma_info which get from rte_dma_info_get(). If the DMA device
     368                 :            :          * does not support priority scheduling, this value should be zero.
     369                 :            :          *
     370                 :            :          * Lowest value indicates higher priority and vice-versa.
     371                 :            :          */
     372                 :            :         uint16_t priority;
     373                 :            :         /** DMA device configuration flags defined as RTE_DMA_CFG_FLAG_*. */
     374                 :            :         uint64_t flags;
     375                 :            : };
     376                 :            : 
     377                 :            : /**
     378                 :            :  * Configure a DMA device.
     379                 :            :  *
     380                 :            :  * This function must be invoked first before any other function in the
     381                 :            :  * API. This function can also be re-invoked when a device is in the
     382                 :            :  * stopped state.
     383                 :            :  *
     384                 :            :  * @param dev_id
     385                 :            :  *   The identifier of the device to configure.
     386                 :            :  * @param dev_conf
     387                 :            :  *   The DMA device configuration structure encapsulated into rte_dma_conf
     388                 :            :  *   object.
     389                 :            :  *
     390                 :            :  * @return
     391                 :            :  *   0 on success. Otherwise negative value is returned.
     392                 :            :  */
     393                 :            : int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf);
     394                 :            : 
     395                 :            : /**
     396                 :            :  * Start a DMA device.
     397                 :            :  *
     398                 :            :  * The device start step is the last one and consists of setting the DMA
     399                 :            :  * to start accepting jobs.
     400                 :            :  *
     401                 :            :  * @param dev_id
     402                 :            :  *   The identifier of the device.
     403                 :            :  *
     404                 :            :  * @return
     405                 :            :  *   0 on success. Otherwise negative value is returned.
     406                 :            :  */
     407                 :            : int rte_dma_start(int16_t dev_id);
     408                 :            : 
     409                 :            : /**
     410                 :            :  * Stop a DMA device.
     411                 :            :  *
     412                 :            :  * The device can be restarted with a call to rte_dma_start().
     413                 :            :  *
     414                 :            :  * @param dev_id
     415                 :            :  *   The identifier of the device.
     416                 :            :  *
     417                 :            :  * @return
     418                 :            :  *   0 on success. Otherwise negative value is returned.
     419                 :            :  */
     420                 :            : int rte_dma_stop(int16_t dev_id);
     421                 :            : 
     422                 :            : /**
     423                 :            :  * Close a DMA device.
     424                 :            :  *
     425                 :            :  * The device cannot be restarted after this call.
     426                 :            :  *
     427                 :            :  * @param dev_id
     428                 :            :  *   The identifier of the device.
     429                 :            :  *
     430                 :            :  * @return
     431                 :            :  *   0 on success. Otherwise negative value is returned.
     432                 :            :  */
     433                 :            : int rte_dma_close(int16_t dev_id);
     434                 :            : 
     435                 :            : /**
     436                 :            :  * DMA transfer direction defines.
     437                 :            :  *
     438                 :            :  * @see struct rte_dma_vchan_conf::direction
     439                 :            :  */
     440                 :            : enum rte_dma_direction {
     441                 :            :         /** DMA transfer direction - from memory to memory.
     442                 :            :          * When the device supports inter-process or inter-OS domain transfers,
     443                 :            :          * the field `type` in `struct rte_dma_vchan_conf::domain`
     444                 :            :          * specifies the type of domain.
     445                 :            :          * For memory-to-memory transfers within the same domain or process,
     446                 :            :          * `type` should be set to `RTE_DMA_INTER_DOMAIN_NONE`.
     447                 :            :          *
     448                 :            :          * @see struct rte_dma_vchan_conf::direction
     449                 :            :          * @see struct rte_dma_inter_domain_param::type
     450                 :            :          */
     451                 :            :         RTE_DMA_DIR_MEM_TO_MEM,
     452                 :            :         /** DMA transfer direction - from memory to device.
     453                 :            :          * In a typical scenario, the SoCs are installed on host servers as
     454                 :            :          * iNICs through the PCIe interface. In this case, the SoCs works in
     455                 :            :          * EP(endpoint) mode, it could initiate a DMA move request from memory
     456                 :            :          * (which is SoCs memory) to device (which is host memory).
     457                 :            :          *
     458                 :            :          * @see struct rte_dma_vchan_conf::direction
     459                 :            :          */
     460                 :            :         RTE_DMA_DIR_MEM_TO_DEV,
     461                 :            :         /** DMA transfer direction - from device to memory.
     462                 :            :          * In a typical scenario, the SoCs are installed on host servers as
     463                 :            :          * iNICs through the PCIe interface. In this case, the SoCs works in
     464                 :            :          * EP(endpoint) mode, it could initiate a DMA move request from device
     465                 :            :          * (which is host memory) to memory (which is SoCs memory).
     466                 :            :          *
     467                 :            :          * @see struct rte_dma_vchan_conf::direction
     468                 :            :          */
     469                 :            :         RTE_DMA_DIR_DEV_TO_MEM,
     470                 :            :         /** DMA transfer direction - from device to device.
     471                 :            :          * In a typical scenario, the SoCs are installed on host servers as
     472                 :            :          * iNICs through the PCIe interface. In this case, the SoCs works in
     473                 :            :          * EP(endpoint) mode, it could initiate a DMA move request from device
     474                 :            :          * (which is host memory) to the device (which is another host memory).
     475                 :            :          *
     476                 :            :          * @see struct rte_dma_vchan_conf::direction
     477                 :            :          */
     478                 :            :         RTE_DMA_DIR_DEV_TO_DEV,
     479                 :            : };
     480                 :            : 
     481                 :            : /**
     482                 :            :  * DMA access port type defines.
     483                 :            :  *
     484                 :            :  * @see struct rte_dma_port_param::port_type
     485                 :            :  */
     486                 :            : enum rte_dma_port_type {
     487                 :            :         RTE_DMA_PORT_NONE,
     488                 :            :         RTE_DMA_PORT_PCIE, /**< The DMA access port is PCIe. */
     489                 :            : };
     490                 :            : 
     491                 :            : /**
     492                 :            :  * A structure used to descript DMA access port parameters.
     493                 :            :  *
     494                 :            :  * @see struct rte_dma_vchan_conf::src_port
     495                 :            :  * @see struct rte_dma_vchan_conf::dst_port
     496                 :            :  */
     497                 :            : struct rte_dma_port_param {
     498                 :            :         /** The device access port type.
     499                 :            :          *
     500                 :            :          * @see enum rte_dma_port_type
     501                 :            :          */
     502                 :            :         enum rte_dma_port_type port_type;
     503                 :            :         union {
     504                 :            :                 /** PCIe access port parameters.
     505                 :            :                  *
     506                 :            :                  * The following model shows SoC's PCIe module connects to
     507                 :            :                  * multiple PCIe hosts and multiple endpoints. The PCIe module
     508                 :            :                  * has an integrated DMA controller.
     509                 :            :                  *
     510                 :            :                  * If the DMA wants to access the memory of host A, it can be
     511                 :            :                  * initiated by PF1 in core0, or by VF0 of PF0 in core0.
     512                 :            :                  *
     513                 :            :                  * \code{.unparsed}
     514                 :            :                  * System Bus
     515                 :            :                  *    |     ----------PCIe module----------
     516                 :            :                  *    |     Bus
     517                 :            :                  *    |     Interface
     518                 :            :                  *    |     -----        ------------------
     519                 :            :                  *    |     |   |        | PCIe Core0     |
     520                 :            :                  *    |     |   |        |                |        -----------
     521                 :            :                  *    |     |   |        |   PF-0 -- VF-0 |        | Host A  |
     522                 :            :                  *    |     |   |--------|        |- VF-1 |--------| Root    |
     523                 :            :                  *    |     |   |        |   PF-1         |        | Complex |
     524                 :            :                  *    |     |   |        |   PF-2         |        -----------
     525                 :            :                  *    |     |   |        ------------------
     526                 :            :                  *    |     |   |
     527                 :            :                  *    |     |   |        ------------------
     528                 :            :                  *    |     |   |        | PCIe Core1     |
     529                 :            :                  *    |     |   |        |                |        -----------
     530                 :            :                  *    |     |   |        |   PF-0 -- VF-0 |        | Host B  |
     531                 :            :                  *    |-----|   |--------|   PF-1 -- VF-0 |--------| Root    |
     532                 :            :                  *    |     |   |        |        |- VF-1 |        | Complex |
     533                 :            :                  *    |     |   |        |   PF-2         |        -----------
     534                 :            :                  *    |     |   |        ------------------
     535                 :            :                  *    |     |   |
     536                 :            :                  *    |     |   |        ------------------
     537                 :            :                  *    |     |DMA|        |                |        ------
     538                 :            :                  *    |     |   |        |                |--------| EP |
     539                 :            :                  *    |     |   |--------| PCIe Core2     |        ------
     540                 :            :                  *    |     |   |        |                |        ------
     541                 :            :                  *    |     |   |        |                |--------| EP |
     542                 :            :                  *    |     |   |        |                |        ------
     543                 :            :                  *    |     -----        ------------------
     544                 :            :                  *
     545                 :            :                  * \endcode
     546                 :            :                  *
     547                 :            :                  * @note If some fields can not be supported by the
     548                 :            :                  * hardware/driver, then the driver ignores those fields.
     549                 :            :                  * Please check driver-specific documentation for limitations
     550                 :            :                  * and capabilities.
     551                 :            :                  */
     552                 :            :                 __extension__
     553                 :            :                 union {
     554                 :            :                         struct {
     555                 :            :                                 uint64_t coreid : 4; /**< PCIe core id used. */
     556                 :            :                                 uint64_t pfid : 8; /**< PF id used. */
     557                 :            :                                 uint64_t vfen : 1; /**< VF enable bit. */
     558                 :            :                                 uint64_t vfid : 16; /**< VF id used. */
     559                 :            :                                 /** The pasid filed in TLP packet. */
     560                 :            :                                 uint64_t pasid : 20;
     561                 :            :                                 /** The attributes filed in TLP packet. */
     562                 :            :                                 uint64_t attr : 3;
     563                 :            :                                 /** The processing hint filed in TLP packet. */
     564                 :            :                                 uint64_t ph : 2;
     565                 :            :                                 /** The steering tag filed in TLP packet. */
     566                 :            :                                 uint64_t st : 16;
     567                 :            :                         };
     568                 :            :                         uint64_t val;
     569                 :            :                 } pcie;
     570                 :            :         };
     571                 :            :         uint64_t reserved[2]; /**< Reserved for future fields. */
     572                 :            : };
     573                 :            : 
     574                 :            : /**
     575                 :            :  * A structure used for offload auto free params.
     576                 :            :  */
     577                 :            : struct rte_dma_auto_free_param {
     578                 :            :         union {
     579                 :            :                 struct {
     580                 :            :                         /**
     581                 :            :                          * Mempool from which buffer is allocated. Mempool info
     582                 :            :                          * is used for freeing buffer by hardware.
     583                 :            :                          *
     584                 :            :                          * @note If the mempool is not supported by the DMA device,
     585                 :            :                          * rte_dma_vchan_setup() will fail.
     586                 :            :                          */
     587                 :            :                         struct rte_mempool *pool;
     588                 :            :                 } m2d;
     589                 :            :         };
     590                 :            :         /** Reserved for future fields. */
     591                 :            :         uint64_t reserved[2];
     592                 :            : };
     593                 :            : 
     594                 :            : /**
     595                 :            :  * Inter-DMA transfer domain type.
     596                 :            :  *
     597                 :            :  * @warning
     598                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     599                 :            :  *
     600                 :            :  * This enum defines the types of transfer domains applicable to DMA operations.
     601                 :            :  * It helps categorize whether a DMA transfer is occurring within the same domain,
     602                 :            :  * across different processes, or between distinct operating system domains.
     603                 :            :  *
     604                 :            :  * @see struct rte_dma_inter_domain_param:type
     605                 :            :  */
     606                 :            : enum rte_dma_inter_domain_type {
     607                 :            :         /** No inter-domain transfer; standard DMA within same domain. */
     608                 :            :         RTE_DMA_INTER_DOMAIN_NONE,
     609                 :            :         /** Transfer occurs between different user-space processes. */
     610                 :            :         RTE_DMA_INTER_PROCESS_DOMAIN,
     611                 :            :         /** Transfer spans across different operating system domains. */
     612                 :            :         RTE_DMA_INTER_OS_DOMAIN,
     613                 :            : };
     614                 :            : 
     615                 :            : /**
     616                 :            :  * Parameters for inter-process or inter-OS DMA transfers.
     617                 :            :  *
     618                 :            :  * @warning
     619                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     620                 :            :  *
     621                 :            :  * This structure defines the parameters required to perform DMA transfers
     622                 :            :  * across different domains, such as between processes or operating systems.
     623                 :            :  * It includes the domain type and handler identifiers
     624                 :            :  * for both the source and destination domains.
     625                 :            :  *
     626                 :            :  * When domain type is RTE_DMA_INTER_DOMAIN_NONE, both source and destination
     627                 :            :  * handlers are invalid, DMA operation is confined within the local process.
     628                 :            :  *
     629                 :            :  * For DMA transfers between the local process or OS domain to another process
     630                 :            :  * or OS domain, valid source and destination handlers must be provided.
     631                 :            :  */
     632                 :            : struct rte_dma_inter_domain_param {
     633                 :            :         /** Type of inter-domain. */
     634                 :            :         enum rte_dma_inter_domain_type type;
     635                 :            :         /** Source domain handler identifier. */
     636                 :            :         uint16_t src_handler;
     637                 :            :         /** Destination domain handler identifier. */
     638                 :            :         uint16_t dst_handler;
     639                 :            :         /** Reserved for future fields. */
     640                 :            :         uint64_t reserved[2];
     641                 :            : };
     642                 :            : 
     643                 :            : /**
     644                 :            :  * A structure used to configure a virtual DMA channel.
     645                 :            :  *
     646                 :            :  * @see rte_dma_vchan_setup
     647                 :            :  */
     648                 :            : struct rte_dma_vchan_conf {
     649                 :            :         /** Transfer direction
     650                 :            :          *
     651                 :            :          * @see enum rte_dma_direction
     652                 :            :          */
     653                 :            :         enum rte_dma_direction direction;
     654                 :            :         /** Number of descriptor for the virtual DMA channel */
     655                 :            :         uint16_t nb_desc;
     656                 :            :         /** 1) Used to describes the device access port parameter in the
     657                 :            :          * device-to-memory transfer scenario.
     658                 :            :          * 2) Used to describes the source device access port parameter in the
     659                 :            :          * device-to-device transfer scenario.
     660                 :            :          *
     661                 :            :          * @see struct rte_dma_port_param
     662                 :            :          */
     663                 :            :         struct rte_dma_port_param src_port;
     664                 :            :         /** 1) Used to describes the device access port parameter in the
     665                 :            :          * memory-to-device transfer scenario.
     666                 :            :          * 2) Used to describes the destination device access port parameter in
     667                 :            :          * the device-to-device transfer scenario.
     668                 :            :          *
     669                 :            :          * @see struct rte_dma_port_param
     670                 :            :          */
     671                 :            :         struct rte_dma_port_param dst_port;
     672                 :            :         /** Buffer params to auto free buffer by hardware. To free the buffer
     673                 :            :          * by hardware, RTE_DMA_OP_FLAG_AUTO_FREE must be set while calling
     674                 :            :          * rte_dma_copy and rte_dma_copy_sg().
     675                 :            :          *
     676                 :            :          * @see RTE_DMA_OP_FLAG_AUTO_FREE
     677                 :            :          * @see struct rte_dma_auto_free_param
     678                 :            :          */
     679                 :            :         struct rte_dma_auto_free_param auto_free;
     680                 :            :         /** Parameters for inter-process or inter-OS domain DMA transfers.
     681                 :            :          * This field specifies the source and destination domain handlers
     682                 :            :          * required for DMA operations that span
     683                 :            :          * across different processes or operating system domains.
     684                 :            :          *
     685                 :            :          * @see RTE_DMA_CAPA_INTER_PROCESS_DOMAIN
     686                 :            :          * @see RTE_DMA_CAPA_INTER_OS_DOMAIN
     687                 :            :          * @see struct rte_dma_inter_domain_param
     688                 :            :          */
     689                 :            :         struct rte_dma_inter_domain_param domain;
     690                 :            : };
     691                 :            : 
     692                 :            : /**
     693                 :            :  * Allocate and set up a virtual DMA channel.
     694                 :            :  *
     695                 :            :  * @param dev_id
     696                 :            :  *   The identifier of the device.
     697                 :            :  * @param vchan
     698                 :            :  *   The identifier of virtual DMA channel. The value must be in the range
     699                 :            :  *   [0, nb_vchans - 1] previously supplied to rte_dma_configure().
     700                 :            :  * @param conf
     701                 :            :  *   The virtual DMA channel configuration structure encapsulated into
     702                 :            :  *   rte_dma_vchan_conf object.
     703                 :            :  *
     704                 :            :  * @return
     705                 :            :  *   0 on success. Otherwise negative value is returned.
     706                 :            :  */
     707                 :            : int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
     708                 :            :                         const struct rte_dma_vchan_conf *conf);
     709                 :            : 
     710                 :            : /**
     711                 :            :  * A structure used to retrieve statistics.
     712                 :            :  *
     713                 :            :  * @see rte_dma_stats_get
     714                 :            :  */
     715                 :            : struct rte_dma_stats {
     716                 :            :         /** Count of operations which were submitted to hardware. */
     717                 :            :         uint64_t submitted;
     718                 :            :         /** Count of operations which were completed, including successful and
     719                 :            :          * failed completions.
     720                 :            :          */
     721                 :            :         uint64_t completed;
     722                 :            :         /** Count of operations which failed to complete. */
     723                 :            :         uint64_t errors;
     724                 :            : };
     725                 :            : 
     726                 :            : /**
     727                 :            :  * Special ID, which is used to represent all virtual DMA channels.
     728                 :            :  *
     729                 :            :  * @see rte_dma_stats_get
     730                 :            :  * @see rte_dma_stats_reset
     731                 :            :  */
     732                 :            : #define RTE_DMA_ALL_VCHAN       0xFFFFu
     733                 :            : 
     734                 :            : /**
     735                 :            :  * Retrieve basic statistics of a or all virtual DMA channel(s).
     736                 :            :  *
     737                 :            :  * @param dev_id
     738                 :            :  *   The identifier of the device.
     739                 :            :  * @param vchan
     740                 :            :  *   The identifier of virtual DMA channel.
     741                 :            :  *   If equal RTE_DMA_ALL_VCHAN means all channels.
     742                 :            :  * @param[out] stats
     743                 :            :  *   The basic statistics structure encapsulated into rte_dma_stats
     744                 :            :  *   object.
     745                 :            :  *
     746                 :            :  * @return
     747                 :            :  *   0 on success. Otherwise negative value is returned.
     748                 :            :  */
     749                 :            : int rte_dma_stats_get(int16_t dev_id, uint16_t vchan,
     750                 :            :                       struct rte_dma_stats *stats);
     751                 :            : 
     752                 :            : /**
     753                 :            :  * Reset basic statistics of a or all virtual DMA channel(s).
     754                 :            :  *
     755                 :            :  * @param dev_id
     756                 :            :  *   The identifier of the device.
     757                 :            :  * @param vchan
     758                 :            :  *   The identifier of virtual DMA channel.
     759                 :            :  *   If equal RTE_DMA_ALL_VCHAN means all channels.
     760                 :            :  *
     761                 :            :  * @return
     762                 :            :  *   0 on success. Otherwise negative value is returned.
     763                 :            :  */
     764                 :            : int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan);
     765                 :            : 
     766                 :            : /**
     767                 :            :  * device vchannel status
     768                 :            :  *
     769                 :            :  * Enum with the options for the channel status, either idle, active or halted due to error
     770                 :            :  * @see rte_dma_vchan_status
     771                 :            :  */
     772                 :            : enum rte_dma_vchan_status {
     773                 :            :         RTE_DMA_VCHAN_IDLE,          /**< not processing, awaiting ops */
     774                 :            :         RTE_DMA_VCHAN_ACTIVE,        /**< currently processing jobs */
     775                 :            :         RTE_DMA_VCHAN_HALTED_ERROR,  /**< not processing due to error, cannot accept new ops */
     776                 :            : };
     777                 :            : 
     778                 :            : /**
     779                 :            :  * Determine if all jobs have completed on a device channel.
     780                 :            :  * This function is primarily designed for testing use, as it allows a process to check if
     781                 :            :  * all jobs are completed, without actually gathering completions from those jobs.
     782                 :            :  *
     783                 :            :  * @param dev_id
     784                 :            :  *   The identifier of the device.
     785                 :            :  * @param vchan
     786                 :            :  *   The identifier of virtual DMA channel.
     787                 :            :  * @param[out] status
     788                 :            :  *   The vchan status
     789                 :            :  * @return
     790                 :            :  *   0 - call completed successfully
     791                 :            :  *   < 0 - error code indicating there was a problem calling the API
     792                 :            :  */
     793                 :            : int
     794                 :            : rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status);
     795                 :            : 
     796                 :            : /**
     797                 :            :  * Dump DMA device info.
     798                 :            :  *
     799                 :            :  * @param dev_id
     800                 :            :  *   The identifier of the device.
     801                 :            :  * @param f
     802                 :            :  *   The file to write the output to.
     803                 :            :  *
     804                 :            :  * @return
     805                 :            :  *   0 on success. Otherwise negative value is returned.
     806                 :            :  */
     807                 :            : int rte_dma_dump(int16_t dev_id, FILE *f);
     808                 :            : 
     809                 :            : /**
     810                 :            :  * Event types for DMA access pair group notifications.
     811                 :            :  *
     812                 :            :  * @warning
     813                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     814                 :            :  *
     815                 :            :  * When the event type is RTE_DMA_GROUP_EVENT_MEMBER_LEFT,
     816                 :            :  * the handler associated with the departing member's domain is no longer valid.
     817                 :            :  * Inter-domain DMA operations targeting that domain should be avoided.
     818                 :            :  *
     819                 :            :  * When the event type is RTE_DMA_GROUP_EVENT_GROUP_DESTROYED,
     820                 :            :  * all handlers associated with the group become invalid.
     821                 :            :  * No further inter-domain DMA operations should be initiated using those handlers.
     822                 :            :  */
     823                 :            : enum rte_dma_access_pair_group_event_type {
     824                 :            :         /** A member left the group (notifies creator and joiners). */
     825                 :            :         RTE_DMA_GROUP_EVENT_MEMBER_LEFT,
     826                 :            :         /** Group was destroyed (notifies joiners). */
     827                 :            :         RTE_DMA_GROUP_EVENT_GROUP_DESTROYED
     828                 :            : };
     829                 :            : 
     830                 :            : /**
     831                 :            :  * This callback is used to notify interested parties
     832                 :            :  * (either the group creator or group joiners)
     833                 :            :  * about significant events related to the lifecycle of a DMA access pair group.
     834                 :            :  *
     835                 :            :  * @warning
     836                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     837                 :            :  *
     838                 :            :  * It can be registered by:
     839                 :            :  * - **Group creators or group joiners** to be notified when a member leaves the group.
     840                 :            :  * - **Group joiners** to be notified when the group is destroyed.
     841                 :            :  *
     842                 :            :  * @param dev_id
     843                 :            :  *   Identifier of the DMA device.
     844                 :            :  * @param group_id
     845                 :            :  *   Identifier of the access pair group where the event occurred.
     846                 :            :  * @param domain_id
     847                 :            :  *   UUID of the domain_id associated with the event.
     848                 :            :  *   For member leave events, this is the domain_id of the member that left.
     849                 :            :  *   For group destruction events,
     850                 :            :  *   this may refer to the domain_id of the respective member.
     851                 :            :  * @param event
     852                 :            :  *   Type of event that occurred.
     853                 :            :  *   @see rte_dma_access_pair_group_event_type
     854                 :            :  */
     855                 :            : typedef void (*rte_dma_access_pair_group_event_cb_t)(int16_t dev_id,
     856                 :            :         int16_t group_id,
     857                 :            :         rte_uuid_t domain_id,
     858                 :            :         enum rte_dma_access_pair_group_event_type event);
     859                 :            : 
     860                 :            : /**
     861                 :            :  * Create an access pair group to enable secure DMA transfers
     862                 :            :  * between devices across different processes or operating system domains.
     863                 :            :  *
     864                 :            :  * @warning
     865                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     866                 :            :  *
     867                 :            :  * @param dev_id
     868                 :            :  *   Identifier of the DMA device initiating the group.
     869                 :            :  * @param domain_id
     870                 :            :  *   Unique identifier representing the process or OS domain.
     871                 :            :  * @param token
     872                 :            :  *   Authentication token used to establish the access group.
     873                 :            :  * @param[out] group_id
     874                 :            :  *   Pointer to store the ID of the newly created access group.
     875                 :            :  * @param cb
     876                 :            :  *   Callback function to be invoked when a member leaves the group.
     877                 :            :  *
     878                 :            :  * @return
     879                 :            :  *   0 on success,
     880                 :            :  *   negative error code on failure.
     881                 :            :  */
     882                 :            : __rte_experimental
     883                 :            : int rte_dma_access_pair_group_create(int16_t dev_id, rte_uuid_t domain_id, rte_uuid_t token,
     884                 :            :                                      int16_t *group_id, rte_dma_access_pair_group_event_cb_t cb);
     885                 :            : 
     886                 :            : /**
     887                 :            :  * Destroy an access pair group if all participating devices have exited.
     888                 :            :  *
     889                 :            :  * @warning
     890                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     891                 :            :  *
     892                 :            :  * This operation is only permitted by the device that originally created the group;
     893                 :            :  * attempts by other devices will result in failure.
     894                 :            :  *
     895                 :            :  * @param dev_id
     896                 :            :  *   Identifier of the device requesting group destruction.
     897                 :            :  * @param group_id
     898                 :            :  *   ID of the access group to be destroyed.
     899                 :            :  * @return
     900                 :            :  *   0 on success,
     901                 :            :  *   negative value on failure indicating the error code.
     902                 :            :  */
     903                 :            : __rte_experimental
     904                 :            : int rte_dma_access_pair_group_destroy(int16_t dev_id, int16_t group_id);
     905                 :            : 
     906                 :            : /**
     907                 :            :  * Join an existing access group to enable secure DMA transfers
     908                 :            :  * between devices across different processes or OS domains.
     909                 :            :  *
     910                 :            :  * @warning
     911                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     912                 :            :  *
     913                 :            :  * @param dev_id
     914                 :            :  *   Identifier of the DMA device attempting to join the group.
     915                 :            :  * @param group_id
     916                 :            :  *   ID of the access group to join.
     917                 :            :  * @param token
     918                 :            :  *   Authentication token used to validate group membership.
     919                 :            :  * @param cb
     920                 :            :  *   Callback function to be invoked when the device leaves the group
     921                 :            :  *   or when the group is destroyed due to some exception or failure.
     922                 :            :  *
     923                 :            :  * @return
     924                 :            :  *   0 on success,
     925                 :            :  *   negative value on failure indicating the error code.
     926                 :            :  */
     927                 :            : __rte_experimental
     928                 :            : int rte_dma_access_pair_group_join(int16_t dev_id, int16_t group_id, rte_uuid_t token,
     929                 :            :                                    rte_dma_access_pair_group_event_cb_t cb);
     930                 :            : 
     931                 :            : /**
     932                 :            :  * Leave an access group, removing the device's entry from the group table
     933                 :            :  * and disabling inter-domain DMA transfers to and from this device.
     934                 :            :  *
     935                 :            :  * @warning
     936                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     937                 :            :  *
     938                 :            :  * This operation is not permitted for the device that originally created the group.
     939                 :            :  *
     940                 :            :  * @param dev_id
     941                 :            :  *   Identifier of the device requesting to leave the group.
     942                 :            :  * @param group_id
     943                 :            :  *   ID of the access group to leave.
     944                 :            :  * @return
     945                 :            :  *   0 on success,
     946                 :            :  *   negative value on failure indicating the error code.
     947                 :            :  */
     948                 :            : __rte_experimental
     949                 :            : int rte_dma_access_pair_group_leave(int16_t dev_id, int16_t group_id);
     950                 :            : 
     951                 :            : /**
     952                 :            :  * Retrieve the handler associated with a specific domain ID,
     953                 :            :  * which is used by the application to query source or destinationin handler
     954                 :            :  * to initiate inter-process or inter-OS DMA transfers.
     955                 :            :  *
     956                 :            :  * @warning
     957                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     958                 :            :  *
     959                 :            :  * @param dev_id
     960                 :            :  *   Identifier of the DMA device requesting the handler.
     961                 :            :  * @param group_id
     962                 :            :  *   ID of the access group to query.
     963                 :            :  * @param domain_id
     964                 :            :  *   Unique identifier of the target process or OS domain.
     965                 :            :  * @param[out] handler
     966                 :            :  *   Pointer to store the retrieved handler value.
     967                 :            :  * @return
     968                 :            :  *   0 on success,
     969                 :            :  *   negative value on failure indicating the error code.
     970                 :            :  */
     971                 :            : __rte_experimental
     972                 :            : int rte_dma_access_pair_group_handler_get(int16_t dev_id, int16_t group_id, rte_uuid_t domain_id,
     973                 :            :                                           uint16_t *handler);
     974                 :            : 
     975                 :            : /**
     976                 :            :  * DMA transfer result status code defines.
     977                 :            :  *
     978                 :            :  * @see rte_dma_completed_status
     979                 :            :  */
     980                 :            : enum rte_dma_status_code {
     981                 :            :         /** The operation completed successfully. */
     982                 :            :         RTE_DMA_STATUS_SUCCESSFUL,
     983                 :            :         /** The operation failed to complete due abort by user.
     984                 :            :          * This is mainly used when processing dev_stop, user could modify the
     985                 :            :          * descriptors (e.g. change one bit to tell hardware abort this job),
     986                 :            :          * it allows outstanding requests to be complete as much as possible,
     987                 :            :          * so reduce the time to stop the device.
     988                 :            :          */
     989                 :            :         RTE_DMA_STATUS_USER_ABORT,
     990                 :            :         /** The operation failed to complete due to following scenarios:
     991                 :            :          * The jobs in a particular batch are not attempted because they
     992                 :            :          * appeared after a fence where a previous job failed. In some HW
     993                 :            :          * implementation it's possible for jobs from later batches would be
     994                 :            :          * completed, though, so report the status from the not attempted jobs
     995                 :            :          * before reporting those newer completed jobs.
     996                 :            :          */
     997                 :            :         RTE_DMA_STATUS_NOT_ATTEMPTED,
     998                 :            :         /** The operation failed to complete due invalid source address. */
     999                 :            :         RTE_DMA_STATUS_INVALID_SRC_ADDR,
    1000                 :            :         /** The operation failed to complete due invalid destination address. */
    1001                 :            :         RTE_DMA_STATUS_INVALID_DST_ADDR,
    1002                 :            :         /** The operation failed to complete due invalid source or destination
    1003                 :            :          * address, cover the case that only knows the address error, but not
    1004                 :            :          * sure which address error.
    1005                 :            :          */
    1006                 :            :         RTE_DMA_STATUS_INVALID_ADDR,
    1007                 :            :         /** The operation failed to complete due invalid length. */
    1008                 :            :         RTE_DMA_STATUS_INVALID_LENGTH,
    1009                 :            :         /** The operation failed to complete due invalid opcode.
    1010                 :            :          * The DMA descriptor could have multiple format, which are
    1011                 :            :          * distinguished by the opcode field.
    1012                 :            :          */
    1013                 :            :         RTE_DMA_STATUS_INVALID_OPCODE,
    1014                 :            :         /** The operation failed to complete due bus read error. */
    1015                 :            :         RTE_DMA_STATUS_BUS_READ_ERROR,
    1016                 :            :         /** The operation failed to complete due bus write error. */
    1017                 :            :         RTE_DMA_STATUS_BUS_WRITE_ERROR,
    1018                 :            :         /** The operation failed to complete due bus error, cover the case that
    1019                 :            :          * only knows the bus error, but not sure which direction error.
    1020                 :            :          */
    1021                 :            :         RTE_DMA_STATUS_BUS_ERROR,
    1022                 :            :         /** The operation failed to complete due data poison. */
    1023                 :            :         RTE_DMA_STATUS_DATA_POISION,
    1024                 :            :         /** The operation failed to complete due descriptor read error. */
    1025                 :            :         RTE_DMA_STATUS_DESCRIPTOR_READ_ERROR,
    1026                 :            :         /** The operation failed to complete due device link error.
    1027                 :            :          * Used to indicates that the link error in the memory-to-device/
    1028                 :            :          * device-to-memory/device-to-device transfer scenario.
    1029                 :            :          */
    1030                 :            :         RTE_DMA_STATUS_DEV_LINK_ERROR,
    1031                 :            :         /** The operation failed to complete due lookup page fault. */
    1032                 :            :         RTE_DMA_STATUS_PAGE_FAULT,
    1033                 :            :         /** The operation failed to complete due unknown reason.
    1034                 :            :          * The initial value is 256, which reserves space for future errors.
    1035                 :            :          */
    1036                 :            :         RTE_DMA_STATUS_ERROR_UNKNOWN = 0x100,
    1037                 :            : };
    1038                 :            : 
    1039                 :            : /**
    1040                 :            :  * A structure used to hold scatter-gather DMA operation request entry.
    1041                 :            :  *
    1042                 :            :  * @see rte_dma_copy_sg
    1043                 :            :  */
    1044                 :            : struct rte_dma_sge {
    1045                 :            :         rte_iova_t addr; /**< The DMA operation address. */
    1046                 :            :         uint32_t length; /**< The DMA operation length. */
    1047                 :            : };
    1048                 :            : 
    1049                 :            : /**
    1050                 :            :  * A structure used to hold event based DMA operation entry.
    1051                 :            :  * All the information required for a DMA transfer
    1052                 :            :  * shall be populated in "struct rte_dma_op" instance.
    1053                 :            :  */
    1054                 :            : struct rte_dma_op {
    1055                 :            :         /** Flags related to the operation.
    1056                 :            :          * @see RTE_DMA_OP_FLAG_*
    1057                 :            :          */
    1058                 :            :         uint64_t flags;
    1059                 :            :         /** Mempool from which op is allocated. */
    1060                 :            :         struct rte_mempool *op_mp;
    1061                 :            :         /** Status code for this operation. */
    1062                 :            :         enum rte_dma_status_code status;
    1063                 :            :         /** Reserved for future use. */
    1064                 :            :         uint32_t rsvd;
    1065                 :            :         /** Implementation-specific opaque data.
    1066                 :            :          * A DMA device implementation use this field to hold
    1067                 :            :          * implementation-specific values
    1068                 :            :          * to share between dequeue and enqueue operations.
    1069                 :            :          * The application should not modify this field.
    1070                 :            :          */
    1071                 :            :         uint64_t impl_opaque[2];
    1072                 :            :         /** Memory to store user specific metadata.
    1073                 :            :          * The DMA device implementation should not modify this area.
    1074                 :            :          */
    1075                 :            :         uint64_t user_meta;
    1076                 :            :         /** Event metadata of DMA completion event.
    1077                 :            :          * Used when RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_VCHAN_EV_BIND
    1078                 :            :          * is not supported in OP_NEW mode.
    1079                 :            :          * @see rte_event_dma_adapter_mode::RTE_EVENT_DMA_ADAPTER_OP_NEW
    1080                 :            :          * @see RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_VCHAN_EV_BIND
    1081                 :            :          *
    1082                 :            :          * Used when RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_FWD
    1083                 :            :          * is not supported in OP_FWD mode.
    1084                 :            :          * @see rte_event_dma_adapter_mode::RTE_EVENT_DMA_ADAPTER_OP_FORWARD
    1085                 :            :          * @see RTE_EVENT_DMA_ADAPTER_CAP_INTERNAL_PORT_OP_FWD
    1086                 :            :          *
    1087                 :            :          * @see struct rte_event::event
    1088                 :            :          */
    1089                 :            :         uint64_t event_meta;
    1090                 :            :         /** DMA device ID to be used with OP_FORWARD mode.
    1091                 :            :          * @see rte_event_dma_adapter_mode::RTE_EVENT_DMA_ADAPTER_OP_FORWARD
    1092                 :            :          */
    1093                 :            :         int16_t dma_dev_id;
    1094                 :            :         /** DMA vchan ID to be used with OP_FORWARD mode
    1095                 :            :          * @see rte_event_dma_adapter_mode::RTE_EVENT_DMA_ADAPTER_OP_FORWARD
    1096                 :            :          */
    1097                 :            :         uint16_t vchan;
    1098                 :            :         /** Number of source segments. */
    1099                 :            :         uint16_t nb_src;
    1100                 :            :         /** Number of destination segments. */
    1101                 :            :         uint16_t nb_dst;
    1102                 :            :         /** Source and destination segments. */
    1103                 :            :         struct rte_dma_sge src_dst_seg[];
    1104                 :            : };
    1105                 :            : 
    1106                 :            : #ifdef __cplusplus
    1107                 :            : }
    1108                 :            : #endif
    1109                 :            : 
    1110                 :            : #include "rte_dmadev_core.h"
    1111                 :            : #include "rte_dmadev_trace_fp.h"
    1112                 :            : 
    1113                 :            : #ifdef __cplusplus
    1114                 :            : extern "C" {
    1115                 :            : #endif
    1116                 :            : 
    1117                 :            : /**@{@name DMA operation flag
    1118                 :            :  * @see rte_dma_copy()
    1119                 :            :  * @see rte_dma_copy_sg()
    1120                 :            :  * @see rte_dma_fill()
    1121                 :            :  */
    1122                 :            : /** Fence flag.
    1123                 :            :  * It means the operation with this flag must be processed only after all
    1124                 :            :  * previous operations are completed.
    1125                 :            :  * If the specify DMA HW works in-order (it means it has default fence between
    1126                 :            :  * operations), this flag could be NOP.
    1127                 :            :  */
    1128                 :            : #define RTE_DMA_OP_FLAG_FENCE   RTE_BIT64(0)
    1129                 :            : /** Submit flag.
    1130                 :            :  * It means the operation with this flag must issue doorbell to hardware after
    1131                 :            :  * enqueued jobs.
    1132                 :            :  */
    1133                 :            : #define RTE_DMA_OP_FLAG_SUBMIT  RTE_BIT64(1)
    1134                 :            : /** Write data to low level cache hint.
    1135                 :            :  * Used for performance optimization, this is just a hint, and there is no
    1136                 :            :  * capability bit for this, driver should not return error if this flag was set.
    1137                 :            :  */
    1138                 :            : #define RTE_DMA_OP_FLAG_LLC     RTE_BIT64(2)
    1139                 :            : /** Auto free buffer flag.
    1140                 :            :  * Operation with this flag must issue command to hardware to free the DMA
    1141                 :            :  * buffer after DMA transfer is completed.
    1142                 :            :  *
    1143                 :            :  * @see struct rte_dma_vchan_conf::auto_free
    1144                 :            :  */
    1145                 :            : #define RTE_DMA_OP_FLAG_AUTO_FREE       RTE_BIT64(3)
    1146                 :            : /**@}*/
    1147                 :            : 
    1148                 :            : /**
    1149                 :            :  * Enqueue a copy operation onto the virtual DMA channel.
    1150                 :            :  *
    1151                 :            :  * This queues up a copy operation to be performed by hardware, if the 'flags'
    1152                 :            :  * parameter contains RTE_DMA_OP_FLAG_SUBMIT then trigger doorbell to begin
    1153                 :            :  * this operation, otherwise do not trigger doorbell.
    1154                 :            :  *
    1155                 :            :  * @param dev_id
    1156                 :            :  *   The identifier of the device.
    1157                 :            :  * @param vchan
    1158                 :            :  *   The identifier of virtual DMA channel.
    1159                 :            :  * @param src
    1160                 :            :  *   The address of the source buffer.
    1161                 :            :  * @param dst
    1162                 :            :  *   The address of the destination buffer.
    1163                 :            :  * @param length
    1164                 :            :  *   The length of the data to be copied.
    1165                 :            :  * @param flags
    1166                 :            :  *   An flags for this operation.
    1167                 :            :  *   @see RTE_DMA_OP_FLAG_*
    1168                 :            :  *
    1169                 :            :  * @return
    1170                 :            :  *   - 0..UINT16_MAX: index of enqueued job.
    1171                 :            :  *   - -ENOSPC: if no space left to enqueue.
    1172                 :            :  *   - other values < 0 on failure.
    1173                 :            :  */
    1174                 :            : static inline int
    1175                 :            : rte_dma_copy(int16_t dev_id, uint16_t vchan, rte_iova_t src, rte_iova_t dst,
    1176                 :            :              uint32_t length, uint64_t flags)
    1177                 :            : {
    1178                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1179                 :            :         int ret;
    1180                 :            : 
    1181                 :            : #ifdef RTE_DMADEV_DEBUG
    1182                 :            :         if (!rte_dma_is_valid(dev_id) || length == 0)
    1183                 :            :                 return -EINVAL;
    1184                 :            :         if (obj->copy == NULL)
    1185                 :            :                 return -ENOTSUP;
    1186                 :            : #endif
    1187                 :            : 
    1188                 :          0 :         ret = obj->copy(obj->dev_private, vchan, src, dst, length, flags);
    1189                 :            :         rte_dma_trace_copy(dev_id, vchan, src, dst, length, flags, ret);
    1190                 :            : 
    1191                 :            :         return ret;
    1192                 :            : }
    1193                 :            : 
    1194                 :            : /**
    1195                 :            :  * Enqueue a scatter-gather list copy operation onto the virtual DMA channel.
    1196                 :            :  *
    1197                 :            :  * This queues up a scatter-gather list copy operation to be performed by
    1198                 :            :  * hardware, if the 'flags' parameter contains RTE_DMA_OP_FLAG_SUBMIT then
    1199                 :            :  * trigger doorbell to begin this operation, otherwise do not trigger doorbell.
    1200                 :            :  *
    1201                 :            :  * @param dev_id
    1202                 :            :  *   The identifier of the device.
    1203                 :            :  * @param vchan
    1204                 :            :  *   The identifier of virtual DMA channel.
    1205                 :            :  * @param src
    1206                 :            :  *   The pointer of source scatter-gather entry array.
    1207                 :            :  * @param dst
    1208                 :            :  *   The pointer of destination scatter-gather entry array.
    1209                 :            :  * @param nb_src
    1210                 :            :  *   The number of source scatter-gather entry.
    1211                 :            :  *   @see struct rte_dma_info::max_sges
    1212                 :            :  * @param nb_dst
    1213                 :            :  *   The number of destination scatter-gather entry.
    1214                 :            :  *   @see struct rte_dma_info::max_sges
    1215                 :            :  * @param flags
    1216                 :            :  *   An flags for this operation.
    1217                 :            :  *   @see RTE_DMA_OP_FLAG_*
    1218                 :            :  *
    1219                 :            :  * @return
    1220                 :            :  *   - 0..UINT16_MAX: index of enqueued job.
    1221                 :            :  *   - -ENOSPC: if no space left to enqueue.
    1222                 :            :  *   - other values < 0 on failure.
    1223                 :            :  */
    1224                 :            : static inline int
    1225                 :            : rte_dma_copy_sg(int16_t dev_id, uint16_t vchan, struct rte_dma_sge *src,
    1226                 :            :                 struct rte_dma_sge *dst, uint16_t nb_src, uint16_t nb_dst,
    1227                 :            :                 uint64_t flags)
    1228                 :            : {
    1229                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1230                 :            :         int ret;
    1231                 :            : 
    1232                 :            : #ifdef RTE_DMADEV_DEBUG
    1233                 :            :         if (!rte_dma_is_valid(dev_id) || src == NULL || dst == NULL ||
    1234                 :            :             nb_src == 0 || nb_dst == 0)
    1235                 :            :                 return -EINVAL;
    1236                 :            :         if (obj->copy_sg == NULL)
    1237                 :            :                 return -ENOTSUP;
    1238                 :            : #endif
    1239                 :            : 
    1240                 :          0 :         ret = obj->copy_sg(obj->dev_private, vchan, src, dst, nb_src, nb_dst, flags);
    1241                 :            :         rte_dma_trace_copy_sg(dev_id, vchan, src, dst, nb_src, nb_dst, flags,
    1242                 :            :                               ret);
    1243                 :            : 
    1244                 :            :         return ret;
    1245                 :            : }
    1246                 :            : 
    1247                 :            : /**
    1248                 :            :  * Enqueue a fill operation onto the virtual DMA channel.
    1249                 :            :  *
    1250                 :            :  * This queues up a fill operation to be performed by hardware, if the 'flags'
    1251                 :            :  * parameter contains RTE_DMA_OP_FLAG_SUBMIT then trigger doorbell to begin
    1252                 :            :  * this operation, otherwise do not trigger doorbell.
    1253                 :            :  *
    1254                 :            :  * @param dev_id
    1255                 :            :  *   The identifier of the device.
    1256                 :            :  * @param vchan
    1257                 :            :  *   The identifier of virtual DMA channel.
    1258                 :            :  * @param pattern
    1259                 :            :  *   The pattern to populate the destination buffer with.
    1260                 :            :  * @param dst
    1261                 :            :  *   The address of the destination buffer.
    1262                 :            :  * @param length
    1263                 :            :  *   The length of the destination buffer.
    1264                 :            :  * @param flags
    1265                 :            :  *   An flags for this operation.
    1266                 :            :  *   @see RTE_DMA_OP_FLAG_*
    1267                 :            :  *
    1268                 :            :  * @return
    1269                 :            :  *   - 0..UINT16_MAX: index of enqueued job.
    1270                 :            :  *   - -ENOSPC: if no space left to enqueue.
    1271                 :            :  *   - other values < 0 on failure.
    1272                 :            :  */
    1273                 :            : static inline int
    1274                 :            : rte_dma_fill(int16_t dev_id, uint16_t vchan, uint64_t pattern,
    1275                 :            :              rte_iova_t dst, uint32_t length, uint64_t flags)
    1276                 :            : {
    1277                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1278                 :            :         int ret;
    1279                 :            : 
    1280                 :            : #ifdef RTE_DMADEV_DEBUG
    1281                 :            :         if (!rte_dma_is_valid(dev_id) || length == 0)
    1282                 :            :                 return -EINVAL;
    1283                 :            :         if (obj->fill == NULL)
    1284                 :            :                 return -ENOTSUP;
    1285                 :            : #endif
    1286                 :            : 
    1287                 :          0 :         ret = obj->fill(obj->dev_private, vchan, pattern, dst, length, flags);
    1288                 :            :         rte_dma_trace_fill(dev_id, vchan, pattern, dst, length, flags, ret);
    1289                 :            : 
    1290                 :            :         return ret;
    1291                 :            : }
    1292                 :            : 
    1293                 :            : /**
    1294                 :            :  * Trigger hardware to begin performing enqueued operations.
    1295                 :            :  *
    1296                 :            :  * Writes the "doorbell" to the hardware to trigger it
    1297                 :            :  * to begin the operations previously enqueued by rte_dma_copy/fill().
    1298                 :            :  *
    1299                 :            :  * @param dev_id
    1300                 :            :  *   The identifier of the device.
    1301                 :            :  * @param vchan
    1302                 :            :  *   The identifier of virtual DMA channel.
    1303                 :            :  *
    1304                 :            :  * @return
    1305                 :            :  *   0 on success. Otherwise negative value is returned.
    1306                 :            :  */
    1307                 :            : static inline int
    1308                 :            : rte_dma_submit(int16_t dev_id, uint16_t vchan)
    1309                 :            : {
    1310                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1311                 :            :         int ret;
    1312                 :            : 
    1313                 :            : #ifdef RTE_DMADEV_DEBUG
    1314                 :            :         if (!rte_dma_is_valid(dev_id))
    1315                 :            :                 return -EINVAL;
    1316                 :            :         if (obj->submit == NULL)
    1317                 :            :                 return -ENOTSUP;
    1318                 :            : #endif
    1319                 :            : 
    1320                 :          0 :         ret = obj->submit(obj->dev_private, vchan);
    1321                 :            :         rte_dma_trace_submit(dev_id, vchan, ret);
    1322                 :            : 
    1323                 :          0 :         return ret;
    1324                 :            : }
    1325                 :            : 
    1326                 :            : /**
    1327                 :            :  * Return the number of operations that have been successfully completed.
    1328                 :            :  * Once an operation has been reported as completed, the results of that
    1329                 :            :  * operation will be visible to all cores on the system.
    1330                 :            :  *
    1331                 :            :  * @param dev_id
    1332                 :            :  *   The identifier of the device.
    1333                 :            :  * @param vchan
    1334                 :            :  *   The identifier of virtual DMA channel.
    1335                 :            :  * @param nb_cpls
    1336                 :            :  *   The maximum number of completed operations that can be processed.
    1337                 :            :  * @param[out] last_idx
    1338                 :            :  *   The last completed operation's ring_idx.
    1339                 :            :  *   If not required, NULL can be passed in.
    1340                 :            :  * @param[out] has_error
    1341                 :            :  *   Indicates if there are transfer error.
    1342                 :            :  *   If not required, NULL can be passed in.
    1343                 :            :  *
    1344                 :            :  * @return
    1345                 :            :  *   The number of operations that successfully completed. This return value
    1346                 :            :  *   must be less than or equal to the value of nb_cpls.
    1347                 :            :  */
    1348                 :            : static inline uint16_t
    1349                 :            : rte_dma_completed(int16_t dev_id, uint16_t vchan, const uint16_t nb_cpls,
    1350                 :            :                   uint16_t *last_idx, bool *has_error)
    1351                 :            : {
    1352                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1353                 :            :         uint16_t idx, ret;
    1354                 :            :         bool err;
    1355                 :            : 
    1356                 :            : #ifdef RTE_DMADEV_DEBUG
    1357                 :            :         if (!rte_dma_is_valid(dev_id) || nb_cpls == 0)
    1358                 :            :                 return 0;
    1359                 :            :         if (obj->completed == NULL)
    1360                 :            :                 return 0;
    1361                 :            : #endif
    1362                 :            : 
    1363                 :            :         /* Ensure the pointer values are non-null to simplify drivers.
    1364                 :            :          * In most cases these should be compile time evaluated, since this is
    1365                 :            :          * an inline function.
    1366                 :            :          * - If NULL is explicitly passed as parameter, then compiler knows the
    1367                 :            :          *   value is NULL
    1368                 :            :          * - If address of local variable is passed as parameter, then compiler
    1369                 :            :          *   can know it's non-NULL.
    1370                 :            :          */
    1371                 :            :         if (last_idx == NULL)
    1372                 :            :                 last_idx = &idx;
    1373                 :            :         if (has_error == NULL)
    1374                 :            :                 has_error = &err;
    1375                 :            : 
    1376                 :          0 :         *has_error = false;
    1377                 :          0 :         ret = obj->completed(obj->dev_private, vchan, nb_cpls, last_idx, has_error);
    1378                 :            :         rte_dma_trace_completed(dev_id, vchan, nb_cpls, last_idx, has_error,
    1379                 :            :                                 ret);
    1380                 :            : 
    1381                 :            :         return ret;
    1382                 :            : }
    1383                 :            : 
    1384                 :            : /**
    1385                 :            :  * Return the number of operations that have been completed, and the operations
    1386                 :            :  * result may succeed or fail.
    1387                 :            :  * Once an operation has been reported as completed successfully, the results of that
    1388                 :            :  * operation will be visible to all cores on the system.
    1389                 :            :  *
    1390                 :            :  * @param dev_id
    1391                 :            :  *   The identifier of the device.
    1392                 :            :  * @param vchan
    1393                 :            :  *   The identifier of virtual DMA channel.
    1394                 :            :  * @param nb_cpls
    1395                 :            :  *   Indicates the size of status array.
    1396                 :            :  * @param[out] last_idx
    1397                 :            :  *   The last completed operation's ring_idx.
    1398                 :            :  *   If not required, NULL can be passed in.
    1399                 :            :  * @param[out] status
    1400                 :            :  *   This is a pointer to an array of length 'nb_cpls' that holds the completion
    1401                 :            :  *   status code of each operation.
    1402                 :            :  *   @see enum rte_dma_status_code
    1403                 :            :  *
    1404                 :            :  * @return
    1405                 :            :  *   The number of operations that completed. This return value must be less
    1406                 :            :  *   than or equal to the value of nb_cpls.
    1407                 :            :  *   If this number is greater than zero (assuming n), then n values in the
    1408                 :            :  *   status array are also set.
    1409                 :            :  */
    1410                 :            : static inline uint16_t
    1411                 :            : rte_dma_completed_status(int16_t dev_id, uint16_t vchan,
    1412                 :            :                          const uint16_t nb_cpls, uint16_t *last_idx,
    1413                 :            :                          enum rte_dma_status_code *status)
    1414                 :            : {
    1415                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1416                 :            :         uint16_t idx, ret;
    1417                 :            : 
    1418                 :            : #ifdef RTE_DMADEV_DEBUG
    1419                 :            :         if (!rte_dma_is_valid(dev_id) || nb_cpls == 0 || status == NULL)
    1420                 :            :                 return 0;
    1421                 :            :         if (obj->completed_status == NULL)
    1422                 :            :                 return 0;
    1423                 :            : #endif
    1424                 :            : 
    1425                 :            :         if (last_idx == NULL)
    1426                 :            :                 last_idx = &idx;
    1427                 :            : 
    1428                 :          0 :         ret = obj->completed_status(obj->dev_private, vchan, nb_cpls, last_idx, status);
    1429                 :            :         rte_dma_trace_completed_status(dev_id, vchan, nb_cpls, last_idx, status,
    1430                 :            :                                        ret);
    1431                 :            : 
    1432                 :            :         return ret;
    1433                 :            : }
    1434                 :            : 
    1435                 :            : /**
    1436                 :            :  * Check remaining capacity in descriptor ring for the current burst.
    1437                 :            :  *
    1438                 :            :  * @param dev_id
    1439                 :            :  *   The identifier of the device.
    1440                 :            :  * @param vchan
    1441                 :            :  *   The identifier of virtual DMA channel.
    1442                 :            :  *
    1443                 :            :  * @return
    1444                 :            :  *   - Remaining space in the descriptor ring for the current burst.
    1445                 :            :  *   - 0 on error
    1446                 :            :  */
    1447                 :            : static inline uint16_t
    1448                 :            : rte_dma_burst_capacity(int16_t dev_id, uint16_t vchan)
    1449                 :            : {
    1450                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1451                 :            :         uint16_t ret;
    1452                 :            : 
    1453                 :            : #ifdef RTE_DMADEV_DEBUG
    1454                 :            :         if (!rte_dma_is_valid(dev_id))
    1455                 :            :                 return 0;
    1456                 :            :         if (obj->burst_capacity == NULL)
    1457                 :            :                 return 0;
    1458                 :            : #endif
    1459                 :          0 :         ret = obj->burst_capacity(obj->dev_private, vchan);
    1460                 :            :         rte_dma_trace_burst_capacity(dev_id, vchan, ret);
    1461                 :            : 
    1462                 :            :         return ret;
    1463                 :            : }
    1464                 :            : 
    1465                 :            : /**
    1466                 :            :  * Enqueue rte_dma_ops to DMA device, can only be used underlying supports
    1467                 :            :  * RTE_DMA_CAPA_OPS_ENQ_DEQ and rte_dma_conf::enable_enq_deq is enabled in
    1468                 :            :  * rte_dma_configure().
    1469                 :            :  * The ops enqueued will be immediately submitted to the DMA device.
    1470                 :            :  * The enqueue should be coupled with dequeue to retrieve completed ops,
    1471                 :            :  * calls to rte_dma_submit(), rte_dma_completed() and rte_dma_completed_status()
    1472                 :            :  * are not valid.
    1473                 :            :  *
    1474                 :            :  * @param dev_id
    1475                 :            :  *   The identifier of the device.
    1476                 :            :  * @param vchan
    1477                 :            :  *   The identifier of virtual DMA channel.
    1478                 :            :  * @param ops
    1479                 :            :  *   Pointer to rte_dma_op array.
    1480                 :            :  * @param nb_ops
    1481                 :            :  *   Number of rte_dma_op in the ops array
    1482                 :            :  * @return uint16_t
    1483                 :            :  *   Number of successfully submitted ops.
    1484                 :            :  */
    1485                 :            : static inline uint16_t
    1486                 :            : rte_dma_enqueue_ops(int16_t dev_id, uint16_t vchan, struct rte_dma_op **ops, uint16_t nb_ops)
    1487                 :            : {
    1488                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1489                 :            :         uint16_t ret;
    1490                 :            : 
    1491                 :            : #ifdef RTE_DMADEV_DEBUG
    1492                 :            :         if (!rte_dma_is_valid(dev_id))
    1493                 :            :                 return 0;
    1494                 :            :         if (*obj->enqueue == NULL)
    1495                 :            :                 return 0;
    1496                 :            : #endif
    1497                 :            : 
    1498                 :          0 :         ret = (*obj->enqueue)(obj->dev_private, vchan, ops, nb_ops);
    1499                 :            :         rte_dma_trace_enqueue_ops(dev_id, vchan, (void **)ops, nb_ops);
    1500                 :            : 
    1501                 :            :         return ret;
    1502                 :            : }
    1503                 :            : 
    1504                 :            : /**
    1505                 :            :  * Dequeue completed rte_dma_ops submitted to the DMA device, can only be used
    1506                 :            :  * underlying supports RTE_DMA_CAPA_OPS_ENQ_DEQ and rte_dma_conf::enable_enq_deq
    1507                 :            :  * is enabled in rte_dma_configure().
    1508                 :            :  *
    1509                 :            :  * @param dev_id
    1510                 :            :  *   The identifier of the device.
    1511                 :            :  * @param vchan
    1512                 :            :  *   The identifier of virtual DMA channel.
    1513                 :            :  * @param ops
    1514                 :            :  *   Pointer to rte_dma_op array.
    1515                 :            :  * @param nb_ops
    1516                 :            :  *   Size of rte_dma_op array.
    1517                 :            :  * @return
    1518                 :            :  *   Number of successfully completed ops. Should be less or equal to nb_ops.
    1519                 :            :  */
    1520                 :            : static inline uint16_t
    1521                 :            : rte_dma_dequeue_ops(int16_t dev_id, uint16_t vchan, struct rte_dma_op **ops, uint16_t nb_ops)
    1522                 :            : {
    1523                 :          0 :         struct rte_dma_fp_object *obj = &rte_dma_fp_objs[dev_id];
    1524                 :            :         uint16_t ret;
    1525                 :            : 
    1526                 :            : #ifdef RTE_DMADEV_DEBUG
    1527                 :            :         if (!rte_dma_is_valid(dev_id))
    1528                 :            :                 return 0;
    1529                 :            :         if (*obj->dequeue == NULL)
    1530                 :            :                 return 0;
    1531                 :            : #endif
    1532                 :            : 
    1533                 :          0 :         ret = (*obj->dequeue)(obj->dev_private, vchan, ops, nb_ops);
    1534                 :            :         rte_dma_trace_dequeue_ops(dev_id, vchan, (void **)ops, nb_ops);
    1535                 :            : 
    1536                 :            :         return ret;
    1537                 :            : }
    1538                 :            : 
    1539                 :            : #ifdef __cplusplus
    1540                 :            : }
    1541                 :            : #endif
    1542                 :            : 
    1543                 :            : #endif /* RTE_DMADEV_H */

Generated by: LCOV version 1.14