NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
dma_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef DMA_COMMON_H_
27 #define DMA_COMMON_H_
28 
29 #include <unistd.h>
30 #include <stdbool.h>
31 
32 #include <doca_dma.h>
33 #include <doca_error.h>
34 
35 #include "common.h"
36 
37 #define MAX_USER_ARG_SIZE 256 /* Maximum size of user input argument */
38 #define MAX_ARG_SIZE (MAX_USER_ARG_SIZE + 1) /* Maximum size of input argument */
39 #define MAX_USER_TXT_SIZE 4096 /* Maximum size of user input text */
40 #define MAX_TXT_SIZE (MAX_USER_TXT_SIZE + 1) /* Maximum size of input text */
41 #define PAGE_SIZE sysconf(_SC_PAGESIZE) /* Page size */
42 #define NUM_DMA_TASKS (1) /* DMA tasks number */
43 
44 /* Configuration struct */
45 struct dma_config {
46  char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* PCI device address */
47  char cpy_txt[MAX_TXT_SIZE]; /* Text to copy between the two local buffers */
48  char export_desc_path[MAX_ARG_SIZE]; /* Path to save/read the exported descriptor file */
49  char buf_info_path[MAX_ARG_SIZE]; /* Path to save/read the buffer information file */
50  int num_src_buf; /* Number of linked_list doca_buf element for the source buffer */
51  int num_dst_buf; /* Number of linked_list doca_buf element for the destination buffer */
52 };
53 
54 struct dma_resources {
55  struct program_core_objects state; /* Core objects that manage our "state" */
56  struct doca_dma *dma_ctx; /* DOCA DMA context */
57  size_t num_remaining_tasks; /* Number of remaining tasks to process */
58  bool run_pe_progress; /* Should we keep on progressing the PE? */
59 };
60 
61 /*
62  * Register the command line parameters for the DOCA DMA samples
63  *
64  * @is_remote [in]: Indication for handling configuration parameters which are
65  * needed when there is a remote side
66  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
67  */
68 doca_error_t register_dma_params(bool is_remote);
69 
70 /*
71  * Allocate DOCA DMA resources
72  *
73  * @pcie_addr [in]: PCIe address of device to open
74  * @num_buf [in]: Number of doca_buf to allocate
75  * @resources [out]: Structure containing all DMA resources
76  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
77  */
78 doca_error_t allocate_dma_resources(const char *pcie_addr, int num_buf, struct dma_resources *resources);
79 
80 /*
81  * Destroy DOCA DMA resources
82  *
83  * @resources [out]: Structure containing all DMA resources
84  * @dma_ctx [in]: DOCA DMA context
85  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
86  */
88 
89 /*
90  * Allocate DOCA DMA host resources
91  *
92  * @pcie_addr [in]: PCIe address of device to open
93  * @state [out]: Structure containing all DOCA core structures
94  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
95  */
96 doca_error_t allocate_dma_host_resources(const char *pcie_addr, struct program_core_objects *state);
97 
98 /*
99  * Destroy DOCA DMA host resources
100  *
101  * @state [in]: Structure containing all DOCA core structures
102  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
103  */
105 
106 /*
107  * Check if given device is capable of executing a DMA memcpy task.
108  *
109  * @devinfo [in]: The DOCA device information
110  * @return: DOCA_SUCCESS if the device supports DMA memcpy task and DOCA_ERROR otherwise.
111  */
112 doca_error_t dma_task_is_supported(struct doca_devinfo *devinfo);
113 
114 #endif
doca_error_t dma_task_is_supported(struct doca_devinfo *devinfo)
Definition: dma_common.c:593
doca_error_t register_dma_params(bool is_remote)
Definition: dma_common.c:204
#define MAX_ARG_SIZE
Definition: dma_common.h:38
#define MAX_TXT_SIZE
Definition: dma_common.h:40
doca_error_t destroy_dma_host_resources(struct program_core_objects *state)
Definition: dma_common.c:576
doca_error_t allocate_dma_host_resources(const char *pcie_addr, struct program_core_objects *state)
Definition: dma_common.c:536
doca_error_t destroy_dma_resources(struct dma_resources *resources)
Definition: dma_common.c:513
doca_error_t allocate_dma_resources(const char *pcie_addr, int num_buf, struct dma_resources *resources)
Definition: dma_common.c:427
struct rdma_resources resources
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
enum doca_error doca_error_t
DOCA API return codes.
char buf_info_path[MAX_ARG_SIZE]
Definition: dma_common.h:49
int num_dst_buf
Definition: dma_common.h:51
char export_desc_path[MAX_ARG_SIZE]
Definition: dma_common.h:48
char cpy_txt[MAX_TXT_SIZE]
Definition: dma_common.h:47
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: dma_common.h:46
int num_src_buf
Definition: dma_common.h:50
struct program_core_objects state
Definition: dma_common.h:55
bool run_pe_progress
Definition: dma_common.h:58